summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2011-12-20 14:37:44 +0400
committerAndrey Nazarov <skuller@skuller.net>2012-04-03 01:25:47 +0400
commitb3e271a53de2610de173f9b2bda5d15dd4d78909 (patch)
treed567b91dadac42e168bcb13db5fe93ffbc7e1533
parentca4a019a74b11aa21fea2a03c6dff3b183463aab (diff)
Massive coding style change.
Use linux style brackets. Pad operators with spaces. Unpad parenthesis, except for ‘if’, ‘for’, ‘while’ constructs.
-rw-r--r--src/baseq2/g_ai.c549
-rw-r--r--src/baseq2/g_chase.c6
-rw-r--r--src/baseq2/g_cmds.c489
-rw-r--r--src/baseq2/g_combat.c263
-rw-r--r--src/baseq2/g_func.c1007
-rw-r--r--src/baseq2/g_items.c1064
-rw-r--r--src/baseq2/g_local.h341
-rw-r--r--src/baseq2/g_main.c268
-rw-r--r--src/baseq2/g_misc.c973
-rw-r--r--src/baseq2/g_monster.c458
-rw-r--r--src/baseq2/g_phys.c491
-rw-r--r--src/baseq2/g_ptrs.c724
-rw-r--r--src/baseq2/g_save.c453
-rw-r--r--src/baseq2/g_spawn.c709
-rw-r--r--src/baseq2/g_svcmds.c139
-rw-r--r--src/baseq2/g_target.c396
-rw-r--r--src/baseq2/g_trigger.c240
-rw-r--r--src/baseq2/g_turret.c152
-rw-r--r--src/baseq2/g_utils.c225
-rw-r--r--src/baseq2/g_weapon.c628
-rw-r--r--src/baseq2/m_actor.c239
-rw-r--r--src/baseq2/m_actor.h2
-rw-r--r--src/baseq2/m_berserk.c151
-rw-r--r--src/baseq2/m_berserk.h2
-rw-r--r--src/baseq2/m_boss2.c334
-rw-r--r--src/baseq2/m_boss2.h2
-rw-r--r--src/baseq2/m_boss3.c33
-rw-r--r--src/baseq2/m_boss31.c362
-rw-r--r--src/baseq2/m_boss31.h2
-rw-r--r--src/baseq2/m_boss32.c399
-rw-r--r--src/baseq2/m_boss32.h2
-rw-r--r--src/baseq2/m_brain.c235
-rw-r--r--src/baseq2/m_brain.h2
-rw-r--r--src/baseq2/m_chick.c251
-rw-r--r--src/baseq2/m_chick.h2
-rw-r--r--src/baseq2/m_flipper.c138
-rw-r--r--src/baseq2/m_flipper.h2
-rw-r--r--src/baseq2/m_float.c240
-rw-r--r--src/baseq2/m_float.h2
-rw-r--r--src/baseq2/m_flyer.c434
-rw-r--r--src/baseq2/m_flyer.h2
-rw-r--r--src/baseq2/m_gladiator.c151
-rw-r--r--src/baseq2/m_gladiator.h2
-rw-r--r--src/baseq2/m_gunner.c207
-rw-r--r--src/baseq2/m_gunner.h2
-rw-r--r--src/baseq2/m_hover.c200
-rw-r--r--src/baseq2/m_hover.h2
-rw-r--r--src/baseq2/m_infantry.c231
-rw-r--r--src/baseq2/m_infantry.h2
-rw-r--r--src/baseq2/m_insane.c260
-rw-r--r--src/baseq2/m_insane.h2
-rw-r--r--src/baseq2/m_medic.c269
-rw-r--r--src/baseq2/m_medic.h2
-rw-r--r--src/baseq2/m_move.c343
-rw-r--r--src/baseq2/m_mutant.c256
-rw-r--r--src/baseq2/m_mutant.h2
-rw-r--r--src/baseq2/m_parasite.c229
-rw-r--r--src/baseq2/m_parasite.h2
-rw-r--r--src/baseq2/m_player.h2
-rw-r--r--src/baseq2/m_soldier.c378
-rw-r--r--src/baseq2/m_soldier.h2
-rw-r--r--src/baseq2/m_supertank.c235
-rw-r--r--src/baseq2/m_supertank.h2
-rw-r--r--src/baseq2/m_tank.c326
-rw-r--r--src/baseq2/m_tank.h2
-rw-r--r--src/baseq2/p_client.c792
-rw-r--r--src/baseq2/p_hud.c297
-rw-r--r--src/baseq2/p_trail.c43
-rw-r--r--src/baseq2/p_view.c511
-rw-r--r--src/baseq2/p_weapon.c797
-rw-r--r--src/bsp.c818
-rw-r--r--src/bsp.h40
-rw-r--r--src/cl_aastat.c325
-rw-r--r--src/cl_console.c706
-rw-r--r--src/cl_demo.c801
-rw-r--r--src/cl_download.c478
-rw-r--r--src/cl_ents.c771
-rw-r--r--src/cl_fx.c1044
-rw-r--r--src/cl_http.c410
-rw-r--r--src/cl_input.c744
-rw-r--r--src/cl_keys.c418
-rw-r--r--src/cl_local.h404
-rw-r--r--src/cl_locs.c170
-rw-r--r--src/cl_main.c2000
-rw-r--r--src/cl_newfx.c682
-rw-r--r--src/cl_null.c17
-rw-r--r--src/cl_parse.c816
-rw-r--r--src/cl_precache.c323
-rw-r--r--src/cl_pred.c130
-rw-r--r--src/cl_public.h98
-rw-r--r--src/cl_ref.c194
-rw-r--r--src/cl_scrn.c1221
-rw-r--r--src/cl_tent.c878
-rw-r--r--src/cl_view.c260
-rw-r--r--src/cmd.c1245
-rw-r--r--src/cmodel.c617
-rw-r--r--src/cmodel.h81
-rw-r--r--src/common.c1313
-rw-r--r--src/common.h389
-rw-r--r--src/crc.c18
-rw-r--r--src/cvar.c724
-rw-r--r--src/d_bsp.h6
-rw-r--r--src/d_md2.h7
-rw-r--r--src/d_md3.h2
-rw-r--r--src/d_pak.h2
-rw-r--r--src/d_pcx.h2
-rw-r--r--src/d_sp2.h2
-rw-r--r--src/d_wal.h2
-rw-r--r--src/error.c15
-rw-r--r--src/error.h8
-rw-r--r--src/files.c1958
-rw-r--r--src/files.h100
-rw-r--r--src/fpu.c3
-rw-r--r--src/fpu.h6
-rw-r--r--src/g_public.h136
-rw-r--r--src/gl_draw.c272
-rw-r--r--src/gl_images.c706
-rw-r--r--src/gl_local.h150
-rw-r--r--src/gl_main.c732
-rw-r--r--src/gl_mesh.c402
-rw-r--r--src/gl_models.c302
-rw-r--r--src/gl_sky.c248
-rw-r--r--src/gl_state.c321
-rw-r--r--src/gl_surf.c499
-rw-r--r--src/gl_tess.c348
-rw-r--r--src/gl_world.c363
-rw-r--r--src/in_dx.c210
-rw-r--r--src/in_evdev.c243
-rw-r--r--src/in_lirc.c85
-rw-r--r--src/in_lirc.h8
-rw-r--r--src/in_public.h18
-rw-r--r--src/io_sleep.c171
-rw-r--r--src/io_sleep.h12
-rw-r--r--src/key_public.h36
-rw-r--r--src/m_flash.c47
-rw-r--r--src/mdfour.c97
-rw-r--r--src/mdfour.h6
-rw-r--r--src/mvd_client.c1717
-rw-r--r--src/mvd_game.c1430
-rw-r--r--src/mvd_gtv.h2
-rw-r--r--src/mvd_local.h89
-rw-r--r--src/mvd_parse.c760
-rw-r--r--src/mvd_public.h22
-rw-r--r--src/net_chan.c537
-rw-r--r--src/net_chan.h30
-rw-r--r--src/net_common.c1040
-rw-r--r--src/net_sock.h72
-rw-r--r--src/net_stream.h16
-rw-r--r--src/pmove.c678
-rw-r--r--src/pmove.h8
-rw-r--r--src/prompt.c382
-rw-r--r--src/prompt.h26
-rw-r--r--src/protocol.h38
-rw-r--r--src/q_field.c158
-rw-r--r--src/q_field.h14
-rw-r--r--src/q_fifo.h57
-rw-r--r--src/q_list.h123
-rw-r--r--src/q_msg.c1783
-rw-r--r--src/q_msg.h216
-rw-r--r--src/q_shared.c649
-rw-r--r--src/q_shared.h349
-rw-r--r--src/qal_api.c102
-rw-r--r--src/qal_api.h152
-rw-r--r--src/qgl_api.c1105
-rw-r--r--src/qgl_api.h254
-rw-r--r--src/r_images.c1185
-rw-r--r--src/r_models.c255
-rw-r--r--src/r_models.h26
-rw-r--r--src/r_shared.h58
-rw-r--r--src/rand1k.h3
-rw-r--r--src/ref_public.h80
-rw-r--r--src/snd_al.c211
-rw-r--r--src/snd_dma.c98
-rw-r--r--src/snd_dx.c209
-rw-r--r--src/snd_local.h82
-rw-r--r--src/snd_main.c543
-rw-r--r--src/snd_mem.c184
-rw-r--r--src/snd_mix.c134
-rw-r--r--src/snd_oss.c170
-rw-r--r--src/snd_public.h26
-rw-r--r--src/snd_sdl.c79
-rw-r--r--src/snd_wave.c247
-rw-r--r--src/sv_ac.c1215
-rw-r--r--src/sv_ccmds.c1082
-rw-r--r--src/sv_ents.c282
-rw-r--r--src/sv_game.c634
-rw-r--r--src/sv_init.c230
-rw-r--r--src/sv_local.h270
-rw-r--r--src/sv_main.c1261
-rw-r--r--src/sv_mvd.c1433
-rw-r--r--src/sv_public.h16
-rw-r--r--src/sv_save.c313
-rw-r--r--src/sv_send.c651
-rw-r--r--src/sv_user.c1087
-rw-r--r--src/sv_world.c323
-rw-r--r--src/sw_aclip.c238
-rw-r--r--src/sw_alias.c365
-rw-r--r--src/sw_block.h22
-rw-r--r--src/sw_bsp.c292
-rw-r--r--src/sw_draw.c367
-rw-r--r--src/sw_edge.c538
-rw-r--r--src/sw_image.c90
-rw-r--r--src/sw_light.c168
-rw-r--r--src/sw_local.h532
-rw-r--r--src/sw_main.c632
-rw-r--r--src/sw_misc.c274
-rw-r--r--src/sw_model.c185
-rw-r--r--src/sw_part.c66
-rw-r--r--src/sw_poly.c683
-rw-r--r--src/sw_polyse.c471
-rw-r--r--src/sw_protect.c7
-rw-r--r--src/sw_rast.c261
-rw-r--r--src/sw_scan.c245
-rw-r--r--src/sw_sird.c96
-rw-r--r--src/sw_sky.c105
-rw-r--r--src/sw_surf.c168
-rw-r--r--src/sys_public.h50
-rw-r--r--src/sys_unix.c600
-rw-r--r--src/sys_win.c784
-rw-r--r--src/tests.c137
-rw-r--r--src/ui_atoms.c413
-rw-r--r--src/ui_demos.c398
-rw-r--r--src/ui_local.h140
-rw-r--r--src/ui_menu.c1287
-rw-r--r--src/ui_multiplayer.c227
-rw-r--r--src/ui_playerconfig.c141
-rw-r--r--src/ui_playermodels.c142
-rw-r--r--src/ui_public.h22
-rw-r--r--src/ui_script.c474
-rw-r--r--src/vid_local.h16
-rw-r--r--src/vid_public.h26
-rw-r--r--src/vid_sdl.c633
-rw-r--r--src/vid_win.c801
-rw-r--r--src/win_ac.c41
-rw-r--r--src/win_ascii.c65
-rw-r--r--src/win_dbg.c447
-rw-r--r--src/win_glimp.c175
-rw-r--r--src/win_glimp.h2
-rw-r--r--src/win_local.h12
-rw-r--r--src/win_swimp.c192
-rw-r--r--src/win_wgl.c79
-rw-r--r--src/win_wgl.h34
-rw-r--r--src/wsaerr.h128
243 files changed, 40284 insertions, 40803 deletions
diff --git a/src/baseq2/g_ai.c b/src/baseq2/g_ai.c
index 52e5048..a4828b4 100644
--- a/src/baseq2/g_ai.c
+++ b/src/baseq2/g_ai.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,10 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
-qboolean FindTarget (edict_t *self);
+qboolean FindTarget(edict_t *self);
extern cvar_t *maxclients;
-qboolean ai_checkattack (edict_t *self, float dist);
+qboolean ai_checkattack(edict_t *self, float dist);
qboolean enemy_vis;
qboolean enemy_infront;
@@ -47,7 +47,7 @@ will be null.
In coop games, sight_client will cycle between the clients.
=================
*/
-void AI_SetSightClient (void)
+void AI_SetSightClient(void)
{
edict_t *ent;
int start, check;
@@ -58,21 +58,18 @@ void AI_SetSightClient (void)
start = level.sight_client - g_edicts;
check = start;
- while (1)
- {
+ while (1) {
check++;
if (check > game.maxclients)
check = 1;
ent = &g_edicts[check];
if (ent->inuse
&& ent->health > 0
- && !(ent->flags & FL_NOTARGET) )
- {
+ && !(ent->flags & FL_NOTARGET)) {
level.sight_client = ent;
return; // got one
}
- if (check == start)
- {
+ if (check == start) {
level.sight_client = NULL;
return; // nobody to see
}
@@ -89,9 +86,9 @@ Move the specified distance at current facing.
This replaces the QC functions: ai_forward, ai_back, ai_pain, and ai_painforward
==============
*/
-void ai_move (edict_t *self, float dist)
+void ai_move(edict_t *self, float dist)
{
- M_walkmove (self, self->s.angles[YAW], dist);
+ M_walkmove(self, self->s.angles[YAW], dist);
}
@@ -103,50 +100,41 @@ Used for standing around and looking for players
Distance is for slight position adjustments needed by the animations
==============
*/
-void ai_stand (edict_t *self, float dist)
+void ai_stand(edict_t *self, float dist)
{
vec3_t v;
if (dist)
- M_walkmove (self, self->s.angles[YAW], dist);
+ M_walkmove(self, self->s.angles[YAW], dist);
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
- if (self->enemy)
- {
- VectorSubtract (self->enemy->s.origin, self->s.origin, v);
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
+ if (self->enemy) {
+ VectorSubtract(self->enemy->s.origin, self->s.origin, v);
self->ideal_yaw = vectoyaw(v);
- if (self->s.angles[YAW] != self->ideal_yaw && self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND)
- {
+ if (self->s.angles[YAW] != self->ideal_yaw && self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND) {
self->monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
- self->monsterinfo.run (self);
+ self->monsterinfo.run(self);
}
- M_ChangeYaw (self);
- ai_checkattack (self, 0);
- }
- else
- FindTarget (self);
+ M_ChangeYaw(self);
+ ai_checkattack(self, 0);
+ } else
+ FindTarget(self);
return;
}
- if (FindTarget (self))
+ if (FindTarget(self))
return;
-
- if (level.time > self->monsterinfo.pausetime)
- {
- self->monsterinfo.walk (self);
+
+ if (level.time > self->monsterinfo.pausetime) {
+ self->monsterinfo.walk(self);
return;
}
- if (!(self->spawnflags & 1) && (self->monsterinfo.idle) && (level.time > self->monsterinfo.idle_time))
- {
- if (self->monsterinfo.idle_time)
- {
- self->monsterinfo.idle (self);
+ if (!(self->spawnflags & 1) && (self->monsterinfo.idle) && (level.time > self->monsterinfo.idle_time)) {
+ if (self->monsterinfo.idle_time) {
+ self->monsterinfo.idle(self);
self->monsterinfo.idle_time = level.time + 15 + random() * 15;
- }
- else
- {
+ } else {
self->monsterinfo.idle_time = level.time + random() * 15;
}
}
@@ -160,23 +148,19 @@ ai_walk
The monster is walking it's beat
=============
*/
-void ai_walk (edict_t *self, float dist)
+void ai_walk(edict_t *self, float dist)
{
- M_MoveToGoal (self, dist);
+ M_MoveToGoal(self, dist);
// check for noticing a player
- if (FindTarget (self))
+ if (FindTarget(self))
return;
- if ((self->monsterinfo.search) && (level.time > self->monsterinfo.idle_time))
- {
- if (self->monsterinfo.idle_time)
- {
- self->monsterinfo.search (self);
+ if ((self->monsterinfo.search) && (level.time > self->monsterinfo.idle_time)) {
+ if (self->monsterinfo.idle_time) {
+ self->monsterinfo.search(self);
self->monsterinfo.idle_time = level.time + 15 + random() * 15;
- }
- else
- {
+ } else {
self->monsterinfo.idle_time = level.time + random() * 15;
}
}
@@ -191,16 +175,16 @@ Turns towards target and advances
Use this call with a distnace of 0 to replace ai_face
==============
*/
-void ai_charge (edict_t *self, float dist)
+void ai_charge(edict_t *self, float dist)
{
vec3_t v;
- VectorSubtract (self->enemy->s.origin, self->s.origin, v);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, v);
self->ideal_yaw = vectoyaw(v);
- M_ChangeYaw (self);
+ M_ChangeYaw(self);
if (dist)
- M_walkmove (self, self->s.angles[YAW], dist);
+ M_walkmove(self, self->s.angles[YAW], dist);
}
@@ -212,15 +196,15 @@ don't move, but turn towards ideal_yaw
Distance is for slight position adjustments needed by the animations
=============
*/
-void ai_turn (edict_t *self, float dist)
+void ai_turn(edict_t *self, float dist)
{
if (dist)
- M_walkmove (self, self->s.angles[YAW], dist);
+ M_walkmove(self, self->s.angles[YAW], dist);
- if (FindTarget (self))
+ if (FindTarget(self))
return;
-
- M_ChangeYaw (self);
+
+ M_ChangeYaw(self);
}
@@ -261,13 +245,13 @@ returns the range catagorization of an entity reletive to self
3 only triggered by damage
=============
*/
-int range (edict_t *self, edict_t *other)
+int range(edict_t *self, edict_t *other)
{
vec3_t v;
float len;
- VectorSubtract (self->s.origin, other->s.origin, v);
- len = VectorLength (v);
+ VectorSubtract(self->s.origin, other->s.origin, v);
+ len = VectorLength(v);
if (len < MELEE_DISTANCE)
return RANGE_MELEE;
if (len < 500)
@@ -284,18 +268,18 @@ visible
returns 1 if the entity is visible to self, even if not infront ()
=============
*/
-qboolean visible (edict_t *self, edict_t *other)
+qboolean visible(edict_t *self, edict_t *other)
{
vec3_t spot1;
vec3_t spot2;
trace_t trace;
- VectorCopy (self->s.origin, spot1);
+ VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
- VectorCopy (other->s.origin, spot2);
+ VectorCopy(other->s.origin, spot2);
spot2[2] += other->viewheight;
- trace = gi.trace (spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE);
-
+ trace = gi.trace(spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE);
+
if (trace.fraction == 1.0)
return qtrue;
return qfalse;
@@ -309,17 +293,17 @@ infront
returns 1 if the entity is in front (in sight) of self
=============
*/
-qboolean infront (edict_t *self, edict_t *other)
+qboolean infront(edict_t *self, edict_t *other)
{
vec3_t vec;
float dot;
vec3_t forward;
-
- AngleVectors (self->s.angles, forward, NULL, NULL);
- VectorSubtract (other->s.origin, self->s.origin, vec);
- VectorNormalize (vec);
- dot = DotProduct (vec, forward);
-
+
+ AngleVectors(self->s.angles, forward, NULL, NULL);
+ VectorSubtract(other->s.origin, self->s.origin, vec);
+ VectorNormalize(vec);
+ dot = DotProduct(vec, forward);
+
if (dot > 0.3)
return qtrue;
return qfalse;
@@ -328,27 +312,26 @@ qboolean infront (edict_t *self, edict_t *other)
//============================================================================
-void HuntTarget (edict_t *self)
+void HuntTarget(edict_t *self)
{
vec3_t vec;
self->goalentity = self->enemy;
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
else
- self->monsterinfo.run (self);
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
+ self->monsterinfo.run(self);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
self->ideal_yaw = vectoyaw(vec);
// wait a while before first attack
if (!(self->monsterinfo.aiflags & AI_STAND_GROUND))
- AttackFinished (self, 1);
+ AttackFinished(self, 1);
}
-void FoundTarget (edict_t *self)
+void FoundTarget(edict_t *self)
{
// let other monsters see this monster for a while
- if (self->enemy->client)
- {
+ if (self->enemy->client) {
level.sight_entity = self;
level.sight_entity_framenum = level.framenum;
level.sight_entity->light_level = 128;
@@ -359,17 +342,15 @@ void FoundTarget (edict_t *self)
VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting);
self->monsterinfo.trail_time = level.time;
- if (!self->combattarget)
- {
- HuntTarget (self);
+ if (!self->combattarget) {
+ HuntTarget(self);
return;
}
self->goalentity = self->movetarget = G_PickTarget(self->combattarget);
- if (!self->movetarget)
- {
+ if (!self->movetarget) {
self->goalentity = self->movetarget = self->enemy;
- HuntTarget (self);
+ HuntTarget(self);
gi.dprintf("%s at %s, combattarget %s not found\n", self->classname, vtos(self->s.origin), self->combattarget);
return;
}
@@ -383,7 +364,7 @@ void FoundTarget (edict_t *self)
self->monsterinfo.pausetime = 0;
// run for it
- self->monsterinfo.run (self);
+ self->monsterinfo.run(self);
}
@@ -404,16 +385,14 @@ checked each frame. This means multi player games will have slightly
slower noticing monsters.
============
*/
-qboolean FindTarget (edict_t *self)
+qboolean FindTarget(edict_t *self)
{
edict_t *client;
qboolean heardit;
int r;
- if (self->monsterinfo.aiflags & AI_GOOD_GUY)
- {
- if (self->goalentity && self->goalentity->inuse && self->goalentity->classname)
- {
+ if (self->monsterinfo.aiflags & AI_GOOD_GUY) {
+ if (self->goalentity && self->goalentity->inuse && self->goalentity->classname) {
if (strcmp(self->goalentity->classname, "target_actor") == 0)
return qfalse;
}
@@ -434,26 +413,18 @@ qboolean FindTarget (edict_t *self)
// but not weapon impact/explosion noises
heardit = qfalse;
- if ((level.sight_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1) )
- {
+ if ((level.sight_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1)) {
client = level.sight_entity;
- if (client->enemy == self->enemy)
- {
+ if (client->enemy == self->enemy) {
return qfalse;
}
- }
- else if (level.sound_entity_framenum >= (level.framenum - 1))
- {
+ } else if (level.sound_entity_framenum >= (level.framenum - 1)) {
client = level.sound_entity;
heardit = qtrue;
- }
- else if (!(self->enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1) )
- {
+ } else if (!(self->enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1)) {
client = level.sound2_entity;
heardit = qtrue;
- }
- else
- {
+ } else {
client = level.sight_client;
if (!client)
return qfalse; // no clients to get mad at
@@ -466,29 +437,22 @@ qboolean FindTarget (edict_t *self)
if (client == self->enemy)
return qtrue; // JDC qfalse;
- if (client->client)
- {
+ if (client->client) {
if (client->flags & FL_NOTARGET)
return qfalse;
- }
- else if (client->svflags & SVF_MONSTER)
- {
+ } else if (client->svflags & SVF_MONSTER) {
if (!client->enemy)
return qfalse;
if (client->enemy->flags & FL_NOTARGET)
return qfalse;
- }
- else if (heardit)
- {
+ } else if (heardit) {
if (client->owner->flags & FL_NOTARGET)
return qfalse;
- }
- else
+ } else
return qfalse;
- if (!heardit)
- {
- r = range (self, client);
+ if (!heardit) {
+ r = range(self, client);
if (r == RANGE_FAR)
return qfalse;
@@ -499,62 +463,47 @@ qboolean FindTarget (edict_t *self)
if (client->light_level <= 5)
return qfalse;
- if (!visible (self, client))
- {
+ if (!visible(self, client)) {
return qfalse;
}
- if (r == RANGE_NEAR)
- {
- if (client->show_hostile < level.time && !infront (self, client))
- {
+ if (r == RANGE_NEAR) {
+ if (client->show_hostile < level.time && !infront(self, client)) {
return qfalse;
}
- }
- else if (r == RANGE_MID)
- {
- if (!infront (self, client))
- {
+ } else if (r == RANGE_MID) {
+ if (!infront(self, client)) {
return qfalse;
}
}
self->enemy = client;
- if (strcmp(self->enemy->classname, "player_noise") != 0)
- {
+ if (strcmp(self->enemy->classname, "player_noise") != 0) {
self->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
- if (!self->enemy->client)
- {
+ if (!self->enemy->client) {
self->enemy = self->enemy->enemy;
- if (!self->enemy->client)
- {
+ if (!self->enemy->client) {
self->enemy = NULL;
return qfalse;
}
}
}
- }
- else // heardit
- {
+ } else { // heardit
vec3_t temp;
- if (self->spawnflags & 1)
- {
- if (!visible (self, client))
+ if (self->spawnflags & 1) {
+ if (!visible(self, client))
return qfalse;
- }
- else
- {
+ } else {
if (!gi.inPHS(self->s.origin, client->s.origin))
return qfalse;
}
- VectorSubtract (client->s.origin, self->s.origin, temp);
+ VectorSubtract(client->s.origin, self->s.origin, temp);
- if (VectorLength(temp) > 1000) // too far to hear
- {
+ if (VectorLength(temp) > 1000) { // too far to hear
return qfalse;
}
@@ -564,7 +513,7 @@ qboolean FindTarget (edict_t *self)
return qfalse;
self->ideal_yaw = vectoyaw(temp);
- M_ChangeYaw (self);
+ M_ChangeYaw(self);
// hunt the sound for a bit; hopefully find the real player
self->monsterinfo.aiflags |= AI_SOUND_TARGET;
@@ -574,10 +523,10 @@ qboolean FindTarget (edict_t *self)
//
// got one
//
- FoundTarget (self);
+ FoundTarget(self);
if (!(self->monsterinfo.aiflags & AI_SOUND_TARGET) && (self->monsterinfo.sight))
- self->monsterinfo.sight (self, self->enemy);
+ self->monsterinfo.sight(self, self->enemy);
return qtrue;
}
@@ -604,32 +553,30 @@ qboolean FacingIdeal(edict_t *self)
//=============================================================================
-qboolean M_CheckAttack (edict_t *self)
+qboolean M_CheckAttack(edict_t *self)
{
vec3_t spot1, spot2;
float chance;
trace_t tr;
- if (self->enemy->health > 0)
- {
- // see if any entities are in the way of the shot
- VectorCopy (self->s.origin, spot1);
+ if (self->enemy->health > 0) {
+ // see if any entities are in the way of the shot
+ VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
- VectorCopy (self->enemy->s.origin, spot2);
+ VectorCopy(self->enemy->s.origin, spot2);
spot2[2] += self->enemy->viewheight;
- tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA|CONTENTS_WINDOW);
+ tr = gi.trace(spot1, NULL, NULL, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA | CONTENTS_WINDOW);
// do we have a clear shot?
if (tr.ent != self->enemy)
return qfalse;
}
-
+
// melee attack
- if (enemy_range == RANGE_MELEE)
- {
+ if (enemy_range == RANGE_MELEE) {
// don't always melee in easy mode
- if (skill->value == 0 && (rand()&3) )
+ if (skill->value == 0 && (rand() & 3))
return qfalse;
if (self->monsterinfo.melee)
self->monsterinfo.attack_state = AS_MELEE;
@@ -637,35 +584,26 @@ qboolean M_CheckAttack (edict_t *self)
self->monsterinfo.attack_state = AS_MISSILE;
return qtrue;
}
-
+
// missile attack
if (!self->monsterinfo.attack)
return qfalse;
-
+
if (level.time < self->monsterinfo.attack_finished)
return qfalse;
-
+
if (enemy_range == RANGE_FAR)
return qfalse;
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MELEE)
- {
+ } else if (enemy_range == RANGE_MELEE) {
chance = 0.2;
- }
- else if (enemy_range == RANGE_NEAR)
- {
+ } else if (enemy_range == RANGE_NEAR) {
chance = 0.1;
- }
- else if (enemy_range == RANGE_MID)
- {
+ } else if (enemy_range == RANGE_MID) {
chance = 0.02;
- }
- else
- {
+ } else {
return qfalse;
}
@@ -674,15 +612,13 @@ qboolean M_CheckAttack (edict_t *self)
else if (skill->value >= 2)
chance *= 2;
- if (random () < chance)
- {
+ if (random() < chance) {
self->monsterinfo.attack_state = AS_MISSILE;
- self->monsterinfo.attack_finished = level.time + 2*random();
+ self->monsterinfo.attack_finished = level.time + 2 * random();
return qtrue;
}
- if (self->flags & FL_FLY)
- {
+ if (self->flags & FL_FLY) {
if (random() < 0.3)
self->monsterinfo.attack_state = AS_SLIDING;
else
@@ -703,11 +639,10 @@ Turn and close until within an angle to launch a melee attack
void ai_run_melee(edict_t *self)
{
self->ideal_yaw = enemy_yaw;
- M_ChangeYaw (self);
+ M_ChangeYaw(self);
- if (FacingIdeal(self))
- {
- self->monsterinfo.melee (self);
+ if (FacingIdeal(self)) {
+ self->monsterinfo.melee(self);
self->monsterinfo.attack_state = AS_STRAIGHT;
}
}
@@ -723,11 +658,10 @@ Turn in place until within an angle to launch a missile attack
void ai_run_missile(edict_t *self)
{
self->ideal_yaw = enemy_yaw;
- M_ChangeYaw (self);
+ M_ChangeYaw(self);
- if (FacingIdeal(self))
- {
- self->monsterinfo.attack (self);
+ if (FacingIdeal(self)) {
+ self->monsterinfo.attack(self);
self->monsterinfo.attack_state = AS_STRAIGHT;
}
};
@@ -743,20 +677,20 @@ Strafe sideways, but stay at aproximately the same range
void ai_run_slide(edict_t *self, float distance)
{
float ofs;
-
+
self->ideal_yaw = enemy_yaw;
- M_ChangeYaw (self);
+ M_ChangeYaw(self);
if (self->monsterinfo.lefty)
ofs = 90;
else
ofs = -90;
-
- if (M_walkmove (self, self->ideal_yaw + ofs, distance))
+
+ if (M_walkmove(self, self->ideal_yaw + ofs, distance))
return;
-
+
self->monsterinfo.lefty = 1 - self->monsterinfo.lefty;
- M_walkmove (self, self->ideal_yaw - ofs, distance);
+ M_walkmove(self, self->ideal_yaw - ofs, distance);
}
@@ -768,23 +702,19 @@ Decides if we're going to attack or do something else
used by ai_run and ai_stand
=============
*/
-qboolean ai_checkattack (edict_t *self, float dist)
+qboolean ai_checkattack(edict_t *self, float dist)
{
vec3_t temp;
qboolean hesDeadJim;
// this causes monsters to run blindly to the combat point w/o firing
- if (self->goalentity)
- {
+ if (self->goalentity) {
if (self->monsterinfo.aiflags & AI_COMBAT_POINT)
return qfalse;
- if (self->monsterinfo.aiflags & AI_SOUND_TARGET)
- {
- if ((level.time - self->enemy->teleport_time) > 5.0)
- {
- if (self->goalentity == self->enemy)
- {
+ if (self->monsterinfo.aiflags & AI_SOUND_TARGET) {
+ if ((level.time - self->enemy->teleport_time) > 5.0) {
+ if (self->goalentity == self->enemy) {
if (self->movetarget)
self->goalentity = self->movetarget;
else
@@ -793,9 +723,7 @@ qboolean ai_checkattack (edict_t *self, float dist)
self->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
if (self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND)
self->monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
- }
- else
- {
+ } else {
self->show_hostile = level.time + 1;
return qfalse;
}
@@ -806,57 +734,41 @@ qboolean ai_checkattack (edict_t *self, float dist)
// see if the enemy is dead
hesDeadJim = qfalse;
- if ((!self->enemy) || (!self->enemy->inuse))
- {
+ if ((!self->enemy) || (!self->enemy->inuse)) {
hesDeadJim = qtrue;
- }
- else if (self->monsterinfo.aiflags & AI_MEDIC)
- {
- if (self->enemy->health > 0)
- {
+ } else if (self->monsterinfo.aiflags & AI_MEDIC) {
+ if (self->enemy->health > 0) {
hesDeadJim = qtrue;
self->monsterinfo.aiflags &= ~AI_MEDIC;
}
- }
- else
- {
- if (self->monsterinfo.aiflags & AI_BRUTAL)
- {
+ } else {
+ if (self->monsterinfo.aiflags & AI_BRUTAL) {
if (self->enemy->health <= -80)
hesDeadJim = qtrue;
- }
- else
- {
+ } else {
if (self->enemy->health <= 0)
hesDeadJim = qtrue;
}
}
- if (hesDeadJim)
- {
+ if (hesDeadJim) {
self->enemy = NULL;
- // FIXME: look all around for other targets
- if (self->oldenemy && self->oldenemy->health > 0)
- {
+ // FIXME: look all around for other targets
+ if (self->oldenemy && self->oldenemy->health > 0) {
self->enemy = self->oldenemy;
self->oldenemy = NULL;
- HuntTarget (self);
- }
- else
- {
- if (self->movetarget)
- {
+ HuntTarget(self);
+ } else {
+ if (self->movetarget) {
self->goalentity = self->movetarget;
- self->monsterinfo.walk (self);
- }
- else
- {
+ self->monsterinfo.walk(self);
+ } else {
// we need the pausetime otherwise the stand code
// will just revert to walking with no target and
// the monsters will wonder around aimlessly trying
// to hunt the world entity
self->monsterinfo.pausetime = level.time + 100000000;
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
}
return qtrue;
}
@@ -866,10 +778,9 @@ qboolean ai_checkattack (edict_t *self, float dist)
// check knowledge of enemy
enemy_vis = visible(self, self->enemy);
- if (enemy_vis)
- {
+ if (enemy_vis) {
self->monsterinfo.search_time = level.time + 5;
- VectorCopy (self->enemy->s.origin, self->monsterinfo.last_sighting);
+ VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting);
}
// look for other coop players here
@@ -881,20 +792,18 @@ qboolean ai_checkattack (edict_t *self, float dist)
enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy);
- VectorSubtract (self->enemy->s.origin, self->s.origin, temp);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp);
// JDC self->ideal_yaw = enemy_yaw;
- if (self->monsterinfo.attack_state == AS_MISSILE)
- {
- ai_run_missile (self);
+ if (self->monsterinfo.attack_state == AS_MISSILE) {
+ ai_run_missile(self);
return qtrue;
}
- if (self->monsterinfo.attack_state == AS_MELEE)
- {
- ai_run_melee (self);
+ if (self->monsterinfo.attack_state == AS_MELEE) {
+ ai_run_melee(self);
return qtrue;
}
@@ -902,7 +811,7 @@ qboolean ai_checkattack (edict_t *self, float dist)
if (!enemy_vis)
return qfalse;
- return self->monsterinfo.checkattack (self);
+ return self->monsterinfo.checkattack(self);
}
@@ -913,7 +822,7 @@ ai_run
The monster has an enemy it is trying to kill
=============
*/
-void ai_run (edict_t *self, float dist)
+void ai_run(edict_t *self, float dist)
{
vec3_t v;
edict_t *tempgoal;
@@ -927,58 +836,52 @@ void ai_run (edict_t *self, float dist)
vec3_t left_target, right_target;
// if we're going to a combat point, just proceed
- if (self->monsterinfo.aiflags & AI_COMBAT_POINT)
- {
- M_MoveToGoal (self, dist);
+ if (self->monsterinfo.aiflags & AI_COMBAT_POINT) {
+ M_MoveToGoal(self, dist);
return;
}
- if (self->monsterinfo.aiflags & AI_SOUND_TARGET)
- {
- VectorSubtract (self->s.origin, self->enemy->s.origin, v);
- if (VectorLength(v) < 64)
- {
+ if (self->monsterinfo.aiflags & AI_SOUND_TARGET) {
+ VectorSubtract(self->s.origin, self->enemy->s.origin, v);
+ if (VectorLength(v) < 64) {
self->monsterinfo.aiflags |= (AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
return;
}
- M_MoveToGoal (self, dist);
+ M_MoveToGoal(self, dist);
- if (!FindTarget (self))
+ if (!FindTarget(self))
return;
}
- if (ai_checkattack (self, dist))
+ if (ai_checkattack(self, dist))
return;
- if (self->monsterinfo.attack_state == AS_SLIDING)
- {
- ai_run_slide (self, dist);
+ if (self->monsterinfo.attack_state == AS_SLIDING) {
+ ai_run_slide(self, dist);
return;
}
- if (enemy_vis)
- {
+ if (enemy_vis) {
// if (self.aiflags & AI_LOST_SIGHT)
// dprint("regained sight\n");
- M_MoveToGoal (self, dist);
+ M_MoveToGoal(self, dist);
self->monsterinfo.aiflags &= ~AI_LOST_SIGHT;
- VectorCopy (self->enemy->s.origin, self->monsterinfo.last_sighting);
+ VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting);
self->monsterinfo.trail_time = level.time;
return;
}
// coop will change to another enemy if visible
- if (coop->value)
- { // FIXME: insane guys get mad with this, which causes crashes!
- if (FindTarget (self))
+ if (coop->value) {
+ // FIXME: insane guys get mad with this, which causes crashes!
+ if (FindTarget(self))
return;
}
- if ((self->monsterinfo.search_time) && (level.time > (self->monsterinfo.search_time + 20)))
- {
- M_MoveToGoal (self, dist);
+ if ((self->monsterinfo.search_time) && (level.time > (self->monsterinfo.search_time + 20))) {
+ M_MoveToGoal(self, dist);
self->monsterinfo.search_time = 0;
// dprint("search timeout\n");
return;
@@ -990,8 +893,7 @@ void ai_run (edict_t *self, float dist)
new = qfalse;
- if (!(self->monsterinfo.aiflags & AI_LOST_SIGHT))
- {
+ if (!(self->monsterinfo.aiflags & AI_LOST_SIGHT)) {
// just lost sight of the player, decide where to go first
// dprint("lost sight of player, last seen at "); dprint(vtos(self.last_sighting)); dprint("\n");
self->monsterinfo.aiflags |= (AI_LOST_SIGHT | AI_PURSUIT_LAST_SEEN);
@@ -999,35 +901,28 @@ void ai_run (edict_t *self, float dist)
new = qtrue;
}
- if (self->monsterinfo.aiflags & AI_PURSUE_NEXT)
- {
+ if (self->monsterinfo.aiflags & AI_PURSUE_NEXT) {
self->monsterinfo.aiflags &= ~AI_PURSUE_NEXT;
// dprint("reached current goal: "); dprint(vtos(self.origin)); dprint(" "); dprint(vtos(self.last_sighting)); dprint(" "); dprint(ftos(vlen(self.origin - self.last_sighting))); dprint("\n");
// give ourself more time since we got this far
self->monsterinfo.search_time = level.time + 5;
- if (self->monsterinfo.aiflags & AI_PURSUE_TEMP)
- {
+ if (self->monsterinfo.aiflags & AI_PURSUE_TEMP) {
// dprint("was temp goal; retrying original\n");
self->monsterinfo.aiflags &= ~AI_PURSUE_TEMP;
marker = NULL;
- VectorCopy (self->monsterinfo.saved_goal, self->monsterinfo.last_sighting);
+ VectorCopy(self->monsterinfo.saved_goal, self->monsterinfo.last_sighting);
new = qtrue;
- }
- else if (self->monsterinfo.aiflags & AI_PURSUIT_LAST_SEEN)
- {
+ } else if (self->monsterinfo.aiflags & AI_PURSUIT_LAST_SEEN) {
self->monsterinfo.aiflags &= ~AI_PURSUIT_LAST_SEEN;
- marker = PlayerTrail_PickFirst (self);
- }
- else
- {
- marker = PlayerTrail_PickNext (self);
+ marker = PlayerTrail_PickFirst(self);
+ } else {
+ marker = PlayerTrail_PickNext(self);
}
- if (marker)
- {
- VectorCopy (marker->s.origin, self->monsterinfo.last_sighting);
+ if (marker) {
+ VectorCopy(marker->s.origin, self->monsterinfo.last_sighting);
self->monsterinfo.trail_time = marker->timestamp;
self->s.angles[YAW] = self->ideal_yaw = marker->s.angles[YAW];
// dprint("heading is "); dprint(ftos(self.ideal_yaw)); dprint("\n");
@@ -1037,71 +932,63 @@ void ai_run (edict_t *self, float dist)
}
}
- VectorSubtract (self->s.origin, self->monsterinfo.last_sighting, v);
+ VectorSubtract(self->s.origin, self->monsterinfo.last_sighting, v);
d1 = VectorLength(v);
- if (d1 <= dist)
- {
+ if (d1 <= dist) {
self->monsterinfo.aiflags |= AI_PURSUE_NEXT;
dist = d1;
}
- VectorCopy (self->monsterinfo.last_sighting, self->goalentity->s.origin);
+ VectorCopy(self->monsterinfo.last_sighting, self->goalentity->s.origin);
- if (new)
- {
+ if (new) {
// gi.dprintf("checking for course correction\n");
tr = gi.trace(self->s.origin, self->mins, self->maxs, self->monsterinfo.last_sighting, self, MASK_PLAYERSOLID);
- if (tr.fraction < 1)
- {
- VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
+ if (tr.fraction < 1) {
+ VectorSubtract(self->goalentity->s.origin, self->s.origin, v);
d1 = VectorLength(v);
center = tr.fraction;
- d2 = d1 * ((center+1)/2);
+ d2 = d1 * ((center + 1) / 2);
self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v);
AngleVectors(self->s.angles, v_forward, v_right, NULL);
VectorSet(v, d2, -16, 0);
- G_ProjectSource (self->s.origin, v, v_forward, v_right, left_target);
+ G_ProjectSource(self->s.origin, v, v_forward, v_right, left_target);
tr = gi.trace(self->s.origin, self->mins, self->maxs, left_target, self, MASK_PLAYERSOLID);
left = tr.fraction;
VectorSet(v, d2, 16, 0);
- G_ProjectSource (self->s.origin, v, v_forward, v_right, right_target);
+ G_ProjectSource(self->s.origin, v, v_forward, v_right, right_target);
tr = gi.trace(self->s.origin, self->mins, self->maxs, right_target, self, MASK_PLAYERSOLID);
right = tr.fraction;
- center = (d1*center)/d2;
- if (left >= center && left > right)
- {
- if (left < 1)
- {
+ center = (d1 * center) / d2;
+ if (left >= center && left > right) {
+ if (left < 1) {
VectorSet(v, d2 * left * 0.5, -16, 0);
- G_ProjectSource (self->s.origin, v, v_forward, v_right, left_target);
+ G_ProjectSource(self->s.origin, v, v_forward, v_right, left_target);
// gi.dprintf("incomplete path, go part way and adjust again\n");
}
- VectorCopy (self->monsterinfo.last_sighting, self->monsterinfo.saved_goal);
+ VectorCopy(self->monsterinfo.last_sighting, self->monsterinfo.saved_goal);
self->monsterinfo.aiflags |= AI_PURSUE_TEMP;
- VectorCopy (left_target, self->goalentity->s.origin);
- VectorCopy (left_target, self->monsterinfo.last_sighting);
- VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
+ VectorCopy(left_target, self->goalentity->s.origin);
+ VectorCopy(left_target, self->monsterinfo.last_sighting);
+ VectorSubtract(self->goalentity->s.origin, self->s.origin, v);
self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v);
// gi.dprintf("adjusted left\n");
// debug_drawline(self.origin, self.last_sighting, 152);
- }
- else if (right >= center && right > left)
- {
- if (right < 1)
- {
+ } else if (right >= center && right > left) {
+ if (right < 1) {
VectorSet(v, d2 * right * 0.5, 16, 0);
- G_ProjectSource (self->s.origin, v, v_forward, v_right, right_target);
+ G_ProjectSource(self->s.origin, v, v_forward, v_right, right_target);
// gi.dprintf("incomplete path, go part way and adjust again\n");
}
- VectorCopy (self->monsterinfo.last_sighting, self->monsterinfo.saved_goal);
+ VectorCopy(self->monsterinfo.last_sighting, self->monsterinfo.saved_goal);
self->monsterinfo.aiflags |= AI_PURSUE_TEMP;
- VectorCopy (right_target, self->goalentity->s.origin);
- VectorCopy (right_target, self->monsterinfo.last_sighting);
- VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
+ VectorCopy(right_target, self->goalentity->s.origin);
+ VectorCopy(right_target, self->monsterinfo.last_sighting);
+ VectorSubtract(self->goalentity->s.origin, self->s.origin, v);
self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v);
// gi.dprintf("adjusted right\n");
// debug_drawline(self.origin, self.last_sighting, 152);
@@ -1110,7 +997,7 @@ void ai_run (edict_t *self, float dist)
// else gi.dprintf("course was fine\n");
}
- M_MoveToGoal (self, dist);
+ M_MoveToGoal(self, dist);
G_FreeEdict(tempgoal);
diff --git a/src/baseq2/g_chase.c b/src/baseq2/g_chase.c
index 159c1c5..b77b621 100644
--- a/src/baseq2/g_chase.c
+++ b/src/baseq2/g_chase.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -51,7 +51,7 @@ void UpdateChaseCam(edict_t *ent)
VectorCopy(targ->client->v_angle, angles);
if (angles[PITCH] > 56)
angles[PITCH] = 56;
- AngleVectors (angles, forward, right, NULL);
+ AngleVectors(angles, forward, right, NULL);
VectorNormalize(forward);
VectorMA(ownerv, -30, forward, o);
@@ -91,7 +91,7 @@ void UpdateChaseCam(edict_t *ent)
ent->client->ps.pmove.pm_type = PM_FREEZE;
VectorCopy(goal, ent->s.origin);
- for (i=0 ; i<3 ; i++)
+ for (i = 0 ; i < 3 ; i++)
ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
if (targ->deadflag) {
diff --git a/src/baseq2/g_cmds.c b/src/baseq2/g_cmds.c
index 5bc5511..f0f333c 100644
--- a/src/baseq2/g_cmds.c
+++ b/src/baseq2/g_cmds.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "m_player.h"
-char *ClientTeam (edict_t *ent)
+char *ClientTeam(edict_t *ent)
{
char *p;
static char value[512];
@@ -31,13 +31,12 @@ char *ClientTeam (edict_t *ent)
if (!ent->client)
return value;
- strcpy(value, Info_ValueForKey (ent->client->pers.userinfo, "skin"));
+ strcpy(value, Info_ValueForKey(ent->client->pers.userinfo, "skin"));
p = strchr(value, '/');
if (!p)
return value;
- if ((int)(dmflags->value) & DF_MODELTEAMS)
- {
+ if ((int)(dmflags->value) & DF_MODELTEAMS) {
*p = 0;
return value;
}
@@ -46,7 +45,7 @@ char *ClientTeam (edict_t *ent)
return ++p;
}
-qboolean OnSameTeam (edict_t *ent1, edict_t *ent2)
+qboolean OnSameTeam(edict_t *ent1, edict_t *ent2)
{
char ent1Team [512];
char ent2Team [512];
@@ -54,8 +53,8 @@ qboolean OnSameTeam (edict_t *ent1, edict_t *ent2)
if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
return qfalse;
- strcpy (ent1Team, ClientTeam (ent1));
- strcpy (ent2Team, ClientTeam (ent2));
+ strcpy(ent1Team, ClientTeam(ent1));
+ strcpy(ent2Team, ClientTeam(ent2));
if (strcmp(ent1Team, ent2Team) == 0)
return qtrue;
@@ -63,7 +62,7 @@ qboolean OnSameTeam (edict_t *ent1, edict_t *ent2)
}
-void SelectNextItem (edict_t *ent, int itflags)
+void SelectNextItem(edict_t *ent, int itflags)
{
gclient_t *cl;
int i, index;
@@ -77,9 +76,8 @@ void SelectNextItem (edict_t *ent, int itflags)
}
// scan for the next valid one
- for (i=1 ; i<=MAX_ITEMS ; i++)
- {
- index = (cl->pers.selected_item + i)%MAX_ITEMS;
+ for (i = 1 ; i <= MAX_ITEMS ; i++) {
+ index = (cl->pers.selected_item + i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
continue;
it = &itemlist[index];
@@ -95,7 +93,7 @@ void SelectNextItem (edict_t *ent, int itflags)
cl->pers.selected_item = -1;
}
-void SelectPrevItem (edict_t *ent, int itflags)
+void SelectPrevItem(edict_t *ent, int itflags)
{
gclient_t *cl;
int i, index;
@@ -109,9 +107,8 @@ void SelectPrevItem (edict_t *ent, int itflags)
}
// scan for the next valid one
- for (i=1 ; i<=MAX_ITEMS ; i++)
- {
- index = (cl->pers.selected_item + MAX_ITEMS - i)%MAX_ITEMS;
+ for (i = 1 ; i <= MAX_ITEMS ; i++) {
+ index = (cl->pers.selected_item + MAX_ITEMS - i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
continue;
it = &itemlist[index];
@@ -127,7 +124,7 @@ void SelectPrevItem (edict_t *ent, int itflags)
cl->pers.selected_item = -1;
}
-void ValidateSelectedItem (edict_t *ent)
+void ValidateSelectedItem(edict_t *ent)
{
gclient_t *cl;
@@ -136,7 +133,7 @@ void ValidateSelectedItem (edict_t *ent)
if (cl->pers.inventory[cl->pers.selected_item])
return; // valid
- SelectNextItem (ent, -1);
+ SelectNextItem(ent, -1);
}
@@ -149,7 +146,7 @@ Cmd_Give_f
Give items to a client
==================
*/
-void Cmd_Give_f (edict_t *ent)
+void Cmd_Give_f(edict_t *ent)
{
char *name;
gitem_t *it;
@@ -158,9 +155,8 @@ void Cmd_Give_f (edict_t *ent)
qboolean give_all;
edict_t *it_ent;
- if (deathmatch->value && !sv_cheats->value)
- {
- gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ if (deathmatch->value && !sv_cheats->value) {
+ gi.cprintf(ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
@@ -171,8 +167,7 @@ void Cmd_Give_f (edict_t *ent)
else
give_all = qfalse;
- if (give_all || Q_stricmp(gi.argv(1), "health") == 0)
- {
+ if (give_all || Q_stricmp(gi.argv(1), "health") == 0) {
if (gi.argc() == 3)
ent->health = atoi(gi.argv(2));
else
@@ -181,10 +176,8 @@ void Cmd_Give_f (edict_t *ent)
return;
}
- if (give_all || Q_stricmp(name, "weapons") == 0)
- {
- for (i=0 ; i<game.num_items ; i++)
- {
+ if (give_all || Q_stricmp(name, "weapons") == 0) {
+ for (i = 0 ; i < game.num_items ; i++) {
it = itemlist + i;
if (!it->pickup)
continue;
@@ -196,23 +189,20 @@ void Cmd_Give_f (edict_t *ent)
return;
}
- if (give_all || Q_stricmp(name, "ammo") == 0)
- {
- for (i=0 ; i<game.num_items ; i++)
- {
+ if (give_all || Q_stricmp(name, "ammo") == 0) {
+ for (i = 0 ; i < game.num_items ; i++) {
it = itemlist + i;
if (!it->pickup)
continue;
if (!(it->flags & IT_AMMO))
continue;
- Add_Ammo (ent, it, 1000);
+ Add_Ammo(ent, it, 1000);
}
if (!give_all)
return;
}
- if (give_all || Q_stricmp(name, "armor") == 0)
- {
+ if (give_all || Q_stricmp(name, "armor") == 0) {
gitem_armor_t *info;
it = FindItem("Jacket Armor");
@@ -229,13 +219,12 @@ void Cmd_Give_f (edict_t *ent)
return;
}
- if (give_all || Q_stricmp(name, "Power Shield") == 0)
- {
+ if (give_all || Q_stricmp(name, "Power Shield") == 0) {
it = FindItem("Power Shield");
it_ent = G_Spawn();
it_ent->classname = it->classname;
- SpawnItem (it_ent, it);
- Touch_Item (it_ent, ent, NULL, NULL);
+ SpawnItem(it_ent, it);
+ Touch_Item(it_ent, ent, NULL, NULL);
if (it_ent->inuse)
G_FreeEdict(it_ent);
@@ -243,53 +232,45 @@ void Cmd_Give_f (edict_t *ent)
return;
}
- if (give_all)
- {
- for (i=0 ; i<game.num_items ; i++)
- {
+ if (give_all) {
+ for (i = 0 ; i < game.num_items ; i++) {
it = itemlist + i;
if (!it->pickup)
continue;
- if (it->flags & (IT_ARMOR|IT_WEAPON|IT_AMMO))
+ if (it->flags & (IT_ARMOR | IT_WEAPON | IT_AMMO))
continue;
ent->client->pers.inventory[i] = 1;
}
return;
}
- it = FindItem (name);
- if (!it)
- {
+ it = FindItem(name);
+ if (!it) {
name = gi.argv(1);
- it = FindItem (name);
- if (!it)
- {
- gi.cprintf (ent, PRINT_HIGH, "unknown item\n");
+ it = FindItem(name);
+ if (!it) {
+ gi.cprintf(ent, PRINT_HIGH, "unknown item\n");
return;
}
}
- if (!it->pickup)
- {
- gi.cprintf (ent, PRINT_HIGH, "non-pickup item\n");
+ if (!it->pickup) {
+ gi.cprintf(ent, PRINT_HIGH, "non-pickup item\n");
return;
}
index = ITEM_INDEX(it);
- if (it->flags & IT_AMMO)
- {
+ if (it->flags & IT_AMMO) {
if (gi.argc() == 3)
ent->client->pers.inventory[index] = atoi(gi.argv(2));
else
ent->client->pers.inventory[index] += it->quantity;
- }
- else
- {
+ } else {
it_ent = G_Spawn();
it_ent->classname = it->classname;
- SpawnItem (it_ent, it);
- Touch_Item (it_ent, ent, NULL, NULL);
+ SpawnItem(it_ent, it);
+ Touch_Item(it_ent, ent, NULL, NULL);
if (it_ent->inuse)
G_FreeEdict(it_ent);
}
@@ -305,23 +286,22 @@ Sets client to godmode
argv(0) god
==================
*/
-void Cmd_God_f (edict_t *ent)
+void Cmd_God_f(edict_t *ent)
{
char *msg;
- if (deathmatch->value && !sv_cheats->value)
- {
- gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ if (deathmatch->value && !sv_cheats->value) {
+ gi.cprintf(ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
ent->flags ^= FL_GODMODE;
- if (!(ent->flags & FL_GODMODE) )
+ if (!(ent->flags & FL_GODMODE))
msg = "godmode OFF\n";
else
msg = "godmode ON\n";
- gi.cprintf (ent, PRINT_HIGH, msg);
+ gi.cprintf(ent, PRINT_HIGH, msg);
}
@@ -334,23 +314,22 @@ Sets client to notarget
argv(0) notarget
==================
*/
-void Cmd_Notarget_f (edict_t *ent)
+void Cmd_Notarget_f(edict_t *ent)
{
char *msg;
- if (deathmatch->value && !sv_cheats->value)
- {
- gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ if (deathmatch->value && !sv_cheats->value) {
+ gi.cprintf(ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
ent->flags ^= FL_NOTARGET;
- if (!(ent->flags & FL_NOTARGET) )
+ if (!(ent->flags & FL_NOTARGET))
msg = "notarget OFF\n";
else
msg = "notarget ON\n";
- gi.cprintf (ent, PRINT_HIGH, msg);
+ gi.cprintf(ent, PRINT_HIGH, msg);
}
@@ -361,28 +340,24 @@ Cmd_Noclip_f
argv(0) noclip
==================
*/
-void Cmd_Noclip_f (edict_t *ent)
+void Cmd_Noclip_f(edict_t *ent)
{
char *msg;
- if (deathmatch->value && !sv_cheats->value)
- {
- gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ if (deathmatch->value && !sv_cheats->value) {
+ gi.cprintf(ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
- if (ent->movetype == MOVETYPE_NOCLIP)
- {
+ if (ent->movetype == MOVETYPE_NOCLIP) {
ent->movetype = MOVETYPE_WALK;
msg = "noclip OFF\n";
- }
- else
- {
+ } else {
ent->movetype = MOVETYPE_NOCLIP;
msg = "noclip ON\n";
}
- gi.cprintf (ent, PRINT_HIGH, msg);
+ gi.cprintf(ent, PRINT_HIGH, msg);
}
@@ -393,32 +368,29 @@ Cmd_Use_f
Use an inventory item
==================
*/
-void Cmd_Use_f (edict_t *ent)
+void Cmd_Use_f(edict_t *ent)
{
int index;
gitem_t *it;
char *s;
s = gi.args();
- it = FindItem (s);
- if (!it)
- {
- gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
+ it = FindItem(s);
+ if (!it) {
+ gi.cprintf(ent, PRINT_HIGH, "unknown item: %s\n", s);
return;
}
- if (!it->use)
- {
- gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
+ if (!it->use) {
+ gi.cprintf(ent, PRINT_HIGH, "Item is not usable.\n");
return;
}
index = ITEM_INDEX(it);
- if (!ent->client->pers.inventory[index])
- {
- gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
+ if (!ent->client->pers.inventory[index]) {
+ gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", s);
return;
}
- it->use (ent, it);
+ it->use(ent, it);
}
@@ -429,32 +401,29 @@ Cmd_Drop_f
Drop an inventory item
==================
*/
-void Cmd_Drop_f (edict_t *ent)
+void Cmd_Drop_f(edict_t *ent)
{
int index;
gitem_t *it;
char *s;
s = gi.args();
- it = FindItem (s);
- if (!it)
- {
- gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
+ it = FindItem(s);
+ if (!it) {
+ gi.cprintf(ent, PRINT_HIGH, "unknown item: %s\n", s);
return;
}
- if (!it->drop)
- {
- gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
+ if (!it->drop) {
+ gi.cprintf(ent, PRINT_HIGH, "Item is not dropable.\n");
return;
}
index = ITEM_INDEX(it);
- if (!ent->client->pers.inventory[index])
- {
- gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
+ if (!ent->client->pers.inventory[index]) {
+ gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", s);
return;
}
- it->drop (ent, it);
+ it->drop(ent, it);
}
@@ -463,7 +432,7 @@ void Cmd_Drop_f (edict_t *ent)
Cmd_Inven_f
=================
*/
-void Cmd_Inven_f (edict_t *ent)
+void Cmd_Inven_f(edict_t *ent)
{
int i;
gclient_t *cl;
@@ -473,20 +442,18 @@ void Cmd_Inven_f (edict_t *ent)
cl->showscores = qfalse;
cl->showhelp = qfalse;
- if (cl->showinventory)
- {
+ if (cl->showinventory) {
cl->showinventory = qfalse;
return;
}
cl->showinventory = qtrue;
- gi.WriteByte (svc_inventory);
- for (i=0 ; i<MAX_ITEMS ; i++)
- {
- gi.WriteShort (cl->pers.inventory[i]);
+ gi.WriteByte(svc_inventory);
+ for (i = 0 ; i < MAX_ITEMS ; i++) {
+ gi.WriteShort(cl->pers.inventory[i]);
}
- gi.unicast (ent, qtrue);
+ gi.unicast(ent, qtrue);
}
/*
@@ -494,25 +461,23 @@ void Cmd_Inven_f (edict_t *ent)
Cmd_InvUse_f
=================
*/
-void Cmd_InvUse_f (edict_t *ent)
+void Cmd_InvUse_f(edict_t *ent)
{
gitem_t *it;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
- if (ent->client->pers.selected_item == -1)
- {
- gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");
+ if (ent->client->pers.selected_item == -1) {
+ gi.cprintf(ent, PRINT_HIGH, "No item to use.\n");
return;
}
it = &itemlist[ent->client->pers.selected_item];
- if (!it->use)
- {
- gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
+ if (!it->use) {
+ gi.cprintf(ent, PRINT_HIGH, "Item is not usable.\n");
return;
}
- it->use (ent, it);
+ it->use(ent, it);
}
/*
@@ -520,7 +485,7 @@ void Cmd_InvUse_f (edict_t *ent)
Cmd_WeapPrev_f
=================
*/
-void Cmd_WeapPrev_f (edict_t *ent)
+void Cmd_WeapPrev_f(edict_t *ent)
{
gclient_t *cl;
int i, index;
@@ -535,17 +500,16 @@ void Cmd_WeapPrev_f (edict_t *ent)
selected_weapon = ITEM_INDEX(cl->pers.weapon);
// scan for the next valid one
- for (i=1 ; i<=MAX_ITEMS ; i++)
- {
- index = (selected_weapon + i)%MAX_ITEMS;
+ for (i = 1 ; i <= MAX_ITEMS ; i++) {
+ index = (selected_weapon + i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
continue;
it = &itemlist[index];
if (!it->use)
continue;
- if (! (it->flags & IT_WEAPON) )
+ if (!(it->flags & IT_WEAPON))
continue;
- it->use (ent, it);
+ it->use(ent, it);
if (cl->pers.weapon == it)
return; // successful
}
@@ -556,7 +520,7 @@ void Cmd_WeapPrev_f (edict_t *ent)
Cmd_WeapNext_f
=================
*/
-void Cmd_WeapNext_f (edict_t *ent)
+void Cmd_WeapNext_f(edict_t *ent)
{
gclient_t *cl;
int i, index;
@@ -571,17 +535,16 @@ void Cmd_WeapNext_f (edict_t *ent)
selected_weapon = ITEM_INDEX(cl->pers.weapon);
// scan for the next valid one
- for (i=1 ; i<=MAX_ITEMS ; i++)
- {
- index = (selected_weapon + MAX_ITEMS - i)%MAX_ITEMS;
+ for (i = 1 ; i <= MAX_ITEMS ; i++) {
+ index = (selected_weapon + MAX_ITEMS - i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
continue;
it = &itemlist[index];
if (!it->use)
continue;
- if (! (it->flags & IT_WEAPON) )
+ if (!(it->flags & IT_WEAPON))
continue;
- it->use (ent, it);
+ it->use(ent, it);
if (cl->pers.weapon == it)
return; // successful
}
@@ -592,7 +555,7 @@ void Cmd_WeapNext_f (edict_t *ent)
Cmd_WeapLast_f
=================
*/
-void Cmd_WeapLast_f (edict_t *ent)
+void Cmd_WeapLast_f(edict_t *ent)
{
gclient_t *cl;
int index;
@@ -609,9 +572,9 @@ void Cmd_WeapLast_f (edict_t *ent)
it = &itemlist[index];
if (!it->use)
return;
- if (! (it->flags & IT_WEAPON) )
+ if (!(it->flags & IT_WEAPON))
return;
- it->use (ent, it);
+ it->use(ent, it);
}
/*
@@ -619,25 +582,23 @@ void Cmd_WeapLast_f (edict_t *ent)
Cmd_InvDrop_f
=================
*/
-void Cmd_InvDrop_f (edict_t *ent)
+void Cmd_InvDrop_f(edict_t *ent)
{
gitem_t *it;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
- if (ent->client->pers.selected_item == -1)
- {
- gi.cprintf (ent, PRINT_HIGH, "No item to drop.\n");
+ if (ent->client->pers.selected_item == -1) {
+ gi.cprintf(ent, PRINT_HIGH, "No item to drop.\n");
return;
}
it = &itemlist[ent->client->pers.selected_item];
- if (!it->drop)
- {
- gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
+ if (!it->drop) {
+ gi.cprintf(ent, PRINT_HIGH, "Item is not dropable.\n");
return;
}
- it->drop (ent, it);
+ it->drop(ent, it);
}
/*
@@ -645,14 +606,14 @@ void Cmd_InvDrop_f (edict_t *ent)
Cmd_Kill_f
=================
*/
-void Cmd_Kill_f (edict_t *ent)
+void Cmd_Kill_f(edict_t *ent)
{
- if((level.time - ent->client->respawn_time) < 5)
+ if ((level.time - ent->client->respawn_time) < 5)
return;
ent->flags &= ~FL_GODMODE;
ent->health = 0;
meansOfDeath = MOD_SUICIDE;
- player_die (ent, ent, ent, 100000, vec3_origin);
+ player_die(ent, ent, ent, 100000, vec3_origin);
}
/*
@@ -660,7 +621,7 @@ void Cmd_Kill_f (edict_t *ent)
Cmd_PutAway_f
=================
*/
-void Cmd_PutAway_f (edict_t *ent)
+void Cmd_PutAway_f(edict_t *ent)
{
ent->client->showscores = qfalse;
ent->client->showhelp = qfalse;
@@ -668,7 +629,7 @@ void Cmd_PutAway_f (edict_t *ent)
}
-int PlayerSort (void const *a, void const *b)
+int PlayerSort(void const *a, void const *b)
{
int anum, bnum;
@@ -690,7 +651,7 @@ int PlayerSort (void const *a, void const *b)
Cmd_Players_f
=================
*/
-void Cmd_Players_f (edict_t *ent)
+void Cmd_Players_f(edict_t *ent)
{
int i;
int count;
@@ -700,32 +661,30 @@ void Cmd_Players_f (edict_t *ent)
count = 0;
for (i = 0 ; i < maxclients->value ; i++)
- if (game.clients[i].pers.connected)
- {
+ if (game.clients[i].pers.connected) {
index[count] = i;
count++;
}
// sort by frags
- qsort (index, count, sizeof(index[0]), PlayerSort);
+ qsort(index, count, sizeof(index[0]), PlayerSort);
// print information
large[0] = 0;
- for (i = 0 ; i < count ; i++)
- {
- Q_snprintf (small, sizeof(small), "%3i %s\n",
- game.clients[index[i]].ps.stats[STAT_FRAGS],
- game.clients[index[i]].pers.netname);
- if (strlen (small) + strlen(large) > sizeof(large) - 100 )
- { // can't print all of them in one packet
- strcat (large, "...\n");
+ for (i = 0 ; i < count ; i++) {
+ Q_snprintf(small, sizeof(small), "%3i %s\n",
+ game.clients[index[i]].ps.stats[STAT_FRAGS],
+ game.clients[index[i]].pers.netname);
+ if (strlen(small) + strlen(large) > sizeof(large) - 100) {
+ // can't print all of them in one packet
+ strcat(large, "...\n");
break;
}
- strcat (large, small);
+ strcat(large, small);
}
- gi.cprintf (ent, PRINT_HIGH, "%s\n%i players\n", large, count);
+ gi.cprintf(ent, PRINT_HIGH, "%s\n%i players\n", large, count);
}
/*
@@ -733,11 +692,11 @@ void Cmd_Players_f (edict_t *ent)
Cmd_Wave_f
=================
*/
-void Cmd_Wave_f (edict_t *ent)
+void Cmd_Wave_f(edict_t *ent)
{
int i;
- i = atoi (gi.argv(1));
+ i = atoi(gi.argv(1));
// can't wave when ducked
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
@@ -748,32 +707,31 @@ void Cmd_Wave_f (edict_t *ent)
ent->client->anim_priority = ANIM_WAVE;
- switch (i)
- {
+ switch (i) {
case 0:
- gi.cprintf (ent, PRINT_HIGH, "flipoff\n");
- ent->s.frame = FRAME_flip01-1;
+ gi.cprintf(ent, PRINT_HIGH, "flipoff\n");
+ ent->s.frame = FRAME_flip01 - 1;
ent->client->anim_end = FRAME_flip12;
break;
case 1:
- gi.cprintf (ent, PRINT_HIGH, "salute\n");
- ent->s.frame = FRAME_salute01-1;
+ gi.cprintf(ent, PRINT_HIGH, "salute\n");
+ ent->s.frame = FRAME_salute01 - 1;
ent->client->anim_end = FRAME_salute11;
break;
case 2:
- gi.cprintf (ent, PRINT_HIGH, "taunt\n");
- ent->s.frame = FRAME_taunt01-1;
+ gi.cprintf(ent, PRINT_HIGH, "taunt\n");
+ ent->s.frame = FRAME_taunt01 - 1;
ent->client->anim_end = FRAME_taunt17;
break;
case 3:
- gi.cprintf (ent, PRINT_HIGH, "wave\n");
- ent->s.frame = FRAME_wave01-1;
+ gi.cprintf(ent, PRINT_HIGH, "wave\n");
+ ent->s.frame = FRAME_wave01 - 1;
ent->client->anim_end = FRAME_wave11;
break;
case 4:
default:
- gi.cprintf (ent, PRINT_HIGH, "point\n");
- ent->s.frame = FRAME_point01-1;
+ gi.cprintf(ent, PRINT_HIGH, "point\n");
+ ent->s.frame = FRAME_point01 - 1;
ent->client->anim_end = FRAME_point12;
break;
}
@@ -784,7 +742,7 @@ void Cmd_Wave_f (edict_t *ent)
Cmd_Say_f
==================
*/
-void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
+void Cmd_Say_f(edict_t *ent, qboolean team, qboolean arg0)
{
int i, j;
edict_t *other;
@@ -792,31 +750,27 @@ void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
char text[2048];
gclient_t *cl;
- if (gi.argc () < 2 && !arg0)
+ if (gi.argc() < 2 && !arg0)
return;
if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
team = qfalse;
if (team)
- Q_snprintf (text, sizeof(text), "(%s): ", ent->client->pers.netname);
+ Q_snprintf(text, sizeof(text), "(%s): ", ent->client->pers.netname);
else
- Q_snprintf (text, sizeof(text), "%s: ", ent->client->pers.netname);
+ Q_snprintf(text, sizeof(text), "%s: ", ent->client->pers.netname);
- if (arg0)
- {
- strcat (text, gi.argv(0));
- strcat (text, " ");
- strcat (text, gi.args());
- }
- else
- {
+ if (arg0) {
+ strcat(text, gi.argv(0));
+ strcat(text, " ");
+ strcat(text, gi.args());
+ } else {
p = gi.args();
- if (*p == '"')
- {
+ if (*p == '"') {
p++;
- p[strlen(p)-1] = 0;
+ p[strlen(p) - 1] = 0;
}
strcat(text, p);
}
@@ -832,36 +786,34 @@ void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
if (level.time < cl->flood_locktill) {
gi.cprintf(ent, PRINT_HIGH, "You can't talk for %d more seconds\n",
- (int)(cl->flood_locktill - level.time));
+ (int)(cl->flood_locktill - level.time));
return;
}
i = cl->flood_whenhead - flood_msgs->value + 1;
if (i < 0)
- i = (sizeof(cl->flood_when)/sizeof(cl->flood_when[0])) + i;
- if (cl->flood_when[i] &&
+ i = (sizeof(cl->flood_when) / sizeof(cl->flood_when[0])) + i;
+ if (cl->flood_when[i] &&
level.time - cl->flood_when[i] < flood_persecond->value) {
cl->flood_locktill = level.time + flood_waitdelay->value;
gi.cprintf(ent, PRINT_CHAT, "Flood protection: You can't talk for %d seconds.\n",
- (int)flood_waitdelay->value);
+ (int)flood_waitdelay->value);
return;
}
cl->flood_whenhead = (cl->flood_whenhead + 1) %
- (sizeof(cl->flood_when)/sizeof(cl->flood_when[0]));
+ (sizeof(cl->flood_when) / sizeof(cl->flood_when[0]));
cl->flood_when[cl->flood_whenhead] = level.time;
}
if (dedicated->value)
gi.cprintf(NULL, PRINT_CHAT, "%s", text);
- for (j = 1; j <= game.maxclients; j++)
- {
+ for (j = 1; j <= game.maxclients; j++) {
other = &g_edicts[j];
if (!other->inuse)
continue;
if (!other->client)
continue;
- if (team)
- {
+ if (team) {
if (!OnSameTeam(ent, other))
continue;
}
@@ -883,14 +835,14 @@ void Cmd_PlayerList_f(edict_t *ent)
continue;
Q_snprintf(st, sizeof(st), "%02d:%02d %4d %3d %s%s\n",
- (level.framenum - e2->client->resp.enterframe) / 600,
- ((level.framenum - e2->client->resp.enterframe) % 600)/10,
- e2->client->ping,
- e2->client->resp.score,
- e2->client->pers.netname,
- e2->client->resp.spectator ? " (spectator)" : "");
+ (level.framenum - e2->client->resp.enterframe) / 600,
+ ((level.framenum - e2->client->resp.enterframe) % 600) / 10,
+ e2->client->ping,
+ e2->client->resp.score,
+ e2->client->pers.netname,
+ e2->client->resp.spectator ? " (spectator)" : "");
if (strlen(text) + strlen(st) > sizeof(text) - 50) {
- sprintf(text+strlen(text), "And more...\n");
+ sprintf(text + strlen(text), "And more...\n");
gi.cprintf(ent, PRINT_HIGH, "%s", text);
return;
}
@@ -905,7 +857,7 @@ void Cmd_PlayerList_f(edict_t *ent)
ClientCommand
=================
*/
-void ClientCommand (edict_t *ent)
+void ClientCommand(edict_t *ent)
{
char *cmd;
@@ -914,79 +866,74 @@ void ClientCommand (edict_t *ent)
cmd = gi.argv(0);
- if (Q_stricmp (cmd, "players") == 0)
- {
- Cmd_Players_f (ent);
+ if (Q_stricmp(cmd, "players") == 0) {
+ Cmd_Players_f(ent);
return;
}
- if (Q_stricmp (cmd, "say") == 0)
- {
- Cmd_Say_f (ent, qfalse, qfalse);
+ if (Q_stricmp(cmd, "say") == 0) {
+ Cmd_Say_f(ent, qfalse, qfalse);
return;
}
- if (Q_stricmp (cmd, "say_team") == 0)
- {
- Cmd_Say_f (ent, qtrue, qfalse);
+ if (Q_stricmp(cmd, "say_team") == 0) {
+ Cmd_Say_f(ent, qtrue, qfalse);
return;
}
- if (Q_stricmp (cmd, "score") == 0)
- {
- Cmd_Score_f (ent);
+ if (Q_stricmp(cmd, "score") == 0) {
+ Cmd_Score_f(ent);
return;
}
- if (Q_stricmp (cmd, "help") == 0)
- {
- Cmd_Help_f (ent);
+ if (Q_stricmp(cmd, "help") == 0) {
+ Cmd_Help_f(ent);
return;
}
if (level.intermissiontime)
return;
- if (Q_stricmp (cmd, "use") == 0)
- Cmd_Use_f (ent);
- else if (Q_stricmp (cmd, "drop") == 0)
- Cmd_Drop_f (ent);
- else if (Q_stricmp (cmd, "give") == 0)
- Cmd_Give_f (ent);
- else if (Q_stricmp (cmd, "god") == 0)
- Cmd_God_f (ent);
- else if (Q_stricmp (cmd, "notarget") == 0)
- Cmd_Notarget_f (ent);
- else if (Q_stricmp (cmd, "noclip") == 0)
- Cmd_Noclip_f (ent);
- else if (Q_stricmp (cmd, "inven") == 0)
- Cmd_Inven_f (ent);
- else if (Q_stricmp (cmd, "invnext") == 0)
- SelectNextItem (ent, -1);
- else if (Q_stricmp (cmd, "invprev") == 0)
- SelectPrevItem (ent, -1);
- else if (Q_stricmp (cmd, "invnextw") == 0)
- SelectNextItem (ent, IT_WEAPON);
- else if (Q_stricmp (cmd, "invprevw") == 0)
- SelectPrevItem (ent, IT_WEAPON);
- else if (Q_stricmp (cmd, "invnextp") == 0)
- SelectNextItem (ent, IT_POWERUP);
- else if (Q_stricmp (cmd, "invprevp") == 0)
- SelectPrevItem (ent, IT_POWERUP);
- else if (Q_stricmp (cmd, "invuse") == 0)
- Cmd_InvUse_f (ent);
- else if (Q_stricmp (cmd, "invdrop") == 0)
- Cmd_InvDrop_f (ent);
- else if (Q_stricmp (cmd, "weapprev") == 0)
- Cmd_WeapPrev_f (ent);
- else if (Q_stricmp (cmd, "weapnext") == 0)
- Cmd_WeapNext_f (ent);
- else if (Q_stricmp (cmd, "weaplast") == 0)
- Cmd_WeapLast_f (ent);
- else if (Q_stricmp (cmd, "kill") == 0)
- Cmd_Kill_f (ent);
- else if (Q_stricmp (cmd, "putaway") == 0)
- Cmd_PutAway_f (ent);
- else if (Q_stricmp (cmd, "wave") == 0)
- Cmd_Wave_f (ent);
+ if (Q_stricmp(cmd, "use") == 0)
+ Cmd_Use_f(ent);
+ else if (Q_stricmp(cmd, "drop") == 0)
+ Cmd_Drop_f(ent);
+ else if (Q_stricmp(cmd, "give") == 0)
+ Cmd_Give_f(ent);
+ else if (Q_stricmp(cmd, "god") == 0)
+ Cmd_God_f(ent);
+ else if (Q_stricmp(cmd, "notarget") == 0)
+ Cmd_Notarget_f(ent);
+ else if (Q_stricmp(cmd, "noclip") == 0)
+ Cmd_Noclip_f(ent);
+ else if (Q_stricmp(cmd, "inven") == 0)
+ Cmd_Inven_f(ent);
+ else if (Q_stricmp(cmd, "invnext") == 0)
+ SelectNextItem(ent, -1);
+ else if (Q_stricmp(cmd, "invprev") == 0)
+ SelectPrevItem(ent, -1);
+ else if (Q_stricmp(cmd, "invnextw") == 0)
+ SelectNextItem(ent, IT_WEAPON);
+ else if (Q_stricmp(cmd, "invprevw") == 0)
+ SelectPrevItem(ent, IT_WEAPON);
+ else if (Q_stricmp(cmd, "invnextp") == 0)
+ SelectNextItem(ent, IT_POWERUP);
+ else if (Q_stricmp(cmd, "invprevp") == 0)
+ SelectPrevItem(ent, IT_POWERUP);
+ else if (Q_stricmp(cmd, "invuse") == 0)
+ Cmd_InvUse_f(ent);
+ else if (Q_stricmp(cmd, "invdrop") == 0)
+ Cmd_InvDrop_f(ent);
+ else if (Q_stricmp(cmd, "weapprev") == 0)
+ Cmd_WeapPrev_f(ent);
+ else if (Q_stricmp(cmd, "weapnext") == 0)
+ Cmd_WeapNext_f(ent);
+ else if (Q_stricmp(cmd, "weaplast") == 0)
+ Cmd_WeapLast_f(ent);
+ else if (Q_stricmp(cmd, "kill") == 0)
+ Cmd_Kill_f(ent);
+ else if (Q_stricmp(cmd, "putaway") == 0)
+ Cmd_PutAway_f(ent);
+ else if (Q_stricmp(cmd, "wave") == 0)
+ Cmd_Wave_f(ent);
else if (Q_stricmp(cmd, "playerlist") == 0)
Cmd_PlayerList_f(ent);
else // anything that doesn't match a command will be a chat
- Cmd_Say_f (ent, qfalse, qtrue);
+ Cmd_Say_f(ent, qfalse, qtrue);
}
diff --git a/src/baseq2/g_combat.c b/src/baseq2/g_combat.c
index 4675356..1625c64 100644
--- a/src/baseq2/g_combat.c
+++ b/src/baseq2/g_combat.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,53 +29,52 @@ Returns qtrue if the inflictor can directly damage the target. Used for
explosions and melee attacks.
============
*/
-qboolean CanDamage (edict_t *targ, edict_t *inflictor)
+qboolean CanDamage(edict_t *targ, edict_t *inflictor)
{
vec3_t dest;
trace_t trace;
// bmodels need special checking because their origin is 0,0,0
- if (targ->movetype == MOVETYPE_PUSH)
- {
- VectorAdd (targ->absmin, targ->absmax, dest);
- VectorScale (dest, 0.5, dest);
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
+ if (targ->movetype == MOVETYPE_PUSH) {
+ VectorAdd(targ->absmin, targ->absmax, dest);
+ VectorScale(dest, 0.5, dest);
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
if (trace.ent == targ)
return qtrue;
return qfalse;
}
-
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, targ->s.origin, inflictor, MASK_SOLID);
+
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, targ->s.origin, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
- VectorCopy (targ->s.origin, dest);
+ VectorCopy(targ->s.origin, dest);
dest[0] += 15.0;
dest[1] += 15.0;
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
- VectorCopy (targ->s.origin, dest);
+ VectorCopy(targ->s.origin, dest);
dest[0] += 15.0;
dest[1] -= 15.0;
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
- VectorCopy (targ->s.origin, dest);
+ VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] += 15.0;
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
- VectorCopy (targ->s.origin, dest);
+ VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] -= 15.0;
- trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
+ trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return qtrue;
@@ -89,18 +88,16 @@ qboolean CanDamage (edict_t *targ, edict_t *inflictor)
Killed
============
*/
-void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void Killed(edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
if (targ->health < -999)
targ->health = -999;
targ->enemy = attacker;
- if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD))
- {
+ if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD)) {
// targ->svflags |= SVF_DEADMONSTER; // now treat as a different content type
- if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY))
- {
+ if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY)) {
level.killed_monsters++;
if (coop->value && attacker->client)
attacker->client->resp.score++;
@@ -110,19 +107,18 @@ void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, v
}
}
- if (targ->movetype == MOVETYPE_PUSH || targ->movetype == MOVETYPE_STOP || targ->movetype == MOVETYPE_NONE)
- { // doors, triggers, etc
- targ->die (targ, inflictor, attacker, damage, point);
+ if (targ->movetype == MOVETYPE_PUSH || targ->movetype == MOVETYPE_STOP || targ->movetype == MOVETYPE_NONE) {
+ // doors, triggers, etc
+ targ->die(targ, inflictor, attacker, damage, point);
return;
}
- if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD))
- {
+ if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD)) {
targ->touch = NULL;
- monster_death_use (targ);
+ monster_death_use(targ);
}
- targ->die (targ, inflictor, attacker, damage, point);
+ targ->die(targ, inflictor, attacker, damage, point);
}
@@ -131,16 +127,16 @@ void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, v
SpawnDamage
================
*/
-void SpawnDamage (int type, vec3_t origin, vec3_t normal, int damage)
+void SpawnDamage(int type, vec3_t origin, vec3_t normal, int damage)
{
if (damage > 255)
damage = 255;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (type);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(type);
// gi.WriteByte (damage);
- gi.WritePosition (origin);
- gi.WriteDir (normal);
- gi.multicast (origin, MULTICAST_PVS);
+ gi.WritePosition(origin);
+ gi.WriteDir(normal);
+ gi.multicast(origin, MULTICAST_PVS);
}
@@ -168,7 +164,7 @@ dflags these flags are used to control how T_Damage works
DAMAGE_NO_PROTECTION kills godmode, armor, everything
============
*/
-static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int dflags)
+static int CheckPowerArmor(edict_t *ent, vec3_t point, vec3_t normal, int damage, int dflags)
{
gclient_t *client;
int save;
@@ -187,21 +183,16 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
if (dflags & DAMAGE_NO_ARMOR)
return 0;
- if (client)
- {
- power_armor_type = PowerArmorType (ent);
- if (power_armor_type != POWER_ARMOR_NONE)
- {
+ if (client) {
+ power_armor_type = PowerArmorType(ent);
+ if (power_armor_type != POWER_ARMOR_NONE) {
index = ITEM_INDEX(FindItem("Cells"));
power = client->pers.inventory[index];
}
- }
- else if (ent->svflags & SVF_MONSTER)
- {
+ } else if (ent->svflags & SVF_MONSTER) {
power_armor_type = ent->monsterinfo.power_armor_type;
power = ent->monsterinfo.power_armor_power;
- }
- else
+ } else
return 0;
if (power_armor_type == POWER_ARMOR_NONE)
@@ -209,26 +200,23 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
if (!power)
return 0;
- if (power_armor_type == POWER_ARMOR_SCREEN)
- {
+ if (power_armor_type == POWER_ARMOR_SCREEN) {
vec3_t vec;
float dot;
vec3_t forward;
// only works if damage point is in front
- AngleVectors (ent->s.angles, forward, NULL, NULL);
- VectorSubtract (point, ent->s.origin, vec);
- VectorNormalize (vec);
- dot = DotProduct (vec, forward);
+ AngleVectors(ent->s.angles, forward, NULL, NULL);
+ VectorSubtract(point, ent->s.origin, vec);
+ VectorNormalize(vec);
+ dot = DotProduct(vec, forward);
if (dot <= 0.3)
return 0;
damagePerCell = 1;
pa_te_type = TE_SCREEN_SPARKS;
damage = damage / 3;
- }
- else
- {
+ } else {
damagePerCell = 2;
pa_te_type = TE_SHIELD_SPARKS;
damage = (2 * damage) / 3;
@@ -240,7 +228,7 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
if (save > damage)
save = damage;
- SpawnDamage (pa_te_type, point, normal, save);
+ SpawnDamage(pa_te_type, point, normal, save);
ent->powerarmor_time = level.time + 0.2;
power_used = save / damagePerCell;
@@ -252,7 +240,7 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
return save;
}
-static int CheckArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int te_sparks, int dflags)
+static int CheckArmor(edict_t *ent, vec3_t point, vec3_t normal, int damage, int te_sparks, int dflags)
{
gclient_t *client;
int save;
@@ -270,16 +258,16 @@ static int CheckArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, in
if (dflags & DAMAGE_NO_ARMOR)
return 0;
- index = ArmorIndex (ent);
+ index = ArmorIndex(ent);
if (!index)
return 0;
- armor = GetItemByIndex (index);
+ armor = GetItemByIndex(index);
if (dflags & DAMAGE_ENERGY)
- save = ceil(((gitem_armor_t *)armor->info)->energy_protection*damage);
+ save = ceil(((gitem_armor_t *)armor->info)->energy_protection * damage);
else
- save = ceil(((gitem_armor_t *)armor->info)->normal_protection*damage);
+ save = ceil(((gitem_armor_t *)armor->info)->normal_protection * damage);
if (save >= client->pers.inventory[index])
save = client->pers.inventory[index];
@@ -287,12 +275,12 @@ static int CheckArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, in
return 0;
client->pers.inventory[index] -= save;
- SpawnDamage (te_sparks, point, normal, save);
+ SpawnDamage(te_sparks, point, normal, save);
return save;
}
-void M_ReactToDamage (edict_t *targ, edict_t *attacker)
+void M_ReactToDamage(edict_t *targ, edict_t *attacker)
{
if (!(attacker->client) && !(attacker->svflags & SVF_MONSTER))
return;
@@ -302,8 +290,7 @@ void M_ReactToDamage (edict_t *targ, edict_t *attacker)
// if we are a good guy monster and our attacker is a player
// or another good guy, do not get mad at them
- if (targ->monsterinfo.aiflags & AI_GOOD_GUY)
- {
+ if (targ->monsterinfo.aiflags & AI_GOOD_GUY) {
if (attacker->client || (attacker->monsterinfo.aiflags & AI_GOOD_GUY))
return;
}
@@ -311,16 +298,13 @@ void M_ReactToDamage (edict_t *targ, edict_t *attacker)
// we now know that we are not both good guys
// if attacker is a client, get mad at them because he's good and we're not
- if (attacker->client)
- {
+ if (attacker->client) {
targ->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
// this can only happen in coop (both new and old enemies are clients)
// only switch if can't see the current enemy
- if (targ->enemy && targ->enemy->client)
- {
- if (visible(targ, targ->enemy))
- {
+ if (targ->enemy && targ->enemy->client) {
+ if (visible(targ, targ->enemy)) {
targ->oldenemy = attacker;
return;
}
@@ -328,53 +312,50 @@ void M_ReactToDamage (edict_t *targ, edict_t *attacker)
}
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED))
- FoundTarget (targ);
+ FoundTarget(targ);
return;
}
// it's the same base (walk/swim/fly) type and a different classname and it's not a tank
// (they spray too much), get mad at them
- if (((targ->flags & (FL_FLY|FL_SWIM)) == (attacker->flags & (FL_FLY|FL_SWIM))) &&
- (strcmp (targ->classname, attacker->classname) != 0) &&
- (strcmp(attacker->classname, "monster_tank") != 0) &&
- (strcmp(attacker->classname, "monster_supertank") != 0) &&
- (strcmp(attacker->classname, "monster_makron") != 0) &&
- (strcmp(attacker->classname, "monster_jorg") != 0) )
- {
+ if (((targ->flags & (FL_FLY | FL_SWIM)) == (attacker->flags & (FL_FLY | FL_SWIM))) &&
+ (strcmp(targ->classname, attacker->classname) != 0) &&
+ (strcmp(attacker->classname, "monster_tank") != 0) &&
+ (strcmp(attacker->classname, "monster_supertank") != 0) &&
+ (strcmp(attacker->classname, "monster_makron") != 0) &&
+ (strcmp(attacker->classname, "monster_jorg") != 0)) {
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED))
- FoundTarget (targ);
+ FoundTarget(targ);
}
// if they *meant* to shoot us, then shoot back
- else if (attacker->enemy == targ)
- {
+ else if (attacker->enemy == targ) {
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED))
- FoundTarget (targ);
+ FoundTarget(targ);
}
// otherwise get mad at whoever they are mad at (help our buddy) unless it is us!
- else if (attacker->enemy && attacker->enemy != targ)
- {
+ else if (attacker->enemy && attacker->enemy != targ) {
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker->enemy;
if (!(targ->monsterinfo.aiflags & AI_DUCKED))
- FoundTarget (targ);
+ FoundTarget(targ);
}
}
-qboolean CheckTeamDamage (edict_t *targ, edict_t *attacker)
+qboolean CheckTeamDamage(edict_t *targ, edict_t *attacker)
{
- //FIXME make the next line real and uncomment this block
- // if ((ability to damage a teammate == OFF) && (targ's team == attacker's team))
+ //FIXME make the next line real and uncomment this block
+ // if ((ability to damage a teammate == OFF) && (targ's team == attacker's team))
return qfalse;
}
-void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod)
+void T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod)
{
gclient_t *client;
int take;
@@ -389,10 +370,8 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
// friendly fire avoidance
// if enabled you can't hurt teammates (but you can hurt yourself)
// knockback still occurs
- if ((targ != attacker) && ((deathmatch->value && ((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS))) || coop->value))
- {
- if (OnSameTeam (targ, attacker))
- {
+ if ((targ != attacker) && ((deathmatch->value && ((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS))) || coop->value)) {
+ if (OnSameTeam(targ, attacker)) {
if ((int)(dmflags->value) & DF_NO_FRIENDLY_FIRE)
damage = 0;
else
@@ -402,8 +381,7 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
meansOfDeath = mod;
// easy mode takes half damage
- if (skill->value == 0 && deathmatch->value == 0 && targ->client)
- {
+ if (skill->value == 0 && deathmatch->value == 0 && targ->client) {
damage *= 0.5;
if (!damage)
damage = 1;
@@ -426,10 +404,8 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
knockback = 0;
// figure momentum add
- if (!(dflags & DAMAGE_NO_KNOCKBACK))
- {
- if ((knockback) && (targ->movetype != MOVETYPE_NONE) && (targ->movetype != MOVETYPE_BOUNCE) && (targ->movetype != MOVETYPE_PUSH) && (targ->movetype != MOVETYPE_STOP))
- {
+ if (!(dflags & DAMAGE_NO_KNOCKBACK)) {
+ if ((knockback) && (targ->movetype != MOVETYPE_NONE) && (targ->movetype != MOVETYPE_BOUNCE) && (targ->movetype != MOVETYPE_PUSH) && (targ->movetype != MOVETYPE_STOP)) {
vec3_t kvel;
float mass;
@@ -439,11 +415,11 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
mass = targ->mass;
if (targ->client && attacker == targ)
- VectorScale (dir, 1600.0 * (float)knockback / mass, kvel); // the rocket jump hack...
+ VectorScale(dir, 1600.0 * (float)knockback / mass, kvel); // the rocket jump hack...
else
- VectorScale (dir, 500.0 * (float)knockback / mass, kvel);
+ VectorScale(dir, 500.0 * (float)knockback / mass, kvel);
- VectorAdd (targ->velocity, kvel, targ->velocity);
+ VectorAdd(targ->velocity, kvel, targ->velocity);
}
}
@@ -451,18 +427,15 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
save = 0;
// check for godmode
- if ( (targ->flags & FL_GODMODE) && !(dflags & DAMAGE_NO_PROTECTION) )
- {
+ if ((targ->flags & FL_GODMODE) && !(dflags & DAMAGE_NO_PROTECTION)) {
take = 0;
save = damage;
- SpawnDamage (te_sparks, point, normal, save);
+ SpawnDamage(te_sparks, point, normal, save);
}
// check for invincibility
- if ((client && client->invincible_framenum > level.framenum ) && !(dflags & DAMAGE_NO_PROTECTION))
- {
- if (targ->pain_debounce_time < level.time)
- {
+ if ((client && client->invincible_framenum > level.framenum) && !(dflags & DAMAGE_NO_PROTECTION)) {
+ if (targ->pain_debounce_time < level.time) {
gi.sound(targ, CHAN_ITEM, gi.soundindex("items/protect4.wav"), 1, ATTN_NORM, 0);
targ->pain_debounce_time = level.time + 2;
}
@@ -470,71 +443,62 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
save = damage;
}
- psave = CheckPowerArmor (targ, point, normal, take, dflags);
+ psave = CheckPowerArmor(targ, point, normal, take, dflags);
take -= psave;
- asave = CheckArmor (targ, point, normal, take, te_sparks, dflags);
+ asave = CheckArmor(targ, point, normal, take, te_sparks, dflags);
take -= asave;
//treat cheat/powerup savings the same as armor
asave += save;
// team damage avoidance
- if (!(dflags & DAMAGE_NO_PROTECTION) && CheckTeamDamage (targ, attacker))
+ if (!(dflags & DAMAGE_NO_PROTECTION) && CheckTeamDamage(targ, attacker))
return;
// do the damage
- if (take)
- {
+ if (take) {
if ((targ->svflags & SVF_MONSTER) || (client))
- SpawnDamage (TE_BLOOD, point, normal, take);
+ SpawnDamage(TE_BLOOD, point, normal, take);
else
- SpawnDamage (te_sparks, point, normal, take);
+ SpawnDamage(te_sparks, point, normal, take);
targ->health = targ->health - take;
-
- if (targ->health <= 0)
- {
+
+ if (targ->health <= 0) {
if ((targ->svflags & SVF_MONSTER) || (client))
targ->flags |= FL_NO_KNOCKBACK;
- Killed (targ, inflictor, attacker, take, point);
+ Killed(targ, inflictor, attacker, take, point);
return;
}
}
- if (targ->svflags & SVF_MONSTER)
- {
- M_ReactToDamage (targ, attacker);
- if (!(targ->monsterinfo.aiflags & AI_DUCKED) && (take))
- {
- targ->pain (targ, attacker, knockback, take);
+ if (targ->svflags & SVF_MONSTER) {
+ M_ReactToDamage(targ, attacker);
+ if (!(targ->monsterinfo.aiflags & AI_DUCKED) && (take)) {
+ targ->pain(targ, attacker, knockback, take);
// nightmare mode monsters don't go into pain frames often
if (skill->value == 3)
targ->pain_debounce_time = level.time + 5;
}
- }
- else if (client)
- {
+ } else if (client) {
if (!(targ->flags & FL_GODMODE) && (take))
- targ->pain (targ, attacker, knockback, take);
- }
- else if (take)
- {
+ targ->pain(targ, attacker, knockback, take);
+ } else if (take) {
if (targ->pain)
- targ->pain (targ, attacker, knockback, take);
+ targ->pain(targ, attacker, knockback, take);
}
// add to the damage inflicted on a player this frame
// the total will be turned into screen blends and view angle kicks
// at the end of the frame
- if (client)
- {
+ if (client) {
client->damage_parmor += psave;
client->damage_armor += asave;
client->damage_blood += take;
client->damage_knockback += knockback;
- VectorCopy (point, client->damage_from);
+ VectorCopy(point, client->damage_from);
}
}
@@ -544,32 +508,29 @@ void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
T_RadiusDamage
============
*/
-void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod)
+void T_RadiusDamage(edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod)
{
float points;
edict_t *ent = NULL;
vec3_t v;
vec3_t dir;
- while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL)
- {
+ while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL) {
if (ent == ignore)
continue;
if (!ent->takedamage)
continue;
- VectorAdd (ent->mins, ent->maxs, v);
- VectorMA (ent->s.origin, 0.5, v, v);
- VectorSubtract (inflictor->s.origin, v, v);
- points = damage - 0.5 * VectorLength (v);
+ VectorAdd(ent->mins, ent->maxs, v);
+ VectorMA(ent->s.origin, 0.5, v, v);
+ VectorSubtract(inflictor->s.origin, v, v);
+ points = damage - 0.5 * VectorLength(v);
if (ent == attacker)
points = points * 0.5;
- if (points > 0)
- {
- if (CanDamage (ent, inflictor))
- {
- VectorSubtract (ent->s.origin, inflictor->s.origin, dir);
- T_Damage (ent, inflictor, attacker, dir, inflictor->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
+ if (points > 0) {
+ if (CanDamage(ent, inflictor)) {
+ VectorSubtract(ent->s.origin, inflictor->s.origin, dir);
+ T_Damage(ent, inflictor, attacker, dir, inflictor->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
}
}
}
diff --git a/src/baseq2/g_func.c b/src/baseq2/g_func.c
index d49a477..06c8671 100644
--- a/src/baseq2/g_func.c
+++ b/src/baseq2/g_func.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -73,65 +73,57 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Support routines for movement (changes in origin using velocity)
//
-void Move_Done (edict_t *ent)
+void Move_Done(edict_t *ent)
{
- VectorClear (ent->velocity);
- ent->moveinfo.endfunc (ent);
+ VectorClear(ent->velocity);
+ ent->moveinfo.endfunc(ent);
}
-void Move_Final (edict_t *ent)
+void Move_Final(edict_t *ent)
{
- if (ent->moveinfo.remaining_distance == 0)
- {
- Move_Done (ent);
+ if (ent->moveinfo.remaining_distance == 0) {
+ Move_Done(ent);
return;
}
- VectorScale (ent->moveinfo.dir, ent->moveinfo.remaining_distance / FRAMETIME, ent->velocity);
+ VectorScale(ent->moveinfo.dir, ent->moveinfo.remaining_distance / FRAMETIME, ent->velocity);
ent->think = Move_Done;
ent->nextthink = level.time + FRAMETIME;
}
-void Move_Begin (edict_t *ent)
+void Move_Begin(edict_t *ent)
{
float frames;
- if ((ent->moveinfo.speed * FRAMETIME) >= ent->moveinfo.remaining_distance)
- {
- Move_Final (ent);
+ if ((ent->moveinfo.speed * FRAMETIME) >= ent->moveinfo.remaining_distance) {
+ Move_Final(ent);
return;
}
- VectorScale (ent->moveinfo.dir, ent->moveinfo.speed, ent->velocity);
+ VectorScale(ent->moveinfo.dir, ent->moveinfo.speed, ent->velocity);
frames = floor((ent->moveinfo.remaining_distance / ent->moveinfo.speed) / FRAMETIME);
ent->moveinfo.remaining_distance -= frames * ent->moveinfo.speed * FRAMETIME;
ent->nextthink = level.time + (frames * FRAMETIME);
ent->think = Move_Final;
}
-void Think_AccelMove (edict_t *ent);
+void Think_AccelMove(edict_t *ent);
-void Move_Calc (edict_t *ent, vec3_t dest, void(*func)(edict_t*))
+void Move_Calc(edict_t *ent, vec3_t dest, void(*func)(edict_t*))
{
- VectorClear (ent->velocity);
- VectorSubtract (dest, ent->s.origin, ent->moveinfo.dir);
- ent->moveinfo.remaining_distance = VectorNormalize (ent->moveinfo.dir);
+ VectorClear(ent->velocity);
+ VectorSubtract(dest, ent->s.origin, ent->moveinfo.dir);
+ ent->moveinfo.remaining_distance = VectorNormalize(ent->moveinfo.dir);
ent->moveinfo.endfunc = func;
- if (ent->moveinfo.speed == ent->moveinfo.accel && ent->moveinfo.speed == ent->moveinfo.decel)
- {
- if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent))
- {
- Move_Begin (ent);
- }
- else
- {
+ if (ent->moveinfo.speed == ent->moveinfo.accel && ent->moveinfo.speed == ent->moveinfo.decel) {
+ if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent)) {
+ Move_Begin(ent);
+ } else {
ent->nextthink = level.time + FRAMETIME;
ent->think = Move_Begin;
}
- }
- else
- {
+ } else {
// accelerative
ent->moveinfo.current_speed = 0;
ent->think = Think_AccelMove;
@@ -144,34 +136,33 @@ void Move_Calc (edict_t *ent, vec3_t dest, void(*func)(edict_t*))
// Support routines for angular movement (changes in angle using avelocity)
//
-void AngleMove_Done (edict_t *ent)
+void AngleMove_Done(edict_t *ent)
{
- VectorClear (ent->avelocity);
- ent->moveinfo.endfunc (ent);
+ VectorClear(ent->avelocity);
+ ent->moveinfo.endfunc(ent);
}
-void AngleMove_Final (edict_t *ent)
+void AngleMove_Final(edict_t *ent)
{
vec3_t move;
if (ent->moveinfo.state == STATE_UP)
- VectorSubtract (ent->moveinfo.end_angles, ent->s.angles, move);
+ VectorSubtract(ent->moveinfo.end_angles, ent->s.angles, move);
else
- VectorSubtract (ent->moveinfo.start_angles, ent->s.angles, move);
+ VectorSubtract(ent->moveinfo.start_angles, ent->s.angles, move);
- if (VectorCompare (move, vec3_origin))
- {
- AngleMove_Done (ent);
+ if (VectorCompare(move, vec3_origin)) {
+ AngleMove_Done(ent);
return;
}
- VectorScale (move, 1.0/FRAMETIME, ent->avelocity);
+ VectorScale(move, 1.0 / FRAMETIME, ent->avelocity);
ent->think = AngleMove_Done;
ent->nextthink = level.time + FRAMETIME;
}
-void AngleMove_Begin (edict_t *ent)
+void AngleMove_Begin(edict_t *ent)
{
vec3_t destdelta;
float len;
@@ -180,42 +171,38 @@ void AngleMove_Begin (edict_t *ent)
// set destdelta to the vector needed to move
if (ent->moveinfo.state == STATE_UP)
- VectorSubtract (ent->moveinfo.end_angles, ent->s.angles, destdelta);
+ VectorSubtract(ent->moveinfo.end_angles, ent->s.angles, destdelta);
else
- VectorSubtract (ent->moveinfo.start_angles, ent->s.angles, destdelta);
-
+ VectorSubtract(ent->moveinfo.start_angles, ent->s.angles, destdelta);
+
// calculate length of vector
- len = VectorLength (destdelta);
-
+ len = VectorLength(destdelta);
+
// divide by speed to get time to reach dest
traveltime = len / ent->moveinfo.speed;
- if (traveltime < FRAMETIME)
- {
- AngleMove_Final (ent);
+ if (traveltime < FRAMETIME) {
+ AngleMove_Final(ent);
return;
}
frames = floor(traveltime / FRAMETIME);
// scale the destdelta vector by the time spent traveling to get velocity
- VectorScale (destdelta, 1.0 / traveltime, ent->avelocity);
+ VectorScale(destdelta, 1.0 / traveltime, ent->avelocity);
// set nextthink to trigger a think when dest is reached
ent->nextthink = level.time + frames * FRAMETIME;
ent->think = AngleMove_Final;
}
-void AngleMove_Calc (edict_t *ent, void(*func)(edict_t*))
+void AngleMove_Calc(edict_t *ent, void(*func)(edict_t*))
{
- VectorClear (ent->avelocity);
+ VectorClear(ent->avelocity);
ent->moveinfo.endfunc = func;
- if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent))
- {
- AngleMove_Begin (ent);
- }
- else
- {
+ if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent)) {
+ AngleMove_Begin(ent);
+ } else {
ent->nextthink = level.time + FRAMETIME;
ent->think = AngleMove_Begin;
}
@@ -239,36 +226,31 @@ void plat_CalcAcceleratedMove(moveinfo_t *moveinfo)
moveinfo->move_speed = moveinfo->speed;
- if (moveinfo->remaining_distance < moveinfo->accel)
- {
+ if (moveinfo->remaining_distance < moveinfo->accel) {
moveinfo->current_speed = moveinfo->remaining_distance;
return;
}
- accel_dist = AccelerationDistance (moveinfo->speed, moveinfo->accel);
- decel_dist = AccelerationDistance (moveinfo->speed, moveinfo->decel);
+ accel_dist = AccelerationDistance(moveinfo->speed, moveinfo->accel);
+ decel_dist = AccelerationDistance(moveinfo->speed, moveinfo->decel);
- if ((moveinfo->remaining_distance - accel_dist - decel_dist) < 0)
- {
+ if ((moveinfo->remaining_distance - accel_dist - decel_dist) < 0) {
float f;
f = (moveinfo->accel + moveinfo->decel) / (moveinfo->accel * moveinfo->decel);
moveinfo->move_speed = (-2 + sqrt(4 - 4 * f * (-2 * moveinfo->remaining_distance))) / (2 * f);
- decel_dist = AccelerationDistance (moveinfo->move_speed, moveinfo->decel);
+ decel_dist = AccelerationDistance(moveinfo->move_speed, moveinfo->decel);
}
moveinfo->decel_distance = decel_dist;
};
-void plat_Accelerate (moveinfo_t *moveinfo)
+void plat_Accelerate(moveinfo_t *moveinfo)
{
// are we decelerating?
- if (moveinfo->remaining_distance <= moveinfo->decel_distance)
- {
- if (moveinfo->remaining_distance < moveinfo->decel_distance)
- {
- if (moveinfo->next_speed)
- {
+ if (moveinfo->remaining_distance <= moveinfo->decel_distance) {
+ if (moveinfo->remaining_distance < moveinfo->decel_distance) {
+ if (moveinfo->next_speed) {
moveinfo->current_speed = moveinfo->next_speed;
moveinfo->next_speed = 0;
return;
@@ -281,8 +263,7 @@ void plat_Accelerate (moveinfo_t *moveinfo)
// are we at full speed and need to start decelerating during this move?
if (moveinfo->current_speed == moveinfo->move_speed)
- if ((moveinfo->remaining_distance - moveinfo->current_speed) < moveinfo->decel_distance)
- {
+ if ((moveinfo->remaining_distance - moveinfo->current_speed) < moveinfo->decel_distance) {
float p1_distance;
float p2_distance;
float distance;
@@ -296,8 +277,7 @@ void plat_Accelerate (moveinfo_t *moveinfo)
}
// are we accelerating?
- if (moveinfo->current_speed < moveinfo->speed)
- {
+ if (moveinfo->current_speed < moveinfo->speed) {
float old_speed;
float p1_distance;
float p1_speed;
@@ -331,36 +311,34 @@ void plat_Accelerate (moveinfo_t *moveinfo)
return;
};
-void Think_AccelMove (edict_t *ent)
+void Think_AccelMove(edict_t *ent)
{
ent->moveinfo.remaining_distance -= ent->moveinfo.current_speed;
if (ent->moveinfo.current_speed == 0) // starting or blocked
plat_CalcAcceleratedMove(&ent->moveinfo);
- plat_Accelerate (&ent->moveinfo);
+ plat_Accelerate(&ent->moveinfo);
// will the entire move complete on next frame?
- if (ent->moveinfo.remaining_distance <= ent->moveinfo.current_speed)
- {
- Move_Final (ent);
+ if (ent->moveinfo.remaining_distance <= ent->moveinfo.current_speed) {
+ Move_Final(ent);
return;
}
- VectorScale (ent->moveinfo.dir, ent->moveinfo.current_speed*10, ent->velocity);
+ VectorScale(ent->moveinfo.dir, ent->moveinfo.current_speed * 10, ent->velocity);
ent->nextthink = level.time + FRAMETIME;
ent->think = Think_AccelMove;
}
-void plat_go_down (edict_t *ent);
+void plat_go_down(edict_t *ent);
-void plat_hit_top (edict_t *ent)
+void plat_hit_top(edict_t *ent)
{
- if (!(ent->flags & FL_TEAMSLAVE))
- {
+ if (!(ent->flags & FL_TEAMSLAVE)) {
if (ent->moveinfo.sound_end)
- gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
+ gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
ent->s.sound = 0;
}
ent->moveinfo.state = STATE_TOP;
@@ -369,99 +347,95 @@ void plat_hit_top (edict_t *ent)
ent->nextthink = level.time + 3;
}
-void plat_hit_bottom (edict_t *ent)
+void plat_hit_bottom(edict_t *ent)
{
- if (!(ent->flags & FL_TEAMSLAVE))
- {
+ if (!(ent->flags & FL_TEAMSLAVE)) {
if (ent->moveinfo.sound_end)
- gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
+ gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
ent->s.sound = 0;
}
ent->moveinfo.state = STATE_BOTTOM;
}
-void plat_go_down (edict_t *ent)
+void plat_go_down(edict_t *ent)
{
- if (!(ent->flags & FL_TEAMSLAVE))
- {
+ if (!(ent->flags & FL_TEAMSLAVE)) {
if (ent->moveinfo.sound_start)
- gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
ent->s.sound = ent->moveinfo.sound_middle;
}
ent->moveinfo.state = STATE_DOWN;
- Move_Calc (ent, ent->moveinfo.end_origin, plat_hit_bottom);
+ Move_Calc(ent, ent->moveinfo.end_origin, plat_hit_bottom);
}
-void plat_go_up (edict_t *ent)
+void plat_go_up(edict_t *ent)
{
- if (!(ent->flags & FL_TEAMSLAVE))
- {
+ if (!(ent->flags & FL_TEAMSLAVE)) {
if (ent->moveinfo.sound_start)
- gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
ent->s.sound = ent->moveinfo.sound_middle;
}
ent->moveinfo.state = STATE_UP;
- Move_Calc (ent, ent->moveinfo.start_origin, plat_hit_top);
+ Move_Calc(ent, ent->moveinfo.start_origin, plat_hit_top);
}
-void plat_blocked (edict_t *self, edict_t *other)
+void plat_blocked(edict_t *self, edict_t *other)
{
- if (!(other->svflags & SVF_MONSTER) && (!other->client) )
- {
+ if (!(other->svflags & SVF_MONSTER) && (!other->client)) {
// give it a chance to go away on it's own terms (like gibs)
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it
if (other)
- BecomeExplosion1 (other);
+ BecomeExplosion1(other);
return;
}
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
if (self->moveinfo.state == STATE_UP)
- plat_go_down (self);
+ plat_go_down(self);
else if (self->moveinfo.state == STATE_DOWN)
- plat_go_up (self);
+ plat_go_up(self);
}
-void Use_Plat (edict_t *ent, edict_t *other, edict_t *activator)
-{
+void Use_Plat(edict_t *ent, edict_t *other, edict_t *activator)
+{
if (ent->think)
return; // already down
- plat_go_down (ent);
+ plat_go_down(ent);
}
-void Touch_Plat_Center (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
+void Touch_Plat_Center(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (!other->client)
return;
-
+
if (other->health <= 0)
return;
ent = ent->enemy; // now point at the plat, not the trigger
if (ent->moveinfo.state == STATE_BOTTOM)
- plat_go_up (ent);
+ plat_go_up(ent);
else if (ent->moveinfo.state == STATE_TOP)
ent->nextthink = level.time + 1; // the player is still on the plat, so delay going down
}
-void plat_spawn_inside_trigger (edict_t *ent)
+void plat_spawn_inside_trigger(edict_t *ent)
{
edict_t *trigger;
vec3_t tmin, tmax;
//
// middle trigger
-//
+//
trigger = G_Spawn();
trigger->touch = Touch_Plat_Center;
trigger->movetype = MOVETYPE_NONE;
trigger->solid = SOLID_TRIGGER;
trigger->enemy = ent;
-
+
tmin[0] = ent->mins[0] + 25;
tmin[1] = ent->mins[1] + 25;
tmin[2] = ent->mins[2];
@@ -474,22 +448,20 @@ void plat_spawn_inside_trigger (edict_t *ent)
if (ent->spawnflags & PLAT_LOW_TRIGGER)
tmax[2] = tmin[2] + 8;
-
- if (tmax[0] - tmin[0] <= 0)
- {
- tmin[0] = (ent->mins[0] + ent->maxs[0]) *0.5;
+
+ if (tmax[0] - tmin[0] <= 0) {
+ tmin[0] = (ent->mins[0] + ent->maxs[0]) * 0.5;
tmax[0] = tmin[0] + 1;
}
- if (tmax[1] - tmin[1] <= 0)
- {
- tmin[1] = (ent->mins[1] + ent->maxs[1]) *0.5;
+ if (tmax[1] - tmin[1] <= 0) {
+ tmin[1] = (ent->mins[1] + ent->maxs[1]) * 0.5;
tmax[1] = tmin[1] + 1;
}
-
- VectorCopy (tmin, trigger->mins);
- VectorCopy (tmax, trigger->maxs);
- gi.linkentity (trigger);
+ VectorCopy(tmin, trigger->mins);
+ VectorCopy(tmax, trigger->maxs);
+
+ gi.linkentity(trigger);
}
@@ -510,13 +482,13 @@ Set "sounds" to one of the following:
1) base fast
2) chain slow
*/
-void SP_func_plat (edict_t *ent)
+void SP_func_plat(edict_t *ent)
{
- VectorClear (ent->s.angles);
+ VectorClear(ent->s.angles);
ent->solid = SOLID_BSP;
ent->movetype = MOVETYPE_PUSH;
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
ent->blocked = plat_blocked;
@@ -542,8 +514,8 @@ void SP_func_plat (edict_t *ent)
st.lip = 8;
// pos1 is the top position, pos2 is the bottom
- VectorCopy (ent->s.origin, ent->pos1);
- VectorCopy (ent->s.origin, ent->pos2);
+ VectorCopy(ent->s.origin, ent->pos1);
+ VectorCopy(ent->s.origin, ent->pos2);
if (st.height)
ent->pos2[2] -= st.height;
else
@@ -551,16 +523,13 @@ void SP_func_plat (edict_t *ent)
ent->use = Use_Plat;
- plat_spawn_inside_trigger (ent); // the "start moving" trigger
+ plat_spawn_inside_trigger(ent); // the "start moving" trigger
- if (ent->targetname)
- {
+ if (ent->targetname) {
ent->moveinfo.state = STATE_UP;
- }
- else
- {
- VectorCopy (ent->pos2, ent->s.origin);
- gi.linkentity (ent);
+ } else {
+ VectorCopy(ent->pos2, ent->s.origin);
+ gi.linkentity(ent);
ent->moveinfo.state = STATE_BOTTOM;
}
@@ -568,14 +537,14 @@ void SP_func_plat (edict_t *ent)
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
- VectorCopy (ent->pos1, ent->moveinfo.start_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
- VectorCopy (ent->pos2, ent->moveinfo.end_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
+ VectorCopy(ent->pos1, ent->moveinfo.start_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.start_angles);
+ VectorCopy(ent->pos2, ent->moveinfo.end_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.end_angles);
- ent->moveinfo.sound_start = gi.soundindex ("plats/pt1_strt.wav");
- ent->moveinfo.sound_middle = gi.soundindex ("plats/pt1_mid.wav");
- ent->moveinfo.sound_end = gi.soundindex ("plats/pt1_end.wav");
+ ent->moveinfo.sound_start = gi.soundindex("plats/pt1_strt.wav");
+ ent->moveinfo.sound_middle = gi.soundindex("plats/pt1_mid.wav");
+ ent->moveinfo.sound_end = gi.soundindex("plats/pt1_end.wav");
}
//====================================================================
@@ -592,35 +561,32 @@ REVERSE will cause the it to rotate in the opposite direction.
STOP mean it will stop moving instead of pushing entities
*/
-void rotating_blocked (edict_t *self, edict_t *other)
+void rotating_blocked(edict_t *self, edict_t *other)
{
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
-void rotating_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void rotating_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (self->avelocity[0] || self->avelocity[1] || self->avelocity[2])
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
-void rotating_use (edict_t *self, edict_t *other, edict_t *activator)
+void rotating_use(edict_t *self, edict_t *other, edict_t *activator)
{
- if (!VectorCompare (self->avelocity, vec3_origin))
- {
+ if (!VectorCompare(self->avelocity, vec3_origin)) {
self->s.sound = 0;
- VectorClear (self->avelocity);
+ VectorClear(self->avelocity);
self->touch = NULL;
- }
- else
- {
+ } else {
self->s.sound = self->moveinfo.sound_middle;
- VectorScale (self->movedir, self->speed, self->avelocity);
+ VectorScale(self->movedir, self->speed, self->avelocity);
if (self->spawnflags & 16)
self->touch = rotating_touch;
}
}
-void SP_func_rotating (edict_t *ent)
+void SP_func_rotating(edict_t *ent)
{
ent->solid = SOLID_BSP;
if (ent->spawnflags & 32)
@@ -639,7 +605,7 @@ void SP_func_rotating (edict_t *ent)
// check for reverse rotation
if (ent->spawnflags & 2)
- VectorNegate (ent->movedir, ent->movedir);
+ VectorNegate(ent->movedir, ent->movedir);
if (!ent->speed)
ent->speed = 100;
@@ -653,15 +619,15 @@ void SP_func_rotating (edict_t *ent)
ent->blocked = rotating_blocked;
if (ent->spawnflags & 1)
- ent->use (ent, NULL, NULL);
+ ent->use(ent, NULL, NULL);
if (ent->spawnflags & 64)
ent->s.effects |= EF_ANIM_ALL;
if (ent->spawnflags & 128)
ent->s.effects |= EF_ANIM_ALLFAST;
- gi.setmodel (ent, ent->model);
- gi.linkentity (ent);
+ gi.setmodel(ent, ent->model);
+ gi.linkentity(ent);
}
/*
@@ -689,18 +655,18 @@ When a button is touched, it moves some distance in the direction of it's angle,
5) in-out
*/
-void button_done (edict_t *self)
+void button_done(edict_t *self)
{
self->moveinfo.state = STATE_BOTTOM;
self->s.effects &= ~EF_ANIM23;
self->s.effects |= EF_ANIM01;
}
-void button_return (edict_t *self)
+void button_return(edict_t *self)
{
self->moveinfo.state = STATE_DOWN;
- Move_Calc (self, self->moveinfo.start_origin, button_done);
+ Move_Calc(self, self->moveinfo.start_origin, button_done);
self->s.frame = 0;
@@ -708,39 +674,38 @@ void button_return (edict_t *self)
self->takedamage = DAMAGE_YES;
}
-void button_wait (edict_t *self)
+void button_wait(edict_t *self)
{
self->moveinfo.state = STATE_TOP;
self->s.effects &= ~EF_ANIM01;
self->s.effects |= EF_ANIM23;
- G_UseTargets (self, self->activator);
+ G_UseTargets(self, self->activator);
self->s.frame = 1;
- if (self->moveinfo.wait >= 0)
- {
+ if (self->moveinfo.wait >= 0) {
self->nextthink = level.time + self->moveinfo.wait;
self->think = button_return;
}
}
-void button_fire (edict_t *self)
+void button_fire(edict_t *self)
{
if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
return;
self->moveinfo.state = STATE_UP;
if (self->moveinfo.sound_start && !(self->flags & FL_TEAMSLAVE))
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
- Move_Calc (self, self->moveinfo.end_origin, button_wait);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ Move_Calc(self, self->moveinfo.end_origin, button_wait);
}
-void button_use (edict_t *self, edict_t *other, edict_t *activator)
+void button_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
- button_fire (self);
+ button_fire(self);
}
-void button_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void button_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (!other->client)
return;
@@ -749,30 +714,30 @@ void button_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *s
return;
self->activator = other;
- button_fire (self);
+ button_fire(self);
}
-void button_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void button_killed(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
self->activator = attacker;
self->health = self->max_health;
self->takedamage = DAMAGE_NO;
- button_fire (self);
+ button_fire(self);
}
-void SP_func_button (edict_t *ent)
+void SP_func_button(edict_t *ent)
{
vec3_t abs_movedir;
float dist;
- G_SetMovedir (ent->s.angles, ent->movedir);
+ G_SetMovedir(ent->s.angles, ent->movedir);
ent->movetype = MOVETYPE_STOP;
ent->solid = SOLID_BSP;
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
if (ent->sounds != 1)
- ent->moveinfo.sound_start = gi.soundindex ("switches/butn2.wav");
-
+ ent->moveinfo.sound_start = gi.soundindex("switches/butn2.wav");
+
if (!ent->speed)
ent->speed = 40;
if (!ent->accel)
@@ -785,23 +750,21 @@ void SP_func_button (edict_t *ent)
if (!st.lip)
st.lip = 4;
- VectorCopy (ent->s.origin, ent->pos1);
+ VectorCopy(ent->s.origin, ent->pos1);
abs_movedir[0] = fabs(ent->movedir[0]);
abs_movedir[1] = fabs(ent->movedir[1]);
abs_movedir[2] = fabs(ent->movedir[2]);
dist = abs_movedir[0] * ent->size[0] + abs_movedir[1] * ent->size[1] + abs_movedir[2] * ent->size[2] - st.lip;
- VectorMA (ent->pos1, dist, ent->movedir, ent->pos2);
+ VectorMA(ent->pos1, dist, ent->movedir, ent->pos2);
ent->use = button_use;
ent->s.effects |= EF_ANIM01;
- if (ent->health)
- {
+ if (ent->health) {
ent->max_health = ent->health;
ent->die = button_killed;
ent->takedamage = DAMAGE_YES;
- }
- else if (! ent->targetname)
+ } else if (! ent->targetname)
ent->touch = button_touch;
ent->moveinfo.state = STATE_BOTTOM;
@@ -810,12 +773,12 @@ void SP_func_button (edict_t *ent)
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
- VectorCopy (ent->pos1, ent->moveinfo.start_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
- VectorCopy (ent->pos2, ent->moveinfo.end_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
+ VectorCopy(ent->pos1, ent->moveinfo.start_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.start_angles);
+ VectorCopy(ent->pos2, ent->moveinfo.end_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.end_angles);
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*
@@ -849,135 +812,123 @@ NOMONSTER monsters will not trigger this door
4) heavy
*/
-void door_use_areaportals (edict_t *self, qboolean open)
+void door_use_areaportals(edict_t *self, qboolean open)
{
edict_t *t = NULL;
if (!self->target)
return;
- while ((t = G_Find (t, FOFS(targetname), self->target)))
- {
- if (Q_stricmp(t->classname, "func_areaportal") == 0)
- {
- gi.SetAreaPortalState (t->style, open);
+ while ((t = G_Find(t, FOFS(targetname), self->target))) {
+ if (Q_stricmp(t->classname, "func_areaportal") == 0) {
+ gi.SetAreaPortalState(t->style, open);
}
}
}
-void door_go_down (edict_t *self);
+void door_go_down(edict_t *self);
-void door_hit_top (edict_t *self)
+void door_hit_top(edict_t *self)
{
- if (!(self->flags & FL_TEAMSLAVE))
- {
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_end)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
self->s.sound = 0;
}
self->moveinfo.state = STATE_TOP;
if (self->spawnflags & DOOR_TOGGLE)
return;
- if (self->moveinfo.wait >= 0)
- {
+ if (self->moveinfo.wait >= 0) {
self->think = door_go_down;
self->nextthink = level.time + self->moveinfo.wait;
}
}
-void door_hit_bottom (edict_t *self)
+void door_hit_bottom(edict_t *self)
{
- if (!(self->flags & FL_TEAMSLAVE))
- {
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_end)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
self->s.sound = 0;
}
self->moveinfo.state = STATE_BOTTOM;
- door_use_areaportals (self, qfalse);
+ door_use_areaportals(self, qfalse);
}
-void door_go_down (edict_t *self)
+void door_go_down(edict_t *self)
{
- if (!(self->flags & FL_TEAMSLAVE))
- {
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_start)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
self->s.sound = self->moveinfo.sound_middle;
}
- if (self->max_health)
- {
+ if (self->max_health) {
self->takedamage = DAMAGE_YES;
self->health = self->max_health;
}
-
+
self->moveinfo.state = STATE_DOWN;
if (strcmp(self->classname, "func_door") == 0)
- Move_Calc (self, self->moveinfo.start_origin, door_hit_bottom);
+ Move_Calc(self, self->moveinfo.start_origin, door_hit_bottom);
else if (strcmp(self->classname, "func_door_rotating") == 0)
- AngleMove_Calc (self, door_hit_bottom);
+ AngleMove_Calc(self, door_hit_bottom);
}
-void door_go_up (edict_t *self, edict_t *activator)
+void door_go_up(edict_t *self, edict_t *activator)
{
if (self->moveinfo.state == STATE_UP)
return; // already going up
- if (self->moveinfo.state == STATE_TOP)
- { // reset top wait time
+ if (self->moveinfo.state == STATE_TOP) {
+ // reset top wait time
if (self->moveinfo.wait >= 0)
self->nextthink = level.time + self->moveinfo.wait;
return;
}
-
- if (!(self->flags & FL_TEAMSLAVE))
- {
+
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_start)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
self->s.sound = self->moveinfo.sound_middle;
}
self->moveinfo.state = STATE_UP;
if (strcmp(self->classname, "func_door") == 0)
- Move_Calc (self, self->moveinfo.end_origin, door_hit_top);
+ Move_Calc(self, self->moveinfo.end_origin, door_hit_top);
else if (strcmp(self->classname, "func_door_rotating") == 0)
- AngleMove_Calc (self, door_hit_top);
+ AngleMove_Calc(self, door_hit_top);
- G_UseTargets (self, activator);
- door_use_areaportals (self, qtrue);
+ G_UseTargets(self, activator);
+ door_use_areaportals(self, qtrue);
}
-void door_use (edict_t *self, edict_t *other, edict_t *activator)
+void door_use(edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *ent;
if (self->flags & FL_TEAMSLAVE)
return;
- if (self->spawnflags & DOOR_TOGGLE)
- {
- if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
- {
+ if (self->spawnflags & DOOR_TOGGLE) {
+ if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP) {
// trigger all paired doors
- for (ent = self ; ent ; ent = ent->teamchain)
- {
+ for (ent = self ; ent ; ent = ent->teamchain) {
ent->message = NULL;
ent->touch = NULL;
- door_go_down (ent);
+ door_go_down(ent);
}
return;
}
}
-
+
// trigger all paired doors
- for (ent = self ; ent ; ent = ent->teamchain)
- {
+ for (ent = self ; ent ; ent = ent->teamchain) {
ent->message = NULL;
ent->touch = NULL;
- door_go_up (ent, activator);
+ door_go_up(ent, activator);
}
};
-void Touch_DoorTrigger (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void Touch_DoorTrigger(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other->health <= 0)
return;
@@ -992,10 +943,10 @@ void Touch_DoorTrigger (edict_t *self, edict_t *other, cplane_t *plane, csurface
return;
self->touch_debounce_time = level.time + 1.0;
- door_use (self->owner, other, other);
+ door_use(self->owner, other, other);
}
-void Think_CalcMoveSpeed (edict_t *self)
+void Think_CalcMoveSpeed(edict_t *self)
{
edict_t *ent;
float min;
@@ -1009,8 +960,7 @@ void Think_CalcMoveSpeed (edict_t *self)
// find the smallest distance any member of the team will be moving
min = fabs(self->moveinfo.distance);
- for (ent = self->teamchain; ent; ent = ent->teamchain)
- {
+ for (ent = self->teamchain; ent; ent = ent->teamchain) {
dist = fabs(ent->moveinfo.distance);
if (dist < min)
min = dist;
@@ -1019,8 +969,7 @@ void Think_CalcMoveSpeed (edict_t *self)
time = min / self->moveinfo.speed;
// adjust speeds so they will all complete at the same time
- for (ent = self; ent; ent = ent->teamchain)
- {
+ for (ent = self; ent; ent = ent->teamchain) {
newspeed = fabs(ent->moveinfo.distance) / time;
ratio = newspeed / ent->moveinfo.speed;
if (ent->moveinfo.accel == ent->moveinfo.speed)
@@ -1035,7 +984,7 @@ void Think_CalcMoveSpeed (edict_t *self)
}
}
-void Think_SpawnDoorTrigger (edict_t *ent)
+void Think_SpawnDoorTrigger(edict_t *ent)
{
edict_t *other;
vec3_t mins, maxs;
@@ -1043,51 +992,49 @@ void Think_SpawnDoorTrigger (edict_t *ent)
if (ent->flags & FL_TEAMSLAVE)
return; // only the team leader spawns a trigger
- VectorCopy (ent->absmin, mins);
- VectorCopy (ent->absmax, maxs);
+ VectorCopy(ent->absmin, mins);
+ VectorCopy(ent->absmax, maxs);
- for (other = ent->teamchain ; other ; other=other->teamchain)
- {
- AddPointToBounds (other->absmin, mins, maxs);
- AddPointToBounds (other->absmax, mins, maxs);
+ for (other = ent->teamchain ; other ; other = other->teamchain) {
+ AddPointToBounds(other->absmin, mins, maxs);
+ AddPointToBounds(other->absmax, mins, maxs);
}
- // expand
+ // expand
mins[0] -= 60;
mins[1] -= 60;
maxs[0] += 60;
maxs[1] += 60;
- other = G_Spawn ();
- VectorCopy (mins, other->mins);
- VectorCopy (maxs, other->maxs);
+ other = G_Spawn();
+ VectorCopy(mins, other->mins);
+ VectorCopy(maxs, other->maxs);
other->owner = ent;
other->solid = SOLID_TRIGGER;
other->movetype = MOVETYPE_NONE;
other->touch = Touch_DoorTrigger;
- gi.linkentity (other);
+ gi.linkentity(other);
if (ent->spawnflags & DOOR_START_OPEN)
- door_use_areaportals (ent, qtrue);
+ door_use_areaportals(ent, qtrue);
- Think_CalcMoveSpeed (ent);
+ Think_CalcMoveSpeed(ent);
}
-void door_blocked (edict_t *self, edict_t *other)
+void door_blocked(edict_t *self, edict_t *other)
{
edict_t *ent;
- if (!(other->svflags & SVF_MONSTER) && (!other->client) )
- {
+ if (!(other->svflags & SVF_MONSTER) && (!other->client)) {
// give it a chance to go away on it's own terms (like gibs)
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it
if (other)
- BecomeExplosion1 (other);
+ BecomeExplosion1(other);
return;
}
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
if (self->spawnflags & DOOR_CRUSHER)
return;
@@ -1095,34 +1042,29 @@ void door_blocked (edict_t *self, edict_t *other)
// if a door has a negative wait, it would never come back if blocked,
// so let it just squash the object to death real fast
- if (self->moveinfo.wait >= 0)
- {
- if (self->moveinfo.state == STATE_DOWN)
- {
+ if (self->moveinfo.wait >= 0) {
+ if (self->moveinfo.state == STATE_DOWN) {
for (ent = self->teammaster ; ent ; ent = ent->teamchain)
- door_go_up (ent, ent->activator);
- }
- else
- {
+ door_go_up(ent, ent->activator);
+ } else {
for (ent = self->teammaster ; ent ; ent = ent->teamchain)
- door_go_down (ent);
+ door_go_down(ent);
}
}
}
-void door_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void door_killed(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
edict_t *ent;
- for (ent = self->teammaster ; ent ; ent = ent->teamchain)
- {
+ for (ent = self->teammaster ; ent ; ent = ent->teamchain) {
ent->health = ent->max_health;
ent->takedamage = DAMAGE_NO;
}
- door_use (self->teammaster, attacker, attacker);
+ door_use(self->teammaster, attacker, attacker);
}
-void door_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void door_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (!other->client)
return;
@@ -1131,29 +1073,28 @@ void door_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *sur
return;
self->touch_debounce_time = level.time + 5.0;
- gi.centerprintf (other, "%s", self->message);
- gi.sound (other, CHAN_AUTO, gi.soundindex ("misc/talk1.wav"), 1, ATTN_NORM, 0);
+ gi.centerprintf(other, "%s", self->message);
+ gi.sound(other, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
-void SP_func_door (edict_t *ent)
+void SP_func_door(edict_t *ent)
{
vec3_t abs_movedir;
- if (ent->sounds != 1)
- {
- ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
- ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
- ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
+ if (ent->sounds != 1) {
+ ent->moveinfo.sound_start = gi.soundindex("doors/dr1_strt.wav");
+ ent->moveinfo.sound_middle = gi.soundindex("doors/dr1_mid.wav");
+ ent->moveinfo.sound_end = gi.soundindex("doors/dr1_end.wav");
}
- G_SetMovedir (ent->s.angles, ent->movedir);
+ G_SetMovedir(ent->s.angles, ent->movedir);
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
ent->blocked = door_blocked;
ent->use = door_use;
-
+
if (!ent->speed)
ent->speed = 100;
if (deathmatch->value)
@@ -1172,43 +1113,39 @@ void SP_func_door (edict_t *ent)
ent->dmg = 2;
// calculate second position
- VectorCopy (ent->s.origin, ent->pos1);
+ VectorCopy(ent->s.origin, ent->pos1);
abs_movedir[0] = fabs(ent->movedir[0]);
abs_movedir[1] = fabs(ent->movedir[1]);
abs_movedir[2] = fabs(ent->movedir[2]);
ent->moveinfo.distance = abs_movedir[0] * ent->size[0] + abs_movedir[1] * ent->size[1] + abs_movedir[2] * ent->size[2] - st.lip;
- VectorMA (ent->pos1, ent->moveinfo.distance, ent->movedir, ent->pos2);
+ VectorMA(ent->pos1, ent->moveinfo.distance, ent->movedir, ent->pos2);
// if it starts open, switch the positions
- if (ent->spawnflags & DOOR_START_OPEN)
- {
- VectorCopy (ent->pos2, ent->s.origin);
- VectorCopy (ent->pos1, ent->pos2);
- VectorCopy (ent->s.origin, ent->pos1);
+ if (ent->spawnflags & DOOR_START_OPEN) {
+ VectorCopy(ent->pos2, ent->s.origin);
+ VectorCopy(ent->pos1, ent->pos2);
+ VectorCopy(ent->s.origin, ent->pos1);
}
ent->moveinfo.state = STATE_BOTTOM;
- if (ent->health)
- {
+ if (ent->health) {
ent->takedamage = DAMAGE_YES;
ent->die = door_killed;
ent->max_health = ent->health;
- }
- else if (ent->targetname && ent->message)
- {
- gi.soundindex ("misc/talk.wav");
+ } else if (ent->targetname && ent->message) {
+ gi.soundindex("misc/talk.wav");
ent->touch = door_touch;
}
-
+
ent->moveinfo.speed = ent->speed;
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
- VectorCopy (ent->pos1, ent->moveinfo.start_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
- VectorCopy (ent->pos2, ent->moveinfo.end_origin);
- VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
+ VectorCopy(ent->pos1, ent->moveinfo.start_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.start_angles);
+ VectorCopy(ent->pos2, ent->moveinfo.end_origin);
+ VectorCopy(ent->s.angles, ent->moveinfo.end_angles);
if (ent->spawnflags & 16)
ent->s.effects |= EF_ANIM_ALL;
@@ -1219,7 +1156,7 @@ void SP_func_door (edict_t *ent)
if (!ent->team)
ent->teammaster = ent;
- gi.linkentity (ent);
+ gi.linkentity(ent);
ent->nextthink = level.time + FRAMETIME;
if (ent->health || ent->targetname)
@@ -1258,9 +1195,9 @@ REVERSE will cause the door to rotate in the opposite direction.
4) heavy
*/
-void SP_func_door_rotating (edict_t *ent)
+void SP_func_door_rotating(edict_t *ent)
{
- VectorClear (ent->s.angles);
+ VectorClear(ent->s.angles);
// set the axis of rotation
VectorClear(ent->movedir);
@@ -1273,21 +1210,20 @@ void SP_func_door_rotating (edict_t *ent)
// check for reverse rotation
if (ent->spawnflags & DOOR_REVERSE)
- VectorNegate (ent->movedir, ent->movedir);
+ VectorNegate(ent->movedir, ent->movedir);
- if (!st.distance)
- {
+ if (!st.distance) {
gi.dprintf("%s at %s with no distance set\n", ent->classname, vtos(ent->s.origin));
st.distance = 90;
}
- VectorCopy (ent->s.angles, ent->pos1);
- VectorMA (ent->s.angles, st.distance, ent->movedir, ent->pos2);
+ VectorCopy(ent->s.angles, ent->pos1);
+ VectorMA(ent->s.angles, st.distance, ent->movedir, ent->pos2);
ent->moveinfo.distance = st.distance;
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
ent->blocked = door_blocked;
ent->use = door_use;
@@ -1304,32 +1240,28 @@ void SP_func_door_rotating (edict_t *ent)
if (!ent->dmg)
ent->dmg = 2;
- if (ent->sounds != 1)
- {
- ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
- ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
- ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
+ if (ent->sounds != 1) {
+ ent->moveinfo.sound_start = gi.soundindex("doors/dr1_strt.wav");
+ ent->moveinfo.sound_middle = gi.soundindex("doors/dr1_mid.wav");
+ ent->moveinfo.sound_end = gi.soundindex("doors/dr1_end.wav");
}
// if it starts open, switch the positions
- if (ent->spawnflags & DOOR_START_OPEN)
- {
- VectorCopy (ent->pos2, ent->s.angles);
- VectorCopy (ent->pos1, ent->pos2);
- VectorCopy (ent->s.angles, ent->pos1);
- VectorNegate (ent->movedir, ent->movedir);
+ if (ent->spawnflags & DOOR_START_OPEN) {
+ VectorCopy(ent->pos2, ent->s.angles);
+ VectorCopy(ent->pos1, ent->pos2);
+ VectorCopy(ent->s.angles, ent->pos1);
+ VectorNegate(ent->movedir, ent->movedir);
}
- if (ent->health)
- {
+ if (ent->health) {
ent->takedamage = DAMAGE_YES;
ent->die = door_killed;
ent->max_health = ent->health;
}
-
- if (ent->targetname && ent->message)
- {
- gi.soundindex ("misc/talk.wav");
+
+ if (ent->targetname && ent->message) {
+ gi.soundindex("misc/talk.wav");
ent->touch = door_touch;
}
@@ -1338,10 +1270,10 @@ void SP_func_door_rotating (edict_t *ent)
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
- VectorCopy (ent->s.origin, ent->moveinfo.start_origin);
- VectorCopy (ent->pos1, ent->moveinfo.start_angles);
- VectorCopy (ent->s.origin, ent->moveinfo.end_origin);
- VectorCopy (ent->pos2, ent->moveinfo.end_angles);
+ VectorCopy(ent->s.origin, ent->moveinfo.start_origin);
+ VectorCopy(ent->pos1, ent->moveinfo.start_angles);
+ VectorCopy(ent->s.origin, ent->moveinfo.end_origin);
+ VectorCopy(ent->pos2, ent->moveinfo.end_angles);
if (ent->spawnflags & 16)
ent->s.effects |= EF_ANIM_ALL;
@@ -1350,7 +1282,7 @@ void SP_func_door_rotating (edict_t *ent)
if (!ent->team)
ent->teammaster = ent;
- gi.linkentity (ent);
+ gi.linkentity(ent);
ent->nextthink = level.time + FRAMETIME;
if (ent->health || ent->targetname)
@@ -1375,51 +1307,49 @@ START_OPEN causes the water to move to its destination when spawned and operate
2) lava
*/
-void SP_func_water (edict_t *self)
+void SP_func_water(edict_t *self)
{
vec3_t abs_movedir;
- G_SetMovedir (self->s.angles, self->movedir);
+ G_SetMovedir(self->s.angles, self->movedir);
self->movetype = MOVETYPE_PUSH;
self->solid = SOLID_BSP;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
- switch (self->sounds)
- {
- default:
- break;
+ switch (self->sounds) {
+ default:
+ break;
- case 1: // water
- self->moveinfo.sound_start = gi.soundindex ("world/mov_watr.wav");
- self->moveinfo.sound_end = gi.soundindex ("world/stp_watr.wav");
- break;
+ case 1: // water
+ self->moveinfo.sound_start = gi.soundindex("world/mov_watr.wav");
+ self->moveinfo.sound_end = gi.soundindex("world/stp_watr.wav");
+ break;
- case 2: // lava
- self->moveinfo.sound_start = gi.soundindex ("world/mov_watr.wav");
- self->moveinfo.sound_end = gi.soundindex ("world/stp_watr.wav");
- break;
+ case 2: // lava
+ self->moveinfo.sound_start = gi.soundindex("world/mov_watr.wav");
+ self->moveinfo.sound_end = gi.soundindex("world/stp_watr.wav");
+ break;
}
// calculate second position
- VectorCopy (self->s.origin, self->pos1);
+ VectorCopy(self->s.origin, self->pos1);
abs_movedir[0] = fabs(self->movedir[0]);
abs_movedir[1] = fabs(self->movedir[1]);
abs_movedir[2] = fabs(self->movedir[2]);
self->moveinfo.distance = abs_movedir[0] * self->size[0] + abs_movedir[1] * self->size[1] + abs_movedir[2] * self->size[2] - st.lip;
- VectorMA (self->pos1, self->moveinfo.distance, self->movedir, self->pos2);
+ VectorMA(self->pos1, self->moveinfo.distance, self->movedir, self->pos2);
// if it starts open, switch the positions
- if (self->spawnflags & DOOR_START_OPEN)
- {
- VectorCopy (self->pos2, self->s.origin);
- VectorCopy (self->pos1, self->pos2);
- VectorCopy (self->s.origin, self->pos1);
+ if (self->spawnflags & DOOR_START_OPEN) {
+ VectorCopy(self->pos2, self->s.origin);
+ VectorCopy(self->pos1, self->pos2);
+ VectorCopy(self->s.origin, self->pos1);
}
- VectorCopy (self->pos1, self->moveinfo.start_origin);
- VectorCopy (self->s.angles, self->moveinfo.start_angles);
- VectorCopy (self->pos2, self->moveinfo.end_origin);
- VectorCopy (self->s.angles, self->moveinfo.end_angles);
+ VectorCopy(self->pos1, self->moveinfo.start_origin);
+ VectorCopy(self->s.angles, self->moveinfo.start_angles);
+ VectorCopy(self->pos2, self->moveinfo.end_origin);
+ VectorCopy(self->s.angles, self->moveinfo.end_angles);
self->moveinfo.state = STATE_BOTTOM;
@@ -1438,7 +1368,7 @@ void SP_func_water (edict_t *self)
self->classname = "func_door";
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -1456,17 +1386,16 @@ dmg default 2
noise looping sound to play when the train is in motion
*/
-void train_next (edict_t *self);
+void train_next(edict_t *self);
-void train_blocked (edict_t *self, edict_t *other)
+void train_blocked(edict_t *self, edict_t *other)
{
- if (!(other->svflags & SVF_MONSTER) && (!other->client) )
- {
+ if (!(other->svflags & SVF_MONSTER) && (!other->client)) {
// give it a chance to go away on it's own terms (like gibs)
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it
if (other)
- BecomeExplosion1 (other);
+ BecomeExplosion1(other);
return;
}
@@ -1476,20 +1405,19 @@ void train_blocked (edict_t *self, edict_t *other)
if (!self->dmg)
return;
self->touch_debounce_time = level.time + 0.5;
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
-void train_wait (edict_t *self)
+void train_wait(edict_t *self)
{
- if (self->target_ent->pathtarget)
- {
+ if (self->target_ent->pathtarget) {
char *savetarget;
edict_t *ent;
ent = self->target_ent;
savetarget = ent->target;
ent->target = ent->pathtarget;
- G_UseTargets (ent, self->activator);
+ G_UseTargets(ent, self->activator);
ent->target = savetarget;
// make sure we didn't get killed by a killtarget
@@ -1497,36 +1425,29 @@ void train_wait (edict_t *self)
return;
}
- if (self->moveinfo.wait)
- {
- if (self->moveinfo.wait > 0)
- {
+ if (self->moveinfo.wait) {
+ if (self->moveinfo.wait > 0) {
self->nextthink = level.time + self->moveinfo.wait;
self->think = train_next;
- }
- else if (self->spawnflags & TRAIN_TOGGLE) // && wait < 0
- {
- train_next (self);
+ } else if (self->spawnflags & TRAIN_TOGGLE) { // && wait < 0
+ train_next(self);
self->spawnflags &= ~TRAIN_START_ON;
- VectorClear (self->velocity);
+ VectorClear(self->velocity);
self->nextthink = 0;
}
- if (!(self->flags & FL_TEAMSLAVE))
- {
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_end)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
self->s.sound = 0;
}
+ } else {
+ train_next(self);
}
- else
- {
- train_next (self);
- }
-
+
}
-void train_next (edict_t *self)
+void train_next(edict_t *self)
{
edict_t *ent;
vec3_t dest;
@@ -1534,116 +1455,105 @@ void train_next (edict_t *self)
first = qtrue;
again:
- if (!self->target)
- {
+ if (!self->target) {
// gi.dprintf ("train_next: no next target\n");
return;
}
- ent = G_PickTarget (self->target);
- if (!ent)
- {
- gi.dprintf ("train_next: bad target %s\n", self->target);
+ ent = G_PickTarget(self->target);
+ if (!ent) {
+ gi.dprintf("train_next: bad target %s\n", self->target);
return;
}
self->target = ent->target;
// check for a teleport path_corner
- if (ent->spawnflags & 1)
- {
- if (!first)
- {
- gi.dprintf ("connected teleport path_corners, see %s at %s\n", ent->classname, vtos(ent->s.origin));
+ if (ent->spawnflags & 1) {
+ if (!first) {
+ gi.dprintf("connected teleport path_corners, see %s at %s\n", ent->classname, vtos(ent->s.origin));
return;
}
first = qfalse;
- VectorSubtract (ent->s.origin, self->mins, self->s.origin);
- VectorCopy (self->s.origin, self->s.old_origin);
+ VectorSubtract(ent->s.origin, self->mins, self->s.origin);
+ VectorCopy(self->s.origin, self->s.old_origin);
self->s.event = EV_OTHER_TELEPORT;
- gi.linkentity (self);
+ gi.linkentity(self);
goto again;
}
self->moveinfo.wait = ent->wait;
self->target_ent = ent;
- if (!(self->flags & FL_TEAMSLAVE))
- {
+ if (!(self->flags & FL_TEAMSLAVE)) {
if (self->moveinfo.sound_start)
- gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
+ gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
self->s.sound = self->moveinfo.sound_middle;
}
- VectorSubtract (ent->s.origin, self->mins, dest);
+ VectorSubtract(ent->s.origin, self->mins, dest);
self->moveinfo.state = STATE_TOP;
- VectorCopy (self->s.origin, self->moveinfo.start_origin);
- VectorCopy (dest, self->moveinfo.end_origin);
- Move_Calc (self, dest, train_wait);
+ VectorCopy(self->s.origin, self->moveinfo.start_origin);
+ VectorCopy(dest, self->moveinfo.end_origin);
+ Move_Calc(self, dest, train_wait);
self->spawnflags |= TRAIN_START_ON;
}
-void train_resume (edict_t *self)
+void train_resume(edict_t *self)
{
edict_t *ent;
vec3_t dest;
ent = self->target_ent;
- VectorSubtract (ent->s.origin, self->mins, dest);
+ VectorSubtract(ent->s.origin, self->mins, dest);
self->moveinfo.state = STATE_TOP;
- VectorCopy (self->s.origin, self->moveinfo.start_origin);
- VectorCopy (dest, self->moveinfo.end_origin);
- Move_Calc (self, dest, train_wait);
+ VectorCopy(self->s.origin, self->moveinfo.start_origin);
+ VectorCopy(dest, self->moveinfo.end_origin);
+ Move_Calc(self, dest, train_wait);
self->spawnflags |= TRAIN_START_ON;
}
-void func_train_find (edict_t *self)
+void func_train_find(edict_t *self)
{
edict_t *ent;
- if (!self->target)
- {
- gi.dprintf ("train_find: no target\n");
+ if (!self->target) {
+ gi.dprintf("train_find: no target\n");
return;
}
- ent = G_PickTarget (self->target);
- if (!ent)
- {
- gi.dprintf ("train_find: target %s not found\n", self->target);
+ ent = G_PickTarget(self->target);
+ if (!ent) {
+ gi.dprintf("train_find: target %s not found\n", self->target);
return;
}
self->target = ent->target;
- VectorSubtract (ent->s.origin, self->mins, self->s.origin);
- gi.linkentity (self);
+ VectorSubtract(ent->s.origin, self->mins, self->s.origin);
+ gi.linkentity(self);
// if not triggered, start immediately
if (!self->targetname)
self->spawnflags |= TRAIN_START_ON;
- if (self->spawnflags & TRAIN_START_ON)
- {
+ if (self->spawnflags & TRAIN_START_ON) {
self->nextthink = level.time + FRAMETIME;
self->think = train_next;
self->activator = self;
}
}
-void train_use (edict_t *self, edict_t *other, edict_t *activator)
+void train_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
- if (self->spawnflags & TRAIN_START_ON)
- {
+ if (self->spawnflags & TRAIN_START_ON) {
if (!(self->spawnflags & TRAIN_TOGGLE))
return;
self->spawnflags &= ~TRAIN_START_ON;
- VectorClear (self->velocity);
+ VectorClear(self->velocity);
self->nextthink = 0;
- }
- else
- {
+ } else {
if (self->target_ent)
train_resume(self);
else
@@ -1651,24 +1561,23 @@ void train_use (edict_t *self, edict_t *other, edict_t *activator)
}
}
-void SP_func_train (edict_t *self)
+void SP_func_train(edict_t *self)
{
self->movetype = MOVETYPE_PUSH;
- VectorClear (self->s.angles);
+ VectorClear(self->s.angles);
self->blocked = train_blocked;
if (self->spawnflags & TRAIN_BLOCK_STOPS)
self->dmg = 0;
- else
- {
+ else {
if (!self->dmg)
self->dmg = 100;
}
self->solid = SOLID_BSP;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
if (st.noise)
- self->moveinfo.sound_middle = gi.soundindex (st.noise);
+ self->moveinfo.sound_middle = gi.soundindex(st.noise);
if (!self->speed)
self->speed = 100;
@@ -1678,66 +1587,57 @@ void SP_func_train (edict_t *self)
self->use = train_use;
- gi.linkentity (self);
+ gi.linkentity(self);
- if (self->target)
- {
+ if (self->target) {
// start trains on the second frame, to make sure their targets have had
// a chance to spawn
self->nextthink = level.time + FRAMETIME;
self->think = func_train_find;
- }
- else
- {
- gi.dprintf ("func_train without a target at %s\n", vtos(self->absmin));
+ } else {
+ gi.dprintf("func_train without a target at %s\n", vtos(self->absmin));
}
}
/*QUAKED trigger_elevator (0.3 0.1 0.6) (-8 -8 -8) (8 8 8)
*/
-void trigger_elevator_use (edict_t *self, edict_t *other, edict_t *activator)
+void trigger_elevator_use(edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *target;
- if (self->movetarget->nextthink)
- {
+ if (self->movetarget->nextthink) {
// gi.dprintf("elevator busy\n");
return;
}
- if (!other->pathtarget)
- {
+ if (!other->pathtarget) {
gi.dprintf("elevator used with no pathtarget\n");
return;
}
- target = G_PickTarget (other->pathtarget);
- if (!target)
- {
+ target = G_PickTarget(other->pathtarget);
+ if (!target) {
gi.dprintf("elevator used with bad pathtarget: %s\n", other->pathtarget);
return;
}
self->movetarget->target_ent = target;
- train_resume (self->movetarget);
+ train_resume(self->movetarget);
}
-void trigger_elevator_init (edict_t *self)
+void trigger_elevator_init(edict_t *self)
{
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("trigger_elevator has no target\n");
return;
}
- self->movetarget = G_PickTarget (self->target);
- if (!self->movetarget)
- {
+ self->movetarget = G_PickTarget(self->target);
+ if (!self->movetarget) {
gi.dprintf("trigger_elevator unable to find target %s\n", self->target);
return;
}
- if (strcmp(self->movetarget->classname, "func_train") != 0)
- {
+ if (strcmp(self->movetarget->classname, "func_train") != 0) {
gi.dprintf("trigger_elevator target %s is not a train\n", self->target);
return;
}
@@ -1747,7 +1647,7 @@ void trigger_elevator_init (edict_t *self)
}
-void SP_trigger_elevator (edict_t *self)
+void SP_trigger_elevator(edict_t *self)
{
self->think = trigger_elevator_init;
self->nextthink = level.time + FRAMETIME;
@@ -1768,19 +1668,18 @@ so, the basic time between firing is a random time between
These can used but not touched.
*/
-void func_timer_think (edict_t *self)
+void func_timer_think(edict_t *self)
{
- G_UseTargets (self, self->activator);
+ G_UseTargets(self, self->activator);
self->nextthink = level.time + self->wait + crandom() * self->random;
}
-void func_timer_use (edict_t *self, edict_t *other, edict_t *activator)
+void func_timer_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
// if on, turn it off
- if (self->nextthink)
- {
+ if (self->nextthink) {
self->nextthink = 0;
return;
}
@@ -1789,10 +1688,10 @@ void func_timer_use (edict_t *self, edict_t *other, edict_t *activator)
if (self->delay)
self->nextthink = level.time + self->delay;
else
- func_timer_think (self);
+ func_timer_think(self);
}
-void SP_func_timer (edict_t *self)
+void SP_func_timer(edict_t *self)
{
if (!self->wait)
self->wait = 1.0;
@@ -1800,14 +1699,12 @@ void SP_func_timer (edict_t *self)
self->use = func_timer_use;
self->think = func_timer_think;
- if (self->random >= self->wait)
- {
+ if (self->random >= self->wait) {
self->random = self->wait - FRAMETIME;
gi.dprintf("func_timer at %s has random >= wait\n", vtos(self->s.origin));
}
- if (self->spawnflags & 1)
- {
+ if (self->spawnflags & 1) {
self->nextthink = level.time + 1.0 + st.pausetime + self->delay + self->wait + crandom() * self->random;
self->activator = self;
}
@@ -1822,15 +1719,12 @@ The brush should be have a surface with at least one current content enabled.
speed default 100
*/
-void func_conveyor_use (edict_t *self, edict_t *other, edict_t *activator)
+void func_conveyor_use(edict_t *self, edict_t *other, edict_t *activator)
{
- if (self->spawnflags & 1)
- {
+ if (self->spawnflags & 1) {
self->speed = 0;
self->spawnflags &= ~1;
- }
- else
- {
+ } else {
self->speed = self->count;
self->spawnflags |= 1;
}
@@ -1839,22 +1733,21 @@ void func_conveyor_use (edict_t *self, edict_t *other, edict_t *activator)
self->count = 0;
}
-void SP_func_conveyor (edict_t *self)
+void SP_func_conveyor(edict_t *self)
{
if (!self->speed)
self->speed = 100;
- if (!(self->spawnflags & 1))
- {
+ if (!(self->spawnflags & 1)) {
self->count = self->speed;
self->speed = 0;
}
self->use = func_conveyor_use;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
self->solid = SOLID_BSP;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -1875,36 +1768,36 @@ always_shoot door is shootebale even if targeted
#define SECRET_1ST_LEFT 2
#define SECRET_1ST_DOWN 4
-void door_secret_move1 (edict_t *self);
-void door_secret_move2 (edict_t *self);
-void door_secret_move3 (edict_t *self);
-void door_secret_move4 (edict_t *self);
-void door_secret_move5 (edict_t *self);
-void door_secret_move6 (edict_t *self);
-void door_secret_done (edict_t *self);
+void door_secret_move1(edict_t *self);
+void door_secret_move2(edict_t *self);
+void door_secret_move3(edict_t *self);
+void door_secret_move4(edict_t *self);
+void door_secret_move5(edict_t *self);
+void door_secret_move6(edict_t *self);
+void door_secret_done(edict_t *self);
-void door_secret_use (edict_t *self, edict_t *other, edict_t *activator)
+void door_secret_use(edict_t *self, edict_t *other, edict_t *activator)
{
// make sure we're not already moving
if (!VectorCompare(self->s.origin, vec3_origin))
return;
- Move_Calc (self, self->pos1, door_secret_move1);
- door_use_areaportals (self, qtrue);
+ Move_Calc(self, self->pos1, door_secret_move1);
+ door_use_areaportals(self, qtrue);
}
-void door_secret_move1 (edict_t *self)
+void door_secret_move1(edict_t *self)
{
self->nextthink = level.time + 1.0;
self->think = door_secret_move2;
}
-void door_secret_move2 (edict_t *self)
+void door_secret_move2(edict_t *self)
{
- Move_Calc (self, self->pos2, door_secret_move3);
+ Move_Calc(self, self->pos2, door_secret_move3);
}
-void door_secret_move3 (edict_t *self)
+void door_secret_move3(edict_t *self)
{
if (self->wait == -1)
return;
@@ -1912,41 +1805,39 @@ void door_secret_move3 (edict_t *self)
self->think = door_secret_move4;
}
-void door_secret_move4 (edict_t *self)
+void door_secret_move4(edict_t *self)
{
- Move_Calc (self, self->pos1, door_secret_move5);
+ Move_Calc(self, self->pos1, door_secret_move5);
}
-void door_secret_move5 (edict_t *self)
+void door_secret_move5(edict_t *self)
{
self->nextthink = level.time + 1.0;
self->think = door_secret_move6;
}
-void door_secret_move6 (edict_t *self)
+void door_secret_move6(edict_t *self)
{
- Move_Calc (self, vec3_origin, door_secret_done);
+ Move_Calc(self, vec3_origin, door_secret_done);
}
-void door_secret_done (edict_t *self)
+void door_secret_done(edict_t *self)
{
- if (!(self->targetname) || (self->spawnflags & SECRET_ALWAYS_SHOOT))
- {
+ if (!(self->targetname) || (self->spawnflags & SECRET_ALWAYS_SHOOT)) {
self->health = 0;
self->takedamage = DAMAGE_YES;
}
- door_use_areaportals (self, qfalse);
+ door_use_areaportals(self, qfalse);
}
-void door_secret_blocked (edict_t *self, edict_t *other)
+void door_secret_blocked(edict_t *self, edict_t *other)
{
- if (!(other->svflags & SVF_MONSTER) && (!other->client) )
- {
+ if (!(other->svflags & SVF_MONSTER) && (!other->client)) {
// give it a chance to go away on it's own terms (like gibs)
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it
if (other)
- BecomeExplosion1 (other);
+ BecomeExplosion1(other);
return;
}
@@ -1954,35 +1845,34 @@ void door_secret_blocked (edict_t *self, edict_t *other)
return;
self->touch_debounce_time = level.time + 0.5;
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
-void door_secret_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void door_secret_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
self->takedamage = DAMAGE_NO;
- door_secret_use (self, attacker, attacker);
+ door_secret_use(self, attacker, attacker);
}
-void SP_func_door_secret (edict_t *ent)
+void SP_func_door_secret(edict_t *ent)
{
vec3_t forward, right, up;
float side;
float width;
float length;
- ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
- ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
- ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
+ ent->moveinfo.sound_start = gi.soundindex("doors/dr1_strt.wav");
+ ent->moveinfo.sound_middle = gi.soundindex("doors/dr1_mid.wav");
+ ent->moveinfo.sound_end = gi.soundindex("doors/dr1_end.wav");
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
ent->blocked = door_secret_blocked;
ent->use = door_secret_use;
- if (!(ent->targetname) || (ent->spawnflags & SECRET_ALWAYS_SHOOT))
- {
+ if (!(ent->targetname) || (ent->spawnflags & SECRET_ALWAYS_SHOOT)) {
ent->health = 0;
ent->takedamage = DAMAGE_YES;
ent->die = door_secret_die;
@@ -1995,12 +1885,12 @@ void SP_func_door_secret (edict_t *ent)
ent->wait = 5;
ent->moveinfo.accel =
- ent->moveinfo.decel =
- ent->moveinfo.speed = 50;
+ ent->moveinfo.decel =
+ ent->moveinfo.speed = 50;
// calculate positions
- AngleVectors (ent->s.angles, forward, right, up);
- VectorClear (ent->s.angles);
+ AngleVectors(ent->s.angles, forward, right, up);
+ VectorClear(ent->s.angles);
side = 1.0 - (ent->spawnflags & SECRET_1ST_LEFT);
if (ent->spawnflags & SECRET_1ST_DOWN)
width = fabs(DotProduct(up, ent->size));
@@ -2008,40 +1898,37 @@ void SP_func_door_secret (edict_t *ent)
width = fabs(DotProduct(right, ent->size));
length = fabs(DotProduct(forward, ent->size));
if (ent->spawnflags & SECRET_1ST_DOWN)
- VectorMA (ent->s.origin, -1 * width, up, ent->pos1);
+ VectorMA(ent->s.origin, -1 * width, up, ent->pos1);
else
- VectorMA (ent->s.origin, side * width, right, ent->pos1);
- VectorMA (ent->pos1, length, forward, ent->pos2);
+ VectorMA(ent->s.origin, side * width, right, ent->pos1);
+ VectorMA(ent->pos1, length, forward, ent->pos2);
- if (ent->health)
- {
+ if (ent->health) {
ent->takedamage = DAMAGE_YES;
ent->die = door_killed;
ent->max_health = ent->health;
- }
- else if (ent->targetname && ent->message)
- {
- gi.soundindex ("misc/talk.wav");
+ } else if (ent->targetname && ent->message) {
+ gi.soundindex("misc/talk.wav");
ent->touch = door_touch;
}
-
+
ent->classname = "func_door";
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED func_killbox (1 0 0) ?
Kills everything inside when fired, irrespective of protection.
*/
-void use_killbox (edict_t *self, edict_t *other, edict_t *activator)
+void use_killbox(edict_t *self, edict_t *other, edict_t *activator)
{
- KillBox (self);
+ KillBox(self);
}
-void SP_func_killbox (edict_t *ent)
+void SP_func_killbox(edict_t *ent)
{
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
ent->use = use_killbox;
ent->svflags = SVF_NOCLIENT;
}
diff --git a/src/baseq2/g_items.c b/src/baseq2/g_items.c
index 3f4a23e..8926c8d 100644
--- a/src/baseq2/g_items.c
+++ b/src/baseq2/g_items.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,21 +20,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
-qboolean Pickup_Weapon (edict_t *ent, edict_t *other);
-void Use_Weapon (edict_t *ent, gitem_t *inv);
-void Drop_Weapon (edict_t *ent, gitem_t *inv);
+qboolean Pickup_Weapon(edict_t *ent, edict_t *other);
+void Use_Weapon(edict_t *ent, gitem_t *inv);
+void Drop_Weapon(edict_t *ent, gitem_t *inv);
-void Weapon_Blaster (edict_t *ent);
-void Weapon_Shotgun (edict_t *ent);
-void Weapon_SuperShotgun (edict_t *ent);
-void Weapon_Machinegun (edict_t *ent);
-void Weapon_Chaingun (edict_t *ent);
-void Weapon_HyperBlaster (edict_t *ent);
-void Weapon_RocketLauncher (edict_t *ent);
-void Weapon_Grenade (edict_t *ent);
-void Weapon_GrenadeLauncher (edict_t *ent);
-void Weapon_Railgun (edict_t *ent);
-void Weapon_BFG (edict_t *ent);
+void Weapon_Blaster(edict_t *ent);
+void Weapon_Shotgun(edict_t *ent);
+void Weapon_SuperShotgun(edict_t *ent);
+void Weapon_Machinegun(edict_t *ent);
+void Weapon_Chaingun(edict_t *ent);
+void Weapon_HyperBlaster(edict_t *ent);
+void Weapon_RocketLauncher(edict_t *ent);
+void Weapon_Grenade(edict_t *ent);
+void Weapon_GrenadeLauncher(edict_t *ent);
+void Weapon_Railgun(edict_t *ent);
+void Weapon_BFG(edict_t *ent);
gitem_armor_t jacketarmor_info = { 25, 50, .30, .00, ARMOR_JACKET};
gitem_armor_t combatarmor_info = { 50, 100, .60, .30, ARMOR_COMBAT};
@@ -49,7 +49,7 @@ static int power_shield_index;
#define HEALTH_IGNORE_MAX 1
#define HEALTH_TIMED 2
-void Use_Quad (edict_t *ent, gitem_t *item);
+void Use_Quad(edict_t *ent, gitem_t *item);
static int quad_drop_timeout_hack;
//======================================================================
@@ -59,7 +59,7 @@ static int quad_drop_timeout_hack;
GetItemByIndex
===============
*/
-gitem_t *GetItemByIndex (int index)
+gitem_t *GetItemByIndex(int index)
{
if (index == 0 || index >= game.num_items)
return NULL;
@@ -74,14 +74,13 @@ FindItemByClassname
===============
*/
-gitem_t *FindItemByClassname (char *classname)
+gitem_t *FindItemByClassname(char *classname)
{
int i;
gitem_t *it;
it = itemlist;
- for (i=0 ; i<game.num_items ; i++, it++)
- {
+ for (i = 0 ; i < game.num_items ; i++, it++) {
if (!it->classname)
continue;
if (!Q_stricmp(it->classname, classname))
@@ -97,14 +96,13 @@ FindItem
===============
*/
-gitem_t *FindItem (char *pickup_name)
+gitem_t *FindItem(char *pickup_name)
{
int i;
gitem_t *it;
it = itemlist;
- for (i=0 ; i<game.num_items ; i++, it++)
- {
+ for (i = 0 ; i < game.num_items ; i++, it++) {
if (!it->pickup_name)
continue;
if (!Q_stricmp(it->pickup_name, pickup_name))
@@ -116,10 +114,9 @@ gitem_t *FindItem (char *pickup_name)
//======================================================================
-void DoRespawn (edict_t *ent)
+void DoRespawn(edict_t *ent)
{
- if (ent->team)
- {
+ if (ent->team) {
edict_t *master;
int count;
int choice;
@@ -137,26 +134,26 @@ void DoRespawn (edict_t *ent)
ent->svflags &= ~SVF_NOCLIENT;
ent->solid = SOLID_TRIGGER;
- gi.linkentity (ent);
+ gi.linkentity(ent);
// send an effect
ent->s.event = EV_ITEM_RESPAWN;
}
-void SetRespawn (edict_t *ent, float delay)
+void SetRespawn(edict_t *ent, float delay)
{
ent->flags |= FL_RESPAWN;
ent->svflags |= SVF_NOCLIENT;
ent->solid = SOLID_NOT;
ent->nextthink = level.time + delay;
ent->think = DoRespawn;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
//======================================================================
-qboolean Pickup_Powerup (edict_t *ent, edict_t *other)
+qboolean Pickup_Powerup(edict_t *ent, edict_t *other)
{
int quantity;
@@ -169,32 +166,30 @@ qboolean Pickup_Powerup (edict_t *ent, edict_t *other)
other->client->pers.inventory[ITEM_INDEX(ent->item)]++;
- if (deathmatch->value)
- {
- if (!(ent->spawnflags & DROPPED_ITEM) )
- SetRespawn (ent, ent->item->quantity);
- if (((int)dmflags->value & DF_INSTANT_ITEMS) || ((ent->item->use == Use_Quad) && (ent->spawnflags & DROPPED_PLAYER_ITEM)))
- {
+ if (deathmatch->value) {
+ if (!(ent->spawnflags & DROPPED_ITEM))
+ SetRespawn(ent, ent->item->quantity);
+ if (((int)dmflags->value & DF_INSTANT_ITEMS) || ((ent->item->use == Use_Quad) && (ent->spawnflags & DROPPED_PLAYER_ITEM))) {
if ((ent->item->use == Use_Quad) && (ent->spawnflags & DROPPED_PLAYER_ITEM))
quad_drop_timeout_hack = (ent->nextthink - level.time) / FRAMETIME;
- ent->item->use (other, ent->item);
+ ent->item->use(other, ent->item);
}
}
return qtrue;
}
-void Drop_General (edict_t *ent, gitem_t *item)
+void Drop_General(edict_t *ent, gitem_t *item)
{
- Drop_Item (ent, item);
+ Drop_Item(ent, item);
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
}
//======================================================================
-qboolean Pickup_Adrenaline (edict_t *ent, edict_t *other)
+qboolean Pickup_Adrenaline(edict_t *ent, edict_t *other)
{
if (!deathmatch->value)
other->max_health += 1;
@@ -203,22 +198,22 @@ qboolean Pickup_Adrenaline (edict_t *ent, edict_t *other)
other->health = other->max_health;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, ent->item->quantity);
+ SetRespawn(ent, ent->item->quantity);
return qtrue;
}
-qboolean Pickup_AncientHead (edict_t *ent, edict_t *other)
+qboolean Pickup_AncientHead(edict_t *ent, edict_t *other)
{
other->max_health += 2;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, ent->item->quantity);
+ SetRespawn(ent, ent->item->quantity);
return qtrue;
}
-qboolean Pickup_Bandolier (edict_t *ent, edict_t *other)
+qboolean Pickup_Bandolier(edict_t *ent, edict_t *other)
{
gitem_t *item;
int index;
@@ -233,8 +228,7 @@ qboolean Pickup_Bandolier (edict_t *ent, edict_t *other)
other->client->pers.max_slugs = 75;
item = FindItem("Bullets");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_bullets)
@@ -242,8 +236,7 @@ qboolean Pickup_Bandolier (edict_t *ent, edict_t *other)
}
item = FindItem("Shells");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_shells)
@@ -251,12 +244,12 @@ qboolean Pickup_Bandolier (edict_t *ent, edict_t *other)
}
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, ent->item->quantity);
+ SetRespawn(ent, ent->item->quantity);
return qtrue;
}
-qboolean Pickup_Pack (edict_t *ent, edict_t *other)
+qboolean Pickup_Pack(edict_t *ent, edict_t *other)
{
gitem_t *item;
int index;
@@ -275,8 +268,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
other->client->pers.max_slugs = 100;
item = FindItem("Bullets");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_bullets)
@@ -284,8 +276,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
item = FindItem("Shells");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_shells)
@@ -293,8 +284,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
item = FindItem("Cells");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_cells)
@@ -302,8 +292,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
item = FindItem("Grenades");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_grenades)
@@ -311,8 +300,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
item = FindItem("Rockets");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_rockets)
@@ -320,8 +308,7 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
item = FindItem("Slugs");
- if (item)
- {
+ if (item) {
index = ITEM_INDEX(item);
other->client->pers.inventory[index] += item->quantity;
if (other->client->pers.inventory[index] > other->client->pers.max_slugs)
@@ -329,27 +316,24 @@ qboolean Pickup_Pack (edict_t *ent, edict_t *other)
}
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, ent->item->quantity);
+ SetRespawn(ent, ent->item->quantity);
return qtrue;
}
//======================================================================
-void Use_Quad (edict_t *ent, gitem_t *item)
+void Use_Quad(edict_t *ent, gitem_t *item)
{
int timeout;
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
- if (quad_drop_timeout_hack)
- {
+ if (quad_drop_timeout_hack) {
timeout = quad_drop_timeout_hack;
quad_drop_timeout_hack = 0;
- }
- else
- {
+ } else {
timeout = 300;
}
@@ -363,10 +347,10 @@ void Use_Quad (edict_t *ent, gitem_t *item)
//======================================================================
-void Use_Breather (edict_t *ent, gitem_t *item)
+void Use_Breather(edict_t *ent, gitem_t *item)
{
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
if (ent->client->breather_framenum > level.framenum)
ent->client->breather_framenum += 300;
@@ -378,10 +362,10 @@ void Use_Breather (edict_t *ent, gitem_t *item)
//======================================================================
-void Use_Envirosuit (edict_t *ent, gitem_t *item)
+void Use_Envirosuit(edict_t *ent, gitem_t *item)
{
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
if (ent->client->enviro_framenum > level.framenum)
ent->client->enviro_framenum += 300;
@@ -393,10 +377,10 @@ void Use_Envirosuit (edict_t *ent, gitem_t *item)
//======================================================================
-void Use_Invulnerability (edict_t *ent, gitem_t *item)
+void Use_Invulnerability(edict_t *ent, gitem_t *item)
{
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
if (ent->client->invincible_framenum > level.framenum)
ent->client->invincible_framenum += 300;
@@ -408,10 +392,10 @@ void Use_Invulnerability (edict_t *ent, gitem_t *item)
//======================================================================
-void Use_Silencer (edict_t *ent, gitem_t *item)
+void Use_Silencer(edict_t *ent, gitem_t *item)
{
ent->client->pers.inventory[ITEM_INDEX(item)]--;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
ent->client->silencer_shots += 30;
// gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage.wav"), 1, ATTN_NORM, 0);
@@ -419,19 +403,15 @@ void Use_Silencer (edict_t *ent, gitem_t *item)
//======================================================================
-qboolean Pickup_Key (edict_t *ent, edict_t *other)
+qboolean Pickup_Key(edict_t *ent, edict_t *other)
{
- if (coop->value)
- {
- if (strcmp(ent->classname, "key_power_cube") == 0)
- {
- if (other->client->pers.power_cubes & ((ent->spawnflags & 0x0000ff00)>> 8))
+ if (coop->value) {
+ if (strcmp(ent->classname, "key_power_cube") == 0) {
+ if (other->client->pers.power_cubes & ((ent->spawnflags & 0x0000ff00) >> 8))
return qfalse;
other->client->pers.inventory[ITEM_INDEX(ent->item)]++;
other->client->pers.power_cubes |= ((ent->spawnflags & 0x0000ff00) >> 8);
- }
- else
- {
+ } else {
if (other->client->pers.inventory[ITEM_INDEX(ent->item)])
return qfalse;
other->client->pers.inventory[ITEM_INDEX(ent->item)] = 1;
@@ -444,7 +424,7 @@ qboolean Pickup_Key (edict_t *ent, edict_t *other)
//======================================================================
-qboolean Add_Ammo (edict_t *ent, gitem_t *item, int count)
+qboolean Add_Ammo(edict_t *ent, gitem_t *item, int count)
{
int index;
int max;
@@ -480,14 +460,14 @@ qboolean Add_Ammo (edict_t *ent, gitem_t *item, int count)
return qtrue;
}
-qboolean Pickup_Ammo (edict_t *ent, edict_t *other)
+qboolean Pickup_Ammo(edict_t *ent, edict_t *other)
{
int oldcount;
int count;
qboolean weapon;
weapon = (ent->item->flags & IT_WEAPON);
- if ( (weapon) && ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if ((weapon) && ((int)dmflags->value & DF_INFINITE_AMMO))
count = 1000;
else if (ent->count)
count = ent->count;
@@ -496,64 +476,62 @@ qboolean Pickup_Ammo (edict_t *ent, edict_t *other)
oldcount = other->client->pers.inventory[ITEM_INDEX(ent->item)];
- if (!Add_Ammo (other, ent->item, count))
+ if (!Add_Ammo(other, ent->item, count))
return qfalse;
- if (weapon && !oldcount)
- {
- if (other->client->pers.weapon != ent->item && ( !deathmatch->value || other->client->pers.weapon == FindItem("blaster") ) )
+ if (weapon && !oldcount) {
+ if (other->client->pers.weapon != ent->item && (!deathmatch->value || other->client->pers.weapon == FindItem("blaster")))
other->client->newweapon = ent->item;
}
if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)) && (deathmatch->value))
- SetRespawn (ent, 30);
+ SetRespawn(ent, 30);
return qtrue;
}
-void Drop_Ammo (edict_t *ent, gitem_t *item)
+void Drop_Ammo(edict_t *ent, gitem_t *item)
{
edict_t *dropped;
int index;
index = ITEM_INDEX(item);
- dropped = Drop_Item (ent, item);
+ dropped = Drop_Item(ent, item);
if (ent->client->pers.inventory[index] >= item->quantity)
dropped->count = item->quantity;
else
dropped->count = ent->client->pers.inventory[index];
- if (ent->client->pers.weapon &&
+ if (ent->client->pers.weapon &&
ent->client->pers.weapon->tag == AMMO_GRENADES &&
item->tag == AMMO_GRENADES &&
ent->client->pers.inventory[index] - dropped->count <= 0) {
- gi.cprintf (ent, PRINT_HIGH, "Can't drop current weapon\n");
+ gi.cprintf(ent, PRINT_HIGH, "Can't drop current weapon\n");
G_FreeEdict(dropped);
return;
}
ent->client->pers.inventory[index] -= dropped->count;
- ValidateSelectedItem (ent);
+ ValidateSelectedItem(ent);
}
//======================================================================
-void MegaHealth_think (edict_t *self)
+void MegaHealth_think(edict_t *self)
{
- if (self->owner->health > self->owner->max_health)
- {
+ if (self->owner->health > self->owner->max_health) {
self->nextthink = level.time + 1;
self->owner->health -= 1;
return;
}
if (!(self->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (self, 20);
+ SetRespawn(self, 20);
else
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-qboolean Pickup_Health (edict_t *ent, edict_t *other)
+qboolean Pickup_Health(edict_t *ent, edict_t *other)
{
if (!(ent->style & HEALTH_IGNORE_MAX))
if (other->health >= other->max_health)
@@ -561,25 +539,21 @@ qboolean Pickup_Health (edict_t *ent, edict_t *other)
other->health += ent->count;
- if (!(ent->style & HEALTH_IGNORE_MAX))
- {
+ if (!(ent->style & HEALTH_IGNORE_MAX)) {
if (other->health > other->max_health)
other->health = other->max_health;
}
- if (ent->style & HEALTH_TIMED)
- {
+ if (ent->style & HEALTH_TIMED) {
ent->think = MegaHealth_think;
ent->nextthink = level.time + 5;
ent->owner = other;
ent->flags |= FL_RESPAWN;
ent->svflags |= SVF_NOCLIENT;
ent->solid = SOLID_NOT;
- }
- else
- {
+ } else {
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, 30);
+ SetRespawn(ent, 30);
}
return qtrue;
@@ -587,7 +561,7 @@ qboolean Pickup_Health (edict_t *ent, edict_t *other)
//======================================================================
-int ArmorIndex (edict_t *ent)
+int ArmorIndex(edict_t *ent)
{
if (!ent->client)
return 0;
@@ -604,7 +578,7 @@ int ArmorIndex (edict_t *ent)
return 0;
}
-qboolean Pickup_Armor (edict_t *ent, edict_t *other)
+qboolean Pickup_Armor(edict_t *ent, edict_t *other)
{
int old_armor_index;
gitem_armor_t *oldinfo;
@@ -616,11 +590,10 @@ qboolean Pickup_Armor (edict_t *ent, edict_t *other)
// get info on new armor
newinfo = (gitem_armor_t *)ent->item->info;
- old_armor_index = ArmorIndex (other);
+ old_armor_index = ArmorIndex(other);
// handle armor shards specially
- if (ent->item->tag == ARMOR_SHARD)
- {
+ if (ent->item->tag == ARMOR_SHARD) {
if (!old_armor_index)
other->client->pers.inventory[jacket_armor_index] = 2;
else
@@ -628,14 +601,12 @@ qboolean Pickup_Armor (edict_t *ent, edict_t *other)
}
// if player has no armor, just use it
- else if (!old_armor_index)
- {
+ else if (!old_armor_index) {
other->client->pers.inventory[ITEM_INDEX(ent->item)] = newinfo->base_count;
}
// use the better armor
- else
- {
+ else {
// get info on old armor
if (old_armor_index == jacket_armor_index)
oldinfo = &jacketarmor_info;
@@ -644,8 +615,7 @@ qboolean Pickup_Armor (edict_t *ent, edict_t *other)
else // (old_armor_index == body_armor_index)
oldinfo = &bodyarmor_info;
- if (newinfo->normal_protection > oldinfo->normal_protection)
- {
+ if (newinfo->normal_protection > oldinfo->normal_protection) {
// calc new armor values
salvage = oldinfo->normal_protection / newinfo->normal_protection;
salvagecount = salvage * other->client->pers.inventory[old_armor_index];
@@ -658,9 +628,7 @@ qboolean Pickup_Armor (edict_t *ent, edict_t *other)
// change armor to new item with computed value
other->client->pers.inventory[ITEM_INDEX(ent->item)] = newcount;
- }
- else
- {
+ } else {
// calc new armor values
salvage = newinfo->normal_protection / oldinfo->normal_protection;
salvagecount = salvage * newinfo->base_count;
@@ -678,14 +646,14 @@ qboolean Pickup_Armor (edict_t *ent, edict_t *other)
}
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
- SetRespawn (ent, 20);
+ SetRespawn(ent, 20);
return qtrue;
}
//======================================================================
-int PowerArmorType (edict_t *ent)
+int PowerArmorType(edict_t *ent)
{
if (!ent->client)
return POWER_ARMOR_NONE;
@@ -702,21 +670,17 @@ int PowerArmorType (edict_t *ent)
return POWER_ARMOR_NONE;
}
-void Use_PowerArmor (edict_t *ent, gitem_t *item)
+void Use_PowerArmor(edict_t *ent, gitem_t *item)
{
int index;
- if (ent->flags & FL_POWER_ARMOR)
- {
+ if (ent->flags & FL_POWER_ARMOR) {
ent->flags &= ~FL_POWER_ARMOR;
gi.sound(ent, CHAN_AUTO, gi.soundindex("misc/power2.wav"), 1, ATTN_NORM, 0);
- }
- else
- {
+ } else {
index = ITEM_INDEX(FindItem("cells"));
- if (!ent->client->pers.inventory[index])
- {
- gi.cprintf (ent, PRINT_HIGH, "No cells for power armor.\n");
+ if (!ent->client->pers.inventory[index]) {
+ gi.cprintf(ent, PRINT_HIGH, "No cells for power armor.\n");
return;
}
ent->flags |= FL_POWER_ARMOR;
@@ -724,7 +688,7 @@ void Use_PowerArmor (edict_t *ent, gitem_t *item)
}
}
-qboolean Pickup_PowerArmor (edict_t *ent, edict_t *other)
+qboolean Pickup_PowerArmor(edict_t *ent, edict_t *other)
{
int quantity;
@@ -732,23 +696,22 @@ qboolean Pickup_PowerArmor (edict_t *ent, edict_t *other)
other->client->pers.inventory[ITEM_INDEX(ent->item)]++;
- if (deathmatch->value)
- {
- if (!(ent->spawnflags & DROPPED_ITEM) )
- SetRespawn (ent, ent->item->quantity);
+ if (deathmatch->value) {
+ if (!(ent->spawnflags & DROPPED_ITEM))
+ SetRespawn(ent, ent->item->quantity);
// auto-use for DM only if we didn't already have one
if (!quantity)
- ent->item->use (other, ent->item);
+ ent->item->use(other, ent->item);
}
return qtrue;
}
-void Drop_PowerArmor (edict_t *ent, gitem_t *item)
+void Drop_PowerArmor(edict_t *ent, gitem_t *item)
{
if ((ent->flags & FL_POWER_ARMOR) && (ent->client->pers.inventory[ITEM_INDEX(item)] == 1))
- Use_PowerArmor (ent, item);
- Drop_General (ent, item);
+ Use_PowerArmor(ent, item);
+ Drop_General(ent, item);
}
//======================================================================
@@ -758,7 +721,7 @@ void Drop_PowerArmor (edict_t *ent, gitem_t *item)
Touch_Item
===============
*/
-void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
+void Touch_Item(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
qboolean taken;
@@ -771,22 +734,20 @@ void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf
taken = ent->item->pickup(ent, other);
- if (taken)
- {
+ if (taken) {
// flash the screen
- other->client->bonus_alpha = 0.25;
+ other->client->bonus_alpha = 0.25;
// show icon and name on status bar
other->client->ps.stats[STAT_PICKUP_ICON] = gi.imageindex(ent->item->icon);
- other->client->ps.stats[STAT_PICKUP_STRING] = CS_ITEMS+ITEM_INDEX(ent->item);
+ other->client->ps.stats[STAT_PICKUP_STRING] = CS_ITEMS + ITEM_INDEX(ent->item);
other->client->pickup_msg_time = level.time + 3.0;
// change selected item
if (ent->item->use)
other->client->pers.selected_item = other->client->ps.stats[STAT_SELECTED_ITEM] = ITEM_INDEX(ent->item);
- if (ent->item->pickup == Pickup_Health)
- {
+ if (ent->item->pickup == Pickup_Health) {
if (ent->count == 2)
gi.sound(other, CHAN_ITEM, gi.soundindex("items/s_health.wav"), 1, ATTN_NORM, 0);
else if (ent->count == 10)
@@ -795,52 +756,47 @@ void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf
gi.sound(other, CHAN_ITEM, gi.soundindex("items/l_health.wav"), 1, ATTN_NORM, 0);
else // (ent->count == 100)
gi.sound(other, CHAN_ITEM, gi.soundindex("items/m_health.wav"), 1, ATTN_NORM, 0);
- }
- else if (ent->item->pickup_sound)
- {
+ } else if (ent->item->pickup_sound) {
gi.sound(other, CHAN_ITEM, gi.soundindex(ent->item->pickup_sound), 1, ATTN_NORM, 0);
}
}
- if (!(ent->spawnflags & ITEM_TARGETS_USED))
- {
- G_UseTargets (ent, other);
+ if (!(ent->spawnflags & ITEM_TARGETS_USED)) {
+ G_UseTargets(ent, other);
ent->spawnflags |= ITEM_TARGETS_USED;
}
if (!taken)
return;
- if (!((coop->value) && (ent->item->flags & IT_STAY_COOP)) || (ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))
- {
+ if (!((coop->value) && (ent->item->flags & IT_STAY_COOP)) || (ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM))) {
if (ent->flags & FL_RESPAWN)
ent->flags &= ~FL_RESPAWN;
else
- G_FreeEdict (ent);
+ G_FreeEdict(ent);
}
}
//======================================================================
-void drop_temp_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
+void drop_temp_touch(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other == ent->owner)
return;
- Touch_Item (ent, other, plane, surf);
+ Touch_Item(ent, other, plane, surf);
}
-void drop_make_touchable (edict_t *ent)
+void drop_make_touchable(edict_t *ent)
{
ent->touch = Touch_Item;
- if (deathmatch->value)
- {
+ if (deathmatch->value) {
ent->nextthink = level.time + 29;
ent->think = G_FreeEdict;
}
}
-edict_t *Drop_Item (edict_t *ent, gitem_t *item)
+edict_t *Drop_Item(edict_t *ent, gitem_t *item)
{
edict_t *dropped;
vec3_t forward, right;
@@ -853,59 +809,53 @@ edict_t *Drop_Item (edict_t *ent, gitem_t *item)
dropped->spawnflags = DROPPED_ITEM;
dropped->s.effects = item->world_model_flags;
dropped->s.renderfx = RF_GLOW;
- VectorSet (dropped->mins, -15, -15, -15);
- VectorSet (dropped->maxs, 15, 15, 15);
- gi.setmodel (dropped, dropped->item->world_model);
+ VectorSet(dropped->mins, -15, -15, -15);
+ VectorSet(dropped->maxs, 15, 15, 15);
+ gi.setmodel(dropped, dropped->item->world_model);
dropped->solid = SOLID_TRIGGER;
- dropped->movetype = MOVETYPE_TOSS;
+ dropped->movetype = MOVETYPE_TOSS;
dropped->touch = drop_temp_touch;
dropped->owner = ent;
- if (ent->client)
- {
+ if (ent->client) {
trace_t trace;
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
VectorSet(offset, 24, 0, -16);
- G_ProjectSource (ent->s.origin, offset, forward, right, dropped->s.origin);
- trace = gi.trace (ent->s.origin, dropped->mins, dropped->maxs,
- dropped->s.origin, ent, CONTENTS_SOLID);
- VectorCopy (trace.endpos, dropped->s.origin);
- }
- else
- {
- AngleVectors (ent->s.angles, forward, right, NULL);
- VectorCopy (ent->s.origin, dropped->s.origin);
+ G_ProjectSource(ent->s.origin, offset, forward, right, dropped->s.origin);
+ trace = gi.trace(ent->s.origin, dropped->mins, dropped->maxs,
+ dropped->s.origin, ent, CONTENTS_SOLID);
+ VectorCopy(trace.endpos, dropped->s.origin);
+ } else {
+ AngleVectors(ent->s.angles, forward, right, NULL);
+ VectorCopy(ent->s.origin, dropped->s.origin);
}
- VectorScale (forward, 100, dropped->velocity);
+ VectorScale(forward, 100, dropped->velocity);
dropped->velocity[2] = 300;
dropped->think = drop_make_touchable;
dropped->nextthink = level.time + 1;
- gi.linkentity (dropped);
+ gi.linkentity(dropped);
return dropped;
}
-void Use_Item (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Item(edict_t *ent, edict_t *other, edict_t *activator)
{
ent->svflags &= ~SVF_NOCLIENT;
ent->use = NULL;
- if (ent->spawnflags & ITEM_NO_TOUCH)
- {
+ if (ent->spawnflags & ITEM_NO_TOUCH) {
ent->solid = SOLID_BBOX;
ent->touch = NULL;
- }
- else
- {
+ } else {
ent->solid = SOLID_TRIGGER;
ent->touch = Touch_Item;
}
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
//======================================================================
@@ -915,69 +865,64 @@ void Use_Item (edict_t *ent, edict_t *other, edict_t *activator)
droptofloor
================
*/
-void droptofloor (edict_t *ent)
+void droptofloor(edict_t *ent)
{
trace_t tr;
vec3_t dest;
float *v;
- v = tv(-15,-15,-15);
- VectorCopy (v, ent->mins);
- v = tv(15,15,15);
- VectorCopy (v, ent->maxs);
+ v = tv(-15, -15, -15);
+ VectorCopy(v, ent->mins);
+ v = tv(15, 15, 15);
+ VectorCopy(v, ent->maxs);
if (ent->model)
- gi.setmodel (ent, ent->model);
+ gi.setmodel(ent, ent->model);
else
- gi.setmodel (ent, ent->item->world_model);
+ gi.setmodel(ent, ent->item->world_model);
ent->solid = SOLID_TRIGGER;
- ent->movetype = MOVETYPE_TOSS;
+ ent->movetype = MOVETYPE_TOSS;
ent->touch = Touch_Item;
- v = tv(0,0,-128);
- VectorAdd (ent->s.origin, v, dest);
+ v = tv(0, 0, -128);
+ VectorAdd(ent->s.origin, v, dest);
- tr = gi.trace (ent->s.origin, ent->mins, ent->maxs, dest, ent, MASK_SOLID);
- if (tr.startsolid)
- {
- gi.dprintf ("droptofloor: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin));
- G_FreeEdict (ent);
+ tr = gi.trace(ent->s.origin, ent->mins, ent->maxs, dest, ent, MASK_SOLID);
+ if (tr.startsolid) {
+ gi.dprintf("droptofloor: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin));
+ G_FreeEdict(ent);
return;
}
- VectorCopy (tr.endpos, ent->s.origin);
+ VectorCopy(tr.endpos, ent->s.origin);
- if (ent->team)
- {
+ if (ent->team) {
ent->flags &= ~FL_TEAMSLAVE;
ent->chain = ent->teamchain;
ent->teamchain = NULL;
ent->svflags |= SVF_NOCLIENT;
ent->solid = SOLID_NOT;
- if (ent == ent->teammaster)
- {
+ if (ent == ent->teammaster) {
ent->nextthink = level.time + FRAMETIME;
ent->think = DoRespawn;
}
}
- if (ent->spawnflags & ITEM_NO_TOUCH)
- {
+ if (ent->spawnflags & ITEM_NO_TOUCH) {
ent->solid = SOLID_BBOX;
ent->touch = NULL;
ent->s.effects &= ~EF_ROTATE;
ent->s.renderfx &= ~RF_GLOW;
}
- if (ent->spawnflags & ITEM_TRIGGER_SPAWN)
- {
+ if (ent->spawnflags & ITEM_TRIGGER_SPAWN) {
ent->svflags |= SVF_NOCLIENT;
ent->solid = SOLID_NOT;
ent->use = Use_Item;
}
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
@@ -990,7 +935,7 @@ This will be called for each item spawned in a level,
and for each item in each client's inventory.
===============
*/
-void PrecacheItem (gitem_t *it)
+void PrecacheItem(gitem_t *it)
{
char *s, *start;
char data[MAX_QPATH];
@@ -1001,20 +946,19 @@ void PrecacheItem (gitem_t *it)
return;
if (it->pickup_sound)
- gi.soundindex (it->pickup_sound);
+ gi.soundindex(it->pickup_sound);
if (it->world_model)
- gi.modelindex (it->world_model);
+ gi.modelindex(it->world_model);
if (it->view_model)
- gi.modelindex (it->view_model);
+ gi.modelindex(it->view_model);
if (it->icon)
- gi.imageindex (it->icon);
+ gi.imageindex(it->icon);
// parse everything for its ammo
- if (it->ammo && it->ammo[0])
- {
- ammo = FindItem (it->ammo);
+ if (it->ammo && it->ammo[0]) {
+ ammo = FindItem(it->ammo);
if (ammo != it)
- PrecacheItem (ammo);
+ PrecacheItem(ammo);
}
// parse the space seperated precache string for other items
@@ -1022,29 +966,28 @@ void PrecacheItem (gitem_t *it)
if (!s || !s[0])
return;
- while (*s)
- {
+ while (*s) {
start = s;
while (*s && *s != ' ')
s++;
- len = s-start;
+ len = s - start;
if (len >= MAX_QPATH || len < 5)
- gi.error ("PrecacheItem: %s has bad precache string", it->classname);
- memcpy (data, start, len);
+ gi.error("PrecacheItem: %s has bad precache string", it->classname);
+ memcpy(data, start, len);
data[len] = 0;
if (*s)
s++;
// determine type based on extension
- if (!strcmp(data+len-3, "md2"))
- gi.modelindex (data);
- else if (!strcmp(data+len-3, "sp2"))
- gi.modelindex (data);
- else if (!strcmp(data+len-3, "wav"))
- gi.soundindex (data);
- if (!strcmp(data+len-3, "pcx"))
- gi.imageindex (data);
+ if (!strcmp(data + len - 3, "md2"))
+ gi.modelindex(data);
+ else if (!strcmp(data + len - 3, "sp2"))
+ gi.modelindex(data);
+ else if (!strcmp(data + len - 3, "wav"))
+ gi.soundindex(data);
+ if (!strcmp(data + len - 3, "pcx"))
+ gi.imageindex(data);
}
}
@@ -1058,65 +1001,52 @@ Items can't be immediately dropped to floor, because they might
be on an entity that hasn't spawned yet.
============
*/
-void SpawnItem (edict_t *ent, gitem_t *item)
+void SpawnItem(edict_t *ent, gitem_t *item)
{
- PrecacheItem (item);
+ PrecacheItem(item);
- if (ent->spawnflags)
- {
- if (strcmp(ent->classname, "key_power_cube") != 0)
- {
+ if (ent->spawnflags) {
+ if (strcmp(ent->classname, "key_power_cube") != 0) {
ent->spawnflags = 0;
gi.dprintf("%s at %s has invalid spawnflags set\n", ent->classname, vtos(ent->s.origin));
}
}
// some items will be prevented in deathmatch
- if (deathmatch->value)
- {
- if ( (int)dmflags->value & DF_NO_ARMOR )
- {
- if (item->pickup == Pickup_Armor || item->pickup == Pickup_PowerArmor)
- {
- G_FreeEdict (ent);
+ if (deathmatch->value) {
+ if ((int)dmflags->value & DF_NO_ARMOR) {
+ if (item->pickup == Pickup_Armor || item->pickup == Pickup_PowerArmor) {
+ G_FreeEdict(ent);
return;
}
}
- if ( (int)dmflags->value & DF_NO_ITEMS )
- {
- if (item->pickup == Pickup_Powerup)
- {
- G_FreeEdict (ent);
+ if ((int)dmflags->value & DF_NO_ITEMS) {
+ if (item->pickup == Pickup_Powerup) {
+ G_FreeEdict(ent);
return;
}
}
- if ( (int)dmflags->value & DF_NO_HEALTH )
- {
- if (item->pickup == Pickup_Health || item->pickup == Pickup_Adrenaline || item->pickup == Pickup_AncientHead)
- {
- G_FreeEdict (ent);
+ if ((int)dmflags->value & DF_NO_HEALTH) {
+ if (item->pickup == Pickup_Health || item->pickup == Pickup_Adrenaline || item->pickup == Pickup_AncientHead) {
+ G_FreeEdict(ent);
return;
}
}
- if ( (int)dmflags->value & DF_INFINITE_AMMO )
- {
- if ( (item->flags == IT_AMMO) || (strcmp(ent->classname, "weapon_bfg") == 0) )
- {
- G_FreeEdict (ent);
+ if ((int)dmflags->value & DF_INFINITE_AMMO) {
+ if ((item->flags == IT_AMMO) || (strcmp(ent->classname, "weapon_bfg") == 0)) {
+ G_FreeEdict(ent);
return;
}
}
}
- if (coop->value && (strcmp(ent->classname, "key_power_cube") == 0))
- {
+ if (coop->value && (strcmp(ent->classname, "key_power_cube") == 0)) {
ent->spawnflags |= (1 << (8 + level.power_cubes));
level.power_cubes++;
}
// don't let them drop items that stay in a coop game
- if ((coop->value) && (item->flags & IT_STAY_COOP))
- {
+ if ((coop->value) && (item->flags & IT_STAY_COOP)) {
item->drop = NULL;
}
@@ -1126,13 +1056,12 @@ void SpawnItem (edict_t *ent, gitem_t *item)
ent->s.effects = item->world_model_flags;
ent->s.renderfx = RF_GLOW;
if (ent->model)
- gi.modelindex (ent->model);
+ gi.modelindex(ent->model);
}
//======================================================================
-gitem_t itemlist[] =
-{
+gitem_t itemlist[] = {
{
NULL
}, // leave index 0 alone
@@ -1141,10 +1070,10 @@ gitem_t itemlist[] =
// ARMOR
//
-/*QUAKED item_armor_body (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_armor_body (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_armor_body",
+ "item_armor_body",
Pickup_Armor,
NULL,
NULL,
@@ -1152,22 +1081,22 @@ gitem_t itemlist[] =
"misc/ar1_pkup.wav",
"models/items/armor/body/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_bodyarmor",
-/* pickup */ "Body Armor",
-/* width */ 3,
+ /* icon */ "i_bodyarmor",
+ /* pickup */ "Body Armor",
+ /* width */ 3,
0,
NULL,
IT_ARMOR,
0,
&bodyarmor_info,
ARMOR_BODY,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_armor_combat (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_armor_combat (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_armor_combat",
+ "item_armor_combat",
Pickup_Armor,
NULL,
NULL,
@@ -1175,22 +1104,22 @@ gitem_t itemlist[] =
"misc/ar1_pkup.wav",
"models/items/armor/combat/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_combatarmor",
-/* pickup */ "Combat Armor",
-/* width */ 3,
+ /* icon */ "i_combatarmor",
+ /* pickup */ "Combat Armor",
+ /* width */ 3,
0,
NULL,
IT_ARMOR,
0,
&combatarmor_info,
ARMOR_COMBAT,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_armor_jacket (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_armor_jacket (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_armor_jacket",
+ "item_armor_jacket",
Pickup_Armor,
NULL,
NULL,
@@ -1198,22 +1127,22 @@ gitem_t itemlist[] =
"misc/ar1_pkup.wav",
"models/items/armor/jacket/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_jacketarmor",
-/* pickup */ "Jacket Armor",
-/* width */ 3,
+ /* icon */ "i_jacketarmor",
+ /* pickup */ "Jacket Armor",
+ /* width */ 3,
0,
NULL,
IT_ARMOR,
0,
&jacketarmor_info,
ARMOR_JACKET,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_armor_shard (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_armor_shard (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_armor_shard",
+ "item_armor_shard",
Pickup_Armor,
NULL,
NULL,
@@ -1221,23 +1150,23 @@ gitem_t itemlist[] =
"misc/ar2_pkup.wav",
"models/items/armor/shard/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_jacketarmor",
-/* pickup */ "Armor Shard",
-/* width */ 3,
+ /* icon */ "i_jacketarmor",
+ /* pickup */ "Armor Shard",
+ /* width */ 3,
0,
NULL,
IT_ARMOR,
0,
NULL,
ARMOR_SHARD,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_power_screen (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_power_screen (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_power_screen",
+ "item_power_screen",
Pickup_PowerArmor,
Use_PowerArmor,
Drop_PowerArmor,
@@ -1245,20 +1174,20 @@ gitem_t itemlist[] =
"misc/ar3_pkup.wav",
"models/items/armor/screen/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_powerscreen",
-/* pickup */ "Power Screen",
-/* width */ 0,
+ /* icon */ "i_powerscreen",
+ /* pickup */ "Power Screen",
+ /* width */ 0,
60,
NULL,
IT_ARMOR,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_power_shield (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_power_shield (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_power_shield",
Pickup_PowerArmor,
@@ -1268,28 +1197,28 @@ gitem_t itemlist[] =
"misc/ar3_pkup.wav",
"models/items/armor/shield/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_powershield",
-/* pickup */ "Power Shield",
-/* width */ 0,
+ /* icon */ "i_powershield",
+ /* pickup */ "Power Shield",
+ /* width */ 0,
60,
NULL,
IT_ARMOR,
0,
NULL,
0,
-/* precache */ "misc/power2.wav misc/power1.wav"
+ /* precache */ "misc/power2.wav misc/power1.wav"
},
//
- // WEAPONS
+ // WEAPONS
//
-/* weapon_blaster (.3 .3 1) (-16 -16 -16) (16 16 16)
-always owned, never in the world
-*/
+ /* weapon_blaster (.3 .3 1) (-16 -16 -16) (16 16 16)
+ always owned, never in the world
+ */
{
- "weapon_blaster",
+ "weapon_blaster",
NULL,
Use_Weapon,
NULL,
@@ -1297,22 +1226,22 @@ always owned, never in the world
"misc/w_pkup.wav",
NULL, 0,
"models/weapons/v_blast/tris.md2",
-/* icon */ "w_blaster",
-/* pickup */ "Blaster",
+ /* icon */ "w_blaster",
+ /* pickup */ "Blaster",
0,
0,
NULL,
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_BLASTER,
NULL,
0,
-/* precache */ "weapons/blastf1a.wav misc/lasfly.wav"
+ /* precache */ "weapons/blastf1a.wav misc/lasfly.wav"
},
-/*QUAKED weapon_shotgun (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_shotgun (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_shotgun",
+ "weapon_shotgun",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1320,22 +1249,22 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_shotg/tris.md2", EF_ROTATE,
"models/weapons/v_shotg/tris.md2",
-/* icon */ "w_shotgun",
-/* pickup */ "Shotgun",
+ /* icon */ "w_shotgun",
+ /* pickup */ "Shotgun",
0,
1,
"Shells",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_SHOTGUN,
NULL,
0,
-/* precache */ "weapons/shotgf1b.wav weapons/shotgr1b.wav"
+ /* precache */ "weapons/shotgf1b.wav weapons/shotgr1b.wav"
},
-/*QUAKED weapon_supershotgun (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_supershotgun (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_supershotgun",
+ "weapon_supershotgun",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1343,22 +1272,22 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_shotg2/tris.md2", EF_ROTATE,
"models/weapons/v_shotg2/tris.md2",
-/* icon */ "w_sshotgun",
-/* pickup */ "Super Shotgun",
+ /* icon */ "w_sshotgun",
+ /* pickup */ "Super Shotgun",
0,
2,
"Shells",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_SUPERSHOTGUN,
NULL,
0,
-/* precache */ "weapons/sshotf1b.wav"
+ /* precache */ "weapons/sshotf1b.wav"
},
-/*QUAKED weapon_machinegun (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_machinegun (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_machinegun",
+ "weapon_machinegun",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1366,22 +1295,22 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_machn/tris.md2", EF_ROTATE,
"models/weapons/v_machn/tris.md2",
-/* icon */ "w_machinegun",
-/* pickup */ "Machinegun",
+ /* icon */ "w_machinegun",
+ /* pickup */ "Machinegun",
0,
1,
"Bullets",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_MACHINEGUN,
NULL,
0,
-/* precache */ "weapons/machgf1b.wav weapons/machgf2b.wav weapons/machgf3b.wav weapons/machgf4b.wav weapons/machgf5b.wav"
+ /* precache */ "weapons/machgf1b.wav weapons/machgf2b.wav weapons/machgf3b.wav weapons/machgf4b.wav weapons/machgf5b.wav"
},
-/*QUAKED weapon_chaingun (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_chaingun (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_chaingun",
+ "weapon_chaingun",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1389,20 +1318,20 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_chain/tris.md2", EF_ROTATE,
"models/weapons/v_chain/tris.md2",
-/* icon */ "w_chaingun",
-/* pickup */ "Chaingun",
+ /* icon */ "w_chaingun",
+ /* pickup */ "Chaingun",
0,
1,
"Bullets",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_CHAINGUN,
NULL,
0,
-/* precache */ "weapons/chngnu1a.wav weapons/chngnl1a.wav weapons/machgf3b.wav` weapons/chngnd1a.wav"
+ /* precache */ "weapons/chngnu1a.wav weapons/chngnl1a.wav weapons/machgf3b.wav` weapons/chngnd1a.wav"
},
-/*QUAKED ammo_grenades (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_grenades (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_grenades",
Pickup_Ammo,
@@ -1412,20 +1341,20 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/grenades/medium/tris.md2", 0,
"models/weapons/v_handgr/tris.md2",
-/* icon */ "a_grenades",
-/* pickup */ "Grenades",
-/* width */ 3,
+ /* icon */ "a_grenades",
+ /* pickup */ "Grenades",
+ /* width */ 3,
5,
"grenades",
- IT_AMMO|IT_WEAPON,
+ IT_AMMO | IT_WEAPON,
WEAP_GRENADES,
NULL,
AMMO_GRENADES,
-/* precache */ "weapons/hgrent1a.wav weapons/hgrena1b.wav weapons/hgrenc1b.wav weapons/hgrenb1a.wav weapons/hgrenb2a.wav "
+ /* precache */ "weapons/hgrent1a.wav weapons/hgrena1b.wav weapons/hgrenc1b.wav weapons/hgrenb1a.wav weapons/hgrenb2a.wav "
},
-/*QUAKED weapon_grenadelauncher (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_grenadelauncher (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"weapon_grenadelauncher",
Pickup_Weapon,
@@ -1435,20 +1364,20 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_launch/tris.md2", EF_ROTATE,
"models/weapons/v_launch/tris.md2",
-/* icon */ "w_glauncher",
-/* pickup */ "Grenade Launcher",
+ /* icon */ "w_glauncher",
+ /* pickup */ "Grenade Launcher",
0,
1,
"Grenades",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_GRENADELAUNCHER,
NULL,
0,
-/* precache */ "models/objects/grenade/tris.md2 weapons/grenlf1a.wav weapons/grenlr1b.wav weapons/grenlb1b.wav"
+ /* precache */ "models/objects/grenade/tris.md2 weapons/grenlf1a.wav weapons/grenlr1b.wav weapons/grenlb1b.wav"
},
-/*QUAKED weapon_rocketlauncher (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_rocketlauncher (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"weapon_rocketlauncher",
Pickup_Weapon,
@@ -1458,22 +1387,22 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_rocket/tris.md2", EF_ROTATE,
"models/weapons/v_rocket/tris.md2",
-/* icon */ "w_rlauncher",
-/* pickup */ "Rocket Launcher",
+ /* icon */ "w_rlauncher",
+ /* pickup */ "Rocket Launcher",
0,
1,
"Rockets",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_ROCKETLAUNCHER,
NULL,
0,
-/* precache */ "models/objects/rocket/tris.md2 weapons/rockfly.wav weapons/rocklf1a.wav weapons/rocklr1b.wav models/objects/debris2/tris.md2"
+ /* precache */ "models/objects/rocket/tris.md2 weapons/rockfly.wav weapons/rocklf1a.wav weapons/rocklr1b.wav models/objects/debris2/tris.md2"
},
-/*QUAKED weapon_hyperblaster (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_hyperblaster (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_hyperblaster",
+ "weapon_hyperblaster",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1481,22 +1410,22 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_hyperb/tris.md2", EF_ROTATE,
"models/weapons/v_hyperb/tris.md2",
-/* icon */ "w_hyperblaster",
-/* pickup */ "HyperBlaster",
+ /* icon */ "w_hyperblaster",
+ /* pickup */ "HyperBlaster",
0,
1,
"Cells",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_HYPERBLASTER,
NULL,
0,
-/* precache */ "weapons/hyprbu1a.wav weapons/hyprbl1a.wav weapons/hyprbf1a.wav weapons/hyprbd1a.wav misc/lasfly.wav"
+ /* precache */ "weapons/hyprbu1a.wav weapons/hyprbl1a.wav weapons/hyprbf1a.wav weapons/hyprbd1a.wav misc/lasfly.wav"
},
-/*QUAKED weapon_railgun (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_railgun (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "weapon_railgun",
+ "weapon_railgun",
Pickup_Weapon,
Use_Weapon,
Drop_Weapon,
@@ -1504,20 +1433,20 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_rail/tris.md2", EF_ROTATE,
"models/weapons/v_rail/tris.md2",
-/* icon */ "w_railgun",
-/* pickup */ "Railgun",
+ /* icon */ "w_railgun",
+ /* pickup */ "Railgun",
0,
1,
"Slugs",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_RAILGUN,
NULL,
0,
-/* precache */ "weapons/rg_hum.wav"
+ /* precache */ "weapons/rg_hum.wav"
},
-/*QUAKED weapon_bfg (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED weapon_bfg (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"weapon_bfg",
Pickup_Weapon,
@@ -1527,24 +1456,24 @@ always owned, never in the world
"misc/w_pkup.wav",
"models/weapons/g_bfg/tris.md2", EF_ROTATE,
"models/weapons/v_bfg/tris.md2",
-/* icon */ "w_bfg",
-/* pickup */ "BFG10K",
+ /* icon */ "w_bfg",
+ /* pickup */ "BFG10K",
0,
50,
"Cells",
- IT_WEAPON|IT_STAY_COOP,
+ IT_WEAPON | IT_STAY_COOP,
WEAP_BFG,
NULL,
0,
-/* precache */ "sprites/s_bfg1.sp2 sprites/s_bfg2.sp2 sprites/s_bfg3.sp2 weapons/bfg__f1y.wav weapons/bfg__l1a.wav weapons/bfg__x1b.wav weapons/bfg_hum.wav"
+ /* precache */ "sprites/s_bfg1.sp2 sprites/s_bfg2.sp2 sprites/s_bfg3.sp2 weapons/bfg__f1y.wav weapons/bfg__l1a.wav weapons/bfg__x1b.wav weapons/bfg_hum.wav"
},
//
// AMMO ITEMS
//
-/*QUAKED ammo_shells (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_shells (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_shells",
Pickup_Ammo,
@@ -1554,20 +1483,20 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/shells/medium/tris.md2", 0,
NULL,
-/* icon */ "a_shells",
-/* pickup */ "Shells",
-/* width */ 3,
+ /* icon */ "a_shells",
+ /* pickup */ "Shells",
+ /* width */ 3,
10,
NULL,
IT_AMMO,
0,
NULL,
AMMO_SHELLS,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED ammo_bullets (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_bullets (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_bullets",
Pickup_Ammo,
@@ -1577,20 +1506,20 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/bullets/medium/tris.md2", 0,
NULL,
-/* icon */ "a_bullets",
-/* pickup */ "Bullets",
-/* width */ 3,
+ /* icon */ "a_bullets",
+ /* pickup */ "Bullets",
+ /* width */ 3,
50,
NULL,
IT_AMMO,
0,
NULL,
AMMO_BULLETS,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED ammo_cells (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_cells (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_cells",
Pickup_Ammo,
@@ -1600,20 +1529,20 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/cells/medium/tris.md2", 0,
NULL,
-/* icon */ "a_cells",
-/* pickup */ "Cells",
-/* width */ 3,
+ /* icon */ "a_cells",
+ /* pickup */ "Cells",
+ /* width */ 3,
50,
NULL,
IT_AMMO,
0,
NULL,
AMMO_CELLS,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED ammo_rockets (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_rockets (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_rockets",
Pickup_Ammo,
@@ -1623,20 +1552,20 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/rockets/medium/tris.md2", 0,
NULL,
-/* icon */ "a_rockets",
-/* pickup */ "Rockets",
-/* width */ 3,
+ /* icon */ "a_rockets",
+ /* pickup */ "Rockets",
+ /* width */ 3,
5,
NULL,
IT_AMMO,
0,
NULL,
AMMO_ROCKETS,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED ammo_slugs (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED ammo_slugs (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"ammo_slugs",
Pickup_Ammo,
@@ -1646,26 +1575,26 @@ always owned, never in the world
"misc/am_pkup.wav",
"models/items/ammo/slugs/medium/tris.md2", 0,
NULL,
-/* icon */ "a_slugs",
-/* pickup */ "Slugs",
-/* width */ 3,
+ /* icon */ "a_slugs",
+ /* pickup */ "Slugs",
+ /* width */ 3,
10,
NULL,
IT_AMMO,
0,
NULL,
AMMO_SLUGS,
-/* precache */ ""
+ /* precache */ ""
},
//
// POWERUP ITEMS
//
-/*QUAKED item_quad (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_quad (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
- "item_quad",
+ "item_quad",
Pickup_Powerup,
Use_Quad,
Drop_General,
@@ -1673,20 +1602,20 @@ always owned, never in the world
"items/pkup.wav",
"models/items/quaddama/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_quad",
-/* pickup */ "Quad Damage",
-/* width */ 2,
+ /* icon */ "p_quad",
+ /* pickup */ "Quad Damage",
+ /* width */ 2,
60,
NULL,
IT_POWERUP,
0,
NULL,
0,
-/* precache */ "items/damage.wav items/damage2.wav items/damage3.wav"
+ /* precache */ "items/damage.wav items/damage2.wav items/damage3.wav"
},
-/*QUAKED item_invulnerability (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_invulnerability (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_invulnerability",
Pickup_Powerup,
@@ -1696,20 +1625,20 @@ always owned, never in the world
"items/pkup.wav",
"models/items/invulner/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_invulnerability",
-/* pickup */ "Invulnerability",
-/* width */ 2,
+ /* icon */ "p_invulnerability",
+ /* pickup */ "Invulnerability",
+ /* width */ 2,
300,
NULL,
IT_POWERUP,
0,
NULL,
0,
-/* precache */ "items/protect.wav items/protect2.wav items/protect4.wav"
+ /* precache */ "items/protect.wav items/protect2.wav items/protect4.wav"
},
-/*QUAKED item_silencer (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_silencer (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_silencer",
Pickup_Powerup,
@@ -1719,20 +1648,20 @@ always owned, never in the world
"items/pkup.wav",
"models/items/silencer/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_silencer",
-/* pickup */ "Silencer",
-/* width */ 2,
+ /* icon */ "p_silencer",
+ /* pickup */ "Silencer",
+ /* width */ 2,
60,
NULL,
IT_POWERUP,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_breather (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_breather (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_breather",
Pickup_Powerup,
@@ -1742,20 +1671,20 @@ always owned, never in the world
"items/pkup.wav",
"models/items/breather/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_rebreather",
-/* pickup */ "Rebreather",
-/* width */ 2,
+ /* icon */ "p_rebreather",
+ /* pickup */ "Rebreather",
+ /* width */ 2,
60,
NULL,
- IT_STAY_COOP|IT_POWERUP,
+ IT_STAY_COOP | IT_POWERUP,
0,
NULL,
0,
-/* precache */ "items/airout.wav"
+ /* precache */ "items/airout.wav"
},
-/*QUAKED item_enviro (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_enviro (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_enviro",
Pickup_Powerup,
@@ -1765,21 +1694,21 @@ always owned, never in the world
"items/pkup.wav",
"models/items/enviro/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_envirosuit",
-/* pickup */ "Environment Suit",
-/* width */ 2,
+ /* icon */ "p_envirosuit",
+ /* pickup */ "Environment Suit",
+ /* width */ 2,
60,
NULL,
- IT_STAY_COOP|IT_POWERUP,
+ IT_STAY_COOP | IT_POWERUP,
0,
NULL,
0,
-/* precache */ "items/airout.wav"
+ /* precache */ "items/airout.wav"
},
-/*QUAKED item_ancient_head (.3 .3 1) (-16 -16 -16) (16 16 16)
-Special item that gives +2 to maximum health
-*/
+ /*QUAKED item_ancient_head (.3 .3 1) (-16 -16 -16) (16 16 16)
+ Special item that gives +2 to maximum health
+ */
{
"item_ancient_head",
Pickup_AncientHead,
@@ -1789,21 +1718,21 @@ Special item that gives +2 to maximum health
"items/pkup.wav",
"models/items/c_head/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_fixme",
-/* pickup */ "Ancient Head",
-/* width */ 2,
+ /* icon */ "i_fixme",
+ /* pickup */ "Ancient Head",
+ /* width */ 2,
60,
NULL,
0,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_adrenaline (.3 .3 1) (-16 -16 -16) (16 16 16)
-gives +1 to maximum health
-*/
+ /*QUAKED item_adrenaline (.3 .3 1) (-16 -16 -16) (16 16 16)
+ gives +1 to maximum health
+ */
{
"item_adrenaline",
Pickup_Adrenaline,
@@ -1813,20 +1742,20 @@ gives +1 to maximum health
"items/pkup.wav",
"models/items/adrenal/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_adrenaline",
-/* pickup */ "Adrenaline",
-/* width */ 2,
+ /* icon */ "p_adrenaline",
+ /* pickup */ "Adrenaline",
+ /* width */ 2,
60,
NULL,
0,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_bandolier (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_bandolier (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_bandolier",
Pickup_Bandolier,
@@ -1836,20 +1765,20 @@ gives +1 to maximum health
"items/pkup.wav",
"models/items/band/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "p_bandolier",
-/* pickup */ "Bandolier",
-/* width */ 2,
+ /* icon */ "p_bandolier",
+ /* pickup */ "Bandolier",
+ /* width */ 2,
60,
NULL,
0,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED item_pack (.3 .3 1) (-16 -16 -16) (16 16 16)
-*/
+ /*QUAKED item_pack (.3 .3 1) (-16 -16 -16) (16 16 16)
+ */
{
"item_pack",
Pickup_Pack,
@@ -1859,24 +1788,24 @@ gives +1 to maximum health
"items/pkup.wav",
"models/items/pack/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_pack",
-/* pickup */ "Ammo Pack",
-/* width */ 2,
+ /* icon */ "i_pack",
+ /* pickup */ "Ammo Pack",
+ /* width */ 2,
180,
NULL,
0,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
//
// KEYS
//
-/*QUAKED key_data_cd (0 .5 .8) (-16 -16 -16) (16 16 16)
-key for computer centers
-*/
+ /*QUAKED key_data_cd (0 .5 .8) (-16 -16 -16) (16 16 16)
+ key for computer centers
+ */
{
"key_data_cd",
Pickup_Key,
@@ -1891,16 +1820,16 @@ key for computer centers
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_power_cube (0 .5 .8) (-16 -16 -16) (16 16 16) TRIGGER_SPAWN NO_TOUCH
-warehouse circuits
-*/
+ /*QUAKED key_power_cube (0 .5 .8) (-16 -16 -16) (16 16 16) TRIGGER_SPAWN NO_TOUCH
+ warehouse circuits
+ */
{
"key_power_cube",
Pickup_Key,
@@ -1915,16 +1844,16 @@ warehouse circuits
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_pyramid (0 .5 .8) (-16 -16 -16) (16 16 16)
-key for the entrance of jail3
-*/
+ /*QUAKED key_pyramid (0 .5 .8) (-16 -16 -16) (16 16 16)
+ key for the entrance of jail3
+ */
{
"key_pyramid",
Pickup_Key,
@@ -1939,16 +1868,16 @@ key for the entrance of jail3
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_data_spinner (0 .5 .8) (-16 -16 -16) (16 16 16)
-key for the city computer
-*/
+ /*QUAKED key_data_spinner (0 .5 .8) (-16 -16 -16) (16 16 16)
+ key for the city computer
+ */
{
"key_data_spinner",
Pickup_Key,
@@ -1963,16 +1892,16 @@ key for the city computer
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_pass (0 .5 .8) (-16 -16 -16) (16 16 16)
-security pass for the security level
-*/
+ /*QUAKED key_pass (0 .5 .8) (-16 -16 -16) (16 16 16)
+ security pass for the security level
+ */
{
"key_pass",
Pickup_Key,
@@ -1987,16 +1916,16 @@ security pass for the security level
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_blue_key (0 .5 .8) (-16 -16 -16) (16 16 16)
-normal door key - blue
-*/
+ /*QUAKED key_blue_key (0 .5 .8) (-16 -16 -16) (16 16 16)
+ normal door key - blue
+ */
{
"key_blue_key",
Pickup_Key,
@@ -2011,16 +1940,16 @@ normal door key - blue
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_red_key (0 .5 .8) (-16 -16 -16) (16 16 16)
-normal door key - red
-*/
+ /*QUAKED key_red_key (0 .5 .8) (-16 -16 -16) (16 16 16)
+ normal door key - red
+ */
{
"key_red_key",
Pickup_Key,
@@ -2035,16 +1964,16 @@ normal door key - red
2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_commander_head (0 .5 .8) (-16 -16 -16) (16 16 16)
-tank commander's head
-*/
+ /*QUAKED key_commander_head (0 .5 .8) (-16 -16 -16) (16 16 16)
+ tank commander's head
+ */
{
"key_commander_head",
Pickup_Key,
@@ -2054,21 +1983,21 @@ tank commander's head
"items/pkup.wav",
"models/monsters/commandr/head/tris.md2", EF_GIB,
NULL,
-/* icon */ "k_comhead",
-/* pickup */ "Commander's Head",
-/* width */ 2,
+ /* icon */ "k_comhead",
+ /* pickup */ "Commander's Head",
+ /* width */ 2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
-/*QUAKED key_airstrike_target (0 .5 .8) (-16 -16 -16) (16 16 16)
-tank commander's head
-*/
+ /*QUAKED key_airstrike_target (0 .5 .8) (-16 -16 -16) (16 16 16)
+ tank commander's head
+ */
{
"key_airstrike_target",
Pickup_Key,
@@ -2078,16 +2007,16 @@ tank commander's head
"items/pkup.wav",
"models/items/keys/target/tris.md2", EF_ROTATE,
NULL,
-/* icon */ "i_airstrike",
-/* pickup */ "Airstrike Marker",
-/* width */ 2,
+ /* icon */ "i_airstrike",
+ /* pickup */ "Airstrike Marker",
+ /* width */ 2,
0,
NULL,
- IT_STAY_COOP|IT_KEY,
+ IT_STAY_COOP | IT_KEY,
0,
NULL,
0,
-/* precache */ ""
+ /* precache */ ""
},
{
@@ -2099,16 +2028,16 @@ tank commander's head
"items/pkup.wav",
NULL, 0,
NULL,
-/* icon */ "i_health",
-/* pickup */ "Health",
-/* width */ 3,
+ /* icon */ "i_health",
+ /* pickup */ "Health",
+ /* width */ 3,
0,
NULL,
0,
0,
NULL,
0,
-/* precache */ "items/s_health.wav items/n_health.wav items/l_health.wav items/m_health.wav"
+ /* precache */ "items/s_health.wav items/n_health.wav items/l_health.wav items/m_health.wav"
},
// end of list marker
@@ -2118,74 +2047,70 @@ tank commander's head
/*QUAKED item_health (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
-void SP_item_health (edict_t *self)
+void SP_item_health(edict_t *self)
{
- if ( deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH) )
- {
- G_FreeEdict (self);
+ if (deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH)) {
+ G_FreeEdict(self);
return;
}
self->model = "models/items/healing/medium/tris.md2";
self->count = 10;
- SpawnItem (self, FindItem ("Health"));
- gi.soundindex ("items/n_health.wav");
+ SpawnItem(self, FindItem("Health"));
+ gi.soundindex("items/n_health.wav");
}
/*QUAKED item_health_small (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
-void SP_item_health_small (edict_t *self)
+void SP_item_health_small(edict_t *self)
{
- if ( deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH) )
- {
- G_FreeEdict (self);
+ if (deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH)) {
+ G_FreeEdict(self);
return;
}
self->model = "models/items/healing/stimpack/tris.md2";
self->count = 2;
- SpawnItem (self, FindItem ("Health"));
+ SpawnItem(self, FindItem("Health"));
self->style = HEALTH_IGNORE_MAX;
- gi.soundindex ("items/s_health.wav");
+ gi.soundindex("items/s_health.wav");
}
/*QUAKED item_health_large (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
-void SP_item_health_large (edict_t *self)
+void SP_item_health_large(edict_t *self)
{
- if ( deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH) )
- {
- G_FreeEdict (self);
+ if (deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH)) {
+ G_FreeEdict(self);
return;
}
self->model = "models/items/healing/large/tris.md2";
self->count = 25;
- SpawnItem (self, FindItem ("Health"));
- gi.soundindex ("items/l_health.wav");
+ SpawnItem(self, FindItem("Health"));
+ gi.soundindex("items/l_health.wav");
}
/*QUAKED item_health_mega (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
-void SP_item_health_mega (edict_t *self)
+void SP_item_health_mega(edict_t *self)
{
- if ( deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH) )
- {
- G_FreeEdict (self);
+ if (deathmatch->value && ((int)dmflags->value & DF_NO_HEALTH)) {
+ G_FreeEdict(self);
return;
}
self->model = "models/items/mega_h/tris.md2";
self->count = 100;
- SpawnItem (self, FindItem ("Health"));
- gi.soundindex ("items/m_health.wav");
- self->style = HEALTH_IGNORE_MAX|HEALTH_TIMED;
+ SpawnItem(self, FindItem("Health"));
+ gi.soundindex("items/m_health.wav");
+ self->style = HEALTH_IGNORE_MAX | HEALTH_TIMED;
}
-void InitItems (void)
+void InitItems(void)
{
- game.num_items = sizeof(itemlist)/sizeof(itemlist[0]) - 1;
+ game.num_items = sizeof(itemlist) / sizeof(itemlist[0]) - 1;
}
@@ -2197,15 +2122,14 @@ SetItemNames
Called by worldspawn
===============
*/
-void SetItemNames (void)
+void SetItemNames(void)
{
int i;
gitem_t *it;
- for (i=0 ; i<game.num_items ; i++)
- {
+ for (i = 0 ; i < game.num_items ; i++) {
it = &itemlist[i];
- gi.configstring (CS_ITEMS+i, it->pickup_name);
+ gi.configstring(CS_ITEMS + i, it->pickup_name);
}
jacket_armor_index = ITEM_INDEX(FindItem("Jacket Armor"));
diff --git a/src/baseq2/g_local.h b/src/baseq2/g_local.h
index bffbf1b..4586c8f 100644
--- a/src/baseq2/g_local.h
+++ b/src/baseq2/g_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -86,23 +86,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BODY_QUEUE_SIZE 8
-typedef enum
-{
+typedef enum {
DAMAGE_NO,
DAMAGE_YES, // will take damage if hit
DAMAGE_AIM // auto targeting recognizes this
} damage_t;
-typedef enum
-{
- WEAPON_READY,
+typedef enum {
+ WEAPON_READY,
WEAPON_ACTIVATING,
WEAPON_DROPPING,
WEAPON_FIRING
} weaponstate_t;
-typedef enum
-{
+typedef enum {
AMMO_BULLETS,
AMMO_SHELLS,
AMMO_ROCKETS,
@@ -188,25 +185,23 @@ typedef enum
// edict->movetype values
-typedef enum
-{
-MOVETYPE_NONE, // never moves
-MOVETYPE_NOCLIP, // origin and angles change with no interaction
-MOVETYPE_PUSH, // no clip to world, push on box contact
-MOVETYPE_STOP, // no clip to world, stops on box contact
-
-MOVETYPE_WALK, // gravity
-MOVETYPE_STEP, // gravity, special edge handling
-MOVETYPE_FLY,
-MOVETYPE_TOSS, // gravity
-MOVETYPE_FLYMISSILE, // extra size to monsters
-MOVETYPE_BOUNCE
+typedef enum {
+ MOVETYPE_NONE, // never moves
+ MOVETYPE_NOCLIP, // origin and angles change with no interaction
+ MOVETYPE_PUSH, // no clip to world, push on box contact
+ MOVETYPE_STOP, // no clip to world, stops on box contact
+
+ MOVETYPE_WALK, // gravity
+ MOVETYPE_STEP, // gravity, special edge handling
+ MOVETYPE_FLY,
+ MOVETYPE_TOSS, // gravity
+ MOVETYPE_FLYMISSILE, // extra size to monsters
+ MOVETYPE_BOUNCE
} movetype_t;
-typedef struct
-{
+typedef struct {
int base_count;
int max_count;
float normal_protection;
@@ -224,20 +219,19 @@ typedef struct
#define IT_POWERUP 32
// gitem_t->weapmodel for weapons indicates model index
-#define WEAP_BLASTER 1
-#define WEAP_SHOTGUN 2
-#define WEAP_SUPERSHOTGUN 3
-#define WEAP_MACHINEGUN 4
-#define WEAP_CHAINGUN 5
-#define WEAP_GRENADES 6
-#define WEAP_GRENADELAUNCHER 7
-#define WEAP_ROCKETLAUNCHER 8
-#define WEAP_HYPERBLASTER 9
+#define WEAP_BLASTER 1
+#define WEAP_SHOTGUN 2
+#define WEAP_SUPERSHOTGUN 3
+#define WEAP_MACHINEGUN 4
+#define WEAP_CHAINGUN 5
+#define WEAP_GRENADES 6
+#define WEAP_GRENADELAUNCHER 7
+#define WEAP_ROCKETLAUNCHER 8
+#define WEAP_HYPERBLASTER 9
#define WEAP_RAILGUN 10
#define WEAP_BFG 11
-typedef struct gitem_s
-{
+typedef struct gitem_s {
char *classname; // spawning name
qboolean (*pickup)(struct edict_s *ent, struct edict_s *other);
void (*use)(struct edict_s *ent, struct gitem_s *item);
@@ -251,7 +245,7 @@ typedef struct gitem_s
// client side info
char *icon;
char *pickup_name; // for printing on pickup
- int count_width; // number of digits to display by icon
+ int count_width; // number of digits to display by icon
int quantity; // for ammo how much, for weapons how much is used per shot
char *ammo; // for weapons
@@ -272,8 +266,7 @@ typedef struct gitem_s
// it should be initialized at dll load time, and read/written to
// the server.ssv file for savegames
//
-typedef struct
-{
+typedef struct {
char helpmessage1[512];
char helpmessage2[512];
int helpchanged; // flash F1 icon if non 0, play sound
@@ -303,8 +296,7 @@ typedef struct
// this structure is cleared as each map is entered
// it is read/written to the level.sav file for savegames
//
-typedef struct
-{
+typedef struct {
int framenum;
float time;
@@ -349,8 +341,7 @@ typedef struct
// spawn_temp_t is only used to hold entity field values that
// can be set from the editor, but aren't actualy present
// in edict_t during gameplay
-typedef struct
-{
+typedef struct {
// world vars
char *sky;
float skyrotate;
@@ -372,8 +363,7 @@ typedef struct
} spawn_temp_t;
-typedef struct
-{
+typedef struct {
// fixed data
vec3_t start_origin;
vec3_t start_angles;
@@ -403,23 +393,20 @@ typedef struct
} moveinfo_t;
-typedef struct
-{
+typedef struct {
void (*aifunc)(edict_t *self, float dist);
float dist;
void (*thinkfunc)(edict_t *self);
} mframe_t;
-typedef struct
-{
+typedef struct {
int firstframe;
int lastframe;
mframe_t *frame;
void (*endfunc)(edict_t *self);
} mmove_t;
-typedef struct
-{
+typedef struct {
mmove_t *currentmove;
int aiflags;
int nextframe;
@@ -578,7 +565,7 @@ typedef enum {
F_BAD,
F_BYTE,
F_SHORT,
- F_INT,
+ F_INT,
F_FLOAT,
F_LSTRING, // string on disk, pointer in memory, TAG_LEVEL
F_GSTRING, // string on disk, pointer in memory, TAG_GAME
@@ -598,62 +585,62 @@ extern gitem_t itemlist[];
//
// g_cmds.c
//
-void Cmd_Help_f (edict_t *ent);
-void Cmd_Score_f (edict_t *ent);
+void Cmd_Help_f(edict_t *ent);
+void Cmd_Score_f(edict_t *ent);
//
// g_items.c
//
-void PrecacheItem (gitem_t *it);
-void InitItems (void);
-void SetItemNames (void);
-gitem_t *FindItem (char *pickup_name);
-gitem_t *FindItemByClassname (char *classname);
+void PrecacheItem(gitem_t *it);
+void InitItems(void);
+void SetItemNames(void);
+gitem_t *FindItem(char *pickup_name);
+gitem_t *FindItemByClassname(char *classname);
#define ITEM_INDEX(x) ((x)-itemlist)
-edict_t *Drop_Item (edict_t *ent, gitem_t *item);
-void SetRespawn (edict_t *ent, float delay);
-void ChangeWeapon (edict_t *ent);
-void SpawnItem (edict_t *ent, gitem_t *item);
-void Think_Weapon (edict_t *ent);
-int ArmorIndex (edict_t *ent);
-int PowerArmorType (edict_t *ent);
-gitem_t *GetItemByIndex (int index);
-qboolean Add_Ammo (edict_t *ent, gitem_t *item, int count);
-void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
+edict_t *Drop_Item(edict_t *ent, gitem_t *item);
+void SetRespawn(edict_t *ent, float delay);
+void ChangeWeapon(edict_t *ent);
+void SpawnItem(edict_t *ent, gitem_t *item);
+void Think_Weapon(edict_t *ent);
+int ArmorIndex(edict_t *ent);
+int PowerArmorType(edict_t *ent);
+gitem_t *GetItemByIndex(int index);
+qboolean Add_Ammo(edict_t *ent, gitem_t *item, int count);
+void Touch_Item(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
//
// g_utils.c
//
-qboolean KillBox (edict_t *ent);
-void G_ProjectSource (const vec3_t point, const vec3_t distance, const vec3_t forward, const vec3_t right, vec3_t result);
-edict_t *G_Find (edict_t *from, int fieldofs, char *match);
-edict_t *findradius (edict_t *from, vec3_t org, float rad);
-edict_t *G_PickTarget (char *targetname);
-void G_UseTargets (edict_t *ent, edict_t *activator);
-void G_SetMovedir (vec3_t angles, vec3_t movedir);
+qboolean KillBox(edict_t *ent);
+void G_ProjectSource(const vec3_t point, const vec3_t distance, const vec3_t forward, const vec3_t right, vec3_t result);
+edict_t *G_Find(edict_t *from, int fieldofs, char *match);
+edict_t *findradius(edict_t *from, vec3_t org, float rad);
+edict_t *G_PickTarget(char *targetname);
+void G_UseTargets(edict_t *ent, edict_t *activator);
+void G_SetMovedir(vec3_t angles, vec3_t movedir);
-void G_InitEdict (edict_t *e);
-edict_t *G_Spawn (void);
-void G_FreeEdict (edict_t *e);
+void G_InitEdict(edict_t *e);
+edict_t *G_Spawn(void);
+void G_FreeEdict(edict_t *e);
-void G_TouchTriggers (edict_t *ent);
-void G_TouchSolids (edict_t *ent);
+void G_TouchTriggers(edict_t *ent);
+void G_TouchSolids(edict_t *ent);
-char *G_CopyString (char *in);
+char *G_CopyString(char *in);
-float *tv (float x, float y, float z);
-char *vtos (vec3_t v);
+float *tv(float x, float y, float z);
+char *vtos(vec3_t v);
-float vectoyaw (vec3_t vec);
-void vectoangles (vec3_t vec, vec3_t angles);
+float vectoyaw(vec3_t vec);
+void vectoangles(vec3_t vec, vec3_t angles);
//
// g_combat.c
//
-qboolean OnSameTeam (edict_t *ent1, edict_t *ent2);
-qboolean CanDamage (edict_t *targ, edict_t *inflictor);
-void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod);
-void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod);
+qboolean OnSameTeam(edict_t *ent1, edict_t *ent2);
+qboolean CanDamage(edict_t *targ, edict_t *inflictor);
+void T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod);
+void T_RadiusDamage(edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod);
// damage flags
#define DAMAGE_RADIUS 0x00000001 // damage was indirect
@@ -674,112 +661,112 @@ void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_
//
// g_monster.c
//
-void monster_fire_bullet (edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype);
-void monster_fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype);
-void monster_fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect);
-void monster_fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype);
-void monster_fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype);
-void monster_fire_railgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype);
-void monster_fire_bfg (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype);
-void M_droptofloor (edict_t *ent);
-void monster_think (edict_t *self);
-void walkmonster_start (edict_t *self);
-void swimmonster_start (edict_t *self);
-void flymonster_start (edict_t *self);
-void AttackFinished (edict_t *self, float time);
-void monster_death_use (edict_t *self);
-void M_CatagorizePosition (edict_t *ent);
-qboolean M_CheckAttack (edict_t *self);
-void M_FlyCheck (edict_t *self);
-void M_CheckGround (edict_t *ent);
+void monster_fire_bullet(edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype);
+void monster_fire_shotgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype);
+void monster_fire_blaster(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect);
+void monster_fire_grenade(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype);
+void monster_fire_rocket(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype);
+void monster_fire_railgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype);
+void monster_fire_bfg(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype);
+void M_droptofloor(edict_t *ent);
+void monster_think(edict_t *self);
+void walkmonster_start(edict_t *self);
+void swimmonster_start(edict_t *self);
+void flymonster_start(edict_t *self);
+void AttackFinished(edict_t *self, float time);
+void monster_death_use(edict_t *self);
+void M_CatagorizePosition(edict_t *ent);
+qboolean M_CheckAttack(edict_t *self);
+void M_FlyCheck(edict_t *self);
+void M_CheckGround(edict_t *ent);
//
// g_misc.c
//
-void ThrowHead (edict_t *self, char *gibname, int damage, int type);
-void ThrowClientHead (edict_t *self, int damage);
-void ThrowGib (edict_t *self, char *gibname, int damage, int type);
+void ThrowHead(edict_t *self, char *gibname, int damage, int type);
+void ThrowClientHead(edict_t *self, int damage);
+void ThrowGib(edict_t *self, char *gibname, int damage, int type);
void BecomeExplosion1(edict_t *self);
//
// g_ai.c
//
-void AI_SetSightClient (void);
-
-void ai_stand (edict_t *self, float dist);
-void ai_move (edict_t *self, float dist);
-void ai_walk (edict_t *self, float dist);
-void ai_turn (edict_t *self, float dist);
-void ai_run (edict_t *self, float dist);
-void ai_charge (edict_t *self, float dist);
-int range (edict_t *self, edict_t *other);
-
-void FoundTarget (edict_t *self);
-qboolean infront (edict_t *self, edict_t *other);
-qboolean visible (edict_t *self, edict_t *other);
+void AI_SetSightClient(void);
+
+void ai_stand(edict_t *self, float dist);
+void ai_move(edict_t *self, float dist);
+void ai_walk(edict_t *self, float dist);
+void ai_turn(edict_t *self, float dist);
+void ai_run(edict_t *self, float dist);
+void ai_charge(edict_t *self, float dist);
+int range(edict_t *self, edict_t *other);
+
+void FoundTarget(edict_t *self);
+qboolean infront(edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
qboolean FacingIdeal(edict_t *self);
//
// g_weapon.c
//
-void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin);
-qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick);
-void fire_bullet (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod);
-void fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod);
-void fire_blaster (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int effect, qboolean hyper);
-void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius);
-void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held);
-void fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage);
-void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick);
-void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius);
+void ThrowDebris(edict_t *self, char *modelname, float speed, vec3_t origin);
+qboolean fire_hit(edict_t *self, vec3_t aim, int damage, int kick);
+void fire_bullet(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod);
+void fire_shotgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod);
+void fire_blaster(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int effect, qboolean hyper);
+void fire_grenade(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius);
+void fire_grenade2(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held);
+void fire_rocket(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage);
+void fire_rail(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick);
+void fire_bfg(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius);
//
// g_ptrail.c
//
-void PlayerTrail_Init (void);
-void PlayerTrail_Add (vec3_t spot);
-void PlayerTrail_New (vec3_t spot);
-edict_t *PlayerTrail_PickFirst (edict_t *self);
-edict_t *PlayerTrail_PickNext (edict_t *self);
-edict_t *PlayerTrail_LastSpot (void);
+void PlayerTrail_Init(void);
+void PlayerTrail_Add(vec3_t spot);
+void PlayerTrail_New(vec3_t spot);
+edict_t *PlayerTrail_PickFirst(edict_t *self);
+edict_t *PlayerTrail_PickNext(edict_t *self);
+edict_t *PlayerTrail_LastSpot(void);
//
// g_client.c
//
-void respawn (edict_t *ent);
-void BeginIntermission (edict_t *targ);
-void PutClientInServer (edict_t *ent);
-void InitClientPersistant (gclient_t *client);
-void InitClientResp (gclient_t *client);
-void InitBodyQue (void);
-void ClientBeginServerFrame (edict_t *ent);
+void respawn(edict_t *ent);
+void BeginIntermission(edict_t *targ);
+void PutClientInServer(edict_t *ent);
+void InitClientPersistant(gclient_t *client);
+void InitClientResp(gclient_t *client);
+void InitBodyQue(void);
+void ClientBeginServerFrame(edict_t *ent);
//
// g_player.c
//
-void player_pain (edict_t *self, edict_t *other, float kick, int damage);
-void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
+void player_pain(edict_t *self, edict_t *other, float kick, int damage);
+void player_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
//
// g_svcmds.c
//
-void ServerCommand (void);
-qboolean SV_FilterPacket (char *from);
+void ServerCommand(void);
+qboolean SV_FilterPacket(char *from);
//
// p_view.c
//
-void ClientEndServerFrame (edict_t *ent);
+void ClientEndServerFrame(edict_t *ent);
//
// p_hud.c
//
-void MoveClientToIntermission (edict_t *client);
-void G_SetStats (edict_t *ent);
-void G_SetSpectatorStats (edict_t *ent);
-void G_CheckChaseStats (edict_t *ent);
-void ValidateSelectedItem (edict_t *ent);
-void DeathmatchScoreboardMessage (edict_t *client, edict_t *killer);
+void MoveClientToIntermission(edict_t *client);
+void G_SetStats(edict_t *ent);
+void G_SetSpectatorStats(edict_t *ent);
+void G_CheckChaseStats(edict_t *ent);
+void ValidateSelectedItem(edict_t *ent);
+void DeathmatchScoreboardMessage(edict_t *client, edict_t *killer);
//
// g_pweapon.c
@@ -789,21 +776,21 @@ void PlayerNoise(edict_t *who, vec3_t where, int type);
//
// m_move.c
//
-qboolean M_CheckBottom (edict_t *ent);
-qboolean M_walkmove (edict_t *ent, float yaw, float dist);
-void M_MoveToGoal (edict_t *ent, float dist);
-void M_ChangeYaw (edict_t *ent);
+qboolean M_CheckBottom(edict_t *ent);
+qboolean M_walkmove(edict_t *ent, float yaw, float dist);
+void M_MoveToGoal(edict_t *ent, float dist);
+void M_ChangeYaw(edict_t *ent);
//
// g_phys.c
//
-void G_RunEntity (edict_t *ent);
+void G_RunEntity(edict_t *ent);
//
// g_main.c
//
-void SaveClientData (void);
-void FetchClientEntData (edict_t *ent);
+void SaveClientData(void);
+void FetchClientEntData(edict_t *ent);
//
// g_chase.c
@@ -826,14 +813,13 @@ void GetChaseTarget(edict_t *ent);
// client data that stays across multiple level loads
-typedef struct
-{
+typedef struct {
char userinfo[MAX_INFO_STRING];
char netname[16];
int hand;
- qboolean connected; // a loadgame will leave valid entities that
- // just don't have a connection yet
+ qboolean connected; // a loadgame will leave valid entities that
+ // just don't have a connection yet
// values saved and restored from edicts when changing levels
int health;
@@ -864,8 +850,7 @@ typedef struct
} client_persistant_t;
// client data that stays across deathmatch respawns
-typedef struct
-{
+typedef struct {
client_persistant_t coop_respawn; // what to set client->pers to on a respawn
int enterframe; // level.framenum the client entered the game
int score; // frags, etc
@@ -876,8 +861,7 @@ typedef struct
// this structure is cleared on each PutClientInServer(),
// except for 'client->pers'
-struct gclient_s
-{
+struct gclient_s {
// known to server
player_state_t ps; // communicated by server to clients
int ping;
@@ -961,8 +945,7 @@ struct gclient_s
};
-struct edict_s
-{
+struct edict_s {
entity_state_t s;
struct gclient_s *client; // NULL if not a player
// the server expects the first part
@@ -974,7 +957,7 @@ struct edict_s
// FIXME: move these fields to a server private sv_entity_t
list_t area; // linked to a division node or leaf
-
+
int num_clusters; // if -1, use headnode instead
int clusternums[MAX_ENT_CLUSTERS];
int headnode; // unused if num_clusters != -1
@@ -999,7 +982,7 @@ struct edict_s
char *model;
float freetime; // sv.time when the object was freed
-
+
//
// only used locally in game, not by server
//
@@ -1036,9 +1019,9 @@ struct edict_s
float ideal_yaw;
float nextthink;
- void (*prethink) (edict_t *ent);
+ void (*prethink)(edict_t *ent);
void (*think)(edict_t *self);
- void (*blocked)(edict_t *self, edict_t *other); //move to moveinfo?
+ void (*blocked)(edict_t *self, edict_t *other); // move to moveinfo?
void (*touch)(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf);
void (*use)(edict_t *self, edict_t *other, edict_t *activator);
void (*pain)(edict_t *self, edict_t *other, float kick, int damage);
@@ -1047,7 +1030,7 @@ struct edict_s
float touch_debounce_time; // are all these legit? do we need more/less of them?
float pain_debounce_time;
float damage_debounce_time;
- float fly_sound_debounce_time; //move to clientinfo
+ float fly_sound_debounce_time; // move to clientinfo
float last_move_time;
int health;
@@ -1065,7 +1048,7 @@ struct edict_s
int dmg;
int radius_dmg;
float dmg_radius;
- int sounds; //make this a spawntemp var?
+ int sounds; // make this a spawntemp var?
int count;
edict_t *chain;
diff --git a/src/baseq2/g_main.c b/src/baseq2/g_main.c
index 2766c78..d3a5c45 100644
--- a/src/baseq2/g_main.c
+++ b/src/baseq2/g_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -74,31 +74,31 @@ cvar_t *sv_maplist;
cvar_t *sv_features;
-void SpawnEntities (const char *mapname, const char *entities, const char *spawnpoint);
-void ClientThink (edict_t *ent, usercmd_t *cmd);
-qboolean ClientConnect (edict_t *ent, char *userinfo);
-void ClientUserinfoChanged (edict_t *ent, char *userinfo);
-void ClientDisconnect (edict_t *ent);
-void ClientBegin (edict_t *ent);
-void ClientCommand (edict_t *ent);
-void RunEntity (edict_t *ent);
-void WriteGame (const char *filename, qboolean autosave);
-void ReadGame (const char *filename);
-void WriteLevel (const char *filename);
-void ReadLevel (const char *filename);
-void InitGame (void);
-void G_RunFrame (void);
+void SpawnEntities(const char *mapname, const char *entities, const char *spawnpoint);
+void ClientThink(edict_t *ent, usercmd_t *cmd);
+qboolean ClientConnect(edict_t *ent, char *userinfo);
+void ClientUserinfoChanged(edict_t *ent, char *userinfo);
+void ClientDisconnect(edict_t *ent);
+void ClientBegin(edict_t *ent);
+void ClientCommand(edict_t *ent);
+void RunEntity(edict_t *ent);
+void WriteGame(const char *filename, qboolean autosave);
+void ReadGame(const char *filename);
+void WriteLevel(const char *filename);
+void ReadLevel(const char *filename);
+void InitGame(void);
+void G_RunFrame(void);
//===================================================================
-void ShutdownGame (void)
+void ShutdownGame(void)
{
- gi.dprintf ("==== ShutdownGame ====\n");
+ gi.dprintf("==== ShutdownGame ====\n");
- gi.FreeTags (TAG_LEVEL);
- gi.FreeTags (TAG_GAME);
+ gi.FreeTags(TAG_LEVEL);
+ gi.FreeTags(TAG_GAME);
}
/*
@@ -110,83 +110,83 @@ only happens when a new game is started or a save game
is loaded.
============
*/
-void InitGame (void)
+void InitGame(void)
{
- gi.dprintf ("==== InitGame ====\n");
+ gi.dprintf("==== InitGame ====\n");
- gun_x = gi.cvar ("gun_x", "0", 0);
- gun_y = gi.cvar ("gun_y", "0", 0);
- gun_z = gi.cvar ("gun_z", "0", 0);
+ gun_x = gi.cvar("gun_x", "0", 0);
+ gun_y = gi.cvar("gun_y", "0", 0);
+ gun_z = gi.cvar("gun_z", "0", 0);
//FIXME: sv_ prefix is wrong for these
- sv_rollspeed = gi.cvar ("sv_rollspeed", "200", 0);
- sv_rollangle = gi.cvar ("sv_rollangle", "2", 0);
- sv_maxvelocity = gi.cvar ("sv_maxvelocity", "2000", 0);
- sv_gravity = gi.cvar ("sv_gravity", "800", 0);
+ sv_rollspeed = gi.cvar("sv_rollspeed", "200", 0);
+ sv_rollangle = gi.cvar("sv_rollangle", "2", 0);
+ sv_maxvelocity = gi.cvar("sv_maxvelocity", "2000", 0);
+ sv_gravity = gi.cvar("sv_gravity", "800", 0);
// noset vars
- dedicated = gi.cvar ("dedicated", "0", CVAR_NOSET);
+ dedicated = gi.cvar("dedicated", "0", CVAR_NOSET);
// latched vars
- sv_cheats = gi.cvar ("cheats", "0", CVAR_SERVERINFO|CVAR_LATCH);
- gi.cvar ("gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_LATCH);
- gi.cvar ("gamedate", __DATE__ , CVAR_SERVERINFO | CVAR_LATCH);
+ sv_cheats = gi.cvar("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
+ gi.cvar("gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_LATCH);
+ gi.cvar("gamedate", __DATE__ , CVAR_SERVERINFO | CVAR_LATCH);
- maxclients = gi.cvar ("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
- maxspectators = gi.cvar ("maxspectators", "4", CVAR_SERVERINFO);
- deathmatch = gi.cvar ("deathmatch", "0", CVAR_LATCH);
- coop = gi.cvar ("coop", "0", CVAR_LATCH);
- skill = gi.cvar ("skill", "1", CVAR_LATCH);
- maxentities = gi.cvar ("maxentities", "1024", CVAR_LATCH);
+ maxclients = gi.cvar("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
+ maxspectators = gi.cvar("maxspectators", "4", CVAR_SERVERINFO);
+ deathmatch = gi.cvar("deathmatch", "0", CVAR_LATCH);
+ coop = gi.cvar("coop", "0", CVAR_LATCH);
+ skill = gi.cvar("skill", "1", CVAR_LATCH);
+ maxentities = gi.cvar("maxentities", "1024", CVAR_LATCH);
// change anytime vars
- dmflags = gi.cvar ("dmflags", "0", CVAR_SERVERINFO);
- fraglimit = gi.cvar ("fraglimit", "0", CVAR_SERVERINFO);
- timelimit = gi.cvar ("timelimit", "0", CVAR_SERVERINFO);
- password = gi.cvar ("password", "", CVAR_USERINFO);
- spectator_password = gi.cvar ("spectator_password", "", CVAR_USERINFO);
- needpass = gi.cvar ("needpass", "0", CVAR_SERVERINFO);
- filterban = gi.cvar ("filterban", "1", 0);
-
- g_select_empty = gi.cvar ("g_select_empty", "0", CVAR_ARCHIVE);
-
- run_pitch = gi.cvar ("run_pitch", "0.002", 0);
- run_roll = gi.cvar ("run_roll", "0.005", 0);
- bob_up = gi.cvar ("bob_up", "0.005", 0);
- bob_pitch = gi.cvar ("bob_pitch", "0.002", 0);
- bob_roll = gi.cvar ("bob_roll", "0.002", 0);
+ dmflags = gi.cvar("dmflags", "0", CVAR_SERVERINFO);
+ fraglimit = gi.cvar("fraglimit", "0", CVAR_SERVERINFO);
+ timelimit = gi.cvar("timelimit", "0", CVAR_SERVERINFO);
+ password = gi.cvar("password", "", CVAR_USERINFO);
+ spectator_password = gi.cvar("spectator_password", "", CVAR_USERINFO);
+ needpass = gi.cvar("needpass", "0", CVAR_SERVERINFO);
+ filterban = gi.cvar("filterban", "1", 0);
+
+ g_select_empty = gi.cvar("g_select_empty", "0", CVAR_ARCHIVE);
+
+ run_pitch = gi.cvar("run_pitch", "0.002", 0);
+ run_roll = gi.cvar("run_roll", "0.005", 0);
+ bob_up = gi.cvar("bob_up", "0.005", 0);
+ bob_pitch = gi.cvar("bob_pitch", "0.002", 0);
+ bob_roll = gi.cvar("bob_roll", "0.002", 0);
// flood control
- flood_msgs = gi.cvar ("flood_msgs", "4", 0);
- flood_persecond = gi.cvar ("flood_persecond", "4", 0);
- flood_waitdelay = gi.cvar ("flood_waitdelay", "10", 0);
+ flood_msgs = gi.cvar("flood_msgs", "4", 0);
+ flood_persecond = gi.cvar("flood_persecond", "4", 0);
+ flood_waitdelay = gi.cvar("flood_waitdelay", "10", 0);
// dm map list
- sv_maplist = gi.cvar ("sv_maplist", "", 0);
+ sv_maplist = gi.cvar("sv_maplist", "", 0);
// obtain server features
- sv_features = gi.cvar( "sv_features", NULL, 0 );
+ sv_features = gi.cvar("sv_features", NULL, 0);
// export our own features
- gi.cvar_forceset( "g_features", va( "%d", G_FEATURES ) );
+ gi.cvar_forceset("g_features", va("%d", G_FEATURES));
// items
- InitItems ();
+ InitItems();
game.helpmessage1[0] = 0;
game.helpmessage2[0] = 0;
// initialize all entities for this game
game.maxentities = maxentities->value;
- clamp( game.maxentities, (int)maxclients->value + 1, MAX_EDICTS );
- g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
+ clamp(game.maxentities, (int)maxclients->value + 1, MAX_EDICTS);
+ g_edicts = gi.TagMalloc(game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
globals.edicts = g_edicts;
globals.max_edicts = game.maxentities;
// initialize all clients for this game
game.maxclients = maxclients->value;
- game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME);
- globals.num_edicts = game.maxclients+1;
+ game.clients = gi.TagMalloc(game.maxclients * sizeof(game.clients[0]), TAG_GAME);
+ globals.num_edicts = game.maxclients + 1;
}
@@ -198,7 +198,7 @@ Returns a pointer to the structure with all entry points
and global variables
=================
*/
-EXPORTED game_export_t *GetGameAPI (game_import_t *import)
+EXPORTED game_export_t *GetGameAPI(game_import_t *import)
{
gi = *import;
@@ -230,30 +230,32 @@ EXPORTED game_export_t *GetGameAPI (game_import_t *import)
#ifndef GAME_HARD_LINKED
// this is only here so the functions in q_shared.c can link
-void Com_LPrintf( print_type_t type, const char *fmt, ... ) {
+void Com_LPrintf(print_type_t type, const char *fmt, ...)
+{
va_list argptr;
char text[MAX_STRING_CHARS];
- if( type == PRINT_DEVELOPER ) {
+ if (type == PRINT_DEVELOPER) {
return;
}
- va_start( argptr, fmt );
- Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- gi.dprintf( "%s", text );
+ gi.dprintf("%s", text);
}
-void Com_Error( error_type_t type, const char *fmt, ... ) {
+void Com_Error(error_type_t type, const char *fmt, ...)
+{
va_list argptr;
char text[MAX_STRING_CHARS];
- va_start( argptr, fmt );
- Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- gi.error( "%s", text );
+ gi.error("%s", text);
}
#endif
@@ -265,19 +267,18 @@ void Com_Error( error_type_t type, const char *fmt, ... ) {
ClientEndServerFrames
=================
*/
-void ClientEndServerFrames (void)
+void ClientEndServerFrames(void)
{
int i;
edict_t *ent;
// calc the player views now that all pushing
// and damage has been added
- for (i=0 ; i<maxclients->value ; i++)
- {
+ for (i = 0 ; i < maxclients->value ; i++) {
ent = g_edicts + 1 + i;
if (!ent->inuse || !ent->client)
continue;
- ClientEndServerFrame (ent);
+ ClientEndServerFrame(ent);
}
}
@@ -293,7 +294,7 @@ edict_t *CreateTargetChangeLevel(char *map)
{
edict_t *ent;
- ent = G_Spawn ();
+ ent = G_Spawn();
ent->classname = "target_changelevel";
Q_snprintf(level.nextmap, sizeof(level.nextmap), "%s", map);
ent->map = level.nextmap;
@@ -307,16 +308,15 @@ EndDMLevel
The timelimit or fraglimit has been exceeded
=================
*/
-void EndDMLevel (void)
+void EndDMLevel(void)
{
edict_t *ent;
char *s, *t, *f;
static const char *seps = " ,\n\r";
// stay on same level flag
- if ((int)dmflags->value & DF_SAME_LEVEL)
- {
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
+ if ((int)dmflags->value & DF_SAME_LEVEL) {
+ BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
@@ -331,11 +331,11 @@ void EndDMLevel (void)
t = strtok(NULL, seps);
if (t == NULL) { // end of list, go to first one
if (f == NULL) // there isn't a first one, same level
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
+ BeginIntermission(CreateTargetChangeLevel(level.mapname));
else
- BeginIntermission (CreateTargetChangeLevel (f) );
+ BeginIntermission(CreateTargetChangeLevel(f));
} else
- BeginIntermission (CreateTargetChangeLevel (t) );
+ BeginIntermission(CreateTargetChangeLevel(t));
free(s);
return;
}
@@ -347,16 +347,16 @@ void EndDMLevel (void)
}
if (level.nextmap[0]) // go to a specific map
- BeginIntermission (CreateTargetChangeLevel (level.nextmap) );
+ BeginIntermission(CreateTargetChangeLevel(level.nextmap));
else { // search for a changelevel
- ent = G_Find (NULL, FOFS(classname), "target_changelevel");
- if (!ent)
- { // the map designer didn't include a changelevel,
+ ent = G_Find(NULL, FOFS(classname), "target_changelevel");
+ if (!ent) {
+ // the map designer didn't include a changelevel,
// so create a fake ent that goes back to the same level
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
+ BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
- BeginIntermission (ent);
+ BeginIntermission(ent);
}
}
@@ -366,14 +366,13 @@ void EndDMLevel (void)
CheckNeedPass
=================
*/
-void CheckNeedPass (void)
+void CheckNeedPass(void)
{
int need;
// if password or spectator_password has changed, update needpass
// as needed
- if (password->modified || spectator_password->modified)
- {
+ if (password->modified || spectator_password->modified) {
password->modified = spectator_password->modified = qfalse;
need = 0;
@@ -392,7 +391,7 @@ void CheckNeedPass (void)
CheckDMRules
=================
*/
-void CheckDMRules (void)
+void CheckDMRules(void)
{
int i;
gclient_t *cl;
@@ -403,28 +402,23 @@ void CheckDMRules (void)
if (!deathmatch->value)
return;
- if (timelimit->value)
- {
- if (level.time >= timelimit->value*60)
- {
- gi.bprintf (PRINT_HIGH, "Timelimit hit.\n");
- EndDMLevel ();
+ if (timelimit->value) {
+ if (level.time >= timelimit->value * 60) {
+ gi.bprintf(PRINT_HIGH, "Timelimit hit.\n");
+ EndDMLevel();
return;
}
}
- if (fraglimit->value)
- {
- for (i=0 ; i<maxclients->value ; i++)
- {
+ if (fraglimit->value) {
+ for (i = 0 ; i < maxclients->value ; i++) {
cl = game.clients + i;
- if (!g_edicts[i+1].inuse)
+ if (!g_edicts[i + 1].inuse)
continue;
- if (cl->resp.score >= fraglimit->value)
- {
- gi.bprintf (PRINT_HIGH, "Fraglimit hit.\n");
- EndDMLevel ();
+ if (cl->resp.score >= fraglimit->value) {
+ gi.bprintf(PRINT_HIGH, "Fraglimit hit.\n");
+ EndDMLevel();
return;
}
}
@@ -437,22 +431,21 @@ void CheckDMRules (void)
ExitLevel
=============
*/
-void ExitLevel (void)
+void ExitLevel(void)
{
int i;
edict_t *ent;
char command [256];
- Q_snprintf (command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
- gi.AddCommandString (command);
+ Q_snprintf(command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
+ gi.AddCommandString(command);
level.changemap = NULL;
level.exitintermission = 0;
level.intermissiontime = 0;
- ClientEndServerFrames ();
+ ClientEndServerFrames();
// clear some things before going to next level
- for (i=0 ; i<maxclients->value ; i++)
- {
+ for (i = 0 ; i < maxclients->value ; i++) {
ent = g_edicts + 1 + i;
if (!ent->inuse)
continue;
@@ -469,22 +462,21 @@ G_RunFrame
Advances the world by 0.1 seconds
================
*/
-void G_RunFrame (void)
+void G_RunFrame(void)
{
int i;
edict_t *ent;
level.framenum++;
- level.time = level.framenum*FRAMETIME;
+ level.time = level.framenum * FRAMETIME;
// choose a client for monsters to target this frame
- AI_SetSightClient ();
+ AI_SetSightClient();
// exit intermissions
- if (level.exitintermission)
- {
- ExitLevel ();
+ if (level.exitintermission) {
+ ExitLevel();
return;
}
@@ -493,41 +485,37 @@ void G_RunFrame (void)
// even the world gets a chance to think
//
ent = &g_edicts[0];
- for (i=0 ; i<globals.num_edicts ; i++, ent++)
- {
+ for (i = 0 ; i < globals.num_edicts ; i++, ent++) {
if (!ent->inuse)
continue;
level.current_entity = ent;
- VectorCopy (ent->s.origin, ent->s.old_origin);
+ VectorCopy(ent->s.origin, ent->s.old_origin);
// if the ground entity moved, make sure we are still on it
- if ((ent->groundentity) && (ent->groundentity->linkcount != ent->groundentity_linkcount))
- {
+ if ((ent->groundentity) && (ent->groundentity->linkcount != ent->groundentity_linkcount)) {
ent->groundentity = NULL;
- if ( !(ent->flags & (FL_SWIM|FL_FLY)) && (ent->svflags & SVF_MONSTER) )
- {
- M_CheckGround (ent);
+ if (!(ent->flags & (FL_SWIM | FL_FLY)) && (ent->svflags & SVF_MONSTER)) {
+ M_CheckGround(ent);
}
}
- if (i > 0 && i <= maxclients->value)
- {
- ClientBeginServerFrame (ent);
+ if (i > 0 && i <= maxclients->value) {
+ ClientBeginServerFrame(ent);
continue;
}
- G_RunEntity (ent);
+ G_RunEntity(ent);
}
// see if it is time to end a deathmatch
- CheckDMRules ();
+ CheckDMRules();
// see if needpass needs updated
- CheckNeedPass ();
+ CheckNeedPass();
// build the playerstate_t structures for all players
- ClientEndServerFrames ();
+ ClientEndServerFrames();
}
diff --git a/src/baseq2/g_misc.c b/src/baseq2/g_misc.c
index c3b3049..0d77f9f 100644
--- a/src/baseq2/g_misc.c
+++ b/src/baseq2/g_misc.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,11 +28,11 @@ Used to group brushes together just for editor convenience.
//=====================================================
-void Use_Areaportal (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Areaportal(edict_t *ent, edict_t *other, edict_t *activator)
{
ent->count ^= 1; // toggle state
// gi.dprintf ("portalstate: %i = %i\n", ent->style, ent->count);
- gi.SetAreaPortalState (ent->style, ent->count);
+ gi.SetAreaPortalState(ent->style, ent->count);
}
/*QUAKED func_areaportal (0 0 0) ?
@@ -41,7 +41,7 @@ This is a non-visible object that divides the world into
areas that are seperated when this portal is not activated.
Usually enclosed in the middle of a door.
*/
-void SP_func_areaportal (edict_t *ent)
+void SP_func_areaportal(edict_t *ent)
{
ent->use = Use_Areaportal;
ent->count = 0; // always start closed;
@@ -55,19 +55,19 @@ void SP_func_areaportal (edict_t *ent)
Misc functions
=================
*/
-void VelocityForDamage (int damage, vec3_t v)
+void VelocityForDamage(int damage, vec3_t v)
{
v[0] = 100.0 * crandom();
v[1] = 100.0 * crandom();
v[2] = 200.0 + 100.0 * random();
if (damage < 50)
- VectorScale (v, 0.7, v);
- else
- VectorScale (v, 1.2, v);
+ VectorScale(v, 0.7, v);
+ else
+ VectorScale(v, 1.2, v);
}
-void ClipGibVelocity (edict_t *ent)
+void ClipGibVelocity(edict_t *ent)
{
if (ent->velocity[0] < -300)
ent->velocity[0] = -300;
@@ -89,19 +89,18 @@ void ClipGibVelocity (edict_t *ent)
gibs
=================
*/
-void gib_think (edict_t *self)
+void gib_think(edict_t *self)
{
self->s.frame++;
self->nextthink = level.time + FRAMETIME;
- if (self->s.frame == 10)
- {
+ if (self->s.frame == 10) {
self->think = G_FreeEdict;
- self->nextthink = level.time + 8 + random()*10;
+ self->nextthink = level.time + 8 + random() * 10;
}
}
-void gib_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void gib_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t normal_angles, right;
@@ -110,16 +109,14 @@ void gib_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf
self->touch = NULL;
- if (plane)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/fhit3.wav"), 1, ATTN_NORM, 0);
+ if (plane) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/fhit3.wav"), 1, ATTN_NORM, 0);
- vectoangles (plane->normal, normal_angles);
- AngleVectors (normal_angles, NULL, right, NULL);
- vectoangles (right, self->s.angles);
+ vectoangles(plane->normal, normal_angles);
+ AngleVectors(normal_angles, NULL, right, NULL);
+ vectoangles(right, self->s.angles);
- if (self->s.modelindex == sm_meat_index)
- {
+ if (self->s.modelindex == sm_meat_index) {
self->s.frame++;
self->think = gib_think;
self->nextthink = level.time + FRAMETIME;
@@ -127,12 +124,12 @@ void gib_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf
}
}
-void gib_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void gib_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-void ThrowGib (edict_t *self, char *gibname, int damage, int type)
+void ThrowGib(edict_t *self, char *gibname, int damage, int type)
{
edict_t *gib;
vec3_t vd;
@@ -142,56 +139,53 @@ void ThrowGib (edict_t *self, char *gibname, int damage, int type)
gib = G_Spawn();
- VectorScale (self->size, 0.5, size);
- VectorAdd (self->absmin, size, origin);
+ VectorScale(self->size, 0.5, size);
+ VectorAdd(self->absmin, size, origin);
gib->s.origin[0] = origin[0] + crandom() * size[0];
gib->s.origin[1] = origin[1] + crandom() * size[1];
gib->s.origin[2] = origin[2] + crandom() * size[2];
- gi.setmodel (gib, gibname);
+ gi.setmodel(gib, gibname);
gib->solid = SOLID_NOT;
gib->s.effects |= EF_GIB;
gib->flags |= FL_NO_KNOCKBACK;
gib->takedamage = DAMAGE_YES;
gib->die = gib_die;
- if (type == GIB_ORGANIC)
- {
+ if (type == GIB_ORGANIC) {
gib->movetype = MOVETYPE_TOSS;
gib->touch = gib_touch;
vscale = 0.5;
- }
- else
- {
+ } else {
gib->movetype = MOVETYPE_BOUNCE;
vscale = 1.0;
}
- VelocityForDamage (damage, vd);
- VectorMA (self->velocity, vscale, vd, gib->velocity);
- ClipGibVelocity (gib);
- gib->avelocity[0] = random()*600;
- gib->avelocity[1] = random()*600;
- gib->avelocity[2] = random()*600;
+ VelocityForDamage(damage, vd);
+ VectorMA(self->velocity, vscale, vd, gib->velocity);
+ ClipGibVelocity(gib);
+ gib->avelocity[0] = random() * 600;
+ gib->avelocity[1] = random() * 600;
+ gib->avelocity[2] = random() * 600;
gib->think = G_FreeEdict;
- gib->nextthink = level.time + 10 + random()*10;
+ gib->nextthink = level.time + 10 + random() * 10;
- gi.linkentity (gib);
+ gi.linkentity(gib);
}
-void ThrowHead (edict_t *self, char *gibname, int damage, int type)
+void ThrowHead(edict_t *self, char *gibname, int damage, int type)
{
vec3_t vd;
float vscale;
self->s.skinnum = 0;
self->s.frame = 0;
- VectorClear (self->mins);
- VectorClear (self->maxs);
+ VectorClear(self->mins);
+ VectorClear(self->maxs);
self->s.modelindex2 = 0;
- gi.setmodel (self, gibname);
+ gi.setmodel(self, gibname);
self->solid = SOLID_NOT;
self->s.effects |= EF_GIB;
self->s.effects &= ~EF_FLIES;
@@ -201,52 +195,46 @@ void ThrowHead (edict_t *self, char *gibname, int damage, int type)
self->takedamage = DAMAGE_YES;
self->die = gib_die;
- if (type == GIB_ORGANIC)
- {
+ if (type == GIB_ORGANIC) {
self->movetype = MOVETYPE_TOSS;
self->touch = gib_touch;
vscale = 0.5;
- }
- else
- {
+ } else {
self->movetype = MOVETYPE_BOUNCE;
vscale = 1.0;
}
- VelocityForDamage (damage, vd);
- VectorMA (self->velocity, vscale, vd, self->velocity);
- ClipGibVelocity (self);
+ VelocityForDamage(damage, vd);
+ VectorMA(self->velocity, vscale, vd, self->velocity);
+ ClipGibVelocity(self);
- self->avelocity[YAW] = crandom()*600;
+ self->avelocity[YAW] = crandom() * 600;
self->think = G_FreeEdict;
- self->nextthink = level.time + 10 + random()*10;
+ self->nextthink = level.time + 10 + random() * 10;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void ThrowClientHead (edict_t *self, int damage)
+void ThrowClientHead(edict_t *self, int damage)
{
vec3_t vd;
char *gibname;
- if (rand()&1)
- {
+ if (rand() & 1) {
gibname = "models/objects/gibs/head2/tris.md2";
self->s.skinnum = 1; // second skin is player
- }
- else
- {
+ } else {
gibname = "models/objects/gibs/skull/tris.md2";
self->s.skinnum = 0;
}
self->s.origin[2] += 32;
self->s.frame = 0;
- gi.setmodel (self, gibname);
- VectorSet (self->mins, -16, -16, 0);
- VectorSet (self->maxs, 16, 16, 16);
+ gi.setmodel(self, gibname);
+ VectorSet(self->mins, -16, -16, 0);
+ VectorSet(self->maxs, 16, 16, 16);
self->takedamage = DAMAGE_NO;
self->solid = SOLID_NOT;
@@ -255,21 +243,18 @@ void ThrowClientHead (edict_t *self, int damage)
self->flags |= FL_NO_KNOCKBACK;
self->movetype = MOVETYPE_BOUNCE;
- VelocityForDamage (damage, vd);
- VectorAdd (self->velocity, vd, self->velocity);
+ VelocityForDamage(damage, vd);
+ VectorAdd(self->velocity, vd, self->velocity);
- if (self->client) // bodies in the queue don't have a client anymore
- {
+ if (self->client) { // bodies in the queue don't have a client anymore
self->client->anim_priority = ANIM_DEATH;
self->client->anim_end = self->s.frame;
- }
- else
- {
+ } else {
self->think = NULL;
self->nextthink = 0;
}
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -278,58 +263,58 @@ void ThrowClientHead (edict_t *self, int damage)
debris
=================
*/
-void debris_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void debris_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin)
+void ThrowDebris(edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
- VectorCopy (origin, chunk->s.origin);
- gi.setmodel (chunk, modelname);
+ VectorCopy(origin, chunk->s.origin);
+ gi.setmodel(chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 + 100 * crandom();
- VectorMA (self->velocity, speed, v, chunk->velocity);
+ VectorMA(self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
- chunk->avelocity[0] = random()*600;
- chunk->avelocity[1] = random()*600;
- chunk->avelocity[2] = random()*600;
+ chunk->avelocity[0] = random() * 600;
+ chunk->avelocity[1] = random() * 600;
+ chunk->avelocity[2] = random() * 600;
chunk->think = G_FreeEdict;
- chunk->nextthink = level.time + 5 + random()*5;
+ chunk->nextthink = level.time + 5 + random() * 5;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_YES;
chunk->die = debris_die;
- gi.linkentity (chunk);
+ gi.linkentity(chunk);
}
-void BecomeExplosion1 (edict_t *self)
+void BecomeExplosion1(edict_t *self)
{
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_EXPLOSION1);
- gi.WritePosition (self->s.origin);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_EXPLOSION1);
+ gi.WritePosition(self->s.origin);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-void BecomeExplosion2 (edict_t *self)
+void BecomeExplosion2(edict_t *self)
{
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_EXPLOSION2);
- gi.WritePosition (self->s.origin);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_EXPLOSION2);
+ gi.WritePosition(self->s.origin);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
@@ -339,24 +324,23 @@ Pathtarget: gets used when an entity that has
this path_corner targeted touches it
*/
-void path_corner_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void path_corner_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t v;
edict_t *next;
if (other->movetarget != self)
return;
-
+
if (other->enemy)
return;
- if (self->pathtarget)
- {
+ if (self->pathtarget) {
char *savetarget;
savetarget = self->target;
self->target = self->pathtarget;
- G_UseTargets (self, other);
+ G_UseTargets(self, other);
self->target = savetarget;
}
@@ -365,52 +349,46 @@ void path_corner_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface
else
next = NULL;
- if ((next) && (next->spawnflags & 1))
- {
- VectorCopy (next->s.origin, v);
+ if ((next) && (next->spawnflags & 1)) {
+ VectorCopy(next->s.origin, v);
v[2] += next->mins[2];
v[2] -= other->mins[2];
- VectorCopy (v, other->s.origin);
+ VectorCopy(v, other->s.origin);
next = G_PickTarget(next->target);
other->s.event = EV_OTHER_TELEPORT;
}
other->goalentity = other->movetarget = next;
- if (self->wait)
- {
+ if (self->wait) {
other->monsterinfo.pausetime = level.time + self->wait;
- other->monsterinfo.stand (other);
+ other->monsterinfo.stand(other);
return;
}
- if (!other->movetarget)
- {
+ if (!other->movetarget) {
other->monsterinfo.pausetime = level.time + 100000000;
- other->monsterinfo.stand (other);
- }
- else
- {
- VectorSubtract (other->goalentity->s.origin, other->s.origin, v);
- other->ideal_yaw = vectoyaw (v);
+ other->monsterinfo.stand(other);
+ } else {
+ VectorSubtract(other->goalentity->s.origin, other->s.origin, v);
+ other->ideal_yaw = vectoyaw(v);
}
}
-void SP_path_corner (edict_t *self)
+void SP_path_corner(edict_t *self)
{
- if (!self->targetname)
- {
- gi.dprintf ("path_corner with no targetname at %s\n", vtos(self->s.origin));
- G_FreeEdict (self);
+ if (!self->targetname) {
+ gi.dprintf("path_corner with no targetname at %s\n", vtos(self->s.origin));
+ G_FreeEdict(self);
return;
}
self->solid = SOLID_TRIGGER;
self->touch = path_corner_touch;
- VectorSet (self->mins, -8, -8, -8);
- VectorSet (self->maxs, 8, 8, 8);
+ VectorSet(self->mins, -8, -8, -8);
+ VectorSet(self->maxs, 8, 8, 8);
self->svflags |= SVF_NOCLIENT;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -419,41 +397,35 @@ Makes this the target of a monster and it will head here
when first activated before going after the activator. If
hold is selected, it will stay here.
*/
-void point_combat_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void point_combat_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *activator;
if (other->movetarget != self)
return;
- if (self->target)
- {
+ if (self->target) {
other->target = self->target;
other->goalentity = other->movetarget = G_PickTarget(other->target);
- if (!other->goalentity)
- {
+ if (!other->goalentity) {
gi.dprintf("%s at %s target %s does not exist\n", self->classname, vtos(self->s.origin), self->target);
other->movetarget = self;
}
self->target = NULL;
- }
- else if ((self->spawnflags & 1) && !(other->flags & (FL_SWIM|FL_FLY)))
- {
+ } else if ((self->spawnflags & 1) && !(other->flags & (FL_SWIM | FL_FLY))) {
other->monsterinfo.pausetime = level.time + 100000000;
other->monsterinfo.aiflags |= AI_STAND_GROUND;
- other->monsterinfo.stand (other);
+ other->monsterinfo.stand(other);
}
- if (other->movetarget == self)
- {
+ if (other->movetarget == self) {
other->target = NULL;
other->movetarget = NULL;
other->goalentity = other->enemy;
other->monsterinfo.aiflags &= ~AI_COMBAT_POINT;
}
- if (self->pathtarget)
- {
+ if (self->pathtarget) {
char *savetarget;
savetarget = self->target;
@@ -466,24 +438,23 @@ void point_combat_touch (edict_t *self, edict_t *other, cplane_t *plane, csurfac
activator = other->activator;
else
activator = other;
- G_UseTargets (self, activator);
+ G_UseTargets(self, activator);
self->target = savetarget;
}
}
-void SP_point_combat (edict_t *self)
+void SP_point_combat(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
self->solid = SOLID_TRIGGER;
self->touch = point_combat_touch;
- VectorSet (self->mins, -8, -8, -16);
- VectorSet (self->maxs, 8, 8, 16);
+ VectorSet(self->mins, -8, -8, -16);
+ VectorSet(self->maxs, 8, 8, 16);
self->svflags = SVF_NOCLIENT;
- gi.linkentity (self);
+ gi.linkentity(self);
};
@@ -498,15 +469,15 @@ void TH_viewthing(edict_t *ent)
void SP_viewthing(edict_t *ent)
{
- gi.dprintf ("viewthing spawned\n");
+ gi.dprintf("viewthing spawned\n");
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
ent->s.renderfx = RF_FRAMELERP;
- VectorSet (ent->mins, -16, -16, -24);
- VectorSet (ent->maxs, 16, 16, 32);
- ent->s.modelindex = gi.modelindex ("models/objects/banner/tris.md2");
- gi.linkentity (ent);
+ VectorSet(ent->mins, -16, -16, -24);
+ VectorSet(ent->maxs, 16, 16, 32);
+ ent->s.modelindex = gi.modelindex("models/objects/banner/tris.md2");
+ gi.linkentity(ent);
ent->nextthink = level.time + 0.5;
ent->think = TH_viewthing;
return;
@@ -516,19 +487,19 @@ void SP_viewthing(edict_t *ent)
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for spotlights, etc.
*/
-void SP_info_null (edict_t *self)
+void SP_info_null(edict_t *self)
{
- G_FreeEdict (self);
+ G_FreeEdict(self);
};
/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for lightning.
*/
-void SP_info_notnull (edict_t *self)
+void SP_info_notnull(edict_t *self)
{
- VectorCopy (self->s.origin, self->absmin);
- VectorCopy (self->s.origin, self->absmax);
+ VectorCopy(self->s.origin, self->absmin);
+ VectorCopy(self->s.origin, self->absmax);
};
@@ -542,36 +513,31 @@ Default _cone value is 10 (used to set size of light for spotlights)
#define START_OFF 1
-void light_use (edict_t *self, edict_t *other, edict_t *activator)
+void light_use(edict_t *self, edict_t *other, edict_t *activator)
{
- if (self->spawnflags & START_OFF)
- {
- gi.configstring (CS_LIGHTS+self->style, "m");
+ if (self->spawnflags & START_OFF) {
+ gi.configstring(CS_LIGHTS + self->style, "m");
self->spawnflags &= ~START_OFF;
- }
- else
- {
- gi.configstring (CS_LIGHTS+self->style, "a");
+ } else {
+ gi.configstring(CS_LIGHTS + self->style, "a");
self->spawnflags |= START_OFF;
}
}
-void SP_light (edict_t *self)
+void SP_light(edict_t *self)
{
// no targeted lights in deathmatch, because they cause global messages
- if (!self->targetname || deathmatch->value)
- {
- G_FreeEdict (self);
+ if (!self->targetname || deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- if (self->style >= 32)
- {
+ if (self->style >= 32) {
self->use = light_use;
if (self->spawnflags & START_OFF)
- gi.configstring (CS_LIGHTS+self->style, "a");
+ gi.configstring(CS_LIGHTS + self->style, "a");
else
- gi.configstring (CS_LIGHTS+self->style, "m");
+ gi.configstring(CS_LIGHTS + self->style, "m");
}
}
@@ -590,29 +556,26 @@ START_ON only valid for TRIGGER_SPAWN walls
the wall will initially be present
*/
-void func_wall_use (edict_t *self, edict_t *other, edict_t *activator)
+void func_wall_use(edict_t *self, edict_t *other, edict_t *activator)
{
- if (self->solid == SOLID_NOT)
- {
+ if (self->solid == SOLID_NOT) {
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
- KillBox (self);
- }
- else
- {
+ KillBox(self);
+ } else {
self->solid = SOLID_NOT;
self->svflags |= SVF_NOCLIENT;
}
- gi.linkentity (self);
+ gi.linkentity(self);
if (!(self->spawnflags & 2))
self->use = NULL;
}
-void SP_func_wall (edict_t *self)
+void SP_func_wall(edict_t *self)
{
self->movetype = MOVETYPE_PUSH;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
if (self->spawnflags & 8)
self->s.effects |= EF_ANIM_ALL;
@@ -620,41 +583,34 @@ void SP_func_wall (edict_t *self)
self->s.effects |= EF_ANIM_ALLFAST;
// just a wall
- if ((self->spawnflags & 7) == 0)
- {
+ if ((self->spawnflags & 7) == 0) {
self->solid = SOLID_BSP;
- gi.linkentity (self);
+ gi.linkentity(self);
return;
}
// it must be TRIGGER_SPAWN
- if (!(self->spawnflags & 1))
- {
+ if (!(self->spawnflags & 1)) {
// gi.dprintf("func_wall missing TRIGGER_SPAWN\n");
self->spawnflags |= 1;
}
// yell if the spawnflags are odd
- if (self->spawnflags & 4)
- {
- if (!(self->spawnflags & 2))
- {
+ if (self->spawnflags & 4) {
+ if (!(self->spawnflags & 2)) {
gi.dprintf("func_wall START_ON without TOGGLE\n");
self->spawnflags |= 2;
}
}
self->use = func_wall_use;
- if (self->spawnflags & 4)
- {
+ if (self->spawnflags & 4) {
self->solid = SOLID_BSP;
- }
- else
- {
+ } else {
self->solid = SOLID_NOT;
self->svflags |= SVF_NOCLIENT;
}
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -662,7 +618,7 @@ void SP_func_wall (edict_t *self)
This is solid bmodel that will fall if it's support it removed.
*/
-void func_object_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void func_object_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
// only squash thing we fall on top of
if (!plane)
@@ -671,27 +627,27 @@ void func_object_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface
return;
if (other->takedamage == DAMAGE_NO)
return;
- T_Damage (other, self, self, vec3_origin, self->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
+ T_Damage(other, self, self, vec3_origin, self->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
-void func_object_release (edict_t *self)
+void func_object_release(edict_t *self)
{
self->movetype = MOVETYPE_TOSS;
self->touch = func_object_touch;
}
-void func_object_use (edict_t *self, edict_t *other, edict_t *activator)
+void func_object_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = NULL;
- KillBox (self);
- func_object_release (self);
+ KillBox(self);
+ func_object_release(self);
}
-void SP_func_object (edict_t *self)
+void SP_func_object(edict_t *self)
{
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
self->mins[0] += 1;
self->mins[1] += 1;
@@ -703,15 +659,12 @@ void SP_func_object (edict_t *self)
if (!self->dmg)
self->dmg = 100;
- if (self->spawnflags == 0)
- {
+ if (self->spawnflags == 0) {
self->solid = SOLID_BSP;
self->movetype = MOVETYPE_PUSH;
self->think = func_object_release;
self->nextthink = level.time + 2 * FRAMETIME;
- }
- else
- {
+ } else {
self->solid = SOLID_NOT;
self->movetype = MOVETYPE_PUSH;
self->use = func_object_use;
@@ -725,7 +678,7 @@ void SP_func_object (edict_t *self)
self->clipmask = MASK_MONSTERSOLID;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -742,7 +695,7 @@ mass defaults to 75. This determines how much debris is emitted when
it explodes. You get one large chunk per 100 of mass (up to 8) and
one small chunk per 25 of mass (up to 16). So 800 gives the most.
*/
-void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void func_explosive_explode(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
vec3_t origin;
vec3_t chunkorigin;
@@ -751,38 +704,36 @@ void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacke
int mass;
// bmodel origins are (0 0 0), we need to adjust that here
- VectorScale (self->size, 0.5, size);
- VectorAdd (self->absmin, size, origin);
- VectorCopy (origin, self->s.origin);
+ VectorScale(self->size, 0.5, size);
+ VectorAdd(self->absmin, size, origin);
+ VectorCopy(origin, self->s.origin);
self->takedamage = DAMAGE_NO;
if (self->dmg)
- T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);
+ T_RadiusDamage(self, attacker, self->dmg, NULL, self->dmg + 40, MOD_EXPLOSIVE);
- VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
- VectorNormalize (self->velocity);
- VectorScale (self->velocity, 150, self->velocity);
+ VectorSubtract(self->s.origin, inflictor->s.origin, self->velocity);
+ VectorNormalize(self->velocity);
+ VectorScale(self->velocity, 150, self->velocity);
// start chunks towards the center
- VectorScale (size, 0.5, size);
+ VectorScale(size, 0.5, size);
mass = self->mass;
if (!mass)
mass = 75;
// big chunks
- if (mass >= 100)
- {
+ if (mass >= 100) {
count = mass / 100;
if (count > 8)
count = 8;
- while(count--)
- {
+ while (count--) {
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
- ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
+ ThrowDebris(self, "models/objects/debris1/tris.md2", 1, chunkorigin);
}
}
@@ -790,59 +741,55 @@ void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacke
count = mass / 25;
if (count > 16)
count = 16;
- while(count--)
- {
+ while (count--) {
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", 2, chunkorigin);
}
- G_UseTargets (self, attacker);
+ G_UseTargets(self, attacker);
if (self->dmg)
- BecomeExplosion1 (self);
+ BecomeExplosion1(self);
else
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
void func_explosive_use(edict_t *self, edict_t *other, edict_t *activator)
{
- func_explosive_explode (self, self, other, self->health, vec3_origin);
+ func_explosive_explode(self, self, other, self->health, vec3_origin);
}
-void func_explosive_spawn (edict_t *self, edict_t *other, edict_t *activator)
+void func_explosive_spawn(edict_t *self, edict_t *other, edict_t *activator)
{
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = NULL;
- KillBox (self);
- gi.linkentity (self);
+ KillBox(self);
+ gi.linkentity(self);
}
-void SP_func_explosive (edict_t *self)
+void SP_func_explosive(edict_t *self)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(self);
return;
}
self->movetype = MOVETYPE_PUSH;
- gi.modelindex ("models/objects/debris1/tris.md2");
- gi.modelindex ("models/objects/debris2/tris.md2");
+ gi.modelindex("models/objects/debris1/tris.md2");
+ gi.modelindex("models/objects/debris2/tris.md2");
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
- if (self->spawnflags & 1)
- {
+ if (self->spawnflags & 1) {
self->svflags |= SVF_NOCLIENT;
self->solid = SOLID_NOT;
self->use = func_explosive_spawn;
- }
- else
- {
+ } else {
self->solid = SOLID_BSP;
if (self->targetname)
self->use = func_explosive_use;
@@ -853,15 +800,14 @@ void SP_func_explosive (edict_t *self)
if (self->spawnflags & 4)
self->s.effects |= EF_ANIM_ALLFAST;
- if (self->use != func_explosive_use)
- {
+ if (self->use != func_explosive_use) {
if (!self->health)
self->health = 100;
self->die = func_explosive_explode;
self->takedamage = DAMAGE_YES;
}
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -870,7 +816,7 @@ Large exploding box. You can override its mass (100),
health (80), and dmg (150).
*/
-void barrel_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void barrel_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
float ratio;
@@ -880,90 +826,90 @@ void barrel_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *s
return;
ratio = (float)other->mass / (float)self->mass;
- VectorSubtract (self->s.origin, other->s.origin, v);
- M_walkmove (self, vectoyaw(v), 20 * ratio * FRAMETIME);
+ VectorSubtract(self->s.origin, other->s.origin, v);
+ M_walkmove(self, vectoyaw(v), 20 * ratio * FRAMETIME);
}
-void barrel_explode (edict_t *self)
+void barrel_explode(edict_t *self)
{
vec3_t org;
float spd;
vec3_t save;
- T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40, MOD_BARREL);
+ T_RadiusDamage(self, self->activator, self->dmg, NULL, self->dmg + 40, MOD_BARREL);
- VectorCopy (self->s.origin, save);
- VectorMA (self->absmin, 0.5, self->size, self->s.origin);
+ VectorCopy(self->s.origin, save);
+ VectorMA(self->absmin, 0.5, self->size, self->s.origin);
// a few big chunks
spd = 1.5 * (float)self->dmg / 200.0;
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris1/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris1/tris.md2", spd, org);
// bottom corners
spd = 1.75 * (float)self->dmg / 200.0;
- VectorCopy (self->absmin, org);
- ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
- VectorCopy (self->absmin, org);
+ VectorCopy(self->absmin, org);
+ ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
+ VectorCopy(self->absmin, org);
org[0] += self->size[0];
- ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
- VectorCopy (self->absmin, org);
+ ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
+ VectorCopy(self->absmin, org);
org[1] += self->size[1];
- ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
- VectorCopy (self->absmin, org);
+ ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
+ VectorCopy(self->absmin, org);
org[0] += self->size[0];
org[1] += self->size[1];
- ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
// a bunch of little chunks
spd = 2 * self->dmg / 200;
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
- ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
+ ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
- VectorCopy (save, self->s.origin);
+ VectorCopy(save, self->s.origin);
if (self->groundentity)
- BecomeExplosion2 (self);
+ BecomeExplosion2(self);
else
- BecomeExplosion1 (self);
+ BecomeExplosion1(self);
}
-void barrel_delay (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void barrel_delay(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
self->takedamage = DAMAGE_NO;
self->nextthink = level.time + 2 * FRAMETIME;
@@ -971,25 +917,25 @@ void barrel_delay (edict_t *self, edict_t *inflictor, edict_t *attacker, int dam
self->activator = attacker;
}
-void SP_misc_explobox (edict_t *self)
+void SP_misc_explobox(edict_t *self)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(self);
return;
}
- gi.modelindex ("models/objects/debris1/tris.md2");
- gi.modelindex ("models/objects/debris2/tris.md2");
- gi.modelindex ("models/objects/debris3/tris.md2");
+ gi.modelindex("models/objects/debris1/tris.md2");
+ gi.modelindex("models/objects/debris2/tris.md2");
+ gi.modelindex("models/objects/debris3/tris.md2");
self->solid = SOLID_BBOX;
self->movetype = MOVETYPE_STEP;
self->model = "models/objects/barrels/tris.md2";
- self->s.modelindex = gi.modelindex (self->model);
- VectorSet (self->mins, -16, -16, 0);
- VectorSet (self->maxs, 16, 16, 40);
+ self->s.modelindex = gi.modelindex(self->model);
+ VectorSet(self->mins, -16, -16, 0);
+ VectorSet(self->maxs, 16, 16, 40);
if (!self->mass)
self->mass = 400;
@@ -1007,7 +953,7 @@ void SP_misc_explobox (edict_t *self)
self->think = M_droptofloor;
self->nextthink = level.time + 2 * FRAMETIME;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -1018,7 +964,7 @@ void SP_misc_explobox (edict_t *self)
/*QUAKED misc_blackhole (1 .5 0) (-8 -8 -8) (8 8 8)
*/
-void misc_blackhole_use (edict_t *ent, edict_t *other, edict_t *activator)
+void misc_blackhole_use(edict_t *ent, edict_t *other, edict_t *activator)
{
/*
gi.WriteByte (svc_temp_entity);
@@ -1026,115 +972,111 @@ void misc_blackhole_use (edict_t *ent, edict_t *other, edict_t *activator)
gi.WritePosition (ent->s.origin);
gi.multicast (ent->s.origin, MULTICAST_PVS);
*/
- G_FreeEdict (ent);
+ G_FreeEdict(ent);
}
-void misc_blackhole_think (edict_t *self)
+void misc_blackhole_think(edict_t *self)
{
if (++self->s.frame < 19)
self->nextthink = level.time + FRAMETIME;
- else
- {
+ else {
self->s.frame = 0;
self->nextthink = level.time + FRAMETIME;
}
}
-void SP_misc_blackhole (edict_t *ent)
+void SP_misc_blackhole(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_NOT;
- VectorSet (ent->mins, -64, -64, 0);
- VectorSet (ent->maxs, 64, 64, 8);
- ent->s.modelindex = gi.modelindex ("models/objects/black/tris.md2");
+ VectorSet(ent->mins, -64, -64, 0);
+ VectorSet(ent->maxs, 64, 64, 8);
+ ent->s.modelindex = gi.modelindex("models/objects/black/tris.md2");
ent->s.renderfx = RF_TRANSLUCENT;
ent->use = misc_blackhole_use;
ent->think = misc_blackhole_think;
ent->nextthink = level.time + 2 * FRAMETIME;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_eastertank (1 .5 0) (-32 -32 -16) (32 32 32)
*/
-void misc_eastertank_think (edict_t *self)
+void misc_eastertank_think(edict_t *self)
{
if (++self->s.frame < 293)
self->nextthink = level.time + FRAMETIME;
- else
- {
+ else {
self->s.frame = 254;
self->nextthink = level.time + FRAMETIME;
}
}
-void SP_misc_eastertank (edict_t *ent)
+void SP_misc_eastertank(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -32, -32, -16);
- VectorSet (ent->maxs, 32, 32, 32);
- ent->s.modelindex = gi.modelindex ("models/monsters/tank/tris.md2");
+ VectorSet(ent->mins, -32, -32, -16);
+ VectorSet(ent->maxs, 32, 32, 32);
+ ent->s.modelindex = gi.modelindex("models/monsters/tank/tris.md2");
ent->s.frame = 254;
ent->think = misc_eastertank_think;
ent->nextthink = level.time + 2 * FRAMETIME;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_easterchick (1 .5 0) (-32 -32 0) (32 32 32)
*/
-void misc_easterchick_think (edict_t *self)
+void misc_easterchick_think(edict_t *self)
{
if (++self->s.frame < 247)
self->nextthink = level.time + FRAMETIME;
- else
- {
+ else {
self->s.frame = 208;
self->nextthink = level.time + FRAMETIME;
}
}
-void SP_misc_easterchick (edict_t *ent)
+void SP_misc_easterchick(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -32, -32, 0);
- VectorSet (ent->maxs, 32, 32, 32);
- ent->s.modelindex = gi.modelindex ("models/monsters/bitch/tris.md2");
+ VectorSet(ent->mins, -32, -32, 0);
+ VectorSet(ent->maxs, 32, 32, 32);
+ ent->s.modelindex = gi.modelindex("models/monsters/bitch/tris.md2");
ent->s.frame = 208;
ent->think = misc_easterchick_think;
ent->nextthink = level.time + 2 * FRAMETIME;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_easterchick2 (1 .5 0) (-32 -32 0) (32 32 32)
*/
-void misc_easterchick2_think (edict_t *self)
+void misc_easterchick2_think(edict_t *self)
{
if (++self->s.frame < 287)
self->nextthink = level.time + FRAMETIME;
- else
- {
+ else {
self->s.frame = 248;
self->nextthink = level.time + FRAMETIME;
}
}
-void SP_misc_easterchick2 (edict_t *ent)
+void SP_misc_easterchick2(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -32, -32, 0);
- VectorSet (ent->maxs, 32, 32, 32);
- ent->s.modelindex = gi.modelindex ("models/monsters/bitch/tris.md2");
+ VectorSet(ent->mins, -32, -32, 0);
+ VectorSet(ent->maxs, 32, 32, 32);
+ ent->s.modelindex = gi.modelindex("models/monsters/bitch/tris.md2");
ent->s.frame = 248;
ent->think = misc_easterchick2_think;
ent->nextthink = level.time + 2 * FRAMETIME;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
@@ -1143,7 +1085,7 @@ Not really a monster, this is the Tank Commander's decapitated body.
There should be a item_commander_head that has this as it's target.
*/
-void commander_body_think (edict_t *self)
+void commander_body_think(edict_t *self)
{
if (++self->s.frame < 24)
self->nextthink = level.time + FRAMETIME;
@@ -1151,38 +1093,38 @@ void commander_body_think (edict_t *self)
self->nextthink = 0;
if (self->s.frame == 22)
- gi.sound (self, CHAN_BODY, gi.soundindex ("tank/thud.wav"), 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, gi.soundindex("tank/thud.wav"), 1, ATTN_NORM, 0);
}
-void commander_body_use (edict_t *self, edict_t *other, edict_t *activator)
+void commander_body_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->think = commander_body_think;
self->nextthink = level.time + FRAMETIME;
- gi.sound (self, CHAN_BODY, gi.soundindex ("tank/pain.wav"), 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, gi.soundindex("tank/pain.wav"), 1, ATTN_NORM, 0);
}
-void commander_body_drop (edict_t *self)
+void commander_body_drop(edict_t *self)
{
self->movetype = MOVETYPE_TOSS;
self->s.origin[2] += 2;
}
-void SP_monster_commander_body (edict_t *self)
+void SP_monster_commander_body(edict_t *self)
{
self->movetype = MOVETYPE_NONE;
self->solid = SOLID_BBOX;
self->model = "models/monsters/commandr/tris.md2";
- self->s.modelindex = gi.modelindex (self->model);
- VectorSet (self->mins, -32, -32, 0);
- VectorSet (self->maxs, 32, 32, 48);
+ self->s.modelindex = gi.modelindex(self->model);
+ VectorSet(self->mins, -32, -32, 0);
+ VectorSet(self->maxs, 32, 32, 48);
self->use = commander_body_use;
self->takedamage = DAMAGE_YES;
self->flags = FL_GODMODE;
self->s.renderfx |= RF_FRAMELERP;
- gi.linkentity (self);
+ gi.linkentity(self);
- gi.soundindex ("tank/thud.wav");
- gi.soundindex ("tank/pain.wav");
+ gi.soundindex("tank/thud.wav");
+ gi.soundindex("tank/pain.wav");
self->think = commander_body_drop;
self->nextthink = level.time + 5 * FRAMETIME;
@@ -1193,19 +1135,19 @@ void SP_monster_commander_body (edict_t *self)
The origin is the bottom of the banner.
The banner is 128 tall.
*/
-void misc_banner_think (edict_t *ent)
+void misc_banner_think(edict_t *ent)
{
ent->s.frame = (ent->s.frame + 1) % 16;
ent->nextthink = level.time + FRAMETIME;
}
-void SP_misc_banner (edict_t *ent)
+void SP_misc_banner(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_NOT;
- ent->s.modelindex = gi.modelindex ("models/objects/banner/tris.md2");
+ ent->s.modelindex = gi.modelindex("models/objects/banner/tris.md2");
ent->s.frame = rand() % 16;
- gi.linkentity (ent);
+ gi.linkentity(ent);
ent->think = misc_banner_think;
ent->nextthink = level.time + FRAMETIME;
@@ -1214,30 +1156,30 @@ void SP_misc_banner (edict_t *ent)
/*QUAKED misc_deadsoldier (1 .5 0) (-16 -16 0) (16 16 16) ON_BACK ON_STOMACH BACK_DECAP FETAL_POS SIT_DECAP IMPALED
This is the dead player model. Comes in 6 exciting different poses!
*/
-void misc_deadsoldier_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void misc_deadsoldier_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
if (self->health > -80)
return;
- gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ gi.sound(self, CHAN_BODY, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
}
-void SP_misc_deadsoldier (edict_t *ent)
+void SP_misc_deadsoldier(edict_t *ent)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (ent);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(ent);
return;
}
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- ent->s.modelindex=gi.modelindex ("models/deadbods/dude/tris.md2");
+ ent->s.modelindex = gi.modelindex("models/deadbods/dude/tris.md2");
// Defaults to frame 0
if (ent->spawnflags & 2)
@@ -1253,15 +1195,15 @@ void SP_misc_deadsoldier (edict_t *ent)
else
ent->s.frame = 0;
- VectorSet (ent->mins, -16, -16, 0);
- VectorSet (ent->maxs, 16, 16, 16);
+ VectorSet(ent->mins, -16, -16, 0);
+ VectorSet(ent->maxs, 16, 16, 16);
ent->deadflag = DEAD_DEAD;
ent->takedamage = DAMAGE_YES;
- ent->svflags |= SVF_MONSTER|SVF_DEADMONSTER;
+ ent->svflags |= SVF_MONSTER | SVF_DEADMONSTER;
ent->die = misc_deadsoldier_die;
ent->monsterinfo.aiflags |= AI_GOOD_GUY;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_viper (1 .5 0) (-16 -16 0) (16 16 32)
@@ -1272,22 +1214,21 @@ There must be a path for it to follow once it is activated.
"speed" How fast the Viper should fly
*/
-extern void train_use (edict_t *self, edict_t *other, edict_t *activator);
-extern void func_train_find (edict_t *self);
+extern void train_use(edict_t *self, edict_t *other, edict_t *activator);
+extern void func_train_find(edict_t *self);
-void misc_viper_use (edict_t *self, edict_t *other, edict_t *activator)
+void misc_viper_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->svflags &= ~SVF_NOCLIENT;
self->use = train_use;
- train_use (self, other, activator);
+ train_use(self, other, activator);
}
-void SP_misc_viper (edict_t *ent)
+void SP_misc_viper(edict_t *ent)
{
- if (!ent->target)
- {
- gi.dprintf ("misc_viper without a target at %s\n", vtos(ent->absmin));
- G_FreeEdict (ent);
+ if (!ent->target) {
+ gi.dprintf("misc_viper without a target at %s\n", vtos(ent->absmin));
+ G_FreeEdict(ent);
return;
}
@@ -1296,9 +1237,9 @@ void SP_misc_viper (edict_t *ent)
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_NOT;
- ent->s.modelindex = gi.modelindex ("models/ships/viper/tris.md2");
- VectorSet (ent->mins, -16, -16, 0);
- VectorSet (ent->maxs, 16, 16, 32);
+ ent->s.modelindex = gi.modelindex("models/ships/viper/tris.md2");
+ VectorSet(ent->mins, -16, -16, 0);
+ VectorSet(ent->maxs, 16, 16, 32);
ent->think = func_train_find;
ent->nextthink = level.time + FRAMETIME;
@@ -1306,37 +1247,37 @@ void SP_misc_viper (edict_t *ent)
ent->svflags |= SVF_NOCLIENT;
ent->moveinfo.accel = ent->moveinfo.decel = ent->moveinfo.speed = ent->speed;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
-/*QUAKED misc_bigviper (1 .5 0) (-176 -120 -24) (176 120 72)
+/*QUAKED misc_bigviper (1 .5 0) (-176 -120 -24) (176 120 72)
This is a large stationary viper as seen in Paul's intro
*/
-void SP_misc_bigviper (edict_t *ent)
+void SP_misc_bigviper(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -176, -120, -24);
- VectorSet (ent->maxs, 176, 120, 72);
- ent->s.modelindex = gi.modelindex ("models/ships/bigviper/tris.md2");
- gi.linkentity (ent);
+ VectorSet(ent->mins, -176, -120, -24);
+ VectorSet(ent->maxs, 176, 120, 72);
+ ent->s.modelindex = gi.modelindex("models/ships/bigviper/tris.md2");
+ gi.linkentity(ent);
}
/*QUAKED misc_viper_bomb (1 0 0) (-8 -8 -8) (8 8 8)
"dmg" how much boom should the bomb make?
*/
-void misc_viper_bomb_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void misc_viper_bomb_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
- G_UseTargets (self, self->activator);
+ G_UseTargets(self, self->activator);
self->s.origin[2] = self->absmin[2] + 1;
- T_RadiusDamage (self, self, self->dmg, NULL, self->dmg+40, MOD_BOMB);
- BecomeExplosion2 (self);
+ T_RadiusDamage(self, self, self->dmg, NULL, self->dmg + 40, MOD_BOMB);
+ BecomeExplosion2(self);
}
-void misc_viper_bomb_prethink (edict_t *self)
+void misc_viper_bomb_prethink(edict_t *self)
{
vec3_t v;
float diff;
@@ -1347,15 +1288,15 @@ void misc_viper_bomb_prethink (edict_t *self)
if (diff < -1.0)
diff = -1.0;
- VectorScale (self->moveinfo.dir, 1.0 + diff, v);
+ VectorScale(self->moveinfo.dir, 1.0 + diff, v);
v[2] = diff;
diff = self->s.angles[2];
- vectoangles (v, self->s.angles);
+ vectoangles(v, self->s.angles);
self->s.angles[2] = diff + 10;
}
-void misc_viper_bomb_use (edict_t *self, edict_t *other, edict_t *activator)
+void misc_viper_bomb_use(edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *viper;
@@ -1368,21 +1309,21 @@ void misc_viper_bomb_use (edict_t *self, edict_t *other, edict_t *activator)
self->touch = misc_viper_bomb_touch;
self->activator = activator;
- viper = G_Find (NULL, FOFS(classname), "misc_viper");
- VectorScale (viper->moveinfo.dir, viper->moveinfo.speed, self->velocity);
+ viper = G_Find(NULL, FOFS(classname), "misc_viper");
+ VectorScale(viper->moveinfo.dir, viper->moveinfo.speed, self->velocity);
self->timestamp = level.time;
- VectorCopy (viper->moveinfo.dir, self->moveinfo.dir);
+ VectorCopy(viper->moveinfo.dir, self->moveinfo.dir);
}
-void SP_misc_viper_bomb (edict_t *self)
+void SP_misc_viper_bomb(edict_t *self)
{
self->movetype = MOVETYPE_NONE;
self->solid = SOLID_NOT;
- VectorSet (self->mins, -8, -8, -8);
- VectorSet (self->maxs, 8, 8, 8);
+ VectorSet(self->mins, -8, -8, -8);
+ VectorSet(self->maxs, 8, 8, 8);
- self->s.modelindex = gi.modelindex ("models/objects/bomb/tris.md2");
+ self->s.modelindex = gi.modelindex("models/objects/bomb/tris.md2");
if (!self->dmg)
self->dmg = 1000;
@@ -1390,7 +1331,7 @@ void SP_misc_viper_bomb (edict_t *self)
self->use = misc_viper_bomb_use;
self->svflags |= SVF_NOCLIENT;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -1402,22 +1343,21 @@ There must be a path for it to follow once it is activated.
"speed" How fast it should fly
*/
-extern void train_use (edict_t *self, edict_t *other, edict_t *activator);
-extern void func_train_find (edict_t *self);
+extern void train_use(edict_t *self, edict_t *other, edict_t *activator);
+extern void func_train_find(edict_t *self);
-void misc_strogg_ship_use (edict_t *self, edict_t *other, edict_t *activator)
+void misc_strogg_ship_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->svflags &= ~SVF_NOCLIENT;
self->use = train_use;
- train_use (self, other, activator);
+ train_use(self, other, activator);
}
-void SP_misc_strogg_ship (edict_t *ent)
+void SP_misc_strogg_ship(edict_t *ent)
{
- if (!ent->target)
- {
- gi.dprintf ("%s without a target at %s\n", ent->classname, vtos(ent->absmin));
- G_FreeEdict (ent);
+ if (!ent->target) {
+ gi.dprintf("%s without a target at %s\n", ent->classname, vtos(ent->absmin));
+ G_FreeEdict(ent);
return;
}
@@ -1426,9 +1366,9 @@ void SP_misc_strogg_ship (edict_t *ent)
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_NOT;
- ent->s.modelindex = gi.modelindex ("models/ships/strogg1/tris.md2");
- VectorSet (ent->mins, -16, -16, 0);
- VectorSet (ent->maxs, 16, 16, 32);
+ ent->s.modelindex = gi.modelindex("models/ships/strogg1/tris.md2");
+ VectorSet(ent->mins, -16, -16, 0);
+ VectorSet(ent->maxs, 16, 16, 32);
ent->think = func_train_find;
ent->nextthink = level.time + FRAMETIME;
@@ -1436,66 +1376,66 @@ void SP_misc_strogg_ship (edict_t *ent)
ent->svflags |= SVF_NOCLIENT;
ent->moveinfo.accel = ent->moveinfo.decel = ent->moveinfo.speed = ent->speed;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_satellite_dish (1 .5 0) (-64 -64 0) (64 64 128)
*/
-void misc_satellite_dish_think (edict_t *self)
+void misc_satellite_dish_think(edict_t *self)
{
self->s.frame++;
if (self->s.frame < 38)
self->nextthink = level.time + FRAMETIME;
}
-void misc_satellite_dish_use (edict_t *self, edict_t *other, edict_t *activator)
+void misc_satellite_dish_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->s.frame = 0;
self->think = misc_satellite_dish_think;
self->nextthink = level.time + FRAMETIME;
}
-void SP_misc_satellite_dish (edict_t *ent)
+void SP_misc_satellite_dish(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -64, -64, 0);
- VectorSet (ent->maxs, 64, 64, 128);
- ent->s.modelindex = gi.modelindex ("models/objects/satellite/tris.md2");
+ VectorSet(ent->mins, -64, -64, 0);
+ VectorSet(ent->maxs, 64, 64, 128);
+ ent->s.modelindex = gi.modelindex("models/objects/satellite/tris.md2");
ent->use = misc_satellite_dish_use;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED light_mine1 (0 1 0) (-2 -2 -12) (2 2 12)
*/
-void SP_light_mine1 (edict_t *ent)
+void SP_light_mine1(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- ent->s.modelindex = gi.modelindex ("models/objects/minelite/light1/tris.md2");
- gi.linkentity (ent);
+ ent->s.modelindex = gi.modelindex("models/objects/minelite/light1/tris.md2");
+ gi.linkentity(ent);
}
/*QUAKED light_mine2 (0 1 0) (-2 -2 -12) (2 2 12)
*/
-void SP_light_mine2 (edict_t *ent)
+void SP_light_mine2(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
- ent->s.modelindex = gi.modelindex ("models/objects/minelite/light2/tris.md2");
- gi.linkentity (ent);
+ ent->s.modelindex = gi.modelindex("models/objects/minelite/light2/tris.md2");
+ gi.linkentity(ent);
}
/*QUAKED misc_gib_arm (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*/
-void SP_misc_gib_arm (edict_t *ent)
+void SP_misc_gib_arm(edict_t *ent)
{
- gi.setmodel (ent, "models/objects/gibs/arm/tris.md2");
+ gi.setmodel(ent, "models/objects/gibs/arm/tris.md2");
ent->solid = SOLID_NOT;
ent->s.effects |= EF_GIB;
ent->takedamage = DAMAGE_YES;
@@ -1503,20 +1443,20 @@ void SP_misc_gib_arm (edict_t *ent)
ent->movetype = MOVETYPE_TOSS;
ent->svflags |= SVF_MONSTER;
ent->deadflag = DEAD_DEAD;
- ent->avelocity[0] = random()*200;
- ent->avelocity[1] = random()*200;
- ent->avelocity[2] = random()*200;
+ ent->avelocity[0] = random() * 200;
+ ent->avelocity[1] = random() * 200;
+ ent->avelocity[2] = random() * 200;
ent->think = G_FreeEdict;
ent->nextthink = level.time + 30;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_gib_leg (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*/
-void SP_misc_gib_leg (edict_t *ent)
+void SP_misc_gib_leg(edict_t *ent)
{
- gi.setmodel (ent, "models/objects/gibs/leg/tris.md2");
+ gi.setmodel(ent, "models/objects/gibs/leg/tris.md2");
ent->solid = SOLID_NOT;
ent->s.effects |= EF_GIB;
ent->takedamage = DAMAGE_YES;
@@ -1524,20 +1464,20 @@ void SP_misc_gib_leg (edict_t *ent)
ent->movetype = MOVETYPE_TOSS;
ent->svflags |= SVF_MONSTER;
ent->deadflag = DEAD_DEAD;
- ent->avelocity[0] = random()*200;
- ent->avelocity[1] = random()*200;
- ent->avelocity[2] = random()*200;
+ ent->avelocity[0] = random() * 200;
+ ent->avelocity[1] = random() * 200;
+ ent->avelocity[2] = random() * 200;
ent->think = G_FreeEdict;
ent->nextthink = level.time + 30;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
/*QUAKED misc_gib_head (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*/
-void SP_misc_gib_head (edict_t *ent)
+void SP_misc_gib_head(edict_t *ent)
{
- gi.setmodel (ent, "models/objects/gibs/head/tris.md2");
+ gi.setmodel(ent, "models/objects/gibs/head/tris.md2");
ent->solid = SOLID_NOT;
ent->s.effects |= EF_GIB;
ent->takedamage = DAMAGE_YES;
@@ -1545,12 +1485,12 @@ void SP_misc_gib_head (edict_t *ent)
ent->movetype = MOVETYPE_TOSS;
ent->svflags |= SVF_MONSTER;
ent->deadflag = DEAD_DEAD;
- ent->avelocity[0] = random()*200;
- ent->avelocity[1] = random()*200;
- ent->avelocity[2] = random()*200;
+ ent->avelocity[0] = random() * 200;
+ ent->avelocity[1] = random() * 200;
+ ent->avelocity[2] = random() * 200;
ent->think = G_FreeEdict;
ent->nextthink = level.time + 30;
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
//=====================================================
@@ -1560,13 +1500,13 @@ used with target_string (must be on same "team")
"count" is position in the string (starts at 1)
*/
-void SP_target_character (edict_t *self)
+void SP_target_character(edict_t *self)
{
self->movetype = MOVETYPE_PUSH;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
self->solid = SOLID_BSP;
self->s.frame = 12;
- gi.linkentity (self);
+ gi.linkentity(self);
return;
}
@@ -1574,20 +1514,18 @@ void SP_target_character (edict_t *self)
/*QUAKED target_string (0 0 1) (-8 -8 -8) (8 8 8)
*/
-void target_string_use (edict_t *self, edict_t *other, edict_t *activator)
+void target_string_use(edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *e;
int n, l;
char c;
l = strlen(self->message);
- for (e = self->teammaster; e; e = e->teamchain)
- {
+ for (e = self->teammaster; e; e = e->teamchain) {
if (!e->count)
continue;
n = e->count - 1;
- if (n > l)
- {
+ if (n > l) {
e->s.frame = 12;
continue;
}
@@ -1604,7 +1542,7 @@ void target_string_use (edict_t *self, edict_t *other, edict_t *activator)
}
}
-void SP_target_string (edict_t *self)
+void SP_target_string(edict_t *self)
{
if (!self->message)
self->message = "";
@@ -1632,39 +1570,33 @@ If START_OFF, this entity must be used before it starts
// TODO: skuller: fix savegame restore bug
-static void func_clock_reset (edict_t *self)
+static void func_clock_reset(edict_t *self)
{
self->activator = NULL;
- if (self->spawnflags & 1)
- {
+ if (self->spawnflags & 1) {
self->health = 0;
self->wait = self->count;
- }
- else if (self->spawnflags & 2)
- {
+ } else if (self->spawnflags & 2) {
self->health = self->count;
self->wait = 0;
}
}
-static void func_clock_format_countdown (edict_t *self)
+static void func_clock_format_countdown(edict_t *self)
{
- if (self->style == 0)
- {
- Q_snprintf (self->message, CLOCK_MESSAGE_SIZE, "%2i", self->health);
+ if (self->style == 0) {
+ Q_snprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i", self->health);
return;
}
- if (self->style == 1)
- {
+ if (self->style == 1) {
Q_snprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i", self->health / 60, self->health % 60);
if (self->message[3] == ' ')
self->message[3] = '0';
return;
}
- if (self->style == 2)
- {
+ if (self->style == 2) {
Q_snprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", self->health / 3600, (self->health - (self->health / 3600) * 3600) / 60, self->health % 60);
if (self->message[3] == ' ')
self->message[3] = '0';
@@ -1674,33 +1606,27 @@ static void func_clock_format_countdown (edict_t *self)
}
}
-void func_clock_think (edict_t *self)
+void func_clock_think(edict_t *self)
{
- if (!self->enemy)
- {
- self->enemy = G_Find (NULL, FOFS(targetname), self->target);
+ if (!self->enemy) {
+ self->enemy = G_Find(NULL, FOFS(targetname), self->target);
if (!self->enemy)
return;
}
- if (self->spawnflags & 1)
- {
- func_clock_format_countdown (self);
+ if (self->spawnflags & 1) {
+ func_clock_format_countdown(self);
self->health++;
- }
- else if (self->spawnflags & 2)
- {
- func_clock_format_countdown (self);
+ } else if (self->spawnflags & 2) {
+ func_clock_format_countdown(self);
self->health--;
- }
- else
- {
+ } else {
struct tm *ltime;
time_t gmtime;
time(&gmtime);
ltime = localtime(&gmtime);
- Q_snprintf (self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
+ Q_snprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
if (self->message[3] == ' ')
self->message[3] = '0';
if (self->message[6] == ' ')
@@ -1708,13 +1634,11 @@ void func_clock_think (edict_t *self)
}
self->enemy->message = self->message;
- self->enemy->use (self->enemy, self, self);
+ self->enemy->use(self->enemy, self, self);
if (((self->spawnflags & 1) && (self->health > self->wait)) ||
- ((self->spawnflags & 2) && (self->health < self->wait)))
- {
- if (self->pathtarget)
- {
+ ((self->spawnflags & 2) && (self->health < self->wait))) {
+ if (self->pathtarget) {
char *savetarget;
char *savemessage;
@@ -1722,7 +1646,7 @@ void func_clock_think (edict_t *self)
savemessage = self->message;
self->target = self->pathtarget;
self->message = NULL;
- G_UseTargets (self, self->activator);
+ G_UseTargets(self, self->activator);
self->target = savetarget;
self->message = savemessage;
}
@@ -1730,7 +1654,7 @@ void func_clock_think (edict_t *self)
if (!(self->spawnflags & 8))
return;
- func_clock_reset (self);
+ func_clock_reset(self);
if (self->spawnflags & 4)
return;
@@ -1739,38 +1663,36 @@ void func_clock_think (edict_t *self)
self->nextthink = level.time + 1;
}
-void func_clock_use (edict_t *self, edict_t *other, edict_t *activator)
+void func_clock_use(edict_t *self, edict_t *other, edict_t *activator)
{
if (!(self->spawnflags & 8))
self->use = NULL;
if (self->activator)
return;
self->activator = activator;
- self->think (self);
+ self->think(self);
}
-void SP_func_clock (edict_t *self)
+void SP_func_clock(edict_t *self)
{
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
- if ((self->spawnflags & 2) && (!self->count))
- {
+ if ((self->spawnflags & 2) && (!self->count)) {
gi.dprintf("%s with no count at %s\n", self->classname, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
if ((self->spawnflags & 1) && (!self->count))
- self->count = 60*60;;
+ self->count = 60 * 60;;
- func_clock_reset (self);
+ func_clock_reset(self);
- self->message = gi.TagMalloc (CLOCK_MESSAGE_SIZE, TAG_LEVEL);
+ self->message = gi.TagMalloc(CLOCK_MESSAGE_SIZE, TAG_LEVEL);
self->think = func_clock_think;
@@ -1782,30 +1704,29 @@ void SP_func_clock (edict_t *self)
//=================================================================================
-void teleporter_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void teleporter_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *dest;
int i;
if (!other->client)
return;
- dest = G_Find (NULL, FOFS(targetname), self->target);
- if (!dest)
- {
- gi.dprintf ("Couldn't find destination\n");
+ dest = G_Find(NULL, FOFS(targetname), self->target);
+ if (!dest) {
+ gi.dprintf("Couldn't find destination\n");
return;
}
// unlink to make sure it can't possibly interfere with KillBox
- gi.unlinkentity (other);
+ gi.unlinkentity(other);
- VectorCopy (dest->s.origin, other->s.origin);
- VectorCopy (dest->s.origin, other->s.old_origin);
+ VectorCopy(dest->s.origin, other->s.origin);
+ VectorCopy(dest->s.origin, other->s.old_origin);
other->s.origin[2] += 10;
// clear the velocity and hold them in place briefly
- VectorClear (other->velocity);
- other->client->ps.pmove.pm_time = 160>>3; // hold time
+ VectorClear(other->velocity);
+ other->client->ps.pmove.pm_time = 160 >> 3; // hold time
other->client->ps.pmove.pm_flags |= PMF_TIME_TELEPORT;
// draw the teleport splash at source and on the player
@@ -1813,68 +1734,66 @@ void teleporter_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_
other->s.event = EV_PLAYER_TELEPORT;
// set angles
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
other->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(dest->s.angles[i] - other->client->resp.cmd_angles[i]);
}
- VectorClear (other->s.angles);
- VectorClear (other->client->ps.viewangles);
- VectorClear (other->client->v_angle);
+ VectorClear(other->s.angles);
+ VectorClear(other->client->ps.viewangles);
+ VectorClear(other->client->v_angle);
// kill anything at the destination
- KillBox (other);
+ KillBox(other);
- gi.linkentity (other);
+ gi.linkentity(other);
}
/*QUAKED misc_teleporter (1 0 0) (-32 -32 -24) (32 32 -16)
Stepping onto this disc will teleport players to the targeted misc_teleporter_dest object.
*/
-void SP_misc_teleporter (edict_t *ent)
+void SP_misc_teleporter(edict_t *ent)
{
edict_t *trig;
- if (!ent->target)
- {
- gi.dprintf ("teleporter without a target.\n");
- G_FreeEdict (ent);
+ if (!ent->target) {
+ gi.dprintf("teleporter without a target.\n");
+ G_FreeEdict(ent);
return;
}
- gi.setmodel (ent, "models/objects/dmspot/tris.md2");
+ gi.setmodel(ent, "models/objects/dmspot/tris.md2");
ent->s.skinnum = 1;
ent->s.effects = EF_TELEPORTER;
- ent->s.sound = gi.soundindex ("world/amb10.wav");
+ ent->s.sound = gi.soundindex("world/amb10.wav");
ent->solid = SOLID_BBOX;
- VectorSet (ent->mins, -32, -32, -24);
- VectorSet (ent->maxs, 32, 32, -16);
- gi.linkentity (ent);
+ VectorSet(ent->mins, -32, -32, -24);
+ VectorSet(ent->maxs, 32, 32, -16);
+ gi.linkentity(ent);
- trig = G_Spawn ();
+ trig = G_Spawn();
trig->touch = teleporter_touch;
trig->solid = SOLID_TRIGGER;
trig->target = ent->target;
trig->owner = ent;
- VectorCopy (ent->s.origin, trig->s.origin);
- VectorSet (trig->mins, -8, -8, 8);
- VectorSet (trig->maxs, 8, 8, 24);
- gi.linkentity (trig);
-
+ VectorCopy(ent->s.origin, trig->s.origin);
+ VectorSet(trig->mins, -8, -8, 8);
+ VectorSet(trig->maxs, 8, 8, 24);
+ gi.linkentity(trig);
+
}
/*QUAKED misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16)
Point teleporters at these.
*/
-void SP_misc_teleporter_dest (edict_t *ent)
+void SP_misc_teleporter_dest(edict_t *ent)
{
- gi.setmodel (ent, "models/objects/dmspot/tris.md2");
+ gi.setmodel(ent, "models/objects/dmspot/tris.md2");
ent->s.skinnum = 0;
ent->solid = SOLID_BBOX;
// ent->s.effects |= EF_FLIES;
- VectorSet (ent->mins, -32, -32, -24);
- VectorSet (ent->maxs, 32, 32, -16);
- gi.linkentity (ent);
+ VectorSet(ent->mins, -32, -32, -24);
+ VectorSet(ent->maxs, 32, 32, -16);
+ gi.linkentity(ent);
}
diff --git a/src/baseq2/g_monster.c b/src/baseq2/g_monster.c
index 3aa8e7e..263ff03 100644
--- a/src/baseq2/g_monster.c
+++ b/src/baseq2/g_monster.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,74 +28,74 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// and we can mess it up based on skill. Spread should be for normal
// and we can tighten or loosen based on skill. We could muck with
// the damages too, but I'm not sure that's such a good idea.
-void monster_fire_bullet (edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype)
+void monster_fire_bullet(edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype)
{
- fire_bullet (self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN);
+ fire_bullet(self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
}
-void monster_fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype)
+void monster_fire_shotgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype)
{
- fire_shotgun (self, start, aimdir, damage, kick, hspread, vspread, count, MOD_UNKNOWN);
+ fire_shotgun(self, start, aimdir, damage, kick, hspread, vspread, count, MOD_UNKNOWN);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
}
-void monster_fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect)
+void monster_fire_blaster(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect)
{
- fire_blaster (self, start, dir, damage, speed, effect, qfalse);
+ fire_blaster(self, start, dir, damage, speed, effect, qfalse);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
-}
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
+}
-void monster_fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype)
+void monster_fire_grenade(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype)
{
- fire_grenade (self, start, aimdir, damage, speed, 2.5, damage+40);
+ fire_grenade(self, start, aimdir, damage, speed, 2.5, damage + 40);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
}
-void monster_fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype)
+void monster_fire_rocket(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype)
{
- fire_rocket (self, start, dir, damage, speed, damage+20, damage);
+ fire_rocket(self, start, dir, damage, speed, damage + 20, damage);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
-}
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
+}
-void monster_fire_railgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype)
+void monster_fire_railgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype)
{
- fire_rail (self, start, aimdir, damage, kick);
+ fire_rail(self, start, aimdir, damage, kick);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
}
-void monster_fire_bfg (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype)
+void monster_fire_bfg(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype)
{
- fire_bfg (self, start, aimdir, damage, speed, damage_radius);
+ fire_bfg(self, start, aimdir, damage, speed, damage_radius);
- gi.WriteByte (svc_muzzleflash2);
- gi.WriteShort (self - g_edicts);
- gi.WriteByte (flashtype);
- gi.multicast (start, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash2);
+ gi.WriteShort(self - g_edicts);
+ gi.WriteByte(flashtype);
+ gi.multicast(start, MULTICAST_PVS);
}
@@ -104,23 +104,23 @@ void monster_fire_bfg (edict_t *self, vec3_t start, vec3_t aimdir, int damage, i
// Monster utility functions
//
-void M_FliesOff (edict_t *self)
+void M_FliesOff(edict_t *self)
{
self->s.effects &= ~EF_FLIES;
self->s.sound = 0;
}
-void M_FliesOn (edict_t *self)
+void M_FliesOn(edict_t *self)
{
if (self->waterlevel)
return;
self->s.effects |= EF_FLIES;
- self->s.sound = gi.soundindex ("infantry/inflies1.wav");
+ self->s.sound = gi.soundindex("infantry/inflies1.wav");
self->think = M_FliesOff;
self->nextthink = level.time + 60;
}
-void M_FlyCheck (edict_t *self)
+void M_FlyCheck(edict_t *self)
{
if (self->waterlevel)
return;
@@ -132,22 +132,21 @@ void M_FlyCheck (edict_t *self)
self->nextthink = level.time + 5 + 10 * random();
}
-void AttackFinished (edict_t *self, float time)
+void AttackFinished(edict_t *self, float time)
{
self->monsterinfo.attack_finished = level.time + time;
}
-void M_CheckGround (edict_t *ent)
+void M_CheckGround(edict_t *ent)
{
vec3_t point;
trace_t trace;
- if (ent->flags & (FL_SWIM|FL_FLY))
+ if (ent->flags & (FL_SWIM | FL_FLY))
return;
- if (ent->velocity[2] > 100)
- {
+ if (ent->velocity[2] > 100) {
ent->groundentity = NULL;
return;
}
@@ -157,11 +156,10 @@ void M_CheckGround (edict_t *ent)
point[1] = ent->s.origin[1];
point[2] = ent->s.origin[2] - 0.25;
- trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, point, ent, MASK_MONSTERSOLID);
+ trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, point, ent, MASK_MONSTERSOLID);
// check steepness
- if ( trace.plane.normal[2] < 0.7 && !trace.startsolid)
- {
+ if (trace.plane.normal[2] < 0.7 && !trace.startsolid) {
ent->groundentity = NULL;
return;
}
@@ -170,9 +168,8 @@ void M_CheckGround (edict_t *ent)
// ent->groundentity_linkcount = trace.ent->linkcount;
// if (!trace.startsolid && !trace.allsolid)
// VectorCopy (trace.endpos, ent->s.origin);
- if (!trace.startsolid && !trace.allsolid)
- {
- VectorCopy (trace.endpos, ent->s.origin);
+ if (!trace.startsolid && !trace.allsolid) {
+ VectorCopy(trace.endpos, ent->s.origin);
ent->groundentity = trace.ent;
ent->groundentity_linkcount = trace.ent->linkcount;
ent->velocity[2] = 0;
@@ -180,7 +177,7 @@ void M_CheckGround (edict_t *ent)
}
-void M_CatagorizePosition (edict_t *ent)
+void M_CatagorizePosition(edict_t *ent)
{
vec3_t point;
int cont;
@@ -190,11 +187,10 @@ void M_CatagorizePosition (edict_t *ent)
//
point[0] = ent->s.origin[0];
point[1] = ent->s.origin[1];
- point[2] = ent->s.origin[2] + ent->mins[2] + 1;
- cont = gi.pointcontents (point);
+ point[2] = ent->s.origin[2] + ent->mins[2] + 1;
+ cont = gi.pointcontents(point);
- if (!(cont & MASK_WATER))
- {
+ if (!(cont & MASK_WATER)) {
ent->waterlevel = 0;
ent->watertype = 0;
return;
@@ -203,102 +199,84 @@ void M_CatagorizePosition (edict_t *ent)
ent->watertype = cont;
ent->waterlevel = 1;
point[2] += 26;
- cont = gi.pointcontents (point);
+ cont = gi.pointcontents(point);
if (!(cont & MASK_WATER))
return;
ent->waterlevel = 2;
point[2] += 22;
- cont = gi.pointcontents (point);
+ cont = gi.pointcontents(point);
if (cont & MASK_WATER)
ent->waterlevel = 3;
}
-void M_WorldEffects (edict_t *ent)
+void M_WorldEffects(edict_t *ent)
{
int dmg;
- if (ent->health > 0)
- {
- if (!(ent->flags & FL_SWIM))
- {
- if (ent->waterlevel < 3)
- {
+ if (ent->health > 0) {
+ if (!(ent->flags & FL_SWIM)) {
+ if (ent->waterlevel < 3) {
ent->air_finished = level.time + 12;
- }
- else if (ent->air_finished < level.time)
- { // drown!
- if (ent->pain_debounce_time < level.time)
- {
+ } else if (ent->air_finished < level.time) {
+ // drown!
+ if (ent->pain_debounce_time < level.time) {
dmg = 2 + 2 * floor(level.time - ent->air_finished);
if (dmg > 15)
dmg = 15;
- T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
+ T_Damage(ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
ent->pain_debounce_time = level.time + 1;
}
}
- }
- else
- {
- if (ent->waterlevel > 0)
- {
+ } else {
+ if (ent->waterlevel > 0) {
ent->air_finished = level.time + 9;
- }
- else if (ent->air_finished < level.time)
- { // suffocate!
- if (ent->pain_debounce_time < level.time)
- {
+ } else if (ent->air_finished < level.time) {
+ // suffocate!
+ if (ent->pain_debounce_time < level.time) {
dmg = 2 + 2 * floor(level.time - ent->air_finished);
if (dmg > 15)
dmg = 15;
- T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
+ T_Damage(ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
ent->pain_debounce_time = level.time + 1;
}
}
}
}
-
- if (ent->waterlevel == 0)
- {
- if (ent->flags & FL_INWATER)
- {
- gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
+
+ if (ent->waterlevel == 0) {
+ if (ent->flags & FL_INWATER) {
+ gi.sound(ent, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
ent->flags &= ~FL_INWATER;
}
return;
}
- if ((ent->watertype & CONTENTS_LAVA) && !(ent->flags & FL_IMMUNE_LAVA))
- {
- if (ent->damage_debounce_time < level.time)
- {
+ if ((ent->watertype & CONTENTS_LAVA) && !(ent->flags & FL_IMMUNE_LAVA)) {
+ if (ent->damage_debounce_time < level.time) {
ent->damage_debounce_time = level.time + 0.2;
- T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 10*ent->waterlevel, 0, 0, MOD_LAVA);
+ T_Damage(ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 10 * ent->waterlevel, 0, 0, MOD_LAVA);
}
}
- if ((ent->watertype & CONTENTS_SLIME) && !(ent->flags & FL_IMMUNE_SLIME))
- {
- if (ent->damage_debounce_time < level.time)
- {
+ if ((ent->watertype & CONTENTS_SLIME) && !(ent->flags & FL_IMMUNE_SLIME)) {
+ if (ent->damage_debounce_time < level.time) {
ent->damage_debounce_time = level.time + 1;
- T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 4*ent->waterlevel, 0, 0, MOD_SLIME);
+ T_Damage(ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 4 * ent->waterlevel, 0, 0, MOD_SLIME);
}
}
-
- if ( !(ent->flags & FL_INWATER) )
- {
- if (!(ent->svflags & SVF_DEADMONSTER))
- {
+
+ if (!(ent->flags & FL_INWATER)) {
+ if (!(ent->svflags & SVF_DEADMONSTER)) {
if (ent->watertype & CONTENTS_LAVA)
if (random() <= 0.5)
- gi.sound (ent, CHAN_BODY, gi.soundindex("player/lava1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_BODY, gi.soundindex("player/lava1.wav"), 1, ATTN_NORM, 0);
else
- gi.sound (ent, CHAN_BODY, gi.soundindex("player/lava2.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_BODY, gi.soundindex("player/lava2.wav"), 1, ATTN_NORM, 0);
else if (ent->watertype & CONTENTS_SLIME)
- gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
else if (ent->watertype & CONTENTS_WATER)
- gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
}
ent->flags |= FL_INWATER;
@@ -307,35 +285,34 @@ void M_WorldEffects (edict_t *ent)
}
-void M_droptofloor (edict_t *ent)
+void M_droptofloor(edict_t *ent)
{
vec3_t end;
trace_t trace;
ent->s.origin[2] += 1;
- VectorCopy (ent->s.origin, end);
+ VectorCopy(ent->s.origin, end);
end[2] -= 256;
-
- trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
+
+ trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
if (trace.fraction == 1 || trace.allsolid)
return;
- VectorCopy (trace.endpos, ent->s.origin);
+ VectorCopy(trace.endpos, ent->s.origin);
- gi.linkentity (ent);
- M_CheckGround (ent);
- M_CatagorizePosition (ent);
+ gi.linkentity(ent);
+ M_CheckGround(ent);
+ M_CatagorizePosition(ent);
}
-void M_SetEffects (edict_t *ent)
+void M_SetEffects(edict_t *ent)
{
- ent->s.effects &= ~(EF_COLOR_SHELL|EF_POWERSCREEN);
- ent->s.renderfx &= ~(RF_SHELL_RED|RF_SHELL_GREEN|RF_SHELL_BLUE);
+ ent->s.effects &= ~(EF_COLOR_SHELL | EF_POWERSCREEN);
+ ent->s.renderfx &= ~(RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE);
- if (ent->monsterinfo.aiflags & AI_RESURRECTING)
- {
+ if (ent->monsterinfo.aiflags & AI_RESURRECTING) {
ent->s.effects |= EF_COLOR_SHELL;
ent->s.renderfx |= RF_SHELL_RED;
}
@@ -343,14 +320,10 @@ void M_SetEffects (edict_t *ent)
if (ent->health <= 0)
return;
- if (ent->powerarmor_time > level.time)
- {
- if (ent->monsterinfo.power_armor_type == POWER_ARMOR_SCREEN)
- {
+ if (ent->powerarmor_time > level.time) {
+ if (ent->monsterinfo.power_armor_type == POWER_ARMOR_SCREEN) {
ent->s.effects |= EF_POWERSCREEN;
- }
- else if (ent->monsterinfo.power_armor_type == POWER_ARMOR_SHIELD)
- {
+ } else if (ent->monsterinfo.power_armor_type == POWER_ARMOR_SHIELD) {
ent->s.effects |= EF_COLOR_SHELL;
ent->s.renderfx |= RF_SHELL_GREEN;
}
@@ -358,7 +331,7 @@ void M_SetEffects (edict_t *ent)
}
-void M_MoveFrame (edict_t *self)
+void M_MoveFrame(edict_t *self)
{
mmove_t *move;
int index;
@@ -366,18 +339,13 @@ void M_MoveFrame (edict_t *self)
move = self->monsterinfo.currentmove;
self->nextthink = level.time + FRAMETIME;
- if ((self->monsterinfo.nextframe) && (self->monsterinfo.nextframe >= move->firstframe) && (self->monsterinfo.nextframe <= move->lastframe))
- {
+ if ((self->monsterinfo.nextframe) && (self->monsterinfo.nextframe >= move->firstframe) && (self->monsterinfo.nextframe <= move->lastframe)) {
self->s.frame = self->monsterinfo.nextframe;
self->monsterinfo.nextframe = 0;
- }
- else
- {
- if (self->s.frame == move->lastframe)
- {
- if (move->endfunc)
- {
- move->endfunc (self);
+ } else {
+ if (self->s.frame == move->lastframe) {
+ if (move->endfunc) {
+ move->endfunc(self);
// regrab move, endfunc is very likely to change it
move = self->monsterinfo.currentmove;
@@ -388,15 +356,11 @@ void M_MoveFrame (edict_t *self)
}
}
- if (self->s.frame < move->firstframe || self->s.frame > move->lastframe)
- {
+ if (self->s.frame < move->firstframe || self->s.frame > move->lastframe) {
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
self->s.frame = move->firstframe;
- }
- else
- {
- if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME))
- {
+ } else {
+ if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME)) {
self->s.frame++;
if (self->s.frame > move->lastframe)
self->s.frame = move->firstframe;
@@ -405,30 +369,28 @@ void M_MoveFrame (edict_t *self)
}
index = self->s.frame - move->firstframe;
- if (move->frame[index].aifunc)
- {
+ if (move->frame[index].aifunc) {
if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME))
- move->frame[index].aifunc (self, move->frame[index].dist * self->monsterinfo.scale);
+ move->frame[index].aifunc(self, move->frame[index].dist * self->monsterinfo.scale);
else
- move->frame[index].aifunc (self, 0);
+ move->frame[index].aifunc(self, 0);
}
if (move->frame[index].thinkfunc)
- move->frame[index].thinkfunc (self);
+ move->frame[index].thinkfunc(self);
}
-void monster_think (edict_t *self)
+void monster_think(edict_t *self)
{
- M_MoveFrame (self);
- if (self->linkcount != self->monsterinfo.linkcount)
- {
+ M_MoveFrame(self);
+ if (self->linkcount != self->monsterinfo.linkcount) {
self->monsterinfo.linkcount = self->linkcount;
- M_CheckGround (self);
+ M_CheckGround(self);
}
- M_CatagorizePosition (self);
- M_WorldEffects (self);
- M_SetEffects (self);
+ M_CatagorizePosition(self);
+ M_WorldEffects(self);
+ M_SetEffects(self);
}
@@ -439,7 +401,7 @@ monster_use
Using a monster makes it angry at the current activator
================
*/
-void monster_use (edict_t *self, edict_t *other, edict_t *activator)
+void monster_use(edict_t *self, edict_t *other, edict_t *activator)
{
if (self->enemy)
return;
@@ -449,40 +411,37 @@ void monster_use (edict_t *self, edict_t *other, edict_t *activator)
return;
if (!(activator->client) && !(activator->monsterinfo.aiflags & AI_GOOD_GUY))
return;
-
+
// delay reaction so if the monster is teleported, its sound is still heard
self->enemy = activator;
- FoundTarget (self);
+ FoundTarget(self);
}
-void monster_start_go (edict_t *self);
+void monster_start_go(edict_t *self);
-void monster_triggered_spawn (edict_t *self)
+void monster_triggered_spawn(edict_t *self)
{
self->s.origin[2] += 1;
- KillBox (self);
+ KillBox(self);
self->solid = SOLID_BBOX;
self->movetype = MOVETYPE_STEP;
self->svflags &= ~SVF_NOCLIENT;
self->air_finished = level.time + 12;
- gi.linkentity (self);
+ gi.linkentity(self);
- monster_start_go (self);
+ monster_start_go(self);
- if (self->enemy && !(self->spawnflags & 1) && !(self->enemy->flags & FL_NOTARGET))
- {
- FoundTarget (self);
- }
- else
- {
+ if (self->enemy && !(self->spawnflags & 1) && !(self->enemy->flags & FL_NOTARGET)) {
+ FoundTarget(self);
+ } else {
self->enemy = NULL;
}
}
-void monster_triggered_spawn_use (edict_t *self, edict_t *other, edict_t *activator)
+void monster_triggered_spawn_use(edict_t *self, edict_t *other, edict_t *activator)
{
// we have a one frame delay here so we don't telefrag the guy who activated us
self->think = monster_triggered_spawn;
@@ -492,7 +451,7 @@ void monster_triggered_spawn_use (edict_t *self, edict_t *other, edict_t *activa
self->use = monster_use;
}
-void monster_triggered_start (edict_t *self)
+void monster_triggered_start(edict_t *self)
{
self->solid = SOLID_NOT;
self->movetype = MOVETYPE_NONE;
@@ -510,14 +469,13 @@ When a monster dies, it fires all of its targets with the current
enemy as activator.
================
*/
-void monster_death_use (edict_t *self)
+void monster_death_use(edict_t *self)
{
- self->flags &= ~(FL_FLY|FL_SWIM);
+ self->flags &= ~(FL_FLY | FL_SWIM);
self->monsterinfo.aiflags &= AI_GOOD_GUY;
- if (self->item)
- {
- Drop_Item (self, self->item);
+ if (self->item) {
+ Drop_Item(self, self->item);
self->item = NULL;
}
@@ -527,22 +485,20 @@ void monster_death_use (edict_t *self)
if (!self->target)
return;
- G_UseTargets (self, self->enemy);
+ G_UseTargets(self, self->enemy);
}
//============================================================================
-qboolean monster_start (edict_t *self)
+qboolean monster_start(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return qfalse;
}
- if ((self->spawnflags & 4) && !(self->monsterinfo.aiflags & AI_GOOD_GUY))
- {
+ if ((self->spawnflags & 4) && !(self->monsterinfo.aiflags & AI_GOOD_GUY)) {
self->spawnflags &= ~4;
self->spawnflags |= 1;
// gi.dprintf("fixed spawnflags on %s at %s\n", self->classname, vtos(self->s.origin));
@@ -566,11 +522,10 @@ qboolean monster_start (edict_t *self)
if (!self->monsterinfo.checkattack)
self->monsterinfo.checkattack = M_CheckAttack;
- VectorCopy (self->s.origin, self->s.old_origin);
+ VectorCopy(self->s.origin, self->s.old_origin);
- if (st.item)
- {
- self->item = FindItemByClassname (st.item);
+ if (st.item) {
+ self->item = FindItemByClassname(st.item);
if (!self->item)
gi.dprintf("%s at %s has bad item: %s\n", self->classname, vtos(self->s.origin), st.item);
}
@@ -582,7 +537,7 @@ qboolean monster_start (edict_t *self)
return qtrue;
}
-void monster_start_go (edict_t *self)
+void monster_start_go(edict_t *self)
{
vec3_t v;
@@ -590,8 +545,7 @@ void monster_start_go (edict_t *self)
return;
// check for target to combat_point and change to combattarget
- if (self->target)
- {
+ if (self->target) {
qboolean notcombat;
qboolean fixup;
edict_t *target;
@@ -599,15 +553,11 @@ void monster_start_go (edict_t *self)
target = NULL;
notcombat = qfalse;
fixup = qfalse;
- while ((target = G_Find (target, FOFS(targetname), self->target)) != NULL)
- {
- if (strcmp(target->classname, "point_combat") == 0)
- {
+ while ((target = G_Find(target, FOFS(targetname), self->target)) != NULL) {
+ if (strcmp(target->classname, "point_combat") == 0) {
self->combattarget = self->target;
fixup = qtrue;
- }
- else
- {
+ } else {
notcombat = qtrue;
}
}
@@ -618,51 +568,40 @@ void monster_start_go (edict_t *self)
}
// validate combattarget
- if (self->combattarget)
- {
+ if (self->combattarget) {
edict_t *target;
target = NULL;
- while ((target = G_Find (target, FOFS(targetname), self->combattarget)) != NULL)
- {
- if (strcmp(target->classname, "point_combat") != 0)
- {
+ while ((target = G_Find(target, FOFS(targetname), self->combattarget)) != NULL) {
+ if (strcmp(target->classname, "point_combat") != 0) {
gi.dprintf("%s at (%i %i %i) has a bad combattarget %s : %s at (%i %i %i)\n",
- self->classname, (int)self->s.origin[0], (int)self->s.origin[1], (int)self->s.origin[2],
- self->combattarget, target->classname, (int)target->s.origin[0], (int)target->s.origin[1],
- (int)target->s.origin[2]);
+ self->classname, (int)self->s.origin[0], (int)self->s.origin[1], (int)self->s.origin[2],
+ self->combattarget, target->classname, (int)target->s.origin[0], (int)target->s.origin[1],
+ (int)target->s.origin[2]);
}
}
}
- if (self->target)
- {
+ if (self->target) {
self->goalentity = self->movetarget = G_PickTarget(self->target);
- if (!self->movetarget)
- {
- gi.dprintf ("%s can't find target %s at %s\n", self->classname, self->target, vtos(self->s.origin));
+ if (!self->movetarget) {
+ gi.dprintf("%s can't find target %s at %s\n", self->classname, self->target, vtos(self->s.origin));
self->target = NULL;
self->monsterinfo.pausetime = 100000000;
- self->monsterinfo.stand (self);
- }
- else if (strcmp (self->movetarget->classname, "path_corner") == 0)
- {
- VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
+ self->monsterinfo.stand(self);
+ } else if (strcmp(self->movetarget->classname, "path_corner") == 0) {
+ VectorSubtract(self->goalentity->s.origin, self->s.origin, v);
self->ideal_yaw = self->s.angles[YAW] = vectoyaw(v);
- self->monsterinfo.walk (self);
+ self->monsterinfo.walk(self);
self->target = NULL;
- }
- else
- {
+ } else {
self->goalentity = self->movetarget = NULL;
self->monsterinfo.pausetime = 100000000;
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
}
- }
- else
- {
+ } else {
self->monsterinfo.pausetime = 100000000;
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
}
self->think = monster_think;
@@ -670,73 +609,72 @@ void monster_start_go (edict_t *self)
}
-void walkmonster_start_go (edict_t *self)
+void walkmonster_start_go(edict_t *self)
{
- if (!(self->spawnflags & 2) && level.time < 1)
- {
- M_droptofloor (self);
+ if (!(self->spawnflags & 2) && level.time < 1) {
+ M_droptofloor(self);
if (self->groundentity)
- if (!M_walkmove (self, 0, 0))
- gi.dprintf ("%s in solid at %s\n", self->classname, vtos(self->s.origin));
+ if (!M_walkmove(self, 0, 0))
+ gi.dprintf("%s in solid at %s\n", self->classname, vtos(self->s.origin));
}
-
+
if (!self->yaw_speed)
self->yaw_speed = 20;
self->viewheight = 25;
- monster_start_go (self);
+ monster_start_go(self);
if (self->spawnflags & 2)
- monster_triggered_start (self);
+ monster_triggered_start(self);
}
-void walkmonster_start (edict_t *self)
+void walkmonster_start(edict_t *self)
{
self->think = walkmonster_start_go;
- monster_start (self);
+ monster_start(self);
}
-void flymonster_start_go (edict_t *self)
+void flymonster_start_go(edict_t *self)
{
- if (!M_walkmove (self, 0, 0))
- gi.dprintf ("%s in solid at %s\n", self->classname, vtos(self->s.origin));
+ if (!M_walkmove(self, 0, 0))
+ gi.dprintf("%s in solid at %s\n", self->classname, vtos(self->s.origin));
if (!self->yaw_speed)
self->yaw_speed = 10;
self->viewheight = 25;
- monster_start_go (self);
+ monster_start_go(self);
if (self->spawnflags & 2)
- monster_triggered_start (self);
+ monster_triggered_start(self);
}
-void flymonster_start (edict_t *self)
+void flymonster_start(edict_t *self)
{
self->flags |= FL_FLY;
self->think = flymonster_start_go;
- monster_start (self);
+ monster_start(self);
}
-void swimmonster_start_go (edict_t *self)
+void swimmonster_start_go(edict_t *self)
{
if (!self->yaw_speed)
self->yaw_speed = 10;
self->viewheight = 10;
- monster_start_go (self);
+ monster_start_go(self);
if (self->spawnflags & 2)
- monster_triggered_start (self);
+ monster_triggered_start(self);
}
-void swimmonster_start (edict_t *self)
+void swimmonster_start(edict_t *self)
{
self->flags |= FL_SWIM;
self->think = swimmonster_start_go;
- monster_start (self);
+ monster_start(self);
}
diff --git a/src/baseq2/g_phys.c b/src/baseq2/g_phys.c
index edc2837..61f8a2a 100644
--- a/src/baseq2/g_phys.c
+++ b/src/baseq2/g_phys.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
pushmove objects do not obey gravity, and do not interact with each other or trigger fields, but block normal movement and push normal objects when they move.
-onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
+onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
doors, plats, etc are SOLID_BSP, and MOVETYPE_PUSH
bonus items are SOLID_TRIGGER touch, and MOVETYPE_TOSS
@@ -46,7 +46,7 @@ SV_TestEntityPosition
============
*/
-edict_t *SV_TestEntityPosition (edict_t *ent)
+edict_t *SV_TestEntityPosition(edict_t *ent)
{
trace_t trace;
int mask;
@@ -55,11 +55,11 @@ edict_t *SV_TestEntityPosition (edict_t *ent)
mask = ent->clipmask;
else
mask = MASK_SOLID;
- trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, ent->s.origin, ent, mask);
-
+ trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, ent->s.origin, ent, mask);
+
if (trace.startsolid)
return g_edicts;
-
+
return NULL;
}
@@ -69,15 +69,14 @@ edict_t *SV_TestEntityPosition (edict_t *ent)
SV_CheckVelocity
================
*/
-void SV_CheckVelocity (edict_t *ent)
+void SV_CheckVelocity(edict_t *ent)
{
int i;
//
// bound velocity
//
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
if (ent->velocity[i] > sv_maxvelocity->value)
ent->velocity[i] = sv_maxvelocity->value;
else if (ent->velocity[i] < -sv_maxvelocity->value)
@@ -92,20 +91,20 @@ SV_RunThink
Runs thinking code for this frame if necessary
=============
*/
-qboolean SV_RunThink (edict_t *ent)
+qboolean SV_RunThink(edict_t *ent)
{
float thinktime;
thinktime = ent->nextthink;
if (thinktime <= 0)
return qtrue;
- if (thinktime > level.time+0.001)
+ if (thinktime > level.time + 0.001)
return qtrue;
-
+
ent->nextthink = 0;
if (!ent->think)
- gi.error ("NULL ent->think");
- ent->think (ent);
+ gi.error("NULL ent->think");
+ ent->think(ent);
return qfalse;
}
@@ -117,7 +116,7 @@ SV_Impact
Two entities have touched, so run their touch functions
==================
*/
-void SV_Impact (edict_t *e1, trace_t *trace)
+void SV_Impact(edict_t *e1, trace_t *trace)
{
edict_t *e2;
// cplane_t backplane;
@@ -125,10 +124,10 @@ void SV_Impact (edict_t *e1, trace_t *trace)
e2 = trace->ent;
if (e1->touch && e1->solid != SOLID_NOT)
- e1->touch (e1, e2, &trace->plane, trace->surface);
-
+ e1->touch(e1, e2, &trace->plane, trace->surface);
+
if (e2->touch && e2->solid != SOLID_NOT)
- e2->touch (e2, e1, NULL, NULL);
+ e2->touch(e2, e1, NULL, NULL);
}
@@ -142,23 +141,22 @@ returns the blocked flags (1 = floor, 2 = step / wall)
*/
#define STOP_EPSILON 0.1
-int ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
+int ClipVelocity(vec3_t in, vec3_t normal, vec3_t out, float overbounce)
{
float backoff;
float change;
int i, blocked;
-
+
blocked = 0;
if (normal[2] > 0)
blocked |= 1; // floor
if (!normal[2])
blocked |= 2; // step
-
- backoff = DotProduct (in, normal) * overbounce;
- for (i=0 ; i<3 ; i++)
- {
- change = normal[i]*backoff;
+ backoff = DotProduct(in, normal) * overbounce;
+
+ for (i = 0 ; i < 3 ; i++) {
+ change = normal[i] * backoff;
out[i] = in[i] - change;
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
out[i] = 0;
@@ -180,7 +178,7 @@ Returns the clipflags if the velocity was modified (hit something solid)
============
*/
#define MAX_CLIP_PLANES 5
-int SV_FlyMove (edict_t *ent, float time, int mask)
+int SV_FlyMove(edict_t *ent, float time, int mask)
{
edict_t *hit;
int bumpcount, numbumps;
@@ -194,117 +192,108 @@ int SV_FlyMove (edict_t *ent, float time, int mask)
vec3_t end;
float time_left;
int blocked;
-
+
numbumps = 4;
-
+
blocked = 0;
- VectorCopy (ent->velocity, original_velocity);
- VectorCopy (ent->velocity, primal_velocity);
+ VectorCopy(ent->velocity, original_velocity);
+ VectorCopy(ent->velocity, primal_velocity);
numplanes = 0;
-
+
time_left = time;
ent->groundentity = NULL;
- for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++)
- {
- for (i=0 ; i<3 ; i++)
+ for (bumpcount = 0 ; bumpcount < numbumps ; bumpcount++) {
+ for (i = 0 ; i < 3 ; i++)
end[i] = ent->s.origin[i] + time_left * ent->velocity[i];
- trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, end, ent, mask);
+ trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, end, ent, mask);
- if (trace.allsolid)
- { // entity is trapped in another solid
- VectorCopy (vec3_origin, ent->velocity);
+ if (trace.allsolid) {
+ // entity is trapped in another solid
+ VectorCopy(vec3_origin, ent->velocity);
return 3;
}
- if (trace.fraction > 0)
- { // actually covered some distance
- VectorCopy (trace.endpos, ent->s.origin);
- VectorCopy (ent->velocity, original_velocity);
+ if (trace.fraction > 0) {
+ // actually covered some distance
+ VectorCopy(trace.endpos, ent->s.origin);
+ VectorCopy(ent->velocity, original_velocity);
numplanes = 0;
}
if (trace.fraction == 1)
- break; // moved the entire distance
+ break; // moved the entire distance
hit = trace.ent;
- if (trace.plane.normal[2] > 0.7)
- {
+ if (trace.plane.normal[2] > 0.7) {
blocked |= 1; // floor
- if ( hit->solid == SOLID_BSP)
- {
+ if (hit->solid == SOLID_BSP) {
ent->groundentity = hit;
ent->groundentity_linkcount = hit->linkcount;
}
}
- if (!trace.plane.normal[2])
- {
+ if (!trace.plane.normal[2]) {
blocked |= 2; // step
}
//
// run the impact function
//
- SV_Impact (ent, &trace);
+ SV_Impact(ent, &trace);
if (!ent->inuse)
break; // removed by the impact function
-
+
time_left -= time_left * trace.fraction;
-
- // cliped to another plane
- if (numplanes >= MAX_CLIP_PLANES)
- { // this shouldn't really happen
- VectorCopy (vec3_origin, ent->velocity);
+
+ // cliped to another plane
+ if (numplanes >= MAX_CLIP_PLANES) {
+ // this shouldn't really happen
+ VectorCopy(vec3_origin, ent->velocity);
return 3;
}
- VectorCopy (trace.plane.normal, planes[numplanes]);
+ VectorCopy(trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
- for (i=0 ; i<numplanes ; i++)
- {
- ClipVelocity (original_velocity, planes[i], new_velocity, 1);
-
- for (j=0 ; j<numplanes ; j++)
- if ((j != i) && !VectorCompare (planes[i], planes[j]))
- {
- if (DotProduct (new_velocity, planes[j]) < 0)
+ for (i = 0 ; i < numplanes ; i++) {
+ ClipVelocity(original_velocity, planes[i], new_velocity, 1);
+
+ for (j = 0 ; j < numplanes ; j++)
+ if ((j != i) && !VectorCompare(planes[i], planes[j])) {
+ if (DotProduct(new_velocity, planes[j]) < 0)
break; // not ok
}
if (j == numplanes)
break;
}
-
- if (i != numplanes)
- { // go along this plane
- VectorCopy (new_velocity, ent->velocity);
- }
- else
- { // go along the crease
- if (numplanes != 2)
- {
+
+ if (i != numplanes) {
+ // go along this plane
+ VectorCopy(new_velocity, ent->velocity);
+ } else {
+ // go along the crease
+ if (numplanes != 2) {
// gi.dprintf ("clip velocity, numplanes == %i\n",numplanes);
- VectorCopy (vec3_origin, ent->velocity);
+ VectorCopy(vec3_origin, ent->velocity);
return 7;
}
- CrossProduct (planes[0], planes[1], dir);
- d = DotProduct (dir, ent->velocity);
- VectorScale (dir, d, ent->velocity);
+ CrossProduct(planes[0], planes[1], dir);
+ d = DotProduct(dir, ent->velocity);
+ VectorScale(dir, d, ent->velocity);
}
//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
- if (DotProduct (ent->velocity, primal_velocity) <= 0)
- {
- VectorCopy (vec3_origin, ent->velocity);
+ if (DotProduct(ent->velocity, primal_velocity) <= 0) {
+ VectorCopy(vec3_origin, ent->velocity);
return blocked;
}
}
@@ -319,7 +308,7 @@ SV_AddGravity
============
*/
-void SV_AddGravity (edict_t *ent)
+void SV_AddGravity(edict_t *ent)
{
ent->velocity[2] -= ent->gravity * sv_gravity->value * FRAMETIME;
}
@@ -339,15 +328,15 @@ SV_PushEntity
Does not change the entities velocity at all
============
*/
-trace_t SV_PushEntity (edict_t *ent, vec3_t push)
+trace_t SV_PushEntity(edict_t *ent, vec3_t push)
{
trace_t trace;
vec3_t start;
vec3_t end;
int mask;
- VectorCopy (ent->s.origin, start);
- VectorAdd (start, push, end);
+ VectorCopy(ent->s.origin, start);
+ VectorAdd(start, push, end);
retry:
if (ent->clipmask)
@@ -355,34 +344,31 @@ retry:
else
mask = MASK_SOLID;
- trace = gi.trace (start, ent->mins, ent->maxs, end, ent, mask);
-
- VectorCopy (trace.endpos, ent->s.origin);
- gi.linkentity (ent);
+ trace = gi.trace(start, ent->mins, ent->maxs, end, ent, mask);
+
+ VectorCopy(trace.endpos, ent->s.origin);
+ gi.linkentity(ent);
- if (trace.fraction != 1.0)
- {
- SV_Impact (ent, &trace);
+ if (trace.fraction != 1.0) {
+ SV_Impact(ent, &trace);
// if the pushed entity went away and the pusher is still there
- if (!trace.ent->inuse && ent->inuse)
- {
+ if (!trace.ent->inuse && ent->inuse) {
// move the pusher back and try again
- VectorCopy (start, ent->s.origin);
- gi.linkentity (ent);
+ VectorCopy(start, ent->s.origin);
+ gi.linkentity(ent);
goto retry;
}
}
if (ent->inuse)
- G_TouchTriggers (ent);
+ G_TouchTriggers(ent);
return trace;
-}
+}
-typedef struct
-{
+typedef struct {
edict_t *ent;
vec3_t origin;
vec3_t angles;
@@ -402,7 +388,7 @@ Objects need to be moved back on a failed push,
otherwise riders would continue to slide.
============
*/
-qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove)
+qboolean SV_Push(edict_t *pusher, vec3_t move, vec3_t amove)
{
int i, e;
edict_t *check, *block;
@@ -412,10 +398,9 @@ qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove)
// clamp the move to 1/8 units, so the position will
// be accurate for client side prediction
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
float temp;
- temp = move[i]*8.0;
+ temp = move[i] * 8.0;
if (temp > 0.0)
temp += 0.5;
else
@@ -424,20 +409,19 @@ qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove)
}
// find the bounding box
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
mins[i] = pusher->absmin[i] + move[i];
maxs[i] = pusher->absmax[i] + move[i];
}
// we need this for pushing things later
- VectorSubtract (vec3_origin, amove, org);
- AngleVectors (org, forward, right, up);
+ VectorSubtract(vec3_origin, amove, org);
+ AngleVectors(org, forward, right, up);
// save the pusher's original position
pushed_p->ent = pusher;
- VectorCopy (pusher->s.origin, pushed_p->origin);
- VectorCopy (pusher->s.angles, pushed_p->angles);
+ VectorCopy(pusher->s.origin, pushed_p->origin);
+ VectorCopy(pusher->s.angles, pushed_p->angles);
#if USE_SMOOTH_DELTA_ANGLES
if (pusher->client)
pushed_p->deltayaw = pusher->client->ps.pmove.delta_angles[YAW];
@@ -445,80 +429,77 @@ qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove)
pushed_p++;
// move the pusher to it's final position
- VectorAdd (pusher->s.origin, move, pusher->s.origin);
- VectorAdd (pusher->s.angles, amove, pusher->s.angles);
- gi.linkentity (pusher);
+ VectorAdd(pusher->s.origin, move, pusher->s.origin);
+ VectorAdd(pusher->s.angles, amove, pusher->s.angles);
+ gi.linkentity(pusher);
// see if any solid entities are inside the final position
- check = g_edicts+1;
- for (e = 1; e < globals.num_edicts; e++, check++)
- {
+ check = g_edicts + 1;
+ for (e = 1; e < globals.num_edicts; e++, check++) {
if (!check->inuse)
continue;
if (check->movetype == MOVETYPE_PUSH
- || check->movetype == MOVETYPE_STOP
- || check->movetype == MOVETYPE_NONE
- || check->movetype == MOVETYPE_NOCLIP)
+ || check->movetype == MOVETYPE_STOP
+ || check->movetype == MOVETYPE_NONE
+ || check->movetype == MOVETYPE_NOCLIP)
continue;
if (!check->area.prev)
continue; // not linked in anywhere
- // if the entity is standing on the pusher, it will definitely be moved
- if (check->groundentity != pusher)
- {
+ // if the entity is standing on the pusher, it will definitely be moved
+ if (check->groundentity != pusher) {
// see if the ent needs to be tested
- if ( check->absmin[0] >= maxs[0]
- || check->absmin[1] >= maxs[1]
- || check->absmin[2] >= maxs[2]
- || check->absmax[0] <= mins[0]
- || check->absmax[1] <= mins[1]
- || check->absmax[2] <= mins[2] )
+ if (check->absmin[0] >= maxs[0]
+ || check->absmin[1] >= maxs[1]
+ || check->absmin[2] >= maxs[2]
+ || check->absmax[0] <= mins[0]
+ || check->absmax[1] <= mins[1]
+ || check->absmax[2] <= mins[2])
continue;
// see if the ent's bbox is inside the pusher's final position
- if (!SV_TestEntityPosition (check))
+ if (!SV_TestEntityPosition(check))
continue;
}
- if ((pusher->movetype == MOVETYPE_PUSH) || (check->groundentity == pusher))
- {
+ if ((pusher->movetype == MOVETYPE_PUSH) || (check->groundentity == pusher)) {
// move this entity
pushed_p->ent = check;
- VectorCopy (check->s.origin, pushed_p->origin);
- VectorCopy (check->s.angles, pushed_p->angles);
+ VectorCopy(check->s.origin, pushed_p->origin);
+ VectorCopy(check->s.angles, pushed_p->angles);
#if USE_SMOOTH_DELTA_ANGLES
if (check->client)
pushed_p->deltayaw = check->client->ps.pmove.delta_angles[YAW];
#endif
pushed_p++;
- // try moving the contacted entity
- VectorAdd (check->s.origin, move, check->s.origin);
+ // try moving the contacted entity
+ VectorAdd(check->s.origin, move, check->s.origin);
#if USE_SMOOTH_DELTA_ANGLES
- if (check->client)
- { // FIXME: doesn't rotate monsters?
+ if (check->client) {
+ // FIXME: doesn't rotate monsters?
// FIXME: skuller: needs client side interpolation
- check->client->ps.pmove.delta_angles[YAW] += ANGLE2SHORT( amove[YAW] );
+ check->client->ps.pmove.delta_angles[YAW] += ANGLE2SHORT(amove[YAW]);
}
#endif
// figure movement due to the pusher's amove
- VectorSubtract (check->s.origin, pusher->s.origin, org);
- org2[0] = DotProduct (org, forward);
- org2[1] = -DotProduct (org, right);
- org2[2] = DotProduct (org, up);
- VectorSubtract (org2, org, move2);
- VectorAdd (check->s.origin, move2, check->s.origin);
+ VectorSubtract(check->s.origin, pusher->s.origin, org);
+ org2[0] = DotProduct(org, forward);
+ org2[1] = -DotProduct(org, right);
+ org2[2] = DotProduct(org, up);
+ VectorSubtract(org2, org, move2);
+ VectorAdd(check->s.origin, move2, check->s.origin);
// may have pushed them off an edge
if (check->groundentity != pusher)
check->groundentity = NULL;
- block = SV_TestEntityPosition (check);
- if (!block)
- { // pushed ok
- gi.linkentity (check);
+ block = SV_TestEntityPosition(check);
+ if (!block) {
+ // pushed ok
+ gi.linkentity(check);
// impact?
continue;
}
@@ -526,40 +507,37 @@ qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove)
// if it is ok to leave in the old position, do it
// this is only relevent for riding entities, not pushed
// FIXME: this doesn't acount for rotation
- VectorSubtract (check->s.origin, move, check->s.origin);
- block = SV_TestEntityPosition (check);
- if (!block)
- {
+ VectorSubtract(check->s.origin, move, check->s.origin);
+ block = SV_TestEntityPosition(check);
+ if (!block) {
pushed_p--;
continue;
}
}
-
+
// save off the obstacle so we can call the block function
obstacle = check;
// move back any entities we already moved
// go backwards, so if the same entity was pushed
// twice, it goes back to the original position
- for (p=pushed_p-1 ; p>=pushed ; p--)
- {
- VectorCopy (p->origin, p->ent->s.origin);
- VectorCopy (p->angles, p->ent->s.angles);
+ for (p = pushed_p - 1 ; p >= pushed ; p--) {
+ VectorCopy(p->origin, p->ent->s.origin);
+ VectorCopy(p->angles, p->ent->s.angles);
#if USE_SMOOTH_DELTA_ANGLES
- if (p->ent->client)
- {
+ if (p->ent->client) {
p->ent->client->ps.pmove.delta_angles[YAW] = p->deltayaw;
}
#endif
- gi.linkentity (p->ent);
+ gi.linkentity(p->ent);
}
return qfalse;
}
//FIXME: is there a better way to handle this?
// see if anything we moved has touched a trigger
- for (p=pushed_p-1 ; p>=pushed ; p--)
- G_TouchTriggers (p->ent);
+ for (p = pushed_p - 1 ; p >= pushed ; p--)
+ G_TouchTriggers(p->ent);
return qtrue;
}
@@ -572,13 +550,13 @@ Bmodel objects don't interact with each other, but
push all box objects
================
*/
-void SV_Physics_Pusher (edict_t *ent)
+void SV_Physics_Pusher(edict_t *ent)
{
vec3_t move, amove;
edict_t *part, *mv;
// if not a team captain, so movement will be handled elsewhere
- if ( ent->flags & FL_TEAMSLAVE)
+ if (ent->flags & FL_TEAMSLAVE)
return;
// make sure all team slaves can move before commiting
@@ -586,27 +564,24 @@ void SV_Physics_Pusher (edict_t *ent)
// if the move is blocked, all moved objects will be backed out
//retry:
pushed_p = pushed;
- for (part = ent ; part ; part=part->teamchain)
- {
+ for (part = ent ; part ; part = part->teamchain) {
if (part->velocity[0] || part->velocity[1] || part->velocity[2] ||
part->avelocity[0] || part->avelocity[1] || part->avelocity[2]
- )
- { // object is moving
- VectorScale (part->velocity, FRAMETIME, move);
- VectorScale (part->avelocity, FRAMETIME, amove);
+ ) {
+ // object is moving
+ VectorScale(part->velocity, FRAMETIME, move);
+ VectorScale(part->avelocity, FRAMETIME, amove);
- if (!SV_Push (part, move, amove))
+ if (!SV_Push(part, move, amove))
break; // move was blocked
}
}
if (pushed_p > &pushed[MAX_EDICTS])
- gi.error ("pushed_p > &pushed[MAX_EDICTS], memory corrupted");
+ gi.error("pushed_p > &pushed[MAX_EDICTS], memory corrupted");
- if (part)
- {
+ if (part) {
// the move failed, bump all nextthink times and back out moves
- for (mv = ent ; mv ; mv=mv->teamchain)
- {
+ for (mv = ent ; mv ; mv = mv->teamchain) {
if (mv->nextthink > 0)
mv->nextthink += FRAMETIME;
}
@@ -614,19 +589,16 @@ void SV_Physics_Pusher (edict_t *ent)
// if the pusher has a "blocked" function, call it
// otherwise, just stay in place until the obstacle is gone
if (part->blocked)
- part->blocked (part, obstacle);
+ part->blocked(part, obstacle);
#if 0
// if the pushed entity went away and the pusher is still there
if (!obstacle->inuse && part->inuse)
goto retry;
#endif
- }
- else
- {
+ } else {
// the move succeeded, so call all think functions
- for (part = ent ; part ; part=part->teamchain)
- {
- SV_RunThink (part);
+ for (part = ent ; part ; part = part->teamchain) {
+ SV_RunThink(part);
}
}
}
@@ -640,10 +612,10 @@ SV_Physics_None
Non moving objects can only think
=============
*/
-void SV_Physics_None (edict_t *ent)
+void SV_Physics_None(edict_t *ent)
{
// regular thinking
- SV_RunThink (ent);
+ SV_RunThink(ent);
}
/*
@@ -653,18 +625,18 @@ SV_Physics_Noclip
A moving object that doesn't obey physics
=============
*/
-void SV_Physics_Noclip (edict_t *ent)
+void SV_Physics_Noclip(edict_t *ent)
{
// regular thinking
- if (!SV_RunThink (ent))
+ if (!SV_RunThink(ent))
return;
if (!ent->inuse)
return;
-
- VectorMA (ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
- VectorMA (ent->s.origin, FRAMETIME, ent->velocity, ent->s.origin);
- gi.linkentity (ent);
+ VectorMA(ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
+ VectorMA(ent->s.origin, FRAMETIME, ent->velocity, ent->s.origin);
+
+ gi.linkentity(ent);
}
/*
@@ -682,7 +654,7 @@ SV_Physics_Toss
Toss, bounce, and fly movement. When onground, do nothing.
=============
*/
-void SV_Physics_Toss (edict_t *ent)
+void SV_Physics_Toss(edict_t *ent)
{
trace_t trace;
vec3_t move;
@@ -693,12 +665,12 @@ void SV_Physics_Toss (edict_t *ent)
vec3_t old_origin;
// regular thinking
- SV_RunThink (ent);
+ SV_RunThink(ent);
if (!ent->inuse)
return;
// if not a team captain, so movement will be handled elsewhere
- if ( ent->flags & FL_TEAMSLAVE)
+ if (ent->flags & FL_TEAMSLAVE)
return;
if (ent->velocity[2] > 0)
@@ -710,55 +682,52 @@ void SV_Physics_Toss (edict_t *ent)
ent->groundentity = NULL;
// if onground, return without moving
- if ( ent->groundentity )
+ if (ent->groundentity)
return;
- VectorCopy (ent->s.origin, old_origin);
+ VectorCopy(ent->s.origin, old_origin);
- SV_CheckVelocity (ent);
+ SV_CheckVelocity(ent);
// add gravity
if (ent->movetype != MOVETYPE_FLY
- && ent->movetype != MOVETYPE_FLYMISSILE)
- SV_AddGravity (ent);
+ && ent->movetype != MOVETYPE_FLYMISSILE)
+ SV_AddGravity(ent);
// move angles
- VectorMA (ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
+ VectorMA(ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
// move origin
- VectorScale (ent->velocity, FRAMETIME, move);
- trace = SV_PushEntity (ent, move);
+ VectorScale(ent->velocity, FRAMETIME, move);
+ trace = SV_PushEntity(ent, move);
if (!ent->inuse)
return;
- if (trace.fraction < 1)
- {
+ if (trace.fraction < 1) {
if (ent->movetype == MOVETYPE_BOUNCE)
backoff = 1.5;
else
backoff = 1;
- ClipVelocity (ent->velocity, trace.plane.normal, ent->velocity, backoff);
+ ClipVelocity(ent->velocity, trace.plane.normal, ent->velocity, backoff);
- // stop if on ground
- if (trace.plane.normal[2] > 0.7)
- {
- if (ent->velocity[2] < 60 || ent->movetype != MOVETYPE_BOUNCE )
- {
+ // stop if on ground
+ if (trace.plane.normal[2] > 0.7) {
+ if (ent->velocity[2] < 60 || ent->movetype != MOVETYPE_BOUNCE) {
ent->groundentity = trace.ent;
ent->groundentity_linkcount = trace.ent->linkcount;
- VectorCopy (vec3_origin, ent->velocity);
- VectorCopy (vec3_origin, ent->avelocity);
+ VectorCopy(vec3_origin, ent->velocity);
+ VectorCopy(vec3_origin, ent->avelocity);
}
}
// if (ent->touch)
// ent->touch (ent, trace.ent, &trace.plane, trace.surface);
}
-
+
// check for water transition
wasinwater = (ent->watertype & MASK_WATER);
- ent->watertype = gi.pointcontents (ent->s.origin);
+ ent->watertype = gi.pointcontents(ent->s.origin);
isinwater = ent->watertype & MASK_WATER;
if (isinwater)
@@ -767,15 +736,14 @@ void SV_Physics_Toss (edict_t *ent)
ent->waterlevel = 0;
if (!wasinwater && isinwater)
- gi.positioned_sound (old_origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
+ gi.positioned_sound(old_origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
else if (wasinwater && !isinwater)
- gi.positioned_sound (ent->s.origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
+ gi.positioned_sound(ent->s.origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
// move teamslaves
- for (slave = ent->teamchain; slave; slave = slave->teamchain)
- {
- VectorCopy (ent->s.origin, slave->s.origin);
- gi.linkentity (slave);
+ for (slave = ent->teamchain; slave; slave = slave->teamchain) {
+ VectorCopy(ent->s.origin, slave->s.origin);
+ gi.linkentity(slave);
}
}
@@ -805,23 +773,19 @@ FIXME: is this qtrue?
#define sv_friction 6
#define sv_waterfriction 1
-void SV_AddRotationalFriction (edict_t *ent)
+void SV_AddRotationalFriction(edict_t *ent)
{
int n;
float adjustment;
- VectorMA (ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
+ VectorMA(ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
adjustment = FRAMETIME * sv_stopspeed * sv_friction;
- for (n = 0; n < 3; n++)
- {
- if (ent->avelocity[n] > 0)
- {
+ for (n = 0; n < 3; n++) {
+ if (ent->avelocity[n] > 0) {
ent->avelocity[n] -= adjustment;
if (ent->avelocity[n] < 0)
ent->avelocity[n] = 0;
- }
- else
- {
+ } else {
ent->avelocity[n] += adjustment;
if (ent->avelocity[n] > 0)
ent->avelocity[n] = 0;
@@ -829,7 +793,7 @@ void SV_AddRotationalFriction (edict_t *ent)
}
}
-void SV_Physics_Step (edict_t *ent)
+void SV_Physics_Step(edict_t *ent)
{
qboolean wasonground;
qboolean hitsound = qfalse;
@@ -841,39 +805,37 @@ void SV_Physics_Step (edict_t *ent)
// airborn monsters should always check for ground
if (!ent->groundentity)
- M_CheckGround (ent);
+ M_CheckGround(ent);
groundentity = ent->groundentity;
- SV_CheckVelocity (ent);
+ SV_CheckVelocity(ent);
if (groundentity)
wasonground = qtrue;
else
wasonground = qfalse;
-
+
if (ent->avelocity[0] || ent->avelocity[1] || ent->avelocity[2])
- SV_AddRotationalFriction (ent);
+ SV_AddRotationalFriction(ent);
// add gravity except:
// flying monsters
// swimming monsters who are in the water
if (! wasonground)
if (!(ent->flags & FL_FLY))
- if (!((ent->flags & FL_SWIM) && (ent->waterlevel > 2)))
- {
- if (ent->velocity[2] < sv_gravity->value*-0.1)
+ if (!((ent->flags & FL_SWIM) && (ent->waterlevel > 2))) {
+ if (ent->velocity[2] < sv_gravity->value * -0.1)
hitsound = qtrue;
if (ent->waterlevel == 0)
- SV_AddGravity (ent);
+ SV_AddGravity(ent);
}
// friction for flying monsters that have been given vertical velocity
- if ((ent->flags & FL_FLY) && (ent->velocity[2] != 0))
- {
+ if ((ent->flags & FL_FLY) && (ent->velocity[2] != 0)) {
speed = fabs(ent->velocity[2]);
control = speed < sv_stopspeed ? sv_stopspeed : speed;
- friction = sv_friction/3;
+ friction = sv_friction / 3;
newspeed = speed - (FRAMETIME * control * friction);
if (newspeed < 0)
newspeed = 0;
@@ -882,8 +844,7 @@ void SV_Physics_Step (edict_t *ent)
}
// friction for flying monsters that have been given vertical velocity
- if ((ent->flags & FL_SWIM) && (ent->velocity[2] != 0))
- {
+ if ((ent->flags & FL_SWIM) && (ent->velocity[2] != 0)) {
speed = fabs(ent->velocity[2]);
control = speed < sv_stopspeed ? sv_stopspeed : speed;
newspeed = speed - (FRAMETIME * control * sv_waterfriction * ent->waterlevel);
@@ -893,21 +854,18 @@ void SV_Physics_Step (edict_t *ent)
ent->velocity[2] *= newspeed;
}
- if (ent->velocity[2] || ent->velocity[1] || ent->velocity[0])
- {
+ if (ent->velocity[2] || ent->velocity[1] || ent->velocity[0]) {
// apply friction
// let dead monsters who aren't completely onground slide
- if ((wasonground) || (ent->flags & (FL_SWIM|FL_FLY)))
- if (!(ent->health <= 0.0 && !M_CheckBottom(ent)))
- {
+ if ((wasonground) || (ent->flags & (FL_SWIM | FL_FLY)))
+ if (!(ent->health <= 0.0 && !M_CheckBottom(ent))) {
vel = ent->velocity;
- speed = sqrt(vel[0]*vel[0] +vel[1]*vel[1]);
- if (speed)
- {
+ speed = sqrt(vel[0] * vel[0] + vel[1] * vel[1]);
+ if (speed) {
friction = sv_friction;
control = speed < sv_stopspeed ? sv_stopspeed : speed;
- newspeed = speed - FRAMETIME*control*friction;
+ newspeed = speed - FRAMETIME * control * friction;
if (newspeed < 0)
newspeed = 0;
@@ -922,21 +880,21 @@ void SV_Physics_Step (edict_t *ent)
mask = MASK_MONSTERSOLID;
else
mask = MASK_SOLID;
- SV_FlyMove (ent, FRAMETIME, mask);
+ SV_FlyMove(ent, FRAMETIME, mask);
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
if (!ent->inuse)
return;
if (ent->groundentity)
if (!wasonground)
if (hitsound)
- gi.sound (ent, 0, gi.soundindex("world/land.wav"), 1, 1, 0);
+ gi.sound(ent, 0, gi.soundindex("world/land.wav"), 1, 1, 0);
}
// regular thinking
- SV_RunThink (ent);
+ SV_RunThink(ent);
}
//============================================================================
@@ -946,33 +904,32 @@ G_RunEntity
================
*/
-void G_RunEntity (edict_t *ent)
+void G_RunEntity(edict_t *ent)
{
if (ent->prethink)
- ent->prethink (ent);
+ ent->prethink(ent);
- switch ( (int)ent->movetype)
- {
+ switch ((int)ent->movetype) {
case MOVETYPE_PUSH:
case MOVETYPE_STOP:
- SV_Physics_Pusher (ent);
+ SV_Physics_Pusher(ent);
break;
case MOVETYPE_NONE:
- SV_Physics_None (ent);
+ SV_Physics_None(ent);
break;
case MOVETYPE_NOCLIP:
- SV_Physics_Noclip (ent);
+ SV_Physics_Noclip(ent);
break;
case MOVETYPE_STEP:
- SV_Physics_Step (ent);
+ SV_Physics_Step(ent);
break;
case MOVETYPE_TOSS:
case MOVETYPE_BOUNCE:
case MOVETYPE_FLY:
case MOVETYPE_FLYMISSILE:
- SV_Physics_Toss (ent);
+ SV_Physics_Toss(ent);
break;
default:
- gi.error ("SV_Physics: bad movetype %i", (int)ent->movetype);
+ gi.error("SV_Physics: bad movetype %i", (int)ent->movetype);
}
}
diff --git a/src/baseq2/g_ptrs.c b/src/baseq2/g_ptrs.c
index c4c08d1..13c6fc2 100644
--- a/src/baseq2/g_ptrs.c
+++ b/src/baseq2/g_ptrs.c
@@ -267,353 +267,353 @@ extern int tank_move_run;
extern int tank_move_stand;
extern int tank_move_start_run;
extern int tank_move_walk;
-extern void door_blocked( void );
-extern void door_secret_blocked( void );
-extern void plat_blocked( void );
-extern void rotating_blocked( void );
-extern void train_blocked( void );
-extern void turret_blocked( void );
-extern void actor_die( void );
-extern void barrel_delay( void );
-extern void berserk_die( void );
-extern void body_die( void );
-extern void boss2_die( void );
-extern void brain_die( void );
-extern void button_killed( void );
-extern void chick_die( void );
-extern void debris_die( void );
-extern void door_killed( void );
-extern void door_secret_die( void );
-extern void flipper_die( void );
-extern void floater_die( void );
-extern void flyer_die( void );
-extern void func_explosive_explode( void );
-extern void gib_die( void );
-extern void gladiator_die( void );
-extern void gunner_die( void );
-extern void hover_die( void );
-extern void infantry_die( void );
-extern void insane_die( void );
-extern void jorg_die( void );
-extern void makron_die( void );
-extern void medic_die( void );
-extern void misc_deadsoldier_die( void );
-extern void mutant_die( void );
-extern void parasite_die( void );
-extern void player_die( void );
-extern void soldier_die( void );
-extern void supertank_die( void );
-extern void tank_die( void );
-extern void turret_driver_die( void );
-extern void actor_attack( void );
-extern void boss2_attack( void );
-extern void chick_attack( void );
-extern void floater_attack( void );
-extern void flyer_attack( void );
-extern void gladiator_attack( void );
-extern void gunner_attack( void );
-extern void hover_start_attack( void );
-extern void infantry_attack( void );
-extern void jorg_attack( void );
-extern void makron_attack( void );
-extern void medic_attack( void );
-extern void mutant_jump( void );
-extern void parasite_attack( void );
-extern void soldier_attack( void );
-extern void supertank_attack( void );
-extern void tank_attack( void );
-extern void Boss2_CheckAttack( void );
-extern void Jorg_CheckAttack( void );
-extern void Makron_CheckAttack( void );
-extern void M_CheckAttack( void );
-extern void medic_checkattack( void );
-extern void mutant_checkattack( void );
-extern void brain_dodge( void );
-extern void chick_dodge( void );
-extern void gunner_dodge( void );
-extern void infantry_dodge( void );
-extern void medic_dodge( void );
-extern void soldier_dodge( void );
-extern void brain_idle( void );
-extern void floater_idle( void );
-extern void flyer_idle( void );
-extern void gladiator_idle( void );
-extern void infantry_fidget( void );
-extern void medic_idle( void );
-extern void mutant_idle( void );
-extern void parasite_idle( void );
-extern void tank_idle( void );
-extern void berserk_melee( void );
-extern void brain_melee( void );
-extern void chick_melee( void );
-extern void flipper_melee( void );
-extern void floater_melee( void );
-extern void flyer_melee( void );
-extern void gladiator_melee( void );
-extern void mutant_melee( void );
-extern void actor_run( void );
-extern void berserk_run( void );
-extern void boss2_run( void );
-extern void brain_run( void );
-extern void chick_run( void );
-extern void flipper_start_run( void );
-extern void floater_run( void );
-extern void flyer_run( void );
-extern void gladiator_run( void );
-extern void gunner_run( void );
-extern void hover_run( void );
-extern void infantry_run( void );
-extern void insane_run( void );
-extern void jorg_run( void );
-extern void makron_run( void );
-extern void medic_run( void );
-extern void mutant_run( void );
-extern void parasite_start_run( void );
-extern void soldier_run( void );
-extern void supertank_run( void );
-extern void tank_run( void );
-extern void berserk_search( void );
-extern void boss2_search( void );
-extern void brain_search( void );
-extern void gladiator_search( void );
-extern void gunner_search( void );
-extern void hover_search( void );
-extern void jorg_search( void );
-extern void medic_search( void );
-extern void mutant_search( void );
-extern void supertank_search( void );
-extern void berserk_sight( void );
-extern void brain_sight( void );
-extern void chick_sight( void );
-extern void flipper_sight( void );
-extern void floater_sight( void );
-extern void flyer_sight( void );
-extern void gladiator_sight( void );
-extern void gunner_sight( void );
-extern void hover_sight( void );
-extern void infantry_sight( void );
-extern void makron_sight( void );
-extern void medic_sight( void );
-extern void mutant_sight( void );
-extern void parasite_sight( void );
-extern void soldier_sight( void );
-extern void tank_sight( void );
-extern void actor_stand( void );
-extern void berserk_stand( void );
-extern void boss2_stand( void );
-extern void brain_stand( void );
-extern void chick_stand( void );
-extern void flipper_stand( void );
-extern void floater_stand( void );
-extern void flyer_stand( void );
-extern void gladiator_stand( void );
-extern void gunner_stand( void );
-extern void hover_stand( void );
-extern void infantry_stand( void );
-extern void insane_stand( void );
-extern void jorg_stand( void );
-extern void makron_stand( void );
-extern void medic_stand( void );
-extern void mutant_stand( void );
-extern void parasite_stand( void );
-extern void soldier_stand( void );
-extern void supertank_stand( void );
-extern void tank_stand( void );
-extern void actor_walk( void );
-extern void berserk_walk( void );
-extern void boss2_walk( void );
-extern void brain_walk( void );
-extern void chick_walk( void );
-extern void flipper_walk( void );
-extern void floater_walk( void );
-extern void flyer_walk( void );
-extern void gladiator_walk( void );
-extern void gunner_walk( void );
-extern void hover_walk( void );
-extern void infantry_walk( void );
-extern void insane_walk( void );
-extern void jorg_walk( void );
-extern void makron_walk( void );
-extern void medic_walk( void );
-extern void mutant_walk( void );
-extern void parasite_start_walk( void );
-extern void soldier_walk( void );
-extern void supertank_walk( void );
-extern void tank_walk( void );
-extern void actor_pain( void );
-extern void berserk_pain( void );
-extern void boss2_pain( void );
-extern void brain_pain( void );
-extern void chick_pain( void );
-extern void flipper_pain( void );
-extern void floater_pain( void );
-extern void flyer_pain( void );
-extern void gladiator_pain( void );
-extern void gunner_pain( void );
-extern void hover_pain( void );
-extern void infantry_pain( void );
-extern void insane_pain( void );
-extern void jorg_pain( void );
-extern void makron_pain( void );
-extern void medic_pain( void );
-extern void mutant_pain( void );
-extern void parasite_pain( void );
-extern void player_pain( void );
-extern void soldier_pain( void );
-extern void supertank_pain( void );
-extern void tank_pain( void );
-extern void AngleMove_Begin( void );
-extern void AngleMove_Done( void );
-extern void AngleMove_Final( void );
-extern void barrel_explode( void );
-extern void bfg_explode( void );
-extern void bfg_think( void );
-extern void BossExplode( void );
-extern void button_return( void );
-extern void commander_body_drop( void );
-extern void commander_body_think( void );
-extern void door_go_down( void );
-extern void door_secret_move2( void );
-extern void door_secret_move4( void );
-extern void door_secret_move6( void );
-extern void DoRespawn( void );
-extern void drop_make_touchable( void );
-extern void droptofloor( void );
-extern void flymonster_start_go( void );
-extern void func_clock_think( void );
-extern void func_object_release( void );
-extern void func_timer_think( void );
-extern void func_train_find( void );
-extern void G_FreeEdict( void );
-extern void gib_think( void );
-extern void Grenade_Explode( void );
-extern void hover_deadthink( void );
-extern void MakronSpawn( void );
-extern void makron_torso_think( void );
-extern void M_droptofloor( void );
-extern void MegaHealth_think( void );
-extern void M_FliesOff( void );
-extern void M_FliesOn( void );
-extern void misc_banner_think( void );
-extern void misc_blackhole_think( void );
-extern void misc_easterchick2_think( void );
-extern void misc_easterchick_think( void );
-extern void misc_eastertank_think( void );
-extern void misc_satellite_dish_think( void );
-extern void monster_think( void );
-extern void monster_triggered_spawn( void );
-extern void Move_Begin( void );
-extern void Move_Done( void );
-extern void Move_Final( void );
-extern void multi_wait( void );
-extern void plat_go_down( void );
-extern void SP_CreateCoopSpots( void );
-extern void SP_FixCoopSpots( void );
-extern void swimmonster_start_go( void );
-extern void target_crosslevel_target_think( void );
-extern void target_earthquake_think( void );
-extern void target_explosion_explode( void );
-extern void target_laser_start( void );
-extern void target_laser_think( void );
-extern void target_lightramp_think( void );
-extern void Think_AccelMove( void );
-extern void Think_Boss3Stand( void );
-extern void Think_CalcMoveSpeed( void );
-extern void Think_Delay( void );
-extern void Think_SpawnDoorTrigger( void );
-extern void TH_viewthing( void );
-extern void train_next( void );
-extern void trigger_elevator_init( void );
-extern void turret_breach_finish_init( void );
-extern void turret_breach_think( void );
-extern void turret_driver_link( void );
-extern void turret_driver_think( void );
-extern void walkmonster_start_go( void );
-extern void barrel_touch( void );
-extern void bfg_touch( void );
-extern void blaster_touch( void );
-extern void button_touch( void );
-extern void door_touch( void );
-extern void drop_temp_touch( void );
-extern void func_object_touch( void );
-extern void gib_touch( void );
-extern void Grenade_Touch( void );
-extern void hurt_touch( void );
-extern void misc_viper_bomb_touch( void );
-extern void mutant_jump_touch( void );
-extern void path_corner_touch( void );
-extern void point_combat_touch( void );
-extern void rocket_touch( void );
-extern void rotating_touch( void );
-extern void target_actor_touch( void );
-extern void teleporter_touch( void );
-extern void Touch_DoorTrigger( void );
-extern void Touch_Item( void );
-extern void Touch_Multi( void );
-extern void Touch_Plat_Center( void );
-extern void trigger_gravity_touch( void );
-extern void trigger_monsterjump_touch( void );
-extern void trigger_push_touch( void );
-extern void actor_use( void );
-extern void button_use( void );
-extern void commander_body_use( void );
-extern void door_secret_use( void );
-extern void door_use( void );
-extern void func_clock_use( void );
-extern void func_conveyor_use( void );
-extern void func_explosive_spawn( void );
-extern void func_explosive_use( void );
-extern void func_object_use( void );
-extern void func_timer_use( void );
-extern void func_wall_use( void );
-extern void hurt_use( void );
-extern void light_use( void );
-extern void misc_blackhole_use( void );
-extern void misc_satellite_dish_use( void );
-extern void misc_strogg_ship_use( void );
-extern void misc_viper_bomb_use( void );
-extern void misc_viper_use( void );
-extern void monster_triggered_spawn_use( void );
-extern void monster_use( void );
-extern void rotating_use( void );
-extern void target_earthquake_use( void );
-extern void target_laser_use( void );
-extern void target_lightramp_use( void );
-extern void target_string_use( void );
-extern void train_use( void );
-extern void trigger_counter_use( void );
-extern void trigger_crosslevel_trigger_use( void );
-extern void trigger_elevator_use( void );
-extern void trigger_enable( void );
-extern void trigger_key_use( void );
-extern void trigger_relay_use( void );
-extern void Use_Areaportal( void );
-extern void Use_Boss3( void );
-extern void Use_Item( void );
-extern void use_killbox( void );
-extern void Use_Multi( void );
-extern void Use_Plat( void );
-extern void use_target_blaster( void );
-extern void use_target_changelevel( void );
-extern void use_target_explosion( void );
-extern void use_target_goal( void );
-extern void Use_Target_Help( void );
-extern void use_target_secret( void );
-extern void use_target_spawner( void );
-extern void Use_Target_Speaker( void );
-extern void use_target_splash( void );
-extern void Use_Target_Tent( void );
-extern void plat_hit_bottom( void );
-extern void plat_hit_top( void );
-extern void button_done( void );
-extern void button_wait( void );
-extern void door_hit_bottom( void );
-extern void door_hit_top( void );
-extern void train_wait( void );
-extern void door_secret_move1( void );
-extern void door_secret_move3( void );
-extern void door_secret_move5( void );
-extern void door_secret_done( void );
+extern void door_blocked(void);
+extern void door_secret_blocked(void);
+extern void plat_blocked(void);
+extern void rotating_blocked(void);
+extern void train_blocked(void);
+extern void turret_blocked(void);
+extern void actor_die(void);
+extern void barrel_delay(void);
+extern void berserk_die(void);
+extern void body_die(void);
+extern void boss2_die(void);
+extern void brain_die(void);
+extern void button_killed(void);
+extern void chick_die(void);
+extern void debris_die(void);
+extern void door_killed(void);
+extern void door_secret_die(void);
+extern void flipper_die(void);
+extern void floater_die(void);
+extern void flyer_die(void);
+extern void func_explosive_explode(void);
+extern void gib_die(void);
+extern void gladiator_die(void);
+extern void gunner_die(void);
+extern void hover_die(void);
+extern void infantry_die(void);
+extern void insane_die(void);
+extern void jorg_die(void);
+extern void makron_die(void);
+extern void medic_die(void);
+extern void misc_deadsoldier_die(void);
+extern void mutant_die(void);
+extern void parasite_die(void);
+extern void player_die(void);
+extern void soldier_die(void);
+extern void supertank_die(void);
+extern void tank_die(void);
+extern void turret_driver_die(void);
+extern void actor_attack(void);
+extern void boss2_attack(void);
+extern void chick_attack(void);
+extern void floater_attack(void);
+extern void flyer_attack(void);
+extern void gladiator_attack(void);
+extern void gunner_attack(void);
+extern void hover_start_attack(void);
+extern void infantry_attack(void);
+extern void jorg_attack(void);
+extern void makron_attack(void);
+extern void medic_attack(void);
+extern void mutant_jump(void);
+extern void parasite_attack(void);
+extern void soldier_attack(void);
+extern void supertank_attack(void);
+extern void tank_attack(void);
+extern void Boss2_CheckAttack(void);
+extern void Jorg_CheckAttack(void);
+extern void Makron_CheckAttack(void);
+extern void M_CheckAttack(void);
+extern void medic_checkattack(void);
+extern void mutant_checkattack(void);
+extern void brain_dodge(void);
+extern void chick_dodge(void);
+extern void gunner_dodge(void);
+extern void infantry_dodge(void);
+extern void medic_dodge(void);
+extern void soldier_dodge(void);
+extern void brain_idle(void);
+extern void floater_idle(void);
+extern void flyer_idle(void);
+extern void gladiator_idle(void);
+extern void infantry_fidget(void);
+extern void medic_idle(void);
+extern void mutant_idle(void);
+extern void parasite_idle(void);
+extern void tank_idle(void);
+extern void berserk_melee(void);
+extern void brain_melee(void);
+extern void chick_melee(void);
+extern void flipper_melee(void);
+extern void floater_melee(void);
+extern void flyer_melee(void);
+extern void gladiator_melee(void);
+extern void mutant_melee(void);
+extern void actor_run(void);
+extern void berserk_run(void);
+extern void boss2_run(void);
+extern void brain_run(void);
+extern void chick_run(void);
+extern void flipper_start_run(void);
+extern void floater_run(void);
+extern void flyer_run(void);
+extern void gladiator_run(void);
+extern void gunner_run(void);
+extern void hover_run(void);
+extern void infantry_run(void);
+extern void insane_run(void);
+extern void jorg_run(void);
+extern void makron_run(void);
+extern void medic_run(void);
+extern void mutant_run(void);
+extern void parasite_start_run(void);
+extern void soldier_run(void);
+extern void supertank_run(void);
+extern void tank_run(void);
+extern void berserk_search(void);
+extern void boss2_search(void);
+extern void brain_search(void);
+extern void gladiator_search(void);
+extern void gunner_search(void);
+extern void hover_search(void);
+extern void jorg_search(void);
+extern void medic_search(void);
+extern void mutant_search(void);
+extern void supertank_search(void);
+extern void berserk_sight(void);
+extern void brain_sight(void);
+extern void chick_sight(void);
+extern void flipper_sight(void);
+extern void floater_sight(void);
+extern void flyer_sight(void);
+extern void gladiator_sight(void);
+extern void gunner_sight(void);
+extern void hover_sight(void);
+extern void infantry_sight(void);
+extern void makron_sight(void);
+extern void medic_sight(void);
+extern void mutant_sight(void);
+extern void parasite_sight(void);
+extern void soldier_sight(void);
+extern void tank_sight(void);
+extern void actor_stand(void);
+extern void berserk_stand(void);
+extern void boss2_stand(void);
+extern void brain_stand(void);
+extern void chick_stand(void);
+extern void flipper_stand(void);
+extern void floater_stand(void);
+extern void flyer_stand(void);
+extern void gladiator_stand(void);
+extern void gunner_stand(void);
+extern void hover_stand(void);
+extern void infantry_stand(void);
+extern void insane_stand(void);
+extern void jorg_stand(void);
+extern void makron_stand(void);
+extern void medic_stand(void);
+extern void mutant_stand(void);
+extern void parasite_stand(void);
+extern void soldier_stand(void);
+extern void supertank_stand(void);
+extern void tank_stand(void);
+extern void actor_walk(void);
+extern void berserk_walk(void);
+extern void boss2_walk(void);
+extern void brain_walk(void);
+extern void chick_walk(void);
+extern void flipper_walk(void);
+extern void floater_walk(void);
+extern void flyer_walk(void);
+extern void gladiator_walk(void);
+extern void gunner_walk(void);
+extern void hover_walk(void);
+extern void infantry_walk(void);
+extern void insane_walk(void);
+extern void jorg_walk(void);
+extern void makron_walk(void);
+extern void medic_walk(void);
+extern void mutant_walk(void);
+extern void parasite_start_walk(void);
+extern void soldier_walk(void);
+extern void supertank_walk(void);
+extern void tank_walk(void);
+extern void actor_pain(void);
+extern void berserk_pain(void);
+extern void boss2_pain(void);
+extern void brain_pain(void);
+extern void chick_pain(void);
+extern void flipper_pain(void);
+extern void floater_pain(void);
+extern void flyer_pain(void);
+extern void gladiator_pain(void);
+extern void gunner_pain(void);
+extern void hover_pain(void);
+extern void infantry_pain(void);
+extern void insane_pain(void);
+extern void jorg_pain(void);
+extern void makron_pain(void);
+extern void medic_pain(void);
+extern void mutant_pain(void);
+extern void parasite_pain(void);
+extern void player_pain(void);
+extern void soldier_pain(void);
+extern void supertank_pain(void);
+extern void tank_pain(void);
+extern void AngleMove_Begin(void);
+extern void AngleMove_Done(void);
+extern void AngleMove_Final(void);
+extern void barrel_explode(void);
+extern void bfg_explode(void);
+extern void bfg_think(void);
+extern void BossExplode(void);
+extern void button_return(void);
+extern void commander_body_drop(void);
+extern void commander_body_think(void);
+extern void door_go_down(void);
+extern void door_secret_move2(void);
+extern void door_secret_move4(void);
+extern void door_secret_move6(void);
+extern void DoRespawn(void);
+extern void drop_make_touchable(void);
+extern void droptofloor(void);
+extern void flymonster_start_go(void);
+extern void func_clock_think(void);
+extern void func_object_release(void);
+extern void func_timer_think(void);
+extern void func_train_find(void);
+extern void G_FreeEdict(void);
+extern void gib_think(void);
+extern void Grenade_Explode(void);
+extern void hover_deadthink(void);
+extern void MakronSpawn(void);
+extern void makron_torso_think(void);
+extern void M_droptofloor(void);
+extern void MegaHealth_think(void);
+extern void M_FliesOff(void);
+extern void M_FliesOn(void);
+extern void misc_banner_think(void);
+extern void misc_blackhole_think(void);
+extern void misc_easterchick2_think(void);
+extern void misc_easterchick_think(void);
+extern void misc_eastertank_think(void);
+extern void misc_satellite_dish_think(void);
+extern void monster_think(void);
+extern void monster_triggered_spawn(void);
+extern void Move_Begin(void);
+extern void Move_Done(void);
+extern void Move_Final(void);
+extern void multi_wait(void);
+extern void plat_go_down(void);
+extern void SP_CreateCoopSpots(void);
+extern void SP_FixCoopSpots(void);
+extern void swimmonster_start_go(void);
+extern void target_crosslevel_target_think(void);
+extern void target_earthquake_think(void);
+extern void target_explosion_explode(void);
+extern void target_laser_start(void);
+extern void target_laser_think(void);
+extern void target_lightramp_think(void);
+extern void Think_AccelMove(void);
+extern void Think_Boss3Stand(void);
+extern void Think_CalcMoveSpeed(void);
+extern void Think_Delay(void);
+extern void Think_SpawnDoorTrigger(void);
+extern void TH_viewthing(void);
+extern void train_next(void);
+extern void trigger_elevator_init(void);
+extern void turret_breach_finish_init(void);
+extern void turret_breach_think(void);
+extern void turret_driver_link(void);
+extern void turret_driver_think(void);
+extern void walkmonster_start_go(void);
+extern void barrel_touch(void);
+extern void bfg_touch(void);
+extern void blaster_touch(void);
+extern void button_touch(void);
+extern void door_touch(void);
+extern void drop_temp_touch(void);
+extern void func_object_touch(void);
+extern void gib_touch(void);
+extern void Grenade_Touch(void);
+extern void hurt_touch(void);
+extern void misc_viper_bomb_touch(void);
+extern void mutant_jump_touch(void);
+extern void path_corner_touch(void);
+extern void point_combat_touch(void);
+extern void rocket_touch(void);
+extern void rotating_touch(void);
+extern void target_actor_touch(void);
+extern void teleporter_touch(void);
+extern void Touch_DoorTrigger(void);
+extern void Touch_Item(void);
+extern void Touch_Multi(void);
+extern void Touch_Plat_Center(void);
+extern void trigger_gravity_touch(void);
+extern void trigger_monsterjump_touch(void);
+extern void trigger_push_touch(void);
+extern void actor_use(void);
+extern void button_use(void);
+extern void commander_body_use(void);
+extern void door_secret_use(void);
+extern void door_use(void);
+extern void func_clock_use(void);
+extern void func_conveyor_use(void);
+extern void func_explosive_spawn(void);
+extern void func_explosive_use(void);
+extern void func_object_use(void);
+extern void func_timer_use(void);
+extern void func_wall_use(void);
+extern void hurt_use(void);
+extern void light_use(void);
+extern void misc_blackhole_use(void);
+extern void misc_satellite_dish_use(void);
+extern void misc_strogg_ship_use(void);
+extern void misc_viper_bomb_use(void);
+extern void misc_viper_use(void);
+extern void monster_triggered_spawn_use(void);
+extern void monster_use(void);
+extern void rotating_use(void);
+extern void target_earthquake_use(void);
+extern void target_laser_use(void);
+extern void target_lightramp_use(void);
+extern void target_string_use(void);
+extern void train_use(void);
+extern void trigger_counter_use(void);
+extern void trigger_crosslevel_trigger_use(void);
+extern void trigger_elevator_use(void);
+extern void trigger_enable(void);
+extern void trigger_key_use(void);
+extern void trigger_relay_use(void);
+extern void Use_Areaportal(void);
+extern void Use_Boss3(void);
+extern void Use_Item(void);
+extern void use_killbox(void);
+extern void Use_Multi(void);
+extern void Use_Plat(void);
+extern void use_target_blaster(void);
+extern void use_target_changelevel(void);
+extern void use_target_explosion(void);
+extern void use_target_goal(void);
+extern void Use_Target_Help(void);
+extern void use_target_secret(void);
+extern void use_target_spawner(void);
+extern void Use_Target_Speaker(void);
+extern void use_target_splash(void);
+extern void Use_Target_Tent(void);
+extern void plat_hit_bottom(void);
+extern void plat_hit_top(void);
+extern void button_done(void);
+extern void button_wait(void);
+extern void door_hit_bottom(void);
+extern void door_hit_top(void);
+extern void train_wait(void);
+extern void door_secret_move1(void);
+extern void door_secret_move3(void);
+extern void door_secret_move5(void);
+extern void door_secret_done(void);
const save_ptr_t save_ptrs[] = {
{ P_blocked, door_blocked },
{ P_blocked, door_secret_blocked },
@@ -706,7 +706,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &boss2_move_pain_light },
{ P_monsterinfo_currentmove, &boss2_move_run },
{ P_monsterinfo_currentmove, &boss2_move_stand },
-{ P_monsterinfo_currentmove, &boss2_move_stand },
+{ P_monsterinfo_currentmove, &boss2_move_stand },
{ P_monsterinfo_currentmove, &boss2_move_walk },
{ P_monsterinfo_currentmove, &brain_move_attack1 },
{ P_monsterinfo_currentmove, &brain_move_attack2 },
@@ -719,7 +719,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &brain_move_pain3 },
{ P_monsterinfo_currentmove, &brain_move_run },
{ P_monsterinfo_currentmove, &brain_move_stand },
-{ P_monsterinfo_currentmove, &brain_move_stand },
+{ P_monsterinfo_currentmove, &brain_move_stand },
{ P_monsterinfo_currentmove, &brain_move_walk1 },
{ P_monsterinfo_currentmove, &chick_move_attack1 },
{ P_monsterinfo_currentmove, &chick_move_death1 },
@@ -745,7 +745,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &flipper_move_run_loop },
{ P_monsterinfo_currentmove, &flipper_move_run_start },
{ P_monsterinfo_currentmove, &flipper_move_stand },
-{ P_monsterinfo_currentmove, &flipper_move_stand },
+{ P_monsterinfo_currentmove, &flipper_move_stand },
{ P_monsterinfo_currentmove, &flipper_move_start_run },
{ P_monsterinfo_currentmove, &flipper_move_walk },
{ P_monsterinfo_currentmove, &floater_move_attack1 },
@@ -755,9 +755,9 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &floater_move_pain2 },
{ P_monsterinfo_currentmove, &floater_move_run },
{ P_monsterinfo_currentmove, &floater_move_stand1 },
-{ P_monsterinfo_currentmove, &floater_move_stand1 },
+{ P_monsterinfo_currentmove, &floater_move_stand1 },
+{ P_monsterinfo_currentmove, &floater_move_stand2 },
{ P_monsterinfo_currentmove, &floater_move_stand2 },
-{ P_monsterinfo_currentmove, &floater_move_stand2 },
{ P_monsterinfo_currentmove, &floater_move_walk },
{ P_monsterinfo_currentmove, &flyer_move_attack2 },
{ P_monsterinfo_currentmove, &flyer_move_end_melee },
@@ -767,7 +767,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &flyer_move_pain3 },
{ P_monsterinfo_currentmove, &flyer_move_run },
{ P_monsterinfo_currentmove, &flyer_move_stand },
-{ P_monsterinfo_currentmove, &flyer_move_stand },
+{ P_monsterinfo_currentmove, &flyer_move_stand },
{ P_monsterinfo_currentmove, &flyer_move_start },
{ P_monsterinfo_currentmove, &flyer_move_start_melee },
{ P_monsterinfo_currentmove, &flyer_move_stop },
@@ -793,7 +793,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &gunner_move_run },
{ P_monsterinfo_currentmove, &gunner_move_runandshoot },
{ P_monsterinfo_currentmove, &gunner_move_stand },
-{ P_monsterinfo_currentmove, &gunner_move_stand },
+{ P_monsterinfo_currentmove, &gunner_move_stand },
{ P_monsterinfo_currentmove, &gunner_move_walk },
{ P_monsterinfo_currentmove, &hover_move_attack1 },
{ P_monsterinfo_currentmove, &hover_move_death1 },
@@ -803,7 +803,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &hover_move_pain3 },
{ P_monsterinfo_currentmove, &hover_move_run },
{ P_monsterinfo_currentmove, &hover_move_stand },
-{ P_monsterinfo_currentmove, &hover_move_stand },
+{ P_monsterinfo_currentmove, &hover_move_stand },
{ P_monsterinfo_currentmove, &hover_move_start_attack },
{ P_monsterinfo_currentmove, &hover_move_walk },
{ P_monsterinfo_currentmove, &infantry_move_attack1 },
@@ -823,8 +823,8 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &insane_move_crawl_pain },
{ P_monsterinfo_currentmove, &insane_move_cross },
{ P_monsterinfo_currentmove, &insane_move_down },
-{ P_monsterinfo_currentmove, &insane_move_downtoup },
-{ P_monsterinfo_currentmove, &insane_move_jumpdown },
+{ P_monsterinfo_currentmove, &insane_move_downtoup },
+{ P_monsterinfo_currentmove, &insane_move_jumpdown },
{ P_monsterinfo_currentmove, &insane_move_runcrawl },
{ P_monsterinfo_currentmove, &insane_move_run_insane },
{ P_monsterinfo_currentmove, &insane_move_run_normal },
@@ -833,14 +833,14 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &insane_move_stand_normal },
{ P_monsterinfo_currentmove, &insane_move_stand_pain },
{ P_monsterinfo_currentmove, &insane_move_struggle_cross },
-{ P_monsterinfo_currentmove, &insane_move_struggle_cross },
+{ P_monsterinfo_currentmove, &insane_move_struggle_cross },
{ P_monsterinfo_currentmove, &insane_move_uptodown },
{ P_monsterinfo_currentmove, &insane_move_walk_insane },
{ P_monsterinfo_currentmove, &insane_move_walk_normal },
{ P_monsterinfo_currentmove, &jorg_move_attack1 },
{ P_monsterinfo_currentmove, &jorg_move_attack2 },
{ P_monsterinfo_currentmove, &jorg_move_death },
-{ P_monsterinfo_currentmove, &jorg_move_end_attack1 },
+{ P_monsterinfo_currentmove, &jorg_move_end_attack1 },
{ P_monsterinfo_currentmove, &jorg_move_pain1 },
{ P_monsterinfo_currentmove, &jorg_move_pain2 },
{ P_monsterinfo_currentmove, &jorg_move_pain3 },
@@ -889,7 +889,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &parasite_move_pain1 },
{ P_monsterinfo_currentmove, &parasite_move_run },
{ P_monsterinfo_currentmove, &parasite_move_stand },
-{ P_monsterinfo_currentmove, &parasite_move_stand },
+{ P_monsterinfo_currentmove, &parasite_move_stand },
{ P_monsterinfo_currentmove, &parasite_move_start_fidget },
{ P_monsterinfo_currentmove, &parasite_move_start_run },
{ P_monsterinfo_currentmove, &parasite_move_start_walk },
@@ -920,7 +920,7 @@ const save_ptr_t save_ptrs[] = {
{ P_monsterinfo_currentmove, &supertank_move_attack2 },
{ P_monsterinfo_currentmove, &supertank_move_death },
{ P_monsterinfo_currentmove, &supertank_move_end_attack1 },
-{ P_monsterinfo_currentmove, &supertank_move_end_attack1 },
+{ P_monsterinfo_currentmove, &supertank_move_end_attack1 },
{ P_monsterinfo_currentmove, &supertank_move_forward },
{ P_monsterinfo_currentmove, &supertank_move_pain1 },
{ P_monsterinfo_currentmove, &supertank_move_pain2 },
@@ -1230,4 +1230,4 @@ const save_ptr_t save_ptrs[] = {
{ P_moveinfo_endfunc, door_secret_move5 },
{ P_moveinfo_endfunc, door_secret_done },
};
-const int num_save_ptrs = sizeof( save_ptrs ) / sizeof( save_ptrs[0] );
+const int num_save_ptrs = sizeof(save_ptrs) / sizeof(save_ptrs[0]);
diff --git a/src/baseq2/g_save.c b/src/baseq2/g_save.c
index 25d608b..8477306 100644
--- a/src/baseq2/g_save.c
+++ b/src/baseq2/g_save.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -32,25 +32,25 @@ typedef struct {
} save_field_t;
#ifdef _DEBUG
-#define _FA(type,name,size) {type,#name,_OFS(name),size}
+#define _FA(type, name, size) { type, #name, _OFS(name), size }
#else
-#define _FA(type,name,size) {type,_OFS(name),size}
+#define _FA(type, name, size) { type, _OFS(name), size }
#endif
-#define _F(type,name) _FA(type,name,1)
-#define SZ(name,size) _FA(F_ZSTRING,name,size)
-#define BA(name,size) _FA(F_BYTE,name,size)
-#define B(name) BA(name,1)
-#define SA(name,size) _FA(F_SHORT,name,size)
-#define S(name) SA(name,1)
-#define IA(name,size) _FA(F_INT,name,size)
-#define I(name) IA(name,1)
-#define FA(name,size) _FA(F_FLOAT,name,size)
-#define F(name) FA(name,1)
-#define L(name) _F(F_LSTRING,name)
-#define V(name) _F(F_VECTOR,name)
-#define T(name) _F(F_ITEM,name)
-#define E(name) _F(F_EDICT,name)
-#define P(name,type) _FA(F_POINTER,name,type)
+#define _F(type, name) _FA(type, name, 1)
+#define SZ(name, size) _FA(F_ZSTRING, name, size)
+#define BA(name, size) _FA(F_BYTE, name, size)
+#define B(name) BA(name, 1)
+#define SA(name, size) _FA(F_SHORT, name, size)
+#define S(name) SA(name, 1)
+#define IA(name, size) _FA(F_INT, name, size)
+#define I(name) IA(name, 1)
+#define FA(name, size) _FA(F_FLOAT, name, size)
+#define F(name) FA(name, 1)
+#define L(name) _F(F_LSTRING, name)
+#define V(name) _F(F_VECTOR, name)
+#define T(name) _F(F_ITEM, name)
+#define E(name) _F(F_EDICT, name)
+#define P(name, type) _FA(F_POINTER, name, type)
static const save_field_t entityfields[] = {
#define _OFS FOFS
@@ -181,7 +181,7 @@ static const save_field_t entityfields[] = {
V(move_origin),
V(move_angles),
-
+
I(light_level),
I(style),
@@ -312,7 +312,7 @@ static const save_field_t clientfields[] = {
I(ps.gunframe),
FA(ps.blend, 4),
-
+
F(ps.fov),
I(ps.rdflags),
@@ -432,313 +432,334 @@ static const save_field_t gamefields[] = {
//=========================================================
-static void write_data( void *buf, size_t len, FILE *f ) {
- if( fwrite( buf, 1, len, f ) != len ) {
- gi.error( "%s: couldn't write %"PRIz" bytes", __func__, len );
+static void write_data(void *buf, size_t len, FILE *f)
+{
+ if (fwrite(buf, 1, len, f) != len) {
+ gi.error("%s: couldn't write %"PRIz" bytes", __func__, len);
}
}
-static void write_short( FILE *f, short v ) {
- v = LittleShort( v );
- write_data( &v, sizeof( v ), f );
+static void write_short(FILE *f, short v)
+{
+ v = LittleShort(v);
+ write_data(&v, sizeof(v), f);
}
-static void write_int( FILE *f, int v ) {
- v = LittleLong( v );
- write_data( &v, sizeof( v ), f );
+static void write_int(FILE *f, int v)
+{
+ v = LittleLong(v);
+ write_data(&v, sizeof(v), f);
}
-static void write_float( FILE *f, float v ) {
- v = LittleFloat( v );
- write_data( &v, sizeof( v ), f );
+static void write_float(FILE *f, float v)
+{
+ v = LittleFloat(v);
+ write_data(&v, sizeof(v), f);
}
-static void write_string( FILE *f, char *s ) {
+static void write_string(FILE *f, char *s)
+{
size_t len;
- if( !s ) {
- write_int( f, -1 );
+ if (!s) {
+ write_int(f, -1);
return;
}
- len = strlen( s );
- write_int( f, len );
- write_data( s, len, f );
+ len = strlen(s);
+ write_int(f, len);
+ write_data(s, len, f);
}
-static void write_vector( FILE *f, vec_t *v ) {
- write_float( f, v[0] );
- write_float( f, v[1] );
- write_float( f, v[2] );
+static void write_vector(FILE *f, vec_t *v)
+{
+ write_float(f, v[0]);
+ write_float(f, v[1]);
+ write_float(f, v[2]);
}
-static void write_index( FILE *f, void *p, size_t size, void *start, int max_index ) {
+static void write_index(FILE *f, void *p, size_t size, void *start, int max_index)
+{
size_t diff;
- if( !p ) {
- write_int( f, -1 );
+ if (!p) {
+ write_int(f, -1);
return;
}
- if( p < start || ( byte * )p > ( byte * )start + max_index * size ) {
- gi.error( "%s: pointer out of range: %p", __func__, p );
+ if (p < start || (byte *)p > (byte *)start + max_index * size) {
+ gi.error("%s: pointer out of range: %p", __func__, p);
}
diff = p - start;
- if( diff % size ) {
- gi.error( "%s: misaligned pointer: %p", __func__, p );
+ if (diff % size) {
+ gi.error("%s: misaligned pointer: %p", __func__, p);
}
- write_int( f, ( int )( diff / size ) );
+ write_int(f, (int)(diff / size));
}
-static void write_pointer( FILE *f, void *p, ptr_type_t type ) {
+static void write_pointer(FILE *f, void *p, ptr_type_t type)
+{
const save_ptr_t *ptr;
int i;
- if( !p ) {
- write_int( f, -1 );
- return;
+ if (!p) {
+ write_int(f, -1);
+ return;
}
- for( i = 0, ptr = save_ptrs; i < num_save_ptrs; i++, ptr++ ) {
- if( ptr->type == type && ptr->ptr == p ) {
- write_int( f, i );
+ for (i = 0, ptr = save_ptrs; i < num_save_ptrs; i++, ptr++) {
+ if (ptr->type == type && ptr->ptr == p) {
+ write_int(f, i);
return;
}
}
- gi.error( "%s: unknown pointer: %p", __func__, p );
+ gi.error("%s: unknown pointer: %p", __func__, p);
}
-static void write_field( FILE *f, const save_field_t *field, void *base ) {
+static void write_field(FILE *f, const save_field_t *field, void *base)
+{
void *p = (byte *)base + field->ofs;
int i;
- switch( field->type ) {
+ switch (field->type) {
case F_BYTE:
- write_data( p, field->size, f );
+ write_data(p, field->size, f);
break;
case F_SHORT:
- for( i = 0; i < field->size; i++ ) {
- write_short( f, (( short * )p)[i] );
+ for (i = 0; i < field->size; i++) {
+ write_short(f, ((short *)p)[i]);
}
break;
case F_INT:
- for( i = 0; i < field->size; i++ ) {
- write_int( f, (( int * )p)[i] );
+ for (i = 0; i < field->size; i++) {
+ write_int(f, ((int *)p)[i]);
}
break;
case F_FLOAT:
- for( i = 0; i < field->size; i++ ) {
- write_float( f, (( float * )p)[i] );
+ for (i = 0; i < field->size; i++) {
+ write_float(f, ((float *)p)[i]);
}
break;
case F_VECTOR:
- write_vector( f, ( vec_t * )p );
+ write_vector(f, (vec_t *)p);
break;
case F_ZSTRING:
- write_string( f, ( char * )p );
+ write_string(f, (char *)p);
break;
case F_LSTRING:
- write_string( f, *( char ** )p );
+ write_string(f, *(char **)p);
break;
case F_EDICT:
- write_index( f, *( void ** )p, sizeof( edict_t ), g_edicts, MAX_EDICTS - 1 );
+ write_index(f, *(void **)p, sizeof(edict_t), g_edicts, MAX_EDICTS - 1);
break;
case F_CLIENT:
- write_index( f, *( void ** )p, sizeof( gclient_t ), game.clients, game.maxclients - 1 );
+ write_index(f, *(void **)p, sizeof(gclient_t), game.clients, game.maxclients - 1);
break;
case F_ITEM:
- write_index( f, *( void ** )p, sizeof( gitem_t ), itemlist, game.num_items - 1 );
+ write_index(f, *(void **)p, sizeof(gitem_t), itemlist, game.num_items - 1);
break;
case F_POINTER:
- write_pointer( f, *( void ** )p, field->size );
+ write_pointer(f, *(void **)p, field->size);
break;
default:
- gi.error( "%s: unknown field type", __func__ );
+ gi.error("%s: unknown field type", __func__);
}
}
-static void write_fields( FILE *f, const save_field_t *fields, void *base ) {
+static void write_fields(FILE *f, const save_field_t *fields, void *base)
+{
const save_field_t *field;
- for( field = fields; field->type; field++ ) {
- write_field( f, field, base );
+ for (field = fields; field->type; field++) {
+ write_field(f, field, base);
}
}
-static void read_data( void *buf, size_t len, FILE *f ) {
- if( fread( buf, 1, len, f ) != len ) {
- gi.error( "%s: couldn't read %"PRIz" bytes", __func__, len );
+static void read_data(void *buf, size_t len, FILE *f)
+{
+ if (fread(buf, 1, len, f) != len) {
+ gi.error("%s: couldn't read %"PRIz" bytes", __func__, len);
}
}
-static int read_short( FILE *f ) {
+static int read_short(FILE *f)
+{
short v;
- read_data( &v, sizeof( v ), f );
- v = LittleShort( v );
+ read_data(&v, sizeof(v), f);
+ v = LittleShort(v);
return v;
}
-static int read_int( FILE *f ) {
+static int read_int(FILE *f)
+{
int v;
- read_data( &v, sizeof( v ), f );
- v = LittleLong( v );
+ read_data(&v, sizeof(v), f);
+ v = LittleLong(v);
return v;
}
-static float read_float( FILE *f ) {
+static float read_float(FILE *f)
+{
float v;
- read_data( &v, sizeof( v ), f );
- v = LittleFloat( v );
+ read_data(&v, sizeof(v), f);
+ v = LittleFloat(v);
return v;
}
-static char *read_string( FILE *f ) {
+static char *read_string(FILE *f)
+{
int len;
char *s;
- len = read_int( f );
- if( len == -1 ) {
+ len = read_int(f);
+ if (len == -1) {
return NULL;
}
- if( len < 0 || len > 65536 ) {
- gi.error( "%s: bad length", __func__ );
+ if (len < 0 || len > 65536) {
+ gi.error("%s: bad length", __func__);
}
- s = gi.TagMalloc( len + 1, TAG_LEVEL );
- read_data( s, len, f );
+ s = gi.TagMalloc(len + 1, TAG_LEVEL);
+ read_data(s, len, f);
s[len] = 0;
return s;
}
-static void read_zstring( FILE *f, char *s, size_t size ) {
+static void read_zstring(FILE *f, char *s, size_t size)
+{
int len;
- len = read_int( f );
- if( len < 0 || len >= size ) {
- gi.error( "%s: bad length", __func__ );
+ len = read_int(f);
+ if (len < 0 || len >= size) {
+ gi.error("%s: bad length", __func__);
}
- read_data( s, len, f );
+ read_data(s, len, f);
s[len] = 0;
}
-static void read_vector( FILE *f, vec_t *v ) {
- v[0] = read_float( f );
- v[1] = read_float( f );
- v[2] = read_float( f );
+static void read_vector(FILE *f, vec_t *v)
+{
+ v[0] = read_float(f);
+ v[1] = read_float(f);
+ v[2] = read_float(f);
}
-static void *read_index( FILE *f, size_t size, void *start, int max_index ) {
+static void *read_index(FILE *f, size_t size, void *start, int max_index)
+{
int index;
byte *p;
- index = read_int( f );
- if( index == -1 ) {
+ index = read_int(f);
+ if (index == -1) {
return NULL;
}
- if( index < 0 || index > max_index ) {
- gi.error( "%s: bad index", __func__ );
+ if (index < 0 || index > max_index) {
+ gi.error("%s: bad index", __func__);
}
- p = ( byte * )start + index * size;
+ p = (byte *)start + index * size;
return p;
}
-static void *read_pointer( FILE *f, ptr_type_t type ) {
+static void *read_pointer(FILE *f, ptr_type_t type)
+{
int index;
const save_ptr_t *ptr;
- index = read_int( f );
- if( index == -1 ) {
+ index = read_int(f);
+ if (index == -1) {
return NULL;
}
- if( index < 0 || index >= num_save_ptrs ) {
- gi.error( "%s: bad index", __func__ );
+ if (index < 0 || index >= num_save_ptrs) {
+ gi.error("%s: bad index", __func__);
}
ptr = &save_ptrs[index];
- if( ptr->type != type ) {
- gi.error( "%s: type mismatch", __func__ );
+ if (ptr->type != type) {
+ gi.error("%s: type mismatch", __func__);
}
return ptr->ptr;
}
-static void read_field( FILE *f, const save_field_t *field, void *base ) {
- void *p = ( byte * )base + field->ofs;
+static void read_field(FILE *f, const save_field_t *field, void *base)
+{
+ void *p = (byte *)base + field->ofs;
int i;
- switch( field->type ) {
+ switch (field->type) {
case F_BYTE:
- read_data( p, field->size, f );
+ read_data(p, field->size, f);
break;
case F_SHORT:
- for( i = 0; i < field->size; i++ ) {
- (( short * )p)[i] = read_short( f );
+ for (i = 0; i < field->size; i++) {
+ ((short *)p)[i] = read_short(f);
}
break;
case F_INT:
- for( i = 0; i < field->size; i++ ) {
- (( int * )p)[i] = read_int( f );
+ for (i = 0; i < field->size; i++) {
+ ((int *)p)[i] = read_int(f);
}
break;
case F_FLOAT:
- for( i = 0; i < field->size; i++ ) {
- (( float * )p)[i] = read_float( f );
+ for (i = 0; i < field->size; i++) {
+ ((float *)p)[i] = read_float(f);
}
break;
case F_VECTOR:
- read_vector( f, ( vec_t * )p );
+ read_vector(f, (vec_t *)p);
break;
case F_LSTRING:
- *( char ** )p = read_string( f );
+ *(char **)p = read_string(f);
break;
case F_ZSTRING:
- read_zstring( f, ( char * )p, field->size );
+ read_zstring(f, (char *)p, field->size);
break;
case F_EDICT:
- *( edict_t ** )p = read_index( f, sizeof( edict_t ), g_edicts, game.maxentities - 1 );
+ *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1);
break;
case F_CLIENT:
- *( gclient_t ** )p = read_index( f, sizeof( gclient_t ), game.clients, game.maxclients - 1 );
+ *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1);
break;
case F_ITEM:
- *( gitem_t ** )p = read_index( f, sizeof( gitem_t ), itemlist, game.num_items - 1 );
+ *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1);
break;
case F_POINTER:
- *( void ** )p = read_pointer( f, field->size );
+ *(void **)p = read_pointer(f, field->size);
break;
default:
- gi.error( "%s: unknown field type", __func__ );
+ gi.error("%s: unknown field type", __func__);
}
}
-static void read_fields( FILE *f, const save_field_t *fields, void *base ) {
+static void read_fields(FILE *f, const save_field_t *fields, void *base)
+{
const save_field_t *field;
- for( field = fields; field->type; field++ ) {
- read_field( f, field, base );
+ for (field = fields; field->type; field++) {
+ read_field(f, field, base);
}
}
@@ -762,75 +783,77 @@ A single player death will automatically restore from the
last save position.
============
*/
-void WriteGame (const char *filename, qboolean autosave) {
+void WriteGame(const char *filename, qboolean autosave)
+{
FILE *f;
int i;
if (!autosave)
- SaveClientData ();
+ SaveClientData();
- f = fopen (filename, "wb");
+ f = fopen(filename, "wb");
if (!f)
- gi.error ("Couldn't open %s", filename);
+ gi.error("Couldn't open %s", filename);
- write_int( f, SAVE_MAGIC1 );
- write_int( f, SAVE_VERSION );
+ write_int(f, SAVE_MAGIC1);
+ write_int(f, SAVE_VERSION);
game.autosaved = autosave;
- write_fields( f, gamefields, &game );
+ write_fields(f, gamefields, &game);
game.autosaved = qfalse;
- for( i = 0; i < game.maxclients; i++ ) {
- write_fields( f, clientfields, &game.clients[i] );
+ for (i = 0; i < game.maxclients; i++) {
+ write_fields(f, clientfields, &game.clients[i]);
}
- fclose (f);
+ fclose(f);
}
-void ReadGame (const char *filename) {
+void ReadGame(const char *filename)
+{
FILE *f;
int i;
- gi.FreeTags (TAG_GAME);
+ gi.FreeTags(TAG_GAME);
- f = fopen (filename, "rb");
+ f = fopen(filename, "rb");
if (!f)
- gi.error ("Couldn't open %s", filename);
+ gi.error("Couldn't open %s", filename);
- i = read_int( f );
- if( i != SAVE_MAGIC1 ) {
- fclose (f);
- gi.error ("Not a save game");
+ i = read_int(f);
+ if (i != SAVE_MAGIC1) {
+ fclose(f);
+ gi.error("Not a save game");
}
- i = read_int( f );
- if( i != SAVE_VERSION ) {
- fclose (f);
- gi.error ("Savegame from an older version.\n");
+ i = read_int(f);
+ if (i != SAVE_VERSION) {
+ fclose(f);
+ gi.error("Savegame from an older version.\n");
}
- read_fields( f, gamefields, &game );
+ read_fields(f, gamefields, &game);
// should agree with server's version
- if( game.maxclients != (int)maxclients->value ) {
- fclose (f);
- gi.error ("Savegame has bad maxclients.\n");
+ if (game.maxclients != (int)maxclients->value) {
+ fclose(f);
+ gi.error("Savegame has bad maxclients.\n");
}
- if( game.maxentities <= game.maxclients || game.maxentities > MAX_EDICTS ) {
- fclose (f);
- gi.error ("Savegame has bad maxentities.\n");
+ if (game.maxentities <= game.maxclients || game.maxentities > MAX_EDICTS) {
+ fclose(f);
+ gi.error("Savegame has bad maxentities.\n");
}
- g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
+ g_edicts = gi.TagMalloc(game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
globals.edicts = g_edicts;
globals.max_edicts = game.maxentities;
- game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME);
- for( i = 0; i < game.maxclients; i++ ) {
- read_fields( f, clientfields, &game.clients[i] );
+ game.clients = gi.TagMalloc(game.maxclients * sizeof(game.clients[0]), TAG_GAME);
+ for (i = 0; i < game.maxclients; i++) {
+ read_fields(f, clientfields, &game.clients[i]);
}
- fclose (f);
+ fclose(f);
}
//==========================================================
@@ -842,32 +865,33 @@ WriteLevel
=================
*/
-void WriteLevel (const char *filename) {
+void WriteLevel(const char *filename)
+{
int i;
edict_t *ent;
FILE *f;
- f = fopen (filename, "wb");
+ f = fopen(filename, "wb");
if (!f)
- gi.error ("Couldn't open %s", filename);
+ gi.error("Couldn't open %s", filename);
- write_int( f, SAVE_MAGIC2 );
- write_int( f, SAVE_VERSION );
+ write_int(f, SAVE_MAGIC2);
+ write_int(f, SAVE_VERSION);
// write out level_locals_t
- write_fields( f, levelfields, &level );
+ write_fields(f, levelfields, &level);
// write out all the entities
- for( i = 0; i < globals.num_edicts; i++ ) {
+ for (i = 0; i < globals.num_edicts; i++) {
ent = &g_edicts[i];
if (!ent->inuse)
continue;
- write_int( f, i );
- write_fields( f, entityfields, ent );
+ write_int(f, i);
+ write_fields(f, entityfields, ent);
}
- write_int( f, -1 );
+ write_int(f, -1);
- fclose (f);
+ fclose(f);
}
@@ -887,7 +911,8 @@ calling ReadLevel.
No clients are connected yet.
=================
*/
-void ReadLevel (const char *filename) {
+void ReadLevel(const char *filename)
+{
int entnum;
FILE *f;
int i;
@@ -895,65 +920,63 @@ void ReadLevel (const char *filename) {
// free any dynamic memory allocated by loading the level
// base state
- gi.FreeTags (TAG_LEVEL);
+ gi.FreeTags(TAG_LEVEL);
- f = fopen (filename, "rb");
+ f = fopen(filename, "rb");
if (!f)
- gi.error ("Couldn't open %s", filename);
+ gi.error("Couldn't open %s", filename);
// wipe all the entities
- memset (g_edicts, 0, game.maxentities*sizeof(g_edicts[0]));
- globals.num_edicts = maxclients->value+1;
+ memset(g_edicts, 0, game.maxentities * sizeof(g_edicts[0]));
+ globals.num_edicts = maxclients->value + 1;
- i = read_int( f );
- if( i != SAVE_MAGIC2 ) {
- fclose (f);
- gi.error ("Not a save game");
+ i = read_int(f);
+ if (i != SAVE_MAGIC2) {
+ fclose(f);
+ gi.error("Not a save game");
}
- i = read_int( f );
- if( i != SAVE_VERSION ) {
- fclose (f);
- gi.error ("Savegame from an older version.\n");
+ i = read_int(f);
+ if (i != SAVE_VERSION) {
+ fclose(f);
+ gi.error("Savegame from an older version.\n");
}
// load the level locals
- read_fields( f, levelfields, &level );
+ read_fields(f, levelfields, &level);
// load all the entities
- while( 1 ) {
- entnum = read_int( f );
- if( entnum == -1 )
+ while (1) {
+ entnum = read_int(f);
+ if (entnum == -1)
break;
- if( entnum < 0 || entnum >= game.maxentities ) {
- gi.error( "%s: bad entity number", __func__ );
+ if (entnum < 0 || entnum >= game.maxentities) {
+ gi.error("%s: bad entity number", __func__);
}
- if( entnum >= globals.num_edicts )
+ if (entnum >= globals.num_edicts)
globals.num_edicts = entnum + 1;
ent = &g_edicts[entnum];
- read_fields( f, entityfields, ent );
+ read_fields(f, entityfields, ent);
ent->inuse = qtrue;
ent->s.number = entnum;
// let the server rebuild world links for this ent
- memset (&ent->area, 0, sizeof(ent->area));
- gi.linkentity (ent);
+ memset(&ent->area, 0, sizeof(ent->area));
+ gi.linkentity(ent);
}
- fclose (f);
+ fclose(f);
// mark all clients as unconnected
- for (i=0 ; i<maxclients->value ; i++)
- {
- ent = &g_edicts[i+1];
+ for (i = 0 ; i < maxclients->value ; i++) {
+ ent = &g_edicts[i + 1];
ent->client = game.clients + i;
ent->client->pers.connected = qfalse;
}
// do any load time things at this point
- for (i=0 ; i<globals.num_edicts ; i++)
- {
+ for (i = 0 ; i < globals.num_edicts ; i++) {
ent = &g_edicts[i];
if (!ent->inuse)
diff --git a/src/baseq2/g_spawn.c b/src/baseq2/g_spawn.c
index 6ebf279..2979095 100644
--- a/src/baseq2/g_spawn.c
+++ b/src/baseq2/g_spawn.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct {
char *name;
- void (*spawn)(edict_t *ent);
+ void (*spawn)(edict_t *ent);
} spawn_func_t;
typedef struct {
@@ -31,122 +31,122 @@ typedef struct {
fieldtype_t type;
} spawn_field_t;
-void SP_item_health (edict_t *self);
-void SP_item_health_small (edict_t *self);
-void SP_item_health_large (edict_t *self);
-void SP_item_health_mega (edict_t *self);
-
-void SP_info_player_start (edict_t *ent);
-void SP_info_player_deathmatch (edict_t *ent);
-void SP_info_player_coop (edict_t *ent);
-void SP_info_player_intermission (edict_t *ent);
-
-void SP_func_plat (edict_t *ent);
-void SP_func_rotating (edict_t *ent);
-void SP_func_button (edict_t *ent);
-void SP_func_door (edict_t *ent);
-void SP_func_door_secret (edict_t *ent);
-void SP_func_door_rotating (edict_t *ent);
-void SP_func_water (edict_t *ent);
-void SP_func_train (edict_t *ent);
-void SP_func_conveyor (edict_t *self);
-void SP_func_wall (edict_t *self);
-void SP_func_object (edict_t *self);
-void SP_func_explosive (edict_t *self);
-void SP_func_timer (edict_t *self);
-void SP_func_areaportal (edict_t *ent);
-void SP_func_clock (edict_t *ent);
-void SP_func_killbox (edict_t *ent);
-
-void SP_trigger_always (edict_t *ent);
-void SP_trigger_once (edict_t *ent);
-void SP_trigger_multiple (edict_t *ent);
-void SP_trigger_relay (edict_t *ent);
-void SP_trigger_push (edict_t *ent);
-void SP_trigger_hurt (edict_t *ent);
-void SP_trigger_key (edict_t *ent);
-void SP_trigger_counter (edict_t *ent);
-void SP_trigger_elevator (edict_t *ent);
-void SP_trigger_gravity (edict_t *ent);
-void SP_trigger_monsterjump (edict_t *ent);
-
-void SP_target_temp_entity (edict_t *ent);
-void SP_target_speaker (edict_t *ent);
-void SP_target_explosion (edict_t *ent);
-void SP_target_changelevel (edict_t *ent);
-void SP_target_secret (edict_t *ent);
-void SP_target_goal (edict_t *ent);
-void SP_target_splash (edict_t *ent);
-void SP_target_spawner (edict_t *ent);
-void SP_target_blaster (edict_t *ent);
-void SP_target_crosslevel_trigger (edict_t *ent);
-void SP_target_crosslevel_target (edict_t *ent);
-void SP_target_laser (edict_t *self);
-void SP_target_help (edict_t *ent);
-void SP_target_actor (edict_t *ent);
-void SP_target_lightramp (edict_t *self);
-void SP_target_earthquake (edict_t *ent);
-void SP_target_character (edict_t *ent);
-void SP_target_string (edict_t *ent);
-
-void SP_worldspawn (edict_t *ent);
-void SP_viewthing (edict_t *ent);
-
-void SP_light (edict_t *self);
-void SP_light_mine1 (edict_t *ent);
-void SP_light_mine2 (edict_t *ent);
-void SP_info_null (edict_t *self);
-void SP_info_notnull (edict_t *self);
-void SP_path_corner (edict_t *self);
-void SP_point_combat (edict_t *self);
-
-void SP_misc_explobox (edict_t *self);
-void SP_misc_banner (edict_t *self);
-void SP_misc_satellite_dish (edict_t *self);
-void SP_misc_actor (edict_t *self);
-void SP_misc_gib_arm (edict_t *self);
-void SP_misc_gib_leg (edict_t *self);
-void SP_misc_gib_head (edict_t *self);
-void SP_misc_insane (edict_t *self);
-void SP_misc_deadsoldier (edict_t *self);
-void SP_misc_viper (edict_t *self);
-void SP_misc_viper_bomb (edict_t *self);
-void SP_misc_bigviper (edict_t *self);
-void SP_misc_strogg_ship (edict_t *self);
-void SP_misc_teleporter (edict_t *self);
-void SP_misc_teleporter_dest (edict_t *self);
-void SP_misc_blackhole (edict_t *self);
-void SP_misc_eastertank (edict_t *self);
-void SP_misc_easterchick (edict_t *self);
-void SP_misc_easterchick2 (edict_t *self);
-
-void SP_monster_berserk (edict_t *self);
-void SP_monster_gladiator (edict_t *self);
-void SP_monster_gunner (edict_t *self);
-void SP_monster_infantry (edict_t *self);
-void SP_monster_soldier_light (edict_t *self);
-void SP_monster_soldier (edict_t *self);
-void SP_monster_soldier_ss (edict_t *self);
-void SP_monster_tank (edict_t *self);
-void SP_monster_medic (edict_t *self);
-void SP_monster_flipper (edict_t *self);
-void SP_monster_chick (edict_t *self);
-void SP_monster_parasite (edict_t *self);
-void SP_monster_flyer (edict_t *self);
-void SP_monster_brain (edict_t *self);
-void SP_monster_floater (edict_t *self);
-void SP_monster_hover (edict_t *self);
-void SP_monster_mutant (edict_t *self);
-void SP_monster_supertank (edict_t *self);
-void SP_monster_boss2 (edict_t *self);
-void SP_monster_jorg (edict_t *self);
-void SP_monster_boss3_stand (edict_t *self);
-
-void SP_monster_commander_body (edict_t *self);
-
-void SP_turret_breach (edict_t *self);
-void SP_turret_base (edict_t *self);
-void SP_turret_driver (edict_t *self);
+void SP_item_health(edict_t *self);
+void SP_item_health_small(edict_t *self);
+void SP_item_health_large(edict_t *self);
+void SP_item_health_mega(edict_t *self);
+
+void SP_info_player_start(edict_t *ent);
+void SP_info_player_deathmatch(edict_t *ent);
+void SP_info_player_coop(edict_t *ent);
+void SP_info_player_intermission(edict_t *ent);
+
+void SP_func_plat(edict_t *ent);
+void SP_func_rotating(edict_t *ent);
+void SP_func_button(edict_t *ent);
+void SP_func_door(edict_t *ent);
+void SP_func_door_secret(edict_t *ent);
+void SP_func_door_rotating(edict_t *ent);
+void SP_func_water(edict_t *ent);
+void SP_func_train(edict_t *ent);
+void SP_func_conveyor(edict_t *self);
+void SP_func_wall(edict_t *self);
+void SP_func_object(edict_t *self);
+void SP_func_explosive(edict_t *self);
+void SP_func_timer(edict_t *self);
+void SP_func_areaportal(edict_t *ent);
+void SP_func_clock(edict_t *ent);
+void SP_func_killbox(edict_t *ent);
+
+void SP_trigger_always(edict_t *ent);
+void SP_trigger_once(edict_t *ent);
+void SP_trigger_multiple(edict_t *ent);
+void SP_trigger_relay(edict_t *ent);
+void SP_trigger_push(edict_t *ent);
+void SP_trigger_hurt(edict_t *ent);
+void SP_trigger_key(edict_t *ent);
+void SP_trigger_counter(edict_t *ent);
+void SP_trigger_elevator(edict_t *ent);
+void SP_trigger_gravity(edict_t *ent);
+void SP_trigger_monsterjump(edict_t *ent);
+
+void SP_target_temp_entity(edict_t *ent);
+void SP_target_speaker(edict_t *ent);
+void SP_target_explosion(edict_t *ent);
+void SP_target_changelevel(edict_t *ent);
+void SP_target_secret(edict_t *ent);
+void SP_target_goal(edict_t *ent);
+void SP_target_splash(edict_t *ent);
+void SP_target_spawner(edict_t *ent);
+void SP_target_blaster(edict_t *ent);
+void SP_target_crosslevel_trigger(edict_t *ent);
+void SP_target_crosslevel_target(edict_t *ent);
+void SP_target_laser(edict_t *self);
+void SP_target_help(edict_t *ent);
+void SP_target_actor(edict_t *ent);
+void SP_target_lightramp(edict_t *self);
+void SP_target_earthquake(edict_t *ent);
+void SP_target_character(edict_t *ent);
+void SP_target_string(edict_t *ent);
+
+void SP_worldspawn(edict_t *ent);
+void SP_viewthing(edict_t *ent);
+
+void SP_light(edict_t *self);
+void SP_light_mine1(edict_t *ent);
+void SP_light_mine2(edict_t *ent);
+void SP_info_null(edict_t *self);
+void SP_info_notnull(edict_t *self);
+void SP_path_corner(edict_t *self);
+void SP_point_combat(edict_t *self);
+
+void SP_misc_explobox(edict_t *self);
+void SP_misc_banner(edict_t *self);
+void SP_misc_satellite_dish(edict_t *self);
+void SP_misc_actor(edict_t *self);
+void SP_misc_gib_arm(edict_t *self);
+void SP_misc_gib_leg(edict_t *self);
+void SP_misc_gib_head(edict_t *self);
+void SP_misc_insane(edict_t *self);
+void SP_misc_deadsoldier(edict_t *self);
+void SP_misc_viper(edict_t *self);
+void SP_misc_viper_bomb(edict_t *self);
+void SP_misc_bigviper(edict_t *self);
+void SP_misc_strogg_ship(edict_t *self);
+void SP_misc_teleporter(edict_t *self);
+void SP_misc_teleporter_dest(edict_t *self);
+void SP_misc_blackhole(edict_t *self);
+void SP_misc_eastertank(edict_t *self);
+void SP_misc_easterchick(edict_t *self);
+void SP_misc_easterchick2(edict_t *self);
+
+void SP_monster_berserk(edict_t *self);
+void SP_monster_gladiator(edict_t *self);
+void SP_monster_gunner(edict_t *self);
+void SP_monster_infantry(edict_t *self);
+void SP_monster_soldier_light(edict_t *self);
+void SP_monster_soldier(edict_t *self);
+void SP_monster_soldier_ss(edict_t *self);
+void SP_monster_tank(edict_t *self);
+void SP_monster_medic(edict_t *self);
+void SP_monster_flipper(edict_t *self);
+void SP_monster_chick(edict_t *self);
+void SP_monster_parasite(edict_t *self);
+void SP_monster_flyer(edict_t *self);
+void SP_monster_brain(edict_t *self);
+void SP_monster_floater(edict_t *self);
+void SP_monster_hover(edict_t *self);
+void SP_monster_mutant(edict_t *self);
+void SP_monster_supertank(edict_t *self);
+void SP_monster_boss2(edict_t *self);
+void SP_monster_jorg(edict_t *self);
+void SP_monster_boss3_stand(edict_t *self);
+
+void SP_monster_commander_body(edict_t *self);
+
+void SP_turret_breach(edict_t *self);
+void SP_turret_base(edict_t *self);
+void SP_turret_driver(edict_t *self);
static const spawn_func_t spawn_funcs[] = {
{"item_health", SP_item_health},
@@ -338,40 +338,37 @@ ED_CallSpawn
Finds the spawn function for the entity and calls it
===============
*/
-void ED_CallSpawn (edict_t *ent)
+void ED_CallSpawn(edict_t *ent)
{
const spawn_func_t *s;
gitem_t *item;
int i;
- if (!ent->classname)
- {
- gi.dprintf ("ED_CallSpawn: NULL classname\n");
+ if (!ent->classname) {
+ gi.dprintf("ED_CallSpawn: NULL classname\n");
return;
}
// check item spawn functions
- for (i=0,item=itemlist ; i<game.num_items ; i++,item++)
- {
+ for (i = 0, item = itemlist ; i < game.num_items ; i++, item++) {
if (!item->classname)
continue;
- if (!strcmp(item->classname, ent->classname))
- { // found it
- SpawnItem (ent, item);
+ if (!strcmp(item->classname, ent->classname)) {
+ // found it
+ SpawnItem(ent, item);
return;
}
}
// check normal spawn functions
- for (s=spawn_funcs ; s->name ; s++)
- {
- if (!strcmp(s->name, ent->classname))
- { // found it
- s->spawn (ent);
+ for (s = spawn_funcs ; s->name ; s++) {
+ if (!strcmp(s->name, ent->classname)) {
+ // found it
+ s->spawn(ent);
return;
}
}
- gi.dprintf ("%s doesn't have a spawn function\n", ent->classname);
+ gi.dprintf("%s doesn't have a spawn function\n", ent->classname);
}
/*
@@ -379,31 +376,28 @@ void ED_CallSpawn (edict_t *ent)
ED_NewString
=============
*/
-static char *ED_NewString (const char *string)
+static char *ED_NewString(const char *string)
{
char *newb, *new_p;
- int i,l;
-
+ int i, l;
+
l = strlen(string) + 1;
- newb = gi.TagMalloc (l, TAG_LEVEL);
+ newb = gi.TagMalloc(l, TAG_LEVEL);
new_p = newb;
- for (i=0 ; i< l ; i++)
- {
- if (string[i] == '\\' && i < l-1)
- {
+ for (i = 0 ; i < l ; i++) {
+ if (string[i] == '\\' && i < l - 1) {
i++;
if (string[i] == 'n')
*new_p++ = '\n';
else
*new_p++ = '\\';
- }
- else
+ } else
*new_p++ = string[i];
}
-
+
return newb;
}
@@ -418,41 +412,39 @@ Takes a key/value pair and sets the binary values
in an edict
===============
*/
-static qboolean ED_ParseField (const spawn_field_t *fields, const char *key, const char *value, byte *b)
+static qboolean ED_ParseField(const spawn_field_t *fields, const char *key, const char *value, byte *b)
{
const spawn_field_t *f;
float v;
vec3_t vec;
- for (f=fields ; f->name ; f++)
- {
- if (!Q_stricmp(f->name, key))
- { // found it
- switch (f->type)
- {
+ for (f = fields ; f->name ; f++) {
+ if (!Q_stricmp(f->name, key)) {
+ // found it
+ switch (f->type) {
case F_LSTRING:
- *(char **)(b+f->ofs) = ED_NewString (value);
+ *(char **)(b + f->ofs) = ED_NewString(value);
break;
case F_VECTOR:
- if( sscanf (value, "%f %f %f", &vec[0], &vec[1], &vec[2]) != 3 ) {
- gi.dprintf( "%s: couldn't parse '%s'\n", __func__, key );
- VectorClear( vec );
+ if (sscanf(value, "%f %f %f", &vec[0], &vec[1], &vec[2]) != 3) {
+ gi.dprintf("%s: couldn't parse '%s'\n", __func__, key);
+ VectorClear(vec);
}
- ((float *)(b+f->ofs))[0] = vec[0];
- ((float *)(b+f->ofs))[1] = vec[1];
- ((float *)(b+f->ofs))[2] = vec[2];
+ ((float *)(b + f->ofs))[0] = vec[0];
+ ((float *)(b + f->ofs))[1] = vec[1];
+ ((float *)(b + f->ofs))[2] = vec[2];
break;
case F_INT:
- *(int *)(b+f->ofs) = atoi(value);
+ *(int *)(b + f->ofs) = atoi(value);
break;
case F_FLOAT:
- *(float *)(b+f->ofs) = atof(value);
+ *(float *)(b + f->ofs) = atof(value);
break;
case F_ANGLEHACK:
v = atof(value);
- ((float *)(b+f->ofs))[0] = 0;
- ((float *)(b+f->ofs))[1] = v;
- ((float *)(b+f->ofs))[2] = 0;
+ ((float *)(b + f->ofs))[0] = 0;
+ ((float *)(b + f->ofs))[1] = v;
+ ((float *)(b + f->ofs))[2] = 0;
break;
case F_IGNORE:
break;
@@ -473,48 +465,47 @@ Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
*/
-void ED_ParseEdict (const char **data, edict_t *ent)
+void ED_ParseEdict(const char **data, edict_t *ent)
{
qboolean init;
char *key, *value;
init = qfalse;
- memset (&st, 0, sizeof(st));
+ memset(&st, 0, sizeof(st));
// go through all the dictionary pairs
- while (1)
- {
- // parse key
- key = COM_Parse (data);
+ while (1) {
+ // parse key
+ key = COM_Parse(data);
if (key[0] == '}')
break;
if (!*data)
- gi.error ("%s: EOF without closing brace", __func__);
+ gi.error("%s: EOF without closing brace", __func__);
- // parse value
- value = COM_Parse (data);
+ // parse value
+ value = COM_Parse(data);
if (!*data)
- gi.error ("%s: EOF without closing brace", __func__);
+ gi.error("%s: EOF without closing brace", __func__);
if (value[0] == '}')
- gi.error ("%s: closing brace without data", __func__);
+ gi.error("%s: closing brace without data", __func__);
- init = qtrue;
+ init = qtrue;
- // keynames with a leading underscore are used for utility comments,
- // and are immediately discarded by quake
+ // keynames with a leading underscore are used for utility comments,
+ // and are immediately discarded by quake
if (key[0] == '_')
continue;
- if( !ED_ParseField( spawn_fields, key, value, ( byte * )ent ) ) {
- if( !ED_ParseField( temp_fields, key, value, ( byte * )&st ) ) {
- gi.dprintf ("%s: %s is not a field\n", __func__, key);
+ if (!ED_ParseField(spawn_fields, key, value, (byte *)ent)) {
+ if (!ED_ParseField(temp_fields, key, value, (byte *)&st)) {
+ gi.dprintf("%s: %s is not a field\n", __func__, key);
}
}
}
if (!init)
- memset (ent, 0, sizeof(*ent));
+ memset(ent, 0, sizeof(*ent));
}
@@ -528,7 +519,7 @@ All but the first will have the FL_TEAMSLAVE flag set.
All but the last will have the teamchain field set to the next one
================
*/
-void G_FindTeams (void)
+void G_FindTeams(void)
{
edict_t *e, *e2, *chain;
int i, j;
@@ -536,8 +527,7 @@ void G_FindTeams (void)
c = 0;
c2 = 0;
- for (i=1, e=g_edicts+i ; i < globals.num_edicts ; i++,e++)
- {
+ for (i = 1, e = g_edicts + i ; i < globals.num_edicts ; i++, e++) {
if (!e->inuse)
continue;
if (!e->team)
@@ -548,16 +538,14 @@ void G_FindTeams (void)
e->teammaster = e;
c++;
c2++;
- for (j=i+1, e2=e+1 ; j < globals.num_edicts ; j++,e2++)
- {
+ for (j = i + 1, e2 = e + 1 ; j < globals.num_edicts ; j++, e2++) {
if (!e2->inuse)
continue;
if (!e2->team)
continue;
if (e2->flags & FL_TEAMSLAVE)
continue;
- if (!strcmp(e->team, e2->team))
- {
+ if (!strcmp(e->team, e2->team)) {
c2++;
chain->teamchain = e2;
e2->teammaster = e;
@@ -567,7 +555,7 @@ void G_FindTeams (void)
}
}
- gi.dprintf ("%i teams with %i entities\n", c, c2);
+ gi.dprintf("%i teams with %i entities\n", c, c2);
}
/*
@@ -578,7 +566,7 @@ Creates a server's entity / program execution context by
parsing textual entity definitions out of an ent file.
==============
*/
-void SpawnEntities (const char *mapname, const char *entities, const char *spawnpoint)
+void SpawnEntities(const char *mapname, const char *entities, const char *spawnpoint)
{
edict_t *ent;
int inhibit;
@@ -586,7 +574,7 @@ void SpawnEntities (const char *mapname, const char *entities, const char *spawn
int i;
float skill_level;
- skill_level = floor (skill->value);
+ skill_level = floor(skill->value);
if (skill_level < 0)
skill_level = 0;
if (skill_level > 3)
@@ -594,76 +582,69 @@ void SpawnEntities (const char *mapname, const char *entities, const char *spawn
if (skill->value != skill_level)
gi.cvar_forceset("skill", va("%f", skill_level));
- SaveClientData ();
+ SaveClientData();
- gi.FreeTags (TAG_LEVEL);
+ gi.FreeTags(TAG_LEVEL);
- memset (&level, 0, sizeof(level));
- memset (g_edicts, 0, game.maxentities * sizeof (g_edicts[0]));
+ memset(&level, 0, sizeof(level));
+ memset(g_edicts, 0, game.maxentities * sizeof(g_edicts[0]));
- strncpy (level.mapname, mapname, sizeof(level.mapname)-1);
- strncpy (game.spawnpoint, spawnpoint, sizeof(game.spawnpoint)-1);
+ strncpy(level.mapname, mapname, sizeof(level.mapname) - 1);
+ strncpy(game.spawnpoint, spawnpoint, sizeof(game.spawnpoint) - 1);
// set client fields on player ents
- for (i=0 ; i<game.maxclients ; i++)
- g_edicts[i+1].client = game.clients + i;
+ for (i = 0 ; i < game.maxclients ; i++)
+ g_edicts[i + 1].client = game.clients + i;
ent = NULL;
inhibit = 0;
// parse ents
- while (1)
- {
- // parse the opening brace
- com_token = COM_Parse (&entities);
+ while (1) {
+ // parse the opening brace
+ com_token = COM_Parse(&entities);
if (!entities)
break;
if (com_token[0] != '{')
- gi.error ("ED_LoadFromFile: found %s when expecting {",com_token);
+ gi.error("ED_LoadFromFile: found %s when expecting {", com_token);
if (!ent)
ent = g_edicts;
else
- ent = G_Spawn ();
- ED_ParseEdict (&entities, ent);
+ ent = G_Spawn();
+ ED_ParseEdict(&entities, ent);
// yet another map hack
if (!Q_stricmp(level.mapname, "command") && !Q_stricmp(ent->classname, "trigger_once") && !Q_stricmp(ent->model, "*27"))
ent->spawnflags &= ~SPAWNFLAG_NOT_HARD;
// remove things (except the world) from different skill levels or deathmatch
- if (ent != g_edicts)
- {
- if (deathmatch->value)
- {
- if ( ent->spawnflags & SPAWNFLAG_NOT_DEATHMATCH )
- {
- G_FreeEdict (ent);
+ if (ent != g_edicts) {
+ if (deathmatch->value) {
+ if (ent->spawnflags & SPAWNFLAG_NOT_DEATHMATCH) {
+ G_FreeEdict(ent);
inhibit++;
continue;
}
- }
- else
- {
+ } else {
if ( /* ((coop->value) && (ent->spawnflags & SPAWNFLAG_NOT_COOP)) || */
((skill->value == 0) && (ent->spawnflags & SPAWNFLAG_NOT_EASY)) ||
((skill->value == 1) && (ent->spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
(((skill->value == 2) || (skill->value == 3)) && (ent->spawnflags & SPAWNFLAG_NOT_HARD))
- )
- {
- G_FreeEdict (ent);
- inhibit++;
- continue;
- }
+ ) {
+ G_FreeEdict(ent);
+ inhibit++;
+ continue;
+ }
}
- ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY|SPAWNFLAG_NOT_MEDIUM|SPAWNFLAG_NOT_HARD|SPAWNFLAG_NOT_COOP|SPAWNFLAG_NOT_DEATHMATCH);
+ ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY | SPAWNFLAG_NOT_MEDIUM | SPAWNFLAG_NOT_HARD | SPAWNFLAG_NOT_COOP | SPAWNFLAG_NOT_DEATHMATCH);
}
- ED_CallSpawn (ent);
- }
+ ED_CallSpawn(ent);
+ }
- gi.dprintf ("%i entities inhibited\n", inhibit);
+ gi.dprintf("%i entities inhibited\n", inhibit);
#ifdef DEBUG
i = 1;
@@ -675,38 +656,38 @@ void SpawnEntities (const char *mapname, const char *entities, const char *spawn
}
#endif
- G_FindTeams ();
+ G_FindTeams();
- PlayerTrail_Init ();
+ PlayerTrail_Init();
}
//===================================================================
#if 0
- // cursor positioning
- xl <value>
- xr <value>
- yb <value>
- yt <value>
- xv <value>
- yv <value>
-
- // drawing
- statpic <name>
- pic <stat>
- num <fieldwidth> <stat>
- string <stat>
-
- // control
- if <stat>
- ifeq <stat> <value>
- ifbit <stat> <value>
- endif
+// cursor positioning
+xl <value>
+xr <value>
+yb <value>
+yt <value>
+xv <value>
+yv <value>
+
+// drawing
+statpic <name>
+pic <stat>
+num <fieldwidth> <stat>
+string <stat>
+
+// control
+if <stat>
+ifeq <stat> <value>
+ifbit <stat> <value>
+endif
#endif
-static const char single_statusbar[] =
+static const char single_statusbar[] =
"yb -24 "
// health
@@ -757,7 +738,7 @@ static const char single_statusbar[] =
" pic 9 "
"endif "
-// help / weapon icon
+// help / weapon icon
"if 11 "
" xv 148 "
" pic 11 "
@@ -815,7 +796,7 @@ static const char dm_statusbar[] =
" pic 9 "
"endif "
-// help / weapon icon
+// help / weapon icon
"if 11 "
" xv 148 "
" pic 11 "
@@ -828,18 +809,18 @@ static const char dm_statusbar[] =
// spectator
"if 17 "
- "xv 0 "
- "yb -58 "
- "string2 \"SPECTATOR MODE\" "
+"xv 0 "
+"yb -58 "
+"string2 \"SPECTATOR MODE\" "
"endif "
// chase camera
"if 16 "
- "xv 0 "
- "yb -68 "
- "string \"Chasing\" "
- "xv 64 "
- "stat_string 16 "
+"xv 0 "
+"yb -68 "
+"string \"Chasing\" "
+"xv 64 "
+"stat_string 16 "
"endif "
;
@@ -854,7 +835,7 @@ Only used for the world.
"gravity" 800 is default gravity
"message" text to print at user logon
*/
-void SP_worldspawn (edict_t *ent)
+void SP_worldspawn(edict_t *ent)
{
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
@@ -864,182 +845,180 @@ void SP_worldspawn (edict_t *ent)
//---------------
// reserve some spots for dead player bodies for coop / deathmatch
- InitBodyQue ();
+ InitBodyQue();
// set configstrings for items
- SetItemNames ();
+ SetItemNames();
if (st.nextmap)
- strcpy (level.nextmap, st.nextmap);
+ strcpy(level.nextmap, st.nextmap);
// make some data visible to the server
- if (ent->message && ent->message[0])
- {
- gi.configstring (CS_NAME, ent->message);
- strncpy (level.level_name, ent->message, sizeof(level.level_name));
- }
- else
- strncpy (level.level_name, level.mapname, sizeof(level.level_name));
+ if (ent->message && ent->message[0]) {
+ gi.configstring(CS_NAME, ent->message);
+ strncpy(level.level_name, ent->message, sizeof(level.level_name));
+ } else
+ strncpy(level.level_name, level.mapname, sizeof(level.level_name));
if (st.sky && st.sky[0])
- gi.configstring (CS_SKY, st.sky);
+ gi.configstring(CS_SKY, st.sky);
else
- gi.configstring (CS_SKY, "unit1_");
+ gi.configstring(CS_SKY, "unit1_");
- gi.configstring (CS_SKYROTATE, va("%f", st.skyrotate) );
+ gi.configstring(CS_SKYROTATE, va("%f", st.skyrotate));
- gi.configstring (CS_SKYAXIS, va("%f %f %f",
- st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]) );
+ gi.configstring(CS_SKYAXIS, va("%f %f %f",
+ st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]));
- gi.configstring (CS_CDTRACK, va("%i", ent->sounds) );
+ gi.configstring(CS_CDTRACK, va("%i", ent->sounds));
- gi.configstring (CS_MAXCLIENTS, va("%i", (int)(maxclients->value) ) );
+ gi.configstring(CS_MAXCLIENTS, va("%i", (int)(maxclients->value)));
// status bar program
if (deathmatch->value)
- gi.configstring (CS_STATUSBAR, dm_statusbar);
+ gi.configstring(CS_STATUSBAR, dm_statusbar);
else
- gi.configstring (CS_STATUSBAR, single_statusbar);
+ gi.configstring(CS_STATUSBAR, single_statusbar);
//---------------
// help icon for statusbar
- gi.imageindex ("i_help");
- level.pic_health = gi.imageindex ("i_health");
- gi.imageindex ("help");
- gi.imageindex ("field_3");
+ gi.imageindex("i_help");
+ level.pic_health = gi.imageindex("i_health");
+ gi.imageindex("help");
+ gi.imageindex("field_3");
if (!st.gravity)
gi.cvar_set("sv_gravity", "800");
else
gi.cvar_set("sv_gravity", st.gravity);
- snd_fry = gi.soundindex ("player/fry.wav"); // standing in lava / slime
+ snd_fry = gi.soundindex("player/fry.wav"); // standing in lava / slime
- PrecacheItem (FindItem ("Blaster"));
+ PrecacheItem(FindItem("Blaster"));
- gi.soundindex ("player/lava1.wav");
- gi.soundindex ("player/lava2.wav");
+ gi.soundindex("player/lava1.wav");
+ gi.soundindex("player/lava2.wav");
- gi.soundindex ("misc/pc_up.wav");
- gi.soundindex ("misc/talk1.wav");
+ gi.soundindex("misc/pc_up.wav");
+ gi.soundindex("misc/talk1.wav");
- gi.soundindex ("misc/udeath.wav");
+ gi.soundindex("misc/udeath.wav");
// gibs
- gi.soundindex ("items/respawn1.wav");
+ gi.soundindex("items/respawn1.wav");
// sexed sounds
- gi.soundindex ("*death1.wav");
- gi.soundindex ("*death2.wav");
- gi.soundindex ("*death3.wav");
- gi.soundindex ("*death4.wav");
- gi.soundindex ("*fall1.wav");
- gi.soundindex ("*fall2.wav");
- gi.soundindex ("*gurp1.wav"); // drowning damage
- gi.soundindex ("*gurp2.wav");
- gi.soundindex ("*jump1.wav"); // player jump
- gi.soundindex ("*pain25_1.wav");
- gi.soundindex ("*pain25_2.wav");
- gi.soundindex ("*pain50_1.wav");
- gi.soundindex ("*pain50_2.wav");
- gi.soundindex ("*pain75_1.wav");
- gi.soundindex ("*pain75_2.wav");
- gi.soundindex ("*pain100_1.wav");
- gi.soundindex ("*pain100_2.wav");
+ gi.soundindex("*death1.wav");
+ gi.soundindex("*death2.wav");
+ gi.soundindex("*death3.wav");
+ gi.soundindex("*death4.wav");
+ gi.soundindex("*fall1.wav");
+ gi.soundindex("*fall2.wav");
+ gi.soundindex("*gurp1.wav"); // drowning damage
+ gi.soundindex("*gurp2.wav");
+ gi.soundindex("*jump1.wav"); // player jump
+ gi.soundindex("*pain25_1.wav");
+ gi.soundindex("*pain25_2.wav");
+ gi.soundindex("*pain50_1.wav");
+ gi.soundindex("*pain50_2.wav");
+ gi.soundindex("*pain75_1.wav");
+ gi.soundindex("*pain75_2.wav");
+ gi.soundindex("*pain100_1.wav");
+ gi.soundindex("*pain100_2.wav");
// sexed models
// THIS ORDER MUST MATCH THE DEFINES IN g_local.h
// you can add more, max 15
- gi.modelindex ("#w_blaster.md2");
- gi.modelindex ("#w_shotgun.md2");
- gi.modelindex ("#w_sshotgun.md2");
- gi.modelindex ("#w_machinegun.md2");
- gi.modelindex ("#w_chaingun.md2");
- gi.modelindex ("#a_grenades.md2");
- gi.modelindex ("#w_glauncher.md2");
- gi.modelindex ("#w_rlauncher.md2");
- gi.modelindex ("#w_hyperblaster.md2");
- gi.modelindex ("#w_railgun.md2");
- gi.modelindex ("#w_bfg.md2");
+ gi.modelindex("#w_blaster.md2");
+ gi.modelindex("#w_shotgun.md2");
+ gi.modelindex("#w_sshotgun.md2");
+ gi.modelindex("#w_machinegun.md2");
+ gi.modelindex("#w_chaingun.md2");
+ gi.modelindex("#a_grenades.md2");
+ gi.modelindex("#w_glauncher.md2");
+ gi.modelindex("#w_rlauncher.md2");
+ gi.modelindex("#w_hyperblaster.md2");
+ gi.modelindex("#w_railgun.md2");
+ gi.modelindex("#w_bfg.md2");
//-------------------
- gi.soundindex ("player/gasp1.wav"); // gasping for air
- gi.soundindex ("player/gasp2.wav"); // head breaking surface, not gasping
+ gi.soundindex("player/gasp1.wav"); // gasping for air
+ gi.soundindex("player/gasp2.wav"); // head breaking surface, not gasping
+
+ gi.soundindex("player/watr_in.wav"); // feet hitting water
+ gi.soundindex("player/watr_out.wav"); // feet leaving water
- gi.soundindex ("player/watr_in.wav"); // feet hitting water
- gi.soundindex ("player/watr_out.wav"); // feet leaving water
+ gi.soundindex("player/watr_un.wav"); // head going underwater
- gi.soundindex ("player/watr_un.wav"); // head going underwater
-
- gi.soundindex ("player/u_breath1.wav");
- gi.soundindex ("player/u_breath2.wav");
+ gi.soundindex("player/u_breath1.wav");
+ gi.soundindex("player/u_breath2.wav");
- gi.soundindex ("items/pkup.wav"); // bonus item pickup
- gi.soundindex ("world/land.wav"); // landing thud
- gi.soundindex ("misc/h2ohit1.wav"); // landing splash
+ gi.soundindex("items/pkup.wav"); // bonus item pickup
+ gi.soundindex("world/land.wav"); // landing thud
+ gi.soundindex("misc/h2ohit1.wav"); // landing splash
- gi.soundindex ("items/damage.wav");
- gi.soundindex ("items/protect.wav");
- gi.soundindex ("items/protect4.wav");
- gi.soundindex ("weapons/noammo.wav");
+ gi.soundindex("items/damage.wav");
+ gi.soundindex("items/protect.wav");
+ gi.soundindex("items/protect4.wav");
+ gi.soundindex("weapons/noammo.wav");
- gi.soundindex ("infantry/inflies1.wav");
+ gi.soundindex("infantry/inflies1.wav");
- sm_meat_index = gi.modelindex ("models/objects/gibs/sm_meat/tris.md2");
- gi.modelindex ("models/objects/gibs/arm/tris.md2");
- gi.modelindex ("models/objects/gibs/bone/tris.md2");
- gi.modelindex ("models/objects/gibs/bone2/tris.md2");
- gi.modelindex ("models/objects/gibs/chest/tris.md2");
- gi.modelindex ("models/objects/gibs/skull/tris.md2");
- gi.modelindex ("models/objects/gibs/head2/tris.md2");
+ sm_meat_index = gi.modelindex("models/objects/gibs/sm_meat/tris.md2");
+ gi.modelindex("models/objects/gibs/arm/tris.md2");
+ gi.modelindex("models/objects/gibs/bone/tris.md2");
+ gi.modelindex("models/objects/gibs/bone2/tris.md2");
+ gi.modelindex("models/objects/gibs/chest/tris.md2");
+ gi.modelindex("models/objects/gibs/skull/tris.md2");
+ gi.modelindex("models/objects/gibs/head2/tris.md2");
//
// Setup light animation tables. 'a' is total darkness, 'z' is doublebright.
//
// 0 normal
- gi.configstring(CS_LIGHTS+0, "m");
-
+ gi.configstring(CS_LIGHTS + 0, "m");
+
// 1 FLICKER (first variety)
- gi.configstring(CS_LIGHTS+1, "mmnmmommommnonmmonqnmmo");
-
+ gi.configstring(CS_LIGHTS + 1, "mmnmmommommnonmmonqnmmo");
+
// 2 SLOW STRONG PULSE
- gi.configstring(CS_LIGHTS+2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
-
+ gi.configstring(CS_LIGHTS + 2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
+
// 3 CANDLE (first variety)
- gi.configstring(CS_LIGHTS+3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
-
+ gi.configstring(CS_LIGHTS + 3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
+
// 4 FAST STROBE
- gi.configstring(CS_LIGHTS+4, "mamamamamama");
-
+ gi.configstring(CS_LIGHTS + 4, "mamamamamama");
+
// 5 GENTLE PULSE 1
- gi.configstring(CS_LIGHTS+5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
-
+ gi.configstring(CS_LIGHTS + 5, "jklmnopqrstuvwxyzyxwvutsrqponmlkj");
+
// 6 FLICKER (second variety)
- gi.configstring(CS_LIGHTS+6, "nmonqnmomnmomomno");
-
+ gi.configstring(CS_LIGHTS + 6, "nmonqnmomnmomomno");
+
// 7 CANDLE (second variety)
- gi.configstring(CS_LIGHTS+7, "mmmaaaabcdefgmmmmaaaammmaamm");
-
+ gi.configstring(CS_LIGHTS + 7, "mmmaaaabcdefgmmmmaaaammmaamm");
+
// 8 CANDLE (third variety)
- gi.configstring(CS_LIGHTS+8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
-
+ gi.configstring(CS_LIGHTS + 8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
+
// 9 SLOW STROBE (fourth variety)
- gi.configstring(CS_LIGHTS+9, "aaaaaaaazzzzzzzz");
-
+ gi.configstring(CS_LIGHTS + 9, "aaaaaaaazzzzzzzz");
+
// 10 FLUORESCENT FLICKER
- gi.configstring(CS_LIGHTS+10, "mmamammmmammamamaaamammma");
+ gi.configstring(CS_LIGHTS + 10, "mmamammmmammamamaaamammma");
// 11 SLOW PULSE NOT FADE TO BLACK
- gi.configstring(CS_LIGHTS+11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
-
+ gi.configstring(CS_LIGHTS + 11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
+
// styles 32-62 are assigned by the light program for switchable lights
// 63 testing
- gi.configstring(CS_LIGHTS+63, "a");
+ gi.configstring(CS_LIGHTS + 63, "a");
}
diff --git a/src/baseq2/g_svcmds.c b/src/baseq2/g_svcmds.c
index 7b87ced..f259593 100644
--- a/src/baseq2/g_svcmds.c
+++ b/src/baseq2/g_svcmds.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,16 +21,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
-void Svcmd_Test_f (void)
+void Svcmd_Test_f(void)
{
- gi.cprintf (NULL, PRINT_HIGH, "Svcmd_Test_f()\n");
+ gi.cprintf(NULL, PRINT_HIGH, "Svcmd_Test_f()\n");
}
/*
==============================================================================
PACKET FILTERING
-
+
You can add or remove addresses from the filter list with:
@@ -57,8 +57,7 @@ If 0, then only addresses matching the list will be allowed. This lets you easi
==============================================================================
*/
-typedef struct
-{
+typedef struct {
unsigned mask;
unsigned compare;
} ipfilter_t;
@@ -73,30 +72,26 @@ int numipfilters;
StringToFilter
=================
*/
-static qboolean StringToFilter (char *s, ipfilter_t *f)
+static qboolean StringToFilter(char *s, ipfilter_t *f)
{
char num[128];
int i, j;
byte b[4];
byte m[4];
-
- for (i=0 ; i<4 ; i++)
- {
+
+ for (i = 0 ; i < 4 ; i++) {
b[i] = 0;
m[i] = 0;
}
-
- for (i=0 ; i<4 ; i++)
- {
- if (*s < '0' || *s > '9')
- {
+
+ for (i = 0 ; i < 4 ; i++) {
+ if (*s < '0' || *s > '9') {
gi.cprintf(NULL, PRINT_HIGH, "Bad filter address: %s\n", s);
return qfalse;
}
-
+
j = 0;
- while (*s >= '0' && *s <= '9')
- {
+ while (*s >= '0' && *s <= '9') {
num[j++] = *s++;
}
num[j] = 0;
@@ -108,10 +103,10 @@ static qboolean StringToFilter (char *s, ipfilter_t *f)
break;
s++;
}
-
+
f->mask = *(unsigned *)m;
f->compare = *(unsigned *)b;
-
+
return qtrue;
}
@@ -120,7 +115,7 @@ static qboolean StringToFilter (char *s, ipfilter_t *f)
SV_FilterPacket
=================
*/
-qboolean SV_FilterPacket (char *from)
+qboolean SV_FilterPacket(char *from)
{
int i;
unsigned in;
@@ -132,18 +127,18 @@ qboolean SV_FilterPacket (char *from)
while (*p && i < 4) {
m[i] = 0;
while (*p >= '0' && *p <= '9') {
- m[i] = m[i]*10 + (*p - '0');
+ m[i] = m[i] * 10 + (*p - '0');
p++;
}
if (!*p || *p == ':')
break;
i++, p++;
}
-
+
in = *(unsigned *)m;
- for (i=0 ; i<numipfilters ; i++)
- if ( (in & ipfilters[i].mask) == ipfilters[i].compare)
+ for (i = 0 ; i < numipfilters ; i++)
+ if ((in & ipfilters[i].mask) == ipfilters[i].compare)
return (int)filterban->value;
return (int)!filterban->value;
@@ -155,29 +150,27 @@ qboolean SV_FilterPacket (char *from)
SV_AddIP_f
=================
*/
-void SVCmd_AddIP_f (void)
+void SVCmd_AddIP_f(void)
{
int i;
-
+
if (gi.argc() < 3) {
gi.cprintf(NULL, PRINT_HIGH, "Usage: addip <ip-mask>\n");
return;
}
- for (i=0 ; i<numipfilters ; i++)
+ for (i = 0 ; i < numipfilters ; i++)
if (ipfilters[i].compare == 0xffffffff)
break; // free spot
- if (i == numipfilters)
- {
- if (numipfilters == MAX_IPFILTERS)
- {
- gi.cprintf (NULL, PRINT_HIGH, "IP filter list is full\n");
+ if (i == numipfilters) {
+ if (numipfilters == MAX_IPFILTERS) {
+ gi.cprintf(NULL, PRINT_HIGH, "IP filter list is full\n");
return;
}
numipfilters++;
}
-
- if (!StringToFilter (gi.argv(2), &ipfilters[i]))
+
+ if (!StringToFilter(gi.argv(2), &ipfilters[i]))
ipfilters[i].compare = 0xffffffff;
}
@@ -186,7 +179,7 @@ void SVCmd_AddIP_f (void)
SV_RemoveIP_f
=================
*/
-void SVCmd_RemoveIP_f (void)
+void SVCmd_RemoveIP_f(void)
{
ipfilter_t f;
int i, j;
@@ -196,20 +189,19 @@ void SVCmd_RemoveIP_f (void)
return;
}
- if (!StringToFilter (gi.argv(2), &f))
+ if (!StringToFilter(gi.argv(2), &f))
return;
- for (i=0 ; i<numipfilters ; i++)
+ for (i = 0 ; i < numipfilters ; i++)
if (ipfilters[i].mask == f.mask
- && ipfilters[i].compare == f.compare)
- {
- for (j=i+1 ; j<numipfilters ; j++)
- ipfilters[j-1] = ipfilters[j];
+ && ipfilters[i].compare == f.compare) {
+ for (j = i + 1 ; j < numipfilters ; j++)
+ ipfilters[j - 1] = ipfilters[j];
numipfilters--;
- gi.cprintf (NULL, PRINT_HIGH, "Removed.\n");
+ gi.cprintf(NULL, PRINT_HIGH, "Removed.\n");
return;
}
- gi.cprintf (NULL, PRINT_HIGH, "Didn't find %s.\n", gi.argv(2));
+ gi.cprintf(NULL, PRINT_HIGH, "Didn't find %s.\n", gi.argv(2));
}
/*
@@ -217,16 +209,15 @@ void SVCmd_RemoveIP_f (void)
SV_ListIP_f
=================
*/
-void SVCmd_ListIP_f (void)
+void SVCmd_ListIP_f(void)
{
int i;
byte b[4];
- gi.cprintf (NULL, PRINT_HIGH, "Filter list:\n");
- for (i=0 ; i<numipfilters ; i++)
- {
+ gi.cprintf(NULL, PRINT_HIGH, "Filter list:\n");
+ for (i = 0 ; i < numipfilters ; i++) {
*(unsigned *)b = ipfilters[i].compare;
- gi.cprintf (NULL, PRINT_HIGH, "%3i.%3i.%3i.%3i\n", b[0], b[1], b[2], b[3]);
+ gi.cprintf(NULL, PRINT_HIGH, "%3i.%3i.%3i.%3i\n", b[0], b[1], b[2], b[3]);
}
}
@@ -235,7 +226,7 @@ void SVCmd_ListIP_f (void)
SV_WriteIP_f
=================
*/
-void SVCmd_WriteIP_f (void)
+void SVCmd_WriteIP_f(void)
{
FILE *f;
char name[MAX_OSPATH];
@@ -246,28 +237,26 @@ void SVCmd_WriteIP_f (void)
game = gi.cvar("game", "", 0);
if (!*game->string)
- sprintf (name, "%s/listip.cfg", GAMEVERSION);
+ sprintf(name, "%s/listip.cfg", GAMEVERSION);
else
- sprintf (name, "%s/listip.cfg", game->string);
+ sprintf(name, "%s/listip.cfg", game->string);
- gi.cprintf (NULL, PRINT_HIGH, "Writing %s.\n", name);
+ gi.cprintf(NULL, PRINT_HIGH, "Writing %s.\n", name);
- f = fopen (name, "wb");
- if (!f)
- {
- gi.cprintf (NULL, PRINT_HIGH, "Couldn't open %s\n", name);
+ f = fopen(name, "wb");
+ if (!f) {
+ gi.cprintf(NULL, PRINT_HIGH, "Couldn't open %s\n", name);
return;
}
-
+
fprintf(f, "set filterban %d\n", (int)filterban->value);
- for (i=0 ; i<numipfilters ; i++)
- {
+ for (i = 0 ; i < numipfilters ; i++) {
*(unsigned *)b = ipfilters[i].compare;
- fprintf (f, "sv addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
+ fprintf(f, "sv addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
}
-
- fclose (f);
+
+ fclose(f);
}
/*
@@ -279,22 +268,22 @@ The game can issue gi.argc() / gi.argv() commands to get the rest
of the parameters
=================
*/
-void ServerCommand (void)
+void ServerCommand(void)
{
char *cmd;
cmd = gi.argv(1);
- if (Q_stricmp (cmd, "test") == 0)
- Svcmd_Test_f ();
- else if (Q_stricmp (cmd, "addip") == 0)
- SVCmd_AddIP_f ();
- else if (Q_stricmp (cmd, "removeip") == 0)
- SVCmd_RemoveIP_f ();
- else if (Q_stricmp (cmd, "listip") == 0)
- SVCmd_ListIP_f ();
- else if (Q_stricmp (cmd, "writeip") == 0)
- SVCmd_WriteIP_f ();
+ if (Q_stricmp(cmd, "test") == 0)
+ Svcmd_Test_f();
+ else if (Q_stricmp(cmd, "addip") == 0)
+ SVCmd_AddIP_f();
+ else if (Q_stricmp(cmd, "removeip") == 0)
+ SVCmd_RemoveIP_f();
+ else if (Q_stricmp(cmd, "listip") == 0)
+ SVCmd_ListIP_f();
+ else if (Q_stricmp(cmd, "writeip") == 0)
+ SVCmd_WriteIP_f();
else
- gi.cprintf (NULL, PRINT_HIGH, "Unknown server command \"%s\"\n", cmd);
+ gi.cprintf(NULL, PRINT_HIGH, "Unknown server command \"%s\"\n", cmd);
}
diff --git a/src/baseq2/g_target.c b/src/baseq2/g_target.c
index 03a2264..1c960f8 100644
--- a/src/baseq2/g_target.c
+++ b/src/baseq2/g_target.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,15 +23,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Fire an origin based temp entity event to the clients.
"style" type byte
*/
-void Use_Target_Tent (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Target_Tent(edict_t *ent, edict_t *other, edict_t *activator)
{
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (ent->style);
- gi.WritePosition (ent->s.origin);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(ent->style);
+ gi.WritePosition(ent->s.origin);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
}
-void SP_target_temp_entity (edict_t *ent)
+void SP_target_temp_entity(edict_t *ent)
{
ent->use = Use_Target_Tent;
}
@@ -55,43 +55,41 @@ Normal sounds play each time the target is used. The reliable flag can be set f
Looped sounds are always atten 3 / vol 1, and the use function toggles it on/off.
Multiple identical looping sounds will just increase volume without any speed cost.
*/
-void Use_Target_Speaker (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Target_Speaker(edict_t *ent, edict_t *other, edict_t *activator)
{
int chan;
- if (ent->spawnflags & 3)
- { // looping sound toggles
+ if (ent->spawnflags & 3) {
+ // looping sound toggles
if (ent->s.sound)
ent->s.sound = 0; // turn it off
else
ent->s.sound = ent->noise_index; // start it
- }
- else
- { // normal sound
+ } else {
+ // normal sound
if (ent->spawnflags & 4)
- chan = CHAN_VOICE|CHAN_RELIABLE;
+ chan = CHAN_VOICE | CHAN_RELIABLE;
else
chan = CHAN_VOICE;
// use a positioned_sound, because this entity won't normally be
// sent to any clients because it is invisible
- gi.positioned_sound (ent->s.origin, ent, chan, ent->noise_index, ent->volume, ent->attenuation, 0);
+ gi.positioned_sound(ent->s.origin, ent, chan, ent->noise_index, ent->volume, ent->attenuation, 0);
}
}
-void SP_target_speaker (edict_t *ent)
+void SP_target_speaker(edict_t *ent)
{
char buffer[MAX_QPATH];
- if(!st.noise)
- {
+ if (!st.noise) {
gi.dprintf("target_speaker with no noise set at %s\n", vtos(ent->s.origin));
return;
}
- if (!strstr (st.noise, ".wav"))
- Q_snprintf (buffer, sizeof(buffer), "%s.wav", st.noise);
+ if (!strstr(st.noise, ".wav"))
+ Q_snprintf(buffer, sizeof(buffer), "%s.wav", st.noise);
else
- strncpy (buffer, st.noise, sizeof(buffer));
- ent->noise_index = gi.soundindex (buffer);
+ strncpy(buffer, st.noise, sizeof(buffer));
+ ent->noise_index = gi.soundindex(buffer);
if (!ent->volume)
ent->volume = 1.0;
@@ -109,18 +107,18 @@ void SP_target_speaker (edict_t *ent)
// must link the entity so we get areas and clusters so
// the server can determine who to send updates to
- gi.linkentity (ent);
+ gi.linkentity(ent);
}
//==========================================================
-void Use_Target_Help (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Target_Help(edict_t *ent, edict_t *other, edict_t *activator)
{
if (ent->spawnflags & 1)
- strncpy (game.helpmessage1, ent->message, sizeof(game.helpmessage2)-1);
+ strncpy(game.helpmessage1, ent->message, sizeof(game.helpmessage2) - 1);
else
- strncpy (game.helpmessage2, ent->message, sizeof(game.helpmessage1)-1);
+ strncpy(game.helpmessage2, ent->message, sizeof(game.helpmessage1) - 1);
game.helpchanged++;
}
@@ -130,16 +128,15 @@ When fired, the "message" key becomes the current personal computer string, and
*/
void SP_target_help(edict_t *ent)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (ent);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(ent);
return;
}
- if (!ent->message)
- {
- gi.dprintf ("%s with no message at %s\n", ent->classname, vtos(ent->s.origin));
- G_FreeEdict (ent);
+ if (!ent->message) {
+ gi.dprintf("%s with no message at %s\n", ent->classname, vtos(ent->s.origin));
+ G_FreeEdict(ent);
return;
}
ent->use = Use_Target_Help;
@@ -151,28 +148,28 @@ void SP_target_help(edict_t *ent)
Counts a secret found.
These are single use targets.
*/
-void use_target_secret (edict_t *ent, edict_t *other, edict_t *activator)
+void use_target_secret(edict_t *ent, edict_t *other, edict_t *activator)
{
- gi.sound (ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
level.found_secrets++;
- G_UseTargets (ent, activator);
- G_FreeEdict (ent);
+ G_UseTargets(ent, activator);
+ G_FreeEdict(ent);
}
-void SP_target_secret (edict_t *ent)
+void SP_target_secret(edict_t *ent)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (ent);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(ent);
return;
}
ent->use = use_target_secret;
if (!st.noise)
st.noise = "misc/secret.wav";
- ent->noise_index = gi.soundindex (st.noise);
+ ent->noise_index = gi.soundindex(st.noise);
ent->svflags = SVF_NOCLIENT;
level.total_secrets++;
// map bug hack
@@ -186,31 +183,31 @@ void SP_target_secret (edict_t *ent)
Counts a goal completed.
These are single use targets.
*/
-void use_target_goal (edict_t *ent, edict_t *other, edict_t *activator)
+void use_target_goal(edict_t *ent, edict_t *other, edict_t *activator)
{
- gi.sound (ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
level.found_goals++;
if (level.found_goals == level.total_goals)
- gi.configstring (CS_CDTRACK, "0");
+ gi.configstring(CS_CDTRACK, "0");
- G_UseTargets (ent, activator);
- G_FreeEdict (ent);
+ G_UseTargets(ent, activator);
+ G_FreeEdict(ent);
}
-void SP_target_goal (edict_t *ent)
+void SP_target_goal(edict_t *ent)
{
- if (deathmatch->value)
- { // auto-remove for deathmatch
- G_FreeEdict (ent);
+ if (deathmatch->value) {
+ // auto-remove for deathmatch
+ G_FreeEdict(ent);
return;
}
ent->use = use_target_goal;
if (!st.noise)
st.noise = "misc/secret.wav";
- ent->noise_index = gi.soundindex (st.noise);
+ ent->noise_index = gi.soundindex(st.noise);
ent->svflags = SVF_NOCLIENT;
level.total_goals++;
}
@@ -224,30 +221,29 @@ Spawns an explosion temporary entity when used.
"delay" wait this long before going off
"dmg" how much radius damage should be done, defaults to 0
*/
-void target_explosion_explode (edict_t *self)
+void target_explosion_explode(edict_t *self)
{
float save;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_EXPLOSION1);
- gi.WritePosition (self->s.origin);
- gi.multicast (self->s.origin, MULTICAST_PHS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_EXPLOSION1);
+ gi.WritePosition(self->s.origin);
+ gi.multicast(self->s.origin, MULTICAST_PHS);
- T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);
+ T_RadiusDamage(self, self->activator, self->dmg, NULL, self->dmg + 40, MOD_EXPLOSIVE);
save = self->delay;
self->delay = 0;
- G_UseTargets (self, self->activator);
+ G_UseTargets(self, self->activator);
self->delay = save;
}
-void use_target_explosion (edict_t *self, edict_t *other, edict_t *activator)
+void use_target_explosion(edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
- if (!self->delay)
- {
- target_explosion_explode (self);
+ if (!self->delay) {
+ target_explosion_explode(self);
return;
}
@@ -255,7 +251,7 @@ void use_target_explosion (edict_t *self, edict_t *other, edict_t *activator)
self->nextthink = level.time + self->delay;
}
-void SP_target_explosion (edict_t *ent)
+void SP_target_explosion(edict_t *ent)
{
ent->use = use_target_explosion;
ent->svflags = SVF_NOCLIENT;
@@ -267,50 +263,46 @@ void SP_target_explosion (edict_t *ent)
/*QUAKED target_changelevel (1 0 0) (-8 -8 -8) (8 8 8)
Changes level to "map" when fired
*/
-void use_target_changelevel (edict_t *self, edict_t *other, edict_t *activator)
+void use_target_changelevel(edict_t *self, edict_t *other, edict_t *activator)
{
if (level.intermissiontime)
return; // already activated
- if (!deathmatch->value && !coop->value)
- {
+ if (!deathmatch->value && !coop->value) {
if (g_edicts[1].health <= 0)
return;
}
// if noexit, do a ton of damage to other
- if (deathmatch->value && !( (int)dmflags->value & DF_ALLOW_EXIT) && other != world)
- {
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 10 * other->max_health, 1000, 0, MOD_EXIT);
+ if (deathmatch->value && !((int)dmflags->value & DF_ALLOW_EXIT) && other != world) {
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 10 * other->max_health, 1000, 0, MOD_EXIT);
return;
}
// if multiplayer, let everyone know who hit the exit
- if (deathmatch->value)
- {
+ if (deathmatch->value) {
if (activator && activator->client)
- gi.bprintf (PRINT_HIGH, "%s exited the level.\n", activator->client->pers.netname);
+ gi.bprintf(PRINT_HIGH, "%s exited the level.\n", activator->client->pers.netname);
}
// if going to a new unit, clear cross triggers
- if (strstr(self->map, "*"))
+ if (strstr(self->map, "*"))
game.serverflags &= ~(SFL_CROSS_TRIGGER_MASK);
- BeginIntermission (self);
+ BeginIntermission(self);
}
-void SP_target_changelevel (edict_t *ent)
+void SP_target_changelevel(edict_t *ent)
{
- if (!ent->map)
- {
+ if (!ent->map) {
gi.dprintf("target_changelevel with no map at %s\n", vtos(ent->s.origin));
- G_FreeEdict (ent);
+ G_FreeEdict(ent);
return;
}
// ugly hack because *SOMEBODY* screwed up their map
- if((Q_stricmp(level.mapname, "fact1") == 0) && (Q_stricmp(ent->map, "fact3") == 0))
- ent->map = "fact3$secret1";
+ if ((Q_stricmp(level.mapname, "fact1") == 0) && (Q_stricmp(ent->map, "fact3") == 0))
+ ent->map = "fact3$secret1";
ent->use = use_target_changelevel;
ent->svflags = SVF_NOCLIENT;
@@ -335,24 +327,24 @@ Set "sounds" to one of the following:
useful for lava/sparks
*/
-void use_target_splash (edict_t *self, edict_t *other, edict_t *activator)
+void use_target_splash(edict_t *self, edict_t *other, edict_t *activator)
{
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_SPLASH);
- gi.WriteByte (self->count);
- gi.WritePosition (self->s.origin);
- gi.WriteDir (self->movedir);
- gi.WriteByte (self->sounds);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_SPLASH);
+ gi.WriteByte(self->count);
+ gi.WritePosition(self->s.origin);
+ gi.WriteDir(self->movedir);
+ gi.WriteByte(self->sounds);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
if (self->dmg)
- T_RadiusDamage (self, activator, self->dmg, NULL, self->dmg+40, MOD_SPLASH);
+ T_RadiusDamage(self, activator, self->dmg, NULL, self->dmg + 40, MOD_SPLASH);
}
-void SP_target_splash (edict_t *self)
+void SP_target_splash(edict_t *self)
{
self->use = use_target_splash;
- G_SetMovedir (self->s.angles, self->movedir);
+ G_SetMovedir(self->s.angles, self->movedir);
if (!self->count)
self->count = 32;
@@ -375,32 +367,31 @@ For gibs:
speed how fast it should be moving otherwise it
will just be dropped
*/
-void ED_CallSpawn (edict_t *ent);
+void ED_CallSpawn(edict_t *ent);
-void use_target_spawner (edict_t *self, edict_t *other, edict_t *activator)
+void use_target_spawner(edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *ent;
ent = G_Spawn();
ent->classname = self->target;
- VectorCopy (self->s.origin, ent->s.origin);
- VectorCopy (self->s.angles, ent->s.angles);
- ED_CallSpawn (ent);
- gi.unlinkentity (ent);
- KillBox (ent);
- gi.linkentity (ent);
+ VectorCopy(self->s.origin, ent->s.origin);
+ VectorCopy(self->s.angles, ent->s.angles);
+ ED_CallSpawn(ent);
+ gi.unlinkentity(ent);
+ KillBox(ent);
+ gi.linkentity(ent);
if (self->speed)
- VectorCopy (self->movedir, ent->velocity);
+ VectorCopy(self->movedir, ent->velocity);
}
-void SP_target_spawner (edict_t *self)
+void SP_target_spawner(edict_t *self)
{
self->use = use_target_spawner;
self->svflags = SVF_NOCLIENT;
- if (self->speed)
- {
- G_SetMovedir (self->s.angles, self->movedir);
- VectorScale (self->movedir, self->speed, self->movedir);
+ if (self->speed) {
+ G_SetMovedir(self->s.angles, self->movedir);
+ VectorScale(self->movedir, self->speed, self->movedir);
}
}
@@ -413,7 +404,7 @@ dmg default is 15
speed default is 1000
*/
-void use_target_blaster (edict_t *self, edict_t *other, edict_t *activator)
+void use_target_blaster(edict_t *self, edict_t *other, edict_t *activator)
{
int effect;
@@ -424,15 +415,15 @@ void use_target_blaster (edict_t *self, edict_t *other, edict_t *activator)
else
effect = EF_BLASTER;
- fire_blaster (self, self->s.origin, self->movedir, self->dmg, self->speed, EF_BLASTER, MOD_TARGET_BLASTER);
- gi.sound (self, CHAN_VOICE, self->noise_index, 1, ATTN_NORM, 0);
+ fire_blaster(self, self->s.origin, self->movedir, self->dmg, self->speed, EF_BLASTER, MOD_TARGET_BLASTER);
+ gi.sound(self, CHAN_VOICE, self->noise_index, 1, ATTN_NORM, 0);
}
-void SP_target_blaster (edict_t *self)
+void SP_target_blaster(edict_t *self)
{
self->use = use_target_blaster;
- G_SetMovedir (self->s.angles, self->movedir);
- self->noise_index = gi.soundindex ("weapons/laser2.wav");
+ G_SetMovedir(self->s.angles, self->movedir);
+ self->noise_index = gi.soundindex("weapons/laser2.wav");
if (!self->dmg)
self->dmg = 15;
@@ -448,13 +439,13 @@ void SP_target_blaster (edict_t *self)
/*QUAKED target_crosslevel_trigger (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1 trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8
Once this trigger is touched/used, any trigger_crosslevel_target with the same trigger number is automatically used when a level is started within the same unit. It is OK to check multiple triggers. Message, delay, target, and killtarget also work.
*/
-void trigger_crosslevel_trigger_use (edict_t *self, edict_t *other, edict_t *activator)
+void trigger_crosslevel_trigger_use(edict_t *self, edict_t *other, edict_t *activator)
{
game.serverflags |= self->spawnflags;
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-void SP_target_crosslevel_trigger (edict_t *self)
+void SP_target_crosslevel_trigger(edict_t *self)
{
self->svflags = SVF_NOCLIENT;
self->use = trigger_crosslevel_trigger_use;
@@ -466,16 +457,15 @@ killtarget also work.
"delay" delay before using targets if the trigger has been activated (default 1)
*/
-void target_crosslevel_target_think (edict_t *self)
+void target_crosslevel_target_think(edict_t *self)
{
- if (self->spawnflags == (game.serverflags & SFL_CROSS_TRIGGER_MASK & self->spawnflags))
- {
- G_UseTargets (self, self);
- G_FreeEdict (self);
+ if (self->spawnflags == (game.serverflags & SFL_CROSS_TRIGGER_MASK & self->spawnflags)) {
+ G_UseTargets(self, self);
+ G_FreeEdict(self);
}
}
-void SP_target_crosslevel_target (edict_t *self)
+void SP_target_crosslevel_target(edict_t *self)
{
if (! self->delay)
self->delay = 1;
@@ -492,7 +482,7 @@ When triggered, fires a laser. You can either set a target
or a direction.
*/
-void target_laser_think (edict_t *self)
+void target_laser_think(edict_t *self)
{
edict_t *ignore;
vec3_t start;
@@ -507,88 +497,84 @@ void target_laser_think (edict_t *self)
else
count = 4;
- if (self->enemy)
- {
- VectorCopy (self->movedir, last_movedir);
- VectorMA (self->enemy->absmin, 0.5, self->enemy->size, point);
- VectorSubtract (point, self->s.origin, self->movedir);
- VectorNormalize (self->movedir);
+ if (self->enemy) {
+ VectorCopy(self->movedir, last_movedir);
+ VectorMA(self->enemy->absmin, 0.5, self->enemy->size, point);
+ VectorSubtract(point, self->s.origin, self->movedir);
+ VectorNormalize(self->movedir);
if (!VectorCompare(self->movedir, last_movedir))
self->spawnflags |= 0x80000000;
}
ignore = self;
- VectorCopy (self->s.origin, start);
- VectorMA (start, 2048, self->movedir, end);
- while(1)
- {
- tr = gi.trace (start, NULL, NULL, end, ignore, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
+ VectorCopy(self->s.origin, start);
+ VectorMA(start, 2048, self->movedir, end);
+ while (1) {
+ tr = gi.trace(start, NULL, NULL, end, ignore, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_DEADMONSTER);
if (!tr.ent)
break;
// hurt it if we can
if ((tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER))
- T_Damage (tr.ent, self, self->activator, self->movedir, tr.endpos, vec3_origin, self->dmg, 1, DAMAGE_ENERGY, MOD_TARGET_LASER);
+ T_Damage(tr.ent, self, self->activator, self->movedir, tr.endpos, vec3_origin, self->dmg, 1, DAMAGE_ENERGY, MOD_TARGET_LASER);
// if we hit something that's not a monster or player or is immune to lasers, we're done
- if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
- {
- if (self->spawnflags & 0x80000000)
- {
+ if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client)) {
+ if (self->spawnflags & 0x80000000) {
self->spawnflags &= ~0x80000000;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_LASER_SPARKS);
- gi.WriteByte (count);
- gi.WritePosition (tr.endpos);
- gi.WriteDir (tr.plane.normal);
- gi.WriteByte (self->s.skinnum);
- gi.multicast (tr.endpos, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_LASER_SPARKS);
+ gi.WriteByte(count);
+ gi.WritePosition(tr.endpos);
+ gi.WriteDir(tr.plane.normal);
+ gi.WriteByte(self->s.skinnum);
+ gi.multicast(tr.endpos, MULTICAST_PVS);
}
break;
}
ignore = tr.ent;
- VectorCopy (tr.endpos, start);
+ VectorCopy(tr.endpos, start);
}
- VectorCopy (tr.endpos, self->s.old_origin);
+ VectorCopy(tr.endpos, self->s.old_origin);
self->nextthink = level.time + FRAMETIME;
}
-void target_laser_on (edict_t *self)
+void target_laser_on(edict_t *self)
{
if (!self->activator)
self->activator = self;
self->spawnflags |= 0x80000001;
self->svflags &= ~SVF_NOCLIENT;
- target_laser_think (self);
+ target_laser_think(self);
}
-void target_laser_off (edict_t *self)
+void target_laser_off(edict_t *self)
{
self->spawnflags &= ~1;
self->svflags |= SVF_NOCLIENT;
self->nextthink = 0;
}
-void target_laser_use (edict_t *self, edict_t *other, edict_t *activator)
+void target_laser_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
if (self->spawnflags & 1)
- target_laser_off (self);
+ target_laser_off(self);
else
- target_laser_on (self);
+ target_laser_on(self);
}
-void target_laser_start (edict_t *self)
+void target_laser_start(edict_t *self)
{
edict_t *ent;
self->movetype = MOVETYPE_NONE;
self->solid = SOLID_NOT;
- self->s.renderfx |= RF_BEAM|RF_TRANSLUCENT;
+ self->s.renderfx |= RF_BEAM | RF_TRANSLUCENT;
self->s.modelindex = 1; // must be non-zero
// set the beam diameter
@@ -609,18 +595,14 @@ void target_laser_start (edict_t *self)
else if (self->spawnflags & 32)
self->s.skinnum = 0xe0e1e2e3;
- if (!self->enemy)
- {
- if (self->target)
- {
- ent = G_Find (NULL, FOFS(targetname), self->target);
+ if (!self->enemy) {
+ if (self->target) {
+ ent = G_Find(NULL, FOFS(targetname), self->target);
if (!ent)
- gi.dprintf ("%s at %s: %s is a bad target\n", self->classname, vtos(self->s.origin), self->target);
+ gi.dprintf("%s at %s: %s is a bad target\n", self->classname, vtos(self->s.origin), self->target);
self->enemy = ent;
- }
- else
- {
- G_SetMovedir (self->s.angles, self->movedir);
+ } else {
+ G_SetMovedir(self->s.angles, self->movedir);
}
}
self->use = target_laser_use;
@@ -629,17 +611,17 @@ void target_laser_start (edict_t *self)
if (!self->dmg)
self->dmg = 1;
- VectorSet (self->mins, -8, -8, -8);
- VectorSet (self->maxs, 8, 8, 8);
- gi.linkentity (self);
+ VectorSet(self->mins, -8, -8, -8);
+ VectorSet(self->maxs, 8, 8, 8);
+ gi.linkentity(self);
if (self->spawnflags & 1)
- target_laser_on (self);
+ target_laser_on(self);
else
- target_laser_off (self);
+ target_laser_off(self);
}
-void SP_target_laser (edict_t *self)
+void SP_target_laser(edict_t *self)
{
// let everything else get spawned before we start firing
self->think = target_laser_start;
@@ -653,20 +635,17 @@ speed How many seconds the ramping will take
message two letters; starting lightlevel and ending lightlevel
*/
-void target_lightramp_think (edict_t *self)
+void target_lightramp_think(edict_t *self)
{
char style[2];
style[0] = 'a' + self->movedir[0] + (level.time - self->timestamp) / FRAMETIME * self->movedir[2];
style[1] = 0;
- gi.configstring (CS_LIGHTS+self->enemy->style, style);
+ gi.configstring(CS_LIGHTS + self->enemy->style, style);
- if ((level.time - self->timestamp) < self->speed)
- {
+ if ((level.time - self->timestamp) < self->speed) {
self->nextthink = level.time + FRAMETIME;
- }
- else if (self->spawnflags & 1)
- {
+ } else if (self->spawnflags & 1) {
char temp;
temp = self->movedir[0];
@@ -676,61 +655,52 @@ void target_lightramp_think (edict_t *self)
}
}
-void target_lightramp_use (edict_t *self, edict_t *other, edict_t *activator)
+void target_lightramp_use(edict_t *self, edict_t *other, edict_t *activator)
{
- if (!self->enemy)
- {
+ if (!self->enemy) {
edict_t *e;
// check all the targets
e = NULL;
- while (1)
- {
- e = G_Find (e, FOFS(targetname), self->target);
+ while (1) {
+ e = G_Find(e, FOFS(targetname), self->target);
if (!e)
break;
- if (strcmp(e->classname, "light") != 0)
- {
+ if (strcmp(e->classname, "light") != 0) {
gi.dprintf("%s at %s ", self->classname, vtos(self->s.origin));
gi.dprintf("target %s (%s at %s) is not a light\n", self->target, e->classname, vtos(e->s.origin));
- }
- else
- {
+ } else {
self->enemy = e;
}
}
- if (!self->enemy)
- {
+ if (!self->enemy) {
gi.dprintf("%s target %s not found at %s\n", self->classname, self->target, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
}
self->timestamp = level.time;
- target_lightramp_think (self);
+ target_lightramp_think(self);
}
-void SP_target_lightramp (edict_t *self)
+void SP_target_lightramp(edict_t *self)
{
- if (!self->message || strlen(self->message) != 2 || self->message[0] < 'a' || self->message[0] > 'z' || self->message[1] < 'a' || self->message[1] > 'z' || self->message[0] == self->message[1])
- {
+ if (!self->message || strlen(self->message) != 2 || self->message[0] < 'a' || self->message[0] > 'z' || self->message[1] < 'a' || self->message[1] > 'z' || self->message[0] == self->message[1]) {
gi.dprintf("target_lightramp has bad ramp (%s) at %s\n", self->message, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
@@ -752,19 +722,17 @@ All players and monsters are affected.
"count" duration of the quake (default:5)
*/
-void target_earthquake_think (edict_t *self)
+void target_earthquake_think(edict_t *self)
{
int i;
edict_t *e;
- if (self->last_move_time < level.time)
- {
- gi.positioned_sound (self->s.origin, self, CHAN_AUTO, self->noise_index, 1.0, ATTN_NONE, 0);
+ if (self->last_move_time < level.time) {
+ gi.positioned_sound(self->s.origin, self, CHAN_AUTO, self->noise_index, 1.0, ATTN_NONE, 0);
self->last_move_time = level.time + 0.5;
}
- for (i=1, e=g_edicts+i; i < globals.num_edicts; i++,e++)
- {
+ for (i = 1, e = g_edicts + i; i < globals.num_edicts; i++, e++) {
if (!e->inuse)
continue;
if (!e->client)
@@ -773,8 +741,8 @@ void target_earthquake_think (edict_t *self)
continue;
e->groundentity = NULL;
- e->velocity[0] += crandom()* 150;
- e->velocity[1] += crandom()* 150;
+ e->velocity[0] += crandom() * 150;
+ e->velocity[1] += crandom() * 150;
e->velocity[2] = self->speed * (100.0 / e->mass);
}
@@ -782,7 +750,7 @@ void target_earthquake_think (edict_t *self)
self->nextthink = level.time + FRAMETIME;
}
-void target_earthquake_use (edict_t *self, edict_t *other, edict_t *activator)
+void target_earthquake_use(edict_t *self, edict_t *other, edict_t *activator)
{
self->timestamp = level.time + self->count;
self->nextthink = level.time + FRAMETIME;
@@ -790,7 +758,7 @@ void target_earthquake_use (edict_t *self, edict_t *other, edict_t *activator)
self->last_move_time = 0;
}
-void SP_target_earthquake (edict_t *self)
+void SP_target_earthquake(edict_t *self)
{
if (!self->targetname)
gi.dprintf("untargeted %s at %s\n", self->classname, vtos(self->s.origin));
@@ -805,5 +773,5 @@ void SP_target_earthquake (edict_t *self)
self->think = target_earthquake_think;
self->use = target_earthquake_use;
- self->noise_index = gi.soundindex ("world/quake.wav");
+ self->noise_index = gi.soundindex("world/quake.wav");
}
diff --git a/src/baseq2/g_trigger.c b/src/baseq2/g_trigger.c
index 5d5c013..5a65684 100644
--- a/src/baseq2/g_trigger.c
+++ b/src/baseq2/g_trigger.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,20 +20,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
-void InitTrigger (edict_t *self)
+void InitTrigger(edict_t *self)
{
- if (!VectorCompare (self->s.angles, vec3_origin))
- G_SetMovedir (self->s.angles, self->movedir);
+ if (!VectorCompare(self->s.angles, vec3_origin))
+ G_SetMovedir(self->s.angles, self->movedir);
self->solid = SOLID_TRIGGER;
self->movetype = MOVETYPE_NONE;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
self->svflags = SVF_NOCLIENT;
}
// the wait time has passed, so set back up for another activation
-void multi_wait (edict_t *ent)
+void multi_wait(edict_t *ent)
{
ent->nextthink = 0;
}
@@ -42,20 +42,18 @@ void multi_wait (edict_t *ent)
// the trigger was just activated
// ent->activator should be set to the activator so it can be held through a delay
// so wait for the delay time before firing
-void multi_trigger (edict_t *ent)
+void multi_trigger(edict_t *ent)
{
if (ent->nextthink)
return; // already been triggered
- G_UseTargets (ent, ent->activator);
+ G_UseTargets(ent, ent->activator);
- if (ent->wait > 0)
- {
+ if (ent->wait > 0) {
ent->think = multi_wait;
ent->nextthink = level.time + ent->wait;
- }
- else
- { // we can't just remove (self) here, because this is a touch function
+ } else {
+ // we can't just remove (self) here, because this is a touch function
// called while looping through area links...
ent->touch = NULL;
ent->nextthink = level.time + FRAMETIME;
@@ -63,29 +61,24 @@ void multi_trigger (edict_t *ent)
}
}
-void Use_Multi (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Multi(edict_t *ent, edict_t *other, edict_t *activator)
{
ent->activator = activator;
- multi_trigger (ent);
+ multi_trigger(ent);
}
-void Touch_Multi (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void Touch_Multi(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
- if(other->client)
- {
+ if (other->client) {
if (self->spawnflags & 2)
return;
- }
- else if (other->svflags & SVF_MONSTER)
- {
+ } else if (other->svflags & SVF_MONSTER) {
if (!(self->spawnflags & 1))
return;
- }
- else
+ } else
return;
- if (!VectorCompare(self->movedir, vec3_origin))
- {
+ if (!VectorCompare(self->movedir, vec3_origin)) {
vec3_t forward;
AngleVectors(other->s.angles, forward, NULL, NULL);
@@ -94,7 +87,7 @@ void Touch_Multi (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *su
}
self->activator = other;
- multi_trigger (self);
+ multi_trigger(self);
}
/*QUAKED trigger_multiple (.5 .5 .5) ? MONSTER NOT_PLAYER TRIGGERED
@@ -108,22 +101,22 @@ sounds
4)
set "message" to text string
*/
-void trigger_enable (edict_t *self, edict_t *other, edict_t *activator)
+void trigger_enable(edict_t *self, edict_t *other, edict_t *activator)
{
self->solid = SOLID_TRIGGER;
self->use = Use_Multi;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void SP_trigger_multiple (edict_t *ent)
+void SP_trigger_multiple(edict_t *ent)
{
if (ent->sounds == 1)
- ent->noise_index = gi.soundindex ("misc/secret.wav");
+ ent->noise_index = gi.soundindex("misc/secret.wav");
else if (ent->sounds == 2)
- ent->noise_index = gi.soundindex ("misc/talk.wav");
+ ent->noise_index = gi.soundindex("misc/talk.wav");
else if (ent->sounds == 3)
- ent->noise_index = gi.soundindex ("misc/trigger1.wav");
-
+ ent->noise_index = gi.soundindex("misc/trigger1.wav");
+
if (!ent->wait)
ent->wait = 0.2;
ent->touch = Touch_Multi;
@@ -131,22 +124,19 @@ void SP_trigger_multiple (edict_t *ent)
ent->svflags |= SVF_NOCLIENT;
- if (ent->spawnflags & 4)
- {
+ if (ent->spawnflags & 4) {
ent->solid = SOLID_NOT;
ent->use = trigger_enable;
- }
- else
- {
+ } else {
ent->solid = SOLID_TRIGGER;
ent->use = Use_Multi;
}
if (!VectorCompare(ent->s.angles, vec3_origin))
- G_SetMovedir (ent->s.angles, ent->movedir);
+ G_SetMovedir(ent->s.angles, ent->movedir);
- gi.setmodel (ent, ent->model);
- gi.linkentity (ent);
+ gi.setmodel(ent, ent->model);
+ gi.linkentity(ent);
}
@@ -169,29 +159,28 @@ void SP_trigger_once(edict_t *ent)
{
// make old maps work because I messed up on flag assignments here
// triggered was on bit 1 when it should have been on bit 4
- if (ent->spawnflags & 1)
- {
+ if (ent->spawnflags & 1) {
vec3_t v;
- VectorMA (ent->mins, 0.5, ent->size, v);
+ VectorMA(ent->mins, 0.5, ent->size, v);
ent->spawnflags &= ~1;
ent->spawnflags |= 4;
gi.dprintf("fixed TRIGGERED flag on %s at %s\n", ent->classname, vtos(v));
}
ent->wait = -1;
- SP_trigger_multiple (ent);
+ SP_trigger_multiple(ent);
}
/*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
This fixed size trigger cannot be touched, it can only be fired by other events.
*/
-void trigger_relay_use (edict_t *self, edict_t *other, edict_t *activator)
+void trigger_relay_use(edict_t *self, edict_t *other, edict_t *activator)
{
- G_UseTargets (self, activator);
+ G_UseTargets(self, activator);
}
-void SP_trigger_relay (edict_t *self)
+void SP_trigger_relay(edict_t *self)
{
self->use = trigger_relay_use;
}
@@ -209,7 +198,7 @@ trigger_key
A relay trigger that only fires it's targets if player has the proper key.
Use "item" to specify the required key, for example "key_data_cd"
*/
-void trigger_key_use (edict_t *self, edict_t *other, edict_t *activator)
+void trigger_key_use(edict_t *self, edict_t *other, edict_t *activator)
{
int index;
@@ -219,47 +208,39 @@ void trigger_key_use (edict_t *self, edict_t *other, edict_t *activator)
return;
index = ITEM_INDEX(self->item);
- if (!activator->client->pers.inventory[index])
- {
+ if (!activator->client->pers.inventory[index]) {
if (level.time < self->touch_debounce_time)
return;
self->touch_debounce_time = level.time + 5.0;
- gi.centerprintf (activator, "You need the %s", self->item->pickup_name);
- gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keytry.wav"), 1, ATTN_NORM, 0);
+ gi.centerprintf(activator, "You need the %s", self->item->pickup_name);
+ gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/keytry.wav"), 1, ATTN_NORM, 0);
return;
}
- gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keyuse.wav"), 1, ATTN_NORM, 0);
- if (coop->value)
- {
+ gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/keyuse.wav"), 1, ATTN_NORM, 0);
+ if (coop->value) {
int player;
edict_t *ent;
- if (strcmp(self->item->classname, "key_power_cube") == 0)
- {
+ if (strcmp(self->item->classname, "key_power_cube") == 0) {
int cube;
for (cube = 0; cube < 8; cube++)
if (activator->client->pers.power_cubes & (1 << cube))
break;
- for (player = 1; player <= game.maxclients; player++)
- {
+ for (player = 1; player <= game.maxclients; player++) {
ent = &g_edicts[player];
if (!ent->inuse)
continue;
if (!ent->client)
continue;
- if (ent->client->pers.power_cubes & (1 << cube))
- {
+ if (ent->client->pers.power_cubes & (1 << cube)) {
ent->client->pers.inventory[index]--;
ent->client->pers.power_cubes &= ~(1 << cube);
}
}
- }
- else
- {
- for (player = 1; player <= game.maxclients; player++)
- {
+ } else {
+ for (player = 1; player <= game.maxclients; player++) {
ent = &g_edicts[player];
if (!ent->inuse)
continue;
@@ -268,40 +249,35 @@ void trigger_key_use (edict_t *self, edict_t *other, edict_t *activator)
ent->client->pers.inventory[index] = 0;
}
}
- }
- else
- {
+ } else {
activator->client->pers.inventory[index]--;
}
- G_UseTargets (self, activator);
+ G_UseTargets(self, activator);
self->use = NULL;
}
-void SP_trigger_key (edict_t *self)
+void SP_trigger_key(edict_t *self)
{
- if (!st.item)
- {
+ if (!st.item) {
gi.dprintf("no key item for trigger_key at %s\n", vtos(self->s.origin));
return;
}
- self->item = FindItemByClassname (st.item);
+ self->item = FindItemByClassname(st.item);
- if (!self->item)
- {
+ if (!self->item) {
gi.dprintf("item %s not found for trigger_key at %s\n", st.item, vtos(self->s.origin));
return;
}
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("%s at %s has no target\n", self->classname, vtos(self->s.origin));
return;
}
- gi.soundindex ("misc/keytry.wav");
- gi.soundindex ("misc/keyuse.wav");
+ gi.soundindex("misc/keytry.wav");
+ gi.soundindex("misc/keyuse.wav");
self->use = trigger_key_use;
}
@@ -327,29 +303,26 @@ void trigger_counter_use(edict_t *self, edict_t *other, edict_t *activator)
{
if (self->count == 0)
return;
-
+
self->count--;
- if (self->count)
- {
- if (! (self->spawnflags & 1))
- {
+ if (self->count) {
+ if (!(self->spawnflags & 1)) {
gi.centerprintf(activator, "%i more to go...", self->count);
- gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/talk1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
return;
}
-
- if (! (self->spawnflags & 1))
- {
+
+ if (!(self->spawnflags & 1)) {
gi.centerprintf(activator, "Sequence completed!");
- gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/talk1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
self->activator = activator;
- multi_trigger (self);
+ multi_trigger(self);
}
-void SP_trigger_counter (edict_t *self)
+void SP_trigger_counter(edict_t *self)
{
self->wait = -1;
if (!self->count)
@@ -370,7 +343,7 @@ trigger_always
/*QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8)
This trigger will always fire. It is activated by the world.
*/
-void SP_trigger_always (edict_t *ent)
+void SP_trigger_always(edict_t *ent)
{
// we must have some delay to make sure our use targets are present
if (ent->delay < 0.2)
@@ -391,29 +364,24 @@ trigger_push
static int windsound;
-void trigger_push_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void trigger_push_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
- if (strcmp(other->classname, "grenade") == 0)
- {
- VectorScale (self->movedir, self->speed * 10, other->velocity);
- }
- else if (other->health > 0)
- {
- VectorScale (self->movedir, self->speed * 10, other->velocity);
+ if (strcmp(other->classname, "grenade") == 0) {
+ VectorScale(self->movedir, self->speed * 10, other->velocity);
+ } else if (other->health > 0) {
+ VectorScale(self->movedir, self->speed * 10, other->velocity);
- if (other->client)
- {
+ if (other->client) {
// don't take falling damage immediately from this
- VectorCopy (other->velocity, other->client->oldvelocity);
- if (other->fly_sound_debounce_time < level.time)
- {
+ VectorCopy(other->velocity, other->client->oldvelocity);
+ if (other->fly_sound_debounce_time < level.time) {
other->fly_sound_debounce_time = level.time + 1.5;
- gi.sound (other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
+ gi.sound(other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
}
}
}
if (self->spawnflags & PUSH_ONCE)
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
@@ -421,14 +389,14 @@ void trigger_push_touch (edict_t *self, edict_t *other, cplane_t *plane, csurfac
Pushes the player
"speed" defaults to 1000
*/
-void SP_trigger_push (edict_t *self)
+void SP_trigger_push(edict_t *self)
{
- InitTrigger (self);
- windsound = gi.soundindex ("misc/windfly.wav");
+ InitTrigger(self);
+ windsound = gi.soundindex("misc/windfly.wav");
self->touch = trigger_push_touch;
if (!self->speed)
self->speed = 1000;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -452,20 +420,20 @@ NO_PROTECTION *nothing* stops the damage
"dmg" default 5 (whole numbers only)
*/
-void hurt_use (edict_t *self, edict_t *other, edict_t *activator)
+void hurt_use(edict_t *self, edict_t *other, edict_t *activator)
{
if (self->solid == SOLID_NOT)
self->solid = SOLID_TRIGGER;
else
self->solid = SOLID_NOT;
- gi.linkentity (self);
+ gi.linkentity(self);
if (!(self->spawnflags & 2))
self->use = NULL;
}
-void hurt_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void hurt_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
int dflags;
@@ -480,24 +448,23 @@ void hurt_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *sur
else
self->timestamp = level.time + FRAMETIME;
- if (!(self->spawnflags & 4))
- {
+ if (!(self->spawnflags & 4)) {
if ((level.framenum % 10) == 0)
- gi.sound (other, CHAN_AUTO, self->noise_index, 1, ATTN_NORM, 0);
+ gi.sound(other, CHAN_AUTO, self->noise_index, 1, ATTN_NORM, 0);
}
if (self->spawnflags & 8)
dflags = DAMAGE_NO_PROTECTION;
else
dflags = 0;
- T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, self->dmg, dflags, MOD_TRIGGER_HURT);
+ T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, self->dmg, dflags, MOD_TRIGGER_HURT);
}
-void SP_trigger_hurt (edict_t *self)
+void SP_trigger_hurt(edict_t *self)
{
- InitTrigger (self);
+ InitTrigger(self);
- self->noise_index = gi.soundindex ("world/electro.wav");
+ self->noise_index = gi.soundindex("world/electro.wav");
self->touch = hurt_touch;
if (!self->dmg)
@@ -511,7 +478,7 @@ void SP_trigger_hurt (edict_t *self)
if (self->spawnflags & 2)
self->use = hurt_use;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -529,21 +496,20 @@ the value of "gravity". 1.0 is standard
gravity for the level.
*/
-void trigger_gravity_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void trigger_gravity_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
other->gravity = self->gravity;
}
-void SP_trigger_gravity (edict_t *self)
+void SP_trigger_gravity(edict_t *self)
{
- if (st.gravity == 0)
- {
+ if (st.gravity == 0) {
gi.dprintf("trigger_gravity without gravity set at %s\n", vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
- InitTrigger (self);
+ InitTrigger(self);
self->gravity = atoi(st.gravity);
self->touch = trigger_gravity_touch;
}
@@ -563,27 +529,27 @@ Walking monsters that touch this will jump in the direction of the trigger's ang
"height" default to 200, the speed thrown upwards
*/
-void trigger_monsterjump_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void trigger_monsterjump_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
- if (other->flags & (FL_FLY | FL_SWIM) )
+ if (other->flags & (FL_FLY | FL_SWIM))
return;
if (other->svflags & SVF_DEADMONSTER)
return;
- if ( !(other->svflags & SVF_MONSTER))
+ if (!(other->svflags & SVF_MONSTER))
return;
// set XY even if not on ground, so the jump will clear lips
other->velocity[0] = self->movedir[0] * self->speed;
other->velocity[1] = self->movedir[1] * self->speed;
-
+
if (!other->groundentity)
return;
-
+
other->groundentity = NULL;
other->velocity[2] = self->movedir[2];
}
-void SP_trigger_monsterjump (edict_t *self)
+void SP_trigger_monsterjump(edict_t *self)
{
if (!self->speed)
self->speed = 200;
@@ -591,7 +557,7 @@ void SP_trigger_monsterjump (edict_t *self)
st.height = 200;
if (self->s.angles[YAW] == 0)
self->s.angles[YAW] = 360;
- InitTrigger (self);
+ InitTrigger(self);
self->touch = trigger_monsterjump_touch;
self->movedir[2] = st.height;
}
diff --git a/src/baseq2/g_turret.c b/src/baseq2/g_turret.c
index cd3c3a9..66f9a22 100644
--- a/src/baseq2/g_turret.c
+++ b/src/baseq2/g_turret.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,13 +24,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void AnglesNormalize(vec3_t vec)
{
- while(vec[0] > 360)
+ while (vec[0] > 360)
vec[0] -= 360;
- while(vec[0] < 0)
+ while (vec[0] < 0)
vec[0] += 360;
- while(vec[1] > 360)
+ while (vec[1] > 360)
vec[1] -= 360;
- while(vec[1] < 0)
+ while (vec[1] < 0)
vec[1] += 360;
}
@@ -49,13 +49,12 @@ void turret_blocked(edict_t *self, edict_t *other)
{
edict_t *attacker;
- if (other->takedamage)
- {
+ if (other->takedamage) {
if (self->teammaster->owner)
attacker = self->teammaster->owner;
else
attacker = self->teammaster;
- T_Damage (other, self, attacker, vec3_origin, other->s.origin, vec3_origin, self->teammaster->dmg, 10, 0, MOD_CRUSH);
+ T_Damage(other, self, attacker, vec3_origin, other->s.origin, vec3_origin, self->teammaster->dmg, 10, 0, MOD_CRUSH);
}
}
@@ -75,31 +74,31 @@ Use "angle" to set the starting angle.
"maxyaw" max acceptable yaw angle : default 360
*/
-void turret_breach_fire (edict_t *self)
+void turret_breach_fire(edict_t *self)
{
vec3_t f, r, u;
vec3_t start;
int damage;
int speed;
- AngleVectors (self->s.angles, f, r, u);
- VectorMA (self->s.origin, self->move_origin[0], f, start);
- VectorMA (start, self->move_origin[1], r, start);
- VectorMA (start, self->move_origin[2], u, start);
+ AngleVectors(self->s.angles, f, r, u);
+ VectorMA(self->s.origin, self->move_origin[0], f, start);
+ VectorMA(start, self->move_origin[1], r, start);
+ VectorMA(start, self->move_origin[2], u, start);
damage = 100 + random() * 50;
speed = 550 + 50 * skill->value;
- fire_rocket (self->teammaster->owner, start, f, damage, speed, 150, damage);
- gi.positioned_sound (start, self, CHAN_WEAPON, gi.soundindex("weapons/rocklf1a.wav"), 1, ATTN_NORM, 0);
+ fire_rocket(self->teammaster->owner, start, f, damage, speed, 150, damage);
+ gi.positioned_sound(start, self, CHAN_WEAPON, gi.soundindex("weapons/rocklf1a.wav"), 1, ATTN_NORM, 0);
}
-void turret_breach_think (edict_t *self)
+void turret_breach_think(edict_t *self)
{
edict_t *ent;
vec3_t current_angles;
vec3_t delta;
- VectorCopy (self->s.angles, current_angles);
+ VectorCopy(self->s.angles, current_angles);
AnglesNormalize(current_angles);
AnglesNormalize(self->move_angles);
@@ -112,8 +111,7 @@ void turret_breach_think (edict_t *self)
else if (self->move_angles[PITCH] < self->pos2[PITCH])
self->move_angles[PITCH] = self->pos2[PITCH];
- if ((self->move_angles[YAW] < self->pos1[YAW]) || (self->move_angles[YAW] > self->pos2[YAW]))
- {
+ if ((self->move_angles[YAW] < self->pos1[YAW]) || (self->move_angles[YAW] > self->pos2[YAW])) {
float dmin, dmax;
dmin = fabs(self->pos1[YAW] - self->move_angles[YAW]);
@@ -132,7 +130,7 @@ void turret_breach_think (edict_t *self)
self->move_angles[YAW] = self->pos2[YAW];
}
- VectorSubtract (self->move_angles, current_angles, delta);
+ VectorSubtract(self->move_angles, current_angles, delta);
if (delta[0] < -180)
delta[0] += 360;
else if (delta[0] > 180)
@@ -152,7 +150,7 @@ void turret_breach_think (edict_t *self)
if (delta[1] < -1 * self->speed * FRAMETIME)
delta[1] = -1 * self->speed * FRAMETIME;
- VectorScale (delta, 1.0/FRAMETIME, self->avelocity);
+ VectorScale(delta, 1.0 / FRAMETIME, self->avelocity);
self->nextthink = level.time + FRAMETIME;
@@ -160,8 +158,7 @@ void turret_breach_think (edict_t *self)
ent->avelocity[1] = self->avelocity[1];
// if we have adriver, adjust his velocities
- if (self->owner)
- {
+ if (self->owner) {
float angle;
float target_z;
float diff;
@@ -174,54 +171,50 @@ void turret_breach_think (edict_t *self)
// x & y
angle = self->s.angles[1] + self->owner->move_origin[1];
- angle *= (M_PI*2 / 360);
+ angle *= (M_PI * 2 / 360);
target[0] = SnapToEights(self->s.origin[0] + cos(angle) * self->owner->move_origin[0]);
target[1] = SnapToEights(self->s.origin[1] + sin(angle) * self->owner->move_origin[0]);
target[2] = self->owner->s.origin[2];
- VectorSubtract (target, self->owner->s.origin, dir);
+ VectorSubtract(target, self->owner->s.origin, dir);
self->owner->velocity[0] = dir[0] * 1.0 / FRAMETIME;
self->owner->velocity[1] = dir[1] * 1.0 / FRAMETIME;
// z
- angle = self->s.angles[PITCH] * (M_PI*2 / 360);
+ angle = self->s.angles[PITCH] * (M_PI * 2 / 360);
target_z = SnapToEights(self->s.origin[2] + self->owner->move_origin[0] * tan(angle) + self->owner->move_origin[2]);
diff = target_z - self->owner->s.origin[2];
self->owner->velocity[2] = diff * 1.0 / FRAMETIME;
- if (self->spawnflags & 65536)
- {
- turret_breach_fire (self);
+ if (self->spawnflags & 65536) {
+ turret_breach_fire(self);
self->spawnflags &= ~65536;
}
}
}
-void turret_breach_finish_init (edict_t *self)
+void turret_breach_finish_init(edict_t *self)
{
// get and save info for muzzle location
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("%s at %s needs a target\n", self->classname, vtos(self->s.origin));
- }
- else
- {
- self->target_ent = G_PickTarget (self->target);
- VectorSubtract (self->target_ent->s.origin, self->s.origin, self->move_origin);
+ } else {
+ self->target_ent = G_PickTarget(self->target);
+ VectorSubtract(self->target_ent->s.origin, self->s.origin, self->move_origin);
G_FreeEdict(self->target_ent);
}
self->teammaster->dmg = self->dmg;
self->think = turret_breach_think;
- self->think (self);
+ self->think(self);
}
-void SP_turret_breach (edict_t *self)
+void SP_turret_breach(edict_t *self)
{
self->solid = SOLID_BSP;
self->movetype = MOVETYPE_PUSH;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
if (!self->speed)
self->speed = 50;
@@ -247,7 +240,7 @@ void SP_turret_breach (edict_t *self)
self->think = turret_breach_finish_init;
self->nextthink = level.time + FRAMETIME;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -256,13 +249,13 @@ This portion of the turret changes yaw only.
MUST be teamed with a turret_breach.
*/
-void SP_turret_base (edict_t *self)
+void SP_turret_base(edict_t *self)
{
self->solid = SOLID_BSP;
self->movetype = MOVETYPE_PUSH;
- gi.setmodel (self, self->model);
+ gi.setmodel(self, self->model);
self->blocked = turret_blocked;
- gi.linkentity (self);
+ gi.linkentity(self);
}
@@ -271,11 +264,11 @@ Must NOT be on the team with the rest of the turret parts.
Instead it must target the turret_breach.
*/
-void infantry_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage);
-void infantry_stand (edict_t *self);
-void monster_use (edict_t *self, edict_t *other, edict_t *activator);
+void infantry_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage);
+void infantry_stand(edict_t *self);
+void monster_use(edict_t *self, edict_t *other, edict_t *activator);
-void turret_driver_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void turret_driver_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
edict_t *ent;
@@ -292,12 +285,12 @@ void turret_driver_die (edict_t *self, edict_t *inflictor, edict_t *attacker, in
self->target_ent->owner = NULL;
self->target_ent->teammaster->owner = NULL;
- infantry_die (self, inflictor, attacker, damage);
+ infantry_die(self, inflictor, attacker, damage);
}
-qboolean FindTarget (edict_t *self);
+qboolean FindTarget(edict_t *self);
-void turret_driver_think (edict_t *self)
+void turret_driver_think(edict_t *self)
{
vec3_t target;
vec3_t dir;
@@ -308,35 +301,28 @@ void turret_driver_think (edict_t *self)
if (self->enemy && (!self->enemy->inuse || self->enemy->health <= 0))
self->enemy = NULL;
- if (!self->enemy)
- {
- if (!FindTarget (self))
+ if (!self->enemy) {
+ if (!FindTarget(self))
return;
self->monsterinfo.trail_time = level.time;
self->monsterinfo.aiflags &= ~AI_LOST_SIGHT;
- }
- else
- {
- if (visible (self, self->enemy))
- {
- if (self->monsterinfo.aiflags & AI_LOST_SIGHT)
- {
+ } else {
+ if (visible(self, self->enemy)) {
+ if (self->monsterinfo.aiflags & AI_LOST_SIGHT) {
self->monsterinfo.trail_time = level.time;
self->monsterinfo.aiflags &= ~AI_LOST_SIGHT;
}
- }
- else
- {
+ } else {
self->monsterinfo.aiflags |= AI_LOST_SIGHT;
return;
}
}
// let the turret know where we want it to aim
- VectorCopy (self->enemy->s.origin, target);
+ VectorCopy(self->enemy->s.origin, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, self->target_ent->s.origin, dir);
- vectoangles (dir, self->target_ent->move_angles);
+ VectorSubtract(target, self->target_ent->s.origin, dir);
+ vectoangles(dir, self->target_ent->move_angles);
// decide if we should shoot
if (level.time < self->monsterinfo.attack_finished)
@@ -351,7 +337,7 @@ void turret_driver_think (edict_t *self)
self->target_ent->spawnflags |= 65536;
}
-void turret_driver_link (edict_t *self)
+void turret_driver_link(edict_t *self)
{
vec3_t vec;
edict_t *ent;
@@ -359,18 +345,18 @@ void turret_driver_link (edict_t *self)
self->think = turret_driver_think;
self->nextthink = level.time + FRAMETIME;
- self->target_ent = G_PickTarget (self->target);
+ self->target_ent = G_PickTarget(self->target);
self->target_ent->owner = self;
self->target_ent->teammaster->owner = self;
- VectorCopy (self->target_ent->s.angles, self->s.angles);
+ VectorCopy(self->target_ent->s.angles, self->s.angles);
vec[0] = self->target_ent->s.origin[0] - self->s.origin[0];
vec[1] = self->target_ent->s.origin[1] - self->s.origin[1];
vec[2] = 0;
self->move_origin[0] = VectorLength(vec);
- VectorSubtract (self->s.origin, self->target_ent->s.origin, vec);
- vectoangles (vec, vec);
+ VectorSubtract(self->s.origin, self->target_ent->s.origin, vec);
+ vectoangles(vec, vec);
AnglesNormalize(vec);
self->move_origin[1] = vec[1];
@@ -384,19 +370,18 @@ void turret_driver_link (edict_t *self)
self->flags |= FL_TEAMSLAVE;
}
-void SP_turret_driver (edict_t *self)
+void SP_turret_driver(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
self->movetype = MOVETYPE_PUSH;
self->solid = SOLID_BBOX;
self->s.modelindex = gi.modelindex("models/monsters/infantry/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 100;
self->gib_health = 0;
@@ -415,12 +400,11 @@ void SP_turret_driver (edict_t *self)
self->takedamage = DAMAGE_AIM;
self->use = monster_use;
self->clipmask = MASK_MONSTERSOLID;
- VectorCopy (self->s.origin, self->s.old_origin);
- self->monsterinfo.aiflags |= AI_STAND_GROUND|AI_DUCKED;
+ VectorCopy(self->s.origin, self->s.old_origin);
+ self->monsterinfo.aiflags |= AI_STAND_GROUND | AI_DUCKED;
- if (st.item)
- {
- self->item = FindItemByClassname (st.item);
+ if (st.item) {
+ self->item = FindItemByClassname(st.item);
if (!self->item)
gi.dprintf("%s at %s has bad item: %s\n", self->classname, vtos(self->s.origin), st.item);
}
@@ -428,5 +412,5 @@ void SP_turret_driver (edict_t *self)
self->think = turret_driver_link;
self->nextthink = level.time + FRAMETIME;
- gi.linkentity (self);
+ gi.linkentity(self);
}
diff --git a/src/baseq2/g_utils.c b/src/baseq2/g_utils.c
index 7d5736b..b5a70aa 100644
--- a/src/baseq2/g_utils.c
+++ b/src/baseq2/g_utils.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
-void G_ProjectSource (const vec3_t point, const vec3_t distance, const vec3_t forward, const vec3_t right, vec3_t result)
+void G_ProjectSource(const vec3_t point, const vec3_t distance, const vec3_t forward, const vec3_t right, vec3_t result)
{
result[0] = point[0] + forward[0] * distance[0] + right[0] * distance[1];
result[1] = point[1] + forward[1] * distance[0] + right[1] * distance[1];
@@ -42,7 +42,7 @@ NULL will be returned if the end of the list is reached.
=============
*/
-edict_t *G_Find (edict_t *from, int fieldofs, char *match)
+edict_t *G_Find(edict_t *from, int fieldofs, char *match)
{
char *s;
@@ -51,14 +51,13 @@ edict_t *G_Find (edict_t *from, int fieldofs, char *match)
else
from++;
- for ( ; from < &g_edicts[globals.num_edicts] ; from++)
- {
+ for (; from < &g_edicts[globals.num_edicts] ; from++) {
if (!from->inuse)
continue;
- s = *(char **) ((byte *)from + fieldofs);
+ s = *(char **)((byte *)from + fieldofs);
if (!s)
continue;
- if (!Q_stricmp (s, match))
+ if (!Q_stricmp(s, match))
return from;
}
@@ -75,7 +74,7 @@ Returns entities that have origins within a spherical area
findradius (origin, radius)
=================
*/
-edict_t *findradius (edict_t *from, vec3_t org, float rad)
+edict_t *findradius(edict_t *from, vec3_t org, float rad)
{
vec3_t eorg;
int j;
@@ -84,14 +83,13 @@ edict_t *findradius (edict_t *from, vec3_t org, float rad)
from = g_edicts;
else
from++;
- for ( ; from < &g_edicts[globals.num_edicts]; from++)
- {
+ for (; from < &g_edicts[globals.num_edicts]; from++) {
if (!from->inuse)
continue;
if (from->solid == SOLID_NOT)
continue;
- for (j=0 ; j<3 ; j++)
- eorg[j] = org[j] - (from->s.origin[j] + (from->mins[j] + from->maxs[j])*0.5);
+ for (j = 0 ; j < 3 ; j++)
+ eorg[j] = org[j] - (from->s.origin[j] + (from->mins[j] + from->maxs[j]) * 0.5);
if (VectorLength(eorg) > rad)
continue;
return from;
@@ -115,21 +113,19 @@ NULL will be returned if the end of the list is reached.
*/
#define MAXCHOICES 8
-edict_t *G_PickTarget (char *targetname)
+edict_t *G_PickTarget(char *targetname)
{
edict_t *ent = NULL;
int num_choices = 0;
edict_t *choice[MAXCHOICES];
- if (!targetname)
- {
+ if (!targetname) {
gi.dprintf("G_PickTarget called with NULL targetname\n");
return NULL;
}
- while(1)
- {
- ent = G_Find (ent, FOFS(targetname), targetname);
+ while (1) {
+ ent = G_Find(ent, FOFS(targetname), targetname);
if (!ent)
break;
choice[num_choices++] = ent;
@@ -137,8 +133,7 @@ edict_t *G_PickTarget (char *targetname)
break;
}
- if (!num_choices)
- {
+ if (!num_choices) {
gi.dprintf("G_PickTarget: target %s not found\n", targetname);
return NULL;
}
@@ -148,10 +143,10 @@ edict_t *G_PickTarget (char *targetname)
-void Think_Delay (edict_t *ent)
+void Think_Delay(edict_t *ent)
{
- G_UseTargets (ent, ent->activator);
- G_FreeEdict (ent);
+ G_UseTargets(ent, ent->activator);
+ G_FreeEdict(ent);
}
/*
@@ -170,53 +165,48 @@ match (string)self.target and call their .use function
==============================
*/
-void G_UseTargets (edict_t *ent, edict_t *activator)
+void G_UseTargets(edict_t *ent, edict_t *activator)
{
edict_t *t;
//
// check for a delay
//
- if (ent->delay)
- {
- // create a temp object to fire at a later time
+ if (ent->delay) {
+ // create a temp object to fire at a later time
t = G_Spawn();
t->classname = "DelayedUse";
t->nextthink = level.time + ent->delay;
t->think = Think_Delay;
t->activator = activator;
if (!activator)
- gi.dprintf ("Think_Delay with no activator\n");
+ gi.dprintf("Think_Delay with no activator\n");
t->message = ent->message;
t->target = ent->target;
t->killtarget = ent->killtarget;
return;
}
-
-
+
+
//
// print the message
//
- if ((ent->message) && !(activator->svflags & SVF_MONSTER))
- {
- gi.centerprintf (activator, "%s", ent->message);
+ if ((ent->message) && !(activator->svflags & SVF_MONSTER)) {
+ gi.centerprintf(activator, "%s", ent->message);
if (ent->noise_index)
- gi.sound (activator, CHAN_AUTO, ent->noise_index, 1, ATTN_NORM, 0);
+ gi.sound(activator, CHAN_AUTO, ent->noise_index, 1, ATTN_NORM, 0);
else
- gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/talk1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
//
// kill killtargets
//
- if (ent->killtarget)
- {
+ if (ent->killtarget) {
t = NULL;
- while ((t = G_Find (t, FOFS(targetname), ent->killtarget)))
- {
- G_FreeEdict (t);
- if (!ent->inuse)
- {
+ while ((t = G_Find(t, FOFS(targetname), ent->killtarget))) {
+ G_FreeEdict(t);
+ if (!ent->inuse) {
gi.dprintf("entity was removed while using killtargets\n");
return;
}
@@ -226,27 +216,21 @@ void G_UseTargets (edict_t *ent, edict_t *activator)
//
// fire targets
//
- if (ent->target)
- {
+ if (ent->target) {
t = NULL;
- while ((t = G_Find (t, FOFS(targetname), ent->target)))
- {
+ while ((t = G_Find(t, FOFS(targetname), ent->target))) {
// doors fire area portals in a specific way
if (!Q_stricmp(t->classname, "func_areaportal") &&
(!Q_stricmp(ent->classname, "func_door") || !Q_stricmp(ent->classname, "func_door_rotating")))
continue;
- if (t == ent)
- {
- gi.dprintf ("WARNING: Entity used itself.\n");
- }
- else
- {
+ if (t == ent) {
+ gi.dprintf("WARNING: Entity used itself.\n");
+ } else {
if (t->use)
- t->use (t, ent, activator);
+ t->use(t, ent, activator);
}
- if (!ent->inuse)
- {
+ if (!ent->inuse) {
gi.dprintf("entity was removed while using targets\n");
return;
}
@@ -263,7 +247,7 @@ This is just a convenience function
for making temporary vectors for function calls
=============
*/
-float *tv (float x, float y, float z)
+float *tv(float x, float y, float z)
{
static int index;
static vec3_t vecs[8];
@@ -272,7 +256,7 @@ float *tv (float x, float y, float z)
// use an array so that multiple tempvectors won't collide
// for a while
v = vecs[index];
- index = (index + 1)&7;
+ index = (index + 1) & 7;
v[0] = x;
v[1] = y;
@@ -290,7 +274,7 @@ This is just a convenience function
for printing vectors
=============
*/
-char *vtos (vec3_t v)
+char *vtos(vec3_t v)
{
static int index;
static char str[8][32];
@@ -298,9 +282,9 @@ char *vtos (vec3_t v)
// use an array so that multiple vtos won't collide
s = str[index];
- index = (index + 1)&7;
+ index = (index + 1) & 7;
- Q_snprintf (s, 32, "(%i %i %i)", (int)v[0], (int)v[1], (int)v[2]);
+ Q_snprintf(s, 32, "(%i %i %i)", (int)v[0], (int)v[1], (int)v[2]);
return s;
}
@@ -311,40 +295,32 @@ vec3_t MOVEDIR_UP = {0, 0, 1};
vec3_t VEC_DOWN = {0, -2, 0};
vec3_t MOVEDIR_DOWN = {0, 0, -1};
-void G_SetMovedir (vec3_t angles, vec3_t movedir)
+void G_SetMovedir(vec3_t angles, vec3_t movedir)
{
- if (VectorCompare (angles, VEC_UP))
- {
- VectorCopy (MOVEDIR_UP, movedir);
- }
- else if (VectorCompare (angles, VEC_DOWN))
- {
- VectorCopy (MOVEDIR_DOWN, movedir);
- }
- else
- {
- AngleVectors (angles, movedir, NULL, NULL);
+ if (VectorCompare(angles, VEC_UP)) {
+ VectorCopy(MOVEDIR_UP, movedir);
+ } else if (VectorCompare(angles, VEC_DOWN)) {
+ VectorCopy(MOVEDIR_DOWN, movedir);
+ } else {
+ AngleVectors(angles, movedir, NULL, NULL);
}
- VectorClear (angles);
+ VectorClear(angles);
}
-float vectoyaw (vec3_t vec)
+float vectoyaw(vec3_t vec)
{
float yaw;
-
- if (/*vec[YAW] == 0 &&*/ vec[PITCH] == 0)
- {
+
+ if (/*vec[YAW] == 0 &&*/ vec[PITCH] == 0) {
yaw = 0;
if (vec[YAW] > 0)
yaw = 90;
else if (vec[YAW] < 0)
yaw = -90;
- }
- else
- {
- yaw = (int) (atan2(vec[YAW], vec[PITCH]) * 180 / M_PI);
+ } else {
+ yaw = (int)(atan2(vec[YAW], vec[PITCH]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
}
@@ -353,23 +329,20 @@ float vectoyaw (vec3_t vec)
}
-void vectoangles (vec3_t value1, vec3_t angles)
+void vectoangles(vec3_t value1, vec3_t angles)
{
float forward;
float yaw, pitch;
-
- if (value1[1] == 0 && value1[0] == 0)
- {
+
+ if (value1[1] == 0 && value1[0] == 0) {
yaw = 0;
if (value1[2] > 0)
pitch = 90;
else
pitch = 270;
- }
- else
- {
+ } else {
if (value1[0])
- yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
+ yaw = (int)(atan2(value1[1], value1[0]) * 180 / M_PI);
else if (value1[1] > 0)
yaw = 90;
else
@@ -377,8 +350,8 @@ void vectoangles (vec3_t value1, vec3_t angles)
if (yaw < 0)
yaw += 360;
- forward = sqrt (value1[0]*value1[0] + value1[1]*value1[1]);
- pitch = (int) (atan2(value1[2], forward) * 180 / M_PI);
+ forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
+ pitch = (int)(atan2(value1[2], forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}
@@ -388,17 +361,17 @@ void vectoangles (vec3_t value1, vec3_t angles)
angles[ROLL] = 0;
}
-char *G_CopyString (char *in)
+char *G_CopyString(char *in)
{
char *out;
-
- out = gi.TagMalloc (strlen(in)+1, TAG_LEVEL);
- strcpy (out, in);
+
+ out = gi.TagMalloc(strlen(in) + 1, TAG_LEVEL);
+ strcpy(out, in);
return out;
}
-void G_InitEdict (edict_t *e)
+void G_InitEdict(edict_t *e)
{
e->inuse = qtrue;
e->classname = "noclass";
@@ -417,28 +390,26 @@ instead of being removed and recreated, which can cause interpolated
angles and bad trails.
=================
*/
-edict_t *G_Spawn (void)
+edict_t *G_Spawn(void)
{
int i;
edict_t *e;
- e = &g_edicts[game.maxclients+1];
- for ( i=game.maxclients+1 ; i<globals.num_edicts ; i++, e++)
- {
+ e = &g_edicts[game.maxclients + 1];
+ for (i = game.maxclients + 1 ; i < globals.num_edicts ; i++, e++) {
// the first couple seconds of server time can involve a lot of
// freeing and allocating, so relax the replacement policy
- if (!e->inuse && ( e->freetime < 2 || level.time - e->freetime > 0.5 ) )
- {
- G_InitEdict (e);
+ if (!e->inuse && (e->freetime < 2 || level.time - e->freetime > 0.5)) {
+ G_InitEdict(e);
return e;
}
}
-
+
if (i == game.maxentities)
- gi.error ("ED_Alloc: no free edicts");
-
+ gi.error("ED_Alloc: no free edicts");
+
globals.num_edicts++;
- G_InitEdict (e);
+ G_InitEdict(e);
return e;
}
@@ -449,17 +420,16 @@ G_FreeEdict
Marks the edict as free
=================
*/
-void G_FreeEdict (edict_t *ed)
+void G_FreeEdict(edict_t *ed)
{
- gi.unlinkentity (ed); // unlink from world
+ gi.unlinkentity(ed); // unlink from world
- if ((ed - g_edicts) <= (maxclients->value + BODY_QUEUE_SIZE))
- {
+ if ((ed - g_edicts) <= (maxclients->value + BODY_QUEUE_SIZE)) {
// gi.dprintf("tried to free special edict\n");
return;
}
- memset (ed, 0, sizeof(*ed));
+ memset(ed, 0, sizeof(*ed));
ed->classname = "freed";
ed->freetime = level.time;
ed->inuse = qfalse;
@@ -472,7 +442,7 @@ G_TouchTriggers
============
*/
-void G_TouchTriggers (edict_t *ent)
+void G_TouchTriggers(edict_t *ent)
{
int i, num;
edict_t *touch[MAX_EDICTS], *hit;
@@ -481,19 +451,18 @@ void G_TouchTriggers (edict_t *ent)
if ((ent->client || (ent->svflags & SVF_MONSTER)) && (ent->health <= 0))
return;
- num = gi.BoxEdicts (ent->absmin, ent->absmax, touch
- , MAX_EDICTS, AREA_TRIGGERS);
+ num = gi.BoxEdicts(ent->absmin, ent->absmax, touch
+ , MAX_EDICTS, AREA_TRIGGERS);
// be careful, it is possible to have an entity in this
// list removed before we get to it (killtriggered)
- for (i=0 ; i<num ; i++)
- {
+ for (i = 0 ; i < num ; i++) {
hit = touch[i];
if (!hit->inuse)
continue;
if (!hit->touch)
continue;
- hit->touch (hit, ent, NULL, NULL);
+ hit->touch(hit, ent, NULL, NULL);
}
}
@@ -505,23 +474,22 @@ Call after linking a new trigger in during gameplay
to force all entities it covers to immediately touch it
============
*/
-void G_TouchSolids (edict_t *ent)
+void G_TouchSolids(edict_t *ent)
{
int i, num;
edict_t *touch[MAX_EDICTS], *hit;
- num = gi.BoxEdicts (ent->absmin, ent->absmax, touch
- , MAX_EDICTS, AREA_SOLID);
+ num = gi.BoxEdicts(ent->absmin, ent->absmax, touch
+ , MAX_EDICTS, AREA_SOLID);
// be careful, it is possible to have an entity in this
// list removed before we get to it (killtriggered)
- for (i=0 ; i<num ; i++)
- {
+ for (i = 0 ; i < num ; i++) {
hit = touch[i];
if (!hit->inuse)
continue;
if (ent->touch)
- ent->touch (hit, ent, NULL, NULL);
+ ent->touch(hit, ent, NULL, NULL);
if (!ent->inuse)
break;
}
@@ -546,18 +514,17 @@ Kills all entities that would touch the proposed new positioning
of ent. Ent should be unlinked before calling this!
=================
*/
-qboolean KillBox (edict_t *ent)
+qboolean KillBox(edict_t *ent)
{
trace_t tr;
- while (1)
- {
- tr = gi.trace (ent->s.origin, ent->mins, ent->maxs, ent->s.origin, NULL, MASK_PLAYERSOLID);
+ while (1) {
+ tr = gi.trace(ent->s.origin, ent->mins, ent->maxs, ent->s.origin, NULL, MASK_PLAYERSOLID);
if (!tr.ent)
break;
// nail it
- T_Damage (tr.ent, ent, ent, vec3_origin, ent->s.origin, vec3_origin, 100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
+ T_Damage(tr.ent, ent, ent, vec3_origin, ent->s.origin, vec3_origin, 100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
// if we didn't kill it, fail
if (tr.ent->solid)
diff --git a/src/baseq2/g_weapon.c b/src/baseq2/g_weapon.c
index 95d8765..26bca48 100644
--- a/src/baseq2/g_weapon.c
+++ b/src/baseq2/g_weapon.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,7 +29,7 @@ a non-instant attack weapon. It checks to see if a
monster's dodge function should be called.
=================
*/
-static void check_dodge (edict_t *self, vec3_t start, vec3_t dir, int speed)
+static void check_dodge(edict_t *self, vec3_t start, vec3_t dir, int speed)
{
vec3_t end;
vec3_t v;
@@ -37,18 +37,16 @@ static void check_dodge (edict_t *self, vec3_t start, vec3_t dir, int speed)
float eta;
// easy mode only ducks one quarter the time
- if (skill->value == 0)
- {
+ if (skill->value == 0) {
if (random() > 0.25)
return;
}
- VectorMA (start, 8192, dir, end);
- tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
- if ((tr.ent) && (tr.ent->svflags & SVF_MONSTER) && (tr.ent->health > 0) && (tr.ent->monsterinfo.dodge) && infront(tr.ent, self))
- {
- VectorSubtract (tr.endpos, start, v);
+ VectorMA(start, 8192, dir, end);
+ tr = gi.trace(start, NULL, NULL, end, self, MASK_SHOT);
+ if ((tr.ent) && (tr.ent->svflags & SVF_MONSTER) && (tr.ent->health > 0) && (tr.ent->monsterinfo.dodge) && infront(tr.ent, self)) {
+ VectorSubtract(tr.endpos, start, v);
eta = (VectorLength(v) - tr.ent->maxs[0]) / speed;
- tr.ent->monsterinfo.dodge (tr.ent, self, eta);
+ tr.ent->monsterinfo.dodge(tr.ent, self, eta);
}
}
@@ -60,7 +58,7 @@ fire_hit
Used for all impact (hit/punch/slash) attacks
=================
*/
-qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
+qboolean fire_hit(edict_t *self, vec3_t aim, int damage, int kick)
{
trace_t tr;
vec3_t forward, right, up;
@@ -70,18 +68,15 @@ qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
vec3_t dir;
//see if enemy is in range
- VectorSubtract (self->enemy->s.origin, self->s.origin, dir);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
range = VectorLength(dir);
if (range > aim[0])
return qfalse;
- if (aim[1] > self->mins[0] && aim[1] < self->maxs[0])
- {
+ if (aim[1] > self->mins[0] && aim[1] < self->maxs[0]) {
// the hit is straight on so back the range up to the edge of their bbox
range -= self->enemy->maxs[0];
- }
- else
- {
+ } else {
// this is a side hit so adjust the "right" value out to the edge of their bbox
if (aim[1] < 0)
aim[1] = self->enemy->mins[0];
@@ -89,11 +84,10 @@ qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
aim[1] = self->enemy->maxs[0];
}
- VectorMA (self->s.origin, range, dir, point);
+ VectorMA(self->s.origin, range, dir, point);
- tr = gi.trace (self->s.origin, NULL, NULL, point, self, MASK_SHOT);
- if (tr.fraction < 1)
- {
+ tr = gi.trace(self->s.origin, NULL, NULL, point, self, MASK_SHOT);
+ if (tr.fraction < 1) {
if (!tr.ent->takedamage)
return qfalse;
// if it will hit any client/monster then hit the one we wanted to hit
@@ -102,22 +96,22 @@ qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
}
AngleVectors(self->s.angles, forward, right, up);
- VectorMA (self->s.origin, range, forward, point);
- VectorMA (point, aim[1], right, point);
- VectorMA (point, aim[2], up, point);
- VectorSubtract (point, self->enemy->s.origin, dir);
+ VectorMA(self->s.origin, range, forward, point);
+ VectorMA(point, aim[1], right, point);
+ VectorMA(point, aim[2], up, point);
+ VectorSubtract(point, self->enemy->s.origin, dir);
// do the damage
- T_Damage (tr.ent, self, self, dir, point, vec3_origin, damage, kick/2, DAMAGE_NO_KNOCKBACK, MOD_HIT);
+ T_Damage(tr.ent, self, self, dir, point, vec3_origin, damage, kick / 2, DAMAGE_NO_KNOCKBACK, MOD_HIT);
if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
return qfalse;
// do our special form of knockback here
- VectorMA (self->enemy->absmin, 0.5, self->enemy->size, v);
- VectorSubtract (v, point, v);
- VectorNormalize (v);
- VectorMA (self->enemy->velocity, kick, v, self->enemy->velocity);
+ VectorMA(self->enemy->absmin, 0.5, self->enemy->size, v);
+ VectorSubtract(v, point, v);
+ VectorNormalize(v);
+ VectorMA(self->enemy->velocity, kick, v, self->enemy->velocity);
if (self->enemy->velocity[2] > 0)
self->enemy->groundentity = NULL;
return qtrue;
@@ -131,7 +125,7 @@ fire_lead
This is an internal support routine used for bullet/pellet based weapons.
=================
*/
-static void fire_lead (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int te_impact, int hspread, int vspread, int mod)
+static void fire_lead(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int te_impact, int hspread, int vspread, int mod)
{
trace_t tr;
vec3_t dir;
@@ -143,96 +137,83 @@ static void fire_lead (edict_t *self, vec3_t start, vec3_t aimdir, int damage, i
qboolean water = qfalse;
int content_mask = MASK_SHOT | MASK_WATER;
- tr = gi.trace (self->s.origin, NULL, NULL, start, self, MASK_SHOT);
- if (!(tr.fraction < 1.0))
- {
- vectoangles (aimdir, dir);
- AngleVectors (dir, forward, right, up);
+ tr = gi.trace(self->s.origin, NULL, NULL, start, self, MASK_SHOT);
+ if (!(tr.fraction < 1.0)) {
+ vectoangles(aimdir, dir);
+ AngleVectors(dir, forward, right, up);
- r = crandom()*hspread;
- u = crandom()*vspread;
- VectorMA (start, 8192, forward, end);
- VectorMA (end, r, right, end);
- VectorMA (end, u, up, end);
+ r = crandom() * hspread;
+ u = crandom() * vspread;
+ VectorMA(start, 8192, forward, end);
+ VectorMA(end, r, right, end);
+ VectorMA(end, u, up, end);
- if (gi.pointcontents (start) & MASK_WATER)
- {
+ if (gi.pointcontents(start) & MASK_WATER) {
water = qtrue;
- VectorCopy (start, water_start);
+ VectorCopy(start, water_start);
content_mask &= ~MASK_WATER;
}
- tr = gi.trace (start, NULL, NULL, end, self, content_mask);
+ tr = gi.trace(start, NULL, NULL, end, self, content_mask);
// see if we hit water
- if (tr.contents & MASK_WATER)
- {
+ if (tr.contents & MASK_WATER) {
int color;
water = qtrue;
- VectorCopy (tr.endpos, water_start);
+ VectorCopy(tr.endpos, water_start);
- if (!VectorCompare (start, tr.endpos))
- {
- if (tr.contents & CONTENTS_WATER)
- {
+ if (!VectorCompare(start, tr.endpos)) {
+ if (tr.contents & CONTENTS_WATER) {
if (strcmp(tr.surface->name, "*brwater") == 0)
color = SPLASH_BROWN_WATER;
else
color = SPLASH_BLUE_WATER;
- }
- else if (tr.contents & CONTENTS_SLIME)
+ } else if (tr.contents & CONTENTS_SLIME)
color = SPLASH_SLIME;
else if (tr.contents & CONTENTS_LAVA)
color = SPLASH_LAVA;
else
color = SPLASH_UNKNOWN;
- if (color != SPLASH_UNKNOWN)
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_SPLASH);
- gi.WriteByte (8);
- gi.WritePosition (tr.endpos);
- gi.WriteDir (tr.plane.normal);
- gi.WriteByte (color);
- gi.multicast (tr.endpos, MULTICAST_PVS);
+ if (color != SPLASH_UNKNOWN) {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_SPLASH);
+ gi.WriteByte(8);
+ gi.WritePosition(tr.endpos);
+ gi.WriteDir(tr.plane.normal);
+ gi.WriteByte(color);
+ gi.multicast(tr.endpos, MULTICAST_PVS);
}
// change bullet's course when it enters water
- VectorSubtract (end, start, dir);
- vectoangles (dir, dir);
- AngleVectors (dir, forward, right, up);
- r = crandom()*hspread*2;
- u = crandom()*vspread*2;
- VectorMA (water_start, 8192, forward, end);
- VectorMA (end, r, right, end);
- VectorMA (end, u, up, end);
+ VectorSubtract(end, start, dir);
+ vectoangles(dir, dir);
+ AngleVectors(dir, forward, right, up);
+ r = crandom() * hspread * 2;
+ u = crandom() * vspread * 2;
+ VectorMA(water_start, 8192, forward, end);
+ VectorMA(end, r, right, end);
+ VectorMA(end, u, up, end);
}
// re-trace ignoring water this time
- tr = gi.trace (water_start, NULL, NULL, end, self, MASK_SHOT);
+ tr = gi.trace(water_start, NULL, NULL, end, self, MASK_SHOT);
}
}
// send gun puff / flash
- if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
- {
- if (tr.fraction < 1.0)
- {
- if (tr.ent->takedamage)
- {
- T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
- }
- else
- {
- if (strncmp (tr.surface->name, "sky", 3) != 0)
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (te_impact);
- gi.WritePosition (tr.endpos);
- gi.WriteDir (tr.plane.normal);
- gi.multicast (tr.endpos, MULTICAST_PVS);
+ if (!((tr.surface) && (tr.surface->flags & SURF_SKY))) {
+ if (tr.fraction < 1.0) {
+ if (tr.ent->takedamage) {
+ T_Damage(tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
+ } else {
+ if (strncmp(tr.surface->name, "sky", 3) != 0) {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(te_impact);
+ gi.WritePosition(tr.endpos);
+ gi.WriteDir(tr.plane.normal);
+ gi.multicast(tr.endpos, MULTICAST_PVS);
if (self->client)
PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
@@ -242,26 +223,25 @@ static void fire_lead (edict_t *self, vec3_t start, vec3_t aimdir, int damage, i
}
// if went through water, determine where the end and make a bubble trail
- if (water)
- {
+ if (water) {
vec3_t pos;
- VectorSubtract (tr.endpos, water_start, dir);
- VectorNormalize (dir);
- VectorMA (tr.endpos, -2, dir, pos);
- if (gi.pointcontents (pos) & MASK_WATER)
- VectorCopy (pos, tr.endpos);
+ VectorSubtract(tr.endpos, water_start, dir);
+ VectorNormalize(dir);
+ VectorMA(tr.endpos, -2, dir, pos);
+ if (gi.pointcontents(pos) & MASK_WATER)
+ VectorCopy(pos, tr.endpos);
else
- tr = gi.trace (pos, NULL, NULL, water_start, tr.ent, MASK_WATER);
+ tr = gi.trace(pos, NULL, NULL, water_start, tr.ent, MASK_WATER);
- VectorAdd (water_start, tr.endpos, pos);
- VectorScale (pos, 0.5, pos);
+ VectorAdd(water_start, tr.endpos, pos);
+ VectorScale(pos, 0.5, pos);
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BUBBLETRAIL);
- gi.WritePosition (water_start);
- gi.WritePosition (tr.endpos);
- gi.multicast (pos, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BUBBLETRAIL);
+ gi.WritePosition(water_start);
+ gi.WritePosition(tr.endpos);
+ gi.multicast(pos, MULTICAST_PVS);
}
}
@@ -274,9 +254,9 @@ Fires a single round. Used for machinegun and chaingun. Would be fine for
pistols, rifles, etc....
=================
*/
-void fire_bullet (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod)
+void fire_bullet(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod)
{
- fire_lead (self, start, aimdir, damage, kick, TE_GUNSHOT, hspread, vspread, mod);
+ fire_lead(self, start, aimdir, damage, kick, TE_GUNSHOT, hspread, vspread, mod);
}
@@ -287,12 +267,12 @@ fire_shotgun
Shoots shotgun pellets. Used by shotgun and super shotgun.
=================
*/
-void fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod)
+void fire_shotgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod)
{
int i;
for (i = 0; i < count; i++)
- fire_lead (self, start, aimdir, damage, kick, TE_SHOTGUN, hspread, vspread, mod);
+ fire_lead(self, start, aimdir, damage, kick, TE_SHOTGUN, hspread, vspread, mod);
}
@@ -303,51 +283,47 @@ fire_blaster
Fires a single blaster bolt. Used by the blaster and hyper blaster.
=================
*/
-void blaster_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void blaster_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
int mod;
if (other == self->owner)
return;
- if (surf && (surf->flags & SURF_SKY))
- {
- G_FreeEdict (self);
+ if (surf && (surf->flags & SURF_SKY)) {
+ G_FreeEdict(self);
return;
}
if (self->owner->client)
PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
- if (other->takedamage)
- {
+ if (other->takedamage) {
if (self->spawnflags & 1)
mod = MOD_HYPERBLASTER;
else
mod = MOD_BLASTER;
- T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, self->dmg, 1, DAMAGE_ENERGY, mod);
- }
- else
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BLASTER);
- gi.WritePosition (self->s.origin);
+ T_Damage(other, self, self->owner, self->velocity, self->s.origin, plane->normal, self->dmg, 1, DAMAGE_ENERGY, mod);
+ } else {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BLASTER);
+ gi.WritePosition(self->s.origin);
if (!plane)
- gi.WriteDir (vec3_origin);
+ gi.WriteDir(vec3_origin);
else
- gi.WriteDir (plane->normal);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteDir(plane->normal);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
}
- G_FreeEdict (self);
+ G_FreeEdict(self);
}
-void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int effect, qboolean hyper)
+void fire_blaster(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int effect, qboolean hyper)
{
edict_t *bolt;
trace_t tr;
- VectorNormalize (dir);
+ VectorNormalize(dir);
bolt = G_Spawn();
bolt->svflags = SVF_DEADMONSTER;
@@ -356,18 +332,18 @@ void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int spee
// (blaster/hyperblaster shots), the player won't be solid clipped against
// the object. Right now trying to run into a firing hyperblaster
// is very jerky since you are predicted 'against' the shots.
- VectorCopy (start, bolt->s.origin);
- VectorCopy (start, bolt->s.old_origin);
- vectoangles (dir, bolt->s.angles);
- VectorScale (dir, speed, bolt->velocity);
+ VectorCopy(start, bolt->s.origin);
+ VectorCopy(start, bolt->s.old_origin);
+ vectoangles(dir, bolt->s.angles);
+ VectorScale(dir, speed, bolt->velocity);
bolt->movetype = MOVETYPE_FLYMISSILE;
bolt->clipmask = MASK_SHOT;
bolt->solid = SOLID_BBOX;
bolt->s.effects |= effect;
- VectorClear (bolt->mins);
- VectorClear (bolt->maxs);
- bolt->s.modelindex = gi.modelindex ("models/objects/laser/tris.md2");
- bolt->s.sound = gi.soundindex ("misc/lasfly.wav");
+ VectorClear(bolt->mins);
+ VectorClear(bolt->maxs);
+ bolt->s.modelindex = gi.modelindex("models/objects/laser/tris.md2");
+ bolt->s.sound = gi.soundindex("misc/lasfly.wav");
bolt->owner = self;
bolt->touch = blaster_touch;
bolt->nextthink = level.time + 2;
@@ -376,18 +352,17 @@ void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int spee
bolt->classname = "bolt";
if (hyper)
bolt->spawnflags = 1;
- gi.linkentity (bolt);
+ gi.linkentity(bolt);
if (self->client)
- check_dodge (self, bolt->s.origin, dir, speed);
+ check_dodge(self, bolt->s.origin, dir, speed);
- tr = gi.trace (self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
- if (tr.fraction < 1.0)
- {
- VectorMA (bolt->s.origin, -10, dir, bolt->s.origin);
- bolt->touch (bolt, tr.ent, NULL, NULL);
+ tr = gi.trace(self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
+ if (tr.fraction < 1.0) {
+ VectorMA(bolt->s.origin, -10, dir, bolt->s.origin);
+ bolt->touch(bolt, tr.ent, NULL, NULL);
}
-}
+}
/*
@@ -395,7 +370,7 @@ void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int spee
fire_grenade
=================
*/
-void Grenade_Explode (edict_t *ent)
+void Grenade_Explode(edict_t *ent)
{
vec3_t origin;
int mod;
@@ -404,22 +379,21 @@ void Grenade_Explode (edict_t *ent)
PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
//FIXME: if we are onground then raise our Z just a bit since we are a point?
- if (ent->enemy)
- {
+ if (ent->enemy) {
float points;
vec3_t v;
vec3_t dir;
- VectorAdd (ent->enemy->mins, ent->enemy->maxs, v);
- VectorMA (ent->enemy->s.origin, 0.5, v, v);
- VectorSubtract (ent->s.origin, v, v);
- points = ent->dmg - 0.5 * VectorLength (v);
- VectorSubtract (ent->enemy->s.origin, ent->s.origin, dir);
+ VectorAdd(ent->enemy->mins, ent->enemy->maxs, v);
+ VectorMA(ent->enemy->s.origin, 0.5, v, v);
+ VectorSubtract(ent->s.origin, v, v);
+ points = ent->dmg - 0.5 * VectorLength(v);
+ VectorSubtract(ent->enemy->s.origin, ent->s.origin, dir);
if (ent->spawnflags & 1)
mod = MOD_HANDGRENADE;
else
mod = MOD_GRENADE;
- T_Damage (ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
+ T_Damage(ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
}
if (ent->spawnflags & 2)
@@ -430,81 +404,73 @@ void Grenade_Explode (edict_t *ent)
mod = MOD_G_SPLASH;
T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy, ent->dmg_radius, mod);
- VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
- gi.WriteByte (svc_temp_entity);
- if (ent->waterlevel)
- {
+ VectorMA(ent->s.origin, -0.02, ent->velocity, origin);
+ gi.WriteByte(svc_temp_entity);
+ if (ent->waterlevel) {
if (ent->groundentity)
- gi.WriteByte (TE_GRENADE_EXPLOSION_WATER);
+ gi.WriteByte(TE_GRENADE_EXPLOSION_WATER);
else
- gi.WriteByte (TE_ROCKET_EXPLOSION_WATER);
- }
- else
- {
+ gi.WriteByte(TE_ROCKET_EXPLOSION_WATER);
+ } else {
if (ent->groundentity)
- gi.WriteByte (TE_GRENADE_EXPLOSION);
+ gi.WriteByte(TE_GRENADE_EXPLOSION);
else
- gi.WriteByte (TE_ROCKET_EXPLOSION);
+ gi.WriteByte(TE_ROCKET_EXPLOSION);
}
- gi.WritePosition (origin);
- gi.multicast (ent->s.origin, MULTICAST_PHS);
+ gi.WritePosition(origin);
+ gi.multicast(ent->s.origin, MULTICAST_PHS);
- G_FreeEdict (ent);
+ G_FreeEdict(ent);
}
-void Grenade_Touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
+void Grenade_Touch(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other == ent->owner)
return;
- if (surf && (surf->flags & SURF_SKY))
- {
- G_FreeEdict (ent);
+ if (surf && (surf->flags & SURF_SKY)) {
+ G_FreeEdict(ent);
return;
}
- if (!other->takedamage)
- {
- if (ent->spawnflags & 1)
- {
+ if (!other->takedamage) {
+ if (ent->spawnflags & 1) {
if (random() > 0.5)
- gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb1a.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/hgrenb1a.wav"), 1, ATTN_NORM, 0);
else
- gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb2a.wav"), 1, ATTN_NORM, 0);
- }
- else
- {
- gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/grenlb1b.wav"), 1, ATTN_NORM, 0);
+ gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/hgrenb2a.wav"), 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/grenlb1b.wav"), 1, ATTN_NORM, 0);
}
return;
}
ent->enemy = other;
- Grenade_Explode (ent);
+ Grenade_Explode(ent);
}
-void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius)
+void fire_grenade(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius)
{
edict_t *grenade;
vec3_t dir;
vec3_t forward, right, up;
- vectoangles (aimdir, dir);
- AngleVectors (dir, forward, right, up);
+ vectoangles(aimdir, dir);
+ AngleVectors(dir, forward, right, up);
grenade = G_Spawn();
- VectorCopy (start, grenade->s.origin);
- VectorScale (aimdir, speed, grenade->velocity);
- VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
- VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
- VectorSet (grenade->avelocity, 300, 300, 300);
+ VectorCopy(start, grenade->s.origin);
+ VectorScale(aimdir, speed, grenade->velocity);
+ VectorMA(grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
+ VectorMA(grenade->velocity, crandom() * 10.0, right, grenade->velocity);
+ VectorSet(grenade->avelocity, 300, 300, 300);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->clipmask = MASK_SHOT;
grenade->solid = SOLID_BBOX;
grenade->s.effects |= EF_GRENADE;
- VectorClear (grenade->mins);
- VectorClear (grenade->maxs);
- grenade->s.modelindex = gi.modelindex ("models/objects/grenade/tris.md2");
+ VectorClear(grenade->mins);
+ VectorClear(grenade->maxs);
+ grenade->s.modelindex = gi.modelindex("models/objects/grenade/tris.md2");
grenade->owner = self;
grenade->touch = Grenade_Touch;
grenade->nextthink = level.time + timer;
@@ -513,31 +479,31 @@ void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int s
grenade->dmg_radius = damage_radius;
grenade->classname = "grenade";
- gi.linkentity (grenade);
+ gi.linkentity(grenade);
}
-void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held)
+void fire_grenade2(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held)
{
edict_t *grenade;
vec3_t dir;
vec3_t forward, right, up;
- vectoangles (aimdir, dir);
- AngleVectors (dir, forward, right, up);
+ vectoangles(aimdir, dir);
+ AngleVectors(dir, forward, right, up);
grenade = G_Spawn();
- VectorCopy (start, grenade->s.origin);
- VectorScale (aimdir, speed, grenade->velocity);
- VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
- VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
- VectorSet (grenade->avelocity, 300, 300, 300);
+ VectorCopy(start, grenade->s.origin);
+ VectorScale(aimdir, speed, grenade->velocity);
+ VectorMA(grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
+ VectorMA(grenade->velocity, crandom() * 10.0, right, grenade->velocity);
+ VectorSet(grenade->avelocity, 300, 300, 300);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->clipmask = MASK_SHOT;
grenade->solid = SOLID_BBOX;
grenade->s.effects |= EF_GRENADE;
- VectorClear (grenade->mins);
- VectorClear (grenade->maxs);
- grenade->s.modelindex = gi.modelindex ("models/objects/grenade2/tris.md2");
+ VectorClear(grenade->mins);
+ VectorClear(grenade->maxs);
+ grenade->s.modelindex = gi.modelindex("models/objects/grenade2/tris.md2");
grenade->owner = self;
grenade->touch = Grenade_Touch;
grenade->nextthink = level.time + timer;
@@ -552,11 +518,10 @@ void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int
grenade->s.sound = gi.soundindex("weapons/hgrenc1b.wav");
if (timer <= 0.0)
- Grenade_Explode (grenade);
- else
- {
- gi.sound (self, CHAN_WEAPON, gi.soundindex ("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
- gi.linkentity (grenade);
+ Grenade_Explode(grenade);
+ else {
+ gi.sound(self, CHAN_WEAPON, gi.soundindex("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
+ gi.linkentity(grenade);
}
}
@@ -566,7 +531,7 @@ void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int
fire_rocket
=================
*/
-void rocket_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
+void rocket_touch(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t origin;
int n;
@@ -574,9 +539,8 @@ void rocket_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *su
if (other == ent->owner)
return;
- if (surf && (surf->flags & SURF_SKY))
- {
- G_FreeEdict (ent);
+ if (surf && (surf->flags & SURF_SKY)) {
+ G_FreeEdict(ent);
return;
}
@@ -584,69 +548,64 @@ void rocket_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *su
PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
// calculate position for the explosion entity
- VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
+ VectorMA(ent->s.origin, -0.02, ent->velocity, origin);
- if (other->takedamage)
- {
- T_Damage (other, ent, ent->owner, ent->velocity, ent->s.origin, plane->normal, ent->dmg, 0, 0, MOD_ROCKET);
- }
- else
- {
+ if (other->takedamage) {
+ T_Damage(other, ent, ent->owner, ent->velocity, ent->s.origin, plane->normal, ent->dmg, 0, 0, MOD_ROCKET);
+ } else {
// don't throw any debris in net games
- if (!deathmatch->value && !coop->value)
- {
- if ((surf) && !(surf->flags & (SURF_WARP|SURF_TRANS33|SURF_TRANS66|SURF_FLOWING)))
- {
+ if (!deathmatch->value && !coop->value) {
+ if ((surf) && !(surf->flags & (SURF_WARP | SURF_TRANS33 | SURF_TRANS66 | SURF_FLOWING))) {
n = rand() % 5;
- while(n--)
- ThrowDebris (ent, "models/objects/debris2/tris.md2", 2, ent->s.origin);
+ while (n--)
+ ThrowDebris(ent, "models/objects/debris2/tris.md2", 2, ent->s.origin);
}
}
}
T_RadiusDamage(ent, ent->owner, ent->radius_dmg, other, ent->dmg_radius, MOD_R_SPLASH);
- gi.WriteByte (svc_temp_entity);
+ gi.WriteByte(svc_temp_entity);
if (ent->waterlevel)
- gi.WriteByte (TE_ROCKET_EXPLOSION_WATER);
+ gi.WriteByte(TE_ROCKET_EXPLOSION_WATER);
else
- gi.WriteByte (TE_ROCKET_EXPLOSION);
- gi.WritePosition (origin);
- gi.multicast (ent->s.origin, MULTICAST_PHS);
+ gi.WriteByte(TE_ROCKET_EXPLOSION);
+ gi.WritePosition(origin);
+ gi.multicast(ent->s.origin, MULTICAST_PHS);
- G_FreeEdict (ent);
+ G_FreeEdict(ent);
}
-void fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage)
+void fire_rocket(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage)
{
edict_t *rocket;
rocket = G_Spawn();
- VectorCopy (start, rocket->s.origin);
- VectorCopy (dir, rocket->movedir);
- vectoangles (dir, rocket->s.angles);
- VectorScale (dir, speed, rocket->velocity);
+ VectorCopy(start, rocket->s.origin);
+ VectorCopy(dir, rocket->movedir);
+ vectoangles(dir, rocket->s.angles);
+ VectorScale(dir, speed, rocket->velocity);
rocket->movetype = MOVETYPE_FLYMISSILE;
rocket->clipmask = MASK_SHOT;
rocket->solid = SOLID_BBOX;
rocket->s.effects |= EF_ROCKET;
- VectorClear (rocket->mins);
- VectorClear (rocket->maxs);
- rocket->s.modelindex = gi.modelindex ("models/objects/rocket/tris.md2");
+ VectorClear(rocket->mins);
+ VectorClear(rocket->maxs);
+ rocket->s.modelindex = gi.modelindex("models/objects/rocket/tris.md2");
rocket->owner = self;
rocket->touch = rocket_touch;
- rocket->nextthink = level.time + 8000/speed;
+ rocket->nextthink = level.time + 8000 / speed;
rocket->think = G_FreeEdict;
rocket->dmg = damage;
rocket->radius_dmg = radius_damage;
rocket->dmg_radius = damage_radius;
- rocket->s.sound = gi.soundindex ("weapons/rockfly.wav");
+ rocket->s.sound = gi.soundindex("weapons/rockfly.wav");
rocket->classname = "rocket";
if (self->client)
- check_dodge (self, rocket->s.origin, dir, speed);
+ check_dodge(self, rocket->s.origin, dir, speed);
- gi.linkentity (rocket);
+ gi.linkentity(rocket);
}
@@ -655,7 +614,7 @@ void fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed
fire_rail
=================
*/
-void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick)
+void fire_rail(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick)
{
vec3_t from;
vec3_t end;
@@ -664,22 +623,18 @@ void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick
int mask;
qboolean water;
- VectorMA (start, 8192, aimdir, end);
- VectorCopy (start, from);
+ VectorMA(start, 8192, aimdir, end);
+ VectorCopy(start, from);
ignore = self;
water = qfalse;
- mask = MASK_SHOT|CONTENTS_SLIME|CONTENTS_LAVA;
- while (ignore)
- {
- tr = gi.trace (from, NULL, NULL, end, ignore, mask);
-
- if (tr.contents & (CONTENTS_SLIME|CONTENTS_LAVA))
- {
- mask &= ~(CONTENTS_SLIME|CONTENTS_LAVA);
+ mask = MASK_SHOT | CONTENTS_SLIME | CONTENTS_LAVA;
+ while (ignore) {
+ tr = gi.trace(from, NULL, NULL, end, ignore, mask);
+
+ if (tr.contents & (CONTENTS_SLIME | CONTENTS_LAVA)) {
+ mask &= ~(CONTENTS_SLIME | CONTENTS_LAVA);
water = qtrue;
- }
- else
- {
+ } else {
//ZOID--added so rail goes through SOLID_BBOX entities (gibs, etc)
if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client) ||
(tr.ent->solid == SOLID_BBOX))
@@ -688,26 +643,25 @@ void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick
ignore = NULL;
if ((tr.ent != self) && (tr.ent->takedamage))
- T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);
+ T_Damage(tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);
}
- VectorCopy (tr.endpos, from);
+ VectorCopy(tr.endpos, from);
}
// send gun puff / flash
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_RAILTRAIL);
- gi.WritePosition (start);
- gi.WritePosition (tr.endpos);
- gi.multicast (self->s.origin, MULTICAST_PHS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_RAILTRAIL);
+ gi.WritePosition(start);
+ gi.WritePosition(tr.endpos);
+ gi.multicast(self->s.origin, MULTICAST_PHS);
// gi.multicast (start, MULTICAST_PHS);
- if (water)
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_RAILTRAIL);
- gi.WritePosition (start);
- gi.WritePosition (tr.endpos);
- gi.multicast (tr.endpos, MULTICAST_PHS);
+ if (water) {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_RAILTRAIL);
+ gi.WritePosition(start);
+ gi.WritePosition(tr.endpos);
+ gi.multicast(tr.endpos, MULTICAST_PHS);
}
if (self->client)
@@ -720,41 +674,39 @@ void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick
fire_bfg
=================
*/
-void bfg_explode (edict_t *self)
+void bfg_explode(edict_t *self)
{
edict_t *ent;
float points;
vec3_t v;
float dist;
- if (self->s.frame == 0)
- {
+ if (self->s.frame == 0) {
// the BFG effect
ent = NULL;
- while ((ent = findradius(ent, self->s.origin, self->dmg_radius)) != NULL)
- {
+ while ((ent = findradius(ent, self->s.origin, self->dmg_radius)) != NULL) {
if (!ent->takedamage)
continue;
if (ent == self->owner)
continue;
- if (!CanDamage (ent, self))
+ if (!CanDamage(ent, self))
continue;
- if (!CanDamage (ent, self->owner))
+ if (!CanDamage(ent, self->owner))
continue;
- VectorAdd (ent->mins, ent->maxs, v);
- VectorMA (ent->s.origin, 0.5, v, v);
- VectorSubtract (self->s.origin, v, v);
+ VectorAdd(ent->mins, ent->maxs, v);
+ VectorMA(ent->s.origin, 0.5, v, v);
+ VectorSubtract(self->s.origin, v, v);
dist = VectorLength(v);
- points = self->radius_dmg * (1.0 - sqrt(dist/self->dmg_radius));
+ points = self->radius_dmg * (1.0 - sqrt(dist / self->dmg_radius));
if (ent == self->owner)
points = points * 0.5;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BFG_EXPLOSION);
- gi.WritePosition (ent->s.origin);
- gi.multicast (ent->s.origin, MULTICAST_PHS);
- T_Damage (ent, self, self->owner, self->velocity, ent->s.origin, vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BFG_EXPLOSION);
+ gi.WritePosition(ent->s.origin);
+ gi.multicast(ent->s.origin, MULTICAST_PHS);
+ T_Damage(ent, self, self->owner, self->velocity, ent->s.origin, vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
}
}
@@ -764,14 +716,13 @@ void bfg_explode (edict_t *self)
self->think = G_FreeEdict;
}
-void bfg_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void bfg_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other == self->owner)
return;
- if (surf && (surf->flags & SURF_SKY))
- {
- G_FreeEdict (self);
+ if (surf && (surf->flags & SURF_SKY)) {
+ G_FreeEdict(self);
return;
}
@@ -780,15 +731,15 @@ void bfg_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf
// core explosion - prevents firing it into the wall/floor
if (other->takedamage)
- T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, 200, 0, 0, MOD_BFG_BLAST);
+ T_Damage(other, self, self->owner, self->velocity, self->s.origin, plane->normal, 200, 0, 0, MOD_BFG_BLAST);
T_RadiusDamage(self, self->owner, 200, other, 100, MOD_BFG_BLAST);
- gi.sound (self, CHAN_VOICE, gi.soundindex ("weapons/bfg__x1b.wav"), 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, gi.soundindex("weapons/bfg__x1b.wav"), 1, ATTN_NORM, 0);
self->solid = SOLID_NOT;
self->touch = NULL;
- VectorMA (self->s.origin, -1 * FRAMETIME, self->velocity, self->s.origin);
- VectorClear (self->velocity);
- self->s.modelindex = gi.modelindex ("sprites/s_bfg3.sp2");
+ VectorMA(self->s.origin, -1 * FRAMETIME, self->velocity, self->s.origin);
+ VectorClear(self->velocity);
+ self->s.modelindex = gi.modelindex("sprites/s_bfg3.sp2");
self->s.frame = 0;
self->s.sound = 0;
self->s.effects &= ~EF_ANIM_ALLFAST;
@@ -796,14 +747,14 @@ void bfg_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf
self->nextthink = level.time + FRAMETIME;
self->enemy = other;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BFG_BIGEXPLOSION);
- gi.WritePosition (self->s.origin);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BFG_BIGEXPLOSION);
+ gi.WritePosition(self->s.origin);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
}
-void bfg_think (edict_t *self)
+void bfg_think(edict_t *self)
{
edict_t *ent;
edict_t *ignore;
@@ -820,8 +771,7 @@ void bfg_think (edict_t *self)
dmg = 10;
ent = NULL;
- while ((ent = findradius(ent, self->s.origin, 256)) != NULL)
- {
+ while ((ent = findradius(ent, self->s.origin, 256)) != NULL) {
if (ent == self)
continue;
@@ -834,77 +784,75 @@ void bfg_think (edict_t *self)
if (!(ent->svflags & SVF_MONSTER) && (!ent->client) && (strcmp(ent->classname, "misc_explobox") != 0))
continue;
- VectorMA (ent->absmin, 0.5, ent->size, point);
+ VectorMA(ent->absmin, 0.5, ent->size, point);
- VectorSubtract (point, self->s.origin, dir);
- VectorNormalize (dir);
+ VectorSubtract(point, self->s.origin, dir);
+ VectorNormalize(dir);
ignore = self;
- VectorCopy (self->s.origin, start);
- VectorMA (start, 2048, dir, end);
- while(1)
- {
- tr = gi.trace (start, NULL, NULL, end, ignore, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
+ VectorCopy(self->s.origin, start);
+ VectorMA(start, 2048, dir, end);
+ while (1) {
+ tr = gi.trace(start, NULL, NULL, end, ignore, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_DEADMONSTER);
if (!tr.ent)
break;
// hurt it if we can
if ((tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER) && (tr.ent != self->owner))
- T_Damage (tr.ent, self, self->owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);
+ T_Damage(tr.ent, self, self->owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);
// if we hit something that's not a monster or player we're done
- if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_LASER_SPARKS);
- gi.WriteByte (4);
- gi.WritePosition (tr.endpos);
- gi.WriteDir (tr.plane.normal);
- gi.WriteByte (self->s.skinnum);
- gi.multicast (tr.endpos, MULTICAST_PVS);
+ if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client)) {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_LASER_SPARKS);
+ gi.WriteByte(4);
+ gi.WritePosition(tr.endpos);
+ gi.WriteDir(tr.plane.normal);
+ gi.WriteByte(self->s.skinnum);
+ gi.multicast(tr.endpos, MULTICAST_PVS);
break;
}
ignore = tr.ent;
- VectorCopy (tr.endpos, start);
+ VectorCopy(tr.endpos, start);
}
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BFG_LASER);
- gi.WritePosition (self->s.origin);
- gi.WritePosition (tr.endpos);
- gi.multicast (self->s.origin, MULTICAST_PHS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BFG_LASER);
+ gi.WritePosition(self->s.origin);
+ gi.WritePosition(tr.endpos);
+ gi.multicast(self->s.origin, MULTICAST_PHS);
}
self->nextthink = level.time + FRAMETIME;
}
-void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius)
+void fire_bfg(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius)
{
edict_t *bfg;
bfg = G_Spawn();
- VectorCopy (start, bfg->s.origin);
- VectorCopy (dir, bfg->movedir);
- vectoangles (dir, bfg->s.angles);
- VectorScale (dir, speed, bfg->velocity);
+ VectorCopy(start, bfg->s.origin);
+ VectorCopy(dir, bfg->movedir);
+ vectoangles(dir, bfg->s.angles);
+ VectorScale(dir, speed, bfg->velocity);
bfg->movetype = MOVETYPE_FLYMISSILE;
bfg->clipmask = MASK_SHOT;
bfg->solid = SOLID_BBOX;
bfg->s.effects |= EF_BFG | EF_ANIM_ALLFAST;
- VectorClear (bfg->mins);
- VectorClear (bfg->maxs);
- bfg->s.modelindex = gi.modelindex ("sprites/s_bfg1.sp2");
+ VectorClear(bfg->mins);
+ VectorClear(bfg->maxs);
+ bfg->s.modelindex = gi.modelindex("sprites/s_bfg1.sp2");
bfg->owner = self;
bfg->touch = bfg_touch;
- bfg->nextthink = level.time + 8000/speed;
+ bfg->nextthink = level.time + 8000 / speed;
bfg->think = G_FreeEdict;
bfg->radius_dmg = damage;
bfg->dmg_radius = damage_radius;
bfg->classname = "bfg blast";
- bfg->s.sound = gi.soundindex ("weapons/bfg__l1a.wav");
+ bfg->s.sound = gi.soundindex("weapons/bfg__l1a.wav");
bfg->think = bfg_think;
bfg->nextthink = level.time + FRAMETIME;
@@ -912,7 +860,7 @@ void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, f
bfg->teamchain = NULL;
if (self->client)
- check_dodge (self, bfg->s.origin, dir, speed);
+ check_dodge(self, bfg->s.origin, dir, speed);
- gi.linkentity (bfg);
+ gi.linkentity(bfg);
}
diff --git a/src/baseq2/m_actor.c b/src/baseq2/m_actor.c
index e98cde4..d819741 100644
--- a/src/baseq2/m_actor.c
+++ b/src/baseq2/m_actor.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,8 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "m_actor.h"
#define MAX_ACTOR_NAMES 8
-char *actor_names[MAX_ACTOR_NAMES] =
-{
+char *actor_names[MAX_ACTOR_NAMES] = {
"Hellrot",
"Tokay",
"Killme",
@@ -36,8 +35,7 @@ char *actor_names[MAX_ACTOR_NAMES] =
};
-mframe_t actor_frames_stand [] =
-{
+mframe_t actor_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -84,7 +82,7 @@ mframe_t actor_frames_stand [] =
};
mmove_t actor_move_stand = {FRAME_stand101, FRAME_stand140, actor_frames_stand, NULL};
-void actor_stand (edict_t *self)
+void actor_stand(edict_t *self)
{
self->monsterinfo.currentmove = &actor_move_stand;
@@ -94,8 +92,7 @@ void actor_stand (edict_t *self)
}
-mframe_t actor_frames_walk [] =
-{
+mframe_t actor_frames_walk [] = {
{ ai_walk, 0, NULL },
{ ai_walk, 6, NULL },
{ ai_walk, 10, NULL },
@@ -110,14 +107,13 @@ mframe_t actor_frames_walk [] =
};
mmove_t actor_move_walk = {FRAME_walk01, FRAME_walk08, actor_frames_walk, NULL};
-void actor_walk (edict_t *self)
+void actor_walk(edict_t *self)
{
self->monsterinfo.currentmove = &actor_move_walk;
}
-mframe_t actor_frames_run [] =
-{
+mframe_t actor_frames_run [] = {
{ ai_run, 4, NULL },
{ ai_run, 15, NULL },
{ ai_run, 15, NULL },
@@ -133,10 +129,9 @@ mframe_t actor_frames_run [] =
};
mmove_t actor_move_run = {FRAME_run02, FRAME_run07, actor_frames_run, NULL};
-void actor_run (edict_t *self)
+void actor_run(edict_t *self)
{
- if ((level.time < self->pain_debounce_time) && (!self->enemy))
- {
+ if ((level.time < self->pain_debounce_time) && (!self->enemy)) {
if (self->movetarget)
actor_walk(self);
else
@@ -144,8 +139,7 @@ void actor_run (edict_t *self)
return;
}
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
actor_stand(self);
return;
}
@@ -154,32 +148,28 @@ void actor_run (edict_t *self)
}
-mframe_t actor_frames_pain1 [] =
-{
+mframe_t actor_frames_pain1 [] = {
{ ai_move, -5, NULL },
{ ai_move, 4, NULL },
{ ai_move, 1, NULL }
};
mmove_t actor_move_pain1 = {FRAME_pain101, FRAME_pain103, actor_frames_pain1, actor_run};
-mframe_t actor_frames_pain2 [] =
-{
+mframe_t actor_frames_pain2 [] = {
{ ai_move, -4, NULL },
{ ai_move, 4, NULL },
{ ai_move, 0, NULL }
};
mmove_t actor_move_pain2 = {FRAME_pain201, FRAME_pain203, actor_frames_pain2, actor_run};
-mframe_t actor_frames_pain3 [] =
-{
+mframe_t actor_frames_pain3 [] = {
{ ai_move, -1, NULL },
{ ai_move, 1, NULL },
{ ai_move, 0, NULL }
};
mmove_t actor_move_pain3 = {FRAME_pain301, FRAME_pain303, actor_frames_pain3, actor_run};
-mframe_t actor_frames_flipoff [] =
-{
+mframe_t actor_frames_flipoff [] = {
{ ai_turn, 0, NULL },
{ ai_turn, 0, NULL },
{ ai_turn, 0, NULL },
@@ -197,8 +187,7 @@ mframe_t actor_frames_flipoff [] =
};
mmove_t actor_move_flipoff = {FRAME_flip01, FRAME_flip14, actor_frames_flipoff, actor_run};
-mframe_t actor_frames_taunt [] =
-{
+mframe_t actor_frames_taunt [] = {
{ ai_turn, 0, NULL },
{ ai_turn, 0, NULL },
{ ai_turn, 0, NULL },
@@ -219,15 +208,14 @@ mframe_t actor_frames_taunt [] =
};
mmove_t actor_move_taunt = {FRAME_taunt01, FRAME_taunt17, actor_frames_taunt, actor_run};
-char *messages[] =
-{
+char *messages[] = {
"Watch it",
"#$@*&",
"Idiot",
"Check your targets"
};
-void actor_pain (edict_t *self, edict_t *other, float kick, int damage)
+void actor_pain(edict_t *self, edict_t *other, float kick, int damage)
{
int n;
@@ -240,19 +228,18 @@ void actor_pain (edict_t *self, edict_t *other, float kick, int damage)
self->pain_debounce_time = level.time + 3;
// gi.sound (self, CHAN_VOICE, actor.sound_pain, 1, ATTN_NORM, 0);
- if ((other->client) && (random() < 0.4))
- {
+ if ((other->client) && (random() < 0.4)) {
vec3_t v;
char *name;
- VectorSubtract (other->s.origin, self->s.origin, v);
- self->ideal_yaw = vectoyaw (v);
+ VectorSubtract(other->s.origin, self->s.origin, v);
+ self->ideal_yaw = vectoyaw(v);
if (random() < 0.5)
self->monsterinfo.currentmove = &actor_move_flipoff;
else
self->monsterinfo.currentmove = &actor_move_taunt;
- name = actor_names[(self - g_edicts)%MAX_ACTOR_NAMES];
- gi.cprintf (other, PRINT_CHAT, "%s: %s!\n", name, messages[rand()%3]);
+ name = actor_names[(self - g_edicts) % MAX_ACTOR_NAMES];
+ gi.cprintf(other, PRINT_CHAT, "%s: %s!\n", name, messages[rand() % 3]);
return;
}
@@ -266,48 +253,41 @@ void actor_pain (edict_t *self, edict_t *other, float kick, int damage)
}
-void actorMachineGun (edict_t *self)
+void actorMachineGun(edict_t *self)
{
vec3_t start, target;
vec3_t forward, right;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_ACTOR_MACHINEGUN_1], forward, right, start);
- if (self->enemy)
- {
- if (self->enemy->health > 0)
- {
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_ACTOR_MACHINEGUN_1], forward, right, start);
+ if (self->enemy) {
+ if (self->enemy->health > 0) {
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- }
- else
- {
- VectorCopy (self->enemy->absmin, target);
+ } else {
+ VectorCopy(self->enemy->absmin, target);
target[2] += (self->enemy->size[2] / 2);
}
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
+ } else {
+ AngleVectors(self->s.angles, forward, NULL, NULL);
}
- else
- {
- AngleVectors (self->s.angles, forward, NULL, NULL);
- }
- monster_fire_bullet (self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_ACTOR_MACHINEGUN_1);
+ monster_fire_bullet(self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_ACTOR_MACHINEGUN_1);
}
-void actor_dead (edict_t *self)
+void actor_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t actor_frames_death1 [] =
-{
+mframe_t actor_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, -13, NULL },
@@ -318,8 +298,7 @@ mframe_t actor_frames_death1 [] =
};
mmove_t actor_move_death1 = {FRAME_death101, FRAME_death107, actor_frames_death1, actor_dead};
-mframe_t actor_frames_death2 [] =
-{
+mframe_t actor_frames_death2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 7, NULL },
{ ai_move, -6, NULL },
@@ -336,19 +315,18 @@ mframe_t actor_frames_death2 [] =
};
mmove_t actor_move_death2 = {FRAME_death201, FRAME_death213, actor_frames_death2, actor_dead};
-void actor_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void actor_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= -80)
- {
+ if (self->health <= -80) {
// gi.sound (self, CHAN_VOICE, actor.sound_gib, 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -369,9 +347,9 @@ void actor_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
}
-void actor_fire (edict_t *self)
+void actor_fire(edict_t *self)
{
- actorMachineGun (self);
+ actorMachineGun(self);
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -379,8 +357,7 @@ void actor_fire (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-mframe_t actor_frames_attack [] =
-{
+mframe_t actor_frames_attack [] = {
{ ai_charge, -2, actor_fire },
{ ai_charge, -2, NULL },
{ ai_charge, 3, NULL },
@@ -398,23 +375,22 @@ void actor_attack(edict_t *self)
}
-void actor_use (edict_t *self, edict_t *other, edict_t *activator)
+void actor_use(edict_t *self, edict_t *other, edict_t *activator)
{
vec3_t v;
self->goalentity = self->movetarget = G_PickTarget(self->target);
- if ((!self->movetarget) || (strcmp(self->movetarget->classname, "target_actor") != 0))
- {
- gi.dprintf ("%s has bad target %s at %s\n", self->classname, self->target, vtos(self->s.origin));
+ if ((!self->movetarget) || (strcmp(self->movetarget->classname, "target_actor") != 0)) {
+ gi.dprintf("%s has bad target %s at %s\n", self->classname, self->target, vtos(self->s.origin));
self->target = NULL;
self->monsterinfo.pausetime = 100000000;
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
return;
}
- VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
+ VectorSubtract(self->goalentity->s.origin, self->s.origin, v);
self->ideal_yaw = self->s.angles[YAW] = vectoyaw(v);
- self->monsterinfo.walk (self);
+ self->monsterinfo.walk(self);
self->target = NULL;
}
@@ -422,33 +398,30 @@ void actor_use (edict_t *self, edict_t *other, edict_t *activator)
/*QUAKED misc_actor (1 .5 0) (-16 -16 -24) (16 16 32)
*/
-void SP_misc_actor (edict_t *self)
+void SP_misc_actor(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- if (!self->targetname)
- {
+ if (!self->targetname) {
gi.dprintf("untargeted %s at %s\n", self->classname, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
- if (!self->target)
- {
+ if (!self->target) {
gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin));
- G_FreeEdict (self);
+ G_FreeEdict(self);
return;
}
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
self->s.modelindex = gi.modelindex("players/male/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
if (!self->health)
self->health = 100;
@@ -466,12 +439,12 @@ void SP_misc_actor (edict_t *self)
self->monsterinfo.aiflags |= AI_GOOD_GUY;
- gi.linkentity (self);
+ gi.linkentity(self);
self->monsterinfo.currentmove = &actor_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
// actors always start in a dormant state, they *must* be used to get going
self->use = actor_use;
@@ -481,7 +454,7 @@ void SP_misc_actor (edict_t *self)
/*QUAKED target_actor (.5 .3 0) (-8 -8 -8) (8 8 8) JUMP SHOOT ATTACK x HOLD BRUTAL
JUMP jump in set direction upon reaching this target
SHOOT take a single shot at the pathtarget
-ATTACK attack pathtarget until it or actor is dead
+ATTACK attack pathtarget until it or actor is dead
"target" next target_actor
"pathtarget" target of any action to be taken at this point
@@ -493,75 +466,63 @@ for JUMP only:
"height" speed thrown upwards (default 200)
*/
-void target_actor_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void target_actor_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t v;
if (other->movetarget != self)
return;
-
+
if (other->enemy)
return;
other->goalentity = other->movetarget = NULL;
- if (self->message)
- {
+ if (self->message) {
int n;
edict_t *ent;
- for (n = 1; n <= game.maxclients; n++)
- {
+ for (n = 1; n <= game.maxclients; n++) {
ent = &g_edicts[n];
if (!ent->inuse)
continue;
- gi.cprintf (ent, PRINT_CHAT, "%s: %s\n", actor_names[(other - g_edicts)%MAX_ACTOR_NAMES], self->message);
+ gi.cprintf(ent, PRINT_CHAT, "%s: %s\n", actor_names[(other - g_edicts) % MAX_ACTOR_NAMES], self->message);
}
}
- if (self->spawnflags & 1) //jump
- {
+ if (self->spawnflags & 1) { //jump
other->velocity[0] = self->movedir[0] * self->speed;
other->velocity[1] = self->movedir[1] * self->speed;
-
- if (other->groundentity)
- {
+
+ if (other->groundentity) {
other->groundentity = NULL;
other->velocity[2] = self->movedir[2];
gi.sound(other, CHAN_VOICE, gi.soundindex("player/male/jump1.wav"), 1, ATTN_NORM, 0);
}
}
- if (self->spawnflags & 2) //shoot
- {
- }
- else if (self->spawnflags & 4) //attack
- {
+ if (self->spawnflags & 2) { //shoot
+ } else if (self->spawnflags & 4) { //attack
other->enemy = G_PickTarget(self->pathtarget);
- if (other->enemy)
- {
+ if (other->enemy) {
other->goalentity = other->enemy;
if (self->spawnflags & 32)
other->monsterinfo.aiflags |= AI_BRUTAL;
- if (self->spawnflags & 16)
- {
+ if (self->spawnflags & 16) {
other->monsterinfo.aiflags |= AI_STAND_GROUND;
- actor_stand (other);
- }
- else
- {
- actor_run (other);
+ actor_stand(other);
+ } else {
+ actor_run(other);
}
}
}
- if (!(self->spawnflags & 6) && (self->pathtarget))
- {
+ if (!(self->spawnflags & 6) && (self->pathtarget)) {
char *savetarget;
savetarget = self->target;
self->target = self->pathtarget;
- G_UseTargets (self, other);
+ G_UseTargets(self, other);
self->target = savetarget;
}
@@ -570,40 +531,36 @@ void target_actor_touch (edict_t *self, edict_t *other, cplane_t *plane, csurfac
if (!other->goalentity)
other->goalentity = other->movetarget;
- if (!other->movetarget && !other->enemy)
- {
+ if (!other->movetarget && !other->enemy) {
other->monsterinfo.pausetime = level.time + 100000000;
- other->monsterinfo.stand (other);
- }
- else if (other->movetarget == other->goalentity)
- {
- VectorSubtract (other->movetarget->s.origin, other->s.origin, v);
- other->ideal_yaw = vectoyaw (v);
+ other->monsterinfo.stand(other);
+ } else if (other->movetarget == other->goalentity) {
+ VectorSubtract(other->movetarget->s.origin, other->s.origin, v);
+ other->ideal_yaw = vectoyaw(v);
}
}
-void SP_target_actor (edict_t *self)
+void SP_target_actor(edict_t *self)
{
if (!self->targetname)
- gi.dprintf ("%s with no targetname at %s\n", self->classname, vtos(self->s.origin));
+ gi.dprintf("%s with no targetname at %s\n", self->classname, vtos(self->s.origin));
self->solid = SOLID_TRIGGER;
self->touch = target_actor_touch;
- VectorSet (self->mins, -8, -8, -8);
- VectorSet (self->maxs, 8, 8, 8);
+ VectorSet(self->mins, -8, -8, -8);
+ VectorSet(self->maxs, 8, 8, 8);
self->svflags = SVF_NOCLIENT;
- if (self->spawnflags & 1)
- {
+ if (self->spawnflags & 1) {
if (!self->speed)
self->speed = 200;
if (!st.height)
st.height = 200;
if (self->s.angles[YAW] == 0)
self->s.angles[YAW] = 360;
- G_SetMovedir (self->s.angles, self->movedir);
+ G_SetMovedir(self->s.angles, self->movedir);
self->movedir[2] = st.height;
}
- gi.linkentity (self);
+ gi.linkentity(self);
}
diff --git a/src/baseq2/m_actor.h b/src/baseq2/m_actor.h
index e7fba7e..c781e4b 100644
--- a/src/baseq2/m_actor.h
+++ b/src/baseq2/m_actor.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_berserk.c b/src/baseq2/m_berserk.c
index d070f72..638a816 100644
--- a/src/baseq2/m_berserk.c
+++ b/src/baseq2/m_berserk.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -36,20 +36,19 @@ static int sound_punch;
static int sound_sight;
static int sound_search;
-void berserk_sight (edict_t *self, edict_t *other)
+void berserk_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void berserk_search (edict_t *self)
+void berserk_search(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
}
-void berserk_fidget (edict_t *self);
-mframe_t berserk_frames_stand [] =
-{
+void berserk_fidget(edict_t *self);
+mframe_t berserk_frames_stand [] = {
{ ai_stand, 0, berserk_fidget },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -58,13 +57,12 @@ mframe_t berserk_frames_stand [] =
};
mmove_t berserk_move_stand = {FRAME_stand1, FRAME_stand5, berserk_frames_stand, NULL};
-void berserk_stand (edict_t *self)
+void berserk_stand(edict_t *self)
{
self->monsterinfo.currentmove = &berserk_move_stand;
}
-mframe_t berserk_frames_stand_fidget [] =
-{
+mframe_t berserk_frames_stand_fidget [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -88,7 +86,7 @@ mframe_t berserk_frames_stand_fidget [] =
};
mmove_t berserk_move_stand_fidget = {FRAME_standb1, FRAME_standb20, berserk_frames_stand_fidget, berserk_stand};
-void berserk_fidget (edict_t *self)
+void berserk_fidget(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
return;
@@ -96,12 +94,11 @@ void berserk_fidget (edict_t *self)
return;
self->monsterinfo.currentmove = &berserk_move_stand_fidget;
- gi.sound (self, CHAN_WEAPON, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_WEAPON, sound_idle, 1, ATTN_IDLE, 0);
}
-mframe_t berserk_frames_walk [] =
-{
+mframe_t berserk_frames_walk [] = {
{ ai_walk, 9.1, NULL },
{ ai_walk, 6.3, NULL },
{ ai_walk, 4.9, NULL },
@@ -117,7 +114,7 @@ mframe_t berserk_frames_walk [] =
};
mmove_t berserk_move_walk = {FRAME_walkc1, FRAME_walkc11, berserk_frames_walk, NULL};
-void berserk_walk (edict_t *self)
+void berserk_walk(edict_t *self)
{
self->monsterinfo.currentmove = &berserk_move_walk;
}
@@ -147,8 +144,7 @@ void() berserk_runb12 =[ $r_att12 , berserk_runb7 ] {{ ai_run(19);};
*/
-mframe_t berserk_frames_run1 [] =
-{
+mframe_t berserk_frames_run1 [] = {
{ ai_run, 21, NULL },
{ ai_run, 11, NULL },
{ ai_run, 21, NULL },
@@ -158,7 +154,7 @@ mframe_t berserk_frames_run1 [] =
};
mmove_t berserk_move_run1 = {FRAME_run1, FRAME_run6, berserk_frames_run1, NULL};
-void berserk_run (edict_t *self)
+void berserk_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &berserk_move_stand;
@@ -167,42 +163,40 @@ void berserk_run (edict_t *self)
}
-void berserk_attack_spike (edict_t *self)
+void berserk_attack_spike(edict_t *self)
{
static vec3_t aim = {MELEE_DISTANCE, 0, -24};
- fire_hit (self, aim, (15 + (rand() % 6)), 400); // Faster attack -- upwards and backwards
+ fire_hit(self, aim, (15 + (rand() % 6)), 400); // Faster attack -- upwards and backwards
}
-void berserk_swing (edict_t *self)
+void berserk_swing(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_punch, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_punch, 1, ATTN_NORM, 0);
}
-mframe_t berserk_frames_attack_spike [] =
-{
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, berserk_swing },
- { ai_charge, 0, berserk_attack_spike },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL }
+mframe_t berserk_frames_attack_spike [] = {
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, berserk_swing },
+ { ai_charge, 0, berserk_attack_spike },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL }
};
mmove_t berserk_move_attack_spike = {FRAME_att_c1, FRAME_att_c8, berserk_frames_attack_spike, berserk_run};
-void berserk_attack_club (edict_t *self)
+void berserk_attack_club(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], -4);
- fire_hit (self, aim, (5 + (rand() % 6)), 400); // Slower attack
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], -4);
+ fire_hit(self, aim, (5 + (rand() % 6)), 400); // Slower attack
}
-mframe_t berserk_frames_attack_club [] =
-{
+mframe_t berserk_frames_attack_club [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -219,14 +213,13 @@ mframe_t berserk_frames_attack_club [] =
mmove_t berserk_move_attack_club = {FRAME_att_c9, FRAME_att_c20, berserk_frames_attack_club, berserk_run};
-void berserk_strike (edict_t *self)
+void berserk_strike(edict_t *self)
{
//FIXME play impact sound
}
-mframe_t berserk_frames_attack_strike [] =
-{
+mframe_t berserk_frames_attack_strike [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -242,11 +235,11 @@ mframe_t berserk_frames_attack_strike [] =
{ ai_move, 9.7, NULL },
{ ai_move, 13.6, NULL }
};
-
+
mmove_t berserk_move_attack_strike = {FRAME_att_c21, FRAME_att_c34, berserk_frames_attack_strike, berserk_run};
-void berserk_melee (edict_t *self)
+void berserk_melee(edict_t *self)
{
if ((rand() % 2) == 0)
self->monsterinfo.currentmove = &berserk_move_attack_spike;
@@ -277,8 +270,7 @@ void() berserk_atke18 =[ $r_attb18, berserk_run1 ] {{ ai_run(7.8);};
*/
-mframe_t berserk_frames_pain1 [] =
-{
+mframe_t berserk_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -287,8 +279,7 @@ mframe_t berserk_frames_pain1 [] =
mmove_t berserk_move_pain1 = {FRAME_painc1, FRAME_painc4, berserk_frames_pain1, berserk_run};
-mframe_t berserk_frames_pain2 [] =
-{
+mframe_t berserk_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -312,7 +303,7 @@ mframe_t berserk_frames_pain2 [] =
};
mmove_t berserk_move_pain2 = {FRAME_painb1, FRAME_painb20, berserk_frames_pain2, berserk_run};
-void berserk_pain (edict_t *self, edict_t *other, float kick, int damage)
+void berserk_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -321,7 +312,7 @@ void berserk_pain (edict_t *self, edict_t *other, float kick, int damage)
return;
self->pain_debounce_time = level.time + 3;
- gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
@@ -333,19 +324,18 @@ void berserk_pain (edict_t *self, edict_t *other, float kick, int damage)
}
-void berserk_dead (edict_t *self)
+void berserk_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t berserk_frames_death1 [] =
-{
+mframe_t berserk_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -359,13 +349,12 @@ mframe_t berserk_frames_death1 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }
-
+
};
mmove_t berserk_move_death1 = {FRAME_death1, FRAME_death13, berserk_frames_death1, berserk_dead};
-mframe_t berserk_frames_death2 [] =
-{
+mframe_t berserk_frames_death2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -378,18 +367,17 @@ mframe_t berserk_frames_death2 [] =
mmove_t berserk_move_death2 = {FRAME_deathc1, FRAME_deathc8, berserk_frames_death2, berserk_dead};
-void berserk_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void berserk_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -397,7 +385,7 @@ void berserk_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
if (self->deadflag == DEAD_DEAD)
return;
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
@@ -410,25 +398,24 @@ void berserk_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
/*QUAKED monster_berserk (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_berserk (edict_t *self)
+void SP_monster_berserk(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
// pre-caches
- sound_pain = gi.soundindex ("berserk/berpain2.wav");
- sound_die = gi.soundindex ("berserk/berdeth2.wav");
- sound_idle = gi.soundindex ("berserk/beridle1.wav");
- sound_punch = gi.soundindex ("berserk/attack.wav");
- sound_search = gi.soundindex ("berserk/bersrch1.wav");
- sound_sight = gi.soundindex ("berserk/sight.wav");
+ sound_pain = gi.soundindex("berserk/berpain2.wav");
+ sound_die = gi.soundindex("berserk/berdeth2.wav");
+ sound_idle = gi.soundindex("berserk/beridle1.wav");
+ sound_punch = gi.soundindex("berserk/attack.wav");
+ sound_search = gi.soundindex("berserk/bersrch1.wav");
+ sound_sight = gi.soundindex("berserk/sight.wav");
self->s.modelindex = gi.modelindex("models/monsters/berserk/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
@@ -451,7 +438,7 @@ void SP_monster_berserk (edict_t *self)
self->monsterinfo.currentmove = &berserk_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- gi.linkentity (self);
+ gi.linkentity(self);
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_berserk.h b/src/baseq2/m_berserk.h
index c6dddc2..597d60e 100644
--- a/src/baseq2/m_berserk.h
+++ b/src/baseq2/m_berserk.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_boss2.c b/src/baseq2/m_boss2.c
index 902582f..ec8ab63 100644
--- a/src/baseq2/m_boss2.c
+++ b/src/baseq2/m_boss2.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,9 +28,9 @@ boss2
#include "g_local.h"
#include "m_boss2.h"
-void BossExplode (edict_t *self);
+void BossExplode(edict_t *self);
-qboolean infront (edict_t *self, edict_t *other);
+qboolean infront(edict_t *self, edict_t *other);
static int sound_pain1;
static int sound_pain2;
@@ -38,121 +38,120 @@ static int sound_pain3;
static int sound_death;
static int sound_search1;
-void boss2_search (edict_t *self)
+void boss2_search(edict_t *self)
{
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_search1, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_VOICE, sound_search1, 1, ATTN_NONE, 0);
}
-void boss2_run (edict_t *self);
-void boss2_stand (edict_t *self);
-void boss2_dead (edict_t *self);
-void boss2_attack (edict_t *self);
-void boss2_attack_mg (edict_t *self);
-void boss2_reattack_mg (edict_t *self);
-void boss2_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
+void boss2_run(edict_t *self);
+void boss2_stand(edict_t *self);
+void boss2_dead(edict_t *self);
+void boss2_attack(edict_t *self);
+void boss2_attack_mg(edict_t *self);
+void boss2_reattack_mg(edict_t *self);
+void boss2_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
-void Boss2Rocket (edict_t *self)
+void Boss2Rocket(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
vec3_t dir;
vec3_t vec;
- AngleVectors (self->s.angles, forward, right, NULL);
+ AngleVectors(self->s.angles, forward, right, NULL);
//1
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_1], forward, right, start);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- monster_fire_rocket (self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_1);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ monster_fire_rocket(self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_1);
//2
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_2], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_2], forward, right, start);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- monster_fire_rocket (self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_2);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ monster_fire_rocket(self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_2);
//3
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_3], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_3], forward, right, start);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- monster_fire_rocket (self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_3);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ monster_fire_rocket(self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_3);
//4
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_4], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_ROCKET_4], forward, right, start);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- monster_fire_rocket (self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_4);
-}
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ monster_fire_rocket(self, start, dir, 50, 500, MZ2_BOSS2_ROCKET_4);
+}
-void boss2_firebullet_right (edict_t *self)
+void boss2_firebullet_right(edict_t *self)
{
vec3_t forward, right, target;
vec3_t start;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_MACHINEGUN_R1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_MACHINEGUN_R1], forward, right, start);
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
- monster_fire_bullet (self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_BOSS2_MACHINEGUN_R1);
-}
+ monster_fire_bullet(self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_BOSS2_MACHINEGUN_R1);
+}
-void boss2_firebullet_left (edict_t *self)
+void boss2_firebullet_left(edict_t *self)
{
vec3_t forward, right, target;
vec3_t start;
-
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_BOSS2_MACHINEGUN_L1], forward, right, start);
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_BOSS2_MACHINEGUN_L1], forward, right, start);
+
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
- monster_fire_bullet (self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_BOSS2_MACHINEGUN_L1);
-}
+ monster_fire_bullet(self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_BOSS2_MACHINEGUN_L1);
+}
-void Boss2MachineGun (edict_t *self)
+void Boss2MachineGun(edict_t *self)
{
-/* vec3_t forward, right;
- vec3_t start;
- vec3_t dir;
- vec3_t vec;
- int flash_number;
-
- AngleVectors (self->s.angles, forward, right, NULL);
-
- flash_number = MZ2_BOSS2_MACHINEGUN_1 + (self->s.frame - FRAME_attack10);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
-
- VectorCopy (self->enemy->s.origin, vec);
- vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- monster_fire_bullet (self, start, dir, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
-*/
+ /* vec3_t forward, right;
+ vec3_t start;
+ vec3_t dir;
+ vec3_t vec;
+ int flash_number;
+
+ AngleVectors (self->s.angles, forward, right, NULL);
+
+ flash_number = MZ2_BOSS2_MACHINEGUN_1 + (self->s.frame - FRAME_attack10);
+ G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+
+ VectorCopy (self->enemy->s.origin, vec);
+ vec[2] += self->enemy->viewheight;
+ VectorSubtract (vec, start, dir);
+ VectorNormalize (dir);
+ monster_fire_bullet (self, start, dir, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
+ */
boss2_firebullet_left(self);
boss2_firebullet_right(self);
-}
+}
-mframe_t boss2_frames_stand [] =
-{
+mframe_t boss2_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -177,8 +176,7 @@ mframe_t boss2_frames_stand [] =
};
mmove_t boss2_move_stand = {FRAME_stand30, FRAME_stand50, boss2_frames_stand, NULL};
-mframe_t boss2_frames_fidget [] =
-{
+mframe_t boss2_frames_fidget [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -212,8 +210,7 @@ mframe_t boss2_frames_fidget [] =
};
mmove_t boss2_move_fidget = {FRAME_stand1, FRAME_stand30, boss2_frames_fidget, NULL};
-mframe_t boss2_frames_walk [] =
-{
+mframe_t boss2_frames_walk [] = {
{ ai_walk, 8, NULL },
{ ai_walk, 8, NULL },
{ ai_walk, 8, NULL },
@@ -238,8 +235,7 @@ mframe_t boss2_frames_walk [] =
mmove_t boss2_move_walk = {FRAME_walk1, FRAME_walk20, boss2_frames_walk, NULL};
-mframe_t boss2_frames_run [] =
-{
+mframe_t boss2_frames_run [] = {
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
@@ -263,8 +259,7 @@ mframe_t boss2_frames_run [] =
};
mmove_t boss2_move_run = {FRAME_walk1, FRAME_walk20, boss2_frames_run, NULL};
-mframe_t boss2_frames_attack_pre_mg [] =
-{
+mframe_t boss2_frames_attack_pre_mg [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
@@ -279,8 +274,7 @@ mmove_t boss2_move_attack_pre_mg = {FRAME_attack1, FRAME_attack9, boss2_frames_a
// Loop this
-mframe_t boss2_frames_attack_mg [] =
-{
+mframe_t boss2_frames_attack_mg [] = {
{ ai_charge, 1, Boss2MachineGun },
{ ai_charge, 1, Boss2MachineGun },
{ ai_charge, 1, Boss2MachineGun },
@@ -290,8 +284,7 @@ mframe_t boss2_frames_attack_mg [] =
};
mmove_t boss2_move_attack_mg = {FRAME_attack10, FRAME_attack15, boss2_frames_attack_mg, NULL};
-mframe_t boss2_frames_attack_post_mg [] =
-{
+mframe_t boss2_frames_attack_post_mg [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
@@ -299,8 +292,7 @@ mframe_t boss2_frames_attack_post_mg [] =
};
mmove_t boss2_move_attack_post_mg = {FRAME_attack16, FRAME_attack19, boss2_frames_attack_post_mg, boss2_run};
-mframe_t boss2_frames_attack_rocket [] =
-{
+mframe_t boss2_frames_attack_rocket [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
@@ -325,8 +317,7 @@ mframe_t boss2_frames_attack_rocket [] =
};
mmove_t boss2_move_attack_rocket = {FRAME_attack20, FRAME_attack40, boss2_frames_attack_rocket, boss2_run};
-mframe_t boss2_frames_pain_heavy [] =
-{
+mframe_t boss2_frames_pain_heavy [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -348,8 +339,7 @@ mframe_t boss2_frames_pain_heavy [] =
};
mmove_t boss2_move_pain_heavy = {FRAME_pain2, FRAME_pain19, boss2_frames_pain_heavy, boss2_run};
-mframe_t boss2_frames_pain_light [] =
-{
+mframe_t boss2_frames_pain_light [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -357,8 +347,7 @@ mframe_t boss2_frames_pain_light [] =
};
mmove_t boss2_move_pain_light = {FRAME_pain20, FRAME_pain23, boss2_frames_pain_light, boss2_run};
-mframe_t boss2_frames_death [] =
-{
+mframe_t boss2_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -411,12 +400,12 @@ mframe_t boss2_frames_death [] =
};
mmove_t boss2_move_death = {FRAME_death2, FRAME_death50, boss2_frames_death, boss2_dead};
-void boss2_stand (edict_t *self)
+void boss2_stand(edict_t *self)
{
- self->monsterinfo.currentmove = &boss2_move_stand;
+ self->monsterinfo.currentmove = &boss2_move_stand;
}
-void boss2_run (edict_t *self)
+void boss2_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &boss2_move_stand;
@@ -424,25 +413,22 @@ void boss2_run (edict_t *self)
self->monsterinfo.currentmove = &boss2_move_run;
}
-void boss2_walk (edict_t *self)
+void boss2_walk(edict_t *self)
{
self->monsterinfo.currentmove = &boss2_move_walk;
}
-void boss2_attack (edict_t *self)
+void boss2_attack(edict_t *self)
{
vec3_t vec;
float range;
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
- range = VectorLength (vec);
-
- if (range <= 125)
- {
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
+ range = VectorLength(vec);
+
+ if (range <= 125) {
self->monsterinfo.currentmove = &boss2_move_attack_pre_mg;
- }
- else
- {
+ } else {
if (random() <= 0.6)
self->monsterinfo.currentmove = &boss2_move_attack_pre_mg;
else
@@ -450,14 +436,14 @@ void boss2_attack (edict_t *self)
}
}
-void boss2_attack_mg (edict_t *self)
+void boss2_attack_mg(edict_t *self)
{
self->monsterinfo.currentmove = &boss2_move_attack_mg;
}
-void boss2_reattack_mg (edict_t *self)
+void boss2_reattack_mg(edict_t *self)
{
- if ( infront(self, self->enemy) )
+ if (infront(self, self->enemy))
if (random() <= 0.7)
self->monsterinfo.currentmove = &boss2_move_attack_mg;
else
@@ -467,7 +453,7 @@ void boss2_reattack_mg (edict_t *self)
}
-void boss2_pain (edict_t *self, edict_t *other, float kick, int damage)
+void boss2_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -477,36 +463,31 @@ void boss2_pain (edict_t *self, edict_t *other, float kick, int damage)
self->pain_debounce_time = level.time + 3;
// American wanted these at no attenuation
- if (damage < 10)
- {
- gi.sound (self, CHAN_VOICE, sound_pain3, 1, ATTN_NONE, 0);
+ if (damage < 10) {
+ gi.sound(self, CHAN_VOICE, sound_pain3, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &boss2_move_pain_light;
- }
- else if (damage < 30)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NONE, 0);
+ } else if (damage < 30) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &boss2_move_pain_light;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NONE, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &boss2_move_pain_heavy;
}
}
-void boss2_dead (edict_t *self)
+void boss2_dead(edict_t *self)
{
- VectorSet (self->mins, -56, -56, 0);
- VectorSet (self->maxs, 56, 56, 80);
+ VectorSet(self->mins, -56, -56, 0);
+ VectorSet(self->maxs, 56, 56, 80);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void boss2_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void boss2_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NONE, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_NO;
self->count = 0;
@@ -516,14 +497,13 @@ void boss2_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
self->s.sound = 0;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -537,7 +517,7 @@ void boss2_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
#endif
}
-qboolean Boss2_CheckAttack (edict_t *self)
+qboolean Boss2_CheckAttack(edict_t *self)
{
vec3_t spot1, spot2;
vec3_t temp;
@@ -547,79 +527,66 @@ qboolean Boss2_CheckAttack (edict_t *self)
int enemy_range;
float enemy_yaw;
- if (self->enemy->health > 0)
- {
- // see if any entities are in the way of the shot
- VectorCopy (self->s.origin, spot1);
+ if (self->enemy->health > 0) {
+ // see if any entities are in the way of the shot
+ VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
- VectorCopy (self->enemy->s.origin, spot2);
+ VectorCopy(self->enemy->s.origin, spot2);
spot2[2] += self->enemy->viewheight;
- tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA);
+ tr = gi.trace(spot1, NULL, NULL, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA);
// do we have a clear shot?
if (tr.ent != self->enemy)
return qfalse;
}
-
+
enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy);
- VectorSubtract (self->enemy->s.origin, self->s.origin, temp);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp);
self->ideal_yaw = enemy_yaw;
// melee attack
- if (enemy_range == RANGE_MELEE)
- {
+ if (enemy_range == RANGE_MELEE) {
if (self->monsterinfo.melee)
self->monsterinfo.attack_state = AS_MELEE;
else
self->monsterinfo.attack_state = AS_MISSILE;
return qtrue;
}
-
+
// missile attack
if (!self->monsterinfo.attack)
return qfalse;
-
+
if (level.time < self->monsterinfo.attack_finished)
return qfalse;
-
+
if (enemy_range == RANGE_FAR)
return qfalse;
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MELEE)
- {
+ } else if (enemy_range == RANGE_MELEE) {
chance = 0.8;
- }
- else if (enemy_range == RANGE_NEAR)
- {
+ } else if (enemy_range == RANGE_NEAR) {
chance = 0.8;
- }
- else if (enemy_range == RANGE_MID)
- {
+ } else if (enemy_range == RANGE_MID) {
chance = 0.8;
- }
- else
- {
+ } else {
return qfalse;
}
- if (random () < chance)
- {
+ if (random() < chance) {
self->monsterinfo.attack_state = AS_MISSILE;
- self->monsterinfo.attack_finished = level.time + 2*random();
+ self->monsterinfo.attack_finished = level.time + 2 * random();
return qtrue;
}
- if (self->flags & FL_FLY)
- {
+ if (self->flags & FL_FLY) {
if (random() < 0.3)
self->monsterinfo.attack_state = AS_SLIDING;
else
@@ -633,27 +600,26 @@ qboolean Boss2_CheckAttack (edict_t *self)
/*QUAKED monster_boss2 (1 .5 0) (-56 -56 0) (56 56 80) Ambush Trigger_Spawn Sight
*/
-void SP_monster_boss2 (edict_t *self)
+void SP_monster_boss2(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("bosshovr/bhvpain1.wav");
- sound_pain2 = gi.soundindex ("bosshovr/bhvpain2.wav");
- sound_pain3 = gi.soundindex ("bosshovr/bhvpain3.wav");
- sound_death = gi.soundindex ("bosshovr/bhvdeth1.wav");
- sound_search1 = gi.soundindex ("bosshovr/bhvunqv1.wav");
+ sound_pain1 = gi.soundindex("bosshovr/bhvpain1.wav");
+ sound_pain2 = gi.soundindex("bosshovr/bhvpain2.wav");
+ sound_pain3 = gi.soundindex("bosshovr/bhvpain3.wav");
+ sound_death = gi.soundindex("bosshovr/bhvdeth1.wav");
+ sound_search1 = gi.soundindex("bosshovr/bhvunqv1.wav");
- self->s.sound = gi.soundindex ("bosshovr/bhvengn1.wav");
+ self->s.sound = gi.soundindex("bosshovr/bhvengn1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/boss2/tris.md2");
- VectorSet (self->mins, -56, -56, 0);
- VectorSet (self->maxs, 56, 56, 80);
+ self->s.modelindex = gi.modelindex("models/monsters/boss2/tris.md2");
+ VectorSet(self->mins, -56, -56, 0);
+ VectorSet(self->maxs, 56, 56, 80);
self->health = 2000;
self->gib_health = -200;
@@ -670,10 +636,10 @@ void SP_monster_boss2 (edict_t *self)
self->monsterinfo.attack = boss2_attack;
self->monsterinfo.search = boss2_search;
self->monsterinfo.checkattack = Boss2_CheckAttack;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &boss2_move_stand;
+ self->monsterinfo.currentmove = &boss2_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- flymonster_start (self);
+ flymonster_start(self);
}
diff --git a/src/baseq2/m_boss2.h b/src/baseq2/m_boss2.h
index dc8bb8f..b061f94 100644
--- a/src/baseq2/m_boss2.h
+++ b/src/baseq2/m_boss2.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_boss3.c b/src/baseq2/m_boss3.c
index 5ca104c..6448938 100644
--- a/src/baseq2/m_boss3.c
+++ b/src/baseq2/m_boss3.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,16 +28,16 @@ boss3
#include "g_local.h"
#include "m_boss32.h"
-void Use_Boss3 (edict_t *ent, edict_t *other, edict_t *activator)
+void Use_Boss3(edict_t *ent, edict_t *other, edict_t *activator)
{
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BOSSTPORT);
- gi.WritePosition (ent->s.origin);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
- G_FreeEdict (ent);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BOSSTPORT);
+ gi.WritePosition(ent->s.origin);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
+ G_FreeEdict(ent);
}
-void Think_Boss3Stand (edict_t *ent)
+void Think_Boss3Stand(edict_t *ent)
{
if (ent->s.frame == FRAME_stand260)
ent->s.frame = FRAME_stand201;
@@ -50,27 +50,26 @@ void Think_Boss3Stand (edict_t *ent)
Just stands and cycles in one place until targeted, then teleports away.
*/
-void SP_monster_boss3_stand (edict_t *self)
+void SP_monster_boss3_stand(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
self->model = "models/monsters/boss3/rider/tris.md2";
- self->s.modelindex = gi.modelindex (self->model);
+ self->s.modelindex = gi.modelindex(self->model);
self->s.frame = FRAME_stand201;
- gi.soundindex ("misc/bigtele.wav");
+ gi.soundindex("misc/bigtele.wav");
- VectorSet (self->mins, -32, -32, 0);
- VectorSet (self->maxs, 32, 32, 90);
+ VectorSet(self->mins, -32, -32, 0);
+ VectorSet(self->maxs, 32, 32, 90);
self->use = Use_Boss3;
self->think = Think_Boss3Stand;
self->nextthink = level.time + FRAMETIME;
- gi.linkentity (self);
+ gi.linkentity(self);
}
diff --git a/src/baseq2/m_boss31.c b/src/baseq2/m_boss31.c
index 0a272fb..d62dc2a 100644
--- a/src/baseq2/m_boss31.c
+++ b/src/baseq2/m_boss31.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,8 +28,8 @@ jorg
#include "g_local.h"
#include "m_boss31.h"
-extern void SP_monster_makron (edict_t *self);
-qboolean visible (edict_t *self, edict_t *other);
+extern void SP_monster_makron(edict_t *self);
+qboolean visible(edict_t *self, edict_t *other);
static int sound_pain1;
static int sound_pain2;
@@ -46,29 +46,29 @@ static int sound_step_left;
static int sound_step_right;
static int sound_death_hit;
-void BossExplode (edict_t *self);
-void MakronToss (edict_t *self);
+void BossExplode(edict_t *self);
+void MakronToss(edict_t *self);
-void jorg_search (edict_t *self)
+void jorg_search(edict_t *self)
{
float r;
r = random();
if (r <= 0.3)
- gi.sound (self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
else if (r <= 0.6)
- gi.sound (self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_search3, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search3, 1, ATTN_NORM, 0);
}
-void jorg_dead (edict_t *self);
-void jorgBFG (edict_t *self);
-void jorgMachineGun (edict_t *self);
-void jorg_firebullet (edict_t *self);
+void jorg_dead(edict_t *self);
+void jorgBFG(edict_t *self);
+void jorgMachineGun(edict_t *self);
+void jorg_firebullet(edict_t *self);
void jorg_reattack1(edict_t *self);
void jorg_attack1(edict_t *self);
void jorg_idle(edict_t *self);
@@ -80,8 +80,7 @@ void jorg_death_hit(edict_t *self);
// stand
//
-mframe_t jorg_frames_stand []=
-{
+mframe_t jorg_frames_stand [] = {
{ ai_stand, 0, jorg_idle },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -136,35 +135,34 @@ mframe_t jorg_frames_stand []=
};
mmove_t jorg_move_stand = {FRAME_stand01, FRAME_stand51, jorg_frames_stand, NULL};
-void jorg_idle (edict_t *self)
+void jorg_idle(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_NORM, 0);
}
-void jorg_death_hit (edict_t *self)
+void jorg_death_hit(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_death_hit, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_BODY, sound_death_hit, 1, ATTN_NORM, 0);
}
-void jorg_step_left (edict_t *self)
+void jorg_step_left(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_step_left, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_BODY, sound_step_left, 1, ATTN_NORM, 0);
}
-void jorg_step_right (edict_t *self)
+void jorg_step_right(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_step_right, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_BODY, sound_step_right, 1, ATTN_NORM, 0);
}
-void jorg_stand (edict_t *self)
+void jorg_stand(edict_t *self)
{
self->monsterinfo.currentmove = &jorg_move_stand;
}
-mframe_t jorg_frames_run [] =
-{
+mframe_t jorg_frames_run [] = {
{ ai_run, 17, jorg_step_left },
{ ai_run, 0, NULL },
{ ai_run, 0, NULL },
@@ -186,8 +184,7 @@ mmove_t jorg_move_run = {FRAME_walk06, FRAME_walk19, jorg_frames_run, NULL};
// walk
//
-mframe_t jorg_frames_start_walk [] =
-{
+mframe_t jorg_frames_start_walk [] = {
{ ai_walk, 5, NULL },
{ ai_walk, 6, NULL },
{ ai_walk, 7, NULL },
@@ -196,8 +193,7 @@ mframe_t jorg_frames_start_walk [] =
};
mmove_t jorg_move_start_walk = {FRAME_walk01, FRAME_walk05, jorg_frames_start_walk, NULL};
-mframe_t jorg_frames_walk [] =
-{
+mframe_t jorg_frames_walk [] = {
{ ai_walk, 17, NULL },
{ ai_walk, 0, NULL },
{ ai_walk, 0, NULL },
@@ -215,8 +211,7 @@ mframe_t jorg_frames_walk [] =
};
mmove_t jorg_move_walk = {FRAME_walk06, FRAME_walk19, jorg_frames_walk, NULL};
-mframe_t jorg_frames_end_walk [] =
-{
+mframe_t jorg_frames_end_walk [] = {
{ ai_walk, 11, NULL },
{ ai_walk, 0, NULL },
{ ai_walk, 0, NULL },
@@ -226,12 +221,12 @@ mframe_t jorg_frames_end_walk [] =
};
mmove_t jorg_move_end_walk = {FRAME_walk20, FRAME_walk25, jorg_frames_end_walk, NULL};
-void jorg_walk (edict_t *self)
+void jorg_walk(edict_t *self)
{
- self->monsterinfo.currentmove = &jorg_move_walk;
+ self->monsterinfo.currentmove = &jorg_move_walk;
}
-void jorg_run (edict_t *self)
+void jorg_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &jorg_move_stand;
@@ -239,8 +234,7 @@ void jorg_run (edict_t *self)
self->monsterinfo.currentmove = &jorg_move_run;
}
-mframe_t jorg_frames_pain3 [] =
-{
+mframe_t jorg_frames_pain3 [] = {
{ ai_move, -28, NULL },
{ ai_move, -6, NULL },
{ ai_move, -3, jorg_step_left },
@@ -269,24 +263,21 @@ mframe_t jorg_frames_pain3 [] =
};
mmove_t jorg_move_pain3 = {FRAME_pain301, FRAME_pain325, jorg_frames_pain3, jorg_run};
-mframe_t jorg_frames_pain2 [] =
-{
+mframe_t jorg_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }
};
mmove_t jorg_move_pain2 = {FRAME_pain201, FRAME_pain203, jorg_frames_pain2, jorg_run};
-mframe_t jorg_frames_pain1 [] =
-{
+mframe_t jorg_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }
};
mmove_t jorg_move_pain1 = {FRAME_pain101, FRAME_pain103, jorg_frames_pain1, jorg_run};
-mframe_t jorg_frames_death1 [] =
-{
+mframe_t jorg_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -310,10 +301,10 @@ mframe_t jorg_frames_death1 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }, // 30
@@ -330,25 +321,24 @@ mframe_t jorg_frames_death1 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, MakronToss },
{ ai_move, 0, BossExplode } // 50
};
mmove_t jorg_move_death = {FRAME_death01, FRAME_death50, jorg_frames_death1, jorg_dead};
-mframe_t jorg_frames_attack2 []=
-{
+mframe_t jorg_frames_attack2 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
- { ai_charge, 0, jorgBFG },
+ { ai_charge, 0, jorgBFG },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -358,8 +348,7 @@ mframe_t jorg_frames_attack2 []=
};
mmove_t jorg_move_attack2 = {FRAME_attak201, FRAME_attak213, jorg_frames_attack2, jorg_run};
-mframe_t jorg_frames_start_attack1 [] =
-{
+mframe_t jorg_frames_start_attack1 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -371,8 +360,7 @@ mframe_t jorg_frames_start_attack1 [] =
};
mmove_t jorg_move_start_attack1 = {FRAME_attak101, FRAME_attak108, jorg_frames_start_attack1, jorg_attack1};
-mframe_t jorg_frames_attack1[]=
-{
+mframe_t jorg_frames_attack1[] = {
{ ai_charge, 0, jorg_firebullet },
{ ai_charge, 0, jorg_firebullet },
{ ai_charge, 0, jorg_firebullet },
@@ -382,8 +370,7 @@ mframe_t jorg_frames_attack1[]=
};
mmove_t jorg_move_attack1 = {FRAME_attak109, FRAME_attak114, jorg_frames_attack1, jorg_reattack1};
-mframe_t jorg_frames_end_attack1[]=
-{
+mframe_t jorg_frames_end_attack1[] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -396,15 +383,13 @@ void jorg_reattack1(edict_t *self)
if (visible(self, self->enemy))
if (random() < 0.9)
self->monsterinfo.currentmove = &jorg_move_attack1;
- else
- {
+ else {
self->s.sound = 0;
- self->monsterinfo.currentmove = &jorg_move_end_attack1;
+ self->monsterinfo.currentmove = &jorg_move_end_attack1;
}
- else
- {
+ else {
self->s.sound = 0;
- self->monsterinfo.currentmove = &jorg_move_end_attack1;
+ self->monsterinfo.currentmove = &jorg_move_end_attack1;
}
}
@@ -413,37 +398,37 @@ void jorg_attack1(edict_t *self)
self->monsterinfo.currentmove = &jorg_move_attack1;
}
-void jorg_pain (edict_t *self, edict_t *other, float kick, int damage)
+void jorg_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
- self->s.skinnum = 1;
-
+ self->s.skinnum = 1;
+
self->s.sound = 0;
if (level.time < self->pain_debounce_time)
- return;
+ return;
// Lessen the chance of him going into his pain frames if he takes little damage
if (damage <= 40)
- if (random()<=0.6)
+ if (random() <= 0.6)
return;
- /*
+ /*
If he's entering his attack1 or using attack1, lessen the chance of him
going into pain
*/
-
- if ( (self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak108) )
+
+ if ((self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak108))
if (random() <= 0.005)
return;
- if ( (self->s.frame >= FRAME_attak109) && (self->s.frame <= FRAME_attak114) )
+ if ((self->s.frame >= FRAME_attak109) && (self->s.frame <= FRAME_attak114))
if (random() <= 0.00005)
return;
- if ( (self->s.frame >= FRAME_attak201) && (self->s.frame <= FRAME_attak208) )
+ if ((self->s.frame >= FRAME_attak201) && (self->s.frame <= FRAME_attak208))
if (random() <= 0.005)
return;
@@ -452,85 +437,79 @@ void jorg_pain (edict_t *self, edict_t *other, float kick, int damage)
if (skill->value == 3)
return; // no pain anims in nightmare
- if (damage <= 50)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM,0);
+ if (damage <= 50) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &jorg_move_pain1;
- }
- else if (damage <= 100)
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM,0);
+ } else if (damage <= 100) {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &jorg_move_pain2;
- }
- else
- {
- if (random() <= 0.3)
- {
- gi.sound (self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM,0);
+ } else {
+ if (random() <= 0.3) {
+ gi.sound(self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &jorg_move_pain3;
}
}
};
-void jorgBFG (edict_t *self)
+void jorgBFG(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
vec3_t dir;
vec3_t vec;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_JORG_BFG_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_JORG_BFG_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- gi.sound (self, CHAN_VOICE, sound_attack2, 1, ATTN_NORM, 0);
- /*void monster_fire_bfg (edict_t *self,
- vec3_t start,
- vec3_t aimdir,
- int damage,
- int speed,
- int kick,
- float damage_radius,
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ gi.sound(self, CHAN_VOICE, sound_attack2, 1, ATTN_NORM, 0);
+ /*void monster_fire_bfg (edict_t *self,
+ vec3_t start,
+ vec3_t aimdir,
+ int damage,
+ int speed,
+ int kick,
+ float damage_radius,
int flashtype)*/
- monster_fire_bfg (self, start, dir, 50, 300, 100, 200, MZ2_JORG_BFG_1);
-}
+ monster_fire_bfg(self, start, dir, 50, 300, 100, 200, MZ2_JORG_BFG_1);
+}
-void jorg_firebullet_right (edict_t *self)
+void jorg_firebullet_right(edict_t *self)
{
vec3_t forward, right, target;
vec3_t start;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_JORG_MACHINEGUN_R1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_JORG_MACHINEGUN_R1], forward, right, start);
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
- monster_fire_bullet (self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_JORG_MACHINEGUN_R1);
-}
+ monster_fire_bullet(self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_JORG_MACHINEGUN_R1);
+}
-void jorg_firebullet_left (edict_t *self)
+void jorg_firebullet_left(edict_t *self)
{
vec3_t forward, right, target;
vec3_t start;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_JORG_MACHINEGUN_L1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_JORG_MACHINEGUN_L1], forward, right, start);
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
- monster_fire_bullet (self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_JORG_MACHINEGUN_L1);
-}
+ monster_fire_bullet(self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_JORG_MACHINEGUN_L1);
+}
-void jorg_firebullet (edict_t *self)
+void jorg_firebullet(edict_t *self)
{
jorg_firebullet_left(self);
jorg_firebullet_right(self);
@@ -540,24 +519,21 @@ void jorg_attack(edict_t *self)
{
vec3_t vec;
float range;
-
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
- range = VectorLength (vec);
-
- if (random() <= 0.75)
- {
- gi.sound (self, CHAN_VOICE, sound_attack1, 1, ATTN_NORM,0);
- self->s.sound = gi.soundindex ("boss3/w_loop.wav");
+
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
+ range = VectorLength(vec);
+
+ if (random() <= 0.75) {
+ gi.sound(self, CHAN_VOICE, sound_attack1, 1, ATTN_NORM, 0);
+ self->s.sound = gi.soundindex("boss3/w_loop.wav");
self->monsterinfo.currentmove = &jorg_move_start_attack1;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_attack2, 1, ATTN_NORM,0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_attack2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &jorg_move_attack2;
}
}
-void jorg_dead (edict_t *self)
+void jorg_dead(edict_t *self)
{
#if 0
edict_t *tempent;
@@ -565,30 +541,30 @@ void jorg_dead (edict_t *self)
VectorSet (self->mins, -16, -16, -24);
VectorSet (self->maxs, 16, 16, -8);
*/
-
+
// Jorg is on modelindex2. Do not clear him.
- VectorSet (self->mins, -60, -60, 0);
- VectorSet (self->maxs, 60, 60, 72);
+ VectorSet(self->mins, -60, -60, 0);
+ VectorSet(self->maxs, 60, 60, 72);
self->movetype = MOVETYPE_TOSS;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
tempent = G_Spawn();
- VectorCopy (self->s.origin, tempent->s.origin);
- VectorCopy (self->s.angles, tempent->s.angles);
+ VectorCopy(self->s.origin, tempent->s.origin);
+ VectorCopy(self->s.angles, tempent->s.angles);
tempent->killtarget = self->killtarget;
tempent->target = self->target;
tempent->activator = self->enemy;
self->killtarget = 0;
self->target = 0;
- SP_monster_makron (tempent);
+ SP_monster_makron(tempent);
#endif
}
-void jorg_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void jorg_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_NO;
self->s.sound = 0;
@@ -596,7 +572,7 @@ void jorg_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage,
self->monsterinfo.currentmove = &jorg_move_death;
}
-qboolean Jorg_CheckAttack (edict_t *self)
+qboolean Jorg_CheckAttack(edict_t *self)
{
vec3_t spot1, spot2;
vec3_t temp;
@@ -606,79 +582,66 @@ qboolean Jorg_CheckAttack (edict_t *self)
int enemy_range;
float enemy_yaw;
- if (self->enemy->health > 0)
- {
- // see if any entities are in the way of the shot
- VectorCopy (self->s.origin, spot1);
+ if (self->enemy->health > 0) {
+ // see if any entities are in the way of the shot
+ VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
- VectorCopy (self->enemy->s.origin, spot2);
+ VectorCopy(self->enemy->s.origin, spot2);
spot2[2] += self->enemy->viewheight;
- tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA);
+ tr = gi.trace(spot1, NULL, NULL, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA);
// do we have a clear shot?
if (tr.ent != self->enemy)
return qfalse;
}
-
+
enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy);
- VectorSubtract (self->enemy->s.origin, self->s.origin, temp);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp);
self->ideal_yaw = enemy_yaw;
// melee attack
- if (enemy_range == RANGE_MELEE)
- {
+ if (enemy_range == RANGE_MELEE) {
if (self->monsterinfo.melee)
self->monsterinfo.attack_state = AS_MELEE;
else
self->monsterinfo.attack_state = AS_MISSILE;
return qtrue;
}
-
+
// missile attack
if (!self->monsterinfo.attack)
return qfalse;
-
+
if (level.time < self->monsterinfo.attack_finished)
return qfalse;
-
+
if (enemy_range == RANGE_FAR)
return qfalse;
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MELEE)
- {
+ } else if (enemy_range == RANGE_MELEE) {
chance = 0.8;
- }
- else if (enemy_range == RANGE_NEAR)
- {
+ } else if (enemy_range == RANGE_NEAR) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MID)
- {
+ } else if (enemy_range == RANGE_MID) {
chance = 0.2;
- }
- else
- {
+ } else {
return qfalse;
}
- if (random () < chance)
- {
+ if (random() < chance) {
self->monsterinfo.attack_state = AS_MISSILE;
- self->monsterinfo.attack_finished = level.time + 2*random();
+ self->monsterinfo.attack_finished = level.time + 2 * random();
return qtrue;
}
- if (self->flags & FL_FLY)
- {
+ if (self->flags & FL_FLY) {
if (random() < 0.3)
self->monsterinfo.attack_state = AS_SLIDING;
else
@@ -689,41 +652,40 @@ qboolean Jorg_CheckAttack (edict_t *self)
}
-void MakronPrecache (void);
+void MakronPrecache(void);
/*QUAKED monster_jorg (1 .5 0) (-80 -80 0) (90 90 140) Ambush Trigger_Spawn Sight
*/
-void SP_monster_jorg (edict_t *self)
+void SP_monster_jorg(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("boss3/bs3pain1.wav");
- sound_pain2 = gi.soundindex ("boss3/bs3pain2.wav");
- sound_pain3 = gi.soundindex ("boss3/bs3pain3.wav");
- sound_death = gi.soundindex ("boss3/bs3deth1.wav");
- sound_attack1 = gi.soundindex ("boss3/bs3atck1.wav");
- sound_attack2 = gi.soundindex ("boss3/bs3atck2.wav");
- sound_search1 = gi.soundindex ("boss3/bs3srch1.wav");
- sound_search2 = gi.soundindex ("boss3/bs3srch2.wav");
- sound_search3 = gi.soundindex ("boss3/bs3srch3.wav");
- sound_idle = gi.soundindex ("boss3/bs3idle1.wav");
- sound_step_left = gi.soundindex ("boss3/step1.wav");
- sound_step_right = gi.soundindex ("boss3/step2.wav");
- sound_firegun = gi.soundindex ("boss3/xfire.wav");
- sound_death_hit = gi.soundindex ("boss3/d_hit.wav");
-
- MakronPrecache ();
+ sound_pain1 = gi.soundindex("boss3/bs3pain1.wav");
+ sound_pain2 = gi.soundindex("boss3/bs3pain2.wav");
+ sound_pain3 = gi.soundindex("boss3/bs3pain3.wav");
+ sound_death = gi.soundindex("boss3/bs3deth1.wav");
+ sound_attack1 = gi.soundindex("boss3/bs3atck1.wav");
+ sound_attack2 = gi.soundindex("boss3/bs3atck2.wav");
+ sound_search1 = gi.soundindex("boss3/bs3srch1.wav");
+ sound_search2 = gi.soundindex("boss3/bs3srch2.wav");
+ sound_search3 = gi.soundindex("boss3/bs3srch3.wav");
+ sound_idle = gi.soundindex("boss3/bs3idle1.wav");
+ sound_step_left = gi.soundindex("boss3/step1.wav");
+ sound_step_right = gi.soundindex("boss3/step2.wav");
+ sound_firegun = gi.soundindex("boss3/xfire.wav");
+ sound_death_hit = gi.soundindex("boss3/d_hit.wav");
+
+ MakronPrecache();
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/boss3/rider/tris.md2");
- self->s.modelindex2 = gi.modelindex ("models/monsters/boss3/jorg/tris.md2");
- VectorSet (self->mins, -80, -80, 0);
- VectorSet (self->maxs, 80, 80, 140);
+ self->s.modelindex = gi.modelindex("models/monsters/boss3/rider/tris.md2");
+ self->s.modelindex2 = gi.modelindex("models/monsters/boss3/jorg/tris.md2");
+ VectorSet(self->mins, -80, -80, 0);
+ VectorSet(self->maxs, 80, 80, 140);
self->health = 3000;
self->gib_health = -2000;
@@ -740,8 +702,8 @@ void SP_monster_jorg (edict_t *self)
self->monsterinfo.melee = NULL;
self->monsterinfo.sight = NULL;
self->monsterinfo.checkattack = Jorg_CheckAttack;
- gi.linkentity (self);
-
+ gi.linkentity(self);
+
self->monsterinfo.currentmove = &jorg_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
diff --git a/src/baseq2/m_boss31.h b/src/baseq2/m_boss31.h
index 82f7a82..28d5ffc 100644
--- a/src/baseq2/m_boss31.h
+++ b/src/baseq2/m_boss31.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_boss32.c b/src/baseq2/m_boss32.c
index c7bd764..be198f9 100644
--- a/src/baseq2/m_boss32.c
+++ b/src/baseq2/m_boss32.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,15 +28,15 @@ Makron -- Final Boss
#include "g_local.h"
#include "m_boss32.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
-void MakronRailgun (edict_t *self);
-void MakronSaveloc (edict_t *self);
-void MakronHyperblaster (edict_t *self);
-void makron_step_left (edict_t *self);
-void makron_step_right (edict_t *self);
-void makronBFG (edict_t *self);
-void makron_dead (edict_t *self);
+void MakronRailgun(edict_t *self);
+void MakronSaveloc(edict_t *self);
+void MakronHyperblaster(edict_t *self);
+void makron_step_left(edict_t *self);
+void makron_step_right(edict_t *self);
+void makronBFG(edict_t *self);
+void makron_dead(edict_t *self);
static int sound_pain4;
static int sound_pain5;
@@ -53,25 +53,24 @@ static int sound_taunt2;
static int sound_taunt3;
static int sound_hit;
-void makron_taunt (edict_t *self)
+void makron_taunt(edict_t *self)
{
float r;
- r=random();
+ r = random();
if (r <= 0.3)
- gi.sound (self, CHAN_AUTO, sound_taunt1, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_AUTO, sound_taunt1, 1, ATTN_NONE, 0);
else if (r <= 0.6)
- gi.sound (self, CHAN_AUTO, sound_taunt2, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_AUTO, sound_taunt2, 1, ATTN_NONE, 0);
else
- gi.sound (self, CHAN_AUTO, sound_taunt3, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_AUTO, sound_taunt3, 1, ATTN_NONE, 0);
}
//
// stand
//
-mframe_t makron_frames_stand []=
-{
+mframe_t makron_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -134,14 +133,13 @@ mframe_t makron_frames_stand []=
{ ai_stand, 0, NULL } // 60
};
mmove_t makron_move_stand = {FRAME_stand201, FRAME_stand260, makron_frames_stand, NULL};
-
-void makron_stand (edict_t *self)
+
+void makron_stand(edict_t *self)
{
self->monsterinfo.currentmove = &makron_move_stand;
}
-mframe_t makron_frames_run [] =
-{
+mframe_t makron_frames_run [] = {
{ ai_run, 3, makron_step_left },
{ ai_run, 12, NULL },
{ ai_run, 8, NULL },
@@ -155,39 +153,38 @@ mframe_t makron_frames_run [] =
};
mmove_t makron_move_run = {FRAME_walk204, FRAME_walk213, makron_frames_run, NULL};
-void makron_hit (edict_t *self)
+void makron_hit(edict_t *self)
{
- gi.sound (self, CHAN_AUTO, sound_hit, 1, ATTN_NONE,0);
+ gi.sound(self, CHAN_AUTO, sound_hit, 1, ATTN_NONE, 0);
}
-void makron_popup (edict_t *self)
+void makron_popup(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_popup, 1, ATTN_NONE,0);
+ gi.sound(self, CHAN_BODY, sound_popup, 1, ATTN_NONE, 0);
}
-void makron_step_left (edict_t *self)
+void makron_step_left(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_step_left, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_BODY, sound_step_left, 1, ATTN_NORM, 0);
}
-void makron_step_right (edict_t *self)
+void makron_step_right(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_step_right, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_BODY, sound_step_right, 1, ATTN_NORM, 0);
}
-void makron_brainsplorch (edict_t *self)
+void makron_brainsplorch(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_brainsplorch, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_VOICE, sound_brainsplorch, 1, ATTN_NORM, 0);
}
-void makron_prerailgun (edict_t *self)
+void makron_prerailgun(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_prerailgun, 1, ATTN_NORM,0);
+ gi.sound(self, CHAN_WEAPON, sound_prerailgun, 1, ATTN_NORM, 0);
}
-mframe_t makron_frames_walk [] =
-{
+mframe_t makron_frames_walk [] = {
{ ai_walk, 3, makron_step_left },
{ ai_walk, 12, NULL },
{ ai_walk, 8, NULL },
@@ -201,12 +198,12 @@ mframe_t makron_frames_walk [] =
};
mmove_t makron_move_walk = {FRAME_walk204, FRAME_walk213, makron_frames_run, NULL};
-void makron_walk (edict_t *self)
+void makron_walk(edict_t *self)
{
- self->monsterinfo.currentmove = &makron_move_walk;
+ self->monsterinfo.currentmove = &makron_move_walk;
}
-void makron_run (edict_t *self)
+void makron_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &makron_move_stand;
@@ -214,8 +211,7 @@ void makron_run (edict_t *self)
self->monsterinfo.currentmove = &makron_move_run;
}
-mframe_t makron_frames_pain6 [] =
-{
+mframe_t makron_frames_pain6 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -246,8 +242,7 @@ mframe_t makron_frames_pain6 [] =
};
mmove_t makron_move_pain6 = {FRAME_pain601, FRAME_pain627, makron_frames_pain6, makron_run};
-mframe_t makron_frames_pain5 [] =
-{
+mframe_t makron_frames_pain5 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -255,8 +250,7 @@ mframe_t makron_frames_pain5 [] =
};
mmove_t makron_move_pain5 = {FRAME_pain501, FRAME_pain504, makron_frames_pain5, makron_run};
-mframe_t makron_frames_pain4 [] =
-{
+mframe_t makron_frames_pain4 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -264,8 +258,7 @@ mframe_t makron_frames_pain4 [] =
};
mmove_t makron_move_pain4 = {FRAME_pain401, FRAME_pain404, makron_frames_pain4, makron_run};
-mframe_t makron_frames_death2 [] =
-{
+mframe_t makron_frames_death2 [] = {
{ ai_move, -15, NULL },
{ ai_move, 3, NULL },
{ ai_move, -12, NULL },
@@ -292,7 +285,7 @@ mframe_t makron_frames_death2 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }, // 30
@@ -306,7 +299,6 @@ mframe_t makron_frames_death2 [] =
{ ai_move, 0, NULL },
{ ai_move, -1, NULL },
{ ai_move, 2, NULL }, // 40
- { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -314,9 +306,10 @@ mframe_t makron_frames_death2 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL }, // 50
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, -6, NULL },
@@ -326,7 +319,7 @@ mframe_t makron_frames_death2 [] =
{ ai_move, -4, makron_step_left },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }, // 60
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, -2, NULL },
{ ai_move, -5, NULL },
@@ -336,7 +329,7 @@ mframe_t makron_frames_death2 [] =
{ ai_move, -7, NULL },
{ ai_move, -4, NULL },
{ ai_move, -4, makron_step_right }, // 70
- { ai_move, -6, NULL },
+ { ai_move, -6, NULL },
{ ai_move, -7, NULL },
{ ai_move, 0, makron_step_left },
{ ai_move, 0, NULL },
@@ -346,7 +339,7 @@ mframe_t makron_frames_death2 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }, // 80
- { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -356,7 +349,7 @@ mframe_t makron_frames_death2 [] =
{ ai_move, 0, NULL },
{ ai_move, 2, NULL },
{ ai_move, 0, NULL }, // 90
- { ai_move, 27, makron_hit },
+ { ai_move, 27, makron_hit },
{ ai_move, 26, NULL },
{ ai_move, 0, makron_brainsplorch },
{ ai_move, 0, NULL },
@@ -364,8 +357,7 @@ mframe_t makron_frames_death2 [] =
};
mmove_t makron_move_death2 = {FRAME_death201, FRAME_death295, makron_frames_death2, makron_dead};
-mframe_t makron_frames_death3 [] =
-{
+mframe_t makron_frames_death3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -389,8 +381,7 @@ mframe_t makron_frames_death3 [] =
};
mmove_t makron_move_death3 = {FRAME_death301, FRAME_death320, makron_frames_death3, NULL};
-mframe_t makron_frames_sight [] =
-{
+mframe_t makron_frames_sight [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -405,29 +396,28 @@ mframe_t makron_frames_sight [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }
};
-mmove_t makron_move_sight= {FRAME_active01, FRAME_active13, makron_frames_sight, makron_run};
+mmove_t makron_move_sight = {FRAME_active01, FRAME_active13, makron_frames_sight, makron_run};
-void makronBFG (edict_t *self)
+void makronBFG(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
vec3_t dir;
vec3_t vec;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_MAKRON_BFG], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_MAKRON_BFG], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
- gi.sound (self, CHAN_VOICE, sound_attack_bfg, 1, ATTN_NORM, 0);
- monster_fire_bfg (self, start, dir, 50, 300, 100, 300, MZ2_MAKRON_BFG);
-}
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
+ gi.sound(self, CHAN_VOICE, sound_attack_bfg, 1, ATTN_NORM, 0);
+ monster_fire_bfg(self, start, dir, 50, 300, 100, 300, MZ2_MAKRON_BFG);
+}
-mframe_t makron_frames_attack3 []=
-{
+mframe_t makron_frames_attack3 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -439,8 +429,7 @@ mframe_t makron_frames_attack3 []=
};
mmove_t makron_move_attack3 = {FRAME_attak301, FRAME_attak308, makron_frames_attack3, makron_run};
-mframe_t makron_frames_attack4[]=
-{
+mframe_t makron_frames_attack4[] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -470,8 +459,7 @@ mframe_t makron_frames_attack4[]=
};
mmove_t makron_move_attack4 = {FRAME_attak401, FRAME_attak426, makron_frames_attack4, makron_run};
-mframe_t makron_frames_attack5[]=
-{
+mframe_t makron_frames_attack5[] = {
{ ai_charge, 0, makron_prerailgun },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -491,31 +479,31 @@ mframe_t makron_frames_attack5[]=
};
mmove_t makron_move_attack5 = {FRAME_attak501, FRAME_attak516, makron_frames_attack5, makron_run};
-void MakronSaveloc (edict_t *self)
+void MakronSaveloc(edict_t *self)
{
- VectorCopy (self->enemy->s.origin, self->pos1); //save for aiming the shot
+ VectorCopy(self->enemy->s.origin, self->pos1); //save for aiming the shot
self->pos1[2] += self->enemy->viewheight;
};
// FIXME: He's not firing from the proper Z
-void MakronRailgun (edict_t *self)
+void MakronRailgun(edict_t *self)
{
vec3_t start;
vec3_t dir;
vec3_t forward, right;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_MAKRON_RAILGUN_1], forward, right, start);
-
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_MAKRON_RAILGUN_1], forward, right, start);
+
// calc direction to where we targted
- VectorSubtract (self->pos1, start, dir);
- VectorNormalize (dir);
+ VectorSubtract(self->pos1, start, dir);
+ VectorNormalize(dir);
- monster_fire_railgun (self, start, dir, 50, 100, MZ2_MAKRON_RAILGUN_1);
+ monster_fire_railgun(self, start, dir, 50, 100, MZ2_MAKRON_RAILGUN_1);
}
// FIXME: This is all wrong. He's not firing at the proper angles.
-void MakronHyperblaster (edict_t *self)
+void MakronHyperblaster(edict_t *self)
{
vec3_t dir;
vec3_t vec;
@@ -525,19 +513,16 @@ void MakronHyperblaster (edict_t *self)
flash_number = MZ2_MAKRON_BLASTER_1 + (self->s.frame - FRAME_attak405);
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- if (self->enemy)
- {
- VectorCopy (self->enemy->s.origin, vec);
+ if (self->enemy) {
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, vec);
- vectoangles (vec, vec);
+ VectorSubtract(vec, start, vec);
+ vectoangles(vec, vec);
dir[0] = vec[0];
- }
- else
- {
+ } else {
dir[0] = 0;
}
if (self->s.frame <= FRAME_attak413)
@@ -546,24 +531,24 @@ void MakronHyperblaster (edict_t *self)
dir[1] = self->s.angles[1] + 10 * (self->s.frame - FRAME_attak421);
dir[2] = 0;
- AngleVectors (dir, forward, NULL, NULL);
+ AngleVectors(dir, forward, NULL, NULL);
- monster_fire_blaster (self, start, forward, 15, 1000, MZ2_MAKRON_BLASTER_1, EF_BLASTER);
-}
+ monster_fire_blaster(self, start, forward, 15, 1000, MZ2_MAKRON_BLASTER_1, EF_BLASTER);
+}
-void makron_pain (edict_t *self, edict_t *other, float kick, int damage)
+void makron_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
- self->s.skinnum = 1;
+ self->s.skinnum = 1;
if (level.time < self->pain_debounce_time)
- return;
+ return;
// Lessen the chance of him going into his pain frames
- if (damage <=25)
- if (random()<0.2)
+ if (damage <= 25)
+ if (random() < 0.2)
return;
self->pain_debounce_time = level.time + 3;
@@ -571,31 +556,21 @@ void makron_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
- if (damage <= 40)
- {
- gi.sound (self, CHAN_VOICE, sound_pain4, 1, ATTN_NONE,0);
+ if (damage <= 40) {
+ gi.sound(self, CHAN_VOICE, sound_pain4, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &makron_move_pain4;
- }
- else if (damage <= 110)
- {
- gi.sound (self, CHAN_VOICE, sound_pain5, 1, ATTN_NONE,0);
+ } else if (damage <= 110) {
+ gi.sound(self, CHAN_VOICE, sound_pain5, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &makron_move_pain5;
- }
- else
- {
- if (damage <= 150)
- {
- if (random() <= 0.45)
- {
- gi.sound (self, CHAN_VOICE, sound_pain6, 1, ATTN_NONE,0);
+ } else {
+ if (damage <= 150) {
+ if (random() <= 0.45) {
+ gi.sound(self, CHAN_VOICE, sound_pain6, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &makron_move_pain6;
}
- }
- else
- {
- if (random() <= 0.35)
- {
- gi.sound (self, CHAN_VOICE, sound_pain6, 1, ATTN_NONE,0);
+ } else {
+ if (random() <= 0.35) {
+ gi.sound(self, CHAN_VOICE, sound_pain6, 1, ATTN_NONE, 0);
self->monsterinfo.currentmove = &makron_move_pain6;
}
}
@@ -615,8 +590,8 @@ void makron_attack(edict_t *self)
r = random();
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
- range = VectorLength (vec);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
+ range = VectorLength(vec);
if (r <= 0.3)
@@ -633,29 +608,28 @@ Makron Torso. This needs to be spawned in
---
*/
-void makron_torso_think (edict_t *self)
+void makron_torso_think(edict_t *self)
{
if (++self->s.frame < 365)
self->nextthink = level.time + FRAMETIME;
- else
- {
+ else {
self->s.frame = 346;
self->nextthink = level.time + FRAMETIME;
}
}
-void makron_torso (edict_t *ent)
+void makron_torso(edict_t *ent)
{
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_NOT;
- VectorSet (ent->mins, -8, -8, 0);
- VectorSet (ent->maxs, 8, 8, 8);
+ VectorSet(ent->mins, -8, -8, 0);
+ VectorSet(ent->maxs, 8, 8, 8);
ent->s.frame = 346;
- ent->s.modelindex = gi.modelindex ("models/monsters/boss3/rider/tris.md2");
+ ent->s.modelindex = gi.modelindex("models/monsters/boss3/rider/tris.md2");
ent->think = makron_torso_think;
ent->nextthink = level.time + 2 * FRAMETIME;
- ent->s.sound = gi.soundindex ("makron/spine.wav");
- gi.linkentity (ent);
+ ent->s.sound = gi.soundindex("makron/spine.wav");
+ gi.linkentity(ent);
}
@@ -663,18 +637,18 @@ void makron_torso (edict_t *ent)
// death
//
-void makron_dead (edict_t *self)
+void makron_dead(edict_t *self)
{
- VectorSet (self->mins, -60, -60, 0);
- VectorSet (self->maxs, 60, 60, 72);
+ VectorSet(self->mins, -60, -60, 0);
+ VectorSet(self->maxs, 60, 60, 72);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void makron_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void makron_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
edict_t *tempent;
@@ -682,14 +656,13 @@ void makron_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
self->s.sound = 0;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 1 /*4*/; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
- ThrowHead (self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 1 /*4*/; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
+ ThrowHead(self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -698,21 +671,21 @@ void makron_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NONE, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NONE, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
tempent = G_Spawn();
- VectorCopy (self->s.origin, tempent->s.origin);
- VectorCopy (self->s.angles, tempent->s.angles);
+ VectorCopy(self->s.origin, tempent->s.origin);
+ VectorCopy(self->s.angles, tempent->s.angles);
tempent->s.origin[1] -= 84;
- makron_torso (tempent);
+ makron_torso(tempent);
self->monsterinfo.currentmove = &makron_move_death2;
-
+
}
-qboolean Makron_CheckAttack (edict_t *self)
+qboolean Makron_CheckAttack(edict_t *self)
{
vec3_t spot1, spot2;
vec3_t temp;
@@ -722,79 +695,66 @@ qboolean Makron_CheckAttack (edict_t *self)
int enemy_range;
float enemy_yaw;
- if (self->enemy->health > 0)
- {
- // see if any entities are in the way of the shot
- VectorCopy (self->s.origin, spot1);
+ if (self->enemy->health > 0) {
+ // see if any entities are in the way of the shot
+ VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
- VectorCopy (self->enemy->s.origin, spot2);
+ VectorCopy(self->enemy->s.origin, spot2);
spot2[2] += self->enemy->viewheight;
- tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA);
+ tr = gi.trace(spot1, NULL, NULL, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA);
// do we have a clear shot?
if (tr.ent != self->enemy)
return qfalse;
}
-
+
enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy);
- VectorSubtract (self->enemy->s.origin, self->s.origin, temp);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp);
self->ideal_yaw = enemy_yaw;
// melee attack
- if (enemy_range == RANGE_MELEE)
- {
+ if (enemy_range == RANGE_MELEE) {
if (self->monsterinfo.melee)
self->monsterinfo.attack_state = AS_MELEE;
else
self->monsterinfo.attack_state = AS_MISSILE;
return qtrue;
}
-
+
// missile attack
if (!self->monsterinfo.attack)
return qfalse;
-
+
if (level.time < self->monsterinfo.attack_finished)
return qfalse;
-
+
if (enemy_range == RANGE_FAR)
return qfalse;
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MELEE)
- {
+ } else if (enemy_range == RANGE_MELEE) {
chance = 0.8;
- }
- else if (enemy_range == RANGE_NEAR)
- {
+ } else if (enemy_range == RANGE_NEAR) {
chance = 0.4;
- }
- else if (enemy_range == RANGE_MID)
- {
+ } else if (enemy_range == RANGE_MID) {
chance = 0.2;
- }
- else
- {
+ } else {
return qfalse;
}
- if (random () < chance)
- {
+ if (random() < chance) {
self->monsterinfo.attack_state = AS_MISSILE;
- self->monsterinfo.attack_finished = level.time + 2*random();
+ self->monsterinfo.attack_finished = level.time + 2 * random();
return qtrue;
}
- if (self->flags & FL_FLY)
- {
+ if (self->flags & FL_FLY) {
if (random() < 0.3)
self->monsterinfo.attack_state = AS_SLIDING;
else
@@ -809,43 +769,42 @@ qboolean Makron_CheckAttack (edict_t *self)
// monster_makron
//
-void MakronPrecache (void)
-{
- sound_pain4 = gi.soundindex ("makron/pain3.wav");
- sound_pain5 = gi.soundindex ("makron/pain2.wav");
- sound_pain6 = gi.soundindex ("makron/pain1.wav");
- sound_death = gi.soundindex ("makron/death.wav");
- sound_step_left = gi.soundindex ("makron/step1.wav");
- sound_step_right = gi.soundindex ("makron/step2.wav");
- sound_attack_bfg = gi.soundindex ("makron/bfg_fire.wav");
- sound_brainsplorch = gi.soundindex ("makron/brain1.wav");
- sound_prerailgun = gi.soundindex ("makron/rail_up.wav");
- sound_popup = gi.soundindex ("makron/popup.wav");
- sound_taunt1 = gi.soundindex ("makron/voice4.wav");
- sound_taunt2 = gi.soundindex ("makron/voice3.wav");
- sound_taunt3 = gi.soundindex ("makron/voice.wav");
- sound_hit = gi.soundindex ("makron/bhit.wav");
-
- gi.modelindex ("models/monsters/boss3/rider/tris.md2");
+void MakronPrecache(void)
+{
+ sound_pain4 = gi.soundindex("makron/pain3.wav");
+ sound_pain5 = gi.soundindex("makron/pain2.wav");
+ sound_pain6 = gi.soundindex("makron/pain1.wav");
+ sound_death = gi.soundindex("makron/death.wav");
+ sound_step_left = gi.soundindex("makron/step1.wav");
+ sound_step_right = gi.soundindex("makron/step2.wav");
+ sound_attack_bfg = gi.soundindex("makron/bfg_fire.wav");
+ sound_brainsplorch = gi.soundindex("makron/brain1.wav");
+ sound_prerailgun = gi.soundindex("makron/rail_up.wav");
+ sound_popup = gi.soundindex("makron/popup.wav");
+ sound_taunt1 = gi.soundindex("makron/voice4.wav");
+ sound_taunt2 = gi.soundindex("makron/voice3.wav");
+ sound_taunt3 = gi.soundindex("makron/voice.wav");
+ sound_hit = gi.soundindex("makron/bhit.wav");
+
+ gi.modelindex("models/monsters/boss3/rider/tris.md2");
}
/*QUAKED monster_makron (1 .5 0) (-30 -30 0) (30 30 90) Ambush Trigger_Spawn Sight
*/
-void SP_monster_makron (edict_t *self)
+void SP_monster_makron(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- MakronPrecache ();
+ MakronPrecache();
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/boss3/rider/tris.md2");
- VectorSet (self->mins, -30, -30, 0);
- VectorSet (self->maxs, 30, 30, 90);
+ self->s.modelindex = gi.modelindex("models/monsters/boss3/rider/tris.md2");
+ VectorSet(self->mins, -30, -30, 0);
+ VectorSet(self->maxs, 30, 30, 90);
self->health = 3000;
self->gib_health = -2000;
@@ -862,8 +821,8 @@ void SP_monster_makron (edict_t *self)
self->monsterinfo.sight = makron_sight;
self->monsterinfo.checkattack = Makron_CheckAttack;
- gi.linkentity (self);
-
+ gi.linkentity(self);
+
// self->monsterinfo.currentmove = &makron_move_stand;
self->monsterinfo.currentmove = &makron_move_sight;
self->monsterinfo.scale = MODEL_SCALE;
@@ -878,22 +837,22 @@ MakronSpawn
=================
*/
-void MakronSpawn (edict_t *self)
+void MakronSpawn(edict_t *self)
{
vec3_t vec;
edict_t *player;
- SP_monster_makron (self);
+ SP_monster_makron(self);
// jump at player
player = level.sight_client;
if (!player)
return;
- VectorSubtract (player->s.origin, self->s.origin, vec);
+ VectorSubtract(player->s.origin, self->s.origin, vec);
self->s.angles[YAW] = vectoyaw(vec);
- VectorNormalize (vec);
- VectorMA (vec3_origin, 400, vec, self->velocity);
+ VectorNormalize(vec);
+ VectorMA(vec3_origin, 400, vec, self->velocity);
self->velocity[2] = 200;
self->groundentity = NULL;
}
@@ -905,13 +864,13 @@ MakronToss
Jorg is just about dead, so set up to launch Makron out
=================
*/
-void MakronToss (edict_t *self)
+void MakronToss(edict_t *self)
{
edict_t *ent;
- ent = G_Spawn ();
+ ent = G_Spawn();
ent->nextthink = level.time + 0.8;
ent->think = MakronSpawn;
ent->target = self->target;
- VectorCopy (self->s.origin, ent->s.origin);
+ VectorCopy(self->s.origin, ent->s.origin);
}
diff --git a/src/baseq2/m_boss32.h b/src/baseq2/m_boss32.h
index 1688d4f..a85cb48 100644
--- a/src/baseq2/m_boss32.h
+++ b/src/baseq2/m_boss32.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_brain.c b/src/baseq2/m_brain.c
index c8f6fff..50c555f 100644
--- a/src/baseq2/m_brain.c
+++ b/src/baseq2/m_brain.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -45,27 +45,26 @@ static int sound_melee2;
static int sound_melee3;
-void brain_sight (edict_t *self, edict_t *other)
+void brain_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void brain_search (edict_t *self)
+void brain_search(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
}
-void brain_run (edict_t *self);
-void brain_dead (edict_t *self);
+void brain_run(edict_t *self);
+void brain_dead(edict_t *self);
//
// STAND
//
-mframe_t brain_frames_stand [] =
-{
+mframe_t brain_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -101,7 +100,7 @@ mframe_t brain_frames_stand [] =
};
mmove_t brain_move_stand = {FRAME_stand01, FRAME_stand30, brain_frames_stand, NULL};
-void brain_stand (edict_t *self)
+void brain_stand(edict_t *self)
{
self->monsterinfo.currentmove = &brain_move_stand;
}
@@ -111,8 +110,7 @@ void brain_stand (edict_t *self)
// IDLE
//
-mframe_t brain_frames_idle [] =
-{
+mframe_t brain_frames_idle [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -148,9 +146,9 @@ mframe_t brain_frames_idle [] =
};
mmove_t brain_move_idle = {FRAME_stand31, FRAME_stand60, brain_frames_idle, brain_stand};
-void brain_idle (edict_t *self)
+void brain_idle(edict_t *self)
{
- gi.sound (self, CHAN_AUTO, sound_idle3, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_AUTO, sound_idle3, 1, ATTN_IDLE, 0);
self->monsterinfo.currentmove = &brain_move_idle;
}
@@ -158,8 +156,7 @@ void brain_idle (edict_t *self)
//
// WALK
//
-mframe_t brain_frames_walk1 [] =
-{
+mframe_t brain_frames_walk1 [] = {
{ ai_walk, 7, NULL },
{ ai_walk, 2, NULL },
{ ai_walk, 3, NULL },
@@ -176,14 +173,13 @@ mmove_t brain_move_walk1 = {FRAME_walk101, FRAME_walk111, brain_frames_walk1, NU
// walk2 is FUBAR, do not use
#if 0
-void brain_walk2_cycle (edict_t *self)
+void brain_walk2_cycle(edict_t *self)
{
if (random() > 0.1)
self->monsterinfo.nextframe = FRAME_walk220;
}
-mframe_t brain_frames_walk2 [] =
-{
+mframe_t brain_frames_walk2 [] = {
{ ai_walk, 3, NULL },
{ ai_walk, -2, NULL },
{ ai_walk, -4, NULL },
@@ -217,24 +213,26 @@ mframe_t brain_frames_walk2 [] =
{ ai_walk, 2, NULL },
{ ai_walk, 0, NULL },
- { ai_walk, 4, brain_walk2_cycle,
- { ai_walk, -1, NULL },
- { ai_walk, -1, NULL },
- { ai_walk, -8, NULL },
- { ai_walk, 0, NULL },
- { ai_walk, 1, NULL },
- { ai_walk, 5, NULL },
- { ai_walk, 2, NULL },
- { ai_walk, -1, NULL },
- { ai_walk, -5, NULL
-};
-mmove_t brain_move_walk2 = {FRAME_walk201, FRAME_walk240, brain_frames_walk2, NULL};
+ {
+ ai_walk, 4, brain_walk2_cycle,
+ { ai_walk, -1, NULL },
+ { ai_walk, -1, NULL },
+ { ai_walk, -8, NULL },
+ { ai_walk, 0, NULL },
+ { ai_walk, 1, NULL },
+ { ai_walk, 5, NULL },
+ { ai_walk, 2, NULL },
+ { ai_walk, -1, NULL },
+ {
+ ai_walk, -5, NULL
+ };
+ mmove_t brain_move_walk2 = {FRAME_walk201, FRAME_walk240, brain_frames_walk2, NULL};
+ }
#endif
-void brain_walk (edict_t *self)
-{
+void brain_walk(edict_t *self) {
// if (random() <= 0.5)
- self->monsterinfo.currentmove = &brain_move_walk1;
+ self->monsterinfo.currentmove = &brain_move_walk1;
// else
// self->monsterinfo.currentmove = &brain_move_walk2;
}
@@ -310,30 +308,27 @@ mmove_t brain_move_pain1 = {FRAME_pain101, FRAME_pain121, brain_frames_pain1, br
// DUCK
//
-void brain_duck_down (edict_t *self)
-{
+void brain_duck_down(edict_t *self) {
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
self->monsterinfo.aiflags |= AI_DUCKED;
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void brain_duck_hold (edict_t *self)
-{
+void brain_duck_hold(edict_t *self) {
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
else
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-void brain_duck_up (edict_t *self)
-{
+void brain_duck_up(edict_t *self) {
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
mframe_t brain_frames_duck [] =
@@ -349,8 +344,7 @@ mframe_t brain_frames_duck [] =
};
mmove_t brain_move_duck = {FRAME_duck01, FRAME_duck08, brain_frames_duck, brain_run};
-void brain_dodge (edict_t *self, edict_t *attacker, float eta)
-{
+void brain_dodge(edict_t *self, edict_t *attacker, float eta) {
if (random() > 0.25)
return;
@@ -400,32 +394,28 @@ mmove_t brain_move_death1 = {FRAME_death101, FRAME_death118, brain_frames_death1
// MELEE
//
-void brain_swing_right (edict_t *self)
-{
- gi.sound (self, CHAN_BODY, sound_melee1, 1, ATTN_NORM, 0);
+void brain_swing_right(edict_t *self) {
+ gi.sound(self, CHAN_BODY, sound_melee1, 1, ATTN_NORM, 0);
}
-void brain_hit_right (edict_t *self)
-{
+void brain_hit_right(edict_t *self) {
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->maxs[0], 8);
- if (fire_hit (self, aim, (15 + (rand() %5)), 40))
- gi.sound (self, CHAN_WEAPON, sound_melee3, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->maxs[0], 8);
+ if (fire_hit(self, aim, (15 + (rand() % 5)), 40))
+ gi.sound(self, CHAN_WEAPON, sound_melee3, 1, ATTN_NORM, 0);
}
-void brain_swing_left (edict_t *self)
-{
- gi.sound (self, CHAN_BODY, sound_melee2, 1, ATTN_NORM, 0);
+void brain_swing_left(edict_t *self) {
+ gi.sound(self, CHAN_BODY, sound_melee2, 1, ATTN_NORM, 0);
}
-void brain_hit_left (edict_t *self)
-{
+void brain_hit_left(edict_t *self) {
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], 8);
- if (fire_hit (self, aim, (15 + (rand() %5)), 40))
- gi.sound (self, CHAN_WEAPON, sound_melee3, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], 8);
+ if (fire_hit(self, aim, (15 + (rand() % 5)), 40))
+ gi.sound(self, CHAN_WEAPON, sound_melee3, 1, ATTN_NORM, 0);
}
mframe_t brain_frames_attack1 [] =
@@ -447,32 +437,28 @@ mframe_t brain_frames_attack1 [] =
{ ai_charge, -1, NULL },
{ ai_charge, -3, NULL },
{ ai_charge, 2, NULL },
- { ai_charge, -11,NULL }
+ { ai_charge, -11, NULL }
};
mmove_t brain_move_attack1 = {FRAME_attak101, FRAME_attak118, brain_frames_attack1, brain_run};
-void brain_chest_open (edict_t *self)
-{
+void brain_chest_open(edict_t *self) {
self->spawnflags &= ~65536;
self->monsterinfo.power_armor_type = POWER_ARMOR_NONE;
- gi.sound (self, CHAN_BODY, sound_chest_open, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, sound_chest_open, 1, ATTN_NORM, 0);
}
-void brain_tentacle_attack (edict_t *self)
-{
+void brain_tentacle_attack(edict_t *self) {
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, 0, 8);
- if (fire_hit (self, aim, (10 + (rand() %5)), -600) && skill->value > 0)
+ VectorSet(aim, MELEE_DISTANCE, 0, 8);
+ if (fire_hit(self, aim, (10 + (rand() % 5)), -600) && skill->value > 0)
self->spawnflags |= 65536;
- gi.sound (self, CHAN_WEAPON, sound_tentacles_retract, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_tentacles_retract, 1, ATTN_NORM, 0);
}
-void brain_chest_closed (edict_t *self)
-{
+void brain_chest_closed(edict_t *self) {
self->monsterinfo.power_armor_type = POWER_ARMOR_SCREEN;
- if (self->spawnflags & 65536)
- {
+ if (self->spawnflags & 65536) {
self->spawnflags &= ~65536;
self->monsterinfo.currentmove = &brain_move_attack1;
}
@@ -500,8 +486,7 @@ mframe_t brain_frames_attack2 [] =
};
mmove_t brain_move_attack2 = {FRAME_attak201, FRAME_attak217, brain_frames_attack2, brain_run};
-void brain_melee(edict_t *self)
-{
+void brain_melee(edict_t *self) {
if (random() <= 0.5)
self->monsterinfo.currentmove = &brain_move_attack1;
else
@@ -529,8 +514,7 @@ mframe_t brain_frames_run [] =
};
mmove_t brain_move_run = {FRAME_walk101, FRAME_walk111, brain_frames_run, NULL};
-void brain_run (edict_t *self)
-{
+void brain_run(edict_t *self) {
self->monsterinfo.power_armor_type = POWER_ARMOR_SCREEN;
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &brain_move_stand;
@@ -539,8 +523,7 @@ void brain_run (edict_t *self)
}
-void brain_pain (edict_t *self, edict_t *other, float kick, int damage)
-{
+void brain_pain(edict_t *self, edict_t *other, float kick, int damage) {
float r;
if (self->health < (self->max_health / 2))
@@ -554,51 +537,43 @@ void brain_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
r = random();
- if (r < 0.33)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (r < 0.33) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &brain_move_pain1;
- }
- else if (r < 0.66)
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else if (r < 0.66) {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &brain_move_pain2;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &brain_move_pain3;
}
}
-void brain_dead (edict_t *self)
-{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+void brain_dead(edict_t *self) {
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void brain_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
-{
+void brain_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point) {
int n;
self->s.effects = 0;
self->monsterinfo.power_armor_type = POWER_ARMOR_NONE;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -607,7 +582,7 @@ void brain_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
if (random() <= 0.5)
@@ -618,34 +593,32 @@ void brain_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
/*QUAKED monster_brain (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_brain (edict_t *self)
-{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+void SP_monster_brain(edict_t *self) {
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_chest_open = gi.soundindex ("brain/brnatck1.wav");
- sound_tentacles_extend = gi.soundindex ("brain/brnatck2.wav");
- sound_tentacles_retract = gi.soundindex ("brain/brnatck3.wav");
- sound_death = gi.soundindex ("brain/brndeth1.wav");
- sound_idle1 = gi.soundindex ("brain/brnidle1.wav");
- sound_idle2 = gi.soundindex ("brain/brnidle2.wav");
- sound_idle3 = gi.soundindex ("brain/brnlens1.wav");
- sound_pain1 = gi.soundindex ("brain/brnpain1.wav");
- sound_pain2 = gi.soundindex ("brain/brnpain2.wav");
- sound_sight = gi.soundindex ("brain/brnsght1.wav");
- sound_search = gi.soundindex ("brain/brnsrch1.wav");
- sound_melee1 = gi.soundindex ("brain/melee1.wav");
- sound_melee2 = gi.soundindex ("brain/melee2.wav");
- sound_melee3 = gi.soundindex ("brain/melee3.wav");
+ sound_chest_open = gi.soundindex("brain/brnatck1.wav");
+ sound_tentacles_extend = gi.soundindex("brain/brnatck2.wav");
+ sound_tentacles_retract = gi.soundindex("brain/brnatck3.wav");
+ sound_death = gi.soundindex("brain/brndeth1.wav");
+ sound_idle1 = gi.soundindex("brain/brnidle1.wav");
+ sound_idle2 = gi.soundindex("brain/brnidle2.wav");
+ sound_idle3 = gi.soundindex("brain/brnlens1.wav");
+ sound_pain1 = gi.soundindex("brain/brnpain1.wav");
+ sound_pain2 = gi.soundindex("brain/brnpain2.wav");
+ sound_sight = gi.soundindex("brain/brnsght1.wav");
+ sound_search = gi.soundindex("brain/brnsrch1.wav");
+ sound_melee1 = gi.soundindex("brain/melee1.wav");
+ sound_melee2 = gi.soundindex("brain/melee2.wav");
+ sound_melee3 = gi.soundindex("brain/melee3.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/brain/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/brain/tris.md2");
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 300;
self->gib_health = -150;
@@ -667,10 +640,10 @@ void SP_monster_brain (edict_t *self)
self->monsterinfo.power_armor_type = POWER_ARMOR_SCREEN;
self->monsterinfo.power_armor_power = 100;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &brain_move_stand;
+ self->monsterinfo.currentmove = &brain_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_brain.h b/src/baseq2/m_brain.h
index af7ee36..8f642b2 100644
--- a/src/baseq2/m_brain.h
+++ b/src/baseq2/m_brain.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_chick.c b/src/baseq2/m_chick.c
index 5bfebad..af670da 100644
--- a/src/baseq2/m_chick.c
+++ b/src/baseq2/m_chick.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,10 +28,10 @@ chick
#include "g_local.h"
#include "m_chick.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
-void chick_stand (edict_t *self);
-void chick_run (edict_t *self);
+void chick_stand(edict_t *self);
+void chick_run(edict_t *self);
void chick_reslash(edict_t *self);
void chick_rerocket(edict_t *self);
void chick_attack1(edict_t *self);
@@ -53,16 +53,15 @@ static int sound_sight;
static int sound_search;
-void ChickMoan (edict_t *self)
+void ChickMoan(edict_t *self)
{
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_idle1, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle1, 1, ATTN_IDLE, 0);
else
- gi.sound (self, CHAN_VOICE, sound_idle2, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle2, 1, ATTN_IDLE, 0);
}
-mframe_t chick_frames_fidget [] =
-{
+mframe_t chick_frames_fidget [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -96,7 +95,7 @@ mframe_t chick_frames_fidget [] =
};
mmove_t chick_move_fidget = {FRAME_stand201, FRAME_stand230, chick_frames_fidget, chick_stand};
-void chick_fidget (edict_t *self)
+void chick_fidget(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
return;
@@ -104,8 +103,7 @@ void chick_fidget (edict_t *self)
self->monsterinfo.currentmove = &chick_move_fidget;
}
-mframe_t chick_frames_stand [] =
-{
+mframe_t chick_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -140,18 +138,17 @@ mframe_t chick_frames_stand [] =
};
mmove_t chick_move_stand = {FRAME_stand101, FRAME_stand130, chick_frames_stand, NULL};
-void chick_stand (edict_t *self)
+void chick_stand(edict_t *self)
{
self->monsterinfo.currentmove = &chick_move_stand;
}
-mframe_t chick_frames_start_run [] =
-{
+mframe_t chick_frames_start_run [] = {
{ ai_run, 1, NULL },
{ ai_run, 0, NULL },
{ ai_run, 0, NULL },
- { ai_run, -1, NULL },
- { ai_run, -1, NULL },
+ { ai_run, -1, NULL },
+ { ai_run, -1, NULL },
{ ai_run, 0, NULL },
{ ai_run, 1, NULL },
{ ai_run, 3, NULL },
@@ -160,8 +157,7 @@ mframe_t chick_frames_start_run [] =
};
mmove_t chick_move_start_run = {FRAME_walk01, FRAME_walk10, chick_frames_start_run, chick_run};
-mframe_t chick_frames_run [] =
-{
+mframe_t chick_frames_run [] = {
{ ai_run, 6, NULL },
{ ai_run, 8, NULL },
{ ai_run, 13, NULL },
@@ -177,8 +173,7 @@ mframe_t chick_frames_run [] =
mmove_t chick_move_run = {FRAME_walk11, FRAME_walk20, chick_frames_run, NULL};
-mframe_t chick_frames_walk [] =
-{
+mframe_t chick_frames_walk [] = {
{ ai_walk, 6, NULL },
{ ai_walk, 8, NULL },
{ ai_walk, 13, NULL },
@@ -193,32 +188,27 @@ mframe_t chick_frames_walk [] =
mmove_t chick_move_walk = {FRAME_walk11, FRAME_walk20, chick_frames_walk, NULL};
-void chick_walk (edict_t *self)
+void chick_walk(edict_t *self)
{
self->monsterinfo.currentmove = &chick_move_walk;
}
-void chick_run (edict_t *self)
+void chick_run(edict_t *self)
{
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
self->monsterinfo.currentmove = &chick_move_stand;
return;
}
if (self->monsterinfo.currentmove == &chick_move_walk ||
- self->monsterinfo.currentmove == &chick_move_start_run)
- {
+ self->monsterinfo.currentmove == &chick_move_start_run) {
self->monsterinfo.currentmove = &chick_move_run;
- }
- else
- {
+ } else {
self->monsterinfo.currentmove = &chick_move_start_run;
}
}
-mframe_t chick_frames_pain1 [] =
-{
+mframe_t chick_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -227,8 +217,7 @@ mframe_t chick_frames_pain1 [] =
};
mmove_t chick_move_pain1 = {FRAME_pain101, FRAME_pain105, chick_frames_pain1, chick_run};
-mframe_t chick_frames_pain2 [] =
-{
+mframe_t chick_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -237,8 +226,7 @@ mframe_t chick_frames_pain2 [] =
};
mmove_t chick_move_pain2 = {FRAME_pain201, FRAME_pain205, chick_frames_pain2, chick_run};
-mframe_t chick_frames_pain3 [] =
-{
+mframe_t chick_frames_pain3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, -6, NULL },
@@ -263,7 +251,7 @@ mframe_t chick_frames_pain3 [] =
};
mmove_t chick_move_pain3 = {FRAME_pain301, FRAME_pain321, chick_frames_pain3, chick_run};
-void chick_pain (edict_t *self, edict_t *other, float kick, int damage)
+void chick_pain(edict_t *self, edict_t *other, float kick, int damage)
{
float r;
@@ -277,11 +265,11 @@ void chick_pain (edict_t *self, edict_t *other, float kick, int damage)
r = random();
if (r < 0.33)
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
else if (r < 0.66)
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
@@ -294,18 +282,17 @@ void chick_pain (edict_t *self, edict_t *other, float kick, int damage)
self->monsterinfo.currentmove = &chick_move_pain3;
}
-void chick_dead (edict_t *self)
+void chick_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, 0);
- VectorSet (self->maxs, 16, 16, 16);
+ VectorSet(self->mins, -16, -16, 0);
+ VectorSet(self->maxs, 16, 16, 16);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t chick_frames_death2 [] =
-{
+mframe_t chick_frames_death2 [] = {
{ ai_move, -6, NULL },
{ ai_move, 0, NULL },
{ ai_move, -1, NULL },
@@ -332,8 +319,7 @@ mframe_t chick_frames_death2 [] =
};
mmove_t chick_move_death2 = {FRAME_death201, FRAME_death223, chick_frames_death2, chick_dead};
-mframe_t chick_frames_death1 [] =
-{
+mframe_t chick_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, -7, NULL },
@@ -346,23 +332,22 @@ mframe_t chick_frames_death1 [] =
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL }
-
+
};
mmove_t chick_move_death1 = {FRAME_death101, FRAME_death112, chick_frames_death1, chick_dead};
-void chick_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void chick_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -375,20 +360,17 @@ void chick_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
self->takedamage = DAMAGE_YES;
n = rand() % 2;
- if (n == 0)
- {
+ if (n == 0) {
self->monsterinfo.currentmove = &chick_move_death1;
- gi.sound (self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
- }
- else
- {
+ gi.sound(self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
+ } else {
self->monsterinfo.currentmove = &chick_move_death2;
- gi.sound (self, CHAN_VOICE, sound_death2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death2, 1, ATTN_NORM, 0);
}
}
-void chick_duck_down (edict_t *self)
+void chick_duck_down(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
@@ -396,10 +378,10 @@ void chick_duck_down (edict_t *self)
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
self->monsterinfo.pausetime = level.time + 1;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void chick_duck_hold (edict_t *self)
+void chick_duck_hold(edict_t *self)
{
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -407,16 +389,15 @@ void chick_duck_hold (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-void chick_duck_up (edict_t *self)
+void chick_duck_up(edict_t *self)
{
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t chick_frames_duck [] =
-{
+mframe_t chick_frames_duck [] = {
{ ai_move, 0, chick_duck_down },
{ ai_move, 1, NULL },
{ ai_move, 4, chick_duck_hold },
@@ -427,7 +408,7 @@ mframe_t chick_frames_duck [] =
};
mmove_t chick_move_duck = {FRAME_duck01, FRAME_duck07, chick_frames_duck, chick_run};
-void chick_dodge (edict_t *self, edict_t *attacker, float eta)
+void chick_dodge(edict_t *self, edict_t *attacker, float eta)
{
if (random() > 0.25)
return;
@@ -438,47 +419,46 @@ void chick_dodge (edict_t *self, edict_t *attacker, float eta)
self->monsterinfo.currentmove = &chick_move_duck;
}
-void ChickSlash (edict_t *self)
+void ChickSlash(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], 10);
- gi.sound (self, CHAN_WEAPON, sound_melee_swing, 1, ATTN_NORM, 0);
- fire_hit (self, aim, (10 + (rand() %6)), 100);
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], 10);
+ gi.sound(self, CHAN_WEAPON, sound_melee_swing, 1, ATTN_NORM, 0);
+ fire_hit(self, aim, (10 + (rand() % 6)), 100);
}
-void ChickRocket (edict_t *self)
+void ChickRocket(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
vec3_t dir;
vec3_t vec;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_CHICK_ROCKET_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_CHICK_ROCKET_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
- monster_fire_rocket (self, start, dir, 50, 500, MZ2_CHICK_ROCKET_1);
-}
+ monster_fire_rocket(self, start, dir, 50, 500, MZ2_CHICK_ROCKET_1);
+}
-void Chick_PreAttack1 (edict_t *self)
+void Chick_PreAttack1(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_missile_prelaunch, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_missile_prelaunch, 1, ATTN_NORM, 0);
}
-void ChickReload (edict_t *self)
+void ChickReload(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_missile_reload, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_missile_reload, 1, ATTN_NORM, 0);
}
-mframe_t chick_frames_start_attack1 [] =
-{
+mframe_t chick_frames_start_attack1 [] = {
{ ai_charge, 0, Chick_PreAttack1 },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -496,8 +476,7 @@ mframe_t chick_frames_start_attack1 [] =
mmove_t chick_move_start_attack1 = {FRAME_attak101, FRAME_attak113, chick_frames_start_attack1, NULL};
-mframe_t chick_frames_attack1 [] =
-{
+mframe_t chick_frames_attack1 [] = {
{ ai_charge, 19, ChickRocket },
{ ai_charge, -6, NULL },
{ ai_charge, -5, NULL },
@@ -516,8 +495,7 @@ mframe_t chick_frames_attack1 [] =
};
mmove_t chick_move_attack1 = {FRAME_attak114, FRAME_attak127, chick_frames_attack1, NULL};
-mframe_t chick_frames_end_attack1 [] =
-{
+mframe_t chick_frames_end_attack1 [] = {
{ ai_charge, -3, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, -6, NULL },
@@ -528,16 +506,14 @@ mmove_t chick_move_end_attack1 = {FRAME_attak128, FRAME_attak132, chick_frames_e
void chick_rerocket(edict_t *self)
{
- if (self->enemy->health > 0)
- {
- if (range (self, self->enemy) > RANGE_MELEE)
- if ( visible (self, self->enemy) )
- if (random() <= 0.6)
- {
+ if (self->enemy->health > 0) {
+ if (range(self, self->enemy) > RANGE_MELEE)
+ if (visible(self, self->enemy))
+ if (random() <= 0.6) {
self->monsterinfo.currentmove = &chick_move_attack1;
return;
}
- }
+ }
self->monsterinfo.currentmove = &chick_move_end_attack1;
}
@@ -546,8 +522,7 @@ void chick_attack1(edict_t *self)
self->monsterinfo.currentmove = &chick_move_attack1;
}
-mframe_t chick_frames_slash [] =
-{
+mframe_t chick_frames_slash [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 7, ChickSlash },
{ ai_charge, -7, NULL },
@@ -560,8 +535,7 @@ mframe_t chick_frames_slash [] =
};
mmove_t chick_move_slash = {FRAME_attak204, FRAME_attak212, chick_frames_slash, NULL};
-mframe_t chick_frames_end_slash [] =
-{
+mframe_t chick_frames_end_slash [] = {
{ ai_charge, -6, NULL },
{ ai_charge, -1, NULL },
{ ai_charge, -6, NULL },
@@ -572,17 +546,12 @@ mmove_t chick_move_end_slash = {FRAME_attak213, FRAME_attak216, chick_frames_end
void chick_reslash(edict_t *self)
{
- if (self->enemy->health > 0)
- {
- if (range (self, self->enemy) == RANGE_MELEE)
- {
- if (random() <= 0.9)
- {
+ if (self->enemy->health > 0) {
+ if (range(self, self->enemy) == RANGE_MELEE) {
+ if (random() <= 0.9) {
self->monsterinfo.currentmove = &chick_move_slash;
return;
- }
- else
- {
+ } else {
self->monsterinfo.currentmove = &chick_move_end_slash;
return;
}
@@ -597,8 +566,7 @@ void chick_slash(edict_t *self)
}
-mframe_t chick_frames_start_slash [] =
-{
+mframe_t chick_frames_start_slash [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 8, NULL },
{ ai_charge, 3, NULL }
@@ -620,40 +588,39 @@ void chick_attack(edict_t *self)
void chick_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
/*QUAKED monster_chick (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_chick (edict_t *self)
+void SP_monster_chick(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_missile_prelaunch = gi.soundindex ("chick/chkatck1.wav");
- sound_missile_launch = gi.soundindex ("chick/chkatck2.wav");
- sound_melee_swing = gi.soundindex ("chick/chkatck3.wav");
- sound_melee_hit = gi.soundindex ("chick/chkatck4.wav");
- sound_missile_reload = gi.soundindex ("chick/chkatck5.wav");
- sound_death1 = gi.soundindex ("chick/chkdeth1.wav");
- sound_death2 = gi.soundindex ("chick/chkdeth2.wav");
- sound_fall_down = gi.soundindex ("chick/chkfall1.wav");
- sound_idle1 = gi.soundindex ("chick/chkidle1.wav");
- sound_idle2 = gi.soundindex ("chick/chkidle2.wav");
- sound_pain1 = gi.soundindex ("chick/chkpain1.wav");
- sound_pain2 = gi.soundindex ("chick/chkpain2.wav");
- sound_pain3 = gi.soundindex ("chick/chkpain3.wav");
- sound_sight = gi.soundindex ("chick/chksght1.wav");
- sound_search = gi.soundindex ("chick/chksrch1.wav");
+ sound_missile_prelaunch = gi.soundindex("chick/chkatck1.wav");
+ sound_missile_launch = gi.soundindex("chick/chkatck2.wav");
+ sound_melee_swing = gi.soundindex("chick/chkatck3.wav");
+ sound_melee_hit = gi.soundindex("chick/chkatck4.wav");
+ sound_missile_reload = gi.soundindex("chick/chkatck5.wav");
+ sound_death1 = gi.soundindex("chick/chkdeth1.wav");
+ sound_death2 = gi.soundindex("chick/chkdeth2.wav");
+ sound_fall_down = gi.soundindex("chick/chkfall1.wav");
+ sound_idle1 = gi.soundindex("chick/chkidle1.wav");
+ sound_idle2 = gi.soundindex("chick/chkidle2.wav");
+ sound_pain1 = gi.soundindex("chick/chkpain1.wav");
+ sound_pain2 = gi.soundindex("chick/chkpain2.wav");
+ sound_pain3 = gi.soundindex("chick/chkpain3.wav");
+ sound_sight = gi.soundindex("chick/chksght1.wav");
+ sound_search = gi.soundindex("chick/chksrch1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/bitch/tris.md2");
- VectorSet (self->mins, -16, -16, 0);
- VectorSet (self->maxs, 16, 16, 56);
+ self->s.modelindex = gi.modelindex("models/monsters/bitch/tris.md2");
+ VectorSet(self->mins, -16, -16, 0);
+ VectorSet(self->maxs, 16, 16, 56);
self->health = 175;
self->gib_health = -70;
@@ -670,10 +637,10 @@ void SP_monster_chick (edict_t *self)
self->monsterinfo.melee = chick_melee;
self->monsterinfo.sight = chick_sight;
- gi.linkentity (self);
+ gi.linkentity(self);
self->monsterinfo.currentmove = &chick_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_chick.h b/src/baseq2/m_chick.h
index b4d5c21..eb51acd 100644
--- a/src/baseq2/m_chick.h
+++ b/src/baseq2/m_chick.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_flipper.c b/src/baseq2/m_flipper.c
index 2fbe1aa..0dbcfd8 100644
--- a/src/baseq2/m_flipper.c
+++ b/src/baseq2/m_flipper.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -39,24 +39,22 @@ static int sound_search;
static int sound_sight;
-void flipper_stand (edict_t *self);
+void flipper_stand(edict_t *self);
-mframe_t flipper_frames_stand [] =
-{
+mframe_t flipper_frames_stand [] = {
{ ai_stand, 0, NULL }
};
-
+
mmove_t flipper_move_stand = {FRAME_flphor01, FRAME_flphor01, flipper_frames_stand, NULL};
-void flipper_stand (edict_t *self)
+void flipper_stand(edict_t *self)
{
- self->monsterinfo.currentmove = &flipper_move_stand;
+ self->monsterinfo.currentmove = &flipper_move_stand;
}
#define FLIPPER_RUN_SPEED 24
-mframe_t flipper_frames_run [] =
-{
+mframe_t flipper_frames_run [] = {
{ ai_run, FLIPPER_RUN_SPEED, NULL }, // 6
{ ai_run, FLIPPER_RUN_SPEED, NULL },
{ ai_run, FLIPPER_RUN_SPEED, NULL },
@@ -86,13 +84,12 @@ mframe_t flipper_frames_run [] =
};
mmove_t flipper_move_run_loop = {FRAME_flpver06, FRAME_flpver29, flipper_frames_run, NULL};
-void flipper_run_loop (edict_t *self)
+void flipper_run_loop(edict_t *self)
{
self->monsterinfo.currentmove = &flipper_move_run_loop;
}
-mframe_t flipper_frames_run_start [] =
-{
+mframe_t flipper_frames_run_start [] = {
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
@@ -102,14 +99,13 @@ mframe_t flipper_frames_run_start [] =
};
mmove_t flipper_move_run_start = {FRAME_flpver01, FRAME_flpver06, flipper_frames_run_start, flipper_run_loop};
-void flipper_run (edict_t *self)
+void flipper_run(edict_t *self)
{
self->monsterinfo.currentmove = &flipper_move_run_start;
}
-/* Standard Swimming */
-mframe_t flipper_frames_walk [] =
-{
+/* Standard Swimming */
+mframe_t flipper_frames_walk [] = {
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
@@ -137,13 +133,12 @@ mframe_t flipper_frames_walk [] =
};
mmove_t flipper_move_walk = {FRAME_flphor01, FRAME_flphor24, flipper_frames_walk, NULL};
-void flipper_walk (edict_t *self)
+void flipper_walk(edict_t *self)
{
self->monsterinfo.currentmove = &flipper_move_walk;
}
-mframe_t flipper_frames_start_run [] =
-{
+mframe_t flipper_frames_start_run [] = {
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
{ ai_run, 8, NULL },
@@ -152,13 +147,12 @@ mframe_t flipper_frames_start_run [] =
};
mmove_t flipper_move_start_run = {FRAME_flphor01, FRAME_flphor05, flipper_frames_start_run, NULL};
-void flipper_start_run (edict_t *self)
+void flipper_start_run(edict_t *self)
{
self->monsterinfo.currentmove = &flipper_move_start_run;
}
-mframe_t flipper_frames_pain2 [] =
-{
+mframe_t flipper_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -167,8 +161,7 @@ mframe_t flipper_frames_pain2 [] =
};
mmove_t flipper_move_pain2 = {FRAME_flppn101, FRAME_flppn105, flipper_frames_pain2, flipper_run};
-mframe_t flipper_frames_pain1 [] =
-{
+mframe_t flipper_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -177,21 +170,20 @@ mframe_t flipper_frames_pain1 [] =
};
mmove_t flipper_move_pain1 = {FRAME_flppn201, FRAME_flppn205, flipper_frames_pain1, flipper_run};
-void flipper_bite (edict_t *self)
+void flipper_bite(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, 0, 0);
- fire_hit (self, aim, 5, 0);
+ VectorSet(aim, MELEE_DISTANCE, 0, 0);
+ fire_hit(self, aim, 5, 0);
}
-void flipper_preattack (edict_t *self)
+void flipper_preattack(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_chomp, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_chomp, 1, ATTN_NORM, 0);
}
-mframe_t flipper_frames_attack [] =
-{
+mframe_t flipper_frames_attack [] = {
{ ai_charge, 0, flipper_preattack },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -220,7 +212,7 @@ void flipper_melee(edict_t *self)
self->monsterinfo.currentmove = &flipper_move_attack;
}
-void flipper_pain (edict_t *self, edict_t *other, float kick, int damage)
+void flipper_pain(edict_t *self, edict_t *other, float kick, int damage)
{
int n;
@@ -231,35 +223,31 @@ void flipper_pain (edict_t *self, edict_t *other, float kick, int damage)
return;
self->pain_debounce_time = level.time + 3;
-
+
if (skill->value == 3)
return; // no pain anims in nightmare
n = (rand() + 1) % 2;
- if (n == 0)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (n == 0) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &flipper_move_pain1;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &flipper_move_pain2;
}
}
-void flipper_dead (edict_t *self)
+void flipper_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t flipper_frames_death [] =
-{
+mframe_t flipper_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -324,24 +312,23 @@ mframe_t flipper_frames_death [] =
};
mmove_t flipper_move_death = {FRAME_flpdth01, FRAME_flpdth56, flipper_frames_death, flipper_dead};
-void flipper_sight (edict_t *self, edict_t *other)
+void flipper_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void flipper_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void flipper_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -350,7 +337,7 @@ void flipper_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->monsterinfo.currentmove = &flipper_move_death;
@@ -358,28 +345,27 @@ void flipper_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
/*QUAKED monster_flipper (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_flipper (edict_t *self)
+void SP_monster_flipper(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("flipper/flppain1.wav");
- sound_pain2 = gi.soundindex ("flipper/flppain2.wav");
- sound_death = gi.soundindex ("flipper/flpdeth1.wav");
- sound_chomp = gi.soundindex ("flipper/flpatck1.wav");
- sound_attack = gi.soundindex ("flipper/flpatck2.wav");
- sound_idle = gi.soundindex ("flipper/flpidle1.wav");
- sound_search = gi.soundindex ("flipper/flpsrch1.wav");
- sound_sight = gi.soundindex ("flipper/flpsght1.wav");
+ sound_pain1 = gi.soundindex("flipper/flppain1.wav");
+ sound_pain2 = gi.soundindex("flipper/flppain2.wav");
+ sound_death = gi.soundindex("flipper/flpdeth1.wav");
+ sound_chomp = gi.soundindex("flipper/flpatck1.wav");
+ sound_attack = gi.soundindex("flipper/flpatck2.wav");
+ sound_idle = gi.soundindex("flipper/flpidle1.wav");
+ sound_search = gi.soundindex("flipper/flpsrch1.wav");
+ sound_sight = gi.soundindex("flipper/flpsght1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/flipper/tris.md2");
- VectorSet (self->mins, -16, -16, 0);
- VectorSet (self->maxs, 16, 16, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/flipper/tris.md2");
+ VectorSet(self->mins, -16, -16, 0);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 50;
self->gib_health = -30;
@@ -394,10 +380,10 @@ void SP_monster_flipper (edict_t *self)
self->monsterinfo.melee = flipper_melee;
self->monsterinfo.sight = flipper_sight;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &flipper_move_stand;
+ self->monsterinfo.currentmove = &flipper_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- swimmonster_start (self);
+ swimmonster_start(self);
}
diff --git a/src/baseq2/m_flipper.h b/src/baseq2/m_flipper.h
index 6958c39..5a922fe 100644
--- a/src/baseq2/m_flipper.h
+++ b/src/baseq2/m_flipper.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_float.c b/src/baseq2/m_float.c
index af2ae84..025f49b 100644
--- a/src/baseq2/m_float.c
+++ b/src/baseq2/m_float.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -38,26 +38,26 @@ static int sound_pain2;
static int sound_sight;
-void floater_sight (edict_t *self, edict_t *other)
+void floater_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void floater_idle (edict_t *self)
+void floater_idle(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
//void floater_stand1 (edict_t *self);
-void floater_dead (edict_t *self);
-void floater_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
-void floater_run (edict_t *self);
-void floater_wham (edict_t *self);
-void floater_zap (edict_t *self);
+void floater_dead(edict_t *self);
+void floater_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
+void floater_run(edict_t *self);
+void floater_wham(edict_t *self);
+void floater_zap(edict_t *self);
-void floater_fire_blaster (edict_t *self)
+void floater_fire_blaster(edict_t *self)
{
vec3_t start;
vec3_t forward, right;
@@ -69,19 +69,18 @@ void floater_fire_blaster (edict_t *self)
effect = EF_HYPERBLASTER;
else
effect = 0;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_FLOAT_BLASTER_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_FLOAT_BLASTER_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, dir);
+ VectorSubtract(end, start, dir);
- monster_fire_blaster (self, start, dir, 1, 1000, MZ2_FLOAT_BLASTER_1, effect);
+ monster_fire_blaster(self, start, dir, 1, 1000, MZ2_FLOAT_BLASTER_1, effect);
}
-mframe_t floater_frames_stand1 [] =
-{
+mframe_t floater_frames_stand1 [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -137,8 +136,7 @@ mframe_t floater_frames_stand1 [] =
};
mmove_t floater_move_stand1 = {FRAME_stand101, FRAME_stand152, floater_frames_stand1, NULL};
-mframe_t floater_frames_stand2 [] =
-{
+mframe_t floater_frames_stand2 [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -194,51 +192,49 @@ mframe_t floater_frames_stand2 [] =
};
mmove_t floater_move_stand2 = {FRAME_stand201, FRAME_stand252, floater_frames_stand2, NULL};
-void floater_stand (edict_t *self)
+void floater_stand(edict_t *self)
{
- if (random() <= 0.5)
+ if (random() <= 0.5)
self->monsterinfo.currentmove = &floater_move_stand1;
else
self->monsterinfo.currentmove = &floater_move_stand2;
}
-mframe_t floater_frames_activate [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
+mframe_t floater_frames_activate [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
{ ai_move, 0, NULL }
};
mmove_t floater_move_activate = {FRAME_actvat01, FRAME_actvat31, floater_frames_activate, NULL};
-mframe_t floater_frames_attack1 [] =
-{
+mframe_t floater_frames_attack1 [] = {
{ ai_charge, 0, NULL }, // Blaster attack
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -256,8 +252,7 @@ mframe_t floater_frames_attack1 [] =
};
mmove_t floater_move_attack1 = {FRAME_attak101, FRAME_attak114, floater_frames_attack1, floater_run};
-mframe_t floater_frames_attack2 [] =
-{
+mframe_t floater_frames_attack2 [] = {
{ ai_charge, 0, NULL }, // Claws
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -286,8 +281,7 @@ mframe_t floater_frames_attack2 [] =
};
mmove_t floater_move_attack2 = {FRAME_attak201, FRAME_attak225, floater_frames_attack2, floater_run};
-mframe_t floater_frames_attack3 [] =
-{
+mframe_t floater_frames_attack3 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -325,8 +319,7 @@ mframe_t floater_frames_attack3 [] =
};
mmove_t floater_move_attack3 = {FRAME_attak301, FRAME_attak334, floater_frames_attack3, floater_run};
-mframe_t floater_frames_death [] =
-{
+mframe_t floater_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -343,8 +336,7 @@ mframe_t floater_frames_death [] =
};
mmove_t floater_move_death = {FRAME_death01, FRAME_death13, floater_frames_death, floater_dead};
-mframe_t floater_frames_pain1 [] =
-{
+mframe_t floater_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -355,8 +347,7 @@ mframe_t floater_frames_pain1 [] =
};
mmove_t floater_move_pain1 = {FRAME_pain101, FRAME_pain107, floater_frames_pain1, floater_run};
-mframe_t floater_frames_pain2 [] =
-{
+mframe_t floater_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -368,8 +359,7 @@ mframe_t floater_frames_pain2 [] =
};
mmove_t floater_move_pain2 = {FRAME_pain201, FRAME_pain208, floater_frames_pain2, floater_run};
-mframe_t floater_frames_pain3 [] =
-{
+mframe_t floater_frames_pain3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -385,8 +375,7 @@ mframe_t floater_frames_pain3 [] =
};
mmove_t floater_move_pain3 = {FRAME_pain301, FRAME_pain312, floater_frames_pain3, floater_run};
-mframe_t floater_frames_walk [] =
-{
+mframe_t floater_frames_walk [] = {
{ ai_walk, 5, NULL },
{ ai_walk, 5, NULL },
{ ai_walk, 5, NULL },
@@ -442,8 +431,7 @@ mframe_t floater_frames_walk [] =
};
mmove_t floater_move_walk = {FRAME_stand101, FRAME_stand152, floater_frames_walk, NULL};
-mframe_t floater_frames_run [] =
-{
+mframe_t floater_frames_run [] = {
{ ai_run, 13, NULL },
{ ai_run, 13, NULL },
{ ai_run, 13, NULL },
@@ -499,7 +487,7 @@ mframe_t floater_frames_run [] =
};
mmove_t floater_move_run = {FRAME_stand101, FRAME_stand152, floater_frames_run, NULL};
-void floater_run (edict_t *self)
+void floater_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &floater_move_stand1;
@@ -507,45 +495,45 @@ void floater_run (edict_t *self)
self->monsterinfo.currentmove = &floater_move_run;
}
-void floater_walk (edict_t *self)
+void floater_walk(edict_t *self)
{
self->monsterinfo.currentmove = &floater_move_walk;
}
-void floater_wham (edict_t *self)
+void floater_wham(edict_t *self)
{
static vec3_t aim = {MELEE_DISTANCE, 0, 0};
- gi.sound (self, CHAN_WEAPON, sound_attack3, 1, ATTN_NORM, 0);
- fire_hit (self, aim, 5 + rand() % 6, -50);
+ gi.sound(self, CHAN_WEAPON, sound_attack3, 1, ATTN_NORM, 0);
+ fire_hit(self, aim, 5 + rand() % 6, -50);
}
-void floater_zap (edict_t *self)
+void floater_zap(edict_t *self)
{
vec3_t forward, right;
vec3_t origin;
vec3_t dir;
vec3_t offset;
- VectorSubtract (self->enemy->s.origin, self->s.origin, dir);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
- AngleVectors (self->s.angles, forward, right, NULL);
+ AngleVectors(self->s.angles, forward, right, NULL);
//FIXME use a flash and replace these two lines with the commented one
- VectorSet (offset, 18.5, -0.9, 10);
- G_ProjectSource (self->s.origin, offset, forward, right, origin);
+ VectorSet(offset, 18.5, -0.9, 10);
+ G_ProjectSource(self->s.origin, offset, forward, right, origin);
// G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, origin);
- gi.sound (self, CHAN_WEAPON, sound_attack2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_attack2, 1, ATTN_NORM, 0);
//FIXME use the flash, Luke
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_SPLASH);
- gi.WriteByte (32);
- gi.WritePosition (origin);
- gi.WriteDir (dir);
- gi.WriteByte (1); //sparks
- gi.multicast (origin, MULTICAST_PVS);
-
- T_Damage (self->enemy, self, self, dir, self->enemy->s.origin, vec3_origin, 5 + rand() % 6, -10, DAMAGE_ENERGY, MOD_UNKNOWN);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_SPLASH);
+ gi.WriteByte(32);
+ gi.WritePosition(origin);
+ gi.WriteDir(dir);
+ gi.WriteByte(1); //sparks
+ gi.multicast(origin, MULTICAST_PVS);
+
+ T_Damage(self->enemy, self, self, dir, self->enemy->s.origin, vec3_origin, 5 + rand() % 6, -10, DAMAGE_ENERGY, MOD_UNKNOWN);
}
void floater_attack(edict_t *self)
@@ -556,14 +544,14 @@ void floater_attack(edict_t *self)
void floater_melee(edict_t *self)
{
- if (random() < 0.5)
+ if (random() < 0.5)
self->monsterinfo.currentmove = &floater_move_attack3;
else
self->monsterinfo.currentmove = &floater_move_attack2;
}
-void floater_pain (edict_t *self, edict_t *other, float kick, int damage)
+void floater_pain(edict_t *self, edict_t *other, float kick, int damage)
{
int n;
@@ -578,61 +566,57 @@ void floater_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
n = (rand() + 1) % 3;
- if (n == 0)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (n == 0) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &floater_move_pain1;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &floater_move_pain2;
}
}
-void floater_dead (edict_t *self)
+void floater_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void floater_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void floater_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- gi.sound (self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
BecomeExplosion1(self);
}
/*QUAKED monster_floater (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_floater (edict_t *self)
+void SP_monster_floater(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_attack2 = gi.soundindex ("floater/fltatck2.wav");
- sound_attack3 = gi.soundindex ("floater/fltatck3.wav");
- sound_death1 = gi.soundindex ("floater/fltdeth1.wav");
- sound_idle = gi.soundindex ("floater/fltidle1.wav");
- sound_pain1 = gi.soundindex ("floater/fltpain1.wav");
- sound_pain2 = gi.soundindex ("floater/fltpain2.wav");
- sound_sight = gi.soundindex ("floater/fltsght1.wav");
+ sound_attack2 = gi.soundindex("floater/fltatck2.wav");
+ sound_attack3 = gi.soundindex("floater/fltatck3.wav");
+ sound_death1 = gi.soundindex("floater/fltdeth1.wav");
+ sound_idle = gi.soundindex("floater/fltidle1.wav");
+ sound_pain1 = gi.soundindex("floater/fltpain1.wav");
+ sound_pain2 = gi.soundindex("floater/fltpain2.wav");
+ sound_sight = gi.soundindex("floater/fltsght1.wav");
- gi.soundindex ("floater/fltatck1.wav");
+ gi.soundindex("floater/fltatck1.wav");
- self->s.sound = gi.soundindex ("floater/fltsrch1.wav");
+ self->s.sound = gi.soundindex("floater/fltsrch1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/float/tris.md2");
- VectorSet (self->mins, -24, -24, -24);
- VectorSet (self->maxs, 24, 24, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/float/tris.md2");
+ VectorSet(self->mins, -24, -24, -24);
+ VectorSet(self->maxs, 24, 24, 32);
self->health = 200;
self->gib_health = -80;
@@ -650,14 +634,14 @@ void SP_monster_floater (edict_t *self)
self->monsterinfo.sight = floater_sight;
self->monsterinfo.idle = floater_idle;
- gi.linkentity (self);
+ gi.linkentity(self);
- if (random() <= 0.5)
- self->monsterinfo.currentmove = &floater_move_stand1;
+ if (random() <= 0.5)
+ self->monsterinfo.currentmove = &floater_move_stand1;
else
- self->monsterinfo.currentmove = &floater_move_stand2;
-
+ self->monsterinfo.currentmove = &floater_move_stand2;
+
self->monsterinfo.scale = MODEL_SCALE;
- flymonster_start (self);
+ flymonster_start(self);
}
diff --git a/src/baseq2/m_float.h b/src/baseq2/m_float.h
index da7e6ed..36b0bc5 100644
--- a/src/baseq2/m_float.h
+++ b/src/baseq2/m_float.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_flyer.c b/src/baseq2/m_flyer.c
index a5ed179..9b9f319 100644
--- a/src/baseq2/m_flyer.c
+++ b/src/baseq2/m_flyer.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ flyer
#include "g_local.h"
#include "m_flyer.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
static int nextmove; // Used for start/stop frames
@@ -42,31 +42,30 @@ static int sound_die;
void flyer_check_melee(edict_t *self);
-void flyer_loop_melee (edict_t *self);
-void flyer_melee (edict_t *self);
-void flyer_setstart (edict_t *self);
-void flyer_stand (edict_t *self);
-void flyer_nextmove (edict_t *self);
+void flyer_loop_melee(edict_t *self);
+void flyer_melee(edict_t *self);
+void flyer_setstart(edict_t *self);
+void flyer_stand(edict_t *self);
+void flyer_nextmove(edict_t *self);
-void flyer_sight (edict_t *self, edict_t *other)
+void flyer_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void flyer_idle (edict_t *self)
+void flyer_idle(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
-void flyer_pop_blades (edict_t *self)
+void flyer_pop_blades(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_sproing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sproing, 1, ATTN_NORM, 0);
}
-mframe_t flyer_frames_stand [] =
-{
+mframe_t flyer_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -116,8 +115,7 @@ mframe_t flyer_frames_stand [] =
mmove_t flyer_move_stand = {FRAME_stand01, FRAME_stand45, flyer_frames_stand, NULL};
-mframe_t flyer_frames_walk [] =
-{
+mframe_t flyer_frames_walk [] = {
{ ai_walk, 5, NULL },
{ ai_walk, 5, NULL },
{ ai_walk, 5, NULL },
@@ -166,8 +164,7 @@ mframe_t flyer_frames_walk [] =
};
mmove_t flyer_move_walk = {FRAME_stand01, FRAME_stand45, flyer_frames_walk, NULL};
-mframe_t flyer_frames_run [] =
-{
+mframe_t flyer_frames_run [] = {
{ ai_run, 10, NULL },
{ ai_run, 10, NULL },
{ ai_run, 10, NULL },
@@ -216,7 +213,7 @@ mframe_t flyer_frames_run [] =
};
mmove_t flyer_move_run = {FRAME_stand01, FRAME_stand45, flyer_frames_run, NULL};
-void flyer_run (edict_t *self)
+void flyer_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &flyer_move_stand;
@@ -224,147 +221,137 @@ void flyer_run (edict_t *self)
self->monsterinfo.currentmove = &flyer_move_run;
}
-void flyer_walk (edict_t *self)
+void flyer_walk(edict_t *self)
{
self->monsterinfo.currentmove = &flyer_move_walk;
}
-void flyer_stand (edict_t *self)
+void flyer_stand(edict_t *self)
{
- self->monsterinfo.currentmove = &flyer_move_stand;
+ self->monsterinfo.currentmove = &flyer_move_stand;
}
-mframe_t flyer_frames_start [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, flyer_nextmove }
+mframe_t flyer_frames_start [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, flyer_nextmove }
};
mmove_t flyer_move_start = {FRAME_start01, FRAME_start06, flyer_frames_start, NULL};
-mframe_t flyer_frames_stop [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, flyer_nextmove }
+mframe_t flyer_frames_stop [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, flyer_nextmove }
};
mmove_t flyer_move_stop = {FRAME_stop01, FRAME_stop07, flyer_frames_stop, NULL};
-void flyer_stop (edict_t *self)
+void flyer_stop(edict_t *self)
{
- self->monsterinfo.currentmove = &flyer_move_stop;
+ self->monsterinfo.currentmove = &flyer_move_stop;
}
-void flyer_start (edict_t *self)
+void flyer_start(edict_t *self)
{
- self->monsterinfo.currentmove = &flyer_move_start;
+ self->monsterinfo.currentmove = &flyer_move_start;
}
-mframe_t flyer_frames_rollright [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_rollright [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_rollright = {FRAME_rollr01, FRAME_rollr09, flyer_frames_rollright, NULL};
-mframe_t flyer_frames_rollleft [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_rollleft [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_rollleft = {FRAME_rollf01, FRAME_rollf09, flyer_frames_rollleft, NULL};
-mframe_t flyer_frames_pain3 [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_pain3 [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_pain3 = {FRAME_pain301, FRAME_pain304, flyer_frames_pain3, flyer_run};
-mframe_t flyer_frames_pain2 [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_pain2 [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_pain2 = {FRAME_pain201, FRAME_pain204, flyer_frames_pain2, flyer_run};
-mframe_t flyer_frames_pain1 [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_pain1 [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_pain1 = {FRAME_pain101, FRAME_pain109, flyer_frames_pain1, flyer_run};
-mframe_t flyer_frames_defense [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }, // Hold this frame
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_defense [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }, // Hold this frame
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_defense = {FRAME_defens01, FRAME_defens06, flyer_frames_defense, NULL};
-mframe_t flyer_frames_bankright [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_bankright [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
mmove_t flyer_move_bankright = {FRAME_bankr01, FRAME_bankr07, flyer_frames_bankright, NULL};
-mframe_t flyer_frames_bankleft [] =
-{
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL },
- { ai_move, 0, NULL }
+mframe_t flyer_frames_bankleft [] = {
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL },
+ { ai_move, 0, NULL }
};
-mmove_t flyer_move_bankleft = {FRAME_bankl01, FRAME_bankl07, flyer_frames_bankleft, NULL};
+mmove_t flyer_move_bankleft = {FRAME_bankl01, FRAME_bankl07, flyer_frames_bankleft, NULL};
-void flyer_fire (edict_t *self, int flash_number)
+void flyer_fire(edict_t *self, int flash_number)
{
vec3_t start;
vec3_t forward, right;
@@ -376,131 +363,127 @@ void flyer_fire (edict_t *self, int flash_number)
effect = EF_HYPERBLASTER;
else
effect = 0;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
-
- VectorCopy (self->enemy->s.origin, end);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, dir);
+ VectorSubtract(end, start, dir);
- monster_fire_blaster (self, start, dir, 1, 1000, flash_number, effect);
+ monster_fire_blaster(self, start, dir, 1, 1000, flash_number, effect);
}
-void flyer_fireleft (edict_t *self)
+void flyer_fireleft(edict_t *self)
{
- flyer_fire (self, MZ2_FLYER_BLASTER_1);
+ flyer_fire(self, MZ2_FLYER_BLASTER_1);
}
-void flyer_fireright (edict_t *self)
+void flyer_fireright(edict_t *self)
{
- flyer_fire (self, MZ2_FLYER_BLASTER_2);
+ flyer_fire(self, MZ2_FLYER_BLASTER_2);
}
-mframe_t flyer_frames_attack2 [] =
-{
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, -10, flyer_fireleft }, // left gun
- { ai_charge, -10, flyer_fireright }, // right gun
- { ai_charge, -10, flyer_fireleft }, // left gun
- { ai_charge, -10, flyer_fireright }, // right gun
- { ai_charge, -10, flyer_fireleft }, // left gun
- { ai_charge, -10, flyer_fireright }, // right gun
- { ai_charge, -10, flyer_fireleft }, // left gun
- { ai_charge, -10, flyer_fireright }, // right gun
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL }
+mframe_t flyer_frames_attack2 [] = {
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, -10, flyer_fireleft }, // left gun
+ { ai_charge, -10, flyer_fireright }, // right gun
+ { ai_charge, -10, flyer_fireleft }, // left gun
+ { ai_charge, -10, flyer_fireright }, // right gun
+ { ai_charge, -10, flyer_fireleft }, // left gun
+ { ai_charge, -10, flyer_fireright }, // right gun
+ { ai_charge, -10, flyer_fireleft }, // left gun
+ { ai_charge, -10, flyer_fireright }, // right gun
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL }
};
mmove_t flyer_move_attack2 = {FRAME_attak201, FRAME_attak217, flyer_frames_attack2, flyer_run};
-void flyer_slash_left (edict_t *self)
+void flyer_slash_left(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], 0);
- fire_hit (self, aim, 5, 0);
- gi.sound (self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], 0);
+ fire_hit(self, aim, 5, 0);
+ gi.sound(self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
}
-void flyer_slash_right (edict_t *self)
+void flyer_slash_right(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->maxs[0], 0);
- fire_hit (self, aim, 5, 0);
- gi.sound (self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->maxs[0], 0);
+ fire_hit(self, aim, 5, 0);
+ gi.sound(self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
}
-mframe_t flyer_frames_start_melee [] =
-{
- { ai_charge, 0, flyer_pop_blades },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL }
+mframe_t flyer_frames_start_melee [] = {
+ { ai_charge, 0, flyer_pop_blades },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL }
};
mmove_t flyer_move_start_melee = {FRAME_attak101, FRAME_attak106, flyer_frames_start_melee, flyer_loop_melee};
-mframe_t flyer_frames_end_melee [] =
-{
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL }
+mframe_t flyer_frames_end_melee [] = {
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL }
};
mmove_t flyer_move_end_melee = {FRAME_attak119, FRAME_attak121, flyer_frames_end_melee, flyer_run};
-mframe_t flyer_frames_loop_melee [] =
-{
- { ai_charge, 0, NULL }, // Loop Start
- { ai_charge, 0, NULL },
- { ai_charge, 0, flyer_slash_left }, // Left Wing Strike
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, flyer_slash_right }, // Right Wing Strike
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL },
- { ai_charge, 0, NULL } // Loop Ends
-
+mframe_t flyer_frames_loop_melee [] = {
+ { ai_charge, 0, NULL }, // Loop Start
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, flyer_slash_left }, // Left Wing Strike
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, flyer_slash_right }, // Right Wing Strike
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL },
+ { ai_charge, 0, NULL } // Loop Ends
+
};
mmove_t flyer_move_loop_melee = {FRAME_attak107, FRAME_attak118, flyer_frames_loop_melee, flyer_check_melee};
-void flyer_loop_melee (edict_t *self)
+void flyer_loop_melee(edict_t *self)
{
-/* if (random() <= 0.5)
- self->monsterinfo.currentmove = &flyer_move_attack1;
- else */
+ /* if (random() <= 0.5)
+ self->monsterinfo.currentmove = &flyer_move_attack1;
+ else */
self->monsterinfo.currentmove = &flyer_move_loop_melee;
}
-void flyer_attack (edict_t *self)
+void flyer_attack(edict_t *self)
{
-/* if (random() <= 0.5)
- self->monsterinfo.currentmove = &flyer_move_attack1;
- else */
+ /* if (random() <= 0.5)
+ self->monsterinfo.currentmove = &flyer_move_attack1;
+ else */
self->monsterinfo.currentmove = &flyer_move_attack2;
}
-void flyer_setstart (edict_t *self)
+void flyer_setstart(edict_t *self)
{
nextmove = ACTION_run;
self->monsterinfo.currentmove = &flyer_move_start;
}
-void flyer_nextmove (edict_t *self)
+void flyer_nextmove(edict_t *self)
{
if (nextmove == ACTION_attack1)
self->monsterinfo.currentmove = &flyer_move_start_melee;
@@ -510,7 +493,7 @@ void flyer_nextmove (edict_t *self)
self->monsterinfo.currentmove = &flyer_move_run;
}
-void flyer_melee (edict_t *self)
+void flyer_melee(edict_t *self)
{
// flyer.nextmove = ACTION_attack1;
// self->monsterinfo.currentmove = &flyer_move_stop;
@@ -519,7 +502,7 @@ void flyer_melee (edict_t *self)
void flyer_check_melee(edict_t *self)
{
- if (range (self, self->enemy) == RANGE_MELEE)
+ if (range(self, self->enemy) == RANGE_MELEE)
if (random() <= 0.8)
self->monsterinfo.currentmove = &flyer_move_loop_melee;
else
@@ -528,7 +511,7 @@ void flyer_check_melee(edict_t *self)
self->monsterinfo.currentmove = &flyer_move_end_melee;
}
-void flyer_pain (edict_t *self, edict_t *other, float kick, int damage)
+void flyer_pain(edict_t *self, edict_t *other, float kick, int damage)
{
int n;
@@ -543,19 +526,14 @@ void flyer_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
n = rand() % 3;
- if (n == 0)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (n == 0) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &flyer_move_pain1;
- }
- else if (n == 1)
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else if (n == 1) {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &flyer_move_pain2;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &flyer_move_pain3;
}
}
@@ -563,45 +541,43 @@ void flyer_pain (edict_t *self, edict_t *other, float kick, int damage)
void flyer_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
BecomeExplosion1(self);
}
-
+
/*QUAKED monster_flyer (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_flyer (edict_t *self)
+void SP_monster_flyer(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
// fix a map bug in jail5.bsp
- if (!Q_stricmp(level.mapname, "jail5") && (self->s.origin[2] == -104))
- {
+ if (!Q_stricmp(level.mapname, "jail5") && (self->s.origin[2] == -104)) {
self->targetname = self->target;
self->target = NULL;
}
- sound_sight = gi.soundindex ("flyer/flysght1.wav");
- sound_idle = gi.soundindex ("flyer/flysrch1.wav");
- sound_pain1 = gi.soundindex ("flyer/flypain1.wav");
- sound_pain2 = gi.soundindex ("flyer/flypain2.wav");
- sound_slash = gi.soundindex ("flyer/flyatck2.wav");
- sound_sproing = gi.soundindex ("flyer/flyatck1.wav");
- sound_die = gi.soundindex ("flyer/flydeth1.wav");
+ sound_sight = gi.soundindex("flyer/flysght1.wav");
+ sound_idle = gi.soundindex("flyer/flysrch1.wav");
+ sound_pain1 = gi.soundindex("flyer/flypain1.wav");
+ sound_pain2 = gi.soundindex("flyer/flypain2.wav");
+ sound_slash = gi.soundindex("flyer/flyatck2.wav");
+ sound_sproing = gi.soundindex("flyer/flyatck1.wav");
+ sound_die = gi.soundindex("flyer/flydeth1.wav");
- gi.soundindex ("flyer/flyatck3.wav");
+ gi.soundindex("flyer/flyatck3.wav");
- self->s.modelindex = gi.modelindex ("models/monsters/flyer/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/flyer/tris.md2");
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.sound = gi.soundindex ("flyer/flyidle1.wav");
+ self->s.sound = gi.soundindex("flyer/flyidle1.wav");
self->health = 50;
self->mass = 50;
@@ -617,10 +593,10 @@ void SP_monster_flyer (edict_t *self)
self->monsterinfo.sight = flyer_sight;
self->monsterinfo.idle = flyer_idle;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &flyer_move_stand;
+ self->monsterinfo.currentmove = &flyer_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- flymonster_start (self);
+ flymonster_start(self);
}
diff --git a/src/baseq2/m_flyer.h b/src/baseq2/m_flyer.h
index 3dc74fb..8e707ba 100644
--- a/src/baseq2/m_flyer.h
+++ b/src/baseq2/m_flyer.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_gladiator.c b/src/baseq2/m_gladiator.c
index 967cbe9..b0e6df8 100644
--- a/src/baseq2/m_gladiator.c
+++ b/src/baseq2/m_gladiator.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -41,28 +41,27 @@ static int sound_search;
static int sound_sight;
-void gladiator_idle (edict_t *self)
+void gladiator_idle(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
-void gladiator_sight (edict_t *self, edict_t *other)
+void gladiator_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void gladiator_search (edict_t *self)
+void gladiator_search(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
}
-void gladiator_cleaver_swing (edict_t *self)
+void gladiator_cleaver_swing(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_cleaver_swing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_cleaver_swing, 1, ATTN_NORM, 0);
}
-mframe_t gladiator_frames_stand [] =
-{
+mframe_t gladiator_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -73,14 +72,13 @@ mframe_t gladiator_frames_stand [] =
};
mmove_t gladiator_move_stand = {FRAME_stand1, FRAME_stand7, gladiator_frames_stand, NULL};
-void gladiator_stand (edict_t *self)
+void gladiator_stand(edict_t *self)
{
self->monsterinfo.currentmove = &gladiator_move_stand;
}
-mframe_t gladiator_frames_walk [] =
-{
+mframe_t gladiator_frames_walk [] = {
{ ai_walk, 15, NULL },
{ ai_walk, 7, NULL },
{ ai_walk, 6, NULL },
@@ -100,14 +98,13 @@ mframe_t gladiator_frames_walk [] =
};
mmove_t gladiator_move_walk = {FRAME_walk1, FRAME_walk16, gladiator_frames_walk, NULL};
-void gladiator_walk (edict_t *self)
+void gladiator_walk(edict_t *self)
{
self->monsterinfo.currentmove = &gladiator_move_walk;
}
-mframe_t gladiator_frames_run [] =
-{
+mframe_t gladiator_frames_run [] = {
{ ai_run, 23, NULL },
{ ai_run, 14, NULL },
{ ai_run, 14, NULL },
@@ -117,7 +114,7 @@ mframe_t gladiator_frames_run [] =
};
mmove_t gladiator_move_run = {FRAME_run1, FRAME_run6, gladiator_frames_run, NULL};
-void gladiator_run (edict_t *self)
+void gladiator_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &gladiator_move_stand;
@@ -126,19 +123,18 @@ void gladiator_run (edict_t *self)
}
-void GaldiatorMelee (edict_t *self)
+void GaldiatorMelee(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], -4);
- if (fire_hit (self, aim, (20 + (rand() %5)), 300))
- gi.sound (self, CHAN_AUTO, sound_cleaver_hit, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], -4);
+ if (fire_hit(self, aim, (20 + (rand() % 5)), 300))
+ gi.sound(self, CHAN_AUTO, sound_cleaver_hit, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_AUTO, sound_cleaver_miss, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_AUTO, sound_cleaver_miss, 1, ATTN_NORM, 0);
}
-mframe_t gladiator_frames_attack_melee [] =
-{
+mframe_t gladiator_frames_attack_melee [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -165,24 +161,23 @@ void gladiator_melee(edict_t *self)
}
-void GladiatorGun (edict_t *self)
+void GladiatorGun(edict_t *self)
{
vec3_t start;
vec3_t dir;
vec3_t forward, right;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_GLADIATOR_RAILGUN_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_GLADIATOR_RAILGUN_1], forward, right, start);
// calc direction to where we targted
- VectorSubtract (self->pos1, start, dir);
- VectorNormalize (dir);
+ VectorSubtract(self->pos1, start, dir);
+ VectorNormalize(dir);
- monster_fire_railgun (self, start, dir, 50, 100, MZ2_GLADIATOR_RAILGUN_1);
+ monster_fire_railgun(self, start, dir, 50, 100, MZ2_GLADIATOR_RAILGUN_1);
}
-mframe_t gladiator_frames_attack_gun [] =
-{
+mframe_t gladiator_frames_attack_gun [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -201,21 +196,20 @@ void gladiator_attack(edict_t *self)
vec3_t v;
// a small safe zone
- VectorSubtract (self->s.origin, self->enemy->s.origin, v);
+ VectorSubtract(self->s.origin, self->enemy->s.origin, v);
range = VectorLength(v);
if (range <= (MELEE_DISTANCE + 32))
return;
// charge up the railgun
- gi.sound (self, CHAN_WEAPON, sound_gun, 1, ATTN_NORM, 0);
- VectorCopy (self->enemy->s.origin, self->pos1); //save for aiming the shot
+ gi.sound(self, CHAN_WEAPON, sound_gun, 1, ATTN_NORM, 0);
+ VectorCopy(self->enemy->s.origin, self->pos1); //save for aiming the shot
self->pos1[2] += self->enemy->viewheight;
self->monsterinfo.currentmove = &gladiator_move_attack_gun;
}
-mframe_t gladiator_frames_pain [] =
-{
+mframe_t gladiator_frames_pain [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -225,8 +219,7 @@ mframe_t gladiator_frames_pain [] =
};
mmove_t gladiator_move_pain = {FRAME_pain1, FRAME_pain6, gladiator_frames_pain, gladiator_run};
-mframe_t gladiator_frames_pain_air [] =
-{
+mframe_t gladiator_frames_pain_air [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -237,14 +230,13 @@ mframe_t gladiator_frames_pain_air [] =
};
mmove_t gladiator_move_pain_air = {FRAME_painup1, FRAME_painup7, gladiator_frames_pain_air, gladiator_run};
-void gladiator_pain (edict_t *self, edict_t *other, float kick, int damage)
+void gladiator_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
- if (level.time < self->pain_debounce_time)
- {
+ if (level.time < self->pain_debounce_time) {
if ((self->velocity[2] > 100) && (self->monsterinfo.currentmove == &gladiator_move_pain))
self->monsterinfo.currentmove = &gladiator_move_pain_air;
return;
@@ -253,9 +245,9 @@ void gladiator_pain (edict_t *self, edict_t *other, float kick, int damage)
self->pain_debounce_time = level.time + 3;
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
@@ -264,22 +256,21 @@ void gladiator_pain (edict_t *self, edict_t *other, float kick, int damage)
self->monsterinfo.currentmove = &gladiator_move_pain_air;
else
self->monsterinfo.currentmove = &gladiator_move_pain;
-
+
}
-void gladiator_dead (edict_t *self)
+void gladiator_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t gladiator_frames_death [] =
-{
+mframe_t gladiator_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -305,19 +296,18 @@ mframe_t gladiator_frames_death [] =
};
mmove_t gladiator_move_death = {FRAME_death1, FRAME_death22, gladiator_frames_death, gladiator_dead};
-void gladiator_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void gladiator_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -326,7 +316,7 @@ void gladiator_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int da
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
@@ -336,31 +326,30 @@ void gladiator_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int da
/*QUAKED monster_gladiator (1 .5 0) (-32 -32 -24) (32 32 64) Ambush Trigger_Spawn Sight
*/
-void SP_monster_gladiator (edict_t *self)
+void SP_monster_gladiator(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("gladiator/pain.wav");
- sound_pain2 = gi.soundindex ("gladiator/gldpain2.wav");
- sound_die = gi.soundindex ("gladiator/glddeth2.wav");
- sound_gun = gi.soundindex ("gladiator/railgun.wav");
- sound_cleaver_swing = gi.soundindex ("gladiator/melee1.wav");
- sound_cleaver_hit = gi.soundindex ("gladiator/melee2.wav");
- sound_cleaver_miss = gi.soundindex ("gladiator/melee3.wav");
- sound_idle = gi.soundindex ("gladiator/gldidle1.wav");
- sound_search = gi.soundindex ("gladiator/gldsrch1.wav");
- sound_sight = gi.soundindex ("gladiator/sight.wav");
+ sound_pain1 = gi.soundindex("gladiator/pain.wav");
+ sound_pain2 = gi.soundindex("gladiator/gldpain2.wav");
+ sound_die = gi.soundindex("gladiator/glddeth2.wav");
+ sound_gun = gi.soundindex("gladiator/railgun.wav");
+ sound_cleaver_swing = gi.soundindex("gladiator/melee1.wav");
+ sound_cleaver_hit = gi.soundindex("gladiator/melee2.wav");
+ sound_cleaver_miss = gi.soundindex("gladiator/melee3.wav");
+ sound_idle = gi.soundindex("gladiator/gldidle1.wav");
+ sound_search = gi.soundindex("gladiator/gldsrch1.wav");
+ sound_sight = gi.soundindex("gladiator/sight.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/gladiatr/tris.md2");
- VectorSet (self->mins, -32, -32, -24);
- VectorSet (self->maxs, 32, 32, 64);
+ self->s.modelindex = gi.modelindex("models/monsters/gladiatr/tris.md2");
+ VectorSet(self->mins, -32, -32, -24);
+ VectorSet(self->maxs, 32, 32, 64);
self->health = 400;
self->gib_health = -175;
@@ -379,9 +368,9 @@ void SP_monster_gladiator (edict_t *self)
self->monsterinfo.idle = gladiator_idle;
self->monsterinfo.search = gladiator_search;
- gi.linkentity (self);
+ gi.linkentity(self);
self->monsterinfo.currentmove = &gladiator_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_gladiator.h b/src/baseq2/m_gladiator.h
index aae6d4c..015afeb 100644
--- a/src/baseq2/m_gladiator.h
+++ b/src/baseq2/m_gladiator.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_gunner.c b/src/baseq2/m_gunner.c
index 88f77d9..ef9a657 100644
--- a/src/baseq2/m_gunner.c
+++ b/src/baseq2/m_gunner.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -38,33 +38,32 @@ static int sound_search;
static int sound_sight;
-void gunner_idlesound (edict_t *self)
+void gunner_idlesound(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
-void gunner_sight (edict_t *self, edict_t *other)
+void gunner_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void gunner_search (edict_t *self)
+void gunner_search(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
}
-qboolean visible (edict_t *self, edict_t *other);
-void GunnerGrenade (edict_t *self);
-void GunnerFire (edict_t *self);
+qboolean visible(edict_t *self, edict_t *other);
+void GunnerGrenade(edict_t *self);
+void GunnerFire(edict_t *self);
void gunner_fire_chain(edict_t *self);
void gunner_refire_chain(edict_t *self);
-void gunner_stand (edict_t *self);
+void gunner_stand(edict_t *self);
-mframe_t gunner_frames_fidget [] =
-{
+mframe_t gunner_frames_fidget [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -121,7 +120,7 @@ mframe_t gunner_frames_fidget [] =
};
mmove_t gunner_move_fidget = {FRAME_stand31, FRAME_stand70, gunner_frames_fidget, gunner_stand};
-void gunner_fidget (edict_t *self)
+void gunner_fidget(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
return;
@@ -129,8 +128,7 @@ void gunner_fidget (edict_t *self)
self->monsterinfo.currentmove = &gunner_move_fidget;
}
-mframe_t gunner_frames_stand [] =
-{
+mframe_t gunner_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -166,14 +164,13 @@ mframe_t gunner_frames_stand [] =
};
mmove_t gunner_move_stand = {FRAME_stand01, FRAME_stand30, gunner_frames_stand, NULL};
-void gunner_stand (edict_t *self)
+void gunner_stand(edict_t *self)
{
- self->monsterinfo.currentmove = &gunner_move_stand;
+ self->monsterinfo.currentmove = &gunner_move_stand;
}
-mframe_t gunner_frames_walk [] =
-{
+mframe_t gunner_frames_walk [] = {
{ ai_walk, 0, NULL },
{ ai_walk, 3, NULL },
{ ai_walk, 4, NULL },
@@ -190,13 +187,12 @@ mframe_t gunner_frames_walk [] =
};
mmove_t gunner_move_walk = {FRAME_walk07, FRAME_walk19, gunner_frames_walk, NULL};
-void gunner_walk (edict_t *self)
+void gunner_walk(edict_t *self)
{
self->monsterinfo.currentmove = &gunner_move_walk;
}
-mframe_t gunner_frames_run [] =
-{
+mframe_t gunner_frames_run [] = {
{ ai_run, 26, NULL },
{ ai_run, 9, NULL },
{ ai_run, 9, NULL },
@@ -209,7 +205,7 @@ mframe_t gunner_frames_run [] =
mmove_t gunner_move_run = {FRAME_run01, FRAME_run08, gunner_frames_run, NULL};
-void gunner_run (edict_t *self)
+void gunner_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &gunner_move_stand;
@@ -217,8 +213,7 @@ void gunner_run (edict_t *self)
self->monsterinfo.currentmove = &gunner_move_run;
}
-mframe_t gunner_frames_runandshoot [] =
-{
+mframe_t gunner_frames_runandshoot [] = {
{ ai_run, 32, NULL },
{ ai_run, 15, NULL },
{ ai_run, 10, NULL },
@@ -229,13 +224,12 @@ mframe_t gunner_frames_runandshoot [] =
mmove_t gunner_move_runandshoot = {FRAME_runs01, FRAME_runs06, gunner_frames_runandshoot, NULL};
-void gunner_runandshoot (edict_t *self)
+void gunner_runandshoot(edict_t *self)
{
self->monsterinfo.currentmove = &gunner_move_runandshoot;
}
-mframe_t gunner_frames_pain3 [] =
-{
+mframe_t gunner_frames_pain3 [] = {
{ ai_move, -3, NULL },
{ ai_move, 1, NULL },
{ ai_move, 1, NULL },
@@ -244,8 +238,7 @@ mframe_t gunner_frames_pain3 [] =
};
mmove_t gunner_move_pain3 = {FRAME_pain301, FRAME_pain305, gunner_frames_pain3, gunner_run};
-mframe_t gunner_frames_pain2 [] =
-{
+mframe_t gunner_frames_pain2 [] = {
{ ai_move, -2, NULL },
{ ai_move, 11, NULL },
{ ai_move, 6, NULL },
@@ -257,8 +250,7 @@ mframe_t gunner_frames_pain2 [] =
};
mmove_t gunner_move_pain2 = {FRAME_pain201, FRAME_pain208, gunner_frames_pain2, gunner_run};
-mframe_t gunner_frames_pain1 [] =
-{
+mframe_t gunner_frames_pain1 [] = {
{ ai_move, 2, NULL },
{ ai_move, 0, NULL },
{ ai_move, -5, NULL },
@@ -280,7 +272,7 @@ mframe_t gunner_frames_pain1 [] =
};
mmove_t gunner_move_pain1 = {FRAME_pain101, FRAME_pain118, gunner_frames_pain1, gunner_run};
-void gunner_pain (edict_t *self, edict_t *other, float kick, int damage)
+void gunner_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -290,10 +282,10 @@ void gunner_pain (edict_t *self, edict_t *other, float kick, int damage)
self->pain_debounce_time = level.time + 3;
- if (rand()&1)
- gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
+ if (rand() & 1)
+ gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
@@ -306,18 +298,17 @@ void gunner_pain (edict_t *self, edict_t *other, float kick, int damage)
self->monsterinfo.currentmove = &gunner_move_pain1;
}
-void gunner_dead (edict_t *self)
+void gunner_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t gunner_frames_death [] =
-{
+mframe_t gunner_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -332,19 +323,18 @@ mframe_t gunner_frames_death [] =
};
mmove_t gunner_move_death = {FRAME_death01, FRAME_death11, gunner_frames_death, gunner_dead};
-void gunner_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void gunner_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -353,31 +343,30 @@ void gunner_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->monsterinfo.currentmove = &gunner_move_death;
}
-void gunner_duck_down (edict_t *self)
+void gunner_duck_down(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
self->monsterinfo.aiflags |= AI_DUCKED;
- if (skill->value >= 2)
- {
+ if (skill->value >= 2) {
if (random() > 0.5)
- GunnerGrenade (self);
+ GunnerGrenade(self);
}
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
self->monsterinfo.pausetime = level.time + 1;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void gunner_duck_hold (edict_t *self)
+void gunner_duck_hold(edict_t *self)
{
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -385,16 +374,15 @@ void gunner_duck_hold (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-void gunner_duck_up (edict_t *self)
+void gunner_duck_up(edict_t *self)
{
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t gunner_frames_duck [] =
-{
+mframe_t gunner_frames_duck [] = {
{ ai_move, 1, gunner_duck_down },
{ ai_move, 1, NULL },
{ ai_move, 1, gunner_duck_hold },
@@ -406,7 +394,7 @@ mframe_t gunner_frames_duck [] =
};
mmove_t gunner_move_duck = {FRAME_duck01, FRAME_duck08, gunner_frames_duck, gunner_run};
-void gunner_dodge (edict_t *self, edict_t *attacker, float eta)
+void gunner_dodge(edict_t *self, edict_t *attacker, float eta)
{
if (random() > 0.25)
return;
@@ -418,12 +406,12 @@ void gunner_dodge (edict_t *self, edict_t *attacker, float eta)
}
-void gunner_opengun (edict_t *self)
+void gunner_opengun(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_open, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_open, 1, ATTN_IDLE, 0);
}
-void GunnerFire (edict_t *self)
+void GunnerFire(edict_t *self)
{
vec3_t start;
vec3_t forward, right;
@@ -433,20 +421,20 @@ void GunnerFire (edict_t *self)
flash_number = MZ2_GUNNER_MACHINEGUN_1 + (self->s.frame - FRAME_attak216);
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
// project enemy back a bit and target there
- VectorCopy (self->enemy->s.origin, target);
- VectorMA (target, -0.2, self->enemy->velocity, target);
+ VectorCopy(self->enemy->s.origin, target);
+ VectorMA(target, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, aim);
- VectorNormalize (aim);
- monster_fire_bullet (self, start, aim, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
+ VectorSubtract(target, start, aim);
+ VectorNormalize(aim);
+ monster_fire_bullet(self, start, aim, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
}
-void GunnerGrenade (edict_t *self)
+void GunnerGrenade(edict_t *self)
{
vec3_t start;
vec3_t forward, right;
@@ -462,17 +450,16 @@ void GunnerGrenade (edict_t *self)
else // (self->s.frame == FRAME_attak114)
flash_number = MZ2_GUNNER_GRENADE_4;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
//FIXME : do a spread -225 -75 75 225 degrees around forward
- VectorCopy (forward, aim);
+ VectorCopy(forward, aim);
- monster_fire_grenade (self, start, aim, 50, 600, flash_number);
+ monster_fire_grenade(self, start, aim, 50, 600, flash_number);
}
-mframe_t gunner_frames_attack_chain [] =
-{
+mframe_t gunner_frames_attack_chain [] = {
/*
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -493,8 +480,7 @@ mframe_t gunner_frames_attack_chain [] =
};
mmove_t gunner_move_attack_chain = {FRAME_attak209, FRAME_attak215, gunner_frames_attack_chain, gunner_fire_chain};
-mframe_t gunner_frames_fire_chain [] =
-{
+mframe_t gunner_frames_fire_chain [] = {
{ ai_charge, 0, GunnerFire },
{ ai_charge, 0, GunnerFire },
{ ai_charge, 0, GunnerFire },
@@ -506,8 +492,7 @@ mframe_t gunner_frames_fire_chain [] =
};
mmove_t gunner_move_fire_chain = {FRAME_attak216, FRAME_attak223, gunner_frames_fire_chain, gunner_refire_chain};
-mframe_t gunner_frames_endfire_chain [] =
-{
+mframe_t gunner_frames_endfire_chain [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -518,8 +503,7 @@ mframe_t gunner_frames_endfire_chain [] =
};
mmove_t gunner_move_endfire_chain = {FRAME_attak224, FRAME_attak230, gunner_frames_endfire_chain, gunner_run};
-mframe_t gunner_frames_attack_grenade [] =
-{
+mframe_t gunner_frames_attack_grenade [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -546,12 +530,9 @@ mmove_t gunner_move_attack_grenade = {FRAME_attak101, FRAME_attak121, gunner_fra
void gunner_attack(edict_t *self)
{
- if (range (self, self->enemy) == RANGE_MELEE)
- {
+ if (range(self, self->enemy) == RANGE_MELEE) {
self->monsterinfo.currentmove = &gunner_move_attack_chain;
- }
- else
- {
+ } else {
if (random() <= 0.5)
self->monsterinfo.currentmove = &gunner_move_attack_grenade;
else
@@ -567,9 +548,8 @@ void gunner_fire_chain(edict_t *self)
void gunner_refire_chain(edict_t *self)
{
if (self->enemy->health > 0)
- if ( visible (self, self->enemy) )
- if (random() <= 0.5)
- {
+ if (visible(self, self->enemy))
+ if (random() <= 0.5) {
self->monsterinfo.currentmove = &gunner_move_fire_chain;
return;
}
@@ -578,30 +558,29 @@ void gunner_refire_chain(edict_t *self)
/*QUAKED monster_gunner (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_gunner (edict_t *self)
+void SP_monster_gunner(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_death = gi.soundindex ("gunner/death1.wav");
- sound_pain = gi.soundindex ("gunner/gunpain2.wav");
- sound_pain2 = gi.soundindex ("gunner/gunpain1.wav");
- sound_idle = gi.soundindex ("gunner/gunidle1.wav");
- sound_open = gi.soundindex ("gunner/gunatck1.wav");
- sound_search = gi.soundindex ("gunner/gunsrch1.wav");
- sound_sight = gi.soundindex ("gunner/sight1.wav");
+ sound_death = gi.soundindex("gunner/death1.wav");
+ sound_pain = gi.soundindex("gunner/gunpain2.wav");
+ sound_pain2 = gi.soundindex("gunner/gunpain1.wav");
+ sound_idle = gi.soundindex("gunner/gunidle1.wav");
+ sound_open = gi.soundindex("gunner/gunatck1.wav");
+ sound_search = gi.soundindex("gunner/gunsrch1.wav");
+ sound_sight = gi.soundindex("gunner/sight1.wav");
- gi.soundindex ("gunner/gunatck2.wav");
- gi.soundindex ("gunner/gunatck3.wav");
+ gi.soundindex("gunner/gunatck2.wav");
+ gi.soundindex("gunner/gunatck3.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/gunner/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/gunner/tris.md2");
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 175;
self->gib_health = -70;
@@ -619,10 +598,10 @@ void SP_monster_gunner (edict_t *self)
self->monsterinfo.sight = gunner_sight;
self->monsterinfo.search = gunner_search;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &gunner_move_stand;
+ self->monsterinfo.currentmove = &gunner_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_gunner.h b/src/baseq2/m_gunner.h
index d9b42f8..3c8bee2 100644
--- a/src/baseq2/m_gunner.h
+++ b/src/baseq2/m_gunner.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_hover.c b/src/baseq2/m_hover.c
index 395d0dc..07eb07c 100644
--- a/src/baseq2/m_hover.c
+++ b/src/baseq2/m_hover.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ hover
#include "g_local.h"
#include "m_hover.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
static int sound_pain1;
@@ -40,30 +40,29 @@ static int sound_search1;
static int sound_search2;
-void hover_sight (edict_t *self, edict_t *other)
+void hover_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void hover_search (edict_t *self)
+void hover_search(edict_t *self)
{
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
}
-void hover_run (edict_t *self);
-void hover_stand (edict_t *self);
-void hover_dead (edict_t *self);
-void hover_attack (edict_t *self);
-void hover_reattack (edict_t *self);
-void hover_fire_blaster (edict_t *self);
-void hover_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
+void hover_run(edict_t *self);
+void hover_stand(edict_t *self);
+void hover_dead(edict_t *self);
+void hover_attack(edict_t *self);
+void hover_reattack(edict_t *self);
+void hover_fire_blaster(edict_t *self);
+void hover_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
-mframe_t hover_frames_stand [] =
-{
+mframe_t hover_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -97,8 +96,7 @@ mframe_t hover_frames_stand [] =
};
mmove_t hover_move_stand = {FRAME_stand01, FRAME_stand30, hover_frames_stand, NULL};
-mframe_t hover_frames_stop1 [] =
-{
+mframe_t hover_frames_stop1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -111,8 +109,7 @@ mframe_t hover_frames_stop1 [] =
};
mmove_t hover_move_stop1 = {FRAME_stop101, FRAME_stop109, hover_frames_stop1, NULL};
-mframe_t hover_frames_stop2 [] =
-{
+mframe_t hover_frames_stop2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -124,8 +121,7 @@ mframe_t hover_frames_stop2 [] =
};
mmove_t hover_move_stop2 = {FRAME_stop201, FRAME_stop208, hover_frames_stop2, NULL};
-mframe_t hover_frames_takeoff [] =
-{
+mframe_t hover_frames_takeoff [] = {
{ ai_move, 0, NULL },
{ ai_move, -2, NULL },
{ ai_move, 5, NULL },
@@ -159,8 +155,7 @@ mframe_t hover_frames_takeoff [] =
};
mmove_t hover_move_takeoff = {FRAME_takeof01, FRAME_takeof30, hover_frames_takeoff, NULL};
-mframe_t hover_frames_pain3 [] =
-{
+mframe_t hover_frames_pain3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -173,8 +168,7 @@ mframe_t hover_frames_pain3 [] =
};
mmove_t hover_move_pain3 = {FRAME_pain301, FRAME_pain309, hover_frames_pain3, hover_run};
-mframe_t hover_frames_pain2 [] =
-{
+mframe_t hover_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -190,8 +184,7 @@ mframe_t hover_frames_pain2 [] =
};
mmove_t hover_move_pain2 = {FRAME_pain201, FRAME_pain212, hover_frames_pain2, hover_run};
-mframe_t hover_frames_pain1 [] =
-{
+mframe_t hover_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 2, NULL },
@@ -223,14 +216,12 @@ mframe_t hover_frames_pain1 [] =
};
mmove_t hover_move_pain1 = {FRAME_pain101, FRAME_pain128, hover_frames_pain1, hover_run};
-mframe_t hover_frames_land [] =
-{
+mframe_t hover_frames_land [] = {
{ ai_move, 0, NULL }
};
mmove_t hover_move_land = {FRAME_land01, FRAME_land01, hover_frames_land, NULL};
-mframe_t hover_frames_forward [] =
-{
+mframe_t hover_frames_forward [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -269,8 +260,7 @@ mframe_t hover_frames_forward [] =
};
mmove_t hover_move_forward = {FRAME_forwrd01, FRAME_forwrd35, hover_frames_forward, NULL};
-mframe_t hover_frames_walk [] =
-{
+mframe_t hover_frames_walk [] = {
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
@@ -309,8 +299,7 @@ mframe_t hover_frames_walk [] =
};
mmove_t hover_move_walk = {FRAME_forwrd01, FRAME_forwrd35, hover_frames_walk, NULL};
-mframe_t hover_frames_run [] =
-{
+mframe_t hover_frames_run [] = {
{ ai_run, 10, NULL },
{ ai_run, 10, NULL },
{ ai_run, 10, NULL },
@@ -349,15 +338,14 @@ mframe_t hover_frames_run [] =
};
mmove_t hover_move_run = {FRAME_forwrd01, FRAME_forwrd35, hover_frames_run, NULL};
-mframe_t hover_frames_death1 [] =
-{
+mframe_t hover_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
- { ai_move, -10,NULL },
+ { ai_move, -10, NULL },
{ ai_move, 3, NULL },
{ ai_move, 5, NULL },
{ ai_move, 4, NULL },
@@ -365,8 +353,7 @@ mframe_t hover_frames_death1 [] =
};
mmove_t hover_move_death1 = {FRAME_death101, FRAME_death111, hover_frames_death1, hover_dead};
-mframe_t hover_frames_backward [] =
-{
+mframe_t hover_frames_backward [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -394,16 +381,14 @@ mframe_t hover_frames_backward [] =
};
mmove_t hover_move_backward = {FRAME_backwd01, FRAME_backwd24, hover_frames_backward, NULL};
-mframe_t hover_frames_start_attack [] =
-{
+mframe_t hover_frames_start_attack [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL }
};
mmove_t hover_move_start_attack = {FRAME_attak101, FRAME_attak103, hover_frames_start_attack, hover_attack};
-mframe_t hover_frames_attack1 [] =
-{
+mframe_t hover_frames_attack1 [] = {
{ ai_charge, -10, hover_fire_blaster },
{ ai_charge, -10, hover_fire_blaster },
{ ai_charge, 0, hover_reattack },
@@ -411,19 +396,17 @@ mframe_t hover_frames_attack1 [] =
mmove_t hover_move_attack1 = {FRAME_attak104, FRAME_attak106, hover_frames_attack1, NULL};
-mframe_t hover_frames_end_attack [] =
-{
+mframe_t hover_frames_end_attack [] = {
{ ai_charge, 1, NULL },
{ ai_charge, 1, NULL }
};
mmove_t hover_move_end_attack = {FRAME_attak107, FRAME_attak108, hover_frames_end_attack, hover_run};
-void hover_reattack (edict_t *self)
+void hover_reattack(edict_t *self)
{
- if (self->enemy->health > 0 )
- if (visible (self, self->enemy) )
- if (random() <= 0.6)
- {
+ if (self->enemy->health > 0)
+ if (visible(self, self->enemy))
+ if (random() <= 0.6) {
self->monsterinfo.currentmove = &hover_move_attack1;
return;
}
@@ -431,7 +414,7 @@ void hover_reattack (edict_t *self)
}
-void hover_fire_blaster (edict_t *self)
+void hover_fire_blaster(edict_t *self)
{
vec3_t start;
vec3_t forward, right;
@@ -444,23 +427,23 @@ void hover_fire_blaster (edict_t *self)
else
effect = 0;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_HOVER_BLASTER_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_HOVER_BLASTER_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, dir);
+ VectorSubtract(end, start, dir);
- monster_fire_blaster (self, start, dir, 1, 1000, MZ2_HOVER_BLASTER_1, effect);
+ monster_fire_blaster(self, start, dir, 1, 1000, MZ2_HOVER_BLASTER_1, effect);
}
-void hover_stand (edict_t *self)
+void hover_stand(edict_t *self)
{
- self->monsterinfo.currentmove = &hover_move_stand;
+ self->monsterinfo.currentmove = &hover_move_stand;
}
-void hover_run (edict_t *self)
+void hover_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &hover_move_stand;
@@ -468,12 +451,12 @@ void hover_run (edict_t *self)
self->monsterinfo.currentmove = &hover_move_run;
}
-void hover_walk (edict_t *self)
+void hover_walk(edict_t *self)
{
self->monsterinfo.currentmove = &hover_move_walk;
}
-void hover_start_attack (edict_t *self)
+void hover_start_attack(edict_t *self)
{
self->monsterinfo.currentmove = &hover_move_start_attack;
}
@@ -484,7 +467,7 @@ void hover_attack(edict_t *self)
}
-void hover_pain (edict_t *self, edict_t *other, float kick, int damage)
+void hover_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -497,60 +480,52 @@ void hover_pain (edict_t *self, edict_t *other, float kick, int damage)
if (skill->value == 3)
return; // no pain anims in nightmare
- if (damage <= 25)
- {
- if (random() < 0.5)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (damage <= 25) {
+ if (random() < 0.5) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &hover_move_pain3;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &hover_move_pain2;
}
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &hover_move_pain1;
}
}
-void hover_deadthink (edict_t *self)
+void hover_deadthink(edict_t *self)
{
- if (!self->groundentity && level.time < self->timestamp)
- {
+ if (!self->groundentity && level.time < self->timestamp) {
self->nextthink = level.time + FRAMETIME;
return;
}
BecomeExplosion1(self);
}
-void hover_dead (edict_t *self)
+void hover_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->think = hover_deadthink;
self->nextthink = level.time + FRAMETIME;
self->timestamp = level.time + 15;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void hover_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void hover_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -560,9 +535,9 @@ void hover_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
// regular death
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_death2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death2, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->monsterinfo.currentmove = &hover_move_death1;
@@ -570,31 +545,30 @@ void hover_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
/*QUAKED monster_hover (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_hover (edict_t *self)
+void SP_monster_hover(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("hover/hovpain1.wav");
- sound_pain2 = gi.soundindex ("hover/hovpain2.wav");
- sound_death1 = gi.soundindex ("hover/hovdeth1.wav");
- sound_death2 = gi.soundindex ("hover/hovdeth2.wav");
- sound_sight = gi.soundindex ("hover/hovsght1.wav");
- sound_search1 = gi.soundindex ("hover/hovsrch1.wav");
- sound_search2 = gi.soundindex ("hover/hovsrch2.wav");
+ sound_pain1 = gi.soundindex("hover/hovpain1.wav");
+ sound_pain2 = gi.soundindex("hover/hovpain2.wav");
+ sound_death1 = gi.soundindex("hover/hovdeth1.wav");
+ sound_death2 = gi.soundindex("hover/hovdeth2.wav");
+ sound_sight = gi.soundindex("hover/hovsght1.wav");
+ sound_search1 = gi.soundindex("hover/hovsrch1.wav");
+ sound_search2 = gi.soundindex("hover/hovsrch2.wav");
- gi.soundindex ("hover/hovatck1.wav");
+ gi.soundindex("hover/hovatck1.wav");
- self->s.sound = gi.soundindex ("hover/hovidle1.wav");
+ self->s.sound = gi.soundindex("hover/hovidle1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
self->s.modelindex = gi.modelindex("models/monsters/hover/tris.md2");
- VectorSet (self->mins, -24, -24, -24);
- VectorSet (self->maxs, 24, 24, 32);
+ VectorSet(self->mins, -24, -24, -24);
+ VectorSet(self->maxs, 24, 24, 32);
self->health = 240;
self->gib_health = -100;
@@ -611,10 +585,10 @@ void SP_monster_hover (edict_t *self)
self->monsterinfo.sight = hover_sight;
self->monsterinfo.search = hover_search;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &hover_move_stand;
+ self->monsterinfo.currentmove = &hover_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- flymonster_start (self);
+ flymonster_start(self);
}
diff --git a/src/baseq2/m_hover.h b/src/baseq2/m_hover.h
index 4be397e..e0e3c3c 100644
--- a/src/baseq2/m_hover.h
+++ b/src/baseq2/m_hover.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_infantry.c b/src/baseq2/m_infantry.c
index c950c63..4fe1a31 100644
--- a/src/baseq2/m_infantry.c
+++ b/src/baseq2/m_infantry.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ INFANTRY
#include "g_local.h"
#include "m_infantry.h"
-void InfantryMachineGun (edict_t *self);
+void InfantryMachineGun(edict_t *self);
static int sound_pain1;
@@ -45,8 +45,7 @@ static int sound_search;
static int sound_idle;
-mframe_t infantry_frames_stand [] =
-{
+mframe_t infantry_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -72,14 +71,13 @@ mframe_t infantry_frames_stand [] =
};
mmove_t infantry_move_stand = {FRAME_stand50, FRAME_stand71, infantry_frames_stand, NULL};
-void infantry_stand (edict_t *self)
+void infantry_stand(edict_t *self)
{
self->monsterinfo.currentmove = &infantry_move_stand;
}
-mframe_t infantry_frames_fidget [] =
-{
+mframe_t infantry_frames_fidget [] = {
{ ai_stand, 1, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 1, NULL },
@@ -132,14 +130,13 @@ mframe_t infantry_frames_fidget [] =
};
mmove_t infantry_move_fidget = {FRAME_stand01, FRAME_stand49, infantry_frames_fidget, infantry_stand};
-void infantry_fidget (edict_t *self)
+void infantry_fidget(edict_t *self)
{
self->monsterinfo.currentmove = &infantry_move_fidget;
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
-mframe_t infantry_frames_walk [] =
-{
+mframe_t infantry_frames_walk [] = {
{ ai_walk, 5, NULL },
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
@@ -155,13 +152,12 @@ mframe_t infantry_frames_walk [] =
};
mmove_t infantry_move_walk = {FRAME_walk03, FRAME_walk14, infantry_frames_walk, NULL};
-void infantry_walk (edict_t *self)
+void infantry_walk(edict_t *self)
{
self->monsterinfo.currentmove = &infantry_move_walk;
}
-mframe_t infantry_frames_run [] =
-{
+mframe_t infantry_frames_run [] = {
{ ai_run, 10, NULL },
{ ai_run, 20, NULL },
{ ai_run, 5, NULL },
@@ -173,7 +169,7 @@ mframe_t infantry_frames_run [] =
};
mmove_t infantry_move_run = {FRAME_run01, FRAME_run08, infantry_frames_run, NULL};
-void infantry_run (edict_t *self)
+void infantry_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &infantry_move_stand;
@@ -182,8 +178,7 @@ void infantry_run (edict_t *self)
}
-mframe_t infantry_frames_pain1 [] =
-{
+mframe_t infantry_frames_pain1 [] = {
{ ai_move, -3, NULL },
{ ai_move, -2, NULL },
{ ai_move, -1, NULL },
@@ -197,8 +192,7 @@ mframe_t infantry_frames_pain1 [] =
};
mmove_t infantry_move_pain1 = {FRAME_pain101, FRAME_pain110, infantry_frames_pain1, infantry_run};
-mframe_t infantry_frames_pain2 [] =
-{
+mframe_t infantry_frames_pain2 [] = {
{ ai_move, -3, NULL },
{ ai_move, -3, NULL },
{ ai_move, 0, NULL },
@@ -212,7 +206,7 @@ mframe_t infantry_frames_pain2 [] =
};
mmove_t infantry_move_pain2 = {FRAME_pain201, FRAME_pain210, infantry_frames_pain2, infantry_run};
-void infantry_pain (edict_t *self, edict_t *other, float kick, int damage)
+void infantry_pain(edict_t *self, edict_t *other, float kick, int damage)
{
int n;
@@ -223,26 +217,22 @@ void infantry_pain (edict_t *self, edict_t *other, float kick, int damage)
return;
self->pain_debounce_time = level.time + 3;
-
+
if (skill->value == 3)
return; // no pain anims in nightmare
n = rand() % 2;
- if (n == 0)
- {
+ if (n == 0) {
self->monsterinfo.currentmove = &infantry_move_pain1;
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
- }
- else
- {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
self->monsterinfo.currentmove = &infantry_move_pain2;
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
}
}
-vec3_t aimangles[] =
-{
+vec3_t aimangles[] = {
{ 0.0, 5.0, 0.0 },
{ 10.0, 15.0, 0.0 },
{ 20.0, 25.0, 0.0 },
@@ -257,63 +247,56 @@ vec3_t aimangles[] =
{ 90.0, 35.0, 0.0 }
};
-void InfantryMachineGun (edict_t *self)
+void InfantryMachineGun(edict_t *self)
{
vec3_t start, target;
vec3_t forward, right;
vec3_t vec;
int flash_number;
- if (self->s.frame == FRAME_attak111)
- {
+ if (self->s.frame == FRAME_attak111) {
flash_number = MZ2_INFANTRY_MACHINEGUN_1;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- if (self->enemy)
- {
- VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
+ if (self->enemy) {
+ VectorMA(self->enemy->s.origin, -0.2, self->enemy->velocity, target);
target[2] += self->enemy->viewheight;
- VectorSubtract (target, start, forward);
- VectorNormalize (forward);
+ VectorSubtract(target, start, forward);
+ VectorNormalize(forward);
+ } else {
+ AngleVectors(self->s.angles, forward, right, NULL);
}
- else
- {
- AngleVectors (self->s.angles, forward, right, NULL);
- }
- }
- else
- {
+ } else {
flash_number = MZ2_INFANTRY_MACHINEGUN_2 + (self->s.frame - FRAME_death211);
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- VectorSubtract (self->s.angles, aimangles[flash_number-MZ2_INFANTRY_MACHINEGUN_2], vec);
- AngleVectors (vec, forward, NULL, NULL);
+ VectorSubtract(self->s.angles, aimangles[flash_number - MZ2_INFANTRY_MACHINEGUN_2], vec);
+ AngleVectors(vec, forward, NULL, NULL);
}
- monster_fire_bullet (self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
+ monster_fire_bullet(self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
}
-void infantry_sight (edict_t *self, edict_t *other)
+void infantry_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_BODY, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, sound_sight, 1, ATTN_NORM, 0);
}
-void infantry_dead (edict_t *self)
+void infantry_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
- gi.linkentity (self);
+ gi.linkentity(self);
- M_FlyCheck (self);
+ M_FlyCheck(self);
}
-mframe_t infantry_frames_death1 [] =
-{
+mframe_t infantry_frames_death1 [] = {
{ ai_move, -4, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -338,8 +321,7 @@ mframe_t infantry_frames_death1 [] =
mmove_t infantry_move_death1 = {FRAME_death101, FRAME_death120, infantry_frames_death1, infantry_dead};
// Off with his head
-mframe_t infantry_frames_death2 [] =
-{
+mframe_t infantry_frames_death2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 1, NULL },
{ ai_move, 5, NULL },
@@ -368,8 +350,7 @@ mframe_t infantry_frames_death2 [] =
};
mmove_t infantry_move_death2 = {FRAME_death201, FRAME_death225, infantry_frames_death2, infantry_dead};
-mframe_t infantry_frames_death3 [] =
-{
+mframe_t infantry_frames_death3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -383,19 +364,18 @@ mframe_t infantry_frames_death3 [] =
mmove_t infantry_move_death3 = {FRAME_death301, FRAME_death309, infantry_frames_death3, infantry_dead};
-void infantry_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void infantry_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -408,25 +388,20 @@ void infantry_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dam
self->takedamage = DAMAGE_YES;
n = rand() % 3;
- if (n == 0)
- {
+ if (n == 0) {
self->monsterinfo.currentmove = &infantry_move_death1;
- gi.sound (self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
- }
- else if (n == 1)
- {
+ gi.sound(self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
+ } else if (n == 1) {
self->monsterinfo.currentmove = &infantry_move_death2;
- gi.sound (self, CHAN_VOICE, sound_die1, 1, ATTN_NORM, 0);
- }
- else
- {
+ gi.sound(self, CHAN_VOICE, sound_die1, 1, ATTN_NORM, 0);
+ } else {
self->monsterinfo.currentmove = &infantry_move_death3;
- gi.sound (self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
}
}
-void infantry_duck_down (edict_t *self)
+void infantry_duck_down(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
@@ -434,10 +409,10 @@ void infantry_duck_down (edict_t *self)
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
self->monsterinfo.pausetime = level.time + 1;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void infantry_duck_hold (edict_t *self)
+void infantry_duck_hold(edict_t *self)
{
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -445,16 +420,15 @@ void infantry_duck_hold (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-void infantry_duck_up (edict_t *self)
+void infantry_duck_up(edict_t *self)
{
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t infantry_frames_duck [] =
-{
+mframe_t infantry_frames_duck [] = {
{ ai_move, -2, infantry_duck_down },
{ ai_move, -5, infantry_duck_hold },
{ ai_move, 3, NULL },
@@ -463,7 +437,7 @@ mframe_t infantry_frames_duck [] =
};
mmove_t infantry_move_duck = {FRAME_duck01, FRAME_duck05, infantry_frames_duck, infantry_run};
-void infantry_dodge (edict_t *self, edict_t *attacker, float eta)
+void infantry_dodge(edict_t *self, edict_t *attacker, float eta)
{
if (random() > 0.25)
return;
@@ -475,18 +449,18 @@ void infantry_dodge (edict_t *self, edict_t *attacker, float eta)
}
-void infantry_cock_gun (edict_t *self)
+void infantry_cock_gun(edict_t *self)
{
int n;
- gi.sound (self, CHAN_WEAPON, sound_weapon_cock, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_weapon_cock, 1, ATTN_NORM, 0);
n = (rand() & 15) + 3 + 7;
self->monsterinfo.pausetime = level.time + n * FRAMETIME;
}
-void infantry_fire (edict_t *self)
+void infantry_fire(edict_t *self)
{
- InfantryMachineGun (self);
+ InfantryMachineGun(self);
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -494,8 +468,7 @@ void infantry_fire (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-mframe_t infantry_frames_attack1 [] =
-{
+mframe_t infantry_frames_attack1 [] = {
{ ai_charge, 4, NULL },
{ ai_charge, -1, NULL },
{ ai_charge, -1, NULL },
@@ -515,22 +488,21 @@ mframe_t infantry_frames_attack1 [] =
mmove_t infantry_move_attack1 = {FRAME_attak101, FRAME_attak115, infantry_frames_attack1, infantry_run};
-void infantry_swing (edict_t *self)
+void infantry_swing(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_punch_swing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_punch_swing, 1, ATTN_NORM, 0);
}
-void infantry_smack (edict_t *self)
+void infantry_smack(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, 0, 0);
- if (fire_hit (self, aim, (5 + (rand() % 5)), 50))
- gi.sound (self, CHAN_WEAPON, sound_punch_hit, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, 0, 0);
+ if (fire_hit(self, aim, (5 + (rand() % 5)), 50))
+ gi.sound(self, CHAN_WEAPON, sound_punch_hit, 1, ATTN_NORM, 0);
}
-mframe_t infantry_frames_attack2 [] =
-{
+mframe_t infantry_frames_attack2 [] = {
{ ai_charge, 3, NULL },
{ ai_charge, 6, NULL },
{ ai_charge, 0, infantry_swing },
@@ -544,7 +516,7 @@ mmove_t infantry_move_attack2 = {FRAME_attak201, FRAME_attak208, infantry_frames
void infantry_attack(edict_t *self)
{
- if (range (self, self->enemy) == RANGE_MELEE)
+ if (range(self, self->enemy) == RANGE_MELEE)
self->monsterinfo.currentmove = &infantry_move_attack2;
else
self->monsterinfo.currentmove = &infantry_move_attack1;
@@ -553,34 +525,33 @@ void infantry_attack(edict_t *self)
/*QUAKED monster_infantry (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_infantry (edict_t *self)
+void SP_monster_infantry(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("infantry/infpain1.wav");
- sound_pain2 = gi.soundindex ("infantry/infpain2.wav");
- sound_die1 = gi.soundindex ("infantry/infdeth1.wav");
- sound_die2 = gi.soundindex ("infantry/infdeth2.wav");
-
- sound_gunshot = gi.soundindex ("infantry/infatck1.wav");
- sound_weapon_cock = gi.soundindex ("infantry/infatck3.wav");
- sound_punch_swing = gi.soundindex ("infantry/infatck2.wav");
- sound_punch_hit = gi.soundindex ("infantry/melee2.wav");
-
- sound_sight = gi.soundindex ("infantry/infsght1.wav");
- sound_search = gi.soundindex ("infantry/infsrch1.wav");
- sound_idle = gi.soundindex ("infantry/infidle1.wav");
-
+ sound_pain1 = gi.soundindex("infantry/infpain1.wav");
+ sound_pain2 = gi.soundindex("infantry/infpain2.wav");
+ sound_die1 = gi.soundindex("infantry/infdeth1.wav");
+ sound_die2 = gi.soundindex("infantry/infdeth2.wav");
+
+ sound_gunshot = gi.soundindex("infantry/infatck1.wav");
+ sound_weapon_cock = gi.soundindex("infantry/infatck3.wav");
+ sound_punch_swing = gi.soundindex("infantry/infatck2.wav");
+ sound_punch_hit = gi.soundindex("infantry/melee2.wav");
+
+ sound_sight = gi.soundindex("infantry/infsght1.wav");
+ sound_search = gi.soundindex("infantry/infsrch1.wav");
+ sound_idle = gi.soundindex("infantry/infidle1.wav");
+
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
self->s.modelindex = gi.modelindex("models/monsters/infantry/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 100;
self->gib_health = -40;
@@ -598,10 +569,10 @@ void SP_monster_infantry (edict_t *self)
self->monsterinfo.sight = infantry_sight;
self->monsterinfo.idle = infantry_fidget;
- gi.linkentity (self);
+ gi.linkentity(self);
self->monsterinfo.currentmove = &infantry_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_infantry.h b/src/baseq2/m_infantry.h
index 3424439..b9fa078 100644
--- a/src/baseq2/m_infantry.h
+++ b/src/baseq2/m_infantry.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_insane.c b/src/baseq2/m_insane.c
index d2fc082..f7c1b8f 100644
--- a/src/baseq2/m_insane.c
+++ b/src/baseq2/m_insane.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,39 +34,38 @@ static int sound_shake;
static int sound_moan;
static int sound_scream[8];
-void insane_fist (edict_t *self)
+void insane_fist(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_fist, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_fist, 1, ATTN_IDLE, 0);
}
-void insane_shake (edict_t *self)
+void insane_shake(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_shake, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_shake, 1, ATTN_IDLE, 0);
}
-void insane_moan (edict_t *self)
+void insane_moan(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_moan, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_moan, 1, ATTN_IDLE, 0);
}
-void insane_scream (edict_t *self)
+void insane_scream(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_scream[rand()%8], 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_scream[rand() % 8], 1, ATTN_IDLE, 0);
}
-void insane_stand (edict_t *self);
-void insane_dead (edict_t *self);
-void insane_cross (edict_t *self);
-void insane_walk (edict_t *self);
-void insane_run (edict_t *self);
-void insane_checkdown (edict_t *self);
-void insane_checkup (edict_t *self);
-void insane_onground (edict_t *self);
+void insane_stand(edict_t *self);
+void insane_dead(edict_t *self);
+void insane_cross(edict_t *self);
+void insane_walk(edict_t *self);
+void insane_run(edict_t *self);
+void insane_checkdown(edict_t *self);
+void insane_checkup(edict_t *self);
+void insane_onground(edict_t *self);
-mframe_t insane_frames_stand_normal [] =
-{
+mframe_t insane_frames_stand_normal [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -76,8 +75,7 @@ mframe_t insane_frames_stand_normal [] =
};
mmove_t insane_move_stand_normal = {FRAME_stand60, FRAME_stand65, insane_frames_stand_normal, insane_stand};
-mframe_t insane_frames_stand_insane [] =
-{
+mframe_t insane_frames_stand_insane [] = {
{ ai_stand, 0, insane_shake },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -111,8 +109,7 @@ mframe_t insane_frames_stand_insane [] =
};
mmove_t insane_move_stand_insane = {FRAME_stand65, FRAME_stand94, insane_frames_stand_insane, insane_stand};
-mframe_t insane_frames_uptodown [] =
-{
+mframe_t insane_frames_uptodown [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -160,8 +157,7 @@ mframe_t insane_frames_uptodown [] =
mmove_t insane_move_uptodown = {FRAME_stand1, FRAME_stand40, insane_frames_uptodown, insane_onground};
-mframe_t insane_frames_downtoup [] =
-{
+mframe_t insane_frames_downtoup [] = {
{ ai_move, -0.7, NULL }, // 41
{ ai_move, -1.2, NULL }, // 42
{ ai_move, -1.5, NULL }, // 43
@@ -184,8 +180,7 @@ mframe_t insane_frames_downtoup [] =
};
mmove_t insane_move_downtoup = {FRAME_stand41, FRAME_stand59, insane_frames_downtoup, insane_stand};
-mframe_t insane_frames_jumpdown [] =
-{
+mframe_t insane_frames_jumpdown [] = {
{ ai_move, 0.2, NULL },
{ ai_move, 11.5, NULL },
{ ai_move, 5.1, NULL },
@@ -195,8 +190,7 @@ mframe_t insane_frames_jumpdown [] =
mmove_t insane_move_jumpdown = {FRAME_stand96, FRAME_stand100, insane_frames_jumpdown, insane_onground};
-mframe_t insane_frames_down [] =
-{
+mframe_t insane_frames_down [] = {
{ ai_move, 0, NULL }, // 100
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -261,8 +255,7 @@ mframe_t insane_frames_down [] =
};
mmove_t insane_move_down = {FRAME_stand100, FRAME_stand160, insane_frames_down, insane_onground};
-mframe_t insane_frames_walk_normal [] =
-{
+mframe_t insane_frames_walk_normal [] = {
{ ai_walk, 0, insane_scream },
{ ai_walk, 2.5, NULL },
{ ai_walk, 3.5, NULL },
@@ -280,8 +273,7 @@ mframe_t insane_frames_walk_normal [] =
mmove_t insane_move_walk_normal = {FRAME_walk27, FRAME_walk39, insane_frames_walk_normal, insane_walk};
mmove_t insane_move_run_normal = {FRAME_walk27, FRAME_walk39, insane_frames_walk_normal, insane_run};
-mframe_t insane_frames_walk_insane [] =
-{
+mframe_t insane_frames_walk_insane [] = {
{ ai_walk, 0, insane_scream }, // walk 1
{ ai_walk, 3.4, NULL }, // walk 2
{ ai_walk, 3.6, NULL }, // 3
@@ -312,8 +304,7 @@ mframe_t insane_frames_walk_insane [] =
mmove_t insane_move_walk_insane = {FRAME_walk1, FRAME_walk26, insane_frames_walk_insane, insane_walk};
mmove_t insane_move_run_insane = {FRAME_walk1, FRAME_walk26, insane_frames_walk_insane, insane_run};
-mframe_t insane_frames_stand_pain [] =
-{
+mframe_t insane_frames_stand_pain [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -328,8 +319,7 @@ mframe_t insane_frames_stand_pain [] =
};
mmove_t insane_move_stand_pain = {FRAME_st_pain2, FRAME_st_pain12, insane_frames_stand_pain, insane_run};
-mframe_t insane_frames_stand_death [] =
-{
+mframe_t insane_frames_stand_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -350,8 +340,7 @@ mframe_t insane_frames_stand_death [] =
};
mmove_t insane_move_stand_death = {FRAME_st_death2, FRAME_st_death18, insane_frames_stand_death, insane_dead};
-mframe_t insane_frames_crawl [] =
-{
+mframe_t insane_frames_crawl [] = {
{ ai_walk, 0, insane_scream },
{ ai_walk, 1.5, NULL },
{ ai_walk, 2.1, NULL },
@@ -365,8 +354,7 @@ mframe_t insane_frames_crawl [] =
mmove_t insane_move_crawl = {FRAME_crawl1, FRAME_crawl9, insane_frames_crawl, NULL};
mmove_t insane_move_runcrawl = {FRAME_crawl1, FRAME_crawl9, insane_frames_crawl, NULL};
-mframe_t insane_frames_crawl_pain [] =
-{
+mframe_t insane_frames_crawl_pain [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -379,8 +367,7 @@ mframe_t insane_frames_crawl_pain [] =
};
mmove_t insane_move_crawl_pain = {FRAME_cr_pain2, FRAME_cr_pain10, insane_frames_crawl_pain, insane_run};
-mframe_t insane_frames_crawl_death [] =
-{
+mframe_t insane_frames_crawl_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -391,8 +378,7 @@ mframe_t insane_frames_crawl_death [] =
};
mmove_t insane_move_crawl_death = {FRAME_cr_death10, FRAME_cr_death16, insane_frames_crawl_death, insane_dead};
-mframe_t insane_frames_cross [] =
-{
+mframe_t insane_frames_cross [] = {
{ ai_move, 0, insane_moan },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -411,8 +397,7 @@ mframe_t insane_frames_cross [] =
};
mmove_t insane_move_cross = {FRAME_cross1, FRAME_cross15, insane_frames_cross, insane_cross};
-mframe_t insane_frames_struggle_cross [] =
-{
+mframe_t insane_frames_struggle_cross [] = {
{ ai_move, 0, insane_scream },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -431,52 +416,48 @@ mframe_t insane_frames_struggle_cross [] =
};
mmove_t insane_move_struggle_cross = {FRAME_cross16, FRAME_cross30, insane_frames_struggle_cross, insane_cross};
-void insane_cross (edict_t *self)
+void insane_cross(edict_t *self)
{
- if (random() < 0.8)
+ if (random() < 0.8)
self->monsterinfo.currentmove = &insane_move_cross;
else
self->monsterinfo.currentmove = &insane_move_struggle_cross;
}
-void insane_walk (edict_t *self)
+void insane_walk(edict_t *self)
{
- if ( self->spawnflags & 16 ) // Hold Ground?
- if (self->s.frame == FRAME_cr_pain10)
- {
+ if (self->spawnflags & 16) // Hold Ground?
+ if (self->s.frame == FRAME_cr_pain10) {
self->monsterinfo.currentmove = &insane_move_down;
return;
}
if (self->spawnflags & 4)
self->monsterinfo.currentmove = &insane_move_crawl;
+ else if (random() <= 0.5)
+ self->monsterinfo.currentmove = &insane_move_walk_normal;
else
- if (random() <= 0.5)
- self->monsterinfo.currentmove = &insane_move_walk_normal;
- else
- self->monsterinfo.currentmove = &insane_move_walk_insane;
+ self->monsterinfo.currentmove = &insane_move_walk_insane;
}
-void insane_run (edict_t *self)
+void insane_run(edict_t *self)
{
- if ( self->spawnflags & 16 ) // Hold Ground?
- if (self->s.frame == FRAME_cr_pain10)
- {
+ if (self->spawnflags & 16) // Hold Ground?
+ if (self->s.frame == FRAME_cr_pain10) {
self->monsterinfo.currentmove = &insane_move_down;
return;
}
if (self->spawnflags & 4) // Crawling?
self->monsterinfo.currentmove = &insane_move_runcrawl;
+ else if (random() <= 0.5) // Else, mix it up
+ self->monsterinfo.currentmove = &insane_move_run_normal;
else
- if (random() <= 0.5) // Else, mix it up
- self->monsterinfo.currentmove = &insane_move_run_normal;
- else
- self->monsterinfo.currentmove = &insane_move_run_insane;
+ self->monsterinfo.currentmove = &insane_move_run_insane;
}
-void insane_pain (edict_t *self, edict_t *other, float kick, int damage)
+void insane_pain(edict_t *self, edict_t *other, float kick, int damage)
{
- int l,r;
+ int l, r;
// if (self->health < (self->max_health / 2))
// self->s.skinnum = 1;
@@ -486,7 +467,7 @@ void insane_pain (edict_t *self, edict_t *other, float kick, int damage)
self->pain_debounce_time = level.time + 3;
- r = 1 + (rand()&1);
+ r = 1 + (rand() & 1);
if (self->health < 25)
l = 25;
else if (self->health < 50)
@@ -495,103 +476,93 @@ void insane_pain (edict_t *self, edict_t *other, float kick, int damage)
l = 75;
else
l = 100;
- gi.sound (self, CHAN_VOICE, gi.soundindex (va("player/male/pain%i_%i.wav", l, r)), 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, gi.soundindex(va("player/male/pain%i_%i.wav", l, r)), 1, ATTN_IDLE, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
// Don't go into pain frames if crucified.
- if (self->spawnflags & 8)
- {
- self->monsterinfo.currentmove = &insane_move_struggle_cross;
+ if (self->spawnflags & 8) {
+ self->monsterinfo.currentmove = &insane_move_struggle_cross;
return;
}
-
- if ( ((self->s.frame >= FRAME_crawl1) && (self->s.frame <= FRAME_crawl9)) || ((self->s.frame >= FRAME_stand99) && (self->s.frame <= FRAME_stand160)) )
- {
+
+ if (((self->s.frame >= FRAME_crawl1) && (self->s.frame <= FRAME_crawl9)) || ((self->s.frame >= FRAME_stand99) && (self->s.frame <= FRAME_stand160))) {
self->monsterinfo.currentmove = &insane_move_crawl_pain;
- }
- else
+ } else
self->monsterinfo.currentmove = &insane_move_stand_pain;
}
-void insane_onground (edict_t *self)
+void insane_onground(edict_t *self)
{
self->monsterinfo.currentmove = &insane_move_down;
}
-void insane_checkdown (edict_t *self)
+void insane_checkdown(edict_t *self)
{
// if ( (self->s.frame == FRAME_stand94) || (self->s.frame == FRAME_stand65) )
if (self->spawnflags & 32) // Always stand
return;
- if (random() < 0.3)
- {
+ if (random() < 0.3) {
if (random() < 0.5)
self->monsterinfo.currentmove = &insane_move_uptodown;
else
- self->monsterinfo.currentmove = &insane_move_jumpdown;
+ self->monsterinfo.currentmove = &insane_move_jumpdown;
}
}
-void insane_checkup (edict_t *self)
+void insane_checkup(edict_t *self)
{
// If Hold_Ground and Crawl are set
- if ( (self->spawnflags & 4) && (self->spawnflags & 16) )
+ if ((self->spawnflags & 4) && (self->spawnflags & 16))
return;
if (random() < 0.5)
- self->monsterinfo.currentmove = &insane_move_downtoup;
+ self->monsterinfo.currentmove = &insane_move_downtoup;
}
-void insane_stand (edict_t *self)
+void insane_stand(edict_t *self)
{
- if (self->spawnflags & 8) // If crucified
- {
+ if (self->spawnflags & 8) { // If crucified
self->monsterinfo.currentmove = &insane_move_cross;
self->monsterinfo.aiflags |= AI_STAND_GROUND;
}
// If Hold_Ground and Crawl are set
- else if ( (self->spawnflags & 4) && (self->spawnflags & 16) )
+ else if ((self->spawnflags & 4) && (self->spawnflags & 16))
self->monsterinfo.currentmove = &insane_move_down;
+ else if (random() < 0.5)
+ self->monsterinfo.currentmove = &insane_move_stand_normal;
else
- if (random() < 0.5)
- self->monsterinfo.currentmove = &insane_move_stand_normal;
- else
- self->monsterinfo.currentmove = &insane_move_stand_insane;
+ self->monsterinfo.currentmove = &insane_move_stand_insane;
}
-void insane_dead (edict_t *self)
+void insane_dead(edict_t *self)
{
- if (self->spawnflags & 8)
- {
+ if (self->spawnflags & 8) {
self->flags |= FL_FLY;
- }
- else
- {
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ } else {
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
}
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void insane_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void insane_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_IDLE, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_IDLE, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -599,18 +570,15 @@ void insane_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
if (self->deadflag == DEAD_DEAD)
return;
- gi.sound (self, CHAN_VOICE, gi.soundindex(va("player/male/death%i.wav", (rand()%4)+1)), 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, gi.soundindex(va("player/male/death%i.wav", (rand() % 4) + 1)), 1, ATTN_IDLE, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
- if (self->spawnflags & 8)
- {
- insane_dead (self);
- }
- else
- {
- if ( ((self->s.frame >= FRAME_crawl1) && (self->s.frame <= FRAME_crawl9)) || ((self->s.frame >= FRAME_stand99) && (self->s.frame <= FRAME_stand160)) )
+ if (self->spawnflags & 8) {
+ insane_dead(self);
+ } else {
+ if (((self->s.frame >= FRAME_crawl1) && (self->s.frame <= FRAME_crawl9)) || ((self->s.frame >= FRAME_stand99) && (self->s.frame <= FRAME_stand160)))
self->monsterinfo.currentmove = &insane_move_crawl_death;
else
self->monsterinfo.currentmove = &insane_move_stand_death;
@@ -620,34 +588,33 @@ void insane_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
/*QUAKED misc_insane (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn CRAWL CRUCIFIED STAND_GROUND ALWAYS_STAND
*/
-void SP_misc_insane (edict_t *self)
+void SP_misc_insane(edict_t *self)
{
// static int skin = 0; //@@
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_fist = gi.soundindex ("insane/insane11.wav");
- sound_shake = gi.soundindex ("insane/insane5.wav");
- sound_moan = gi.soundindex ("insane/insane7.wav");
- sound_scream[0] = gi.soundindex ("insane/insane1.wav");
- sound_scream[1] = gi.soundindex ("insane/insane2.wav");
- sound_scream[2] = gi.soundindex ("insane/insane3.wav");
- sound_scream[3] = gi.soundindex ("insane/insane4.wav");
- sound_scream[4] = gi.soundindex ("insane/insane6.wav");
- sound_scream[5] = gi.soundindex ("insane/insane8.wav");
- sound_scream[6] = gi.soundindex ("insane/insane9.wav");
- sound_scream[7] = gi.soundindex ("insane/insane10.wav");
+ sound_fist = gi.soundindex("insane/insane11.wav");
+ sound_shake = gi.soundindex("insane/insane5.wav");
+ sound_moan = gi.soundindex("insane/insane7.wav");
+ sound_scream[0] = gi.soundindex("insane/insane1.wav");
+ sound_scream[1] = gi.soundindex("insane/insane2.wav");
+ sound_scream[2] = gi.soundindex("insane/insane3.wav");
+ sound_scream[3] = gi.soundindex("insane/insane4.wav");
+ sound_scream[4] = gi.soundindex("insane/insane6.wav");
+ sound_scream[5] = gi.soundindex("insane/insane8.wav");
+ sound_scream[6] = gi.soundindex("insane/insane9.wav");
+ sound_scream[7] = gi.soundindex("insane/insane10.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
self->s.modelindex = gi.modelindex("models/monsters/insane/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->health = 100;
self->gib_health = -50;
@@ -671,25 +638,22 @@ void SP_misc_insane (edict_t *self)
// if (skin > 12)
// skin = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
if (self->spawnflags & 16) // Stand Ground
self->monsterinfo.aiflags |= AI_STAND_GROUND;
self->monsterinfo.currentmove = &insane_move_stand_normal;
-
+
self->monsterinfo.scale = MODEL_SCALE;
- if (self->spawnflags & 8) // Crucified ?
- {
- VectorSet (self->mins, -16, 0, 0);
- VectorSet (self->maxs, 16, 8, 32);
+ if (self->spawnflags & 8) { // Crucified ?
+ VectorSet(self->mins, -16, 0, 0);
+ VectorSet(self->maxs, 16, 8, 32);
self->flags |= FL_NO_KNOCKBACK;
- flymonster_start (self);
- }
- else
- {
- walkmonster_start (self);
- self->s.skinnum = rand()%3;
+ flymonster_start(self);
+ } else {
+ walkmonster_start(self);
+ self->s.skinnum = rand() % 3;
}
}
diff --git a/src/baseq2/m_insane.h b/src/baseq2/m_insane.h
index 12d9dde..4ce38db 100644
--- a/src/baseq2/m_insane.h
+++ b/src/baseq2/m_insane.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_medic.c b/src/baseq2/m_medic.c
index a5b2aec..3bcb593 100644
--- a/src/baseq2/m_medic.c
+++ b/src/baseq2/m_medic.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ MEDIC
#include "g_local.h"
#include "m_medic.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
static int sound_idle1;
@@ -43,13 +43,12 @@ static int sound_hook_heal;
static int sound_hook_retract;
-edict_t *medic_FindDeadMonster (edict_t *self)
+edict_t *medic_FindDeadMonster(edict_t *self)
{
edict_t *ent = NULL;
edict_t *best = NULL;
- while ((ent = findradius(ent, self->s.origin, 1024)) != NULL)
- {
+ while ((ent = findradius(ent, self->s.origin, 1024)) != NULL) {
if (ent == self)
continue;
if (!(ent->svflags & SVF_MONSTER))
@@ -64,8 +63,7 @@ edict_t *medic_FindDeadMonster (edict_t *self)
continue;
if (!visible(self, ent))
continue;
- if (!best)
- {
+ if (!best) {
best = ent;
continue;
}
@@ -77,50 +75,46 @@ edict_t *medic_FindDeadMonster (edict_t *self)
return best;
}
-void medic_idle (edict_t *self)
+void medic_idle(edict_t *self)
{
edict_t *ent;
- gi.sound (self, CHAN_VOICE, sound_idle1, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle1, 1, ATTN_IDLE, 0);
ent = medic_FindDeadMonster(self);
- if (ent)
- {
+ if (ent) {
self->enemy = ent;
self->enemy->owner = self;
self->monsterinfo.aiflags |= AI_MEDIC;
- FoundTarget (self);
+ FoundTarget(self);
}
}
-void medic_search (edict_t *self)
+void medic_search(edict_t *self)
{
edict_t *ent;
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_IDLE, 0);
- if (!self->oldenemy)
- {
+ if (!self->oldenemy) {
ent = medic_FindDeadMonster(self);
- if (ent)
- {
+ if (ent) {
self->oldenemy = self->enemy;
self->enemy = ent;
self->enemy->owner = self;
self->monsterinfo.aiflags |= AI_MEDIC;
- FoundTarget (self);
+ FoundTarget(self);
}
}
}
-void medic_sight (edict_t *self, edict_t *other)
+void medic_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-mframe_t medic_frames_stand [] =
-{
+mframe_t medic_frames_stand [] = {
{ ai_stand, 0, medic_idle },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -215,14 +209,13 @@ mframe_t medic_frames_stand [] =
};
mmove_t medic_move_stand = {FRAME_wait1, FRAME_wait90, medic_frames_stand, NULL};
-void medic_stand (edict_t *self)
+void medic_stand(edict_t *self)
{
self->monsterinfo.currentmove = &medic_move_stand;
}
-mframe_t medic_frames_walk [] =
-{
+mframe_t medic_frames_walk [] = {
{ ai_walk, 6.2, NULL },
{ ai_walk, 18.1, NULL },
{ ai_walk, 1, NULL },
@@ -238,38 +231,35 @@ mframe_t medic_frames_walk [] =
};
mmove_t medic_move_walk = {FRAME_walk1, FRAME_walk12, medic_frames_walk, NULL};
-void medic_walk (edict_t *self)
+void medic_walk(edict_t *self)
{
self->monsterinfo.currentmove = &medic_move_walk;
}
-mframe_t medic_frames_run [] =
-{
+mframe_t medic_frames_run [] = {
{ ai_run, 18, NULL },
{ ai_run, 22.5, NULL },
{ ai_run, 25.4, NULL },
{ ai_run, 23.4, NULL },
{ ai_run, 24, NULL },
{ ai_run, 35.6, NULL }
-
+
};
mmove_t medic_move_run = {FRAME_run1, FRAME_run6, medic_frames_run, NULL};
-void medic_run (edict_t *self)
+void medic_run(edict_t *self)
{
- if (!(self->monsterinfo.aiflags & AI_MEDIC))
- {
+ if (!(self->monsterinfo.aiflags & AI_MEDIC)) {
edict_t *ent;
ent = medic_FindDeadMonster(self);
- if (ent)
- {
+ if (ent) {
self->oldenemy = self->enemy;
self->enemy = ent;
self->enemy->owner = self;
self->monsterinfo.aiflags |= AI_MEDIC;
- FoundTarget (self);
+ FoundTarget(self);
return;
}
}
@@ -281,8 +271,7 @@ void medic_run (edict_t *self)
}
-mframe_t medic_frames_pain1 [] =
-{
+mframe_t medic_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -294,8 +283,7 @@ mframe_t medic_frames_pain1 [] =
};
mmove_t medic_move_pain1 = {FRAME_paina1, FRAME_paina8, medic_frames_pain1, medic_run};
-mframe_t medic_frames_pain2 [] =
-{
+mframe_t medic_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -314,7 +302,7 @@ mframe_t medic_frames_pain2 [] =
};
mmove_t medic_move_pain2 = {FRAME_painb1, FRAME_painb15, medic_frames_pain2, medic_run};
-void medic_pain (edict_t *self, edict_t *other, float kick, int damage)
+void medic_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -327,19 +315,16 @@ void medic_pain (edict_t *self, edict_t *other, float kick, int damage)
if (skill->value == 3)
return; // no pain anims in nightmare
- if (random() < 0.5)
- {
+ if (random() < 0.5) {
self->monsterinfo.currentmove = &medic_move_pain1;
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
- }
- else
- {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
self->monsterinfo.currentmove = &medic_move_pain2;
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
}
}
-void medic_fire_blaster (edict_t *self)
+void medic_fire_blaster(edict_t *self)
{
vec3_t start;
vec3_t forward, right;
@@ -354,29 +339,28 @@ void medic_fire_blaster (edict_t *self)
else
effect = 0;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_MEDIC_BLASTER_1], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[MZ2_MEDIC_BLASTER_1], forward, right, start);
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, dir);
+ VectorSubtract(end, start, dir);
- monster_fire_blaster (self, start, dir, 2, 1000, MZ2_MEDIC_BLASTER_1, effect);
+ monster_fire_blaster(self, start, dir, 2, 1000, MZ2_MEDIC_BLASTER_1, effect);
}
-void medic_dead (edict_t *self)
+void medic_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t medic_frames_death [] =
-{
+mframe_t medic_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -410,7 +394,7 @@ mframe_t medic_frames_death [] =
};
mmove_t medic_move_death = {FRAME_death1, FRAME_death30, medic_frames_death, medic_dead};
-void medic_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void medic_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
@@ -419,14 +403,13 @@ void medic_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
self->enemy->owner = NULL;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -435,7 +418,7 @@ void medic_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
@@ -443,7 +426,7 @@ void medic_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage
}
-void medic_duck_down (edict_t *self)
+void medic_duck_down(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
@@ -451,10 +434,10 @@ void medic_duck_down (edict_t *self)
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
self->monsterinfo.pausetime = level.time + 1;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void medic_duck_hold (edict_t *self)
+void medic_duck_hold(edict_t *self)
{
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -462,16 +445,15 @@ void medic_duck_hold (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-void medic_duck_up (edict_t *self)
+void medic_duck_up(edict_t *self)
{
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t medic_frames_duck [] =
-{
+mframe_t medic_frames_duck [] = {
{ ai_move, -1, NULL },
{ ai_move, -1, NULL },
{ ai_move, -1, medic_duck_down },
@@ -491,7 +473,7 @@ mframe_t medic_frames_duck [] =
};
mmove_t medic_move_duck = {FRAME_duck1, FRAME_duck16, medic_frames_duck, medic_run};
-void medic_dodge (edict_t *self, edict_t *attacker, float eta)
+void medic_dodge(edict_t *self, edict_t *attacker, float eta)
{
if (random() > 0.25)
return;
@@ -502,8 +484,7 @@ void medic_dodge (edict_t *self, edict_t *attacker, float eta)
self->monsterinfo.currentmove = &medic_move_duck;
}
-mframe_t medic_frames_attackHyperBlaster [] =
-{
+mframe_t medic_frames_attackHyperBlaster [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -524,16 +505,15 @@ mframe_t medic_frames_attackHyperBlaster [] =
mmove_t medic_move_attackHyperBlaster = {FRAME_attack15, FRAME_attack30, medic_frames_attackHyperBlaster, medic_run};
-void medic_continue (edict_t *self)
+void medic_continue(edict_t *self)
{
- if (visible (self, self->enemy) )
+ if (visible(self, self->enemy))
if (random() <= 0.95)
self->monsterinfo.currentmove = &medic_move_attackHyperBlaster;
}
-mframe_t medic_frames_attackBlaster [] =
-{
+mframe_t medic_frames_attackBlaster [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 5, NULL },
{ ai_charge, 5, NULL },
@@ -545,22 +525,21 @@ mframe_t medic_frames_attackBlaster [] =
{ ai_charge, 0, medic_fire_blaster },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
- { ai_charge, 0, medic_fire_blaster },
+ { ai_charge, 0, medic_fire_blaster },
{ ai_charge, 0, NULL },
{ ai_charge, 0, medic_continue } // Change to medic_continue... Else, go to frame 32
};
mmove_t medic_move_attackBlaster = {FRAME_attack1, FRAME_attack14, medic_frames_attackBlaster, medic_run};
-void medic_hook_launch (edict_t *self)
+void medic_hook_launch(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_hook_launch, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_hook_launch, 1, ATTN_NORM, 0);
}
-void ED_CallSpawn (edict_t *ent);
+void ED_CallSpawn(edict_t *ent);
-static vec3_t medic_cable_offsets[] =
-{
+static vec3_t medic_cable_offsets[] = {
{ 45.0, -9.2, 15.5 },
{ 48.4, -9.7, 15.2 },
{ 47.8, -9.8, 15.8 },
@@ -573,7 +552,7 @@ static vec3_t medic_cable_offsets[] =
{ 32.7, -19.7, 10.4 }
};
-void medic_cable_attack (edict_t *self)
+void medic_cable_attack(edict_t *self)
{
vec3_t offset, start, end, f, r;
trace_t tr;
@@ -583,34 +562,31 @@ void medic_cable_attack (edict_t *self)
if (!self->enemy->inuse)
return;
- AngleVectors (self->s.angles, f, r, NULL);
- VectorCopy (medic_cable_offsets[self->s.frame - FRAME_attack42], offset);
- G_ProjectSource (self->s.origin, offset, f, r, start);
+ AngleVectors(self->s.angles, f, r, NULL);
+ VectorCopy(medic_cable_offsets[self->s.frame - FRAME_attack42], offset);
+ G_ProjectSource(self->s.origin, offset, f, r, start);
// check for max distance
- VectorSubtract (start, self->enemy->s.origin, dir);
+ VectorSubtract(start, self->enemy->s.origin, dir);
distance = VectorLength(dir);
if (distance > 256)
return;
// check for min/max pitch
- vectoangles (dir, angles);
+ vectoangles(dir, angles);
if (angles[0] < -180)
angles[0] += 360;
if (fabs(angles[0]) > 45)
return;
- tr = gi.trace (start, NULL, NULL, self->enemy->s.origin, self, MASK_SHOT);
+ tr = gi.trace(start, NULL, NULL, self->enemy->s.origin, self, MASK_SHOT);
if (tr.fraction != 1.0 && tr.ent != self->enemy)
return;
- if (self->s.frame == FRAME_attack43)
- {
- gi.sound (self->enemy, CHAN_AUTO, sound_hook_hit, 1, ATTN_NORM, 0);
+ if (self->s.frame == FRAME_attack43) {
+ gi.sound(self->enemy, CHAN_AUTO, sound_hook_hit, 1, ATTN_NORM, 0);
self->enemy->monsterinfo.aiflags |= AI_RESURRECTING;
- }
- else if (self->s.frame == FRAME_attack50)
- {
+ } else if (self->s.frame == FRAME_attack50) {
self->enemy->spawnflags = 0;
self->enemy->monsterinfo.aiflags = 0;
self->enemy->target = NULL;
@@ -618,49 +594,44 @@ void medic_cable_attack (edict_t *self)
self->enemy->combattarget = NULL;
self->enemy->deathtarget = NULL;
self->enemy->owner = self;
- ED_CallSpawn (self->enemy);
+ ED_CallSpawn(self->enemy);
self->enemy->owner = NULL;
- if (self->enemy->think)
- {
+ if (self->enemy->think) {
self->enemy->nextthink = level.time;
- self->enemy->think (self->enemy);
+ self->enemy->think(self->enemy);
}
self->enemy->monsterinfo.aiflags |= AI_RESURRECTING;
- if (self->oldenemy && self->oldenemy->client)
- {
+ if (self->oldenemy && self->oldenemy->client) {
self->enemy->enemy = self->oldenemy;
- FoundTarget (self->enemy);
+ FoundTarget(self->enemy);
}
- }
- else
- {
+ } else {
if (self->s.frame == FRAME_attack44)
- gi.sound (self, CHAN_WEAPON, sound_hook_heal, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_hook_heal, 1, ATTN_NORM, 0);
}
// adjust start for beam origin being in middle of a segment
- VectorMA (start, 8, f, start);
+ VectorMA(start, 8, f, start);
// adjust end z for end spot since the monster is currently dead
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
end[2] = self->enemy->absmin[2] + self->enemy->size[2] / 2;
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_MEDIC_CABLE_ATTACK);
- gi.WriteShort (self - g_edicts);
- gi.WritePosition (start);
- gi.WritePosition (end);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_MEDIC_CABLE_ATTACK);
+ gi.WriteShort(self - g_edicts);
+ gi.WritePosition(start);
+ gi.WritePosition(end);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
}
-void medic_hook_retract (edict_t *self)
+void medic_hook_retract(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_hook_retract, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_hook_retract, 1, ATTN_NORM, 0);
self->enemy->monsterinfo.aiflags &= ~AI_RESURRECTING;
}
-mframe_t medic_frames_attackCable [] =
-{
+mframe_t medic_frames_attackCable [] = {
{ ai_move, 2, NULL },
{ ai_move, 3, NULL },
{ ai_move, 5, NULL },
@@ -701,46 +672,44 @@ void medic_attack(edict_t *self)
self->monsterinfo.currentmove = &medic_move_attackBlaster;
}
-qboolean medic_checkattack (edict_t *self)
+qboolean medic_checkattack(edict_t *self)
{
- if (self->monsterinfo.aiflags & AI_MEDIC)
- {
+ if (self->monsterinfo.aiflags & AI_MEDIC) {
medic_attack(self);
return qtrue;
}
- return M_CheckAttack (self);
+ return M_CheckAttack(self);
}
/*QUAKED monster_medic (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_medic (edict_t *self)
+void SP_monster_medic(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_idle1 = gi.soundindex ("medic/idle.wav");
- sound_pain1 = gi.soundindex ("medic/medpain1.wav");
- sound_pain2 = gi.soundindex ("medic/medpain2.wav");
- sound_die = gi.soundindex ("medic/meddeth1.wav");
- sound_sight = gi.soundindex ("medic/medsght1.wav");
- sound_search = gi.soundindex ("medic/medsrch1.wav");
- sound_hook_launch = gi.soundindex ("medic/medatck2.wav");
- sound_hook_hit = gi.soundindex ("medic/medatck3.wav");
- sound_hook_heal = gi.soundindex ("medic/medatck4.wav");
- sound_hook_retract = gi.soundindex ("medic/medatck5.wav");
+ sound_idle1 = gi.soundindex("medic/idle.wav");
+ sound_pain1 = gi.soundindex("medic/medpain1.wav");
+ sound_pain2 = gi.soundindex("medic/medpain2.wav");
+ sound_die = gi.soundindex("medic/meddeth1.wav");
+ sound_sight = gi.soundindex("medic/medsght1.wav");
+ sound_search = gi.soundindex("medic/medsrch1.wav");
+ sound_hook_launch = gi.soundindex("medic/medatck2.wav");
+ sound_hook_hit = gi.soundindex("medic/medatck3.wav");
+ sound_hook_heal = gi.soundindex("medic/medatck4.wav");
+ sound_hook_retract = gi.soundindex("medic/medatck5.wav");
- gi.soundindex ("medic/medatck1.wav");
+ gi.soundindex("medic/medatck1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/medic/tris.md2");
- VectorSet (self->mins, -24, -24, -24);
- VectorSet (self->maxs, 24, 24, 32);
+ self->s.modelindex = gi.modelindex("models/monsters/medic/tris.md2");
+ VectorSet(self->mins, -24, -24, -24);
+ VectorSet(self->maxs, 24, 24, 32);
self->health = 300;
self->gib_health = -130;
@@ -760,10 +729,10 @@ void SP_monster_medic (edict_t *self)
self->monsterinfo.search = medic_search;
self->monsterinfo.checkattack = medic_checkattack;
- gi.linkentity (self);
+ gi.linkentity(self);
self->monsterinfo.currentmove = &medic_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_medic.h b/src/baseq2/m_medic.h
index 6b596b2..a4c349e 100644
--- a/src/baseq2/m_medic.h
+++ b/src/baseq2/m_medic.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_move.c b/src/baseq2/m_move.c
index 02a11fe..192b629 100644
--- a/src/baseq2/m_move.c
+++ b/src/baseq2/m_move.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,26 +34,25 @@ is not a staircase.
*/
int c_yes, c_no;
-qboolean M_CheckBottom (edict_t *ent)
+qboolean M_CheckBottom(edict_t *ent)
{
vec3_t mins, maxs, start, stop;
trace_t trace;
int x, y;
float mid, bottom;
-
- VectorAdd (ent->s.origin, ent->mins, mins);
- VectorAdd (ent->s.origin, ent->maxs, maxs);
+
+ VectorAdd(ent->s.origin, ent->mins, mins);
+ VectorAdd(ent->s.origin, ent->maxs, maxs);
// if all of the points under the corners are solid world, don't bother
// with the tougher checks
// the corners must be within 16 of the midpoint
start[2] = mins[2] - 1;
- for (x=0 ; x<=1 ; x++)
- for (y=0 ; y<=1 ; y++)
- {
+ for (x = 0 ; x <= 1 ; x++)
+ for (y = 0 ; y <= 1 ; y++) {
start[0] = x ? maxs[0] : mins[0];
start[1] = y ? maxs[1] : mins[1];
- if (gi.pointcontents (start) != CONTENTS_SOLID)
+ if (gi.pointcontents(start) != CONTENTS_SOLID)
goto realcheck;
}
@@ -66,26 +65,25 @@ realcheck:
// check it for real...
//
start[2] = mins[2];
-
+
// the midpoint must be within 16 of the bottom
- start[0] = stop[0] = (mins[0] + maxs[0])*0.5;
- start[1] = stop[1] = (mins[1] + maxs[1])*0.5;
- stop[2] = start[2] - 2*STEPSIZE;
- trace = gi.trace (start, vec3_origin, vec3_origin, stop, ent, MASK_MONSTERSOLID);
+ start[0] = stop[0] = (mins[0] + maxs[0]) * 0.5;
+ start[1] = stop[1] = (mins[1] + maxs[1]) * 0.5;
+ stop[2] = start[2] - 2 * STEPSIZE;
+ trace = gi.trace(start, vec3_origin, vec3_origin, stop, ent, MASK_MONSTERSOLID);
if (trace.fraction == 1.0)
return qfalse;
mid = bottom = trace.endpos[2];
-
-// the corners must be within 16 of the midpoint
- for (x=0 ; x<=1 ; x++)
- for (y=0 ; y<=1 ; y++)
- {
+
+// the corners must be within 16 of the midpoint
+ for (x = 0 ; x <= 1 ; x++)
+ for (y = 0 ; y <= 1 ; y++) {
start[0] = stop[0] = x ? maxs[0] : mins[0];
start[1] = stop[1] = y ? maxs[1] : mins[1];
-
- trace = gi.trace (start, vec3_origin, vec3_origin, stop, ent, MASK_MONSTERSOLID);
-
+
+ trace = gi.trace(start, vec3_origin, vec3_origin, stop, ent, MASK_MONSTERSOLID);
+
if (trace.fraction != 1.0 && trace.endpos[2] > bottom)
bottom = trace.endpos[2];
if (trace.fraction == 1.0 || mid - trace.endpos[2] > STEPSIZE)
@@ -109,7 +107,7 @@ pr_global_struct->trace_normal is set to the normal of the blocking wall
*/
//FIXME since we need to test end position contents here, can we avoid doing
//it again later in catagorize position?
-qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
+qboolean SV_movestep(edict_t *ent, vec3_t move, qboolean relink)
{
float dz;
vec3_t oldorg, neworg, end;
@@ -119,32 +117,26 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
vec3_t test;
int contents;
-// try the move
- VectorCopy (ent->s.origin, oldorg);
- VectorAdd (ent->s.origin, move, neworg);
+// try the move
+ VectorCopy(ent->s.origin, oldorg);
+ VectorAdd(ent->s.origin, move, neworg);
// flying monsters don't step up
- if ( ent->flags & (FL_SWIM | FL_FLY) )
- {
- // try one move with vertical motion, then one without
- for (i=0 ; i<2 ; i++)
- {
- VectorAdd (ent->s.origin, move, neworg);
- if (i == 0 && ent->enemy)
- {
+ if (ent->flags & (FL_SWIM | FL_FLY)) {
+ // try one move with vertical motion, then one without
+ for (i = 0 ; i < 2 ; i++) {
+ VectorAdd(ent->s.origin, move, neworg);
+ if (i == 0 && ent->enemy) {
if (!ent->goalentity)
ent->goalentity = ent->enemy;
dz = ent->s.origin[2] - ent->goalentity->s.origin[2];
- if (ent->goalentity->client)
- {
+ if (ent->goalentity->client) {
if (dz > 40)
neworg[2] -= 8;
if (!((ent->flags & FL_SWIM) && (ent->waterlevel < 2)))
if (dz < 30)
neworg[2] += 8;
- }
- else
- {
+ } else {
if (dz > 8)
neworg[2] -= 8;
else if (dz > 0)
@@ -155,13 +147,11 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
neworg[2] += dz;
}
}
- trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, neworg, ent, MASK_MONSTERSOLID);
-
+ trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, neworg, ent, MASK_MONSTERSOLID);
+
// fly monsters don't enter water voluntarily
- if (ent->flags & FL_FLY)
- {
- if (!ent->waterlevel)
- {
+ if (ent->flags & FL_FLY) {
+ if (!ent->waterlevel) {
test[0] = trace.endpos[0];
test[1] = trace.endpos[1];
test[2] = trace.endpos[2] + ent->mins[2] + 1;
@@ -172,10 +162,8 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
}
// swim monsters don't exit water voluntarily
- if (ent->flags & FL_SWIM)
- {
- if (ent->waterlevel < 2)
- {
+ if (ent->flags & FL_SWIM) {
+ if (ent->waterlevel < 2) {
test[0] = trace.endpos[0];
test[1] = trace.endpos[1];
test[2] = trace.endpos[2] + ent->mins[2] + 1;
@@ -185,21 +173,19 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
}
}
- if (trace.fraction == 1)
- {
- VectorCopy (trace.endpos, ent->s.origin);
- if (relink)
- {
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ if (trace.fraction == 1) {
+ VectorCopy(trace.endpos, ent->s.origin);
+ if (relink) {
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
}
return qtrue;
}
-
+
if (!ent->enemy)
break;
}
-
+
return qfalse;
}
@@ -210,84 +196,75 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
stepsize = 1;
neworg[2] += stepsize;
- VectorCopy (neworg, end);
- end[2] -= stepsize*2;
+ VectorCopy(neworg, end);
+ end[2] -= stepsize * 2;
- trace = gi.trace (neworg, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
+ trace = gi.trace(neworg, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
if (trace.allsolid)
return qfalse;
- if (trace.startsolid)
- {
+ if (trace.startsolid) {
neworg[2] -= stepsize;
- trace = gi.trace (neworg, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
+ trace = gi.trace(neworg, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID);
if (trace.allsolid || trace.startsolid)
return qfalse;
}
// don't go in to water
- if (ent->waterlevel == 0)
- {
+ if (ent->waterlevel == 0) {
test[0] = trace.endpos[0];
test[1] = trace.endpos[1];
- test[2] = trace.endpos[2] + ent->mins[2] + 1;
+ test[2] = trace.endpos[2] + ent->mins[2] + 1;
contents = gi.pointcontents(test);
if (contents & MASK_WATER)
return qfalse;
}
- if (trace.fraction == 1)
- {
- // if monster had the ground pulled out, go ahead and fall
- if ( ent->flags & FL_PARTIALGROUND )
- {
- VectorAdd (ent->s.origin, move, ent->s.origin);
- if (relink)
- {
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ if (trace.fraction == 1) {
+ // if monster had the ground pulled out, go ahead and fall
+ if (ent->flags & FL_PARTIALGROUND) {
+ VectorAdd(ent->s.origin, move, ent->s.origin);
+ if (relink) {
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
}
ent->groundentity = NULL;
return qtrue;
}
-
+
return qfalse; // walked off an edge
}
// check point traces down for dangling corners
- VectorCopy (trace.endpos, ent->s.origin);
-
- if (!M_CheckBottom (ent))
- {
- if ( ent->flags & FL_PARTIALGROUND )
- { // entity had floor mostly pulled out from underneath it
+ VectorCopy(trace.endpos, ent->s.origin);
+
+ if (!M_CheckBottom(ent)) {
+ if (ent->flags & FL_PARTIALGROUND) {
+ // entity had floor mostly pulled out from underneath it
// and is trying to correct
- if (relink)
- {
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ if (relink) {
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
}
return qtrue;
}
- VectorCopy (oldorg, ent->s.origin);
+ VectorCopy(oldorg, ent->s.origin);
return qfalse;
}
- if ( ent->flags & FL_PARTIALGROUND )
- {
+ if (ent->flags & FL_PARTIALGROUND) {
ent->flags &= ~FL_PARTIALGROUND;
}
ent->groundentity = trace.ent;
ent->groundentity_linkcount = trace.ent->linkcount;
// the move is ok
- if (relink)
- {
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ if (relink) {
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
}
return qtrue;
}
@@ -301,13 +278,13 @@ M_ChangeYaw
===============
*/
-void M_ChangeYaw (edict_t *ent)
+void M_ChangeYaw(edict_t *ent)
{
float ideal;
float current;
float move;
float speed;
-
+
current = anglemod(ent->s.angles[YAW]);
ideal = ent->ideal_yaw;
@@ -316,28 +293,22 @@ void M_ChangeYaw (edict_t *ent)
move = ideal - current;
speed = ent->yaw_speed;
- if (ideal > current)
- {
+ if (ideal > current) {
if (move >= 180)
move = move - 360;
- }
- else
- {
+ } else {
if (move <= -180)
move = move + 360;
}
- if (move > 0)
- {
+ if (move > 0) {
if (move > speed)
move = speed;
- }
- else
- {
+ } else {
if (move < -speed)
move = -speed;
}
-
- ent->s.angles[YAW] = anglemod (current + move);
+
+ ent->s.angles[YAW] = anglemod(current + move);
}
@@ -350,33 +321,32 @@ facing it.
======================
*/
-qboolean SV_StepDirection (edict_t *ent, float yaw, float dist)
+qboolean SV_StepDirection(edict_t *ent, float yaw, float dist)
{
vec3_t move, oldorigin;
float delta;
-
+
ent->ideal_yaw = yaw;
- M_ChangeYaw (ent);
-
- yaw = yaw*M_PI*2 / 360;
- move[0] = cos(yaw)*dist;
- move[1] = sin(yaw)*dist;
+ M_ChangeYaw(ent);
+
+ yaw = yaw * M_PI * 2 / 360;
+ move[0] = cos(yaw) * dist;
+ move[1] = sin(yaw) * dist;
move[2] = 0;
- VectorCopy (ent->s.origin, oldorigin);
- if (SV_movestep (ent, move, qfalse))
- {
+ VectorCopy(ent->s.origin, oldorigin);
+ if (SV_movestep(ent, move, qfalse)) {
delta = ent->s.angles[YAW] - ent->ideal_yaw;
- if (delta > 45 && delta < 315)
- { // not turned far enough, so don't take the step
- VectorCopy (oldorigin, ent->s.origin);
+ if (delta > 45 && delta < 315) {
+ // not turned far enough, so don't take the step
+ VectorCopy(oldorigin, ent->s.origin);
}
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
return qtrue;
}
- gi.linkentity (ent);
- G_TouchTriggers (ent);
+ gi.linkentity(ent);
+ G_TouchTriggers(ent);
return qfalse;
}
@@ -386,7 +356,7 @@ SV_FixCheckBottom
======================
*/
-void SV_FixCheckBottom (edict_t *ent)
+void SV_FixCheckBottom(edict_t *ent)
{
ent->flags |= FL_PARTIALGROUND;
}
@@ -400,9 +370,9 @@ SV_NewChaseDir
================
*/
#define DI_NODIR -1
-void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist)
+void SV_NewChaseDir(edict_t *actor, edict_t *enemy, float dist)
{
- float deltax,deltay;
+ float deltax, deltay;
float d[3];
float tdir, olddir, turnaround;
@@ -410,80 +380,75 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist)
if (!enemy)
return;
- olddir = anglemod( (int)(actor->ideal_yaw/45)*45 );
+ olddir = anglemod((int)(actor->ideal_yaw / 45) * 45);
turnaround = anglemod(olddir - 180);
deltax = enemy->s.origin[0] - actor->s.origin[0];
deltay = enemy->s.origin[1] - actor->s.origin[1];
- if (deltax>10)
- d[1]= 0;
- else if (deltax<-10)
- d[1]= 180;
+ if (deltax > 10)
+ d[1] = 0;
+ else if (deltax < -10)
+ d[1] = 180;
else
- d[1]= DI_NODIR;
- if (deltay<-10)
- d[2]= 270;
- else if (deltay>10)
- d[2]= 90;
+ d[1] = DI_NODIR;
+ if (deltay < -10)
+ d[2] = 270;
+ else if (deltay > 10)
+ d[2] = 90;
else
- d[2]= DI_NODIR;
+ d[2] = DI_NODIR;
// try direct route
- if (d[1] != DI_NODIR && d[2] != DI_NODIR)
- {
+ if (d[1] != DI_NODIR && d[2] != DI_NODIR) {
if (d[1] == 0)
tdir = d[2] == 90 ? 45 : 315;
else
tdir = d[2] == 90 ? 135 : 215;
-
+
if (tdir != turnaround && SV_StepDirection(actor, tdir, dist))
return;
}
// try other directions
- if ( ((rand()&3) & 1) || abs(deltay)>abs(deltax))
- {
- tdir=d[1];
- d[1]=d[2];
- d[2]=tdir;
+ if (((rand() & 3) & 1) || abs(deltay) > abs(deltax)) {
+ tdir = d[1];
+ d[1] = d[2];
+ d[2] = tdir;
}
- if (d[1]!=DI_NODIR && d[1]!=turnaround
- && SV_StepDirection(actor, d[1], dist))
- return;
+ if (d[1] != DI_NODIR && d[1] != turnaround
+ && SV_StepDirection(actor, d[1], dist))
+ return;
- if (d[2]!=DI_NODIR && d[2]!=turnaround
- && SV_StepDirection(actor, d[2], dist))
- return;
+ if (d[2] != DI_NODIR && d[2] != turnaround
+ && SV_StepDirection(actor, d[2], dist))
+ return;
-/* there is no direct path to the player, so pick another direction */
+ /* there is no direct path to the player, so pick another direction */
- if (olddir!=DI_NODIR && SV_StepDirection(actor, olddir, dist))
- return;
+ if (olddir != DI_NODIR && SV_StepDirection(actor, olddir, dist))
+ return;
- if (rand()&1) /*randomly determine direction of search*/
- {
- for (tdir=0 ; tdir<=315 ; tdir += 45)
- if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
- return;
- }
- else
- {
- for (tdir=315 ; tdir >=0 ; tdir -= 45)
- if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
- return;
+ if (rand() & 1) { /*randomly determine direction of search*/
+ for (tdir = 0 ; tdir <= 315 ; tdir += 45)
+ if (tdir != turnaround && SV_StepDirection(actor, tdir, dist))
+ return;
+ } else {
+ for (tdir = 315 ; tdir >= 0 ; tdir -= 45)
+ if (tdir != turnaround && SV_StepDirection(actor, tdir, dist))
+ return;
}
- if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) )
- return;
+ if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist))
+ return;
actor->ideal_yaw = olddir; // can't move
// if a bridge was pulled out from underneath a monster, it may not have
// a valid standing position at all
- if (!M_CheckBottom (actor))
- SV_FixCheckBottom (actor);
+ if (!M_CheckBottom(actor))
+ SV_FixCheckBottom(actor);
}
/*
@@ -492,12 +457,11 @@ SV_CloseEnough
======================
*/
-qboolean SV_CloseEnough (edict_t *ent, edict_t *goal, float dist)
+qboolean SV_CloseEnough(edict_t *ent, edict_t *goal, float dist)
{
int i;
-
- for (i=0 ; i<3 ; i++)
- {
+
+ for (i = 0 ; i < 3 ; i++) {
if (goal->absmin[i] > ent->absmax[i] + dist)
return qfalse;
if (goal->absmax[i] < ent->absmin[i] - dist)
@@ -512,24 +476,23 @@ qboolean SV_CloseEnough (edict_t *ent, edict_t *goal, float dist)
M_MoveToGoal
======================
*/
-void M_MoveToGoal (edict_t *ent, float dist)
+void M_MoveToGoal(edict_t *ent, float dist)
{
edict_t *goal;
-
+
goal = ent->goalentity;
- if (!ent->groundentity && !(ent->flags & (FL_FLY|FL_SWIM)))
+ if (!ent->groundentity && !(ent->flags & (FL_FLY | FL_SWIM)))
return;
// if the next step hits the enemy, return immediately
- if (ent->enemy && SV_CloseEnough (ent, ent->enemy, dist) )
+ if (ent->enemy && SV_CloseEnough(ent, ent->enemy, dist))
return;
// bump around...
- if ( (rand()&3)==1 || !SV_StepDirection (ent, ent->ideal_yaw, dist))
- {
+ if ((rand() & 3) == 1 || !SV_StepDirection(ent, ent->ideal_yaw, dist)) {
if (ent->inuse)
- SV_NewChaseDir (ent, goal, dist);
+ SV_NewChaseDir(ent, goal, dist);
}
}
@@ -539,17 +502,17 @@ void M_MoveToGoal (edict_t *ent, float dist)
M_walkmove
===============
*/
-qboolean M_walkmove (edict_t *ent, float yaw, float dist)
+qboolean M_walkmove(edict_t *ent, float yaw, float dist)
{
vec3_t move;
-
- if (!ent->groundentity && !(ent->flags & (FL_FLY|FL_SWIM)))
+
+ if (!ent->groundentity && !(ent->flags & (FL_FLY | FL_SWIM)))
return qfalse;
- yaw = yaw*M_PI*2 / 360;
-
- move[0] = cos(yaw)*dist;
- move[1] = sin(yaw)*dist;
+ yaw = yaw * M_PI * 2 / 360;
+
+ move[0] = cos(yaw) * dist;
+ move[1] = sin(yaw) * dist;
move[2] = 0;
return SV_movestep(ent, move, qtrue);
diff --git a/src/baseq2/m_mutant.c b/src/baseq2/m_mutant.c
index 6805c62..419149e 100644
--- a/src/baseq2/m_mutant.c
+++ b/src/baseq2/m_mutant.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -47,31 +47,31 @@ static int sound_thud;
// SOUNDS
//
-void mutant_step (edict_t *self)
+void mutant_step(edict_t *self)
{
int n;
n = (rand() + 1) % 3;
if (n == 0)
- gi.sound (self, CHAN_VOICE, sound_step1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_step1, 1, ATTN_NORM, 0);
else if (n == 1)
- gi.sound (self, CHAN_VOICE, sound_step2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_step2, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_step3, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_step3, 1, ATTN_NORM, 0);
}
-void mutant_sight (edict_t *self, edict_t *other)
+void mutant_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void mutant_search (edict_t *self)
+void mutant_search(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
}
-void mutant_swing (edict_t *self)
+void mutant_swing(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_swing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_swing, 1, ATTN_NORM, 0);
}
@@ -79,8 +79,7 @@ void mutant_swing (edict_t *self)
// STAND
//
-mframe_t mutant_frames_stand [] =
-{
+mframe_t mutant_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -140,7 +139,7 @@ mframe_t mutant_frames_stand [] =
};
mmove_t mutant_move_stand = {FRAME_stand101, FRAME_stand151, mutant_frames_stand, NULL};
-void mutant_stand (edict_t *self)
+void mutant_stand(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_stand;
}
@@ -150,14 +149,13 @@ void mutant_stand (edict_t *self)
// IDLE
//
-void mutant_idle_loop (edict_t *self)
+void mutant_idle_loop(edict_t *self)
{
if (random() < 0.75)
self->monsterinfo.nextframe = FRAME_stand155;
}
-mframe_t mutant_frames_idle [] =
-{
+mframe_t mutant_frames_idle [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -174,10 +172,10 @@ mframe_t mutant_frames_idle [] =
};
mmove_t mutant_move_idle = {FRAME_stand152, FRAME_stand164, mutant_frames_idle, mutant_stand};
-void mutant_idle (edict_t *self)
+void mutant_idle(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_idle;
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
@@ -185,10 +183,9 @@ void mutant_idle (edict_t *self)
// WALK
//
-void mutant_walk (edict_t *self);
+void mutant_walk(edict_t *self);
-mframe_t mutant_frames_walk [] =
-{
+mframe_t mutant_frames_walk [] = {
{ ai_walk, 3, NULL },
{ ai_walk, 1, NULL },
{ ai_walk, 5, NULL },
@@ -204,13 +201,12 @@ mframe_t mutant_frames_walk [] =
};
mmove_t mutant_move_walk = {FRAME_walk05, FRAME_walk16, mutant_frames_walk, NULL};
-void mutant_walk_loop (edict_t *self)
+void mutant_walk_loop(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_walk;
}
-mframe_t mutant_frames_start_walk [] =
-{
+mframe_t mutant_frames_start_walk [] = {
{ ai_walk, 5, NULL },
{ ai_walk, 5, NULL },
{ ai_walk, -2, NULL },
@@ -218,7 +214,7 @@ mframe_t mutant_frames_start_walk [] =
};
mmove_t mutant_move_start_walk = {FRAME_walk01, FRAME_walk04, mutant_frames_start_walk, mutant_walk_loop};
-void mutant_walk (edict_t *self)
+void mutant_walk(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_start_walk;
}
@@ -228,8 +224,7 @@ void mutant_walk (edict_t *self)
// RUN
//
-mframe_t mutant_frames_run [] =
-{
+mframe_t mutant_frames_run [] = {
{ ai_run, 40, NULL },
{ ai_run, 40, mutant_step },
{ ai_run, 24, NULL },
@@ -239,7 +234,7 @@ mframe_t mutant_frames_run [] =
};
mmove_t mutant_move_run = {FRAME_run03, FRAME_run08, mutant_frames_run, NULL};
-void mutant_run (edict_t *self)
+void mutant_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &mutant_move_stand;
@@ -252,39 +247,38 @@ void mutant_run (edict_t *self)
// MELEE
//
-void mutant_hit_left (edict_t *self)
+void mutant_hit_left(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->mins[0], 8);
- if (fire_hit (self, aim, (10 + (rand() %5)), 100))
- gi.sound (self, CHAN_WEAPON, sound_hit, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->mins[0], 8);
+ if (fire_hit(self, aim, (10 + (rand() % 5)), 100))
+ gi.sound(self, CHAN_WEAPON, sound_hit, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
}
-void mutant_hit_right (edict_t *self)
+void mutant_hit_right(edict_t *self)
{
vec3_t aim;
- VectorSet (aim, MELEE_DISTANCE, self->maxs[0], 8);
- if (fire_hit (self, aim, (10 + (rand() %5)), 100))
- gi.sound (self, CHAN_WEAPON, sound_hit2, 1, ATTN_NORM, 0);
+ VectorSet(aim, MELEE_DISTANCE, self->maxs[0], 8);
+ if (fire_hit(self, aim, (10 + (rand() % 5)), 100))
+ gi.sound(self, CHAN_WEAPON, sound_hit2, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
}
-void mutant_check_refire (edict_t *self)
+void mutant_check_refire(edict_t *self)
{
if (!self->enemy || !self->enemy->inuse || self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attack09;
}
-mframe_t mutant_frames_attack [] =
-{
+mframe_t mutant_frames_attack [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, mutant_hit_left },
@@ -295,7 +289,7 @@ mframe_t mutant_frames_attack [] =
};
mmove_t mutant_move_attack = {FRAME_attack09, FRAME_attack15, mutant_frames_attack, mutant_run};
-void mutant_melee (edict_t *self)
+void mutant_melee(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_attack;
}
@@ -305,34 +299,29 @@ void mutant_melee (edict_t *self)
// ATTACK
//
-void mutant_jump_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
+void mutant_jump_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
- if (self->health <= 0)
- {
+ if (self->health <= 0) {
self->touch = NULL;
return;
}
- if (other->takedamage)
- {
- if (VectorLength(self->velocity) > 400)
- {
+ if (other->takedamage) {
+ if (VectorLength(self->velocity) > 400) {
vec3_t point;
vec3_t normal;
int damage;
- VectorCopy (self->velocity, normal);
+ VectorCopy(self->velocity, normal);
VectorNormalize(normal);
- VectorMA (self->s.origin, self->maxs[0], normal, point);
+ VectorMA(self->s.origin, self->maxs[0], normal, point);
damage = 40 + 10 * random();
- T_Damage (other, self, self, self->velocity, point, normal, damage, damage, 0, MOD_UNKNOWN);
+ T_Damage(other, self, self, self->velocity, point, normal, damage, damage, 0, MOD_UNKNOWN);
}
}
- if (!M_CheckBottom (self))
- {
- if (self->groundentity)
- {
+ if (!M_CheckBottom(self)) {
+ if (self->groundentity) {
self->monsterinfo.nextframe = FRAME_attack02;
self->touch = NULL;
}
@@ -342,14 +331,14 @@ void mutant_jump_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface
self->touch = NULL;
}
-void mutant_jump_takeoff (edict_t *self)
+void mutant_jump_takeoff(edict_t *self)
{
vec3_t forward;
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
- AngleVectors (self->s.angles, forward, NULL, NULL);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ AngleVectors(self->s.angles, forward, NULL, NULL);
self->s.origin[2] += 1;
- VectorScale (forward, 600, self->velocity);
+ VectorScale(forward, 600, self->velocity);
self->velocity[2] = 250;
self->groundentity = NULL;
self->monsterinfo.aiflags |= AI_DUCKED;
@@ -357,11 +346,10 @@ void mutant_jump_takeoff (edict_t *self)
self->touch = mutant_jump_touch;
}
-void mutant_check_landing (edict_t *self)
+void mutant_check_landing(edict_t *self)
{
- if (self->groundentity)
- {
- gi.sound (self, CHAN_WEAPON, sound_thud, 1, ATTN_NORM, 0);
+ if (self->groundentity) {
+ gi.sound(self, CHAN_WEAPON, sound_thud, 1, ATTN_NORM, 0);
self->monsterinfo.attack_finished = 0;
self->monsterinfo.aiflags &= ~AI_DUCKED;
return;
@@ -373,8 +361,7 @@ void mutant_check_landing (edict_t *self)
self->monsterinfo.nextframe = FRAME_attack05;
}
-mframe_t mutant_frames_jump [] =
-{
+mframe_t mutant_frames_jump [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 17, NULL },
{ ai_charge, 15, mutant_jump_takeoff },
@@ -386,7 +373,7 @@ mframe_t mutant_frames_jump [] =
};
mmove_t mutant_move_jump = {FRAME_attack01, FRAME_attack08, mutant_frames_jump, mutant_run};
-void mutant_jump (edict_t *self)
+void mutant_jump(edict_t *self)
{
self->monsterinfo.currentmove = &mutant_move_jump;
}
@@ -396,14 +383,14 @@ void mutant_jump (edict_t *self)
// CHECKATTACK
//
-qboolean mutant_check_melee (edict_t *self)
+qboolean mutant_check_melee(edict_t *self)
{
- if (range (self, self->enemy) == RANGE_MELEE)
+ if (range(self, self->enemy) == RANGE_MELEE)
return qtrue;
return qfalse;
}
-qboolean mutant_check_jump (edict_t *self)
+qboolean mutant_check_jump(edict_t *self)
{
vec3_t v;
float distance;
@@ -421,8 +408,7 @@ qboolean mutant_check_jump (edict_t *self)
if (distance < 100)
return qfalse;
- if (distance > 100)
- {
+ if (distance > 100) {
if (random() < 0.9)
return qfalse;
}
@@ -430,19 +416,17 @@ qboolean mutant_check_jump (edict_t *self)
return qtrue;
}
-qboolean mutant_checkattack (edict_t *self)
+qboolean mutant_checkattack(edict_t *self)
{
if (!self->enemy || self->enemy->health <= 0)
return qfalse;
- if (mutant_check_melee(self))
- {
+ if (mutant_check_melee(self)) {
self->monsterinfo.attack_state = AS_MELEE;
return qtrue;
}
- if (mutant_check_jump(self))
- {
+ if (mutant_check_jump(self)) {
self->monsterinfo.attack_state = AS_MISSILE;
// FIXME play a jump sound here
return qtrue;
@@ -456,8 +440,7 @@ qboolean mutant_checkattack (edict_t *self)
// PAIN
//
-mframe_t mutant_frames_pain1 [] =
-{
+mframe_t mutant_frames_pain1 [] = {
{ ai_move, 4, NULL },
{ ai_move, -3, NULL },
{ ai_move, -8, NULL },
@@ -466,9 +449,8 @@ mframe_t mutant_frames_pain1 [] =
};
mmove_t mutant_move_pain1 = {FRAME_pain101, FRAME_pain105, mutant_frames_pain1, mutant_run};
-mframe_t mutant_frames_pain2 [] =
-{
- { ai_move, -24,NULL },
+mframe_t mutant_frames_pain2 [] = {
+ { ai_move, -24, NULL },
{ ai_move, 11, NULL },
{ ai_move, 5, NULL },
{ ai_move, -2, NULL },
@@ -477,9 +459,8 @@ mframe_t mutant_frames_pain2 [] =
};
mmove_t mutant_move_pain2 = {FRAME_pain201, FRAME_pain206, mutant_frames_pain2, mutant_run};
-mframe_t mutant_frames_pain3 [] =
-{
- { ai_move, -22,NULL },
+mframe_t mutant_frames_pain3 [] = {
+ { ai_move, -22, NULL },
{ ai_move, 3, NULL },
{ ai_move, 3, NULL },
{ ai_move, 2, NULL },
@@ -493,7 +474,7 @@ mframe_t mutant_frames_pain3 [] =
};
mmove_t mutant_move_pain3 = {FRAME_pain301, FRAME_pain311, mutant_frames_pain3, mutant_run};
-void mutant_pain (edict_t *self, edict_t *other, float kick, int damage)
+void mutant_pain(edict_t *self, edict_t *other, float kick, int damage)
{
float r;
@@ -509,19 +490,14 @@ void mutant_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
r = random();
- if (r < 0.33)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ if (r < 0.33) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &mutant_move_pain1;
- }
- else if (r < 0.66)
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ } else if (r < 0.66) {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &mutant_move_pain2;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &mutant_move_pain3;
}
}
@@ -531,19 +507,18 @@ void mutant_pain (edict_t *self, edict_t *other, float kick, int damage)
// DEATH
//
-void mutant_dead (edict_t *self)
+void mutant_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
- gi.linkentity (self);
+ gi.linkentity(self);
- M_FlyCheck (self);
+ M_FlyCheck(self);
}
-mframe_t mutant_frames_death1 [] =
-{
+mframe_t mutant_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -556,8 +531,7 @@ mframe_t mutant_frames_death1 [] =
};
mmove_t mutant_move_death1 = {FRAME_death101, FRAME_death109, mutant_frames_death1, mutant_dead};
-mframe_t mutant_frames_death2 [] =
-{
+mframe_t mutant_frames_death2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -571,18 +545,17 @@ mframe_t mutant_frames_death2 [] =
};
mmove_t mutant_move_death2 = {FRAME_death201, FRAME_death210, mutant_frames_death2, mutant_dead};
-void mutant_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void mutant_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -590,7 +563,7 @@ void mutant_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
if (self->deadflag == DEAD_DEAD)
return;
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->s.skinnum = 1;
@@ -608,33 +581,32 @@ void mutant_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
/*QUAKED monster_mutant (1 .5 0) (-32 -32 -24) (32 32 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_mutant (edict_t *self)
+void SP_monster_mutant(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_swing = gi.soundindex ("mutant/mutatck1.wav");
- sound_hit = gi.soundindex ("mutant/mutatck2.wav");
- sound_hit2 = gi.soundindex ("mutant/mutatck3.wav");
- sound_death = gi.soundindex ("mutant/mutdeth1.wav");
- sound_idle = gi.soundindex ("mutant/mutidle1.wav");
- sound_pain1 = gi.soundindex ("mutant/mutpain1.wav");
- sound_pain2 = gi.soundindex ("mutant/mutpain2.wav");
- sound_sight = gi.soundindex ("mutant/mutsght1.wav");
- sound_search = gi.soundindex ("mutant/mutsrch1.wav");
- sound_step1 = gi.soundindex ("mutant/step1.wav");
- sound_step2 = gi.soundindex ("mutant/step2.wav");
- sound_step3 = gi.soundindex ("mutant/step3.wav");
- sound_thud = gi.soundindex ("mutant/thud1.wav");
-
+ sound_swing = gi.soundindex("mutant/mutatck1.wav");
+ sound_hit = gi.soundindex("mutant/mutatck2.wav");
+ sound_hit2 = gi.soundindex("mutant/mutatck3.wav");
+ sound_death = gi.soundindex("mutant/mutdeth1.wav");
+ sound_idle = gi.soundindex("mutant/mutidle1.wav");
+ sound_pain1 = gi.soundindex("mutant/mutpain1.wav");
+ sound_pain2 = gi.soundindex("mutant/mutpain2.wav");
+ sound_sight = gi.soundindex("mutant/mutsght1.wav");
+ sound_search = gi.soundindex("mutant/mutsrch1.wav");
+ sound_step1 = gi.soundindex("mutant/step1.wav");
+ sound_step2 = gi.soundindex("mutant/step2.wav");
+ sound_step3 = gi.soundindex("mutant/step3.wav");
+ sound_thud = gi.soundindex("mutant/thud1.wav");
+
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/mutant/tris.md2");
- VectorSet (self->mins, -32, -32, -24);
- VectorSet (self->maxs, 32, 32, 48);
+ self->s.modelindex = gi.modelindex("models/monsters/mutant/tris.md2");
+ VectorSet(self->mins, -32, -32, -24);
+ VectorSet(self->maxs, 32, 32, 48);
self->health = 300;
self->gib_health = -120;
@@ -654,10 +626,10 @@ void SP_monster_mutant (edict_t *self)
self->monsterinfo.idle = mutant_idle;
self->monsterinfo.checkattack = mutant_checkattack;
- gi.linkentity (self);
-
+ gi.linkentity(self);
+
self->monsterinfo.currentmove = &mutant_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_mutant.h b/src/baseq2/m_mutant.h
index f59fca0..49a9415 100644
--- a/src/baseq2/m_mutant.h
+++ b/src/baseq2/m_mutant.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_parasite.c b/src/baseq2/m_parasite.c
index 14e4db4..4b2ae4f 100644
--- a/src/baseq2/m_parasite.c
+++ b/src/baseq2/m_parasite.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -42,49 +42,48 @@ static int sound_scratch;
static int sound_search;
-void parasite_stand (edict_t *self);
-void parasite_start_run (edict_t *self);
-void parasite_run (edict_t *self);
-void parasite_walk (edict_t *self);
-void parasite_start_walk (edict_t *self);
-void parasite_end_fidget (edict_t *self);
-void parasite_do_fidget (edict_t *self);
-void parasite_refidget (edict_t *self);
+void parasite_stand(edict_t *self);
+void parasite_start_run(edict_t *self);
+void parasite_run(edict_t *self);
+void parasite_walk(edict_t *self);
+void parasite_start_walk(edict_t *self);
+void parasite_end_fidget(edict_t *self);
+void parasite_do_fidget(edict_t *self);
+void parasite_refidget(edict_t *self);
-void parasite_launch (edict_t *self)
+void parasite_launch(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_launch, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_launch, 1, ATTN_NORM, 0);
}
-void parasite_reel_in (edict_t *self)
+void parasite_reel_in(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_reelin, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_reelin, 1, ATTN_NORM, 0);
}
-void parasite_sight (edict_t *self, edict_t *other)
+void parasite_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_WEAPON, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_sight, 1, ATTN_NORM, 0);
}
-void parasite_tap (edict_t *self)
+void parasite_tap(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_tap, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_WEAPON, sound_tap, 1, ATTN_IDLE, 0);
}
-void parasite_scratch (edict_t *self)
+void parasite_scratch(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_scratch, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_WEAPON, sound_scratch, 1, ATTN_IDLE, 0);
}
-void parasite_search (edict_t *self)
+void parasite_search(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_search, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_WEAPON, sound_search, 1, ATTN_IDLE, 0);
}
-mframe_t parasite_frames_start_fidget [] =
-{
+mframe_t parasite_frames_start_fidget [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -92,8 +91,7 @@ mframe_t parasite_frames_start_fidget [] =
};
mmove_t parasite_move_start_fidget = {FRAME_stand18, FRAME_stand21, parasite_frames_start_fidget, parasite_do_fidget};
-mframe_t parasite_frames_fidget [] =
-{
+mframe_t parasite_frames_fidget [] = {
{ ai_stand, 0, parasite_scratch },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -103,8 +101,7 @@ mframe_t parasite_frames_fidget [] =
};
mmove_t parasite_move_fidget = {FRAME_stand22, FRAME_stand27, parasite_frames_fidget, parasite_refidget};
-mframe_t parasite_frames_end_fidget [] =
-{
+mframe_t parasite_frames_end_fidget [] = {
{ ai_stand, 0, parasite_scratch },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -116,32 +113,31 @@ mframe_t parasite_frames_end_fidget [] =
};
mmove_t parasite_move_end_fidget = {FRAME_stand28, FRAME_stand35, parasite_frames_end_fidget, parasite_stand};
-void parasite_end_fidget (edict_t *self)
+void parasite_end_fidget(edict_t *self)
{
self->monsterinfo.currentmove = &parasite_move_end_fidget;
}
-void parasite_do_fidget (edict_t *self)
+void parasite_do_fidget(edict_t *self)
{
self->monsterinfo.currentmove = &parasite_move_fidget;
}
-void parasite_refidget (edict_t *self)
-{
+void parasite_refidget(edict_t *self)
+{
if (random() <= 0.8)
self->monsterinfo.currentmove = &parasite_move_fidget;
else
self->monsterinfo.currentmove = &parasite_move_end_fidget;
}
-void parasite_idle (edict_t *self)
-{
+void parasite_idle(edict_t *self)
+{
self->monsterinfo.currentmove = &parasite_move_start_fidget;
}
-mframe_t parasite_frames_stand [] =
-{
+mframe_t parasite_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, parasite_tap },
@@ -162,14 +158,13 @@ mframe_t parasite_frames_stand [] =
};
mmove_t parasite_move_stand = {FRAME_stand01, FRAME_stand17, parasite_frames_stand, parasite_stand};
-void parasite_stand (edict_t *self)
+void parasite_stand(edict_t *self)
{
self->monsterinfo.currentmove = &parasite_move_stand;
}
-mframe_t parasite_frames_run [] =
-{
+mframe_t parasite_frames_run [] = {
{ ai_run, 30, NULL },
{ ai_run, 30, NULL },
{ ai_run, 22, NULL },
@@ -180,15 +175,13 @@ mframe_t parasite_frames_run [] =
};
mmove_t parasite_move_run = {FRAME_run03, FRAME_run09, parasite_frames_run, NULL};
-mframe_t parasite_frames_start_run [] =
-{
+mframe_t parasite_frames_start_run [] = {
{ ai_run, 0, NULL },
{ ai_run, 30, NULL },
};
mmove_t parasite_move_start_run = {FRAME_run01, FRAME_run02, parasite_frames_start_run, parasite_run};
-mframe_t parasite_frames_stop_run [] =
-{
+mframe_t parasite_frames_stop_run [] = {
{ ai_run, 20, NULL },
{ ai_run, 20, NULL },
{ ai_run, 12, NULL },
@@ -198,15 +191,15 @@ mframe_t parasite_frames_stop_run [] =
};
mmove_t parasite_move_stop_run = {FRAME_run10, FRAME_run15, parasite_frames_stop_run, NULL};
-void parasite_start_run (edict_t *self)
-{
+void parasite_start_run(edict_t *self)
+{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &parasite_move_stand;
else
self->monsterinfo.currentmove = &parasite_move_start_run;
}
-void parasite_run (edict_t *self)
+void parasite_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &parasite_move_stand;
@@ -215,8 +208,7 @@ void parasite_run (edict_t *self)
}
-mframe_t parasite_frames_walk [] =
-{
+mframe_t parasite_frames_walk [] = {
{ ai_walk, 30, NULL },
{ ai_walk, 30, NULL },
{ ai_walk, 22, NULL },
@@ -227,15 +219,13 @@ mframe_t parasite_frames_walk [] =
};
mmove_t parasite_move_walk = {FRAME_run03, FRAME_run09, parasite_frames_walk, parasite_walk};
-mframe_t parasite_frames_start_walk [] =
-{
+mframe_t parasite_frames_start_walk [] = {
{ ai_walk, 0, NULL },
{ ai_walk, 30, parasite_walk }
};
mmove_t parasite_move_start_walk = {FRAME_run01, FRAME_run02, parasite_frames_start_walk, NULL};
-mframe_t parasite_frames_stop_walk [] =
-{
+mframe_t parasite_frames_stop_walk [] = {
{ ai_walk, 20, NULL },
{ ai_walk, 20, NULL },
{ ai_walk, 12, NULL },
@@ -245,19 +235,18 @@ mframe_t parasite_frames_stop_walk [] =
};
mmove_t parasite_move_stop_walk = {FRAME_run10, FRAME_run15, parasite_frames_stop_walk, NULL};
-void parasite_start_walk (edict_t *self)
-{
+void parasite_start_walk(edict_t *self)
+{
self->monsterinfo.currentmove = &parasite_move_start_walk;
}
-void parasite_walk (edict_t *self)
+void parasite_walk(edict_t *self)
{
self->monsterinfo.currentmove = &parasite_move_walk;
}
-mframe_t parasite_frames_pain1 [] =
-{
+mframe_t parasite_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -272,7 +261,7 @@ mframe_t parasite_frames_pain1 [] =
};
mmove_t parasite_move_pain1 = {FRAME_pain101, FRAME_pain111, parasite_frames_pain1, parasite_start_run};
-void parasite_pain (edict_t *self, edict_t *other, float kick, int damage)
+void parasite_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
self->s.skinnum = 1;
@@ -286,25 +275,25 @@ void parasite_pain (edict_t *self, edict_t *other, float kick, int damage)
return; // no pain anims in nightmare
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &parasite_move_pain1;
}
-static qboolean parasite_drain_attack_ok (vec3_t start, vec3_t end)
+static qboolean parasite_drain_attack_ok(vec3_t start, vec3_t end)
{
vec3_t dir, angles;
// check for max distance
- VectorSubtract (start, end, dir);
+ VectorSubtract(start, end, dir);
if (VectorLength(dir) > 256)
return qfalse;
// check for min/max pitch
- vectoangles (dir, angles);
+ vectoangles(dir, angles);
if (angles[0] < -180)
angles[0] += 360;
if (fabs(angles[0]) > 30)
@@ -313,58 +302,52 @@ static qboolean parasite_drain_attack_ok (vec3_t start, vec3_t end)
return qtrue;
}
-void parasite_drain_attack (edict_t *self)
+void parasite_drain_attack(edict_t *self)
{
vec3_t offset, start, f, r, end, dir;
trace_t tr;
int damage;
- AngleVectors (self->s.angles, f, r, NULL);
- VectorSet (offset, 24, 0, 6);
- G_ProjectSource (self->s.origin, offset, f, r, start);
+ AngleVectors(self->s.angles, f, r, NULL);
+ VectorSet(offset, 24, 0, 6);
+ G_ProjectSource(self->s.origin, offset, f, r, start);
- VectorCopy (self->enemy->s.origin, end);
- if (!parasite_drain_attack_ok(start, end))
- {
+ VectorCopy(self->enemy->s.origin, end);
+ if (!parasite_drain_attack_ok(start, end)) {
end[2] = self->enemy->s.origin[2] + self->enemy->maxs[2] - 8;
- if (!parasite_drain_attack_ok(start, end))
- {
+ if (!parasite_drain_attack_ok(start, end)) {
end[2] = self->enemy->s.origin[2] + self->enemy->mins[2] + 8;
if (!parasite_drain_attack_ok(start, end))
return;
}
}
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
- tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
+ tr = gi.trace(start, NULL, NULL, end, self, MASK_SHOT);
if (tr.ent != self->enemy)
return;
- if (self->s.frame == FRAME_drain03)
- {
+ if (self->s.frame == FRAME_drain03) {
damage = 5;
- gi.sound (self->enemy, CHAN_AUTO, sound_impact, 1, ATTN_NORM, 0);
- }
- else
- {
+ gi.sound(self->enemy, CHAN_AUTO, sound_impact, 1, ATTN_NORM, 0);
+ } else {
if (self->s.frame == FRAME_drain04)
- gi.sound (self, CHAN_WEAPON, sound_suck, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_suck, 1, ATTN_NORM, 0);
damage = 2;
}
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_PARASITE_ATTACK);
- gi.WriteShort (self - g_edicts);
- gi.WritePosition (start);
- gi.WritePosition (end);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_PARASITE_ATTACK);
+ gi.WriteShort(self - g_edicts);
+ gi.WritePosition(start);
+ gi.WritePosition(end);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
- VectorSubtract (start, end, dir);
- T_Damage (self->enemy, self, self, dir, self->enemy->s.origin, vec3_origin, damage, 0, DAMAGE_NO_KNOCKBACK, MOD_UNKNOWN);
+ VectorSubtract(start, end, dir);
+ T_Damage(self->enemy, self, self, dir, self->enemy->s.origin, vec3_origin, damage, 0, DAMAGE_NO_KNOCKBACK, MOD_UNKNOWN);
}
-mframe_t parasite_frames_drain [] =
-{
+mframe_t parasite_frames_drain [] = {
{ ai_charge, 0, parasite_launch },
{ ai_charge, 0, NULL },
{ ai_charge, 15, parasite_drain_attack }, // Target hits
@@ -387,8 +370,7 @@ mframe_t parasite_frames_drain [] =
mmove_t parasite_move_drain = {FRAME_drain01, FRAME_drain18, parasite_frames_drain, parasite_start_run};
-mframe_t parasite_frames_break [] =
-{
+mframe_t parasite_frames_break [] = {
{ ai_charge, 0, NULL },
{ ai_charge, -3, NULL },
{ ai_charge, 1, NULL },
@@ -417,7 +399,7 @@ mframe_t parasite_frames_break [] =
{ ai_charge, 0, NULL }, // slides
{ ai_charge, 0, NULL }, // slides
{ ai_charge, 4, NULL },
- { ai_charge, 11, NULL },
+ { ai_charge, 11, NULL },
{ ai_charge, -2, NULL },
{ ai_charge, -5, NULL },
{ ai_charge, 1, NULL }
@@ -425,17 +407,17 @@ mframe_t parasite_frames_break [] =
mmove_t parasite_move_break = {FRAME_break01, FRAME_break32, parasite_frames_break, parasite_start_run};
/*
-===
+===
Break Stuff Ends
===
*/
-void parasite_attack (edict_t *self)
+void parasite_attack(edict_t *self)
{
// if (random() <= 0.2)
// self->monsterinfo.currentmove = &parasite_move_break;
// else
- self->monsterinfo.currentmove = &parasite_move_drain;
+ self->monsterinfo.currentmove = &parasite_move_drain;
}
@@ -446,18 +428,17 @@ Death Stuff Starts
===
*/
-void parasite_dead (edict_t *self)
+void parasite_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t parasite_frames_death [] =
-{
+mframe_t parasite_frames_death [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -468,19 +449,18 @@ mframe_t parasite_frames_death [] =
};
mmove_t parasite_move_death = {FRAME_death101, FRAME_death107, parasite_frames_death, parasite_dead};
-void parasite_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void parasite_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 2; n++)
- ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 2; n++)
+ ThrowGib(self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -489,7 +469,7 @@ void parasite_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dam
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->monsterinfo.currentmove = &parasite_move_death;
@@ -503,17 +483,16 @@ End Death Stuff
/*QUAKED monster_parasite (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_parasite (edict_t *self)
+void SP_monster_parasite(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("parasite/parpain1.wav");
- sound_pain2 = gi.soundindex ("parasite/parpain2.wav");
- sound_die = gi.soundindex ("parasite/pardeth1.wav");
+ sound_pain1 = gi.soundindex("parasite/parpain1.wav");
+ sound_pain2 = gi.soundindex("parasite/parpain2.wav");
+ sound_die = gi.soundindex("parasite/pardeth1.wav");
sound_launch = gi.soundindex("parasite/paratck1.wav");
sound_impact = gi.soundindex("parasite/paratck2.wav");
sound_suck = gi.soundindex("parasite/paratck3.wav");
@@ -523,9 +502,9 @@ void SP_monster_parasite (edict_t *self)
sound_scratch = gi.soundindex("parasite/paridle2.wav");
sound_search = gi.soundindex("parasite/parsrch1.wav");
- self->s.modelindex = gi.modelindex ("models/monsters/parasite/tris.md2");
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 24);
+ self->s.modelindex = gi.modelindex("models/monsters/parasite/tris.md2");
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 24);
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
@@ -543,10 +522,10 @@ void SP_monster_parasite (edict_t *self)
self->monsterinfo.sight = parasite_sight;
self->monsterinfo.idle = parasite_idle;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.currentmove = &parasite_move_stand;
+ self->monsterinfo.currentmove = &parasite_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
- walkmonster_start (self);
+ walkmonster_start(self);
}
diff --git a/src/baseq2/m_parasite.h b/src/baseq2/m_parasite.h
index 2410e79..a4a502d 100644
--- a/src/baseq2/m_parasite.h
+++ b/src/baseq2/m_parasite.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_player.h b/src/baseq2/m_player.h
index e1edcd8..14b456b 100644
--- a/src/baseq2/m_player.h
+++ b/src/baseq2/m_player.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_soldier.c b/src/baseq2/m_soldier.c
index dd07a9d..5afdb48 100644
--- a/src/baseq2/m_soldier.c
+++ b/src/baseq2/m_soldier.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -41,27 +41,26 @@ static int sound_death_ss;
static int sound_cock;
-void soldier_idle (edict_t *self)
+void soldier_idle(edict_t *self)
{
if (random() > 0.8)
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
-void soldier_cock (edict_t *self)
+void soldier_cock(edict_t *self)
{
if (self->s.frame == FRAME_stand322)
- gi.sound (self, CHAN_WEAPON, sound_cock, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_WEAPON, sound_cock, 1, ATTN_IDLE, 0);
else
- gi.sound (self, CHAN_WEAPON, sound_cock, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_cock, 1, ATTN_NORM, 0);
}
// STAND
-void soldier_stand (edict_t *self);
+void soldier_stand(edict_t *self);
-mframe_t soldier_frames_stand1 [] =
-{
+mframe_t soldier_frames_stand1 [] = {
{ ai_stand, 0, soldier_idle },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -97,8 +96,7 @@ mframe_t soldier_frames_stand1 [] =
};
mmove_t soldier_move_stand1 = {FRAME_stand101, FRAME_stand130, soldier_frames_stand1, soldier_stand};
-mframe_t soldier_frames_stand3 [] =
-{
+mframe_t soldier_frames_stand3 [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -145,8 +143,7 @@ mframe_t soldier_frames_stand3 [] =
mmove_t soldier_move_stand3 = {FRAME_stand301, FRAME_stand339, soldier_frames_stand3, soldier_stand};
#if 0
-mframe_t soldier_frames_stand4 [] =
-{
+mframe_t soldier_frames_stand4 [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -208,7 +205,7 @@ mframe_t soldier_frames_stand4 [] =
mmove_t soldier_move_stand4 = {FRAME_stand401, FRAME_stand452, soldier_frames_stand4, NULL};
#endif
-void soldier_stand (edict_t *self)
+void soldier_stand(edict_t *self)
{
if ((self->monsterinfo.currentmove == &soldier_move_stand3) || (random() < 0.8))
self->monsterinfo.currentmove = &soldier_move_stand1;
@@ -221,14 +218,13 @@ void soldier_stand (edict_t *self)
// WALK
//
-void soldier_walk1_random (edict_t *self)
+void soldier_walk1_random(edict_t *self)
{
if (random() > 0.1)
self->monsterinfo.nextframe = FRAME_walk101;
}
-mframe_t soldier_frames_walk1 [] =
-{
+mframe_t soldier_frames_walk1 [] = {
{ ai_walk, 3, NULL },
{ ai_walk, 6, NULL },
{ ai_walk, 2, NULL },
@@ -265,8 +261,7 @@ mframe_t soldier_frames_walk1 [] =
};
mmove_t soldier_move_walk1 = {FRAME_walk101, FRAME_walk133, soldier_frames_walk1, NULL};
-mframe_t soldier_frames_walk2 [] =
-{
+mframe_t soldier_frames_walk2 [] = {
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
{ ai_walk, 9, NULL },
@@ -280,7 +275,7 @@ mframe_t soldier_frames_walk2 [] =
};
mmove_t soldier_move_walk2 = {FRAME_walk209, FRAME_walk218, soldier_frames_walk2, NULL};
-void soldier_walk (edict_t *self)
+void soldier_walk(edict_t *self)
{
if (random() < 0.5)
self->monsterinfo.currentmove = &soldier_move_walk1;
@@ -293,17 +288,15 @@ void soldier_walk (edict_t *self)
// RUN
//
-void soldier_run (edict_t *self);
+void soldier_run(edict_t *self);
-mframe_t soldier_frames_start_run [] =
-{
+mframe_t soldier_frames_start_run [] = {
{ ai_run, 7, NULL },
{ ai_run, 5, NULL }
};
mmove_t soldier_move_start_run = {FRAME_run01, FRAME_run02, soldier_frames_start_run, soldier_run};
-mframe_t soldier_frames_run [] =
-{
+mframe_t soldier_frames_run [] = {
{ ai_run, 10, NULL },
{ ai_run, 11, NULL },
{ ai_run, 11, NULL },
@@ -313,22 +306,18 @@ mframe_t soldier_frames_run [] =
};
mmove_t soldier_move_run = {FRAME_run03, FRAME_run08, soldier_frames_run, NULL};
-void soldier_run (edict_t *self)
+void soldier_run(edict_t *self)
{
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
self->monsterinfo.currentmove = &soldier_move_stand1;
return;
}
if (self->monsterinfo.currentmove == &soldier_move_walk1 ||
self->monsterinfo.currentmove == &soldier_move_walk2 ||
- self->monsterinfo.currentmove == &soldier_move_start_run)
- {
+ self->monsterinfo.currentmove == &soldier_move_start_run) {
self->monsterinfo.currentmove = &soldier_move_run;
- }
- else
- {
+ } else {
self->monsterinfo.currentmove = &soldier_move_start_run;
}
}
@@ -338,8 +327,7 @@ void soldier_run (edict_t *self)
// PAIN
//
-mframe_t soldier_frames_pain1 [] =
-{
+mframe_t soldier_frames_pain1 [] = {
{ ai_move, -3, NULL },
{ ai_move, 4, NULL },
{ ai_move, 1, NULL },
@@ -348,8 +336,7 @@ mframe_t soldier_frames_pain1 [] =
};
mmove_t soldier_move_pain1 = {FRAME_pain101, FRAME_pain105, soldier_frames_pain1, soldier_run};
-mframe_t soldier_frames_pain2 [] =
-{
+mframe_t soldier_frames_pain2 [] = {
{ ai_move, -13, NULL },
{ ai_move, -1, NULL },
{ ai_move, 2, NULL },
@@ -360,8 +347,7 @@ mframe_t soldier_frames_pain2 [] =
};
mmove_t soldier_move_pain2 = {FRAME_pain201, FRAME_pain207, soldier_frames_pain2, soldier_run};
-mframe_t soldier_frames_pain3 [] =
-{
+mframe_t soldier_frames_pain3 [] = {
{ ai_move, -8, NULL },
{ ai_move, 10, NULL },
{ ai_move, -4, NULL },
@@ -383,8 +369,7 @@ mframe_t soldier_frames_pain3 [] =
};
mmove_t soldier_move_pain3 = {FRAME_pain301, FRAME_pain318, soldier_frames_pain3, soldier_run};
-mframe_t soldier_frames_pain4 [] =
-{
+mframe_t soldier_frames_pain4 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -406,17 +391,16 @@ mframe_t soldier_frames_pain4 [] =
mmove_t soldier_move_pain4 = {FRAME_pain401, FRAME_pain417, soldier_frames_pain4, soldier_run};
-void soldier_pain (edict_t *self, edict_t *other, float kick, int damage)
+void soldier_pain(edict_t *self, edict_t *other, float kick, int damage)
{
float r;
int n;
if (self->health < (self->max_health / 2))
- self->s.skinnum |= 1;
+ self->s.skinnum |= 1;
- if (level.time < self->pain_debounce_time)
- {
- if ((self->velocity[2] > 100) && ( (self->monsterinfo.currentmove == &soldier_move_pain1) || (self->monsterinfo.currentmove == &soldier_move_pain2) || (self->monsterinfo.currentmove == &soldier_move_pain3)))
+ if (level.time < self->pain_debounce_time) {
+ if ((self->velocity[2] > 100) && ((self->monsterinfo.currentmove == &soldier_move_pain1) || (self->monsterinfo.currentmove == &soldier_move_pain2) || (self->monsterinfo.currentmove == &soldier_move_pain3)))
self->monsterinfo.currentmove = &soldier_move_pain4;
return;
}
@@ -425,14 +409,13 @@ void soldier_pain (edict_t *self, edict_t *other, float kick, int damage)
n = self->s.skinnum | 1;
if (n == 1)
- gi.sound (self, CHAN_VOICE, sound_pain_light, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain_light, 1, ATTN_NORM, 0);
else if (n == 3)
- gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_pain_ss, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain_ss, 1, ATTN_NORM, 0);
- if (self->velocity[2] > 100)
- {
+ if (self->velocity[2] > 100) {
self->monsterinfo.currentmove = &soldier_move_pain4;
return;
}
@@ -459,7 +442,7 @@ static int blaster_flash [] = {MZ2_SOLDIER_BLASTER_1, MZ2_SOLDIER_BLASTER_2, MZ2
static int shotgun_flash [] = {MZ2_SOLDIER_SHOTGUN_1, MZ2_SOLDIER_SHOTGUN_2, MZ2_SOLDIER_SHOTGUN_3, MZ2_SOLDIER_SHOTGUN_4, MZ2_SOLDIER_SHOTGUN_5, MZ2_SOLDIER_SHOTGUN_6, MZ2_SOLDIER_SHOTGUN_7, MZ2_SOLDIER_SHOTGUN_8};
static int machinegun_flash [] = {MZ2_SOLDIER_MACHINEGUN_1, MZ2_SOLDIER_MACHINEGUN_2, MZ2_SOLDIER_MACHINEGUN_3, MZ2_SOLDIER_MACHINEGUN_4, MZ2_SOLDIER_MACHINEGUN_5, MZ2_SOLDIER_MACHINEGUN_6, MZ2_SOLDIER_MACHINEGUN_7, MZ2_SOLDIER_MACHINEGUN_8};
-void soldier_fire (edict_t *self, int flash_number)
+void soldier_fire(edict_t *self, int flash_number)
{
vec3_t start;
vec3_t forward, right, up;
@@ -476,45 +459,37 @@ void soldier_fire (edict_t *self, int flash_number)
else
flash_index = machinegun_flash[flash_number];
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_index], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_index], forward, right, start);
- if (flash_number == 5 || flash_number == 6)
- {
- VectorCopy (forward, aim);
- }
- else
- {
- VectorCopy (self->enemy->s.origin, end);
+ if (flash_number == 5 || flash_number == 6) {
+ VectorCopy(forward, aim);
+ } else {
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, aim);
- vectoangles (aim, dir);
- AngleVectors (dir, forward, right, up);
-
- r = crandom()*1000;
- u = crandom()*500;
- VectorMA (start, 8192, forward, end);
- VectorMA (end, r, right, end);
- VectorMA (end, u, up, end);
-
- VectorSubtract (end, start, aim);
- VectorNormalize (aim);
+ VectorSubtract(end, start, aim);
+ vectoangles(aim, dir);
+ AngleVectors(dir, forward, right, up);
+
+ r = crandom() * 1000;
+ u = crandom() * 500;
+ VectorMA(start, 8192, forward, end);
+ VectorMA(end, r, right, end);
+ VectorMA(end, u, up, end);
+
+ VectorSubtract(end, start, aim);
+ VectorNormalize(aim);
}
- if (self->s.skinnum <= 1)
- {
- monster_fire_blaster (self, start, aim, 5, 600, flash_index, EF_BLASTER);
- }
- else if (self->s.skinnum <= 3)
- {
- monster_fire_shotgun (self, start, aim, 2, 1, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SHOTGUN_COUNT, flash_index);
- }
- else
- {
+ if (self->s.skinnum <= 1) {
+ monster_fire_blaster(self, start, aim, 5, 600, flash_index, EF_BLASTER);
+ } else if (self->s.skinnum <= 3) {
+ monster_fire_shotgun(self, start, aim, 2, 1, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SHOTGUN_COUNT, flash_index);
+ } else {
if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME))
self->monsterinfo.pausetime = level.time + (3 + rand() % 8) * FRAMETIME;
- monster_fire_bullet (self, start, aim, 2, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_index);
+ monster_fire_bullet(self, start, aim, 2, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_index);
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -525,12 +500,12 @@ void soldier_fire (edict_t *self, int flash_number)
// ATTACK1 (blaster/shotgun)
-void soldier_fire1 (edict_t *self)
+void soldier_fire1(edict_t *self)
{
- soldier_fire (self, 0);
+ soldier_fire(self, 0);
}
-void soldier_attack1_refire1 (edict_t *self)
+void soldier_attack1_refire1(edict_t *self)
{
if (self->s.skinnum > 1)
return;
@@ -538,13 +513,13 @@ void soldier_attack1_refire1 (edict_t *self)
if (self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attak102;
else
self->monsterinfo.nextframe = FRAME_attak110;
}
-void soldier_attack1_refire2 (edict_t *self)
+void soldier_attack1_refire2(edict_t *self)
{
if (self->s.skinnum < 2)
return;
@@ -552,12 +527,11 @@ void soldier_attack1_refire2 (edict_t *self)
if (self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attak102;
}
-mframe_t soldier_frames_attack1 [] =
-{
+mframe_t soldier_frames_attack1 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, soldier_fire1 },
@@ -575,12 +549,12 @@ mmove_t soldier_move_attack1 = {FRAME_attak101, FRAME_attak112, soldier_frames_a
// ATTACK2 (blaster/shotgun)
-void soldier_fire2 (edict_t *self)
+void soldier_fire2(edict_t *self)
{
- soldier_fire (self, 1);
+ soldier_fire(self, 1);
}
-void soldier_attack2_refire1 (edict_t *self)
+void soldier_attack2_refire1(edict_t *self)
{
if (self->s.skinnum > 1)
return;
@@ -588,13 +562,13 @@ void soldier_attack2_refire1 (edict_t *self)
if (self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attak204;
else
self->monsterinfo.nextframe = FRAME_attak216;
}
-void soldier_attack2_refire2 (edict_t *self)
+void soldier_attack2_refire2(edict_t *self)
{
if (self->s.skinnum < 2)
return;
@@ -602,12 +576,11 @@ void soldier_attack2_refire2 (edict_t *self)
if (self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attak204;
}
-mframe_t soldier_frames_attack2 [] =
-{
+mframe_t soldier_frames_attack2 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -631,7 +604,7 @@ mmove_t soldier_move_attack2 = {FRAME_attak201, FRAME_attak218, soldier_frames_a
// ATTACK3 (duck and shoot)
-void soldier_duck_down (edict_t *self)
+void soldier_duck_down(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_DUCKED)
return;
@@ -639,31 +612,30 @@ void soldier_duck_down (edict_t *self)
self->maxs[2] -= 32;
self->takedamage = DAMAGE_YES;
self->monsterinfo.pausetime = level.time + 1;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void soldier_duck_up (edict_t *self)
+void soldier_duck_up(edict_t *self)
{
self->monsterinfo.aiflags &= ~AI_DUCKED;
self->maxs[2] += 32;
self->takedamage = DAMAGE_AIM;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void soldier_fire3 (edict_t *self)
+void soldier_fire3(edict_t *self)
{
- soldier_duck_down (self);
- soldier_fire (self, 2);
+ soldier_duck_down(self);
+ soldier_fire(self, 2);
}
-void soldier_attack3_refire (edict_t *self)
+void soldier_attack3_refire(edict_t *self)
{
if ((level.time + 0.4) < self->monsterinfo.pausetime)
self->monsterinfo.nextframe = FRAME_attak303;
}
-mframe_t soldier_frames_attack3 [] =
-{
+mframe_t soldier_frames_attack3 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, soldier_fire3 },
@@ -678,9 +650,9 @@ mmove_t soldier_move_attack3 = {FRAME_attak301, FRAME_attak309, soldier_frames_a
// ATTACK4 (machinegun)
-void soldier_fire4 (edict_t *self)
+void soldier_fire4(edict_t *self)
{
- soldier_fire (self, 3);
+ soldier_fire(self, 3);
//
// if (self->enemy->health <= 0)
// return;
@@ -689,8 +661,7 @@ void soldier_fire4 (edict_t *self)
// self->monsterinfo.nextframe = FRAME_attak402;
}
-mframe_t soldier_frames_attack4 [] =
-{
+mframe_t soldier_frames_attack4 [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, soldier_fire4 },
@@ -703,22 +674,21 @@ mmove_t soldier_move_attack4 = {FRAME_attak401, FRAME_attak406, soldier_frames_a
#if 0
// ATTACK5 (prone)
-void soldier_fire5 (edict_t *self)
+void soldier_fire5(edict_t *self)
{
- soldier_fire (self, 4);
+ soldier_fire(self, 4);
}
-void soldier_attack5_refire (edict_t *self)
+void soldier_attack5_refire(edict_t *self)
{
if (self->enemy->health <= 0)
return;
- if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
+ if (((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE))
self->monsterinfo.nextframe = FRAME_attak505;
}
-mframe_t soldier_frames_attack5 [] =
-{
+mframe_t soldier_frames_attack5 [] = {
{ ai_charge, 8, NULL },
{ ai_charge, 8, NULL },
{ ai_charge, 0, NULL },
@@ -733,12 +703,12 @@ mmove_t soldier_move_attack5 = {FRAME_attak501, FRAME_attak508, soldier_frames_a
// ATTACK6 (run & shoot)
-void soldier_fire8 (edict_t *self)
+void soldier_fire8(edict_t *self)
{
- soldier_fire (self, 7);
+ soldier_fire(self, 7);
}
-void soldier_attack6_refire (edict_t *self)
+void soldier_attack6_refire(edict_t *self)
{
if (self->enemy->health <= 0)
return;
@@ -750,8 +720,7 @@ void soldier_attack6_refire (edict_t *self)
self->monsterinfo.nextframe = FRAME_runs03;
}
-mframe_t soldier_frames_attack6 [] =
-{
+mframe_t soldier_frames_attack6 [] = {
{ ai_charge, 10, NULL },
{ ai_charge, 4, NULL },
{ ai_charge, 12, NULL },
@@ -771,15 +740,12 @@ mmove_t soldier_move_attack6 = {FRAME_runs01, FRAME_runs14, soldier_frames_attac
void soldier_attack(edict_t *self)
{
- if (self->s.skinnum < 4)
- {
+ if (self->s.skinnum < 4) {
if (random() < 0.5)
self->monsterinfo.currentmove = &soldier_move_attack1;
else
self->monsterinfo.currentmove = &soldier_move_attack2;
- }
- else
- {
+ } else {
self->monsterinfo.currentmove = &soldier_move_attack4;
}
}
@@ -792,12 +758,11 @@ void soldier_attack(edict_t *self)
void soldier_sight(edict_t *self, edict_t *other)
{
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_sight1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_sight2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight2, 1, ATTN_NORM, 0);
- if ((skill->value > 0) && (range(self, self->enemy) >= RANGE_MID))
- {
+ if ((skill->value > 0) && (range(self, self->enemy) >= RANGE_MID)) {
if (random() > 0.5)
self->monsterinfo.currentmove = &soldier_move_attack6;
}
@@ -807,7 +772,7 @@ void soldier_sight(edict_t *self, edict_t *other)
// DUCK
//
-void soldier_duck_hold (edict_t *self)
+void soldier_duck_hold(edict_t *self)
{
if (level.time >= self->monsterinfo.pausetime)
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
@@ -815,8 +780,7 @@ void soldier_duck_hold (edict_t *self)
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
}
-mframe_t soldier_frames_duck [] =
-{
+mframe_t soldier_frames_duck [] = {
{ ai_move, 5, soldier_duck_down },
{ ai_move, -1, soldier_duck_hold },
{ ai_move, 1, NULL },
@@ -825,7 +789,7 @@ mframe_t soldier_frames_duck [] =
};
mmove_t soldier_move_duck = {FRAME_duck01, FRAME_duck05, soldier_frames_duck, soldier_run};
-void soldier_dodge (edict_t *self, edict_t *attacker, float eta)
+void soldier_dodge(edict_t *self, edict_t *attacker, float eta)
{
float r;
@@ -836,8 +800,7 @@ void soldier_dodge (edict_t *self, edict_t *attacker, float eta)
if (!self->enemy)
self->enemy = attacker;
- if (skill->value == 0)
- {
+ if (skill->value == 0) {
self->monsterinfo.currentmove = &soldier_move_duck;
return;
}
@@ -845,8 +808,7 @@ void soldier_dodge (edict_t *self, edict_t *attacker, float eta)
self->monsterinfo.pausetime = level.time + eta + 0.3;
r = random();
- if (skill->value == 1)
- {
+ if (skill->value == 1) {
if (r > 0.33)
self->monsterinfo.currentmove = &soldier_move_duck;
else
@@ -854,8 +816,7 @@ void soldier_dodge (edict_t *self, edict_t *attacker, float eta)
return;
}
- if (skill->value >= 2)
- {
+ if (skill->value >= 2) {
if (r > 0.66)
self->monsterinfo.currentmove = &soldier_move_duck;
else
@@ -871,28 +832,27 @@ void soldier_dodge (edict_t *self, edict_t *attacker, float eta)
// DEATH
//
-void soldier_fire6 (edict_t *self)
+void soldier_fire6(edict_t *self)
{
- soldier_fire (self, 5);
+ soldier_fire(self, 5);
}
-void soldier_fire7 (edict_t *self)
+void soldier_fire7(edict_t *self)
{
- soldier_fire (self, 6);
+ soldier_fire(self, 6);
}
-void soldier_dead (edict_t *self)
+void soldier_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, -8);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, -8);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t soldier_frames_death1 [] =
-{
+mframe_t soldier_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, -10, NULL },
{ ai_move, -10, NULL },
@@ -935,8 +895,7 @@ mframe_t soldier_frames_death1 [] =
};
mmove_t soldier_move_death1 = {FRAME_death101, FRAME_death136, soldier_frames_death1, soldier_dead};
-mframe_t soldier_frames_death2 [] =
-{
+mframe_t soldier_frames_death2 [] = {
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
@@ -978,8 +937,7 @@ mframe_t soldier_frames_death2 [] =
};
mmove_t soldier_move_death2 = {FRAME_death201, FRAME_death235, soldier_frames_death2, soldier_dead};
-mframe_t soldier_frames_death3 [] =
-{
+mframe_t soldier_frames_death3 [] = {
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
@@ -1032,8 +990,7 @@ mframe_t soldier_frames_death3 [] =
};
mmove_t soldier_move_death3 = {FRAME_death301, FRAME_death345, soldier_frames_death3, soldier_dead};
-mframe_t soldier_frames_death4 [] =
-{
+mframe_t soldier_frames_death4 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -1095,8 +1052,7 @@ mframe_t soldier_frames_death4 [] =
};
mmove_t soldier_move_death4 = {FRAME_death401, FRAME_death453, soldier_frames_death4, soldier_dead};
-mframe_t soldier_frames_death5 [] =
-{
+mframe_t soldier_frames_death5 [] = {
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
{ ai_move, -5, NULL },
@@ -1126,8 +1082,7 @@ mframe_t soldier_frames_death5 [] =
};
mmove_t soldier_move_death5 = {FRAME_death501, FRAME_death524, soldier_frames_death5, soldier_dead};
-mframe_t soldier_frames_death6 [] =
-{
+mframe_t soldier_frames_death6 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -1141,18 +1096,17 @@ mframe_t soldier_frames_death6 [] =
};
mmove_t soldier_move_death6 = {FRAME_death601, FRAME_death610, soldier_frames_death6, soldier_dead};
-void soldier_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void soldier_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 3; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowGib (self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 3; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowGib(self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -1166,14 +1120,13 @@ void soldier_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
self->s.skinnum |= 1;
if (self->s.skinnum == 1)
- gi.sound (self, CHAN_VOICE, sound_death_light, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death_light, 1, ATTN_NORM, 0);
else if (self->s.skinnum == 3)
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
else // (self->s.skinnum == 5)
- gi.sound (self, CHAN_VOICE, sound_death_ss, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death_ss, 1, ATTN_NORM, 0);
- if (fabs((self->s.origin[2] + self->viewheight) - point[2]) <= 4)
- {
+ if (fabs((self->s.origin[2] + self->viewheight) - point[2]) <= 4) {
// head shot
self->monsterinfo.currentmove = &soldier_move_death3;
return;
@@ -1197,20 +1150,20 @@ void soldier_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int dama
// SPAWN
//
-void SP_monster_soldier_x (edict_t *self)
+void SP_monster_soldier_x(edict_t *self)
{
- self->s.modelindex = gi.modelindex ("models/monsters/soldier/tris.md2");
+ self->s.modelindex = gi.modelindex("models/monsters/soldier/tris.md2");
self->monsterinfo.scale = MODEL_SCALE;
- VectorSet (self->mins, -16, -16, -24);
- VectorSet (self->maxs, 16, 16, 32);
+ VectorSet(self->mins, -16, -16, -24);
+ VectorSet(self->maxs, 16, 16, 32);
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- sound_idle = gi.soundindex ("soldier/solidle1.wav");
- sound_sight1 = gi.soundindex ("soldier/solsght1.wav");
- sound_sight2 = gi.soundindex ("soldier/solsrch1.wav");
- sound_cock = gi.soundindex ("infantry/infatck3.wav");
+ sound_idle = gi.soundindex("soldier/solidle1.wav");
+ sound_sight1 = gi.soundindex("soldier/solsght1.wav");
+ sound_sight2 = gi.soundindex("soldier/solsrch1.wav");
+ sound_cock = gi.soundindex("infantry/infatck3.wav");
self->mass = 100;
@@ -1225,31 +1178,30 @@ void SP_monster_soldier_x (edict_t *self)
self->monsterinfo.melee = NULL;
self->monsterinfo.sight = soldier_sight;
- gi.linkentity (self);
+ gi.linkentity(self);
- self->monsterinfo.stand (self);
+ self->monsterinfo.stand(self);
- walkmonster_start (self);
+ walkmonster_start(self);
}
/*QUAKED monster_soldier_light (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_soldier_light (edict_t *self)
+void SP_monster_soldier_light(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- SP_monster_soldier_x (self);
+ SP_monster_soldier_x(self);
- sound_pain_light = gi.soundindex ("soldier/solpain2.wav");
- sound_death_light = gi.soundindex ("soldier/soldeth2.wav");
- gi.modelindex ("models/objects/laser/tris.md2");
- gi.soundindex ("misc/lasfly.wav");
- gi.soundindex ("soldier/solatck2.wav");
+ sound_pain_light = gi.soundindex("soldier/solpain2.wav");
+ sound_death_light = gi.soundindex("soldier/soldeth2.wav");
+ gi.modelindex("models/objects/laser/tris.md2");
+ gi.soundindex("misc/lasfly.wav");
+ gi.soundindex("soldier/solatck2.wav");
self->s.skinnum = 0;
self->health = 20;
@@ -1258,19 +1210,18 @@ void SP_monster_soldier_light (edict_t *self)
/*QUAKED monster_soldier (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_soldier (edict_t *self)
+void SP_monster_soldier(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- SP_monster_soldier_x (self);
+ SP_monster_soldier_x(self);
- sound_pain = gi.soundindex ("soldier/solpain1.wav");
- sound_death = gi.soundindex ("soldier/soldeth1.wav");
- gi.soundindex ("soldier/solatck1.wav");
+ sound_pain = gi.soundindex("soldier/solpain1.wav");
+ sound_death = gi.soundindex("soldier/soldeth1.wav");
+ gi.soundindex("soldier/solatck1.wav");
self->s.skinnum = 2;
self->health = 30;
@@ -1279,19 +1230,18 @@ void SP_monster_soldier (edict_t *self)
/*QUAKED monster_soldier_ss (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
*/
-void SP_monster_soldier_ss (edict_t *self)
+void SP_monster_soldier_ss(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- SP_monster_soldier_x (self);
+ SP_monster_soldier_x(self);
- sound_pain_ss = gi.soundindex ("soldier/solpain3.wav");
- sound_death_ss = gi.soundindex ("soldier/soldeth3.wav");
- gi.soundindex ("soldier/solatck3.wav");
+ sound_pain_ss = gi.soundindex("soldier/solpain3.wav");
+ sound_death_ss = gi.soundindex("soldier/soldeth3.wav");
+ gi.soundindex("soldier/solatck3.wav");
self->s.skinnum = 4;
self->health = 40;
diff --git a/src/baseq2/m_soldier.h b/src/baseq2/m_soldier.h
index 020ec94..097f532 100644
--- a/src/baseq2/m_soldier.h
+++ b/src/baseq2/m_soldier.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_supertank.c b/src/baseq2/m_supertank.c
index d67b05e..66aca4c 100644
--- a/src/baseq2/m_supertank.c
+++ b/src/baseq2/m_supertank.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ SUPERTANK
#include "g_local.h"
#include "m_supertank.h"
-qboolean visible (edict_t *self, edict_t *other);
+qboolean visible(edict_t *self, edict_t *other);
static int sound_pain1;
static int sound_pain2;
@@ -39,25 +39,25 @@ static int sound_search2;
static int tread_sound;
-void BossExplode (edict_t *self);
+void BossExplode(edict_t *self);
-void TreadSound (edict_t *self)
+void TreadSound(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, tread_sound, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, tread_sound, 1, ATTN_NORM, 0);
}
-void supertank_search (edict_t *self)
+void supertank_search(edict_t *self)
{
if (random() < 0.5)
- gi.sound (self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search1, 1, ATTN_NORM, 0);
else
- gi.sound (self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_search2, 1, ATTN_NORM, 0);
}
-void supertank_dead (edict_t *self);
-void supertankRocket (edict_t *self);
-void supertankMachineGun (edict_t *self);
+void supertank_dead(edict_t *self);
+void supertankRocket(edict_t *self);
+void supertankMachineGun(edict_t *self);
void supertank_reattack1(edict_t *self);
@@ -65,8 +65,7 @@ void supertank_reattack1(edict_t *self);
// stand
//
-mframe_t supertank_frames_stand []=
-{
+mframe_t supertank_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -129,15 +128,14 @@ mframe_t supertank_frames_stand []=
{ ai_stand, 0, NULL }
};
mmove_t supertank_move_stand = {FRAME_stand_1, FRAME_stand_60, supertank_frames_stand, NULL};
-
-void supertank_stand (edict_t *self)
+
+void supertank_stand(edict_t *self)
{
self->monsterinfo.currentmove = &supertank_move_stand;
}
-mframe_t supertank_frames_run [] =
-{
+mframe_t supertank_frames_run [] = {
{ ai_run, 12, TreadSound },
{ ai_run, 12, NULL },
{ ai_run, 12, NULL },
@@ -164,8 +162,7 @@ mmove_t supertank_move_run = {FRAME_forwrd_1, FRAME_forwrd_18, supertank_frames_
//
-mframe_t supertank_frames_forward [] =
-{
+mframe_t supertank_frames_forward [] = {
{ ai_walk, 4, TreadSound },
{ ai_walk, 4, NULL },
{ ai_walk, 4, NULL },
@@ -187,17 +184,17 @@ mframe_t supertank_frames_forward [] =
};
mmove_t supertank_move_forward = {FRAME_forwrd_1, FRAME_forwrd_18, supertank_frames_forward, NULL};
-void supertank_forward (edict_t *self)
+void supertank_forward(edict_t *self)
{
- self->monsterinfo.currentmove = &supertank_move_forward;
+ self->monsterinfo.currentmove = &supertank_move_forward;
}
-void supertank_walk (edict_t *self)
+void supertank_walk(edict_t *self)
{
- self->monsterinfo.currentmove = &supertank_move_forward;
+ self->monsterinfo.currentmove = &supertank_move_forward;
}
-void supertank_run (edict_t *self)
+void supertank_run(edict_t *self)
{
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
self->monsterinfo.currentmove = &supertank_move_stand;
@@ -205,8 +202,7 @@ void supertank_run (edict_t *self)
self->monsterinfo.currentmove = &supertank_move_run;
}
-mframe_t supertank_frames_turn_right [] =
-{
+mframe_t supertank_frames_turn_right [] = {
{ ai_move, 0, TreadSound },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -228,8 +224,7 @@ mframe_t supertank_frames_turn_right [] =
};
mmove_t supertank_move_turn_right = {FRAME_right_1, FRAME_right_18, supertank_frames_turn_right, supertank_run};
-mframe_t supertank_frames_turn_left [] =
-{
+mframe_t supertank_frames_turn_left [] = {
{ ai_move, 0, TreadSound },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -252,8 +247,7 @@ mframe_t supertank_frames_turn_left [] =
mmove_t supertank_move_turn_left = {FRAME_left_1, FRAME_left_18, supertank_frames_turn_left, supertank_run};
-mframe_t supertank_frames_pain3 [] =
-{
+mframe_t supertank_frames_pain3 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -261,8 +255,7 @@ mframe_t supertank_frames_pain3 [] =
};
mmove_t supertank_move_pain3 = {FRAME_pain3_9, FRAME_pain3_12, supertank_frames_pain3, supertank_run};
-mframe_t supertank_frames_pain2 [] =
-{
+mframe_t supertank_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -270,8 +263,7 @@ mframe_t supertank_frames_pain2 [] =
};
mmove_t supertank_move_pain2 = {FRAME_pain2_5, FRAME_pain2_8, supertank_frames_pain2, supertank_run};
-mframe_t supertank_frames_pain1 [] =
-{
+mframe_t supertank_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -279,8 +271,7 @@ mframe_t supertank_frames_pain1 [] =
};
mmove_t supertank_move_pain1 = {FRAME_pain1_1, FRAME_pain1_4, supertank_frames_pain1, supertank_run};
-mframe_t supertank_frames_death1 [] =
-{
+mframe_t supertank_frames_death1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -308,8 +299,7 @@ mframe_t supertank_frames_death1 [] =
};
mmove_t supertank_move_death = {FRAME_death_1, FRAME_death_24, supertank_frames_death1, supertank_dead};
-mframe_t supertank_frames_backward[] =
-{
+mframe_t supertank_frames_backward[] = {
{ ai_walk, 0, TreadSound },
{ ai_walk, 0, NULL },
{ ai_walk, 0, NULL },
@@ -331,8 +321,7 @@ mframe_t supertank_frames_backward[] =
};
mmove_t supertank_move_backward = {FRAME_backwd_1, FRAME_backwd_18, supertank_frames_backward, NULL};
-mframe_t supertank_frames_attack4[]=
-{
+mframe_t supertank_frames_attack4[] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -342,8 +331,7 @@ mframe_t supertank_frames_attack4[]=
};
mmove_t supertank_move_attack4 = {FRAME_attak4_1, FRAME_attak4_6, supertank_frames_attack4, supertank_run};
-mframe_t supertank_frames_attack3[]=
-{
+mframe_t supertank_frames_attack3[] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -374,8 +362,7 @@ mframe_t supertank_frames_attack3[]=
};
mmove_t supertank_move_attack3 = {FRAME_attak3_1, FRAME_attak3_27, supertank_frames_attack3, supertank_run};
-mframe_t supertank_frames_attack2[]=
-{
+mframe_t supertank_frames_attack2[] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -406,8 +393,7 @@ mframe_t supertank_frames_attack2[]=
};
mmove_t supertank_move_attack2 = {FRAME_attak2_1, FRAME_attak2_27, supertank_frames_attack2, supertank_run};
-mframe_t supertank_frames_attack1[]=
-{
+mframe_t supertank_frames_attack1[] = {
{ ai_charge, 0, supertankMachineGun },
{ ai_charge, 0, supertankMachineGun },
{ ai_charge, 0, supertankMachineGun },
@@ -418,8 +404,7 @@ mframe_t supertank_frames_attack1[]=
};
mmove_t supertank_move_attack1 = {FRAME_attak1_1, FRAME_attak1_6, supertank_frames_attack1, supertank_reattack1};
-mframe_t supertank_frames_end_attack1[]=
-{
+mframe_t supertank_frames_end_attack1[] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -444,28 +429,28 @@ void supertank_reattack1(edict_t *self)
if (random() < 0.9)
self->monsterinfo.currentmove = &supertank_move_attack1;
else
- self->monsterinfo.currentmove = &supertank_move_end_attack1;
+ self->monsterinfo.currentmove = &supertank_move_end_attack1;
else
self->monsterinfo.currentmove = &supertank_move_end_attack1;
}
-void supertank_pain (edict_t *self, edict_t *other, float kick, int damage)
+void supertank_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
- self->s.skinnum = 1;
+ self->s.skinnum = 1;
if (level.time < self->pain_debounce_time)
- return;
+ return;
// Lessen the chance of him going into his pain frames
- if (damage <=25)
- if (random()<0.2)
+ if (damage <= 25)
+ if (random() < 0.2)
return;
// Don't go into pain if he's firing his rockets
if (skill->value >= 2)
- if ( (self->s.frame >= FRAME_attak2_1) && (self->s.frame <= FRAME_attak2_14) )
+ if ((self->s.frame >= FRAME_attak2_1) && (self->s.frame <= FRAME_attak2_14))
return;
self->pain_debounce_time = level.time + 3;
@@ -473,25 +458,20 @@ void supertank_pain (edict_t *self, edict_t *other, float kick, int damage)
if (skill->value == 3)
return; // no pain anims in nightmare
- if (damage <= 10)
- {
- gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM,0);
+ if (damage <= 10) {
+ gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &supertank_move_pain1;
- }
- else if (damage <= 25)
- {
- gi.sound (self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM,0);
+ } else if (damage <= 25) {
+ gi.sound(self, CHAN_VOICE, sound_pain3, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &supertank_move_pain2;
- }
- else
- {
- gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM,0);
+ } else {
+ gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
self->monsterinfo.currentmove = &supertank_move_pain3;
}
};
-void supertankRocket (edict_t *self)
+void supertankRocket(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
@@ -506,18 +486,18 @@ void supertankRocket (edict_t *self)
else // (self->s.frame == FRAME_attak2_14)
flash_number = MZ2_SUPERTANK_ROCKET_3;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
- monster_fire_rocket (self, start, dir, 50, 500, flash_number);
-}
+ monster_fire_rocket(self, start, dir, 50, 500, flash_number);
+}
-void supertankMachineGun (edict_t *self)
+void supertankMachineGun(edict_t *self)
{
vec3_t dir;
vec3_t vec;
@@ -532,20 +512,19 @@ void supertankMachineGun (edict_t *self)
dir[1] = self->s.angles[1];
dir[2] = 0;
- AngleVectors (dir, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(dir, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- if (self->enemy)
- {
- VectorCopy (self->enemy->s.origin, vec);
- VectorMA (vec, 0, self->enemy->velocity, vec);
+ if (self->enemy) {
+ VectorCopy(self->enemy->s.origin, vec);
+ VectorMA(vec, 0, self->enemy->velocity, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, forward);
- VectorNormalize (forward);
- }
+ VectorSubtract(vec, start, forward);
+ VectorNormalize(forward);
+ }
- monster_fire_bullet (self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
-}
+ monster_fire_bullet(self, start, forward, 6, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
+}
void supertank_attack(edict_t *self)
@@ -554,20 +533,18 @@ void supertank_attack(edict_t *self)
float range;
//float r;
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
- range = VectorLength (vec);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
+ range = VectorLength(vec);
//r = random();
// Attack 1 == Chaingun
// Attack 2 == Rocket Launcher
- if (range <= 160)
- {
+ if (range <= 160) {
self->monsterinfo.currentmove = &supertank_move_attack1;
- }
- else
- { // fire rockets more often at distance
+ } else {
+ // fire rockets more often at distance
if (random() < 0.3)
self->monsterinfo.currentmove = &supertank_move_attack1;
else
@@ -580,27 +557,26 @@ void supertank_attack(edict_t *self)
// death
//
-void supertank_dead (edict_t *self)
+void supertank_dead(edict_t *self)
{
- VectorSet (self->mins, -60, -60, 0);
- VectorSet (self->maxs, 60, 60, 72);
+ VectorSet(self->mins, -60, -60, 0);
+ VectorSet(self->maxs, 60, 60, 72);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-void BossExplode (edict_t *self)
+void BossExplode(edict_t *self)
{
vec3_t org;
int n;
self->think = BossExplode;
- VectorCopy (self->s.origin, org);
- org[2] += 24 + (rand()&15);
- switch (self->count++)
- {
+ VectorCopy(self->s.origin, org);
+ org[2] += 24 + (rand() & 15);
+ switch (self->count++) {
case 0:
org[0] -= 24;
org[1] -= 24;
@@ -635,28 +611,28 @@ void BossExplode (edict_t *self)
break;
case 8:
self->s.sound = 0;
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", 500, GIB_ORGANIC);
- for (n= 0; n < 8; n++)
- ThrowGib (self, "models/objects/gibs/sm_metal/tris.md2", 500, GIB_METALLIC);
- ThrowGib (self, "models/objects/gibs/chest/tris.md2", 500, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/gear/tris.md2", 500, GIB_METALLIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", 500, GIB_ORGANIC);
+ for (n = 0; n < 8; n++)
+ ThrowGib(self, "models/objects/gibs/sm_metal/tris.md2", 500, GIB_METALLIC);
+ ThrowGib(self, "models/objects/gibs/chest/tris.md2", 500, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/gear/tris.md2", 500, GIB_METALLIC);
self->deadflag = DEAD_DEAD;
return;
}
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_EXPLOSION1);
- gi.WritePosition (org);
- gi.multicast (self->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_EXPLOSION1);
+ gi.WritePosition(org);
+ gi.multicast(self->s.origin, MULTICAST_PVS);
self->nextthink = level.time + 0.1;
}
-void supertank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void supertank_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
- gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_NO;
self->count = 0;
@@ -669,29 +645,28 @@ void supertank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int da
/*QUAKED monster_supertank (1 .5 0) (-64 -64 0) (64 64 72) Ambush Trigger_Spawn Sight
*/
-void SP_monster_supertank (edict_t *self)
+void SP_monster_supertank(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- sound_pain1 = gi.soundindex ("bosstank/btkpain1.wav");
- sound_pain2 = gi.soundindex ("bosstank/btkpain2.wav");
- sound_pain3 = gi.soundindex ("bosstank/btkpain3.wav");
- sound_death = gi.soundindex ("bosstank/btkdeth1.wav");
- sound_search1 = gi.soundindex ("bosstank/btkunqv1.wav");
- sound_search2 = gi.soundindex ("bosstank/btkunqv2.wav");
+ sound_pain1 = gi.soundindex("bosstank/btkpain1.wav");
+ sound_pain2 = gi.soundindex("bosstank/btkpain2.wav");
+ sound_pain3 = gi.soundindex("bosstank/btkpain3.wav");
+ sound_death = gi.soundindex("bosstank/btkdeth1.wav");
+ sound_search1 = gi.soundindex("bosstank/btkunqv1.wav");
+ sound_search2 = gi.soundindex("bosstank/btkunqv2.wav");
// self->s.sound = gi.soundindex ("bosstank/btkengn1.wav");
- tread_sound = gi.soundindex ("bosstank/btkengn1.wav");
+ tread_sound = gi.soundindex("bosstank/btkengn1.wav");
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- self->s.modelindex = gi.modelindex ("models/monsters/boss1/tris.md2");
- VectorSet (self->mins, -64, -64, 0);
- VectorSet (self->maxs, 64, 64, 112);
+ self->s.modelindex = gi.modelindex("models/monsters/boss1/tris.md2");
+ VectorSet(self->mins, -64, -64, 0);
+ VectorSet(self->maxs, 64, 64, 112);
self->health = 1500;
self->gib_health = -500;
@@ -708,8 +683,8 @@ void SP_monster_supertank (edict_t *self)
self->monsterinfo.melee = NULL;
self->monsterinfo.sight = NULL;
- gi.linkentity (self);
-
+ gi.linkentity(self);
+
self->monsterinfo.currentmove = &supertank_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
diff --git a/src/baseq2/m_supertank.h b/src/baseq2/m_supertank.h
index 2e7d629..e24b3d1 100644
--- a/src/baseq2/m_supertank.h
+++ b/src/baseq2/m_supertank.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/m_tank.c b/src/baseq2/m_tank.c
index 6f43d60..86847d8 100644
--- a/src/baseq2/m_tank.c
+++ b/src/baseq2/m_tank.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,9 +29,9 @@ TANK
#include "m_tank.h"
-void tank_refire_rocket (edict_t *self);
-void tank_doattack_rocket (edict_t *self);
-void tank_reattack_blaster (edict_t *self);
+void tank_refire_rocket(edict_t *self);
+void tank_doattack_rocket(edict_t *self);
+void tank_reattack_blaster(edict_t *self);
static int sound_thud;
static int sound_pain;
@@ -46,30 +46,30 @@ static int sound_strike;
// misc
//
-void tank_sight (edict_t *self, edict_t *other)
+void tank_sight(edict_t *self, edict_t *other)
{
- gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
}
-void tank_footstep (edict_t *self)
+void tank_footstep(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_step, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, sound_step, 1, ATTN_NORM, 0);
}
-void tank_thud (edict_t *self)
+void tank_thud(edict_t *self)
{
- gi.sound (self, CHAN_BODY, sound_thud, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_BODY, sound_thud, 1, ATTN_NORM, 0);
}
-void tank_windup (edict_t *self)
+void tank_windup(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_windup, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_WEAPON, sound_windup, 1, ATTN_NORM, 0);
}
-void tank_idle (edict_t *self)
+void tank_idle(edict_t *self)
{
- gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
+ gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
}
@@ -77,8 +77,7 @@ void tank_idle (edict_t *self)
// stand
//
-mframe_t tank_frames_stand []=
-{
+mframe_t tank_frames_stand [] = {
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
{ ai_stand, 0, NULL },
@@ -111,8 +110,8 @@ mframe_t tank_frames_stand []=
{ ai_stand, 0, NULL }
};
mmove_t tank_move_stand = {FRAME_stand01, FRAME_stand30, tank_frames_stand, NULL};
-
-void tank_stand (edict_t *self)
+
+void tank_stand(edict_t *self)
{
self->monsterinfo.currentmove = &tank_move_stand;
}
@@ -122,10 +121,9 @@ void tank_stand (edict_t *self)
// walk
//
-void tank_walk (edict_t *self);
+void tank_walk(edict_t *self);
-mframe_t tank_frames_start_walk [] =
-{
+mframe_t tank_frames_start_walk [] = {
{ ai_walk, 0, NULL },
{ ai_walk, 6, NULL },
{ ai_walk, 6, NULL },
@@ -133,8 +131,7 @@ mframe_t tank_frames_start_walk [] =
};
mmove_t tank_move_start_walk = {FRAME_walk01, FRAME_walk04, tank_frames_start_walk, tank_walk};
-mframe_t tank_frames_walk [] =
-{
+mframe_t tank_frames_walk [] = {
{ ai_walk, 4, NULL },
{ ai_walk, 5, NULL },
{ ai_walk, 3, NULL },
@@ -154,8 +151,7 @@ mframe_t tank_frames_walk [] =
};
mmove_t tank_move_walk = {FRAME_walk05, FRAME_walk20, tank_frames_walk, NULL};
-mframe_t tank_frames_stop_walk [] =
-{
+mframe_t tank_frames_stop_walk [] = {
{ ai_walk, 3, NULL },
{ ai_walk, 3, NULL },
{ ai_walk, 2, NULL },
@@ -164,9 +160,9 @@ mframe_t tank_frames_stop_walk [] =
};
mmove_t tank_move_stop_walk = {FRAME_walk21, FRAME_walk25, tank_frames_stop_walk, tank_stand};
-void tank_walk (edict_t *self)
+void tank_walk(edict_t *self)
{
- self->monsterinfo.currentmove = &tank_move_walk;
+ self->monsterinfo.currentmove = &tank_move_walk;
}
@@ -174,10 +170,9 @@ void tank_walk (edict_t *self)
// run
//
-void tank_run (edict_t *self);
+void tank_run(edict_t *self);
-mframe_t tank_frames_start_run [] =
-{
+mframe_t tank_frames_start_run [] = {
{ ai_run, 0, NULL },
{ ai_run, 6, NULL },
{ ai_run, 6, NULL },
@@ -185,8 +180,7 @@ mframe_t tank_frames_start_run [] =
};
mmove_t tank_move_start_run = {FRAME_walk01, FRAME_walk04, tank_frames_start_run, tank_run};
-mframe_t tank_frames_run [] =
-{
+mframe_t tank_frames_run [] = {
{ ai_run, 4, NULL },
{ ai_run, 5, NULL },
{ ai_run, 3, NULL },
@@ -206,8 +200,7 @@ mframe_t tank_frames_run [] =
};
mmove_t tank_move_run = {FRAME_walk05, FRAME_walk20, tank_frames_run, NULL};
-mframe_t tank_frames_stop_run [] =
-{
+mframe_t tank_frames_stop_run [] = {
{ ai_run, 3, NULL },
{ ai_run, 3, NULL },
{ ai_run, 2, NULL },
@@ -216,26 +209,22 @@ mframe_t tank_frames_stop_run [] =
};
mmove_t tank_move_stop_run = {FRAME_walk21, FRAME_walk25, tank_frames_stop_run, tank_walk};
-void tank_run (edict_t *self)
+void tank_run(edict_t *self)
{
if (self->enemy && self->enemy->client)
self->monsterinfo.aiflags |= AI_BRUTAL;
else
self->monsterinfo.aiflags &= ~AI_BRUTAL;
- if (self->monsterinfo.aiflags & AI_STAND_GROUND)
- {
+ if (self->monsterinfo.aiflags & AI_STAND_GROUND) {
self->monsterinfo.currentmove = &tank_move_stand;
return;
}
if (self->monsterinfo.currentmove == &tank_move_walk ||
- self->monsterinfo.currentmove == &tank_move_start_run)
- {
+ self->monsterinfo.currentmove == &tank_move_start_run) {
self->monsterinfo.currentmove = &tank_move_run;
- }
- else
- {
+ } else {
self->monsterinfo.currentmove = &tank_move_start_run;
}
}
@@ -244,8 +233,7 @@ void tank_run (edict_t *self)
// pain
//
-mframe_t tank_frames_pain1 [] =
-{
+mframe_t tank_frames_pain1 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -253,8 +241,7 @@ mframe_t tank_frames_pain1 [] =
};
mmove_t tank_move_pain1 = {FRAME_pain101, FRAME_pain104, tank_frames_pain1, tank_run};
-mframe_t tank_frames_pain2 [] =
-{
+mframe_t tank_frames_pain2 [] = {
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -263,8 +250,7 @@ mframe_t tank_frames_pain2 [] =
};
mmove_t tank_move_pain2 = {FRAME_pain201, FRAME_pain205, tank_frames_pain2, tank_run};
-mframe_t tank_frames_pain3 [] =
-{
+mframe_t tank_frames_pain3 [] = {
{ ai_move, -7, NULL },
{ ai_move, 0, NULL },
{ ai_move, 0, NULL },
@@ -285,32 +271,31 @@ mframe_t tank_frames_pain3 [] =
mmove_t tank_move_pain3 = {FRAME_pain301, FRAME_pain316, tank_frames_pain3, tank_run};
-void tank_pain (edict_t *self, edict_t *other, float kick, int damage)
+void tank_pain(edict_t *self, edict_t *other, float kick, int damage)
{
if (self->health < (self->max_health / 2))
- self->s.skinnum |= 1;
+ self->s.skinnum |= 1;
if (damage <= 10)
return;
if (level.time < self->pain_debounce_time)
- return;
+ return;
if (damage <= 30)
if (random() > 0.2)
return;
-
+
// If hard or nightmare, don't go into pain while attacking
- if ( skill->value >= 2)
- {
- if ( (self->s.frame >= FRAME_attak301) && (self->s.frame <= FRAME_attak330) )
+ if (skill->value >= 2) {
+ if ((self->s.frame >= FRAME_attak301) && (self->s.frame <= FRAME_attak330))
return;
- if ( (self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak116) )
+ if ((self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak116))
return;
}
self->pain_debounce_time = level.time + 3;
- gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
if (skill->value == 3)
return; // no pain anims in nightmare
@@ -328,7 +313,7 @@ void tank_pain (edict_t *self, edict_t *other, float kick, int damage)
// attacks
//
-void TankBlaster (edict_t *self)
+void TankBlaster(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
@@ -343,22 +328,22 @@ void TankBlaster (edict_t *self)
else // (self->s.frame == FRAME_attak116)
flash_number = MZ2_TANK_BLASTER_3;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- VectorCopy (self->enemy->s.origin, end);
+ VectorCopy(self->enemy->s.origin, end);
end[2] += self->enemy->viewheight;
- VectorSubtract (end, start, dir);
+ VectorSubtract(end, start, dir);
- monster_fire_blaster (self, start, dir, 30, 800, flash_number, EF_BLASTER);
-}
+ monster_fire_blaster(self, start, dir, 30, 800, flash_number, EF_BLASTER);
+}
-void TankStrike (edict_t *self)
+void TankStrike(edict_t *self)
{
- gi.sound (self, CHAN_WEAPON, sound_strike, 1, ATTN_NORM, 0);
-}
+ gi.sound(self, CHAN_WEAPON, sound_strike, 1, ATTN_NORM, 0);
+}
-void TankRocket (edict_t *self)
+void TankRocket(edict_t *self)
{
vec3_t forward, right;
vec3_t start;
@@ -373,18 +358,18 @@ void TankRocket (edict_t *self)
else // (self->s.frame == FRAME_attak330)
flash_number = MZ2_TANK_ROCKET_3;
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- VectorCopy (self->enemy->s.origin, vec);
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, dir);
- VectorNormalize (dir);
+ VectorSubtract(vec, start, dir);
+ VectorNormalize(dir);
- monster_fire_rocket (self, start, dir, 50, 550, flash_number);
-}
+ monster_fire_rocket(self, start, dir, 50, 550, flash_number);
+}
-void TankMachineGun (edict_t *self)
+void TankMachineGun(edict_t *self)
{
vec3_t dir;
vec3_t vec;
@@ -394,19 +379,16 @@ void TankMachineGun (edict_t *self)
flash_number = MZ2_TANK_MACHINEGUN_1 + (self->s.frame - FRAME_attak406);
- AngleVectors (self->s.angles, forward, right, NULL);
- G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
+ AngleVectors(self->s.angles, forward, right, NULL);
+ G_ProjectSource(self->s.origin, monster_flash_offset[flash_number], forward, right, start);
- if (self->enemy)
- {
- VectorCopy (self->enemy->s.origin, vec);
+ if (self->enemy) {
+ VectorCopy(self->enemy->s.origin, vec);
vec[2] += self->enemy->viewheight;
- VectorSubtract (vec, start, vec);
- vectoangles (vec, vec);
+ VectorSubtract(vec, start, vec);
+ vectoangles(vec, vec);
dir[0] = vec[0];
- }
- else
- {
+ } else {
dir[0] = 0;
}
if (self->s.frame <= FRAME_attak415)
@@ -415,14 +397,13 @@ void TankMachineGun (edict_t *self)
dir[1] = self->s.angles[1] + 8 * (self->s.frame - FRAME_attak419);
dir[2] = 0;
- AngleVectors (dir, forward, NULL, NULL);
+ AngleVectors(dir, forward, NULL, NULL);
- monster_fire_bullet (self, start, forward, 20, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
-}
+ monster_fire_bullet(self, start, forward, 20, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
+}
-mframe_t tank_frames_attack_blast [] =
-{
+mframe_t tank_frames_attack_blast [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -442,8 +423,7 @@ mframe_t tank_frames_attack_blast [] =
};
mmove_t tank_move_attack_blast = {FRAME_attak101, FRAME_attak116, tank_frames_attack_blast, tank_reattack_blaster};
-mframe_t tank_frames_reattack_blast [] =
-{
+mframe_t tank_frames_reattack_blast [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, TankBlaster },
@@ -453,8 +433,7 @@ mframe_t tank_frames_reattack_blast [] =
};
mmove_t tank_move_reattack_blast = {FRAME_attak111, FRAME_attak116, tank_frames_reattack_blast, tank_reattack_blaster};
-mframe_t tank_frames_attack_post_blast [] =
-{
+mframe_t tank_frames_attack_post_blast [] = {
{ ai_move, 0, NULL }, // 17
{ ai_move, 0, NULL },
{ ai_move, 2, NULL },
@@ -464,13 +443,12 @@ mframe_t tank_frames_attack_post_blast [] =
};
mmove_t tank_move_attack_post_blast = {FRAME_attak117, FRAME_attak122, tank_frames_attack_post_blast, tank_run};
-void tank_reattack_blaster (edict_t *self)
+void tank_reattack_blaster(edict_t *self)
{
if (skill->value >= 2)
- if (visible (self, self->enemy))
+ if (visible(self, self->enemy))
if (self->enemy->health > 0)
- if (random() <= 0.6)
- {
+ if (random() <= 0.6) {
self->monsterinfo.currentmove = &tank_move_reattack_blast;
return;
}
@@ -478,14 +456,13 @@ void tank_reattack_blaster (edict_t *self)
}
-void tank_poststrike (edict_t *self)
+void tank_poststrike(edict_t *self)
{
self->enemy = NULL;
- tank_run (self);
+ tank_run(self);
}
-mframe_t tank_frames_attack_strike [] =
-{
+mframe_t tank_frames_attack_strike [] = {
{ ai_move, 3, NULL },
{ ai_move, 2, NULL },
{ ai_move, 2, NULL },
@@ -527,8 +504,7 @@ mframe_t tank_frames_attack_strike [] =
};
mmove_t tank_move_attack_strike = {FRAME_attak201, FRAME_attak238, tank_frames_attack_strike, tank_poststrike};
-mframe_t tank_frames_attack_pre_rocket [] =
-{
+mframe_t tank_frames_attack_pre_rocket [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -555,9 +531,8 @@ mframe_t tank_frames_attack_pre_rocket [] =
};
mmove_t tank_move_attack_pre_rocket = {FRAME_attak301, FRAME_attak321, tank_frames_attack_pre_rocket, tank_doattack_rocket};
-mframe_t tank_frames_attack_fire_rocket [] =
-{
- { ai_charge, -3, NULL }, // Loop Start 22
+mframe_t tank_frames_attack_fire_rocket [] = {
+ { ai_charge, -3, NULL }, // Loop Start 22
{ ai_charge, 0, NULL },
{ ai_charge, 0, TankRocket }, // 24
{ ai_charge, 0, NULL },
@@ -569,8 +544,7 @@ mframe_t tank_frames_attack_fire_rocket [] =
};
mmove_t tank_move_attack_fire_rocket = {FRAME_attak322, FRAME_attak330, tank_frames_attack_fire_rocket, tank_refire_rocket};
-mframe_t tank_frames_attack_post_rocket [] =
-{
+mframe_t tank_frames_attack_post_rocket [] = {
{ ai_charge, 0, NULL }, // 31
{ ai_charge, -1, NULL },
{ ai_charge, -1, NULL },
@@ -599,8 +573,7 @@ mframe_t tank_frames_attack_post_rocket [] =
};
mmove_t tank_move_attack_post_rocket = {FRAME_attak331, FRAME_attak353, tank_frames_attack_post_rocket, tank_run};
-mframe_t tank_frames_attack_chain [] =
-{
+mframe_t tank_frames_attack_chain [] = {
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
{ ai_charge, 0, NULL },
@@ -633,21 +606,20 @@ mframe_t tank_frames_attack_chain [] =
};
mmove_t tank_move_attack_chain = {FRAME_attak401, FRAME_attak429, tank_frames_attack_chain, tank_run};
-void tank_refire_rocket (edict_t *self)
+void tank_refire_rocket(edict_t *self)
{
// Only on hard or nightmare
- if ( skill->value >= 2 )
+ if (skill->value >= 2)
if (self->enemy->health > 0)
- if (visible(self, self->enemy) )
- if (random() <= 0.4)
- {
+ if (visible(self, self->enemy))
+ if (random() <= 0.4) {
self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
return;
}
self->monsterinfo.currentmove = &tank_move_attack_post_rocket;
}
-void tank_doattack_rocket (edict_t *self)
+void tank_doattack_rocket(edict_t *self)
{
self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
}
@@ -658,42 +630,34 @@ void tank_attack(edict_t *self)
float range;
float r;
- if (self->enemy->health < 0)
- {
+ if (self->enemy->health < 0) {
self->monsterinfo.currentmove = &tank_move_attack_strike;
self->monsterinfo.aiflags &= ~AI_BRUTAL;
return;
}
- VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
- range = VectorLength (vec);
+ VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
+ range = VectorLength(vec);
r = random();
- if (range <= 125)
- {
+ if (range <= 125) {
if (r < 0.4)
self->monsterinfo.currentmove = &tank_move_attack_chain;
- else
+ else
self->monsterinfo.currentmove = &tank_move_attack_blast;
- }
- else if (range <= 250)
- {
+ } else if (range <= 250) {
if (r < 0.5)
self->monsterinfo.currentmove = &tank_move_attack_chain;
else
self->monsterinfo.currentmove = &tank_move_attack_blast;
- }
- else
- {
+ } else {
if (r < 0.33)
self->monsterinfo.currentmove = &tank_move_attack_chain;
- else if (r < 0.66)
- {
+ else if (r < 0.66) {
self->monsterinfo.currentmove = &tank_move_attack_pre_rocket;
self->pain_debounce_time = level.time + 5.0; // no pain for a while
- }
- else
+ } else
self->monsterinfo.currentmove = &tank_move_attack_blast;
}
}
@@ -703,18 +667,17 @@ void tank_attack(edict_t *self)
// death
//
-void tank_dead (edict_t *self)
+void tank_dead(edict_t *self)
{
- VectorSet (self->mins, -16, -16, -16);
- VectorSet (self->maxs, 16, 16, -0);
+ VectorSet(self->mins, -16, -16, -16);
+ VectorSet(self->maxs, 16, 16, -0);
self->movetype = MOVETYPE_TOSS;
self->svflags |= SVF_DEADMONSTER;
self->nextthink = 0;
- gi.linkentity (self);
+ gi.linkentity(self);
}
-mframe_t tank_frames_death1 [] =
-{
+mframe_t tank_frames_death1 [] = {
{ ai_move, -7, NULL },
{ ai_move, -2, NULL },
{ ai_move, -2, NULL },
@@ -750,20 +713,19 @@ mframe_t tank_frames_death1 [] =
};
mmove_t tank_move_death = {FRAME_death101, FRAME_death132, tank_frames_death1, tank_dead};
-void tank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void tank_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
// check for gib
- if (self->health <= self->gib_health)
- {
- gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 1 /*4*/; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
- ThrowGib (self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
- ThrowHead (self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
+ if (self->health <= self->gib_health) {
+ gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 1 /*4*/; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
+ ThrowGib(self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
+ ThrowHead(self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
self->deadflag = DEAD_DEAD;
return;
}
@@ -772,12 +734,12 @@ void tank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage,
return;
// regular death
- gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
+ gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
self->deadflag = DEAD_DEAD;
self->takedamage = DAMAGE_YES;
self->monsterinfo.currentmove = &tank_move_death;
-
+
}
@@ -789,44 +751,40 @@ void tank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage,
*/
/*QUAKED monster_tank_commander (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
*/
-void SP_monster_tank (edict_t *self)
+void SP_monster_tank(edict_t *self)
{
- if (deathmatch->value)
- {
- G_FreeEdict (self);
+ if (deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- self->s.modelindex = gi.modelindex ("models/monsters/tank/tris.md2");
- VectorSet (self->mins, -32, -32, -16);
- VectorSet (self->maxs, 32, 32, 72);
+ self->s.modelindex = gi.modelindex("models/monsters/tank/tris.md2");
+ VectorSet(self->mins, -32, -32, -16);
+ VectorSet(self->maxs, 32, 32, 72);
self->movetype = MOVETYPE_STEP;
self->solid = SOLID_BBOX;
- sound_pain = gi.soundindex ("tank/tnkpain2.wav");
- sound_thud = gi.soundindex ("tank/tnkdeth2.wav");
- sound_idle = gi.soundindex ("tank/tnkidle1.wav");
- sound_die = gi.soundindex ("tank/death.wav");
- sound_step = gi.soundindex ("tank/step.wav");
- sound_windup = gi.soundindex ("tank/tnkatck4.wav");
- sound_strike = gi.soundindex ("tank/tnkatck5.wav");
- sound_sight = gi.soundindex ("tank/sight1.wav");
-
- gi.soundindex ("tank/tnkatck1.wav");
- gi.soundindex ("tank/tnkatk2a.wav");
- gi.soundindex ("tank/tnkatk2b.wav");
- gi.soundindex ("tank/tnkatk2c.wav");
- gi.soundindex ("tank/tnkatk2d.wav");
- gi.soundindex ("tank/tnkatk2e.wav");
- gi.soundindex ("tank/tnkatck3.wav");
-
- if (strcmp(self->classname, "monster_tank_commander") == 0)
- {
+ sound_pain = gi.soundindex("tank/tnkpain2.wav");
+ sound_thud = gi.soundindex("tank/tnkdeth2.wav");
+ sound_idle = gi.soundindex("tank/tnkidle1.wav");
+ sound_die = gi.soundindex("tank/death.wav");
+ sound_step = gi.soundindex("tank/step.wav");
+ sound_windup = gi.soundindex("tank/tnkatck4.wav");
+ sound_strike = gi.soundindex("tank/tnkatck5.wav");
+ sound_sight = gi.soundindex("tank/sight1.wav");
+
+ gi.soundindex("tank/tnkatck1.wav");
+ gi.soundindex("tank/tnkatk2a.wav");
+ gi.soundindex("tank/tnkatk2b.wav");
+ gi.soundindex("tank/tnkatk2c.wav");
+ gi.soundindex("tank/tnkatk2d.wav");
+ gi.soundindex("tank/tnkatk2e.wav");
+ gi.soundindex("tank/tnkatck3.wav");
+
+ if (strcmp(self->classname, "monster_tank_commander") == 0) {
self->health = 1000;
self->gib_health = -225;
- }
- else
- {
+ } else {
self->health = 750;
self->gib_health = -200;
}
@@ -844,8 +802,8 @@ void SP_monster_tank (edict_t *self)
self->monsterinfo.sight = tank_sight;
self->monsterinfo.idle = tank_idle;
- gi.linkentity (self);
-
+ gi.linkentity(self);
+
self->monsterinfo.currentmove = &tank_move_stand;
self->monsterinfo.scale = MODEL_SCALE;
diff --git a/src/baseq2/m_tank.h b/src/baseq2/m_tank.h
index 39c41d4..cfc8e23 100644
--- a/src/baseq2/m_tank.h
+++ b/src/baseq2/m_tank.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/baseq2/p_client.c b/src/baseq2/p_client.c
index 6b1033f..ddabcb6 100644
--- a/src/baseq2/p_client.c
+++ b/src/baseq2/p_client.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,9 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "g_local.h"
#include "m_player.h"
-void ClientUserinfoChanged (edict_t *ent, char *userinfo);
+void ClientUserinfoChanged(edict_t *ent, char *userinfo);
-void SP_misc_teleporter_dest (edict_t *ent);
+void SP_misc_teleporter_dest(edict_t *ent);
//
// Gross, ugly, disgustuing hack section
@@ -36,25 +36,22 @@ void SP_misc_teleporter_dest (edict_t *ent);
// we use carnal knowledge of the maps to fix the coop spot targetnames to match
// that of the nearest named single player spot
-void SP_FixCoopSpots (edict_t *self)
+void SP_FixCoopSpots(edict_t *self)
{
edict_t *spot;
vec3_t d;
spot = NULL;
- while(1)
- {
+ while (1) {
spot = G_Find(spot, FOFS(classname), "info_player_start");
if (!spot)
return;
if (!spot->targetname)
continue;
VectorSubtract(self->s.origin, spot->s.origin, d);
- if (VectorLength(d) < 384)
- {
- if ((!self->targetname) || Q_stricmp(self->targetname, spot->targetname) != 0)
- {
+ if (VectorLength(d) < 384) {
+ if ((!self->targetname) || Q_stricmp(self->targetname, spot->targetname) != 0) {
// gi.dprintf("FixCoopSpots changed %s at %s targetname from %s to %s\n", self->classname, vtos(self->s.origin), self->targetname, spot->targetname);
self->targetname = spot->targetname;
}
@@ -67,12 +64,11 @@ void SP_FixCoopSpots (edict_t *self)
// some maps don't have any coop spots at all, so we need to create them
// where they should have been
-void SP_CreateCoopSpots (edict_t *self)
+void SP_CreateCoopSpots(edict_t *self)
{
edict_t *spot;
- if(Q_stricmp(level.mapname, "security") == 0)
- {
+ if (Q_stricmp(level.mapname, "security") == 0) {
spot = G_Spawn();
spot->classname = "info_player_coop";
spot->s.origin[0] = 188 - 64;
@@ -109,8 +105,7 @@ void SP_info_player_start(edict_t *self)
{
if (!coop->value)
return;
- if(Q_stricmp(level.mapname, "security") == 0)
- {
+ if (Q_stricmp(level.mapname, "security") == 0) {
// invoke one of our gross, ugly, disgusting hacks
self->think = SP_CreateCoopSpots;
self->nextthink = level.time + FRAMETIME;
@@ -122,12 +117,11 @@ potential spawning position for deathmatch games
*/
void SP_info_player_deathmatch(edict_t *self)
{
- if (!deathmatch->value)
- {
- G_FreeEdict (self);
+ if (!deathmatch->value) {
+ G_FreeEdict(self);
return;
}
- SP_misc_teleporter_dest (self);
+ SP_misc_teleporter_dest(self);
}
/*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 32)
@@ -136,27 +130,25 @@ potential spawning position for coop games
void SP_info_player_coop(edict_t *self)
{
- if (!coop->value)
- {
- G_FreeEdict (self);
+ if (!coop->value) {
+ G_FreeEdict(self);
return;
}
- if((Q_stricmp(level.mapname, "jail2") == 0) ||
- (Q_stricmp(level.mapname, "jail4") == 0) ||
- (Q_stricmp(level.mapname, "mine1") == 0) ||
- (Q_stricmp(level.mapname, "mine2") == 0) ||
- (Q_stricmp(level.mapname, "mine3") == 0) ||
- (Q_stricmp(level.mapname, "mine4") == 0) ||
- (Q_stricmp(level.mapname, "lab") == 0) ||
- (Q_stricmp(level.mapname, "boss1") == 0) ||
- (Q_stricmp(level.mapname, "fact3") == 0) ||
- (Q_stricmp(level.mapname, "biggun") == 0) ||
- (Q_stricmp(level.mapname, "space") == 0) ||
- (Q_stricmp(level.mapname, "command") == 0) ||
- (Q_stricmp(level.mapname, "power2") == 0) ||
- (Q_stricmp(level.mapname, "strike") == 0))
- {
+ if ((Q_stricmp(level.mapname, "jail2") == 0) ||
+ (Q_stricmp(level.mapname, "jail4") == 0) ||
+ (Q_stricmp(level.mapname, "mine1") == 0) ||
+ (Q_stricmp(level.mapname, "mine2") == 0) ||
+ (Q_stricmp(level.mapname, "mine3") == 0) ||
+ (Q_stricmp(level.mapname, "mine4") == 0) ||
+ (Q_stricmp(level.mapname, "lab") == 0) ||
+ (Q_stricmp(level.mapname, "boss1") == 0) ||
+ (Q_stricmp(level.mapname, "fact3") == 0) ||
+ (Q_stricmp(level.mapname, "biggun") == 0) ||
+ (Q_stricmp(level.mapname, "space") == 0) ||
+ (Q_stricmp(level.mapname, "command") == 0) ||
+ (Q_stricmp(level.mapname, "power2") == 0) ||
+ (Q_stricmp(level.mapname, "strike") == 0)) {
// invoke one of our gross, ugly, disgusting hacks
self->think = SP_FixCoopSpots;
self->nextthink = level.time + FRAMETIME;
@@ -176,39 +168,39 @@ void SP_info_player_intermission(void)
//=======================================================================
-void player_pain (edict_t *self, edict_t *other, float kick, int damage)
+void player_pain(edict_t *self, edict_t *other, float kick, int damage)
{
// player pain is handled at the end of the frame in P_DamageFeedback
}
-qboolean IsFemale (edict_t *ent)
+qboolean IsFemale(edict_t *ent)
{
char *info;
if (!ent->client)
return qfalse;
- info = Info_ValueForKey (ent->client->pers.userinfo, "gender");
+ info = Info_ValueForKey(ent->client->pers.userinfo, "gender");
if (info[0] == 'f' || info[0] == 'F')
return qtrue;
return qfalse;
}
-qboolean IsNeutral (edict_t *ent)
+qboolean IsNeutral(edict_t *ent)
{
char *info;
if (!ent->client)
return qfalse;
- info = Info_ValueForKey (ent->client->pers.userinfo, "gender");
+ info = Info_ValueForKey(ent->client->pers.userinfo, "gender");
if (info[0] != 'f' && info[0] != 'F' && info[0] != 'm' && info[0] != 'M')
return qtrue;
return qfalse;
}
-void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
+void ClientObituary(edict_t *self, edict_t *inflictor, edict_t *attacker)
{
int mod;
char *message;
@@ -218,15 +210,13 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
if (coop->value && attacker->client)
meansOfDeath |= MOD_FRIENDLY_FIRE;
- if (deathmatch->value || coop->value)
- {
+ if (deathmatch->value || coop->value) {
ff = meansOfDeath & MOD_FRIENDLY_FIRE;
mod = meansOfDeath & ~MOD_FRIENDLY_FIRE;
message = NULL;
message2 = "";
- switch (mod)
- {
+ switch (mod) {
case MOD_SUICIDE:
message = "suicides";
break;
@@ -264,10 +254,8 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
message = "was in the wrong place";
break;
}
- if (attacker == self)
- {
- switch (mod)
- {
+ if (attacker == self) {
+ switch (mod) {
case MOD_HELD_GRENADE:
message = "tried to put the pin back in";
break;
@@ -301,9 +289,8 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
break;
}
}
- if (message)
- {
- gi.bprintf (PRINT_MEDIUM, "%s %s.\n", self->client->pers.netname, message);
+ if (message) {
+ gi.bprintf(PRINT_MEDIUM, "%s %s.\n", self->client->pers.netname, message);
if (deathmatch->value)
self->client->resp.score--;
self->enemy = NULL;
@@ -311,10 +298,8 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
}
self->enemy = attacker;
- if (attacker && attacker->client)
- {
- switch (mod)
- {
+ if (attacker && attacker->client) {
+ switch (mod) {
case MOD_BLASTER:
message = "was blasted by";
break;
@@ -384,11 +369,9 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
message2 = "'s personal space";
break;
}
- if (message)
- {
- gi.bprintf (PRINT_MEDIUM,"%s %s %s%s\n", self->client->pers.netname, message, attacker->client->pers.netname, message2);
- if (deathmatch->value)
- {
+ if (message) {
+ gi.bprintf(PRINT_MEDIUM, "%s %s %s%s\n", self->client->pers.netname, message, attacker->client->pers.netname, message2);
+ if (deathmatch->value) {
if (ff)
attacker->client->resp.score--;
else
@@ -399,15 +382,15 @@ void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
}
}
- gi.bprintf (PRINT_MEDIUM,"%s died.\n", self->client->pers.netname);
+ gi.bprintf(PRINT_MEDIUM, "%s died.\n", self->client->pers.netname);
if (deathmatch->value)
self->client->resp.score--;
}
-void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
+void Touch_Item(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
-void TossClientWeapon (edict_t *self)
+void TossClientWeapon(edict_t *self)
{
gitem_t *item;
edict_t *drop;
@@ -418,9 +401,9 @@ void TossClientWeapon (edict_t *self)
return;
item = self->client->pers.weapon;
- if (! self->client->pers.inventory[self->client->ammo_index] )
+ if (! self->client->pers.inventory[self->client->ammo_index])
item = NULL;
- if (item && (strcmp (item->pickup_name, "Blaster") == 0))
+ if (item && (strcmp(item->pickup_name, "Blaster") == 0))
item = NULL;
if (!((int)(dmflags->value) & DF_QUAD_DROP))
@@ -433,18 +416,16 @@ void TossClientWeapon (edict_t *self)
else
spread = 0.0;
- if (item)
- {
+ if (item) {
self->client->v_angle[YAW] -= spread;
- drop = Drop_Item (self, item);
+ drop = Drop_Item(self, item);
self->client->v_angle[YAW] += spread;
drop->spawnflags = DROPPED_PLAYER_ITEM;
}
- if (quad)
- {
+ if (quad) {
self->client->v_angle[YAW] += spread;
- drop = Drop_Item (self, FindItemByClassname ("item_quad"));
+ drop = Drop_Item(self, FindItemByClassname("item_quad"));
self->client->v_angle[YAW] -= spread;
drop->spawnflags |= DROPPED_PLAYER_ITEM;
@@ -460,26 +441,21 @@ void TossClientWeapon (edict_t *self)
LookAtKiller
==================
*/
-void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker)
+void LookAtKiller(edict_t *self, edict_t *inflictor, edict_t *attacker)
{
vec3_t dir;
- if (attacker && attacker != world && attacker != self)
- {
- VectorSubtract (attacker->s.origin, self->s.origin, dir);
- }
- else if (inflictor && inflictor != world && inflictor != self)
- {
- VectorSubtract (inflictor->s.origin, self->s.origin, dir);
- }
- else
- {
+ if (attacker && attacker != world && attacker != self) {
+ VectorSubtract(attacker->s.origin, self->s.origin, dir);
+ } else if (inflictor && inflictor != world && inflictor != self) {
+ VectorSubtract(inflictor->s.origin, self->s.origin, dir);
+ } else {
self->client->killer_yaw = self->s.angles[YAW];
return;
}
if (dir[0])
- self->client->killer_yaw = 180/M_PI*atan2(dir[1], dir[0]);
+ self->client->killer_yaw = 180 / M_PI * atan2(dir[1], dir[0]);
else {
self->client->killer_yaw = 0;
if (dir[1] > 0)
@@ -489,7 +465,7 @@ void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker)
}
if (self->client->killer_yaw < 0)
self->client->killer_yaw += 360;
-
+
}
@@ -498,11 +474,11 @@ void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker)
player_die
==================
*/
-void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void player_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
- VectorClear (self->avelocity);
+ VectorClear(self->avelocity);
self->takedamage = DAMAGE_YES;
self->movetype = MOVETYPE_TOSS;
@@ -520,20 +496,18 @@ void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
// self->solid = SOLID_NOT;
self->svflags |= SVF_DEADMONSTER;
- if (!self->deadflag)
- {
+ if (!self->deadflag) {
self->client->respawn_time = level.time + 1.0;
- LookAtKiller (self, inflictor, attacker);
+ LookAtKiller(self, inflictor, attacker);
self->client->ps.pmove.pm_type = PM_DEAD;
- ClientObituary (self, inflictor, attacker);
- TossClientWeapon (self);
+ ClientObituary(self, inflictor, attacker);
+ TossClientWeapon(self);
if (deathmatch->value)
- Cmd_Help_f (self); // show scores
+ Cmd_Help_f(self); // show scores
// clear inventory
// this is kind of ugly, but it's how we want to handle keys in coop
- for (n = 0; n < game.num_items; n++)
- {
+ for (n = 0; n < game.num_items; n++) {
if (coop->value && itemlist[n].flags & IT_KEY)
self->client->resp.coop_respawn.inventory[n] = self->client->pers.inventory[n];
self->client->pers.inventory[n] = 0;
@@ -547,51 +521,46 @@ void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damag
self->client->enviro_framenum = 0;
self->flags &= ~FL_POWER_ARMOR;
- if (self->health < -40)
- { // gib
- gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
- ThrowClientHead (self, damage);
+ if (self->health < -40) {
+ // gib
+ gi.sound(self, CHAN_BODY, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ ThrowClientHead(self, damage);
self->takedamage = DAMAGE_NO;
- }
- else
- { // normal death
- if (!self->deadflag)
- {
+ } else {
+ // normal death
+ if (!self->deadflag) {
static int i;
- i = (i+1)%3;
+ i = (i + 1) % 3;
// start a death animation
self->client->anim_priority = ANIM_DEATH;
- if (self->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- self->s.frame = FRAME_crdeath1-1;
+ if (self->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ self->s.frame = FRAME_crdeath1 - 1;
self->client->anim_end = FRAME_crdeath5;
- }
- else switch (i)
- {
- case 0:
- self->s.frame = FRAME_death101-1;
- self->client->anim_end = FRAME_death106;
- break;
- case 1:
- self->s.frame = FRAME_death201-1;
- self->client->anim_end = FRAME_death206;
- break;
- case 2:
- self->s.frame = FRAME_death301-1;
- self->client->anim_end = FRAME_death308;
- break;
- }
- gi.sound (self, CHAN_VOICE, gi.soundindex(va("*death%i.wav", (rand()%4)+1)), 1, ATTN_NORM, 0);
+ } else switch (i) {
+ case 0:
+ self->s.frame = FRAME_death101 - 1;
+ self->client->anim_end = FRAME_death106;
+ break;
+ case 1:
+ self->s.frame = FRAME_death201 - 1;
+ self->client->anim_end = FRAME_death206;
+ break;
+ case 2:
+ self->s.frame = FRAME_death301 - 1;
+ self->client->anim_end = FRAME_death308;
+ break;
+ }
+ gi.sound(self, CHAN_VOICE, gi.soundindex(va("*death%i.wav", (rand() % 4) + 1)), 1, ATTN_NORM, 0);
}
}
self->deadflag = DEAD_DEAD;
- gi.linkentity (self);
+ gi.linkentity(self);
}
//=======================================================================
@@ -604,11 +573,11 @@ This is only called when the game first initializes in single player,
but is called after each death and level change in deathmatch
==============
*/
-void InitClientPersistant (gclient_t *client)
+void InitClientPersistant(gclient_t *client)
{
gitem_t *item;
- memset (&client->pers, 0, sizeof(client->pers));
+ memset(&client->pers, 0, sizeof(client->pers));
item = FindItem("Blaster");
client->pers.selected_item = ITEM_INDEX(item);
@@ -630,9 +599,9 @@ void InitClientPersistant (gclient_t *client)
}
-void InitClientResp (gclient_t *client)
+void InitClientResp(gclient_t *client)
{
- memset (&client->resp, 0, sizeof(client->resp));
+ memset(&client->resp, 0, sizeof(client->resp));
client->resp.enterframe = level.framenum;
client->resp.coop_respawn = client->pers;
}
@@ -641,31 +610,30 @@ void InitClientResp (gclient_t *client)
==================
SaveClientData
-Some information that should be persistant, like health,
+Some information that should be persistant, like health,
is still stored in the edict structure, so it needs to
be mirrored out to the client structure before all the
edicts are wiped.
==================
*/
-void SaveClientData (void)
+void SaveClientData(void)
{
int i;
edict_t *ent;
- for (i=0 ; i<game.maxclients ; i++)
- {
- ent = &g_edicts[1+i];
+ for (i = 0 ; i < game.maxclients ; i++) {
+ ent = &g_edicts[1 + i];
if (!ent->inuse)
continue;
game.clients[i].pers.health = ent->health;
game.clients[i].pers.max_health = ent->max_health;
- game.clients[i].pers.savedFlags = (ent->flags & (FL_GODMODE|FL_NOTARGET|FL_POWER_ARMOR));
+ game.clients[i].pers.savedFlags = (ent->flags & (FL_GODMODE | FL_NOTARGET | FL_POWER_ARMOR));
if (coop->value)
game.clients[i].pers.score = ent->client->resp.score;
}
}
-void FetchClientEntData (edict_t *ent)
+void FetchClientEntData(edict_t *ent)
{
ent->health = ent->client->pers.health;
ent->max_health = ent->client->pers.max_health;
@@ -691,7 +659,7 @@ PlayersRangeFromSpot
Returns the distance to the nearest player from the given spot
================
*/
-float PlayersRangeFromSpot (edict_t *spot)
+float PlayersRangeFromSpot(edict_t *spot)
{
edict_t *player;
float bestplayerdistance;
@@ -702,8 +670,7 @@ float PlayersRangeFromSpot (edict_t *spot)
bestplayerdistance = 9999999;
- for (n = 1; n <= maxclients->value; n++)
- {
+ for (n = 1; n <= maxclients->value; n++) {
player = &g_edicts[n];
if (!player->inuse)
@@ -712,8 +679,8 @@ float PlayersRangeFromSpot (edict_t *spot)
if (player->health <= 0)
continue;
- VectorSubtract (spot->s.origin, player->s.origin, v);
- playerdistance = VectorLength (v);
+ VectorSubtract(spot->s.origin, player->s.origin, v);
+ playerdistance = VectorLength(v);
if (playerdistance < bestplayerdistance)
bestplayerdistance = playerdistance;
@@ -730,7 +697,7 @@ go to a random point, but NOT the two points closest
to other players
================
*/
-edict_t *SelectRandomDeathmatchSpawnPoint (void)
+edict_t *SelectRandomDeathmatchSpawnPoint(void)
{
edict_t *spot, *spot1, *spot2;
int count = 0;
@@ -741,17 +708,13 @@ edict_t *SelectRandomDeathmatchSpawnPoint (void)
range1 = range2 = 99999;
spot1 = spot2 = NULL;
- while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL)
- {
+ while ((spot = G_Find(spot, FOFS(classname), "info_player_deathmatch")) != NULL) {
count++;
range = PlayersRangeFromSpot(spot);
- if (range < range1)
- {
+ if (range < range1) {
range1 = range;
spot1 = spot;
- }
- else if (range < range2)
- {
+ } else if (range < range2) {
range2 = range;
spot2 = spot;
}
@@ -760,22 +723,19 @@ edict_t *SelectRandomDeathmatchSpawnPoint (void)
if (!count)
return NULL;
- if (count <= 2)
- {
+ if (count <= 2) {
spot1 = spot2 = NULL;
- }
- else
+ } else
count -= 2;
selection = rand() % count;
spot = NULL;
- do
- {
- spot = G_Find (spot, FOFS(classname), "info_player_deathmatch");
+ do {
+ spot = G_Find(spot, FOFS(classname), "info_player_deathmatch");
if (spot == spot1 || spot == spot2)
selection++;
- } while(selection--);
+ } while (selection--);
return spot;
}
@@ -786,7 +746,7 @@ SelectFarthestDeathmatchSpawnPoint
================
*/
-edict_t *SelectFarthestDeathmatchSpawnPoint (void)
+edict_t *SelectFarthestDeathmatchSpawnPoint(void)
{
edict_t *bestspot;
float bestdistance, bestplayerdistance;
@@ -796,39 +756,36 @@ edict_t *SelectFarthestDeathmatchSpawnPoint (void)
spot = NULL;
bestspot = NULL;
bestdistance = 0;
- while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL)
- {
- bestplayerdistance = PlayersRangeFromSpot (spot);
+ while ((spot = G_Find(spot, FOFS(classname), "info_player_deathmatch")) != NULL) {
+ bestplayerdistance = PlayersRangeFromSpot(spot);
- if (bestplayerdistance > bestdistance)
- {
+ if (bestplayerdistance > bestdistance) {
bestspot = spot;
bestdistance = bestplayerdistance;
}
}
- if (bestspot)
- {
+ if (bestspot) {
return bestspot;
}
// if there is a player just spawned on each and every start spot
// we have no choice to turn one into a telefrag meltdown
- spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
+ spot = G_Find(NULL, FOFS(classname), "info_player_deathmatch");
return spot;
}
-edict_t *SelectDeathmatchSpawnPoint (void)
+edict_t *SelectDeathmatchSpawnPoint(void)
{
- if ( (int)(dmflags->value) & DF_SPAWN_FARTHEST)
- return SelectFarthestDeathmatchSpawnPoint ();
+ if ((int)(dmflags->value) & DF_SPAWN_FARTHEST)
+ return SelectFarthestDeathmatchSpawnPoint();
else
- return SelectRandomDeathmatchSpawnPoint ();
+ return SelectRandomDeathmatchSpawnPoint();
}
-edict_t *SelectCoopSpawnPoint (edict_t *ent)
+edict_t *SelectCoopSpawnPoint(edict_t *ent)
{
int index;
edict_t *spot = NULL;
@@ -843,17 +800,16 @@ edict_t *SelectCoopSpawnPoint (edict_t *ent)
spot = NULL;
// assume there are four coop spots at each spawnpoint
- while (1)
- {
- spot = G_Find (spot, FOFS(classname), "info_player_coop");
+ while (1) {
+ spot = G_Find(spot, FOFS(classname), "info_player_coop");
if (!spot)
return NULL; // we didn't have enough...
target = spot->targetname;
if (!target)
target = "";
- if ( Q_stricmp(game.spawnpoint, target) == 0 )
- { // this is a coop spawn point for one of the clients here
+ if (Q_stricmp(game.spawnpoint, target) == 0) {
+ // this is a coop spawn point for one of the clients here
index--;
if (!index)
return spot; // this is it
@@ -872,20 +828,18 @@ SelectSpawnPoint
Chooses a player start, deathmatch start, coop start, etc
============
*/
-void SelectSpawnPoint (edict_t *ent, vec3_t origin, vec3_t angles)
+void SelectSpawnPoint(edict_t *ent, vec3_t origin, vec3_t angles)
{
edict_t *spot = NULL;
if (deathmatch->value)
- spot = SelectDeathmatchSpawnPoint ();
+ spot = SelectDeathmatchSpawnPoint();
else if (coop->value)
- spot = SelectCoopSpawnPoint (ent);
+ spot = SelectCoopSpawnPoint(ent);
// find a single player start spot
- if (!spot)
- {
- while ((spot = G_Find (spot, FOFS(classname), "info_player_start")) != NULL)
- {
+ if (!spot) {
+ while ((spot = G_Find(spot, FOFS(classname), "info_player_start")) != NULL) {
if (!game.spawnpoint[0] && !spot->targetname)
break;
@@ -896,86 +850,82 @@ void SelectSpawnPoint (edict_t *ent, vec3_t origin, vec3_t angles)
break;
}
- if (!spot)
- {
- if (!game.spawnpoint[0])
- { // there wasn't a spawnpoint without a target, so use any
- spot = G_Find (spot, FOFS(classname), "info_player_start");
+ if (!spot) {
+ if (!game.spawnpoint[0]) {
+ // there wasn't a spawnpoint without a target, so use any
+ spot = G_Find(spot, FOFS(classname), "info_player_start");
}
if (!spot)
- gi.error ("Couldn't find spawn point %s\n", game.spawnpoint);
+ gi.error("Couldn't find spawn point %s\n", game.spawnpoint);
}
}
- VectorCopy (spot->s.origin, origin);
+ VectorCopy(spot->s.origin, origin);
origin[2] += 9;
- VectorCopy (spot->s.angles, angles);
+ VectorCopy(spot->s.angles, angles);
}
//======================================================================
-void InitBodyQue (void)
+void InitBodyQue(void)
{
int i;
edict_t *ent;
level.body_que = 0;
- for (i=0; i<BODY_QUEUE_SIZE ; i++)
- {
+ for (i = 0; i < BODY_QUEUE_SIZE ; i++) {
ent = G_Spawn();
ent->classname = "bodyque";
}
}
-void body_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
+void body_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
- if (self->health < -40)
- {
- gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
- for (n= 0; n < 4; n++)
- ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
+ if (self->health < -40) {
+ gi.sound(self, CHAN_BODY, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
+ for (n = 0; n < 4; n++)
+ ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
self->s.origin[2] -= 48;
- ThrowClientHead (self, damage);
+ ThrowClientHead(self, damage);
self->takedamage = DAMAGE_NO;
}
}
-void CopyToBodyQue (edict_t *ent)
+void CopyToBodyQue(edict_t *ent)
{
edict_t *body;
- gi.unlinkentity (ent);
+ gi.unlinkentity(ent);
// grab a body que and cycle to the next one
body = &g_edicts[game.maxclients + level.body_que + 1];
level.body_que = (level.body_que + 1) % BODY_QUEUE_SIZE;
// send an effect on the removed body
- if (body->s.modelindex)
- {
- gi.WriteByte (svc_temp_entity);
- gi.WriteByte (TE_BLOOD);
- gi.WritePosition (body->s.origin);
- gi.WriteDir (vec3_origin);
- gi.multicast (body->s.origin, MULTICAST_PVS);
- }
-
- gi.unlinkentity (body);
+ if (body->s.modelindex) {
+ gi.WriteByte(svc_temp_entity);
+ gi.WriteByte(TE_BLOOD);
+ gi.WritePosition(body->s.origin);
+ gi.WriteDir(vec3_origin);
+ gi.multicast(body->s.origin, MULTICAST_PVS);
+ }
+
+ gi.unlinkentity(body);
body->s = ent->s;
body->s.number = body - g_edicts;
body->s.event = EV_OTHER_TELEPORT;
body->svflags = ent->svflags;
- VectorCopy (ent->mins, body->mins);
- VectorCopy (ent->maxs, body->maxs);
- VectorCopy (ent->absmin, body->absmin);
- VectorCopy (ent->absmax, body->absmax);
- VectorCopy (ent->size, body->size);
- VectorCopy (ent->velocity, body->velocity);
- VectorCopy (ent->avelocity, body->avelocity);
+ VectorCopy(ent->mins, body->mins);
+ VectorCopy(ent->maxs, body->maxs);
+ VectorCopy(ent->absmin, body->absmin);
+ VectorCopy(ent->absmax, body->absmax);
+ VectorCopy(ent->size, body->size);
+ VectorCopy(ent->velocity, body->velocity);
+ VectorCopy(ent->avelocity, body->avelocity);
body->solid = ent->solid;
body->clipmask = ent->clipmask;
body->owner = ent->owner;
@@ -985,18 +935,17 @@ void CopyToBodyQue (edict_t *ent)
body->die = body_die;
body->takedamage = DAMAGE_YES;
- gi.linkentity (body);
+ gi.linkentity(body);
}
-void respawn (edict_t *self)
+void respawn(edict_t *self)
{
- if (deathmatch->value || coop->value)
- {
+ if (deathmatch->value || coop->value) {
// spectator's don't leave bodies
if (self->movetype != MOVETYPE_NOCLIP)
- CopyToBodyQue (self);
+ CopyToBodyQue(self);
self->svflags &= ~SVF_NOCLIENT;
- PutClientInServer (self);
+ PutClientInServer(self);
// add a teleportation effect
self->s.event = EV_PLAYER_TELEPORT;
@@ -1011,14 +960,14 @@ void respawn (edict_t *self)
}
// restart the entire server
- gi.AddCommandString ("menu_loadgame\n");
+ gi.AddCommandString("menu_loadgame\n");
}
-/*
+/*
* only called when pers.spectator changes
* note that resp.spectator should be the opposite of pers.spectator here
*/
-void spectator_respawn (edict_t *ent)
+void spectator_respawn(edict_t *ent)
{
int i, numspec;
@@ -1026,14 +975,14 @@ void spectator_respawn (edict_t *ent)
// exceed max_spectators
if (ent->client->pers.spectator) {
- char *value = Info_ValueForKey (ent->client->pers.userinfo, "spectator");
- if (*spectator_password->string &&
- strcmp(spectator_password->string, "none") &&
+ char *value = Info_ValueForKey(ent->client->pers.userinfo, "spectator");
+ if (*spectator_password->string &&
+ strcmp(spectator_password->string, "none") &&
strcmp(spectator_password->string, value)) {
gi.cprintf(ent, PRINT_HIGH, "Spectator password incorrect.\n");
ent->client->pers.spectator = qfalse;
- gi.WriteByte (svc_stufftext);
- gi.WriteString ("spectator 0\n");
+ gi.WriteByte(svc_stufftext);
+ gi.WriteString("spectator 0\n");
gi.unicast(ent, qtrue);
return;
}
@@ -1047,21 +996,21 @@ void spectator_respawn (edict_t *ent)
gi.cprintf(ent, PRINT_HIGH, "Server spectator limit is full.");
ent->client->pers.spectator = qfalse;
// reset his spectator var
- gi.WriteByte (svc_stufftext);
- gi.WriteString ("spectator 0\n");
+ gi.WriteByte(svc_stufftext);
+ gi.WriteString("spectator 0\n");
gi.unicast(ent, qtrue);
return;
}
} else {
// he was a spectator and wants to join the game
// he must have the right password
- char *value = Info_ValueForKey (ent->client->pers.userinfo, "password");
- if (*password->string && strcmp(password->string, "none") &&
+ char *value = Info_ValueForKey(ent->client->pers.userinfo, "password");
+ if (*password->string && strcmp(password->string, "none") &&
strcmp(password->string, value)) {
gi.cprintf(ent, PRINT_HIGH, "Password incorrect.\n");
ent->client->pers.spectator = qtrue;
- gi.WriteByte (svc_stufftext);
- gi.WriteString ("spectator 1\n");
+ gi.WriteByte(svc_stufftext);
+ gi.WriteString("spectator 1\n");
gi.unicast(ent, qtrue);
return;
}
@@ -1071,15 +1020,15 @@ void spectator_respawn (edict_t *ent)
ent->client->resp.score = ent->client->pers.score = 0;
ent->svflags &= ~SVF_NOCLIENT;
- PutClientInServer (ent);
+ PutClientInServer(ent);
// add a teleportation effect
if (!ent->client->pers.spectator) {
// send effect
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_LOGIN);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_LOGIN);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
// hold in place briefly
ent->client->ps.pmove.pm_flags = PMF_TIME_TELEPORT;
@@ -1088,10 +1037,10 @@ void spectator_respawn (edict_t *ent)
ent->client->respawn_time = level.time;
- if (ent->client->pers.spectator)
- gi.bprintf (PRINT_HIGH, "%s has moved to the sidelines\n", ent->client->pers.netname);
+ if (ent->client->pers.spectator)
+ gi.bprintf(PRINT_HIGH, "%s has moved to the sidelines\n", ent->client->pers.netname);
else
- gi.bprintf (PRINT_HIGH, "%s joined the game\n", ent->client->pers.netname);
+ gi.bprintf(PRINT_HIGH, "%s joined the game\n", ent->client->pers.netname);
}
//==============================================================
@@ -1105,9 +1054,9 @@ Called when a player connects to a server or respawns in
a deathmatch.
============
*/
-void PutClientInServer (edict_t *ent)
+void PutClientInServer(edict_t *ent)
{
- vec3_t mins = {-16, -16, -24};
+ vec3_t mins = { -16, -16, -24};
vec3_t maxs = {16, 16, 32};
int index;
vec3_t spawn_origin, spawn_angles;
@@ -1119,28 +1068,25 @@ void PutClientInServer (edict_t *ent)
// find a spawn point
// do it before setting health back up, so farthest
// ranging doesn't count this client
- SelectSpawnPoint (ent, spawn_origin, spawn_angles);
+ SelectSpawnPoint(ent, spawn_origin, spawn_angles);
- index = ent-g_edicts-1;
+ index = ent - g_edicts - 1;
client = ent->client;
// deathmatch wipes most client data every spawn
- if (deathmatch->value)
- {
+ if (deathmatch->value) {
char userinfo[MAX_INFO_STRING];
resp = client->resp;
- memcpy (userinfo, client->pers.userinfo, sizeof(userinfo));
- InitClientPersistant (client);
- ClientUserinfoChanged (ent, userinfo);
- }
- else if (coop->value)
- {
+ memcpy(userinfo, client->pers.userinfo, sizeof(userinfo));
+ InitClientPersistant(client);
+ ClientUserinfoChanged(ent, userinfo);
+ } else if (coop->value) {
// int n;
char userinfo[MAX_INFO_STRING];
resp = client->resp;
- memcpy (userinfo, client->pers.userinfo, sizeof(userinfo));
+ memcpy(userinfo, client->pers.userinfo, sizeof(userinfo));
// this is kind of ugly, but it's how we want to handle keys in coop
// for (n = 0; n < game.num_items; n++)
// {
@@ -1150,25 +1096,23 @@ void PutClientInServer (edict_t *ent)
resp.coop_respawn.game_helpchanged = client->pers.game_helpchanged;
resp.coop_respawn.helpchanged = client->pers.helpchanged;
client->pers = resp.coop_respawn;
- ClientUserinfoChanged (ent, userinfo);
+ ClientUserinfoChanged(ent, userinfo);
if (resp.score > client->pers.score)
client->pers.score = resp.score;
- }
- else
- {
- memset (&resp, 0, sizeof(resp));
+ } else {
+ memset(&resp, 0, sizeof(resp));
}
// clear everything but the persistant data
saved = client->pers;
- memset (client, 0, sizeof(*client));
+ memset(client, 0, sizeof(*client));
client->pers = saved;
if (client->pers.health <= 0)
InitClientPersistant(client);
client->resp = resp;
// copy some data from the client to the entity
- FetchClientEntData (ent);
+ FetchClientEntData(ent);
// clear entity values
ent->groundentity = NULL;
@@ -1191,23 +1135,20 @@ void PutClientInServer (edict_t *ent)
ent->flags &= ~FL_NO_KNOCKBACK;
ent->svflags &= ~SVF_DEADMONSTER;
- VectorCopy (mins, ent->mins);
- VectorCopy (maxs, ent->maxs);
- VectorClear (ent->velocity);
+ VectorCopy(mins, ent->mins);
+ VectorCopy(maxs, ent->maxs);
+ VectorClear(ent->velocity);
// clear playerstate values
- memset (&ent->client->ps, 0, sizeof(client->ps));
+ memset(&ent->client->ps, 0, sizeof(client->ps));
- client->ps.pmove.origin[0] = spawn_origin[0]*8;
- client->ps.pmove.origin[1] = spawn_origin[1]*8;
- client->ps.pmove.origin[2] = spawn_origin[2]*8;
+ client->ps.pmove.origin[0] = spawn_origin[0] * 8;
+ client->ps.pmove.origin[1] = spawn_origin[1] * 8;
+ client->ps.pmove.origin[2] = spawn_origin[2] * 8;
- if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV))
- {
+ if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV)) {
client->ps.fov = 90;
- }
- else
- {
+ } else {
client->ps.fov = atoi(Info_ValueForKey(client->pers.userinfo, "fov"));
if (client->ps.fov < 1)
client->ps.fov = 90;
@@ -1226,21 +1167,20 @@ void PutClientInServer (edict_t *ent)
ent->s.skinnum = ent - g_edicts - 1;
ent->s.frame = 0;
- VectorCopy (spawn_origin, ent->s.origin);
+ VectorCopy(spawn_origin, ent->s.origin);
ent->s.origin[2] += 1; // make sure off ground
- VectorCopy (ent->s.origin, ent->s.old_origin);
+ VectorCopy(ent->s.origin, ent->s.old_origin);
// set the delta angle
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
client->ps.pmove.delta_angles[i] = ANGLE2SHORT(spawn_angles[i] - client->resp.cmd_angles[i]);
}
ent->s.angles[PITCH] = 0;
ent->s.angles[YAW] = spawn_angles[YAW];
ent->s.angles[ROLL] = 0;
- VectorCopy (ent->s.angles, client->ps.viewangles);
- VectorCopy (ent->s.angles, client->v_angle);
+ VectorCopy(ent->s.angles, client->ps.viewangles);
+ VectorCopy(ent->s.angles, client->v_angle);
// spawn a spectator
if (client->pers.spectator) {
@@ -1252,56 +1192,53 @@ void PutClientInServer (edict_t *ent)
ent->solid = SOLID_NOT;
ent->svflags |= SVF_NOCLIENT;
ent->client->ps.gunindex = 0;
- gi.linkentity (ent);
+ gi.linkentity(ent);
return;
} else
client->resp.spectator = qfalse;
- if (!KillBox (ent))
- { // could't spawn in?
+ if (!KillBox(ent)) {
+ // could't spawn in?
}
- gi.linkentity (ent);
+ gi.linkentity(ent);
// force the current weapon up
client->newweapon = client->pers.weapon;
- ChangeWeapon (ent);
+ ChangeWeapon(ent);
}
/*
=====================
ClientBeginDeathmatch
-A client has just connected to the server in
+A client has just connected to the server in
deathmatch mode, so clear everything out before starting them.
=====================
*/
-void ClientBeginDeathmatch (edict_t *ent)
+void ClientBeginDeathmatch(edict_t *ent)
{
- G_InitEdict (ent);
+ G_InitEdict(ent);
- InitClientResp (ent->client);
+ InitClientResp(ent->client);
// locate ent at a spawn point
- PutClientInServer (ent);
+ PutClientInServer(ent);
- if (level.intermissiontime)
- {
- MoveClientToIntermission (ent);
- }
- else
- {
+ if (level.intermissiontime) {
+ MoveClientToIntermission(ent);
+ } else {
// send effect
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_LOGIN);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_LOGIN);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
}
- gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
+ gi.bprintf(PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
// make sure all view stuff is valid
- ClientEndServerFrame (ent);
+ ClientEndServerFrame(ent);
}
@@ -1313,60 +1250,52 @@ called when a client has finished connecting, and is ready
to be placed into the game. This will happen every level load.
============
*/
-void ClientBegin (edict_t *ent)
+void ClientBegin(edict_t *ent)
{
int i;
ent->client = game.clients + (ent - g_edicts - 1);
- if (deathmatch->value)
- {
- ClientBeginDeathmatch (ent);
+ if (deathmatch->value) {
+ ClientBeginDeathmatch(ent);
return;
}
// if there is already a body waiting for us (a loadgame), just
// take it, otherwise spawn one from scratch
- if (ent->inuse == qtrue)
- {
+ if (ent->inuse == qtrue) {
// the client has cleared the client side viewangles upon
// connecting to the server, which is different than the
// state when the game is saved, so we need to compensate
// with deltaangles
- for (i=0 ; i<3 ; i++)
+ for (i = 0 ; i < 3 ; i++)
ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(ent->client->ps.viewangles[i]);
- }
- else
- {
+ } else {
// a spawn point will completely reinitialize the entity
// except for the persistant data that was initialized at
// ClientConnect() time
- G_InitEdict (ent);
+ G_InitEdict(ent);
ent->classname = "player";
- InitClientResp (ent->client);
- PutClientInServer (ent);
+ InitClientResp(ent->client);
+ PutClientInServer(ent);
}
- if (level.intermissiontime)
- {
- MoveClientToIntermission (ent);
- }
- else
- {
+ if (level.intermissiontime) {
+ MoveClientToIntermission(ent);
+ } else {
// send effect if in a multiplayer game
- if (game.maxclients > 1)
- {
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_LOGIN);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
-
- gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
+ if (game.maxclients > 1) {
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_LOGIN);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
+
+ gi.bprintf(PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
}
}
// make sure all view stuff is valid
- ClientEndServerFrame (ent);
+ ClientEndServerFrame(ent);
}
/*
@@ -1379,23 +1308,22 @@ The game can override any of the settings in place
(forcing skins or names, etc) before copying it off.
============
*/
-void ClientUserinfoChanged (edict_t *ent, char *userinfo)
+void ClientUserinfoChanged(edict_t *ent, char *userinfo)
{
char *s;
int playernum;
// check for malformed or illegal info strings
- if (!Info_Validate(userinfo))
- {
- strcpy (userinfo, "\\name\\badinfo\\skin\\male/grunt");
+ if (!Info_Validate(userinfo)) {
+ strcpy(userinfo, "\\name\\badinfo\\skin\\male/grunt");
}
// set name
- s = Info_ValueForKey (userinfo, "name");
- strncpy (ent->client->pers.netname, s, sizeof(ent->client->pers.netname)-1);
+ s = Info_ValueForKey(userinfo, "name");
+ strncpy(ent->client->pers.netname, s, sizeof(ent->client->pers.netname) - 1);
// set spectator
- s = Info_ValueForKey (userinfo, "spectator");
+ s = Info_ValueForKey(userinfo, "spectator");
// spectators are only supported in deathmatch
if (deathmatch->value && *s && strcmp(s, "0"))
ent->client->pers.spectator = qtrue;
@@ -1403,20 +1331,17 @@ void ClientUserinfoChanged (edict_t *ent, char *userinfo)
ent->client->pers.spectator = qfalse;
// set skin
- s = Info_ValueForKey (userinfo, "skin");
+ s = Info_ValueForKey(userinfo, "skin");
- playernum = ent-g_edicts-1;
+ playernum = ent - g_edicts - 1;
// combine name and skin into a configstring
- gi.configstring (CS_PLAYERSKINS+playernum, va("%s\\%s", ent->client->pers.netname, s) );
+ gi.configstring(CS_PLAYERSKINS + playernum, va("%s\\%s", ent->client->pers.netname, s));
// fov
- if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV))
- {
+ if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV)) {
ent->client->ps.fov = 90;
- }
- else
- {
+ } else {
ent->client->ps.fov = atoi(Info_ValueForKey(userinfo, "fov"));
if (ent->client->ps.fov < 1)
ent->client->ps.fov = 90;
@@ -1425,14 +1350,13 @@ void ClientUserinfoChanged (edict_t *ent, char *userinfo)
}
// handedness
- s = Info_ValueForKey (userinfo, "hand");
- if (strlen(s))
- {
+ s = Info_ValueForKey(userinfo, "hand");
+ if (strlen(s)) {
ent->client->pers.hand = atoi(s);
}
// save off the userinfo in case we want to check something later
- strncpy (ent->client->pers.userinfo, userinfo, sizeof(ent->client->pers.userinfo)-1);
+ strncpy(ent->client->pers.userinfo, userinfo, sizeof(ent->client->pers.userinfo) - 1);
}
@@ -1448,24 +1372,24 @@ Changing levels will NOT cause this to be called again, but
loadgames will.
============
*/
-qboolean ClientConnect (edict_t *ent, char *userinfo)
+qboolean ClientConnect(edict_t *ent, char *userinfo)
{
char *value;
// check to see if they are on the banned IP list
- value = Info_ValueForKey (userinfo, "ip");
+ value = Info_ValueForKey(userinfo, "ip");
if (SV_FilterPacket(value)) {
Info_SetValueForKey(userinfo, "rejmsg", "Banned.");
return qfalse;
}
// check for a spectator
- value = Info_ValueForKey (userinfo, "spectator");
+ value = Info_ValueForKey(userinfo, "spectator");
if (deathmatch->value && *value && strcmp(value, "0")) {
int i, numspec;
- if (*spectator_password->string &&
- strcmp(spectator_password->string, "none") &&
+ if (*spectator_password->string &&
+ strcmp(spectator_password->string, "none") &&
strcmp(spectator_password->string, value)) {
Info_SetValueForKey(userinfo, "rejmsg", "Spectator password required or incorrect.");
return qfalse;
@@ -1473,7 +1397,7 @@ qboolean ClientConnect (edict_t *ent, char *userinfo)
// count spectators
for (i = numspec = 0; i < maxclients->value; i++)
- if (g_edicts[i+1].inuse && g_edicts[i+1].client->pers.spectator)
+ if (g_edicts[i + 1].inuse && g_edicts[i + 1].client->pers.spectator)
numspec++;
if (numspec >= maxspectators->value) {
@@ -1482,8 +1406,8 @@ qboolean ClientConnect (edict_t *ent, char *userinfo)
}
} else {
// check for a password
- value = Info_ValueForKey (userinfo, "password");
- if (*password->string && strcmp(password->string, "none") &&
+ value = Info_ValueForKey(userinfo, "password");
+ if (*password->string && strcmp(password->string, "none") &&
strcmp(password->string, value)) {
Info_SetValueForKey(userinfo, "rejmsg", "Password required or incorrect.");
return qfalse;
@@ -1496,18 +1420,17 @@ qboolean ClientConnect (edict_t *ent, char *userinfo)
// if there is already a body waiting for us (a loadgame), just
// take it, otherwise spawn one from scratch
- if (ent->inuse == qfalse)
- {
+ if (ent->inuse == qfalse) {
// clear the respawning variables
- InitClientResp (ent->client);
+ InitClientResp(ent->client);
if (!game.autosaved || !ent->client->pers.weapon)
- InitClientPersistant (ent->client);
+ InitClientPersistant(ent->client);
}
- ClientUserinfoChanged (ent, userinfo);
+ ClientUserinfoChanged(ent, userinfo);
if (game.maxclients > 1)
- gi.dprintf ("%s connected\n", ent->client->pers.netname);
+ gi.dprintf("%s connected\n", ent->client->pers.netname);
ent->svflags = 0; // make sure we start with known default
ent->client->pers.connected = qtrue;
@@ -1522,22 +1445,22 @@ Called when a player drops from the server.
Will not be called between levels.
============
*/
-void ClientDisconnect (edict_t *ent)
+void ClientDisconnect(edict_t *ent)
{
//int playernum;
if (!ent->client)
return;
- gi.bprintf (PRINT_HIGH, "%s disconnected\n", ent->client->pers.netname);
+ gi.bprintf(PRINT_HIGH, "%s disconnected\n", ent->client->pers.netname);
// send effect
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_LOGOUT);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_LOGOUT);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
- gi.unlinkentity (ent);
+ gi.unlinkentity(ent);
ent->s.modelindex = 0;
ent->s.sound = 0;
ent->s.event = 0;
@@ -1559,29 +1482,29 @@ void ClientDisconnect (edict_t *ent)
edict_t *pm_passent;
// pmove doesn't need to know about passent and contentmask
-trace_t PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
+trace_t PM_trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
{
if (pm_passent->health > 0)
- return gi.trace (start, mins, maxs, end, pm_passent, MASK_PLAYERSOLID);
+ return gi.trace(start, mins, maxs, end, pm_passent, MASK_PLAYERSOLID);
else
- return gi.trace (start, mins, maxs, end, pm_passent, MASK_DEADSOLID);
+ return gi.trace(start, mins, maxs, end, pm_passent, MASK_DEADSOLID);
}
-unsigned CheckBlock (void *b, int c)
+unsigned CheckBlock(void *b, int c)
{
- int v,i;
+ int v, i;
v = 0;
- for (i=0 ; i<c ; i++)
- v+= ((byte *)b)[i];
+ for (i = 0 ; i < c ; i++)
+ v += ((byte *)b)[i];
return v;
}
-void PrintPmove (pmove_t *pm)
+void PrintPmove(pmove_t *pm)
{
unsigned c1, c2;
- c1 = CheckBlock (&pm->s, sizeof(pm->s));
- c2 = CheckBlock (&pm->cmd, sizeof(pm->cmd));
- Com_Printf ("sv %3i:%i %i\n", pm->cmd.impulse, c1, c2);
+ c1 = CheckBlock(&pm->s, sizeof(pm->s));
+ c2 = CheckBlock(&pm->cmd, sizeof(pm->cmd));
+ Com_Printf("sv %3i:%i %i\n", pm->cmd.impulse, c1, c2);
}
/*
@@ -1592,7 +1515,7 @@ This will be called once for each client frame, which will
usually be a couple times for each server frame.
==============
*/
-void ClientThink (edict_t *ent, usercmd_t *ucmd)
+void ClientThink(edict_t *ent, usercmd_t *ucmd)
{
gclient_t *client;
edict_t *other;
@@ -1602,12 +1525,11 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
level.current_entity = ent;
client = ent->client;
- if (level.intermissiontime)
- {
+ if (level.intermissiontime) {
client->ps.pmove.pm_type = PM_FREEZE;
// can exit intermission after five seconds
- if (level.time > level.intermissiontime + 5.0
- && (ucmd->buttons & BUTTON_ANY) )
+ if (level.time > level.intermissiontime + 5.0
+ && (ucmd->buttons & BUTTON_ANY))
level.exitintermission = qtrue;
return;
}
@@ -1623,7 +1545,7 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
} else {
// set up for pmove
- memset (&pm, 0, sizeof(pm));
+ memset(&pm, 0, sizeof(pm));
if (ent->movetype == MOVETYPE_NOCLIP)
client->ps.pmove.pm_type = PM_SPECTATOR;
@@ -1637,16 +1559,14 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
client->ps.pmove.gravity = sv_gravity->value;
pm.s = client->ps.pmove;
- for (i=0 ; i<3 ; i++)
- {
- pm.s.origin[i] = ent->s.origin[i]*8;
- pm.s.velocity[i] = ent->velocity[i]*8;
+ for (i = 0 ; i < 3 ; i++) {
+ pm.s.origin[i] = ent->s.origin[i] * 8;
+ pm.s.velocity[i] = ent->velocity[i] * 8;
}
- if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))
- {
+ if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s))) {
pm.snapinitial = qtrue;
- // gi.dprintf ("pmove changed!\n");
+ // gi.dprintf ("pmove changed!\n");
}
pm.cmd = *ucmd;
@@ -1655,27 +1575,25 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
pm.pointcontents = gi.pointcontents;
// perform a pmove
- gi.Pmove (&pm);
+ gi.Pmove(&pm);
// save results of pmove
client->ps.pmove = pm.s;
client->old_pmove = pm.s;
- for (i=0 ; i<3 ; i++)
- {
- ent->s.origin[i] = pm.s.origin[i]*0.125;
- ent->velocity[i] = pm.s.velocity[i]*0.125;
+ for (i = 0 ; i < 3 ; i++) {
+ ent->s.origin[i] = pm.s.origin[i] * 0.125;
+ ent->velocity[i] = pm.s.velocity[i] * 0.125;
}
- VectorCopy (pm.mins, ent->mins);
- VectorCopy (pm.maxs, ent->maxs);
+ VectorCopy(pm.mins, ent->mins);
+ VectorCopy(pm.maxs, ent->maxs);
client->resp.cmd_angles[0] = SHORT2ANGLE(ucmd->angles[0]);
client->resp.cmd_angles[1] = SHORT2ANGLE(ucmd->angles[1]);
client->resp.cmd_angles[2] = SHORT2ANGLE(ucmd->angles[2]);
- if (ent->groundentity && !pm.groundentity && (pm.cmd.upmove >= 10) && (pm.waterlevel == 0))
- {
+ if (ent->groundentity && !pm.groundentity && (pm.cmd.upmove >= 10) && (pm.waterlevel == 0)) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
PlayerNoise(ent, ent->s.origin, PNOISE_SELF);
}
@@ -1687,35 +1605,31 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
if (pm.groundentity)
ent->groundentity_linkcount = pm.groundentity->linkcount;
- if (ent->deadflag)
- {
+ if (ent->deadflag) {
client->ps.viewangles[ROLL] = 40;
client->ps.viewangles[PITCH] = -15;
client->ps.viewangles[YAW] = client->killer_yaw;
- }
- else
- {
- VectorCopy (pm.viewangles, client->v_angle);
- VectorCopy (pm.viewangles, client->ps.viewangles);
+ } else {
+ VectorCopy(pm.viewangles, client->v_angle);
+ VectorCopy(pm.viewangles, client->ps.viewangles);
}
- gi.linkentity (ent);
+ gi.linkentity(ent);
if (ent->movetype != MOVETYPE_NOCLIP)
- G_TouchTriggers (ent);
+ G_TouchTriggers(ent);
// touch other objects
- for (i=0 ; i<pm.numtouch ; i++)
- {
+ for (i = 0 ; i < pm.numtouch ; i++) {
other = pm.touchents[i];
- for (j=0 ; j<i ; j++)
+ for (j = 0 ; j < i ; j++)
if (pm.touchents[j] == other)
break;
if (j != i)
continue; // duplicated
if (!other->touch)
continue;
- other->touch (other, ent, NULL, NULL);
+ other->touch(other, ent, NULL, NULL);
}
}
@@ -1729,8 +1643,7 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
ent->light_level = ucmd->lightlevel;
// fire weapon from final position if needed
- if (client->latched_buttons & BUTTON_ATTACK)
- {
+ if (client->latched_buttons & BUTTON_ATTACK) {
if (client->resp.spectator) {
client->latched_buttons = 0;
@@ -1743,7 +1656,7 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
} else if (!client->weapon_thunk) {
client->weapon_thunk = qtrue;
- Think_Weapon (ent);
+ Think_Weapon(ent);
}
}
@@ -1777,7 +1690,7 @@ This will be called once for each server frame, before running
any other entities in the world.
==============
*/
-void ClientBeginServerFrame (edict_t *ent)
+void ClientBeginServerFrame(edict_t *ent)
{
gclient_t *client;
int buttonMask;
@@ -1796,24 +1709,21 @@ void ClientBeginServerFrame (edict_t *ent)
// run weapon animations if it hasn't been done by a ucmd_t
if (!client->weapon_thunk && !client->resp.spectator)
- Think_Weapon (ent);
+ Think_Weapon(ent);
else
client->weapon_thunk = qfalse;
- if (ent->deadflag)
- {
+ if (ent->deadflag) {
// wait for any button just going down
- if ( level.time > client->respawn_time)
- {
+ if (level.time > client->respawn_time) {
// in deathmatch, only wait for attack button
if (deathmatch->value)
buttonMask = BUTTON_ATTACK;
else
buttonMask = -1;
- if ( ( client->latched_buttons & buttonMask ) ||
- (deathmatch->value && ((int)dmflags->value & DF_FORCE_RESPAWN) ) )
- {
+ if ((client->latched_buttons & buttonMask) ||
+ (deathmatch->value && ((int)dmflags->value & DF_FORCE_RESPAWN))) {
respawn(ent);
client->latched_buttons = 0;
}
@@ -1823,8 +1733,8 @@ void ClientBeginServerFrame (edict_t *ent)
// add player trail so monsters can follow
if (!deathmatch->value)
- if (!visible (ent, PlayerTrail_LastSpot() ) )
- PlayerTrail_Add (ent->s.old_origin);
+ if (!visible(ent, PlayerTrail_LastSpot()))
+ PlayerTrail_Add(ent->s.old_origin);
client->latched_buttons = 0;
}
diff --git a/src/baseq2/p_hud.c b/src/baseq2/p_hud.c
index c3c7ab2..060e969 100644
--- a/src/baseq2/p_hud.c
+++ b/src/baseq2/p_hud.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,15 +29,15 @@ INTERMISSION
======================================================================
*/
-void MoveClientToIntermission (edict_t *ent)
+void MoveClientToIntermission(edict_t *ent)
{
if (deathmatch->value || coop->value)
ent->client->showscores = qtrue;
- VectorCopy (level.intermission_origin, ent->s.origin);
- ent->client->ps.pmove.origin[0] = level.intermission_origin[0]*8;
- ent->client->ps.pmove.origin[1] = level.intermission_origin[1]*8;
- ent->client->ps.pmove.origin[2] = level.intermission_origin[2]*8;
- VectorCopy (level.intermission_angle, ent->client->ps.viewangles);
+ VectorCopy(level.intermission_origin, ent->s.origin);
+ ent->client->ps.pmove.origin[0] = level.intermission_origin[0] * 8;
+ ent->client->ps.pmove.origin[1] = level.intermission_origin[1] * 8;
+ ent->client->ps.pmove.origin[2] = level.intermission_origin[2] * 8;
+ VectorCopy(level.intermission_angle, ent->client->ps.viewangles);
ent->client->ps.pmove.pm_type = PM_FREEZE;
ent->client->ps.gunindex = 0;
ent->client->ps.blend[3] = 0;
@@ -62,15 +62,14 @@ void MoveClientToIntermission (edict_t *ent)
// add the layout
- if (deathmatch->value || coop->value)
- {
- DeathmatchScoreboardMessage (ent, NULL);
- gi.unicast (ent, qtrue);
+ if (deathmatch->value || coop->value) {
+ DeathmatchScoreboardMessage(ent, NULL);
+ gi.unicast(ent, qtrue);
}
}
-void BeginIntermission (edict_t *targ)
+void BeginIntermission(edict_t *targ)
{
int i, n;
edict_t *ent, *client;
@@ -81,8 +80,7 @@ void BeginIntermission (edict_t *targ)
game.autosaved = qfalse;
// respawn any dead clients
- for (i=0 ; i<maxclients->value ; i++)
- {
+ for (i = 0 ; i < maxclients->value ; i++) {
client = g_edicts + 1 + i;
if (!client->inuse)
continue;
@@ -93,28 +91,21 @@ void BeginIntermission (edict_t *targ)
level.intermissiontime = level.time;
level.changemap = targ->map;
- if (strstr(level.changemap, "*"))
- {
- if (coop->value)
- {
- for (i=0 ; i<maxclients->value ; i++)
- {
+ if (strstr(level.changemap, "*")) {
+ if (coop->value) {
+ for (i = 0 ; i < maxclients->value ; i++) {
client = g_edicts + 1 + i;
if (!client->inuse)
continue;
// strip players of all keys between units
- for (n = 0; n < MAX_ITEMS; n++)
- {
+ for (n = 0; n < MAX_ITEMS; n++) {
if (itemlist[n].flags & IT_KEY)
client->client->pers.inventory[n] = 0;
}
}
}
- }
- else
- {
- if (!deathmatch->value)
- {
+ } else {
+ if (!deathmatch->value) {
level.exitintermission = 1; // go immediately to the next level
return;
}
@@ -123,34 +114,31 @@ void BeginIntermission (edict_t *targ)
level.exitintermission = 0;
// find an intermission spot
- ent = G_Find (NULL, FOFS(classname), "info_player_intermission");
- if (!ent)
- { // the map creator forgot to put in an intermission point...
- ent = G_Find (NULL, FOFS(classname), "info_player_start");
+ ent = G_Find(NULL, FOFS(classname), "info_player_intermission");
+ if (!ent) {
+ // the map creator forgot to put in an intermission point...
+ ent = G_Find(NULL, FOFS(classname), "info_player_start");
if (!ent)
- ent = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
- }
- else
- { // chose one of four spots
+ ent = G_Find(NULL, FOFS(classname), "info_player_deathmatch");
+ } else {
+ // chose one of four spots
i = rand() & 3;
- while (i--)
- {
- ent = G_Find (ent, FOFS(classname), "info_player_intermission");
+ while (i--) {
+ ent = G_Find(ent, FOFS(classname), "info_player_intermission");
if (!ent) // wrap around the list
- ent = G_Find (ent, FOFS(classname), "info_player_intermission");
+ ent = G_Find(ent, FOFS(classname), "info_player_intermission");
}
}
- VectorCopy (ent->s.origin, level.intermission_origin);
- VectorCopy (ent->s.angles, level.intermission_angle);
+ VectorCopy(ent->s.origin, level.intermission_origin);
+ VectorCopy(ent->s.angles, level.intermission_angle);
// move all clients to the intermission point
- for (i=0 ; i<maxclients->value ; i++)
- {
+ for (i = 0 ; i < maxclients->value ; i++) {
client = g_edicts + 1 + i;
if (!client->inuse)
continue;
- MoveClientToIntermission (client);
+ MoveClientToIntermission(client);
}
}
@@ -161,7 +149,7 @@ DeathmatchScoreboardMessage
==================
*/
-void DeathmatchScoreboardMessage (edict_t *ent, edict_t *killer)
+void DeathmatchScoreboardMessage(edict_t *ent, edict_t *killer)
{
char entry[1024];
char string[1400];
@@ -178,21 +166,18 @@ void DeathmatchScoreboardMessage (edict_t *ent, edict_t *killer)
// sort the clients by score
total = 0;
- for (i=0 ; i<game.maxclients ; i++)
- {
+ for (i = 0 ; i < game.maxclients ; i++) {
cl_ent = g_edicts + 1 + i;
if (!cl_ent->inuse || game.clients[i].resp.spectator)
continue;
score = game.clients[i].resp.score;
- for (j=0 ; j<total ; j++)
- {
+ for (j = 0 ; j < total ; j++) {
if (score > sortedscores[j])
break;
}
- for (k=total ; k>j ; k--)
- {
- sorted[k] = sorted[k-1];
- sortedscores[k] = sortedscores[k-1];
+ for (k = total ; k > j ; k--) {
+ sorted[k] = sorted[k - 1];
+ sortedscores[k] = sortedscores[k - 1];
}
sorted[j] = i;
sortedscores[j] = score;
@@ -208,14 +193,13 @@ void DeathmatchScoreboardMessage (edict_t *ent, edict_t *killer)
if (total > 12)
total = 12;
- for (i=0 ; i<total ; i++)
- {
+ for (i = 0 ; i < total ; i++) {
cl = &game.clients[sorted[i]];
cl_ent = g_edicts + 1 + sorted[i];
- picnum = gi.imageindex ("i_fixme");
- x = (i>=6) ? 160 : 0;
- y = 32 + 32 * (i%6);
+ picnum = gi.imageindex("i_fixme");
+ x = (i >= 6) ? 160 : 0;
+ y = 32 + 32 * (i % 6);
// add a dogtag
if (cl_ent == ent)
@@ -224,30 +208,29 @@ void DeathmatchScoreboardMessage (edict_t *ent, edict_t *killer)
tag = "tag2";
else
tag = NULL;
- if (tag)
- {
- Q_snprintf (entry, sizeof(entry),
- "xv %i yv %i picn %s ",x+32, y, tag);
+ if (tag) {
+ Q_snprintf(entry, sizeof(entry),
+ "xv %i yv %i picn %s ", x + 32, y, tag);
j = strlen(entry);
if (stringlength + j > 1024)
break;
- strcpy (string + stringlength, entry);
+ strcpy(string + stringlength, entry);
stringlength += j;
}
// send the layout
- Q_snprintf (entry, sizeof(entry),
- "client %i %i %i %i %i %i ",
- x, y, sorted[i], cl->resp.score, cl->ping, (level.framenum - cl->resp.enterframe)/600);
+ Q_snprintf(entry, sizeof(entry),
+ "client %i %i %i %i %i %i ",
+ x, y, sorted[i], cl->resp.score, cl->ping, (level.framenum - cl->resp.enterframe) / 600);
j = strlen(entry);
if (stringlength + j > 1024)
break;
- strcpy (string + stringlength, entry);
+ strcpy(string + stringlength, entry);
stringlength += j;
}
- gi.WriteByte (svc_layout);
- gi.WriteString (string);
+ gi.WriteByte(svc_layout);
+ gi.WriteString(string);
}
@@ -259,10 +242,10 @@ Draw instead of help message.
Note that it isn't that hard to overflow the 1400 byte message limit!
==================
*/
-void DeathmatchScoreboard (edict_t *ent)
+void DeathmatchScoreboard(edict_t *ent)
{
- DeathmatchScoreboardMessage (ent, ent->enemy);
- gi.unicast (ent, qtrue);
+ DeathmatchScoreboardMessage(ent, ent->enemy);
+ gi.unicast(ent, qtrue);
}
@@ -273,7 +256,7 @@ Cmd_Score_f
Display the scoreboard
==================
*/
-void Cmd_Score_f (edict_t *ent)
+void Cmd_Score_f(edict_t *ent)
{
ent->client->showinventory = qfalse;
ent->client->showhelp = qfalse;
@@ -281,14 +264,13 @@ void Cmd_Score_f (edict_t *ent)
if (!deathmatch->value && !coop->value)
return;
- if (ent->client->showscores)
- {
+ if (ent->client->showscores) {
ent->client->showscores = qfalse;
return;
}
ent->client->showscores = qtrue;
- DeathmatchScoreboard (ent);
+ DeathmatchScoreboard(ent);
}
@@ -299,7 +281,7 @@ HelpComputer
Draw help computer.
==================
*/
-void HelpComputer (edict_t *ent)
+void HelpComputer(edict_t *ent)
{
char string[1024];
char *sk;
@@ -314,25 +296,25 @@ void HelpComputer (edict_t *ent)
sk = "hard+";
// send the layout
- Q_snprintf (string, sizeof(string),
- "xv 32 yv 8 picn help " // background
- "xv 202 yv 12 string2 \"%s\" " // skill
- "xv 0 yv 24 cstring2 \"%s\" " // level name
- "xv 0 yv 54 cstring2 \"%s\" " // help 1
- "xv 0 yv 110 cstring2 \"%s\" " // help 2
- "xv 50 yv 164 string2 \" kills goals secrets\" "
- "xv 50 yv 172 string2 \"%3i/%3i %i/%i %i/%i\" ",
- sk,
- level.level_name,
- game.helpmessage1,
- game.helpmessage2,
- level.killed_monsters, level.total_monsters,
- level.found_goals, level.total_goals,
- level.found_secrets, level.total_secrets);
-
- gi.WriteByte (svc_layout);
- gi.WriteString (string);
- gi.unicast (ent, qtrue);
+ Q_snprintf(string, sizeof(string),
+ "xv 32 yv 8 picn help " // background
+ "xv 202 yv 12 string2 \"%s\" " // skill
+ "xv 0 yv 24 cstring2 \"%s\" " // level name
+ "xv 0 yv 54 cstring2 \"%s\" " // help 1
+ "xv 0 yv 110 cstring2 \"%s\" " // help 2
+ "xv 50 yv 164 string2 \" kills goals secrets\" "
+ "xv 50 yv 172 string2 \"%3i/%3i %i/%i %i/%i\" ",
+ sk,
+ level.level_name,
+ game.helpmessage1,
+ game.helpmessage2,
+ level.killed_monsters, level.total_monsters,
+ level.found_goals, level.total_goals,
+ level.found_secrets, level.total_secrets);
+
+ gi.WriteByte(svc_layout);
+ gi.WriteString(string);
+ gi.unicast(ent, qtrue);
}
@@ -343,27 +325,25 @@ Cmd_Help_f
Display the current help message
==================
*/
-void Cmd_Help_f (edict_t *ent)
+void Cmd_Help_f(edict_t *ent)
{
// this is for backwards compatability
- if (deathmatch->value)
- {
- Cmd_Score_f (ent);
+ if (deathmatch->value) {
+ Cmd_Score_f(ent);
return;
}
ent->client->showinventory = qfalse;
ent->client->showscores = qfalse;
- if (ent->client->showhelp && (ent->client->pers.game_helpchanged == game.helpchanged))
- {
+ if (ent->client->showhelp && (ent->client->pers.game_helpchanged == game.helpchanged)) {
ent->client->showhelp = qfalse;
return;
}
ent->client->showhelp = qtrue;
ent->client->pers.helpchanged = 0;
- HelpComputer (ent);
+ HelpComputer(ent);
}
@@ -374,7 +354,7 @@ void Cmd_Help_f (edict_t *ent)
G_SetStats
===============
*/
-void G_SetStats (edict_t *ent)
+void G_SetStats(edict_t *ent)
{
gitem_t *item;
int index, cells;
@@ -389,47 +369,39 @@ void G_SetStats (edict_t *ent)
//
// ammo
//
- if (!ent->client->ammo_index /* || !ent->client->pers.inventory[ent->client->ammo_index] */)
- {
+ if (!ent->client->ammo_index /* || !ent->client->pers.inventory[ent->client->ammo_index] */) {
ent->client->ps.stats[STAT_AMMO_ICON] = 0;
ent->client->ps.stats[STAT_AMMO] = 0;
- }
- else
- {
+ } else {
item = &itemlist[ent->client->ammo_index];
- ent->client->ps.stats[STAT_AMMO_ICON] = gi.imageindex (item->icon);
+ ent->client->ps.stats[STAT_AMMO_ICON] = gi.imageindex(item->icon);
ent->client->ps.stats[STAT_AMMO] = ent->client->pers.inventory[ent->client->ammo_index];
}
-
+
//
// armor
//
- power_armor_type = PowerArmorType (ent);
- if (power_armor_type)
- {
- cells = ent->client->pers.inventory[ITEM_INDEX(FindItem ("cells"))];
- if (cells == 0)
- { // ran out of cells for power armor
+ power_armor_type = PowerArmorType(ent);
+ if (power_armor_type) {
+ cells = ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))];
+ if (cells == 0) {
+ // ran out of cells for power armor
ent->flags &= ~FL_POWER_ARMOR;
gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/power2.wav"), 1, ATTN_NORM, 0);
power_armor_type = 0;;
}
}
- index = ArmorIndex (ent);
- if (power_armor_type && (!index || (level.framenum & 8) ) )
- { // flash between power armor and other armor icon
- ent->client->ps.stats[STAT_ARMOR_ICON] = gi.imageindex ("i_powershield");
+ index = ArmorIndex(ent);
+ if (power_armor_type && (!index || (level.framenum & 8))) {
+ // flash between power armor and other armor icon
+ ent->client->ps.stats[STAT_ARMOR_ICON] = gi.imageindex("i_powershield");
ent->client->ps.stats[STAT_ARMOR] = cells;
- }
- else if (index)
- {
- item = GetItemByIndex (index);
- ent->client->ps.stats[STAT_ARMOR_ICON] = gi.imageindex (item->icon);
+ } else if (index) {
+ item = GetItemByIndex(index);
+ ent->client->ps.stats[STAT_ARMOR_ICON] = gi.imageindex(item->icon);
ent->client->ps.stats[STAT_ARMOR] = ent->client->pers.inventory[index];
- }
- else
- {
+ } else {
ent->client->ps.stats[STAT_ARMOR_ICON] = 0;
ent->client->ps.stats[STAT_ARMOR] = 0;
}
@@ -437,8 +409,7 @@ void G_SetStats (edict_t *ent)
//
// pickup message
//
- if (level.time > ent->client->pickup_msg_time)
- {
+ if (level.time > ent->client->pickup_msg_time) {
ent->client->ps.stats[STAT_PICKUP_ICON] = 0;
ent->client->ps.stats[STAT_PICKUP_STRING] = 0;
}
@@ -446,28 +417,19 @@ void G_SetStats (edict_t *ent)
//
// timers
//
- if (ent->client->quad_framenum > level.framenum)
- {
- ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_quad");
- ent->client->ps.stats[STAT_TIMER] = (ent->client->quad_framenum - level.framenum)/10;
- }
- else if (ent->client->invincible_framenum > level.framenum)
- {
- ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_invulnerability");
- ent->client->ps.stats[STAT_TIMER] = (ent->client->invincible_framenum - level.framenum)/10;
- }
- else if (ent->client->enviro_framenum > level.framenum)
- {
- ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_envirosuit");
- ent->client->ps.stats[STAT_TIMER] = (ent->client->enviro_framenum - level.framenum)/10;
- }
- else if (ent->client->breather_framenum > level.framenum)
- {
- ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_rebreather");
- ent->client->ps.stats[STAT_TIMER] = (ent->client->breather_framenum - level.framenum)/10;
- }
- else
- {
+ if (ent->client->quad_framenum > level.framenum) {
+ ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_quad");
+ ent->client->ps.stats[STAT_TIMER] = (ent->client->quad_framenum - level.framenum) / 10;
+ } else if (ent->client->invincible_framenum > level.framenum) {
+ ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_invulnerability");
+ ent->client->ps.stats[STAT_TIMER] = (ent->client->invincible_framenum - level.framenum) / 10;
+ } else if (ent->client->enviro_framenum > level.framenum) {
+ ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_envirosuit");
+ ent->client->ps.stats[STAT_TIMER] = (ent->client->enviro_framenum - level.framenum) / 10;
+ } else if (ent->client->breather_framenum > level.framenum) {
+ ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_rebreather");
+ ent->client->ps.stats[STAT_TIMER] = (ent->client->breather_framenum - level.framenum) / 10;
+ } else {
ent->client->ps.stats[STAT_TIMER_ICON] = 0;
ent->client->ps.stats[STAT_TIMER] = 0;
}
@@ -478,7 +440,7 @@ void G_SetStats (edict_t *ent)
if (ent->client->pers.selected_item == -1)
ent->client->ps.stats[STAT_SELECTED_ICON] = 0;
else
- ent->client->ps.stats[STAT_SELECTED_ICON] = gi.imageindex (itemlist[ent->client->pers.selected_item].icon);
+ ent->client->ps.stats[STAT_SELECTED_ICON] = gi.imageindex(itemlist[ent->client->pers.selected_item].icon);
ent->client->ps.stats[STAT_SELECTED_ITEM] = ent->client->pers.selected_item;
@@ -487,16 +449,13 @@ void G_SetStats (edict_t *ent)
//
ent->client->ps.stats[STAT_LAYOUTS] = 0;
- if (deathmatch->value)
- {
+ if (deathmatch->value) {
if (ent->client->pers.health <= 0 || level.intermissiontime
|| ent->client->showscores)
ent->client->ps.stats[STAT_LAYOUTS] |= 1;
if (ent->client->showinventory && ent->client->pers.health > 0)
ent->client->ps.stats[STAT_LAYOUTS] |= 2;
- }
- else
- {
+ } else {
if (ent->client->showscores || ent->client->showhelp)
ent->client->ps.stats[STAT_LAYOUTS] |= 1;
if (ent->client->showinventory && ent->client->pers.health > 0)
@@ -511,11 +470,11 @@ void G_SetStats (edict_t *ent)
//
// help icon / current weapon if not shown
//
- if (ent->client->pers.helpchanged && (level.framenum&8) )
- ent->client->ps.stats[STAT_HELPICON] = gi.imageindex ("i_help");
- else if ( (ent->client->pers.hand == CENTER_HANDED || ent->client->ps.fov > 91)
- && ent->client->pers.weapon)
- ent->client->ps.stats[STAT_HELPICON] = gi.imageindex (ent->client->pers.weapon->icon);
+ if (ent->client->pers.helpchanged && (level.framenum & 8))
+ ent->client->ps.stats[STAT_HELPICON] = gi.imageindex("i_help");
+ else if ((ent->client->pers.hand == CENTER_HANDED || ent->client->ps.fov > 91)
+ && ent->client->pers.weapon)
+ ent->client->ps.stats[STAT_HELPICON] = gi.imageindex(ent->client->pers.weapon->icon);
else
ent->client->ps.stats[STAT_HELPICON] = 0;
@@ -527,7 +486,7 @@ void G_SetStats (edict_t *ent)
G_CheckChaseStats
===============
*/
-void G_CheckChaseStats (edict_t *ent)
+void G_CheckChaseStats(edict_t *ent)
{
int i;
gclient_t *cl;
@@ -546,12 +505,12 @@ void G_CheckChaseStats (edict_t *ent)
G_SetSpectatorStats
===============
*/
-void G_SetSpectatorStats (edict_t *ent)
+void G_SetSpectatorStats(edict_t *ent)
{
gclient_t *cl = ent->client;
if (!cl->chase_target)
- G_SetStats (ent);
+ G_SetStats(ent);
cl->ps.stats[STAT_SPECTATOR] = 1;
@@ -563,8 +522,8 @@ void G_SetSpectatorStats (edict_t *ent)
cl->ps.stats[STAT_LAYOUTS] |= 2;
if (cl->chase_target && cl->chase_target->inuse)
- cl->ps.stats[STAT_CHASE] = CS_PLAYERSKINS +
- (cl->chase_target - g_edicts) - 1;
+ cl->ps.stats[STAT_CHASE] = CS_PLAYERSKINS +
+ (cl->chase_target - g_edicts) - 1;
else
cl->ps.stats[STAT_CHASE] = 0;
}
diff --git a/src/baseq2/p_trail.c b/src/baseq2/p_trail.c
index 07828b4..dbdee4b 100644
--- a/src/baseq2/p_trail.c
+++ b/src/baseq2/p_trail.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -46,15 +46,14 @@ qboolean trail_active = qfalse;
#define PREV(n) (((n) - 1) & (TRAIL_LENGTH - 1))
-void PlayerTrail_Init (void)
+void PlayerTrail_Init(void)
{
int n;
if (deathmatch->value /* FIXME || coop */)
return;
- for (n = 0; n < TRAIL_LENGTH; n++)
- {
+ for (n = 0; n < TRAIL_LENGTH; n++) {
trail[n] = G_Spawn();
trail[n]->classname = "player_trail";
}
@@ -64,35 +63,35 @@ void PlayerTrail_Init (void)
}
-void PlayerTrail_Add (vec3_t spot)
+void PlayerTrail_Add(vec3_t spot)
{
vec3_t temp;
if (!trail_active)
return;
- VectorCopy (spot, trail[trail_head]->s.origin);
+ VectorCopy(spot, trail[trail_head]->s.origin);
trail[trail_head]->timestamp = level.time;
- VectorSubtract (spot, trail[PREV(trail_head)]->s.origin, temp);
- trail[trail_head]->s.angles[1] = vectoyaw (temp);
+ VectorSubtract(spot, trail[PREV(trail_head)]->s.origin, temp);
+ trail[trail_head]->s.angles[1] = vectoyaw(temp);
trail_head = NEXT(trail_head);
}
-void PlayerTrail_New (vec3_t spot)
+void PlayerTrail_New(vec3_t spot)
{
if (!trail_active)
return;
- PlayerTrail_Init ();
- PlayerTrail_Add (spot);
+ PlayerTrail_Init();
+ PlayerTrail_Add(spot);
}
-edict_t *PlayerTrail_PickFirst (edict_t *self)
+edict_t *PlayerTrail_PickFirst(edict_t *self)
{
int marker;
int n;
@@ -100,28 +99,25 @@ edict_t *PlayerTrail_PickFirst (edict_t *self)
if (!trail_active)
return NULL;
- for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
- {
- if(trail[marker]->timestamp <= self->monsterinfo.trail_time)
+ for (marker = trail_head, n = TRAIL_LENGTH; n; n--) {
+ if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
marker = NEXT(marker);
else
break;
}
- if (visible(self, trail[marker]))
- {
+ if (visible(self, trail[marker])) {
return trail[marker];
}
- if (visible(self, trail[PREV(marker)]))
- {
+ if (visible(self, trail[PREV(marker)])) {
return trail[PREV(marker)];
}
return trail[marker];
}
-edict_t *PlayerTrail_PickNext (edict_t *self)
+edict_t *PlayerTrail_PickNext(edict_t *self)
{
int marker;
int n;
@@ -129,9 +125,8 @@ edict_t *PlayerTrail_PickNext (edict_t *self)
if (!trail_active)
return NULL;
- for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
- {
- if(trail[marker]->timestamp <= self->monsterinfo.trail_time)
+ for (marker = trail_head, n = TRAIL_LENGTH; n; n--) {
+ if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
marker = NEXT(marker);
else
break;
@@ -140,7 +135,7 @@ edict_t *PlayerTrail_PickNext (edict_t *self)
return trail[marker];
}
-edict_t *PlayerTrail_LastSpot (void)
+edict_t *PlayerTrail_LastSpot(void)
{
return trail[PREV(trail_head)];
}
diff --git a/src/baseq2/p_view.c b/src/baseq2/p_view.c
index c049ba0..9fa7bf3 100644
--- a/src/baseq2/p_view.c
+++ b/src/baseq2/p_view.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -39,25 +39,25 @@ SV_CalcRoll
===============
*/
-float SV_CalcRoll (vec3_t angles, vec3_t velocity)
+float SV_CalcRoll(vec3_t angles, vec3_t velocity)
{
float sign;
float side;
float value;
-
- side = DotProduct (velocity, right);
+
+ side = DotProduct(velocity, right);
sign = side < 0 ? -1 : 1;
side = fabs(side);
-
+
value = sv_rollangle->value;
if (side < sv_rollspeed->value)
side = side * value / sv_rollspeed->value;
else
side = value;
-
- return side*sign;
-
+
+ return side * sign;
+
}
@@ -68,7 +68,7 @@ P_DamageFeedback
Handles color blends and view kicks
===============
*/
-void P_DamageFeedback (edict_t *player)
+void P_DamageFeedback(edict_t *player)
{
gclient_t *client;
float side;
@@ -94,31 +94,26 @@ void P_DamageFeedback (edict_t *player)
return; // didn't take any damage
// start a pain animation if still in the player model
- if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255)
- {
+ if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255) {
static int i;
client->anim_priority = ANIM_PAIN;
- if (client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- player->s.frame = FRAME_crpain1-1;
+ if (client->ps.pmove.pm_flags & PMF_DUCKED) {
+ player->s.frame = FRAME_crpain1 - 1;
client->anim_end = FRAME_crpain4;
- }
- else
- {
- i = (i+1)%3;
- switch (i)
- {
+ } else {
+ i = (i + 1) % 3;
+ switch (i) {
case 0:
- player->s.frame = FRAME_pain101-1;
+ player->s.frame = FRAME_pain101 - 1;
client->anim_end = FRAME_pain104;
break;
case 1:
- player->s.frame = FRAME_pain201-1;
+ player->s.frame = FRAME_pain201 - 1;
client->anim_end = FRAME_pain204;
break;
case 2:
- player->s.frame = FRAME_pain301-1;
+ player->s.frame = FRAME_pain301 - 1;
client->anim_end = FRAME_pain304;
break;
}
@@ -130,9 +125,8 @@ void P_DamageFeedback (edict_t *player)
count = 10; // always make a visible effect
// play an apropriate pain sound
- if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
- {
- r = 1 + (rand()&1);
+ if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum)) {
+ r = 1 + (rand() & 1);
player->pain_debounce_time = level.time + 0.7;
if (player->health < 25)
l = 25;
@@ -142,13 +136,13 @@ void P_DamageFeedback (edict_t *player)
l = 75;
else
l = 100;
- gi.sound (player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);
+ gi.sound(player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);
}
// the total alpha of the blend is always proportional to count
if (client->damage_alpha < 0)
client->damage_alpha = 0;
- client->damage_alpha += count*0.01;
+ client->damage_alpha += count * 0.01;
if (client->damage_alpha < 0.2)
client->damage_alpha = 0.2;
if (client->damage_alpha > 0.6)
@@ -156,37 +150,36 @@ void P_DamageFeedback (edict_t *player)
// the color of the blend will vary based on how much was absorbed
// by different armors
- VectorClear (v);
+ VectorClear(v);
if (client->damage_parmor)
- VectorMA (v, (float)client->damage_parmor/realcount, power_color, v);
+ VectorMA(v, (float)client->damage_parmor / realcount, power_color, v);
if (client->damage_armor)
- VectorMA (v, (float)client->damage_armor/realcount, acolor, v);
+ VectorMA(v, (float)client->damage_armor / realcount, acolor, v);
if (client->damage_blood)
- VectorMA (v, (float)client->damage_blood/realcount, bcolor, v);
- VectorCopy (v, client->damage_blend);
+ VectorMA(v, (float)client->damage_blood / realcount, bcolor, v);
+ VectorCopy(v, client->damage_blend);
//
// calculate view angle kicks
//
kick = abs(client->damage_knockback);
- if (kick && player->health > 0) // kick of 0 means no view adjust at all
- {
+ if (kick && player->health > 0) { // kick of 0 means no view adjust at all
kick = kick * 100 / player->health;
- if (kick < count*0.5)
- kick = count*0.5;
+ if (kick < count * 0.5)
+ kick = count * 0.5;
if (kick > 50)
kick = 50;
- VectorSubtract (client->damage_from, player->s.origin, v);
- VectorNormalize (v);
-
- side = DotProduct (v, right);
- client->v_dmg_roll = kick*side*0.3;
-
- side = -DotProduct (v, forward);
- client->v_dmg_pitch = kick*side*0.3;
+ VectorSubtract(client->damage_from, player->s.origin, v);
+ VectorNormalize(v);
+
+ side = DotProduct(v, right);
+ client->v_dmg_roll = kick * side * 0.3;
+
+ side = -DotProduct(v, forward);
+ client->v_dmg_pitch = kick * side * 0.3;
client->v_dmg_time = level.time + DAMAGE_TIME;
}
@@ -213,13 +206,13 @@ Auto pitching on slopes?
fall from 256: 580 = 336400
fall from 384: 720 = 518400
fall from 512: 800 = 640000
- fall from 640: 960 =
+ fall from 640: 960 =
damage = deltavelocity*deltavelocity * 0.0001
===============
*/
-void SV_CalcViewOffset (edict_t *ent)
+void SV_CalcViewOffset(edict_t *ent)
{
float *angles;
float bob;
@@ -234,25 +227,21 @@ void SV_CalcViewOffset (edict_t *ent)
angles = ent->client->ps.kick_angles;
// if dead, fix the angle and don't add any kick
- if (ent->deadflag)
- {
- VectorClear (angles);
+ if (ent->deadflag) {
+ VectorClear(angles);
ent->client->ps.viewangles[ROLL] = 40;
ent->client->ps.viewangles[PITCH] = -15;
ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;
- }
- else
- {
+ } else {
// add angles based on weapon kick
- VectorCopy (ent->client->kick_angles, angles);
+ VectorCopy(ent->client->kick_angles, angles);
// add angles based on damage kick
ratio = (ent->client->v_dmg_time - level.time) / DAMAGE_TIME;
- if (ratio < 0)
- {
+ if (ratio < 0) {
ratio = 0;
ent->client->v_dmg_pitch = 0;
ent->client->v_dmg_roll = 0;
@@ -269,11 +258,11 @@ void SV_CalcViewOffset (edict_t *ent)
// add angles based on velocity
- delta = DotProduct (ent->velocity, forward);
- angles[PITCH] += delta*run_pitch->value;
-
- delta = DotProduct (ent->velocity, right);
- angles[ROLL] += delta*run_roll->value;
+ delta = DotProduct(ent->velocity, forward);
+ angles[PITCH] += delta * run_pitch->value;
+
+ delta = DotProduct(ent->velocity, right);
+ angles[ROLL] += delta * run_roll->value;
// add angles based on bob
@@ -293,7 +282,7 @@ void SV_CalcViewOffset (edict_t *ent)
// base origin
- VectorClear (v);
+ VectorClear(v);
// add view height
@@ -316,7 +305,7 @@ void SV_CalcViewOffset (edict_t *ent)
// add kick offset
- VectorAdd (v, ent->client->kick_origin, v);
+ VectorAdd(v, ent->client->kick_origin, v);
// absolutely bound offsets
// so the view can never be outside the player box
@@ -334,7 +323,7 @@ void SV_CalcViewOffset (edict_t *ent)
else if (v[2] > 30)
v[2] = 30;
- VectorCopy (v, ent->client->ps.viewoffset);
+ VectorCopy(v, ent->client->ps.viewoffset);
}
/*
@@ -342,7 +331,7 @@ void SV_CalcViewOffset (edict_t *ent)
SV_CalcGunOffset
==============
*/
-void SV_CalcGunOffset (edict_t *ent)
+void SV_CalcGunOffset(edict_t *ent)
{
int i;
float delta;
@@ -350,8 +339,7 @@ void SV_CalcGunOffset (edict_t *ent)
// gun angles from bobbing
ent->client->ps.gunangles[ROLL] = xyspeed * bobfracsin * 0.005;
ent->client->ps.gunangles[YAW] = xyspeed * bobfracsin * 0.01;
- if (bobcycle & 1)
- {
+ if (bobcycle & 1) {
ent->client->ps.gunangles[ROLL] = -ent->client->ps.gunangles[ROLL];
ent->client->ps.gunangles[YAW] = -ent->client->ps.gunangles[YAW];
}
@@ -359,8 +347,7 @@ void SV_CalcGunOffset (edict_t *ent)
ent->client->ps.gunangles[PITCH] = xyspeed * bobfracsin * 0.005;
// gun angles from delta movement
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
delta = ent->client->oldviewangles[i] - ent->client->ps.viewangles[i];
if (delta > 180)
delta -= 360;
@@ -371,20 +358,19 @@ void SV_CalcGunOffset (edict_t *ent)
if (delta < -45)
delta = -45;
if (i == YAW)
- ent->client->ps.gunangles[ROLL] += 0.1*delta;
+ ent->client->ps.gunangles[ROLL] += 0.1 * delta;
ent->client->ps.gunangles[i] += 0.2 * delta;
}
// gun height
- VectorClear (ent->client->ps.gunoffset);
+ VectorClear(ent->client->ps.gunoffset);
// ent->ps->gunorigin[2] += bob;
// gun_x / gun_y / gun_z are development tools
- for (i=0 ; i<3 ; i++)
- {
- ent->client->ps.gunoffset[i] += forward[i]*(gun_y->value);
- ent->client->ps.gunoffset[i] += right[i]*gun_x->value;
- ent->client->ps.gunoffset[i] += up[i]* (-gun_z->value);
+ for (i = 0 ; i < 3 ; i++) {
+ ent->client->ps.gunoffset[i] += forward[i] * (gun_y->value);
+ ent->client->ps.gunoffset[i] += right[i] * gun_x->value;
+ ent->client->ps.gunoffset[i] += up[i] * (-gun_z->value);
}
}
@@ -394,18 +380,18 @@ void SV_CalcGunOffset (edict_t *ent)
SV_AddBlend
=============
*/
-void SV_AddBlend (float r, float g, float b, float a, float *v_blend)
+void SV_AddBlend(float r, float g, float b, float a, float *v_blend)
{
float a2, a3;
if (a <= 0)
return;
- a2 = v_blend[3] + (1-v_blend[3])*a; // new total alpha
- a3 = v_blend[3]/a2; // fraction of color from old
+ a2 = v_blend[3] + (1 - v_blend[3]) * a; // new total alpha
+ a3 = v_blend[3] / a2; // fraction of color from old
- v_blend[0] = v_blend[0]*a3 + r*(1-a3);
- v_blend[1] = v_blend[1]*a3 + g*(1-a3);
- v_blend[2] = v_blend[2]*a3 + b*(1-a3);
+ v_blend[0] = v_blend[0] * a3 + r * (1 - a3);
+ v_blend[1] = v_blend[1] * a3 + g * (1 - a3);
+ v_blend[2] = v_blend[2] * a3 + b * (1 - a3);
v_blend[3] = a2;
}
@@ -415,71 +401,64 @@ void SV_AddBlend (float r, float g, float b, float a, float *v_blend)
SV_CalcBlend
=============
*/
-void SV_CalcBlend (edict_t *ent)
+void SV_CalcBlend(edict_t *ent)
{
int contents;
vec3_t vieworg;
int remaining;
- ent->client->ps.blend[0] = ent->client->ps.blend[1] =
- ent->client->ps.blend[2] = ent->client->ps.blend[3] = 0;
+ ent->client->ps.blend[0] = ent->client->ps.blend[1] =
+ ent->client->ps.blend[2] = ent->client->ps.blend[3] = 0;
// add for contents
- VectorAdd (ent->s.origin, ent->client->ps.viewoffset, vieworg);
- contents = gi.pointcontents (vieworg);
- if (contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER) )
+ VectorAdd(ent->s.origin, ent->client->ps.viewoffset, vieworg);
+ contents = gi.pointcontents(vieworg);
+ if (contents & (CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER))
ent->client->ps.rdflags |= RDF_UNDERWATER;
else
ent->client->ps.rdflags &= ~RDF_UNDERWATER;
- if (contents & (CONTENTS_SOLID|CONTENTS_LAVA))
- SV_AddBlend (1.0, 0.3, 0.0, 0.6, ent->client->ps.blend);
+ if (contents & (CONTENTS_SOLID | CONTENTS_LAVA))
+ SV_AddBlend(1.0, 0.3, 0.0, 0.6, ent->client->ps.blend);
else if (contents & CONTENTS_SLIME)
- SV_AddBlend (0.0, 0.1, 0.05, 0.6, ent->client->ps.blend);
+ SV_AddBlend(0.0, 0.1, 0.05, 0.6, ent->client->ps.blend);
else if (contents & CONTENTS_WATER)
- SV_AddBlend (0.5, 0.3, 0.2, 0.4, ent->client->ps.blend);
+ SV_AddBlend(0.5, 0.3, 0.2, 0.4, ent->client->ps.blend);
// add for powerups
- if (ent->client->quad_framenum > level.framenum)
- {
+ if (ent->client->quad_framenum > level.framenum) {
remaining = ent->client->quad_framenum - level.framenum;
if (remaining == 30) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage2.wav"), 1, ATTN_NORM, 0);
- if (remaining > 30 || (remaining & 4) )
- SV_AddBlend (0, 0, 1, 0.08, ent->client->ps.blend);
- }
- else if (ent->client->invincible_framenum > level.framenum)
- {
+ if (remaining > 30 || (remaining & 4))
+ SV_AddBlend(0, 0, 1, 0.08, ent->client->ps.blend);
+ } else if (ent->client->invincible_framenum > level.framenum) {
remaining = ent->client->invincible_framenum - level.framenum;
if (remaining == 30) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
- if (remaining > 30 || (remaining & 4) )
- SV_AddBlend (1, 1, 0, 0.08, ent->client->ps.blend);
- }
- else if (ent->client->enviro_framenum > level.framenum)
- {
+ if (remaining > 30 || (remaining & 4))
+ SV_AddBlend(1, 1, 0, 0.08, ent->client->ps.blend);
+ } else if (ent->client->enviro_framenum > level.framenum) {
remaining = ent->client->enviro_framenum - level.framenum;
if (remaining == 30) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
- if (remaining > 30 || (remaining & 4) )
- SV_AddBlend (0, 1, 0, 0.08, ent->client->ps.blend);
- }
- else if (ent->client->breather_framenum > level.framenum)
- {
+ if (remaining > 30 || (remaining & 4))
+ SV_AddBlend(0, 1, 0, 0.08, ent->client->ps.blend);
+ } else if (ent->client->breather_framenum > level.framenum) {
remaining = ent->client->breather_framenum - level.framenum;
if (remaining == 30) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
- if (remaining > 30 || (remaining & 4) )
- SV_AddBlend (0.4, 1, 0.4, 0.04, ent->client->ps.blend);
+ if (remaining > 30 || (remaining & 4))
+ SV_AddBlend(0.4, 1, 0.4, 0.04, ent->client->ps.blend);
}
// add for damage
if (ent->client->damage_alpha > 0)
- SV_AddBlend (ent->client->damage_blend[0],ent->client->damage_blend[1]
- ,ent->client->damage_blend[2], ent->client->damage_alpha, ent->client->ps.blend);
+ SV_AddBlend(ent->client->damage_blend[0], ent->client->damage_blend[1]
+ , ent->client->damage_blend[2], ent->client->damage_alpha, ent->client->ps.blend);
if (ent->client->bonus_alpha > 0)
- SV_AddBlend (0.85, 0.7, 0.3, ent->client->bonus_alpha, ent->client->ps.blend);
+ SV_AddBlend(0.85, 0.7, 0.3, ent->client->bonus_alpha, ent->client->ps.blend);
// drop the damage value
ent->client->damage_alpha -= 0.06;
@@ -498,7 +477,7 @@ void SV_CalcBlend (edict_t *ent)
P_FallingDamage
=================
*/
-void P_FallingDamage (edict_t *ent)
+void P_FallingDamage(edict_t *ent)
{
float delta;
int damage;
@@ -510,17 +489,14 @@ void P_FallingDamage (edict_t *ent)
if (ent->movetype == MOVETYPE_NOCLIP)
return;
- if ((ent->client->oldvelocity[2] < 0) && (ent->velocity[2] > ent->client->oldvelocity[2]) && (!ent->groundentity))
- {
+ if ((ent->client->oldvelocity[2] < 0) && (ent->velocity[2] > ent->client->oldvelocity[2]) && (!ent->groundentity)) {
delta = ent->client->oldvelocity[2];
- }
- else
- {
+ } else {
if (!ent->groundentity)
return;
delta = ent->velocity[2] - ent->client->oldvelocity[2];
}
- delta = delta*delta * 0.0001;
+ delta = delta * delta * 0.0001;
// never take falling damage if completely underwater
if (ent->waterlevel == 3)
@@ -533,37 +509,32 @@ void P_FallingDamage (edict_t *ent)
if (delta < 1)
return;
- if (delta < 15)
- {
+ if (delta < 15) {
ent->s.event = EV_FOOTSTEP;
return;
}
- ent->client->fall_value = delta*0.5;
+ ent->client->fall_value = delta * 0.5;
if (ent->client->fall_value > 40)
ent->client->fall_value = 40;
ent->client->fall_time = level.time + FALL_TIME;
- if (delta > 30)
- {
- if (ent->health > 0)
- {
+ if (delta > 30) {
+ if (ent->health > 0) {
if (delta >= 55)
ent->s.event = EV_FALLFAR;
else
ent->s.event = EV_FALL;
}
ent->pain_debounce_time = level.time; // no normal pain sound
- damage = (delta-30)/2;
+ damage = (delta - 30) / 2;
if (damage < 1)
damage = 1;
- VectorSet (dir, 0, 0, 1);
+ VectorSet(dir, 0, 0, 1);
- if (!deathmatch->value || !((int)dmflags->value & DF_NO_FALLING) )
- T_Damage (ent, world, world, dir, ent->s.origin, vec3_origin, damage, 0, 0, MOD_FALLING);
- }
- else
- {
+ if (!deathmatch->value || !((int)dmflags->value & DF_NO_FALLING))
+ T_Damage(ent, world, world, dir, ent->s.origin, vec3_origin, damage, 0, 0, MOD_FALLING);
+ } else {
ent->s.event = EV_FALLSHORT;
return;
}
@@ -576,14 +547,13 @@ void P_FallingDamage (edict_t *ent)
P_WorldEffects
=============
*/
-void P_WorldEffects (void)
+void P_WorldEffects(void)
{
qboolean breather;
qboolean envirosuit;
int waterlevel, old_waterlevel;
- if (current_player->movetype == MOVETYPE_NOCLIP)
- {
+ if (current_player->movetype == MOVETYPE_NOCLIP) {
current_player->air_finished = level.time + 12; // don't need air
return;
}
@@ -598,15 +568,14 @@ void P_WorldEffects (void)
//
// if just entered a water volume, play a sound
//
- if (!old_waterlevel && waterlevel)
- {
+ if (!old_waterlevel && waterlevel) {
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
if (current_player->watertype & CONTENTS_LAVA)
- gi.sound (current_player, CHAN_BODY, gi.soundindex("player/lava_in.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_BODY, gi.soundindex("player/lava_in.wav"), 1, ATTN_NORM, 0);
else if (current_player->watertype & CONTENTS_SLIME)
- gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
else if (current_player->watertype & CONTENTS_WATER)
- gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
current_player->flags |= FL_INWATER;
// clear damage_debounce, so the pain sound will play immediately
@@ -616,53 +585,46 @@ void P_WorldEffects (void)
//
// if just completely exited a water volume, play a sound
//
- if (old_waterlevel && ! waterlevel)
- {
+ if (old_waterlevel && ! waterlevel) {
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
- gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
current_player->flags &= ~FL_INWATER;
}
//
// check for head just going under water
//
- if (old_waterlevel != 3 && waterlevel == 3)
- {
- gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_un.wav"), 1, ATTN_NORM, 0);
+ if (old_waterlevel != 3 && waterlevel == 3) {
+ gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_un.wav"), 1, ATTN_NORM, 0);
}
//
// check for head just coming out of water
//
- if (old_waterlevel == 3 && waterlevel != 3)
- {
- if (current_player->air_finished < level.time)
- { // gasp for air
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp1.wav"), 1, ATTN_NORM, 0);
+ if (old_waterlevel == 3 && waterlevel != 3) {
+ if (current_player->air_finished < level.time) {
+ // gasp for air
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/gasp1.wav"), 1, ATTN_NORM, 0);
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
- }
- else if (current_player->air_finished < level.time + 11)
- { // just break surface
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp2.wav"), 1, ATTN_NORM, 0);
+ } else if (current_player->air_finished < level.time + 11) {
+ // just break surface
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/gasp2.wav"), 1, ATTN_NORM, 0);
}
}
//
// check for drowning
//
- if (waterlevel == 3)
- {
+ if (waterlevel == 3) {
// breather or envirosuit give air
- if (breather || envirosuit)
- {
+ if (breather || envirosuit) {
current_player->air_finished = level.time + 10;
- if (((int)(current_client->breather_framenum - level.framenum) % 25) == 0)
- {
+ if (((int)(current_client->breather_framenum - level.framenum) % 25) == 0) {
if (!current_client->breather_sound)
- gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_AUTO, gi.soundindex("player/u_breath1.wav"), 1, ATTN_NORM, 0);
else
- gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath2.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_AUTO, gi.soundindex("player/u_breath2.wav"), 1, ATTN_NORM, 0);
current_client->breather_sound ^= 1;
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
//FIXME: release a bubble?
@@ -670,11 +632,10 @@ void P_WorldEffects (void)
}
// if out of air, start drowning
- if (current_player->air_finished < level.time)
- { // drown!
- if (current_player->client->next_drown_time < level.time
- && current_player->health > 0)
- {
+ if (current_player->air_finished < level.time) {
+ // drown!
+ if (current_player->client->next_drown_time < level.time
+ && current_player->health > 0) {
current_player->client->next_drown_time = level.time + 1;
// take more damage the longer underwater
@@ -684,20 +645,18 @@ void P_WorldEffects (void)
// play a gurp sound instead of a normal pain sound
if (current_player->health <= current_player->dmg)
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/drown1.wav"), 1, ATTN_NORM, 0);
- else if (rand()&1)
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp1.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/drown1.wav"), 1, ATTN_NORM, 0);
+ else if (rand() & 1)
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("*gurp1.wav"), 1, ATTN_NORM, 0);
else
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp2.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("*gurp2.wav"), 1, ATTN_NORM, 0);
current_player->pain_debounce_time = level.time;
- T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, current_player->dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
+ T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, current_player->dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
}
}
- }
- else
- {
+ } else {
current_player->air_finished = level.time + 12;
current_player->dmg = 2;
}
@@ -705,32 +664,28 @@ void P_WorldEffects (void)
//
// check for sizzle damage
//
- if (waterlevel && (current_player->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
- {
- if (current_player->watertype & CONTENTS_LAVA)
- {
+ if (waterlevel && (current_player->watertype & (CONTENTS_LAVA | CONTENTS_SLIME))) {
+ if (current_player->watertype & CONTENTS_LAVA) {
if (current_player->health > 0
&& current_player->pain_debounce_time <= level.time
- && current_client->invincible_framenum < level.framenum)
- {
- if (rand()&1)
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn1.wav"), 1, ATTN_NORM, 0);
+ && current_client->invincible_framenum < level.framenum) {
+ if (rand() & 1)
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/burn1.wav"), 1, ATTN_NORM, 0);
else
- gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn2.wav"), 1, ATTN_NORM, 0);
+ gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/burn2.wav"), 1, ATTN_NORM, 0);
current_player->pain_debounce_time = level.time + 1;
}
if (envirosuit) // take 1/3 damage with envirosuit
- T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_LAVA);
+ T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1 * waterlevel, 0, 0, MOD_LAVA);
else
- T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 3*waterlevel, 0, 0, MOD_LAVA);
+ T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 3 * waterlevel, 0, 0, MOD_LAVA);
}
- if (current_player->watertype & CONTENTS_SLIME)
- {
- if (!envirosuit)
- { // no damage from slime with envirosuit
- T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_SLIME);
+ if (current_player->watertype & CONTENTS_SLIME) {
+ if (!envirosuit) {
+ // no damage from slime with envirosuit
+ T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1 * waterlevel, 0, 0, MOD_SLIME);
}
}
}
@@ -742,7 +697,7 @@ void P_WorldEffects (void)
G_SetClientEffects
===============
*/
-void G_SetClientEffects (edict_t *ent)
+void G_SetClientEffects(edict_t *ent)
{
int pa_type;
int remaining;
@@ -753,39 +708,32 @@ void G_SetClientEffects (edict_t *ent)
if (ent->health <= 0 || level.intermissiontime)
return;
- if (ent->powerarmor_time > level.time)
- {
- pa_type = PowerArmorType (ent);
- if (pa_type == POWER_ARMOR_SCREEN)
- {
+ if (ent->powerarmor_time > level.time) {
+ pa_type = PowerArmorType(ent);
+ if (pa_type == POWER_ARMOR_SCREEN) {
ent->s.effects |= EF_POWERSCREEN;
- }
- else if (pa_type == POWER_ARMOR_SHIELD)
- {
+ } else if (pa_type == POWER_ARMOR_SHIELD) {
ent->s.effects |= EF_COLOR_SHELL;
ent->s.renderfx |= RF_SHELL_GREEN;
}
}
- if (ent->client->quad_framenum > level.framenum)
- {
+ if (ent->client->quad_framenum > level.framenum) {
remaining = ent->client->quad_framenum - level.framenum;
- if (remaining > 30 || (remaining & 4) )
+ if (remaining > 30 || (remaining & 4))
ent->s.effects |= EF_QUAD;
}
- if (ent->client->invincible_framenum > level.framenum)
- {
+ if (ent->client->invincible_framenum > level.framenum) {
remaining = ent->client->invincible_framenum - level.framenum;
- if (remaining > 30 || (remaining & 4) )
+ if (remaining > 30 || (remaining & 4))
ent->s.effects |= EF_PENT;
}
// show cheaters!!!
- if (ent->flags & FL_GODMODE)
- {
+ if (ent->flags & FL_GODMODE) {
ent->s.effects |= EF_COLOR_SHELL;
- ent->s.renderfx |= (RF_SHELL_RED|RF_SHELL_GREEN|RF_SHELL_BLUE);
+ ent->s.renderfx |= (RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE);
}
}
@@ -795,14 +743,13 @@ void G_SetClientEffects (edict_t *ent)
G_SetClientEvent
===============
*/
-void G_SetClientEvent (edict_t *ent)
+void G_SetClientEvent(edict_t *ent)
{
if (ent->s.event)
return;
- if ( ent->groundentity && xyspeed > 225)
- {
- if ( (int)(current_client->bobtime+bobmove) != bobcycle )
+ if (ent->groundentity && xyspeed > 225) {
+ if ((int)(current_client->bobtime + bobmove) != bobcycle)
ent->s.event = EV_FOOTSTEP;
}
}
@@ -812,21 +759,19 @@ void G_SetClientEvent (edict_t *ent)
G_SetClientSound
===============
*/
-void G_SetClientSound (edict_t *ent)
+void G_SetClientSound(edict_t *ent)
{
char *weap;
- if (ent->client->pers.game_helpchanged != game.helpchanged)
- {
+ if (ent->client->pers.game_helpchanged != game.helpchanged) {
ent->client->pers.game_helpchanged = game.helpchanged;
ent->client->pers.helpchanged = 1;
}
// help beep (no more than three times)
- if (ent->client->pers.helpchanged && ent->client->pers.helpchanged <= 3 && !(level.framenum&63) )
- {
+ if (ent->client->pers.helpchanged && ent->client->pers.helpchanged <= 3 && !(level.framenum & 63)) {
ent->client->pers.helpchanged++;
- gi.sound (ent, CHAN_VOICE, gi.soundindex ("misc/pc_up.wav"), 1, ATTN_STATIC, 0);
+ gi.sound(ent, CHAN_VOICE, gi.soundindex("misc/pc_up.wav"), 1, ATTN_STATIC, 0);
}
@@ -835,7 +780,7 @@ void G_SetClientSound (edict_t *ent)
else
weap = "";
- if (ent->waterlevel && (ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
+ if (ent->waterlevel && (ent->watertype & (CONTENTS_LAVA | CONTENTS_SLIME)))
ent->s.sound = snd_fry;
else if (strcmp(weap, "weapon_railgun") == 0)
ent->s.sound = gi.soundindex("weapons/rg_hum.wav");
@@ -852,7 +797,7 @@ void G_SetClientSound (edict_t *ent)
G_SetClientFrame
===============
*/
-void G_SetClientFrame (edict_t *ent)
+void G_SetClientFrame(edict_t *ent)
{
gclient_t *client;
qboolean duck, run;
@@ -879,24 +824,20 @@ void G_SetClientFrame (edict_t *ent)
if (!ent->groundentity && client->anim_priority <= ANIM_WAVE)
goto newanim;
- if(client->anim_priority == ANIM_REVERSE)
- {
- if(ent->s.frame > client->anim_end)
- {
+ if (client->anim_priority == ANIM_REVERSE) {
+ if (ent->s.frame > client->anim_end) {
ent->s.frame--;
return;
}
- }
- else if (ent->s.frame < client->anim_end)
- { // continue an animation
+ } else if (ent->s.frame < client->anim_end) {
+ // continue an animation
ent->s.frame++;
return;
}
if (client->anim_priority == ANIM_DEATH)
return; // stay there
- if (client->anim_priority == ANIM_JUMP)
- {
+ if (client->anim_priority == ANIM_JUMP) {
if (!ent->groundentity)
return; // stay there
ent->client->anim_priority = ANIM_WAVE;
@@ -911,35 +852,26 @@ newanim:
client->anim_duck = duck;
client->anim_run = run;
- if (!ent->groundentity)
- {
+ if (!ent->groundentity) {
client->anim_priority = ANIM_JUMP;
if (ent->s.frame != FRAME_jump2)
ent->s.frame = FRAME_jump1;
client->anim_end = FRAME_jump2;
- }
- else if (run)
- { // running
- if (duck)
- {
+ } else if (run) {
+ // running
+ if (duck) {
ent->s.frame = FRAME_crwalk1;
client->anim_end = FRAME_crwalk6;
- }
- else
- {
+ } else {
ent->s.frame = FRAME_run1;
client->anim_end = FRAME_run6;
}
- }
- else
- { // standing
- if (duck)
- {
+ } else {
+ // standing
+ if (duck) {
ent->s.frame = FRAME_crstnd01;
client->anim_end = FRAME_crstnd19;
- }
- else
- {
+ } else {
ent->s.frame = FRAME_stand01;
client->anim_end = FRAME_stand40;
}
@@ -955,7 +887,7 @@ Called for each player at the end of the server frame
and right after spawning
=================
*/
-void ClientEndServerFrame (edict_t *ent)
+void ClientEndServerFrame(edict_t *ent)
{
float bobtime;
int i;
@@ -967,59 +899,55 @@ void ClientEndServerFrame (edict_t *ent)
// If the origin or velocity have changed since ClientThink(),
// update the pmove values. This will happen when the client
// is pushed by a bmodel or kicked by an explosion.
- //
+ //
// If it wasn't updated here, the view position would lag a frame
// behind the body position when pushed -- "sinking into plats"
//
- for (i=0 ; i<3 ; i++)
- {
- current_client->ps.pmove.origin[i] = ent->s.origin[i]*8.0;
- current_client->ps.pmove.velocity[i] = ent->velocity[i]*8.0;
+ for (i = 0 ; i < 3 ; i++) {
+ current_client->ps.pmove.origin[i] = ent->s.origin[i] * 8.0;
+ current_client->ps.pmove.velocity[i] = ent->velocity[i] * 8.0;
}
//
// If the end of unit layout is displayed, don't give
// the player any normal movement attributes
//
- if (level.intermissiontime)
- {
+ if (level.intermissiontime) {
// FIXME: add view drifting here?
current_client->ps.blend[3] = 0;
current_client->ps.fov = 90;
- G_SetStats (ent);
+ G_SetStats(ent);
return;
}
- AngleVectors (ent->client->v_angle, forward, right, up);
+ AngleVectors(ent->client->v_angle, forward, right, up);
// burn from lava, etc
- P_WorldEffects ();
+ P_WorldEffects();
//
// set model angles from view angles so other things in
// the world can tell which direction you are looking
//
if (ent->client->v_angle[PITCH] > 180)
- ent->s.angles[PITCH] = (-360 + ent->client->v_angle[PITCH])/3;
+ ent->s.angles[PITCH] = (-360 + ent->client->v_angle[PITCH]) / 3;
else
- ent->s.angles[PITCH] = ent->client->v_angle[PITCH]/3;
+ ent->s.angles[PITCH] = ent->client->v_angle[PITCH] / 3;
ent->s.angles[YAW] = ent->client->v_angle[YAW];
ent->s.angles[ROLL] = 0;
- ent->s.angles[ROLL] = SV_CalcRoll (ent->s.angles, ent->velocity)*4;
+ ent->s.angles[ROLL] = SV_CalcRoll(ent->s.angles, ent->velocity) * 4;
//
// calculate speed and cycle to be used for
// all cyclic walking effects
//
- xyspeed = sqrt(ent->velocity[0]*ent->velocity[0] + ent->velocity[1]*ent->velocity[1]);
+ xyspeed = sqrt(ent->velocity[0] * ent->velocity[0] + ent->velocity[1] * ent->velocity[1]);
- if (xyspeed < 5)
- {
+ if (xyspeed < 5) {
bobmove = 0;
current_client->bobtime = 0; // start at beginning of cycle again
- }
- else if (ent->groundentity)
- { // so bobbing only cycles when on ground
+ } else if (ent->groundentity) {
+ // so bobbing only cycles when on ground
if (xyspeed > 210)
bobmove = 0.25;
else if (xyspeed > 100)
@@ -1027,61 +955,60 @@ void ClientEndServerFrame (edict_t *ent)
else
bobmove = 0.0625;
}
-
+
bobtime = (current_client->bobtime += bobmove);
if (current_client->ps.pmove.pm_flags & PMF_DUCKED)
bobtime *= 4;
bobcycle = (int)bobtime;
- bobfracsin = fabs(sin(bobtime*M_PI));
+ bobfracsin = fabs(sin(bobtime * M_PI));
// detect hitting the floor
- P_FallingDamage (ent);
+ P_FallingDamage(ent);
// apply all the damage taken this frame
- P_DamageFeedback (ent);
+ P_DamageFeedback(ent);
// determine the view offsets
- SV_CalcViewOffset (ent);
+ SV_CalcViewOffset(ent);
// determine the gun offsets
- SV_CalcGunOffset (ent);
+ SV_CalcGunOffset(ent);
// determine the full screen color blend
// must be after viewoffset, so eye contents can be
// accurately determined
// FIXME: with client prediction, the contents
// should be determined by the client
- SV_CalcBlend (ent);
+ SV_CalcBlend(ent);
// chase cam stuff
if (ent->client->resp.spectator)
G_SetSpectatorStats(ent);
else
- G_SetStats (ent);
+ G_SetStats(ent);
G_CheckChaseStats(ent);
- G_SetClientEvent (ent);
+ G_SetClientEvent(ent);
- G_SetClientEffects (ent);
+ G_SetClientEffects(ent);
- G_SetClientSound (ent);
+ G_SetClientSound(ent);
- G_SetClientFrame (ent);
+ G_SetClientFrame(ent);
- VectorCopy (ent->velocity, ent->client->oldvelocity);
- VectorCopy (ent->client->ps.viewangles, ent->client->oldviewangles);
+ VectorCopy(ent->velocity, ent->client->oldvelocity);
+ VectorCopy(ent->client->ps.viewangles, ent->client->oldviewangles);
// clear weapon kicks
- VectorClear (ent->client->kick_origin);
- VectorClear (ent->client->kick_angles);
+ VectorClear(ent->client->kick_origin);
+ VectorClear(ent->client->kick_angles);
// if the scoreboard is up, update it
- if (ent->client->showscores && !(level.framenum & 31) )
- {
- DeathmatchScoreboardMessage (ent, ent->enemy);
- gi.unicast (ent, qfalse);
+ if (ent->client->showscores && !(level.framenum & 31)) {
+ DeathmatchScoreboardMessage(ent, ent->enemy);
+ gi.unicast(ent, qfalse);
}
}
diff --git a/src/baseq2/p_weapon.c b/src/baseq2/p_weapon.c
index ea75737..ab107b9 100644
--- a/src/baseq2/p_weapon.c
+++ b/src/baseq2/p_weapon.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,19 +27,19 @@ static qboolean is_quad;
static byte is_silenced;
-void weapon_grenade_fire (edict_t *ent, qboolean held);
+void weapon_grenade_fire(edict_t *ent, qboolean held);
-static void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
+static void P_ProjectSource(gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
{
vec3_t _distance;
- VectorCopy (distance, _distance);
+ VectorCopy(distance, _distance);
if (client->pers.hand == LEFT_HANDED)
_distance[1] *= -1;
else if (client->pers.hand == CENTER_HANDED)
_distance[1] = 0;
- G_ProjectSource (point, _distance, forward, right, result);
+ G_ProjectSource(point, _distance, forward, right, result);
}
@@ -59,10 +59,8 @@ void PlayerNoise(edict_t *who, vec3_t where, int type)
{
edict_t *noise;
- if (type == PNOISE_WEAPON)
- {
- if (who->client->silencer_shots)
- {
+ if (type == PNOISE_WEAPON) {
+ if (who->client->silencer_shots) {
who->client->silencer_shots--;
return;
}
@@ -75,88 +73,80 @@ void PlayerNoise(edict_t *who, vec3_t where, int type)
return;
- if (!who->mynoise)
- {
+ if (!who->mynoise) {
noise = G_Spawn();
noise->classname = "player_noise";
- VectorSet (noise->mins, -8, -8, -8);
- VectorSet (noise->maxs, 8, 8, 8);
+ VectorSet(noise->mins, -8, -8, -8);
+ VectorSet(noise->maxs, 8, 8, 8);
noise->owner = who;
noise->svflags = SVF_NOCLIENT;
who->mynoise = noise;
noise = G_Spawn();
noise->classname = "player_noise";
- VectorSet (noise->mins, -8, -8, -8);
- VectorSet (noise->maxs, 8, 8, 8);
+ VectorSet(noise->mins, -8, -8, -8);
+ VectorSet(noise->maxs, 8, 8, 8);
noise->owner = who;
noise->svflags = SVF_NOCLIENT;
who->mynoise2 = noise;
}
- if (type == PNOISE_SELF || type == PNOISE_WEAPON)
- {
+ if (type == PNOISE_SELF || type == PNOISE_WEAPON) {
noise = who->mynoise;
level.sound_entity = noise;
level.sound_entity_framenum = level.framenum;
- }
- else // type == PNOISE_IMPACT
- {
+ } else { // type == PNOISE_IMPACT
noise = who->mynoise2;
level.sound2_entity = noise;
level.sound2_entity_framenum = level.framenum;
}
- VectorCopy (where, noise->s.origin);
- VectorSubtract (where, noise->maxs, noise->absmin);
- VectorAdd (where, noise->maxs, noise->absmax);
+ VectorCopy(where, noise->s.origin);
+ VectorSubtract(where, noise->maxs, noise->absmin);
+ VectorAdd(where, noise->maxs, noise->absmax);
noise->teleport_time = level.time;
- gi.linkentity (noise);
+ gi.linkentity(noise);
}
-qboolean Pickup_Weapon (edict_t *ent, edict_t *other)
+qboolean Pickup_Weapon(edict_t *ent, edict_t *other)
{
int index;
gitem_t *ammo;
index = ITEM_INDEX(ent->item);
- if ( ( ((int)(dmflags->value) & DF_WEAPONS_STAY) || coop->value)
- && other->client->pers.inventory[index])
- {
- if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM) ) )
+ if ((((int)(dmflags->value) & DF_WEAPONS_STAY) || coop->value)
+ && other->client->pers.inventory[index]) {
+ if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))
return qfalse; // leave the weapon for others to pickup
}
other->client->pers.inventory[index]++;
- if (!(ent->spawnflags & DROPPED_ITEM) )
- {
+ if (!(ent->spawnflags & DROPPED_ITEM)) {
// give them some ammo with it
- ammo = FindItem (ent->item->ammo);
- if ( (int)dmflags->value & DF_INFINITE_AMMO )
- Add_Ammo (other, ammo, 1000);
+ ammo = FindItem(ent->item->ammo);
+ if ((int)dmflags->value & DF_INFINITE_AMMO)
+ Add_Ammo(other, ammo, 1000);
else
- Add_Ammo (other, ammo, ammo->quantity);
+ Add_Ammo(other, ammo, ammo->quantity);
- if (! (ent->spawnflags & DROPPED_PLAYER_ITEM) )
- {
- if (deathmatch->value)
- {
+ if (!(ent->spawnflags & DROPPED_PLAYER_ITEM)) {
+ if (deathmatch->value) {
if ((int)(dmflags->value) & DF_WEAPONS_STAY)
ent->flags |= FL_RESPAWN;
else
- SetRespawn (ent, 30);
+ SetRespawn(ent, 30);
}
if (coop->value)
ent->flags |= FL_RESPAWN;
}
}
- if (other->client->pers.weapon != ent->item &&
+ if (other->client->pers.weapon != ent->item &&
(other->client->pers.inventory[index] == 1) &&
- ( !deathmatch->value || other->client->pers.weapon == FindItem("blaster") ) )
+ (!deathmatch->value || other->client->pers.weapon == FindItem("blaster")))
other->client->newweapon = ent->item;
return qtrue;
@@ -171,15 +161,14 @@ The old weapon has been dropped all the way, so make the new one
current
===============
*/
-void ChangeWeapon (edict_t *ent)
+void ChangeWeapon(edict_t *ent)
{
int i;
- if (ent->client->grenade_time)
- {
+ if (ent->client->grenade_time) {
ent->client->grenade_time = level.time;
ent->client->weapon_sound = 0;
- weapon_grenade_fire (ent, qfalse);
+ weapon_grenade_fire(ent, qfalse);
ent->client->grenade_time = 0;
}
@@ -202,8 +191,8 @@ void ChangeWeapon (edict_t *ent)
else
ent->client->ammo_index = 0;
- if (!ent->client->pers.weapon)
- { // dead
+ if (!ent->client->pers.weapon) {
+ // dead
ent->client->ps.gunindex = 0;
return;
}
@@ -213,16 +202,13 @@ void ChangeWeapon (edict_t *ent)
ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);
ent->client->anim_priority = ANIM_PAIN;
- if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- ent->s.frame = FRAME_crpain1;
- ent->client->anim_end = FRAME_crpain4;
- }
- else
- {
- ent->s.frame = FRAME_pain301;
- ent->client->anim_end = FRAME_pain304;
-
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ ent->s.frame = FRAME_crpain1;
+ ent->client->anim_end = FRAME_crpain4;
+ } else {
+ ent->s.frame = FRAME_pain301;
+ ent->client->anim_end = FRAME_pain304;
+
}
}
@@ -231,45 +217,39 @@ void ChangeWeapon (edict_t *ent)
NoAmmoWeaponChange
=================
*/
-void NoAmmoWeaponChange (edict_t *ent)
+void NoAmmoWeaponChange(edict_t *ent)
{
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("slugs"))]
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("railgun"))] )
- {
- ent->client->newweapon = FindItem ("railgun");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("slugs"))]
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("railgun"))]) {
+ ent->client->newweapon = FindItem("railgun");
return;
}
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))]
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("hyperblaster"))] )
- {
- ent->client->newweapon = FindItem ("hyperblaster");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))]
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("hyperblaster"))]) {
+ ent->client->newweapon = FindItem("hyperblaster");
return;
}
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("chaingun"))] )
- {
- ent->client->newweapon = FindItem ("chaingun");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("chaingun"))]) {
+ ent->client->newweapon = FindItem("chaingun");
return;
}
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("machinegun"))] )
- {
- ent->client->newweapon = FindItem ("machinegun");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("machinegun"))]) {
+ ent->client->newweapon = FindItem("machinegun");
return;
}
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))] > 1
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("super shotgun"))] )
- {
- ent->client->newweapon = FindItem ("super shotgun");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))] > 1
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("super shotgun"))]) {
+ ent->client->newweapon = FindItem("super shotgun");
return;
}
- if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))]
- && ent->client->pers.inventory[ITEM_INDEX(FindItem("shotgun"))] )
- {
- ent->client->newweapon = FindItem ("shotgun");
+ if (ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))]
+ && ent->client->pers.inventory[ITEM_INDEX(FindItem("shotgun"))]) {
+ ent->client->newweapon = FindItem("shotgun");
return;
}
- ent->client->newweapon = FindItem ("blaster");
+ ent->client->newweapon = FindItem("blaster");
}
/*
@@ -279,24 +259,22 @@ Think_Weapon
Called by ClientBeginServerFrame and ClientThink
=================
*/
-void Think_Weapon (edict_t *ent)
+void Think_Weapon(edict_t *ent)
{
// if just died, put the weapon away
- if (ent->health < 1)
- {
+ if (ent->health < 1) {
ent->client->newweapon = NULL;
- ChangeWeapon (ent);
+ ChangeWeapon(ent);
}
// call active weapon think routine
- if (ent->client->pers.weapon && ent->client->pers.weapon->weaponthink)
- {
+ if (ent->client->pers.weapon && ent->client->pers.weapon->weaponthink) {
is_quad = (ent->client->quad_framenum > level.framenum);
if (ent->client->silencer_shots)
is_silenced = MZ_SILENCED;
else
is_silenced = 0;
- ent->client->pers.weapon->weaponthink (ent);
+ ent->client->pers.weapon->weaponthink(ent);
}
}
@@ -308,7 +286,7 @@ Use_Weapon
Make the weapon ready if there is ammo
================
*/
-void Use_Weapon (edict_t *ent, gitem_t *item)
+void Use_Weapon(edict_t *ent, gitem_t *item)
{
int ammo_index;
gitem_t *ammo_item;
@@ -317,20 +295,17 @@ void Use_Weapon (edict_t *ent, gitem_t *item)
if (item == ent->client->pers.weapon)
return;
- if (item->ammo && !g_select_empty->value && !(item->flags & IT_AMMO))
- {
+ if (item->ammo && !g_select_empty->value && !(item->flags & IT_AMMO)) {
ammo_item = FindItem(item->ammo);
ammo_index = ITEM_INDEX(ammo_item);
- if (!ent->client->pers.inventory[ammo_index])
- {
- gi.cprintf (ent, PRINT_HIGH, "No %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
+ if (!ent->client->pers.inventory[ammo_index]) {
+ gi.cprintf(ent, PRINT_HIGH, "No %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
return;
}
- if (ent->client->pers.inventory[ammo_index] < item->quantity)
- {
- gi.cprintf (ent, PRINT_HIGH, "Not enough %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
+ if (ent->client->pers.inventory[ammo_index] < item->quantity) {
+ gi.cprintf(ent, PRINT_HIGH, "Not enough %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
return;
}
}
@@ -346,7 +321,7 @@ void Use_Weapon (edict_t *ent, gitem_t *item)
Drop_Weapon
================
*/
-void Drop_Weapon (edict_t *ent, gitem_t *item)
+void Drop_Weapon(edict_t *ent, gitem_t *item)
{
int index;
@@ -355,13 +330,12 @@ void Drop_Weapon (edict_t *ent, gitem_t *item)
index = ITEM_INDEX(item);
// see if we're already using it
- if ( ((item == ent->client->pers.weapon) || (item == ent->client->newweapon))&& (ent->client->pers.inventory[index] == 1) )
- {
- gi.cprintf (ent, PRINT_HIGH, "Can't drop current weapon\n");
+ if (((item == ent->client->pers.weapon) || (item == ent->client->newweapon)) && (ent->client->pers.inventory[index] == 1)) {
+ gi.cprintf(ent, PRINT_HIGH, "Can't drop current weapon\n");
return;
}
- Drop_Item (ent, item);
+ Drop_Item(ent, item);
ent->client->pers.inventory[index]--;
}
@@ -377,35 +351,27 @@ A generic function to handle the basics of weapon thinking
#define FRAME_IDLE_FIRST (FRAME_FIRE_LAST + 1)
#define FRAME_DEACTIVATE_FIRST (FRAME_IDLE_LAST + 1)
-void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
+void Weapon_Generic(edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
{
int n;
- if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
- {
+ if (ent->deadflag || ent->s.modelindex != 255) { // VWep animations screw up corpses
return;
}
- if (ent->client->weaponstate == WEAPON_DROPPING)
- {
- if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST)
- {
- ChangeWeapon (ent);
+ if (ent->client->weaponstate == WEAPON_DROPPING) {
+ if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST) {
+ ChangeWeapon(ent);
return;
- }
- else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4)
- {
+ } else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4) {
ent->client->anim_priority = ANIM_REVERSE;
- if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- ent->s.frame = FRAME_crpain4+1;
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ ent->s.frame = FRAME_crpain4 + 1;
ent->client->anim_end = FRAME_crpain1;
- }
- else
- {
- ent->s.frame = FRAME_pain304+1;
+ } else {
+ ent->s.frame = FRAME_pain304 + 1;
ent->client->anim_end = FRAME_pain301;
-
+
}
}
@@ -413,10 +379,8 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
return;
}
- if (ent->client->weaponstate == WEAPON_ACTIVATING)
- {
- if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST)
- {
+ if (ent->client->weaponstate == WEAPON_ACTIVATING) {
+ if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST) {
ent->client->weaponstate = WEAPON_READY;
ent->client->ps.gunframe = FRAME_IDLE_FIRST;
return;
@@ -426,78 +390,58 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
return;
}
- if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
- {
+ if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING)) {
ent->client->weaponstate = WEAPON_DROPPING;
ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
- if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
- {
+ if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4) {
ent->client->anim_priority = ANIM_REVERSE;
- if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- ent->s.frame = FRAME_crpain4+1;
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ ent->s.frame = FRAME_crpain4 + 1;
ent->client->anim_end = FRAME_crpain1;
- }
- else
- {
- ent->s.frame = FRAME_pain304+1;
+ } else {
+ ent->s.frame = FRAME_pain304 + 1;
ent->client->anim_end = FRAME_pain301;
-
+
}
}
return;
}
- if (ent->client->weaponstate == WEAPON_READY)
- {
- if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
- {
+ if (ent->client->weaponstate == WEAPON_READY) {
+ if (((ent->client->latched_buttons | ent->client->buttons) & BUTTON_ATTACK)) {
ent->client->latched_buttons &= ~BUTTON_ATTACK;
- if ((!ent->client->ammo_index) ||
- ( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
- {
+ if ((!ent->client->ammo_index) ||
+ (ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity)) {
ent->client->ps.gunframe = FRAME_FIRE_FIRST;
ent->client->weaponstate = WEAPON_FIRING;
// start the animation
ent->client->anim_priority = ANIM_ATTACK;
- if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- ent->s.frame = FRAME_crattak1-1;
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ ent->s.frame = FRAME_crattak1 - 1;
ent->client->anim_end = FRAME_crattak9;
- }
- else
- {
- ent->s.frame = FRAME_attack1-1;
+ } else {
+ ent->s.frame = FRAME_attack1 - 1;
ent->client->anim_end = FRAME_attack8;
}
- }
- else
- {
- if (level.time >= ent->pain_debounce_time)
- {
+ } else {
+ if (level.time >= ent->pain_debounce_time) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
- NoAmmoWeaponChange (ent);
+ NoAmmoWeaponChange(ent);
}
- }
- else
- {
- if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
- {
+ } else {
+ if (ent->client->ps.gunframe == FRAME_IDLE_LAST) {
ent->client->ps.gunframe = FRAME_IDLE_FIRST;
return;
}
- if (pause_frames)
- {
- for (n = 0; pause_frames[n]; n++)
- {
- if (ent->client->ps.gunframe == pause_frames[n])
- {
- if (rand()&15)
+ if (pause_frames) {
+ for (n = 0; pause_frames[n]; n++) {
+ if (ent->client->ps.gunframe == pause_frames[n]) {
+ if (rand() & 15)
return;
}
}
@@ -508,16 +452,13 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
}
}
- if (ent->client->weaponstate == WEAPON_FIRING)
- {
- for (n = 0; fire_frames[n]; n++)
- {
- if (ent->client->ps.gunframe == fire_frames[n])
- {
+ if (ent->client->weaponstate == WEAPON_FIRING) {
+ for (n = 0; fire_frames[n]; n++) {
+ if (ent->client->ps.gunframe == fire_frames[n]) {
if (ent->client->quad_framenum > level.framenum)
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);
- fire (ent);
+ fire(ent);
break;
}
}
@@ -525,7 +466,7 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
if (!fire_frames[n])
ent->client->ps.gunframe++;
- if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
+ if (ent->client->ps.gunframe == FRAME_IDLE_FIRST + 1)
ent->client->weaponstate = WEAPON_READY;
}
}
@@ -543,7 +484,7 @@ GRENADE
#define GRENADE_MINSPEED 400
#define GRENADE_MAXSPEED 800
-void weapon_grenade_fire (edict_t *ent, qboolean held)
+void weapon_grenade_fire(edict_t *ent, qboolean held)
{
vec3_t offset;
vec3_t forward, right;
@@ -553,86 +494,73 @@ void weapon_grenade_fire (edict_t *ent, qboolean held)
int speed;
float radius;
- radius = damage+40;
+ radius = damage + 40;
if (is_quad)
damage *= 4;
- VectorSet(offset, 8, 8, ent->viewheight-8);
- AngleVectors (ent->client->v_angle, forward, right, NULL);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ VectorSet(offset, 8, 8, ent->viewheight - 8);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
timer = ent->client->grenade_time - level.time;
speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER);
- fire_grenade2 (ent, start, forward, damage, speed, timer, radius, held);
+ fire_grenade2(ent, start, forward, damage, speed, timer, radius, held);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
ent->client->grenade_time = level.time + 1.0;
- if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
- {
+ if (ent->deadflag || ent->s.modelindex != 255) { // VWep animations screw up corpses
return;
}
if (ent->health <= 0)
return;
- if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
ent->client->anim_priority = ANIM_ATTACK;
- ent->s.frame = FRAME_crattak1-1;
+ ent->s.frame = FRAME_crattak1 - 1;
ent->client->anim_end = FRAME_crattak3;
- }
- else
- {
+ } else {
ent->client->anim_priority = ANIM_REVERSE;
ent->s.frame = FRAME_wave08;
ent->client->anim_end = FRAME_wave01;
}
}
-void Weapon_Grenade (edict_t *ent)
+void Weapon_Grenade(edict_t *ent)
{
- if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
- {
- ChangeWeapon (ent);
+ if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY)) {
+ ChangeWeapon(ent);
return;
}
- if (ent->client->weaponstate == WEAPON_ACTIVATING)
- {
+ if (ent->client->weaponstate == WEAPON_ACTIVATING) {
ent->client->weaponstate = WEAPON_READY;
ent->client->ps.gunframe = 16;
return;
}
- if (ent->client->weaponstate == WEAPON_READY)
- {
- if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
- {
+ if (ent->client->weaponstate == WEAPON_READY) {
+ if (((ent->client->latched_buttons | ent->client->buttons) & BUTTON_ATTACK)) {
ent->client->latched_buttons &= ~BUTTON_ATTACK;
- if (ent->client->pers.inventory[ent->client->ammo_index])
- {
+ if (ent->client->pers.inventory[ent->client->ammo_index]) {
ent->client->ps.gunframe = 1;
ent->client->weaponstate = WEAPON_FIRING;
ent->client->grenade_time = 0;
- }
- else
- {
- if (level.time >= ent->pain_debounce_time)
- {
+ } else {
+ if (level.time >= ent->pain_debounce_time) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
- NoAmmoWeaponChange (ent);
+ NoAmmoWeaponChange(ent);
}
return;
}
- if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48))
- {
- if (rand()&15)
+ if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48)) {
+ if (rand() & 15)
return;
}
@@ -641,48 +569,39 @@ void Weapon_Grenade (edict_t *ent)
return;
}
- if (ent->client->weaponstate == WEAPON_FIRING)
- {
+ if (ent->client->weaponstate == WEAPON_FIRING) {
if (ent->client->ps.gunframe == 5)
gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);
- if (ent->client->ps.gunframe == 11)
- {
- if (!ent->client->grenade_time)
- {
+ if (ent->client->ps.gunframe == 11) {
+ if (!ent->client->grenade_time) {
ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
}
// they waited too long, detonate it in their hand
- if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
- {
+ if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time) {
ent->client->weapon_sound = 0;
- weapon_grenade_fire (ent, qtrue);
+ weapon_grenade_fire(ent, qtrue);
ent->client->grenade_blew_up = qtrue;
}
if (ent->client->buttons & BUTTON_ATTACK)
return;
- if (ent->client->grenade_blew_up)
- {
- if (level.time >= ent->client->grenade_time)
- {
+ if (ent->client->grenade_blew_up) {
+ if (level.time >= ent->client->grenade_time) {
ent->client->ps.gunframe = 15;
ent->client->grenade_blew_up = qfalse;
- }
- else
- {
+ } else {
return;
}
}
}
- if (ent->client->ps.gunframe == 12)
- {
+ if (ent->client->ps.gunframe == 12) {
ent->client->weapon_sound = 0;
- weapon_grenade_fire (ent, qfalse);
+ weapon_grenade_fire(ent, qfalse);
}
if ((ent->client->ps.gunframe == 15) && (level.time < ent->client->grenade_time))
@@ -690,8 +609,7 @@ void Weapon_Grenade (edict_t *ent)
ent->client->ps.gunframe++;
- if (ent->client->ps.gunframe == 16)
- {
+ if (ent->client->ps.gunframe == 16) {
ent->client->grenade_time = 0;
ent->client->weaponstate = WEAPON_READY;
}
@@ -706,7 +624,7 @@ GRENADE LAUNCHER
======================================================================
*/
-void weapon_grenadelauncher_fire (edict_t *ent)
+void weapon_grenadelauncher_fire(edict_t *ent)
{
vec3_t offset;
vec3_t forward, right;
@@ -714,38 +632,38 @@ void weapon_grenadelauncher_fire (edict_t *ent)
int damage = 120;
float radius;
- radius = damage+40;
+ radius = damage + 40;
if (is_quad)
damage *= 4;
- VectorSet(offset, 8, 8, ent->viewheight-8);
- AngleVectors (ent->client->v_angle, forward, right, NULL);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ VectorSet(offset, 8, 8, ent->viewheight - 8);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
- fire_grenade (ent, start, forward, damage, 600, 2.5, radius);
+ fire_grenade(ent, start, forward, damage, 600, 2.5, radius);
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_GRENADE | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_GRENADE | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
}
-void Weapon_GrenadeLauncher (edict_t *ent)
+void Weapon_GrenadeLauncher(edict_t *ent)
{
static int pause_frames[] = {34, 51, 59, 0};
static int fire_frames[] = {6, 0};
- Weapon_Generic (ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
+ Weapon_Generic(ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
}
/*
@@ -756,7 +674,7 @@ ROCKET
======================================================================
*/
-void Weapon_RocketLauncher_Fire (edict_t *ent)
+void Weapon_RocketLauncher_Fire(edict_t *ent)
{
vec3_t offset, start;
vec3_t forward, right;
@@ -767,41 +685,40 @@ void Weapon_RocketLauncher_Fire (edict_t *ent)
damage = 100 + (int)(random() * 20.0);
radius_damage = 120;
damage_radius = 120;
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
radius_damage *= 4;
}
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
- VectorSet(offset, 8, 8, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
- fire_rocket (ent, start, forward, damage, 650, damage_radius, radius_damage);
+ VectorSet(offset, 8, 8, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
+ fire_rocket(ent, start, forward, damage, 650, damage_radius, radius_damage);
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_ROCKET | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_ROCKET | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
}
-void Weapon_RocketLauncher (edict_t *ent)
+void Weapon_RocketLauncher(edict_t *ent)
{
static int pause_frames[] = {25, 33, 42, 50, 0};
static int fire_frames[] = {5, 0};
- Weapon_Generic (ent, 4, 12, 50, 54, pause_frames, fire_frames, Weapon_RocketLauncher_Fire);
+ Weapon_Generic(ent, 4, 12, 50, 54, pause_frames, fire_frames, Weapon_RocketLauncher_Fire);
}
@@ -813,7 +730,7 @@ BLASTER / HYPERBLASTER
======================================================================
*/
-void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, int effect)
+void Blaster_Fire(edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, int effect)
{
vec3_t forward, right;
vec3_t start;
@@ -821,30 +738,30 @@ void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, in
if (is_quad)
damage *= 4;
- AngleVectors (ent->client->v_angle, forward, right, NULL);
- VectorSet(offset, 24, 8, ent->viewheight-8);
- VectorAdd (offset, g_offset, offset);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
+ VectorSet(offset, 24, 8, ent->viewheight - 8);
+ VectorAdd(offset, g_offset, offset);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
- fire_blaster (ent, start, forward, damage, 1000, effect, hyper);
+ fire_blaster(ent, start, forward, damage, 1000, effect, hyper);
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
if (hyper)
- gi.WriteByte (MZ_HYPERBLASTER | is_silenced);
+ gi.WriteByte(MZ_HYPERBLASTER | is_silenced);
else
- gi.WriteByte (MZ_BLASTER | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(MZ_BLASTER | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
PlayerNoise(ent, start, PNOISE_WEAPON);
}
-void Weapon_Blaster_Fire (edict_t *ent)
+void Weapon_Blaster_Fire(edict_t *ent)
{
int damage;
@@ -852,20 +769,20 @@ void Weapon_Blaster_Fire (edict_t *ent)
damage = 15;
else
damage = 10;
- Blaster_Fire (ent, vec3_origin, damage, qfalse, EF_BLASTER);
+ Blaster_Fire(ent, vec3_origin, damage, qfalse, EF_BLASTER);
ent->client->ps.gunframe++;
}
-void Weapon_Blaster (edict_t *ent)
+void Weapon_Blaster(edict_t *ent)
{
static int pause_frames[] = {19, 32, 0};
static int fire_frames[] = {5, 0};
- Weapon_Generic (ent, 4, 8, 52, 55, pause_frames, fire_frames, Weapon_Blaster_Fire);
+ Weapon_Generic(ent, 4, 8, 52, 55, pause_frames, fire_frames, Weapon_Blaster_Fire);
}
-void Weapon_HyperBlaster_Fire (edict_t *ent)
+void Weapon_HyperBlaster_Fire(edict_t *ent)
{
float rotation;
vec3_t offset;
@@ -874,24 +791,17 @@ void Weapon_HyperBlaster_Fire (edict_t *ent)
ent->client->weapon_sound = gi.soundindex("weapons/hyprbl1a.wav");
- if (!(ent->client->buttons & BUTTON_ATTACK))
- {
+ if (!(ent->client->buttons & BUTTON_ATTACK)) {
ent->client->ps.gunframe++;
- }
- else
- {
- if (! ent->client->pers.inventory[ent->client->ammo_index] )
- {
- if (level.time >= ent->pain_debounce_time)
- {
+ } else {
+ if (! ent->client->pers.inventory[ent->client->ammo_index]) {
+ if (level.time >= ent->pain_debounce_time) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
- NoAmmoWeaponChange (ent);
- }
- else
- {
- rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
+ NoAmmoWeaponChange(ent);
+ } else {
+ rotation = (ent->client->ps.gunframe - 5) * 2 * M_PI / 6;
offset[0] = -4 * sin(rotation);
offset[1] = 0;
offset[2] = 4 * cos(rotation);
@@ -904,18 +814,15 @@ void Weapon_HyperBlaster_Fire (edict_t *ent)
damage = 15;
else
damage = 20;
- Blaster_Fire (ent, offset, damage, qtrue, effect);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ Blaster_Fire(ent, offset, damage, qtrue, effect);
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
ent->client->anim_priority = ANIM_ATTACK;
- if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
ent->s.frame = FRAME_crattak1 - 1;
ent->client->anim_end = FRAME_crattak9;
- }
- else
- {
+ } else {
ent->s.frame = FRAME_attack1 - 1;
ent->client->anim_end = FRAME_attack8;
}
@@ -926,20 +833,19 @@ void Weapon_HyperBlaster_Fire (edict_t *ent)
ent->client->ps.gunframe = 6;
}
- if (ent->client->ps.gunframe == 12)
- {
+ if (ent->client->ps.gunframe == 12) {
gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/hyprbd1a.wav"), 1, ATTN_NORM, 0);
ent->client->weapon_sound = 0;
}
}
-void Weapon_HyperBlaster (edict_t *ent)
+void Weapon_HyperBlaster(edict_t *ent)
{
static int pause_frames[] = {0};
static int fire_frames[] = {6, 7, 8, 9, 10, 11, 0};
- Weapon_Generic (ent, 5, 20, 49, 53, pause_frames, fire_frames, Weapon_HyperBlaster_Fire);
+ Weapon_Generic(ent, 5, 20, 49, 53, pause_frames, fire_frames, Weapon_HyperBlaster_Fire);
}
/*
@@ -950,7 +856,7 @@ MACHINEGUN / CHAINGUN
======================================================================
*/
-void Machinegun_Fire (edict_t *ent)
+void Machinegun_Fire(edict_t *ent)
{
int i;
vec3_t start;
@@ -960,8 +866,7 @@ void Machinegun_Fire (edict_t *ent)
int kick = 2;
vec3_t offset;
- if (!(ent->client->buttons & BUTTON_ATTACK))
- {
+ if (!(ent->client->buttons & BUTTON_ATTACK)) {
ent->client->machinegun_shots = 0;
ent->client->ps.gunframe++;
return;
@@ -972,26 +877,22 @@ void Machinegun_Fire (edict_t *ent)
else
ent->client->ps.gunframe = 5;
- if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
- {
+ if (ent->client->pers.inventory[ent->client->ammo_index] < 1) {
ent->client->ps.gunframe = 6;
- if (level.time >= ent->pain_debounce_time)
- {
+ if (level.time >= ent->pain_debounce_time) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
- NoAmmoWeaponChange (ent);
+ NoAmmoWeaponChange(ent);
return;
}
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
kick *= 4;
}
- for (i=1 ; i<3 ; i++)
- {
+ for (i = 1 ; i < 3 ; i++) {
ent->client->kick_origin[i] = crandom() * 0.35;
ent->client->kick_angles[i] = crandom() * 0.7;
}
@@ -999,52 +900,48 @@ void Machinegun_Fire (edict_t *ent)
ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;
// raise the gun as it is firing
- if (!deathmatch->value)
- {
+ if (!deathmatch->value) {
ent->client->machinegun_shots++;
if (ent->client->machinegun_shots > 9)
ent->client->machinegun_shots = 9;
}
// get start / end positions
- VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
- AngleVectors (angles, forward, right, NULL);
- VectorSet(offset, 0, 8, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
- fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
+ VectorAdd(ent->client->v_angle, ent->client->kick_angles, angles);
+ AngleVectors(angles, forward, right, NULL);
+ VectorSet(offset, 0, 8, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
+ fire_bullet(ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_MACHINEGUN | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_MACHINEGUN | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
ent->client->anim_priority = ANIM_ATTACK;
- if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
- ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
+ ent->s.frame = FRAME_crattak1 - (int)(random() + 0.25);
ent->client->anim_end = FRAME_crattak9;
- }
- else
- {
- ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
+ } else {
+ ent->s.frame = FRAME_attack1 - (int)(random() + 0.25);
ent->client->anim_end = FRAME_attack8;
}
}
-void Weapon_Machinegun (edict_t *ent)
+void Weapon_Machinegun(edict_t *ent)
{
static int pause_frames[] = {23, 45, 0};
static int fire_frames[] = {4, 5, 0};
- Weapon_Generic (ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
+ Weapon_Generic(ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
}
-void Chaingun_Fire (edict_t *ent)
+void Chaingun_Fire(edict_t *ent)
{
int i;
int shots;
@@ -1063,113 +960,95 @@ void Chaingun_Fire (edict_t *ent)
if (ent->client->ps.gunframe == 5)
gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);
- if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
- {
+ if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK)) {
ent->client->ps.gunframe = 32;
ent->client->weapon_sound = 0;
return;
- }
- else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
- && ent->client->pers.inventory[ent->client->ammo_index])
- {
+ } else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
+ && ent->client->pers.inventory[ent->client->ammo_index]) {
ent->client->ps.gunframe = 15;
- }
- else
- {
+ } else {
ent->client->ps.gunframe++;
}
- if (ent->client->ps.gunframe == 22)
- {
+ if (ent->client->ps.gunframe == 22) {
ent->client->weapon_sound = 0;
gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
- }
- else
- {
+ } else {
ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
}
ent->client->anim_priority = ANIM_ATTACK;
- if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
- {
+ if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
ent->client->anim_end = FRAME_crattak9;
- }
- else
- {
+ } else {
ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
ent->client->anim_end = FRAME_attack8;
}
if (ent->client->ps.gunframe <= 9)
shots = 1;
- else if (ent->client->ps.gunframe <= 14)
- {
+ else if (ent->client->ps.gunframe <= 14) {
if (ent->client->buttons & BUTTON_ATTACK)
shots = 2;
else
shots = 1;
- }
- else
+ } else
shots = 3;
if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
shots = ent->client->pers.inventory[ent->client->ammo_index];
- if (!shots)
- {
- if (level.time >= ent->pain_debounce_time)
- {
+ if (!shots) {
+ if (level.time >= ent->pain_debounce_time) {
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
- NoAmmoWeaponChange (ent);
+ NoAmmoWeaponChange(ent);
return;
}
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
kick *= 4;
}
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0 ; i < 3 ; i++) {
ent->client->kick_origin[i] = crandom() * 0.35;
ent->client->kick_angles[i] = crandom() * 0.7;
}
- for (i=0 ; i<shots ; i++)
- {
+ for (i = 0 ; i < shots ; i++) {
// get start / end positions
- AngleVectors (ent->client->v_angle, forward, right, up);
- r = 7 + crandom()*4;
- u = crandom()*4;
- VectorSet(offset, 0, r, u + ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ AngleVectors(ent->client->v_angle, forward, right, up);
+ r = 7 + crandom() * 4;
+ u = crandom() * 4;
+ VectorSet(offset, 0, r, u + ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
- fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
+ fire_bullet(ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
}
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte((MZ_CHAINGUN1 + shots - 1) | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index] -= shots;
}
-void Weapon_Chaingun (edict_t *ent)
+void Weapon_Chaingun(edict_t *ent)
{
static int pause_frames[] = {38, 43, 51, 61, 0};
static int fire_frames[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
- Weapon_Generic (ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
+ Weapon_Generic(ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
}
@@ -1181,7 +1060,7 @@ SHOTGUN / SUPERSHOTGUN
======================================================================
*/
-void weapon_shotgun_fire (edict_t *ent)
+void weapon_shotgun_fire(edict_t *ent)
{
vec3_t start;
vec3_t forward, right;
@@ -1189,54 +1068,52 @@ void weapon_shotgun_fire (edict_t *ent)
int damage = 4;
int kick = 8;
- if (ent->client->ps.gunframe == 9)
- {
+ if (ent->client->ps.gunframe == 9) {
ent->client->ps.gunframe++;
return;
}
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -2;
- VectorSet(offset, 0, 8, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ VectorSet(offset, 0, 8, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
kick *= 4;
}
if (deathmatch->value)
- fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN);
+ fire_shotgun(ent, start, forward, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN);
else
- fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);
+ fire_shotgun(ent, start, forward, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_SHOTGUN | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_SHOTGUN | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
}
-void Weapon_Shotgun (edict_t *ent)
+void Weapon_Shotgun(edict_t *ent)
{
static int pause_frames[] = {22, 28, 34, 0};
static int fire_frames[] = {8, 9, 0};
- Weapon_Generic (ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
+ Weapon_Generic(ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
}
-void weapon_supershotgun_fire (edict_t *ent)
+void weapon_supershotgun_fire(edict_t *ent)
{
vec3_t start;
vec3_t forward, right;
@@ -1245,16 +1122,15 @@ void weapon_supershotgun_fire (edict_t *ent)
int damage = 6;
int kick = 12;
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -2;
- VectorSet(offset, 0, 8, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
+ VectorSet(offset, 0, 8, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
kick *= 4;
}
@@ -1262,31 +1138,31 @@ void weapon_supershotgun_fire (edict_t *ent)
v[PITCH] = ent->client->v_angle[PITCH];
v[YAW] = ent->client->v_angle[YAW] - 5;
v[ROLL] = ent->client->v_angle[ROLL];
- AngleVectors (v, forward, NULL, NULL);
- fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
+ AngleVectors(v, forward, NULL, NULL);
+ fire_shotgun(ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT / 2, MOD_SSHOTGUN);
v[YAW] = ent->client->v_angle[YAW] + 5;
- AngleVectors (v, forward, NULL, NULL);
- fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
+ AngleVectors(v, forward, NULL, NULL);
+ fire_shotgun(ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT / 2, MOD_SSHOTGUN);
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_SSHOTGUN | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_SSHOTGUN | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index] -= 2;
}
-void Weapon_SuperShotgun (edict_t *ent)
+void Weapon_SuperShotgun(edict_t *ent)
{
static int pause_frames[] = {29, 42, 57, 0};
static int fire_frames[] = {7, 0};
- Weapon_Generic (ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
+ Weapon_Generic(ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
}
@@ -1299,7 +1175,7 @@ RAILGUN
======================================================================
*/
-void weapon_railgun_fire (edict_t *ent)
+void weapon_railgun_fire(edict_t *ent)
{
vec3_t start;
vec3_t forward, right;
@@ -1307,52 +1183,49 @@ void weapon_railgun_fire (edict_t *ent)
int damage;
int kick;
- if (deathmatch->value)
- { // normal damage is too extreme in dm
+ if (deathmatch->value) {
+ // normal damage is too extreme in dm
damage = 100;
kick = 200;
- }
- else
- {
+ } else {
damage = 150;
kick = 250;
}
- if (is_quad)
- {
+ if (is_quad) {
damage *= 4;
kick *= 4;
}
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
- VectorScale (forward, -3, ent->client->kick_origin);
+ VectorScale(forward, -3, ent->client->kick_origin);
ent->client->kick_angles[0] = -3;
- VectorSet(offset, 0, 7, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
- fire_rail (ent, start, forward, damage, kick);
+ VectorSet(offset, 0, 7, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
+ fire_rail(ent, start, forward, damage, kick);
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_RAILGUN | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_RAILGUN | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index]--;
}
-void Weapon_Railgun (edict_t *ent)
+void Weapon_Railgun(edict_t *ent)
{
static int pause_frames[] = {56, 0};
static int fire_frames[] = {4, 0};
- Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
+ Weapon_Generic(ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
}
@@ -1364,7 +1237,7 @@ BFG10K
======================================================================
*/
-void weapon_bfg_fire (edict_t *ent)
+void weapon_bfg_fire(edict_t *ent)
{
vec3_t offset, start;
vec3_t forward, right;
@@ -1376,13 +1249,12 @@ void weapon_bfg_fire (edict_t *ent)
else
damage = 500;
- if (ent->client->ps.gunframe == 9)
- {
+ if (ent->client->ps.gunframe == 9) {
// send muzzle flash
- gi.WriteByte (svc_muzzleflash);
- gi.WriteShort (ent-g_edicts);
- gi.WriteByte (MZ_BFG | is_silenced);
- gi.multicast (ent->s.origin, MULTICAST_PVS);
+ gi.WriteByte(svc_muzzleflash);
+ gi.WriteShort(ent - g_edicts);
+ gi.WriteByte(MZ_BFG | is_silenced);
+ gi.multicast(ent->s.origin, MULTICAST_PVS);
ent->client->ps.gunframe++;
@@ -1392,8 +1264,7 @@ void weapon_bfg_fire (edict_t *ent)
// cells can go down during windup (from power armor hits), so
// check again and abort firing if we don't have enough now
- if (ent->client->pers.inventory[ent->client->ammo_index] < 50)
- {
+ if (ent->client->pers.inventory[ent->client->ammo_index] < 50) {
ent->client->ps.gunframe++;
return;
}
@@ -1401,33 +1272,33 @@ void weapon_bfg_fire (edict_t *ent)
if (is_quad)
damage *= 4;
- AngleVectors (ent->client->v_angle, forward, right, NULL);
+ AngleVectors(ent->client->v_angle, forward, right, NULL);
- VectorScale (forward, -2, ent->client->kick_origin);
+ VectorScale(forward, -2, ent->client->kick_origin);
// make a big pitch kick with an inverse fall
ent->client->v_dmg_pitch = -40;
- ent->client->v_dmg_roll = crandom()*8;
+ ent->client->v_dmg_roll = crandom() * 8;
ent->client->v_dmg_time = level.time + DAMAGE_TIME;
- VectorSet(offset, 8, 8, ent->viewheight-8);
- P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
- fire_bfg (ent, start, forward, damage, 400, damage_radius);
+ VectorSet(offset, 8, 8, ent->viewheight - 8);
+ P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
+ fire_bfg(ent, start, forward, damage, 400, damage_radius);
ent->client->ps.gunframe++;
PlayerNoise(ent, start, PNOISE_WEAPON);
- if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
+ if (!((int)dmflags->value & DF_INFINITE_AMMO))
ent->client->pers.inventory[ent->client->ammo_index] -= 50;
}
-void Weapon_BFG (edict_t *ent)
+void Weapon_BFG(edict_t *ent)
{
static int pause_frames[] = {39, 45, 50, 55, 0};
static int fire_frames[] = {9, 17, 0};
- Weapon_Generic (ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
+ Weapon_Generic(ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
}
diff --git a/src/bsp.c b/src/bsp.c
index 1e7689b..da379c0 100644
--- a/src/bsp.c
+++ b/src/bsp.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -39,51 +39,52 @@ static cvar_t *map_visibility_patch;
===============================================================================
*/
-#define ALLOC( size ) \
- Hunk_Alloc( &bsp->pool, size )
+#define ALLOC(size) \
+ Hunk_Alloc(&bsp->pool, size)
-#define LOAD( Func ) \
- static qerror_t BSP_Load##Func( bsp_t *bsp, void *base, size_t count )
+#define LOAD(func) \
+ static qerror_t BSP_Load##func(bsp_t *bsp, void *base, size_t count)
-#define DEBUG( msg ) \
- Com_DPrintf( "%s: %s\n", __func__, msg )
+#define DEBUG(msg) \
+ Com_DPrintf("%s: %s\n", __func__, msg)
-LOAD( Visibility ) {
+LOAD(Visibility)
+{
unsigned numclusters, bitofs;
int i, j;
- if( !count ) {
+ if (!count) {
return Q_ERR_SUCCESS;
}
- if( count < 4 ) {
- DEBUG( "too small header" );
+ if (count < 4) {
+ DEBUG("too small header");
return Q_ERR_TOO_FEW;
}
bsp->numvisibility = count;
- bsp->vis = ALLOC( count );
- memcpy( bsp->vis, base, count );
+ bsp->vis = ALLOC(count);
+ memcpy(bsp->vis, base, count);
- numclusters = LittleLong( bsp->vis->numclusters );
- if( numclusters > MAX_MAP_LEAFS ) {
- DEBUG( "bad numclusters" );
+ numclusters = LittleLong(bsp->vis->numclusters);
+ if (numclusters > MAX_MAP_LEAFS) {
+ DEBUG("bad numclusters");
return Q_ERR_TOO_MANY;
}
- if( numclusters > ( count - 4 ) / 8 ) {
- DEBUG( "too small header" );
+ if (numclusters > (count - 4) / 8) {
+ DEBUG("too small header");
return Q_ERR_TOO_FEW;
}
bsp->vis->numclusters = numclusters;
- bsp->visrowsize = ( numclusters + 7 ) >> 3;
+ bsp->visrowsize = (numclusters + 7) >> 3;
- for( i = 0; i < numclusters; i++ ) {
- for( j = 0; j < 2; j++ ) {
- bitofs = LittleLong( bsp->vis->bitofs[i][j] );
- if( bitofs >= count ) {
- DEBUG( "bad bitofs" );
+ for (i = 0; i < numclusters; i++) {
+ for (j = 0; j < 2; j++) {
+ bitofs = LittleLong(bsp->vis->bitofs[i][j]);
+ if (bitofs >= count) {
+ DEBUG("bad bitofs");
return Q_ERR_BAD_INDEX;
}
bsp->vis->bitofs[i][j] = bitofs;
@@ -93,7 +94,8 @@ LOAD( Visibility ) {
return Q_ERR_SUCCESS;
}
-LOAD( Texinfo ) {
+LOAD(Texinfo)
+{
dtexinfo_t *in;
mtexinfo_t *out;
int i;
@@ -104,30 +106,30 @@ LOAD( Texinfo ) {
#endif
bsp->numtexinfo = count;
- bsp->texinfo = ALLOC( sizeof( *out ) * count );
+ bsp->texinfo = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->texinfo;
- for( i = 0; i < count; i++, in++, out++ ) {
- memcpy( out->c.name, in->texture, sizeof( out->c.name ) );
- out->c.name[ sizeof( out->c.name ) - 1 ] = 0;
- memcpy( out->name, in->texture, sizeof( out->name ) );
- out->name[ sizeof( out->name ) - 1 ] = 0;
- out->c.flags = LittleLong (in->flags);
- out->c.value = LittleLong (in->value);
+ for (i = 0; i < count; i++, in++, out++) {
+ memcpy(out->c.name, in->texture, sizeof(out->c.name));
+ out->c.name[sizeof(out->c.name) - 1] = 0;
+ memcpy(out->name, in->texture, sizeof(out->name));
+ out->name[sizeof(out->name) - 1] = 0;
+ out->c.flags = LittleLong(in->flags);
+ out->c.value = LittleLong(in->value);
#if USE_REF
- for( j = 0; j < 2; j++ ) {
- for( k = 0; k < 3; k++ ) {
- out->axis[j][k] = LittleFloat( in->vecs[j][k] );
+ for (j = 0; j < 2; j++) {
+ for (k = 0; k < 3; k++) {
+ out->axis[j][k] = LittleFloat(in->vecs[j][k]);
}
- out->offset[j] = LittleFloat( in->vecs[j][k] );
+ out->offset[j] = LittleFloat(in->vecs[j][k]);
}
- next = ( int32_t )LittleLong( in->nexttexinfo );
- if( next > 0 ) {
- if( next >= count ) {
- DEBUG( "bad anim chain" );
+ next = (int32_t)LittleLong(in->nexttexinfo);
+ if (next > 0) {
+ if (next >= count) {
+ DEBUG("bad anim chain");
return Q_ERR_BAD_INDEX;
}
out->next = bsp->texinfo + next;
@@ -140,11 +142,11 @@ LOAD( Texinfo ) {
#if USE_REF
// count animation frames
out = bsp->texinfo;
- for( i = 0; i < count; i++, out++ ) {
+ for (i = 0; i < count; i++, out++) {
out->numframes = 1;
- for( step = out->next; step && step != out; step = step->next ) {
- if( out->numframes == count ) {
- DEBUG( "infinite anim chain" );
+ for (step = out->next; step && step != out; step = step->next) {
+ if (out->numframes == count) {
+ DEBUG("infinite anim chain");
return Q_ERR_INFINITE_LOOP;
}
out->numframes++;
@@ -155,52 +157,54 @@ LOAD( Texinfo ) {
return Q_ERR_SUCCESS;
}
-LOAD( Planes ) {
+LOAD(Planes)
+{
dplane_t *in;
cplane_t *out;
int i, j;
-
+
bsp->numplanes = count;
- bsp->planes = ALLOC( sizeof( *out ) * count );
+ bsp->planes = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->planes;
- for( i = 0; i < count; i++, in++, out++ ) {
- for( j = 0; j < 3; j++ ) {
- out->normal[j] = LittleFloat( in->normal[j] );
+ for (i = 0; i < count; i++, in++, out++) {
+ for (j = 0; j < 3; j++) {
+ out->normal[j] = LittleFloat(in->normal[j]);
}
- out->dist = LittleFloat( in->dist );
- SetPlaneType( out );
- SetPlaneSignbits( out );
+ out->dist = LittleFloat(in->dist);
+ SetPlaneType(out);
+ SetPlaneSignbits(out);
}
return Q_ERR_SUCCESS;
}
-LOAD( BrushSides ) {
+LOAD(BrushSides)
+{
dbrushside_t *in;
mbrushside_t *out;
int i;
unsigned planenum, texinfo;
bsp->numbrushsides = count;
- bsp->brushsides = ALLOC( sizeof( *out ) * count );
+ bsp->brushsides = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->brushsides;
- for( i = 0; i < count; i++, in++, out++ ) {
- planenum = LittleShort (in->planenum);
- if( planenum >= bsp->numplanes ) {
- DEBUG( "bad planenum" );
+ for (i = 0; i < count; i++, in++, out++) {
+ planenum = LittleShort(in->planenum);
+ if (planenum >= bsp->numplanes) {
+ DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
}
out->plane = bsp->planes + planenum;
- texinfo = LittleShort (in->texinfo);
- if( texinfo == ( uint16_t )-1 ) {
+ texinfo = LittleShort(in->texinfo);
+ if (texinfo == (uint16_t)-1) {
out->texinfo = &nulltexinfo;
} else {
if (texinfo >= bsp->numtexinfo) {
- DEBUG( "bad texinfo" );
+ DEBUG("bad texinfo");
return Q_ERR_BAD_INDEX;
}
out->texinfo = bsp->texinfo + texinfo;
@@ -210,23 +214,24 @@ LOAD( BrushSides ) {
return Q_ERR_SUCCESS;
}
-LOAD( Brushes ) {
+LOAD(Brushes)
+{
dbrush_t *in;
mbrush_t *out;
int i;
unsigned firstside, numsides, lastside;
-
+
bsp->numbrushes = count;
- bsp->brushes = ALLOC( sizeof( *out ) * count );
+ bsp->brushes = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->brushes;
- for( i = 0; i < count; i++, out++, in++ ) {
+ for (i = 0; i < count; i++, out++, in++) {
firstside = LittleLong(in->firstside);
numsides = LittleLong(in->numsides);
lastside = firstside + numsides;
- if( lastside < firstside || lastside > bsp->numbrushsides ) {
- DEBUG( "bad brushsides" );
+ if (lastside < firstside || lastside > bsp->numbrushsides) {
+ DEBUG("bad brushsides");
return Q_ERR_BAD_INDEX;
}
out->firstbrushside = bsp->brushsides + firstside;
@@ -238,21 +243,22 @@ LOAD( Brushes ) {
return Q_ERR_SUCCESS;
}
-LOAD( LeafBrushes ) {
+LOAD(LeafBrushes)
+{
uint16_t *in;
mbrush_t **out;
int i;
unsigned brushnum;
-
+
bsp->numleafbrushes = count;
- bsp->leafbrushes = ALLOC( sizeof( *out ) * count );
+ bsp->leafbrushes = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->leafbrushes;
- for( i = 0; i < count; i++, in++, out++ ) {
- brushnum = LittleShort( *in );
- if( brushnum >= bsp->numbrushes ) {
- DEBUG( "bad brushnum" );
+ for (i = 0; i < count; i++, in++, out++) {
+ brushnum = LittleShort(*in);
+ if (brushnum >= bsp->numbrushes) {
+ DEBUG("bad brushnum");
return Q_ERR_BAD_INDEX;
}
*out = bsp->brushes + brushnum;
@@ -263,7 +269,8 @@ LOAD( LeafBrushes ) {
#if USE_REF
-LOAD( Lightmap ) {
+LOAD(Lightmap)
+{
#if USE_REF == REF_SOFT
byte *in;
byte *out;
@@ -272,68 +279,70 @@ LOAD( Lightmap ) {
count /= 3;
#endif
- if( !count ) {
+ if (!count) {
return Q_ERR_SUCCESS;
}
bsp->numlightmapbytes = count;
- bsp->lightmap = ALLOC( count );
+ bsp->lightmap = ALLOC(count);
#if USE_REF == REF_SOFT
// convert the 24 bit lighting down to 8 bit
// by taking the brightest component
in = base;
out = bsp->lightmap;
- for( i = 0; i < count; i++, in += 3, out++ ) {
- if( in[0] > in[1] && in[0] > in[2] )
+ for (i = 0; i < count; i++, in += 3, out++) {
+ if (in[0] > in[1] && in[0] > in[2])
*out = in[0];
- else if( in[1] > in[0] && in[1] > in[2] )
+ else if (in[1] > in[0] && in[1] > in[2])
*out = in[1];
else
*out = in[2];
}
#else
- memcpy( bsp->lightmap, base, count );
+ memcpy(bsp->lightmap, base, count);
#endif
return Q_ERR_SUCCESS;
}
-LOAD( Vertices ) {
+LOAD(Vertices)
+{
dvertex_t *in;
mvertex_t *out;
int i, j;
-
+
bsp->numvertices = count;
- bsp->vertices = ALLOC( sizeof( *out ) * count );
+ bsp->vertices = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->vertices;
- for( i = 0; i < count; i++, out++, in++ ) {
- for( j = 0; j < 3; j++ ) {
- out->point[j] = LittleFloat( in->point[j] );
+ for (i = 0; i < count; i++, out++, in++) {
+ for (j = 0; j < 3; j++) {
+ out->point[j] = LittleFloat(in->point[j]);
}
}
return Q_ERR_SUCCESS;
}
-LOAD( Edges ) {
+LOAD(Edges)
+{
dedge_t *in;
medge_t *out;
int i, j;
unsigned vertnum;
-
+
bsp->numedges = count;
- bsp->edges = ALLOC( sizeof( *out ) * count );
+ bsp->edges = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->edges;
- for( i = 0; i < count; i++, out++, in++ ) {
- for( j = 0; j < 2; j++ ) {
- vertnum = LittleShort( in->v[j] );
- if( vertnum >= bsp->numvertices ) {
- DEBUG( "bad vertnum" );
+ for (i = 0; i < count; i++, out++, in++) {
+ for (j = 0; j < 2; j++) {
+ vertnum = LittleShort(in->v[j]);
+ if (vertnum >= bsp->numvertices) {
+ DEBUG("bad vertnum");
return Q_ERR_BAD_INDEX;
}
out->v[j] = bsp->vertices + vertnum;
@@ -343,28 +352,29 @@ LOAD( Edges ) {
return Q_ERR_SUCCESS;
}
-LOAD( SurfEdges ) {
+LOAD(SurfEdges)
+{
int *in;
msurfedge_t *out;
int i;
int index, vert;
-
+
bsp->numsurfedges = count;
- bsp->surfedges = ALLOC( sizeof( *out ) * count );
+ bsp->surfedges = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->surfedges;
- for( i = 0; i < count; i++, out++, in++ ) {
- index = ( int32_t )LittleLong( *in );
+ for (i = 0; i < count; i++, out++, in++) {
+ index = (int32_t)LittleLong(*in);
vert = 0;
- if( index < 0 ) {
+ if (index < 0) {
index = -index;
vert = 1;
}
- if( index >= bsp->numedges ) {
- DEBUG( "bad edgenum" );
+ if (index >= bsp->numedges) {
+ DEBUG("bad edgenum");
return Q_ERR_BAD_INDEX;
}
@@ -375,7 +385,8 @@ LOAD( SurfEdges ) {
return Q_ERR_SUCCESS;
}
-LOAD( Faces ) {
+LOAD(Faces)
+{
dface_t *in;
mface_t *out;
int i, j;
@@ -384,84 +395,85 @@ LOAD( Faces ) {
unsigned planenum, side;
bsp->numfaces = count;
- bsp->faces = ALLOC( sizeof( *out ) * count );
+ bsp->faces = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->faces;
- for( i = 0; i < count; i++, in++, out++ ) {
- firstedge = LittleLong( in->firstedge );
- numedges = LittleShort( in->numedges );
+ for (i = 0; i < count; i++, in++, out++) {
+ firstedge = LittleLong(in->firstedge);
+ numedges = LittleShort(in->numedges);
lastedge = firstedge + numedges;
- if( numedges < 3 ) {
- DEBUG( "bad surfedges" );
+ if (numedges < 3) {
+ DEBUG("bad surfedges");
return Q_ERR_TOO_FEW;
}
- if( lastedge < firstedge || lastedge > bsp->numsurfedges ) {
- DEBUG( "bad surfedges" );
+ if (lastedge < firstedge || lastedge > bsp->numsurfedges) {
+ DEBUG("bad surfedges");
return Q_ERR_BAD_INDEX;
}
out->firstsurfedge = bsp->surfedges + firstedge;
out->numsurfedges = numedges;
- planenum = LittleShort( in->planenum );
- if( planenum >= bsp->numplanes ) {
- DEBUG( "bad planenum" );
+ planenum = LittleShort(in->planenum);
+ if (planenum >= bsp->numplanes) {
+ DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
}
out->plane = bsp->planes + planenum;
- texinfo = LittleShort( in->texinfo );
- if( texinfo >= bsp->numtexinfo ) {
- DEBUG( "bad texinfo" );
+ texinfo = LittleShort(in->texinfo);
+ if (texinfo >= bsp->numtexinfo) {
+ DEBUG("bad texinfo");
return Q_ERR_BAD_INDEX;
}
out->texinfo = bsp->texinfo + texinfo;
- for( j = 0; j < MAX_LIGHTMAPS && in->styles[j] != 255; j++ ) {
+ for (j = 0; j < MAX_LIGHTMAPS && in->styles[j] != 255; j++) {
out->styles[j] = in->styles[j];
}
out->numstyles = j;
- for( ; j < MAX_LIGHTMAPS; j++ ) {
+ for (; j < MAX_LIGHTMAPS; j++) {
out->styles[j] = 255;
}
- lightofs = LittleLong( in->lightofs );
- if( lightofs == ( uint32_t )-1 || bsp->numlightmapbytes == 0 ) {
+ lightofs = LittleLong(in->lightofs);
+ if (lightofs == (uint32_t)-1 || bsp->numlightmapbytes == 0) {
out->lightmap = NULL;
} else {
#if USE_REF == REF_SOFT
// lighting info is converted from 24 bit on disk to 8 bit
lightofs /= 3;
#endif
- if( lightofs >= bsp->numlightmapbytes ) {
- DEBUG( "bad lightofs" );
+ if (lightofs >= bsp->numlightmapbytes) {
+ DEBUG("bad lightofs");
return Q_ERR_BAD_INDEX;
}
out->lightmap = bsp->lightmap + lightofs;
}
- side = LittleShort( in->side );
+ side = LittleShort(in->side);
out->drawflags = side & DSURF_PLANEBACK;
}
return Q_ERR_SUCCESS;
}
-LOAD( LeafFaces ) {
+LOAD(LeafFaces)
+{
uint16_t *in;
mface_t **out;
int i;
unsigned facenum;
-
+
bsp->numleaffaces = count;
- bsp->leaffaces = ALLOC( sizeof( *out ) * count );
+ bsp->leaffaces = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->leaffaces;
- for( i = 0; i < count; i++, in++, out++ ) {
- facenum = LittleShort( *in );
- if( facenum >= bsp->numfaces ) {
- DEBUG( "bad facenum" );
+ for (i = 0; i < count; i++, in++, out++) {
+ facenum = LittleShort(*in);
+ if (facenum >= bsp->numfaces) {
+ DEBUG("bad facenum");
return Q_ERR_BAD_INDEX;
}
*out = bsp->faces + facenum;
@@ -471,7 +483,8 @@ LOAD( LeafFaces ) {
}
#endif
-LOAD( Leafs ) {
+LOAD(Leafs)
+{
dleaf_t *in;
mleaf_t *out;
int i, cluster;
@@ -481,64 +494,64 @@ LOAD( Leafs ) {
unsigned firstleafface, numleaffaces;
#endif
- if( !count ) {
- DEBUG( "map with no leafs" );
+ if (!count) {
+ DEBUG("map with no leafs");
return Q_ERR_TOO_FEW;
}
bsp->numleafs = count;
- bsp->leafs = ALLOC( sizeof( *out ) * count );
+ bsp->leafs = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->leafs;
- for( i = 0; i < count; i++, in++, out++ ) {
+ for (i = 0; i < count; i++, in++, out++) {
out->plane = NULL;
- out->contents = LittleLong (in->contents);
- cluster = ( int16_t )LittleShort (in->cluster);
- if( cluster == -1 ) {
+ out->contents = LittleLong(in->contents);
+ cluster = (int16_t)LittleShort(in->cluster);
+ if (cluster == -1) {
// solid leafs use special -1 cluster
out->cluster = -1;
- } else if( bsp->vis == NULL ) {
+ } else if (bsp->vis == NULL) {
// map has no vis, let's use 0 as a default cluster
out->cluster = 0;
} else {
// validate cluster
- if( cluster < 0 || cluster >= bsp->vis->numclusters ) {
- DEBUG( "bad cluster" );
+ if (cluster < 0 || cluster >= bsp->vis->numclusters) {
+ DEBUG("bad cluster");
return Q_ERR_BAD_INDEX;
}
out->cluster = cluster;
}
- area = LittleShort( in->area );
- if( area >= bsp->numareas ) {
- DEBUG( "bad area" );
+ area = LittleShort(in->area);
+ if (area >= bsp->numareas) {
+ DEBUG("bad area");
return Q_ERR_BAD_INDEX;
}
out->area = area;
- firstleafbrush = LittleShort (in->firstleafbrush);
- numleafbrushes = LittleShort (in->numleafbrushes);
- if( firstleafbrush + numleafbrushes > bsp->numleafbrushes ) {
- DEBUG( "bad leafbrushes" );
+ firstleafbrush = LittleShort(in->firstleafbrush);
+ numleafbrushes = LittleShort(in->numleafbrushes);
+ if (firstleafbrush + numleafbrushes > bsp->numleafbrushes) {
+ DEBUG("bad leafbrushes");
return Q_ERR_BAD_INDEX;
}
out->firstleafbrush = bsp->leafbrushes + firstleafbrush;
out->numleafbrushes = numleafbrushes;
#if USE_REF
- firstleafface = LittleShort (in->firstleafface);
- numleaffaces = LittleShort (in->numleaffaces);
- if( firstleafface + numleaffaces > bsp->numleaffaces ) {
- DEBUG( "bad leaffaces" );
+ firstleafface = LittleShort(in->firstleafface);
+ numleaffaces = LittleShort(in->numleaffaces);
+ if (firstleafface + numleaffaces > bsp->numleaffaces) {
+ DEBUG("bad leaffaces");
return Q_ERR_BAD_INDEX;
}
out->firstleafface = bsp->leaffaces + firstleafface;
out->numleaffaces = numleaffaces;
- for( j = 0; j < 3; j++ ) {
- out->mins[j] = ( int16_t )LittleShort( in->mins[j] );
- out->maxs[j] = ( int16_t )LittleShort( in->maxs[j] );
+ for (j = 0; j < 3; j++) {
+ out->mins[j] = (int16_t)LittleShort(in->mins[j]);
+ out->maxs[j] = (int16_t)LittleShort(in->maxs[j]);
}
out->parent = NULL;
@@ -547,14 +560,15 @@ LOAD( Leafs ) {
}
if (bsp->leafs[0].contents != CONTENTS_SOLID) {
- DEBUG( "map leaf 0 is not CONTENTS_SOLID" );
+ DEBUG("map leaf 0 is not CONTENTS_SOLID");
return Q_ERR_INVALID_FORMAT;
}
return Q_ERR_SUCCESS;
}
-LOAD( Nodes ) {
+LOAD(Nodes)
+{
dnode_t *in;
uint32_t child;
mnode_t *out;
@@ -564,36 +578,36 @@ LOAD( Nodes ) {
unsigned firstface, numfaces;
#endif
- if( !count ) {
- DEBUG( "map with no nodes" );
+ if (!count) {
+ DEBUG("map with no nodes");
return Q_ERR_TOO_FEW;
}
-
+
bsp->numnodes = count;
- bsp->nodes = ALLOC( sizeof( *out ) * count );
+ bsp->nodes = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->nodes;
- for( i = 0; i < count; i++, out++, in++ ) {
+ for (i = 0; i < count; i++, out++, in++) {
planeNum = LittleLong(in->planenum);
- if( planeNum >= bsp->numplanes ) {
- DEBUG( "bad planenum" );
+ if (planeNum >= bsp->numplanes) {
+ DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
}
out->plane = bsp->planes + planeNum;
- for( j = 0; j < 2; j++ ) {
- child = LittleLong( in->children[j] );
- if( child & 0x80000000 ) {
+ for (j = 0; j < 2; j++) {
+ child = LittleLong(in->children[j]);
+ if (child & 0x80000000) {
child = ~child;
- if( child >= bsp->numleafs ) {
- DEBUG( "bad leafnum" );
+ if (child >= bsp->numleafs) {
+ DEBUG("bad leafnum");
return Q_ERR_BAD_INDEX;
}
- out->children[j] = ( mnode_t * )( bsp->leafs + child );
+ out->children[j] = (mnode_t *)(bsp->leafs + child);
} else {
- if( child >= count ) {
- DEBUG( "bad nodenum" );
+ if (child >= count) {
+ DEBUG("bad nodenum");
return Q_ERR_BAD_INDEX;
}
out->children[j] = bsp->nodes + child;
@@ -601,18 +615,18 @@ LOAD( Nodes ) {
}
#if USE_REF
- firstface = LittleShort( in->firstface );
- numfaces = LittleShort( in->numfaces );
- if( firstface + numfaces > bsp->numfaces ) {
- DEBUG( "bad faces" );
+ firstface = LittleShort(in->firstface);
+ numfaces = LittleShort(in->numfaces);
+ if (firstface + numfaces > bsp->numfaces) {
+ DEBUG("bad faces");
return Q_ERR_BAD_INDEX;
}
out->firstface = bsp->faces + firstface;
out->numfaces = numfaces;
- for( j = 0; j < 3; j++ ) {
- out->mins[j] = ( int16_t )LittleShort( in->mins[j] );
- out->maxs[j] = ( int16_t )LittleShort( in->maxs[j] );
+ for (j = 0; j < 3; j++) {
+ out->mins[j] = (int16_t)LittleShort(in->mins[j]);
+ out->maxs[j] = (int16_t)LittleShort(in->maxs[j]);
}
out->parent = NULL;
@@ -623,7 +637,8 @@ LOAD( Nodes ) {
return Q_ERR_SUCCESS;
}
-LOAD( Submodels ) {
+LOAD(Submodels)
+{
dmodel_t *in;
mmodel_t *out;
int i, j;
@@ -632,46 +647,46 @@ LOAD( Submodels ) {
unsigned firstface, numfaces, lastface;
#endif
- if( !count ) {
- DEBUG( "map with no models" );
+ if (!count) {
+ DEBUG("map with no models");
return Q_ERR_TOO_FEW;
}
- bsp->models = ALLOC( sizeof( *out ) * count );
+ bsp->models = ALLOC(sizeof(*out) * count);
bsp->nummodels = count;
in = base;
out = bsp->models;
- for( i = 0; i < count; i++, in++, out++ ) {
- for( j = 0; j < 3; j++ ) {
+ for (i = 0; i < count; i++, in++, out++) {
+ for (j = 0; j < 3; j++) {
// spread the mins / maxs by a pixel
- out->mins[j] = LittleFloat (in->mins[j]) - 1;
- out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
- out->origin[j] = LittleFloat (in->origin[j]);
+ out->mins[j] = LittleFloat(in->mins[j]) - 1;
+ out->maxs[j] = LittleFloat(in->maxs[j]) + 1;
+ out->origin[j] = LittleFloat(in->origin[j]);
}
- headnode = LittleLong (in->headnode);
- if( headnode >= bsp->numnodes ) {
+ headnode = LittleLong(in->headnode);
+ if (headnode >= bsp->numnodes) {
// FIXME: headnode may be garbage for some models (a leaf perhaps)
- Com_DPrintf( "%s: bad headnode\n", __func__ );
+ Com_DPrintf("%s: bad headnode\n", __func__);
out->headnode = NULL;
} else {
out->headnode = bsp->nodes + headnode;
}
#if USE_REF
- if( i == 0 ) {
+ if (i == 0) {
continue;
}
- firstface = LittleLong( in->firstface );
- numfaces = LittleLong( in->numfaces );
+ firstface = LittleLong(in->firstface);
+ numfaces = LittleLong(in->numfaces);
lastface = firstface + numfaces;
- if( lastface < firstface || lastface > bsp->numfaces ) {
- DEBUG( "bad faces" );
+ if (lastface < firstface || lastface > bsp->numfaces) {
+ DEBUG("bad faces");
return Q_ERR_BAD_INDEX;
}
out->firstface = bsp->faces + firstface;
out->numfaces = numfaces;
- out->radius = RadiusFromBounds( out->mins, out->maxs );
+ out->radius = RadiusFromBounds(out->mins, out->maxs);
#endif
}
@@ -679,41 +694,43 @@ LOAD( Submodels ) {
}
// These are validated after all the areas are loaded
-LOAD( AreaPortals ) {
+LOAD(AreaPortals)
+{
dareaportal_t *in;
mareaportal_t *out;
int i;
bsp->numareaportals = count;
- bsp->areaportals = ALLOC( sizeof( *out ) * count );
+ bsp->areaportals = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->areaportals;
- for( i = 0; i < count; i++, in++, out++ ) {
- out->portalnum = LittleLong (in->portalnum);
- out->otherarea = LittleLong (in->otherarea);
+ for (i = 0; i < count; i++, in++, out++) {
+ out->portalnum = LittleLong(in->portalnum);
+ out->otherarea = LittleLong(in->otherarea);
}
return Q_ERR_SUCCESS;
}
-LOAD( Areas ) {
+LOAD(Areas)
+{
darea_t *in;
marea_t *out;
int i;
unsigned numareaportals, firstareaportal, lastareaportal;
bsp->numareas = count;
- bsp->areas = ALLOC( sizeof( *out ) * count );
+ bsp->areas = ALLOC(sizeof(*out) * count);
in = base;
out = bsp->areas;
- for( i = 0; i < count; i++, in++, out++ ) {
- numareaportals = LittleLong (in->numareaportals);
- firstareaportal = LittleLong (in->firstareaportal);
+ for (i = 0; i < count; i++, in++, out++) {
+ numareaportals = LittleLong(in->numareaportals);
+ firstareaportal = LittleLong(in->firstareaportal);
lastareaportal = firstareaportal + numareaportals;
- if( lastareaportal < firstareaportal || lastareaportal > bsp->numareaportals ) {
- DEBUG( "bad areaportals" );
+ if (lastareaportal < firstareaportal || lastareaportal > bsp->numareaportals) {
+ DEBUG("bad areaportals");
return Q_ERR_BAD_INDEX;
}
out->numareaportals = numareaportals;
@@ -724,10 +741,11 @@ LOAD( Areas ) {
return Q_ERR_SUCCESS;
}
-LOAD( EntString ) {
+LOAD(EntString)
+{
bsp->numentitychars = count;
- bsp->entitystring = ALLOC( count + 1 );
- memcpy( bsp->entitystring, base, count );
+ bsp->entitystring = ALLOC(count + 1);
+ memcpy(bsp->entitystring, base, count);
bsp->entitystring[count] = 0;
return Q_ERR_SUCCESS;
@@ -742,38 +760,37 @@ LOAD( EntString ) {
*/
typedef struct {
- qerror_t (*load)( bsp_t *, void *, size_t );
+ qerror_t (*load)(bsp_t *, void *, size_t);
unsigned lump;
size_t disksize;
size_t memsize;
size_t maxcount;
} lump_info_t;
-#define L( Func, Lump, TypeDisk, TypeMem ) \
- { BSP_Load##Func, LUMP_##Lump, sizeof( TypeDisk ), \
- sizeof( TypeMem ), MAX_MAP_##Lump }
+#define L(func, lump, disk_t, mem_t) \
+ { BSP_Load##func, LUMP_##lump, sizeof(disk_t), sizeof(mem_t), MAX_MAP_##lump }
static const lump_info_t bsp_lumps[] = {
- L( Visibility, VISIBILITY, byte, byte ),
- L( Texinfo, TEXINFO, dtexinfo_t, mtexinfo_t ),
- L( Planes, PLANES, dplane_t, cplane_t ),
- L( BrushSides, BRUSHSIDES, dbrushside_t, mbrushside_t ),
- L( Brushes, BRUSHES, dbrush_t, mbrush_t ),
- L( LeafBrushes, LEAFBRUSHES, uint16_t, mbrush_t * ),
- L( AreaPortals, AREAPORTALS, dareaportal_t, mareaportal_t ),
- L( Areas, AREAS, darea_t, marea_t ),
+ L(Visibility, VISIBILITY, byte, byte),
+ L(Texinfo, TEXINFO, dtexinfo_t, mtexinfo_t),
+ L(Planes, PLANES, dplane_t, cplane_t),
+ L(BrushSides, BRUSHSIDES, dbrushside_t, mbrushside_t),
+ L(Brushes, BRUSHES, dbrush_t, mbrush_t),
+ L(LeafBrushes, LEAFBRUSHES, uint16_t, mbrush_t *),
+ L(AreaPortals, AREAPORTALS, dareaportal_t, mareaportal_t),
+ L(Areas, AREAS, darea_t, marea_t),
#if USE_REF
- L( Lightmap, LIGHTING, byte, byte ),
- L( Vertices, VERTEXES, dvertex_t, mvertex_t ),
- L( Edges, EDGES, dedge_t, medge_t ),
- L( SurfEdges, SURFEDGES, uint32_t, msurfedge_t ),
- L( Faces, FACES, dface_t, mface_t ),
- L( LeafFaces, LEAFFACES, uint16_t, mface_t * ),
+ L(Lightmap, LIGHTING, byte, byte),
+ L(Vertices, VERTEXES, dvertex_t, mvertex_t),
+ L(Edges, EDGES, dedge_t, medge_t),
+ L(SurfEdges, SURFEDGES, uint32_t, msurfedge_t),
+ L(Faces, FACES, dface_t, mface_t),
+ L(LeafFaces, LEAFFACES, uint16_t, mface_t *),
#endif
- L( Leafs, LEAFS, dleaf_t, mleaf_t ),
- L( Nodes, NODES, dnode_t, mnode_t ),
- L( Submodels, MODELS, dmodel_t, mmodel_t ),
- L( EntString, ENTSTRING, char, char ),
+ L(Leafs, LEAFS, dleaf_t, mleaf_t),
+ L(Nodes, NODES, dnode_t, mnode_t),
+ L(Submodels, MODELS, dmodel_t, mmodel_t),
+ L(EntString, ENTSTRING, char, char),
{ NULL }
};
@@ -781,31 +798,33 @@ static const lump_info_t bsp_lumps[] = {
static list_t bsp_cache;
-static void BSP_List_f( void ) {
+static void BSP_List_f(void)
+{
bsp_t *bsp;
size_t bytes;
- if( LIST_EMPTY( &bsp_cache ) ) {
- Com_Printf( "BSP cache is empty\n" );
+ if (LIST_EMPTY(&bsp_cache)) {
+ Com_Printf("BSP cache is empty\n");
return;
}
- Com_Printf( "------------------\n");
+ Com_Printf("------------------\n");
bytes = 0;
- LIST_FOR_EACH( bsp_t, bsp, &bsp_cache, entry ) {
- Com_Printf( "%8"PRIz" : %s (%d refs)\n",
- bsp->pool.mapped, bsp->name, bsp->refcount );
+ LIST_FOR_EACH(bsp_t, bsp, &bsp_cache, entry) {
+ Com_Printf("%8"PRIz" : %s (%d refs)\n",
+ bsp->pool.mapped, bsp->name, bsp->refcount);
bytes += bsp->pool.mapped;
}
- Com_Printf( "Total resident: %"PRIz"\n", bytes );
+ Com_Printf("Total resident: %"PRIz"\n", bytes);
}
-static bsp_t *BSP_Find( const char *name ) {
+static bsp_t *BSP_Find(const char *name)
+{
bsp_t *bsp;
- LIST_FOR_EACH( bsp_t, bsp, &bsp_cache, entry ) {
- if( !FS_pathcmp( bsp->name, name ) ) {
+ LIST_FOR_EACH(bsp_t, bsp, &bsp_cache, entry) {
+ if (!FS_pathcmp(bsp->name, name)) {
return bsp;
}
}
@@ -813,19 +832,20 @@ static bsp_t *BSP_Find( const char *name ) {
return NULL;
}
-static qerror_t BSP_SetParent( mnode_t *node, int key ) {
+static qerror_t BSP_SetParent(mnode_t *node, int key)
+{
mnode_t *child;
#if USE_REF
mface_t *face;
int i;
#endif
- while( node->plane ) {
+ while (node->plane) {
#if USE_REF
// a face may never belong to more than one node
- for( i = 0, face = node->firstface; i < node->numfaces; i++, face++ ) {
- if( face->drawframe ) {
- DEBUG( "duplicate face" );
+ for (i = 0, face = node->firstface; i < node->numfaces; i++, face++) {
+ if (face->drawframe) {
+ DEBUG("duplicate face");
return Q_ERR_INFINITE_LOOP;
}
face->drawframe = key;
@@ -833,18 +853,18 @@ static qerror_t BSP_SetParent( mnode_t *node, int key ) {
#endif
child = node->children[0];
- if( child->parent ) {
- DEBUG( "cycle encountered" );
+ if (child->parent) {
+ DEBUG("cycle encountered");
return Q_ERR_INFINITE_LOOP;
}
child->parent = node;
- if( BSP_SetParent( child, key ) ) {
+ if (BSP_SetParent(child, key)) {
return Q_ERR_INFINITE_LOOP;
}
child = node->children[1];
- if( child->parent ) {
- DEBUG( "cycle encountered" );
+ if (child->parent) {
+ DEBUG("cycle encountered");
return Q_ERR_INFINITE_LOOP;
}
child->parent = node;
@@ -854,7 +874,8 @@ static qerror_t BSP_SetParent( mnode_t *node, int key ) {
return Q_ERR_SUCCESS;
}
-static qerror_t BSP_ValidateTree( bsp_t *bsp ) {
+static qerror_t BSP_ValidateTree(bsp_t *bsp)
+{
mmodel_t *mod;
qerror_t ret;
int i;
@@ -863,24 +884,24 @@ static qerror_t BSP_ValidateTree( bsp_t *bsp ) {
int j;
#endif
- for( i = 0, mod = bsp->models; i < bsp->nummodels; i++, mod++ ) {
- if( i == 0 && mod->headnode != bsp->nodes ) {
- DEBUG( "map model 0 headnode is not the first node" );
+ for (i = 0, mod = bsp->models; i < bsp->nummodels; i++, mod++) {
+ if (i == 0 && mod->headnode != bsp->nodes) {
+ DEBUG("map model 0 headnode is not the first node");
return Q_ERR_INVALID_FORMAT;
}
- if( mod->headnode ) {
- ret = BSP_SetParent( mod->headnode, ~i );
- if( ret ) {
+ if (mod->headnode) {
+ ret = BSP_SetParent(mod->headnode, ~i);
+ if (ret) {
return ret;
}
}
#if USE_REF
// a face may never belong to more than one model
- for( j = 0, face = mod->firstface; j < mod->numfaces; j++, face++ ) {
- if( face->drawframe && face->drawframe != ~i ) {
- DEBUG( "duplicate face" );
+ for (j = 0, face = mod->firstface; j < mod->numfaces; j++, face++) {
+ if (face->drawframe && face->drawframe != ~i) {
+ DEBUG("duplicate face");
return Q_ERR_INFINITE_LOOP;
}
face->drawframe = ~i;
@@ -893,21 +914,22 @@ static qerror_t BSP_ValidateTree( bsp_t *bsp ) {
// also calculates the last portal number used
// by CM code to allocate portalopen[] array
-static qerror_t BSP_ValidateAreaPortals( bsp_t *bsp ) {
+static qerror_t BSP_ValidateAreaPortals(bsp_t *bsp)
+{
mareaportal_t *p;
int i;
bsp->lastareaportal = 0;
- for( i = 0, p = bsp->areaportals; i < bsp->numareaportals; i++, p++ ) {
- if( p->portalnum >= MAX_MAP_AREAPORTALS ) {
- DEBUG( "bad portalnum" );
+ for (i = 0, p = bsp->areaportals; i < bsp->numareaportals; i++, p++) {
+ if (p->portalnum >= MAX_MAP_AREAPORTALS) {
+ DEBUG("bad portalnum");
return Q_ERR_TOO_MANY;
}
- if( p->portalnum > bsp->lastareaportal ) {
+ if (p->portalnum > bsp->lastareaportal) {
bsp->lastareaportal = p->portalnum;
}
- if( p->otherarea >= bsp->numareas ) {
- DEBUG( "bad otherarea" );
+ if (p->otherarea >= bsp->numareas) {
+ DEBUG("bad otherarea");
return Q_ERR_BAD_INDEX;
}
}
@@ -915,17 +937,18 @@ static qerror_t BSP_ValidateAreaPortals( bsp_t *bsp ) {
return Q_ERR_SUCCESS;
}
-void BSP_Free( bsp_t *bsp ) {
- if( !bsp ) {
+void BSP_Free(bsp_t *bsp)
+{
+ if (!bsp) {
return;
}
- if( bsp->refcount <= 0 ) {
- Com_Error( ERR_FATAL, "%s: negative refcount", __func__ );
+ if (bsp->refcount <= 0) {
+ Com_Error(ERR_FATAL, "%s: negative refcount", __func__);
}
- if( --bsp->refcount == 0 ) {
- Hunk_Free( &bsp->pool );
- List_Remove( &bsp->entry );
- Z_Free( bsp );
+ if (--bsp->refcount == 0) {
+ Hunk_Free(&bsp->pool);
+ List_Remove(&bsp->entry);
+ Z_Free(bsp);
}
}
@@ -937,7 +960,8 @@ BSP_Load
Loads in the map and all submodels
==================
*/
-qerror_t BSP_Load( const char *name, bsp_t **bsp_p ) {
+qerror_t BSP_Load(const char *name, bsp_t **bsp_p)
+{
bsp_t *bsp;
byte *buf;
dheader_t *header;
@@ -948,12 +972,12 @@ qerror_t BSP_Load( const char *name, bsp_t **bsp_p ) {
size_t lumpcount[HEADER_LUMPS];
size_t memsize;
- if( !name || !name[0] ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!name || !name[0]) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
- if( ( bsp = BSP_Find( name ) ) != NULL ) {
- Com_PageInMemory( bsp->pool.base, bsp->pool.cursize );
+ if ((bsp = BSP_Find(name)) != NULL) {
+ Com_PageInMemory(bsp->pool.base, bsp->pool.cursize);
bsp->refcount++;
*bsp_p = bsp;
return Q_ERR_SUCCESS;
@@ -964,38 +988,38 @@ qerror_t BSP_Load( const char *name, bsp_t **bsp_p ) {
//
// load the file
//
- filelen = FS_LoadFile( name, ( void ** )&buf );
- if( !buf ) {
+ filelen = FS_LoadFile(name, (void **)&buf);
+ if (!buf) {
return filelen;
}
// byte swap and validate the header
- header = ( dheader_t * )buf;
- if( LittleLong( header->ident ) != IDBSPHEADER ) {
+ header = (dheader_t *)buf;
+ if (LittleLong(header->ident) != IDBSPHEADER) {
ret = Q_ERR_UNKNOWN_FORMAT;
goto fail2;
}
- if( LittleLong( header->version ) != BSPVERSION ) {
+ if (LittleLong(header->version) != BSPVERSION) {
ret = Q_ERR_UNKNOWN_FORMAT;
goto fail2;
}
// byte swap and validate all lumps
memsize = 0;
- for( info = bsp_lumps; info->load; info++ ) {
- ofs = LittleLong( header->lumps[info->lump].fileofs );
- len = LittleLong( header->lumps[info->lump].filelen );
+ for (info = bsp_lumps; info->load; info++) {
+ ofs = LittleLong(header->lumps[info->lump].fileofs);
+ len = LittleLong(header->lumps[info->lump].filelen);
end = ofs + len;
- if( end < ofs || end > filelen ) {
+ if (end < ofs || end > filelen) {
ret = Q_ERR_BAD_EXTENT;
goto fail2;
}
- if( len % info->disksize ) {
+ if (len % info->disksize) {
ret = Q_ERR_ODD_SIZE;
goto fail2;
}
count = len / info->disksize;
- if( count > info->maxcount ) {
+ if (count > info->maxcount) {
ret = Q_ERR_TOO_MANY;
goto fail2;
}
@@ -1007,49 +1031,49 @@ qerror_t BSP_Load( const char *name, bsp_t **bsp_p ) {
}
// load into hunk
- len = strlen( name );
- bsp = Z_Mallocz( sizeof( *bsp ) + len );
- memcpy( bsp->name, name, len + 1 );
+ len = strlen(name);
+ bsp = Z_Mallocz(sizeof(*bsp) + len);
+ memcpy(bsp->name, name, len + 1);
bsp->refcount = 1;
// add an extra page for cacheline alignment overhead
- Hunk_Begin( &bsp->pool, memsize + 4096 );
+ Hunk_Begin(&bsp->pool, memsize + 4096);
// calculate the checksum
- bsp->checksum = LittleLong( Com_BlockChecksum( buf, filelen ) );
+ bsp->checksum = LittleLong(Com_BlockChecksum(buf, filelen));
// load all lumps
- for( info = bsp_lumps; info->load; info++ ) {
- ret = info->load( bsp, lumpdata[info->lump], lumpcount[info->lump] );
- if( ret ) {
+ for (info = bsp_lumps; info->load; info++) {
+ ret = info->load(bsp, lumpdata[info->lump], lumpcount[info->lump]);
+ if (ret) {
goto fail1;
}
}
- ret = BSP_ValidateAreaPortals( bsp );
- if( ret ) {
+ ret = BSP_ValidateAreaPortals(bsp);
+ if (ret) {
goto fail1;
}
- ret = BSP_ValidateTree( bsp );
- if( ret ) {
+ ret = BSP_ValidateTree(bsp);
+ if (ret) {
goto fail1;
}
- Hunk_End( &bsp->pool );
+ Hunk_End(&bsp->pool);
- List_Append( &bsp_cache, &bsp->entry );
+ List_Append(&bsp_cache, &bsp->entry);
- FS_FreeFile( buf );
+ FS_FreeFile(buf);
*bsp_p = bsp;
return Q_ERR_SUCCESS;
fail1:
- Hunk_Free( &bsp->pool );
- Z_Free( bsp );
+ Hunk_Free(&bsp->pool);
+ Z_Free(bsp);
fail2:
- FS_FreeFile( buf );
+ FS_FreeFile(buf);
return ret;
}
@@ -1063,7 +1087,8 @@ HELPER FUNCTIONS
#if USE_REF
-mface_t *BSP_LightPoint( mnode_t *node, vec3_t start, vec3_t end, int *ps, int *pt ) {
+mface_t *BSP_LightPoint(mnode_t *node, vec3_t start, vec3_t end, int *ps, int *pt)
+{
vec_t startFrac, endFrac, midFrac;
vec3_t _start, mid;
int side;
@@ -1072,46 +1097,46 @@ mface_t *BSP_LightPoint( mnode_t *node, vec3_t start, vec3_t end, int *ps, int *
int i;
int s, t;
- VectorCopy( start, _start );
- while( node->plane ) {
+ VectorCopy(start, _start);
+ while (node->plane) {
// calculate distancies
- startFrac = PlaneDiffFast( _start, node->plane );
- endFrac = PlaneDiffFast( end, node->plane );
- side = ( startFrac < 0 );
+ startFrac = PlaneDiffFast(_start, node->plane);
+ endFrac = PlaneDiffFast(end, node->plane);
+ side = (startFrac < 0);
- if( ( endFrac < 0 ) == side ) {
+ if ((endFrac < 0) == side) {
// both points are one the same side
node = node->children[side];
continue;
}
// find crossing point
- midFrac = startFrac / ( startFrac - endFrac );
- LerpVector( _start, end, midFrac, mid );
+ midFrac = startFrac / (startFrac - endFrac);
+ LerpVector(_start, end, midFrac, mid);
// check near side
- surf = BSP_LightPoint( node->children[side], _start, mid, ps, pt );
- if( surf ) {
+ surf = BSP_LightPoint(node->children[side], _start, mid, ps, pt);
+ if (surf) {
return surf;
}
- for( i = 0, surf = node->firstface; i < node->numfaces; i++, surf++ ) {
- if( !surf->lightmap ) {
+ for (i = 0, surf = node->firstface; i < node->numfaces; i++, surf++) {
+ if (!surf->lightmap) {
continue;
}
texinfo = surf->texinfo;
- if( texinfo->c.flags & SURF_NOLM_MASK ) {
+ if (texinfo->c.flags & SURF_NOLM_MASK) {
continue;
}
- s = DotProduct( texinfo->axis[0], mid ) + texinfo->offset[0];
- t = DotProduct( texinfo->axis[1], mid ) + texinfo->offset[1];
+ s = DotProduct(texinfo->axis[0], mid) + texinfo->offset[0];
+ t = DotProduct(texinfo->axis[1], mid) + texinfo->offset[1];
s -= surf->texturemins[0];
t -= surf->texturemins[1];
- if( s < 0 || t < 0 ) {
+ if (s < 0 || t < 0) {
continue;
}
- if( s > surf->extents[0] || t > surf->extents[1] ) {
+ if (s > surf->extents[0] || t > surf->extents[1]) {
continue;
}
@@ -1122,8 +1147,8 @@ mface_t *BSP_LightPoint( mnode_t *node, vec3_t start, vec3_t end, int *ps, int *
}
// check far side
- VectorCopy( mid, _start );
- node = node->children[side^1];
+ VectorCopy(mid, _start);
+ node = node->children[side ^ 1];
}
return NULL;
@@ -1131,79 +1156,79 @@ mface_t *BSP_LightPoint( mnode_t *node, vec3_t start, vec3_t end, int *ps, int *
#endif
-byte *BSP_ClusterVis( bsp_t *bsp, byte *mask, int cluster, int vis ) {
+byte *BSP_ClusterVis(bsp_t *bsp, byte *mask, int cluster, int vis)
+{
byte *in, *out, *in_end, *out_end;
int c;
- if( !bsp || !bsp->vis ) {
- return memset( mask, 0xff, VIS_MAX_BYTES );
+ if (!bsp || !bsp->vis) {
+ return memset(mask, 0xff, VIS_MAX_BYTES);
}
- if( cluster == -1 ) {
- return memset( mask, 0, bsp->visrowsize );
+ if (cluster == -1) {
+ return memset(mask, 0, bsp->visrowsize);
}
- if( cluster < 0 || cluster >= bsp->vis->numclusters ) {
- Com_Error( ERR_DROP, "%s: bad cluster", __func__ );
+ if (cluster < 0 || cluster >= bsp->vis->numclusters) {
+ Com_Error(ERR_DROP, "%s: bad cluster", __func__);
}
// decompress vis
- in_end = ( byte * )bsp->vis + bsp->numvisibility;
- in = ( byte * )bsp->vis + bsp->vis->bitofs[cluster][vis];
+ in_end = (byte *)bsp->vis + bsp->numvisibility;
+ in = (byte *)bsp->vis + bsp->vis->bitofs[cluster][vis];
out_end = mask + bsp->visrowsize;
out = mask;
do {
- if( in >= in_end ) {
+ if (in >= in_end) {
goto overrun;
}
- if( *in ) {
+ if (*in) {
*out++ = *in++;
continue;
}
- if( in + 1 >= in_end ) {
+ if (in + 1 >= in_end) {
goto overrun;
}
c = in[1];
in += 2;
- if( out + c > out_end ) {
+ if (out + c > out_end) {
overrun:
c = out_end - out;
}
- while( c-- ) {
+ while (c--) {
*out++ = 0;
}
- } while( out < out_end );
+ } while (out < out_end);
// apply our ugly PVS patches
- if( map_visibility_patch->integer ) {
- if( bsp->checksum == 0x1e5b50c5 ) {
+ if (map_visibility_patch->integer) {
+ if (bsp->checksum == 0x1e5b50c5) {
// q2dm3, pent bridge
- if( cluster == 345 || cluster == 384 ) {
- Q_SetBit( mask, 466 );
- Q_SetBit( mask, 484 );
- Q_SetBit( mask, 692 );
+ if (cluster == 345 || cluster == 384) {
+ Q_SetBit(mask, 466);
+ Q_SetBit(mask, 484);
+ Q_SetBit(mask, 692);
}
- } else if( bsp->checksum == 0x04cfa792 ) {
+ } else if (bsp->checksum == 0x04cfa792) {
// q2dm1, above lower RL
- if( cluster == 395 ) {
- Q_SetBit( mask, 176 );
- Q_SetBit( mask, 183 );
+ if (cluster == 395) {
+ Q_SetBit(mask, 176);
+ Q_SetBit(mask, 183);
}
- } else if( bsp->checksum == 0x2c3ab9b0 ) {
+ } else if (bsp->checksum == 0x2c3ab9b0) {
// q2dm8, CG/RG area
- if( cluster == 629 || cluster == 631 ||
- cluster == 633 || cluster == 639 )
- {
- Q_SetBit( mask, 908 );
- Q_SetBit( mask, 909 );
- Q_SetBit( mask, 910 );
- Q_SetBit( mask, 915 );
- Q_SetBit( mask, 923 );
- Q_SetBit( mask, 924 );
- Q_SetBit( mask, 927 );
- Q_SetBit( mask, 930 );
- Q_SetBit( mask, 938 );
- Q_SetBit( mask, 939 );
- Q_SetBit( mask, 947 );
+ if (cluster == 629 || cluster == 631 ||
+ cluster == 633 || cluster == 639) {
+ Q_SetBit(mask, 908);
+ Q_SetBit(mask, 909);
+ Q_SetBit(mask, 910);
+ Q_SetBit(mask, 915);
+ Q_SetBit(mask, 923);
+ Q_SetBit(mask, 924);
+ Q_SetBit(mask, 927);
+ Q_SetBit(mask, 930);
+ Q_SetBit(mask, 938);
+ Q_SetBit(mask, 939);
+ Q_SetBit(mask, 947);
}
}
}
@@ -1211,18 +1236,19 @@ overrun:
return mask;
}
-mleaf_t *BSP_PointLeaf( mnode_t *node, vec3_t p ) {
+mleaf_t *BSP_PointLeaf(mnode_t *node, vec3_t p)
+{
float d;
- while( node->plane ) {
- d = PlaneDiffFast( p, node->plane );
- if( d < 0 )
+ while (node->plane) {
+ d = PlaneDiffFast(p, node->plane);
+ if (d < 0)
node = node->children[1];
else
node = node->children[0];
}
- return ( mleaf_t * )node;
+ return (mleaf_t *)node;
}
/*
@@ -1230,28 +1256,30 @@ mleaf_t *BSP_PointLeaf( mnode_t *node, vec3_t p ) {
BSP_InlineModel
==================
*/
-mmodel_t *BSP_InlineModel( bsp_t *bsp, const char *name ) {
+mmodel_t *BSP_InlineModel(bsp_t *bsp, const char *name)
+{
int num;
- if( !bsp || !name ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!bsp || !name) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
- if( name[0] != '*' ) {
- Com_Error( ERR_DROP, "%s: bad name: %s", __func__, name );
+ if (name[0] != '*') {
+ Com_Error(ERR_DROP, "%s: bad name: %s", __func__, name);
}
- num = atoi( name + 1 );
- if( num < 1 || num >= bsp->nummodels ) {
- Com_Error ( ERR_DROP, "%s: bad number: %d", __func__, num );
+ num = atoi(name + 1);
+ if (num < 1 || num >= bsp->nummodels) {
+ Com_Error(ERR_DROP, "%s: bad number: %d", __func__, num);
}
return &bsp->models[num];
}
-void BSP_Init( void ) {
- map_visibility_patch = Cvar_Get( "map_visibility_patch", "1", 0 );
+void BSP_Init(void)
+{
+ map_visibility_patch = Cvar_Get("map_visibility_patch", "1", 0);
- Cmd_AddCommand( "bsplist", BSP_List_f );
+ Cmd_AddCommand("bsplist", BSP_List_f);
- List_Init( &bsp_cache );
+ List_Init(&bsp_cache);
}
diff --git a/src/bsp.h b/src/bsp.h
index 6b675cf..f8ec401 100644
--- a/src/bsp.h
+++ b/src/bsp.h
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -66,13 +66,13 @@ typedef struct {
} msurfedge_t;
#define SURF_NOLM_MASK \
- (SURF_SKY|SURF_WARP|SURF_FLOWING|SURF_TRANS33|SURF_TRANS66)
+ (SURF_SKY | SURF_WARP | SURF_FLOWING | SURF_TRANS33 | SURF_TRANS66)
#define DSURF_PLANEBACK 1
// for lightmap block calculation
-#define S_MAX(surf) (((surf)->extents[0]>>4)+1)
-#define T_MAX(surf) (((surf)->extents[1]>>4)+1)
+#define S_MAX(surf) (((surf)->extents[0] >> 4) + 1)
+#define T_MAX(surf) (((surf)->extents[1] >> 4) + 1)
typedef struct mface_s {
msurfedge_t *firstsurfedge;
@@ -109,7 +109,7 @@ typedef struct mface_s {
#endif
typedef struct mnode_s {
-/* ======> */
+ /* ======> */
cplane_t *plane; // never NULL to differentiate from leafs
#if USE_REF
union {
@@ -123,7 +123,7 @@ typedef struct mnode_s {
int visframe;
#endif
struct mnode_s *parent;
-/* <====== */
+ /* <====== */
struct mnode_s *children[2];
@@ -146,7 +146,7 @@ typedef struct {
} mbrush_t;
typedef struct {
-/* ======> */
+ /* ======> */
cplane_t *plane; // always NULL to differentiate from nodes
#if USE_REF
vec3_t mins;
@@ -155,7 +155,7 @@ typedef struct {
int visframe;
#endif
struct mnode_s *parent;
-/* <====== */
+ /* <====== */
int contents;
int cluster;
@@ -184,9 +184,9 @@ typedef struct {
typedef struct mmodel_s {
#if USE_REF
-/* ======> */
+ /* ======> */
int type;
-/* <====== */
+ /* <====== */
#endif
vec3_t mins, maxs;
vec3_t origin; // for sounds or lights
@@ -194,7 +194,7 @@ typedef struct mmodel_s {
#if USE_REF
float radius;
-
+
int numfaces;
mface_t *firstface;
@@ -222,7 +222,7 @@ typedef struct bsp_s {
cplane_t *planes;
int numnodes;
- mnode_t *nodes;
+ mnode_t *nodes;
int numleafs;
mleaf_t *leafs;
@@ -273,17 +273,17 @@ typedef struct bsp_s {
char name[1];
} bsp_t;
-qerror_t BSP_Load( const char *name, bsp_t **bsp_p );
-void BSP_Free( bsp_t *bsp );
-const char *BSP_GetError( void );
+qerror_t BSP_Load(const char *name, bsp_t **bsp_p);
+void BSP_Free(bsp_t *bsp);
+const char *BSP_GetError(void);
#if USE_REF
-mface_t *BSP_LightPoint( mnode_t *node, vec3_t start, vec3_t end, int *ps, int *pt );
+mface_t *BSP_LightPoint(mnode_t *node, vec3_t start, vec3_t end, int *ps, int *pt);
#endif
-byte *BSP_ClusterVis( bsp_t *bsp, byte *mask, int cluster, int vis );
-mleaf_t *BSP_PointLeaf( mnode_t *node, vec3_t p );
-mmodel_t *BSP_InlineModel( bsp_t *bsp, const char *name );
+byte *BSP_ClusterVis(bsp_t *bsp, byte *mask, int cluster, int vis);
+mleaf_t *BSP_PointLeaf(mnode_t *node, vec3_t p);
+mmodel_t *BSP_InlineModel(bsp_t *bsp, const char *name);
-void BSP_Init( void );
+void BSP_Init(void);
diff --git a/src/cl_aastat.c b/src/cl_aastat.c
index cae2510..e4dc674 100644
--- a/src/cl_aastat.c
+++ b/src/cl_aastat.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -31,18 +31,19 @@ STAT PROGRAMS TO TEXT
#define TH_WIDTH 80
#define TH_HEIGHT 40
-static void TH_DrawString( char *dst, int x, int y, char *src, size_t len ) {
+static void TH_DrawString(char *dst, int x, int y, char *src, size_t len)
+{
int c;
- if( x + len > TH_WIDTH ) {
+ if (x + len > TH_WIDTH) {
len = TH_WIDTH - x;
}
- dst += y * ( TH_WIDTH + 1 ) + x;
- while( len-- ) {
+ dst += y * (TH_WIDTH + 1) + x;
+ while (len--) {
c = *src++;
c &= 127;
- switch( c ) {
+ switch (c) {
case 13: c = '>'; break;
case 16: c = '['; break;
case 17: c = ']'; break;
@@ -50,7 +51,7 @@ static void TH_DrawString( char *dst, int x, int y, char *src, size_t len ) {
case 30: c = '='; break;
case 31: c = '>'; break;
default:
- if( c < 32 ) {
+ if (c < 32) {
c = 32;
}
break;
@@ -59,36 +60,39 @@ static void TH_DrawString( char *dst, int x, int y, char *src, size_t len ) {
}
}
-static void TH_DrawCenterString( char *dst, int x, int y, char *src, size_t len ) {
+static void TH_DrawCenterString(char *dst, int x, int y, char *src, size_t len)
+{
x -= len / 2;
- if( x < 0 ) {
+ if (x < 0) {
src -= x;
x = 0;
}
- TH_DrawString( dst, x, y, src, len );
+ TH_DrawString(dst, x, y, src, len);
}
-static void TH_DrawNumber( char *dst, int x, int y, int width, int value ) {
+static void TH_DrawNumber(char *dst, int x, int y, int width, int value)
+{
char num[16];
int l;
- if( width < 1 )
+ if (width < 1)
return;
// draw number string
- if( width > 5 )
+ if (width > 5)
width = 5;
- l = Q_snprintf( num, sizeof( num ), "%d", value );
- if( l > width )
+ l = Q_snprintf(num, sizeof(num), "%d", value);
+ if (l > width)
l = width;
x += width - l;
- TH_DrawString( dst, x, y, num, l );
+ TH_DrawString(dst, x, y, num, l);
}
-static void TH_DrawLayoutString( char *dst, const char *s ) {
+static void TH_DrawLayoutString(char *dst, const char *s)
+{
char buffer[MAX_QPATH];
int x, y;
int value;
@@ -97,189 +101,189 @@ static void TH_DrawLayoutString( char *dst, const char *s ) {
int width, index;
clientinfo_t *ci;
- if( !s[0] )
+ if (!s[0])
return;
x = 0;
y = 0;
width = 3;
- while( s ) {
- token = COM_Parse( &s );
- if( token[2] == 0 ) {
- if( token[0] == 'x' ) {
- if( token[1] == 'l' ) {
- token = COM_Parse( &s );
- x = atoi( token ) / 8;
+ while (s) {
+ token = COM_Parse(&s);
+ if (token[2] == 0) {
+ if (token[0] == 'x') {
+ if (token[1] == 'l') {
+ token = COM_Parse(&s);
+ x = atoi(token) / 8;
continue;
}
- if( token[1] == 'r' ) {
- token = COM_Parse( &s );
- x = TH_WIDTH + atoi( token ) / 8;
+ if (token[1] == 'r') {
+ token = COM_Parse(&s);
+ x = TH_WIDTH + atoi(token) / 8;
continue;
}
- if( token[1] == 'v' ) {
- token = COM_Parse( &s );
- x = TH_WIDTH / 2 - 20 + atoi( token ) / 8;
+ if (token[1] == 'v') {
+ token = COM_Parse(&s);
+ x = TH_WIDTH / 2 - 20 + atoi(token) / 8;
continue;
}
}
- if( token[0] == 'y' ) {
- if( token[1] == 't' ) {
- token = COM_Parse( &s );
- y = atoi( token ) / 8;
+ if (token[0] == 'y') {
+ if (token[1] == 't') {
+ token = COM_Parse(&s);
+ y = atoi(token) / 8;
continue;
}
- if( token[1] == 'b' ) {
- token = COM_Parse( &s );
- y = TH_HEIGHT + atoi( token ) / 8;
+ if (token[1] == 'b') {
+ token = COM_Parse(&s);
+ y = TH_HEIGHT + atoi(token) / 8;
continue;
}
- if( token[1] == 'v' ) {
- token = COM_Parse( &s );
- y = TH_HEIGHT / 2 - 15 + atoi( token ) / 8;
+ if (token[1] == 'v') {
+ token = COM_Parse(&s);
+ y = TH_HEIGHT / 2 - 15 + atoi(token) / 8;
continue;
}
}
}
- if( !strcmp( token, "pic" ) ) {
+ if (!strcmp(token, "pic")) {
// draw a pic from a stat number
- COM_Parse( &s );
+ COM_Parse(&s);
continue;
}
- if( !strcmp( token, "client" ) ) {
+ if (!strcmp(token, "client")) {
// draw a deathmatch client block
int score, ping, time;
- token = COM_Parse( &s );
- x = TH_WIDTH / 2 - 20 + atoi( token ) / 8;
- token = COM_Parse( &s );
- y = TH_HEIGHT / 2 - 15 + atoi( token ) / 8;
+ token = COM_Parse(&s);
+ x = TH_WIDTH / 2 - 20 + atoi(token) / 8;
+ token = COM_Parse(&s);
+ y = TH_HEIGHT / 2 - 15 + atoi(token) / 8;
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_CLIENTS ) {
- Com_Error( ERR_DROP, "%s: invalid client index", __func__ );
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_CLIENTS) {
+ Com_Error(ERR_DROP, "%s: invalid client index", __func__);
}
ci = &cl.clientinfo[value];
- token = COM_Parse( &s );
- score = atoi( token );
+ token = COM_Parse(&s);
+ score = atoi(token);
- token = COM_Parse( &s );
- ping = atoi( token );
+ token = COM_Parse(&s);
+ ping = atoi(token);
- token = COM_Parse( &s );
- time = atoi( token );
+ token = COM_Parse(&s);
+ time = atoi(token);
- len = strlen( ci->name );
- TH_DrawString( dst, x + 4, y, ci->name, len );
- len = Q_scnprintf( buffer, sizeof( buffer ), "Score: %i", score );
- TH_DrawString( dst, x + 4, y + 1, buffer, len );
- len = Q_scnprintf( buffer, sizeof( buffer ), "Ping: %i", ping );
- TH_DrawString( dst, x + 4, y + 2, buffer, len );
- len = Q_scnprintf( buffer, sizeof( buffer ), "Time: %i", time );
- TH_DrawString( dst, x + 4, y + 3, buffer, len );
+ len = strlen(ci->name);
+ TH_DrawString(dst, x + 4, y, ci->name, len);
+ len = Q_scnprintf(buffer, sizeof(buffer), "Score: %i", score);
+ TH_DrawString(dst, x + 4, y + 1, buffer, len);
+ len = Q_scnprintf(buffer, sizeof(buffer), "Ping: %i", ping);
+ TH_DrawString(dst, x + 4, y + 2, buffer, len);
+ len = Q_scnprintf(buffer, sizeof(buffer), "Time: %i", time);
+ TH_DrawString(dst, x + 4, y + 3, buffer, len);
continue;
}
- if( !strcmp( token, "ctf" ) ) {
+ if (!strcmp(token, "ctf")) {
// draw a ctf client block
int score, ping;
- token = COM_Parse( &s );
- x = TH_WIDTH / 2 - 20 + atoi( token ) / 8;
- token = COM_Parse( &s );
- y = TH_HEIGHT / 2 - 15 + atoi( token ) / 8;
+ token = COM_Parse(&s);
+ x = TH_WIDTH / 2 - 20 + atoi(token) / 8;
+ token = COM_Parse(&s);
+ y = TH_HEIGHT / 2 - 15 + atoi(token) / 8;
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_CLIENTS ) {
- Com_Error( ERR_DROP, "%s: invalid client index", __func__ );
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_CLIENTS) {
+ Com_Error(ERR_DROP, "%s: invalid client index", __func__);
}
ci = &cl.clientinfo[value];
- token = COM_Parse( &s );
- score = atoi( token );
+ token = COM_Parse(&s);
+ score = atoi(token);
- token = COM_Parse( &s );
- ping = atoi( token );
- if( ping > 999 )
+ token = COM_Parse(&s);
+ ping = atoi(token);
+ if (ping > 999)
ping = 999;
- len = Q_scnprintf( buffer, sizeof( buffer ), "%3d %3d %-12.12s",
- score, ping, ci->name );
- TH_DrawString( dst, x, y, buffer, len );
+ len = Q_scnprintf(buffer, sizeof(buffer), "%3d %3d %-12.12s",
+ score, ping, ci->name);
+ TH_DrawString(dst, x, y, buffer, len);
continue;
}
- if( !strcmp( token, "picn" ) ) {
+ if (!strcmp(token, "picn")) {
// draw a pic from a name
- COM_Parse( &s );
+ COM_Parse(&s);
continue;
}
- if( !strcmp( token, "num" ) ) {
+ if (!strcmp(token, "num")) {
// draw a number
- token = COM_Parse( &s );
- width = atoi( token );
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ token = COM_Parse(&s);
+ width = atoi(token);
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
value = cl.frame.ps.stats[value];
- TH_DrawNumber( dst, x, y, width, value );
+ TH_DrawNumber(dst, x, y, width, value);
continue;
}
- if( !strcmp( token, "stat_string" ) ) {
- token = COM_Parse( &s );
- index = atoi( token );
- if( index < 0 || index >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid string index", __func__ );
+ if (!strcmp(token, "stat_string")) {
+ token = COM_Parse(&s);
+ index = atoi(token);
+ if (index < 0 || index >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid string index", __func__);
}
index = cl.frame.ps.stats[index];
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- Com_Error( ERR_DROP, "%s: invalid string index", __func__ );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ Com_Error(ERR_DROP, "%s: invalid string index", __func__);
}
- len = strlen( cl.configstrings[index] );
- TH_DrawString( dst, x, y, cl.configstrings[index], len );
+ len = strlen(cl.configstrings[index]);
+ TH_DrawString(dst, x, y, cl.configstrings[index], len);
continue;
}
- if( !strncmp( token, "cstring", 7 ) ) {
- token = COM_Parse( &s );
- len = strlen( token );
- TH_DrawCenterString( dst, x + 40 / 2, y, token, len );
+ if (!strncmp(token, "cstring", 7)) {
+ token = COM_Parse(&s);
+ len = strlen(token);
+ TH_DrawCenterString(dst, x + 40 / 2, y, token, len);
continue;
}
- if( !strncmp( token, "string", 6 ) ) {
- token = COM_Parse( &s );
- len = strlen( token );
- TH_DrawString( dst, x, y, token, len );
+ if (!strncmp(token, "string", 6)) {
+ token = COM_Parse(&s);
+ len = strlen(token);
+ TH_DrawString(dst, x, y, token, len);
continue;
}
- if( !strcmp( token, "if" ) ) {
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ if (!strcmp(token, "if")) {
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
value = cl.frame.ps.stats[value];
- if( !value ) { // skip to endif
- while( strcmp( token, "endif" ) ) {
- token = COM_Parse( &s );
- if( !s ) {
+ if (!value) { // skip to endif
+ while (strcmp(token, "endif")) {
+ token = COM_Parse(&s);
+ if (!s) {
break;
}
}
@@ -289,83 +293,86 @@ static void TH_DrawLayoutString( char *dst, const char *s ) {
}
}
-static void SCR_ScoreShot_f( void ) {
- char buffer[( TH_WIDTH + 1 ) * TH_HEIGHT];
+static void SCR_ScoreShot_f(void)
+{
+ char buffer[(TH_WIDTH + 1) * TH_HEIGHT];
char path[MAX_OSPATH];
qhandle_t f;
int i;
qerror_t ret;
- if( cls.state != ca_active ) {
- Com_Printf( "Must be in a level.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("Must be in a level.\n");
return;
}
- if( Cmd_Argc() > 1 ) {
- f = FS_EasyOpenFile( path, sizeof( path ), FS_MODE_WRITE | FS_FLAG_TEXT,
- SCORESHOTS_DIRECTORY "/", Cmd_Argv( 1 ), ".txt" );
- if( !f ) {
+ if (Cmd_Argc() > 1) {
+ f = FS_EasyOpenFile(path, sizeof(path), FS_MODE_WRITE | FS_FLAG_TEXT,
+ SCORESHOTS_DIRECTORY "/", Cmd_Argv(1), ".txt");
+ if (!f) {
return;
}
} else {
- // find a file name to save it to
- for( i = 0; i < 1000; i++ ) {
- Q_snprintf( path, sizeof( path ), SCORESHOTS_DIRECTORY "/quake%03d.txt", i );
- ret = FS_FOpenFile( path, &f, FS_MODE_WRITE | FS_FLAG_TEXT | FS_FLAG_EXCL );
- if( f ) {
+ // find a file name to save it to
+ for (i = 0; i < 1000; i++) {
+ Q_snprintf(path, sizeof(path), SCORESHOTS_DIRECTORY "/quake%03d.txt", i);
+ ret = FS_FOpenFile(path, &f, FS_MODE_WRITE | FS_FLAG_TEXT | FS_FLAG_EXCL);
+ if (f) {
break;
}
- if( ret != Q_ERR_EXIST ) {
- Com_EPrintf( "Couldn't exclusively open %s for writing: %s\n",
- path, Q_ErrorString( ret ) );
+ if (ret != Q_ERR_EXIST) {
+ Com_EPrintf("Couldn't exclusively open %s for writing: %s\n",
+ path, Q_ErrorString(ret));
return;
}
}
- if( i == 1000 ) {
- Com_EPrintf( "All scoreshot slots are full.\n" );
+ if (i == 1000) {
+ Com_EPrintf("All scoreshot slots are full.\n");
return;
}
}
- memset( buffer, ' ', sizeof( buffer ) );
- for( i = 0; i < TH_HEIGHT; i++ ) {
- buffer[ i * ( TH_WIDTH + 1 ) + TH_WIDTH ] = '\n';
+ memset(buffer, ' ', sizeof(buffer));
+ for (i = 0; i < TH_HEIGHT; i++) {
+ buffer[i * (TH_WIDTH + 1) + TH_WIDTH] = '\n';
}
- TH_DrawLayoutString( buffer, cl.configstrings[CS_STATUSBAR] );
- TH_DrawLayoutString( buffer, cl.layout );
+ TH_DrawLayoutString(buffer, cl.configstrings[CS_STATUSBAR]);
+ TH_DrawLayoutString(buffer, cl.layout);
- FS_Write( buffer, sizeof( buffer ), f );
+ FS_Write(buffer, sizeof(buffer), f);
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- Com_Printf( "Wrote %s.\n", path );
+ Com_Printf("Wrote %s.\n", path);
}
-static void SCR_ScoreDump_f( void ) {
- char buffer[( TH_WIDTH + 1 ) * TH_HEIGHT];
+static void SCR_ScoreDump_f(void)
+{
+ char buffer[(TH_WIDTH + 1) * TH_HEIGHT];
int i;
- if( cls.state != ca_active ) {
- Com_Printf( "Must be in a level.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("Must be in a level.\n");
return;
}
- memset( buffer, ' ', sizeof( buffer ) );
- for( i = 0; i < TH_HEIGHT - 1; i++ ) {
- buffer[ i * ( TH_WIDTH + 1 ) + TH_WIDTH ] = '\n';
+ memset(buffer, ' ', sizeof(buffer));
+ for (i = 0; i < TH_HEIGHT - 1; i++) {
+ buffer[i * (TH_WIDTH + 1) + TH_WIDTH] = '\n';
}
- buffer[ i * ( TH_WIDTH + 1 ) + TH_WIDTH ] = 0;
+ buffer[i * (TH_WIDTH + 1) + TH_WIDTH] = 0;
- TH_DrawLayoutString( buffer, cl.configstrings[CS_STATUSBAR] );
- TH_DrawLayoutString( buffer, cl.layout );
+ TH_DrawLayoutString(buffer, cl.configstrings[CS_STATUSBAR]);
+ TH_DrawLayoutString(buffer, cl.layout);
- Com_Printf( "%s\n", buffer );
+ Com_Printf("%s\n", buffer);
}
-void CL_InitAscii( void ) {
- Cmd_AddCommand( "aashot", SCR_ScoreShot_f );
- Cmd_AddCommand( "aadump", SCR_ScoreDump_f );
+void CL_InitAscii(void)
+{
+ Cmd_AddCommand("aashot", SCR_ScoreShot_f);
+ Cmd_AddCommand("aadump", SCR_ScoreDump_f);
}
diff --git a/src/cl_console.c b/src/cl_console.c
index d91572b..175fde8 100644
--- a/src/cl_console.c
+++ b/src/cl_console.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,10 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "prompt.h"
#define CON_TIMES 16
-#define CON_TIMES_MASK ( CON_TIMES - 1 )
+#define CON_TIMES_MASK (CON_TIMES - 1)
#define CON_TOTALLINES 1024 // total lines in console scrollback
-#define CON_TOTALLINES_MASK ( CON_TOTALLINES - 1 )
+#define CON_TOTALLINES_MASK (CON_TOTALLINES - 1)
#define CON_LINEWIDTH 100 // fixed width, do not need more
@@ -58,7 +58,7 @@ typedef struct console_s {
float scale;
unsigned times[CON_TIMES]; // cls.realtime time the line was generated
- // for transparent notify lines
+ // for transparent notify lines
qboolean skipNotify;
qhandle_t backImage;
@@ -97,7 +97,8 @@ static cvar_t *con_history;
Con_SkipNotify
================
*/
-void Con_SkipNotify( qboolean skip ) {
+void Con_SkipNotify(qboolean skip)
+{
con.skipNotify = skip;
}
@@ -106,10 +107,11 @@ void Con_SkipNotify( qboolean skip ) {
Con_ClearTyping
================
*/
-void Con_ClearTyping( void ) {
+void Con_ClearTyping(void)
+{
// clear any typing
- IF_Clear( &con.prompt.inputLine );
- Prompt_ClearState( &con.prompt );
+ IF_Clear(&con.prompt.inputLine);
+ Prompt_ClearState(&con.prompt);
}
/*
@@ -120,15 +122,16 @@ Instantly removes the console. Unless `force' is true, does not remove the conso
if user has typed something into it since the last call to Con_Popup.
================
*/
-void Con_Close( qboolean force ) {
- if( con.mode && !force ) {
+void Con_Close(qboolean force)
+{
+ if (con.mode && !force) {
return;
}
Con_ClearTyping();
Con_ClearNotify_f();
- Key_SetDest( cls.key_dest & ~KEY_CONSOLE );
+ Key_SetDest(cls.key_dest & ~KEY_CONSOLE);
con.destHeight = con.currentHeight = 0;
con.mode = CON_DEFAULT;
@@ -142,12 +145,13 @@ Con_Popup
Drop to connection screen.
================
*/
-void Con_Popup( void ) {
- if( con.mode == CON_DEFAULT ) {
+void Con_Popup(void)
+{
+ if (con.mode == CON_DEFAULT) {
con.mode = CON_POPUP;
}
- Key_SetDest( cls.key_dest | KEY_CONSOLE );
+ Key_SetDest(cls.key_dest | KEY_CONSOLE);
Con_RunConsole();
}
@@ -158,40 +162,44 @@ Con_ToggleConsole_f
Toggles console up/down animation.
================
*/
-static void toggle_console( consoleMode_t mode, chatMode_t chat ) {
+static void toggle_console(consoleMode_t mode, chatMode_t chat)
+{
SCR_EndLoadingPlaque(); // get rid of loading plaque
Con_ClearTyping();
Con_ClearNotify_f();
- if( cls.key_dest & KEY_CONSOLE ) {
- Key_SetDest( cls.key_dest & ~KEY_CONSOLE );
+ if (cls.key_dest & KEY_CONSOLE) {
+ Key_SetDest(cls.key_dest & ~KEY_CONSOLE);
con.mode = CON_DEFAULT;
con.chat = CHAT_NONE;
return;
}
- if( mode == CON_CHAT && ( cls.state != ca_active || cls.demo.playback ) ) {
- Com_Printf( "You must be in a level to chat.\n" );
+ if (mode == CON_CHAT && (cls.state != ca_active || cls.demo.playback)) {
+ Com_Printf("You must be in a level to chat.\n");
return;
}
// toggling console discards chat message
- Key_SetDest( ( cls.key_dest | KEY_CONSOLE ) & ~KEY_MESSAGE );
+ Key_SetDest((cls.key_dest | KEY_CONSOLE) & ~KEY_MESSAGE);
con.mode = mode;
con.chat = chat;
}
-void Con_ToggleConsole_f( void ) {
- toggle_console( CON_DEFAULT, CHAT_NONE );
+void Con_ToggleConsole_f(void)
+{
+ toggle_console(CON_DEFAULT, CHAT_NONE);
}
-static void Con_ToggleChat_f( void ) {
- toggle_console( CON_CHAT, CHAT_DEFAULT );
+static void Con_ToggleChat_f(void)
+{
+ toggle_console(CON_CHAT, CHAT_DEFAULT);
}
-static void Con_ToggleChat2_f( void ) {
- toggle_console( CON_CHAT, CHAT_TEAM );
+static void Con_ToggleChat2_f(void)
+{
+ toggle_console(CON_CHAT, CHAT_TEAM);
}
/*
@@ -199,14 +207,16 @@ static void Con_ToggleChat2_f( void ) {
Con_Clear_f
================
*/
-static void Con_Clear_f( void ) {
- memset( con.text, 0, sizeof( con.text ) );
+static void Con_Clear_f(void)
+{
+ memset(con.text, 0, sizeof(con.text));
con.display = con.current;
}
-static void Con_Dump_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- FS_File_g( "condumps", ".txt", FS_SEARCH_STRIPEXT, ctx );
+static void Con_Dump_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ FS_File_g("condumps", ".txt", FS_SEARCH_STRIPEXT, ctx);
}
}
@@ -217,51 +227,53 @@ Con_Dump_f
Save the console contents out to a file
================
*/
-static void Con_Dump_f( void ) {
+static void Con_Dump_f(void)
+{
int l;
char *line;
qhandle_t f;
char name[MAX_OSPATH];
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- f = FS_EasyOpenFile( name, sizeof( name ), FS_MODE_WRITE | FS_FLAG_TEXT,
- "condumps/", Cmd_Argv( 1 ), ".txt" );
- if( !f ) {
+ f = FS_EasyOpenFile(name, sizeof(name), FS_MODE_WRITE | FS_FLAG_TEXT,
+ "condumps/", Cmd_Argv(1), ".txt");
+ if (!f) {
return;
}
// skip empty lines
- for( l = con.current - CON_TOTALLINES + 1 ; l <= con.current ; l++ ) {
- if( con.text[l & CON_TOTALLINES_MASK][0] ) {
+ for (l = con.current - CON_TOTALLINES + 1; l <= con.current; l++) {
+ if (con.text[l & CON_TOTALLINES_MASK][0]) {
break;
}
}
// write the remaining lines
- for( ; l <= con.current ; l++ ) {
+ for (; l <= con.current; l++) {
line = con.text[l & CON_TOTALLINES_MASK];
- FS_FPrintf( f, "%s\n", line + 1 );
+ FS_FPrintf(f, "%s\n", line + 1);
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- Com_Printf( "Dumped console text to %s.\n", name );
+ Com_Printf("Dumped console text to %s.\n", name);
}
-
+
/*
================
Con_ClearNotify_f
================
*/
-void Con_ClearNotify_f( void ) {
+void Con_ClearNotify_f(void)
+{
int i;
-
- for( i = 0; i < CON_TIMES; i++ )
+
+ for (i = 0; i < CON_TIMES; i++)
con.times[i] = 0;
}
@@ -270,25 +282,28 @@ void Con_ClearNotify_f( void ) {
Con_MessageMode_f
================
*/
-static void start_message_mode( chatMode_t mode ) {
- if( cls.state != ca_active || cls.demo.playback ) {
- Com_Printf( "You must be in a level to chat.\n" );
+static void start_message_mode(chatMode_t mode)
+{
+ if (cls.state != ca_active || cls.demo.playback) {
+ Com_Printf("You must be in a level to chat.\n");
return;
}
- Con_Close( qtrue );
+ Con_Close(qtrue);
con.chat = mode;
- IF_Replace( &con.chatPrompt.inputLine, Cmd_RawArgs() );
- Key_SetDest( cls.key_dest | KEY_MESSAGE );
+ IF_Replace(&con.chatPrompt.inputLine, Cmd_RawArgs());
+ Key_SetDest(cls.key_dest | KEY_MESSAGE);
}
-static void Con_MessageMode_f( void ) {
- start_message_mode( CHAT_DEFAULT );
+static void Con_MessageMode_f(void)
+{
+ start_message_mode(CHAT_DEFAULT);
}
-static void Con_MessageMode2_f( void ) {
- start_message_mode( CHAT_TEAM );
+static void Con_MessageMode2_f(void)
+{
+ start_message_mode(CHAT_TEAM);
}
/*
@@ -296,40 +311,42 @@ static void Con_MessageMode2_f( void ) {
Con_RemoteMode_f
================
*/
-static void Con_RemoteMode_f( void ) {
+static void Con_RemoteMode_f(void)
+{
netadr_t adr;
char *s;
- if( Cmd_Argc() != 3 ) {
- Com_Printf( "Usage: %s <address> <password>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 3) {
+ Com_Printf("Usage: %s <address> <password>\n", Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- if( !NET_StringToAdr( s, &adr, PORT_SERVER ) ) {
- Com_Printf( "Bad address: %s\n", s );
+ s = Cmd_Argv(1);
+ if (!NET_StringToAdr(s, &adr, PORT_SERVER)) {
+ Com_Printf("Bad address: %s\n", s);
return;
}
- s = Cmd_Argv( 2 );
+ s = Cmd_Argv(2);
- if( !( cls.key_dest & KEY_CONSOLE ) ) {
- toggle_console( CON_REMOTE, CHAT_NONE );
+ if (!(cls.key_dest & KEY_CONSOLE)) {
+ toggle_console(CON_REMOTE, CHAT_NONE);
} else {
con.mode = CON_REMOTE;
con.chat = CHAT_NONE;
}
con.remoteAddress = adr;
- if( con.remotePassword ) {
- Z_Free( con.remotePassword );
+ if (con.remotePassword) {
+ Z_Free(con.remotePassword);
}
- con.remotePassword = Z_CopyString( s );
+ con.remotePassword = Z_CopyString(s);
}
-static void CL_RemoteMode_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Com_Address_g( ctx );
+static void CL_RemoteMode_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Com_Address_g(ctx);
}
}
@@ -340,15 +357,16 @@ Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
-static void Con_CheckResize( void ) {
+static void Con_CheckResize(void)
+{
int width;
con.vidWidth = r_config.width * con.scale;
con.vidHeight = r_config.height * con.scale;
- width = ( con.vidWidth / CHAR_WIDTH ) - 2;
+ width = (con.vidWidth / CHAR_WIDTH) - 2;
- if( width == con.linewidth )
+ if (width == con.linewidth)
return;
con.linewidth = width > CON_LINEWIDTH ? CON_LINEWIDTH : width;
@@ -364,19 +382,21 @@ Con_CheckTop
Make sure at least one line is visible if console is backscrolled.
================
*/
-static void Con_CheckTop( void ) {
+static void Con_CheckTop(void)
+{
int top = con.current - CON_TOTALLINES + 1;
- if( top < 1 ) {
+ if (top < 1) {
top = 1;
}
- if( con.display < top ) {
+ if (con.display < top) {
con.display = top;
}
}
-static void con_param_changed( cvar_t *self ) {
- if( con.initialized && cls.ref_initialized ) {
+static void con_param_changed(cvar_t *self)
+{
+ if (con.initialized && cls.ref_initialized) {
Con_RegisterMedia();
}
}
@@ -400,30 +420,31 @@ static const cmdreg_t c_console[] = {
Con_Init
================
*/
-void Con_Init( void ) {
- memset( &con, 0, sizeof( con ) );
+void Con_Init(void)
+{
+ memset(&con, 0, sizeof(con));
//
// register our commands
//
- Cmd_Register( c_console );
-
- con_notifytime = Cvar_Get( "con_notifytime", "3", 0 );
- con_notifylines = Cvar_Get( "con_notifylines", "4", 0 );
- con_clock = Cvar_Get( "con_clock", "0", 0 );
- con_height = Cvar_Get( "con_height", "0.5", 0 );
- con_speed = Cvar_Get( "scr_conspeed", "3", 0 );
- con_alpha = Cvar_Get( "con_alpha", "1", 0 );
- con_scale = Cvar_Get( "con_scale", "1", 0 );
- con_font = Cvar_Get( "con_font", "conchars", 0 );
+ Cmd_Register(c_console);
+
+ con_notifytime = Cvar_Get("con_notifytime", "3", 0);
+ con_notifylines = Cvar_Get("con_notifylines", "4", 0);
+ con_clock = Cvar_Get("con_clock", "0", 0);
+ con_height = Cvar_Get("con_height", "0.5", 0);
+ con_speed = Cvar_Get("scr_conspeed", "3", 0);
+ con_alpha = Cvar_Get("con_alpha", "1", 0);
+ con_scale = Cvar_Get("con_scale", "1", 0);
+ con_font = Cvar_Get("con_font", "conchars", 0);
con_font->changed = con_param_changed;
- con_background = Cvar_Get( "con_background", "conback", 0 );
+ con_background = Cvar_Get("con_background", "conback", 0);
con_background->changed = con_param_changed;
- con_scroll = Cvar_Get( "con_scroll", "0", 0 );
- con_history = Cvar_Get( "con_history", "0", 0 );
+ con_scroll = Cvar_Get("con_scroll", "0", 0);
+ con_history = Cvar_Get("con_history", "0", 0);
- IF_Init( &con.prompt.inputLine, 0, MAX_FIELD_TEXT - 1 );
- IF_Init( &con.chatPrompt.inputLine, 0, MAX_FIELD_TEXT - 1 );
+ IF_Init(&con.prompt.inputLine, 0, MAX_FIELD_TEXT - 1);
+ IF_Init(&con.chatPrompt.inputLine, 0, MAX_FIELD_TEXT - 1);
con.prompt.printf = Con_Printf;
@@ -441,9 +462,10 @@ void Con_Init( void ) {
con.initialized = qtrue;
}
-void Con_PostInit( void ) {
- if( con_history->integer > 0 ) {
- Prompt_LoadHistory( &con.prompt, COM_HISTORYFILE_NAME );
+void Con_PostInit(void)
+{
+ if (con_history->integer > 0) {
+ Prompt_LoadHistory(&con.prompt, COM_HISTORYFILE_NAME);
}
}
@@ -452,44 +474,48 @@ void Con_PostInit( void ) {
Con_Shutdown
================
*/
-void Con_Shutdown( void ) {
- if( con_history->integer > 0 ) {
- Prompt_SaveHistory( &con.prompt, COM_HISTORYFILE_NAME, con_history->integer );
+void Con_Shutdown(void)
+{
+ if (con_history->integer > 0) {
+ Prompt_SaveHistory(&con.prompt, COM_HISTORYFILE_NAME, con_history->integer);
}
- Prompt_Clear( &con.prompt );
+ Prompt_Clear(&con.prompt);
}
-static void Con_CarriageRet( void ) {
+static void Con_CarriageRet(void)
+{
char *p;
p = con.text[con.current & CON_TOTALLINES_MASK];
- memset( p, 0, sizeof( con.text[0] ) );
+ memset(p, 0, sizeof(con.text[0]));
// add color from last line
con.x = 0;
p[con.x++] = con.color;
// update time for transparent overlay
- if( !con.skipNotify ) {
+ if (!con.skipNotify) {
con.times[con.current & CON_TIMES_MASK] = cls.realtime;
}
}
-static void Con_Linefeed( void ) {
- if( con.display == con.current )
+static void Con_Linefeed(void)
+{
+ if (con.display == con.current)
con.display++;
con.current++;
Con_CarriageRet();
- if( con_scroll->integer & 2 ) {
+ if (con_scroll->integer & 2) {
con.display = con.current;
} else {
Con_CheckTop();
}
}
-void Con_SetColor( color_index_t color ) {
+void Con_SetColor(color_index_t color)
+{
con.color = color;
}
@@ -502,16 +528,17 @@ All console printing must go through this in order to be displayed on screen
If no console is visible, the text will appear at the top of the game window
================
*/
-void Con_Print( const char *txt ) {
+void Con_Print(const char *txt)
+{
char *p;
int l;
- if( !con.initialized )
+ if (!con.initialized)
return;
- while( *txt ) {
- if( con.newline ) {
- if( con.newline == '\n' ) {
+ while (*txt) {
+ if (con.newline) {
+ if (con.newline == '\n') {
Con_Linefeed();
} else {
Con_CarriageRet();
@@ -519,23 +546,23 @@ void Con_Print( const char *txt ) {
con.newline = 0;
}
- // count word length
- for( p = ( char * )txt; *p > 32; p++ )
+ // count word length
+ for (p = (char *)txt; *p > 32; p++)
;
l = p - txt;
- // word wrap
- if( l < con.linewidth && con.x + l > con.linewidth ) {
+ // word wrap
+ if (l < con.linewidth && con.x + l > con.linewidth) {
Con_Linefeed();
}
- switch( *txt ) {
+ switch (*txt) {
case '\r':
case '\n':
con.newline = *txt;
break;
default: // display character and advance
- if( con.x == con.linewidth ) {
+ if (con.x == con.linewidth) {
Con_Linefeed();
}
p = con.text[con.current & CON_TOTALLINES_MASK];
@@ -555,15 +582,16 @@ Print text to graphical console only,
bypassing system console and logfiles
================
*/
-void Con_Printf( const char *fmt, ... ) {
+void Con_Printf(const char *fmt, ...)
+{
va_list argptr;
char msg[MAXPRINTMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- Con_Print( msg );
+ Con_Print(msg);
}
/*
@@ -571,30 +599,31 @@ void Con_Printf( const char *fmt, ... ) {
Con_RegisterMedia
================
*/
-void Con_RegisterMedia( void ) {
+void Con_RegisterMedia(void)
+{
qerror_t ret;
- ret = _R_RegisterFont( con_font->string, &con.charsetImage );
- if( !con.charsetImage ) {
- if( strcmp( con_font->string, "conchars" ) ) {
- Com_WPrintf( "Couldn't load console font: %s\n", Q_ErrorString( ret ) );
- Cvar_Reset( con_font );
- ret = _R_RegisterFont( "conchars", &con.charsetImage );
+ ret = _R_RegisterFont(con_font->string, &con.charsetImage);
+ if (!con.charsetImage) {
+ if (strcmp(con_font->string, "conchars")) {
+ Com_WPrintf("Couldn't load console font: %s\n", Q_ErrorString(ret));
+ Cvar_Reset(con_font);
+ ret = _R_RegisterFont("conchars", &con.charsetImage);
}
- if( !con.charsetImage ) {
- Com_Error( ERR_FATAL, "Couldn't load pics/conchars.pcx: %s", Q_ErrorString( ret ) );
+ if (!con.charsetImage) {
+ Com_Error(ERR_FATAL, "Couldn't load pics/conchars.pcx: %s", Q_ErrorString(ret));
}
}
- ret = _R_RegisterPic( con_background->string, &con.backImage );
- if( !con.backImage ) {
- if( strcmp( con_background->string, "conback" ) ) {
- Com_WPrintf( "Couldn't load console background: %s\n", Q_ErrorString( ret ) );
- Cvar_Reset( con_background );
- ret = _R_RegisterPic( "conback", &con.backImage );
+ ret = _R_RegisterPic(con_background->string, &con.backImage);
+ if (!con.backImage) {
+ if (strcmp(con_background->string, "conback")) {
+ Com_WPrintf("Couldn't load console background: %s\n", Q_ErrorString(ret));
+ Cvar_Reset(con_background);
+ ret = _R_RegisterPic("conback", &con.backImage);
}
- if( !con.charsetImage ) {
- Com_EPrintf( "Couldn't load pics/conback.pcx: %s\n", Q_ErrorString( ret ) );
+ if (!con.charsetImage) {
+ Com_EPrintf("Couldn't load pics/conback.pcx: %s\n", Q_ErrorString(ret));
}
}
}
@@ -607,36 +636,37 @@ DRAWING
==============================================================================
*/
-static int Con_DrawLine( int v, int line, float alpha ) {
+static int Con_DrawLine(int v, int line, float alpha)
+{
char *p = con.text[line & CON_TOTALLINES_MASK];
color_index_t c = *p;
color_t color;
int flags = 0;
- switch( c ) {
+ switch (c) {
case COLOR_ALT:
flags = UI_ALTCOLOR;
// fall through
case COLOR_NONE:
R_ClearColor();
- if( alpha != 1 ) {
- R_SetAlpha( alpha );
+ if (alpha != 1) {
+ R_SetAlpha(alpha);
}
break;
default:
color.u32 = colorTable[c & 7];
- if( alpha != 1 ) {
+ if (alpha != 1) {
color.u8[3] = alpha * 255;
}
- R_SetColor( color.u32 );
+ R_SetColor(color.u32);
break;
}
- return R_DrawString( CHAR_WIDTH, v, flags, con.linewidth - 1, p + 1,
- con.charsetImage );
+ return R_DrawString(CHAR_WIDTH, v, flags, con.linewidth - 1, p + 1,
+ con.charsetImage);
}
-#define CON_PRESTEP ( 10 + CHAR_HEIGHT * 2 )
+#define CON_PRESTEP (10 + CHAR_HEIGHT * 2)
/*
================
@@ -645,7 +675,8 @@ Con_DrawNotify
Draws the last few lines of output transparently over the game top
================
*/
-static void Con_DrawNotify( void ) {
+static void Con_DrawNotify(void)
+{
int v;
char *text;
int i, j;
@@ -654,45 +685,45 @@ static void Con_DrawNotify( void ) {
float alpha;
// only draw notify in game
- if( cls.state != ca_active ) {
- return;
+ if (cls.state != ca_active) {
+ return;
}
- if( cls.key_dest & ( KEY_MENU|KEY_CONSOLE ) ) {
+ if (cls.key_dest & (KEY_MENU | KEY_CONSOLE)) {
return;
}
- if( con.currentHeight ) {
+ if (con.currentHeight) {
return;
}
j = con_notifylines->integer;
- if( j > CON_TIMES ) {
+ if (j > CON_TIMES) {
j = CON_TIMES;
}
v = 0;
- for( i = con.current - j + 1; i <= con.current; i++ ) {
- if( i < 0 )
+ for (i = con.current - j + 1; i <= con.current; i++) {
+ if (i < 0)
continue;
time = con.times[i & CON_TIMES_MASK];
- if( time == 0 )
+ if (time == 0)
continue;
// alpha fade the last string left on screen
- alpha = SCR_FadeAlpha( time, con_notifytime->value * 1000, 300 );
- if( !alpha )
+ alpha = SCR_FadeAlpha(time, con_notifytime->value * 1000, 300);
+ if (!alpha)
continue;
- if( v || i != con.current ) {
+ if (v || i != con.current) {
alpha = 1; // don't fade
}
- Con_DrawLine( v, i, alpha );
+ Con_DrawLine(v, i, alpha);
v += CHAR_HEIGHT;
}
R_ClearColor();
- if( cls.key_dest & KEY_MESSAGE ) {
- if( con.chat == CHAT_TEAM ) {
+ if (cls.key_dest & KEY_MESSAGE) {
+ if (con.chat == CHAT_TEAM) {
text = "say_team:";
skip = 11;
} else {
@@ -700,11 +731,11 @@ static void Con_DrawNotify( void ) {
skip = 5;
}
- R_DrawString( CHAR_WIDTH, v, 0, MAX_STRING_CHARS, text,
- con.charsetImage );
+ R_DrawString(CHAR_WIDTH, v, 0, MAX_STRING_CHARS, text,
+ con.charsetImage);
con.chatPrompt.inputLine.visibleChars = con.linewidth - skip + 1;
- IF_Draw( &con.chatPrompt.inputLine, skip * CHAR_WIDTH, v,
- UI_DRAWCURSOR, con.charsetImage );
+ IF_Draw(&con.chatPrompt.inputLine, skip * CHAR_WIDTH, v,
+ UI_DRAWCURSOR, con.charsetImage);
}
}
@@ -715,7 +746,8 @@ Con_DrawSolidConsole
Draws the console with the solid background
================
*/
-static void Con_DrawSolidConsole( void ) {
+static void Con_DrawSolidConsole(void)
+{
int i, x, y;
int rows;
char *text;
@@ -727,35 +759,34 @@ static void Con_DrawSolidConsole( void ) {
int widths[2];
vislines = con.vidHeight * con.currentHeight;
- if( vislines <= 0 )
+ if (vislines <= 0)
return;
- if( vislines > con.vidHeight )
+ if (vislines > con.vidHeight)
vislines = con.vidHeight;
// setup transparency
- if( cls.state == ca_active &&
+ if (cls.state == ca_active &&
con_alpha->value &&
- ( cls.key_dest & KEY_MENU ) == 0 )
- {
- alpha = 0.5f + 0.5f * ( con.currentHeight / con_height->value );
- R_SetAlpha( alpha * Cvar_ClampValue( con_alpha, 0, 1 ) );
+ (cls.key_dest & KEY_MENU) == 0) {
+ alpha = 0.5f + 0.5f * (con.currentHeight / con_height->value);
+ R_SetAlpha(alpha * Cvar_ClampValue(con_alpha, 0, 1));
}
clip.left = 0;
clip.top = 0;
clip.right = 0;
clip.bottom = 0;
- R_SetClipRect( DRAW_CLIP_TOP, &clip );
+ R_SetClipRect(DRAW_CLIP_TOP, &clip);
// draw the background
- if( cls.state != ca_active || ( cls.key_dest & KEY_MENU ) || con_alpha->value ) {
- R_DrawStretchPic( 0, vislines - con.vidHeight,
- con.vidWidth, con.vidHeight, con.backImage );
+ if (cls.state != ca_active || (cls.key_dest & KEY_MENU) || con_alpha->value) {
+ R_DrawStretchPic(0, vislines - con.vidHeight,
+ con.vidWidth, con.vidHeight, con.backImage);
}
#if 0
- if( cls.state > ca_disconnected && cls.state < ca_active ) {
- R_DrawFill( 0, vislines, con.vidWidth, con.vidHeight - vislines, 0 );
+ if (cls.state > ca_disconnected && cls.state < ca_active) {
+ R_DrawFill(0, vislines, con.vidWidth, con.vidHeight - vislines, 0);
}
#endif
@@ -764,12 +795,12 @@ static void Con_DrawSolidConsole( void ) {
rows = y / CHAR_HEIGHT + 1; // rows of text to draw
// draw arrows to show the buffer is backscrolled
- if( con.display != con.current ) {
- R_SetColor( U32_RED );
- for( i = 1; i < con.linewidth / 2; i += 4 ) {
- R_DrawChar( i * CHAR_WIDTH, y, 0, '^', con.charsetImage );
+ if (con.display != con.current) {
+ R_SetColor(U32_RED);
+ for (i = 1; i < con.linewidth / 2; i += 4) {
+ R_DrawChar(i * CHAR_WIDTH, y, 0, '^', con.charsetImage);
}
-
+
y -= CHAR_HEIGHT;
rows--;
}
@@ -778,52 +809,52 @@ static void Con_DrawSolidConsole( void ) {
R_ClearColor();
row = con.display;
widths[0] = widths[1] = 0;
- for( i = 0; i < rows; i++ ) {
- if( row < 0 )
+ for (i = 0; i < rows; i++) {
+ if (row < 0)
break;
- if( con.current - row > CON_TOTALLINES - 1 )
+ if (con.current - row > CON_TOTALLINES - 1)
break; // past scrollback wrap point
-
- x = Con_DrawLine( y, row, 1 );
- if( i < 2 ) {
+
+ x = Con_DrawLine(y, row, 1);
+ if (i < 2) {
widths[i] = x;
}
y -= CHAR_HEIGHT;
row--;
}
-
+
R_ClearColor();
//ZOID
// draw the download bar
// figure out width
- if( cls.download.current ) {
+ if (cls.download.current) {
int n, j;
- if( ( text = strrchr( cls.download.current->path, '/' ) ) != NULL )
+ if ((text = strrchr(cls.download.current->path, '/')) != NULL)
text++;
else
text = cls.download.current->path;
- x = con.linewidth - ( ( con.linewidth * 7 ) / 40 );
- y = x - strlen( text ) - 8;
+ x = con.linewidth - ((con.linewidth * 7) / 40);
+ y = x - strlen(text) - 8;
i = con.linewidth / 3;
- if ( strlen( text ) > i ) {
+ if (strlen(text) > i) {
y = x - i - 11;
- strncpy( buffer, text, i );
+ strncpy(buffer, text, i);
buffer[i] = 0;
- strcat( buffer, "..." );
+ strcat(buffer, "...");
} else {
- strcpy( buffer, text );
+ strcpy(buffer, text);
}
- strcat( buffer, ": " );
- i = strlen( buffer );
+ strcat(buffer, ": ");
+ i = strlen(buffer);
buffer[i++] = '\x80';
// where's the dot go?
- n = y * cls.download.percent / 100;
- for ( j = 0; j < y; j++ ) {
- if ( j == n ) {
+ n = y * cls.download.percent / 100;
+ for (j = 0; j < y; j++) {
+ if (j == n) {
buffer[i++] = '\x83';
} else {
buffer[i++] = '\x81';
@@ -832,21 +863,21 @@ static void Con_DrawSolidConsole( void ) {
buffer[i++] = '\x82';
buffer[i] = 0;
- sprintf( buffer + i, " %02d%%", cls.download.percent );
+ sprintf(buffer + i, " %02d%%", cls.download.percent);
// draw it
y = vislines - 10;
- R_DrawString( CHAR_WIDTH, y, 0, CON_LINEWIDTH, buffer, con.charsetImage );
+ R_DrawString(CHAR_WIDTH, y, 0, CON_LINEWIDTH, buffer, con.charsetImage);
}
//ZOID
// draw the input prompt, user text, and cursor if desired
x = 0;
- if( cls.key_dest & KEY_CONSOLE ) {
+ if (cls.key_dest & KEY_CONSOLE) {
y = vislines - CON_PRESTEP + CHAR_HEIGHT;
// draw command prompt
- switch( con.mode ) {
+ switch (con.mode) {
case CON_CHAT:
i = '&';
break;
@@ -857,46 +888,46 @@ static void Con_DrawSolidConsole( void ) {
i = 17;
break;
}
- R_SetColor( U32_YELLOW );
- R_DrawChar( CHAR_WIDTH, y, 0, i, con.charsetImage );
+ R_SetColor(U32_YELLOW);
+ R_DrawChar(CHAR_WIDTH, y, 0, i, con.charsetImage);
R_ClearColor();
// draw input line
- x = IF_Draw( &con.prompt.inputLine, 2 * CHAR_WIDTH, y,
- UI_DRAWCURSOR, con.charsetImage );
+ x = IF_Draw(&con.prompt.inputLine, 2 * CHAR_WIDTH, y,
+ UI_DRAWCURSOR, con.charsetImage);
}
#define APP_VERSION APPLICATION " " VERSION
-#define VER_WIDTH ( ( int )( sizeof( APP_VERSION ) + 1 ) * CHAR_WIDTH )
+#define VER_WIDTH ((int)(sizeof(APP_VERSION) + 1) * CHAR_WIDTH)
y = vislines - CON_PRESTEP + CHAR_HEIGHT;
row = 0;
// shift version upwards to prevent overdraw
- if( x > con.vidWidth - VER_WIDTH ) {
+ if (x > con.vidWidth - VER_WIDTH) {
y -= CHAR_HEIGHT;
row++;
}
- R_SetColor( U32_CYAN );
+ R_SetColor(U32_CYAN);
// draw clock
- if( con_clock->integer ) {
- x = Com_Time_m( buffer, sizeof( buffer ) ) * CHAR_WIDTH;
- if( widths[row] + x + CHAR_WIDTH <= con.vidWidth ) {
- R_DrawString( con.vidWidth - CHAR_WIDTH - x, y - CHAR_HEIGHT,
- UI_RIGHT, MAX_STRING_CHARS, buffer, con.charsetImage );
+ if (con_clock->integer) {
+ x = Com_Time_m(buffer, sizeof(buffer)) * CHAR_WIDTH;
+ if (widths[row] + x + CHAR_WIDTH <= con.vidWidth) {
+ R_DrawString(con.vidWidth - CHAR_WIDTH - x, y - CHAR_HEIGHT,
+ UI_RIGHT, MAX_STRING_CHARS, buffer, con.charsetImage);
}
}
// draw version
- if( !row || widths[0] + VER_WIDTH <= con.vidWidth ) {
- SCR_DrawStringEx( con.vidWidth - CHAR_WIDTH, y, UI_RIGHT,
- MAX_STRING_CHARS, APP_VERSION, con.charsetImage );
+ if (!row || widths[0] + VER_WIDTH <= con.vidWidth) {
+ SCR_DrawStringEx(con.vidWidth - CHAR_WIDTH, y, UI_RIGHT,
+ MAX_STRING_CHARS, APP_VERSION, con.charsetImage);
}
// restore rendering parameters
R_ClearColor();
- R_SetClipRect( DRAW_CLIP_DISABLED, NULL );
+ R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
}
//=============================================================================
@@ -908,19 +939,20 @@ Con_RunConsole
Scroll it up or down
==================
*/
-void Con_RunConsole( void ) {
- if( cls.disable_screen ) {
+void Con_RunConsole(void)
+{
+ if (cls.disable_screen) {
con.destHeight = con.currentHeight = 0;
return;
}
- if( !( cls.key_dest & KEY_MENU ) ) {
- if( cls.state == ca_disconnected ) {
+ if (!(cls.key_dest & KEY_MENU)) {
+ if (cls.state == ca_disconnected) {
// draw fullscreen console
con.destHeight = con.currentHeight = 1;
return;
}
- if( cls.state > ca_disconnected && cls.state < ca_active ) {
+ if (cls.state > ca_disconnected && cls.state < ca_active) {
// draw half-screen console
con.destHeight = con.currentHeight = 0.5f;
return;
@@ -928,20 +960,20 @@ void Con_RunConsole( void ) {
}
// decide on the height of the console
- if( cls.key_dest & KEY_CONSOLE ) {
- con.destHeight = Cvar_ClampValue( con_height, 0.1f, 1 );
+ if (cls.key_dest & KEY_CONSOLE) {
+ con.destHeight = Cvar_ClampValue(con_height, 0.1f, 1);
} else {
con.destHeight = 0; // none visible
}
- if( con.currentHeight > con.destHeight ) {
+ if (con.currentHeight > con.destHeight) {
con.currentHeight -= con_speed->value * cls.frametime;
- if( con.currentHeight < con.destHeight ) {
+ if (con.currentHeight < con.destHeight) {
con.currentHeight = con.destHeight;
}
- } else if( con.currentHeight < con.destHeight ) {
+ } else if (con.currentHeight < con.destHeight) {
con.currentHeight += con_speed->value * cls.frametime;
- if( con.currentHeight > con.destHeight ) {
+ if (con.currentHeight > con.destHeight) {
con.currentHeight = con.destHeight;
}
}
@@ -952,17 +984,18 @@ void Con_RunConsole( void ) {
SCR_DrawConsole
==================
*/
-void Con_DrawConsole( void ) {
- Cvar_ClampValue( con_scale, 1, 9 );
+void Con_DrawConsole(void)
+{
+ Cvar_ClampValue(con_scale, 1, 9);
con.scale = 1.0f / con_scale->value;
- R_SetScale( &con.scale );
+ R_SetScale(&con.scale);
Con_CheckResize();
Con_DrawSolidConsole();
- Con_DrawNotify();
+ Con_DrawNotify();
- R_SetScale( NULL );
+ R_SetScale(NULL);
}
@@ -974,81 +1007,85 @@ void Con_DrawConsole( void ) {
==============================================================================
*/
-static void Con_Say( char *msg ) {
- CL_ClientCommand( va( "say%s \"%s\"", con.chat == CHAT_TEAM ? "_team" : "", msg ) );
+static void Con_Say(char *msg)
+{
+ CL_ClientCommand(va("say%s \"%s\"", con.chat == CHAT_TEAM ? "_team" : "", msg));
}
// don't close console after connecting
-static void Con_InteractiveMode( void ) {
- if( !con.mode ) {
+static void Con_InteractiveMode(void)
+{
+ if (!con.mode) {
con.mode = CON_DEFAULT;
}
}
-static void Con_Action( void ) {
- char *cmd = Prompt_Action( &con.prompt );
+static void Con_Action(void)
+{
+ char *cmd = Prompt_Action(&con.prompt);
Con_InteractiveMode();
-
- if( !cmd ) {
- Con_Printf( "]\n" );
+
+ if (!cmd) {
+ Con_Printf("]\n");
return;
}
-
+
// backslash text are commands, else chat
- if( cmd[0] == '\\' || cmd[0] == '/' ) {
- Cbuf_AddText( &cmd_buffer, cmd + 1 ); // skip slash
- Cbuf_AddText( &cmd_buffer, "\n" );
+ if (cmd[0] == '\\' || cmd[0] == '/') {
+ Cbuf_AddText(&cmd_buffer, cmd + 1); // skip slash
+ Cbuf_AddText(&cmd_buffer, "\n");
} else {
- if( con.mode == CON_REMOTE ) {
- CL_SendRcon( &con.remoteAddress, con.remotePassword, cmd );
- } else if( cls.state == ca_active && con.mode == CON_CHAT ) {
- Con_Say( cmd );
+ if (con.mode == CON_REMOTE) {
+ CL_SendRcon(&con.remoteAddress, con.remotePassword, cmd);
+ } else if (cls.state == ca_active && con.mode == CON_CHAT) {
+ Con_Say(cmd);
} else {
- Cbuf_AddText( &cmd_buffer, cmd );
- Cbuf_AddText( &cmd_buffer, "\n" );
+ Cbuf_AddText(&cmd_buffer, cmd);
+ Cbuf_AddText(&cmd_buffer, "\n");
}
}
- Con_Printf( "]%s\n", cmd );
+ Con_Printf("]%s\n", cmd);
- if( cls.state == ca_disconnected ) {
- SCR_UpdateScreen (); // force an update, because the command
- // may take some time
+ if (cls.state == ca_disconnected) {
+ // force an update, because the command may take some time
+ SCR_UpdateScreen();
}
}
-static void Con_Paste( void ) {
+static void Con_Paste(void)
+{
char *cbd, *s;
Con_InteractiveMode();
- if( ( cbd = VID_GetClipboardData() ) == NULL ) {
+ if ((cbd = VID_GetClipboardData()) == NULL) {
return;
}
s = cbd;
- while( *s ) {
+ while (*s) {
int c = *s++;
- switch( c ) {
+ switch (c) {
case '\n':
- if( *s ) {
+ if (*s) {
Con_Action();
}
break;
case '\r':
case '\t':
- IF_CharEvent( &con.prompt.inputLine, ' ' );
+ IF_CharEvent(&con.prompt.inputLine, ' ');
break;
default:
- if( Q_isprint( c ) ) {
- IF_CharEvent( &con.prompt.inputLine, c );
+ if (Q_isprint(c)) {
+ IF_CharEvent(&con.prompt.inputLine, c);
}
break;
}
}
- Z_Free( cbd );
+ Z_Free(cbd);
}
/*
@@ -1058,56 +1095,56 @@ Key_Console
Interactive line editing and console scrollback
====================
*/
-void Key_Console( int key ) {
- if( key == 'l' && Key_IsDown( K_CTRL ) ) {
+void Key_Console(int key)
+{
+ if (key == 'l' && Key_IsDown(K_CTRL)) {
Con_Clear_f();
return;
}
- if( key == 'd' && Key_IsDown( K_CTRL ) ) {
+ if (key == 'd' && Key_IsDown(K_CTRL)) {
con.mode = CON_DEFAULT;
return;
}
- if( key == K_ENTER || key == K_KP_ENTER ) {
+ if (key == K_ENTER || key == K_KP_ENTER) {
Con_Action();
goto scroll;
}
- if( ( key == 'v' && Key_IsDown( K_CTRL ) ) ||
- ( key == K_INS && Key_IsDown( K_SHIFT ) ) || key == K_MOUSE3 )
- {
+ if ((key == 'v' && Key_IsDown(K_CTRL)) ||
+ (key == K_INS && Key_IsDown(K_SHIFT)) || key == K_MOUSE3) {
Con_Paste();
goto scroll;
}
- if( key == K_TAB ) {
- Prompt_CompleteCommand( &con.prompt, qtrue );
+ if (key == K_TAB) {
+ Prompt_CompleteCommand(&con.prompt, qtrue);
goto scroll;
}
- if( key == 'r' && Key_IsDown( K_CTRL ) ) {
- Prompt_CompleteHistory( &con.prompt, qfalse );
+ if (key == 'r' && Key_IsDown(K_CTRL)) {
+ Prompt_CompleteHistory(&con.prompt, qfalse);
goto scroll;
}
- if( key == 's' && Key_IsDown( K_CTRL ) ) {
- Prompt_CompleteHistory( &con.prompt, qtrue );
+ if (key == 's' && Key_IsDown(K_CTRL)) {
+ Prompt_CompleteHistory(&con.prompt, qtrue);
goto scroll;
}
- if( key == K_UPARROW || ( key == 'p' && Key_IsDown( K_CTRL ) ) ) {
- Prompt_HistoryUp( &con.prompt );
+ if (key == K_UPARROW || (key == 'p' && Key_IsDown(K_CTRL))) {
+ Prompt_HistoryUp(&con.prompt);
goto scroll;
}
- if( key == K_DOWNARROW || ( key == 'n' && Key_IsDown( K_CTRL ) ) ) {
- Prompt_HistoryDown( &con.prompt );
+ if (key == K_DOWNARROW || (key == 'n' && Key_IsDown(K_CTRL))) {
+ Prompt_HistoryDown(&con.prompt);
goto scroll;
}
- if( key == K_PGUP || key == K_MWHEELUP ) {
- if( Key_IsDown( K_CTRL ) ) {
+ if (key == K_PGUP || key == K_MWHEELUP) {
+ if (Key_IsDown(K_CTRL)) {
con.display -= 6;
} else {
con.display -= 2;
@@ -1116,42 +1153,43 @@ void Key_Console( int key ) {
return;
}
- if( key == K_PGDN || key == K_MWHEELDOWN ) {
- if( Key_IsDown( K_CTRL ) ) {
+ if (key == K_PGDN || key == K_MWHEELDOWN) {
+ if (Key_IsDown(K_CTRL)) {
con.display += 6;
} else {
con.display += 2;
}
- if( con.display > con.current ) {
+ if (con.display > con.current) {
con.display = con.current;
}
return;
}
- if( key == K_HOME && Key_IsDown( K_CTRL ) ) {
+ if (key == K_HOME && Key_IsDown(K_CTRL)) {
con.display = 1;
Con_CheckTop();
return;
}
- if( key == K_END && Key_IsDown( K_CTRL ) ) {
+ if (key == K_END && Key_IsDown(K_CTRL)) {
con.display = con.current;
return;
}
- if( IF_KeyEvent( &con.prompt.inputLine, key ) ) {
- Prompt_ClearState( &con.prompt );
+ if (IF_KeyEvent(&con.prompt.inputLine, key)) {
+ Prompt_ClearState(&con.prompt);
Con_InteractiveMode();
}
-scroll:
- if( con_scroll->integer & 1 ) {
+scroll:
+ if (con_scroll->integer & 1) {
con.display = con.current;
}
}
-void Char_Console( int key ) {
- if( IF_CharEvent( &con.prompt.inputLine, key ) ) {
+void Char_Console(int key)
+{
+ if (IF_CharEvent(&con.prompt.inputLine, key)) {
Con_InteractiveMode();
}
}
@@ -1161,55 +1199,57 @@ void Char_Console( int key ) {
Key_Message
====================
*/
-void Key_Message( int key ) {
- if( key == 'l' && Key_IsDown( K_CTRL ) ) {
- IF_Clear( &con.chatPrompt.inputLine );
+void Key_Message(int key)
+{
+ if (key == 'l' && Key_IsDown(K_CTRL)) {
+ IF_Clear(&con.chatPrompt.inputLine);
return;
}
- if( key == K_ENTER || key == K_KP_ENTER ) {
- char *cmd = Prompt_Action( &con.chatPrompt );
-
- if( cmd ) {
- Con_Say( cmd );
+ if (key == K_ENTER || key == K_KP_ENTER) {
+ char *cmd = Prompt_Action(&con.chatPrompt);
+
+ if (cmd) {
+ Con_Say(cmd);
}
- Key_SetDest( cls.key_dest & ~KEY_MESSAGE );
+ Key_SetDest(cls.key_dest & ~KEY_MESSAGE);
return;
}
- if( key == K_ESCAPE ) {
- Key_SetDest( cls.key_dest & ~KEY_MESSAGE );
- IF_Clear( &con.chatPrompt.inputLine );
+ if (key == K_ESCAPE) {
+ Key_SetDest(cls.key_dest & ~KEY_MESSAGE);
+ IF_Clear(&con.chatPrompt.inputLine);
return;
}
- if( key == 'r' && Key_IsDown( K_CTRL ) ) {
- Prompt_CompleteHistory( &con.chatPrompt, qfalse );
+ if (key == 'r' && Key_IsDown(K_CTRL)) {
+ Prompt_CompleteHistory(&con.chatPrompt, qfalse);
return;
}
- if( key == 's' && Key_IsDown( K_CTRL ) ) {
- Prompt_CompleteHistory( &con.chatPrompt, qtrue );
+ if (key == 's' && Key_IsDown(K_CTRL)) {
+ Prompt_CompleteHistory(&con.chatPrompt, qtrue);
return;
}
- if( key == K_UPARROW || ( key == 'p' && Key_IsDown( K_CTRL ) ) ) {
- Prompt_HistoryUp( &con.chatPrompt );
+ if (key == K_UPARROW || (key == 'p' && Key_IsDown(K_CTRL))) {
+ Prompt_HistoryUp(&con.chatPrompt);
return;
}
- if( key == K_DOWNARROW || ( key == 'n' && Key_IsDown( K_CTRL ) ) ) {
- Prompt_HistoryDown( &con.chatPrompt );
+ if (key == K_DOWNARROW || (key == 'n' && Key_IsDown(K_CTRL))) {
+ Prompt_HistoryDown(&con.chatPrompt);
return;
}
- if( IF_KeyEvent( &con.chatPrompt.inputLine, key ) ) {
- Prompt_ClearState( &con.chatPrompt );
+ if (IF_KeyEvent(&con.chatPrompt.inputLine, key)) {
+ Prompt_ClearState(&con.chatPrompt);
}
}
-void Char_Message( int key ) {
- IF_CharEvent( &con.chatPrompt.inputLine, key );
+void Char_Message(int key)
+{
+ IF_CharEvent(&con.chatPrompt.inputLine, key);
}
diff --git a/src/cl_demo.c b/src/cl_demo.c
index f53878e..82df171 100644
--- a/src/cl_demo.c
+++ b/src/cl_demo.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -40,47 +40,49 @@ Dumps the current demo message, prefixed by the length.
Stops demo recording and returns false on write error.
====================
*/
-qboolean CL_WriteDemoMessage( sizebuf_t *buf ) {
+qboolean CL_WriteDemoMessage(sizebuf_t *buf)
+{
uint32_t msglen;
ssize_t ret;
- if( buf->overflowed ) {
- SZ_Clear( buf );
- Com_WPrintf( "Demo message overflowed (should never happen).\n" );
+ if (buf->overflowed) {
+ SZ_Clear(buf);
+ Com_WPrintf("Demo message overflowed (should never happen).\n");
return qtrue;
}
- if( !buf->cursize )
+ if (!buf->cursize)
return qtrue;
- msglen = LittleLong( buf->cursize );
- ret = FS_Write( &msglen, 4, cls.demo.recording );
- if( ret != 4 )
+ msglen = LittleLong(buf->cursize);
+ ret = FS_Write(&msglen, 4, cls.demo.recording);
+ if (ret != 4)
goto fail;
- ret = FS_Write( buf->data, buf->cursize, cls.demo.recording );
- if( ret != buf->cursize )
+ ret = FS_Write(buf->data, buf->cursize, cls.demo.recording);
+ if (ret != buf->cursize)
goto fail;
- Com_DDPrintf( "%s: wrote %"PRIz" bytes\n", __func__, buf->cursize );
+ Com_DDPrintf("%s: wrote %"PRIz" bytes\n", __func__, buf->cursize);
- SZ_Clear( buf );
+ SZ_Clear(buf);
return qtrue;
fail:
- SZ_Clear( buf );
- Com_EPrintf( "Couldn't write demo: %s\n", Q_ErrorString( ret ) );
+ SZ_Clear(buf);
+ Com_EPrintf("Couldn't write demo: %s\n", Q_ErrorString(ret));
CL_Stop_f();
return qfalse;
}
// writes a delta update of an entity_state_t list to the message.
-static void emit_packet_entities( server_frame_t *from, server_frame_t *to ) {
+static void emit_packet_entities(server_frame_t *from, server_frame_t *to)
+{
entity_state_t *oldent, *newent;
int oldindex, newindex;
int oldnum, newnum;
int i, from_num_entities;
- if( !from )
+ if (!from)
from_num_entities = 0;
else
from_num_entities = from->numEntities;
@@ -88,88 +90,89 @@ static void emit_packet_entities( server_frame_t *from, server_frame_t *to ) {
newindex = 0;
oldindex = 0;
oldent = newent = 0;
- while( newindex < to->numEntities || oldindex < from_num_entities ) {
- if( newindex >= to->numEntities ) {
+ while (newindex < to->numEntities || oldindex < from_num_entities) {
+ if (newindex >= to->numEntities) {
newnum = 9999;
} else {
- i = ( to->firstEntity + newindex ) & PARSE_ENTITIES_MASK;
+ i = (to->firstEntity + newindex) & PARSE_ENTITIES_MASK;
newent = &cl.entityStates[i];
newnum = newent->number;
}
- if( oldindex >= from_num_entities ) {
+ if (oldindex >= from_num_entities) {
oldnum = 9999;
} else {
- i = ( from->firstEntity + oldindex ) & PARSE_ENTITIES_MASK;
+ i = (from->firstEntity + oldindex) & PARSE_ENTITIES_MASK;
oldent = &cl.entityStates[i];
oldnum = oldent->number;
}
- if( newnum == oldnum ) {
+ if (newnum == oldnum) {
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the entity has not changed at all
// note that players are always 'newentities' in compatibility mode,
// this updates their oldorigin always and prevents warping
- MSG_WriteDeltaEntity( oldent, newent,
- newent->number <= cl.maxclients ? MSG_ES_NEWENTITY : 0 );
+ MSG_WriteDeltaEntity(oldent, newent,
+ newent->number <= cl.maxclients ? MSG_ES_NEWENTITY : 0);
oldindex++;
newindex++;
continue;
}
- if( newnum < oldnum ) {
+ if (newnum < oldnum) {
// this is a new entity, send it from the baseline
- MSG_WriteDeltaEntity( &cl.baselines[newnum], newent,
- MSG_ES_FORCE|MSG_ES_NEWENTITY );
+ MSG_WriteDeltaEntity(&cl.baselines[newnum], newent,
+ MSG_ES_FORCE | MSG_ES_NEWENTITY);
newindex++;
continue;
}
- if( newnum > oldnum ) {
+ if (newnum > oldnum) {
// the old entity isn't present in the new message
- MSG_WriteDeltaEntity( oldent, NULL, MSG_ES_FORCE );
+ MSG_WriteDeltaEntity(oldent, NULL, MSG_ES_FORCE);
oldindex++;
continue;
}
}
- MSG_WriteShort( 0 ); // end of packetentities
+ MSG_WriteShort(0); // end of packetentities
}
-static void emit_delta_frame( server_frame_t *from, server_frame_t *to,
- int fromnum, int tonum )
+static void emit_delta_frame(server_frame_t *from, server_frame_t *to,
+ int fromnum, int tonum)
{
- MSG_WriteByte( svc_frame );
- MSG_WriteLong( tonum );
- MSG_WriteLong( fromnum ); // what we are delta'ing from
- MSG_WriteByte( 0 ); // rate dropped packets
+ MSG_WriteByte(svc_frame);
+ MSG_WriteLong(tonum);
+ MSG_WriteLong(fromnum); // what we are delta'ing from
+ MSG_WriteByte(0); // rate dropped packets
// send over the areabits
- MSG_WriteByte( to->areabytes );
- MSG_WriteData( to->areabits, to->areabytes );
+ MSG_WriteByte(to->areabytes);
+ MSG_WriteData(to->areabits, to->areabytes);
// delta encode the playerstate
- MSG_WriteByte( svc_playerinfo );
- MSG_WriteDeltaPlayerstate_Default( from ? &from->ps : NULL, &to->ps );
+ MSG_WriteByte(svc_playerinfo);
+ MSG_WriteDeltaPlayerstate_Default(from ? &from->ps : NULL, &to->ps);
// delta encode the entities
- MSG_WriteByte( svc_packetentities );
- emit_packet_entities( from, to );
+ MSG_WriteByte(svc_packetentities);
+ emit_packet_entities(from, to);
}
// the only place where last_frame is updated
-static void flush_demo_frame( void ) {
- if( cls.demo.buffer.cursize + msg_write.cursize > cls.demo.buffer.maxsize ) {
- Com_DPrintf( "Demo frame overflowed\n" );
+static void flush_demo_frame(void)
+{
+ if (cls.demo.buffer.cursize + msg_write.cursize > cls.demo.buffer.maxsize) {
+ Com_DPrintf("Demo frame overflowed\n");
cls.demo.frames_dropped++;
} else {
- SZ_Write( &cls.demo.buffer, msg_write.data, msg_write.cursize );
+ SZ_Write(&cls.demo.buffer, msg_write.data, msg_write.cursize);
cls.demo.last_frame = cl.frame.number;
cls.demo.frames_written++;
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
// frames_written counter starts at 0, but we add 1 to every frame number
@@ -184,13 +187,14 @@ CL_EmitDemoFrame
Writes delta from the last frame we got to the current frame.
====================
*/
-void CL_EmitDemoFrame( void ) {
+void CL_EmitDemoFrame(void)
+{
server_frame_t *oldframe;
player_state_t *oldstate;
int lastframe;
// the first frame is delta uncompressed
- if( FRAME_PRE == 0 ) {
+ if (FRAME_PRE == 0) {
oldframe = NULL;
oldstate = NULL;
lastframe = -1;
@@ -198,9 +202,8 @@ void CL_EmitDemoFrame( void ) {
oldframe = &cl.frames[cls.demo.last_frame & UPDATE_MASK];
oldstate = &oldframe->ps;
lastframe = FRAME_PRE;
- if( oldframe->number != cls.demo.last_frame || !oldframe->valid ||
- cl.numEntityStates - oldframe->firstEntity > MAX_PARSE_ENTITIES )
- {
+ if (oldframe->number != cls.demo.last_frame || !oldframe->valid ||
+ cl.numEntityStates - oldframe->firstEntity > MAX_PARSE_ENTITIES) {
oldframe = NULL;
oldstate = NULL;
lastframe = -1;
@@ -208,55 +211,57 @@ void CL_EmitDemoFrame( void ) {
}
// emit and flush frame
- emit_delta_frame( oldframe, &cl.frame, lastframe, FRAME_CUR );
+ emit_delta_frame(oldframe, &cl.frame, lastframe, FRAME_CUR);
flush_demo_frame();
}
-static void emit_zero_frame( void ) {
+static void emit_zero_frame(void)
+{
int lastframe;
// the first frame is delta uncompressed
- if( FRAME_PRE == 0 )
+ if (FRAME_PRE == 0)
lastframe = -1;
else
lastframe = FRAME_PRE;
- MSG_WriteByte( svc_frame );
- MSG_WriteLong( FRAME_CUR );
- MSG_WriteLong( lastframe ); // what we are delta'ing from
- MSG_WriteByte( 0 ); // rate dropped packets
+ MSG_WriteByte(svc_frame);
+ MSG_WriteLong(FRAME_CUR);
+ MSG_WriteLong(lastframe); // what we are delta'ing from
+ MSG_WriteByte(0); // rate dropped packets
// send over the areabits
- MSG_WriteByte( cl.frame.areabytes );
- MSG_WriteData( cl.frame.areabits, cl.frame.areabytes );
+ MSG_WriteByte(cl.frame.areabytes);
+ MSG_WriteData(cl.frame.areabits, cl.frame.areabytes);
- MSG_WriteByte( svc_playerinfo );
- MSG_WriteShort( 0 );
- MSG_WriteLong( 0 );
+ MSG_WriteByte(svc_playerinfo);
+ MSG_WriteShort(0);
+ MSG_WriteLong(0);
- MSG_WriteByte( svc_packetentities );
- MSG_WriteShort( 0 );
+ MSG_WriteByte(svc_packetentities);
+ MSG_WriteShort(0);
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (!CL_WriteDemoMessage(&msg_write))
return;
cls.demo.frames_written++;
}
-static size_t format_demo_status( char *buffer, size_t size ) {
- off_t pos = FS_Tell( cls.demo.recording );
- size_t len = Com_FormatSizeLong( buffer, size, pos );
+static size_t format_demo_status(char *buffer, size_t size)
+{
+ off_t pos = FS_Tell(cls.demo.recording);
+ size_t len = Com_FormatSizeLong(buffer, size, pos);
int min, sec, frames = cls.demo.frames_written;
sec = frames / 10; frames %= 10;
min = sec / 60; sec %= 60;
- len += Q_scnprintf( buffer + len, size - len, ", %d:%02d.%d",
- min, sec, frames );
+ len += Q_scnprintf(buffer + len, size - len, ", %d:%02d.%d",
+ min, sec, frames);
- if( cls.demo.frames_dropped || cls.demo.messages_dropped ) {
- len += Q_scnprintf( buffer + len, size - len, ", %d/%d dropped",
- cls.demo.frames_dropped, cls.demo.messages_dropped );
+ if (cls.demo.frames_dropped || cls.demo.messages_dropped) {
+ len += Q_scnprintf(buffer + len, size - len, ", %d/%d dropped",
+ cls.demo.frames_dropped, cls.demo.messages_dropped);
}
return len;
@@ -269,31 +274,32 @@ CL_Stop_f
stop recording a demo
====================
*/
-void CL_Stop_f( void ) {
+void CL_Stop_f(void)
+{
uint32_t msglen;
char buffer[MAX_QPATH];
- if( !cls.demo.recording ) {
- Com_Printf( "Not recording a demo.\n" );
+ if (!cls.demo.recording) {
+ Com_Printf("Not recording a demo.\n");
return;
}
- if( cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2) {
// tell the server we finished recording
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_RECORDING );
- MSG_WriteShort( 0 );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_RECORDING);
+ MSG_WriteShort(0);
+ MSG_FlushTo(&cls.netchan->message);
}
// finish up
- msglen = ( uint32_t )-1;
- FS_Write( &msglen, 4, cls.demo.recording );
+ msglen = (uint32_t)-1;
+ FS_Write(&msglen, 4, cls.demo.recording);
- format_demo_status( buffer, sizeof( buffer ) );
+ format_demo_status(buffer, sizeof(buffer));
// close demofile
- FS_FCloseFile( cls.demo.recording );
+ FS_FCloseFile(cls.demo.recording);
cls.demo.recording = 0;
cls.demo.paused = qfalse;
cls.demo.frames_written = 0;
@@ -301,7 +307,7 @@ void CL_Stop_f( void ) {
cls.demo.messages_dropped = 0;
// print some statistics
- Com_Printf( "Stopped demo (%s).\n", buffer );
+ Com_Printf("Stopped demo (%s).\n", buffer);
}
static const cmd_option_t o_record[] = {
@@ -321,7 +327,8 @@ record <demoname>
Begins recording a demo from the current position
====================
*/
-static void CL_Record_f( void ) {
+static void CL_Record_f(void)
+{
char buffer[MAX_OSPATH];
int i, c;
size_t len;
@@ -330,16 +337,16 @@ static void CL_Record_f( void ) {
qhandle_t f;
unsigned mode = FS_MODE_WRITE;
size_t size = Cvar_ClampInteger(
- cl_demomsglen,
- MIN_PACKETLEN,
- MAX_PACKETLEN_WRITABLE );
+ cl_demomsglen,
+ MIN_PACKETLEN,
+ MAX_PACKETLEN_WRITABLE);
- while( ( c = Cmd_ParseOptions( o_record ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_record)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_record, "<filename>" );
- Com_Printf( "Begin client demo recording.\n" );
- Cmd_PrintHelp( o_record );
+ Cmd_PrintUsage(o_record, "<filename>");
+ Com_Printf("Begin client demo recording.\n");
+ Cmd_PrintHelp(o_record);
return;
case 'z':
mode |= FS_FLAG_GZIP;
@@ -354,50 +361,50 @@ static void CL_Record_f( void ) {
}
}
- if( cls.demo.recording ) {
- format_demo_status( buffer, sizeof( buffer ) );
- Com_Printf( "Already recording (%s).\n", buffer );
+ if (cls.demo.recording) {
+ format_demo_status(buffer, sizeof(buffer));
+ Com_Printf("Already recording (%s).\n", buffer);
return;
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
- if( cls.state != ca_active ) {
- Com_Printf( "You must be in a level to record.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("You must be in a level to record.\n");
return;
}
//
// open the demo file
//
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode,
- "demos/", cmd_optarg, ".dm2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode,
+ "demos/", cmd_optarg, ".dm2");
+ if (!f) {
return;
}
- Com_Printf( "Recording client demo to %s.\n", buffer );
+ Com_Printf("Recording client demo to %s.\n", buffer);
cls.demo.recording = f;
cls.demo.paused = qfalse;
- SZ_Init( &cls.demo.buffer, demo_buffer, size );
+ SZ_Init(&cls.demo.buffer, demo_buffer, size);
demo_extra = 0;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
- if( cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2) {
// tell the server we are recording
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_RECORDING );
- MSG_WriteShort( 1 );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_RECORDING);
+ MSG_WriteShort(1);
+ MSG_FlushTo(&cls.netchan->message);
}
//
@@ -405,134 +412,137 @@ static void CL_Record_f( void ) {
//
// send the serverdata
- MSG_WriteByte( svc_serverdata );
- MSG_WriteLong( PROTOCOL_VERSION_DEFAULT );
- MSG_WriteLong( 0x10000 + cl.servercount );
- MSG_WriteByte( 1 ); // demos are always attract loops
- MSG_WriteString( cl.gamedir );
- MSG_WriteShort( cl.clientNum );
- MSG_WriteString( cl.configstrings[CS_NAME] );
+ MSG_WriteByte(svc_serverdata);
+ MSG_WriteLong(PROTOCOL_VERSION_DEFAULT);
+ MSG_WriteLong(0x10000 + cl.servercount);
+ MSG_WriteByte(1); // demos are always attract loops
+ MSG_WriteString(cl.gamedir);
+ MSG_WriteShort(cl.clientNum);
+ MSG_WriteString(cl.configstrings[CS_NAME]);
// configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
s = cl.configstrings[i];
- if( !*s )
+ if (!*s)
continue;
- len = strlen( s );
- if( len > MAX_QPATH )
+ len = strlen(s);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- if( msg_write.cursize + len + 4 > size ) {
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (msg_write.cursize + len + 4 > size) {
+ if (!CL_WriteDemoMessage(&msg_write))
return;
}
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( s, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(s, len);
+ MSG_WriteByte(0);
}
// baselines
- for( i = 1; i < MAX_EDICTS; i++ ) {
+ for (i = 1; i < MAX_EDICTS; i++) {
ent = &cl.baselines[i];
- if( !ent->number )
+ if (!ent->number)
continue;
- if( msg_write.cursize + 64 > size ) {
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (msg_write.cursize + 64 > size) {
+ if (!CL_WriteDemoMessage(&msg_write))
return;
}
- MSG_WriteByte( svc_spawnbaseline );
- MSG_WriteDeltaEntity( NULL, ent, MSG_ES_FORCE );
+ MSG_WriteByte(svc_spawnbaseline);
+ MSG_WriteDeltaEntity(NULL, ent, MSG_ES_FORCE);
}
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( "precache\n" );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString("precache\n");
// write it to the demo file
- CL_WriteDemoMessage( &msg_write );
+ CL_WriteDemoMessage(&msg_write);
// the rest of the demo file will be individual frames
}
// resumes demo recording after pause or seek. tries to fit flushed
// configstrings and frame into single packet for seamless 'stitch'
-static void resume_record( void ) {
+static void resume_record(void)
+{
int i, j, index;
size_t len;
char *s;
// write dirty configstrings
- for( i = 0; i < CS_BITMAP_LONGS; i++ ) {
- if( ((uint32_t *)cl.dcs)[i] == 0 )
+ for (i = 0; i < CS_BITMAP_LONGS; i++) {
+ if (((uint32_t *)cl.dcs)[i] == 0)
continue;
index = i << 5;
- for( j = 0; j < 32; j++, index++ ) {
- if( !Q_IsBitSet( cl.dcs, index ) )
+ for (j = 0; j < 32; j++, index++) {
+ if (!Q_IsBitSet(cl.dcs, index))
continue;
s = cl.configstrings[index];
- len = strlen( s );
- if( len > MAX_QPATH )
+ len = strlen(s);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- if( cls.demo.buffer.cursize + len + 4 > cls.demo.buffer.maxsize ) {
- if( !CL_WriteDemoMessage( &cls.demo.buffer ) )
+ if (cls.demo.buffer.cursize + len + 4 > cls.demo.buffer.maxsize) {
+ if (!CL_WriteDemoMessage(&cls.demo.buffer))
return;
// multiple packets = not seamless
}
- SZ_WriteByte( &cls.demo.buffer, svc_configstring );
- SZ_WriteShort( &cls.demo.buffer, index );
- SZ_Write( &cls.demo.buffer, s, len );
- SZ_WriteByte( &cls.demo.buffer, 0 );
+ SZ_WriteByte(&cls.demo.buffer, svc_configstring);
+ SZ_WriteShort(&cls.demo.buffer, index);
+ SZ_Write(&cls.demo.buffer, s, len);
+ SZ_WriteByte(&cls.demo.buffer, 0);
}
}
// emit and flush delta uncompressed frame
- if( cl.frame.valid ) {
- emit_delta_frame( NULL, &cl.frame, -1, FRAME_CUR );
+ if (cl.frame.valid) {
+ emit_delta_frame(NULL, &cl.frame, -1, FRAME_CUR);
flush_demo_frame();
}
// FIXME: write layout if it fits? most likely it won't
// write it to the demo file
- CL_WriteDemoMessage( &cls.demo.buffer );
+ CL_WriteDemoMessage(&cls.demo.buffer);
}
-static void CL_Suspend_f( void ) {
- if( !cls.demo.recording ) {
- Com_Printf( "Not recording a demo.\n" );
+static void CL_Suspend_f(void)
+{
+ if (!cls.demo.recording) {
+ Com_Printf("Not recording a demo.\n");
return;
}
- if( !cls.demo.paused ) {
- Com_Printf( "Suspended demo recording.\n" );
+ if (!cls.demo.paused) {
+ Com_Printf("Suspended demo recording.\n");
cls.demo.paused = qtrue;
return;
}
resume_record();
- if( !cls.demo.recording )
+ if (!cls.demo.recording)
// write failed
return;
- Com_Printf( "Resumed demo recording.\n" );
+ Com_Printf("Resumed demo recording.\n");
cls.demo.paused = qfalse;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
}
-static int read_first_message( qhandle_t f ) {
+static int read_first_message(qhandle_t f)
+{
uint32_t ul;
uint16_t us;
size_t msglen;
@@ -541,127 +551,131 @@ static int read_first_message( qhandle_t f ) {
int type;
// read magic/msglen
- read = FS_Read( &ul, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&ul, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
// check for gzip header
- if( CHECK_GZIP_HEADER( ul ) ) {
- ret = FS_FilterFile( f );
- if( ret ) {
+ if (CHECK_GZIP_HEADER(ul)) {
+ ret = FS_FilterFile(f);
+ if (ret) {
return ret;
}
- read = FS_Read( &ul, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&ul, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
}
// determine demo type
- if( ul == MVD_MAGIC ) {
- read = FS_Read( &us, 2, f );
- if( read != 2 ) {
+ if (ul == MVD_MAGIC) {
+ read = FS_Read(&us, 2, f);
+ if (read != 2) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
- if( !us ) {
+ if (!us) {
return Q_ERR_UNEXPECTED_EOF;
}
- msglen = LittleShort( us );
+ msglen = LittleShort(us);
type = 1;
} else {
- if( ul == ( uint32_t )-1 ) {
+ if (ul == (uint32_t)-1) {
return Q_ERR_UNEXPECTED_EOF;
}
- msglen = LittleLong( ul );
+ msglen = LittleLong(ul);
type = 0;
}
- if( msglen < 64 || msglen > sizeof( msg_read_buffer ) ) {
+ if (msglen < 64 || msglen > sizeof(msg_read_buffer)) {
return Q_ERR_INVALID_FORMAT;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
// read packet data
- read = FS_Read( msg_read.data, msglen, f );
- if( read != msglen ) {
+ read = FS_Read(msg_read.data, msglen, f);
+ if (read != msglen) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
return type;
}
-static int read_next_message( qhandle_t f ) {
+static int read_next_message(qhandle_t f)
+{
uint32_t msglen;
ssize_t read;
// read msglen
- read = FS_Read( &msglen, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&msglen, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
// check for EOF packet
- if( msglen == ( uint32_t )-1 ) {
+ if (msglen == (uint32_t)-1) {
return 0;
}
- msglen = LittleLong( msglen );
- if( msglen > sizeof( msg_read_buffer ) ) {
+ msglen = LittleLong(msglen);
+ if (msglen > sizeof(msg_read_buffer)) {
return Q_ERR_INVALID_FORMAT;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
// read packet data
- read = FS_Read( msg_read.data, msglen, f );
- if( read != msglen ) {
+ read = FS_Read(msg_read.data, msglen, f);
+ if (read != msglen) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
return 1;
}
-static void finish_demo( int ret ) {
- char *s = Cvar_VariableString( "nextserver" );
+static void finish_demo(int ret)
+{
+ char *s = Cvar_VariableString("nextserver");
- if( !s[0] ) {
- if( ret == 0 ) {
- Com_Error( ERR_DISCONNECT, "Demo finished" );
+ if (!s[0]) {
+ if (ret == 0) {
+ Com_Error(ERR_DISCONNECT, "Demo finished");
} else {
- Com_Error( ERR_DROP, "Couldn't read demo: %s", Q_ErrorString( ret ) );
+ Com_Error(ERR_DROP, "Couldn't read demo: %s", Q_ErrorString(ret));
}
}
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
- Cvar_Set( "nextserver", "" );
+ Cvar_Set("nextserver", "");
- Cbuf_AddText( &cmd_buffer, s );
- Cbuf_AddText( &cmd_buffer, "\n" );
- Cbuf_Execute( &cmd_buffer );
+ Cbuf_AddText(&cmd_buffer, s);
+ Cbuf_AddText(&cmd_buffer, "\n");
+ Cbuf_Execute(&cmd_buffer);
}
-static void update_status( void ) {
- if( cls.demo.file_size ) {
- off_t pos = FS_Tell( cls.demo.playback );
+static void update_status(void)
+{
+ if (cls.demo.file_size) {
+ off_t pos = FS_Tell(cls.demo.playback);
- if( pos > cls.demo.file_offset )
- cls.demo.file_percent = ( pos - cls.demo.file_offset ) * 100 / cls.demo.file_size;
+ if (pos > cls.demo.file_offset)
+ cls.demo.file_percent = (pos - cls.demo.file_offset) * 100 / cls.demo.file_size;
else
cls.demo.file_percent = 0;
}
}
-static void parse_next_message( void ) {
+static void parse_next_message(void)
+{
int ret;
- ret = read_next_message( cls.demo.playback );
- if( ret <= 0 ) {
- finish_demo( ret );
+ ret = read_next_message(cls.demo.playback);
+ if (ret <= 0) {
+ finish_demo(ret);
return;
}
@@ -675,62 +689,64 @@ static void parse_next_message( void ) {
CL_PlayDemo_f
====================
*/
-static void CL_PlayDemo_f( void ) {
+static void CL_PlayDemo_f(void)
+{
char name[MAX_OSPATH];
qhandle_t f;
int type;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- f = FS_EasyOpenFile( name, sizeof( name ), FS_MODE_READ,
- "demos/", Cmd_Argv( 1 ), ".dm2" );
- if( !f ) {
+ f = FS_EasyOpenFile(name, sizeof(name), FS_MODE_READ,
+ "demos/", Cmd_Argv(1), ".dm2");
+ if (!f) {
return;
}
- type = read_first_message( f );
- if( type < 0 ) {
- Com_Printf( "Couldn't read %s: %s\n", name, Q_ErrorString( type ) );
- FS_FCloseFile( f );
+ type = read_first_message(f);
+ if (type < 0) {
+ Com_Printf("Couldn't read %s: %s\n", name, Q_ErrorString(type));
+ FS_FCloseFile(f);
return;
}
- if( type == 1 ) {
+ if (type == 1) {
#if USE_MVD_CLIENT
- Cbuf_InsertText( &cmd_buffer, va( "mvdplay --replace @@ \"/%s\"\n", name ) );
+ Cbuf_InsertText(&cmd_buffer, va("mvdplay --replace @@ \"/%s\"\n", name));
#else
- Com_Printf( "MVD support was not compiled in.\n" );
+ Com_Printf("MVD support was not compiled in.\n");
#endif
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return;
}
// if running a local server, kill it and reissue
- SV_Shutdown( "Server was killed.\n", ERR_DISCONNECT );
+ SV_Shutdown("Server was killed.\n", ERR_DISCONNECT);
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
cls.demo.playback = f;
cls.state = ca_connected;
- Q_strlcpy( cls.servername, COM_SkipPath( name ), sizeof( cls.servername ) );
+ Q_strlcpy(cls.servername, COM_SkipPath(name), sizeof(cls.servername));
cls.serverAddress.type = NA_LOOPBACK;
Con_Popup();
SCR_UpdateScreen();
CL_ParseServerMessage();
- while( cls.state == ca_connected ) {
- Cbuf_Execute( &cl_cmdbuf );
+ while (cls.state == ca_connected) {
+ Cbuf_Execute(&cl_cmdbuf);
parse_next_message();
}
}
-static void CL_Demo_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- FS_File_g( "demos", "*.dm2;*.dm2.gz;*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx );
+static void CL_Demo_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ FS_File_g("demos", "*.dm2;*.dm2.gz;*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx);
}
}
@@ -750,7 +766,8 @@ Periodically builds a fake demo packet used to reconstruct delta compression
state, configstrings and layouts at the given server frame.
====================
*/
-void CL_EmitDemoSnapshot( void ) {
+void CL_EmitDemoSnapshot(void)
+{
demosnap_t *snap;
off_t pos;
char *from, *to;
@@ -758,86 +775,86 @@ void CL_EmitDemoSnapshot( void ) {
server_frame_t *lastframe, *frame;
int i, j, lastnum;
- if( cl_demosnaps->integer <= 0 )
+ if (cl_demosnaps->integer <= 0)
return;
- if( cls.demo.frames_read < cls.demo.last_snapshot + cl_demosnaps->integer * 10 )
+ if (cls.demo.frames_read < cls.demo.last_snapshot + cl_demosnaps->integer * 10)
return;
- if( !cl.frame.valid )
+ if (!cl.frame.valid)
return;
- if( !cls.demo.file_size )
+ if (!cls.demo.file_size)
return;
- pos = FS_Tell( cls.demo.playback );
- if( pos < cls.demo.file_offset )
+ pos = FS_Tell(cls.demo.playback);
+ if (pos < cls.demo.file_offset)
return;
// write all the backups, since we can't predict what frame the next
// delta will come from
lastframe = NULL;
lastnum = -1;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
- j = cl.frame.number - ( UPDATE_BACKUP - 1 ) + i;
+ for (i = 0; i < UPDATE_BACKUP; i++) {
+ j = cl.frame.number - (UPDATE_BACKUP - 1) + i;
frame = &cl.frames[j & UPDATE_MASK];
- if( frame->number != j || !frame->valid ||
- cl.numEntityStates - frame->firstEntity > MAX_PARSE_ENTITIES )
- {
+ if (frame->number != j || !frame->valid ||
+ cl.numEntityStates - frame->firstEntity > MAX_PARSE_ENTITIES) {
continue;
}
- emit_delta_frame( lastframe, frame, lastnum, j );
+ emit_delta_frame(lastframe, frame, lastnum, j);
lastframe = frame;
lastnum = frame->number;
}
// write configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = cl.baseconfigstrings[i];
to = cl.configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- len = strlen( to );
- if( len > MAX_QPATH )
+ len = strlen(to);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( to, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(to, len);
+ MSG_WriteByte(0);
}
// write layout
- MSG_WriteByte( svc_layout );
- MSG_WriteString( cl.layout );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteString(cl.layout);
- snap = Z_Malloc( sizeof( *snap ) + msg_write.cursize - 1 );
+ snap = Z_Malloc(sizeof(*snap) + msg_write.cursize - 1);
snap->framenum = cls.demo.frames_read;
snap->filepos = pos;
snap->msglen = msg_write.cursize;
- memcpy( snap->data, msg_write.data, msg_write.cursize );
- List_Append( &cls.demo.snapshots, &snap->entry );
+ memcpy(snap->data, msg_write.data, msg_write.cursize);
+ List_Append(&cls.demo.snapshots, &snap->entry);
- Com_DPrintf( "[%d] snaplen %"PRIz"\n", cls.demo.frames_read, msg_write.cursize );
+ Com_DPrintf("[%d] snaplen %"PRIz"\n", cls.demo.frames_read, msg_write.cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
cls.demo.last_snapshot = cls.demo.frames_read;
}
-static demosnap_t *find_snapshot( int framenum ) {
+static demosnap_t *find_snapshot(int framenum)
+{
demosnap_t *snap, *prev;
- if( LIST_EMPTY( &cls.demo.snapshots ) )
+ if (LIST_EMPTY(&cls.demo.snapshots))
return NULL;
- prev = LIST_FIRST( demosnap_t, &cls.demo.snapshots, entry );
+ prev = LIST_FIRST(demosnap_t, &cls.demo.snapshots, entry);
- LIST_FOR_EACH( demosnap_t, snap, &cls.demo.snapshots, entry ) {
- if( snap->framenum > framenum )
+ LIST_FOR_EACH(demosnap_t, snap, &cls.demo.snapshots, entry) {
+ if (snap->framenum > framenum)
break;
prev = snap;
}
@@ -852,24 +869,25 @@ CL_FirstDemoFrame
Called after the first valid frame is parsed from the demo.
====================
*/
-void CL_FirstDemoFrame( void ) {
+void CL_FirstDemoFrame(void)
+{
ssize_t len, ofs;
- Com_DPrintf( "[%d] first frame\n", cl.frame.number );
+ Com_DPrintf("[%d] first frame\n", cl.frame.number);
// save base configstrings
- memcpy( cl.baseconfigstrings, cl.configstrings, sizeof( cl.baseconfigstrings ) );
+ memcpy(cl.baseconfigstrings, cl.configstrings, sizeof(cl.baseconfigstrings));
// obtain file length and offset of the second frame
- len = FS_Length( cls.demo.playback );
- ofs = FS_Tell( cls.demo.playback );
- if( len > 0 && ofs > 0 ) {
+ len = FS_Length(cls.demo.playback);
+ ofs = FS_Tell(cls.demo.playback);
+ if (len > 0 && ofs > 0) {
cls.demo.file_offset = ofs;
cls.demo.file_size = len - ofs;
}
// begin timedemo
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
cls.demo.time_frames = 0;
cls.demo.time_start = Sys_Milliseconds();
}
@@ -878,49 +896,50 @@ void CL_FirstDemoFrame( void ) {
cls.demo.last_snapshot = INT_MIN;
}
-static void CL_Seek_f( void ) {
+static void CL_Seek_f(void)
+{
demosnap_t *snap;
int i, j, ret, index, frames, dest, prev;
char *from, *to;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s [+-]<timespec>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s [+-]<timespec>\n", Cmd_Argv(0));
return;
}
#if USE_MVD_CLIENT
- if( sv_running->integer == ss_broadcast ) {
- Cbuf_InsertText( &cmd_buffer, va( "mvdseek \"%s\" @@\n", Cmd_Argv( 1 ) ) );
+ if (sv_running->integer == ss_broadcast) {
+ Cbuf_InsertText(&cmd_buffer, va("mvdseek \"%s\" @@\n", Cmd_Argv(1)));
return;
}
#endif
- if( !cls.demo.playback ) {
- Com_Printf( "Not playing a demo.\n" );
+ if (!cls.demo.playback) {
+ Com_Printf("Not playing a demo.\n");
return;
}
- to = Cmd_Argv( 1 );
+ to = Cmd_Argv(1);
- if( *to == '-' || *to == '+' ) {
+ if (*to == '-' || *to == '+') {
// relative to current frame
- if( !Com_ParseTimespec( to + 1, &frames ) ) {
- Com_Printf( "Invalid relative timespec.\n" );
+ if (!Com_ParseTimespec(to + 1, &frames)) {
+ Com_Printf("Invalid relative timespec.\n");
return;
}
- if( *to == '-' )
+ if (*to == '-')
frames = -frames;
dest = cls.demo.frames_read + frames;
} else {
// relative to first frame
- if( !Com_ParseTimespec( to, &dest ) ) {
- Com_Printf( "Invalid absolute timespec.\n" );
+ if (!Com_ParseTimespec(to, &dest)) {
+ Com_Printf("Invalid absolute timespec.\n");
return;
}
frames = dest - cls.demo.frames_read;
}
- if( !frames )
+ if (!frames)
// already there
return;
@@ -928,7 +947,7 @@ static void CL_Seek_f( void ) {
cls.demo.seeking = qtrue;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
// stop sounds
S_StopAllSounds();
@@ -936,49 +955,49 @@ static void CL_Seek_f( void ) {
// save previous server frame number
prev = cl.frame.number;
- Com_DPrintf( "[%d] seeking to %d\n", cls.demo.frames_read, dest );
+ Com_DPrintf("[%d] seeking to %d\n", cls.demo.frames_read, dest);
// seek to the previous most recent snapshot
- if( frames < 0 || cls.demo.last_snapshot > cls.demo.frames_read ) {
- snap = find_snapshot( dest );
-
- if( snap ) {
- Com_DPrintf( "found snap at %d\n", snap->framenum );
- ret = FS_Seek( cls.demo.playback, snap->filepos );
- if( ret < 0 ) {
- Com_EPrintf( "Couldn't seek demo: %s\n", Q_ErrorString( ret ) );
+ if (frames < 0 || cls.demo.last_snapshot > cls.demo.frames_read) {
+ snap = find_snapshot(dest);
+
+ if (snap) {
+ Com_DPrintf("found snap at %d\n", snap->framenum);
+ ret = FS_Seek(cls.demo.playback, snap->filepos);
+ if (ret < 0) {
+ Com_EPrintf("Couldn't seek demo: %s\n", Q_ErrorString(ret));
goto done;
}
// reset configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = cl.baseconfigstrings[i];
to = cl.configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- Q_SetBit( cl.dcs, i );
- strcpy( to, from );
+ Q_SetBit(cl.dcs, i);
+ strcpy(to, from);
}
- SZ_Init( &msg_read, snap->data, snap->msglen );
+ SZ_Init(&msg_read, snap->data, snap->msglen);
msg_read.cursize = snap->msglen;
CL_SeekDemoMessage();
cls.demo.frames_read = snap->framenum;
- Com_DPrintf( "[%d] after snap parse %d\n", cls.demo.frames_read, cl.frame.number );
- } else if( frames < 0 ) {
- Com_Printf( "Couldn't seek backwards without snapshots!\n" );
+ Com_DPrintf("[%d] after snap parse %d\n", cls.demo.frames_read, cl.frame.number);
+ } else if (frames < 0) {
+ Com_Printf("Couldn't seek backwards without snapshots!\n");
goto done;
}
}
// skip forward to destination frame
- while( cls.demo.frames_read < dest ) {
- ret = read_next_message( cls.demo.playback );
- if( ret <= 0 ) {
- finish_demo( ret );
+ while (cls.demo.frames_read < dest) {
+ ret = read_next_message(cls.demo.playback);
+ if (ret <= 0) {
+ finish_demo(ret);
return;
}
@@ -986,24 +1005,24 @@ static void CL_Seek_f( void ) {
CL_EmitDemoSnapshot();
}
- Com_DPrintf( "[%d] after skip %d\n", cls.demo.frames_read, cl.frame.number );
+ Com_DPrintf("[%d] after skip %d\n", cls.demo.frames_read, cl.frame.number);
// update dirty configstrings
- for( i = 0; i < CS_BITMAP_LONGS; i++ ) {
- if( ((uint32_t *)cl.dcs)[i] == 0 )
+ for (i = 0; i < CS_BITMAP_LONGS; i++) {
+ if (((uint32_t *)cl.dcs)[i] == 0)
continue;
index = i << 5;
- for( j = 0; j < 32; j++, index++ ) {
- if( Q_IsBitSet( cl.dcs, index ) )
- CL_UpdateConfigstring( index );
+ for (j = 0; j < 32; j++, index++) {
+ if (Q_IsBitSet(cl.dcs, index))
+ CL_UpdateConfigstring(index);
}
}
// don't lerp to old
- memset( &cl.oldframe, 0, sizeof( cl.oldframe ) );
+ memset(&cl.oldframe, 0, sizeof(cl.oldframe));
#if USE_FPS
- memset( &cl.oldkeyframe, 0, sizeof( cl.oldkeyframe ) );
+ memset(&cl.oldkeyframe, 0, sizeof(cl.oldkeyframe));
#endif
// clear old effects
@@ -1016,7 +1035,7 @@ static void CL_Seek_f( void ) {
// fire up destination frame
CL_DeltaFrame();
- if( cls.demo.recording && !cls.demo.paused )
+ if (cls.demo.recording && !cls.demo.paused)
resume_record();
update_status();
@@ -1027,23 +1046,24 @@ done:
cls.demo.seeking = qfalse;
}
-static void parse_info_string( demoInfo_t *info, int clientNum, int index, const char *string ) {
+static void parse_info_string(demoInfo_t *info, int clientNum, int index, const char *string)
+{
size_t len;
char *p;
- if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS ) {
- if( index - CS_PLAYERSKINS == clientNum ) {
- Q_strlcpy( info->pov, string, sizeof( info->pov ) );
- p = strchr( info->pov, '\\' );
- if( p ) {
+ if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS) {
+ if (index - CS_PLAYERSKINS == clientNum) {
+ Q_strlcpy(info->pov, string, sizeof(info->pov));
+ p = strchr(info->pov, '\\');
+ if (p) {
*p = 0;
}
}
- } else if( index == CS_MODELS + 1 ) {
- len = strlen( string );
- if( len > 9 ) {
- memcpy( info->map, string + 5, len - 9 ); // skip "maps/"
- info->map[ len - 9 ] = 0; // cut off ".bsp"
+ } else if (index == CS_MODELS + 1) {
+ len = strlen(string);
+ if (len > 9) {
+ memcpy(info->map, string + 5, len - 9); // skip "maps/"
+ info->map[len - 9] = 0; // cut off ".bsp"
}
}
}
@@ -1053,126 +1073,128 @@ static void parse_info_string( demoInfo_t *info, int clientNum, int index, const
CL_GetDemoInfo
====================
*/
-demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
+demoInfo_t *CL_GetDemoInfo(const char *path, demoInfo_t *info)
+{
qhandle_t f;
int c, index;
char string[MAX_QPATH];
int clientNum, type;
- FS_FOpenFile( path, &f, FS_MODE_READ );
- if( !f ) {
+ FS_FOpenFile(path, &f, FS_MODE_READ);
+ if (!f) {
return NULL;
}
- type = read_first_message( f );
- if( type < 0 ) {
+ type = read_first_message(f);
+ if (type < 0) {
goto fail;
}
- if( type == 0 ) {
- if( MSG_ReadByte() != svc_serverdata ) {
+ if (type == 0) {
+ if (MSG_ReadByte() != svc_serverdata) {
goto fail;
}
- if( MSG_ReadLong() != PROTOCOL_VERSION_DEFAULT ) {
+ if (MSG_ReadLong() != PROTOCOL_VERSION_DEFAULT) {
goto fail;
}
MSG_ReadLong();
MSG_ReadByte();
- MSG_ReadString( NULL, 0);
+ MSG_ReadString(NULL, 0);
clientNum = MSG_ReadShort();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
- while( 1 ) {
+ while (1) {
c = MSG_ReadByte();
- if( c == -1 ) {
- if( read_next_message( f ) <= 0 ) {
+ if (c == -1) {
+ if (read_next_message(f) <= 0) {
break;
}
continue; // parse new message
}
- if( c != svc_configstring ) {
+ if (c != svc_configstring) {
break;
}
index = MSG_ReadShort();
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
goto fail;
}
- MSG_ReadString( string, sizeof( string ) );
- parse_info_string( info, clientNum, index, string );
+ MSG_ReadString(string, sizeof(string));
+ parse_info_string(info, clientNum, index, string);
}
info->mvd = qfalse;
} else {
- if( ( MSG_ReadByte() & SVCMD_MASK ) != mvd_serverdata ) {
+ if ((MSG_ReadByte() & SVCMD_MASK) != mvd_serverdata) {
goto fail;
}
- if( MSG_ReadLong() != PROTOCOL_VERSION_MVD ) {
+ if (MSG_ReadLong() != PROTOCOL_VERSION_MVD) {
goto fail;
}
MSG_ReadShort();
MSG_ReadLong();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
clientNum = MSG_ReadShort();
- while( 1 ) {
+ while (1) {
index = MSG_ReadShort();
- if( index == MAX_CONFIGSTRINGS ) {
+ if (index == MAX_CONFIGSTRINGS) {
break;
}
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
goto fail;
}
- MSG_ReadString( string, sizeof( string ) );
- parse_info_string( info, clientNum, index, string );
+ MSG_ReadString(string, sizeof(string));
+ parse_info_string(info, clientNum, index, string);
}
info->mvd = qtrue;
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return info;
fail:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return NULL;
}
// =========================================================================
-void CL_CleanupDemos( void ) {
+void CL_CleanupDemos(void)
+{
demosnap_t *snap, *next;
size_t total;
- if( cls.demo.recording ) {
+ if (cls.demo.recording) {
CL_Stop_f();
}
- if( cls.demo.playback ) {
- FS_FCloseFile( cls.demo.playback );
+ if (cls.demo.playback) {
+ FS_FCloseFile(cls.demo.playback);
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
unsigned msec = Sys_Milliseconds();
- float sec = ( msec - cls.demo.time_start ) * 0.001f;
+ float sec = (msec - cls.demo.time_start) * 0.001f;
float fps = cls.demo.time_frames / sec;
- Com_Printf( "%u frames, %3.1f seconds: %3.1f fps\n",
- cls.demo.time_frames, sec, fps );
+ Com_Printf("%u frames, %3.1f seconds: %3.1f fps\n",
+ cls.demo.time_frames, sec, fps);
}
}
total = 0;
- LIST_FOR_EACH_SAFE( demosnap_t, snap, next, &cls.demo.snapshots, entry ) {
+ LIST_FOR_EACH_SAFE(demosnap_t, snap, next, &cls.demo.snapshots, entry) {
total += snap->msglen;
- Z_Free( snap );
+ Z_Free(snap);
}
- if( total )
- Com_DPrintf( "Freed %"PRIz" bytes of snaps\n", total );
+ if (total)
+ Com_DPrintf("Freed %"PRIz" bytes of snaps\n", total);
- memset( &cls.demo, 0, sizeof( cls.demo ) );
+ memset(&cls.demo, 0, sizeof(cls.demo));
- List_Init( &cls.demo.snapshots );
+ List_Init(&cls.demo.snapshots);
}
/*
@@ -1180,29 +1202,29 @@ void CL_CleanupDemos( void ) {
CL_DemoFrame
====================
*/
-void CL_DemoFrame( int msec ) {
- if( cls.state < ca_connected ) {
+void CL_DemoFrame(int msec)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
parse_next_message();
return;
}
- if( cls.demo.recording && cl_paused->integer == 2 &&
- !cls.demo.paused && cls.demo.frames_written )
- {
+ if (cls.demo.recording && cl_paused->integer == 2 &&
+ !cls.demo.paused && cls.demo.frames_written) {
// XXX: record zero frames when manually paused
// for syncing with audio comments, etc
demo_extra += msec;
- if( demo_extra > 100 ) {
+ if (demo_extra > 100) {
emit_zero_frame();
demo_extra = 0;
}
}
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
parse_next_message();
cl.time = cl.servertime;
cls.demo.time_frames++;
@@ -1211,9 +1233,9 @@ void CL_DemoFrame( int msec ) {
// cl.time has already been advanced for this client frame
// read the next frame to start lerp cycle again
- while( cl.servertime < cl.time ) {
+ while (cl.servertime < cl.time) {
parse_next_message();
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
break;
}
}
@@ -1234,12 +1256,13 @@ static const cmdreg_t c_demo[] = {
CL_InitDemos
====================
*/
-void CL_InitDemos( void ) {
- cl_demosnaps = Cvar_Get( "cl_demosnaps", "10", 0 );
- cl_demomsglen = Cvar_Get( "cl_demomsglen", va( "%d", MAX_PACKETLEN_WRITABLE_DEFAULT ), 0 );
+void CL_InitDemos(void)
+{
+ cl_demosnaps = Cvar_Get("cl_demosnaps", "10", 0);
+ cl_demomsglen = Cvar_Get("cl_demomsglen", va("%d", MAX_PACKETLEN_WRITABLE_DEFAULT), 0);
- Cmd_Register( c_demo );
- List_Init( &cls.demo.snapshots );
+ Cmd_Register(c_demo);
+ List_Init(&cls.demo.snapshots);
}
diff --git a/src/cl_download.c b/src/cl_download.c
index 1763fd2..a5c4c7f 100644
--- a/src/cl_download.c
+++ b/src/cl_download.c
@@ -46,25 +46,26 @@ Entry will stay in queue for entire lifetime of server connection,
to make sure each path is tried exactly once.
===============
*/
-qerror_t CL_QueueDownload( const char *path, dltype_t type ) {
+qerror_t CL_QueueDownload(const char *path, dltype_t type)
+{
dlqueue_t *q;
size_t len;
- FOR_EACH_DLQ( q ) {
+ FOR_EACH_DLQ(q) {
// avoid sending duplicate requests
- if( !FS_pathcmp( path, q->path ) ) {
- Com_DPrintf( "%s: %s [DUP]\n", __func__, path );
+ if (!FS_pathcmp(path, q->path)) {
+ Com_DPrintf("%s: %s [DUP]\n", __func__, path);
return Q_ERR_EXIST;
}
}
- len = strlen( path );
- if( len >= MAX_QPATH ) {
- Com_Error( ERR_DROP, "%s: oversize quake path", __func__ );
+ len = strlen(path);
+ if (len >= MAX_QPATH) {
+ Com_Error(ERR_DROP, "%s: oversize quake path", __func__);
}
- q = Z_Malloc( sizeof( *q ) + len );
- memcpy( q->path, path, len + 1 );
+ q = Z_Malloc(sizeof(*q) + len);
+ memcpy(q->path, path, len + 1);
q->type = type;
q->state = DL_PENDING;
@@ -72,14 +73,14 @@ qerror_t CL_QueueDownload( const char *path, dltype_t type ) {
// paks get bumped to the top and HTTP switches to single downloading.
// this prevents someone on 28k dialup trying to do both the main .pak
// and referenced configstrings data at once.
- if( type == DL_PAK )
- List_Insert( &cls.download.queue, &q->entry );
+ if (type == DL_PAK)
+ List_Insert(&cls.download.queue, &q->entry);
else
#endif
- List_Append( &cls.download.queue, &q->entry );
+ List_Append(&cls.download.queue, &q->entry);
cls.download.pending++;
- Com_DPrintf( "%s: %s [%d]\n", __func__, path, cls.download.pending );
+ Com_DPrintf("%s: %s [%d]\n", __func__, path, cls.download.pending);
return Q_ERR_SUCCESS;
}
@@ -90,17 +91,18 @@ CL_FinishDownload
Mark the queue entry as done, decrementing pending count.
===============
*/
-void CL_FinishDownload( dlqueue_t *q ) {
- if( q->state == DL_DONE ) {
- Com_Error( ERR_DROP, "%s: already done", __func__ );
+void CL_FinishDownload(dlqueue_t *q)
+{
+ if (q->state == DL_DONE) {
+ Com_Error(ERR_DROP, "%s: already done", __func__);
}
- if( !cls.download.pending ) {
- Com_Error( ERR_DROP, "%s: bad pending count", __func__ );
+ if (!cls.download.pending) {
+ Com_Error(ERR_DROP, "%s: bad pending count", __func__);
}
q->state = DL_DONE;
cls.download.pending--;
- Com_DPrintf( "%s: %s [%d]\n", __func__, q->path, cls.download.pending );
+ Com_DPrintf("%s: %s [%d]\n", __func__, q->path, cls.download.pending);
}
/*
@@ -110,25 +112,26 @@ CL_CleanupDownloads
Disconnected from server, clean up.
===============
*/
-void CL_CleanupDownloads( void ) {
+void CL_CleanupDownloads(void)
+{
dlqueue_t *q, *n;
#if USE_CURL
HTTP_CleanupDownloads();
#endif
- FOR_EACH_DLQ_SAFE( q, n ) {
- Z_Free( q );
+ FOR_EACH_DLQ_SAFE(q, n) {
+ Z_Free(q);
}
- List_Init( &cls.download.queue );
+ List_Init(&cls.download.queue);
cls.download.pending = 0;
cls.download.current = NULL;
cls.download.percent = 0;
- if( cls.download.file ) {
- FS_FCloseFile( cls.download.file );
+ if (cls.download.file) {
+ FS_FCloseFile(cls.download.file);
cls.download.file = 0;
}
@@ -136,38 +139,39 @@ void CL_CleanupDownloads( void ) {
}
// start legacy UDP download
-static qboolean start_download( dlqueue_t *q ) {
+static qboolean start_download(dlqueue_t *q)
+{
size_t len;
qhandle_t f;
ssize_t ret;
- len = strlen( q->path );
- if( len >= MAX_QPATH ) {
- Com_Error( ERR_DROP, "%s: oversize quake path", __func__ );
+ len = strlen(q->path);
+ if (len >= MAX_QPATH) {
+ Com_Error(ERR_DROP, "%s: oversize quake path", __func__);
}
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
- memcpy( cls.download.temp, q->path, len );
- memcpy( cls.download.temp + len, ".tmp", 5 );
+ memcpy(cls.download.temp, q->path, len);
+ memcpy(cls.download.temp + len, ".tmp", 5);
//ZOID
// check to see if we already have a tmp for this file, if so, try to resume
// open the file if not opened yet
- ret = FS_FOpenFile( cls.download.temp, &f, FS_MODE_RDWR );
- if( ret >= 0 ) { // it exists
+ ret = FS_FOpenFile(cls.download.temp, &f, FS_MODE_RDWR);
+ if (ret >= 0) { // it exists
cls.download.file = f;
// give the server an offset to start the download
- Com_DPrintf( "[UDP] Resuming %s\n", q->path );
- CL_ClientCommand( va( "download \"%s\" %d", q->path, (int)ret ) );
- } else if( ret == Q_ERR_NOENT ) { // it doesn't exist
- Com_DPrintf( "[UDP] Downloading %s\n", q->path );
- CL_ClientCommand( va( "download \"%s\"", q->path ) );
+ Com_DPrintf("[UDP] Resuming %s\n", q->path);
+ CL_ClientCommand(va("download \"%s\" %d", q->path, (int)ret));
+ } else if (ret == Q_ERR_NOENT) { // it doesn't exist
+ Com_DPrintf("[UDP] Downloading %s\n", q->path);
+ CL_ClientCommand(va("download \"%s\"", q->path));
} else { // error happened
- Com_EPrintf( "[UDP] Couldn't open %s for appending: %s\n",
- cls.download.temp, Q_ErrorString( ret ) );
- CL_FinishDownload( q );
+ Com_EPrintf("[UDP] Couldn't open %s for appending: %s\n",
+ cls.download.temp, Q_ErrorString(ret));
+ CL_FinishDownload(q);
return qfalse;
}
@@ -183,16 +187,17 @@ CL_StartNextDownload
Start another UDP download if possible
===============
*/
-void CL_StartNextDownload( void ) {
+void CL_StartNextDownload(void)
+{
dlqueue_t *q;
- if( !cls.download.pending || cls.download.current ) {
+ if (!cls.download.pending || cls.download.current) {
return;
}
- FOR_EACH_DLQ( q ) {
- if( q->state == DL_PENDING ) {
- if( start_download( q ) ) {
+ FOR_EACH_DLQ(q) {
+ if (q->state == DL_PENDING) {
+ if (start_download(q)) {
break;
}
}
@@ -206,75 +211,76 @@ CL_HandleDownload
A download data has been received from the server
=====================
*/
-void CL_HandleDownload( const byte *data, int size, int percent ) {
+void CL_HandleDownload(const byte *data, int size, int percent)
+{
dlqueue_t *q = cls.download.current;
const char *msg = NULL;
qerror_t ret;
- if( !q ) {
- Com_Error( ERR_DROP, "%s: no download requested", __func__ );
+ if (!q) {
+ Com_Error(ERR_DROP, "%s: no download requested", __func__);
}
- if( size == -1 ) {
- if( !percent ) {
+ if (size == -1) {
+ if (!percent) {
msg = "FAIL";
} else {
msg = "STOP";
}
- if( cls.download.file ) {
+ if (cls.download.file) {
// if here, we tried to resume a file but the server said no
- FS_FCloseFile( cls.download.file );
+ FS_FCloseFile(cls.download.file);
}
goto another;
}
// open the file if not opened yet
- if( !cls.download.file ) {
- ret = FS_FOpenFile( cls.download.temp, &cls.download.file, FS_MODE_WRITE );
- if( !cls.download.file ) {
- Com_EPrintf( "[UDP] Couldn't open %s for writing: %s\n",
- cls.download.temp, Q_ErrorString( ret ) );
+ if (!cls.download.file) {
+ ret = FS_FOpenFile(cls.download.temp, &cls.download.file, FS_MODE_WRITE);
+ if (!cls.download.file) {
+ Com_EPrintf("[UDP] Couldn't open %s for writing: %s\n",
+ cls.download.temp, Q_ErrorString(ret));
goto another;
}
}
- ret = FS_Write( data, size, cls.download.file );
- if( ret != size ) {
- Com_EPrintf( "[UDP] Couldn't write %s: %s\n",
- cls.download.temp, Q_ErrorString( ret ) );
- FS_FCloseFile( cls.download.file );
+ ret = FS_Write(data, size, cls.download.file);
+ if (ret != size) {
+ Com_EPrintf("[UDP] Couldn't write %s: %s\n",
+ cls.download.temp, Q_ErrorString(ret));
+ FS_FCloseFile(cls.download.file);
goto another;
}
- if( percent != 100 ) {
+ if (percent != 100) {
// request next block
// change display routines by zoid
cls.download.percent = percent;
- CL_ClientCommand( "nextdl" );
+ CL_ClientCommand("nextdl");
} else {
- FS_FCloseFile( cls.download.file );
+ FS_FCloseFile(cls.download.file);
// rename the temp file to it's final name
- ret = FS_RenameFile( cls.download.temp, q->path );
- if( ret ) {
- Com_EPrintf( "[UDP] Couldn't rename %s to %s: %s\n",
- cls.download.temp, q->path, Q_ErrorString( ret ) );
+ ret = FS_RenameFile(cls.download.temp, q->path);
+ if (ret) {
+ Com_EPrintf("[UDP] Couldn't rename %s to %s: %s\n",
+ cls.download.temp, q->path, Q_ErrorString(ret));
} else {
msg = "DONE";
}
another:
// finished with current path
- CL_FinishDownload( q );
+ CL_FinishDownload(q);
cls.download.current = NULL;
cls.download.percent = 0;
cls.download.file = 0;
cls.download.temp[0] = 0;
- if( msg ) {
- Com_Printf( "[UDP] %s [%s] [%d remaining file%s]\n",
- q->path, msg, cls.download.pending, cls.download.pending == 1 ? "" : "s" );
+ if (msg) {
+ Com_Printf("[UDP] %s [%s] [%d remaining file%s]\n",
+ q->path, msg, cls.download.pending, cls.download.pending == 1 ? "" : "s");
}
// get another file if needed
@@ -292,44 +298,45 @@ Only predefined set of filename extensions is allowed,
to prevent the server from uploading arbitrary files.
===============
*/
-qboolean CL_CheckDownloadExtension( const char *ext ) {
+qboolean CL_CheckDownloadExtension(const char *ext)
+{
static const char allowed[][4] = {
"pcx", "wal", "wav", "md2", "sp2", "tga", "png",
"jpg", "bsp", "ent", "txt", "dm2", "loc", "md3"
};
- static const int total = sizeof( allowed ) / sizeof( allowed[0] );
+ static const int total = sizeof(allowed) / sizeof(allowed[0]);
int i;
- for( i = 0; i < total; i++ )
- if( !Q_stricmp( ext, allowed[i] ) )
+ for (i = 0; i < total; i++)
+ if (!Q_stricmp(ext, allowed[i]))
return qtrue;
return qfalse;
}
// attempts to start a download from the server if file doesn't exist.
-static qerror_t check_file_len( const char *path, size_t len, dltype_t type ) {
+static qerror_t check_file_len(const char *path, size_t len, dltype_t type)
+{
char buffer[MAX_QPATH], *ext;
qerror_t ret;
// check for oversize path
- if( len >= MAX_QPATH )
+ if (len >= MAX_QPATH)
return Q_ERR_NAMETOOLONG;
// normalize path
- len = FS_NormalizePath( buffer, path );
+ len = FS_NormalizePath(buffer, path);
// check for empty path
- if( len == 0 )
+ if (len == 0)
return Q_ERR_NAMETOOSHORT;
// check path
- if( !Q_ispath( buffer[0] )
- || !Q_ispath( buffer[ len - 1 ] )
- || !FS_ValidatePath( buffer )
- || strstr( buffer, ".." )
- || !strchr( buffer, '/' ) )
- {
+ if (!Q_ispath(buffer[0])
+ || !Q_ispath(buffer[len - 1])
+ || !FS_ValidatePath(buffer)
+ || strstr(buffer, "..")
+ || !strchr(buffer, '/')) {
// some of these checks are too conservative or even redundant
// once we have normalized the path, however they have to stay for
// compatibility reasons with older servers (some would even ban us
@@ -338,32 +345,33 @@ static qerror_t check_file_len( const char *path, size_t len, dltype_t type ) {
}
// check extension
- ext = COM_FileExtension( buffer );
- if( *ext != '.' || !CL_CheckDownloadExtension( ext + 1 ) )
+ ext = COM_FileExtension(buffer);
+ if (*ext != '.' || !CL_CheckDownloadExtension(ext + 1))
return Q_ERR_INVALID_PATH;
- if( FS_FileExists( buffer ) )
+ if (FS_FileExists(buffer))
// it exists, no need to download
return Q_ERR_EXIST;
#if USE_CURL
- ret = HTTP_QueueDownload( buffer, type );
- if( ret != Q_ERR_NOSYS )
+ ret = HTTP_QueueDownload(buffer, type);
+ if (ret != Q_ERR_NOSYS)
return ret;
#endif
// queue and start legacy UDP download
- ret = CL_QueueDownload( buffer, type );
- if( ret == Q_ERR_SUCCESS )
+ ret = CL_QueueDownload(buffer, type);
+ if (ret == Q_ERR_SUCCESS)
CL_StartNextDownload();
return ret;
}
-#define check_file( path, type ) \
- check_file_len( path, strlen( path ), type )
+#define check_file(path, type) \
+ check_file_len(path, strlen(path), type)
-static void check_skins( const char *name ) {
+static void check_skins(const char *name)
+{
size_t i, num_skins, ofs_skins, end_skins;
byte *model;
size_t len;
@@ -372,78 +380,76 @@ static void check_skins( const char *name ) {
char *md2skin;
dsp2frame_t *sp2frame;
uint32_t ident;
- char fn[ MAX_QPATH ];
+ char fn[MAX_QPATH];
- len = FS_LoadFile( name, ( void ** )&model );
- if( !model ) {
+ len = FS_LoadFile(name, (void **)&model);
+ if (!model) {
// couldn't load it
return;
}
- if( len < sizeof( ident ) ) {
+ if (len < sizeof(ident)) {
// file too small
goto done;
}
// check ident
- ident = LittleLong( *( uint32_t * )model );
- switch( ident ) {
+ ident = LittleLong(*(uint32_t *)model);
+ switch (ident) {
case MD2_IDENT:
// alias model
- md2header = ( dmd2header_t * )model;
- if( len < sizeof( *md2header ) ||
- LittleLong( md2header->ident ) != MD2_IDENT ||
- LittleLong( md2header->version ) != MD2_VERSION )
- {
+ md2header = (dmd2header_t *)model;
+ if (len < sizeof(*md2header) ||
+ LittleLong(md2header->ident) != MD2_IDENT ||
+ LittleLong(md2header->version) != MD2_VERSION) {
// not an alias model
goto done;
}
- num_skins = LittleLong( md2header->num_skins );
- ofs_skins = LittleLong( md2header->ofs_skins );
+ num_skins = LittleLong(md2header->num_skins);
+ ofs_skins = LittleLong(md2header->ofs_skins);
end_skins = ofs_skins + num_skins * MD2_MAX_SKINNAME;
- if( num_skins > MD2_MAX_SKINS || end_skins < ofs_skins || end_skins > len ) {
+ if (num_skins > MD2_MAX_SKINS || end_skins < ofs_skins || end_skins > len) {
// bad alias model
goto done;
}
- md2skin = ( char * )model + ofs_skins;
- for( i = 0; i < num_skins; i++ ) {
- if( !Q_memccpy( fn, md2skin, 0, sizeof( fn ) ) ) {
+ md2skin = (char *)model + ofs_skins;
+ for (i = 0; i < num_skins; i++) {
+ if (!Q_memccpy(fn, md2skin, 0, sizeof(fn))) {
// bad alias model
goto done;
}
- check_file( fn, DL_OTHER );
+ check_file(fn, DL_OTHER);
md2skin += MD2_MAX_SKINNAME;
}
break;
case SP2_IDENT:
// sprite model
- sp2header = ( dsp2header_t * )model;
- if( len < sizeof( *sp2header ) ||
- LittleLong( sp2header->ident ) != SP2_IDENT ||
- LittleLong( sp2header->version ) != SP2_VERSION )
- {
+ sp2header = (dsp2header_t *)model;
+ if (len < sizeof(*sp2header) ||
+ LittleLong(sp2header->ident) != SP2_IDENT ||
+ LittleLong(sp2header->version) != SP2_VERSION) {
// not a sprite model
goto done;
}
- num_skins = LittleLong( sp2header->numframes );
- ofs_skins = sizeof( *sp2header );
- end_skins = ofs_skins + num_skins * sizeof( dsp2frame_t );
- if( num_skins > SP2_MAX_FRAMES || end_skins < ofs_skins || end_skins > len ) {
+ num_skins = LittleLong(sp2header->numframes);
+ ofs_skins = sizeof(*sp2header);
+ end_skins = ofs_skins + num_skins * sizeof(dsp2frame_t);
+ if (num_skins > SP2_MAX_FRAMES || end_skins < ofs_skins || end_skins > len) {
// bad sprite model
goto done;
}
- sp2frame = ( dsp2frame_t * )( model + ofs_skins );
- for( i = 0; i < num_skins; i++ ) {
- if( !Q_memccpy( fn, sp2frame->name, 0, sizeof( fn ) ) ) {
+ sp2frame = (dsp2frame_t *)(model + ofs_skins);
+ for (i = 0; i < num_skins; i++) {
+ if (!Q_memccpy(fn, sp2frame->name, 0, sizeof(fn))) {
// bad sprite model
goto done;
}
- check_file( fn, DL_OTHER );
+ check_file(fn, DL_OTHER);
sp2frame++;
}
break;
@@ -454,62 +460,64 @@ static void check_skins( const char *name ) {
}
done:
- FS_FreeFile( model );
+ FS_FreeFile(model);
}
-static void check_player( const char *name ) {
- char fn[ MAX_QPATH ], model[ MAX_QPATH ], skin[ MAX_QPATH ], *p;
+static void check_player(const char *name)
+{
+ char fn[MAX_QPATH], model[MAX_QPATH], skin[MAX_QPATH], *p;
size_t len;
int i, j;
- CL_ParsePlayerSkin( NULL, model, skin, name );
+ CL_ParsePlayerSkin(NULL, model, skin, name);
// model
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/tris.md2", NULL );
- check_file_len( fn, len, DL_OTHER );
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/tris.md2", NULL);
+ check_file_len(fn, len, DL_OTHER);
// weapon models
- for( i = 0; i < cl.numWeaponModels; i++ ) {
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/", cl.weaponModels[i], NULL );
- check_file_len( fn, len, DL_OTHER );
+ for (i = 0; i < cl.numWeaponModels; i++) {
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/", cl.weaponModels[i], NULL);
+ check_file_len(fn, len, DL_OTHER);
}
// default weapon skin
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/weapon.pcx", NULL );
- check_file_len( fn, len, DL_OTHER );
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/weapon.pcx", NULL);
+ check_file_len(fn, len, DL_OTHER);
// skin
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/", skin, ".pcx", NULL );
- check_file_len( fn, len, DL_OTHER );
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/", skin, ".pcx", NULL);
+ check_file_len(fn, len, DL_OTHER);
// skin_i
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/", skin, "_i.pcx", NULL );
- check_file_len( fn, len, DL_OTHER );
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/", skin, "_i.pcx", NULL);
+ check_file_len(fn, len, DL_OTHER);
// sexed sounds
- for( i = 0; i < precache_sexed_total; i++ ) {
- j = precache_sexed_sounds[ i ];
- p = cl.configstrings[ CS_SOUNDS + j ];
+ for (i = 0; i < precache_sexed_total; i++) {
+ j = precache_sexed_sounds[i];
+ p = cl.configstrings[CS_SOUNDS + j];
- if( *p == '*' ) {
- len = Q_concat( fn, sizeof( fn ), "players/", model, "/", p + 1, NULL );
- check_file_len( fn, len, DL_OTHER );
+ if (*p == '*') {
+ len = Q_concat(fn, sizeof(fn), "players/", model, "/", p + 1, NULL);
+ check_file_len(fn, len, DL_OTHER);
}
}
}
// for precaching dependencies
-static qboolean downloads_pending( dltype_t type ) {
+static qboolean downloads_pending(dltype_t type)
+{
dlqueue_t *q;
// DL_OTHER just checks for any download
- if( type == DL_OTHER ) {
+ if (type == DL_OTHER) {
return !!cls.download.pending;
}
// see if there are pending downloads of the given type
- FOR_EACH_DLQ( q ) {
- if( q->state != DL_DONE && q->type == type ) {
+ FOR_EACH_DLQ(q) {
+ if (q->state != DL_DONE && q->type == type) {
return qtrue;
}
}
@@ -524,16 +532,17 @@ CL_RequestNextDownload
Runs precache check and dispatches downloads.
=====================
*/
-void CL_RequestNextDownload( void ) {
- char fn[ MAX_QPATH ], *name;
+void CL_RequestNextDownload(void)
+{
+ char fn[MAX_QPATH], *name;
size_t len;
int i;
- if( cls.state != ca_connected && cls.state != ca_loading )
+ if (cls.state != ca_connected && cls.state != ca_loading)
return;
- if( allow_download->integer <= 0 || NET_IsLocalAddress( &cls.serverAddress ) ) {
- if( precache_check <= PRECACHE_MAP ) {
+ if (allow_download->integer <= 0 || NET_IsLocalAddress(&cls.serverAddress)) {
+ if (precache_check <= PRECACHE_MAP) {
CL_RegisterBspModels();
}
@@ -541,23 +550,23 @@ void CL_RequestNextDownload( void ) {
return;
}
- switch( precache_check ) {
+ switch (precache_check) {
case PRECACHE_MODELS:
// confirm map
- if( allow_download_maps->integer )
- check_file( cl.configstrings[ CS_MODELS + 1 ], DL_MAP );
+ if (allow_download_maps->integer)
+ check_file(cl.configstrings[CS_MODELS + 1], DL_MAP);
// checking for models
- if( allow_download_models->integer ) {
- for( i = 2; i < MAX_MODELS; i++ ) {
- name = cl.configstrings[ CS_MODELS + i ];
- if( !name[0] ) {
+ if (allow_download_models->integer) {
+ for (i = 2; i < MAX_MODELS; i++) {
+ name = cl.configstrings[CS_MODELS + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '*' || name[0] == '#' ) {
+ if (name[0] == '*' || name[0] == '#') {
continue;
}
- check_file( name, DL_MODEL );
+ check_file(name, DL_MODEL);
}
}
@@ -565,89 +574,89 @@ void CL_RequestNextDownload( void ) {
// fall through
case PRECACHE_OTHER:
- if( allow_download_models->integer ) {
- if( downloads_pending( DL_MODEL ) ) {
+ if (allow_download_models->integer) {
+ if (downloads_pending(DL_MODEL)) {
// pending downloads (models), let's wait here before we can check skins.
- Com_DPrintf( "%s: waiting for models...\n", __func__ );
+ Com_DPrintf("%s: waiting for models...\n", __func__);
return;
}
- for( i = 2; i < MAX_MODELS; i++ ) {
- name = cl.configstrings[ CS_MODELS + i ];
- if( !name[0] ) {
+ for (i = 2; i < MAX_MODELS; i++) {
+ name = cl.configstrings[CS_MODELS + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '*' || name[0] == '#' ) {
+ if (name[0] == '*' || name[0] == '#') {
continue;
}
- check_skins( name );
+ check_skins(name);
}
}
- if( allow_download_sounds->integer ) {
- for( i = 1; i < MAX_SOUNDS; i++ ) {
- name = cl.configstrings[ CS_SOUNDS + i ];
- if( !name[0] ) {
+ if (allow_download_sounds->integer) {
+ for (i = 1; i < MAX_SOUNDS; i++) {
+ name = cl.configstrings[CS_SOUNDS + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '*' ) {
+ if (name[0] == '*') {
continue;
}
- if( name[0] == '#' ) {
- len = Q_strlcpy( fn, name + 1, sizeof( fn ) );
+ if (name[0] == '#') {
+ len = Q_strlcpy(fn, name + 1, sizeof(fn));
} else {
- len = Q_concat( fn, sizeof( fn ), "sound/", name, NULL );
+ len = Q_concat(fn, sizeof(fn), "sound/", name, NULL);
}
- check_file_len( fn, len, DL_OTHER );
+ check_file_len(fn, len, DL_OTHER);
}
}
- if( allow_download_pics->integer ) {
- for( i = 1; i < MAX_IMAGES; i++ ) {
- name = cl.configstrings[ CS_IMAGES + i ];
- if( !name[0] ) {
+ if (allow_download_pics->integer) {
+ for (i = 1; i < MAX_IMAGES; i++) {
+ name = cl.configstrings[CS_IMAGES + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '/' || name[0] == '\\' ) {
- len = Q_strlcpy( fn, name + 1, sizeof( fn ) );
+ if (name[0] == '/' || name[0] == '\\') {
+ len = Q_strlcpy(fn, name + 1, sizeof(fn));
} else {
- len = Q_concat( fn, sizeof( fn ), "pics/", name, ".pcx", NULL );
+ len = Q_concat(fn, sizeof(fn), "pics/", name, ".pcx", NULL);
}
- check_file_len( fn, len, DL_OTHER );
+ check_file_len(fn, len, DL_OTHER);
}
}
- if( allow_download_players->integer ) {
+ if (allow_download_players->integer) {
// find sexed sounds
precache_sexed_total = 0;
- for( i = 1; i < MAX_SOUNDS; i++ ) {
- if( cl.configstrings[ CS_SOUNDS + i ][ 0 ] == '*' ) {
+ for (i = 1; i < MAX_SOUNDS; i++) {
+ if (cl.configstrings[CS_SOUNDS + i][0] == '*') {
precache_sexed_sounds[precache_sexed_total++] = i;
}
}
- for( i = 0; i < MAX_CLIENTS; i++ ) {
- name = cl.configstrings[ CS_PLAYERSKINS + i ];
- if( !name[0] ) {
+ for (i = 0; i < MAX_CLIENTS; i++) {
+ name = cl.configstrings[CS_PLAYERSKINS + i];
+ if (!name[0]) {
continue;
}
- check_player( name );
+ check_player(name);
}
}
- if( allow_download_textures->integer ) {
+ if (allow_download_textures->integer) {
static const char env_suf[6][3] = {
"rt", "bk", "lf", "ft", "up", "dn"
};
- for( i = 0; i < 12; i++ ) {
- if( i & 1 )
- len = Q_concat( fn, sizeof( fn ),
- "env/", cl.configstrings[ CS_SKY ], env_suf[ i >> 1 ], ".pcx", NULL );
+ for (i = 0; i < 12; i++) {
+ if (i & 1)
+ len = Q_concat(fn, sizeof(fn),
+ "env/", cl.configstrings[CS_SKY], env_suf[i >> 1], ".pcx", NULL);
else
- len = Q_concat( fn, sizeof( fn ),
- "env/", cl.configstrings[ CS_SKY ], env_suf[ i >> 1 ], ".tga", NULL );
- check_file_len( fn, len, DL_OTHER );
+ len = Q_concat(fn, sizeof(fn),
+ "env/", cl.configstrings[CS_SKY], env_suf[i >> 1], ".tga", NULL);
+ check_file_len(fn, len, DL_OTHER);
}
}
@@ -655,21 +664,19 @@ void CL_RequestNextDownload( void ) {
// fall through
case PRECACHE_MAP:
- if( downloads_pending( DL_MAP ) ) {
+ if (downloads_pending(DL_MAP)) {
// map might still be downloading?
- Com_DPrintf( "%s: waiting for map...\n", __func__ );
+ Com_DPrintf("%s: waiting for map...\n", __func__);
return;
}
// load the map file before checking textures
CL_RegisterBspModels();
- if( allow_download_textures->integer ) {
- for( i = 0; i < cl.bsp->numtexinfo; i++ ) {
- name = cl.bsp->texinfo[ i ].name;
-
- len = Q_concat( fn, sizeof( fn ), "textures/", name, ".wal", NULL );
- check_file_len( fn, len, DL_OTHER );
+ if (allow_download_textures->integer) {
+ for (i = 0; i < cl.bsp->numtexinfo; i++) {
+ len = Q_concat(fn, sizeof(fn), "textures/", cl.bsp->texinfo[i].name, ".wal", NULL);
+ check_file_len(fn, len, DL_OTHER);
}
}
@@ -677,9 +684,9 @@ void CL_RequestNextDownload( void ) {
// fall through
case PRECACHE_FINAL:
- if( downloads_pending( DL_OTHER ) ) {
+ if (downloads_pending(DL_OTHER)) {
// pending downloads (possibly textures), let's wait here.
- Com_DPrintf( "%s: waiting for others...\n", __func__ );
+ Com_DPrintf("%s: waiting for others...\n", __func__);
return;
}
@@ -688,11 +695,12 @@ void CL_RequestNextDownload( void ) {
break;
default:
- Com_Error( ERR_DROP, "%s: bad precache_check\n", __func__ );
+ Com_Error(ERR_DROP, "%s: bad precache_check\n", __func__);
}
}
-void CL_ResetPrecacheCheck( void ) {
+void CL_ResetPrecacheCheck(void)
+{
precache_check = PRECACHE_MODELS;
}
@@ -703,36 +711,38 @@ CL_Download_f
Request a download from the server
===============
*/
-static void CL_Download_f( void ) {
+static void CL_Download_f(void)
+{
char *path;
qerror_t ret;
- if( cls.state < ca_connected ) {
- Com_Printf( "Must be connected to a server.\n" );
+ if (cls.state < ca_connected) {
+ Com_Printf("Must be connected to a server.\n");
return;
}
- if( allow_download->integer == -1 ) {
- Com_Printf( "Downloads are permanently disabled.\n" );
+ if (allow_download->integer == -1) {
+ Com_Printf("Downloads are permanently disabled.\n");
return;
}
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: download <filename>\n" );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: download <filename>\n");
return;
}
- path = Cmd_Argv( 1 );
+ path = Cmd_Argv(1);
- ret = check_file( path, DL_OTHER );
- if( ret ) {
- Com_Printf( "Couldn't download %s: %s\n", path, Q_ErrorString( ret ) );
+ ret = check_file(path, DL_OTHER);
+ if (ret) {
+ Com_Printf("Couldn't download %s: %s\n", path, Q_ErrorString(ret));
}
}
-void CL_InitDownloads( void ) {
- Cmd_AddCommand( "download", CL_Download_f );
+void CL_InitDownloads(void)
+{
+ Cmd_AddCommand("download", CL_Download_f);
- List_Init( &cls.download.queue );
+ List_Init(&cls.download.queue);
}
diff --git a/src/cl_ents.c b/src/cl_ents.c
index a03965f..b54c614 100644
--- a/src/cl_ents.c
+++ b/src/cl_ents.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -32,21 +32,22 @@ FRAME PARSING
=========================================================================
*/
-static inline qboolean entity_optimized( const entity_state_t *state ) {
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO )
+static inline qboolean entity_optimized(const entity_state_t *state)
+{
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO)
return qfalse;
- if( state->number != cl.frame.clientNum + 1 )
+ if (state->number != cl.frame.clientNum + 1)
return qfalse;
- if( cl.frame.ps.pmove.pm_type >= PM_DEAD )
+ if (cl.frame.ps.pmove.pm_type >= PM_DEAD)
return qfalse;
return qtrue;
}
static inline void
-entity_new( centity_t *ent, const entity_state_t *state, const vec_t *origin )
+entity_new(centity_t *ent, const entity_state_t *state, const vec_t *origin)
{
ent->trailcount = 1024; // for diminishing rocket / grenade trails
@@ -57,37 +58,36 @@ entity_new( centity_t *ent, const entity_state_t *state, const vec_t *origin )
ent->event_frame = cl.frame.number;
#endif
- if( state->event == EV_PLAYER_TELEPORT ||
+ if (state->event == EV_PLAYER_TELEPORT ||
state->event == EV_OTHER_TELEPORT ||
- ( state->renderfx & (RF_FRAMELERP|RF_BEAM) ) )
- {
+ (state->renderfx & (RF_FRAMELERP | RF_BEAM))) {
// no lerping if teleported
- VectorCopy( origin, ent->lerp_origin );
+ VectorCopy(origin, ent->lerp_origin);
return;
}
// old_origin is valid for new entities,
// so use it as starting point for interpolating between
- VectorCopy( state->old_origin, ent->prev.origin );
- VectorCopy( state->old_origin, ent->lerp_origin );
+ VectorCopy(state->old_origin, ent->prev.origin);
+ VectorCopy(state->old_origin, ent->lerp_origin);
}
static inline void
-entity_old( centity_t *ent, const entity_state_t *state, const vec_t *origin )
+entity_old(centity_t *ent, const entity_state_t *state, const vec_t *origin)
{
int event = state->event;
#if USE_FPS
// check for new event
- if( state->event != ent->current.event )
+ if (state->event != ent->current.event)
ent->event_frame = cl.frame.number; // new
- else if( cl.frame.number - ent->event_frame >= cl.framediv )
+ else if (cl.frame.number - ent->event_frame >= cl.framediv)
ent->event_frame = cl.frame.number; // refreshed
else
event = 0; // duplicated
#endif
- if( state->modelindex != ent->current.modelindex
+ if (state->modelindex != ent->current.modelindex
|| state->modelindex2 != ent->current.modelindex2
|| state->modelindex3 != ent->current.modelindex3
|| state->modelindex4 != ent->current.modelindex4
@@ -96,8 +96,7 @@ entity_old( centity_t *ent, const entity_state_t *state, const vec_t *origin )
|| abs(origin[0] - ent->current.origin[0]) > 512
|| abs(origin[1] - ent->current.origin[1]) > 512
|| abs(origin[2] - ent->current.origin[2]) > 512
- || cl_nolerp->integer )
- {
+ || cl_nolerp->integer) {
// some data changes will force no lerping
ent->trailcount = 1024; // for diminishing rocket / grenade trails
@@ -107,19 +106,19 @@ entity_old( centity_t *ent, const entity_state_t *state, const vec_t *origin )
ent->prev_frame = state->frame;
#endif
// no lerping if teleported or morphed
- VectorCopy( origin, ent->lerp_origin );
+ VectorCopy(origin, ent->lerp_origin);
return;
}
#if USE_FPS
// start alias model animation
- if( state->frame != ent->current.frame ) {
+ if (state->frame != ent->current.frame) {
ent->prev_frame = ent->current.frame;
ent->anim_start = cl.servertime - cl.frametime;
- Com_DDPrintf( "[%d] anim start %d: %d --> %d [%d]\n",
- ent->anim_start, state->number,
- ent->prev_frame, state->frame,
- cl.frame.number );
+ Com_DDPrintf("[%d] anim start %d: %d --> %d [%d]\n",
+ ent->anim_start, state->number,
+ ent->prev_frame, state->frame,
+ cl.frame.number);
}
#endif
@@ -127,55 +126,57 @@ entity_old( centity_t *ent, const entity_state_t *state, const vec_t *origin )
ent->prev = ent->current;
}
-static void entity_update( const entity_state_t *state ) {
+static void entity_update(const entity_state_t *state)
+{
centity_t *ent = &cl_entities[state->number];
const vec_t *origin;
vec3_t origin_v;
// if entity is solid, decode mins/maxs and add to the list
- if( state->solid && state->number != cl.frame.clientNum + 1 ) {
+ if (state->solid && state->number != cl.frame.clientNum + 1) {
cl.solidEntities[cl.numSolidEntities++] = ent;
- if( state->solid != PACKED_BSP ) {
+ if (state->solid != PACKED_BSP) {
// encoded bbox
- if( cl.esFlags & MSG_ES_LONGSOLID ) {
- MSG_UnpackSolid32( state->solid, ent->mins, ent->maxs );
+ if (cl.esFlags & MSG_ES_LONGSOLID) {
+ MSG_UnpackSolid32(state->solid, ent->mins, ent->maxs);
} else {
- MSG_UnpackSolid16( state->solid, ent->mins, ent->maxs );
+ MSG_UnpackSolid16(state->solid, ent->mins, ent->maxs);
}
}
}
// work around Q2PRO server bandwidth optimization
- if( entity_optimized( state ) ) {
- VectorScale( cl.frame.ps.pmove.origin, 0.125f, origin_v );
+ if (entity_optimized(state)) {
+ VectorScale(cl.frame.ps.pmove.origin, 0.125f, origin_v);
origin = origin_v;
} else {
origin = state->origin;
}
- if( ent->serverframe != cl.oldframe.number ) {
+ if (ent->serverframe != cl.oldframe.number) {
// wasn't in last update, so initialize some things
- entity_new( ent, state, origin );
+ entity_new(ent, state, origin);
} else {
- entity_old( ent, state, origin );
+ entity_old(ent, state, origin);
}
ent->serverframe = cl.frame.number;
ent->current = *state;
// work around Q2PRO server bandwidth optimization
- if( entity_optimized( state ) ) {
- Com_PlayerToEntityState( &cl.frame.ps, &ent->current );
+ if (entity_optimized(state)) {
+ Com_PlayerToEntityState(&cl.frame.ps, &ent->current);
}
}
// an entity has just been parsed that has an event value
-static void entity_event (int number) {
+static void entity_event(int number)
+{
centity_t *cent = &cl_entities[number];
// EF_TELEPORTER acts like an event, but is not cleared each frame
- if( ( cent->current.effects & EF_TELEPORTER ) && CL_FRAMESYNC ) {
- CL_TeleporterParticles( cent->current.origin );
+ if ((cent->current.effects & EF_TELEPORTER) && CL_FRAMESYNC) {
+ CL_TeleporterParticles(cent->current.origin);
}
#if USE_FPS
@@ -185,31 +186,32 @@ static void entity_event (int number) {
switch (cent->current.event) {
case EV_ITEM_RESPAWN:
- S_StartSound (NULL, number, CHAN_WEAPON, S_RegisterSound("items/respawn1.wav"), 1, ATTN_IDLE, 0);
- CL_ItemRespawnParticles (cent->current.origin);
+ S_StartSound(NULL, number, CHAN_WEAPON, S_RegisterSound("items/respawn1.wav"), 1, ATTN_IDLE, 0);
+ CL_ItemRespawnParticles(cent->current.origin);
break;
case EV_PLAYER_TELEPORT:
- S_StartSound (NULL, number, CHAN_WEAPON, S_RegisterSound("misc/tele1.wav"), 1, ATTN_IDLE, 0);
- CL_TeleportParticles (cent->current.origin);
+ S_StartSound(NULL, number, CHAN_WEAPON, S_RegisterSound("misc/tele1.wav"), 1, ATTN_IDLE, 0);
+ CL_TeleportParticles(cent->current.origin);
break;
case EV_FOOTSTEP:
if (cl_footsteps->integer)
- S_StartSound (NULL, number, CHAN_BODY, cl_sfx_footsteps[rand()&3], 1, ATTN_NORM, 0);
+ S_StartSound(NULL, number, CHAN_BODY, cl_sfx_footsteps[rand() & 3], 1, ATTN_NORM, 0);
break;
case EV_FALLSHORT:
- S_StartSound (NULL, number, CHAN_AUTO, S_RegisterSound ("player/land1.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, number, CHAN_AUTO, S_RegisterSound("player/land1.wav"), 1, ATTN_NORM, 0);
break;
case EV_FALL:
- S_StartSound (NULL, number, CHAN_AUTO, S_RegisterSound ("*fall2.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, number, CHAN_AUTO, S_RegisterSound("*fall2.wav"), 1, ATTN_NORM, 0);
break;
case EV_FALLFAR:
- S_StartSound (NULL, number, CHAN_AUTO, S_RegisterSound ("*fall1.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, number, CHAN_AUTO, S_RegisterSound("*fall1.wav"), 1, ATTN_NORM, 0);
break;
}
}
-static void set_active_state( void ) {
- cl.serverdelta = Q_align( cl.frame.number, CL_FRAMEDIV );
+static void set_active_state(void)
+{
+ cl.serverdelta = Q_align(cl.frame.number, CL_FRAMEDIV);
cl.time = cl.servertime = 0; // set time, needed for demos
#if USE_FPS
cl.keytime = cl.keyservertime = 0;
@@ -218,44 +220,43 @@ static void set_active_state( void ) {
cl.oldframe.valid = qfalse;
cl.frameflags = 0;
cl.putaway = qfalse;
- if( cls.netchan ) {
+ if (cls.netchan) {
cl.initialSeq = cls.netchan->outgoing_sequence;
}
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
// init some demo things
CL_FirstDemoFrame();
} else {
// set initial cl.predicted_origin and cl.predicted_angles
- VectorScale( cl.frame.ps.pmove.origin, 0.125f, cl.predicted_origin );
- VectorScale( cl.frame.ps.pmove.velocity, 0.125f, cl.predicted_velocity );
- if( cl.frame.ps.pmove.pm_type < PM_DEAD &&
- cls.serverProtocol > PROTOCOL_VERSION_DEFAULT )
- {
+ VectorScale(cl.frame.ps.pmove.origin, 0.125f, cl.predicted_origin);
+ VectorScale(cl.frame.ps.pmove.velocity, 0.125f, cl.predicted_velocity);
+ if (cl.frame.ps.pmove.pm_type < PM_DEAD &&
+ cls.serverProtocol > PROTOCOL_VERSION_DEFAULT) {
// enhanced servers don't send viewangles
CL_PredictAngles();
} else {
// just use what server provided
- VectorCopy( cl.frame.ps.viewangles, cl.predicted_angles );
+ VectorCopy(cl.frame.ps.viewangles, cl.predicted_angles);
}
}
- SCR_EndLoadingPlaque (); // get rid of loading plaque
+ SCR_EndLoadingPlaque(); // get rid of loading plaque
SCR_LagClear();
- Con_Close( qfalse ); // get rid of connection screen
+ Con_Close(qfalse); // get rid of connection screen
CL_CheckForPause();
CL_UpdateFrameTimes();
- if( !cls.demo.playback ) {
- EXEC_TRIGGER( cl_beginmapcmd );
- Cmd_ExecTrigger( "#cl_enterlevel" );
+ if (!cls.demo.playback) {
+ EXEC_TRIGGER(cl_beginmapcmd);
+ Cmd_ExecTrigger("#cl_enterlevel");
}
}
static void
-player_update( server_frame_t *oldframe, server_frame_t *frame, int framediv )
+player_update(server_frame_t *oldframe, server_frame_t *frame, int framediv)
{
player_state_t *ps, *ops;
centity_t *ent;
@@ -266,45 +267,43 @@ player_update( server_frame_t *oldframe, server_frame_t *frame, int framediv )
ops = &oldframe->ps;
// no lerping if previous frame was dropped or invalid
- if( !oldframe->valid )
+ if (!oldframe->valid)
goto dup;
oldnum = frame->number - framediv;
- if( oldframe->number != oldnum )
+ if (oldframe->number != oldnum)
goto dup;
// no lerping if player entity was teleported (origin check)
- if( abs( ops->pmove.origin[0] - ps->pmove.origin[0] ) > 256*8 ||
- abs( ops->pmove.origin[1] - ps->pmove.origin[1] ) > 256*8 ||
- abs( ops->pmove.origin[2] - ps->pmove.origin[2] ) > 256*8 )
- {
+ if (abs(ops->pmove.origin[0] - ps->pmove.origin[0]) > 256 * 8 ||
+ abs(ops->pmove.origin[1] - ps->pmove.origin[1]) > 256 * 8 ||
+ abs(ops->pmove.origin[2] - ps->pmove.origin[2]) > 256 * 8) {
goto dup;
}
// no lerping if player entity was teleported (event check)
ent = &cl_entities[frame->clientNum + 1];
- if( ent->serverframe > oldnum &&
+ if (ent->serverframe > oldnum &&
ent->serverframe <= frame->number &&
#if USE_FPS
ent->event_frame > oldnum &&
ent->event_frame <= frame->number &&
#endif
- ( ent->current.event == EV_PLAYER_TELEPORT
- || ent->current.event == EV_OTHER_TELEPORT ) )
- {
+ (ent->current.event == EV_PLAYER_TELEPORT
+ || ent->current.event == EV_OTHER_TELEPORT)) {
goto dup;
}
// no lerping if teleport bit was flipped
- if( ( ops->pmove.pm_flags ^ ps->pmove.pm_flags ) & PMF_TELEPORT_BIT )
+ if ((ops->pmove.pm_flags ^ ps->pmove.pm_flags) & PMF_TELEPORT_BIT)
goto dup;
// no lerping if POV number changed
- if( oldframe->clientNum != frame->clientNum )
+ if (oldframe->clientNum != frame->clientNum)
goto dup;
// developer option
- if( cl_nolerp->integer )
+ if (cl_nolerp->integer)
goto dup;
return;
@@ -321,66 +320,67 @@ CL_DeltaFrame
A valid frame has been parsed.
==================
*/
-void CL_DeltaFrame( void ) {
+void CL_DeltaFrame(void)
+{
centity_t *ent;
entity_state_t *state;
int i, j;
int framenum;
// getting a valid frame message ends the connection process
- if( cls.state == ca_precached )
+ if (cls.state == ca_precached)
set_active_state();
// set server time
framenum = cl.frame.number - cl.serverdelta;
cl.servertime = framenum * CL_FRAMETIME;
#if USE_FPS
- cl.keyservertime = ( framenum / cl.framediv ) * BASE_FRAMETIME;
+ cl.keyservertime = (framenum / cl.framediv) * BASE_FRAMETIME;
#endif
// rebuild the list of solid entities for this frame
cl.numSolidEntities = 0;
// initialize position of the player's own entity from playerstate.
- // this is needed in situations when player entity is invisible, but
+ // this is needed in situations when player entity is invisible, but
// server sends an effect referencing it's origin (such as MZ_LOGIN, etc)
- ent = &cl_entities[ cl.frame.clientNum + 1 ];
- Com_PlayerToEntityState( &cl.frame.ps, &ent->current );
+ ent = &cl_entities[cl.frame.clientNum + 1];
+ Com_PlayerToEntityState(&cl.frame.ps, &ent->current);
- for( i = 0; i < cl.frame.numEntities; i++ ) {
- j = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ for (i = 0; i < cl.frame.numEntities; i++) {
+ j = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
state = &cl.entityStates[j];
// set current and prev
- entity_update( state );
+ entity_update(state);
// fire events
- entity_event( state->number );
+ entity_event(state->number);
}
- if( cls.demo.recording && !cls.demo.paused && !cls.demo.seeking && CL_FRAMESYNC ) {
+ if (cls.demo.recording && !cls.demo.paused && !cls.demo.seeking && CL_FRAMESYNC) {
CL_EmitDemoFrame();
}
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
// this delta has nothing to do with local viewangles,
// clear it to avoid interfering with demo freelook hack
- VectorClear( cl.frame.ps.pmove.delta_angles );
+ VectorClear(cl.frame.ps.pmove.delta_angles);
}
-
- if( !cl.oldframe.ps.stats[STAT_LAYOUTS] && cl.frame.ps.stats[STAT_LAYOUTS] ) {
+
+ if (!cl.oldframe.ps.stats[STAT_LAYOUTS] && cl.frame.ps.stats[STAT_LAYOUTS]) {
cl.putaway = qfalse;
}
- if( cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type ) {
+ if (cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type) {
IN_Activate();
}
- player_update( &cl.oldframe, &cl.frame, 1 );
+ player_update(&cl.oldframe, &cl.frame, 1);
#if USE_FPS
- if( CL_FRAMESYNC )
- player_update( &cl.oldkeyframe, &cl.keyframe, cl.framediv );
+ if (CL_FRAMESYNC)
+ player_update(&cl.oldkeyframe, &cl.keyframe, cl.framediv);
#endif
CL_CheckPredictionError();
@@ -390,26 +390,27 @@ void CL_DeltaFrame( void ) {
#ifdef _DEBUG
// for debugging problems when out-of-date entity origin is referenced
-void CL_CheckEntityPresent( int entnum, const char *what ) {
+void CL_CheckEntityPresent(int entnum, const char *what)
+{
centity_t *e = &cl_entities[entnum];
- if( entnum == cl.frame.clientNum + 1 ) {
+ if (entnum == cl.frame.clientNum + 1) {
return; // player entity = current
}
e = &cl_entities[entnum];
- if( e->serverframe == cl.frame.number ) {
+ if (e->serverframe == cl.frame.number) {
return; // current
}
- if( e->serverframe ) {
- Com_LPrintf( PRINT_DEVELOPER,
- "SERVER BUG: %s on entity %d last seen %d frames ago\n",
- what, entnum, cl.frame.number - e->serverframe );
+ if (e->serverframe) {
+ Com_LPrintf(PRINT_DEVELOPER,
+ "SERVER BUG: %s on entity %d last seen %d frames ago\n",
+ what, entnum, cl.frame.number - e->serverframe);
} else {
- Com_LPrintf( PRINT_DEVELOPER,
- "SERVER BUG: %s on entity %d never seen before\n",
- what, entnum );
+ Com_LPrintf(PRINT_DEVELOPER,
+ "SERVER BUG: %s on entity %d never seen before\n",
+ what, entnum);
}
}
#endif
@@ -429,7 +430,8 @@ CL_AddPacketEntities
===============
*/
-static void CL_AddPacketEntities( void ) {
+static void CL_AddPacketEntities(void)
+{
entity_t ent;
entity_state_t *s1;
float autorotate;
@@ -441,15 +443,15 @@ static void CL_AddPacketEntities( void ) {
unsigned int effects, renderfx;
// bonus items rotate at a fixed rate
- autorotate = anglemod( cl.time * 0.1f );
+ autorotate = anglemod(cl.time * 0.1f);
// brush models can auto animate their frames
autoanim = 2 * cl.time / 1000;
- memset( &ent, 0, sizeof( ent ) );
+ memset(&ent, 0, sizeof(ent));
- for( pnum = 0; pnum < cl.frame.numEntities; pnum++ ) {
- i = ( cl.frame.firstEntity + pnum ) & PARSE_ENTITIES_MASK;
+ for (pnum = 0; pnum < cl.frame.numEntities; pnum++) {
+ i = (cl.frame.firstEntity + pnum) & PARSE_ENTITIES_MASK;
s1 = &cl.entityStates[i];
cent = &cl_entities[s1->number];
@@ -507,44 +509,44 @@ static void CL_AddPacketEntities( void ) {
if (renderfx & RF_FRAMELERP) {
// step origin discretely, because the frames
// do the animation properly
- VectorCopy (cent->current.origin, ent.origin);
- VectorCopy (cent->current.old_origin, ent.oldorigin); // FIXME
- } else if( renderfx & RF_BEAM ) {
+ VectorCopy(cent->current.origin, ent.origin);
+ VectorCopy(cent->current.old_origin, ent.oldorigin); // FIXME
+ } else if (renderfx & RF_BEAM) {
// interpolate start and end points for beams
- LerpVector( cent->prev.origin, cent->current.origin,
- cl.lerpfrac, ent.origin );
- LerpVector( cent->prev.old_origin, cent->current.old_origin,
- cl.lerpfrac, ent.oldorigin );
+ LerpVector(cent->prev.origin, cent->current.origin,
+ cl.lerpfrac, ent.origin);
+ LerpVector(cent->prev.old_origin, cent->current.old_origin,
+ cl.lerpfrac, ent.oldorigin);
} else {
- if( s1->number == cl.frame.clientNum + 1 ) {
+ if (s1->number == cl.frame.clientNum + 1) {
// use predicted origin
- VectorCopy( cl.playerEntityOrigin, ent.origin );
- VectorCopy( cl.playerEntityOrigin, ent.oldorigin );
+ VectorCopy(cl.playerEntityOrigin, ent.origin);
+ VectorCopy(cl.playerEntityOrigin, ent.oldorigin);
} else {
// interpolate origin
- LerpVector( cent->prev.origin, cent->current.origin,
- cl.lerpfrac, ent.origin );
- VectorCopy( ent.origin, ent.oldorigin );
+ LerpVector(cent->prev.origin, cent->current.origin,
+ cl.lerpfrac, ent.origin);
+ VectorCopy(ent.origin, ent.oldorigin);
}
#if USE_FPS
// run alias model animation
- if( cent->prev_frame != s1->frame ) {
+ if (cent->prev_frame != s1->frame) {
int delta = cl.time - cent->anim_start;
float frac;
- if( delta > BASE_FRAMETIME ) {
- Com_DDPrintf( "[%d] anim end %d: %d --> %d\n",
- cl.time, s1->number,
- cent->prev_frame, s1->frame );
+ if (delta > BASE_FRAMETIME) {
+ Com_DDPrintf("[%d] anim end %d: %d --> %d\n",
+ cl.time, s1->number,
+ cent->prev_frame, s1->frame);
cent->prev_frame = s1->frame;
frac = 1;
- } else if( delta > 0 ) {
+ } else if (delta > 0) {
frac = delta * BASE_1_FRAMETIME;
- Com_DDPrintf( "[%d] anim run %d: %d --> %d [%f]\n",
- cl.time, s1->number,
- cent->prev_frame, s1->frame,
- frac );
+ Com_DDPrintf("[%d] anim run %d: %d --> %d [%f]\n",
+ cl.time, s1->number,
+ cent->prev_frame, s1->frame,
+ frac);
} else {
frac = 0;
}
@@ -555,48 +557,42 @@ static void CL_AddPacketEntities( void ) {
#endif
}
- if( ( effects & EF_GIB ) && !cl_gibs->integer ) {
+ if ((effects & EF_GIB) && !cl_gibs->integer) {
goto skip;
}
// create a new entity
-
+
// tweak the color of beams
- if ( renderfx & RF_BEAM )
- { // the four beam colors are encoded in 32 bits of skinnum (hack)
+ if (renderfx & RF_BEAM) {
+ // the four beam colors are encoded in 32 bits of skinnum (hack)
ent.alpha = 0.30;
- ent.skinnum = (s1->skinnum >> ((rand() % 4)*8)) & 0xff;
+ ent.skinnum = (s1->skinnum >> ((rand() % 4) * 8)) & 0xff;
ent.model = 0;
- }
- else
- {
+ } else {
// set skin
- if (s1->modelindex == 255)
- { // use custom player skin
+ if (s1->modelindex == 255) {
+ // use custom player skin
ent.skinnum = 0;
ci = &cl.clientinfo[s1->skinnum & 0xff];
ent.skin = ci->skin;
ent.model = ci->model;
- if (!ent.skin || !ent.model)
- {
+ if (!ent.skin || !ent.model) {
ent.skin = cl.baseclientinfo.skin;
ent.model = cl.baseclientinfo.model;
ci = &cl.baseclientinfo;
}
//============
//PGM
- if (renderfx & RF_USE_DISGUISE)
- {
+ if (renderfx & RF_USE_DISGUISE) {
char buffer[MAX_QPATH];
- Q_concat( buffer, sizeof( buffer ), "players/", ci->model_name, "/disguise.pcx", NULL );
- ent.skin = R_RegisterSkin( buffer );
+ Q_concat(buffer, sizeof(buffer), "players/", ci->model_name, "/disguise.pcx", NULL);
+ ent.skin = R_RegisterSkin(buffer);
}
//PGM
//============
- }
- else
- {
+ } else {
ent.skinnum = s1->skinnum;
ent.skin = 0;
ent.model = cl.model_draw[s1->modelindex];
@@ -620,41 +616,40 @@ static void CL_AddPacketEntities( void ) {
ent.angles[2] = 0;
}
// RAFAEL
- else if (effects & EF_SPINNINGLIGHTS)
- {
+ else if (effects & EF_SPINNINGLIGHTS) {
vec3_t forward;
vec3_t start;
ent.angles[0] = 0;
- ent.angles[1] = anglemod(cl.time/2) + s1->angles[1];
+ ent.angles[1] = anglemod(cl.time / 2) + s1->angles[1];
ent.angles[2] = 180;
- AngleVectors (ent.angles, forward, NULL, NULL);
- VectorMA (ent.origin, 64, forward, start);
- V_AddLight (start, 100, 1, 0, 0);
- } else if( s1->number == cl.frame.clientNum + 1 ) {
- VectorCopy( cl.playerEntityAngles, ent.angles ); // use predicted angles
+ AngleVectors(ent.angles, forward, NULL, NULL);
+ VectorMA(ent.origin, 64, forward, start);
+ V_AddLight(start, 100, 1, 0, 0);
+ } else if (s1->number == cl.frame.clientNum + 1) {
+ VectorCopy(cl.playerEntityAngles, ent.angles); // use predicted angles
} else { // interpolate angles
LerpAngles(cent->prev.angles, cent->current.angles,
- cl.lerpfrac, ent.angles);
+ cl.lerpfrac, ent.angles);
// mimic original ref_gl "leaning" bug (uuugly!)
- if( s1->modelindex == 255 && cl_rollhack->integer ) {
+ if (s1->modelindex == 255 && cl_rollhack->integer) {
ent.angles[ROLL] = -ent.angles[ROLL];
}
}
- if( s1->number == cl.frame.clientNum + 1 ) {
+ if (s1->number == cl.frame.clientNum + 1) {
if (effects & EF_FLAG1)
- V_AddLight (ent.origin, 225, 1.0, 0.1, 0.1);
+ V_AddLight(ent.origin, 225, 1.0, 0.1, 0.1);
else if (effects & EF_FLAG2)
- V_AddLight (ent.origin, 225, 0.1, 0.1, 1.0);
+ V_AddLight(ent.origin, 225, 0.1, 0.1, 1.0);
else if (effects & EF_TAGTRAIL) //PGM
- V_AddLight (ent.origin, 225, 1.0, 1.0, 0.0); //PGM
+ V_AddLight(ent.origin, 225, 1.0, 1.0, 0.0); //PGM
else if (effects & EF_TRACKERTRAIL) //PGM
- V_AddLight (ent.origin, 225, -1.0, -1.0, -1.0); //PGM
+ V_AddLight(ent.origin, 225, -1.0, -1.0, -1.0); //PGM
- if( !cl.thirdPersonView ) {
+ if (!cl.thirdPersonView) {
#if 0
ent.flags |= RF_VIEWERMODEL; // only draw from mirrors
#else
@@ -668,21 +663,18 @@ static void CL_AddPacketEntities( void ) {
goto skip;
}
- if (effects & EF_BFG)
- {
+ if (effects & EF_BFG) {
ent.flags |= RF_TRANSLUCENT;
ent.alpha = 0.30;
}
// RAFAEL
- if (effects & EF_PLASMA)
- {
+ if (effects & EF_PLASMA) {
ent.flags |= RF_TRANSLUCENT;
ent.alpha = 0.6;
}
- if (effects & EF_SPHERETRANS)
- {
+ if (effects & EF_SPHERETRANS) {
ent.flags |= RF_TRANSLUCENT;
// PMM - *sigh* yet more EF overloading
if (effects & EF_TRACKERTRAIL)
@@ -693,29 +685,25 @@ static void CL_AddPacketEntities( void ) {
//pmm
// add to refresh list
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
// color shells generate a seperate entity for the main model
- if (effects & EF_COLOR_SHELL)
- {
+ if (effects & EF_COLOR_SHELL) {
// PMM - at this point, all of the shells have been handled
// if we're in the rogue pack, set up the custom mixing, otherwise just
// keep going
- if(!strcmp(fs_game->string,"rogue"))
- {
+ if (!strcmp(fs_game->string, "rogue")) {
// all of the solo colors are fine. we need to catch any of the combinations that look bad
// (double & half) and turn them into the appropriate color, and make double/quad something special
- if (renderfx & RF_SHELL_HALF_DAM)
- {
+ if (renderfx & RF_SHELL_HALF_DAM) {
// ditch the half damage shell if any of red, blue, or double are on
- if (renderfx & (RF_SHELL_RED|RF_SHELL_BLUE|RF_SHELL_DOUBLE))
+ if (renderfx & (RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_DOUBLE))
renderfx &= ~RF_SHELL_HALF_DAM;
}
- if (renderfx & RF_SHELL_DOUBLE)
- {
+ if (renderfx & RF_SHELL_DOUBLE) {
// lose the yellow shell if we have a red, blue, or green shell
- if (renderfx & (RF_SHELL_RED|RF_SHELL_BLUE|RF_SHELL_GREEN))
+ if (renderfx & (RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_GREEN))
renderfx &= ~RF_SHELL_DOUBLE;
// if we have a red shell, turn it to purple by adding blue
if (renderfx & RF_SHELL_RED)
@@ -733,7 +721,7 @@ static void CL_AddPacketEntities( void ) {
// pmm
ent.flags = renderfx | RF_TRANSLUCENT;
ent.alpha = 0.30;
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
}
ent.skin = 0; // never use a custom skin on others
@@ -742,10 +730,9 @@ static void CL_AddPacketEntities( void ) {
ent.alpha = 0;
// duplicate for linked models
- if (s1->modelindex2)
- {
- if (s1->modelindex2 == 255)
- { // custom weapon
+ if (s1->modelindex2) {
+ if (s1->modelindex2 == 255) {
+ // custom weapon
ci = &cl.clientinfo[s1->skinnum & 0xff];
i = (s1->skinnum >> 8); // 0 is default weapon model
if (i < 0 || i > cl.numWeaponModels - 1)
@@ -757,207 +744,169 @@ static void CL_AddPacketEntities( void ) {
if (!ent.model)
ent.model = cl.baseclientinfo.weaponmodel[0];
}
- }
- else
+ } else
ent.model = cl.model_draw[s1->modelindex2];
// PMM - check for the defender sphere shell .. make it translucent
// replaces the previous version which used the high bit on modelindex2 to determine transparency
- if (!Q_strcasecmp (cl.configstrings[CS_MODELS+(s1->modelindex2)], "models/items/shell/tris.md2"))
- {
+ if (!Q_strcasecmp(cl.configstrings[CS_MODELS + (s1->modelindex2)], "models/items/shell/tris.md2")) {
ent.alpha = 0.32;
ent.flags = RF_TRANSLUCENT;
}
// pmm
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
//PGM - make sure these get reset.
ent.flags = 0;
ent.alpha = 0;
//PGM
}
- if (s1->modelindex3)
- {
+ if (s1->modelindex3) {
ent.model = cl.model_draw[s1->modelindex3];
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
}
- if (s1->modelindex4)
- {
+ if (s1->modelindex4) {
ent.model = cl.model_draw[s1->modelindex4];
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
}
- if ( effects & EF_POWERSCREEN )
- {
+ if (effects & EF_POWERSCREEN) {
ent.model = cl_mod_powerscreen;
ent.oldframe = 0;
ent.frame = 0;
ent.flags |= (RF_TRANSLUCENT | RF_SHELL_GREEN);
ent.alpha = 0.30;
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
}
// add automatic particle trails
- if ( (effects&~EF_ROTATE) )
- {
- if (effects & EF_ROCKET)
- {
- if( !( cl_disable_particles->integer & NOPART_ROCKET_TRAIL ) ) {
- CL_RocketTrail( cent->lerp_origin, ent.origin, cent );
+ if ((effects&~EF_ROTATE)) {
+ if (effects & EF_ROCKET) {
+ if (!(cl_disable_particles->integer & NOPART_ROCKET_TRAIL)) {
+ CL_RocketTrail(cent->lerp_origin, ent.origin, cent);
}
- V_AddLight (ent.origin, 200, 1, 1, 0);
+ V_AddLight(ent.origin, 200, 1, 1, 0);
}
- // PGM - Do not reorder EF_BLASTER and EF_HYPERBLASTER.
+ // PGM - Do not reorder EF_BLASTER and EF_HYPERBLASTER.
// EF_BLASTER | EF_TRACKER is a special case for EF_BLASTER2... Cheese!
- else if (effects & EF_BLASTER)
- {
+ else if (effects & EF_BLASTER) {
// CL_BlasterTrail (cent->lerp_origin, ent.origin);
//PGM
- if (effects & EF_TRACKER) // lame... problematic?
- {
- CL_BlasterTrail2 (cent->lerp_origin, ent.origin);
- V_AddLight (ent.origin, 200, 0, 1, 0);
- }
- else
- {
- CL_BlasterTrail (cent->lerp_origin, ent.origin);
- V_AddLight (ent.origin, 200, 1, 1, 0);
+ if (effects & EF_TRACKER) { // lame... problematic?
+ CL_BlasterTrail2(cent->lerp_origin, ent.origin);
+ V_AddLight(ent.origin, 200, 0, 1, 0);
+ } else {
+ CL_BlasterTrail(cent->lerp_origin, ent.origin);
+ V_AddLight(ent.origin, 200, 1, 1, 0);
}
//PGM
- }
- else if (effects & EF_HYPERBLASTER)
- {
+ } else if (effects & EF_HYPERBLASTER) {
if (effects & EF_TRACKER) // PGM overloaded for blaster2.
- V_AddLight (ent.origin, 200, 0, 1, 0); // PGM
+ V_AddLight(ent.origin, 200, 0, 1, 0); // PGM
else // PGM
- V_AddLight (ent.origin, 200, 1, 1, 0);
- }
- else if (effects & EF_GIB)
- {
- CL_DiminishingTrail (cent->lerp_origin, ent.origin, cent, effects);
- }
- else if (effects & EF_GRENADE)
- {
- if( !( cl_disable_particles->integer & NOPART_GRENADE_TRAIL ) ) {
- CL_DiminishingTrail( cent->lerp_origin, ent.origin, cent, effects );
+ V_AddLight(ent.origin, 200, 1, 1, 0);
+ } else if (effects & EF_GIB) {
+ CL_DiminishingTrail(cent->lerp_origin, ent.origin, cent, effects);
+ } else if (effects & EF_GRENADE) {
+ if (!(cl_disable_particles->integer & NOPART_GRENADE_TRAIL)) {
+ CL_DiminishingTrail(cent->lerp_origin, ent.origin, cent, effects);
}
- }
- else if (effects & EF_FLIES)
- {
- CL_FlyEffect (cent, ent.origin);
- }
- else if (effects & EF_BFG)
- {
+ } else if (effects & EF_FLIES) {
+ CL_FlyEffect(cent, ent.origin);
+ } else if (effects & EF_BFG) {
if (effects & EF_ANIM_ALLFAST) {
- CL_BfgParticles (&ent);
+ CL_BfgParticles(&ent);
#if USE_DLIGHTS
i = 200;
} else {
static const int bfg_lightramp[6] = {300, 400, 600, 300, 150, 75};
- i = s1->frame; clamp( i, 0, 5 );
+ i = s1->frame; clamp(i, 0, 5);
i = bfg_lightramp[i];
#endif
}
- V_AddLight (ent.origin, i, 0, 1, 0);
+ V_AddLight(ent.origin, i, 0, 1, 0);
}
// RAFAEL
- else if (effects & EF_TRAP)
- {
+ else if (effects & EF_TRAP) {
ent.origin[2] += 32;
- CL_TrapParticles (&ent);
+ CL_TrapParticles(&ent);
#if USE_DLIGHTS
- i = (rand()%100) + 100;
- V_AddLight (ent.origin, i, 1, 0.8, 0.1);
+ i = (rand() % 100) + 100;
+ V_AddLight(ent.origin, i, 1, 0.8, 0.1);
#endif
- }
- else if (effects & EF_FLAG1)
- {
- CL_FlagTrail (cent->lerp_origin, ent.origin, 242);
- V_AddLight (ent.origin, 225, 1, 0.1, 0.1);
- }
- else if (effects & EF_FLAG2)
- {
- CL_FlagTrail (cent->lerp_origin, ent.origin, 115);
- V_AddLight (ent.origin, 225, 0.1, 0.1, 1);
+ } else if (effects & EF_FLAG1) {
+ CL_FlagTrail(cent->lerp_origin, ent.origin, 242);
+ V_AddLight(ent.origin, 225, 1, 0.1, 0.1);
+ } else if (effects & EF_FLAG2) {
+ CL_FlagTrail(cent->lerp_origin, ent.origin, 115);
+ V_AddLight(ent.origin, 225, 0.1, 0.1, 1);
}
//======
//ROGUE
- else if (effects & EF_TAGTRAIL)
- {
- CL_TagTrail (cent->lerp_origin, ent.origin, 220);
- V_AddLight (ent.origin, 225, 1.0, 1.0, 0.0);
- }
- else if (effects & EF_TRACKERTRAIL)
- {
- if (effects & EF_TRACKER)
- {
+ else if (effects & EF_TAGTRAIL) {
+ CL_TagTrail(cent->lerp_origin, ent.origin, 220);
+ V_AddLight(ent.origin, 225, 1.0, 1.0, 0.0);
+ } else if (effects & EF_TRACKERTRAIL) {
+ if (effects & EF_TRACKER) {
#if USE_DLIGHTS
float intensity;
- intensity = 50 + (500 * (sin(cl.time/500.0) + 1.0));
- V_AddLight (ent.origin, intensity, -1.0, -1.0, -1.0);
+ intensity = 50 + (500 * (sin(cl.time / 500.0) + 1.0));
+ V_AddLight(ent.origin, intensity, -1.0, -1.0, -1.0);
#endif
+ } else {
+ CL_Tracker_Shell(cent->lerp_origin);
+ V_AddLight(ent.origin, 155, -1.0, -1.0, -1.0);
}
- else
- {
- CL_Tracker_Shell (cent->lerp_origin);
- V_AddLight (ent.origin, 155, -1.0, -1.0, -1.0);
- }
- }
- else if (effects & EF_TRACKER)
- {
- CL_TrackerTrail (cent->lerp_origin, ent.origin, 0);
+ } else if (effects & EF_TRACKER) {
+ CL_TrackerTrail(cent->lerp_origin, ent.origin, 0);
// FIXME - check out this effect in rendition
- V_AddLight (ent.origin, 200, -1, -1, -1);
+ V_AddLight(ent.origin, 200, -1, -1, -1);
}
//ROGUE
//======
// RAFAEL
- else if (effects & EF_GREENGIB)
- {
- CL_DiminishingTrail (cent->lerp_origin, ent.origin, cent, effects);
+ else if (effects & EF_GREENGIB) {
+ CL_DiminishingTrail(cent->lerp_origin, ent.origin, cent, effects);
}
// RAFAEL
- else if (effects & EF_IONRIPPER)
- {
- CL_IonripperTrail (cent->lerp_origin, ent.origin);
- V_AddLight (ent.origin, 100, 1, 0.5, 0.5);
+ else if (effects & EF_IONRIPPER) {
+ CL_IonripperTrail(cent->lerp_origin, ent.origin);
+ V_AddLight(ent.origin, 100, 1, 0.5, 0.5);
}
// RAFAEL
- else if (effects & EF_BLUEHYPERBLASTER)
- {
- V_AddLight (ent.origin, 200, 0, 0, 1);
+ else if (effects & EF_BLUEHYPERBLASTER) {
+ V_AddLight(ent.origin, 200, 0, 0, 1);
}
// RAFAEL
- else if (effects & EF_PLASMA)
- {
- if (effects & EF_ANIM_ALLFAST)
- {
- CL_BlasterTrail (cent->lerp_origin, ent.origin);
+ else if (effects & EF_PLASMA) {
+ if (effects & EF_ANIM_ALLFAST) {
+ CL_BlasterTrail(cent->lerp_origin, ent.origin);
}
- V_AddLight (ent.origin, 130, 1, 0.5, 0.5);
+ V_AddLight(ent.origin, 130, 1, 0.5, 0.5);
}
}
skip:
- VectorCopy (ent.origin, cent->lerp_origin);
+ VectorCopy(ent.origin, cent->lerp_origin);
}
}
-static int shell_effect_hack( void ) {
+static int shell_effect_hack(void)
+{
centity_t *ent;
int flags = 0;
- if( cl.frame.clientNum == CLIENTNUM_NONE )
+ if (cl.frame.clientNum == CLIENTNUM_NONE)
return 0;
ent = &cl_entities[cl.frame.clientNum + 1];
- if( ent->serverframe != cl.frame.number )
+ if (ent->serverframe != cl.frame.number)
return 0;
- if( !ent->current.modelindex )
+ if (!ent->current.modelindex)
return 0;
if (ent->current.effects & EF_PENT)
@@ -977,17 +926,18 @@ static int shell_effect_hack( void ) {
CL_AddViewWeapon
==============
*/
-static void CL_AddViewWeapon( void ) {
+static void CL_AddViewWeapon(void)
+{
player_state_t *ps, *ops;
entity_t gun; // view model
int i, flags;
// allow the gun to be completely removed
- if( cl_gun->integer < 1 ) {
+ if (cl_gun->integer < 1) {
return;
}
- if( info_hand->integer == 2 ) {
+ if (info_hand->integer == 2) {
return;
}
@@ -995,39 +945,39 @@ static void CL_AddViewWeapon( void ) {
ps = CL_KEYPS;
ops = CL_OLDKEYPS;
- memset( &gun, 0, sizeof( gun ) );
+ memset(&gun, 0, sizeof(gun));
- if( gun_model ) {
+ if (gun_model) {
gun.model = gun_model; // development tool
} else {
gun.model = cl.model_draw[ps->gunindex];
}
- if( !gun.model ) {
+ if (!gun.model) {
return;
}
// set up gun position
- for( i = 0; i < 3; i++ ) {
- gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i]
- + CL_KEYLERPFRAC * (ps->gunoffset[i] - ops->gunoffset[i]);
- gun.angles[i] = cl.refdef.viewangles[i] + LerpAngle( ops->gunangles[i],
- ps->gunangles[i], CL_KEYLERPFRAC );
+ for (i = 0; i < 3; i++) {
+ gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i] +
+ CL_KEYLERPFRAC * (ps->gunoffset[i] - ops->gunoffset[i]);
+ gun.angles[i] = cl.refdef.viewangles[i] + LerpAngle(ops->gunangles[i],
+ ps->gunangles[i], CL_KEYLERPFRAC);
}
// adjust for high fov
- if( ps->fov > 90 ) {
- vec_t ofs = ( 90 - ps->fov ) * 0.2f;
- VectorMA( gun.origin, ofs, cl.v_forward, gun.origin );
+ if (ps->fov > 90) {
+ vec_t ofs = (90 - ps->fov) * 0.2f;
+ VectorMA(gun.origin, ofs, cl.v_forward, gun.origin);
}
- VectorCopy( gun.origin, gun.oldorigin ); // don't lerp at all
+ VectorCopy(gun.origin, gun.oldorigin); // don't lerp at all
- if( gun_frame ) {
+ if (gun_frame) {
gun.frame = gun_frame; // development tool
gun.oldframe = gun_frame; // development tool
} else {
gun.frame = ps->gunframe;
- if( gun.frame == 0 ) {
+ if (gun.frame == 0) {
gun.oldframe = 0; // just changed weapons, don't lerp from old
} else {
gun.oldframe = ops->gunframe;
@@ -1036,40 +986,41 @@ static void CL_AddViewWeapon( void ) {
}
gun.flags = RF_MINLIGHT | RF_DEPTHHACK | RF_WEAPONMODEL;
- if( info_hand->integer == 1 ) {
+ if (info_hand->integer == 1) {
gun.flags |= RF_LEFTHAND;
}
- if( cl_gunalpha->value != 1 ) {
- gun.alpha = Cvar_ClampValue( cl_gunalpha, 0.1f, 1.0f );
+ if (cl_gunalpha->value != 1) {
+ gun.alpha = Cvar_ClampValue(cl_gunalpha, 0.1f, 1.0f);
gun.flags |= RF_TRANSLUCENT;
}
- V_AddEntity( &gun );
+ V_AddEntity(&gun);
// add shell effect from player entity
flags = shell_effect_hack();
- if( flags ) {
+ if (flags) {
gun.alpha = 0.30f * cl_gunalpha->value;
gun.flags |= flags | RF_TRANSLUCENT;
- V_AddEntity( &gun );
+ V_AddEntity(&gun);
}
}
-static void CL_SetupFirstPersonView( void ) {
+static void CL_SetupFirstPersonView(void)
+{
player_state_t *ps, *ops;
vec3_t kickangles;
float lerp;
// add kick angles
- if( cl_kickangles->integer ) {
+ if (cl_kickangles->integer) {
ps = CL_KEYPS;
ops = CL_OLDKEYPS;
lerp = CL_KEYLERPFRAC;
- LerpAngles( ops->kick_angles, ps->kick_angles, lerp, kickangles );
- VectorAdd( cl.refdef.viewangles, kickangles, cl.refdef.viewangles );
+ LerpAngles(ops->kick_angles, ps->kick_angles, lerp, kickangles);
+ VectorAdd(cl.refdef.viewangles, kickangles, cl.refdef.viewangles);
}
// add the weapon
@@ -1083,7 +1034,8 @@ static void CL_SetupFirstPersonView( void ) {
CL_SetupThirdPersionView
===============
*/
-static void CL_SetupThirdPersionView( void ) {
+static void CL_SetupThirdPersionView(void)
+{
vec3_t focus;
float fscale, rscale;
float dist, angle, range;
@@ -1091,54 +1043,55 @@ static void CL_SetupThirdPersionView( void ) {
static vec3_t mins = { -4, -4, -4 }, maxs = { 4, 4, 4 };
// if dead, set a nice view angle
- if( cl.frame.ps.stats[STAT_HEALTH] <= 0 ) {
+ if (cl.frame.ps.stats[STAT_HEALTH] <= 0) {
cl.refdef.viewangles[ROLL] = 0;
cl.refdef.viewangles[PITCH] = 10;
}
- VectorMA( cl.refdef.vieworg, 512, cl.v_forward, focus );
+ VectorMA(cl.refdef.vieworg, 512, cl.v_forward, focus);
cl.refdef.vieworg[2] += 8;
cl.refdef.viewangles[PITCH] *= 0.5f;
- AngleVectors( cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up );
+ AngleVectors(cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
- angle = DEG2RAD( cl_thirdperson_angle->value );
+ angle = DEG2RAD(cl_thirdperson_angle->value);
range = cl_thirdperson_range->value;
- fscale = cos( angle );
- rscale = sin( angle );
- VectorMA( cl.refdef.vieworg, -range * fscale, cl.v_forward, cl.refdef.vieworg );
- VectorMA( cl.refdef.vieworg, -range * rscale, cl.v_right, cl.refdef.vieworg );
-
- CM_BoxTrace( &trace, cl.playerEntityOrigin, cl.refdef.vieworg,
- mins, maxs, cl.bsp->nodes, MASK_SOLID );
- if( trace.fraction != 1.0f ) {
- VectorCopy( trace.endpos, cl.refdef.vieworg );
+ fscale = cos(angle);
+ rscale = sin(angle);
+ VectorMA(cl.refdef.vieworg, -range * fscale, cl.v_forward, cl.refdef.vieworg);
+ VectorMA(cl.refdef.vieworg, -range * rscale, cl.v_right, cl.refdef.vieworg);
+
+ CM_BoxTrace(&trace, cl.playerEntityOrigin, cl.refdef.vieworg,
+ mins, maxs, cl.bsp->nodes, MASK_SOLID);
+ if (trace.fraction != 1.0f) {
+ VectorCopy(trace.endpos, cl.refdef.vieworg);
}
- VectorSubtract( focus, cl.refdef.vieworg, focus );
- dist = sqrt( focus[0] * focus[0] + focus[1] * focus[1] );
+ VectorSubtract(focus, cl.refdef.vieworg, focus);
+ dist = sqrt(focus[0] * focus[0] + focus[1] * focus[1]);
- cl.refdef.viewangles[PITCH] = -180 / M_PI * atan2( focus[2], dist );
+ cl.refdef.viewangles[PITCH] = -180 / M_PI * atan2(focus[2], dist);
cl.refdef.viewangles[YAW] -= cl_thirdperson_angle->value;
cl.thirdPersonView = qtrue;
}
-static void CL_FinishViewValues( void ) {
+static void CL_FinishViewValues(void)
+{
centity_t *ent;
- if( !cl_thirdperson->integer )
+ if (!cl_thirdperson->integer)
goto first;
- if( cl.frame.clientNum == CLIENTNUM_NONE )
+ if (cl.frame.clientNum == CLIENTNUM_NONE)
goto first;
ent = &cl_entities[cl.frame.clientNum + 1];
- if( ent->serverframe != cl.frame.number )
+ if (ent->serverframe != cl.frame.number)
goto first;
- if( !ent->current.modelindex )
+ if (!ent->current.modelindex)
goto first;
CL_SetupThirdPersionView();
@@ -1149,12 +1102,13 @@ first:
}
#if USE_SMOOTH_DELTA_ANGLES
-static inline float LerpShort( int a2, int a1, float frac ) {
+static inline float LerpShort(int a2, int a1, float frac)
+{
if (a1 - a2 > 32768)
a1 &= 65536;
if (a2 - a1 > 32768)
a1 &= 65536;
- return a2 + frac * ( a1 - a2 );
+ return a2 + frac * (a1 - a2);
}
#endif
@@ -1167,7 +1121,8 @@ Usually called from CL_AddEntities, but may be directly called from the main
loop if rendering is disabled but sound is running.
===============
*/
-void CL_CalcViewValues( void ) {
+void CL_CalcViewValues(void)
+{
player_state_t *ps, *ops;
vec3_t viewoffset;
float fov, lerp;
@@ -1179,71 +1134,71 @@ void CL_CalcViewValues( void ) {
lerp = cl.lerpfrac;
// calculate the origin
- if( !cls.demo.playback && cl_predict->integer && !( ps->pmove.pm_flags & PMF_NO_PREDICTION ) ) {
+ if (!cls.demo.playback && cl_predict->integer && !(ps->pmove.pm_flags & PMF_NO_PREDICTION)) {
// use predicted values
unsigned delta = cls.realtime - cl.predicted_step_time;
float backlerp = lerp - 1.0;
- VectorMA( cl.predicted_origin, backlerp, cl.prediction_error, cl.refdef.vieworg );
-
+ VectorMA(cl.predicted_origin, backlerp, cl.prediction_error, cl.refdef.vieworg);
+
// smooth out stair climbing
- if( cl.predicted_step < 16 ) {
+ if (cl.predicted_step < 16) {
delta <<= 1; // small steps
}
- if( delta < 100 ) {
- cl.refdef.vieworg[2] -= cl.predicted_step * ( 100 - delta ) * 0.01f;
+ if (delta < 100) {
+ cl.refdef.vieworg[2] -= cl.predicted_step * (100 - delta) * 0.01f;
}
- } else {
+ } else {
// just use interpolated values
cl.refdef.vieworg[0] = ops->pmove.origin[0] * 0.125f +
- lerp * ( ps->pmove.origin[0] - ops->pmove.origin[0] ) * 0.125f;
+ lerp * (ps->pmove.origin[0] - ops->pmove.origin[0]) * 0.125f;
cl.refdef.vieworg[1] = ops->pmove.origin[1] * 0.125f +
- lerp * ( ps->pmove.origin[1] - ops->pmove.origin[1] ) * 0.125f;
+ lerp * (ps->pmove.origin[1] - ops->pmove.origin[1]) * 0.125f;
cl.refdef.vieworg[2] = ops->pmove.origin[2] * 0.125f +
- lerp * ( ps->pmove.origin[2] - ops->pmove.origin[2] ) * 0.125f;
+ lerp * (ps->pmove.origin[2] - ops->pmove.origin[2]) * 0.125f;
}
// if not running a demo or on a locked frame, add the local angle movement
- if( cls.demo.playback ) {
- if( cls.key_dest == KEY_GAME && Key_IsDown( K_SHIFT ) ) {
- VectorCopy( cl.viewangles, cl.refdef.viewangles );
+ if (cls.demo.playback) {
+ if (cls.key_dest == KEY_GAME && Key_IsDown(K_SHIFT)) {
+ VectorCopy(cl.viewangles, cl.refdef.viewangles);
} else {
- LerpAngles( ops->viewangles, ps->viewangles, lerp,
- cl.refdef.viewangles );
+ LerpAngles(ops->viewangles, ps->viewangles, lerp,
+ cl.refdef.viewangles);
}
- } else if( ps->pmove.pm_type < PM_DEAD ) {
+ } else if (ps->pmove.pm_type < PM_DEAD) {
// use predicted values
- VectorCopy( cl.predicted_angles, cl.refdef.viewangles );
- } else if( ops->pmove.pm_type < PM_DEAD && cls.serverProtocol > PROTOCOL_VERSION_DEFAULT ) {
+ VectorCopy(cl.predicted_angles, cl.refdef.viewangles);
+ } else if (ops->pmove.pm_type < PM_DEAD && cls.serverProtocol > PROTOCOL_VERSION_DEFAULT) {
// lerp from predicted angles, since enhanced servers
// do not send viewangles each frame
- LerpAngles( cl.predicted_angles, ps->viewangles, lerp, cl.refdef.viewangles );
+ LerpAngles(cl.predicted_angles, ps->viewangles, lerp, cl.refdef.viewangles);
} else {
// just use interpolated values
- LerpAngles( ops->viewangles, ps->viewangles, lerp, cl.refdef.viewangles );
+ LerpAngles(ops->viewangles, ps->viewangles, lerp, cl.refdef.viewangles);
}
-
+
#if USE_SMOOTH_DELTA_ANGLES
- cl.delta_angles[0] = LerpShort( ops->pmove.delta_angles[0], ps->pmove.delta_angles[0], lerp );
- cl.delta_angles[1] = LerpShort( ops->pmove.delta_angles[1], ps->pmove.delta_angles[1], lerp );
- cl.delta_angles[2] = LerpShort( ops->pmove.delta_angles[2], ps->pmove.delta_angles[2], lerp );
+ cl.delta_angles[0] = LerpShort(ops->pmove.delta_angles[0], ps->pmove.delta_angles[0], lerp);
+ cl.delta_angles[1] = LerpShort(ops->pmove.delta_angles[1], ps->pmove.delta_angles[1], lerp);
+ cl.delta_angles[2] = LerpShort(ops->pmove.delta_angles[2], ps->pmove.delta_angles[2], lerp);
#endif
- if( cls.demo.playback && ( info_uf->integer & UF_LOCALFOV ) ) {
+ if (cls.demo.playback && (info_uf->integer & UF_LOCALFOV)) {
fov = info_fov->value;
- if( fov < 1 ) {
+ if (fov < 1) {
fov = 90;
- } else if( fov > 160 ) {
+ } else if (fov > 160) {
fov = 160;
}
cl.fov_x = fov;
} else {
// interpolate field of view
- cl.fov_x = ops->fov + lerp * ( ps->fov - ops->fov );
+ cl.fov_x = ops->fov + lerp * (ps->fov - ops->fov);
}
// don't interpolate blend color
- Vector4Copy( ps->blend, cl.refdef.blend );
+ Vector4Copy(ps->blend, cl.refdef.blend);
#if USE_FPS
ps = &cl.keyframe.ps;
@@ -1252,25 +1207,25 @@ void CL_CalcViewValues( void ) {
lerp = cl.keylerpfrac;
#endif
- LerpVector( ops->viewoffset, ps->viewoffset, lerp, viewoffset );
+ LerpVector(ops->viewoffset, ps->viewoffset, lerp, viewoffset);
- AngleVectors( cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up );
+ AngleVectors(cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
- VectorCopy( cl.refdef.vieworg, cl.playerEntityOrigin );
- VectorCopy( cl.refdef.viewangles, cl.playerEntityAngles );
+ VectorCopy(cl.refdef.vieworg, cl.playerEntityOrigin);
+ VectorCopy(cl.refdef.viewangles, cl.playerEntityAngles);
- if( cl.playerEntityAngles[PITCH] > 180 ) {
+ if (cl.playerEntityAngles[PITCH] > 180) {
cl.playerEntityAngles[PITCH] -= 360;
}
cl.playerEntityAngles[PITCH] = cl.playerEntityAngles[PITCH] / 3;
- VectorAdd( cl.refdef.vieworg, viewoffset, cl.refdef.vieworg );
+ VectorAdd(cl.refdef.vieworg, viewoffset, cl.refdef.vieworg);
- VectorCopy( cl.refdef.vieworg, listener_origin );
- VectorCopy( cl.v_forward, listener_forward );
- VectorCopy( cl.v_right, listener_right );
- VectorCopy( cl.v_up, listener_up );
+ VectorCopy(cl.refdef.vieworg, listener_origin);
+ VectorCopy(cl.v_forward, listener_forward);
+ VectorCopy(cl.v_right, listener_right);
+ VectorCopy(cl.v_up, listener_up);
}
/*
@@ -1280,7 +1235,8 @@ CL_AddEntities
Emits all entities, particles, and lights to the refresh
===============
*/
-void CL_AddEntities( void ) {
+void CL_AddEntities(void)
+{
CL_CalcViewValues();
CL_FinishViewValues();
CL_AddPacketEntities();
@@ -1302,32 +1258,33 @@ CL_GetEntitySoundOrigin
Called to get the sound spatialization origin
===============
*/
-void CL_GetEntitySoundOrigin( int entnum, vec3_t org ) {
+void CL_GetEntitySoundOrigin(int entnum, vec3_t org)
+{
centity_t *ent;
mmodel_t *cm;
vec3_t mid;
- if( entnum < 0 || entnum >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad entnum: %d", __func__, entnum );
+ if (entnum < 0 || entnum >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad entnum: %d", __func__, entnum);
}
- if( !entnum || entnum == listener_entnum ) {
+ if (!entnum || entnum == listener_entnum) {
// should this ever happen?
- VectorCopy( listener_origin, org );
+ VectorCopy(listener_origin, org);
return;
}
// interpolate origin
// FIXME: what should be the sound origin point for RF_BEAM entities?
ent = &cl_entities[entnum];
- LerpVector( ent->prev.origin, ent->current.origin, cl.lerpfrac, org );
+ LerpVector(ent->prev.origin, ent->current.origin, cl.lerpfrac, org);
// offset the origin for BSP models
- if( ent->current.solid == PACKED_BSP ) {
+ if (ent->current.solid == PACKED_BSP) {
cm = cl.model_clip[ent->current.modelindex];
- if( cm ) {
- VectorAvg( cm->mins, cm->maxs, mid );
- VectorAdd( org, mid, org );
+ if (cm) {
+ VectorAvg(cm->mins, cm->maxs, mid);
+ VectorAdd(org, mid, org);
}
}
}
diff --git a/src/cl_fx.c b/src/cl_fx.c
index 8bffad1..bf0e69c 100644
--- a/src/cl_fx.c
+++ b/src/cl_fx.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_local.h"
-void CL_LogoutEffect (vec3_t org, int type);
-void CL_ItemRespawnParticles (vec3_t org);
+void CL_LogoutEffect(vec3_t org, int type);
+void CL_ItemRespawnParticles(vec3_t org);
static vec3_t avelocities[NUMVERTEXNORMALS];
@@ -44,12 +44,13 @@ typedef struct clightstyle_s {
} clightstyle_t;
static clightstyle_t cl_lightstyles[MAX_LIGHTSTYLES];
-static LIST_DECL( cl_lightlist );
+static LIST_DECL(cl_lightlist);
static int cl_lastofs;
-void CL_ClearLightStyles( void ) {
- memset( cl_lightstyles, 0, sizeof( cl_lightstyles ) );
- List_Init( &cl_lightlist );
+void CL_ClearLightStyles(void)
+{
+ memset(cl_lightstyles, 0, sizeof(cl_lightstyles));
+ List_Init(&cl_lightlist);
cl_lastofs = -1;
}
@@ -58,45 +59,53 @@ void CL_ClearLightStyles( void ) {
CL_RunLightStyles
================
*/
-void CL_RunLightStyles( void ) {
+void CL_RunLightStyles(void)
+{
int ofs;
clightstyle_t *ls;
ofs = cl.time / 100;
- if( ofs == cl_lastofs )
+ if (ofs == cl_lastofs)
return;
cl_lastofs = ofs;
- LIST_FOR_EACH( clightstyle_t, ls, &cl_lightlist, entry ) {
- ls->value[0] = ls->value[1] = ls->value[2] = ls->value[3] =
- ls->map[ofs % ls->length];
+ LIST_FOR_EACH(clightstyle_t, ls, &cl_lightlist, entry) {
+ ls->value[0] =
+ ls->value[1] =
+ ls->value[2] =
+ ls->value[3] = ls->map[ofs % ls->length];
}
}
-void CL_SetLightStyle( int index, const char *s ) {
+void CL_SetLightStyle(int index, const char *s)
+{
int i;
- clightstyle_t *dest;
+ clightstyle_t *ls;
- dest = &cl_lightstyles[index];
- dest->length = strlen( s );
- if( dest->length > MAX_QPATH ) {
- Com_Error( ERR_DROP, "%s: oversize style", __func__ );
+ ls = &cl_lightstyles[index];
+ ls->length = strlen(s);
+ if (ls->length > MAX_QPATH) {
+ Com_Error(ERR_DROP, "%s: oversize style", __func__);
}
- for( i = 0; i < dest->length; i++ ) {
- dest->map[i] = ( float )( s[i] - 'a' ) / ( float )( 'm' - 'a' );
+ for (i = 0; i < ls->length; i++) {
+ ls->map[i] = (float)(s[i] - 'a') / (float)('m' - 'a');
}
- if( dest->entry.prev ) {
- List_Delete( &dest->entry );
+ if (ls->entry.prev) {
+ List_Delete(&ls->entry);
}
- if( dest->length > 1 ) {
- List_Append( &cl_lightlist, &dest->entry );
+ if (ls->length > 1) {
+ List_Append(&cl_lightlist, &ls->entry);
return;
}
- dest->value[0] = dest->value[1] = dest->value[2] = dest->value[3] = dest->map[0] = 1;
+ ls->value[0] =
+ ls->value[1] =
+ ls->value[2] =
+ ls->value[3] =
+ ls->map[0] = 1;
}
/*
@@ -104,12 +113,13 @@ void CL_SetLightStyle( int index, const char *s ) {
CL_AddLightStyles
================
*/
-void CL_AddLightStyles( void ) {
+void CL_AddLightStyles(void)
+{
int i;
clightstyle_t *ls;
- for( i = 0, ls = cl_lightstyles; i < MAX_LIGHTSTYLES; i++, ls++ )
- V_AddLightStyle( i, ls->value );
+ for (i = 0, ls = cl_lightstyles; i < MAX_LIGHTSTYLES; i++, ls++)
+ V_AddLightStyle(i, ls->value);
}
#endif
@@ -126,8 +136,9 @@ DLIGHT MANAGEMENT
static cdlight_t cl_dlights[MAX_DLIGHTS];
-static void clear_dlights (void) {
- memset (cl_dlights, 0, sizeof(cl_dlights));
+static void clear_dlights(void)
+{
+ memset(cl_dlights, 0, sizeof(cl_dlights));
}
/*
@@ -136,20 +147,17 @@ CL_AllocDlight
===============
*/
-cdlight_t *CL_AllocDlight (int key)
+cdlight_t *CL_AllocDlight(int key)
{
int i;
cdlight_t *dl;
// first look for an exact key match
- if (key)
- {
+ if (key) {
dl = cl_dlights;
- for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
- {
- if (dl->key == key)
- {
- memset (dl, 0, sizeof(*dl));
+ for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
+ if (dl->key == key) {
+ memset(dl, 0, sizeof(*dl));
dl->key = key;
return dl;
}
@@ -158,18 +166,16 @@ cdlight_t *CL_AllocDlight (int key)
// then look for anything else
dl = cl_dlights;
- for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
- {
- if (dl->die < cl.time)
- {
- memset (dl, 0, sizeof(*dl));
+ for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
+ if (dl->die < cl.time) {
+ memset(dl, 0, sizeof(*dl));
dl->key = key;
return dl;
}
}
dl = &cl_dlights[0];
- memset (dl, 0, sizeof(*dl));
+ memset(dl, 0, sizeof(*dl));
dl->key = key;
return dl;
}
@@ -180,24 +186,22 @@ CL_RunDLights
===============
*/
-void CL_RunDLights (void)
+void CL_RunDLights(void)
{
int i;
cdlight_t *dl;
dl = cl_dlights;
- for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
- {
+ for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (!dl->radius)
continue;
-
- if (dl->die < cl.time)
- {
+
+ if (dl->die < cl.time) {
dl->radius = 0;
return;
}
#if 0
- dl->radius -= cls.frametime*dl->decay;
+ dl->radius -= cls.frametime * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
#endif
@@ -210,18 +214,17 @@ CL_AddDLights
===============
*/
-void CL_AddDLights (void)
+void CL_AddDLights(void)
{
int i;
cdlight_t *dl;
dl = cl_dlights;
- for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
- {
+ for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (!dl->radius)
continue;
- V_AddLight (dl->origin, dl->radius,
- dl->color[0], dl->color[1], dl->color[2]);
+ V_AddLight(dl->origin, dl->radius,
+ dl->color[0], dl->color[1], dl->color[2]);
}
}
@@ -234,7 +237,7 @@ void CL_AddDLights (void)
CL_MuzzleFlash
==============
*/
-void CL_MuzzleFlash (void)
+void CL_MuzzleFlash(void)
{
#if USE_DLIGHTS
vec3_t fv, rv;
@@ -245,29 +248,29 @@ void CL_MuzzleFlash (void)
char soundname[MAX_QPATH];
#ifdef _DEBUG
- if( developer->integer )
- CL_CheckEntityPresent( mz.entity, "muzzleflash" );
+ if (developer->integer)
+ CL_CheckEntityPresent(mz.entity, "muzzleflash");
#endif
pl = &cl_entities[mz.entity];
#if USE_DLIGHTS
- dl = CL_AllocDlight (mz.entity);
- VectorCopy (pl->current.origin, dl->origin);
- AngleVectors (pl->current.angles, fv, rv, NULL);
- VectorMA (dl->origin, 18, fv, dl->origin);
- VectorMA (dl->origin, 16, rv, dl->origin);
+ dl = CL_AllocDlight(mz.entity);
+ VectorCopy(pl->current.origin, dl->origin);
+ AngleVectors(pl->current.angles, fv, rv, NULL);
+ VectorMA(dl->origin, 18, fv, dl->origin);
+ VectorMA(dl->origin, 16, rv, dl->origin);
if (mz.silenced)
- dl->radius = 100 + (rand()&31);
+ dl->radius = 100 + (rand() & 31);
else
- dl->radius = 200 + (rand()&31);
+ dl->radius = 200 + (rand() & 31);
//dl->minlight = 32;
dl->die = cl.time; // + 0.1;
-#define DL_COLOR(r,g,b) VectorSet(dl->color,r,g,b)
-#define DL_RADIUS(r) (dl->radius=r)
-#define DL_DIE(t) (dl->die=cl.time+t)
+#define DL_COLOR(r, g, b) VectorSet(dl->color, r, g, b)
+#define DL_RADIUS(r) (dl->radius = r)
+#define DL_DIE(t) (dl->die = cl.time + t)
#else
-#define DL_COLOR(r,g,b)
+#define DL_COLOR(r, g, b)
#define DL_RADIUS(r)
#define DL_DIE(t)
#endif
@@ -277,147 +280,146 @@ void CL_MuzzleFlash (void)
else
volume = 1;
- switch (mz.weapon)
- {
+ switch (mz.weapon) {
case MZ_BLASTER:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/blastf1a.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/blastf1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_BLUEHYPERBLASTER:
- DL_COLOR(0,0,1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/hyprbf1a.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(0, 0, 1);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/hyprbf1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_HYPERBLASTER:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/hyprbf1a.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/hyprbf1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_MACHINEGUN:
- DL_COLOR(1,1,0);
+ DL_COLOR(1, 1, 0);
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
break;
case MZ_SHOTGUN:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/shotgf1b.wav"), volume, ATTN_NORM, 0);
- S_StartSound (NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/shotgr1b.wav"), volume, ATTN_NORM, 0.1);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/shotgf1b.wav"), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/shotgr1b.wav"), volume, ATTN_NORM, 0.1);
break;
case MZ_SSHOTGUN:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/sshotf1b.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/sshotf1b.wav"), volume, ATTN_NORM, 0);
break;
case MZ_CHAINGUN1:
- DL_RADIUS(200 + (rand()&31));
- DL_COLOR(1,0.25,0);
+ DL_RADIUS(200 + (rand() & 31));
+ DL_COLOR(1, 0.25, 0);
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
break;
case MZ_CHAINGUN2:
- DL_RADIUS(225 + (rand()&31));
- DL_COLOR(1,0.5,0);
+ DL_RADIUS(225 + (rand() & 31));
+ DL_COLOR(1, 0.5, 0);
DL_DIE(0.1); // long delay
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.05);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.05);
break;
case MZ_CHAINGUN3:
- DL_RADIUS(250 + (rand()&31));
- DL_COLOR(1,1,0);
+ DL_RADIUS(250 + (rand() & 31));
+ DL_COLOR(1, 1, 0);
DL_DIE(0.1); // long delay
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0);
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.033);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.033);
Q_snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.066);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), volume, ATTN_NORM, 0.066);
break;
case MZ_RAILGUN:
- DL_COLOR(0.5,0.5,1.0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/railgf1a.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(0.5, 0.5, 1.0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/railgf1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_ROCKET:
- DL_COLOR(1,0.5,0.2);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/rocklf1a.wav"), volume, ATTN_NORM, 0);
- S_StartSound (NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/rocklr1b.wav"), volume, ATTN_NORM, 0.1);
+ DL_COLOR(1, 0.5, 0.2);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/rocklf1a.wav"), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/rocklr1b.wav"), volume, ATTN_NORM, 0.1);
break;
case MZ_GRENADE:
- DL_COLOR(1,0.5,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), volume, ATTN_NORM, 0);
- S_StartSound (NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/grenlr1b.wav"), volume, ATTN_NORM, 0.1);
+ DL_COLOR(1, 0.5, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_AUTO, S_RegisterSound("weapons/grenlr1b.wav"), volume, ATTN_NORM, 0.1);
break;
case MZ_BFG:
- DL_COLOR(0,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/bfg__f1y.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(0, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/bfg__f1y.wav"), volume, ATTN_NORM, 0);
break;
case MZ_LOGIN:
- DL_COLOR(0,1,0);
+ DL_COLOR(0, 1, 0);
DL_DIE(1.0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
- CL_LogoutEffect (pl->current.origin, mz.weapon);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
+ CL_LogoutEffect(pl->current.origin, mz.weapon);
break;
case MZ_LOGOUT:
- DL_COLOR(1,0,0);
+ DL_COLOR(1, 0, 0);
DL_DIE(1.0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
- CL_LogoutEffect (pl->current.origin, mz.weapon);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
+ CL_LogoutEffect(pl->current.origin, mz.weapon);
break;
case MZ_RESPAWN:
- DL_COLOR(1,1,0);
+ DL_COLOR(1, 1, 0);
DL_DIE(1.0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
- CL_LogoutEffect (pl->current.origin, mz.weapon);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/grenlf1a.wav"), 1, ATTN_NORM, 0);
+ CL_LogoutEffect(pl->current.origin, mz.weapon);
break;
- // RAFAEL
+ // RAFAEL
case MZ_PHALANX:
- DL_COLOR(1,0.5,0.5);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/plasshot.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(1, 0.5, 0.5);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/plasshot.wav"), volume, ATTN_NORM, 0);
break;
- // RAFAEL
- case MZ_IONRIPPER:
- DL_COLOR(1,0.5,0.5);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/rippfiref.wav"), volume, ATTN_NORM, 0);
+ // RAFAEL
+ case MZ_IONRIPPER:
+ DL_COLOR(1, 0.5, 0.5);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/rippfiref.wav"), volume, ATTN_NORM, 0);
break;
// ======================
// PGM
case MZ_ETF_RIFLE:
- DL_COLOR(0.9,0.7,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/nail1.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(0.9, 0.7, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/nail1.wav"), volume, ATTN_NORM, 0);
break;
case MZ_SHOTGUN2:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/shotg2.wav"), volume, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/shotg2.wav"), volume, ATTN_NORM, 0);
break;
case MZ_HEATBEAM:
- DL_COLOR(1,1,0);
+ DL_COLOR(1, 1, 0);
DL_DIE(100);
// S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/bfg__l1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_BLASTER2:
- DL_COLOR(0,1,0);
+ DL_COLOR(0, 1, 0);
// FIXME - different sound for blaster2 ??
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/blastf1a.wav"), volume, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/blastf1a.wav"), volume, ATTN_NORM, 0);
break;
case MZ_TRACKER:
// negative flashes handled the same in gl/soft until CL_AddDLights
- DL_COLOR(-1,-1,-1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/disint2.wav"), volume, ATTN_NORM, 0);
- break;
+ DL_COLOR(-1, -1, -1);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/disint2.wav"), volume, ATTN_NORM, 0);
+ break;
case MZ_NUKE1:
- DL_COLOR(1,0,0);
+ DL_COLOR(1, 0, 0);
DL_DIE(100);
break;
case MZ_NUKE2:
- DL_COLOR(1,1,0);
+ DL_COLOR(1, 1, 0);
DL_DIE(100);
break;
case MZ_NUKE4:
- DL_COLOR(0,0,1);
+ DL_COLOR(0, 0, 1);
DL_DIE(100);
break;
case MZ_NUKE8:
- DL_COLOR(0,1,1);
+ DL_COLOR(0, 1, 1);
DL_DIE(100);
break;
// PGM
@@ -431,7 +433,7 @@ void CL_MuzzleFlash (void)
CL_MuzzleFlash2
==============
*/
-void CL_MuzzleFlash2 (void)
+void CL_MuzzleFlash2(void)
{
centity_t *ent;
vec3_t origin;
@@ -444,22 +446,21 @@ void CL_MuzzleFlash2 (void)
// locate the origin
ent = &cl_entities[mz.entity];
- AngleVectors (ent->current.angles, forward, right, NULL);
+ AngleVectors(ent->current.angles, forward, right, NULL);
ofs = monster_flash_offset[mz.weapon];
origin[0] = ent->current.origin[0] + forward[0] * ofs[0] + right[0] * ofs[1];
origin[1] = ent->current.origin[1] + forward[1] * ofs[0] + right[1] * ofs[1];
origin[2] = ent->current.origin[2] + forward[2] * ofs[0] + right[2] * ofs[1] + ofs[2];
#if USE_DLIGHTS
- dl = CL_AllocDlight (mz.entity);
- VectorCopy (origin, dl->origin);
- dl->radius = 200 + (rand()&31);
+ dl = CL_AllocDlight(mz.entity);
+ VectorCopy(origin, dl->origin);
+ dl->radius = 200 + (rand() & 31);
//dl->minlight = 32;
dl->die = cl.time; // + 0.1;
#endif
- switch (mz.weapon)
- {
+ switch (mz.weapon) {
case MZ2_INFANTRY_MACHINEGUN_1:
case MZ2_INFANTRY_MACHINEGUN_2:
case MZ2_INFANTRY_MACHINEGUN_3:
@@ -473,10 +474,10 @@ void CL_MuzzleFlash2 (void)
case MZ2_INFANTRY_MACHINEGUN_11:
case MZ2_INFANTRY_MACHINEGUN_12:
case MZ2_INFANTRY_MACHINEGUN_13:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_SOLDIER_MACHINEGUN_1:
@@ -487,10 +488,10 @@ void CL_MuzzleFlash2 (void)
case MZ2_SOLDIER_MACHINEGUN_6:
case MZ2_SOLDIER_MACHINEGUN_7:
case MZ2_SOLDIER_MACHINEGUN_8:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck3.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck3.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_GUNNER_MACHINEGUN_1:
@@ -501,10 +502,10 @@ void CL_MuzzleFlash2 (void)
case MZ2_GUNNER_MACHINEGUN_6:
case MZ2_GUNNER_MACHINEGUN_7:
case MZ2_GUNNER_MACHINEGUN_8:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("gunner/gunatck2.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("gunner/gunatck2.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_ACTOR_MACHINEGUN_1:
@@ -515,10 +516,10 @@ void CL_MuzzleFlash2 (void)
case MZ2_SUPERTANK_MACHINEGUN_5:
case MZ2_SUPERTANK_MACHINEGUN_6:
case MZ2_TURRET_MACHINEGUN: // PGM
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_BOSS2_MACHINEGUN_L1:
@@ -528,10 +529,10 @@ void CL_MuzzleFlash2 (void)
case MZ2_BOSS2_MACHINEGUN_L5:
case MZ2_CARRIER_MACHINEGUN_L1: // PMM
case MZ2_CARRIER_MACHINEGUN_L2: // PMM
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NONE, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("infantry/infatck1.wav"), 1, ATTN_NONE, 0);
break;
case MZ2_SOLDIER_BLASTER_1:
@@ -543,29 +544,29 @@ void CL_MuzzleFlash2 (void)
case MZ2_SOLDIER_BLASTER_7:
case MZ2_SOLDIER_BLASTER_8:
case MZ2_TURRET_BLASTER: // PGM
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck2.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck2.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_FLYER_BLASTER_1:
case MZ2_FLYER_BLASTER_2:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("flyer/flyatck3.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("flyer/flyatck3.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_MEDIC_BLASTER_1:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("medic/medatck1.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("medic/medatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_HOVER_BLASTER_1:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("hover/hovatck1.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("hover/hovatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_FLOAT_BLASTER_1:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("floater/fltatck1.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("floater/fltatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_SOLDIER_SHOTGUN_1:
@@ -576,16 +577,16 @@ void CL_MuzzleFlash2 (void)
case MZ2_SOLDIER_SHOTGUN_6:
case MZ2_SOLDIER_SHOTGUN_7:
case MZ2_SOLDIER_SHOTGUN_8:
- DL_COLOR(1,1,0);
+ DL_COLOR(1, 1, 0);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck1.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("soldier/solatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_TANK_BLASTER_1:
case MZ2_TANK_BLASTER_2:
case MZ2_TANK_BLASTER_3:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck3.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck3.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_TANK_MACHINEGUN_1:
@@ -607,24 +608,24 @@ void CL_MuzzleFlash2 (void)
case MZ2_TANK_MACHINEGUN_17:
case MZ2_TANK_MACHINEGUN_18:
case MZ2_TANK_MACHINEGUN_19:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
Q_snprintf(soundname, sizeof(soundname), "tank/tnkatk2%c.wav", 'a' + rand() % 5);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound(soundname), 1, ATTN_NORM, 0);
break;
case MZ2_CHICK_ROCKET_1:
case MZ2_TURRET_ROCKET: // PGM
- DL_COLOR(1,0.5,0.2);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("chick/chkatck2.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 0.5, 0.2);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("chick/chkatck2.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_TANK_ROCKET_1:
case MZ2_TANK_ROCKET_2:
case MZ2_TANK_ROCKET_3:
- DL_COLOR(1,0.5,0.2);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck1.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 0.5, 0.2);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck1.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_SUPERTANK_ROCKET_1:
@@ -638,29 +639,29 @@ void CL_MuzzleFlash2 (void)
// case MZ2_CARRIER_ROCKET_2:
// case MZ2_CARRIER_ROCKET_3:
// case MZ2_CARRIER_ROCKET_4:
- DL_COLOR(1,0.5,0.2);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/rocket.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 0.5, 0.2);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/rocket.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_GUNNER_GRENADE_1:
case MZ2_GUNNER_GRENADE_2:
case MZ2_GUNNER_GRENADE_3:
case MZ2_GUNNER_GRENADE_4:
- DL_COLOR(1,0.5,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("gunner/gunatck3.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 0.5, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("gunner/gunatck3.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_GLADIATOR_RAILGUN_1:
- // PMM
+ // PMM
case MZ2_CARRIER_RAILGUN:
case MZ2_WIDOW_RAIL:
- // pmm
- DL_COLOR(0.5,0.5,1.0);
+ // pmm
+ DL_COLOR(0.5, 0.5, 1.0);
break;
// --- Xian's shit starts ---
case MZ2_MAKRON_BFG:
- DL_COLOR(0.5,1,0.5);
+ DL_COLOR(0.5, 1, 0.5);
//S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("makron/bfg_firef.wav"), 1, ATTN_NORM, 0);
break;
@@ -681,20 +682,20 @@ void CL_MuzzleFlash2 (void)
case MZ2_MAKRON_BLASTER_15:
case MZ2_MAKRON_BLASTER_16:
case MZ2_MAKRON_BLASTER_17:
- DL_COLOR(1,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("makron/blaster.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(1, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("makron/blaster.wav"), 1, ATTN_NORM, 0);
break;
-
+
case MZ2_JORG_MACHINEGUN_L1:
case MZ2_JORG_MACHINEGUN_L2:
case MZ2_JORG_MACHINEGUN_L3:
case MZ2_JORG_MACHINEGUN_L4:
case MZ2_JORG_MACHINEGUN_L5:
case MZ2_JORG_MACHINEGUN_L6:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("boss3/xfiref.wav"), 1, ATTN_NORM, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("boss3/xfiref.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_JORG_MACHINEGUN_R1:
@@ -703,13 +704,13 @@ void CL_MuzzleFlash2 (void)
case MZ2_JORG_MACHINEGUN_R4:
case MZ2_JORG_MACHINEGUN_R5:
case MZ2_JORG_MACHINEGUN_R6:
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
break;
case MZ2_JORG_BFG_1:
- DL_COLOR(0.5,1,0.5);
+ DL_COLOR(0.5, 1, 0.5);
break;
case MZ2_BOSS2_MACHINEGUN_R1:
@@ -719,8 +720,8 @@ void CL_MuzzleFlash2 (void)
case MZ2_BOSS2_MACHINEGUN_R5:
case MZ2_CARRIER_MACHINEGUN_R1: // PMM
case MZ2_CARRIER_MACHINEGUN_R2: // PMM
- DL_COLOR(1,1,0);
- CL_ParticleEffect (origin, vec3_origin, 0, 40);
+ DL_COLOR(1, 1, 0);
+ CL_ParticleEffect(origin, vec3_origin, 0, 40);
CL_SmokeAndFlash(origin);
break;
@@ -765,13 +766,13 @@ void CL_MuzzleFlash2 (void)
case MZ2_WIDOW_RUN_6:
case MZ2_WIDOW_RUN_7:
case MZ2_WIDOW_RUN_8:
- DL_COLOR(0,1,0);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck3.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(0, 1, 0);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("tank/tnkatck3.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_WIDOW_DISRUPTOR:
- DL_COLOR(-1,-1,-1);
- S_StartSound (NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/disint2.wav"), 1, ATTN_NORM, 0);
+ DL_COLOR(-1, -1, -1);
+ S_StartSound(NULL, mz.entity, CHAN_WEAPON, S_RegisterSound("weapons/disint2.wav"), 1, ATTN_NORM, 0);
break;
case MZ2_WIDOW_PLASMABEAM:
@@ -791,8 +792,8 @@ void CL_MuzzleFlash2 (void)
case MZ2_WIDOW2_BEAM_SWEEP_9:
case MZ2_WIDOW2_BEAM_SWEEP_10:
case MZ2_WIDOW2_BEAM_SWEEP_11:
- DL_RADIUS(300 + (rand()&100));
- DL_COLOR(1,1,0);
+ DL_RADIUS(300 + (rand() & 100));
+ DL_COLOR(1, 1, 0);
DL_DIE(200);
break;
// ROGUE
@@ -816,19 +817,20 @@ static cparticle_t *active_particles, *free_particles;
static cparticle_t particles[MAX_PARTICLES];
static const int cl_numparticles = MAX_PARTICLES;
-static void clear_particles (void)
+static void clear_particles(void)
{
int i;
-
+
free_particles = &particles[0];
active_particles = NULL;
- for (i=0 ;i<cl_numparticles ; i++)
- particles[i].next = &particles[i+1];
- particles[cl_numparticles-1].next = NULL;
+ for (i = 0; i < cl_numparticles; i++)
+ particles[i].next = &particles[i + 1];
+ particles[cl_numparticles - 1].next = NULL;
}
-cparticle_t *CL_AllocParticle( void ) {
+cparticle_t *CL_AllocParticle(void)
+{
cparticle_t *p;
if (!free_particles)
@@ -848,33 +850,31 @@ CL_ParticleEffect
Wall impact puffs
===============
*/
-void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count)
+void CL_ParticleEffect(vec3_t org, vec3_t dir, int color, int count)
{
int i, j;
cparticle_t *p;
float d;
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = color + (rand()&7);
+ p->color = color + (rand() & 7);
- d = rand()&31;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = crand()*20;
+ d = rand() & 31;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = crand() * 20;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
@@ -884,14 +884,13 @@ void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count)
CL_ParticleEffect2
===============
*/
-void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count)
+void CL_ParticleEffect2(vec3_t org, vec3_t dir, int color, int count)
{
int i, j;
cparticle_t *p;
float d;
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -899,18 +898,17 @@ void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count)
p->time = cl.time;
p->color = color;
- d = rand()&7;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = crand()*20;
+ d = rand() & 7;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = crand() * 20;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
@@ -920,13 +918,12 @@ void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count)
CL_TeleporterParticles
===============
*/
-void CL_TeleporterParticles (vec3_t org)
+void CL_TeleporterParticles(vec3_t org)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<8 ; i++)
- {
+ for (i = 0; i < 8; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -934,14 +931,13 @@ void CL_TeleporterParticles (vec3_t org)
p->time = cl.time;
p->color = 0xdb;
- for (j=0 ; j<2 ; j++)
- {
- p->org[j] = org[j] - 16 + (rand()&31);
- p->vel[j] = crand()*14;
+ for (j = 0; j < 2; j++) {
+ p->org[j] = org[j] - 16 + (rand() & 31);
+ p->vel[j] = crand() * 14;
}
- p->org[2] = org[2] - 8 + (rand()&7);
- p->vel[2] = 80 + (rand()&7);
+ p->org[2] = org[2] - 8 + (rand() & 7);
+ p->vel[2] = 80 + (rand() & 7);
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
@@ -958,13 +954,12 @@ CL_LogoutEffect
===============
*/
-void CL_LogoutEffect (vec3_t org, int type)
+void CL_LogoutEffect(vec3_t org, int type)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<500 ; i++)
- {
+ for (i = 0; i < 500; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -972,24 +967,24 @@ void CL_LogoutEffect (vec3_t org, int type)
p->time = cl.time;
if (type == MZ_LOGIN)
- p->color = 0xd0 + (rand()&7); // green
+ p->color = 0xd0 + (rand() & 7); // green
else if (type == MZ_LOGOUT)
- p->color = 0x40 + (rand()&7); // red
+ p->color = 0x40 + (rand() & 7); // red
else
- p->color = 0xe0 + (rand()&7); // yellow
+ p->color = 0xe0 + (rand() & 7); // yellow
- p->org[0] = org[0] - 16 + frand()*32;
- p->org[1] = org[1] - 16 + frand()*32;
- p->org[2] = org[2] - 24 + frand()*56;
+ p->org[0] = org[0] - 16 + frand() * 32;
+ p->org[1] = org[1] - 16 + frand() * 32;
+ p->org[2] = org[2] - 24 + frand() * 56;
- for (j=0 ; j<3 ; j++)
- p->vel[j] = crand()*20;
+ for (j = 0; j < 3; j++)
+ p->vel[j] = crand() * 20;
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1.0 + frand()*0.3);
+ p->alphavel = -1.0 / (1.0 + frand() * 0.3);
}
}
@@ -1000,33 +995,32 @@ CL_ItemRespawnParticles
===============
*/
-void CL_ItemRespawnParticles (vec3_t org)
+void CL_ItemRespawnParticles(vec3_t org)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<64 ; i++)
- {
+ for (i = 0; i < 64; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = 0xd4 + (rand()&3); // green
+ p->color = 0xd4 + (rand() & 3); // green
- p->org[0] = org[0] + crand()*8;
- p->org[1] = org[1] + crand()*8;
- p->org[2] = org[2] + crand()*8;
+ p->org[0] = org[0] + crand() * 8;
+ p->org[1] = org[1] + crand() * 8;
+ p->org[2] = org[2] + crand() * 8;
- for (j=0 ; j<3 ; j++)
- p->vel[j] = crand()*8;
+ for (j = 0; j < 3; j++)
+ p->vel[j] = crand() * 8;
p->accel[0] = p->accel[1] = 0;
- p->accel[2] = -PARTICLE_GRAVITY*0.2;
+ p->accel[2] = -PARTICLE_GRAVITY * 0.2;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1.0 + frand()*0.3);
+ p->alphavel = -1.0 / (1.0 + frand() * 0.3);
}
}
@@ -1036,31 +1030,29 @@ void CL_ItemRespawnParticles (vec3_t org)
CL_ExplosionParticles
===============
*/
-void CL_ExplosionParticles (vec3_t org)
+void CL_ExplosionParticles(vec3_t org)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<256 ; i++)
- {
+ for (i = 0; i < 256; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = 0xe0 + (rand()&7);
+ p->color = 0xe0 + (rand() & 7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()%32)-16);
- p->vel[j] = (rand()%384)-192;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() % 32) - 16);
+ p->vel[j] = (rand() % 384) - 192;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -0.8 / (0.5 + frand()*0.3);
+ p->alphavel = -0.8 / (0.5 + frand() * 0.3);
}
}
@@ -1069,39 +1061,38 @@ void CL_ExplosionParticles (vec3_t org)
CL_BigTeleportParticles
===============
*/
-void CL_BigTeleportParticles (vec3_t org)
+void CL_BigTeleportParticles(vec3_t org)
{
int i;
cparticle_t *p;
float angle, dist;
- static const int colortable[4] = {2*8,13*8,21*8,18*8};
+ static const int colortable[4] = {2 * 8, 13 * 8, 21 * 8, 18 * 8};
- for (i=0 ; i<4096 ; i++)
- {
+ for (i = 0; i < 4096; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = colortable[rand()&3];
+ p->color = colortable[rand() & 3];
- angle = M_PI*2*(rand()&1023)/1023.0;
- dist = rand()&31;
- p->org[0] = org[0] + cos(angle)*dist;
- p->vel[0] = cos(angle)*(70+(rand()&63));
- p->accel[0] = -cos(angle)*100;
+ angle = M_PI * 2 * (rand() & 1023) / 1023.0;
+ dist = rand() & 31;
+ p->org[0] = org[0] + cos(angle) * dist;
+ p->vel[0] = cos(angle) * (70 + (rand() & 63));
+ p->accel[0] = -cos(angle) * 100;
- p->org[1] = org[1] + sin(angle)*dist;
- p->vel[1] = sin(angle)*(70+(rand()&63));
- p->accel[1] = -sin(angle)*100;
+ p->org[1] = org[1] + sin(angle) * dist;
+ p->vel[1] = sin(angle) * (70 + (rand() & 63));
+ p->accel[1] = -sin(angle) * 100;
- p->org[2] = org[2] + 8 + (rand()%90);
- p->vel[2] = -100 + (rand()&31);
- p->accel[2] = PARTICLE_GRAVITY*4;
+ p->org[2] = org[2] + 8 + (rand() % 90);
+ p->vel[2] = -100 + (rand() & 31);
+ p->accel[2] = PARTICLE_GRAVITY * 4;
p->alpha = 1.0;
- p->alphavel = -0.3 / (0.5 + frand()*0.3);
+ p->alphavel = -0.3 / (0.5 + frand() * 0.3);
}
}
@@ -1113,33 +1104,31 @@ CL_BlasterParticles
Wall impact puffs
===============
*/
-void CL_BlasterParticles (vec3_t org, vec3_t dir)
+void CL_BlasterParticles(vec3_t org, vec3_t dir)
{
int i, j;
cparticle_t *p;
float d;
- for (i=0 ; i<40 ; i++)
- {
+ for (i = 0; i < 40; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = 0xe0 + (rand()&7);
+ p->color = 0xe0 + (rand() & 7);
- d = rand()&15;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = dir[j] * 30 + crand()*40;
+ d = rand() & 15;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = dir[j] * 30 + crand() * 40;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
@@ -1150,7 +1139,7 @@ CL_BlasterTrail
===============
*/
-void CL_BlasterTrail (vec3_t start, vec3_t end)
+void CL_BlasterTrail(vec3_t start, vec3_t end)
{
vec3_t move;
vec3_t vec;
@@ -1159,36 +1148,34 @@ void CL_BlasterTrail (vec3_t start, vec3_t end)
cparticle_t *p;
int dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.3+frand()*0.2);
+ p->alphavel = -1.0 / (0.3 + frand() * 0.2);
p->color = 0xe0;
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
p->org[j] = move[j] + crand();
- p->vel[j] = crand()*5;
+ p->vel[j] = crand() * 5;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1198,7 +1185,7 @@ CL_QuadTrail
===============
*/
-void CL_QuadTrail (vec3_t start, vec3_t end)
+void CL_QuadTrail(vec3_t start, vec3_t end)
{
vec3_t move;
vec3_t vec;
@@ -1207,35 +1194,33 @@ void CL_QuadTrail (vec3_t start, vec3_t end)
cparticle_t *p;
int dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.8+frand()*0.2);
+ p->alphavel = -1.0 / (0.8 + frand() * 0.2);
p->color = 115;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*16;
- p->vel[j] = crand()*5;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 16;
+ p->vel[j] = crand() * 5;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1245,7 +1230,7 @@ CL_FlagTrail
===============
*/
-void CL_FlagTrail (vec3_t start, vec3_t end, int color)
+void CL_FlagTrail(vec3_t start, vec3_t end, int color)
{
vec3_t move;
vec3_t vec;
@@ -1254,35 +1239,33 @@ void CL_FlagTrail (vec3_t start, vec3_t end, int color)
cparticle_t *p;
int dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.8+frand()*0.2);
+ p->alphavel = -1.0 / (0.8 + frand() * 0.2);
p->color = color;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*16;
- p->vel[j] = crand()*5;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 16;
+ p->vel[j] = crand() * 5;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1292,7 +1275,7 @@ CL_DiminishingTrail
===============
*/
-void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags)
+void CL_DiminishingTrail(vec3_t start, vec3_t end, centity_t *old, int flags)
{
vec3_t move;
vec3_t vec;
@@ -1303,78 +1286,63 @@ void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags)
float orgscale;
float velscale;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 0.5;
- VectorScale (vec, dec, vec);
+ VectorScale(vec, dec, vec);
- if (old->trailcount > 900)
- {
+ if (old->trailcount > 900) {
orgscale = 4;
velscale = 15;
- }
- else if (old->trailcount > 800)
- {
+ } else if (old->trailcount > 800) {
orgscale = 2;
velscale = 10;
- }
- else
- {
+ } else {
orgscale = 1;
velscale = 5;
}
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
// drop less particles as it flies
- if ((rand()&1023) < old->trailcount)
- {
+ if ((rand() & 1023) < old->trailcount) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
- if (flags & EF_GIB)
- {
+ if (flags & EF_GIB) {
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.4);
- p->color = 0xe8 + (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*orgscale;
- p->vel[j] = crand()*velscale;
+ p->alphavel = -1.0 / (1 + frand() * 0.4);
+ p->color = 0xe8 + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * orgscale;
+ p->vel[j] = crand() * velscale;
p->accel[j] = 0;
}
p->vel[2] -= PARTICLE_GRAVITY;
- }
- else if (flags & EF_GREENGIB)
- {
+ } else if (flags & EF_GREENGIB) {
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.4);
- p->color = 0xdb + (rand()&7);
- for (j=0; j< 3; j++)
- {
- p->org[j] = move[j] + crand()*orgscale;
- p->vel[j] = crand()*velscale;
+ p->alphavel = -1.0 / (1 + frand() * 0.4);
+ p->color = 0xdb + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * orgscale;
+ p->vel[j] = crand() * velscale;
p->accel[j] = 0;
}
p->vel[2] -= PARTICLE_GRAVITY;
- }
- else
- {
+ } else {
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.2);
- p->color = 4 + (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*orgscale;
- p->vel[j] = crand()*velscale;
+ p->alphavel = -1.0 / (1 + frand() * 0.2);
+ p->color = 4 + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * orgscale;
+ p->vel[j] = crand() * velscale;
}
p->accel[2] = 20;
}
@@ -1383,11 +1351,11 @@ void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags)
old->trailcount -= 5;
if (old->trailcount < 100)
old->trailcount = 100;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
-void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up)
+void MakeNormalVectors(vec3_t forward, vec3_t right, vec3_t up)
{
float d;
@@ -1397,10 +1365,10 @@ void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up)
right[2] = forward[1];
right[0] = forward[2];
- d = DotProduct (right, forward);
- VectorMA (right, -d, forward, right);
- VectorNormalize (right);
- CrossProduct (right, forward, up);
+ d = DotProduct(right, forward);
+ VectorMA(right, -d, forward, right);
+ VectorNormalize(right);
+ CrossProduct(right, forward, up);
}
/*
@@ -1409,7 +1377,7 @@ CL_RocketTrail
===============
*/
-void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old)
+void CL_RocketTrail(vec3_t start, vec3_t end, centity_t *old)
{
vec3_t move;
vec3_t vec;
@@ -1419,40 +1387,37 @@ void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old)
float dec;
// smoke
- CL_DiminishingTrail (start, end, old, EF_ROCKET);
+ CL_DiminishingTrail(start, end, old, EF_ROCKET);
// fire
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 1;
- VectorScale (vec, dec, vec);
+ VectorScale(vec, dec, vec);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
- if ( (rand()&7) == 0)
- {
+ if ((rand() & 7) == 0) {
p = CL_AllocParticle();
if (!p)
return;
-
- VectorClear (p->accel);
+
+ VectorClear(p->accel);
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.2);
- p->color = 0xdc + (rand()&3);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*5;
- p->vel[j] = crand()*20;
+ p->alphavel = -1.0 / (1 + frand() * 0.2);
+ p->color = 0xdc + (rand() & 3);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 5;
+ p->vel[j] = crand() * 20;
}
p->accel[2] = -PARTICLE_GRAVITY;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1462,7 +1427,7 @@ CL_RailTrail
===============
*/
-void CL_OldRailTrail (void)
+void CL_OldRailTrail(void)
{
vec3_t move;
vec3_t vec;
@@ -1476,46 +1441,43 @@ void CL_OldRailTrail (void)
vec3_t dir;
byte clr = 0x74;
- VectorCopy (te.pos1, move);
- VectorSubtract (te.pos2, te.pos1, vec);
- len = VectorNormalize (vec);
+ VectorCopy(te.pos1, move);
+ VectorSubtract(te.pos2, te.pos1, vec);
+ len = VectorNormalize(vec);
- MakeNormalVectors (vec, right, up);
+ MakeNormalVectors(vec, right, up);
- for (i=0 ; i<len ; i++)
- {
+ for (i = 0; i < len; i++) {
p = CL_AllocParticle();
if (!p)
return;
-
+
p->time = cl.time;
- VectorClear (p->accel);
+ VectorClear(p->accel);
d = i * 0.1;
c = cos(d);
s = sin(d);
- VectorScale (right, c, dir);
- VectorMA (dir, s, up, dir);
+ VectorScale(right, c, dir);
+ VectorMA(dir, s, up, dir);
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.2);
- p->color = clr + (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + dir[j]*3;
- p->vel[j] = dir[j]*6;
+ p->alphavel = -1.0 / (1 + frand() * 0.2);
+ p->color = clr + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + dir[j] * 3;
+ p->vel[j] = dir[j] * 6;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
dec = 0.75;
- VectorScale (vec, dec, vec);
- VectorCopy (te.pos1, move);
+ VectorScale(vec, dec, vec);
+ VectorCopy(te.pos1, move);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
@@ -1523,20 +1485,19 @@ void CL_OldRailTrail (void)
return;
p->time = cl.time;
- VectorClear (p->accel);
+ VectorClear(p->accel);
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.6+frand()*0.2);
- p->color = rand()&15;
+ p->alphavel = -1.0 / (0.6 + frand() * 0.2);
+ p->color = rand() & 15;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*3;
- p->vel[j] = crand()*3;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 3;
+ p->vel[j] = crand() * 3;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1547,7 +1508,7 @@ CL_BubbleTrail
===============
*/
-void CL_BubbleTrail (vec3_t start, vec3_t end)
+void CL_BubbleTrail(vec3_t start, vec3_t end)
{
vec3_t move;
vec3_t vec;
@@ -1556,33 +1517,31 @@ void CL_BubbleTrail (vec3_t start, vec3_t end)
cparticle_t *p;
float dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 32;
- VectorScale (vec, dec, vec);
+ VectorScale(vec, dec, vec);
- for (i=0 ; i<len ; i+=dec)
- {
+ for (i = 0; i < len; i += dec) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
+ VectorClear(p->accel);
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.2);
- p->color = 4 + (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*2;
- p->vel[j] = crand()*5;
+ p->alphavel = -1.0 / (1 + frand() * 0.2);
+ p->color = 4 + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 2;
+ p->vel[j] = crand() * 5;
}
p->vel[2] += 6;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1594,7 +1553,7 @@ CL_FlyParticles
*/
#define BEAMLENGTH 16
-static void CL_FlyParticles (vec3_t origin, int count)
+static void CL_FlyParticles(vec3_t origin, int count)
{
int i;
cparticle_t *p;
@@ -1604,13 +1563,11 @@ static void CL_FlyParticles (vec3_t origin, int count)
float dist = 64;
float ltime;
-
if (count > NUMVERTEXNORMALS)
count = NUMVERTEXNORMALS;
ltime = (float)cl.time / 1000.0;
- for (i=0 ; i<count ; i+=2)
- {
+ for (i = 0; i < count; i += 2) {
angle = ltime * avelocities[i][0];
sy = sin(angle);
cy = cos(angle);
@@ -1620,9 +1577,9 @@ static void CL_FlyParticles (vec3_t origin, int count)
angle = ltime * avelocities[i][2];
sr = sin(angle);
cr = cos(angle);
-
- forward[0] = cp*cy;
- forward[1] = cp*sy;
+
+ forward[0] = cp * cy;
+ forward[1] = cp * sy;
forward[2] = -sp;
p = CL_AllocParticle();
@@ -1631,13 +1588,13 @@ static void CL_FlyParticles (vec3_t origin, int count)
p->time = cl.time;
- dist = sin(ltime + i)*64;
- p->org[0] = origin[0] + bytedirs[i][0]*dist + forward[0]*BEAMLENGTH;
- p->org[1] = origin[1] + bytedirs[i][1]*dist + forward[1]*BEAMLENGTH;
- p->org[2] = origin[2] + bytedirs[i][2]*dist + forward[2]*BEAMLENGTH;
+ dist = sin(ltime + i) * 64;
+ p->org[0] = origin[0] + bytedirs[i][0] * dist + forward[0] * BEAMLENGTH;
+ p->org[1] = origin[1] + bytedirs[i][1] * dist + forward[1] * BEAMLENGTH;
+ p->org[2] = origin[2] + bytedirs[i][2] * dist + forward[2] * BEAMLENGTH;
- VectorClear (p->vel);
- VectorClear (p->accel);
+ VectorClear(p->vel);
+ VectorClear(p->accel);
p->color = 0;
@@ -1646,27 +1603,23 @@ static void CL_FlyParticles (vec3_t origin, int count)
}
}
-void CL_FlyEffect (centity_t *ent, vec3_t origin)
+void CL_FlyEffect(centity_t *ent, vec3_t origin)
{
int n;
int count;
int starttime;
- if (ent->fly_stoptime < cl.time)
- {
+ if (ent->fly_stoptime < cl.time) {
starttime = cl.time;
ent->fly_stoptime = cl.time + 60000;
- }
- else
- {
+ } else {
starttime = ent->fly_stoptime - 60000;
}
n = cl.time - starttime;
if (n < 20000)
count = n * 162 / 20000.0;
- else
- {
+ else {
n = ent->fly_stoptime - cl.time;
if (n < 20000)
count = n * 162 / 20000.0;
@@ -1674,7 +1627,7 @@ void CL_FlyEffect (centity_t *ent, vec3_t origin)
count = 162;
}
- CL_FlyParticles (origin, count);
+ CL_FlyParticles(origin, count);
}
@@ -1685,7 +1638,7 @@ CL_BfgParticles
*/
#define BEAMLENGTH 16
-void CL_BfgParticles (entity_t *ent)
+void CL_BfgParticles(entity_t *ent)
{
int i;
cparticle_t *p;
@@ -1695,10 +1648,9 @@ void CL_BfgParticles (entity_t *ent)
float dist = 64;
vec3_t v;
float ltime;
-
+
ltime = (float)cl.time / 1000.0;
- for (i=0 ; i<NUMVERTEXNORMALS ; i++)
- {
+ for (i = 0; i < NUMVERTEXNORMALS; i++) {
angle = ltime * avelocities[i][0];
sy = sin(angle);
cy = cos(angle);
@@ -1708,9 +1660,9 @@ void CL_BfgParticles (entity_t *ent)
angle = ltime * avelocities[i][2];
sr = sin(angle);
cr = cos(angle);
-
- forward[0] = cp*cy;
- forward[1] = cp*sy;
+
+ forward[0] = cp * cy;
+ forward[1] = cp * sy;
forward[2] = -sp;
p = CL_AllocParticle();
@@ -1719,17 +1671,17 @@ void CL_BfgParticles (entity_t *ent)
p->time = cl.time;
- dist = sin(ltime + i)*64;
- p->org[0] = ent->origin[0] + bytedirs[i][0]*dist + forward[0]*BEAMLENGTH;
- p->org[1] = ent->origin[1] + bytedirs[i][1]*dist + forward[1]*BEAMLENGTH;
- p->org[2] = ent->origin[2] + bytedirs[i][2]*dist + forward[2]*BEAMLENGTH;
+ dist = sin(ltime + i) * 64;
+ p->org[0] = ent->origin[0] + bytedirs[i][0] * dist + forward[0] * BEAMLENGTH;
+ p->org[1] = ent->origin[1] + bytedirs[i][1] * dist + forward[1] * BEAMLENGTH;
+ p->org[2] = ent->origin[2] + bytedirs[i][2] * dist + forward[2] * BEAMLENGTH;
- VectorClear (p->vel);
- VectorClear (p->accel);
+ VectorClear(p->vel);
+ VectorClear(p->accel);
- VectorSubtract (p->org, ent->origin, v);
+ VectorSubtract(p->org, ent->origin, v);
dist = VectorLength(v) / 90.0;
- p->color = floor (0xd0 + dist * 7);
+ p->color = floor(0xd0 + dist * 7);
p->alpha = 1.0 - dist;
p->alphavel = -100;
@@ -1743,31 +1695,29 @@ CL_BFGExplosionParticles
===============
*/
//FIXME combined with CL_ExplosionParticles
-void CL_BFGExplosionParticles (vec3_t org)
+void CL_BFGExplosionParticles(vec3_t org)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<256 ; i++)
- {
+ for (i = 0; i < 256; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = 0xd0 + (rand()&7);
+ p->color = 0xd0 + (rand() & 7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()%32)-16);
- p->vel[j] = (rand()%384)-192;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() % 32) - 16);
+ p->vel[j] = (rand() % 384) - 192;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -0.8 / (0.5 + frand()*0.3);
+ p->alphavel = -0.8 / (0.5 + frand() * 0.3);
}
}
@@ -1778,38 +1728,37 @@ CL_TeleportParticles
===============
*/
-void CL_TeleportParticles (vec3_t org)
+void CL_TeleportParticles(vec3_t org)
{
int i, j, k;
cparticle_t *p;
float vel;
vec3_t dir;
- for (i=-16 ; i<=16 ; i+=4)
- for (j=-16 ; j<=16 ; j+=4)
- for (k=-16 ; k<=32 ; k+=4)
- {
+ for (i = -16; i <= 16; i += 4)
+ for (j = -16; j <= 16; j += 4)
+ for (k = -16; k <= 32; k += 4) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = 7 + (rand()&7);
+ p->color = 7 + (rand() & 7);
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.3 + (rand()&7) * 0.02);
-
- p->org[0] = org[0] + i + (rand()&3);
- p->org[1] = org[1] + j + (rand()&3);
- p->org[2] = org[2] + k + (rand()&3);
-
- dir[0] = j*8;
- dir[1] = i*8;
- dir[2] = k*8;
-
- VectorNormalize (dir);
- vel = 50 + (rand()&63);
- VectorScale (dir, vel, p->vel);
+ p->alphavel = -1.0 / (0.3 + (rand() & 7) * 0.02);
+
+ p->org[0] = org[0] + i + (rand() & 3);
+ p->org[1] = org[1] + j + (rand() & 3);
+ p->org[2] = org[2] + k + (rand() & 3);
+
+ dir[0] = j * 8;
+ dir[1] = i * 8;
+ dir[2] = k * 8;
+
+ VectorNormalize(dir);
+ vel = 50 + (rand() & 63);
+ VectorScale(dir, vel, p->vel);
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
@@ -1826,7 +1775,7 @@ extern particle_t r_particles[MAX_PARTICLES];
CL_AddParticles
===============
*/
-void CL_AddParticles (void)
+void CL_AddParticles(void)
{
cparticle_t *p, *next;
float alpha;
@@ -1839,24 +1788,20 @@ void CL_AddParticles (void)
active = NULL;
tail = NULL;
- for (p=active_particles ; p ; p=next)
- {
+ for (p = active_particles; p; p = next) {
next = p->next;
// PMM - added INSTANT_PARTICLE handling for heat beam
- if (p->alphavel != INSTANT_PARTICLE)
- {
- time = (cl.time - p->time)*0.001;
- alpha = p->alpha + time*p->alphavel;
- if (alpha <= 0)
- { // faded out
+ if (p->alphavel != INSTANT_PARTICLE) {
+ time = (cl.time - p->time) * 0.001;
+ alpha = p->alpha + time * p->alphavel;
+ if (alpha <= 0) {
+ // faded out
p->next = free_particles;
free_particles = p;
continue;
}
- }
- else
- {
+ } else {
alpha = p->alpha;
}
@@ -1867,8 +1812,7 @@ void CL_AddParticles (void)
p->next = NULL;
if (!tail)
active = tail = p;
- else
- {
+ else {
tail->next = p;
tail = p;
}
@@ -1877,14 +1821,14 @@ void CL_AddParticles (void)
alpha = 1;
color = p->color;
- time2 = time*time;
+ time2 = time * time;
- part->origin[0] = p->org[0] + p->vel[0]*time + p->accel[0]*time2;
- part->origin[1] = p->org[1] + p->vel[1]*time + p->accel[1]*time2;
- part->origin[2] = p->org[2] + p->vel[2]*time + p->accel[2]*time2;
+ part->origin[0] = p->org[0] + p->vel[0] * time + p->accel[0] * time2;
+ part->origin[1] = p->org[1] + p->vel[1] * time + p->accel[1] * time2;
+ part->origin[2] = p->org[2] + p->vel[2] * time + p->accel[2] * time2;
#if USE_REF == REF_GL
- if( color == -1 ) {
+ if (color == -1) {
part->rgba.u8[0] = p->rgba.u8[0];
part->rgba.u8[1] = p->rgba.u8[1];
part->rgba.u8[2] = p->rgba.u8[2];
@@ -1895,10 +1839,9 @@ void CL_AddParticles (void)
part->color = color;
part->alpha = alpha;
-// V_AddParticle( &part );
+// V_AddParticle(&part);
// PMM
- if (p->alphavel == INSTANT_PARTICLE)
- {
+ if (p->alphavel == INSTANT_PARTICLE) {
p->alphavel = 0.0;
p->alpha = 0.0;
}
@@ -1914,19 +1857,20 @@ CL_ClearEffects
==============
*/
-void CL_ClearEffects (void)
+void CL_ClearEffects(void)
{
- clear_particles ();
+ clear_particles();
#if USE_DLIGHTS
- clear_dlights ();
+ clear_dlights();
#endif
}
-void CL_InitEffects( void ) {
+void CL_InitEffects(void)
+{
int i;
- for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
- avelocities[0][i] = (rand()&255) * 0.01;
+ for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
+ avelocities[0][i] = (rand() & 255) * 0.01;
}
diff --git a/src/cl_http.c b/src/cl_http.c
index 35da081..7d9749d 100644
--- a/src/cl_http.c
+++ b/src/cl_http.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -70,7 +70,8 @@ bandwidth.
// libcurl callback to update progress info. Mainly just used as
// a way to cancel the transfer if required.
-static int progress_func (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+static int progress_func(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+{
dlhandle_t *dl = (dlhandle_t *)clientp;
//dl->position = (unsigned)dlnow;
@@ -87,7 +88,8 @@ static int progress_func (void *clientp, double dltotal, double dlnow, double ul
}
// libcurl callback for filelists.
-static size_t recv_func (void *ptr, size_t size, size_t nmemb, void *stream) {
+static size_t recv_func(void *ptr, size_t size, size_t nmemb, void *stream)
+{
size_t new_size, bytes = size * nmemb;
dlhandle_t *dl = (dlhandle_t *)stream;
@@ -98,7 +100,7 @@ static size_t recv_func (void *ptr, size_t size, size_t nmemb, void *stream) {
if (new_size < MIN_DLSIZE)
new_size = MIN_DLSIZE;
dl->size = new_size;
- dl->buffer = Z_Malloc (dl->size);
+ dl->buffer = Z_Malloc(dl->size);
} else if (dl->position + bytes >= dl->size) {
char *tmp = dl->buffer;
@@ -107,25 +109,26 @@ static size_t recv_func (void *ptr, size_t size, size_t nmemb, void *stream) {
new_size = MAX_DLSIZE;
if (dl->position + bytes >= new_size)
goto oversize;
- dl->buffer = Z_Malloc (new_size);
- memcpy (dl->buffer, tmp, dl->size);
- Z_Free (tmp);
+ dl->buffer = Z_Malloc(new_size);
+ memcpy(dl->buffer, tmp, dl->size);
+ Z_Free(tmp);
dl->size = new_size;
}
- memcpy (dl->buffer + dl->position, ptr, bytes);
+ memcpy(dl->buffer + dl->position, ptr, bytes);
dl->position += bytes;
dl->buffer[dl->position] = 0;
return bytes;
oversize:
- Com_DPrintf ("[HTTP] Oversize file while trying to download '%s'\n", dl->url);
+ Com_DPrintf("[HTTP] Oversize file while trying to download '%s'\n", dl->url);
return 0;
}
// libcurl callback to update header info.
-static size_t header_func (void *ptr, size_t size, size_t nmemb, void *stream) {
+static size_t header_func(void *ptr, size_t size, size_t nmemb, void *stream)
+{
size_t len, bytes = size * nmemb;
dlhandle_t *dl = (dlhandle_t *)stream;
char buffer[64];
@@ -136,36 +139,37 @@ static size_t header_func (void *ptr, size_t size, size_t nmemb, void *stream) {
if (bytes <= 16)
return bytes;
- if (bytes > sizeof(buffer)-1)
- bytes = sizeof(buffer)-1;
+ if (bytes > sizeof(buffer) - 1)
+ bytes = sizeof(buffer) - 1;
- memcpy (buffer, ptr, bytes);
+ memcpy(buffer, ptr, bytes);
buffer[bytes] = 0;
- if (!Q_strncasecmp (buffer, "Content-Length: ", 16)) {
+ if (!Q_strncasecmp(buffer, "Content-Length: ", 16)) {
//allocate buffer based on what the server claims content-length is. +1 for nul
- len = strtoul (buffer + 16, NULL, 10);
+ len = strtoul(buffer + 16, NULL, 10);
if (len >= MAX_DLSIZE) {
- Com_DPrintf ("[HTTP] Oversize file while trying to download '%s'\n", dl->url);
+ Com_DPrintf("[HTTP] Oversize file while trying to download '%s'\n", dl->url);
return 0;
}
dl->size = len + 1;
- dl->buffer = Z_Malloc (dl->size);
+ dl->buffer = Z_Malloc(dl->size);
}
return bytes;
}
#ifdef _DEBUG
-static int debug_func (CURL *c, curl_infotype type, char *data, size_t size, void * ptr) {
+static int debug_func(CURL *c, curl_infotype type, char *data, size_t size, void * ptr)
+{
char buffer[MAXPRINTMSG];
if (type == CURLINFO_TEXT) {
- if (size > sizeof(buffer)-1)
- size = sizeof(buffer)-1;
- memcpy (buffer, data, size);
+ if (size > sizeof(buffer) - 1)
+ size = sizeof(buffer) - 1;
+ memcpy(buffer, data, size);
buffer[size] = 0;
- Com_LPrintf (PRINT_DEVELOPER, "[HTTP] %s\n", buffer);
+ Com_LPrintf(PRINT_DEVELOPER, "[HTTP] %s\n", buffer);
}
return 0;
@@ -175,16 +179,17 @@ static int debug_func (CURL *c, curl_infotype type, char *data, size_t size, voi
// Properly escapes a path with HTTP %encoding. libcurl's function
// seems to treat '/' and such as illegal chars and encodes almost
// the entire url...
-static void escape_path (const char *path, char *escaped) {
+static void escape_path(const char *path, char *escaped)
+{
static const char allowed[] = ";/?:@&=+$,[]-_.!~*'()";
int c;
char *p;
p = escaped;
- while(*path) {
+ while (*path) {
c = *path++;
- if (!Q_isalnum (c) && !strchr(allowed, c)) {
- sprintf (p, "%%%02x", c);
+ if (!Q_isalnum(c) && !strchr(allowed, c)) {
+ sprintf(p, "%%%02x", c);
p += 3;
} else {
*p++ = c;
@@ -194,51 +199,52 @@ static void escape_path (const char *path, char *escaped) {
}
// Actually starts a download by adding it to the curl multi handle.
-static void start_download (dlqueue_t *entry, dlhandle_t *dl) {
+static void start_download(dlqueue_t *entry, dlhandle_t *dl)
+{
size_t len;
char temp[MAX_QPATH];
- char escaped[MAX_QPATH*4];
+ char escaped[MAX_QPATH * 4];
CURLMcode ret;
qerror_t err;
-
+
//yet another hack to accomodate filelists, how i wish i could push :(
//NULL file handle indicates filelist.
if (entry->type == DL_LIST) {
dl->file = NULL;
dl->path[0] = 0;
- escape_path (entry->path, escaped);
+ escape_path(entry->path, escaped);
} else {
- len = Q_snprintf (dl->path, sizeof(dl->path), "%s/%s.tmp", fs_gamedir, entry->path);
+ len = Q_snprintf(dl->path, sizeof(dl->path), "%s/%s.tmp", fs_gamedir, entry->path);
if (len >= sizeof(dl->path)) {
- Com_EPrintf ("[HTTP] Refusing oversize temporary file path.\n");
+ Com_EPrintf("[HTTP] Refusing oversize temporary file path.\n");
goto fail;
}
// FIXME: should use baseq2 instead of empty gamedir?
- len = Q_snprintf (temp, sizeof(temp), "%s/%s", fs_game->string, entry->path);
+ len = Q_snprintf(temp, sizeof(temp), "%s/%s", fs_game->string, entry->path);
if (len >= sizeof(temp)) {
- Com_EPrintf ("[HTTP] Refusing oversize server file path.\n");
+ Com_EPrintf("[HTTP] Refusing oversize server file path.\n");
goto fail;
}
- escape_path (temp, escaped);
+ escape_path(temp, escaped);
- err = FS_CreatePath (dl->path);
+ err = FS_CreatePath(dl->path);
if (err < 0) {
- Com_EPrintf ("[HTTP] Couldn't create path to '%s': %s\n", dl->path, Q_ErrorString (err));
+ Com_EPrintf("[HTTP] Couldn't create path to '%s': %s\n", dl->path, Q_ErrorString(err));
goto fail;
}
//don't bother with http resume... too annoying if server doesn't support it.
- dl->file = fopen (dl->path, "wb");
+ dl->file = fopen(dl->path, "wb");
if (!dl->file) {
- Com_EPrintf ("[HTTP] Couldn't open '%s' for writing: %s\n", dl->path, strerror (errno));
+ Com_EPrintf("[HTTP] Couldn't open '%s' for writing: %s\n", dl->path, strerror(errno));
goto fail;
}
}
- len = Q_snprintf (dl->url, sizeof(dl->url), "%s%s", download_server, escaped);
+ len = Q_snprintf(dl->url, sizeof(dl->url), "%s%s", download_server, escaped);
if (len >= sizeof(dl->url)) {
- Com_EPrintf ("[HTTP] Refusing oversize download URL.\n");
+ Com_EPrintf("[HTTP] Refusing oversize download URL.\n");
goto fail;
}
@@ -247,50 +253,50 @@ static void start_download (dlqueue_t *entry, dlhandle_t *dl) {
dl->position = 0;
dl->queue = entry;
if (!dl->curl)
- dl->curl = curl_easy_init ();
+ dl->curl = curl_easy_init();
- curl_easy_setopt (dl->curl, CURLOPT_ENCODING, "");
+ curl_easy_setopt(dl->curl, CURLOPT_ENCODING, "");
#ifdef _DEBUG
if (cl_http_debug->integer) {
- curl_easy_setopt (dl->curl, CURLOPT_DEBUGFUNCTION, debug_func);
- curl_easy_setopt (dl->curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(dl->curl, CURLOPT_DEBUGFUNCTION, debug_func);
+ curl_easy_setopt(dl->curl, CURLOPT_VERBOSE, 1);
}
#endif
- curl_easy_setopt (dl->curl, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(dl->curl, CURLOPT_NOPROGRESS, 0);
if (dl->file) {
- curl_easy_setopt (dl->curl, CURLOPT_WRITEDATA, dl->file);
- curl_easy_setopt (dl->curl, CURLOPT_WRITEFUNCTION, NULL);
- curl_easy_setopt (dl->curl, CURLOPT_WRITEHEADER, NULL);
- curl_easy_setopt (dl->curl, CURLOPT_HEADERFUNCTION, NULL);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEDATA, dl->file);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEFUNCTION, NULL);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEHEADER, NULL);
+ curl_easy_setopt(dl->curl, CURLOPT_HEADERFUNCTION, NULL);
} else {
- curl_easy_setopt (dl->curl, CURLOPT_WRITEDATA, dl);
- curl_easy_setopt (dl->curl, CURLOPT_WRITEFUNCTION, recv_func);
- curl_easy_setopt (dl->curl, CURLOPT_WRITEHEADER, dl);
- curl_easy_setopt (dl->curl, CURLOPT_HEADERFUNCTION, header_func);
- }
- curl_easy_setopt (dl->curl, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt (dl->curl, CURLOPT_PROXY, cl_http_proxy->string);
- curl_easy_setopt (dl->curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_easy_setopt (dl->curl, CURLOPT_MAXREDIRS, 5);
- curl_easy_setopt (dl->curl, CURLOPT_PROGRESSFUNCTION, progress_func);
- curl_easy_setopt (dl->curl, CURLOPT_PROGRESSDATA, dl);
- curl_easy_setopt (dl->curl, CURLOPT_USERAGENT, com_version->string);
- curl_easy_setopt (dl->curl, CURLOPT_REFERER, download_referer);
- curl_easy_setopt (dl->curl, CURLOPT_URL, dl->url);
-
- ret = curl_multi_add_handle (curl_multi, dl->curl);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEDATA, dl);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEFUNCTION, recv_func);
+ curl_easy_setopt(dl->curl, CURLOPT_WRITEHEADER, dl);
+ curl_easy_setopt(dl->curl, CURLOPT_HEADERFUNCTION, header_func);
+ }
+ curl_easy_setopt(dl->curl, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(dl->curl, CURLOPT_PROXY, cl_http_proxy->string);
+ curl_easy_setopt(dl->curl, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt(dl->curl, CURLOPT_MAXREDIRS, 5);
+ curl_easy_setopt(dl->curl, CURLOPT_PROGRESSFUNCTION, progress_func);
+ curl_easy_setopt(dl->curl, CURLOPT_PROGRESSDATA, dl);
+ curl_easy_setopt(dl->curl, CURLOPT_USERAGENT, com_version->string);
+ curl_easy_setopt(dl->curl, CURLOPT_REFERER, download_referer);
+ curl_easy_setopt(dl->curl, CURLOPT_URL, dl->url);
+
+ ret = curl_multi_add_handle(curl_multi, dl->curl);
if (ret != CURLM_OK) {
- Com_EPrintf ("[HTTP] Failed to add download handle: %s\n",
- curl_multi_strerror (ret));
+ Com_EPrintf("[HTTP] Failed to add download handle: %s\n",
+ curl_multi_strerror(ret));
fail:
- CL_FinishDownload( entry );
+ CL_FinishDownload(entry);
// see if we have more to dl
- CL_RequestNextDownload ();
+ CL_RequestNextDownload();
return;
}
- Com_DPrintf ("[HTTP] Fetching %s...\n", dl->url);
+ Com_DPrintf("[HTTP] Fetching %s...\n", dl->url);
entry->state = DL_RUNNING;
curl_handles++;
}
@@ -302,7 +308,8 @@ HTTP_CleanupDownloads
Disconnected from server, or fatal HTTP error occured. Clean up.
===============
*/
-void HTTP_CleanupDownloads (void) {
+void HTTP_CleanupDownloads(void)
+{
dlhandle_t *dl;
int i;
@@ -314,20 +321,20 @@ void HTTP_CleanupDownloads (void) {
dl = &download_handles[i];
if (dl->file) {
- fclose (dl->file);
- remove (dl->path);
+ fclose(dl->file);
+ remove(dl->path);
dl->file = NULL;
}
if (dl->buffer) {
- Z_Free (dl->buffer);
+ Z_Free(dl->buffer);
dl->buffer = NULL;
}
if (dl->curl) {
if (curl_multi)
- curl_multi_remove_handle (curl_multi, dl->curl);
- curl_easy_cleanup (dl->curl);
+ curl_multi_remove_handle(curl_multi, dl->curl);
+ curl_easy_cleanup(dl->curl);
dl->curl = NULL;
}
@@ -335,7 +342,7 @@ void HTTP_CleanupDownloads (void) {
}
if (curl_multi) {
- curl_multi_cleanup (curl_multi);
+ curl_multi_cleanup(curl_multi);
curl_multi = NULL;
}
}
@@ -348,28 +355,30 @@ HTTP_Init
Init libcurl and multi handle.
===============
*/
-void HTTP_Init (void) {
- cl_http_downloads = Cvar_Get ("cl_http_downloads", "1", 0);
- cl_http_filelists = Cvar_Get ("cl_http_filelists", "1", 0);
- cl_http_max_connections = Cvar_Get ("cl_http_max_connections", "2", 0);
+void HTTP_Init(void)
+{
+ cl_http_downloads = Cvar_Get("cl_http_downloads", "1", 0);
+ cl_http_filelists = Cvar_Get("cl_http_filelists", "1", 0);
+ cl_http_max_connections = Cvar_Get("cl_http_max_connections", "2", 0);
//cl_http_max_connections->changed = _cl_http_max_connections_changed;
- cl_http_proxy = Cvar_Get ("cl_http_proxy", "", 0);
+ cl_http_proxy = Cvar_Get("cl_http_proxy", "", 0);
#ifdef _DEBUG
- cl_http_debug = Cvar_Get ("cl_http_debug", "0", 0);
+ cl_http_debug = Cvar_Get("cl_http_debug", "0", 0);
#endif
- curl_global_init (CURL_GLOBAL_NOTHING);
+ curl_global_init(CURL_GLOBAL_NOTHING);
curl_initialized = qtrue;
- Com_DPrintf ("%s initialized.\n", curl_version());
+ Com_DPrintf("%s initialized.\n", curl_version());
}
-void HTTP_Shutdown (void) {
+void HTTP_Shutdown(void)
+{
if (!curl_initialized)
return;
HTTP_CleanupDownloads();
- curl_global_cleanup ();
+ curl_global_cleanup();
curl_initialized = qfalse;
}
@@ -381,9 +390,10 @@ HTTP_SetServer
A new server is specified, so we nuke all our state.
===============
*/
-void HTTP_SetServer (const char *url) {
+void HTTP_SetServer(const char *url)
+{
if (curl_multi) {
- Com_EPrintf ("[HTTP] Set server without cleanup?\n");
+ Com_EPrintf("[HTTP] Set server without cleanup?\n");
return;
}
@@ -394,18 +404,18 @@ void HTTP_SetServer (const char *url) {
if (allow_download->integer == -1)
return;
- if (strncmp (url, "http://", 7)) {
- Com_Printf ("[HTTP] Ignoring download server URL with non-HTTP schema.\n");
+ if (strncmp(url, "http://", 7)) {
+ Com_Printf("[HTTP] Ignoring download server URL with non-HTTP schema.\n");
return;
}
- curl_multi = curl_multi_init ();
+ curl_multi = curl_multi_init();
- Q_strlcpy (download_server, url, sizeof(download_server));
- Q_snprintf (download_referer, sizeof(download_referer),
- "quake2://%s", NET_AdrToString (&cls.serverAddress));
+ Q_strlcpy(download_server, url, sizeof(download_server));
+ Q_snprintf(download_referer, sizeof(download_referer),
+ "quake2://%s", NET_AdrToString(&cls.serverAddress));
- Com_Printf ("[HTTP] Download server at %s\n", download_server);
+ Com_Printf("[HTTP] Download server at %s\n", download_server);
}
/*
@@ -416,7 +426,8 @@ Called from the precache check to queue a download. Return value of
Q_ERR_NOSYS will cause standard UDP downloading to be used instead.
===============
*/
-qerror_t HTTP_QueueDownload (const char *path, dltype_t type) {
+qerror_t HTTP_QueueDownload(const char *path, dltype_t type)
+{
size_t len;
qboolean need_list;
char temp[MAX_QPATH];
@@ -427,9 +438,9 @@ qerror_t HTTP_QueueDownload (const char *path, dltype_t type) {
return Q_ERR_NOSYS;
// first download queued, so we want the mod filelist
- need_list = LIST_EMPTY (&cls.download.queue);
+ need_list = LIST_EMPTY(&cls.download.queue);
- ret = CL_QueueDownload (path, type);
+ ret = CL_QueueDownload(path, type);
if (ret) {
return ret;
}
@@ -439,9 +450,9 @@ qerror_t HTTP_QueueDownload (const char *path, dltype_t type) {
if (need_list) {
//grab the filelist
- len = Q_snprintf (temp, sizeof(temp), "%s.filelist", fs_game->string);
+ len = Q_snprintf(temp, sizeof(temp), "%s.filelist", fs_game->string);
if (len < sizeof(temp))
- CL_QueueDownload (temp, DL_LIST);
+ CL_QueueDownload(temp, DL_LIST);
//this is a nasty hack to let the server know what we're doing so admins don't
//get confused by a ton of people stuck in CNCT state. it's assumed the server
@@ -451,12 +462,12 @@ qerror_t HTTP_QueueDownload (const char *path, dltype_t type) {
}
//special case for map file lists, i really wanted a server-push mechanism for this, but oh well
- len = strlen (path);
- if (len > 4 && !Q_stricmp (path + len - 4, ".bsp")) {
- len = Q_snprintf (temp, sizeof(temp), "%s/%s", fs_game->string, path);
+ len = strlen(path);
+ if (len > 4 && !Q_stricmp(path + len - 4, ".bsp")) {
+ len = Q_snprintf(temp, sizeof(temp), "%s/%s", fs_game->string, path);
if (len + 5 < sizeof(temp)) {
- memcpy (temp + len - 4, ".filelist", 10);
- CL_QueueDownload (temp, DL_LIST);
+ memcpy(temp + len - 4, ".filelist", 10);
+ CL_QueueDownload(temp, DL_LIST);
}
}
@@ -464,7 +475,8 @@ qerror_t HTTP_QueueDownload (const char *path, dltype_t type) {
}
// Validate a path supplied by a filelist.
-static void check_and_queue_download (char *path) {
+static void check_and_queue_download(char *path)
+{
size_t len;
char *ext;
dltype_t type;
@@ -474,7 +486,7 @@ static void check_and_queue_download (char *path) {
if (len >= MAX_QPATH)
return;
- ext = strrchr (path, '.');
+ ext = strrchr(path, '.');
if (!ext)
return;
@@ -482,22 +494,22 @@ static void check_and_queue_download (char *path) {
if (!ext[0])
return;
- Q_strlwr (ext);
+ Q_strlwr(ext);
- if (!strcmp (ext, "pak") || !strcmp (ext, "pkz")) {
- Com_Printf ("[HTTP] Filelist is requesting a .%s file '%s'\n", ext, path);
+ if (!strcmp(ext, "pak") || !strcmp(ext, "pkz")) {
+ Com_Printf("[HTTP] Filelist is requesting a .%s file '%s'\n", ext, path);
type = DL_PAK;
} else {
type = DL_OTHER;
if (!CL_CheckDownloadExtension(ext)) {
- Com_WPrintf ("[HTTP] Illegal file type '%s' in filelist.\n", path);
+ Com_WPrintf("[HTTP] Illegal file type '%s' in filelist.\n", path);
return;
}
}
- if (path[0] == '@'){
+ if (path[0] == '@') {
if (type == DL_PAK) {
- Com_WPrintf ("[HTTP] '@' prefix used on a pak file '%s' in filelist.\n", path);
+ Com_WPrintf("[HTTP] '@' prefix used on a pak file '%s' in filelist.\n", path);
return;
}
flags = FS_PATH_GAME;
@@ -505,72 +517,74 @@ static void check_and_queue_download (char *path) {
len--;
} else if (type == DL_PAK) {
//by definition paks are game-local
- flags = FS_PATH_GAME|FS_TYPE_REAL;
+ flags = FS_PATH_GAME | FS_TYPE_REAL;
} else {
flags = 0;
}
- len = FS_NormalizePath (path, path);
+ len = FS_NormalizePath(path, path);
if (len == 0 ||
- !Q_ispath (path[0]) ||
- !Q_ispath (path[len-1]) ||
- !FS_ValidatePath (path) ||
- strstr (path, "..") ||
- (type == DL_OTHER && !strchr (path, '/')) ||
- (type == DL_PAK && strchr(path, '/')))
- {
- Com_WPrintf ("[HTTP] Illegal path '%s' in filelist.\n", path);
+ !Q_ispath(path[0]) ||
+ !Q_ispath(path[len - 1]) ||
+ !FS_ValidatePath(path) ||
+ strstr(path, "..") ||
+ (type == DL_OTHER && !strchr(path, '/')) ||
+ (type == DL_PAK && strchr(path, '/'))) {
+ Com_WPrintf("[HTTP] Illegal path '%s' in filelist.\n", path);
return;
}
- if (!FS_FileExistsEx (path, flags)) {
- CL_QueueDownload (path, type);
+ if (!FS_FileExistsEx(path, flags)) {
+ CL_QueueDownload(path, type);
}
}
// A filelist is in memory, scan and validate it and queue up the files.
-static void parse_file_list (dlhandle_t *dl) {
+static void parse_file_list(dlhandle_t *dl)
+{
char *list;
char *p;
if (cl_http_filelists->integer) {
list = dl->buffer;
while (1) {
- p = strchr (list, '\n');
+ p = strchr(list, '\n');
if (p) {
if (p > list && *(p - 1) == '\r')
*(p - 1) = 0;
*p = 0;
if (*list)
- check_and_queue_download (list);
+ check_and_queue_download(list);
list = p + 1;
} else {
if (*list)
- check_and_queue_download (list);
+ check_and_queue_download(list);
break;
}
}
}
- Z_Free (dl->buffer);
+ Z_Free(dl->buffer);
dl->buffer = NULL;
}
// A pak file just downloaded, let's see if we can remove some stuff from
// the queue which is in the .pak.
-static void rescan_queue (void) {
+static void rescan_queue(void)
+{
dlqueue_t *q;
- FOR_EACH_DLQ (q) {
- if (q->state == DL_PENDING && q->type < DL_LIST && FS_FileExists (q->path))
- CL_FinishDownload (q);
+ FOR_EACH_DLQ(q) {
+ if (q->state == DL_PENDING && q->type < DL_LIST && FS_FileExists(q->path))
+ CL_FinishDownload(q);
}
}
// Fatal HTTP error occured, remove any special entries from
// queue and fall back to UDP downloading.
-static void abort_downloads (void) {
+static void abort_downloads(void)
+{
dlqueue_t *q;
HTTP_CleanupDownloads();
@@ -578,19 +592,20 @@ static void abort_downloads (void) {
cls.download.current = NULL;
cls.download.percent = 0;
- FOR_EACH_DLQ (q) {
+ FOR_EACH_DLQ(q) {
if (q->state != DL_DONE && q->type >= DL_LIST)
- CL_FinishDownload (q);
+ CL_FinishDownload(q);
else if (q->state == DL_RUNNING)
q->state = DL_PENDING;
}
- CL_RequestNextDownload ();
- CL_StartNextDownload ();
+ CL_RequestNextDownload();
+ CL_StartNextDownload();
}
// curl doesn't provide reverse-lookup of the void * ptr, so search for it
-static dlhandle_t *find_handle (CURL *curl) {
+static dlhandle_t *find_handle(CURL *curl)
+{
size_t i;
dlhandle_t *dl;
@@ -601,10 +616,11 @@ static dlhandle_t *find_handle (CURL *curl) {
}
}
- Com_Error (ERR_FATAL, "CURL handle not found for CURLMSG_DONE");
+ Com_Error(ERR_FATAL, "CURL handle not found for CURLMSG_DONE");
}
-static const char *http_strerror (int response) {
+static const char *http_strerror(int response)
+{
static char buffer[32];
//common codes
@@ -624,21 +640,21 @@ static const char *http_strerror (int response) {
}
if (response < 100 || response >= 600) {
- Q_snprintf (buffer, sizeof (buffer), "%d <bad code>", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d <bad code>", response);
return buffer;
}
//generic classes
if (response < 200) {
- Q_snprintf (buffer, sizeof (buffer), "%d Informational", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d Informational", response);
} else if (response < 300) {
- Q_snprintf (buffer, sizeof (buffer), "%d Success", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d Success", response);
} else if (response < 400) {
- Q_snprintf (buffer, sizeof (buffer), "%d Redirection", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d Redirection", response);
} else if (response < 500) {
- Q_snprintf (buffer, sizeof (buffer), "%d Client Error", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d Client Error", response);
} else {
- Q_snprintf (buffer, sizeof (buffer), "%d Server Error", response);
+ Q_snprintf(buffer, sizeof(buffer), "%d Server Error", response);
}
return buffer;
@@ -646,7 +662,8 @@ static const char *http_strerror (int response) {
// A download finished, find out what it was, whether there were any errors and
// if so, how severe. If none, rename file and other such stuff.
-static qboolean finish_download (void) {
+static qboolean finish_download(void)
+{
int msgs_in_queue;
CURLMsg *msg;
CURLcode result;
@@ -661,7 +678,7 @@ static qboolean finish_download (void) {
print_type_t level;
do {
- msg = curl_multi_info_read (curl_multi, &msgs_in_queue);
+ msg = curl_multi_info_read(curl_multi, &msgs_in_queue);
if (!msg)
break;
@@ -669,14 +686,14 @@ static qboolean finish_download (void) {
continue;
curl = msg->easy_handle;
- dl = find_handle (curl);
+ dl = find_handle(curl);
cls.download.current = NULL;
cls.download.percent = 0;
//filelist processing is done on read
if (dl->file) {
- fclose (dl->file);
+ fclose(dl->file);
dl->file = NULL;
}
@@ -685,16 +702,16 @@ static qboolean finish_download (void) {
result = msg->data.result;
switch (result) {
- //for some reason curl returns CURLE_OK for a 404...
+ //for some reason curl returns CURLE_OK for a 404...
case CURLE_HTTP_RETURNED_ERROR:
case CURLE_OK:
- curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &response);
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
if (result == CURLE_OK && response == 200) {
//success
break;
}
- err = http_strerror (response);
+ err = http_strerror(response);
//404 is non-fatal
if (response == 404) {
@@ -713,73 +730,73 @@ static qboolean finish_download (void) {
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_PROXY:
//connection problems are fatal
- err = curl_easy_strerror (result);
+ err = curl_easy_strerror(result);
level = PRINT_ERROR;
fatal_error = qtrue;
goto fail2;
default:
- err = curl_easy_strerror (result);
+ err = curl_easy_strerror(result);
level = PRINT_WARNING;
fail1:
//we mark download as done even if it errored
//to prevent multiple attempts.
- CL_FinishDownload (dl->queue);
+ CL_FinishDownload(dl->queue);
fail2:
- Com_LPrintf (level,
- "[HTTP] %s [%s] [%d remaining file%s]\n",
- dl->queue->path, err, cls.download.pending,
- cls.download.pending == 1 ? "" : "s");
+ Com_LPrintf(level,
+ "[HTTP] %s [%s] [%d remaining file%s]\n",
+ dl->queue->path, err, cls.download.pending,
+ cls.download.pending == 1 ? "" : "s");
if (dl->path[0]) {
- remove (dl->path);
+ remove(dl->path);
dl->path[0] = 0;
}
if (dl->buffer) {
- Z_Free (dl->buffer);
+ Z_Free(dl->buffer);
dl->buffer = NULL;
}
- curl_multi_remove_handle (curl_multi, curl);
+ curl_multi_remove_handle(curl_multi, curl);
continue;
}
//mark as done
- CL_FinishDownload (dl->queue);
+ CL_FinishDownload(dl->queue);
//show some stats
- curl_easy_getinfo (curl, CURLINFO_TOTAL_TIME, &sec);
- curl_easy_getinfo (curl, CURLINFO_SIZE_DOWNLOAD, &bytes);
+ curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &sec);
+ curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes);
if (sec < 0.001)
sec = 0.001;
- Com_FormatSizeLong (size, sizeof (size), bytes);
- Com_FormatSizeLong (speed, sizeof (speed), bytes / sec);
+ Com_FormatSizeLong(size, sizeof(size), bytes);
+ Com_FormatSizeLong(speed, sizeof(speed), bytes / sec);
//FIXME:
//technically i shouldn't need to do this as curl will auto reuse the
//existing handle when you change the url. however, the curl_handles goes
//all weird when reusing a download slot in this way. if you can figure
//out why, please let me know.
- curl_multi_remove_handle (curl_multi, curl);
+ curl_multi_remove_handle(curl_multi, curl);
- Com_Printf ("[HTTP] %s [%s, %s/sec] [%d remaining file%s]\n",
- dl->queue->path, size, speed, cls.download.pending,
- cls.download.pending == 1 ? "" : "s");
+ Com_Printf("[HTTP] %s [%s, %s/sec] [%d remaining file%s]\n",
+ dl->queue->path, size, speed, cls.download.pending,
+ cls.download.pending == 1 ? "" : "s");
if (dl->path[0]) {
//rename the temp file
- Q_snprintf (temp, sizeof(temp), "%s/%s", fs_gamedir, dl->queue->path);
+ Q_snprintf(temp, sizeof(temp), "%s/%s", fs_gamedir, dl->queue->path);
- if (rename (dl->path, temp))
- Com_EPrintf ("[HTTP] Failed to rename '%s' to '%s': %s\n",
- dl->path, dl->queue->path, strerror (errno));
+ if (rename(dl->path, temp))
+ Com_EPrintf("[HTTP] Failed to rename '%s' to '%s': %s\n",
+ dl->path, dl->queue->path, strerror(errno));
dl->path[0] = 0;
//a pak file is very special...
if (dl->queue->type == DL_PAK) {
- CL_RestartFilesystem (qfalse);
- rescan_queue ();
+ CL_RestartFilesystem(qfalse);
+ rescan_queue();
}
} else if (!fatal_error) {
- parse_file_list (dl);
+ parse_file_list(dl);
}
} while (msgs_in_queue > 0);
@@ -790,12 +807,13 @@ fail2:
}
// see if we have more to dl
- CL_RequestNextDownload ();
+ CL_RequestNextDownload();
return qtrue;
}
// Find a free download handle to start another queue entry on.
-static dlhandle_t *get_free_handle (void) {
+static dlhandle_t *get_free_handle(void)
+{
dlhandle_t *dl;
int i;
@@ -809,7 +827,8 @@ static dlhandle_t *get_free_handle (void) {
}
// Start another HTTP download if possible.
-static void start_next_download (void) {
+static void start_next_download(void)
+{
dlqueue_t *q;
if (!cls.download.pending || curl_handles >= cl_http_max_connections->integer) {
@@ -817,14 +836,14 @@ static void start_next_download (void) {
}
//not enough downloads running, queue some more!
- FOR_EACH_DLQ (q) {
+ FOR_EACH_DLQ(q) {
if (q->state == DL_RUNNING) {
if (q->type == DL_PAK)
break; // hack for pak file single downloading
} else if (q->state == DL_PENDING) {
dlhandle_t *dl = get_free_handle();
if (dl)
- start_download (q, dl);
+ start_download(q, dl);
break;
}
}
@@ -839,32 +858,33 @@ connecting to minimise latency. Also starts new downloads if we're not doing
the maximum already.
===============
*/
-void HTTP_RunDownloads (void) {
+void HTTP_RunDownloads(void)
+{
int new_count;
CURLMcode ret;
if (!curl_multi)
return;
- start_next_download ();
+ start_next_download();
do {
- ret = curl_multi_perform (curl_multi, &new_count);
+ ret = curl_multi_perform(curl_multi, &new_count);
if (new_count < curl_handles) {
//hmm, something either finished or errored out.
- if (!finish_download ())
+ if (!finish_download())
return; //aborted
curl_handles = new_count;
}
} while (ret == CURLM_CALL_MULTI_PERFORM);
if (ret != CURLM_OK) {
- Com_EPrintf ("[HTTP] Error running downloads: %s.\n",
- curl_multi_strerror(ret));
+ Com_EPrintf("[HTTP] Error running downloads: %s.\n",
+ curl_multi_strerror(ret));
abort_downloads();
return;
}
- start_next_download ();
+ start_next_download();
}
diff --git a/src/cl_input.c b/src/cl_input.c
index 6693269..ba602c0 100644
--- a/src/cl_input.c
+++ b/src/cl_input.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -92,34 +92,35 @@ static cvar_t *in_direct;
static cvar_t *in_smart_grab;
static cvar_t *in_hide_delay;
-static inline grab_t get_grab_mode( void ) {
+static inline grab_t get_grab_mode(void)
+{
// never grab if main window doesn't have focus
- if( cls.active != ACT_ACTIVATED )
+ if (cls.active != ACT_ACTIVATED)
return IN_FREE;
// always grab in full screen
- if( r_config.flags & QVF_FULLSCREEN )
+ if (r_config.flags & QVF_FULLSCREEN)
return IN_GRAB;
// show cursor if menu is up
- if( cls.key_dest & KEY_MENU )
+ if (cls.key_dest & KEY_MENU)
return IN_SHOW;
// hide cursor, but don't grab if console is up
- if( cls.key_dest & KEY_CONSOLE )
+ if (cls.key_dest & KEY_CONSOLE)
return IN_HIDE;
- if( sv_paused->integer )
+ if (sv_paused->integer)
return IN_HIDE;
- if( cls.state < ca_active )
+ if (cls.state < ca_active)
return IN_HIDE;
// don't grab if mouse input is not needed
- if( in_smart_grab->integer ) {
+ if (in_smart_grab->integer) {
// playing a demo (and not using freelook)
- if( cls.demo.playback && !Key_IsDown( K_SHIFT ) )
+ if (cls.demo.playback && !Key_IsDown(K_SHIFT))
return IN_HIDE;
// spectator mode
- if( cl.frame.ps.pmove.pm_type == PM_FREEZE )
+ if (cl.frame.ps.pmove.pm_type == PM_FREEZE)
return IN_HIDE;
}
@@ -132,17 +133,18 @@ static inline grab_t get_grab_mode( void ) {
IN_Activate
============
*/
-void IN_Activate( void ) {
+void IN_Activate(void)
+{
grab_t grab;
- if( !input.initialized ) {
+ if (!input.initialized) {
return;
}
grab = get_grab_mode();
// set up cursor hiding policy
- if( grab == IN_HIDE && in_hide_delay->value > 0.1f ) {
+ if (grab == IN_HIDE && in_hide_delay->value > 0.1f) {
input.hide_cursor = HIDE_SHOW;
input.last_motion = com_localTime;
input.hide_delay = in_hide_delay->value * 1000;
@@ -151,11 +153,11 @@ void IN_Activate( void ) {
input.hide_cursor = HIDE_NOT;
input.last_motion = com_localTime;
input.hide_delay = 0;
- if( grab == IN_HIDE )
+ if (grab == IN_HIDE)
grab = IN_SHOW;
}
- input.api.Grab( grab );
+ input.api.Grab(grab);
}
/*
@@ -163,7 +165,8 @@ void IN_Activate( void ) {
IN_Restart_f
============
*/
-static void IN_Restart_f( void ) {
+static void IN_Restart_f(void)
+{
IN_Shutdown();
IN_Init();
}
@@ -173,21 +176,21 @@ static void IN_Restart_f( void ) {
IN_Frame
============
*/
-void IN_Frame( void ) {
- if( input.modified ) {
+void IN_Frame(void)
+{
+ if (input.modified) {
IN_Restart_f();
input.modified = qfalse;
return;
}
- if( input.initialized ) {
- if( input.api.GetEvents ) {
+ if (input.initialized) {
+ if (input.api.GetEvents) {
input.api.GetEvents();
}
- if( input.hide_cursor == HIDE_SHOW &&
- com_localTime - input.last_motion > input.hide_delay )
- {
- input.api.Grab( IN_HIDE );
+ if (input.hide_cursor == HIDE_SHOW &&
+ com_localTime - input.last_motion > input.hide_delay) {
+ input.api.Grab(IN_HIDE);
input.hide_cursor = HIDE_HIDE;
}
}
@@ -202,26 +205,27 @@ void IN_Frame( void ) {
IN_MouseEvent
================
*/
-void IN_MouseEvent( int x, int y ) {
+void IN_MouseEvent(int x, int y)
+{
input.last_motion = com_localTime;
- if( input.hide_cursor == HIDE_HIDE ) {
- input.api.Grab( IN_SHOW );
+ if (input.hide_cursor == HIDE_HIDE) {
+ input.api.Grab(IN_SHOW);
input.hide_cursor = HIDE_SHOW;
}
- if( x < 0 && y < 0 ) {
+ if (x < 0 && y < 0) {
// cursor is over non-client area
- if( input.hide_cursor == HIDE_SHOW )
+ if (input.hide_cursor == HIDE_SHOW)
input.hide_cursor = HIDE_SHOW_NC;
return;
}
// cursor is over client area
- if( input.hide_cursor == HIDE_SHOW_NC )
+ if (input.hide_cursor == HIDE_SHOW_NC)
input.hide_cursor = HIDE_SHOW;
#if USE_UI
- UI_MouseEvent( x, y );
+ UI_MouseEvent(x, y);
#endif
}
@@ -230,9 +234,10 @@ void IN_MouseEvent( int x, int y ) {
IN_WarpMouse
================
*/
-void IN_WarpMouse( int x, int y ) {
- if( input.initialized && input.api.Warp ) {
- input.api.Warp( x, y );
+void IN_WarpMouse(int x, int y)
+{
+ if (input.initialized && input.api.Warp) {
+ input.api.Warp(x, y);
}
}
@@ -241,24 +246,27 @@ void IN_WarpMouse( int x, int y ) {
IN_Shutdown
============
*/
-void IN_Shutdown( void ) {
- if( input.initialized ) {
+void IN_Shutdown(void)
+{
+ if (input.initialized) {
#if USE_DINPUT
in_direct->changed = NULL;
#endif
input.api.Shutdown();
- memset( &input, 0, sizeof( input ) );
+ memset(&input, 0, sizeof(input));
}
#if USE_LIRC
Lirc_Shutdown();
#endif
}
-static void in_changed_hard( cvar_t *self ) {
+static void in_changed_hard(cvar_t *self)
+{
input.modified = qtrue;
}
-static void in_changed_soft( cvar_t *self ) {
+static void in_changed_soft(cvar_t *self)
+{
IN_Activate();
}
@@ -267,36 +275,37 @@ static void in_changed_soft( cvar_t *self ) {
IN_Init
============
*/
-void IN_Init( void ) {
+void IN_Init(void)
+{
qboolean ret = qfalse;
#if USE_LIRC
Lirc_Init();
#endif
- in_enable = Cvar_Get( "in_enable", "1", 0 );
+ in_enable = Cvar_Get("in_enable", "1", 0);
in_enable->changed = in_changed_hard;
- if( !in_enable->integer ) {
- Com_Printf( "Mouse input disabled.\n" );
+ if (!in_enable->integer) {
+ Com_Printf("Mouse input disabled.\n");
return;
}
#if USE_DINPUT
- in_direct = Cvar_Get( "in_direct", "1", 0 );
- if( in_direct->integer ) {
- DI_FillAPI( &input.api );
+ in_direct = Cvar_Get("in_direct", "1", 0);
+ if (in_direct->integer) {
+ DI_FillAPI(&input.api);
ret = input.api.Init();
- if( !ret ) {
- Cvar_Set( "in_direct", "0" );
+ if (!ret) {
+ Cvar_Set("in_direct", "0");
}
}
#endif
- if( !ret ) {
- VID_FillInputAPI( &input.api );
+ if (!ret) {
+ VID_FillInputAPI(&input.api);
ret = input.api.Init();
- if( !ret ) {
- Cvar_Set( "in_enable", "0" );
+ if (!ret) {
+ Cvar_Set("in_enable", "0");
return;
}
}
@@ -305,10 +314,10 @@ void IN_Init( void ) {
in_direct->changed = in_changed_hard;
#endif
- in_smart_grab = Cvar_Get( "in_smart_grab", "0", 0 );
+ in_smart_grab = Cvar_Get("in_smart_grab", "0", 0);
in_smart_grab->changed = in_changed_soft;
- in_hide_delay = Cvar_Get( "in_hide_delay", "0", 0 );
+ in_hide_delay = Cvar_Get("in_hide_delay", "0", 0);
in_hide_delay->changed = in_changed_soft;
input.initialized = qtrue;
@@ -359,10 +368,11 @@ static kbutton_t in_up, in_down;
static int in_impulse;
static qboolean in_mlooking;
-static void KeyDown (kbutton_t *b) {
+static void KeyDown(kbutton_t *b)
+{
int k;
char *c;
-
+
c = Cmd_Argv(1);
if (c[0])
k = atoi(c);
@@ -371,16 +381,16 @@ static void KeyDown (kbutton_t *b) {
if (k == b->down[0] || k == b->down[1])
return; // repeating key
-
+
if (!b->down[0])
b->down[0] = k;
else if (!b->down[1])
b->down[1] = k;
else {
- Com_WPrintf ("Three keys down for a button!\n");
+ Com_WPrintf("Three keys down for a button!\n");
return;
}
-
+
if (b->state & 1)
return; // still down
@@ -394,7 +404,8 @@ static void KeyDown (kbutton_t *b) {
b->state |= 1 + 2; // down + impulse down
}
-static void KeyUp (kbutton_t *b) {
+static void KeyUp(kbutton_t *b)
+{
int k;
char *c;
unsigned uptime;
@@ -424,80 +435,97 @@ static void KeyUp (kbutton_t *b) {
// save timestamp
c = Cmd_Argv(2);
uptime = atoi(c);
- if( !uptime ) {
+ if (!uptime) {
b->msec += 10;
- } else if( uptime > b->downtime ) {
+ } else if (uptime > b->downtime) {
b->msec += uptime - b->downtime;
}
b->state &= ~1; // now up
}
-static void KeyClear( kbutton_t *b ) {
+static void KeyClear(kbutton_t *b)
+{
b->msec = 0;
b->state &= ~2; // clear impulses
- if( b->state & 1 ) {
+ if (b->state & 1) {
b->downtime = com_eventTime; // still down
}
}
-static void IN_KLookDown( void ) { KeyDown( &in_klook ); }
-static void IN_KLookUp( void ) { KeyUp( &in_klook ); }
-static void IN_UpDown( void ) { KeyDown( &in_up ); }
-static void IN_UpUp( void ) { KeyUp( &in_up ); }
-static void IN_DownDown( void ) { KeyDown( &in_down ); }
-static void IN_DownUp( void ) { KeyUp( &in_down ); }
-static void IN_LeftDown( void ) { KeyDown( &in_left ); }
-static void IN_LeftUp( void ) { KeyUp( &in_left ); }
-static void IN_RightDown( void ) { KeyDown( &in_right ); }
-static void IN_RightUp( void ) { KeyUp( &in_right ); }
-static void IN_ForwardDown( void ) { KeyDown( &in_forward ); }
-static void IN_ForwardUp( void ) { KeyUp( &in_forward ); }
-static void IN_BackDown( void ) { KeyDown( &in_back ); }
-static void IN_BackUp( void ) { KeyUp( &in_back ); }
-static void IN_LookupDown( void ) { KeyDown( &in_lookup ); }
-static void IN_LookupUp( void ) { KeyUp( &in_lookup ); }
-static void IN_LookdownDown( void ) { KeyDown( &in_lookdown ); }
-static void IN_LookdownUp( void ) { KeyUp( &in_lookdown ); }
-static void IN_MoveleftDown( void ) { KeyDown( &in_moveleft ); }
-static void IN_MoveleftUp( void ) { KeyUp( &in_moveleft ); }
-static void IN_MoverightDown( void ) { KeyDown( &in_moveright ); }
-static void IN_MoverightUp( void ) { KeyUp( &in_moveright ); }
-static void IN_SpeedDown( void ) { KeyDown( &in_speed ); }
-static void IN_SpeedUp( void ) { KeyUp( &in_speed ); }
-static void IN_StrafeDown( void ) { KeyDown( &in_strafe ); }
-static void IN_StrafeUp( void ) { KeyUp( &in_strafe ); }
-static void IN_AttackDown( void ) {
- KeyDown( &in_attack );
- if( cl_instantpacket->integer ) {
+static void IN_KLookDown(void) { KeyDown(&in_klook); }
+static void IN_KLookUp(void) { KeyUp(&in_klook); }
+static void IN_UpDown(void) { KeyDown(&in_up); }
+static void IN_UpUp(void) { KeyUp(&in_up); }
+static void IN_DownDown(void) { KeyDown(&in_down); }
+static void IN_DownUp(void) { KeyUp(&in_down); }
+static void IN_LeftDown(void) { KeyDown(&in_left); }
+static void IN_LeftUp(void) { KeyUp(&in_left); }
+static void IN_RightDown(void) { KeyDown(&in_right); }
+static void IN_RightUp(void) { KeyUp(&in_right); }
+static void IN_ForwardDown(void) { KeyDown(&in_forward); }
+static void IN_ForwardUp(void) { KeyUp(&in_forward); }
+static void IN_BackDown(void) { KeyDown(&in_back); }
+static void IN_BackUp(void) { KeyUp(&in_back); }
+static void IN_LookupDown(void) { KeyDown(&in_lookup); }
+static void IN_LookupUp(void) { KeyUp(&in_lookup); }
+static void IN_LookdownDown(void) { KeyDown(&in_lookdown); }
+static void IN_LookdownUp(void) { KeyUp(&in_lookdown); }
+static void IN_MoveleftDown(void) { KeyDown(&in_moveleft); }
+static void IN_MoveleftUp(void) { KeyUp(&in_moveleft); }
+static void IN_MoverightDown(void) { KeyDown(&in_moveright); }
+static void IN_MoverightUp(void) { KeyUp(&in_moveright); }
+static void IN_SpeedDown(void) { KeyDown(&in_speed); }
+static void IN_SpeedUp(void) { KeyUp(&in_speed); }
+static void IN_StrafeDown(void) { KeyDown(&in_strafe); }
+static void IN_StrafeUp(void) { KeyUp(&in_strafe); }
+
+static void IN_AttackDown(void)
+{
+ KeyDown(&in_attack);
+ if (cl_instantpacket->integer) {
cl.sendPacketNow = qtrue;
}
}
-static void IN_AttackUp( void ) { KeyUp( &in_attack ); }
-static void IN_UseDown ( void ) {
- KeyDown( &in_use );
- if( cl_instantpacket->integer ) {
+
+static void IN_AttackUp(void)
+{
+ KeyUp(&in_attack);
+}
+
+static void IN_UseDown(void)
+{
+ KeyDown(&in_use);
+ if (cl_instantpacket->integer) {
cl.sendPacketNow = qtrue;
}
}
-static void IN_UseUp ( void ) { KeyUp( &in_use ); }
-static void IN_Impulse ( void ) {
- in_impulse = atoi( Cmd_Argv( 1 ) );
+static void IN_UseUp(void)
+{
+ KeyUp(&in_use);
}
-static void IN_CenterView( void ) {
- cl.viewangles[PITCH] = -SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
+static void IN_Impulse(void)
+{
+ in_impulse = atoi(Cmd_Argv(1));
}
-static void IN_MLookDown( void ) {
+static void IN_CenterView(void)
+{
+ cl.viewangles[PITCH] = -SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[PITCH]);
+}
+
+static void IN_MLookDown(void)
+{
in_mlooking = qtrue;
}
-static void IN_MLookUp( void ) {
+static void IN_MLookUp(void)
+{
in_mlooking = qfalse;
- if( !freelook->integer && lookspring->integer )
+ if (!freelook->integer && lookspring->integer)
IN_CenterView();
}
@@ -508,24 +536,25 @@ CL_KeyState
Returns the fraction of the frame that the key was down
===============
*/
-static float CL_KeyState( kbutton_t *key ) {
+static float CL_KeyState(kbutton_t *key)
+{
unsigned msec = key->msec;
float val;
- if( key->state & 1 ) {
+ if (key->state & 1) {
// still down
- if( com_eventTime > key->downtime ) {
+ if (com_eventTime > key->downtime) {
msec += com_eventTime - key->downtime;
}
}
- if( !cl.cmd.msec ) {
+ if (!cl.cmd.msec) {
return 0;
}
- val = ( float )msec / cl.cmd.msec;
+ val = (float)msec / cl.cmd.msec;
- return clamp( val, 0, 1 );
+ return clamp(val, 0, 1);
}
//==========================================================================
@@ -535,25 +564,26 @@ static float CL_KeyState( kbutton_t *key ) {
CL_MouseMove
================
*/
-static void CL_MouseMove( void ) {
+static void CL_MouseMove(void)
+{
static int old_dx, old_dy;
int dx, dy;
float mx, my;
float speed;
- if( !input.initialized ) {
+ if (!input.initialized) {
return;
}
- if( cls.key_dest & (KEY_MENU|KEY_CONSOLE) ) {
+ if (cls.key_dest & (KEY_MENU | KEY_CONSOLE)) {
return;
}
- if( !input.api.GetMotion( &dx, &dy ) ) {
+ if (!input.api.GetMotion(&dx, &dy)) {
return;
}
- if( m_filter->integer ) {
- mx = ( dx + old_dx ) * 0.5f;
- my = ( dy + old_dy ) * 0.5f;
+ if (m_filter->integer) {
+ mx = (dx + old_dx) * 0.5f;
+ my = (dy + old_dy) * 0.5f;
} else {
mx = dx;
my = dy;
@@ -562,31 +592,31 @@ static void CL_MouseMove( void ) {
old_dx = dx;
old_dy = dy;
- if( !mx && !my ) {
+ if (!mx && !my) {
return;
}
- Cvar_ClampValue( m_accel, 0, 1 );
+ Cvar_ClampValue(m_accel, 0, 1);
- speed = sqrt( mx * mx + my * my );
+ speed = sqrt(mx * mx + my * my);
speed = sensitivity->value + speed * m_accel->value;
mx *= speed;
my *= speed;
- if( m_autosens->integer ) {
+ if (m_autosens->integer) {
mx *= cl.fov_x / 90.0f;
- my *= V_CalcFov( cl.fov_x, 4, 3 ) / 73.739795291688f;
+ my *= V_CalcFov(cl.fov_x, 4, 3) / 73.739795291688f;
}
// add mouse X/Y movement
- if( ( in_strafe.state & 1 ) || ( lookstrafe->integer && !in_mlooking ) ) {
+ if ((in_strafe.state & 1) || (lookstrafe->integer && !in_mlooking)) {
cl.mousemove[1] += m_side->value * mx;
} else {
cl.viewangles[YAW] -= m_yaw->value * mx;
}
- if( ( in_mlooking || freelook->integer ) && !( in_strafe.state & 1 ) ) {
+ if ((in_mlooking || freelook->integer) && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * my;
} else {
cl.mousemove[0] -= m_forward->value * my;
@@ -601,25 +631,26 @@ CL_AdjustAngles
Moves the local angle positions
================
*/
-static void CL_AdjustAngles( int msec ) {
+static void CL_AdjustAngles(int msec)
+{
float speed;
-
- if( in_speed.state & 1 )
+
+ if (in_speed.state & 1)
speed = msec * cl_anglespeedkey->value * 0.001f;
else
speed = msec * 0.001f;
- if( !( in_strafe.state & 1 ) ) {
- cl.viewangles[YAW] -= speed*cl_yawspeed->value*CL_KeyState(&in_right);
- cl.viewangles[YAW] += speed*cl_yawspeed->value*CL_KeyState(&in_left);
+ if (!(in_strafe.state & 1)) {
+ cl.viewangles[YAW] -= speed * cl_yawspeed->value * CL_KeyState(&in_right);
+ cl.viewangles[YAW] += speed * cl_yawspeed->value * CL_KeyState(&in_left);
}
- if( in_klook.state & 1 ) {
- cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_forward);
- cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_back);
+ if (in_klook.state & 1) {
+ cl.viewangles[PITCH] -= speed * cl_pitchspeed->value * CL_KeyState(&in_forward);
+ cl.viewangles[PITCH] += speed * cl_pitchspeed->value * CL_KeyState(&in_back);
}
-
- cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_lookup);
- cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_lookdown);
+
+ cl.viewangles[PITCH] -= speed * cl_pitchspeed->value * CL_KeyState(&in_lookup);
+ cl.viewangles[PITCH] += speed * cl_pitchspeed->value * CL_KeyState(&in_lookdown);
}
/*
@@ -629,41 +660,44 @@ CL_BaseMove
Build the intended movement vector
================
*/
-static void CL_BaseMove( vec3_t move ) {
- if( in_strafe.state & 1 ) {
- move[1] += cl_sidespeed->value * CL_KeyState( &in_right );
- move[1] -= cl_sidespeed->value * CL_KeyState( &in_left );
+static void CL_BaseMove(vec3_t move)
+{
+ if (in_strafe.state & 1) {
+ move[1] += cl_sidespeed->value * CL_KeyState(&in_right);
+ move[1] -= cl_sidespeed->value * CL_KeyState(&in_left);
}
- move[1] += cl_sidespeed->value * CL_KeyState( &in_moveright );
- move[1] -= cl_sidespeed->value * CL_KeyState( &in_moveleft );
+ move[1] += cl_sidespeed->value * CL_KeyState(&in_moveright);
+ move[1] -= cl_sidespeed->value * CL_KeyState(&in_moveleft);
- move[2] += cl_upspeed->value * CL_KeyState( &in_up );
- move[2] -= cl_upspeed->value * CL_KeyState( &in_down );
+ move[2] += cl_upspeed->value * CL_KeyState(&in_up);
+ move[2] -= cl_upspeed->value * CL_KeyState(&in_down);
- if( !( in_klook.state & 1 ) ) {
- move[0] += cl_forwardspeed->value * CL_KeyState( &in_forward );
- move[0] -= cl_forwardspeed->value * CL_KeyState( &in_back );
+ if (!(in_klook.state & 1)) {
+ move[0] += cl_forwardspeed->value * CL_KeyState(&in_forward);
+ move[0] -= cl_forwardspeed->value * CL_KeyState(&in_back);
}
// adjust for speed key / running
- if( ( in_speed.state & 1 ) ^ cl_run->integer ) {
- VectorScale( move, 2, move );
+ if ((in_speed.state & 1) ^ cl_run->integer) {
+ VectorScale(move, 2, move);
}
}
-static void CL_ClampSpeed( vec3_t move ) {
+static void CL_ClampSpeed(vec3_t move)
+{
float speed = cl.pmp.maxspeed;
- clamp( move[0], -speed, speed );
- clamp( move[1], -speed, speed );
- clamp( move[2], -speed, speed );
+ clamp(move[0], -speed, speed);
+ clamp(move[1], -speed, speed);
+ clamp(move[2], -speed, speed);
}
-static void CL_ClampPitch( void ) {
+static void CL_ClampPitch(void)
+{
float pitch;
- pitch = SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
+ pitch = SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[PITCH]);
if (pitch > 180)
pitch -= 360;
@@ -686,10 +720,11 @@ Updates msec, angles and builds interpolated movement vector for local predictio
Doesn't touch command forward/side/upmove, these are filled by CL_FinalizeCmd.
=================
*/
-void CL_UpdateCmd( int msec ) {
- VectorClear( cl.localmove );
+void CL_UpdateCmd(int msec)
+{
+ VectorClear(cl.localmove);
- if( sv_paused->integer ) {
+ if (sv_paused->integer) {
return;
}
@@ -697,10 +732,10 @@ void CL_UpdateCmd( int msec ) {
cl.cmd.msec += msec;
// adjust viewangles
- CL_AdjustAngles( msec );
+ CL_AdjustAngles(msec);
// get basic movement from keyboard
- CL_BaseMove( cl.localmove );
+ CL_BaseMove(cl.localmove);
// allow mice to add to the move
CL_MouseMove();
@@ -710,13 +745,13 @@ void CL_UpdateCmd( int msec ) {
cl.localmove[1] += cl.mousemove[1];
// clamp to server defined max speed
- CL_ClampSpeed( cl.localmove );
+ CL_ClampSpeed(cl.localmove);
CL_ClampPitch();
-
- cl.cmd.angles[0] = ANGLE2SHORT( cl.viewangles[0] );
- cl.cmd.angles[1] = ANGLE2SHORT( cl.viewangles[1] );
- cl.cmd.angles[2] = ANGLE2SHORT( cl.viewangles[2] );
+
+ cl.cmd.angles[0] = ANGLE2SHORT(cl.viewangles[0]);
+ cl.cmd.angles[1] = ANGLE2SHORT(cl.viewangles[1]);
+ cl.cmd.angles[2] = ANGLE2SHORT(cl.viewangles[2]);
}
@@ -725,75 +760,76 @@ void CL_UpdateCmd( int msec ) {
CL_RegisterInput
============
*/
-void CL_RegisterInput( void ) {
- Cmd_AddCommand ("centerview",IN_CenterView);
-
- Cmd_AddCommand ("+moveup",IN_UpDown);
- Cmd_AddCommand ("-moveup",IN_UpUp);
- Cmd_AddCommand ("+movedown",IN_DownDown);
- Cmd_AddCommand ("-movedown",IN_DownUp);
- Cmd_AddCommand ("+left",IN_LeftDown);
- Cmd_AddCommand ("-left",IN_LeftUp);
- Cmd_AddCommand ("+right",IN_RightDown);
- Cmd_AddCommand ("-right",IN_RightUp);
- Cmd_AddCommand ("+forward",IN_ForwardDown);
- Cmd_AddCommand ("-forward",IN_ForwardUp);
- Cmd_AddCommand ("+back",IN_BackDown);
- Cmd_AddCommand ("-back",IN_BackUp);
- Cmd_AddCommand ("+lookup", IN_LookupDown);
- Cmd_AddCommand ("-lookup", IN_LookupUp);
- Cmd_AddCommand ("+lookdown", IN_LookdownDown);
- Cmd_AddCommand ("-lookdown", IN_LookdownUp);
- Cmd_AddCommand ("+strafe", IN_StrafeDown);
- Cmd_AddCommand ("-strafe", IN_StrafeUp);
- Cmd_AddCommand ("+moveleft", IN_MoveleftDown);
- Cmd_AddCommand ("-moveleft", IN_MoveleftUp);
- Cmd_AddCommand ("+moveright", IN_MoverightDown);
- Cmd_AddCommand ("-moveright", IN_MoverightUp);
- Cmd_AddCommand ("+speed", IN_SpeedDown);
- Cmd_AddCommand ("-speed", IN_SpeedUp);
- Cmd_AddCommand ("+attack", IN_AttackDown);
- Cmd_AddCommand ("-attack", IN_AttackUp);
- Cmd_AddCommand ("+use", IN_UseDown);
- Cmd_AddCommand ("-use", IN_UseUp);
- Cmd_AddCommand ("impulse", IN_Impulse);
- Cmd_AddCommand ("+klook", IN_KLookDown);
- Cmd_AddCommand ("-klook", IN_KLookUp);
- Cmd_AddCommand( "+mlook", IN_MLookDown );
- Cmd_AddCommand( "-mlook", IN_MLookUp );
-
- Cmd_AddCommand( "in_restart", IN_Restart_f );
-
- cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0);
- cl_maxpackets = Cvar_Get( "cl_maxpackets", "30", 0 );
- cl_fuzzhack = Cvar_Get( "cl_fuzzhack", "0", 0 );
- cl_packetdup = Cvar_Get( "cl_packetdup", "1", 0 );
+void CL_RegisterInput(void)
+{
+ Cmd_AddCommand("centerview", IN_CenterView);
+
+ Cmd_AddCommand("+moveup", IN_UpDown);
+ Cmd_AddCommand("-moveup", IN_UpUp);
+ Cmd_AddCommand("+movedown", IN_DownDown);
+ Cmd_AddCommand("-movedown", IN_DownUp);
+ Cmd_AddCommand("+left", IN_LeftDown);
+ Cmd_AddCommand("-left", IN_LeftUp);
+ Cmd_AddCommand("+right", IN_RightDown);
+ Cmd_AddCommand("-right", IN_RightUp);
+ Cmd_AddCommand("+forward", IN_ForwardDown);
+ Cmd_AddCommand("-forward", IN_ForwardUp);
+ Cmd_AddCommand("+back", IN_BackDown);
+ Cmd_AddCommand("-back", IN_BackUp);
+ Cmd_AddCommand("+lookup", IN_LookupDown);
+ Cmd_AddCommand("-lookup", IN_LookupUp);
+ Cmd_AddCommand("+lookdown", IN_LookdownDown);
+ Cmd_AddCommand("-lookdown", IN_LookdownUp);
+ Cmd_AddCommand("+strafe", IN_StrafeDown);
+ Cmd_AddCommand("-strafe", IN_StrafeUp);
+ Cmd_AddCommand("+moveleft", IN_MoveleftDown);
+ Cmd_AddCommand("-moveleft", IN_MoveleftUp);
+ Cmd_AddCommand("+moveright", IN_MoverightDown);
+ Cmd_AddCommand("-moveright", IN_MoverightUp);
+ Cmd_AddCommand("+speed", IN_SpeedDown);
+ Cmd_AddCommand("-speed", IN_SpeedUp);
+ Cmd_AddCommand("+attack", IN_AttackDown);
+ Cmd_AddCommand("-attack", IN_AttackUp);
+ Cmd_AddCommand("+use", IN_UseDown);
+ Cmd_AddCommand("-use", IN_UseUp);
+ Cmd_AddCommand("impulse", IN_Impulse);
+ Cmd_AddCommand("+klook", IN_KLookDown);
+ Cmd_AddCommand("-klook", IN_KLookUp);
+ Cmd_AddCommand("+mlook", IN_MLookDown);
+ Cmd_AddCommand("-mlook", IN_MLookUp);
+
+ Cmd_AddCommand("in_restart", IN_Restart_f);
+
+ cl_nodelta = Cvar_Get("cl_nodelta", "0", 0);
+ cl_maxpackets = Cvar_Get("cl_maxpackets", "30", 0);
+ cl_fuzzhack = Cvar_Get("cl_fuzzhack", "0", 0);
+ cl_packetdup = Cvar_Get("cl_packetdup", "1", 0);
#ifdef _DEBUG
- cl_showpackets = Cvar_Get( "cl_showpackets", "0", 0 );
+ cl_showpackets = Cvar_Get("cl_showpackets", "0", 0);
#endif
- cl_instantpacket = Cvar_Get( "cl_instantpacket", "1", 0 );
- cl_batchcmds = Cvar_Get( "cl_batchcmds", "1", 0 );
-
- cl_upspeed = Cvar_Get ( "cl_upspeed", "200", 0 );
- cl_forwardspeed = Cvar_Get ( "cl_forwardspeed", "200", 0 );
- cl_sidespeed = Cvar_Get ( "cl_sidespeed", "200", 0 );
- cl_yawspeed = Cvar_Get ( "cl_yawspeed", "140", 0 );
- cl_pitchspeed = Cvar_Get ( "cl_pitchspeed", "150", CVAR_CHEAT );
- cl_anglespeedkey = Cvar_Get ( "cl_anglespeedkey", "1.5", CVAR_CHEAT );
- cl_run = Cvar_Get( "cl_run", "1", CVAR_ARCHIVE );
-
- freelook = Cvar_Get( "freelook", "1", CVAR_ARCHIVE );
- lookspring = Cvar_Get ( "lookspring", "0", CVAR_ARCHIVE );
- lookstrafe = Cvar_Get ( "lookstrafe", "0", CVAR_ARCHIVE );
- sensitivity = Cvar_Get ( "sensitivity", "3", CVAR_ARCHIVE );
-
- m_pitch = Cvar_Get ( "m_pitch", "0.022", CVAR_ARCHIVE );
- m_yaw = Cvar_Get ( "m_yaw", "0.022", 0 );
- m_forward = Cvar_Get ( "m_forward", "1", 0 );
- m_side = Cvar_Get ( "m_side", "1", 0 );
- m_filter = Cvar_Get( "m_filter", "0", 0 );
- m_accel = Cvar_Get( "m_accel", "0", 0 );
- m_autosens = Cvar_Get( "m_autosens", "0", 0 );
+ cl_instantpacket = Cvar_Get("cl_instantpacket", "1", 0);
+ cl_batchcmds = Cvar_Get("cl_batchcmds", "1", 0);
+
+ cl_upspeed = Cvar_Get("cl_upspeed", "200", 0);
+ cl_forwardspeed = Cvar_Get("cl_forwardspeed", "200", 0);
+ cl_sidespeed = Cvar_Get("cl_sidespeed", "200", 0);
+ cl_yawspeed = Cvar_Get("cl_yawspeed", "140", 0);
+ cl_pitchspeed = Cvar_Get("cl_pitchspeed", "150", CVAR_CHEAT);
+ cl_anglespeedkey = Cvar_Get("cl_anglespeedkey", "1.5", CVAR_CHEAT);
+ cl_run = Cvar_Get("cl_run", "1", CVAR_ARCHIVE);
+
+ freelook = Cvar_Get("freelook", "1", CVAR_ARCHIVE);
+ lookspring = Cvar_Get("lookspring", "0", CVAR_ARCHIVE);
+ lookstrafe = Cvar_Get("lookstrafe", "0", CVAR_ARCHIVE);
+ sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE);
+
+ m_pitch = Cvar_Get("m_pitch", "0.022", CVAR_ARCHIVE);
+ m_yaw = Cvar_Get("m_yaw", "0.022", 0);
+ m_forward = Cvar_Get("m_forward", "1", 0);
+ m_side = Cvar_Get("m_side", "1", 0);
+ m_filter = Cvar_Get("m_filter", "0", 0);
+ m_accel = Cvar_Get("m_accel", "0", 0);
+ m_autosens = Cvar_Get("m_autosens", "0", 0);
}
/*
@@ -804,56 +840,57 @@ Builds the actual movement vector for sending to server. Assumes that msec
and angles are already set for this frame by CL_UpdateCmd.
=================
*/
-void CL_FinalizeCmd( void ) {
+void CL_FinalizeCmd(void)
+{
vec3_t move;
// command buffer ticks in sync with cl_maxfps
- if( cmd_buffer.waitCount > 0 ) {
+ if (cmd_buffer.waitCount > 0) {
cmd_buffer.waitCount--;
}
- if( cl_cmdbuf.waitCount > 0 ) {
+ if (cl_cmdbuf.waitCount > 0) {
cl_cmdbuf.waitCount--;
}
- if( cls.state < ca_active ) {
+ if (cls.state < ca_active) {
return; // not talking to a server
}
- if( sv_paused->integer ) {
+ if (sv_paused->integer) {
return;
}
//
// figure button bits
-//
- if( in_attack.state & 3 )
+//
+ if (in_attack.state & 3)
cl.cmd.buttons |= BUTTON_ATTACK;
- if( in_use.state & 3 )
+ if (in_use.state & 3)
cl.cmd.buttons |= BUTTON_USE;
in_attack.state &= ~2;
in_use.state &= ~2;
- if( cls.key_dest == KEY_GAME && Key_AnyKeyDown() ) {
+ if (cls.key_dest == KEY_GAME && Key_AnyKeyDown()) {
cl.cmd.buttons |= BUTTON_ANY;
}
- if( cl.cmd.msec > 250 ) {
+ if (cl.cmd.msec > 250) {
cl.cmd.msec = 100; // time was unreasonable
}
// rebuild the movement vector
- VectorClear( move );
+ VectorClear(move);
// get basic movement from keyboard
- CL_BaseMove( move );
+ CL_BaseMove(move);
// add mouse forward/side movement
move[0] += cl.mousemove[0];
move[1] += cl.mousemove[1];
// clamp to server defined max speed
- CL_ClampSpeed( move );
+ CL_ClampSpeed(move);
// store the movement vector
cl.cmd.forwardmove = move[0];
@@ -864,20 +901,20 @@ void CL_FinalizeCmd( void ) {
cl.mousemove[0] = 0;
cl.mousemove[1] = 0;
- KeyClear( &in_right );
- KeyClear( &in_left );
+ KeyClear(&in_right);
+ KeyClear(&in_left);
- KeyClear( &in_moveright );
- KeyClear( &in_moveleft );
+ KeyClear(&in_moveright);
+ KeyClear(&in_moveleft);
- KeyClear( &in_up );
- KeyClear( &in_down );
+ KeyClear(&in_up);
+ KeyClear(&in_down);
- KeyClear( &in_forward );
- KeyClear( &in_back );
+ KeyClear(&in_forward);
+ KeyClear(&in_back);
- KeyClear( &in_lookup );
- KeyClear( &in_lookdown );
+ KeyClear(&in_lookup);
+ KeyClear(&in_lookdown);
cl.cmd.impulse = in_impulse;
in_impulse = 0;
@@ -887,43 +924,45 @@ void CL_FinalizeCmd( void ) {
cl.cmds[cl.cmdNumber & CMD_MASK] = cl.cmd;
// clear pending cmd
- memset( &cl.cmd, 0, sizeof( cl.cmd ) );
+ memset(&cl.cmd, 0, sizeof(cl.cmd));
}
-static inline qboolean ready_to_send( void ) {
+static inline qboolean ready_to_send(void)
+{
unsigned msec;
- if( cl.sendPacketNow ) {
+ if (cl.sendPacketNow) {
return qtrue;
}
- if( cls.netchan->message.cursize || cls.netchan->reliable_ack_pending ) {
+ if (cls.netchan->message.cursize || cls.netchan->reliable_ack_pending) {
return qtrue;
}
- if( !cl_maxpackets->integer ) {
+ if (!cl_maxpackets->integer) {
return qtrue;
}
- if( cl_maxpackets->integer < 10 ) {
- Cvar_Set( "cl_maxpackets", "10" );
+ if (cl_maxpackets->integer < 10) {
+ Cvar_Set("cl_maxpackets", "10");
}
msec = 1000 / cl_maxpackets->integer;
- if( msec ) {
- msec = 100 / ( 100 / msec );
+ if (msec) {
+ msec = 100 / (100 / msec);
}
- if( cls.realtime - cl.lastTransmitTime < msec ) {
+ if (cls.realtime - cl.lastTransmitTime < msec) {
return qfalse;
}
return qtrue;
}
-static inline qboolean ready_to_send_hacked( void ) {
- if( !cl_fuzzhack->integer ) {
+static inline qboolean ready_to_send_hacked(void)
+{
+ if (!cl_fuzzhack->integer) {
return qtrue; // packet drop hack disabled
}
- if( cl.cmdNumber - cl.lastTransmitCmdNumberReal > 2 ) {
+ if (cl.cmdNumber - cl.lastTransmitCmdNumberReal > 2) {
return qtrue; // can't drop more than 2 cmds
}
@@ -935,7 +974,8 @@ static inline qboolean ready_to_send_hacked( void ) {
CL_SendDefaultCmd
=================
*/
-static void CL_SendDefaultCmd( void ) {
+static void CL_SendDefaultCmd(void)
+{
size_t cursize, checksumIndex;
usercmd_t *cmd, *oldcmd;
client_history_t *history;
@@ -949,7 +989,7 @@ static void CL_SendDefaultCmd( void ) {
cl.lastTransmitCmdNumber = cl.cmdNumber;
// see if we are ready to send this packet
- if( !ready_to_send_hacked() ) {
+ if (!ready_to_send_hacked()) {
cls.netchan->outgoing_sequence++; // just drop the packet
return;
}
@@ -958,45 +998,45 @@ static void CL_SendDefaultCmd( void ) {
cl.lastTransmitCmdNumberReal = cl.cmdNumber;
// begin a client move command
- MSG_WriteByte( clc_move );
+ MSG_WriteByte(clc_move);
// save the position for a checksum byte
checksumIndex = 0;
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
+ if (cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT) {
checksumIndex = msg_write.cursize;
- SZ_GetSpace( &msg_write, 1 );
+ SZ_GetSpace(&msg_write, 1);
}
// let the server know what the last frame we
// got was, so the next message can be delta compressed
- if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
- MSG_WriteLong( -1 ); // no compression
+ if (cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/) {
+ MSG_WriteLong(-1); // no compression
} else {
- MSG_WriteLong( cl.frame.number );
+ MSG_WriteLong(cl.frame.number);
}
// send this and the previous cmds in the message, so
// if the last packet was dropped, it can be recovered
- cmd = &cl.cmds[( cl.cmdNumber - 2 ) & CMD_MASK];
- MSG_WriteDeltaUsercmd( NULL, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
+ cmd = &cl.cmds[(cl.cmdNumber - 2) & CMD_MASK];
+ MSG_WriteDeltaUsercmd(NULL, cmd, cls.protocolVersion);
+ MSG_WriteByte(cl.lightlevel);
oldcmd = cmd;
- cmd = &cl.cmds[( cl.cmdNumber - 1 ) & CMD_MASK];
- MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
+ cmd = &cl.cmds[(cl.cmdNumber - 1) & CMD_MASK];
+ MSG_WriteDeltaUsercmd(oldcmd, cmd, cls.protocolVersion);
+ MSG_WriteByte(cl.lightlevel);
oldcmd = cmd;
cmd = &cl.cmds[cl.cmdNumber & CMD_MASK];
- MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
+ MSG_WriteDeltaUsercmd(oldcmd, cmd, cls.protocolVersion);
+ MSG_WriteByte(cl.lightlevel);
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
+ if (cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT) {
// calculate a checksum over the move commands
msg_write.data[checksumIndex] = COM_BlockSequenceCRCByte(
- msg_write.data + checksumIndex + 1,
- msg_write.cursize - checksumIndex - 1,
- cls.netchan->outgoing_sequence );
+ msg_write.data + checksumIndex + 1,
+ msg_write.cursize - checksumIndex - 1,
+ cls.netchan->outgoing_sequence);
}
P_FRAMES++;
@@ -1004,14 +1044,14 @@ static void CL_SendDefaultCmd( void ) {
//
// deliver the message
//
- cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data, 1 );
+ cursize = cls.netchan->Transmit(cls.netchan, msg_write.cursize, msg_write.data, 1);
#ifdef _DEBUG
- if( cl_showpackets->integer ) {
- Com_Printf( "%"PRIz" ", cursize );
+ if (cl_showpackets->integer) {
+ Com_Printf("%"PRIz" ", cursize);
}
#endif
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
/*
@@ -1019,7 +1059,8 @@ static void CL_SendDefaultCmd( void ) {
CL_SendBatchedCmd
=================
*/
-static void CL_SendBatchedCmd( void ) {
+static void CL_SendBatchedCmd(void)
+{
int i, j, seq, bits;
int numCmds, numDups;
int totalCmds, totalMsec;
@@ -1029,7 +1070,7 @@ static void CL_SendBatchedCmd( void ) {
byte *patch;
// see if we are ready to send this packet
- if( !ready_to_send() ) {
+ if (!ready_to_send()) {
return;
}
@@ -1045,49 +1086,49 @@ static void CL_SendBatchedCmd( void ) {
cl.lastTransmitCmdNumberReal = cl.cmdNumber;
// begin a client move command
- patch = SZ_GetSpace( &msg_write, 1 );
+ patch = SZ_GetSpace(&msg_write, 1);
// let the server know what the last frame we
// got was, so the next message can be delta compressed
- if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
+ if (cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/) {
*patch = clc_move_nodelta; // no compression
} else {
*patch = clc_move_batched;
- MSG_WriteLong( cl.frame.number );
+ MSG_WriteLong(cl.frame.number);
}
- Cvar_ClampInteger( cl_packetdup, 0, MAX_PACKET_FRAMES - 1 );
+ Cvar_ClampInteger(cl_packetdup, 0, MAX_PACKET_FRAMES - 1);
numDups = cl_packetdup->integer;
*patch |= numDups << SVCMD_BITS;
// send lightlevel
- MSG_WriteByte( cl.lightlevel );
+ MSG_WriteByte(cl.lightlevel);
// send this and the previous cmds in the message, so
// if the last packet was dropped, it can be recovered
oldcmd = NULL;
totalCmds = 0;
totalMsec = 0;
- for( i = seq - numDups; i <= seq; i++ ) {
- oldest = &cl.history[( i - 1 ) & CMD_MASK];
+ for (i = seq - numDups; i <= seq; i++) {
+ oldest = &cl.history[(i - 1) & CMD_MASK];
history = &cl.history[i & CMD_MASK];
numCmds = history->cmdNumber - oldest->cmdNumber;
- if( numCmds >= MAX_PACKET_USERCMDS ) {
- Com_WPrintf( "%s: MAX_PACKET_USERCMDS exceeded\n", __func__ );
- SZ_Clear( &msg_write );
+ if (numCmds >= MAX_PACKET_USERCMDS) {
+ Com_WPrintf("%s: MAX_PACKET_USERCMDS exceeded\n", __func__);
+ SZ_Clear(&msg_write);
break;
}
totalCmds += numCmds;
- MSG_WriteBits( numCmds, 5 );
- for( j = oldest->cmdNumber + 1; j <= history->cmdNumber; j++ ) {
+ MSG_WriteBits(numCmds, 5);
+ for (j = oldest->cmdNumber + 1; j <= history->cmdNumber; j++) {
cmd = &cl.cmds[j & CMD_MASK];
totalMsec += cmd->msec;
- bits = MSG_WriteDeltaUsercmd_Enhanced( oldcmd, cmd, cls.protocolVersion );
+ bits = MSG_WriteDeltaUsercmd_Enhanced(oldcmd, cmd, cls.protocolVersion);
#ifdef _DEBUG
- if( cl_showpackets->integer == 3 ) {
- MSG_ShowDeltaUsercmdBits_Enhanced( bits );
+ if (cl_showpackets->integer == 3) {
+ MSG_ShowDeltaUsercmdBits_Enhanced(bits);
}
#endif
oldcmd = cmd;
@@ -1099,21 +1140,22 @@ static void CL_SendBatchedCmd( void ) {
//
// deliver the message
//
- cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data, 1 );
+ cursize = cls.netchan->Transmit(cls.netchan, msg_write.cursize, msg_write.data, 1);
#ifdef _DEBUG
- if( cl_showpackets->integer == 1 ) {
- Com_Printf( "%"PRIz"(%i) ", cursize, totalCmds );
- } else if( cl_showpackets->integer == 2 ) {
- Com_Printf( "%"PRIz"(%i) ", cursize, totalMsec );
- } else if( cl_showpackets->integer == 3 ) {
- Com_Printf( " | " );
+ if (cl_showpackets->integer == 1) {
+ Com_Printf("%"PRIz"(%i) ", cursize, totalCmds);
+ } else if (cl_showpackets->integer == 2) {
+ Com_Printf("%"PRIz"(%i) ", cursize, totalMsec);
+ } else if (cl_showpackets->integer == 3) {
+ Com_Printf(" | ");
}
#endif
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-static void CL_SendKeepAlive( void ) {
+static void CL_SendKeepAlive(void)
+{
client_history_t *history;
size_t cursize;
@@ -1127,83 +1169,85 @@ static void CL_SendKeepAlive( void ) {
cl.lastTransmitCmdNumber = cl.cmdNumber;
cl.lastTransmitCmdNumberReal = cl.cmdNumber;
- cursize = cls.netchan->Transmit( cls.netchan, 0, NULL, 1 );
+ cursize = cls.netchan->Transmit(cls.netchan, 0, NULL, 1);
#ifdef _DEBUG
- if( cl_showpackets->integer ) {
- Com_Printf( "%"PRIz" ", cursize );
+ if (cl_showpackets->integer) {
+ Com_Printf("%"PRIz" ", cursize);
}
#endif
}
-static void CL_SendUserinfo( void ) {
+static void CL_SendUserinfo(void)
+{
char userinfo[MAX_INFO_STRING];
cvar_t *var;
int i;
- if( !cls.userinfo_modified ) {
+ if (!cls.userinfo_modified) {
return;
}
- if( cls.userinfo_modified == MAX_PACKET_USERINFOS ) {
- size_t len = Cvar_BitInfo( userinfo, CVAR_USERINFO );
- Com_DDPrintf( "%s: %u: full update\n", __func__, com_framenum );
- MSG_WriteByte( clc_userinfo );
- MSG_WriteData( userinfo, len + 1 );
- MSG_FlushTo( &cls.netchan->message );
- } else if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
- Com_DDPrintf( "%s: %u: %d updates\n", __func__, com_framenum,
- cls.userinfo_modified );
- for( i = 0; i < cls.userinfo_modified; i++ ) {
+ if (cls.userinfo_modified == MAX_PACKET_USERINFOS) {
+ size_t len = Cvar_BitInfo(userinfo, CVAR_USERINFO);
+ Com_DDPrintf("%s: %u: full update\n", __func__, com_framenum);
+ MSG_WriteByte(clc_userinfo);
+ MSG_WriteData(userinfo, len + 1);
+ MSG_FlushTo(&cls.netchan->message);
+ } else if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO) {
+ Com_DDPrintf("%s: %u: %d updates\n", __func__, com_framenum,
+ cls.userinfo_modified);
+ for (i = 0; i < cls.userinfo_modified; i++) {
var = cls.userinfo_updates[i];
- MSG_WriteByte( clc_userinfo_delta );
- MSG_WriteString( var->name );
- if( var->flags & CVAR_USERINFO ) {
- MSG_WriteString( var->string );
+ MSG_WriteByte(clc_userinfo_delta);
+ MSG_WriteString(var->name);
+ if (var->flags & CVAR_USERINFO) {
+ MSG_WriteString(var->string);
} else {
// no longer in userinfo
- MSG_WriteString( NULL );
+ MSG_WriteString(NULL);
}
}
- MSG_FlushTo( &cls.netchan->message );
+ MSG_FlushTo(&cls.netchan->message);
} else {
- Com_WPrintf( "%s: update count is %d, should never happen.\n",
- __func__, cls.userinfo_modified );
+ Com_WPrintf("%s: update count is %d, should never happen.\n",
+ __func__, cls.userinfo_modified);
}
cls.userinfo_modified = 0;
}
-void CL_SendCmd( void ) {
- if( cls.state < ca_connected ) {
+void CL_SendCmd(void)
+{
+ if (cls.state < ca_connected) {
return; // not talking to a server
}
// generate usercmds while playing a demo,
// but do not send them
- if( !cls.netchan ) {
+ if (!cls.netchan) {
return;
}
- if( cls.state < ca_active || sv_paused->integer ) {
+ if (cls.state < ca_active || sv_paused->integer) {
// send a userinfo update if needed
CL_SendUserinfo();
// just keepalive or update reliable
- if( cls.netchan->ShouldUpdate( cls.netchan ) ) {
+ if (cls.netchan->ShouldUpdate(cls.netchan)) {
CL_SendKeepAlive();
}
return;
}
// are there any new usercmds to send after all?
- if( cl.lastTransmitCmdNumber == cl.cmdNumber ) {
+ if (cl.lastTransmitCmdNumber == cl.cmdNumber) {
return; // nothing to send
}
// send a userinfo update if needed
CL_SendUserinfo();
- if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO && cl_batchcmds->integer ) {
+ if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO && cl_batchcmds->integer) {
CL_SendBatchedCmd();
} else {
CL_SendDefaultCmd();
diff --git a/src/cl_keys.c b/src/cl_keys.c
index 696b2b1..114178e 100644
--- a/src/cl_keys.c
+++ b/src/cl_keys.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -150,7 +150,8 @@ static const keyname_t keynames[] = {
Key_GetOverstrikeMode
===================
*/
-qboolean Key_GetOverstrikeMode( void ) {
+qboolean Key_GetOverstrikeMode(void)
+{
return key_overstrike;
}
@@ -159,7 +160,8 @@ qboolean Key_GetOverstrikeMode( void ) {
Key_SetOverstrikeMode
===================
*/
-void Key_SetOverstrikeMode( qboolean overstrike ) {
+void Key_SetOverstrikeMode(qboolean overstrike)
+{
key_overstrike = overstrike;
}
@@ -168,7 +170,8 @@ void Key_SetOverstrikeMode( qboolean overstrike ) {
Key_GetDest
===================
*/
-keydest_t Key_GetDest( void ) {
+keydest_t Key_GetDest(void)
+{
return cls.key_dest;
}
@@ -177,17 +180,18 @@ keydest_t Key_GetDest( void ) {
Key_SetDest
===================
*/
-void Key_SetDest( keydest_t dest ) {
+void Key_SetDest(keydest_t dest)
+{
int diff;
// if not connected, console or menu should be up
- if( cls.state < ca_active && !( dest & (KEY_MENU|KEY_CONSOLE) ) ) {
+ if (cls.state < ca_active && !(dest & (KEY_MENU | KEY_CONSOLE))) {
dest |= KEY_CONSOLE;
}
diff = cls.key_dest ^ dest;
- if( diff & KEY_CONSOLE ) {
- if( dest & KEY_CONSOLE ) {
+ if (diff & KEY_CONSOLE) {
+ if (dest & KEY_CONSOLE) {
// release all keys, to keep the character from continuing an
// action started before a console switch
Key_ClearStates();
@@ -197,7 +201,7 @@ void Key_SetDest( keydest_t dest ) {
cls.key_dest = dest;
// activate or deactivate mouse
- if( diff & (KEY_CONSOLE|KEY_MENU) ) {
+ if (diff & (KEY_CONSOLE | KEY_MENU)) {
IN_Activate();
CL_CheckForPause();
}
@@ -208,8 +212,9 @@ void Key_SetDest( keydest_t dest ) {
Key_IsDown
===================
*/
-qboolean Key_IsDown( int key ) {
- if( key < 0 || key > 255 ) {
+qboolean Key_IsDown(int key)
+{
+ if (key < 0 || key > 255) {
return qfalse;
}
@@ -221,7 +226,8 @@ qboolean Key_IsDown( int key ) {
Key_AnyKeyDown
===================
*/
-qboolean Key_AnyKeyDown( void ) {
+qboolean Key_AnyKeyDown(void)
+{
return anykeydown;
}
@@ -234,16 +240,17 @@ the given string. Single ascii characters return themselves, while
the K_* names are matched up.
===================
*/
-int Key_StringToKeynum( const char *str ) {
+int Key_StringToKeynum(const char *str)
+{
const keyname_t *kn;
-
- if( !str || !str[0] )
+
+ if (!str || !str[0])
return -1;
- if( !str[1] )
+ if (!str[1])
return str[0];
- for( kn = keynames; kn->name; kn++ ) {
- if( !Q_stricmp( str, kn->name ) )
+ for (kn = keynames; kn->name; kn++) {
+ if (!Q_stricmp(str, kn->name))
return kn->keynum;
}
return -1;
@@ -258,21 +265,22 @@ given keynum.
FIXME: handle quote special (general escape sequence?)
===================
*/
-char *Key_KeynumToString( int keynum ) {
- const keyname_t *kn;
+char *Key_KeynumToString(int keynum)
+{
+ const keyname_t *kn;
static char tinystr[2];
-
- if( keynum == -1 )
+
+ if (keynum == -1)
return "<KEY NOT FOUND>";
- if( keynum > 32 && keynum < 127 ) {
+ if (keynum > 32 && keynum < 127) {
// printable ascii
tinystr[0] = keynum;
tinystr[1] = 0;
return tinystr;
}
-
- for( kn = keynames; kn->name; kn++ )
- if( keynum == kn->keynum )
+
+ for (kn = keynames; kn->name; kn++)
+ if (keynum == kn->keynum)
return kn->name;
return "<UNKNOWN KEYNUM>";
@@ -285,13 +293,14 @@ Key_SetBinding
Returns the name of the first key found.
===================
*/
-char *Key_GetBinding( const char *binding ) {
+char *Key_GetBinding(const char *binding)
+{
int key;
- for( key = 0; key < 256; key++ ) {
- if( keybindings[key] ) {
- if( !Q_stricmp( keybindings[key], binding ) ) {
- return Key_KeynumToString( key );
+ for (key = 0; key < 256; key++) {
+ if (keybindings[key]) {
+ if (!Q_stricmp(keybindings[key], binding)) {
+ return Key_KeynumToString(key);
}
}
}
@@ -304,13 +313,14 @@ char *Key_GetBinding( const char *binding ) {
Key_EnumBindings
===================
*/
-int Key_EnumBindings( int key, const char *binding ) {
- if( key < 0 ) {
+int Key_EnumBindings(int key, const char *binding)
+{
+ if (key < 0) {
key = 0;
}
- for( ; key < 256; key++ ) {
- if( keybindings[key] ) {
- if( !Q_stricmp( keybindings[key], binding ) ) {
+ for (; key < 256; key++) {
+ if (keybindings[key]) {
+ if (!Q_stricmp(keybindings[key], binding)) {
return key;
}
}
@@ -324,54 +334,59 @@ int Key_EnumBindings( int key, const char *binding ) {
Key_SetBinding
===================
*/
-void Key_SetBinding( int keynum, const char *binding ) {
- if( keynum < 0 || keynum > 255 )
+void Key_SetBinding(int keynum, const char *binding)
+{
+ if (keynum < 0 || keynum > 255)
return;
// free old binding
- if( keybindings[keynum] ) {
- Z_Free( keybindings[keynum] );
+ if (keybindings[keynum]) {
+ Z_Free(keybindings[keynum]);
}
-
+
// allocate memory for new binding
- keybindings[keynum] = Z_CopyString( binding );
+ keybindings[keynum] = Z_CopyString(binding);
}
-static void Key_Name_g( genctx_t *ctx ) {
+static void Key_Name_g(genctx_t *ctx)
+{
const keyname_t *k;
ctx->ignorecase = qtrue;
- for( k = keynames; k->name; k++ ) {
- if( !Prompt_AddMatch( ctx, k->name ) ) {
+ for (k = keynames; k->name; k++) {
+ if (!Prompt_AddMatch(ctx, k->name)) {
break;
}
}
}
-static void Key_Bound_g( genctx_t *ctx ) {
+static void Key_Bound_g(genctx_t *ctx)
+{
int i;
ctx->ignorecase = qtrue;
- for( i = 0; i < 256; i++ ) {
- if( keybindings[i] ) {
- if( !Prompt_AddMatch( ctx, Key_KeynumToString( i ) ) ) {
+ for (i = 0; i < 256; i++) {
+ if (keybindings[i]) {
+ if (!Prompt_AddMatch(ctx, Key_KeynumToString(i))) {
break;
}
}
}
}
-static void Key_Bind_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Key_Name_g( ctx );
+static void Key_Bind_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Key_Name_g(ctx);
} else {
- Com_Generic_c( ctx, argnum - 2 );
+ Com_Generic_c(ctx, argnum - 2);
}
}
-static void Key_Unbind_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Key_Bound_g( ctx );
+static void Key_Unbind_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Key_Bound_g(ctx);
}
}
@@ -380,21 +395,22 @@ static void Key_Unbind_c( genctx_t *ctx, int argnum ) {
Key_Unbind_f
===================
*/
-static void Key_Unbind_f( void ) {
+static void Key_Unbind_f(void)
+{
int b;
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "unbind <key> : remove commands from a key\n" );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("unbind <key> : remove commands from a key\n");
return;
}
-
- b = Key_StringToKeynum( Cmd_Argv( 1 ) );
- if( b == -1 ) {
- Com_Printf( "\"%s\" isn't a valid key\n", Cmd_Argv( 1 ) );
+
+ b = Key_StringToKeynum(Cmd_Argv(1));
+ if (b == -1) {
+ Com_Printf("\"%s\" isn't a valid key\n", Cmd_Argv(1));
return;
}
- Key_SetBinding( b, NULL );
+ Key_SetBinding(b, NULL);
}
/*
@@ -402,12 +418,13 @@ static void Key_Unbind_f( void ) {
Key_Unbindall_f
===================
*/
-static void Key_Unbindall_f( void ) {
+static void Key_Unbindall_f(void)
+{
int i;
-
- for( i = 0; i < 256; i++ )
- if( keybindings[i] )
- Key_SetBinding( i, NULL );
+
+ for (i = 0; i < 256; i++)
+ if (keybindings[i])
+ Key_SetBinding(i, NULL);
}
@@ -416,31 +433,32 @@ static void Key_Unbindall_f( void ) {
Key_Bind_f
===================
*/
-static void Key_Bind_f( void ) {
+static void Key_Bind_f(void)
+{
int c, b;
-
+
c = Cmd_Argc();
- if( c < 2 ) {
- Com_Printf( "bind <key> [command] : attach a command to a key\n" );
+ if (c < 2) {
+ Com_Printf("bind <key> [command] : attach a command to a key\n");
return;
}
- b = Key_StringToKeynum( Cmd_Argv( 1 ) );
- if( b == -1 ) {
- Com_Printf( "\"%s\" isn't a valid key\n", Cmd_Argv( 1 ) );
+ b = Key_StringToKeynum(Cmd_Argv(1));
+ if (b == -1) {
+ Com_Printf("\"%s\" isn't a valid key\n", Cmd_Argv(1));
return;
}
- if( c == 2 ) {
- if( keybindings[b] )
- Com_Printf( "\"%s\" = \"%s\"\n", Cmd_Argv( 1 ), keybindings[b] );
+ if (c == 2) {
+ if (keybindings[b])
+ Com_Printf("\"%s\" = \"%s\"\n", Cmd_Argv(1), keybindings[b]);
else
- Com_Printf( "\"%s\" is not bound\n", Cmd_Argv( 1 ) );
+ Com_Printf("\"%s\" is not bound\n", Cmd_Argv(1));
return;
}
-
+
// copy the rest of the command line
- Key_SetBinding( b, Cmd_ArgsFrom( 2 ) );
+ Key_SetBinding(b, Cmd_ArgsFrom(2));
}
/*
@@ -450,13 +468,14 @@ Key_WriteBindings
Writes lines containing "bind key value"
============
*/
-void Key_WriteBindings( qhandle_t f ) {
+void Key_WriteBindings(qhandle_t f)
+{
int i;
- for( i = 0; i < 256; i++ ) {
- if( keybindings[i] && keybindings[i][0] ) {
- FS_FPrintf( f, "bind %s \"%s\"\n", Key_KeynumToString( i ),
- keybindings[i] );
+ for (i = 0; i < 256; i++) {
+ if (keybindings[i] && keybindings[i][0]) {
+ FS_FPrintf(f, "bind %s \"%s\"\n", Key_KeynumToString(i),
+ keybindings[i]);
}
}
}
@@ -468,13 +487,14 @@ Key_Bindlist_f
============
*/
-static void Key_Bindlist_f( void ) {
+static void Key_Bindlist_f(void)
+{
int i;
- for( i = 0; i < 256; i++ ) {
- if( keybindings[i] && keybindings[i][0] ) {
- Com_Printf( "%s \"%s\"\n", Key_KeynumToString( i ),
- keybindings[i] );
+ for (i = 0; i < 256; i++) {
+ if (keybindings[i] && keybindings[i][0]) {
+ Com_Printf("%s \"%s\"\n", Key_KeynumToString(i),
+ keybindings[i]);
}
}
}
@@ -493,13 +513,14 @@ static cmdreg_t c_keys[] = {
Key_Init
===================
*/
-void Key_Init( void ) {
+void Key_Init(void)
+{
int i;
-
+
//
// init ascii characters in console mode
//
- for( i = K_ASCIIFIRST; i <= K_ASCIILAST; i++ )
+ for (i = K_ASCIIFIRST; i <= K_ASCIILAST; i++)
consolekeys[i] = qtrue;
#define K(x) \
@@ -559,9 +580,9 @@ void Key_Init( void ) {
//
// init ascii keyshift characters
//
- for( i = 0; i < 256; i++ )
+ for (i = 0; i < 256; i++)
keyshift[i] = i;
- for( i = 'a'; i <= 'z'; i++ )
+ for (i = 'a'; i <= 'z'; i++)
keyshift[i] = i - 'a' + 'A';
keyshift['1'] = '!';
@@ -588,13 +609,13 @@ void Key_Init( void ) {
#endif
menubound[K_ESCAPE] = qtrue;
- for( i = 0; i < 12; i++ )
- menubound[K_F1+i] = qtrue;
+ for (i = 0; i < 12; i++)
+ menubound[K_F1 + i] = qtrue;
//
// register our functions
//
- Cmd_Register( c_keys );
+ Cmd_Register(c_keys);
}
/*
@@ -605,57 +626,57 @@ Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
===================
*/
-void Key_Event( unsigned key, qboolean down, unsigned time ) {
+void Key_Event(unsigned key, qboolean down, unsigned time)
+{
char *kb;
char cmd[MAX_STRING_CHARS];
- if( key >= 256 ) {
- Com_Error( ERR_FATAL, "%s: bad key", __func__ );
+ if (key >= 256) {
+ Com_Error(ERR_FATAL, "%s: bad key", __func__);
}
- Com_DDDPrintf( "%u: %c%s\n", time,
- down ? '+' : '-', Key_KeynumToString( key ) );
+ Com_DDDPrintf("%u: %c%s\n", time,
+ down ? '+' : '-', Key_KeynumToString(key));
// hack for menu key binding
- if( key_wait_cb && down && !key_wait_cb( key_wait_arg, key ) ) {
+ if (key_wait_cb && down && !key_wait_cb(key_wait_arg, key)) {
return;
}
// update auto-repeat status
- if( down ) {
+ if (down) {
key_repeats[key]++;
- if( !( cls.key_dest & (KEY_CONSOLE|KEY_MESSAGE|KEY_MENU) )
- && key != K_BACKSPACE
- && key != K_PAUSE
- && key != K_PGUP
- && key != K_KP_PGUP
+ if (!(cls.key_dest & (KEY_CONSOLE | KEY_MESSAGE | KEY_MENU))
+ && key != K_BACKSPACE
+ && key != K_PAUSE
+ && key != K_PGUP
+ && key != K_KP_PGUP
&& key != K_PGDN
&& key != K_KP_PGDN
- && key_repeats[key] > 1 )
- {
+ && key_repeats[key] > 1) {
return; // ignore most autorepeats
}
- if( key >= K_MOUSEFIRST && !keybindings[key] && !consolekeys[key] ) {
- Com_Printf( "%s is unbound, hit F4 to set.\n",
- Key_KeynumToString( key ) );
+ if (key >= K_MOUSEFIRST && !keybindings[key] && !consolekeys[key]) {
+ Com_Printf("%s is unbound, hit F4 to set.\n",
+ Key_KeynumToString(key));
}
} else {
key_repeats[key] = 0;
}
// console key is hardcoded, so the user can never unbind it
- if( !Key_IsDown( K_SHIFT ) && ( key == '`' || key == '~' ) ) {
- if( down ) {
+ if (!Key_IsDown(K_SHIFT) && (key == '`' || key == '~')) {
+ if (down) {
Con_ToggleConsole_f();
}
return;
}
// Alt+Enter is hardcoded for all systems
- if( Key_IsDown( K_ALT ) && key == K_ENTER ) {
- if( down ) {
- extern void VID_ToggleFullscreen( void );
+ if (Key_IsDown(K_ALT) && key == K_ENTER) {
+ if (down) {
+ extern void VID_ToggleFullscreen(void);
VID_ToggleFullscreen();
}
@@ -663,48 +684,47 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
}
// menu key is hardcoded, so the user can never unbind it
- if( key == K_ESCAPE ) {
- if( !down ) {
+ if (key == K_ESCAPE) {
+ if (!down) {
return;
}
- if( key_repeats[key] > 1 ) {
+ if (key_repeats[key] > 1) {
return;
}
- if( cls.key_dest == KEY_GAME &&
+ if (cls.key_dest == KEY_GAME &&
!cls.demo.playback &&
cl.clientNum != -1 &&
cl.frame.ps.stats[STAT_LAYOUTS] &&
- !cl.putaway )
- {
+ !cl.putaway) {
// put away help computer / inventory
- CL_ClientCommand( "putaway" );
+ CL_ClientCommand("putaway");
cl.putaway = qtrue;
return;
}
- if( cls.key_dest & KEY_CONSOLE ) {
- if( cls.state < ca_active && !( cls.key_dest & KEY_MENU ) ) {
+ if (cls.key_dest & KEY_CONSOLE) {
+ if (cls.state < ca_active && !(cls.key_dest & KEY_MENU)) {
#if USE_UI
- UI_OpenMenu( UIMENU_MAIN );
+ UI_OpenMenu(UIMENU_MAIN);
#endif
} else {
- Con_Close( qtrue );
+ Con_Close(qtrue);
}
}
#if USE_UI
- else if( cls.key_dest & KEY_MENU ) {
- UI_Keydown( key );
+ else if (cls.key_dest & KEY_MENU) {
+ UI_Keydown(key);
}
#endif
- else if( cls.key_dest & KEY_MESSAGE ) {
- Key_Message( key );
+ else if (cls.key_dest & KEY_MESSAGE) {
+ Key_Message(key);
}
#if USE_UI
- else if( cls.state == ca_active ) {
- UI_OpenMenu( UIMENU_GAME );
+ else if (cls.state == ca_active) {
+ UI_OpenMenu(UIMENU_GAME);
} else {
- UI_OpenMenu( UIMENU_MAIN );
+ UI_OpenMenu(UIMENU_MAIN);
}
#endif
return;
@@ -712,99 +732,98 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
// track if any key is down for BUTTON_ANY
keydown[key] = down;
- if( down ) {
- if( key_repeats[key] == 1 )
+ if (down) {
+ if (key_repeats[key] == 1)
anykeydown++;
} else {
anykeydown--;
- if( anykeydown < 0 )
+ if (anykeydown < 0)
anykeydown = 0;
}
// hack for demo freelook in windowed mode
- if( cls.key_dest == KEY_GAME && cls.demo.playback && key == K_SHIFT ) {
+ if (cls.key_dest == KEY_GAME && cls.demo.playback && key == K_SHIFT) {
IN_Activate();
}
-
+
//
// if not a consolekey, send to the interpreter no matter what mode is
//
- if( ( cls.key_dest == KEY_GAME ) ||
- ( ( cls.key_dest & KEY_CONSOLE ) && !consolekeys[key] ) ||
- ( ( cls.key_dest & KEY_MENU ) && menubound[key] ) )
- {
+ if ((cls.key_dest == KEY_GAME) ||
+ ((cls.key_dest & KEY_CONSOLE) && !consolekeys[key]) ||
+ ((cls.key_dest & KEY_MENU) && menubound[key])) {
//
// Key up events only generate commands if the game key binding is
// a button command (leading + sign).
// Button commands include the kenum as a parameter, so multiple
// downs can be matched with ups.
//
- if( !down ) {
+ if (!down) {
kb = keybindings[key];
- if( kb && kb[0] == '+' ) {
- Q_snprintf( cmd, sizeof( cmd ), "-%s %i %i\n",
- kb + 1, key, time );
- Cbuf_AddText( &cmd_buffer, cmd );
+ if (kb && kb[0] == '+') {
+ Q_snprintf(cmd, sizeof(cmd), "-%s %i %i\n",
+ kb + 1, key, time);
+ Cbuf_AddText(&cmd_buffer, cmd);
}
#if !USE_CHAR_EVENTS
- if( keyshift[key] != key ) {
+ if (keyshift[key] != key) {
kb = keybindings[keyshift[key]];
- if( kb && kb[0] == '+' ) {
- Q_snprintf( cmd, sizeof( cmd ), "-%s %i %i\n",
- kb + 1, key, time );
- Cbuf_AddText( &cmd_buffer, cmd );
+ if (kb && kb[0] == '+') {
+ Q_snprintf(cmd, sizeof(cmd), "-%s %i %i\n",
+ kb + 1, key, time);
+ Cbuf_AddText(&cmd_buffer, cmd);
}
}
#endif
return;
}
- if( key_repeats[key] > 1 ) {
+ if (key_repeats[key] > 1) {
return;
}
#if !USE_CHAR_EVENTS
- if( Key_IsDown( K_SHIFT ) && keyshift[key] != key && keybindings[keyshift[key]] ) {
+ if (Key_IsDown(K_SHIFT) && keyshift[key] != key && keybindings[keyshift[key]]) {
key = keyshift[key];
}
#endif
kb = keybindings[key];
- if( kb ) {
- if( kb[0] == '+' ) {
+ if (kb) {
+ if (kb[0] == '+') {
// button commands add keynum and time as a parm
- Q_snprintf( cmd, sizeof( cmd ), "%s %i %i\n", kb, key, time );
- Cbuf_AddText( &cmd_buffer, cmd );
+ Q_snprintf(cmd, sizeof(cmd), "%s %i %i\n", kb, key, time);
+ Cbuf_AddText(&cmd_buffer, cmd);
} else {
- Cbuf_AddText( &cmd_buffer, kb );
- Cbuf_AddText( &cmd_buffer, "\n" );
+ Cbuf_AddText(&cmd_buffer, kb);
+ Cbuf_AddText(&cmd_buffer, "\n");
}
}
return;
}
- if( !down )
+ if (!down)
return; // other subsystems only care about key down events
- if( cls.key_dest & KEY_CONSOLE ) {
- Key_Console( key );
+ if (cls.key_dest & KEY_CONSOLE) {
+ Key_Console(key);
}
#if USE_UI
- else if( cls.key_dest & KEY_MENU ) {
- UI_Keydown( key );
+ else if (cls.key_dest & KEY_MENU) {
+ UI_Keydown(key);
}
#endif
- else if( cls.key_dest & KEY_MESSAGE ) {
- Key_Message( key );
+ else if (cls.key_dest & KEY_MESSAGE) {
+ Key_Message(key);
}
#if !USE_CHAR_EVENTS
- if( Key_IsDown( K_CTRL ) || Key_IsDown( K_ALT ) ) {
+ if (Key_IsDown(K_CTRL) || Key_IsDown(K_ALT)) {
return;
}
- switch( key ) {
+ switch (key) {
case K_KP_SLASH:
key = '/';
break;
@@ -853,24 +872,24 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
}
// if key is printable, generate char events
- if( key < 32 || key >= 127 ) {
+ if (key < 32 || key >= 127) {
return;
}
-
- if( Key_IsDown( K_SHIFT ) ) {
+
+ if (Key_IsDown(K_SHIFT)) {
key = keyshift[key];
}
- if( cls.key_dest & KEY_CONSOLE ) {
- Char_Console( key );
+ if (cls.key_dest & KEY_CONSOLE) {
+ Char_Console(key);
}
#if USE_UI
- else if( cls.key_dest & KEY_MENU ) {
- UI_CharEvent( key );
+ else if (cls.key_dest & KEY_MENU) {
+ UI_CharEvent(key);
}
#endif
- else if( cls.key_dest & KEY_MESSAGE ) {
- Char_Message( key );
+ else if (cls.key_dest & KEY_MESSAGE) {
+ Char_Message(key);
}
#endif // !USE_CHAR_EVENTS
@@ -884,21 +903,22 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
Key_CharEvent
===================
*/
-void Key_CharEvent( int key ) {
- if( key == '`' || key == '~' ) {
+void Key_CharEvent(int key)
+{
+ if (key == '`' || key == '~') {
return;
}
- if( cls.key_dest & KEY_CONSOLE ) {
- Char_Console( key );
+ if (cls.key_dest & KEY_CONSOLE) {
+ Char_Console(key);
}
#if USE_UI
- else if( cls.key_dest & KEY_MENU ) {
- UI_CharEvent( key );
+ else if (cls.key_dest & KEY_MENU) {
+ UI_CharEvent(key);
}
#endif
- else if( cls.key_dest & KEY_MESSAGE ) {
- Char_Message( key );
+ else if (cls.key_dest & KEY_MESSAGE) {
+ Char_Message(key);
}
}
@@ -909,12 +929,13 @@ void Key_CharEvent( int key ) {
Key_ClearStates
===================
*/
-void Key_ClearStates( void ) {
+void Key_ClearStates(void)
+{
int i;
- for( i = 0; i < 256; i++ ) {
- if( keydown[i] || key_repeats[i] )
- Key_Event( i, qfalse, 0 );
+ for (i = 0; i < 256; i++) {
+ if (keydown[i] || key_repeats[i])
+ Key_Event(i, qfalse, 0);
keydown[i] = 0;
key_repeats[i] = 0;
}
@@ -927,7 +948,8 @@ void Key_ClearStates( void ) {
Key_WaitKey
===================
*/
-void Key_WaitKey( keywaitcb_t wait, void *arg ) {
+void Key_WaitKey(keywaitcb_t wait, void *arg)
+{
key_wait_cb = wait;
key_wait_arg = arg;
}
diff --git a/src/cl_local.h b/src/cl_local.h
index b2c6d6d..cbd5e97 100644
--- a/src/cl_local.h
+++ b/src/cl_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -222,7 +222,7 @@ typedef struct client_state_s {
// predicted values, used for smooth player entity movement in thirdperson view
vec3_t playerEntityOrigin;
vec3_t playerEntityAngles;
-
+
//
// transient data from server
//
@@ -301,9 +301,9 @@ typedef enum {
} connstate_t;
#define FOR_EACH_DLQ(q) \
- LIST_FOR_EACH (dlqueue_t, q, &cls.download.queue, entry)
+ LIST_FOR_EACH(dlqueue_t, q, &cls.download.queue, entry)
#define FOR_EACH_DLQ_SAFE(q, n) \
- LIST_FOR_EACH_SAFE (dlqueue_t, q, n, &cls.download.queue, entry)
+ LIST_FOR_EACH_SAFE(dlqueue_t, q, n, &cls.download.queue, entry)
typedef enum {
// generic types
@@ -345,8 +345,8 @@ typedef struct client_static_s {
// so that the client knows to send it to the server
int framecount;
- unsigned realtime; // always increasing, no clamping, etc
- float frametime; // seconds since last frame
+ unsigned realtime; // always increasing, no clamping, etc
+ float frametime; // seconds since last frame
// preformance measurement
#define C_FPS cls.measure.fps[0]
@@ -388,7 +388,7 @@ typedef struct client_static_s {
#endif
#define RECENT_ADDR 4
-#define RECENT_MASK (RECENT_ADDR-1)
+#define RECENT_MASK (RECENT_ADDR - 1)
netadr_t recent_addr[RECENT_ADDR];
int recent_head;
@@ -399,7 +399,7 @@ typedef struct client_static_s {
dlqueue_t *current; // path being downloaded
int percent; // how much downloaded
qhandle_t file; // UDP file transfer from server
- char temp[MAX_QPATH+4]; // account 4 bytes for .tmp suffix
+ char temp[MAX_QPATH + 4]; // account 4 bytes for .tmp suffix
} download;
// demo recording info must be here, so it isn't cleared on level change
@@ -455,15 +455,15 @@ extern cvar_t *cl_noglow;
extern cvar_t *cl_nolerp;
#ifdef _DEBUG
-#define SHOWNET(level,...) \
- if( cl_shownet->integer > level ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
-#define SHOWCLAMP(level,...) \
- if( cl_showclamp->integer > level ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+#define SHOWNET(level, ...) \
+ if (cl_shownet->integer > level) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
+#define SHOWCLAMP(level, ...) \
+ if (cl_showclamp->integer > level) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#define SHOWMISS(...) \
- if( cl_showmiss->integer ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (cl_showmiss->integer) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
extern cvar_t *cl_shownet;
extern cvar_t *cl_showmiss;
extern cvar_t *cl_showclamp;
@@ -514,20 +514,20 @@ extern cvar_t *info_uf;
// cl_main
//
-void CL_Init (void);
-void CL_Quit_f (void);
-void CL_Disconnect( error_type_t type );
-void CL_Begin( void );
-void CL_CheckForResend( void );
-void CL_ClearState (void);
-void CL_RestartFilesystem( qboolean total );
-void CL_RestartRefresh( qboolean total );
-void CL_ClientCommand( const char *string );
-void CL_SendRcon( const netadr_t *adr, const char *pass, const char *cmd );
-const char *CL_Server_g( const char *partial, int argnum, int state );
-void CL_CheckForPause( void );
-void CL_UpdateFrameTimes( void );
-qboolean CL_CheckForIgnore( const char *s );
+void CL_Init(void);
+void CL_Quit_f(void);
+void CL_Disconnect(error_type_t type);
+void CL_Begin(void);
+void CL_CheckForResend(void);
+void CL_ClearState(void);
+void CL_RestartFilesystem(qboolean total);
+void CL_RestartRefresh(qboolean total);
+void CL_ClientCommand(const char *string);
+void CL_SendRcon(const netadr_t *adr, const char *pass, const char *cmd);
+const char *CL_Server_g(const char *partial, int argnum, int state);
+void CL_CheckForPause(void);
+void CL_UpdateFrameTimes(void);
+qboolean CL_CheckForIgnore(const char *s);
//
// cl_precache
@@ -542,40 +542,40 @@ typedef enum {
LOAD_FINISH
} load_state_t;
-void CL_ParsePlayerSkin( char *name, char *model, char *skin, const char *s );
-void CL_LoadClientinfo( clientinfo_t *ci, const char *s );
-void CL_LoadState( load_state_t state );
-void CL_RegisterSounds( void );
-void CL_RegisterBspModels( void );
-void CL_RegisterVWepModels( void );
-void CL_PrepRefresh( void );
-void CL_UpdateConfigstring( int index );
+void CL_ParsePlayerSkin(char *name, char *model, char *skin, const char *s);
+void CL_LoadClientinfo(clientinfo_t *ci, const char *s);
+void CL_LoadState(load_state_t state);
+void CL_RegisterSounds(void);
+void CL_RegisterBspModels(void);
+void CL_RegisterVWepModels(void);
+void CL_PrepRefresh(void);
+void CL_UpdateConfigstring(int index);
//
// cl_download
//
-qerror_t CL_QueueDownload( const char *path, dltype_t type );
-void CL_FinishDownload( dlqueue_t *q );
-void CL_CleanupDownloads( void );
-void CL_HandleDownload( const byte *data, int size, int percent );
-qboolean CL_CheckDownloadExtension( const char *ext );
-void CL_StartNextDownload( void );
-void CL_RequestNextDownload( void );
-void CL_ResetPrecacheCheck( void );
-void CL_InitDownloads( void );
+qerror_t CL_QueueDownload(const char *path, dltype_t type);
+void CL_FinishDownload(dlqueue_t *q);
+void CL_CleanupDownloads(void);
+void CL_HandleDownload(const byte *data, int size, int percent);
+qboolean CL_CheckDownloadExtension(const char *ext);
+void CL_StartNextDownload(void);
+void CL_RequestNextDownload(void);
+void CL_ResetPrecacheCheck(void);
+void CL_InitDownloads(void);
//
// cl_input
//
-void IN_Init( void );
-void IN_Shutdown( void );
-void IN_Frame( void );
-void IN_Activate( void );
+void IN_Init(void);
+void IN_Shutdown(void);
+void IN_Frame(void);
+void IN_Activate(void);
-void CL_RegisterInput( void );
-void CL_UpdateCmd( int msec );
-void CL_FinalizeCmd( void );
-void CL_SendCmd( void );
+void CL_RegisterInput(void);
+void CL_UpdateCmd(int msec);
+void CL_FinalizeCmd(void);
+void CL_SendCmd(void);
//
// cl_parse.c
@@ -615,23 +615,23 @@ extern tent_params_t te;
extern mz_params_t mz;
extern snd_params_t snd;
-void CL_ParseServerMessage (void);
-void CL_SeekDemoMessage( void );
+void CL_ParseServerMessage(void);
+void CL_SeekDemoMessage(void);
//
// cl_ents.c
//
-void CL_DeltaFrame( void );
-void CL_AddEntities (void);
-void CL_CalcViewValues( void );
+void CL_DeltaFrame(void);
+void CL_AddEntities(void);
+void CL_CalcViewValues(void);
#ifdef _DEBUG
-void CL_CheckEntityPresent( int entnum, const char *what );
+void CL_CheckEntityPresent(int entnum, const char *what);
#endif
// the sound code makes callbacks to the client for entitiy position
// information, so entities can be dynamically re-spatialized
-void CL_GetEntitySoundOrigin( int ent, vec3_t org );
+void CL_GetEntitySoundOrigin(int ent, vec3_t org);
//
// cl_view.c
@@ -639,20 +639,20 @@ void CL_GetEntitySoundOrigin( int ent, vec3_t org );
extern int gun_frame;
extern qhandle_t gun_model;
-void V_Init( void );
-void V_Shutdown( void );
-void V_RenderView( void );
-void V_AddEntity (entity_t *ent);
-void V_AddParticle( particle_t *p );
+void V_Init(void);
+void V_Shutdown(void);
+void V_RenderView(void);
+void V_AddEntity(entity_t *ent);
+void V_AddParticle(particle_t *p);
#if USE_DLIGHTS
-void V_AddLight (vec3_t org, float intensity, float r, float g, float b);
+void V_AddLight(vec3_t org, float intensity, float r, float g, float b);
#else
-#define V_AddLight(org,intensity,r,g,b)
+#define V_AddLight(org, intensity, r, g, b)
#endif
#if USE_LIGHTSTYLES
-void V_AddLightStyle (int style, vec4_t value);
+void V_AddLightStyle(int style, vec4_t value);
#endif
-void CL_UpdateBlendSetting( void );
+void CL_UpdateBlendSetting(void);
//
// cl_tent.c
@@ -675,20 +675,20 @@ typedef struct cl_sustain_s {
void CL_SmokeAndFlash(vec3_t origin);
-void CL_RegisterTEntSounds (void);
-void CL_RegisterTEntModels (void);
-void CL_ParseTEnt (void);
-void CL_AddTEnts (void);
-void CL_ClearTEnts (void);
-void CL_InitTEnts( void );
+void CL_RegisterTEntSounds(void);
+void CL_RegisterTEntModels(void);
+void CL_ParseTEnt(void);
+void CL_AddTEnts(void);
+void CL_ClearTEnts(void);
+void CL_InitTEnts(void);
//
// cl_pred.c
//
-void CL_PredictAngles( void );
-void CL_PredictMovement (void);
-void CL_CheckPredictionError (void);
+void CL_PredictAngles(void);
+void CL_PredictMovement(void);
+void CL_CheckPredictionError(void);
//
// cl_fx.c
@@ -727,43 +727,43 @@ typedef struct cdlight_s {
} cdlight_t;
#endif
-void CL_BigTeleportParticles (vec3_t org);
-void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old);
-void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags);
-void CL_FlyEffect (centity_t *ent, vec3_t origin);
-void CL_BfgParticles (entity_t *ent);
-void CL_ItemRespawnParticles (vec3_t org);
-void CL_InitEffects (void);
-void CL_ClearEffects (void);
-void CL_BlasterParticles (vec3_t org, vec3_t dir);
-void CL_ExplosionParticles (vec3_t org);
-void CL_BFGExplosionParticles (vec3_t org);
-void CL_BlasterTrail (vec3_t start, vec3_t end);
-void CL_QuadTrail (vec3_t start, vec3_t end);
-void CL_OldRailTrail (void);
-void CL_BubbleTrail (vec3_t start, vec3_t end);
-void CL_FlagTrail (vec3_t start, vec3_t end, int color);
-void CL_MuzzleFlash (void);
-void CL_MuzzleFlash2 (void);
-void CL_TeleporterParticles (vec3_t org);
-void CL_TeleportParticles (vec3_t org);
-void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count);
-void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count);
-cparticle_t *CL_AllocParticle( void );
-void CL_RunParticles (void);
-void CL_AddParticles (void);
+void CL_BigTeleportParticles(vec3_t org);
+void CL_RocketTrail(vec3_t start, vec3_t end, centity_t *old);
+void CL_DiminishingTrail(vec3_t start, vec3_t end, centity_t *old, int flags);
+void CL_FlyEffect(centity_t *ent, vec3_t origin);
+void CL_BfgParticles(entity_t *ent);
+void CL_ItemRespawnParticles(vec3_t org);
+void CL_InitEffects(void);
+void CL_ClearEffects(void);
+void CL_BlasterParticles(vec3_t org, vec3_t dir);
+void CL_ExplosionParticles(vec3_t org);
+void CL_BFGExplosionParticles(vec3_t org);
+void CL_BlasterTrail(vec3_t start, vec3_t end);
+void CL_QuadTrail(vec3_t start, vec3_t end);
+void CL_OldRailTrail(void);
+void CL_BubbleTrail(vec3_t start, vec3_t end);
+void CL_FlagTrail(vec3_t start, vec3_t end, int color);
+void CL_MuzzleFlash(void);
+void CL_MuzzleFlash2(void);
+void CL_TeleporterParticles(vec3_t org);
+void CL_TeleportParticles(vec3_t org);
+void CL_ParticleEffect(vec3_t org, vec3_t dir, int color, int count);
+void CL_ParticleEffect2(vec3_t org, vec3_t dir, int color, int count);
+cparticle_t *CL_AllocParticle(void);
+void CL_RunParticles(void);
+void CL_AddParticles(void);
#if USE_DLIGHTS
-cdlight_t *CL_AllocDlight (int key);
-void CL_RunDLights (void);
-void CL_AddDLights (void);
+cdlight_t *CL_AllocDlight(int key);
+void CL_RunDLights(void);
+void CL_AddDLights(void);
#endif
#if USE_LIGHTSTYLES
-void CL_ClearLightStyles( void );
-void CL_SetLightStyle( int index, const char *s );
-void CL_RunLightStyles (void);
-void CL_AddLightStyles (void);
+void CL_ClearLightStyles(void);
+void CL_SetLightStyle(int index, const char *s);
+void CL_RunLightStyles(void);
+void CL_AddLightStyles(void);
#endif
-void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up);
+void MakeNormalVectors(vec3_t forward, vec3_t right, vec3_t up);
//
// cl_newfx.c
@@ -771,38 +771,38 @@ void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up);
// ========
// PGM
-void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color);
-void CL_BlasterTrail2 (vec3_t start, vec3_t end);
-void CL_DebugTrail (vec3_t start, vec3_t end);
-void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing);
+void CL_BlasterParticles2(vec3_t org, vec3_t dir, unsigned int color);
+void CL_BlasterTrail2(vec3_t start, vec3_t end);
+void CL_DebugTrail(vec3_t start, vec3_t end);
+void CL_SmokeTrail(vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing);
#if USE_DLIGHTS
-void CL_Flashlight (int ent, vec3_t pos);
+void CL_Flashlight(int ent, vec3_t pos);
#endif
-void CL_ForceWall (vec3_t start, vec3_t end, int color);
-void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel);
-void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist);
-void CL_Heatbeam (vec3_t start, vec3_t end);
-void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
-void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor);
+void CL_ForceWall(vec3_t start, vec3_t end, int color);
+void CL_GenericParticleEffect(vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel);
+void CL_BubbleTrail2(vec3_t start, vec3_t end, int dist);
+void CL_Heatbeam(vec3_t start, vec3_t end);
+void CL_ParticleSteamEffect(vec3_t org, vec3_t dir, int color, int count, int magnitude);
+void CL_TrackerTrail(vec3_t start, vec3_t end, int particleColor);
void CL_Tracker_Explode(vec3_t origin);
-void CL_TagTrail (vec3_t start, vec3_t end, int color);
+void CL_TagTrail(vec3_t start, vec3_t end, int color);
#if USE_DLIGHTS
-void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b);
+void CL_ColorFlash(vec3_t pos, int ent, int intensity, float r, float g, float b);
#endif
void CL_Tracker_Shell(vec3_t origin);
void CL_MonsterPlasma_Shell(vec3_t origin);
-void CL_ColorExplosionParticles (vec3_t org, int color, int run);
-void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
-void CL_Widowbeamout (cl_sustain_t *self);
-void CL_Nukeblast (cl_sustain_t *self);
-void CL_WidowSplash (void);
+void CL_ColorExplosionParticles(vec3_t org, int color, int run);
+void CL_ParticleSmokeEffect(vec3_t org, vec3_t dir, int color, int count, int magnitude);
+void CL_Widowbeamout(cl_sustain_t *self);
+void CL_Nukeblast(cl_sustain_t *self);
+void CL_WidowSplash(void);
// PGM
// ========
// RAFAEL
-void CL_IonripperTrail (vec3_t start, vec3_t end);
-void CL_TrapParticles (entity_t *ent);
-void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count);
+void CL_IonripperTrail(vec3_t start, vec3_t end);
+void CL_TrapParticles(entity_t *ent);
+void CL_ParticleEffect3(vec3_t org, vec3_t dir, int color, int count);
// RAFAEL
void CL_ParticleSteamEffect2(cl_sustain_t *self);
@@ -811,114 +811,114 @@ void CL_ParticleSteamEffect2(cl_sustain_t *self);
//
// cl_demo.c
//
-void CL_InitDemos( void );
-void CL_CleanupDemos( void );
-void CL_DemoFrame( int msec );
-qboolean CL_WriteDemoMessage( sizebuf_t *buf );
-void CL_EmitDemoFrame( void );
-void CL_EmitDemoSnapshot( void );
-void CL_FirstDemoFrame( void );
-void CL_Stop_f( void );
-demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info );
+void CL_InitDemos(void);
+void CL_CleanupDemos(void);
+void CL_DemoFrame(int msec);
+qboolean CL_WriteDemoMessage(sizebuf_t *buf);
+void CL_EmitDemoFrame(void);
+void CL_EmitDemoSnapshot(void);
+void CL_FirstDemoFrame(void);
+void CL_Stop_f(void);
+demoInfo_t *CL_GetDemoInfo(const char *path, demoInfo_t *info);
//
// cl_locs.c
//
-void LOC_Init( void );
-void LOC_LoadLocations( void );
-void LOC_FreeLocations( void );
-void LOC_UpdateCvars( void );
-void LOC_AddLocationsToScene( void );
+void LOC_Init(void);
+void LOC_LoadLocations(void);
+void LOC_FreeLocations(void);
+void LOC_UpdateCvars(void);
+void LOC_AddLocationsToScene(void);
//
// cl_console.c
//
-void Con_Init( void );
-void Con_PostInit( void );
-void Con_Shutdown( void );
-void Con_DrawConsole( void );
-void Con_RunConsole( void );
-void Con_Print( const char *txt );
-void Con_ClearNotify_f( void );
-void Con_ToggleConsole_f (void);
-void Con_ClearTyping( void );
-void Con_Close( qboolean force );
-void Con_Popup( void );
-void Con_SkipNotify( qboolean skip );
-void Con_RegisterMedia( void );
-
-void Key_Console( int key );
-void Key_Message( int key );
-void Char_Console( int key );
-void Char_Message( int key );
+void Con_Init(void);
+void Con_PostInit(void);
+void Con_Shutdown(void);
+void Con_DrawConsole(void);
+void Con_RunConsole(void);
+void Con_Print(const char *txt);
+void Con_ClearNotify_f(void);
+void Con_ToggleConsole_f(void);
+void Con_ClearTyping(void);
+void Con_Close(qboolean force);
+void Con_Popup(void);
+void Con_SkipNotify(qboolean skip);
+void Con_RegisterMedia(void);
+
+void Key_Console(int key);
+void Key_Message(int key);
+void Char_Console(int key);
+void Char_Message(int key);
//
// cl_ref.c
//
-void CL_InitRefresh( void );
-void CL_ShutdownRefresh( void );
-void CL_RunRefresh( void );
+void CL_InitRefresh(void);
+void CL_ShutdownRefresh(void);
+void CL_RunRefresh(void);
//
// cl_ui.c
//
-void CL_InitUI( void );
-void CL_ShutdownUI( void );
+void CL_InitUI(void);
+void CL_ShutdownUI(void);
//
// cl_scrn.c
//
extern vrect_t scr_vrect; // position of render window
-void SCR_Init (void);
-void SCR_Shutdown( void );
-void SCR_UpdateScreen (void);
-void SCR_SizeUp( void );
-void SCR_SizeDown( void );
-void SCR_CenterPrint( const char *str );
-void SCR_BeginLoadingPlaque( void );
-void SCR_EndLoadingPlaque( void );
-void SCR_DebugGraph ( float value, int color );
-void SCR_TouchPics ( void );
-void SCR_RegisterMedia( void );
-void SCR_ModeChanged( void );
-void SCR_LagSample( void );
-void SCR_LagClear( void );
-void SCR_SetCrosshairColor( void );
-
-float SCR_FadeAlpha( unsigned startTime, unsigned visTime, unsigned fadeTime );
-int SCR_DrawStringEx( int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font );
-void SCR_DrawStringMulti( int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font );
+void SCR_Init(void);
+void SCR_Shutdown(void);
+void SCR_UpdateScreen(void);
+void SCR_SizeUp(void);
+void SCR_SizeDown(void);
+void SCR_CenterPrint(const char *str);
+void SCR_BeginLoadingPlaque(void);
+void SCR_EndLoadingPlaque(void);
+void SCR_DebugGraph(float value, int color);
+void SCR_TouchPics(void);
+void SCR_RegisterMedia(void);
+void SCR_ModeChanged(void);
+void SCR_LagSample(void);
+void SCR_LagClear(void);
+void SCR_SetCrosshairColor(void);
+
+float SCR_FadeAlpha(unsigned startTime, unsigned visTime, unsigned fadeTime);
+int SCR_DrawStringEx(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font);
+void SCR_DrawStringMulti(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font);
#ifdef _DEBUG
-void CL_AddNetgraph (void);
+void CL_AddNetgraph(void);
#endif
//
// cl_keys.c
//
-void Key_Init( void );
-void Key_Event( unsigned key, qboolean down, unsigned time );
-void Key_CharEvent( int key );
-void Key_WriteBindings( qhandle_t f );
+void Key_Init(void);
+void Key_Event(unsigned key, qboolean down, unsigned time);
+void Key_CharEvent(int key);
+void Key_WriteBindings(qhandle_t f);
//
// cl_aastat.c
//
-void CL_InitAscii( void );
+void CL_InitAscii(void);
#if USE_CURL
//
// cl_http.c
//
-void HTTP_CleanupDownloads (void);
-void HTTP_Init (void);
-void HTTP_Shutdown (void);
-qerror_t HTTP_QueueDownload (const char *path, dltype_t type);
-void HTTP_RunDownloads (void);
-void HTTP_SetServer (const char *url);
+void HTTP_CleanupDownloads(void);
+void HTTP_Init(void);
+void HTTP_Shutdown(void);
+qerror_t HTTP_QueueDownload(const char *path, dltype_t type);
+void HTTP_RunDownloads(void);
+void HTTP_SetServer(const char *url);
#endif
diff --git a/src/cl_locs.c b/src/cl_locs.c
index 31c842d..05b9b99 100644
--- a/src/cl_locs.c
+++ b/src/cl_locs.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -30,7 +30,7 @@ typedef struct {
char name[1];
} location_t;
-static LIST_DECL( cl_locations );
+static LIST_DECL(cl_locations);
static cvar_t *loc_draw;
static cvar_t *loc_trace;
@@ -41,17 +41,18 @@ static cvar_t *loc_dist;
LOC_Alloc
==============
*/
-static location_t *LOC_Alloc( const char *name ) {
+static location_t *LOC_Alloc(const char *name)
+{
location_t *loc;
char buffer[MAX_QPATH];
size_t len;
- Q_strlcpy( buffer, name, sizeof( buffer ) );
- len = COM_strclr( buffer );
+ Q_strlcpy(buffer, name, sizeof(buffer));
+ len = COM_strclr(buffer);
- loc = Z_Malloc( sizeof( *loc ) + len );
- memcpy( loc->name, buffer, len + 1 );
- List_Append( &cl_locations, &loc->entry );
+ loc = Z_Malloc(sizeof(*loc) + len);
+ memcpy(loc->name, buffer, len + 1);
+ List_Append(&cl_locations, &loc->entry);
return loc;
}
@@ -61,7 +62,8 @@ static location_t *LOC_Alloc( const char *name ) {
LOC_LoadLocations
==============
*/
-void LOC_LoadLocations( void ) {
+void LOC_LoadLocations(void)
+{
char path[MAX_OSPATH];
char *buffer, *s, *p;
int line, count;
@@ -70,48 +72,48 @@ void LOC_LoadLocations( void ) {
qerror_t ret;
// load from main directory
- Q_concat( path, sizeof( path ), "locs/", cl.mapname, ".loc", NULL );
+ Q_concat(path, sizeof(path), "locs/", cl.mapname, ".loc", NULL);
- ret = FS_LoadFile( path, (void **)&buffer );
- if( !buffer ) {
- if( ret != Q_ERR_NOENT ) {
- Com_EPrintf( "Couldn't load %s: %s\n", path, Q_ErrorString( ret ) );
+ ret = FS_LoadFile(path, (void **)&buffer);
+ if (!buffer) {
+ if (ret != Q_ERR_NOENT) {
+ Com_EPrintf("Couldn't load %s: %s\n", path, Q_ErrorString(ret));
}
return;
}
s = buffer;
line = count = 0;
- while( *s ) {
- p = strchr( s, '\n' );
- if( p ) {
+ while (*s) {
+ p = strchr(s, '\n');
+ if (p) {
*p = 0;
}
- Cmd_TokenizeString( s, qfalse );
+ Cmd_TokenizeString(s, qfalse);
line++;
argc = Cmd_Argc();
- if( argc != 0 && argc < 4 ) {
- Com_WPrintf( "Line %i is incomplete in %s\n", line, path );
+ if (argc != 0 && argc < 4) {
+ Com_WPrintf("Line %i is incomplete in %s\n", line, path);
} else {
- loc = LOC_Alloc( Cmd_RawArgsFrom( 3 ) );
- loc->origin[0] = atof( Cmd_Argv( 0 ) ) * 0.125f;
- loc->origin[1] = atof( Cmd_Argv( 1 ) ) * 0.125f;
- loc->origin[2] = atof( Cmd_Argv( 2 ) ) * 0.125f;
+ loc = LOC_Alloc(Cmd_RawArgsFrom(3));
+ loc->origin[0] = atof(Cmd_Argv(0)) * 0.125f;
+ loc->origin[1] = atof(Cmd_Argv(1)) * 0.125f;
+ loc->origin[2] = atof(Cmd_Argv(2)) * 0.125f;
count++;
}
- if( !p ) {
+ if (!p) {
break;
}
s = p + 1;
}
- Com_DPrintf( "Loaded %i locations from %s\n", count, path );
+ Com_DPrintf("Loaded %i locations from %s\n", count, path);
- FS_FreeFile( buffer );
+ FS_FreeFile(buffer);
}
/*
@@ -119,13 +121,14 @@ void LOC_LoadLocations( void ) {
LOC_FreeLocations
==============
*/
-void LOC_FreeLocations( void ) {
+void LOC_FreeLocations(void)
+{
location_t *loc, *next;
- LIST_FOR_EACH_SAFE( location_t, loc, next, &cl_locations, entry ) {
- Z_Free( loc );
+ LIST_FOR_EACH_SAFE(location_t, loc, next, &cl_locations, entry) {
+ Z_Free(loc);
}
- List_Init( &cl_locations );
+ List_Init(&cl_locations);
}
/*
@@ -133,7 +136,8 @@ void LOC_FreeLocations( void ) {
LOC_FindClosest
==============
*/
-static location_t *LOC_FindClosest( vec3_t pos ) {
+static location_t *LOC_FindClosest(vec3_t pos)
+{
location_t *loc, *nearest;
vec3_t dir;
float dist, minDist;
@@ -141,23 +145,23 @@ static location_t *LOC_FindClosest( vec3_t pos ) {
minDist = 99999;
nearest = NULL;
- LIST_FOR_EACH( location_t, loc, &cl_locations, entry ) {
- VectorSubtract( pos, loc->origin, dir );
- dist = VectorLength( dir );
+ LIST_FOR_EACH(location_t, loc, &cl_locations, entry) {
+ VectorSubtract(pos, loc->origin, dir);
+ dist = VectorLength(dir);
- if( dist > loc_dist->value ) {
+ if (dist > loc_dist->value) {
continue;
}
- if( loc_trace->integer ) {
- CM_BoxTrace( &trace, pos, loc->origin, vec3_origin, vec3_origin,
- cl.bsp->nodes, MASK_SOLID );
- if( trace.fraction != 1.0f ) {
+ if (loc_trace->integer) {
+ CM_BoxTrace(&trace, pos, loc->origin, vec3_origin, vec3_origin,
+ cl.bsp->nodes, MASK_SOLID);
+ if (trace.fraction != 1.0f) {
continue;
}
}
-
- if( dist < minDist ) {
+
+ if (dist < minDist) {
minDist = dist;
nearest = loc;
}
@@ -171,41 +175,42 @@ static location_t *LOC_FindClosest( vec3_t pos ) {
LOC_AddLocationsToScene
==============
*/
-void LOC_AddLocationsToScene( void ) {
+void LOC_AddLocationsToScene(void)
+{
location_t *loc, *nearest;
vec3_t dir;
float dist;
entity_t ent;
- if( !loc_draw->integer ) {
+ if (!loc_draw->integer) {
return;
}
- memset( &ent, 0, sizeof( ent ) );
- ent.model = R_RegisterModel( "models/items/c_head/tris.md2" );
- ent.skin = R_RegisterSkin( "models/items/c_head/skin.pcx" );
+ memset(&ent, 0, sizeof(ent));
+ ent.model = R_RegisterModel("models/items/c_head/tris.md2");
+ ent.skin = R_RegisterSkin("models/items/c_head/skin.pcx");
- nearest = LOC_FindClosest( cl.playerEntityOrigin );
- if( !nearest ) {
+ nearest = LOC_FindClosest(cl.playerEntityOrigin);
+ if (!nearest) {
return;
}
- LIST_FOR_EACH( location_t, loc, &cl_locations, entry ) {
- VectorSubtract( cl.playerEntityOrigin, loc->origin, dir );
- dist = VectorLength( dir );
+ LIST_FOR_EACH(location_t, loc, &cl_locations, entry) {
+ VectorSubtract(cl.playerEntityOrigin, loc->origin, dir);
+ dist = VectorLength(dir);
- if( dist > loc_dist->integer ) {
+ if (dist > loc_dist->integer) {
continue;
}
- VectorCopy( loc->origin, ent.origin );
+ VectorCopy(loc->origin, ent.origin);
- if( loc == nearest ) {
- ent.origin[2] += 10.0f * sin( cl.time * 0.01f );
- V_AddLight( loc->origin, 200, 1, 1, 1 );
+ if (loc == nearest) {
+ ent.origin[2] += 10.0f * sin(cl.time * 0.01f);
+ V_AddLight(loc->origin, 200, 1, 1, 1);
}
- V_AddEntity( &ent );
+ V_AddEntity(&ent);
}
@@ -216,18 +221,19 @@ void LOC_AddLocationsToScene( void ) {
LOC_Here_m
==============
*/
-static size_t LOC_Here_m( char *buffer, size_t size ) {
+static size_t LOC_Here_m(char *buffer, size_t size)
+{
location_t *loc;
size_t ret;
- ret = Q_strlcpy( buffer, "unknown", size );
- if( cls.state != ca_active ) {
+ ret = Q_strlcpy(buffer, "unknown", size);
+ if (cls.state != ca_active) {
return ret;
}
- loc = LOC_FindClosest( cl.playerEntityOrigin );
- if( loc ) {
- ret = Q_strlcpy( buffer, loc->name, size );
+ loc = LOC_FindClosest(cl.playerEntityOrigin);
+ if (loc) {
+ ret = Q_strlcpy(buffer, loc->name, size);
}
return ret;
}
@@ -237,24 +243,25 @@ static size_t LOC_Here_m( char *buffer, size_t size ) {
LOC_There_m
==============
*/
-static size_t LOC_There_m( char *buffer, size_t size ) {
+static size_t LOC_There_m(char *buffer, size_t size)
+{
location_t *loc;
vec3_t pos;
trace_t trace;
int ret;
- ret = Q_strlcpy( buffer, "unknown", size );
- if( cls.state != ca_active ) {
+ ret = Q_strlcpy(buffer, "unknown", size);
+ if (cls.state != ca_active) {
return ret;
}
- VectorMA( cl.playerEntityOrigin, 8192, cl.v_forward, pos );
- CM_BoxTrace( &trace, cl.playerEntityOrigin, pos, vec3_origin, vec3_origin,
- cl.bsp->nodes, MASK_SOLID );
+ VectorMA(cl.playerEntityOrigin, 8192, cl.v_forward, pos);
+ CM_BoxTrace(&trace, cl.playerEntityOrigin, pos, vec3_origin, vec3_origin,
+ cl.bsp->nodes, MASK_SOLID);
- loc = LOC_FindClosest( trace.endpos );
- if( loc ) {
- ret = Q_strlcpy( buffer, loc->name, size );
+ loc = LOC_FindClosest(trace.endpos);
+ if (loc) {
+ ret = Q_strlcpy(buffer, loc->name, size);
}
return ret;
}
@@ -264,13 +271,14 @@ static size_t LOC_There_m( char *buffer, size_t size ) {
LOC_Init
==============
*/
-void LOC_Init( void ) {
-// loc_enable = Cvar_Get( "loc_enable", "0", 0 );
- loc_trace = Cvar_Get( "loc_trace", "0", 0 );
- loc_draw = Cvar_Get( "loc_draw", "0", 0 );
- loc_dist = Cvar_Get( "loc_dist", "500", 0 );
-
- Cmd_AddMacro( "loc_here", LOC_Here_m );
- Cmd_AddMacro( "loc_there", LOC_There_m );
+void LOC_Init(void)
+{
+// loc_enable = Cvar_Get("loc_enable", "0", 0);
+ loc_trace = Cvar_Get("loc_trace", "0", 0);
+ loc_draw = Cvar_Get("loc_draw", "0", 0);
+ loc_dist = Cvar_Get("loc_dist", "500", 0);
+
+ Cmd_AddMacro("loc_here", LOC_Here_m);
+ Cmd_AddMacro("loc_there", LOC_There_m);
}
diff --git a/src/cl_main.c b/src/cl_main.c
index b8dcaf1..ccc627e 100644
--- a/src/cl_main.c
+++ b/src/cl_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+*/
// cl_main.c -- client main loop
#include "cl_local.h"
@@ -92,7 +92,7 @@ extern cvar_t *gl_brightness;
client_static_t cls;
client_state_t cl;
-centity_t cl_entities[ MAX_EDICTS ];
+centity_t cl_entities[MAX_EDICTS];
// used for executing stringcmds
cmdbuf_t cl_cmdbuf;
@@ -115,12 +115,13 @@ typedef struct {
} request_t;
#define MAX_REQUESTS 64
-#define REQUEST_MASK ( MAX_REQUESTS - 1 )
+#define REQUEST_MASK (MAX_REQUESTS - 1)
static request_t clientRequests[MAX_REQUESTS];
static int currentRequest;
-static request_t *CL_AddRequest( const netadr_t *adr, requestType_t type ) {
+static request_t *CL_AddRequest(const netadr_t *adr, requestType_t type)
+{
request_t *r;
r = &clientRequests[currentRequest & REQUEST_MASK];
@@ -133,86 +134,91 @@ static request_t *CL_AddRequest( const netadr_t *adr, requestType_t type ) {
return r;
}
-static void CL_UpdateGunSetting( void ) {
+static void CL_UpdateGunSetting(void)
+{
int nogun;
- if( cls.state < ca_connected ) {
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol < PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.serverProtocol < PROTOCOL_VERSION_R1Q2) {
return;
}
- if( cl_gun->integer == -1 ) {
+ if (cl_gun->integer == -1) {
nogun = 2;
- } else if( cl_gun->integer == 0 || info_hand->integer == 2 ) {
+ } else if (cl_gun->integer == 0 || info_hand->integer == 2) {
nogun = 1;
} else {
nogun = 0;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_NOGUN );
- MSG_WriteShort( nogun );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_NOGUN);
+ MSG_WriteShort(nogun);
+ MSG_FlushTo(&cls.netchan->message);
}
-static void CL_UpdateGibSetting( void ) {
- if( cls.state < ca_connected ) {
+static void CL_UpdateGibSetting(void)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
return;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_NOGIBS );
- MSG_WriteShort( !cl_gibs->integer );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_NOGIBS);
+ MSG_WriteShort(!cl_gibs->integer);
+ MSG_FlushTo(&cls.netchan->message);
}
-static void CL_UpdateFootstepsSetting( void ) {
- if( cls.state < ca_connected ) {
+static void CL_UpdateFootstepsSetting(void)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
return;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_NOFOOTSTEPS );
- MSG_WriteShort( !cl_footsteps->integer );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_NOFOOTSTEPS);
+ MSG_WriteShort(!cl_footsteps->integer);
+ MSG_FlushTo(&cls.netchan->message);
}
-static void CL_UpdatePredictSetting( void ) {
- if( cls.state < ca_connected ) {
+static void CL_UpdatePredictSetting(void)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
return;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_NOPREDICT );
- MSG_WriteShort( !cl_predict->integer );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_NOPREDICT);
+ MSG_WriteShort(!cl_predict->integer);
+ MSG_FlushTo(&cls.netchan->message);
}
#if USE_FPS
-static void CL_UpdateRateSetting( void ) {
- if( cls.state < ca_connected ) {
+static void CL_UpdateRateSetting(void)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
return;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_FPS );
- MSG_WriteShort( cl_updaterate->integer );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_FPS);
+ MSG_WriteShort(cl_updaterate->integer);
+ MSG_FlushTo(&cls.netchan->message);
}
#endif
@@ -221,36 +227,38 @@ static void CL_UpdateRateSetting( void ) {
CL_ClientCommand
===================
*/
-void CL_ClientCommand( const char *string ) {
- if ( !cls.netchan ) {
+void CL_ClientCommand(const char *string)
+{
+ if (!cls.netchan) {
return;
}
- Com_DDPrintf( "%s: %s\n", __func__, string );
+ Com_DDPrintf("%s: %s\n", __func__, string);
- MSG_WriteByte( clc_stringcmd );
- MSG_WriteString( string );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_stringcmd);
+ MSG_WriteString(string);
+ MSG_FlushTo(&cls.netchan->message);
}
/*
===================
CL_ForwardToServer
-
+
adds the current command line as a clc_stringcmd to the client message.
things like godmode, noclip, etc, are commands directed to the server,
so when they are typed in at the console, they will need to be forwarded.
===================
*/
-qboolean CL_ForwardToServer( void ) {
+qboolean CL_ForwardToServer(void)
+{
char *cmd;
- cmd = Cmd_Argv( 0 );
- if( cls.state < ca_active || *cmd == '-' || *cmd == '+' ) {
+ cmd = Cmd_Argv(0);
+ if (cls.state < ca_active || *cmd == '-' || *cmd == '+') {
return qfalse;
}
- CL_ClientCommand( Cmd_RawArgsFrom( 0 ) );
+ CL_ClientCommand(Cmd_RawArgsFrom(0));
return qtrue;
}
@@ -259,19 +267,20 @@ qboolean CL_ForwardToServer( void ) {
CL_ForwardToServer_f
==================
*/
-static void CL_ForwardToServer_f( void ) {
- if ( cls.state < ca_connected ) {
- Com_Printf( "Can't \"%s\", not connected\n", Cmd_Argv( 0 ) );
+static void CL_ForwardToServer_f(void)
+{
+ if (cls.state < ca_connected) {
+ Com_Printf("Can't \"%s\", not connected\n", Cmd_Argv(0));
return;
}
- if ( cls.demo.playback ) {
+ if (cls.demo.playback) {
return;
}
// don't forward the first argument
- if ( Cmd_Argc() > 1 ) {
- CL_ClientCommand( Cmd_RawArgs() );
+ if (Cmd_Argc() > 1) {
+ CL_ClientCommand(Cmd_RawArgs());
}
}
@@ -280,19 +289,20 @@ static void CL_ForwardToServer_f( void ) {
CL_Pause_f
==================
*/
-static void CL_Pause_f( void ) {
+static void CL_Pause_f(void)
+{
#if USE_MVD_CLIENT
- if( sv_running->integer == ss_broadcast ) {
- Cbuf_InsertText( &cmd_buffer, "mvdpause @@\n" );
+ if (sv_running->integer == ss_broadcast) {
+ Cbuf_InsertText(&cmd_buffer, "mvdpause @@\n");
return;
}
#endif
// activate manual pause
- if( cl_paused->integer == 2 ) {
- Cvar_Set( "cl_paused", "0" );
+ if (cl_paused->integer == 2) {
+ Cvar_Set("cl_paused", "0");
} else {
- Cvar_Set( "cl_paused", "2" );
+ Cvar_Set("cl_paused", "2");
}
CL_CheckForPause();
@@ -301,31 +311,31 @@ static void CL_Pause_f( void ) {
/*
=================
CL_CheckForResend
-
+
Resend a connect message if the last one has timed out
=================
*/
-void CL_CheckForResend( void ) {
+void CL_CheckForResend(void)
+{
char tail[MAX_QPATH];
char userinfo[MAX_INFO_STRING];
int maxmsglen;
- if ( cls.demo.playback ) {
+ if (cls.demo.playback) {
return;
}
// if the local server is running and we aren't
// then connect
- if ( cls.state < ca_connecting && sv_running->integer > ss_loading ) {
- strcpy( cls.servername, "localhost" );
+ if (cls.state < ca_connecting && sv_running->integer > ss_loading) {
+ strcpy(cls.servername, "localhost");
cls.serverAddress.type = NA_LOOPBACK;
cls.serverProtocol = cl_protocol->integer;
- if( cls.serverProtocol < PROTOCOL_VERSION_DEFAULT ||
- cls.serverProtocol > PROTOCOL_VERSION_Q2PRO )
- {
+ if (cls.serverProtocol < PROTOCOL_VERSION_DEFAULT ||
+ cls.serverProtocol > PROTOCOL_VERSION_Q2PRO) {
cls.serverProtocol = PROTOCOL_VERSION_Q2PRO;
}
-
+
// we don't need a challenge on the localhost
cls.state = ca_connecting;
cls.connect_time -= CONNECT_FAST;
@@ -335,52 +345,52 @@ void CL_CheckForResend( void ) {
Con_Popup();
#if USE_UI
- UI_OpenMenu( UIMENU_NONE );
+ UI_OpenMenu(UIMENU_NONE);
#endif
}
// resend if we haven't gotten a reply yet
- if( cls.state != ca_connecting && cls.state != ca_challenging ) {
+ if (cls.state != ca_connecting && cls.state != ca_challenging) {
return;
}
- if( cls.realtime - cls.connect_time < CONNECT_DELAY ) {
+ if (cls.realtime - cls.connect_time < CONNECT_DELAY) {
return;
}
cls.connect_time = cls.realtime; // for retransmit requests
cls.connect_count++;
- if ( cls.state == ca_challenging ) {
- Com_Printf( "Requesting challenge... %i\n", cls.connect_count );
- OOB_PRINT( NS_CLIENT, &cls.serverAddress, "getchallenge\n" );
+ if (cls.state == ca_challenging) {
+ Com_Printf("Requesting challenge... %i\n", cls.connect_count);
+ OOB_PRINT(NS_CLIENT, &cls.serverAddress, "getchallenge\n");
return;
}
//
// We have gotten a challenge from the server, so try and connect.
//
- Com_Printf( "Requesting connection... %i\n", cls.connect_count );
+ Com_Printf("Requesting connection... %i\n", cls.connect_count);
cls.userinfo_modified = 0;
// use maximum allowed msglen for loopback
maxmsglen = net_maxmsglen->integer;
- if( NET_IsLocalAddress( &cls.serverAddress ) ) {
+ if (NET_IsLocalAddress(&cls.serverAddress)) {
maxmsglen = MAX_PACKETLEN_WRITABLE;
}
// add protocol dependent stuff
- switch( cls.serverProtocol ) {
+ switch (cls.serverProtocol) {
case PROTOCOL_VERSION_R1Q2:
- Q_snprintf( tail, sizeof( tail ), " %d %d",
- maxmsglen, PROTOCOL_VERSION_R1Q2_CURRENT );
+ Q_snprintf(tail, sizeof(tail), " %d %d",
+ maxmsglen, PROTOCOL_VERSION_R1Q2_CURRENT);
cls.quakePort = net_qport->integer & 0xff;
break;
case PROTOCOL_VERSION_Q2PRO:
- Q_snprintf( tail, sizeof( tail ), " %d %d %d %d",
- maxmsglen, net_chantype->integer, USE_ZLIB,
- PROTOCOL_VERSION_Q2PRO_CURRENT );
+ Q_snprintf(tail, sizeof(tail), " %d %d %d %d",
+ maxmsglen, net_chantype->integer, USE_ZLIB,
+ PROTOCOL_VERSION_Q2PRO_CURRENT);
cls.quakePort = net_qport->integer & 0xff;
break;
default:
@@ -389,37 +399,39 @@ void CL_CheckForResend( void ) {
break;
}
- Cvar_BitInfo( userinfo, CVAR_USERINFO );
- Netchan_OutOfBand( NS_CLIENT, &cls.serverAddress,
- "connect %i %i %i \"%s\"%s\n", cls.serverProtocol, cls.quakePort,
- cls.challenge, userinfo, tail );
+ Cvar_BitInfo(userinfo, CVAR_USERINFO);
+ Netchan_OutOfBand(NS_CLIENT, &cls.serverAddress,
+ "connect %i %i %i \"%s\"%s\n", cls.serverProtocol, cls.quakePort,
+ cls.challenge, userinfo, tail);
}
-static void CL_RecentIP_g( genctx_t *ctx ) {
+static void CL_RecentIP_g(genctx_t *ctx)
+{
netadr_t *a;
int i, j;
j = cls.recent_head - RECENT_ADDR;
- if( j < 0 ) {
+ if (j < 0) {
j = 0;
}
- for( i = cls.recent_head - 1; i >= j; i-- ) {
+ for (i = cls.recent_head - 1; i >= j; i--) {
a = &cls.recent_addr[i & RECENT_MASK];
- if( a->type ) {
- Prompt_AddMatch( ctx, NET_AdrToString( a ) );
+ if (a->type) {
+ Prompt_AddMatch(ctx, NET_AdrToString(a));
}
}
}
-static void CL_Connect_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- CL_RecentIP_g( ctx );
- Com_Address_g( ctx );
- } else if( argnum == 2 ) {
- if( !ctx->partial[0] || ( ctx->partial[0] == '3' && !ctx->partial[1] ) ) {
- Prompt_AddMatch( ctx, "34" );
- Prompt_AddMatch( ctx, "35" );
- Prompt_AddMatch( ctx, "36" );
+static void CL_Connect_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ CL_RecentIP_g(ctx);
+ Com_Address_g(ctx);
+ } else if (argnum == 2) {
+ if (!ctx->partial[0] || (ctx->partial[0] == '3' && !ctx->partial[1])) {
+ Prompt_AddMatch(ctx, "34");
+ Prompt_AddMatch(ctx, "35");
+ Prompt_AddMatch(ctx, "36");
}
}
}
@@ -427,59 +439,59 @@ static void CL_Connect_c( genctx_t *ctx, int argnum ) {
/*
================
CL_Connect_f
-
+
================
*/
-static void CL_Connect_f( void ) {
+static void CL_Connect_f(void)
+{
char *server, *p;
netadr_t address;
int protocol;
int argc = Cmd_Argc();
- if( argc < 2 ) {
+ if (argc < 2) {
usage:
- Com_Printf( "Usage: %s <server> [34|35|36]\n", Cmd_Argv( 0 ) );
+ Com_Printf("Usage: %s <server> [34|35|36]\n", Cmd_Argv(0));
return;
}
- if( argc > 2 ) {
- protocol = atoi( Cmd_Argv( 2 ) );
- if( protocol < PROTOCOL_VERSION_DEFAULT ||
- protocol > PROTOCOL_VERSION_Q2PRO )
- {
+ if (argc > 2) {
+ protocol = atoi(Cmd_Argv(2));
+ if (protocol < PROTOCOL_VERSION_DEFAULT ||
+ protocol > PROTOCOL_VERSION_Q2PRO) {
goto usage;
}
} else {
protocol = cl_protocol->integer;
- if( !protocol ) {
+ if (!protocol) {
protocol = PROTOCOL_VERSION_Q2PRO;
}
}
- server = Cmd_Argv( 1 );
+ server = Cmd_Argv(1);
// support quake2://<address>[/] scheme
- if( !Q_strncasecmp( server, "quake2://", 9 ) ) {
+ if (!Q_strncasecmp(server, "quake2://", 9)) {
server += 9;
- if( ( p = strchr( server, '/' ) ) != NULL ) {
+ if ((p = strchr(server, '/')) != NULL) {
*p = 0;
}
}
- if ( !NET_StringToAdr( server, &address, PORT_SERVER ) ) {
- Com_Printf( "Bad server address\n" );
+ if (!NET_StringToAdr(server, &address, PORT_SERVER)) {
+ Com_Printf("Bad server address\n");
return;
}
// copy early to avoid potential cmd_argv[1] clobbering
- Q_strlcpy( cls.servername, server, sizeof( cls.servername ) );
+ Q_strlcpy(cls.servername, server, sizeof(cls.servername));
// if running a local server, kill it and reissue
- SV_Shutdown( "Server was killed.\n", ERR_DISCONNECT );
+ SV_Shutdown("Server was killed.\n", ERR_DISCONNECT);
- NET_Config( NET_CLIENT );
+ NET_Config(NET_CLIENT);
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
cls.serverAddress = address;
cls.serverProtocol = protocol;
@@ -493,120 +505,126 @@ usage:
CL_CheckForResend();
- Cvar_Set( "timedemo", "0" );
+ Cvar_Set("timedemo", "0");
}
-static void CL_FollowIP_f( void ) {
+static void CL_FollowIP_f(void)
+{
netadr_t *a;
int i, j;
- if( Cmd_Argc() > 1 ) {
+ if (Cmd_Argc() > 1) {
// optional second argument references less recent address
- j = atoi( Cmd_Argv( 1 ) ) + 1;
- clamp( j, 1, RECENT_ADDR );
+ j = atoi(Cmd_Argv(1)) + 1;
+ clamp(j, 1, RECENT_ADDR);
} else {
j = 1;
}
i = cls.recent_head - j;
- if( i < 0 ) {
- Com_Printf( "No IP address to follow.\n" );
+ if (i < 0) {
+ Com_Printf("No IP address to follow.\n");
return;
}
a = &cls.recent_addr[i & RECENT_MASK];
- if( a->type ) {
- char *s = NET_AdrToString( a );
- Com_Printf( "Following %s...\n", s );
- Cbuf_InsertText( cmd_current, va( "connect %s\n", s ) );
+ if (a->type) {
+ char *s = NET_AdrToString(a);
+ Com_Printf("Following %s...\n", s);
+ Cbuf_InsertText(cmd_current, va("connect %s\n", s));
}
}
-static void CL_PassiveConnect_f( void ) {
+static void CL_PassiveConnect_f(void)
+{
netadr_t address;
- if( cls.passive ) {
+ if (cls.passive) {
cls.passive = qfalse;
- Com_Printf( "No longer listening for passive connections.\n" );
+ Com_Printf("No longer listening for passive connections.\n");
return;
}
// if running a local server, kill it and reissue
- SV_Shutdown( "Server was killed.\n", ERR_DISCONNECT );
+ SV_Shutdown("Server was killed.\n", ERR_DISCONNECT);
- NET_Config( NET_CLIENT );
+ NET_Config(NET_CLIENT);
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
- if( !NET_GetAddress( NS_CLIENT, &address ) ) {
+ if (!NET_GetAddress(NS_CLIENT, &address)) {
return;
}
cls.passive = qtrue;
- Com_Printf( "Listening for passive connections at %s.\n",
- NET_AdrToString( &address ) );
+ Com_Printf("Listening for passive connections at %s.\n",
+ NET_AdrToString(&address));
}
-void CL_SendRcon( const netadr_t *adr, const char *pass, const char *cmd ) {
- NET_Config( NET_CLIENT );
+void CL_SendRcon(const netadr_t *adr, const char *pass, const char *cmd)
+{
+ NET_Config(NET_CLIENT);
- CL_AddRequest( adr, REQ_RCON );
+ CL_AddRequest(adr, REQ_RCON);
- Netchan_OutOfBand( NS_CLIENT, adr, "rcon \"%s\" %s", pass, cmd );
+ Netchan_OutOfBand(NS_CLIENT, adr, "rcon \"%s\" %s", pass, cmd);
}
/*
=====================
CL_Rcon_f
-
+
Send the rest of the command line over as
an unconnected command.
=====================
*/
-static void CL_Rcon_f( void ) {
+static void CL_Rcon_f(void)
+{
netadr_t address;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <command>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <command>\n", Cmd_Argv(0));
return;
}
- if( !rcon_password->string[0] ) {
- Com_Printf( "You must set 'rcon_password' before "
- "issuing an rcon command.\n" );
+ if (!rcon_password->string[0]) {
+ Com_Printf("You must set 'rcon_password' before "
+ "issuing an rcon command.\n");
return;
}
- if( !cls.netchan ) {
- if( !rcon_address->string[0] ) {
- Com_Printf( "You must either be connected, "
- "or set the 'rcon_address' cvar "
- "to issue rcon commands.\n" );
+ if (!cls.netchan) {
+ if (!rcon_address->string[0]) {
+ Com_Printf("You must either be connected, "
+ "or set the 'rcon_address' cvar "
+ "to issue rcon commands.\n");
return;
}
- if( !NET_StringToAdr( rcon_address->string, &address, PORT_SERVER ) ) {
- Com_Printf( "Bad address: %s\n", rcon_address->string );
+ if (!NET_StringToAdr(rcon_address->string, &address, PORT_SERVER)) {
+ Com_Printf("Bad address: %s\n", rcon_address->string);
return;
}
} else {
address = cls.netchan->remote_address;
}
- CL_SendRcon( &address, rcon_password->string, Cmd_RawArgs() );
+ CL_SendRcon(&address, rcon_password->string, Cmd_RawArgs());
}
-static void CL_Rcon_c( genctx_t *ctx, int argnum ) {
- Com_Generic_c( ctx, argnum - 1 );
+static void CL_Rcon_c(genctx_t *ctx, int argnum)
+{
+ Com_Generic_c(ctx, argnum - 1);
}
/*
=====================
CL_ClearState
-
+
=====================
*/
-void CL_ClearState( void ) {
+void CL_ClearState(void)
+{
S_StopAllSounds();
CL_ClearEffects();
#if USE_LIGHTSTYLES
@@ -616,11 +634,11 @@ void CL_ClearState( void ) {
LOC_FreeLocations();
// wipe the entire cl structure
- BSP_Free( cl.bsp );
- memset( &cl, 0, sizeof( cl ) );
- memset( &cl_entities, 0, sizeof( cl_entities ) );
+ BSP_Free(cl.bsp);
+ memset(&cl, 0, sizeof(cl));
+ memset(&cl_entities, 0, sizeof(cl_entities));
- if( cls.state > ca_connected ) {
+ if (cls.state > ca_connected) {
cls.state = ca_connected;
CL_CheckForPause();
CL_UpdateFrameTimes();
@@ -640,26 +658,27 @@ void CL_ClearState( void ) {
/*
=====================
CL_Disconnect
-
+
Goes from a connected state to full screen console state
Sends a disconnect message to the server
This is also called on Com_Error, so it shouldn't cause any errors
=====================
*/
-void CL_Disconnect( error_type_t type ) {
- if( !cls.state ) {
+void CL_Disconnect(error_type_t type)
+{
+ if (!cls.state) {
return;
}
SCR_EndLoadingPlaque(); // get rid of loading plaque
- if( cls.state > ca_disconnected && !cls.demo.playback ) {
- EXEC_TRIGGER( cl_disconnectcmd );
+ if (cls.state > ca_disconnected && !cls.demo.playback) {
+ EXEC_TRIGGER(cl_disconnectcmd);
}
#if 0
- if( cls.ref_initialized ) {
- R_CinematicSetPalette( NULL );
+ if (cls.ref_initialized) {
+ R_CinematicSetPalette(NULL);
}
#endif
@@ -670,16 +689,16 @@ void CL_Disconnect( error_type_t type ) {
cls.errorReceived = qfalse;
#endif
- if( cls.netchan ) {
+ if (cls.netchan) {
// send a disconnect message to the server
- MSG_WriteByte( clc_stringcmd );
- MSG_WriteData( "disconnect", 11 );
+ MSG_WriteByte(clc_stringcmd);
+ MSG_WriteData("disconnect", 11);
- cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data, 3 );
+ cls.netchan->Transmit(cls.netchan, msg_write.cursize, msg_write.data, 3);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- Netchan_Close( cls.netchan );
+ Netchan_Close(cls.netchan);
cls.netchan = NULL;
}
@@ -689,16 +708,16 @@ void CL_Disconnect( error_type_t type ) {
// stop download
CL_CleanupDownloads();
- CL_ClearState ();
+ CL_ClearState();
cls.state = ca_disconnected;
cls.userinfo_modified = 0;
#if USE_UI
- if( type == ERR_DISCONNECT ) {
- UI_OpenMenu( UIMENU_DEFAULT );
+ if (type == ERR_DISCONNECT) {
+ UI_OpenMenu(UIMENU_DEFAULT);
} else {
- UI_OpenMenu( UIMENU_NONE );
+ UI_OpenMenu(UIMENU_NONE);
}
#endif
@@ -712,16 +731,18 @@ void CL_Disconnect( error_type_t type ) {
CL_Disconnect_f
================
*/
-static void CL_Disconnect_f( void ) {
- if( cls.state > ca_disconnected ) {
- Com_Error( ERR_DISCONNECT, "Disconnected from server" );
+static void CL_Disconnect_f(void)
+{
+ if (cls.state > ca_disconnected) {
+ Com_Error(ERR_DISCONNECT, "Disconnected from server");
}
}
-static void CL_ServerStatus_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- CL_RecentIP_g( ctx );
- Com_Address_g( ctx );
+static void CL_ServerStatus_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ CL_RecentIP_g(ctx);
+ Com_Address_g(ctx);
}
}
@@ -730,32 +751,33 @@ static void CL_ServerStatus_c( genctx_t *ctx, int argnum ) {
CL_ServerStatus_f
================
*/
-static void CL_ServerStatus_f( void ) {
+static void CL_ServerStatus_f(void)
+{
char *s;
netadr_t adr;
neterr_t ret;
- if( Cmd_Argc() < 2 ) {
- if( !cls.netchan ) {
- Com_Printf( "Usage: %s [address]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ if (!cls.netchan) {
+ Com_Printf("Usage: %s [address]\n", Cmd_Argv(0));
return;
}
adr = cls.netchan->remote_address;
} else {
- s = Cmd_Argv( 1 );
- if( !NET_StringToAdr( s, &adr, PORT_SERVER ) ) {
- Com_Printf( "Bad address: %s\n", s );
+ s = Cmd_Argv(1);
+ if (!NET_StringToAdr(s, &adr, PORT_SERVER)) {
+ Com_Printf("Bad address: %s\n", s);
return;
}
}
- CL_AddRequest( &adr, REQ_STATUS );
+ CL_AddRequest(&adr, REQ_STATUS);
- NET_Config( NET_CLIENT );
+ NET_Config(NET_CLIENT);
- ret = OOB_PRINT( NS_CLIENT, &adr, "status" );
- if( ret == NET_ERROR ) {
- Com_Printf( "%s to %s\n", NET_ErrorString(), NET_AdrToString( &adr ) );
+ ret = OOB_PRINT(NS_CLIENT, &adr, "status");
+ if (ret == NET_ERROR) {
+ Com_Printf("%s to %s\n", NET_ErrorString(), NET_AdrToString(&adr));
}
}
@@ -764,9 +786,10 @@ static void CL_ServerStatus_f( void ) {
SortPlayers
====================
*/
-static int QDECL SortPlayers( const void *v1, const void *v2 ) {
- const playerStatus_t *p1 = ( const playerStatus_t * )v1;
- const playerStatus_t *p2 = ( const playerStatus_t * )v2;
+static int QDECL SortPlayers(const void *v1, const void *v2)
+{
+ const playerStatus_t *p1 = (const playerStatus_t *)v1;
+ const playerStatus_t *p2 = (const playerStatus_t *)v2;
return p2->score - p1->score;
}
@@ -776,84 +799,85 @@ static int QDECL SortPlayers( const void *v1, const void *v2 ) {
CL_ServerStatusResponse
====================
*/
-static qboolean CL_ServerStatusResponse( const char *status, size_t len, serverStatus_t *dest ) {
+static qboolean CL_ServerStatusResponse(const char *status, size_t len, serverStatus_t *dest)
+{
const char *s;
playerStatus_t *player;
size_t infolen;
- memset( dest, 0, sizeof( *dest ) );
+ memset(dest, 0, sizeof(*dest));
- s = memchr( status, '\n', len );
- if( !s ) {
+ s = memchr(status, '\n', len);
+ if (!s) {
return qfalse;
}
infolen = s - status;
- if( !infolen || infolen >= MAX_STRING_CHARS ) {
+ if (!infolen || infolen >= MAX_STRING_CHARS) {
return qfalse;
}
s++;
- strcpy( dest->address, NET_AdrToString( &net_from ) );
- memcpy( dest->infostring, status, infolen );
-
+ strcpy(dest->address, NET_AdrToString(&net_from));
+ memcpy(dest->infostring, status, infolen);
+
// HACK: check if this is a status response
- if( !strstr( dest->infostring, "\\maxclients\\" ) ) {
+ if (!strstr(dest->infostring, "\\maxclients\\")) {
return qfalse;
}
// parse player list
- if( *s < 32 ) {
+ if (*s < 32) {
return qtrue;
}
do {
player = &dest->players[dest->numPlayers];
- player->score = atoi( COM_Parse( &s ) );
- player->ping = atoi( COM_Parse( &s ) );
- if( !s ) {
+ player->score = atoi(COM_Parse(&s));
+ player->ping = atoi(COM_Parse(&s));
+ if (!s) {
break;
- }
- Q_strlcpy( player->name, COM_Parse( &s ), sizeof( player->name ) );
+ }
+ Q_strlcpy(player->name, COM_Parse(&s), sizeof(player->name));
- if ( ++dest->numPlayers == MAX_STATUS_PLAYERS ) {
+ if (++dest->numPlayers == MAX_STATUS_PLAYERS) {
break;
}
- } while( s );
+ } while (s);
- qsort( dest->players, dest->numPlayers, sizeof( dest->players[ 0 ] ),
- SortPlayers );
+ qsort(dest->players, dest->numPlayers, sizeof(dest->players[0]), SortPlayers);
return qtrue;
}
-static void CL_DumpServerInfo( const serverStatus_t *status ) {
+static void CL_DumpServerInfo(const serverStatus_t *status)
+{
char key[MAX_STRING_CHARS];
char value[MAX_STRING_CHARS];
const playerStatus_t *player;
const char *infostring;
int i;
- Com_Printf( "Info response from %s:\n",
- NET_AdrToString( &net_from ) );
+ Com_Printf("Info response from %s:\n",
+ NET_AdrToString(&net_from));
infostring = status->infostring;
do {
- Info_NextPair( &infostring, key, value );
-
- if( !key[0] ) {
+ Info_NextPair(&infostring, key, value);
+
+ if (!key[0]) {
break;
}
- if( value[0] ) {
- Com_Printf( "%-20s %s\n", key, value );
+ if (value[0]) {
+ Com_Printf("%-20s %s\n", key, value);
} else {
- Com_Printf( "%-20s <MISSING VALUE>\n", key );
+ Com_Printf("%-20s <MISSING VALUE>\n", key);
}
- } while( infostring );
+ } while (infostring);
- Com_Printf( "\nNum Score Ping Name\n" );
- for( i = 0, player = status->players; i < status->numPlayers; i++, player++ ) {
- Com_Printf( "%3i %5i %4i %s\n", i + 1, player->score, player->ping,
- player->name );
+ Com_Printf("\nNum Score Ping Name\n");
+ for (i = 0, player = status->players; i < status->numPlayers; i++, player++) {
+ Com_Printf("%3i %5i %4i %s\n", i + 1, player->score, player->ping,
+ player->name);
}
}
@@ -862,7 +886,8 @@ static void CL_DumpServerInfo( const serverStatus_t *status ) {
CL_ParsePrintMessage
====================
*/
-static void CL_ParsePrintMessage( void ) {
+static void CL_ParsePrintMessage(void)
+{
request_t *r;
serverStatus_t serverStatus;
char string[MAX_NET_STRING];
@@ -870,49 +895,49 @@ static void CL_ParsePrintMessage( void ) {
unsigned delta;
size_t len;
- len = MSG_ReadString( string, sizeof( string ) );
+ len = MSG_ReadString(string, sizeof(string));
oldest = currentRequest - MAX_REQUESTS;
- if( oldest < 0 ) {
+ if (oldest < 0) {
oldest = 0;
}
- for( i = currentRequest - 1; i >= oldest; i-- ) {
+ for (i = currentRequest - 1; i >= oldest; i--) {
r = &clientRequests[i & REQUEST_MASK];
- if( !r->type ) {
+ if (!r->type) {
continue;
}
delta = cls.realtime - r->time;
- if( r->adr.type == NA_BROADCAST ) {
- if( delta > 3000 ) {
+ if (r->adr.type == NA_BROADCAST) {
+ if (delta > 3000) {
continue;
}
} else {
- if( delta > 6000 ) {
+ if (delta > 6000) {
break;
}
- if( !NET_IsEqualBaseAdr( &net_from, &r->adr ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &r->adr)) {
continue;
}
}
- switch( r->type ) {
+ switch (r->type) {
case REQ_STATUS:
- if( !CL_ServerStatusResponse( string, len, &serverStatus ) ) {
+ if (!CL_ServerStatusResponse(string, len, &serverStatus)) {
continue;
}
- CL_DumpServerInfo( &serverStatus );
+ CL_DumpServerInfo(&serverStatus);
break;
- //case REQ_INFO:
- // break;
+ //case REQ_INFO:
+ // break;
#if USE_UI
case REQ_PING:
- if( !CL_ServerStatusResponse( string, len, &serverStatus ) ) {
+ if (!CL_ServerStatusResponse(string, len, &serverStatus)) {
continue;
}
- UI_AddToServerList( &serverStatus );
+ UI_AddToServerList(&serverStatus);
break;
#endif
case REQ_RCON:
- Com_Printf( "%s", string );
+ Com_Printf("%s", string);
return; // rcon may come in multiple packets
default:
break;
@@ -924,28 +949,27 @@ static void CL_ParsePrintMessage( void ) {
// finally, check is this is response from the server we are connecting to
// and if so, start channenge cycle again
- if ( ( cls.state == ca_challenging || cls.state == ca_connecting ) &&
- NET_IsEqualBaseAdr( &net_from, &cls.serverAddress ) )
- {
- Com_Printf( "%s", string );
+ if ((cls.state == ca_challenging || cls.state == ca_connecting) &&
+ NET_IsEqualBaseAdr(&net_from, &cls.serverAddress)) {
+ Com_Printf("%s", string);
cls.state = ca_challenging;
//cls.connect_count = 0;
return;
}
- Com_DPrintf( "%s: dropped unrequested packet\n", __func__ );
+ Com_DPrintf("%s: dropped unrequested packet\n", __func__);
}
/*
====================
CL_Packet_f
-
+
packet <destination> <contents>
-
+
Contents allows \n escape character
====================
-*/
+*/
/*
void CL_Packet_f (void)
{
@@ -953,13 +977,13 @@ void CL_Packet_f (void)
int i, l;
char *in, *out;
netadr_t adr;
-
+
if (Cmd_Argc() != 3)
{
Com_Printf ("packet <destination> <contents>\n");
return;
}
-
+
if (!NET_StringToAdr (Cmd_Argv(1), &adr))
{
Com_Printf ("Bad address\n");
@@ -967,13 +991,13 @@ void CL_Packet_f (void)
}
if (!adr.port)
adr.port = BigShort (PORT_SERVER);
-
+
in = Cmd_Argv(2);
out = send+4;
send[0] = send[1] = send[2] = send[3] = (char)0xff;
-
+
l = strlen (in);
- for (i=0 ; i<l ; i++)
+ for (i=0; i<l; i++)
{
if (in[i] == '\\' && in[i+1] == 'n')
{
@@ -984,7 +1008,7 @@ void CL_Packet_f (void)
*out++ = in[i];
}
*out = 0;
-
+
NET_SendPacket (NS_CLIENT, out-send, send, &adr);
}
*/
@@ -992,29 +1016,30 @@ void CL_Packet_f (void)
/*
=================
CL_Changing_f
-
+
Just sent as a hint to the client that they should
drop to full console
=================
*/
-static void CL_Changing_f( void ) {
+static void CL_Changing_f(void)
+{
int i, j;
char *s;
- if ( cls.state < ca_connected ) {
+ if (cls.state < ca_connected) {
return;
}
- if ( cls.demo.recording )
+ if (cls.demo.recording)
CL_Stop_f();
S_StopAllSounds();
- Com_Printf( "Changing map...\n" );
+ Com_Printf("Changing map...\n");
- if( !cls.demo.playback ) {
- EXEC_TRIGGER( cl_changemapcmd );
- Cmd_ExecTrigger( "#cl_changelevel" );
+ if (!cls.demo.playback) {
+ EXEC_TRIGGER(cl_changemapcmd);
+ Cmd_ExecTrigger("#cl_changelevel");
}
SCR_BeginLoadingPlaque();
@@ -1029,10 +1054,10 @@ static void CL_Changing_f( void ) {
// parse additional parameters
j = Cmd_Argc();
- for( i = 1; i < j; i++ ) {
- s = Cmd_Argv( i );
- if( !strncmp( s, "map=", 4 ) ) {
- Q_strlcpy( cl.mapname, s + 4, sizeof( cl.mapname ) );
+ for (i = 1; i < j; i++) {
+ s = Cmd_Argv(i);
+ if (!strncmp(s, "map=", 4)) {
+ Q_strlcpy(cl.mapname, s + 4, sizeof(cl.mapname));
}
}
@@ -1043,42 +1068,43 @@ static void CL_Changing_f( void ) {
/*
=================
CL_Reconnect_f
-
+
The server is changing levels
=================
*/
-static void CL_Reconnect_f( void ) {
- if( cls.state >= ca_precached ) {
- CL_Disconnect( ERR_RECONNECT );
+static void CL_Reconnect_f(void)
+{
+ if (cls.state >= ca_precached) {
+ CL_Disconnect(ERR_RECONNECT);
}
- if( cls.state >= ca_connected ) {
+ if (cls.state >= ca_connected) {
cls.state = ca_connected;
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
return;
}
- if( cls.download.file ) {
+ if (cls.download.file) {
return; // if we are downloading, we don't change!
}
- Com_Printf( "Reconnecting...\n" );
+ Com_Printf("Reconnecting...\n");
- CL_ClientCommand( "new" );
+ CL_ClientCommand("new");
return;
}
// issued manually at console
- if( cls.serverAddress.type == NA_BAD ) {
- Com_Printf( "No server to reconnect to.\n" );
+ if (cls.serverAddress.type == NA_BAD) {
+ Com_Printf("No server to reconnect to.\n");
return;
}
- if( cls.serverAddress.type == NA_LOOPBACK ) {
- Com_Printf( "Can not reconnect to loopback.\n" );
+ if (cls.serverAddress.type == NA_LOOPBACK) {
+ Com_Printf("Can not reconnect to loopback.\n");
return;
}
- Com_Printf( "Reconnecting...\n" );
+ Com_Printf("Reconnecting...\n");
cls.state = ca_challenging;
cls.connect_time -= CONNECT_FAST;
@@ -1091,11 +1117,11 @@ static void CL_Reconnect_f( void ) {
/*
=================
CL_ParseStatusMessage
-
+
Handle a reply from a ping
=================
*/
-void CL_ParseStatusMessage ( void ) {}
+void CL_ParseStatusMessage(void) {}
#endif
/*
@@ -1103,31 +1129,32 @@ void CL_ParseStatusMessage ( void ) {}
CL_SendStatusRequest
=================
*/
-qboolean CL_SendStatusRequest( char *buffer, size_t size ) {
+qboolean CL_SendStatusRequest(char *buffer, size_t size)
+{
netadr_t address;
- memset( &address, 0, sizeof( address ) );
+ memset(&address, 0, sizeof(address));
- NET_Config( NET_CLIENT );
+ NET_Config(NET_CLIENT);
- if( !buffer ) {
+ if (!buffer) {
// send a broadcast packet
address.type = NA_BROADCAST;
- address.port = BigShort( PORT_SERVER );
+ address.port = BigShort(PORT_SERVER);
} else {
- if ( !NET_StringToAdr( buffer, &address, PORT_SERVER ) ) {
+ if (!NET_StringToAdr(buffer, &address, PORT_SERVER)) {
return qfalse;
}
// return resolved address
- if( size > 0 ) {
- Q_strlcpy( buffer, NET_AdrToString( &address ), size );
+ if (size > 0) {
+ Q_strlcpy(buffer, NET_AdrToString(&address), size);
}
}
- CL_AddRequest( &address, REQ_PING );
+ CL_AddRequest(&address, REQ_PING);
- OOB_PRINT( NS_CLIENT, &address, "status" );
+ OOB_PRINT(NS_CLIENT, &address, "status");
// Com_ProcessEvents();
@@ -1140,46 +1167,47 @@ qboolean CL_SendStatusRequest( char *buffer, size_t size ) {
CL_PingServers_f
=================
*/
-static void CL_PingServers_f( void ) {
+static void CL_PingServers_f(void)
+{
int i;
char buffer[32];
cvar_t *var;
netadr_t address;
- memset( &address, 0, sizeof( address ) );
+ memset(&address, 0, sizeof(address));
- NET_Config( NET_CLIENT );
+ NET_Config(NET_CLIENT);
// send a broadcast packet
- Com_Printf( "pinging broadcast...\n" );
+ Com_Printf("pinging broadcast...\n");
address.type = NA_BROADCAST;
- address.port = BigShort( PORT_SERVER );
+ address.port = BigShort(PORT_SERVER);
- CL_AddRequest( &address, REQ_STATUS );
+ CL_AddRequest(&address, REQ_STATUS);
- OOB_PRINT( NS_CLIENT, &address, "status" );
+ OOB_PRINT(NS_CLIENT, &address, "status");
SCR_UpdateScreen();
// send a packet to each address book entry
- for( i = 0; i < 64; i++ ) {
- Q_snprintf( buffer, sizeof( buffer ), "adr%i", i );
- var = Cvar_FindVar( buffer );
- if( !var ) {
+ for (i = 0; i < 64; i++) {
+ Q_snprintf(buffer, sizeof(buffer), "adr%i", i);
+ var = Cvar_FindVar(buffer);
+ if (!var) {
break;
}
- if( !var->string[0] )
+ if (!var->string[0])
continue;
- if( !NET_StringToAdr( var->string, &address, PORT_SERVER ) ) {
- Com_Printf( "bad address: %s\n", var->string );
+ if (!NET_StringToAdr(var->string, &address, PORT_SERVER)) {
+ Com_Printf("bad address: %s\n", var->string);
continue;
}
- Com_Printf( "pinging %s...\n", var->string );
- CL_AddRequest( &address, REQ_STATUS );
+ Com_Printf("pinging %s...\n", var->string);
+ CL_AddRequest(&address, REQ_STATUS);
- OOB_PRINT( NS_CLIENT, &address, "status" );
+ OOB_PRINT(NS_CLIENT, &address, "status");
// Com_ProcessEvents();
SCR_UpdateScreen();
@@ -1189,79 +1217,83 @@ static void CL_PingServers_f( void ) {
/*
=================
CL_Skins_f
-
+
Load or download any custom player skins and models
=================
*/
-static void CL_Skins_f( void ) {
+static void CL_Skins_f(void)
+{
int i;
char *s;
clientinfo_t *ci;
- if( cls.state < ca_loading ) {
- Com_Printf( "Must be in a level to load skins.\n" );
+ if (cls.state < ca_loading) {
+ Com_Printf("Must be in a level to load skins.\n");
return;
}
CL_RegisterVWepModels();
- for( i = 0 ; i < MAX_CLIENTS; i++ ) {
- s = cl.configstrings[ CS_PLAYERSKINS + i ];
- if( !s[0] )
+ for (i = 0; i < MAX_CLIENTS; i++) {
+ s = cl.configstrings[CS_PLAYERSKINS + i];
+ if (!s[0])
continue;
ci = &cl.clientinfo[i];
- CL_LoadClientinfo( ci, s );
- if( !ci->model_name[0] || !ci->skin_name[0] )
+ CL_LoadClientinfo(ci, s);
+ if (!ci->model_name[0] || !ci->skin_name[0])
ci = &cl.baseclientinfo;
- Com_Printf( "client %d: %s --> %s/%s\n", i, s,
- ci->model_name, ci->skin_name );
+ Com_Printf("client %d: %s --> %s/%s\n", i, s,
+ ci->model_name, ci->skin_name);
SCR_UpdateScreen();
}
}
-static void cl_noskins_changed( cvar_t *self ) {
+static void cl_noskins_changed(cvar_t *self)
+{
int i;
char *s;
clientinfo_t *ci;
- if( cls.state < ca_loading ) {
+ if (cls.state < ca_loading) {
return;
}
- for( i = 0 ; i < MAX_CLIENTS; i++ ) {
- s = cl.configstrings[ CS_PLAYERSKINS + i ];
- if( !s[0] )
+ for (i = 0; i < MAX_CLIENTS; i++) {
+ s = cl.configstrings[CS_PLAYERSKINS + i];
+ if (!s[0])
continue;
ci = &cl.clientinfo[i];
- CL_LoadClientinfo( ci, s );
+ CL_LoadClientinfo(ci, s);
}
}
-static void cl_vwep_changed( cvar_t *self ) {
- if( cls.state < ca_loading ) {
+static void cl_vwep_changed(cvar_t *self)
+{
+ if (cls.state < ca_loading) {
return;
}
CL_RegisterVWepModels();
- cl_noskins_changed( self );
+ cl_noskins_changed(self);
}
-static void CL_Name_g( genctx_t *ctx ) {
+static void CL_Name_g(genctx_t *ctx)
+{
int i;
clientinfo_t *ci;
char buffer[MAX_CLIENT_NAME];
- if( cls.state < ca_loading ) {
+ if (cls.state < ca_loading) {
return;
}
- for( i = 0; i < MAX_CLIENTS; i++ ) {
+ for (i = 0; i < MAX_CLIENTS; i++) {
ci = &cl.clientinfo[i];
- if( !ci->name[0] ) {
+ if (!ci->name[0]) {
continue;
}
- Q_strlcpy( buffer, ci->name, sizeof( buffer ) );
- if( COM_strclr( buffer ) && !Prompt_AddMatch( ctx, buffer ) ) {
+ Q_strlcpy(buffer, ci->name, sizeof(buffer));
+ if (COM_strclr(buffer) && !Prompt_AddMatch(ctx, buffer)) {
break;
}
}
@@ -1271,11 +1303,12 @@ static void CL_Name_g( genctx_t *ctx ) {
/*
=================
CL_ConnectionlessPacket
-
+
Responses to broadcasts, etc
=================
*/
-static void CL_ConnectionlessPacket( void ) {
+static void CL_ConnectionlessPacket(void)
+{
char string[MAX_STRING_CHARS];
char *s, *c;
int i, j, k;
@@ -1284,55 +1317,55 @@ static void CL_ConnectionlessPacket( void ) {
MSG_BeginReading();
MSG_ReadLong(); // skip the -1
- len = MSG_ReadStringLine( string, sizeof( string ) );
- if( len >= sizeof( string ) ) {
- Com_DPrintf( "Oversize message received. Ignored.\n" );
+ len = MSG_ReadStringLine(string, sizeof(string));
+ if (len >= sizeof(string)) {
+ Com_DPrintf("Oversize message received. Ignored.\n");
return;
}
- Cmd_TokenizeString( string, qfalse );
+ Cmd_TokenizeString(string, qfalse);
- c = Cmd_Argv( 0 );
+ c = Cmd_Argv(0);
- Com_DPrintf( "%s: %s\n", NET_AdrToString ( &net_from ), string );
+ Com_DPrintf("%s: %s\n", NET_AdrToString(&net_from), string);
// challenge from the server we are connecting to
- if ( !strcmp( c, "challenge" ) ) {
+ if (!strcmp(c, "challenge")) {
int mask = 0;
- if ( cls.state < ca_challenging ) {
- Com_DPrintf( "Challenge received while not connecting. Ignored.\n" );
+ if (cls.state < ca_challenging) {
+ Com_DPrintf("Challenge received while not connecting. Ignored.\n");
return;
}
- if ( !NET_IsEqualBaseAdr( &net_from, &cls.serverAddress ) ) {
- Com_DPrintf( "Challenge from different address. Ignored.\n" );
+ if (!NET_IsEqualBaseAdr(&net_from, &cls.serverAddress)) {
+ Com_DPrintf("Challenge from different address. Ignored.\n");
return;
}
- if ( cls.state > ca_challenging ) {
- Com_DPrintf( "Dup challenge received. Ignored.\n" );
+ if (cls.state > ca_challenging) {
+ Com_DPrintf("Dup challenge received. Ignored.\n");
return;
}
- cls.challenge = atoi( Cmd_Argv( 1 ) );
+ cls.challenge = atoi(Cmd_Argv(1));
cls.state = ca_connecting;
cls.connect_time -= CONNECT_INSTANT; // fire immediately
//cls.connect_count = 0;
// parse additional parameters
j = Cmd_Argc();
- for( i = 2; i < j; i++ ) {
- s = Cmd_Argv( i );
- if( !strncmp( s, "p=", 2 ) ) {
+ for (i = 2; i < j; i++) {
+ s = Cmd_Argv(i);
+ if (!strncmp(s, "p=", 2)) {
s += 2;
- while( *s ) {
- k = strtoul( s, &s, 10 );
- if( k == PROTOCOL_VERSION_R1Q2 ) {
+ while (*s) {
+ k = strtoul(s, &s, 10);
+ if (k == PROTOCOL_VERSION_R1Q2) {
mask |= 1;
- } else if( k == PROTOCOL_VERSION_Q2PRO ) {
+ } else if (k == PROTOCOL_VERSION_Q2PRO) {
mask |= 2;
}
- s = strchr( s, ',' );
- if( s == NULL ) {
+ s = strchr(s, ',');
+ if (s == NULL) {
break;
}
s++;
@@ -1341,46 +1374,46 @@ static void CL_ConnectionlessPacket( void ) {
}
// choose supported protocol
- switch( cls.serverProtocol ) {
+ switch (cls.serverProtocol) {
case PROTOCOL_VERSION_Q2PRO:
- if( mask & 2 ) {
+ if (mask & 2) {
break;
}
cls.serverProtocol = PROTOCOL_VERSION_R1Q2;
case PROTOCOL_VERSION_R1Q2:
- if( mask & 1 ) {
+ if (mask & 1) {
break;
}
default:
cls.serverProtocol = PROTOCOL_VERSION_DEFAULT;
break;
}
- Com_DPrintf( "Selected protocol %d\n", cls.serverProtocol );
+ Com_DPrintf("Selected protocol %d\n", cls.serverProtocol);
CL_CheckForResend();
return;
}
// server connection
- if ( !strcmp( c, "client_connect" ) ) {
+ if (!strcmp(c, "client_connect")) {
netchan_type_t type;
int anticheat = 0;
char mapname[MAX_QPATH];
- if ( cls.state < ca_connecting ) {
- Com_DPrintf( "Connect received while not connecting. Ignored.\n" );
+ if (cls.state < ca_connecting) {
+ Com_DPrintf("Connect received while not connecting. Ignored.\n");
return;
}
- if ( !NET_IsEqualBaseAdr( &net_from, &cls.serverAddress ) ) {
- Com_DPrintf( "Connect from different address. Ignored.\n" );
+ if (!NET_IsEqualBaseAdr(&net_from, &cls.serverAddress)) {
+ Com_DPrintf("Connect from different address. Ignored.\n");
return;
}
- if ( cls.state > ca_connecting ) {
- Com_DPrintf( "Dup connect received. Ignored.\n" );
+ if (cls.state > ca_connecting) {
+ Com_DPrintf("Dup connect received. Ignored.\n");
return;
}
- if ( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO) {
type = NETCHAN_NEW;
} else {
type = NETCHAN_OLD;
@@ -1390,89 +1423,89 @@ static void CL_ConnectionlessPacket( void ) {
// parse additional parameters
j = Cmd_Argc();
- for( i = 1; i < j; i++ ) {
- s = Cmd_Argv( i );
- if( !strncmp( s, "ac=", 3 ) ) {
+ for (i = 1; i < j; i++) {
+ s = Cmd_Argv(i);
+ if (!strncmp(s, "ac=", 3)) {
s += 3;
- if( *s ) {
- anticheat = atoi( s );
+ if (*s) {
+ anticheat = atoi(s);
}
- } else if( !strncmp( s, "nc=", 3 ) ) {
+ } else if (!strncmp(s, "nc=", 3)) {
s += 3;
- if( *s ) {
- type = atoi( s );
- if( type != NETCHAN_OLD && type != NETCHAN_NEW ) {
- Com_Error( ERR_DISCONNECT,
- "Server returned invalid netchan type" );
+ if (*s) {
+ type = atoi(s);
+ if (type != NETCHAN_OLD && type != NETCHAN_NEW) {
+ Com_Error(ERR_DISCONNECT,
+ "Server returned invalid netchan type");
}
}
- } else if( !strncmp( s, "map=", 4 ) ) {
- Q_strlcpy( mapname, s + 4, sizeof( mapname ) );
+ } else if (!strncmp(s, "map=", 4)) {
+ Q_strlcpy(mapname, s + 4, sizeof(mapname));
}
#if USE_CURL
- else if( !strncmp( s, "dlserver=", 9 ) ) {
- HTTP_SetServer( s + 9 );
+ else if (!strncmp(s, "dlserver=", 9)) {
+ HTTP_SetServer(s + 9);
}
#endif
}
- Com_Printf( "Connected to %s (protocol %d).\n",
- NET_AdrToString( &cls.serverAddress ), cls.serverProtocol );
- if( cls.netchan ) {
+ Com_Printf("Connected to %s (protocol %d).\n",
+ NET_AdrToString(&cls.serverAddress), cls.serverProtocol);
+ if (cls.netchan) {
// this may happen after svc_reconnect
- Netchan_Close( cls.netchan );
+ Netchan_Close(cls.netchan);
}
- cls.netchan = Netchan_Setup( NS_CLIENT, type, &cls.serverAddress,
- cls.quakePort, 1024, cls.serverProtocol );
+ cls.netchan = Netchan_Setup(NS_CLIENT, type, &cls.serverAddress,
+ cls.quakePort, 1024, cls.serverProtocol);
#if USE_AC_CLIENT
- if( anticheat ) {
- MSG_WriteByte( clc_nop );
- MSG_FlushTo( &cls.netchan->message );
- cls.netchan->Transmit( cls.netchan, 0, NULL, 3 );
+ if (anticheat) {
+ MSG_WriteByte(clc_nop);
+ MSG_FlushTo(&cls.netchan->message);
+ cls.netchan->Transmit(cls.netchan, 0, NULL, 3);
S_StopAllSounds();
cls.connect_count = -1;
- Com_Printf( "Loading anticheat, this may take a few moments...\n" );
+ Com_Printf("Loading anticheat, this may take a few moments...\n");
SCR_UpdateScreen();
- if( !Sys_GetAntiCheatAPI() ) {
- Com_Printf( "Trying to connect without anticheat.\n" );
+ if (!Sys_GetAntiCheatAPI()) {
+ Com_Printf("Trying to connect without anticheat.\n");
} else {
- Com_LPrintf( PRINT_NOTICE, "Anticheat loaded successfully.\n" );
+ Com_LPrintf(PRINT_NOTICE, "Anticheat loaded successfully.\n");
}
}
#else
- if( anticheat >= 2 ) {
- Com_Printf( "Anticheat required by server, "
- "but no anticheat support linked in.\n" );
+ if (anticheat >= 2) {
+ Com_Printf("Anticheat required by server, "
+ "but no anticheat support linked in.\n");
}
#endif
- CL_ClientCommand( "new" );
+ CL_ClientCommand("new");
cls.state = ca_connected;
cls.connect_count = 0;
- strcpy( cl.mapname, mapname ); // for levelshot screen
+ strcpy(cl.mapname, mapname); // for levelshot screen
return;
}
#if 0
// server responding to a status broadcast
- if ( !strcmp( c, "info" ) ) {
+ if (!strcmp(c, "info")) {
CL_ParseStatusMessage();
return;
}
#endif
- if ( !strcmp( c, "passive_connect" ) ) {
- if( !cls.passive ) {
- Com_DPrintf( "Passive connect received while not connecting. Ignored.\n" );
+ if (!strcmp(c, "passive_connect")) {
+ if (!cls.passive) {
+ Com_DPrintf("Passive connect received while not connecting. Ignored.\n");
return;
}
- s = NET_AdrToString( &net_from );
- Com_Printf( "Received passive connect from %s.\n", s );
+ s = NET_AdrToString(&net_from);
+ Com_Printf("Received passive connect from %s.\n", s);
cls.serverAddress = net_from;
cls.serverProtocol = cl_protocol->integer;
- Q_strlcpy( cls.servername, s, sizeof( cls.servername ) );
+ Q_strlcpy(cls.servername, s, sizeof(cls.servername));
cls.passive = qfalse;
cls.state = ca_challenging;
@@ -1484,12 +1517,12 @@ static void CL_ConnectionlessPacket( void ) {
}
// print command from somewhere
- if ( !strcmp( c, "print" ) ) {
+ if (!strcmp(c, "print")) {
CL_ParsePrintMessage();
return;
}
- Com_DPrintf( "Unknown connectionless packet command.\n" );
+ Com_DPrintf("Unknown connectionless packet command.\n");
}
@@ -1498,38 +1531,39 @@ static void CL_ConnectionlessPacket( void ) {
CL_PacketEvent
=================
*/
-static void CL_PacketEvent( void ) {
+static void CL_PacketEvent(void)
+{
//
// remote command packet
//
- if( *( int * )msg_read.data == -1 ) {
+ if (*(int *)msg_read.data == -1) {
CL_ConnectionlessPacket();
return;
}
- if( cls.state < ca_connected ) {
+ if (cls.state < ca_connected) {
return;
}
- if( !cls.netchan ) {
+ if (!cls.netchan) {
return; // dump it if not connected
}
- if( msg_read.cursize < 8 ) {
- Com_DPrintf( "%s: runt packet\n", NET_AdrToString( &net_from ) );
+ if (msg_read.cursize < 8) {
+ Com_DPrintf("%s: runt packet\n", NET_AdrToString(&net_from));
return;
}
//
// packet from server
//
- if( !NET_IsEqualAdr( &net_from, &cls.netchan->remote_address ) ) {
- Com_DPrintf( "%s: sequenced packet without connection\n",
- NET_AdrToString( &net_from ) );
+ if (!NET_IsEqualAdr(&net_from, &cls.netchan->remote_address)) {
+ Com_DPrintf("%s: sequenced packet without connection\n",
+ NET_AdrToString(&net_from));
return;
}
- if( !cls.netchan->Process( cls.netchan ) )
+ if (!cls.netchan->Process(cls.netchan))
return; // wasn't accepted for some reason
#if USE_ICMP
@@ -1538,7 +1572,7 @@ static void CL_PacketEvent( void ) {
CL_ParseServerMessage();
- if( !cls.netchan )
+ if (!cls.netchan)
return; // might have disconnected
#ifdef _DEBUG
@@ -1549,20 +1583,21 @@ static void CL_PacketEvent( void ) {
}
#if USE_ICMP
-void CL_ErrorEvent( void ) {
+void CL_ErrorEvent(void)
+{
//
// error packet from server
//
- if( cls.state < ca_connected ) {
+ if (cls.state < ca_connected) {
return;
}
- if( !cls.netchan ) {
+ if (!cls.netchan) {
return; // dump it if not connected
}
- if( !NET_IsEqualBaseAdr( &net_from, &cls.netchan->remote_address ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &cls.netchan->remote_address)) {
return;
}
- if( net_from.port && net_from.port != cls.netchan->remote_address.port ) {
+ if (net_from.port && net_from.port != cls.netchan->remote_address.port) {
return;
}
@@ -1578,58 +1613,60 @@ void CL_ErrorEvent( void ) {
CL_FixUpGender_f
==============
*/
-static void CL_FixUpGender( void ) {
+static void CL_FixUpGender(void)
+{
char *p;
char sk[MAX_QPATH];
- Q_strlcpy( sk, info_skin->string, sizeof( sk ) );
- if ( ( p = strchr( sk, '/' ) ) != NULL )
+ Q_strlcpy(sk, info_skin->string, sizeof(sk));
+ if ((p = strchr(sk, '/')) != NULL)
*p = 0;
- if ( Q_stricmp( sk, "male" ) == 0 || Q_stricmp( sk, "cyborg" ) == 0 )
- Cvar_Set ( "gender", "male" );
- else if ( Q_stricmp( sk, "female" ) == 0 || Q_stricmp( sk, "crackhor" ) == 0 )
- Cvar_Set ( "gender", "female" );
+ if (Q_stricmp(sk, "male") == 0 || Q_stricmp(sk, "cyborg") == 0)
+ Cvar_Set("gender", "male");
+ else if (Q_stricmp(sk, "female") == 0 || Q_stricmp(sk, "crackhor") == 0)
+ Cvar_Set("gender", "female");
else
- Cvar_Set ( "gender", "none" );
+ Cvar_Set("gender", "none");
info_gender->modified = qfalse;
}
-void CL_UpdateUserinfo( cvar_t *var, from_t from ) {
+void CL_UpdateUserinfo(cvar_t *var, from_t from)
+{
int i;
- if( var == info_skin && from > FROM_CONSOLE && gender_auto->integer ) {
- CL_FixUpGender();
+ if (var == info_skin && from > FROM_CONSOLE && gender_auto->integer) {
+ CL_FixUpGender();
}
- if( !cls.netchan ) {
+ if (!cls.netchan) {
return;
}
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
// transmit at next oportunity
- cls.userinfo_modified = MAX_PACKET_USERINFOS;
+ cls.userinfo_modified = MAX_PACKET_USERINFOS;
goto done;
}
- if( cls.userinfo_modified == MAX_PACKET_USERINFOS ) {
+ if (cls.userinfo_modified == MAX_PACKET_USERINFOS) {
// can't hold any more
goto done;
}
// check for the same variable being modified twice
- for( i = 0; i < cls.userinfo_modified; i++ ) {
- if( cls.userinfo_updates[i] == var ) {
- Com_DDPrintf( "%s: %u: %s [DUP]\n",
- __func__, com_framenum, var->name );
+ for (i = 0; i < cls.userinfo_modified; i++) {
+ if (cls.userinfo_updates[i] == var) {
+ Com_DDPrintf("%s: %u: %s [DUP]\n",
+ __func__, com_framenum, var->name);
return;
}
}
- cls.userinfo_updates[cls.userinfo_modified++] = var;
+ cls.userinfo_updates[cls.userinfo_modified++] = var;
done:
- Com_DDPrintf( "%s: %u: %s [%d]\n",
- __func__, com_framenum, var->name, cls.userinfo_modified );
+ Com_DDPrintf("%s: %u: %s [%d]\n",
+ __func__, com_framenum, var->name, cls.userinfo_modified);
}
/*
@@ -1637,24 +1674,26 @@ done:
CL_Userinfo_f
==============
*/
-static void CL_Userinfo_f ( void ) {
+static void CL_Userinfo_f(void)
+{
char userinfo[MAX_INFO_STRING];
- Cvar_BitInfo( userinfo, CVAR_USERINFO );
+ Cvar_BitInfo(userinfo, CVAR_USERINFO);
- Com_Printf( "User info settings:\n" );
- Info_Print( userinfo );
+ Com_Printf("User info settings:\n");
+ Info_Print(userinfo);
}
/*
=================
CL_RestartSound_f
-
+
Restart the sound subsystem so it can pick up
new parameters and flush all sounds
=================
*/
-static void CL_RestartSound_f( void ) {
+static void CL_RestartSound_f(void)
+{
S_Shutdown();
S_Init();
CL_RegisterSounds();
@@ -1667,23 +1706,25 @@ CL_PlaySound_f
Moved here from sound code so that command is always registered.
=================
*/
-static void CL_PlaySound_c( genctx_t *ctx, int state ) {
- FS_File_g( "sound", "*.wav", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER | FS_SEARCH_STRIPEXT, ctx );
+static void CL_PlaySound_c(genctx_t *ctx, int state)
+{
+ FS_File_g("sound", "*.wav", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER | FS_SEARCH_STRIPEXT, ctx);
}
-static void CL_PlaySound_f( void ) {
+static void CL_PlaySound_f(void)
+{
int i;
char name[MAX_QPATH];
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <sound> [...]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <sound> [...]\n", Cmd_Argv(0));
return;
}
- for( i = 1; i < Cmd_Argc(); i++ ) {
- Cmd_ArgvBuffer( i, name, sizeof( name ) );
- COM_DefaultExtension( name, ".wav", sizeof( name ) );
- S_StartLocalSound( name );
+ for (i = 1; i < Cmd_Argc(); i++) {
+ Cmd_ArgvBuffer(i, name, sizeof(name));
+ COM_DefaultExtension(name, ".wav", sizeof(name));
+ S_StartLocalSound(name);
}
}
@@ -1696,9 +1737,10 @@ CL_Begin
Called after all downloads are done. Not used for demos.
=================
*/
-void CL_Begin( void ) {
+void CL_Begin(void)
+{
#if USE_REF == REF_GL
- if( !Q_stricmp( cl.gamedir, "gloom" ) ) {
+ if (!Q_stricmp(cl.gamedir, "gloom")) {
// cheat protect our custom modulate cvars
gl_modulate_world->flags |= CVAR_CHEAT;
gl_modulate_entities->flags |= CVAR_CHEAT;
@@ -1708,18 +1750,18 @@ void CL_Begin( void ) {
Cvar_FixCheats();
- CL_PrepRefresh ();
- CL_LoadState( LOAD_SOUNDS );
- CL_RegisterSounds ();
+ CL_PrepRefresh();
+ CL_LoadState(LOAD_SOUNDS);
+ CL_RegisterSounds();
LOC_LoadLocations();
- CL_LoadState( LOAD_FINISH );
+ CL_LoadState(LOAD_FINISH);
cls.state = ca_precached;
#if USE_FPS
CL_UpdateRateSetting();
#endif
- CL_ClientCommand( va( "begin %i\n", precache_spawncount ) );
+ CL_ClientCommand(va("begin %i\n", precache_spawncount));
CL_UpdateGunSetting();
CL_UpdateBlendSetting();
@@ -1731,40 +1773,41 @@ void CL_Begin( void ) {
/*
=================
CL_Precache_f
-
+
The server will send this command right
before allowing the client into the server
=================
*/
-static void CL_Precache_f( void ) {
- if( cls.state < ca_connected ) {
+static void CL_Precache_f(void)
+{
+ if (cls.state < ca_connected) {
return;
}
cls.state = ca_loading;
- CL_LoadState( LOAD_MAP );
+ CL_LoadState(LOAD_MAP);
S_StopAllSounds();
CL_RegisterVWepModels();
// demos use different precache sequence
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
CL_RegisterBspModels();
CL_PrepRefresh();
- CL_LoadState( LOAD_SOUNDS );
+ CL_LoadState(LOAD_SOUNDS);
CL_RegisterSounds();
- CL_LoadState( LOAD_FINISH );
+ CL_LoadState(LOAD_FINISH);
cls.state = ca_precached;
return;
}
- precache_spawncount = atoi( Cmd_Argv( 1 ) );
+ precache_spawncount = atoi(Cmd_Argv(1));
CL_ResetPrecacheCheck();
CL_RequestNextDownload();
- if( cls.state != ca_precached ) {
+ if (cls.state != ca_precached) {
cls.state = ca_connected;
}
}
@@ -1777,11 +1820,12 @@ typedef struct {
static list_t cl_ignores;
-static ignore_t *find_ignore( const char *match ) {
+static ignore_t *find_ignore(const char *match)
+{
ignore_t *ignore;
- LIST_FOR_EACH( ignore_t, ignore, &cl_ignores, entry ) {
- if( !strcmp( ignore->match, match ) ) {
+ LIST_FOR_EACH(ignore_t, ignore, &cl_ignores, entry) {
+ if (!strcmp(ignore->match, match)) {
return ignore;
}
}
@@ -1789,130 +1833,138 @@ static ignore_t *find_ignore( const char *match ) {
return NULL;
}
-static void list_ignores( void ) {
+static void list_ignores(void)
+{
ignore_t *ignore;
- if( LIST_EMPTY( &cl_ignores ) ) {
- Com_Printf( "No ignore filters.\n" );
+ if (LIST_EMPTY(&cl_ignores)) {
+ Com_Printf("No ignore filters.\n");
return;
}
- Com_Printf( "Current ignore filters:\n" );
- LIST_FOR_EACH( ignore_t, ignore, &cl_ignores, entry ) {
- Com_Printf( "\"%s\" (%u hit%s)\n", ignore->match,
- ignore->hits, ignore->hits == 1 ? "" : "s" );
+ Com_Printf("Current ignore filters:\n");
+ LIST_FOR_EACH(ignore_t, ignore, &cl_ignores, entry) {
+ Com_Printf("\"%s\" (%u hit%s)\n", ignore->match,
+ ignore->hits, ignore->hits == 1 ? "" : "s");
}
}
-static void add_ignore( const char *match ) {
+static void add_ignore(const char *match)
+{
ignore_t *ignore;
size_t matchlen;
// don't create the same ignore twice
- if( find_ignore( match ) ) {
+ if (find_ignore(match)) {
return;
}
- matchlen = strlen( match );
- if( matchlen < 3 ) {
- Com_Printf( "Match string \"%s\" is too short.\n", match );
+ matchlen = strlen(match);
+ if (matchlen < 3) {
+ Com_Printf("Match string \"%s\" is too short.\n", match);
return;
}
- ignore = Z_Malloc( sizeof( *ignore ) + matchlen );
+ ignore = Z_Malloc(sizeof(*ignore) + matchlen);
ignore->hits = 0;
- memcpy( ignore->match, match, matchlen + 1 );
- List_Append( &cl_ignores, &ignore->entry );
+ memcpy(ignore->match, match, matchlen + 1);
+ List_Append(&cl_ignores, &ignore->entry);
}
-static void remove_ignore( const char *match ) {
+static void remove_ignore(const char *match)
+{
ignore_t *ignore;
- ignore = find_ignore( match );
- if( !ignore ) {
- Com_Printf( "Can't find ignore filter \"%s\"\n", match );
+ ignore = find_ignore(match);
+ if (!ignore) {
+ Com_Printf("Can't find ignore filter \"%s\"\n", match);
return;
}
- List_Remove( &ignore->entry );
- Z_Free( ignore );
+ List_Remove(&ignore->entry);
+ Z_Free(ignore);
}
-static void remove_all_ignores( void ) {
+static void remove_all_ignores(void)
+{
ignore_t *ignore, *next;
int count = 0;
- LIST_FOR_EACH_SAFE( ignore_t, ignore, next, &cl_ignores, entry ) {
- Z_Free( ignore );
+ LIST_FOR_EACH_SAFE(ignore_t, ignore, next, &cl_ignores, entry) {
+ Z_Free(ignore);
count++;
}
- Com_Printf( "Removed %d ignore filter%s.\n", count, count == 1 ? "" : "s" );
- List_Init( &cl_ignores );
+ Com_Printf("Removed %d ignore filter%s.\n", count, count == 1 ? "" : "s");
+ List_Init(&cl_ignores);
}
-static void CL_IgnoreText_f( void ) {
- if( Cmd_Argc() == 1 ) {
+static void CL_IgnoreText_f(void)
+{
+ if (Cmd_Argc() == 1) {
list_ignores();
return;
}
- add_ignore( Cmd_ArgsFrom( 1 ) );
+ add_ignore(Cmd_ArgsFrom(1));
}
-static void CL_UnIgnoreText_f( void ) {
- if( Cmd_Argc() == 1 ) {
+static void CL_UnIgnoreText_f(void)
+{
+ if (Cmd_Argc() == 1) {
list_ignores();
return;
}
- if( LIST_EMPTY( &cl_ignores ) ) {
- Com_Printf( "No ignore filters.\n" );
+ if (LIST_EMPTY(&cl_ignores)) {
+ Com_Printf("No ignore filters.\n");
return;
}
- if( !strcmp( Cmd_Argv( 1 ), "all" ) ) {
+ if (!strcmp(Cmd_Argv(1), "all")) {
remove_all_ignores();
return;
}
- remove_ignore( Cmd_ArgsFrom( 1 ) );
+ remove_ignore(Cmd_ArgsFrom(1));
}
-static void CL_IgnoreNick_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- CL_Name_g( ctx );
+static void CL_IgnoreNick_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ CL_Name_g(ctx);
}
}
// properly escapes any special characters in nickname
-static size_t parse_ignore_nick( int argnum, char *buffer ) {
+static size_t parse_ignore_nick(int argnum, char *buffer)
+{
char temp[MAX_CLIENT_NAME];
char *p, *s;
int c;
size_t len;
- Cmd_ArgvBuffer( argnum, temp, sizeof( temp ) );
+ Cmd_ArgvBuffer(argnum, temp, sizeof(temp));
s = temp;
p = buffer;
len = 0;
- while( *s ) {
+ while (*s) {
c = *s++;
c &= 127;
- if( c == '?' ) {
+ if (c == '?') {
*p++ = '\\';
*p++ = '?';
len += 2;
- } else if( c == '*' ) {
+ } else if (c == '*') {
*p++ = '\\';
*p++ = '*';
len += 2;
- } else if( c == '\\' ) {
+ } else if (c == '\\') {
*p++ = '\\';
*p++ = '\\';
len += 2;
- } else if( Q_isprint( c ) ) {
+ } else if (Q_isprint(c)) {
*p++ = c;
len++;
}
@@ -1923,44 +1975,46 @@ static size_t parse_ignore_nick( int argnum, char *buffer ) {
return len;
}
-static void CL_IgnoreNick_f( void ) {
- char nick[MAX_CLIENT_NAME*2];
- char match[MAX_CLIENT_NAME*3];
+static void CL_IgnoreNick_f(void)
+{
+ char nick[MAX_CLIENT_NAME * 2];
+ char match[MAX_CLIENT_NAME * 3];
- if( Cmd_Argc() == 1 ) {
+ if (Cmd_Argc() == 1) {
list_ignores();
return;
}
- if( !parse_ignore_nick( 1, nick ) ) {
+ if (!parse_ignore_nick(1, nick)) {
return;
}
- Q_snprintf( match, sizeof( match ), "%s: *", nick );
- add_ignore( match );
+ Q_snprintf(match, sizeof(match), "%s: *", nick);
+ add_ignore(match);
- Q_snprintf( match, sizeof( match ), "(%s): *", nick );
- add_ignore( match );
+ Q_snprintf(match, sizeof(match), "(%s): *", nick);
+ add_ignore(match);
}
-static void CL_UnIgnoreNick_f( void ) {
- char nick[MAX_CLIENT_NAME*2];
- char match[MAX_CLIENT_NAME*3];
+static void CL_UnIgnoreNick_f(void)
+{
+ char nick[MAX_CLIENT_NAME * 2];
+ char match[MAX_CLIENT_NAME * 3];
- if( Cmd_Argc() == 1 ) {
+ if (Cmd_Argc() == 1) {
list_ignores();
return;
}
- if( !parse_ignore_nick( 1, nick ) ) {
+ if (!parse_ignore_nick(1, nick)) {
return;
}
- Q_snprintf( match, sizeof( match ), "%s: *", nick );
- remove_ignore( match );
+ Q_snprintf(match, sizeof(match), "%s: *", nick);
+ remove_ignore(match);
- Q_snprintf( match, sizeof( match ), "(%s): *", nick );
- remove_ignore( match );
+ Q_snprintf(match, sizeof(match), "(%s): *", nick);
+ remove_ignore(match);
}
/*
@@ -1968,19 +2022,20 @@ static void CL_UnIgnoreNick_f( void ) {
CL_CheckForIgnore
=================
*/
-qboolean CL_CheckForIgnore( const char *s ) {
+qboolean CL_CheckForIgnore(const char *s)
+{
char buffer[MAX_STRING_CHARS];
ignore_t *ignore;
- if( LIST_EMPTY( &cl_ignores ) ) {
+ if (LIST_EMPTY(&cl_ignores)) {
return qfalse;
}
- Q_strlcpy( buffer, s, sizeof( buffer ) );
- COM_strclr( buffer );
+ Q_strlcpy(buffer, s, sizeof(buffer));
+ COM_strclr(buffer);
- LIST_FOR_EACH( ignore_t, ignore, &cl_ignores, entry ) {
- if( Com_WildCmp( ignore->match, buffer ) ) {
+ LIST_FOR_EACH(ignore_t, ignore, &cl_ignores, entry) {
+ if (Com_WildCmp(ignore->match, buffer)) {
ignore->hits++;
return qtrue;
}
@@ -1989,54 +2044,57 @@ qboolean CL_CheckForIgnore( const char *s ) {
return qfalse;
}
-static void CL_DumpClients_f( void ) {
+static void CL_DumpClients_f(void)
+{
int i;
- if ( cls.state != ca_active ) {
- Com_Printf( "Must be in a level to dump.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("Must be in a level to dump.\n");
return;
}
- for ( i = 0 ; i < MAX_CLIENTS ; i++ ) {
- if ( !cl.clientinfo[ i ].name[ 0 ] ) {
+ for (i = 0; i < MAX_CLIENTS; i++) {
+ if (!cl.clientinfo[i].name[0]) {
continue;
}
- Com_Printf( "%3i: %s\n", i, cl.clientinfo[ i ].name );
+ Com_Printf("%3i: %s\n", i, cl.clientinfo[i].name);
}
}
-static void dump_program( const char *text, const char *name ) {
+static void dump_program(const char *text, const char *name)
+{
char buffer[MAX_OSPATH];
- if( cls.state != ca_active ) {
- Com_Printf( "Must be in a level to dump.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("Must be in a level to dump.\n");
return;
}
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- if( !*text ) {
- Com_Printf( "No %s to dump.\n", name );
+ if (!*text) {
+ Com_Printf("No %s to dump.\n", name);
return;
}
- if( FS_EasyWriteFile( buffer, sizeof( buffer ), FS_MODE_WRITE | FS_FLAG_TEXT,
- "layouts/", Cmd_Argv( 1 ), ".txt", text, strlen( text ) ) )
- {
- Com_Printf( "Dumped %s program to %s.\n", name, buffer );
+ if (FS_EasyWriteFile(buffer, sizeof(buffer), FS_MODE_WRITE | FS_FLAG_TEXT,
+ "layouts/", Cmd_Argv(1), ".txt", text, strlen(text))) {
+ Com_Printf("Dumped %s program to %s.\n", name, buffer);
}
}
-static void CL_DumpStatusbar_f( void ) {
- dump_program( cl.configstrings[CS_STATUSBAR], "status bar" );
+static void CL_DumpStatusbar_f(void)
+{
+ dump_program(cl.configstrings[CS_STATUSBAR], "status bar");
}
-static void CL_DumpLayout_f( void ) {
- dump_program( cl.layout, "layout" );
+static void CL_DumpLayout_f(void)
+{
+ dump_program(cl.layout, "layout");
}
static const cmd_option_t o_writeconfig[] = {
@@ -2048,8 +2106,9 @@ static const cmd_option_t o_writeconfig[] = {
{ NULL }
};
-static void CL_WriteConfig_c( genctx_t *ctx, int argnum ) {
- Cmd_Option_c( o_writeconfig, Cmd_Config_g, ctx, argnum );
+static void CL_WriteConfig_c(genctx_t *ctx, int argnum)
+{
+ Cmd_Option_c(o_writeconfig, Cmd_Config_g, ctx, argnum);
}
/*
@@ -2057,14 +2116,15 @@ static void CL_WriteConfig_c( genctx_t *ctx, int argnum ) {
CL_WriteConfig_f
===============
*/
-static void CL_WriteConfig_f( void ) {
+static void CL_WriteConfig_f(void)
+{
char buffer[MAX_OSPATH];
qboolean aliases = qfalse, bindings = qfalse, modified = qfalse;
int c, mask = 0;
qhandle_t f;
- while( ( c = Cmd_ParseOptions( o_writeconfig ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_writeconfig)) != -1) {
+ switch (c) {
case 'a':
aliases = qtrue;
break;
@@ -2075,9 +2135,9 @@ static void CL_WriteConfig_f( void ) {
mask |= CVAR_ARCHIVE;
break;
case 'h':
- Cmd_PrintUsage( o_writeconfig, "<filename>" );
- Com_Printf( "Save current configuration into file.\n" );
- Cmd_PrintHelp( o_writeconfig );
+ Cmd_PrintUsage(o_writeconfig, "<filename>");
+ Com_Printf("Save current configuration into file.\n");
+ Cmd_PrintHelp(o_writeconfig);
return;
case 'm':
modified = qtrue;
@@ -2088,164 +2148,187 @@ static void CL_WriteConfig_f( void ) {
}
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
- if( !aliases && !bindings && !mask ) {
+ if (!aliases && !bindings && !mask) {
bindings = qtrue;
mask = CVAR_ARCHIVE;
}
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), FS_MODE_WRITE | FS_FLAG_TEXT,
- "configs/", cmd_optarg, ".cfg" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), FS_MODE_WRITE | FS_FLAG_TEXT,
+ "configs/", cmd_optarg, ".cfg");
+ if (!f) {
return;
}
- FS_FPrintf( f, "// generated by q2pro\n" );
+ FS_FPrintf(f, "// generated by q2pro\n");
- if( bindings ) {
- FS_FPrintf( f, "\n// key bindings\n" );
- Key_WriteBindings( f );
+ if (bindings) {
+ FS_FPrintf(f, "\n// key bindings\n");
+ Key_WriteBindings(f);
}
- if( aliases ) {
- FS_FPrintf( f, "\n// command aliases\n" );
- Cmd_WriteAliases( f );
+ if (aliases) {
+ FS_FPrintf(f, "\n// command aliases\n");
+ Cmd_WriteAliases(f);
}
- if( mask ) {
- FS_FPrintf( f, "\n//%s cvars\n", modified ? "modified" : "archived" );
- Cvar_WriteVariables( f, mask, modified );
+ if (mask) {
+ FS_FPrintf(f, "\n//%s cvars\n", modified ? "modified" : "archived");
+ Cvar_WriteVariables(f, mask, modified);
}
-
- FS_FCloseFile( f );
- Com_Printf( "Wrote %s.\n", buffer );
+ FS_FCloseFile(f);
+
+ Com_Printf("Wrote %s.\n", buffer);
}
-static void CL_Say_c( genctx_t *ctx, int argnum ) {
- CL_Name_g( ctx );
+static void CL_Say_c(genctx_t *ctx, int argnum)
+{
+ CL_Name_g(ctx);
}
-static size_t CL_Mapname_m( char *buffer, size_t size ) {
- return Q_strlcpy( buffer, cl.mapname, size );
+static size_t CL_Mapname_m(char *buffer, size_t size)
+{
+ return Q_strlcpy(buffer, cl.mapname, size);
}
-static size_t CL_Server_m( char *buffer, size_t size ) {
- return Q_strlcpy( buffer, cls.servername, size );
+static size_t CL_Server_m(char *buffer, size_t size)
+{
+ return Q_strlcpy(buffer, cls.servername, size);
}
-static size_t CL_Ups_m( char *buffer, size_t size ) {
+static size_t CL_Ups_m(char *buffer, size_t size)
+{
vec3_t vel;
int ups;
player_state_t *ps;
- if( cl.frame.clientNum == CLIENTNUM_NONE ) {
- if( size ) {
+ if (cl.frame.clientNum == CLIENTNUM_NONE) {
+ if (size) {
*buffer = 0;
}
return 0;
}
- if( !cls.demo.playback && cl.frame.clientNum == cl.clientNum &&
- cl_predict->integer )
- {
- VectorCopy( cl.predicted_velocity, vel );
+ if (!cls.demo.playback && cl.frame.clientNum == cl.clientNum &&
+ cl_predict->integer) {
+ VectorCopy(cl.predicted_velocity, vel);
} else {
ps = &cl.frame.ps;
-
+
vel[0] = ps->pmove.velocity[0] * 0.125f;
vel[1] = ps->pmove.velocity[1] * 0.125f;
vel[2] = ps->pmove.velocity[2] * 0.125f;
}
- ups = VectorLength( vel );
- return Q_scnprintf( buffer, size, "%d", ups );
+ ups = VectorLength(vel);
+ return Q_scnprintf(buffer, size, "%d", ups);
}
-static size_t CL_Timer_m( char *buffer, size_t size ) {
+static size_t CL_Timer_m(char *buffer, size_t size)
+{
int hour, min, sec;
sec = cl.time / 1000;
min = sec / 60; sec %= 60;
hour = min / 60; min %= 60;
- if( hour ) {
- return Q_scnprintf( buffer, size, "%i:%i:%02i", hour, min, sec );
+ if (hour) {
+ return Q_scnprintf(buffer, size, "%i:%i:%02i", hour, min, sec);
}
- return Q_scnprintf( buffer, size, "%i:%02i", min, sec );
+ return Q_scnprintf(buffer, size, "%i:%02i", min, sec);
}
-static size_t CL_DemoPos_m( char *buffer, size_t size ) {
+static size_t CL_DemoPos_m(char *buffer, size_t size)
+{
int sec, min, framenum;
- if( cls.demo.playback )
+ if (cls.demo.playback)
framenum = cls.demo.frames_read;
else
#if USE_MVD_CLIENT
- if( MVD_GetDemoPercent( NULL, &framenum ) == -1 )
+ if (MVD_GetDemoPercent(NULL, &framenum) == -1)
#endif
- framenum = 0;
+ framenum = 0;
sec = framenum / 10; framenum %= 10;
min = sec / 60; sec %= 60;
- return Q_scnprintf( buffer, sizeof( buffer ),
- "%d:%02d.%d", min, sec, framenum );
+ return Q_scnprintf(buffer, sizeof(buffer),
+ "%d:%02d.%d", min, sec, framenum);
}
-static size_t CL_Fps_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", C_FPS );
+static size_t CL_Fps_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", C_FPS);
}
-static size_t R_Fps_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", R_FPS );
+
+static size_t R_Fps_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", R_FPS);
}
-static size_t CL_Mps_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", C_MPS );
+
+static size_t CL_Mps_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", C_MPS);
}
-static size_t CL_Pps_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", C_PPS );
+
+static size_t CL_Pps_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", C_PPS);
}
-static size_t CL_Ping_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", cls.measure.ping );
+
+static size_t CL_Ping_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", cls.measure.ping);
}
-static size_t CL_Lag_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%.2f%%", cls.netchan ?
- ( (float)cls.netchan->total_dropped /
- cls.netchan->total_received ) * 100.0f : 0 );
+
+static size_t CL_Lag_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%.2f%%", cls.netchan ?
+ ((float)cls.netchan->total_dropped /
+ cls.netchan->total_received) * 100.0f : 0);
}
-static size_t CL_Health_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_HEALTH] );
+
+static size_t CL_Health_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", cl.frame.ps.stats[STAT_HEALTH]);
}
-static size_t CL_Ammo_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_AMMO] );
+
+static size_t CL_Ammo_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", cl.frame.ps.stats[STAT_AMMO]);
}
-static size_t CL_Armor_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_ARMOR] );
+
+static size_t CL_Armor_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%i", cl.frame.ps.stats[STAT_ARMOR]);
}
/*
====================
CL_RestartFilesystem
-
+
Flush caches and restart the VFS.
====================
*/
-void CL_RestartFilesystem( qboolean total ) {
+void CL_RestartFilesystem(qboolean total)
+{
int cls_state;
- if( !cl_running->integer ) {
- FS_Restart( total );
+ if (!cl_running->integer) {
+ FS_Restart(total);
return;
}
- Com_DPrintf( "%s(%d)\n", __func__, total );
+ Com_DPrintf("%s(%d)\n", __func__, total);
// temporary switch to loading state
cls_state = cls.state;
- if( cls.state >= ca_precached ) {
+ if (cls.state >= ca_precached) {
cls.state = ca_loading;
}
@@ -2256,12 +2339,12 @@ void CL_RestartFilesystem( qboolean total ) {
S_StopAllSounds();
S_FreeAllSounds();
- if( cls.ref_initialized ) {
- R_Shutdown( qfalse );
+ if (cls.ref_initialized) {
+ R_Shutdown(qfalse);
- FS_Restart( total );
+ FS_Restart(total);
- R_Init( qfalse );
+ R_Init(qfalse);
SCR_RegisterMedia();
Con_RegisterMedia();
@@ -2269,21 +2352,21 @@ void CL_RestartFilesystem( qboolean total ) {
UI_Init();
#endif
} else {
- FS_Restart( total );
+ FS_Restart(total);
}
#if USE_UI
- if( cls_state == ca_disconnected ) {
- UI_OpenMenu( UIMENU_DEFAULT );
+ if (cls_state == ca_disconnected) {
+ UI_OpenMenu(UIMENU_DEFAULT);
} else
#endif
- if( cls_state >= ca_loading ) {
- CL_LoadState( LOAD_MAP );
- CL_PrepRefresh();
- CL_LoadState( LOAD_SOUNDS );
- CL_RegisterSounds();
- CL_LoadState( LOAD_FINISH );
- }
+ if (cls_state >= ca_loading) {
+ CL_LoadState(LOAD_MAP);
+ CL_PrepRefresh();
+ CL_LoadState(LOAD_SOUNDS);
+ CL_RegisterSounds();
+ CL_LoadState(LOAD_FINISH);
+ }
// switch back to original state
cls.state = cls_state;
@@ -2293,22 +2376,23 @@ void CL_RestartFilesystem( qboolean total ) {
cvar_modified &= ~CVAR_FILES;
}
-void CL_RestartRefresh( qboolean total ) {
+void CL_RestartRefresh(qboolean total)
+{
int cls_state;
- if( !cls.ref_initialized ) {
+ if (!cls.ref_initialized) {
return;
}
// temporary switch to loading state
cls_state = cls.state;
- if ( cls.state >= ca_precached ) {
+ if (cls.state >= ca_precached) {
cls.state = ca_loading;
}
S_StopAllSounds();
-
- if( total ) {
+
+ if (total) {
IN_Shutdown();
CL_ShutdownRefresh();
CL_InitRefresh();
@@ -2317,8 +2401,8 @@ void CL_RestartRefresh( qboolean total ) {
#if USE_UI
UI_Shutdown();
#endif
- R_Shutdown( qfalse );
- R_Init( qfalse );
+ R_Shutdown(qfalse);
+ R_Init(qfalse);
SCR_RegisterMedia();
Con_RegisterMedia();
#if USE_UI
@@ -2327,15 +2411,15 @@ void CL_RestartRefresh( qboolean total ) {
}
#if USE_UI
- if( cls_state == ca_disconnected ) {
- UI_OpenMenu( UIMENU_DEFAULT );
+ if (cls_state == ca_disconnected) {
+ UI_OpenMenu(UIMENU_DEFAULT);
} else
#endif
- if( cls_state >= ca_loading ) {
- CL_LoadState( LOAD_MAP );
- CL_PrepRefresh();
- CL_LoadState( LOAD_FINISH );
- }
+ if (cls_state >= ca_loading) {
+ CL_LoadState(LOAD_MAP);
+ CL_PrepRefresh();
+ CL_LoadState(LOAD_FINISH);
+ }
// switch back to original state
cls.state = cls_state;
@@ -2348,12 +2432,13 @@ void CL_RestartRefresh( qboolean total ) {
/*
====================
CL_ReloadRefresh
-
+
Flush caches and reload all models and textures.
====================
*/
-static void CL_ReloadRefresh_f( void ) {
- CL_RestartRefresh( qfalse );
+static void CL_ReloadRefresh_f(void)
+{
+ CL_RestartRefresh(qfalse);
}
/*
@@ -2363,94 +2448,105 @@ CL_RestartRefresh
Perform complete restart of the renderer subsystem.
====================
*/
-static void CL_RestartRefresh_f( void ) {
- CL_RestartRefresh( qtrue );
+static void CL_RestartRefresh_f(void)
+{
+ CL_RestartRefresh(qtrue);
}
// execute string in server command buffer
-static void exec_server_string( cmdbuf_t *buf, const char *text ) {
+static void exec_server_string(cmdbuf_t *buf, const char *text)
+{
char *s;
- Cmd_TokenizeString( text, qtrue );
-
+ Cmd_TokenizeString(text, qtrue);
+
// execute the command line
- if( !Cmd_Argc() ) {
+ if (!Cmd_Argc()) {
return; // no tokens
}
- Com_DPrintf( "stufftext: %s\n", text );
+ Com_DPrintf("stufftext: %s\n", text);
- s = Cmd_Argv( 0 );
+ s = Cmd_Argv(0);
// handle private client commands
- if( !strcmp( s, "changing" ) ) {
+ if (!strcmp(s, "changing")) {
CL_Changing_f();
return;
}
- if( !strcmp( s, "precache" ) ) {
+ if (!strcmp(s, "precache")) {
CL_Precache_f();
return;
}
// forbid nearly every command from demos
- if( cls.demo.playback ) {
- if( strcmp( s, "play" ) ) {
+ if (cls.demo.playback) {
+ if (strcmp(s, "play")) {
return;
}
}
// execute regular commands
- Cmd_ExecuteCommand( buf );
+ Cmd_ExecuteCommand(buf);
}
-static void cl_gun_changed( cvar_t *self ) {
+static void cl_gun_changed(cvar_t *self)
+{
CL_UpdateGunSetting();
}
-static void info_hand_changed( cvar_t *self ) {
+static void info_hand_changed(cvar_t *self)
+{
CL_UpdateGunSetting();
}
-static void cl_gibs_changed( cvar_t *self ) {
+static void cl_gibs_changed(cvar_t *self)
+{
CL_UpdateGibSetting();
}
-static void cl_footsteps_changed( cvar_t *self ) {
+static void cl_footsteps_changed(cvar_t *self)
+{
CL_UpdateFootstepsSetting();
}
-static void cl_predict_changed( cvar_t *self ) {
+static void cl_predict_changed(cvar_t *self)
+{
CL_UpdatePredictSetting();
}
#if USE_FPS
-static void cl_updaterate_changed( cvar_t *self ) {
+static void cl_updaterate_changed(cvar_t *self)
+{
CL_UpdateRateSetting();
}
#endif
-static void cl_sync_changed( cvar_t *self ) {
+static void cl_sync_changed(cvar_t *self)
+{
CL_UpdateFrameTimes();
}
// allow downloads to be permanently disabled as a
// protection measure from malicious (or just stupid) servers
// that force downloads by stuffing commands
-static void cl_allow_download_changed( cvar_t *self ) {
- if( self->integer == -1 ) {
+static void cl_allow_download_changed(cvar_t *self)
+{
+ if (self->integer == -1) {
self->flags |= CVAR_ROM;
}
}
// ugly hack for compatibility
-static void cl_chat_sound_changed( cvar_t *self ) {
- if( !*self->string )
+static void cl_chat_sound_changed(cvar_t *self)
+{
+ if (!*self->string)
self->integer = 0;
- else if( !Q_stricmp( self->string, "misc/talk.wav" ) )
+ else if (!Q_stricmp(self->string, "misc/talk.wav"))
self->integer = 1;
- else if( !Q_stricmp( self->string, "misc/talk1.wav" ) )
+ else if (!Q_stricmp(self->string, "misc/talk1.wav"))
self->integer = 2;
- else if( !self->integer && !COM_IsUint( self->string ) )
+ else if (!self->integer && !COM_IsUint(self->string))
self->integer = 1;
}
@@ -2506,7 +2602,8 @@ static const cmdreg_t c_client[] = {
CL_InitLocal
=================
*/
-static void CL_InitLocal ( void ) {
+static void CL_InitLocal(void)
+{
cvar_t *var;
int i;
@@ -2521,37 +2618,37 @@ static void CL_InitLocal ( void ) {
CL_InitTEnts();
CL_InitDownloads();
- List_Init( &cl_ignores );
+ List_Init(&cl_ignores);
- Cmd_Register( c_client );
+ Cmd_Register(c_client);
- for ( i = 0 ; i < MAX_LOCAL_SERVERS ; i++ ) {
- var = Cvar_Get( va( "adr%i", i ), "", CVAR_ARCHIVE );
+ for (i = 0; i < MAX_LOCAL_SERVERS; i++) {
+ var = Cvar_Get(va("adr%i", i), "", CVAR_ARCHIVE);
var->generator = Com_Address_g;
}
//
// register our variables
//
- cl_gun = Cvar_Get ( "cl_gun", "1", 0 );
+ cl_gun = Cvar_Get("cl_gun", "1", 0);
cl_gun->changed = cl_gun_changed;
- cl_gunalpha = Cvar_Get ( "cl_gunalpha", "1", 0 );
- cl_footsteps = Cvar_Get( "cl_footsteps", "1", 0 );
+ cl_gunalpha = Cvar_Get("cl_gunalpha", "1", 0);
+ cl_footsteps = Cvar_Get("cl_footsteps", "1", 0);
cl_footsteps->changed = cl_footsteps_changed;
- cl_noskins = Cvar_Get ( "cl_noskins", "0", 0 );
+ cl_noskins = Cvar_Get("cl_noskins", "0", 0);
cl_noskins->changed = cl_noskins_changed;
- cl_predict = Cvar_Get ( "cl_predict", "1", 0 );
+ cl_predict = Cvar_Get("cl_predict", "1", 0);
cl_predict->changed = cl_predict_changed;
- cl_kickangles = Cvar_Get( "cl_kickangles", "1", CVAR_CHEAT );
- cl_maxfps = Cvar_Get( "cl_maxfps", "60", 0 );
+ cl_kickangles = Cvar_Get("cl_kickangles", "1", CVAR_CHEAT);
+ cl_maxfps = Cvar_Get("cl_maxfps", "60", 0);
cl_maxfps->changed = cl_sync_changed;
- cl_async = Cvar_Get( "cl_async", "1", 0 );
+ cl_async = Cvar_Get("cl_async", "1", 0);
cl_async->changed = cl_sync_changed;
- r_maxfps = Cvar_Get( "r_maxfps", "0", 0 );
+ r_maxfps = Cvar_Get("r_maxfps", "0", 0);
r_maxfps->changed = cl_sync_changed;
- cl_rollhack = Cvar_Get( "cl_rollhack", "1", 0 );
- cl_noglow = Cvar_Get( "cl_noglow", "0", 0 );
- cl_nolerp = Cvar_Get( "cl_nolerp", "0", 0 );
+ cl_rollhack = Cvar_Get("cl_rollhack", "1", 0);
+ cl_noglow = Cvar_Get("cl_noglow", "0", 0);
+ cl_nolerp = Cvar_Get("cl_nolerp", "0", 0);
// hack for timedemo
com_timedemo->changed = cl_sync_changed;
@@ -2559,84 +2656,84 @@ static void CL_InitLocal ( void ) {
CL_UpdateFrameTimes();
#ifdef _DEBUG
- cl_shownet = Cvar_Get( "cl_shownet", "0", 0 );
- cl_showmiss = Cvar_Get ( "cl_showmiss", "0", 0 );
- cl_showclamp = Cvar_Get ( "showclamp", "0", 0 );
+ cl_shownet = Cvar_Get("cl_shownet", "0", 0);
+ cl_showmiss = Cvar_Get("cl_showmiss", "0", 0);
+ cl_showclamp = Cvar_Get("showclamp", "0", 0);
#endif
- cl_timeout = Cvar_Get ( "cl_timeout", "120", 0 );
+ cl_timeout = Cvar_Get("cl_timeout", "120", 0);
- rcon_address = Cvar_Get ( "rcon_address", "", CVAR_PRIVATE );
+ rcon_address = Cvar_Get("rcon_address", "", CVAR_PRIVATE);
rcon_address->generator = Com_Address_g;
- cl_thirdperson = Cvar_Get( "cl_thirdperson", "0", CVAR_CHEAT );
- cl_thirdperson_angle = Cvar_Get( "cl_thirdperson_angle", "0", 0 );
- cl_thirdperson_range = Cvar_Get( "cl_thirdperson_range", "60", 0 );
+ cl_thirdperson = Cvar_Get("cl_thirdperson", "0", CVAR_CHEAT);
+ cl_thirdperson_angle = Cvar_Get("cl_thirdperson_angle", "0", 0);
+ cl_thirdperson_range = Cvar_Get("cl_thirdperson_range", "60", 0);
- cl_disable_particles = Cvar_Get( "cl_disable_particles", "0", 0 );
- cl_disable_explosions = Cvar_Get( "cl_disable_explosions", "0", 0 );
- cl_gibs = Cvar_Get( "cl_gibs", "1", 0 );
+ cl_disable_particles = Cvar_Get("cl_disable_particles", "0", 0);
+ cl_disable_explosions = Cvar_Get("cl_disable_explosions", "0", 0);
+ cl_gibs = Cvar_Get("cl_gibs", "1", 0);
cl_gibs->changed = cl_gibs_changed;
#if USE_FPS
- cl_updaterate = Cvar_Get( "cl_updaterate", "0", 0 );
+ cl_updaterate = Cvar_Get("cl_updaterate", "0", 0);
cl_updaterate->changed = cl_updaterate_changed;
#endif
- cl_chat_notify = Cvar_Get( "cl_chat_notify", "1", 0 );
- cl_chat_sound = Cvar_Get( "cl_chat_sound", "1", 0 );
+ cl_chat_notify = Cvar_Get("cl_chat_notify", "1", 0);
+ cl_chat_sound = Cvar_Get("cl_chat_sound", "1", 0);
cl_chat_sound->changed = cl_chat_sound_changed;
- cl_chat_sound_changed( cl_chat_sound );
- cl_chat_filter = Cvar_Get( "cl_chat_filter", "0", 0 );
+ cl_chat_sound_changed(cl_chat_sound);
+ cl_chat_filter = Cvar_Get("cl_chat_filter", "0", 0);
- cl_disconnectcmd = Cvar_Get( "cl_disconnectcmd", "", 0 );
- cl_changemapcmd = Cvar_Get( "cl_changemapcmd", "", 0 );
- cl_beginmapcmd = Cvar_Get( "cl_beginmapcmd", "", 0 );
+ cl_disconnectcmd = Cvar_Get("cl_disconnectcmd", "", 0);
+ cl_changemapcmd = Cvar_Get("cl_changemapcmd", "", 0);
+ cl_beginmapcmd = Cvar_Get("cl_beginmapcmd", "", 0);
- cl_protocol = Cvar_Get( "cl_protocol", "0", 0 );
+ cl_protocol = Cvar_Get("cl_protocol", "0", 0);
- gender_auto = Cvar_Get ( "gender_auto", "1", CVAR_ARCHIVE );
+ gender_auto = Cvar_Get("gender_auto", "1", CVAR_ARCHIVE);
- cl_vwep = Cvar_Get ( "cl_vwep", "1", CVAR_ARCHIVE );
+ cl_vwep = Cvar_Get("cl_vwep", "1", CVAR_ARCHIVE);
cl_vwep->changed = cl_vwep_changed;
allow_download->changed = cl_allow_download_changed;
- cl_allow_download_changed( allow_download );
+ cl_allow_download_changed(allow_download);
//
// userinfo
//
- info_password = Cvar_Get( "password", "", CVAR_USERINFO );
- info_spectator = Cvar_Get( "spectator", "0", CVAR_USERINFO );
- info_name = Cvar_Get( "name", "unnamed", CVAR_USERINFO | CVAR_ARCHIVE );
- info_skin = Cvar_Get( "skin", "male/grunt", CVAR_USERINFO | CVAR_ARCHIVE );
- info_rate = Cvar_Get( "rate", "5000", CVAR_USERINFO | CVAR_ARCHIVE );
- info_msg = Cvar_Get( "msg", "1", CVAR_USERINFO | CVAR_ARCHIVE );
- info_hand = Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE );
+ info_password = Cvar_Get("password", "", CVAR_USERINFO);
+ info_spectator = Cvar_Get("spectator", "0", CVAR_USERINFO);
+ info_name = Cvar_Get("name", "unnamed", CVAR_USERINFO | CVAR_ARCHIVE);
+ info_skin = Cvar_Get("skin", "male/grunt", CVAR_USERINFO | CVAR_ARCHIVE);
+ info_rate = Cvar_Get("rate", "5000", CVAR_USERINFO | CVAR_ARCHIVE);
+ info_msg = Cvar_Get("msg", "1", CVAR_USERINFO | CVAR_ARCHIVE);
+ info_hand = Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE);
info_hand->changed = info_hand_changed;
- info_fov = Cvar_Get( "fov", "90", CVAR_USERINFO | CVAR_ARCHIVE );
- info_gender = Cvar_Get( "gender", "male", CVAR_USERINFO | CVAR_ARCHIVE );
+ info_fov = Cvar_Get("fov", "90", CVAR_USERINFO | CVAR_ARCHIVE);
+ info_gender = Cvar_Get("gender", "male", CVAR_USERINFO | CVAR_ARCHIVE);
info_gender->modified = qfalse; // clear this so we know when user sets it manually
- info_uf = Cvar_Get( "uf", va( "%d", UF_LOCALFOV ), CVAR_USERINFO );
+ info_uf = Cvar_Get("uf", va("%d", UF_LOCALFOV), CVAR_USERINFO);
//
// macros
//
- Cmd_AddMacro( "cl_mapname", CL_Mapname_m );
- Cmd_AddMacro( "cl_server", CL_Server_m );
- Cmd_AddMacro( "cl_timer", CL_Timer_m );
- Cmd_AddMacro( "cl_demopos", CL_DemoPos_m );
- Cmd_AddMacro( "cl_ups", CL_Ups_m );
- Cmd_AddMacro( "cl_fps", CL_Fps_m );
- Cmd_AddMacro( "r_fps", R_Fps_m );
- Cmd_AddMacro( "cl_mps", CL_Mps_m ); // moves per second
- Cmd_AddMacro( "cl_pps", CL_Pps_m ); // packets per second
- Cmd_AddMacro( "cl_ping", CL_Ping_m );
- Cmd_AddMacro( "cl_lag", CL_Lag_m );
- Cmd_AddMacro( "cl_health", CL_Health_m );
- Cmd_AddMacro( "cl_ammo", CL_Ammo_m );
- Cmd_AddMacro( "cl_armor", CL_Armor_m );
+ Cmd_AddMacro("cl_mapname", CL_Mapname_m);
+ Cmd_AddMacro("cl_server", CL_Server_m);
+ Cmd_AddMacro("cl_timer", CL_Timer_m);
+ Cmd_AddMacro("cl_demopos", CL_DemoPos_m);
+ Cmd_AddMacro("cl_ups", CL_Ups_m);
+ Cmd_AddMacro("cl_fps", CL_Fps_m);
+ Cmd_AddMacro("r_fps", R_Fps_m);
+ Cmd_AddMacro("cl_mps", CL_Mps_m); // moves per second
+ Cmd_AddMacro("cl_pps", CL_Pps_m); // packets per second
+ Cmd_AddMacro("cl_ping", CL_Ping_m);
+ Cmd_AddMacro("cl_lag", CL_Lag_m);
+ Cmd_AddMacro("cl_health", CL_Health_m);
+ Cmd_AddMacro("cl_ammo", CL_Ammo_m);
+ Cmd_AddMacro("cl_armor", CL_Armor_m);
}
/*
@@ -2644,26 +2741,27 @@ static void CL_InitLocal ( void ) {
CL_CheatsOK
==================
*/
-qboolean CL_CheatsOK( void ) {
+qboolean CL_CheatsOK(void)
+{
// can cheat when disconnected or playing a demo
- if( cls.state < ca_connected || cls.demo.playback )
+ if (cls.state < ca_connected || cls.demo.playback)
return qtrue;
// can't cheat on remote servers
- if( !sv_running->integer )
+ if (!sv_running->integer)
return qfalse;
// developer option
- if( Cvar_VariableInteger( "cheats" ) )
+ if (Cvar_VariableInteger("cheats"))
return qtrue;
// single player can cheat
- if( cls.state > ca_connected && cl.maxclients == 1 )
+ if (cls.state > ca_connected && cl.maxclients == 1)
return qtrue;
#if USE_MVD_CLIENT
// can cheat when playing MVD
- if( MVD_GetDemoPercent( NULL, NULL ) != -1 )
+ if (MVD_GetDemoPercent(NULL, NULL) != -1)
return qtrue;
#endif
@@ -2677,9 +2775,10 @@ qboolean CL_CheatsOK( void ) {
CL_Activate
==================
*/
-void CL_Activate( active_t active ) {
- if( cls.active != active ) {
- Com_DDDPrintf( "%s: %u\n", __func__, active );
+void CL_Activate(active_t active)
+{
+ if (cls.active != active) {
+ Com_DDDPrintf("%s: %u\n", __func__, active);
cls.active = active;
cls.disable_screen = 0;
Key_ClearStates();
@@ -2689,10 +2788,11 @@ void CL_Activate( active_t active ) {
}
}
-static void CL_SetClientTime( void ) {
+static void CL_SetClientTime(void)
+{
int prevtime;
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
cl.time = cl.servertime;
cl.lerpfrac = 1.0f;
#if USE_FPS
@@ -2703,60 +2803,61 @@ static void CL_SetClientTime( void ) {
}
prevtime = cl.servertime - CL_FRAMETIME;
- if( cl.time > cl.servertime ) {
- SHOWCLAMP( 1, "high clamp %i\n", cl.time - cl.servertime );
+ if (cl.time > cl.servertime) {
+ SHOWCLAMP(1, "high clamp %i\n", cl.time - cl.servertime);
cl.time = cl.servertime;
cl.lerpfrac = 1.0f;
- } else if( cl.time < prevtime ) {
- SHOWCLAMP( 1, "low clamp %i\n", prevtime - cl.time );
+ } else if (cl.time < prevtime) {
+ SHOWCLAMP(1, "low clamp %i\n", prevtime - cl.time);
cl.time = prevtime;
cl.lerpfrac = 0;
} else {
- cl.lerpfrac = ( cl.time - prevtime ) * CL_1_FRAMETIME;
+ cl.lerpfrac = (cl.time - prevtime) * CL_1_FRAMETIME;
}
- SHOWCLAMP( 2, "time %d %d, lerpfrac %.3f\n",
- cl.time, cl.servertime, cl.lerpfrac );
+ SHOWCLAMP(2, "time %d %d, lerpfrac %.3f\n",
+ cl.time, cl.servertime, cl.lerpfrac);
#if USE_FPS
prevtime = cl.keyservertime - BASE_FRAMETIME;
- if( cl.keytime > cl.keyservertime ) {
- SHOWCLAMP( 1, "high keyclamp %i\n", cl.keytime - cl.keyservertime );
+ if (cl.keytime > cl.keyservertime) {
+ SHOWCLAMP(1, "high keyclamp %i\n", cl.keytime - cl.keyservertime);
cl.keytime = cl.keyservertime;
cl.keylerpfrac = 1.0f;
- } else if( cl.keytime < prevtime ) {
- SHOWCLAMP( 1, "low keyclamp %i\n", prevtime - cl.keytime );
+ } else if (cl.keytime < prevtime) {
+ SHOWCLAMP(1, "low keyclamp %i\n", prevtime - cl.keytime);
cl.keytime = prevtime;
cl.keylerpfrac = 0;
} else {
- cl.keylerpfrac = ( cl.keytime - prevtime ) * BASE_1_FRAMETIME;
+ cl.keylerpfrac = (cl.keytime - prevtime) * BASE_1_FRAMETIME;
}
- SHOWCLAMP( 2, "keytime %d %d keylerpfrac %.3f\n",
- cl.keytime, cl.keyservertime, cl.keylerpfrac );
+ SHOWCLAMP(2, "keytime %d %d keylerpfrac %.3f\n",
+ cl.keytime, cl.keyservertime, cl.keylerpfrac);
#endif
}
-static void CL_MeasureStats( void ) {
+static void CL_MeasureStats(void)
+{
int i;
- if( com_localTime - cls.measure.time < 1000 ) {
+ if (com_localTime - cls.measure.time < 1000) {
return;
}
// measure average ping
- if( cls.netchan ) {
+ if (cls.netchan) {
int ack = cls.netchan->incoming_acknowledged;
int ping = 0;
int j, k = 0;
i = ack - 16 + 1;
- if( i < cl.initialSeq ) {
+ if (i < cl.initialSeq) {
i = cl.initialSeq;
}
- for( j = i; j <= ack; j++ ) {
+ for (j = i; j <= ack; j++) {
client_history_t *h = &cl.history[j & CMD_MASK];
- if( h->rcvd > h->sent ) {
+ if (h->rcvd > h->sent) {
ping += h->rcvd - h->sent;
k++;
}
@@ -2766,7 +2867,7 @@ static void CL_MeasureStats( void ) {
}
// measure main/refresh frame counts
- for( i = 0; i < 4; i++ ) {
+ for (i = 0; i < 4; i++) {
cls.measure.fps[i] = cls.measure.frames[i];
cls.measure.frames[i] = 0;
}
@@ -2775,42 +2876,44 @@ static void CL_MeasureStats( void ) {
}
#if USE_AUTOREPLY
-static void CL_CheckForReply( void ) {
- if( !cl.reply_delta ) {
+static void CL_CheckForReply(void)
+{
+ if (!cl.reply_delta) {
return;
}
- if( cls.realtime - cl.reply_time < cl.reply_delta ) {
+ if (cls.realtime - cl.reply_time < cl.reply_delta) {
return;
}
- CL_ClientCommand( va( "say \"%s\"", com_version->string ) );
+ CL_ClientCommand(va("say \"%s\"", com_version->string));
cl.reply_delta = 0;
}
#endif
-static void CL_CheckTimeout( void ) {
+static void CL_CheckTimeout(void)
+{
unsigned delta;
- if( NET_IsLocalAddress( &cls.netchan->remote_address ) ) {
+ if (NET_IsLocalAddress(&cls.netchan->remote_address)) {
return;
}
#if USE_ICMP
- if( cls.errorReceived ) {
+ if (cls.errorReceived) {
delta = 5000;
- if( com_localTime - cls.netchan->last_received > delta ) {
- Com_Error( ERR_DISCONNECT, "Server connection was reset." );
+ if (com_localTime - cls.netchan->last_received > delta) {
+ Com_Error(ERR_DISCONNECT, "Server connection was reset.");
}
}
#endif
-
+
delta = cl_timeout->value * 1000;
- if( delta && com_localTime - cls.netchan->last_received > delta ) {
+ if (delta && com_localTime - cls.netchan->last_received > delta) {
// timeoutcount saves debugger
- if ( ++cl.timeoutcount > 5 ) {
- Com_Error( ERR_DISCONNECT, "Server connection timed out." );
+ if (++cl.timeoutcount > 5) {
+ Com_Error(ERR_DISCONNECT, "Server connection timed out.");
}
} else {
cl.timeoutcount = 0;
@@ -2823,35 +2926,36 @@ CL_CheckForPause
=================
*/
-void CL_CheckForPause( void ) {
- if( cls.state != ca_active ) {
+void CL_CheckForPause(void)
+{
+ if (cls.state != ca_active) {
// only pause when active
- Cvar_Set( "cl_paused", "0" );
- Cvar_Set( "sv_paused", "0" );
+ Cvar_Set("cl_paused", "0");
+ Cvar_Set("sv_paused", "0");
return;
}
- if( cls.key_dest & (KEY_CONSOLE|KEY_MENU) ) {
+ if (cls.key_dest & (KEY_CONSOLE | KEY_MENU)) {
// only pause in single player
- if( cl_paused->integer == 0 ) {
- Cvar_Set( "cl_paused", "1" );
+ if (cl_paused->integer == 0) {
+ Cvar_Set("cl_paused", "1");
}
- } else if( cl_paused->integer == 1 ) {
+ } else if (cl_paused->integer == 1) {
// only resume after automatic pause
- Cvar_Set( "cl_paused", "0" );
+ Cvar_Set("cl_paused", "0");
}
// hack for demo playback pause/unpause
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
// don't pause when running timedemo!
- if( cl_paused->integer && !com_timedemo->integer ) {
- if( !sv_paused->integer ) {
- Cvar_Set( "sv_paused", "1" );
+ if (cl_paused->integer && !com_timedemo->integer) {
+ if (!sv_paused->integer) {
+ Cvar_Set("sv_paused", "1");
IN_Activate();
}
} else {
- if( sv_paused->integer ) {
- Cvar_Set( "sv_paused", "0" );
+ if (sv_paused->integer) {
+ Cvar_Set("sv_paused", "0");
IN_Activate();
}
}
@@ -2886,8 +2990,9 @@ static int ref_msec, phys_msec, main_msec;
static int ref_extra, phys_extra, main_extra;
static sync_mode_t sync_mode;
-static inline int fps_to_msec( int fps ) {
- return ( 1000 + fps / 2 ) / fps;
+static inline int fps_to_msec(int fps)
+{
+ return (1000 + fps / 2) / fps;
}
/*
@@ -2897,43 +3002,44 @@ CL_UpdateFrameTimes
Called whenever async/fps cvars change, but not every frame
==================
*/
-void CL_UpdateFrameTimes( void ) {
- if( !cls.state ) {
+void CL_UpdateFrameTimes(void)
+{
+ if (!cls.state) {
return; // not yet fully initialized
}
// check if video driver supports syncing to vertical retrace
- if( cl_async->integer > 1 && !( r_config.flags & QVF_VIDEOSYNC ) ) {
- Cvar_Reset( cl_async );
+ if (cl_async->integer > 1 && !(r_config.flags & QVF_VIDEOSYNC)) {
+ Cvar_Reset(cl_async);
}
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
// timedemo just runs at full speed
ref_msec = phys_msec = main_msec = 0;
sync_mode = SYNC_FULL;
- } else if( cls.active == ACT_MINIMIZED ) {
+ } else if (cls.active == ACT_MINIMIZED) {
// run at 10 fps if minimized
ref_msec = phys_msec = 0;
- main_msec = fps_to_msec( 10 );
+ main_msec = fps_to_msec(10);
sync_mode = SYNC_SLEEP_10;
- } else if( cls.active == ACT_RESTORED || cls.state < ca_active ) {
+ } else if (cls.active == ACT_RESTORED || cls.state < ca_active) {
// run at 60 fps if not active
ref_msec = phys_msec = 0;
- if( cl_async->integer > 1 ) {
+ if (cl_async->integer > 1) {
main_msec = 0;
sync_mode = SYNC_SLEEP_VIDEO;
} else {
- main_msec = fps_to_msec( 60 );
+ main_msec = fps_to_msec(60);
sync_mode = SYNC_SLEEP_60;
}
- } else if( cl_async->integer > 0 ) {
+ } else if (cl_async->integer > 0) {
// run physics and refresh separately
- phys_msec = fps_to_msec( Cvar_ClampInteger( cl_maxfps, 10, 120 ) );
- if( cl_async->integer > 1 ) {
+ phys_msec = fps_to_msec(Cvar_ClampInteger(cl_maxfps, 10, 120));
+ if (cl_async->integer > 1) {
ref_msec = 0;
sync_mode = ASYNC_VIDEO;
- } else if( r_maxfps->integer ) {
- ref_msec = fps_to_msec( Cvar_ClampInteger( r_maxfps, 10, 1000 ) );
+ } else if (r_maxfps->integer) {
+ ref_msec = fps_to_msec(Cvar_ClampInteger(r_maxfps, 10, 1000));
sync_mode = ASYNC_MAXFPS;
} else {
ref_msec = 1;
@@ -2943,8 +3049,8 @@ void CL_UpdateFrameTimes( void ) {
} else {
// everything ticks in sync with refresh
phys_msec = ref_msec = 0;
- if( cl_maxfps->integer ) {
- main_msec = fps_to_msec( Cvar_ClampInteger( cl_maxfps, 10, 1000 ) );
+ if (cl_maxfps->integer) {
+ main_msec = fps_to_msec(Cvar_ClampInteger(cl_maxfps, 10, 1000));
sync_mode = SYNC_MAXFPS;
} else {
main_msec = 1;
@@ -2952,8 +3058,8 @@ void CL_UpdateFrameTimes( void ) {
}
}
- Com_DDDPrintf( "%s: mode=%s main_msec=%d ref_msec=%d, phys_msec=%d\n",
- __func__, sync_names[sync_mode], main_msec, ref_msec, phys_msec );
+ Com_DDDPrintf("%s: mode=%s main_msec=%d ref_msec=%d, phys_msec=%d\n",
+ __func__, sync_names[sync_mode], main_msec, ref_msec, phys_msec);
ref_extra = phys_extra = main_extra = 0;
}
@@ -2961,15 +3067,16 @@ void CL_UpdateFrameTimes( void ) {
/*
==================
CL_Frame
-
+
==================
*/
-unsigned CL_Frame( unsigned msec ) {
+unsigned CL_Frame(unsigned msec)
+{
qboolean phys_frame, ref_frame;
time_after_ref = time_before_ref = 0;
- if( !cl_running->integer ) {
+ if (!cl_running->integer) {
return UINT_MAX;
}
@@ -2979,7 +3086,7 @@ unsigned CL_Frame( unsigned msec ) {
CL_ProcessEvents();
ref_frame = phys_frame = qtrue;
- switch( sync_mode ) {
+ switch (sync_mode) {
case SYNC_FULL:
// timedemo just runs at full speed
break;
@@ -2989,7 +3096,7 @@ unsigned CL_Frame( unsigned msec ) {
// fall through
case SYNC_SLEEP_60:
// run at limited fps if not active
- if( main_extra < main_msec ) {
+ if (main_extra < main_msec) {
return main_msec - main_extra;
}
break;
@@ -3002,28 +3109,28 @@ unsigned CL_Frame( unsigned msec ) {
case ASYNC_FULL:
// run physics and refresh separately
phys_extra += main_extra;
- if( phys_extra < phys_msec ) {
+ if (phys_extra < phys_msec) {
phys_frame = qfalse;
- } else if( phys_extra > phys_msec * 4 ) {
+ } else if (phys_extra > phys_msec * 4) {
phys_extra = phys_msec;
}
- if( sync_mode == ASYNC_VIDEO ) {
+ if (sync_mode == ASYNC_VIDEO) {
// sync refresh to vertical retrace
ref_frame = VID_VideoSync();
} else {
ref_extra += main_extra;
- if( ref_extra < ref_msec ) {
+ if (ref_extra < ref_msec) {
ref_frame = qfalse;
- } else if( ref_extra > ref_msec * 4 ) {
+ } else if (ref_extra > ref_msec * 4) {
ref_extra = ref_msec;
}
}
break;
case SYNC_MAXFPS:
// everything ticks in sync with refresh
- if( main_extra < main_msec ) {
- if( !cl.sendPacketNow ) {
+ if (main_extra < main_msec) {
+ if (!cl.sendPacketNow) {
return 0;
}
ref_frame = qfalse;
@@ -3031,18 +3138,18 @@ unsigned CL_Frame( unsigned msec ) {
break;
}
- Com_DDDDPrintf( "main_extra=%d ref_frame=%d ref_extra=%d "
- "phys_frame=%d phys_extra=%d\n",
- main_extra, ref_frame, ref_extra,
- phys_frame, phys_extra );
+ Com_DDDDPrintf("main_extra=%d ref_frame=%d ref_extra=%d "
+ "phys_frame=%d phys_extra=%d\n",
+ main_extra, ref_frame, ref_extra,
+ phys_frame, phys_extra);
// decide the simulation time
cls.frametime = main_extra * 0.001f;
- if( cls.frametime > 1.0 / 5 )
+ if (cls.frametime > 1.0 / 5)
cls.frametime = 1.0 / 5;
- if( !sv_paused->integer ) {
+ if (!sv_paused->integer) {
cl.time += main_extra;
#if USE_FPS
cl.keytime += main_extra;
@@ -3050,11 +3157,11 @@ unsigned CL_Frame( unsigned msec ) {
}
// read next demo frame
- if( cls.demo.playback )
- CL_DemoFrame( main_extra );
+ if (cls.demo.playback)
+ CL_DemoFrame(main_extra);
// calculate local time
- if( cls.state == ca_active && !sv_paused->integer )
+ if (cls.state == ca_active && !sv_paused->integer)
CL_SetClientTime();
#if USE_AUTOREPLY
@@ -3066,18 +3173,18 @@ unsigned CL_Frame( unsigned msec ) {
CL_CheckForResend();
// read user intentions
- CL_UpdateCmd( main_extra );
+ CL_UpdateCmd(main_extra);
// finalize pending cmd
phys_frame |= cl.sendPacketNow;
- if( phys_frame ) {
+ if (phys_frame) {
CL_FinalizeCmd();
phys_extra -= phys_msec;
M_FRAMES++;
// don't let the time go too far off
// this can happen due to cl.sendPacketNow
- if( phys_extra < -phys_msec * 4 ) {
+ if (phys_extra < -phys_msec * 4) {
phys_extra = 0;
}
}
@@ -3090,14 +3197,14 @@ unsigned CL_Frame( unsigned msec ) {
Con_RunConsole();
- if( ref_frame ) {
+ if (ref_frame) {
// update the screen
- if ( host_speeds->integer )
+ if (host_speeds->integer)
time_before_ref = Sys_Milliseconds();
SCR_UpdateScreen();
- if ( host_speeds->integer )
+ if (host_speeds->integer)
time_after_ref = Sys_Milliseconds();
ref_extra -= ref_msec;
@@ -3115,14 +3222,14 @@ run_fx:
#if USE_LIGHTSTYLES
CL_RunLightStyles();
#endif
- } else if( sync_mode == SYNC_SLEEP_10 ) {
+ } else if (sync_mode == SYNC_SLEEP_10) {
// force audio and effects update if not rendering
CL_CalcViewValues();
goto run_fx;
}
// check connection timeout
- if( cls.netchan )
+ if (cls.netchan)
CL_CheckTimeout();
C_FRAMES++;
@@ -3140,8 +3247,9 @@ run_fx:
CL_ProcessEvents
============
*/
-qboolean CL_ProcessEvents( void ) {
- if( !cl_running->integer ) {
+qboolean CL_ProcessEvents(void)
+{
+ if (!cl_running->integer) {
return qfalse;
}
@@ -3149,22 +3257,22 @@ qboolean CL_ProcessEvents( void ) {
IN_Frame();
- memset( &net_from, 0, sizeof( net_from ) );
+ memset(&net_from, 0, sizeof(net_from));
net_from.type = NA_LOOPBACK;
// process loopback packets
- while( NET_GetLoopPacket( NS_CLIENT ) ) {
+ while (NET_GetLoopPacket(NS_CLIENT)) {
CL_PacketEvent();
}
// process network packets
- while( NET_GetPacket( NS_CLIENT ) ) {
+ while (NET_GetPacket(NS_CLIENT)) {
CL_PacketEvent();
}
// process console and stuffed commands
- Cbuf_Execute( &cmd_buffer );
- Cbuf_Execute( &cl_cmdbuf );
+ Cbuf_Execute(&cmd_buffer);
+ Cbuf_Execute(&cl_cmdbuf);
#if USE_CURL
HTTP_RunDownloads();
@@ -3180,12 +3288,13 @@ qboolean CL_ProcessEvents( void ) {
CL_Init
====================
*/
-void CL_Init( void ) {
- if( dedicated->integer ) {
+void CL_Init(void)
+{
+ if (dedicated->integer) {
return; // nothing running on the client
}
- if( cl_running->integer ) {
+ if (cl_running->integer) {
return;
}
@@ -3206,8 +3315,8 @@ void CL_Init( void ) {
IN_Init();
#if USE_ZLIB
- if( inflateInit2( &cls.z, -MAX_WBITS ) != Z_OK ) {
- Com_Error( ERR_FATAL, "%s: inflateInit2() failed", __func__ );
+ if (inflateInit2(&cls.z, -MAX_WBITS) != Z_OK) {
+ Com_Error(ERR_FATAL, "%s: inflateInit2() failed", __func__);
}
#endif
@@ -3216,7 +3325,7 @@ void CL_Init( void ) {
#endif
#if USE_UI
- UI_OpenMenu( UIMENU_DEFAULT );
+ UI_OpenMenu(UIMENU_DEFAULT);
#endif
Con_PostInit();
@@ -3224,10 +3333,10 @@ void CL_Init( void ) {
cl_cmdbuf.from = FROM_STUFFTEXT;
cl_cmdbuf.text = cl_cmdbuf_text;
- cl_cmdbuf.maxsize = sizeof( cl_cmdbuf_text );
+ cl_cmdbuf.maxsize = sizeof(cl_cmdbuf_text);
cl_cmdbuf.exec = exec_server_string;
- Cvar_Set( "cl_running", "1" );
+ Cvar_Set("cl_running", "1");
}
/*
@@ -3237,51 +3346,52 @@ CL_WriteConfig
Writes key bindings and archived cvars to config.cfg
===============
*/
-static void CL_WriteConfig( void ) {
+static void CL_WriteConfig(void)
+{
qhandle_t f;
qerror_t ret;
- ret = FS_FOpenFile( COM_CONFIG_NAME, &f, FS_MODE_WRITE | FS_FLAG_TEXT );
- if( !f ) {
- Com_EPrintf( "Couldn't open %s for writing: %s\n",
- COM_CONFIG_NAME, Q_ErrorString( ret ) );
+ ret = FS_FOpenFile(COM_CONFIG_NAME, &f, FS_MODE_WRITE | FS_FLAG_TEXT);
+ if (!f) {
+ Com_EPrintf("Couldn't open %s for writing: %s\n",
+ COM_CONFIG_NAME, Q_ErrorString(ret));
return;
}
- FS_FPrintf( f, "// generated by q2pro, do not modify\n" );
+ FS_FPrintf(f, "// generated by q2pro, do not modify\n");
- Key_WriteBindings( f );
- Cvar_WriteVariables( f, CVAR_ARCHIVE, qfalse );
-
- FS_FCloseFile( f );
-}
+ Key_WriteBindings(f);
+ Cvar_WriteVariables(f, CVAR_ARCHIVE, qfalse);
+ FS_FCloseFile(f);
+}
/*
===============
CL_Shutdown
-
+
FIXME: this is a callback from Com_Quit and Com_Error. It would be better
to run quit through here before the final handoff to the sys code.
===============
*/
-void CL_Shutdown( void ) {
+void CL_Shutdown(void)
+{
static qboolean isdown = qfalse;
-
- if( isdown ) {
- Com_Printf( "CL_Shutdown: recursive shutdown\n" );
+
+ if (isdown) {
+ Com_Printf("CL_Shutdown: recursive shutdown\n");
return;
}
isdown = qtrue;
- if( !cl_running || !cl_running->integer ) {
+ if (!cl_running || !cl_running->integer) {
return;
}
- CL_Disconnect( ERR_FATAL );
+ CL_Disconnect(ERR_FATAL);
#if USE_ZLIB
- inflateEnd( &cls.z );
+ inflateEnd(&cls.z);
#endif
#if USE_CURL
@@ -3294,9 +3404,9 @@ void CL_Shutdown( void ) {
CL_ShutdownRefresh();
CL_WriteConfig();
- memset( &cls, 0, sizeof( cls ) );
+ memset(&cls, 0, sizeof(cls));
- Cvar_Set( "cl_running", "0" );
+ Cvar_Set("cl_running", "0");
isdown = qfalse;
}
diff --git a/src/cl_newfx.c b/src/cl_newfx.c
index 6b1974c..5397366 100644
--- a/src/cl_newfx.c
+++ b/src/cl_newfx.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,22 +28,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
vectoangles2 - this is duplicated in the game DLL, but I need it heref.
======
*/
-static void vectoangles2 (vec3_t value1, vec3_t angles)
+static void vectoangles2(vec3_t value1, vec3_t angles)
{
float forward;
float yaw, pitch;
-
- if (value1[1] == 0 && value1[0] == 0)
- {
+
+ if (value1[1] == 0 && value1[0] == 0) {
yaw = 0;
if (value1[2] > 0)
pitch = 90;
else
pitch = 270;
- }
- else
- {
- // PMM - fixed to correct for pitch of 0
+ } else {
+ // PMM - fixed to correct for pitch of 0
if (value1[0])
yaw = (atan2(value1[1], value1[0]) * 180 / M_PI);
else if (value1[1] > 0)
@@ -54,7 +51,7 @@ static void vectoangles2 (vec3_t value1, vec3_t angles)
if (yaw < 0)
yaw += 360;
- forward = sqrt (value1[0]*value1[0] + value1[1]*value1[1]);
+ forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
pitch = (atan2(value1[2], forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
@@ -68,12 +65,12 @@ static void vectoangles2 (vec3_t value1, vec3_t angles)
//=============
//=============
#if USE_DLIGHTS
-void CL_Flashlight (int ent, vec3_t pos)
+void CL_Flashlight(int ent, vec3_t pos)
{
cdlight_t *dl;
- dl = CL_AllocDlight (ent);
- VectorCopy (pos, dl->origin);
+ dl = CL_AllocDlight(ent);
+ VectorCopy(pos, dl->origin);
dl->radius = 400;
//dl->minlight = 250;
dl->die = cl.time + 100;
@@ -87,12 +84,12 @@ void CL_Flashlight (int ent, vec3_t pos)
CL_ColorFlash - flash of light
======
*/
-void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b)
+void CL_ColorFlash(vec3_t pos, int ent, int intensity, float r, float g, float b)
{
cdlight_t *dl;
- dl = CL_AllocDlight (ent);
- VectorCopy (pos, dl->origin);
+ dl = CL_AllocDlight(ent);
+ VectorCopy(pos, dl->origin);
dl->radius = intensity;
//dl->minlight = 250;
dl->die = cl.time + 100;
@@ -108,7 +105,7 @@ void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float
CL_DebugTrail
======
*/
-void CL_DebugTrail (vec3_t start, vec3_t end)
+void CL_DebugTrail(vec3_t start, vec3_t end)
{
vec3_t move;
vec3_t vec;
@@ -121,22 +118,21 @@ void CL_DebugTrail (vec3_t start, vec3_t end)
// float d, c, s;
// vec3_t dir;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
- MakeNormalVectors (vec, right, up);
+ MakeNormalVectors(vec, right, up);
// VectorScale(vec, RT2_SKIP, vec);
// dec = 1.0;
// dec = 0.75;
dec = 3;
- VectorScale (vec, dec, vec);
- VectorCopy (start, move);
+ VectorScale(vec, dec, vec);
+ VectorCopy(start, move);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
@@ -144,22 +140,22 @@ void CL_DebugTrail (vec3_t start, vec3_t end)
return;
p->time = cl.time;
- VectorClear (p->accel);
- VectorClear (p->vel);
+ VectorClear(p->accel);
+ VectorClear(p->vel);
p->alpha = 1.0;
p->alphavel = -0.1;
// p->alphavel = 0;
- p->color = 0x74 + (rand()&7);
- VectorCopy (move, p->org);
-/*
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*2;
- p->vel[j] = crand()*3;
- p->accel[j] = 0;
- }
-*/
- VectorAdd (move, vec, move);
+ p->color = 0x74 + (rand() & 7);
+ VectorCopy(move, p->org);
+ /*
+ for (j=0; j<3; j++)
+ {
+ p->org[j] = move[j] + crand()*2;
+ p->vel[j] = crand()*3;
+ p->accel[j] = 0;
+ }
+ */
+ VectorAdd(move, vec, move);
}
}
@@ -169,7 +165,7 @@ void CL_DebugTrail (vec3_t start, vec3_t end)
CL_SmokeTrail
===============
*/
-void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing)
+void CL_SmokeTrail(vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing)
{
vec3_t move;
vec3_t vec;
@@ -177,39 +173,37 @@ void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int
int j;
cparticle_t *p;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
- VectorScale (vec, spacing, vec);
+ VectorScale(vec, spacing, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= spacing;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.5);
+ p->alphavel = -1.0 / (1 + frand() * 0.5);
p->color = colorStart + (rand() % colorRun);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*3;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 3;
p->accel[j] = 0;
}
- p->vel[2] = 20 + crand()*5;
+ p->vel[2] = 20 + crand() * 5;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
-void CL_ForceWall (vec3_t start, vec3_t end, int color)
+void CL_ForceWall(vec3_t start, vec3_t end, int color)
{
vec3_t move;
vec3_t vec;
@@ -217,40 +211,37 @@ void CL_ForceWall (vec3_t start, vec3_t end, int color)
int j;
cparticle_t *p;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
- VectorScale (vec, 4, vec);
+ VectorScale(vec, 4, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= 4;
- if (frand() > 0.3)
- {
+ if (frand() > 0.3) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (3.0+frand()*0.5);
+ p->alphavel = -1.0 / (3.0 + frand() * 0.5);
p->color = color;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*3;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 3;
p->accel[j] = 0;
}
p->vel[0] = 0;
p->vel[1] = 0;
- p->vel[2] = -40 - (crand()*10);
+ p->vel[2] = -40 - (crand() * 10);
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -260,14 +251,13 @@ void CL_ForceWall (vec3_t start, vec3_t end, int color)
CL_GenericParticleEffect
===============
*/
-void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel)
+void CL_GenericParticleEffect(vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel)
{
int i, j;
cparticle_t *p;
float d;
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -279,10 +269,9 @@ void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int
p->color = color;
d = rand() & dirspread;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = crand()*20;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = crand() * 20;
}
p->accel[0] = p->accel[1] = 0;
@@ -290,7 +279,7 @@ void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int
// VectorCopy (accel, p->accel);
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*alphavel);
+ p->alphavel = -1.0 / (0.5 + frand() * alphavel);
// p->alphavel = alphavel;
}
}
@@ -301,7 +290,7 @@ CL_BubbleTrail2 (lets you control the # of bubbles by setting the distance betwe
===============
*/
-void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist)
+void CL_BubbleTrail2(vec3_t start, vec3_t end, int dist)
{
vec3_t move;
vec3_t vec;
@@ -310,39 +299,37 @@ void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist)
cparticle_t *p;
float dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = dist;
- VectorScale (vec, dec, vec);
+ VectorScale(vec, dec, vec);
- for (i=0 ; i<len ; i+=dec)
- {
+ for (i = 0; i < len; i += dec) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
+ VectorClear(p->accel);
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (1+frand()*0.1);
- p->color = 4 + (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*2;
- p->vel[j] = crand()*10;
+ p->alphavel = -1.0 / (1 + frand() * 0.1);
+ p->color = 4 + (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 2;
+ p->vel[j] = crand() * 10;
}
p->org[2] -= 4;
// p->vel[2] += 6;
p->vel[2] += 20;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
-void CL_Heatbeam (vec3_t start, vec3_t forward)
+void CL_Heatbeam(vec3_t start, vec3_t forward)
{
vec3_t move;
vec3_t vec;
@@ -360,79 +347,74 @@ void CL_Heatbeam (vec3_t start, vec3_t forward)
float variance;
vec3_t end;
- VectorMA (start, 4096, forward, end);
+ VectorMA(start, 4096, forward, end);
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
// FIXME - pmm - these might end up using old values?
// MakeNormalVectors (vec, right, up);
- VectorCopy (cl.v_right, right);
- VectorCopy (cl.v_up, up);
+ VectorCopy(cl.v_right, right);
+ VectorCopy(cl.v_up, up);
#if USE_REF == REF_GL
- { // GL mode
- VectorMA (move, -0.5, right, move);
- VectorMA (move, -0.5, up, move);
+ {
+ // GL mode
+ VectorMA(move, -0.5, right, move);
+ VectorMA(move, -0.5, up, move);
}
#endif
// otherwise assume SOFT
- ltime = (float) cl.time/1000.0;
- start_pt = fmod(ltime*96.0,step);
- VectorMA (move, start_pt, vec, move);
+ ltime = (float) cl.time / 1000.0;
+ start_pt = fmod(ltime * 96.0, step);
+ VectorMA(move, start_pt, vec, move);
- VectorScale (vec, step, vec);
+ VectorScale(vec, step, vec);
// Com_Printf ("%f\n", ltime);
- rstep = M_PI/10.0;
- for (i=start_pt ; i<len ; i+=step)
- {
- if (i>step*5) // don't bother after the 5th ring
+ rstep = M_PI / 10.0;
+ for (i = start_pt; i < len; i += step) {
+ if (i > step * 5) // don't bother after the 5th ring
break;
- for (rot = 0; rot < M_PI*2; rot += rstep)
- {
+ for (rot = 0; rot < M_PI * 2; rot += rstep) {
p = CL_AllocParticle();
if (!p)
return;
-
+
p->time = cl.time;
- VectorClear (p->accel);
+ VectorClear(p->accel);
// rot+= fmod(ltime, 12.0)*M_PI;
// c = cos(rot)/2.0;
// s = sin(rot)/2.0;
// variance = 0.4 + ((float)rand()/(float)RAND_MAX) *0.2;
variance = 0.5;
- c = cos(rot)*variance;
- s = sin(rot)*variance;
-
+ c = cos(rot) * variance;
+ s = sin(rot) * variance;
+
// trim it so it looks like it's starting at the origin
- if (i < 10)
- {
- VectorScale (right, c*(i/10.0), dir);
- VectorMA (dir, s*(i/10.0), up, dir);
+ if (i < 10) {
+ VectorScale(right, c * (i / 10.0), dir);
+ VectorMA(dir, s * (i / 10.0), up, dir);
+ } else {
+ VectorScale(right, c, dir);
+ VectorMA(dir, s, up, dir);
}
- else
- {
- VectorScale (right, c, dir);
- VectorMA (dir, s, up, dir);
- }
-
+
p->alpha = 0.5;
- // p->alphavel = -1.0 / (1+frand()*0.2);
+ // p->alphavel = -1.0 / (1+frand()*0.2);
p->alphavel = -1000.0;
- // p->color = 0x74 + (rand()&7);
- p->color = 223 - (rand()&7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + dir[j]*3;
- // p->vel[j] = dir[j]*6;
+ // p->color = 0x74 + (rand()&7);
+ p->color = 223 - (rand() & 7);
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + dir[j] * 3;
+ // p->vel[j] = dir[j]*6;
p->vel[j] = 0;
}
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -444,7 +426,7 @@ CL_ParticleSteamEffect
Puffs with velocity along direction, with some randomness thrown in
===============
*/
-void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude)
+void CL_ParticleSteamEffect(vec3_t org, vec3_t dir, int color, int count, int magnitude)
{
int i, j;
cparticle_t *p;
@@ -454,37 +436,35 @@ void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int m
// vectoangles2 (dir, angle_dir);
// AngleVectors (angle_dir, f, r, u);
- MakeNormalVectors (dir, r, u);
+ MakeNormalVectors(dir, r, u);
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = color + (rand()&7);
+ p->color = color + (rand() & 7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + magnitude*0.1*crand();
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + magnitude * 0.1 * crand();
// p->vel[j] = dir[j]*magnitude;
}
- VectorScale (dir, magnitude, p->vel);
- d = crand()*magnitude/3;
- VectorMA (p->vel, d, r, p->vel);
- d = crand()*magnitude/3;
- VectorMA (p->vel, d, u, p->vel);
+ VectorScale(dir, magnitude, p->vel);
+ d = crand() * magnitude / 3;
+ VectorMA(p->vel, d, r, p->vel);
+ d = crand() * magnitude / 3;
+ VectorMA(p->vel, d, u, p->vel);
p->accel[0] = p->accel[1] = 0;
- p->accel[2] = -PARTICLE_GRAVITY/2;
+ p->accel[2] = -PARTICLE_GRAVITY / 2;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
-void CL_ParticleSteamEffect2 (cl_sustain_t *self)
+void CL_ParticleSteamEffect2(cl_sustain_t *self)
//vec3_t org, vec3_t dir, int color, int count, int magnitude)
{
int i, j;
@@ -496,34 +476,32 @@ void CL_ParticleSteamEffect2 (cl_sustain_t *self)
// vectoangles2 (dir, angle_dir);
// AngleVectors (angle_dir, f, r, u);
- VectorCopy (self->dir, dir);
- MakeNormalVectors (dir, r, u);
+ VectorCopy(self->dir, dir);
+ MakeNormalVectors(dir, r, u);
- for (i=0 ; i<self->count ; i++)
- {
+ for (i = 0; i < self->count; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = self->color + (rand()&7);
+ p->color = self->color + (rand() & 7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = self->org[j] + self->magnitude*0.1*crand();
+ for (j = 0; j < 3; j++) {
+ p->org[j] = self->org[j] + self->magnitude * 0.1 * crand();
// p->vel[j] = dir[j]*magnitude;
}
- VectorScale (dir, self->magnitude, p->vel);
- d = crand()*self->magnitude/3;
- VectorMA (p->vel, d, r, p->vel);
- d = crand()*self->magnitude/3;
- VectorMA (p->vel, d, u, p->vel);
+ VectorScale(dir, self->magnitude, p->vel);
+ d = crand() * self->magnitude / 3;
+ VectorMA(p->vel, d, r, p->vel);
+ d = crand() * self->magnitude / 3;
+ VectorMA(p->vel, d, u, p->vel);
p->accel[0] = p->accel[1] = 0;
- p->accel[2] = -PARTICLE_GRAVITY/2;
+ p->accel[2] = -PARTICLE_GRAVITY / 2;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
self->nextthink += self->thinkinterval;
}
@@ -533,38 +511,37 @@ void CL_ParticleSteamEffect2 (cl_sustain_t *self)
CL_TrackerTrail
===============
*/
-void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor)
+void CL_TrackerTrail(vec3_t start, vec3_t end, int particleColor)
{
vec3_t move;
vec3_t vec;
- vec3_t forward,right,up,angle_dir;
+ vec3_t forward, right, up, angle_dir;
float len;
int j;
cparticle_t *p;
int dec;
float dist;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
VectorCopy(vec, forward);
- vectoangles2 (forward, angle_dir);
- AngleVectors (angle_dir, forward, right, up);
+ vectoangles2(forward, angle_dir);
+ AngleVectors(angle_dir, forward, right, up);
dec = 3;
- VectorScale (vec, 3, vec);
+ VectorScale(vec, 3, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
@@ -572,15 +549,14 @@ void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor)
p->color = particleColor;
dist = DotProduct(move, forward);
VectorMA(move, 8 * cos(dist), up, p->org);
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
// p->org[j] = move[j] + crand();
p->vel[j] = 0;
p->accel[j] = 0;
}
p->vel[2] = 5;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -590,13 +566,12 @@ void CL_Tracker_Shell(vec3_t origin)
int i;
cparticle_t *p;
- for(i=0;i<300;i++)
- {
+ for (i = 0; i < 300; i++) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
@@ -607,7 +582,7 @@ void CL_Tracker_Shell(vec3_t origin)
dir[1] = crand();
dir[2] = crand();
VectorNormalize(dir);
-
+
VectorMA(origin, 40, dir, p->org);
}
}
@@ -618,13 +593,12 @@ void CL_MonsterPlasma_Shell(vec3_t origin)
int i;
cparticle_t *p;
- for(i=0;i<40;i++)
- {
+ for (i = 0; i < 40; i++) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
@@ -635,46 +609,45 @@ void CL_MonsterPlasma_Shell(vec3_t origin)
dir[1] = crand();
dir[2] = crand();
VectorNormalize(dir);
-
+
VectorMA(origin, 10, dir, p->org);
// VectorMA(origin, 10*(((rand () & 0x7fff) / ((float)0x7fff))), dir, p->org);
}
}
-void CL_Widowbeamout (cl_sustain_t *self)
+void CL_Widowbeamout(cl_sustain_t *self)
{
vec3_t dir;
int i;
cparticle_t *p;
- static int colortable[4] = {2*8,13*8,21*8,18*8};
+ static int colortable[4] = {2 * 8, 13 * 8, 21 * 8, 18 * 8};
float ratio;
- ratio = 1.0 - (((float)self->endtime - (float)cl.time)/2100.0);
+ ratio = 1.0 - (((float)self->endtime - (float)cl.time) / 2100.0);
- for(i=0;i<300;i++)
- {
+ for (i = 0; i < 300; i++) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
p->alphavel = INSTANT_PARTICLE;
- p->color = colortable[rand()&3];
+ p->color = colortable[rand() & 3];
dir[0] = crand();
dir[1] = crand();
dir[2] = crand();
VectorNormalize(dir);
-
+
VectorMA(self->org, (45.0 * ratio), dir, p->org);
// VectorMA(origin, 10*(((rand () & 0x7fff) / ((float)0x7fff))), dir, p->org);
}
}
-void CL_Nukeblast (cl_sustain_t *self)
+void CL_Nukeblast(cl_sustain_t *self)
{
vec3_t dir;
int i;
@@ -682,46 +655,44 @@ void CL_Nukeblast (cl_sustain_t *self)
static int colortable[4] = {110, 112, 114, 116};
float ratio;
- ratio = 1.0 - (((float)self->endtime - (float)cl.time)/1000.0);
+ ratio = 1.0 - (((float)self->endtime - (float)cl.time) / 1000.0);
- for(i=0;i<700;i++)
- {
+ for (i = 0; i < 700; i++) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
p->alphavel = INSTANT_PARTICLE;
- p->color = colortable[rand()&3];
+ p->color = colortable[rand() & 3];
dir[0] = crand();
dir[1] = crand();
dir[2] = crand();
VectorNormalize(dir);
-
+
VectorMA(self->org, (200.0 * ratio), dir, p->org);
// VectorMA(origin, 10*(((rand () & 0x7fff) / ((float)0x7fff))), dir, p->org);
}
}
-void CL_WidowSplash (void)
+void CL_WidowSplash(void)
{
- static int colortable[4] = {2*8,13*8,21*8,18*8};
+ static int colortable[4] = {2 * 8, 13 * 8, 21 * 8, 18 * 8};
int i;
cparticle_t *p;
vec3_t dir;
- for (i=0 ; i<256 ; i++)
- {
+ for (i = 0; i < 256; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = colortable[rand()&3];
+ p->color = colortable[rand() & 3];
dir[0] = crand();
dir[1] = crand();
@@ -733,7 +704,7 @@ void CL_WidowSplash (void)
p->accel[0] = p->accel[1] = 0;
p->alpha = 1.0;
- p->alphavel = -0.8 / (0.5 + frand()*0.3);
+ p->alphavel = -0.8 / (0.5 + frand() * 0.3);
}
}
@@ -744,13 +715,12 @@ void CL_Tracker_Explode(vec3_t origin)
int i;
cparticle_t *p;
- for(i=0;i<300;i++)
- {
+ for (i = 0; i < 300; i++) {
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
@@ -762,11 +732,11 @@ void CL_Tracker_Explode(vec3_t origin)
dir[2] = crand();
VectorNormalize(dir);
VectorScale(dir, -1, backdir);
-
+
VectorMA(origin, 64, dir, p->org);
VectorScale(backdir, 64, p->vel);
}
-
+
}
/*
@@ -775,7 +745,7 @@ CL_TagTrail
===============
*/
-void CL_TagTrail (vec3_t start, vec3_t end, int color)
+void CL_TagTrail(vec3_t start, vec3_t end, int color)
{
vec3_t move;
vec3_t vec;
@@ -784,35 +754,33 @@ void CL_TagTrail (vec3_t start, vec3_t end, int color)
cparticle_t *p;
int dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
- while (len >= 0)
- {
+ while (len >= 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.8+frand()*0.2);
+ p->alphavel = -1.0 / (0.8 + frand() * 0.2);
p->color = color;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = move[j] + crand()*16;
- p->vel[j] = crand()*5;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = move[j] + crand() * 16;
+ p->vel[j] = crand() * 5;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -821,13 +789,12 @@ void CL_TagTrail (vec3_t start, vec3_t end, int color)
CL_ColorExplosionParticles
===============
*/
-void CL_ColorExplosionParticles (vec3_t org, int color, int run)
+void CL_ColorExplosionParticles(vec3_t org, int color, int run)
{
int i, j;
cparticle_t *p;
- for (i=0 ; i<128 ; i++)
- {
+ for (i = 0; i < 128; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -835,17 +802,16 @@ void CL_ColorExplosionParticles (vec3_t org, int color, int run)
p->time = cl.time;
p->color = color + (rand() % run);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()%32)-16);
- p->vel[j] = (rand()%256)-128;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() % 32) - 16);
+ p->vel[j] = (rand() % 256) - 128;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -0.4 / (0.6 + frand()*0.2);
+ p->alphavel = -0.4 / (0.6 + frand() * 0.2);
}
}
@@ -854,39 +820,37 @@ void CL_ColorExplosionParticles (vec3_t org, int color, int run)
CL_ParticleSmokeEffect - like the steam effect, but unaffected by gravity
===============
*/
-void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude)
+void CL_ParticleSmokeEffect(vec3_t org, vec3_t dir, int color, int count, int magnitude)
{
int i, j;
cparticle_t *p;
float d;
vec3_t r, u;
- MakeNormalVectors (dir, r, u);
+ MakeNormalVectors(dir, r, u);
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = color + (rand()&7);
+ p->color = color + (rand() & 7);
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + magnitude*0.1*crand();
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + magnitude * 0.1 * crand();
// p->vel[j] = dir[j]*magnitude;
}
- VectorScale (dir, magnitude, p->vel);
- d = crand()*magnitude/3;
- VectorMA (p->vel, d, r, p->vel);
- d = crand()*magnitude/3;
- VectorMA (p->vel, d, u, p->vel);
+ VectorScale(dir, magnitude, p->vel);
+ d = crand() * magnitude / 3;
+ VectorMA(p->vel, d, r, p->vel);
+ d = crand() * magnitude / 3;
+ VectorMA(p->vel, d, u, p->vel);
p->accel[0] = p->accel[1] = p->accel[2] = 0;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
@@ -897,7 +861,7 @@ CL_BlasterParticles2
Wall impact puffs (Green)
===============
*/
-void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color)
+void CL_BlasterParticles2(vec3_t org, vec3_t dir, unsigned int color)
{
int i, j;
cparticle_t *p;
@@ -905,27 +869,25 @@ void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color)
int count;
count = 40;
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
p->time = cl.time;
- p->color = color + (rand()&7);
+ p->color = color + (rand() & 7);
- d = rand()&15;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = dir[j] * 30 + crand()*40;
+ d = rand() & 15;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = dir[j] * 30 + crand() * 40;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = -PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
@@ -936,7 +898,7 @@ CL_BlasterTrail2
Green!
===============
*/
-void CL_BlasterTrail2 (vec3_t start, vec3_t end)
+void CL_BlasterTrail2(vec3_t start, vec3_t end)
{
vec3_t move;
vec3_t vec;
@@ -945,36 +907,34 @@ void CL_BlasterTrail2 (vec3_t start, vec3_t end)
cparticle_t *p;
int dec;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.3+frand()*0.2);
+ p->alphavel = -1.0 / (0.3 + frand() * 0.2);
p->color = 0xd0;
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
p->org[j] = move[j] + crand();
- p->vel[j] = crand()*5;
+ p->vel[j] = crand() * 5;
p->accel[j] = 0;
}
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -984,7 +944,7 @@ void CL_BlasterTrail2 (vec3_t start, vec3_t end)
CL_IonripperTrail
===============
*/
-void CL_IonripperTrail (vec3_t start, vec3_t ent)
+void CL_IonripperTrail(vec3_t start, vec3_t ent)
{
vec3_t move;
vec3_t vec;
@@ -994,39 +954,34 @@ void CL_IonripperTrail (vec3_t start, vec3_t ent)
int dec;
int left = 0;
- VectorCopy (start, move);
- VectorSubtract (ent, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(ent, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
+ VectorClear(p->accel);
p->time = cl.time;
p->alpha = 0.5;
p->alphavel = -1.0 / (0.3 + frand() * 0.2);
- p->color = 0xe4 + (rand()&3);
+ p->color = 0xe4 + (rand() & 3);
- for (j=0; j<3; j++)
- {
+ for (j = 0; j < 3; j++) {
p->org[j] = move[j];
p->accel[j] = 0;
}
- if (left)
- {
+ if (left) {
left = 0;
p->vel[0] = 10;
- }
- else
- {
+ } else {
left = 1;
p->vel[0] = -10;
}
@@ -1034,7 +989,7 @@ void CL_IonripperTrail (vec3_t start, vec3_t ent)
p->vel[1] = 0;
p->vel[2] = 0;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
}
@@ -1044,7 +999,7 @@ CL_TrapParticles
===============
*/
// RAFAEL
-void CL_TrapParticles (entity_t *ent)
+void CL_TrapParticles(entity_t *ent)
{
vec3_t move;
vec3_t vec;
@@ -1054,87 +1009,80 @@ void CL_TrapParticles (entity_t *ent)
cparticle_t *p;
int dec;
- ent->origin[2]-=14;
- VectorCopy (ent->origin, start);
- VectorCopy (ent->origin, end);
- end[2]+=64;
+ ent->origin[2] -= 14;
+ VectorCopy(ent->origin, start);
+ VectorCopy(ent->origin, end);
+ end[2] += 64;
- VectorCopy (start, move);
- VectorSubtract (end, start, vec);
- len = VectorNormalize (vec);
+ VectorCopy(start, move);
+ VectorSubtract(end, start, vec);
+ len = VectorNormalize(vec);
dec = 5;
- VectorScale (vec, 5, vec);
+ VectorScale(vec, 5, vec);
// FIXME: this is a really silly way to have a loop
- while (len > 0)
- {
+ while (len > 0) {
len -= dec;
p = CL_AllocParticle();
if (!p)
return;
- VectorClear (p->accel);
-
+ VectorClear(p->accel);
+
p->time = cl.time;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.3+frand()*0.2);
+ p->alphavel = -1.0 / (0.3 + frand() * 0.2);
p->color = 0xe0;
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
p->org[j] = move[j] + crand();
- p->vel[j] = crand()*15;
+ p->vel[j] = crand() * 15;
p->accel[j] = 0;
}
p->accel[2] = PARTICLE_GRAVITY;
- VectorAdd (move, vec, move);
+ VectorAdd(move, vec, move);
}
{
-
-
- int i, j, k;
- cparticle_t *p;
- float vel;
- vec3_t dir;
- vec3_t org;
-
-
- ent->origin[2]+=14;
- VectorCopy (ent->origin, org);
-
-
- for (i=-2 ; i<=2 ; i+=4)
- for (j=-2 ; j<=2 ; j+=4)
- for (k=-2 ; k<=4 ; k+=4)
- {
- p = CL_AllocParticle();
- if (!p)
- return;
-
- p->time = cl.time;
- p->color = 0xe0 + (rand()&3);
-
- p->alpha = 1.0;
- p->alphavel = -1.0 / (0.3 + (rand()&7) * 0.02);
-
- p->org[0] = org[0] + i + ((rand()&23) * crand());
- p->org[1] = org[1] + j + ((rand()&23) * crand());
- p->org[2] = org[2] + k + ((rand()&23) * crand());
-
- dir[0] = j * 8;
- dir[1] = i * 8;
- dir[2] = k * 8;
-
- VectorNormalize (dir);
- vel = 50 + (rand()&63);
- VectorScale (dir, vel, p->vel);
-
- p->accel[0] = p->accel[1] = 0;
- p->accel[2] = -PARTICLE_GRAVITY;
- }
+ int i, j, k;
+ cparticle_t *p;
+ float vel;
+ vec3_t dir;
+ vec3_t org;
+
+ ent->origin[2] += 14;
+ VectorCopy(ent->origin, org);
+
+ for (i = -2; i <= 2; i += 4)
+ for (j = -2; j <= 2; j += 4)
+ for (k = -2; k <= 4; k += 4) {
+ p = CL_AllocParticle();
+ if (!p)
+ return;
+
+ p->time = cl.time;
+ p->color = 0xe0 + (rand() & 3);
+
+ p->alpha = 1.0;
+ p->alphavel = -1.0 / (0.3 + (rand() & 7) * 0.02);
+
+ p->org[0] = org[0] + i + ((rand() & 23) * crand());
+ p->org[1] = org[1] + j + ((rand() & 23) * crand());
+ p->org[2] = org[2] + k + ((rand() & 23) * crand());
+
+ dir[0] = j * 8;
+ dir[1] = i * 8;
+ dir[2] = k * 8;
+
+ VectorNormalize(dir);
+ vel = 50 + (rand() & 63);
+ VectorScale(dir, vel, p->vel);
+
+ p->accel[0] = p->accel[1] = 0;
+ p->accel[2] = -PARTICLE_GRAVITY;
+ }
}
}
@@ -1144,14 +1092,13 @@ void CL_TrapParticles (entity_t *ent)
CL_ParticleEffect3
===============
*/
-void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count)
+void CL_ParticleEffect3(vec3_t org, vec3_t dir, int color, int count)
{
int i, j;
cparticle_t *p;
float d;
- for (i=0 ; i<count ; i++)
- {
+ for (i = 0; i < count; i++) {
p = CL_AllocParticle();
if (!p)
return;
@@ -1159,18 +1106,17 @@ void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count)
p->time = cl.time;
p->color = color;
- d = rand()&7;
- for (j=0 ; j<3 ; j++)
- {
- p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
- p->vel[j] = crand()*20;
+ d = rand() & 7;
+ for (j = 0; j < 3; j++) {
+ p->org[j] = org[j] + ((rand() & 7) - 4) + d * dir[j];
+ p->vel[j] = crand() * 20;
}
p->accel[0] = p->accel[1] = 0;
p->accel[2] = PARTICLE_GRAVITY;
p->alpha = 1.0;
- p->alphavel = -1.0 / (0.5 + frand()*0.3);
+ p->alphavel = -1.0 / (0.5 + frand() * 0.3);
}
}
diff --git a/src/cl_null.c b/src/cl_null.c
index 30aebbf..43575fc 100644
--- a/src/cl_null.c
+++ b/src/cl_null.c
@@ -24,20 +24,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "common.h"
#include "files.h"
-qboolean CL_CheatsOK( void ) {
+qboolean CL_CheatsOK(void)
+{
// developer option
- if( Cvar_VariableInteger( "cheats" ) ) {
+ if (Cvar_VariableInteger("cheats")) {
return qtrue;
}
return qfalse;
}
-static void Key_Bind_Null_f( void ) {
+static void Key_Bind_Null_f(void)
+{
}
-void Key_Init( void ) {
- Cmd_AddCommand( "bind", Key_Bind_Null_f );
- Cmd_AddCommand( "unbind", Key_Bind_Null_f );
- Cmd_AddCommand( "unbindall", Key_Bind_Null_f );
+void Key_Init(void)
+{
+ Cmd_AddCommand("bind", Key_Bind_Null_f);
+ Cmd_AddCommand("unbind", Key_Bind_Null_f);
+ Cmd_AddCommand("unbindall", Key_Bind_Null_f);
}
diff --git a/src/cl_parse.c b/src/cl_parse.c
index f26a69f..6902e31 100644
--- a/src/cl_parse.c
+++ b/src/cl_parse.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,15 +29,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=====================================================================
*/
-static inline void CL_ParseDeltaEntity( server_frame_t *frame,
- int newnum,
- entity_state_t *old,
- int bits )
+static inline void CL_ParseDeltaEntity(server_frame_t *frame,
+ int newnum,
+ entity_state_t *old,
+ int bits)
{
entity_state_t *state;
- if( frame->numEntities >= MAX_PACKET_ENTITIES ) {
- Com_Error( ERR_DROP, "%s: MAX_PACKET_ENTITIES exceeded", __func__ );
+ if (frame->numEntities >= MAX_PACKET_ENTITIES) {
+ Com_Error(ERR_DROP, "%s: MAX_PACKET_ENTITIES exceeded", __func__);
}
state = &cl.entityStates[cl.numEntityStates & PARSE_ENTITIES_MASK];
@@ -45,21 +45,21 @@ static inline void CL_ParseDeltaEntity( server_frame_t *frame,
frame->numEntities++;
#ifdef _DEBUG
- if( cl_shownet->integer > 2 && bits ) {
- MSG_ShowDeltaEntityBits( bits );
- Com_LPrintf( PRINT_DEVELOPER, "\n" );
+ if (cl_shownet->integer > 2 && bits) {
+ MSG_ShowDeltaEntityBits(bits);
+ Com_LPrintf(PRINT_DEVELOPER, "\n");
}
#endif
- MSG_ParseDeltaEntity( old, state, newnum, bits, cl.esFlags );
+ MSG_ParseDeltaEntity(old, state, newnum, bits, cl.esFlags);
// shuffle previous origin to old
- if( !(bits & U_OLDORIGIN) && !(state->renderfx & RF_BEAM) )
- VectorCopy( old->origin, state->old_origin );
+ if (!(bits & U_OLDORIGIN) && !(state->renderfx & RF_BEAM))
+ VectorCopy(old->origin, state->old_origin);
}
-static void CL_ParsePacketEntities( server_frame_t *oldframe,
- server_frame_t *frame )
+static void CL_ParsePacketEntities(server_frame_t *oldframe,
+ server_frame_t *frame)
{
int newnum;
int bits;
@@ -73,10 +73,10 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
// delta from the entities present in oldframe
oldindex = 0;
oldstate = NULL;
- if( !oldframe ) {
+ if (!oldframe) {
oldnum = 99999;
} else {
- if( oldindex >= oldframe->numEntities ) {
+ if (oldindex >= oldframe->numEntities) {
oldnum = 99999;
} else {
i = oldframe->firstEntity + oldindex;
@@ -85,28 +85,28 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
}
}
- while( 1 ) {
- newnum = MSG_ParseEntityBits( &bits );
- if( newnum < 0 || newnum >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad number: %d", __func__, newnum );
+ while (1) {
+ newnum = MSG_ParseEntityBits(&bits);
+ if (newnum < 0 || newnum >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad number: %d", __func__, newnum);
}
- if( msg_read.readcount > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (msg_read.readcount > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
}
- if( !newnum ) {
+ if (!newnum) {
break;
}
- while( oldnum < newnum ) {
+ while (oldnum < newnum) {
// one or more entities from the old packet are unchanged
- SHOWNET( 3, " unchanged: %i\n", oldnum );
- CL_ParseDeltaEntity( frame, oldnum, oldstate, 0 );
-
+ SHOWNET(3, " unchanged: %i\n", oldnum);
+ CL_ParseDeltaEntity(frame, oldnum, oldstate, 0);
+
oldindex++;
- if( oldindex >= oldframe->numEntities ) {
+ if (oldindex >= oldframe->numEntities) {
oldnum = 99999;
} else {
i = oldframe->firstEntity + oldindex;
@@ -115,19 +115,19 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
}
}
- if( bits & U_REMOVE ) {
+ if (bits & U_REMOVE) {
// the entity present in oldframe is not in the current frame
- SHOWNET( 2, " remove: %i\n", newnum );
- if( oldnum != newnum ) {
- Com_DPrintf( "U_REMOVE: oldnum != newnum\n" );
+ SHOWNET(2, " remove: %i\n", newnum);
+ if (oldnum != newnum) {
+ Com_DPrintf("U_REMOVE: oldnum != newnum\n");
}
- if( !oldframe ) {
- Com_Error( ERR_DROP, "U_REMOVE: NULL oldframe" );
+ if (!oldframe) {
+ Com_Error(ERR_DROP, "U_REMOVE: NULL oldframe");
}
oldindex++;
- if( oldindex >= oldframe->numEntities ) {
+ if (oldindex >= oldframe->numEntities) {
oldnum = 99999;
} else {
i = oldframe->firstEntity + oldindex;
@@ -137,17 +137,17 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
continue;
}
- if( oldnum == newnum ) {
+ if (oldnum == newnum) {
// delta from previous state
- SHOWNET( 2, " delta: %i ", newnum );
- CL_ParseDeltaEntity( frame, newnum, oldstate, bits );
- if( !bits ) {
- SHOWNET( 2, "\n" );
+ SHOWNET(2, " delta: %i ", newnum);
+ CL_ParseDeltaEntity(frame, newnum, oldstate, bits);
+ if (!bits) {
+ SHOWNET(2, "\n");
}
oldindex++;
- if( oldindex >= oldframe->numEntities ) {
+ if (oldindex >= oldframe->numEntities) {
oldnum = 99999;
} else {
i = oldframe->firstEntity + oldindex;
@@ -157,12 +157,12 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
continue;
}
- if( oldnum > newnum ) {
+ if (oldnum > newnum) {
// delta from baseline
- SHOWNET( 2, " baseline: %i ", newnum );
- CL_ParseDeltaEntity( frame, newnum, &cl.baselines[newnum], bits );
- if( !bits ) {
- SHOWNET( 2, "\n" );
+ SHOWNET(2, " baseline: %i ", newnum);
+ CL_ParseDeltaEntity(frame, newnum, &cl.baselines[newnum], bits);
+ if (!bits) {
+ SHOWNET(2, "\n");
}
continue;
}
@@ -170,14 +170,14 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
}
// any remaining entities in the old frame are copied over
- while( oldnum != 99999 ) {
+ while (oldnum != 99999) {
// one or more entities from the old packet are unchanged
- SHOWNET( 3, " unchanged: %i\n", oldnum );
- CL_ParseDeltaEntity( frame, oldnum, oldstate, 0 );
-
+ SHOWNET(3, " unchanged: %i\n", oldnum);
+ CL_ParseDeltaEntity(frame, oldnum, oldstate, 0);
+
oldindex++;
- if( oldindex >= oldframe->numEntities ) {
+ if (oldindex >= oldframe->numEntities) {
oldnum = 99999;
} else {
i = oldframe->firstEntity + oldindex;
@@ -187,27 +187,28 @@ static void CL_ParsePacketEntities( server_frame_t *oldframe,
}
}
-static void CL_ParseFrame( int extrabits ) {
+static void CL_ParseFrame(int extrabits)
+{
uint32_t bits, extraflags;
int currentframe, deltaframe,
delta, surpressed;
server_frame_t frame, *oldframe;
player_state_t *from;
int length;
-
- memset( &frame, 0, sizeof( frame ) );
+
+ memset(&frame, 0, sizeof(frame));
cl.frameflags = 0;
surpressed = 0;
extraflags = 0;
- if( cls.serverProtocol > PROTOCOL_VERSION_DEFAULT ) {
+ if (cls.serverProtocol > PROTOCOL_VERSION_DEFAULT) {
bits = MSG_ReadLong();
currentframe = bits & FRAMENUM_MASK;
delta = bits >> FRAMENUM_BITS;
- if( delta == 31 ) {
+ if (delta == 31) {
deltaframe = -1;
} else {
deltaframe = currentframe - delta;
@@ -216,24 +217,24 @@ static void CL_ParseFrame( int extrabits ) {
bits = MSG_ReadByte();
surpressed = bits & SURPRESSCOUNT_MASK;
- if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
- if( surpressed & FF_CLIENTPRED ) {
+ if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO) {
+ if (surpressed & FF_CLIENTPRED) {
// CLIENTDROP is implied, don't draw both
surpressed &= ~FF_CLIENTDROP;
}
cl.frameflags |= surpressed;
- } else if( surpressed ) {
+ } else if (surpressed) {
cl.frameflags |= FF_SURPRESSED;
}
- extraflags = ( extrabits << 4 ) | ( bits >> SURPRESSCOUNT_BITS );
+ extraflags = (extrabits << 4) | (bits >> SURPRESSCOUNT_BITS);
} else {
currentframe = MSG_ReadLong();
deltaframe = MSG_ReadLong();
// BIG HACK to let old demos continue to work
- if( cls.serverProtocol != PROTOCOL_VERSION_OLD ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_OLD) {
surpressed = MSG_ReadByte();
- if( surpressed ) {
+ if (surpressed) {
cl.frameflags |= FF_SURPRESSED;
}
}
@@ -242,39 +243,38 @@ static void CL_ParseFrame( int extrabits ) {
frame.number = currentframe;
frame.delta = deltaframe;
- if( cls.netchan && cls.netchan->dropped ) {
+ if (cls.netchan && cls.netchan->dropped) {
cl.frameflags |= FF_SERVERDROP;
}
// if the frame is delta compressed from data that we no longer have
// available, we must suck up the rest of the frame, but not use it, then
// ask for a non-compressed message
- if( deltaframe > 0 ) {
+ if (deltaframe > 0) {
oldframe = &cl.frames[deltaframe & UPDATE_MASK];
from = &oldframe->ps;
- if( deltaframe == currentframe ) {
+ if (deltaframe == currentframe) {
// old servers may cause this on map change
- Com_DPrintf( "%s: delta from current frame\n", __func__ );
+ Com_DPrintf("%s: delta from current frame\n", __func__);
cl.frameflags |= FF_BADFRAME;
- } else if( oldframe->number != deltaframe ) {
+ } else if (oldframe->number != deltaframe) {
// the frame that the server did the delta from
// is too old, so we can't reconstruct it properly.
- Com_DPrintf( "%s: delta frame was never received or too old\n", __func__ );
+ Com_DPrintf("%s: delta frame was never received or too old\n", __func__);
cl.frameflags |= FF_OLDFRAME;
- } else if( !oldframe->valid ) {
+ } else if (!oldframe->valid) {
// should never happen
- Com_DPrintf( "%s: delta from invalid frame\n", __func__ );
+ Com_DPrintf("%s: delta from invalid frame\n", __func__);
cl.frameflags |= FF_BADFRAME;
- } else if( cl.numEntityStates - oldframe->firstEntity >
- MAX_PARSE_ENTITIES - MAX_PACKET_ENTITIES )
- {
- Com_DPrintf( "%s: delta entities too old\n", __func__ );
+ } else if (cl.numEntityStates - oldframe->firstEntity >
+ MAX_PARSE_ENTITIES - MAX_PACKET_ENTITIES) {
+ Com_DPrintf("%s: delta entities too old\n", __func__);
cl.frameflags |= FF_OLDENT;
} else {
frame.valid = qtrue; // valid delta parse
}
- if( !frame.valid && cl.frame.valid && cls.demo.playback ) {
- Com_DPrintf( "%s: recovering broken demo\n", __func__ );
+ if (!frame.valid && cl.frame.valid && cls.demo.playback) {
+ Com_DPrintf("%s: recovering broken demo\n", __func__);
oldframe = &cl.frame;
from = &oldframe->ps;
frame.valid = qtrue;
@@ -288,86 +288,86 @@ static void CL_ParseFrame( int extrabits ) {
// read areabits
length = MSG_ReadByte();
- if( length ) {
- if( length < 0 || msg_read.readcount + length > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (length) {
+ if (length < 0 || msg_read.readcount + length > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
}
- if( length > sizeof( frame.areabits ) ) {
- Com_Error( ERR_DROP, "%s: invalid areabits length", __func__ );
+ if (length > sizeof(frame.areabits)) {
+ Com_Error(ERR_DROP, "%s: invalid areabits length", __func__);
}
- memcpy( frame.areabits, msg_read.data + msg_read.readcount, length );
+ memcpy(frame.areabits, msg_read.data + msg_read.readcount, length);
msg_read.readcount += length;
frame.areabytes = length;
} else {
frame.areabytes = 0;
}
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
- if( MSG_ReadByte() != svc_playerinfo ) {
- Com_Error( ERR_DROP, "%s: not playerinfo", __func__ );
+ if (cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT) {
+ if (MSG_ReadByte() != svc_playerinfo) {
+ Com_Error(ERR_DROP, "%s: not playerinfo", __func__);
}
}
- SHOWNET( 2, "%3"PRIz":playerinfo\n", msg_read.readcount - 1 );
+ SHOWNET(2, "%3"PRIz":playerinfo\n", msg_read.readcount - 1);
// parse playerstate
bits = MSG_ReadShort();
- if( cls.serverProtocol > PROTOCOL_VERSION_DEFAULT ) {
- MSG_ParseDeltaPlayerstate_Enhanced( from, &frame.ps, bits, extraflags );
+ if (cls.serverProtocol > PROTOCOL_VERSION_DEFAULT) {
+ MSG_ParseDeltaPlayerstate_Enhanced(from, &frame.ps, bits, extraflags);
#ifdef _DEBUG
- if( cl_shownet->integer > 2 ) {
- MSG_ShowDeltaPlayerstateBits_Enhanced( bits );
- Com_LPrintf( PRINT_DEVELOPER, "\n" );
+ if (cl_shownet->integer > 2) {
+ MSG_ShowDeltaPlayerstateBits_Enhanced(bits);
+ Com_LPrintf(PRINT_DEVELOPER, "\n");
}
#endif
- if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO) {
// parse clientNum
- if( extraflags & EPS_CLIENTNUM ) {
+ if (extraflags & EPS_CLIENTNUM) {
frame.clientNum = MSG_ReadByte();
- } else if( oldframe ) {
+ } else if (oldframe) {
frame.clientNum = oldframe->clientNum;
}
} else {
frame.clientNum = cl.clientNum;
}
} else {
- MSG_ParseDeltaPlayerstate_Default( from, &frame.ps, bits );
+ MSG_ParseDeltaPlayerstate_Default(from, &frame.ps, bits);
#ifdef _DEBUG
- if( cl_shownet->integer > 2 ) {
- MSG_ShowDeltaPlayerstateBits_Default( bits );
- Com_LPrintf( PRINT_DEVELOPER, "\n" );
+ if (cl_shownet->integer > 2) {
+ MSG_ShowDeltaPlayerstateBits_Default(bits);
+ Com_LPrintf(PRINT_DEVELOPER, "\n");
}
#endif
frame.clientNum = cl.clientNum;
}
// parse packetentities
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
- if( MSG_ReadByte() != svc_packetentities ) {
- Com_Error( ERR_DROP, "%s: not packetentities", __func__ );
+ if (cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT) {
+ if (MSG_ReadByte() != svc_packetentities) {
+ Com_Error(ERR_DROP, "%s: not packetentities", __func__);
}
}
- SHOWNET( 2, "%3"PRIz":packetentities\n", msg_read.readcount - 1 );
+ SHOWNET(2, "%3"PRIz":packetentities\n", msg_read.readcount - 1);
- CL_ParsePacketEntities( oldframe, &frame );
+ CL_ParsePacketEntities(oldframe, &frame);
// save the frame off in the backup array for later delta comparisons
cl.frames[currentframe & UPDATE_MASK] = frame;
#ifdef _DEBUG
- if( cl_shownet->integer > 2 ) {
+ if (cl_shownet->integer > 2) {
int rtt = 0;
- if( cls.netchan ) {
+ if (cls.netchan) {
int seq = cls.netchan->incoming_acknowledged & CMD_MASK;
rtt = cls.realtime - cl.history[seq].sent;
}
- Com_LPrintf( PRINT_DEVELOPER, "%3"PRIz":frame:%d delta:%d rtt:%d\n",
- msg_read.readcount - 1, frame.number, frame.delta, rtt );
+ Com_LPrintf(PRINT_DEVELOPER, "%3"PRIz":frame:%d delta:%d rtt:%d\n",
+ msg_read.readcount - 1, frame.number, frame.delta, rtt);
}
#endif
- if( !frame.valid ) {
+ if (!frame.valid) {
cl.frame.valid = qfalse;
#if USE_FPS
cl.keyframe.valid = qfalse;
@@ -375,19 +375,19 @@ static void CL_ParseFrame( int extrabits ) {
return; // do not change anything
}
- if( !frame.ps.fov ) {
+ if (!frame.ps.fov) {
// fail out early to prevent spurious errors later
- Com_Error( ERR_DROP, "%s: bad fov", __func__ );
+ Com_Error(ERR_DROP, "%s: bad fov", __func__);
}
- if( cls.state < ca_precached )
+ if (cls.state < ca_precached)
return;
cl.oldframe = cl.frame;
cl.frame = frame;
#if USE_FPS
- if( CL_FRAMESYNC ) {
+ if (CL_FRAMESYNC) {
cl.oldkeyframe = cl.keyframe;
cl.keyframe = cl.frame;
}
@@ -395,7 +395,7 @@ static void CL_ParseFrame( int extrabits ) {
cls.demo.frames_read++;
- if( !cls.demo.seeking )
+ if (!cls.demo.seeking)
CL_DeltaFrame();
}
@@ -407,82 +407,86 @@ static void CL_ParseFrame( int extrabits ) {
=====================================================================
*/
-static void CL_ParseConfigstring( int index ) {
+static void CL_ParseConfigstring(int index)
+{
size_t len, maxlen;
char *s;
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- Com_Error( ERR_DROP, "%s: bad index: %d", __func__, index );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ Com_Error(ERR_DROP, "%s: bad index: %d", __func__, index);
}
s = cl.configstrings[index];
- maxlen = CS_SIZE( index );
- len = MSG_ReadString( s, maxlen );
+ maxlen = CS_SIZE(index);
+ len = MSG_ReadString(s, maxlen);
- SHOWNET( 2, " %d \"%s\"\n", index, s );
+ SHOWNET(2, " %d \"%s\"\n", index, s);
- if( len >= maxlen ) {
+ if (len >= maxlen) {
Com_WPrintf(
"%s: index %d overflowed: %"PRIz" > %"PRIz"\n",
- __func__, index, len, maxlen - 1 );
- len = maxlen - 1;
+ __func__, index, len, maxlen - 1);
+ len = maxlen - 1;
}
- if( cls.demo.seeking ) {
- Q_SetBit( cl.dcs, index );
+ if (cls.demo.seeking) {
+ Q_SetBit(cl.dcs, index);
return;
}
- if( cls.demo.recording && cls.demo.paused ) {
- Q_SetBit( cl.dcs, index );
+ if (cls.demo.recording && cls.demo.paused) {
+ Q_SetBit(cl.dcs, index);
}
- // do something apropriate
- CL_UpdateConfigstring( index );
+ // do something apropriate
+ CL_UpdateConfigstring(index);
}
-static void CL_ParseBaseline( int index, int bits ) {
- if( index < 1 || index >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad index: %d", __func__, index );
+static void CL_ParseBaseline(int index, int bits)
+{
+ if (index < 1 || index >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad index: %d", __func__, index);
}
#ifdef _DEBUG
- if( cl_shownet->integer > 2 ) {
- MSG_ShowDeltaEntityBits( bits );
- Com_LPrintf( PRINT_DEVELOPER, "\n" );
+ if (cl_shownet->integer > 2) {
+ MSG_ShowDeltaEntityBits(bits);
+ Com_LPrintf(PRINT_DEVELOPER, "\n");
}
#endif
- MSG_ParseDeltaEntity( NULL, &cl.baselines[index], index, bits, cl.esFlags );
+ MSG_ParseDeltaEntity(NULL, &cl.baselines[index], index, bits, cl.esFlags);
}
// instead of wasting space for svc_configstring and svc_spawnbaseline
// bytes, entire game state is compressed into a single stream.
-static void CL_ParseGamestate( void ) {
+static void CL_ParseGamestate(void)
+{
int index, bits;
- while( msg_read.readcount < msg_read.cursize ) {
+ while (msg_read.readcount < msg_read.cursize) {
index = MSG_ReadShort();
- if( index == MAX_CONFIGSTRINGS ) {
+ if (index == MAX_CONFIGSTRINGS) {
break;
}
- CL_ParseConfigstring( index );
+ CL_ParseConfigstring(index);
}
- while( msg_read.readcount < msg_read.cursize ) {
- index = MSG_ParseEntityBits( &bits );
- if( !index ) {
+ while (msg_read.readcount < msg_read.cursize) {
+ index = MSG_ParseEntityBits(&bits);
+ if (!index) {
break;
}
- CL_ParseBaseline( index, bits );
+ CL_ParseBaseline(index, bits);
}
}
-static void CL_ParseServerData( void ) {
+static void CL_ParseServerData(void)
+{
char levelname[MAX_QPATH];
int i, protocol, attractloop;
size_t len;
- Cbuf_Execute( &cl_cmdbuf ); // make sure any stuffed commands are done
-
+ Cbuf_Execute(&cl_cmdbuf); // make sure any stuffed commands are done
+
// wipe the client_state_t struct
CL_ClearState();
@@ -491,37 +495,37 @@ static void CL_ParseServerData( void ) {
cl.servercount = MSG_ReadLong();
attractloop = MSG_ReadByte();
- Com_DPrintf( "Serverdata packet received "
- "(protocol=%d, servercount=%d, attractloop=%d)\n",
- protocol, cl.servercount, attractloop );
+ Com_DPrintf("Serverdata packet received "
+ "(protocol=%d, servercount=%d, attractloop=%d)\n",
+ protocol, cl.servercount, attractloop);
// check protocol
- if( cls.serverProtocol != protocol ) {
- if( !cls.demo.playback ) {
- Com_Error( ERR_DROP, "Requested protocol version %d, but server returned %d.",
- cls.serverProtocol, protocol );
+ if (cls.serverProtocol != protocol) {
+ if (!cls.demo.playback) {
+ Com_Error(ERR_DROP, "Requested protocol version %d, but server returned %d.",
+ cls.serverProtocol, protocol);
}
// BIG HACK to let demos from release work with the 3.0x patch!!!
- if( protocol < PROTOCOL_VERSION_OLD || protocol > PROTOCOL_VERSION_Q2PRO ) {
- Com_Error( ERR_DROP, "Demo uses unsupported protocol version %d.", protocol );
+ if (protocol < PROTOCOL_VERSION_OLD || protocol > PROTOCOL_VERSION_Q2PRO) {
+ Com_Error(ERR_DROP, "Demo uses unsupported protocol version %d.", protocol);
}
cls.serverProtocol = protocol;
}
// game directory
- len = MSG_ReadString( cl.gamedir, sizeof( cl.gamedir ) );
- if( len >= sizeof( cl.gamedir ) ) {
- Com_Error( ERR_DROP, "Oversize gamedir string" );
+ len = MSG_ReadString(cl.gamedir, sizeof(cl.gamedir));
+ if (len >= sizeof(cl.gamedir)) {
+ Com_Error(ERR_DROP, "Oversize gamedir string");
}
// never allow demos to change gamedir
// do not change gamedir if connected to local sever either,
// as it was already done by SV_InitGame, and changing it
// here will not work since server is now running
- if( !cls.demo.playback && !sv_running->integer ) {
+ if (!cls.demo.playback && !sv_running->integer) {
// pretend it has been set by user, so that 'changed' hook
// gets called and filesystem is restarted
- Cvar_UserSet( "game", cl.gamedir );
+ Cvar_UserSet("game", cl.gamedir);
// protect it from modifications while we are connected
fs_game->flags |= CVAR_ROM;
@@ -531,10 +535,10 @@ static void CL_ParseServerData( void ) {
cl.clientNum = MSG_ReadShort();
// get the full level name
- MSG_ReadString( levelname, sizeof( levelname ) );
+ MSG_ReadString(levelname, sizeof(levelname));
// setup default pmove parameters
- PmoveInit( &cl.pmp );
+ PmoveInit(&cl.pmp);
#if USE_FPS
// setup default frame times
@@ -543,80 +547,80 @@ static void CL_ParseServerData( void ) {
cl.framediv = 1;
#endif
- if( cls.serverProtocol == PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.serverProtocol == PROTOCOL_VERSION_R1Q2) {
i = MSG_ReadByte();
- if( i ) {
- Com_Error( ERR_DROP, "'Enhanced' R1Q2 servers are not supported" );
+ if (i) {
+ Com_Error(ERR_DROP, "'Enhanced' R1Q2 servers are not supported");
}
i = MSG_ReadShort();
// for some reason, R1Q2 servers always report the highest protocol
// version they support, while still using the lower version
// client specified in the 'connect' packet. oh well...
- if( !R1Q2_SUPPORTED( i ) ) {
+ if (!R1Q2_SUPPORTED(i)) {
Com_WPrintf(
"R1Q2 server reports unsupported protocol version %d.\n"
"Assuming it really uses our current client version %d.\n"
- "Things will break if it does not!\n", i, PROTOCOL_VERSION_R1Q2_CURRENT );
- clamp( i, PROTOCOL_VERSION_R1Q2_MINIMUM, PROTOCOL_VERSION_R1Q2_CURRENT );
+ "Things will break if it does not!\n", i, PROTOCOL_VERSION_R1Q2_CURRENT);
+ clamp(i, PROTOCOL_VERSION_R1Q2_MINIMUM, PROTOCOL_VERSION_R1Q2_CURRENT);
}
- Com_DPrintf( "Using minor R1Q2 protocol version %d\n", i );
+ Com_DPrintf("Using minor R1Q2 protocol version %d\n", i);
cls.protocolVersion = i;
MSG_ReadByte(); // used to be advanced deltas
i = MSG_ReadByte();
- if( i ) {
- Com_DPrintf( "R1Q2 strafejump hack enabled\n" );
+ if (i) {
+ Com_DPrintf("R1Q2 strafejump hack enabled\n");
cl.pmp.strafehack = qtrue;
}
cl.esFlags |= MSG_ES_BEAMORIGIN;
- if( cls.protocolVersion >= PROTOCOL_VERSION_R1Q2_LONG_SOLID ) {
+ if (cls.protocolVersion >= PROTOCOL_VERSION_R1Q2_LONG_SOLID) {
cl.esFlags |= MSG_ES_LONGSOLID;
}
cl.pmp.speedmult = 2;
- } else if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
+ } else if (cls.serverProtocol == PROTOCOL_VERSION_Q2PRO) {
i = MSG_ReadShort();
- if( !Q2PRO_SUPPORTED( i ) ) {
- Com_Error( ERR_DROP,
- "Q2PRO server reports unsupported protocol version %d.\n"
- "Current client version is %d.", i, PROTOCOL_VERSION_Q2PRO_CURRENT );
+ if (!Q2PRO_SUPPORTED(i)) {
+ Com_Error(ERR_DROP,
+ "Q2PRO server reports unsupported protocol version %d.\n"
+ "Current client version is %d.", i, PROTOCOL_VERSION_Q2PRO_CURRENT);
}
- Com_DPrintf( "Using minor Q2PRO protocol version %d\n", i );
+ Com_DPrintf("Using minor Q2PRO protocol version %d\n", i);
cls.protocolVersion = i;
MSG_ReadByte(); // used to be gametype
i = MSG_ReadByte();
- if( i ) {
- Com_DPrintf( "Q2PRO strafejump hack enabled\n" );
+ if (i) {
+ Com_DPrintf("Q2PRO strafejump hack enabled\n");
cl.pmp.strafehack = qtrue;
}
i = MSG_ReadByte(); //atu QWMod
- if( i ) {
- Com_DPrintf( "Q2PRO QW mode enabled\n" );
- PmoveEnableQW( &cl.pmp );
+ if (i) {
+ Com_DPrintf("Q2PRO QW mode enabled\n");
+ PmoveEnableQW(&cl.pmp);
}
cl.esFlags |= MSG_ES_UMASK;
- if( cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID ) {
+ if (cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID) {
cl.esFlags |= MSG_ES_LONGSOLID;
}
- if( cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN ) {
+ if (cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN) {
cl.esFlags |= MSG_ES_BEAMORIGIN;
}
- if( cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_SHORT_ANGLES ) {
+ if (cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_SHORT_ANGLES) {
cl.esFlags |= MSG_ES_SHORTANGLES;
}
- if( cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK ) {
+ if (cls.protocolVersion >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK) {
i = MSG_ReadByte();
- if( i ) {
- Com_DPrintf( "Q2PRO waterjump hack enabled\n" );
+ if (i) {
+ Com_DPrintf("Q2PRO waterjump hack enabled\n");
cl.pmp.waterhack = qtrue;
}
}
- cl.pmp.speedmult = 2;
+ cl.pmp.speedmult = 2;
cl.pmp.flyhack = qtrue; // fly hack is unconditionally enabled
cl.pmp.flyfriction = 4;
}
- if( cl.clientNum == -1 ) {
+ if (cl.clientNum == -1) {
// tell the server to advance to the next map / cinematic
- CL_ClientCommand( va( "nextserver %i\n", cl.servercount ) );
+ CL_ClientCommand(va("nextserver %i\n", cl.servercount));
} else {
// seperate the printfs so the server message can have a color
Con_Printf(
@@ -624,14 +628,14 @@ static void CL_ParseServerData( void ) {
"\35\36\36\36\36\36\36\36\36\36\36\36"
"\36\36\36\36\36\36\36\36\36\36\36\36"
"\36\36\36\36\36\36\36\36\36\36\36\37"
- "\n\n" );
+ "\n\n");
- Com_SetColor( COLOR_ALT );
- Com_Printf( "%s\n", levelname );
- Com_SetColor( COLOR_NONE );
+ Com_SetColor(COLOR_ALT);
+ Com_Printf("%s\n", levelname);
+ Com_SetColor(COLOR_NONE);
// make sure clientNum is in range
- if( cl.clientNum < 0 || cl.clientNum >= MAX_CLIENTS ) {
+ if (cl.clientNum < 0 || cl.clientNum >= MAX_CLIENTS) {
cl.clientNum = CLIENTNUM_NONE;
}
}
@@ -649,10 +653,11 @@ tent_params_t te;
mz_params_t mz;
snd_params_t snd;
-static void CL_ParseTEntPacket( void ) {
+static void CL_ParseTEntPacket(void)
+{
te.type = MSG_ReadByte();
- switch( te.type ) {
+ switch (te.type) {
case TE_BLOOD:
case TE_GUNSHOT:
case TE_SPARKS:
@@ -668,8 +673,8 @@ static void CL_ParseTEntPacket( void ) {
case TE_HEATBEAM_STEAM:
case TE_MOREBLOOD:
case TE_ELECTRIC_SPARKS:
- MSG_ReadPos( te.pos1 );
- MSG_ReadDir( te.dir );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadDir(te.dir);
break;
case TE_SPLASH:
@@ -677,8 +682,8 @@ static void CL_ParseTEntPacket( void ) {
case TE_WELDING_SPARKS:
case TE_TUNNEL_SPARKS:
te.count = MSG_ReadByte();
- MSG_ReadPos( te.pos1 );
- MSG_ReadDir( te.dir );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadDir(te.dir);
te.color = MSG_ReadByte();
break;
@@ -688,8 +693,8 @@ static void CL_ParseTEntPacket( void ) {
case TE_DEBUGTRAIL:
case TE_BUBBLETRAIL2:
case TE_BFG_LASER:
- MSG_ReadPos( te.pos1 );
- MSG_ReadPos( te.pos2 );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadPos(te.pos2);
break;
case TE_GRENADE_EXPLOSION:
@@ -711,7 +716,7 @@ static void CL_ParseTEntPacket( void ) {
case TE_DBALL_GOAL:
case TE_WIDOWSPLASH:
case TE_NUKEBLAST:
- MSG_ReadPos( te.pos1 );
+ MSG_ReadPos(te.pos1);
break;
case TE_PARASITE_ATTACK:
@@ -719,63 +724,64 @@ static void CL_ParseTEntPacket( void ) {
case TE_HEATBEAM:
case TE_MONSTER_HEATBEAM:
te.entity1 = MSG_ReadShort();
- MSG_ReadPos( te.pos1 );
- MSG_ReadPos( te.pos2 );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadPos(te.pos2);
break;
case TE_GRAPPLE_CABLE:
te.entity1 = MSG_ReadShort();
- MSG_ReadPos( te.pos1 );
- MSG_ReadPos( te.pos2 );
- MSG_ReadPos( te.offset );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadPos(te.pos2);
+ MSG_ReadPos(te.offset);
break;
case TE_LIGHTNING:
te.entity1 = MSG_ReadShort();
te.entity2 = MSG_ReadShort();
- MSG_ReadPos( te.pos1 );
- MSG_ReadPos( te.pos2 );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadPos(te.pos2);
break;
case TE_FLASHLIGHT:
- MSG_ReadPos( te.pos1 );
+ MSG_ReadPos(te.pos1);
te.entity1 = MSG_ReadShort();
break;
case TE_FORCEWALL:
- MSG_ReadPos( te.pos1 );
- MSG_ReadPos( te.pos2 );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadPos(te.pos2);
te.color = MSG_ReadByte();
break;
case TE_STEAM:
te.entity1 = MSG_ReadShort();
te.count = MSG_ReadByte();
- MSG_ReadPos( te.pos1 );
- MSG_ReadDir( te.dir );
+ MSG_ReadPos(te.pos1);
+ MSG_ReadDir(te.dir);
te.color = MSG_ReadByte();
te.entity2 = MSG_ReadShort();
- if( te.entity1 != -1 ) {
+ if (te.entity1 != -1) {
te.time = MSG_ReadLong();
}
break;
case TE_WIDOWBEAMOUT:
te.entity1 = MSG_ReadShort();
- MSG_ReadPos( te.pos1 );
+ MSG_ReadPos(te.pos1);
break;
default:
- Com_Error( ERR_DROP, "%s: bad type", __func__ );
+ Com_Error(ERR_DROP, "%s: bad type", __func__);
}
}
-static void CL_ParseMuzzleFlashPacket( int mask ) {
+static void CL_ParseMuzzleFlashPacket(int mask)
+{
int entity, weapon;
entity = MSG_ReadShort();
- if( entity < 1 || entity >= MAX_EDICTS )
- Com_Error( ERR_DROP, "%s: bad entity", __func__ );
+ if (entity < 1 || entity >= MAX_EDICTS)
+ Com_Error(ERR_DROP, "%s: bad entity", __func__);
weapon = MSG_ReadByte();
mz.silenced = weapon & mask;
@@ -783,38 +789,39 @@ static void CL_ParseMuzzleFlashPacket( int mask ) {
mz.entity = entity;
}
-static void CL_ParseStartSoundPacket( void ) {
+static void CL_ParseStartSoundPacket(void)
+{
int flags, channel, entity;
flags = MSG_ReadByte();
- if( ( flags & (SND_ENT|SND_POS) ) == 0 )
- Com_Error( ERR_DROP, "%s: neither SND_ENT nor SND_POS set", __func__ );
+ if ((flags & (SND_ENT | SND_POS)) == 0)
+ Com_Error(ERR_DROP, "%s: neither SND_ENT nor SND_POS set", __func__);
snd.index = MSG_ReadByte();
- if( snd.index == -1 )
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (snd.index == -1)
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
- if( flags & SND_VOLUME )
+ if (flags & SND_VOLUME)
snd.volume = MSG_ReadByte() / 255.0f;
else
snd.volume = DEFAULT_SOUND_PACKET_VOLUME;
-
- if( flags & SND_ATTENUATION )
+
+ if (flags & SND_ATTENUATION)
snd.attenuation = MSG_ReadByte() / 64.0f;
else
snd.attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
- if( flags & SND_OFFSET )
+ if (flags & SND_OFFSET)
snd.timeofs = MSG_ReadByte() / 1000.0f;
else
snd.timeofs = 0;
- if( flags & SND_ENT ) {
+ if (flags & SND_ENT) {
// entity relative
- channel = MSG_ReadShort();
+ channel = MSG_ReadShort();
entity = channel >> 3;
- if( entity < 0 || entity >= MAX_EDICTS )
- Com_Error( ERR_DROP, "%s: bad entity: %d", __func__, entity );
+ if (entity < 0 || entity >= MAX_EDICTS)
+ Com_Error(ERR_DROP, "%s: bad entity: %d", __func__, entity);
snd.entity = entity;
snd.channel = channel & 7;
} else {
@@ -823,29 +830,30 @@ static void CL_ParseStartSoundPacket( void ) {
}
// positioned in space
- if( flags & SND_POS )
- MSG_ReadPos( snd.pos );
+ if (flags & SND_POS)
+ MSG_ReadPos(snd.pos);
snd.flags = flags;
- SHOWNET( 2, " %s\n", cl.configstrings[ CS_SOUNDS + snd.index ] );
+ SHOWNET(2, " %s\n", cl.configstrings[CS_SOUNDS + snd.index]);
}
-static void CL_ParseReconnect( void ) {
- if( cls.demo.playback ) {
- Com_Error( ERR_DISCONNECT, "Server disconnected" );
+static void CL_ParseReconnect(void)
+{
+ if (cls.demo.playback) {
+ Com_Error(ERR_DISCONNECT, "Server disconnected");
}
- Com_Printf( "Server disconnected, reconnecting\n" );
+ Com_Printf("Server disconnected, reconnecting\n");
// free netchan now to prevent `disconnect'
// message from being sent to server
- if( cls.netchan ) {
- Netchan_Close( cls.netchan );
+ if (cls.netchan) {
+ Netchan_Close(cls.netchan);
cls.netchan = NULL;
}
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
cls.state = ca_challenging;
cls.connect_time -= CONNECT_FAST;
@@ -855,42 +863,43 @@ static void CL_ParseReconnect( void ) {
}
#if USE_AUTOREPLY
-static void CL_CheckForVersion( const char *s ) {
+static void CL_CheckForVersion(const char *s)
+{
char *p;
- p = strstr( s, ": " );
- if( !p ) {
+ p = strstr(s, ": ");
+ if (!p) {
return;
}
- if( strncmp( p + 2, "!version", 8 ) ) {
+ if (strncmp(p + 2, "!version", 8)) {
return;
}
- if( cl.reply_time && cls.realtime - cl.reply_time < 120000 ) {
+ if (cl.reply_time && cls.realtime - cl.reply_time < 120000) {
return;
}
cl.reply_time = cls.realtime;
- cl.reply_delta = 1024 + ( rand() & 1023 );
+ cl.reply_delta = 1024 + (rand() & 1023);
}
#endif
// attempt to scan out an IP address in dotted-quad notation and
// add it into circular array of recent addresses
-static void CL_CheckForIP( const char *s ) {
+static void CL_CheckForIP(const char *s)
+{
unsigned b1, b2, b3, b4, port;
netadr_t *a;
char *p;
- while( *s ) {
- if( sscanf( s, "%3u.%3u.%3u.%3u", &b1, &b2, &b3, &b4 ) == 4 &&
- b1 < 256 && b2 < 256 && b3 < 256 && b4 < 256 )
- {
- p = strchr( s, ':' );
- if( p ) {
- port = strtoul( p + 1, NULL, 10 );
- if( port < 1024 || port > 65535 ) {
+ while (*s) {
+ if (sscanf(s, "%3u.%3u.%3u.%3u", &b1, &b2, &b3, &b4) == 4 &&
+ b1 < 256 && b2 < 256 && b3 < 256 && b4 < 256) {
+ p = strchr(s, ':');
+ if (p) {
+ port = strtoul(p + 1, NULL, 10);
+ if (port < 1024 || port > 65535) {
break; // privileged or invalid port
}
} else {
@@ -903,7 +912,7 @@ static void CL_CheckForIP( const char *s ) {
a->ip.u8[1] = b2;
a->ip.u8[2] = b3;
a->ip.u8[3] = b4;
- a->port = BigShort( port );
+ a->port = BigShort(port);
break;
}
@@ -911,208 +920,217 @@ static void CL_CheckForIP( const char *s ) {
}
}
-static void CL_ParsePrint( void ) {
+static void CL_ParsePrint(void)
+{
int level;
char s[MAX_STRING_CHARS];
const char *fmt;
level = MSG_ReadByte();
- MSG_ReadString( s, sizeof( s ) );
+ MSG_ReadString(s, sizeof(s));
- SHOWNET( 2, " %i \"%s\"\n", level, s );
+ SHOWNET(2, " %i \"%s\"\n", level, s);
- if( level != PRINT_CHAT ) {
- Com_Printf( "%s", s );
- if( !cls.demo.playback ) {
- COM_strclr( s );
- Cmd_ExecTrigger( s );
+ if (level != PRINT_CHAT) {
+ Com_Printf("%s", s);
+ if (!cls.demo.playback) {
+ COM_strclr(s);
+ Cmd_ExecTrigger(s);
}
return;
}
- if( CL_CheckForIgnore( s ) ) {
+ if (CL_CheckForIgnore(s)) {
return;
}
#if USE_AUTOREPLY
- if( !cls.demo.playback ) {
- CL_CheckForVersion( s );
+ if (!cls.demo.playback) {
+ CL_CheckForVersion(s);
}
#endif
- CL_CheckForIP( s );
+ CL_CheckForIP(s);
// disable notify
- if( !cl_chat_notify->integer ) {
- Con_SkipNotify( qtrue );
+ if (!cl_chat_notify->integer) {
+ Con_SkipNotify(qtrue);
}
// filter text
- if( cl_chat_filter->integer ) {
- COM_strclr( s );
+ if (cl_chat_filter->integer) {
+ COM_strclr(s);
fmt = "%s\n";
} else {
fmt = "%s";
}
- Com_LPrintf( PRINT_TALK, fmt, s );
+ Com_LPrintf(PRINT_TALK, fmt, s);
- Con_SkipNotify( qfalse );
+ Con_SkipNotify(qfalse);
#if USE_CHATHUD
- SCR_AddToChatHUD( s );
+ SCR_AddToChatHUD(s);
#endif
// play sound
- if( cl_chat_sound->integer > 1 )
- S_StartLocalSound_( "misc/talk1.wav" );
- else if( cl_chat_sound->integer > 0 )
- S_StartLocalSound_( "misc/talk.wav" );
+ if (cl_chat_sound->integer > 1)
+ S_StartLocalSound_("misc/talk1.wav");
+ else if (cl_chat_sound->integer > 0)
+ S_StartLocalSound_("misc/talk.wav");
}
-static void CL_ParseCenterPrint( void ) {
+static void CL_ParseCenterPrint(void)
+{
char s[MAX_STRING_CHARS];
- MSG_ReadString( s, sizeof( s ) );
- SHOWNET( 2, " \"%s\"\n", s );
- SCR_CenterPrint( s );
+ MSG_ReadString(s, sizeof(s));
+ SHOWNET(2, " \"%s\"\n", s);
+ SCR_CenterPrint(s);
- if( !cls.demo.playback ) {
- COM_strclr( s );
- Cmd_ExecTrigger( s );
+ if (!cls.demo.playback) {
+ COM_strclr(s);
+ Cmd_ExecTrigger(s);
}
}
-static void CL_ParseStuffText( void ) {
+static void CL_ParseStuffText(void)
+{
char s[MAX_STRING_CHARS];
- MSG_ReadString( s, sizeof( s ) );
- SHOWNET( 2, " \"%s\"\n", s );
- Cbuf_AddText( &cl_cmdbuf, s );
+ MSG_ReadString(s, sizeof(s));
+ SHOWNET(2, " \"%s\"\n", s);
+ Cbuf_AddText(&cl_cmdbuf, s);
}
-static void CL_ParseLayout( void ) {
- MSG_ReadString( cl.layout, sizeof( cl.layout ) );
- SHOWNET( 2, " \"%s\"\n", cl.layout );
+static void CL_ParseLayout(void)
+{
+ MSG_ReadString(cl.layout, sizeof(cl.layout));
+ SHOWNET(2, " \"%s\"\n", cl.layout);
cl.putaway = qfalse;
}
-static void CL_ParseInventory( void ) {
+static void CL_ParseInventory(void)
+{
int i;
- for( i = 0; i < MAX_ITEMS; i++ ) {
+ for (i = 0; i < MAX_ITEMS; i++) {
cl.inventory[i] = MSG_ReadShort();
}
cl.putaway = qfalse;
}
-static void CL_ParseDownload( void ) {
+static void CL_ParseDownload(void)
+{
int size, percent;
byte *data;
- if( !cls.download.temp[0] ) {
- Com_Error( ERR_DROP, "%s: no download requested", __func__ );
+ if (!cls.download.temp[0]) {
+ Com_Error(ERR_DROP, "%s: no download requested", __func__);
}
// read the data
size = MSG_ReadShort();
percent = MSG_ReadByte();
- if( size == -1 ) {
- CL_HandleDownload( NULL, size, percent );
+ if (size == -1) {
+ CL_HandleDownload(NULL, size, percent);
return;
}
- if( size < 0 ) {
- Com_Error( ERR_DROP, "%s: bad size: %d", __func__, size );
+ if (size < 0) {
+ Com_Error(ERR_DROP, "%s: bad size: %d", __func__, size);
}
- if( msg_read.readcount + size > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (msg_read.readcount + size > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
}
data = msg_read.data + msg_read.readcount;
msg_read.readcount += size;
- CL_HandleDownload( data, size, percent );
+ CL_HandleDownload(data, size, percent);
}
-static void CL_ParseZPacket( void ) {
+static void CL_ParseZPacket(void)
+{
#if USE_ZLIB
sizebuf_t temp;
byte buffer[MAX_MSGLEN];
int inlen, outlen;
- if( msg_read.data != msg_read_buffer ) {
- Com_Error( ERR_DROP, "%s: recursively entered", __func__ );
+ if (msg_read.data != msg_read_buffer) {
+ Com_Error(ERR_DROP, "%s: recursively entered", __func__);
}
inlen = MSG_ReadWord();
outlen = MSG_ReadWord();
- if( inlen == -1 || outlen == -1 || msg_read.readcount + inlen > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (inlen == -1 || outlen == -1 || msg_read.readcount + inlen > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
}
- if( outlen > MAX_MSGLEN ) {
- Com_Error( ERR_DROP, "%s: invalid output length", __func__ );
+ if (outlen > MAX_MSGLEN) {
+ Com_Error(ERR_DROP, "%s: invalid output length", __func__);
}
- inflateReset( &cls.z );
+ inflateReset(&cls.z);
cls.z.next_in = msg_read.data + msg_read.readcount;
- cls.z.avail_in = ( uInt )inlen;
+ cls.z.avail_in = (uInt)inlen;
cls.z.next_out = buffer;
- cls.z.avail_out = ( uInt )outlen;
- if( inflate( &cls.z, Z_FINISH ) != Z_STREAM_END ) {
- Com_Error( ERR_DROP, "%s: inflate() failed: %s", __func__, cls.z.msg );
+ cls.z.avail_out = (uInt)outlen;
+ if (inflate(&cls.z, Z_FINISH) != Z_STREAM_END) {
+ Com_Error(ERR_DROP, "%s: inflate() failed: %s", __func__, cls.z.msg);
}
msg_read.readcount += inlen;
temp = msg_read;
- SZ_Init( &msg_read, buffer, outlen );
+ SZ_Init(&msg_read, buffer, outlen);
msg_read.cursize = outlen;
CL_ParseServerMessage();
msg_read = temp;
#else
- Com_Error( ERR_DROP, "Compressed server packet received, "
- "but no zlib support linked in." );
+ Com_Error(ERR_DROP, "Compressed server packet received, "
+ "but no zlib support linked in.");
#endif
}
#if USE_FPS
-static void set_server_fps( int value ) {
+static void set_server_fps(int value)
+{
int framediv = value / BASE_FRAMERATE;
- clamp( framediv, 1, MAX_FRAMEDIV );
+ clamp(framediv, 1, MAX_FRAMEDIV);
cl.frametime = BASE_FRAMETIME / framediv;
cl.frametime_inv = framediv * BASE_1_FRAMETIME;
cl.framediv = framediv;
// fix time delta
- if( cls.state == ca_active ) {
+ if (cls.state == ca_active) {
int delta = cl.frame.number - cl.servertime / cl.frametime;
- cl.serverdelta = Q_align( delta, framediv );
+ cl.serverdelta = Q_align(delta, framediv);
}
- Com_DPrintf( "client framediv=%d time=%d delta=%d\n",
- framediv, cl.servertime, cl.serverdelta );
+ Com_DPrintf("client framediv=%d time=%d delta=%d\n",
+ framediv, cl.servertime, cl.serverdelta);
}
#endif
-static void CL_ParseSetting( void ) {
+static void CL_ParseSetting(void)
+{
uint32_t index, value;
index = MSG_ReadLong();
value = MSG_ReadLong();
- switch( index ) {
+ switch (index) {
#if USE_FPS
case SVS_FPS:
- set_server_fps( value );
+ set_server_fps(value);
break;
#endif
default:
@@ -1125,31 +1143,32 @@ static void CL_ParseSetting( void ) {
CL_ParseServerMessage
=====================
*/
-void CL_ParseServerMessage( void ) {
+void CL_ParseServerMessage(void)
+{
int cmd, extrabits;
size_t readcount;
int index, bits;
#ifdef _DEBUG
- if( cl_shownet->integer == 1 ) {
- Com_LPrintf( PRINT_DEVELOPER, "%"PRIz" ", msg_read.cursize );
- } else if( cl_shownet->integer > 1 ) {
- Com_LPrintf( PRINT_DEVELOPER, "------------------\n" );
+ if (cl_shownet->integer == 1) {
+ Com_LPrintf(PRINT_DEVELOPER, "%"PRIz" ", msg_read.cursize);
+ } else if (cl_shownet->integer > 1) {
+ Com_LPrintf(PRINT_DEVELOPER, "------------------\n");
}
#endif
//
// parse the message
//
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of server message", __func__ );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of server message", __func__);
}
readcount = msg_read.readcount;
- if( ( cmd = MSG_ReadByte() ) == -1 ) {
- SHOWNET( 1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 );
+ if ((cmd = MSG_ReadByte()) == -1) {
+ SHOWNET(1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1);
break;
}
@@ -1157,23 +1176,23 @@ void CL_ParseServerMessage( void ) {
cmd &= SVCMD_MASK;
#ifdef _DEBUG
- if( cl_shownet->integer > 1 ) {
- MSG_ShowSVC( cmd );
+ if (cl_shownet->integer > 1) {
+ MSG_ShowSVC(cmd);
}
#endif
-
- // other commands
- switch( cmd ) {
+
+ // other commands
+ switch (cmd) {
default:
- badbyte:
- Com_Error( ERR_DROP, "%s: illegible server message: %d", __func__, cmd );
+badbyte:
+ Com_Error(ERR_DROP, "%s: illegible server message: %d", __func__, cmd);
break;
-
+
case svc_nop:
break;
-
+
case svc_disconnect:
- Com_Error( ERR_DISCONNECT, "Server disconnected" );
+ Com_Error(ERR_DISCONNECT, "Server disconnected");
break;
case svc_reconnect:
@@ -1183,32 +1202,32 @@ void CL_ParseServerMessage( void ) {
case svc_print:
CL_ParsePrint();
break;
-
+
case svc_centerprint:
CL_ParseCenterPrint();
break;
-
+
case svc_stufftext:
CL_ParseStuffText();
break;
-
+
case svc_serverdata:
CL_ParseServerData();
continue;
-
+
case svc_configstring:
index = MSG_ReadShort();
- CL_ParseConfigstring( index );
+ CL_ParseConfigstring(index);
break;
-
+
case svc_sound:
CL_ParseStartSoundPacket();
S_ParseStartSound();
break;
-
+
case svc_spawnbaseline:
- index = MSG_ParseEntityBits( &bits );
- CL_ParseBaseline( index, bits );
+ index = MSG_ParseEntityBits(&bits);
+ CL_ParseBaseline(index, bits);
break;
case svc_temp_entity:
@@ -1217,12 +1236,12 @@ void CL_ParseServerMessage( void ) {
break;
case svc_muzzleflash:
- CL_ParseMuzzleFlashPacket( MZ_SILENCED );
+ CL_ParseMuzzleFlashPacket(MZ_SILENCED);
CL_MuzzleFlash();
break;
case svc_muzzleflash2:
- CL_ParseMuzzleFlashPacket( 0 );
+ CL_ParseMuzzleFlashPacket(0);
CL_MuzzleFlash2();
break;
@@ -1231,7 +1250,7 @@ void CL_ParseServerMessage( void ) {
continue;
case svc_frame:
- CL_ParseFrame( extrabits );
+ CL_ParseFrame(extrabits);
continue;
case svc_inventory:
@@ -1243,21 +1262,21 @@ void CL_ParseServerMessage( void ) {
break;
case svc_zpacket:
- if( cls.serverProtocol < PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.serverProtocol < PROTOCOL_VERSION_R1Q2) {
goto badbyte;
}
CL_ParseZPacket();
continue;
case svc_gamestate:
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO ) {
+ if (cls.serverProtocol != PROTOCOL_VERSION_Q2PRO) {
goto badbyte;
}
CL_ParseGamestate();
continue;
case svc_setting:
- if( cls.serverProtocol < PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.serverProtocol < PROTOCOL_VERSION_R1Q2) {
goto badbyte;
}
CL_ParseSetting();
@@ -1265,14 +1284,14 @@ void CL_ParseServerMessage( void ) {
}
// if recording demos, copy off protocol invariant stuff
- if( cls.demo.recording && !cls.demo.paused ) {
+ if (cls.demo.recording && !cls.demo.paused) {
size_t len = msg_read.readcount - readcount;
// it is very easy to overflow standard 1390 bytes
// demo frame with modern servers... attempt to preserve
// reliable messages at least, assuming they come first
- if( cls.demo.buffer.cursize + len < cls.demo.buffer.maxsize ) {
- SZ_Write( &cls.demo.buffer, msg_read.data + readcount, len );
+ if (cls.demo.buffer.cursize + len < cls.demo.buffer.maxsize) {
+ SZ_Write(&cls.demo.buffer, msg_read.data + readcount, len);
} else {
cls.demo.messages_dropped++;
}
@@ -1280,12 +1299,12 @@ void CL_ParseServerMessage( void ) {
}
// if recording demos, write the message out
- if( cls.demo.recording && !cls.demo.paused && CL_FRAMESYNC ) {
- CL_WriteDemoMessage( &cls.demo.buffer );
+ if (cls.demo.recording && !cls.demo.paused && CL_FRAMESYNC) {
+ CL_WriteDemoMessage(&cls.demo.buffer);
}
// if playing demos, save a snapshot once the full packet is parsed
- if( cls.demo.playback )
+ if (cls.demo.playback)
CL_EmitDemoSnapshot();
}
@@ -1297,28 +1316,29 @@ A variant of ParseServerMessage that skips over non-important action messages,
used for seeking in demos.
=====================
*/
-void CL_SeekDemoMessage( void ) {
+void CL_SeekDemoMessage(void)
+{
int cmd, extrabits;
int index;
#ifdef _DEBUG
- if( cl_shownet->integer == 1 ) {
- Com_LPrintf( PRINT_DEVELOPER, "%"PRIz" ", msg_read.cursize );
- } else if( cl_shownet->integer > 1 ) {
- Com_LPrintf( PRINT_DEVELOPER, "------------------\n" );
+ if (cl_shownet->integer == 1) {
+ Com_LPrintf(PRINT_DEVELOPER, "%"PRIz" ", msg_read.cursize);
+ } else if (cl_shownet->integer > 1) {
+ Com_LPrintf(PRINT_DEVELOPER, "------------------\n");
}
#endif
//
// parse the message
//
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- Com_Error( ERR_DROP, "%s: read past end of server message", __func__ );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ Com_Error(ERR_DROP, "%s: read past end of server message", __func__);
}
- if( ( cmd = MSG_ReadByte() ) == -1 ) {
- SHOWNET( 1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 );
+ if ((cmd = MSG_ReadByte()) == -1) {
+ SHOWNET(1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1);
break;
}
@@ -1326,15 +1346,15 @@ void CL_SeekDemoMessage( void ) {
cmd &= SVCMD_MASK;
#ifdef _DEBUG
- if( cl_shownet->integer > 1 ) {
- MSG_ShowSVC( cmd );
+ if (cl_shownet->integer > 1) {
+ MSG_ShowSVC(cmd);
}
#endif
- // other commands
- switch( cmd ) {
+ // other commands
+ switch (cmd) {
default:
- Com_Error( ERR_DROP, "%s: illegible server message: %d", __func__, cmd );
+ Com_Error(ERR_DROP, "%s: illegible server message: %d", __func__, cmd);
break;
case svc_nop:
@@ -1342,7 +1362,7 @@ void CL_SeekDemoMessage( void ) {
case svc_disconnect:
case svc_reconnect:
- Com_Error( ERR_DISCONNECT, "Server disconnected" );
+ Com_Error(ERR_DISCONNECT, "Server disconnected");
break;
case svc_print:
@@ -1351,12 +1371,12 @@ void CL_SeekDemoMessage( void ) {
case svc_centerprint:
case svc_stufftext:
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
break;
case svc_configstring:
index = MSG_ReadShort();
- CL_ParseConfigstring( index );
+ CL_ParseConfigstring(index);
break;
case svc_sound:
@@ -1369,11 +1389,11 @@ void CL_SeekDemoMessage( void ) {
case svc_muzzleflash:
case svc_muzzleflash2:
- CL_ParseMuzzleFlashPacket( 0 );
+ CL_ParseMuzzleFlashPacket(0);
break;
case svc_frame:
- CL_ParseFrame( extrabits );
+ CL_ParseFrame(extrabits);
continue;
case svc_inventory:
diff --git a/src/cl_precache.c b/src/cl_precache.c
index 88a6405..4d5d4b5 100644
--- a/src/cl_precache.c
+++ b/src/cl_precache.c
@@ -32,62 +32,63 @@ Breaks up playerskin into name (optional), model and skin components.
If model or skin are found to be invalid, replaces them with sane defaults.
================
*/
-void CL_ParsePlayerSkin( char *name, char *model, char *skin, const char *s ) {
+void CL_ParsePlayerSkin(char *name, char *model, char *skin, const char *s)
+{
size_t len;
char *t;
// configstring parsing guarantees that playerskins can never
// overflow, but still check the length to be entirely fool-proof
- len = strlen( s );
- if( len >= MAX_QPATH ) {
- Com_Error( ERR_DROP, "%s: oversize playerskin", __func__ );
+ len = strlen(s);
+ if (len >= MAX_QPATH) {
+ Com_Error(ERR_DROP, "%s: oversize playerskin", __func__);
}
// isolate the player's name
- t = strchr( s, '\\' );
- if( t ) {
+ t = strchr(s, '\\');
+ if (t) {
len = t - s;
- strcpy( model, t + 1 );
+ strcpy(model, t + 1);
} else {
len = 0;
- strcpy( model, s );
+ strcpy(model, s);
}
// copy the player's name
- if( name ) {
- memcpy( name, s, len );
+ if (name) {
+ memcpy(name, s, len);
name[len] = 0;
}
// isolate the model name
- t = strchr( model, '/' );
- if( !t )
- t = strchr( model, '\\' );
- if( !t )
+ t = strchr(model, '/');
+ if (!t)
+ t = strchr(model, '\\');
+ if (!t)
t = model;
- if( t == model )
+ if (t == model)
goto default_model;
*t++ = 0;
// apply restrictions on skins
- if( cl_noskins->integer == 2 || !COM_IsPath( t ) )
+ if (cl_noskins->integer == 2 || !COM_IsPath(t))
goto default_skin;
- if( cl_noskins->integer || !COM_IsPath( model ) )
+ if (cl_noskins->integer || !COM_IsPath(model))
goto default_model;
// isolate the skin name
- strcpy( skin, t );
+ strcpy(skin, t);
return;
default_skin:
- if( !Q_stricmp( model, "female" ) ) {
- strcpy( model, "female" );
- strcpy( skin, "athena" );
+ if (!Q_stricmp(model, "female")) {
+ strcpy(model, "female");
+ strcpy(skin, "athena");
} else {
default_model:
- strcpy( model, "male" );
- strcpy( skin, "grunt" );
+ strcpy(model, "male");
+ strcpy(skin, "grunt");
}
}
@@ -97,7 +98,8 @@ CL_LoadClientinfo
================
*/
-void CL_LoadClientinfo( clientinfo_t *ci, const char *s ) {
+void CL_LoadClientinfo(clientinfo_t *ci, const char *s)
+{
int i;
char model_name[MAX_QPATH];
char skin_name[MAX_QPATH];
@@ -106,81 +108,81 @@ void CL_LoadClientinfo( clientinfo_t *ci, const char *s ) {
char weapon_filename[MAX_QPATH];
char icon_filename[MAX_QPATH];
- CL_ParsePlayerSkin( ci->name, model_name, skin_name, s );
+ CL_ParsePlayerSkin(ci->name, model_name, skin_name, s);
// model file
- Q_concat( model_filename, sizeof( model_filename ),
- "players/", model_name, "/tris.md2", NULL );
- ci->model = R_RegisterModel( model_filename );
- if( !ci->model && Q_stricmp( model_name, "male" ) ) {
- strcpy( model_name, "male" );
- strcpy( model_filename, "players/male/tris.md2" );
- ci->model = R_RegisterModel( model_filename );
+ Q_concat(model_filename, sizeof(model_filename),
+ "players/", model_name, "/tris.md2", NULL);
+ ci->model = R_RegisterModel(model_filename);
+ if (!ci->model && Q_stricmp(model_name, "male")) {
+ strcpy(model_name, "male");
+ strcpy(model_filename, "players/male/tris.md2");
+ ci->model = R_RegisterModel(model_filename);
}
// skin file
- Q_concat( skin_filename, sizeof( skin_filename ),
- "players/", model_name, "/", skin_name, ".pcx", NULL );
- ci->skin = R_RegisterSkin( skin_filename );
+ Q_concat(skin_filename, sizeof(skin_filename),
+ "players/", model_name, "/", skin_name, ".pcx", NULL);
+ ci->skin = R_RegisterSkin(skin_filename);
// if we don't have the skin and the model was female,
// see if athena skin exists
- if( !ci->skin && !Q_stricmp( model_name, "female" ) ) {
- strcpy( skin_name, "athena" );
- strcpy( skin_filename, "players/female/athena.pcx" );
- ci->skin = R_RegisterSkin( skin_filename );
+ if (!ci->skin && !Q_stricmp(model_name, "female")) {
+ strcpy(skin_name, "athena");
+ strcpy(skin_filename, "players/female/athena.pcx");
+ ci->skin = R_RegisterSkin(skin_filename);
}
// if we don't have the skin and the model wasn't male,
// see if the male has it (this is for CTF's skins)
- if( !ci->skin && Q_stricmp( model_name, "male" ) ) {
+ if (!ci->skin && Q_stricmp(model_name, "male")) {
// change model to male
- strcpy( model_name, "male" );
- strcpy( model_filename, "players/male/tris.md2" );
- ci->model = R_RegisterModel( model_filename );
+ strcpy(model_name, "male");
+ strcpy(model_filename, "players/male/tris.md2");
+ ci->model = R_RegisterModel(model_filename);
// see if the skin exists for the male model
- Q_concat( skin_filename, sizeof( skin_filename ),
- "players/male/", skin_name, ".pcx", NULL );
- ci->skin = R_RegisterSkin( skin_filename );
+ Q_concat(skin_filename, sizeof(skin_filename),
+ "players/male/", skin_name, ".pcx", NULL);
+ ci->skin = R_RegisterSkin(skin_filename);
}
// if we still don't have a skin, it means that the male model
// didn't have it, so default to grunt
- if( !ci->skin ) {
+ if (!ci->skin) {
// see if the skin exists for the male model
- strcpy( skin_name, "grunt" );
- strcpy( skin_filename, "players/male/grunt.pcx" );
- ci->skin = R_RegisterSkin( skin_filename );
+ strcpy(skin_name, "grunt");
+ strcpy(skin_filename, "players/male/grunt.pcx");
+ ci->skin = R_RegisterSkin(skin_filename);
}
// weapon file
- for( i = 0; i < cl.numWeaponModels; i++ ) {
- Q_concat( weapon_filename, sizeof( weapon_filename ),
- "players/", model_name, "/", cl.weaponModels[i], NULL );
- ci->weaponmodel[i] = R_RegisterModel( weapon_filename );
- if( !ci->weaponmodel[i] && Q_stricmp( model_name, "male" ) ) {
+ for (i = 0; i < cl.numWeaponModels; i++) {
+ Q_concat(weapon_filename, sizeof(weapon_filename),
+ "players/", model_name, "/", cl.weaponModels[i], NULL);
+ ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
+ if (!ci->weaponmodel[i] && Q_stricmp(model_name, "male")) {
// try male
- Q_concat( weapon_filename, sizeof( weapon_filename ),
- "players/male/", cl.weaponModels[i], NULL );
- ci->weaponmodel[i] = R_RegisterModel( weapon_filename );
+ Q_concat(weapon_filename, sizeof(weapon_filename),
+ "players/male/", cl.weaponModels[i], NULL);
+ ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
}
}
// icon file
- Q_concat( icon_filename, sizeof( icon_filename ),
- "/players/", model_name, "/", skin_name, "_i.pcx", NULL );
- ci->icon = R_RegisterPic( icon_filename );
+ Q_concat(icon_filename, sizeof(icon_filename),
+ "/players/", model_name, "/", skin_name, "_i.pcx", NULL);
+ ci->icon = R_RegisterPic(icon_filename);
- strcpy( ci->model_name, model_name );
- strcpy( ci->skin_name, skin_name );
+ strcpy(ci->model_name, model_name);
+ strcpy(ci->skin_name, skin_name);
// base info should be at least partially valid
- if( ci == &cl.baseclientinfo )
+ if (ci == &cl.baseclientinfo)
return;
// must have loaded all data types to be valid
- if( !ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0] ) {
+ if (!ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0]) {
ci->skin = 0;
ci->icon = 0;
ci->model = 0;
@@ -195,13 +197,14 @@ void CL_LoadClientinfo( clientinfo_t *ci, const char *s ) {
CL_LoadState
=================
*/
-void CL_LoadState( load_state_t state ) {
- extern void VID_PumpEvents( void );
+void CL_LoadState(load_state_t state)
+{
+ extern void VID_PumpEvents(void);
const char *s;
- switch( state ) {
+ switch (state) {
case LOAD_MAP:
- s = cl.configstrings[ CS_MODELS + 1 ];
+ s = cl.configstrings[CS_MODELS + 1];
break;
case LOAD_MODELS:
s = "models";
@@ -222,10 +225,10 @@ void CL_LoadState( load_state_t state ) {
return;
}
- if( s ) {
- Con_Printf( "Loading %s...\r", s );
+ if (s) {
+ Con_Printf("Loading %s...\r", s);
} else {
- Con_Print( "\r" );
+ Con_Print("\r");
}
SCR_UpdateScreen();
@@ -237,19 +240,20 @@ void CL_LoadState( load_state_t state ) {
CL_RegisterSounds
=================
*/
-void CL_RegisterSounds( void ) {
+void CL_RegisterSounds(void)
+{
int i;
char *s;
- S_BeginRegistration ();
- CL_RegisterTEntSounds ();
- for ( i = 1; i < MAX_SOUNDS; i++ ) {
- s = cl.configstrings[ CS_SOUNDS + i ];
- if ( !s[ 0 ] )
+ S_BeginRegistration();
+ CL_RegisterTEntSounds();
+ for (i = 1; i < MAX_SOUNDS; i++) {
+ s = cl.configstrings[CS_SOUNDS + i];
+ if (!s[0])
break;
- cl.sound_precache[ i ] = S_RegisterSound( s );
+ cl.sound_precache[i] = S_RegisterSound(s);
}
- S_EndRegistration ();
+ S_EndRegistration();
}
/*
@@ -259,36 +263,37 @@ CL_RegisterBspModels
Registers main BSP file and inline models
=================
*/
-void CL_RegisterBspModels( void ) {
+void CL_RegisterBspModels(void)
+{
qerror_t ret;
char *name;
int i;
- ret = BSP_Load( cl.configstrings[ CS_MODELS + 1 ], &cl.bsp );
- if( cl.bsp == NULL ) {
- Com_Error( ERR_DROP, "Couldn't load %s: %s",
- cl.configstrings[ CS_MODELS + 1 ], Q_ErrorString( ret ) );
+ ret = BSP_Load(cl.configstrings[CS_MODELS + 1], &cl.bsp);
+ if (cl.bsp == NULL) {
+ Com_Error(ERR_DROP, "Couldn't load %s: %s",
+ cl.configstrings[CS_MODELS + 1], Q_ErrorString(ret));
}
#if USE_MAPCHECKSUM
- if( cl.bsp->checksum != atoi( cl.configstrings[ CS_MAPCHECKSUM ] ) ) {
- if( cls.demo.playback ) {
- Com_WPrintf( "Local map version differs from demo: %i != %s\n",
- cl.bsp->checksum, cl.configstrings[ CS_MAPCHECKSUM ] );
+ if (cl.bsp->checksum != atoi(cl.configstrings[CS_MAPCHECKSUM])) {
+ if (cls.demo.playback) {
+ Com_WPrintf("Local map version differs from demo: %i != %s\n",
+ cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
} else {
- Com_Error( ERR_DROP, "Local map version differs from server: %i != %s",
- cl.bsp->checksum, cl.configstrings[ CS_MAPCHECKSUM ] );
+ Com_Error(ERR_DROP, "Local map version differs from server: %i != %s",
+ cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
}
}
#endif
- for ( i = 1; i < MAX_MODELS; i++ ) {
- name = cl.configstrings[CS_MODELS+i];
- if( !name[0] ) {
+ for (i = 1; i < MAX_MODELS; i++) {
+ name = cl.configstrings[CS_MODELS + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '*' )
- cl.model_clip[i] = BSP_InlineModel( cl.bsp, name );
+ if (name[0] == '*')
+ cl.model_clip[i] = BSP_InlineModel(cl.bsp, name);
else
cl.model_clip[i] = NULL;
}
@@ -301,31 +306,32 @@ CL_RegisterVWepModels
Builds a list of visual weapon models
=================
*/
-void CL_RegisterVWepModels( void ) {
+void CL_RegisterVWepModels(void)
+{
int i;
char *name;
cl.numWeaponModels = 1;
- strcpy( cl.weaponModels[0], "weapon.md2" );
+ strcpy(cl.weaponModels[0], "weapon.md2");
// only default model when vwep is off
- if( !cl_vwep->integer ) {
+ if (!cl_vwep->integer) {
return;
}
- for( i = 2; i < MAX_MODELS; i++ ) {
- name = cl.configstrings[ CS_MODELS + i ];
- if( !name[0] ) {
+ for (i = 2; i < MAX_MODELS; i++) {
+ name = cl.configstrings[CS_MODELS + i];
+ if (!name[0]) {
break;
}
- if( name[0] != '#' ) {
+ if (name[0] != '#') {
continue;
}
// special player weapon model
- strcpy( cl.weaponModels[cl.numWeaponModels++], name + 1 );
+ strcpy(cl.weaponModels[cl.numWeaponModels++], name + 1);
- if( cl.numWeaponModels == MAX_CLIENTWEAPONMODELS ) {
+ if (cl.numWeaponModels == MAX_CLIENTWEAPONMODELS) {
break;
}
}
@@ -338,64 +344,64 @@ CL_PrepRefresh
Call before entering a new level, or after changing dlls
=================
*/
-void CL_PrepRefresh (void) {
+void CL_PrepRefresh(void)
+{
int i;
char *name;
float rotate;
vec3_t axis;
- if( !cls.ref_initialized )
+ if (!cls.ref_initialized)
return;
- if( !cl.mapname[0] )
+ if (!cl.mapname[0])
return; // no map loaded
// register models, pics, and skins
- R_BeginRegistration( cl.mapname );
+ R_BeginRegistration(cl.mapname);
- CL_LoadState( LOAD_MODELS );
+ CL_LoadState(LOAD_MODELS);
- CL_RegisterTEntModels ();
+ CL_RegisterTEntModels();
- for( i = 2; i < MAX_MODELS; i++ ) {
- name = cl.configstrings[ CS_MODELS + i ];
- if( !name[0] ) {
+ for (i = 2; i < MAX_MODELS; i++) {
+ name = cl.configstrings[CS_MODELS + i];
+ if (!name[0]) {
break;
}
- if( name[0] == '#' ) {
+ if (name[0] == '#') {
continue;
}
- cl.model_draw[i] = R_RegisterModel( name );
+ cl.model_draw[i] = R_RegisterModel(name);
}
- CL_LoadState( LOAD_IMAGES );
- for( i = 1; i < MAX_IMAGES; i++ ) {
- name = cl.configstrings[ CS_IMAGES + i ];
- if( !name[0] ) {
+ CL_LoadState(LOAD_IMAGES);
+ for (i = 1; i < MAX_IMAGES; i++) {
+ name = cl.configstrings[CS_IMAGES + i];
+ if (!name[0]) {
break;
}
- cl.image_precache[i] = R_RegisterPic( name );
+ cl.image_precache[i] = R_RegisterPic(name);
}
- CL_LoadState( LOAD_CLIENTS );
- for(i = 0; i < MAX_CLIENTS; i++ ) {
- name = cl.configstrings[ CS_PLAYERSKINS + i ];
- if( !name[0] ) {
+ CL_LoadState(LOAD_CLIENTS);
+ for (i = 0; i < MAX_CLIENTS; i++) {
+ name = cl.configstrings[CS_PLAYERSKINS + i];
+ if (!name[0]) {
continue;
}
- CL_LoadClientinfo( &cl.clientinfo[i], name );
+ CL_LoadClientinfo(&cl.clientinfo[i], name);
}
- CL_LoadClientinfo( &cl.baseclientinfo, "unnamed\\male/grunt" );
+ CL_LoadClientinfo(&cl.baseclientinfo, "unnamed\\male/grunt");
// set sky textures and speed
- rotate = atof( cl.configstrings[CS_SKYROTATE] );
- if( sscanf( cl.configstrings[CS_SKYAXIS], "%f %f %f",
- &axis[0], &axis[1], &axis[2]) != 3 )
- {
- Com_DPrintf( "Couldn't parse CS_SKYAXIS\n" );
- VectorClear( axis );
+ rotate = atof(cl.configstrings[CS_SKYROTATE]);
+ if (sscanf(cl.configstrings[CS_SKYAXIS], "%f %f %f",
+ &axis[0], &axis[1], &axis[2]) != 3) {
+ Com_DPrintf("Couldn't parse CS_SKYAXIS\n");
+ VectorClear(axis);
}
- R_SetSky( cl.configstrings[CS_SKY], rotate, axis );
+ R_SetSky(cl.configstrings[CS_SKY], rotate, axis);
// the renderer can now free unneeded stuff
R_EndRegistration();
@@ -413,67 +419,68 @@ CL_UpdateConfigstring
A configstring update has been parsed.
=================
*/
-void CL_UpdateConfigstring( int index ) {
+void CL_UpdateConfigstring(int index)
+{
const char *s = cl.configstrings[index];
- if( index == CS_MAXCLIENTS ) {
- cl.maxclients = atoi( s );
+ if (index == CS_MAXCLIENTS) {
+ cl.maxclients = atoi(s);
return;
}
- if( index == CS_AIRACCEL ) {
- if( cl.pmp.qwmode )
+ if (index == CS_AIRACCEL) {
+ if (cl.pmp.qwmode)
cl.pmp.airaccelerate = qtrue;
else
- cl.pmp.airaccelerate = atoi( s ) ? qtrue : qfalse;
+ cl.pmp.airaccelerate = atoi(s) ? qtrue : qfalse;
return;
}
- if( index == CS_MODELS + 1 ) {
- size_t len = strlen( s );
+ if (index == CS_MODELS + 1) {
+ size_t len = strlen(s);
- if( len <= 9 ) {
- Com_Error( ERR_DROP, "%s: bad world model: %s", __func__, s );
+ if (len <= 9) {
+ Com_Error(ERR_DROP, "%s: bad world model: %s", __func__, s);
}
- memcpy( cl.mapname, s + 5, len - 9 ); // skip "maps/"
+ memcpy(cl.mapname, s + 5, len - 9); // skip "maps/"
cl.mapname[len - 9] = 0; // cut off ".bsp"
return;
}
#if USE_LIGHTSTYLES
- if( index >= CS_LIGHTS && index < CS_LIGHTS + MAX_LIGHTSTYLES ) {
- CL_SetLightStyle( index - CS_LIGHTS, s );
+ if (index >= CS_LIGHTS && index < CS_LIGHTS + MAX_LIGHTSTYLES) {
+ CL_SetLightStyle(index - CS_LIGHTS, s);
return;
}
#endif
- if( cls.state < ca_precached ) {
+ if (cls.state < ca_precached) {
return;
}
- if( index >= CS_MODELS + 2 && index < CS_MODELS + MAX_MODELS ) {
+ if (index >= CS_MODELS + 2 && index < CS_MODELS + MAX_MODELS) {
int i = index - CS_MODELS;
- cl.model_draw[i] = R_RegisterModel( s );
- if( *s == '*' )
- cl.model_clip[i] = BSP_InlineModel( cl.bsp, s );
+ cl.model_draw[i] = R_RegisterModel(s);
+ if (*s == '*')
+ cl.model_clip[i] = BSP_InlineModel(cl.bsp, s);
else
cl.model_clip[i] = NULL;
return;
}
- if( index >= CS_SOUNDS && index < CS_SOUNDS + MAX_MODELS ) {
- cl.sound_precache[ index - CS_SOUNDS ] = S_RegisterSound( s );
+ if (index >= CS_SOUNDS && index < CS_SOUNDS + MAX_MODELS) {
+ cl.sound_precache[index - CS_SOUNDS] = S_RegisterSound(s);
return;
}
- if( index >= CS_IMAGES && index < CS_IMAGES + MAX_MODELS ) {
- cl.image_precache[ index - CS_IMAGES] = R_RegisterPic( s );
+ if (index >= CS_IMAGES && index < CS_IMAGES + MAX_MODELS) {
+ cl.image_precache[index - CS_IMAGES] = R_RegisterPic(s);
return;
}
- if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS ) {
- CL_LoadClientinfo( &cl.clientinfo[ index - CS_PLAYERSKINS ], s );
+ if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS) {
+ CL_LoadClientinfo(&cl.clientinfo[index - CS_PLAYERSKINS], s);
return;
}
}
diff --git a/src/cl_pred.c b/src/cl_pred.c
index 34547c2..1a92a09 100644
--- a/src/cl_pred.c
+++ b/src/cl_pred.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,22 +26,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
CL_CheckPredictionError
===================
*/
-void CL_CheckPredictionError( void ) {
+void CL_CheckPredictionError(void)
+{
int frame;
int delta[3];
unsigned cmd;
int len;
- if( !cls.netchan ) {
+ if (!cls.netchan) {
return;
}
- if( sv_paused->integer ) {
- VectorClear( cl.prediction_error );
+ if (sv_paused->integer) {
+ VectorClear(cl.prediction_error);
return;
}
- if( !cl_predict->integer || ( cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION ) )
+ if (!cl_predict->integer || (cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION))
return;
// calculate the last usercmd_t we sent that the server has processed
@@ -49,30 +50,30 @@ void CL_CheckPredictionError( void ) {
cmd = cl.history[frame].cmdNumber;
// don't predict steps against server returned data
- if( cl.predicted_step_frame < cmd + 1 ) {
+ if (cl.predicted_step_frame < cmd + 1) {
cl.predicted_step_frame = cmd + 1;
}
cmd &= CMD_MASK;
// compare what the server returned with what we had predicted it to be
- VectorSubtract( cl.frame.ps.pmove.origin, cl.predicted_origins[cmd], delta );
+ VectorSubtract(cl.frame.ps.pmove.origin, cl.predicted_origins[cmd], delta);
// save the prediction error for interpolation
- len = abs( delta[0] ) + abs( delta[1] ) + abs( delta[2] );
- if( len > 640 ) { // 80 world units
+ len = abs(delta[0]) + abs(delta[1]) + abs(delta[2]);
+ if (len > 640) { // 80 world units
// a teleport or something
- VectorClear( cl.prediction_error );
+ VectorClear(cl.prediction_error);
} else {
- if( delta[0] || delta[1] || delta[2] ) {
- SHOWMISS( "prediction miss on %i: %i (%d %d %d)\n",
- cl.frame.number, len, delta[0], delta[1], delta[2]);
+ if (delta[0] || delta[1] || delta[2]) {
+ SHOWMISS("prediction miss on %i: %i (%d %d %d)\n",
+ cl.frame.number, len, delta[0], delta[1], delta[2]);
}
- VectorCopy( cl.frame.ps.pmove.origin, cl.predicted_origins[cmd] );
+ VectorCopy(cl.frame.ps.pmove.origin, cl.predicted_origins[cmd]);
// save for error interpolation
- VectorScale( delta, 0.125f, cl.prediction_error );
+ VectorScale(delta, 0.125f, cl.prediction_error);
}
}
@@ -82,34 +83,35 @@ CL_ClipMoveToEntities
====================
*/
-static void CL_ClipMoveToEntities( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr ) {
+static void CL_ClipMoveToEntities(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr)
+{
int i;
trace_t trace;
mnode_t *headnode;
centity_t *ent;
mmodel_t *cmodel;
- for( i = 0; i < cl.numSolidEntities; i++ ) {
+ for (i = 0; i < cl.numSolidEntities; i++) {
ent = cl.solidEntities[i];
- if( ent->current.solid == PACKED_BSP ) {
+ if (ent->current.solid == PACKED_BSP) {
// special value for bmodel
cmodel = cl.model_clip[ent->current.modelindex];
- if( !cmodel )
+ if (!cmodel)
continue;
headnode = cmodel->headnode;
} else {
- headnode = CM_HeadnodeForBox( ent->mins, ent->maxs );
+ headnode = CM_HeadnodeForBox(ent->mins, ent->maxs);
}
- if( tr->allsolid )
+ if (tr->allsolid)
return;
- CM_TransformedBoxTrace( &trace, start, end,
- mins, maxs, headnode, MASK_PLAYERSOLID,
- ent->current.origin, ent->current.angles );
+ CM_TransformedBoxTrace(&trace, start, end,
+ mins, maxs, headnode, MASK_PLAYERSOLID,
+ ent->current.origin, ent->current.angles);
- CM_ClipEntity( tr, &trace, ( struct edict_s * )ent );
+ CM_ClipEntity(tr, &trace, (struct edict_s *)ent);
}
}
@@ -119,29 +121,31 @@ static void CL_ClipMoveToEntities( vec3_t start, vec3_t mins, vec3_t maxs, vec3_
CL_PMTrace
================
*/
-static trace_t CL_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) {
+static trace_t CL_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
+{
trace_t t;
// check against world
- CM_BoxTrace (&t, start, end, mins, maxs, cl.bsp->nodes, MASK_PLAYERSOLID);
+ CM_BoxTrace(&t, start, end, mins, maxs, cl.bsp->nodes, MASK_PLAYERSOLID);
if (t.fraction < 1.0)
t.ent = (struct edict_s *)1;
// check all other solid models
- CL_ClipMoveToEntities (start, mins, maxs, end, &t);
+ CL_ClipMoveToEntities(start, mins, maxs, end, &t);
return t;
}
-static int CL_PointContents (vec3_t point) {
+static int CL_PointContents(vec3_t point)
+{
int i;
centity_t *ent;
mmodel_t *cmodel;
int contents;
- contents = CM_PointContents (point, cl.bsp->nodes);
+ contents = CM_PointContents(point, cl.bsp->nodes);
- for (i=0 ; i<cl.numSolidEntities ; i++) {
+ for (i = 0; i < cl.numSolidEntities; i++) {
ent = cl.solidEntities[i];
if (ent->current.solid != PACKED_BSP) // special value for bmodel
@@ -152,9 +156,9 @@ static int CL_PointContents (vec3_t point) {
continue;
contents |= CM_TransformedPointContents(
- point, cmodel->headnode,
- ent->current.origin,
- ent->current.angles );
+ point, cmodel->headnode,
+ ent->current.origin,
+ ent->current.angles);
}
return contents;
@@ -167,30 +171,32 @@ CL_PredictMovement
Sets cl.predicted_origin and cl.predicted_angles
=================
*/
-void CL_PredictAngles( void ) {
- cl.predicted_angles[0] = cl.viewangles[0] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[0] );
- cl.predicted_angles[1] = cl.viewangles[1] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[1] );
- cl.predicted_angles[2] = cl.viewangles[2] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[2] );
+void CL_PredictAngles(void)
+{
+ cl.predicted_angles[0] = cl.viewangles[0] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[0]);
+ cl.predicted_angles[1] = cl.viewangles[1] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[1]);
+ cl.predicted_angles[2] = cl.viewangles[2] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[2]);
}
-void CL_PredictMovement( void ) {
+void CL_PredictMovement(void)
+{
unsigned ack, current, frame;
pmove_t pm;
int step, oldz;
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
return;
}
- if( cls.demo.playback ) {
+ if (cls.demo.playback) {
return;
}
- if( sv_paused->integer ) {
+ if (sv_paused->integer) {
return;
}
- if( !cl_predict->integer || ( cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION ) ) {
+ if (!cl_predict->integer || (cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION)) {
// just set angles
CL_PredictAngles();
return;
@@ -200,13 +206,13 @@ void CL_PredictMovement( void ) {
current = cl.cmdNumber;
// if we are too far out of date, just freeze
- if( current - ack > CMD_BACKUP - 1 ) {
- SHOWMISS( "%i: exceeded CMD_BACKUP\n", cl.frame.number );
- return;
+ if (current - ack > CMD_BACKUP - 1) {
+ SHOWMISS("%i: exceeded CMD_BACKUP\n", cl.frame.number);
+ return;
}
- if( !cl.cmd.msec && current == ack ) {
- SHOWMISS( "%i: not moved\n", cl.frame.number );
+ if (!cl.cmd.msec && current == ack) {
+ SHOWMISS("%i: not moved\n", cl.frame.number);
return;
}
@@ -214,52 +220,52 @@ void CL_PredictMovement( void ) {
X86_SINGLE_FPCW;
// copy current state to pmove
- memset( &pm, 0, sizeof( pm ) );
+ memset(&pm, 0, sizeof(pm));
pm.trace = CL_Trace;
pm.pointcontents = CL_PointContents;
pm.s = cl.frame.ps.pmove;
#if USE_SMOOTH_DELTA_ANGLES
- VectorCopy( cl.delta_angles, pm.s.delta_angles );
+ VectorCopy(cl.delta_angles, pm.s.delta_angles);
#endif
// run frames
- while( ++ack <= current ) {
+ while (++ack <= current) {
pm.cmd = cl.cmds[ack & CMD_MASK];
- Pmove( &pm, &cl.pmp );
+ Pmove(&pm, &cl.pmp);
// save for debug checking
- VectorCopy( pm.s.origin, cl.predicted_origins[ack & CMD_MASK] );
+ VectorCopy(pm.s.origin, cl.predicted_origins[ack & CMD_MASK]);
}
// run pending cmd
- if( cl.cmd.msec ) {
+ if (cl.cmd.msec) {
pm.cmd = cl.cmd;
pm.cmd.forwardmove = cl.localmove[0];
pm.cmd.sidemove = cl.localmove[1];
pm.cmd.upmove = cl.localmove[2];
- Pmove( &pm, &cl.pmp );
+ Pmove(&pm, &cl.pmp);
frame = current;
// save for debug checking
- VectorCopy( pm.s.origin, cl.predicted_origins[( current + 1 ) & CMD_MASK] );
+ VectorCopy(pm.s.origin, cl.predicted_origins[(current + 1) & CMD_MASK]);
} else {
frame = current - 1;
}
X86_POP_FPCW;
-
+
oldz = cl.predicted_origins[cl.predicted_step_frame & CMD_MASK][2];
step = pm.s.origin[2] - oldz;
- if( step > 63 && step < 160 && ( pm.s.pm_flags & PMF_ON_GROUND ) ) {
+ if (step > 63 && step < 160 && (pm.s.pm_flags & PMF_ON_GROUND)) {
cl.predicted_step = step * 0.125f;
cl.predicted_step_time = cls.realtime;/// - cls.frametime * 500;
}
cl.predicted_step_frame = frame;
// copy results out for rendering
- VectorScale( pm.s.origin, 0.125f, cl.predicted_origin );
- VectorScale( pm.s.velocity, 0.125f, cl.predicted_velocity );
- VectorCopy( pm.viewangles, cl.predicted_angles );
+ VectorScale(pm.s.origin, 0.125f, cl.predicted_origin);
+ VectorScale(pm.s.velocity, 0.125f, cl.predicted_velocity);
+ VectorCopy(pm.viewangles, cl.predicted_angles);
}
diff --git a/src/cl_public.h b/src/cl_public.h
index 223771c..77cee04 100644
--- a/src/cl_public.h
+++ b/src/cl_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -47,57 +47,57 @@ typedef enum {
ACT_ACTIVATED
} active_t;
-qboolean CL_ProcessEvents( void );
+qboolean CL_ProcessEvents(void);
#if USE_ICMP
-void CL_ErrorEvent( void );
+void CL_ErrorEvent(void);
#endif
-void CL_Init (void);
-void CL_Disconnect( error_type_t type );
-void CL_Shutdown (void);
-unsigned CL_Frame (unsigned msec);
-void CL_RestartFilesystem( qboolean total );
-void CL_Activate( active_t active );
-void CL_UpdateUserinfo( cvar_t *var, from_t from );
-qboolean CL_SendStatusRequest( char *buffer, size_t size );
-demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info );
-qboolean CL_CheatsOK( void );
-
-qboolean CL_ForwardToServer( void );
+void CL_Init(void);
+void CL_Disconnect(error_type_t type);
+void CL_Shutdown(void);
+unsigned CL_Frame(unsigned msec);
+void CL_RestartFilesystem(qboolean total);
+void CL_Activate(active_t active);
+void CL_UpdateUserinfo(cvar_t *var, from_t from);
+qboolean CL_SendStatusRequest(char *buffer, size_t size);
+demoInfo_t *CL_GetDemoInfo(const char *path, demoInfo_t *info);
+qboolean CL_CheatsOK(void);
+
+qboolean CL_ForwardToServer(void);
// adds the current command line as a clc_stringcmd to the client message.
// things like godmode, noclip, etc, are commands directed to the server,
// so when they are typed in at the console, they will need to be forwarded.
-void Con_Init( void );
-void Con_SetColor( color_index_t color );
-void Con_Print( const char *text );
-void Con_Printf( const char *fmt, ... );
-void Con_Close( qboolean force );
+void Con_Init(void);
+void Con_SetColor(color_index_t color);
+void Con_Print(const char *text);
+void Con_Printf(const char *fmt, ...);
+void Con_Close(qboolean force);
// this is in the client code, but can be used for debugging from server
-void SCR_DebugGraph (float value, int color);
-void SCR_BeginLoadingPlaque (void);
-void SCR_EndLoadingPlaque( void );
-void SCR_ModeChanged( void );
-void SCR_UpdateScreen( void );
-
-#define U32_BLACK MakeColor( 0, 0, 0, 255 )
-#define U32_RED MakeColor( 255, 0, 0, 255 )
-#define U32_GREEN MakeColor( 0, 255, 0, 255 )
-#define U32_YELLOW MakeColor( 255, 255, 0, 255 )
-#define U32_BLUE MakeColor( 0, 0, 255, 255 )
-#define U32_CYAN MakeColor( 0, 255, 255, 255 )
-#define U32_MAGENTA MakeColor( 255, 0, 255, 255 )
-#define U32_WHITE MakeColor( 255, 255, 255, 255 )
+void SCR_DebugGraph(float value, int color);
+void SCR_BeginLoadingPlaque(void);
+void SCR_EndLoadingPlaque(void);
+void SCR_ModeChanged(void);
+void SCR_UpdateScreen(void);
+
+#define U32_BLACK MakeColor( 0, 0, 0, 255)
+#define U32_RED MakeColor(255, 0, 0, 255)
+#define U32_GREEN MakeColor( 0, 255, 0, 255)
+#define U32_YELLOW MakeColor(255, 255, 0, 255)
+#define U32_BLUE MakeColor( 0, 0, 255, 255)
+#define U32_CYAN MakeColor( 0, 255, 255, 255)
+#define U32_MAGENTA MakeColor(255, 0, 255, 255)
+#define U32_WHITE MakeColor(255, 255, 255, 255)
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 8
#define UI_LEFT 0x00000001
#define UI_RIGHT 0x00000002
-#define UI_CENTER (UI_LEFT|UI_RIGHT)
+#define UI_CENTER (UI_LEFT | UI_RIGHT)
#define UI_BOTTOM 0x00000004
#define UI_TOP 0x00000008
-#define UI_MIDDLE (UI_BOTTOM|UI_TOP)
+#define UI_MIDDLE (UI_BOTTOM | UI_TOP)
#define UI_DROPSHADOW 0x00000010
#define UI_ALTCOLOR 0x00000020
#define UI_IGNORECOLOR 0x00000040
@@ -108,21 +108,21 @@ void SCR_UpdateScreen( void );
extern const uint32_t colorTable[8];
-qboolean SCR_ParseColor( const char *s, color_t *color );
+qboolean SCR_ParseColor(const char *s, color_t *color);
-float V_CalcFov( float fov_x, float width, float height );
+float V_CalcFov(float fov_x, float width, float height);
-void IN_Frame( void );
-void IN_Activate( void );
-void IN_MouseEvent( int x, int y );
-void IN_WarpMouse( int x, int y );
+void IN_Frame(void);
+void IN_Activate(void);
+void IN_MouseEvent(int x, int y);
+void IN_WarpMouse(int x, int y);
-void Key_Init( void );
-void Key_Event( unsigned key, qboolean down, unsigned time );
-void Key_CharEvent( int key );
-void Key_WriteBindings( qhandle_t f );
+void Key_Init(void);
+void Key_Event(unsigned key, qboolean down, unsigned time);
+void Key_CharEvent(int key);
+void Key_WriteBindings(qhandle_t f);
-char *VID_GetClipboardData( void );
-void VID_SetClipboardData( const char *data );
-void VID_FatalShutdown( void );
+char *VID_GetClipboardData(void);
+void VID_SetClipboardData(const char *data);
+void VID_FatalShutdown(void);
diff --git a/src/cl_ref.c b/src/cl_ref.c
index 38464b3..92688c7 100644
--- a/src/cl_ref.c
+++ b/src/cl_ref.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -52,7 +52,8 @@ HELPER FUNCTIONS
// 640x480@75
// 640x480@75:32
// 640x480:32@75
-qboolean VID_GetFullscreen( vrect_t *rc, int *freq_p, int *depth_p ) {
+qboolean VID_GetFullscreen(vrect_t *rc, int *freq_p, int *depth_p)
+{
unsigned long w, h, freq, depth;
char *s;
int mode;
@@ -63,62 +64,62 @@ qboolean VID_GetFullscreen( vrect_t *rc, int *freq_p, int *depth_p ) {
rc->width = 640;
rc->height = 480;
- if( freq_p )
+ if (freq_p)
*freq_p = 0;
- if( depth_p )
+ if (depth_p)
*depth_p = 0;
- if( !vid_modelist || !vid_fullscreen )
+ if (!vid_modelist || !vid_fullscreen)
return qfalse;
s = vid_modelist->string;
- if( !*s )
+ if (!*s)
return qfalse;
mode = 1;
- while( 1 ) {
- w = strtoul( s, &s, 10 );
- if( *s != 'x' && *s != 'X' ) {
- Com_DPrintf( "Mode %d is malformed\n", mode );
+ while (1) {
+ w = strtoul(s, &s, 10);
+ if (*s != 'x' && *s != 'X') {
+ Com_DPrintf("Mode %d is malformed\n", mode);
return qfalse;
}
- h = strtoul( s + 1, &s, 10 );
+ h = strtoul(s + 1, &s, 10);
freq = depth = 0;
- if( *s == '@' ) {
- freq = strtoul( s + 1, &s, 10 );
- if( *s == ':' ) {
- depth = strtoul( s + 1, &s, 10 );
+ if (*s == '@') {
+ freq = strtoul(s + 1, &s, 10);
+ if (*s == ':') {
+ depth = strtoul(s + 1, &s, 10);
}
- } else if( *s == ':' ) {
- depth = strtoul( s + 1, &s, 10 );
- if( *s == '@' ) {
- freq = strtoul( s + 1, &s, 10 );
+ } else if (*s == ':') {
+ depth = strtoul(s + 1, &s, 10);
+ if (*s == '@') {
+ freq = strtoul(s + 1, &s, 10);
}
}
- if( mode == vid_fullscreen->integer ) {
+ if (mode == vid_fullscreen->integer) {
break;
}
- while( Q_isspace( *s ) )
+ while (Q_isspace(*s))
s++;
- if( *s == 0 ) {
- Com_DPrintf( "Mode %d not found\n", vid_fullscreen->integer );
+ if (*s == 0) {
+ Com_DPrintf("Mode %d not found\n", vid_fullscreen->integer);
return qfalse;
}
mode++;
}
// sanity check
- if( w < 64 || w > 8192 || h < 64 || h > 8192 || freq > 1000 || depth > 32 ) {
- Com_DPrintf( "Mode %lux%lu@%lu:%lu doesn't look sane\n", w, h, freq, depth );
+ if (w < 64 || w > 8192 || h < 64 || h > 8192 || freq > 1000 || depth > 32) {
+ Com_DPrintf("Mode %lux%lu@%lu:%lu doesn't look sane\n", w, h, freq, depth);
return qfalse;
}
rc->width = w;
rc->height = h;
- if( freq_p )
+ if (freq_p)
*freq_p = freq;
- if( depth_p )
+ if (depth_p)
*depth_p = depth;
return qtrue;
@@ -128,7 +129,8 @@ qboolean VID_GetFullscreen( vrect_t *rc, int *freq_p, int *depth_p ) {
// 640x480+0
// 640x480+0+0
// 640x480-100-100
-qboolean VID_GetGeometry( vrect_t *rc ) {
+qboolean VID_GetGeometry(vrect_t *rc)
+{
unsigned long w, h;
long x, y;
char *s;
@@ -139,30 +141,30 @@ qboolean VID_GetGeometry( vrect_t *rc ) {
rc->width = 640;
rc->height = 480;
- if( !vid_geometry )
+ if (!vid_geometry)
return qfalse;
s = vid_geometry->string;
- if( !*s )
+ if (!*s)
return qfalse;
- w = strtoul( s, &s, 10 );
- if( *s != 'x' && *s != 'X' ) {
- Com_DPrintf( "Geometry string is malformed\n" );
+ w = strtoul(s, &s, 10);
+ if (*s != 'x' && *s != 'X') {
+ Com_DPrintf("Geometry string is malformed\n");
return qfalse;
}
- h = strtoul( s + 1, &s, 10 );
+ h = strtoul(s + 1, &s, 10);
x = y = 0;
- if( *s == '+' || *s == '-' ) {
- x = strtol( s, &s, 10 );
- if( *s == '+' || *s == '-' ) {
- y = strtol( s, &s, 10 );
+ if (*s == '+' || *s == '-') {
+ x = strtol(s, &s, 10);
+ if (*s == '+' || *s == '-') {
+ y = strtol(s, &s, 10);
}
}
// sanity check
- if( w < 64 || w > 8192 || h < 64 || h > 8192 ) {
- Com_DPrintf( "Geometry %lux%lu doesn't look sane\n", w, h );
+ if (w < 64 || w > 8192 || h < 64 || h > 8192) {
+ Com_DPrintf("Geometry %lux%lu doesn't look sane\n", w, h);
return qfalse;
}
@@ -174,28 +176,30 @@ qboolean VID_GetGeometry( vrect_t *rc ) {
return qtrue;
}
-void VID_SetGeometry( vrect_t *rc ) {
+void VID_SetGeometry(vrect_t *rc)
+{
char buffer[MAX_QPATH];
- if( !vid_geometry )
+ if (!vid_geometry)
return;
- Q_snprintf( buffer, sizeof( buffer ), "%dx%d%+d%+d",
- rc->width, rc->height, rc->x, rc->y );
- Cvar_SetByVar( vid_geometry, buffer, FROM_CODE );
+ Q_snprintf(buffer, sizeof(buffer), "%dx%d%+d%+d",
+ rc->width, rc->height, rc->x, rc->y);
+ Cvar_SetByVar(vid_geometry, buffer, FROM_CODE);
}
-void VID_ToggleFullscreen( void ) {
- if( !vid_fullscreen || !_vid_fullscreen )
+void VID_ToggleFullscreen(void)
+{
+ if (!vid_fullscreen || !_vid_fullscreen)
return;
- if( !vid_fullscreen->integer ) {
- if( !_vid_fullscreen->integer ) {
- Cvar_Set( "_vid_fullscreen", "1" );
+ if (!vid_fullscreen->integer) {
+ if (!_vid_fullscreen->integer) {
+ Cvar_Set("_vid_fullscreen", "1");
}
- Cbuf_AddText( &cmd_buffer, "set vid_fullscreen $_vid_fullscreen\n" );
+ Cbuf_AddText(&cmd_buffer, "set vid_fullscreen $_vid_fullscreen\n");
} else {
- Cbuf_AddText( &cmd_buffer, "set vid_fullscreen 0\n" );
+ Cbuf_AddText(&cmd_buffer, "set vid_fullscreen 0\n");
}
}
@@ -212,26 +216,27 @@ LOADING / SHUTDOWN
CL_RunResfresh
============
*/
-void CL_RunRefresh( void ) {
- if( !cls.ref_initialized ) {
+void CL_RunRefresh(void)
+{
+ if (!cls.ref_initialized) {
return;
}
-
+
VID_PumpEvents();
- if( mode_changed ) {
- if( mode_changed & MODE_FULLSCREEN ) {
+ if (mode_changed) {
+ if (mode_changed & MODE_FULLSCREEN) {
VID_SetMode();
- if( vid_fullscreen->integer ) {
- Cvar_Set( "_vid_fullscreen", vid_fullscreen->string );
+ if (vid_fullscreen->integer) {
+ Cvar_Set("_vid_fullscreen", vid_fullscreen->string);
}
} else {
- if( vid_fullscreen->integer ) {
- if( mode_changed & MODE_MODELIST ) {
+ if (vid_fullscreen->integer) {
+ if (mode_changed & MODE_MODELIST) {
VID_SetMode();
}
} else {
- if( mode_changed & MODE_GEOMETRY ) {
+ if (mode_changed & MODE_GEOMETRY) {
VID_SetMode();
}
}
@@ -239,24 +244,27 @@ void CL_RunRefresh( void ) {
mode_changed = 0;
}
- if( cvar_modified & CVAR_REFRESH ) {
- CL_RestartRefresh( qtrue );
+ if (cvar_modified & CVAR_REFRESH) {
+ CL_RestartRefresh(qtrue);
cvar_modified &= ~CVAR_REFRESH;
- } else if( cvar_modified & CVAR_FILES ) {
- CL_RestartRefresh( qfalse );
+ } else if (cvar_modified & CVAR_FILES) {
+ CL_RestartRefresh(qfalse);
cvar_modified &= ~CVAR_FILES;
}
}
-static void vid_geometry_changed( cvar_t *self ) {
+static void vid_geometry_changed(cvar_t *self)
+{
mode_changed |= MODE_GEOMETRY;
}
-static void vid_fullscreen_changed( cvar_t *self ) {
+static void vid_fullscreen_changed(cvar_t *self)
+{
mode_changed |= MODE_FULLSCREEN;
}
-static void vid_modelist_changed( cvar_t *self ) {
+static void vid_modelist_changed(cvar_t *self)
+{
mode_changed |= MODE_MODELIST;
}
@@ -265,38 +273,39 @@ static void vid_modelist_changed( cvar_t *self ) {
CL_InitRefresh
============
*/
-void CL_InitRefresh( void ) {
+void CL_InitRefresh(void)
+{
char *modelist;
- if( cls.ref_initialized ) {
+ if (cls.ref_initialized) {
return;
}
modelist = VID_GetDefaultModeList();
// Create the video variables so we know how to start the graphics drivers
- vid_ref = Cvar_Get( "vid_ref", VID_REF, CVAR_ROM );
- vid_fullscreen = Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
- _vid_fullscreen = Cvar_Get( "_vid_fullscreen", "1", CVAR_ARCHIVE );
- vid_modelist = Cvar_Get( "vid_modelist", modelist, 0 );
- vid_geometry = Cvar_Get( "vid_geometry", VID_GEOMETRY, CVAR_ARCHIVE );
-
- Z_Free( modelist );
-
- if( vid_fullscreen->integer ) {
- Cvar_Set( "_vid_fullscreen", vid_fullscreen->string );
- } else if( !_vid_fullscreen->integer ) {
- Cvar_Set( "_vid_fullscreen", "1" );
+ vid_ref = Cvar_Get("vid_ref", VID_REF, CVAR_ROM);
+ vid_fullscreen = Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE);
+ _vid_fullscreen = Cvar_Get("_vid_fullscreen", "1", CVAR_ARCHIVE);
+ vid_modelist = Cvar_Get("vid_modelist", modelist, 0);
+ vid_geometry = Cvar_Get("vid_geometry", VID_GEOMETRY, CVAR_ARCHIVE);
+
+ Z_Free(modelist);
+
+ if (vid_fullscreen->integer) {
+ Cvar_Set("_vid_fullscreen", vid_fullscreen->string);
+ } else if (!_vid_fullscreen->integer) {
+ Cvar_Set("_vid_fullscreen", "1");
}
- Com_SetLastError( NULL );
+ Com_SetLastError(NULL);
- if( !R_Init( qtrue ) ) {
- Com_Error( ERR_FATAL, "Couldn't initialize refresh: %s", Com_GetLastError() );
+ if (!R_Init(qtrue)) {
+ Com_Error(ERR_FATAL, "Couldn't initialize refresh: %s", Com_GetLastError());
}
cls.ref_initialized = qtrue;
-
+
vid_geometry->changed = vid_geometry_changed;
vid_fullscreen->changed = vid_fullscreen_changed;
vid_modelist->changed = vid_modelist_changed;
@@ -313,7 +322,7 @@ void CL_InitRefresh( void ) {
SCR_RegisterMedia();
Con_RegisterMedia();
- cvar_modified &= ~(CVAR_FILES|CVAR_REFRESH);
+ cvar_modified &= ~(CVAR_FILES | CVAR_REFRESH);
}
/*
@@ -321,8 +330,9 @@ void CL_InitRefresh( void ) {
CL_ShutdownRefresh
============
*/
-void CL_ShutdownRefresh( void ) {
- if( !cls.ref_initialized ) {
+void CL_ShutdownRefresh(void)
+{
+ if (!cls.ref_initialized) {
return;
}
@@ -337,10 +347,10 @@ void CL_ShutdownRefresh( void ) {
vid_fullscreen->changed = NULL;
vid_modelist->changed = NULL;
- R_Shutdown( qtrue );
+ R_Shutdown(qtrue);
cls.ref_initialized = qfalse;
- Z_LeakTest( TAG_RENDERER );
+ Z_LeakTest(TAG_RENDERER);
}
diff --git a/src/cl_scrn.c b/src/cl_scrn.c
index 385f653..ac72aef 100644
--- a/src/cl_scrn.c
+++ b/src/cl_scrn.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_local.h"
#define STAT_PICS 11
-#define STAT_MINUS (STAT_PICS-1) // num frame for '-' stats digit
+#define STAT_MINUS (STAT_PICS - 1) // num frame for '-' stats digit
static struct {
qboolean initialized; // ready to draw
@@ -95,10 +95,14 @@ static cvar_t *scr_graphshift;
vrect_t scr_vrect; // position of render window on screen
static const char *const sb_nums[2][STAT_PICS] = {
- { "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
- "num_6", "num_7", "num_8", "num_9", "num_minus" },
- { "anum_0", "anum_1", "anum_2", "anum_3", "anum_4", "anum_5",
- "anum_6", "anum_7", "anum_8", "anum_9", "anum_minus" }
+ {
+ "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
+ "num_6", "num_7", "num_8", "num_9", "num_minus"
+ },
+ {
+ "anum_0", "anum_1", "anum_2", "anum_3", "anum_4", "anum_5",
+ "anum_6", "anum_7", "anum_8", "anum_9", "anum_minus"
+ }
};
const uint32_t colorTable[8] = {
@@ -114,30 +118,30 @@ UTILS
===============================================================================
*/
-#define SCR_DrawString( x, y, flags, string ) \
- SCR_DrawStringEx( x, y, flags, MAX_STRING_CHARS, string, scr.font_pic )
+#define SCR_DrawString(x, y, flags, string) \
+ SCR_DrawStringEx(x, y, flags, MAX_STRING_CHARS, string, scr.font_pic)
/*
==============
SCR_DrawStringEx
==============
*/
-int SCR_DrawStringEx( int x, int y, int flags, size_t maxlen,
- const char *s, qhandle_t font )
+int SCR_DrawStringEx(int x, int y, int flags, size_t maxlen,
+ const char *s, qhandle_t font)
{
- size_t len = strlen( s );
-
- if( len > maxlen ) {
+ size_t len = strlen(s);
+
+ if (len > maxlen) {
len = maxlen;
}
-
- if( ( flags & UI_CENTER ) == UI_CENTER ) {
+
+ if ((flags & UI_CENTER) == UI_CENTER) {
x -= len * CHAR_WIDTH / 2;
- } else if( flags & UI_RIGHT ) {
+ } else if (flags & UI_RIGHT) {
x -= len * CHAR_WIDTH;
}
- return R_DrawString( x, y, flags, maxlen, s, font );
+ return R_DrawString(x, y, flags, maxlen, s, font);
}
@@ -146,24 +150,24 @@ int SCR_DrawStringEx( int x, int y, int flags, size_t maxlen,
SCR_DrawStringMulti
==============
*/
-void SCR_DrawStringMulti( int x, int y, int flags, size_t maxlen,
- const char *s, qhandle_t font )
+void SCR_DrawStringMulti(int x, int y, int flags, size_t maxlen,
+ const char *s, qhandle_t font)
{
char *p;
size_t len;
- while( *s ) {
- p = strchr( s, '\n' );
- if( !p ) {
- SCR_DrawStringEx( x, y, flags, maxlen, s, font );
+ while (*s) {
+ p = strchr(s, '\n');
+ if (!p) {
+ SCR_DrawStringEx(x, y, flags, maxlen, s, font);
break;
}
len = p - s;
- if( len > maxlen ) {
+ if (len > maxlen) {
len = maxlen;
}
- SCR_DrawStringEx( x, y, flags, len, s, font );
+ SCR_DrawStringEx(x, y, flags, len, s, font);
y += CHAR_HEIGHT;
s = p + 1;
@@ -176,62 +180,64 @@ void SCR_DrawStringMulti( int x, int y, int flags, size_t maxlen,
SCR_FadeAlpha
=================
*/
-float SCR_FadeAlpha( unsigned startTime, unsigned visTime, unsigned fadeTime ) {
+float SCR_FadeAlpha(unsigned startTime, unsigned visTime, unsigned fadeTime)
+{
float alpha;
unsigned timeLeft, delta = cls.realtime - startTime;
- if( delta >= visTime ) {
+ if (delta >= visTime) {
return 0;
}
- if( fadeTime > visTime ) {
+ if (fadeTime > visTime) {
fadeTime = visTime;
}
alpha = 1;
timeLeft = visTime - delta;
- if( timeLeft < fadeTime ) {
- alpha = ( float )timeLeft / fadeTime;
+ if (timeLeft < fadeTime) {
+ alpha = (float)timeLeft / fadeTime;
}
return alpha;
}
-qboolean SCR_ParseColor( const char *s, color_t *color ) {
+qboolean SCR_ParseColor(const char *s, color_t *color)
+{
int i;
int c[8];
// parse generic color
- if( *s == '#' ) {
+ if (*s == '#') {
s++;
- for( i = 0; s[i]; i++ ) {
- if( i == 8 ) {
+ for (i = 0; s[i]; i++) {
+ if (i == 8) {
return qfalse;
}
- c[i] = Q_charhex( s[i] );
- if( c[i] == -1 ) {
+ c[i] = Q_charhex(s[i]);
+ if (c[i] == -1) {
return qfalse;
}
}
- switch( i ) {
+ switch (i) {
case 3:
- color->u8[0] = c[0] | ( c[0] << 4 );
- color->u8[1] = c[1] | ( c[1] << 4 );
- color->u8[2] = c[2] | ( c[2] << 4 );
+ color->u8[0] = c[0] | (c[0] << 4);
+ color->u8[1] = c[1] | (c[1] << 4);
+ color->u8[2] = c[2] | (c[2] << 4);
color->u8[3] = 255;
break;
case 6:
- color->u8[0] = c[1] | ( c[0] << 4 );
- color->u8[1] = c[3] | ( c[2] << 4 );
- color->u8[2] = c[5] | ( c[4] << 4 );
+ color->u8[0] = c[1] | (c[0] << 4);
+ color->u8[1] = c[3] | (c[2] << 4);
+ color->u8[2] = c[5] | (c[4] << 4);
color->u8[3] = 255;
break;
case 8:
- color->u8[0] = c[1] | ( c[0] << 4 );
- color->u8[1] = c[3] | ( c[2] << 4 );
- color->u8[2] = c[5] | ( c[4] << 4 );
- color->u8[3] = c[7] | ( c[6] << 4 );
+ color->u8[0] = c[1] | (c[0] << 4);
+ color->u8[1] = c[3] | (c[2] << 4);
+ color->u8[2] = c[5] | (c[4] << 4);
+ color->u8[3] = c[7] | (c[6] << 4);
break;
default:
return qfalse;
@@ -241,8 +247,8 @@ qboolean SCR_ParseColor( const char *s, color_t *color ) {
}
// parse name or index
- i = Com_ParseColor( s, COLOR_WHITE );
- if( i == COLOR_NONE ) {
+ i = Com_ParseColor(s, COLOR_WHITE);
+ if (i == COLOR_NONE) {
return qfalse;
}
@@ -266,7 +272,7 @@ CL_AddNetgraph
A new packet was just parsed
==============
*/
-void CL_AddNetgraph (void)
+void CL_AddNetgraph(void)
{
int i;
int in;
@@ -280,10 +286,10 @@ void CL_AddNetgraph (void)
if (scr_debuggraph->integer || scr_timegraph->integer)
return;
- for (i=0 ; i<cls.netchan->dropped ; i++)
- SCR_DebugGraph (30, 0x40);
+ for (i = 0; i < cls.netchan->dropped; i++)
+ SCR_DebugGraph(30, 0x40);
- //for (i=0 ; i<cl.surpressCount ; i++)
+ //for (i=0; i<cl.surpressCount; i++)
// SCR_DebugGraph (30, 0xdf);
// see what the latency was on this packet
@@ -292,12 +298,11 @@ void CL_AddNetgraph (void)
ping /= 30;
if (ping > 30)
ping = 30;
- SCR_DebugGraph (ping, 0xd0);
+ SCR_DebugGraph(ping, 0xd0);
}
-typedef struct
-{
+typedef struct {
float value;
int color;
} graphsamp_t;
@@ -310,10 +315,10 @@ static graphsamp_t values[2048];
SCR_DebugGraph
==============
*/
-void SCR_DebugGraph (float value, int color)
+void SCR_DebugGraph(float value, int color)
{
- values[current&2047].value = value;
- values[current&2047].color = color;
+ values[current & 2047].value = value;
+ values[current & 2047].color = color;
current++;
}
@@ -322,7 +327,7 @@ void SCR_DebugGraph (float value, int color)
SCR_DrawDebugGraph
==============
*/
-static void SCR_DrawDebugGraph (void)
+static void SCR_DrawDebugGraph(void)
{
int a, x, y, w, i, h;
float v;
@@ -333,28 +338,28 @@ static void SCR_DrawDebugGraph (void)
//
w = r_config.width;
- x = w-1;
+ x = w - 1;
y = r_config.height;
- R_DrawFill8 (x, y-scr_graphheight->value,
- w, scr_graphheight->value, 8);
+ R_DrawFill8(x, y - scr_graphheight->value,
+ w, scr_graphheight->value, 8);
- for (a=0 ; a<w ; a++)
- {
- i = (current-1-a+2048) & 2047;
+ for (a = 0; a < w; a++) {
+ i = (current - 1 - a + 2048) & 2047;
v = values[i].value;
color = values[i].color;
- v = v*scr_graphscale->value + scr_graphshift->value;
-
+ v = v * scr_graphscale->value + scr_graphshift->value;
+
if (v < 0)
- v += scr_graphheight->value * (1+(int)(-v/scr_graphheight->value));
+ v += scr_graphheight->value * (1 + (int)(-v / scr_graphheight->value));
h = (int)v % (int)scr_graphheight->value;
- R_DrawFill8 (x, y - h, 1, h, color);
+ R_DrawFill8(x, y - h, 1, h, color);
x--;
}
}
#endif
-static void draw_percent_bar( int percent, qboolean paused, int framenum ) {
+static void draw_percent_bar(int percent, qboolean paused, int framenum)
+{
char buffer[16];
int x, w;
size_t len;
@@ -363,63 +368,64 @@ static void draw_percent_bar( int percent, qboolean paused, int framenum ) {
w = scr.hud_width * percent / 100;
- R_DrawFill8( 0, scr.hud_height, w, CHAR_HEIGHT, 4 );
- R_DrawFill8( w, scr.hud_height, scr.hud_width - w, CHAR_HEIGHT, 0 );
+ R_DrawFill8(0, scr.hud_height, w, CHAR_HEIGHT, 4);
+ R_DrawFill8(w, scr.hud_height, scr.hud_width - w, CHAR_HEIGHT, 0);
- len = Q_scnprintf( buffer, sizeof( buffer ), "%d%%", percent );
- x = ( scr.hud_width - len * CHAR_WIDTH ) / 2;
- R_DrawString( x, scr.hud_height, 0, MAX_STRING_CHARS, buffer, scr.font_pic );
+ len = Q_scnprintf(buffer, sizeof(buffer), "%d%%", percent);
+ x = (scr.hud_width - len * CHAR_WIDTH) / 2;
+ R_DrawString(x, scr.hud_height, 0, MAX_STRING_CHARS, buffer, scr.font_pic);
- if( scr_demobar->integer > 1 ) {
+ if (scr_demobar->integer > 1) {
int sec = framenum / 10;
int min = sec / 60; sec %= 60;
- Q_scnprintf( buffer, sizeof( buffer ), "%d:%02d.%d", min, sec, framenum % 10 );
- R_DrawString( 0, scr.hud_height, 0, MAX_STRING_CHARS, buffer, scr.font_pic );
+ Q_scnprintf(buffer, sizeof(buffer), "%d:%02d.%d", min, sec, framenum % 10);
+ R_DrawString(0, scr.hud_height, 0, MAX_STRING_CHARS, buffer, scr.font_pic);
}
- if( paused ) {
- SCR_DrawString( scr.hud_width, scr.hud_height, UI_RIGHT, "[PAUSED]" );
+ if (paused) {
+ SCR_DrawString(scr.hud_width, scr.hud_height, UI_RIGHT, "[PAUSED]");
}
}
-static void draw_demo_bar( void ) {
-#if USE_MVD_CLIENT
+static void draw_demo_bar(void)
+{
+#if USE_MVD_CLIENT
int percent;
qboolean paused;
int framenum;
#endif
- if( !scr_demobar->integer ) {
+ if (!scr_demobar->integer) {
return;
}
- if( cls.demo.playback ) {
- if( cls.demo.file_size ) {
+ if (cls.demo.playback) {
+ if (cls.demo.file_size) {
draw_percent_bar(
cls.demo.file_percent,
sv_paused->integer &&
cl_paused->integer &&
scr_showpause->integer == 2,
- cls.demo.frames_read );
+ cls.demo.frames_read);
}
return;
}
-#if USE_MVD_CLIENT
- if( sv_running->integer != ss_broadcast ) {
+#if USE_MVD_CLIENT
+ if (sv_running->integer != ss_broadcast) {
return;
}
- if( ( percent = MVD_GetDemoPercent( &paused, &framenum ) ) == -1 ) {
+ if ((percent = MVD_GetDemoPercent(&paused, &framenum)) == -1) {
return;
}
- if( sv_paused->integer && cl_paused->integer && scr_showpause->integer == 2 ) {
+ if (sv_paused->integer && cl_paused->integer && scr_showpause->integer == 2) {
paused |= qtrue;
}
- draw_percent_bar( percent, paused, framenum );
+ draw_percent_bar(percent, paused, framenum);
#endif
}
@@ -443,49 +449,51 @@ Called for important messages that should stay in the center of the screen
for a few moments
==============
*/
-void SCR_CenterPrint( const char *str ) {
+void SCR_CenterPrint(const char *str)
+{
const char *s;
scr_centertime_start = cls.realtime;
- if( !strcmp( scr_centerstring, str ) ) {
+ if (!strcmp(scr_centerstring, str)) {
return;
}
- Q_strlcpy( scr_centerstring, str, sizeof( scr_centerstring ) );
+ Q_strlcpy(scr_centerstring, str, sizeof(scr_centerstring));
// count the number of lines for centering
scr_center_lines = 1;
s = str;
- while( *s ) {
- if( *s == '\n' )
+ while (*s) {
+ if (*s == '\n')
scr_center_lines++;
s++;
}
// echo it to the console
- Com_Printf( "%s\n", scr_centerstring );
+ Com_Printf("%s\n", scr_centerstring);
Con_ClearNotify_f();
}
-static void draw_center_string( void ) {
+static void draw_center_string(void)
+{
int y;
float alpha;
- Cvar_ClampValue( scr_centertime, 0.3f, 10.0f );
+ Cvar_ClampValue(scr_centertime, 0.3f, 10.0f);
- alpha = SCR_FadeAlpha( scr_centertime_start, scr_centertime->value * 1000, 300 );
- if( !alpha ) {
+ alpha = SCR_FadeAlpha(scr_centertime_start, scr_centertime->value * 1000, 300);
+ if (!alpha) {
return;
}
- R_SetAlpha( alpha * scr_alpha->value );
+ R_SetAlpha(alpha * scr_alpha->value);
y = scr.hud_height / 4 - scr_center_lines * 8 / 2;
- SCR_DrawStringMulti( scr.hud_width / 2, y, UI_CENTER,
- MAX_STRING_CHARS, scr_centerstring, scr.font_pic );
+ SCR_DrawStringMulti(scr.hud_width / 2, y, UI_CENTER,
+ MAX_STRING_CHARS, scr_centerstring, scr.font_pic);
- R_SetAlpha( scr_alpha->value );
+ R_SetAlpha(scr_alpha->value);
}
/*
@@ -496,11 +504,11 @@ LAGOMETER
===============================================================================
*/
-#define LAG_WIDTH 48
-#define LAG_HEIGHT 48
+#define LAG_WIDTH 48
+#define LAG_HEIGHT 48
-#define LAG_CRIT_BIT ( 1 << 31 )
-#define LAG_WARN_BIT ( 1 << 30 )
+#define LAG_CRIT_BIT (1 << 31)
+#define LAG_WARN_BIT (1 << 30)
#define LAG_BASE 0xD5
#define LAG_WARN 0xDC
@@ -511,85 +519,89 @@ static struct {
unsigned head;
} lag;
-void SCR_LagClear( void ) {
+void SCR_LagClear(void)
+{
lag.head = 0;
}
-void SCR_LagSample( void ) {
+void SCR_LagSample(void)
+{
int i = cls.netchan->incoming_acknowledged & CMD_MASK;
client_history_t *h = &cl.history[i];
unsigned ping;
h->rcvd = cls.realtime;
- if( !h->cmdNumber || h->rcvd < h->sent ) {
+ if (!h->cmdNumber || h->rcvd < h->sent) {
return;
}
ping = h->rcvd - h->sent;
- for( i = 0; i < cls.netchan->dropped; i++ ) {
+ for (i = 0; i < cls.netchan->dropped; i++) {
lag.samples[lag.head % LAG_WIDTH] = ping | LAG_CRIT_BIT;
lag.head++;
}
- if( cl.frameflags & FF_SURPRESSED ) {
+ if (cl.frameflags & FF_SURPRESSED) {
ping |= LAG_WARN_BIT;
}
lag.samples[lag.head % LAG_WIDTH] = ping;
lag.head++;
}
-static void draw_ping_graph( int x, int y ) {
- int i, j, v, c, max = Cvar_ClampInteger( scr_lag_max, 16, 480 );
+static void draw_ping_graph(int x, int y)
+{
+ int i, j, v, c, max = Cvar_ClampInteger(scr_lag_max, 16, 480);
- for( i = 0; i < LAG_WIDTH; i++ ) {
+ for (i = 0; i < LAG_WIDTH; i++) {
j = lag.head - i - 1;
- if( j < 0 ) {
+ if (j < 0) {
break;
}
v = lag.samples[j % LAG_WIDTH];
- if( v & LAG_CRIT_BIT ) {
+ if (v & LAG_CRIT_BIT) {
c = LAG_CRIT;
- } else if( v & LAG_WARN_BIT ) {
+ } else if (v & LAG_WARN_BIT) {
c = LAG_WARN;
} else {
c = LAG_BASE;
}
- v &= ~(LAG_WARN_BIT|LAG_CRIT_BIT);
+ v &= ~(LAG_WARN_BIT | LAG_CRIT_BIT);
v = v * LAG_HEIGHT / max;
- if( v > LAG_HEIGHT ) {
+ if (v > LAG_HEIGHT) {
v = LAG_HEIGHT;
}
- R_DrawFill8( x + LAG_WIDTH - i - 1, y + LAG_HEIGHT - v, 1, v, c );
+ R_DrawFill8(x + LAG_WIDTH - i - 1, y + LAG_HEIGHT - v, 1, v, c);
}
}
-static void draw_lagometer( void ) {
+static void draw_lagometer(void)
+{
int x = scr_lag_x->integer;
int y = scr_lag_y->integer;
- if( x < 0 ) {
+ if (x < 0) {
x += scr.hud_width - LAG_WIDTH + 1;
}
- if( y < 0 ) {
+ if (y < 0) {
y += scr.hud_height - LAG_HEIGHT + 1;
}
// draw ping graph
- if( scr_lag_draw->integer ) {
- if( scr_lag_draw->integer > 1 ) {
- R_DrawFill8( x, y, LAG_WIDTH, LAG_HEIGHT, 4 );
+ if (scr_lag_draw->integer) {
+ if (scr_lag_draw->integer > 1) {
+ R_DrawFill8(x, y, LAG_WIDTH, LAG_HEIGHT, 4);
}
- draw_ping_graph( x, y );
+ draw_ping_graph(x, y);
}
// draw phone jack
- if( cls.netchan && cls.netchan->outgoing_sequence - cls.netchan->incoming_acknowledged >= CMD_BACKUP ) {
- if( ( cls.realtime >> 8 ) & 3 ) {
- R_DrawStretchPic( x, y, LAG_WIDTH, LAG_HEIGHT, scr.net_pic );
+ if (cls.netchan && cls.netchan->outgoing_sequence - cls.netchan->incoming_acknowledged >= CMD_BACKUP) {
+ if ((cls.realtime >> 8) & 3) {
+ R_DrawStretchPic(x, y, LAG_WIDTH, LAG_HEIGHT, scr.net_pic);
}
}
}
@@ -612,34 +624,37 @@ typedef struct {
color_t color;
} drawobj_t;
-#define FOR_EACH_DRAWOBJ( obj ) \
- LIST_FOR_EACH( drawobj_t, obj, &scr_objects, entry )
-#define FOR_EACH_DRAWOBJ_SAFE( obj, next ) \
- LIST_FOR_EACH_SAFE( drawobj_t, obj, next, &scr_objects, entry )
+#define FOR_EACH_DRAWOBJ(obj) \
+ LIST_FOR_EACH(drawobj_t, obj, &scr_objects, entry)
+#define FOR_EACH_DRAWOBJ_SAFE(obj, next) \
+ LIST_FOR_EACH_SAFE(drawobj_t, obj, next, &scr_objects, entry)
-static LIST_DECL( scr_objects );
+static LIST_DECL(scr_objects);
-static void SCR_Color_g( genctx_t *ctx ) {
+static void SCR_Color_g(genctx_t *ctx)
+{
int color;
- for( color = 0; color < 10; color++ ) {
- if( !Prompt_AddMatch( ctx, colorNames[color] ) ) {
+ for (color = 0; color < 10; color++) {
+ if (!Prompt_AddMatch(ctx, colorNames[color])) {
break;
}
}
}
-static void SCR_Draw_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Cvar_Variable_g( ctx );
- Cmd_Macro_g( ctx );
- } else if( argnum == 4 ) {
- SCR_Color_g( ctx );
+static void SCR_Draw_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Cvar_Variable_g(ctx);
+ Cmd_Macro_g(ctx);
+ } else if (argnum == 4) {
+ SCR_Color_g(ctx);
}
}
// draw cl_fps -1 80
-static void SCR_Draw_f( void ) {
+static void SCR_Draw_f(void)
+{
int x, y;
const char *s, *c;
drawobj_t *obj;
@@ -648,163 +663,167 @@ static void SCR_Draw_f( void ) {
int flags;
int argc = Cmd_Argc();
- if( argc == 1 ) {
- if( LIST_EMPTY( &scr_objects ) ) {
- Com_Printf( "No draw strings registered.\n" );
+ if (argc == 1) {
+ if (LIST_EMPTY(&scr_objects)) {
+ Com_Printf("No draw strings registered.\n");
return;
}
- Com_Printf( "Name X Y\n"
- "--------------- ---- ----\n" );
- FOR_EACH_DRAWOBJ( obj ) {
+ Com_Printf("Name X Y\n"
+ "--------------- ---- ----\n");
+ FOR_EACH_DRAWOBJ(obj) {
s = obj->macro ? obj->macro->name : obj->cvar->name;
- Com_Printf( "%-15s %4d %4d\n", s, obj->x, obj->y );
+ Com_Printf("%-15s %4d %4d\n", s, obj->x, obj->y);
}
return;
}
- if( argc < 4 ) {
- Com_Printf( "Usage: %s <name> <x> <y> [color]\n", Cmd_Argv( 0 ) );
+ if (argc < 4) {
+ Com_Printf("Usage: %s <name> <x> <y> [color]\n", Cmd_Argv(0));
return;
}
color.u32 = U32_BLACK;
flags = UI_IGNORECOLOR;
- s = Cmd_Argv( 1 );
- x = atoi( Cmd_Argv( 2 ) );
- if( x < 0 ) {
+ s = Cmd_Argv(1);
+ x = atoi(Cmd_Argv(2));
+ if (x < 0) {
flags |= UI_RIGHT;
}
- y = atoi( Cmd_Argv( 3 ) );
+ y = atoi(Cmd_Argv(3));
- if( argc > 4 ) {
- c = Cmd_Argv( 4 );
- if( !strcmp( c, "alt" ) ) {
+ if (argc > 4) {
+ c = Cmd_Argv(4);
+ if (!strcmp(c, "alt")) {
flags |= UI_ALTCOLOR;
} else {
- if( !SCR_ParseColor( c, &color ) ) {
- Com_Printf( "Unknown color '%s'\n", c );
+ if (!SCR_ParseColor(c, &color)) {
+ Com_Printf("Unknown color '%s'\n", c);
return;
}
flags &= ~UI_IGNORECOLOR;
}
}
- obj = Z_Malloc( sizeof( *obj ) );
+ obj = Z_Malloc(sizeof(*obj));
obj->x = x;
obj->y = y;
obj->flags = flags;
obj->color.u32 = color.u32;
- macro = Cmd_FindMacro( s );
- if( macro ) {
+ macro = Cmd_FindMacro(s);
+ if (macro) {
obj->cvar = NULL;
obj->macro = macro;
} else {
- obj->cvar = Cvar_WeakGet( s );
+ obj->cvar = Cvar_WeakGet(s);
obj->macro = NULL;
}
- List_Append( &scr_objects, &obj->entry );
+ List_Append(&scr_objects, &obj->entry);
}
-static void SCR_Draw_g( genctx_t *ctx ) {
+static void SCR_Draw_g(genctx_t *ctx)
+{
drawobj_t *obj;
const char *s;
- if( LIST_EMPTY( &scr_objects ) ) {
+ if (LIST_EMPTY(&scr_objects)) {
return;
}
- Prompt_AddMatch( ctx, "all" );
-
- FOR_EACH_DRAWOBJ( obj ) {
+ Prompt_AddMatch(ctx, "all");
+
+ FOR_EACH_DRAWOBJ(obj) {
s = obj->macro ? obj->macro->name : obj->cvar->name;
- if( !Prompt_AddMatch( ctx, s ) ) {
+ if (!Prompt_AddMatch(ctx, s)) {
break;
}
}
}
-static void SCR_UnDraw_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- SCR_Draw_g( ctx );
+static void SCR_UnDraw_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ SCR_Draw_g(ctx);
}
}
-static void SCR_UnDraw_f( void ) {
+static void SCR_UnDraw_f(void)
+{
char *s;
drawobj_t *obj, *next;
cmd_macro_t *macro;
cvar_t *cvar;
qboolean deleted;
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <name>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <name>\n", Cmd_Argv(0));
return;
}
- if( LIST_EMPTY( &scr_objects ) ) {
- Com_Printf( "No draw strings registered.\n" );
+ if (LIST_EMPTY(&scr_objects)) {
+ Com_Printf("No draw strings registered.\n");
return;
}
- s = Cmd_Argv( 1 );
- if( !strcmp( s, "all" ) ) {
- FOR_EACH_DRAWOBJ_SAFE( obj, next ) {
- Z_Free( obj );
+ s = Cmd_Argv(1);
+ if (!strcmp(s, "all")) {
+ FOR_EACH_DRAWOBJ_SAFE(obj, next) {
+ Z_Free(obj);
}
- List_Init( &scr_objects );
- Com_Printf( "Deleted all draw strings.\n" );
+ List_Init(&scr_objects);
+ Com_Printf("Deleted all draw strings.\n");
return;
}
cvar = NULL;
- macro = Cmd_FindMacro( s );
- if( !macro ) {
- cvar = Cvar_WeakGet( s );
+ macro = Cmd_FindMacro(s);
+ if (!macro) {
+ cvar = Cvar_WeakGet(s);
}
deleted = qfalse;
- FOR_EACH_DRAWOBJ_SAFE( obj, next ) {
- if( obj->macro == macro && obj->cvar == cvar ) {
- List_Remove( &obj->entry );
- Z_Free( obj );
+ FOR_EACH_DRAWOBJ_SAFE(obj, next) {
+ if (obj->macro == macro && obj->cvar == cvar) {
+ List_Remove(&obj->entry);
+ Z_Free(obj);
deleted = qtrue;
}
}
- if( !deleted ) {
- Com_Printf( "Draw string '%s' not found.\n", s );
+ if (!deleted) {
+ Com_Printf("Draw string '%s' not found.\n", s);
}
}
-static void draw_objects( void ) {
+static void draw_objects(void)
+{
char buffer[MAX_QPATH];
int x, y;
drawobj_t *obj;
- FOR_EACH_DRAWOBJ( obj ) {
+ FOR_EACH_DRAWOBJ(obj) {
x = obj->x;
y = obj->y;
- if( x < 0 ) {
+ if (x < 0) {
x += scr.hud_width + 1;
}
- if( y < 0 ) {
+ if (y < 0) {
y += scr.hud_height - CHAR_HEIGHT + 1;
}
- if( !( obj->flags & UI_IGNORECOLOR ) ) {
- R_SetColor( obj->color.u32 );
+ if (!(obj->flags & UI_IGNORECOLOR)) {
+ R_SetColor(obj->color.u32);
}
- if( obj->macro ) {
- obj->macro->function( buffer, sizeof( buffer ) );
- SCR_DrawString( x, y, obj->flags, buffer );
+ if (obj->macro) {
+ obj->macro->function(buffer, sizeof(buffer));
+ SCR_DrawString(x, y, obj->flags, buffer);
} else {
- SCR_DrawString( x, y, obj->flags, obj->cvar->string );
+ SCR_DrawString(x, y, obj->flags, obj->cvar->string);
}
- if( !( obj->flags & UI_IGNORECOLOR ) ) {
+ if (!(obj->flags & UI_IGNORECOLOR)) {
R_ClearColor();
- R_SetAlpha( scr_alpha->value );
+ R_SetAlpha(scr_alpha->value);
}
}
}
@@ -817,57 +836,60 @@ DEBUG STUFF
===============================================================================
*/
-static void draw_turtle( void ) {
+static void draw_turtle(void)
+{
int x = CHAR_WIDTH;
- int y = scr.hud_height - 11*CHAR_HEIGHT;
+ int y = scr.hud_height - 11 * CHAR_HEIGHT;
-#define DF( f ) \
- if( cl.frameflags & FF_ ## f ) { \
- SCR_DrawString( x, y, UI_ALTCOLOR, #f ); \
+#define DF(f) \
+ if (cl.frameflags & FF_##f) { \
+ SCR_DrawString(x, y, UI_ALTCOLOR, #f); \
y += CHAR_HEIGHT; \
}
- if( scr_showturtle->integer > 1 ) {
- DF( SURPRESSED )
+ if (scr_showturtle->integer > 1) {
+ DF(SURPRESSED)
}
- DF( CLIENTPRED )
- if( scr_showturtle->integer > 1 ) {
- DF( CLIENTDROP )
- DF( SERVERDROP )
+ DF(CLIENTPRED)
+ if (scr_showturtle->integer > 1) {
+ DF(CLIENTDROP)
+ DF(SERVERDROP)
}
- DF( BADFRAME )
- DF( OLDFRAME )
- DF( OLDENT )
- DF( NODELTA )
+ DF(BADFRAME)
+ DF(OLDFRAME)
+ DF(OLDENT)
+ DF(NODELTA)
#undef DF
}
#ifdef _DEBUG
-static void draw_stats( void ) {
+static void draw_stats(void)
+{
char buffer[MAX_QPATH];
int i, j;
int x, y;
j = scr_showstats->integer;
- if( j > MAX_STATS ) {
+ if (j > MAX_STATS) {
j = MAX_STATS;
}
x = CHAR_WIDTH;
- y = ( scr.hud_height - j * CHAR_HEIGHT ) / 2;
- for( i = 0; i < j; i++ ) {
- Q_snprintf( buffer, sizeof( buffer ), "%2d: %d", i, cl.frame.ps.stats[i] );
- if( cl.oldframe.ps.stats[i] != cl.frame.ps.stats[i] ) {
- R_SetColor( U32_RED );
+ y = (scr.hud_height - j * CHAR_HEIGHT) / 2;
+ for (i = 0; i < j; i++) {
+ Q_snprintf(buffer, sizeof(buffer), "%2d: %d", i, cl.frame.ps.stats[i]);
+ if (cl.oldframe.ps.stats[i] != cl.frame.ps.stats[i]) {
+ R_SetColor(U32_RED);
}
- R_DrawString( x, y, 0, MAX_STRING_CHARS, buffer, scr.font_pic );
+ R_DrawString(x, y, 0, MAX_STRING_CHARS, buffer, scr.font_pic);
R_ClearColor();
y += CHAR_HEIGHT;
}
}
-static void draw_pmove( void ) {
+static void draw_pmove(void)
+{
static const char * const types[] = {
"NORMAL", "SPECTATOR", "DEAD", "GIB", "FREEZE"
};
@@ -877,20 +899,20 @@ static void draw_pmove( void ) {
"NO_PREDICTION", "TELEPORT_BIT"
};
int x = CHAR_WIDTH;
- int y = ( scr.hud_height - 2 * CHAR_HEIGHT ) / 2;
+ int y = (scr.hud_height - 2 * CHAR_HEIGHT) / 2;
unsigned i, j;
i = cl.frame.ps.pmove.pm_type;
- if( i > PM_FREEZE ) {
+ if (i > PM_FREEZE) {
i = PM_FREEZE;
}
- R_DrawString( x, y, 0, MAX_STRING_CHARS, types[i], scr.font_pic );
+ R_DrawString(x, y, 0, MAX_STRING_CHARS, types[i], scr.font_pic);
y += CHAR_HEIGHT;
j = cl.frame.ps.pmove.pm_flags;
- for( i = 0; i < 8; i++ ) {
- if( j & ( 1 << i ) ) {
- x = R_DrawString( x, y, 0, MAX_STRING_CHARS, flags[i], scr.font_pic );
+ for (i = 0; i < 8; i++) {
+ if (j & (1 << i)) {
+ x = R_DrawString(x, y, 0, MAX_STRING_CHARS, flags[i], scr.font_pic);
x += CHAR_WIDTH;
}
}
@@ -901,11 +923,12 @@ static void draw_pmove( void ) {
//============================================================================
// Sets scr_vrect, the coordinates of the rendered window
-static void calc_vrect( void ) {
+static void calc_vrect(void)
+{
int size;
// bound viewsize
- size = Cvar_ClampInteger( scr_viewsize, 40, 100 );
+ size = Cvar_ClampInteger(scr_viewsize, 40, 100);
scr_viewsize->modified = qfalse;
scr_vrect.width = scr.hud_width * size / 100;
@@ -914,8 +937,8 @@ static void calc_vrect( void ) {
scr_vrect.height = scr.hud_height * size / 100;
scr_vrect.height &= ~1;
- scr_vrect.x = ( scr.hud_width - scr_vrect.width ) / 2;
- scr_vrect.y = ( scr.hud_height - scr_vrect.height ) / 2;
+ scr_vrect.x = (scr.hud_width - scr_vrect.width) / 2;
+ scr_vrect.y = (scr.hud_height - scr_vrect.height) / 2;
}
/*
@@ -925,8 +948,9 @@ SCR_SizeUp_f
Keybinding command
=================
*/
-static void SCR_SizeUp_f( void ) {
- Cvar_SetInteger( scr_viewsize, scr_viewsize->integer + 10, FROM_CONSOLE );
+static void SCR_SizeUp_f(void)
+{
+ Cvar_SetInteger(scr_viewsize, scr_viewsize->integer + 10, FROM_CONSOLE);
}
/*
@@ -936,8 +960,9 @@ SCR_SizeDown_f
Keybinding command
=================
*/
-static void SCR_SizeDown_f( void ) {
- Cvar_SetInteger( scr_viewsize, scr_viewsize->integer - 10, FROM_CONSOLE );
+static void SCR_SizeDown_f(void)
+{
+ Cvar_SetInteger(scr_viewsize, scr_viewsize->integer - 10, FROM_CONSOLE);
}
/*
@@ -947,25 +972,26 @@ SCR_Sky_f
Set a specific sky and rotation speed
=================
*/
-static void SCR_Sky_f( void ) {
+static void SCR_Sky_f(void)
+{
float rotate = 0;
vec3_t axis = { 0, 0, 1 };
int argc = Cmd_Argc();
- if( argc < 2 ) {
- Com_Printf ("Usage: sky <basename> [rotate] [axis x y z]\n");
+ if (argc < 2) {
+ Com_Printf("Usage: sky <basename> [rotate] [axis x y z]\n");
return;
}
- if( argc > 2 )
+ if (argc > 2)
rotate = atof(Cmd_Argv(2));
- if( argc == 6 ) {
+ if (argc == 6) {
axis[0] = atof(Cmd_Argv(3));
axis[1] = atof(Cmd_Argv(4));
axis[2] = atof(Cmd_Argv(5));
}
- R_SetSky (Cmd_Argv(1), rotate, axis);
+ R_SetSky(Cmd_Argv(1), rotate, axis);
}
/*
@@ -973,64 +999,66 @@ static void SCR_Sky_f( void ) {
SCR_TimeRefresh_f
================
*/
-static void SCR_TimeRefresh_f (void) {
+static void SCR_TimeRefresh_f(void)
+{
int i;
unsigned start, stop;
float time;
- if( cls.state != ca_active ) {
- Com_Printf( "No map loaded.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("No map loaded.\n");
return;
}
- start = Sys_Milliseconds ();
+ start = Sys_Milliseconds();
if (Cmd_Argc() == 2) {
// run without page flipping
R_BeginFrame();
- for (i=0 ; i<128 ; i++) {
- cl.refdef.viewangles[1] = i/128.0f*360.0f;
- R_RenderFrame (&cl.refdef);
+ for (i = 0; i < 128; i++) {
+ cl.refdef.viewangles[1] = i / 128.0f * 360.0f;
+ R_RenderFrame(&cl.refdef);
}
R_EndFrame();
} else {
- for (i=0 ; i<128 ; i++) {
- cl.refdef.viewangles[1] = i/128.0f*360.0f;
+ for (i = 0; i < 128; i++) {
+ cl.refdef.viewangles[1] = i / 128.0f * 360.0f;
R_BeginFrame();
- R_RenderFrame (&cl.refdef);
+ R_RenderFrame(&cl.refdef);
R_EndFrame();
}
}
stop = Sys_Milliseconds();
- time = (stop-start)*0.001f;
- Com_Printf ("%f seconds (%f fps)\n", time, 128.0f/time);
+ time = (stop - start) * 0.001f;
+ Com_Printf("%f seconds (%f fps)\n", time, 128.0f / time);
}
//============================================================================
-static void scr_crosshair_changed( cvar_t *self ) {
+static void scr_crosshair_changed(cvar_t *self)
+{
char buffer[16];
int w, h;
float scale;
- if( scr_crosshair->integer > 0 ) {
- Q_snprintf( buffer, sizeof( buffer ), "ch%i", scr_crosshair->integer );
- scr.crosshair_pic = R_RegisterPic( buffer );
- R_GetPicSize( &w, &h, scr.crosshair_pic );
+ if (scr_crosshair->integer > 0) {
+ Q_snprintf(buffer, sizeof(buffer), "ch%i", scr_crosshair->integer);
+ scr.crosshair_pic = R_RegisterPic(buffer);
+ R_GetPicSize(&w, &h, scr.crosshair_pic);
// prescale
- scale = Cvar_ClampValue( ch_scale, 0.1f, 9.0f );
+ scale = Cvar_ClampValue(ch_scale, 0.1f, 9.0f);
scr.crosshair_width = w * scale;
scr.crosshair_height = h * scale;
- if( scr.crosshair_width < 1 )
+ if (scr.crosshair_width < 1)
scr.crosshair_width = 1;
- if( scr.crosshair_height < 1 )
+ if (scr.crosshair_height < 1)
scr.crosshair_height = 1;
- if( ch_health->integer ) {
+ if (ch_health->integer) {
SCR_SetCrosshairColor();
} else {
scr.crosshair_color.u8[0] = (byte)(ch_red->value * 255);
@@ -1043,16 +1071,17 @@ static void scr_crosshair_changed( cvar_t *self ) {
}
}
-void SCR_SetCrosshairColor( void ) {
+void SCR_SetCrosshairColor(void)
+{
int health;
- if( !ch_health->integer ) {
+ if (!ch_health->integer) {
return;
}
health = cl.frame.ps.stats[STAT_HEALTH];
- if( health <= 0 ) {
- VectorSet( scr.crosshair_color.u8, 0, 0, 0 );
+ if (health <= 0) {
+ VectorSet(scr.crosshair_color.u8, 0, 0, 0);
return;
}
@@ -1060,25 +1089,26 @@ void SCR_SetCrosshairColor( void ) {
scr.crosshair_color.u8[0] = 255;
// green
- if( health >= 66 ) {
+ if (health >= 66) {
scr.crosshair_color.u8[1] = 255;
- } else if( health < 33 ) {
+ } else if (health < 33) {
scr.crosshair_color.u8[1] = 0;
} else {
- scr.crosshair_color.u8[1] = ( 255 * ( health - 33 ) ) / 33;
+ scr.crosshair_color.u8[1] = (255 * (health - 33)) / 33;
}
// blue
- if( health >= 99 ) {
+ if (health >= 99) {
scr.crosshair_color.u8[2] = 255;
- } else if( health < 66 ) {
+ } else if (health < 66) {
scr.crosshair_color.u8[2] = 0;
} else {
- scr.crosshair_color.u8[2] = ( 255 * ( health - 66 ) ) / 33;
+ scr.crosshair_color.u8[2] = (255 * (health - 66)) / 33;
}
}
-void SCR_ModeChanged( void ) {
+void SCR_ModeChanged(void)
+{
IN_Activate();
#if USE_UI
UI_ModeChanged();
@@ -1093,37 +1123,39 @@ void SCR_ModeChanged( void ) {
SCR_RegisterMedia
==================
*/
-void SCR_RegisterMedia( void ) {
+void SCR_RegisterMedia(void)
+{
int i, j;
- for( i = 0; i < 2; i++ )
- for( j = 0; j < STAT_PICS; j++ )
- scr.sb_pics[i][j] = R_RegisterPic( sb_nums[i][j] );
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < STAT_PICS; j++)
+ scr.sb_pics[i][j] = R_RegisterPic(sb_nums[i][j]);
- scr.inven_pic = R_RegisterPic( "inventory" );
- scr.field_pic = R_RegisterPic( "field_3" );
+ scr.inven_pic = R_RegisterPic("inventory");
+ scr.field_pic = R_RegisterPic("field_3");
- scr.backtile_pic = R_RegisterPic( "backtile" );
+ scr.backtile_pic = R_RegisterPic("backtile");
- scr.pause_pic = R_RegisterPic( "pause" );
- R_GetPicSize( &scr.pause_width, &scr.pause_height, scr.pause_pic );
+ scr.pause_pic = R_RegisterPic("pause");
+ R_GetPicSize(&scr.pause_width, &scr.pause_height, scr.pause_pic);
- scr.loading_pic = R_RegisterPic( "loading" );
- R_GetPicSize( &scr.loading_width, &scr.loading_height, scr.loading_pic );
+ scr.loading_pic = R_RegisterPic("loading");
+ R_GetPicSize(&scr.loading_width, &scr.loading_height, scr.loading_pic);
- scr.net_pic = R_RegisterPic( "net" );
- scr.font_pic = R_RegisterFont( scr_font->string );
+ scr.net_pic = R_RegisterPic("net");
+ scr.font_pic = R_RegisterFont(scr_font->string);
- scr_crosshair_changed( scr_crosshair );
+ scr_crosshair_changed(scr_crosshair);
}
-static void scr_font_changed( cvar_t *self ) {
- scr.font_pic = R_RegisterFont( self->string );
+static void scr_font_changed(cvar_t *self)
+{
+ scr.font_pic = R_RegisterFont(self->string);
}
static const cmdreg_t scr_cmds[] = {
{ "timerefresh", SCR_TimeRefresh_f },
- { "sizeup", SCR_SizeUp_f },
+ { "sizeup", SCR_SizeUp_f },
{ "sizedown", SCR_SizeDown_f },
{ "sky", SCR_Sky_f },
{ "draw", SCR_Draw_f, SCR_Draw_c },
@@ -1136,60 +1168,62 @@ static const cmdreg_t scr_cmds[] = {
SCR_Init
==================
*/
-void SCR_Init( void ) {
- scr_viewsize = Cvar_Get ("viewsize", "100", CVAR_ARCHIVE);
- scr_showpause = Cvar_Get ("scr_showpause", "1", 0);
- scr_centertime = Cvar_Get ("scr_centertime", "2.5", 0);
+void SCR_Init(void)
+{
+ scr_viewsize = Cvar_Get("viewsize", "100", CVAR_ARCHIVE);
+ scr_showpause = Cvar_Get("scr_showpause", "1", 0);
+ scr_centertime = Cvar_Get("scr_centertime", "2.5", 0);
#ifdef _DEBUG
- scr_netgraph = Cvar_Get ("netgraph", "0", 0);
- scr_timegraph = Cvar_Get ("timegraph", "0", 0);
- scr_debuggraph = Cvar_Get ("debuggraph", "0", 0);
- scr_graphheight = Cvar_Get ("graphheight", "32", 0);
- scr_graphscale = Cvar_Get ("graphscale", "1", 0);
- scr_graphshift = Cvar_Get ("graphshift", "0", 0);
+ scr_netgraph = Cvar_Get("netgraph", "0", 0);
+ scr_timegraph = Cvar_Get("timegraph", "0", 0);
+ scr_debuggraph = Cvar_Get("debuggraph", "0", 0);
+ scr_graphheight = Cvar_Get("graphheight", "32", 0);
+ scr_graphscale = Cvar_Get("graphscale", "1", 0);
+ scr_graphshift = Cvar_Get("graphshift", "0", 0);
#endif
- scr_demobar = Cvar_Get( "scr_demobar", "1", 0 );
- scr_font = Cvar_Get( "scr_font", "conchars", 0 );
+ scr_demobar = Cvar_Get("scr_demobar", "1", 0);
+ scr_font = Cvar_Get("scr_font", "conchars", 0);
scr_font->changed = scr_font_changed;
- scr_scale = Cvar_Get( "scr_scale", "1", 0 );
- scr_crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE);
+ scr_scale = Cvar_Get("scr_scale", "1", 0);
+ scr_crosshair = Cvar_Get("crosshair", "0", CVAR_ARCHIVE);
scr_crosshair->changed = scr_crosshair_changed;
- ch_health = Cvar_Get ("ch_health", "0", 0);
+ ch_health = Cvar_Get("ch_health", "0", 0);
ch_health->changed = scr_crosshair_changed;
- ch_red = Cvar_Get ("ch_red", "1", 0);
+ ch_red = Cvar_Get("ch_red", "1", 0);
ch_red->changed = scr_crosshair_changed;
- ch_green = Cvar_Get ("ch_green", "1", 0);
+ ch_green = Cvar_Get("ch_green", "1", 0);
ch_green->changed = scr_crosshair_changed;
- ch_blue = Cvar_Get ("ch_blue", "1", 0);
+ ch_blue = Cvar_Get("ch_blue", "1", 0);
ch_blue->changed = scr_crosshair_changed;
- ch_alpha = Cvar_Get ("ch_alpha", "1", 0);
+ ch_alpha = Cvar_Get("ch_alpha", "1", 0);
ch_alpha->changed = scr_crosshair_changed;
- ch_scale = Cvar_Get ("ch_scale", "1", 0);
+ ch_scale = Cvar_Get("ch_scale", "1", 0);
ch_scale->changed = scr_crosshair_changed;
- ch_x = Cvar_Get ("ch_x", "0", 0);
- ch_y = Cvar_Get ("ch_y", "0", 0);
-
- scr_draw2d = Cvar_Get( "scr_draw2d", "2", 0 );
- scr_showturtle = Cvar_Get( "scr_showturtle", "1", 0 );
- scr_lag_x = Cvar_Get( "scr_lag_x", "-1", 0 );
- scr_lag_y = Cvar_Get( "scr_lag_y", "-1", 0 );
- scr_lag_draw = Cvar_Get( "scr_lag_draw", "0", 0 );
- scr_lag_max = Cvar_Get( "scr_lag_max", "200", 0 );
- scr_alpha = Cvar_Get( "scr_alpha", "1", 0 );
+ ch_x = Cvar_Get("ch_x", "0", 0);
+ ch_y = Cvar_Get("ch_y", "0", 0);
+
+ scr_draw2d = Cvar_Get("scr_draw2d", "2", 0);
+ scr_showturtle = Cvar_Get("scr_showturtle", "1", 0);
+ scr_lag_x = Cvar_Get("scr_lag_x", "-1", 0);
+ scr_lag_y = Cvar_Get("scr_lag_y", "-1", 0);
+ scr_lag_draw = Cvar_Get("scr_lag_draw", "0", 0);
+ scr_lag_max = Cvar_Get("scr_lag_max", "200", 0);
+ scr_alpha = Cvar_Get("scr_alpha", "1", 0);
#ifdef _DEBUG
- scr_showstats = Cvar_Get( "scr_showstats", "0", 0 );
- scr_showpmove = Cvar_Get( "scr_showpmove", "0", 0 );
+ scr_showstats = Cvar_Get("scr_showstats", "0", 0);
+ scr_showpmove = Cvar_Get("scr_showpmove", "0", 0);
#endif
- Cmd_Register( scr_cmds );
+ Cmd_Register(scr_cmds);
scr.initialized = qtrue;
}
-void SCR_Shutdown( void ) {
- Cmd_Deregister( scr_cmds );
+void SCR_Shutdown(void)
+{
+ Cmd_Deregister(scr_cmds);
scr.initialized = qfalse;
}
@@ -1200,20 +1234,21 @@ void SCR_Shutdown( void ) {
SCR_BeginLoadingPlaque
================
*/
-void SCR_BeginLoadingPlaque( void ) {
- if( !cls.state ) {
+void SCR_BeginLoadingPlaque(void)
+{
+ if (!cls.state) {
return;
}
- if( cls.disable_screen ) {
+ if (cls.disable_screen) {
return;
}
#ifdef _DEBUG
- if( developer->integer ) {
+ if (developer->integer) {
return;
}
#endif
// if at console or menu, don't bring up the plaque
- if( cls.key_dest & (KEY_CONSOLE|KEY_MENU) ) {
+ if (cls.key_dest & (KEY_CONSOLE | KEY_MENU)) {
return;
}
@@ -1228,8 +1263,9 @@ void SCR_BeginLoadingPlaque( void ) {
SCR_EndLoadingPlaque
================
*/
-void SCR_EndLoadingPlaque( void ) {
- if( !cls.state ) {
+void SCR_EndLoadingPlaque(void)
+{
+ if (!cls.state) {
return;
}
cls.disable_screen = 0;
@@ -1240,33 +1276,34 @@ void SCR_EndLoadingPlaque( void ) {
}
// Clear any parts of the tiled background that were drawn on last frame
-static void tile_clear( void ) {
+static void tile_clear(void)
+{
int top, bottom, left, right;
- //if( con.currentHeight == 1 )
+ //if (con.currentHeight == 1)
// return; // full screen console
- if( scr_viewsize->integer == 100 )
+ if (scr_viewsize->integer == 100)
return; // full screen rendering
top = scr_vrect.y;
bottom = top + scr_vrect.height - 1;
left = scr_vrect.x;
right = left + scr_vrect.width - 1;
-
+
// clear above view screen
- R_TileClear( 0, 0, r_config.width, top, scr.backtile_pic );
+ R_TileClear(0, 0, r_config.width, top, scr.backtile_pic);
// clear below view screen
- R_TileClear( 0, bottom, r_config.width,
- r_config.height - bottom, scr.backtile_pic );
+ R_TileClear(0, bottom, r_config.width,
+ r_config.height - bottom, scr.backtile_pic);
// clear left of view screen
- R_TileClear( 0, top, left, scr_vrect.height, scr.backtile_pic );
-
+ R_TileClear(0, top, left, scr_vrect.height, scr.backtile_pic);
+
// clear right of view screen
- R_TileClear( right, top, r_config.width - right,
- scr_vrect.height, scr.backtile_pic );
+ R_TileClear(right, top, r_config.width - right,
+ scr_vrect.height, scr.backtile_pic);
}
/*
@@ -1282,45 +1319,46 @@ STAT PROGRAMS
#define DIGIT_WIDTH 16
#define ICON_SPACE 8
-#define HUD_DrawString( x, y, string ) \
- R_DrawString( x, y, 0, MAX_STRING_CHARS, string, scr.font_pic )
+#define HUD_DrawString(x, y, string) \
+ R_DrawString(x, y, 0, MAX_STRING_CHARS, string, scr.font_pic)
-#define HUD_DrawAltString( x, y, string ) \
- R_DrawString( x, y, UI_ALTCOLOR, MAX_STRING_CHARS, string, scr.font_pic )
+#define HUD_DrawAltString(x, y, string) \
+ R_DrawString(x, y, UI_ALTCOLOR, MAX_STRING_CHARS, string, scr.font_pic)
-#define HUD_DrawCenterString( x, y, string ) \
- SCR_DrawStringMulti( x, y, UI_CENTER, MAX_STRING_CHARS, string, scr.font_pic )
+#define HUD_DrawCenterString(x, y, string) \
+ SCR_DrawStringMulti(x, y, UI_CENTER, MAX_STRING_CHARS, string, scr.font_pic)
-#define HUD_DrawAltCenterString( x, y, string ) \
- SCR_DrawStringMulti( x, y, UI_CENTER|UI_ALTCOLOR, MAX_STRING_CHARS, string, scr.font_pic )
+#define HUD_DrawAltCenterString(x, y, string) \
+ SCR_DrawStringMulti(x, y, UI_CENTER|UI_ALTCOLOR, MAX_STRING_CHARS, string, scr.font_pic)
-static void HUD_DrawNumber( int x, int y, int color, int width, int value ) {
+static void HUD_DrawNumber(int x, int y, int color, int width, int value)
+{
char num[16], *ptr;
int l;
int frame;
- if( width < 1 )
+ if (width < 1)
return;
// draw number string
- if( width > 5 )
+ if (width > 5)
width = 5;
color &= 1;
- l = Q_scnprintf( num, sizeof( num ), "%i", value );
- if( l > width )
+ l = Q_scnprintf(num, sizeof(num), "%i", value);
+ if (l > width)
l = width;
- x += 2 + DIGIT_WIDTH * ( width - l );
+ x += 2 + DIGIT_WIDTH * (width - l);
ptr = num;
- while( *ptr && l ) {
- if( *ptr == '-' )
+ while (*ptr && l) {
+ if (*ptr == '-')
frame = STAT_MINUS;
else
frame = *ptr - '0';
- R_DrawPic( x, y, scr.sb_pics[color][frame] );
+ R_DrawPic(x, y, scr.sb_pics[color][frame]);
x += DIGIT_WIDTH;
ptr++;
l--;
@@ -1329,7 +1367,8 @@ static void HUD_DrawNumber( int x, int y, int color, int width, int value ) {
#define DISPLAY_ITEMS 17
-static void draw_inventory( void ) {
+static void draw_inventory(void)
+{
int i;
int num, selected_num, item;
int index[MAX_ITEMS];
@@ -1343,61 +1382,62 @@ static void draw_inventory( void ) {
num = 0;
selected_num = 0;
- for( i = 0; i < MAX_ITEMS; i++ ) {
- if( i == selected ) {
+ for (i = 0; i < MAX_ITEMS; i++) {
+ if (i == selected) {
selected_num = num;
}
- if( cl.inventory[i] ) {
+ if (cl.inventory[i]) {
index[num++] = i;
}
}
// determine scroll point
top = selected_num - DISPLAY_ITEMS / 2;
- if( top > num - DISPLAY_ITEMS ) {
+ if (top > num - DISPLAY_ITEMS) {
top = num - DISPLAY_ITEMS;
}
- if( top < 0 ) {
+ if (top < 0) {
top = 0;
}
- x = ( scr.hud_width - 256 ) / 2;
- y = ( scr.hud_height - 240 ) / 2;
+ x = (scr.hud_width - 256) / 2;
+ y = (scr.hud_height - 240) / 2;
- R_DrawPic( x, y + 8, scr.inven_pic );
+ R_DrawPic(x, y + 8, scr.inven_pic);
y += 24;
x += 24;
- HUD_DrawString( x, y, "hotkey ### item" );
+ HUD_DrawString(x, y, "hotkey ### item");
y += CHAR_HEIGHT;
- HUD_DrawString( x, y, "------ --- ----" );
+ HUD_DrawString(x, y, "------ --- ----");
y += CHAR_HEIGHT;
- for( i = top; i < num && i < top + DISPLAY_ITEMS; i++ ) {
+ for (i = top; i < num && i < top + DISPLAY_ITEMS; i++) {
item = index[i];
// search for a binding
- Q_concat( string, sizeof( string ),
- "use ", cl.configstrings[CS_ITEMS + item], NULL );
- bind = Key_GetBinding( string );
-
- Q_snprintf( string, sizeof( string ), "%6s %3i %s",
- bind, cl.inventory[item], cl.configstrings[CS_ITEMS + item] );
-
- if( item != selected ) {
- HUD_DrawAltString( x, y, string );
+ Q_concat(string, sizeof(string),
+ "use ", cl.configstrings[CS_ITEMS + item], NULL);
+ bind = Key_GetBinding(string);
+
+ Q_snprintf(string, sizeof(string), "%6s %3i %s",
+ bind, cl.inventory[item], cl.configstrings[CS_ITEMS + item]);
+
+ if (item != selected) {
+ HUD_DrawAltString(x, y, string);
} else { // draw a blinky cursor by the selected item
- HUD_DrawString( x, y, string );
- if( ( cls.realtime >> 8 ) & 1 ) {
- R_DrawChar( x - CHAR_WIDTH, y, 0, 15, scr.font_pic );
+ HUD_DrawString(x, y, string);
+ if ((cls.realtime >> 8) & 1) {
+ R_DrawChar(x - CHAR_WIDTH, y, 0, 15, scr.font_pic);
}
}
-
+
y += CHAR_HEIGHT;
}
}
-static void draw_layout_string( const char *s ) {
+static void draw_layout_string(const char *s)
+{
char buffer[MAX_QPATH];
int x, y;
int value;
@@ -1406,277 +1446,277 @@ static void draw_layout_string( const char *s ) {
int index;
clientinfo_t *ci;
- if( !s[0] )
+ if (!s[0])
return;
x = 0;
y = 0;
width = 3;
- while( s ) {
- token = COM_Parse( &s );
- if( token[2] == 0 ) {
- if( token[0] == 'x' ) {
- if( token[1] == 'l' ) {
- token = COM_Parse( &s );
- x = atoi( token );
+ while (s) {
+ token = COM_Parse(&s);
+ if (token[2] == 0) {
+ if (token[0] == 'x') {
+ if (token[1] == 'l') {
+ token = COM_Parse(&s);
+ x = atoi(token);
continue;
}
- if( token[1] == 'r' ) {
- token = COM_Parse( &s );
- x = scr.hud_width + atoi( token );
+ if (token[1] == 'r') {
+ token = COM_Parse(&s);
+ x = scr.hud_width + atoi(token);
continue;
}
- if( token[1] == 'v' ) {
- token = COM_Parse( &s );
- x = scr.hud_width / 2 - 160 + atoi( token );
+ if (token[1] == 'v') {
+ token = COM_Parse(&s);
+ x = scr.hud_width / 2 - 160 + atoi(token);
continue;
}
}
- if( token[0] == 'y' ) {
- if( token[1] == 't' ) {
- token = COM_Parse( &s );
- y = atoi( token );
+ if (token[0] == 'y') {
+ if (token[1] == 't') {
+ token = COM_Parse(&s);
+ y = atoi(token);
continue;
}
- if( token[1] == 'b' ) {
- token = COM_Parse( &s );
- y = scr.hud_height + atoi( token );
+ if (token[1] == 'b') {
+ token = COM_Parse(&s);
+ y = scr.hud_height + atoi(token);
continue;
}
- if( token[1] == 'v' ) {
- token = COM_Parse( &s );
- y = scr.hud_height / 2 - 120 + atoi( token );
+ if (token[1] == 'v') {
+ token = COM_Parse(&s);
+ y = scr.hud_height / 2 - 120 + atoi(token);
continue;
}
}
}
- if( !strcmp( token, "pic" ) ) {
+ if (!strcmp(token, "pic")) {
// draw a pic from a stat number
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
value = cl.frame.ps.stats[value];
- if( value < 0 || value >= MAX_IMAGES ) {
- Com_Error( ERR_DROP, "%s: invalid pic index", __func__ );
+ if (value < 0 || value >= MAX_IMAGES) {
+ Com_Error(ERR_DROP, "%s: invalid pic index", __func__);
}
token = cl.configstrings[CS_IMAGES + value];
- if( token[0] ) {
- R_DrawPic( x, y, cl.image_precache[value] );
+ if (token[0]) {
+ R_DrawPic(x, y, cl.image_precache[value]);
}
continue;
}
- if( !strcmp( token, "client" ) ) {
+ if (!strcmp(token, "client")) {
// draw a deathmatch client block
int score, ping, time;
- token = COM_Parse( &s );
- x = scr.hud_width / 2 - 160 + atoi( token );
- token = COM_Parse( &s );
- y = scr.hud_height / 2 - 120 + atoi( token );
+ token = COM_Parse(&s);
+ x = scr.hud_width / 2 - 160 + atoi(token);
+ token = COM_Parse(&s);
+ y = scr.hud_height / 2 - 120 + atoi(token);
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_CLIENTS ) {
- Com_Error( ERR_DROP, "%s: invalid client index", __func__ );
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_CLIENTS) {
+ Com_Error(ERR_DROP, "%s: invalid client index", __func__);
}
ci = &cl.clientinfo[value];
- token = COM_Parse( &s );
- score = atoi( token );
+ token = COM_Parse(&s);
+ score = atoi(token);
- token = COM_Parse( &s );
- ping = atoi( token );
+ token = COM_Parse(&s);
+ ping = atoi(token);
- token = COM_Parse( &s );
- time = atoi( token );
+ token = COM_Parse(&s);
+ time = atoi(token);
- HUD_DrawString( x + 32, y, ci->name );
- Q_snprintf( buffer, sizeof( buffer ), "Score: %i", score );
- HUD_DrawString( x + 32, y + CHAR_HEIGHT, buffer );
- Q_snprintf( buffer, sizeof( buffer ), "Ping: %i", ping );
- HUD_DrawString( x + 32, y + 2 * CHAR_HEIGHT, buffer );
- Q_snprintf( buffer, sizeof( buffer ), "Time: %i", time );
- HUD_DrawString( x + 32, y + 3 * CHAR_HEIGHT, buffer );
+ HUD_DrawString(x + 32, y, ci->name);
+ Q_snprintf(buffer, sizeof(buffer), "Score: %i", score);
+ HUD_DrawString(x + 32, y + CHAR_HEIGHT, buffer);
+ Q_snprintf(buffer, sizeof(buffer), "Ping: %i", ping);
+ HUD_DrawString(x + 32, y + 2 * CHAR_HEIGHT, buffer);
+ Q_snprintf(buffer, sizeof(buffer), "Time: %i", time);
+ HUD_DrawString(x + 32, y + 3 * CHAR_HEIGHT, buffer);
- if( !ci->icon ) {
+ if (!ci->icon) {
ci = &cl.baseclientinfo;
}
- R_DrawPic( x, y, ci->icon );
+ R_DrawPic(x, y, ci->icon);
continue;
}
- if( !strcmp( token, "ctf" ) ) {
+ if (!strcmp(token, "ctf")) {
// draw a ctf client block
int score, ping;
- token = COM_Parse( &s );
- x = scr.hud_width / 2 - 160 + atoi( token );
- token = COM_Parse( &s );
- y = scr.hud_height / 2 - 120 + atoi( token );
+ token = COM_Parse(&s);
+ x = scr.hud_width / 2 - 160 + atoi(token);
+ token = COM_Parse(&s);
+ y = scr.hud_height / 2 - 120 + atoi(token);
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_CLIENTS ) {
- Com_Error( ERR_DROP, "%s: invalid client index", __func__ );
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_CLIENTS) {
+ Com_Error(ERR_DROP, "%s: invalid client index", __func__);
}
ci = &cl.clientinfo[value];
- token = COM_Parse( &s );
- score = atoi( token );
+ token = COM_Parse(&s);
+ score = atoi(token);
- token = COM_Parse( &s );
- ping = atoi( token );
- if( ping > 999 )
+ token = COM_Parse(&s);
+ ping = atoi(token);
+ if (ping > 999)
ping = 999;
- Q_snprintf( buffer, sizeof( buffer ), "%3d %3d %-12.12s",
- score, ping, ci->name );
- if( value == cl.frame.clientNum ) {
- HUD_DrawAltString( x, y, buffer );
+ Q_snprintf(buffer, sizeof(buffer), "%3d %3d %-12.12s",
+ score, ping, ci->name);
+ if (value == cl.frame.clientNum) {
+ HUD_DrawAltString(x, y, buffer);
} else {
- HUD_DrawString( x, y, buffer );
+ HUD_DrawString(x, y, buffer);
}
continue;
}
- if( !strcmp( token, "picn" ) ) {
+ if (!strcmp(token, "picn")) {
// draw a pic from a name
- token = COM_Parse( &s );
- R_DrawPic( x, y, R_RegisterPic( token ) );
+ token = COM_Parse(&s);
+ R_DrawPic(x, y, R_RegisterPic(token));
continue;
}
- if( !strcmp( token, "num" ) ) {
+ if (!strcmp(token, "num")) {
// draw a number
- token = COM_Parse( &s );
- width = atoi( token );
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ token = COM_Parse(&s);
+ width = atoi(token);
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
value = cl.frame.ps.stats[value];
- HUD_DrawNumber( x, y, 0, width, value );
+ HUD_DrawNumber(x, y, 0, width, value);
continue;
}
- if( !strcmp( token, "hnum" ) ) {
+ if (!strcmp(token, "hnum")) {
// health number
int color;
width = 3;
value = cl.frame.ps.stats[STAT_HEALTH];
- if( value > 25 )
+ if (value > 25)
color = 0; // green
- else if( value > 0 )
- color = ( ( cl.frame.number / CL_FRAMEDIV ) >> 2 ) & 1; // flash
+ else if (value > 0)
+ color = ((cl.frame.number / CL_FRAMEDIV) >> 2) & 1; // flash
else
color = 1;
- if( cl.frame.ps.stats[STAT_FLASHES] & 1 )
- R_DrawPic( x, y, scr.field_pic );
+ if (cl.frame.ps.stats[STAT_FLASHES] & 1)
+ R_DrawPic(x, y, scr.field_pic);
- HUD_DrawNumber( x, y, color, width, value );
+ HUD_DrawNumber(x, y, color, width, value);
continue;
}
- if( !strcmp( token, "anum" ) ) {
+ if (!strcmp(token, "anum")) {
// ammo number
int color;
width = 3;
value = cl.frame.ps.stats[STAT_AMMO];
- if( value > 5 )
+ if (value > 5)
color = 0; // green
- else if( value >= 0 )
- color = ( ( cl.frame.number / CL_FRAMEDIV ) >> 2 ) & 1; // flash
+ else if (value >= 0)
+ color = ((cl.frame.number / CL_FRAMEDIV) >> 2) & 1; // flash
else
continue; // negative number = don't show
- if( cl.frame.ps.stats[STAT_FLASHES] & 4 )
- R_DrawPic( x, y, scr.field_pic );
+ if (cl.frame.ps.stats[STAT_FLASHES] & 4)
+ R_DrawPic(x, y, scr.field_pic);
- HUD_DrawNumber( x, y, color, width, value );
+ HUD_DrawNumber(x, y, color, width, value);
continue;
}
- if( !strcmp( token, "rnum" ) ) {
+ if (!strcmp(token, "rnum")) {
// armor number
int color;
width = 3;
value = cl.frame.ps.stats[STAT_ARMOR];
- if( value < 1 )
+ if (value < 1)
continue;
color = 0; // green
- if( cl.frame.ps.stats[STAT_FLASHES] & 2 )
- R_DrawPic( x, y, scr.field_pic );
+ if (cl.frame.ps.stats[STAT_FLASHES] & 2)
+ R_DrawPic(x, y, scr.field_pic);
- HUD_DrawNumber( x, y, color, width, value );
+ HUD_DrawNumber(x, y, color, width, value);
continue;
}
- if( !strcmp( token, "stat_string" ) ) {
- token = COM_Parse( &s );
- index = atoi( token );
- if( index < 0 || index >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ if (!strcmp(token, "stat_string")) {
+ token = COM_Parse(&s);
+ index = atoi(token);
+ if (index < 0 || index >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
index = cl.frame.ps.stats[index];
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- Com_Error( ERR_DROP, "%s: invalid string index", __func__ );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ Com_Error(ERR_DROP, "%s: invalid string index", __func__);
}
- HUD_DrawString( x, y, cl.configstrings[index] );
+ HUD_DrawString(x, y, cl.configstrings[index]);
continue;
}
- if( !strcmp( token, "cstring" ) ) {
- token = COM_Parse( &s );
- HUD_DrawCenterString( x + 320 / 2, y, token );
+ if (!strcmp(token, "cstring")) {
+ token = COM_Parse(&s);
+ HUD_DrawCenterString(x + 320 / 2, y, token);
continue;
}
- if( !strcmp( token, "cstring2" ) ) {
- token = COM_Parse( &s );
- HUD_DrawAltCenterString( x + 320 / 2, y, token );
+ if (!strcmp(token, "cstring2")) {
+ token = COM_Parse(&s);
+ HUD_DrawAltCenterString(x + 320 / 2, y, token);
continue;
}
- if( !strcmp( token, "string" ) ) {
- token = COM_Parse( &s );
- HUD_DrawString( x, y, token );
+ if (!strcmp(token, "string")) {
+ token = COM_Parse(&s);
+ HUD_DrawString(x, y, token);
continue;
}
- if( !strcmp( token, "string2" ) ) {
- token = COM_Parse( &s );
- HUD_DrawAltString( x, y, token );
+ if (!strcmp(token, "string2")) {
+ token = COM_Parse(&s);
+ HUD_DrawAltString(x, y, token);
continue;
}
- if( !strcmp( token, "if" ) ) {
- token = COM_Parse( &s );
- value = atoi( token );
- if( value < 0 || value >= MAX_STATS ) {
- Com_Error( ERR_DROP, "%s: invalid stat index", __func__ );
+ if (!strcmp(token, "if")) {
+ token = COM_Parse(&s);
+ value = atoi(token);
+ if (value < 0 || value >= MAX_STATS) {
+ Com_Error(ERR_DROP, "%s: invalid stat index", __func__);
}
value = cl.frame.ps.stats[value];
- if( !value ) { // skip to endif
- while( strcmp( token, "endif" ) ) {
- token = COM_Parse( &s );
- if( !s ) {
+ if (!value) { // skip to endif
+ while (strcmp(token, "endif")) {
+ token = COM_Parse(&s);
+ if (!s) {
break;
}
}
@@ -1686,33 +1726,37 @@ static void draw_layout_string( const char *s ) {
}
}
-static void draw_pause( void ) {
- int x = ( scr.hud_width - scr.pause_width ) / 2;
- int y = ( scr.hud_height - scr.pause_height ) / 2;
+static void draw_pause(void)
+{
+ int x = (scr.hud_width - scr.pause_width) / 2;
+ int y = (scr.hud_height - scr.pause_height) / 2;
- R_DrawPic( x, y, scr.pause_pic );
+ R_DrawPic(x, y, scr.pause_pic);
}
-static void draw_loading( void ) {
- int x = ( r_config.width - scr.loading_width ) / 2;
- int y = ( r_config.height - scr.loading_height ) / 2;
+static void draw_loading(void)
+{
+ int x = (r_config.width - scr.loading_width) / 2;
+ int y = (r_config.height - scr.loading_height) / 2;
- R_DrawPic( x, y, scr.loading_pic );
+ R_DrawPic(x, y, scr.loading_pic);
}
-static void draw_crosshair( void ) {
- int x = ( scr.hud_width - scr.crosshair_width ) / 2;
- int y = ( scr.hud_height - scr.crosshair_height ) / 2;
+static void draw_crosshair(void)
+{
+ int x = (scr.hud_width - scr.crosshair_width) / 2;
+ int y = (scr.hud_height - scr.crosshair_height) / 2;
x += ch_x->integer;
y += ch_y->integer;
- R_SetColor( scr.crosshair_color.u32 );
- R_DrawStretchPic( x, y, scr.crosshair_width, scr.crosshair_height,
- scr.crosshair_pic );
+ R_SetColor(scr.crosshair_color.u32);
+ R_DrawStretchPic(x, y, scr.crosshair_width, scr.crosshair_height,
+ scr.crosshair_pic);
}
-static void draw_2d( void ) {
+static void draw_2d(void)
+{
#if USE_REF == REF_SOFT
clipRect_t rc;
@@ -1722,13 +1766,13 @@ static void draw_2d( void ) {
rc.right = scr.hud_width;
rc.bottom = scr.hud_height;
- R_SetClipRect( DRAW_CLIP_MASK, &rc );
+ R_SetClipRect(DRAW_CLIP_MASK, &rc);
#else
float scale;
- if( scr_scale->value != 1 ) {
- scale = 1.0f / Cvar_ClampValue( scr_scale, 1, 9 );
- R_SetScale( &scale );
+ if (scr_scale->value != 1) {
+ scale = 1.0f / Cvar_ClampValue(scr_scale, 1, 9);
+ R_SetScale(&scale);
scr.hud_height *= scale;
scr.hud_width *= scale;
@@ -1736,25 +1780,24 @@ static void draw_2d( void ) {
#endif
// crosshair has it's own color and alpha
- if( scr_crosshair->integer ) {
+ if (scr_crosshair->integer) {
draw_crosshair();
}
// the rest of 2D elements share common alpha
R_ClearColor();
- R_SetAlpha( Cvar_ClampValue( scr_alpha, 0, 1 ) );
+ R_SetAlpha(Cvar_ClampValue(scr_alpha, 0, 1));
- if( scr_draw2d->integer > 1 ) {
- draw_layout_string( cl.configstrings[CS_STATUSBAR] );
+ if (scr_draw2d->integer > 1) {
+ draw_layout_string(cl.configstrings[CS_STATUSBAR]);
}
- if( ( cl.frame.ps.stats[STAT_LAYOUTS] & 1 ) ||
- ( cls.demo.playback && Key_IsDown( K_F1 ) ) )
- {
- draw_layout_string( cl.layout );
+ if ((cl.frame.ps.stats[STAT_LAYOUTS] & 1) ||
+ (cls.demo.playback && Key_IsDown(K_F1))) {
+ draw_layout_string(cl.layout);
}
- if( cl.frame.ps.stats[STAT_LAYOUTS] & 2 ) {
+ if (cl.frame.ps.stats[STAT_LAYOUTS] & 2) {
draw_inventory();
}
@@ -1764,11 +1807,11 @@ static void draw_2d( void ) {
draw_objects();
- if( cl.frameflags && scr_showturtle->integer > 0 ) {
+ if (cl.frameflags && scr_showturtle->integer > 0) {
draw_turtle();
}
- if( sv_paused->integer && cl_paused->integer && scr_showpause->integer == 1 ) {
+ if (sv_paused->integer && cl_paused->integer && scr_showpause->integer == 1) {
draw_pause();
}
@@ -1776,25 +1819,26 @@ static void draw_2d( void ) {
R_ClearColor();
#ifdef _DEBUG
- if( scr_showstats->integer ) {
+ if (scr_showstats->integer) {
draw_stats();
}
- if( scr_showpmove->integer ) {
+ if (scr_showpmove->integer) {
draw_pmove();
}
#endif
#if USE_REF == REF_SOFT
- R_SetClipRect( DRAW_CLIP_DISABLED, NULL );
+ R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
#else
- R_SetScale( NULL );
+ R_SetScale(NULL);
#endif
}
-static void draw_active_frame( void ) {
- if( cls.state < ca_active ) {
+static void draw_active_frame(void)
+{
+ if (cls.state < ca_active) {
// draw black background if not active
- R_DrawFill8( 0, 0, r_config.width, r_config.height, 0 );
+ R_DrawFill8(0, 0, r_config.width, r_config.height, 0);
return;
}
@@ -1812,7 +1856,7 @@ static void draw_active_frame( void ) {
V_RenderView();
// draw all 2D elements
- if( scr_draw2d->integer && !( cls.key_dest & KEY_MENU ) ) {
+ if (scr_draw2d->integer && !(cls.key_dest & KEY_MENU)) {
draw_2d();
}
}
@@ -1827,27 +1871,28 @@ This is called every frame, and can also be called explicitly to flush
text to the screen.
==================
*/
-void SCR_UpdateScreen( void ) {
+void SCR_UpdateScreen(void)
+{
static int recursive;
- if( !scr.initialized ) {
+ if (!scr.initialized) {
return; // not initialized yet
}
// if the screen is disabled (loading plaque is up), do nothing at all
- if( cls.disable_screen ) {
+ if (cls.disable_screen) {
unsigned delta = Sys_Milliseconds() - cls.disable_screen;
- if( delta < 120*1000 ) {
+ if (delta < 120 * 1000) {
return;
}
cls.disable_screen = 0;
- Com_Printf( "Loading plaque timed out.\n" );
+ Com_Printf("Loading plaque timed out.\n");
}
- if( recursive > 1 ) {
- Com_Error( ERR_FATAL, "%s: recursively called", __func__ );
+ if (recursive > 1) {
+ Com_Error(ERR_FATAL, "%s: recursively called", __func__);
}
recursive++;
@@ -1855,13 +1900,13 @@ void SCR_UpdateScreen( void ) {
R_BeginFrame();
#if USE_UI
- if( UI_IsTransparent() ) {
+ if (UI_IsTransparent()) {
// do 3D refresh drawing
draw_active_frame();
}
// draw main menu
- UI_Draw( cls.realtime );
+ UI_Draw(cls.realtime);
#else
// do 3D refresh drawing
draw_active_frame();
@@ -1871,17 +1916,17 @@ void SCR_UpdateScreen( void ) {
Con_DrawConsole();
// draw loading plaque
- if( scr.draw_loading ) {
+ if (scr.draw_loading) {
draw_loading();
scr.draw_loading = qfalse;
}
#ifdef _DEBUG
// draw debug graphs
- if( scr_timegraph->integer )
- SCR_DebugGraph( cls.frametime*300, 0 );
+ if (scr_timegraph->integer)
+ SCR_DebugGraph(cls.frametime * 300, 0);
- if( scr_debuggraph->integer || scr_timegraph->integer || scr_netgraph->integer ) {
+ if (scr_debuggraph->integer || scr_timegraph->integer || scr_netgraph->integer) {
SCR_DrawDebugGraph();
}
#endif
diff --git a/src/cl_tent.c b/src/cl_tent.c
index 6f3db5e..cdde872 100644
--- a/src/cl_tent.c
+++ b/src/cl_tent.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_local.h"
-void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up);
+void MakeNormalVectors(vec3_t forward, vec3_t right, vec3_t up);
qhandle_t cl_sfx_ric1;
qhandle_t cl_sfx_ric2;
@@ -64,81 +64,80 @@ qhandle_t cl_mod_explo4_big;
CL_RegisterTEntSounds
=================
*/
-void CL_RegisterTEntSounds (void)
+void CL_RegisterTEntSounds(void)
{
int i;
char name[MAX_QPATH];
- cl_sfx_ric1 = S_RegisterSound ("world/ric1.wav");
- cl_sfx_ric2 = S_RegisterSound ("world/ric2.wav");
- cl_sfx_ric3 = S_RegisterSound ("world/ric3.wav");
+ cl_sfx_ric1 = S_RegisterSound("world/ric1.wav");
+ cl_sfx_ric2 = S_RegisterSound("world/ric2.wav");
+ cl_sfx_ric3 = S_RegisterSound("world/ric3.wav");
cl_sfx_lashit = S_RegisterSound("weapons/lashit.wav");
- cl_sfx_spark5 = S_RegisterSound ("world/spark5.wav");
- cl_sfx_spark6 = S_RegisterSound ("world/spark6.wav");
- cl_sfx_spark7 = S_RegisterSound ("world/spark7.wav");
- cl_sfx_railg = S_RegisterSound ("weapons/railgf1a.wav");
- cl_sfx_rockexp = S_RegisterSound ("weapons/rocklx1a.wav");
- cl_sfx_grenexp = S_RegisterSound ("weapons/grenlx1a.wav");
- cl_sfx_watrexp = S_RegisterSound ("weapons/xpld_wat.wav");
+ cl_sfx_spark5 = S_RegisterSound("world/spark5.wav");
+ cl_sfx_spark6 = S_RegisterSound("world/spark6.wav");
+ cl_sfx_spark7 = S_RegisterSound("world/spark7.wav");
+ cl_sfx_railg = S_RegisterSound("weapons/railgf1a.wav");
+ cl_sfx_rockexp = S_RegisterSound("weapons/rocklx1a.wav");
+ cl_sfx_grenexp = S_RegisterSound("weapons/grenlx1a.wav");
+ cl_sfx_watrexp = S_RegisterSound("weapons/xpld_wat.wav");
// RAFAEL
// cl_sfx_plasexp = S_RegisterSound ("weapons/plasexpl.wav");
- S_RegisterSound ("player/land1.wav");
+ S_RegisterSound("player/land1.wav");
- S_RegisterSound ("player/fall2.wav");
- S_RegisterSound ("player/fall1.wav");
+ S_RegisterSound("player/fall2.wav");
+ S_RegisterSound("player/fall1.wav");
- for (i=0 ; i<4 ; i++)
- {
- Q_snprintf (name, sizeof(name), "player/step%i.wav", i+1);
- cl_sfx_footsteps[i] = S_RegisterSound (name);
+ for (i = 0; i < 4; i++) {
+ Q_snprintf(name, sizeof(name), "player/step%i.wav", i + 1);
+ cl_sfx_footsteps[i] = S_RegisterSound(name);
}
//PGM
- cl_sfx_lightning = S_RegisterSound ("weapons/tesla.wav");
- cl_sfx_disrexp = S_RegisterSound ("weapons/disrupthit.wav");
+ cl_sfx_lightning = S_RegisterSound("weapons/tesla.wav");
+ cl_sfx_disrexp = S_RegisterSound("weapons/disrupthit.wav");
//PGM
-}
+}
/*
=================
CL_RegisterTEntModels
=================
*/
-void CL_RegisterTEntModels (void)
+void CL_RegisterTEntModels(void)
{
- cl_mod_explode = R_RegisterModel ("models/objects/explode/tris.md2");
- cl_mod_smoke = R_RegisterModel ("models/objects/smoke/tris.md2");
- cl_mod_flash = R_RegisterModel ("models/objects/flash/tris.md2");
- cl_mod_parasite_segment = R_RegisterModel ("models/monsters/parasite/segment/tris.md2");
- cl_mod_grapple_cable = R_RegisterModel ("models/ctf/segment/tris.md2");
- cl_mod_parasite_tip = R_RegisterModel ("models/monsters/parasite/tip/tris.md2");
- cl_mod_explo4 = R_RegisterModel ("models/objects/r_explode/tris.md2");
- cl_mod_bfg_explo = R_RegisterModel ("sprites/s_bfg2.sp2");
- cl_mod_powerscreen = R_RegisterModel ("models/items/armor/effect/tris.md2");
-
- R_RegisterModel ("models/objects/laser/tris.md2");
- R_RegisterModel ("models/objects/grenade2/tris.md2");
- R_RegisterModel ("models/weapons/v_machn/tris.md2");
- R_RegisterModel ("models/weapons/v_handgr/tris.md2");
- R_RegisterModel ("models/weapons/v_shotg2/tris.md2");
- R_RegisterModel ("models/objects/gibs/bone/tris.md2");
- R_RegisterModel ("models/objects/gibs/sm_meat/tris.md2");
- R_RegisterModel ("models/objects/gibs/bone2/tris.md2");
+ cl_mod_explode = R_RegisterModel("models/objects/explode/tris.md2");
+ cl_mod_smoke = R_RegisterModel("models/objects/smoke/tris.md2");
+ cl_mod_flash = R_RegisterModel("models/objects/flash/tris.md2");
+ cl_mod_parasite_segment = R_RegisterModel("models/monsters/parasite/segment/tris.md2");
+ cl_mod_grapple_cable = R_RegisterModel("models/ctf/segment/tris.md2");
+ cl_mod_parasite_tip = R_RegisterModel("models/monsters/parasite/tip/tris.md2");
+ cl_mod_explo4 = R_RegisterModel("models/objects/r_explode/tris.md2");
+ cl_mod_bfg_explo = R_RegisterModel("sprites/s_bfg2.sp2");
+ cl_mod_powerscreen = R_RegisterModel("models/items/armor/effect/tris.md2");
+
+ R_RegisterModel("models/objects/laser/tris.md2");
+ R_RegisterModel("models/objects/grenade2/tris.md2");
+ R_RegisterModel("models/weapons/v_machn/tris.md2");
+ R_RegisterModel("models/weapons/v_handgr/tris.md2");
+ R_RegisterModel("models/weapons/v_shotg2/tris.md2");
+ R_RegisterModel("models/objects/gibs/bone/tris.md2");
+ R_RegisterModel("models/objects/gibs/sm_meat/tris.md2");
+ R_RegisterModel("models/objects/gibs/bone2/tris.md2");
// RAFAEL
// R_RegisterModel ("models/objects/blaser/tris.md2");
- R_RegisterPic ("w_machinegun");
- R_RegisterPic ("a_bullets");
- R_RegisterPic ("i_health");
- R_RegisterPic ("a_grenades");
+ R_RegisterPic("w_machinegun");
+ R_RegisterPic("a_bullets");
+ R_RegisterPic("i_health");
+ R_RegisterPic("a_grenades");
//ROGUE
- cl_mod_explo4_big = R_RegisterModel ("models/objects/r_explode2/tris.md2");
- cl_mod_lightning = R_RegisterModel ("models/proj/lightning/tris.md2");
- cl_mod_heatbeam = R_RegisterModel ("models/proj/beam/tris.md2");
- cl_mod_monster_heatbeam = R_RegisterModel ("models/proj/widowbeam/tris.md2");
+ cl_mod_explo4_big = R_RegisterModel("models/objects/r_explode2/tris.md2");
+ cl_mod_lightning = R_RegisterModel("models/proj/lightning/tris.md2");
+ cl_mod_heatbeam = R_RegisterModel("models/proj/beam/tris.md2");
+ cl_mod_monster_heatbeam = R_RegisterModel("models/proj/widowbeam/tris.md2");
//ROGUE
-}
+}
/*
==============================================================
@@ -172,18 +171,20 @@ typedef struct {
static explosion_t cl_explosions[MAX_EXPLOSIONS];
-static void clear_explosions( void ) {
- memset (cl_explosions, 0, sizeof(cl_explosions));
+static void clear_explosions(void)
+{
+ memset(cl_explosions, 0, sizeof(cl_explosions));
}
-static explosion_t *alloc_explosion( void ) {
+static explosion_t *alloc_explosion(void)
+{
explosion_t *e, *oldest;
int i;
int time;
-
- for( i = 0, e = cl_explosions; i < MAX_EXPLOSIONS; i++, e++ ) {
+
+ for (i = 0, e = cl_explosions; i < MAX_EXPLOSIONS; i++, e++) {
if (e->type == ex_free) {
- memset (e, 0, sizeof (*e));
+ memset(e, 0, sizeof(*e));
return e;
}
}
@@ -191,26 +192,27 @@ static explosion_t *alloc_explosion( void ) {
time = cl.time;
oldest = cl_explosions;
- for(i = 0, e = cl_explosions; i < MAX_EXPLOSIONS; i++, e++ ) {
- if ( e->start < time) {
+ for (i = 0, e = cl_explosions; i < MAX_EXPLOSIONS; i++, e++) {
+ if (e->start < time) {
time = e->start;
oldest = e;
}
}
- memset (oldest, 0, sizeof (*oldest));
+ memset(oldest, 0, sizeof(*oldest));
return oldest;
}
-static explosion_t *plain_explosion( void ) {
+static explosion_t *plain_explosion(void)
+{
explosion_t *ex;
- ex = alloc_explosion ();
- VectorCopy (te.pos1, ex->ent.origin);
+ ex = alloc_explosion();
+ VectorCopy(te.pos1, ex->ent.origin);
ex->type = ex_poly;
ex->ent.flags = RF_FULLBRIGHT;
ex->start = cl.servertime - CL_FRAMETIME;
ex->light = 350;
- VectorSet( ex->lightcolor, 1.0, 0.5, 0.5 );
+ VectorSet(ex->lightcolor, 1.0, 0.5, 0.5);
ex->ent.angles[1] = rand() % 360;
ex->ent.model = cl_mod_explo4;
if (frand() < 0.5)
@@ -229,16 +231,16 @@ void CL_SmokeAndFlash(vec3_t origin)
{
explosion_t *ex;
- ex = alloc_explosion ();
- VectorCopy (origin, ex->ent.origin);
+ ex = alloc_explosion();
+ VectorCopy(origin, ex->ent.origin);
ex->type = ex_misc;
ex->frames = 4;
ex->ent.flags = RF_TRANSLUCENT;
ex->start = cl.servertime - CL_FRAMETIME;
ex->ent.model = cl_mod_smoke;
- ex = alloc_explosion ();
- VectorCopy (origin, ex->ent.origin);
+ ex = alloc_explosion();
+ VectorCopy(origin, ex->ent.origin);
ex->type = ex_flash;
ex->ent.flags = RF_FULLBRIGHT;
ex->frames = 2;
@@ -251,7 +253,7 @@ void CL_SmokeAndFlash(vec3_t origin)
CL_AddExplosions
=================
*/
-static void CL_AddExplosions (void)
+static void CL_AddExplosions(void)
{
entity_t *ent;
int i;
@@ -259,29 +261,28 @@ static void CL_AddExplosions (void)
float frac;
int f;
- memset (&ent, 0, sizeof(ent));
+ memset(&ent, 0, sizeof(ent));
- for (i=0, ex=cl_explosions ; i< MAX_EXPLOSIONS ; i++, ex++)
- {
+ for (i = 0, ex = cl_explosions; i < MAX_EXPLOSIONS; i++, ex++) {
if (ex->type == ex_free)
continue;
- frac = (cl.time - ex->start)*BASE_1_FRAMETIME;
+ frac = (cl.time - ex->start) * BASE_1_FRAMETIME;
f = floor(frac);
ent = &ex->ent;
switch (ex->type) {
case ex_mflash:
- if (f >= ex->frames-1)
+ if (f >= ex->frames - 1)
ex->type = ex_free;
break;
case ex_misc:
case ex_light:
- if (f >= ex->frames-1) {
+ if (f >= ex->frames - 1) {
ex->type = ex_free;
break;
}
- ent->alpha = 1.0 - frac/(ex->frames-1);
+ ent->alpha = 1.0 - frac / (ex->frames - 1);
break;
case ex_flash:
if (f >= 1) {
@@ -291,15 +292,15 @@ static void CL_AddExplosions (void)
ent->alpha = 1.0;
break;
case ex_poly:
- if (f >= ex->frames-1) {
+ if (f >= ex->frames - 1) {
ex->type = ex_free;
break;
}
- ent->alpha = (16.0 - (float)f)/16.0;
+ ent->alpha = (16.0 - (float)f) / 16.0;
if (f < 10) {
- ent->skinnum = (f>>1);
+ ent->skinnum = (f >> 1);
if (ent->skinnum < 0)
ent->skinnum = 0;
} else {
@@ -311,12 +312,12 @@ static void CL_AddExplosions (void)
}
break;
case ex_poly2:
- if (f >= ex->frames-1) {
+ if (f >= ex->frames - 1) {
ex->type = ex_free;
break;
}
- ent->alpha = (5.0 - (float)f)/5.0;
+ ent->alpha = (5.0 - (float)f) / 5.0;
ent->skinnum = 0;
ent->flags |= RF_TRANSLUCENT;
break;
@@ -327,12 +328,12 @@ static void CL_AddExplosions (void)
if (ex->type == ex_free)
continue;
if (ex->light) {
- V_AddLight (ent->origin, ex->light*ent->alpha,
- ex->lightcolor[0], ex->lightcolor[1], ex->lightcolor[2]);
+ V_AddLight(ent->origin, ex->light * ent->alpha,
+ ex->lightcolor[0], ex->lightcolor[1], ex->lightcolor[2]);
}
- if( ex->type != ex_light ) {
- VectorCopy (ent->origin, ent->oldorigin);
+ if (ex->type != ex_light) {
+ VectorCopy(ent->origin, ent->oldorigin);
if (f < 0)
f = 0;
@@ -340,7 +341,7 @@ static void CL_AddExplosions (void)
ent->oldframe = ex->baseframe + f;
ent->backlerp = 1.0 - (frac - f);
- V_AddEntity (ent);
+ V_AddEntity(ent);
}
}
}
@@ -368,17 +369,19 @@ typedef struct {
static laser_t cl_lasers[MAX_LASERS];
-static void clear_lasers( void ) {
- memset (cl_lasers, 0, sizeof(cl_lasers));
+static void clear_lasers(void)
+{
+ memset(cl_lasers, 0, sizeof(cl_lasers));
}
-static laser_t *alloc_laser( void ) {
+static laser_t *alloc_laser(void)
+{
laser_t *l;
int i;
- for( i = 0, l = cl_lasers; i < MAX_LASERS; i++, l++ ) {
- if( cl.time - l->starttime >= l->lifetime ) {
- memset( l, 0, sizeof( *l ) );
+ for (i = 0, l = cl_lasers; i < MAX_LASERS; i++, l++) {
+ if (cl.time - l->starttime >= l->lifetime) {
+ memset(l, 0, sizeof(*l));
l->starttime = cl.time;
return l;
}
@@ -387,22 +390,23 @@ static laser_t *alloc_laser( void ) {
return NULL;
}
-static void CL_AddLasers( void ) {
+static void CL_AddLasers(void)
+{
laser_t *l;
entity_t ent;
int i;
int time;
- memset( &ent, 0, sizeof( ent ) );
+ memset(&ent, 0, sizeof(ent));
- for( i = 0, l = cl_lasers; i < MAX_LASERS; i++, l++ ) {
- time = l->lifetime - ( cl.time - l->starttime );
- if( time < 0 ) {
+ for (i = 0, l = cl_lasers; i < MAX_LASERS; i++, l++) {
+ time = l->lifetime - (cl.time - l->starttime);
+ if (time < 0) {
continue;
}
#if USE_REF == REF_GL
- if( l->color == -1 ) {
+ if (l->color == -1) {
float f = (float)time / (float)l->lifetime;
ent.rgba.u8[0] = l->rgba.u8[0];
ent.rgba.u8[1] = l->rgba.u8[1];
@@ -413,12 +417,12 @@ static void CL_AddLasers( void ) {
ent.alpha = 0.30f;
ent.skinnum = l->color;
- ent.flags = RF_TRANSLUCENT|RF_BEAM;
- VectorCopy( l->start, ent.origin );
- VectorCopy( l->end, ent.oldorigin );
+ ent.flags = RF_TRANSLUCENT | RF_BEAM;
+ VectorCopy(l->start, ent.origin);
+ VectorCopy(l->end, ent.oldorigin);
ent.frame = l->width;
- V_AddEntity( &ent );
+ V_AddEntity(&ent);
}
}
@@ -427,17 +431,18 @@ static void CL_AddLasers( void ) {
CL_ParseLaser
=================
*/
-static void CL_ParseLaser( int colors ) {
+static void CL_ParseLaser(int colors)
+{
laser_t *l;
l = alloc_laser();
if (!l)
return;
- VectorCopy( te.pos1, l->start );
- VectorCopy( te.pos2, l->end );
+ VectorCopy(te.pos1, l->start);
+ VectorCopy(te.pos2, l->end);
l->lifetime = 100;
- l->color = ( colors >> ( ( rand() % 4 ) * 8 ) ) & 0xff;
+ l->color = (colors >> ((rand() % 4) * 8)) & 0xff;
l->width = 4;
}
@@ -466,64 +471,67 @@ static beam_t cl_beams[MAX_BEAMS];
//Currently only used by the plasma beam
static beam_t cl_playerbeams[MAX_BEAMS];
-static void clear_beams( void ) {
- memset (cl_beams, 0, sizeof(cl_beams));
- memset (cl_playerbeams, 0, sizeof(cl_playerbeams));
+static void clear_beams(void)
+{
+ memset(cl_beams, 0, sizeof(cl_beams));
+ memset(cl_playerbeams, 0, sizeof(cl_playerbeams));
}
-static void CL_ParseBeam (qhandle_t model) {
+static void CL_ParseBeam(qhandle_t model)
+{
beam_t *b;
int i;
-
+
// override any beam with the same source AND destination entities
- for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
+ for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++)
if (b->entity == te.entity1 && b->dest_entity == te.entity2)
goto override;
// find a free beam
- for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++) {
+ for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++) {
if (!b->model || b->endtime < cl.time) {
override:
b->entity = te.entity1;
b->dest_entity = te.entity2;
b->model = model;
b->endtime = cl.time + 200;
- VectorCopy (te.pos1, b->start);
- VectorCopy (te.pos2, b->end);
- VectorCopy (te.offset, b->offset);
+ VectorCopy(te.pos1, b->start);
+ VectorCopy(te.pos2, b->end);
+ VectorCopy(te.offset, b->offset);
return;
}
}
}
// ROGUE
-static void CL_ParsePlayerBeam (qhandle_t model) {
+static void CL_ParsePlayerBeam(qhandle_t model)
+{
beam_t *b;
int i;
-
+
// override any beam with the same entity
// PMM - For player beams, we only want one per player (entity) so..
- for (i=0, b=cl_playerbeams ; i< MAX_BEAMS ; i++, b++) {
+ for (i = 0, b = cl_playerbeams; i < MAX_BEAMS; i++, b++) {
if (b->entity == te.entity1) {
b->entity = te.entity1;
b->model = model;
b->endtime = cl.time + 200;
- VectorCopy (te.pos1, b->start);
- VectorCopy (te.pos2, b->end);
- VectorCopy (te.offset, b->offset);
+ VectorCopy(te.pos1, b->start);
+ VectorCopy(te.pos2, b->end);
+ VectorCopy(te.offset, b->offset);
return;
}
}
// find a free beam
- for (i=0, b=cl_playerbeams ; i< MAX_BEAMS ; i++, b++) {
+ for (i = 0, b = cl_playerbeams; i < MAX_BEAMS; i++, b++) {
if (!b->model || b->endtime < cl.time) {
b->entity = te.entity1;
b->model = model;
b->endtime = cl.time + 100; // PMM - this needs to be 100 to prevent multiple heatbeams
- VectorCopy (te.pos1, b->start);
- VectorCopy (te.pos2, b->end);
- VectorCopy (te.offset, b->offset);
+ VectorCopy(te.pos1, b->start);
+ VectorCopy(te.pos2, b->end);
+ VectorCopy(te.offset, b->offset);
return;
}
}
@@ -536,9 +544,9 @@ static void CL_ParsePlayerBeam (qhandle_t model) {
CL_AddBeams
=================
*/
-static void CL_AddBeams (void)
+static void CL_AddBeams(void)
{
- int i,j;
+ int i, j;
beam_t *b;
vec3_t dist, org;
float d;
@@ -547,35 +555,30 @@ static void CL_AddBeams (void)
float forward;
float len, steps;
float model_length;
-
+
// update beams
- for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
- {
+ for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++) {
if (!b->model || b->endtime < cl.time)
continue;
// if coming from the player, update the start position
- if (b->entity == cl.frame.clientNum+1) // entity 0 is the world
- {
- VectorCopy (cl.refdef.vieworg, b->start);
+ if (b->entity == cl.frame.clientNum + 1) { // entity 0 is the world
+ VectorCopy(cl.refdef.vieworg, b->start);
b->start[2] -= 22; // adjust for view height
}
- VectorAdd (b->start, b->offset, org);
+ VectorAdd(b->start, b->offset, org);
- // calculate pitch and yaw
- VectorSubtract (b->end, org, dist);
+ // calculate pitch and yaw
+ VectorSubtract(b->end, org, dist);
- if (dist[1] == 0 && dist[0] == 0)
- {
+ if (dist[1] == 0 && dist[0] == 0) {
yaw = 0;
if (dist[2] > 0)
pitch = 90;
else
pitch = 270;
- }
- else
- {
- // PMM - fixed to correct for pitch of 0
+ } else {
+ // PMM - fixed to correct for pitch of 0
if (dist[0])
yaw = (atan2(dist[1], dist[0]) * 180 / M_PI);
else if (dist[1] > 0)
@@ -584,71 +587,63 @@ static void CL_AddBeams (void)
yaw = 270;
if (yaw < 0)
yaw += 360;
-
- forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
+
+ forward = sqrt(dist[0] * dist[0] + dist[1] * dist[1]);
pitch = (atan2(dist[2], forward) * -180.0 / M_PI);
if (pitch < 0)
pitch += 360.0;
}
- // add new entities for the beams
+ // add new entities for the beams
d = VectorNormalize(dist);
- memset (&ent, 0, sizeof(ent));
- if (b->model == cl_mod_lightning)
- {
+ memset(&ent, 0, sizeof(ent));
+ if (b->model == cl_mod_lightning) {
model_length = 35.0;
- d-= 20.0; // correction so it doesn't end in middle of tesla
- }
- else
- {
+ d -= 20.0; // correction so it doesn't end in middle of tesla
+ } else {
model_length = 30.0;
}
- steps = ceil(d/model_length);
- len = (d-model_length)/(steps-1);
+ steps = ceil(d / model_length);
+ len = (d - model_length) / (steps - 1);
// PMM - special case for lightning model .. if the real length is shorter than the model,
// flip it around & draw it from the end to the start. This prevents the model from going
// through the tesla mine (instead it goes through the target)
- if ((b->model == cl_mod_lightning) && (d <= model_length))
- {
+ if ((b->model == cl_mod_lightning) && (d <= model_length)) {
// Com_Printf ("special case\n");
- VectorCopy (b->end, ent.origin);
+ VectorCopy(b->end, ent.origin);
// offset to push beam outside of tesla model (negative because dist is from end to start
// for this beam)
-// for (j=0 ; j<3 ; j++)
+// for (j=0; j<3; j++)
// ent.origin[j] -= dist[j]*10.0;
ent.model = b->model;
ent.flags = RF_FULLBRIGHT;
ent.angles[0] = pitch;
ent.angles[1] = yaw;
- ent.angles[2] = rand()%360;
- V_AddEntity (&ent);
+ ent.angles[2] = rand() % 360;
+ V_AddEntity(&ent);
return;
}
- while (d > 0)
- {
- VectorCopy (org, ent.origin);
+ while (d > 0) {
+ VectorCopy(org, ent.origin);
ent.model = b->model;
- if (b->model == cl_mod_lightning)
- {
+ if (b->model == cl_mod_lightning) {
ent.flags = RF_FULLBRIGHT;
ent.angles[0] = -pitch;
ent.angles[1] = yaw + 180.0;
- ent.angles[2] = rand()%360;
- }
- else
- {
+ ent.angles[2] = rand() % 360;
+ } else {
ent.angles[0] = pitch;
ent.angles[1] = yaw;
- ent.angles[2] = rand()%360;
+ ent.angles[2] = rand() % 360;
}
-
+
// Com_Printf("B: %d -> %d\n", b->entity, b->dest_entity);
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
- for (j=0 ; j<3 ; j++)
- org[j] += dist[j]*len;
+ for (j = 0; j < 3; j++)
+ org[j] += dist[j] * len;
d -= model_length;
}
}
@@ -660,9 +655,9 @@ ROGUE - draw player locked beams
CL_AddPlayerBeams
=================
*/
-static void CL_AddPlayerBeams (void)
+static void CL_AddPlayerBeams(void)
{
- int i,j;
+ int i, j;
beam_t *b;
vec3_t dist, org;
float d;
@@ -672,7 +667,7 @@ static void CL_AddPlayerBeams (void)
float len, steps;
int framenum = 0;
float model_length;
-
+
float hand_multiplier;
// frame_t *oldframe;
player_state_t *ps, *ops;
@@ -687,86 +682,74 @@ static void CL_AddPlayerBeams (void)
//PMM
// update beams
- for (i=0, b=cl_playerbeams ; i< MAX_BEAMS ; i++, b++)
- {
- vec3_t f,r,u;
+ for (i = 0, b = cl_playerbeams; i < MAX_BEAMS; i++, b++) {
+ vec3_t f, r, u;
if (!b->model || b->endtime < cl.time)
continue;
- if(cl_mod_heatbeam && (b->model == cl_mod_heatbeam))
- {
+ if (cl_mod_heatbeam && (b->model == cl_mod_heatbeam)) {
// if coming from the player, update the start position
- if (b->entity == cl.frame.clientNum+1) // entity 0 is the world
- {
+ if (b->entity == cl.frame.clientNum + 1) { // entity 0 is the world
// set up gun position
ps = &cl.frame.ps;
ops = &cl.oldframe.ps;
- if( !cl.oldframe.valid || cl.oldframe.number != cl.frame.number - 1 )
+ if (!cl.oldframe.valid || cl.oldframe.number != cl.frame.number - 1)
ops = ps; // previous frame was dropped or invalid
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
b->start[j] = cl.refdef.vieworg[j] + ops->gunoffset[j]
- + cl.lerpfrac * (ps->gunoffset[j] - ops->gunoffset[j]);
+ + cl.lerpfrac * (ps->gunoffset[j] - ops->gunoffset[j]);
}
- VectorMA (b->start, (hand_multiplier * b->offset[0]), cl.v_right, org);
- VectorMA ( org, b->offset[1], cl.v_forward, org);
- VectorMA ( org, b->offset[2], cl.v_up, org);
+ VectorMA(b->start, (hand_multiplier * b->offset[0]), cl.v_right, org);
+ VectorMA(org, b->offset[1], cl.v_forward, org);
+ VectorMA(org, b->offset[2], cl.v_up, org);
if (info_hand->integer == 2) {
- VectorMA (org, -1, cl.v_up, org);
+ VectorMA(org, -1, cl.v_up, org);
}
// FIXME - take these out when final
- VectorCopy (cl.v_right, r);
- VectorCopy (cl.v_forward, f);
- VectorCopy (cl.v_up, u);
+ VectorCopy(cl.v_right, r);
+ VectorCopy(cl.v_forward, f);
+ VectorCopy(cl.v_up, u);
- }
- else
- VectorCopy (b->start, org);
- }
- else
- {
+ } else
+ VectorCopy(b->start, org);
+ } else {
// if coming from the player, update the start position
- if (b->entity == cl.frame.clientNum+1) // entity 0 is the world
- {
- VectorCopy (cl.refdef.vieworg, b->start);
+ if (b->entity == cl.frame.clientNum + 1) { // entity 0 is the world
+ VectorCopy(cl.refdef.vieworg, b->start);
b->start[2] -= 22; // adjust for view height
}
- VectorAdd (b->start, b->offset, org);
+ VectorAdd(b->start, b->offset, org);
}
- // calculate pitch and yaw
- VectorSubtract (b->end, org, dist);
+ // calculate pitch and yaw
+ VectorSubtract(b->end, org, dist);
//PMM
- if(cl_mod_heatbeam && (b->model == cl_mod_heatbeam) && (b->entity == cl.frame.clientNum+1))
- {
+ if (cl_mod_heatbeam && (b->model == cl_mod_heatbeam) && (b->entity == cl.frame.clientNum + 1)) {
vec_t len;
- len = VectorLength (dist);
- VectorScale (f, len, dist);
- VectorMA (dist, (hand_multiplier * b->offset[0]), r, dist);
- VectorMA (dist, b->offset[1], f, dist);
- VectorMA (dist, b->offset[2], u, dist);
+ len = VectorLength(dist);
+ VectorScale(f, len, dist);
+ VectorMA(dist, (hand_multiplier * b->offset[0]), r, dist);
+ VectorMA(dist, b->offset[1], f, dist);
+ VectorMA(dist, b->offset[2], u, dist);
if (info_hand->integer == 2) {
- VectorMA (org, -1, cl.v_up, org);
+ VectorMA(org, -1, cl.v_up, org);
}
}
//PMM
- if (dist[1] == 0 && dist[0] == 0)
- {
+ if (dist[1] == 0 && dist[0] == 0) {
yaw = 0;
if (dist[2] > 0)
pitch = 90;
else
pitch = 270;
- }
- else
- {
- // PMM - fixed to correct for pitch of 0
+ } else {
+ // PMM - fixed to correct for pitch of 0
if (dist[0])
yaw = (atan2(dist[1], dist[0]) * 180 / M_PI);
else if (dist[1] > 0)
@@ -775,17 +758,15 @@ static void CL_AddPlayerBeams (void)
yaw = 270;
if (yaw < 0)
yaw += 360;
-
- forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
+
+ forward = sqrt(dist[0] * dist[0] + dist[1] * dist[1]);
pitch = (atan2(dist[2], forward) * -180.0 / M_PI);
if (pitch < 0)
pitch += 360.0;
}
-
- if (cl_mod_heatbeam && (b->model == cl_mod_heatbeam))
- {
- if (b->entity != cl.frame.clientNum+1)
- {
+
+ if (cl_mod_heatbeam && (b->model == cl_mod_heatbeam)) {
+ if (b->entity != cl.frame.clientNum + 1) {
framenum = 2;
// Com_Printf ("Third person\n");
ent.angles[0] = -pitch;
@@ -793,77 +774,63 @@ static void CL_AddPlayerBeams (void)
ent.angles[2] = 0;
// Com_Printf ("%f %f - %f %f %f\n", -pitch, yaw+180.0, b->offset[0], b->offset[1], b->offset[2]);
AngleVectors(ent.angles, f, r, u);
-
+
// if it's a non-origin offset, it's a player, so use the hardcoded player offset
- if (!VectorCompare (b->offset, vec3_origin))
- {
- VectorMA (org, -(b->offset[0])+1, r, org);
- VectorMA (org, -(b->offset[1]), f, org);
- VectorMA (org, -(b->offset[2])-10, u, org);
- }
- else
- {
+ if (!VectorCompare(b->offset, vec3_origin)) {
+ VectorMA(org, -(b->offset[0]) + 1, r, org);
+ VectorMA(org, -(b->offset[1]), f, org);
+ VectorMA(org, -(b->offset[2]) - 10, u, org);
+ } else {
// if it's a monster, do the particle effect
CL_MonsterPlasma_Shell(b->start);
}
- }
- else
- {
+ } else {
framenum = 1;
}
}
// if it's the heatbeam, draw the particle effect
- if ((cl_mod_heatbeam && (b->model == cl_mod_heatbeam) && (b->entity == cl.frame.clientNum+1)))
- {
- CL_Heatbeam (org, dist);
+ if ((cl_mod_heatbeam && (b->model == cl_mod_heatbeam) && (b->entity == cl.frame.clientNum + 1))) {
+ CL_Heatbeam(org, dist);
}
- // add new entities for the beams
+ // add new entities for the beams
d = VectorNormalize(dist);
- memset (&ent, 0, sizeof(ent));
- if (b->model == cl_mod_heatbeam)
- {
+ memset(&ent, 0, sizeof(ent));
+ if (b->model == cl_mod_heatbeam) {
model_length = 32.0;
- }
- else if (b->model == cl_mod_lightning)
- {
+ } else if (b->model == cl_mod_lightning) {
model_length = 35.0;
- d-= 20.0; // correction so it doesn't end in middle of tesla
- }
- else
- {
+ d -= 20.0; // correction so it doesn't end in middle of tesla
+ } else {
model_length = 30.0;
}
- steps = ceil(d/model_length);
- len = (d-model_length)/(steps-1);
+ steps = ceil(d / model_length);
+ len = (d - model_length) / (steps - 1);
// PMM - special case for lightning model .. if the real length is shorter than the model,
// flip it around & draw it from the end to the start. This prevents the model from going
// through the tesla mine (instead it goes through the target)
- if ((b->model == cl_mod_lightning) && (d <= model_length))
- {
+ if ((b->model == cl_mod_lightning) && (d <= model_length)) {
// Com_Printf ("special case\n");
- VectorCopy (b->end, ent.origin);
+ VectorCopy(b->end, ent.origin);
// offset to push beam outside of tesla model (negative because dist is from end to start
// for this beam)
-// for (j=0 ; j<3 ; j++)
+// for (j=0; j<3; j++)
// ent.origin[j] -= dist[j]*10.0;
ent.model = b->model;
ent.flags = RF_FULLBRIGHT;
ent.angles[0] = pitch;
ent.angles[1] = yaw;
- ent.angles[2] = rand()%360;
- V_AddEntity (&ent);
+ ent.angles[2] = rand() % 360;
+ V_AddEntity(&ent);
return;
}
- while (d > 0)
- {
- VectorCopy (org, ent.origin);
+ while (d > 0) {
+ VectorCopy(org, ent.origin);
ent.model = b->model;
- if(cl_mod_heatbeam && (b->model == cl_mod_heatbeam))
- {
+ if (cl_mod_heatbeam && (b->model == cl_mod_heatbeam)) {
// ent.flags = RF_FULLBRIGHT|RF_TRANSLUCENT;
// ent.alpha = 0.3;
ent.flags = RF_FULLBRIGHT;
@@ -872,26 +839,22 @@ static void CL_AddPlayerBeams (void)
ent.angles[2] = (cl.time) % 360;
// ent.angles[2] = rand()%360;
ent.frame = framenum;
- }
- else if (b->model == cl_mod_lightning)
- {
+ } else if (b->model == cl_mod_lightning) {
ent.flags = RF_FULLBRIGHT;
ent.angles[0] = -pitch;
ent.angles[1] = yaw + 180.0;
- ent.angles[2] = rand()%360;
- }
- else
- {
+ ent.angles[2] = rand() % 360;
+ } else {
ent.angles[0] = pitch;
ent.angles[1] = yaw;
- ent.angles[2] = rand()%360;
+ ent.angles[2] = rand() % 360;
}
-
+
// Com_Printf("B: %d -> %d\n", b->entity, b->dest_entity);
- V_AddEntity (&ent);
+ V_AddEntity(&ent);
- for (j=0 ; j<3 ; j++)
- org[j] += dist[j]*len;
+ for (j = 0; j < 3; j++)
+ org[j] += dist[j] * len;
d -= model_length;
}
}
@@ -911,15 +874,17 @@ SUSTAIN MANAGEMENT
static cl_sustain_t cl_sustains[MAX_SUSTAINS];
-static void clear_sustains( void ) {
- memset (cl_sustains, 0, sizeof(cl_sustains));
+static void clear_sustains(void)
+{
+ memset(cl_sustains, 0, sizeof(cl_sustains));
}
-static cl_sustain_t *alloc_sustain( void ) {
+static cl_sustain_t *alloc_sustain(void)
+{
int i;
cl_sustain_t *s;
- for (i=0, s=cl_sustains; i<MAX_SUSTAINS; i++, s++) {
+ for (i = 0, s = cl_sustains; i < MAX_SUSTAINS; i++, s++) {
if (s->id == 0) {
return s;
}
@@ -927,36 +892,38 @@ static cl_sustain_t *alloc_sustain( void ) {
return NULL;
}
-static void CL_ProcessSustain (void) {
+static void CL_ProcessSustain(void)
+{
cl_sustain_t *s;
int i;
- for (i=0, s=cl_sustains; i< MAX_SUSTAINS; i++, s++) {
+ for (i = 0, s = cl_sustains; i < MAX_SUSTAINS; i++, s++) {
if (s->id) {
if ((s->endtime >= cl.time) && (cl.time >= s->nextthink))
- s->think (s);
+ s->think(s);
else if (s->endtime < cl.time)
s->id = 0;
}
}
}
-static void CL_ParseSteam (void) {
+static void CL_ParseSteam(void)
+{
cl_sustain_t *s;
- if( te.entity1 == -1 ) {
- CL_ParticleSteamEffect (te.pos1, te.dir, te.color & 0xff, te.count, te.entity2);
+ if (te.entity1 == -1) {
+ CL_ParticleSteamEffect(te.pos1, te.dir, te.color & 0xff, te.count, te.entity2);
return;
}
-
+
s = alloc_sustain();
if (!s)
return;
-
+
s->id = te.entity1;
s->count = te.count;
- VectorCopy( te.pos1, s->org );
- VectorCopy( te.dir, s->dir );
+ VectorCopy(te.pos1, s->org);
+ VectorCopy(te.dir, s->dir);
s->color = te.color & 0xff;
s->magnitude = te.entity2;
s->endtime = cl.time + te.time;
@@ -965,7 +932,8 @@ static void CL_ParseSteam (void) {
s->nextthink = cl.time;
}
-static void CL_ParseWidow (void) {
+static void CL_ParseWidow(void)
+{
cl_sustain_t *s;
s = alloc_sustain();
@@ -973,14 +941,15 @@ static void CL_ParseWidow (void) {
return;
s->id = te.entity1;
- VectorCopy (te.pos1, s->org);
+ VectorCopy(te.pos1, s->org);
s->endtime = cl.time + 2100;
s->think = CL_Widowbeamout;
s->thinkinterval = 1;
s->nextthink = cl.time;
}
-static void CL_ParseNuke (void) {
+static void CL_ParseNuke(void)
+{
cl_sustain_t *s;
s = alloc_sustain();
@@ -988,7 +957,7 @@ static void CL_ParseNuke (void) {
return;
s->id = 21000;
- VectorCopy (te.pos1, s->org);
+ VectorCopy(te.pos1, s->org);
s->endtime = cl.time + 1000;
s->think = CL_Nukeblast;
s->thinkinterval = 1;
@@ -1009,38 +978,42 @@ static cvar_t *cl_railcore_width;
static cvar_t *cl_railspiral_color;
static cvar_t *cl_railspiral_radius;
-static void cl_railcore_color_changed( cvar_t *self ) {
- if( !SCR_ParseColor( self->string, &railcore_color ) ) {
- Com_WPrintf( "Invalid value '%s' for '%s'\n", self->string, self->name );
- Cvar_Reset( self );
+static void cl_railcore_color_changed(cvar_t *self)
+{
+ if (!SCR_ParseColor(self->string, &railcore_color)) {
+ Com_WPrintf("Invalid value '%s' for '%s'\n", self->string, self->name);
+ Cvar_Reset(self);
railcore_color.u32 = U32_RED;
}
}
-static void cl_railspiral_color_changed( cvar_t *self ) {
- if( !SCR_ParseColor( self->string, &railspiral_color ) ) {
- Com_WPrintf( "Invalid value '%s' for '%s'\n", self->string, self->name );
- Cvar_Reset( self );
+static void cl_railspiral_color_changed(cvar_t *self)
+{
+ if (!SCR_ParseColor(self->string, &railspiral_color)) {
+ Com_WPrintf("Invalid value '%s' for '%s'\n", self->string, self->name);
+ Cvar_Reset(self);
railspiral_color.u32 = U32_BLUE;
}
}
-static void CL_RailCore( void ) {
+static void CL_RailCore(void)
+{
laser_t *l;
l = alloc_laser();
if (!l)
return;
- VectorCopy( te.pos1, l->start );
- VectorCopy( te.pos2, l->end );
+ VectorCopy(te.pos1, l->start);
+ VectorCopy(te.pos2, l->end);
l->color = -1;
l->lifetime = 1000 * cl_railtrail_time->value;
l->width = cl_railcore_width->integer;
l->rgba.u32 = railcore_color.u32;
}
-static void CL_RailSpiral( void ) {
+static void CL_RailSpiral(void)
+{
vec3_t move;
vec3_t vec;
float len;
@@ -1052,46 +1025,47 @@ static void CL_RailSpiral( void ) {
float d, c, s;
vec3_t dir;
- VectorCopy( te.pos1, move );
- VectorSubtract( te.pos2, te.pos1, vec );
- len = VectorNormalize( vec );
+ VectorCopy(te.pos1, move);
+ VectorSubtract(te.pos2, te.pos1, vec);
+ len = VectorNormalize(vec);
- MakeNormalVectors( vec, right, up );
+ MakeNormalVectors(vec, right, up);
- for( i=0 ; i<len ; i++ ) {
+ for (i = 0; i < len; i++) {
p = CL_AllocParticle();
if (!p)
return;
-
+
p->time = cl.time;
- VectorClear( p->accel );
+ VectorClear(p->accel);
d = i * 0.1;
- c = cos( d );
- s = sin( d );
+ c = cos(d);
+ s = sin(d);
- VectorScale( right, c, dir );
- VectorMA( dir, s, up, dir );
+ VectorScale(right, c, dir);
+ VectorMA(dir, s, up, dir);
p->alpha = 1.0;
- p->alphavel = -1.0 / ( cl_railtrail_time->value + frand() * 0.2 );
+ p->alphavel = -1.0 / (cl_railtrail_time->value + frand() * 0.2);
p->color = -1;
p->rgba.u32 = railspiral_color.u32;
- for( j=0 ; j<3 ; j++ ) {
+ for (j = 0; j < 3; j++) {
p->org[j] = move[j] + dir[j] * cl_railspiral_radius->value;
p->vel[j] = dir[j] * 6;
}
- VectorAdd( move, vec, move );
+ VectorAdd(move, vec, move);
}
}
-static void CL_RailTrail( void ) {
- if( !cl_railtrail_type->integer ) {
+static void CL_RailTrail(void)
+{
+ if (!cl_railtrail_type->integer) {
CL_OldRailTrail();
} else {
CL_RailCore();
- if( cl_railtrail_type->integer > 1 ) {
+ if (cl_railtrail_type->integer > 1) {
CL_RailSpiral();
}
}
@@ -1101,11 +1075,12 @@ static void CL_RailTrail( void ) {
#define CL_RailTrail CL_OldRailTrail
#endif
-static void dirtoangles( vec3_t angles ) {
- angles[0] = acos(te.dir[2])/M_PI*180;
+static void dirtoangles(vec3_t angles)
+{
+ angles[0] = acos(te.dir[2]) / M_PI * 180;
// PMM - fixed to correct for pitch of 0
if (te.dir[0])
- angles[1] = atan2(te.dir[1], te.dir[0])/M_PI*180;
+ angles[1] = atan2(te.dir[1], te.dir[0]) / M_PI * 180;
else if (te.dir[1] > 0)
angles[1] = 90;
else if (te.dir[1] < 0)
@@ -1121,16 +1096,15 @@ CL_ParseTEnt
*/
static const byte splash_color[] = {0x00, 0xe0, 0xb0, 0x50, 0xd0, 0xe0, 0xe8};
-void CL_ParseTEnt (void)
+void CL_ParseTEnt(void)
{
explosion_t *ex;
int r;
- switch (te.type)
- {
+ switch (te.type) {
case TE_BLOOD: // bullet hitting flesh
- if( !( cl_disable_particles->integer & NOPART_BLOOD ) ) {
- CL_ParticleEffect (te.pos1, te.dir, 0xe8, 60);
+ if (!(cl_disable_particles->integer & NOPART_BLOOD)) {
+ CL_ParticleEffect(te.pos1, te.dir, 0xe8, 60);
}
break;
@@ -1138,37 +1112,37 @@ void CL_ParseTEnt (void)
case TE_SPARKS:
case TE_BULLET_SPARKS:
if (te.type == TE_GUNSHOT)
- CL_ParticleEffect (te.pos1, te.dir, 0, 40);
+ CL_ParticleEffect(te.pos1, te.dir, 0, 40);
else
- CL_ParticleEffect (te.pos1, te.dir, 0xe0, 6);
+ CL_ParticleEffect(te.pos1, te.dir, 0xe0, 6);
if (te.type != TE_SPARKS) {
CL_SmokeAndFlash(te.pos1);
-
+
// impact sound
- r = rand()&15;
+ r = rand() & 15;
if (r == 1)
- S_StartSound (te.pos1, 0, 0, cl_sfx_ric1, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_ric1, 1, ATTN_NORM, 0);
else if (r == 2)
- S_StartSound (te.pos1, 0, 0, cl_sfx_ric2, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_ric2, 1, ATTN_NORM, 0);
else if (r == 3)
- S_StartSound (te.pos1, 0, 0, cl_sfx_ric3, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_ric3, 1, ATTN_NORM, 0);
}
break;
-
+
case TE_SCREEN_SPARKS:
case TE_SHIELD_SPARKS:
if (te.type == TE_SCREEN_SPARKS)
- CL_ParticleEffect (te.pos1, te.dir, 0xd0, 40);
+ CL_ParticleEffect(te.pos1, te.dir, 0xd0, 40);
else
- CL_ParticleEffect (te.pos1, te.dir, 0xb0, 40);
+ CL_ParticleEffect(te.pos1, te.dir, 0xb0, 40);
//FIXME : replace or remove this sound
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
-
+
case TE_SHOTGUN: // bullet hitting wall
- CL_ParticleEffect (te.pos1, te.dir, 0, 20);
+ CL_ParticleEffect(te.pos1, te.dir, 0, 20);
CL_SmokeAndFlash(te.pos1);
break;
@@ -1177,50 +1151,49 @@ void CL_ParseTEnt (void)
r = 0x00;
else
r = splash_color[te.color];
- CL_ParticleEffect (te.pos1, te.dir, r, te.count);
+ CL_ParticleEffect(te.pos1, te.dir, r, te.count);
- if (te.color == SPLASH_SPARKS)
- {
+ if (te.color == SPLASH_SPARKS) {
r = rand() & 3;
if (r == 0)
- S_StartSound (te.pos1, 0, 0, cl_sfx_spark5, 1, ATTN_STATIC, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_spark5, 1, ATTN_STATIC, 0);
else if (r == 1)
- S_StartSound (te.pos1, 0, 0, cl_sfx_spark6, 1, ATTN_STATIC, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_spark6, 1, ATTN_STATIC, 0);
else
- S_StartSound (te.pos1, 0, 0, cl_sfx_spark7, 1, ATTN_STATIC, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_spark7, 1, ATTN_STATIC, 0);
}
break;
case TE_LASER_SPARKS:
- CL_ParticleEffect2 (te.pos1, te.dir, te.color, te.count);
+ CL_ParticleEffect2(te.pos1, te.dir, te.color, te.count);
break;
- // RAFAEL
+ // RAFAEL
case TE_BLUEHYPERBLASTER:
- CL_BlasterParticles (te.pos1, te.dir);
+ CL_BlasterParticles(te.pos1, te.dir);
break;
case TE_BLASTER: // blaster hitting wall
case TE_BLASTER2: // green blaster hitting wall
case TE_FLECHETTE: // flechette
- ex = alloc_explosion ();
- VectorCopy (te.pos1, ex->ent.origin);
- dirtoangles( ex->ent.angles );
+ ex = alloc_explosion();
+ VectorCopy(te.pos1, ex->ent.origin);
+ dirtoangles(ex->ent.angles);
ex->type = ex_misc;
- ex->ent.flags = RF_FULLBRIGHT|RF_TRANSLUCENT;
- switch(te.type) {
+ ex->ent.flags = RF_FULLBRIGHT | RF_TRANSLUCENT;
+ switch (te.type) {
case TE_BLASTER:
- CL_BlasterParticles( te.pos1, te.dir );
+ CL_BlasterParticles(te.pos1, te.dir);
ex->lightcolor[0] = 1;
ex->lightcolor[1] = 1;
break;
case TE_BLASTER2:
- CL_BlasterParticles2 (te.pos1, te.dir, 0xd0);
+ CL_BlasterParticles2(te.pos1, te.dir, 0xd0);
ex->ent.skinnum = 1;
ex->lightcolor[1] = 1;
break;
case TE_FLECHETTE:
- CL_BlasterParticles2 (te.pos1, te.dir, 0x6f); // 75
+ CL_BlasterParticles2(te.pos1, te.dir, 0x6f); // 75
ex->ent.skinnum = 2;
ex->lightcolor[0] = 0.19;
ex->lightcolor[1] = 0.41;
@@ -1231,85 +1204,85 @@ void CL_ParseTEnt (void)
ex->light = 150;
ex->ent.model = cl_mod_explode;
ex->frames = 4;
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
-
+
case TE_RAILTRAIL: // railgun effect
- CL_RailTrail ();
- S_StartSound (te.pos2, 0, 0, cl_sfx_railg, 1, ATTN_NORM, 0);
+ CL_RailTrail();
+ S_StartSound(te.pos2, 0, 0, cl_sfx_railg, 1, ATTN_NORM, 0);
break;
case TE_GRENADE_EXPLOSION:
case TE_GRENADE_EXPLOSION_WATER:
- ex = plain_explosion ();
+ ex = plain_explosion();
ex->frames = 19;
ex->baseframe = 30;
- if( cl_disable_explosions->integer & NOEXP_GRENADE ) {
+ if (cl_disable_explosions->integer & NOEXP_GRENADE) {
ex->type = ex_light;
}
-
- if( !( cl_disable_particles->integer & NOPART_GRENADE_EXPLOSION ) ) {
- CL_ExplosionParticles( te.pos1 );
+
+ if (!(cl_disable_particles->integer & NOPART_GRENADE_EXPLOSION)) {
+ CL_ExplosionParticles(te.pos1);
}
if (te.type == TE_GRENADE_EXPLOSION_WATER)
- S_StartSound (te.pos1, 0, 0, cl_sfx_watrexp, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_watrexp, 1, ATTN_NORM, 0);
else
- S_StartSound (te.pos1, 0, 0, cl_sfx_grenexp, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_grenexp, 1, ATTN_NORM, 0);
break;
case TE_EXPLOSION2:
- ex = plain_explosion ();
+ ex = plain_explosion();
ex->frames = 19;
ex->baseframe = 30;
- CL_ExplosionParticles( te.pos1 );
- S_StartSound (te.pos1, 0, 0, cl_sfx_grenexp, 1, ATTN_NORM, 0);
+ CL_ExplosionParticles(te.pos1);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_grenexp, 1, ATTN_NORM, 0);
break;
- // RAFAEL
+ // RAFAEL
case TE_PLASMA_EXPLOSION:
plain_explosion();
- CL_ExplosionParticles (te.pos1);
- S_StartSound (te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
+ CL_ExplosionParticles(te.pos1);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
break;
case TE_ROCKET_EXPLOSION:
case TE_ROCKET_EXPLOSION_WATER:
ex = plain_explosion();
- if( cl_disable_explosions->integer & NOEXP_ROCKET ) {
+ if (cl_disable_explosions->integer & NOEXP_ROCKET) {
ex->type = ex_light;
}
- if( !( cl_disable_particles->integer & NOPART_ROCKET_EXPLOSION ) ) {
- CL_ExplosionParticles( te.pos1 );
+ if (!(cl_disable_particles->integer & NOPART_ROCKET_EXPLOSION)) {
+ CL_ExplosionParticles(te.pos1);
}
- if( te.type == TE_ROCKET_EXPLOSION_WATER )
- S_StartSound( te.pos1, 0, 0, cl_sfx_watrexp, 1, ATTN_NORM, 0 );
+ if (te.type == TE_ROCKET_EXPLOSION_WATER)
+ S_StartSound(te.pos1, 0, 0, cl_sfx_watrexp, 1, ATTN_NORM, 0);
else
- S_StartSound( te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0 );
+ S_StartSound(te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
break;
-
+
case TE_EXPLOSION1:
plain_explosion();
- CL_ExplosionParticles( te.pos1 );
- S_StartSound( te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0 );
+ CL_ExplosionParticles(te.pos1);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
break;
case TE_EXPLOSION1_NP: // PMM
plain_explosion();
- S_StartSound( te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0 );
+ S_StartSound(te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
break;
case TE_EXPLOSION1_BIG: // PMM
ex = plain_explosion();
ex->ent.model = cl_mod_explo4_big;
- S_StartSound( te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0 );
+ S_StartSound(te.pos1, 0, 0, cl_sfx_rockexp, 1, ATTN_NORM, 0);
break;
case TE_BFG_EXPLOSION:
- ex = alloc_explosion ();
- VectorCopy (te.pos1, ex->ent.origin);
+ ex = alloc_explosion();
+ VectorCopy(te.pos1, ex->ent.origin);
ex->type = ex_poly;
ex->ent.flags = RF_FULLBRIGHT;
ex->start = cl.servertime - CL_FRAMETIME;
@@ -1324,46 +1297,46 @@ void CL_ParseTEnt (void)
break;
case TE_BFG_BIGEXPLOSION:
- CL_BFGExplosionParticles (te.pos1);
+ CL_BFGExplosionParticles(te.pos1);
break;
case TE_BFG_LASER:
- CL_ParseLaser (0xd0d1d2d3);
+ CL_ParseLaser(0xd0d1d2d3);
break;
case TE_BUBBLETRAIL:
- CL_BubbleTrail (te.pos1, te.pos2);
+ CL_BubbleTrail(te.pos1, te.pos2);
break;
case TE_PARASITE_ATTACK:
case TE_MEDIC_CABLE_ATTACK:
- VectorClear( te.offset );
+ VectorClear(te.offset);
te.entity2 = 0;
- CL_ParseBeam (cl_mod_parasite_segment);
+ CL_ParseBeam(cl_mod_parasite_segment);
break;
case TE_BOSSTPORT: // boss teleporting to station
- CL_BigTeleportParticles (te.pos1);
- S_StartSound (te.pos1, 0, 0, S_RegisterSound ("misc/bigtele.wav"), 1, ATTN_NONE, 0);
+ CL_BigTeleportParticles(te.pos1);
+ S_StartSound(te.pos1, 0, 0, S_RegisterSound("misc/bigtele.wav"), 1, ATTN_NONE, 0);
break;
case TE_GRAPPLE_CABLE:
te.entity2 = 0;
- CL_ParseBeam (cl_mod_grapple_cable);
+ CL_ParseBeam(cl_mod_grapple_cable);
break;
- // RAFAEL
+ // RAFAEL
case TE_WELDING_SPARKS:
- CL_ParticleEffect2 (te.pos1, te.dir, te.color, te.count);
+ CL_ParticleEffect2(te.pos1, te.dir, te.color, te.count);
- ex = alloc_explosion ();
- VectorCopy (te.pos1, ex->ent.origin);
+ ex = alloc_explosion();
+ VectorCopy(te.pos1, ex->ent.origin);
ex->type = ex_flash;
// note to self
// we need a better no draw flag
ex->ent.flags = RF_BEAM;
ex->start = cl.servertime - CL_FRAMETIME;
- ex->light = 100 + (rand()%75);
+ ex->light = 100 + (rand() % 75);
ex->lightcolor[0] = 1.0;
ex->lightcolor[1] = 1.0;
ex->lightcolor[2] = 0.3;
@@ -1372,23 +1345,23 @@ void CL_ParseTEnt (void)
break;
case TE_GREENBLOOD:
- CL_ParticleEffect2 (te.pos1, te.dir, 0xdf, 30);
+ CL_ParticleEffect2(te.pos1, te.dir, 0xdf, 30);
break;
- // RAFAEL
+ // RAFAEL
case TE_TUNNEL_SPARKS:
- CL_ParticleEffect3 (te.pos1, te.dir, te.color, te.count);
+ CL_ParticleEffect3(te.pos1, te.dir, te.color, te.count);
break;
case TE_LIGHTNING:
- S_StartSound (NULL, te.entity1, CHAN_WEAPON, cl_sfx_lightning, 1, ATTN_NORM, 0);
- VectorClear( te.offset );
- CL_ParseBeam (cl_mod_lightning);
+ S_StartSound(NULL, te.entity1, CHAN_WEAPON, cl_sfx_lightning, 1, ATTN_NORM, 0);
+ VectorClear(te.offset);
+ CL_ParseBeam(cl_mod_lightning);
break;
case TE_DEBUGTRAIL:
- CL_DebugTrail (te.pos1, te.pos2);
+ CL_DebugTrail(te.pos1, te.pos2);
break;
case TE_PLAIN_EXPLOSION:
@@ -1407,23 +1380,23 @@ void CL_ParseTEnt (void)
case TE_HEATBEAM:
VectorSet(te.offset, 2, 7, -3);
- CL_ParsePlayerBeam (cl_mod_heatbeam);
+ CL_ParsePlayerBeam(cl_mod_heatbeam);
break;
case TE_MONSTER_HEATBEAM:
VectorClear(te.offset);
//CL_ParsePlayerBeam (cl_mod_monster_heatbeam);
- CL_ParsePlayerBeam (cl_mod_heatbeam); // FIXME?
+ CL_ParsePlayerBeam(cl_mod_heatbeam); // FIXME?
break;
case TE_HEATBEAM_SPARKS:
- CL_ParticleSteamEffect (te.pos1, te.dir, 0x8, 50, 60);
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ CL_ParticleSteamEffect(te.pos1, te.dir, 0x8, 50, 60);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
-
+
case TE_HEATBEAM_STEAM:
- CL_ParticleSteamEffect (te.pos1, te.dir, 0xE0, 20, 60);
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ CL_ParticleSteamEffect(te.pos1, te.dir, 0xE0, 20, 60);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
case TE_STEAM:
@@ -1431,54 +1404,54 @@ void CL_ParseTEnt (void)
break;
case TE_BUBBLETRAIL2:
- CL_BubbleTrail2 (te.pos1, te.pos2, 8);
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ CL_BubbleTrail2(te.pos1, te.pos2, 8);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
case TE_MOREBLOOD:
- CL_ParticleEffect (te.pos1, te.dir, 0xe8, 250);
+ CL_ParticleEffect(te.pos1, te.dir, 0xe8, 250);
break;
case TE_CHAINFIST_SMOKE:
- VectorSet( te.dir, 0, 0, 1 );
- CL_ParticleSmokeEffect (te.pos1, te.dir, 0, 20, 20);
+ VectorSet(te.dir, 0, 0, 1);
+ CL_ParticleSmokeEffect(te.pos1, te.dir, 0, 20, 20);
break;
case TE_ELECTRIC_SPARKS:
- CL_ParticleEffect (te.pos1, te.dir, 0x75, 40);
+ CL_ParticleEffect(te.pos1, te.dir, 0x75, 40);
//FIXME : replace or remove this sound
- S_StartSound (te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0);
break;
case TE_TRACKER_EXPLOSION:
#if USE_DLIGHTS
- CL_ColorFlash (te.pos1, 0, 150, -1, -1, -1);
+ CL_ColorFlash(te.pos1, 0, 150, -1, -1, -1);
#endif
- CL_ColorExplosionParticles (te.pos1, 0, 1);
- S_StartSound (te.pos1, 0, 0, cl_sfx_disrexp, 1, ATTN_NORM, 0);
+ CL_ColorExplosionParticles(te.pos1, 0, 1);
+ S_StartSound(te.pos1, 0, 0, cl_sfx_disrexp, 1, ATTN_NORM, 0);
break;
case TE_TELEPORT_EFFECT:
case TE_DBALL_GOAL:
- CL_TeleportParticles (te.pos1);
+ CL_TeleportParticles(te.pos1);
break;
case TE_WIDOWBEAMOUT:
- CL_ParseWidow ();
+ CL_ParseWidow();
break;
case TE_NUKEBLAST:
- CL_ParseNuke ();
+ CL_ParseNuke();
break;
case TE_WIDOWSPLASH:
- CL_WidowSplash ();
+ CL_WidowSplash();
break;
//PGM
//==============
default:
- Com_Error (ERR_DROP, "%s: bad type", __func__);
+ Com_Error(ERR_DROP, "%s: bad type", __func__);
}
}
@@ -1487,11 +1460,12 @@ void CL_ParseTEnt (void)
CL_AddTEnts
=================
*/
-void CL_AddTEnts (void) {
- CL_AddBeams ();
+void CL_AddTEnts(void)
+{
+ CL_AddBeams();
// PMM - draw plasma beams
- CL_AddPlayerBeams ();
- CL_AddExplosions ();
+ CL_AddPlayerBeams();
+ CL_AddExplosions();
// PMM - set up sustain
CL_ProcessSustain();
CL_AddLasers();
@@ -1502,7 +1476,8 @@ void CL_AddTEnts (void) {
CL_ClearTEnts
=================
*/
-void CL_ClearTEnts (void) {
+void CL_ClearTEnts(void)
+{
clear_beams();
clear_explosions();
clear_lasers();
@@ -1513,20 +1488,21 @@ void CL_ClearTEnts (void) {
}
-void CL_InitTEnts( void ) {
+void CL_InitTEnts(void)
+{
#if USE_REF == REF_GL
- cl_railtrail_type = Cvar_Get( "cl_railtrail_type", "0", 0 );
- cl_railtrail_time = Cvar_Get( "cl_railtrail_time", "1.0", 0 );
- cl_railcore_color = Cvar_Get( "cl_railcore_color", "red", 0 );
+ cl_railtrail_type = Cvar_Get("cl_railtrail_type", "0", 0);
+ cl_railtrail_time = Cvar_Get("cl_railtrail_time", "1.0", 0);
+ cl_railcore_color = Cvar_Get("cl_railcore_color", "red", 0);
cl_railcore_color->changed = cl_railcore_color_changed;
cl_railcore_color->generator = Com_Color_g;
- cl_railcore_color_changed( cl_railcore_color );
- cl_railcore_width = Cvar_Get( "cl_railcore_width", "2", 0 );
- cl_railspiral_color = Cvar_Get( "cl_railspiral_color", "blue", 0 );
+ cl_railcore_color_changed(cl_railcore_color);
+ cl_railcore_width = Cvar_Get("cl_railcore_width", "2", 0);
+ cl_railspiral_color = Cvar_Get("cl_railspiral_color", "blue", 0);
cl_railspiral_color->changed = cl_railspiral_color_changed;
cl_railspiral_color->generator = Com_Color_g;
- cl_railspiral_color_changed( cl_railspiral_color );
- cl_railspiral_radius = Cvar_Get( "cl_railspiral_radius", "3", 0 );
+ cl_railspiral_color_changed(cl_railspiral_color);
+ cl_railspiral_radius = Cvar_Get("cl_railspiral_radius", "3", 0);
#endif
}
diff --git a/src/cl_view.c b/src/cl_view.c
index cf9807c..cddda9c 100644
--- a/src/cl_view.c
+++ b/src/cl_view.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -72,7 +72,8 @@ V_ClearScene
Specifies the model that will be used as the world
====================
*/
-static void V_ClearScene (void) {
+static void V_ClearScene(void)
+{
#if USE_DLIGHTS
r_numdlights = 0;
#endif
@@ -87,10 +88,11 @@ V_AddEntity
=====================
*/
-void V_AddEntity (entity_t *ent) {
+void V_AddEntity(entity_t *ent)
+{
if (r_numentities >= MAX_ENTITIES)
return;
-
+
r_entities[r_numentities++] = *ent;
}
@@ -101,7 +103,8 @@ V_AddParticle
=====================
*/
-void V_AddParticle( particle_t *p ) {
+void V_AddParticle(particle_t *p)
+{
if (r_numparticles >= MAX_PARTICLES)
return;
r_particles[r_numparticles++] = *p;
@@ -114,16 +117,17 @@ V_AddLight
=====================
*/
-void V_AddLight (vec3_t org, float intensity, float r, float g, float b) {
+void V_AddLight(vec3_t org, float intensity, float r, float g, float b)
+{
dlight_t *dl;
if (r_numdlights >= MAX_DLIGHTS)
return;
dl = &r_dlights[r_numdlights++];
- VectorCopy (org, dl->origin);
+ VectorCopy(org, dl->origin);
#if USE_REF == REF_SOFT
// negative light in softwaref. only black allowed
- if( r < 0 || g < 0 || b < 0 ) {
+ if (r < 0 || g < 0 || b < 0) {
dl->intensity = -intensity;
dl->color[0] = 1;
dl->color[1] = 1;
@@ -145,11 +149,12 @@ V_AddLightStyle
=====================
*/
-void V_AddLightStyle (int style, vec4_t value) {
+void V_AddLightStyle(int style, vec4_t value)
+{
lightstyle_t *ls;
if (style < 0 || style >= MAX_LIGHTSTYLES)
- Com_Error (ERR_DROP, "Bad light style %i", style);
+ Com_Error(ERR_DROP, "Bad light style %i", style);
ls = &r_lightstyles[style];
//ls->white = r+g+b;
@@ -169,22 +174,22 @@ V_TestParticles
If cl_testparticles is set, create 4096 particles in the view
================
*/
-static void V_TestParticles (void) {
+static void V_TestParticles(void)
+{
particle_t *p;
int i, j;
float d, r, u;
r_numparticles = MAX_PARTICLES;
- for (i=0 ; i<r_numparticles ; i++)
- {
- d = i*0.25;
- r = 4*((i&7)-3.5);
- u = 4*(((i>>3)&7)-3.5);
+ for (i = 0; i < r_numparticles; i++) {
+ d = i * 0.25;
+ r = 4 * ((i & 7) - 3.5);
+ u = 4 * (((i >> 3) & 7) - 3.5);
p = &r_particles[i];
- for (j=0 ; j<3 ; j++)
- p->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j]*d +
- cl.v_right[j]*r + cl.v_up[j]*u;
+ for (j = 0; j < 3; j++)
+ p->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j] * d +
+ cl.v_right[j] * r + cl.v_up[j] * u;
p->color = 8;
p->alpha = cl_testparticles->value;
@@ -198,24 +203,24 @@ V_TestEntities
If cl_testentities is set, create 32 player models
================
*/
-static void V_TestEntities (void) {
+static void V_TestEntities(void)
+{
int i, j;
float f, r;
entity_t *ent;
r_numentities = 32;
- memset (r_entities, 0, sizeof(r_entities));
+ memset(r_entities, 0, sizeof(r_entities));
- for (i=0 ; i<r_numentities ; i++)
- {
+ for (i = 0; i < r_numentities; i++) {
ent = &r_entities[i];
- r = 64 * ( (i%4) - 1.5 );
- f = 64 * (i/4) + 128;
+ r = 64 * ((i % 4) - 1.5);
+ f = 64 * (i / 4) + 128;
- for (j=0 ; j<3 ; j++)
- ent->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j]*f +
- cl.v_right[j]*r;
+ for (j = 0; j < 3; j++)
+ ent->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j] * f +
+ cl.v_right[j] * r;
ent->model = cl.baseclientinfo.model;
ent->skin = cl.baseclientinfo.skin;
@@ -230,37 +235,37 @@ V_TestLights
If cl_testlights is set, create 32 lights models
================
*/
-static void V_TestLights (void) {
+static void V_TestLights(void)
+{
int i, j;
float f, r;
dlight_t *dl;
- if( cl_testlights->integer == 2 ) {
+ if (cl_testlights->integer == 2) {
dl = &r_dlights[0];
r_numdlights = 1;
-
- VectorMA( cl.refdef.vieworg, 256, cl.v_forward, dl->origin );
- VectorSet( dl->color, 1, 1, 1 );
+
+ VectorMA(cl.refdef.vieworg, 256, cl.v_forward, dl->origin);
+ VectorSet(dl->color, 1, 1, 1);
dl->intensity = 256;
return;
}
-
+
r_numdlights = 32;
- memset (r_dlights, 0, sizeof(r_dlights));
+ memset(r_dlights, 0, sizeof(r_dlights));
- for (i=0 ; i<r_numdlights ; i++)
- {
+ for (i = 0; i < r_numdlights; i++) {
dl = &r_dlights[i];
- r = 64 * ( (i%4) - 1.5 );
- f = 64 * (i/4) + 128;
+ r = 64 * ((i % 4) - 1.5);
+ f = 64 * (i / 4) + 128;
- for (j=0 ; j<3 ; j++)
- dl->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j]*f +
- cl.v_right[j]*r;
- dl->color[0] = ((i%6)+1) & 1;
- dl->color[1] = (((i%6)+1) & 2)>>1;
- dl->color[2] = (((i%6)+1) & 4)>>2;
+ for (j = 0; j < 3; j++)
+ dl->origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j] * f +
+ cl.v_right[j] * r;
+ dl->color[0] = ((i % 6) + 1) & 1;
+ dl->color[1] = (((i % 6) + 1) & 2) >> 1;
+ dl->color[2] = (((i % 6) + 1) & 4) >> 2;
dl->intensity = 200;
}
}
@@ -270,82 +275,84 @@ static void V_TestLights (void) {
//===================================================================
-void CL_UpdateBlendSetting( void ) {
- if( cls.state < ca_connected ) {
+void CL_UpdateBlendSetting(void)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.serverProtocol < PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.serverProtocol < PROTOCOL_VERSION_R1Q2) {
return;
}
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_NOBLEND );
- MSG_WriteShort( !cl_add_blend->integer );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_NOBLEND);
+ MSG_WriteShort(!cl_add_blend->integer);
+ MSG_FlushTo(&cls.netchan->message);
}
//============================================================================
// gun frame debugging functions
-static void V_Gun_Next_f (void) {
+static void V_Gun_Next_f(void)
+{
gun_frame++;
- Com_Printf ("frame %i\n", gun_frame);
+ Com_Printf("frame %i\n", gun_frame);
}
-static void V_Gun_Prev_f (void) {
+static void V_Gun_Prev_f(void)
+{
gun_frame--;
if (gun_frame < 0)
gun_frame = 0;
- Com_Printf ("frame %i\n", gun_frame);
+ Com_Printf("frame %i\n", gun_frame);
}
-static void V_Gun_Model_f (void) {
+static void V_Gun_Model_f(void)
+{
char name[MAX_QPATH];
if (Cmd_Argc() != 2) {
gun_model = 0;
return;
}
- Q_concat (name, sizeof(name), "models/", Cmd_Argv(1), "/tris.md2", NULL );
- gun_model = R_RegisterModel (name);
+ Q_concat(name, sizeof(name), "models/", Cmd_Argv(1), "/tris.md2", NULL);
+ gun_model = R_RegisterModel(name);
}
//============================================================================
-static int QDECL entitycmpfnc( const entity_t *a, const entity_t *b )
+static int QDECL entitycmpfnc(const entity_t *a, const entity_t *b)
{
/*
** all other models are sorted by model then skin
*/
- if ( a->model == b->model )
- {
- return ( ( int ) a->skin - ( int ) b->skin );
- }
- else
- {
- return ( ( int ) a->model - ( int ) b->model );
+ if (a->model == b->model) {
+ return ((int) a->skin - (int) b->skin);
+ } else {
+ return ((int) a->model - (int) b->model);
}
}
-static void V_SetLightLevel( void ) {
+static void V_SetLightLevel(void)
+{
vec3_t shadelight;
// save off light value for server to look at (BIG HACK!)
- R_LightPoint( cl.refdef.vieworg, shadelight );
+ R_LightPoint(cl.refdef.vieworg, shadelight);
// pick the greatest component, which should be the same
// as the mono value returned by software
- if( shadelight[0] > shadelight[1] ) {
- if( shadelight[0] > shadelight[2] ) {
- cl.lightlevel = 150.0f*shadelight[0];
+ if (shadelight[0] > shadelight[1]) {
+ if (shadelight[0] > shadelight[2]) {
+ cl.lightlevel = 150.0f * shadelight[0];
} else {
- cl.lightlevel = 150.0f*shadelight[2];
+ cl.lightlevel = 150.0f * shadelight[2];
}
} else {
- if( shadelight[1] > shadelight[2] ) {
- cl.lightlevel = 150.0f*shadelight[1];
+ if (shadelight[1] > shadelight[2]) {
+ cl.lightlevel = 150.0f * shadelight[1];
} else {
- cl.lightlevel = 150.0f*shadelight[2];
+ cl.lightlevel = 150.0f * shadelight[2];
}
}
}
@@ -355,17 +362,18 @@ static void V_SetLightLevel( void ) {
V_CalcFov
====================
*/
-float V_CalcFov( float fov_x, float width, float height ) {
+float V_CalcFov(float fov_x, float width, float height)
+{
float a;
float x;
- if( fov_x < 1 || fov_x > 179 )
- Com_Error( ERR_DROP, "%s: bad fov: %f", __func__, fov_x );
+ if (fov_x < 1 || fov_x > 179)
+ Com_Error(ERR_DROP, "%s: bad fov: %f", __func__, fov_x);
- x = width / tan( fov_x / 360 * M_PI );
+ x = width / tan(fov_x / 360 * M_PI);
- a = atan( height / x );
- a = a * 360/ M_PI;
+ a = atan(height / x);
+ a = a * 360 / M_PI;
return a;
}
@@ -377,28 +385,28 @@ V_RenderView
==================
*/
-void V_RenderView( void ) {
+void V_RenderView(void)
+{
// an invalid frame will just use the exact previous refdef
// we can't use the old frame if the video mode has changed, though...
- if( cl.frame.valid ) {
- V_ClearScene ();
+ if (cl.frame.valid) {
+ V_ClearScene();
// build a refresh entity list and calc cl.sim*
// this also calls CL_CalcViewValues which loads
// v_forward, etc.
- CL_AddEntities ();
+ CL_AddEntities();
#ifdef _DEBUG
if (cl_testparticles->integer)
- V_TestParticles ();
+ V_TestParticles();
if (cl_testentities->integer)
- V_TestEntities ();
+ V_TestEntities();
#if USE_DLIGHTS
if (cl_testlights->integer)
- V_TestLights ();
+ V_TestLights();
#endif
- if (cl_testblend->integer)
- {
+ if (cl_testblend->integer) {
cl.refdef.blend[0] = 1;
cl.refdef.blend[1] = 0.5;
cl.refdef.blend[2] = 0.25;
@@ -409,9 +417,9 @@ void V_RenderView( void ) {
// never let it sit exactly on a node line, because a water plane can
// dissapear when viewed with the eye exactly on it.
// the server protocol only specifies to 1/8 pixel, so add 1/16 in each axis
- cl.refdef.vieworg[0] += 1.0/16;
- cl.refdef.vieworg[1] += 1.0/16;
- cl.refdef.vieworg[2] += 1.0/16;
+ cl.refdef.vieworg[0] += 1.0 / 16;
+ cl.refdef.vieworg[1] += 1.0 / 16;
+ cl.refdef.vieworg[2] += 1.0 / 16;
cl.refdef.x = scr_vrect.x;
cl.refdef.y = scr_vrect.y;
@@ -419,17 +427,17 @@ void V_RenderView( void ) {
cl.refdef.height = scr_vrect.height;
// adjust for non-4/3 screens
- if( cl_adjustfov->integer ) {
- cl.refdef.fov_y = V_CalcFov (cl.fov_x, 4, 3);
- cl.refdef.fov_x = V_CalcFov (cl.refdef.fov_y, cl.refdef.height, cl.refdef.width);
+ if (cl_adjustfov->integer) {
+ cl.refdef.fov_y = V_CalcFov(cl.fov_x, 4, 3);
+ cl.refdef.fov_x = V_CalcFov(cl.refdef.fov_y, cl.refdef.height, cl.refdef.width);
} else {
cl.refdef.fov_x = cl.fov_x;
- cl.refdef.fov_y = V_CalcFov (cl.refdef.fov_x, cl.refdef.width, cl.refdef.height);
+ cl.refdef.fov_y = V_CalcFov(cl.refdef.fov_x, cl.refdef.width, cl.refdef.height);
}
- cl.refdef.time = cl.time*0.001;
+ cl.refdef.time = cl.time * 0.001;
- if( cl.frame.areabytes ) {
+ if (cl.frame.areabytes) {
cl.refdef.areabits = cl.frame.areabits;
} else {
cl.refdef.areabits = NULL;
@@ -444,7 +452,7 @@ void V_RenderView( void ) {
r_numdlights = 0;
#endif
if (!cl_add_blend->integer)
- Vector4Clear (cl.refdef.blend);
+ Vector4Clear(cl.refdef.blend);
cl.refdef.num_entities = r_numentities;
cl.refdef.entities = r_entities;
@@ -461,16 +469,16 @@ void V_RenderView( void ) {
cl.refdef.rdflags = cl.frame.ps.rdflags;
// sort entities for better cache locality
- qsort( cl.refdef.entities, cl.refdef.num_entities, sizeof( cl.refdef.entities[0] ), (int (QDECL *)(const void *, const void *))entitycmpfnc );
+ qsort(cl.refdef.entities, cl.refdef.num_entities, sizeof(cl.refdef.entities[0]), (int (QDECL *)(const void *, const void *))entitycmpfnc);
}
- R_RenderFrame (&cl.refdef);
+ R_RenderFrame(&cl.refdef);
#ifdef _DEBUG
if (cl_stats->integer)
#if USE_DLIGHTS
- Com_Printf ("ent:%i lt:%i part:%i\n", r_numentities, r_numdlights, r_numparticles);
+ Com_Printf("ent:%i lt:%i part:%i\n", r_numentities, r_numdlights, r_numparticles);
#else
- Com_Printf ("ent:%i part:%i\n", r_numentities, r_numparticles);
+ Com_Printf("ent:%i part:%i\n", r_numentities, r_numparticles);
#endif
#endif
@@ -483,10 +491,11 @@ void V_RenderView( void ) {
V_Viewpos_f
=============
*/
-static void V_Viewpos_f (void) {
- Com_Printf ("(%i %i %i) : %i\n", (int)cl.refdef.vieworg[0],
- (int)cl.refdef.vieworg[1], (int)cl.refdef.vieworg[2],
- (int)cl.refdef.viewangles[YAW]);
+static void V_Viewpos_f(void)
+{
+ Com_Printf("(%i %i %i) : %i\n", (int)cl.refdef.vieworg[0],
+ (int)cl.refdef.vieworg[1], (int)cl.refdef.vieworg[2],
+ (int)cl.refdef.viewangles[YAW]);
}
static const cmdreg_t v_cmds[] = {
@@ -497,7 +506,8 @@ static const cmdreg_t v_cmds[] = {
{ NULL }
};
-static void cl_add_blend_changed( cvar_t *self ) {
+static void cl_add_blend_changed(cvar_t *self)
+{
CL_UpdateBlendSetting();
}
@@ -506,33 +516,35 @@ static void cl_add_blend_changed( cvar_t *self ) {
V_Init
=============
*/
-void V_Init( void ) {
- Cmd_Register( v_cmds );
+void V_Init(void)
+{
+ Cmd_Register(v_cmds);
#ifdef _DEBUG
- cl_testblend = Cvar_Get ("cl_testblend", "0", 0);
- cl_testparticles = Cvar_Get ("cl_testparticles", "0", 0);
- cl_testentities = Cvar_Get ("cl_testentities", "0", 0);
+ cl_testblend = Cvar_Get("cl_testblend", "0", 0);
+ cl_testparticles = Cvar_Get("cl_testparticles", "0", 0);
+ cl_testentities = Cvar_Get("cl_testentities", "0", 0);
#if USE_DLIGHTS
- cl_testlights = Cvar_Get ("cl_testlights", "0", CVAR_CHEAT);
+ cl_testlights = Cvar_Get("cl_testlights", "0", CVAR_CHEAT);
#endif
- cl_stats = Cvar_Get ("cl_stats", "0", 0);
+ cl_stats = Cvar_Get("cl_stats", "0", 0);
#endif
#if USE_DLIGHTS
- cl_add_lights = Cvar_Get ( "cl_lights", "1", 0 );
+ cl_add_lights = Cvar_Get("cl_lights", "1", 0);
#endif
- cl_add_particles = Cvar_Get ( "cl_particles", "1", 0 );
- cl_add_entities = Cvar_Get ( "cl_entities", "1", 0 );
- cl_add_blend = Cvar_Get ( "cl_blend", "1", 0 );
+ cl_add_particles = Cvar_Get("cl_particles", "1", 0);
+ cl_add_entities = Cvar_Get("cl_entities", "1", 0);
+ cl_add_blend = Cvar_Get("cl_blend", "1", 0);
cl_add_blend->changed = cl_add_blend_changed;
- cl_adjustfov = Cvar_Get ("cl_adjustfov", "0", 0);
+ cl_adjustfov = Cvar_Get("cl_adjustfov", "0", 0);
}
-void V_Shutdown( void ) {
- Cmd_Deregister( v_cmds );
+void V_Shutdown(void)
+{
+ Cmd_Deregister(v_cmds);
}
diff --git a/src/cmd.c b/src/cmd.c
index fa08259..eb8d9b4 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,10 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_public.h"
#endif
-#define Cmd_Malloc( size ) Z_TagMalloc( size, TAG_CMD )
-#define Cmd_CopyString( string ) Z_TagCopyString( string, TAG_CMD )
+#define Cmd_Malloc(size) Z_TagMalloc(size, TAG_CMD)
+#define Cmd_CopyString(string) Z_TagCopyString(string, TAG_CMD)
-static char *Cmd_ArgsRange( int from, int to );
+static char *Cmd_ArgsRange(int from, int to);
/*
=============================================================================
@@ -54,11 +54,12 @@ next frame. This allows commands like:
bind g "impulse 5 ; +attack ; wait ; -attack ; impulse 2"
============
*/
-static void Cmd_Wait_f( void ) {
+static void Cmd_Wait_f(void)
+{
int count;
-
- count = atoi( Cmd_Argv( 1 ) );
- if( count < 1 ) {
+
+ count = atoi(Cmd_Argv(1));
+ if (count < 1) {
count = 1;
}
cmd_current->waitCount += count;
@@ -69,11 +70,12 @@ static void Cmd_Wait_f( void ) {
Cbuf_Init
============
*/
-void Cbuf_Init( void ) {
- memset( &cmd_buffer, 0, sizeof( cmd_buffer ) );
+void Cbuf_Init(void)
+{
+ memset(&cmd_buffer, 0, sizeof(cmd_buffer));
cmd_buffer.from = FROM_CONSOLE;
cmd_buffer.text = cmd_buffer_text;
- cmd_buffer.maxsize = sizeof( cmd_buffer_text );
+ cmd_buffer.maxsize = sizeof(cmd_buffer_text);
cmd_buffer.exec = Cmd_ExecuteString;
}
@@ -84,21 +86,23 @@ Cbuf_AddText
Adds command text at the end of the buffer
============
*/
-void Cbuf_AddText( cmdbuf_t *buf, const char *text ) {
- size_t l = strlen( text );
+void Cbuf_AddText(cmdbuf_t *buf, const char *text)
+{
+ size_t l = strlen(text);
- if( buf->cursize + l > buf->maxsize ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (buf->cursize + l > buf->maxsize) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- memcpy( buf->text + buf->cursize, text, l );
+ memcpy(buf->text + buf->cursize, text, l);
buf->cursize += l;
}
-char *Cbuf_Alloc( cmdbuf_t *buf, size_t len ) {
+char *Cbuf_Alloc(cmdbuf_t *buf, size_t len)
+{
char *text;
- if( buf->cursize + len > buf->maxsize ) {
+ if (buf->cursize + len > buf->maxsize) {
return NULL;
}
text = buf->text + buf->cursize;
@@ -115,20 +119,21 @@ Adds command text at the beginning of command buffer.
Adds a \n to the text.
============
*/
-void Cbuf_InsertText( cmdbuf_t *buf, const char *text ) {
- size_t l = strlen( text );
+void Cbuf_InsertText(cmdbuf_t *buf, const char *text)
+{
+ size_t l = strlen(text);
// add the entire text of the file
- if( !l ) {
+ if (!l) {
return;
}
- if( buf->cursize + l + 1 > buf->maxsize ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (buf->cursize + l + 1 > buf->maxsize) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- memmove( buf->text + l + 1, buf->text, buf->cursize );
- memcpy( buf->text, text, l );
+ memmove(buf->text + l + 1, buf->text, buf->cursize);
+ memcpy(buf->text, text, l);
buf->text[l] = '\n';
buf->cursize += l + 1;
}
@@ -138,14 +143,15 @@ void Cbuf_InsertText( cmdbuf_t *buf, const char *text ) {
Cbuf_Execute
============
*/
-void Cbuf_Execute( cmdbuf_t *buf ) {
+void Cbuf_Execute(cmdbuf_t *buf)
+{
int i;
char *text;
char line[MAX_STRING_CHARS];
int quotes;
- while( buf->cursize ) {
- if( buf->waitCount > 0 ) {
+ while (buf->cursize) {
+ if (buf->waitCount > 0) {
// skip out while text still remains in buffer, leaving it
// for next frame (counter is decremented externally now)
return;
@@ -155,37 +161,37 @@ void Cbuf_Execute( cmdbuf_t *buf ) {
text = buf->text;
quotes = 0;
- for( i = 0; i < buf->cursize; i++ ) {
- if( text[i] == '"' )
+ for (i = 0; i < buf->cursize; i++) {
+ if (text[i] == '"')
quotes++;
- if( !( quotes & 1 ) && text[i] == ';' )
+ if (!(quotes & 1) && text[i] == ';')
break; // don't break if inside a quoted string
- if( text[i] == '\n' )
+ if (text[i] == '\n')
break;
}
// check for overflow
- if( i > sizeof( line ) - 1 ) {
- i = sizeof( line ) - 1;
+ if (i > sizeof(line) - 1) {
+ i = sizeof(line) - 1;
}
- memcpy( line, text, i );
+ memcpy(line, text, i);
line[i] = 0;
-
+
// delete the text from the command buffer and move remaining commands down
// this is necessary because commands (exec, alias) can insert data at the
// beginning of the text buffer
- if( i == buf->cursize ) {
+ if (i == buf->cursize) {
buf->cursize = 0;
} else {
i++;
buf->cursize -= i;
- memmove( text, text + i, buf->cursize );
+ memmove(text, text + i, buf->cursize);
}
// execute the command line
cmd_current = buf;
- buf->exec( buf, line );
+ buf->exec(buf, line);
}
buf->aliasCount = 0; // don't allow infinite alias loops
@@ -201,10 +207,10 @@ void Cbuf_Execute( cmdbuf_t *buf ) {
#define ALIAS_HASH_SIZE 64
-#define FOR_EACH_ALIAS_HASH( alias, hash ) \
- LIST_FOR_EACH( cmdalias_t, alias, &cmd_aliasHash[hash], hashEntry )
-#define FOR_EACH_ALIAS( alias ) \
- LIST_FOR_EACH( cmdalias_t, alias, &cmd_alias, listEntry )
+#define FOR_EACH_ALIAS_HASH(alias, hash) \
+ LIST_FOR_EACH(cmdalias_t, alias, &cmd_aliasHash[hash], hashEntry)
+#define FOR_EACH_ALIAS(alias) \
+ LIST_FOR_EACH(cmdalias_t, alias, &cmd_alias, listEntry)
typedef struct cmdalias_s {
list_t hashEntry;
@@ -221,13 +227,14 @@ static list_t cmd_aliasHash[ALIAS_HASH_SIZE];
Cmd_AliasFind
===============
*/
-static cmdalias_t *Cmd_AliasFind( const char *name ) {
+static cmdalias_t *Cmd_AliasFind(const char *name)
+{
unsigned hash;
cmdalias_t *alias;
- hash = Com_HashString( name, ALIAS_HASH_SIZE );
- FOR_EACH_ALIAS_HASH( alias, hash ) {
- if( !strcmp( name, alias->name ) ) {
+ hash = Com_HashString(name, ALIAS_HASH_SIZE);
+ FOR_EACH_ALIAS_HASH(alias, hash) {
+ if (!strcmp(name, alias->name)) {
return alias;
}
}
@@ -235,46 +242,49 @@ static cmdalias_t *Cmd_AliasFind( const char *name ) {
return NULL;
}
-char *Cmd_AliasCommand( const char *name ) {
+char *Cmd_AliasCommand(const char *name)
+{
cmdalias_t *a;
- a = Cmd_AliasFind( name );
- if( !a ) {
+ a = Cmd_AliasFind(name);
+ if (!a) {
return NULL;
}
return a->value;
}
-void Cmd_AliasSet( const char *name, const char *cmd ) {
+void Cmd_AliasSet(const char *name, const char *cmd)
+{
cmdalias_t *a;
unsigned hash;
size_t len;
// if the alias already exists, reuse it
- a = Cmd_AliasFind( name );
- if( a ) {
- Z_Free( a->value );
- a->value = Cmd_CopyString( cmd );
+ a = Cmd_AliasFind(name);
+ if (a) {
+ Z_Free(a->value);
+ a->value = Cmd_CopyString(cmd);
return;
}
- len = strlen( name );
- a = Cmd_Malloc( sizeof( cmdalias_t ) + len );
- memcpy( a->name, name, len + 1 );
- a->value = Cmd_CopyString( cmd );
+ len = strlen(name);
+ a = Cmd_Malloc(sizeof(cmdalias_t) + len);
+ memcpy(a->name, name, len + 1);
+ a->value = Cmd_CopyString(cmd);
- List_Append( &cmd_alias, &a->listEntry );
+ List_Append(&cmd_alias, &a->listEntry);
- hash = Com_HashString( name, ALIAS_HASH_SIZE );
- List_Append( &cmd_aliasHash[hash], &a->hashEntry );
+ hash = Com_HashString(name, ALIAS_HASH_SIZE);
+ List_Append(&cmd_aliasHash[hash], &a->hashEntry);
}
-void Cmd_Alias_g( genctx_t *ctx ) {
+void Cmd_Alias_g(genctx_t *ctx)
+{
cmdalias_t *a;
- FOR_EACH_ALIAS( a ) {
- if( !Prompt_AddMatch( ctx, a->name ) ) {
+ FOR_EACH_ALIAS(a) {
+ if (!Prompt_AddMatch(ctx, a->name)) {
break;
}
}
@@ -288,49 +298,51 @@ Cmd_Alias_f
Creates a new command that executes a command string (possibly ; seperated)
===============
*/
-void Cmd_Alias_f( void ) {
+void Cmd_Alias_f(void)
+{
cmdalias_t *a;
char *s, *cmd;
- if( Cmd_Argc() < 2 ) {
- if( LIST_EMPTY( &cmd_alias ) ) {
- Com_Printf( "No alias commands registered.\n" );
+ if (Cmd_Argc() < 2) {
+ if (LIST_EMPTY(&cmd_alias)) {
+ Com_Printf("No alias commands registered.\n");
return;
}
- Com_Printf( "Registered alias commands:\n" );
- FOR_EACH_ALIAS( a ) {
- Com_Printf( "\"%s\" = \"%s\"\n", a->name, a->value );
+ Com_Printf("Registered alias commands:\n");
+ FOR_EACH_ALIAS(a) {
+ Com_Printf("\"%s\" = \"%s\"\n", a->name, a->value);
}
return;
}
- s = Cmd_Argv( 1 );
- if( Cmd_Exists( s ) ) {
- Com_Printf( "\"%s\" already defined as a command\n", s );
+ s = Cmd_Argv(1);
+ if (Cmd_Exists(s)) {
+ Com_Printf("\"%s\" already defined as a command\n", s);
return;
}
- if( Cvar_Exists( s, qtrue ) ) {
- Com_Printf( "\"%s\" already defined as a cvar\n", s );
+ if (Cvar_Exists(s, qtrue)) {
+ Com_Printf("\"%s\" already defined as a cvar\n", s);
return;
}
- if( Cmd_Argc() < 3 ) {
- a = Cmd_AliasFind( s );
- if( a ) {
- Com_Printf( "\"%s\" = \"%s\"\n", a->name, a->value );
+ if (Cmd_Argc() < 3) {
+ a = Cmd_AliasFind(s);
+ if (a) {
+ Com_Printf("\"%s\" = \"%s\"\n", a->name, a->value);
} else {
- Com_Printf( "\"%s\" is undefined\n", s );
+ Com_Printf("\"%s\" is undefined\n", s);
}
return;
}
// copy the rest of the command line
- cmd = Cmd_ArgsFrom( 2 );
- Cmd_AliasSet( s, cmd );
+ cmd = Cmd_ArgsFrom(2);
+ Cmd_AliasSet(s, cmd);
}
-static void Cmd_UnAlias_f( void ) {
+static void Cmd_UnAlias_f(void)
+{
static const cmd_option_t options[] = {
{ "h", "help", "display this message" },
{ "a", "all", "delete everything" },
@@ -341,70 +353,73 @@ static void Cmd_UnAlias_f( void ) {
unsigned hash;
int c;
- while( ( c = Cmd_ParseOptions( options ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(options)) != -1) {
+ switch (c) {
case 'h':
- Com_Printf( "Usage: %s [-ha] [name]\n", Cmd_Argv( 0 ) );
- Cmd_PrintHelp( options );
+ Com_Printf("Usage: %s [-ha] [name]\n", Cmd_Argv(0));
+ Cmd_PrintHelp(options);
return;
case 'a':
- LIST_FOR_EACH_SAFE( cmdalias_t, a, n, &cmd_alias, listEntry ) {
- Z_Free( a->value );
- Z_Free( a );
+ LIST_FOR_EACH_SAFE(cmdalias_t, a, n, &cmd_alias, listEntry) {
+ Z_Free(a->value);
+ Z_Free(a);
}
- for( hash = 0; hash < ALIAS_HASH_SIZE; hash++ ) {
- List_Init( &cmd_aliasHash[hash] );
+ for (hash = 0; hash < ALIAS_HASH_SIZE; hash++) {
+ List_Init(&cmd_aliasHash[hash]);
}
- List_Init( &cmd_alias );
- Com_Printf( "Removed all alias commands.\n" );
+ List_Init(&cmd_alias);
+ Com_Printf("Removed all alias commands.\n");
return;
default:
return;
}
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing alias name.\n"
- "Try %s --help for more information.\n",
- Cmd_Argv( 0 ) );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing alias name.\n"
+ "Try %s --help for more information.\n",
+ Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- a = Cmd_AliasFind( s );
- if( !a ) {
- Com_Printf( "\"%s\" is undefined.\n", s );
+ s = Cmd_Argv(1);
+ a = Cmd_AliasFind(s);
+ if (!a) {
+ Com_Printf("\"%s\" is undefined.\n", s);
return;
}
- List_Delete( &a->listEntry );
- List_Delete( &a->hashEntry );
+ List_Delete(&a->listEntry);
+ List_Delete(&a->hashEntry);
- Z_Free( a->value );
- Z_Free( a );
+ Z_Free(a->value);
+ Z_Free(a);
}
#if USE_CLIENT
-void Cmd_WriteAliases( qhandle_t f ) {
+void Cmd_WriteAliases(qhandle_t f)
+{
cmdalias_t *a;
- FOR_EACH_ALIAS( a ) {
- FS_FPrintf( f, "alias \"%s\" \"%s\"\n", a->name, a->value );
+ FOR_EACH_ALIAS(a) {
+ FS_FPrintf(f, "alias \"%s\" \"%s\"\n", a->name, a->value);
}
}
#endif
-static void Cmd_Alias_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Cmd_Alias_g( ctx );
+static void Cmd_Alias_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Cmd_Alias_g(ctx);
} else {
- Com_Generic_c( ctx, argnum - 2 );
+ Com_Generic_c(ctx, argnum - 2);
}
}
-static void Cmd_UnAlias_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Cmd_Alias_g( ctx );
+static void Cmd_UnAlias_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Cmd_Alias_g(ctx);
}
}
@@ -416,10 +431,10 @@ MESSAGE TRIGGERS
=============================================================================
*/
-#define FOR_EACH_TRIGGER( trig ) \
- LIST_FOR_EACH( cmd_trigger_t, trig, &cmd_triggers, entry )
-#define FOR_EACH_TRIGGER_SAFE( trig, next ) \
- LIST_FOR_EACH_SAFE( cmd_trigger_t, trig, next, &cmd_triggers, entry )
+#define FOR_EACH_TRIGGER(trig) \
+ LIST_FOR_EACH(cmd_trigger_t, trig, &cmd_triggers, entry)
+#define FOR_EACH_TRIGGER_SAFE(trig, next) \
+ LIST_FOR_EACH_SAFE(cmd_trigger_t, trig, next, &cmd_triggers, entry)
typedef struct {
list_t entry;
@@ -429,11 +444,12 @@ typedef struct {
static list_t cmd_triggers;
-static cmd_trigger_t *find_trigger( const char *command, const char *match ) {
+static cmd_trigger_t *find_trigger(const char *command, const char *match)
+{
cmd_trigger_t *trigger;
- FOR_EACH_TRIGGER( trigger ) {
- if( !strcmp( trigger->command, command ) && !strcmp( trigger->match, match ) ) {
+ FOR_EACH_TRIGGER(trigger) {
+ if (!strcmp(trigger->command, command) && !strcmp(trigger->match, match)) {
return trigger;
}
}
@@ -441,17 +457,18 @@ static cmd_trigger_t *find_trigger( const char *command, const char *match ) {
return NULL;
}
-static void list_triggers( void ) {
+static void list_triggers(void)
+{
cmd_trigger_t *trigger;
- if( LIST_EMPTY( &cmd_triggers ) ) {
- Com_Printf( "No current message triggers\n" );
+ if (LIST_EMPTY(&cmd_triggers)) {
+ Com_Printf("No current message triggers\n");
return;
}
- Com_Printf( "Current message triggers:\n" );
- FOR_EACH_TRIGGER( trigger ) {
- Com_Printf( "\"%s\" = \"%s\"\n", trigger->command, trigger->match );
+ Com_Printf("Current message triggers:\n");
+ FOR_EACH_TRIGGER(trigger) {
+ Com_Printf("\"%s\" = \"%s\"\n", trigger->command, trigger->match);
}
}
@@ -460,87 +477,89 @@ static void list_triggers( void ) {
Cmd_Trigger_f
============
*/
-static void Cmd_Trigger_f( void ) {
+static void Cmd_Trigger_f(void)
+{
cmd_trigger_t *trigger;
const char *command, *match;
size_t cmdlen, matchlen;
- if( Cmd_Argc() == 1 ) {
+ if (Cmd_Argc() == 1) {
list_triggers();
return;
}
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <command> <match>\n", Cmd_Argv(0) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <command> <match>\n", Cmd_Argv(0));
return;
}
- command = Cmd_Argv( 1 );
- match = Cmd_ArgsFrom( 2 );
+ command = Cmd_Argv(1);
+ match = Cmd_ArgsFrom(2);
// don't create the same trigger twice
- if( find_trigger( command, match ) ) {
+ if (find_trigger(command, match)) {
return;
}
- cmdlen = strlen( command ) + 1;
- matchlen = strlen( match ) + 1;
- if( matchlen < 4 ) {
- Com_Printf( "Match string is too short\n" );
+ cmdlen = strlen(command) + 1;
+ matchlen = strlen(match) + 1;
+ if (matchlen < 4) {
+ Com_Printf("Match string is too short\n");
return;
}
- trigger = Z_Malloc( sizeof( *trigger ) + cmdlen + matchlen );
+ trigger = Z_Malloc(sizeof(*trigger) + cmdlen + matchlen);
trigger->command = (char *)(trigger + 1);
trigger->match = trigger->command + cmdlen;
- memcpy( trigger->command, command, cmdlen );
- memcpy( trigger->match, match, matchlen );
- List_Append( &cmd_triggers, &trigger->entry );
+ memcpy(trigger->command, command, cmdlen);
+ memcpy(trigger->match, match, matchlen);
+ List_Append(&cmd_triggers, &trigger->entry);
}
-static void Cmd_UnTrigger_f( void ) {
+static void Cmd_UnTrigger_f(void)
+{
cmd_trigger_t *trigger, *next;
const char *command, *match;
- if( Cmd_Argc() == 1 ) {
+ if (Cmd_Argc() == 1) {
list_triggers();
return;
}
- if( LIST_EMPTY( &cmd_triggers ) ) {
- Com_Printf( "No current message triggers\n" );
+ if (LIST_EMPTY(&cmd_triggers)) {
+ Com_Printf("No current message triggers\n");
return;
}
- if( Cmd_Argc() == 2 ) {
- if( !Q_stricmp( Cmd_Argv( 1 ), "all" ) ) {
+ if (Cmd_Argc() == 2) {
+ if (!Q_stricmp(Cmd_Argv(1), "all")) {
int count = 0;
- FOR_EACH_TRIGGER_SAFE( trigger, next ) {
- Z_Free( trigger );
+ FOR_EACH_TRIGGER_SAFE(trigger, next) {
+ Z_Free(trigger);
count++;
}
- Com_Printf( "Removed %d trigger%s\n", count, count == 1 ? "" : "s" );
- List_Init( &cmd_triggers );
+ Com_Printf("Removed %d trigger%s\n", count, count == 1 ? "" : "s");
+ List_Init(&cmd_triggers);
return;
}
- Com_Printf( "Usage: %s <command> <match>\n", Cmd_Argv(0) );
+ Com_Printf("Usage: %s <command> <match>\n", Cmd_Argv(0));
return;
}
- command = Cmd_Argv( 1 );
- match = Cmd_ArgsFrom( 2 );
+ command = Cmd_Argv(1);
+ match = Cmd_ArgsFrom(2);
- trigger = find_trigger( command, match );
- if( !trigger ) {
- Com_Printf( "Can't find trigger \"%s\" = \"%s\"\n", command, match );
+ trigger = find_trigger(command, match);
+ if (!trigger) {
+ Com_Printf("Can't find trigger \"%s\" = \"%s\"\n", command, match);
return;
}
- List_Remove( &trigger->entry );
- Z_Free( trigger );
+ List_Remove(&trigger->entry);
+ Z_Free(trigger);
}
/*
@@ -548,16 +567,17 @@ static void Cmd_UnTrigger_f( void ) {
Cmd_ExecTrigger
============
*/
-void Cmd_ExecTrigger( const char *string ) {
+void Cmd_ExecTrigger(const char *string)
+{
cmd_trigger_t *trigger;
char *match;
// execute matching triggers
- FOR_EACH_TRIGGER( trigger ) {
- match = Cmd_MacroExpandString( trigger->match, qfalse );
- if( match && Com_WildCmp( match, string ) ) {
- Cbuf_AddText( &cmd_buffer, trigger->command );
- Cbuf_AddText( &cmd_buffer, "\n" );
+ FOR_EACH_TRIGGER(trigger) {
+ match = Cmd_MacroExpandString(trigger->match, qfalse);
+ if (match && Com_WildCmp(match, string)) {
+ Cbuf_AddText(&cmd_buffer, trigger->command);
+ Cbuf_AddText(&cmd_buffer, "\n");
}
}
}
@@ -575,85 +595,86 @@ void Cmd_ExecTrigger( const char *string ) {
Cmd_If_f
============
*/
-static void Cmd_If_f( void ) {
+static void Cmd_If_f(void)
+{
char *a, *b, *op;
qboolean numeric;
qboolean matched;
int i, j;
- if( Cmd_Argc() < 5 ) {
- Com_Printf( "Usage: if <expr> <op> <expr> [then] <command> [else <command>]\n" );
+ if (Cmd_Argc() < 5) {
+ Com_Printf("Usage: if <expr> <op> <expr> [then] <command> [else <command>]\n");
return;
}
- a = Cmd_Argv( 1 );
- op = Cmd_Argv( 2 );
- b = Cmd_Argv( 3 );
+ a = Cmd_Argv(1);
+ op = Cmd_Argv(2);
+ b = Cmd_Argv(3);
- numeric = COM_IsFloat( a ) && COM_IsFloat( b );
- if( !strcmp( op, "==" ) ) {
- matched = numeric ? atof( a ) == atof( b ) : !strcmp( a, b );
- } else if( !strcmp( op, "!=" ) || !strcmp( op, "<>" ) ) {
- matched = numeric ? atof( a ) != atof( b ) : strcmp( a, b );
- } else if( !strcmp( op, "<" ) ) {
- if( !numeric ) {
+ numeric = COM_IsFloat(a) && COM_IsFloat(b);
+ if (!strcmp(op, "==")) {
+ matched = numeric ? atof(a) == atof(b) : !strcmp(a, b);
+ } else if (!strcmp(op, "!=") || !strcmp(op, "<>")) {
+ matched = numeric ? atof(a) != atof(b) : strcmp(a, b);
+ } else if (!strcmp(op, "<")) {
+ if (!numeric) {
error:
- Com_Printf( "Can't use '%s' with non-numeric expression(s)\n", op );
+ Com_Printf("Can't use '%s' with non-numeric expression(s)\n", op);
return;
}
- matched = atof( a ) < atof( b );
- } else if( !strcmp( op, "<=" ) ) {
- if( !numeric )
+ matched = atof(a) < atof(b);
+ } else if (!strcmp(op, "<=")) {
+ if (!numeric)
goto error;
- matched = atof( a ) <= atof( b );
- } else if( !strcmp( op, ">" ) ) {
- if( !numeric )
+ matched = atof(a) <= atof(b);
+ } else if (!strcmp(op, ">")) {
+ if (!numeric)
goto error;
- matched = atof( a ) > atof( b );
- } else if( !strcmp( op, ">=" ) ) {
- if( !numeric )
+ matched = atof(a) > atof(b);
+ } else if (!strcmp(op, ">=")) {
+ if (!numeric)
goto error;
- matched = atof( a ) >= atof( b );
- } else if( !Q_stricmp( op, "isin" ) ) {
- matched = strstr( b, a ) != NULL;
- } else if( !Q_stricmp( op, "!isin" ) ) {
- matched = strstr( b, a ) == NULL;
- } else if( !Q_stricmp( op, "isini" ) ) {
- matched = Q_stristr( b, a ) != NULL;
- } else if( !Q_stricmp( op, "!isini" ) ) {
- matched = Q_stristr( b, a ) == NULL;
- } else if( !Q_stricmp( op, "eq" ) ) {
- matched = !Q_stricmp( a, b );
- } else if( !Q_stricmp( op, "ne" ) ) {
- matched = Q_stricmp( a, b );
+ matched = atof(a) >= atof(b);
+ } else if (!Q_stricmp(op, "isin")) {
+ matched = strstr(b, a) != NULL;
+ } else if (!Q_stricmp(op, "!isin")) {
+ matched = strstr(b, a) == NULL;
+ } else if (!Q_stricmp(op, "isini")) {
+ matched = Q_stristr(b, a) != NULL;
+ } else if (!Q_stricmp(op, "!isini")) {
+ matched = Q_stristr(b, a) == NULL;
+ } else if (!Q_stricmp(op, "eq")) {
+ matched = !Q_stricmp(a, b);
+ } else if (!Q_stricmp(op, "ne")) {
+ matched = Q_stricmp(a, b);
} else {
- Com_Printf( "Unknown operator '%s'\n", op );
- Com_Printf( "Valid are: ==, != or <>, <, <=, >, >=, [!]isin[i], eq, ne\n" );
+ Com_Printf("Unknown operator '%s'\n", op);
+ Com_Printf("Valid are: ==, != or <>, <, <=, >, >=, [!]isin[i], eq, ne\n");
return;
}
// skip over optional 'then'
i = 4;
- if( !Q_stricmp( Cmd_Argv( i ), "then" ) ) {
+ if (!Q_stricmp(Cmd_Argv(i), "then")) {
i++;
}
// scan out branch 1 argument range
- for( j = i; i < Cmd_Argc(); i++ ) {
- if( !Q_stricmp( Cmd_Argv( i ), "else" ) ) {
+ for (j = i; i < Cmd_Argc(); i++) {
+ if (!Q_stricmp(Cmd_Argv(i), "else")) {
break;
}
}
- if( matched ) {
+ if (matched) {
// execute branch 1
- if( i > j ) {
- Cbuf_InsertText( cmd_current, Cmd_ArgsRange( j, i - 1 ) );
+ if (i > j) {
+ Cbuf_InsertText(cmd_current, Cmd_ArgsRange(j, i - 1));
}
} else {
// execute branch 2
- if( ++i < Cmd_Argc() ) {
- Cbuf_InsertText( cmd_current, Cmd_ArgsFrom( i ) );
+ if (++i < Cmd_Argc()) {
+ Cbuf_InsertText(cmd_current, Cmd_ArgsFrom(i));
}
}
}
@@ -676,13 +697,14 @@ static cmd_macro_t *cmd_macroHash[MACRO_HASH_SIZE];
Cmd_FindMacro
============
*/
-cmd_macro_t *Cmd_FindMacro( const char *name ) {
+cmd_macro_t *Cmd_FindMacro(const char *name)
+{
cmd_macro_t *macro;
unsigned hash;
- hash = Com_HashString( name, MACRO_HASH_SIZE );
- for( macro = cmd_macroHash[hash]; macro; macro = macro->hashNext ) {
- if( !strcmp( macro->name, name ) ) {
+ hash = Com_HashString(name, MACRO_HASH_SIZE);
+ for (macro = cmd_macroHash[hash]; macro; macro = macro->hashNext) {
+ if (!strcmp(macro->name, name)) {
return macro;
}
}
@@ -690,11 +712,12 @@ cmd_macro_t *Cmd_FindMacro( const char *name ) {
return NULL;
}
-void Cmd_Macro_g( genctx_t *ctx ) {
+void Cmd_Macro_g(genctx_t *ctx)
+{
cmd_macro_t *m;
- for( m = cmd_macros; m; m = m->next ) {
- if( !Prompt_AddMatch( ctx, m->name ) ) {
+ for (m = cmd_macros; m; m = m->next) {
+ if (!Prompt_AddMatch(ctx, m->name)) {
break;
}
}
@@ -705,32 +728,33 @@ void Cmd_Macro_g( genctx_t *ctx ) {
Cmd_AddMacro
============
*/
-void Cmd_AddMacro( const char *name, xmacro_t function ) {
+void Cmd_AddMacro(const char *name, xmacro_t function)
+{
cmd_macro_t *macro;
unsigned hash;
// fail if the macro is a variable name
- if( Cvar_Exists( name, qfalse ) ) {
- Com_WPrintf( "%s: %s already defined as a cvar\n", __func__, name );
+ if (Cvar_Exists(name, qfalse)) {
+ Com_WPrintf("%s: %s already defined as a cvar\n", __func__, name);
return;
}
// fail if the macro already exists
- macro = Cmd_FindMacro( name );
- if( macro ) {
- if( macro->function != function ) {
- Com_WPrintf( "%s: %s already defined\n", __func__, name );
+ macro = Cmd_FindMacro(name);
+ if (macro) {
+ if (macro->function != function) {
+ Com_WPrintf("%s: %s already defined\n", __func__, name);
}
return;
}
- macro = Cmd_Malloc( sizeof( cmd_macro_t ) );
+ macro = Cmd_Malloc(sizeof(cmd_macro_t));
macro->name = name;
macro->function = function;
macro->next = cmd_macros;
cmd_macros = macro;
- hash = Com_HashString( name, MACRO_HASH_SIZE );
+ hash = Com_HashString(name, MACRO_HASH_SIZE);
macro->hashNext = cmd_macroHash[hash];
cmd_macroHash[hash] = macro;
}
@@ -746,10 +770,10 @@ void Cmd_AddMacro( const char *name, xmacro_t function ) {
#define CMD_HASH_SIZE 128
-#define FOR_EACH_CMD_HASH( cmd, hash ) \
- LIST_FOR_EACH( cmd_function_t, cmd, &cmd_hash[hash], hashEntry )
-#define FOR_EACH_CMD( cmd ) \
- LIST_FOR_EACH( cmd_function_t, cmd, &cmd_functions, listEntry )
+#define FOR_EACH_CMD_HASH(cmd, hash) \
+ LIST_FOR_EACH(cmd_function_t, cmd, &cmd_hash[hash], hashEntry)
+#define FOR_EACH_CMD(cmd) \
+ LIST_FOR_EACH(cmd_function_t, cmd, &cmd_functions, listEntry)
typedef struct cmd_function_s {
list_t hashEntry;
@@ -785,32 +809,36 @@ int cmd_optind;
char *cmd_optarg;
char *cmd_optopt;
-from_t Cmd_From( void ) {
+from_t Cmd_From(void)
+{
return cmd_current->from;
}
-size_t Cmd_ArgOffset( int arg ) {
- if( arg < 0 ) {
+size_t Cmd_ArgOffset(int arg)
+{
+ if (arg < 0) {
return 0;
}
- if( arg >= cmd_argc ) {
+ if (arg >= cmd_argc) {
return cmd_string_len;
}
- return cmd_offsets[arg];
+ return cmd_offsets[arg];
}
-int Cmd_FindArgForOffset( size_t offset ) {
+int Cmd_FindArgForOffset(size_t offset)
+{
int i;
-
- for( i = 1; i < cmd_argc; i++ ) {
- if( offset < cmd_offsets[i] ) {
+
+ for (i = 1; i < cmd_argc; i++) {
+ if (offset < cmd_offsets[i]) {
break;
}
}
- return i - 1;
+ return i - 1;
}
-size_t Cmd_WhiteSpaceTail( void ) {
+size_t Cmd_WhiteSpaceTail(void)
+{
return cmd_string_tail;
}
@@ -819,7 +847,8 @@ size_t Cmd_WhiteSpaceTail( void ) {
Cmd_Argc
============
*/
-int Cmd_Argc( void ) {
+int Cmd_Argc(void)
+{
return cmd_argc;
}
@@ -828,11 +857,12 @@ int Cmd_Argc( void ) {
Cmd_Argv
============
*/
-char *Cmd_Argv( int arg ) {
- if( arg < 0 || arg >= cmd_argc ) {
+char *Cmd_Argv(int arg)
+{
+ if (arg < 0 || arg >= cmd_argc) {
return cmd_null_string;
}
- return cmd_argv[arg];
+ return cmd_argv[arg];
}
/*
@@ -840,16 +870,17 @@ char *Cmd_Argv( int arg ) {
Cmd_ArgvBuffer
============
*/
-size_t Cmd_ArgvBuffer( int arg, char *buffer, size_t size ) {
+size_t Cmd_ArgvBuffer(int arg, char *buffer, size_t size)
+{
char *s;
- if( arg < 0 || arg >= cmd_argc ) {
+ if (arg < 0 || arg >= cmd_argc) {
s = cmd_null_string;
} else {
s = cmd_argv[arg];
}
- return Q_strlcpy( buffer, s, size );
+ return Q_strlcpy(buffer, s, size);
}
@@ -860,31 +891,34 @@ Cmd_Args
Returns a single string containing argv(1) to argv(argc()-1)
============
*/
-char *Cmd_Args( void ) {
+char *Cmd_Args(void)
+{
int i;
- if( cmd_argc < 2 ) {
+ if (cmd_argc < 2) {
return cmd_null_string;
}
cmd_args[0] = 0;
- for( i = 1; i < cmd_argc - 1; i++ ) {
- strcat( cmd_args, cmd_argv[i] );
- strcat( cmd_args, " " );
+ for (i = 1; i < cmd_argc - 1; i++) {
+ strcat(cmd_args, cmd_argv[i]);
+ strcat(cmd_args, " ");
}
- strcat( cmd_args, cmd_argv[i] );
+ strcat(cmd_args, cmd_argv[i]);
return cmd_args;
}
-char *Cmd_RawArgs( void ) {
- if( cmd_argc < 2 ) {
+char *Cmd_RawArgs(void)
+{
+ if (cmd_argc < 2) {
return cmd_null_string;
}
return cmd_string + cmd_offsets[1];
}
-char *Cmd_RawString( void ) {
+char *Cmd_RawString(void)
+{
return cmd_string;
}
@@ -893,8 +927,9 @@ char *Cmd_RawString( void ) {
Cmd_ArgsBuffer
============
*/
-size_t Cmd_ArgsBuffer( char *buffer, size_t size ) {
- return Q_strlcpy( buffer, Cmd_Args(), size );
+size_t Cmd_ArgsBuffer(char *buffer, size_t size)
+{
+ return Q_strlcpy(buffer, Cmd_Args(), size);
}
/*
@@ -904,48 +939,51 @@ Cmd_ArgsFrom
Returns a single string containing argv(1) to argv(from-1)
============
*/
-char *Cmd_ArgsFrom( int from ) {
+char *Cmd_ArgsFrom(int from)
+{
int i;
- if( from < 0 || from >= cmd_argc ) {
+ if (from < 0 || from >= cmd_argc) {
return cmd_null_string;
}
cmd_args[0] = 0;
- for( i = from; i < cmd_argc - 1; i++ ) {
- strcat( cmd_args, cmd_argv[i] );
- strcat( cmd_args, " " );
+ for (i = from; i < cmd_argc - 1; i++) {
+ strcat(cmd_args, cmd_argv[i]);
+ strcat(cmd_args, " ");
}
- strcat( cmd_args, cmd_argv[i] );
+ strcat(cmd_args, cmd_argv[i]);
return cmd_args;
}
-static char *Cmd_ArgsRange( int from, int to ) {
+static char *Cmd_ArgsRange(int from, int to)
+{
int i;
- if( from < 0 || from >= cmd_argc ) {
+ if (from < 0 || from >= cmd_argc) {
return cmd_null_string;
}
- if( to > cmd_argc - 1 ) {
+ if (to > cmd_argc - 1) {
to = cmd_argc - 1;
}
cmd_args[0] = 0;
- for( i = from; i < to; i++ ) {
- strcat( cmd_args, cmd_argv[i] );
- strcat( cmd_args, " " );
+ for (i = from; i < to; i++) {
+ strcat(cmd_args, cmd_argv[i]);
+ strcat(cmd_args, " ");
}
- strcat( cmd_args, cmd_argv[i] );
+ strcat(cmd_args, cmd_argv[i]);
return cmd_args;
}
-char *Cmd_RawArgsFrom( int from ) {
+char *Cmd_RawArgsFrom(int from)
+{
size_t offset;
- if( from < 0 || from >= cmd_argc ) {
+ if (from < 0 || from >= cmd_argc) {
return cmd_null_string;
}
@@ -954,96 +992,98 @@ char *Cmd_RawArgsFrom( int from ) {
return cmd_string + offset;
}
-void Cmd_Shift( void ) {
+void Cmd_Shift(void)
+{
int i;
-
- if( !cmd_argc ) {
+
+ if (!cmd_argc) {
return;
}
- if( cmd_argc == 1 ) {
+ if (cmd_argc == 1) {
cmd_string[0] = 0;
return;
}
cmd_argc--;
- for( i = 0; i < cmd_argc; i++ ) {
- cmd_offsets[i] = cmd_offsets[ i + 1 ];
- cmd_argv[i] = cmd_argv[ i + 1 ];
+ for (i = 0; i < cmd_argc; i++) {
+ cmd_offsets[i] = cmd_offsets[i + 1];
+ cmd_argv[i] = cmd_argv[i + 1];
}
- memmove( cmd_string, cmd_string + cmd_offsets[1],
- MAX_STRING_CHARS - cmd_offsets[1] );
+ memmove(cmd_string, cmd_string + cmd_offsets[1],
+ MAX_STRING_CHARS - cmd_offsets[1]);
}
-int Cmd_ParseOptions( const cmd_option_t *opt ) {
+int Cmd_ParseOptions(const cmd_option_t *opt)
+{
const cmd_option_t *o;
char *s, *p;
cmd_optopt = cmd_null_string;
- if( cmd_optind == cmd_argc ) {
+ if (cmd_optind == cmd_argc) {
cmd_optarg = cmd_null_string;
return -1; // no more arguments
}
s = cmd_argv[cmd_optind];
- if( *s != '-' ) {
+ if (*s != '-') {
cmd_optarg = s;
return -1; // non-option argument
}
cmd_optopt = s++;
- if( *s == '-' ) {
+ if (*s == '-') {
s++;
- if( *s == 0 ) {
- if( ++cmd_optind < cmd_argc ) {
+ if (*s == 0) {
+ if (++cmd_optind < cmd_argc) {
cmd_optarg = cmd_argv[cmd_optind];
} else {
cmd_optarg = cmd_null_string;
}
return -1; // special terminator
}
- if( ( p = strchr( s, '=' ) ) != NULL ) {
+ if ((p = strchr(s, '=')) != NULL) {
*p = 0;
}
- for( o = opt; o->sh; o++ ) {
- if( !strcmp( o->lo, s ) ) {
+ for (o = opt; o->sh; o++) {
+ if (!strcmp(o->lo, s)) {
break;
}
}
- if( p ) {
- if( o->sh[1] == ':' ) {
+ if (p) {
+ if (o->sh[1] == ':') {
cmd_optarg = p + 1;
} else {
- Com_Printf( "%s does not take an argument.\n", o->lo );
+ Com_Printf("%s does not take an argument.\n", o->lo);
Cmd_PrintHint();
}
*p = 0;
}
} else {
p = NULL;
- if( s[1] ) {
+ if (s[1]) {
goto unknown;
}
- for( o = opt; o->sh; o++ ) {
- if( o->sh[0] == *s ) {
+ for (o = opt; o->sh; o++) {
+ if (o->sh[0] == *s) {
break;
}
}
}
- if( !o->sh ) {
+ if (!o->sh) {
unknown:
- Com_Printf( "Unknown option: %s.\n", cmd_argv[cmd_optind] );
+ Com_Printf("Unknown option: %s.\n", cmd_argv[cmd_optind]);
Cmd_PrintHint();
return '?';
}
// parse option argument
- if( !p && o->sh[1] == ':' ) {
- if( cmd_optind + 1 == cmd_argc ) {
- Com_Printf( "Missing argument to %s.\n", cmd_argv[cmd_optind] );
+ if (!p && o->sh[1] == ':') {
+ if (cmd_optind + 1 == cmd_argc) {
+ Com_Printf("Missing argument to %s.\n", cmd_argv[cmd_optind]);
Cmd_PrintHint();
return ':';
}
@@ -1055,65 +1095,71 @@ unknown:
return o->sh[0];
}
-void Cmd_PrintUsage( const cmd_option_t *opt, const char *suffix ) {
- Com_Printf( "Usage: %s [-", cmd_argv[0] );
- while( opt->sh ) {
- Com_Printf( "%c", opt->sh[0] );
- if( opt->sh[1] == ':' ) {
- Com_Printf( ":" );
+void Cmd_PrintUsage(const cmd_option_t *opt, const char *suffix)
+{
+ Com_Printf("Usage: %s [-", cmd_argv[0]);
+ while (opt->sh) {
+ Com_Printf("%c", opt->sh[0]);
+ if (opt->sh[1] == ':') {
+ Com_Printf(":");
}
opt++;
}
- if( suffix ) {
- Com_Printf( "] %s\n", suffix );
+ if (suffix) {
+ Com_Printf("] %s\n", suffix);
} else {
- Com_Printf( "]\n" );
+ Com_Printf("]\n");
}
}
-void Cmd_PrintHelp( const cmd_option_t *opt ) {
+void Cmd_PrintHelp(const cmd_option_t *opt)
+{
char buffer[32];
- Com_Printf( "\nAvailable options:\n" );
- while( opt->sh ) {
- if( opt->sh[1] == ':' ) {
- Q_concat( buffer, sizeof( buffer ),
- opt->lo, "=<", opt->sh + 2, ">", NULL );
+ Com_Printf("\nAvailable options:\n");
+ while (opt->sh) {
+ if (opt->sh[1] == ':') {
+ Q_concat(buffer, sizeof(buffer),
+ opt->lo, "=<", opt->sh + 2, ">", NULL);
} else {
- Q_strlcpy( buffer, opt->lo, sizeof( buffer ) );
+ Q_strlcpy(buffer, opt->lo, sizeof(buffer));
}
- Com_Printf( "-%c | --%-16.16s | %s\n", opt->sh[0], buffer, opt->help );
+ Com_Printf("-%c | --%-16.16s | %s\n", opt->sh[0], buffer, opt->help);
opt++;
}
- Com_Printf( "\n" );
+ Com_Printf("\n");
}
-void Cmd_PrintHint( void ) {
- Com_Printf( "Try '%s --help' for more information.\n", cmd_argv[0] );
+void Cmd_PrintHint(void)
+{
+ Com_Printf("Try '%s --help' for more information.\n", cmd_argv[0]);
}
-void Cmd_Option_c( const cmd_option_t *opt, xgenerator_t g, genctx_t *ctx, int argnum ) {
- if( ctx->partial[0] == '-' ) {
- for( ; opt->sh; opt++ ) {
- if( ctx->count >= ctx->size ) {
+void Cmd_Option_c(const cmd_option_t *opt, xgenerator_t g, genctx_t *ctx, int argnum)
+{
+ if (ctx->partial[0] == '-') {
+ for (; opt->sh; opt++) {
+ if (ctx->count >= ctx->size) {
break;
}
- if( ctx->partial[1] == '-' ) {
- if( !strncmp( opt->lo, ctx->partial + 2, ctx->length - 2 ) ) {
- ctx->matches[ctx->count++] = Z_CopyString( va( "--%s", opt->lo ) );
+ if (ctx->partial[1] == '-') {
+ if (!strncmp(opt->lo, ctx->partial + 2, ctx->length - 2)) {
+ ctx->matches[ctx->count++] = Z_CopyString(va("--%s", opt->lo));
}
- } else if( !ctx->partial[1] || opt->sh[0] == ctx->partial[1] ) {
- ctx->matches[ctx->count++] = Z_CopyString( va( "-%c", opt->sh[0] ) );
+ } else if (!ctx->partial[1] || opt->sh[0] == ctx->partial[1]) {
+ ctx->matches[ctx->count++] = Z_CopyString(va("-%c", opt->sh[0]));
}
}
} else {
- /* if( argnum > 1 ) {
+#if 0
+ if (argnum > 1) {
s = cmd_argv[argnum - 1];
- }*/
- if( g ) {
- g( ctx );
- } else if( !ctx->partial[0] && ctx->count < ctx->size ) {
- ctx->matches[ctx->count++] = Z_CopyString( "-" );
+ }
+#endif
+ if (g) {
+ g(ctx);
+ } else if (!ctx->partial[0] && ctx->count < ctx->size) {
+ ctx->matches[ctx->count++] = Z_CopyString("-");
}
}
}
@@ -1124,7 +1170,8 @@ void Cmd_Option_c( const cmd_option_t *opt, xgenerator_t g, genctx_t *ctx, int a
Cmd_MacroExpandString
======================
*/
-char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) {
+char *Cmd_MacroExpandString(const char *text, qboolean aliasHack)
+{
size_t i, j, len;
int count;
qboolean inquote;
@@ -1137,59 +1184,59 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) {
cvar_t *var;
qboolean rescan;
- len = strlen( text );
- if( len >= MAX_STRING_CHARS ) {
- Com_Printf( "Line exceeded %i chars, discarded.\n", MAX_STRING_CHARS );
+ len = strlen(text);
+ if (len >= MAX_STRING_CHARS) {
+ Com_Printf("Line exceeded %i chars, discarded.\n", MAX_STRING_CHARS);
return NULL;
}
- scan = memcpy( expanded, text, len + 1 );
+ scan = memcpy(expanded, text, len + 1);
inquote = qfalse;
count = 0;
- for( i = 0; i < len; i++ ) {
- if( !scan[i] ) {
+ for (i = 0; i < len; i++) {
+ if (!scan[i]) {
break;
}
- if( scan[i] == '"' ) {
+ if (scan[i] == '"') {
inquote ^= 1;
}
- if( inquote ) {
+ if (inquote) {
continue; // don't expand inside quotes
}
- if( scan[i] != '$' ) {
+ if (scan[i] != '$') {
continue;
}
-
+
// scan out the complete macro
start = scan + i + 1;
- if( *start == 0 ) {
+ if (*start == 0) {
break; // end of string
}
// allow $$ escape syntax
- if( *start == '$' ) {
- memmove( scan + i, start, len - i );
+ if (*start == '$') {
+ memmove(scan + i, start, len - i);
continue;
}
// skip leading spaces
- while( *start && *start <= 32 ) {
+ while (*start && *start <= 32) {
start++;
}
token = temporary;
- if( *start == '{' ) {
+ if (*start == '{') {
// allow ${variable} syntax
start++;
- if( *start == '$' ) { // allow ${$variable} syntax
+ if (*start == '$') { // allow ${$variable} syntax
start++;
}
- while( *start ) {
- if( *start == '}' ) {
+ while (*start) {
+ if (*start == '}') {
start++;
break;
}
@@ -1197,64 +1244,64 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) {
}
} else {
// parse single word
- while( *start > 32 ) {
- if( *start == '$' ) { // allow $var$ syntax
+ while (*start > 32) {
+ if (*start == '$') { // allow $var$ syntax
start++;
break;
}
*token++ = *start++;
}
}
-
+
*token = 0;
- if( token == temporary ) {
+ if (token == temporary) {
continue;
}
rescan = qfalse;
-
- if( aliasHack ) {
+
+ if (aliasHack) {
// expand positional parameters only
- if( !strcmp( temporary, "@" ) ) {
+ if (!strcmp(temporary, "@")) {
token = Cmd_Args();
} else {
int arg1, arg2;
char *s;
// parse {arg1-arg2} format for ranges
- arg1 = strtoul( temporary, &s, 10 );
- if( s[0] == '-' ) {
- if( s[1] ) {
- arg2 = strtoul( s + 1, &s, 10 );
- if( s[0] ) {
+ arg1 = strtoul(temporary, &s, 10);
+ if (s[0] == '-') {
+ if (s[1]) {
+ arg2 = strtoul(s + 1, &s, 10);
+ if (s[0]) {
continue; // second part is not a number
}
} else {
arg2 = cmd_argc - 1;
}
- token = Cmd_ArgsRange( arg1, arg2 );
- } else if( s[0] == 0 ) {
- token = Cmd_Argv( arg1 );
+ token = Cmd_ArgsRange(arg1, arg2);
+ } else if (s[0] == 0) {
+ token = Cmd_Argv(arg1);
} else {
continue; // first part is not a number
}
}
} else {
// check for macros first
- macro = Cmd_FindMacro( temporary );
- if( macro ) {
- macro->function( buffer, MAX_STRING_CHARS - len );
+ macro = Cmd_FindMacro(temporary);
+ if (macro) {
+ macro->function(buffer, MAX_STRING_CHARS - len);
token = buffer;
} else {
// than variables
- var = Cvar_FindVar( temporary );
- if( var && !( var->flags & CVAR_PRIVATE ) ) {
+ var = Cvar_FindVar(temporary);
+ if (var && !(var->flags & CVAR_PRIVATE)) {
token = var->string;
rescan = qtrue;
- } else if( !strcmp( temporary, "qt" ) ) {
+ } else if (!strcmp(temporary, "qt")) {
token = "\"";
- } else if( !strcmp( temporary, "sc" ) ) {
+ } else if (!strcmp(temporary, "sc")) {
token = ";";
} else {
token = "";
@@ -1262,33 +1309,33 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) {
}
}
- j = strlen( token );
+ j = strlen(token);
len += j;
- if( len >= MAX_STRING_CHARS ) {
- Com_Printf( "Expanded line exceeded %i chars, discarded.\n",
- MAX_STRING_CHARS );
+ if (len >= MAX_STRING_CHARS) {
+ Com_Printf("Expanded line exceeded %i chars, discarded.\n",
+ MAX_STRING_CHARS);
return NULL;
}
- strncpy( temporary, scan, i );
- strcpy( temporary + i, token );
- strcpy( temporary + i + j, start );
+ strncpy(temporary, scan, i);
+ strcpy(temporary + i, token);
+ strcpy(temporary + i + j, start);
- strcpy( expanded, temporary );
+ strcpy(expanded, temporary);
scan = expanded;
- if( !rescan ) {
+ if (!rescan) {
i += j;
}
i--;
- if( ++count == 100 ) {
- Com_Printf( "Macro expansion loop, discarded.\n" );
+ if (++count == 100) {
+ Com_Printf("Macro expansion loop, discarded.\n");
return NULL;
}
}
- if( inquote ) {
- Com_Printf( "Line has unmatched quote, discarded.\n" );
+ if (inquote) {
+ Com_Printf("Line has unmatched quote, discarded.\n");
return NULL;
}
@@ -1303,12 +1350,13 @@ Parses the given string into command line tokens.
$Cvars will be expanded unless they are in a quoted token
============
*/
-void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
+void Cmd_TokenizeString(const char *text, qboolean macroExpand)
+{
int i;
char *data, *start, *dest;
// clear the args from the last string
- for( i = 0; i < cmd_argc; i++ ) {
+ for (i = 0; i < cmd_argc; i++) {
cmd_argv[i] = NULL;
cmd_offsets[i] = 0;
}
@@ -1320,43 +1368,43 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
cmd_optind = 1;
cmd_optarg = cmd_optopt = cmd_null_string;
- if( !text[0] ) {
+ if (!text[0]) {
return;
}
// macro expand the text
- if( macroExpand ) {
- text = Cmd_MacroExpandString( text, qfalse );
- if( !text ) {
+ if (macroExpand) {
+ text = Cmd_MacroExpandString(text, qfalse);
+ if (!text) {
return;
}
}
- cmd_string_len = Q_strlcpy( cmd_string, text, sizeof( cmd_string ) );
- if( cmd_string_len >= sizeof( cmd_string ) ) {
- Com_Printf( "Line exceeded %i chars, discarded.\n", MAX_STRING_CHARS );
+ cmd_string_len = Q_strlcpy(cmd_string, text, sizeof(cmd_string));
+ if (cmd_string_len >= sizeof(cmd_string)) {
+ Com_Printf("Line exceeded %i chars, discarded.\n", MAX_STRING_CHARS);
return;
}
// strip off any trailing whitespace
- while( cmd_string_len ) {
- if( cmd_string[ cmd_string_len - 1 ] > ' ' ) {
+ while (cmd_string_len) {
+ if (cmd_string[cmd_string_len - 1] > ' ') {
break;
}
- cmd_string[ cmd_string_len - 1 ] = 0;
+ cmd_string[cmd_string_len - 1] = 0;
cmd_string_len--;
cmd_string_tail++;
}
dest = cmd_data;
start = data = cmd_string;
- while( cmd_argc < MAX_STRING_TOKENS ) {
+ while (cmd_argc < MAX_STRING_TOKENS) {
// skip whitespace up to a /n
- while( *data <= ' ' ) {
- if( *data == 0 ) {
+ while (*data <= ' ') {
+ if (*data == 0) {
return; // end of text
}
- if( *data == '\n' ) {
+ if (*data == '\n') {
return; // a newline seperates commands in the buffer
}
data++;
@@ -1367,7 +1415,7 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
cmd_argv[cmd_argc] = dest;
cmd_argc++;
- if( *data == ';' ) {
+ if (*data == ';') {
data++;
*dest++ = ';';
*dest++ = 0;
@@ -1375,10 +1423,10 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
}
// parse quoted string
- if( *data == '\"' ) {
+ if (*data == '\"') {
data++;
- while( *data != '\"' ) {
- if( *data == 0 ) {
+ while (*data != '\"') {
+ if (*data == 0) {
return; // end of data
}
*dest++ = *data++;
@@ -1389,18 +1437,18 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
}
// parse reqular token
- while( *data > ' ' ) {
- if( *data == '\"' ) {
+ while (*data > ' ') {
+ if (*data == '\"') {
break;
}
- if( *data == ';' ) {
+ if (*data == ';') {
break;
}
*dest++ = *data++;
}
*dest++ = 0;
- if( *data == 0 ) {
+ if (*data == 0) {
return; // end of text
}
}
@@ -1411,13 +1459,14 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) {
Cmd_Find
============
*/
-static cmd_function_t *Cmd_Find( const char *name ) {
+static cmd_function_t *Cmd_Find(const char *name)
+{
cmd_function_t *cmd;
unsigned hash;
- hash = Com_HashString( name, CMD_HASH_SIZE );
- FOR_EACH_CMD_HASH( cmd, hash ) {
- if( !strcmp( cmd->name, name ) ) {
+ hash = Com_HashString(name, CMD_HASH_SIZE);
+ FOR_EACH_CMD_HASH(cmd, hash) {
+ if (!strcmp(cmd->name, name)) {
return cmd;
}
}
@@ -1425,21 +1474,22 @@ static cmd_function_t *Cmd_Find( const char *name ) {
return NULL;
}
-static void Cmd_RegCommand( const cmdreg_t *reg ) {
+static void Cmd_RegCommand(const cmdreg_t *reg)
+{
cmd_function_t *cmd;
unsigned hash;
-
+
// fail if the command is a variable name
- if( Cvar_Exists( reg->name, qfalse ) ) {
- Com_WPrintf( "%s: %s already defined as a cvar\n", __func__, reg->name );
+ if (Cvar_Exists(reg->name, qfalse)) {
+ Com_WPrintf("%s: %s already defined as a cvar\n", __func__, reg->name);
return;
}
// fail if the command already exists
- cmd = Cmd_Find( reg->name );
- if( cmd ) {
- if( cmd->function ) {
- Com_WPrintf( "%s: %s already defined\n", __func__, reg->name );
+ cmd = Cmd_Find(reg->name);
+ if (cmd) {
+ if (cmd->function) {
+ Com_WPrintf("%s: %s already defined\n", __func__, reg->name);
return;
}
cmd->function = reg->function;
@@ -1447,15 +1497,15 @@ static void Cmd_RegCommand( const cmdreg_t *reg ) {
return;
}
- cmd = Cmd_Malloc( sizeof( *cmd ) );
- cmd->name = ( char * )reg->name;
+ cmd = Cmd_Malloc(sizeof(*cmd));
+ cmd->name = (char *)reg->name;
cmd->function = reg->function;
cmd->completer = reg->completer;
- List_Append( &cmd_functions, &cmd->listEntry );
+ List_Append(&cmd_functions, &cmd->listEntry);
- hash = Com_HashString( reg->name, CMD_HASH_SIZE );
- List_Append( &cmd_hash[hash], &cmd->hashEntry );
+ hash = Com_HashString(reg->name, CMD_HASH_SIZE);
+ List_Append(&cmd_hash[hash], &cmd->hashEntry);
}
/*
@@ -1463,25 +1513,28 @@ static void Cmd_RegCommand( const cmdreg_t *reg ) {
Cmd_AddCommand
============
*/
-void Cmd_AddCommand( const char *name, xcommand_t function ) {
+void Cmd_AddCommand(const char *name, xcommand_t function)
+{
cmdreg_t reg;
reg.name = name;
reg.function = function;
reg.completer = NULL;
- Cmd_RegCommand( &reg );
+ Cmd_RegCommand(&reg);
}
-void Cmd_Register( const cmdreg_t *reg ) {
- while( reg->name ) {
- Cmd_RegCommand( reg );
+void Cmd_Register(const cmdreg_t *reg)
+{
+ while (reg->name) {
+ Cmd_RegCommand(reg);
reg++;
}
}
-void Cmd_Deregister( const cmdreg_t *reg ) {
- while( reg->name ) {
- Cmd_RemoveCommand( reg->name );
+void Cmd_Deregister(const cmdreg_t *reg)
+{
+ while (reg->name) {
+ Cmd_RemoveCommand(reg->name);
reg++;
}
}
@@ -1491,18 +1544,19 @@ void Cmd_Deregister( const cmdreg_t *reg ) {
Cmd_RemoveCommand
============
*/
-void Cmd_RemoveCommand( const char *name ) {
+void Cmd_RemoveCommand(const char *name)
+{
cmd_function_t *cmd;
- cmd = Cmd_Find( name );
- if( !cmd ) {
- Com_DPrintf( "%s: %s not added\n", __func__, name );
+ cmd = Cmd_Find(name);
+ if (!cmd) {
+ Com_DPrintf("%s: %s not added\n", __func__, name);
return;
}
- List_Delete( &cmd->listEntry );
- List_Delete( &cmd->hashEntry );
- Z_Free( cmd );
+ List_Delete(&cmd->listEntry);
+ List_Delete(&cmd->hashEntry);
+ Z_Free(cmd);
}
/*
@@ -1510,83 +1564,88 @@ void Cmd_RemoveCommand( const char *name ) {
Cmd_Exists
============
*/
-qboolean Cmd_Exists( const char *name ) {
- cmd_function_t *cmd = Cmd_Find( name );
+qboolean Cmd_Exists(const char *name)
+{
+ cmd_function_t *cmd = Cmd_Find(name);
return cmd ? qtrue : qfalse;
}
-xcommand_t Cmd_FindFunction( const char *name ) {
- cmd_function_t *cmd = Cmd_Find( name );
+xcommand_t Cmd_FindFunction(const char *name)
+{
+ cmd_function_t *cmd = Cmd_Find(name);
return cmd ? cmd->function : NULL;
}
-xcompleter_t Cmd_FindCompleter( const char *name ) {
- cmd_function_t *cmd = Cmd_Find( name );
+xcompleter_t Cmd_FindCompleter(const char *name)
+{
+ cmd_function_t *cmd = Cmd_Find(name);
return cmd ? cmd->completer : NULL;
}
-void Cmd_Command_g( genctx_t *ctx ) {
+void Cmd_Command_g(genctx_t *ctx)
+{
cmd_function_t *cmd;
- FOR_EACH_CMD( cmd ) {
- if( !Prompt_AddMatch( ctx, cmd->name ) ) {
+ FOR_EACH_CMD(cmd) {
+ if (!Prompt_AddMatch(ctx, cmd->name)) {
break;
}
}
}
-void Cmd_ExecuteCommand( cmdbuf_t *buf ) {
+void Cmd_ExecuteCommand(cmdbuf_t *buf)
+{
cmd_function_t *cmd;
cmdalias_t *a;
cvar_t *v;
char *text;
// check functions
- cmd = Cmd_Find( cmd_argv[0] );
- if( cmd ) {
- if( cmd->function ) {
+ cmd = Cmd_Find(cmd_argv[0]);
+ if (cmd) {
+ if (cmd->function) {
cmd->function();
} else
#if USE_CLIENT
- if( !CL_ForwardToServer() )
+ if (!CL_ForwardToServer())
#endif
- {
- Com_Printf( "Can't \"%s\", not connected\n", cmd_argv[0] );
- }
+ {
+ Com_Printf("Can't \"%s\", not connected\n", cmd_argv[0]);
+ }
return;
}
// check aliases
- a = Cmd_AliasFind( cmd_argv[0] );
- if( a ) {
- if( buf->aliasCount >= ALIAS_LOOP_COUNT ) {
- Com_WPrintf( "Runaway alias loop\n" );
+ a = Cmd_AliasFind(cmd_argv[0]);
+ if (a) {
+ if (buf->aliasCount >= ALIAS_LOOP_COUNT) {
+ Com_WPrintf("Runaway alias loop\n");
return;
}
- text = Cmd_MacroExpandString( a->value, qtrue );
- if( text ) {
+ text = Cmd_MacroExpandString(a->value, qtrue);
+ if (text) {
buf->aliasCount++;
- Cbuf_InsertText( buf, text );
+ Cbuf_InsertText(buf, text);
}
return;
}
-
+
// check variables
- v = Cvar_FindVar( cmd_argv[0] );
- if( v ) {
- Cvar_Command( v );
+ v = Cvar_FindVar(cmd_argv[0]);
+ if (v) {
+ Cvar_Command(v);
return;
}
#if USE_CLIENT
// send it as a server command if we are connected
- if( !CL_ForwardToServer() )
+ if (!CL_ForwardToServer())
#endif
{
- Com_Printf( "Unknown command \"%s\"\n", cmd_argv[0] );
+ Com_Printf("Unknown command \"%s\"\n", cmd_argv[0]);
}
}
@@ -1597,37 +1656,39 @@ Cmd_ExecuteString
A complete command line has been parsed, so try to execute it
============
*/
-void Cmd_ExecuteString( cmdbuf_t *buf, const char *text ) {
- Cmd_TokenizeString( text, qtrue );
-
+void Cmd_ExecuteString(cmdbuf_t *buf, const char *text)
+{
+ Cmd_TokenizeString(text, qtrue);
+
// execute the command line
- if( !cmd_argc ) {
+ if (!cmd_argc) {
return; // no tokens
}
- Cmd_ExecuteCommand( buf );
+ Cmd_ExecuteCommand(buf);
}
-qerror_t Cmd_ExecuteFile( const char *path, unsigned flags ) {
+qerror_t Cmd_ExecuteFile(const char *path, unsigned flags)
+{
char *f;
ssize_t len;
qerror_t ret;
cmdbuf_t *buf;
- len = FS_LoadFileEx( path, ( void ** )&f, flags, TAG_FILESYSTEM );
- if( !f ) {
+ len = FS_LoadFileEx(path, (void **)&f, flags, TAG_FILESYSTEM);
+ if (!f) {
return len;
}
// check for binary file
- if( memchr( f, 0, len ) ) {
+ if (memchr(f, 0, len)) {
ret = Q_ERR_INVALID_FORMAT;
goto finish;
}
// sanity check file size after stripping off comments
- len = COM_Compress( f );
- if( len > CMD_BUFFER_SIZE ) {
+ len = COM_Compress(f);
+ if (len > CMD_BUFFER_SIZE) {
ret = Q_ERR_FBIG;
goto finish;
}
@@ -1637,24 +1698,24 @@ qerror_t Cmd_ExecuteFile( const char *path, unsigned flags ) {
buf = &cmd_buffer;
// check for exec loop
- if( ++buf->aliasCount > ALIAS_LOOP_COUNT ) {
+ if (++buf->aliasCount > ALIAS_LOOP_COUNT) {
ret = Q_ERR_RUNAWAY_LOOP;
goto finish;
}
// check for overflow
- if( buf->cursize + len + 1 > buf->maxsize ) {
+ if (buf->cursize + len + 1 > buf->maxsize) {
ret = Q_ERR_STRING_TRUNCATED;
goto finish;
}
// everything ok, execute it
- Com_Printf( "Execing %s\n", path );
- Cbuf_InsertText( buf, f );
+ Com_Printf("Execing %s\n", path);
+ Cbuf_InsertText(buf, f);
ret = Q_ERR_SUCCESS;
finish:
- FS_FreeFile( f );
+ FS_FreeFile(f);
return ret;
}
@@ -1663,51 +1724,54 @@ finish:
Cmd_Exec_f
===============
*/
-static void Cmd_Exec_f( void ) {
+static void Cmd_Exec_f(void)
+{
char buffer[MAX_QPATH];
size_t len;
qerror_t ret;
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "%s <filename> : execute a script file\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("%s <filename> : execute a script file\n", Cmd_Argv(0));
return;
}
- len = FS_NormalizePathBuffer( buffer, Cmd_Argv( 1 ), sizeof( buffer ) );
- if( len >= sizeof( buffer ) ) {
- Q_PrintError( "exec", Q_ERR_NAMETOOLONG );
+ len = FS_NormalizePathBuffer(buffer, Cmd_Argv(1), sizeof(buffer));
+ if (len >= sizeof(buffer)) {
+ Q_PrintError("exec", Q_ERR_NAMETOOLONG);
return;
}
- if( len == 0 ) {
- Q_PrintError( "exec", Q_ERR_NAMETOOSHORT );
+ if (len == 0) {
+ Q_PrintError("exec", Q_ERR_NAMETOOSHORT);
return;
}
- ret = Cmd_ExecuteFile( buffer, 0 );
- if( ret == Q_ERR_NOENT && COM_CompareExtension( buffer, ".cfg" ) ) {
+ ret = Cmd_ExecuteFile(buffer, 0);
+ if (ret == Q_ERR_NOENT && COM_CompareExtension(buffer, ".cfg")) {
// try with .cfg extension
- len = Q_strlcat( buffer, ".cfg", sizeof( buffer ) );
- if( len >= sizeof( buffer ) ) {
- Q_PrintError( "exec", Q_ERR_NAMETOOLONG );
+ len = Q_strlcat(buffer, ".cfg", sizeof(buffer));
+ if (len >= sizeof(buffer)) {
+ Q_PrintError("exec", Q_ERR_NAMETOOLONG);
return;
}
- ret = Cmd_ExecuteFile( buffer, 0 );
+ ret = Cmd_ExecuteFile(buffer, 0);
}
- if( ret ) {
- Com_Printf( "Couldn't exec %s: %s\n", buffer, Q_ErrorString( ret ) );
+ if (ret) {
+ Com_Printf("Couldn't exec %s: %s\n", buffer, Q_ErrorString(ret));
}
}
-void Cmd_Config_g( genctx_t *ctx ) {
- FS_File_g( "", "*.cfg", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER | FS_SEARCH_STRIPEXT, ctx );
+void Cmd_Config_g(genctx_t *ctx)
+{
+ FS_File_g("", "*.cfg", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER | FS_SEARCH_STRIPEXT, ctx);
}
-static void Cmd_Exec_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Cmd_Config_g( ctx );
+static void Cmd_Exec_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Cmd_Config_g(ctx);
}
}
@@ -1718,8 +1782,9 @@ Cmd_Echo_f
Just prints the rest of the line to the console
===============
*/
-static void Cmd_Echo_f( void ) {
- Com_Printf( "%s\n", Cmd_Args() );
+static void Cmd_Echo_f(void)
+{
+ Com_Printf("%s\n", Cmd_Args());
}
static const cmd_option_t o_echo[] = {
@@ -1730,17 +1795,19 @@ static const cmd_option_t o_echo[] = {
{ NULL }
};
-static void Cmd_EchoEx_c( genctx_t *ctx, int argnum ) {
- Cmd_Option_c( o_echo, NULL, ctx, argnum );
+static void Cmd_EchoEx_c(genctx_t *ctx, int argnum)
+{
+ Cmd_Option_c(o_echo, NULL, ctx, argnum);
}
-static char *unescape_string( char *dst, const char *src ) {
+static char *unescape_string(char *dst, const char *src)
+{
int c1, c2;
char *p = dst;
- while( *src ) {
- if( src[0] == '\\' && src[1] ) {
- switch( src[1] ) {
+ while (*src) {
+ if (src[0] == '\\' && src[1]) {
+ switch (src[1]) {
case 'a': *p++ = '\a'; break;
case 'b': *p++ = '\b'; break;
case 't': *p++ = '\t'; break;
@@ -1750,13 +1817,13 @@ static char *unescape_string( char *dst, const char *src ) {
case 'r': *p++ = '\r'; break;
case '\\': *p++ = '\\'; break;
case 'x':
- if( ( c1 = Q_charhex( src[2] ) ) == -1 ) {
+ if ((c1 = Q_charhex(src[2])) == -1) {
break;
}
- if( ( c2 = Q_charhex( src[3] ) ) == -1 ) {
+ if ((c2 = Q_charhex(src[3])) == -1) {
break;
}
- *p++ = ( c1 << 4 ) | c2;
+ *p++ = (c1 << 4) | c2;
src += 2;
break;
default:
@@ -1773,25 +1840,26 @@ static char *unescape_string( char *dst, const char *src ) {
return dst;
}
-static void Cmd_EchoEx_f( void ) {
+static void Cmd_EchoEx_f(void)
+{
char buffer[MAX_STRING_CHARS], *s;
qboolean escapes = qfalse;
color_index_t color = COLOR_NONE;
const char *newline = "\n";
int c;
- while( ( c = Cmd_ParseOptions( o_echo ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_echo)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_echo, "[text]" );
- Com_Printf( "Print a line of text into the console.\n" );
- Cmd_PrintHelp( o_echo );
+ Cmd_PrintUsage(o_echo, "[text]");
+ Com_Printf("Print a line of text into the console.\n");
+ Cmd_PrintHelp(o_echo);
return;
case 'e':
escapes = qtrue;
break;
case 'c':
- color = Com_ParseColor( cmd_optarg, COLOR_NONE );
+ color = Com_ParseColor(cmd_optarg, COLOR_NONE);
break;
case 'n':
newline = "";
@@ -1801,14 +1869,14 @@ static void Cmd_EchoEx_f( void ) {
}
}
- s = Cmd_RawArgsFrom( cmd_optind );
- if( escapes ) {
- s = unescape_string( buffer, s );
+ s = Cmd_RawArgsFrom(cmd_optind);
+ if (escapes) {
+ s = unescape_string(buffer, s);
}
- Com_SetColor( color );
- Com_Printf( "%s%s", s, newline );
- Com_SetColor( COLOR_NONE );
+ Com_SetColor(color);
+ Com_Printf("%s%s", s, newline);
+ Com_SetColor(COLOR_NONE);
}
/*
@@ -1816,25 +1884,26 @@ static void Cmd_EchoEx_f( void ) {
Cmd_List_f
============
*/
-static void Cmd_List_f( void ) {
+static void Cmd_List_f(void)
+{
cmd_function_t *cmd;
int i, total;
char *filter = NULL;
- if( cmd_argc > 1 ) {
+ if (cmd_argc > 1) {
filter = cmd_argv[1];
}
i = total = 0;
- FOR_EACH_CMD( cmd ) {
+ FOR_EACH_CMD(cmd) {
total++;
- if( filter && !Com_WildCmp( filter, cmd->name ) ) {
+ if (filter && !Com_WildCmp(filter, cmd->name)) {
continue;
}
- Com_Printf( "%s\n", cmd->name );
+ Com_Printf("%s\n", cmd->name);
i++;
}
- Com_Printf( "%i of %i commands\n", i, total );
+ Com_Printf("%i of %i commands\n", i, total);
}
/*
@@ -1842,70 +1911,73 @@ static void Cmd_List_f( void ) {
Cmd_MacroList_f
============
*/
-static void Cmd_MacroList_f( void ) {
+static void Cmd_MacroList_f(void)
+{
cmd_macro_t *macro;
int i, total;
char *filter = NULL;
char buffer[MAX_QPATH];
- if( cmd_argc > 1 ) {
+ if (cmd_argc > 1) {
filter = cmd_argv[1];
}
i = 0;
- for( macro = cmd_macros, total = 0; macro; macro = macro->next, total++ ) {
- if( filter && !Com_WildCmp( filter, macro->name ) ) {
+ for (macro = cmd_macros, total = 0; macro; macro = macro->next, total++) {
+ if (filter && !Com_WildCmp(filter, macro->name)) {
continue;
}
- macro->function( buffer, sizeof( buffer ) );
- Com_Printf( "%-16s %s\n", macro->name, buffer );
+ macro->function(buffer, sizeof(buffer));
+ Com_Printf("%-16s %s\n", macro->name, buffer);
i++;
}
- Com_Printf( "%i of %i macros\n", i, total );
+ Com_Printf("%i of %i macros\n", i, total);
}
-static void Cmd_Text_f( void ) {
- Cbuf_AddText( cmd_current, Cmd_Args() );
- Cbuf_AddText( cmd_current, "\n" );
+static void Cmd_Text_f(void)
+{
+ Cbuf_AddText(cmd_current, Cmd_Args());
+ Cbuf_AddText(cmd_current, "\n");
}
-static void Cmd_Complete_f( void ) {
+static void Cmd_Complete_f(void)
+{
cmd_function_t *cmd;
char *name;
unsigned hash;
size_t len;
- if( cmd_argc < 2 ) {
- Com_Printf( "Usage: %s <command>", cmd_argv[0] );
+ if (cmd_argc < 2) {
+ Com_Printf("Usage: %s <command>", cmd_argv[0]);
return;
}
name = cmd_argv[1];
// fail if the command is a variable name
- if( Cvar_Exists( name, qtrue ) ) {
- Com_Printf( "%s is already defined as a cvar\n", name );
+ if (Cvar_Exists(name, qtrue)) {
+ Com_Printf("%s is already defined as a cvar\n", name);
return;
}
-
+
// fail if the command already exists
- cmd = Cmd_Find( name );
- if( cmd ) {
- //Com_Printf( "%s is already defined\n", name );
+ cmd = Cmd_Find(name);
+ if (cmd) {
+ //Com_Printf("%s is already defined\n", name);
return;
}
- len = strlen( name ) + 1;
- cmd = Cmd_Malloc( sizeof( *cmd ) + len );
- cmd->name = ( char * )( cmd + 1 );
- memcpy( cmd->name, name, len );
+ len = strlen(name) + 1;
+ cmd = Cmd_Malloc(sizeof(*cmd) + len);
+ cmd->name = (char *)(cmd + 1);
+ memcpy(cmd->name, name, len);
cmd->function = NULL;
cmd->completer = NULL;
- List_Append( &cmd_functions, &cmd->listEntry );
+ List_Append(&cmd_functions, &cmd->listEntry);
- hash = Com_HashString( name, CMD_HASH_SIZE );
- List_Append( &cmd_hash[hash], &cmd->hashEntry );
+ hash = Com_HashString(name, CMD_HASH_SIZE);
+ List_Append(&cmd_hash[hash], &cmd->hashEntry);
}
static const cmdreg_t c_cmd[] = {
@@ -1931,21 +2003,22 @@ static const cmdreg_t c_cmd[] = {
Cmd_Init
============
*/
-void Cmd_Init( void ) {
+void Cmd_Init(void)
+{
int i;
- List_Init( &cmd_functions );
- for( i = 0; i < CMD_HASH_SIZE; i++ ) {
- List_Init( &cmd_hash[i] );
+ List_Init(&cmd_functions);
+ for (i = 0; i < CMD_HASH_SIZE; i++) {
+ List_Init(&cmd_hash[i]);
}
- List_Init( &cmd_alias );
- for( i = 0; i < ALIAS_HASH_SIZE; i++ ) {
- List_Init( &cmd_aliasHash[i] );
+ List_Init(&cmd_alias);
+ for (i = 0; i < ALIAS_HASH_SIZE; i++) {
+ List_Init(&cmd_aliasHash[i]);
}
- List_Init( &cmd_triggers );
+ List_Init(&cmd_triggers);
- Cmd_Register( c_cmd );
+ Cmd_Register(c_cmd);
}
diff --git a/src/cmodel.c b/src/cmodel.c
index 9b026a6..59ca887 100644
--- a/src/cmodel.c
+++ b/src/cmodel.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -35,20 +35,21 @@ static int checkcount;
static cvar_t *map_noareas;
static cvar_t *map_allsolid_bug;
-static void FloodAreaConnections( cm_t *cm );
+static void FloodAreaConnections(cm_t *cm);
/*
==================
CM_FreeMap
==================
*/
-void CM_FreeMap( cm_t *cm ) {
- if( cm->floodnums ) {
- Z_Free( cm->floodnums );
+void CM_FreeMap(cm_t *cm)
+{
+ if (cm->floodnums) {
+ Z_Free(cm->floodnums);
}
- BSP_Free( cm->cache );
+ BSP_Free(cm->cache);
- memset( cm, 0, sizeof( *cm ) );
+ memset(cm, 0, sizeof(*cm));
}
/*
@@ -58,44 +59,47 @@ CM_LoadMap
Loads in the map and all submodels
==================
*/
-qerror_t CM_LoadMap( cm_t *cm, const char *name ) {
+qerror_t CM_LoadMap(cm_t *cm, const char *name)
+{
bsp_t *cache;
qerror_t ret;
- ret = BSP_Load( name, &cache );
- if( !cache ) {
+ ret = BSP_Load(name, &cache);
+ if (!cache) {
return ret;
}
cm->cache = cache;
- cm->floodnums = Z_TagMallocz( sizeof( int ) * cm->cache->numareas +
- sizeof( qboolean ) * ( cm->cache->lastareaportal + 1 ), TAG_CMODEL );
- cm->portalopen = ( qboolean * )( cm->floodnums + cm->cache->numareas );
- FloodAreaConnections( cm );
+ cm->floodnums = Z_TagMallocz(sizeof(int) * cm->cache->numareas +
+ sizeof(qboolean) * (cm->cache->lastareaportal + 1), TAG_CMODEL);
+ cm->portalopen = (qboolean *)(cm->floodnums + cm->cache->numareas);
+ FloodAreaConnections(cm);
return Q_ERR_SUCCESS;
}
-mnode_t *CM_NodeNum( cm_t *cm, int number ) {
- if( !cm->cache ) {
- return ( mnode_t * )&nullleaf;
+mnode_t *CM_NodeNum(cm_t *cm, int number)
+{
+ if (!cm->cache) {
+ return (mnode_t *)&nullleaf;
}
- if( number == -1 ) {
- return ( mnode_t * )cm->cache->leafs; // special case for solid leaf
+ if (number == -1) {
+ return (mnode_t *)cm->cache->leafs; // special case for solid leaf
}
- if( number < 0 || number >= cm->cache->numnodes ) {
- Com_EPrintf( "%s: bad number: %d\n", __func__, number );
- return ( mnode_t * )&nullleaf;
+ if (number < 0 || number >= cm->cache->numnodes) {
+ Com_EPrintf("%s: bad number: %d\n", __func__, number);
+ return (mnode_t *)&nullleaf;
}
return cm->cache->nodes + number;
}
-mleaf_t *CM_LeafNum( cm_t *cm, int number ) {
- if( !cm->cache ) {
+mleaf_t *CM_LeafNum(cm_t *cm, int number)
+{
+ if (!cm->cache) {
return &nullleaf;
}
- if( number < 0 || number >= cm->cache->numleafs ) {
- Com_EPrintf( "%s: bad number: %d\n", __func__, number );
+ if (number < 0 || number >= cm->cache->numleafs) {
+ Com_EPrintf("%s: bad number: %d\n", __func__, number);
return &nullleaf;
}
return cm->cache->leafs + number;
@@ -120,7 +124,8 @@ Set up the planes and nodes so that the six floats of a bounding box
can just be stored out and get a proper clipping hull structure.
===================
*/
-static void CM_InitBoxHull( void ) {
+static void CM_InitBoxHull(void)
+{
int i;
int side;
mnode_t *c;
@@ -139,36 +144,36 @@ static void CM_InitBoxHull( void ) {
box_leafbrush = &box_brush;
- for( i = 0; i < 6; i++ ) {
+ for (i = 0; i < 6; i++) {
side = i & 1;
// brush sides
s = &box_brushsides[i];
- s->plane = &box_planes[i*2+side];
+ s->plane = &box_planes[i * 2 + side];
s->texinfo = &nulltexinfo;
// nodes
c = &box_nodes[i];
- c->plane = &box_planes[i*2];
- c->children[side] = ( mnode_t * )&box_emptyleaf;
- if( i != 5 )
- c->children[side^1] = &box_nodes[i + 1];
+ c->plane = &box_planes[i * 2];
+ c->children[side] = (mnode_t *)&box_emptyleaf;
+ if (i != 5)
+ c->children[side ^ 1] = &box_nodes[i + 1];
else
- c->children[side^1] = ( mnode_t * )&box_leaf;
+ c->children[side ^ 1] = (mnode_t *)&box_leaf;
// planes
- p = &box_planes[i*2];
+ p = &box_planes[i * 2];
p->type = i >> 1;
p->signbits = 0;
- VectorClear( p->normal );
- p->normal[i>>1] = 1;
+ VectorClear(p->normal);
+ p->normal[i >> 1] = 1;
- p = &box_planes[i*2+1];
- p->type = 3 + ( i >> 1 );
+ p = &box_planes[i * 2 + 1];
+ p->type = 3 + (i >> 1);
p->signbits = 0;
- VectorClear( p->normal );
- p->normal[i>>1] = -1;
- }
+ VectorClear(p->normal);
+ p->normal[i >> 1] = -1;
+ }
}
@@ -180,7 +185,8 @@ To keep everything totally uniform, bounding boxes are turned into small
BSP trees instead of being compared directly.
===================
*/
-mnode_t *CM_HeadnodeForBox( vec3_t mins, vec3_t maxs ) {
+mnode_t *CM_HeadnodeForBox(vec3_t mins, vec3_t maxs)
+{
box_planes[0].dist = maxs[0];
box_planes[1].dist = -maxs[0];
box_planes[2].dist = mins[0];
@@ -198,11 +204,12 @@ mnode_t *CM_HeadnodeForBox( vec3_t mins, vec3_t maxs ) {
}
-mleaf_t *CM_PointLeaf( cm_t *cm, vec3_t p ) {
- if( !cm->cache ) {
+mleaf_t *CM_PointLeaf(cm_t *cm, vec3_t p)
+{
+ if (!cm->cache) {
return &nullleaf; // server may call this without map loaded
}
- return BSP_PointLeaf( cm->cache->nodes, p );
+ return BSP_PointLeaf(cm->cache->nodes, p);
}
/*
@@ -217,32 +224,33 @@ static mleaf_t **leaf_list;
static float *leaf_mins, *leaf_maxs;
static mnode_t *leaf_topnode;
-static void CM_BoxLeafs_r( mnode_t *node ) {
+static void CM_BoxLeafs_r(mnode_t *node)
+{
int s;
- while( node->plane ) {
- s = BoxOnPlaneSideFast( leaf_mins, leaf_maxs, node->plane );
- if( s == 1 ) {
+ while (node->plane) {
+ s = BoxOnPlaneSideFast(leaf_mins, leaf_maxs, node->plane);
+ if (s == 1) {
node = node->children[0];
- } else if( s == 2 ) {
+ } else if (s == 2) {
node = node->children[1];
} else {
// go down both
- if( !leaf_topnode ) {
+ if (!leaf_topnode) {
leaf_topnode = node;
}
- CM_BoxLeafs_r( node->children[0] );
+ CM_BoxLeafs_r(node->children[0]);
node = node->children[1];
}
}
- if( leaf_count < leaf_maxcount ) {
- leaf_list[leaf_count++] = ( mleaf_t * )node;
+ if (leaf_count < leaf_maxcount) {
+ leaf_list[leaf_count++] = (mleaf_t *)node;
}
}
-static int CM_BoxLeafs_headnode( vec3_t mins, vec3_t maxs, mleaf_t **list, int listsize,
- mnode_t *headnode, mnode_t **topnode )
+static int CM_BoxLeafs_headnode(vec3_t mins, vec3_t maxs, mleaf_t **list, int listsize,
+ mnode_t *headnode, mnode_t **topnode)
{
leaf_list = list;
leaf_count = 0;
@@ -252,19 +260,20 @@ static int CM_BoxLeafs_headnode( vec3_t mins, vec3_t maxs, mleaf_t **list, int l
leaf_topnode = NULL;
- CM_BoxLeafs_r( headnode );
+ CM_BoxLeafs_r(headnode);
- if( topnode )
+ if (topnode)
*topnode = leaf_topnode;
return leaf_count;
}
-int CM_BoxLeafs( cm_t *cm, vec3_t mins, vec3_t maxs, mleaf_t **list, int listsize, mnode_t **topnode ) {
- if( !cm->cache ) // map not loaded
+int CM_BoxLeafs(cm_t *cm, vec3_t mins, vec3_t maxs, mleaf_t **list, int listsize, mnode_t **topnode)
+{
+ if (!cm->cache) // map not loaded
return 0;
- return CM_BoxLeafs_headnode( mins, maxs, list,
- listsize, cm->cache->nodes, topnode );
+ return CM_BoxLeafs_headnode(mins, maxs, list,
+ listsize, cm->cache->nodes, topnode);
}
@@ -275,14 +284,15 @@ CM_PointContents
==================
*/
-int CM_PointContents( vec3_t p, mnode_t *headnode ) {
+int CM_PointContents(vec3_t p, mnode_t *headnode)
+{
mleaf_t *leaf;
- if( !headnode ) {
+ if (!headnode) {
return 0;
}
- leaf = BSP_PointLeaf( headnode, p );
+ leaf = BSP_PointLeaf(headnode, p);
return leaf->contents;
}
@@ -295,32 +305,32 @@ Handles offseting and rotation of the end points for moving and
rotating entities
==================
*/
-int CM_TransformedPointContents( vec3_t p, mnode_t *headnode, vec3_t origin, vec3_t angles ) {
+int CM_TransformedPointContents(vec3_t p, mnode_t *headnode, vec3_t origin, vec3_t angles)
+{
vec3_t p_l;
vec3_t temp;
vec3_t forward, right, up;
mleaf_t *leaf;
- if( !headnode ) {
+ if (!headnode) {
return 0;
}
// subtract origin offset
- VectorSubtract (p, origin, p_l);
+ VectorSubtract(p, origin, p_l);
// rotate start and end into the models frame of reference
- if (headnode != box_headnode &&
- (angles[0] || angles[1] || angles[2]) )
- {
- AngleVectors (angles, forward, right, up);
-
- VectorCopy (p_l, temp);
- p_l[0] = DotProduct (temp, forward);
- p_l[1] = -DotProduct (temp, right);
- p_l[2] = DotProduct (temp, up);
+ if (headnode != box_headnode &&
+ (angles[0] || angles[1] || angles[2])) {
+ AngleVectors(angles, forward, right, up);
+
+ VectorCopy(p_l, temp);
+ p_l[0] = DotProduct(temp, forward);
+ p_l[1] = -DotProduct(temp, right);
+ p_l[2] = DotProduct(temp, up);
}
- leaf = BSP_PointLeaf( headnode, p_l );
+ leaf = BSP_PointLeaf(headnode, p_l);
return leaf->contents;
}
@@ -350,8 +360,8 @@ static qboolean trace_ispoint; // optimized case
CM_ClipBoxToBrush
================
*/
-static void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
- trace_t *trace, mbrush_t *brush)
+static void CM_ClipBoxToBrush(vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
+ trace_t *trace, mbrush_t *brush)
{
int i, j;
cplane_t *plane, *clipplane;
@@ -375,35 +385,32 @@ static void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
leadside = NULL;
side = brush->firstbrushside;
- for (i=0 ; i<brush->numsides ; i++, side++)
- {
+ for (i = 0; i < brush->numsides; i++, side++) {
plane = side->plane;
// FIXME: special case for axial
- if (!trace_ispoint)
- { // general box case
+ if (!trace_ispoint) {
+ // general box case
// push the plane out apropriately for mins/maxs
// FIXME: use signbits into 8 way lookup for each mins/maxs
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
if (plane->normal[j] < 0)
ofs[j] = maxs[j];
else
ofs[j] = mins[j];
}
- dist = DotProduct (ofs, plane->normal);
+ dist = DotProduct(ofs, plane->normal);
dist = plane->dist - dist;
- }
- else
- { // special point case
+ } else {
+ // special point case
dist = plane->dist;
}
- d1 = DotProduct (p1, plane->normal) - dist;
- d2 = DotProduct (p2, plane->normal) - dist;
+ d1 = DotProduct(p1, plane->normal) - dist;
+ d2 = DotProduct(p2, plane->normal) - dist;
if (d2 > 0)
getout = qtrue; // endpoint is not in solid
@@ -418,30 +425,28 @@ static void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
continue;
// crosses face
- if (d1 > d2)
- { // enter
- f = (d1-DIST_EPSILON) / (d1-d2);
- if (f > enterfrac)
- {
+ if (d1 > d2) {
+ // enter
+ f = (d1 - DIST_EPSILON) / (d1 - d2);
+ if (f > enterfrac) {
enterfrac = f;
clipplane = plane;
leadside = side;
}
- }
- else
- { // leave
- f = (d1+DIST_EPSILON) / (d1-d2);
+ } else {
+ // leave
+ f = (d1 + DIST_EPSILON) / (d1 - d2);
if (f < leavefrac)
leavefrac = f;
}
}
- if (!startout)
- { // original point was inside brush
+ if (!startout) {
+ // original point was inside brush
trace->startsolid = qtrue;
- if( !getout ) {
+ if (!getout) {
trace->allsolid = qtrue;
- if( !map_allsolid_bug->integer ) {
+ if (!map_allsolid_bug->integer) {
// original Q2 didn't set these
trace->fraction = 0;
trace->contents = brush->contents;
@@ -449,10 +454,8 @@ static void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
}
return;
}
- if (enterfrac < leavefrac)
- {
- if (enterfrac > -1 && enterfrac < trace->fraction)
- {
+ if (enterfrac < leavefrac) {
+ if (enterfrac > -1 && enterfrac < trace->fraction) {
if (enterfrac < 0)
enterfrac = 0;
trace->fraction = enterfrac;
@@ -468,8 +471,8 @@ static void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
CM_TestBoxInBrush
================
*/
-static void CM_TestBoxInBrush (vec3_t mins, vec3_t maxs, vec3_t p1,
- trace_t *trace, mbrush_t *brush)
+static void CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
+ trace_t *trace, mbrush_t *brush)
{
int i, j;
cplane_t *plane;
@@ -482,8 +485,7 @@ static void CM_TestBoxInBrush (vec3_t mins, vec3_t maxs, vec3_t p1,
return;
side = brush->firstbrushside;
- for (i=0 ; i<brush->numsides ; i++, side++)
- {
+ for (i = 0; i < brush->numsides; i++, side++) {
plane = side->plane;
// FIXME: special case for axial
@@ -493,17 +495,16 @@ static void CM_TestBoxInBrush (vec3_t mins, vec3_t maxs, vec3_t p1,
// push the plane out apropriately for mins/maxs
// FIXME: use signbits into 8 way lookup for each mins/maxs
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
if (plane->normal[j] < 0)
ofs[j] = maxs[j];
else
ofs[j] = mins[j];
}
- dist = DotProduct (ofs, plane->normal);
+ dist = DotProduct(ofs, plane->normal);
dist = plane->dist - dist;
- d1 = DotProduct (p1, plane->normal) - dist;
+ d1 = DotProduct(p1, plane->normal) - dist;
// if completely in front of face, no intersection
if (d1 > 0)
@@ -523,25 +524,24 @@ static void CM_TestBoxInBrush (vec3_t mins, vec3_t maxs, vec3_t p1,
CM_TraceToLeaf
================
*/
-static void CM_TraceToLeaf ( mleaf_t *leaf )
+static void CM_TraceToLeaf(mleaf_t *leaf)
{
int k;
mbrush_t *b, **leafbrush;
- if( !( leaf->contents & trace_contents ) )
+ if (!(leaf->contents & trace_contents))
return;
// trace line against all brushes in the leaf
leafbrush = leaf->firstleafbrush;
- for (k=0 ; k<leaf->numleafbrushes ; k++, leafbrush++)
- {
+ for (k = 0; k < leaf->numleafbrushes; k++, leafbrush++) {
b = *leafbrush;
if (b->checkcount == checkcount)
continue; // already checked this brush in another leaf
b->checkcount = checkcount;
- if ( !(b->contents & trace_contents))
+ if (!(b->contents & trace_contents))
continue;
- CM_ClipBoxToBrush (trace_mins, trace_maxs, trace_start, trace_end, trace_trace, b);
+ CM_ClipBoxToBrush(trace_mins, trace_maxs, trace_start, trace_end, trace_trace, b);
if (!trace_trace->fraction)
return;
}
@@ -554,25 +554,24 @@ static void CM_TraceToLeaf ( mleaf_t *leaf )
CM_TestInLeaf
================
*/
-static void CM_TestInLeaf ( mleaf_t *leaf )
+static void CM_TestInLeaf(mleaf_t *leaf)
{
int k;
mbrush_t *b, **leafbrush;
- if( !( leaf->contents & trace_contents ) )
+ if (!(leaf->contents & trace_contents))
return;
// trace line against all brushes in the leaf
leafbrush = leaf->firstleafbrush;
- for (k=0 ; k<leaf->numleafbrushes ; k++, leafbrush++)
- {
+ for (k = 0; k < leaf->numleafbrushes; k++, leafbrush++) {
b = *leafbrush;
if (b->checkcount == checkcount)
continue; // already checked this brush in another leaf
b->checkcount = checkcount;
- if ( !(b->contents & trace_contents))
+ if (!(b->contents & trace_contents))
continue;
- CM_TestBoxInBrush (trace_mins, trace_maxs, trace_start, trace_trace, b);
+ CM_TestBoxInBrush(trace_mins, trace_maxs, trace_start, trace_trace, b);
if (!trace_trace->fraction)
return;
}
@@ -586,7 +585,7 @@ CM_RecursiveHullCheck
==================
*/
-static void CM_RecursiveHullCheck ( mnode_t *node, float p1f, float p2f, vec3_t p1, vec3_t p2)
+static void CM_RecursiveHullCheck(mnode_t *node, float p1f, float p2f, vec3_t p1, vec3_t p2)
{
cplane_t *plane;
float t1, t2, offset;
@@ -604,7 +603,7 @@ recheck:
// if plane is NULL, we are in a leaf node
plane = node->plane;
if (!plane) {
- CM_TraceToLeaf ( ( mleaf_t * )node );
+ CM_TraceToLeaf((mleaf_t *)node);
return;
}
@@ -612,53 +611,43 @@ recheck:
// find the point distances to the seperating plane
// and the offset for the size of the box
//
- if (plane->type < 3)
- {
+ if (plane->type < 3) {
t1 = p1[plane->type] - plane->dist;
t2 = p2[plane->type] - plane->dist;
offset = trace_extents[plane->type];
- }
- else
- {
- t1 = PlaneDiff( p1, plane );
- t2 = PlaneDiff( p2, plane );
+ } else {
+ t1 = PlaneDiff(p1, plane);
+ t2 = PlaneDiff(p2, plane);
if (trace_ispoint)
offset = 0;
else
- offset = fabs(trace_extents[0]*plane->normal[0]) +
- fabs(trace_extents[1]*plane->normal[1]) +
- fabs(trace_extents[2]*plane->normal[2]);
+ offset = fabs(trace_extents[0] * plane->normal[0]) +
+ fabs(trace_extents[1] * plane->normal[1]) +
+ fabs(trace_extents[2] * plane->normal[2]);
}
// see which sides we need to consider
- if (t1 >= offset && t2 >= offset)
- {
+ if (t1 >= offset && t2 >= offset) {
node = node->children[0];
goto recheck;
}
- if (t1 < -offset && t2 < -offset)
- {
+ if (t1 < -offset && t2 < -offset) {
node = node->children[1];
goto recheck;
}
// put the crosspoint DIST_EPSILON pixels on the near side
- if (t1 < t2)
- {
- idist = 1.0/(t1-t2);
+ if (t1 < t2) {
+ idist = 1.0 / (t1 - t2);
side = 1;
- frac2 = (t1 + offset + DIST_EPSILON)*idist;
- frac = (t1 - offset + DIST_EPSILON)*idist;
- }
- else if (t1 > t2)
- {
- idist = 1.0/(t1-t2);
+ frac2 = (t1 + offset + DIST_EPSILON) * idist;
+ frac = (t1 - offset + DIST_EPSILON) * idist;
+ } else if (t1 > t2) {
+ idist = 1.0 / (t1 - t2);
side = 0;
- frac2 = (t1 - offset - DIST_EPSILON)*idist;
- frac = (t1 + offset + DIST_EPSILON)*idist;
- }
- else
- {
+ frac2 = (t1 - offset - DIST_EPSILON) * idist;
+ frac = (t1 + offset + DIST_EPSILON) * idist;
+ } else {
side = 0;
frac = 1;
frac2 = 0;
@@ -669,12 +658,12 @@ recheck:
frac = 0;
if (frac > 1)
frac = 1;
-
- midf = p1f + (p2f - p1f)*frac;
- for (i=0 ; i<3 ; i++)
- mid[i] = p1[i] + frac*(p2[i] - p1[i]);
- CM_RecursiveHullCheck (node->children[side], p1f, midf, p1, mid);
+ midf = p1f + (p2f - p1f) * frac;
+ for (i = 0; i < 3; i++)
+ mid[i] = p1[i] + frac * (p2[i] - p1[i]);
+
+ CM_RecursiveHullCheck(node->children[side], p1f, midf, p1, mid);
// go past the node
@@ -682,12 +671,12 @@ recheck:
frac2 = 0;
if (frac2 > 1)
frac2 = 1;
-
- midf = p1f + (p2f - p1f)*frac2;
- for (i=0 ; i<3 ; i++)
- mid[i] = p1[i] + frac2*(p2[i] - p1[i]);
- CM_RecursiveHullCheck (node->children[side^1], midf, p2f, mid, p2);
+ midf = p1f + (p2f - p1f) * frac2;
+ for (i = 0; i < 3; i++)
+ mid[i] = p1[i] + frac2 * (p2[i] - p1[i]);
+
+ CM_RecursiveHullCheck(node->children[side ^ 1], midf, p2f, mid, p2);
}
@@ -699,9 +688,9 @@ recheck:
CM_BoxTrace
==================
*/
-void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
- vec3_t mins, vec3_t maxs,
- mnode_t *headnode, int brushmask )
+void CM_BoxTrace(trace_t *trace, vec3_t start, vec3_t end,
+ vec3_t mins, vec3_t maxs,
+ mnode_t *headnode, int brushmask)
{
int i;
@@ -709,45 +698,42 @@ void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
// fill in a default trace
trace_trace = trace;
- memset (trace_trace, 0, sizeof( *trace_trace ));
+ memset(trace_trace, 0, sizeof(*trace_trace));
trace_trace->fraction = 1;
trace_trace->surface = &(nulltexinfo.c);
- if( !headnode ) {
+ if (!headnode) {
return;
}
trace_contents = brushmask;
- VectorCopy (start, trace_start);
- VectorCopy (end, trace_end);
- VectorCopy (mins, trace_mins);
- VectorCopy (maxs, trace_maxs);
+ VectorCopy(start, trace_start);
+ VectorCopy(end, trace_end);
+ VectorCopy(mins, trace_mins);
+ VectorCopy(maxs, trace_maxs);
//
// check for position test special case
//
- if (start[0] == end[0] && start[1] == end[1] && start[2] == end[2])
- {
+ if (start[0] == end[0] && start[1] == end[1] && start[2] == end[2]) {
mleaf_t *leafs[1024];
int i, numleafs;
vec3_t c1, c2;
- VectorAdd (start, mins, c1);
- VectorAdd (start, maxs, c2);
- for (i=0 ; i<3 ; i++)
- {
+ VectorAdd(start, mins, c1);
+ VectorAdd(start, maxs, c2);
+ for (i = 0; i < 3; i++) {
c1[i] -= 1;
c2[i] += 1;
}
- numleafs = CM_BoxLeafs_headnode (c1, c2, leafs, 1024, headnode, NULL);
- for (i=0 ; i<numleafs ; i++)
- {
- CM_TestInLeaf (leafs[i]);
+ numleafs = CM_BoxLeafs_headnode(c1, c2, leafs, 1024, headnode, NULL);
+ for (i = 0; i < numleafs; i++) {
+ CM_TestInLeaf(leafs[i]);
if (trace_trace->allsolid)
break;
}
- VectorCopy (start, trace_trace->endpos);
+ VectorCopy(start, trace_trace->endpos);
return;
}
@@ -755,13 +741,10 @@ void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
// check for point special case
//
if (mins[0] == 0 && mins[1] == 0 && mins[2] == 0
- && maxs[0] == 0 && maxs[1] == 0 && maxs[2] == 0)
- {
+ && maxs[0] == 0 && maxs[1] == 0 && maxs[2] == 0) {
trace_ispoint = qtrue;
- VectorClear (trace_extents);
- }
- else
- {
+ VectorClear(trace_extents);
+ } else {
trace_ispoint = qfalse;
trace_extents[0] = -mins[0] > maxs[0] ? -mins[0] : maxs[0];
trace_extents[1] = -mins[1] > maxs[1] ? -mins[1] : maxs[1];
@@ -771,18 +754,15 @@ void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
//
// general sweeping through world
//
- CM_RecursiveHullCheck (headnode, 0, 1, start, end);
+ CM_RecursiveHullCheck(headnode, 0, 1, start, end);
- if (trace_trace->fraction == 1)
- {
- VectorCopy (end, trace_trace->endpos);
- }
- else
- {
- for (i=0 ; i<3 ; i++)
+ if (trace_trace->fraction == 1) {
+ VectorCopy(end, trace_trace->endpos);
+ } else {
+ for (i = 0; i < 3; i++)
trace_trace->endpos[i] = start[i] + trace_trace->fraction * (end[i] - start[i]);
}
-
+
}
@@ -794,10 +774,10 @@ Handles offseting and rotation of the end points for moving and
rotating entities
==================
*/
-void CM_TransformedBoxTrace ( trace_t *trace, vec3_t start, vec3_t end,
- vec3_t mins, vec3_t maxs,
- mnode_t *headnode, int brushmask,
- vec3_t origin, vec3_t angles)
+void CM_TransformedBoxTrace(trace_t *trace, vec3_t start, vec3_t end,
+ vec3_t mins, vec3_t maxs,
+ mnode_t *headnode, int brushmask,
+ vec3_t origin, vec3_t angles)
{
vec3_t start_l, end_l;
vec3_t a;
@@ -806,44 +786,42 @@ void CM_TransformedBoxTrace ( trace_t *trace, vec3_t start, vec3_t end,
qboolean rotated;
// subtract origin offset
- VectorSubtract (start, origin, start_l);
- VectorSubtract (end, origin, end_l);
+ VectorSubtract(start, origin, start_l);
+ VectorSubtract(end, origin, end_l);
// rotate start and end into the models frame of reference
- if (headnode != box_headnode &&
- (angles[0] || angles[1] || angles[2]) )
+ if (headnode != box_headnode &&
+ (angles[0] || angles[1] || angles[2]))
rotated = qtrue;
else
rotated = qfalse;
- if (rotated)
- {
- AngleVectors (angles, forward, right, up);
+ if (rotated) {
+ AngleVectors(angles, forward, right, up);
- VectorCopy (start_l, temp);
- start_l[0] = DotProduct (temp, forward);
- start_l[1] = -DotProduct (temp, right);
- start_l[2] = DotProduct (temp, up);
+ VectorCopy(start_l, temp);
+ start_l[0] = DotProduct(temp, forward);
+ start_l[1] = -DotProduct(temp, right);
+ start_l[2] = DotProduct(temp, up);
- VectorCopy (end_l, temp);
- end_l[0] = DotProduct (temp, forward);
- end_l[1] = -DotProduct (temp, right);
- end_l[2] = DotProduct (temp, up);
+ VectorCopy(end_l, temp);
+ end_l[0] = DotProduct(temp, forward);
+ end_l[1] = -DotProduct(temp, right);
+ end_l[2] = DotProduct(temp, up);
}
// sweep the box through the model
- CM_BoxTrace ( trace, start_l, end_l, mins, maxs, headnode, brushmask);
+ CM_BoxTrace(trace, start_l, end_l, mins, maxs, headnode, brushmask);
- if (rotated && trace->fraction != 1.0)
- {
+ if (rotated && trace->fraction != 1.0) {
// FIXME: figure out how to do this with existing angles
- VectorNegate (angles, a);
- AngleVectors (a, forward, right, up);
+ VectorNegate(angles, a);
+ AngleVectors(a, forward, right, up);
- VectorCopy (trace->plane.normal, temp);
- trace->plane.normal[0] = DotProduct (temp, forward);
- trace->plane.normal[1] = -DotProduct (temp, right);
- trace->plane.normal[2] = DotProduct (temp, up);
+ VectorCopy(trace->plane.normal, temp);
+ trace->plane.normal[0] = DotProduct(temp, forward);
+ trace->plane.normal[1] = -DotProduct(temp, right);
+ trace->plane.normal[2] = DotProduct(temp, up);
}
trace->endpos[0] = start[0] + trace->fraction * (end[0] - start[0]);
@@ -851,12 +829,13 @@ void CM_TransformedBoxTrace ( trace_t *trace, vec3_t start, vec3_t end,
trace->endpos[2] = start[2] + trace->fraction * (end[2] - start[2]);
}
-void CM_ClipEntity( trace_t *dst, const trace_t *src, struct edict_s *ent ) {
+void CM_ClipEntity(trace_t *dst, const trace_t *src, struct edict_s *ent)
+{
dst->allsolid |= src->allsolid;
dst->startsolid |= src->startsolid;
- if( src->fraction < dst->fraction ) {
+ if (src->fraction < dst->fraction) {
dst->fraction = src->fraction;
- VectorCopy( src->endpos, dst->endpos );
+ VectorCopy(src->endpos, dst->endpos);
dst->plane = src->plane;
dst->surface = src->surface;
dst->contents |= src->contents;
@@ -873,28 +852,30 @@ AREAPORTALS
===============================================================================
*/
-static void FloodArea_r( cm_t *cm, int number, int floodnum ) {
+static void FloodArea_r(cm_t *cm, int number, int floodnum)
+{
int i;
mareaportal_t *p;
marea_t *area;
area = &cm->cache->areas[number];
- if( area->floodvalid == floodvalid ) {
- if( cm->floodnums[number] == floodnum )
+ if (area->floodvalid == floodvalid) {
+ if (cm->floodnums[number] == floodnum)
return;
- Com_Error( ERR_DROP, "FloodArea_r: reflooded" );
+ Com_Error(ERR_DROP, "FloodArea_r: reflooded");
}
cm->floodnums[number] = floodnum;
area->floodvalid = floodvalid;
p = area->firstareaportal;
- for( i = 0; i < area->numareaportals; i++, p++ ) {
- if( cm->portalopen[p->portalnum] )
- FloodArea_r( cm, p->otherarea, floodnum );
+ for (i = 0; i < area->numareaportals; i++, p++) {
+ if (cm->portalopen[p->portalnum])
+ FloodArea_r(cm, p->otherarea, floodnum);
}
}
-static void FloodAreaConnections( cm_t *cm ) {
+static void FloodAreaConnections(cm_t *cm)
+{
int i;
marea_t *area;
int floodnum;
@@ -904,52 +885,54 @@ static void FloodAreaConnections( cm_t *cm ) {
floodnum = 0;
// area 0 is not used
- for( i = 1; i < cm->cache->numareas; i++ ) {
+ for (i = 1; i < cm->cache->numareas; i++) {
area = &cm->cache->areas[i];
- if( area->floodvalid == floodvalid )
+ if (area->floodvalid == floodvalid)
continue; // already flooded into
floodnum++;
- FloodArea_r( cm, i, floodnum );
+ FloodArea_r(cm, i, floodnum);
}
}
-void CM_SetAreaPortalState( cm_t *cm, int portalnum, qboolean open ) {
- if( !cm->cache ) {
+void CM_SetAreaPortalState(cm_t *cm, int portalnum, qboolean open)
+{
+ if (!cm->cache) {
return;
}
- if( portalnum < 0 || portalnum >= MAX_MAP_AREAPORTALS ) {
- Com_EPrintf( "%s: portalnum %d is out of range\n", __func__, portalnum );
+ if (portalnum < 0 || portalnum >= MAX_MAP_AREAPORTALS) {
+ Com_EPrintf("%s: portalnum %d is out of range\n", __func__, portalnum);
return;
}
// ignore areaportals not referenced by areas
- if( portalnum > cm->cache->lastareaportal ) {
- Com_DPrintf( "%s: portalnum %d is not in use\n", __func__, portalnum );
+ if (portalnum > cm->cache->lastareaportal) {
+ Com_DPrintf("%s: portalnum %d is not in use\n", __func__, portalnum);
return;
}
cm->portalopen[portalnum] = open;
- FloodAreaConnections( cm );
+ FloodAreaConnections(cm);
}
-qboolean CM_AreasConnected( cm_t *cm, int area1, int area2 ) {
+qboolean CM_AreasConnected(cm_t *cm, int area1, int area2)
+{
bsp_t *cache = cm->cache;
- if( !cache ) {
+ if (!cache) {
return qfalse;
}
- if( map_noareas->integer ) {
+ if (map_noareas->integer) {
return qtrue;
}
- if( area1 < 1 || area2 < 1 ) {
+ if (area1 < 1 || area2 < 1) {
return qfalse;
}
- if( area1 >= cache->numareas || area2 >= cache->numareas ) {
- Com_EPrintf( "%s: area > numareas\n", __func__ );
+ if (area1 >= cache->numareas || area2 >= cache->numareas) {
+ Com_EPrintf("%s: area > numareas\n", __func__);
return qfalse;
}
- if( cm->floodnums[area1] == cm->floodnums[area2] ) {
+ if (cm->floodnums[area1] == cm->floodnums[area2]) {
return qtrue;
}
@@ -967,28 +950,29 @@ that area in the same flood as the area parameter
This is used by the client refreshes to cull visibility
=================
*/
-int CM_WriteAreaBits( cm_t *cm, byte *buffer, int area ) {
+int CM_WriteAreaBits(cm_t *cm, byte *buffer, int area)
+{
bsp_t *cache = cm->cache;
int i;
int floodnum;
int bytes;
- if( !cache ) {
+ if (!cache) {
return 0;
}
- bytes = ( cache->numareas + 7 ) >> 3;
+ bytes = (cache->numareas + 7) >> 3;
- if( map_noareas->integer || !area ) {
+ if (map_noareas->integer || !area) {
// for debugging, send everything
- memset( buffer, 255, bytes );
+ memset(buffer, 255, bytes);
} else {
- memset( buffer, 0, bytes );
+ memset(buffer, 0, bytes);
floodnum = cm->floodnums[area];
- for ( i = 0; i < cache->numareas; i++) {
- if( cm->floodnums[i] == floodnum ) {
- Q_SetBit( buffer, i );
+ for (i = 0; i < cache->numareas; i++) {
+ if (cm->floodnums[i] == floodnum) {
+ Q_SetBit(buffer, i);
}
}
}
@@ -996,54 +980,56 @@ int CM_WriteAreaBits( cm_t *cm, byte *buffer, int area ) {
return bytes;
}
-int CM_WritePortalBits( cm_t *cm, byte *buffer ) {
+int CM_WritePortalBits(cm_t *cm, byte *buffer)
+{
int i, bytes, numportals;
- if( !cm->cache ) {
+ if (!cm->cache) {
return 0;
}
numportals = cm->cache->lastareaportal + 1;
- if( numportals > MAX_MAP_AREAS ) {
+ if (numportals > MAX_MAP_AREAS) {
/* HACK: use the same array size as areabytes!
* It is nonsense for a map to have > 256 areaportals anyway. */
- Com_WPrintf( "%s: too many areaportals\n", __func__ );
+ Com_WPrintf("%s: too many areaportals\n", __func__);
numportals = MAX_MAP_AREAS;
}
- bytes = ( numportals + 7 ) >> 3;
- memset( buffer, 0, bytes );
- for( i = 0; i < numportals; i++ ) {
- if( cm->portalopen[i] ) {
- Q_SetBit( buffer, i );
+ bytes = (numportals + 7) >> 3;
+ memset(buffer, 0, bytes);
+ for (i = 0; i < numportals; i++) {
+ if (cm->portalopen[i]) {
+ Q_SetBit(buffer, i);
}
}
return bytes;
}
-void CM_SetPortalStates( cm_t *cm, byte *buffer, int bytes ) {
+void CM_SetPortalStates(cm_t *cm, byte *buffer, int bytes)
+{
int i, numportals;
- if( !cm->cache ) {
+ if (!cm->cache) {
return;
}
- if( !bytes ) {
- for( i = 0; i <= cm->cache->lastareaportal; i++ ) {
+ if (!bytes) {
+ for (i = 0; i <= cm->cache->lastareaportal; i++) {
cm->portalopen[i] = qtrue;
}
} else {
numportals = bytes << 3;
- if( numportals > cm->cache->lastareaportal + 1 ) {
+ if (numportals > cm->cache->lastareaportal + 1) {
numportals = cm->cache->lastareaportal + 1;
}
- for( i = 0; i < numportals; i++ ) {
- cm->portalopen[i] = Q_IsBitSet( buffer, i );
+ for (i = 0; i < numportals; i++) {
+ cm->portalopen[i] = Q_IsBitSet(buffer, i);
}
}
- FloodAreaConnections( cm );
+ FloodAreaConnections(cm);
}
@@ -1055,21 +1041,22 @@ Returns qtrue if any leaf under headnode has a cluster that
is potentially visible
=============
*/
-qboolean CM_HeadnodeVisible( mnode_t *node, byte *visbits ) {
+qboolean CM_HeadnodeVisible(mnode_t *node, byte *visbits)
+{
mleaf_t *leaf;
int cluster;
- while( node->plane ) {
- if( CM_HeadnodeVisible( node->children[0], visbits ) )
+ while (node->plane) {
+ if (CM_HeadnodeVisible(node->children[0], visbits))
return qtrue;
node = node->children[1];
}
- leaf = ( mleaf_t * )node;
+ leaf = (mleaf_t *)node;
cluster = leaf->cluster;
- if( cluster == -1 )
+ if (cluster == -1)
return qfalse;
- if( Q_IsBitSet( visbits, cluster ) )
+ if (Q_IsBitSet(visbits, cluster))
return qtrue;
return qfalse;
}
@@ -1083,7 +1070,8 @@ The client will interpolate the view position,
so we can't use a single PVS point
===========
*/
-byte *CM_FatPVS( cm_t *cm, byte *mask, const vec3_t org ) {
+byte *CM_FatPVS(cm_t *cm, byte *mask, const vec3_t org)
+{
byte temp[VIS_MAX_BYTES];
mleaf_t *leafs[64];
int clusters[64];
@@ -1091,40 +1079,40 @@ byte *CM_FatPVS( cm_t *cm, byte *mask, const vec3_t org ) {
uint_fast32_t *src, *dst;
vec3_t mins, maxs;
- if( !cm->cache ) { // map not loaded
- return memset( mask, 0, VIS_MAX_BYTES );
+ if (!cm->cache) { // map not loaded
+ return memset(mask, 0, VIS_MAX_BYTES);
}
- if( !cm->cache->vis ) {
- return memset( mask, 0xff, VIS_MAX_BYTES );
+ if (!cm->cache->vis) {
+ return memset(mask, 0xff, VIS_MAX_BYTES);
}
- for( i = 0; i < 3; i++ ) {
+ for (i = 0; i < 3; i++) {
mins[i] = org[i] - 8;
maxs[i] = org[i] + 8;
}
- count = CM_BoxLeafs( cm, mins, maxs, leafs, 64, NULL );
- if( count < 1 )
- Com_Error( ERR_DROP, "CM_FatPVS: leaf count < 1" );
- longs = VIS_FAST_LONGS( cm->cache );
+ count = CM_BoxLeafs(cm, mins, maxs, leafs, 64, NULL);
+ if (count < 1)
+ Com_Error(ERR_DROP, "CM_FatPVS: leaf count < 1");
+ longs = VIS_FAST_LONGS(cm->cache);
// convert leafs to clusters
- for( i = 0 ; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
clusters[i] = leafs[i]->cluster;
}
- BSP_ClusterVis( cm->cache, mask, clusters[0], DVIS_PVS );
+ BSP_ClusterVis(cm->cache, mask, clusters[0], DVIS_PVS);
// or in all the other leaf bits
- for( i = 1; i < count; i++ ) {
- for( j = 0; j < i; j++ ) {
- if( clusters[i] == clusters[j] ) {
+ for (i = 1; i < count; i++) {
+ for (j = 0; j < i; j++) {
+ if (clusters[i] == clusters[j]) {
goto nextleaf; // already have the cluster we want
}
}
- src = ( uint_fast32_t * )BSP_ClusterVis( cm->cache, temp, clusters[i], DVIS_PVS );
- dst = ( uint_fast32_t * )mask;
- for( j = 0; j < longs; j++ ) {
+ src = (uint_fast32_t *)BSP_ClusterVis(cm->cache, temp, clusters[i], DVIS_PVS);
+ dst = (uint_fast32_t *)mask;
+ for (j = 0; j < longs; j++) {
*dst++ |= *src++;
}
@@ -1139,12 +1127,13 @@ nextleaf:;
CM_Init
=============
*/
-void CM_Init( void ) {
+void CM_Init(void)
+{
CM_InitBoxHull();
nullleaf.cluster = -1;
- map_noareas = Cvar_Get( "map_noareas", "0", 0 );
- map_allsolid_bug = Cvar_Get( "map_allsolid_bug", "1", 0 );
+ map_noareas = Cvar_Get("map_noareas", "0", 0);
+ map_allsolid_bug = Cvar_Get("map_allsolid_bug", "1", 0);
}
diff --git a/src/cmodel.h b/src/cmodel.h
index 49621fe..ad837e4 100644
--- a/src/cmodel.h
+++ b/src/cmodel.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// bitmasks communicated by server
-#define MAX_MAP_AREA_BYTES ( MAX_MAP_AREAS / 8 )
+#define MAX_MAP_AREA_BYTES (MAX_MAP_AREAS / 8)
#define MAX_MAP_PORTAL_BYTES MAX_MAP_AREA_BYTES
typedef struct {
@@ -33,58 +33,59 @@ typedef struct {
qboolean *portalopen;
} cm_t;
-void CM_Init( void );
+void CM_Init(void);
-void CM_FreeMap( cm_t *cm );
-qerror_t CM_LoadMap( cm_t *cm, const char *name );
+void CM_FreeMap(cm_t *cm);
+qerror_t CM_LoadMap(cm_t *cm, const char *name);
-int CM_NumClusters( cm_t *cm );
-int CM_NumInlineModels( cm_t *cm );
-char *CM_EntityString( cm_t *cm );
-mnode_t *CM_NodeNum( cm_t *cm, int number );
-mleaf_t *CM_LeafNum( cm_t *cm, int number );
-#define CM_InlineModel( cm, name ) BSP_InlineModel( (cm)->cache, name )
+int CM_NumClusters(cm_t *cm);
+int CM_NumInlineModels(cm_t *cm);
+char *CM_EntityString(cm_t *cm);
+mnode_t *CM_NodeNum(cm_t *cm, int number);
+mleaf_t *CM_LeafNum(cm_t *cm, int number);
-#define CM_NumNode( cm, node ) ( (node) ? ( (node) - (cm)->cache->nodes ) : -1 )
+#define CM_InlineModel(cm, name) BSP_InlineModel((cm)->cache, name)
+
+#define CM_NumNode(cm, node) ((node) ? ((node) - (cm)->cache->nodes) : -1)
// creates a clipping hull for an arbitrary box
-mnode_t *CM_HeadnodeForBox( vec3_t mins, vec3_t maxs );
+mnode_t *CM_HeadnodeForBox(vec3_t mins, vec3_t maxs);
// returns an ORed contents mask
-int CM_PointContents( vec3_t p, mnode_t *headnode );
-int CM_TransformedPointContents( vec3_t p, mnode_t *headnode,
- vec3_t origin, vec3_t angles );
-
-void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
- vec3_t mins, vec3_t maxs,
- mnode_t *headnode, int brushmask );
-void CM_TransformedBoxTrace( trace_t *trace, vec3_t start, vec3_t end,
- vec3_t mins, vec3_t maxs,
- mnode_t * headnode, int brushmask,
- vec3_t origin, vec3_t angles );
-void CM_ClipEntity( trace_t *dst, const trace_t *src, struct edict_s *ent );
+int CM_PointContents(vec3_t p, mnode_t *headnode);
+int CM_TransformedPointContents(vec3_t p, mnode_t *headnode,
+ vec3_t origin, vec3_t angles);
+
+void CM_BoxTrace(trace_t *trace, vec3_t start, vec3_t end,
+ vec3_t mins, vec3_t maxs,
+ mnode_t *headnode, int brushmask);
+void CM_TransformedBoxTrace(trace_t *trace, vec3_t start, vec3_t end,
+ vec3_t mins, vec3_t maxs,
+ mnode_t * headnode, int brushmask,
+ vec3_t origin, vec3_t angles);
+void CM_ClipEntity(trace_t *dst, const trace_t *src, struct edict_s *ent);
// call with topnode set to the headnode, returns with topnode
// set to the first node that splits the box
-int CM_BoxLeafs( cm_t *cm, vec3_t mins, vec3_t maxs, mleaf_t **list,
- int listsize, mnode_t **topnode );
-mleaf_t *CM_PointLeaf( cm_t *cm, vec3_t p );
+int CM_BoxLeafs(cm_t *cm, vec3_t mins, vec3_t maxs, mleaf_t **list,
+ int listsize, mnode_t **topnode);
+mleaf_t *CM_PointLeaf(cm_t *cm, vec3_t p);
-#define CM_LeafContents( leaf ) (leaf)->contents
-#define CM_LeafCluster( leaf ) (leaf)->cluster
-#define CM_LeafArea( leaf ) (leaf)->area
+#define CM_LeafContents(leaf) (leaf)->contents
+#define CM_LeafCluster(leaf) (leaf)->cluster
+#define CM_LeafArea(leaf) (leaf)->area
-byte *CM_FatPVS( cm_t *cm, byte *mask, const vec3_t org );
+byte *CM_FatPVS(cm_t *cm, byte *mask, const vec3_t org);
-void CM_SetAreaPortalState ( cm_t *cm, int portalnum, qboolean open );
-qboolean CM_AreasConnected( cm_t *cm, int area1, int area2 );
+void CM_SetAreaPortalState(cm_t *cm, int portalnum, qboolean open);
+qboolean CM_AreasConnected(cm_t *cm, int area1, int area2);
-int CM_WriteAreaBits( cm_t *cm, byte *buffer, int area );
-int CM_WritePortalBits( cm_t *cm, byte *buffer );
-void CM_SetPortalStates( cm_t *cm, byte *buffer, int bytes );
-qboolean CM_HeadnodeVisible( mnode_t *headnode, byte *visbits );
+int CM_WriteAreaBits(cm_t *cm, byte *buffer, int area);
+int CM_WritePortalBits(cm_t *cm, byte *buffer);
+void CM_SetPortalStates(cm_t *cm, byte *buffer, int bytes);
+qboolean CM_HeadnodeVisible(mnode_t *headnode, byte *visbits);
-void CM_WritePortalState( cm_t *cm, qhandle_t f );
-void CM_ReadPortalState( cm_t *cm, qhandle_t f );
+void CM_WritePortalState(cm_t *cm, qhandle_t f);
+void CM_ReadPortalState(cm_t *cm, qhandle_t f);
diff --git a/src/common.c b/src/common.c
index 371accb..dd64000 100644
--- a/src/common.c
+++ b/src/common.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -124,8 +124,9 @@ static size_t rd_buffersize;
static size_t rd_length;
static rdflush_t rd_flush;
-void Com_BeginRedirect( int target, char *buffer, size_t buffersize, rdflush_t flush ) {
- if( rd_target || !target || !buffer || buffersize < 1 || !flush ) {
+void Com_BeginRedirect(int target, char *buffer, size_t buffersize, rdflush_t flush)
+{
+ if (rd_target || !target || !buffer || buffersize < 1 || !flush) {
return;
}
rd_target = target;
@@ -135,7 +136,8 @@ void Com_BeginRedirect( int target, char *buffer, size_t buffersize, rdflush_t f
rd_length = 0;
}
-static void Com_AbortRedirect( void ) {
+static void Com_AbortRedirect(void)
+{
rd_target = 0;
rd_buffer = NULL;
rd_buffersize = 0;
@@ -143,11 +145,12 @@ static void Com_AbortRedirect( void ) {
rd_length = 0;
}
-void Com_EndRedirect( void ) {
- if( !rd_target ) {
+void Com_EndRedirect(void)
+{
+ if (!rd_target) {
return;
}
- rd_flush( rd_target, rd_buffer, rd_length );
+ rd_flush(rd_target, rd_buffer, rd_length);
rd_target = 0;
rd_buffer = NULL;
rd_buffersize = 0;
@@ -155,104 +158,111 @@ void Com_EndRedirect( void ) {
rd_length = 0;
}
-static void Com_Redirect( const char *msg, size_t total ) {
+static void Com_Redirect(const char *msg, size_t total)
+{
size_t length;
- while( total ) {
+ while (total) {
length = total;
- if( length > rd_buffersize ) {
+ if (length > rd_buffersize) {
length = rd_buffersize;
}
- if( rd_length + length > rd_buffersize ) {
- rd_flush( rd_target, rd_buffer, rd_length );
+ if (rd_length + length > rd_buffersize) {
+ rd_flush(rd_target, rd_buffer, rd_length);
rd_length = 0;
}
- memcpy( rd_buffer + rd_length, msg, length );
+ memcpy(rd_buffer + rd_length, msg, length);
rd_length += length;
total -= length;
}
}
-static void logfile_close( void ) {
- if( !com_logFile ) {
+static void logfile_close(void)
+{
+ if (!com_logFile) {
return;
}
- Com_Printf( "Closing console log.\n" );
+ Com_Printf("Closing console log.\n");
- FS_FCloseFile( com_logFile );
+ FS_FCloseFile(com_logFile);
com_logFile = 0;
}
-static void logfile_open( void ) {
+static void logfile_open(void)
+{
char buffer[MAX_OSPATH];
unsigned mode;
qhandle_t f;
mode = logfile_enable->integer > 1 ? FS_MODE_APPEND : FS_MODE_WRITE;
- if( logfile_flush->integer > 0 ) {
- if( logfile_flush->integer > 1 ) {
+ if (logfile_flush->integer > 0) {
+ if (logfile_flush->integer > 1) {
mode |= FS_BUF_NONE;
} else {
mode |= FS_BUF_LINE;
}
}
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode | FS_FLAG_TEXT,
- "logs/", logfile_name->string, ".log" );
- if( !f ) {
- Cvar_Set( "logfile", "0" );
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode | FS_FLAG_TEXT,
+ "logs/", logfile_name->string, ".log");
+ if (!f) {
+ Cvar_Set("logfile", "0");
return;
}
com_logFile = f;
com_logNewline = qtrue;
- Com_Printf( "Logging console to %s\n", buffer );
+ Com_Printf("Logging console to %s\n", buffer);
}
-static void logfile_enable_changed( cvar_t *self ) {
+static void logfile_enable_changed(cvar_t *self)
+{
logfile_close();
- if( self->integer ) {
+ if (self->integer) {
logfile_open();
- }
+ }
}
-static void logfile_param_changed( cvar_t *self ) {
- if( logfile_enable->integer ) {
+static void logfile_param_changed(cvar_t *self)
+{
+ if (logfile_enable->integer) {
logfile_close();
logfile_open();
- }
+ }
}
-static size_t format_local_time( char *buffer, size_t size, const char *fmt ) {
+static size_t format_local_time(char *buffer, size_t size, const char *fmt)
+{
static struct tm cached_tm;
static time_t cached_time;
time_t now;
struct tm *tm;
- if( !size ) {
+ if (!size) {
return 0;
}
buffer[0] = 0;
- now = time( NULL );
- if( now == cached_time ) {
+ now = time(NULL);
+ if (now == cached_time) {
// avoid calling localtime() too often since it is not that cheap
tm = &cached_tm;
} else {
- tm = localtime( &now );
- if( !tm ) {
+ tm = localtime(&now);
+ if (!tm) {
return 0;
}
cached_time = now;
cached_tm = *tm;
}
- return strftime( buffer, size, fmt, tm );
+ return strftime(buffer, size, fmt, tm);
}
-static void logfile_write( print_type_t type, const char *s ) {
+static void logfile_write(print_type_t type, const char *s)
+{
char text[MAXPRINTMSG];
char buf[MAX_QPATH];
char *p, *maxp;
@@ -260,21 +270,21 @@ static void logfile_write( print_type_t type, const char *s ) {
ssize_t ret;
int c;
- if( logfile_prefix->string[0] ) {
- p = strchr( logfile_prefix->string, '@' );
- if( p ) {
+ if (logfile_prefix->string[0]) {
+ p = strchr(logfile_prefix->string, '@');
+ if (p) {
// expand it in place, hacky
- switch( type ) {
- case PRINT_TALK: *p = 'T'; break;
- case PRINT_DEVELOPER: *p = 'D'; break;
- case PRINT_WARNING: *p = 'W'; break;
- case PRINT_ERROR: *p = 'E'; break;
- case PRINT_NOTICE: *p = 'N'; break;
- default: *p = 'A'; break;
+ switch (type) {
+ case PRINT_TALK: *p = 'T'; break;
+ case PRINT_DEVELOPER: *p = 'D'; break;
+ case PRINT_WARNING: *p = 'W'; break;
+ case PRINT_ERROR: *p = 'E'; break;
+ case PRINT_NOTICE: *p = 'N'; break;
+ default: *p = 'A'; break;
}
}
- len = format_local_time( buf, sizeof( buf ), logfile_prefix->string );
- if( p ) {
+ len = format_local_time(buf, sizeof(buf), logfile_prefix->string);
+ if (p) {
*p = '@';
}
} else {
@@ -282,40 +292,40 @@ static void logfile_write( print_type_t type, const char *s ) {
}
p = text;
- maxp = text + sizeof( text ) - 1;
- while( *s ) {
- if( com_logNewline ) {
- if( len > 0 && p + len < maxp ) {
- memcpy( p, buf, len );
+ maxp = text + sizeof(text) - 1;
+ while (*s) {
+ if (com_logNewline) {
+ if (len > 0 && p + len < maxp) {
+ memcpy(p, buf, len);
p += len;
}
com_logNewline = qfalse;
}
- if( p == maxp ) {
+ if (p == maxp) {
break;
}
c = *s++;
- if( c == '\n' ) {
+ if (c == '\n') {
com_logNewline = qtrue;
} else {
- c = Q_charascii( c );
+ c = Q_charascii(c);
}
-
+
*p++ = c;
}
*p = 0;
len = p - text;
- ret = FS_Write( text, len, com_logFile );
- if( ret != len ) {
+ ret = FS_Write(text, len, com_logFile);
+ if (ret != len) {
// zero handle BEFORE doing anything else to avoid recursion
qhandle_t tmp = com_logFile;
com_logFile = 0;
- FS_FCloseFile( tmp );
- Com_EPrintf( "Couldn't write console log: %s\n", Q_ErrorString( ret ) );
- Cvar_Set( "logfile", "0" );
+ FS_FCloseFile(tmp);
+ Com_EPrintf("Couldn't write console log: %s\n", Q_ErrorString(ret));
+ Cvar_Set("logfile", "0");
}
}
@@ -328,36 +338,40 @@ When called from SIGHUP handler on UNIX-like systems,
will close and reopen logfile handle for rotation.
=============
*/
-void Com_FlushLogs( void ) {
- if( logfile_enable ) {
- logfile_enable_changed( logfile_enable );
+void Com_FlushLogs(void)
+{
+ if (logfile_enable) {
+ logfile_enable_changed(logfile_enable);
}
}
#endif
-void Com_SetColor( color_index_t color ) {
- if( rd_target ) {
+void Com_SetColor(color_index_t color)
+{
+ if (rd_target) {
return;
}
#if USE_CLIENT
// graphical console
- Con_SetColor( color );
+ Con_SetColor(color);
#endif
#if USE_SYSCON
// debugging console
- Sys_SetConsoleColor( color );
+ Sys_SetConsoleColor(color);
#endif
}
-void Com_SetLastError( const char *msg ) {
- if( msg ) {
- Q_strlcpy( com_errorMsg, msg, sizeof( com_errorMsg ) );
+void Com_SetLastError(const char *msg)
+{
+ if (msg) {
+ Q_strlcpy(com_errorMsg, msg, sizeof(com_errorMsg));
} else {
- strcpy( com_errorMsg, "No error" );
+ strcpy(com_errorMsg, "No error");
}
}
-char *Com_GetLastError( void ) {
+char *Com_GetLastError(void)
+{
return com_errorMsg;
}
@@ -369,57 +383,58 @@ Both client and server can use this, and it will output
to the apropriate place.
=============
*/
-void Com_LPrintf( print_type_t type, const char *fmt, ... ) {
+void Com_LPrintf(print_type_t type, const char *fmt, ...)
+{
va_list argptr;
char msg[MAXPRINTMSG];
size_t len;
// may be entered recursively only once
- if( com_printEntered >= 2 ) {
+ if (com_printEntered >= 2) {
return;
}
com_printEntered++;
- va_start( argptr, fmt );
- len = Q_vscnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- if( type == PRINT_ERROR && !com_errorEntered && len ) {
+ if (type == PRINT_ERROR && !com_errorEntered && len) {
size_t errlen = len;
- if( errlen >= sizeof( com_errorMsg ) ) {
- errlen = sizeof( com_errorMsg ) - 1;
+ if (errlen >= sizeof(com_errorMsg)) {
+ errlen = sizeof(com_errorMsg) - 1;
}
// save error msg
- memcpy( com_errorMsg, msg, errlen );
+ memcpy(com_errorMsg, msg, errlen);
com_errorMsg[errlen] = 0;
// strip trailing '\n'
- if( com_errorMsg[errlen - 1] == '\n' ) {
+ if (com_errorMsg[errlen - 1] == '\n') {
com_errorMsg[errlen - 1] = 0;
}
}
- if( rd_target ) {
- Com_Redirect( msg, len );
+ if (rd_target) {
+ Com_Redirect(msg, len);
} else {
- switch( type ) {
+ switch (type) {
case PRINT_TALK:
- Com_SetColor( COLOR_ALT );
+ Com_SetColor(COLOR_ALT);
break;
case PRINT_DEVELOPER:
- Com_SetColor( COLOR_BLUE );
+ Com_SetColor(COLOR_BLUE);
break;
case PRINT_WARNING:
- Com_SetColor( COLOR_YELLOW );
+ Com_SetColor(COLOR_YELLOW);
break;
case PRINT_ERROR:
- Com_SetColor( COLOR_RED );
+ Com_SetColor(COLOR_RED);
break;
case PRINT_NOTICE:
- Com_SetColor( COLOR_CYAN );
+ Com_SetColor(COLOR_CYAN);
break;
default:
break;
@@ -427,24 +442,24 @@ void Com_LPrintf( print_type_t type, const char *fmt, ... ) {
#if USE_CLIENT
// graphical console
- Con_Print( msg );
+ Con_Print(msg);
#endif
#if USE_SYSCON
// debugging console
- Sys_ConsoleOutput( msg );
+ Sys_ConsoleOutput(msg);
#endif
// remote console
- //SV_ConsoleOutput( msg );
+ //SV_ConsoleOutput(msg);
// logfile
- if( com_logFile ) {
- logfile_write( type, msg );
+ if (com_logFile) {
+ logfile_write(type, msg);
}
- if( type ) {
- Com_SetColor( COLOR_NONE );
+ if (type) {
+ Com_SetColor(COLOR_NONE);
}
}
@@ -460,31 +475,32 @@ Both client and server can use this, and it will
do the apropriate things.
=============
*/
-void Com_Error( error_type_t code, const char *fmt, ... ) {
+void Com_Error(error_type_t code, const char *fmt, ...)
+{
char msg[MAXERRORMSG];
va_list argptr;
size_t len;
// may not be entered recursively
- if( com_errorEntered ) {
+ if (com_errorEntered) {
#ifdef _DEBUG
- if( com_debug_break && com_debug_break->integer ) {
+ if (com_debug_break && com_debug_break->integer) {
Sys_DebugBreak();
}
#endif
- Sys_Error( "recursive error after: %s", com_errorMsg );
+ Sys_Error("recursive error after: %s", com_errorMsg);
}
com_errorEntered = qtrue;
- va_start( argptr, fmt );
- len = Q_vscnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
// save error msg
// can't print into it directly since it may
// overlap with one of the arguments!
- memcpy( com_errorMsg, msg, len + 1 );
+ memcpy(com_errorMsg, msg, len + 1);
// fix up drity message buffers
MSG_Init();
@@ -497,61 +513,62 @@ void Com_Error( error_type_t code, const char *fmt, ... ) {
X86_POP_FPCW;
- if( code == ERR_DISCONNECT || code == ERR_RECONNECT ) {
- Com_WPrintf( "%s\n", com_errorMsg );
- SV_Shutdown( va( "Server was killed: %s\n", com_errorMsg ), code );
+ if (code == ERR_DISCONNECT || code == ERR_RECONNECT) {
+ Com_WPrintf("%s\n", com_errorMsg);
+ SV_Shutdown(va("Server was killed: %s\n", com_errorMsg), code);
#if USE_CLIENT
- CL_Disconnect( code );
+ CL_Disconnect(code);
#endif
goto abort;
}
#ifdef _DEBUG
- if( com_debug_break && com_debug_break->integer ) {
+ if (com_debug_break && com_debug_break->integer) {
Sys_DebugBreak();
}
#endif
// make otherwise non-fatal errors fatal
- if( com_fatal_error && com_fatal_error->integer ) {
+ if (com_fatal_error && com_fatal_error->integer) {
code = ERR_FATAL;
}
- if( code == ERR_DROP ) {
- Com_EPrintf( "********************\n"
- "ERROR: %s\n"
- "********************\n", com_errorMsg );
- SV_Shutdown( va( "Server crashed: %s\n", com_errorMsg ), ERR_DROP );
+ if (code == ERR_DROP) {
+ Com_EPrintf("********************\n"
+ "ERROR: %s\n"
+ "********************\n", com_errorMsg);
+ SV_Shutdown(va("Server crashed: %s\n", com_errorMsg), ERR_DROP);
#if USE_CLIENT
- CL_Disconnect( ERR_DROP );
+ CL_Disconnect(ERR_DROP);
#endif
goto abort;
}
- if( com_logFile ) {
- FS_FPrintf( com_logFile, "FATAL: %s\n", com_errorMsg );
+ if (com_logFile) {
+ FS_FPrintf(com_logFile, "FATAL: %s\n", com_errorMsg);
}
- SV_Shutdown( va( "Server fatal crashed: %s\n", com_errorMsg ), ERR_FATAL );
+ SV_Shutdown(va("Server fatal crashed: %s\n", com_errorMsg), ERR_FATAL);
#if USE_CLIENT
CL_Shutdown();
#endif
Qcommon_Shutdown();
- Sys_Error( "%s", com_errorMsg );
+ Sys_Error("%s", com_errorMsg);
// doesn't get there
abort:
- if( com_logFile ) {
- FS_Flush( com_logFile );
+ if (com_logFile) {
+ FS_Flush(com_logFile);
}
com_errorEntered = qfalse;
- longjmp( abortframe, -1 );
+ longjmp(abortframe, -1);
}
#ifdef _WIN32
-void Com_AbortFrame( void ) {
- longjmp( abortframe, -1 );
+void Com_AbortFrame(void)
+{
+ longjmp(abortframe, -1);
}
#endif
@@ -563,19 +580,20 @@ Both client and server can use this, and it will
do the apropriate things. This function never returns.
=============
*/
-void Com_Quit( const char *reason, error_type_t type ) {
+void Com_Quit(const char *reason, error_type_t type)
+{
char buffer[MAX_STRING_CHARS];
char *what = type == ERR_RECONNECT ? "restarted" : "quit";
- if( reason && *reason ) {
- Q_snprintf( buffer, sizeof( buffer ),
- "Server %s: %s\n", what, reason );
+ if (reason && *reason) {
+ Q_snprintf(buffer, sizeof(buffer),
+ "Server %s: %s\n", what, reason);
} else {
- Q_snprintf( buffer, sizeof( buffer ),
- "Server %s\n", what );
+ Q_snprintf(buffer, sizeof(buffer),
+ "Server %s\n", what);
}
- SV_Shutdown( buffer, type );
+ SV_Shutdown(buffer, type);
#if USE_CLIENT
CL_Shutdown();
@@ -585,13 +603,15 @@ void Com_Quit( const char *reason, error_type_t type ) {
Sys_Quit();
}
-static void Com_Quit_f( void ) {
- Com_Quit( Cmd_Args(), ERR_DISCONNECT );
+static void Com_Quit_f(void)
+{
+ Com_Quit(Cmd_Args(), ERR_DISCONNECT);
}
#if !USE_CLIENT
-static void Com_Recycle_f( void ) {
- Com_Quit( Cmd_Args(), ERR_RECONNECT );
+static void Com_Recycle_f(void)
+{
+ Com_Quit(Cmd_Args(), ERR_RECONNECT);
}
#endif
@@ -609,14 +629,14 @@ just cleared malloc with counters now...
#define Z_MAGIC 0x1d0d
#define Z_TAIL 0x5b7b
-#define Z_TAIL_F( z ) \
- *( uint16_t * )( ( byte * )(z) + (z)->size - sizeof( uint16_t ) )
+#define Z_TAIL_F(z) \
+ *(uint16_t *)((byte *)(z) + (z)->size - sizeof(uint16_t))
-#define Z_FOR_EACH( z ) \
- for( (z) = z_chain.next; (z) != &z_chain; (z) = (z)->next )
+#define Z_FOR_EACH(z) \
+ for ((z) = z_chain.next; (z) != &z_chain; (z) = (z)->next)
-#define Z_FOR_EACH_SAFE( z, n ) \
- for( (z) = z_chain.next; (z) != &z_chain; (z) = (n) )
+#define Z_FOR_EACH_SAFE(z, n) \
+ for ((z) = z_chain.next; (z) != &z_chain; (z) = (n))
typedef struct zhead_s {
uint16_t magic;
@@ -629,7 +649,7 @@ typedef struct zhead_s {
} zhead_t;
// number of overhead bytes
-#define Z_EXTRA ( sizeof( zhead_t ) + sizeof( uint16_t ) )
+#define Z_EXTRA (sizeof(zhead_t) + sizeof(uint16_t))
static zhead_t z_chain;
@@ -642,21 +662,20 @@ typedef struct {
} zstatic_t;
static const zstatic_t z_static[] = {
-#define Z_STATIC( x ) \
- { { Z_MAGIC, TAG_STATIC, q_offsetof( zstatic_t, tail ) + \
- sizeof( uint16_t ) }, x, Z_TAIL }
-
- Z_STATIC( "0" ),
- Z_STATIC( "1" ),
- Z_STATIC( "2" ),
- Z_STATIC( "3" ),
- Z_STATIC( "4" ),
- Z_STATIC( "5" ),
- Z_STATIC( "6" ),
- Z_STATIC( "7" ),
- Z_STATIC( "8" ),
- Z_STATIC( "9" ),
- Z_STATIC( "" )
+#define Z_STATIC(x) \
+ { { Z_MAGIC, TAG_STATIC, q_offsetof(zstatic_t, tail) + sizeof(uint16_t) }, x, Z_TAIL }
+
+ Z_STATIC("0"),
+ Z_STATIC("1"),
+ Z_STATIC("2"),
+ Z_STATIC("3"),
+ Z_STATIC("4"),
+ Z_STATIC("5"),
+ Z_STATIC("6"),
+ Z_STATIC("7"),
+ Z_STATIC("8"),
+ Z_STATIC("9"),
+ Z_STATIC("")
#undef Z_STATIC
};
@@ -683,44 +702,47 @@ static const char z_tagnames[TAG_MAX][8] = {
"cmodel"
};
-static inline void Z_Validate( zhead_t *z, const char *func ) {
- if( z->magic != Z_MAGIC ) {
- Com_Error( ERR_FATAL, "%s: bad magic", func );
+static inline void Z_Validate(zhead_t *z, const char *func)
+{
+ if (z->magic != Z_MAGIC) {
+ Com_Error(ERR_FATAL, "%s: bad magic", func);
}
- if( Z_TAIL_F( z ) != Z_TAIL ) {
- Com_Error( ERR_FATAL, "%s: bad tail", func );
+ if (Z_TAIL_F(z) != Z_TAIL) {
+ Com_Error(ERR_FATAL, "%s: bad tail", func);
}
- if( z->tag == TAG_FREE ) {
- Com_Error( ERR_FATAL, "%s: bad tag", func );
+ if (z->tag == TAG_FREE) {
+ Com_Error(ERR_FATAL, "%s: bad tag", func);
}
}
-void Z_Check( void ) {
+void Z_Check(void)
+{
zhead_t *z;
- Z_FOR_EACH( z ) {
- Z_Validate( z, __func__ );
+ Z_FOR_EACH(z) {
+ Z_Validate(z, __func__);
}
}
-void Z_LeakTest( memtag_t tag ) {
+void Z_LeakTest(memtag_t tag)
+{
zhead_t *z;
size_t numLeaks = 0, numBytes = 0;
-
- Z_FOR_EACH( z ) {
- Z_Validate( z, __func__ );
- if( z->tag == tag ) {
+
+ Z_FOR_EACH(z) {
+ Z_Validate(z, __func__);
+ if (z->tag == tag) {
numLeaks++;
numBytes += z->size;
}
}
- if( numLeaks ) {
- Com_WPrintf( "************* Z_LeakTest *************\n"
- "%s leaked %"PRIz" bytes of memory (%"PRIz" object%s)\n"
- "**************************************\n",
- z_tagnames[tag < TAG_MAX ? tag : TAG_FREE],
- numBytes, numLeaks, numLeaks == 1 ? "" : "s" );
+ if (numLeaks) {
+ Com_WPrintf("************* Z_LeakTest *************\n"
+ "%s leaked %"PRIz" bytes of memory (%"PRIz" object%s)\n"
+ "**************************************\n",
+ z_tagnames[tag < TAG_MAX ? tag : TAG_FREE],
+ numBytes, numLeaks, numLeaks == 1 ? "" : "s");
}
}
@@ -729,28 +751,29 @@ void Z_LeakTest( memtag_t tag ) {
Z_Free
========================
*/
-void Z_Free( void *ptr ) {
+void Z_Free(void *ptr)
+{
zhead_t *z;
zstats_t *s;
- if( !ptr ) {
+ if (!ptr) {
return;
}
- z = ( zhead_t * )ptr - 1;
+ z = (zhead_t *)ptr - 1;
- Z_Validate( z, __func__ );
+ Z_Validate(z, __func__);
s = &z_stats[z->tag < TAG_MAX ? z->tag : TAG_FREE];
s->count--;
s->bytes -= z->size;
-
- if( z->tag != TAG_STATIC ) {
+
+ if (z->tag != TAG_STATIC) {
z->prev->next = z->next;
z->next->prev = z->prev;
z->magic = 0xdead;
z->tag = TAG_FREE;
- free( z );
+ free(z);
}
}
@@ -760,38 +783,39 @@ void Z_Free( void *ptr ) {
Z_Realloc
========================
*/
-void *Z_Realloc( void *ptr, size_t size ) {
+void *Z_Realloc(void *ptr, size_t size)
+{
zhead_t *z;
zstats_t *s;
- if( !ptr ) {
- return Z_Malloc( size );
+ if (!ptr) {
+ return Z_Malloc(size);
}
- if( !size ) {
- Z_Free( ptr );
+ if (!size) {
+ Z_Free(ptr);
return NULL;
}
- z = ( zhead_t * )ptr - 1;
+ z = (zhead_t *)ptr - 1;
- Z_Validate( z, __func__ );
+ Z_Validate(z, __func__);
- if( z->tag == TAG_STATIC ) {
- Com_Error( ERR_FATAL, "%s: couldn't realloc static memory", __func__ );
+ if (z->tag == TAG_STATIC) {
+ Com_Error(ERR_FATAL, "%s: couldn't realloc static memory", __func__);
}
s = &z_stats[z->tag < TAG_MAX ? z->tag : TAG_FREE];
s->bytes -= z->size;
- if( size > SIZE_MAX - Z_EXTRA - 3 ) {
- Com_Error( ERR_FATAL, "%s: bad size", __func__ );
+ if (size > SIZE_MAX - Z_EXTRA - 3) {
+ Com_Error(ERR_FATAL, "%s: bad size", __func__);
}
- size = ( size + Z_EXTRA + 3 ) & ~3;
- z = realloc( z, size );
- if( !z ) {
- Com_Error( ERR_FATAL, "%s: couldn't realloc %"PRIz" bytes", __func__, size );
+ size = (size + Z_EXTRA + 3) & ~3;
+ z = realloc(z, size);
+ if (!z) {
+ Com_Error(ERR_FATAL, "%s: couldn't realloc %"PRIz" bytes", __func__, size);
}
z->size = size;
@@ -800,7 +824,7 @@ void *Z_Realloc( void *ptr, size_t size ) {
s->bytes += size;
- Z_TAIL_F( z ) = Z_TAIL;
+ Z_TAIL_F(z) = Z_TAIL;
return z + 1;
}
@@ -811,26 +835,27 @@ void *Z_Realloc( void *ptr, size_t size ) {
Z_Stats_f
========================
*/
-static void Z_Stats_f( void ) {
+static void Z_Stats_f(void)
+{
size_t bytes = 0, count = 0;
zstats_t *s;
int i;
- Com_Printf( " bytes blocks name\n"
- "--------- ------ -------\n" );
+ Com_Printf(" bytes blocks name\n"
+ "--------- ------ -------\n");
- for( i = 0, s = z_stats; i < TAG_MAX; i++, s++ ) {
- if( !s->count ) {
+ for (i = 0, s = z_stats; i < TAG_MAX; i++, s++) {
+ if (!s->count) {
continue;
}
- Com_Printf( "%9"PRIz" %6"PRIz" %s\n", s->bytes, s->count, z_tagnames[i] );
+ Com_Printf("%9"PRIz" %6"PRIz" %s\n", s->bytes, s->count, z_tagnames[i]);
bytes += s->bytes;
count += s->count;
}
- Com_Printf( "--------- ------ -------\n"
- "%9"PRIz" %6"PRIz" total\n",
- bytes, count );
+ Com_Printf("--------- ------ -------\n"
+ "%9"PRIz" %6"PRIz" total\n",
+ bytes, count);
}
/*
@@ -838,14 +863,15 @@ static void Z_Stats_f( void ) {
Z_FreeTags
========================
*/
-void Z_FreeTags( memtag_t tag ) {
+void Z_FreeTags(memtag_t tag)
+{
zhead_t *z, *n;
- Z_FOR_EACH_SAFE( z, n ) {
- Z_Validate( z, __func__ );
+ Z_FOR_EACH_SAFE(z, n) {
+ Z_Validate(z, __func__);
n = z->next;
- if( z->tag == tag ) {
- Z_Free( z + 1 );
+ if (z->tag == tag) {
+ Z_Free(z + 1);
}
}
}
@@ -855,35 +881,36 @@ void Z_FreeTags( memtag_t tag ) {
Z_TagMalloc
========================
*/
-void *Z_TagMalloc( size_t size, memtag_t tag ) {
+void *Z_TagMalloc(size_t size, memtag_t tag)
+{
zhead_t *z;
zstats_t *s;
- if( !size ) {
+ if (!size) {
return NULL;
}
- if( tag == TAG_FREE ) {
- Com_Error( ERR_FATAL, "%s: bad tag", __func__ );
+ if (tag == TAG_FREE) {
+ Com_Error(ERR_FATAL, "%s: bad tag", __func__);
}
-
- if( size > SIZE_MAX - Z_EXTRA - 3 ) {
- Com_Error( ERR_FATAL, "%s: bad size", __func__ );
+
+ if (size > SIZE_MAX - Z_EXTRA - 3) {
+ Com_Error(ERR_FATAL, "%s: bad size", __func__);
}
- size = ( size + Z_EXTRA + 3 ) & ~3;
- z = malloc( size );
- if( !z ) {
- Com_Error( ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size );
+ size = (size + Z_EXTRA + 3) & ~3;
+ z = malloc(size);
+ if (!z) {
+ Com_Error(ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size);
}
z->magic = Z_MAGIC;
z->tag = tag;
z->size = size;
#ifdef _DEBUG
-#if( defined __GNUC__ )
- z->addr = __builtin_return_address( 0 );
-#elif( defined _MSC_VER )
+#if (defined __GNUC__)
+ z->addr = __builtin_return_address(0);
+#elif (defined _MSC_VER)
z->addr = _ReturnAddress();
#else
z->addr = NULL;
@@ -895,12 +922,12 @@ void *Z_TagMalloc( size_t size, memtag_t tag ) {
z_chain.next->prev = z;
z_chain.next = z;
- if( z_perturb && z_perturb->integer ) {
- memset( z + 1, z_perturb->integer, size -
- sizeof( zhead_t ) - sizeof( uint16_t ) );
+ if (z_perturb && z_perturb->integer) {
+ memset(z + 1, z_perturb->integer, size -
+ sizeof(zhead_t) - sizeof(uint16_t));
}
- Z_TAIL_F( z ) = Z_TAIL;
+ Z_TAIL_F(z) = Z_TAIL;
s = &z_stats[tag < TAG_MAX ? tag : TAG_FREE];
s->count++;
@@ -909,32 +936,35 @@ void *Z_TagMalloc( size_t size, memtag_t tag ) {
return z + 1;
}
-void *Z_TagMallocz( size_t size, memtag_t tag ) {
- if( !size ) {
+void *Z_TagMallocz(size_t size, memtag_t tag)
+{
+ if (!size) {
return NULL;
}
- return memset( Z_TagMalloc( size, tag ), 0, size );
+ return memset(Z_TagMalloc(size, tag), 0, size);
}
static byte *z_reserved_data;
static size_t z_reserved_inuse;
static size_t z_reserved_total;
-void Z_TagReserve( size_t size, memtag_t tag ) {
- z_reserved_data = Z_TagMalloc( size, tag );
+void Z_TagReserve(size_t size, memtag_t tag)
+{
+ z_reserved_data = Z_TagMalloc(size, tag);
z_reserved_total = size;
z_reserved_inuse = 0;
}
-void *Z_ReservedAlloc( size_t size ) {
+void *Z_ReservedAlloc(size_t size)
+{
void *ptr;
- if( !size ) {
+ if (!size) {
return NULL;
}
- if( size > z_reserved_total - z_reserved_inuse ) {
- Com_Error( ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size );
+ if (size > z_reserved_total - z_reserved_inuse) {
+ Com_Error(ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size);
}
ptr = z_reserved_data + z_reserved_inuse;
@@ -943,22 +973,24 @@ void *Z_ReservedAlloc( size_t size ) {
return ptr;
}
-void *Z_ReservedAllocz( size_t size ) {
- if( !size ) {
+void *Z_ReservedAllocz(size_t size)
+{
+ if (!size) {
return NULL;
}
- return memset( Z_ReservedAlloc( size ), 0, size );
+ return memset(Z_ReservedAlloc(size), 0, size);
}
-char *Z_ReservedCopyString( const char *in ) {
+char *Z_ReservedCopyString(const char *in)
+{
size_t len;
- if( !in ) {
+ if (!in) {
return NULL;
}
- len = strlen( in ) + 1;
- return memcpy( Z_ReservedAlloc( len ), in, len );
+ len = strlen(in) + 1;
+ return memcpy(Z_ReservedAlloc(len), in, len);
}
/*
@@ -966,7 +998,8 @@ char *Z_ReservedCopyString( const char *in ) {
Z_Init
========================
*/
-static void Z_Init( void ) {
+static void Z_Init(void)
+{
z_chain.next = z_chain.prev = &z_chain;
}
@@ -975,15 +1008,16 @@ static void Z_Init( void ) {
Z_TagCopyString
================
*/
-char *Z_TagCopyString( const char *in, memtag_t tag ) {
+char *Z_TagCopyString(const char *in, memtag_t tag)
+{
size_t len;
- if( !in ) {
+ if (!in) {
return NULL;
}
- len = strlen( in ) + 1;
- return memcpy( Z_TagMalloc( len, tag ), in, len );
+ len = strlen(in) + 1;
+ return memcpy(Z_TagMalloc(len, tag), in, len);
}
/*
@@ -991,27 +1025,28 @@ char *Z_TagCopyString( const char *in, memtag_t tag ) {
Cvar_CopyString
================
*/
-char *Cvar_CopyString( const char *in ) {
+char *Cvar_CopyString(const char *in)
+{
size_t len;
zstatic_t *z;
zstats_t *s;
int i;
- if( !in ) {
+ if (!in) {
return NULL;
}
- if( !in[0] ) {
+ if (!in[0]) {
i = 10;
- } else if( !in[1] && Q_isdigit( in[0] ) ) {
+ } else if (!in[1] && Q_isdigit(in[0])) {
i = in[0] - '0';
} else {
- len = strlen( in ) + 1;
- return memcpy( Z_TagMalloc( len, TAG_CVAR ), in, len );
+ len = strlen(in) + 1;
+ return memcpy(Z_TagMalloc(len, TAG_CVAR), in, len);
}
// return static storage
- z = ( zstatic_t * )&z_static[i];
+ z = (zstatic_t *)&z_static[i];
s = &z_stats[TAG_STATIC];
s->count++;
s->bytes += z->z.size;
@@ -1026,24 +1061,25 @@ char *Cvar_CopyString( const char *in ) {
==============================================================================
*/
-size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len ) {
+size_t FIFO_Read(fifo_t *fifo, void *buffer, size_t len)
+{
size_t wrapped, head = fifo->ay - fifo->ax;
- if( head > len ) {
- if( buffer ) {
- memcpy( buffer, fifo->data + fifo->ax, len );
+ if (head > len) {
+ if (buffer) {
+ memcpy(buffer, fifo->data + fifo->ax, len);
fifo->ax += len;
}
return len;
}
wrapped = len - head;
- if( wrapped > fifo->bs ) {
+ if (wrapped > fifo->bs) {
wrapped = fifo->bs;
}
- if( buffer ) {
- memcpy( buffer, fifo->data + fifo->ax, head );
- memcpy( ( byte * )buffer + head, fifo->data, wrapped );
+ if (buffer) {
+ memcpy(buffer, fifo->data + fifo->ax, head);
+ memcpy((byte *)buffer + head, fifo->data, wrapped);
fifo->ax = wrapped;
fifo->ay = fifo->bs;
fifo->bs = 0;
@@ -1052,37 +1088,38 @@ size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len ) {
return head + wrapped;
}
-size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len ) {
+size_t FIFO_Write(fifo_t *fifo, const void *buffer, size_t len)
+{
size_t tail, wrapped, remaining;
- if( fifo->bs ) {
+ if (fifo->bs) {
remaining = fifo->ax - fifo->bs;
- if( len > remaining ) {
+ if (len > remaining) {
len = remaining;
}
- if( buffer ) {
- memcpy( fifo->data + fifo->bs, buffer, len );
+ if (buffer) {
+ memcpy(fifo->data + fifo->bs, buffer, len);
fifo->bs += len;
}
return len;
}
tail = fifo->size - fifo->ay;
- if( tail > len ) {
- if( buffer ) {
- memcpy( fifo->data + fifo->ay, buffer, len );
+ if (tail > len) {
+ if (buffer) {
+ memcpy(fifo->data + fifo->ay, buffer, len);
fifo->ay += len;
}
return len;
}
wrapped = len - tail;
- if( wrapped > fifo->ax ) {
+ if (wrapped > fifo->ax) {
wrapped = fifo->ax;
}
- if( buffer ) {
- memcpy( fifo->data + fifo->ay, buffer, tail );
- memcpy( fifo->data, ( byte * )buffer + tail, wrapped );
+ if (buffer) {
+ memcpy(fifo->data + fifo->ay, buffer, tail);
+ memcpy(fifo->data, (byte *)buffer + tail, wrapped);
fifo->ay = fifo->size;
fifo->bs = wrapped;
}
@@ -1090,21 +1127,22 @@ size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len ) {
return tail + wrapped;
}
-qboolean FIFO_ReadMessage( fifo_t *fifo, size_t msglen ) {
+qboolean FIFO_ReadMessage(fifo_t *fifo, size_t msglen)
+{
size_t len;
byte *data;
- data = FIFO_Peek( fifo, &len );
- if( len < msglen ) {
+ data = FIFO_Peek(fifo, &len);
+ if (len < msglen) {
// read in two chunks into message buffer
- if( !FIFO_TryRead( fifo, msg_read_buffer, msglen ) ) {
+ if (!FIFO_TryRead(fifo, msg_read_buffer, msglen)) {
return qfalse; // not yet available
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
} else {
// read in a single block without copying any memory
- SZ_Init( &msg_read, data, msglen );
- FIFO_Decommit( fifo, msglen );
+ SZ_Init(&msg_read, data, msglen);
+ FIFO_Decommit(fifo, msglen);
}
msg_read.cursize = msglen;
@@ -1123,49 +1161,52 @@ const vec3_t bytedirs[NUMVERTEXNORMALS] = {
#include "anorms.h"
};
-int DirToByte( const vec3_t dir ) {
+int DirToByte(const vec3_t dir)
+{
int i, best;
float d, bestd;
-
- if( !dir ) {
+
+ if (!dir) {
return 0;
}
bestd = 0;
best = 0;
- for( i = 0; i < NUMVERTEXNORMALS; i++ ) {
- d = DotProduct( dir, bytedirs[i] );
- if( d > bestd ) {
+ for (i = 0; i < NUMVERTEXNORMALS; i++) {
+ d = DotProduct(dir, bytedirs[i]);
+ if (d > bestd) {
bestd = d;
best = i;
}
}
-
+
return best;
}
#if 0
-void ByteToDir( int index, vec3_t dir ) {
- if( index < 0 || index >= NUMVERTEXNORMALS ) {
- Com_Error( ERR_FATAL, "ByteToDir: illegal index" );
+void ByteToDir(int index, vec3_t dir)
+{
+ if (index < 0 || index >= NUMVERTEXNORMALS) {
+ Com_Error(ERR_FATAL, "ByteToDir: illegal index");
}
- VectorCopy( bytedirs[index], dir );
+ VectorCopy(bytedirs[index], dir);
}
#endif
-void SetPlaneType( cplane_t *plane ) {
+void SetPlaneType(cplane_t *plane)
+{
vec_t *normal = plane->normal;
-
- if( normal[0] == 1 ) {
+
+ if (normal[0] == 1) {
plane->type = PLANE_X;
return;
}
- if( normal[1] == 1 ) {
+ if (normal[1] == 1) {
plane->type = PLANE_Y;
return;
}
- if( normal[2] == 1 ) {
+ if (normal[2] == 1) {
plane->type = PLANE_Z;
return;
}
@@ -1173,16 +1214,17 @@ void SetPlaneType( cplane_t *plane ) {
plane->type = PLANE_NON_AXIAL;
}
-void SetPlaneSignbits( cplane_t *plane ) {
+void SetPlaneSignbits(cplane_t *plane)
+{
int bits = 0;
-
- if( plane->normal[0] < 0 ) {
+
+ if (plane->normal[0] < 0) {
bits |= 1;
}
- if( plane->normal[1] < 0 ) {
+ if (plane->normal[1] < 0) {
bits |= 2;
}
- if( plane->normal[2] < 0 ) {
+ if (plane->normal[2] < 0) {
bits |= 4;
}
plane->signbits = bits;
@@ -1196,19 +1238,20 @@ Returns 1, 2, or 1 + 2
==================
*/
#if !USE_ASM
-int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, cplane_t *p ) {
+int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, cplane_t *p)
+{
vec_t *bounds[2] = { emins, emaxs };
int i = p->signbits & 1;
- int j = ( p->signbits >> 1 ) & 1;
- int k = ( p->signbits >> 2 ) & 1;
+ int j = (p->signbits >> 1) & 1;
+ int k = (p->signbits >> 2) & 1;
-#define P(i,j,k) \
- p->normal[0]*bounds[i][0]+ \
- p->normal[1]*bounds[j][1]+ \
- p->normal[2]*bounds[k][2]
+#define P(i, j, k) \
+ p->normal[0] * bounds[i][0] + \
+ p->normal[1] * bounds[j][1] + \
+ p->normal[2] * bounds[k][2]
- vec_t dist1 = P( i ^ 1, j ^ 1, k ^ 1 );
- vec_t dist2 = P( i, j, k );
+ vec_t dist1 = P(i ^ 1, j ^ 1, k ^ 1);
+ vec_t dist2 = P(i, j, k);
int sides = 0;
#undef P
@@ -1230,20 +1273,21 @@ int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, cplane_t *p ) {
==============================================================================
*/
-static qboolean match_raw( int c1, int c2, qboolean ignorecase ) {
- if( c1 != c2 ) {
- if( !ignorecase ) {
+static qboolean match_raw(int c1, int c2, qboolean ignorecase)
+{
+ if (c1 != c2) {
+ if (!ignorecase) {
return qfalse;
}
#ifdef _WIN32
// ugly hack for file listing
- c1 = c1 == '\\' ? '/' : Q_tolower( c1 );
- c2 = c2 == '\\' ? '/' : Q_tolower( c2 );
+ c1 = c1 == '\\' ? '/' : Q_tolower(c1);
+ c2 = c2 == '\\' ? '/' : Q_tolower(c2);
#else
- c1 = Q_tolower( c1 );
- c2 = Q_tolower( c2 );
+ c1 = Q_tolower(c1);
+ c2 = Q_tolower(c2);
#endif
- if( c1 != c2 ) {
+ if (c1 != c2) {
return qfalse;
}
}
@@ -1251,44 +1295,49 @@ static qboolean match_raw( int c1, int c2, qboolean ignorecase ) {
return qtrue;
}
-static qboolean match_char( int c1, int c2, qboolean ignorecase ) {
- if( c1 == '?' ) {
+static qboolean match_char(int c1, int c2, qboolean ignorecase)
+{
+ if (c1 == '?') {
return !!c2; // match any char except NUL
}
- return match_raw( c1, c2, ignorecase );
+ return match_raw(c1, c2, ignorecase);
}
-static qboolean match_part( const char *filter, const char *string, size_t len, qboolean ignorecase ) {
+static qboolean match_part(const char *filter, const char *string,
+ size_t len, qboolean ignorecase)
+{
qboolean match;
do {
// skip over escape character
- if( *filter == '\\' ) {
+ if (*filter == '\\') {
filter++;
- match = match_raw( *filter, *string, ignorecase );
+ match = match_raw(*filter, *string, ignorecase);
} else {
- match = match_char( *filter, *string, ignorecase );
+ match = match_char(*filter, *string, ignorecase);
}
- if( !match ) {
+ if (!match) {
return qfalse;
}
filter++;
string++;
- } while( --len );
+ } while (--len);
return qtrue;
}
// match the longest possible part
-static const char *match_filter( const char *filter, const char *string, size_t len, qboolean ignorecase ) {
+static const char *match_filter(const char *filter, const char *string,
+ size_t len, qboolean ignorecase)
+{
const char *ret = NULL;
- size_t remaining = strlen( string );
+ size_t remaining = strlen(string);
- while( remaining >= len ) {
- if( match_part( filter, string, len, ignorecase ) ) {
+ while (remaining >= len) {
+ if (match_part(filter, string, len, ignorecase)) {
string += len;
remaining -= len;
ret = string;
@@ -1316,52 +1365,54 @@ characters lose their meaning in this case.
=================
*/
-qboolean Com_WildCmpEx( const char *filter, const char *string, int term, qboolean ignorecase ) {
+qboolean Com_WildCmpEx(const char *filter, const char *string,
+ int term, qboolean ignorecase)
+{
const char *sub;
size_t len;
qboolean match;
- while( *filter && *filter != term ) {
- if( *filter == '*' ) {
+ while (*filter && *filter != term) {
+ if (*filter == '*') {
// skip consecutive wildcards
do {
filter++;
- } while( *filter == '*' );
+ } while (*filter == '*');
// scan out filter part to match
- for( sub = filter, len = 0; *filter && *filter != term && *filter != '*'; filter++, len++ ) {
+ for (sub = filter, len = 0; *filter && *filter != term && *filter != '*'; filter++, len++) {
// skip over escape character
- if( *filter == '\\' ) {
+ if (*filter == '\\') {
filter++;
- if( !*filter ) {
+ if (!*filter) {
break;
}
}
}
// wildcard at the end matches everything
- if( !len ) {
+ if (!len) {
return qtrue;
}
- string = match_filter( sub, string, len, ignorecase );
- if( !string ) {
+ string = match_filter(sub, string, len, ignorecase);
+ if (!string) {
return qfalse;
}
} else {
// skip over escape character
- if( *filter == '\\' ) {
+ if (*filter == '\\') {
filter++;
- if( !*filter ) {
+ if (!*filter) {
break;
}
- match = match_raw( *filter, *string, ignorecase );
+ match = match_raw(*filter, *string, ignorecase);
} else {
- match = match_char( *filter, *string, ignorecase );
+ match = match_char(*filter, *string, ignorecase);
}
// match single character
- if( !match ) {
+ if (!match) {
return qfalse;
}
@@ -1396,16 +1447,17 @@ Parses color name or index up to the maximum allowed index.
Returns COLOR_NONE in case of error.
================
*/
-color_index_t Com_ParseColor( const char *s, color_index_t last ) {
+color_index_t Com_ParseColor(const char *s, color_index_t last)
+{
color_index_t i;
- if( COM_IsUint( s ) ) {
- i = strtoul( s, NULL, 10 );
+ if (COM_IsUint(s)) {
+ i = strtoul(s, NULL, 10);
return i > last ? COLOR_NONE : i;
}
- for( i = 0; i <= last; i++ ) {
- if( !strcmp( colorNames[i], s ) ) {
+ for (i = 0; i <= last; i++) {
+ if (!strcmp(colorNames[i], s)) {
return i;
}
}
@@ -1421,28 +1473,29 @@ Com_ParseExtensionString
Helper function to parse an OpenGL-style extension string.
================
*/
-unsigned Com_ParseExtensionString( const char *s, const char *const extnames[] ) {
+unsigned Com_ParseExtensionString(const char *s, const char *const extnames[])
+{
unsigned mask;
const char *p;
size_t l1, l2;
int i;
- if( !s ) {
+ if (!s) {
return 0;
}
mask = 0;
- while( *s ) {
- p = Q_strchrnul( s, ' ' );
+ while (*s) {
+ p = Q_strchrnul(s, ' ');
l1 = p - s;
- for( i = 0; extnames[i]; i++ ) {
- l2 = strlen( extnames[i] );
- if( l1 == l2 && !memcmp( s, extnames[i], l1 ) ) {
+ for (i = 0; extnames[i]; i++) {
+ l2 = strlen(extnames[i]);
+ if (l1 == l2 && !memcmp(s, extnames[i], l1)) {
mask |= 1 << i;
break;
}
}
- if( !*p ) {
+ if (!*p) {
break;
}
s = p + 1;
@@ -1459,13 +1512,14 @@ Com_PlayerToEntityState
Restores entity origin and angles from player state
================
*/
-void Com_PlayerToEntityState( const player_state_t *ps, entity_state_t *es ) {
+void Com_PlayerToEntityState(const player_state_t *ps, entity_state_t *es)
+{
vec_t pitch;
- VectorScale( ps->pmove.origin, 0.125f, es->origin );
+ VectorScale(ps->pmove.origin, 0.125f, es->origin);
pitch = ps->viewangles[PITCH];
- if( pitch > 180 ) {
+ if (pitch > 180) {
pitch -= 360;
}
es->angles[PITCH] = pitch / 3;
@@ -1482,34 +1536,35 @@ Parses time/frame specification for seeking in demos.
Does not check for integer overflow...
================
*/
-qboolean Com_ParseTimespec( const char *s, int *frames ) {
+qboolean Com_ParseTimespec(const char *s, int *frames)
+{
unsigned long c1, c2, c3;
char *p;
- c1 = strtoul( s, &p, 10 );
- if( !*p ) {
+ c1 = strtoul(s, &p, 10);
+ if (!*p) {
*frames = c1 * 10; // sec
return qtrue;
}
- if( *p == '.' ) {
- c2 = strtoul( p + 1, &p, 10 );
- if( *p )
+ if (*p == '.') {
+ c2 = strtoul(p + 1, &p, 10);
+ if (*p)
return qfalse;
*frames = c1 * 10 + c2; // sec.frac
return qtrue;
}
- if( *p == ':' ) {
- c2 = strtoul( p + 1, &p, 10 );
- if( !*p ) {
+ if (*p == ':') {
+ c2 = strtoul(p + 1, &p, 10);
+ if (!*p) {
*frames = c1 * 600 + c2 * 10; // min:sec
return qtrue;
}
- if( *p == '.' ) {
- c3 = strtoul( p + 1, &p, 10 );
- if( *p )
+ if (*p == '.') {
+ c3 = strtoul(p + 1, &p, 10);
+ if (*p)
return qfalse;
*frames = c1 * 600 + c2 * 10 + c3; // min:sec.frac
return qtrue;
@@ -1527,17 +1582,18 @@ qboolean Com_ParseTimespec( const char *s, int *frames ) {
Com_HashString
================
*/
-unsigned Com_HashString( const char *s, unsigned size ) {
+unsigned Com_HashString(const char *s, unsigned size)
+{
unsigned hash, c;
hash = 0;
- while( *s ) {
+ while (*s) {
c = *s++;
hash = 127 * hash + c;
}
- hash = ( hash >> 20 ) ^ ( hash >> 10 ) ^ hash;
- return hash & ( size - 1 );
+ hash = (hash >> 20) ^(hash >> 10) ^ hash;
+ return hash & (size - 1);
}
/*
@@ -1548,17 +1604,18 @@ A case-insensitive version of Com_HashString that hashes up to 'len'
characters.
================
*/
-unsigned Com_HashStringLen( const char *s, size_t len, unsigned size ) {
+unsigned Com_HashStringLen(const char *s, size_t len, unsigned size)
+{
unsigned hash, c;
hash = 0;
- while( *s && len-- ) {
- c = Q_tolower( *s++ );
+ while (*s && len--) {
+ c = Q_tolower(*s++);
hash = 127 * hash + c;
}
- hash = ( hash >> 20 ) ^ ( hash >> 10 ) ^ hash;
- return hash & ( size - 1 );
+ hash = (hash >> 20) ^(hash >> 10) ^ hash;
+ return hash & (size - 1);
}
/*
@@ -1569,35 +1626,38 @@ Com_PageInMemory
*/
int paged_total;
-void Com_PageInMemory( void *buffer, size_t size ) {
+void Com_PageInMemory(void *buffer, size_t size)
+{
int i;
- for( i = size - 1; i > 0; i -= 4096 )
- paged_total += (( byte * )buffer)[i];
+ for (i = size - 1; i > 0; i -= 4096)
+ paged_total += ((byte *)buffer)[i];
}
-size_t Com_FormatTime( char *buffer, size_t size, time_t t ) {
+size_t Com_FormatTime(char *buffer, size_t size, time_t t)
+{
int sec, min, hour, day;
min = t / 60; sec = t % 60;
hour = min / 60; min %= 60;
day = hour / 24; hour %= 24;
- if( day ) {
- return Q_scnprintf( buffer, size, "%d+%d:%02d.%02d", day, hour, min, sec );
+ if (day) {
+ return Q_scnprintf(buffer, size, "%d+%d:%02d.%02d", day, hour, min, sec);
}
- if( hour ) {
- return Q_scnprintf( buffer, size, "%d:%02d.%02d", hour, min, sec );
+ if (hour) {
+ return Q_scnprintf(buffer, size, "%d:%02d.%02d", hour, min, sec);
}
- return Q_scnprintf( buffer, size, "%02d.%02d", min, sec );
+ return Q_scnprintf(buffer, size, "%02d.%02d", min, sec);
}
-size_t Com_FormatTimeLong( char *buffer, size_t size, time_t t ) {
+size_t Com_FormatTimeLong(char *buffer, size_t size, time_t t)
+{
int sec, min, hour, day;
size_t len;
- if( !t ) {
- return Q_scnprintf( buffer, size, "0 secs" );
+ if (!t) {
+ return Q_scnprintf(buffer, size, "0 secs");
}
min = t / 60; sec = t % 60;
@@ -1606,77 +1666,81 @@ size_t Com_FormatTimeLong( char *buffer, size_t size, time_t t ) {
len = 0;
- if( day ) {
- len += Q_scnprintf( buffer + len, size - len,
- "%d day%s%s", day, day == 1 ? "" : "s", ( hour || min || sec ) ? ", " : "" );
+ if (day) {
+ len += Q_scnprintf(buffer + len, size - len,
+ "%d day%s%s", day, day == 1 ? "" : "s", (hour || min || sec) ? ", " : "");
}
- if( hour ) {
- len += Q_scnprintf( buffer + len, size - len,
- "%d hour%s%s", hour, hour == 1 ? "" : "s", ( min || sec ) ? ", " : "" );
+ if (hour) {
+ len += Q_scnprintf(buffer + len, size - len,
+ "%d hour%s%s", hour, hour == 1 ? "" : "s", (min || sec) ? ", " : "");
}
- if( min ) {
- len += Q_scnprintf( buffer + len, size - len,
- "%d min%s%s", min, min == 1 ? "" : "s", sec ? ", " : "" );
+ if (min) {
+ len += Q_scnprintf(buffer + len, size - len,
+ "%d min%s%s", min, min == 1 ? "" : "s", sec ? ", " : "");
}
- if( sec ) {
- len += Q_scnprintf( buffer + len, size - len,
- "%d sec%s", sec, sec == 1 ? "" : "s" );
+ if (sec) {
+ len += Q_scnprintf(buffer + len, size - len,
+ "%d sec%s", sec, sec == 1 ? "" : "s");
}
return len;
}
-size_t Com_TimeDiff( char *buffer, size_t size, time_t *p, time_t now ) {
+size_t Com_TimeDiff(char *buffer, size_t size, time_t *p, time_t now)
+{
time_t diff;
- if( *p > now ) {
+ if (*p > now) {
*p = now;
}
diff = now - *p;
- return Com_FormatTime( buffer, size, diff );
+ return Com_FormatTime(buffer, size, diff);
}
-size_t Com_TimeDiffLong( char *buffer, size_t size, time_t *p, time_t now ) {
+size_t Com_TimeDiffLong(char *buffer, size_t size, time_t *p, time_t now)
+{
time_t diff;
- if( *p > now ) {
+ if (*p > now) {
*p = now;
}
diff = now - *p;
- return Com_FormatTimeLong( buffer, size, diff );
+ return Com_FormatTimeLong(buffer, size, diff);
}
-size_t Com_FormatSize( char *dest, size_t destsize, off_t bytes ) {
- if( bytes >= 10000000 ) {
- return Q_scnprintf( dest, destsize, "%dM", (int)(bytes / 1000000) );
+size_t Com_FormatSize(char *dest, size_t destsize, off_t bytes)
+{
+ if (bytes >= 10000000) {
+ return Q_scnprintf(dest, destsize, "%dM", (int)(bytes / 1000000));
}
- if( bytes >= 1000000 ) {
- return Q_scnprintf( dest, destsize, "%.1fM", (float)bytes / 1000000 );
+ if (bytes >= 1000000) {
+ return Q_scnprintf(dest, destsize, "%.1fM", (float)bytes / 1000000);
}
- if( bytes >= 1000 ) {
- return Q_scnprintf( dest, destsize, "%dK", (int)(bytes / 1000) );
+ if (bytes >= 1000) {
+ return Q_scnprintf(dest, destsize, "%dK", (int)(bytes / 1000));
}
- if( bytes >= 0 ) {
- return Q_scnprintf( dest, destsize, "%d", (int)bytes );
+ if (bytes >= 0) {
+ return Q_scnprintf(dest, destsize, "%d", (int)bytes);
}
- return Q_scnprintf( dest, destsize, "???" );
+ return Q_scnprintf(dest, destsize, "???");
}
-size_t Com_FormatSizeLong( char *dest, size_t destsize, off_t bytes ) {
- if( bytes >= 10000000 ) {
- return Q_scnprintf( dest, destsize, "%d MB", (int)(bytes / 1000000) );
+size_t Com_FormatSizeLong(char *dest, size_t destsize, off_t bytes)
+{
+ if (bytes >= 10000000) {
+ return Q_scnprintf(dest, destsize, "%d MB", (int)(bytes / 1000000));
}
- if( bytes >= 1000000 ) {
- return Q_scnprintf( dest, destsize, "%.1f MB", (float)bytes / 1000000 );
+ if (bytes >= 1000000) {
+ return Q_scnprintf(dest, destsize, "%.1f MB", (float)bytes / 1000000);
}
- if( bytes >= 1000 ) {
- return Q_scnprintf( dest, destsize, "%d kB", (int)(bytes / 1000) );
+ if (bytes >= 1000) {
+ return Q_scnprintf(dest, destsize, "%d kB", (int)(bytes / 1000));
}
- if( bytes >= 0 ) {
- return Q_scnprintf( dest, destsize, "%d byte%s",
- (int)bytes, bytes == 1 ? "" : "s" );
+ if (bytes >= 0) {
+ return Q_scnprintf(dest, destsize, "%d byte%s",
+ (int)bytes, bytes == 1 ? "" : "s");
}
- return Q_scnprintf( dest, destsize, "unknown size" );
+ return Q_scnprintf(dest, destsize, "unknown size");
}
/*
@@ -1687,130 +1751,141 @@ size_t Com_FormatSizeLong( char *dest, size_t destsize, off_t bytes ) {
==============================================================================
*/
-size_t Com_Time_m( char *buffer, size_t size ) {
- return format_local_time( buffer, size, com_time_format->string );
+size_t Com_Time_m(char *buffer, size_t size)
+{
+ return format_local_time(buffer, size, com_time_format->string);
}
-static size_t Com_Date_m( char *buffer, size_t size ) {
- return format_local_time( buffer, size, com_date_format->string );
+static size_t Com_Date_m(char *buffer, size_t size)
+{
+ return format_local_time(buffer, size, com_date_format->string);
}
-size_t Com_Uptime_m( char *buffer, size_t size ) {
- return Com_TimeDiff( buffer, size, &com_startTime, time( NULL ) );
+size_t Com_Uptime_m(char *buffer, size_t size)
+{
+ return Com_TimeDiff(buffer, size, &com_startTime, time(NULL));
}
-size_t Com_UptimeLong_m( char *buffer, size_t size ) {
- return Com_TimeDiffLong( buffer, size, &com_startTime, time( NULL ) );
+size_t Com_UptimeLong_m(char *buffer, size_t size)
+{
+ return Com_TimeDiffLong(buffer, size, &com_startTime, time(NULL));
}
-static size_t Com_Random_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%d", rand_byte() % 10 );
+static size_t Com_Random_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%d", rand_byte() % 10);
}
-static size_t Com_MapList_m( char *buffer, size_t size ) {
+static size_t Com_MapList_m(char *buffer, size_t size)
+{
int i, numFiles;
void **list;
char *s, *p;
size_t len, total = 0;
- list = FS_ListFiles( "maps", ".bsp", 0, &numFiles );
- for( i = 0; i < numFiles; i++ ) {
+ list = FS_ListFiles("maps", ".bsp", 0, &numFiles);
+ for (i = 0; i < numFiles; i++) {
s = list[i];
- p = COM_FileExtension( list[i] );
+ p = COM_FileExtension(list[i]);
*p = 0;
- len = strlen( s );
- if( total + len + 1 < size ) {
- memcpy( buffer + total, s, len );
+ len = strlen(s);
+ if (total + len + 1 < size) {
+ memcpy(buffer + total, s, len);
buffer[total + len] = ' ';
total += len + 1;
}
- Z_Free( s );
+ Z_Free(s);
}
buffer[total] = 0;
- Z_Free( list );
+ Z_Free(list);
return total;
}
-static void Com_LastError_f( void ) {
- Com_Printf( "%s\n", com_errorMsg );
+static void Com_LastError_f(void)
+{
+ Com_Printf("%s\n", com_errorMsg);
}
#if 0
-static void Com_Setenv_f( void ) {
+static void Com_Setenv_f(void)
+{
int argc = Cmd_Argc();
- if( argc > 2 ) {
- Q_setenv( Cmd_Argv( 1 ), Cmd_ArgsFrom( 2 ) );
- } else if( argc == 2 ) {
- char *env = getenv( Cmd_Argv( 1 ) );
+ if (argc > 2) {
+ Q_setenv(Cmd_Argv(1), Cmd_ArgsFrom(2));
+ } else if (argc == 2) {
+ char *env = getenv(Cmd_Argv(1));
- if( env ) {
- Com_Printf( "%s=%s\n", Cmd_Argv( 1 ), env );
+ if (env) {
+ Com_Printf("%s=%s\n", Cmd_Argv(1), env);
} else {
- Com_Printf( "%s undefined\n", Cmd_Argv( 1 ) );
+ Com_Printf("%s undefined\n", Cmd_Argv(1));
}
} else {
- Com_Printf( "Usage: %s <name> [value]\n", Cmd_Argv( 0 ) );
+ Com_Printf("Usage: %s <name> [value]\n", Cmd_Argv(0));
}
}
#endif
-void Com_Address_g( genctx_t *ctx ) {
+void Com_Address_g(genctx_t *ctx)
+{
int i;
cvar_t *var;
-
- for( i = 0; i < 1024; i++ ) {
- var = Cvar_FindVar( va( "adr%d", i ) );
- if( !var ) {
+
+ for (i = 0; i < 1024; i++) {
+ var = Cvar_FindVar(va("adr%d", i));
+ if (!var) {
break;
}
- if( !var->string[0] ) {
+ if (!var->string[0]) {
continue;
}
- if( !Prompt_AddMatch( ctx, var->string ) ) {
+ if (!Prompt_AddMatch(ctx, var->string)) {
break;
}
}
}
-void Com_Generic_c( genctx_t *ctx, int argnum ) {
+void Com_Generic_c(genctx_t *ctx, int argnum)
+{
xcompleter_t c;
xgenerator_t g;
cvar_t *var;
char *s;
// complete command, alias or cvar name
- if( !argnum ) {
- Cmd_Command_g( ctx );
- Cvar_Variable_g( ctx );
- Cmd_Alias_g( ctx );
+ if (!argnum) {
+ Cmd_Command_g(ctx);
+ Cvar_Variable_g(ctx);
+ Cmd_Alias_g(ctx);
return;
}
// protect against possible duplicates
ctx->ignoredups = qtrue;
- s = Cmd_Argv( ctx->argnum - argnum );
+ s = Cmd_Argv(ctx->argnum - argnum);
// complete command argument or cvar value
- if( ( c = Cmd_FindCompleter( s ) ) != NULL ) {
- c( ctx, argnum );
- } else if( argnum == 1 && ( var = Cvar_FindVar( s ) ) != NULL ) {
+ if ((c = Cmd_FindCompleter(s)) != NULL) {
+ c(ctx, argnum);
+ } else if (argnum == 1 && (var = Cvar_FindVar(s)) != NULL) {
g = var->generator;
- if( g ) {
+ if (g) {
ctx->data = var;
- g( ctx );
+ g(ctx);
}
}
}
#if USE_CLIENT
-void Com_Color_g( genctx_t *ctx ) {
+void Com_Color_g(genctx_t *ctx)
+{
int color;
- for( color = 0; color < 8; color++ ) {
- if( !Prompt_AddMatch( ctx, colorNames[color] ) ) {
+ for (color = 0; color < 8; color++) {
+ if (!Prompt_AddMatch(ctx, colorNames[color])) {
break;
}
}
@@ -1830,26 +1905,27 @@ the client and server initialize for the first time.
Other commands are added late, after all initialization is complete.
===============
*/
-static void Com_AddEarlyCommands( qboolean clear ) {
+static void Com_AddEarlyCommands(qboolean clear)
+{
int i;
char *s;
- for( i = 1; i < com_argc; i++ ) {
+ for (i = 1; i < com_argc; i++) {
s = com_argv[i];
- if( !s ) {
+ if (!s) {
continue;
}
- if( strcmp( s, "+set" ) ) {
+ if (strcmp(s, "+set")) {
continue;
}
- if( i + 2 >= com_argc ) {
- Com_Printf( "Usage: +set <variable> <value>\n" );
+ if (i + 2 >= com_argc) {
+ Com_Printf("Usage: +set <variable> <value>\n");
com_argc = i;
break;
}
- Cvar_SetEx( com_argv[ i + 1 ], com_argv[ i + 2 ], FROM_CMDLINE );
- if( clear ) {
- com_argv[i] = com_argv[ i + 1 ] = com_argv[ i + 2 ] = NULL;
+ Cvar_SetEx(com_argv[i + 1], com_argv[i + 2], FROM_CMDLINE);
+ if (clear) {
+ com_argv[i] = com_argv[i + 1] = com_argv[i + 2] = NULL;
}
i += 2;
}
@@ -1868,44 +1944,46 @@ will keep the demoloop from immediately starting
Assumes +set commands are already filtered out
=================
*/
-static qboolean Com_AddLateCommands( void ) {
+static qboolean Com_AddLateCommands(void)
+{
int i;
char *s;
qboolean ret = qfalse;
- for( i = 1; i < com_argc; i++ ) {
+ for (i = 1; i < com_argc; i++) {
s = com_argv[i];
- if( !s ) {
+ if (!s) {
continue;
}
- if( *s == '+' ) {
- if( ret ) {
- Cbuf_AddText( &cmd_buffer, "\n" );
+ if (*s == '+') {
+ if (ret) {
+ Cbuf_AddText(&cmd_buffer, "\n");
}
s++;
- } else if( ret ) {
- Cbuf_AddText( &cmd_buffer, " " );
+ } else if (ret) {
+ Cbuf_AddText(&cmd_buffer, " ");
}
- Cbuf_AddText( &cmd_buffer, s );
+ Cbuf_AddText(&cmd_buffer, s);
ret = qtrue;
}
- if( ret ) {
- Cbuf_AddText( &cmd_buffer, "\n" );
- Cbuf_Execute( &cmd_buffer );
+ if (ret) {
+ Cbuf_AddText(&cmd_buffer, "\n");
+ Cbuf_Execute(&cmd_buffer);
}
return ret;
}
-static void Com_AddConfigFile( const char *name, unsigned flags ) {
+static void Com_AddConfigFile(const char *name, unsigned flags)
+{
qerror_t ret;
- ret = Cmd_ExecuteFile( name, flags );
- if( ret == Q_ERR_SUCCESS ) {
- Cbuf_Execute( &cmd_buffer );
- } else if( ret != Q_ERR_NOENT ) {
- Com_WPrintf( "Couldn't exec %s: %s\n", name, Q_ErrorString( ret ) );
+ ret = Cmd_ExecuteFile(name, flags);
+ if (ret == Q_ERR_SUCCESS) {
+ Cbuf_Execute(&cmd_buffer);
+ } else if (ret != Q_ERR_NOENT) {
+ Com_WPrintf("Couldn't exec %s: %s\n", name, Q_ErrorString(ret));
}
}
@@ -1914,14 +1992,15 @@ static void Com_AddConfigFile( const char *name, unsigned flags ) {
Qcommon_Init
=================
*/
-void Qcommon_Init( int argc, char **argv ) {
- if( setjmp( abortframe ) )
- Sys_Error( "Error during initialization: %s", com_errorMsg );
+void Qcommon_Init(int argc, char **argv)
+{
+ if (setjmp(abortframe))
+ Sys_Error("Error during initialization: %s", com_errorMsg);
com_argc = argc;
com_argv = argv;
- Com_SetLastError( NULL );
+ Com_SetLastError(NULL);
X86_SetFPCW();
@@ -1937,66 +2016,66 @@ void Qcommon_Init( int argc, char **argv ) {
#if USE_CLIENT
Con_Init();
#endif
-
+
//
// init commands and vars
//
- z_perturb = Cvar_Get( "z_perturb", "0", 0 );
+ z_perturb = Cvar_Get("z_perturb", "0", 0);
#if USE_CLIENT
- host_speeds = Cvar_Get ("host_speeds", "0", 0);
+ host_speeds = Cvar_Get("host_speeds", "0", 0);
#endif
#ifdef _DEBUG
- developer = Cvar_Get ("developer", "0", 0);
+ developer = Cvar_Get("developer", "0", 0);
#endif
- timescale = Cvar_Get ("timescale", "1", CVAR_CHEAT );
- fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT );
- logfile_enable = Cvar_Get( "logfile", "0", 0 );
- logfile_flush = Cvar_Get( "logfile_flush", "0", 0 );
- logfile_name = Cvar_Get( "logfile_name", "console", 0 );
- logfile_prefix = Cvar_Get( "logfile_prefix", "[%Y-%m-%d %H:%M] ", 0 );
+ timescale = Cvar_Get("timescale", "1", CVAR_CHEAT);
+ fixedtime = Cvar_Get("fixedtime", "0", CVAR_CHEAT);
+ logfile_enable = Cvar_Get("logfile", "0", 0);
+ logfile_flush = Cvar_Get("logfile_flush", "0", 0);
+ logfile_name = Cvar_Get("logfile_name", "console", 0);
+ logfile_prefix = Cvar_Get("logfile_prefix", "[%Y-%m-%d %H:%M] ", 0);
#if USE_CLIENT
- dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET);
- cl_running = Cvar_Get( "cl_running", "0", CVAR_ROM );
- cl_paused = Cvar_Get( "cl_paused", "0", CVAR_ROM );
+ dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET);
+ cl_running = Cvar_Get("cl_running", "0", CVAR_ROM);
+ cl_paused = Cvar_Get("cl_paused", "0", CVAR_ROM);
#else
- dedicated = Cvar_Get ("dedicated", "1", CVAR_ROM);
+ dedicated = Cvar_Get("dedicated", "1", CVAR_ROM);
#endif
- sv_running = Cvar_Get( "sv_running", "0", CVAR_ROM );
- sv_paused = Cvar_Get( "sv_paused", "0", CVAR_ROM );
- com_timedemo = Cvar_Get( "timedemo", "0", CVAR_CHEAT );
- com_date_format = Cvar_Get( "com_date_format", "%Y-%m-%d", 0 );
+ sv_running = Cvar_Get("sv_running", "0", CVAR_ROM);
+ sv_paused = Cvar_Get("sv_paused", "0", CVAR_ROM);
+ com_timedemo = Cvar_Get("timedemo", "0", CVAR_CHEAT);
+ com_date_format = Cvar_Get("com_date_format", "%Y-%m-%d", 0);
#ifdef _WIN32
- com_time_format = Cvar_Get( "com_time_format", "%H.%M", 0 );
+ com_time_format = Cvar_Get("com_time_format", "%H.%M", 0);
#else
- com_time_format = Cvar_Get( "com_time_format", "%H:%M", 0 );
+ com_time_format = Cvar_Get("com_time_format", "%H:%M", 0);
#endif
#ifdef _DEBUG
- com_debug_break = Cvar_Get( "com_debug_break", "0", 0 );
+ com_debug_break = Cvar_Get("com_debug_break", "0", 0);
#endif
- com_fatal_error = Cvar_Get( "com_fatal_error", "0", 0 );
- com_version = Cvar_Get( "version", com_version_string, CVAR_SERVERINFO|CVAR_ROM );
+ com_fatal_error = Cvar_Get("com_fatal_error", "0", 0);
+ com_version = Cvar_Get("version", com_version_string, CVAR_SERVERINFO | CVAR_ROM);
- allow_download = Cvar_Get( "allow_download", Com_IsDedicated() ? "0" : "1", CVAR_ARCHIVE );
- allow_download_players = Cvar_Get( "allow_download_players", "1", CVAR_ARCHIVE );
- allow_download_models = Cvar_Get( "allow_download_models", "1", CVAR_ARCHIVE );
- allow_download_sounds = Cvar_Get( "allow_download_sounds", "1", CVAR_ARCHIVE );
- allow_download_maps = Cvar_Get( "allow_download_maps", "1", CVAR_ARCHIVE );
- allow_download_textures = Cvar_Get( "allow_download_textures", "1", CVAR_ARCHIVE );
- allow_download_pics = Cvar_Get( "allow_download_pics", "1", CVAR_ARCHIVE );
- allow_download_others = Cvar_Get( "allow_download_others", "0", 0 );
+ allow_download = Cvar_Get("allow_download", Com_IsDedicated() ? "0" : "1", CVAR_ARCHIVE);
+ allow_download_players = Cvar_Get("allow_download_players", "1", CVAR_ARCHIVE);
+ allow_download_models = Cvar_Get("allow_download_models", "1", CVAR_ARCHIVE);
+ allow_download_sounds = Cvar_Get("allow_download_sounds", "1", CVAR_ARCHIVE);
+ allow_download_maps = Cvar_Get("allow_download_maps", "1", CVAR_ARCHIVE);
+ allow_download_textures = Cvar_Get("allow_download_textures", "1", CVAR_ARCHIVE);
+ allow_download_pics = Cvar_Get("allow_download_pics", "1", CVAR_ARCHIVE);
+ allow_download_others = Cvar_Get("allow_download_others", "0", 0);
- rcon_password = Cvar_Get( "rcon_password", "", CVAR_PRIVATE );
+ rcon_password = Cvar_Get("rcon_password", "", CVAR_PRIVATE);
- Cmd_AddCommand ("z_stats", Z_Stats_f);
+ Cmd_AddCommand("z_stats", Z_Stats_f);
- //Cmd_AddCommand( "setenv", Com_Setenv_f );
+ //Cmd_AddCommand("setenv", Com_Setenv_f);
- Cmd_AddMacro( "com_date", Com_Date_m );
- Cmd_AddMacro( "com_time", Com_Time_m );
- Cmd_AddMacro( "com_uptime", Com_Uptime_m );
- Cmd_AddMacro( "com_uptime_long", Com_UptimeLong_m );
- Cmd_AddMacro( "random", Com_Random_m );
- Cmd_AddMacro( "com_maplist", Com_MapList_m );
+ Cmd_AddMacro("com_date", Com_Date_m);
+ Cmd_AddMacro("com_time", Com_Time_m);
+ Cmd_AddMacro("com_uptime", Com_Uptime_m);
+ Cmd_AddMacro("com_uptime_long", Com_UptimeLong_m);
+ Cmd_AddMacro("random", Com_Random_m);
+ Cmd_AddMacro("com_maplist", Com_MapList_m);
// add any system-wide configuration files
Sys_AddDefaultConfig();
@@ -2005,7 +2084,7 @@ void Qcommon_Init( int argc, char **argv ) {
// a basedir or cddir needs to be set before execing
// config files, but we want other parms to override
// the settings of the config files
- Com_AddEarlyCommands( qfalse );
+ Com_AddEarlyCommands(qfalse);
Sys_Init();
@@ -2026,24 +2105,24 @@ void Qcommon_Init( int argc, char **argv ) {
logfile_enable->changed = logfile_enable_changed;
logfile_flush->changed = logfile_param_changed;
logfile_name->changed = logfile_param_changed;
- logfile_enable_changed( logfile_enable );
+ logfile_enable_changed(logfile_enable);
// execute configs: default.cfg may come from the packfile, but config.cfg
// and autoexec.cfg must be real files within the game directory
- Com_AddConfigFile( COM_DEFAULTCFG_NAME, 0 );
- Com_AddConfigFile( COM_CONFIG_NAME, FS_TYPE_REAL|FS_PATH_GAME );
- Com_AddConfigFile( COM_AUTOEXECCFG_NAME, FS_TYPE_REAL|FS_PATH_GAME );
+ Com_AddConfigFile(COM_DEFAULTCFG_NAME, 0);
+ Com_AddConfigFile(COM_CONFIG_NAME, FS_TYPE_REAL | FS_PATH_GAME);
+ Com_AddConfigFile(COM_AUTOEXECCFG_NAME, FS_TYPE_REAL | FS_PATH_GAME);
- Com_AddEarlyCommands( qtrue );
+ Com_AddEarlyCommands(qtrue);
- Cmd_AddCommand( "lasterror", Com_LastError_f );
+ Cmd_AddCommand("lasterror", Com_LastError_f);
- Cmd_AddCommand( "quit", Com_Quit_f );
+ Cmd_AddCommand("quit", Com_Quit_f);
#if !USE_CLIENT
- Cmd_AddCommand( "recycle", Com_Recycle_f );
+ Cmd_AddCommand("recycle", Com_Recycle_f);
#endif
- srand( Sys_Milliseconds() );
+ srand(Sys_Milliseconds());
Netchan_Init();
NET_Init();
@@ -2062,12 +2141,12 @@ void Qcommon_Init( int argc, char **argv ) {
#endif
// add + commands from command line
- if( !Com_AddLateCommands() ) {
+ if (!Com_AddLateCommands()) {
// if the user didn't give any commands, run default action
char *cmd = Com_IsDedicated() ? "dedicated_start" : "client_start";
- if( ( cmd = Cmd_AliasCommand( cmd ) ) != NULL ) {
- Cbuf_AddText( &cmd_buffer, cmd );
- Cbuf_Execute( &cmd_buffer );
+ if ((cmd = Cmd_AliasCommand(cmd)) != NULL) {
+ Cbuf_AddText(&cmd_buffer, cmd);
+ Cbuf_Execute(&cmd_buffer);
}
}
#if USE_CLIENT
@@ -2081,17 +2160,17 @@ void Qcommon_Init( int argc, char **argv ) {
// even not given a starting map, dedicated server starts
// listening for rcon commands (create socket after all configs
// are executed to make sure port number is properly set)
- if( Com_IsDedicated() ) {
- NET_Config( NET_SERVER );
+ if (Com_IsDedicated()) {
+ NET_Config(NET_SERVER);
}
- Com_AddConfigFile( "postinit.cfg", FS_TYPE_REAL|FS_PATH_GAME );
+ Com_AddConfigFile("postinit.cfg", FS_TYPE_REAL | FS_PATH_GAME);
- Com_Printf( "====== " PRODUCT " initialized ======\n\n" );
- Com_LPrintf( PRINT_NOTICE, APPLICATION " " VERSION ", " __DATE__ "\n" );
- Com_Printf( "http://skuller.net/q2pro/\n\n" );
+ Com_Printf("====== " PRODUCT " initialized ======\n\n");
+ Com_LPrintf(PRINT_NOTICE, APPLICATION " " VERSION ", " __DATE__ "\n");
+ Com_Printf("http://skuller.net/q2pro/\n\n");
- time( &com_startTime );
+ time(&com_startTime);
com_eventTime = Sys_Milliseconds();
}
@@ -2101,7 +2180,8 @@ void Qcommon_Init( int argc, char **argv ) {
Qcommon_Frame
=================
*/
-void Qcommon_Frame( void ) {
+void Qcommon_Frame(void)
+{
#if USE_CLIENT
unsigned time_before, time_event, time_between, time_after;
unsigned clientrem;
@@ -2110,52 +2190,52 @@ void Qcommon_Frame( void ) {
static unsigned remaining;
static float frac;
- if( setjmp( abortframe ) ) {
+ if (setjmp(abortframe)) {
return; // an ERR_DROP was thrown
}
#if USE_CLIENT
time_before = time_event = time_between = time_after = 0;
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_before = Sys_Milliseconds();
#endif
// sleep on network sockets when running a dedicated server
// still do a select(), but don't sleep when running a client!
- IO_Sleep( remaining );
+ IO_Sleep(remaining);
// calculate time spent running last frame and sleeping
oldtime = com_eventTime;
com_eventTime = Sys_Milliseconds();
- if( oldtime > com_eventTime ) {
+ if (oldtime > com_eventTime) {
oldtime = com_eventTime;
}
msec = com_eventTime - oldtime;
#if USE_CLIENT
// spin until msec is non-zero if running a client
- if( !dedicated->integer && !com_timedemo->integer ) {
- while( msec < 1 ) {
+ if (!dedicated->integer && !com_timedemo->integer) {
+ while (msec < 1) {
qboolean break_now = CL_ProcessEvents();
com_eventTime = Sys_Milliseconds();
msec = com_eventTime - oldtime;
- if( break_now )
+ if (break_now)
break;
}
}
#endif
- if( msec > 250 ) {
- Com_DPrintf( "Hitch warning: %u msec frame time\n", msec );
+ if (msec > 250) {
+ Com_DPrintf("Hitch warning: %u msec frame time\n", msec);
msec = 100; // time was unreasonable,
- // host OS was hibernated or something
+ // host OS was hibernated or something
}
- if( fixedtime->integer ) {
- Cvar_ClampInteger( fixedtime, 1, 1000 );
+ if (fixedtime->integer) {
+ Cvar_ClampInteger(fixedtime, 1, 1000);
msec = fixedtime->integer;
- } else if( timescale->value > 0 ) {
+ } else if (timescale->value > 0) {
frac += msec * timescale->value;
msec = frac;
frac -= msec;
@@ -2166,7 +2246,7 @@ void Qcommon_Frame( void ) {
com_framenum++;
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_event = Sys_Milliseconds();
#endif
@@ -2175,21 +2255,21 @@ void Qcommon_Frame( void ) {
Sys_RunConsole();
#endif
- remaining = SV_Frame( msec );
+ remaining = SV_Frame(msec);
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_between = Sys_Milliseconds();
- clientrem = CL_Frame( msec );
- if( remaining > clientrem ) {
+ clientrem = CL_Frame(msec);
+ if (remaining > clientrem) {
remaining = clientrem;
}
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_after = Sys_Milliseconds();
- if( host_speeds->integer ) {
+ if (host_speeds->integer) {
int all, ev, sv, gm, cl, rf;
all = time_after - time_before;
@@ -2201,8 +2281,8 @@ void Qcommon_Frame( void ) {
sv -= gm;
cl -= rf;
- Com_Printf( "all:%3i ev:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n",
- all, ev, sv, gm, cl, rf );
+ Com_Printf("all:%3i ev:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n",
+ all, ev, sv, gm, cl, rf);
}
#endif
}
@@ -2212,7 +2292,8 @@ void Qcommon_Frame( void ) {
Qcommon_Shutdown
=================
*/
-void Qcommon_Shutdown( void ) {
+void Qcommon_Shutdown(void)
+{
NET_Shutdown();
logfile_close();
FS_Shutdown();
diff --git a/src/common.h b/src/common.h
index d894075..9b8d6cd 100644
--- a/src/common.h
+++ b/src/common.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -43,7 +43,7 @@ Command text buffering and command execution
==============================================================
*/
-#define CMD_BUFFER_SIZE ( 1 << 16 ) // bumped max config size up to 64K
+#define CMD_BUFFER_SIZE (1 << 16) // bumped max config size up to 64K
#define ALIAS_LOOP_COUNT 16
@@ -64,7 +64,7 @@ typedef struct cmdbuf_s {
size_t maxsize;
int waitCount;
int aliasCount; // for detecting runaway loops
- void (*exec)( struct cmdbuf_s *, const char * );
+ void (*exec)(struct cmdbuf_s *, const char *);
} cmdbuf_t;
// generic console buffer
@@ -85,25 +85,25 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
*/
-void Cbuf_Init( void );
+void Cbuf_Init(void);
// allocates an initial text buffer that will grow as needed
-void Cbuf_AddText( cmdbuf_t *buf, const char *text );
+void Cbuf_AddText(cmdbuf_t *buf, const char *text);
// as new commands are generated from the console or keybindings,
// the text is added to the end of the command buffer.
-void Cbuf_InsertText( cmdbuf_t *buf, const char *text );
+void Cbuf_InsertText(cmdbuf_t *buf, const char *text);
// when a command wants to issue other commands immediately, the text is
// inserted at the beginning of the buffer, before any remaining unexecuted
// commands.
-void Cbuf_Execute( cmdbuf_t *buf );
+void Cbuf_Execute(cmdbuf_t *buf);
// Pulls off \n terminated lines of text from the command buffer and sends
// them through Cmd_ExecuteString. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.
// Do not call inside a command function!
-char *Cbuf_Alloc( cmdbuf_t *buf, size_t len );
+char *Cbuf_Alloc(cmdbuf_t *buf, size_t len);
//===========================================================================
@@ -125,10 +125,10 @@ typedef struct genctx_s {
qboolean ignoredups;
} genctx_t;
-typedef void ( *xcommand_t )( void );
-typedef void ( *xcommandex_t )( cmdbuf_t * );
-typedef size_t ( *xmacro_t )( char *, size_t );
-typedef void ( *xcompleter_t )( struct genctx_s *, int );
+typedef void (*xcommand_t)(void);
+typedef void (*xcommandex_t)(cmdbuf_t *);
+typedef size_t (*xmacro_t)(char *, size_t);
+typedef void (*xcompleter_t)(struct genctx_s *, int);
typedef struct cmd_macro_s {
struct cmd_macro_s *next, *hashNext;
@@ -146,96 +146,96 @@ typedef struct cmdreg_s {
xcompleter_t completer;
} cmdreg_t;
-void Cmd_Init( void );
+void Cmd_Init(void);
-qboolean Cmd_Exists( const char *cmd_name );
+qboolean Cmd_Exists(const char *cmd_name);
// used by the cvar code to check for cvar / command name overlap
-void Cmd_ExecTrigger( const char *string );
+void Cmd_ExecTrigger(const char *string);
-xcommand_t Cmd_FindFunction( const char *name );
-cmd_macro_t *Cmd_FindMacro( const char *name );
-xcompleter_t Cmd_FindCompleter( const char *name );
+xcommand_t Cmd_FindFunction(const char *name);
+cmd_macro_t *Cmd_FindMacro(const char *name);
+xcompleter_t Cmd_FindCompleter(const char *name);
-char *Cmd_AliasCommand( const char *name );
-void Cmd_AliasSet( const char *name, const char *cmd );
+char *Cmd_AliasCommand(const char *name);
+void Cmd_AliasSet(const char *name, const char *cmd);
-void Cmd_Command_g( genctx_t *ctx );
-void Cmd_Alias_g( genctx_t *ctx );
-void Cmd_Macro_g( genctx_t *ctx );
-void Cmd_Config_g( genctx_t *ctx );
-void Cmd_Option_c( const cmd_option_t *opt, xgenerator_t g, genctx_t *ctx, int argnum );
+void Cmd_Command_g(genctx_t *ctx);
+void Cmd_Alias_g(genctx_t *ctx);
+void Cmd_Macro_g(genctx_t *ctx);
+void Cmd_Config_g(genctx_t *ctx);
+void Cmd_Option_c(const cmd_option_t *opt, xgenerator_t g, genctx_t *ctx, int argnum);
// attempts to match a partial command for automatic command line completion
// returns NULL if nothing fits
-void Cmd_TokenizeString( const char *text, qboolean macroExpand );
+void Cmd_TokenizeString(const char *text, qboolean macroExpand);
// Takes a null terminated string. Does not need to be /n terminated.
// breaks the string up into arg tokens.
-void Cmd_ExecuteCommand( cmdbuf_t *buf );
+void Cmd_ExecuteCommand(cmdbuf_t *buf);
// execute already tokenized string
-void Cmd_ExecuteString( cmdbuf_t *buf, const char *text );
+void Cmd_ExecuteString(cmdbuf_t *buf, const char *text);
// Parses a single line of text into arguments and tries to execute it
// as if it was typed at the console
-qerror_t Cmd_ExecuteFile( const char *path, unsigned flags );
+qerror_t Cmd_ExecuteFile(const char *path, unsigned flags);
// execute a config file
-char *Cmd_MacroExpandString( const char *text, qboolean aliasHack );
+char *Cmd_MacroExpandString(const char *text, qboolean aliasHack);
-void Cmd_Register( const cmdreg_t *reg );
-void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
+void Cmd_Register(const cmdreg_t *reg);
+void Cmd_AddCommand(const char *cmd_name, xcommand_t function);
// called by the init functions of other parts of the program to
// register commands and functions to call for them.
// The cmd_name is referenced later, so it should not be in temp memory
// if function is NULL, the command will be forwarded to the server
// as a clc_stringcmd instead of executed locally
-void Cmd_Deregister( const cmdreg_t *reg );
-void Cmd_RemoveCommand( const char *cmd_name );
-
-void Cmd_AddMacro( const char *name, xmacro_t function );
-
-from_t Cmd_From( void );
-int Cmd_Argc( void );
-char *Cmd_Argv( int arg );
-char *Cmd_Args( void );
-char *Cmd_RawArgs( void );
-char *Cmd_ArgsFrom( int from );
-char *Cmd_RawArgsFrom( int from );
-size_t Cmd_ArgsBuffer( char *buffer, size_t size );
-size_t Cmd_ArgvBuffer( int arg, char *buffer, size_t size );
-size_t Cmd_ArgOffset( int arg );
-int Cmd_FindArgForOffset( size_t offset );
-size_t Cmd_WhiteSpaceTail( void );
-char *Cmd_RawString( void );
-void Cmd_Shift( void );
+void Cmd_Deregister(const cmdreg_t *reg);
+void Cmd_RemoveCommand(const char *cmd_name);
+
+void Cmd_AddMacro(const char *name, xmacro_t function);
+
+from_t Cmd_From(void);
+int Cmd_Argc(void);
+char *Cmd_Argv(int arg);
+char *Cmd_Args(void);
+char *Cmd_RawArgs(void);
+char *Cmd_ArgsFrom(int from);
+char *Cmd_RawArgsFrom(int from);
+size_t Cmd_ArgsBuffer(char *buffer, size_t size);
+size_t Cmd_ArgvBuffer(int arg, char *buffer, size_t size);
+size_t Cmd_ArgOffset(int arg);
+int Cmd_FindArgForOffset(size_t offset);
+size_t Cmd_WhiteSpaceTail(void);
+char *Cmd_RawString(void);
+void Cmd_Shift(void);
// The functions that execute commands get their parameters with these
// functions. Cmd_Argv () will return an empty string, not a NULL
// if arg > argc, so string operations are always safe.
-void Cmd_Alias_f( void );
+void Cmd_Alias_f(void);
-void Cmd_WriteAliases( qhandle_t f );
+void Cmd_WriteAliases(qhandle_t f);
-#define EXEC_TRIGGER( var ) \
+#define EXEC_TRIGGER(var) \
do { \
- if( (var)->string[0] ) { \
- Cbuf_AddText( &cmd_buffer, (var)->string ); \
+ if ((var)->string[0]) { \
+ Cbuf_AddText(&cmd_buffer, (var)->string); \
} \
- } while( 0 )
+ } while(0)
extern int cmd_optind;
extern char *cmd_optarg;
extern char *cmd_optopt;
-int Cmd_ParseOptions( const cmd_option_t *opt );
-void Cmd_PrintHelp( const cmd_option_t *opt );
-void Cmd_PrintUsage( const cmd_option_t *opt, const char *suffix );
-void Cmd_PrintHint( void );
+int Cmd_ParseOptions(const cmd_option_t *opt);
+void Cmd_PrintHelp(const cmd_option_t *opt);
+void Cmd_PrintUsage(const cmd_option_t *opt, const char *suffix);
+void Cmd_PrintHint(void);
-const char *Cmd_Completer( const cmd_option_t *opt, const char *partial,
- int argnum, int state, xgenerator_t generator );
+const char *Cmd_Completer(const cmd_option_t *opt, const char *partial,
+ int argnum, int state, xgenerator_t generator);
/*
==============================================================
@@ -258,95 +258,95 @@ Cvars are restricted from having the same names as commands to keep this
interface from being ambiguous.
*/
-#define CVAR_CHEAT ( 1 << 5 ) // can't be changed when connected
-#define CVAR_PRIVATE ( 1 << 6 ) // never macro expanded or saved to config
-#define CVAR_ROM ( 1 << 7 ) // can't be changed even from cmdline
-#define CVAR_MODIFIED ( 1 << 8 ) // modified by user
-#define CVAR_CUSTOM ( 1 << 9 ) // created by user
-#define CVAR_WEAK ( 1 << 10 ) // doesn't have value
-#define CVAR_GAME ( 1 << 11 ) // created by game library
-#define CVAR_FILES ( 1 << 13 ) // r_reload when changed
-#define CVAR_REFRESH ( 1 << 14 ) // vid_restart when changed
-#define CVAR_SOUND ( 1 << 15 ) // snd_restart when changed
-
-#define CVAR_INFOMASK (CVAR_USERINFO|CVAR_SERVERINFO)
-#define CVAR_MODIFYMASK (CVAR_INFOMASK|CVAR_FILES|CVAR_REFRESH|CVAR_SOUND)
-#define CVAR_NOARCHIVEMASK (CVAR_NOSET|CVAR_CHEAT|CVAR_PRIVATE|CVAR_ROM)
+#define CVAR_CHEAT (1 << 5) // can't be changed when connected
+#define CVAR_PRIVATE (1 << 6) // never macro expanded or saved to config
+#define CVAR_ROM (1 << 7) // can't be changed even from cmdline
+#define CVAR_MODIFIED (1 << 8) // modified by user
+#define CVAR_CUSTOM (1 << 9) // created by user
+#define CVAR_WEAK (1 << 10) // doesn't have value
+#define CVAR_GAME (1 << 11) // created by game library
+#define CVAR_FILES (1 << 13) // r_reload when changed
+#define CVAR_REFRESH (1 << 14) // vid_restart when changed
+#define CVAR_SOUND (1 << 15) // snd_restart when changed
+
+#define CVAR_INFOMASK (CVAR_USERINFO | CVAR_SERVERINFO)
+#define CVAR_MODIFYMASK (CVAR_INFOMASK | CVAR_FILES | CVAR_REFRESH | CVAR_SOUND)
+#define CVAR_NOARCHIVEMASK (CVAR_NOSET | CVAR_CHEAT | CVAR_PRIVATE | CVAR_ROM)
#define CVAR_EXTENDED_MASK (~31)
extern cvar_t *cvar_vars;
extern int cvar_modified;
-void Cvar_Init (void);
+void Cvar_Init(void);
-void Cvar_Variable_g( genctx_t *ctx );
-void Cvar_Default_g( genctx_t *ctx );
+void Cvar_Variable_g(genctx_t *ctx);
+void Cvar_Default_g(genctx_t *ctx);
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
-int Cvar_CountLatchedVars( void );
-void Cvar_GetLatchedVars (void);
+int Cvar_CountLatchedVars(void);
+void Cvar_GetLatchedVars(void);
// any CVAR_LATCHED variables that have been set will now take effect
-void Cvar_FixCheats( void );
+void Cvar_FixCheats(void);
// resets all cheating cvars to default
-void Cvar_Command( cvar_t *v );
+void Cvar_Command(cvar_t *v);
// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
// command. Returns qtrue if the command was a variable reference that
// was handled. (print or change)
-void Cvar_WriteVariables( qhandle_t f, int mask, qboolean modified );
+void Cvar_WriteVariables(qhandle_t f, int mask, qboolean modified);
// appends lines containing "set variable value" for all variables
// with matching flags
-size_t Cvar_BitInfo( char *info, int bit );
+size_t Cvar_BitInfo(char *info, int bit);
-cvar_t *Cvar_FindVar( const char *var_name );
-xgenerator_t Cvar_FindGenerator( const char *var_name );
-qboolean Cvar_Exists( const char *name, qboolean weak );
+cvar_t *Cvar_FindVar(const char *var_name);
+xgenerator_t Cvar_FindGenerator(const char *var_name);
+qboolean Cvar_Exists(const char *name, qboolean weak);
-cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
+cvar_t *Cvar_Get(const char *var_name, const char *value, int flags);
// creates the variable if it doesn't exist, or returns the existing one
// if it exists, the value will not be changed, but flags will be ORed in
// that allows variables to be unarchived without needing bitflags
-cvar_t *Cvar_WeakGet( const char *var_name );
+cvar_t *Cvar_WeakGet(const char *var_name);
// creates weak variable without value
-void Cvar_SetByVar( cvar_t *var, const char *value, from_t from );
+void Cvar_SetByVar(cvar_t *var, const char *value, from_t from);
// set by cvar pointer
-cvar_t *Cvar_SetEx( const char *var_name, const char *value, from_t from );
+cvar_t *Cvar_SetEx(const char *var_name, const char *value, from_t from);
// will create the variable if it doesn't exist
-cvar_t *Cvar_Set( const char *var_name, const char *value );
+cvar_t *Cvar_Set(const char *var_name, const char *value);
// will set the variable even if NOSET or LATCH
-cvar_t *Cvar_UserSet( const char *var_name, const char *value );
-cvar_t *Cvar_FullSet( const char *var_name, const char *value,
- int flags, from_t from );
+cvar_t *Cvar_UserSet(const char *var_name, const char *value);
+cvar_t *Cvar_FullSet(const char *var_name, const char *value,
+ int flags, from_t from);
-#define Cvar_Reset( x ) \
- Cvar_SetByVar( x, (x)->default_string, FROM_CODE )
+#define Cvar_Reset(x) \
+ Cvar_SetByVar(x, (x)->default_string, FROM_CODE)
-void Cvar_SetValue( cvar_t *var, float value, from_t from );
-void Cvar_SetInteger( cvar_t *var, int value, from_t from );
-//void Cvar_SetHex( cvar_t *var, int value, from_t from );
+void Cvar_SetValue(cvar_t *var, float value, from_t from);
+void Cvar_SetInteger(cvar_t *var, int value, from_t from);
+//void Cvar_SetHex(cvar_t *var, int value, from_t from);
// expands value to a string and calls Cvar_Set
-int Cvar_ClampInteger( cvar_t *var, int min, int max );
-float Cvar_ClampValue( cvar_t *var, float min, float max );
+int Cvar_ClampInteger(cvar_t *var, int min, int max);
+float Cvar_ClampValue(cvar_t *var, float min, float max);
-float Cvar_VariableValue( const char *var_name );
-int Cvar_VariableInteger( const char *var_name );
+float Cvar_VariableValue(const char *var_name);
+int Cvar_VariableInteger(const char *var_name);
// returns 0 if not defined or non numeric
-char *Cvar_VariableString( const char *var_name );
+char *Cvar_VariableString(const char *var_name);
// returns an empty string if not defined
-#define Cvar_VariableStringBuffer( name, buffer, size ) \
- Q_strlcpy( buffer, Cvar_VariableString( name ), size )
+#define Cvar_VariableStringBuffer(name, buffer, size) \
+ Q_strlcpy(buffer, Cvar_VariableString(name), size)
-void Cvar_Set_f( void );
+void Cvar_Set_f(void);
/*
==============================================================
@@ -356,10 +356,10 @@ ZONE
==============================================================
*/
-#define Z_Malloc( size ) Z_TagMalloc( size, TAG_GENERAL )
-#define Z_Mallocz( size ) Z_TagMallocz( size, TAG_GENERAL )
-#define Z_Reserve( size ) Z_TagReserve( size, TAG_GENERAL )
-#define Z_CopyString( string ) Z_TagCopyString( string, TAG_GENERAL )
+#define Z_Malloc(size) Z_TagMalloc(size, TAG_GENERAL)
+#define Z_Mallocz(size) Z_TagMallocz(size, TAG_GENERAL)
+#define Z_Reserve(size) Z_TagReserve(size, TAG_GENERAL)
+#define Z_CopyString(string) Z_TagCopyString(string, TAG_GENERAL)
// memory tags to allow dynamic memory to be cleaned up
// game DLL has separate tag namespace starting at TAG_MAX
@@ -382,20 +382,20 @@ typedef enum memtag_e {
} memtag_t;
// may return pointer to static memory
-char *Cvar_CopyString( const char *in );
+char *Cvar_CopyString(const char *in);
-void Z_Free( void *ptr );
-void *Z_TagMalloc( size_t size, memtag_t tag ) q_malloc;
-void *Z_TagMallocz( size_t size, memtag_t tag ) q_malloc;
-char *Z_TagCopyString( const char *in, memtag_t tag ) q_malloc;
-void Z_FreeTags( memtag_t tag );
-void Z_LeakTest( memtag_t tag );
-void Z_Check( void );
+void Z_Free(void *ptr);
+void *Z_TagMalloc(size_t size, memtag_t tag) q_malloc;
+void *Z_TagMallocz(size_t size, memtag_t tag) q_malloc;
+char *Z_TagCopyString(const char *in, memtag_t tag) q_malloc;
+void Z_FreeTags(memtag_t tag);
+void Z_LeakTest(memtag_t tag);
+void Z_Check(void);
-void Z_TagReserve( size_t size, memtag_t tag );
-void *Z_ReservedAlloc( size_t size ) q_malloc;
-void *Z_ReservedAllocz( size_t size ) q_malloc;
-char *Z_ReservedCopyString( const char *in ) q_malloc;
+void Z_TagReserve(size_t size, memtag_t tag);
+void *Z_ReservedAlloc(size_t size) q_malloc;
+void *Z_ReservedAllocz(size_t size) q_malloc;
+char *Z_ReservedCopyString(const char *in) q_malloc;
/*
==============================================================
@@ -406,45 +406,47 @@ MATH
*/
#define NUMVERTEXNORMALS 162
+
extern const vec3_t bytedirs[NUMVERTEXNORMALS];
-int DirToByte( const vec3_t dir );
-//void ByteToDir( int index, vec3_t dir );
+int DirToByte(const vec3_t dir);
+//void ByteToDir(int index, vec3_t dir);
-void SetPlaneType( cplane_t *plane );
-void SetPlaneSignbits( cplane_t *plane );
+void SetPlaneType(cplane_t *plane);
+void SetPlaneSignbits(cplane_t *plane);
#define BOX_INFRONT 1
#define BOX_BEHIND 2
#define BOX_INTERSECTS 3
-int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, cplane_t *p );
+int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, cplane_t *p);
-static inline int BoxOnPlaneSideFast( vec3_t emins, vec3_t emaxs, cplane_t *p ) {
+static inline int BoxOnPlaneSideFast(vec3_t emins, vec3_t emaxs, cplane_t *p)
+{
// fast axial cases
- if( p->type < 3 ) {
- if( p->dist <= emins[p->type] )
+ if (p->type < 3) {
+ if (p->dist <= emins[p->type])
return BOX_INFRONT;
- if( p->dist >= emaxs[p->type] )
+ if (p->dist >= emaxs[p->type])
return BOX_BEHIND;
return BOX_INTERSECTS;
}
// slow generic case
- return BoxOnPlaneSide( emins, emaxs, p );
+ return BoxOnPlaneSide(emins, emaxs, p);
}
-static inline vec_t PlaneDiffFast( vec3_t v, cplane_t *p ) {
+static inline vec_t PlaneDiffFast(vec3_t v, cplane_t *p)
+{
// fast axial cases
- if( p->type < 3 ) {
+ if (p->type < 3) {
return v[p->type] - p->dist;
}
// slow generic case
- return PlaneDiff( v, p );
+ return PlaneDiff(v, p);
}
-
/*
==============================================================
@@ -456,7 +458,7 @@ MISC
#define MAXPRINTMSG 4096
#define MAXERRORMSG 1024
-#define CONST_STR_LEN( x ) x, x ? sizeof( x ) - 1 : 0
+#define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
typedef enum {
COLOR_BLACK,
@@ -474,12 +476,13 @@ typedef enum {
typedef struct {
const char *name;
- void (* const func)( void );
+ void (* const func)(void);
} ucmd_t;
-static inline const ucmd_t *Com_Find( const ucmd_t *u, const char *c ) {
- for( ; u->name; u++ ) {
- if( !strcmp( c, u->name ) ) {
+static inline const ucmd_t *Com_Find(const ucmd_t *u, const char *c)
+{
+ for (; u->name; u++) {
+ if (!strcmp(c, u->name)) {
return u;
}
}
@@ -491,90 +494,90 @@ typedef struct string_entry_s {
char string[1];
} string_entry_t;
-typedef void (*rdflush_t)( int target, char *buffer, size_t len );
+typedef void (*rdflush_t)(int target, char *buffer, size_t len);
-void Com_BeginRedirect (int target, char *buffer, size_t buffersize, rdflush_t flush);
-void Com_EndRedirect (void);
+void Com_BeginRedirect(int target, char *buffer, size_t buffersize, rdflush_t flush);
+void Com_EndRedirect(void);
#ifdef _WIN32
-void Com_AbortFrame( void );
+void Com_AbortFrame(void);
#endif
-char *Com_GetLastError( void );
-void Com_SetLastError( const char *msg );
+char *Com_GetLastError(void);
+void Com_SetLastError(const char *msg);
-void Com_Quit( const char *reason, error_type_t type ) q_noreturn;
+void Com_Quit(const char *reason, error_type_t type) q_noreturn;
-void Com_SetColor( color_index_t color );
+void Com_SetColor(color_index_t color);
-byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence);
+byte COM_BlockSequenceCRCByte(byte *base, size_t length, int sequence);
-void Com_Address_g( genctx_t *ctx );
-void Com_Generic_c( genctx_t *ctx, int argnum );
+void Com_Address_g(genctx_t *ctx);
+void Com_Generic_c(genctx_t *ctx, int argnum);
#if USE_CLIENT
-void Com_Color_g( genctx_t *ctx );
+void Com_Color_g(genctx_t *ctx);
#endif
-void Com_PlayerToEntityState( const player_state_t *ps, entity_state_t *es );
+void Com_PlayerToEntityState(const player_state_t *ps, entity_state_t *es);
#if USE_CLIENT || USE_MVD_CLIENT
-qboolean Com_ParseTimespec( const char *s, int *frames );
+qboolean Com_ParseTimespec(const char *s, int *frames);
#endif
-qboolean Com_WildCmpEx( const char *filter, const char *string, int term, qboolean ignorecase );
-#define Com_WildCmp( filter, string ) Com_WildCmpEx( filter, string, 0, qfalse )
+qboolean Com_WildCmpEx(const char *filter, const char *string, int term, qboolean ignorecase);
+#define Com_WildCmp(filter, string) Com_WildCmpEx(filter, string, 0, qfalse)
-unsigned Com_HashString( const char *s, unsigned size );
-unsigned Com_HashStringLen( const char *s, size_t len, unsigned size );
+unsigned Com_HashString(const char *s, unsigned size);
+unsigned Com_HashStringLen(const char *s, size_t len, unsigned size);
-qboolean Prompt_AddMatch( genctx_t *ctx, const char *s );
+qboolean Prompt_AddMatch(genctx_t *ctx, const char *s);
-size_t Com_FormatTime( char *buffer, size_t size, time_t t );
-size_t Com_FormatTimeLong( char *buffer, size_t size, time_t t );
-size_t Com_TimeDiff( char *buffer, size_t size,
- time_t *p, time_t now );
-size_t Com_TimeDiffLong( char *buffer, size_t size,
- time_t *p, time_t now );
+size_t Com_FormatTime(char *buffer, size_t size, time_t t);
+size_t Com_FormatTimeLong(char *buffer, size_t size, time_t t);
+size_t Com_TimeDiff(char *buffer, size_t size,
+ time_t *p, time_t now);
+size_t Com_TimeDiffLong(char *buffer, size_t size,
+ time_t *p, time_t now);
-size_t Com_Time_m( char *buffer, size_t size );
-size_t Com_Uptime_m( char *buffer, size_t size );
-size_t Com_UptimeLong_m( char *buffer, size_t size );
+size_t Com_Time_m(char *buffer, size_t size);
+size_t Com_Uptime_m(char *buffer, size_t size);
+size_t Com_UptimeLong_m(char *buffer, size_t size);
-size_t Com_FormatSize( char *dest, size_t destsize, off_t bytes );
-size_t Com_FormatSizeLong( char *dest, size_t destsize, off_t bytes );
+size_t Com_FormatSize(char *dest, size_t destsize, off_t bytes);
+size_t Com_FormatSizeLong(char *dest, size_t destsize, off_t bytes);
-uint32_t Com_BlockChecksum( void *buffer, size_t len );
+uint32_t Com_BlockChecksum(void *buffer, size_t len);
-void Com_PageInMemory( void *buffer, size_t size );
+void Com_PageInMemory(void *buffer, size_t size);
-color_index_t Com_ParseColor( const char *s, color_index_t last );
+color_index_t Com_ParseColor(const char *s, color_index_t last);
#if USE_REF == REF_GL
-unsigned Com_ParseExtensionString( const char *s, const char *const extnames[] );
+unsigned Com_ParseExtensionString(const char *s, const char *const extnames[]);
#endif
#ifndef _WIN32
-void Com_FlushLogs( void );
+void Com_FlushLogs(void);
#endif
#if USE_CLIENT
-#define Com_IsDedicated() ( dedicated->integer != 0 )
+#define Com_IsDedicated() (dedicated->integer != 0)
#else
#define Com_IsDedicated() 1
#endif
#ifdef _DEBUG
#define Com_DPrintf(...) \
- if( developer && developer->integer > 0 ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (developer && developer->integer > 0) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#define Com_DDPrintf(...) \
- if( developer && developer->integer > 1 ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (developer && developer->integer > 1) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#define Com_DDDPrintf(...) \
- if( developer && developer->integer > 2 ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (developer && developer->integer > 2) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#define Com_DDDDPrintf(...) \
- if( developer && developer->integer > 3 ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (developer && developer->integer > 3) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#else
#define Com_DPrintf(...)
#define Com_DDPrintf(...)
@@ -583,7 +586,7 @@ void Com_FlushLogs( void );
#endif
#if USE_TESTS
-void Com_InitTests( void );
+void Com_InitTests(void);
#endif
#ifdef _DEBUG
@@ -635,8 +638,8 @@ extern qhandle_t com_logFile;
extern const char *const colorNames[10];
-void Qcommon_Init( int argc, char **argv );
-void Qcommon_Frame( void );
-void Qcommon_Shutdown( void );
+void Qcommon_Init(int argc, char **argv);
+void Qcommon_Frame(void);
+void Qcommon_Shutdown(void);
diff --git a/src/crc.c b/src/crc.c
index 9dfbc9b..3e0a8fc 100644
--- a/src/crc.c
+++ b/src/crc.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -63,7 +63,8 @@ static const uint16_t crctable[256] = {
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
-static uint16_t CRC_Block (byte *start, size_t count) {
+static uint16_t CRC_Block(byte *start, size_t count)
+{
uint16_t crc = CRC_INIT_VALUE;
while (count--)
@@ -146,7 +147,8 @@ COM_BlockSequenceCRCByte
For proxy protecting
====================
*/
-byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence) {
+byte COM_BlockSequenceCRCByte(byte *base, size_t length, int sequence)
+{
int n;
const byte *p;
int x;
@@ -160,18 +162,18 @@ byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence) {
if (length > 60)
length = 60;
- memcpy (chkb, base, length);
+ memcpy(chkb, base, length);
chkb[length] = p[0];
- chkb[length+1] = p[1];
- chkb[length+2] = p[2];
- chkb[length+3] = p[3];
+ chkb[length + 1] = p[1];
+ chkb[length + 2] = p[2];
+ chkb[length + 3] = p[3];
length += 4;
crc = CRC_Block(chkb, length);
- for (x=0, n=0; n<length; n++)
+ for (x = 0, n = 0; n < length; n++)
x += chkb[n];
crc = (crc ^ x) & 0xff;
diff --git a/src/cvar.c b/src/cvar.c
index beee68d..e9b0c63 100644
--- a/src/cvar.c
+++ b/src/cvar.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,7 +27,7 @@ cvar_t *cvar_vars;
int cvar_modified;
-#define Cvar_Malloc( size ) Z_TagMalloc( size, TAG_CVAR )
+#define Cvar_Malloc(size) Z_TagMalloc(size, TAG_CVAR)
#define CVARHASH_SIZE 256
@@ -38,14 +38,15 @@ static cvar_t *cvarHash[CVARHASH_SIZE];
Cvar_FindVar
============
*/
-cvar_t *Cvar_FindVar( const char *var_name ) {
+cvar_t *Cvar_FindVar(const char *var_name)
+{
cvar_t *var;
unsigned hash;
- hash = Com_HashString( var_name, CVARHASH_SIZE );
-
- for( var = cvarHash[hash]; var; var = var->hashNext ) {
- if( !strcmp( var_name, var->name ) ) {
+ hash = Com_HashString(var_name, CVARHASH_SIZE);
+
+ for (var = cvarHash[hash]; var; var = var->hashNext) {
+ if (!strcmp(var_name, var->name)) {
return var;
}
}
@@ -53,8 +54,9 @@ cvar_t *Cvar_FindVar( const char *var_name ) {
return NULL;
}
-xgenerator_t Cvar_FindGenerator( const char *var_name ) {
- cvar_t *var = Cvar_FindVar( var_name );
+xgenerator_t Cvar_FindGenerator(const char *var_name)
+{
+ cvar_t *var = Cvar_FindVar(var_name);
return var ? var->generator : NULL;
}
@@ -64,12 +66,13 @@ xgenerator_t Cvar_FindGenerator( const char *var_name ) {
Cvar_Exists
============
*/
-qboolean Cvar_Exists( const char *var_name, qboolean weak ) {
- cvar_t *var = Cvar_FindVar( var_name );
+qboolean Cvar_Exists(const char *var_name, qboolean weak)
+{
+ cvar_t *var = Cvar_FindVar(var_name);
- if( !var )
+ if (!var)
return qfalse;
- if( !weak && (var->flags & (CVAR_CUSTOM|CVAR_WEAK)) )
+ if (!weak && (var->flags & (CVAR_CUSTOM | CVAR_WEAK)))
return qfalse;
return qtrue;
}
@@ -79,11 +82,12 @@ qboolean Cvar_Exists( const char *var_name, qboolean weak ) {
Cvar_VariableValue
============
*/
-float Cvar_VariableValue( const char *var_name ) {
+float Cvar_VariableValue(const char *var_name)
+{
cvar_t *var;
-
- var = Cvar_FindVar( var_name );
- if( !var )
+
+ var = Cvar_FindVar(var_name);
+ if (!var)
return 0;
return var->value;
@@ -94,11 +98,12 @@ float Cvar_VariableValue( const char *var_name ) {
Cvar_VariableInteger
============
*/
-int Cvar_VariableInteger( const char *var_name ) {
+int Cvar_VariableInteger(const char *var_name)
+{
cvar_t *var;
-
- var = Cvar_FindVar( var_name );
- if( !var )
+
+ var = Cvar_FindVar(var_name);
+ if (!var)
return 0;
return var->integer;
@@ -110,89 +115,95 @@ int Cvar_VariableInteger( const char *var_name ) {
Cvar_VariableString
============
*/
-char *Cvar_VariableString( const char *var_name ) {
+char *Cvar_VariableString(const char *var_name)
+{
cvar_t *var;
-
- var = Cvar_FindVar( var_name );
- if( !var )
+
+ var = Cvar_FindVar(var_name);
+ if (!var)
return "";
return var->string;
}
-void Cvar_Variable_g( genctx_t *ctx ) {
+void Cvar_Variable_g(genctx_t *ctx)
+{
cvar_t *c;
-
- for( c = cvar_vars; c; c = c->next ) {
- if( !Prompt_AddMatch( ctx, c->name ) ) {
+
+ for (c = cvar_vars; c; c = c->next) {
+ if (!Prompt_AddMatch(ctx, c->name)) {
break;
}
}
}
-void Cvar_Default_g( genctx_t *ctx ) {
+void Cvar_Default_g(genctx_t *ctx)
+{
cvar_t *c = ctx->data;
- if( c ) {
- if( strcmp( c->string, c->default_string ) ) {
- Prompt_AddMatch( ctx, c->string );
+ if (c) {
+ if (strcmp(c->string, c->default_string)) {
+ Prompt_AddMatch(ctx, c->string);
}
- Prompt_AddMatch( ctx, c->default_string );
+ Prompt_AddMatch(ctx, c->default_string);
}
}
// parse integer and float values
-static void parse_string_value( cvar_t *var ) {
+static void parse_string_value(cvar_t *var)
+{
char *s = var->string;
-
- if( s[0] == '0' && s[1] == 'x' ) {
- long v = strtol( s, NULL, 16 );
- var->integer = clamp( v, INT_MIN, INT_MAX );
- var->value = ( float )var->integer;
+ if (s[0] == '0' && s[1] == 'x') {
+ long v = strtol(s, NULL, 16);
+
+ var->integer = clamp(v, INT_MIN, INT_MAX);
+ var->value = (float)var->integer;
} else {
- var->integer = atoi( var->string );
- var->value = atof( var->string );
+ var->integer = atoi(var->string);
+ var->value = atof(var->string);
}
}
// string value has been changed, do some things
-static void change_string_value( cvar_t *var, const char *value, from_t from ) {
+static void change_string_value(cvar_t *var, const char *value, from_t from)
+{
// free the old value string
- Z_Free( var->string );
+ Z_Free(var->string);
- var->string = Cvar_CopyString( value );
- parse_string_value( var );
+ var->string = Cvar_CopyString(value);
+ parse_string_value(var);
#if USE_CLIENT
- if( var->flags & CVAR_USERINFO ) {
- CL_UpdateUserinfo( var, from );
+ if (var->flags & CVAR_USERINFO) {
+ CL_UpdateUserinfo(var, from);
}
#endif
var->modified = qtrue;
- if( from != FROM_CODE ) {
+ if (from != FROM_CODE) {
cvar_modified |= var->flags & CVAR_MODIFYMASK;
var->flags |= CVAR_MODIFIED;
- if( from == FROM_MENU && !(var->flags & CVAR_NOARCHIVEMASK) ) {
+ if (from == FROM_MENU && !(var->flags & CVAR_NOARCHIVEMASK)) {
var->flags |= CVAR_ARCHIVE;
}
- if( var->changed ) {
- var->changed( var );
+ if (var->changed) {
+ var->changed(var);
}
}
}
-static qboolean validate_info_cvar( const char *s ) {
- size_t len = Info_SubValidate( s );
+static qboolean validate_info_cvar(const char *s)
+{
+ size_t len = Info_SubValidate(s);
- if( len == SIZE_MAX ) {
- Com_Printf( "Info cvars should not contain '\\', ';' or '\"' characters.\n" );
+ if (len == SIZE_MAX) {
+ Com_Printf("Info cvars should not contain '\\', ';' or '\"' characters.\n");
return qfalse;
}
- if( len >= MAX_QPATH ) {
- Com_Printf( "Info cvars should be less than 64 characters long.\n" );
+ if (len >= MAX_QPATH) {
+ Com_Printf("Info cvars should be less than 64 characters long.\n");
return qfalse;
}
@@ -203,22 +214,22 @@ static qboolean validate_info_cvar( const char *s ) {
// Cvar_Get has been called from subsystem initialization routine.
// check if the first instance of this cvar has been created by user,
// and if so, enforce any restrictions on the cvar value as defined by flags
-static void get_engine_cvar( cvar_t *var, const char *var_value, int flags ) {
- if( var->flags & (CVAR_CUSTOM|CVAR_WEAK) ) {
+static void get_engine_cvar(cvar_t *var, const char *var_value, int flags)
+{
+ if (var->flags & (CVAR_CUSTOM | CVAR_WEAK)) {
// update default string if cvar was set from command line
- Z_Free( var->default_string );
- var->default_string = Cvar_CopyString( var_value );
+ Z_Free(var->default_string);
+ var->default_string = Cvar_CopyString(var_value);
// see if it was changed from it's default value
- if( strcmp( var_value, var->string ) ) {
- if( ( ( flags & CVAR_ROM ) ||
- ( ( flags & CVAR_NOSET ) && com_initialized ) ||
- ( ( flags & CVAR_CHEAT ) && !CL_CheatsOK() ) ||
- ( ( flags & CVAR_INFOMASK ) && !validate_info_cvar( var->string ) ) ||
- ( var->flags & CVAR_WEAK ) ) )
- {
+ if (strcmp(var_value, var->string)) {
+ if ((flags & CVAR_ROM) ||
+ ((flags & CVAR_NOSET) && com_initialized) ||
+ ((flags & CVAR_CHEAT) && !CL_CheatsOK()) ||
+ ((flags & CVAR_INFOMASK) && !validate_info_cvar(var->string)) ||
+ (var->flags & CVAR_WEAK)) {
// restricted cvars are reset back to default value
- change_string_value( var, var_value, FROM_CODE );
+ change_string_value(var, var_value, FROM_CODE);
} else {
// normal cvars are just flagged as modified by user
flags |= CVAR_MODIFIED;
@@ -229,7 +240,7 @@ static void get_engine_cvar( cvar_t *var, const char *var_value, int flags ) {
}
// some flags are not saved
- var->flags &= ~(CVAR_GAME|CVAR_CUSTOM|CVAR_WEAK);
+ var->flags &= ~(CVAR_GAME | CVAR_CUSTOM | CVAR_WEAK);
var->flags |= flags;
}
@@ -241,53 +252,54 @@ If the non-volatile variable already exists, the value will not be set.
The flags will be or'ed in if the variable exists.
============
*/
-cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
+cvar_t *Cvar_Get(const char *var_name, const char *var_value, int flags)
+{
cvar_t *var, *c, **p;
unsigned hash;
size_t length;
- if( !var_name ) {
- Com_Error( ERR_FATAL, "Cvar_Get: NULL var_name" );
+ if (!var_name) {
+ Com_Error(ERR_FATAL, "Cvar_Get: NULL var_name");
}
- if( !var_value ) {
- return Cvar_FindVar( var_name );
+ if (!var_value) {
+ return Cvar_FindVar(var_name);
}
- if( flags & CVAR_INFOMASK ) {
- if( !validate_info_cvar( var_name ) ) {
+ if (flags & CVAR_INFOMASK) {
+ if (!validate_info_cvar(var_name)) {
return NULL;
}
- if( !validate_info_cvar( var_value ) ) {
+ if (!validate_info_cvar(var_value)) {
return NULL;
}
}
- var = Cvar_FindVar( var_name );
- if( var ) {
- if( !( flags & (CVAR_WEAK|CVAR_CUSTOM) ) ) {
- get_engine_cvar( var, var_value, flags );
+ var = Cvar_FindVar(var_name);
+ if (var) {
+ if (!(flags & (CVAR_WEAK | CVAR_CUSTOM))) {
+ get_engine_cvar(var, var_value, flags);
}
return var;
}
// create new variable
- length = strlen( var_name ) + 1;
- var = Cvar_Malloc( sizeof( *var ) + length );
- var->name = ( char * )( var + 1 );
- memcpy( var->name, var_name, length );
- var->string = Cvar_CopyString( var_value );
+ length = strlen(var_name) + 1;
+ var = Cvar_Malloc(sizeof(*var) + length);
+ var->name = (char *)(var + 1);
+ memcpy(var->name, var_name, length);
+ var->string = Cvar_CopyString(var_value);
var->latched_string = NULL;
- var->default_string = Cvar_CopyString( var_value );
- parse_string_value( var );
+ var->default_string = Cvar_CopyString(var_value);
+ parse_string_value(var);
var->flags = flags;
var->changed = NULL;
var->generator = Cvar_Default_g;
var->modified = qtrue;
// sort the variable in
- for( c = cvar_vars, p = &cvar_vars; c; p = &c->next, c = c->next ) {
- if( strcmp( var->name, c->name ) < 0 ) {
+ for (c = cvar_vars, p = &cvar_vars; c; p = &c->next, c = c->next) {
+ if (strcmp(var->name, c->name) < 0) {
break;
}
}
@@ -295,7 +307,7 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
*p = var;
// link the variable in
- hash = Com_HashString( var_name, CVARHASH_SIZE );
+ hash = Com_HashString(var_name, CVARHASH_SIZE);
var->hashNext = cvarHash[hash];
cvarHash[hash] = var;
@@ -307,15 +319,17 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
Cvar_WeakGet
============
*/
-cvar_t *Cvar_WeakGet( const char *var_name ) {
- return Cvar_Get( var_name, "", CVAR_WEAK );
+cvar_t *Cvar_WeakGet(const char *var_name)
+{
+ return Cvar_Get(var_name, "", CVAR_WEAK);
}
-static void set_back_cvar( cvar_t *var ) {
- if( var->flags & CVAR_LATCH ) {
+static void set_back_cvar(cvar_t *var)
+{
+ if (var->flags & CVAR_LATCH) {
// set back to current value
- if( var->latched_string ) {
- Z_Free( var->latched_string );
+ if (var->latched_string) {
+ Z_Free(var->latched_string);
var->latched_string = NULL;
}
}
@@ -326,56 +340,57 @@ static void set_back_cvar( cvar_t *var ) {
Cvar_SetByVar
============
*/
-void Cvar_SetByVar( cvar_t *var, const char *value, from_t from ) {
- if( !value ) {
+void Cvar_SetByVar(cvar_t *var, const char *value, from_t from)
+{
+ if (!value) {
value = "";
}
- if( !strcmp( value, var->string ) ) {
- set_back_cvar( var );
+ if (!strcmp(value, var->string)) {
+ set_back_cvar(var);
return; // not changed
}
- if( var->flags & CVAR_INFOMASK ) {
- if( !validate_info_cvar( value ) ) {
+ if (var->flags & CVAR_INFOMASK) {
+ if (!validate_info_cvar(value)) {
return;
}
}
// some cvars may not be changed by user at all
- if( from != FROM_CODE ) {
- if( var->flags & CVAR_ROM ) {
- Com_Printf( "%s is read-only.\n", var->name );
+ if (from != FROM_CODE) {
+ if (var->flags & CVAR_ROM) {
+ Com_Printf("%s is read-only.\n", var->name);
return;
}
- if( var->flags & CVAR_CHEAT ) {
- if( !CL_CheatsOK() ) {
- Com_Printf( "%s is cheat protected.\n", var->name );
+ if (var->flags & CVAR_CHEAT) {
+ if (!CL_CheatsOK()) {
+ Com_Printf("%s is cheat protected.\n", var->name);
return;
}
}
}
// some cvars may require special processing if set by user from console
- if( from <= FROM_CONSOLE && com_initialized ) {
- if( var->flags & CVAR_NOSET ) {
- Com_Printf( "%s may be set from command line only.\n", var->name );
+ if (from <= FROM_CONSOLE && com_initialized) {
+ if (var->flags & CVAR_NOSET) {
+ Com_Printf("%s may be set from command line only.\n", var->name);
return;
}
- if( var->flags & CVAR_LATCH ) {
+ if (var->flags & CVAR_LATCH) {
// free latched value
- if( var->latched_string ) {
- if( !strcmp( var->latched_string, value ) ) {
+ if (var->latched_string) {
+ if (!strcmp(var->latched_string, value)) {
return; // latched string not changed
}
- Z_Free( var->latched_string );
+ Z_Free(var->latched_string);
var->latched_string = NULL;
}
- if( sv_running->integer ) {
- Com_Printf( "%s will be changed for next game.\n", var->name );
- var->latched_string = Cvar_CopyString( value );
+ if (sv_running->integer) {
+ Com_Printf("%s will be changed for next game.\n", var->name);
+ var->latched_string = Cvar_CopyString(value);
return;
}
// server is down, it's ok to update this cvar now
@@ -384,12 +399,12 @@ void Cvar_SetByVar( cvar_t *var, const char *value, from_t from ) {
}
// free latched string, if any
- if( var->latched_string ) {
- Z_Free( var->latched_string );
+ if (var->latched_string) {
+ Z_Free(var->latched_string);
var->latched_string = NULL;
}
- change_string_value( var, value, from );
+ change_string_value(var, value, from);
}
/*
@@ -397,16 +412,17 @@ void Cvar_SetByVar( cvar_t *var, const char *value, from_t from ) {
Cvar_SetEx
============
*/
-cvar_t *Cvar_SetEx( const char *var_name, const char *value, from_t from ) {
+cvar_t *Cvar_SetEx(const char *var_name, const char *value, from_t from)
+{
cvar_t *var;
- var = Cvar_FindVar( var_name );
- if( !var ) {
+ var = Cvar_FindVar(var_name);
+ if (!var) {
// create it
- return Cvar_Get( var_name, value, CVAR_CUSTOM );
+ return Cvar_Get(var_name, value, CVAR_CUSTOM);
}
- Cvar_SetByVar( var, value, from );
+ Cvar_SetByVar(var, value, from);
return var;
}
@@ -416,22 +432,23 @@ cvar_t *Cvar_SetEx( const char *var_name, const char *value, from_t from ) {
Cvar_FullSet
============
*/
-cvar_t *Cvar_FullSet( const char *var_name, const char *value, int flags, from_t from ) {
+cvar_t *Cvar_FullSet(const char *var_name, const char *value, int flags, from_t from)
+{
cvar_t *var;
- var = Cvar_FindVar( var_name );
- if( !var ) {
+ var = Cvar_FindVar(var_name);
+ if (!var) {
// create it
- return Cvar_Get( var_name, value, flags | CVAR_CUSTOM );
+ return Cvar_Get(var_name, value, flags | CVAR_CUSTOM);
}
- Cvar_SetByVar( var, value, from );
+ Cvar_SetByVar(var, value, from);
#if USE_CLIENT
// force retransmit of userinfo variables
// needed for compatibility with q2admin
- if( ( var->flags | flags ) & CVAR_USERINFO ) {
- CL_UpdateUserinfo( var, from );
+ if ((var->flags | flags) & CVAR_USERINFO) {
+ CL_UpdateUserinfo(var, from);
}
#endif
@@ -446,8 +463,9 @@ cvar_t *Cvar_FullSet( const char *var_name, const char *value, int flags, from_t
Cvar_Set
============
*/
-cvar_t *Cvar_Set( const char *var_name, const char *value ) {
- return Cvar_SetEx( var_name, value, FROM_CODE );
+cvar_t *Cvar_Set(const char *var_name, const char *value)
+{
+ return Cvar_SetEx(var_name, value, FROM_CODE);
}
/*
@@ -455,8 +473,9 @@ cvar_t *Cvar_Set( const char *var_name, const char *value ) {
Cvar_UserSet
============
*/
-cvar_t *Cvar_UserSet( const char *var_name, const char *value ) {
- return Cvar_SetEx( var_name, value, FROM_CONSOLE );
+cvar_t *Cvar_UserSet(const char *var_name, const char *value)
+{
+ return Cvar_SetEx(var_name, value, FROM_CONSOLE);
}
@@ -465,20 +484,21 @@ cvar_t *Cvar_UserSet( const char *var_name, const char *value ) {
Cvar_SetValue
============
*/
-void Cvar_SetValue( cvar_t *var, float value, from_t from ) {
+void Cvar_SetValue(cvar_t *var, float value, from_t from)
+{
char val[32];
- if( var->value == value ) {
- set_back_cvar( var );
+ if (var->value == value) {
+ set_back_cvar(var);
return; // not changed
}
- if( value == (int)value )
- Q_snprintf( val, sizeof( val ), "%i", (int)value );
+ if (value == (int)value)
+ Q_snprintf(val, sizeof(val), "%i", (int)value);
else
- Q_snprintf( val, sizeof( val ), "%f", value);
+ Q_snprintf(val, sizeof(val), "%f", value);
- Cvar_SetByVar( var, val, from );
+ Cvar_SetByVar(var, val, from);
}
/*
@@ -486,17 +506,18 @@ void Cvar_SetValue( cvar_t *var, float value, from_t from ) {
Cvar_SetInteger
============
*/
-void Cvar_SetInteger( cvar_t *var, int value, from_t from ) {
+void Cvar_SetInteger(cvar_t *var, int value, from_t from)
+{
char val[32];
- if( var->integer == value ) {
- set_back_cvar( var );
+ if (var->integer == value) {
+ set_back_cvar(var);
return; // not changed
}
- Q_snprintf( val, sizeof( val ), "%i", value );
+ Q_snprintf(val, sizeof(val), "%i", value);
- Cvar_SetByVar( var, val, from );
+ Cvar_SetByVar(var, val, from);
}
#if 0
@@ -505,17 +526,18 @@ void Cvar_SetInteger( cvar_t *var, int value, from_t from ) {
Cvar_SetHex
============
*/
-void Cvar_SetHex( cvar_t *var, int value, from_t from ) {
+void Cvar_SetHex(cvar_t *var, int value, from_t from)
+{
char val[32];
- if( var->integer == value ) {
- set_back_cvar( var );
+ if (var->integer == value) {
+ set_back_cvar(var);
return; // not changed
}
- Q_snprintf( val, sizeof( val ), "0x%X", value );
+ Q_snprintf(val, sizeof(val), "0x%X", value);
- Cvar_SetByVar( var, val, from );
+ Cvar_SetByVar(var, val, from);
}
#endif
@@ -524,17 +546,18 @@ void Cvar_SetHex( cvar_t *var, int value, from_t from ) {
Cvar_ClampInteger
============
*/
-int Cvar_ClampInteger( cvar_t *var, int min, int max ) {
+int Cvar_ClampInteger(cvar_t *var, int min, int max)
+{
char val[32];
- if( var->integer < min ) {
- Q_snprintf( val, sizeof( val ), "%i", min );
- Cvar_SetByVar( var, val, FROM_CODE );
+ if (var->integer < min) {
+ Q_snprintf(val, sizeof(val), "%i", min);
+ Cvar_SetByVar(var, val, FROM_CODE);
return min;
}
- if( var->integer > max ) {
- Q_snprintf( val, sizeof( val ), "%i", max );
- Cvar_SetByVar( var, val, FROM_CODE );
+ if (var->integer > max) {
+ Q_snprintf(val, sizeof(val), "%i", max);
+ Cvar_SetByVar(var, val, FROM_CODE);
return max;
}
return var->integer;
@@ -545,25 +568,26 @@ int Cvar_ClampInteger( cvar_t *var, int min, int max ) {
Cvar_ClampValue
============
*/
-float Cvar_ClampValue( cvar_t *var, float min, float max ) {
+float Cvar_ClampValue(cvar_t *var, float min, float max)
+{
char val[32];
- if( var->value < min ) {
- if( min == (int)min ) {
- Q_snprintf( val, sizeof( val ), "%i", (int)min );
+ if (var->value < min) {
+ if (min == (int)min) {
+ Q_snprintf(val, sizeof(val), "%i", (int)min);
} else {
- Q_snprintf( val, sizeof( val ), "%f", min );
+ Q_snprintf(val, sizeof(val), "%f", min);
}
- Cvar_SetByVar( var, val, FROM_CODE );
+ Cvar_SetByVar(var, val, FROM_CODE);
return min;
}
- if( var->value > max ) {
- if( max == (int)max ) {
- Q_snprintf( val, sizeof( val ), "%i", (int)max );
+ if (var->value > max) {
+ if (max == (int)max) {
+ Q_snprintf(val, sizeof(val), "%i", (int)max);
} else {
- Q_snprintf( val, sizeof( val ), "%f", max );
+ Q_snprintf(val, sizeof(val), "%f", max);
}
- Cvar_SetByVar( var, val, FROM_CODE );
+ Cvar_SetByVar(var, val, FROM_CODE);
return max;
}
return var->value;
@@ -574,19 +598,20 @@ float Cvar_ClampValue( cvar_t *var, float min, float max ) {
Cvar_FixCheats
==================
*/
-void Cvar_FixCheats( void ) {
+void Cvar_FixCheats(void)
+{
cvar_t *var;
- if( CL_CheatsOK() ) {
+ if (CL_CheatsOK()) {
return;
}
// fix any cheating cvars
- for( var = cvar_vars; var; var = var->next ) {
- if( var->flags & CVAR_CHEAT ) {
- Cvar_SetByVar( var, var->default_string, FROM_CODE );
- if( var->changed )
- var->changed( var );
+ for (var = cvar_vars; var; var = var->next) {
+ if (var->flags & CVAR_CHEAT) {
+ Cvar_SetByVar(var, var->default_string, FROM_CODE);
+ if (var->changed)
+ var->changed(var);
}
}
}
@@ -598,36 +623,38 @@ Cvar_GetLatchedVars
Any variables with latched values will now be updated
============
*/
-void Cvar_GetLatchedVars( void ) {
+void Cvar_GetLatchedVars(void)
+{
cvar_t *var;
- for( var = cvar_vars; var; var = var->next ) {
- if( var->flags & CVAR_GAME )
+ for (var = cvar_vars; var; var = var->next) {
+ if (var->flags & CVAR_GAME)
var->flags &= ~CVAR_SERVERINFO;
- if( !(var->flags & CVAR_LATCH) )
+ if (!(var->flags & CVAR_LATCH))
continue;
- if( !var->latched_string )
+ if (!var->latched_string)
continue;
- Z_Free( var->string );
+ Z_Free(var->string);
var->string = var->latched_string;
var->latched_string = NULL;
- parse_string_value( var );
+ parse_string_value(var);
var->modified = qtrue;
cvar_modified |= var->flags & CVAR_MODIFYMASK;
- if( var->changed ) {
- var->changed( var );
+ if (var->changed) {
+ var->changed(var);
}
}
}
-int Cvar_CountLatchedVars( void ) {
+int Cvar_CountLatchedVars(void)
+{
cvar_t *var;
int total = 0;
- for( var = cvar_vars; var; var = var->next ) {
- if( !(var->flags & CVAR_LATCH) )
+ for (var = cvar_vars; var; var = var->next) {
+ if (!(var->flags & CVAR_LATCH))
continue;
- if( !var->latched_string )
+ if (!var->latched_string)
continue;
total++;
}
@@ -642,36 +669,38 @@ Cvar_Command
Handles variable inspection and changing from the console
============
*/
-void Cvar_Command( cvar_t *v ) {
+void Cvar_Command(cvar_t *v)
+{
// perform a variable print or set
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "\"%s\" is \"%s\"", v->name, v->string );
- if( strcmp( v->string, v->default_string ) ) {
- Com_Printf( " default: \"%s\"", v->default_string );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("\"%s\" is \"%s\"", v->name, v->string);
+ if (strcmp(v->string, v->default_string)) {
+ Com_Printf(" default: \"%s\"", v->default_string);
}
- if( v->latched_string && strcmp( v->latched_string, v->string ) ) {
- Com_Printf( " latched: \"%s\"", v->latched_string );
+ if (v->latched_string && strcmp(v->latched_string, v->string)) {
+ Com_Printf(" latched: \"%s\"", v->latched_string);
}
- Com_Printf( "\n" );
+ Com_Printf("\n");
} else {
- Cvar_SetByVar( v, Cmd_ArgsFrom( 1 ), Cmd_From() );
+ Cvar_SetByVar(v, Cmd_ArgsFrom(1), Cmd_From());
}
}
-static void Cvar_Set_c( genctx_t *ctx, int argnum ) {
+static void Cvar_Set_c(genctx_t *ctx, int argnum)
+{
char *s;
cvar_t *var;
xgenerator_t g;
- if( argnum == 1 ) {
- Cvar_Variable_g( ctx );
- } else if( argnum == 2 ) {
- s = Cmd_Argv( ctx->argnum - 1 );
- if( ( var = Cvar_FindVar( s ) ) != NULL ) {
+ if (argnum == 1) {
+ Cvar_Variable_g(ctx);
+ } else if (argnum == 2) {
+ s = Cmd_Argv(ctx->argnum - 1);
+ if ((var = Cvar_FindVar(s)) != NULL) {
g = var->generator;
- if( g ) {
+ if (g) {
ctx->data = var;
- g( ctx );
+ g(ctx);
}
}
}
@@ -685,36 +714,37 @@ Cvar_Set_f
Allows setting and defining of arbitrary cvars from console
============
*/
-void Cvar_Set_f( void ) {
+void Cvar_Set_f(void)
+{
int c, flags;
char *f;
c = Cmd_Argc();
- if( c < 3 ) {
- Com_Printf( "Usage: set <variable> <value> [u / s]\n" );
+ if (c < 3) {
+ Com_Printf("Usage: set <variable> <value> [u / s]\n");
return;
}
- if( c == 3 ) {
- Cvar_SetEx( Cmd_Argv( 1 ), Cmd_Argv( 2 ), Cmd_From() );
+ if (c == 3) {
+ Cvar_SetEx(Cmd_Argv(1), Cmd_Argv(2), Cmd_From());
return;
}
- if( c == 4 ) {
- f = Cmd_Argv( 3 );
- if( !strcmp( f, "u" ) ) {
+ if (c == 4) {
+ f = Cmd_Argv(3);
+ if (!strcmp(f, "u")) {
flags = CVAR_USERINFO;
- } else if( !strcmp( f, "s" ) ) {
+ } else if (!strcmp(f, "s")) {
flags = CVAR_SERVERINFO;
} else {
goto set;
}
- Cvar_FullSet( Cmd_Argv( 1 ), Cmd_Argv( 2 ), flags, Cmd_From() );
+ Cvar_FullSet(Cmd_Argv(1), Cmd_Argv(2), flags, Cmd_From());
return;
}
set:
- Cvar_SetEx( Cmd_Argv( 1 ), Cmd_ArgsFrom( 2 ), Cmd_From() );
+ Cvar_SetEx(Cmd_Argv(1), Cmd_ArgsFrom(2), Cmd_From());
}
/*
@@ -724,31 +754,32 @@ Cvar_SetFlag_f
Allows setting and defining of arbitrary cvars from console
============
*/
-static void Cvar_SetFlag_f( void ) {
- char *s = Cmd_Argv( 0 );
+static void Cvar_SetFlag_f(void)
+{
+ char *s = Cmd_Argv(0);
int flags;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <variable> <value>\n", s );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <variable> <value>\n", s);
return;
}
- if( !strcmp( s, "seta" ) ) {
- cvar_t *var = Cvar_SetEx( Cmd_Argv( 1 ), Cmd_ArgsFrom( 2 ), Cmd_From() );
- if( var && !(var->flags & CVAR_NOARCHIVEMASK) )
+ if (!strcmp(s, "seta")) {
+ cvar_t *var = Cvar_SetEx(Cmd_Argv(1), Cmd_ArgsFrom(2), Cmd_From());
+ if (var && !(var->flags & CVAR_NOARCHIVEMASK))
var->flags |= CVAR_ARCHIVE;
return;
}
- if( !strcmp( s, "setu" ) ) {
+ if (!strcmp(s, "setu")) {
flags = CVAR_USERINFO;
- } else if( !strcmp( s, "sets" ) ) {
+ } else if (!strcmp(s, "sets")) {
flags = CVAR_SERVERINFO;
} else {
return;
}
- Cvar_FullSet( Cmd_Argv( 1 ), Cmd_ArgsFrom( 2 ), flags, Cmd_From() );
+ Cvar_FullSet(Cmd_Argv(1), Cmd_ArgsFrom(2), flags, Cmd_From());
}
#if USE_CLIENT
@@ -761,23 +792,24 @@ Appends lines containing "set variable value" for all variables
with the archive flag set to true.
============
*/
-void Cvar_WriteVariables( qhandle_t f, int mask, qboolean modified ) {
+void Cvar_WriteVariables(qhandle_t f, int mask, qboolean modified)
+{
cvar_t *var;
char *s, *a;
- for( var = cvar_vars; var; var = var->next ) {
- if( var->flags & CVAR_NOARCHIVEMASK )
+ for (var = cvar_vars; var; var = var->next) {
+ if (var->flags & CVAR_NOARCHIVEMASK)
continue;
- if( !( var->flags & mask ) )
+ if (!(var->flags & mask))
continue;
s = var->latched_string ? var->latched_string : var->string;
- if( modified && !strcmp( s, var->default_string ) )
+ if (modified && !strcmp(s, var->default_string))
continue;
- a = !modified && ( var->flags & CVAR_ARCHIVE ) ? "a" : "";
- FS_FPrintf( f, "set%s %s \"%s\"\n", a, var->name, s );
- }
+ a = !modified && (var->flags & CVAR_ARCHIVE) ? "a" : "";
+ FS_FPrintf(f, "set%s %s \"%s\"\n", a, var->name, s);
+ }
}
#endif
@@ -805,11 +837,13 @@ static const cmd_option_t o_cvarlist[] = {
{ NULL }
};
-static void Cvar_List_c( genctx_t *ctx, int argnum ) {
- Cmd_Option_c( o_cvarlist, NULL, ctx, argnum );
+static void Cvar_List_c(genctx_t *ctx, int argnum)
+{
+ Cmd_Option_c(o_cvarlist, NULL, ctx, argnum);
}
-static void Cvar_List_f( void ) {
+static void Cvar_List_f(void)
+{
cvar_t *var;
int i, total;
qboolean verbose = qfalse, modified = qfalse, latched = qfalse;
@@ -818,8 +852,8 @@ static void Cvar_List_f( void ) {
char buffer[5];
int c;
- while( ( c = Cmd_ParseOptions( o_cvarlist ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_cvarlist)) != -1) {
+ switch (c) {
case 'a':
mask |= CVAR_ARCHIVE;
break;
@@ -827,19 +861,19 @@ static void Cvar_List_f( void ) {
mask |= CVAR_CHEAT;
break;
case 'h':
- Cmd_PrintUsage( o_cvarlist, NULL );
- Com_Printf( "List registered console variables.\n" );
- Cmd_PrintHelp( o_cvarlist );
+ Cmd_PrintUsage(o_cvarlist, NULL);
+ Com_Printf("List registered console variables.\n");
+ Cmd_PrintHelp(o_cvarlist);
Com_Printf(
- "Flags legend:\n"
- "C: cheat protected\n"
- "A: archived in config file\n"
- "U: included in userinfo\n"
- "S: included in serverinfo\n"
- "N: set from command line only\n"
- "R: read-only variable\n"
- "L: latched\n"
- "?: created by user\n" );
+ "Flags legend:\n"
+ "C: cheat protected\n"
+ "A: archived in config file\n"
+ "U: included in userinfo\n"
+ "S: included in serverinfo\n"
+ "N: set from command line only\n"
+ "R: read-only variable\n"
+ "L: latched\n"
+ "?: created by user\n");
return;
case 'l':
latched = qtrue;
@@ -873,55 +907,54 @@ static void Cvar_List_f( void ) {
}
}
- buffer[sizeof( buffer ) - 1] = 0;
+ buffer[sizeof(buffer) - 1] = 0;
i = 0;
- for( var = cvar_vars, total = 0; var; var = var->next, total++ ) {
- if( latched && !var->latched_string ) {
+ for (var = cvar_vars, total = 0; var; var = var->next, total++) {
+ if (latched && !var->latched_string) {
continue;
}
- if( mask && !( var->flags & mask ) ) {
+ if (mask && !(var->flags & mask)) {
continue;
}
- if( wildcard && !Com_WildCmp( wildcard, var->name ) ) {
+ if (wildcard && !Com_WildCmp(wildcard, var->name)) {
continue;
}
- if( modified && ( !strcmp( var->latched_string ? var->latched_string :
- var->string, var->default_string ) || ( var->flags & CVAR_ROM ) ) )
- {
+ if (modified && (!strcmp(var->latched_string ? var->latched_string :
+ var->string, var->default_string) || (var->flags & CVAR_ROM))) {
continue;
}
- if( verbose ) {
- memset( buffer, '-', sizeof( buffer ) - 1 );
+ if (verbose) {
+ memset(buffer, '-', sizeof(buffer) - 1);
- if( var->flags & CVAR_CHEAT )
+ if (var->flags & CVAR_CHEAT)
buffer[0] = 'C';
- else if( var->flags & CVAR_ARCHIVE )
+ else if (var->flags & CVAR_ARCHIVE)
buffer[0] = 'A';
- if( var->flags & CVAR_USERINFO )
+ if (var->flags & CVAR_USERINFO)
buffer[1] = 'U';
- if( var->flags & CVAR_SERVERINFO )
+ if (var->flags & CVAR_SERVERINFO)
buffer[2] = 'S';
- if( var->flags & CVAR_ROM )
+ if (var->flags & CVAR_ROM)
buffer[3] = 'R';
- else if( var->flags & CVAR_NOSET )
+ else if (var->flags & CVAR_NOSET)
buffer[3] = 'N';
- else if( var->flags & CVAR_LATCH )
+ else if (var->flags & CVAR_LATCH)
buffer[3] = 'L';
- else if( var->flags & CVAR_CUSTOM )
+ else if (var->flags & CVAR_CUSTOM)
buffer[3] = '?';
- Com_Printf( "%s ", buffer );
+ Com_Printf("%s ", buffer);
}
- Com_Printf( "%s \"%s\"\n", var->name, var->string );
+ Com_Printf("%s \"%s\"\n", var->name, var->string);
i++;
}
- Com_Printf( "%i of %i cvars\n", i, total );
+ Com_Printf("%i of %i cvars\n", i, total);
}
/*
@@ -929,54 +962,56 @@ static void Cvar_List_f( void ) {
Cvar_Toggle_f
============
*/
-static void Cvar_Toggle_f( void ) {
+static void Cvar_Toggle_f(void)
+{
cvar_t *var;
int i, argc = Cmd_Argc();
- if( argc < 2 ) {
- Com_Printf( "Usage: %s <variable> [values]\n", Cmd_Argv( 0 ) );
+ if (argc < 2) {
+ Com_Printf("Usage: %s <variable> [values]\n", Cmd_Argv(0));
return;
}
- var = Cvar_FindVar( Cmd_Argv( 1 ) );
- if( !var ) {
- Com_Printf( "%s is not a variable\n", Cmd_Argv( 1 ) );
+ var = Cvar_FindVar(Cmd_Argv(1));
+ if (!var) {
+ Com_Printf("%s is not a variable\n", Cmd_Argv(1));
return;
}
- if( argc < 3 ) {
- if( !strcmp( var->string, "0" ) ) {
- Cvar_SetByVar( var, "1", Cmd_From() );
- } else if( !strcmp( var->string, "1" ) ) {
- Cvar_SetByVar( var, "0", Cmd_From() );
+ if (argc < 3) {
+ if (!strcmp(var->string, "0")) {
+ Cvar_SetByVar(var, "1", Cmd_From());
+ } else if (!strcmp(var->string, "1")) {
+ Cvar_SetByVar(var, "0", Cmd_From());
} else {
- Com_Printf( "\"%s\" is \"%s\", can't toggle\n",
- var->name, var->string );
+ Com_Printf("\"%s\" is \"%s\", can't toggle\n",
+ var->name, var->string);
}
return;
}
- for( i = 0; i < argc - 2; i++ ) {
- if( !Q_stricmp( var->string, Cmd_Argv( 2 + i ) ) ) {
- i = ( i + 1 ) % ( argc - 2 );
- Cvar_SetByVar( var, Cmd_Argv( 2 + i ), Cmd_From() );
+ for (i = 0; i < argc - 2; i++) {
+ if (!Q_stricmp(var->string, Cmd_Argv(2 + i))) {
+ i = (i + 1) % (argc - 2);
+ Cvar_SetByVar(var, Cmd_Argv(2 + i), Cmd_From());
return;
}
}
- Com_Printf( "\"%s\" is \"%s\", can't cycle\n", var->name, var->string );
+ Com_Printf("\"%s\" is \"%s\", can't cycle\n", var->name, var->string);
}
-static void Cvar_Toggle_c( genctx_t *ctx, int argnum ) {
+static void Cvar_Toggle_c(genctx_t *ctx, int argnum)
+{
char *s;
xgenerator_t g;
- if( argnum == 1 ) {
- Cvar_Variable_g( ctx );
+ if (argnum == 1) {
+ Cvar_Variable_g(ctx);
} else {
- s = Cmd_Argv( ctx->argnum - argnum + 1 );
- if( ( g = Cvar_FindGenerator( s ) ) != NULL ) {
- g( ctx );
+ s = Cmd_Argv(ctx->argnum - argnum + 1);
+ if ((g = Cvar_FindGenerator(s)) != NULL) {
+ g(ctx);
}
}
}
@@ -986,43 +1021,44 @@ static void Cvar_Toggle_c( genctx_t *ctx, int argnum ) {
Cvar_Inc_f
============
*/
-static void Cvar_Inc_f( void ) {
+static void Cvar_Inc_f(void)
+{
cvar_t *var;
float value;
char val[32];
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <variable> [value]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <variable> [value]\n", Cmd_Argv(0));
return;
}
- var = Cvar_FindVar( Cmd_Argv( 1 ) );
- if( !var ) {
- Com_Printf( "%s is not a variable\n", Cmd_Argv( 1 ) );
+ var = Cvar_FindVar(Cmd_Argv(1));
+ if (!var) {
+ Com_Printf("%s is not a variable\n", Cmd_Argv(1));
return;
}
- if( !COM_IsFloat( var->string ) ) {
- Com_Printf( "\"%s\" is \"%s\", can't %s\n",
- var->name, var->string, Cmd_Argv( 0 ) );
+ if (!COM_IsFloat(var->string)) {
+ Com_Printf("\"%s\" is \"%s\", can't %s\n",
+ var->name, var->string, Cmd_Argv(0));
return;
}
value = 1;
- if( Cmd_Argc() > 2 ) {
- value = atof( Cmd_Argv( 2 ) );
+ if (Cmd_Argc() > 2) {
+ value = atof(Cmd_Argv(2));
}
- if( !strcmp( Cmd_Argv( 0 ), "dec" ) ) {
+ if (!strcmp(Cmd_Argv(0), "dec")) {
value = -value;
}
value += var->value;
- if( value == ( int )value )
- Q_snprintf( val, sizeof( val ), "%i", ( int )value );
+ if (value == (int)value)
+ Q_snprintf(val, sizeof(val), "%i", (int)value);
else
- Q_snprintf( val, sizeof( val ), "%f", value );
+ Q_snprintf(val, sizeof(val), "%f", value);
- Cvar_SetByVar( var, val, Cmd_From() );
+ Cvar_SetByVar(var, val, Cmd_From());
}
/*
@@ -1030,60 +1066,63 @@ static void Cvar_Inc_f( void ) {
Cvar_Reset_f
============
*/
-static void Cvar_Reset_f( void ) {
+static void Cvar_Reset_f(void)
+{
cvar_t *var;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <variable>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <variable>\n", Cmd_Argv(0));
return;
}
- var = Cvar_FindVar( Cmd_Argv( 1 ) );
- if( !var ) {
- Com_Printf( "%s is not a variable\n", Cmd_Argv( 1 ) );
+ var = Cvar_FindVar(Cmd_Argv(1));
+ if (!var) {
+ Com_Printf("%s is not a variable\n", Cmd_Argv(1));
return;
}
- Cvar_SetByVar( var, var->default_string, Cmd_From() );
+ Cvar_SetByVar(var, var->default_string, Cmd_From());
}
-static void Cvar_Reset_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Cvar_Variable_g( ctx );
+static void Cvar_Reset_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Cvar_Variable_g(ctx);
}
}
-size_t Cvar_BitInfo( char *info, int bit ) {
+size_t Cvar_BitInfo(char *info, int bit)
+{
char newi[MAX_INFO_STRING], *v;
cvar_t *var;
size_t len, total = 0;
int c;
- for( var = cvar_vars; var; var = var->next ) {
- if( !( var->flags & bit ) ) {
+ for (var = cvar_vars; var; var = var->next) {
+ if (!(var->flags & bit)) {
continue;
}
- if( var->flags & CVAR_PRIVATE ) {
+ if (var->flags & CVAR_PRIVATE) {
continue;
}
- if( !var->string[0] ) {
+ if (!var->string[0]) {
continue;
}
- len = Q_concat( newi, sizeof( newi ),
- "\\", var->name, "\\", var->string, NULL );
- if( len >= sizeof( newi ) ) {
+ len = Q_concat(newi, sizeof(newi),
+ "\\", var->name, "\\", var->string, NULL);
+ if (len >= sizeof(newi)) {
continue;
}
- if( total + len >= MAX_INFO_STRING ) {
+ if (total + len >= MAX_INFO_STRING) {
break;
}
// only copy ascii values
v = newi;
- while( *v ) {
+ while (*v) {
c = *v++;
c &= 127; // strip high bits
- if( Q_isprint( c ) )
+ if (Q_isprint(c))
info[total++] = c;
}
}
@@ -1111,7 +1150,8 @@ static const cmdreg_t c_cvar[] = {
Cvar_Init
============
*/
-void Cvar_Init( void ) {
- Cmd_Register( c_cvar );
+void Cvar_Init(void)
+{
+ Cmd_Register(c_cvar);
}
diff --git a/src/d_bsp.h b/src/d_bsp.h
index 8036860..6596703 100644
--- a/src/d_bsp.h
+++ b/src/d_bsp.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -93,7 +93,7 @@ typedef struct {
typedef struct {
uint32_t ident;
- uint32_t version;
+ uint32_t version;
lump_t lumps[HEADER_LUMPS];
} dheader_t;
@@ -145,7 +145,7 @@ typedef struct {
uint16_t side;
uint32_t firstedge; // we must support > 64k edges
- uint16_t numedges;
+ uint16_t numedges;
uint16_t texinfo;
// lighting info
diff --git a/src/d_md2.h b/src/d_md2.h
index be907ed..0c0abf1 100644
--- a/src/d_md2.h
+++ b/src/d_md2.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -60,8 +60,7 @@ typedef struct {
} dmd2frame_t;
#define MD2_MAX_FRAMESIZE \
- ( sizeof( dmd2frame_t ) + sizeof( dmd2trivertx_t ) * ( MD2_MAX_VERTS - 1 ) )
-
+ (sizeof(dmd2frame_t) + sizeof(dmd2trivertx_t) * (MD2_MAX_VERTS - 1))
// the glcmd format:
// a positive integer starts a tristrip command, followed by that many
@@ -91,7 +90,7 @@ typedef struct dmd2header_s {
uint32_t ofs_st; // byte offset from start for stverts
uint32_t ofs_tris; // offset for dtriangles
uint32_t ofs_frames; // offset for first frame
- uint32_t ofs_glcmds;
+ uint32_t ofs_glcmds;
uint32_t ofs_end; // end of file
} dmd2header_t;
diff --git a/src/d_md3.h b/src/d_md3.h
index 332d732..106ff6e 100644
--- a/src/d_md3.h
+++ b/src/d_md3.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/d_pak.h b/src/d_pak.h
index a5556ee..9462815 100644
--- a/src/d_pak.h
+++ b/src/d_pak.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/d_pcx.h b/src/d_pcx.h
index 43dc416..55bd308 100644
--- a/src/d_pcx.h
+++ b/src/d_pcx.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/d_sp2.h b/src/d_sp2.h
index 7421050..096a086 100644
--- a/src/d_sp2.h
+++ b/src/d_sp2.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/d_wal.h b/src/d_wal.h
index 700502a..69b3972 100644
--- a/src/d_wal.h
+++ b/src/d_wal.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/error.c b/src/error.c
index 806177f..cf5c681 100644
--- a/src/error.c
+++ b/src/error.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -49,25 +49,26 @@ static const char *const error_table[] = {
};
static const int num_errors =
- sizeof( error_table ) / sizeof( error_table[0] );
+ sizeof(error_table) / sizeof(error_table[0]);
-const char *Q_ErrorString( qerror_t error ) {
+const char *Q_ErrorString(qerror_t error)
+{
int e;
- if( error >= 0 ) {
+ if (error >= 0) {
return "Success";
}
- if( error > -ERRNO_MAX ) {
+ if (error > -ERRNO_MAX) {
#if EINVAL > 0
e = -error;
#else
e = error;
#endif
- return strerror( e );
+ return strerror(e);
}
- e = _Q_ERR( error );
+ e = _Q_ERR(error);
return error_table[e >= num_errors ? 0 : e];
}
diff --git a/src/error.h b/src/error.h
index 4031863..a121113 100644
--- a/src/error.h
+++ b/src/error.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -64,7 +64,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define Q_ERR_EXIST Q_ERR(EEXIST)
#define Q_ERR_BADF Q_ERR(EBADF)
-#define Q_PrintError( what, code ) \
- Com_Printf( "Couldn't %s: %s\n", what, Q_ErrorString( code ) )
+#define Q_PrintError(what, code) \
+ Com_Printf("Couldn't %s: %s\n", what, Q_ErrorString(code))
-const char *Q_ErrorString( qerror_t error );
+const char *Q_ErrorString(qerror_t error);
diff --git a/src/files.c b/src/files.c
index 601ac77..1e47c7a 100644
--- a/src/files.c
+++ b/src/files.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -64,8 +64,8 @@ QUAKE FILESYSTEM
#ifdef _DEBUG
#define FS_DPrintf(...) \
- if( fs_debug && fs_debug->integer ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (fs_debug && fs_debug->integer) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#else
#define FS_DPrintf(...)
#endif
@@ -174,16 +174,16 @@ cvar_t *fs_game;
// local stream used for all file loads
static zipstream_t fs_zipstream;
-static void open_zip_file( file_t *file );
-static void close_zip_file( file_t *file );
-static ssize_t tell_zip_file( file_t *file );
-static ssize_t read_zip_file( file_t *file, void *buf, size_t len );
+static void open_zip_file(file_t *file);
+static void close_zip_file(file_t *file);
+static ssize_t tell_zip_file(file_t *file);
+static ssize_t read_zip_file(file_t *file, void *buf, size_t len);
#endif
// for tracking users of pack_t instance
// allows FS to be restarted while reading something from pack
-static pack_t *pack_get( pack_t *pack );
-static void pack_put( pack_t *pack );
+static pack_t *pack_get(pack_t *pack);
+static void pack_put(pack_t *pack);
/*
@@ -199,12 +199,13 @@ all generated files (savegames, screenshots, demos, config files) will be saved
*/
#ifdef _WIN32
-char *FS_ReplaceSeparators( char *s, int separator ) {
+char *FS_ReplaceSeparators(char *s, int separator)
+{
char *p;
p = s;
- while( *p ) {
- if( *p == '/' || *p == '\\' ) {
+ while (*p) {
+ if (*p == '/' || *p == '\\') {
*p = separator;
}
p++;
@@ -214,12 +215,13 @@ char *FS_ReplaceSeparators( char *s, int separator ) {
}
#endif
-static inline qboolean validate_char( int c ) {
- if( !Q_isprint( c ) )
+static inline qboolean validate_char(int c)
+{
+ if (!Q_isprint(c))
return qfalse;
#ifdef _WIN32
- if( strchr( "<>:\"|?*", c ) )
+ if (strchr("<>:\"|?*", c))
return qfalse;
#endif
@@ -233,9 +235,10 @@ FS_ValidatePath
Checks for bad characters in path (OS specific).
================
*/
-qboolean FS_ValidatePath( const char *s ) {
- for( ; *s; s++ ) {
- if( !validate_char( *s ) )
+qboolean FS_ValidatePath(const char *s)
+{
+ for (; *s; s++) {
+ if (!validate_char(*s))
return qfalse;
}
@@ -260,27 +263,28 @@ May operate in place if in == out.
./foo -> foo
================
*/
-size_t FS_NormalizePath( char *out, const char *in ) {
+size_t FS_NormalizePath(char *out, const char *in)
+{
char *start = out;
uint32_t pre = '/';
- while( 1 ) {
+ while (1) {
int c = *in++;
- if( c == '/' || c == '\\' || c == 0 ) {
- if( ( pre & 0xffffff ) == ( ( '/' << 16 ) | ( '.' << 8 ) | '.' ) ) {
+ if (c == '/' || c == '\\' || c == 0) {
+ if ((pre & 0xffffff) == (('/' << 16) | ('.' << 8) | '.')) {
out -= 4;
- if( out < start ) {
+ if (out < start) {
// can't go past root
out = start;
- if( c == 0 )
+ if (c == 0)
break;
} else {
- while( out > start && *out != '/' )
+ while (out > start && *out != '/')
out--;
- if( c == 0 )
+ if (c == 0)
break;
- if( out > start )
+ if (out > start)
// save the slash
out++;
}
@@ -288,11 +292,11 @@ size_t FS_NormalizePath( char *out, const char *in ) {
continue;
}
- if( ( pre & 0xffff ) == ( ( '/' << 8 ) | '.' ) ) {
+ if ((pre & 0xffff) == (('/' << 8) | '.')) {
// eat the dot
out--;
- if( c == 0 ) {
- if( out > start )
+ if (c == 0) {
+ if (out > start)
// eat the slash
out--;
break;
@@ -301,18 +305,18 @@ size_t FS_NormalizePath( char *out, const char *in ) {
continue;
}
- if( ( pre & 0xff ) == '/' ) {
- if( c == 0 )
+ if ((pre & 0xff) == '/') {
+ if (c == 0)
break;
continue;
}
- if( c == 0 )
+ if (c == 0)
break;
c = '/';
}
- pre = ( pre << 8 ) | c;
+ pre = (pre << 8) | c;
*out++ = c;
}
@@ -328,26 +332,28 @@ Buffer safe version of FS_NormalizePath. Return value >= size signifies
overflow, empty string is stored in output buffer in this case.
================
*/
-size_t FS_NormalizePathBuffer( char *out, const char *in, size_t size ) {
- size_t len = strlen( in );
+size_t FS_NormalizePathBuffer(char *out, const char *in, size_t size)
+{
+ size_t len = strlen(in);
- if( len >= size ) {
- if( size )
+ if (len >= size) {
+ if (size)
*out = 0;
return len;
}
- return FS_NormalizePath( out, in );
+ return FS_NormalizePath(out, in);
}
// =============================================================================
-static file_t *alloc_handle( qhandle_t *f ) {
+static file_t *alloc_handle(qhandle_t *f)
+{
file_t *file;
int i;
- for( i = 0, file = fs_files; i < MAX_FILE_HANDLES; i++, file++ ) {
- if( file->type == FS_FREE ) {
+ for (i = 0, file = fs_files; i < MAX_FILE_HANDLES; i++, file++) {
+ if (file->type == FS_FREE) {
*f = i + 1;
return file;
}
@@ -356,45 +362,48 @@ static file_t *alloc_handle( qhandle_t *f ) {
return NULL;
}
-static file_t *file_for_handle( qhandle_t f ) {
+static file_t *file_for_handle(qhandle_t f)
+{
file_t *file;
- if( f < 1 || f > MAX_FILE_HANDLES )
+ if (f < 1 || f > MAX_FILE_HANDLES)
return NULL;
file = &fs_files[f - 1];
- if( file->type == FS_FREE )
+ if (file->type == FS_FREE)
return NULL;
- if( file->type < FS_FREE || file->type >= FS_BAD )
- Com_Error( ERR_FATAL, "%s: bad file type", __func__ );
+ if (file->type < FS_FREE || file->type >= FS_BAD)
+ Com_Error(ERR_FATAL, "%s: bad file type", __func__);
return file;
}
-static void cleanup_path( char *s ) {
- for( ; *s; s++ ) {
- if( !validate_char( *s ) )
+static void cleanup_path(char *s)
+{
+ for (; *s; s++) {
+ if (!validate_char(*s))
*s = '_';
}
}
// expects a buffer of at least MAX_OSPATH bytes!
-static symlink_t *expand_links( char *buffer, size_t *len_p ) {
+static symlink_t *expand_links(char *buffer, size_t *len_p)
+{
symlink_t *link;
size_t namelen = *len_p;
- for( link = fs_links; link; link = link->next ) {
- if( link->namelen > namelen ) {
+ for (link = fs_links; link; link = link->next) {
+ if (link->namelen > namelen) {
continue;
}
- if( !FS_pathcmpn( buffer, link->name, link->namelen ) ) {
+ if (!FS_pathcmpn(buffer, link->name, link->namelen)) {
size_t newlen = namelen - link->namelen + link->targlen;
- if( newlen < MAX_OSPATH ) {
- memmove( buffer + link->targlen, buffer + link->namelen,
- namelen - link->namelen + 1 );
- memcpy( buffer, link->target, link->targlen );
+ if (newlen < MAX_OSPATH) {
+ memmove(buffer + link->targlen, buffer + link->namelen,
+ namelen - link->namelen + 1);
+ memcpy(buffer, link->target, link->targlen);
}
*len_p = newlen;
@@ -410,13 +419,14 @@ static symlink_t *expand_links( char *buffer, size_t *len_p ) {
FS_Length
================
*/
-ssize_t FS_Length( qhandle_t f ) {
- file_t *file = file_for_handle( f );
+ssize_t FS_Length(qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- if( ( file->mode & FS_MODE_MASK ) == FS_MODE_READ )
+ if ((file->mode & FS_MODE_MASK) == FS_MODE_READ)
return file->length;
return Q_ERR_NOSYS;
@@ -427,17 +437,18 @@ ssize_t FS_Length( qhandle_t f ) {
FS_Tell
============
*/
-ssize_t FS_Tell( qhandle_t f ) {
- file_t *file = file_for_handle( f );
+ssize_t FS_Tell(qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
long ret;
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- ret = ftell( file->fp );
- if( ret == -1 ) {
+ ret = ftell(file->fp);
+ if (ret == -1) {
return Q_ERR(errno);
}
return ret;
@@ -445,10 +456,10 @@ ssize_t FS_Tell( qhandle_t f ) {
return file->length - file->rest_out;
#if USE_ZLIB
case FS_ZIP:
- return tell_zip_file( file );
+ return tell_zip_file(file);
case FS_GZ:
- ret = gztell( file->zfp );
- if( ret == -1 ) {
+ ret = gztell(file->zfp);
+ if (ret == -1) {
return Q_ERR_LIBRARY_ERROR;
}
return ret;
@@ -458,18 +469,19 @@ ssize_t FS_Tell( qhandle_t f ) {
}
}
-static qerror_t seek_pak_file( file_t *file, off_t offset ) {
+static qerror_t seek_pak_file(file_t *file, off_t offset)
+{
packfile_t *entry = file->entry;
long filepos;
- if( offset > entry->filelen )
+ if (offset > entry->filelen)
offset = entry->filelen;
- if( entry->filepos > LONG_MAX - offset )
+ if (entry->filepos > LONG_MAX - offset)
return Q_ERR_INVAL;
filepos = entry->filepos + offset;
- if( fseek( file->fp, filepos, SEEK_SET ) == -1 )
+ if (fseek(file->fp, filepos, SEEK_SET) == -1)
return Q_ERR(errno);
file->rest_out = entry->filelen - offset;
@@ -484,29 +496,30 @@ FS_Seek
Seeks to an absolute position within the file.
============
*/
-qerror_t FS_Seek( qhandle_t f, off_t offset ) {
- file_t *file = file_for_handle( f );
+qerror_t FS_Seek(qhandle_t f, off_t offset)
+{
+ file_t *file = file_for_handle(f);
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- if( offset > LONG_MAX )
+ if (offset > LONG_MAX)
return Q_ERR_INVAL;
- if( offset < 0 )
+ if (offset < 0)
offset = 0;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- if( fseek( file->fp, (long)offset, SEEK_SET ) == -1 ) {
+ if (fseek(file->fp, (long)offset, SEEK_SET) == -1) {
return Q_ERR(errno);
}
return Q_ERR_SUCCESS;
case FS_PAK:
- return seek_pak_file( file, offset );
+ return seek_pak_file(file, offset);
#if USE_ZLIB
case FS_GZ:
- if( gzseek( file->zfp, (z_off_t)offset, SEEK_SET ) == -1 ) {
+ if (gzseek(file->zfp, (z_off_t)offset, SEEK_SET) == -1) {
return Q_ERR(errno);
}
return Q_ERR_SUCCESS;
@@ -524,7 +537,8 @@ Creates any directories needed to store the given filename.
Expects a fully qualified, normalized system path (i.e. with / separators).
============
*/
-qerror_t FS_CreatePath( char *path ) {
+qerror_t FS_CreatePath(char *path)
+{
char *ofs;
int ret;
@@ -532,13 +546,13 @@ qerror_t FS_CreatePath( char *path ) {
#ifdef _WIN32
// check for UNC path and skip "//computer/share/" part
- if( *path == '/' && path[1] == '/' ) {
+ if (*path == '/' && path[1] == '/') {
char *p;
- p = strchr( path + 2, '/' );
- if( p ) {
- p = strchr( p + 1, '/' );
- if( p ) {
+ p = strchr(path + 2, '/');
+ if (p) {
+ p = strchr(p + 1, '/');
+ if (p) {
ofs = p + 1;
}
}
@@ -546,16 +560,16 @@ qerror_t FS_CreatePath( char *path ) {
#endif
// skip leading slash(es)
- for( ; *ofs == '/'; ofs++ )
+ for (; *ofs == '/'; ofs++)
;
- for( ; *ofs; ofs++ ) {
- if( *ofs == '/' ) {
+ for (; *ofs; ofs++) {
+ if (*ofs == '/') {
// create the directory
*ofs = 0;
- ret = Q_mkdir( path );
+ ret = Q_mkdir(path);
*ofs = '/';
- if( ret == -1 && errno != EEXIST ) {
+ if (ret == -1 && errno != EEXIST) {
return Q_ERR(errno);
}
}
@@ -577,19 +591,20 @@ Turns FS_REAL file into FS_GZIP by reopening it through GZIP.
File position is reset to the beginning of file.
============
*/
-qerror_t FS_FilterFile( qhandle_t f ) {
+qerror_t FS_FilterFile(qhandle_t f)
+{
#if USE_ZLIB
- file_t *file = file_for_handle( f );
+ file_t *file = file_for_handle(f);
unsigned mode;
char *modeStr;
void *zfp;
uint32_t magic;
size_t length;
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- switch( file->type ) {
+ switch (file->type) {
case FS_GZ:
return Q_ERR_SUCCESS;
case FS_REAL:
@@ -599,39 +614,39 @@ qerror_t FS_FilterFile( qhandle_t f ) {
}
mode = file->mode & FS_MODE_MASK;
- switch( mode ) {
+ switch (mode) {
case FS_MODE_READ:
// should have at least 10 bytes of header and 8 bytes of trailer
- if( file->length < 18 ) {
+ if (file->length < 18) {
return Q_ERR_FILE_TOO_SMALL;
}
// seek to the header
- if( fseek( file->fp, 0, SEEK_SET ) == -1 ) {
+ if (fseek(file->fp, 0, SEEK_SET) == -1) {
return Q_ERR(errno);
}
// read magic
- if( fread( &magic, 1, 4, file->fp ) != 4 ) {
- return FS_ERR_READ( file->fp );
+ if (fread(&magic, 1, 4, file->fp) != 4) {
+ return FS_ERR_READ(file->fp);
}
// check for gzip header
- if( !CHECK_GZIP_HEADER( magic ) ) {
+ if (!CHECK_GZIP_HEADER(magic)) {
return Q_ERR_INVALID_FORMAT;
}
// seek to the trailer
- if( fseek( file->fp, file->length - 4, SEEK_SET ) == -1 ) {
+ if (fseek(file->fp, file->length - 4, SEEK_SET) == -1) {
return Q_ERR(errno);
}
// read uncompressed length
- if( fread( &magic, 1, 4, file->fp ) != 4 ) {
- return FS_ERR_READ( file->fp );
+ if (fread(&magic, 1, 4, file->fp) != 4) {
+ return FS_ERR_READ(file->fp);
}
- length = LittleLong( magic );
+ length = LittleLong(magic);
modeStr = "rb";
break;
@@ -645,12 +660,12 @@ qerror_t FS_FilterFile( qhandle_t f ) {
}
// rewind back to beginning
- if( fseek( file->fp, 0, SEEK_SET ) == -1 ) {
+ if (fseek(file->fp, 0, SEEK_SET) == -1) {
return Q_ERR(errno);
}
- zfp = gzdopen( fileno( file->fp ), modeStr );
- if( !zfp ) {
+ zfp = gzdopen(fileno(file->fp), modeStr);
+ if (!zfp) {
return Q_ERR_FAILURE;
}
@@ -669,31 +684,32 @@ qerror_t FS_FilterFile( qhandle_t f ) {
FS_FCloseFile
==============
*/
-void FS_FCloseFile( qhandle_t f ) {
- file_t *file = file_for_handle( f );
+void FS_FCloseFile(qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
- if( !file )
+ if (!file)
return;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- fclose( file->fp );
+ fclose(file->fp);
break;
case FS_PAK:
- if( file->unique ) {
- fclose( file->fp );
- pack_put( file->pack );
+ if (file->unique) {
+ fclose(file->fp);
+ pack_put(file->pack);
}
break;
#if USE_ZLIB
case FS_GZ:
- gzclose( file->zfp );
- fclose( file->fp );
+ gzclose(file->zfp);
+ fclose(file->fp);
break;
case FS_ZIP:
- if( file->unique ) {
- close_zip_file( file );
- pack_put( file->pack );
+ if (file->unique) {
+ close_zip_file(file);
+ pack_put(file->pack);
}
break;
#endif
@@ -701,10 +717,11 @@ void FS_FCloseFile( qhandle_t f ) {
break;
}
- memset( file, 0, sizeof( *file ) );
+ memset(file, 0, sizeof(*file));
}
-static inline FILE *fopen_hack( const char *path, const char *mode ) {
+static inline FILE *fopen_hack(const char *path, const char *mode)
+{
#ifndef _GNU_SOURCE
if (mode[0] == 'w' && mode[1] == 'x') {
#ifdef _WIN32
@@ -743,10 +760,11 @@ static inline FILE *fopen_hack( const char *path, const char *mode ) {
}
#endif // _GNU_SOURCE
- return fopen( path, mode );
+ return fopen(path, mode);
}
-static ssize_t open_file_write( file_t *file, const char *name ) {
+static ssize_t open_file_write(file_t *file, const char *name)
+{
char normalized[MAX_OSPATH], fullpath[MAX_OSPATH];
FILE *fp;
char mode_str[8];
@@ -756,42 +774,42 @@ static ssize_t open_file_write( file_t *file, const char *name ) {
qerror_t ret;
// normalize the path
- len = FS_NormalizePathBuffer( normalized, name, sizeof( normalized ) );
- if( len >= sizeof( normalized ) ) {
+ len = FS_NormalizePathBuffer(normalized, name, sizeof(normalized));
+ if (len >= sizeof(normalized)) {
return Q_ERR_NAMETOOLONG;
}
// reject empty paths
- if( len == 0 ) {
+ if (len == 0) {
return Q_ERR_NAMETOOSHORT;
}
// check for bad characters
- if( !FS_ValidatePath( normalized ) ) {
+ if (!FS_ValidatePath(normalized)) {
ret = Q_ERR_INVALID_PATH;
goto fail1;
}
// expand the path
- if( ( file->mode & FS_PATH_MASK ) == FS_PATH_BASE ) {
- if( sys_homedir->string[0] ) {
- len = Q_concat( fullpath, sizeof( fullpath ),
- sys_homedir->string, "/" BASEGAME "/", normalized, NULL );
+ if ((file->mode & FS_PATH_MASK) == FS_PATH_BASE) {
+ if (sys_homedir->string[0]) {
+ len = Q_concat(fullpath, sizeof(fullpath),
+ sys_homedir->string, "/" BASEGAME "/", normalized, NULL);
} else {
- len = Q_concat( fullpath, sizeof( fullpath ),
- sys_basedir->string, "/" BASEGAME "/", normalized, NULL );
+ len = Q_concat(fullpath, sizeof(fullpath),
+ sys_basedir->string, "/" BASEGAME "/", normalized, NULL);
}
} else {
- len = Q_concat( fullpath, sizeof( fullpath ),
- fs_gamedir, "/", normalized, NULL );
+ len = Q_concat(fullpath, sizeof(fullpath),
+ fs_gamedir, "/", normalized, NULL);
}
- if( len >= sizeof( fullpath ) ) {
+ if (len >= sizeof(fullpath)) {
ret = Q_ERR_NAMETOOLONG;
goto fail1;
}
mode = file->mode & FS_MODE_MASK;
- switch( mode ) {
+ switch (mode) {
case FS_MODE_APPEND:
strcpy(mode_str, "a");
break;
@@ -815,59 +833,59 @@ static ssize_t open_file_write( file_t *file, const char *name ) {
if (!(file->mode & FS_FLAG_TEXT))
strcat(mode_str, "b");
- ret = FS_CreatePath( fullpath );
- if( ret ) {
+ ret = FS_CreatePath(fullpath);
+ if (ret) {
goto fail1;
}
- fp = fopen_hack( fullpath, mode_str );
- if( !fp ) {
+ fp = fopen_hack(fullpath, mode_str);
+ if (!fp) {
ret = Q_ERR(errno);
goto fail1;
}
#ifndef _WIN32
// check if this is a regular file
- ret = Sys_GetFileInfo( fp, NULL );
- if( ret ) {
+ ret = Sys_GetFileInfo(fp, NULL);
+ if (ret) {
goto fail2;
}
#endif
- switch( file->mode & FS_BUF_MASK ) {
+ switch (file->mode & FS_BUF_MASK) {
case FS_BUF_NONE:
// make it unbuffered
- setvbuf( fp, NULL, _IONBF, BUFSIZ );
+ setvbuf(fp, NULL, _IONBF, BUFSIZ);
break;
case FS_BUF_LINE:
// make it line buffered
- setvbuf( fp, NULL, _IOLBF, BUFSIZ );
+ setvbuf(fp, NULL, _IOLBF, BUFSIZ);
break;
case FS_BUF_FULL:
// make it fully buffered
- setvbuf( fp, NULL, _IOFBF, BUFSIZ );
+ setvbuf(fp, NULL, _IOFBF, BUFSIZ);
break;
default:
// use default mode (normally fully buffered)
break;
}
- if( mode == FS_MODE_RDWR ) {
+ if (mode == FS_MODE_RDWR) {
// seek to the end of file for appending
- if( fseek( fp, 0, SEEK_END ) == -1 ) {
+ if (fseek(fp, 0, SEEK_END) == -1) {
ret = Q_ERR(errno);
goto fail2;
}
}
-
+
// return current position (non-zero for appending modes)
- pos = ftell( fp );
- if( pos == -1 ) {
+ pos = ftell(fp);
+ if (pos == -1) {
ret = Q_ERR(errno);
goto fail2;
}
- FS_DPrintf( "%s: %s: %lu bytes\n", __func__, fullpath, pos );
+ FS_DPrintf("%s: %s: %lu bytes\n", __func__, fullpath, pos);
file->type = FS_REAL;
file->fp = fp;
@@ -878,51 +896,52 @@ static ssize_t open_file_write( file_t *file, const char *name ) {
return pos;
fail2:
- fclose( fp );
+ fclose(fp);
fail1:
- FS_DPrintf( "%s: %s: %s\n", __func__, normalized, Q_ErrorString( ret ) );
+ FS_DPrintf("%s: %s: %s\n", __func__, normalized, Q_ErrorString(ret));
return ret;
}
#if USE_ZLIB
-static qerror_t check_header_coherency( FILE *fp, packfile_t *entry ) {
+static qerror_t check_header_coherency(FILE *fp, packfile_t *entry)
+{
unsigned flags, comp_mtd;
size_t comp_len, file_len;
size_t name_size, xtra_size;
byte header[ZIP_SIZELOCALHEADER];
size_t ofs;
- if( fseek( fp, (long)entry->filepos, SEEK_SET ) == -1 )
+ if (fseek(fp, (long)entry->filepos, SEEK_SET) == -1)
return Q_ERR(errno);
- if( fread( header, 1, sizeof( header ), fp ) != sizeof( header ) )
- return FS_ERR_READ( fp );
+ if (fread(header, 1, sizeof(header), fp) != sizeof(header))
+ return FS_ERR_READ(fp);
// check the magic
- if( LittleLongMem( &header[0] ) != ZIP_LOCALHEADERMAGIC )
+ if (LittleLongMem(&header[0]) != ZIP_LOCALHEADERMAGIC)
return Q_ERR_NOT_COHERENT;
- flags = LittleShortMem( &header[6] );
- comp_mtd = LittleShortMem( &header[8] );
- comp_len = LittleLongMem( &header[18] );
- file_len = LittleLongMem( &header[22] );
- name_size = LittleShortMem( &header[26] );
- xtra_size = LittleShortMem( &header[28] );
+ flags = LittleShortMem(&header[6]);
+ comp_mtd = LittleShortMem(&header[8]);
+ comp_len = LittleLongMem(&header[18]);
+ file_len = LittleLongMem(&header[22]);
+ name_size = LittleShortMem(&header[26]);
+ xtra_size = LittleShortMem(&header[28]);
- if( comp_mtd != entry->compmtd )
+ if (comp_mtd != entry->compmtd)
return Q_ERR_NOT_COHERENT;
// bit 3 tells that file lengths were not known
// at the time local header was written, so don't check them
- if( ( flags & 8 ) == 0 ) {
- if( comp_len != entry->complen )
+ if ((flags & 8) == 0) {
+ if (comp_len != entry->complen)
return Q_ERR_NOT_COHERENT;
- if( file_len != entry->filelen )
+ if (file_len != entry->filelen)
return Q_ERR_NOT_COHERENT;
}
ofs = ZIP_SIZELOCALHEADER + name_size + xtra_size;
- if( entry->filepos > LONG_MAX - ofs ) {
+ if (entry->filepos > LONG_MAX - ofs) {
return Q_ERR_SPIPE;
}
@@ -931,34 +950,37 @@ static qerror_t check_header_coherency( FILE *fp, packfile_t *entry ) {
return Q_ERR_SUCCESS;
}
-static voidpf FS_zalloc OF(( voidpf opaque, uInt items, uInt size )) {
- return FS_Malloc( items * size );
+static voidpf FS_zalloc OF((voidpf opaque, uInt items, uInt size))
+{
+ return FS_Malloc(items * size);
}
-static void FS_zfree OF(( voidpf opaque, voidpf address )) {
- Z_Free( address );
+static void FS_zfree OF((voidpf opaque, voidpf address))
+{
+ Z_Free(address);
}
-static void open_zip_file( file_t *file ) {
+static void open_zip_file(file_t *file)
+{
zipstream_t *s;
z_streamp z;
- if( file->unique ) {
- s = FS_Malloc( sizeof( *s ) );
- memset( &s->stream, 0, sizeof( s->stream ) );
+ if (file->unique) {
+ s = FS_Malloc(sizeof(*s));
+ memset(&s->stream, 0, sizeof(s->stream));
} else {
s = &fs_zipstream;
}
z = &s->stream;
- if( z->state ) {
+ if (z->state) {
// already initialized, just reset
- inflateReset( z );
+ inflateReset(z);
} else {
z->zalloc = FS_zalloc;
z->zfree = FS_zfree;
- if( inflateInit2( z, -MAX_WBITS ) != Z_OK ) {
- Com_Error( ERR_FATAL, "%s: inflateInit2() failed", __func__ );
+ if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ Com_Error(ERR_FATAL, "%s: inflateInit2() failed", __func__);
}
}
@@ -971,31 +993,34 @@ static void open_zip_file( file_t *file ) {
}
// only called for unique handles
-static void close_zip_file( file_t *file ) {
+static void close_zip_file(file_t *file)
+{
zipstream_t *s = file->zfp;
- inflateEnd( &s->stream );
- Z_Free( s );
-
- fclose( file->fp );
+ inflateEnd(&s->stream);
+ Z_Free(s);
+
+ fclose(file->fp);
}
-static ssize_t tell_zip_file( file_t *file ) {
+static ssize_t tell_zip_file(file_t *file)
+{
zipstream_t *s = file->zfp;
return s->stream.total_out;
}
-static ssize_t read_zip_file( file_t *file, void *buf, size_t len ) {
+static ssize_t read_zip_file(file_t *file, void *buf, size_t len)
+{
zipstream_t *s = file->zfp;
z_streamp z = &s->stream;
size_t block, result;
int ret;
- if( len > file->rest_out ) {
+ if (len > file->rest_out) {
len = file->rest_out;
}
- if( !len ) {
+ if (!len) {
return 0;
}
@@ -1003,21 +1028,21 @@ static ssize_t read_zip_file( file_t *file, void *buf, size_t len ) {
z->avail_out = (uInt)len;
do {
- if( !z->avail_in ) {
- if( !s->rest_in ) {
+ if (!z->avail_in) {
+ if (!s->rest_in) {
break;
}
// fill in the temp buffer
block = ZIP_BUFSIZE;
- if( block > s->rest_in ) {
+ if (block > s->rest_in) {
block = s->rest_in;
}
- result = fread( s->buffer, 1, block, file->fp );
- if( result != block ) {
- file->error = FS_ERR_READ( file->fp );
- if( !result ) {
+ result = fread(s->buffer, 1, block, file->fp);
+ if (result != block) {
+ file->error = FS_ERR_READ(file->fp);
+ if (!result) {
break;
}
}
@@ -1027,23 +1052,23 @@ static ssize_t read_zip_file( file_t *file, void *buf, size_t len ) {
z->avail_in = result;
}
- ret = inflate( z, Z_SYNC_FLUSH );
- if( ret == Z_STREAM_END ) {
+ ret = inflate(z, Z_SYNC_FLUSH);
+ if (ret == Z_STREAM_END) {
break;
}
- if( ret != Z_OK ) {
+ if (ret != Z_OK) {
file->error = Q_ERR_INFLATE_FAILED;
break;
}
- if( file->error ) {
+ if (file->error) {
break;
}
- } while( z->avail_out );
+ } while (z->avail_out);
len -= z->avail_out;
file->rest_out -= len;
- if( file->error && len == 0 ) {
+ if (file->error && len == 0) {
return file->error;
}
@@ -1053,31 +1078,32 @@ static ssize_t read_zip_file( file_t *file, void *buf, size_t len ) {
#endif
// open a new file on the pakfile
-static ssize_t open_from_pak( file_t *file, pack_t *pack, packfile_t *entry, qboolean unique ) {
+static ssize_t open_from_pak(file_t *file, pack_t *pack, packfile_t *entry, qboolean unique)
+{
FILE *fp;
qerror_t ret;
- if( unique ) {
- fp = fopen( pack->filename, "rb" );
- if( !fp ) {
+ if (unique) {
+ fp = fopen(pack->filename, "rb");
+ if (!fp) {
ret = Q_ERR(errno);
goto fail1;
}
} else {
fp = pack->fp;
- clearerr( fp );
+ clearerr(fp);
}
#if USE_ZLIB
- if( pack->type == FS_ZIP && !entry->coherent ) {
- ret = check_header_coherency( fp, entry );
- if( ret ) {
+ if (pack->type == FS_ZIP && !entry->coherent) {
+ ret = check_header_coherency(fp, entry);
+ if (ret) {
goto fail2;
}
}
#endif
- if( fseek( fp, (long)entry->filepos, SEEK_SET ) == -1 ) {
+ if (fseek(fp, (long)entry->filepos, SEEK_SET) == -1) {
ret = Q_ERR(errno);
goto fail2;
}
@@ -1092,9 +1118,9 @@ static ssize_t open_from_pak( file_t *file, pack_t *pack, packfile_t *entry, qbo
file->length = entry->filelen;
#if USE_ZLIB
- if( pack->type == FS_ZIP ) {
- if( entry->compmtd ) {
- open_zip_file( file );
+ if (pack->type == FS_ZIP) {
+ if (entry->compmtd) {
+ open_zip_file(file);
} else {
// stored, just pretend it's a packfile
file->type = FS_PAK;
@@ -1102,29 +1128,30 @@ static ssize_t open_from_pak( file_t *file, pack_t *pack, packfile_t *entry, qbo
}
#endif
- if( unique ) {
+ if (unique) {
// reference source pak
- pack_get( pack );
+ pack_get(pack);
}
- FS_DPrintf( "%s: %s/%s: %"PRIz" bytes\n",
- __func__, pack->filename, entry->name, entry->filelen );
+ FS_DPrintf("%s: %s/%s: %"PRIz" bytes\n",
+ __func__, pack->filename, entry->name, entry->filelen);
return entry->filelen;
fail2:
- if( unique ) {
- fclose( fp );
+ if (unique) {
+ fclose(fp);
}
fail1:
- FS_DPrintf( "%s: %s: %s\n", __func__, entry->name, Q_ErrorString( ret ) );
+ FS_DPrintf("%s: %s: %s\n", __func__, entry->name, Q_ErrorString(ret));
return ret;
}
// Finds the file in the search path.
// Fills file_t and returns file length.
// Used for streaming data out of either a pak file or a seperate file.
-static ssize_t open_file_read( file_t *file, const char *name, qboolean unique ) {
+static ssize_t open_file_read(file_t *file, const char *name, qboolean unique)
+{
char normalized[MAX_OSPATH], fullpath[MAX_OSPATH];
searchpath_t *search;
pack_t *pak;
@@ -1141,74 +1168,74 @@ static ssize_t open_file_read( file_t *file, const char *name, qboolean unique )
#endif
// normalize path
- namelen = FS_NormalizePathBuffer( normalized, name, MAX_OSPATH );
- if( namelen >= MAX_OSPATH ) {
+ namelen = FS_NormalizePathBuffer(normalized, name, MAX_OSPATH);
+ if (namelen >= MAX_OSPATH) {
return Q_ERR_NAMETOOLONG;
}
// expand symlinks
- if( expand_links( normalized, &namelen ) && namelen >= MAX_OSPATH ) {
+ if (expand_links(normalized, &namelen) && namelen >= MAX_OSPATH) {
return Q_ERR_NAMETOOLONG;
}
// reject empty paths
- if( namelen == 0 ) {
+ if (namelen == 0) {
return Q_ERR_NAMETOOSHORT;
}
- hash = FS_HashPath( normalized, 0 );
+ hash = FS_HashPath(normalized, 0);
valid = -1; // not yet checked
// search through the path, one element at a time
- for( search = fs_searchpaths; search; search = search->next ) {
- if( file->mode & FS_PATH_MASK ) {
- if( ( file->mode & search->mode & FS_PATH_MASK ) == 0 ) {
+ for (search = fs_searchpaths; search; search = search->next) {
+ if (file->mode & FS_PATH_MASK) {
+ if ((file->mode & search->mode & FS_PATH_MASK) == 0) {
continue;
}
}
- // is the element a pak file?
- if( search->pack ) {
- if( ( file->mode & FS_TYPE_MASK ) == FS_TYPE_REAL ) {
+ // is the element a pak file?
+ if (search->pack) {
+ if ((file->mode & FS_TYPE_MASK) == FS_TYPE_REAL) {
continue;
}
- // don't bother searching in paks if length exceedes MAX_QPATH
- if( namelen >= MAX_QPATH ) {
+ // don't bother searching in paks if length exceedes MAX_QPATH
+ if (namelen >= MAX_QPATH) {
continue;
}
- // look through all the pak file elements
+ // look through all the pak file elements
pak = search->pack;
- entry = pak->file_hash[ hash & ( pak->hash_size - 1 ) ];
- for( ; entry; entry = entry->hash_next ) {
- if( entry->namelen != namelen ) {
+ entry = pak->file_hash[hash & (pak->hash_size - 1)];
+ for (; entry; entry = entry->hash_next) {
+ if (entry->namelen != namelen) {
continue;
}
#ifdef _DEBUG
fs_count_strcmp++;
#endif
- if( !FS_pathcmp( entry->name, normalized ) ) {
+ if (!FS_pathcmp(entry->name, normalized)) {
// found it!
- return open_from_pak( file, pak, entry, unique );
+ return open_from_pak(file, pak, entry, unique);
}
}
} else {
- if( ( file->mode & FS_TYPE_MASK ) == FS_TYPE_PAK ) {
+ if ((file->mode & FS_TYPE_MASK) == FS_TYPE_PAK) {
continue;
}
- // don't error out immediately if the path is found to be invalid,
- // just stop looking for it in directory tree but continue to search
- // for it in packs, to give broken maps or mods a chance to work
- if( valid == -1 ) {
- valid = FS_ValidatePath( normalized );
+ // don't error out immediately if the path is found to be invalid,
+ // just stop looking for it in directory tree but continue to search
+ // for it in packs, to give broken maps or mods a chance to work
+ if (valid == -1) {
+ valid = FS_ValidatePath(normalized);
}
- if( valid == 0 ) {
+ if (valid == 0) {
continue;
}
- // check a file in the directory tree
- len = Q_concat( fullpath, sizeof( fullpath ),
- search->filename, "/", normalized, NULL );
- if( len >= sizeof( fullpath ) ) {
+ // check a file in the directory tree
+ len = Q_concat(fullpath, sizeof(fullpath),
+ search->filename, "/", normalized, NULL);
+ if (len >= sizeof(fullpath)) {
ret = Q_ERR_NAMETOOLONG;
goto fail;
}
@@ -1216,18 +1243,18 @@ static ssize_t open_file_read( file_t *file, const char *name, qboolean unique )
#ifdef _DEBUG
fs_count_open++;
#endif
- fp = fopen( fullpath, "rb" );
- if( !fp ) {
- if( errno == ENOENT ) {
+ fp = fopen(fullpath, "rb");
+ if (!fp) {
+ if (errno == ENOENT) {
continue;
}
ret = Q_ERR(errno);
goto fail;
}
- ret = Sys_GetFileInfo( fp, &info );
- if( ret ) {
- fclose( fp );
+ ret = Sys_GetFileInfo(fp, &info);
+ if (ret) {
+ fclose(fp);
goto fail;
}
@@ -1237,7 +1264,7 @@ static ssize_t open_file_read( file_t *file, const char *name, qboolean unique )
file->error = Q_ERR_SUCCESS;
file->length = info.size;
- FS_DPrintf( "%s: %s: %"PRIz" bytes\n", __func__, fullpath, info.size );
+ FS_DPrintf("%s: %s: %"PRIz" bytes\n", __func__, fullpath, info.size);
return info.size;
}
}
@@ -1246,24 +1273,25 @@ static ssize_t open_file_read( file_t *file, const char *name, qboolean unique )
ret = valid ? Q_ERR_NOENT : Q_ERR_INVALID_PATH;
fail:
- FS_DPrintf( "%s: %s: %s\n", __func__, normalized, Q_ErrorString( ret ) );
+ FS_DPrintf("%s: %s: %s\n", __func__, normalized, Q_ErrorString(ret));
return ret;
}
-static ssize_t read_pak_file( file_t *file, void *buf, size_t len ) {
+static ssize_t read_pak_file(file_t *file, void *buf, size_t len)
+{
size_t result;
- if( len > file->rest_out ) {
+ if (len > file->rest_out) {
len = file->rest_out;
}
- if( !len ) {
+ if (!len) {
return 0;
}
- result = fread( buf, 1, len, file->fp );
- if( result != len ) {
- file->error = FS_ERR_READ( file->fp );
- if( !result ) {
+ result = fread(buf, 1, len, file->fp);
+ if (result != len) {
+ file->error = FS_ERR_READ(file->fp);
+ if (!result) {
return file->error;
}
}
@@ -1272,13 +1300,14 @@ static ssize_t read_pak_file( file_t *file, void *buf, size_t len ) {
return result;
}
-static ssize_t read_phys_file( file_t *file, void *buf, size_t len ) {
+static ssize_t read_phys_file(file_t *file, void *buf, size_t len)
+{
size_t result;
- result = fread( buf, 1, len, file->fp );
- if( result != len && ferror( file->fp ) ) {
+ result = fread(buf, 1, len, file->fp);
+ if (result != len && ferror(file->fp)) {
file->error = Q_ERR(errno);
- if( !result ) {
+ if (!result) {
return file->error;
}
}
@@ -1291,87 +1320,90 @@ static ssize_t read_phys_file( file_t *file, void *buf, size_t len ) {
FS_Read
=================
*/
-ssize_t FS_Read( void *buf, size_t len, qhandle_t f ) {
- file_t *file = file_for_handle( f );
+ssize_t FS_Read(void *buf, size_t len, qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
#if USE_ZLIB
int ret;
#endif
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- if( ( file->mode & FS_MODE_MASK ) != FS_MODE_READ )
+ if ((file->mode & FS_MODE_MASK) != FS_MODE_READ)
return Q_ERR_INVAL;
// can't continue after error
- if( file->error )
+ if (file->error)
return file->error;
- if( len > SSIZE_MAX )
+ if (len > SSIZE_MAX)
return Q_ERR_INVAL;
- if( len == 0 )
+ if (len == 0)
return 0;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- return read_phys_file( file, buf, len );
+ return read_phys_file(file, buf, len);
case FS_PAK:
- return read_pak_file( file, buf, len );
+ return read_pak_file(file, buf, len);
#if USE_ZLIB
case FS_GZ:
- ret = gzread( file->zfp, buf, len );
- if( ret < 0 ) {
+ ret = gzread(file->zfp, buf, len);
+ if (ret < 0) {
return Q_ERR_LIBRARY_ERROR;
}
return ret;
case FS_ZIP:
- return read_zip_file( file, buf, len );
+ return read_zip_file(file, buf, len);
#endif
default:
return Q_ERR_NOSYS;
}
}
-ssize_t FS_ReadLine( qhandle_t f, char *buffer, size_t size ) {
- file_t *file = file_for_handle( f );
+ssize_t FS_ReadLine(qhandle_t f, char *buffer, size_t size)
+{
+ file_t *file = file_for_handle(f);
char *s;
size_t len;
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- if( ( file->mode & FS_MODE_MASK ) != FS_MODE_READ )
+ if ((file->mode & FS_MODE_MASK) != FS_MODE_READ)
return Q_ERR_INVAL;
- if( file->type != FS_REAL )
+ if (file->type != FS_REAL)
return Q_ERR_NOSYS;
do {
- s = fgets( buffer, size, file->fp );
- if( !s ) {
- return ferror( file->fp ) ? Q_ERR(errno) : 0;
+ s = fgets(buffer, size, file->fp);
+ if (!s) {
+ return ferror(file->fp) ? Q_ERR(errno) : 0;
}
- len = strlen( s );
- } while( len < 2 );
+ len = strlen(s);
+ } while (len < 2);
- s[ len - 1 ] = 0;
+ s[len - 1] = 0;
return len - 1;
}
-void FS_Flush( qhandle_t f ) {
- file_t *file = file_for_handle( f );
+void FS_Flush(qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
- if( !file )
+ if (!file)
return;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- fflush( file->fp );
+ fflush(file->fp);
break;
#if USE_ZLIB
case FS_GZ:
- gzflush( file->zfp, Z_SYNC_FLUSH );
+ gzflush(file->zfp, Z_SYNC_FLUSH);
break;
#endif
default:
@@ -1384,44 +1416,45 @@ void FS_Flush( qhandle_t f ) {
FS_Write
=================
*/
-ssize_t FS_Write( const void *buf, size_t len, qhandle_t f ) {
- file_t *file = file_for_handle( f );
+ssize_t FS_Write(const void *buf, size_t len, qhandle_t f)
+{
+ file_t *file = file_for_handle(f);
size_t result;
- if( !file )
+ if (!file)
return Q_ERR_BADF;
- if( ( file->mode & FS_MODE_MASK ) == FS_MODE_READ )
+ if ((file->mode & FS_MODE_MASK) == FS_MODE_READ)
return Q_ERR_INVAL;
// can't continue after error
- if( file->error )
+ if (file->error)
return file->error;
- if( len > SSIZE_MAX )
+ if (len > SSIZE_MAX)
return Q_ERR_INVAL;
- if( len == 0 )
+ if (len == 0)
return 0;
- switch( file->type ) {
+ switch (file->type) {
case FS_REAL:
- result = fwrite( buf, 1, len, file->fp );
- if( result != len ) {
- file->error = FS_ERR_WRITE( file->fp );
+ result = fwrite(buf, 1, len, file->fp);
+ if (result != len) {
+ file->error = FS_ERR_WRITE(file->fp);
return file->error;
}
break;
#if USE_ZLIB
case FS_GZ:
- if( gzwrite( file->zfp, buf, len ) == 0 ) {
+ if (gzwrite(file->zfp, buf, len) == 0) {
file->error = Q_ERR_LIBRARY_ERROR;
return file->error;
}
break;
#endif
default:
- Com_Error( ERR_FATAL, "%s: bad file type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad file type", __func__);
}
return len;
@@ -1432,36 +1465,37 @@ ssize_t FS_Write( const void *buf, size_t len, qhandle_t f ) {
FS_FOpenFile
============
*/
-ssize_t FS_FOpenFile( const char *name, qhandle_t *f, unsigned mode ) {
+ssize_t FS_FOpenFile(const char *name, qhandle_t *f, unsigned mode)
+{
file_t *file;
qhandle_t handle;
ssize_t ret;
- if( !name || !f ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!name || !f) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
*f = 0;
- if( !fs_searchpaths ) {
+ if (!fs_searchpaths) {
return Q_ERR_AGAIN; // not yet initialized
}
// allocate new file handle
- file = alloc_handle( &handle );
- if( !file ) {
+ file = alloc_handle(&handle);
+ if (!file) {
return Q_ERR_MFILE;
}
file->mode = mode;
- if( ( mode & FS_MODE_MASK ) == FS_MODE_READ ) {
- ret = open_file_read( file, name, qtrue );
+ if ((mode & FS_MODE_MASK) == FS_MODE_READ) {
+ ret = open_file_read(file, name, qtrue);
} else {
- ret = open_file_write( file, name );
+ ret = open_file_write(file, name);
}
- if( ret >= 0 ) {
+ if (ret >= 0) {
*f = handle;
}
@@ -1469,100 +1503,100 @@ ssize_t FS_FOpenFile( const char *name, qhandle_t *f, unsigned mode ) {
}
// reading from outside of source directory is allowed, extension is optional
-static qhandle_t easy_open_read( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext )
+static qhandle_t easy_open_read(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext)
{
ssize_t len;
qhandle_t f;
- if( *name == '/' ) {
+ if (*name == '/') {
// full path is given, ignore directory and extension
- len = Q_strlcpy( buf, name + 1, size );
+ len = Q_strlcpy(buf, name + 1, size);
} else {
// first try without extension
- len = Q_concat( buf, size, dir, name, NULL );
- if( len >= size ) {
- Q_PrintError( "open", Q_ERR_NAMETOOLONG );
+ len = Q_concat(buf, size, dir, name, NULL);
+ if (len >= size) {
+ Q_PrintError("open", Q_ERR_NAMETOOLONG);
return 0;
}
// print normalized path in case of error
- FS_NormalizePath( buf, buf );
+ FS_NormalizePath(buf, buf);
- len = FS_FOpenFile( buf, &f, mode );
- if( f ) {
+ len = FS_FOpenFile(buf, &f, mode);
+ if (f) {
return f; // succeeded
}
- if( len != Q_ERR_NOENT ) {
+ if (len != Q_ERR_NOENT) {
goto fail; // fatal error
}
- if( !COM_CompareExtension( buf, ext ) ) {
+ if (!COM_CompareExtension(buf, ext)) {
goto fail; // name already has the extension
}
// now try to append extension
- len = Q_strlcat( buf, ext, size );
+ len = Q_strlcat(buf, ext, size);
}
- if( len >= size ) {
- Q_PrintError( "open", Q_ERR_NAMETOOLONG );
+ if (len >= size) {
+ Q_PrintError("open", Q_ERR_NAMETOOLONG);
return 0;
}
- len = FS_FOpenFile( buf, &f, mode );
- if( f ) {
+ len = FS_FOpenFile(buf, &f, mode);
+ if (f) {
return f;
}
fail:
- Com_Printf( "Couldn't open %s: %s\n", buf, Q_ErrorString( len ) );
+ Com_Printf("Couldn't open %s: %s\n", buf, Q_ErrorString(len));
return 0;
}
// writing to outside of destination directory is disallowed, extension is forced
-static qhandle_t easy_open_write( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext )
+static qhandle_t easy_open_write(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext)
{
char normalized[MAX_OSPATH];
ssize_t len;
qhandle_t f;
// make it impossible to escape the destination directory when writing files
- len = FS_NormalizePathBuffer( normalized, name, sizeof( normalized ) );
- if( len >= sizeof( normalized ) ) {
- Q_PrintError( "open", Q_ERR_NAMETOOLONG );
+ len = FS_NormalizePathBuffer(normalized, name, sizeof(normalized));
+ if (len >= sizeof(normalized)) {
+ Q_PrintError("open", Q_ERR_NAMETOOLONG);
return 0;
}
// reject empty filenames
- if( len == 0 ) {
- Q_PrintError( "open", Q_ERR_NAMETOOSHORT );
+ if (len == 0) {
+ Q_PrintError("open", Q_ERR_NAMETOOSHORT);
return 0;
}
// replace any bad characters with underscores to make automatic commands happy
- cleanup_path( normalized );
+ cleanup_path(normalized);
// don't append the extension if name already has it
- if( !COM_CompareExtension( normalized, ext ) ) {
- ext = ( mode & FS_FLAG_GZIP ) ? "" : NULL;
+ if (!COM_CompareExtension(normalized, ext)) {
+ ext = (mode & FS_FLAG_GZIP) ? "" : NULL;
}
- len = Q_concat( buf, size, dir, normalized, ext,
- ( mode & FS_FLAG_GZIP ) ? ".gz" : NULL, NULL );
- if( len >= size ) {
- Q_PrintError( "open", Q_ERR_NAMETOOLONG );
+ len = Q_concat(buf, size, dir, normalized, ext,
+ (mode & FS_FLAG_GZIP) ? ".gz" : NULL, NULL);
+ if (len >= size) {
+ Q_PrintError("open", Q_ERR_NAMETOOLONG);
return 0;
}
- len = FS_FOpenFile( buf, &f, mode );
- if( !f ) {
+ len = FS_FOpenFile(buf, &f, mode);
+ if (!f) {
goto fail1;
}
- if( mode & FS_FLAG_GZIP ) {
- len = FS_FilterFile( f );
- if( len ) {
+ if (mode & FS_FLAG_GZIP) {
+ len = FS_FilterFile(f);
+ if (len) {
goto fail2;
}
}
@@ -1570,9 +1604,9 @@ static qhandle_t easy_open_write( char *buf, size_t size, unsigned mode,
return f;
fail2:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
fail1:
- Com_EPrintf( "Couldn't open %s: %s\n", buf, Q_ErrorString( len ) );
+ Com_EPrintf("Couldn't open %s: %s\n", buf, Q_ErrorString(len));
return 0;
}
@@ -1585,14 +1619,14 @@ the arguments, checks for path buffer overflow, and attempts
to open the file, printing an error message in case of failure.
============
*/
-qhandle_t FS_EasyOpenFile( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext )
+qhandle_t FS_EasyOpenFile(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext)
{
- if( ( mode & FS_MODE_MASK ) == FS_MODE_READ ) {
- return easy_open_read( buf, size, mode, dir, name, ext );
+ if ((mode & FS_MODE_MASK) == FS_MODE_READ) {
+ return easy_open_read(buf, size, mode, dir, name, ext);
}
- return easy_open_write( buf, size, mode, dir, name, ext );
+ return easy_open_write(buf, size, mode, dir, name, ext);
}
/*
@@ -1603,65 +1637,66 @@ opens non-unique file handle as an optimization
a NULL buffer will just return the file length without loading
============
*/
-ssize_t FS_LoadFileEx( const char *path, void **buffer, unsigned flags, memtag_t tag ) {
+ssize_t FS_LoadFileEx(const char *path, void **buffer, unsigned flags, memtag_t tag)
+{
file_t *file;
qhandle_t f;
byte *buf;
ssize_t len, read;
- if( !path ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!path) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
- if( buffer ) {
+ if (buffer) {
*buffer = NULL;
}
- if( !fs_searchpaths ) {
+ if (!fs_searchpaths) {
return Q_ERR_AGAIN; // not yet initialized
}
// allocate new file handle
- file = alloc_handle( &f );
- if( !file ) {
+ file = alloc_handle(&f);
+ if (!file) {
return Q_ERR_MFILE;
}
- file->mode = ( flags & ~FS_MODE_MASK ) | FS_MODE_READ;
+ file->mode = (flags & ~FS_MODE_MASK) | FS_MODE_READ;
// look for it in the filesystem or pack files
- len = open_file_read( file, path, qfalse );
- if( len < 0 ) {
+ len = open_file_read(file, path, qfalse);
+ if (len < 0) {
return len;
}
// NULL buffer just checks for file existence
- if( !buffer ) {
+ if (!buffer) {
goto done;
}
// sanity check file size
- if( len > MAX_LOADFILE ) {
+ if (len > MAX_LOADFILE) {
len = Q_ERR_FBIG;
goto done;
}
// allocate chunk of memory, +1 for NUL
- buf = Z_TagMalloc( len + 1, tag );
+ buf = Z_TagMalloc(len + 1, tag);
// read entire file
- read = FS_Read( buf, len, f );
- if( read != len ) {
+ read = FS_Read(buf, len, f);
+ if (read != len) {
len = read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
- Z_Free( buf );
+ Z_Free(buf);
goto done;
}
-
+
*buffer = buf;
buf[len] = 0;
done:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return len;
}
@@ -1670,21 +1705,22 @@ done:
FS_WriteFile
================
*/
-qerror_t FS_WriteFile( const char *path, const void *data, size_t len ) {
+qerror_t FS_WriteFile(const char *path, const void *data, size_t len)
+{
qhandle_t f;
ssize_t write;
qerror_t ret;
// TODO: write to temp file perhaps?
- write = FS_FOpenFile( path, &f, FS_MODE_WRITE );
- if( !f ) {
+ write = FS_FOpenFile(path, &f, FS_MODE_WRITE);
+ if (!f) {
return write;
}
- write = FS_Write( data, len, f );
+ write = FS_Write(data, len, f);
ret = write == len ? Q_ERR_SUCCESS : write < 0 ? write : Q_ERR_FAILURE;
-
- FS_FCloseFile( f );
+
+ FS_FCloseFile(f);
return ret;
}
@@ -1697,27 +1733,27 @@ the arguments, checks for path buffer overflow, and attempts
to write the file, printing an error message in case of failure.
============
*/
-qboolean FS_EasyWriteFile( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext,
- const void *data, size_t len )
+qboolean FS_EasyWriteFile(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext,
+ const void *data, size_t len)
{
qhandle_t f;
ssize_t write;
qerror_t ret;
// TODO: write to temp file perhaps?
- f = easy_open_write( buf, size, mode, dir, name, ext );
- if( !f ) {
+ f = easy_open_write(buf, size, mode, dir, name, ext);
+ if (!f) {
return qfalse;
}
- write = FS_Write( data, len, f );
+ write = FS_Write(data, len, f);
ret = write == len ? Q_ERR_SUCCESS : write < 0 ? write : Q_ERR_FAILURE;
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- if( ret ) {
- Com_EPrintf( "Couldn't write %s: %s\n", buf, Q_ErrorString( ret ) );
+ if (ret) {
+ Com_EPrintf("Couldn't write %s: %s\n", buf, Q_ErrorString(ret));
return qfalse;
}
@@ -1731,38 +1767,39 @@ qboolean FS_EasyWriteFile( char *buf, size_t size, unsigned mode,
FS_RenameFile
================
*/
-qerror_t FS_RenameFile( const char *from, const char *to ) {
+qerror_t FS_RenameFile(const char *from, const char *to)
+{
char normalized[MAX_OSPATH];
char frompath[MAX_OSPATH];
char topath[MAX_OSPATH];
size_t len;
// check from
- len = FS_NormalizePathBuffer( normalized, from, sizeof( normalized ) );
- if( len >= sizeof( normalized ) )
+ len = FS_NormalizePathBuffer(normalized, from, sizeof(normalized));
+ if (len >= sizeof(normalized))
return Q_ERR_NAMETOOLONG;
- if( !FS_ValidatePath( normalized ) )
+ if (!FS_ValidatePath(normalized))
return Q_ERR_INVALID_PATH;
- len = Q_concat( frompath, sizeof( frompath ), fs_gamedir, "/", normalized, NULL );
- if( len >= sizeof( frompath ) )
+ len = Q_concat(frompath, sizeof(frompath), fs_gamedir, "/", normalized, NULL);
+ if (len >= sizeof(frompath))
return Q_ERR_NAMETOOLONG;
// check to
- len = FS_NormalizePathBuffer( normalized, to, sizeof( normalized ) );
- if( len >= sizeof( normalized ) )
+ len = FS_NormalizePathBuffer(normalized, to, sizeof(normalized));
+ if (len >= sizeof(normalized))
return Q_ERR_NAMETOOLONG;
- if( !FS_ValidatePath( normalized ) )
+ if (!FS_ValidatePath(normalized))
return Q_ERR_INVALID_PATH;
- len = Q_concat( topath, sizeof( topath ), fs_gamedir, "/", normalized, NULL );
- if( len >= sizeof( topath ) )
+ len = Q_concat(topath, sizeof(topath), fs_gamedir, "/", normalized, NULL);
+ if (len >= sizeof(topath))
return Q_ERR_NAMETOOLONG;
// rename it
- if( rename( frompath, topath ) )
+ if (rename(frompath, topath))
return Q_ERR(errno);
return Q_ERR_SUCCESS;
@@ -1775,87 +1812,92 @@ qerror_t FS_RenameFile( const char *from, const char *to ) {
FS_FPrintf
================
*/
-ssize_t FS_FPrintf( qhandle_t f, const char *format, ... ) {
+ssize_t FS_FPrintf(qhandle_t f, const char *format, ...)
+{
va_list argptr;
char string[MAXPRINTMSG];
size_t len;
- va_start( argptr, format );
- len = Q_vsnprintf( string, sizeof( string ), format, argptr );
- va_end( argptr );
+ va_start(argptr, format);
+ len = Q_vsnprintf(string, sizeof(string), format, argptr);
+ va_end(argptr);
- if( len >= sizeof( string ) ) {
+ if (len >= sizeof(string)) {
return Q_ERR_STRING_TRUNCATED;
}
- return FS_Write( string, len, f );
+ return FS_Write(string, len, f);
}
// references pack_t instance
-static pack_t *pack_get( pack_t *pack ) {
+static pack_t *pack_get(pack_t *pack)
+{
pack->refcount++;
return pack;
}
// dereferences pack_t instance
-static void pack_put( pack_t *pack ) {
- if( !pack ) {
+static void pack_put(pack_t *pack)
+{
+ if (!pack) {
return;
}
- if( !pack->refcount ) {
- Com_Error( ERR_FATAL, "%s: refcount already zero", __func__ );
+ if (!pack->refcount) {
+ Com_Error(ERR_FATAL, "%s: refcount already zero", __func__);
}
- if( !--pack->refcount ) {
- FS_DPrintf( "Freeing packfile %s\n", pack->filename );
- fclose( pack->fp );
- Z_Free( pack );
+ if (!--pack->refcount) {
+ FS_DPrintf("Freeing packfile %s\n", pack->filename);
+ fclose(pack->fp);
+ Z_Free(pack);
}
}
// allocates pack_t instance along with filenames and hashes in one chunk of memory
-static pack_t *pack_alloc( FILE *fp, filetype_t type, const char *name,
- unsigned num_files, size_t names_len )
+static pack_t *pack_alloc(FILE *fp, filetype_t type, const char *name,
+ unsigned num_files, size_t names_len)
{
pack_t *pack;
unsigned hash_size;
size_t len;
- hash_size = npot32( num_files / 3 );
+ hash_size = npot32(num_files / 3);
- len = strlen( name ) + 1;
- pack = FS_Malloc( sizeof( pack_t ) +
- num_files * sizeof( packfile_t ) +
- hash_size * sizeof( packfile_t * ) +
- len + names_len );
+ len = strlen(name) + 1;
+ pack = FS_Malloc(sizeof(pack_t) +
+ num_files * sizeof(packfile_t) +
+ hash_size * sizeof(packfile_t *) +
+ len + names_len);
pack->type = type;
pack->refcount = 0;
pack->fp = fp;
pack->num_files = num_files;
pack->hash_size = hash_size;
- pack->files = ( packfile_t * )( pack + 1 );
- pack->file_hash = ( packfile_t ** )( pack->files + num_files );
- pack->filename = ( char * )( pack->file_hash + hash_size );
+ pack->files = (packfile_t *)(pack + 1);
+ pack->file_hash = (packfile_t **)(pack->files + num_files);
+ pack->filename = (char *)(pack->file_hash + hash_size);
pack->names = pack->filename + len;
- memcpy( pack->filename, name, len );
- memset( pack->file_hash, 0, hash_size * sizeof( packfile_t * ) );
+ memcpy(pack->filename, name, len);
+ memset(pack->file_hash, 0, hash_size * sizeof(packfile_t *));
return pack;
}
// normalizes and inserts the filename into hash table
-static void pack_hash_file( pack_t *pack, packfile_t *file ) {
+static void pack_hash_file(pack_t *pack, packfile_t *file)
+{
unsigned hash;
- file->namelen = FS_NormalizePath( file->name, file->name );
+ file->namelen = FS_NormalizePath(file->name, file->name);
- hash = FS_HashPath( file->name, pack->hash_size );
+ hash = FS_HashPath(file->name, pack->hash_size);
file->hash_next = pack->file_hash[hash];
pack->file_hash[hash] = file;
}
// Loads the header and directory, adding the files at the beginning
// of the list so they override previous pack files.
-static pack_t *load_pak_file( const char *packfile ) {
+static pack_t *load_pak_file(const char *packfile)
+{
dpackheader_t header;
packfile_t *file;
dpackfile_t *dfile;
@@ -1866,118 +1908,119 @@ static pack_t *load_pak_file( const char *packfile ) {
FILE *fp;
dpackfile_t info[MAX_FILES_IN_PACK];
- fp = fopen( packfile, "rb" );
- if( !fp ) {
- Com_Printf( "Couldn't open %s: %s\n", packfile, strerror( errno ) );
+ fp = fopen(packfile, "rb");
+ if (!fp) {
+ Com_Printf("Couldn't open %s: %s\n", packfile, strerror(errno));
return NULL;
}
- if( fread( &header, 1, sizeof( header ), fp ) != sizeof( header ) ) {
- Com_Printf( "Reading header failed on %s\n", packfile );
+ if (fread(&header, 1, sizeof(header), fp) != sizeof(header)) {
+ Com_Printf("Reading header failed on %s\n", packfile);
goto fail;
}
- if( LittleLong( header.ident ) != IDPAKHEADER ) {
- Com_Printf( "%s is not a 'PACK' file\n", packfile );
+ if (LittleLong(header.ident) != IDPAKHEADER) {
+ Com_Printf("%s is not a 'PACK' file\n", packfile);
goto fail;
}
- header.dirlen = LittleLong( header.dirlen );
- if( header.dirlen > LONG_MAX || header.dirlen % sizeof( dpackfile_t ) ) {
- Com_Printf( "%s has bad directory length\n", packfile );
+ header.dirlen = LittleLong(header.dirlen);
+ if (header.dirlen > LONG_MAX || header.dirlen % sizeof(dpackfile_t)) {
+ Com_Printf("%s has bad directory length\n", packfile);
goto fail;
}
- num_files = header.dirlen / sizeof( dpackfile_t );
- if( num_files < 1 ) {
- Com_Printf( "%s has no files\n", packfile );
+ num_files = header.dirlen / sizeof(dpackfile_t);
+ if (num_files < 1) {
+ Com_Printf("%s has no files\n", packfile);
goto fail;
}
- if( num_files > MAX_FILES_IN_PACK ) {
- Com_Printf( "%s has too many files: %u > %u\n", packfile, num_files, MAX_FILES_IN_PACK );
+ if (num_files > MAX_FILES_IN_PACK) {
+ Com_Printf("%s has too many files: %u > %u\n", packfile, num_files, MAX_FILES_IN_PACK);
goto fail;
}
- header.dirofs = LittleLong( header.dirofs );
- if( header.dirofs > LONG_MAX - header.dirlen ) {
- Com_Printf( "%s has bad directory offset\n", packfile );
+ header.dirofs = LittleLong(header.dirofs);
+ if (header.dirofs > LONG_MAX - header.dirlen) {
+ Com_Printf("%s has bad directory offset\n", packfile);
goto fail;
}
- if( fseek( fp, (long)header.dirofs, SEEK_SET ) ) {
- Com_Printf( "Seeking to directory failed on %s\n", packfile );
+ if (fseek(fp, (long)header.dirofs, SEEK_SET)) {
+ Com_Printf("Seeking to directory failed on %s\n", packfile);
goto fail;
}
- if( fread( info, 1, header.dirlen, fp ) != header.dirlen ) {
- Com_Printf( "Reading directory failed on %s\n", packfile );
+ if (fread(info, 1, header.dirlen, fp) != header.dirlen) {
+ Com_Printf("Reading directory failed on %s\n", packfile);
goto fail;
}
names_len = 0;
- for( i = 0, dfile = info; i < num_files; i++, dfile++ ) {
- dfile->filepos = LittleLong( dfile->filepos );
- dfile->filelen = LittleLong( dfile->filelen );
- if( dfile->filelen > LONG_MAX || dfile->filepos > LONG_MAX - dfile->filelen ) {
- Com_Printf( "%s has bad directory structure\n", packfile );
+ for (i = 0, dfile = info; i < num_files; i++, dfile++) {
+ dfile->filepos = LittleLong(dfile->filepos);
+ dfile->filelen = LittleLong(dfile->filelen);
+ if (dfile->filelen > LONG_MAX || dfile->filepos > LONG_MAX - dfile->filelen) {
+ Com_Printf("%s has bad directory structure\n", packfile);
goto fail;
}
- dfile->name[sizeof( dfile->name ) - 1] = 0;
- names_len += strlen( dfile->name ) + 1;
+ dfile->name[sizeof(dfile->name) - 1] = 0;
+ names_len += strlen(dfile->name) + 1;
}
// allocate the pack
- pack = pack_alloc( fp, FS_PAK, packfile, num_files, names_len );
+ pack = pack_alloc(fp, FS_PAK, packfile, num_files, names_len);
// parse the directory
file = pack->files;
name = pack->names;
- for( i = 0, dfile = info; i < num_files; i++, dfile++ ) {
- len = strlen( dfile->name ) + 1;
+ for (i = 0, dfile = info; i < num_files; i++, dfile++) {
+ len = strlen(dfile->name) + 1;
- file->name = memcpy( name, dfile->name, len );
+ file->name = memcpy(name, dfile->name, len);
name += len;
file->filepos = dfile->filepos;
file->filelen = dfile->filelen;
file->coherent = qtrue;
- pack_hash_file( pack, file );
+ pack_hash_file(pack, file);
file++;
}
- FS_DPrintf( "%s: %u files, %u hash\n",
- packfile, pack->num_files, pack->hash_size );
+ FS_DPrintf("%s: %u files, %u hash\n",
+ packfile, pack->num_files, pack->hash_size);
return pack;
fail:
- fclose( fp );
+ fclose(fp);
return NULL;
}
#if USE_ZLIB
// Locate the central directory of a zipfile (at the end, just before the global comment)
-static size_t search_central_header( FILE *fp ) {
+static size_t search_central_header(FILE *fp)
+{
size_t file_size, back_read;
size_t max_back = 0xffff; // maximum size of global comment
byte buf[ZIP_BUFREADCOMMENT + 4];
long ret;
- if( fseek( fp, 0, SEEK_END ) == -1 )
+ if (fseek(fp, 0, SEEK_END) == -1)
return 0;
- ret = ftell( fp );
- if( ret == -1 )
+ ret = ftell(fp);
+ if (ret == -1)
return 0;
file_size = (size_t)ret;
- if( max_back > file_size )
+ if (max_back > file_size)
max_back = file_size;
back_read = 4;
- while( back_read < max_back ) {
+ while (back_read < max_back) {
size_t i, read_size, read_pos;
- if( back_read + ZIP_BUFREADCOMMENT > max_back )
+ if (back_read + ZIP_BUFREADCOMMENT > max_back)
back_read = max_back;
else
back_read += ZIP_BUFREADCOMMENT;
@@ -1985,27 +2028,28 @@ static size_t search_central_header( FILE *fp ) {
read_pos = file_size - back_read;
read_size = back_read;
- if( read_size > ZIP_BUFREADCOMMENT + 4 )
+ if (read_size > ZIP_BUFREADCOMMENT + 4)
read_size = ZIP_BUFREADCOMMENT + 4;
- if( fseek( fp, (long)read_pos, SEEK_SET ) == -1 )
+ if (fseek(fp, (long)read_pos, SEEK_SET) == -1)
break;
- if( fread( buf, 1, read_size, fp ) != read_size )
+ if (fread(buf, 1, read_size, fp) != read_size)
break;
i = read_size - 4;
do {
// check the magic
- if( LittleLongMem( buf + i ) == ZIP_ENDHEADERMAGIC )
+ if (LittleLongMem(buf + i) == ZIP_ENDHEADERMAGIC)
return read_pos + i;
- } while( i-- );
+ } while (i--);
}
return 0;
}
// Get Info about the current file in the zipfile, with internal only info
-static size_t get_file_info( FILE *fp, size_t pos, packfile_t *file, size_t *len, size_t remaining ) {
+static size_t get_file_info(FILE *fp, size_t pos, packfile_t *file, size_t *len, size_t remaining)
+{
size_t name_size, xtra_size, comm_size;
size_t comp_len, file_len, file_pos;
unsigned comp_mtd;
@@ -2013,60 +2057,60 @@ static size_t get_file_info( FILE *fp, size_t pos, packfile_t *file, size_t *len
*len = 0;
- if( pos > LONG_MAX )
+ if (pos > LONG_MAX)
return 0;
- if( fseek( fp, (long)pos, SEEK_SET ) == -1 )
+ if (fseek(fp, (long)pos, SEEK_SET) == -1)
return 0;
- if( fread( header, 1, sizeof( header ), fp ) != sizeof( header ) )
+ if (fread(header, 1, sizeof(header), fp) != sizeof(header))
return 0;
// check the magic
- if( LittleLongMem( &header[0] ) != ZIP_CENTRALHEADERMAGIC )
+ if (LittleLongMem(&header[0]) != ZIP_CENTRALHEADERMAGIC)
return 0;
- comp_mtd = LittleShortMem( &header[10] );
- comp_len = LittleLongMem( &header[20] );
- file_len = LittleLongMem( &header[24] );
- name_size = LittleShortMem( &header[28] );
- xtra_size = LittleShortMem( &header[30] );
- comm_size = LittleShortMem( &header[32] );
- file_pos = LittleLongMem( &header[42] );
+ comp_mtd = LittleShortMem(&header[10]);
+ comp_len = LittleLongMem(&header[20]);
+ file_len = LittleLongMem(&header[24]);
+ name_size = LittleShortMem(&header[28]);
+ xtra_size = LittleShortMem(&header[30]);
+ comm_size = LittleShortMem(&header[32]);
+ file_pos = LittleLongMem(&header[42]);
- if( file_len > LONG_MAX )
+ if (file_len > LONG_MAX)
return 0;
- if( comp_len > LONG_MAX || file_pos > LONG_MAX - comp_len )
+ if (comp_len > LONG_MAX || file_pos > LONG_MAX - comp_len)
return 0;
- if( !file_len || !comp_len ) {
+ if (!file_len || !comp_len) {
goto skip; // skip directories and empty files
}
- if( !comp_mtd ) {
- if( file_len != comp_len ) {
- FS_DPrintf( "%s: skipping file stored with file_len != comp_len\n", __func__ );
+ if (!comp_mtd) {
+ if (file_len != comp_len) {
+ FS_DPrintf("%s: skipping file stored with file_len != comp_len\n", __func__);
goto skip;
}
- } else if( comp_mtd != Z_DEFLATED ) {
- FS_DPrintf( "%s: skipping file compressed with unknown method\n", __func__ );
+ } else if (comp_mtd != Z_DEFLATED) {
+ FS_DPrintf("%s: skipping file compressed with unknown method\n", __func__);
goto skip;
}
- if( !name_size ) {
- FS_DPrintf( "%s: skipping file with empty name\n", __func__ );
+ if (!name_size) {
+ FS_DPrintf("%s: skipping file with empty name\n", __func__);
goto skip;
}
- if( name_size >= MAX_QPATH ) {
- FS_DPrintf( "%s: skipping file with oversize name\n", __func__ );
+ if (name_size >= MAX_QPATH) {
+ FS_DPrintf("%s: skipping file with oversize name\n", __func__);
goto skip;
}
// fill in the info
- if( file ) {
- if( name_size >= remaining )
+ if (file) {
+ if (name_size >= remaining)
return 0; // directory changed on disk?
file->compmtd = comp_mtd;
file->complen = comp_len;
file->filelen = file_len;
file->filepos = file_pos;
- if( fread( file->name, 1, name_size, fp ) != name_size )
+ if (fread(file->name, 1, name_size, fp) != name_size)
return 0;
file->name[name_size] = 0;
}
@@ -2077,7 +2121,8 @@ skip:
return ZIP_SIZECENTRALDIRITEM + name_size + xtra_size + comm_size;
}
-static pack_t *load_zip_file( const char *packfile ) {
+static pack_t *load_zip_file(const char *packfile)
+{
packfile_t *file;
char *name;
size_t len, names_len;
@@ -2088,105 +2133,105 @@ static pack_t *load_zip_file( const char *packfile ) {
FILE *fp;
byte header[ZIP_SIZECENTRALHEADER];
- fp = fopen( packfile, "rb" );
- if( !fp ) {
- Com_Printf( "Couldn't open %s: %s\n", packfile, strerror( errno ) );
+ fp = fopen(packfile, "rb");
+ if (!fp) {
+ Com_Printf("Couldn't open %s: %s\n", packfile, strerror(errno));
return NULL;
}
- header_pos = search_central_header( fp );
- if( !header_pos ) {
- Com_Printf( "No central header found in %s\n", packfile );
+ header_pos = search_central_header(fp);
+ if (!header_pos) {
+ Com_Printf("No central header found in %s\n", packfile);
goto fail2;
}
- if( fseek( fp, (long)header_pos, SEEK_SET ) == -1 ) {
- Com_Printf( "Couldn't seek to central header in %s\n", packfile );
+ if (fseek(fp, (long)header_pos, SEEK_SET) == -1) {
+ Com_Printf("Couldn't seek to central header in %s\n", packfile);
goto fail2;
}
- if( fread( header, 1, sizeof( header ), fp ) != sizeof( header ) ) {
- Com_Printf( "Reading central header failed on %s\n", packfile );
+ if (fread(header, 1, sizeof(header), fp) != sizeof(header)) {
+ Com_Printf("Reading central header failed on %s\n", packfile);
goto fail2;
}
- num_disk = LittleShortMem( &header[4] );
- num_disk_cd = LittleShortMem( &header[6] );
- num_files = LittleShortMem( &header[8] );
- num_files_cd = LittleShortMem( &header[10] );
- if( num_files_cd != num_files || num_disk_cd != 0 || num_disk != 0 ) {
- Com_Printf( "%s is an unsupported multi-part archive\n", packfile );
+ num_disk = LittleShortMem(&header[4]);
+ num_disk_cd = LittleShortMem(&header[6]);
+ num_files = LittleShortMem(&header[8]);
+ num_files_cd = LittleShortMem(&header[10]);
+ if (num_files_cd != num_files || num_disk_cd != 0 || num_disk != 0) {
+ Com_Printf("%s is an unsupported multi-part archive\n", packfile);
goto fail2;
}
- if( num_files < 1 ) {
- Com_Printf( "%s has no files\n", packfile );
+ if (num_files < 1) {
+ Com_Printf("%s has no files\n", packfile);
goto fail2;
}
- if( num_files > ZIP_MAXFILES ) {
- Com_Printf( "%s has too many files: %u > %u\n", packfile, num_files, ZIP_MAXFILES );
+ if (num_files > ZIP_MAXFILES) {
+ Com_Printf("%s has too many files: %u > %u\n", packfile, num_files, ZIP_MAXFILES);
goto fail2;
}
- central_size = LittleLongMem( &header[12] );
- central_ofs = LittleLongMem( &header[16] );
+ central_size = LittleLongMem(&header[12]);
+ central_ofs = LittleLongMem(&header[16]);
central_end = central_ofs + central_size;
- if( central_end > header_pos || central_end < central_ofs ) {
- Com_Printf( "%s has bad central directory offset\n", packfile );
+ if (central_end > header_pos || central_end < central_ofs) {
+ Com_Printf("%s has bad central directory offset\n", packfile);
goto fail2;
}
// non-zero for sfx?
extra_bytes = header_pos - central_end;
- if( extra_bytes ) {
- Com_Printf( "%s has %"PRIz" extra bytes at the beginning, funny sfx archive?\n",
- packfile, extra_bytes );
+ if (extra_bytes) {
+ Com_Printf("%s has %"PRIz" extra bytes at the beginning, funny sfx archive?\n",
+ packfile, extra_bytes);
}
// parse the directory
num_files = 0;
names_len = 0;
header_pos = central_ofs + extra_bytes;
- for( i = 0; i < num_files_cd; i++ ) {
- ofs = get_file_info( fp, header_pos, NULL, &len, 0 );
- if( !ofs ) {
- Com_Printf( "%s has bad central directory structure (pass %d)\n", packfile, 1 );
+ for (i = 0; i < num_files_cd; i++) {
+ ofs = get_file_info(fp, header_pos, NULL, &len, 0);
+ if (!ofs) {
+ Com_Printf("%s has bad central directory structure (pass %d)\n", packfile, 1);
goto fail2;
}
header_pos += ofs;
- if( len ) {
+ if (len) {
names_len += len;
num_files++;
}
}
- if( !num_files ) {
- Com_Printf( "%s has no valid files\n", packfile );
+ if (!num_files) {
+ Com_Printf("%s has no valid files\n", packfile);
goto fail2;
}
// allocate the pack
- pack = pack_alloc( fp, FS_ZIP, packfile, num_files, names_len );
+ pack = pack_alloc(fp, FS_ZIP, packfile, num_files, names_len);
// parse the directory
file = pack->files;
name = pack->names;
header_pos = central_ofs + extra_bytes;
- for( i = 0; i < num_files_cd; i++ ) {
- if( !num_files )
+ for (i = 0; i < num_files_cd; i++) {
+ if (!num_files)
break;
file->name = name;
- ofs = get_file_info( fp, header_pos, file, &len, names_len );
- if( !ofs ) {
- Com_Printf( "%s has bad central directory structure (pass %d)\n", packfile, 2 );
+ ofs = get_file_info(fp, header_pos, file, &len, names_len);
+ if (!ofs) {
+ Com_Printf("%s has bad central directory structure (pass %d)\n", packfile, 2);
goto fail1; // directory changed on disk?
}
header_pos += ofs;
- if( len ) {
+ if (len) {
// fix absolute position
file->filepos += extra_bytes;
file->coherent = qfalse;
- pack_hash_file( pack, file );
+ pack_hash_file(pack, file);
// advance pointers, decrement counters
file++;
@@ -2197,15 +2242,15 @@ static pack_t *load_zip_file( const char *packfile ) {
}
}
- FS_DPrintf( "%s: %u files, %u skipped, %u hash\n",
- packfile, pack->num_files, num_files_cd - pack->num_files, pack->hash_size );
+ FS_DPrintf("%s: %u files, %u skipped, %u hash\n",
+ packfile, pack->num_files, num_files_cd - pack->num_files, pack->hash_size);
return pack;
fail1:
- Z_Free( pack );
+ Z_Free(pack);
fail2:
- fclose( fp );
+ fclose(fp);
return NULL;
}
#endif
@@ -2213,35 +2258,37 @@ fail2:
// this is complicated as we need pakXX.pak loaded first,
// sorted in numerical order, then the rest of the paks in
// alphabetical order, e.g. pak0.pak, pak2.pak, pak17.pak, abc.pak...
-static int QDECL pakcmp( const void *p1, const void *p2 ) {
- char *s1 = *( char ** )p1;
- char *s2 = *( char ** )p2;
-
- if( !Q_stricmpn( s1, "pak", 3 ) ) {
- if( !Q_stricmpn( s2, "pak", 3 ) ) {
- unsigned long n1 = strtoul( s1 + 3, &s1, 10 );
- unsigned long n2 = strtoul( s2 + 3, &s2, 10 );
- if( n1 > n2 ) {
+static int QDECL pakcmp(const void *p1, const void *p2)
+{
+ char *s1 = *(char **)p1;
+ char *s2 = *(char **)p2;
+
+ if (!Q_stricmpn(s1, "pak", 3)) {
+ if (!Q_stricmpn(s2, "pak", 3)) {
+ unsigned long n1 = strtoul(s1 + 3, &s1, 10);
+ unsigned long n2 = strtoul(s2 + 3, &s2, 10);
+ if (n1 > n2) {
return 1;
}
- if( n1 < n2 ) {
+ if (n1 < n2) {
return -1;
}
goto alphacmp;
}
return -1;
}
- if( !Q_stricmpn( s2, "pak", 3 ) ) {
+ if (!Q_stricmpn(s2, "pak", 3)) {
return 1;
}
alphacmp:
- return Q_stricmp( s1, s2 );
+ return Q_stricmp(s1, s2);
}
// sets fs_gamedir, adds the directory to the head of the path,
// then loads and adds pak*.pak, then anything else in alphabethical order.
-static void q_printf( 2, 3 ) add_game_dir( unsigned mode, const char *fmt, ... ) {
+static void q_printf(2, 3) add_game_dir(unsigned mode, const char *fmt, ...)
+{
va_list argptr;
searchpath_t *search;
pack_t *pack;
@@ -2250,24 +2297,24 @@ static void q_printf( 2, 3 ) add_game_dir( unsigned mode, const char *fmt, ... )
char path[MAX_OSPATH];
size_t len;
- va_start( argptr, fmt );
- len = Q_vsnprintf( fs_gamedir, sizeof( fs_gamedir ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(fs_gamedir, sizeof(fs_gamedir), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( fs_gamedir ) ) {
- Com_EPrintf( "%s: refusing oversize path\n", __func__ );
+ if (len >= sizeof(fs_gamedir)) {
+ Com_EPrintf("%s: refusing oversize path\n", __func__);
return;
}
#ifdef _WIN32
- FS_ReplaceSeparators( fs_gamedir, '/' );
+ FS_ReplaceSeparators(fs_gamedir, '/');
#endif
// add the directory to the search path
- search = FS_Malloc( sizeof( searchpath_t ) + len );
+ search = FS_Malloc(sizeof(searchpath_t) + len);
search->mode = mode;
search->pack = NULL;
- memcpy( search->filename, fs_gamedir, len + 1 );
+ memcpy(search->filename, fs_gamedir, len + 1);
search->next = fs_searchpaths;
fs_searchpaths = search;
@@ -2279,38 +2326,38 @@ static void q_printf( 2, 3 ) add_game_dir( unsigned mode, const char *fmt, ... )
// add any pack files
count = 0;
- Sys_ListFiles_r( fs_gamedir, PAK_EXT, 0, 0, &count, files, 0 );
- if( !count ) {
+ Sys_ListFiles_r(fs_gamedir, PAK_EXT, 0, 0, &count, files, 0);
+ if (!count) {
return;
}
- qsort( files, count, sizeof( files[0] ), pakcmp );
+ qsort(files, count, sizeof(files[0]), pakcmp);
- for( i = 0; i < count; i++ ) {
- len = Q_concat( path, sizeof( path ), fs_gamedir, "/", files[i], NULL );
- if( len >= sizeof( path ) ) {
- Com_EPrintf( "%s: refusing oversize path\n", __func__ );
+ for (i = 0; i < count; i++) {
+ len = Q_concat(path, sizeof(path), fs_gamedir, "/", files[i], NULL);
+ if (len >= sizeof(path)) {
+ Com_EPrintf("%s: refusing oversize path\n", __func__);
continue;
}
#if USE_ZLIB
// FIXME: guess packfile type by contents instead?
- if( len > 4 && !Q_stricmp( path + len - 4, ".pkz" ) )
- pack = load_zip_file( path );
+ if (len > 4 && !Q_stricmp(path + len - 4, ".pkz"))
+ pack = load_zip_file(path);
else
#endif
- pack = load_pak_file( path );
- if( !pack )
+ pack = load_pak_file(path);
+ if (!pack)
continue;
- search = FS_Malloc( sizeof( searchpath_t ) );
+ search = FS_Malloc(sizeof(searchpath_t));
search->mode = mode;
search->filename[0] = 0;
- search->pack = pack_get( pack );
+ search->pack = pack_get(pack);
search->next = fs_searchpaths;
- fs_searchpaths = search;
+ fs_searchpaths = search;
}
- for( i = 0; i < count; i++ ) {
- Z_Free( files[i] );
+ for (i = 0; i < count; i++) {
+ Z_Free(files[i]);
}
}
@@ -2319,34 +2366,36 @@ static void q_printf( 2, 3 ) add_game_dir( unsigned mode, const char *fmt, ... )
FS_CopyInfo
=================
*/
-file_info_t *FS_CopyInfo( const char *name, size_t size, time_t ctime, time_t mtime ) {
+file_info_t *FS_CopyInfo(const char *name, size_t size, time_t ctime, time_t mtime)
+{
file_info_t *out;
size_t len;
- if( !name ) {
+ if (!name) {
return NULL;
}
- len = strlen( name );
- out = FS_Mallocz( sizeof( *out ) + len );
+ len = strlen(name);
+ out = FS_Mallocz(sizeof(*out) + len);
out->size = size;
out->ctime = ctime;
out->mtime = mtime;
- memcpy( out->name, name, len + 1 );
+ memcpy(out->name, name, len + 1);
return out;
}
-void **FS_CopyList( void **list, int count ) {
+void **FS_CopyList(void **list, int count)
+{
void **out;
int i;
- if( !count ) {
+ if (!count) {
return NULL;
}
- out = FS_Malloc( sizeof( void * ) * ( count + 1 ) );
- for( i = 0; i < count; i++ ) {
+ out = FS_Malloc(sizeof(void *) * (count + 1));
+ for (i = 0; i < count; i++) {
out[i] = list[i];
}
out[i] = NULL;
@@ -2354,30 +2403,32 @@ void **FS_CopyList( void **list, int count ) {
return out;
}
-qboolean FS_WildCmp( const char *filter, const char *string ) {
+qboolean FS_WildCmp(const char *filter, const char *string)
+{
do {
- if( Com_WildCmpEx( filter, string, ';', qtrue ) ) {
+ if (Com_WildCmpEx(filter, string, ';', qtrue)) {
return qtrue;
}
- filter = strchr( filter, ';' );
- if( filter ) filter++;
- } while( filter );
+ filter = strchr(filter, ';');
+ if (filter) filter++;
+ } while (filter);
return qfalse;
}
-qboolean FS_ExtCmp( const char *ext, const char *name ) {
+qboolean FS_ExtCmp(const char *ext, const char *name)
+{
int c1, c2;
const char *e, *n, *l;
- if( !name[0] || !ext[0] ) {
+ if (!name[0] || !ext[0]) {
return qfalse;
}
- for( l = name; l[1]; l++ )
+ for (l = name; l[1]; l++)
;
- for( e = ext; e[1]; e++ )
+ for (e = ext; e[1]; e++)
;
rescan:
@@ -2386,43 +2437,45 @@ rescan:
c1 = *e--;
c2 = *n--;
- if( c1 == ';' ) {
+ if (c1 == ';') {
break; // matched
}
-
- if( c1 != c2 ) {
- c1 = Q_tolower( c1 );
- c2 = Q_tolower( c2 );
- if( c1 != c2 ) {
- while( e > ext ) {
+
+ if (c1 != c2) {
+ c1 = Q_tolower(c1);
+ c2 = Q_tolower(c2);
+ if (c1 != c2) {
+ while (e > ext) {
c1 = *e--;
- if( c1 == ';' ) {
+ if (c1 == ';') {
goto rescan;
}
}
return qfalse;
}
}
- if( n < name ) {
+ if (n < name) {
return qfalse;
}
- } while( e >= ext );
+ } while (e >= ext);
return qtrue;
}
-static int infocmp( const void *p1, const void *p2 ) {
- file_info_t *n1 = *( file_info_t ** )p1;
- file_info_t *n2 = *( file_info_t ** )p2;
+static int infocmp(const void *p1, const void *p2)
+{
+ file_info_t *n1 = *(file_info_t **)p1;
+ file_info_t *n2 = *(file_info_t **)p2;
- return FS_pathcmp( n1->name, n2->name );
+ return FS_pathcmp(n1->name, n2->name);
}
-static int alphacmp( const void *p1, const void *p2 ) {
- char *s1 = *( char ** )p1;
- char *s2 = *( char ** )p2;
+static int alphacmp(const void *p1, const void *p2)
+{
+ char *s1 = *(char **)p1;
+ char *s2 = *(char **)p2;
- return FS_pathcmp( s1, s2 );
+ return FS_pathcmp(s1, s2);
}
/*
@@ -2430,10 +2483,10 @@ static int alphacmp( const void *p1, const void *p2 ) {
FS_ListFiles
=================
*/
-void **FS_ListFiles( const char *path,
- const char *filter,
- unsigned flags,
- int *count_p )
+void **FS_ListFiles(const char *path,
+ const char *filter,
+ unsigned flags,
+ int *count_p)
{
searchpath_t *search;
packfile_t *file;
@@ -2448,175 +2501,175 @@ void **FS_ListFiles( const char *path,
count = 0;
valid = -1;
- if( !path ) {
+ if (!path) {
path = "";
pathlen = 0;
} else {
// normalize the path
- pathlen = FS_NormalizePathBuffer( normalized, path, sizeof( normalized ) );
- if( pathlen >= sizeof( normalized ) ) {
+ pathlen = FS_NormalizePathBuffer(normalized, path, sizeof(normalized));
+ if (pathlen >= sizeof(normalized)) {
goto fail;
}
path = normalized;
}
- for( search = fs_searchpaths; search; search = search->next ) {
- if( flags & FS_PATH_MASK ) {
- if( ( flags & search->mode & FS_PATH_MASK ) == 0 ) {
+ for (search = fs_searchpaths; search; search = search->next) {
+ if (flags & FS_PATH_MASK) {
+ if ((flags & search->mode & FS_PATH_MASK) == 0) {
continue;
}
}
- if( search->pack ) {
- if( ( flags & FS_TYPE_MASK ) == FS_TYPE_REAL ) {
+ if (search->pack) {
+ if ((flags & FS_TYPE_MASK) == FS_TYPE_REAL) {
continue; // don't search in paks
}
// TODO: add directory search support for pak files
- if( flags & FS_SEARCH_DIRSONLY ) {
+ if (flags & FS_SEARCH_DIRSONLY) {
continue;
}
- for( i = 0; i < search->pack->num_files; i++ ) {
+ for (i = 0; i < search->pack->num_files; i++) {
file = &search->pack->files[i];
s = file->name;
// check path
- if( pathlen ) {
- if( file->namelen < pathlen ) {
+ if (pathlen) {
+ if (file->namelen < pathlen) {
continue;
}
- if( FS_pathcmpn( s, path, pathlen ) ) {
+ if (FS_pathcmpn(s, path, pathlen)) {
continue;
}
- if( s[pathlen] != '/' ) {
+ if (s[pathlen] != '/') {
continue; // matched prefix must be a directory
}
- if( flags & FS_SEARCH_BYFILTER ) {
+ if (flags & FS_SEARCH_BYFILTER) {
s += pathlen + 1;
}
}
// check filter
- if( filter ) {
- if( flags & FS_SEARCH_BYFILTER ) {
- if( !FS_WildCmp( filter, s ) ) {
+ if (filter) {
+ if (flags & FS_SEARCH_BYFILTER) {
+ if (!FS_WildCmp(filter, s)) {
continue;
}
} else {
- if( !FS_ExtCmp( filter, s ) ) {
+ if (!FS_ExtCmp(filter, s)) {
continue;
}
}
}
// strip path
- if( !( flags & FS_SEARCH_SAVEPATH ) ) {
- s = COM_SkipPath( s );
+ if (!(flags & FS_SEARCH_SAVEPATH)) {
+ s = COM_SkipPath(s);
}
// strip extension
- if( flags & FS_SEARCH_STRIPEXT ) {
- p = COM_FileExtension( s );
- if( *p ) {
+ if (flags & FS_SEARCH_STRIPEXT) {
+ p = COM_FileExtension(s);
+ if (*p) {
len = p - s;
- s = memcpy( buffer, s, len );
+ s = memcpy(buffer, s, len);
s[len] = 0;
}
}
- if( !*s ) {
+ if (!*s) {
continue;
}
// copy info off
- if( flags & FS_SEARCH_EXTRAINFO ) {
- info = FS_CopyInfo( s, file->filelen, 0, 0 );
+ if (flags & FS_SEARCH_EXTRAINFO) {
+ info = FS_CopyInfo(s, file->filelen, 0, 0);
} else {
- info = FS_CopyString( s );
+ info = FS_CopyString(s);
}
files[count++] = info;
- if( count >= MAX_LISTED_FILES ) {
+ if (count >= MAX_LISTED_FILES) {
break;
}
}
} else {
- if( ( flags & FS_TYPE_MASK ) == FS_TYPE_PAK ) {
+ if ((flags & FS_TYPE_MASK) == FS_TYPE_PAK) {
continue; // don't search in filesystem
}
- len = strlen( search->filename );
+ len = strlen(search->filename);
- if( pathlen ) {
- if( len + pathlen + 1 >= MAX_OSPATH ) {
+ if (pathlen) {
+ if (len + pathlen + 1 >= MAX_OSPATH) {
continue;
}
- if( valid == -1 ) {
- valid = FS_ValidatePath( path );
+ if (valid == -1) {
+ valid = FS_ValidatePath(path);
}
- if( valid == 0 ) {
+ if (valid == 0) {
continue;
}
- s = memcpy( buffer, search->filename, len );
+ s = memcpy(buffer, search->filename, len);
s[len++] = '/';
- memcpy( s + len, path, pathlen + 1 );
+ memcpy(s + len, path, pathlen + 1);
} else {
s = search->filename;
}
- if( flags & FS_SEARCH_BYFILTER ) {
+ if (flags & FS_SEARCH_BYFILTER) {
len += pathlen + 1;
}
- Sys_ListFiles_r( s, filter, flags, len, &count, files, 0 );
+ Sys_ListFiles_r(s, filter, flags, len, &count, files, 0);
}
- if( count >= MAX_LISTED_FILES ) {
+ if (count >= MAX_LISTED_FILES) {
break;
}
}
- if( !count ) {
+ if (!count) {
fail:
- if( count_p ) {
+ if (count_p) {
*count_p = 0;
}
return NULL;
}
- if( flags & FS_SEARCH_EXTRAINFO ) {
+ if (flags & FS_SEARCH_EXTRAINFO) {
// TODO
- qsort( files, count, sizeof( files[0] ), infocmp );
+ qsort(files, count, sizeof(files[0]), infocmp);
total = count;
} else {
// sort alphabetically
- qsort( files, count, sizeof( files[0] ), alphacmp );
+ qsort(files, count, sizeof(files[0]), alphacmp);
// remove duplicates
total = 1;
- for( i = 1; i < count; i++ ) {
- if( !FS_pathcmp( files[ i - 1 ], files[i] ) ) {
- Z_Free( files[ i - 1 ] );
- files[i-1] = NULL;
+ for (i = 1; i < count; i++) {
+ if (!FS_pathcmp(files[i - 1], files[i])) {
+ Z_Free(files[i - 1]);
+ files[i - 1] = NULL;
} else {
total++;
}
}
}
- list = FS_Malloc( sizeof( void * ) * ( total + 1 ) );
+ list = FS_Malloc(sizeof(void *) * (total + 1));
total = 0;
- for( i = 0; i < count; i++ ) {
- if( files[i] ) {
+ for (i = 0; i < count; i++) {
+ if (files[i]) {
list[total++] = files[i];
}
}
list[total] = NULL;
- if( count_p ) {
+ if (count_p) {
*count_p = total;
}
@@ -2628,60 +2681,63 @@ fail:
FS_FreeList
=================
*/
-void FS_FreeList( void **list ) {
+void FS_FreeList(void **list)
+{
void **p;
- if( !list ) {
+ if (!list) {
return;
}
- for( p = list; *p; p++ ) {
- Z_Free( *p );
+ for (p = list; *p; p++) {
+ Z_Free(*p);
}
- Z_Free( list );
+ Z_Free(list);
}
-void FS_File_g( const char *path, const char *ext, unsigned flags, genctx_t *ctx ) {
+void FS_File_g(const char *path, const char *ext, unsigned flags, genctx_t *ctx)
+{
int i, numFiles;
void **list;
char *s;
- list = FS_ListFiles( path, ext, flags, &numFiles );
- if( !list ) {
+ list = FS_ListFiles(path, ext, flags, &numFiles);
+ if (!list) {
return;
}
- for( i = 0; i < numFiles; i++ ) {
+ for (i = 0; i < numFiles; i++) {
s = list[i];
- if( ctx->count < ctx->size && !strncmp( s, ctx->partial, ctx->length ) ) {
+ if (ctx->count < ctx->size && !strncmp(s, ctx->partial, ctx->length)) {
ctx->matches[ctx->count++] = s;
} else {
- Z_Free( s );
+ Z_Free(s);
}
}
- Z_Free( list );
+ Z_Free(list);
}
-static void print_file_list( const char *path, const char *ext, unsigned flags ) {
+static void print_file_list(const char *path, const char *ext, unsigned flags)
+{
void **list;
int i, listed, total;
- list = FS_ListFiles( path, ext, flags, &total );
+ list = FS_ListFiles(path, ext, flags, &total);
// don't list too many files to avoid console spam
listed = total > 128 ? 128 : total;
- for( i = 0; i < listed; i++ ) {
- Com_Printf( "%s\n", ( char * )list[i] );
+ for (i = 0; i < listed; i++) {
+ Com_Printf("%s\n", (char *)list[i]);
}
- FS_FreeList( list );
+ FS_FreeList(list);
- if( listed == total ) {
- Com_Printf( "%i files listed\n", listed );
+ if (listed == total) {
+ Com_Printf("%i files listed\n", listed);
} else {
- Com_Printf( "%i files listed (%d files more)\n", listed, total - listed );
+ Com_Printf("%i files listed (%d files more)\n", listed, total - listed);
}
}
@@ -2690,23 +2746,24 @@ static void print_file_list( const char *path, const char *ext, unsigned flags )
FS_FDir_f
============
*/
-static void FS_FDir_f( void ) {
+static void FS_FDir_f(void)
+{
unsigned flags;
char *filter;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <filter> [full_path]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <filter> [full_path]\n", Cmd_Argv(0));
return;
}
- filter = Cmd_Argv( 1 );
+ filter = Cmd_Argv(1);
flags = FS_SEARCH_BYFILTER;
- if( Cmd_Argc() > 2 ) {
+ if (Cmd_Argc() > 2) {
flags |= FS_SEARCH_SAVEPATH;
}
- print_file_list( NULL, filter, flags );
+ print_file_list(NULL, filter, flags);
}
/*
@@ -2714,22 +2771,23 @@ static void FS_FDir_f( void ) {
FS_Dir_f
============
*/
-static void FS_Dir_f( void ) {
+static void FS_Dir_f(void)
+{
char *path, *ext;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <directory> [.extension]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <directory> [.extension]\n", Cmd_Argv(0));
return;
}
- path = Cmd_Argv( 1 );
- if( Cmd_Argc() > 2 ) {
- ext = Cmd_Argv( 2 );
+ path = Cmd_Argv(1);
+ if (Cmd_Argc() > 2) {
+ ext = Cmd_Argv(2);
} else {
ext = NULL;
}
- print_file_list( path, ext, 0 );
+ print_file_list(path, ext, 0);
}
/*
@@ -2739,7 +2797,8 @@ FS_WhereIs_f
Verbosely looks up a filename with exactly the same logic as open_file_read.
============
*/
-static void FS_WhereIs_f( void ) {
+static void FS_WhereIs_f(void)
+{
char normalized[MAX_OSPATH], fullpath[MAX_OSPATH];
searchpath_t *search;
pack_t *pak;
@@ -2752,123 +2811,123 @@ static void FS_WhereIs_f( void ) {
size_t len, namelen;
qboolean report_all;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <path> [all]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <path> [all]\n", Cmd_Argv(0));
return;
}
// normalize path
- namelen = FS_NormalizePathBuffer( normalized, Cmd_Argv( 1 ), MAX_OSPATH );
- if( namelen >= MAX_OSPATH ) {
- Com_Printf( "Refusing to lookup oversize path.\n" );
+ namelen = FS_NormalizePathBuffer(normalized, Cmd_Argv(1), MAX_OSPATH);
+ if (namelen >= MAX_OSPATH) {
+ Com_Printf("Refusing to lookup oversize path.\n");
return;
}
// expand symlinks
- link = expand_links( normalized, &namelen );
- if( link ) {
- if( namelen >= MAX_OSPATH ) {
- Com_Printf( "Oversize symbolic link ('%s --> '%s').\n",
- link->name, link->target );
+ link = expand_links(normalized, &namelen);
+ if (link) {
+ if (namelen >= MAX_OSPATH) {
+ Com_Printf("Oversize symbolic link ('%s --> '%s').\n",
+ link->name, link->target);
return;
}
- Com_Printf( "Symbolic link ('%s' --> '%s') in effect.\n",
- link->name, link->target );
+ Com_Printf("Symbolic link ('%s' --> '%s') in effect.\n",
+ link->name, link->target);
}
// reject empty paths
- if( namelen == 0 ) {
- Com_Printf( "Refusing to lookup empty path.\n" );
+ if (namelen == 0) {
+ Com_Printf("Refusing to lookup empty path.\n");
return;
}
// warn about non-standard path length
- if( namelen >= MAX_QPATH ) {
- Com_Printf( "Not searching for '%s' in pack files "
- "since path length exceedes %d characters.\n",
- normalized, MAX_QPATH - 1 );
+ if (namelen >= MAX_QPATH) {
+ Com_Printf("Not searching for '%s' in pack files "
+ "since path length exceedes %d characters.\n",
+ normalized, MAX_QPATH - 1);
}
report_all = Cmd_Argc() >= 3;
total = 0;
- hash = FS_HashPath( normalized, 0 );
+ hash = FS_HashPath(normalized, 0);
valid = -1; // not yet checked
// search through the path, one element at a time
- for( search = fs_searchpaths; search; search = search->next ) {
- // is the element a pak file?
- if( search->pack ) {
- // don't bother searching in paks if length exceedes MAX_QPATH
- if( namelen >= MAX_QPATH ) {
+ for (search = fs_searchpaths; search; search = search->next) {
+ // is the element a pak file?
+ if (search->pack) {
+ // don't bother searching in paks if length exceedes MAX_QPATH
+ if (namelen >= MAX_QPATH) {
continue;
}
- // look through all the pak file elements
+ // look through all the pak file elements
pak = search->pack;
- entry = pak->file_hash[ hash & ( pak->hash_size - 1 ) ];
- for( ; entry; entry = entry->hash_next ) {
- if( entry->namelen != namelen ) {
+ entry = pak->file_hash[hash & (pak->hash_size - 1)];
+ for (; entry; entry = entry->hash_next) {
+ if (entry->namelen != namelen) {
continue;
}
- if( !FS_pathcmp( entry->name, normalized ) ) {
+ if (!FS_pathcmp(entry->name, normalized)) {
// found it!
- Com_Printf( "%s/%s (%"PRIz" bytes)\n", pak->filename,
- normalized, entry->filelen );
- if( !report_all ) {
+ Com_Printf("%s/%s (%"PRIz" bytes)\n", pak->filename,
+ normalized, entry->filelen);
+ if (!report_all) {
return;
}
total++;
}
}
} else {
- if( valid == -1 ) {
- valid = FS_ValidatePath( normalized );
- if( !valid ) {
- // warn about invalid path
- Com_Printf( "Not searching for '%s' in physical file "
- "system since path contains invalid characters.\n",
- normalized );
+ if (valid == -1) {
+ valid = FS_ValidatePath(normalized);
+ if (!valid) {
+ // warn about invalid path
+ Com_Printf("Not searching for '%s' in physical file "
+ "system since path contains invalid characters.\n",
+ normalized);
}
}
- if( valid == 0 ) {
+ if (valid == 0) {
continue;
}
- // check a file in the directory tree
- len = Q_concat( fullpath, MAX_OSPATH,
- search->filename, "/", normalized, NULL );
- if( len >= MAX_OSPATH ) {
- Com_WPrintf( "Full path length '%s/%s' exceeded %d characters.\n",
- search->filename, normalized, MAX_OSPATH - 1 );
- if( !report_all ) {
+ // check a file in the directory tree
+ len = Q_concat(fullpath, MAX_OSPATH,
+ search->filename, "/", normalized, NULL);
+ if (len >= MAX_OSPATH) {
+ Com_WPrintf("Full path length '%s/%s' exceeded %d characters.\n",
+ search->filename, normalized, MAX_OSPATH - 1);
+ if (!report_all) {
return;
}
continue;
}
- ret = Sys_GetPathInfo( fullpath, &info );
- if( !ret ) {
- Com_Printf( "%s (%"PRIz" bytes)\n", fullpath, info.size );
- if( !report_all ) {
+ ret = Sys_GetPathInfo(fullpath, &info);
+ if (!ret) {
+ Com_Printf("%s (%"PRIz" bytes)\n", fullpath, info.size);
+ if (!report_all) {
return;
}
total++;
- } else if( ret != Q_ERR_NOENT ) {
- Com_EPrintf( "Couldn't get info on '%s': %s\n",
- fullpath, Q_ErrorString( ret ) );
- if( !report_all ) {
+ } else if (ret != Q_ERR_NOENT) {
+ Com_EPrintf("Couldn't get info on '%s': %s\n",
+ fullpath, Q_ErrorString(ret));
+ if (!report_all) {
return;
}
}
}
}
- if( total ) {
- Com_Printf( "%d instances of %s\n", total, normalized );
+ if (total) {
+ Com_Printf("%d instances of %s\n", total, normalized);
} else {
- Com_Printf( "%s was not found\n", normalized );
+ Com_Printf("%s was not found\n", normalized);
}
}
@@ -2877,34 +2936,35 @@ static void FS_WhereIs_f( void ) {
FS_Path_f
============
*/
-static void FS_Path_f( void ) {
+static void FS_Path_f(void)
+{
searchpath_t *s;
int numFilesInPAK = 0;
#if USE_ZLIB
int numFilesInZIP = 0;
#endif
- Com_Printf( "Current search path:\n" );
- for( s = fs_searchpaths; s; s = s->next ) {
- if( s->pack ) {
+ Com_Printf("Current search path:\n");
+ for (s = fs_searchpaths; s; s = s->next) {
+ if (s->pack) {
#if USE_ZLIB
- if( s->pack->type == FS_ZIP )
+ if (s->pack->type == FS_ZIP)
numFilesInZIP += s->pack->num_files;
else
#endif
numFilesInPAK += s->pack->num_files;
- Com_Printf( "%s (%i files)\n", s->pack->filename, s->pack->num_files );
+ Com_Printf("%s (%i files)\n", s->pack->filename, s->pack->num_files);
} else {
- Com_Printf( "%s\n", s->filename );
+ Com_Printf("%s\n", s->filename);
}
}
- if( numFilesInPAK ) {
- Com_Printf( "%i files in PAK files\n", numFilesInPAK );
+ if (numFilesInPAK) {
+ Com_Printf("%i files in PAK files\n", numFilesInPAK);
}
#if USE_ZLIB
- if( numFilesInZIP ) {
- Com_Printf( "%i files in PKZ files\n", numFilesInZIP );
+ if (numFilesInZIP) {
+ Com_Printf("%i files in PKZ files\n", numFilesInZIP);
}
#endif
}
@@ -2915,7 +2975,8 @@ static void FS_Path_f( void ) {
FS_Stats_f
================
*/
-static void FS_Stats_f( void ) {
+static void FS_Stats_f(void)
+{
searchpath_t *path;
pack_t *pack, *maxpack = NULL;
packfile_t *file, *max = NULL;
@@ -2924,19 +2985,19 @@ static void FS_Stats_f( void ) {
int totalHashSize, totalLen;
totalHashSize = totalLen = 0;
- for( path = fs_searchpaths; path; path = path->next ) {
- if( !( pack = path->pack ) ) {
+ for (path = fs_searchpaths; path; path = path->next) {
+ if (!(pack = path->pack)) {
continue;
}
- for( i = 0; i < pack->hash_size; i++ ) {
- if( !( file = pack->file_hash[i] ) ) {
+ for (i = 0; i < pack->hash_size; i++) {
+ if (!(file = pack->file_hash[i])) {
continue;
}
len = 0;
- for( ; file ; file = file->hash_next ) {
+ for (; file; file = file->hash_next) {
len++;
}
- if( maxLen < len ) {
+ if (maxLen < len) {
max = pack->file_hash[i];
maxpack = pack;
maxLen = len;
@@ -2947,53 +3008,57 @@ static void FS_Stats_f( void ) {
//totalHashSize += pack->hash_size;
}
- Com_Printf( "Total calls to OpenFileRead: %d\n", fs_count_read );
- Com_Printf( "Total path comparsions: %d\n", fs_count_strcmp );
- Com_Printf( "Total calls to fopen: %d\n", fs_count_open );
+ Com_Printf("Total calls to OpenFileRead: %d\n", fs_count_read);
+ Com_Printf("Total path comparsions: %d\n", fs_count_strcmp);
+ Com_Printf("Total calls to fopen: %d\n", fs_count_open);
- if( !totalHashSize ) {
- Com_Printf( "No stats to display\n" );
+ if (!totalHashSize) {
+ Com_Printf("No stats to display\n");
return;
}
- Com_Printf( "Maximum hash bucket length is %d, average is %.2f\n", maxLen, ( float )totalLen / totalHashSize );
- if( max ) {
- Com_Printf( "Dumping longest bucket (%s):\n", maxpack->filename );
- for( file = max; file ; file = file->hash_next ) {
- Com_Printf( "%s\n", file->name );
+ Com_Printf("Maximum hash bucket length is %d, average is %.2f\n", maxLen, (float)totalLen / totalHashSize);
+ if (max) {
+ Com_Printf("Dumping longest bucket (%s):\n", maxpack->filename);
+ for (file = max; file; file = file->hash_next) {
+ Com_Printf("%s\n", file->name);
}
}
}
#endif // _DEBUG
-static void FS_Link_g( genctx_t *ctx ) {
+static void FS_Link_g(genctx_t *ctx)
+{
symlink_t *link;
- for( link = fs_links; link; link = link->next ) {
- if( !Prompt_AddMatch( ctx, link->name ) ) {
+ for (link = fs_links; link; link = link->next) {
+ if (!Prompt_AddMatch(ctx, link->name)) {
break;
}
}
}
-static void FS_Link_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- FS_Link_g( ctx );
+static void FS_Link_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ FS_Link_g(ctx);
}
}
-static void free_all_links( void ) {
+static void free_all_links(void)
+{
symlink_t *link, *next;
- for( link = fs_links; link; link = next ) {
+ for (link = fs_links; link; link = next) {
next = link->next;
- Z_Free( link->target );
- Z_Free( link );
+ Z_Free(link->target);
+ Z_Free(link);
}
fs_links = NULL;
}
-static void FS_UnLink_f( void ) {
+static void FS_UnLink_f(void)
+{
static const cmd_option_t options[] = {
{ "a", "all", "delete all links" },
{ "h", "help", "display this message" },
@@ -3003,16 +3068,16 @@ static void FS_UnLink_f( void ) {
char *name;
int c;
- while( ( c = Cmd_ParseOptions( options ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(options)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( options, "<name>" );
- Com_Printf( "Deletes a symbolic link with the specified name." );
- Cmd_PrintHelp( options );
+ Cmd_PrintUsage(options, "<name>");
+ Com_Printf("Deletes a symbolic link with the specified name.");
+ Cmd_PrintHelp(options);
return;
case 'a':
free_all_links();
- Com_Printf( "Deleted all symbolic links.\n" );
+ Com_Printf("Deleted all symbolic links.\n");
return;
default:
return;
@@ -3020,29 +3085,30 @@ static void FS_UnLink_f( void ) {
}
name = cmd_optarg;
- if( !name[0] ) {
- Com_Printf( "Missing name argument.\n" );
+ if (!name[0]) {
+ Com_Printf("Missing name argument.\n");
Cmd_PrintHint();
return;
}
- for( link = fs_links, next_p = &fs_links; link; link = link->next ) {
- if( !FS_pathcmp( link->name, name ) ) {
+ for (link = fs_links, next_p = &fs_links; link; link = link->next) {
+ if (!FS_pathcmp(link->name, name)) {
break;
}
next_p = &link->next;
}
- if( !link ) {
- Com_Printf( "Symbolic link '%s' does not exist.\n", name );
+ if (!link) {
+ Com_Printf("Symbolic link '%s' does not exist.\n", name);
return;
}
*next_p = link->next;
- Z_Free( link->target );
- Z_Free( link );
+ Z_Free(link->target);
+ Z_Free(link);
}
-static void FS_Link_f( void ) {
+static void FS_Link_f(void)
+{
int argc, count;
symlink_t *link;
size_t namelen, targlen;
@@ -3050,129 +3116,134 @@ static void FS_Link_f( void ) {
char target[MAX_OSPATH];
argc = Cmd_Argc();
- if( argc == 1 ) {
- for( link = fs_links, count = 0; link; link = link->next, count++ ) {
- Com_Printf( "%s --> %s\n", link->name, link->target );
+ if (argc == 1) {
+ for (link = fs_links, count = 0; link; link = link->next, count++) {
+ Com_Printf("%s --> %s\n", link->name, link->target);
}
- Com_Printf( "------------------\n"
- "%d symbolic links listed.\n", count );
+ Com_Printf("------------------\n"
+ "%d symbolic links listed.\n", count);
return;
}
- if( argc != 3 ) {
- Com_Printf( "Usage: %s <name> <target>\n"
- "Creates symbolic link to target with the specified name.\n"
- "Virtual quake paths are accepted.\n"
- "Links are effective only for reading.\n",
- Cmd_Argv( 0 ) );
+ if (argc != 3) {
+ Com_Printf("Usage: %s <name> <target>\n"
+ "Creates symbolic link to target with the specified name.\n"
+ "Virtual quake paths are accepted.\n"
+ "Links are effective only for reading.\n",
+ Cmd_Argv(0));
return;
}
- namelen = FS_NormalizePathBuffer( name, Cmd_Argv( 1 ), sizeof( name ) );
- if( namelen == 0 || namelen >= sizeof( name ) ) {
- Com_Printf( "Invalid symbolic link name.\n" );
+ namelen = FS_NormalizePathBuffer(name, Cmd_Argv(1), sizeof(name));
+ if (namelen == 0 || namelen >= sizeof(name)) {
+ Com_Printf("Invalid symbolic link name.\n");
return;
}
- targlen = FS_NormalizePathBuffer( target, Cmd_Argv( 2 ), sizeof( target ) );
- if( targlen == 0 || targlen >= sizeof( target ) ) {
- Com_Printf( "Invalid symbolic link target.\n" );
+ targlen = FS_NormalizePathBuffer(target, Cmd_Argv(2), sizeof(target));
+ if (targlen == 0 || targlen >= sizeof(target)) {
+ Com_Printf("Invalid symbolic link target.\n");
return;
}
// search for existing link with this name
- for( link = fs_links; link; link = link->next ) {
- if( !FS_pathcmp( link->name, name ) ) {
- Z_Free( link->target );
+ for (link = fs_links; link; link = link->next) {
+ if (!FS_pathcmp(link->name, name)) {
+ Z_Free(link->target);
goto update;
}
}
// create new link
- link = FS_Malloc( sizeof( *link ) + namelen );
- memcpy( link->name, name, namelen + 1 );
+ link = FS_Malloc(sizeof(*link) + namelen);
+ memcpy(link->name, name, namelen + 1);
link->namelen = namelen;
link->next = fs_links;
fs_links = link;
update:
- link->target = FS_CopyString( target );
+ link->target = FS_CopyString(target);
link->targlen = targlen;
}
-static void free_search_path( searchpath_t *path ) {
- pack_put( path->pack );
- Z_Free( path );
+static void free_search_path(searchpath_t *path)
+{
+ pack_put(path->pack);
+ Z_Free(path);
}
-static void free_all_paths( void ) {
+static void free_all_paths(void)
+{
searchpath_t *path, *next;
- for( path = fs_searchpaths; path; path = next ) {
+ for (path = fs_searchpaths; path; path = next) {
next = path->next;
- free_search_path( path );
+ free_search_path(path);
}
fs_searchpaths = NULL;
}
-static void free_game_paths( void ) {
+static void free_game_paths(void)
+{
searchpath_t *path, *next;
- for( path = fs_searchpaths; path != fs_base_searchpaths; path = next ) {
+ for (path = fs_searchpaths; path != fs_base_searchpaths; path = next) {
next = path->next;
- free_search_path( path );
+ free_search_path(path);
}
fs_searchpaths = fs_base_searchpaths;
}
-static void setup_base_paths( void ) {
+static void setup_base_paths(void)
+{
// base paths have both BASE and GAME bits set by default
// the GAME bit will be removed once gamedir is set,
// and will be put back once gamedir is reset to basegame
- add_game_dir( FS_PATH_BASE|FS_PATH_GAME, "%s/"BASEGAME, sys_basedir->string );
+ add_game_dir(FS_PATH_BASE | FS_PATH_GAME, "%s/"BASEGAME, sys_basedir->string);
fs_base_searchpaths = fs_searchpaths;
}
// Sets the gamedir and path to a different directory.
-static void setup_game_paths( void ) {
+static void setup_game_paths(void)
+{
searchpath_t *path;
- if( fs_game->string[0] ) {
+ if (fs_game->string[0]) {
// add system path first
- add_game_dir( FS_PATH_GAME, "%s/%s", sys_basedir->string, fs_game->string );
+ add_game_dir(FS_PATH_GAME, "%s/%s", sys_basedir->string, fs_game->string);
// home paths override system paths
- if( sys_homedir->string[0] ) {
- add_game_dir( FS_PATH_BASE, "%s/"BASEGAME, sys_homedir->string );
- add_game_dir( FS_PATH_GAME, "%s/%s", sys_homedir->string, fs_game->string );
+ if (sys_homedir->string[0]) {
+ add_game_dir(FS_PATH_BASE, "%s/"BASEGAME, sys_homedir->string);
+ add_game_dir(FS_PATH_GAME, "%s/%s", sys_homedir->string, fs_game->string);
}
// remove the game bit from base paths
- for( path = fs_base_searchpaths; path; path = path->next ) {
+ for (path = fs_base_searchpaths; path; path = path->next) {
path->mode &= ~FS_PATH_GAME;
}
// this var is set for compatibility with server browsers, etc
- Cvar_FullSet( "gamedir", fs_game->string, CVAR_ROM|CVAR_SERVERINFO, FROM_CODE );
+ Cvar_FullSet("gamedir", fs_game->string, CVAR_ROM | CVAR_SERVERINFO, FROM_CODE);
} else {
- if( sys_homedir->string[0] ) {
- add_game_dir( FS_PATH_BASE|FS_PATH_GAME,
- "%s/"BASEGAME, sys_homedir->string );
+ if (sys_homedir->string[0]) {
+ add_game_dir(FS_PATH_BASE | FS_PATH_GAME,
+ "%s/"BASEGAME, sys_homedir->string);
}
// add the game bit to base paths
- for( path = fs_base_searchpaths; path; path = path->next ) {
+ for (path = fs_base_searchpaths; path; path = path->next) {
path->mode |= FS_PATH_GAME;
}
- Cvar_FullSet( "gamedir", "", CVAR_ROM, FROM_CODE );
+ Cvar_FullSet("gamedir", "", CVAR_ROM, FROM_CODE);
}
// this var is used by the game library to find it's home directory
- Cvar_FullSet( "fs_gamedir", fs_gamedir, CVAR_ROM, FROM_CODE );
+ Cvar_FullSet("fs_gamedir", fs_gamedir, CVAR_ROM, FROM_CODE);
}
/*
@@ -3182,10 +3253,11 @@ FS_Restart
Unless total is true, reloads paks only up to base dir
================
*/
-void FS_Restart( qboolean total ) {
- Com_Printf( "----- FS_Restart -----\n" );
-
- if( total ) {
+void FS_Restart(qboolean total)
+{
+ Com_Printf("----- FS_Restart -----\n");
+
+ if (total) {
// perform full reset
free_all_paths();
setup_base_paths();
@@ -3198,21 +3270,22 @@ void FS_Restart( qboolean total ) {
FS_Path_f();
- Com_Printf( "----------------------\n" );
+ Com_Printf("----------------------\n");
}
/*
============
FS_Restart_f
-
+
Console command to fully re-start the file system.
============
*/
-static void FS_Restart_f( void ) {
+static void FS_Restart_f(void)
+{
#if USE_CLIENT
- CL_RestartFilesystem( qtrue );
+ CL_RestartFilesystem(qtrue);
#else
- FS_Restart( qtrue );
+ FS_Restart(qtrue);
#endif
}
@@ -3236,19 +3309,20 @@ static const cmdreg_t c_fs[] = {
FS_Shutdown
================
*/
-void FS_Shutdown( void ) {
+void FS_Shutdown(void)
+{
file_t *file;
int i;
- if( !fs_searchpaths ) {
+ if (!fs_searchpaths) {
return;
}
// close file handles
- for( i = 0, file = fs_files; i < MAX_FILE_HANDLES; i++, file++ ) {
- if( file->type != FS_FREE ) {
- Com_WPrintf( "%s: closing handle %d\n", __func__, i + 1 );
- FS_FCloseFile( i + 1 );
+ for (i = 0, file = fs_files; i < MAX_FILE_HANDLES; i++, file++) {
+ if (file->type != FS_FREE) {
+ Com_WPrintf("%s: closing handle %d\n", __func__, i + 1);
+ FS_FCloseFile(i + 1);
}
}
@@ -3259,33 +3333,34 @@ void FS_Shutdown( void ) {
free_all_paths();
#if USE_ZLIB
- inflateEnd( &fs_zipstream.stream );
+ inflateEnd(&fs_zipstream.stream);
#endif
- Z_LeakTest( TAG_FILESYSTEM );
+ Z_LeakTest(TAG_FILESYSTEM);
- Cmd_Deregister( c_fs );
+ Cmd_Deregister(c_fs);
}
// this is called when local server starts up and gets it's latched variables,
// client receives a serverdata packet, or user changes the game by hand while
// disconnected
-static void fs_game_changed( cvar_t *self ) {
+static void fs_game_changed(cvar_t *self)
+{
char *s = self->string;
qerror_t ret;
// validate it
- if( *s ) {
- if( !Q_stricmp( s, BASEGAME ) ) {
- Cvar_Reset( self );
- } else if( !COM_IsPath( s ) ) {
- Com_Printf( "'%s' should contain characters [A-Za-z0-9_-] only.\n", self->name );
- Cvar_Reset( self );
+ if (*s) {
+ if (!Q_stricmp(s, BASEGAME)) {
+ Cvar_Reset(self);
+ } else if (!COM_IsPath(s)) {
+ Com_Printf("'%s' should contain characters [A-Za-z0-9_-] only.\n", self->name);
+ Cvar_Reset(self);
}
}
// check for the first time startup
- if( !fs_base_searchpaths ) {
+ if (!fs_base_searchpaths) {
// start up with baseq2 by default
setup_base_paths();
@@ -3298,15 +3373,15 @@ static void fs_game_changed( cvar_t *self ) {
// otherwise, restart the filesystem
#if USE_CLIENT
- CL_RestartFilesystem( qfalse );
+ CL_RestartFilesystem(qfalse);
#else
- FS_Restart( qfalse );
+ FS_Restart(qfalse);
#endif
// exec autoexec.cfg (must be a real file within the game directory)
- ret = Cmd_ExecuteFile( COM_AUTOEXECCFG_NAME, FS_TYPE_REAL|FS_PATH_GAME );
- if( ret && ret != Q_ERR_NOENT ) {
- Com_WPrintf( "Couldn't exec %s: %s\n", COM_AUTOEXECCFG_NAME, Q_ErrorString( ret ) );
+ ret = Cmd_ExecuteFile(COM_AUTOEXECCFG_NAME, FS_TYPE_REAL | FS_PATH_GAME);
+ if (ret && ret != Q_ERR_NOENT) {
+ Com_WPrintf("Couldn't exec %s: %s\n", COM_AUTOEXECCFG_NAME, Q_ErrorString(ret));
}
}
@@ -3315,20 +3390,21 @@ static void fs_game_changed( cvar_t *self ) {
FS_Init
================
*/
-void FS_Init( void ) {
- Com_Printf( "------- FS_Init -------\n" );
+void FS_Init(void)
+{
+ Com_Printf("------- FS_Init -------\n");
- Cmd_Register( c_fs );
+ Cmd_Register(c_fs);
#ifdef _DEBUG
- fs_debug = Cvar_Get( "fs_debug", "0", 0 );
+ fs_debug = Cvar_Get("fs_debug", "0", 0);
#endif
// get the game cvar and start the filesystem
- fs_game = Cvar_Get( "game", DEFGAME, CVAR_LATCH|CVAR_SERVERINFO );
+ fs_game = Cvar_Get("game", DEFGAME, CVAR_LATCH | CVAR_SERVERINFO);
fs_game->changed = fs_game_changed;
- fs_game_changed( fs_game );
+ fs_game_changed(fs_game);
- Com_Printf( "-----------------------\n" );
+ Com_Printf("-----------------------\n");
}
diff --git a/src/files.h b/src/files.h
index 926d59a..c8ae0e7 100644
--- a/src/files.h
+++ b/src/files.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -77,96 +77,96 @@ typedef struct file_info_s {
//
#define MAX_LOADFILE 0x1000000
-#define FS_Malloc( size ) Z_TagMalloc( size, TAG_FILESYSTEM )
-#define FS_Mallocz( size ) Z_TagMallocz( size, TAG_FILESYSTEM )
-#define FS_CopyString( string ) Z_TagCopyString( string, TAG_FILESYSTEM )
-#define FS_LoadFile( path, buf ) FS_LoadFileEx( path, buf, 0, TAG_FILESYSTEM )
-#define FS_FreeFile( buf ) Z_Free( buf )
+#define FS_Malloc(size) Z_TagMalloc(size, TAG_FILESYSTEM)
+#define FS_Mallocz(size) Z_TagMallocz(size, TAG_FILESYSTEM)
+#define FS_CopyString(string) Z_TagCopyString(string, TAG_FILESYSTEM)
+#define FS_LoadFile(path, buf) FS_LoadFileEx(path, buf, 0, TAG_FILESYSTEM)
+#define FS_FreeFile(buf) Z_Free(buf)
// just regular malloc for now
-#define FS_AllocTempMem( size ) FS_Malloc( size )
-#define FS_FreeTempMem( buf ) Z_Free( buf )
+#define FS_AllocTempMem(size) FS_Malloc(size)
+#define FS_FreeTempMem(buf) Z_Free(buf)
// just regular caseless string comparsion
#define FS_pathcmp Q_strcasecmp
#define FS_pathcmpn Q_strncasecmp
-#define FS_HashPath( s, size ) Com_HashStringLen( s, SIZE_MAX, size )
-#define FS_HashPathLen( s, len, size ) Com_HashStringLen( s, len, size )
+#define FS_HashPath(s, size) Com_HashStringLen(s, SIZE_MAX, size)
+#define FS_HashPathLen(s, len, size) Com_HashStringLen(s, len, size)
-void FS_Init( void );
-void FS_Shutdown( void );
-void FS_Restart( qboolean total );
+void FS_Init(void);
+void FS_Shutdown(void);
+void FS_Restart(qboolean total);
#if USE_CLIENT
-qerror_t FS_RenameFile( const char *from, const char *to );
+qerror_t FS_RenameFile(const char *from, const char *to);
#endif
-qerror_t FS_CreatePath( char *path );
+qerror_t FS_CreatePath(char *path);
-char *FS_CopyExtraInfo( const char *name, const file_info_t *info );
+char *FS_CopyExtraInfo(const char *name, const file_info_t *info);
-ssize_t FS_FOpenFile( const char *filename, qhandle_t *f, unsigned mode );
-void FS_FCloseFile( qhandle_t f );
-qhandle_t FS_EasyOpenFile( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext );
+ssize_t FS_FOpenFile(const char *filename, qhandle_t *f, unsigned mode);
+void FS_FCloseFile(qhandle_t f);
+qhandle_t FS_EasyOpenFile(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext);
// nasty hack to check if file has valid gzip header:
// first 4 bytes of header are interpreted as 32-bit magic value.
// this value is checked to contain gzip ident bytes (0x1f, 0x8b),
// Z_DEFLATED compression byte (0x08), reserved options must be unset
#define CHECK_GZIP_HEADER(magic) \
- ((LittleLong(magic)&0xe0ffffff)==0x00088b1f)
+ ((LittleLong(magic) & 0xe0ffffff) == 0x00088b1f)
-qerror_t FS_FilterFile( qhandle_t f );
+qerror_t FS_FilterFile(qhandle_t f);
-#define FS_FileExistsEx( path, flags ) \
- ( FS_LoadFileEx( path, NULL, flags, TAG_FREE ) != Q_ERR_NOENT )
-#define FS_FileExists( path ) \
- FS_FileExistsEx( path, 0 )
+#define FS_FileExistsEx(path, flags) \
+ (FS_LoadFileEx(path, NULL, flags, TAG_FREE) != Q_ERR_NOENT)
+#define FS_FileExists(path) \
+ FS_FileExistsEx(path, 0)
-ssize_t FS_LoadFileEx( const char *path, void **buffer, unsigned flags, memtag_t tag );
+ssize_t FS_LoadFileEx(const char *path, void **buffer, unsigned flags, memtag_t tag);
// a NULL buffer will just return the file length without loading
// length < 0 indicates error
-qerror_t FS_WriteFile( const char *path, const void *data, size_t len );
+qerror_t FS_WriteFile(const char *path, const void *data, size_t len);
-qboolean FS_EasyWriteFile( char *buf, size_t size, unsigned mode,
- const char *dir, const char *name, const char *ext,
- const void *data, size_t len );
+qboolean FS_EasyWriteFile(char *buf, size_t size, unsigned mode,
+ const char *dir, const char *name, const char *ext,
+ const void *data, size_t len);
-ssize_t FS_Read( void *buffer, size_t len, qhandle_t f );
-ssize_t FS_Write( const void *buffer, size_t len, qhandle_t f );
+ssize_t FS_Read(void *buffer, size_t len, qhandle_t f);
+ssize_t FS_Write(const void *buffer, size_t len, qhandle_t f);
// properly handles partial reads
-ssize_t FS_FPrintf( qhandle_t f, const char *format, ... ) q_printf( 2, 3 );
-ssize_t FS_ReadLine( qhandle_t f, char *buffer, size_t size );
+ssize_t FS_FPrintf(qhandle_t f, const char *format, ...) q_printf(2, 3);
+ssize_t FS_ReadLine(qhandle_t f, char *buffer, size_t size);
-void FS_Flush( qhandle_t f );
+void FS_Flush(qhandle_t f);
-ssize_t FS_Tell( qhandle_t f );
-qerror_t FS_Seek( qhandle_t f, off_t offset );
+ssize_t FS_Tell(qhandle_t f);
+qerror_t FS_Seek(qhandle_t f, off_t offset);
-ssize_t FS_Length( qhandle_t f );
+ssize_t FS_Length(qhandle_t f);
-qboolean FS_WildCmp( const char *filter, const char *string );
-qboolean FS_ExtCmp( const char *extension, const char *string );
+qboolean FS_WildCmp(const char *filter, const char *string);
+qboolean FS_ExtCmp(const char *extension, const char *string);
-void **FS_ListFiles( const char *path, const char *filter, unsigned flags, int *count_p );
-void **FS_CopyList( void **list, int count );
-file_info_t *FS_CopyInfo( const char *name, size_t size, time_t ctime, time_t mtime );
-void FS_FreeList( void **list );
+void **FS_ListFiles(const char *path, const char *filter, unsigned flags, int *count_p);
+void **FS_CopyList(void **list, int count);
+file_info_t *FS_CopyInfo(const char *name, size_t size, time_t ctime, time_t mtime);
+void FS_FreeList(void **list);
-size_t FS_NormalizePath( char *out, const char *in );
-size_t FS_NormalizePathBuffer( char *out, const char *in, size_t size );
+size_t FS_NormalizePath(char *out, const char *in);
+size_t FS_NormalizePathBuffer(char *out, const char *in, size_t size);
-qboolean FS_ValidatePath( const char *s );
+qboolean FS_ValidatePath(const char *s);
#ifdef _WIN32
-char *FS_ReplaceSeparators( char *s, int separator );
+char *FS_ReplaceSeparators(char *s, int separator);
#endif
-void FS_File_g( const char *path, const char *ext, unsigned flags, genctx_t *ctx );
+void FS_File_g(const char *path, const char *ext, unsigned flags, genctx_t *ctx);
extern cvar_t *fs_game;
diff --git a/src/fpu.c b/src/fpu.c
index 9e21130..48355a6 100644
--- a/src/fpu.c
+++ b/src/fpu.c
@@ -25,7 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
uint16_t pushed_cw, single_cw, full_cw, chop_cw, ceil_cw;
-void X86_SetFPCW( void ) {
+void X86_SetFPCW(void)
+{
uint16_t cw;
// save the control word into pushed_cw
diff --git a/src/fpu.h b/src/fpu.h
index 62125bc..59095c1 100644
--- a/src/fpu.h
+++ b/src/fpu.h
@@ -24,8 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define X86_STORE_FPCW(x) __asm fnstcw x
#define X86_LOAD_FPCW(x) __asm fldcw x
#else
-#define X86_STORE_FPCW(x) __asm__ __volatile__( "fnstcw %0" : "=m" (x) )
-#define X86_LOAD_FPCW(x) __asm__ __volatile__( "fldcw %0" : : "m" (x) )
+#define X86_STORE_FPCW(x) __asm__ __volatile__("fnstcw %0" : "=m" (x))
+#define X86_LOAD_FPCW(x) __asm__ __volatile__("fldcw %0" : : "m" (x))
#endif
#define X86_PUSH_FPCW X86_STORE_FPCW(pushed_cw)
@@ -38,7 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern uint16_t pushed_cw, single_cw, full_cw, chop_cw, ceil_cw;
-void X86_SetFPCW( void );
+void X86_SetFPCW(void);
#else
diff --git a/src/g_public.h b/src/g_public.h
index 14c2ff5..859cb0e 100644
--- a/src/g_public.h
+++ b/src/g_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -57,8 +57,7 @@ typedef struct gclient_s gclient_t;
#ifndef GAME_INCLUDE
-struct gclient_s
-{
+struct gclient_s {
player_state_t ps; // communicated by server to clients
int ping;
@@ -68,8 +67,7 @@ struct gclient_s
};
-struct edict_s
-{
+struct edict_s {
entity_state_t s;
struct gclient_s *client;
qboolean inuse;
@@ -77,7 +75,7 @@ struct edict_s
// FIXME: move these fields to a server private sv_entity_t
list_t area; // linked to a division node or leaf
-
+
int num_clusters; // if -1, use headnode instead
int clusternums[MAX_ENT_CLUSTERS];
int headnode; // unused if num_clusters != -1
@@ -103,80 +101,79 @@ struct edict_s
//
// functions provided by the main engine
//
-typedef struct
-{
+typedef struct {
// special messages
- void (* q_printf( 2, 3 ) bprintf) (int printlevel, const char *fmt, ...);
- void (* q_printf( 1, 2 ) dprintf) (const char *fmt, ...);
- void (* q_printf( 3, 4 ) cprintf) (edict_t *ent, int printlevel, const char *fmt, ...);
- void (* q_printf( 2, 3 ) centerprintf) (edict_t *ent, const char *fmt, ...);
- void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs);
- void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs);
+ void (* q_printf(2, 3) bprintf)(int printlevel, const char *fmt, ...);
+ void (* q_printf(1, 2) dprintf)(const char *fmt, ...);
+ void (* q_printf(3, 4) cprintf)(edict_t *ent, int printlevel, const char *fmt, ...);
+ void (* q_printf(2, 3) centerprintf)(edict_t *ent, const char *fmt, ...);
+ void (*sound)(edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs);
+ void (*positioned_sound)(vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs);
// config strings hold all the index strings, the lightstyles,
// and misc data like the sky definition and cdtrack.
// All of the current configstrings are sent to clients when
// they connect, and changes are sent to all connected clients.
- void (*configstring) (int num, const char *string);
+ void (*configstring)(int num, const char *string);
- void (* q_noreturn q_printf( 1, 2 ) error) (const char *fmt, ...);
+ void (* q_noreturn q_printf(1, 2) error)(const char *fmt, ...);
// the *index functions create configstrings and some internal server state
- int (*modelindex) (const char *name);
- int (*soundindex) (const char *name);
- int (*imageindex) (const char *name);
+ int (*modelindex)(const char *name);
+ int (*soundindex)(const char *name);
+ int (*imageindex)(const char *name);
- void (*setmodel) (edict_t *ent, const char *name);
+ void (*setmodel)(edict_t *ent, const char *name);
// collision detection
- trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
- int (*pointcontents) (vec3_t point);
- qboolean (*inPVS) (vec3_t p1, vec3_t p2);
- qboolean (*inPHS) (vec3_t p1, vec3_t p2);
- void (*SetAreaPortalState) (int portalnum, qboolean open);
- qboolean (*AreasConnected) (int area1, int area2);
+ trace_t (*trace)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
+ int (*pointcontents)(vec3_t point);
+ qboolean (*inPVS)(vec3_t p1, vec3_t p2);
+ qboolean (*inPHS)(vec3_t p1, vec3_t p2);
+ void (*SetAreaPortalState)(int portalnum, qboolean open);
+ qboolean (*AreasConnected)(int area1, int area2);
// an entity will never be sent to a client or used for collision
// if it is not passed to linkentity. If the size, position, or
// solidity changes, it must be relinked.
- void (*linkentity) (edict_t *ent);
- void (*unlinkentity) (edict_t *ent); // call before removing an interactive edict
- int (*BoxEdicts) (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
- void (*Pmove) (pmove_t *pmove); // player movement code common with client prediction
+ void (*linkentity)(edict_t *ent);
+ void (*unlinkentity)(edict_t *ent); // call before removing an interactive edict
+ int (*BoxEdicts)(vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
+ void (*Pmove)(pmove_t *pmove); // player movement code common with client prediction
// network messaging
- void (*multicast) (vec3_t origin, multicast_t to);
- void (*unicast) (edict_t *ent, qboolean reliable);
- void (*WriteChar) (int c);
- void (*WriteByte) (int c);
- void (*WriteShort) (int c);
- void (*WriteLong) (int c);
- void (*WriteFloat) (float f);
- void (*WriteString) (const char *s);
- void (*WritePosition) (const vec3_t pos); // some fractional bits
- void (*WriteDir) (const vec3_t pos); // single byte encoded, very coarse
- void (*WriteAngle) (float f);
+ void (*multicast)(vec3_t origin, multicast_t to);
+ void (*unicast)(edict_t *ent, qboolean reliable);
+ void (*WriteChar)(int c);
+ void (*WriteByte)(int c);
+ void (*WriteShort)(int c);
+ void (*WriteLong)(int c);
+ void (*WriteFloat)(float f);
+ void (*WriteString)(const char *s);
+ void (*WritePosition)(const vec3_t pos); // some fractional bits
+ void (*WriteDir)(const vec3_t pos); // single byte encoded, very coarse
+ void (*WriteAngle)(float f);
// managed memory allocation
- void *(*TagMalloc) (size_t size, unsigned tag);
- void (*TagFree) (void *block);
- void (*FreeTags) (unsigned tag);
+ void *(*TagMalloc)(size_t size, unsigned tag);
+ void (*TagFree)(void *block);
+ void (*FreeTags)(unsigned tag);
// console variable interaction
- cvar_t *(*cvar) (const char *var_name, const char *value, int flags);
- cvar_t *(*cvar_set) (const char *var_name, const char *value);
- cvar_t *(*cvar_forceset) (const char *var_name, const char *value);
+ cvar_t *(*cvar)(const char *var_name, const char *value, int flags);
+ cvar_t *(*cvar_set)(const char *var_name, const char *value);
+ cvar_t *(*cvar_forceset)(const char *var_name, const char *value);
// ClientCommand and ServerCommand parameter access
- int (*argc) (void);
- char *(*argv) (int n);
- char *(*args) (void); // concatenation of all argv >= 1
+ int (*argc)(void);
+ char *(*argv)(int n);
+ char *(*args)(void); // concatenation of all argv >= 1
// add commands to the server console as if they were typed in
// for map changing, etc
- void (*AddCommandString) (const char *text);
+ void (*AddCommandString)(const char *text);
- void (*DebugGraph) (float value, int color);
+ void (*DebugGraph)(float value, int color);
} game_import_t;
//
@@ -190,45 +187,44 @@ typedef struct {
int max_edicts;
} edict_pool_t;
-typedef struct
-{
+typedef struct {
int apiversion;
// the init function will only be called when a game starts,
// not each time a level is loaded. Persistant data for clients
// and the server can be allocated in init
- void (*Init) (void);
- void (*Shutdown) (void);
+ void (*Init)(void);
+ void (*Shutdown)(void);
// each new level entered will cause a call to SpawnEntities
- void (*SpawnEntities) (const char *mapname, const char *entstring, const char *spawnpoint);
+ void (*SpawnEntities)(const char *mapname, const char *entstring, const char *spawnpoint);
// Read/Write Game is for storing persistant cross level information
// about the world state and the clients.
// WriteGame is called every time a level is exited.
// ReadGame is called on a loadgame.
- void (*WriteGame) (const char *filename, qboolean autosave);
- void (*ReadGame) (const char *filename);
+ void (*WriteGame)(const char *filename, qboolean autosave);
+ void (*ReadGame)(const char *filename);
// ReadLevel is called after the default map information has been
// loaded with SpawnEntities
- void (*WriteLevel) (const char *filename);
- void (*ReadLevel) (const char *filename);
+ void (*WriteLevel)(const char *filename);
+ void (*ReadLevel)(const char *filename);
- qboolean (*ClientConnect) (edict_t *ent, char *userinfo);
- void (*ClientBegin) (edict_t *ent);
- void (*ClientUserinfoChanged) (edict_t *ent, char *userinfo);
- void (*ClientDisconnect) (edict_t *ent);
- void (*ClientCommand) (edict_t *ent);
- void (*ClientThink) (edict_t *ent, usercmd_t *cmd);
+ qboolean (*ClientConnect)(edict_t *ent, char *userinfo);
+ void (*ClientBegin)(edict_t *ent);
+ void (*ClientUserinfoChanged)(edict_t *ent, char *userinfo);
+ void (*ClientDisconnect)(edict_t *ent);
+ void (*ClientCommand)(edict_t *ent);
+ void (*ClientThink)(edict_t *ent, usercmd_t *cmd);
- void (*RunFrame) (void);
+ void (*RunFrame)(void);
// ServerCommand will be called when an "sv <command>" command is issued on the
// server console.
// The game can issue gi.argc() / gi.argv() commands to get the rest
// of the parameters
- void (*ServerCommand) (void);
+ void (*ServerCommand)(void);
//
// global variables shared between game and server
@@ -236,7 +232,7 @@ typedef struct
// The edict array is allocated in the game dll so it
// can vary in size from one game to another.
- //
+ //
// The size will be fixed when ge->Init() is called
struct edict_s *edicts;
int edict_size;
diff --git a/src/gl_draw.c b/src/gl_draw.c
index 5b61794..15a5cdb 100644
--- a/src/gl_draw.c
+++ b/src/gl_draw.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,28 +25,27 @@ drawStatic_t draw;
static inline void _GL_StretchPic(
float x, float y, float w, float h,
float s1, float t1, float s2, float t2,
- uint32_t color, int texnum, int flags )
+ uint32_t color, int texnum, int flags)
{
vec_t *dst_vert;
uint32_t *dst_color;
int *dst_indices;
- if( tess.numverts + 4 > TESS_MAX_VERTICES ||
+ if (tess.numverts + 4 > TESS_MAX_VERTICES ||
tess.numindices + 6 > TESS_MAX_INDICES ||
- ( tess.numverts && tess.texnum[0] != texnum ) )
- {
+ (tess.numverts && tess.texnum[0] != texnum)) {
GL_Flush2D();
}
tess.texnum[0] = texnum;
dst_vert = tess.vertices + tess.numverts * 4;
- Vector4Set( dst_vert, x, y, s1, t1 );
- Vector4Set( dst_vert + 4, x + w, y, s2, t1 );
- Vector4Set( dst_vert + 8, x + w, y + h, s2, t2 );
- Vector4Set( dst_vert + 12, x, y + h, s1, t2 );
+ Vector4Set(dst_vert, x, y, s1, t1);
+ Vector4Set(dst_vert + 4, x + w, y, s2, t1);
+ Vector4Set(dst_vert + 8, x + w, y + h, s2, t2);
+ Vector4Set(dst_vert + 12, x, y + h, s1, t2);
- dst_color = ( uint32_t * )tess.colors + tess.numverts;
+ dst_color = (uint32_t *)tess.colors + tess.numverts;
dst_color[0] = color;
dst_color[1] = color;
dst_color[2] = color;
@@ -60,17 +59,17 @@ static inline void _GL_StretchPic(
dst_indices[4] = tess.numverts + 1;
dst_indices[5] = tess.numverts + 2;
- if( flags & if_transparent ) {
- if( ( flags & if_paletted ) && draw.scale == 1 ) {
+ if (flags & if_transparent) {
+ if ((flags & if_paletted) && draw.scale == 1) {
tess.flags |= 1;
} else {
tess.flags |= 2;
}
}
-#define U32_ALPHA MakeColor( 0, 0, 0, 255 )
+#define U32_ALPHA MakeColor(0, 0, 0, 255)
- if( ( color & U32_ALPHA ) != U32_ALPHA ) {
+ if ((color & U32_ALPHA) != U32_ALPHA) {
tess.flags |= 2;
}
@@ -81,7 +80,8 @@ static inline void _GL_StretchPic(
#define GL_StretchPic(x,y,w,h,s1,t1,s2,t2,color,image) \
_GL_StretchPic(x,y,w,h,s1,t1,s2,t2,color,(image)->texnum,(image)->flags)
-void GL_Blend( void ) {
+void GL_Blend(void)
+{
color_t color;
color.u8[0] = glr.fd.blend[0] * 255;
@@ -89,37 +89,41 @@ void GL_Blend( void ) {
color.u8[2] = glr.fd.blend[2] * 255;
color.u8[3] = glr.fd.blend[3] * 255;
- _GL_StretchPic( glr.fd.x, glr.fd.y, glr.fd.width, glr.fd.height, 0, 0, 1, 1,
- color.u32, TEXNUM_WHITE, 0 );
+ _GL_StretchPic(glr.fd.x, glr.fd.y, glr.fd.width, glr.fd.height, 0, 0, 1, 1,
+ color.u32, TEXNUM_WHITE, 0);
}
-void R_ClearColor( void ) {
+void R_ClearColor(void)
+{
draw.colors[0].u32 = U32_WHITE;
draw.colors[1].u32 = U32_WHITE;
}
-void R_SetAlpha( float alpha ) {
+void R_SetAlpha(float alpha)
+{
draw.colors[0].u8[3] =
- draw.colors[1].u8[3] = alpha * 255;
+ draw.colors[1].u8[3] = alpha * 255;
}
-void R_SetColor( uint32_t color ) {
+void R_SetColor(uint32_t color)
+{
draw.colors[0].u32 = color;
draw.colors[1].u8[3] = draw.colors[0].u8[3];
}
-void R_SetClipRect( int flags, const clipRect_t *clip ) {
+void R_SetClipRect(int flags, const clipRect_t *clip)
+{
clipRect_t rc;
float scale;
- if( ( draw.flags & DRAW_CLIP_MASK ) == flags ) {
+ if ((draw.flags & DRAW_CLIP_MASK) == flags) {
return;
}
GL_Flush2D();
- if( flags == DRAW_CLIP_DISABLED ) {
- qglDisable( GL_SCISSOR_TEST );
+ if (flags == DRAW_CLIP_DISABLED) {
+ qglDisable(GL_SCISSOR_TEST);
draw.flags &= ~DRAW_CLIP_MASK;
return;
}
@@ -128,140 +132,150 @@ void R_SetClipRect( int flags, const clipRect_t *clip ) {
rc.left = 0;
rc.top = 0;
- if( flags & DRAW_CLIP_LEFT ) {
+ if (flags & DRAW_CLIP_LEFT) {
rc.left = clip->left * scale;
- if( rc.left < 0 ) {
+ if (rc.left < 0) {
rc.left = 0;
}
}
- if( flags & DRAW_CLIP_TOP ) {
+ if (flags & DRAW_CLIP_TOP) {
rc.top = clip->top * scale;
- if( rc.top < 0 ) {
+ if (rc.top < 0) {
rc.top = 0;
}
}
rc.right = r_config.width;
rc.bottom = r_config.height;
- if( flags & DRAW_CLIP_RIGHT ) {
+ if (flags & DRAW_CLIP_RIGHT) {
rc.right = clip->right * scale;
- if( rc.right > r_config.width ) {
+ if (rc.right > r_config.width) {
rc.right = r_config.width;
}
}
- if( flags & DRAW_CLIP_BOTTOM ) {
+ if (flags & DRAW_CLIP_BOTTOM) {
rc.bottom = clip->bottom * scale;
- if( rc.bottom > r_config.height ) {
+ if (rc.bottom > r_config.height) {
rc.bottom = r_config.height;
}
}
- if( rc.right < rc.left ) {
+ if (rc.right < rc.left) {
rc.right = rc.left;
}
- if( rc.bottom < rc.top ) {
+ if (rc.bottom < rc.top) {
rc.bottom = rc.top;
}
- qglEnable( GL_SCISSOR_TEST );
- qglScissor( rc.left, r_config.height - rc.bottom,
- rc.right - rc.left, rc.bottom - rc.top );
- draw.flags = ( draw.flags & ~DRAW_CLIP_MASK ) | flags;
+ qglEnable(GL_SCISSOR_TEST);
+ qglScissor(rc.left, r_config.height - rc.bottom,
+ rc.right - rc.left, rc.bottom - rc.top);
+ draw.flags = (draw.flags & ~DRAW_CLIP_MASK) | flags;
}
-void R_SetScale( float *scale ) {
+void R_SetScale(float *scale)
+{
float f = scale ? *scale : 1;
- if( draw.scale == f ) {
+ if (draw.scale == f) {
return;
}
-
+
GL_Flush2D();
- qglMatrixMode( GL_PROJECTION );
+ qglMatrixMode(GL_PROJECTION);
qglLoadIdentity();
- qglOrtho( 0, Q_rint( r_config.width * f ),
- Q_rint( r_config.height * f ), 0, -1, 1 );
+ qglOrtho(0, Q_rint(r_config.width * f),
+ Q_rint(r_config.height * f), 0, -1, 1);
draw.scale = f;
}
-qboolean R_GetPicSize( int *w, int *h, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+qboolean R_GetPicSize(int *w, int *h, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- if( w ) {
+ if (w) {
*w = image->width;
}
- if( h ) {
+ if (h) {
*h = image->height;
}
return image->flags & if_transparent;
}
-void R_DrawStretchPicST( int x, int y, int w, int h, float s1, float t1,
- float s2, float t2, qhandle_t pic )
+void R_DrawStretchPicST(int x, int y, int w, int h, float s1, float t1,
+ float s2, float t2, qhandle_t pic)
{
/* TODO: scrap support */
- GL_StretchPic( x, y, w, h, s1, t1, s2, t2,
- draw.colors[0].u32, IMG_ForHandle( pic ) );
+ GL_StretchPic(x, y, w, h, s1, t1, s2, t2,
+ draw.colors[0].u32, IMG_ForHandle(pic));
}
-void R_DrawStretchPic( int x, int y, int w, int h, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- GL_StretchPic( x, y, w, h, image->sl, image->tl, image->sh, image->th,
- draw.colors[0].u32, image );
+ GL_StretchPic(x, y, w, h, image->sl, image->tl, image->sh, image->th,
+ draw.colors[0].u32, image);
}
-void R_DrawPic( int x, int y, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+void R_DrawPic(int x, int y, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- GL_StretchPic( x, y, image->width, image->height,
- image->sl, image->tl, image->sh, image->th, draw.colors[0].u32, image );
+ GL_StretchPic(x, y, image->width, image->height,
+ image->sl, image->tl, image->sh, image->th, draw.colors[0].u32, image);
}
-#define DIV64 ( 1.0f / 64.0f )
+#define DIV64 (1.0f / 64.0f)
-void R_TileClear( int x, int y, int w, int h, qhandle_t pic ) {
- GL_StretchPic( x, y, w, h, x * DIV64, y * DIV64,
- ( x + w ) * DIV64, ( y + h ) * DIV64, U32_WHITE, IMG_ForHandle( pic ) );
+void R_TileClear(int x, int y, int w, int h, qhandle_t pic)
+{
+ GL_StretchPic(x, y, w, h, x * DIV64, y * DIV64,
+ (x + w) * DIV64, (y + h) * DIV64, U32_WHITE, IMG_ForHandle(pic));
}
-void R_DrawFill8( int x, int y, int w, int h, int c ) {
- _GL_StretchPic( x, y, w, h, 0, 0, 1, 1, d_8to24table[c & 0xff], TEXNUM_WHITE, 0 );
+void R_DrawFill8(int x, int y, int w, int h, int c)
+{
+ _GL_StretchPic(x, y, w, h, 0, 0, 1, 1, d_8to24table[c & 0xff], TEXNUM_WHITE, 0);
}
-void R_DrawFill32( int x, int y, int w, int h, uint32_t color ) {
- _GL_StretchPic( x, y, w, h, 0, 0, 1, 1, color, TEXNUM_WHITE, 0 );
+void R_DrawFill32(int x, int y, int w, int h, uint32_t color)
+{
+ _GL_StretchPic(x, y, w, h, 0, 0, 1, 1, color, TEXNUM_WHITE, 0);
}
-static inline void draw_char( int x, int y, int c, qboolean alt, image_t *image ) {
+static inline void draw_char(int x, int y, int c, qboolean alt, image_t *image)
+{
float s, t;
-
- if( ( c & 127 ) == 32 ) {
+
+ if ((c & 127) == 32) {
return;
}
c |= alt << 7;
- s = ( c & 15 ) * 0.0625f;
- t = ( c >> 4 ) * 0.0625f;
- GL_StretchPic( x, y, CHAR_WIDTH, CHAR_HEIGHT, s, t,
- s + 0.0625f, t + 0.0625f, draw.colors[alt].u32, image );
+ s = (c & 15) * 0.0625f;
+ t = (c >> 4) * 0.0625f;
+ GL_StretchPic(x, y, CHAR_WIDTH, CHAR_HEIGHT, s, t,
+ s + 0.0625f, t + 0.0625f, draw.colors[alt].u32, image);
}
-void R_DrawChar( int x, int y, int flags, int c, qhandle_t font ) {
- qboolean alt = ( flags & UI_ALTCOLOR ) ? qtrue : qfalse;
- draw_char( x, y, c & 255, alt, IMG_ForHandle( font ) );
+void R_DrawChar(int x, int y, int flags, int c, qhandle_t font)
+{
+ qboolean alt = (flags & UI_ALTCOLOR) ? qtrue : qfalse;
+ draw_char(x, y, c & 255, alt, IMG_ForHandle(font));
}
-int R_DrawString( int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font ) {
- image_t *image = IMG_ForHandle( font );
- qboolean alt = ( flags & UI_ALTCOLOR ) ? qtrue : qfalse;
+int R_DrawString(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font)
+{
+ image_t *image = IMG_ForHandle(font);
+ qboolean alt = (flags & UI_ALTCOLOR) ? qtrue : qfalse;
- while( maxlen-- && *s ) {
+ while (maxlen-- && *s) {
byte c = *s++;
- draw_char( x, y, c, alt, image );
+ draw_char(x, y, c, alt, image);
x += CHAR_WIDTH;
}
@@ -272,86 +286,90 @@ int R_DrawString( int x, int y, int flags, size_t maxlen, const char *s, qhandle
image_t *r_charset;
-void Draw_Stringf( int x, int y, const char *fmt, ... ) {
+void Draw_Stringf(int x, int y, const char *fmt, ...)
+{
va_list argptr;
char buffer[MAX_STRING_CHARS];
char *string;
byte c;
float s, t;
- va_start( argptr, fmt );
- Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(buffer, sizeof(buffer), fmt, argptr);
+ va_end(argptr);
string = buffer;
- while( *string ) {
+ while (*string) {
c = *string++;
- s = ( c & 15 ) * 0.0625f;
- t = ( c >> 4 ) * 0.0625f;
+ s = (c & 15) * 0.0625f;
+ t = (c >> 4) * 0.0625f;
- GL_StretchPic( x, y, CHAR_WIDTH, CHAR_HEIGHT, s, t,
- s + 0.0625f, t + 0.0625f, U32_WHITE, r_charset );
+ GL_StretchPic(x, y, CHAR_WIDTH, CHAR_HEIGHT, s, t,
+ s + 0.0625f, t + 0.0625f, U32_WHITE, r_charset);
x += CHAR_WIDTH;
}
}
-void Draw_Stats( void ) {
+void Draw_Stats(void)
+{
int x = 10, y = 10;
- if( !r_charset ) {
+ if (!r_charset) {
qhandle_t tmp;
- tmp = R_RegisterFont( "conchars" );
- if( !tmp ) return;
- r_charset = IMG_ForHandle( tmp );
+ tmp = R_RegisterFont("conchars");
+ if (!tmp) return;
+ r_charset = IMG_ForHandle(tmp);
}
- Draw_Stringf( x, y, "Nodes visible : %i", c.nodesVisible ); y += 10;
- Draw_Stringf( x, y, "Nodes culled : %i", c.nodesCulled ); y += 10;
- Draw_Stringf( x, y, "Nodes drawn : %i", c.nodesDrawn ); y += 10;
- Draw_Stringf( x, y, "Leaves drawn : %i", c.leavesDrawn ); y += 10;
- Draw_Stringf( x, y, "Faces drawn : %i", c.facesDrawn ); y += 10;
- if( c.facesCulled ) {
- Draw_Stringf( x, y, "Faces culled : %i", c.facesCulled ); y += 10;
+ Draw_Stringf(x, y, "Nodes visible : %i", c.nodesVisible); y += 10;
+ Draw_Stringf(x, y, "Nodes culled : %i", c.nodesCulled); y += 10;
+ Draw_Stringf(x, y, "Nodes drawn : %i", c.nodesDrawn); y += 10;
+ Draw_Stringf(x, y, "Leaves drawn : %i", c.leavesDrawn); y += 10;
+ Draw_Stringf(x, y, "Faces drawn : %i", c.facesDrawn); y += 10;
+ if (c.facesCulled) {
+ Draw_Stringf(x, y, "Faces culled : %i", c.facesCulled); y += 10;
}
- if( c.boxesCulled ) {
- Draw_Stringf( x, y, "Boxes culled : %i", c.boxesCulled ); y += 10;
+ if (c.boxesCulled) {
+ Draw_Stringf(x, y, "Boxes culled : %i", c.boxesCulled); y += 10;
}
- if( c.spheresCulled ) {
- Draw_Stringf( x, y, "Spheres culled : %i", c.spheresCulled ); y += 10;
+ if (c.spheresCulled) {
+ Draw_Stringf(x, y, "Spheres culled : %i", c.spheresCulled); y += 10;
}
- if( c.rotatedBoxesCulled ) {
- Draw_Stringf( x, y, "RtBoxes culled : %i", c.rotatedBoxesCulled ); y += 10;
+ if (c.rotatedBoxesCulled) {
+ Draw_Stringf(x, y, "RtBoxes culled : %i", c.rotatedBoxesCulled); y += 10;
}
- Draw_Stringf( x, y, "Tris drawn : %i", c.trisDrawn ); y += 10;
- Draw_Stringf( x, y, "Tex switches : %i", c.texSwitches ); y += 10;
- if( c.texUploads ) {
- Draw_Stringf( x, y, "Tex uploads : %i", c.texUploads ); y += 10;
+ Draw_Stringf(x, y, "Tris drawn : %i", c.trisDrawn); y += 10;
+ Draw_Stringf(x, y, "Tex switches : %i", c.texSwitches); y += 10;
+ if (c.texUploads) {
+ Draw_Stringf(x, y, "Tex uploads : %i", c.texUploads); y += 10;
}
- if( c.batchesDrawn ) {
- Draw_Stringf( x, y, "Batches drawn: %i", c.batchesDrawn ); y += 10;
- Draw_Stringf( x, y, "Faces / batch: %i", c.facesDrawn / c.batchesDrawn );
+ if (c.batchesDrawn) {
+ Draw_Stringf(x, y, "Batches drawn: %i", c.batchesDrawn); y += 10;
+ Draw_Stringf(x, y, "Faces / batch: %i", c.facesDrawn / c.batchesDrawn);
y += 10;
- Draw_Stringf( x, y, "Tris / batch : %i", c.trisDrawn / c.batchesDrawn );
+ Draw_Stringf(x, y, "Tris / batch : %i", c.trisDrawn / c.batchesDrawn);
y += 10;
}
- Draw_Stringf( x, y, "2D batches : %i", c.batchesDrawn2D ); y += 10;
+ Draw_Stringf(x, y, "2D batches : %i", c.batchesDrawn2D); y += 10;
}
-void Draw_Lightmaps( void ) {
+void Draw_Lightmaps(void)
+{
int i, x, y;
- for( i = 0; i < lm.nummaps; i++ ) {
+ for (i = 0; i < lm.nummaps; i++) {
x = i & 1;
y = i >> 1;
- _GL_StretchPic( 256*x, 256*y, 256, 256,
- 0, 0, 1, 1, U32_WHITE, TEXNUM_LIGHTMAP+i, 0 );
+ _GL_StretchPic(256 * x, 256 * y, 256, 256,
+ 0, 0, 1, 1, U32_WHITE, TEXNUM_LIGHTMAP + i, 0);
}
}
-void Draw_Scrap( void ) {
- _GL_StretchPic( 0, 0, 256, 256,
- 0, 0, 1, 1, U32_WHITE, TEXNUM_SCRAP, if_paletted|if_transparent );
+void Draw_Scrap(void)
+{
+ _GL_StretchPic(0, 0, 256, 256,
+ 0, 0, 1, 1, U32_WHITE, TEXNUM_SCRAP, if_paletted | if_transparent);
}
#endif
diff --git a/src/gl_images.c b/src/gl_images.c
index 1c2b49f..d36b605 100644
--- a/src/gl_images.c
+++ b/src/gl_images.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -49,7 +49,7 @@ static cvar_t *gl_intensity;
static cvar_t *gl_gamma;
static cvar_t *gl_invert;
-static qboolean GL_Upload8( byte *data, int width, int height, qboolean mipmap );
+static qboolean GL_Upload8(byte *data, int width, int height, qboolean mipmap);
typedef struct {
const char *name;
@@ -65,7 +65,7 @@ static const glmode_t filterModes[] = {
{ "GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR }
};
-static const int numFilterModes = sizeof( filterModes ) / sizeof( filterModes[0] );
+static const int numFilterModes = sizeof(filterModes) / sizeof(filterModes[0]);
typedef struct {
const char *name;
@@ -81,7 +81,7 @@ static const gltmode_t alphaModes[] = {
{ "GL_RGBA2", GL_RGBA2 }
};
-static const int numAlphaModes = sizeof( alphaModes ) / sizeof( alphaModes[0] );
+static const int numAlphaModes = sizeof(alphaModes) / sizeof(alphaModes[0]);
static const gltmode_t solidModes[] = {
{ "default", 4 },
@@ -96,20 +96,21 @@ static const gltmode_t solidModes[] = {
#endif
};
-static const int numSolidModes = sizeof( solidModes ) / sizeof( solidModes[0] );
+static const int numSolidModes = sizeof(solidModes) / sizeof(solidModes[0]);
-static void gl_texturemode_changed( cvar_t *self ) {
+static void gl_texturemode_changed(cvar_t *self)
+{
int i;
image_t *image;
- for( i = 0; i < numFilterModes ; i++ ) {
- if( !Q_stricmp( filterModes[i].name, self->string ) )
+ for (i = 0; i < numFilterModes; i++) {
+ if (!Q_stricmp(filterModes[i].name, self->string))
break;
}
- if( i == numFilterModes ) {
- Com_WPrintf( "Bad texture mode: %s\n", self->string );
- Cvar_Reset( self );
+ if (i == numFilterModes) {
+ Com_WPrintf("Bad texture mode: %s\n", self->string);
+ Cvar_Reset(self);
gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
gl_filter_max = GL_LINEAR;
} else {
@@ -118,83 +119,87 @@ static void gl_texturemode_changed( cvar_t *self ) {
}
// change all the existing mipmap texture objects
- for( i = 0, image = r_images; i < r_numImages; i++, image++ ) {
- if( image->type == it_wall || image->type == it_skin ) {
- GL_BindTexture( image->texnum );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- gl_filter_min );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- gl_filter_max );
+ for (i = 0, image = r_images; i < r_numImages; i++, image++) {
+ if (image->type == it_wall || image->type == it_skin) {
+ GL_BindTexture(image->texnum);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ gl_filter_min);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ gl_filter_max);
}
}
}
-static void gl_texturemode_g( genctx_t *ctx ) {
+static void gl_texturemode_g(genctx_t *ctx)
+{
int i;
-
- for( i = 0; i < numFilterModes ; i++ ) {
- if( !Prompt_AddMatch( ctx, filterModes[i].name ) ) {
+
+ for (i = 0; i < numFilterModes; i++) {
+ if (!Prompt_AddMatch(ctx, filterModes[i].name)) {
break;
}
}
}
-static void gl_anisotropy_changed( cvar_t *self ) {
+static void gl_anisotropy_changed(cvar_t *self)
+{
int i;
image_t *image;
- if( gl_config.maxAnisotropy < 2 ) {
+ if (gl_config.maxAnisotropy < 2) {
return;
}
gl_filter_anisotropy = self->value;
- clamp( gl_filter_anisotropy, 1, gl_config.maxAnisotropy );
+ clamp(gl_filter_anisotropy, 1, gl_config.maxAnisotropy);
// change all the existing mipmap texture objects
- for( i = 0, image = r_images; i < r_numImages; i++, image++ ) {
- if( image->type == it_wall || image->type == it_skin ) {
- GL_BindTexture( image->texnum );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
- gl_filter_anisotropy );
+ for (i = 0, image = r_images; i < r_numImages; i++, image++) {
+ if (image->type == it_wall || image->type == it_skin) {
+ GL_BindTexture(image->texnum);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
+ gl_filter_anisotropy);
}
}
}
-static void gl_bilerp_chars_changed( cvar_t *self ) {
+static void gl_bilerp_chars_changed(cvar_t *self)
+{
int i;
image_t *image;
GLfloat param = self->integer ? GL_LINEAR : GL_NEAREST;
// change all the existing charset texture objects
- for( i = 0, image = r_images; i < r_numImages; i++, image++ ) {
- if( image->type == it_charset ) {
- GL_BindTexture( image->texnum );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param );
+ for (i = 0, image = r_images; i < r_numImages; i++, image++) {
+ if (image->type == it_charset) {
+ GL_BindTexture(image->texnum);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
}
}
}
-static void gl_bilerp_pics_changed( cvar_t *self ) {
+static void gl_bilerp_pics_changed(cvar_t *self)
+{
int i;
image_t *image;
GLfloat param = self->integer ? GL_LINEAR : GL_NEAREST;
// change all the existing pic texture objects
- for( i = 0, image = r_images; i < r_numImages; i++, image++ ) {
- if( image->type == it_pic ) {
- GL_BindTexture( image->texnum );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param );
+ for (i = 0, image = r_images; i < r_numImages; i++, image++) {
+ if (image->type == it_pic) {
+ GL_BindTexture(image->texnum);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
}
}
// change scrap texture object
- if( !gl_noscrap->integer ) {
+ if (!gl_noscrap->integer) {
param = self->integer > 1 ? GL_LINEAR : GL_NEAREST;
- GL_BindTexture( TEXNUM_SCRAP );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param );
+ GL_BindTexture(TEXNUM_SCRAP);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
}
}
@@ -204,26 +209,28 @@ static void gl_bilerp_pics_changed( cvar_t *self ) {
GL_TextureAlphaMode
===============
*/
-static void GL_TextureAlphaMode( void ) {
+static void GL_TextureAlphaMode(void)
+{
int i;
- for( i = 0; i < numAlphaModes; i++ ) {
- if( !Q_stricmp( alphaModes[i].name, gl_texturealphamode->string ) ) {
+ for (i = 0; i < numAlphaModes; i++) {
+ if (!Q_stricmp(alphaModes[i].name, gl_texturealphamode->string)) {
gl_tex_alpha_format = alphaModes[i].mode;
return;
}
}
- Com_WPrintf( "Bad texture alpha mode: %s\n", gl_texturealphamode->string );
- Cvar_Reset( gl_texturealphamode );
+ Com_WPrintf("Bad texture alpha mode: %s\n", gl_texturealphamode->string);
+ Cvar_Reset(gl_texturealphamode);
gl_tex_alpha_format = alphaModes[0].mode;
}
-static void gl_texturealphamode_g( genctx_t *ctx ) {
+static void gl_texturealphamode_g(genctx_t *ctx)
+{
int i;
-
- for( i = 0; i < numAlphaModes; i++ ) {
- if( !Prompt_AddMatch( ctx, alphaModes[i].name ) ) {
+
+ for (i = 0; i < numAlphaModes; i++) {
+ if (!Prompt_AddMatch(ctx, alphaModes[i].name)) {
break;
}
}
@@ -234,26 +241,28 @@ static void gl_texturealphamode_g( genctx_t *ctx ) {
GL_TextureSolidMode
===============
*/
-static void GL_TextureSolidMode( void ) {
+static void GL_TextureSolidMode(void)
+{
int i;
- for( i = 0; i < numSolidModes; i++ ) {
- if( !Q_stricmp( solidModes[i].name, gl_texturesolidmode->string ) ) {
+ for (i = 0; i < numSolidModes; i++) {
+ if (!Q_stricmp(solidModes[i].name, gl_texturesolidmode->string)) {
gl_tex_solid_format = solidModes[i].mode;
return;
}
}
- Com_WPrintf( "Bad texture solid mode: %s\n", gl_texturesolidmode->string );
- Cvar_Reset( gl_texturesolidmode );
+ Com_WPrintf("Bad texture solid mode: %s\n", gl_texturesolidmode->string);
+ Cvar_Reset(gl_texturesolidmode);
gl_tex_solid_format = solidModes[0].mode;
}
-static void gl_texturesolidmode_g( genctx_t *ctx ) {
+static void gl_texturesolidmode_g(genctx_t *ctx)
+{
int i;
-
- for( i = 0; i < numSolidModes; i++ ) {
- if( !Prompt_AddMatch( ctx, solidModes[i].name ) ) {
+
+ for (i = 0; i < numSolidModes; i++) {
+ if (!Prompt_AddMatch(ctx, solidModes[i].name)) {
break;
}
}
@@ -277,29 +286,32 @@ static int scrap_inuse[SCRAP_BLOCK_WIDTH];
static byte scrap_data[SCRAP_BLOCK_WIDTH * SCRAP_BLOCK_HEIGHT];
static qboolean scrap_dirty;
-#define Scrap_AllocBlock( w, h, s, t ) \
- GL_AllocBlock( SCRAP_BLOCK_WIDTH, SCRAP_BLOCK_HEIGHT, scrap_inuse, w, h, s, t )
+#define Scrap_AllocBlock(w, h, s, t) \
+ GL_AllocBlock(SCRAP_BLOCK_WIDTH, SCRAP_BLOCK_HEIGHT, scrap_inuse, w, h, s, t)
-static void Scrap_Init( void ) {
+static void Scrap_Init(void)
+{
// make scrap texture initially transparent
- memset( scrap_data, 255, sizeof( scrap_data ) );
+ memset(scrap_data, 255, sizeof(scrap_data));
}
-static void Scrap_Shutdown( void ) {
+static void Scrap_Shutdown(void)
+{
int i;
- for( i = 0; i < SCRAP_BLOCK_WIDTH; i++ ) {
+ for (i = 0; i < SCRAP_BLOCK_WIDTH; i++) {
scrap_inuse[i] = 0;
}
scrap_dirty = qfalse;
}
-void Scrap_Upload( void ) {
- if( !scrap_dirty ) {
+void Scrap_Upload(void)
+{
+ if (!scrap_dirty) {
return;
}
- GL_BindTexture( TEXNUM_SCRAP );
- GL_Upload8( scrap_data, SCRAP_BLOCK_WIDTH, SCRAP_BLOCK_HEIGHT, qfalse );
+ GL_BindTexture(TEXNUM_SCRAP);
+ GL_Upload8(scrap_data, SCRAP_BLOCK_WIDTH, SCRAP_BLOCK_HEIGHT, qfalse);
scrap_dirty = qfalse;
}
@@ -317,9 +329,9 @@ typedef struct {
// must be a power of 2
#define FLOODFILL_FIFO_SIZE 0x1000
-#define FLOODFILL_FIFO_MASK ( FLOODFILL_FIFO_SIZE - 1 )
+#define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)
-#define FLOODFILL_STEP( off, dx, dy ) \
+#define FLOODFILL_STEP(off, dx, dy) \
do { \
if (pos[off] == fillcolor) { \
pos[off] = 255; \
@@ -329,7 +341,7 @@ typedef struct {
} else if (pos[off] != 255) { \
fdc = pos[off]; \
} \
- } while( 0 )
+ } while(0)
/*
=================
@@ -338,15 +350,15 @@ Mod_FloodFillSkin
Fill background pixels so mipmapping doesn't have haloes
=================
*/
-static void R_FloodFillSkin( byte *skin, int skinwidth, int skinheight ) {
+static void R_FloodFillSkin(byte *skin, int skinwidth, int skinheight)
+{
byte fillcolor = *skin; // assume this is the pixel to fill
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int inpt = 0, outpt = 0;
int filledcolor = -1;
int i;
- if (filledcolor == -1)
- {
+ if (filledcolor == -1) {
filledcolor = 0;
// attempt to find opaque black
for (i = 0; i < 256; ++i)
@@ -373,11 +385,11 @@ static void R_FloodFillSkin( byte *skin, int skinwidth, int skinheight ) {
outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;
- if (x > 0) FLOODFILL_STEP( -1, -1, 0 );
- if (x < skinwidth - 1) FLOODFILL_STEP( 1, 1, 0 );
- if (y > 0) FLOODFILL_STEP( -skinwidth, 0, -1 );
- if (y < skinheight - 1) FLOODFILL_STEP( skinwidth, 0, 1 );
-
+ if (x > 0) FLOODFILL_STEP(-1, -1, 0);
+ if (x < skinwidth - 1) FLOODFILL_STEP(1, 1, 0);
+ if (y > 0) FLOODFILL_STEP(-skinwidth, 0, -1);
+ if (y < skinheight - 1) FLOODFILL_STEP(skinwidth, 0, 1);
+
skin[x + skinwidth * y] = fdc;
}
}
@@ -397,7 +409,8 @@ Transform to grayscale by replacing color components with
overall pixel luminance computed from weighted color sum
================
*/
-static void GL_GrayScaleTexture( byte *in, int inwidth, int inheight ) {
+static void GL_GrayScaleTexture(byte *in, int inwidth, int inheight)
+{
int i, c;
byte *p;
float r, g, b, y;
@@ -405,14 +418,14 @@ static void GL_GrayScaleTexture( byte *in, int inwidth, int inheight ) {
p = in;
c = inwidth * inheight;
- for( i = 0; i < c; i++, p += 4 ) {
+ for (i = 0; i < c; i++, p += 4) {
r = p[0];
g = p[1];
b = p[2];
- y = LUMINANCE( r, g, b );
- p[0] = y + ( r - y ) * colorscale;
- p[1] = y + ( g - y ) * colorscale;
- p[2] = y + ( b - y ) * colorscale;
+ y = LUMINANCE(r, g, b);
+ p[0] = y + (r - y) * colorscale;
+ p[1] = y + (g - y) * colorscale;
+ p[2] = y + (b - y) * colorscale;
}
}
@@ -424,21 +437,22 @@ Scale up the pixel values in a texture to increase the
lighting range
================
*/
-static void GL_LightScaleTexture( byte *in, int inwidth, int inheight, qboolean mipmap ) {
+static void GL_LightScaleTexture(byte *in, int inwidth, int inheight, qboolean mipmap)
+{
int i, c;
byte *p;
p = in;
c = inwidth * inheight;
- if( mipmap ) {
- for( i = 0; i < c; i++, p += 4 ) {
+ if (mipmap) {
+ for (i = 0; i < c; i++, p += 4) {
p[0] = gammaintensitytable[p[0]];
p[1] = gammaintensitytable[p[1]];
p[2] = gammaintensitytable[p[2]];
}
} else {
- for( i = 0; i < c; i++, p += 4 ) {
+ for (i = 0; i < c; i++, p += 4) {
p[0] = gammatable[p[0]];
p[1] = gammatable[p[1]];
p[2] = gammatable[p[2]];
@@ -446,17 +460,18 @@ static void GL_LightScaleTexture( byte *in, int inwidth, int inheight, qboolean
}
}
-static void GL_ColorInvertTexture( byte *in, int inwidth, int inheight ) {
+static void GL_ColorInvertTexture(byte *in, int inwidth, int inheight)
+{
int i, c;
byte *p;
p = in;
c = inwidth * inheight;
- for( i = 0; i < c; i++, p += 4 ) {
- p[0] = 255-p[0];
- p[1] = 255-p[1];
- p[2] = 255-p[2];
+ for (i = 0; i < c; i++, p += 4) {
+ p[0] = 255 - p[0];
+ p[1] = 255 - p[1];
+ p[2] = 255 - p[2];
}
}
@@ -465,7 +480,8 @@ static void GL_ColorInvertTexture( byte *in, int inwidth, int inheight ) {
GL_ResampleTexture
================
*/
-static void GL_ResampleTexture( const byte *in, int inwidth, int inheight, byte *out, int outwidth, int outheight ) {
+static void GL_ResampleTexture(const byte *in, int inwidth, int inheight, byte *out, int outwidth, int outheight)
+{
int i, j;
const byte *inrow1, *inrow2;
unsigned frac, fracstep;
@@ -473,37 +489,37 @@ static void GL_ResampleTexture( const byte *in, int inwidth, int inheight, byte
const byte *pix1, *pix2, *pix3, *pix4;
float heightScale;
- if( outwidth > MAX_TEXTURE_SIZE ) {
- Com_Error( ERR_FATAL, "%s: outwidth > %d", __func__, MAX_TEXTURE_SIZE );
+ if (outwidth > MAX_TEXTURE_SIZE) {
+ Com_Error(ERR_FATAL, "%s: outwidth > %d", __func__, MAX_TEXTURE_SIZE);
}
fracstep = inwidth * 0x10000 / outwidth;
frac = fracstep >> 2;
- for( i = 0; i < outwidth; i++ ) {
- p1[i] = 4 * ( frac >> 16 );
+ for (i = 0; i < outwidth; i++) {
+ p1[i] = 4 * (frac >> 16);
frac += fracstep;
}
- frac = 3 * ( fracstep >> 2 );
- for( i = 0; i < outwidth; i++ ) {
- p2[i] = 4 * ( frac >> 16 );
+ frac = 3 * (fracstep >> 2);
+ for (i = 0; i < outwidth; i++) {
+ p2[i] = 4 * (frac >> 16);
frac += fracstep;
}
- heightScale = ( float )inheight / outheight;
+ heightScale = (float)inheight / outheight;
inwidth <<= 2;
- for( i = 0; i < outheight; i++ ) {
- inrow1 = in + inwidth * ( int )( ( i + 0.25f ) * heightScale );
- inrow2 = in + inwidth * ( int )( ( i + 0.75f ) * heightScale );
- for( j = 0; j < outwidth; j++ ) {
+ for (i = 0; i < outheight; i++) {
+ inrow1 = in + inwidth * (int)((i + 0.25f) * heightScale);
+ inrow2 = in + inwidth * (int)((i + 0.75f) * heightScale);
+ for (j = 0; j < outwidth; j++) {
pix1 = inrow1 + p1[j];
pix2 = inrow1 + p2[j];
pix3 = inrow2 + p1[j];
pix4 = inrow2 + p2[j];
- out[0] = ( pix1[0] + pix2[0] + pix3[0] + pix4[0] ) >> 2;
- out[1] = ( pix1[1] + pix2[1] + pix3[1] + pix4[1] ) >> 2;
- out[2] = ( pix1[2] + pix2[2] + pix3[2] + pix4[2] ) >> 2;
- out[3] = ( pix1[3] + pix2[3] + pix3[3] + pix4[3] ) >> 2;
+ out[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2;
+ out[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2;
+ out[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2]) >> 2;
+ out[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3]) >> 2;
out += 4;
}
}
@@ -516,75 +532,80 @@ GL_MipMap
Operates in place, quartering the size of the texture
================
*/
-static void GL_MipMap( byte *in, int width, int height ) {
+static void GL_MipMap(byte *in, int width, int height)
+{
int i, j;
byte *out;
width <<= 2;
height >>= 1;
out = in;
- for( i = 0; i < height; i++, in += width ) {
- for( j = 0; j < width; j += 8, out += 4, in += 8 ) {
- out[0] = ( in[0] + in[4] + in[width+0] + in[width+4] ) >> 2;
- out[1] = ( in[1] + in[5] + in[width+1] + in[width+5] ) >> 2;
- out[2] = ( in[2] + in[6] + in[width+2] + in[width+6] ) >> 2;
- out[3] = ( in[3] + in[7] + in[width+3] + in[width+7] ) >> 2;
+ for (i = 0; i < height; i++, in += width) {
+ for (j = 0; j < width; j += 8, out += 4, in += 8) {
+ out[0] = (in[0] + in[4] + in[width + 0] + in[width + 4]) >> 2;
+ out[1] = (in[1] + in[5] + in[width + 1] + in[width + 5]) >> 2;
+ out[2] = (in[2] + in[6] + in[width + 2] + in[width + 6]) >> 2;
+ out[3] = (in[3] + in[7] + in[width + 3] + in[width + 7]) >> 2;
}
}
}
// returns true if image should not be bilinear filtered
// (useful for small images in scarp, charsets, etc)
-static inline qboolean is_nearest( void ) {
- if( gls.texnum[gls.tmu] == TEXNUM_SCRAP && gl_bilerp_pics->integer <= 1 ) {
+static inline qboolean is_nearest(void)
+{
+ if (gls.texnum[gls.tmu] == TEXNUM_SCRAP && gl_bilerp_pics->integer <= 1) {
return qtrue; // hack for scrap texture
}
- if( !upload_image ) {
+ if (!upload_image) {
return qfalse;
}
- if( upload_image->type == it_charset ) {
+ if (upload_image->type == it_charset) {
return !gl_bilerp_chars->integer;
}
- if( upload_image->type == it_pic ) {
+ if (upload_image->type == it_pic) {
return !gl_bilerp_pics->integer;
}
return qfalse;
}
-static inline qboolean is_wall( void ) {
- if( !upload_image ) {
+static inline qboolean is_wall(void)
+{
+ if (!upload_image) {
return qfalse;
}
- if( upload_image->type != it_wall ) {
+ if (upload_image->type != it_wall) {
return qfalse; // not a wall texture
}
- if( !upload_texinfo ) {
+ if (!upload_texinfo) {
return qtrue; // don't know what type of surface it is
- }
- if( upload_texinfo->c.flags & (SURF_SKY|SURF_WARP) ) {
+ }
+ if (upload_texinfo->c.flags & (SURF_SKY | SURF_WARP)) {
return qfalse; // don't grayscale or invert sky and liquid surfaces
}
return qtrue;
}
-static inline qboolean is_downsample( void ) {
- if( !upload_image ) {
+static inline qboolean is_downsample(void)
+{
+ if (!upload_image) {
return qtrue;
}
- if( upload_image->type != it_skin ) {
+ if (upload_image->type != it_skin) {
return qtrue; // not a skin
}
return !!gl_downsample_skins->integer;
}
-static inline qboolean is_alpha( byte *data, int width, int height ) {
+static inline qboolean is_alpha(byte *data, int width, int height)
+{
int i, c;
byte *scan;
c = width * height;
scan = data + 3;
- for( i = 0; i < c; i++, scan += 4 ) {
- if( *scan != 255 ) {
+ for (i = 0; i < c; i++, scan += 4) {
+ if (*scan != 255) {
return qtrue;
}
}
@@ -597,7 +618,8 @@ static inline qboolean is_alpha( byte *data, int width, int height ) {
GL_Upload32
===============
*/
-static qboolean GL_Upload32( byte *data, int width, int height, qboolean mipmap ) {
+static qboolean GL_Upload32(byte *data, int width, int height, qboolean mipmap)
+{
byte *scaled;
int scaled_width, scaled_height;
int comp;
@@ -605,20 +627,20 @@ static qboolean GL_Upload32( byte *data, int width, int height, qboolean mipmap
int maxsize;
// find the next-highest power of two
- scaled_width = npot32( width );
- scaled_height = npot32( height );
+ scaled_width = npot32(width);
+ scaled_height = npot32(height);
// save the flag indicating if costly resampling can be avoided
picmip = scaled_width == width && scaled_height == height;
maxsize = gl_config.maxTextureSize;
- if( mipmap && is_downsample() ) {
+ if (mipmap && is_downsample()) {
// round world textures down, if requested
- if( gl_round_down->integer ) {
- if( scaled_width > width )
+ if (gl_round_down->integer) {
+ if (scaled_width > width)
scaled_width >>= 1;
- if( scaled_height > height )
+ if (scaled_height > height)
scaled_height >>= 1;
}
@@ -626,23 +648,23 @@ static qboolean GL_Upload32( byte *data, int width, int height, qboolean mipmap
scaled_width >>= gl_picmip->integer;
scaled_height >>= gl_picmip->integer;
- if( gl_maxmip->integer > 0 ) {
- maxsize = 1 << Cvar_ClampInteger( gl_maxmip, 1, 12 );
- if( maxsize > gl_config.maxTextureSize ) {
+ if (gl_maxmip->integer > 0) {
+ maxsize = 1 << Cvar_ClampInteger(gl_maxmip, 1, 12);
+ if (maxsize > gl_config.maxTextureSize) {
maxsize = gl_config.maxTextureSize;
}
}
}
// don't ever bother with >256 textures
- while( scaled_width > maxsize || scaled_height > maxsize ) {
+ while (scaled_width > maxsize || scaled_height > maxsize) {
scaled_width >>= 1;
scaled_height >>= 1;
}
- if( scaled_width < 1 )
+ if (scaled_width < 1)
scaled_width = 1;
- if( scaled_height < 1 )
+ if (scaled_height < 1)
scaled_height = 1;
upload_width = scaled_width;
@@ -650,86 +672,85 @@ static qboolean GL_Upload32( byte *data, int width, int height, qboolean mipmap
// set colorscale and lightscale before mipmap
comp = gl_tex_solid_format;
- if( is_wall() && colorscale != 1 ) {
- GL_GrayScaleTexture( data, width, height );
- if( colorscale == 0 ) {
+ if (is_wall() && colorscale != 1) {
+ GL_GrayScaleTexture(data, width, height);
+ if (colorscale == 0) {
comp = GL_LUMINANCE;
}
}
- if( !( r_config.flags & QVF_GAMMARAMP ) &&
- ( mipmap || gl_gamma_scale_pics->integer ) )
- {
- GL_LightScaleTexture( data, width, height, mipmap );
+ if (!(r_config.flags & QVF_GAMMARAMP) &&
+ (mipmap || gl_gamma_scale_pics->integer)) {
+ GL_LightScaleTexture(data, width, height, mipmap);
}
- if( is_wall() && gl_invert->integer ) {
- GL_ColorInvertTexture( data, width, height );
+ if (is_wall() && gl_invert->integer) {
+ GL_ColorInvertTexture(data, width, height);
}
- if( scaled_width == width && scaled_height == height ) {
+ if (scaled_width == width && scaled_height == height) {
// optimized case, do nothing
scaled = data;
- } else if( picmip ) {
+ } else if (picmip) {
// optimized case, use faster mipmap operation
scaled = data;
- while( width > scaled_width || height > scaled_height ) {
- GL_MipMap( scaled, width, height );
+ while (width > scaled_width || height > scaled_height) {
+ GL_MipMap(scaled, width, height);
width >>= 1;
height >>= 1;
}
} else {
- scaled = FS_AllocTempMem( scaled_width * scaled_height * 4 );
- GL_ResampleTexture( data, width, height, scaled,
- scaled_width, scaled_height );
+ scaled = FS_AllocTempMem(scaled_width * scaled_height * 4);
+ GL_ResampleTexture(data, width, height, scaled,
+ scaled_width, scaled_height);
}
// scan the texture for any non-255 alpha
- isalpha = is_alpha( scaled, scaled_width, scaled_height );
- if( isalpha ) {
+ isalpha = is_alpha(scaled, scaled_width, scaled_height);
+ if (isalpha) {
comp = gl_tex_alpha_format;
}
- qglTexImage2D( GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, scaled );
+ qglTexImage2D(GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, scaled);
c.texUploads++;
- if( mipmap ) {
+ if (mipmap) {
int miplevel = 0;
- while( scaled_width > 1 || scaled_height > 1 ) {
- GL_MipMap( scaled, scaled_width, scaled_height );
+ while (scaled_width > 1 || scaled_height > 1) {
+ GL_MipMap(scaled, scaled_width, scaled_height);
scaled_width >>= 1;
scaled_height >>= 1;
- if( scaled_width < 1 )
+ if (scaled_width < 1)
scaled_width = 1;
- if( scaled_height < 1 )
+ if (scaled_height < 1)
scaled_height = 1;
miplevel++;
- qglTexImage2D( GL_TEXTURE_2D, miplevel, comp, scaled_width,
- scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled );
+ qglTexImage2D(GL_TEXTURE_2D, miplevel, comp, scaled_width,
+ scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
}
}
- if( mipmap ) {
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max );
-
- if( gl_config.maxAnisotropy >= 2 ) {
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
- gl_filter_anisotropy );
+ if (mipmap) {
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
+
+ if (gl_config.maxAnisotropy >= 2) {
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
+ gl_filter_anisotropy);
}
- } else if( is_nearest() ) {
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ } else if (is_nearest()) {
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} else {
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
-
- if( scaled != data ) {
- FS_FreeTempMem( scaled );
+
+ if (scaled != data) {
+ FS_FreeTempMem(scaled);
}
return isalpha;
@@ -742,35 +763,36 @@ GL_Upload8
Returns has_alpha
===============
*/
-static qboolean GL_Upload8( byte *data, int width, int height, qboolean mipmap ) {
- byte buffer[MAX_PALETTED_PIXELS*4];
+static qboolean GL_Upload8(byte *data, int width, int height, qboolean mipmap)
+{
+ byte buffer[MAX_PALETTED_PIXELS * 4];
byte *dest;
int i, s;
int p;
s = width * height;
- if( s > MAX_PALETTED_PIXELS ) {
+ if (s > MAX_PALETTED_PIXELS) {
// should never happen
- Com_Error( ERR_FATAL, "GL_Upload8: too large" );
+ Com_Error(ERR_FATAL, "GL_Upload8: too large");
}
dest = buffer;
- for( i = 0; i < s; i++ ) {
+ for (i = 0; i < s; i++) {
p = data[i];
- *( uint32_t * )dest = d_8to24table[p];
+ *(uint32_t *)dest = d_8to24table[p];
- if (p == 255) {
+ if (p == 255) {
// transparent, so scan around for another color
// to avoid alpha fringes
// FIXME: do a full flood fill so mips work...
- if (i > width && data[i-width] != 255)
- p = data[i-width];
- else if (i < s-width && data[i+width] != 255)
- p = data[i+width];
- else if (i > 0 && data[i-1] != 255)
- p = data[i-1];
- else if (i < s-1 && data[i+1] != 255)
- p = data[i+1];
+ if (i > width && data[i - width] != 255)
+ p = data[i - width];
+ else if (i < s - width && data[i + width] != 255)
+ p = data[i + width];
+ else if (i > 0 && data[i - 1] != 255)
+ p = data[i - 1];
+ else if (i < s - 1 && data[i + 1] != 255)
+ p = data[i + 1];
else
p = 0;
// copy rgb components
@@ -782,7 +804,7 @@ static qboolean GL_Upload8( byte *data, int width, int height, qboolean mipmap )
dest += 4;
}
- return GL_Upload32( buffer, width, height, mipmap );
+ return GL_Upload32(buffer, width, height, mipmap);
}
@@ -791,28 +813,28 @@ static qboolean GL_Upload8( byte *data, int width, int height, qboolean mipmap )
IMG_Load
================
*/
-void IMG_Load( image_t *image, byte *pic, int width, int height ) {
+void IMG_Load(image_t *image, byte *pic, int width, int height)
+{
qboolean mipmap, transparent;
byte *src, *dst, *ptr;
int i, j, s, t;
- if( !pic ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!pic) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
upload_image = image;
// load small 8-bit pics onto the scrap
- if( image->type == it_pic && ( image->flags & if_paletted ) &&
- width < 64 && height < 64 && !gl_noscrap->integer )
- {
- if( Scrap_AllocBlock( width, height, &s, &t ) ) {
+ if (image->type == it_pic && (image->flags & if_paletted) &&
+ width < 64 && height < 64 && !gl_noscrap->integer) {
+ if (Scrap_AllocBlock(width, height, &s, &t)) {
src = pic;
dst = &scrap_data[t * SCRAP_BLOCK_WIDTH + s];
- for( i = 0; i < height; i++ ) {
+ for (i = 0; i < height; i++) {
ptr = dst;
- for( j = 0; j < width; j++ ) {
- *ptr++ = *src++;
+ for (j = 0; j < width; j++) {
+ *ptr++ = *src++;
}
dst += SCRAP_BLOCK_WIDTH;
}
@@ -821,13 +843,13 @@ void IMG_Load( image_t *image, byte *pic, int width, int height ) {
image->upload_width = width;
image->upload_height = height;
image->flags |= if_scrap | if_transparent;
- image->sl = ( s + 0.01f ) / ( float )SCRAP_BLOCK_WIDTH;
- image->sh = ( s + width - 0.01f ) / ( float )SCRAP_BLOCK_WIDTH;
- image->tl = ( t + 0.01f ) / ( float )SCRAP_BLOCK_HEIGHT;
- image->th = ( t + height - 0.01f ) / ( float )SCRAP_BLOCK_HEIGHT;
+ image->sl = (s + 0.01f) / (float)SCRAP_BLOCK_WIDTH;
+ image->sh = (s + width - 0.01f) / (float)SCRAP_BLOCK_WIDTH;
+ image->tl = (t + 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
+ image->th = (t + height - 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
scrap_dirty = qtrue;
- if( !gl_static.registering ) {
+ if (!gl_static.registering) {
Scrap_Upload();
}
@@ -836,18 +858,18 @@ void IMG_Load( image_t *image, byte *pic, int width, int height ) {
}
}
- if( image->type == it_skin && ( image->flags & if_paletted ) )
- R_FloodFillSkin( pic, width, height );
+ if (image->type == it_skin && (image->flags & if_paletted))
+ R_FloodFillSkin(pic, width, height);
- mipmap = ( image->type == it_wall || image->type == it_skin );
- image->texnum = ( image - r_images );
- GL_BindTexture( image->texnum );
- if( image->flags & if_paletted ) {
- transparent = GL_Upload8( pic, width, height, mipmap );
+ mipmap = (image->type == it_wall || image->type == it_skin);
+ image->texnum = (image - r_images);
+ GL_BindTexture(image->texnum);
+ if (image->flags & if_paletted) {
+ transparent = GL_Upload8(pic, width, height, mipmap);
} else {
- transparent = GL_Upload32( pic, width, height, mipmap );
+ transparent = GL_Upload32(pic, width, height, mipmap);
}
- if( transparent ) {
+ if (transparent) {
image->flags |= if_transparent;
}
image->upload_width = upload_width; // after power of 2 and scales
@@ -860,41 +882,44 @@ void IMG_Load( image_t *image, byte *pic, int width, int height ) {
upload_image = NULL;
}
-void IMG_Unload( image_t *image ) {
- if( image->texnum > 0 && image->texnum < MAX_RIMAGES ) {
- qglDeleteTextures( 1, &image->texnum );
+void IMG_Unload(image_t *image)
+{
+ if (image->texnum > 0 && image->texnum < MAX_RIMAGES) {
+ qglDeleteTextures(1, &image->texnum);
image->texnum = 0;
}
}
-static void GL_BuildIntensityTable( void ) {
+static void GL_BuildIntensityTable(void)
+{
int i, j;
float f;
- f = Cvar_ClampValue( gl_intensity, 1, 5 );
+ f = Cvar_ClampValue(gl_intensity, 1, 5);
gl_static.inverse_intensity = 1 / f;
- for( i = 0; i < 256; i++ ) {
+ for (i = 0; i < 256; i++) {
j = i * f;
- if( j > 255 ) {
+ if (j > 255) {
j = 255;
}
intensitytable[i] = j;
}
}
-static void GL_BuildGammaTables( void ) {
+static void GL_BuildGammaTables(void)
+{
int i;
float inf, g = gl_gamma->value;
- if( g == 1.0f ) {
- for( i = 0; i < 256; i++ ) {
+ if (g == 1.0f) {
+ for (i = 0; i < 256; i++) {
gammatable[i] = i;
gammaintensitytable[i] = intensitytable[i];
}
} else {
- for( i = 0; i < 256; i++ ) {
- inf = 255 * pow( ( i + 0.5 ) / 255.5, g ) + 0.5;
- if( inf > 255 ) {
+ for (i = 0; i < 256; i++) {
+ inf = 255 * pow((i + 0.5) / 255.5, g) + 0.5;
+ if (inf > 255) {
inf = 255;
}
gammatable[i] = inf;
@@ -903,32 +928,34 @@ static void GL_BuildGammaTables( void ) {
}
}
-static void gl_gamma_changed( cvar_t *self ) {
+static void gl_gamma_changed(cvar_t *self)
+{
GL_BuildGammaTables();
- VID_UpdateGamma( gammatable );
+ VID_UpdateGamma(gammatable);
}
static const byte dottexture[8][8] = {
- {0,0,0,0,0,0,0,0},
- {0,0,1,1,0,0,0,0},
- {0,1,1,1,1,0,0,0},
- {0,1,1,1,1,0,0,0},
- {0,0,1,1,0,0,0,0},
- {0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0},
+ {0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 1, 1, 0, 0, 0, 0},
+ {0, 1, 1, 1, 1, 0, 0, 0},
+ {0, 1, 1, 1, 1, 0, 0, 0},
+ {0, 0, 1, 1, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0},
};
-static void GL_InitDefaultTexture( void ) {
+static void GL_InitDefaultTexture(void)
+{
int i, j;
- byte pixels[8*8*4];
+ byte pixels[8 * 8 * 4];
byte *dst;
image_t *ntx;
dst = pixels;
- for( i = 0; i < 8; i++ ) {
- for( j = 0; j < 8; j++ ) {
- dst[0] = dottexture[ i & 3 ][ j & 3 ] * 255;
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ dst[0] = dottexture[i & 3][j & 3] * 255;
dst[1] = 0;
dst[2] = 0;
dst[3] = 255;
@@ -936,8 +963,8 @@ static void GL_InitDefaultTexture( void ) {
}
}
- GL_BindTexture( TEXNUM_DEFAULT );
- GL_Upload32( pixels, 8, 8, qtrue );
+ GL_BindTexture(TEXNUM_DEFAULT);
+ GL_Upload32(pixels, 8, 8, qtrue);
// fill in notexture image
ntx = R_NOTEXTURE;
@@ -952,72 +979,75 @@ static void GL_InitDefaultTexture( void ) {
ntx->th = 1;
}
-static void GL_InitParticleTexture( void ) {
- byte pixels[16*16*4];
+static void GL_InitParticleTexture(void)
+{
+ byte pixels[16 * 16 * 4];
byte *dst;
float x, y, f;
int i, j;
dst = pixels;
- for( i = 0; i < 16; i++ ) {
- for( j = 0; j < 16; j++ ) {
- x = j - 16/2 + 0.5f;
- y = i - 16/2 + 0.5f;
- f = sqrt( x * x + y * y );
- f = 1.0f - f / ( 16/2 - 0.5f );
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ x = j - 16 / 2 + 0.5f;
+ y = i - 16 / 2 + 0.5f;
+ f = sqrt(x * x + y * y);
+ f = 1.0f - f / (16 / 2 - 0.5f);
dst[0] = 255;
dst[1] = 255;
dst[2] = 255;
- dst[3] = 255 * clamp( f, 0, 1 );
+ dst[3] = 255 * clamp(f, 0, 1);
dst += 4;
}
}
- GL_BindTexture( TEXNUM_PARTICLE );
- GL_Upload32( pixels, 16, 16, qfalse );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
+ GL_BindTexture(TEXNUM_PARTICLE);
+ GL_Upload32(pixels, 16, 16, qfalse);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
-static void GL_InitWhiteImage( void ) {
+static void GL_InitWhiteImage(void)
+{
uint32_t pixel;
pixel = U32_WHITE;
- GL_BindTexture( TEXNUM_WHITE );
- GL_Upload32( ( byte * )&pixel, 1, 1, qfalse );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ GL_BindTexture(TEXNUM_WHITE);
+ GL_Upload32((byte *)&pixel, 1, 1, qfalse);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pixel = U32_BLACK;
- GL_BindTexture( TEXNUM_BLACK );
- GL_Upload32( ( byte * )&pixel, 1, 1, qfalse );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ GL_BindTexture(TEXNUM_BLACK);
+ GL_Upload32((byte *)&pixel, 1, 1, qfalse);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
-static void GL_InitBeamTexture( void ) {
- byte pixels[16*16*4];
+static void GL_InitBeamTexture(void)
+{
+ byte pixels[16 * 16 * 4];
byte *dst;
float f;
int i, j;
dst = pixels;
- for( i = 0; i < 16; i++ ) {
- for( j = 0; j < 16; j++ ) {
- f = abs( j - 16/2 ) - 0.5f;
- f = 1.0f - f / ( 16/2 - 2.5f );
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ f = abs(j - 16 / 2) - 0.5f;
+ f = 1.0f - f / (16 / 2 - 2.5f);
dst[0] = 255;
dst[1] = 255;
dst[2] = 255;
- dst[3] = 255 * clamp( f, 0, 1 );
+ dst[3] = 255 * clamp(f, 0, 1);
dst += 4;
}
}
-
- GL_BindTexture( TEXNUM_BEAM );
- GL_Upload32( pixels, 16, 16, qfalse );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+ GL_BindTexture(TEXNUM_BEAM);
+ GL_Upload32(pixels, 16, 16, qfalse);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
/*
@@ -1025,38 +1055,39 @@ static void GL_InitBeamTexture( void ) {
GL_InitImages
===============
*/
-void GL_InitImages( void ) {
- gl_bilerp_chars = Cvar_Get( "gl_bilerp_chars", "0", 0 );
+void GL_InitImages(void)
+{
+ gl_bilerp_chars = Cvar_Get("gl_bilerp_chars", "0", 0);
gl_bilerp_chars->changed = gl_bilerp_chars_changed;
- gl_bilerp_pics = Cvar_Get( "gl_bilerp_pics", "1", 0 );
+ gl_bilerp_pics = Cvar_Get("gl_bilerp_pics", "1", 0);
gl_bilerp_pics->changed = gl_bilerp_pics_changed;
- gl_texturemode = Cvar_Get( "gl_texturemode",
- "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE );
+ gl_texturemode = Cvar_Get("gl_texturemode",
+ "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE);
gl_texturemode->changed = gl_texturemode_changed;
gl_texturemode->generator = gl_texturemode_g;
- gl_anisotropy = Cvar_Get( "gl_anisotropy", "1", 0 );
+ gl_anisotropy = Cvar_Get("gl_anisotropy", "1", 0);
gl_anisotropy->changed = gl_anisotropy_changed;
- gl_noscrap = Cvar_Get( "gl_noscrap", "0", CVAR_FILES );
- gl_round_down = Cvar_Get( "gl_round_down", "0", CVAR_FILES );
- gl_picmip = Cvar_Get( "gl_picmip", "0", CVAR_FILES );
- gl_maxmip = Cvar_Get( "gl_maxmip", "0", CVAR_FILES );
- gl_downsample_skins = Cvar_Get( "gl_downsample_skins", "1", CVAR_FILES );
- gl_gamma_scale_pics = Cvar_Get( "gl_gamma_scale_pics", "0", CVAR_FILES );
- gl_texturealphamode = Cvar_Get( "gl_texturealphamode",
- "default", CVAR_ARCHIVE|CVAR_FILES );
+ gl_noscrap = Cvar_Get("gl_noscrap", "0", CVAR_FILES);
+ gl_round_down = Cvar_Get("gl_round_down", "0", CVAR_FILES);
+ gl_picmip = Cvar_Get("gl_picmip", "0", CVAR_FILES);
+ gl_maxmip = Cvar_Get("gl_maxmip", "0", CVAR_FILES);
+ gl_downsample_skins = Cvar_Get("gl_downsample_skins", "1", CVAR_FILES);
+ gl_gamma_scale_pics = Cvar_Get("gl_gamma_scale_pics", "0", CVAR_FILES);
+ gl_texturealphamode = Cvar_Get("gl_texturealphamode",
+ "default", CVAR_ARCHIVE | CVAR_FILES);
gl_texturealphamode->generator = gl_texturealphamode_g;
- gl_texturesolidmode = Cvar_Get( "gl_texturesolidmode",
- "default", CVAR_ARCHIVE|CVAR_FILES );
+ gl_texturesolidmode = Cvar_Get("gl_texturesolidmode",
+ "default", CVAR_ARCHIVE | CVAR_FILES);
gl_texturesolidmode->generator = gl_texturesolidmode_g;
- gl_saturation = Cvar_Get( "gl_saturation", "1", CVAR_FILES );
- gl_intensity = Cvar_Get( "intensity", "1", CVAR_FILES );
- gl_invert = Cvar_Get( "gl_invert", "0", CVAR_FILES );
- if( r_config.flags & QVF_GAMMARAMP ) {
- gl_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE );
+ gl_saturation = Cvar_Get("gl_saturation", "1", CVAR_FILES);
+ gl_intensity = Cvar_Get("intensity", "1", CVAR_FILES);
+ gl_invert = Cvar_Get("gl_invert", "0", CVAR_FILES);
+ if (r_config.flags & QVF_GAMMARAMP) {
+ gl_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE);
gl_gamma->changed = gl_gamma_changed;
gl_gamma->flags &= ~CVAR_FILES;
} else {
- gl_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE|CVAR_FILES );
+ gl_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE | CVAR_FILES);
}
IMG_Init();
@@ -1065,22 +1096,22 @@ void GL_InitImages( void ) {
GL_BuildIntensityTable();
- if( r_config.flags & QVF_GAMMARAMP ) {
- gl_gamma_changed( gl_gamma );
+ if (r_config.flags & QVF_GAMMARAMP) {
+ gl_gamma_changed(gl_gamma);
} else {
GL_BuildGammaTables();
}
// FIXME: the name 'saturation' is misleading in this context
- colorscale = Cvar_ClampValue( gl_saturation, 0, 1 );
+ colorscale = Cvar_ClampValue(gl_saturation, 0, 1);
GL_TextureAlphaMode();
GL_TextureSolidMode();
- gl_texturemode_changed( gl_texturemode );
- gl_anisotropy_changed( gl_anisotropy );
- gl_bilerp_chars_changed( gl_bilerp_chars );
- gl_bilerp_pics_changed( gl_bilerp_pics );
+ gl_texturemode_changed(gl_texturemode);
+ gl_anisotropy_changed(gl_anisotropy);
+ gl_bilerp_chars_changed(gl_bilerp_chars);
+ gl_bilerp_pics_changed(gl_bilerp_pics);
upload_image = NULL;
upload_texinfo = NULL;
@@ -1102,7 +1133,8 @@ extern image_t *r_charset;
GL_ShutdownImages
===============
*/
-void GL_ShutdownImages( void ) {
+void GL_ShutdownImages(void)
+{
GLuint texnums[NUM_TEXNUMS];
int i, j;
@@ -1116,11 +1148,11 @@ void GL_ShutdownImages( void ) {
gl_gamma->changed = NULL;
// unbind everything
- qglActiveTextureARB( GL_TEXTURE1_ARB );
- qglBindTexture( GL_TEXTURE_2D, 0 );
- qglActiveTextureARB( GL_TEXTURE0_ARB );
- qglBindTexture( GL_TEXTURE_2D, 0 );
- for( i = 0; i < MAX_TMUS; i++ ) {
+ qglActiveTextureARB(GL_TEXTURE1_ARB);
+ qglBindTexture(GL_TEXTURE_2D, 0);
+ qglActiveTextureARB(GL_TEXTURE0_ARB);
+ qglBindTexture(GL_TEXTURE_2D, 0);
+ for (i = 0; i < MAX_TMUS; i++) {
gls.texnum[i] = 0;
gls.texenv[i] = 0;
}
@@ -1128,10 +1160,10 @@ void GL_ShutdownImages( void ) {
// delete auto textures
j = TEXNUM_LIGHTMAP + lm.highwater - TEXNUM_DEFAULT;
- for( i = 0; i < j; i++ ) {
+ for (i = 0; i < j; i++) {
texnums[i] = TEXNUM_DEFAULT + i;
}
- qglDeleteTextures( j, texnums );
+ qglDeleteTextures(j, texnums);
lm.highwater = 0;
diff --git a/src/gl_local.h b/src/gl_local.h
index 51b4f2d..7c8b722 100644
--- a/src/gl_local.h
+++ b/src/gl_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -37,7 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/*
* gl_main.c
- *
+ *
*/
#define MAX_TMUS 2
@@ -55,8 +55,8 @@ typedef struct {
float entity_modulate;
float inverse_intensity;
float sintab[256];
-#define TAB_SIN(x) gl_static.sintab[(x)&255]
-#define TAB_COS(x) gl_static.sintab[((x)+64)&255]
+#define TAB_SIN(x) gl_static.sintab[(x) & 255]
+#define TAB_COS(x) gl_static.sintab[((x) + 64) & 255]
byte latlngtab[NUMVERTEXNORMALS][2];
byte lightstylemap[MAX_LIGHTSTYLES];
} glStatic_t;
@@ -168,21 +168,21 @@ typedef enum {
CULL_CLIP
} glCullResult_t;
-glCullResult_t GL_CullBox( vec3_t bounds[2] );
-glCullResult_t GL_CullSphere( const vec3_t origin, float radius );
-glCullResult_t GL_CullLocalBox( const vec3_t origin, vec3_t bounds[2] );
+glCullResult_t GL_CullBox(vec3_t bounds[2]);
+glCullResult_t GL_CullSphere(const vec3_t origin, float radius);
+glCullResult_t GL_CullLocalBox(const vec3_t origin, vec3_t bounds[2]);
-//void GL_DrawBox( const vec3_t origin, vec3_t bounds[2] );
+//void GL_DrawBox(const vec3_t origin, vec3_t bounds[2]);
-qboolean GL_AllocBlock( int width, int height, int *inuse,
- int w, int h, int *s, int *t );
+qboolean GL_AllocBlock(int width, int height, int *inuse,
+ int w, int h, int *s, int *t);
-void GL_ClearErrors( void );
-qboolean GL_ShowErrors( const char *func );
+void GL_ClearErrors(void);
+qboolean GL_ShowErrors(const char *func);
/*
* gl_model.c
- *
+ *
*/
typedef struct maliastc_s {
@@ -218,11 +218,11 @@ typedef struct maliasmesh_s {
/*
* gl_surf.c
- *
+ *
*/
#define DLIGHT_CUTOFF 64
-#define LIGHT_STYLE(surf,i) \
+#define LIGHT_STYLE(surf, i) \
&glr.fd.lightstyles[gl_static.lightstylemap[(surf)->styles[i]]]
#define LM_MAX_LIGHTMAPS 32
@@ -240,15 +240,15 @@ typedef struct {
extern lightmap_builder_t lm;
-void GL_AdjustColor( vec3_t color );
-void GL_BeginLights( void );
-void GL_EndLights( void );
-void GL_PushLights( mface_t *surf );
+void GL_AdjustColor(vec3_t color);
+void GL_BeginLights(void);
+void GL_EndLights(void);
+void GL_PushLights(mface_t *surf);
-void LM_RebuildSurfaces( void );
+void LM_RebuildSurfaces(void);
-void GL_LoadWorld( const char *name );
-void GL_FreeWorld( void );
+void GL_LoadWorld(const char *name);
+void GL_FreeWorld(void);
/*
* gl_state.c
@@ -262,15 +262,15 @@ typedef enum {
typedef enum {
GLS_DEFAULT = 0,
- GLS_DEPTHMASK_FALSE = ( 1 << 0 ),
- GLS_DEPTHTEST_DISABLE = ( 1 << 1 ),
- GLS_BLEND_BLEND = ( 1 << 2 ),
- GLS_BLEND_ADD = ( 1 << 3 ),
- GLS_BLEND_MODULATE = ( 1 << 4 ),
- GLS_ALPHATEST_ENABLE = ( 1 << 5 )
+ GLS_DEPTHMASK_FALSE = (1 << 0),
+ GLS_DEPTHTEST_DISABLE = (1 << 1),
+ GLS_BLEND_BLEND = (1 << 2),
+ GLS_BLEND_ADD = (1 << 3),
+ GLS_BLEND_MODULATE = (1 << 4),
+ GLS_ALPHATEST_ENABLE = (1 << 5)
} glStateBits_t;
-#define GLS_BLEND_MASK (GLS_BLEND_BLEND|GLS_BLEND_ADD|GLS_BLEND_MODULATE)
+#define GLS_BLEND_MASK (GLS_BLEND_BLEND | GLS_BLEND_ADD | GLS_BLEND_MODULATE)
typedef struct {
int tmu;
@@ -283,21 +283,21 @@ typedef struct {
extern glState_t gls;
-void GL_BindTexture( int texnum );
-void GL_SelectTMU( int tmu );
-void GL_TexEnv( GLenum texenv );
-void GL_CullFace( glCullFace_t cull );
-void GL_Bits( glStateBits_t bits );
-void GL_Setup2D( void );
-void GL_Setup3D( void );
+void GL_BindTexture(int texnum);
+void GL_SelectTMU(int tmu);
+void GL_TexEnv(GLenum texenv);
+void GL_CullFace(glCullFace_t cull);
+void GL_Bits(glStateBits_t bits);
+void GL_Setup2D(void);
+void GL_Setup3D(void);
-void GL_SetDefaultState( void );
-void GL_InitPrograms( void );
-void GL_ShutdownPrograms( void );
-void GL_EnableWarp( void );
-void GL_DisableWarp( void );
-void GL_EnableOutlines( void );
-void GL_DisableOutlines( void );
+void GL_SetDefaultState(void);
+void GL_InitPrograms(void);
+void GL_ShutdownPrograms(void);
+void GL_EnableWarp(void);
+void GL_DisableWarp(void);
+void GL_EnableOutlines(void);
+void GL_DisableOutlines(void);
/*
@@ -313,13 +313,13 @@ typedef struct {
extern drawStatic_t draw;
#ifdef _DEBUG
-void Draw_Stringf( int x, int y, const char *fmt, ... );
-void Draw_Stats( void );
-void Draw_Lightmaps( void );
-void Draw_Scrap( void );
+void Draw_Stringf(int x, int y, const char *fmt, ...);
+void Draw_Stats(void);
+void Draw_Lightmaps(void);
+void Draw_Scrap(void);
#endif
-void GL_Blend( void );
+void GL_Blend(void);
/*
@@ -327,7 +327,7 @@ void GL_Blend( void );
*
*/
-#define LUMINANCE(r,g,b) ((r)*0.2126f + (g)*0.7152f + (b)*0.0722f)
+#define LUMINANCE(r, g, b) ((r) * 0.2126f + (g) * 0.7152f + (b) * 0.0722f)
// auto textures
enum {
@@ -340,20 +340,20 @@ enum {
TEXNUM_LIGHTMAP // must be the last one
};
-#define NUM_TEXNUMS (TEXNUM_LIGHTMAP+LM_MAX_LIGHTMAPS-TEXNUM_DEFAULT)
+#define NUM_TEXNUMS (TEXNUM_LIGHTMAP + LM_MAX_LIGHTMAPS - TEXNUM_DEFAULT)
extern mtexinfo_t *upload_texinfo;
-void Scrap_Upload( void );
+void Scrap_Upload(void);
-void GL_InitImages( void );
-void GL_ShutdownImages( void );
+void GL_InitImages(void);
+void GL_ShutdownImages(void);
-void GL_UpdateGammaTable( qboolean realTime );
+void GL_UpdateGammaTable(qboolean realTime);
-image_t *R_ImageForHandle( qhandle_t hPic );
-qhandle_t R_RegisterSkin( const char *name );
-qhandle_t R_RegisterPic( const char *name );
+image_t *R_ImageForHandle(qhandle_t hPic);
+qhandle_t R_RegisterSkin(const char *name);
+qhandle_t R_RegisterPic(const char *name);
/*
@@ -361,13 +361,13 @@ qhandle_t R_RegisterPic( const char *name );
*
*/
#define TESS_MAX_FACES 256
-#define TESS_MAX_VERTICES ( 16 * TESS_MAX_FACES )
-#define TESS_MAX_INDICES ( 3 * TESS_MAX_VERTICES )
+#define TESS_MAX_VERTICES (16 * TESS_MAX_FACES)
+#define TESS_MAX_INDICES (3 * TESS_MAX_VERTICES)
typedef struct {
vec_t vertices[VERTEX_SIZE*TESS_MAX_VERTICES];
int indices[TESS_MAX_INDICES];
- byte colors[4*TESS_MAX_VERTICES];
+ byte colors[4 * TESS_MAX_VERTICES];
int texnum[MAX_TMUS];
int numverts;
int numindices;
@@ -376,35 +376,35 @@ typedef struct {
extern tesselator_t tess;
-void GL_Flush2D( void );
-void GL_DrawParticles( void );
-void GL_DrawBeams( void );
+void GL_Flush2D(void);
+void GL_DrawParticles(void);
+void GL_DrawBeams(void);
-void GL_AddAlphaFace( mface_t *face );
-void GL_AddSolidFace( mface_t *face );
-void GL_DrawAlphaFaces( void );
-void GL_DrawSolidFaces( void );
+void GL_AddAlphaFace(mface_t *face);
+void GL_AddSolidFace(mface_t *face);
+void GL_DrawAlphaFaces(void);
+void GL_DrawSolidFaces(void);
/*
* gl_world.c
*
*/
-void GL_DrawBspModel( mmodel_t *model );
-void GL_DrawWorld( void );
-void _R_LightPoint( vec3_t origin, vec3_t color );
+void GL_DrawBspModel(mmodel_t *model);
+void GL_DrawWorld(void);
+void _R_LightPoint(vec3_t origin, vec3_t color);
/*
* gl_sky.c
*
*/
-void R_AddSkySurface( mface_t *surf );
-void R_ClearSkyBox( void );
-void R_DrawSkyBox( void );
-void R_SetSky( const char *name, float rotate, vec3_t axis );
+void R_AddSkySurface(mface_t *surf);
+void R_ClearSkyBox(void);
+void R_DrawSkyBox(void);
+void R_SetSky(const char *name, float rotate, vec3_t axis);
/*
* gl_mesh.c
*
*/
-void GL_DrawAliasModel( model_t *model );
+void GL_DrawAliasModel(model_t *model);
diff --git a/src/gl_main.c b/src/gl_main.c
index e698581..c1566df 100644
--- a/src/gl_main.c
+++ b/src/gl_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/*
* gl_main.c
- *
+ *
*/
#include "gl_local.h"
@@ -83,69 +83,71 @@ cvar_t *gl_showerrors;
// ==============================================================================
-static void GL_SetupFrustum( void ) {
+static void GL_SetupFrustum(void)
+{
cplane_t *f;
vec3_t forward, left, up;
vec_t fovSin, fovCos, angle;
- angle = DEG2RAD( glr.fd.fov_x / 2 );
- fovSin = sin( angle );
- fovCos = cos( angle );
+ angle = DEG2RAD(glr.fd.fov_x / 2);
+ fovSin = sin(angle);
+ fovCos = cos(angle);
- VectorScale( glr.viewaxis[0], fovSin, forward );
- VectorScale( glr.viewaxis[1], fovCos, left );
+ VectorScale(glr.viewaxis[0], fovSin, forward);
+ VectorScale(glr.viewaxis[1], fovCos, left);
/* right side */
f = &glr.frustumPlanes[0];
- VectorAdd( forward, left, f->normal );
- f->dist = DotProduct( glr.fd.vieworg, f->normal );
+ VectorAdd(forward, left, f->normal);
+ f->dist = DotProduct(glr.fd.vieworg, f->normal);
f->type = PLANE_NON_AXIAL;
- SetPlaneSignbits( f );
+ SetPlaneSignbits(f);
/* left side */
f = &glr.frustumPlanes[1];
- VectorSubtract( forward, left, f->normal );
- f->dist = DotProduct( glr.fd.vieworg, f->normal );
+ VectorSubtract(forward, left, f->normal);
+ f->dist = DotProduct(glr.fd.vieworg, f->normal);
f->type = PLANE_NON_AXIAL;
- SetPlaneSignbits( f );
+ SetPlaneSignbits(f);
- angle = DEG2RAD( glr.fd.fov_y / 2 );
- fovSin = sin( angle );
- fovCos = cos( angle );
+ angle = DEG2RAD(glr.fd.fov_y / 2);
+ fovSin = sin(angle);
+ fovCos = cos(angle);
- VectorScale( glr.viewaxis[0], fovSin, forward );
- VectorScale( glr.viewaxis[2], fovCos, up );
+ VectorScale(glr.viewaxis[0], fovSin, forward);
+ VectorScale(glr.viewaxis[2], fovCos, up);
/* up side */
f = &glr.frustumPlanes[2];
- VectorAdd( forward, up, f->normal );
- f->dist = DotProduct( glr.fd.vieworg, f->normal );
+ VectorAdd(forward, up, f->normal);
+ f->dist = DotProduct(glr.fd.vieworg, f->normal);
f->type = PLANE_NON_AXIAL;
- SetPlaneSignbits( f );
+ SetPlaneSignbits(f);
/* down side */
f = &glr.frustumPlanes[3];
- VectorSubtract( forward, up, f->normal );
- f->dist = DotProduct( glr.fd.vieworg, f->normal );
+ VectorSubtract(forward, up, f->normal);
+ f->dist = DotProduct(glr.fd.vieworg, f->normal);
f->type = PLANE_NON_AXIAL;
- SetPlaneSignbits( f );
+ SetPlaneSignbits(f);
}
-glCullResult_t GL_CullBox( vec3_t bounds[2] ) {
+glCullResult_t GL_CullBox(vec3_t bounds[2])
+{
int i, bits;
glCullResult_t cull;
- if( !gl_cull_models->integer ) {
+ if (!gl_cull_models->integer) {
return CULL_IN;
}
-
+
cull = CULL_IN;
- for( i = 0; i < 4; i++ ) {
- bits = BoxOnPlaneSide( bounds[0], bounds[1], &glr.frustumPlanes[i] );
- if( bits == BOX_BEHIND ) {
+ for (i = 0; i < 4; i++) {
+ bits = BoxOnPlaneSide(bounds[0], bounds[1], &glr.frustumPlanes[i]);
+ if (bits == BOX_BEHIND) {
return CULL_OUT;
}
- if( bits != BOX_INFRONT ) {
+ if (bits != BOX_INFRONT) {
cull = CULL_CLIP;
}
}
@@ -153,23 +155,24 @@ glCullResult_t GL_CullBox( vec3_t bounds[2] ) {
return cull;
}
-glCullResult_t GL_CullSphere( const vec3_t origin, float radius ) {
+glCullResult_t GL_CullSphere(const vec3_t origin, float radius)
+{
float dist;
cplane_t *p;
int i;
glCullResult_t cull;
- if( !gl_cull_models->integer ) {
+ if (!gl_cull_models->integer) {
return CULL_IN;
}
cull = CULL_IN;
- for( i = 0, p = glr.frustumPlanes; i < 4; i++, p++ ) {
- dist = PlaneDiff( origin, p );
- if( dist < -radius ) {
+ for (i = 0, p = glr.frustumPlanes; i < 4; i++, p++) {
+ dist = PlaneDiff(origin, p);
+ if (dist < -radius) {
return CULL_OUT;
}
- if( dist <= radius ) {
+ if (dist <= radius) {
cull = CULL_CLIP;
}
}
@@ -177,22 +180,23 @@ glCullResult_t GL_CullSphere( const vec3_t origin, float radius ) {
return cull;
}
-static inline void make_box_points( const vec3_t origin,
- vec3_t bounds[2],
- vec3_t points[8] )
+static inline void make_box_points(const vec3_t origin,
+ vec3_t bounds[2],
+ vec3_t points[8])
{
int i;
- for( i = 0; i < 8; i++ ) {
- VectorCopy( origin, points[i] );
- VectorMA( points[i], bounds[(i>>0)&1][0], glr.entaxis[0], points[i] );
- VectorMA( points[i], bounds[(i>>1)&1][1], glr.entaxis[1], points[i] );
- VectorMA( points[i], bounds[(i>>2)&1][2], glr.entaxis[2], points[i] );
+ for (i = 0; i < 8; i++) {
+ VectorCopy(origin, points[i]);
+ VectorMA(points[i], bounds[(i >> 0) & 1][0], glr.entaxis[0], points[i]);
+ VectorMA(points[i], bounds[(i >> 1) & 1][1], glr.entaxis[1], points[i]);
+ VectorMA(points[i], bounds[(i >> 2) & 1][2], glr.entaxis[2], points[i]);
}
}
-glCullResult_t GL_CullLocalBox( const vec3_t origin, vec3_t bounds[2] ) {
+glCullResult_t GL_CullLocalBox(const vec3_t origin, vec3_t bounds[2])
+{
vec3_t points[8];
cplane_t *p;
int i, j;
@@ -200,30 +204,30 @@ glCullResult_t GL_CullLocalBox( const vec3_t origin, vec3_t bounds[2] ) {
qboolean infront;
glCullResult_t cull;
- if( !gl_cull_models->integer ) {
+ if (!gl_cull_models->integer) {
return CULL_IN;
}
- make_box_points( origin, bounds, points );
+ make_box_points(origin, bounds, points);
cull = CULL_IN;
- for( i = 0, p = glr.frustumPlanes; i < 4; i++, p++ ) {
+ for (i = 0, p = glr.frustumPlanes; i < 4; i++, p++) {
infront = qfalse;
- for( j = 0; j < 8; j++ ) {
- dot = DotProduct( points[j], p->normal );
- if( dot >= p->dist ) {
+ for (j = 0; j < 8; j++) {
+ dot = DotProduct(points[j], p->normal);
+ if (dot >= p->dist) {
infront = qtrue;
- if( cull == CULL_CLIP ) {
+ if (cull == CULL_CLIP) {
break;
}
} else {
cull = CULL_CLIP;
- if( infront ) {
+ if (infront) {
break;
}
}
}
- if( !infront ) {
+ if (!infront) {
return CULL_OUT;
}
}
@@ -232,61 +236,62 @@ glCullResult_t GL_CullLocalBox( const vec3_t origin, vec3_t bounds[2] ) {
}
#if 0
-void GL_DrawBox( const vec3_t origin, vec3_t bounds[2] ) {
+void GL_DrawBox(const vec3_t origin, vec3_t bounds[2])
+{
static const int indices1[4] = { 0, 1, 3, 2 };
static const int indices2[4] = { 4, 5, 7, 6 };
static const int indices3[8] = { 0, 4, 1, 5, 2, 6, 3, 7 };
vec3_t points[8];
- qglDisable( GL_TEXTURE_2D );
- qglDisable( GL_DEPTH_TEST );
- qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
- qglColor4f( 1, 1, 1, 1 );
+ qglDisable(GL_TEXTURE_2D);
+ qglDisable(GL_DEPTH_TEST);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglColor4f(1, 1, 1, 1);
- make_box_points( origin, bounds, points );
+ make_box_points(origin, bounds, points);
- qglVertexPointer( 3, GL_FLOAT, 0, points );
- qglDrawElements( GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices1 );
- qglDrawElements( GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices2 );
- qglDrawElements( GL_LINES, 8, GL_UNSIGNED_INT, indices3 );
+ qglVertexPointer(3, GL_FLOAT, 0, points);
+ qglDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices1);
+ qglDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices2);
+ qglDrawElements(GL_LINES, 8, GL_UNSIGNED_INT, indices3);
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
- qglEnable( GL_DEPTH_TEST );
- qglEnable( GL_TEXTURE_2D );
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglEnable(GL_DEPTH_TEST);
+ qglEnable(GL_TEXTURE_2D);
}
#endif
// shared between lightmap and scrap allocators
-qboolean GL_AllocBlock( int width, int height, int *inuse,
- int w, int h, int *s, int *t )
+qboolean GL_AllocBlock(int width, int height, int *inuse,
+ int w, int h, int *s, int *t)
{
int i, j, k, x, y, max_inuse, min_inuse;
x = 0; y = height;
min_inuse = height;
- for( i = 0; i < width - w; i++ ) {
+ for (i = 0; i < width - w; i++) {
max_inuse = 0;
- for( j = 0; j < w; j++ ) {
- k = inuse[ i + j ];
- if( k >= min_inuse ) {
+ for (j = 0; j < w; j++) {
+ k = inuse[i + j];
+ if (k >= min_inuse) {
break;
}
- if( max_inuse < k ) {
+ if (max_inuse < k) {
max_inuse = k;
}
}
- if( j == w ) {
+ if (j == w) {
x = i;
y = min_inuse = max_inuse;
}
}
- if( y + h > height ) {
+ if (y + h > height) {
return qfalse;
}
- for( i = 0; i < w; i++ ) {
- inuse[ x + i ] = y + h;
+ for (i = 0; i < w; i++) {
+ inuse[x + i] = y + h;
}
*s = x;
@@ -294,19 +299,20 @@ qboolean GL_AllocBlock( int width, int height, int *inuse,
return qtrue;
}
-static void GL_DrawSpriteModel( model_t *model ) {
+static void GL_DrawSpriteModel(model_t *model)
+{
static const vec_t tcoords[8] = { 0, 1, 0, 0, 1, 1, 1, 0 };
entity_t *e = glr.ent;
mspriteframe_t *frame = &model->spriteframes[e->frame % model->numframes];
image_t *image = frame->image;
- float alpha = ( e->flags & RF_TRANSLUCENT ) ? e->alpha : 1;
+ float alpha = (e->flags & RF_TRANSLUCENT) ? e->alpha : 1;
int bits = GLS_DEPTHMASK_FALSE;
vec3_t up, down, left, right;
vec3_t points[4];
- if( alpha == 1 ) {
- if( image->flags & if_transparent ) {
- if( image->flags & if_paletted ) {
+ if (alpha == 1) {
+ if (image->flags & if_transparent) {
+ if (image->flags & if_paletted) {
bits |= GLS_ALPHATEST_ENABLE;
} else {
bits |= GLS_BLEND_BLEND;
@@ -316,27 +322,28 @@ static void GL_DrawSpriteModel( model_t *model ) {
bits |= GLS_BLEND_BLEND;
}
- GL_TexEnv( GL_MODULATE );
- GL_Bits( bits );
- GL_BindTexture( image->texnum );
- qglColor4f( 1, 1, 1, alpha );
+ GL_TexEnv(GL_MODULATE);
+ GL_Bits(bits);
+ GL_BindTexture(image->texnum);
+ qglColor4f(1, 1, 1, alpha);
- VectorScale( glr.viewaxis[1], frame->origin_x, left );
- VectorScale( glr.viewaxis[1], frame->origin_x - frame->width, right );
- VectorScale( glr.viewaxis[2], -frame->origin_y, down );
- VectorScale( glr.viewaxis[2], frame->height - frame->origin_y, up );
+ VectorScale(glr.viewaxis[1], frame->origin_x, left);
+ VectorScale(glr.viewaxis[1], frame->origin_x - frame->width, right);
+ VectorScale(glr.viewaxis[2], -frame->origin_y, down);
+ VectorScale(glr.viewaxis[2], frame->height - frame->origin_y, up);
- VectorAdd3( e->origin, down, left, points[0] );
- VectorAdd3( e->origin, up, left, points[1] );
- VectorAdd3( e->origin, down, right, points[2] );
- VectorAdd3( e->origin, up, right, points[3] );
+ VectorAdd3(e->origin, down, left, points[0]);
+ VectorAdd3(e->origin, up, left, points[1]);
+ VectorAdd3(e->origin, down, right, points[2]);
+ VectorAdd3(e->origin, up, right, points[3]);
- qglTexCoordPointer( 2, GL_FLOAT, 0, tcoords );
- qglVertexPointer( 3, GL_FLOAT, 0, points );
- qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
+ qglTexCoordPointer(2, GL_FLOAT, 0, tcoords);
+ qglVertexPointer(3, GL_FLOAT, 0, points);
+ qglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
-static void GL_DrawNullModel( void ) {
+static void GL_DrawNullModel(void)
+{
static const uint32_t colors[6] = {
U32_RED, U32_RED,
U32_GREEN, U32_GREEN,
@@ -345,116 +352,118 @@ static void GL_DrawNullModel( void ) {
entity_t *e = glr.ent;
vec3_t points[6];
- VectorCopy( e->origin, points[0] );
- VectorCopy( e->origin, points[2] );
- VectorCopy( e->origin, points[4] );
+ VectorCopy(e->origin, points[0]);
+ VectorCopy(e->origin, points[2]);
+ VectorCopy(e->origin, points[4]);
- VectorMA( e->origin, 16, glr.entaxis[0], points[1] );
- VectorMA( e->origin, 16, glr.entaxis[1], points[3] );
- VectorMA( e->origin, 16, glr.entaxis[2], points[5] );
+ VectorMA(e->origin, 16, glr.entaxis[0], points[1]);
+ VectorMA(e->origin, 16, glr.entaxis[1], points[3]);
+ VectorMA(e->origin, 16, glr.entaxis[2], points[5]);
- qglDisable( GL_TEXTURE_2D );
- //qglDisable( GL_DEPTH_TEST );
- qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
- qglEnableClientState( GL_COLOR_ARRAY );
+ qglDisable(GL_TEXTURE_2D);
+ //qglDisable(GL_DEPTH_TEST);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglEnableClientState(GL_COLOR_ARRAY);
- qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors );
- qglVertexPointer( 3, GL_FLOAT, 0, points );
- qglDrawArrays( GL_LINES, 0, 6 );
+ qglColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
+ qglVertexPointer(3, GL_FLOAT, 0, points);
+ qglDrawArrays(GL_LINES, 0, 6);
- qglDisableClientState( GL_COLOR_ARRAY );
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
- //qglEnable( GL_DEPTH_TEST );
- qglEnable( GL_TEXTURE_2D );
+ qglDisableClientState(GL_COLOR_ARRAY);
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ //qglEnable(GL_DEPTH_TEST);
+ qglEnable(GL_TEXTURE_2D);
}
-static void GL_DrawEntities( int mask ) {
+static void GL_DrawEntities(int mask)
+{
entity_t *ent, *last;
model_t *model;
- if( !gl_drawentities->integer ) {
+ if (!gl_drawentities->integer) {
return;
}
last = glr.fd.entities + glr.fd.num_entities;
- for( ent = glr.fd.entities; ent != last; ent++ ) {
- if( ent->flags & RF_BEAM ) {
+ for (ent = glr.fd.entities; ent != last; ent++) {
+ if (ent->flags & RF_BEAM) {
/* beams are drawn elsewhere in single batch */
glr.num_beams++;
continue;
}
- if( ( ent->flags & RF_TRANSLUCENT ) != mask ) {
+ if ((ent->flags & RF_TRANSLUCENT) != mask) {
continue;
}
glr.ent = ent;
- if( !VectorEmpty( ent->angles ) ) {
+ if (!VectorEmpty(ent->angles)) {
glr.entrotated = qtrue;
- AngleVectors( ent->angles, glr.entaxis[0], glr.entaxis[1], glr.entaxis[2] );
- VectorInverse( glr.entaxis[1] );
+ AngleVectors(ent->angles, glr.entaxis[0], glr.entaxis[1], glr.entaxis[2]);
+ VectorInverse(glr.entaxis[1]);
} else {
glr.entrotated = qfalse;
- VectorSet( glr.entaxis[0], 1, 0, 0 );
- VectorSet( glr.entaxis[1], 0, 1, 0 );
- VectorSet( glr.entaxis[2], 0, 0, 1 );
+ VectorSet(glr.entaxis[0], 1, 0, 0);
+ VectorSet(glr.entaxis[1], 0, 1, 0);
+ VectorSet(glr.entaxis[2], 0, 0, 1);
}
// inline BSP model
- if( ent->model & 0x80000000 ) {
+ if (ent->model & 0x80000000) {
bsp_t *bsp = gl_static.world.cache;
int index = ~ent->model;
- if( !bsp ) {
- Com_Error( ERR_DROP, "%s: inline model without world",
- __func__ );
+ if (!bsp) {
+ Com_Error(ERR_DROP, "%s: inline model without world",
+ __func__);
}
- if( index < 1 || index >= bsp->nummodels ) {
- Com_Error( ERR_DROP, "%s: inline model %d out of range",
- __func__, index );
+ if (index < 1 || index >= bsp->nummodels) {
+ Com_Error(ERR_DROP, "%s: inline model %d out of range",
+ __func__, index);
}
- GL_DrawBspModel( &bsp->models[index] );
+ GL_DrawBspModel(&bsp->models[index]);
continue;
}
- model = MOD_ForHandle( ent->model );
- if( !model ) {
+ model = MOD_ForHandle(ent->model);
+ if (!model) {
GL_DrawNullModel();
continue;
}
- switch( model->type ) {
+ switch (model->type) {
case MOD_ALIAS:
- GL_DrawAliasModel( model );
+ GL_DrawAliasModel(model);
break;
case MOD_SPRITE:
- GL_DrawSpriteModel( model );
+ GL_DrawSpriteModel(model);
break;
case MOD_EMPTY:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad model type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad model type", __func__);
}
- if( gl_showorigins->integer ) {
+ if (gl_showorigins->integer) {
GL_DrawNullModel();
}
}
}
-static void GL_DrawTearing( void ) {
+static void GL_DrawTearing(void)
+{
vec2_t points[4];
static int i;
// alternate colors to make tearing obvious
i++;
- if( i & 1 ) {
- qglClearColor( 1, 1, 1, 1 );
- qglColor4f( 1, 1, 1, 1 );
+ if (i & 1) {
+ qglClearColor(1, 1, 1, 1);
+ qglColor4f(1, 1, 1, 1);
} else {
- qglClearColor( 1, 0, 0, 0 );
- qglColor4f( 1, 0, 0, 1 );
+ qglClearColor(1, 0, 0, 0);
+ qglColor4f(1, 0, 0, 1);
}
points[0][0] = 0;
@@ -466,67 +475,71 @@ static void GL_DrawTearing( void ) {
points[3][0] = r_config.width;
points[3][1] = 0;
- qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- qglDisable( GL_TEXTURE_2D );
- qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
+ qglDisable(GL_TEXTURE_2D);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
- qglVertexPointer( 2, GL_FLOAT, 0, points );
- qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
+ qglVertexPointer(2, GL_FLOAT, 0, points);
+ qglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
- qglEnable( GL_TEXTURE_2D );
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglEnable(GL_TEXTURE_2D);
- qglClearColor( 0, 0, 0, 1 );
+ qglClearColor(0, 0, 0, 1);
}
-static const char *GL_ErrorString( GLenum err ) {
+static const char *GL_ErrorString(GLenum err)
+{
const char *str;
- switch( err ) {
+ switch (err) {
#define E(x) case GL_##x: str = "GL_"#x; break;
- E( NO_ERROR )
- E( INVALID_ENUM )
- E( INVALID_VALUE )
- E( INVALID_OPERATION )
- E( STACK_OVERFLOW )
- E( STACK_UNDERFLOW )
- E( OUT_OF_MEMORY )
- default: str = "UNKNOWN ERROR";
+ E(NO_ERROR)
+ E(INVALID_ENUM)
+ E(INVALID_VALUE)
+ E(INVALID_OPERATION)
+ E(STACK_OVERFLOW)
+ E(STACK_UNDERFLOW)
+ E(OUT_OF_MEMORY)
+ default: str = "UNKNOWN ERROR";
#undef E
}
return str;
}
-void GL_ClearErrors( void ) {
+void GL_ClearErrors(void)
+{
GLenum err;
- while( ( err = qglGetError() ) != GL_NO_ERROR )
+ while ((err = qglGetError()) != GL_NO_ERROR)
;
}
-qboolean GL_ShowErrors( const char *func ) {
+qboolean GL_ShowErrors(const char *func)
+{
GLenum err = qglGetError();
- if( err == GL_NO_ERROR ) {
+ if (err == GL_NO_ERROR) {
return qfalse;
}
do {
- if( gl_showerrors->integer ) {
- Com_EPrintf( "%s: %s\n", func, GL_ErrorString( err ) );
+ if (gl_showerrors->integer) {
+ Com_EPrintf("%s: %s\n", func, GL_ErrorString(err));
}
- } while( ( err = qglGetError() ) != GL_NO_ERROR );
+ } while ((err = qglGetError()) != GL_NO_ERROR);
return qtrue;
}
-void R_RenderFrame( refdef_t *fd ) {
+void R_RenderFrame(refdef_t *fd)
+{
GL_Flush2D();
- if( !gl_static.world.cache && !( fd->rdflags & RDF_NOWORLDMODEL ) ) {
- Com_Error( ERR_FATAL, "%s: NULL worldmodel", __func__ );
+ if (!gl_static.world.cache && !(fd->rdflags & RDF_NOWORLDMODEL)) {
+ Com_Error(ERR_FATAL, "%s: NULL worldmodel", __func__);
}
glr.drawframe++;
@@ -535,98 +548,100 @@ void R_RenderFrame( refdef_t *fd ) {
glr.num_beams = 0;
#if USE_DLIGHTS
- if( gl_dynamic->integer != 1 ) {
+ if (gl_dynamic->integer != 1) {
glr.fd.num_dlights = 0;
}
#endif
- if( lm.dirty ) {
+ if (lm.dirty) {
LM_RebuildSurfaces();
lm.dirty = qfalse;
}
GL_Setup3D();
-
- if( gl_cull_nodes->integer ) {
+
+ if (gl_cull_nodes->integer) {
GL_SetupFrustum();
}
- if( !( glr.fd.rdflags & RDF_NOWORLDMODEL ) && gl_drawworld->integer ) {
+ if (!(glr.fd.rdflags & RDF_NOWORLDMODEL) && gl_drawworld->integer) {
GL_DrawWorld();
}
- GL_DrawEntities( 0 );
+ GL_DrawEntities(0);
GL_DrawBeams();
GL_DrawParticles();
- GL_DrawEntities( RF_TRANSLUCENT );
+ GL_DrawEntities(RF_TRANSLUCENT);
GL_DrawAlphaFaces();
// go back into 2D mode
GL_Setup2D();
- if( gl_polyblend->integer && glr.fd.blend[3] != 0 ) {
+ if (gl_polyblend->integer && glr.fd.blend[3] != 0) {
GL_Blend();
}
#ifdef _DEBUG
- if( gl_lightmap->integer > 1 ) {
+ if (gl_lightmap->integer > 1) {
Draw_Lightmaps();
}
#endif
- GL_ShowErrors( __func__ );
+ GL_ShowErrors(__func__);
}
-void R_BeginFrame( void ) {
- if( gl_log->integer ) {
+void R_BeginFrame(void)
+{
+ if (gl_log->integer) {
QGL_LogNewFrame();
}
-
- memset( &c, 0, sizeof( c ) );
-
+
+ memset(&c, 0, sizeof(c));
+
GL_Setup2D();
- if( gl_clear->integer ) {
- qglClear( GL_COLOR_BUFFER_BIT );
+ if (gl_clear->integer) {
+ qglClear(GL_COLOR_BUFFER_BIT);
}
- GL_ShowErrors( __func__ );
+ GL_ShowErrors(__func__);
}
-void R_EndFrame( void ) {
+void R_EndFrame(void)
+{
#ifdef _DEBUG
- if( gl_showstats->integer ) {
+ if (gl_showstats->integer) {
GL_Flush2D();
Draw_Stats();
}
- if( gl_showscrap->integer ) {
+ if (gl_showscrap->integer) {
Draw_Scrap();
}
#endif
GL_Flush2D();
- if( gl_showtearing->integer ) {
+ if (gl_showtearing->integer) {
GL_DrawTearing();
}
- if( gl_log->modified ) {
- QGL_EnableLogging( gl_log->integer );
+ if (gl_log->modified) {
+ QGL_EnableLogging(gl_log->integer);
gl_log->modified = qfalse;
}
// enable/disable fragment programs on the fly
- if( gl_fragment_program->modified ) {
+ if (gl_fragment_program->modified) {
GL_ShutdownPrograms();
GL_InitPrograms();
gl_fragment_program->modified = qfalse;
}
- GL_ShowErrors( __func__ );
-
+ GL_ShowErrors(__func__);
+
VID_EndFrame();
// qglFinish();
@@ -634,175 +649,183 @@ void R_EndFrame( void ) {
// ==============================================================================
-static void GL_Strings_f( void ) {
- Com_Printf( "GL_VENDOR: %s\n", gl_config.vendorString );
- Com_Printf( "GL_RENDERER: %s\n", gl_config.rendererString );
- Com_Printf( "GL_VERSION: %s\n", gl_config.versionString );
- Com_Printf( "GL_EXTENSIONS: %s\n", gl_config.extensionsString );
- Com_Printf( "GL_MAX_TEXTURE_SIZE: %d\n", gl_config.maxTextureSize );
- Com_Printf( "GL_MAX_TEXTURE_UNITS: %d\n", gl_config.numTextureUnits );
- Com_Printf( "GL_MAX_TEXTURE_MAX_ANISOTROPY: %d\n", (int)gl_config.maxAnisotropy );
+static void GL_Strings_f(void)
+{
+ Com_Printf("GL_VENDOR: %s\n", gl_config.vendorString);
+ Com_Printf("GL_RENDERER: %s\n", gl_config.rendererString);
+ Com_Printf("GL_VERSION: %s\n", gl_config.versionString);
+ Com_Printf("GL_EXTENSIONS: %s\n", gl_config.extensionsString);
+ Com_Printf("GL_MAX_TEXTURE_SIZE: %d\n", gl_config.maxTextureSize);
+ Com_Printf("GL_MAX_TEXTURE_UNITS: %d\n", gl_config.numTextureUnits);
+ Com_Printf("GL_MAX_TEXTURE_MAX_ANISOTROPY: %d\n", (int)gl_config.maxAnisotropy);
}
-static size_t GL_ViewCluster_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%d", glr.viewcluster1 );
+static size_t GL_ViewCluster_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%d", glr.viewcluster1);
}
-static void gl_modulate_entities_changed( cvar_t *self ) {
+static void gl_modulate_entities_changed(cvar_t *self)
+{
gl_static.entity_modulate = gl_modulate->value * gl_modulate_entities->value;
}
// this one is defined in gl_surf.c
-extern void gl_lightmap_changed( cvar_t *self );
+extern void gl_lightmap_changed(cvar_t *self);
-static void gl_modulate_changed( cvar_t *self ) {
- gl_lightmap_changed( self );
- gl_modulate_entities_changed( self );
+static void gl_modulate_changed(cvar_t *self)
+{
+ gl_lightmap_changed(self);
+ gl_modulate_entities_changed(self);
}
-static void gl_novis_changed( cvar_t *self ) {
+static void gl_novis_changed(cvar_t *self)
+{
glr.viewcluster1 = glr.viewcluster2 = -2;
}
-static void GL_Register( void ) {
+static void GL_Register(void)
+{
// regular variables
- gl_partscale = Cvar_Get( "gl_partscale", "2", 0 );
+ gl_partscale = Cvar_Get("gl_partscale", "2", 0);
#if USE_CELSHADING
- gl_celshading = Cvar_Get( "gl_celshading", "0", 0 );
+ gl_celshading = Cvar_Get("gl_celshading", "0", 0);
#endif
#if USE_DOTSHADING
- gl_dotshading = Cvar_Get( "gl_dotshading", "1", 0 );
+ gl_dotshading = Cvar_Get("gl_dotshading", "1", 0);
#endif
- gl_modulate = Cvar_Get( "gl_modulate", "1", CVAR_ARCHIVE );
+ gl_modulate = Cvar_Get("gl_modulate", "1", CVAR_ARCHIVE);
gl_modulate->changed = gl_modulate_changed;
- gl_modulate_world = Cvar_Get( "gl_modulate_world", "1", 0 );
+ gl_modulate_world = Cvar_Get("gl_modulate_world", "1", 0);
gl_modulate_world->changed = gl_lightmap_changed;
- gl_coloredlightmaps = Cvar_Get( "gl_coloredlightmaps", "1", 0 );
+ gl_coloredlightmaps = Cvar_Get("gl_coloredlightmaps", "1", 0);
gl_coloredlightmaps->changed = gl_lightmap_changed;
- gl_brightness = Cvar_Get( "gl_brightness", "0", 0 );
+ gl_brightness = Cvar_Get("gl_brightness", "0", 0);
gl_brightness->changed = gl_lightmap_changed;
- gl_dynamic = Cvar_Get( "gl_dynamic", "2", 0 );
+ gl_dynamic = Cvar_Get("gl_dynamic", "2", 0);
gl_dynamic->changed = gl_lightmap_changed;
#if USE_DLIGHTS
- gl_dlight_falloff = Cvar_Get( "gl_dlight_falloff", "1", 0 );
+ gl_dlight_falloff = Cvar_Get("gl_dlight_falloff", "1", 0);
#endif
- gl_modulate_entities = Cvar_Get( "gl_modulate_entities", "1", 0 );
+ gl_modulate_entities = Cvar_Get("gl_modulate_entities", "1", 0);
gl_modulate_entities->changed = gl_modulate_entities_changed;
- gl_doublelight_entities = Cvar_Get( "gl_doublelight_entities", "1", 0 );
- gl_fragment_program = Cvar_Get( "gl_fragment_program", "1", 0 );
- gl_vertex_buffer_object = Cvar_Get( "gl_vertex_buffer_object", "1", CVAR_FILES );
+ gl_doublelight_entities = Cvar_Get("gl_doublelight_entities", "1", 0);
+ gl_fragment_program = Cvar_Get("gl_fragment_program", "1", 0);
+ gl_vertex_buffer_object = Cvar_Get("gl_vertex_buffer_object", "1", CVAR_FILES);
gl_vertex_buffer_object->modified = qtrue;
// development variables
- gl_znear = Cvar_Get( "gl_znear", "2", CVAR_CHEAT );
- gl_zfar = Cvar_Get( "gl_zfar", "16384", 0 );
- gl_log = Cvar_Get( "gl_log", "0", 0 );
- gl_drawworld = Cvar_Get( "gl_drawworld", "1", CVAR_CHEAT );
- gl_drawentities = Cvar_Get( "gl_drawentities", "1", CVAR_CHEAT );
- gl_drawsky = Cvar_Get( "gl_drawsky", "1", 0 );
- gl_showtris = Cvar_Get( "gl_showtris", "0", CVAR_CHEAT );
- gl_showorigins = Cvar_Get( "gl_showorigins", "0", CVAR_CHEAT );
- gl_showtearing = Cvar_Get( "gl_showtearing", "0", 0 );
+ gl_znear = Cvar_Get("gl_znear", "2", CVAR_CHEAT);
+ gl_zfar = Cvar_Get("gl_zfar", "16384", 0);
+ gl_log = Cvar_Get("gl_log", "0", 0);
+ gl_drawworld = Cvar_Get("gl_drawworld", "1", CVAR_CHEAT);
+ gl_drawentities = Cvar_Get("gl_drawentities", "1", CVAR_CHEAT);
+ gl_drawsky = Cvar_Get("gl_drawsky", "1", 0);
+ gl_showtris = Cvar_Get("gl_showtris", "0", CVAR_CHEAT);
+ gl_showorigins = Cvar_Get("gl_showorigins", "0", CVAR_CHEAT);
+ gl_showtearing = Cvar_Get("gl_showtearing", "0", 0);
#ifdef _DEBUG
- gl_showstats = Cvar_Get( "gl_showstats", "0", 0 );
- gl_showscrap = Cvar_Get( "gl_showscrap", "0", 0 );
- gl_nobind = Cvar_Get( "gl_nobind", "0", CVAR_CHEAT );
- gl_test = Cvar_Get( "gl_test", "0", 0 );
+ gl_showstats = Cvar_Get("gl_showstats", "0", 0);
+ gl_showscrap = Cvar_Get("gl_showscrap", "0", 0);
+ gl_nobind = Cvar_Get("gl_nobind", "0", CVAR_CHEAT);
+ gl_test = Cvar_Get("gl_test", "0", 0);
#endif
- gl_cull_nodes = Cvar_Get( "gl_cull_nodes", "1", 0 );
- gl_cull_models = Cvar_Get( "gl_cull_models", "1", 0 );
- gl_clear = Cvar_Get( "gl_clear", "0", 0 );
- gl_novis = Cvar_Get( "gl_novis", "0", 0 );
+ gl_cull_nodes = Cvar_Get("gl_cull_nodes", "1", 0);
+ gl_cull_models = Cvar_Get("gl_cull_models", "1", 0);
+ gl_clear = Cvar_Get("gl_clear", "0", 0);
+ gl_novis = Cvar_Get("gl_novis", "0", 0);
gl_novis->changed = gl_novis_changed;
- gl_lockpvs = Cvar_Get( "gl_lockpvs", "0", CVAR_CHEAT );
- gl_lightmap = Cvar_Get( "gl_lightmap", "0", CVAR_CHEAT );
- gl_fullbright = Cvar_Get( "r_fullbright", "0", CVAR_CHEAT );
- gl_polyblend = Cvar_Get( "gl_polyblend", "1", 0 );
- gl_showerrors = Cvar_Get( "gl_showerrors", "1", 0 );
+ gl_lockpvs = Cvar_Get("gl_lockpvs", "0", CVAR_CHEAT);
+ gl_lightmap = Cvar_Get("gl_lightmap", "0", CVAR_CHEAT);
+ gl_fullbright = Cvar_Get("r_fullbright", "0", CVAR_CHEAT);
+ gl_polyblend = Cvar_Get("gl_polyblend", "1", 0);
+ gl_showerrors = Cvar_Get("gl_showerrors", "1", 0);
- gl_modulate_entities_changed( gl_modulate_entities );
+ gl_modulate_entities_changed(gl_modulate_entities);
- Cmd_AddCommand( "strings", GL_Strings_f );
- Cmd_AddMacro( "gl_viewcluster", GL_ViewCluster_m );
+ Cmd_AddCommand("strings", GL_Strings_f);
+ Cmd_AddMacro("gl_viewcluster", GL_ViewCluster_m);
}
-static void GL_Unregister( void ) {
- Cmd_RemoveCommand( "strings" );
+static void GL_Unregister(void)
+{
+ Cmd_RemoveCommand("strings");
}
-static qboolean GL_SetupExtensions( void ) {
+static qboolean GL_SetupExtensions(void)
+{
int integer;
float value;
- if( !gl_config.extensionsString || !gl_config.extensionsString[0] ) {
- Com_EPrintf( "No OpenGL extensions found, check your drivers\n" );
+ if (!gl_config.extensionsString || !gl_config.extensionsString[0]) {
+ Com_EPrintf("No OpenGL extensions found, check your drivers\n");
return qfalse;
}
// parse extension string
- gl_config.ext_supported = QGL_ParseExtensionString( gl_config.extensionsString );
+ gl_config.ext_supported = QGL_ParseExtensionString(gl_config.extensionsString);
gl_config.ext_enabled = 0;
// initialize our 'always on' extensions
- if( gl_config.ext_supported & QGL_EXT_compiled_vertex_array ) {
- Com_Printf( "...enabling GL_EXT_compiled_vertex_array\n" );
+ if (gl_config.ext_supported & QGL_EXT_compiled_vertex_array) {
+ Com_Printf("...enabling GL_EXT_compiled_vertex_array\n");
gl_config.ext_enabled |= QGL_EXT_compiled_vertex_array;
} else {
- Com_Printf( "GL_EXT_compiled_vertex_array not found\n" );
+ Com_Printf("GL_EXT_compiled_vertex_array not found\n");
}
-
+
gl_config.numTextureUnits = 1;
- if( gl_config.ext_supported & QGL_ARB_multitexture ) {
- qglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &integer );
- if( integer >= 2 ) {
- Com_Printf( "...enabling GL_ARB_multitexture (%d TMUs)\n", integer );
+ if (gl_config.ext_supported & QGL_ARB_multitexture) {
+ qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &integer);
+ if (integer >= 2) {
+ Com_Printf("...enabling GL_ARB_multitexture (%d TMUs)\n", integer);
gl_config.ext_enabled |= QGL_ARB_multitexture;
- if( integer > MAX_TMUS ) {
+ if (integer > MAX_TMUS) {
integer = MAX_TMUS;
}
gl_config.numTextureUnits = integer;
} else {
- Com_Printf( "...ignoring GL_ARB_multitexture,\n"
- "%d TMU is not enough\n", integer );
+ Com_Printf("...ignoring GL_ARB_multitexture,\n"
+ "%d TMU is not enough\n", integer);
}
} else {
- Com_Printf( "GL_ARB_multitexture not found\n" );
+ Com_Printf("GL_ARB_multitexture not found\n");
}
gl_config.maxAnisotropy = 1;
- if( gl_config.ext_supported & QGL_EXT_texture_filter_anisotropic ) {
- qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value );
- if( value >= 2 ) {
- Com_Printf( "...enabling GL_EXT_texture_filter_anisotropic (%d max)\n", ( int )value );
+ if (gl_config.ext_supported & QGL_EXT_texture_filter_anisotropic) {
+ qglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value);
+ if (value >= 2) {
+ Com_Printf("...enabling GL_EXT_texture_filter_anisotropic (%d max)\n", (int)value);
gl_config.ext_enabled |= QGL_EXT_texture_filter_anisotropic;
gl_config.maxAnisotropy = value;
} else {
- Com_Printf( "...ignoring GL_EXT_texture_filter_anisotropic,\n"
- "%d anisotropy is not enough\n", ( int )value );
+ Com_Printf("...ignoring GL_EXT_texture_filter_anisotropic,\n"
+ "%d anisotropy is not enough\n", (int)value);
}
} else {
- Com_Printf( "GL_EXT_texture_filter_anisotropic not found\n" );
+ Com_Printf("GL_EXT_texture_filter_anisotropic not found\n");
}
- QGL_InitExtensions( gl_config.ext_enabled );
+ QGL_InitExtensions(gl_config.ext_enabled);
// lack of multitexture support is a show stopper
- if( !qglActiveTextureARB ) {
- Com_EPrintf( "Required OpenGL extensions are missing\n" );
+ if (!qglActiveTextureARB) {
+ Com_EPrintf("Required OpenGL extensions are missing\n");
return qfalse;
}
- qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &integer );
- if( integer < 256 ) {
- Com_EPrintf( "OpenGL reports invalid maximum texture size\n" );
+ qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &integer);
+ if (integer < 256) {
+ Com_EPrintf("OpenGL reports invalid maximum texture size\n");
return qfalse;
}
- if( integer & ( integer - 1 ) ) {
- integer = npot32( integer ) >> 1;
+ if (integer & (integer - 1)) {
+ integer = npot32(integer) >> 1;
}
- if( integer > MAX_TEXTURE_SIZE ) {
+ if (integer > MAX_TEXTURE_SIZE) {
integer = MAX_TEXTURE_SIZE;
}
@@ -811,57 +834,60 @@ static qboolean GL_SetupExtensions( void ) {
return qtrue;
}
-static void GL_IdentifyRenderer( void ) {
+static void GL_IdentifyRenderer(void)
+{
char *p;
// parse renderer
- if( Q_stristr( gl_config.rendererString, "mesa dri" ) ) {
+ if (Q_stristr(gl_config.rendererString, "mesa dri")) {
gl_config.renderer = GL_RENDERER_MESADRI;
} else {
gl_config.renderer = GL_RENDERER_OTHER;
}
// parse version
- gl_config.version_major = strtoul( gl_config.versionString, &p, 10 );
- if( *p == '.' ) {
- gl_config.version_minor = strtoul( p + 1, NULL, 10 );
+ gl_config.version_major = strtoul(gl_config.versionString, &p, 10);
+ if (*p == '.') {
+ gl_config.version_minor = strtoul(p + 1, NULL, 10);
}
}
-static void GL_InitTables( void ) {
+static void GL_InitTables(void)
+{
vec_t lat, lng;
const vec_t *v;
int i;
- for( i = 0; i < NUMVERTEXNORMALS; i++ ) {
+ for (i = 0; i < NUMVERTEXNORMALS; i++) {
v = bytedirs[i];
- lat = acos( v[2] );
- lng = atan2( v[1], v[0] );
- gl_static.latlngtab[i][0] = lat * (255.0f/(2*M_PI));
- gl_static.latlngtab[i][1] = lng * (255.0f/(2*M_PI));
+ lat = acos(v[2]);
+ lng = atan2(v[1], v[0]);
+ gl_static.latlngtab[i][0] = lat * (255.0f / (2 * M_PI));
+ gl_static.latlngtab[i][1] = lng * (255.0f / (2 * M_PI));
}
- for( i = 0; i < 256; i++ ) {
- gl_static.sintab[i] = sin( i * (2*M_PI/255.0f) );
+ for (i = 0; i < 256; i++) {
+ gl_static.sintab[i] = sin(i * (2 * M_PI / 255.0f));
}
}
-static void GL_PostInit( void ) {
+static void GL_PostInit(void)
+{
registration_sequence = 1;
- if( gl_vertex_buffer_object->modified ) {
+ if (gl_vertex_buffer_object->modified) {
// enable buffer objects before map is loaded
- if( gl_config.ext_supported & QGL_ARB_vertex_buffer_object ) {
- if( gl_vertex_buffer_object->integer ) {
- Com_Printf( "...enabling GL_ARB_vertex_buffer_object\n" );
- QGL_InitExtensions( QGL_ARB_vertex_buffer_object );
+ if (gl_config.ext_supported & QGL_ARB_vertex_buffer_object) {
+ if (gl_vertex_buffer_object->integer) {
+ Com_Printf("...enabling GL_ARB_vertex_buffer_object\n");
+ QGL_InitExtensions(QGL_ARB_vertex_buffer_object);
gl_config.ext_enabled |= QGL_ARB_vertex_buffer_object;
} else {
- Com_Printf( "...ignoring GL_ARB_vertex_buffer_object\n" );
+ Com_Printf("...ignoring GL_ARB_vertex_buffer_object\n");
}
- } else if( gl_vertex_buffer_object->integer ) {
- Com_Printf( "GL_ARB_vertex_buffer_object not found\n" );
- Cvar_Set( "gl_vertex_buffer_object", "0" );
+ } else if (gl_vertex_buffer_object->integer) {
+ Com_Printf("GL_ARB_vertex_buffer_object not found\n");
+ Cvar_Set("gl_vertex_buffer_object", "0");
}
// reset the modified flag
@@ -873,27 +899,28 @@ static void GL_PostInit( void ) {
GL_SetDefaultState();
}
-// ==============================================================================
+// ==============================================================================
/*
===============
R_Init
===============
*/
-qboolean R_Init( qboolean total ) {
- Com_DPrintf( "GL_Init( %i )\n", total );
+qboolean R_Init(qboolean total)
+{
+ Com_DPrintf("GL_Init( %i )\n", total);
- if( !total ) {
+ if (!total) {
GL_PostInit();
return qtrue;
}
- Com_Printf( "------- R_Init -------\n" );
- Com_DPrintf( "ref_gl " VERSION ", " __DATE__ "\n" );
+ Com_Printf("------- R_Init -------\n");
+ Com_DPrintf("ref_gl " VERSION ", " __DATE__ "\n");
// initialize OS-specific parts of OpenGL
// create the window and set up the context
- if( !VID_Init() ) {
+ if (!VID_Init()) {
return qfalse;
}
@@ -901,24 +928,25 @@ qboolean R_Init( qboolean total ) {
QGL_Init();
// get various static strings from OpenGL
-#define GET_STRING( x ) ( const char * )qglGetString( x )
- gl_config.vendorString = GET_STRING( GL_VENDOR );
- gl_config.rendererString = GET_STRING( GL_RENDERER );
- gl_config.versionString = GET_STRING( GL_VERSION );
- gl_config.extensionsString = GET_STRING( GL_EXTENSIONS );
+#define GET_STRING(x) (const char *)qglGetString(x)
+
+ gl_config.vendorString = GET_STRING(GL_VENDOR);
+ gl_config.rendererString = GET_STRING(GL_RENDERER);
+ gl_config.versionString = GET_STRING(GL_VERSION);
+ gl_config.extensionsString = GET_STRING(GL_EXTENSIONS);
// parse renderer/version strings
GL_IdentifyRenderer();
// parse extension string
- if( !GL_SetupExtensions() ) {
+ if (!GL_SetupExtensions()) {
goto fail;
}
// register our variables
GL_Register();
- QGL_EnableLogging( gl_log->integer );
+ QGL_EnableLogging(gl_log->integer);
gl_log->modified = qfalse;
GL_PostInit();
@@ -928,16 +956,16 @@ qboolean R_Init( qboolean total ) {
GL_InitTables();
- if( (( size_t )tess.vertices) & 15 ) {
- Com_WPrintf( "tess.vertices not 16 byte aligned\n" );
+ if (((size_t)tess.vertices) & 15) {
+ Com_WPrintf("tess.vertices not 16 byte aligned\n");
}
- Com_Printf( "----------------------\n" );
+ Com_Printf("----------------------\n");
return qtrue;
fail:
- memset( &gl_config, 0, sizeof( gl_config ) );
+ memset(&gl_config, 0, sizeof(gl_config));
QGL_Shutdown();
VID_Shutdown();
return qfalse;
@@ -948,23 +976,24 @@ fail:
R_Shutdown
===============
*/
-void R_Shutdown( qboolean total ) {
- Com_DPrintf( "GL_Shutdown( %i )\n", total );
+void R_Shutdown(qboolean total)
+{
+ Com_DPrintf("GL_Shutdown( %i )\n", total);
GL_FreeWorld();
GL_ShutdownImages();
MOD_Shutdown();
- if( gl_vertex_buffer_object->modified ) {
+ if (gl_vertex_buffer_object->modified) {
// disable buffer objects after map is freed
- QGL_ShutdownExtensions( QGL_ARB_vertex_buffer_object );
+ QGL_ShutdownExtensions(QGL_ARB_vertex_buffer_object);
gl_config.ext_enabled &= ~QGL_ARB_vertex_buffer_object;
}
- if( !total ) {
+ if (!total) {
return;
}
-
+
GL_ShutdownPrograms();
// shut down OS specific OpenGL stuff like contexts, etc.
@@ -975,8 +1004,8 @@ void R_Shutdown( qboolean total ) {
GL_Unregister();
- memset( &gl_static, 0, sizeof( gl_static ) );
- memset( &gl_config, 0, sizeof( gl_config ) );
+ memset(&gl_static, 0, sizeof(gl_static));
+ memset(&gl_config, 0, sizeof(gl_config));
}
/*
@@ -984,17 +1013,18 @@ void R_Shutdown( qboolean total ) {
R_BeginRegistration
===============
*/
-void R_BeginRegistration( const char *name ) {
+void R_BeginRegistration(const char *name)
+{
char fullname[MAX_QPATH];
gl_static.registering = qtrue;
registration_sequence++;
- memset( &glr, 0, sizeof( glr ) );
+ memset(&glr, 0, sizeof(glr));
glr.viewcluster1 = glr.viewcluster2 = -2;
-
- Q_concat( fullname, sizeof( fullname ), "maps/", name, ".bsp", NULL );
- GL_LoadWorld( fullname );
+
+ Q_concat(fullname, sizeof(fullname), "maps/", name, ".bsp", NULL);
+ GL_LoadWorld(fullname);
}
/*
@@ -1002,7 +1032,8 @@ void R_BeginRegistration( const char *name ) {
R_EndRegistration
===============
*/
-void R_EndRegistration( void ) {
+void R_EndRegistration(void)
+{
IMG_FreeUnused();
MOD_FreeUnused();
Scrap_Upload();
@@ -1014,7 +1045,8 @@ void R_EndRegistration( void ) {
R_ModeChanged
===============
*/
-void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels ) {
+void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels)
+{
r_config.width = width & ~7;
r_config.height = height & ~1;
r_config.flags = flags;
diff --git a/src/gl_mesh.c b/src/gl_mesh.c
index 1135cf3..046a6d9 100644
--- a/src/gl_mesh.c
+++ b/src/gl_mesh.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -30,17 +30,18 @@ static vec3_t translate;
static float frontlerp;
static float backlerp;
-typedef void (*tessfunc_t)( const maliasmesh_t *, int, int );
+typedef void (*tessfunc_t)(const maliasmesh_t *, int, int);
#if USE_DOTSHADING
static const vec_t *shadelight;
static vec3_t shadedir;
// matches the anormtab.h precalculations
-static inline vec_t shadedot( const vec_t *normal ) {
- vec_t d = DotProduct( normal, shadedir );
+static inline vec_t shadedot(const vec_t *normal)
+{
+ vec_t d = DotProduct(normal, shadedir);
- if( d < 0 ) {
+ if (d < 0) {
d *= 0.3f;
}
@@ -49,60 +50,62 @@ static inline vec_t shadedot( const vec_t *normal ) {
#endif // USE_DOTSHADING
-static inline void get_static_normal( vec_t *normal, const maliasvert_t *vert ) {
+static inline void get_static_normal(vec_t *normal, const maliasvert_t *vert)
+{
unsigned lat = vert->norm[0];
unsigned lng = vert->norm[1];
- normal[0] = TAB_SIN( lat ) * TAB_COS( lng );
- normal[1] = TAB_SIN( lat ) * TAB_SIN( lng );
- normal[2] = TAB_COS( lat );
+ normal[0] = TAB_SIN(lat) * TAB_COS(lng);
+ normal[1] = TAB_SIN(lat) * TAB_SIN(lng);
+ normal[2] = TAB_COS(lat);
}
-static void tess_static_mesh( const maliasmesh_t *mesh, int oldframe, int newframe ) {
+static void tess_static_mesh(const maliasmesh_t *mesh, int oldframe, int newframe)
+{
maliasvert_t *src_vert = &mesh->verts[newframe * mesh->numverts];
vec_t *dst_vert = tess.vertices;
int i, count = mesh->numverts;
vec3_t normal;
- if( glr.ent->flags & RF_SHELL_MASK ) {
+ if (glr.ent->flags & RF_SHELL_MASK) {
vec_t scale = (glr.ent->flags & RF_WEAPONMODEL) ? WEAPONSHELL_SCALE : POWERSUIT_SCALE;
- for( i = 0; i < count; i++ ) {
- get_static_normal( normal, src_vert );
+ for (i = 0; i < count; i++) {
+ get_static_normal(normal, src_vert);
dst_vert[0] = normal[0] * scale +
- src_vert->pos[0] * newscale[0] + translate[0];
+ src_vert->pos[0] * newscale[0] + translate[0];
dst_vert[1] = normal[1] * scale +
- src_vert->pos[1] * newscale[1] + translate[1];
+ src_vert->pos[1] * newscale[1] + translate[1];
dst_vert[2] = normal[2] * scale +
- src_vert->pos[2] * newscale[2] + translate[2];
+ src_vert->pos[2] * newscale[2] + translate[2];
dst_vert += 4;
src_vert++;
}
#if USE_DOTSHADING
- } else if( shadelight ) {
+ } else if (shadelight) {
vec_t d;
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
dst_vert[0] = src_vert->pos[0] * newscale[0] + translate[0];
dst_vert[1] = src_vert->pos[1] * newscale[1] + translate[1];
dst_vert[2] = src_vert->pos[2] * newscale[2] + translate[2];
- get_static_normal( normal, src_vert );
+ get_static_normal(normal, src_vert);
- d = shadedot( normal );
+ d = shadedot(normal);
dst_vert[3] = shadelight[0] * d;
dst_vert[4] = shadelight[1] * d;
dst_vert[5] = shadelight[2] * d;
dst_vert[6] = shadelight[3];
dst_vert += VERTEX_SIZE;
-
+
src_vert++;
}
#endif
} else {
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
dst_vert[0] = src_vert->pos[0] * newscale[0] + translate[0];
dst_vert[1] = src_vert->pos[1] * newscale[1] + translate[1];
dst_vert[2] = src_vert->pos[2] * newscale[2] + translate[2];
@@ -115,54 +118,55 @@ static void tess_static_mesh( const maliasmesh_t *mesh, int oldframe, int newfra
c.trisDrawn += count;
}
-static inline void get_lerped_normal( vec_t *normal,
- const maliasvert_t *oldvert, const maliasvert_t *newvert )
+static inline void get_lerped_normal(vec_t *normal,
+ const maliasvert_t *oldvert, const maliasvert_t *newvert)
{
vec3_t oldnorm, newnorm, tmp;
vec_t len;
- get_static_normal( oldnorm, oldvert );
- get_static_normal( newnorm, newvert );
+ get_static_normal(oldnorm, oldvert);
+ get_static_normal(newnorm, newvert);
- LerpVector2( oldnorm, newnorm, backlerp, frontlerp, tmp );
+ LerpVector2(oldnorm, newnorm, backlerp, frontlerp, tmp);
// normalize result
- len = 1 / VectorLength( tmp );
- VectorScale( tmp, len, normal );
+ len = 1 / VectorLength(tmp);
+ VectorScale(tmp, len, normal);
}
-static void tess_lerped_mesh( const maliasmesh_t *mesh, int oldframe, int newframe ) {
+static void tess_lerped_mesh(const maliasmesh_t *mesh, int oldframe, int newframe)
+{
maliasvert_t *src_oldvert = &mesh->verts[oldframe * mesh->numverts];
maliasvert_t *src_newvert = &mesh->verts[newframe * mesh->numverts];
vec_t *dst_vert = tess.vertices;
int i, count = mesh->numverts;
vec3_t normal;
- if( glr.ent->flags & RF_SHELL_MASK ) {
+ if (glr.ent->flags & RF_SHELL_MASK) {
vec_t scale = (glr.ent->flags & RF_WEAPONMODEL) ? WEAPONSHELL_SCALE : POWERSUIT_SCALE;
- for( i = 0; i < count; i++ ) {
- get_lerped_normal( normal, src_oldvert, src_newvert );
+ for (i = 0; i < count; i++) {
+ get_lerped_normal(normal, src_oldvert, src_newvert);
dst_vert[0] = normal[0] * scale +
- src_oldvert->pos[0] * oldscale[0] +
- src_newvert->pos[0] * newscale[0] + translate[0];
+ src_oldvert->pos[0] * oldscale[0] +
+ src_newvert->pos[0] * newscale[0] + translate[0];
dst_vert[1] = normal[1] * scale +
- src_oldvert->pos[1] * oldscale[1] +
- src_newvert->pos[1] * newscale[1] + translate[1];
+ src_oldvert->pos[1] * oldscale[1] +
+ src_newvert->pos[1] * newscale[1] + translate[1];
dst_vert[2] = normal[2] * scale +
- src_oldvert->pos[2] * oldscale[2] +
- src_newvert->pos[2] * newscale[2] + translate[2];
+ src_oldvert->pos[2] * oldscale[2] +
+ src_newvert->pos[2] * newscale[2] + translate[2];
dst_vert += 4;
-
+
src_oldvert++;
src_newvert++;
}
#if USE_DOTSHADING
- } else if( shadelight ) {
+ } else if (shadelight) {
vec_t d;
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
dst_vert[0] =
src_oldvert->pos[0] * oldscale[0] +
src_newvert->pos[0] * newscale[0] + translate[0];
@@ -173,9 +177,9 @@ static void tess_lerped_mesh( const maliasmesh_t *mesh, int oldframe, int newfra
src_oldvert->pos[2] * oldscale[2] +
src_newvert->pos[2] * newscale[2] + translate[2];
- get_lerped_normal( normal, src_oldvert, src_newvert );
+ get_lerped_normal(normal, src_oldvert, src_newvert);
- d = shadedot( normal );
+ d = shadedot(normal);
dst_vert[3] = shadelight[0] * d;
dst_vert[4] = shadelight[1] * d;
dst_vert[5] = shadelight[2] * d;
@@ -187,7 +191,7 @@ static void tess_lerped_mesh( const maliasmesh_t *mesh, int oldframe, int newfra
}
#endif
} else {
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
dst_vert[0] =
src_oldvert->pos[0] * oldscale[0] +
src_newvert->pos[0] * newscale[0] + translate[0];
@@ -203,70 +207,72 @@ static void tess_lerped_mesh( const maliasmesh_t *mesh, int oldframe, int newfra
src_newvert++;
}
}
-
+
c.trisDrawn += count;
}
-static void GL_SetAliasColor( vec3_t origin, vec_t *color ) {
+static void GL_SetAliasColor(vec3_t origin, vec_t *color)
+{
int flags = glr.ent->flags;
float f, m;
int i;
- if( flags & RF_SHELL_MASK ) {
- VectorClear( color );
- if( flags & RF_SHELL_HALF_DAM ) {
+ if (flags & RF_SHELL_MASK) {
+ VectorClear(color);
+ if (flags & RF_SHELL_HALF_DAM) {
color[0] = 0.56f;
color[1] = 0.59f;
color[2] = 0.45f;
}
- if( flags & RF_SHELL_DOUBLE ) {
+ if (flags & RF_SHELL_DOUBLE) {
color[0] = 0.9f;
color[1] = 0.7f;
}
- if( flags & RF_SHELL_RED ) {
+ if (flags & RF_SHELL_RED) {
color[0] = 1;
}
- if( flags & RF_SHELL_GREEN ) {
+ if (flags & RF_SHELL_GREEN) {
color[1] = 1;
}
- if( flags & RF_SHELL_BLUE ) {
+ if (flags & RF_SHELL_BLUE) {
color[2] = 1;
}
- } else if( flags & RF_FULLBRIGHT ) {
- VectorSet( color, 1, 1, 1 );
- } else if( ( flags & RF_IR_VISIBLE ) && ( glr.fd.rdflags & RDF_IRGOGGLES ) ) {
- VectorSet( color, 1, 0, 0 );
+ } else if (flags & RF_FULLBRIGHT) {
+ VectorSet(color, 1, 1, 1);
+ } else if ((flags & RF_IR_VISIBLE) && (glr.fd.rdflags & RDF_IRGOGGLES)) {
+ VectorSet(color, 1, 0, 0);
} else {
- _R_LightPoint( origin, color );
+ _R_LightPoint(origin, color);
- if( flags & RF_MINLIGHT ) {
- for( i = 0; i < 3; i++ ) {
- if( color[i] > 0.1f ) {
+ if (flags & RF_MINLIGHT) {
+ for (i = 0; i < 3; i++) {
+ if (color[i] > 0.1f) {
break;
}
}
- if( i == 3 ) {
- VectorSet( color, 0.1f, 0.1f, 0.1f );
+ if (i == 3) {
+ VectorSet(color, 0.1f, 0.1f, 0.1f);
}
}
- if( flags & RF_GLOW ) {
- f = 0.1f * sin( glr.fd.time * 7 );
- for( i = 0; i < 3; i++ ) {
+ if (flags & RF_GLOW) {
+ f = 0.1f * sin(glr.fd.time * 7);
+ for (i = 0; i < 3; i++) {
m = color[i] * 0.8f;
color[i] += f;
- if( color[i] < m )
+ if (color[i] < m)
color[i] = m;
}
}
- for( i = 0; i < 3; i++ ) {
- clamp( color[i], 0, 1 );
+ for (i = 0; i < 3; i++) {
+ clamp(color[i], 0, 1);
}
}
}
-void GL_DrawAliasModel( model_t *model ) {
+void GL_DrawAliasModel(model_t *model)
+{
entity_t *ent = glr.ent;
image_t *image;
int oldframeIdx, newframeIdx;
@@ -286,14 +292,14 @@ void GL_DrawAliasModel( model_t *model ) {
int back, front;
newframeIdx = ent->frame;
- if( newframeIdx < 0 || newframeIdx >= model->numframes ) {
- Com_DPrintf( "%s: no such frame %d\n", __func__, newframeIdx );
+ if (newframeIdx < 0 || newframeIdx >= model->numframes) {
+ Com_DPrintf("%s: no such frame %d\n", __func__, newframeIdx);
newframeIdx = 0;
}
oldframeIdx = ent->oldframe;
- if( oldframeIdx < 0 || oldframeIdx >= model->numframes ) {
- Com_DPrintf( "%s: no such oldframe %d\n", __func__, oldframeIdx );
+ if (oldframeIdx < 0 || oldframeIdx >= model->numframes) {
+ Com_DPrintf("%s: no such oldframe %d\n", __func__, oldframeIdx);
oldframeIdx = 0;
}
@@ -303,122 +309,121 @@ void GL_DrawAliasModel( model_t *model ) {
frontlerp = 1.0f - backlerp;
// interpolate origin, if necessarry
- if( ent->flags & RF_FRAMELERP ) {
- LerpVector2( ent->oldorigin, ent->origin,
- backlerp, frontlerp, origin );
+ if (ent->flags & RF_FRAMELERP) {
+ LerpVector2(ent->oldorigin, ent->origin,
+ backlerp, frontlerp, origin);
} else {
- VectorCopy( ent->origin, origin );
+ VectorCopy(ent->origin, origin);
}
- if( newframeIdx == oldframeIdx || backlerp == 0 ) {
+ if (newframeIdx == oldframeIdx || backlerp == 0) {
oldframe = NULL;
- if( glr.entrotated ) {
- cull = GL_CullSphere( origin, newframe->radius );
- if( cull == CULL_OUT ) {
+ if (glr.entrotated) {
+ cull = GL_CullSphere(origin, newframe->radius);
+ if (cull == CULL_OUT) {
c.spheresCulled++;
return;
}
- if( cull == CULL_CLIP ) {
- cull = GL_CullLocalBox( origin, newframe->bounds );
- if( cull == CULL_OUT ) {
+ if (cull == CULL_CLIP) {
+ cull = GL_CullLocalBox(origin, newframe->bounds);
+ if (cull == CULL_OUT) {
c.rotatedBoxesCulled++;
return;
}
}
} else {
- VectorAdd( newframe->bounds[0], origin, bounds[0] );
- VectorAdd( newframe->bounds[1], origin, bounds[1] );
- if( GL_CullBox( bounds ) == CULL_OUT ) {
+ VectorAdd(newframe->bounds[0], origin, bounds[0]);
+ VectorAdd(newframe->bounds[1], origin, bounds[1]);
+ if (GL_CullBox(bounds) == CULL_OUT) {
c.boxesCulled++;
return;
}
}
- VectorCopy( newframe->scale, newscale );
- VectorCopy( newframe->translate, translate );
+ VectorCopy(newframe->scale, newscale);
+ VectorCopy(newframe->translate, translate);
tessfunc = tess_static_mesh;
} else {
oldframe = model->frames + oldframeIdx;
- if( glr.entrotated ) {
+ if (glr.entrotated) {
radius = newframe->radius > oldframe->radius ?
- newframe->radius : oldframe->radius;
- cull = GL_CullSphere( origin, radius );
- if( cull == CULL_OUT ) {
+ newframe->radius : oldframe->radius;
+ cull = GL_CullSphere(origin, radius);
+ if (cull == CULL_OUT) {
c.spheresCulled++;
return;
}
- UnionBounds( newframe->bounds, oldframe->bounds, bounds );
- if( cull == CULL_CLIP ) {
- cull = GL_CullLocalBox( origin, bounds );
- if( cull == CULL_OUT ) {
+ UnionBounds(newframe->bounds, oldframe->bounds, bounds);
+ if (cull == CULL_CLIP) {
+ cull = GL_CullLocalBox(origin, bounds);
+ if (cull == CULL_OUT) {
c.rotatedBoxesCulled++;
return;
}
}
} else {
- UnionBounds( newframe->bounds, oldframe->bounds, bounds );
- VectorAdd( bounds[0], origin, bounds[0] );
- VectorAdd( bounds[1], origin, bounds[1] );
- if( GL_CullBox( bounds ) == CULL_OUT ) {
+ UnionBounds(newframe->bounds, oldframe->bounds, bounds);
+ VectorAdd(bounds[0], origin, bounds[0]);
+ VectorAdd(bounds[1], origin, bounds[1]);
+ if (GL_CullBox(bounds) == CULL_OUT) {
c.boxesCulled++;
return;
}
}
- VectorScale( oldframe->scale, backlerp, oldscale );
- VectorScale( newframe->scale, frontlerp, newscale );
+ VectorScale(oldframe->scale, backlerp, oldscale);
+ VectorScale(newframe->scale, frontlerp, newscale);
- LerpVector2( oldframe->translate, newframe->translate,
- backlerp, frontlerp, translate );
+ LerpVector2(oldframe->translate, newframe->translate,
+ backlerp, frontlerp, translate);
tessfunc = tess_lerped_mesh;
}
#if USE_CELSHADING
scale = 0;
- if( gl_celshading->value > 0 && ( ent->flags & RF_SHELL_MASK ) == 0 ) {
- if( gl_celshading->value > 10 ) {
- Cvar_Set( "gl_celshading", "10" );
+ if (gl_celshading->value > 0 && (ent->flags & RF_SHELL_MASK) == 0) {
+ if (gl_celshading->value > 10) {
+ Cvar_Set("gl_celshading", "10");
}
- VectorSubtract( origin, glr.fd.vieworg, dir );
- scale = VectorLength( dir );
+ VectorSubtract(origin, glr.fd.vieworg, dir);
+ scale = VectorLength(dir);
scale = 1.0f - scale / 700.0f;
}
#endif
// setup color
- GL_SetAliasColor( origin, color );
+ GL_SetAliasColor(origin, color);
// setup transparency
bits = GLS_DEFAULT;
color[3] = 1;
- if( ent->flags & RF_TRANSLUCENT ) {
+ if (ent->flags & RF_TRANSLUCENT) {
color[3] = ent->alpha;
- bits |= GLS_BLEND_BLEND|GLS_DEPTHMASK_FALSE;
+ bits |= GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE;
}
- GL_TexEnv( GL_MODULATE );
-
+ GL_TexEnv(GL_MODULATE);
+
qglPushMatrix();
- qglTranslatef( origin[0], origin[1], origin[2] );
- if( glr.entrotated ) {
- qglRotatef( ent->angles[YAW], 0, 0, 1 );
- qglRotatef( ent->angles[PITCH], 0, 1, 0 );
- qglRotatef( ent->angles[ROLL], 1, 0, 0 );
+ qglTranslatef(origin[0], origin[1], origin[2]);
+ if (glr.entrotated) {
+ qglRotatef(ent->angles[YAW], 0, 0, 1);
+ qglRotatef(ent->angles[PITCH], 0, 1, 0);
+ qglRotatef(ent->angles[ROLL], 1, 0, 0);
}
- if( ent->flags & RF_DEPTHHACK ) {
- qglDepthRange( 0, 0.25f );
+ if (ent->flags & RF_DEPTHHACK) {
+ qglDepthRange(0, 0.25f);
}
- if( ( ent->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) ==
- (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
- qglMatrixMode( GL_PROJECTION );
- qglScalef( -1, 1, 1 );
- qglMatrixMode( GL_MODELVIEW );
- qglCullFace( GL_BACK );
+ if ((ent->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) ==
+ (RF_WEAPONMODEL | RF_LEFTHAND)) {
+ qglMatrixMode(GL_PROJECTION);
+ qglScalef(-1, 1, 1);
+ qglMatrixMode(GL_MODELVIEW);
+ qglCullFace(GL_BACK);
back = GL_BACK;
front = GL_FRONT;
} else {
@@ -428,48 +433,48 @@ void GL_DrawAliasModel( model_t *model ) {
#if USE_DOTSHADING
shadelight = NULL;
- if( gl_dotshading->integer && ( ent->flags & RF_SHELL_MASK ) == 0 ) {
+ if (gl_dotshading->integer && (ent->flags & RF_SHELL_MASK) == 0) {
float cp, cy, sp, sy;
vec_t yaw;
shadelight = color;
// matches the anormtab.h precalculations
- yaw = -DEG2RAD( ent->angles[YAW] );
- cy = cos( yaw );
- sy = sin( yaw );
- cp = cos( -M_PI/4 );
- sp = sin( -M_PI/4 );
- shadedir[0] = cp*cy;
- shadedir[1] = cp*sy;
+ yaw = -DEG2RAD(ent->angles[YAW]);
+ cy = cos(yaw);
+ sy = sin(yaw);
+ cp = cos(-M_PI / 4);
+ sp = sin(-M_PI / 4);
+ shadedir[0] = cp * cy;
+ shadedir[1] = cp * sy;
shadedir[2] = -sp;
- qglVertexPointer( 3, GL_FLOAT, 4*VERTEX_SIZE, tess.vertices );
- qglColorPointer( 4, GL_FLOAT, 4*VERTEX_SIZE, tess.vertices + 3 );
- qglEnableClientState( GL_COLOR_ARRAY );
+ qglVertexPointer(3, GL_FLOAT, 4 * VERTEX_SIZE, tess.vertices);
+ qglColorPointer(4, GL_FLOAT, 4 * VERTEX_SIZE, tess.vertices + 3);
+ qglEnableClientState(GL_COLOR_ARRAY);
} else
#endif
{
- qglVertexPointer( 3, GL_FLOAT, 4*4, tess.vertices );
- qglColor4fv( color );
+ qglVertexPointer(3, GL_FLOAT, 4 * 4, tess.vertices);
+ qglColor4fv(color);
}
last = model->meshes + model->nummeshes;
- for( mesh = model->meshes; mesh < last; mesh++ ) {
- if( ent->flags & RF_SHELL_MASK ) {
- GL_Bits( bits );
- GL_BindTexture( TEXNUM_WHITE );
+ for (mesh = model->meshes; mesh < last; mesh++) {
+ if (ent->flags & RF_SHELL_MASK) {
+ GL_Bits(bits);
+ GL_BindTexture(TEXNUM_WHITE);
} else {
- if( ent->skin ) {
- image = IMG_ForHandle( ent->skin );
- } else if( mesh->numskins ) {
- if( ent->skinnum < 0 || ent->skinnum >= mesh->numskins ) {
- Com_DPrintf( "%s: no such skin: %d\n",
- __func__, ent->skinnum );
+ if (ent->skin) {
+ image = IMG_ForHandle(ent->skin);
+ } else if (mesh->numskins) {
+ if (ent->skinnum < 0 || ent->skinnum >= mesh->numskins) {
+ Com_DPrintf("%s: no such skin: %d\n",
+ __func__, ent->skinnum);
image = mesh->skins[0];
} else {
image = mesh->skins[ent->skinnum];
- if( image->texnum == TEXNUM_DEFAULT ) {
+ if (image->texnum == TEXNUM_DEFAULT) {
image = mesh->skins[0];
}
}
@@ -477,85 +482,84 @@ void GL_DrawAliasModel( model_t *model ) {
image = R_NOTEXTURE;
}
- if( ( image->flags & ( if_transparent|if_paletted ) ) == if_transparent ) {
- GL_Bits( bits | GLS_BLEND_BLEND );
+ if ((image->flags & (if_transparent | if_paletted)) == if_transparent) {
+ GL_Bits(bits | GLS_BLEND_BLEND);
} else {
- GL_Bits( bits );
+ GL_Bits(bits);
}
- GL_BindTexture( image->texnum );
+ GL_BindTexture(image->texnum);
}
- (*tessfunc)( mesh, oldframeIdx, newframeIdx );
+ (*tessfunc)(mesh, oldframeIdx, newframeIdx);
- qglTexCoordPointer( 2, GL_FLOAT, 0, mesh->tcoords );
+ qglTexCoordPointer(2, GL_FLOAT, 0, mesh->tcoords);
- if( qglLockArraysEXT ) {
- qglLockArraysEXT( 0, mesh->numverts );
+ if (qglLockArraysEXT) {
+ qglLockArraysEXT(0, mesh->numverts);
}
- qglDrawElements( GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
- mesh->indices );
+ qglDrawElements(GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
+ mesh->indices);
#if USE_CELSHADING
- if( scale > 0 && scale <= 1 ) {
- qglCullFace( front );
- qglPolygonMode( back, GL_LINE );
- qglDisable( GL_TEXTURE_2D );
- qglLineWidth( gl_celshading->value*scale );
- GL_Bits( bits | GLS_BLEND_BLEND );
+ if (scale > 0 && scale <= 1) {
+ qglCullFace(front);
+ qglPolygonMode(back, GL_LINE);
+ qglDisable(GL_TEXTURE_2D);
+ qglLineWidth(gl_celshading->value * scale);
+ GL_Bits(bits | GLS_BLEND_BLEND);
#if USE_DOTSHADING
- if( shadelight ) {
- qglDisableClientState( GL_COLOR_ARRAY );
+ if (shadelight) {
+ qglDisableClientState(GL_COLOR_ARRAY);
}
#endif
- qglColor4f( 0, 0, 0, scale );
- qglDrawElements( GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
- mesh->indices );
- qglCullFace( back );
- qglPolygonMode( back, GL_FILL );
+ qglColor4f(0, 0, 0, scale);
+ qglDrawElements(GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
+ mesh->indices);
+ qglCullFace(back);
+ qglPolygonMode(back, GL_FILL);
#if USE_DOTSHADING
- if( shadelight ) {
- qglEnableClientState( GL_COLOR_ARRAY );
+ if (shadelight) {
+ qglEnableClientState(GL_COLOR_ARRAY);
} else
#endif
- qglColor4fv( color );
- qglLineWidth( 1 );
- qglEnable( GL_TEXTURE_2D );
+ qglColor4fv(color);
+ qglLineWidth(1);
+ qglEnable(GL_TEXTURE_2D);
}
#endif
- if( gl_showtris->integer ) {
+ if (gl_showtris->integer) {
GL_EnableOutlines();
- qglDrawElements( GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
- mesh->indices );
+ qglDrawElements(GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT,
+ mesh->indices);
GL_DisableOutlines();
}
- if( qglUnlockArraysEXT ) {
+ if (qglUnlockArraysEXT) {
qglUnlockArraysEXT();
}
}
#if USE_DOTSHADING
- if( shadelight ) {
- qglDisableClientState( GL_COLOR_ARRAY );
+ if (shadelight) {
+ qglDisableClientState(GL_COLOR_ARRAY);
}
#endif
- if( ent->flags & RF_DEPTHHACK ) {
- qglDepthRange( 0, 1 );
+ if (ent->flags & RF_DEPTHHACK) {
+ qglDepthRange(0, 1);
}
- if( ( ent->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) ==
- (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
- qglMatrixMode( GL_PROJECTION );
- qglScalef( -1, 1, 1 );
- qglMatrixMode( GL_MODELVIEW );
- qglCullFace( GL_FRONT );
+ if ((ent->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) ==
+ (RF_WEAPONMODEL | RF_LEFTHAND)) {
+ qglMatrixMode(GL_PROJECTION);
+ qglScalef(-1, 1, 1);
+ qglMatrixMode(GL_MODELVIEW);
+ qglCullFace(GL_FRONT);
}
-
+
qglPopMatrix();
}
diff --git a/src/gl_models.c b/src/gl_models.c
index 400c764..3af4354 100644
--- a/src/gl_models.c
+++ b/src/gl_models.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "d_md3.h"
#include "d_sp2.h"
-qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
+qerror_t MOD_LoadMD2(model_t *model, const void *rawdata, size_t length)
+{
dmd2header_t header;
dmd2frame_t *src_frame;
dmd2trivertx_t *src_vert;
@@ -35,9 +36,9 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
uint32_t *finalIndices;
maliastc_t *dst_tc;
int i, j, k;
- uint16_t remap[MD2_MAX_TRIANGLES*3];
- uint16_t vertIndices[MD2_MAX_TRIANGLES*3];
- uint16_t tcIndices[MD2_MAX_TRIANGLES*3];
+ uint16_t remap[MD2_MAX_TRIANGLES * 3];
+ uint16_t vertIndices[MD2_MAX_TRIANGLES * 3];
+ uint16_t tcIndices[MD2_MAX_TRIANGLES * 3];
int numverts, numindices;
char skinname[MAX_QPATH];
char *src_skin;
@@ -46,20 +47,20 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
vec3_t mins, maxs;
qerror_t ret;
- if( length < sizeof( header ) ) {
+ if (length < sizeof(header)) {
return Q_ERR_FILE_TOO_SMALL;
}
// byte swap the header
- header = *( dmd2header_t * )rawdata;
- for( i = 0; i < sizeof( header )/4; i++ ) {
- (( uint32_t * )&header)[i] = LittleLong( (( uint32_t * )&header)[i] );
+ header = *(dmd2header_t *)rawdata;
+ for (i = 0; i < sizeof(header) / 4; i++) {
+ ((uint32_t *)&header)[i] = LittleLong(((uint32_t *)&header)[i]);
}
// validate the header
- ret = MOD_ValidateMD2( &header, length );
- if( ret ) {
- if( ret == Q_ERR_TOO_FEW ) {
+ ret = MOD_ValidateMD2(&header, length);
+ if (ret) {
+ if (ret == Q_ERR_TOO_FEW) {
// empty models draw nothing
model->type = MOD_EMPTY;
return Q_ERR_SUCCESS;
@@ -67,58 +68,57 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
return ret;
}
- Hunk_Begin( &model->pool, 0x400000 );
+ Hunk_Begin(&model->pool, 0x400000);
model->type = MOD_ALIAS;
// load all triangle indices
- src_tri = ( dmd2triangle_t * )( ( byte * )rawdata + header.ofs_tris );
- for( i = 0; i < header.num_tris; i++ ) {
- for( j = 0; j < 3; j++ ) {
- uint16_t idx_xyz = LittleShort( src_tri->index_xyz[j] );
- uint16_t idx_st = LittleShort( src_tri->index_st[j] );
+ src_tri = (dmd2triangle_t *)((byte *)rawdata + header.ofs_tris);
+ for (i = 0; i < header.num_tris; i++) {
+ for (j = 0; j < 3; j++) {
+ uint16_t idx_xyz = LittleShort(src_tri->index_xyz[j]);
+ uint16_t idx_st = LittleShort(src_tri->index_st[j]);
- if( idx_xyz >= header.num_xyz || idx_st >= header.num_st ) {
+ if (idx_xyz >= header.num_xyz || idx_st >= header.num_st) {
ret = Q_ERR_BAD_INDEX;
goto fail;
}
- vertIndices[i*3+j] = idx_xyz;
- tcIndices[i*3+j] = idx_st;
+ vertIndices[i * 3 + j] = idx_xyz;
+ tcIndices[i * 3 + j] = idx_st;
}
src_tri++;
}
numindices = header.num_tris * 3;
- model->meshes = MOD_Malloc( sizeof( maliasmesh_t ) );
+ model->meshes = MOD_Malloc(sizeof(maliasmesh_t));
model->nummeshes = 1;
dst_mesh = model->meshes;
- dst_mesh->indices = MOD_Malloc( numindices * sizeof( uint32_t ) );
+ dst_mesh->indices = MOD_Malloc(numindices * sizeof(uint32_t));
dst_mesh->numtris = header.num_tris;
dst_mesh->numindices = numindices;
- for( i = 0; i < numindices; i++ ) {
+ for (i = 0; i < numindices; i++) {
remap[i] = 0xFFFF;
}
numverts = 0;
- src_tc = ( dmd2stvert_t * )( ( byte * )rawdata + header.ofs_st );
+ src_tc = (dmd2stvert_t *)((byte *)rawdata + header.ofs_st);
finalIndices = dst_mesh->indices;
- for( i = 0; i < numindices; i++ ) {
- if( remap[i] != 0xFFFF ) {
+ for (i = 0; i < numindices; i++) {
+ if (remap[i] != 0xFFFF) {
continue; // already remapped
}
- for( j = i + 1; j < numindices; j++ ) {
- if( vertIndices[i] == vertIndices[j] &&
- ( src_tc[tcIndices[i]].s == src_tc[tcIndices[j]].s &&
- src_tc[tcIndices[i]].t == src_tc[tcIndices[j]].t ) )
- {
+ for (j = i + 1; j < numindices; j++) {
+ if (vertIndices[i] == vertIndices[j] &&
+ (src_tc[tcIndices[i]].s == src_tc[tcIndices[j]].s &&
+ src_tc[tcIndices[i]].t == src_tc[tcIndices[j]].t)) {
// duplicate vertex
remap[j] = i;
finalIndices[j] = numverts;
- }
+ }
}
// new vertex
@@ -126,98 +126,99 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
finalIndices[i] = numverts++;
}
- dst_mesh->verts = MOD_Malloc( numverts * header.num_frames * sizeof( maliasvert_t ) );
- dst_mesh->tcoords = MOD_Malloc( numverts * sizeof( maliastc_t ) );
+ dst_mesh->verts = MOD_Malloc(numverts * header.num_frames * sizeof(maliasvert_t));
+ dst_mesh->tcoords = MOD_Malloc(numverts * sizeof(maliastc_t));
dst_mesh->numverts = numverts;
// load all skins
- src_skin = ( char * )rawdata + header.ofs_skins;
- for( i = 0; i < header.num_skins; i++ ) {
- if( !Q_memccpy( skinname, src_skin, 0, sizeof( skinname ) ) ) {
+ src_skin = (char *)rawdata + header.ofs_skins;
+ for (i = 0; i < header.num_skins; i++) {
+ if (!Q_memccpy(skinname, src_skin, 0, sizeof(skinname))) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
- FS_NormalizePath( skinname, skinname );
- dst_mesh->skins[i] = IMG_Find( skinname, it_skin );
+ FS_NormalizePath(skinname, skinname);
+ dst_mesh->skins[i] = IMG_Find(skinname, it_skin);
src_skin += MD2_MAX_SKINNAME;
}
dst_mesh->numskins = header.num_skins;
// load all tcoords
- src_tc = ( dmd2stvert_t * )( ( byte * )rawdata + header.ofs_st );
+ src_tc = (dmd2stvert_t *)((byte *)rawdata + header.ofs_st);
dst_tc = dst_mesh->tcoords;
scaleS = 1.0f / header.skinwidth;
scaleT = 1.0f / header.skinheight;
- for( i = 0; i < numindices; i++ ) {
- if( remap[i] == i ) {
- float s = ( int16_t )LittleShort( src_tc[ tcIndices[i] ].s );
- float t = ( int16_t )LittleShort( src_tc[ tcIndices[i] ].t );
+ for (i = 0; i < numindices; i++) {
+ if (remap[i] == i) {
+ float s = (int16_t)LittleShort(src_tc[tcIndices[i]].s);
+ float t = (int16_t)LittleShort(src_tc[tcIndices[i]].t);
- dst_tc[ finalIndices[i] ].st[0] = s * scaleS;
- dst_tc[ finalIndices[i] ].st[1] = t * scaleT;
+ dst_tc[finalIndices[i]].st[0] = s * scaleS;
+ dst_tc[finalIndices[i]].st[1] = t * scaleT;
}
}
// load all frames
- model->frames = MOD_Malloc( header.num_frames * sizeof( maliasframe_t ) );
+ model->frames = MOD_Malloc(header.num_frames * sizeof(maliasframe_t));
model->numframes = header.num_frames;
- src_frame = ( dmd2frame_t * )( ( byte * )rawdata + header.ofs_frames );
+ src_frame = (dmd2frame_t *)((byte *)rawdata + header.ofs_frames);
dst_frame = model->frames;
- for( j = 0; j < header.num_frames; j++ ) {
- LittleVector( src_frame->scale, dst_frame->scale );
- LittleVector( src_frame->translate, dst_frame->translate );
+ for (j = 0; j < header.num_frames; j++) {
+ LittleVector(src_frame->scale, dst_frame->scale);
+ LittleVector(src_frame->translate, dst_frame->translate);
// load frame vertices
- ClearBounds( mins, maxs );
- for( i = 0; i < numindices; i++ ) {
- if( remap[i] == i ) {
- src_vert = &src_frame->verts[ vertIndices[i] ];
- dst_vert = &dst_mesh->verts[ j * numverts + finalIndices[i] ];
+ ClearBounds(mins, maxs);
+ for (i = 0; i < numindices; i++) {
+ if (remap[i] == i) {
+ src_vert = &src_frame->verts[vertIndices[i]];
+ dst_vert = &dst_mesh->verts[j * numverts + finalIndices[i]];
dst_vert->pos[0] = src_vert->v[0];
dst_vert->pos[1] = src_vert->v[1];
dst_vert->pos[2] = src_vert->v[2];
k = src_vert->lightnormalindex;
- if( k >= NUMVERTEXNORMALS ) {
+ if (k >= NUMVERTEXNORMALS) {
ret = Q_ERR_BAD_INDEX;
goto fail;
}
dst_vert->norm[0] = gl_static.latlngtab[k][0];
dst_vert->norm[1] = gl_static.latlngtab[k][1];
- for ( k = 0; k < 3; k++ ) {
+ for (k = 0; k < 3; k++) {
val = dst_vert->pos[k];
- if( val < mins[k] )
+ if (val < mins[k])
mins[k] = val;
- if( val > maxs[k] )
+ if (val > maxs[k])
maxs[k] = val;
}
}
}
- VectorVectorScale( mins, dst_frame->scale, mins );
- VectorVectorScale( maxs, dst_frame->scale, maxs );
+ VectorVectorScale(mins, dst_frame->scale, mins);
+ VectorVectorScale(maxs, dst_frame->scale, maxs);
- dst_frame->radius = RadiusFromBounds( mins, maxs );
+ dst_frame->radius = RadiusFromBounds(mins, maxs);
- VectorAdd( mins, dst_frame->translate, dst_frame->bounds[0] );
- VectorAdd( maxs, dst_frame->translate, dst_frame->bounds[1] );
+ VectorAdd(mins, dst_frame->translate, dst_frame->bounds[0]);
+ VectorAdd(maxs, dst_frame->translate, dst_frame->bounds[1]);
- src_frame = ( dmd2frame_t * )( ( byte * )src_frame + header.framesize );
+ src_frame = (dmd2frame_t *)((byte *)src_frame + header.framesize);
dst_frame++;
}
- Hunk_End( &model->pool );
+ Hunk_End(&model->pool);
return Q_ERR_SUCCESS;
fail:
- Hunk_Free( &model->pool );
+ Hunk_Free(&model->pool);
return ret;
}
#if USE_MD3
-qerror_t MOD_LoadMD3( model_t *model, const void *rawdata, size_t length ) {
+qerror_t MOD_LoadMD3(model_t *model, const void *rawdata, size_t length)
+{
dmd3header_t header;
uint32_t offset;
dmd3frame_t *src_frame;
@@ -238,203 +239,204 @@ qerror_t MOD_LoadMD3( model_t *model, const void *rawdata, size_t length ) {
int i, j;
qerror_t ret;
- if( length < sizeof( header ) ) {
+ if (length < sizeof(header)) {
return Q_ERR_FILE_TOO_SMALL;
}
// byte swap the header
- header = *( dmd3header_t * )rawdata;
- for( i = 0; i < sizeof( header )/4; i++ ) {
- (( uint32_t * )&header)[i] = LittleLong( (( uint32_t * )&header)[i] );
+ header = *(dmd3header_t *)rawdata;
+ for (i = 0; i < sizeof(header) / 4; i++) {
+ ((uint32_t *)&header)[i] = LittleLong(((uint32_t *)&header)[i]);
}
- if( header.ident != MD3_IDENT )
+ if (header.ident != MD3_IDENT)
return Q_ERR_UNKNOWN_FORMAT;
- if( header.version != MD3_VERSION )
+ if (header.version != MD3_VERSION)
return Q_ERR_UNKNOWN_FORMAT;
- if( header.num_frames < 1 )
+ if (header.num_frames < 1)
return Q_ERR_TOO_FEW;
- if( header.num_frames > MD3_MAX_FRAMES )
+ if (header.num_frames > MD3_MAX_FRAMES)
return Q_ERR_TOO_MANY;
- if( header.num_meshes < 1 )
+ if (header.num_meshes < 1)
return Q_ERR_TOO_FEW;
- if( header.num_meshes > MD3_MAX_MESHES )
+ if (header.num_meshes > MD3_MAX_MESHES)
return Q_ERR_TOO_MANY;
-
- Hunk_Begin( &model->pool, 0x400000 );
+
+ Hunk_Begin(&model->pool, 0x400000);
model->type = MOD_ALIAS;
model->numframes = header.num_frames;
model->nummeshes = header.num_meshes;
- model->meshes = MOD_Malloc( sizeof( maliasmesh_t ) * header.num_meshes );
- model->frames = MOD_Malloc( sizeof( maliasframe_t ) * header.num_frames );
+ model->meshes = MOD_Malloc(sizeof(maliasmesh_t) * header.num_meshes);
+ model->frames = MOD_Malloc(sizeof(maliasframe_t) * header.num_frames);
+
+ rawend = (byte *)rawdata + length;
- rawend = ( byte * )rawdata + length;
-
// load all frames
- src_frame = ( dmd3frame_t * )( ( byte * )rawdata + header.ofs_frames );
- if( ( byte * )( src_frame + header.num_frames ) > rawend ) {
+ src_frame = (dmd3frame_t *)((byte *)rawdata + header.ofs_frames);
+ if ((byte *)(src_frame + header.num_frames) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
dst_frame = model->frames;
- for( i = 0; i < header.num_frames; i++ ) {
- LittleVector( src_frame->translate, dst_frame->translate );
- VectorSet( dst_frame->scale, MD3_XYZ_SCALE, MD3_XYZ_SCALE, MD3_XYZ_SCALE );
+ for (i = 0; i < header.num_frames; i++) {
+ LittleVector(src_frame->translate, dst_frame->translate);
+ VectorSet(dst_frame->scale, MD3_XYZ_SCALE, MD3_XYZ_SCALE, MD3_XYZ_SCALE);
- LittleVector( src_frame->mins, dst_frame->bounds[0] );
- LittleVector( src_frame->maxs, dst_frame->bounds[1] );
- dst_frame->radius = LittleFloat( src_frame->radius );
+ LittleVector(src_frame->mins, dst_frame->bounds[0]);
+ LittleVector(src_frame->maxs, dst_frame->bounds[1]);
+ dst_frame->radius = LittleFloat(src_frame->radius);
src_frame++; dst_frame++;
}
// load all meshes
- src_mesh = ( dmd3mesh_t * )( ( byte * )rawdata + header.ofs_meshes );
+ src_mesh = (dmd3mesh_t *)((byte *)rawdata + header.ofs_meshes);
dst_mesh = model->meshes;
- for( i = 0; i < header.num_meshes; i++ ) {
- if( ( byte * )( src_mesh + 1 ) > rawend ) {
+ for (i = 0; i < header.num_meshes; i++) {
+ if ((byte *)(src_mesh + 1) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
- numverts = LittleLong( src_mesh->num_verts );
- if( numverts < 3 ) {
+ numverts = LittleLong(src_mesh->num_verts);
+ if (numverts < 3) {
ret = Q_ERR_TOO_FEW;
goto fail;
}
- if( numverts > TESS_MAX_VERTICES ) {
+ if (numverts > TESS_MAX_VERTICES) {
ret = Q_ERR_TOO_MANY;
goto fail;
}
- numtris = LittleLong( src_mesh->num_tris );
- if( numtris < 1 ) {
+ numtris = LittleLong(src_mesh->num_tris);
+ if (numtris < 1) {
ret = Q_ERR_TOO_FEW;
goto fail;
}
- if( numtris > TESS_MAX_INDICES / 3 ) {
+ if (numtris > TESS_MAX_INDICES / 3) {
ret = Q_ERR_TOO_MANY;
goto fail;
}
-
+
dst_mesh->numtris = numtris;
dst_mesh->numindices = numtris * 3;
dst_mesh->numverts = numverts;
- dst_mesh->verts = MOD_Malloc( sizeof( maliasvert_t ) * numverts * header.num_frames );
- dst_mesh->tcoords = MOD_Malloc( sizeof( maliastc_t ) * numverts );
- dst_mesh->indices = MOD_Malloc( sizeof( uint32_t ) * numtris * 3 );
+ dst_mesh->verts = MOD_Malloc(sizeof(maliasvert_t) * numverts * header.num_frames);
+ dst_mesh->tcoords = MOD_Malloc(sizeof(maliastc_t) * numverts);
+ dst_mesh->indices = MOD_Malloc(sizeof(uint32_t) * numtris * 3);
// load all skins
- numskins = LittleLong( src_mesh->num_skins );
- if( numskins > MAX_ALIAS_SKINS ) {
+ numskins = LittleLong(src_mesh->num_skins);
+ if (numskins > MAX_ALIAS_SKINS) {
ret = Q_ERR_TOO_MANY;
goto fail;
}
- offset = LittleLong( src_mesh->ofs_skins );
- src_skin = ( dmd3skin_t * )( ( byte * )src_mesh + offset );
- if( ( byte * )( src_skin + numskins ) > rawend ) {
+ offset = LittleLong(src_mesh->ofs_skins);
+ src_skin = (dmd3skin_t *)((byte *)src_mesh + offset);
+ if ((byte *)(src_skin + numskins) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
- for( j = 0; j < numskins; j++ ) {
- if( !Q_memccpy( skinname, src_skin->name, 0, sizeof( skinname ) ) ) {
+ for (j = 0; j < numskins; j++) {
+ if (!Q_memccpy(skinname, src_skin->name, 0, sizeof(skinname))) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
- FS_NormalizePath( skinname, skinname );
- dst_mesh->skins[j] = IMG_Find( skinname, it_skin );
+ FS_NormalizePath(skinname, skinname);
+ dst_mesh->skins[j] = IMG_Find(skinname, it_skin);
}
dst_mesh->numskins = numskins;
-
+
// load all vertices
totalVerts = numverts * header.num_frames;
- offset = LittleLong( src_mesh->ofs_verts );
- src_vert = ( dmd3vertex_t * )( ( byte * )src_mesh + offset );
- if( ( byte * )( src_vert + totalVerts ) > rawend ) {
+ offset = LittleLong(src_mesh->ofs_verts);
+ src_vert = (dmd3vertex_t *)((byte *)src_mesh + offset);
+ if ((byte *)(src_vert + totalVerts) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
dst_vert = dst_mesh->verts;
- for( j = 0; j < totalVerts; j++ ) {
- dst_vert->pos[0] = ( int16_t )LittleShort( src_vert->point[0] );
- dst_vert->pos[1] = ( int16_t )LittleShort( src_vert->point[1] );
- dst_vert->pos[2] = ( int16_t )LittleShort( src_vert->point[2] );
+ for (j = 0; j < totalVerts; j++) {
+ dst_vert->pos[0] = (int16_t)LittleShort(src_vert->point[0]);
+ dst_vert->pos[1] = (int16_t)LittleShort(src_vert->point[1]);
+ dst_vert->pos[2] = (int16_t)LittleShort(src_vert->point[2]);
dst_vert->norm[0] = src_vert->norm[0];
dst_vert->norm[1] = src_vert->norm[1];
src_vert++; dst_vert++;
}
-
+
// load all texture coords
- offset = LittleLong( src_mesh->ofs_tcs );
- src_tc = ( dmd3coord_t * )( ( byte * )src_mesh + offset );
- if( ( byte * )( src_tc + numverts ) > rawend ) {
+ offset = LittleLong(src_mesh->ofs_tcs);
+ src_tc = (dmd3coord_t *)((byte *)src_mesh + offset);
+ if ((byte *)(src_tc + numverts) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
dst_tc = dst_mesh->tcoords;
- for( j = 0; j < numverts; j++ ) {
- dst_tc->st[0] = LittleFloat( src_tc->st[0] );
- dst_tc->st[1] = LittleFloat( src_tc->st[1] );
+ for (j = 0; j < numverts; j++) {
+ dst_tc->st[0] = LittleFloat(src_tc->st[0]);
+ dst_tc->st[1] = LittleFloat(src_tc->st[1]);
src_tc++; dst_tc++;
}
// load all triangle indices
- offset = LittleLong( src_mesh->ofs_indexes );
- src_idx = ( uint32_t * )( ( byte * )src_mesh + offset );
- if( ( byte * )( src_idx + numtris * 3 ) > rawend ) {
+ offset = LittleLong(src_mesh->ofs_indexes);
+ src_idx = (uint32_t *)((byte *)src_mesh + offset);
+ if ((byte *)(src_idx + numtris * 3) > rawend) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
dst_idx = dst_mesh->indices;
- for( j = 0; j < numtris; j++ ) {
- dst_idx[0] = LittleLong( src_idx[0] );
- dst_idx[1] = LittleLong( src_idx[1] );
- dst_idx[2] = LittleLong( src_idx[2] );
- if( dst_idx[0] >= numverts || dst_idx[1] >= numverts || dst_idx[2] >= numverts ) {
+ for (j = 0; j < numtris; j++) {
+ dst_idx[0] = LittleLong(src_idx[0]);
+ dst_idx[1] = LittleLong(src_idx[1]);
+ dst_idx[2] = LittleLong(src_idx[2]);
+ if (dst_idx[0] >= numverts || dst_idx[1] >= numverts || dst_idx[2] >= numverts) {
ret = Q_ERR_BAD_INDEX;
goto fail;
}
src_idx += 3; dst_idx += 3;
}
-
- offset = LittleLong( src_mesh->meshsize );
- src_mesh = ( dmd3mesh_t * )( ( byte * )src_mesh + offset );
+
+ offset = LittleLong(src_mesh->meshsize);
+ src_mesh = (dmd3mesh_t *)((byte *)src_mesh + offset);
dst_mesh++;
}
- Hunk_End( &model->pool );
+ Hunk_End(&model->pool);
return Q_ERR_SUCCESS;
fail:
- Hunk_Free( &model->pool );
+ Hunk_Free(&model->pool);
return ret;
}
#endif
-void MOD_Reference( model_t *model ) {
+void MOD_Reference(model_t *model)
+{
int i, j;
// register any images used by the models
- switch( model->type ) {
+ switch (model->type) {
case MOD_ALIAS:
- for( i = 0; i < model->nummeshes; i++ ) {
+ for (i = 0; i < model->nummeshes; i++) {
maliasmesh_t *mesh = &model->meshes[i];
- for( j = 0; j < mesh->numskins; j++ ) {
+ for (j = 0; j < mesh->numskins; j++) {
mesh->skins[j]->registration_sequence = registration_sequence;
}
}
break;
case MOD_SPRITE:
- for( i = 0; i < model->numframes; i++ ) {
+ for (i = 0; i < model->numframes; i++) {
model->spriteframes[i].image->registration_sequence = registration_sequence;
}
break;
case MOD_EMPTY:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad model type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad model type", __func__);
}
model->registration_sequence = registration_sequence;
diff --git a/src/gl_sky.c b/src/gl_sky.c
index 4f9510d..2fbc5f2 100644
--- a/src/gl_sky.c
+++ b/src/gl_sky.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,75 +26,69 @@ static vec3_t skyaxis;
static int sky_images[6];
static const vec3_t skyclip[6] = {
- {1,1,0},
- {1,-1,0},
- {0,-1,1},
- {0,1,1},
- {1,0,1},
- {-1,0,1}
+ { 1, 1, 0 },
+ { 1, -1, 0 },
+ { 0, -1, 1 },
+ { 0, 1, 1 },
+ { 1, 0, 1 },
+ { -1, 0, 1 }
};
// 1 = s, 2 = t, 3 = 2048
static const int st_to_vec[6][3] = {
- {3,-1,2},
- {-3,1,2},
+ { 3, -1, 2 },
+ { -3, 1, 2 },
- {1,3,2},
- {-1,-3,2},
+ { 1, 3, 2 },
+ { -1, -3, 2 },
- {-2,-1,3}, // 0 degrees yaw, look straight up
- {2,-1,-3} // look straight down
+ { -2, -1, 3 }, // 0 degrees yaw, look straight up
+ { 2, -1, -3 } // look straight down
};
// s = [0]/[2], t = [1]/[2]
static const int vec_to_st[6][3] = {
- {-2,3,1},
- {2,3,-1},
+ { -2, 3, 1 },
+ { 2, 3, -1 },
- {1,3,2},
- {-1,3,-2},
+ { 1, 3, 2 },
+ { -1, 3, -2 },
- {-2,-1,3},
- {-2,1,-3}
+ { -2, -1, 3 },
+ { -2, 1, -3 }
};
static float skymins[2][6], skymaxs[2][6];
static const float sky_min = 1.0f / 512.0f;
static const float sky_max = 511.0f / 512.0f;
-static void DrawSkyPolygon (int nump, vec3_t vecs)
+static void DrawSkyPolygon(int nump, vec3_t vecs)
{
- int i,j;
+ int i, j;
vec3_t v, av;
float s, t, dv;
int axis;
float *vp;
// decide which face it maps to
- VectorCopy (vec3_origin, v);
- for (i=0, vp=vecs ; i<nump ; i++, vp+=3)
- {
- VectorAdd (vp, v, v);
+ VectorCopy(vec3_origin, v);
+ for (i = 0, vp = vecs; i < nump; i++, vp += 3) {
+ VectorAdd(vp, v, v);
}
av[0] = fabs(v[0]);
av[1] = fabs(v[1]);
av[2] = fabs(v[2]);
- if (av[0] > av[1] && av[0] > av[2])
- {
+ if (av[0] > av[1] && av[0] > av[2]) {
if (v[0] < 0)
axis = 1;
else
axis = 0;
- }
- else if (av[1] > av[2] && av[1] > av[0])
- {
+ } else if (av[1] > av[2] && av[1] > av[0]) {
if (v[1] < 0)
axis = 3;
else
axis = 2;
- }
- else
- {
+ } else {
if (v[2] < 0)
axis = 5;
else
@@ -102,8 +96,7 @@ static void DrawSkyPolygon (int nump, vec3_t vecs)
}
// project new texture coords
- for (i=0 ; i<nump ; i++, vecs+=3)
- {
+ for (i = 0; i < nump; i++, vecs += 3) {
j = vec_to_st[axis][2];
if (j > 0)
dv = vecs[j - 1];
@@ -113,14 +106,14 @@ static void DrawSkyPolygon (int nump, vec3_t vecs)
continue; // don't divide by zero
j = vec_to_st[axis][0];
if (j < 0)
- s = -vecs[-j -1] / dv;
+ s = -vecs[-j - 1] / dv;
else
- s = vecs[j-1] / dv;
+ s = vecs[j - 1] / dv;
j = vec_to_st[axis][1];
if (j < 0)
- t = -vecs[-j -1] / dv;
+ t = -vecs[-j - 1] / dv;
else
- t = vecs[j-1] / dv;
+ t = vecs[j - 1] / dv;
if (s < skymins[0][axis])
skymins[0][axis] = s;
@@ -140,7 +133,7 @@ static void DrawSkyPolygon (int nump, vec3_t vecs)
#define SIDE_BACK 1
#define SIDE_ON 2
-static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
+static void ClipSkyPolygon(int nump, vec3_t vecs, int stage)
{
const float *norm;
float *v;
@@ -152,73 +145,65 @@ static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
int newc[2];
int i, j;
- if (nump > MAX_CLIP_VERTS-2)
- Com_Error( ERR_DROP, "ClipSkyPolygon: MAX_CLIP_VERTS");
- if (stage == 6)
- { // fully clipped, so draw it
- DrawSkyPolygon (nump, vecs);
+ if (nump > MAX_CLIP_VERTS - 2)
+ Com_Error(ERR_DROP, "ClipSkyPolygon: MAX_CLIP_VERTS");
+ if (stage == 6) {
+ // fully clipped, so draw it
+ DrawSkyPolygon(nump, vecs);
return;
}
front = back = qfalse;
norm = skyclip[stage];
- for (i=0, v = vecs ; i<nump ; i++, v+=3)
- {
- d = DotProduct (v, norm);
- if (d > ON_EPSILON)
- {
+ for (i = 0, v = vecs; i < nump; i++, v += 3) {
+ d = DotProduct(v, norm);
+ if (d > ON_EPSILON) {
front = qtrue;
sides[i] = SIDE_FRONT;
- }
- else if (d < -ON_EPSILON)
- {
+ } else if (d < -ON_EPSILON) {
back = qtrue;
sides[i] = SIDE_BACK;
- }
- else
+ } else
sides[i] = SIDE_ON;
dists[i] = d;
}
- if (!front || !back)
- { // not clipped
- ClipSkyPolygon (nump, vecs, stage+1);
+ if (!front || !back) {
+ // not clipped
+ ClipSkyPolygon(nump, vecs, stage + 1);
return;
}
// clip it
sides[i] = sides[0];
dists[i] = dists[0];
- VectorCopy (vecs, (vecs+(i*3)) );
+ VectorCopy(vecs, (vecs + (i * 3)));
newc[0] = newc[1] = 0;
- for (i=0, v = vecs ; i<nump ; i++, v+=3)
- {
- switch (sides[i])
- {
+ for (i = 0, v = vecs; i < nump; i++, v += 3) {
+ switch (sides[i]) {
case SIDE_FRONT:
- VectorCopy (v, newv[0][newc[0]]);
+ VectorCopy(v, newv[0][newc[0]]);
newc[0]++;
break;
case SIDE_BACK:
- VectorCopy (v, newv[1][newc[1]]);
+ VectorCopy(v, newv[1][newc[1]]);
newc[1]++;
break;
case SIDE_ON:
- VectorCopy (v, newv[0][newc[0]]);
+ VectorCopy(v, newv[0][newc[0]]);
newc[0]++;
- VectorCopy (v, newv[1][newc[1]]);
+ VectorCopy(v, newv[1][newc[1]]);
newc[1]++;
break;
}
- if (sides[i] == SIDE_ON || sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
+ if (sides[i] == SIDE_ON || sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i])
continue;
- d = dists[i] / (dists[i] - dists[i+1]);
- for (j=0 ; j<3 ; j++)
- {
- e = v[j] + d*(v[j+3] - v[j]);
+ d = dists[i] / (dists[i] - dists[i + 1]);
+ for (j = 0; j < 3; j++) {
+ e = v[j] + d * (v[j + 3] - v[j]);
newv[0][newc[0]][j] = e;
newv[1][newc[1]][j] = e;
}
@@ -227,8 +212,8 @@ static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
}
// continue
- ClipSkyPolygon (newc[0], newv[0][0], stage+1);
- ClipSkyPolygon (newc[1], newv[1][0], stage+1);
+ ClipSkyPolygon(newc[0], newv[0][0], stage + 1);
+ ClipSkyPolygon(newc[1], newv[1][0], stage + 1);
}
/*
@@ -236,25 +221,26 @@ static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
R_AddSkySurface
=================
*/
-void R_AddSkySurface( mface_t *fa ) {
+void R_AddSkySurface(mface_t *fa)
+{
int i;
vec3_t verts[MAX_CLIP_VERTS];
msurfedge_t *surfedge;
mvertex_t *vert;
medge_t *edge;
- if( fa->numsurfedges > MAX_CLIP_VERTS ) {
- Com_Error( ERR_DROP, "%s: too many verts", __func__ );
+ if (fa->numsurfedges > MAX_CLIP_VERTS) {
+ Com_Error(ERR_DROP, "%s: too many verts", __func__);
}
// calculate vertex values for sky box
surfedge = fa->firstsurfedge;
- for( i = 0; i < fa->numsurfedges; i++, surfedge++ ) {
+ for (i = 0; i < fa->numsurfedges; i++, surfedge++) {
edge = surfedge->edge;
vert = edge->v[surfedge->vert];
- VectorSubtract (vert->point, glr.fd.vieworg, verts[i]);
+ VectorSubtract(vert->point, glr.fd.vieworg, verts[i]);
}
- ClipSkyPolygon (fa->numsurfedges, verts[0], 0);
+ ClipSkyPolygon(fa->numsurfedges, verts[0], 0);
}
@@ -263,28 +249,27 @@ void R_AddSkySurface( mface_t *fa ) {
R_ClearSkyBox
==============
*/
-void R_ClearSkyBox( void ) {
+void R_ClearSkyBox(void)
+{
int i;
- for (i=0 ; i<6 ; i++)
- {
+ for (i = 0; i < 6; i++) {
skymins[0][i] = skymins[1][i] = 9999;
skymaxs[0][i] = skymaxs[1][i] = -9999;
}
}
-static void MakeSkyVec (float s, float t, int axis, vec_t *v)
+static void MakeSkyVec(float s, float t, int axis, vec_t *v)
{
vec3_t b;
int j, k;
- b[0] = s*4800;//2300;
- b[1] = t*4800;//2300;
- b[2] = 4800;//2300;
+ b[0] = s * 4800; //2300;
+ b[1] = t * 4800; //2300;
+ b[2] = 4800; //2300;
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
k = st_to_vec[axis][j];
if (k < 0)
v[j] = -b[-k - 1];
@@ -293,8 +278,8 @@ static void MakeSkyVec (float s, float t, int axis, vec_t *v)
}
// avoid bilerp seam
- s = (s+1)*0.5;
- t = (t+1)*0.5;
+ s = (s + 1) * 0.5;
+ t = (t + 1) * 0.5;
if (s < sky_min)
s = sky_min;
@@ -309,23 +294,24 @@ static void MakeSkyVec (float s, float t, int axis, vec_t *v)
v[4] = 1.0 - t;
}
-#define SKY_VISIBLE( side ) \
- ( skymins[0][side] < skymaxs[0][side] && \
- skymins[1][side] < skymaxs[1][side] )
+#define SKY_VISIBLE(side) \
+ (skymins[0][side] < skymaxs[0][side] && \
+ skymins[1][side] < skymaxs[1][side])
/*
==============
R_DrawSkyBox
==============
*/
-void R_DrawSkyBox( void ) {
- static const int skytexorder[6] = {0,2,1,3,4,5};
+void R_DrawSkyBox(void)
+{
+ static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
vec5_t verts[4];
int i;
- if( skyrotate ) {
+ if (skyrotate) {
// hack, forces full sky to draw when rotating
- for( i = 0; i < 6; i++ ) {
+ for (i = 0; i < 6; i++) {
skymins[0][i] = -1;
skymins[1][i] = -1;
skymaxs[0][i] = 1;
@@ -333,50 +319,51 @@ void R_DrawSkyBox( void ) {
}
} else {
// check for no sky at all
- for( i = 0; i < 6; i++ ) {
- if( SKY_VISIBLE( i ) ) {
+ for (i = 0; i < 6; i++) {
+ if (SKY_VISIBLE(i)) {
break;
}
}
- if( i == 6 ) {
+ if (i == 6) {
return; // nothing visible
}
}
- qglPushMatrix ();
- qglTranslatef (glr.fd.vieworg[0], glr.fd.vieworg[1], glr.fd.vieworg[2]);
- if( skyrotate ) {
- qglRotatef (glr.fd.time * skyrotate, skyaxis[0], skyaxis[1], skyaxis[2]);
+ qglPushMatrix();
+ qglTranslatef(glr.fd.vieworg[0], glr.fd.vieworg[1], glr.fd.vieworg[2]);
+ if (skyrotate) {
+ qglRotatef(glr.fd.time * skyrotate, skyaxis[0], skyaxis[1], skyaxis[2]);
}
- GL_TexEnv( GL_REPLACE );
- GL_Bits( GLS_DEFAULT );
+ GL_TexEnv(GL_REPLACE);
+ GL_Bits(GLS_DEFAULT);
- qglVertexPointer( 3, GL_FLOAT, 5*4, &verts[0][0] );
- qglTexCoordPointer( 2, GL_FLOAT, 5*4, &verts[0][3] );
+ qglVertexPointer(3, GL_FLOAT, 5 * 4, &verts[0][0]);
+ qglTexCoordPointer(2, GL_FLOAT, 5 * 4, &verts[0][3]);
- for( i = 0; i < 6; i++ ) {
- if( !SKY_VISIBLE( i ) ) {
+ for (i = 0; i < 6; i++) {
+ if (!SKY_VISIBLE(i)) {
continue;
}
- GL_BindTexture (sky_images[skytexorder[i]]);
+ GL_BindTexture(sky_images[skytexorder[i]]);
- MakeSkyVec (skymaxs[0][i], skymins[1][i], i, verts[0]);
- MakeSkyVec (skymins[0][i], skymins[1][i], i, verts[1]);
- MakeSkyVec (skymaxs[0][i], skymaxs[1][i], i, verts[2]);
- MakeSkyVec (skymins[0][i], skymaxs[1][i], i, verts[3]);
- qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
+ MakeSkyVec(skymaxs[0][i], skymins[1][i], i, verts[0]);
+ MakeSkyVec(skymins[0][i], skymins[1][i], i, verts[1]);
+ MakeSkyVec(skymaxs[0][i], skymaxs[1][i], i, verts[2]);
+ MakeSkyVec(skymins[0][i], skymaxs[1][i], i, verts[3]);
+ qglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
- qglPopMatrix ();
+ qglPopMatrix();
}
-static void R_UnsetSky( void ) {
+static void R_UnsetSky(void)
+{
int i;
skyrotate = 0;
- for( i = 0; i < 6; i++ ) {
+ for (i = 0; i < 6; i++) {
sky_images[i] = TEXNUM_BLACK;
}
}
@@ -386,7 +373,8 @@ static void R_UnsetSky( void ) {
R_SetSky
============
*/
-void R_SetSky( const char *name, float rotate, vec3_t axis ) {
+void R_SetSky(const char *name, float rotate, vec3_t axis)
+{
int i;
char pathname[MAX_QPATH];
image_t *image;
@@ -394,24 +382,24 @@ void R_SetSky( const char *name, float rotate, vec3_t axis ) {
// 3dstudio environment map names
static const char suf[6][3] = { "rt", "bk", "lf", "ft", "up", "dn" };
- if( !gl_drawsky->integer ) {
+ if (!gl_drawsky->integer) {
R_UnsetSky();
return;
}
skyrotate = rotate;
- VectorCopy (axis, skyaxis);
+ VectorCopy(axis, skyaxis);
- for( i = 0; i < 6; i++ ) {
- len = Q_concat( pathname, sizeof( pathname ),
- "env/", name, suf[i], ".tga", NULL );
- if( len >= sizeof( pathname ) ) {
+ for (i = 0; i < 6; i++) {
+ len = Q_concat(pathname, sizeof(pathname),
+ "env/", name, suf[i], ".tga", NULL);
+ if (len >= sizeof(pathname)) {
R_UnsetSky();
return;
}
- FS_NormalizePath( pathname, pathname );
- image = IMG_Find( pathname, it_sky );
- if( image->texnum == TEXNUM_DEFAULT ) {
+ FS_NormalizePath(pathname, pathname);
+ image = IMG_Find(pathname, it_sky);
+ if (image->texnum == TEXNUM_DEFAULT) {
R_UnsetSky();
return;
}
diff --git a/src/gl_state.c b/src/gl_state.c
index 353fc98..b6a3151 100644
--- a/src/gl_state.c
+++ b/src/gl_state.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,225 +23,234 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
glState_t gls;
-void GL_BindTexture( int texnum ) {
+void GL_BindTexture(int texnum)
+{
#ifdef _DEBUG
- if( gl_nobind->integer && !gls.tmu ) {
+ if (gl_nobind->integer && !gls.tmu) {
texnum = TEXNUM_DEFAULT;
}
#endif
- if( gls.texnum[gls.tmu] == texnum ) {
+ if (gls.texnum[gls.tmu] == texnum) {
return;
}
- qglBindTexture( GL_TEXTURE_2D, texnum );
+ qglBindTexture(GL_TEXTURE_2D, texnum);
gls.texnum[gls.tmu] = texnum;
c.texSwitches++;
}
-void GL_SelectTMU( int tmu ) {
- if( gls.tmu == tmu ) {
+void GL_SelectTMU(int tmu)
+{
+ if (gls.tmu == tmu) {
return;
}
- if( tmu < 0 || tmu >= gl_config.numTextureUnits ) {
- Com_Error( ERR_FATAL, "GL_SelectTMU: bad tmu %d", tmu );
+ if (tmu < 0 || tmu >= gl_config.numTextureUnits) {
+ Com_Error(ERR_FATAL, "GL_SelectTMU: bad tmu %d", tmu);
}
- qglActiveTextureARB( GL_TEXTURE0_ARB + tmu );
- qglClientActiveTextureARB( GL_TEXTURE0_ARB + tmu );
+ qglActiveTextureARB(GL_TEXTURE0_ARB + tmu);
+ qglClientActiveTextureARB(GL_TEXTURE0_ARB + tmu);
gls.tmu = tmu;
}
-void GL_TexEnv( GLenum texenv ) {
- if( gls.texenv[gls.tmu] == texenv ) {
+void GL_TexEnv(GLenum texenv)
+{
+ if (gls.texenv[gls.tmu] == texenv) {
return;
}
- switch( texenv ) {
+ switch (texenv) {
case GL_REPLACE:
case GL_MODULATE:
case GL_BLEND:
case GL_ADD:
- qglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texenv );
+ qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texenv);
break;
default:
- Com_Error( ERR_FATAL, "GL_TexEnv: bad texenv" );
+ Com_Error(ERR_FATAL, "GL_TexEnv: bad texenv");
break;
}
gls.texenv[gls.tmu] = texenv;
}
-void GL_CullFace( glCullFace_t cull ) {
- if( gls.cull == cull ) {
+void GL_CullFace(glCullFace_t cull)
+{
+ if (gls.cull == cull) {
return;
}
- switch( cull ) {
+ switch (cull) {
case GLS_CULL_DISABLE:
- qglDisable( GL_CULL_FACE );
+ qglDisable(GL_CULL_FACE);
break;
case GLS_CULL_FRONT:
- qglEnable( GL_CULL_FACE );
- qglCullFace( GL_FRONT );
+ qglEnable(GL_CULL_FACE);
+ qglCullFace(GL_FRONT);
break;
case GLS_CULL_BACK:
- qglEnable( GL_CULL_FACE );
- qglCullFace( GL_BACK );
+ qglEnable(GL_CULL_FACE);
+ qglCullFace(GL_BACK);
break;
default:
- Com_Error( ERR_FATAL, "GL_CullFace: bad cull" );
+ Com_Error(ERR_FATAL, "GL_CullFace: bad cull");
break;
}
gls.cull = cull;
}
-void GL_Bits( glStateBits_t bits ) {
+void GL_Bits(glStateBits_t bits)
+{
glStateBits_t diff = bits ^ gls.bits;
- if( !diff ) {
+ if (!diff) {
return;
}
- if( diff & GLS_BLEND_MASK ) {
- if( bits & GLS_BLEND_MASK ) {
- qglEnable( GL_BLEND );
- if( bits & GLS_BLEND_BLEND ) {
- qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- } else if( bits & GLS_BLEND_ADD ) {
- qglBlendFunc( GL_SRC_ALPHA, GL_ONE );
- } else if( bits & GLS_BLEND_MODULATE ) {
- qglBlendFunc( GL_DST_COLOR, GL_ONE );
+ if (diff & GLS_BLEND_MASK) {
+ if (bits & GLS_BLEND_MASK) {
+ qglEnable(GL_BLEND);
+ if (bits & GLS_BLEND_BLEND) {
+ qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ } else if (bits & GLS_BLEND_ADD) {
+ qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } else if (bits & GLS_BLEND_MODULATE) {
+ qglBlendFunc(GL_DST_COLOR, GL_ONE);
}
} else {
- qglDisable( GL_BLEND );
+ qglDisable(GL_BLEND);
}
}
-
- if( diff & GLS_DEPTHMASK_FALSE ) {
- if( bits & GLS_DEPTHMASK_FALSE ) {
- qglDepthMask( GL_FALSE );
+
+ if (diff & GLS_DEPTHMASK_FALSE) {
+ if (bits & GLS_DEPTHMASK_FALSE) {
+ qglDepthMask(GL_FALSE);
} else {
- qglDepthMask( GL_TRUE );
+ qglDepthMask(GL_TRUE);
}
}
-
- if( diff & GLS_DEPTHTEST_DISABLE ) {
- if( bits & GLS_DEPTHTEST_DISABLE ) {
- qglDisable( GL_DEPTH_TEST );
+
+ if (diff & GLS_DEPTHTEST_DISABLE) {
+ if (bits & GLS_DEPTHTEST_DISABLE) {
+ qglDisable(GL_DEPTH_TEST);
} else {
- qglEnable( GL_DEPTH_TEST );
+ qglEnable(GL_DEPTH_TEST);
}
}
- if( diff & GLS_ALPHATEST_ENABLE ) {
- if( bits & GLS_ALPHATEST_ENABLE ) {
- qglEnable( GL_ALPHA_TEST );
+ if (diff & GLS_ALPHATEST_ENABLE) {
+ if (bits & GLS_ALPHATEST_ENABLE) {
+ qglEnable(GL_ALPHA_TEST);
} else {
- qglDisable( GL_ALPHA_TEST );
+ qglDisable(GL_ALPHA_TEST);
}
}
-
+
gls.bits = bits;
}
-void GL_Setup2D( void ) {
- qglViewport( 0, 0, r_config.width, r_config.height );
+void GL_Setup2D(void)
+{
+ qglViewport(0, 0, r_config.width, r_config.height);
- qglMatrixMode( GL_PROJECTION );
+ qglMatrixMode(GL_PROJECTION);
qglLoadIdentity();
- qglOrtho( 0, r_config.width, r_config.height, 0, -1, 1 );
+ qglOrtho(0, r_config.width, r_config.height, 0, -1, 1);
draw.scale = 1;
draw.colors[0].u32 = U32_WHITE;
draw.colors[1].u32 = U32_WHITE;
- if( draw.flags & DRAW_CLIP_MASK ) {
- qglDisable( GL_SCISSOR_TEST );
+ if (draw.flags & DRAW_CLIP_MASK) {
+ qglDisable(GL_SCISSOR_TEST);
}
draw.flags = 0;
- qglMatrixMode( GL_MODELVIEW );
+ qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity();
- GL_Bits( GLS_DEPTHTEST_DISABLE );
- GL_CullFace( GLS_CULL_DISABLE );
+ GL_Bits(GLS_DEPTHTEST_DISABLE);
+ GL_CullFace(GLS_CULL_DISABLE);
}
-void GL_Setup3D( void ) {
+void GL_Setup3D(void)
+{
GLdouble xmin, xmax, ymin, ymax;
int yb = glr.fd.y + glr.fd.height;
- qglViewport( glr.fd.x, r_config.height - yb,
- glr.fd.width, glr.fd.height );
+ qglViewport(glr.fd.x, r_config.height - yb,
+ glr.fd.width, glr.fd.height);
- qglMatrixMode( GL_PROJECTION );
+ qglMatrixMode(GL_PROJECTION);
qglLoadIdentity();
- ymax = gl_znear->value * tan( glr.fd.fov_y * M_PI / 360.0 );
+ ymax = gl_znear->value * tan(glr.fd.fov_y * M_PI / 360.0);
ymin = -ymax;
- xmax = gl_znear->value * tan( glr.fd.fov_x * M_PI / 360.0 );
+ xmax = gl_znear->value * tan(glr.fd.fov_x * M_PI / 360.0);
xmin = -xmax;
- qglFrustum( xmin, xmax, ymin, ymax, gl_znear->value, gl_zfar->value );
-
- qglMatrixMode( GL_MODELVIEW );
+ qglFrustum(xmin, xmax, ymin, ymax, gl_znear->value, gl_zfar->value);
+
+ qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity();
- qglRotatef( -90, 1, 0, 0 ); /* put z axis up */
- qglRotatef( 90, 0, 0, 1 ); /* put y axis west, x axis north */
- qglRotatef( -glr.fd.viewangles[ROLL], 1, 0, 0 );
- qglRotatef( -glr.fd.viewangles[PITCH], 0, 1, 0 );
- qglRotatef( -glr.fd.viewangles[YAW], 0, 0, 1 );
- qglTranslatef( -glr.fd.vieworg[0], -glr.fd.vieworg[1], -glr.fd.vieworg[2] );
+ qglRotatef(-90, 1, 0, 0); /* put z axis up */
+ qglRotatef(90, 0, 0, 1); /* put y axis west, x axis north */
+ qglRotatef(-glr.fd.viewangles[ROLL], 1, 0, 0);
+ qglRotatef(-glr.fd.viewangles[PITCH], 0, 1, 0);
+ qglRotatef(-glr.fd.viewangles[YAW], 0, 0, 1);
+ qglTranslatef(-glr.fd.vieworg[0], -glr.fd.vieworg[1], -glr.fd.vieworg[2]);
- AngleVectors( glr.fd.viewangles,
- glr.viewaxis[0], glr.viewaxis[1], glr.viewaxis[2] );
- VectorInverse( glr.viewaxis[1] );
+ AngleVectors(glr.fd.viewangles,
+ glr.viewaxis[0], glr.viewaxis[1], glr.viewaxis[2]);
+ VectorInverse(glr.viewaxis[1]);
- GL_Bits( GLS_DEFAULT );
- GL_CullFace( GLS_CULL_FRONT );
+ GL_Bits(GLS_DEFAULT);
+ GL_CullFace(GLS_CULL_FRONT);
- qglClear( GL_DEPTH_BUFFER_BIT );
+ qglClear(GL_DEPTH_BUFFER_BIT);
}
-void GL_SetDefaultState( void ) {
- qglClearColor( 0, 0, 0, 1 );
- qglClearDepth( 1 );
- qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- qglEnable( GL_DEPTH_TEST );
- qglDepthFunc( GL_LEQUAL );
- qglDepthRange( 0, 1 );
- qglDepthMask( GL_TRUE );
- qglDisable( GL_BLEND );
- qglDisable( GL_ALPHA_TEST );
- qglAlphaFunc( GL_GREATER, 0.666f );
- qglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
- qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- qglEnableClientState( GL_VERTEX_ARRAY );
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
-
- GL_SelectTMU( 0 );
- GL_BindTexture( 0 );
- qglEnable( GL_TEXTURE_2D );
- GL_Bits( GLS_DEFAULT );
+void GL_SetDefaultState(void)
+{
+ qglClearColor(0, 0, 0, 1);
+ qglClearDepth(1);
+ qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ qglEnable(GL_DEPTH_TEST);
+ qglDepthFunc(GL_LEQUAL);
+ qglDepthRange(0, 1);
+ qglDepthMask(GL_TRUE);
+ qglDisable(GL_BLEND);
+ qglDisable(GL_ALPHA_TEST);
+ qglAlphaFunc(GL_GREATER, 0.666f);
+ qglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
+ qglEnableClientState(GL_VERTEX_ARRAY);
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ GL_SelectTMU(0);
+ GL_BindTexture(0);
+ qglEnable(GL_TEXTURE_2D);
+ GL_Bits(GLS_DEFAULT);
}
// for screenshots
-byte *IMG_ReadPixels( qboolean reverse, int *width, int *height ) {
+byte *IMG_ReadPixels(qboolean reverse, int *width, int *height)
+{
byte *pixels;
- pixels = FS_AllocTempMem( r_config.width * r_config.height * 3 );
+ pixels = FS_AllocTempMem(r_config.width * r_config.height * 3);
- qglReadPixels( 0, 0, r_config.width, r_config.height,
- reverse ? GL_BGR : GL_RGB, GL_UNSIGNED_BYTE, pixels );
+ qglReadPixels(0, 0, r_config.width, r_config.height,
+ reverse ? GL_BGR : GL_RGB, GL_UNSIGNED_BYTE, pixels);
*width = r_config.width;
*height = r_config.height;
@@ -249,92 +258,98 @@ byte *IMG_ReadPixels( qboolean reverse, int *width, int *height ) {
return pixels;
}
-void GL_EnableOutlines( void ) {
- if( gls.fp_enabled ) {
- qglDisable( GL_FRAGMENT_PROGRAM_ARB );
+void GL_EnableOutlines(void)
+{
+ if (gls.fp_enabled) {
+ qglDisable(GL_FRAGMENT_PROGRAM_ARB);
}
- qglDisable( GL_TEXTURE_2D );
- qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
- qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- qglDepthRange( 0, 0 );
- qglColor4f( 1, 1, 1, 1 );
+ qglDisable(GL_TEXTURE_2D);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ qglDepthRange(0, 0);
+ qglColor4f(1, 1, 1, 1);
}
-void GL_DisableOutlines( void ) {
- qglDepthRange( 0, 1 );
- qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
- qglEnable( GL_TEXTURE_2D );
- if( gls.fp_enabled ) {
- qglEnable( GL_FRAGMENT_PROGRAM_ARB );
+void GL_DisableOutlines(void)
+{
+ qglDepthRange(0, 1);
+ qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglEnable(GL_TEXTURE_2D);
+ if (gls.fp_enabled) {
+ qglEnable(GL_FRAGMENT_PROGRAM_ARB);
}
}
-void GL_EnableWarp( void ) {
+void GL_EnableWarp(void)
+{
vec4_t param;
- qglEnable( GL_FRAGMENT_PROGRAM_ARB );
- qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, gl_static.prognum_warp );
+ qglEnable(GL_FRAGMENT_PROGRAM_ARB);
+ qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, gl_static.prognum_warp);
param[0] = glr.fd.time;
param[1] = glr.fd.time;
param[2] = param[3] = 0;
- qglProgramLocalParameter4fvARB( GL_FRAGMENT_PROGRAM_ARB, 0, param );
+ qglProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, param);
gls.fp_enabled = qtrue;
}
-void GL_DisableWarp( void ) {
- qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, 0 );
- qglDisable( GL_FRAGMENT_PROGRAM_ARB );
+void GL_DisableWarp(void)
+{
+ qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
+ qglDisable(GL_FRAGMENT_PROGRAM_ARB);
gls.fp_enabled = qfalse;
}
-void GL_InitPrograms( void ) {
+void GL_InitPrograms(void)
+{
GLuint prog;
- if( gl_config.ext_supported & QGL_ARB_fragment_program ) {
- if( gl_fragment_program->integer ) {
- Com_Printf( "...enabling GL_ARB_fragment_program\n" );
- QGL_InitExtensions( QGL_ARB_fragment_program );
+ if (gl_config.ext_supported & QGL_ARB_fragment_program) {
+ if (gl_fragment_program->integer) {
+ Com_Printf("...enabling GL_ARB_fragment_program\n");
+ QGL_InitExtensions(QGL_ARB_fragment_program);
gl_config.ext_enabled |= QGL_ARB_fragment_program;
} else {
- Com_Printf( "...ignoring GL_ARB_fragment_program\n" );
+ Com_Printf("...ignoring GL_ARB_fragment_program\n");
}
- } else if( gl_fragment_program->integer ) {
- Com_Printf( "GL_ARB_fragment_program not found\n" );
- Cvar_Set( "gl_fragment_program", "0" );
+ } else if (gl_fragment_program->integer) {
+ Com_Printf("GL_ARB_fragment_program not found\n");
+ Cvar_Set("gl_fragment_program", "0");
}
- if( !qglProgramStringARB ) {
+ if (!qglProgramStringARB) {
return;
}
GL_ClearErrors();
- qglGenProgramsARB( 1, &prog );
- qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, prog );
- qglProgramStringARB( GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
- sizeof( gl_prog_warp ) - 1, gl_prog_warp );
-
- if( GL_ShowErrors( "Failed to initialize fragment program" ) ) {
- qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, 0 );
- qglDeleteProgramsARB( 1, &prog );
+ qglGenProgramsARB(1, &prog);
+ qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
+ qglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ sizeof(gl_prog_warp) - 1, gl_prog_warp);
+
+ if (GL_ShowErrors("Failed to initialize fragment program")) {
+ qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
+ qglDeleteProgramsARB(1, &prog);
return;
}
- qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, 0 );
+ qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
gl_static.prognum_warp = prog;
}
-void GL_ShutdownPrograms( void ) {
- if( !qglDeleteProgramsARB ) {
+void GL_ShutdownPrograms(void)
+{
+ if (!qglDeleteProgramsARB) {
return;
}
- if( gl_static.prognum_warp ) {
- qglDeleteProgramsARB( 1, &gl_static.prognum_warp );
+ if (gl_static.prognum_warp) {
+ qglDeleteProgramsARB(1, &gl_static.prognum_warp);
gl_static.prognum_warp = 0;
}
- QGL_ShutdownExtensions( QGL_ARB_fragment_program );
+ QGL_ShutdownExtensions(QGL_ARB_fragment_program);
gl_config.ext_enabled &= ~QGL_ARB_fragment_program;
}
diff --git a/src/gl_surf.c b/src/gl_surf.c
index bbc7a8a..aa9bd83 100644
--- a/src/gl_surf.c
+++ b/src/gl_surf.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/*
* gl_surf.c -- surface post-processing code
- *
+ *
*/
#include "gl_local.h"
@@ -35,31 +35,32 @@ LIGHTMAP COLOR ADJUSTING
*/
static inline void
-adjust_color_f( vec_t *out, const vec_t *in, float modulate ) {
+adjust_color_f(vec_t *out, const vec_t *in, float modulate)
+{
float r, g, b, y, max;
// add & modulate
- r = ( in[0] + gl_static.world.add ) * modulate;
- g = ( in[1] + gl_static.world.add ) * modulate;
- b = ( in[2] + gl_static.world.add ) * modulate;
+ r = (in[0] + gl_static.world.add) * modulate;
+ g = (in[1] + gl_static.world.add) * modulate;
+ b = (in[2] + gl_static.world.add) * modulate;
// catch negative lights
- if( r < 0 ) r = 0;
- if( g < 0 ) g = 0;
- if( b < 0 ) b = 0;
+ if (r < 0) r = 0;
+ if (g < 0) g = 0;
+ if (b < 0) b = 0;
// determine the brightest of the three color components
max = g;
- if( r > max ) {
+ if (r > max) {
max = r;
}
- if( b > max ) {
+ if (b > max) {
max = b;
}
// rescale all the color components if the intensity of the greatest
// channel exceeds 1.0
- if( max > 255 ) {
+ if (max > 255) {
y = 255.0f / max;
r *= y;
g *= y;
@@ -68,11 +69,11 @@ adjust_color_f( vec_t *out, const vec_t *in, float modulate ) {
// transform to grayscale by replacing color components with
// overall pixel luminance computed from weighted color sum
- if( gl_static.world.scale != 1 ) {
- y = LUMINANCE( r, g, b );
- r = y + ( r - y ) * gl_static.world.scale;
- g = y + ( g - y ) * gl_static.world.scale;
- b = y + ( b - y ) * gl_static.world.scale;
+ if (gl_static.world.scale != 1) {
+ y = LUMINANCE(r, g, b);
+ r = y + (r - y) * gl_static.world.scale;
+ g = y + (g - y) * gl_static.world.scale;
+ b = y + (b - y) * gl_static.world.scale;
}
out[0] = r;
@@ -81,19 +82,21 @@ adjust_color_f( vec_t *out, const vec_t *in, float modulate ) {
}
static inline void
-adjust_color_ub( byte *out, const vec_t *in ) {
+adjust_color_ub(byte *out, const vec_t *in)
+{
vec3_t tmp;
- adjust_color_f( tmp, in, gl_static.world.modulate );
- out[0] = ( byte )tmp[0];
- out[1] = ( byte )tmp[1];
- out[2] = ( byte )tmp[2];
+ adjust_color_f(tmp, in, gl_static.world.modulate);
+ out[0] = (byte)tmp[0];
+ out[1] = (byte)tmp[1];
+ out[2] = (byte)tmp[2];
out[3] = 255;
}
-void GL_AdjustColor( vec3_t color ) {
- adjust_color_f( color, color, gl_static.entity_modulate );
- VectorScale( color, (1.0f/255), color );
+void GL_AdjustColor(vec3_t color)
+{
+ adjust_color_f(color, color, gl_static.entity_modulate);
+ VectorScale(color, (1.0f / 255), color);
}
/*
@@ -107,10 +110,11 @@ DYNAMIC BLOCKLIGHTS
// max 512 extents plus borders
#define MAX_BLOCKLIGHTS (34*34)
-static float blocklights[MAX_BLOCKLIGHTS*3];
+static float blocklights[MAX_BLOCKLIGHTS * 3];
#if USE_DLIGHTS
-static void add_dynamic_lights( mface_t *surf ) {
+static void add_dynamic_lights(mface_t *surf)
+{
dlight_t *light;
mtexinfo_t *texinfo;
cplane_t *plane;
@@ -121,47 +125,47 @@ static void add_dynamic_lights( mface_t *surf ) {
int smax, tmax, s, t, sd, td;
int i, j, k;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
k = !!gl_dlight_falloff->integer;
scale = 1 + 0.1f * k;
- for( i = 0; i < glr.fd.num_dlights; i++ ) {
- if( !( surf->dlightbits & ( 1 << i ) ) ) {
+ for (i = 0; i < glr.fd.num_dlights; i++) {
+ if (!(surf->dlightbits & (1 << i))) {
continue;
}
light = &glr.fd.dlights[i];
plane = surf->plane;
- dist = PlaneDiffFast( light->transformed, plane );
- radius = light->intensity * scale - fabs( dist );
- if( radius < DLIGHT_CUTOFF ) {
+ dist = PlaneDiffFast(light->transformed, plane);
+ radius = light->intensity * scale - fabs(dist);
+ if (radius < DLIGHT_CUTOFF) {
continue;
}
- VectorMA( light->transformed, -dist, plane->normal, point );
+ VectorMA(light->transformed, -dist, plane->normal, point);
texinfo = surf->texinfo;
- local[0] = DotProduct( point, texinfo->axis[0] ) + texinfo->offset[0];
- local[1] = DotProduct( point, texinfo->axis[1] ) + texinfo->offset[1];
+ local[0] = DotProduct(point, texinfo->axis[0]) + texinfo->offset[0];
+ local[1] = DotProduct(point, texinfo->axis[1]) + texinfo->offset[1];
local[0] -= surf->texturemins[0];
local[1] -= surf->texturemins[1];
bl = blocklights;
- for( t = 0; t < tmax; t++ ) {
- td = abs( local[1] - ( t << 4 ) );
- for( s = 0; s < smax; s++ ) {
- sd = abs( local[0] - ( s << 4 ) );
- if( sd > td ) {
- j = sd + ( td >> 1 );
+ for (t = 0; t < tmax; t++) {
+ td = abs(local[1] - (t << 4));
+ for (s = 0; s < smax; s++) {
+ sd = abs(local[0] - (s << 4));
+ if (sd > td) {
+ j = sd + (td >> 1);
} else {
- j = td + ( sd >> 1 );
+ j = td + (sd >> 1);
}
- if( j + DLIGHT_CUTOFF < radius ) {
- f = radius - ( j + DLIGHT_CUTOFF * k );
+ if (j + DLIGHT_CUTOFF < radius) {
+ f = radius - (j + DLIGHT_CUTOFF * k);
bl[0] += light->color[0] * f;
bl[1] += light->color[1] * f;
bl[2] += light->color[2] * f;
@@ -174,25 +178,26 @@ static void add_dynamic_lights( mface_t *surf ) {
}
#endif
-static void add_light_styles( mface_t *surf, int size ) {
+static void add_light_styles(mface_t *surf, int size)
+{
lightstyle_t *style;
byte *src;
float *bl;
int i, j;
- if( !surf->numstyles ) {
+ if (!surf->numstyles) {
// should this ever happen?
- memset( blocklights, 0, sizeof( blocklights[0] ) * size * 3 );
+ memset(blocklights, 0, sizeof(blocklights[0]) * size * 3);
return;
}
// init primary lightmap
- style = LIGHT_STYLE( surf, 0 );
+ style = LIGHT_STYLE(surf, 0);
src = surf->lightmap;
bl = blocklights;
- if( style->white == 1 ) {
- for( j = 0; j < size; j++ ) {
+ if (style->white == 1) {
+ for (j = 0; j < size; j++) {
bl[0] = src[0];
bl[1] = src[1];
bl[2] = src[2];
@@ -200,7 +205,7 @@ static void add_light_styles( mface_t *surf, int size ) {
bl += 3; src += 3;
}
} else {
- for( j = 0; j < size; j++ ) {
+ for (j = 0; j < size; j++) {
bl[0] = src[0] * style->rgb[0];
bl[1] = src[1] * style->rgb[1];
bl[2] = src[2] * style->rgb[2];
@@ -212,11 +217,11 @@ static void add_light_styles( mface_t *surf, int size ) {
surf->stylecache[0] = style->white;
// add remaining lightmaps
- for( i = 1; i < surf->numstyles; i++ ) {
- style = LIGHT_STYLE( surf, i );
+ for (i = 1; i < surf->numstyles; i++) {
+ style = LIGHT_STYLE(surf, i);
bl = blocklights;
- for( j = 0; j < size; j++ ) {
+ for (j = 0; j < size; j++) {
bl[0] += src[0] * style->rgb[0];
bl[1] += src[1] * style->rgb[1];
bl[2] += src[2] * style->rgb[2];
@@ -228,22 +233,23 @@ static void add_light_styles( mface_t *surf, int size ) {
}
}
-static void update_dynamic_lightmap( mface_t *surf ) {
- byte temp[MAX_BLOCKLIGHTS*4], *dst;
+static void update_dynamic_lightmap(mface_t *surf)
+{
+ byte temp[MAX_BLOCKLIGHTS * 4], *dst;
int smax, tmax, size, i;
float *bl;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax;
// add all the lightmaps
- add_light_styles( surf, size );
+ add_light_styles(surf, size);
#if USE_DLIGHTS
// add all the dynamic lights
- if( surf->dlightframe == glr.dlightframe ) {
- add_dynamic_lights( surf );
+ if (surf->dlightframe == glr.dlightframe) {
+ add_dynamic_lights(surf);
} else {
surf->dlightframe = 0;
}
@@ -252,47 +258,50 @@ static void update_dynamic_lightmap( mface_t *surf ) {
// put into texture format
bl = blocklights;
dst = temp;
- for( i = 0; i < size; i++ ) {
- adjust_color_ub( dst, bl );
+ for (i = 0; i < size; i++) {
+ adjust_color_ub(dst, bl);
bl += 3; dst += 4;
}
// upload lightmap subimage
- GL_BindTexture( surf->texnum[1] );
- qglTexSubImage2D( GL_TEXTURE_2D, 0,
- surf->light_s, surf->light_t, smax, tmax,
- GL_RGBA, GL_UNSIGNED_BYTE, temp );
+ GL_BindTexture(surf->texnum[1]);
+ qglTexSubImage2D(GL_TEXTURE_2D, 0,
+ surf->light_s, surf->light_t, smax, tmax,
+ GL_RGBA, GL_UNSIGNED_BYTE, temp);
c.texUploads++;
}
-void GL_BeginLights( void ) {
- qglActiveTextureARB( GL_TEXTURE1_ARB );
+void GL_BeginLights(void)
+{
+ qglActiveTextureARB(GL_TEXTURE1_ARB);
gls.tmu = 1;
}
-void GL_EndLights( void ) {
- qglActiveTextureARB( GL_TEXTURE0_ARB );
+void GL_EndLights(void)
+{
+ qglActiveTextureARB(GL_TEXTURE0_ARB);
gls.tmu = 0;
}
-void GL_PushLights( mface_t *surf ) {
+void GL_PushLights(mface_t *surf)
+{
lightstyle_t *style;
int i;
#if USE_DLIGHTS
// dynamic this frame or dynamic previously
- if( surf->dlightframe ) {
- update_dynamic_lightmap( surf );
+ if (surf->dlightframe) {
+ update_dynamic_lightmap(surf);
return;
}
#endif
// check for light style updates
- for( i = 0; i < surf->numstyles; i++ ) {
- style = LIGHT_STYLE( surf, i );
- if( style->white != surf->stylecache[i] ) {
- update_dynamic_lightmap( surf );
+ for (i = 0; i < surf->numstyles; i++) {
+ style = LIGHT_STYLE(surf, i);
+ if (style->white != surf->stylecache[i]) {
+ update_dynamic_lightmap(surf);
return;
}
}
@@ -306,41 +315,44 @@ LIGHTMAPS BUILDING
=============================================================================
*/
-#define LM_AllocBlock( w, h, s, t ) \
- GL_AllocBlock( LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, lm.inuse, w, h, s, t )
+#define LM_AllocBlock(w, h, s, t) \
+ GL_AllocBlock(LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, lm.inuse, w, h, s, t)
-static void LM_InitBlock( void ) {
+static void LM_InitBlock(void)
+{
int i;
-
- for( i = 0; i < LM_BLOCK_WIDTH; i++ ) {
+
+ for (i = 0; i < LM_BLOCK_WIDTH; i++) {
lm.inuse[i] = 0;
}
lm.dirty = qfalse;
}
-static void LM_UploadBlock( void ) {
- if( !lm.dirty ) {
+static void LM_UploadBlock(void)
+{
+ if (!lm.dirty) {
return;
}
// bypassing our state tracker here, be careful to reset TMU1 afterwards!
- qglBindTexture( GL_TEXTURE_2D, TEXNUM_LIGHTMAP + lm.nummaps );
- qglTexImage2D( GL_TEXTURE_2D, 0, lm.comp, LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ qglBindTexture(GL_TEXTURE_2D, TEXNUM_LIGHTMAP + lm.nummaps);
+ qglTexImage2D(GL_TEXTURE_2D, 0, lm.comp, LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- if( lm.highwater < ++lm.nummaps ) {
+ if (lm.highwater < ++lm.nummaps) {
lm.highwater = lm.nummaps;
}
}
-static void build_style_map( int dynamic ) {
+static void build_style_map(int dynamic)
+{
static lightstyle_t fake;
int i;
- if( !dynamic ) {
+ if (!dynamic) {
// make all styles fullbright
fake.rgb[0] = 1;
fake.rgb[1] = 1;
@@ -348,62 +360,66 @@ static void build_style_map( int dynamic ) {
fake.white = 1;
glr.fd.lightstyles = &fake;
- memset( gl_static.lightstylemap, 0, sizeof( gl_static.lightstylemap ) );
+ memset(gl_static.lightstylemap, 0, sizeof(gl_static.lightstylemap));
return;
}
- for( i = 0; i < MAX_LIGHTSTYLES; i++ ) {
+ for (i = 0; i < MAX_LIGHTSTYLES; i++) {
gl_static.lightstylemap[i] = i;
}
- if( dynamic != 1 ) {
+ if (dynamic != 1) {
// make dynamic styles fullbright
- for( i = 1; i < 32; i++ ) {
+ for (i = 1; i < 32; i++) {
gl_static.lightstylemap[i] = 0;
}
}
}
-static void LM_BeginBuilding( void ) {
- qglActiveTextureARB( GL_TEXTURE1_ARB );
+static void LM_BeginBuilding(void)
+{
+ qglActiveTextureARB(GL_TEXTURE1_ARB);
LM_InitBlock();
// start up with fullbright styles
- build_style_map( 0 );
+ build_style_map(0);
}
-static void LM_EndBuilding( void ) {
+static void LM_EndBuilding(void)
+{
// upload the last lightmap
LM_UploadBlock();
LM_InitBlock();
- qglActiveTextureARB( GL_TEXTURE0_ARB );
+ qglActiveTextureARB(GL_TEXTURE0_ARB);
// because LM_UploadBlock doesn't use our state tracker functions,
// their idea of what is bound to TMU1 needs to be reset
gls.texnum[1] = 0;
// now build the real lightstyle map
- build_style_map( gl_dynamic->integer );
+ build_style_map(gl_dynamic->integer);
}
-static void LM_FreeLightmaps( void ) {
+static void LM_FreeLightmaps(void)
+{
// lightmap textures are not deleted from memory when changing maps,
// they are merely reused
lm.nummaps = 0;
}
-static void build_primary_lightmap( mface_t *surf ) {
+static void build_primary_lightmap(mface_t *surf)
+{
byte *ptr, *dst;
int smax, tmax, size, i, j;
float *bl;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax;
// add all the lightmaps
- add_light_styles( surf, size );
+ add_light_styles(surf, size);
#if USE_DLIGHTS
surf->dlightframe = 0;
@@ -411,11 +427,11 @@ static void build_primary_lightmap( mface_t *surf ) {
// put into texture format
bl = blocklights;
- dst = &lm.buffer[ ( surf->light_t * LM_BLOCK_WIDTH + surf->light_s ) << 2 ];
- for( i = 0; i < tmax; i++ ) {
+ dst = &lm.buffer[(surf->light_t * LM_BLOCK_WIDTH + surf->light_s) << 2];
+ for (i = 0; i < tmax; i++) {
ptr = dst;
- for( j = 0; j < smax; j++ ) {
- adjust_color_ub( ptr, bl );
+ for (j = 0; j < smax; j++) {
+ adjust_color_ub(ptr, bl);
bl += 3; ptr += 4;
}
@@ -423,25 +439,25 @@ static void build_primary_lightmap( mface_t *surf ) {
}
}
-static qboolean LM_BuildSurface( mface_t *surf, vec_t *vbo ) {
+static qboolean LM_BuildSurface(mface_t *surf, vec_t *vbo)
+{
int smax, tmax, size, s, t, i;
byte *src, *ptr;
bsp_t *bsp;
// validate extents
- if( surf->extents[0] < 0 || surf->extents[0] > 512 ||
- surf->extents[1] < 0 || surf->extents[1] > 512 )
- {
- Com_EPrintf( "%s: bad surface extents\n", __func__ );
+ if (surf->extents[0] < 0 || surf->extents[0] > 512 ||
+ surf->extents[1] < 0 || surf->extents[1] > 512) {
+ Com_EPrintf("%s: bad surface extents\n", __func__);
return qfalse;
}
// validate blocklights size
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax;
- if( size > MAX_BLOCKLIGHTS ) {
- Com_EPrintf( "%s: MAX_BLOCKLIGHTS exceeded\n", __func__ );
+ if (size > MAX_BLOCKLIGHTS) {
+ Com_EPrintf("%s: MAX_BLOCKLIGHTS exceeded\n", __func__);
return qfalse;
}
@@ -449,21 +465,21 @@ static qboolean LM_BuildSurface( mface_t *surf, vec_t *vbo ) {
bsp = gl_static.world.cache;
src = surf->lightmap + surf->numstyles * size * 3;
ptr = bsp->lightmap + bsp->numlightmapbytes;
- if( src > ptr ) {
- Com_EPrintf( "%s: bad surface lightmap\n", __func__ );
+ if (src > ptr) {
+ Com_EPrintf("%s: bad surface lightmap\n", __func__);
return qfalse;
}
- if( !LM_AllocBlock( smax, tmax, &s, &t ) ) {
+ if (!LM_AllocBlock(smax, tmax, &s, &t)) {
LM_UploadBlock();
- if( lm.nummaps == LM_MAX_LIGHTMAPS ) {
- Com_EPrintf( "%s: LM_MAX_LIGHTMAPS exceeded\n", __func__ );
+ if (lm.nummaps == LM_MAX_LIGHTMAPS) {
+ Com_EPrintf("%s: LM_MAX_LIGHTMAPS exceeded\n", __func__);
return qfalse;
}
LM_InitBlock();
- if( !LM_AllocBlock( smax, tmax, &s, &t ) ) {
- Com_EPrintf( "%s: LM_AllocBlock( %d, %d ) failed\n",
- __func__, smax, tmax );
+ if (!LM_AllocBlock(smax, tmax, &s, &t)) {
+ Com_EPrintf("%s: LM_AllocBlock(%d, %d) failed\n",
+ __func__, smax, tmax);
return qfalse;
}
}
@@ -476,16 +492,16 @@ static qboolean LM_BuildSurface( mface_t *surf, vec_t *vbo ) {
surf->texnum[1] = TEXNUM_LIGHTMAP + lm.nummaps;
// build the primary lightmap
- build_primary_lightmap( surf );
+ build_primary_lightmap(surf);
// normalize and store lmtc in vertices
- s = ( s << 4 ) + 8;
- t = ( t << 4 ) + 8;
+ s = (s << 4) + 8;
+ t = (t << 4) + 8;
- s -= surf->texturemins[0];
+ s -= surf->texturemins[0];
t -= surf->texturemins[1];
- for( i = 0; i < surf->numsurfedges; i++ ) {
+ for (i = 0; i < surf->numsurfedges; i++) {
vbo[5] += s;
vbo[6] += t;
vbo[5] /= LM_BLOCK_WIDTH * 16;
@@ -497,58 +513,59 @@ static qboolean LM_BuildSurface( mface_t *surf, vec_t *vbo ) {
}
// called from the main loop whenever lightmap parameters change
-void LM_RebuildSurfaces( void ) {
+void LM_RebuildSurfaces(void)
+{
bsp_t *bsp = gl_static.world.cache;
mface_t *surf;
int i, texnum;
- if( !bsp ) {
+ if (!bsp) {
return;
}
- build_style_map( gl_dynamic->integer );
+ build_style_map(gl_dynamic->integer);
- if( !lm.nummaps ) {
+ if (!lm.nummaps) {
return;
}
- qglActiveTextureARB( GL_TEXTURE1_ARB );
- qglBindTexture( GL_TEXTURE_2D, TEXNUM_LIGHTMAP );
+ qglActiveTextureARB(GL_TEXTURE1_ARB);
+ qglBindTexture(GL_TEXTURE_2D, TEXNUM_LIGHTMAP);
texnum = TEXNUM_LIGHTMAP;
- for( i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++ ) {
- if( !surf->lightmap ) {
+ for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
+ if (!surf->lightmap) {
continue;
}
- if( surf->drawflags & SURF_NOLM_MASK ) {
+ if (surf->drawflags & SURF_NOLM_MASK) {
continue;
}
- if( !surf->texnum[1] ) {
+ if (!surf->texnum[1]) {
continue;
}
- if( surf->texnum[1] != texnum ) {
+ if (surf->texnum[1] != texnum) {
// done with previous lightmap
- qglTexImage2D( GL_TEXTURE_2D, 0, lm.comp,
- LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer );
- qglBindTexture( GL_TEXTURE_2D, surf->texnum[1] );
+ qglTexImage2D(GL_TEXTURE_2D, 0, lm.comp,
+ LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer);
+ qglBindTexture(GL_TEXTURE_2D, surf->texnum[1]);
texnum = surf->texnum[1];
c.texUploads++;
}
- build_primary_lightmap( surf );
+ build_primary_lightmap(surf);
}
// upload the last lightmap
- qglTexImage2D( GL_TEXTURE_2D, 0, lm.comp,
- LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer );
+ qglTexImage2D(GL_TEXTURE_2D, 0, lm.comp,
+ LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, lm.buffer);
c.texUploads++;
- qglActiveTextureARB( GL_TEXTURE0_ARB );
+ qglActiveTextureARB(GL_TEXTURE0_ARB);
gls.texnum[1] = 0;
}
@@ -561,7 +578,8 @@ POLYGONS BUILDING
=============================================================================
*/
-static void build_surface_poly( mface_t *surf, vec_t *vbo ) {
+static void build_surface_poly(mface_t *surf, vec_t *vbo)
+{
msurfedge_t *src_surfedge;
mvertex_t *src_vert;
medge_t *src_edge;
@@ -569,7 +587,7 @@ static void build_surface_poly( mface_t *surf, vec_t *vbo ) {
int i;
vec2_t scale, tc, mins, maxs;
int bmins[2], bmaxs[2];
-
+
surf->texnum[0] = texinfo->image->texnum;
surf->texnum[1] = 0;
@@ -581,23 +599,23 @@ static void build_surface_poly( mface_t *surf, vec_t *vbo ) {
maxs[0] = maxs[1] = -99999;
src_surfedge = surf->firstsurfedge;
- for( i = 0; i < surf->numsurfedges; i++ ) {
+ for (i = 0; i < surf->numsurfedges; i++) {
src_edge = src_surfedge->edge;
src_vert = src_edge->v[src_surfedge->vert];
src_surfedge++;
// vertex coordinates
- VectorCopy( src_vert->point, vbo );
-
+ VectorCopy(src_vert->point, vbo);
+
// texture0 coordinates
- tc[0] = DotProduct( vbo, texinfo->axis[0] ) + texinfo->offset[0];
- tc[1] = DotProduct( vbo, texinfo->axis[1] ) + texinfo->offset[1];
+ tc[0] = DotProduct(vbo, texinfo->axis[0]) + texinfo->offset[0];
+ tc[1] = DotProduct(vbo, texinfo->axis[1]) + texinfo->offset[1];
- if( mins[0] > tc[0] ) mins[0] = tc[0];
- if( maxs[0] < tc[0] ) maxs[0] = tc[0];
-
- if( mins[1] > tc[1] ) mins[1] = tc[1];
- if( maxs[1] < tc[1] ) maxs[1] = tc[1];
+ if (mins[0] > tc[0]) mins[0] = tc[0];
+ if (maxs[0] < tc[0]) maxs[0] = tc[0];
+
+ if (mins[1] > tc[1]) mins[1] = tc[1];
+ if (maxs[1] < tc[1]) maxs[1] = tc[1];
vbo[3] = tc[0] * scale[0];
vbo[4] = tc[1] * scale[1];
@@ -610,24 +628,25 @@ static void build_surface_poly( mface_t *surf, vec_t *vbo ) {
}
// calculate surface extents
- bmins[0] = floor( mins[0] / 16 );
- bmins[1] = floor( mins[1] / 16 );
- bmaxs[0] = ceil( maxs[0] / 16 );
- bmaxs[1] = ceil( maxs[1] / 16 );
+ bmins[0] = floor(mins[0] / 16);
+ bmins[1] = floor(mins[1] / 16);
+ bmaxs[0] = ceil(maxs[0] / 16);
+ bmaxs[1] = ceil(maxs[1] / 16);
surf->texturemins[0] = bmins[0] << 4;
surf->texturemins[1] = bmins[1] << 4;
- surf->extents[0] = ( bmaxs[0] - bmins[0] ) << 4;
- surf->extents[1] = ( bmaxs[1] - bmins[1] ) << 4;
+ surf->extents[0] = (bmaxs[0] - bmins[0]) << 4;
+ surf->extents[1] = (bmaxs[1] - bmins[1]) << 4;
}
// duplicates normalized texture0 coordinates for non-lit surfaces in texture1
// to make them render properly when gl_lightmap hack is used
-static void duplicate_surface_lmtc( mface_t *surf, vec_t *vbo ) {
+static void duplicate_surface_lmtc(mface_t *surf, vec_t *vbo)
+{
int i;
- for( i = 0; i < surf->numsurfedges; i++ ) {
+ for (i = 0; i < surf->numsurfedges; i++) {
vbo[5] = vbo[3];
vbo[6] = vbo[4];
@@ -635,63 +654,66 @@ static void duplicate_surface_lmtc( mface_t *surf, vec_t *vbo ) {
}
}
-void GL_FreeWorld( void ) {
- if( !gl_static.world.cache ) {
+void GL_FreeWorld(void)
+{
+ if (!gl_static.world.cache) {
return;
}
- BSP_Free( gl_static.world.cache );
+ BSP_Free(gl_static.world.cache);
- if( gl_static.world.vertices ) {
- Hunk_Free( &gl_static.world.pool );
- } else if( qglDeleteBuffersARB ) {
- qglDeleteBuffersARB( 1, &gl_static.world.bufnum );
+ if (gl_static.world.vertices) {
+ Hunk_Free(&gl_static.world.pool);
+ } else if (qglDeleteBuffersARB) {
+ qglDeleteBuffersARB(1, &gl_static.world.bufnum);
}
LM_FreeLightmaps();
-
- memset( &gl_static.world, 0, sizeof( gl_static.world ) );
+
+ memset(&gl_static.world, 0, sizeof(gl_static.world));
}
-static vec_t *create_vbo( int size ) {
+static vec_t *create_vbo(int size)
+{
GLuint buf;
vec_t *vbo;
GL_ClearErrors();
- qglGenBuffersARB( 1, &buf );
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, buf );
- qglBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB );
- if( GL_ShowErrors( "Failed to create world model VBO" ) ) {
+ qglGenBuffersARB(1, &buf);
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, buf);
+ qglBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB);
+ if (GL_ShowErrors("Failed to create world model VBO")) {
goto fail;
}
- vbo = qglMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB );
- GL_ShowErrors( "Failed to map world model VBO data" );
- if( !vbo ) {
+ vbo = qglMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB);
+ GL_ShowErrors("Failed to map world model VBO data");
+ if (!vbo) {
goto fail;
}
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
gl_static.world.vertices = NULL;
gl_static.world.bufnum = buf;
return vbo;
fail:
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
- qglDeleteBuffersARB( 1, &buf );
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ qglDeleteBuffersARB(1, &buf);
return NULL;
}
// silence GCC warning
-extern void gl_lightmap_changed( cvar_t *self );
+extern void gl_lightmap_changed(cvar_t *self);
-void gl_lightmap_changed( cvar_t *self ) {
- gl_static.world.scale = Cvar_ClampValue( gl_coloredlightmaps, 0, 1 );
+void gl_lightmap_changed(cvar_t *self)
+{
+ gl_static.world.scale = Cvar_ClampValue(gl_coloredlightmaps, 0, 1);
lm.comp = gl_static.world.scale ? GL_RGB : GL_LUMINANCE;
// FIXME: the name 'brightness' is misleading in this context
- gl_static.world.add = 255 * Cvar_ClampValue( gl_brightness, -1, 1 );
+ gl_static.world.add = 255 * Cvar_ClampValue(gl_brightness, -1, 1);
gl_static.world.modulate = gl_modulate->value * gl_modulate_world->value;
@@ -699,7 +721,8 @@ void gl_lightmap_changed( cvar_t *self ) {
lm.dirty = qtrue;
}
-void GL_LoadWorld( const char *name ) {
+void GL_LoadWorld(const char *name)
+{
char buffer[MAX_QPATH];
mface_t *surf;
int i, size, count;
@@ -708,24 +731,24 @@ void GL_LoadWorld( const char *name ) {
mtexinfo_t *info;
qerror_t ret;
- ret = BSP_Load( name, &bsp );
- if( !bsp ) {
- Com_Error( ERR_DROP, "%s: couldn't load %s: %s",
- __func__, name, Q_ErrorString( ret ) );
+ ret = BSP_Load(name, &bsp);
+ if (!bsp) {
+ Com_Error(ERR_DROP, "%s: couldn't load %s: %s",
+ __func__, name, Q_ErrorString(ret));
}
// check if the required world model was already loaded
- if( gl_static.world.cache == bsp ) {
- for( i = 0; i < bsp->numtexinfo; i++ ) {
+ if (gl_static.world.cache == bsp) {
+ for (i = 0; i < bsp->numtexinfo; i++) {
bsp->texinfo[i].image->registration_sequence = registration_sequence;
}
- for( i = 0; i < bsp->numnodes; i++ ) {
+ for (i = 0; i < bsp->numnodes; i++) {
bsp->nodes[i].visframe = 0;
}
- for( i = 0; i < bsp->numleafs; i++ ) {
+ for (i = 0; i < bsp->numleafs; i++) {
bsp->leafs[i].visframe = 0;
}
- Com_DPrintf( "%s: reused old world model\n", __func__ );
+ Com_DPrintf("%s: reused old world model\n", __func__);
bsp->refcount--;
return;
}
@@ -733,42 +756,42 @@ void GL_LoadWorld( const char *name ) {
// free previous model, if any
GL_FreeWorld();
- gl_lightmap_changed( NULL );
+ gl_lightmap_changed(NULL);
gl_static.world.cache = bsp;
// register all texinfo
- for( i = 0, info = bsp->texinfo; i < bsp->numtexinfo; i++, info++ ) {
- Q_concat( buffer, sizeof( buffer ), "textures/", info->name, ".wal", NULL );
- FS_NormalizePath( buffer, buffer );
+ for (i = 0, info = bsp->texinfo; i < bsp->numtexinfo; i++, info++) {
+ Q_concat(buffer, sizeof(buffer), "textures/", info->name, ".wal", NULL);
+ FS_NormalizePath(buffer, buffer);
upload_texinfo = info;
- info->image = IMG_Find( buffer, it_wall );
+ info->image = IMG_Find(buffer, it_wall);
upload_texinfo = NULL;
}
// calculate vertex buffer size in bytes
count = 0;
- for( i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++ ) {
+ for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
count += surf->numsurfedges;
}
size = count * VERTEX_SIZE * 4;
// try to map our VBO
vbo = NULL;
- if( qglBindBufferARB ) {
- vbo = create_vbo( size );
- if( vbo ) {
- Com_DPrintf( "%s: %d bytes of vertex data as VBO\n", __func__, size );
+ if (qglBindBufferARB) {
+ vbo = create_vbo(size);
+ if (vbo) {
+ Com_DPrintf("%s: %d bytes of vertex data as VBO\n", __func__, size);
}
}
// no VBO, allocate on hunk
- if( !vbo ) {
- Hunk_Begin( &gl_static.world.pool, size );
- vbo = Hunk_Alloc( &gl_static.world.pool, size );
- Hunk_End( &gl_static.world.pool );
+ if (!vbo) {
+ Hunk_Begin(&gl_static.world.pool, size);
+ vbo = Hunk_Alloc(&gl_static.world.pool, size);
+ Hunk_End(&gl_static.world.pool);
- Com_DPrintf( "%s: %d bytes of vertex data on hunk\n", __func__, size );
+ Com_DPrintf("%s: %d bytes of vertex data on hunk\n", __func__, size);
gl_static.world.vertices = vbo;
}
@@ -777,25 +800,25 @@ void GL_LoadWorld( const char *name ) {
// post process all surfaces
count = 0;
- for( i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++ ) {
+ for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
// hack surface flags into drawflags for faster access
surf->drawflags |= surf->texinfo->c.flags & ~DSURF_PLANEBACK;
- if( surf->drawflags & SURF_SKY ) {
+ if (surf->drawflags & SURF_SKY) {
continue;
}
surf->firstvert = count;
- build_surface_poly( surf, vbo );
+ build_surface_poly(surf, vbo);
- if( gl_fullbright->integer || ( surf->drawflags & SURF_NOLM_MASK ) ) {
+ if (gl_fullbright->integer || (surf->drawflags & SURF_NOLM_MASK)) {
surf->lightmap = NULL;
- } else if( surf->lightmap && !LM_BuildSurface( surf, vbo ) ) {
+ } else if (surf->lightmap && !LM_BuildSurface(surf, vbo)) {
surf->lightmap = NULL;
}
- if( !surf->lightmap ) {
- duplicate_surface_lmtc( surf, vbo );
+ if (!surf->lightmap) {
+ duplicate_surface_lmtc(surf, vbo);
}
count += surf->numsurfedges;
@@ -804,15 +827,15 @@ void GL_LoadWorld( const char *name ) {
// end building lightmaps
LM_EndBuilding();
- Com_DPrintf( "%s: %d lightmaps built\n", __func__, lm.nummaps );
+ Com_DPrintf("%s: %d lightmaps built\n", __func__, lm.nummaps);
// unmap our VBO
- if( qglBindBufferARB && !gl_static.world.vertices ) {
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl_static.world.bufnum );
- if( !qglUnmapBufferARB( GL_ARRAY_BUFFER_ARB ) ) {
- Com_Error( ERR_DROP, "Failed to unmap VBO data" );
+ if (qglBindBufferARB && !gl_static.world.vertices) {
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, gl_static.world.bufnum);
+ if (!qglUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) {
+ Com_Error(ERR_DROP, "Failed to unmap VBO data");
}
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
}
diff --git a/src/gl_tess.c b/src/gl_tess.c
index 967a57e..fec28da 100644
--- a/src/gl_tess.c
+++ b/src/gl_tess.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -33,47 +33,48 @@ tesselator_t tess;
static mface_t *faces_alpha, *faces_warp, *faces_alpha_warp;
static mface_t *faces_hash[FACE_HASH_SIZE];
-void GL_Flush2D( void ) {
+void GL_Flush2D(void)
+{
glStateBits_t bits;
- if( !tess.numverts ) {
+ if (!tess.numverts) {
return;
}
bits = GLS_DEPTHTEST_DISABLE;
- if( tess.flags & 2 ) {
+ if (tess.flags & 2) {
bits |= GLS_BLEND_BLEND;
- } else if( tess.flags & 1 ) {
+ } else if (tess.flags & 1) {
bits |= GLS_ALPHATEST_ENABLE;
}
- GL_BindTexture( tess.texnum[0] );
- GL_TexEnv( GL_MODULATE );
- GL_Bits( bits );
+ GL_BindTexture(tess.texnum[0]);
+ GL_TexEnv(GL_MODULATE);
+ GL_Bits(bits);
- qglEnableClientState( GL_COLOR_ARRAY );
+ qglEnableClientState(GL_COLOR_ARRAY);
- qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors );
- qglTexCoordPointer( 2, GL_FLOAT, 16, tess.vertices + 2 );
- qglVertexPointer( 2, GL_FLOAT, 16, tess.vertices );
+ qglColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.colors);
+ qglTexCoordPointer(2, GL_FLOAT, 16, tess.vertices + 2);
+ qglVertexPointer(2, GL_FLOAT, 16, tess.vertices);
- if( qglLockArraysEXT ) {
- qglLockArraysEXT( 0, tess.numverts );
+ if (qglLockArraysEXT) {
+ qglLockArraysEXT(0, tess.numverts);
}
- qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices );
+ qglDrawElements(GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices);
- if( gl_showtris->integer ) {
+ if (gl_showtris->integer) {
GL_EnableOutlines();
- qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices );
+ qglDrawElements(GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices);
GL_DisableOutlines();
}
- if( qglUnlockArraysEXT ) {
+ if (qglUnlockArraysEXT) {
qglUnlockArraysEXT();
}
- qglDisableClientState( GL_COLOR_ARRAY );
+ qglDisableClientState(GL_COLOR_ARRAY);
c.batchesDrawn2D++;
@@ -83,7 +84,8 @@ void GL_Flush2D( void ) {
tess.flags = 0;
}
-void GL_DrawParticles( void ) {
+void GL_DrawParticles(void)
+{
particle_t *p;
int i;
vec3_t transformed;
@@ -93,62 +95,62 @@ void GL_DrawParticles( void ) {
vec_t *dst_vert;
uint32_t *dst_color;
- if( !glr.fd.num_particles ) {
+ if (!glr.fd.num_particles) {
return;
}
- GL_BindTexture( TEXNUM_PARTICLE );
- GL_TexEnv( GL_MODULATE );
- GL_Bits( GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE );
+ GL_BindTexture(TEXNUM_PARTICLE);
+ GL_TexEnv(GL_MODULATE);
+ GL_Bits(GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE);
- qglEnableClientState( GL_COLOR_ARRAY );
- qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors );
- qglTexCoordPointer( 2, GL_FLOAT, 20, tess.vertices + 3 );
- qglVertexPointer( 3, GL_FLOAT, 20, tess.vertices );
+ qglEnableClientState(GL_COLOR_ARRAY);
+ qglColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.colors);
+ qglTexCoordPointer(2, GL_FLOAT, 20, tess.vertices + 3);
+ qglVertexPointer(3, GL_FLOAT, 20, tess.vertices);
#define PARTICLE_SIZE (1+M_SQRT1_2)
#define PARTICLE_SCALE (1/(2*PARTICLE_SIZE))
numverts = 0;
- for( i = 0, p = glr.fd.particles; i < glr.fd.num_particles; i++, p++ ) {
- VectorSubtract( p->origin, glr.fd.vieworg, transformed );
- dist = DotProduct( transformed, glr.viewaxis[0] );
+ for (i = 0, p = glr.fd.particles; i < glr.fd.num_particles; i++, p++) {
+ VectorSubtract(p->origin, glr.fd.vieworg, transformed);
+ dist = DotProduct(transformed, glr.viewaxis[0]);
scale = gl_partscale->value;
- if( dist > 20 ) {
+ if (dist > 20) {
scale += dist * 0.01f;
}
- if( p->color == -1 ) {
+ if (p->color == -1) {
color.u32 = p->rgba.u32;
} else {
color.u32 = d_8to24table[p->color & 0xff];
color.u8[3] = 255 * p->alpha;
}
- if( numverts + 3 > TESS_MAX_VERTICES ) {
- qglDrawArrays( GL_TRIANGLES, 0, numverts );
- if( gl_showtris->integer ) {
- qglDisableClientState( GL_COLOR_ARRAY );
+ if (numverts + 3 > TESS_MAX_VERTICES) {
+ qglDrawArrays(GL_TRIANGLES, 0, numverts);
+ if (gl_showtris->integer) {
+ qglDisableClientState(GL_COLOR_ARRAY);
GL_EnableOutlines();
- qglDrawArrays( GL_TRIANGLES, 0, numverts );
+ qglDrawArrays(GL_TRIANGLES, 0, numverts);
GL_DisableOutlines();
- qglEnableClientState( GL_COLOR_ARRAY );
+ qglEnableClientState(GL_COLOR_ARRAY);
}
numverts = 0;
}
dst_vert = tess.vertices + numverts * 5;
- VectorMA( p->origin, scale*PARTICLE_SCALE, glr.viewaxis[1], dst_vert );
- VectorMA( dst_vert, -scale*PARTICLE_SCALE, glr.viewaxis[2], dst_vert );
- VectorMA( dst_vert, scale, glr.viewaxis[2], dst_vert + 5 );
- VectorMA( dst_vert, -scale, glr.viewaxis[1], dst_vert + 10 );
+ VectorMA(p->origin, scale * PARTICLE_SCALE, glr.viewaxis[1], dst_vert);
+ VectorMA(dst_vert, -scale * PARTICLE_SCALE, glr.viewaxis[2], dst_vert);
+ VectorMA(dst_vert, scale, glr.viewaxis[2], dst_vert + 5);
+ VectorMA(dst_vert, -scale, glr.viewaxis[1], dst_vert + 10);
dst_vert[ 3] = 0; dst_vert[ 4] = 0;
dst_vert[ 8] = 0; dst_vert[ 9] = PARTICLE_SIZE;
dst_vert[13] = PARTICLE_SIZE; dst_vert[14] = 0;
- dst_color = ( uint32_t * )tess.colors + numverts;
+ dst_color = (uint32_t *)tess.colors + numverts;
dst_color[0] = color.u32;
dst_color[1] = color.u32;
dst_color[2] = color.u32;
@@ -156,18 +158,19 @@ void GL_DrawParticles( void ) {
numverts += 3;
}
- qglDrawArrays( GL_TRIANGLES, 0, numverts );
- qglDisableClientState( GL_COLOR_ARRAY );
+ qglDrawArrays(GL_TRIANGLES, 0, numverts);
+ qglDisableClientState(GL_COLOR_ARRAY);
- if( gl_showtris->integer ) {
+ if (gl_showtris->integer) {
GL_EnableOutlines();
- qglDrawArrays( GL_TRIANGLES, 0, numverts );
+ qglDrawArrays(GL_TRIANGLES, 0, numverts);
GL_DisableOutlines();
}
}
/* all things serve the Beam */
-void GL_DrawBeams( void ) {
+void GL_DrawBeams(void)
+{
vec3_t d1, d2, d3;
vec_t *start, *end;
color_t color;
@@ -180,63 +183,62 @@ void GL_DrawBeams( void ) {
entity_t *ent;
int i;
- if( !glr.num_beams ) {
+ if (!glr.num_beams) {
return;
}
- GL_BindTexture( TEXNUM_BEAM );
- GL_TexEnv( GL_MODULATE );
- GL_Bits( GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE );
+ GL_BindTexture(TEXNUM_BEAM);
+ GL_TexEnv(GL_MODULATE);
+ GL_Bits(GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE);
- qglEnableClientState( GL_COLOR_ARRAY );
- qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors );
- qglTexCoordPointer( 2, GL_FLOAT, 20, tess.vertices + 3 );
- qglVertexPointer( 3, GL_FLOAT, 20, tess.vertices );
+ qglEnableClientState(GL_COLOR_ARRAY);
+ qglColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.colors);
+ qglTexCoordPointer(2, GL_FLOAT, 20, tess.vertices + 3);
+ qglVertexPointer(3, GL_FLOAT, 20, tess.vertices);
numverts = numindices = 0;
- for( i = 0, ent = glr.fd.entities; i < glr.fd.num_entities; i++, ent++ ) {
- if( !( ent->flags & RF_BEAM ) ) {
+ for (i = 0, ent = glr.fd.entities; i < glr.fd.num_entities; i++, ent++) {
+ if (!(ent->flags & RF_BEAM)) {
continue;
}
start = ent->origin;
end = ent->oldorigin;
- VectorSubtract( end, start, d1 );
- VectorSubtract( glr.fd.vieworg, start, d2 );
- CrossProduct( d1, d2, d3 );
- length = VectorLength( d3 );
+ VectorSubtract(end, start, d1);
+ VectorSubtract(glr.fd.vieworg, start, d2);
+ CrossProduct(d1, d2, d3);
+ length = VectorLength(d3);
length = ent->frame * 1.2f / length;
- VectorScale( d3, length, d3 );
+ VectorScale(d3, length, d3);
- length = VectorLength( d1 );
+ length = VectorLength(d1);
- if( ent->skinnum == -1 ) {
+ if (ent->skinnum == -1) {
color.u32 = ent->rgba.u32;
} else {
color.u32 = d_8to24table[ent->skinnum & 0xff];
color.u8[3] = 255 * ent->alpha;
}
- if( numverts + 4 > TESS_MAX_VERTICES ||
- numindices + 6 > TESS_MAX_INDICES )
- {
- qglDrawElements( GL_TRIANGLES, numindices,
- GL_UNSIGNED_INT, tess.indices );
+ if (numverts + 4 > TESS_MAX_VERTICES ||
+ numindices + 6 > TESS_MAX_INDICES) {
+ qglDrawElements(GL_TRIANGLES, numindices,
+ GL_UNSIGNED_INT, tess.indices);
numverts = numindices = 0;
}
dst_vert = tess.vertices + numverts * 5;
- VectorAdd( start, d3, dst_vert );
- VectorSubtract( start, d3, dst_vert + 5 );
- VectorSubtract( end, d3, dst_vert + 10 );
- VectorAdd( end, d3, dst_vert + 15 );
+ VectorAdd(start, d3, dst_vert);
+ VectorSubtract(start, d3, dst_vert + 5);
+ VectorSubtract(end, d3, dst_vert + 10);
+ VectorAdd(end, d3, dst_vert + 15);
dst_vert[3] = 0; dst_vert[4] = 0;
dst_vert[8] = 1; dst_vert[9] = 0;
dst_vert[13] = 1; dst_vert[14] = length;
dst_vert[18] = 0; dst_vert[19] = length;
-
- dst_color = ( uint32_t * )tess.colors + numverts;
+
+ dst_color = (uint32_t *)tess.colors + numverts;
dst_color[0] = color.u32;
dst_color[1] = color.u32;
dst_color[2] = color.u32;
@@ -254,110 +256,113 @@ void GL_DrawBeams( void ) {
numindices += 6;
}
- qglDrawElements( GL_TRIANGLES, numindices,
- GL_UNSIGNED_INT, tess.indices );
- qglDisableClientState( GL_COLOR_ARRAY );
+ qglDrawElements(GL_TRIANGLES, numindices,
+ GL_UNSIGNED_INT, tess.indices);
+ qglDisableClientState(GL_COLOR_ARRAY);
}
-static void GL_BindArrays( void ) {
+static void GL_BindArrays(void)
+{
vec_t *ptr;
- if( gl_static.world.vertices ) {
+ if (gl_static.world.vertices) {
ptr = tess.vertices;
} else {
ptr = NULL;
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl_static.world.bufnum );
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, gl_static.world.bufnum);
}
- qglVertexPointer( 3, GL_FLOAT, 4*VERTEX_SIZE, ptr + 0 );
- qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE,
- gl_lightmap->integer ? ptr + 5 : ptr + 3 );
+ qglVertexPointer(3, GL_FLOAT, 4 * VERTEX_SIZE, ptr + 0);
+ qglTexCoordPointer(2, GL_FLOAT, 4 * VERTEX_SIZE,
+ gl_lightmap->integer ? ptr + 5 : ptr + 3);
- qglClientActiveTextureARB( GL_TEXTURE1_ARB );
- qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
- qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE, ptr + 5 );
- qglClientActiveTextureARB( GL_TEXTURE0_ARB );
+ qglClientActiveTextureARB(GL_TEXTURE1_ARB);
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglTexCoordPointer(2, GL_FLOAT, 4 * VERTEX_SIZE, ptr + 5);
+ qglClientActiveTextureARB(GL_TEXTURE0_ARB);
}
-static void GL_UnbindArrays( void ) {
- if( !gl_static.world.vertices ) {
- qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+static void GL_UnbindArrays(void)
+{
+ if (!gl_static.world.vertices) {
+ qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
- qglClientActiveTextureARB( GL_TEXTURE1_ARB );
- qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
- qglClientActiveTextureARB( GL_TEXTURE0_ARB );
+ qglClientActiveTextureARB(GL_TEXTURE1_ARB);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ qglClientActiveTextureARB(GL_TEXTURE0_ARB);
}
-static void GL_Flush3D( void ) {
- if( !tess.numindices ) {
+static void GL_Flush3D(void)
+{
+ if (!tess.numindices) {
return;
}
- if( tess.flags & (SURF_TRANS33|SURF_TRANS66|SURF_WARP) ) {
+ if (tess.flags & (SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)) {
float f = gl_static.inverse_intensity;
- if( tess.flags & SURF_TRANS33 ) {
- qglColor4f( f, f, f, 0.33f );
- } else if( tess.flags & SURF_TRANS66 ) {
- qglColor4f( f, f, f, 0.66f );
+ if (tess.flags & SURF_TRANS33) {
+ qglColor4f(f, f, f, 0.33f);
+ } else if (tess.flags & SURF_TRANS66) {
+ qglColor4f(f, f, f, 0.66f);
} else {
- qglColor4f( f, f, f, 1.0f );
+ qglColor4f(f, f, f, 1.0f);
}
- GL_TexEnv( GL_MODULATE );
+ GL_TexEnv(GL_MODULATE);
} else {
- GL_TexEnv( GL_REPLACE );
+ GL_TexEnv(GL_REPLACE);
}
- GL_BindTexture( tess.texnum[0] );
+ GL_BindTexture(tess.texnum[0]);
- if( tess.flags & SURF_FLOWING ) {
+ if (tess.flags & SURF_FLOWING) {
float scaled, scroll;
- if( tess.flags & SURF_WARP ) {
+ if (tess.flags & SURF_WARP) {
scaled = glr.fd.time * 0.5f;
scroll = -scaled;
} else {
scaled = glr.fd.time / 40;
- scroll = -64 * ( scaled - (int)scaled );
+ scroll = -64 * (scaled - (int)scaled);
}
- qglMatrixMode( GL_TEXTURE );
+ qglMatrixMode(GL_TEXTURE);
qglPushMatrix();
- qglTranslatef( scroll, 0, 0 );
+ qglTranslatef(scroll, 0, 0);
}
- if( tess.texnum[1] ) {
- GL_SelectTMU( 1 );
- qglEnable( GL_TEXTURE_2D );
- GL_TexEnv( GL_MODULATE );
- GL_BindTexture( tess.texnum[1] );
+ if (tess.texnum[1]) {
+ GL_SelectTMU(1);
+ qglEnable(GL_TEXTURE_2D);
+ GL_TexEnv(GL_MODULATE);
+ GL_BindTexture(tess.texnum[1]);
}
- if( gl_static.world.vertices && qglLockArraysEXT ) {
- qglLockArraysEXT( 0, tess.numverts );
+ if (gl_static.world.vertices && qglLockArraysEXT) {
+ qglLockArraysEXT(0, tess.numverts);
}
- qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices );
+ qglDrawElements(GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices);
- if( tess.texnum[1] ) {
- qglDisable( GL_TEXTURE_2D );
- GL_SelectTMU( 0 );
+ if (tess.texnum[1]) {
+ qglDisable(GL_TEXTURE_2D);
+ GL_SelectTMU(0);
}
- if( gl_showtris->integer ) {
+ if (gl_showtris->integer) {
GL_EnableOutlines();
- qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices );
+ qglDrawElements(GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices);
GL_DisableOutlines();
}
- if( gl_static.world.vertices && qglUnlockArraysEXT ) {
+ if (gl_static.world.vertices && qglUnlockArraysEXT) {
qglUnlockArraysEXT();
}
- if( tess.flags & SURF_FLOWING ) {
+ if (tess.flags & SURF_FLOWING) {
qglPopMatrix();
- qglMatrixMode( GL_MODELVIEW );
+ qglMatrixMode(GL_MODELVIEW);
}
c.batchesDrawn++;
@@ -368,32 +373,34 @@ static void GL_Flush3D( void ) {
tess.flags = 0;
}
-static int GL_CopyVerts( mface_t *surf ) {
+static int GL_CopyVerts(mface_t *surf)
+{
void *src, *dst;
int firstvert;
- if( tess.numverts + surf->numsurfedges > TESS_MAX_VERTICES ) {
+ if (tess.numverts + surf->numsurfedges > TESS_MAX_VERTICES) {
GL_Flush3D();
}
src = gl_static.world.vertices + surf->firstvert * VERTEX_SIZE;
dst = tess.vertices + tess.numverts * VERTEX_SIZE;
- memcpy( dst, src, surf->numsurfedges * VERTEX_SIZE * sizeof( vec_t ) );
+ memcpy(dst, src, surf->numsurfedges * VERTEX_SIZE * sizeof(vec_t));
firstvert = tess.numverts;
tess.numverts += surf->numsurfedges;
return firstvert;
}
-static int GL_TextureAnimation( mtexinfo_t *tex ) {
+static int GL_TextureAnimation(mtexinfo_t *tex)
+{
int frame, c;
- if( !tex->next )
+ if (!tex->next)
return tex->image->texnum;
- frame = ( int )( glr.fd.time * 2 );
+ frame = (int)(glr.fd.time * 2);
c = frame % tex->numframes;
- while( c ) {
+ while (c) {
tex = tex->next;
c--;
}
@@ -404,29 +411,29 @@ static int GL_TextureAnimation( mtexinfo_t *tex ) {
#define SURF_FLUSH_MASK \
(SURF_TRANS33|SURF_TRANS66|SURF_WARP|SURF_FLOWING)
-static void GL_DrawFace( mface_t *surf ) {
+static void GL_DrawFace(mface_t *surf)
+{
int numtris = surf->numsurfedges - 2;
int numindices = numtris * 3;
int diff = surf->drawflags ^ tess.flags;
- int texnum = GL_TextureAnimation( surf->texinfo );
+ int texnum = GL_TextureAnimation(surf->texinfo);
int *dst_indices;
int i, j;
- if( tess.texnum[0] != texnum ||
+ if (tess.texnum[0] != texnum ||
tess.texnum[1] != surf->texnum[1] ||
- ( diff & SURF_FLUSH_MASK ) ||
- tess.numindices + numindices > TESS_MAX_INDICES )
- {
+ (diff & SURF_FLUSH_MASK) ||
+ tess.numindices + numindices > TESS_MAX_INDICES) {
GL_Flush3D();
}
- if( gl_static.world.vertices ) {
- j = GL_CopyVerts( surf );
+ if (gl_static.world.vertices) {
+ j = GL_CopyVerts(surf);
} else {
j = surf->firstvert;
}
- if( gl_lightmap->integer ) {
+ if (gl_lightmap->integer) {
tess.texnum[0] = surf->texnum[1] ? surf->texnum[1] : texnum;
tess.texnum[1] = 0;
} else {
@@ -437,10 +444,10 @@ static void GL_DrawFace( mface_t *surf ) {
tess.flags = surf->drawflags;
dst_indices = tess.indices + tess.numindices;
- for( i = 0; i < numtris; i++ ) {
+ for (i = 0; i < numtris; i++) {
dst_indices[0] = j;
- dst_indices[1] = j + ( i + 1 );
- dst_indices[2] = j + ( i + 2 );
+ dst_indices[1] = j + (i + 1);
+ dst_indices[2] = j + (i + 2);
dst_indices += 3;
}
tess.numindices += numindices;
@@ -448,74 +455,79 @@ static void GL_DrawFace( mface_t *surf ) {
c.trisDrawn += numtris;
}
-static inline void GL_DrawChain( mface_t **head ) {
+static inline void GL_DrawChain(mface_t **head)
+{
mface_t *face;
- for( face = *head; face; face = face->next ) {
- GL_DrawFace( face );
+ for (face = *head; face; face = face->next) {
+ GL_DrawFace(face);
}
*head = NULL;
}
-void GL_DrawSolidFaces( void ) {
+void GL_DrawSolidFaces(void)
+{
int i;
GL_BindArrays();
- GL_Bits( GLS_DEFAULT );
+ GL_Bits(GLS_DEFAULT);
- if( faces_warp ) {
+ if (faces_warp) {
GL_EnableWarp();
- GL_DrawChain( &faces_warp );
+ GL_DrawChain(&faces_warp);
GL_Flush3D();
GL_DisableWarp();
}
- for( i = 0; i < FACE_HASH_SIZE; i++ ) {
- GL_DrawChain( &faces_hash[i] );
+ for (i = 0; i < FACE_HASH_SIZE; i++) {
+ GL_DrawChain(&faces_hash[i]);
}
GL_Flush3D();
GL_UnbindArrays();
}
-void GL_DrawAlphaFaces( void ) {
+void GL_DrawAlphaFaces(void)
+{
GL_BindArrays();
- GL_Bits( GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE );
+ GL_Bits(GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE);
- if( faces_alpha_warp ) {
+ if (faces_alpha_warp) {
GL_EnableWarp();
- GL_DrawChain( &faces_alpha_warp );
+ GL_DrawChain(&faces_alpha_warp);
GL_Flush3D();
GL_DisableWarp();
}
- GL_DrawChain( &faces_alpha );
+ GL_DrawChain(&faces_alpha);
GL_Flush3D();
GL_UnbindArrays();
}
-void GL_AddSolidFace( mface_t *face ) {
- if( ( face->drawflags & SURF_WARP ) && gl_static.prognum_warp ) {
+void GL_AddSolidFace(mface_t *face)
+{
+ if ((face->drawflags & SURF_WARP) && gl_static.prognum_warp) {
face->next = faces_warp;
faces_warp = face;
} else {
- unsigned i = FACE_HASH( face->texnum[0], face->texnum[1] );
+ unsigned i = FACE_HASH(face->texnum[0], face->texnum[1]);
face->next = faces_hash[i];
faces_hash[i] = face;
- if( face->lightmap && !( face->drawflags & SURF_NOLM_MASK ) && gl_dynamic->integer ) {
- GL_PushLights( face );
+ if (face->lightmap && !(face->drawflags & SURF_NOLM_MASK) && gl_dynamic->integer) {
+ GL_PushLights(face);
}
}
c.facesDrawn++;
}
-void GL_AddAlphaFace( mface_t *face ) {
- if( ( face->drawflags & SURF_WARP ) && gl_static.prognum_warp ) {
+void GL_AddAlphaFace(mface_t *face)
+{
+ if ((face->drawflags & SURF_WARP) && gl_static.prognum_warp) {
face->next = faces_alpha_warp;
faces_alpha_warp = face;
} else {
diff --git a/src/gl_world.c b/src/gl_world.c
index 492d7a3..d006139 100644
--- a/src/gl_world.c
+++ b/src/gl_world.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,7 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "gl_local.h"
-static qboolean GL_LightPoint( vec3_t origin, vec3_t color ) {
+static qboolean GL_LightPoint(vec3_t origin, vec3_t color)
+{
bsp_t *bsp = gl_static.world.cache;
mface_t *surf;
int s, t, i;
@@ -33,48 +34,48 @@ static qboolean GL_LightPoint( vec3_t origin, vec3_t color ) {
lightstyle_t *style;
vec3_t point;
- if( !bsp || !bsp->lightmap ) {
+ if (!bsp || !bsp->lightmap) {
return qfalse;
}
point[0] = origin[0];
point[1] = origin[1];
point[2] = origin[2] - 8192;
-
- surf = BSP_LightPoint( bsp->nodes, origin, point, &s, &t );
- if( !surf ) {
+
+ surf = BSP_LightPoint(bsp->nodes, origin, point, &s, &t);
+ if (!surf) {
return qfalse;
}
fracu = s & 15;
fracv = t & 15;
- w1 = ( 16 - fracu ) * ( 16 - fracv );
- w2 = fracu * ( 16 - fracv );
+ w1 = (16 - fracu) * (16 - fracv);
+ w2 = fracu * (16 - fracv);
w3 = fracu * fracv;
- w4 = ( 16 - fracu ) * fracv;
+ w4 = (16 - fracu) * fracv;
s >>= 4;
t >>= 4;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax * 3;
- VectorClear( color );
+ VectorClear(color);
lightmap = surf->lightmap;
- for( i = 0; i < surf->numstyles; i++ ) {
- b1 = &lightmap[3 * ( ( t + 0 ) * smax + ( s + 0 ) )];
- b2 = &lightmap[3 * ( ( t + 0 ) * smax + ( s + 1 ) )];
- b3 = &lightmap[3 * ( ( t + 1 ) * smax + ( s + 1 ) )];
- b4 = &lightmap[3 * ( ( t + 1 ) * smax + ( s + 0 ) )];
+ for (i = 0; i < surf->numstyles; i++) {
+ b1 = &lightmap[3 * ((t + 0) * smax + (s + 0))];
+ b2 = &lightmap[3 * ((t + 0) * smax + (s + 1))];
+ b3 = &lightmap[3 * ((t + 1) * smax + (s + 1))];
+ b4 = &lightmap[3 * ((t + 1) * smax + (s + 0))];
- temp[0] = ( w1 * b1[0] + w2 * b2[0] + w3 * b3[0] + w4 * b4[0] ) >> 8;
- temp[1] = ( w1 * b1[1] + w2 * b2[1] + w3 * b3[1] + w4 * b4[1] ) >> 8;
- temp[2] = ( w1 * b1[2] + w2 * b2[2] + w3 * b3[2] + w4 * b4[2] ) >> 8;
+ temp[0] = (w1 * b1[0] + w2 * b2[0] + w3 * b3[0] + w4 * b4[0]) >> 8;
+ temp[1] = (w1 * b1[1] + w2 * b2[1] + w3 * b3[1] + w4 * b4[1]) >> 8;
+ temp[2] = (w1 * b1[2] + w2 * b2[2] + w3 * b3[2] + w4 * b4[2]) >> 8;
- style = LIGHT_STYLE( surf, i );
+ style = LIGHT_STYLE(surf, i);
color[0] += temp[0] * style->rgb[0];
color[1] += temp[1] * style->rgb[1];
@@ -83,129 +84,136 @@ static qboolean GL_LightPoint( vec3_t origin, vec3_t color ) {
lightmap += size;
}
- GL_AdjustColor( color );
+ GL_AdjustColor(color);
return qtrue;
}
#if USE_DLIGHTS
-static void GL_MarkLights_r( mnode_t *node, dlight_t *light, int lightbit ) {
+static void GL_MarkLights_r(mnode_t *node, dlight_t *light, int lightbit)
+{
vec_t dot;
int count;
mface_t *face;
-
- while( node->plane ) {
- dot = PlaneDiffFast( light->transformed, node->plane );
- if( dot > light->intensity - DLIGHT_CUTOFF ) {
+
+ while (node->plane) {
+ dot = PlaneDiffFast(light->transformed, node->plane);
+ if (dot > light->intensity - DLIGHT_CUTOFF) {
node = node->children[0];
continue;
}
- if( dot < -light->intensity + DLIGHT_CUTOFF ) {
+ if (dot < -light->intensity + DLIGHT_CUTOFF) {
node = node->children[1];
continue;
}
face = node->firstface;
count = node->numfaces;
- while( count-- ) {
- if( !( face->drawflags & SURF_NOLM_MASK ) ) {
- if( face->dlightframe != glr.dlightframe ) {
+ while (count--) {
+ if (!(face->drawflags & SURF_NOLM_MASK)) {
+ if (face->dlightframe != glr.dlightframe) {
face->dlightframe = glr.dlightframe;
face->dlightbits = 0;
}
-
+
face->dlightbits |= lightbit;
}
face++;
}
- GL_MarkLights_r( node->children[0], light, lightbit );
+ GL_MarkLights_r(node->children[0], light, lightbit);
node = node->children[1];
}
}
-static void GL_MarkLights( void ) {
+static void GL_MarkLights(void)
+{
int i;
dlight_t *light;
- for( i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++ ) {
- VectorCopy( light->origin, light->transformed );
- GL_MarkLights_r( gl_static.world.cache->nodes, light, 1 << i );
+ for (i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++) {
+ VectorCopy(light->origin, light->transformed);
+ GL_MarkLights_r(gl_static.world.cache->nodes, light, 1 << i);
}
}
-static void GL_TransformLights( mmodel_t *model ) {
+static void GL_TransformLights(mmodel_t *model)
+{
int i;
dlight_t *light;
vec3_t temp;
- if( !model->headnode ) {
+ if (!model->headnode) {
return;
}
-
- for( i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++ ) {
- VectorSubtract( light->origin, glr.ent->origin, temp );
- light->transformed[0] = DotProduct( temp, glr.entaxis[0] );
- light->transformed[1] = DotProduct( temp, glr.entaxis[1] );
- light->transformed[2] = DotProduct( temp, glr.entaxis[2] );
- GL_MarkLights_r( model->headnode, light, 1 << i );
+
+ for (i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++) {
+ VectorSubtract(light->origin, glr.ent->origin, temp);
+ light->transformed[0] = DotProduct(temp, glr.entaxis[0]);
+ light->transformed[1] = DotProduct(temp, glr.entaxis[1]);
+ light->transformed[2] = DotProduct(temp, glr.entaxis[2]);
+ GL_MarkLights_r(model->headnode, light, 1 << i);
}
}
-static void GL_AddLights( vec3_t origin, vec3_t color ) {
+static void GL_AddLights(vec3_t origin, vec3_t color)
+{
dlight_t *light;
vec3_t dir;
vec_t f;
int i;
- for( i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++ ) {
- VectorSubtract( light->origin, origin, dir );
- f = light->intensity - VectorLength( dir );
- if( f > 0 ) {
- f *= (1.0f/255);
- VectorMA( color, f, light->color, color );
+ for (i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++) {
+ VectorSubtract(light->origin, origin, dir);
+ f = light->intensity - VectorLength(dir);
+ if (f > 0) {
+ f *= (1.0f / 255);
+ VectorMA(color, f, light->color, color);
}
}
}
#endif
-void _R_LightPoint( vec3_t origin, vec3_t color ) {
- if( gl_fullbright->integer ) {
- VectorSet( color, 1, 1, 1 );
+void _R_LightPoint(vec3_t origin, vec3_t color)
+{
+ if (gl_fullbright->integer) {
+ VectorSet(color, 1, 1, 1);
return;
}
// get lighting from world
- if( !GL_LightPoint( origin, color ) ) {
- VectorSet( color, 1, 1, 1 );
+ if (!GL_LightPoint(origin, color)) {
+ VectorSet(color, 1, 1, 1);
}
#if USE_DLIGHTS
- if( gl_dynamic->integer == 1 ) {
+ if (gl_dynamic->integer == 1) {
// add dynamic lights
- GL_AddLights( origin, color );
+ GL_AddLights(origin, color);
}
#endif
- if( gl_doublelight_entities->integer ) {
+ if (gl_doublelight_entities->integer) {
// apply modulate twice to mimic original ref_gl behavior
- VectorScale( color, gl_static.entity_modulate, color );
+ VectorScale(color, gl_static.entity_modulate, color);
}
}
-void R_LightPoint( vec3_t origin, vec3_t color ) {
+void R_LightPoint(vec3_t origin, vec3_t color)
+{
int i;
- _R_LightPoint( origin, color );
+ _R_LightPoint(origin, color);
- for( i = 0; i < 3; i++ ) {
- clamp( color[i], 0, 1 );
+ for (i = 0; i < 3; i++) {
+ clamp(color[i], 0, 1);
}
}
-static void GL_MarkLeaves( void ) {
+static void GL_MarkLeaves(void)
+{
static int lastNodesVisible;
byte vis1[VIS_MAX_BYTES];
byte vis2[VIS_MAX_BYTES];
@@ -217,24 +225,24 @@ static void GL_MarkLeaves( void ) {
int i;
bsp_t *bsp = gl_static.world.cache;
- leaf = BSP_PointLeaf( bsp->nodes, glr.fd.vieworg );
+ leaf = BSP_PointLeaf(bsp->nodes, glr.fd.vieworg);
cluster1 = cluster2 = leaf->cluster;
- VectorCopy( glr.fd.vieworg, tmp );
- if( !leaf->contents ) {
- tmp[2] -= 16;
+ VectorCopy(glr.fd.vieworg, tmp);
+ if (!leaf->contents) {
+ tmp[2] -= 16;
} else {
- tmp[2] += 16;
- }
- leaf = BSP_PointLeaf( bsp->nodes, tmp );
- if( !( leaf->contents & CONTENTS_SOLID ) ) {
+ tmp[2] += 16;
+ }
+ leaf = BSP_PointLeaf(bsp->nodes, tmp);
+ if (!(leaf->contents & CONTENTS_SOLID)) {
cluster2 = leaf->cluster;
}
-
- if( cluster1 == glr.viewcluster1 && cluster2 == glr.viewcluster2 ) {
+
+ if (cluster1 == glr.viewcluster1 && cluster2 == glr.viewcluster2) {
goto finish;
}
-
- if( gl_lockpvs->integer ) {
+
+ if (gl_lockpvs->integer) {
goto finish;
}
@@ -242,50 +250,50 @@ static void GL_MarkLeaves( void ) {
glr.viewcluster1 = cluster1;
glr.viewcluster2 = cluster2;
- if( !bsp->vis || gl_novis->integer || cluster1 == -1 ) {
+ if (!bsp->vis || gl_novis->integer || cluster1 == -1) {
// mark everything visible
- for( i = 0; i < bsp->numnodes; i++ ) {
+ for (i = 0; i < bsp->numnodes; i++) {
bsp->nodes[i].visframe = glr.visframe;
}
- for( i = 0; i < bsp->numleafs; i++ ) {
+ for (i = 0; i < bsp->numleafs; i++) {
bsp->leafs[i].visframe = glr.visframe;
}
lastNodesVisible = bsp->numnodes;
goto finish;
}
- BSP_ClusterVis( bsp, vis1, cluster1, DVIS_PVS );
- if( cluster1 != cluster2 ) {
- BSP_ClusterVis( bsp, vis2, cluster2, DVIS_PVS );
- longs = VIS_FAST_LONGS( bsp );
- src1 = ( uint_fast32_t * )vis1;
- src2 = ( uint_fast32_t * )vis2;
- while( longs-- ) {
+ BSP_ClusterVis(bsp, vis1, cluster1, DVIS_PVS);
+ if (cluster1 != cluster2) {
+ BSP_ClusterVis(bsp, vis2, cluster2, DVIS_PVS);
+ longs = VIS_FAST_LONGS(bsp);
+ src1 = (uint_fast32_t *)vis1;
+ src2 = (uint_fast32_t *)vis2;
+ while (longs--) {
*src1++ |= *src2++;
}
}
lastNodesVisible = 0;
- for( i = 0, leaf = bsp->leafs; i < bsp->numleafs; i++, leaf++ ) {
+ for (i = 0, leaf = bsp->leafs; i < bsp->numleafs; i++, leaf++) {
cluster1 = leaf->cluster;
- if( cluster1 == -1 ) {
+ if (cluster1 == -1) {
continue;
}
- if( Q_IsBitSet( vis1, cluster1 ) ) {
- node = ( mnode_t * )leaf;
+ if (Q_IsBitSet(vis1, cluster1)) {
+ node = (mnode_t *)leaf;
// mark parent nodes visible
do {
- if( node->visframe == glr.visframe ) {
+ if (node->visframe == glr.visframe) {
break;
}
node->visframe = glr.visframe;
node = node->parent;
lastNodesVisible++;
- } while( node );
+ } while (node);
}
}
-
+
finish:
c.nodesVisible = lastNodesVisible;
@@ -293,11 +301,12 @@ finish:
#define BACKFACE_EPSILON 0.001f
-#define BSP_CullFace( face, dot ) \
- ( ( (dot) < -BACKFACE_EPSILON && !( (face)->drawflags & DSURF_PLANEBACK ) ) || \
- ( (dot) > BACKFACE_EPSILON && ( (face)->drawflags & DSURF_PLANEBACK ) ) )
+#define BSP_CullFace(face, dot) \
+ (((dot) < -BACKFACE_EPSILON && !((face)->drawflags & DSURF_PLANEBACK)) || \
+ ((dot) > BACKFACE_EPSILON && ((face)->drawflags & DSURF_PLANEBACK)))
-void GL_DrawBspModel( mmodel_t *model ) {
+void GL_DrawBspModel(mmodel_t *model)
+{
mface_t *face;
int count, mask = 0;
vec3_t bounds[2];
@@ -306,36 +315,36 @@ void GL_DrawBspModel( mmodel_t *model ) {
entity_t *ent = glr.ent;
glCullResult_t cull;
- if( glr.entrotated ) {
- cull = GL_CullSphere( ent->origin, model->radius );
- if( cull == CULL_OUT ) {
+ if (glr.entrotated) {
+ cull = GL_CullSphere(ent->origin, model->radius);
+ if (cull == CULL_OUT) {
c.spheresCulled++;
return;
}
- if( cull == CULL_CLIP ) {
- VectorCopy( model->mins, bounds[0] );
- VectorCopy( model->maxs, bounds[1] );
- cull = GL_CullLocalBox( ent->origin, bounds );
- if( cull == CULL_OUT ) {
+ if (cull == CULL_CLIP) {
+ VectorCopy(model->mins, bounds[0]);
+ VectorCopy(model->maxs, bounds[1]);
+ cull = GL_CullLocalBox(ent->origin, bounds);
+ if (cull == CULL_OUT) {
c.rotatedBoxesCulled++;
return;
}
}
- VectorSubtract( glr.fd.vieworg, ent->origin, temp );
- transformed[0] = DotProduct( temp, glr.entaxis[0] );
- transformed[1] = DotProduct( temp, glr.entaxis[1] );
- transformed[2] = DotProduct( temp, glr.entaxis[2] );
+ VectorSubtract(glr.fd.vieworg, ent->origin, temp);
+ transformed[0] = DotProduct(temp, glr.entaxis[0]);
+ transformed[1] = DotProduct(temp, glr.entaxis[1]);
+ transformed[2] = DotProduct(temp, glr.entaxis[2]);
} else {
- VectorAdd( model->mins, ent->origin, bounds[0] );
- VectorAdd( model->maxs, ent->origin, bounds[1] );
- cull = GL_CullBox( bounds );
- if( cull == CULL_OUT ) {
+ VectorAdd(model->mins, ent->origin, bounds[0]);
+ VectorAdd(model->maxs, ent->origin, bounds[1]);
+ cull = GL_CullBox(bounds);
+ if (cull == CULL_OUT) {
c.boxesCulled++;
return;
}
- VectorSubtract( glr.fd.vieworg, ent->origin, transformed );
- if( VectorEmpty( ent->origin ) && model->drawframe != glr.drawframe ) {
- mask = SURF_TRANS33|SURF_TRANS66;
+ VectorSubtract(glr.fd.vieworg, ent->origin, transformed);
+ if (VectorEmpty(ent->origin) && model->drawframe != glr.drawframe) {
+ mask = SURF_TRANS33 | SURF_TRANS66;
}
}
@@ -345,42 +354,42 @@ void GL_DrawBspModel( mmodel_t *model ) {
#if USE_DLIGHTS
glr.dlightframe++;
- if( gl_dynamic->integer == 1 ) {
- GL_TransformLights( model );
+ if (gl_dynamic->integer == 1) {
+ GL_TransformLights(model);
}
#endif
- if( gl_dynamic->integer ) {
+ if (gl_dynamic->integer) {
GL_BeginLights();
}
qglPushMatrix();
- qglTranslatef( ent->origin[0], ent->origin[1], ent->origin[2] );
- if( glr.entrotated ) {
- qglRotatef( ent->angles[YAW], 0, 0, 1 );
- qglRotatef( ent->angles[PITCH], 0, 1, 0 );
- qglRotatef( ent->angles[ROLL], 1, 0, 0 );
+ qglTranslatef(ent->origin[0], ent->origin[1], ent->origin[2]);
+ if (glr.entrotated) {
+ qglRotatef(ent->angles[YAW], 0, 0, 1);
+ qglRotatef(ent->angles[PITCH], 0, 1, 0);
+ qglRotatef(ent->angles[ROLL], 1, 0, 0);
}
// draw visible faces
// FIXME: go by headnode instead?
face = model->firstface;
count = model->numfaces;
- while( count-- ) {
- dot = PlaneDiffFast( transformed, face->plane );
- if( BSP_CullFace( face, dot ) ) {
+ while (count--) {
+ dot = PlaneDiffFast(transformed, face->plane);
+ if (BSP_CullFace(face, dot)) {
c.facesCulled++;
- } else if( face->drawflags & mask ) {
+ } else if (face->drawflags & mask) {
// FIXME: alpha faces are not supported
// on rotated or translated inline models
- GL_AddAlphaFace( face );
+ GL_AddAlphaFace(face);
} else {
- GL_AddSolidFace( face );
+ GL_AddSolidFace(face);
}
face++;
}
- if( gl_dynamic->integer ) {
+ if (gl_dynamic->integer) {
GL_EndLights();
}
@@ -392,23 +401,24 @@ void GL_DrawBspModel( mmodel_t *model ) {
#define NODE_CLIPPED 0
#define NODE_UNCLIPPED 15
-static inline qboolean GL_ClipNode( mnode_t *node, int *clipflags ) {
+static inline qboolean GL_ClipNode(mnode_t *node, int *clipflags)
+{
int flags = *clipflags;
int i, bits, mask;
-
- if( flags == NODE_UNCLIPPED ) {
+
+ if (flags == NODE_UNCLIPPED) {
return qtrue;
}
- for( i = 0, mask = 1; i < 4; i++, mask <<= 1 ) {
- if( flags & mask ) {
+ for (i = 0, mask = 1; i < 4; i++, mask <<= 1) {
+ if (flags & mask) {
continue;
}
- bits = BoxOnPlaneSide( node->mins, node->maxs,
- &glr.frustumPlanes[i] );
- if( bits == BOX_BEHIND ) {
+ bits = BoxOnPlaneSide(node->mins, node->maxs,
+ &glr.frustumPlanes[i]);
+ if (bits == BOX_BEHIND) {
return qfalse;
}
- if( bits == BOX_INFRONT ) {
+ if (bits == BOX_INFRONT) {
flags |= mask;
}
}
@@ -418,101 +428,106 @@ static inline qboolean GL_ClipNode( mnode_t *node, int *clipflags ) {
return qtrue;
}
-static inline void GL_DrawLeaf( mleaf_t *leaf ) {
+static inline void GL_DrawLeaf(mleaf_t *leaf)
+{
mface_t **face, **last;
- if( leaf->contents == CONTENTS_SOLID ) {
+ if (leaf->contents == CONTENTS_SOLID) {
return; // solid leaf
}
- if( glr.fd.areabits && !Q_IsBitSet( glr.fd.areabits, leaf->area ) ) {
+ if (glr.fd.areabits && !Q_IsBitSet(glr.fd.areabits, leaf->area)) {
return; // door blocks sight
}
last = leaf->firstleafface + leaf->numleaffaces;
- for( face = leaf->firstleafface; face < last; face++ ) {
+ for (face = leaf->firstleafface; face < last; face++) {
(*face)->drawframe = glr.drawframe;
}
c.leavesDrawn++;
}
-static inline void GL_AddGenericFace( mface_t *face ) {
- if( face->drawflags & SURF_SKY ) {
- R_AddSkySurface( face );
+static inline void GL_AddGenericFace(mface_t *face)
+{
+ if (face->drawflags & SURF_SKY) {
+ R_AddSkySurface(face);
return;
}
- if( face->drawflags & (SURF_TRANS33|SURF_TRANS66) ) {
- GL_AddAlphaFace( face );
+ if (face->drawflags & (SURF_TRANS33 | SURF_TRANS66)) {
+ GL_AddAlphaFace(face);
return;
}
- GL_AddSolidFace( face );
+ GL_AddSolidFace(face);
}
-static inline void GL_DrawNode( mnode_t *node, vec_t dot ) {
+static inline void GL_DrawNode(mnode_t *node, vec_t dot)
+{
mface_t *face, *last = node->firstface + node->numfaces;
- for( face = node->firstface; face < last; face++ ) {
- if( face->drawframe != glr.drawframe ) {
+ for (face = node->firstface; face < last; face++) {
+ if (face->drawframe != glr.drawframe) {
continue;
}
- if( BSP_CullFace( face, dot ) ) {
+ if (BSP_CullFace(face, dot)) {
c.facesCulled++;
} else {
- GL_AddGenericFace( face );
+ GL_AddGenericFace(face);
}
}
c.nodesDrawn++;
}
-static void GL_WorldNode_r( mnode_t *node, int clipflags ) {
+static void GL_WorldNode_r(mnode_t *node, int clipflags)
+{
int side;
vec_t dot;
- while( node->visframe == glr.visframe ) {
- if( !GL_ClipNode( node, &clipflags ) ) {
+ while (node->visframe == glr.visframe) {
+ if (!GL_ClipNode(node, &clipflags)) {
c.nodesCulled++;
break;
}
- if( !node->plane ) {
- GL_DrawLeaf( ( mleaf_t * )node );
+ if (!node->plane) {
+ GL_DrawLeaf((mleaf_t *)node);
break;
}
- dot = PlaneDiffFast( glr.fd.vieworg, node->plane );
+ dot = PlaneDiffFast(glr.fd.vieworg, node->plane);
side = dot < 0;
- GL_WorldNode_r( node->children[side], clipflags );
+ GL_WorldNode_r(node->children[side], clipflags);
- GL_DrawNode( node, dot );
+ GL_DrawNode(node, dot);
- node = node->children[ side ^ 1 ];
+ node = node->children[side ^ 1];
}
}
-void GL_DrawWorld( void ) {
+void GL_DrawWorld(void)
+{
GL_MarkLeaves();
#if USE_DLIGHTS
glr.dlightframe++;
- if( gl_dynamic->integer == 1 ) {
+ if (gl_dynamic->integer == 1) {
GL_MarkLights();
}
#endif
-
+
R_ClearSkyBox();
- if( gl_dynamic->integer ) {
+ if (gl_dynamic->integer) {
GL_BeginLights();
}
- GL_WorldNode_r( gl_static.world.cache->nodes,
- gl_cull_nodes->integer ? NODE_CLIPPED : NODE_UNCLIPPED );
+ GL_WorldNode_r(gl_static.world.cache->nodes,
+ gl_cull_nodes->integer ? NODE_CLIPPED : NODE_UNCLIPPED);
- if( gl_dynamic->integer ) {
+ if (gl_dynamic->integer) {
GL_EndLights();
}
diff --git a/src/in_dx.c b/src/in_dx.c
index 347ed9a..22b9a09 100644
--- a/src/in_dx.c
+++ b/src/in_dx.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,7 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static HMODULE hDirectInput;
-typedef HRESULT (WINAPI *LPDIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT *, LPUNKNOWN );
+typedef HRESULT(WINAPI *LPDIRECTINPUTCREATE)(HINSTANCE, DWORD, LPDIRECTINPUT *, LPUNKNOWN);
static LPDIRECTINPUTCREATE pDirectInputCreate;
@@ -43,41 +43,41 @@ static qboolean di_initialized;
static LPDIRECTINPUT di;
static LPDIRECTINPUTDEVICE di_mouse;
-#define DEFINE_STATIC_GUID( name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8 ) \
+#define DEFINE_STATIC_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
static const GUID _##name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
-DEFINE_STATIC_GUID( GUID_SysMouse, 0x6F1D2B60, 0xD5A0, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
-DEFINE_STATIC_GUID( GUID_XAxis, 0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
-DEFINE_STATIC_GUID( GUID_YAxis, 0xA36D02E1, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
-DEFINE_STATIC_GUID( GUID_ZAxis, 0xA36D02E2, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
+DEFINE_STATIC_GUID(GUID_SysMouse, 0x6F1D2B60, 0xD5A0, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
+DEFINE_STATIC_GUID(GUID_XAxis, 0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
+DEFINE_STATIC_GUID(GUID_YAxis, 0xA36D02E1, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
+DEFINE_STATIC_GUID(GUID_ZAxis, 0xA36D02E2, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
static const DIOBJECTDATAFORMAT mouseObjectDataFormat[] = {
- { &_GUID_XAxis, DIMOFS_X, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 },
- { &_GUID_YAxis, DIMOFS_Y, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 },
- { &_GUID_ZAxis, DIMOFS_Z, DIDFT_RELAXIS|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON0, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0 },
- { NULL, DIMOFS_BUTTON1, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0 },
- { NULL, DIMOFS_BUTTON2, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON3, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON4, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON5, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON6, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
- { NULL, DIMOFS_BUTTON7, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 }
+ { &_GUID_XAxis, DIMOFS_X, DIDFT_RELAXIS | DIDFT_ANYINSTANCE, 0 },
+ { &_GUID_YAxis, DIMOFS_Y, DIDFT_RELAXIS | DIDFT_ANYINSTANCE, 0 },
+ { &_GUID_ZAxis, DIMOFS_Z, DIDFT_RELAXIS | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON0, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIMOFS_BUTTON1, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIMOFS_BUTTON2, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON3, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON4, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON5, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON6, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 },
+ { NULL, DIMOFS_BUTTON7, DIDFT_BUTTON | DIDFT_ANYINSTANCE | DIDFT_OPTIONAL, 0 }
};
static const DIDATAFORMAT mouseDataFormat = {
- sizeof( DIDATAFORMAT ),
- sizeof( DIOBJECTDATAFORMAT ),
+ sizeof(DIDATAFORMAT),
+ sizeof(DIOBJECTDATAFORMAT),
DIDF_RELAXIS,
- sizeof( DIMOUSESTATE2 ),
- sizeof( mouseObjectDataFormat ) / sizeof( mouseObjectDataFormat[0] ),
- ( LPDIOBJECTDATAFORMAT )mouseObjectDataFormat
+ sizeof(DIMOUSESTATE2),
+ sizeof(mouseObjectDataFormat) / sizeof(mouseObjectDataFormat[0]),
+ (LPDIOBJECTDATAFORMAT)mouseObjectDataFormat
};
static const DIPROPDWORD mouseBufferSize = {
{
- sizeof( DIPROPDWORD ),
- sizeof( DIPROPHEADER ),
+ sizeof(DIPROPDWORD),
+ sizeof(DIPROPHEADER),
0,
DIPH_DEVICE
},
@@ -89,31 +89,32 @@ static const DIPROPDWORD mouseBufferSize = {
DI_GetMouseEvents
===========
*/
-static void DI_GetMouseEvents( void ) {
+static void DI_GetMouseEvents(void)
+{
DIDEVICEOBJECTDATA data[16];
LPDIDEVICEOBJECTDATA p, last;
DWORD numElements, button;
int value;
HRESULT hr;
- if( di_grabbed != IN_GRAB ) {
+ if (di_grabbed != IN_GRAB) {
return;
}
do {
numElements = 16;
- hr = IDirectInputDevice_GetDeviceData( di_mouse, sizeof( data[0] ), data, &numElements, 0 );
- if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) {
- IDirectInputDevice_Acquire( di_mouse );
+ hr = IDirectInputDevice_GetDeviceData(di_mouse, sizeof(data[0]), data, &numElements, 0);
+ if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) {
+ IDirectInputDevice_Acquire(di_mouse);
return;
}
- if( FAILED( hr ) ) {
- Com_EPrintf( "GetDeviceData failed with error 0x%lX\n", hr );
+ if (FAILED(hr)) {
+ Com_EPrintf("GetDeviceData failed with error 0x%lX\n", hr);
return;
}
last = data + numElements;
- for( p = data; p < last; p++ ) {
- switch( p->dwOfs ) {
+ for (p = data; p < last; p++) {
+ switch (p->dwOfs) {
case DIMOFS_BUTTON0:
case DIMOFS_BUTTON1:
case DIMOFS_BUTTON2:
@@ -122,31 +123,31 @@ static void DI_GetMouseEvents( void ) {
case DIMOFS_BUTTON5:
case DIMOFS_BUTTON6:
case DIMOFS_BUTTON7:
- button = p->dwOfs - DIMOFS_BUTTON0;
- if( p->dwData & 0x80 ) {
- Key_Event( K_MOUSE1 + button, qtrue, p->dwTimeStamp );
+ button = p->dwOfs - DIMOFS_BUTTON0;
+ if (p->dwData & 0x80) {
+ Key_Event(K_MOUSE1 + button, qtrue, p->dwTimeStamp);
} else {
- Key_Event( K_MOUSE1 + button, qfalse, p->dwTimeStamp );
+ Key_Event(K_MOUSE1 + button, qfalse, p->dwTimeStamp);
}
break;
case DIMOFS_Z:
value = p->dwData;
- if( !value ) {
+ if (!value) {
break;
}
- if( value > 0 ) {
- Key_Event( K_MWHEELUP, qtrue, p->dwTimeStamp );
- Key_Event( K_MWHEELUP, qfalse, p->dwTimeStamp );
+ if (value > 0) {
+ Key_Event(K_MWHEELUP, qtrue, p->dwTimeStamp);
+ Key_Event(K_MWHEELUP, qfalse, p->dwTimeStamp);
} else {
- Key_Event( K_MWHEELDOWN, qtrue, p->dwTimeStamp );
- Key_Event( K_MWHEELDOWN, qfalse, p->dwTimeStamp );
+ Key_Event(K_MWHEELDOWN, qtrue, p->dwTimeStamp);
+ Key_Event(K_MWHEELDOWN, qfalse, p->dwTimeStamp);
}
break;
default:
break;
}
}
- } while( hr == DI_BUFFEROVERFLOW );
+ } while (hr == DI_BUFFEROVERFLOW);
}
/*
@@ -154,17 +155,18 @@ static void DI_GetMouseEvents( void ) {
DI_GetMouseMotion
===========
*/
-static qboolean DI_GetMouseMotion( int *dx, int *dy ) {
+static qboolean DI_GetMouseMotion(int *dx, int *dy)
+{
DIMOUSESTATE2 state;
HRESULT hr;
- if( di_grabbed != IN_GRAB ) {
+ if (di_grabbed != IN_GRAB) {
return qfalse;
}
- hr = IDirectInputDevice_GetDeviceState( di_mouse, sizeof( state ), &state );
- if( FAILED( hr ) ) {
- Com_EPrintf( "GetDeviceState failed with error 0x%lX\n", hr );
+ hr = IDirectInputDevice_GetDeviceState(di_mouse, sizeof(state), &state);
+ if (FAILED(hr)) {
+ Com_EPrintf("GetDeviceState failed with error 0x%lX\n", hr);
return qfalse;
}
@@ -178,18 +180,19 @@ static qboolean DI_GetMouseMotion( int *dx, int *dy ) {
DI_ShutdownMouse
===========
*/
-static void DI_ShutdownMouse( void ) {
- Com_Printf( "Shutting down DirectInput\n" );
+static void DI_ShutdownMouse(void)
+{
+ Com_Printf("Shutting down DirectInput\n");
- if( di_mouse ) {
- if( di_grabbed ) {
- IDirectInputDevice_Unacquire( di_mouse );
+ if (di_mouse) {
+ if (di_grabbed) {
+ IDirectInputDevice_Unacquire(di_mouse);
}
- IDirectInputDevice_Release( di_mouse );
+ IDirectInputDevice_Release(di_mouse);
di_mouse = NULL;
}
- if( di ) {
- IDirectInput_Release( di );
+ if (di) {
+ IDirectInput_Release(di);
di = NULL;
}
di_grabbed = qfalse;
@@ -202,71 +205,72 @@ static void DI_ShutdownMouse( void ) {
DI_StartupMouse
===========
*/
-static qboolean DI_InitMouse( void ) {
+static qboolean DI_InitMouse(void)
+{
HRESULT hr;
- if( !win.wnd ) {
+ if (!win.wnd) {
return qfalse;
}
- Com_Printf( "Initializing DirectInput\n" );
+ Com_Printf("Initializing DirectInput\n");
- if( !hDirectInput ) {
- hDirectInput = LoadLibrary( "dinput.dll" );
- if( !hDirectInput ) {
- Com_EPrintf( "Failed to load dinput.dll\n" );
+ if (!hDirectInput) {
+ hDirectInput = LoadLibrary("dinput.dll");
+ if (!hDirectInput) {
+ Com_EPrintf("Failed to load dinput.dll\n");
return qfalse;
}
- pDirectInputCreate = ( LPDIRECTINPUTCREATE )
- GetProcAddress( hDirectInput, "DirectInputCreateA" );
- if( !pDirectInputCreate ) {
- Com_EPrintf( "Failed to obtain DirectInputCreate\n" );
+ pDirectInputCreate = (LPDIRECTINPUTCREATE)
+ GetProcAddress(hDirectInput, "DirectInputCreateA");
+ if (!pDirectInputCreate) {
+ Com_EPrintf("Failed to obtain DirectInputCreate\n");
goto fail;
}
}
- hr = pDirectInputCreate( hGlobalInstance, DIRECTINPUT_VERSION, &di, NULL );
- if( FAILED( hr ) ) {
- Com_EPrintf( "DirectInputCreate failed with error 0x%lX\n", hr );
+ hr = pDirectInputCreate(hGlobalInstance, DIRECTINPUT_VERSION, &di, NULL);
+ if (FAILED(hr)) {
+ Com_EPrintf("DirectInputCreate failed with error 0x%lX\n", hr);
goto fail;
}
- hr = IDirectInput_CreateDevice( di, &_GUID_SysMouse, &di_mouse, NULL );
- if( FAILED( hr ) ) {
- Com_EPrintf( "CreateDevice failed with error 0x%lX\n", hr );
+ hr = IDirectInput_CreateDevice(di, &_GUID_SysMouse, &di_mouse, NULL);
+ if (FAILED(hr)) {
+ Com_EPrintf("CreateDevice failed with error 0x%lX\n", hr);
goto fail;
}
- hr = IDirectInputDevice_SetDataFormat( di_mouse, &mouseDataFormat );
- if( FAILED( hr ) ) {
- Com_EPrintf( "SetDataFormat failed with error 0x%lX\n", hr );
+ hr = IDirectInputDevice_SetDataFormat(di_mouse, &mouseDataFormat);
+ if (FAILED(hr)) {
+ Com_EPrintf("SetDataFormat failed with error 0x%lX\n", hr);
goto fail;
}
- hr = IDirectInputDevice_SetCooperativeLevel( di_mouse, win.wnd, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
- if( FAILED( hr ) ) {
- Com_EPrintf( "SetCooperativeLevel failed with error 0x%lX\n", hr );
+ hr = IDirectInputDevice_SetCooperativeLevel(di_mouse, win.wnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
+ if (FAILED(hr)) {
+ Com_EPrintf("SetCooperativeLevel failed with error 0x%lX\n", hr);
goto fail;
}
- hr = IDirectInputDevice_SetProperty( di_mouse, DIPROP_BUFFERSIZE, &mouseBufferSize.diph );
- if( FAILED( hr ) ) {
- Com_EPrintf( "SetProperty failed with error 0x%lX\n", hr );
+ hr = IDirectInputDevice_SetProperty(di_mouse, DIPROP_BUFFERSIZE, &mouseBufferSize.diph);
+ if (FAILED(hr)) {
+ Com_EPrintf("SetProperty failed with error 0x%lX\n", hr);
goto fail;
}
di_initialized = qtrue;
-
+
return qtrue;
fail:
- if( di_mouse ) {
- IDirectInputDevice_Release( di_mouse );
+ if (di_mouse) {
+ IDirectInputDevice_Release(di_mouse);
di_mouse = NULL;
}
- if( di ) {
- IDirectInput_Release( di );
+ if (di) {
+ IDirectInput_Release(di);
di = NULL;
}
return qfalse;
@@ -277,28 +281,29 @@ fail:
DI_GrabMouse
===========
*/
-static void DI_GrabMouse( grab_t grab ) {
+static void DI_GrabMouse(grab_t grab)
+{
HRESULT hr;
- if( !di_initialized ) {
+ if (!di_initialized) {
return;
}
- if( di_grabbed == grab ) {
+ if (di_grabbed == grab) {
return;
}
- if( grab == IN_GRAB ) {
- Com_DPrintf( "IDirectInputDevice_Acquire\n" );
- hr = IDirectInputDevice_Acquire( di_mouse );
- if( FAILED( hr ) ) {
- Com_EPrintf( "Failed to acquire mouse, error 0x%lX\n", hr );
+ if (grab == IN_GRAB) {
+ Com_DPrintf("IDirectInputDevice_Acquire\n");
+ hr = IDirectInputDevice_Acquire(di_mouse);
+ if (FAILED(hr)) {
+ Com_EPrintf("Failed to acquire mouse, error 0x%lX\n", hr);
}
} else {
- Com_DPrintf( "IDirectInputDevice_Unacquire\n" );
- hr = IDirectInputDevice_Unacquire( di_mouse );
- if( FAILED( hr ) ) {
- Com_EPrintf( "Failed to unacquire mouse, error 0x%lX\n", hr );
+ Com_DPrintf("IDirectInputDevice_Unacquire\n");
+ hr = IDirectInputDevice_Unacquire(di_mouse);
+ if (FAILED(hr)) {
+ Com_EPrintf("Failed to unacquire mouse, error 0x%lX\n", hr);
}
}
@@ -311,7 +316,8 @@ static void DI_GrabMouse( grab_t grab ) {
DI_FillAPI
@@@@@@@@@@@@@@@@@@@
*/
-void DI_FillAPI( inputAPI_t *api ) {
+void DI_FillAPI(inputAPI_t *api)
+{
api->Init = DI_InitMouse;
api->Shutdown = DI_ShutdownMouse;
api->Grab = DI_GrabMouse;
diff --git a/src/in_evdev.c b/src/in_evdev.c
index 5d38503..8013f1b 100644
--- a/src/in_evdev.c
+++ b/src/in_evdev.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -40,10 +40,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <libudev.h>
#endif
-#define FOR_EACH_EVDEV( dev ) \
- LIST_FOR_EACH( evdev_t, dev, &evdev.devices, entry )
-#define FOR_EACH_EVDEV_SAFE( dev, next ) \
- LIST_FOR_EACH_SAFE( evdev_t, dev, next, &evdev.devices, entry )
+#define FOR_EACH_EVDEV(dev) \
+ LIST_FOR_EACH(evdev_t, dev, &evdev.devices, entry)
+#define FOR_EACH_EVDEV_SAFE(dev, next) \
+ LIST_FOR_EACH_SAFE(evdev_t, dev, next, &evdev.devices, entry)
typedef struct {
list_t entry;
@@ -59,75 +59,77 @@ static struct {
} evdev;
#define MAX_EVENTS 64
-#define EVENT_SIZE sizeof( struct input_event )
-
-static void evdev_remove( evdev_t *dev ) {
- IO_Remove( dev->fd );
- close( dev->fd );
- List_Remove( &dev->entry );
- Z_Free( dev );
+#define EVENT_SIZE sizeof(struct input_event)
+
+static void evdev_remove(evdev_t *dev)
+{
+ IO_Remove(dev->fd);
+ close(dev->fd);
+ List_Remove(&dev->entry);
+ Z_Free(dev);
}
-static void evdev_read( evdev_t *dev ) {
+static void evdev_read(evdev_t *dev)
+{
struct input_event ev[MAX_EVENTS];
ssize_t bytes;
size_t i, count;
unsigned button, time;
#if 0
- if( !dev->io->canread ) {
+ if (!dev->io->canread) {
return;
}
#endif
- bytes = read( dev->fd, ev, EVENT_SIZE * MAX_EVENTS );
- if( bytes == -1 ) {
- if( errno == EAGAIN || errno == EINTR ) {
+ bytes = read(dev->fd, ev, EVENT_SIZE * MAX_EVENTS);
+ if (bytes == -1) {
+ if (errno == EAGAIN || errno == EINTR) {
return;
}
- Com_EPrintf( "Couldn't read event: %s\n", strerror( errno ) );
- evdev_remove( dev );
+ Com_EPrintf("Couldn't read event: %s\n", strerror(errno));
+ evdev_remove(dev);
return;
}
- if( bytes < EVENT_SIZE ) {
+ if (bytes < EVENT_SIZE) {
return; // should not happen
}
count = bytes / EVENT_SIZE;
- for( i = 0 ; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
time = ev[i].time.tv_sec * 1000 + ev[i].time.tv_usec / 1000;
- switch( ev[i].type ) {
+ switch (ev[i].type) {
case EV_KEY:
- if( ev[i].code >= BTN_MOUSE && ev[i].code < BTN_MOUSE + 8 ) {
+ if (ev[i].code >= BTN_MOUSE && ev[i].code < BTN_MOUSE + 8) {
button = K_MOUSE1 + ev[i].code - BTN_MOUSE;
- Key_Event( button, !!ev[i].value, time );
+ Key_Event(button, !!ev[i].value, time);
}
break;
- case EV_REL:
- switch( ev[i].code ) {
- case REL_X:
- evdev.dx += ( int )ev[i].value;
- break;
- case REL_Y:
- evdev.dy += ( int )ev[i].value;
- break;
- case REL_WHEEL:
- if( ( int )ev[i].value == 1 ) {
- Key_Event( K_MWHEELUP, qtrue, time );
- Key_Event( K_MWHEELUP, qfalse, time );
- } else if( ( int )ev[i].value == -1 ) {
- Key_Event( K_MWHEELDOWN, qtrue, time );
- Key_Event( K_MWHEELDOWN, qfalse, time );
+ case EV_REL:
+ switch (ev[i].code) {
+ case REL_X:
+ evdev.dx += (int)ev[i].value;
+ break;
+ case REL_Y:
+ evdev.dy += (int)ev[i].value;
+ break;
+ case REL_WHEEL:
+ if ((int)ev[i].value == 1) {
+ Key_Event(K_MWHEELUP, qtrue, time);
+ Key_Event(K_MWHEELUP, qfalse, time);
+ } else if ((int)ev[i].value == -1) {
+ Key_Event(K_MWHEELDOWN, qtrue, time);
+ Key_Event(K_MWHEELDOWN, qfalse, time);
}
break;
case REL_HWHEEL:
- if( ( int )ev[i].value == 1 ) {
- Key_Event( K_MWHEELRIGHT, qtrue, time );
- Key_Event( K_MWHEELRIGHT, qfalse, time );
- } else if( ( int )ev[i].value == -1 ) {
- Key_Event( K_MWHEELLEFT, qtrue, time );
- Key_Event( K_MWHEELLEFT, qfalse, time );
+ if ((int)ev[i].value == 1) {
+ Key_Event(K_MWHEELRIGHT, qtrue, time);
+ Key_Event(K_MWHEELRIGHT, qfalse, time);
+ } else if ((int)ev[i].value == -1) {
+ Key_Event(K_MWHEELLEFT, qtrue, time);
+ Key_Event(K_MWHEELLEFT, qfalse, time);
}
break;
default:
@@ -140,20 +142,22 @@ static void evdev_read( evdev_t *dev ) {
}
}
-static void GetMouseEvents( void ) {
+static void GetMouseEvents(void)
+{
evdev_t *dev, *next;
- if( !evdev.initialized || !evdev.grabbed ) {
+ if (!evdev.initialized || !evdev.grabbed) {
return;
}
- FOR_EACH_EVDEV_SAFE( dev, next ) {
- evdev_read( dev );
+ FOR_EACH_EVDEV_SAFE(dev, next) {
+ evdev_read(dev);
}
}
-static qboolean GetMouseMotion( int *dx, int *dy ) {
- if( !evdev.initialized || !evdev.grabbed ) {
+static qboolean GetMouseMotion(int *dx, int *dy)
+{
+ if (!evdev.initialized || !evdev.grabbed) {
return qfalse;
}
@@ -164,50 +168,53 @@ static qboolean GetMouseMotion( int *dx, int *dy ) {
return qtrue;
}
-static void ShutdownMouse( void ) {
+static void ShutdownMouse(void)
+{
evdev_t *dev, *next;
- if( !evdev.initialized ) {
+ if (!evdev.initialized) {
return;
}
- FOR_EACH_EVDEV_SAFE( dev, next ) {
- evdev_remove( dev );
+ FOR_EACH_EVDEV_SAFE(dev, next) {
+ evdev_remove(dev);
}
#if USE_SDL
- SDL_ShowCursor( SDL_ENABLE );
- SDL_WM_GrabInput( SDL_GRAB_OFF );
- SDL_WM_SetCaption( PRODUCT, APPLICATION );
+ SDL_ShowCursor(SDL_ENABLE);
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_WM_SetCaption(PRODUCT, APPLICATION);
#endif
- memset( &evdev, 0, sizeof( evdev ) );
+ memset(&evdev, 0, sizeof(evdev));
}
-static evdev_t *evdev_add( const char *path ) {
+static evdev_t *evdev_add(const char *path)
+{
evdev_t *dev;
int fd;
- fd = open( path, O_RDONLY );
- if( fd == -1 ) {
- Com_EPrintf( "Couldn't open %s: %s\n", path, strerror( errno ) );
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ Com_EPrintf("Couldn't open %s: %s\n", path, strerror(errno));
return NULL;
}
- Com_DPrintf( "Adding device %s\n", path );
+ Com_DPrintf("Adding device %s\n", path);
- fcntl( fd, F_SETFL, fcntl( fd, F_GETFL, 0 ) | FNDELAY );
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FNDELAY);
- dev = Z_Malloc( sizeof( *dev ) );
+ dev = Z_Malloc(sizeof(*dev));
dev->fd = fd;
- dev->io = IO_Add( fd );
- List_Append( &evdev.devices, &dev->entry );
+ dev->io = IO_Add(fd);
+ List_Append(&evdev.devices, &dev->entry);
return dev;
}
#if USE_UDEV
-static void auto_add_devices( void ) {
+static void auto_add_devices(void)
+{
struct udev *udev;
struct udev_enumerate *enumerate;
struct udev_list_entry *list, *entry;
@@ -215,44 +222,45 @@ static void auto_add_devices( void ) {
const char *path;
udev = udev_new();
- if( !udev ) {
- Com_EPrintf( "Couldn't create udev handle\n" );
+ if (!udev) {
+ Com_EPrintf("Couldn't create udev handle\n");
return;
}
- enumerate = udev_enumerate_new( udev );
- udev_enumerate_add_match_subsystem( enumerate, "input" );
- udev_enumerate_add_match_sysname( enumerate, "event[0-9]*" );
- udev_enumerate_add_match_property( enumerate, "ID_INPUT_MOUSE", "1" );
- udev_enumerate_scan_devices( enumerate );
- list = udev_enumerate_get_list_entry( enumerate );
- udev_list_entry_foreach( entry, list ) {
- path = udev_list_entry_get_name( entry );
- dev = udev_device_new_from_syspath( udev, path );
- if( dev ) {
- path = udev_device_get_devnode( dev );
- if( path ) {
- evdev_add( path );
+ enumerate = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(enumerate, "input");
+ udev_enumerate_add_match_sysname(enumerate, "event[0-9]*");
+ udev_enumerate_add_match_property(enumerate, "ID_INPUT_MOUSE", "1");
+ udev_enumerate_scan_devices(enumerate);
+ list = udev_enumerate_get_list_entry(enumerate);
+ udev_list_entry_foreach(entry, list) {
+ path = udev_list_entry_get_name(entry);
+ dev = udev_device_new_from_syspath(udev, path);
+ if (dev) {
+ path = udev_device_get_devnode(dev);
+ if (path) {
+ evdev_add(path);
}
- udev_device_unref( dev );
+ udev_device_unref(dev);
}
}
- udev_enumerate_unref( enumerate );
- udev_unref( udev );
+ udev_enumerate_unref(enumerate);
+ udev_unref(udev);
}
#endif
-static qboolean InitMouse( void ) {
+static qboolean InitMouse(void)
+{
cvar_t *var;
- List_Init( &evdev.devices );
+ List_Init(&evdev.devices);
+
+ var = Cvar_Get("in_device", "", 0);
- var = Cvar_Get( "in_device", "", 0 );
-
- if( var->string[0] ) {
+ if (var->string[0]) {
// add user specified device
- if( !evdev_add( var->string ) ) {
+ if (!evdev_add(var->string)) {
return qfalse;
}
} else {
@@ -260,72 +268,73 @@ static qboolean InitMouse( void ) {
// find devices automatically
auto_add_devices();
- if( LIST_EMPTY( &evdev.devices ) ) {
+ if (LIST_EMPTY(&evdev.devices)) {
Com_EPrintf(
"Automatic libudev scan was unable to find any "
"usable mouse device. You may need to set the "
"'in_device' variable manually before direct "
- "mouse input can be used.\n" );
+ "mouse input can be used.\n");
return qfalse;
}
#else
Com_EPrintf(
"No input device specified, and libudev support "
"is not compiled in. Please set the 'in_device' variable "
- "manually before direct mouse input can be used.\n" );
+ "manually before direct mouse input can be used.\n");
return qfalse;
#endif
}
- Com_Printf( "Evdev mouse initialized.\n" );
+ Com_Printf("Evdev mouse initialized.\n");
evdev.initialized = qtrue;
return qtrue;
}
-static void GrabMouse( grab_t grab ) {
+static void GrabMouse(grab_t grab)
+{
struct input_event ev;
evdev_t *dev;
- if( !evdev.initialized ) {
+ if (!evdev.initialized) {
return;
}
- if( evdev.grabbed == grab ) {
+ if (evdev.grabbed == grab) {
evdev.dx = 0;
evdev.dy = 0;
return;
}
- if( grab == IN_GRAB ) {
+ if (grab == IN_GRAB) {
#if USE_SDL
- SDL_WM_GrabInput( SDL_GRAB_ON );
- SDL_WM_SetCaption( "[" PRODUCT "]", APPLICATION );
- SDL_ShowCursor( SDL_DISABLE );
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ SDL_WM_SetCaption("[" PRODUCT "]", APPLICATION);
+ SDL_ShowCursor(SDL_DISABLE);
#endif
} else {
#if USE_SDL
- if( evdev.grabbed == IN_GRAB ) {
- SDL_WM_GrabInput( SDL_GRAB_OFF );
- SDL_WM_SetCaption( PRODUCT, APPLICATION );
+ if (evdev.grabbed == IN_GRAB) {
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_WM_SetCaption(PRODUCT, APPLICATION);
}
- if( grab == IN_HIDE ) {
- SDL_ShowCursor( SDL_DISABLE );
+ if (grab == IN_HIDE) {
+ SDL_ShowCursor(SDL_DISABLE);
} else {
- SDL_ShowCursor( SDL_ENABLE );
+ SDL_ShowCursor(SDL_ENABLE);
}
#endif
}
- FOR_EACH_EVDEV( dev ) {
- if( !grab ) {
+ FOR_EACH_EVDEV(dev) {
+ if (!grab) {
dev->io->wantread = qfalse;
continue;
}
// pump pending events
dev->io->wantread = qtrue;
- while( read( dev->fd, &ev, EVENT_SIZE ) == EVENT_SIZE )
+ while (read(dev->fd, &ev, EVENT_SIZE) == EVENT_SIZE)
;
}
@@ -334,9 +343,10 @@ static void GrabMouse( grab_t grab ) {
evdev.grabbed = grab;
}
-static void WarpMouse( int x, int y ) {
+static void WarpMouse(int x, int y)
+{
#if USE_SDL
- SDL_WarpMouse( x, y );
+ SDL_WarpMouse(x, y);
#endif
}
@@ -345,7 +355,8 @@ static void WarpMouse( int x, int y ) {
DI_FillAPI
@@@@@@@@@@@@@@@@@@@
*/
-void DI_FillAPI( inputAPI_t *api ) {
+void DI_FillAPI(inputAPI_t *api)
+{
api->Init = InitMouse;
api->Shutdown = ShutdownMouse;
api->Grab = GrabMouse;
diff --git a/src/in_lirc.c b/src/in_lirc.c
index 0af53e5..287d4d2 100644
--- a/src/in_lirc.c
+++ b/src/in_lirc.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -43,90 +43,93 @@ static struct {
ioentry_t *io;
} lirc;
-void Lirc_GetEvents( void ) {
+void Lirc_GetEvents(void)
+{
char *code, *str;
int ret, key;
unsigned time;
- if( !lirc.initialized || !lirc.io->canread ) {
+ if (!lirc.initialized || !lirc.io->canread) {
return;
}
- while( ( ret = lirc_nextcode( &code ) ) == 0 && code ) {
+ while ((ret = lirc_nextcode(&code)) == 0 && code) {
time = Sys_Milliseconds();
- Com_DPrintf( "%s: %u %s\n", __func__, time, code );
- while( ( ret = lirc_code2char( lirc.config, code, &str ) ) == 0 && str ) {
- if( *str == '@' ) {
- key = Key_StringToKeynum( str + 1 );
- if( key > 0 ) {
- Key_Event( key, qtrue, time );
- Key_Event( key, qfalse, time );
+ Com_DPrintf("%s: %u %s\n", __func__, time, code);
+ while ((ret = lirc_code2char(lirc.config, code, &str)) == 0 && str) {
+ if (*str == '@') {
+ key = Key_StringToKeynum(str + 1);
+ if (key > 0) {
+ Key_Event(key, qtrue, time);
+ Key_Event(key, qfalse, time);
}
} else {
- Cbuf_AddText( &cmd_buffer, str );
- Cbuf_AddText( &cmd_buffer, "\n" );
+ Cbuf_AddText(&cmd_buffer, str);
+ Cbuf_AddText(&cmd_buffer, "\n");
}
}
- free( code );
- if( ret ) {
+ free(code);
+ if (ret) {
goto error;
}
}
- if( ret ) {
+ if (ret) {
error:
- Com_EPrintf( "Error reading from LIRC.\n" );
- Cvar_Reset( lirc_enable );
+ Com_EPrintf("Error reading from LIRC.\n");
+ Cvar_Reset(lirc_enable);
Lirc_Shutdown();
}
}
-void Lirc_Shutdown( void ) {
- if( !lirc.initialized ) {
+void Lirc_Shutdown(void)
+{
+ if (!lirc.initialized) {
return;
}
- lirc_freeconfig( lirc.config );
- IO_Remove( lirc.fd );
+ lirc_freeconfig(lirc.config);
+ IO_Remove(lirc.fd);
lirc_deinit();
- memset( &lirc, 0, sizeof( lirc ) );
+ memset(&lirc, 0, sizeof(lirc));
}
-static void lirc_param_changed( cvar_t *self ) {
+static void lirc_param_changed(cvar_t *self)
+{
Lirc_Shutdown();
Lirc_Init();
}
-qboolean Lirc_Init( void ) {
- lirc_enable = Cvar_Get( "lirc_enable", "0", 0 );
+qboolean Lirc_Init(void)
+{
+ lirc_enable = Cvar_Get("lirc_enable", "0", 0);
lirc_enable->changed = lirc_param_changed;
- lirc_config = Cvar_Get( "lirc_config", "", CVAR_NOSET );
+ lirc_config = Cvar_Get("lirc_config", "", CVAR_NOSET);
//lirc_config->changed = lirc_param_changed;
- if( !lirc_enable->integer ) {
+ if (!lirc_enable->integer) {
return qfalse;
}
- lirc.fd = lirc_init( APPLICATION, 0 );
- if( lirc.fd == -1 ) {
- Com_EPrintf( "Failed to initialize LIRC.\n" );
- Cvar_Reset( lirc_enable );
+ lirc.fd = lirc_init(APPLICATION, 0);
+ if (lirc.fd == -1) {
+ Com_EPrintf("Failed to initialize LIRC.\n");
+ Cvar_Reset(lirc_enable);
return qfalse;
}
- if( lirc_readconfig( lirc_config->string[0] ? lirc_config->string : NULL,
- &lirc.config, NULL ) != 0 )
- {
- Com_EPrintf( "Failed to read LIRC config.\n" );
+ if (lirc_readconfig(lirc_config->string[0] ? lirc_config->string : NULL,
+ &lirc.config, NULL) != 0) {
+ Com_EPrintf("Failed to read LIRC config.\n");
lirc_deinit();
- Cvar_Reset( lirc_enable );
+ Cvar_Reset(lirc_enable);
return qfalse;
}
-
- fcntl( lirc.fd, F_SETFL, fcntl( lirc.fd, F_GETFL, 0 ) | FNDELAY );
- lirc.io = IO_Add( lirc.fd );
+
+ fcntl(lirc.fd, F_SETFL, fcntl(lirc.fd, F_GETFL, 0) | FNDELAY);
+ lirc.io = IO_Add(lirc.fd);
lirc.io->wantread = qtrue;
- Com_Printf( "LIRC interface initialized.\n" );
+ Com_Printf("LIRC interface initialized.\n");
lirc.initialized = qtrue;
return qtrue;
diff --git a/src/in_lirc.h b/src/in_lirc.h
index 72d628f..23de418 100644
--- a/src/in_lirc.h
+++ b/src/in_lirc.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -18,6 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-void Lirc_GetEvents( void );
-void Lirc_Shutdown( void );
-qboolean Lirc_Init( void );
+void Lirc_GetEvents(void);
+void Lirc_Shutdown(void);
+qboolean Lirc_Init(void);
diff --git a/src/in_public.h b/src/in_public.h
index e1b09cb..cbb53f4 100644
--- a/src/in_public.h
+++ b/src/in_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -30,16 +30,16 @@ typedef enum {
} grab_t;
typedef struct inputAPI_s {
- qboolean (*Init)( void );
- void (*Shutdown)( void );
- void (*Grab)( grab_t grab );
- void (*Warp)( int x, int y );
- void (*GetEvents)( void );
- qboolean (*GetMotion)( int *dx, int *dy );
+ qboolean (*Init)(void);
+ void (*Shutdown)(void);
+ void (*Grab)(grab_t grab);
+ void (*Warp)(int x, int y);
+ void (*GetEvents)(void);
+ qboolean(*GetMotion)(int *dx, int *dy);
} inputAPI_t;
-void VID_FillInputAPI( inputAPI_t *api );
+void VID_FillInputAPI(inputAPI_t *api);
#if USE_DINPUT
-void DI_FillAPI( inputAPI_t *api );
+void DI_FillAPI(inputAPI_t *api);
#endif
diff --git a/src/io_sleep.c b/src/io_sleep.c
index d4728c6..3116e44 100644
--- a/src/io_sleep.c
+++ b/src/io_sleep.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -35,20 +35,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static ioentry_t entries[FD_SETSIZE];
static int numfds;
-ioentry_t *IO_Add( int fd ) {
+ioentry_t *IO_Add(int fd)
+{
ioentry_t *e;
#ifdef _WIN32
int i;
- for( i = 0, e = entries; i < numfds; i++, e++ ) {
- if( !e->inuse ) {
+ for (i = 0, e = entries; i < numfds; i++, e++) {
+ if (!e->inuse) {
break;
}
}
- if( i == numfds ) {
- if( ++numfds > FD_SETSIZE ) {
- Com_Error( ERR_FATAL, "%s: no more space for fd: %d", __func__, fd );
+ if (i == numfds) {
+ if (++numfds > FD_SETSIZE) {
+ Com_Error(ERR_FATAL, "%s: no more space for fd: %d", __func__, fd);
}
}
@@ -62,7 +63,7 @@ ioentry_t *IO_Add( int fd ) {
CHECK_FD
- if( fd >= numfds ) {
+ if (fd >= numfds) {
numfds = fd + 1;
}
@@ -72,16 +73,17 @@ ioentry_t *IO_Add( int fd ) {
return e;
}
-void IO_Remove( int fd ) {
+void IO_Remove(int fd)
+{
ioentry_t *e;
int i;
- e = IO_Get( fd );
- memset( e, 0, sizeof( *e ) );
+ e = IO_Get(fd);
+ memset(e, 0, sizeof(*e));
- for( i = numfds - 1; i >= 0; i-- ) {
+ for (i = numfds - 1; i >= 0; i--) {
e = &entries[i];
- if( e->inuse ) {
+ if (e->inuse) {
break;
}
}
@@ -89,21 +91,22 @@ void IO_Remove( int fd ) {
numfds = i + 1;
}
-ioentry_t *IO_Get( int fd ) {
+ioentry_t *IO_Get(int fd)
+{
ioentry_t *e;
#ifdef _WIN32
int i;
- for( i = 0, e = entries; i < numfds; i++, e++ ) {
- if( !e->inuse ) {
+ for (i = 0, e = entries; i < numfds; i++, e++) {
+ if (!e->inuse) {
continue;
}
- if( e->fd == fd ) {
+ if (e->fd == fd) {
return e;
}
}
-
- Com_Error( ERR_FATAL, "%s: fd not found: %d", __func__, fd );
+
+ Com_Error(ERR_FATAL, "%s: fd not found: %d", __func__, fd);
#else
CHECK_FD
@@ -122,7 +125,8 @@ IO_Sleep
Sleeps msec or until some file descriptor is ready
====================
*/
-int IO_Sleep( int msec ) {
+int IO_Sleep(int msec)
+{
struct timeval timeout;
fd_set rfd, wfd;
#ifdef _WIN32
@@ -131,16 +135,16 @@ int IO_Sleep( int msec ) {
ioentry_t *e;
int i, ret;
- if( !numfds ) {
+ if (!numfds) {
// don't bother with select()
- Sys_Sleep( msec );
+ Sys_Sleep(msec);
return 0;
}
- FD_ZERO( &rfd );
- FD_ZERO( &wfd );
+ FD_ZERO(&rfd);
+ FD_ZERO(&wfd);
#ifdef _WIN32
- FD_ZERO( &efd );
+ FD_ZERO(&efd);
#endif
#ifdef _WIN32
@@ -149,64 +153,64 @@ int IO_Sleep( int msec ) {
#define FD i
#endif
- for( i = 0, e = entries; i < numfds; i++, e++ ) {
- if( !e->inuse ) {
+ for (i = 0, e = entries; i < numfds; i++, e++) {
+ if (!e->inuse) {
continue;
}
e->canread = qfalse;
- if( e->wantread ) {
- FD_SET( FD, &rfd );
+ if (e->wantread) {
+ FD_SET(FD, &rfd);
}
e->canwrite = qfalse;
- if( e->wantwrite ) {
- FD_SET( FD, &wfd );
+ if (e->wantwrite) {
+ FD_SET(FD, &wfd);
}
#ifdef _WIN32
e->canexcept = qfalse;
- if( e->wantexcept ) {
- FD_SET( FD, &efd );
+ if (e->wantexcept) {
+ FD_SET(FD, &efd);
}
#endif
}
timeout.tv_sec = msec / 1000;
- timeout.tv_usec = ( msec % 1000 ) * 1000;
+ timeout.tv_usec = (msec % 1000) * 1000;
- ret = select( numfds, &rfd, &wfd,
+ ret = select(numfds, &rfd, &wfd,
#ifdef _WIN32
- &efd,
+ & efd,
#else
- NULL,
+ NULL,
#endif
- &timeout );
- if( ret == -1 ) {
+ & timeout);
+ if (ret == -1) {
#ifdef _WIN32
// TODO: report WSA error
#else
- if( errno != EINTR ) {
- Com_EPrintf( "%s: %s\n", __func__, strerror( errno ) );
+ if (errno != EINTR) {
+ Com_EPrintf("%s: %s\n", __func__, strerror(errno));
}
#endif
return ret;
}
- if( !ret ) {
+ if (!ret) {
return ret;
}
- for( i = 0; i < numfds; i++ ) {
+ for (i = 0; i < numfds; i++) {
e = &entries[i];
- if( !e->inuse ) {
+ if (!e->inuse) {
continue;
}
- if( e->wantread && FD_ISSET( FD, &rfd ) ) {
+ if (e->wantread && FD_ISSET(FD, &rfd)) {
e->canread = qtrue;
}
- if( e->wantwrite && FD_ISSET( FD, &wfd ) ) {
+ if (e->wantwrite && FD_ISSET(FD, &wfd)) {
e->canwrite = qtrue;
}
#ifdef _WIN32
- if( e->wantexcept && FD_ISSET( FD, &efd ) ) {
+ if (e->wantexcept && FD_ISSET(FD, &efd)) {
e->canexcept = qtrue;
}
#endif
@@ -224,7 +228,8 @@ IO_Sleep
Sleeps msec or until some file descriptor from a given subset is ready
====================
*/
-int IO_Sleepv( int msec, ... ) {
+int IO_Sleepv(int msec, ...)
+{
va_list argptr;
struct timeval timeout;
fd_set rfd, wfd;
@@ -234,93 +239,93 @@ int IO_Sleepv( int msec, ... ) {
ioentry_t *e;
int i, ret;
- if( !numfds ) {
+ if (!numfds) {
// don't bother with select()
- Sys_Sleep( msec );
+ Sys_Sleep(msec);
return 0;
}
- FD_ZERO( &rfd );
- FD_ZERO( &wfd );
+ FD_ZERO(&rfd);
+ FD_ZERO(&wfd);
#ifdef _WIN32
- FD_ZERO( &efd );
+ FD_ZERO(&efd);
#endif
- va_start( argptr, msec );
- while( 1 ) {
- i = va_arg( argptr, int );
- if( i == -1 ) {
+ va_start(argptr, msec);
+ while (1) {
+ i = va_arg(argptr, int);
+ if (i == -1) {
break;
}
e = &entries[i];
- if( !e->inuse ) {
+ if (!e->inuse) {
continue;
}
e->canread = qfalse;
- if( e->wantread ) {
- FD_SET( FD, &rfd );
+ if (e->wantread) {
+ FD_SET(FD, &rfd);
}
e->canwrite = qfalse;
- if( e->wantwrite ) {
- FD_SET( FD, &wfd );
+ if (e->wantwrite) {
+ FD_SET(FD, &wfd);
}
#ifdef _WIN32
e->canexcept = qfalse;
- if( e->wantexcept ) {
- FD_SET( FD, &efd );
+ if (e->wantexcept) {
+ FD_SET(FD, &efd);
}
#endif
}
- va_end( argptr );
+ va_end(argptr);
timeout.tv_sec = msec / 1000;
- timeout.tv_usec = ( msec % 1000 ) * 1000;
+ timeout.tv_usec = (msec % 1000) * 1000;
- ret = select( numfds, &rfd, &wfd,
+ ret = select(numfds, &rfd, &wfd,
#ifdef _WIN32
- &efd,
+ & efd,
#else
- NULL,
+ NULL,
#endif
- &timeout );
- if( ret == -1 ) {
+ & timeout);
+ if (ret == -1) {
#ifdef _WIN32
// TODO: report WSA error
#else
- if( errno != EINTR ) {
- Com_EPrintf( "%s: %s\n", __func__, strerror( errno ) );
+ if (errno != EINTR) {
+ Com_EPrintf("%s: %s\n", __func__, strerror(errno));
}
#endif
return ret;
}
- if( !ret ) {
+ if (!ret) {
return ret;
}
- va_start( argptr, msec );
- while( 1 ) {
- i = va_arg( argptr, int );
- if( i == -1 ) {
+ va_start(argptr, msec);
+ while (1) {
+ i = va_arg(argptr, int);
+ if (i == -1) {
break;
}
e = &entries[i];
- if( !e->inuse ) {
+ if (!e->inuse) {
continue;
}
- if( e->wantread && FD_ISSET( FD, &rfd ) ) {
+ if (e->wantread && FD_ISSET(FD, &rfd)) {
e->canread = qtrue;
}
- if( e->wantwrite && FD_ISSET( FD, &wfd ) ) {
+ if (e->wantwrite && FD_ISSET(FD, &wfd)) {
e->canwrite = qtrue;
}
#ifdef _WIN32
- if( e->wantexcept && FD_ISSET( FD, &efd ) ) {
+ if (e->wantexcept && FD_ISSET(FD, &efd)) {
e->canexcept = qtrue;
}
#endif
}
- va_end( argptr );
+ va_end(argptr);
return ret;
}
diff --git a/src/io_sleep.h b/src/io_sleep.h
index d4746ca..fa80418 100644
--- a/src/io_sleep.h
+++ b/src/io_sleep.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -35,11 +35,11 @@ typedef struct {
#endif
} ioentry_t;
-ioentry_t *IO_Add( int fd );
-void IO_Remove( int fd );
-ioentry_t *IO_Get( int fd );
-int IO_Sleep( int msec );
+ioentry_t *IO_Add(int fd);
+void IO_Remove(int fd);
+ioentry_t *IO_Get(int fd);
+int IO_Sleep(int msec);
#if USE_AC_SERVER
-int IO_Sleepv( int msec, ... );
+int IO_Sleepv(int msec, ...);
#endif
diff --git a/src/key_public.h b/src/key_public.h
index 227ce91..b30aff0 100644
--- a/src/key_public.h
+++ b/src/key_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -111,27 +111,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef enum keydest_e {
KEY_GAME = 0,
- KEY_CONSOLE = ( 1 << 0 ),
- KEY_MESSAGE = ( 1 << 1 ),
- KEY_MENU = ( 1 << 2 )
+ KEY_CONSOLE = (1 << 0),
+ KEY_MESSAGE = (1 << 1),
+ KEY_MENU = (1 << 2)
} keydest_t;
-typedef qboolean (*keywaitcb_t)( void *arg, int key );
+typedef qboolean(*keywaitcb_t)(void *arg, int key);
-qboolean Key_GetOverstrikeMode( void );
-void Key_SetOverstrikeMode( qboolean overstrike );
-keydest_t Key_GetDest( void );
-void Key_SetDest( keydest_t dest );
+qboolean Key_GetOverstrikeMode(void);
+void Key_SetOverstrikeMode(qboolean overstrike);
+keydest_t Key_GetDest(void);
+void Key_SetDest(keydest_t dest);
-qboolean Key_IsDown( int key );
-qboolean Key_AnyKeyDown( void );
-void Key_ClearStates( void );
+qboolean Key_IsDown(int key);
+qboolean Key_AnyKeyDown(void);
+void Key_ClearStates(void);
-char *Key_KeynumToString ( int keynum );
-int Key_StringToKeynum( const char *str );
-void Key_SetBinding( int keynum, const char *binding );
-char *Key_GetBinding( const char *binding );
-int Key_EnumBindings( int key, const char *binding );
+char *Key_KeynumToString(int keynum);
+int Key_StringToKeynum(const char *str);
+void Key_SetBinding(int keynum, const char *binding);
+char *Key_GetBinding(const char *binding);
+int Key_EnumBindings(int key, const char *binding);
-void Key_WaitKey( keywaitcb_t wait, void *arg );
+void Key_WaitKey(keywaitcb_t wait, void *arg);
diff --git a/src/m_flash.c b/src/m_flash.c
index d06741a..4c115da 100644
--- a/src/m_flash.c
+++ b/src/m_flash.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful },
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,8 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// this file is included in both the game dll and quake2 },
// the game needs it to source shot locations, the client
// needs it to position muzzle flashes
-const vec3_t monster_flash_offset[256] =
-{
+const vec3_t monster_flash_offset[256] = {
// flash 0 is not used
{ 0.0, 0.0, 0.0 },
@@ -257,13 +256,13 @@ const vec3_t monster_flash_offset[256] =
// MZ2_MAKRON_BLASTER_2 103
{ -1.6, -19.3, 59.5 },
// MZ2_MAKRON_BLASTER_3 104
- { -0.1, -14.4, 59.5 },
+ { -0.1, -14.4, 59.5 },
// MZ2_MAKRON_BLASTER_4 105
- { 2.0, -7.6, 59.5 },
+ { 2.0, -7.6, 59.5 },
// MZ2_MAKRON_BLASTER_5 106
{ 3.4, 1.3, 59.5 },
// MZ2_MAKRON_BLASTER_6 107
- { 3.7, 11.1, 59.5 },
+ { 3.7, 11.1, 59.5 },
// MZ2_MAKRON_BLASTER_7 108
{ -0.3, 22.3, 59.5 },
// MZ2_MAKRON_BLASTER_8 109
@@ -281,7 +280,7 @@ const vec3_t monster_flash_offset[256] =
// MZ2_MAKRON_BLASTER_14 115
{ 5.9, -4.4, 59.5 },
// MZ2_MAKRON_BLASTER_15 116
- { 4.2, -14.1, 59.5 },
+ { 4.2, -14.1, 59.5 },
// MZ2_MAKRON_BLASTER_16 117
{ 2.4, -18.8, 59.5 },
// MZ2_MAKRON_BLASTER_17 118
@@ -290,29 +289,29 @@ const vec3_t monster_flash_offset[256] =
{ -17.3, 7.8, 72.4 },
// MZ2_JORG_MACHINEGUN_L1 120
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_L2 121
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_L3 122
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_L4 123
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_L5 124
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_L6 125
- { 78.5, -47.1, 96 },
+ { 78.5, -47.1, 96 },
// MZ2_JORG_MACHINEGUN_R1 126
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_MACHINEGUN_R2 127
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_MACHINEGUN_R3 128
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_MACHINEGUN_R4 129
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_MACHINEGUN_R5 130
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_MACHINEGUN_R6 131
- { 78.5, 46.7, 96 },
+ { 78.5, 46.7, 96 },
// MZ2_JORG_BFG_1 132
{ 6.3, -9, 111.2 },
@@ -351,23 +350,23 @@ const vec3_t monster_flash_offset[256] =
// MZ2_MEDIC_BLASTER_2 146
{ 12.1, 5.4, 16.5 },
// MZ2_CARRIER_RAILGUN 147
- { 32, 0, 6 },
+ { 32, 0, 6 },
// MZ2_WIDOW_DISRUPTOR 148
{ 57.72, 14.50, 88.81 },
// MZ2_WIDOW_BLASTER 149
{ 56, 32, 32 },
// MZ2_WIDOW_RAIL 150
- { 62, -20, 84 },
+ { 62, -20, 84 },
// MZ2_WIDOW_PLASMABEAM 151 // PMM - not used!
- { 32, 0, 6 },
+ { 32, 0, 6 },
// MZ2_CARRIER_MACHINEGUN_L2 152
{ 61, -32, 12 },
// MZ2_CARRIER_MACHINEGUN_R2 153
{ 61, 32, 12 },
// MZ2_WIDOW_RAIL_LEFT 154
- { 17, -62, 91 },
+ { 17, -62, 91 },
// MZ2_WIDOW_RAIL_RIGHT 155
- { 68, 12, 86 },
+ { 68, 12, 86 },
// MZ2_WIDOW_BLASTER_SWEEP1 156 pmm - the sweeps need to be in sequential order
{ 47.5, 56, 89 },
// MZ2_WIDOW_BLASTER_SWEEP2 157
diff --git a/src/mdfour.c b/src/mdfour.c
index 9706dbb..1fba891 100644
--- a/src/mdfour.c
+++ b/src/mdfour.c
@@ -59,40 +59,40 @@ static void mdfour64(uint32_t *M)
int j;
uint32_t AA, BB, CC, DD;
uint32_t X[16];
- uint32_t A,B,C,D;
+ uint32_t A, B, C, D;
- for (j=0;j<16;j++)
+ for (j = 0; j < 16; j++)
X[j] = M[j];
A = m->A; B = m->B; C = m->C; D = m->D;
AA = A; BB = B; CC = C; DD = D;
- ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7);
- ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19);
- ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7);
- ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19);
- ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7);
- ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19);
- ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7);
- ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19);
-
- ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5);
- ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13);
- ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5);
- ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13);
- ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5);
- ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13);
- ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5);
- ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13);
-
- ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9);
- ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15);
- ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9);
- ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15);
- ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9);
- ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15);
- ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9);
- ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15);
+ ROUND1(A, B, C, D, 0, 3); ROUND1(D, A, B, C, 1, 7);
+ ROUND1(C, D, A, B, 2, 11); ROUND1(B, C, D, A, 3, 19);
+ ROUND1(A, B, C, D, 4, 3); ROUND1(D, A, B, C, 5, 7);
+ ROUND1(C, D, A, B, 6, 11); ROUND1(B, C, D, A, 7, 19);
+ ROUND1(A, B, C, D, 8, 3); ROUND1(D, A, B, C, 9, 7);
+ ROUND1(C, D, A, B, 10, 11); ROUND1(B, C, D, A, 11, 19);
+ ROUND1(A, B, C, D, 12, 3); ROUND1(D, A, B, C, 13, 7);
+ ROUND1(C, D, A, B, 14, 11); ROUND1(B, C, D, A, 15, 19);
+
+ ROUND2(A, B, C, D, 0, 3); ROUND2(D, A, B, C, 4, 5);
+ ROUND2(C, D, A, B, 8, 9); ROUND2(B, C, D, A, 12, 13);
+ ROUND2(A, B, C, D, 1, 3); ROUND2(D, A, B, C, 5, 5);
+ ROUND2(C, D, A, B, 9, 9); ROUND2(B, C, D, A, 13, 13);
+ ROUND2(A, B, C, D, 2, 3); ROUND2(D, A, B, C, 6, 5);
+ ROUND2(C, D, A, B, 10, 9); ROUND2(B, C, D, A, 14, 13);
+ ROUND2(A, B, C, D, 3, 3); ROUND2(D, A, B, C, 7, 5);
+ ROUND2(C, D, A, B, 11, 9); ROUND2(B, C, D, A, 15, 13);
+
+ ROUND3(A, B, C, D, 0, 3); ROUND3(D, A, B, C, 8, 9);
+ ROUND3(C, D, A, B, 4, 11); ROUND3(B, C, D, A, 12, 15);
+ ROUND3(A, B, C, D, 2, 3); ROUND3(D, A, B, C, 10, 9);
+ ROUND3(C, D, A, B, 6, 11); ROUND3(B, C, D, A, 14, 15);
+ ROUND3(A, B, C, D, 1, 3); ROUND3(D, A, B, C, 9, 9);
+ ROUND3(C, D, A, B, 5, 11); ROUND3(B, C, D, A, 13, 15);
+ ROUND3(A, B, C, D, 3, 3); ROUND3(D, A, B, C, 11, 9);
+ ROUND3(C, D, A, B, 7, 11); ROUND3(B, C, D, A, 15, 15);
A += AA; B += BB; C += CC; D += DD;
@@ -101,7 +101,7 @@ static void mdfour64(uint32_t *M)
C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
#endif
- for (j=0;j<16;j++)
+ for (j = 0; j < 16; j++)
X[j] = 0;
m->A = A; m->B = B; m->C = C; m->D = D;
@@ -111,17 +111,17 @@ static void copy64(uint32_t *M, uint8_t *in)
{
int i;
- for (i=0;i<16;i++)
- M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
- (in[i*4+1]<<8) | (in[i*4+0]<<0);
+ for (i = 0; i < 16; i++)
+ M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
+ (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
}
-static void copy4(uint8_t *out,uint32_t x)
+static void copy4(uint8_t *out, uint32_t x)
{
- out[0] = x&0xFF;
- out[1] = (x>>8)&0xFF;
- out[2] = (x>>16)&0xFF;
- out[3] = (x>>24)&0xFF;
+ out[0] = x & 0xFF;
+ out[1] = (x >> 8) & 0xFF;
+ out[2] = (x >> 16) & 0xFF;
+ out[3] = (x >> 24) & 0xFF;
}
void mdfour_begin(struct mdfour *md)
@@ -149,14 +149,14 @@ static void mdfour_tail(uint8_t *in, size_t n)
buf[n] = 0x80;
if (n <= 55) {
- copy4(buf+56, b);
+ copy4(buf + 56, b);
copy64(M, buf);
mdfour64(M);
} else {
- copy4(buf+120, b);
+ copy4(buf + 120, b);
copy64(M, buf);
mdfour64(M);
- copy64(M, buf+64);
+ copy64(M, buf + 64);
mdfour64(M);
}
}
@@ -186,22 +186,23 @@ void mdfour_result(struct mdfour *md, uint8_t *out)
m = md;
copy4(out, m->A);
- copy4(out+4, m->B);
- copy4(out+8, m->C);
- copy4(out+12, m->D);
+ copy4(out + 4, m->B);
+ copy4(out + 8, m->C);
+ copy4(out + 12, m->D);
}
//===================================================================
-uint32_t Com_BlockChecksum( void *buffer, size_t len ) {
+uint32_t Com_BlockChecksum(void *buffer, size_t len)
+{
uint32_t digest[4];
uint32_t val;
struct mdfour md;
- mdfour_begin( &md );
- mdfour_update( &md, ( uint8_t * )buffer, len );
- mdfour_result( &md, ( uint8_t * )digest );
-
+ mdfour_begin(&md);
+ mdfour_update(&md, (uint8_t *)buffer, len);
+ mdfour_result(&md, (uint8_t *)digest);
+
val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
return val;
diff --git a/src/mdfour.h b/src/mdfour.h
index aaa2e0f..88477ed 100644
--- a/src/mdfour.h
+++ b/src/mdfour.h
@@ -30,7 +30,7 @@ typedef struct mdfour {
uint32_t totalN;
} mdfour_t;
-void mdfour_begin( struct mdfour *md );
-void mdfour_update( struct mdfour *md, uint8_t *in, size_t n );
-void mdfour_result( struct mdfour *md, uint8_t *out );
+void mdfour_begin(struct mdfour *md);
+void mdfour_update(struct mdfour *md, uint8_t *in, size_t n);
+void mdfour_result(struct mdfour *md, uint8_t *out);
diff --git a/src/mvd_client.c b/src/mvd_client.c
index 5aac403..22c9da7 100644
--- a/src/mvd_client.c
+++ b/src/mvd_client.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,13 +27,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "net_stream.h"
#include <setjmp.h>
-#define FOR_EACH_GTV( gtv ) \
- LIST_FOR_EACH( gtv_t, gtv, &mvd_gtv_list, entry )
+#define FOR_EACH_GTV(gtv) \
+ LIST_FOR_EACH(gtv_t, gtv, &mvd_gtv_list, entry)
-#define GTV_DEFAULT_BACKOFF (5*1000) // 5 seconds
-#define GTV_MAXIMUM_BACKOFF (5*3600*1000) // 5 hours
+#define GTV_DEFAULT_BACKOFF (5 * 1000) // 5 seconds
+#define GTV_MAXIMUM_BACKOFF (5 * 3600 * 1000) // 5 hours
-#define GTV_PING_INTERVAL (60*1000) // 1 minute
+#define GTV_PING_INTERVAL (60 * 1000) // 1 minute
typedef enum {
GTV_DISCONNECTED, // disconnected
@@ -55,9 +55,9 @@ typedef struct gtv_s {
char name[MAX_MVD_NAME];
gtv_state_t state;
mvd_t *mvd;
- void (*drop)( struct gtv_s * );
- void (*destroy)( struct gtv_s * );
- void (*run)( struct gtv_s * );
+ void (*drop)(struct gtv_s *);
+ void (*destroy)(struct gtv_s *);
+ void (*run)(struct gtv_s *);
// connection variables
char *username, *password;
@@ -99,8 +99,8 @@ static const char *const mvd_states[MVD_NUM_STATES] = {
"DEAD", "WAIT", "READ"
};
-LIST_DECL( mvd_gtv_list );
-LIST_DECL( mvd_channel_list );
+LIST_DECL(mvd_gtv_list);
+LIST_DECL(mvd_channel_list);
mvd_t mvd_waitingRoom;
qboolean mvd_dirty;
@@ -125,98 +125,103 @@ static cvar_t *mvd_snaps;
// ====================================================================
-void MVD_StopRecord( mvd_t *mvd ) {
+void MVD_StopRecord(mvd_t *mvd)
+{
uint16_t msglen;
msglen = 0;
- FS_Write( &msglen, 2, mvd->demorecording );
+ FS_Write(&msglen, 2, mvd->demorecording);
- FS_FCloseFile( mvd->demorecording );
+ FS_FCloseFile(mvd->demorecording);
mvd->demorecording = 0;
- Z_Free( mvd->demoname );
+ Z_Free(mvd->demoname);
mvd->demoname = NULL;
}
-static void MVD_Free( mvd_t *mvd ) {
+static void MVD_Free(mvd_t *mvd)
+{
mvd_snap_t *snap, *next;
int i;
- LIST_FOR_EACH_SAFE( mvd_snap_t, snap, next, &mvd->snapshots, entry ) {
- Z_Free( snap );
+ LIST_FOR_EACH_SAFE(mvd_snap_t, snap, next, &mvd->snapshots, entry) {
+ Z_Free(snap);
}
// stop demo recording
- if( mvd->demorecording ) {
- MVD_StopRecord( mvd );
+ if (mvd->demorecording) {
+ MVD_StopRecord(mvd);
}
- for( i = 0; i < mvd->maxclients; i++ ) {
- MVD_FreePlayer( &mvd->players[i] );
+ for (i = 0; i < mvd->maxclients; i++) {
+ MVD_FreePlayer(&mvd->players[i]);
}
- Z_Free( mvd->players );
+ Z_Free(mvd->players);
- CM_FreeMap( &mvd->cm );
+ CM_FreeMap(&mvd->cm);
- Z_Free( mvd->delay.data );
+ Z_Free(mvd->delay.data);
- List_Remove( &mvd->entry );
- Z_Free( mvd );
+ List_Remove(&mvd->entry);
+ Z_Free(mvd);
}
-static void MVD_Destroy( mvd_t *mvd ) {
+static void MVD_Destroy(mvd_t *mvd)
+{
mvd_client_t *client, *next;
// update channel menus
- if( !LIST_EMPTY( &mvd->entry ) ) {
+ if (!LIST_EMPTY(&mvd->entry)) {
mvd_dirty = qtrue;
}
// cause UDP clients to reconnect
- LIST_FOR_EACH_SAFE( mvd_client_t, client, next, &mvd->clients, entry ) {
- MVD_SwitchChannel( client, &mvd_waitingRoom );
+ LIST_FOR_EACH_SAFE(mvd_client_t, client, next, &mvd->clients, entry) {
+ MVD_SwitchChannel(client, &mvd_waitingRoom);
}
// destroy any existing GTV connection
- if( mvd->gtv ) {
+ if (mvd->gtv) {
mvd->gtv->mvd = NULL; // don't double destroy
- mvd->gtv->destroy( mvd->gtv );
+ mvd->gtv->destroy(mvd->gtv);
}
// free all channel data
- MVD_Free( mvd );
+ MVD_Free(mvd);
}
-void MVD_Destroyf( mvd_t *mvd, const char *fmt, ... ) {
+void MVD_Destroyf(mvd_t *mvd, const char *fmt, ...)
+{
va_list argptr;
char text[MAXERRORMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- Com_Printf( "[%s] =X= %s\n", mvd->name, text );
+ Com_Printf("[%s] =X= %s\n", mvd->name, text);
// notify spectators
- if( Com_IsDedicated() ) {
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, 0,
- "[MVD] %s\n", text );
+ if (Com_IsDedicated()) {
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, 0,
+ "[MVD] %s\n", text);
}
- MVD_Destroy( mvd );
+ MVD_Destroy(mvd);
- longjmp( mvd_jmpbuf, -1 );
+ longjmp(mvd_jmpbuf, -1);
}
#if USE_CLIENT
-static mvd_t *find_local_channel( void ) {
+static mvd_t *find_local_channel(void)
+{
mvd_client_t *client;
mvd_t *mvd;
- FOR_EACH_MVD( mvd ) {
- FOR_EACH_MVDCL( client, mvd ) {
- if( NET_IsLocalAddress( &client->cl->netchan->remote_address ) ) {
+ FOR_EACH_MVD(mvd) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (NET_IsLocalAddress(&client->cl->netchan->remote_address)) {
return mvd;
}
}
@@ -225,48 +230,49 @@ static mvd_t *find_local_channel( void ) {
}
#endif
-mvd_t *MVD_SetChannel( int arg ) {
- char *s = Cmd_Argv( arg );
+mvd_t *MVD_SetChannel(int arg)
+{
+ char *s = Cmd_Argv(arg);
mvd_t *mvd;
int id;
- if( LIST_EMPTY( &mvd_channel_list ) ) {
- Com_Printf( "No active channels.\n" );
+ if (LIST_EMPTY(&mvd_channel_list)) {
+ Com_Printf("No active channels.\n");
return NULL;
}
- if( !*s ) {
- if( LIST_SINGLE( &mvd_channel_list ) ) {
- return LIST_FIRST( mvd_t, &mvd_channel_list, entry );
+ if (!*s) {
+ if (LIST_SINGLE(&mvd_channel_list)) {
+ return LIST_FIRST(mvd_t, &mvd_channel_list, entry);
}
- Com_Printf( "Please specify an exact channel ID.\n" );
+ Com_Printf("Please specify an exact channel ID.\n");
return NULL;
}
#if USE_CLIENT
// special value of @@ returns the channel local client is on
- if( !dedicated->integer && !strcmp( s, "@@" ) ) {
- if( ( mvd = find_local_channel() ) != NULL ) {
+ if (!dedicated->integer && !strcmp(s, "@@")) {
+ if ((mvd = find_local_channel()) != NULL) {
return mvd;
}
} else
#endif
- if( COM_IsUint( s ) ) {
- id = atoi( s );
- FOR_EACH_MVD( mvd ) {
- if( mvd->id == id ) {
- return mvd;
+ if (COM_IsUint(s)) {
+ id = atoi(s);
+ FOR_EACH_MVD(mvd) {
+ if (mvd->id == id) {
+ return mvd;
+ }
}
- }
- } else {
- FOR_EACH_MVD( mvd ) {
- if( !strcmp( mvd->name, s ) ) {
- return mvd;
+ } else {
+ FOR_EACH_MVD(mvd) {
+ if (!strcmp(mvd->name, s)) {
+ return mvd;
+ }
}
}
- }
- Com_Printf( "No such channel ID: %s\n", s );
+ Com_Printf("No such channel ID: %s\n", s);
return NULL;
}
@@ -278,91 +284,95 @@ COMMON GTV STUFF
====================================================================
*/
-static void q_noreturn q_printf( 2, 3 )
-gtv_dropf( gtv_t *gtv, const char *fmt, ... ) {
+static void q_noreturn q_printf(2, 3)
+gtv_dropf(gtv_t *gtv, const char *fmt, ...)
+{
va_list argptr;
char text[MAXERRORMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- Com_Printf( "[%s] =!= %s\n", gtv->name, text );
+ Com_Printf("[%s] =!= %s\n", gtv->name, text);
- gtv->drop( gtv );
+ gtv->drop(gtv);
- longjmp( mvd_jmpbuf, -1 );
+ longjmp(mvd_jmpbuf, -1);
}
-static void q_noreturn q_printf( 2, 3 )
-gtv_destroyf( gtv_t *gtv, const char *fmt, ... ) {
+static void q_noreturn q_printf(2, 3)
+gtv_destroyf(gtv_t *gtv, const char *fmt, ...)
+{
va_list argptr;
char text[MAXERRORMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- Com_Printf( "[%s] =X= %s\n", gtv->name, text );
+ Com_Printf("[%s] =X= %s\n", gtv->name, text);
- gtv->destroy( gtv );
+ gtv->destroy(gtv);
- longjmp( mvd_jmpbuf, -1 );
+ longjmp(mvd_jmpbuf, -1);
}
-static mvd_t *create_channel( gtv_t *gtv ) {
+static mvd_t *create_channel(gtv_t *gtv)
+{
mvd_t *mvd;
- mvd = MVD_Mallocz( sizeof( *mvd ) );
+ mvd = MVD_Mallocz(sizeof(*mvd));
mvd->gtv = gtv;
mvd->id = gtv->id;
- Q_strlcpy( mvd->name, gtv->name, sizeof( mvd->name ) );
+ Q_strlcpy(mvd->name, gtv->name, sizeof(mvd->name));
mvd->pool.edicts = mvd->edicts;
- mvd->pool.edict_size = sizeof( edict_t );
+ mvd->pool.edict_size = sizeof(edict_t);
mvd->pool.max_edicts = MAX_EDICTS;
mvd->pm_type = PM_SPECTATOR;
mvd->min_packets = mvd_wait_delay->value * 10;
- List_Init( &mvd->snapshots );
- List_Init( &mvd->clients );
- List_Init( &mvd->entry );
+ List_Init(&mvd->snapshots);
+ List_Init(&mvd->clients);
+ List_Init(&mvd->entry);
return mvd;
}
-static gtv_t *gtv_set_conn( int arg ) {
- char *s = Cmd_Argv( arg );
+static gtv_t *gtv_set_conn(int arg)
+{
+ char *s = Cmd_Argv(arg);
gtv_t *gtv;
int id;
- if( LIST_EMPTY( &mvd_gtv_list ) ) {
- Com_Printf( "No GTV connections.\n" );
+ if (LIST_EMPTY(&mvd_gtv_list)) {
+ Com_Printf("No GTV connections.\n");
return NULL;
}
- if( !*s ) {
- if( LIST_SINGLE( &mvd_gtv_list ) ) {
- return LIST_FIRST( gtv_t, &mvd_gtv_list, entry );
+ if (!*s) {
+ if (LIST_SINGLE(&mvd_gtv_list)) {
+ return LIST_FIRST(gtv_t, &mvd_gtv_list, entry);
}
- Com_Printf( "Please specify an exact connection ID.\n" );
+ Com_Printf("Please specify an exact connection ID.\n");
return NULL;
}
- if( COM_IsUint( s ) ) {
- id = atoi( s );
- FOR_EACH_GTV( gtv ) {
- if( gtv->id == id ) {
+ if (COM_IsUint(s)) {
+ id = atoi(s);
+ FOR_EACH_GTV(gtv) {
+ if (gtv->id == id) {
return gtv;
}
}
} else {
- FOR_EACH_GTV( gtv ) {
- if( !strcmp( gtv->name, s ) ) {
+ FOR_EACH_GTV(gtv) {
+ if (!strcmp(gtv->name, s)) {
return gtv;
}
}
}
- Com_Printf( "No such connection ID: %s\n", s );
+ Com_Printf("No such connection ID: %s\n", s);
return NULL;
}
@@ -373,36 +383,37 @@ MVD_Frame
Called from main server loop.
==============
*/
-int MVD_Frame( void ) {
+int MVD_Frame(void)
+{
static unsigned prevtime;
gtv_t *gtv, *next;
int connections = 0;
- if( sv.state == ss_broadcast ) {
+ if (sv.state == ss_broadcast) {
unsigned delta = mvd_suspend_time->value * 60 * 1000;
- if( !delta || !LIST_EMPTY( &sv_clientlist ) ) {
+ if (!delta || !LIST_EMPTY(&sv_clientlist)) {
prevtime = svs.realtime;
- if( !mvd_active ) {
- Com_DPrintf( "Resuming MVD streams.\n" );
+ if (!mvd_active) {
+ Com_DPrintf("Resuming MVD streams.\n");
mvd_active = qtrue;
}
- } else if( mvd_active ) {
- if( svs.realtime - prevtime > delta ) {
- Com_DPrintf( "Suspending MVD streams.\n" );
+ } else if (mvd_active) {
+ if (svs.realtime - prevtime > delta) {
+ Com_DPrintf("Suspending MVD streams.\n");
mvd_active = qfalse;
}
}
}
// run all GTV connections (but not demos)
- LIST_FOR_EACH_SAFE( gtv_t, gtv, next, &mvd_gtv_list, entry ) {
- if( setjmp( mvd_jmpbuf ) ) {
- SZ_Clear( &msg_write );
+ LIST_FOR_EACH_SAFE(gtv_t, gtv, next, &mvd_gtv_list, entry) {
+ if (setjmp(mvd_jmpbuf)) {
+ SZ_Clear(&msg_write);
continue;
}
- gtv->run( gtv );
+ gtv->run(gtv);
connections++;
}
@@ -411,25 +422,26 @@ int MVD_Frame( void ) {
}
#if USE_CLIENT
-int MVD_GetDemoPercent( qboolean *paused, int *framenum ) {
+int MVD_GetDemoPercent(qboolean *paused, int *framenum)
+{
mvd_t *mvd;
gtv_t *gtv;
- if( ( mvd = find_local_channel() ) == NULL )
+ if ((mvd = find_local_channel()) == NULL)
return -1;
- if( ( gtv = mvd->gtv ) == NULL )
+ if ((gtv = mvd->gtv) == NULL)
return -1;
- if( !gtv->demoplayback )
+ if (!gtv->demoplayback)
return -1;
- if( paused )
+ if (paused)
*paused = mvd->state == MVD_WAITING ? qtrue : qfalse;
- if( framenum )
+ if (framenum)
*framenum = mvd->framenum;
- if( !gtv->demosize )
+ if (!gtv->demosize)
return -1;
return gtv->demopos * 100 / gtv->demosize;
@@ -444,101 +456,106 @@ DEMO PLAYER
====================================================================
*/
-static void demo_play_next( gtv_t *gtv, string_entry_t *entry );
+static void demo_play_next(gtv_t *gtv, string_entry_t *entry);
-static void emit_base_frame( mvd_t *mvd );
+static void emit_base_frame(mvd_t *mvd);
-static ssize_t demo_load_message( qhandle_t f ) {
+static ssize_t demo_load_message(qhandle_t f)
+{
uint16_t us;
ssize_t msglen, read;
- read = FS_Read( &us, 2, f );
- if( read != 2 ) {
+ read = FS_Read(&us, 2, f);
+ if (read != 2) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
- if( !us ) {
+ if (!us) {
return 0;
}
- msglen = LittleShort( us );
- if( msglen > MAX_MSGLEN ) {
+ msglen = LittleShort(us);
+ if (msglen > MAX_MSGLEN) {
return Q_ERR_INVALID_FORMAT;
}
- read = FS_Read( msg_read_buffer, msglen, f );
- if( read != msglen ) {
+ read = FS_Read(msg_read_buffer, msglen, f);
+ if (read != msglen) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
return read;
}
-static ssize_t demo_skip_map( qhandle_t f ) {
+static ssize_t demo_skip_map(qhandle_t f)
+{
ssize_t msglen;
- while( 1 ) {
- if( ( msglen = demo_load_message( f ) ) <= 0 ) {
+ while (1) {
+ if ((msglen = demo_load_message(f)) <= 0) {
return msglen;
}
- if( msg_read_buffer[0] == mvd_serverdata ) {
+ if (msg_read_buffer[0] == mvd_serverdata) {
break;
- }
+ }
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
return msglen;
}
-static ssize_t demo_read_message( qhandle_t f ) {
+static ssize_t demo_read_message(qhandle_t f)
+{
ssize_t msglen;
- if( ( msglen = demo_load_message( f ) ) <= 0 ) {
+ if ((msglen = demo_load_message(f)) <= 0) {
return msglen;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
return msglen;
}
-static ssize_t demo_read_first( qhandle_t f ) {
+static ssize_t demo_read_first(qhandle_t f)
+{
uint32_t magic;
ssize_t read;
qerror_t ret;
// read magic
- read = FS_Read( &magic, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&magic, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
// check for gzip header
- if( CHECK_GZIP_HEADER( magic ) ) {
- ret = FS_FilterFile( f );
- if( ret ) {
+ if (CHECK_GZIP_HEADER(magic)) {
+ ret = FS_FilterFile(f);
+ if (ret) {
return ret;
}
- read = FS_Read( &magic, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&magic, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
}
- if( magic != MVD_MAGIC ) {
+ if (magic != MVD_MAGIC) {
return Q_ERR_UNKNOWN_FORMAT;
}
// read the first message
- read = demo_read_message( f );
+ read = demo_read_message(f);
return read ? read : Q_ERR_UNEXPECTED_EOF;
}
// periodically builds a fake demo packet used to reconstruct delta compression
// state, configstrings and layouts at the given server frame.
-static void demo_emit_snapshot( mvd_t *mvd ) {
+static void demo_emit_snapshot(mvd_t *mvd)
+{
mvd_snap_t *snap;
gtv_t *gtv;
off_t pos;
@@ -546,71 +563,72 @@ static void demo_emit_snapshot( mvd_t *mvd ) {
size_t len;
int i;
- if( mvd_snaps->integer <= 0 )
+ if (mvd_snaps->integer <= 0)
return;
- if( mvd->framenum < mvd->last_snapshot + mvd_snaps->integer * 10 )
+ if (mvd->framenum < mvd->last_snapshot + mvd_snaps->integer * 10)
return;
gtv = mvd->gtv;
- if( !gtv )
+ if (!gtv)
return;
- if( !gtv->demosize )
+ if (!gtv->demosize)
return;
- pos = FS_Tell( gtv->demoplayback );
- if( pos < gtv->demopos )
+ pos = FS_Tell(gtv->demoplayback);
+ if (pos < gtv->demopos)
return;
// write baseline frame
- MSG_WriteByte( mvd_frame );
- emit_base_frame( mvd );
+ MSG_WriteByte(mvd_frame);
+ emit_base_frame(mvd);
// write configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = mvd->baseconfigstrings[i];
to = mvd->configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- len = strlen( to );
- if( len > MAX_QPATH )
+ len = strlen(to);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- MSG_WriteByte( mvd_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( to, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(mvd_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(to, len);
+ MSG_WriteByte(0);
}
// TODO: write private layouts/configstrings
- snap = MVD_Malloc( sizeof( *snap ) + msg_write.cursize - 1 );
+ snap = MVD_Malloc(sizeof(*snap) + msg_write.cursize - 1);
snap->framenum = mvd->framenum;
snap->filepos = pos;
snap->msglen = msg_write.cursize;
- memcpy( snap->data, msg_write.data, msg_write.cursize );
- List_Append( &mvd->snapshots, &snap->entry );
+ memcpy(snap->data, msg_write.data, msg_write.cursize);
+ List_Append(&mvd->snapshots, &snap->entry);
- Com_DPrintf( "[%d] snaplen %"PRIz"\n", mvd->framenum, msg_write.cursize );
+ Com_DPrintf("[%d] snaplen %"PRIz"\n", mvd->framenum, msg_write.cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
mvd->last_snapshot = mvd->framenum;
}
-static mvd_snap_t *demo_find_snapshot( mvd_t *mvd, int framenum ) {
+static mvd_snap_t *demo_find_snapshot(mvd_t *mvd, int framenum)
+{
mvd_snap_t *snap, *prev;
- if( LIST_EMPTY( &mvd->snapshots ) )
+ if (LIST_EMPTY(&mvd->snapshots))
return NULL;
- prev = LIST_FIRST( mvd_snap_t, &mvd->snapshots, entry );
+ prev = LIST_FIRST(mvd_snap_t, &mvd->snapshots, entry);
- LIST_FOR_EACH( mvd_snap_t, snap, &mvd->snapshots, entry ) {
- if( snap->framenum > framenum )
+ LIST_FOR_EACH(mvd_snap_t, snap, &mvd->snapshots, entry) {
+ if (snap->framenum > framenum)
break;
prev = snap;
}
@@ -618,34 +636,37 @@ static mvd_snap_t *demo_find_snapshot( mvd_t *mvd, int framenum ) {
return prev;
}
-static void demo_update( gtv_t *gtv ) {
- if( gtv->demosize ) {
- gtv->demopos = FS_Tell( gtv->demoplayback );
+static void demo_update(gtv_t *gtv)
+{
+ if (gtv->demosize) {
+ gtv->demopos = FS_Tell(gtv->demoplayback);
}
}
-static void demo_finish( gtv_t *gtv, ssize_t ret ) {
- if( ret < 0 ) {
- gtv_destroyf( gtv, "Couldn't read %s: %s", gtv->demoentry->string, Q_ErrorString( ret ) );
+static void demo_finish(gtv_t *gtv, ssize_t ret)
+{
+ if (ret < 0) {
+ gtv_destroyf(gtv, "Couldn't read %s: %s", gtv->demoentry->string, Q_ErrorString(ret));
}
- demo_play_next( gtv, gtv->demoentry->next );
+ demo_play_next(gtv, gtv->demoentry->next);
}
-static qboolean demo_read_frame( mvd_t *mvd ) {
+static qboolean demo_read_frame(mvd_t *mvd)
+{
gtv_t *gtv = mvd->gtv;
int count;
ssize_t ret;
- if( mvd->state == MVD_WAITING ) {
+ if (mvd->state == MVD_WAITING) {
return qfalse; // paused by user
}
- if( !gtv ) {
- MVD_Destroyf( mvd, "End of MVD stream reached" );
+ if (!gtv) {
+ MVD_Destroyf(mvd, "End of MVD stream reached");
}
- if( gtv->demowait ) {
+ if (gtv->demowait) {
gtv->demowait = qfalse;
return qfalse;
}
@@ -653,76 +674,77 @@ static qboolean demo_read_frame( mvd_t *mvd ) {
count = gtv->demoskip;
gtv->demoskip = 0;
- if( count ) {
- Com_Printf( "[%s] -=- Skipping map%s...\n", gtv->name, count == 1 ? "" : "s" );
+ if (count) {
+ Com_Printf("[%s] -=- Skipping map%s...\n", gtv->name, count == 1 ? "" : "s");
do {
- ret = demo_skip_map( gtv->demoplayback );
- if( ret <= 0 ) {
+ ret = demo_skip_map(gtv->demoplayback);
+ if (ret <= 0) {
goto next;
}
- } while( --count );
+ } while (--count);
} else {
- ret = demo_read_message( gtv->demoplayback );
- if( ret <= 0 ) {
+ ret = demo_read_message(gtv->demoplayback);
+ if (ret <= 0) {
goto next;
}
}
- demo_update( gtv );
+ demo_update(gtv);
- MVD_ParseMessage( mvd );
- demo_emit_snapshot( mvd );
+ MVD_ParseMessage(mvd);
+ demo_emit_snapshot(mvd);
return qtrue;
next:
- demo_finish( gtv, ret );
+ demo_finish(gtv, ret);
return qtrue;
}
-static void demo_play_next( gtv_t *gtv, string_entry_t *entry ) {
+static void demo_play_next(gtv_t *gtv, string_entry_t *entry)
+{
ssize_t len, ret;
- if( !entry ) {
- if( gtv->demoloop ) {
- if( --gtv->demoloop == 0 ) {
- gtv_destroyf( gtv, "End of play list reached" );
+ if (!entry) {
+ if (gtv->demoloop) {
+ if (--gtv->demoloop == 0) {
+ gtv_destroyf(gtv, "End of play list reached");
}
}
entry = gtv->demohead;
}
// close previous file
- if( gtv->demoplayback ) {
- FS_FCloseFile( gtv->demoplayback );
+ if (gtv->demoplayback) {
+ FS_FCloseFile(gtv->demoplayback);
gtv->demoplayback = 0;
}
// open new file
- len = FS_FOpenFile( entry->string, &gtv->demoplayback, FS_MODE_READ );
- if( !gtv->demoplayback ) {
- gtv_destroyf( gtv, "Couldn't open %s: %s", entry->string, Q_ErrorString( len ) );
+ len = FS_FOpenFile(entry->string, &gtv->demoplayback, FS_MODE_READ);
+ if (!gtv->demoplayback) {
+ gtv_destroyf(gtv, "Couldn't open %s: %s", entry->string, Q_ErrorString(len));
}
// read the first message
- ret = demo_read_first( gtv->demoplayback );
- if( ret < 0 ) {
- gtv_destroyf( gtv, "Couldn't read %s: %s", entry->string, Q_ErrorString( ret ) );
+ ret = demo_read_first(gtv->demoplayback);
+ if (ret < 0) {
+ gtv_destroyf(gtv, "Couldn't read %s: %s", entry->string, Q_ErrorString(ret));
}
// create MVD channel
- if( !gtv->mvd ) {
- gtv->mvd = create_channel( gtv );
+ if (!gtv->mvd) {
+ gtv->mvd = create_channel(gtv);
gtv->mvd->read_frame = demo_read_frame;
} else {
gtv->mvd->demoseeking = qfalse;
}
- Com_Printf( "[%s] -=- Reading from %s\n", gtv->name, entry->string );
+ Com_Printf("[%s] -=- Reading from %s\n", gtv->name, entry->string);
// parse gamestate
- MVD_ParseMessage( gtv->mvd );
- if( !gtv->mvd->state ) {
- gtv_destroyf( gtv, "First message of %s does not contain gamestate", entry->string );
+ MVD_ParseMessage(gtv->mvd);
+ if (!gtv->mvd->state) {
+ gtv_destroyf(gtv, "First message of %s does not contain gamestate", entry->string);
}
gtv->mvd->state = MVD_READING;
@@ -731,48 +753,50 @@ static void demo_play_next( gtv_t *gtv, string_entry_t *entry ) {
gtv->demoentry = entry;
// set channel address
- Q_strlcpy( gtv->address, COM_SkipPath( entry->string ), sizeof( gtv->address ) );
+ Q_strlcpy(gtv->address, COM_SkipPath(entry->string), sizeof(gtv->address));
- len = FS_Length( gtv->demoplayback );
- ret = FS_Tell( gtv->demoplayback );
- if( len > 0 && ret > 0 ) {
+ len = FS_Length(gtv->demoplayback);
+ ret = FS_Tell(gtv->demoplayback);
+ if (len > 0 && ret > 0) {
gtv->demosize = len;
gtv->demopos = ret;
} else {
gtv->demosize = gtv->demopos = 0;
}
- demo_emit_snapshot( gtv->mvd );
+ demo_emit_snapshot(gtv->mvd);
}
-static void demo_free_playlist( gtv_t *gtv ) {
+static void demo_free_playlist(gtv_t *gtv)
+{
string_entry_t *entry, *next;
- for( entry = gtv->demohead; entry; entry = next ) {
+ for (entry = gtv->demohead; entry; entry = next) {
next = entry->next;
- Z_Free( entry );
+ Z_Free(entry);
}
gtv->demohead = gtv->demoentry = NULL;
}
-static void demo_destroy( gtv_t *gtv ) {
+static void demo_destroy(gtv_t *gtv)
+{
mvd_t *mvd = gtv->mvd;
// destroy any associated MVD channel
- if( mvd ) {
+ if (mvd) {
mvd->gtv = NULL;
- MVD_Destroy( mvd );
+ MVD_Destroy(mvd);
}
- if( gtv->demoplayback ) {
- FS_FCloseFile( gtv->demoplayback );
+ if (gtv->demoplayback) {
+ FS_FCloseFile(gtv->demoplayback);
gtv->demoplayback = 0;
}
- demo_free_playlist( gtv );
+ demo_free_playlist(gtv);
- Z_Free( gtv );
+ Z_Free(gtv);
}
@@ -784,61 +808,65 @@ GTV CONNECTIONS
====================================================================
*/
-static void write_stream( gtv_t *gtv, void *data, size_t len ) {
- if( FIFO_Write( &gtv->stream.send, data, len ) != len ) {
- gtv_destroyf( gtv, "Send buffer overflowed" );
+static void write_stream(gtv_t *gtv, void *data, size_t len)
+{
+ if (FIFO_Write(&gtv->stream.send, data, len) != len) {
+ gtv_destroyf(gtv, "Send buffer overflowed");
}
// don't timeout
gtv->last_sent = svs.realtime;
}
-static void write_message( gtv_t *gtv, gtv_clientop_t op ) {
+static void write_message(gtv_t *gtv, gtv_clientop_t op)
+{
byte header[3];
size_t len = msg_write.cursize + 1;
header[0] = len & 255;
- header[1] = ( len >> 8 ) & 255;
+ header[1] = (len >> 8) & 255;
header[2] = op;
- write_stream( gtv, header, sizeof( header ) );
+ write_stream(gtv, header, sizeof(header));
- write_stream( gtv, msg_write.data, msg_write.cursize );
+ write_stream(gtv, msg_write.data, msg_write.cursize);
}
-static void q_noreturn gtv_oob_kill( mvd_t *mvd ) {
+static void q_noreturn gtv_oob_kill(mvd_t *mvd)
+{
gtv_t *gtv = mvd->gtv;
- if( gtv ) {
+ if (gtv) {
// don't kill connection!
gtv->mvd = NULL;
mvd->gtv = NULL;
}
- MVD_Destroyf( mvd, "Ran out of buffers" );
+ MVD_Destroyf(mvd, "Ran out of buffers");
}
-static qboolean gtv_wait_stop( mvd_t *mvd ) {
+static qboolean gtv_wait_stop(mvd_t *mvd)
+{
gtv_t *gtv = mvd->gtv;
int min_packets = mvd->min_packets, usage;
// if not connected, flush any data left
- if( !gtv || gtv->state != GTV_READING ) {
- if( !mvd->num_packets ) {
- gtv_oob_kill( mvd );
+ if (!gtv || gtv->state != GTV_READING) {
+ if (!mvd->num_packets) {
+ gtv_oob_kill(mvd);
}
min_packets = 1;
}
// see how many frames are buffered
- if( mvd->num_packets >= min_packets ) {
- Com_Printf( "[%s] -=- Waiting finished, reading...\n", mvd->name );
+ if (mvd->num_packets >= min_packets) {
+ Com_Printf("[%s] -=- Waiting finished, reading...\n", mvd->name);
goto stop;
}
// see how much data is buffered
- usage = FIFO_Percent( &mvd->delay );
- if( usage >= mvd_wait_percent->value ) {
- Com_Printf( "[%s] -=- Buffering finished, reading...\n", mvd->name );
+ usage = FIFO_Percent(&mvd->delay);
+ if (usage >= mvd_wait_percent->value) {
+ Com_Printf("[%s] -=- Buffering finished, reading...\n", mvd->name);
goto stop;
}
@@ -846,9 +874,9 @@ static qboolean gtv_wait_stop( mvd_t *mvd ) {
stop:
// notify spectators
- if( Com_IsDedicated() ) {
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, 0,
- "[MVD] Streaming resumed.\n" );
+ if (Com_IsDedicated()) {
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, 0,
+ "[MVD] Streaming resumed.\n");
}
mvd->state = MVD_READING;
mvd->dirty = qtrue;
@@ -856,27 +884,28 @@ stop:
}
// ran out of buffers
-static void gtv_wait_start( mvd_t *mvd ) {
+static void gtv_wait_start(mvd_t *mvd)
+{
gtv_t *gtv = mvd->gtv;
int tr = mvd_wait_delay->value * 10;
// if not connected, kill the channel
- if( !gtv ) {
- MVD_Destroyf( mvd, "End of MVD stream reached" );
+ if (!gtv) {
+ MVD_Destroyf(mvd, "End of MVD stream reached");
}
// FIXME: if connection is suspended, kill the channel
- if( gtv->state != GTV_READING ) {
- gtv_oob_kill( mvd );
+ if (gtv->state != GTV_READING) {
+ gtv_oob_kill(mvd);
}
- Com_Printf( "[%s] -=- Buffering data...\n", mvd->name );
+ Com_Printf("[%s] -=- Buffering data...\n", mvd->name);
// oops, underflowed in the middle of the game,
// resume as quickly as possible after there is some
// data available again
mvd->min_packets = 50 + 5 * mvd->underflows;
- if( mvd->min_packets > tr ) {
+ if (mvd->min_packets > tr) {
mvd->min_packets = tr;
}
mvd->underflows++;
@@ -884,201 +913,209 @@ static void gtv_wait_start( mvd_t *mvd ) {
mvd->dirty = qtrue;
// notify spectators
- if( Com_IsDedicated() ) {
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, 0,
- "[MVD] Buffering data, please wait...\n" );
+ if (Com_IsDedicated()) {
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, 0,
+ "[MVD] Buffering data, please wait...\n");
}
// send ping to force server to flush
- write_message( gtv, GTC_PING );
- NET_UpdateStream( &gtv->stream );
+ write_message(gtv, GTC_PING);
+ NET_UpdateStream(&gtv->stream);
}
-static qboolean gtv_read_frame( mvd_t *mvd ) {
+static qboolean gtv_read_frame(mvd_t *mvd)
+{
uint16_t msglen;
- switch( mvd->state ) {
+ switch (mvd->state) {
case MVD_WAITING:
- if( !gtv_wait_stop( mvd ) ) {
+ if (!gtv_wait_stop(mvd)) {
return qfalse;
}
break;
case MVD_READING:
- if( !mvd->num_packets ) {
- gtv_wait_start( mvd );
+ if (!mvd->num_packets) {
+ gtv_wait_start(mvd);
return qfalse;
}
break;
default:
- MVD_Destroyf( mvd, "%s: bad mvd->state", __func__ );
+ MVD_Destroyf(mvd, "%s: bad mvd->state", __func__);
}
// NOTE: if we got here, delay buffer MUST contain
// at least one complete, non-empty packet
// parse msglen
- if( FIFO_Read( &mvd->delay, &msglen, 2 ) != 2 ) {
- MVD_Destroyf( mvd, "%s: partial data", __func__ );
+ if (FIFO_Read(&mvd->delay, &msglen, 2) != 2) {
+ MVD_Destroyf(mvd, "%s: partial data", __func__);
}
- msglen = LittleShort( msglen );
- if( msglen < 1 || msglen > MAX_MSGLEN ) {
- MVD_Destroyf( mvd, "%s: invalid msglen", __func__ );
+ msglen = LittleShort(msglen);
+ if (msglen < 1 || msglen > MAX_MSGLEN) {
+ MVD_Destroyf(mvd, "%s: invalid msglen", __func__);
}
// read this message
- if( !FIFO_ReadMessage( &mvd->delay, msglen ) ) {
- MVD_Destroyf( mvd, "%s: partial data", __func__ );
+ if (!FIFO_ReadMessage(&mvd->delay, msglen)) {
+ MVD_Destroyf(mvd, "%s: partial data", __func__);
}
// decrement buffered packets counter
mvd->num_packets--;
// parse it
- MVD_ParseMessage( mvd );
+ MVD_ParseMessage(mvd);
return qtrue;
}
-static qboolean gtv_forward_cmd( mvd_client_t *client ) {
+static qboolean gtv_forward_cmd(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
gtv_t *gtv = mvd->gtv;
char *text;
size_t len;
- if( !gtv || gtv->state < GTV_CONNECTED ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Not connected to the game server.\n" );
+ if (!gtv || gtv->state < GTV_CONNECTED) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Not connected to the game server.\n");
return qfalse;
}
- if( !( gtv->flags & GTF_STRINGCMDS ) ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Game server does not allow command forwarding.\n" );
+ if (!(gtv->flags & GTF_STRINGCMDS)) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Game server does not allow command forwarding.\n");
return qfalse;
}
- if( FIFO_Usage( &gtv->stream.send ) ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Send buffer not empty, please wait.\n" );
+ if (FIFO_Usage(&gtv->stream.send)) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Send buffer not empty, please wait.\n");
return qfalse;
}
text = Cmd_Args();
- len = strlen( text );
- if( len > 150 ) {
+ len = strlen(text);
+ if (len > 150) {
len = 150;
}
// send it
- MSG_WriteData( text, len );
- MSG_WriteByte( 0 );
- write_message( gtv, GTC_STRINGCMD );
- SZ_Clear( &msg_write );
- NET_UpdateStream( &gtv->stream );
+ MSG_WriteData(text, len);
+ MSG_WriteByte(0);
+ write_message(gtv, GTC_STRINGCMD);
+ SZ_Clear(&msg_write);
+ NET_UpdateStream(&gtv->stream);
return qtrue;
}
-static void send_hello( gtv_t *gtv ) {
+static void send_hello(gtv_t *gtv)
+{
int flags = GTF_STRINGCMDS;
#if USE_ZLIB
flags |= GTF_DEFLATE;
#endif
- MSG_WriteShort( GTV_PROTOCOL_VERSION );
- MSG_WriteLong( flags );
- MSG_WriteLong( 0 ); // reserved
- MSG_WriteString( gtv->username ? gtv->username : mvd_username->string );
- MSG_WriteString( gtv->password ? gtv->password : mvd_password->string );
- MSG_WriteString( com_version->string );
- write_message( gtv, GTC_HELLO );
- SZ_Clear( &msg_write );
+ MSG_WriteShort(GTV_PROTOCOL_VERSION);
+ MSG_WriteLong(flags);
+ MSG_WriteLong(0); // reserved
+ MSG_WriteString(gtv->username ? gtv->username : mvd_username->string);
+ MSG_WriteString(gtv->password ? gtv->password : mvd_password->string);
+ MSG_WriteString(com_version->string);
+ write_message(gtv, GTC_HELLO);
+ SZ_Clear(&msg_write);
- Com_Printf( "[%s] -=- Sending client hello...\n", gtv->name );
+ Com_Printf("[%s] -=- Sending client hello...\n", gtv->name);
gtv->state = GTV_PREPARING;
}
-static void send_stream_start( gtv_t *gtv ) {
+static void send_stream_start(gtv_t *gtv)
+{
int maxbuf;
- if( gtv->mvd ) {
+ if (gtv->mvd) {
maxbuf = gtv->mvd->min_packets / 2;
} else {
maxbuf = mvd_wait_delay->value * 10 / 2;
}
- if( maxbuf < 10 ) {
+ if (maxbuf < 10) {
maxbuf = 10;
}
// send stream start request
- MSG_WriteShort( maxbuf );
- write_message( gtv, GTC_STREAM_START );
- SZ_Clear( &msg_write );
+ MSG_WriteShort(maxbuf);
+ write_message(gtv, GTC_STREAM_START);
+ SZ_Clear(&msg_write);
- Com_Printf( "[%s] -=- Sending stream start request...\n", gtv->name );
+ Com_Printf("[%s] -=- Sending stream start request...\n", gtv->name);
gtv->state = GTV_RESUMING;
}
-static void send_stream_stop( gtv_t *gtv ) {
+static void send_stream_stop(gtv_t *gtv)
+{
// send stream stop request
- write_message( gtv, GTC_STREAM_STOP );
+ write_message(gtv, GTC_STREAM_STOP);
- Com_Printf( "[%s] -=- Sending stream stop request...\n", gtv->name );
+ Com_Printf("[%s] -=- Sending stream stop request...\n", gtv->name);
gtv->state = GTV_SUSPENDING;
}
#if USE_ZLIB
-static voidpf gtv_zalloc OF(( voidpf opaque, uInt items, uInt size )) {
- return MVD_Malloc( items * size );
+static voidpf gtv_zalloc OF((voidpf opaque, uInt items, uInt size))
+{
+ return MVD_Malloc(items * size);
}
-static void gtv_zfree OF(( voidpf opaque, voidpf address )) {
- Z_Free( address );
+static void gtv_zfree OF((voidpf opaque, voidpf address))
+{
+ Z_Free(address);
}
#endif
-static void parse_hello( gtv_t *gtv ) {
+static void parse_hello(gtv_t *gtv)
+{
int flags;
- if( gtv->state >= GTV_CONNECTED ) {
- gtv_destroyf( gtv, "Duplicated server hello" );
+ if (gtv->state >= GTV_CONNECTED) {
+ gtv_destroyf(gtv, "Duplicated server hello");
}
flags = MSG_ReadLong();
- if( flags & GTF_DEFLATE ) {
+ if (flags & GTF_DEFLATE) {
#if USE_ZLIB
- if( !gtv->z_str.state ) {
+ if (!gtv->z_str.state) {
gtv->z_str.zalloc = gtv_zalloc;
gtv->z_str.zfree = gtv_zfree;
- if( inflateInit( &gtv->z_str ) != Z_OK ) {
- gtv_destroyf( gtv, "inflateInit() failed: %s",
- gtv->z_str.msg );
+ if (inflateInit(&gtv->z_str) != Z_OK) {
+ gtv_destroyf(gtv, "inflateInit() failed: %s",
+ gtv->z_str.msg);
}
}
- if( !gtv->z_buf.data ) {
- gtv->z_buf.data = MVD_Malloc( MAX_GTS_MSGLEN );
+ if (!gtv->z_buf.data) {
+ gtv->z_buf.data = MVD_Malloc(MAX_GTS_MSGLEN);
gtv->z_buf.size = MAX_GTS_MSGLEN;
}
gtv->z_act = qtrue; // remaining data is deflated
#else
- gtv_destroyf( gtv, "Server sending deflated data" );
+ gtv_destroyf(gtv, "Server sending deflated data");
#endif
}
-
- Com_Printf( "[%s] -=- Server hello done.\n", gtv->name );
- if( sv.state != ss_broadcast ) {
+ Com_Printf("[%s] -=- Server hello done.\n", gtv->name);
+
+ if (sv.state != ss_broadcast) {
// the game is just starting
- SV_InitGame( MVD_SPAWN_INTERNAL );
+ SV_InitGame(MVD_SPAWN_INTERNAL);
MVD_Spawn();
} else {
// notify spectators
- if( Com_IsDedicated() && gtv->mvd ) {
- MVD_BroadcastPrintf( gtv->mvd, PRINT_HIGH, 0,
- "[MVD] Restored connection to the game server!\n" );
+ if (Com_IsDedicated() && gtv->mvd) {
+ MVD_BroadcastPrintf(gtv->mvd, PRINT_HIGH, 0,
+ "[MVD] Restored connection to the game server!\n");
}
}
@@ -1086,64 +1123,67 @@ static void parse_hello( gtv_t *gtv ) {
gtv->state = GTV_CONNECTED;
}
-static void parse_stream_start( gtv_t *gtv ) {
- if( gtv->state != GTV_RESUMING ) {
- gtv_destroyf( gtv, "Unexpected stream start ack in state %u", gtv->state );
+static void parse_stream_start(gtv_t *gtv)
+{
+ if (gtv->state != GTV_RESUMING) {
+ gtv_destroyf(gtv, "Unexpected stream start ack in state %u", gtv->state);
}
- Com_Printf( "[%s] -=- Stream start ack received.\n", gtv->name );
+ Com_Printf("[%s] -=- Stream start ack received.\n", gtv->name);
gtv->state = GTV_READING;
}
-static void parse_stream_stop( gtv_t *gtv ) {
- if( gtv->state != GTV_SUSPENDING ) {
- gtv_destroyf( gtv, "Unexpected stream stop ack in state %u", gtv->state );
+static void parse_stream_stop(gtv_t *gtv)
+{
+ if (gtv->state != GTV_SUSPENDING) {
+ gtv_destroyf(gtv, "Unexpected stream stop ack in state %u", gtv->state);
}
- Com_Printf( "[%s] -=- Stream stop ack received.\n", gtv->name );
+ Com_Printf("[%s] -=- Stream stop ack received.\n", gtv->name);
gtv->state = GTV_CONNECTED;
}
-static void parse_stream_data( gtv_t *gtv ) {
+static void parse_stream_data(gtv_t *gtv)
+{
mvd_t *mvd = gtv->mvd;
size_t size;
- if( gtv->state < GTV_WAITING ) {
- gtv_destroyf( gtv, "Unexpected stream data packet" );
+ if (gtv->state < GTV_WAITING) {
+ gtv_destroyf(gtv, "Unexpected stream data packet");
}
// ignore any pending data while suspending
- if( gtv->state == GTV_SUSPENDING ) {
+ if (gtv->state == GTV_SUSPENDING) {
msg_read.readcount = msg_read.cursize;
return;
}
// empty data part acts as stream suspend marker
- if( msg_read.readcount == msg_read.cursize ) {
- if( gtv->state == GTV_READING ) {
- Com_Printf( "[%s] -=- Stream suspended by server.\n", gtv->name );
+ if (msg_read.readcount == msg_read.cursize) {
+ if (gtv->state == GTV_READING) {
+ Com_Printf("[%s] -=- Stream suspended by server.\n", gtv->name);
gtv->state = GTV_WAITING;
}
return;
}
// non-empty data part acts as stream resume marker
- if( gtv->state == GTV_WAITING ) {
- Com_Printf( "[%s] -=- Stream resumed by server.\n", gtv->name );
+ if (gtv->state == GTV_WAITING) {
+ Com_Printf("[%s] -=- Stream resumed by server.\n", gtv->name);
gtv->state = GTV_READING;
}
// create the channel, if not yet created
- if( !mvd ) {
- mvd = create_channel( gtv );
+ if (!mvd) {
+ mvd = create_channel(gtv);
- Cvar_ClampInteger( mvd_buffer_size, 2, 10 );
+ Cvar_ClampInteger(mvd_buffer_size, 2, 10);
// allocate delay buffer
size = mvd_buffer_size->integer * MAX_MSGLEN;
- mvd->delay.data = MVD_Malloc( size );
+ mvd->delay.data = MVD_Malloc(size);
mvd->delay.size = size;
mvd->read_frame = gtv_read_frame;
mvd->forward_cmd = gtv_forward_cmd;
@@ -1151,49 +1191,49 @@ static void parse_stream_data( gtv_t *gtv ) {
gtv->mvd = mvd;
}
- if( !mvd->state ) {
+ if (!mvd->state) {
// parse it in place until we get a gamestate
- MVD_ParseMessage( mvd );
+ MVD_ParseMessage(mvd);
} else {
byte *data = msg_read.data + 1;
size_t len = msg_read.cursize - 1;
uint16_t msglen;
// see if this packet fits
- if( FIFO_Write( &mvd->delay, NULL, len + 2 ) != len + 2 ) {
- if( mvd->state == MVD_WAITING ) {
+ if (FIFO_Write(&mvd->delay, NULL, len + 2) != len + 2) {
+ if (mvd->state == MVD_WAITING) {
// if delay buffer overflowed in waiting state,
// something is seriously wrong, disconnect for safety
- gtv_destroyf( gtv, "Delay buffer overflowed in waiting state" );
+ gtv_destroyf(gtv, "Delay buffer overflowed in waiting state");
}
// oops, overflowed
- Com_Printf( "[%s] =!= Delay buffer overflowed!\n", gtv->name );
+ Com_Printf("[%s] =!= Delay buffer overflowed!\n", gtv->name);
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// notify spectators
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, 0,
- "[MVD] Delay buffer overflowed!\n" );
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, 0,
+ "[MVD] Delay buffer overflowed!\n");
}
// clear entire delay buffer
// minimize the delay
- FIFO_Clear( &mvd->delay );
+ FIFO_Clear(&mvd->delay);
mvd->state = MVD_WAITING;
mvd->num_packets = 0;
mvd->min_packets = 50;
mvd->overflows++;
// send stream stop request
- write_message( gtv, GTC_STREAM_STOP );
+ write_message(gtv, GTC_STREAM_STOP);
gtv->state = GTV_SUSPENDING;
return;
}
// write it into delay buffer
- msglen = LittleShort( len );
- FIFO_Write( &mvd->delay, &msglen, 2 );
- FIFO_Write( &mvd->delay, data, len );
+ msglen = LittleShort(len);
+ FIFO_Write(&mvd->delay, &msglen, 2);
+ FIFO_Write(&mvd->delay, data, len);
// increment buffered packets counter
mvd->num_packets++;
@@ -1202,41 +1242,42 @@ static void parse_stream_data( gtv_t *gtv ) {
}
}
-static qboolean parse_message( gtv_t *gtv, fifo_t *fifo ) {
+static qboolean parse_message(gtv_t *gtv, fifo_t *fifo)
+{
uint32_t magic;
uint16_t msglen;
int cmd;
// check magic
- if( gtv->state < GTV_PREPARING ) {
- if( !FIFO_TryRead( fifo, &magic, 4 ) ) {
+ if (gtv->state < GTV_PREPARING) {
+ if (!FIFO_TryRead(fifo, &magic, 4)) {
return qfalse;
}
- if( magic != MVD_MAGIC ) {
- gtv_destroyf( gtv, "Not a MVD/GTV stream" );
+ if (magic != MVD_MAGIC) {
+ gtv_destroyf(gtv, "Not a MVD/GTV stream");
}
// send client hello
- send_hello( gtv );
+ send_hello(gtv);
}
// parse msglen
- if( !gtv->msglen ) {
- if( !FIFO_TryRead( fifo, &msglen, 2 ) ) {
+ if (!gtv->msglen) {
+ if (!FIFO_TryRead(fifo, &msglen, 2)) {
return qfalse;
}
- msglen = LittleShort( msglen );
- if( !msglen ) {
- gtv_dropf( gtv, "End of MVD/GTV stream" );
+ msglen = LittleShort(msglen);
+ if (!msglen) {
+ gtv_dropf(gtv, "End of MVD/GTV stream");
}
- if( msglen > MAX_MSGLEN ) {
- gtv_destroyf( gtv, "Oversize message" );
+ if (msglen > MAX_MSGLEN) {
+ gtv_destroyf(gtv, "Oversize message");
}
gtv->msglen = msglen;
}
// read this message
- if( !FIFO_ReadMessage( fifo, gtv->msglen ) ) {
+ if (!FIFO_ReadMessage(fifo, gtv->msglen)) {
return qfalse;
}
@@ -1244,111 +1285,114 @@ static qboolean parse_message( gtv_t *gtv, fifo_t *fifo ) {
cmd = MSG_ReadByte();
- switch( cmd ) {
+ switch (cmd) {
case GTS_HELLO:
- parse_hello( gtv );
+ parse_hello(gtv);
break;
case GTS_PONG:
break;
case GTS_STREAM_START:
- parse_stream_start( gtv );
+ parse_stream_start(gtv);
break;
case GTS_STREAM_STOP:
- parse_stream_stop( gtv );
+ parse_stream_stop(gtv);
break;
case GTS_STREAM_DATA:
- parse_stream_data( gtv );
+ parse_stream_data(gtv);
break;
case GTS_ERROR:
- gtv_destroyf( gtv, "Server side error occured." );
+ gtv_destroyf(gtv, "Server side error occured.");
break;
case GTS_BADREQUEST:
- gtv_destroyf( gtv, "Server refused to process our request." );
+ gtv_destroyf(gtv, "Server refused to process our request.");
break;
case GTS_NOACCESS:
- gtv_destroyf( gtv,
- "You don't have permission to access "
- "MVD/GTV stream on this server." );
+ gtv_destroyf(gtv,
+ "You don't have permission to access "
+ "MVD/GTV stream on this server.");
break;
case GTS_DISCONNECT:
- gtv_destroyf( gtv, "Server has been shut down." );
+ gtv_destroyf(gtv, "Server has been shut down.");
break;
case GTS_RECONNECT:
- gtv_dropf( gtv, "Server has been restarted." );
+ gtv_dropf(gtv, "Server has been restarted.");
break;
default:
- gtv_destroyf( gtv, "Unknown command byte" );
+ gtv_destroyf(gtv, "Unknown command byte");
}
- if( msg_read.readcount > msg_read.cursize ) {
- gtv_destroyf( gtv, "Read past end of message" );
+ if (msg_read.readcount > msg_read.cursize) {
+ gtv_destroyf(gtv, "Read past end of message");
}
-
+
gtv->last_rcvd = svs.realtime; // don't timeout
return qtrue;
}
#if USE_ZLIB
-static int inflate_stream( fifo_t *dst, fifo_t *src, z_streamp z ) {
+static int inflate_stream(fifo_t *dst, fifo_t *src, z_streamp z)
+{
byte *data;
size_t avail_in, avail_out;
int ret = Z_BUF_ERROR;
do {
- data = FIFO_Peek( src, &avail_in );
- if( !avail_in ) {
+ data = FIFO_Peek(src, &avail_in);
+ if (!avail_in) {
break;
}
z->next_in = data;
- z->avail_in = ( uInt )avail_in;
+ z->avail_in = (uInt)avail_in;
- data = FIFO_Reserve( dst, &avail_out );
- if( !avail_out ) {
+ data = FIFO_Reserve(dst, &avail_out);
+ if (!avail_out) {
break;
}
z->next_out = data;
- z->avail_out = ( uInt )avail_out;
+ z->avail_out = (uInt)avail_out;
- ret = inflate( z, Z_SYNC_FLUSH );
+ ret = inflate(z, Z_SYNC_FLUSH);
- FIFO_Decommit( src, avail_in - z->avail_in );
- FIFO_Commit( dst, avail_out - z->avail_out );
- } while( ret == Z_OK );
+ FIFO_Decommit(src, avail_in - z->avail_in);
+ FIFO_Commit(dst, avail_out - z->avail_out);
+ } while (ret == Z_OK);
return ret;
}
-static void inflate_more( gtv_t *gtv ) {
- int ret = inflate_stream( &gtv->z_buf, &gtv->stream.recv, &gtv->z_str );
+static void inflate_more(gtv_t *gtv)
+{
+ int ret = inflate_stream(&gtv->z_buf, &gtv->stream.recv, &gtv->z_str);
- switch( ret ) {
+ switch (ret) {
case Z_BUF_ERROR:
case Z_OK:
break;
case Z_STREAM_END:
- inflateReset( &gtv->z_str );
+ inflateReset(&gtv->z_str);
gtv->z_act = qfalse;
break;
default:
- gtv_destroyf( gtv, "inflate() failed: %s", gtv->z_str.msg );
+ gtv_destroyf(gtv, "inflate() failed: %s", gtv->z_str.msg);
}
}
#endif
-static neterr_t run_connect( gtv_t *gtv ) {
+static neterr_t run_connect(gtv_t *gtv)
+{
neterr_t ret;
uint32_t magic;
// run connection
- if( ( ret = NET_RunConnect( &gtv->stream ) ) != NET_OK ) {
+ if ((ret = NET_RunConnect(&gtv->stream)) != NET_OK) {
return ret;
}
- Com_Printf( "[%s] -=- Connected to the game server!\n", gtv->name );
+ Com_Printf("[%s] -=- Connected to the game server!\n", gtv->name);
// allocate buffers
- if( !gtv->data ) {
- gtv->data = MVD_Malloc( MAX_GTS_MSGLEN + MAX_GTC_MSGLEN );
+ if (!gtv->data) {
+ gtv->data = MVD_Malloc(MAX_GTS_MSGLEN + MAX_GTC_MSGLEN);
}
gtv->stream.recv.data = gtv->data;
gtv->stream.recv.size = MAX_GTS_MSGLEN;
@@ -1360,12 +1404,13 @@ static neterr_t run_connect( gtv_t *gtv ) {
// send magic
magic = MVD_MAGIC;
- write_stream( gtv, &magic, 4 );
+ write_stream(gtv, &magic, 4);
return NET_OK;
}
-static neterr_t run_stream( gtv_t *gtv ) {
+static neterr_t run_stream(gtv_t *gtv)
+{
neterr_t ret;
#ifdef _DEBUG
int count;
@@ -1373,23 +1418,23 @@ static neterr_t run_stream( gtv_t *gtv ) {
#endif
// run network stream
- if( ( ret = NET_RunStream( &gtv->stream ) ) != NET_OK ) {
+ if ((ret = NET_RunStream(&gtv->stream)) != NET_OK) {
return ret;
}
#ifdef _DEBUG
count = 0;
- usage = FIFO_Usage( &gtv->stream.recv );
+ usage = FIFO_Usage(&gtv->stream.recv);
#endif
#if USE_ZLIB
- if( gtv->z_act ) {
- while( 1 ) {
+ if (gtv->z_act) {
+ while (1) {
// decompress more data
- if( gtv->z_act ) {
- inflate_more( gtv );
+ if (gtv->z_act) {
+ inflate_more(gtv);
}
- if( !parse_message( gtv, &gtv->z_buf ) ) {
+ if (!parse_message(gtv, &gtv->z_buf)) {
break;
}
#ifdef _DEBUG
@@ -1398,186 +1443,191 @@ static neterr_t run_stream( gtv_t *gtv ) {
}
} else
#endif
- while( parse_message( gtv, &gtv->stream.recv ) ) {
+ while (parse_message(gtv, &gtv->stream.recv)) {
#ifdef _DEBUG
count++;
#endif
}
#ifdef _DEBUG
- if( mvd_shownet->integer == -1 ) {
- size_t total = usage - FIFO_Usage( &gtv->stream.recv );
+ if (mvd_shownet->integer == -1) {
+ size_t total = usage - FIFO_Usage(&gtv->stream.recv);
- Com_Printf( "[%s] %"PRIz" bytes, %d msgs\n",
- gtv->name, total, count );
+ Com_Printf("[%s] %"PRIz" bytes, %d msgs\n",
+ gtv->name, total, count);
}
#endif
return NET_OK;
}
-static void check_timeouts( gtv_t *gtv ) {
+static void check_timeouts(gtv_t *gtv)
+{
unsigned timeout = mvd_timeout->value * 1000;
// drop if no data has been received for too long
- if( svs.realtime - gtv->last_rcvd > timeout ) {
- gtv_dropf( gtv, "Server connection timed out." );
+ if (svs.realtime - gtv->last_rcvd > timeout) {
+ gtv_dropf(gtv, "Server connection timed out.");
}
- if( gtv->state < GTV_CONNECTED ) {
+ if (gtv->state < GTV_CONNECTED) {
return;
}
// stop/start stream depending on global state
- if( mvd_active ) {
- if( gtv->state == GTV_CONNECTED ) {
- send_stream_start( gtv );
+ if (mvd_active) {
+ if (gtv->state == GTV_CONNECTED) {
+ send_stream_start(gtv);
}
- } else if( gtv->state == GTV_WAITING || gtv->state == GTV_READING ) {
- send_stream_stop( gtv );
+ } else if (gtv->state == GTV_WAITING || gtv->state == GTV_READING) {
+ send_stream_stop(gtv);
}
// ping if no data has been sent for too long
- if( svs.realtime - gtv->last_sent > GTV_PING_INTERVAL ) {
- write_message( gtv, GTC_PING );
+ if (svs.realtime - gtv->last_sent > GTV_PING_INTERVAL) {
+ write_message(gtv, GTC_PING);
}
}
-static qboolean check_reconnect( gtv_t *gtv ) {
+static qboolean check_reconnect(gtv_t *gtv)
+{
netadr_t adr;
- if( svs.realtime - gtv->retry_time < gtv->retry_backoff ) {
+ if (svs.realtime - gtv->retry_time < gtv->retry_backoff) {
return qfalse;
}
- Com_Printf( "[%s] -=- Attempting to reconnect to %s...\n",
- gtv->name, gtv->address );
+ Com_Printf("[%s] -=- Attempting to reconnect to %s...\n",
+ gtv->name, gtv->address);
gtv->state = GTV_CONNECTING;
// don't timeout
gtv->last_sent = gtv->last_rcvd = svs.realtime;
- if( !NET_StringToAdr( gtv->address, &adr, PORT_SERVER ) ) {
- gtv_dropf( gtv, "Unable to lookup %s\n", gtv->address );
+ if (!NET_StringToAdr(gtv->address, &adr, PORT_SERVER)) {
+ gtv_dropf(gtv, "Unable to lookup %s\n", gtv->address);
}
- if( NET_Connect( &adr, &gtv->stream ) == NET_ERROR ) {
- gtv_dropf( gtv, "%s to %s\n", NET_ErrorString(),
- NET_AdrToString( &adr ) );
+ if (NET_Connect(&adr, &gtv->stream) == NET_ERROR) {
+ gtv_dropf(gtv, "%s to %s\n", NET_ErrorString(),
+ NET_AdrToString(&adr));
}
return qtrue;
}
-static void gtv_run( gtv_t *gtv ) {
+static void gtv_run(gtv_t *gtv)
+{
neterr_t ret = NET_AGAIN;
// check if it is time to reconnect
- if( !gtv->state ) {
- if( !check_reconnect( gtv ) ) {
+ if (!gtv->state) {
+ if (!check_reconnect(gtv)) {
return;
}
}
// run network stream
- switch( gtv->stream.state ) {
+ switch (gtv->stream.state) {
case NS_CONNECTING:
- ret = run_connect( gtv );
- if( ret == NET_AGAIN ) {
+ ret = run_connect(gtv);
+ if (ret == NET_AGAIN) {
return;
}
- if( ret == NET_OK ) {
- case NS_CONNECTED:
- ret = run_stream( gtv );
+ if (ret == NET_OK) {
+ case NS_CONNECTED:
+ ret = run_stream(gtv);
}
break;
default:
return;
}
- switch( ret ) {
+ switch (ret) {
case NET_AGAIN:
case NET_OK:
- check_timeouts( gtv );
- NET_UpdateStream( &gtv->stream );
+ check_timeouts(gtv);
+ NET_UpdateStream(&gtv->stream);
break;
case NET_ERROR:
- gtv_dropf( gtv, "%s to %s", NET_ErrorString(),
- NET_AdrToString( &gtv->stream.address ) );
+ gtv_dropf(gtv, "%s to %s", NET_ErrorString(),
+ NET_AdrToString(&gtv->stream.address));
break;
case NET_CLOSED:
- gtv_dropf( gtv, "Server has closed connection." );
+ gtv_dropf(gtv, "Server has closed connection.");
break;
}
}
-static void gtv_destroy( gtv_t *gtv ) {
+static void gtv_destroy(gtv_t *gtv)
+{
mvd_t *mvd = gtv->mvd;
// drop any associated MVD channel
- if( mvd ) {
+ if (mvd) {
mvd->gtv = NULL; // don't double destroy
- if( !mvd->state ) {
+ if (!mvd->state) {
// free it here, since it is not yet
// added to global channel list
- MVD_Free( mvd );
- } else if( Com_IsDedicated() ) {
+ MVD_Free(mvd);
+ } else if (Com_IsDedicated()) {
// notify spectators
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, 0,
- "[MVD] Disconnected from the game server!\n" );
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, 0,
+ "[MVD] Disconnected from the game server!\n");
}
}
// make sure network connection is closed
- NET_Close( &gtv->stream );
+ NET_Close(&gtv->stream);
// unlink from the list of connections
- List_Remove( &gtv->entry );
+ List_Remove(&gtv->entry);
// free all memory buffers
- Z_Free( gtv->username );
- Z_Free( gtv->password );
+ Z_Free(gtv->username);
+ Z_Free(gtv->password);
#if USE_ZLIB
- inflateEnd( &gtv->z_str );
- Z_Free( gtv->z_buf.data );
+ inflateEnd(&gtv->z_str);
+ Z_Free(gtv->z_buf.data);
#endif
- Z_Free( gtv->data );
- Z_Free( gtv );
+ Z_Free(gtv->data);
+ Z_Free(gtv);
}
-static void gtv_drop( gtv_t *gtv ) {
+static void gtv_drop(gtv_t *gtv)
+{
time_t sec;
char buffer[MAX_QPATH];
- if( gtv->stream.state < NS_CONNECTED ) {
- gtv->retry_backoff += 15*1000;
+ if (gtv->stream.state < NS_CONNECTED) {
+ gtv->retry_backoff += 15 * 1000;
} else {
// notify spectators
- if( Com_IsDedicated() && gtv->mvd ) {
- MVD_BroadcastPrintf( gtv->mvd, PRINT_HIGH, 0,
- "[MVD] Lost connection to the game server!\n" );
+ if (Com_IsDedicated() && gtv->mvd) {
+ MVD_BroadcastPrintf(gtv->mvd, PRINT_HIGH, 0,
+ "[MVD] Lost connection to the game server!\n");
}
- if( gtv->state >= GTV_CONNECTED ) {
+ if (gtv->state >= GTV_CONNECTED) {
gtv->retry_backoff = GTV_DEFAULT_BACKOFF;
} else {
- gtv->retry_backoff += 30*1000;
+ gtv->retry_backoff += 30 * 1000;
}
}
- if( gtv->retry_backoff > GTV_MAXIMUM_BACKOFF ) {
+ if (gtv->retry_backoff > GTV_MAXIMUM_BACKOFF) {
gtv->retry_backoff = GTV_MAXIMUM_BACKOFF;
}
sec = gtv->retry_backoff / 1000;
- Com_FormatTimeLong( buffer, sizeof( buffer ), sec );
- Com_Printf( "[%s] -=- Reconnecting in %s.\n", gtv->name, buffer );
+ Com_FormatTimeLong(buffer, sizeof(buffer), sec);
+ Com_Printf("[%s] -=- Reconnecting in %s.\n", gtv->name, buffer);
- NET_Close( &gtv->stream );
+ NET_Close(&gtv->stream);
#if USE_ZLIB
- inflateReset( &gtv->z_str );
- FIFO_Clear( &gtv->z_buf );
+ inflateReset(&gtv->z_str);
+ FIFO_Clear(&gtv->z_buf);
gtv->z_act = qfalse;
#endif
gtv->msglen = 0;
@@ -1594,18 +1644,19 @@ OPERATOR COMMANDS
====================================================================
*/
-void MVD_Spawn( void ) {
- Cvar_SetInteger( sv_running, ss_broadcast, FROM_CODE );
- Cvar_Set( "sv_paused", "0" );
- Cvar_Set( "timedemo", "0" );
- SV_InfoSet( "port", net_port->string );
+void MVD_Spawn(void)
+{
+ Cvar_SetInteger(sv_running, ss_broadcast, FROM_CODE);
+ Cvar_Set("sv_paused", "0");
+ Cvar_Set("timedemo", "0");
+ SV_InfoSet("port", net_port->string);
#if USE_SYSCON
SV_SetConsoleTitle();
#endif
// generate spawncount for Waiting Room
- sv.spawncount = ( rand() | ( rand() << 16 ) ) ^ Sys_Milliseconds();
+ sv.spawncount = (rand() | (rand() << 16)) ^ Sys_Milliseconds();
sv.spawncount &= 0x7FFFFFFF;
#if USE_FPS
@@ -1618,166 +1669,176 @@ void MVD_Spawn( void ) {
sv.state = ss_broadcast;
}
-static void MVD_Spawn_f( void ) {
- SV_InitGame( MVD_SPAWN_ENABLED );
+static void MVD_Spawn_f(void)
+{
+ SV_InitGame(MVD_SPAWN_ENABLED);
MVD_Spawn();
}
-static void list_generic( void ) {
+static void list_generic(void)
+{
mvd_t *mvd;
Com_Printf(
"id name map spc plr stat buf pckt address \n"
- "-- ------------ -------- --- --- ---- --- ---- --------------\n" );
+ "-- ------------ -------- --- --- ---- --- ---- --------------\n");
- FOR_EACH_MVD( mvd ) {
- Com_Printf( "%2d %-12.12s %-8.8s %3d %3d %-4.4s %3d %4u %s\n",
- mvd->id, mvd->name, mvd->mapname,
- List_Count( &mvd->clients ), mvd->numplayers,
- mvd_states[mvd->state],
- FIFO_Percent( &mvd->delay ), mvd->num_packets,
- mvd->gtv ? mvd->gtv->address : "<disconnected>" );
+ FOR_EACH_MVD(mvd) {
+ Com_Printf("%2d %-12.12s %-8.8s %3d %3d %-4.4s %3d %4u %s\n",
+ mvd->id, mvd->name, mvd->mapname,
+ List_Count(&mvd->clients), mvd->numplayers,
+ mvd_states[mvd->state],
+ FIFO_Percent(&mvd->delay), mvd->num_packets,
+ mvd->gtv ? mvd->gtv->address : "<disconnected>");
}
}
-static void list_recordings( void ) {
+static void list_recordings(void)
+{
mvd_t *mvd;
char buffer[8];
off_t pos;
Com_Printf(
"id name map size name\n"
- "-- ------------ -------- ---- --------------\n" );
+ "-- ------------ -------- ---- --------------\n");
- FOR_EACH_MVD( mvd ) {
- if( mvd->demorecording ) {
- pos = FS_Tell( mvd->demorecording );
- Com_FormatSize( buffer, sizeof( buffer ), pos );
+ FOR_EACH_MVD(mvd) {
+ if (mvd->demorecording) {
+ pos = FS_Tell(mvd->demorecording);
+ Com_FormatSize(buffer, sizeof(buffer), pos);
} else {
- strcpy( buffer, "-" );
+ strcpy(buffer, "-");
}
- Com_Printf( "%2d %-12.12s %-8.8s %-4s %s\n",
- mvd->id, mvd->name, mvd->mapname,
- buffer, mvd->demoname ? mvd->demoname : "-" );
+ Com_Printf("%2d %-12.12s %-8.8s %-4s %s\n",
+ mvd->id, mvd->name, mvd->mapname,
+ buffer, mvd->demoname ? mvd->demoname : "-");
}
}
-static void MVD_ListChannels_f( void ) {
+static void MVD_ListChannels_f(void)
+{
char *s;
- if( LIST_EMPTY( &mvd_channel_list ) ) {
- Com_Printf( "No MVD channels.\n" );
+ if (LIST_EMPTY(&mvd_channel_list)) {
+ Com_Printf("No MVD channels.\n");
return;
}
- s = Cmd_Argv( 1 );
- if( *s == 'r' ) {
+ s = Cmd_Argv(1);
+ if (*s == 'r') {
list_recordings();
} else {
list_generic();
}
}
-static void MVD_ListServers_f( void ) {
+static void MVD_ListServers_f(void)
+{
gtv_t *gtv;
unsigned ratio;
- if( LIST_EMPTY( &mvd_gtv_list ) ) {
- Com_Printf( "No GTV connections.\n" );
+ if (LIST_EMPTY(&mvd_gtv_list)) {
+ Com_Printf("No GTV connections.\n");
return;
}
Com_Printf(
"id name state ratio lastmsg address \n"
- "-- ------------ ------------ ----- ------- --------------\n" );
+ "-- ------------ ------------ ----- ------- --------------\n");
- FOR_EACH_GTV( gtv ) {
+ FOR_EACH_GTV(gtv) {
ratio = 100;
#if USE_ZLIB
- if( gtv->z_act && gtv->z_str.total_out ) {
- ratio = 100 * ( ( double )gtv->z_str.total_in /
- gtv->z_str.total_out );
+ if (gtv->z_act && gtv->z_str.total_out) {
+ ratio = 100 * ((double)gtv->z_str.total_in /
+ gtv->z_str.total_out);
}
#endif
- Com_Printf( "%2d %-12.12s %-12.12s %4u%% %7u %s\n",
- gtv->id, gtv->name, gtv_states[gtv->state],
- ratio, svs.realtime - gtv->last_rcvd,
- NET_AdrToString( &gtv->stream.address ) );
+ Com_Printf("%2d %-12.12s %-12.12s %4u%% %7u %s\n",
+ gtv->id, gtv->name, gtv_states[gtv->state],
+ ratio, svs.realtime - gtv->last_rcvd,
+ NET_AdrToString(&gtv->stream.address));
}
}
-void MVD_StreamedStop_f( void ) {
+void MVD_StreamedStop_f(void)
+{
mvd_t *mvd;
- mvd = MVD_SetChannel( 1 );
- if( !mvd ) {
- Com_Printf( "Usage: %s [chanid]\n", Cmd_Argv( 0 ) );
+ mvd = MVD_SetChannel(1);
+ if (!mvd) {
+ Com_Printf("Usage: %s [chanid]\n", Cmd_Argv(0));
return;
}
- if( !mvd->demorecording ) {
- Com_Printf( "[%s] Not recording a demo.\n", mvd->name );
+ if (!mvd->demorecording) {
+ Com_Printf("[%s] Not recording a demo.\n", mvd->name);
return;
}
- MVD_StopRecord( mvd );
+ MVD_StopRecord(mvd);
- Com_Printf( "[%s] Stopped recording.\n", mvd->name );
+ Com_Printf("[%s] Stopped recording.\n", mvd->name);
}
-static inline int player_flags( mvd_t *mvd, mvd_player_t *player ) {
+static inline int player_flags(mvd_t *mvd, mvd_player_t *player)
+{
int flags = 0;
- if( !player->inuse )
+ if (!player->inuse)
flags |= MSG_PS_REMOVE;
return flags;
}
-static inline int entity_flags( mvd_t *mvd, edict_t *ent ) {
+static inline int entity_flags(mvd_t *mvd, edict_t *ent)
+{
int flags = MSG_ES_UMASK;
- if( !ent->inuse ) {
+ if (!ent->inuse) {
flags |= MSG_ES_REMOVE;
- } else if( ent->s.number <= mvd->maxclients ) {
- mvd_player_t *player = &mvd->players[ ent->s.number - 1 ];
- if( player->inuse && player->ps.pmove.pm_type == PM_NORMAL )
+ } else if (ent->s.number <= mvd->maxclients) {
+ mvd_player_t *player = &mvd->players[ent->s.number - 1];
+ if (player->inuse && player->ps.pmove.pm_type == PM_NORMAL)
flags |= MSG_ES_FIRSTPERSON;
}
return flags;
}
-static void emit_base_frame( mvd_t *mvd ) {
+static void emit_base_frame(mvd_t *mvd)
+{
edict_t *ent;
mvd_player_t *player;
int i, portalbytes;
byte portalbits[MAX_MAP_PORTAL_BYTES];
- portalbytes = CM_WritePortalBits( &mvd->cm, portalbits );
- MSG_WriteByte( portalbytes );
- MSG_WriteData( portalbits, portalbytes );
+ portalbytes = CM_WritePortalBits(&mvd->cm, portalbits);
+ MSG_WriteByte(portalbytes);
+ MSG_WriteData(portalbits, portalbytes);
// send base player states
- for( i = 0; i < mvd->maxclients; i++ ) {
+ for (i = 0; i < mvd->maxclients; i++) {
player = &mvd->players[i];
- MSG_WriteDeltaPlayerstate_Packet( NULL, &player->ps, i,
- player_flags( mvd, player ) );
+ MSG_WriteDeltaPlayerstate_Packet(NULL, &player->ps, i,
+ player_flags(mvd, player));
}
- MSG_WriteByte( CLIENTNUM_NONE );
+ MSG_WriteByte(CLIENTNUM_NONE);
// send base entity states
- for( i = 1; i < mvd->pool.num_edicts; i++ ) {
+ for (i = 1; i < mvd->pool.num_edicts; i++) {
ent = &mvd->edicts[i];
ent->s.number = i;
- MSG_WriteDeltaEntity( NULL, &ent->s, entity_flags( mvd, ent ) );
+ MSG_WriteDeltaEntity(NULL, &ent->s, entity_flags(mvd, ent));
}
- MSG_WriteShort( 0 );
+ MSG_WriteShort(0);
}
-static void emit_gamestate( mvd_t *mvd ) {
+static void emit_gamestate(mvd_t *mvd)
+{
int i, extra;
char *s;
size_t len;
@@ -1786,37 +1847,38 @@ static void emit_gamestate( mvd_t *mvd ) {
extra = mvd->flags << SVCMD_BITS;
// send the serverdata
- MSG_WriteByte( mvd_serverdata | extra );
- MSG_WriteLong( PROTOCOL_VERSION_MVD );
- MSG_WriteShort( PROTOCOL_VERSION_MVD_CURRENT );
- MSG_WriteLong( mvd->servercount );
- MSG_WriteString( mvd->gamedir );
- MSG_WriteShort( mvd->clientNum );
+ MSG_WriteByte(mvd_serverdata | extra);
+ MSG_WriteLong(PROTOCOL_VERSION_MVD);
+ MSG_WriteShort(PROTOCOL_VERSION_MVD_CURRENT);
+ MSG_WriteLong(mvd->servercount);
+ MSG_WriteString(mvd->gamedir);
+ MSG_WriteShort(mvd->clientNum);
// send configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
s = mvd->configstrings[i];
- if( !*s )
+ if (!*s)
continue;
- len = strlen( s );
- if( len > MAX_QPATH )
+ len = strlen(s);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- MSG_WriteShort( i );
- MSG_WriteData( s, len );
- MSG_WriteByte( 0 );
+ MSG_WriteShort(i);
+ MSG_WriteData(s, len);
+ MSG_WriteByte(0);
}
- MSG_WriteShort( MAX_CONFIGSTRINGS );
+ MSG_WriteShort(MAX_CONFIGSTRINGS);
// send baseline frame
- emit_base_frame( mvd );
+ emit_base_frame(mvd);
// TODO: write private layouts/configstrings
}
-void MVD_StreamedRecord_f( void ) {
+void MVD_StreamedRecord_f(void)
+{
char buffer[MAX_OSPATH];
qhandle_t f;
mvd_t *mvd;
@@ -1826,12 +1888,12 @@ void MVD_StreamedRecord_f( void ) {
ssize_t ret;
int c;
- while( ( c = Cmd_ParseOptions( o_record ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_record)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_record, "<filename> [chanid]" );
- Com_Printf( "Begin MVD recording on the specified channel.\n" );
- Cmd_PrintHelp( o_record );
+ Cmd_PrintUsage(o_record, "<filename> [chanid]");
+ Com_Printf("Begin MVD recording on the specified channel.\n");
+ Cmd_PrintHelp(o_record);
return;
case 'z':
mode |= FS_FLAG_GZIP;
@@ -1841,61 +1903,61 @@ void MVD_StreamedRecord_f( void ) {
}
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
-
- if( ( mvd = MVD_SetChannel( cmd_optind + 1 ) ) == NULL ) {
+
+ if ((mvd = MVD_SetChannel(cmd_optind + 1)) == NULL) {
Cmd_PrintHint();
return;
}
- if( mvd->demorecording ) {
- Com_Printf( "[%s] Already recording into %s.\n",
- mvd->name, mvd->demoname );
+ if (mvd->demorecording) {
+ Com_Printf("[%s] Already recording into %s.\n",
+ mvd->name, mvd->demoname);
return;
}
//
// open the demo file
//
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode,
- "demos/", cmd_optarg, ".mvd2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode,
+ "demos/", cmd_optarg, ".mvd2");
+ if (!f) {
return;
}
- Com_Printf( "[%s] Recording into %s\n", mvd->name, buffer );
+ Com_Printf("[%s] Recording into %s\n", mvd->name, buffer);
mvd->demorecording = f;
- mvd->demoname = MVD_CopyString( buffer );
+ mvd->demoname = MVD_CopyString(buffer);
- emit_gamestate( mvd );
+ emit_gamestate(mvd);
// write magic
magic = MVD_MAGIC;
- ret = FS_Write( &magic, 4, f );
- if( ret != 4 )
+ ret = FS_Write(&magic, 4, f);
+ if (ret != 4)
goto fail;
// write gamestate
- msglen = LittleShort( msg_write.cursize );
- ret = FS_Write( &msglen, 2, f );
- if( ret != 2 )
+ msglen = LittleShort(msg_write.cursize);
+ ret = FS_Write(&msglen, 2, f);
+ if (ret != 2)
goto fail;
- ret = FS_Write( msg_write.data, msg_write.cursize, f );
- if( ret != msg_write.cursize )
+ ret = FS_Write(msg_write.data, msg_write.cursize, f);
+ if (ret != msg_write.cursize)
goto fail;
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
return;
fail:
- SZ_Clear( &msg_write );
- Com_EPrintf( "[%s] Couldn't write demo: %s\n", mvd->name, Q_ErrorString( ret ) );
- MVD_StopRecord( mvd );
+ SZ_Clear(&msg_write);
+ Com_EPrintf("[%s] Couldn't write demo: %s\n", mvd->name, Q_ErrorString(ret));
+ MVD_StopRecord(mvd);
}
static const cmd_option_t o_mvdconnect[] = {
@@ -1906,8 +1968,9 @@ static const cmd_option_t o_mvdconnect[] = {
{ NULL }
};
-static void MVD_Connect_c( genctx_t *ctx, int argnum ) {
- Cmd_Option_c( o_mvdconnect, Com_Address_g, ctx, argnum );
+static void MVD_Connect_c(genctx_t *ctx, int argnum)
+{
+ Cmd_Option_c(o_mvdconnect, Com_Address_g, ctx, argnum);
}
/*
@@ -1915,19 +1978,20 @@ static void MVD_Connect_c( genctx_t *ctx, int argnum ) {
MVD_Connect_f
==============
*/
-static void MVD_Connect_f( void ) {
+static void MVD_Connect_f(void)
+{
netadr_t adr;
netstream_t stream;
char *name = NULL, *username = NULL, *password = NULL;
gtv_t *gtv;
int c;
- while( ( c = Cmd_ParseOptions( o_mvdconnect ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_mvdconnect)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_mvdconnect, "<address[:port]>" );
- Com_Printf( "Connect to the specified MVD/GTV server.\n" );
- Cmd_PrintHelp( o_mvdconnect );
+ Cmd_PrintUsage(o_mvdconnect, "<address[:port]>");
+ Com_Printf("Connect to the specified MVD/GTV server.\n");
+ Cmd_PrintHelp(o_mvdconnect);
return;
case 'n':
name = cmd_optarg;
@@ -1943,36 +2007,36 @@ static void MVD_Connect_f( void ) {
}
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing address argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing address argument.\n");
Cmd_PrintHint();
return;
}
// resolve hostname
- if( !NET_StringToAdr( cmd_optarg, &adr, PORT_SERVER ) ) {
- Com_Printf( "Bad server address: %s\n", cmd_optarg );
+ if (!NET_StringToAdr(cmd_optarg, &adr, PORT_SERVER)) {
+ Com_Printf("Bad server address: %s\n", cmd_optarg);
return;
}
// don't allow multiple connections
- FOR_EACH_GTV( gtv ) {
- if( NET_IsEqualAdr( &adr, &gtv->stream.address ) ) {
- Com_Printf( "[%s] =!= Connection to %s already exists.\n",
- gtv->name, NET_AdrToString( &adr ) );
+ FOR_EACH_GTV(gtv) {
+ if (NET_IsEqualAdr(&adr, &gtv->stream.address)) {
+ Com_Printf("[%s] =!= Connection to %s already exists.\n",
+ gtv->name, NET_AdrToString(&adr));
return;
}
}
// create new socket and start connecting
- if( NET_Connect( &adr, &stream ) == NET_ERROR ) {
- Com_EPrintf( "%s to %s\n", NET_ErrorString(),
- NET_AdrToString( &adr ) );
+ if (NET_Connect(&adr, &stream) == NET_ERROR) {
+ Com_EPrintf("%s to %s\n", NET_ErrorString(),
+ NET_AdrToString(&adr));
return;
}
// create new connection
- gtv = MVD_Mallocz( sizeof( *gtv ) );
+ gtv = MVD_Mallocz(sizeof(*gtv));
gtv->id = mvd_chanid++;
gtv->state = GTV_CONNECTING;
gtv->stream = stream;
@@ -1980,67 +2044,70 @@ static void MVD_Connect_f( void ) {
gtv->run = gtv_run;
gtv->drop = gtv_drop;
gtv->destroy = gtv_destroy;
- gtv->username = MVD_CopyString( username );
- gtv->password = MVD_CopyString( password );
- List_Append( &mvd_gtv_list, &gtv->entry );
+ gtv->username = MVD_CopyString(username);
+ gtv->password = MVD_CopyString(password);
+ List_Append(&mvd_gtv_list, &gtv->entry);
// set channel name
- if( name ) {
- Q_strlcpy( gtv->name, name, sizeof( gtv->name ) );
+ if (name) {
+ Q_strlcpy(gtv->name, name, sizeof(gtv->name));
} else {
- Q_snprintf( gtv->name, sizeof( gtv->name ), "net%d", gtv->id );
+ Q_snprintf(gtv->name, sizeof(gtv->name), "net%d", gtv->id);
}
- Q_strlcpy( gtv->address, cmd_optarg, sizeof( gtv->address ) );
+ Q_strlcpy(gtv->address, cmd_optarg, sizeof(gtv->address));
- Com_Printf( "[%s] -=- Connecting to %s...\n",
- gtv->name, NET_AdrToString( &adr ) );
+ Com_Printf("[%s] -=- Connecting to %s...\n",
+ gtv->name, NET_AdrToString(&adr));
}
-static void MVD_Disconnect_f( void ) {
+static void MVD_Disconnect_f(void)
+{
gtv_t *gtv;
- gtv = gtv_set_conn( 1 );
- if( !gtv ) {
+ gtv = gtv_set_conn(1);
+ if (!gtv) {
return;
}
- Com_Printf( "[%s] =X= Connection destroyed.\n", gtv->name );
- gtv->destroy( gtv );
+ Com_Printf("[%s] =X= Connection destroyed.\n", gtv->name);
+ gtv->destroy(gtv);
}
-static void MVD_Kill_f( void ) {
+static void MVD_Kill_f(void)
+{
mvd_t *mvd;
- mvd = MVD_SetChannel( 1 );
- if( !mvd ) {
+ mvd = MVD_SetChannel(1);
+ if (!mvd) {
return;
}
- Com_Printf( "[%s] =X= Channel was killed.\n", mvd->name );
- MVD_Destroy( mvd );
+ Com_Printf("[%s] =X= Channel was killed.\n", mvd->name);
+ MVD_Destroy(mvd);
}
-static void MVD_Pause_f( void ) {
+static void MVD_Pause_f(void)
+{
mvd_t *mvd;
- mvd = MVD_SetChannel( 1 );
- if( !mvd ) {
+ mvd = MVD_SetChannel(1);
+ if (!mvd) {
return;
}
- if( !mvd->gtv || !mvd->gtv->demoplayback ) {
- Com_Printf( "[%s] Only demo channels can be paused.\n", mvd->name );
+ if (!mvd->gtv || !mvd->gtv->demoplayback) {
+ Com_Printf("[%s] Only demo channels can be paused.\n", mvd->name);
return;
}
- switch( mvd->state ) {
+ switch (mvd->state) {
case MVD_WAITING:
- //Com_Printf( "[%s] Channel was resumed.\n", mvd->name );
+ //Com_Printf("[%s] Channel was resumed.\n", mvd->name);
mvd->state = MVD_READING;
break;
case MVD_READING:
- //Com_Printf( "[%s] Channel was paused.\n", mvd->name );
+ //Com_Printf("[%s] Channel was paused.\n", mvd->name);
mvd->state = MVD_WAITING;
break;
default:
@@ -2048,30 +2115,32 @@ static void MVD_Pause_f( void ) {
}
}
-static void MVD_Skip_f( void ) {
+static void MVD_Skip_f(void)
+{
mvd_t *mvd;
int count;
- mvd = MVD_SetChannel( 1 );
- if( !mvd ) {
- Com_Printf( "Usage: %s [chan_id] [count]\n", Cmd_Argv( 0 ) );
+ mvd = MVD_SetChannel(1);
+ if (!mvd) {
+ Com_Printf("Usage: %s [chan_id] [count]\n", Cmd_Argv(0));
return;
}
- count = atoi( Cmd_Argv( 2 ) );
- if( count < 1 ) {
+ count = atoi(Cmd_Argv(2));
+ if (count < 1) {
count = 1;
}
- if( !mvd->gtv || !mvd->gtv->demoplayback ) {
- Com_Printf( "[%s] Maps can be skipped only on demo channels.\n", mvd->name );
+ if (!mvd->gtv || !mvd->gtv->demoplayback) {
+ Com_Printf("[%s] Maps can be skipped only on demo channels.\n", mvd->name);
return;
}
mvd->gtv->demoskip = count;
}
-static void MVD_Seek_f( void ) {
+static void MVD_Seek_f(void)
+{
mvd_t *mvd;
gtv_t *gtv;
mvd_snap_t *snap;
@@ -2080,139 +2149,139 @@ static void MVD_Seek_f( void ) {
edict_t *ent;
qboolean gamestate;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s [+-]<timespec> [chanid]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s [+-]<timespec> [chanid]\n", Cmd_Argv(0));
return;
}
- mvd = MVD_SetChannel( 2 );
- if( !mvd ) {
+ mvd = MVD_SetChannel(2);
+ if (!mvd) {
return;
}
gtv = mvd->gtv;
- if( !gtv || !gtv->demoplayback ) {
- Com_Printf( "[%s] Seeking is only supported on demo channels.\n", mvd->name );
+ if (!gtv || !gtv->demoplayback) {
+ Com_Printf("[%s] Seeking is only supported on demo channels.\n", mvd->name);
return;
}
- if( mvd->demorecording ) {
+ if (mvd->demorecording) {
// need some sort of nodelta frame support for that :(
- Com_Printf( "[%s] Seeking is not yet supported during demo recording, sorry.\n", mvd->name );
+ Com_Printf("[%s] Seeking is not yet supported during demo recording, sorry.\n", mvd->name);
return;
}
- to = Cmd_Argv( 1 );
+ to = Cmd_Argv(1);
- if( *to == '-' || *to == '+' ) {
+ if (*to == '-' || *to == '+') {
// relative to current frame
- if( !Com_ParseTimespec( to + 1, &frames ) ) {
- Com_Printf( "Invalid relative timespec.\n" );
+ if (!Com_ParseTimespec(to + 1, &frames)) {
+ Com_Printf("Invalid relative timespec.\n");
return;
}
- if( *to == '-' )
+ if (*to == '-')
frames = -frames;
dest = mvd->framenum + frames;
} else {
// relative to first frame
- if( !Com_ParseTimespec( to, &dest ) ) {
- Com_Printf( "Invalid absolute timespec.\n" );
+ if (!Com_ParseTimespec(to, &dest)) {
+ Com_Printf("Invalid absolute timespec.\n");
return;
}
frames = dest - mvd->framenum;
}
- if( !frames )
+ if (!frames)
// already there
return;
- if( setjmp( mvd_jmpbuf ) )
+ if (setjmp(mvd_jmpbuf))
return;
// disable effects processing
mvd->demoseeking = qtrue;
// clear dirty configstrings
- memset( mvd->dcs, 0, sizeof( mvd->dcs ) );
+ memset(mvd->dcs, 0, sizeof(mvd->dcs));
- Com_DPrintf( "[%d] seeking to %d\n", mvd->framenum, dest );
+ Com_DPrintf("[%d] seeking to %d\n", mvd->framenum, dest);
// seek to the previous most recent snapshot
- if( frames < 0 || mvd->last_snapshot > mvd->framenum ) {
- snap = demo_find_snapshot( mvd, dest );
-
- if( snap ) {
- Com_DPrintf( "found snap at %d\n", snap->framenum );
- ret = FS_Seek( gtv->demoplayback, snap->filepos );
- if( ret < 0 ) {
- Com_EPrintf( "[%s] Couldn't seek demo: %s\n", mvd->name, Q_ErrorString( ret ) );
+ if (frames < 0 || mvd->last_snapshot > mvd->framenum) {
+ snap = demo_find_snapshot(mvd, dest);
+
+ if (snap) {
+ Com_DPrintf("found snap at %d\n", snap->framenum);
+ ret = FS_Seek(gtv->demoplayback, snap->filepos);
+ if (ret < 0) {
+ Com_EPrintf("[%s] Couldn't seek demo: %s\n", mvd->name, Q_ErrorString(ret));
goto done;
}
// clear delta state
- MVD_ClearState( mvd, qfalse );
+ MVD_ClearState(mvd, qfalse);
// reset configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = mvd->baseconfigstrings[i];
to = mvd->configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- Q_SetBit( mvd->dcs, i );
- strcpy( to, from );
+ Q_SetBit(mvd->dcs, i);
+ strcpy(to, from);
}
// set player names
- MVD_SetPlayerNames( mvd );
+ MVD_SetPlayerNames(mvd);
- SZ_Init( &msg_read, snap->data, snap->msglen );
+ SZ_Init(&msg_read, snap->data, snap->msglen);
msg_read.cursize = snap->msglen;
- MVD_ParseMessage( mvd );
+ MVD_ParseMessage(mvd);
mvd->framenum = snap->framenum;
- } else if( frames < 0 ) {
- Com_Printf( "[%s] Couldn't seek backwards without snapshots!\n", mvd->name );
+ } else if (frames < 0) {
+ Com_Printf("[%s] Couldn't seek backwards without snapshots!\n", mvd->name);
goto done;
}
}
// skip forward to destination frame
- while( mvd->framenum < dest ) {
- ret = demo_read_message( gtv->demoplayback );
- if( ret <= 0 ) {
- demo_finish( gtv, ret );
+ while (mvd->framenum < dest) {
+ ret = demo_read_message(gtv->demoplayback);
+ if (ret <= 0) {
+ demo_finish(gtv, ret);
return;
}
- gamestate = MVD_ParseMessage( mvd );
+ gamestate = MVD_ParseMessage(mvd);
- demo_emit_snapshot( mvd );
+ demo_emit_snapshot(mvd);
- if( gamestate ) {
+ if (gamestate) {
// got a gamestate, abort seek
- Com_DPrintf( "got gamestate while seeking!\n" );
+ Com_DPrintf("got gamestate while seeking!\n");
goto done;
}
}
- Com_DPrintf( "[%d] after skip\n", mvd->framenum );
+ Com_DPrintf("[%d] after skip\n", mvd->framenum);
// update dirty configstrings
- for( i = 0; i < CS_BITMAP_LONGS; i++ ) {
- if( ((uint32_t *)mvd->dcs)[i] == 0 )
+ for (i = 0; i < CS_BITMAP_LONGS; i++) {
+ if (((uint32_t *)mvd->dcs)[i] == 0)
continue;
index = i << 5;
- for( j = 0; j < 32; j++, index++ ) {
- if( Q_IsBitSet( mvd->dcs, index ) )
- MVD_UpdateConfigstring( mvd, index );
+ for (j = 0; j < 32; j++, index++) {
+ if (Q_IsBitSet(mvd->dcs, index))
+ MVD_UpdateConfigstring(mvd, index);
}
}
// ouch
- CM_SetPortalStates( &mvd->cm, NULL, 0 );
+ CM_SetPortalStates(&mvd->cm, NULL, 0);
// init world entity
ent = &mvd->edicts[0];
@@ -2220,32 +2289,33 @@ static void MVD_Seek_f( void ) {
ent->inuse = qtrue;
// relink entities, reset origins and events
- for( i = 1; i < mvd->pool.num_edicts; i++ ) {
+ for (i = 1; i < mvd->pool.num_edicts; i++) {
ent = &mvd->edicts[i];
- if( !ent->inuse )
+ if (!ent->inuse)
continue;
- MVD_LinkEdict( mvd, ent );
+ MVD_LinkEdict(mvd, ent);
- if( !( ent->s.renderfx & RF_BEAM ) )
- VectorCopy( ent->s.origin, ent->s.old_origin );
+ if (!(ent->s.renderfx & RF_BEAM))
+ VectorCopy(ent->s.origin, ent->s.old_origin);
ent->s.event = EV_OTHER_TELEPORT;
}
- MVD_UpdateClients( mvd );
+ MVD_UpdateClients(mvd);
// wait one frame to give entity events a chance to be communicated back to
// clients
gtv->demowait = qtrue;
- demo_update( gtv );
+ demo_update(gtv);
done:
mvd->demoseeking = qfalse;
}
-static void MVD_Control_f( void ) {
+static void MVD_Control_f(void)
+{
static const cmd_option_t options[] = {
{ "h", "help", "display this message" },
{ "l:number", "loop", "replay <number> of times (0 means forever)" },
@@ -2258,17 +2328,17 @@ static void MVD_Control_f( void ) {
int todo = 0;
int c;
- while( ( c = Cmd_ParseOptions( options ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(options)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( options, "[chanid]" );
- Com_Printf( "Change attributes of existing MVD channel.\n" );
- Cmd_PrintHelp( options );
+ Cmd_PrintUsage(options, "[chanid]");
+ Com_Printf("Change attributes of existing MVD channel.\n");
+ Cmd_PrintHelp(options);
return;
case 'l':
- loop = atoi( cmd_optarg );
- if( loop < 0 ) {
- Com_Printf( "Invalid value for %s option.\n", cmd_optopt );
+ loop = atoi(cmd_optarg);
+ if (loop < 0) {
+ Com_Printf("Invalid value for %s option.\n", cmd_optopt);
Cmd_PrintHint();
return;
}
@@ -2283,24 +2353,24 @@ static void MVD_Control_f( void ) {
}
}
- if( !todo ) {
- Com_Printf( "At least one option needed.\n" );
+ if (!todo) {
+ Com_Printf("At least one option needed.\n");
Cmd_PrintHint();
return;
}
- mvd = MVD_SetChannel( cmd_optind );
- if( !mvd ) {
+ mvd = MVD_SetChannel(cmd_optind);
+ if (!mvd) {
Cmd_PrintHint();
return;
}
- if( name ) {
- Com_Printf( "[%s] Channel renamed to %s.\n", mvd->name, name );
- Q_strlcpy( mvd->name, name, sizeof( mvd->name ) );
+ if (name) {
+ Com_Printf("[%s] Channel renamed to %s.\n", mvd->name, name);
+ Q_strlcpy(mvd->name, name, sizeof(mvd->name));
}
- if( loop != -1 ) {
- //Com_Printf( "[%s] Loop count changed to %d.\n", mvd->name, loop );
+ if (loop != -1) {
+ //Com_Printf("[%s] Loop count changed to %d.\n", mvd->name, loop);
//mvd->demoloop = loop;
}
}
@@ -2315,15 +2385,18 @@ static const cmd_option_t o_mvdplay[] = {
{ NULL }
};
-void MVD_File_g( genctx_t *ctx ) {
- FS_File_g( "demos", "*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx );
+void MVD_File_g(genctx_t *ctx)
+{
+ FS_File_g("demos", "*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx);
}
-static void MVD_Play_c( genctx_t *ctx, int argnum ) {
- Cmd_Option_c( o_mvdplay, MVD_File_g, ctx, argnum );
+static void MVD_Play_c(genctx_t *ctx, int argnum)
+{
+ Cmd_Option_c(o_mvdplay, MVD_File_g, ctx, argnum);
}
-static void MVD_Play_f( void ) {
+static void MVD_Play_f(void)
+{
char *name = NULL;
char buffer[MAX_OSPATH];
int loop = -1, chan_id = -1;
@@ -2334,19 +2407,19 @@ static void MVD_Play_f( void ) {
string_entry_t *entry, *head;
int i;
- while( ( c = Cmd_ParseOptions( o_mvdplay ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_mvdplay)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_mvdplay, "[/]<filename> [...]" );
- Com_Printf( "Create new MVD channel and begin demo playback.\n" );
- Cmd_PrintHelp( o_mvdplay );
- Com_Printf( "Final path is formatted as demos/<filename>.mvd2.\n"
- "Prepend slash to specify raw path.\n" );
+ Cmd_PrintUsage(o_mvdplay, "[/]<filename> [...]");
+ Com_Printf("Create new MVD channel and begin demo playback.\n");
+ Cmd_PrintHelp(o_mvdplay);
+ Com_Printf("Final path is formatted as demos/<filename>.mvd2.\n"
+ "Prepend slash to specify raw path.\n");
return;
case 'l':
- loop = atoi( cmd_optarg );
- if( loop < 0 ) {
- Com_Printf( "Invalid value for %s option.\n", cmd_optopt );
+ loop = atoi(cmd_optarg);
+ if (loop < 0) {
+ Com_Printf("Invalid value for %s option.\n", cmd_optopt);
Cmd_PrintHint();
return;
}
@@ -2363,106 +2436,107 @@ static void MVD_Play_f( void ) {
}
argc = Cmd_Argc();
- if( cmd_optind == argc ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (cmd_optind == argc) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
- if( chan_id != -1 ) {
- mvd_t *mvd = MVD_SetChannel( chan_id );
- if( mvd ) {
+ if (chan_id != -1) {
+ mvd_t *mvd = MVD_SetChannel(chan_id);
+ if (mvd) {
gtv = mvd->gtv;
}
}
// build the playlist
head = NULL;
- for( i = argc - 1; i >= cmd_optind; i-- ) {
+ for (i = argc - 1; i >= cmd_optind; i--) {
// try to open it
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), FS_MODE_READ,
- "demos/", Cmd_Argv( i ), ".mvd2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), FS_MODE_READ,
+ "demos/", Cmd_Argv(i), ".mvd2");
+ if (!f) {
continue;
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- len = strlen( buffer );
- entry = MVD_Malloc( sizeof( *entry ) + len );
- memcpy( entry->string, buffer, len + 1 );
+ len = strlen(buffer);
+ entry = MVD_Malloc(sizeof(*entry) + len);
+ memcpy(entry->string, buffer, len + 1);
entry->next = head;
head = entry;
}
- if( !head ) {
+ if (!head) {
return;
}
- if( gtv ) {
+ if (gtv) {
// free existing playlist
- demo_free_playlist( gtv );
+ demo_free_playlist(gtv);
} else {
// create new connection
- gtv = MVD_Mallocz( sizeof( *gtv ) );
+ gtv = MVD_Mallocz(sizeof(*gtv));
gtv->id = mvd_chanid++;
gtv->state = GTV_READING;
gtv->drop = demo_destroy;
gtv->destroy = demo_destroy;
gtv->demoloop = 1;
- Q_snprintf( gtv->name, sizeof( gtv->name ), "dem%d", gtv->id );
+ Q_snprintf(gtv->name, sizeof(gtv->name), "dem%d", gtv->id);
}
// set channel name
- if( name ) {
- Q_strlcpy( gtv->name, name, sizeof( gtv->name ) );
+ if (name) {
+ Q_strlcpy(gtv->name, name, sizeof(gtv->name));
}
// set loop parameter
- if( loop != -1 ) {
+ if (loop != -1) {
gtv->demoloop = loop;
}
// set new playlist
gtv->demohead = head;
- if( setjmp( mvd_jmpbuf ) ) {
+ if (setjmp(mvd_jmpbuf)) {
return;
}
- demo_play_next( gtv, head );
+ demo_play_next(gtv, head);
}
-void MVD_Shutdown( void ) {
+void MVD_Shutdown(void)
+{
gtv_t *gtv, *gtv_next;
mvd_t *mvd, *mvd_next;
// kill all GTV connections
- LIST_FOR_EACH_SAFE( gtv_t, gtv, gtv_next, &mvd_gtv_list, entry ) {
- gtv->destroy( gtv );
+ LIST_FOR_EACH_SAFE(gtv_t, gtv, gtv_next, &mvd_gtv_list, entry) {
+ gtv->destroy(gtv);
}
// kill all MVD channels (including demo GTVs)
- LIST_FOR_EACH_SAFE( mvd_t, mvd, mvd_next, &mvd_channel_list, entry ) {
- if( mvd->gtv ) {
+ LIST_FOR_EACH_SAFE(mvd_t, mvd, mvd_next, &mvd_channel_list, entry) {
+ if (mvd->gtv) {
mvd->gtv->mvd = NULL; // don't double destroy
- mvd->gtv->destroy( mvd->gtv );
+ mvd->gtv->destroy(mvd->gtv);
}
- MVD_Free( mvd );
+ MVD_Free(mvd);
}
- List_Init( &mvd_gtv_list );
- List_Init( &mvd_channel_list );
+ List_Init(&mvd_gtv_list);
+ List_Init(&mvd_channel_list);
- Z_Free( mvd_clients );
+ Z_Free(mvd_clients);
mvd_clients = NULL;
mvd_chanid = 0;
mvd_active = qfalse;
- Z_LeakTest( TAG_MVD );
+ Z_LeakTest(TAG_MVD);
}
static const cmdreg_t c_mvd[] = {
@@ -2487,19 +2561,20 @@ static const cmdreg_t c_mvd[] = {
MVD_Register
==============
*/
-void MVD_Register( void ) {
+void MVD_Register(void)
+{
#ifdef _DEBUG
- mvd_shownet = Cvar_Get( "mvd_shownet", "0", 0 );
+ mvd_shownet = Cvar_Get("mvd_shownet", "0", 0);
#endif
- mvd_timeout = Cvar_Get( "mvd_timeout", "90", 0 );
- mvd_suspend_time = Cvar_Get( "mvd_suspend_time", "5", 0 );
- mvd_wait_delay = Cvar_Get( "mvd_wait_delay", "20", 0 );
- mvd_wait_percent = Cvar_Get( "mvd_wait_percent", "35", 0 );
- mvd_buffer_size = Cvar_Get( "mvd_buffer_size", "3", 0 );
- mvd_username = Cvar_Get( "mvd_username", "unnamed", 0 );
- mvd_password = Cvar_Get( "mvd_password", "", CVAR_PRIVATE );
- mvd_snaps = Cvar_Get( "mvd_snaps", "10", 0 );
-
- Cmd_Register( c_mvd );
+ mvd_timeout = Cvar_Get("mvd_timeout", "90", 0);
+ mvd_suspend_time = Cvar_Get("mvd_suspend_time", "5", 0);
+ mvd_wait_delay = Cvar_Get("mvd_wait_delay", "20", 0);
+ mvd_wait_percent = Cvar_Get("mvd_wait_percent", "35", 0);
+ mvd_buffer_size = Cvar_Get("mvd_buffer_size", "3", 0);
+ mvd_username = Cvar_Get("mvd_username", "unnamed", 0);
+ mvd_password = Cvar_Get("mvd_password", "", CVAR_PRIVATE);
+ mvd_snaps = Cvar_Get("mvd_snaps", "10", 0);
+
+ Cmd_Register(c_mvd);
}
diff --git a/src/mvd_game.c b/src/mvd_game.c
index 0c15c2a..838bbf7 100644
--- a/src/mvd_game.c
+++ b/src/mvd_game.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -45,7 +45,7 @@ extern jmp_buf mvd_jmpbuf;
static int mvd_numplayers;
-static void MVD_UpdateClient( mvd_client_t *client );
+static void MVD_UpdateClient(mvd_client_t *client);
/*
==============================================================================
@@ -58,10 +58,11 @@ LAYOUTS
// clients per screen page
#define PAGE_CLIENTS 16
-#define VER_OFS ( 272 - ( int )( sizeof( VERSION ) - 1 ) * CHAR_WIDTH )
+#define VER_OFS (272 - (int)(sizeof(VERSION) - 1) * CHAR_WIDTH)
-static void MVD_LayoutClients( mvd_client_t *client ) {
- static const char header[] =
+static void MVD_LayoutClients(mvd_client_t *client)
+{
+ static const char header[] =
"xv 16 yv 0 string2 \" Name RTT Status\"";
char layout[MAX_STRING_CHARS];
char buffer[MAX_QPATH];
@@ -72,48 +73,48 @@ static void MVD_LayoutClients( mvd_client_t *client ) {
int y, i, prestep, flags;
// calculate prestep
- if( client->layout_cursor < 0 ) {
+ if (client->layout_cursor < 0) {
client->layout_cursor = 0;
- } else if( client->layout_cursor ) {
- total = List_Count( &mvd->clients );
- if( client->layout_cursor > total / PAGE_CLIENTS ) {
+ } else if (client->layout_cursor) {
+ total = List_Count(&mvd->clients);
+ if (client->layout_cursor > total / PAGE_CLIENTS) {
client->layout_cursor = total / PAGE_CLIENTS;
}
}
prestep = client->layout_cursor * PAGE_CLIENTS;
- memcpy( layout, header, sizeof( header ) - 1 );
- total = sizeof( header ) - 1;
+ memcpy(layout, header, sizeof(header) - 1);
+ total = sizeof(header) - 1;
y = 8;
i = 0;
- FOR_EACH_MVDCL( cl, mvd ) {
- if( ++i < prestep ) {
+ FOR_EACH_MVDCL(cl, mvd) {
+ if (++i < prestep) {
continue;
}
- if( cl->cl->state < cs_spawned ) {
+ if (cl->cl->state < cs_spawned) {
continue;
}
- if( cl->target ) {
- strcpy( status, "-> " );
- strcpy( status + 3, cl->target->name );
+ if (cl->target) {
+ strcpy(status, "-> ");
+ strcpy(status + 3, cl->target->name);
} else {
- strcpy( status, "observing" );
+ strcpy(status, "observing");
}
- len = Q_snprintf( buffer, sizeof( buffer ),
- "yv %d string \"%3d %-15.15s %3d %s\"",
- y, i, cl->cl->name, cl->ping, status );
- if( len >= sizeof( buffer ) ) {
+ len = Q_snprintf(buffer, sizeof(buffer),
+ "yv %d string \"%3d %-15.15s %3d %s\"",
+ y, i, cl->cl->name, cl->ping, status);
+ if (len >= sizeof(buffer)) {
continue;
}
- if( total + len >= sizeof( layout ) ) {
+ if (total + len >= sizeof(layout)) {
break;
}
- memcpy( layout + total, buffer, len );
+ memcpy(layout + total, buffer, len);
total += len;
- if( y > 8 * PAGE_CLIENTS ) {
+ if (y > 8 * PAGE_CLIENTS) {
break;
}
y += 8;
@@ -123,31 +124,33 @@ static void MVD_LayoutClients( mvd_client_t *client ) {
// the very first layout update is reliably delivered
flags = MSG_CLEAR;
- if( !client->layout_time ) {
+ if (!client->layout_time) {
flags |= MSG_RELIABLE;
}
// send the layout
- MSG_WriteByte( svc_layout );
- MSG_WriteData( layout, total + 1 );
- SV_ClientAddMessage( client->cl, flags );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteData(layout, total + 1);
+ SV_ClientAddMessage(client->cl, flags);
client->layout_time = svs.realtime;
}
-static int MVD_CountClients( mvd_t *mvd ) {
+static int MVD_CountClients(mvd_t *mvd)
+{
mvd_client_t *c;
int count = 0;
- FOR_EACH_MVDCL( c, mvd ) {
- if( c->cl->state == cs_spawned ) {
+ FOR_EACH_MVDCL(c, mvd) {
+ if (c->cl->state == cs_spawned) {
count++;
}
}
return count;
}
-static void MVD_LayoutChannels( mvd_client_t *client ) {
+static void MVD_LayoutChannels(mvd_client_t *client)
+{
static const char header[] =
"xv 32 yv 8 picn inventory "
"xv %d yv 172 string2 " VERSION " "
@@ -165,37 +168,37 @@ static void MVD_LayoutChannels( mvd_client_t *client ) {
size_t len, total;
int cursor, y;
- total = Q_scnprintf( layout, sizeof( layout ),
- header, VER_OFS );
+ total = Q_scnprintf(layout, sizeof(layout),
+ header, VER_OFS);
// FIXME: improve this
- cursor = List_Count( &mvd_channel_list );
- if( cursor ) {
- if( client->layout_cursor < 0 ) {
+ cursor = List_Count(&mvd_channel_list);
+ if (cursor) {
+ if (client->layout_cursor < 0) {
client->layout_cursor = cursor - 1;
- } else if( client->layout_cursor > cursor - 1 ) {
+ } else if (client->layout_cursor > cursor - 1) {
client->layout_cursor = 0;
}
y = 64;
cursor = 0;
- FOR_EACH_MVD( mvd ) {
- len = Q_snprintf( buffer, sizeof( buffer ),
- "yv %d string%s \"%c%-12.12s %-7.7s %d/%d\" ", y,
- mvd == client->mvd ? "2" : "",
- cursor == client->layout_cursor ? 0x8d : 0x20,
- mvd->name, mvd->mapname,
- MVD_CountClients( mvd ), mvd->numplayers );
- if( len >= sizeof( buffer ) ) {
+ FOR_EACH_MVD(mvd) {
+ len = Q_snprintf(buffer, sizeof(buffer),
+ "yv %d string%s \"%c%-12.12s %-7.7s %d/%d\" ", y,
+ mvd == client->mvd ? "2" : "",
+ cursor == client->layout_cursor ? 0x8d : 0x20,
+ mvd->name, mvd->mapname,
+ MVD_CountClients(mvd), mvd->numplayers);
+ if (len >= sizeof(buffer)) {
continue;
}
- if( total + len >= sizeof( layout ) ) {
+ if (total + len >= sizeof(layout)) {
break;
}
- memcpy( layout + total, buffer, len );
+ memcpy(layout + total, buffer, len);
total += len;
y += 8;
- if( y > 164 ) {
+ if (y > 164) {
break;
}
@@ -203,16 +206,16 @@ static void MVD_LayoutChannels( mvd_client_t *client ) {
}
} else {
client->layout_cursor = 0;
- memcpy( layout + total, nochans, sizeof( nochans ) - 1 );
- total += sizeof( nochans ) - 1;
+ memcpy(layout + total, nochans, sizeof(nochans) - 1);
+ total += sizeof(nochans) - 1;
}
layout[total] = 0;
// send the layout
- MSG_WriteByte( svc_layout );
- MSG_WriteData( layout, total + 1 );
- SV_ClientAddMessage( client->cl, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteData(layout, total + 1);
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE | MSG_CLEAR);
client->layout_time = svs.realtime;
}
@@ -221,16 +224,18 @@ static void MVD_LayoutChannels( mvd_client_t *client ) {
#define YES "\xD9\xE5\xF3"
#define NO "\xCE\xEF"
-static int clamp_menu_cursor( mvd_client_t *client ) {
- if( client->layout_cursor < 0 ) {
+static int clamp_menu_cursor(mvd_client_t *client)
+{
+ if (client->layout_cursor < 0) {
client->layout_cursor = MENU_ITEMS - 1;
- } else if( client->layout_cursor > MENU_ITEMS - 1 ) {
+ } else if (client->layout_cursor > MENU_ITEMS - 1) {
client->layout_cursor = 0;
}
return client->layout_cursor;
}
-static void MVD_LayoutMenu( mvd_client_t *client ) {
+static void MVD_LayoutMenu(mvd_client_t *client)
+{
static const char format[] =
"xv 32 yv 8 picn inventory "
"xv 0 yv 32 cstring \"\020Main Menu\021\" xv 56 "
@@ -250,149 +255,156 @@ static void MVD_LayoutMenu( mvd_client_t *client ) {
char cur[MENU_ITEMS];
size_t total;
- memset( cur, 0x20, sizeof( cur ) );
- cur[ clamp_menu_cursor( client ) ] = 0x8d;
-
- total = Q_scnprintf( layout, sizeof( layout ), format,
- cur[0], client->target ? "Leave" : "Enter", cur[1],
- cur[2], MVD_CountClients( client->mvd ),
- cur[3], List_Count( &mvd_channel_list ), cur[4],
- cur[5], ( client->uf & UF_MUTE_OBSERVERS ) ? YES : NO,
- cur[6], ( client->uf & UF_MUTE_MISC ) ? YES : NO,
- cur[7], ( client->uf & UF_MUTE_PLAYERS ) ? YES: NO,
- cur[8], ( client->uf & UF_LOCALFOV ) ? YES : NO,
- client->uf,
- cur[9], client->mvd->state == MVD_WAITING ?
- "xv 0 yv 160 cstring [BUFFERING]" : "",
- VER_OFS );
+ memset(cur, 0x20, sizeof(cur));
+ cur[clamp_menu_cursor(client)] = 0x8d;
+
+ total = Q_scnprintf(layout, sizeof(layout), format,
+ cur[0], client->target ? "Leave" : "Enter", cur[1],
+ cur[2], MVD_CountClients(client->mvd),
+ cur[3], List_Count(&mvd_channel_list), cur[4],
+ cur[5], (client->uf & UF_MUTE_OBSERVERS) ? YES : NO,
+ cur[6], (client->uf & UF_MUTE_MISC) ? YES : NO,
+ cur[7], (client->uf & UF_MUTE_PLAYERS) ? YES : NO,
+ cur[8], (client->uf & UF_LOCALFOV) ? YES : NO,
+ client->uf,
+ cur[9], client->mvd->state == MVD_WAITING ?
+ "xv 0 yv 160 cstring [BUFFERING]" : "",
+ VER_OFS);
// send the layout
- MSG_WriteByte( svc_layout );
- MSG_WriteData( layout, total + 1 );
- SV_ClientAddMessage( client->cl, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteData(layout, total + 1);
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE | MSG_CLEAR);
client->layout_time = svs.realtime;
}
-static void MVD_LayoutScores( mvd_client_t *client ) {
+static void MVD_LayoutScores(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
int flags = MSG_CLEAR;
char *layout;
- if( client->layout_type == LAYOUT_OLDSCORES ) {
+ if (client->layout_type == LAYOUT_OLDSCORES) {
layout = mvd->oldscores;
} else {
layout = mvd->layout;
}
- if( !layout || !layout[0] ) {
+ if (!layout || !layout[0]) {
layout = "xv 100 yv 60 string \"<no scoreboard>\"";
}
// end-of-match scoreboard is reliably delivered
- if( !client->layout_time || mvd->intermission ) {
+ if (!client->layout_time || mvd->intermission) {
flags |= MSG_RELIABLE;
}
// send the layout
- MSG_WriteByte( svc_layout );
- MSG_WriteString( layout );
- SV_ClientAddMessage( client->cl, flags );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteString(layout);
+ SV_ClientAddMessage(client->cl, flags);
client->layout_time = svs.realtime;
}
-static void MVD_LayoutFollow( mvd_client_t *client ) {
+static void MVD_LayoutFollow(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
char *name = client->target ? client->target->name : "<no target>";
char layout[MAX_STRING_CHARS];
size_t total;
- total = Q_scnprintf( layout, sizeof( layout ),
- "%s string \"[%s] Chasing %s\"",
- mvd_chase_prefix->string, mvd->name, name );
+ total = Q_scnprintf(layout, sizeof(layout),
+ "%s string \"[%s] Chasing %s\"",
+ mvd_chase_prefix->string, mvd->name, name);
// send the layout
- MSG_WriteByte( svc_layout );
- MSG_WriteData( layout, total + 1 );
- SV_ClientAddMessage( client->cl, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteData(layout, total + 1);
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE | MSG_CLEAR);
client->layout_time = svs.realtime;
}
-static void MVD_SetNewLayout( mvd_client_t *client, mvd_layout_t type ) {
+static void MVD_SetNewLayout(mvd_client_t *client, mvd_layout_t type)
+{
// force an update
client->layout_type = type;
client->layout_time = 0;
client->layout_cursor = 0;
}
-static void MVD_SetDefaultLayout( mvd_client_t *client ) {
+static void MVD_SetDefaultLayout(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_layout_t type;
- if( mvd == &mvd_waitingRoom ) {
+ if (mvd == &mvd_waitingRoom) {
type = LAYOUT_CHANNELS;
- } else if( mvd->intermission ) {
+ } else if (mvd->intermission) {
type = LAYOUT_SCORES;
- } else if( client->target ) {
+ } else if (client->target) {
type = LAYOUT_FOLLOW;
} else {
type = LAYOUT_NONE;
}
- MVD_SetNewLayout( client, type );
+ MVD_SetNewLayout(client, type);
}
-static void MVD_ToggleLayout( mvd_client_t *client, mvd_layout_t type ) {
- if( client->layout_type == type ) {
- MVD_SetDefaultLayout( client );
+static void MVD_ToggleLayout(mvd_client_t *client, mvd_layout_t type)
+{
+ if (client->layout_type == type) {
+ MVD_SetDefaultLayout(client);
} else {
- MVD_SetNewLayout( client, type );
+ MVD_SetNewLayout(client, type);
}
}
-static void MVD_SetFollowLayout( mvd_client_t *client ) {
- if( !client->layout_type ) {
- MVD_SetDefaultLayout( client );
- } else if( client->layout_type == LAYOUT_FOLLOW ) {
+static void MVD_SetFollowLayout(mvd_client_t *client)
+{
+ if (!client->layout_type) {
+ MVD_SetDefaultLayout(client);
+ } else if (client->layout_type == LAYOUT_FOLLOW) {
client->layout_time = 0; // force an update
}
}
// this is the only function that actually writes layouts
-static void MVD_UpdateLayouts( mvd_t *mvd ) {
+static void MVD_UpdateLayouts(mvd_t *mvd)
+{
mvd_client_t *client;
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state != cs_spawned ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state != cs_spawned) {
continue;
}
client->ps.stats[STAT_LAYOUTS] = client->layout_type ? 1 : 0;
- switch( client->layout_type ) {
+ switch (client->layout_type) {
case LAYOUT_FOLLOW:
- if( !client->layout_time ) {
- MVD_LayoutFollow( client );
+ if (!client->layout_time) {
+ MVD_LayoutFollow(client);
}
break;
case LAYOUT_OLDSCORES:
case LAYOUT_SCORES:
- if( !client->layout_time ) {
- MVD_LayoutScores( client );
+ if (!client->layout_time) {
+ MVD_LayoutScores(client);
}
break;
case LAYOUT_MENU:
- if( mvd->dirty || !client->layout_time ) {
- MVD_LayoutMenu( client );
+ if (mvd->dirty || !client->layout_time) {
+ MVD_LayoutMenu(client);
}
break;
case LAYOUT_CLIENTS:
- if( svs.realtime - client->layout_time > LAYOUT_MSEC ) {
- MVD_LayoutClients( client );
+ if (svs.realtime - client->layout_time > LAYOUT_MSEC) {
+ MVD_LayoutClients(client);
}
break;
case LAYOUT_CHANNELS:
- if( mvd_dirty || !client->layout_time ) {
- MVD_LayoutChannels( client );
+ if (mvd_dirty || !client->layout_time) {
+ MVD_LayoutChannels(client);
}
break;
default:
@@ -412,28 +424,30 @@ CHASE CAMERA
==============================================================================
*/
-static void write_cs_list( mvd_client_t *client, mvd_cs_t *cs ) {
- for( ; cs; cs = cs->next ) {
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( cs->index );
- MSG_WriteString( cs->string );
- SV_ClientAddMessage( client->cl, MSG_RELIABLE|MSG_CLEAR );
+static void write_cs_list(mvd_client_t *client, mvd_cs_t *cs)
+{
+ for (; cs; cs = cs->next) {
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(cs->index);
+ MSG_WriteString(cs->string);
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE | MSG_CLEAR);
}
}
-static void MVD_FollowStop( mvd_client_t *client ) {
+static void MVD_FollowStop(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
int i;
client->ps.viewangles[ROLL] = 0;
- for( i = 0; i < 3; i++ ) {
+ for (i = 0; i < 3; i++) {
client->ps.pmove.delta_angles[i] = ANGLE2SHORT(
- client->ps.viewangles[i] ) - client->lastcmd.angles[i];
+ client->ps.viewangles[i]) - client->lastcmd.angles[i];
}
- VectorClear( client->ps.kick_angles );
- Vector4Clear( client->ps.blend );
+ VectorClear(client->ps.kick_angles);
+ Vector4Clear(client->ps.blend);
client->ps.pmove.pm_flags = 0;
client->ps.pmove.pm_type = mvd->pm_type;
client->ps.rdflags = 0;
@@ -441,22 +455,23 @@ static void MVD_FollowStop( mvd_client_t *client ) {
client->ps.fov = client->fov;
// send delta configstrings
- write_cs_list( client, mvd->dummy->configstrings );
+ write_cs_list(client, mvd->dummy->configstrings);
client->clientNum = mvd->clientNum;
client->oldtarget = client->target;
client->target = NULL;
client->chase_mask = 0;
- if( client->layout_type == LAYOUT_FOLLOW ) {
- MVD_SetDefaultLayout( client );
+ if (client->layout_type == LAYOUT_FOLLOW) {
+ MVD_SetDefaultLayout(client);
}
- MVD_UpdateClient( client );
+ MVD_UpdateClient(client);
}
-static void MVD_FollowStart( mvd_client_t *client, mvd_player_t *target ) {
- if( client->target == target ) {
+static void MVD_FollowStart(mvd_client_t *client, mvd_player_t *target)
+{
+ if (client->target == target) {
return;
}
@@ -465,109 +480,114 @@ static void MVD_FollowStart( mvd_client_t *client, mvd_player_t *target ) {
client->chase_mask = 0;
// send delta configstrings
- write_cs_list( client, target->configstrings );
+ write_cs_list(client, target->configstrings);
- SV_ClientPrintf( client->cl, PRINT_LOW, "[MVD] Chasing %s.\n", target->name );
+ SV_ClientPrintf(client->cl, PRINT_LOW, "[MVD] Chasing %s.\n", target->name);
- MVD_SetFollowLayout( client );
- MVD_UpdateClient( client );
+ MVD_SetFollowLayout(client);
+ MVD_UpdateClient(client);
}
-static void MVD_FollowFirst( mvd_client_t *client ) {
+static void MVD_FollowFirst(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *target;
int i;
// pick up the first active player
- for( i = 0; i < mvd->maxclients; i++ ) {
+ for (i = 0; i < mvd->maxclients; i++) {
target = &mvd->players[i];
- if( target->inuse && target != mvd->dummy ) {
- MVD_FollowStart( client, target );
+ if (target->inuse && target != mvd->dummy) {
+ MVD_FollowStart(client, target);
return;
}
}
- SV_ClientPrintf( client->cl, PRINT_MEDIUM, "[MVD] No players to chase.\n" );
+ SV_ClientPrintf(client->cl, PRINT_MEDIUM, "[MVD] No players to chase.\n");
}
-static void MVD_FollowLast( mvd_client_t *client ) {
+static void MVD_FollowLast(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *target;
int i;
// pick up the last active player
- for( i = 0; i < mvd->maxclients; i++ ) {
- target = &mvd->players[ mvd->maxclients - i - 1 ];
- if( target->inuse && target != mvd->dummy ) {
- MVD_FollowStart( client, target );
+ for (i = 0; i < mvd->maxclients; i++) {
+ target = &mvd->players[mvd->maxclients - i - 1];
+ if (target->inuse && target != mvd->dummy) {
+ MVD_FollowStart(client, target);
return;
}
}
- SV_ClientPrintf( client->cl, PRINT_MEDIUM, "[MVD] No players to chase.\n" );
+ SV_ClientPrintf(client->cl, PRINT_MEDIUM, "[MVD] No players to chase.\n");
}
-static void MVD_FollowNext( mvd_client_t *client ) {
+static void MVD_FollowNext(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *target = client->target;
- if( !target ) {
- MVD_FollowFirst( client );
+ if (!target) {
+ MVD_FollowFirst(client);
return;
}
do {
- if( target == mvd->players + mvd->maxclients - 1 ) {
+ if (target == mvd->players + mvd->maxclients - 1) {
target = mvd->players;
} else {
target++;
}
- if( target == client->target ) {
+ if (target == client->target) {
return;
}
- } while( !target->inuse || target == mvd->dummy );
+ } while (!target->inuse || target == mvd->dummy);
- MVD_FollowStart( client, target );
+ MVD_FollowStart(client, target);
}
-static void MVD_FollowPrev( mvd_client_t *client ) {
+static void MVD_FollowPrev(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *target = client->target;
- if( !target ) {
- MVD_FollowLast( client );
+ if (!target) {
+ MVD_FollowLast(client);
return;
}
do {
- if( target == mvd->players ) {
+ if (target == mvd->players) {
target = mvd->players + mvd->maxclients - 1;
} else {
target--;
}
- if( target == client->target ) {
+ if (target == client->target) {
return;
}
- } while( !target->inuse || target == mvd->dummy );
+ } while (!target->inuse || target == mvd->dummy);
- MVD_FollowStart( client, target );
+ MVD_FollowStart(client, target);
}
-static mvd_player_t *MVD_MostFollowed( mvd_t *mvd ) {
+static mvd_player_t *MVD_MostFollowed(mvd_t *mvd)
+{
int count[MAX_CLIENTS];
mvd_client_t *other;
mvd_player_t *player, *target = NULL;
int i, maxcount = -1;
- memset( count, 0, sizeof( count ) );
+ memset(count, 0, sizeof(count));
- FOR_EACH_MVDCL( other, mvd ) {
- if( other->cl->state == cs_spawned && other->target ) {
- count[ other->target - mvd->players ]++;
+ FOR_EACH_MVDCL(other, mvd) {
+ if (other->cl->state == cs_spawned && other->target) {
+ count[other->target - mvd->players]++;
}
}
- for( i = 0, player = mvd->players; i < mvd->maxclients; i++, player++ ) {
- if( player->inuse && player != mvd->dummy && maxcount < count[i] ) {
+ for (i = 0, player = mvd->players; i < mvd->maxclients; i++, player++) {
+ if (player->inuse && player != mvd->dummy && maxcount < count[i]) {
maxcount = count[i];
target = player;
}
@@ -575,21 +595,22 @@ static mvd_player_t *MVD_MostFollowed( mvd_t *mvd ) {
return target;
}
-static void MVD_UpdateClient( mvd_client_t *client ) {
+static void MVD_UpdateClient(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *target;
int i, mask = client->chase_mask;
entity_state_t *ent;
- if( mask ) {
+ if (mask) {
// find new target for auto chasecam
- for( i = 0, target = mvd->players; i < mvd->maxclients; i++, target++ ) {
- if( !target->inuse || target == mvd->dummy ) {
+ for (i = 0, target = mvd->players; i < mvd->maxclients; i++, target++) {
+ if (!target->inuse || target == mvd->dummy) {
continue;
}
- ent = &mvd->edicts[ i + 1 ].s;
- if( ent->effects & mask ) {
- MVD_FollowStart( client, target );
+ ent = &mvd->edicts[i + 1].s;
+ if (ent->effects & mask) {
+ MVD_FollowStart(client, target);
client->chase_mask = mask;
goto copy;
}
@@ -597,33 +618,33 @@ static void MVD_UpdateClient( mvd_client_t *client ) {
}
target = client->target;
- if( !target ) {
+ if (!target) {
// copy stats of the dummy MVD observer
target = mvd->dummy;
- for( i = 0; i < MAX_STATS; i++ ) {
+ for (i = 0; i < MAX_STATS; i++) {
client->ps.stats[i] = target->ps.stats[i];
}
} else {
- if( !target->inuse ) {
+ if (!target->inuse) {
// player is no longer active
- MVD_FollowStop( client );
+ MVD_FollowStop(client);
return;
}
copy:
// copy entire player state
client->ps = target->ps;
- if( client->uf & UF_LOCALFOV ) {
+ if (client->uf & UF_LOCALFOV) {
client->ps.fov = client->fov;
}
client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
client->ps.pmove.pm_type = PM_FREEZE;
client->clientNum = target - mvd->players;
- if( mvd_stats_hack->integer && target != mvd->dummy ) {
+ if (mvd_stats_hack->integer && target != mvd->dummy) {
// copy stats of the dummy MVD observer
target = mvd->dummy;
- for( i = 0; i < MAX_STATS; i++ ) {
- if( mvd_stats_hack->integer & ( 1 << i ) ) {
+ for (i = 0; i < MAX_STATS; i++) {
+ if (mvd_stats_hack->integer & (1 << i)) {
client->ps.stats[i] = target->ps.stats[i];
}
}
@@ -631,7 +652,7 @@ copy:
}
// override score
- switch( mvd_stats_score->integer ) {
+ switch (mvd_stats_score->integer) {
case 0:
client->ps.stats[STAT_FRAGS] = 0;
break;
@@ -649,55 +670,57 @@ SPECTATOR COMMANDS
==============================================================================
*/
-void MVD_BroadcastPrintf( mvd_t *mvd, int level, int mask, const char *fmt, ... ) {
+void MVD_BroadcastPrintf(mvd_t *mvd, int level, int mask, const char *fmt, ...)
+{
va_list argptr;
char text[MAX_STRING_CHARS];
size_t len;
mvd_client_t *other;
client_t *cl;
- va_start( argptr, fmt );
- len = Q_vsnprintf( text, sizeof( text ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(text, sizeof(text), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( text ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(text)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- if( level == PRINT_CHAT && mvd_filter_version->integer ) {
+ if (level == PRINT_CHAT && mvd_filter_version->integer) {
char *s;
- while( ( s = strstr( text, "!version" ) ) != NULL ) {
+ while ((s = strstr(text, "!version")) != NULL) {
s[6] = '0';
}
}
- MSG_WriteByte( svc_print );
- MSG_WriteByte( level );
- MSG_WriteData( text, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(level);
+ MSG_WriteData(text, len + 1);
- FOR_EACH_MVDCL( other, mvd ) {
+ FOR_EACH_MVDCL(other, mvd) {
cl = other->cl;
- if( cl->state < cs_spawned ) {
+ if (cl->state < cs_spawned) {
continue;
}
- if( level < cl->messagelevel ) {
+ if (level < cl->messagelevel) {
continue;
}
- if( other->uf & mask ) {
+ if (other->uf & mask) {
continue;
}
- SV_ClientAddMessage( cl, MSG_RELIABLE );
+ SV_ClientAddMessage(cl, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-static void MVD_SetServerState( client_t *cl, mvd_t *mvd ) {
+static void MVD_SetServerState(client_t *cl, mvd_t *mvd)
+{
cl->gamedir = mvd->gamedir;
cl->mapname = mvd->mapname;
- cl->configstrings = ( char * )mvd->configstrings;
+ cl->configstrings = (char *)mvd->configstrings;
cl->slot = mvd->clientNum;
cl->cm = &mvd->cm;
cl->pool = &mvd->pool;
@@ -705,148 +728,154 @@ static void MVD_SetServerState( client_t *cl, mvd_t *mvd ) {
cl->maxclients = mvd->maxclients;
}
-void MVD_SwitchChannel( mvd_client_t *client, mvd_t *mvd ) {
+void MVD_SwitchChannel(mvd_client_t *client, mvd_t *mvd)
+{
client_t *cl = client->cl;
- List_Remove( &client->entry );
- List_SeqAdd( &mvd->clients, &client->entry );
+ List_Remove(&client->entry);
+ List_SeqAdd(&mvd->clients, &client->entry);
client->mvd = mvd;
client->begin_time = 0;
client->target = client->oldtarget = NULL;
client->chase_mask = 0;
- MVD_SetServerState( cl, mvd );
+ MVD_SetServerState(cl, mvd);
// needs to reconnect
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( va( "changing map=%s; reconnect\n", mvd->mapname ) );
- SV_ClientReset( cl );
- SV_ClientAddMessage( cl, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(va("changing map=%s; reconnect\n", mvd->mapname));
+ SV_ClientReset(cl);
+ SV_ClientAddMessage(cl, MSG_RELIABLE | MSG_CLEAR);
}
-static qboolean MVD_PartFilter( mvd_client_t *client ) {
+static qboolean MVD_PartFilter(mvd_client_t *client)
+{
unsigned i, delta, treshold;
float f = mvd_part_filter->value;
- if( !f ) {
+ if (!f) {
return qtrue; // show everyone
}
- if( f < 0 ) {
+ if (f < 0) {
return qfalse; // hide everyone
}
- if( client->admin ) {
+ if (client->admin) {
return qtrue; // show admins
}
- if( !client->floodHead ) {
+ if (!client->floodHead) {
return qfalse; // not talked yet
}
// take the most recent sample
- i = ( client->floodHead - 1 ) & FLOOD_MASK;
+ i = (client->floodHead - 1) & FLOOD_MASK;
delta = svs.realtime - client->floodSamples[i];
treshold = f * 1000;
return delta < treshold;
}
-static void MVD_TrySwitchChannel( mvd_client_t *client, mvd_t *mvd ) {
- if( mvd == client->mvd ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You are already %s.\n", mvd == &mvd_waitingRoom ?
- "in the Waiting Room" : "on this channel" );
+static void MVD_TrySwitchChannel(mvd_client_t *client, mvd_t *mvd)
+{
+ if (mvd == client->mvd) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You are already %s.\n", mvd == &mvd_waitingRoom ?
+ "in the Waiting Room" : "on this channel");
return; // nothing to do
}
- if( client->begin_time ) {
- if( svs.realtime - client->begin_time < 2000 ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You may not switch channels too soon.\n" );
+ if (client->begin_time) {
+ if (svs.realtime - client->begin_time < 2000) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You may not switch channels too soon.\n");
return;
}
- if( MVD_PartFilter( client ) ) {
- MVD_BroadcastPrintf( client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
- "[MVD] %s left the channel\n", client->cl->name );
+ if (MVD_PartFilter(client)) {
+ MVD_BroadcastPrintf(client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
+ "[MVD] %s left the channel\n", client->cl->name);
}
}
- MVD_SwitchChannel( client, mvd );
+ MVD_SwitchChannel(client, mvd);
}
-static void MVD_Admin_f( mvd_client_t *client ) {
+static void MVD_Admin_f(mvd_client_t *client)
+{
char *s = mvd_admin_password->string;
- if( client->admin ) {
+ if (client->admin) {
client->admin = qfalse;
- SV_ClientPrintf( client->cl, PRINT_HIGH, "[MVD] Lost admin status.\n" );
+ SV_ClientPrintf(client->cl, PRINT_HIGH, "[MVD] Lost admin status.\n");
return;
}
- if( !NET_IsLocalAddress( &client->cl->netchan->remote_address ) ) {
- if( Cmd_Argc() < 2 ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH, "Usage: %s <password>\n", Cmd_Argv( 0 ) );
+ if (!NET_IsLocalAddress(&client->cl->netchan->remote_address)) {
+ if (Cmd_Argc() < 2) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH, "Usage: %s <password>\n", Cmd_Argv(0));
return;
}
- if( !s[0] || strcmp( s, Cmd_Argv( 1 ) ) ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH, "[MVD] Invalid password.\n" );
+ if (!s[0] || strcmp(s, Cmd_Argv(1))) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH, "[MVD] Invalid password.\n");
return;
}
}
client->admin = qtrue;
- SV_ClientPrintf( client->cl, PRINT_HIGH, "[MVD] Granted admin status.\n" );
+ SV_ClientPrintf(client->cl, PRINT_HIGH, "[MVD] Granted admin status.\n");
}
-static void MVD_Forward_f( mvd_client_t *client ) {
+static void MVD_Forward_f(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
- if( !client->admin ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You don't have admin status.\n" );
+ if (!client->admin) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You don't have admin status.\n");
return;
}
- if( !mvd->forward_cmd ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] This channel does not support command forwarding.\n" );
+ if (!mvd->forward_cmd) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] This channel does not support command forwarding.\n");
return;
}
- mvd->forward_cmd( client );
+ mvd->forward_cmd(client);
}
-static void MVD_Say_f( mvd_client_t *client, int argnum ) {
+static void MVD_Say_f(mvd_client_t *client, int argnum)
+{
mvd_t *mvd = client->mvd;
unsigned delta, delay = mvd_flood_waitdelay->value * 1000;
unsigned treshold = mvd_flood_persecond->value * 1000;
char text[150], *p;
unsigned i, j;
- if( mvd_flood_mute->integer && !client->admin ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Spectators may not talk on this server.\n" );
+ if (mvd_flood_mute->integer && !client->admin) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Spectators may not talk on this server.\n");
return;
}
- if( client->uf & UF_MUTE_OBSERVERS ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Please turn off ignore mode first.\n" );
+ if (client->uf & UF_MUTE_OBSERVERS) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Please turn off ignore mode first.\n");
return;
}
- if( client->floodTime ) {
+ if (client->floodTime) {
delta = svs.realtime - client->floodTime;
- if( delta < delay ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You can't talk for %u more seconds.\n",
- ( delay - delta ) / 1000 );
+ if (delta < delay) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You can't talk for %u more seconds.\n",
+ (delay - delta) / 1000);
return;
}
}
- j = Cvar_ClampInteger( mvd_flood_msgs, 0, FLOOD_SAMPLES - 1 ) + 1;
- if( client->floodHead >= j ) {
- i = ( client->floodHead - j ) & FLOOD_MASK;
+ j = Cvar_ClampInteger(mvd_flood_msgs, 0, FLOOD_SAMPLES - 1) + 1;
+ if (client->floodHead >= j) {
+ i = (client->floodHead - j) & FLOOD_MASK;
delta = svs.realtime - client->floodSamples[i];
- if( delta < treshold ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You can't talk for %u seconds.\n", delay / 1000 );
+ if (delta < treshold) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You can't talk for %u seconds.\n", delay / 1000);
client->floodTime = svs.realtime;
return;
}
@@ -855,53 +884,55 @@ static void MVD_Say_f( mvd_client_t *client, int argnum ) {
client->floodSamples[client->floodHead & FLOOD_MASK] = svs.realtime;
client->floodHead++;
- Q_snprintf( text, sizeof( text ), "[MVD] %s: %s",
- client->cl->name, Cmd_ArgsFrom( argnum ) );
- for( p = text; *p; p++ ) {
+ Q_snprintf(text, sizeof(text), "[MVD] %s: %s",
+ client->cl->name, Cmd_ArgsFrom(argnum));
+ for (p = text; *p; p++) {
*p |= 128;
}
- MVD_BroadcastPrintf( mvd, PRINT_HIGH, client->admin ?
- 0 : UF_MUTE_OBSERVERS, "%s\n", text );
+ MVD_BroadcastPrintf(mvd, PRINT_HIGH, client->admin ?
+ 0 : UF_MUTE_OBSERVERS, "%s\n", text);
}
-static void MVD_Observe_f( mvd_client_t *client ) {
- if( client->mvd == &mvd_waitingRoom ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Please enter a channel first.\n" );
+static void MVD_Observe_f(mvd_client_t *client)
+{
+ if (client->mvd == &mvd_waitingRoom) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Please enter a channel first.\n");
return;
}
client->chase_mask = 0;
- if( client->mvd->intermission ) {
+ if (client->mvd->intermission) {
return;
}
- if( client->target ) {
- MVD_FollowStop( client );
- } else if( client->oldtarget && client->oldtarget->inuse ) {
- MVD_FollowStart( client, client->oldtarget );
+ if (client->target) {
+ MVD_FollowStop(client);
+ } else if (client->oldtarget && client->oldtarget->inuse) {
+ MVD_FollowStart(client, client->oldtarget);
} else {
- MVD_FollowFirst( client );
+ MVD_FollowFirst(client);
}
}
-static mvd_player_t *MVD_SetPlayer( mvd_client_t *client, const char *s ) {
+static mvd_player_t *MVD_SetPlayer(mvd_client_t *client, const char *s)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *player, *match;
int i, count;
// numeric values are just slot numbers
- if( COM_IsUint( s ) ) {
- i = atoi( s );
- if( i < 0 || i >= mvd->maxclients ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Player number %d is invalid.\n", i );
+ if (COM_IsUint(s)) {
+ i = atoi(s);
+ if (i < 0 || i >= mvd->maxclients) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Player number %d is invalid.\n", i);
return NULL;
}
player = &mvd->players[i];
- if( !player->inuse || player == mvd->dummy ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Player %d is not active.\n", i );
+ if (!player->inuse || player == mvd->dummy) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Player %d is not active.\n", i);
return NULL;
}
@@ -911,59 +942,60 @@ static mvd_player_t *MVD_SetPlayer( mvd_client_t *client, const char *s ) {
// check for a name match
match = NULL;
count = 0;
- for( i = 0, player = mvd->players; i < mvd->maxclients; i++, player++ ) {
- if( !player->inuse || player == mvd->dummy ) {
+ for (i = 0, player = mvd->players; i < mvd->maxclients; i++, player++) {
+ if (!player->inuse || player == mvd->dummy) {
continue;
}
- if( !Q_stricmp( player->name, s ) ) {
+ if (!Q_stricmp(player->name, s)) {
return player; // exact match
}
- if( Q_stristr( player->name, s ) ) {
+ if (Q_stristr(player->name, s)) {
match = player; // partial match
count++;
}
}
- if( !match ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] No players matching '%s' found.\n", s );
+ if (!match) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] No players matching '%s' found.\n", s);
return NULL;
}
- if( count > 1 ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] '%s' matches multiple players.\n", s );
+ if (count > 1) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] '%s' matches multiple players.\n", s);
return NULL;
}
return match;
}
-static void MVD_Follow_f( mvd_client_t *client ) {
+static void MVD_Follow_f(mvd_client_t *client)
+{
mvd_t *mvd = client->mvd;
mvd_player_t *player;
char *s;
int mask;
- if( mvd == &mvd_waitingRoom ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Please enter a channel first.\n" );
+ if (mvd == &mvd_waitingRoom) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Please enter a channel first.\n");
return;
}
- if( mvd->intermission ) {
+ if (mvd->intermission) {
return;
}
- if( Cmd_Argc() < 2 ) {
- MVD_Observe_f( client );
+ if (Cmd_Argc() < 2) {
+ MVD_Observe_f(client);
return;
}
- s = Cmd_Argv( 1 );
- if( *s == '!' ) {
+ s = Cmd_Argv(1);
+ if (*s == '!') {
s++;
- switch( *s ) {
+ switch (*s) {
case 'q':
mask = EF_QUAD;
break;
@@ -979,58 +1011,59 @@ static void MVD_Follow_f( mvd_client_t *client ) {
case '!':
goto match;
case 'p':
- if( client->oldtarget ) {
- if( client->oldtarget->inuse ) {
- MVD_FollowStart( client, client->oldtarget );
+ if (client->oldtarget) {
+ if (client->oldtarget->inuse) {
+ MVD_FollowStart(client, client->oldtarget);
} else {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Previous chase target is not active.\n" );
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Previous chase target is not active.\n");
}
} else {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] You have no previous chase target.\n" );
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] You have no previous chase target.\n");
}
return;
default:
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Unknown chase target '%s'. Valid targets are: "
- "q[uad]/i[nvulner]/r[ed_flag]/b[lue_flag]/p[revious_target].\n", s );
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Unknown chase target '%s'. Valid targets are: "
+ "q[uad]/i[nvulner]/r[ed_flag]/b[lue_flag]/p[revious_target].\n", s);
return;
}
- SV_ClientPrintf( client->cl, PRINT_MEDIUM,
- "[MVD] Chasing players with '%s' powerup.\n", s );
+ SV_ClientPrintf(client->cl, PRINT_MEDIUM,
+ "[MVD] Chasing players with '%s' powerup.\n", s);
client->chase_mask = mask;
return;
}
match:
- player = MVD_SetPlayer( client, s );
- if( player ) {
- MVD_FollowStart( client, player );
+ player = MVD_SetPlayer(client, s);
+ if (player) {
+ MVD_FollowStart(client, player);
}
}
-static void MVD_Invuse_f( mvd_client_t *client ) {
+static void MVD_Invuse_f(mvd_client_t *client)
+{
mvd_t *mvd;
int uf = client->uf;
- if( client->layout_type == LAYOUT_MENU ) {
- switch( clamp_menu_cursor( client ) ) {
+ if (client->layout_type == LAYOUT_MENU) {
+ switch (clamp_menu_cursor(client)) {
case 0:
- MVD_SetDefaultLayout( client );
- MVD_Observe_f( client );
+ MVD_SetDefaultLayout(client);
+ MVD_Observe_f(client);
return;
case 1:
- MVD_SetNewLayout( client, LAYOUT_SCORES );
+ MVD_SetNewLayout(client, LAYOUT_SCORES);
break;
case 2:
- MVD_SetNewLayout( client, LAYOUT_CLIENTS );
+ MVD_SetNewLayout(client, LAYOUT_CLIENTS);
break;
case 3:
- MVD_SetNewLayout( client, LAYOUT_CHANNELS );
+ MVD_SetNewLayout(client, LAYOUT_CHANNELS);
break;
case 4:
- MVD_TrySwitchChannel( client, &mvd_waitingRoom );
+ MVD_TrySwitchChannel(client, &mvd_waitingRoom);
return;
case 5:
client->uf ^= UF_MUTE_OBSERVERS;
@@ -1045,204 +1078,208 @@ static void MVD_Invuse_f( mvd_client_t *client ) {
client->uf ^= UF_LOCALFOV;
break;
case 9:
- MVD_SetDefaultLayout( client );
+ MVD_SetDefaultLayout(client);
break;
}
- if( uf != client->uf ) {
- SV_ClientCommand( client->cl, "set uf %d u\n", client->uf );
+ if (uf != client->uf) {
+ SV_ClientCommand(client->cl, "set uf %d u\n", client->uf);
client->layout_time = 0; // force an update
}
return;
}
- if( client->layout_type == LAYOUT_CHANNELS ) {
- mvd = LIST_INDEX( mvd_t, client->layout_cursor, &mvd_channel_list, entry );
- if( mvd ) {
- MVD_TrySwitchChannel( client, mvd );
+ if (client->layout_type == LAYOUT_CHANNELS) {
+ mvd = LIST_INDEX(mvd_t, client->layout_cursor, &mvd_channel_list, entry);
+ if (mvd) {
+ MVD_TrySwitchChannel(client, mvd);
}
return;
}
}
-static void MVD_Join_f( mvd_client_t *client ) {
+static void MVD_Join_f(mvd_client_t *client)
+{
mvd_t *mvd;
-
- SV_BeginRedirect( RD_CLIENT );
- mvd = MVD_SetChannel( 1 );
+
+ SV_BeginRedirect(RD_CLIENT);
+ mvd = MVD_SetChannel(1);
Com_EndRedirect();
- if( !mvd ) {
+ if (!mvd) {
return;
}
- if( mvd->state < MVD_WAITING ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] This channel is not ready yet.\n" );
+ if (mvd->state < MVD_WAITING) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] This channel is not ready yet.\n");
return;
}
- MVD_TrySwitchChannel( client, mvd );
+ MVD_TrySwitchChannel(client, mvd);
}
-static void print_channel( client_t *cl, mvd_t *mvd ) {
+static void print_channel(client_t *cl, mvd_t *mvd)
+{
mvd_player_t *player;
char buffer[MAX_QPATH];
size_t len, total;
int i;
total = 0;
- for( i = 0; i < mvd->maxclients; i++ ) {
+ for (i = 0; i < mvd->maxclients; i++) {
player = &mvd->players[i];
- if( !player->inuse || player == mvd->dummy ) {
+ if (!player->inuse || player == mvd->dummy) {
continue;
}
- len = strlen( player->name );
- if( total + len + 2 >= sizeof( buffer ) ) {
+ len = strlen(player->name);
+ if (total + len + 2 >= sizeof(buffer)) {
break;
}
- if( total ) {
- buffer[total+0] = ',';
- buffer[total+1] = ' ';
+ if (total) {
+ buffer[total + 0] = ',';
+ buffer[total + 1] = ' ';
total += 2;
}
- memcpy( buffer + total, player->name, len );
+ memcpy(buffer + total, player->name, len);
total += len;
}
buffer[total] = 0;
- SV_ClientPrintf( cl, PRINT_HIGH,
- "%2d %-12.12s %-8.8s %3d %3d %s\n", mvd->id,
- mvd->name, mvd->mapname,
- List_Count( &mvd->clients ),
- mvd->numplayers, buffer );
+ SV_ClientPrintf(cl, PRINT_HIGH,
+ "%2d %-12.12s %-8.8s %3d %3d %s\n", mvd->id,
+ mvd->name, mvd->mapname,
+ List_Count(&mvd->clients),
+ mvd->numplayers, buffer);
}
-static void mvd_channel_list_f( mvd_client_t *client ) {
+static void mvd_channel_list_f(mvd_client_t *client)
+{
mvd_t *mvd;
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "id name map spc plr who is playing\n"
- "-- ------------ -------- --- --- --------------\n" );
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "id name map spc plr who is playing\n"
+ "-- ------------ -------- --- --- --------------\n");
- FOR_EACH_MVD( mvd ) {
- print_channel( client->cl, mvd );
+ FOR_EACH_MVD(mvd) {
+ print_channel(client->cl, mvd);
}
}
-static void MVD_Clients_f( mvd_client_t *client ) {
+static void MVD_Clients_f(mvd_client_t *client)
+{
// TODO: dump them in console
client->layout_type = LAYOUT_CLIENTS;
client->layout_time = 0;
client->layout_cursor = 0;
}
-static void MVD_Commands_f( mvd_client_t *client ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "chase [player_id] toggle chasecam mode\n"
- "observe toggle observer mode\n"
- "menu show main menu\n"
- "score show scoreboard\n"
- "oldscore show previous scoreboard\n"
- "channels list active channels\n"
- "join [channel_id] join specified channel\n"
- "leave go to the Waiting Room\n"
- );
+static void MVD_Commands_f(mvd_client_t *client)
+{
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "chase [player_id] toggle chasecam mode\n"
+ "observe toggle observer mode\n"
+ "menu show main menu\n"
+ "score show scoreboard\n"
+ "oldscore show previous scoreboard\n"
+ "channels list active channels\n"
+ "join [channel_id] join specified channel\n"
+ "leave go to the Waiting Room\n"
+ );
}
-static void MVD_GameClientCommand( edict_t *ent ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static void MVD_GameClientCommand(edict_t *ent)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
char *cmd;
- if( client->cl->state < cs_spawned ) {
+ if (client->cl->state < cs_spawned) {
return;
}
- cmd = Cmd_Argv( 0 );
+ cmd = Cmd_Argv(0);
- if( !strcmp( cmd, "!mvdadmin" ) ) {
- MVD_Admin_f( client );
+ if (!strcmp(cmd, "!mvdadmin")) {
+ MVD_Admin_f(client);
return;
}
- if( !strcmp( cmd, "fwd" ) ) {
- MVD_Forward_f( client );
+ if (!strcmp(cmd, "fwd")) {
+ MVD_Forward_f(client);
return;
}
- if( !strcmp( cmd, "say" ) || !strcmp( cmd, "say_team" ) ) {
- MVD_Say_f( client, 1 );
+ if (!strcmp(cmd, "say") || !strcmp(cmd, "say_team")) {
+ MVD_Say_f(client, 1);
return;
}
- if( !strcmp( cmd, "follow" ) || !strcmp( cmd, "chase" ) ) {
- MVD_Follow_f( client );
+ if (!strcmp(cmd, "follow") || !strcmp(cmd, "chase")) {
+ MVD_Follow_f(client);
return;
}
- if( !strcmp( cmd, "observe" ) || !strcmp( cmd, "spectate" ) ||
- !strcmp( cmd, "observer" ) || !strcmp( cmd, "spectator" ) ||
- !strcmp( cmd, "obs" ) || !strcmp( cmd, "spec" ) )
- {
- MVD_Observe_f( client );
+ if (!strcmp(cmd, "observe") || !strcmp(cmd, "spectate") ||
+ !strcmp(cmd, "observer") || !strcmp(cmd, "spectator") ||
+ !strcmp(cmd, "obs") || !strcmp(cmd, "spec")) {
+ MVD_Observe_f(client);
return;
}
- if( !strcmp( cmd, "inven" ) || !strcmp( cmd, "menu" ) ) {
- MVD_ToggleLayout( client, LAYOUT_MENU );
+ if (!strcmp(cmd, "inven") || !strcmp(cmd, "menu")) {
+ MVD_ToggleLayout(client, LAYOUT_MENU);
return;
}
- if( !strcmp( cmd, "invnext" ) ) {
- if( client->layout_type >= LAYOUT_MENU ) {
+ if (!strcmp(cmd, "invnext")) {
+ if (client->layout_type >= LAYOUT_MENU) {
client->layout_cursor++;
client->layout_time = 0;
- } else if( !client->mvd->intermission ) {
- MVD_FollowNext( client );
+ } else if (!client->mvd->intermission) {
+ MVD_FollowNext(client);
}
return;
}
- if( !strcmp( cmd, "invprev" ) ) {
- if( client->layout_type >= LAYOUT_MENU ) {
+ if (!strcmp(cmd, "invprev")) {
+ if (client->layout_type >= LAYOUT_MENU) {
client->layout_cursor--;
client->layout_time = 0;
- } else if( !client->mvd->intermission ) {
- MVD_FollowPrev( client );
+ } else if (!client->mvd->intermission) {
+ MVD_FollowPrev(client);
}
return;
}
- if( !strcmp( cmd, "invuse" ) ) {
- MVD_Invuse_f( client );
+ if (!strcmp(cmd, "invuse")) {
+ MVD_Invuse_f(client);
return;
}
- if( !strcmp( cmd, "help" ) || !strcmp( cmd, "score" ) ) {
- MVD_ToggleLayout( client, LAYOUT_SCORES );
+ if (!strcmp(cmd, "help") || !strcmp(cmd, "score")) {
+ MVD_ToggleLayout(client, LAYOUT_SCORES);
return;
}
- if( !strcmp( cmd, "oldscore" ) || !strcmp( cmd, "oldscores" ) ||
- !strcmp( cmd, "lastscore" ) || !strcmp( cmd, "lastscores" ) )
- {
- MVD_ToggleLayout( client, LAYOUT_OLDSCORES );
+ if (!strcmp(cmd, "oldscore") || !strcmp(cmd, "oldscores") ||
+ !strcmp(cmd, "lastscore") || !strcmp(cmd, "lastscores")) {
+ MVD_ToggleLayout(client, LAYOUT_OLDSCORES);
return;
}
- if( !strcmp( cmd, "putaway" ) ) {
- MVD_SetDefaultLayout( client );
+ if (!strcmp(cmd, "putaway")) {
+ MVD_SetDefaultLayout(client);
return;
}
- if( !strcmp( cmd, "channels" ) ) {
- mvd_channel_list_f( client );
+ if (!strcmp(cmd, "channels")) {
+ mvd_channel_list_f(client);
return;
}
- if( !strcmp( cmd, "clients" ) || !strcmp( cmd, "players" ) ) {
- MVD_Clients_f( client );
+ if (!strcmp(cmd, "clients") || !strcmp(cmd, "players")) {
+ MVD_Clients_f(client);
return;
}
- if( !strcmp( cmd, "join" ) ) {
- MVD_Join_f( client );
+ if (!strcmp(cmd, "join")) {
+ MVD_Join_f(client);
return;
}
- if( !strcmp( cmd, "leave" ) ) {
- MVD_TrySwitchChannel( client, &mvd_waitingRoom );
+ if (!strcmp(cmd, "leave")) {
+ MVD_TrySwitchChannel(client, &mvd_waitingRoom);
return;
}
- if( !strcmp( cmd, "commands" ) ) {
- MVD_Commands_f( client );
+ if (!strcmp(cmd, "commands")) {
+ MVD_Commands_f(client);
return;
}
- MVD_Say_f( client, 0 );
+ MVD_Say_f(client, 0);
}
/*
@@ -1253,29 +1290,31 @@ CONFIGSTRING MANAGEMENT
==============================================================================
*/
-void MVD_FreePlayer( mvd_player_t *player ) {
+void MVD_FreePlayer(mvd_player_t *player)
+{
mvd_cs_t *cs, *next;
- for( cs = player->configstrings; cs; cs = next ) {
+ for (cs = player->configstrings; cs; cs = next) {
next = cs->next;
- Z_Free( cs );
+ Z_Free(cs);
}
player->configstrings = NULL;
}
-static void reset_unicast_strings( mvd_t *mvd, int index ) {
+static void reset_unicast_strings(mvd_t *mvd, int index)
+{
mvd_cs_t *cs, **next_p;
mvd_player_t *player;
int i;
- for( i = 0; i < mvd->maxclients; i++ ) {
+ for (i = 0; i < mvd->maxclients; i++) {
player = &mvd->players[i];
next_p = &player->configstrings;
- for( cs = player->configstrings; cs; cs = cs->next ) {
- if( cs->index == index ) {
- Com_DPrintf( "%s: reset %d on %d\n", __func__, index, i );
+ for (cs = player->configstrings; cs; cs = cs->next) {
+ if (cs->index == index) {
+ Com_DPrintf("%s: reset %d on %d\n", __func__, index, i);
*next_p = cs->next;
- Z_Free( cs );
+ Z_Free(cs);
break;
}
next_p = &cs->next;
@@ -1283,72 +1322,76 @@ static void reset_unicast_strings( mvd_t *mvd, int index ) {
}
}
-static void set_player_name( mvd_t *mvd, int index ) {
+static void set_player_name(mvd_t *mvd, int index)
+{
mvd_player_t *player;
char *string, *p;
- string = mvd->configstrings[ CS_PLAYERSKINS + index ];
+ string = mvd->configstrings[CS_PLAYERSKINS + index];
player = &mvd->players[index];
- Q_strlcpy( player->name, string, sizeof( player->name ) );
- p = strchr( player->name, '\\' );
- if( p ) {
+ Q_strlcpy(player->name, string, sizeof(player->name));
+ p = strchr(player->name, '\\');
+ if (p) {
*p = 0;
}
}
-static void update_player_name( mvd_t *mvd, int index ) {
+static void update_player_name(mvd_t *mvd, int index)
+{
mvd_client_t *client;
// parse player name
- set_player_name( mvd, index );
+ set_player_name(mvd, index);
// update layouts
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state < cs_spawned ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state < cs_spawned) {
continue;
}
- if( client->layout_type != LAYOUT_FOLLOW ) {
+ if (client->layout_type != LAYOUT_FOLLOW) {
continue;
}
- if( client->target == mvd->players + index ) {
+ if (client->target == mvd->players + index) {
client->layout_time = 0;
}
}
}
-void MVD_SetPlayerNames( mvd_t *mvd ) {
+void MVD_SetPlayerNames(mvd_t *mvd)
+{
int i;
- for( i = 0; i < mvd->maxclients; i++ ) {
- set_player_name( mvd, i );
+ for (i = 0; i < mvd->maxclients; i++) {
+ set_player_name(mvd, i);
}
}
-void MVD_UpdateConfigstring( mvd_t *mvd, int index ) {
+void MVD_UpdateConfigstring(mvd_t *mvd, int index)
+{
char *s = mvd->configstrings[index];
mvd_client_t *client;
- if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + mvd->maxclients ) {
+ if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + mvd->maxclients) {
// update player name
- update_player_name( mvd, index - CS_PLAYERSKINS );
- } else if( index >= CS_GENERAL ) {
+ update_player_name(mvd, index - CS_PLAYERSKINS);
+ } else if (index >= CS_GENERAL) {
// reset unicast versions of this string
- reset_unicast_strings( mvd, index );
+ reset_unicast_strings(mvd, index);
}
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( index );
- MSG_WriteString( s );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(index);
+ MSG_WriteString(s);
// broadcast configstring change
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state < cs_primed ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state < cs_primed) {
continue;
}
- SV_ClientAddMessage( client->cl, MSG_RELIABLE );
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
/*
@@ -1359,49 +1402,52 @@ MISC GAME FUNCTIONS
==============================================================================
*/
-void MVD_LinkEdict( mvd_t *mvd, edict_t *ent ) {
+void MVD_LinkEdict(mvd_t *mvd, edict_t *ent)
+{
int index;
mmodel_t *cm;
bsp_t *cache = mvd->cm.cache;
- if( !cache ) {
+ if (!cache) {
return;
}
- if( ent->s.solid == PACKED_BSP ) {
+ if (ent->s.solid == PACKED_BSP) {
index = ent->s.modelindex;
- if( index < 1 || index > cache->nummodels ) {
- Com_WPrintf( "%s: entity %d: bad inline model index: %d\n",
- __func__, ent->s.number, index );
+ if (index < 1 || index > cache->nummodels) {
+ Com_WPrintf("%s: entity %d: bad inline model index: %d\n",
+ __func__, ent->s.number, index);
return;
}
- cm = &cache->models[ index - 1 ];
- VectorCopy( cm->mins, ent->mins );
- VectorCopy( cm->maxs, ent->maxs );
+ cm = &cache->models[index - 1];
+ VectorCopy(cm->mins, ent->mins);
+ VectorCopy(cm->maxs, ent->maxs);
ent->solid = SOLID_BSP;
- } else if( ent->s.solid ) {
- MSG_UnpackSolid16( ent->s.solid, ent->mins, ent->maxs );
+ } else if (ent->s.solid) {
+ MSG_UnpackSolid16(ent->s.solid, ent->mins, ent->maxs);
ent->solid = SOLID_BBOX;
} else {
- VectorClear( ent->mins );
- VectorClear( ent->maxs );
+ VectorClear(ent->mins);
+ VectorClear(ent->maxs);
ent->solid = SOLID_NOT;
}
- SV_LinkEdict( &mvd->cm, ent );
+ SV_LinkEdict(&mvd->cm, ent);
}
-void MVD_RemoveClient( client_t *client ) {
+void MVD_RemoveClient(client_t *client)
+{
int index = client - svs.client_pool;
mvd_client_t *cl = &mvd_clients[index];
- List_Remove( &cl->entry );
+ List_Remove(&cl->entry);
- memset( cl, 0, sizeof( *cl ) );
+ memset(cl, 0, sizeof(*cl));
cl->cl = client;
}
-static void MVD_GameInit( void ) {
+static void MVD_GameInit(void)
+{
mvd_t *mvd = &mvd_waitingRoom;
edict_t *edicts;
cvar_t *mvd_default_map;
@@ -1411,87 +1457,88 @@ static void MVD_GameInit( void ) {
int i;
qerror_t ret;
- Com_Printf( "----- MVD_GameInit -----\n" );
-
- mvd_admin_password = Cvar_Get( "mvd_admin_password", "", CVAR_PRIVATE );
- mvd_part_filter = Cvar_Get( "mvd_part_filter", "0", 0 );
- mvd_flood_msgs = Cvar_Get( "flood_msgs", "4", 0 );
- mvd_flood_persecond = Cvar_Get( "flood_persecond", "4", 0 ); // FIXME: rename this
- mvd_flood_waitdelay = Cvar_Get( "flood_waitdelay", "10", 0 );
- mvd_flood_mute = Cvar_Get( "flood_mute", "0", 0 );
- mvd_filter_version = Cvar_Get( "mvd_filter_version", "0", 0 );
- mvd_default_map = Cvar_Get( "mvd_default_map", "q2dm1", CVAR_LATCH );
- mvd_stats_score = Cvar_Get( "mvd_stats_score", "0", 0 );
- mvd_stats_hack = Cvar_Get( "mvd_stats_hack", "0", 0 );
- mvd_freeze_hack = Cvar_Get( "mvd_freeze_hack", "1", 0 );
- mvd_chase_prefix = Cvar_Get( "mvd_chase_prefix", "xv 0 yb -64", 0 );
- Cvar_Set( "g_features", va( "%d", MVD_FEATURES ) );
-
- Z_TagReserve( ( sizeof( edict_t ) +
- sizeof( mvd_client_t ) ) * sv_maxclients->integer +
- sizeof( edict_t ), TAG_MVD );
- mvd_clients = Z_ReservedAllocz( sizeof( mvd_client_t ) *
- sv_maxclients->integer );
- edicts = Z_ReservedAllocz( sizeof( edict_t ) *
- ( sv_maxclients->integer + 1 ) );
-
- for( i = 0; i < sv_maxclients->integer; i++ ) {
+ Com_Printf("----- MVD_GameInit -----\n");
+
+ mvd_admin_password = Cvar_Get("mvd_admin_password", "", CVAR_PRIVATE);
+ mvd_part_filter = Cvar_Get("mvd_part_filter", "0", 0);
+ mvd_flood_msgs = Cvar_Get("flood_msgs", "4", 0);
+ mvd_flood_persecond = Cvar_Get("flood_persecond", "4", 0); // FIXME: rename this
+ mvd_flood_waitdelay = Cvar_Get("flood_waitdelay", "10", 0);
+ mvd_flood_mute = Cvar_Get("flood_mute", "0", 0);
+ mvd_filter_version = Cvar_Get("mvd_filter_version", "0", 0);
+ mvd_default_map = Cvar_Get("mvd_default_map", "q2dm1", CVAR_LATCH);
+ mvd_stats_score = Cvar_Get("mvd_stats_score", "0", 0);
+ mvd_stats_hack = Cvar_Get("mvd_stats_hack", "0", 0);
+ mvd_freeze_hack = Cvar_Get("mvd_freeze_hack", "1", 0);
+ mvd_chase_prefix = Cvar_Get("mvd_chase_prefix", "xv 0 yb -64", 0);
+ Cvar_Set("g_features", va("%d", MVD_FEATURES));
+
+ Z_TagReserve((sizeof(edict_t) +
+ sizeof(mvd_client_t)) * sv_maxclients->integer +
+ sizeof(edict_t), TAG_MVD);
+ mvd_clients = Z_ReservedAllocz(sizeof(mvd_client_t) *
+ sv_maxclients->integer);
+ edicts = Z_ReservedAllocz(sizeof(edict_t) *
+ (sv_maxclients->integer + 1));
+
+ for (i = 0; i < sv_maxclients->integer; i++) {
mvd_clients[i].cl = &svs.client_pool[i];
- edicts[i + 1].client = ( gclient_t * )&mvd_clients[i];
+ edicts[i + 1].client = (gclient_t *)&mvd_clients[i];
}
mvd_ge.edicts = edicts;
- mvd_ge.edict_size = sizeof( edict_t );
+ mvd_ge.edict_size = sizeof(edict_t);
mvd_ge.num_edicts = sv_maxclients->integer + 1;
mvd_ge.max_edicts = sv_maxclients->integer + 1;
- Q_snprintf( buffer, sizeof( buffer ),
- "maps/%s.bsp", mvd_default_map->string );
+ Q_snprintf(buffer, sizeof(buffer),
+ "maps/%s.bsp", mvd_default_map->string);
- ret = BSP_Load( buffer, &bsp );
- if( !bsp ) {
- Com_EPrintf( "Couldn't load %s for the Waiting Room: %s\n",
- buffer, Q_ErrorString( ret ) );
- Cvar_Reset( mvd_default_map );
- strcpy( buffer, "maps/q2dm1.bsp" );
+ ret = BSP_Load(buffer, &bsp);
+ if (!bsp) {
+ Com_EPrintf("Couldn't load %s for the Waiting Room: %s\n",
+ buffer, Q_ErrorString(ret));
+ Cvar_Reset(mvd_default_map);
+ strcpy(buffer, "maps/q2dm1.bsp");
checksum = 80717714;
- VectorSet( mvd->spawnOrigin, 984, 192, 784 );
- VectorSet( mvd->spawnAngles, 25, 72, 0 );
+ VectorSet(mvd->spawnOrigin, 984, 192, 784);
+ VectorSet(mvd->spawnAngles, 25, 72, 0);
} else {
// get the spectator spawn point
- MVD_ParseEntityString( mvd, bsp->entitystring );
+ MVD_ParseEntityString(mvd, bsp->entitystring);
checksum = bsp->checksum;
- BSP_Free( bsp );
+ BSP_Free(bsp);
}
- strcpy( mvd->name, "Waiting Room" );
- Cvar_VariableStringBuffer( "game", mvd->gamedir, sizeof( mvd->gamedir ) );
- Q_strlcpy( mvd->mapname, mvd_default_map->string, sizeof( mvd->mapname ) );
- List_Init( &mvd->clients );
+ strcpy(mvd->name, "Waiting Room");
+ Cvar_VariableStringBuffer("game", mvd->gamedir, sizeof(mvd->gamedir));
+ Q_strlcpy(mvd->mapname, mvd_default_map->string, sizeof(mvd->mapname));
+ List_Init(&mvd->clients);
- strcpy( mvd->configstrings[CS_NAME], "Waiting Room" );
- strcpy( mvd->configstrings[CS_SKY], "unit1_" );
- strcpy( mvd->configstrings[CS_MAXCLIENTS], "8" );
- sprintf( mvd->configstrings[CS_MAPCHECKSUM], "%d", checksum );
- strcpy( mvd->configstrings[CS_MODELS + 1], buffer );
- strcpy( mvd->configstrings[CS_LIGHTS], "m" );
+ strcpy(mvd->configstrings[CS_NAME], "Waiting Room");
+ strcpy(mvd->configstrings[CS_SKY], "unit1_");
+ strcpy(mvd->configstrings[CS_MAXCLIENTS], "8");
+ sprintf(mvd->configstrings[CS_MAPCHECKSUM], "%d", checksum);
+ strcpy(mvd->configstrings[CS_MODELS + 1], buffer);
+ strcpy(mvd->configstrings[CS_LIGHTS], "m");
mvd->dummy = &mvd_dummy;
mvd->pm_type = PM_FREEZE;
mvd->servercount = sv.spawncount;
// set serverinfo variables
- SV_InfoSet( "mapname", mvd->mapname );
-// SV_InfoSet( "gamedir", "gtv" );
- SV_InfoSet( "gamename", "gtv" );
- SV_InfoSet( "gamedate", __DATE__ );
- MVD_InfoSet( "mvd_channels", "0" );
- MVD_InfoSet( "mvd_players", "0" );
+ SV_InfoSet("mapname", mvd->mapname);
+ //SV_InfoSet("gamedir", "gtv");
+ SV_InfoSet("gamename", "gtv");
+ SV_InfoSet("gamedate", __DATE__);
+ MVD_InfoSet("mvd_channels", "0");
+ MVD_InfoSet("mvd_players", "0");
mvd_numplayers = 0;
}
-static void MVD_GameShutdown( void ) {
- Com_Printf( "----- MVD_GameShutdown -----\n" );
+static void MVD_GameShutdown(void)
+{
+ Com_Printf("----- MVD_GameShutdown -----\n");
MVD_Shutdown();
@@ -1500,71 +1547,78 @@ static void MVD_GameShutdown( void ) {
mvd_ge.num_edicts = 0;
mvd_ge.max_edicts = 0;
- Cvar_Set( "g_features", "0" );
+ Cvar_Set("g_features", "0");
}
-static void MVD_GameSpawnEntities( const char *mapname, const char *entstring, const char *spawnpoint ) {
+static void MVD_GameSpawnEntities(const char *mapname, const char *entstring, const char *spawnpoint)
+{
}
-static void MVD_GameWriteGame( const char *filename, qboolean autosave ) {
+static void MVD_GameWriteGame(const char *filename, qboolean autosave)
+{
}
-static void MVD_GameReadGame( const char *filename ) {
+static void MVD_GameReadGame(const char *filename)
+{
}
-static void MVD_GameWriteLevel( const char *filename ) {
+static void MVD_GameWriteLevel(const char *filename)
+{
}
-static void MVD_GameReadLevel( const char *filename ) {
+static void MVD_GameReadLevel(const char *filename)
+{
}
-static qboolean MVD_GameClientConnect( edict_t *ent, char *userinfo ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static qboolean MVD_GameClientConnect(edict_t *ent, char *userinfo)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
mvd_t *mvd;
// if there is exactly one active channel, assign them to it,
// otherwise, assign to Waiting Room
- if( LIST_SINGLE( &mvd_channel_list ) ) {
- mvd = LIST_FIRST( mvd_t, &mvd_channel_list, entry );
+ if (LIST_SINGLE(&mvd_channel_list)) {
+ mvd = LIST_FIRST(mvd_t, &mvd_channel_list, entry);
} else {
mvd = &mvd_waitingRoom;
}
- List_SeqAdd( &mvd->clients, &client->entry );
+ List_SeqAdd(&mvd->clients, &client->entry);
client->mvd = mvd;
-
+
// override server state
- MVD_SetServerState( client->cl, mvd );
+ MVD_SetServerState(client->cl, mvd);
return qtrue;
}
-static void MVD_GameClientBegin( edict_t *ent ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static void MVD_GameClientBegin(edict_t *ent)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
mvd_t *mvd = client->mvd;
mvd_player_t *target;
client->floodTime = 0;
client->floodHead = 0;
- memset( &client->lastcmd, 0, sizeof( client->lastcmd ) );
- memset( &client->ps, 0, sizeof( client->ps ) );
+ memset(&client->lastcmd, 0, sizeof(client->lastcmd));
+ memset(&client->ps, 0, sizeof(client->ps));
client->jump_held = 0;
client->layout_type = LAYOUT_NONE;
client->layout_time = 0;
client->layout_cursor = 0;
-
- if( !client->begin_time ) {
- if( MVD_PartFilter( client ) ) {
- MVD_BroadcastPrintf( mvd, PRINT_MEDIUM, UF_MUTE_MISC,
- "[MVD] %s entered the channel\n", client->cl->name );
+
+ if (!client->begin_time) {
+ if (MVD_PartFilter(client)) {
+ MVD_BroadcastPrintf(mvd, PRINT_MEDIUM, UF_MUTE_MISC,
+ "[MVD] %s entered the channel\n", client->cl->name);
}
- if( Com_IsDedicated() && mvd != &mvd_waitingRoom ) {
+ if (Com_IsDedicated() && mvd != &mvd_waitingRoom) {
// notify them if channel is in waiting state
- if( mvd->state == MVD_WAITING ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Buffering data, please wait...\n" );
+ if (mvd->state == MVD_WAITING) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Buffering data, please wait...\n");
}
- if( !mvd->cm.cache ) {
- SV_ClientPrintf( client->cl, PRINT_HIGH,
- "[MVD] Visibility data is missing for this map!\n" );
+ if (!mvd->cm.cache) {
+ SV_ClientPrintf(client->cl, PRINT_HIGH,
+ "[MVD] Visibility data is missing for this map!\n");
}
}
- target = MVD_MostFollowed( mvd );
+ target = MVD_MostFollowed(mvd);
} else {
target = client->oldtarget;
}
@@ -1572,122 +1626,129 @@ static void MVD_GameClientBegin( edict_t *ent ) {
client->target = NULL;
client->begin_time = svs.realtime;
- MVD_SetDefaultLayout( client );
+ MVD_SetDefaultLayout(client);
- if( mvd->intermission ) {
+ if (mvd->intermission) {
// force them to chase dummy MVD client
client->target = mvd->dummy;
- MVD_SetFollowLayout( client );
- MVD_UpdateClient( client );
- } else if( target && target->inuse ) {
+ MVD_SetFollowLayout(client);
+ MVD_UpdateClient(client);
+ } else if (target && target->inuse) {
// start normal chase cam mode
- MVD_FollowStart( client, target );
+ MVD_FollowStart(client, target);
} else {
// spawn the spectator
- VectorScale( mvd->spawnOrigin, 8, client->ps.pmove.origin );
- VectorCopy( mvd->spawnAngles, client->ps.viewangles );
- MVD_FollowStop( client );
+ VectorScale(mvd->spawnOrigin, 8, client->ps.pmove.origin);
+ VectorCopy(mvd->spawnAngles, client->ps.viewangles);
+ MVD_FollowStop(client);
}
mvd_dirty = qtrue;
}
-static void MVD_GameClientUserinfoChanged( edict_t *ent, char *userinfo ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static void MVD_GameClientUserinfoChanged(edict_t *ent, char *userinfo)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
char *s;
float fov;
- s = Info_ValueForKey( userinfo, "uf" );
- if( *s ) {
- client->uf = atoi( s );
+ s = Info_ValueForKey(userinfo, "uf");
+ if (*s) {
+ client->uf = atoi(s);
} else {
client->uf = UF_LOCALFOV;
}
- s = Info_ValueForKey( userinfo, "fov" );
- fov = atof( s );
- if( fov < 1 ) {
+ s = Info_ValueForKey(userinfo, "fov");
+ fov = atof(s);
+ if (fov < 1) {
fov = 90;
- } else if( fov > 160 ) {
+ } else if (fov > 160) {
fov = 160;
}
client->fov = fov;
- if( client->uf & UF_LOCALFOV ) {
+ if (client->uf & UF_LOCALFOV) {
client->ps.fov = fov;
}
}
-void MVD_GameClientNameChanged( edict_t *ent, const char *name ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+void MVD_GameClientNameChanged(edict_t *ent, const char *name)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
client_t *cl = client->cl;
- if( client->begin_time && MVD_PartFilter( client ) ) {
- MVD_BroadcastPrintf( client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
- "[MVD] %s changed name to %s\n", cl->name, name );
+ if (client->begin_time && MVD_PartFilter(client)) {
+ MVD_BroadcastPrintf(client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
+ "[MVD] %s changed name to %s\n", cl->name, name);
}
}
// called early from SV_DropClient to prevent multiple disconnect messages
-void MVD_GameClientDrop( edict_t *ent, const char *prefix, const char *reason ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+void MVD_GameClientDrop(edict_t *ent, const char *prefix, const char *reason)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
client_t *cl = client->cl;
- if( client->begin_time && MVD_PartFilter( client ) ) {
- MVD_BroadcastPrintf( client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
- "[MVD] %s%s%s\n", cl->name, prefix, reason );
+ if (client->begin_time && MVD_PartFilter(client)) {
+ MVD_BroadcastPrintf(client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
+ "[MVD] %s%s%s\n", cl->name, prefix, reason);
}
client->begin_time = 0;
}
-static void MVD_GameClientDisconnect( edict_t *ent ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static void MVD_GameClientDisconnect(edict_t *ent)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
client_t *cl = client->cl;
- if( client->begin_time && MVD_PartFilter( client ) ) {
- MVD_BroadcastPrintf( client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
- "[MVD] %s disconnected\n", cl->name );
+ if (client->begin_time && MVD_PartFilter(client)) {
+ MVD_BroadcastPrintf(client->mvd, PRINT_MEDIUM, UF_MUTE_MISC,
+ "[MVD] %s disconnected\n", cl->name);
}
client->begin_time = 0;
}
-static trace_t MVD_Trace( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end ) {
+static trace_t MVD_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
+{
trace_t trace;
- memset( &trace, 0, sizeof( trace ) );
- VectorCopy( end, trace.endpos );
+ memset(&trace, 0, sizeof(trace));
+ VectorCopy(end, trace.endpos);
trace.fraction = 1;
return trace;
}
-static int MVD_PointContents( vec3_t p ) {
+static int MVD_PointContents(vec3_t p)
+{
return 0;
}
-static void MVD_GameClientThink( edict_t *ent, usercmd_t *cmd ) {
- mvd_client_t *client = EDICT_MVDCL( ent );
+static void MVD_GameClientThink(edict_t *ent, usercmd_t *cmd)
+{
+ mvd_client_t *client = EDICT_MVDCL(ent);
usercmd_t *old = &client->lastcmd;
pmove_t pm;
- if( ( cmd->buttons & ~old->buttons ) & BUTTON_ATTACK ) {
- MVD_Observe_f( client );
+ if ((cmd->buttons & ~old->buttons) & BUTTON_ATTACK) {
+ MVD_Observe_f(client);
}
- if( client->target ) {
- if( cmd->upmove >= 10 ) {
- if( client->jump_held < 1 ) {
- if( !client->mvd->intermission ) {
- MVD_FollowNext( client );
+ if (client->target) {
+ if (cmd->upmove >= 10) {
+ if (client->jump_held < 1) {
+ if (!client->mvd->intermission) {
+ MVD_FollowNext(client);
}
client->jump_held = 1;
}
- } else if( cmd->upmove <= -10 ) {
- if( client->jump_held > -1 ) {
- if( !client->mvd->intermission ) {
- MVD_FollowPrev( client );
+ } else if (cmd->upmove <= -10) {
+ if (client->jump_held > -1) {
+ if (!client->mvd->intermission) {
+ MVD_FollowPrev(client);
}
client->jump_held = -1;
}
@@ -1695,24 +1756,25 @@ static void MVD_GameClientThink( edict_t *ent, usercmd_t *cmd ) {
client->jump_held = 0;
}
} else {
- memset( &pm, 0, sizeof( pm ) );
+ memset(&pm, 0, sizeof(pm));
pm.trace = MVD_Trace;
pm.pointcontents = MVD_PointContents;
pm.s = client->ps.pmove;
pm.cmd = *cmd;
- PF_Pmove( &pm );
+ PF_Pmove(&pm);
client->ps.pmove = pm.s;
- if( pm.s.pm_type != PM_FREEZE ) {
- VectorCopy( pm.viewangles, client->ps.viewangles );
+ if (pm.s.pm_type != PM_FREEZE) {
+ VectorCopy(pm.viewangles, client->ps.viewangles);
}
}
*old = *cmd;
}
-static void MVD_IntermissionStart( mvd_t *mvd ) {
+static void MVD_IntermissionStart(mvd_t *mvd)
+{
mvd_client_t *client;
// set this early so MVD_SetDefaultLayout works
@@ -1722,24 +1784,25 @@ static void MVD_IntermissionStart( mvd_t *mvd ) {
// save oldscores
// FIXME: unfortunately this will also reset oldscores during
// match timeout with certain mods (OpenTDM should work fine though)
- strcpy( mvd->oldscores, mvd->layout );
+ strcpy(mvd->oldscores, mvd->layout);
#endif
// force all clients to switch to the MVD dummy
// and open the scoreboard, unless they had some special layout up
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state != cs_spawned ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state != cs_spawned) {
continue;
}
client->oldtarget = client->target;
client->target = mvd->dummy;
- if( client->layout_type < LAYOUT_SCORES ) {
- MVD_SetDefaultLayout( client );
+ if (client->layout_type < LAYOUT_SCORES) {
+ MVD_SetDefaultLayout(client);
}
}
}
-static void MVD_IntermissionStop( mvd_t *mvd ) {
+static void MVD_IntermissionStop(mvd_t *mvd)
+{
mvd_client_t *client;
mvd_player_t *target;
@@ -1748,120 +1811,125 @@ static void MVD_IntermissionStop( mvd_t *mvd ) {
// force all clients to switch to previous mode
// and close the scoreboard
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state != cs_spawned ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state != cs_spawned) {
continue;
}
- if( client->layout_type == LAYOUT_SCORES ) {
+ if (client->layout_type == LAYOUT_SCORES) {
client->layout_type = 0;
}
target = client->oldtarget;
- if( target && target->inuse ) {
+ if (target && target->inuse) {
// start normal chase cam mode
- MVD_FollowStart( client, target );
+ MVD_FollowStart(client, target);
} else {
- MVD_FollowStop( client );
+ MVD_FollowStop(client);
}
client->oldtarget = NULL;
}
}
// called just after new frame is parsed
-void MVD_UpdateClients( mvd_t *mvd ) {
+void MVD_UpdateClients(mvd_t *mvd)
+{
mvd_client_t *client;
// check for intermission
- if( mvd_freeze_hack->integer ) {
- if( !mvd->intermission ) {
- if( mvd->dummy->ps.pmove.pm_type == PM_FREEZE ) {
- MVD_IntermissionStart( mvd );
+ if (mvd_freeze_hack->integer) {
+ if (!mvd->intermission) {
+ if (mvd->dummy->ps.pmove.pm_type == PM_FREEZE) {
+ MVD_IntermissionStart(mvd);
}
- } else if( mvd->dummy->ps.pmove.pm_type != PM_FREEZE ) {
- MVD_IntermissionStop( mvd );
+ } else if (mvd->dummy->ps.pmove.pm_type != PM_FREEZE) {
+ MVD_IntermissionStop(mvd);
}
- } else if( mvd->intermission ) {
- MVD_IntermissionStop( mvd );
+ } else if (mvd->intermission) {
+ MVD_IntermissionStop(mvd);
}
// update UDP clients
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state == cs_spawned ) {
- MVD_UpdateClient( client );
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state == cs_spawned) {
+ MVD_UpdateClient(client);
}
}
}
-static void MVD_WriteDemoMessage( mvd_t *mvd ) {
+static void MVD_WriteDemoMessage(mvd_t *mvd)
+{
uint16_t msglen;
ssize_t ret;
- msglen = LittleShort( msg_read.cursize );
- ret = FS_Write( &msglen, 2, mvd->demorecording );
- if( ret != 2 )
+ msglen = LittleShort(msg_read.cursize);
+ ret = FS_Write(&msglen, 2, mvd->demorecording);
+ if (ret != 2)
goto fail;
- ret = FS_Write( msg_read.data, msg_read.cursize, mvd->demorecording );
- if( ret == msg_read.cursize )
+ ret = FS_Write(msg_read.data, msg_read.cursize, mvd->demorecording);
+ if (ret == msg_read.cursize)
return;
fail:
- Com_EPrintf( "[%s] Couldn't write demo: %s\n", mvd->name, Q_ErrorString( ret ) );
- MVD_StopRecord( mvd );
+ Com_EPrintf("[%s] Couldn't write demo: %s\n", mvd->name, Q_ErrorString(ret));
+ MVD_StopRecord(mvd);
}
-static void MVD_GameRunFrame( void ) {
+static void MVD_GameRunFrame(void)
+{
mvd_t *mvd, *next;
int numplayers = 0;
- LIST_FOR_EACH_SAFE( mvd_t, mvd, next, &mvd_channel_list, entry ) {
- if( setjmp( mvd_jmpbuf ) ) {
+ LIST_FOR_EACH_SAFE(mvd_t, mvd, next, &mvd_channel_list, entry) {
+ if (setjmp(mvd_jmpbuf)) {
continue;
}
// parse stream
- if( !mvd->read_frame( mvd ) ) {
+ if (!mvd->read_frame(mvd)) {
goto update;
}
// write this message to demofile
- if( mvd->demorecording ) {
- MVD_WriteDemoMessage( mvd );
+ if (mvd->demorecording) {
+ MVD_WriteDemoMessage(mvd);
}
update:
- MVD_UpdateLayouts( mvd );
+ MVD_UpdateLayouts(mvd);
numplayers += mvd->numplayers;
}
- MVD_UpdateLayouts( &mvd_waitingRoom );
-
- if( mvd_dirty ) {
- MVD_InfoSet( "mvd_channels", va( "%d", List_Count( &mvd_channel_list ) ) );
+ MVD_UpdateLayouts(&mvd_waitingRoom);
+
+ if (mvd_dirty) {
+ MVD_InfoSet("mvd_channels", va("%d", List_Count(&mvd_channel_list)));
mvd_dirty = qfalse;
}
- if( numplayers != mvd_numplayers ) {
- MVD_InfoSet( "mvd_players", va( "%d", numplayers ) );
+ if (numplayers != mvd_numplayers) {
+ MVD_InfoSet("mvd_players", va("%d", numplayers));
mvd_numplayers = numplayers;
mvd_dirty = qtrue; // update layouts next frame
}
}
-static void MVD_GameServerCommand( void ) {
+static void MVD_GameServerCommand(void)
+{
}
-void MVD_PrepWorldFrame( void ) {
+void MVD_PrepWorldFrame(void)
+{
mvd_t *mvd;
edict_t *ent;
int i;
// reset events and old origins
- FOR_EACH_MVD( mvd ) {
- for( i = 1, ent = &mvd->edicts[1]; i < mvd->pool.num_edicts; i++, ent++ ) {
- if( !ent->inuse ) {
+ FOR_EACH_MVD(mvd) {
+ for (i = 1, ent = &mvd->edicts[1]; i < mvd->pool.num_edicts; i++, ent++) {
+ if (!ent->inuse) {
continue;
}
- if( !( ent->s.renderfx & RF_BEAM ) ) {
- VectorCopy( ent->s.origin, ent->s.old_origin );
+ if (!(ent->s.renderfx & RF_BEAM)) {
+ VectorCopy(ent->s.origin, ent->s.old_origin);
}
ent->s.event = 0;
}
diff --git a/src/mvd_gtv.h b/src/mvd_gtv.h
index cac7567..edfac43 100644
--- a/src/mvd_gtv.h
+++ b/src/mvd_gtv.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/mvd_local.h b/src/mvd_local.h
index b516b11..b317dd9 100644
--- a/src/mvd_local.h
+++ b/src/mvd_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,24 +21,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sv_local.h"
#include "q_fifo.h"
-#define MVD_Malloc( size ) Z_TagMalloc( size, TAG_MVD )
-#define MVD_Mallocz( size ) Z_TagMallocz( size, TAG_MVD )
-#define MVD_CopyString( s ) Z_TagCopyString( s, TAG_MVD )
+#define MVD_Malloc(size) Z_TagMalloc(size, TAG_MVD)
+#define MVD_Mallocz(size) Z_TagMallocz(size, TAG_MVD)
+#define MVD_CopyString(s) Z_TagCopyString(s, TAG_MVD)
-#define FOR_EACH_MVD( mvd ) \
- LIST_FOR_EACH( mvd_t, mvd, &mvd_channel_list, entry )
+#define FOR_EACH_MVD(mvd) \
+ LIST_FOR_EACH(mvd_t, mvd, &mvd_channel_list, entry)
-#define FOR_EACH_MVDCL( cl, mvd ) \
- LIST_FOR_EACH( mvd_client_t, cl, &(mvd)->clients, entry )
+#define FOR_EACH_MVDCL(cl, mvd) \
+ LIST_FOR_EACH(mvd_client_t, cl, &(mvd)->clients, entry)
-#define EDICT_MVDCL( ent ) (( mvd_client_t * )( (ent)->client ))
-#define CS_NUM( c, n ) ( ( char * )(c) + (n) * MAX_QPATH )
+#define EDICT_MVDCL(ent) ((mvd_client_t *)((ent)->client))
+#define CS_NUM(c, n) ((char *)(c) + (n) * MAX_QPATH)
-#define MVD_InfoSet( var, val ) \
- Cvar_FullSet( var, val, CVAR_SERVERINFO|CVAR_GAME, FROM_CODE )
+#define MVD_InfoSet(var, val) \
+ Cvar_FullSet(var, val, CVAR_SERVERINFO | CVAR_GAME, FROM_CODE)
// game features MVD client supports
-#define MVD_FEATURES (GMF_CLIENTNUM|GMF_PROPERINUSE|GMF_WANT_ALL_DISCONNECTS)
+#define MVD_FEATURES (GMF_CLIENTNUM | GMF_PROPERINUSE | GMF_WANT_ALL_DISCONNECTS)
#define LAYOUT_MSEC 3000
@@ -52,8 +52,8 @@ typedef enum {
LAYOUT_CHANNELS // MVD channel list
} mvd_layout_t;
-#define FLOOD_SAMPLES 16
-#define FLOOD_MASK ( FLOOD_SAMPLES - 1 )
+#define FLOOD_SAMPLES 16
+#define FLOOD_MASK (FLOOD_SAMPLES - 1)
typedef struct mvd_cs_s {
struct mvd_cs_s *next;
@@ -69,11 +69,11 @@ typedef struct {
} mvd_player_t;
typedef struct {
-/* =================== */
+ /* =================== */
player_state_t ps;
int ping;
int clientNum;
-/* =================== */
+ /* =================== */
list_t entry;
struct mvd_s *mvd;
@@ -127,8 +127,8 @@ typedef struct mvd_s {
int id;
char name[MAX_MVD_NAME];
struct gtv_s *gtv;
- qboolean (*read_frame)( struct mvd_s * );
- qboolean (*forward_cmd)( mvd_client_t * );
+ qboolean (*read_frame)(struct mvd_s *);
+ qboolean (*forward_cmd)(mvd_client_t *);
// demo related variables
qhandle_t demorecording;
@@ -185,31 +185,30 @@ extern qboolean mvd_dirty;
extern cvar_t *mvd_shownet;
#endif
-void MVD_Destroyf( mvd_t *mvd, const char *fmt, ... )
- q_noreturn q_printf( 2, 3 );
-void MVD_Shutdown( void );
+void MVD_Destroyf(mvd_t *mvd, const char *fmt, ...) q_noreturn q_printf(2, 3);
+void MVD_Shutdown(void);
-mvd_t *MVD_SetChannel( int arg );
+mvd_t *MVD_SetChannel(int arg);
-void MVD_File_g( genctx_t *ctx );
+void MVD_File_g(genctx_t *ctx);
-void MVD_Spawn( void );
+void MVD_Spawn(void);
-void MVD_StopRecord( mvd_t *mvd );
+void MVD_StopRecord(mvd_t *mvd);
-void MVD_StreamedStop_f( void );
-void MVD_StreamedRecord_f( void );
+void MVD_StreamedStop_f(void);
+void MVD_StreamedRecord_f(void);
-void MVD_Register( void );
-int MVD_Frame( void );
+void MVD_Register(void);
+int MVD_Frame(void);
//
// mvd_parse.c
//
-qboolean MVD_ParseMessage( mvd_t *mvd );
-void MVD_ParseEntityString( mvd_t *mvd, const char *data );
-void MVD_ClearState( mvd_t *mvd, qboolean full );
+qboolean MVD_ParseMessage(mvd_t *mvd);
+void MVD_ParseEntityString(mvd_t *mvd, const char *data);
+void MVD_ClearState(mvd_t *mvd, qboolean full);
//
// mvd_game.c
@@ -217,16 +216,16 @@ void MVD_ClearState( mvd_t *mvd, qboolean full );
extern mvd_client_t *mvd_clients; // [maxclients]
-void MVD_SwitchChannel( mvd_client_t *client, mvd_t *mvd );
-void MVD_RemoveClient( client_t *client );
-void MVD_BroadcastPrintf( mvd_t *mvd, int level,
- int mask, const char *fmt, ... ) q_printf( 4, 5 );
-void MVD_PrepWorldFrame( void );
-void MVD_GameClientNameChanged( edict_t *ent, const char *name );
-void MVD_GameClientDrop( edict_t *ent, const char *prefix, const char *reason );
-void MVD_UpdateClients( mvd_t *mvd );
-void MVD_FreePlayer( mvd_player_t *player );
-void MVD_UpdateConfigstring( mvd_t *mvd, int index );
-void MVD_SetPlayerNames( mvd_t *mvd );
-void MVD_LinkEdict( mvd_t *mvd, edict_t *ent );
+void MVD_SwitchChannel(mvd_client_t *client, mvd_t *mvd);
+void MVD_RemoveClient(client_t *client);
+void MVD_BroadcastPrintf(mvd_t *mvd, int level,
+ int mask, const char *fmt, ...) q_printf(4, 5);
+void MVD_PrepWorldFrame(void);
+void MVD_GameClientNameChanged(edict_t *ent, const char *name);
+void MVD_GameClientDrop(edict_t *ent, const char *prefix, const char *reason);
+void MVD_UpdateClients(mvd_t *mvd);
+void MVD_FreePlayer(mvd_player_t *player);
+void MVD_UpdateConfigstring(mvd_t *mvd, int index);
+void MVD_SetPlayerNames(mvd_t *mvd);
+void MVD_LinkEdict(mvd_t *mvd, edict_t *ent);
diff --git a/src/mvd_parse.c b/src/mvd_parse.c
index e41e67b..c6a34f8 100644
--- a/src/mvd_parse.c
+++ b/src/mvd_parse.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,18 +27,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static qboolean match_ended_hack;
#ifdef _DEBUG
-#define SHOWNET(level,...) \
- if( mvd_shownet->integer > level ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
-
-#define MVD_ShowSVC( cmd ) \
- Com_Printf( "%3"PRIz":%s\n", msg_read.readcount - 1, \
- MVD_ServerCommandString( cmd ) )
-
-static const char *MVD_ServerCommandString( int cmd ) {
- switch( cmd ) {
- case -1: return "END OF MESSAGE";
- default: return "UNKNOWN COMMAND";
+#define SHOWNET(level, ...) \
+ if (mvd_shownet->integer > level) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
+
+#define MVD_ShowSVC(cmd) \
+ Com_Printf("%3"PRIz":%s\n", msg_read.readcount - 1, MVD_ServerCommandString(cmd))
+
+static const char *MVD_ServerCommandString(int cmd)
+{
+ switch (cmd) {
+ case -1: return "END OF MESSAGE";
+ default: return "UNKNOWN COMMAND";
#define M(x) \
case mvd_##x: return "mvd_" #x;
M(bad)
@@ -62,95 +62,96 @@ static const char *MVD_ServerCommandString( int cmd ) {
#define SHOWNET(...)
#endif
-void MVD_ParseEntityString( mvd_t *mvd, const char *data ) {
+void MVD_ParseEntityString(mvd_t *mvd, const char *data)
+{
const char *p;
char key[MAX_STRING_CHARS];
char value[MAX_STRING_CHARS];
char classname[MAX_QPATH];
vec3_t origin;
vec3_t angles;
-
- while( data ) {
- p = COM_Parse( &data );
- if( !p[0] ) {
+
+ while (data) {
+ p = COM_Parse(&data);
+ if (!p[0]) {
break;
}
- if( p[0] != '{' ) {
- Com_Error( ERR_DROP, "expected '{', found '%s'", p );
+ if (p[0] != '{') {
+ Com_Error(ERR_DROP, "expected '{', found '%s'", p);
}
-
+
classname[0] = 0;
- VectorClear( origin );
- VectorClear( angles );
- while( 1 ) {
- p = COM_Parse( &data );
- if( p[0] == '}' ) {
+ VectorClear(origin);
+ VectorClear(angles);
+ while (1) {
+ p = COM_Parse(&data);
+ if (p[0] == '}') {
break;
}
- if( p[0] == '{' ) {
- Com_Error( ERR_DROP, "expected key, found '{'" );
+ if (p[0] == '{') {
+ Com_Error(ERR_DROP, "expected key, found '{'");
}
- Q_strlcpy( key, p, sizeof( key ) );
-
- p = COM_Parse( &data );
- if( !data ) {
- Com_Error( ERR_DROP, "expected key/value pair, found EOF" );
+ Q_strlcpy(key, p, sizeof(key));
+
+ p = COM_Parse(&data);
+ if (!data) {
+ Com_Error(ERR_DROP, "expected key/value pair, found EOF");
}
- if( p[0] == '}' || p[0] == '{' ) {
- Com_Error( ERR_DROP, "expected value, found '%s'", p );
+ if (p[0] == '}' || p[0] == '{') {
+ Com_Error(ERR_DROP, "expected value, found '%s'", p);
}
- if( !strcmp( key, "classname" ) ) {
- Q_strlcpy( classname, p, sizeof( classname ) );
+ if (!strcmp(key, "classname")) {
+ Q_strlcpy(classname, p, sizeof(classname));
continue;
}
- Q_strlcpy( value, p, sizeof( value ) );
+ Q_strlcpy(value, p, sizeof(value));
p = value;
- if( !strcmp( key, "origin" ) ) {
- origin[0] = atof( COM_Parse( &p ) );
- origin[1] = atof( COM_Parse( &p ) );
- origin[2] = atof( COM_Parse( &p ) );
- } else if( !strncmp( key, "angle", 5 ) ) {
- if( key[5] == 0 ) {
+ if (!strcmp(key, "origin")) {
+ origin[0] = atof(COM_Parse(&p));
+ origin[1] = atof(COM_Parse(&p));
+ origin[2] = atof(COM_Parse(&p));
+ } else if (!strncmp(key, "angle", 5)) {
+ if (key[5] == 0) {
angles[0] = 0;
- angles[1] = atof( COM_Parse( &p ) );
+ angles[1] = atof(COM_Parse(&p));
angles[2] = 0;
- } else if( key[5] == 's' && key[6] == 0 ) {
- angles[0] = atof( COM_Parse( &p ) );
- angles[1] = atof( COM_Parse( &p ) );
- angles[2] = atof( COM_Parse( &p ) );
+ } else if (key[5] == 's' && key[6] == 0) {
+ angles[0] = atof(COM_Parse(&p));
+ angles[1] = atof(COM_Parse(&p));
+ angles[2] = atof(COM_Parse(&p));
}
}
}
- if( !classname[0] ) {
- Com_Error( ERR_DROP, "entity with no classname" );
+ if (!classname[0]) {
+ Com_Error(ERR_DROP, "entity with no classname");
}
- if( strncmp( classname, "info_player_", 12 ) ) {
+ if (strncmp(classname, "info_player_", 12)) {
continue;
}
- if( !strcmp( classname + 12, "intermission" ) ) {
- VectorCopy( origin, mvd->spawnOrigin );
- VectorCopy( angles, mvd->spawnAngles );
+ if (!strcmp(classname + 12, "intermission")) {
+ VectorCopy(origin, mvd->spawnOrigin);
+ VectorCopy(angles, mvd->spawnAngles);
break;
}
-
- if( !strcmp( classname + 12, "start" ) ||
- !strcmp( classname + 12, "deathmatch" ) )
- {
- VectorCopy( origin, mvd->spawnOrigin );
- VectorCopy( angles, mvd->spawnAngles );
+
+ if (!strcmp(classname + 12, "start") ||
+ !strcmp(classname + 12, "deathmatch")) {
+ VectorCopy(origin, mvd->spawnOrigin);
+ VectorCopy(angles, mvd->spawnAngles);
}
}
}
-static void MVD_ParseMulticast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
+static void MVD_ParseMulticast(mvd_t *mvd, mvd_ops_t op, int extrabits)
+{
mvd_client_t *client;
client_t *cl;
byte mask[VIS_MAX_BYTES];
@@ -164,7 +165,7 @@ static void MVD_ParseMulticast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
length = MSG_ReadByte();
length |= extrabits << 8;
- switch( op ) {
+ switch (op) {
case mvd_multicast_all_r:
reliable = qtrue;
// intentional fallthrough
@@ -176,122 +177,125 @@ static void MVD_ParseMulticast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
// intentional fallthrough
case mvd_multicast_phs:
leafnum = MSG_ReadWord();
- if( mvd->demoseeking ) {
+ if (mvd->demoseeking) {
leaf1 = NULL;
break;
}
- leaf1 = CM_LeafNum( &mvd->cm, leafnum );
- BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PHS );
+ leaf1 = CM_LeafNum(&mvd->cm, leafnum);
+ BSP_ClusterVis(mvd->cm.cache, mask, leaf1->cluster, DVIS_PHS);
break;
case mvd_multicast_pvs_r:
reliable = qtrue;
// intentional fallthrough
case mvd_multicast_pvs:
leafnum = MSG_ReadWord();
- if( mvd->demoseeking ) {
+ if (mvd->demoseeking) {
leaf1 = NULL;
break;
}
- leaf1 = CM_LeafNum( &mvd->cm, leafnum );
- BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PVS );
+ leaf1 = CM_LeafNum(&mvd->cm, leafnum);
+ BSP_ClusterVis(mvd->cm.cache, mask, leaf1->cluster, DVIS_PVS);
break;
default:
- MVD_Destroyf( mvd, "bad op" );
+ MVD_Destroyf(mvd, "bad op");
}
// skip data payload
data = msg_read.data + msg_read.readcount;
msg_read.readcount += length;
- if( msg_read.readcount > msg_read.cursize ) {
- MVD_Destroyf( mvd, "read past end of message" );
+ if (msg_read.readcount > msg_read.cursize) {
+ MVD_Destroyf(mvd, "read past end of message");
}
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
// send the data to all relevent clients
- FOR_EACH_MVDCL( client, mvd ) {
+ FOR_EACH_MVDCL(client, mvd) {
cl = client->cl;
- if( cl->state < cs_primed ) {
+ if (cl->state < cs_primed) {
continue;
}
// do not send unreliables to connecting clients
- if( !reliable && ( cl->state != cs_spawned || cl->download || cl->nodata ) ) {
+ if (!reliable && (cl->state != cs_spawned || cl->download || cl->nodata)) {
continue;
}
- if( leaf1 ) {
+ if (leaf1) {
// find the client's PVS
ps = &client->ps;
#if 0
- VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, org );
+ VectorMA(ps->viewoffset, 0.125f, ps->pmove.origin, org);
#else
// FIXME: for some strange reason, game code assumes the server
// uses entity origin for PVS/PHS culling, not the view origin
- VectorScale( ps->pmove.origin, 0.125f, org );
+ VectorScale(ps->pmove.origin, 0.125f, org);
#endif
- leaf2 = CM_PointLeaf( &mvd->cm, org );
- if( !CM_AreasConnected( &mvd->cm, leaf1->area, leaf2->area ) )
+ leaf2 = CM_PointLeaf(&mvd->cm, org);
+ if (!CM_AreasConnected(&mvd->cm, leaf1->area, leaf2->area))
continue;
- if( leaf2->cluster == -1 )
+ if (leaf2->cluster == -1)
continue;
- if( !Q_IsBitSet( mask, leaf2->cluster ) )
+ if (!Q_IsBitSet(mask, leaf2->cluster))
continue;
}
- cl->AddMessage( cl, data, length, reliable );
+ cl->AddMessage(cl, data, length, reliable);
}
}
-static void MVD_UnicastSend( mvd_t *mvd, qboolean reliable, byte *data, size_t length, mvd_player_t *player ) {
+static void MVD_UnicastSend(mvd_t *mvd, qboolean reliable, byte *data, size_t length, mvd_player_t *player)
+{
mvd_player_t *target;
mvd_client_t *client;
client_t *cl;
-
+
// send to all relevant clients
- FOR_EACH_MVDCL( client, mvd ) {
+ FOR_EACH_MVDCL(client, mvd) {
cl = client->cl;
- if( cl->state < cs_spawned ) {
+ if (cl->state < cs_spawned) {
continue;
}
target = client->target ? client->target : mvd->dummy;
- if( target == player ) {
- cl->AddMessage( cl, data, length, reliable );
+ if (target == player) {
+ cl->AddMessage(cl, data, length, reliable);
}
}
}
-static void MVD_UnicastLayout( mvd_t *mvd, mvd_player_t *player ) {
+static void MVD_UnicastLayout(mvd_t *mvd, mvd_player_t *player)
+{
mvd_client_t *client;
- if( player != mvd->dummy ) {
- MSG_ReadString( NULL, 0 );
+ if (player != mvd->dummy) {
+ MSG_ReadString(NULL, 0);
return; // we don't care about others
}
- MSG_ReadString( mvd->layout, sizeof( mvd->layout ) );
+ MSG_ReadString(mvd->layout, sizeof(mvd->layout));
// HACK: if we got "match ended" string this frame, save oldscores
- if( match_ended_hack ) {
- strcpy( mvd->oldscores, mvd->layout );
+ if (match_ended_hack) {
+ strcpy(mvd->oldscores, mvd->layout);
}
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
// force an update to all relevant clients
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->cl->state < cs_spawned ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->cl->state < cs_spawned) {
continue;
}
- if( client->layout_type == LAYOUT_SCORES ) {
+ if (client->layout_type == LAYOUT_SCORES) {
client->layout_time = 0;
}
}
}
-static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) {
+static void MVD_UnicastString(mvd_t *mvd, qboolean reliable, mvd_player_t *player)
+{
int index;
char string[MAX_QPATH];
mvd_cs_t *cs;
@@ -302,42 +306,43 @@ static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *play
readcount = msg_read.readcount - 1;
index = MSG_ReadShort();
- length = MSG_ReadString( string, sizeof( string ) );
+ length = MSG_ReadString(string, sizeof(string));
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ MVD_Destroyf(mvd, "%s: bad index: %d", __func__, index);
}
- if( index < CS_GENERAL ) {
- Com_DPrintf( "%s: common configstring: %d\n", __func__, index );
+ if (index < CS_GENERAL) {
+ Com_DPrintf("%s: common configstring: %d\n", __func__, index);
return;
}
- if( length >= sizeof( string ) ) {
- Com_DPrintf( "%s: oversize configstring: %d\n", __func__, index );
+ if (length >= sizeof(string)) {
+ Com_DPrintf("%s: oversize configstring: %d\n", __func__, index);
return;
}
- for( cs = player->configstrings; cs; cs = cs->next ) {
- if( cs->index == index ) {
+ for (cs = player->configstrings; cs; cs = cs->next) {
+ if (cs->index == index) {
break;
}
}
- if( !cs ) {
- cs = MVD_Malloc( sizeof( *cs ) + MAX_QPATH - 1 );
+ if (!cs) {
+ cs = MVD_Malloc(sizeof(*cs) + MAX_QPATH - 1);
cs->index = index;
cs->next = player->configstrings;
player->configstrings = cs;
}
- memcpy( cs->string, string, length + 1 );
+ memcpy(cs->string, string, length + 1);
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
length = msg_read.readcount - readcount;
- MVD_UnicastSend( mvd, reliable, data, length, player );
+ MVD_UnicastSend(mvd, reliable, data, length, player);
}
-static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) {
+static void MVD_UnicastPrint(mvd_t *mvd, qboolean reliable, mvd_player_t *player)
+{
int level;
byte *data;
size_t readcount, length;
@@ -349,54 +354,55 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe
readcount = msg_read.readcount - 1;
level = MSG_ReadByte();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
length = msg_read.readcount - readcount;
-
+
// send to all relevant clients
- FOR_EACH_MVDCL( client, mvd ) {
+ FOR_EACH_MVDCL(client, mvd) {
cl = client->cl;
- if( cl->state < cs_spawned ) {
+ if (cl->state < cs_spawned) {
continue;
}
- if( level < cl->messagelevel ) {
+ if (level < cl->messagelevel) {
continue;
}
- if( level == PRINT_CHAT && ( client->uf & UF_MUTE_PLAYERS ) ) {
+ if (level == PRINT_CHAT && (client->uf & UF_MUTE_PLAYERS)) {
continue;
}
// decide if message should be routed or not
- target = ( mvd->flags & MVF_NOMSGS ) ? mvd->dummy :
- client->target ? client->target : mvd->dummy;
- if( target == player ) {
- cl->AddMessage( cl, data, length, reliable );
+ target = (mvd->flags & MVF_NOMSGS) ? mvd->dummy :
+ client->target ? client->target : mvd->dummy;
+ if (target == player) {
+ cl->AddMessage(cl, data, length, reliable);
}
}
}
-static void MVD_UnicastStuff( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) {
+static void MVD_UnicastStuff(mvd_t *mvd, qboolean reliable, mvd_player_t *player)
+{
char string[8];
byte *data;
size_t readcount, length;
- if( mvd->demoseeking ) {
- MSG_ReadString( NULL, 0 );
+ if (mvd->demoseeking) {
+ MSG_ReadString(NULL, 0);
return;
}
data = msg_read.data + msg_read.readcount - 1;
readcount = msg_read.readcount - 1;
- MSG_ReadString( string, sizeof( string ) );
- if( strncmp( string, "play ", 5 ) ) {
+ MSG_ReadString(string, sizeof(string));
+ if (strncmp(string, "play ", 5)) {
return;
}
length = msg_read.readcount - readcount;
- MVD_UnicastSend( mvd, reliable, data, length, player );
+ MVD_UnicastSend(mvd, reliable, data, length, player);
}
/*
@@ -405,7 +411,8 @@ MVD_ParseUnicast
Attempt to parse the datagram and find custom configstrings,
layouts, etc. Give up as soon as unknown command byte is encountered.
*/
-static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
+static void MVD_ParseUnicast(mvd_t *mvd, mvd_ops_t op, int extrabits)
+{
int clientNum;
size_t length, last;
mvd_player_t *player;
@@ -417,55 +424,55 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
length |= extrabits << 8;
clientNum = MSG_ReadByte();
- if( clientNum < 0 || clientNum >= mvd->maxclients ) {
- MVD_Destroyf( mvd, "%s: bad number: %d", __func__, clientNum );
+ if (clientNum < 0 || clientNum >= mvd->maxclients) {
+ MVD_Destroyf(mvd, "%s: bad number: %d", __func__, clientNum);
}
last = msg_read.readcount + length;
- if( last > msg_read.cursize ) {
- MVD_Destroyf( mvd, "%s: read past end of message", __func__ );
+ if (last > msg_read.cursize) {
+ MVD_Destroyf(mvd, "%s: read past end of message", __func__);
}
player = &mvd->players[clientNum];
reliable = op == mvd_unicast_r ? qtrue : qfalse;
- while( msg_read.readcount < last ) {
+ while (msg_read.readcount < last) {
cmd = MSG_ReadByte();
#ifdef _DEBUG
- if( mvd_shownet->integer > 1 ) {
- MSG_ShowSVC( cmd );
+ if (mvd_shownet->integer > 1) {
+ MSG_ShowSVC(cmd);
}
#endif
- switch( cmd ) {
+ switch (cmd) {
case svc_layout:
- MVD_UnicastLayout( mvd, player );
+ MVD_UnicastLayout(mvd, player);
break;
case svc_configstring:
- MVD_UnicastString( mvd, reliable, player );
+ MVD_UnicastString(mvd, reliable, player);
break;
case svc_print:
- MVD_UnicastPrint( mvd, reliable, player );
+ MVD_UnicastPrint(mvd, reliable, player);
break;
case svc_stufftext:
- MVD_UnicastStuff( mvd, reliable, player );
+ MVD_UnicastStuff(mvd, reliable, player);
break;
default:
- SHOWNET( 1, "%"PRIz":SKIPPING UNICAST\n", msg_read.readcount - 1 );
+ SHOWNET(1, "%"PRIz":SKIPPING UNICAST\n", msg_read.readcount - 1);
// send remaining data and return
data = msg_read.data + msg_read.readcount - 1;
length = last - msg_read.readcount + 1;
- if( !mvd->demoseeking )
- MVD_UnicastSend( mvd, reliable, data, length, player );
+ if (!mvd->demoseeking)
+ MVD_UnicastSend(mvd, reliable, data, length, player);
msg_read.readcount = last;
return;
}
}
- SHOWNET( 1, "%"PRIz":END OF UNICAST\n", msg_read.readcount - 1 );
+ SHOWNET(1, "%"PRIz":END OF UNICAST\n", msg_read.readcount - 1);
- if( msg_read.readcount > last ) {
- MVD_Destroyf( mvd, "%s: read past end of unicast", __func__ );
+ if (msg_read.readcount > last) {
+ MVD_Destroyf(mvd, "%s: read past end of unicast", __func__);
}
}
@@ -478,7 +485,8 @@ are able to postition sounds on BSP models properly.
FIXME: this duplicates code in sv_game.c
*/
-static void MVD_ParseSound( mvd_t *mvd, int extrabits ) {
+static void MVD_ParseSound(mvd_t *mvd, int extrabits)
+{
int flags, index;
int volume, attenuation, offset, sendchan;
int entnum;
@@ -497,98 +505,98 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) {
index = MSG_ReadByte();
volume = attenuation = offset = 0;
- if( flags & SND_VOLUME )
+ if (flags & SND_VOLUME)
volume = MSG_ReadByte();
- if( flags & SND_ATTENUATION )
+ if (flags & SND_ATTENUATION)
attenuation = MSG_ReadByte();
- if( flags & SND_OFFSET )
+ if (flags & SND_OFFSET)
offset = MSG_ReadByte();
// entity relative
sendchan = MSG_ReadShort();
entnum = sendchan >> 3;
- if( entnum < 0 || entnum >= MAX_EDICTS ) {
- MVD_Destroyf( mvd, "%s: bad entnum: %d", __func__, entnum );
+ if (entnum < 0 || entnum >= MAX_EDICTS) {
+ MVD_Destroyf(mvd, "%s: bad entnum: %d", __func__, entnum);
}
entity = &mvd->edicts[entnum];
- if( !entity->inuse ) {
- Com_DPrintf( "%s: entnum not in use: %d\n", __func__, entnum );
+ if (!entity->inuse) {
+ Com_DPrintf("%s: entnum not in use: %d\n", __func__, entnum);
return;
}
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
- FOR_EACH_MVDCL( client, mvd ) {
+ FOR_EACH_MVDCL(client, mvd) {
cl = client->cl;
// do not send unreliables to connecting clients
- if( cl->state != cs_spawned || cl->download || cl->nodata ) {
+ if (cl->state != cs_spawned || cl->download || cl->nodata) {
continue;
}
// PHS cull this sound
- if( !( extrabits & 1 ) ) {
+ if (!(extrabits & 1)) {
// get client viewpos
ps = &client->ps;
- VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, origin );
- leaf = CM_PointLeaf( &mvd->cm, origin );
- area = CM_LeafArea( leaf );
- if( !CM_AreasConnected( &mvd->cm, area, entity->areanum ) ) {
+ VectorMA(ps->viewoffset, 0.125f, ps->pmove.origin, origin);
+ leaf = CM_PointLeaf(&mvd->cm, origin);
+ area = CM_LeafArea(leaf);
+ if (!CM_AreasConnected(&mvd->cm, area, entity->areanum)) {
// doors can legally straddle two areas, so
// we may need to check another one
- if( !entity->areanum2 || !CM_AreasConnected( &mvd->cm, area, entity->areanum2 ) ) {
+ if (!entity->areanum2 || !CM_AreasConnected(&mvd->cm, area, entity->areanum2)) {
continue; // blocked by a door
}
}
- BSP_ClusterVis( mvd->cm.cache, mask, leaf->cluster, DVIS_PHS );
- if( !SV_EdictPV( &mvd->cm, entity, mask ) ) {
+ BSP_ClusterVis(mvd->cm.cache, mask, leaf->cluster, DVIS_PHS);
+ if (!SV_EdictPV(&mvd->cm, entity, mask)) {
continue; // not in PHS
}
}
// use the entity origin unless it is a bmodel
- if( entity->solid == SOLID_BSP ) {
- VectorAvg( entity->mins, entity->maxs, origin );
- VectorAdd( entity->s.origin, origin, origin );
+ if (entity->solid == SOLID_BSP) {
+ VectorAvg(entity->mins, entity->maxs, origin);
+ VectorAdd(entity->s.origin, origin, origin);
} else {
- VectorCopy( entity->s.origin, origin );
+ VectorCopy(entity->s.origin, origin);
}
// reliable sounds will always have position explicitly set,
// as no one gurantees reliables to be delivered in time
- if( extrabits & 2 ) {
- MSG_WriteByte( svc_sound );
- MSG_WriteByte( flags | SND_POS );
- MSG_WriteByte( index );
-
- if( flags & SND_VOLUME )
- MSG_WriteByte( volume );
- if( flags & SND_ATTENUATION )
- MSG_WriteByte( attenuation );
- if( flags & SND_OFFSET )
- MSG_WriteByte( offset );
-
- MSG_WriteShort( sendchan );
- MSG_WritePos( origin );
-
- SV_ClientAddMessage( cl, MSG_RELIABLE|MSG_CLEAR );
+ if (extrabits & 2) {
+ MSG_WriteByte(svc_sound);
+ MSG_WriteByte(flags | SND_POS);
+ MSG_WriteByte(index);
+
+ if (flags & SND_VOLUME)
+ MSG_WriteByte(volume);
+ if (flags & SND_ATTENUATION)
+ MSG_WriteByte(attenuation);
+ if (flags & SND_OFFSET)
+ MSG_WriteByte(offset);
+
+ MSG_WriteShort(sendchan);
+ MSG_WritePos(origin);
+
+ SV_ClientAddMessage(cl, MSG_RELIABLE | MSG_CLEAR);
continue;
}
- if( LIST_EMPTY( &cl->msg_free_list ) ) {
- Com_WPrintf( "%s: %s: out of message slots\n",
- __func__, cl->name );
+ if (LIST_EMPTY(&cl->msg_free_list)) {
+ Com_WPrintf("%s: %s: out of message slots\n",
+ __func__, cl->name);
continue;
}
// default client doesn't know that bmodels have weird origins
- if( entity->solid == SOLID_BSP && cl->protocol == PROTOCOL_VERSION_DEFAULT ) {
+ if (entity->solid == SOLID_BSP && cl->protocol == PROTOCOL_VERSION_DEFAULT) {
flags |= SND_POS;
}
- msg = LIST_FIRST( message_packet_t, &cl->msg_free_list, entry );
+ msg = LIST_FIRST(message_packet_t, &cl->msg_free_list, entry);
msg->cursize = 0;
msg->flags = flags;
@@ -597,90 +605,93 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) {
msg->attenuation = attenuation;
msg->timeofs = offset;
msg->sendchan = sendchan;
- for( i = 0; i < 3; i++ ) {
+ for (i = 0; i < 3; i++) {
msg->pos[i] = origin[i] * 8;
}
- List_Remove( &msg->entry );
- List_Append( &cl->msg_unreliable_list, &msg->entry );
+ List_Remove(&msg->entry);
+ List_Append(&cl->msg_unreliable_list, &msg->entry);
cl->msg_unreliable_bytes += MAX_SOUND_PACKET;
flags &= ~SND_POS;
}
}
-static void MVD_ParseConfigstring( mvd_t *mvd ) {
+static void MVD_ParseConfigstring(mvd_t *mvd)
+{
int index;
size_t len, maxlen;
char *s;
index = MSG_ReadShort();
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ MVD_Destroyf(mvd, "%s: bad index: %d", __func__, index);
}
s = mvd->configstrings[index];
- maxlen = CS_SIZE( index );
- len = MSG_ReadString( s, maxlen );
- if( len >= maxlen ) {
- MVD_Destroyf( mvd, "%s: index %d overflowed", __func__, index );
+ maxlen = CS_SIZE(index);
+ len = MSG_ReadString(s, maxlen);
+ if (len >= maxlen) {
+ MVD_Destroyf(mvd, "%s: index %d overflowed", __func__, index);
}
- if( mvd->demoseeking ) {
- Q_SetBit( mvd->dcs, index );
+ if (mvd->demoseeking) {
+ Q_SetBit(mvd->dcs, index);
return;
}
- MVD_UpdateConfigstring( mvd, index );
+ MVD_UpdateConfigstring(mvd, index);
}
-static void MVD_ParsePrint( mvd_t *mvd ) {
+static void MVD_ParsePrint(mvd_t *mvd)
+{
int level;
char string[MAX_STRING_CHARS];
level = MSG_ReadByte();
- MSG_ReadString( string, sizeof( string ) );
+ MSG_ReadString(string, sizeof(string));
- if( level == PRINT_HIGH && strstr( string, "Match ended." ) ) {
+ if (level == PRINT_HIGH && strstr(string, "Match ended.")) {
match_ended_hack = qtrue;
}
- if( mvd->demoseeking )
+ if (mvd->demoseeking)
return;
- MVD_BroadcastPrintf( mvd, level, level == PRINT_CHAT ?
- UF_MUTE_PLAYERS : 0, "%s", string );
+ MVD_BroadcastPrintf(mvd, level, level == PRINT_CHAT ?
+ UF_MUTE_PLAYERS : 0, "%s", string);
}
/*
Fix origin and angles on each player entity by
extracting data from player state.
*/
-static void MVD_PlayerToEntityStates( mvd_t *mvd ) {
+static void MVD_PlayerToEntityStates(mvd_t *mvd)
+{
mvd_player_t *player;
edict_t *edict;
int i;
mvd->numplayers = 0;
- for( i = 1, player = mvd->players; i <= mvd->maxclients; i++, player++ ) {
- if( !player->inuse || player == mvd->dummy ) {
+ for (i = 1, player = mvd->players; i <= mvd->maxclients; i++, player++) {
+ if (!player->inuse || player == mvd->dummy) {
continue;
}
mvd->numplayers++;
- if( player->ps.pmove.pm_type != PM_NORMAL ) {
+ if (player->ps.pmove.pm_type != PM_NORMAL) {
continue; // can be out of sync, in this case
- // server should provide valid data
+ // server should provide valid data
}
edict = &mvd->edicts[i];
- if( !edict->inuse ) {
+ if (!edict->inuse) {
continue; // not present in this frame
}
- Com_PlayerToEntityState( &player->ps, &edict->s );
+ Com_PlayerToEntityState(&player->ps, &edict->s);
- MVD_LinkEdict( mvd, edict );
+ MVD_LinkEdict(mvd, edict);
}
}
@@ -691,51 +702,52 @@ static void MVD_PlayerToEntityStates( mvd_t *mvd ) {
MVD_ParsePacketEntities
==================
*/
-static void MVD_ParsePacketEntities( mvd_t *mvd ) {
+static void MVD_ParsePacketEntities(mvd_t *mvd)
+{
int number;
int bits;
edict_t *ent;
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- MVD_Destroyf( mvd, "%s: read past end of message", __func__ );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ MVD_Destroyf(mvd, "%s: read past end of message", __func__);
}
- number = MSG_ParseEntityBits( &bits );
- if( number < 0 || number >= MAX_EDICTS ) {
- MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number );
+ number = MSG_ParseEntityBits(&bits);
+ if (number < 0 || number >= MAX_EDICTS) {
+ MVD_Destroyf(mvd, "%s: bad number: %d", __func__, number);
}
- if( !number ) {
+ if (!number) {
break;
}
ent = &mvd->edicts[number];
#ifdef _DEBUG
- if( mvd_shownet->integer > 2 ) {
- Com_Printf( " %s: %d ", ent->inuse ?
- "delta" : "baseline", number );
- MSG_ShowDeltaEntityBits( bits );
- Com_Printf( "\n" );
+ if (mvd_shownet->integer > 2) {
+ Com_Printf(" %s: %d ", ent->inuse ?
+ "delta" : "baseline", number);
+ MSG_ShowDeltaEntityBits(bits);
+ Com_Printf("\n");
}
#endif
- MSG_ParseDeltaEntity( &ent->s, &ent->s, number, bits, 0 );
+ MSG_ParseDeltaEntity(&ent->s, &ent->s, number, bits, 0);
// lazily relink even if removed
- if( ( bits & RELINK_MASK ) && !mvd->demoseeking ) {
- MVD_LinkEdict( mvd, ent );
+ if ((bits & RELINK_MASK) && !mvd->demoseeking) {
+ MVD_LinkEdict(mvd, ent);
}
- if( bits & U_REMOVE ) {
- SHOWNET( 2, " remove: %d\n", number );
+ if (bits & U_REMOVE) {
+ SHOWNET(2, " remove: %d\n", number);
ent->inuse = qfalse;
continue;
}
ent->inuse = qtrue;
- if( number >= mvd->pool.num_edicts ) {
+ if (number >= mvd->pool.num_edicts) {
mvd->pool.num_edicts = number + 1;
}
}
@@ -746,23 +758,24 @@ static void MVD_ParsePacketEntities( mvd_t *mvd ) {
MVD_ParsePacketPlayers
==================
*/
-static void MVD_ParsePacketPlayers( mvd_t *mvd ) {
+static void MVD_ParsePacketPlayers(mvd_t *mvd)
+{
int number;
int bits;
mvd_player_t *player;
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- MVD_Destroyf( mvd, "%s: read past end of message", __func__ );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ MVD_Destroyf(mvd, "%s: read past end of message", __func__);
}
number = MSG_ReadByte();
- if( number == CLIENTNUM_NONE ) {
+ if (number == CLIENTNUM_NONE) {
break;
}
- if( number < 0 || number >= mvd->maxclients ) {
- MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number );
+ if (number < 0 || number >= mvd->maxclients) {
+ MVD_Destroyf(mvd, "%s: bad number: %d", __func__, number);
}
player = &mvd->players[number];
@@ -770,18 +783,18 @@ static void MVD_ParsePacketPlayers( mvd_t *mvd ) {
bits = MSG_ReadShort();
#ifdef _DEBUG
- if( mvd_shownet->integer > 2 ) {
- Com_Printf( " %s: %d ", player->inuse ?
- "delta" : "baseline", number );
- MSG_ShowDeltaPlayerstateBits_Packet( bits );
- Com_Printf( "\n" );
+ if (mvd_shownet->integer > 2) {
+ Com_Printf(" %s: %d ", player->inuse ?
+ "delta" : "baseline", number);
+ MSG_ShowDeltaPlayerstateBits_Packet(bits);
+ Com_Printf("\n");
}
#endif
- MSG_ParseDeltaPlayerstate_Packet( &player->ps, &player->ps, bits );
+ MSG_ParseDeltaPlayerstate_Packet(&player->ps, &player->ps, bits);
- if( bits & PPS_REMOVE ) {
- SHOWNET( 2, " remove: %d\n", number );
+ if (bits & PPS_REMOVE) {
+ SHOWNET(2, " remove: %d\n", number);
player->inuse = qfalse;
continue;
}
@@ -795,18 +808,19 @@ static void MVD_ParsePacketPlayers( mvd_t *mvd ) {
MVD_ParseFrame
================
*/
-static void MVD_ParseFrame( mvd_t *mvd ) {
+static void MVD_ParseFrame(mvd_t *mvd)
+{
byte *data;
int length;
// read portalbits
length = MSG_ReadByte();
- if( length ) {
- if( length < 0 || msg_read.readcount + length > msg_read.cursize ) {
- MVD_Destroyf( mvd, "%s: read past end of message", __func__ );
+ if (length) {
+ if (length < 0 || msg_read.readcount + length > msg_read.cursize) {
+ MVD_Destroyf(mvd, "%s: read past end of message", __func__);
}
- if( length > MAX_MAP_PORTAL_BYTES ) {
- MVD_Destroyf( mvd, "%s: bad portalbits length: %d", __func__, length );
+ if (length > MAX_MAP_PORTAL_BYTES) {
+ MVD_Destroyf(mvd, "%s: bad portalbits length: %d", __func__, length);
}
data = msg_read.data + msg_read.readcount;
msg_read.readcount += length;
@@ -814,95 +828,97 @@ static void MVD_ParseFrame( mvd_t *mvd ) {
data = NULL;
}
- if( !mvd->demoseeking )
- CM_SetPortalStates( &mvd->cm, data, length );
+ if (!mvd->demoseeking)
+ CM_SetPortalStates(&mvd->cm, data, length);
- SHOWNET( 1, "%3"PRIz":playerinfo\n", msg_read.readcount - 1 );
- MVD_ParsePacketPlayers( mvd );
- SHOWNET( 1, "%3"PRIz":packetentities\n", msg_read.readcount - 1 );
- MVD_ParsePacketEntities( mvd );
- SHOWNET( 1, "%3"PRIz":frame:%u\n", msg_read.readcount - 1, mvd->framenum );
- MVD_PlayerToEntityStates( mvd );
+ SHOWNET(1, "%3"PRIz":playerinfo\n", msg_read.readcount - 1);
+ MVD_ParsePacketPlayers(mvd);
+ SHOWNET(1, "%3"PRIz":packetentities\n", msg_read.readcount - 1);
+ MVD_ParsePacketEntities(mvd);
+ SHOWNET(1, "%3"PRIz":frame:%u\n", msg_read.readcount - 1, mvd->framenum);
+ MVD_PlayerToEntityStates(mvd);
// update clients now so that effects datagram that
// follows can reference current view positions
- if( mvd->state && !mvd->demoseeking ) {
- MVD_UpdateClients( mvd );
+ if (mvd->state && !mvd->demoseeking) {
+ MVD_UpdateClients(mvd);
}
mvd->framenum++;
}
-void MVD_ClearState( mvd_t *mvd, qboolean full ) {
+void MVD_ClearState(mvd_t *mvd, qboolean full)
+{
mvd_player_t *player;
mvd_snap_t *snap, *next;
int i;
// clear all entities, don't trust num_edicts as it is possible
// to miscount removed entities
- memset( mvd->edicts, 0, sizeof( mvd->edicts ) );
+ memset(mvd->edicts, 0, sizeof(mvd->edicts));
mvd->pool.num_edicts = 0;
// clear all players
- for( i = 0; i < mvd->maxclients; i++ ) {
+ for (i = 0; i < mvd->maxclients; i++) {
player = &mvd->players[i];
- MVD_FreePlayer( player );
- memset( player, 0, sizeof( *player ) );
+ MVD_FreePlayer(player);
+ memset(player, 0, sizeof(*player));
}
mvd->numplayers = 0;
- if( !full )
+ if (!full)
return;
// free all snapshots
- LIST_FOR_EACH_SAFE( mvd_snap_t, snap, next, &mvd->snapshots, entry ) {
- Z_Free( snap );
+ LIST_FOR_EACH_SAFE(mvd_snap_t, snap, next, &mvd->snapshots, entry) {
+ Z_Free(snap);
}
- List_Init( &mvd->snapshots );
+ List_Init(&mvd->snapshots);
// free current map
- CM_FreeMap( &mvd->cm );
+ CM_FreeMap(&mvd->cm);
- if( mvd->intermission ) {
+ if (mvd->intermission) {
// save oldscores
- //strcpy( mvd->oldscores, mvd->layout );
+ //strcpy(mvd->oldscores, mvd->layout);
}
- memset( mvd->configstrings, 0, sizeof( mvd->configstrings ) );
+ memset(mvd->configstrings, 0, sizeof(mvd->configstrings));
mvd->layout[0] = 0;
mvd->framenum = 0;
// intermission flag will be cleared in MVD_ChangeLevel
}
-static void MVD_ChangeLevel( mvd_t *mvd ) {
+static void MVD_ChangeLevel(mvd_t *mvd)
+{
mvd_client_t *client;
- if( sv.state != ss_broadcast ) {
+ if (sv.state != ss_broadcast) {
// the game is just starting
- SV_InitGame( MVD_SPAWN_INTERNAL );
+ SV_InitGame(MVD_SPAWN_INTERNAL);
MVD_Spawn();
return;
}
// cause all UDP clients to reconnect
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( va( "changing map=%s; reconnect\n", mvd->mapname ) );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(va("changing map=%s; reconnect\n", mvd->mapname));
- FOR_EACH_MVDCL( client, mvd ) {
- if( client->target != mvd->dummy ) {
+ FOR_EACH_MVDCL(client, mvd) {
+ if (client->target != mvd->dummy) {
// make them switch to previous target instead of MVD dummy
client->oldtarget = client->target;
}
client->target = NULL;
- SV_ClientReset( client->cl );
+ SV_ClientReset(client->cl);
client->cl->spawncount = mvd->servercount;
- SV_ClientAddMessage( client->cl, MSG_RELIABLE );
+ SV_ClientAddMessage(client->cl, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
mvd->intermission = qfalse;
@@ -911,7 +927,8 @@ static void MVD_ChangeLevel( mvd_t *mvd ) {
SV_SendAsyncPackets();
}
-static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) {
+static void MVD_ParseServerData(mvd_t *mvd, int extrabits)
+{
int protocol;
size_t len, maxlen;
char *string;
@@ -920,158 +937,159 @@ static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) {
edict_t *ent;
// clear the leftover from previous level
- MVD_ClearState( mvd, qtrue );
+ MVD_ClearState(mvd, qtrue);
// parse major protocol version
protocol = MSG_ReadLong();
- if( protocol != PROTOCOL_VERSION_MVD ) {
- MVD_Destroyf( mvd, "Unsupported protocol: %d", protocol );
+ if (protocol != PROTOCOL_VERSION_MVD) {
+ MVD_Destroyf(mvd, "Unsupported protocol: %d", protocol);
}
// parse minor protocol version
protocol = MSG_ReadShort();
- if( !MVD_SUPPORTED( protocol ) ) {
- MVD_Destroyf( mvd, "Unsupported MVD protocol version: %d.\n"
- "Current version is %d.\n", protocol, PROTOCOL_VERSION_MVD_CURRENT );
+ if (!MVD_SUPPORTED(protocol)) {
+ MVD_Destroyf(mvd, "Unsupported MVD protocol version: %d.\n"
+ "Current version is %d.\n", protocol, PROTOCOL_VERSION_MVD_CURRENT);
}
mvd->servercount = MSG_ReadLong();
- len = MSG_ReadString( mvd->gamedir, sizeof( mvd->gamedir ) );
- if( len >= sizeof( mvd->gamedir ) ) {
- MVD_Destroyf( mvd, "Oversize gamedir string" );
+ len = MSG_ReadString(mvd->gamedir, sizeof(mvd->gamedir));
+ if (len >= sizeof(mvd->gamedir)) {
+ MVD_Destroyf(mvd, "Oversize gamedir string");
}
mvd->clientNum = MSG_ReadShort();
mvd->flags = extrabits;
#if 0
// change gamedir unless playing a demo
- Cvar_UserSet( "game", mvd->gamedir );
+ Cvar_UserSet("game", mvd->gamedir);
#endif
// parse configstrings
- while( 1 ) {
+ while (1) {
index = MSG_ReadShort();
- if( index == MAX_CONFIGSTRINGS ) {
+ if (index == MAX_CONFIGSTRINGS) {
break;
}
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
- MVD_Destroyf( mvd, "Bad configstring index: %d", index );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
+ MVD_Destroyf(mvd, "Bad configstring index: %d", index);
}
string = mvd->configstrings[index];
- maxlen = CS_SIZE( index );
- len = MSG_ReadString( string, maxlen );
- if( len >= maxlen ) {
- MVD_Destroyf( mvd, "Configstring %d overflowed", index );
+ maxlen = CS_SIZE(index);
+ len = MSG_ReadString(string, maxlen);
+ if (len >= maxlen) {
+ MVD_Destroyf(mvd, "Configstring %d overflowed", index);
}
- if( msg_read.readcount > msg_read.cursize ) {
- MVD_Destroyf( mvd, "Read past end of message" );
+ if (msg_read.readcount > msg_read.cursize) {
+ MVD_Destroyf(mvd, "Read past end of message");
}
}
// parse maxclients
- index = atoi( mvd->configstrings[CS_MAXCLIENTS] );
- if( index < 1 || index > MAX_CLIENTS ) {
- MVD_Destroyf( mvd, "Invalid maxclients" );
+ index = atoi(mvd->configstrings[CS_MAXCLIENTS]);
+ if (index < 1 || index > MAX_CLIENTS) {
+ MVD_Destroyf(mvd, "Invalid maxclients");
}
// check if maxclients changed
- if( index != mvd->maxclients ) {
+ if (index != mvd->maxclients) {
mvd_client_t *client;
// free any old players
- Z_Free( mvd->players );
+ Z_Free(mvd->players);
// allocate new players
- mvd->players = MVD_Mallocz( sizeof( mvd_player_t ) * index );
+ mvd->players = MVD_Mallocz(sizeof(mvd_player_t) * index);
mvd->maxclients = index;
// clear chase targets
- FOR_EACH_MVDCL( client, mvd ) {
+ FOR_EACH_MVDCL(client, mvd) {
client->target = client->oldtarget = NULL;
}
}
// validate clientNum
- if( mvd->clientNum < 0 || mvd->clientNum >= mvd->maxclients ) {
- MVD_Destroyf( mvd, "Invalid client num: %d", mvd->clientNum );
+ if (mvd->clientNum < 0 || mvd->clientNum >= mvd->maxclients) {
+ MVD_Destroyf(mvd, "Invalid client num: %d", mvd->clientNum);
}
mvd->dummy = mvd->players + mvd->clientNum;
// parse world model
- string = mvd->configstrings[ CS_MODELS + 1 ];
- len = strlen( string );
- if( len <= 9 ) {
- MVD_Destroyf( mvd, "Bad world model: %s", string );
+ string = mvd->configstrings[CS_MODELS + 1];
+ len = strlen(string);
+ if (len <= 9) {
+ MVD_Destroyf(mvd, "Bad world model: %s", string);
}
- memcpy( mvd->mapname, string + 5, len - 9 ); // skip "maps/"
+ memcpy(mvd->mapname, string + 5, len - 9); // skip "maps/"
mvd->mapname[len - 9] = 0; // cut off ".bsp"
// load the world model (we are only interesed in visibility info)
- Com_Printf( "[%s] -=- Loading %s...\n", mvd->name, string );
- ret = CM_LoadMap( &mvd->cm, string );
- if( ret ) {
- Com_EPrintf( "[%s] =!= Couldn't load %s: %s\n", mvd->name, string, Q_ErrorString( ret ) );
+ Com_Printf("[%s] -=- Loading %s...\n", mvd->name, string);
+ ret = CM_LoadMap(&mvd->cm, string);
+ if (ret) {
+ Com_EPrintf("[%s] =!= Couldn't load %s: %s\n", mvd->name, string, Q_ErrorString(ret));
// continue with null visibility
}
#if USE_MAPCHECKSUM
- else if( mvd->cm.cache->checksum != atoi( mvd->configstrings[CS_MAPCHECKSUM] ) ) {
- Com_EPrintf( "[%s] =!= Local map version differs from server!\n", mvd->name );
- CM_FreeMap( &mvd->cm );
+ else if (mvd->cm.cache->checksum != atoi(mvd->configstrings[CS_MAPCHECKSUM])) {
+ Com_EPrintf("[%s] =!= Local map version differs from server!\n", mvd->name);
+ CM_FreeMap(&mvd->cm);
}
#endif
// set player names
- MVD_SetPlayerNames( mvd );
+ MVD_SetPlayerNames(mvd);
// init world entity
ent = &mvd->edicts[0];
ent->solid = SOLID_BSP;
ent->inuse = qtrue;
- if( mvd->cm.cache ) {
+ if (mvd->cm.cache) {
// get the spawn point for spectators
- MVD_ParseEntityString( mvd, mvd->cm.cache->entitystring );
+ MVD_ParseEntityString(mvd, mvd->cm.cache->entitystring);
}
// parse baseline frame
- MVD_ParseFrame( mvd );
+ MVD_ParseFrame(mvd);
// save base configstrings
- memcpy( mvd->baseconfigstrings, mvd->configstrings, sizeof( mvd->baseconfigstrings ) );
+ memcpy(mvd->baseconfigstrings, mvd->configstrings, sizeof(mvd->baseconfigstrings));
// force inital snapshot
mvd->last_snapshot = INT_MIN;
// if the channel has been just created, init some things
- if( !mvd->state ) {
+ if (!mvd->state) {
mvd_t *cur;
// sort this one into the list of active channels
- FOR_EACH_MVD( cur ) {
- if( cur->id > mvd->id ) {
+ FOR_EACH_MVD(cur) {
+ if (cur->id > mvd->id) {
break;
}
}
- List_Append( &cur->entry, &mvd->entry );
+ List_Append(&cur->entry, &mvd->entry);
mvd->state = MVD_WAITING;
}
// case all UDP clients to reconnect
- MVD_ChangeLevel( mvd );
+ MVD_ChangeLevel(mvd);
}
-qboolean MVD_ParseMessage( mvd_t *mvd ) {
+qboolean MVD_ParseMessage(mvd_t *mvd)
+{
int cmd, extrabits;
qboolean ret = qfalse;
#ifdef _DEBUG
- if( mvd_shownet->integer == 1 ) {
- Com_Printf( "%"PRIz" ", msg_read.cursize );
- } else if( mvd_shownet->integer > 1 ) {
- Com_Printf( "------------------\n" );
+ if (mvd_shownet->integer == 1) {
+ Com_Printf("%"PRIz" ", msg_read.cursize);
+ } else if (mvd_shownet->integer > 1) {
+ Com_Printf("------------------\n");
}
#endif
@@ -1079,12 +1097,12 @@ qboolean MVD_ParseMessage( mvd_t *mvd ) {
// parse the message
//
match_ended_hack = qfalse;
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- MVD_Destroyf( mvd, "Read past end of message" );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ MVD_Destroyf(mvd, "Read past end of message");
}
- if( msg_read.readcount == msg_read.cursize ) {
- SHOWNET( 1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 );
+ if (msg_read.readcount == msg_read.cursize) {
+ SHOWNET(1, "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1);
break;
}
@@ -1093,14 +1111,14 @@ qboolean MVD_ParseMessage( mvd_t *mvd ) {
cmd &= SVCMD_MASK;
#ifdef _DEBUG
- if( mvd_shownet->integer > 1 ) {
- MVD_ShowSVC( cmd );
+ if (mvd_shownet->integer > 1) {
+ MVD_ShowSVC(cmd);
}
#endif
-
- switch( cmd ) {
+
+ switch (cmd) {
case mvd_serverdata:
- MVD_ParseServerData( mvd, extrabits );
+ MVD_ParseServerData(mvd, extrabits);
ret |= qtrue;
break;
case mvd_multicast_all:
@@ -1109,29 +1127,29 @@ qboolean MVD_ParseMessage( mvd_t *mvd ) {
case mvd_multicast_all_r:
case mvd_multicast_pvs_r:
case mvd_multicast_phs_r:
- MVD_ParseMulticast( mvd, cmd, extrabits );
+ MVD_ParseMulticast(mvd, cmd, extrabits);
break;
case mvd_unicast:
case mvd_unicast_r:
- MVD_ParseUnicast( mvd, cmd, extrabits );
+ MVD_ParseUnicast(mvd, cmd, extrabits);
break;
case mvd_configstring:
- MVD_ParseConfigstring( mvd );
+ MVD_ParseConfigstring(mvd);
break;
case mvd_frame:
- MVD_ParseFrame( mvd );
+ MVD_ParseFrame(mvd);
break;
case mvd_sound:
- MVD_ParseSound( mvd, extrabits );
+ MVD_ParseSound(mvd, extrabits);
break;
case mvd_print:
- MVD_ParsePrint( mvd );
+ MVD_ParsePrint(mvd);
break;
case mvd_nop:
break;
default:
- MVD_Destroyf( mvd, "Illegible command at %"PRIz": %d",
- msg_read.readcount - 1, cmd );
+ MVD_Destroyf(mvd, "Illegible command at %"PRIz": %d",
+ msg_read.readcount - 1, cmd);
}
}
diff --git a/src/mvd_public.h b/src/mvd_public.h
index 7883504..0e3b6f6 100644
--- a/src/mvd_public.h
+++ b/src/mvd_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,16 +24,16 @@ extern list_t mvd_gtv_list;
struct client_s;
-void MVD_Register( void );
-void MVD_Shutdown( void );
-void MVD_RemoveClient( struct client_s *client );
-int MVD_Frame( void );
-void MVD_PrepWorldFrame( void );
+void MVD_Register(void);
+void MVD_Shutdown(void);
+void MVD_RemoveClient(struct client_s *client);
+int MVD_Frame(void);
+void MVD_PrepWorldFrame(void);
-void MVD_GameClientDrop( edict_t *ent, const char *prefix, const char *reason );
-void MVD_GameClientNameChanged( edict_t *ent, const char *name );
+void MVD_GameClientDrop(edict_t *ent, const char *prefix, const char *reason);
+void MVD_GameClientNameChanged(edict_t *ent, const char *name);
-void MVD_StreamedStop_f( void );
-void MVD_StreamedRecord_f( void );
-void MVD_File_g( genctx_t *ctx );
+void MVD_StreamedStop_f(void);
+void MVD_StreamedRecord_f(void);
+void MVD_File_g(genctx_t *ctx);
diff --git a/src/net_chan.c b/src/net_chan.c
index 6ac2c9e..f4acd89 100644
--- a/src/net_chan.c
+++ b/src/net_chan.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -83,11 +83,11 @@ unacknowledged reliable
static cvar_t *showpackets;
static cvar_t *showdrop;
#define SHOWPACKET(...) \
- if( showpackets->integer ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (showpackets->integer) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#define SHOWDROP(...) \
- if( showdrop->integer ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (showdrop->integer) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#else
#define SHOWPACKET(...)
#define SHOWDROP(...)
@@ -98,9 +98,10 @@ cvar_t *net_maxmsglen;
cvar_t *net_chantype;
// allow either 0 (no hard limit), or an integer between 512 and 4086
-static void net_maxmsglen_changed( cvar_t *self ) {
- if( self->integer ) {
- Cvar_ClampInteger( self, MIN_PACKETLEN, MAX_PACKETLEN_WRITABLE );
+static void net_maxmsglen_changed(cvar_t *self)
+{
+ if (self->integer) {
+ Cvar_ClampInteger(self, MIN_PACKETLEN, MAX_PACKETLEN_WRITABLE);
}
}
@@ -110,20 +111,21 @@ Netchan_Init
===============
*/
-void Netchan_Init( void ) {
+void Netchan_Init(void)
+{
int port;
#ifdef _DEBUG
- showpackets = Cvar_Get( "showpackets", "0", 0 );
- showdrop = Cvar_Get( "showdrop", "0", 0 );
+ showpackets = Cvar_Get("showpackets", "0", 0);
+ showdrop = Cvar_Get("showdrop", "0", 0);
#endif
// pick a port value that should be nice and random
port = Sys_Milliseconds() & 0xffff;
- net_qport = Cvar_Get( "qport", va( "%d", port ), 0 );
- net_maxmsglen = Cvar_Get( "net_maxmsglen", "1390", 0 );
+ net_qport = Cvar_Get("qport", va("%d", port), 0);
+ net_maxmsglen = Cvar_Get("net_maxmsglen", "1390", 0);
net_maxmsglen->changed = net_maxmsglen_changed;
- net_chantype = Cvar_Get( "net_chantype", "1", 0 );
+ net_chantype = Cvar_Get("net_chantype", "1", 0);
}
/*
@@ -133,36 +135,37 @@ Netchan_OutOfBand
Sends a text message in an out-of-band datagram
================
*/
-void Netchan_OutOfBand( netsrc_t sock, const netadr_t *address,
- const char *format, ... )
+void Netchan_OutOfBand(netsrc_t sock, const netadr_t *address,
+ const char *format, ...)
{
va_list argptr;
struct {
uint32_t header;
- char data[MAX_PACKETLEN_DEFAULT-4];
+ char data[MAX_PACKETLEN_DEFAULT - 4];
} packet;
size_t len;
// write the packet header
packet.header = 0xffffffff;
-
- va_start( argptr, format );
- len = Q_vsnprintf( packet.data, sizeof( packet.data ), format, argptr );
- va_end( argptr );
- if( len >= sizeof( packet.data ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ va_start(argptr, format);
+ len = Q_vsnprintf(packet.data, sizeof(packet.data), format, argptr);
+ va_end(argptr);
+
+ if (len >= sizeof(packet.data)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
// send the datagram
- NET_SendPacket( sock, address, len + 4, &packet );
+ NET_SendPacket(sock, address, len + 4, &packet);
}
// ============================================================================
-static size_t NetchanOld_TransmitNextFragment( netchan_t *netchan ) {
- Com_Error( ERR_FATAL, "%s: not implemented", __func__ );
+static size_t NetchanOld_TransmitNextFragment(netchan_t *netchan)
+{
+ Com_Error(ERR_FATAL, "%s: not implemented", __func__);
return 0;
}
@@ -176,8 +179,9 @@ transmition / retransmition of the reliable messages.
A 0 length will still generate a packet and deal with the reliable messages.
================
*/
-static size_t NetchanOld_Transmit( netchan_t *netchan, size_t length, const void *data, int numpackets ) {
- netchan_old_t *chan = ( netchan_old_t * )netchan;
+static size_t NetchanOld_Transmit(netchan_t *netchan, size_t length, const void *data, int numpackets)
+{
+ netchan_old_t *chan = (netchan_old_t *)netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
qboolean send_reliable;
@@ -185,81 +189,80 @@ static size_t NetchanOld_Transmit( netchan_t *netchan, size_t length, const void
int i;
// check for message overflow
- if( netchan->message.overflowed ) {
+ if (netchan->message.overflowed) {
netchan->fatal_error = qtrue;
- Com_WPrintf( "%s: outgoing message overflow\n",
- NET_AdrToString( &netchan->remote_address ) );
+ Com_WPrintf("%s: outgoing message overflow\n",
+ NET_AdrToString(&netchan->remote_address));
return 0;
}
send_reliable = qfalse;
// if the remote side dropped the last reliable message, resend it
- if( netchan->incoming_acknowledged > chan->last_reliable_sequence &&
- chan->incoming_reliable_acknowledged != chan->reliable_sequence )
- {
+ if (netchan->incoming_acknowledged > chan->last_reliable_sequence &&
+ chan->incoming_reliable_acknowledged != chan->reliable_sequence) {
send_reliable = qtrue;
}
// if the reliable transmit buffer is empty, copy the current message out
- if( !netchan->reliable_length && netchan->message.cursize ) {
+ if (!netchan->reliable_length && netchan->message.cursize) {
send_reliable = qtrue;
- memcpy( chan->reliable_buf, chan->message_buf,
- netchan->message.cursize );
+ memcpy(chan->reliable_buf, chan->message_buf,
+ netchan->message.cursize);
netchan->reliable_length = netchan->message.cursize;
netchan->message.cursize = 0;
chan->reliable_sequence ^= 1;
}
// write the packet header
- w1 = ( netchan->outgoing_sequence & ~( 1 << 31 ) ) |
- ( send_reliable << 31 );
- w2 = ( netchan->incoming_sequence & ~( 1 << 31 ) ) |
- ( chan->incoming_reliable_sequence << 31 );
+ w1 = (netchan->outgoing_sequence & ~(1 << 31)) |
+ (send_reliable << 31);
+ w2 = (netchan->incoming_sequence & ~(1 << 31)) |
+ (chan->incoming_reliable_sequence << 31);
- SZ_TagInit( &send, send_buf, sizeof( send_buf ), SZ_NC_SEND_OLD );
+ SZ_TagInit(&send, send_buf, sizeof(send_buf), SZ_NC_SEND_OLD);
- SZ_WriteLong( &send, w1 );
- SZ_WriteLong( &send, w2 );
+ SZ_WriteLong(&send, w1);
+ SZ_WriteLong(&send, w2);
#if USE_CLIENT
// send the qport if we are a client
- if( netchan->sock == NS_CLIENT ) {
- if( netchan->protocol < PROTOCOL_VERSION_R1Q2 ) {
- SZ_WriteShort( &send, netchan->qport );
- } else if( netchan->qport ) {
- SZ_WriteByte( &send, netchan->qport );
+ if (netchan->sock == NS_CLIENT) {
+ if (netchan->protocol < PROTOCOL_VERSION_R1Q2) {
+ SZ_WriteShort(&send, netchan->qport);
+ } else if (netchan->qport) {
+ SZ_WriteByte(&send, netchan->qport);
}
}
#endif
// copy the reliable message to the packet first
- if( send_reliable ) {
- SZ_Write( &send, chan->reliable_buf, netchan->reliable_length );
+ if (send_reliable) {
+ SZ_Write(&send, chan->reliable_buf, netchan->reliable_length);
chan->last_reliable_sequence = netchan->outgoing_sequence;
}
// add the unreliable part if space is available
- if( send.maxsize - send.cursize >= length )
- SZ_Write( &send, data, length );
+ if (send.maxsize - send.cursize >= length)
+ SZ_Write(&send, data, length);
else
- Com_WPrintf( "%s: dumped unreliable\n",
- NET_AdrToString( &netchan->remote_address ) );
+ Com_WPrintf("%s: dumped unreliable\n",
+ NET_AdrToString(&netchan->remote_address));
- SHOWPACKET( "send %4"PRIz" : s=%d ack=%d rack=%d",
- send.cursize,
- netchan->outgoing_sequence,
- netchan->incoming_sequence,
- chan->incoming_reliable_sequence );
- if( send_reliable ) {
- SHOWPACKET( " reliable=%i", chan->reliable_sequence );
+ SHOWPACKET("send %4"PRIz" : s=%d ack=%d rack=%d",
+ send.cursize,
+ netchan->outgoing_sequence,
+ netchan->incoming_sequence,
+ chan->incoming_reliable_sequence);
+ if (send_reliable) {
+ SHOWPACKET(" reliable=%i", chan->reliable_sequence);
}
- SHOWPACKET( "\n" );
+ SHOWPACKET("\n");
// send the datagram
- for( i = 0; i < numpackets; i++ ) {
- NET_SendPacket( netchan->sock, &netchan->remote_address,
- send.cursize, send.data );
+ for (i = 0; i < numpackets; i++) {
+ NET_SendPacket(netchan->sock, &netchan->remote_address,
+ send.cursize, send.data);
}
netchan->outgoing_sequence++;
@@ -277,24 +280,25 @@ called when the current net_message is from remote_address
modifies net_message so that it points to the packet payload
=================
*/
-static qboolean NetchanOld_Process( netchan_t *netchan ) {
- netchan_old_t *chan = ( netchan_old_t * )netchan;
+static qboolean NetchanOld_Process(netchan_t *netchan)
+{
+ netchan_old_t *chan = (netchan_old_t *)netchan;
uint32_t sequence, sequence_ack;
uint32_t reliable_ack, reliable_message;
-// get sequence numbers
+// get sequence numbers
MSG_BeginReading();
sequence = MSG_ReadLong();
sequence_ack = MSG_ReadLong();
// read the qport if we are a server
#if USE_CLIENT
- if( netchan->sock == NS_SERVER )
+ if (netchan->sock == NS_SERVER)
#endif
{
- if( netchan->protocol < PROTOCOL_VERSION_R1Q2 ) {
+ if (netchan->protocol < PROTOCOL_VERSION_R1Q2) {
MSG_ReadShort();
- } else if( netchan->qport ) {
+ } else if (netchan->qport) {
MSG_ReadByte();
}
}
@@ -302,37 +306,37 @@ static qboolean NetchanOld_Process( netchan_t *netchan ) {
reliable_message = sequence >> 31;
reliable_ack = sequence_ack >> 31;
- sequence &= ~( 1 << 31 );
- sequence_ack &= ~( 1 << 31 );
+ sequence &= ~(1 << 31);
+ sequence_ack &= ~(1 << 31);
- SHOWPACKET( "recv %4"PRIz" : s=%d ack=%d rack=%d",
- msg_read.cursize,
- sequence,
- sequence_ack,
- reliable_ack );
- if( reliable_message ) {
- SHOWPACKET( " reliable=%d", chan->incoming_reliable_sequence ^ 1 );
+ SHOWPACKET("recv %4"PRIz" : s=%d ack=%d rack=%d",
+ msg_read.cursize,
+ sequence,
+ sequence_ack,
+ reliable_ack);
+ if (reliable_message) {
+ SHOWPACKET(" reliable=%d", chan->incoming_reliable_sequence ^ 1);
}
- SHOWPACKET( "\n" );
+ SHOWPACKET("\n");
//
// discard stale or duplicated packets
//
- if( sequence <= netchan->incoming_sequence ) {
- SHOWDROP( "%s: out of order packet %i at %i\n",
- NET_AdrToString( &netchan->remote_address ),
- sequence, netchan->incoming_sequence );
+ if (sequence <= netchan->incoming_sequence) {
+ SHOWDROP("%s: out of order packet %i at %i\n",
+ NET_AdrToString(&netchan->remote_address),
+ sequence, netchan->incoming_sequence);
return qfalse;
}
//
// dropped packets don't keep the message from being used
//
- netchan->dropped = sequence - ( netchan->incoming_sequence + 1 );
- if( netchan->dropped > 0 ) {
- SHOWDROP( "%s: dropped %i packets at %i\n",
- NET_AdrToString( &netchan->remote_address ),
- netchan->dropped, sequence );
+ netchan->dropped = sequence - (netchan->incoming_sequence + 1);
+ if (netchan->dropped > 0) {
+ SHOWDROP("%s: dropped %i packets at %i\n",
+ NET_AdrToString(&netchan->remote_address),
+ netchan->dropped, sequence);
}
//
@@ -340,15 +344,15 @@ static qboolean NetchanOld_Process( netchan_t *netchan ) {
// clear the buffer to make way for the next
//
chan->incoming_reliable_acknowledged = reliable_ack;
- if( reliable_ack == chan->reliable_sequence )
+ if (reliable_ack == chan->reliable_sequence)
netchan->reliable_length = 0; // it has been received
-
+
//
-// if this message contains a reliable message, bump incoming_reliable_sequence
+// if this message contains a reliable message, bump incoming_reliable_sequence
//
netchan->incoming_sequence = sequence;
netchan->incoming_acknowledged = sequence_ack;
- if( reliable_message ) {
+ if (reliable_message) {
netchan->reliable_ack_pending = qtrue;
chan->incoming_reliable_sequence ^= 1;
}
@@ -369,10 +373,10 @@ static qboolean NetchanOld_Process( netchan_t *netchan ) {
NetchanOld_ShouldUpdate
================
*/
-static qboolean NetchanOld_ShouldUpdate( netchan_t *netchan ) {
- if( netchan->message.cursize || netchan->reliable_ack_pending ||
- com_localTime - netchan->last_sent > 1000 )
- {
+static qboolean NetchanOld_ShouldUpdate(netchan_t *netchan)
+{
+ if (netchan->message.cursize || netchan->reliable_ack_pending ||
+ com_localTime - netchan->last_sent > 1000) {
return qtrue;
}
@@ -386,17 +390,17 @@ NetchanOld_Setup
called to open a channel to a remote system
==============
*/
-static netchan_t *NetchanOld_Setup( netsrc_t sock, const netadr_t *adr,
- int qport, size_t maxpacketlen )
+static netchan_t *NetchanOld_Setup(netsrc_t sock, const netadr_t *adr,
+ int qport, size_t maxpacketlen)
{
netchan_old_t *chan;
netchan_t *netchan;
- Z_Reserve( sizeof( *chan ) + maxpacketlen * 2 );
+ Z_Reserve(sizeof(*chan) + maxpacketlen * 2);
- chan = Z_ReservedAlloc( sizeof( *chan ) );
- memset( chan, 0, sizeof( *chan ) );
- netchan = ( netchan_t * )chan;
+ chan = Z_ReservedAlloc(sizeof(*chan));
+ memset(chan, 0, sizeof(*chan));
+ netchan = (netchan_t *)chan;
netchan->sock = sock;
netchan->remote_address = *adr;
netchan->qport = qport;
@@ -411,10 +415,10 @@ static netchan_t *NetchanOld_Setup( netsrc_t sock, const netadr_t *adr,
netchan->TransmitNextFragment = NetchanOld_TransmitNextFragment;
netchan->ShouldUpdate = NetchanOld_ShouldUpdate;
- chan->message_buf = Z_ReservedAlloc( maxpacketlen );
- SZ_Init( &netchan->message, chan->message_buf, maxpacketlen );
+ chan->message_buf = Z_ReservedAlloc(maxpacketlen);
+ SZ_Init(&netchan->message, chan->message_buf, maxpacketlen);
- chan->reliable_buf = Z_ReservedAlloc( maxpacketlen );
+ chan->reliable_buf = Z_ReservedAlloc(maxpacketlen);
return netchan;
}
@@ -427,8 +431,9 @@ static netchan_t *NetchanOld_Setup( netsrc_t sock, const netadr_t *adr,
NetchanNew_TransmitNextFragment
================
*/
-static size_t NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
- netchan_new_t *chan = ( netchan_new_t * )netchan;
+static size_t NetchanNew_TransmitNextFragment(netchan_t *netchan)
+{
+ netchan_new_t *chan = (netchan_new_t *)netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
qboolean send_reliable;
@@ -440,70 +445,69 @@ static size_t NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
send_reliable = netchan->reliable_length ? qtrue : qfalse;
// write the packet header
- w1 = ( netchan->outgoing_sequence & 0x3FFFFFFF ) | ( 1 << 30 ) |
- ( send_reliable << 31 );
- w2 = ( netchan->incoming_sequence & 0x3FFFFFFF ) | ( 0 << 30 ) |
- ( chan->incoming_reliable_sequence << 31 );
+ w1 = (netchan->outgoing_sequence & 0x3FFFFFFF) | (1 << 30) |
+ (send_reliable << 31);
+ w2 = (netchan->incoming_sequence & 0x3FFFFFFF) | (0 << 30) |
+ (chan->incoming_reliable_sequence << 31);
- SZ_TagInit( &send, send_buf, sizeof( send_buf ), SZ_NC_SEND_FRG );
+ SZ_TagInit(&send, send_buf, sizeof(send_buf), SZ_NC_SEND_FRG);
- SZ_WriteLong( &send, w1 );
- SZ_WriteLong( &send, w2 );
+ SZ_WriteLong(&send, w1);
+ SZ_WriteLong(&send, w2);
#if USE_CLIENT
// send the qport if we are a client
- if( netchan->sock == NS_CLIENT && netchan->qport ) {
- SZ_WriteByte( &send, netchan->qport );
+ if (netchan->sock == NS_CLIENT && netchan->qport) {
+ SZ_WriteByte(&send, netchan->qport);
}
#endif
fragment_length = chan->fragment_out.cursize - chan->fragment_out.readcount;
- if( fragment_length > netchan->maxpacketlen ) {
+ if (fragment_length > netchan->maxpacketlen) {
fragment_length = netchan->maxpacketlen;
}
-
+
more_fragments = qtrue;
- if( chan->fragment_out.readcount + fragment_length ==
- chan->fragment_out.cursize )
- {
+ if (chan->fragment_out.readcount + fragment_length ==
+ chan->fragment_out.cursize) {
more_fragments = qfalse;
}
// write fragment offset
- offset = ( chan->fragment_out.readcount & 0x7FFF ) |
- ( more_fragments << 15 );
- SZ_WriteShort( &send, offset );
+ offset = (chan->fragment_out.readcount & 0x7FFF) |
+ (more_fragments << 15);
+ SZ_WriteShort(&send, offset);
// write fragment contents
- SZ_Write( &send, chan->fragment_out.data + chan->fragment_out.readcount,
- fragment_length );
-
- SHOWPACKET( "send %4"PRIz" : s=%d ack=%d rack=%d "
- "fragment_offset=%"PRIz" more_fragments=%d",
- send.cursize,
- netchan->outgoing_sequence,
- netchan->incoming_sequence,
- chan->incoming_reliable_sequence,
- chan->fragment_out.readcount,
- more_fragments );
- if( send_reliable ) {
- SHOWPACKET( " reliable=%i ", chan->reliable_sequence );
- }
- SHOWPACKET( "\n" );
+ SZ_Write(&send, chan->fragment_out.data + chan->fragment_out.readcount,
+ fragment_length);
+
+ SHOWPACKET("send %4"PRIz" : s=%d ack=%d rack=%d "
+ "fragment_offset=%"PRIz" more_fragments=%d",
+ send.cursize,
+ netchan->outgoing_sequence,
+ netchan->incoming_sequence,
+ chan->incoming_reliable_sequence,
+ chan->fragment_out.readcount,
+ more_fragments);
+ if (send_reliable) {
+ SHOWPACKET(" reliable=%i ", chan->reliable_sequence);
+ }
+ SHOWPACKET("\n");
chan->fragment_out.readcount += fragment_length;
netchan->fragment_pending = more_fragments;
// if the message has been sent completely, clear the fragment buffer
- if( !netchan->fragment_pending ) {
+ if (!netchan->fragment_pending) {
netchan->outgoing_sequence++;
netchan->last_sent = com_localTime;
- SZ_Clear( &chan->fragment_out );
+ SZ_Clear(&chan->fragment_out);
}
// send the datagram
- NET_SendPacket( netchan->sock, &netchan->remote_address,
- send.cursize, send.data );
+ NET_SendPacket(netchan->sock, &netchan->remote_address,
+ send.cursize, send.data);
return send.cursize;
}
@@ -513,8 +517,9 @@ static size_t NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
NetchanNew_Transmit
================
*/
-static size_t NetchanNew_Transmit( netchan_t *netchan, size_t length, const void *data, int numpackets ) {
- netchan_new_t *chan = ( netchan_new_t * )netchan;
+static size_t NetchanNew_Transmit(netchan_t *netchan, size_t length, const void *data, int numpackets)
+{
+ netchan_new_t *chan = (netchan_new_t *)netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
qboolean send_reliable;
@@ -522,93 +527,91 @@ static size_t NetchanNew_Transmit( netchan_t *netchan, size_t length, const void
int i;
// check for message overflow
- if( netchan->message.overflowed ) {
+ if (netchan->message.overflowed) {
netchan->fatal_error = qtrue;
- Com_WPrintf( "%s: outgoing message overflow\n",
- NET_AdrToString( &netchan->remote_address ) );
+ Com_WPrintf("%s: outgoing message overflow\n",
+ NET_AdrToString(&netchan->remote_address));
return 0;
}
- if( netchan->fragment_pending ) {
- return NetchanNew_TransmitNextFragment( netchan );
+ if (netchan->fragment_pending) {
+ return NetchanNew_TransmitNextFragment(netchan);
}
send_reliable = qfalse;
// if the remote side dropped the last reliable message, resend it
- if( netchan->incoming_acknowledged > chan->last_reliable_sequence &&
- chan->incoming_reliable_acknowledged != chan->reliable_sequence )
- {
+ if (netchan->incoming_acknowledged > chan->last_reliable_sequence &&
+ chan->incoming_reliable_acknowledged != chan->reliable_sequence) {
send_reliable = qtrue;
}
// if the reliable transmit buffer is empty, copy the current message out
- if( !netchan->reliable_length && netchan->message.cursize ) {
+ if (!netchan->reliable_length && netchan->message.cursize) {
send_reliable = qtrue;
- memcpy( chan->reliable_buf, chan->message_buf,
- netchan->message.cursize );
+ memcpy(chan->reliable_buf, chan->message_buf,
+ netchan->message.cursize);
netchan->reliable_length = netchan->message.cursize;
netchan->message.cursize = 0;
chan->reliable_sequence ^= 1;
}
- if( length > netchan->maxpacketlen || ( send_reliable &&
- ( netchan->reliable_length + length > netchan->maxpacketlen ) ) )
- {
- if( send_reliable ) {
+ if (length > netchan->maxpacketlen || (send_reliable &&
+ (netchan->reliable_length + length > netchan->maxpacketlen))) {
+ if (send_reliable) {
chan->last_reliable_sequence = netchan->outgoing_sequence;
- SZ_Write( &chan->fragment_out, chan->reliable_buf,
- netchan->reliable_length );
+ SZ_Write(&chan->fragment_out, chan->reliable_buf,
+ netchan->reliable_length);
}
// add the unreliable part if space is available
- if( chan->fragment_out.maxsize - chan->fragment_out.cursize >= length )
- SZ_Write( &chan->fragment_out, data, length );
+ if (chan->fragment_out.maxsize - chan->fragment_out.cursize >= length)
+ SZ_Write(&chan->fragment_out, data, length);
else
- Com_WPrintf( "%s: dumped unreliable\n",
- NET_AdrToString( &netchan->remote_address ) );
- return NetchanNew_TransmitNextFragment( netchan );
+ Com_WPrintf("%s: dumped unreliable\n",
+ NET_AdrToString(&netchan->remote_address));
+ return NetchanNew_TransmitNextFragment(netchan);
}
// write the packet header
- w1 = ( netchan->outgoing_sequence & 0x3FFFFFFF ) | ( send_reliable << 31 );
- w2 = ( netchan->incoming_sequence & 0x3FFFFFFF ) |
- ( chan->incoming_reliable_sequence << 31 );
+ w1 = (netchan->outgoing_sequence & 0x3FFFFFFF) | (send_reliable << 31);
+ w2 = (netchan->incoming_sequence & 0x3FFFFFFF) |
+ (chan->incoming_reliable_sequence << 31);
- SZ_TagInit( &send, send_buf, sizeof( send_buf ), SZ_NC_SEND_NEW );
+ SZ_TagInit(&send, send_buf, sizeof(send_buf), SZ_NC_SEND_NEW);
- SZ_WriteLong( &send, w1 );
- SZ_WriteLong( &send, w2 );
+ SZ_WriteLong(&send, w1);
+ SZ_WriteLong(&send, w2);
#if USE_CLIENT
// send the qport if we are a client
- if( netchan->sock == NS_CLIENT && netchan->qport ) {
- SZ_WriteByte( &send, netchan->qport );
+ if (netchan->sock == NS_CLIENT && netchan->qport) {
+ SZ_WriteByte(&send, netchan->qport);
}
#endif
-
+
// copy the reliable message to the packet first
- if( send_reliable ) {
+ if (send_reliable) {
chan->last_reliable_sequence = netchan->outgoing_sequence;
- SZ_Write( &send, chan->reliable_buf, netchan->reliable_length );
+ SZ_Write(&send, chan->reliable_buf, netchan->reliable_length);
}
-
+
// add the unreliable part
- SZ_Write( &send, data, length );
+ SZ_Write(&send, data, length);
- SHOWPACKET( "send %4"PRIz" : s=%d ack=%d rack=%d",
- send.cursize,
- netchan->outgoing_sequence,
- netchan->incoming_sequence,
- chan->incoming_reliable_sequence );
- if( send_reliable ) {
- SHOWPACKET( " reliable=%d", chan->reliable_sequence );
+ SHOWPACKET("send %4"PRIz" : s=%d ack=%d rack=%d",
+ send.cursize,
+ netchan->outgoing_sequence,
+ netchan->incoming_sequence,
+ chan->incoming_reliable_sequence);
+ if (send_reliable) {
+ SHOWPACKET(" reliable=%d", chan->reliable_sequence);
}
- SHOWPACKET( "\n" );
+ SHOWPACKET("\n");
// send the datagram
- for( i = 0; i < numpackets; i++ ) {
- NET_SendPacket( netchan->sock, &netchan->remote_address,
- send.cursize, send.data );
+ for (i = 0; i < numpackets; i++) {
+ NET_SendPacket(netchan->sock, &netchan->remote_address,
+ send.cursize, send.data);
}
netchan->outgoing_sequence++;
@@ -623,70 +626,71 @@ static size_t NetchanNew_Transmit( netchan_t *netchan, size_t length, const void
NetchanNew_Process
=================
*/
-static qboolean NetchanNew_Process( netchan_t *netchan ) {
- netchan_new_t *chan = ( netchan_new_t * )netchan;
+static qboolean NetchanNew_Process(netchan_t *netchan)
+{
+ netchan_new_t *chan = (netchan_new_t *)netchan;
uint32_t sequence, sequence_ack, reliable_ack;
qboolean reliable_message, fragmented_message, more_fragments;
uint16_t fragment_offset;
size_t length;
-// get sequence numbers
+// get sequence numbers
MSG_BeginReading();
sequence = MSG_ReadLong();
sequence_ack = MSG_ReadLong();
// read the qport if we are a server
#if USE_CLIENT
- if( netchan->sock == NS_SERVER )
+ if (netchan->sock == NS_SERVER)
#endif
- if( netchan->qport ) {
+ if (netchan->qport) {
MSG_ReadByte();
}
reliable_message = sequence >> 31;
reliable_ack = sequence_ack >> 31;
- fragmented_message = ( sequence >> 30 ) & 1;
+ fragmented_message = (sequence >> 30) & 1;
sequence &= 0x3FFFFFFF;
sequence_ack &= 0x3FFFFFFF;
fragment_offset = 0;
more_fragments = qfalse;
- if( fragmented_message ) {
+ if (fragmented_message) {
fragment_offset = MSG_ReadShort();
more_fragments = fragment_offset >> 15;
fragment_offset &= 0x7FFF;
}
- SHOWPACKET( "recv %4"PRIz" : s=%d ack=%d rack=%d",
- msg_read.cursize, sequence, sequence_ack, reliable_ack );
- if( fragmented_message ) {
- SHOWPACKET( " fragment_offset=%d more_fragments=%d",
- fragment_offset, more_fragments );
+ SHOWPACKET("recv %4"PRIz" : s=%d ack=%d rack=%d",
+ msg_read.cursize, sequence, sequence_ack, reliable_ack);
+ if (fragmented_message) {
+ SHOWPACKET(" fragment_offset=%d more_fragments=%d",
+ fragment_offset, more_fragments);
}
- if( reliable_message ) {
- SHOWPACKET( " reliable=%d", chan->incoming_reliable_sequence ^ 1 );
+ if (reliable_message) {
+ SHOWPACKET(" reliable=%d", chan->incoming_reliable_sequence ^ 1);
}
- SHOWPACKET( "\n" );
+ SHOWPACKET("\n");
//
// discard stale or duplicated packets
//
- if( sequence <= netchan->incoming_sequence ) {
- SHOWDROP( "%s: out of order packet %i at %i\n",
- NET_AdrToString( &netchan->remote_address ),
- sequence, netchan->incoming_sequence );
+ if (sequence <= netchan->incoming_sequence) {
+ SHOWDROP("%s: out of order packet %i at %i\n",
+ NET_AdrToString(&netchan->remote_address),
+ sequence, netchan->incoming_sequence);
return qfalse;
}
//
// dropped packets don't keep the message from being used
//
- netchan->dropped = sequence - ( netchan->incoming_sequence + 1 );
- if( netchan->dropped > 0 ) {
- SHOWDROP( "%s: dropped %i packets at %i\n",
- NET_AdrToString( &netchan->remote_address ),
- netchan->dropped, sequence );
+ netchan->dropped = sequence - (netchan->incoming_sequence + 1);
+ if (netchan->dropped > 0) {
+ SHOWDROP("%s: dropped %i packets at %i\n",
+ NET_AdrToString(&netchan->remote_address),
+ netchan->dropped, sequence);
}
//
@@ -694,7 +698,7 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
// clear the buffer to make way for the next
//
chan->incoming_reliable_acknowledged = reliable_ack;
- if( reliable_ack == chan->reliable_sequence ) {
+ if (reliable_ack == chan->reliable_sequence) {
netchan->reliable_length = 0; // it has been received
}
@@ -702,52 +706,52 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
//
// parse fragment header, if any
//
- if( fragmented_message ) {
- if( chan->fragment_sequence != sequence ) {
+ if (fragmented_message) {
+ if (chan->fragment_sequence != sequence) {
// start new receive sequence
chan->fragment_sequence = sequence;
- SZ_Clear( &chan->fragment_in );
+ SZ_Clear(&chan->fragment_in);
}
- if( fragment_offset < chan->fragment_in.cursize ) {
- SHOWDROP( "%s: out of order fragment at %i\n",
- NET_AdrToString( &netchan->remote_address ), sequence );
+ if (fragment_offset < chan->fragment_in.cursize) {
+ SHOWDROP("%s: out of order fragment at %i\n",
+ NET_AdrToString(&netchan->remote_address), sequence);
return qfalse;
}
- if( fragment_offset > chan->fragment_in.cursize ) {
- SHOWDROP( "%s: dropped fragment(s) at %i\n",
- NET_AdrToString( &netchan->remote_address ), sequence );
+ if (fragment_offset > chan->fragment_in.cursize) {
+ SHOWDROP("%s: dropped fragment(s) at %i\n",
+ NET_AdrToString(&netchan->remote_address), sequence);
return qfalse;
}
length = msg_read.cursize - msg_read.readcount;
- if( chan->fragment_in.cursize + length > chan->fragment_in.maxsize ) {
- SHOWDROP( "%s: oversize fragment at %i\n",
- NET_AdrToString( &netchan->remote_address ), sequence );
+ if (chan->fragment_in.cursize + length > chan->fragment_in.maxsize) {
+ SHOWDROP("%s: oversize fragment at %i\n",
+ NET_AdrToString(&netchan->remote_address), sequence);
return qfalse;
}
- SZ_Write( &chan->fragment_in, msg_read.data +
- msg_read.readcount, length );
- if( more_fragments ) {
+ SZ_Write(&chan->fragment_in, msg_read.data +
+ msg_read.readcount, length);
+ if (more_fragments) {
return qfalse;
}
// message has been sucessfully assembled
- SZ_Clear( &msg_read );
- SZ_Write( &msg_read, chan->fragment_in.data,
- chan->fragment_in.cursize );
- SZ_Clear( &chan->fragment_in );
+ SZ_Clear(&msg_read);
+ SZ_Write(&msg_read, chan->fragment_in.data,
+ chan->fragment_in.cursize);
+ SZ_Clear(&chan->fragment_in);
}
netchan->incoming_sequence = sequence;
netchan->incoming_acknowledged = sequence_ack;
-
+
//
-// if this message contains a reliable message, bump incoming_reliable_sequence
+// if this message contains a reliable message, bump incoming_reliable_sequence
//
- if( reliable_message ) {
+ if (reliable_message) {
netchan->reliable_ack_pending = qtrue;
chan->incoming_reliable_sequence ^= 1;
}
@@ -759,7 +763,7 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
netchan->total_dropped += netchan->dropped;
netchan->total_received += netchan->dropped + 1;
-
+
return qtrue;
}
@@ -768,14 +772,14 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
NetchanNew_ShouldUpdate
==============
*/
-static qboolean NetchanNew_ShouldUpdate( netchan_t *netchan ) {
- netchan_new_t *chan = ( netchan_new_t * )netchan;
+static qboolean NetchanNew_ShouldUpdate(netchan_t *netchan)
+{
+ netchan_new_t *chan = (netchan_new_t *)netchan;
- if( netchan->message.cursize ||
+ if (netchan->message.cursize ||
netchan->reliable_ack_pending ||
chan->fragment_out.cursize ||
- com_localTime - netchan->last_sent > 1000 )
- {
+ com_localTime - netchan->last_sent > 1000) {
return qtrue;
}
@@ -787,14 +791,14 @@ static qboolean NetchanNew_ShouldUpdate( netchan_t *netchan ) {
NetchanNew_Setup
==============
*/
-static netchan_t *NetchanNew_Setup( netsrc_t sock, const netadr_t *adr,
- int qport, size_t maxpacketlen )
+static netchan_t *NetchanNew_Setup(netsrc_t sock, const netadr_t *adr,
+ int qport, size_t maxpacketlen)
{
netchan_new_t *chan;
netchan_t *netchan;
- chan = Z_Mallocz( sizeof( *chan ) );
- netchan = ( netchan_t * )chan;
+ chan = Z_Mallocz(sizeof(*chan));
+ netchan = (netchan_t *)chan;
netchan->sock = sock;
netchan->remote_address = *adr;
netchan->qport = qport;
@@ -809,12 +813,12 @@ static netchan_t *NetchanNew_Setup( netsrc_t sock, const netadr_t *adr,
netchan->TransmitNextFragment = NetchanNew_TransmitNextFragment;
netchan->ShouldUpdate = NetchanNew_ShouldUpdate;
- SZ_Init( &netchan->message, chan->message_buf,
- sizeof( chan->message_buf ) );
- SZ_TagInit( &chan->fragment_in, chan->fragment_in_buf,
- sizeof( chan->fragment_in_buf ), SZ_NC_FRG_IN );
- SZ_TagInit( &chan->fragment_out, chan->fragment_out_buf,
- sizeof( chan->fragment_out_buf ), SZ_NC_FRG_OUT );
+ SZ_Init(&netchan->message, chan->message_buf,
+ sizeof(chan->message_buf));
+ SZ_TagInit(&chan->fragment_in, chan->fragment_in_buf,
+ sizeof(chan->fragment_in_buf), SZ_NC_FRG_IN);
+ SZ_TagInit(&chan->fragment_out, chan->fragment_out_buf,
+ sizeof(chan->fragment_out_buf), SZ_NC_FRG_OUT);
return netchan;
}
@@ -824,22 +828,22 @@ static netchan_t *NetchanNew_Setup( netsrc_t sock, const netadr_t *adr,
Netchan_Setup
==============
*/
-netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
- const netadr_t *adr, int qport, size_t maxpacketlen, int protocol )
+netchan_t *Netchan_Setup(netsrc_t sock, netchan_type_t type,
+ const netadr_t *adr, int qport, size_t maxpacketlen, int protocol)
{
netchan_t *netchan;
- clamp( maxpacketlen, 256, MAX_PACKETLEN_WRITABLE );
+ clamp(maxpacketlen, 256, MAX_PACKETLEN_WRITABLE);
- switch( type ) {
+ switch (type) {
case NETCHAN_OLD:
- netchan = NetchanOld_Setup( sock, adr, qport, maxpacketlen );
+ netchan = NetchanOld_Setup(sock, adr, qport, maxpacketlen);
break;
case NETCHAN_NEW:
- netchan = NetchanNew_Setup( sock, adr, qport, maxpacketlen );
+ netchan = NetchanNew_Setup(sock, adr, qport, maxpacketlen);
break;
default:
- Com_Error( ERR_FATAL, "Netchan_Setup: bad type" );
+ Com_Error(ERR_FATAL, "Netchan_Setup: bad type");
netchan = NULL;
}
@@ -855,7 +859,8 @@ netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
Netchan_Close
==============
*/
-void Netchan_Close( netchan_t *netchan ) {
- Z_Free( netchan );
+void Netchan_Close(netchan_t *netchan)
+{
+ Z_Free(netchan);
}
diff --git a/src/net_chan.h b/src/net_chan.h
index 29318f3..ec56838 100644
--- a/src/net_chan.h
+++ b/src/net_chan.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -43,10 +43,10 @@ typedef struct netchan_s {
netadr_t remote_address;
int qport; // qport value to write when transmitting
- sizebuf_t message; // writing buffer for reliable data
+ sizebuf_t message; // writing buffer for reliable data
size_t reliable_length;
-
+
qboolean reliable_ack_pending; // set to qtrue each time reliable is received
qboolean fragment_pending;
@@ -55,25 +55,25 @@ typedef struct netchan_s {
int incoming_acknowledged;
int outgoing_sequence;
- size_t (*Transmit)( struct netchan_s *, size_t, const void *, int );
- size_t (*TransmitNextFragment)( struct netchan_s * );
- qboolean (*Process)( struct netchan_s * );
- qboolean (*ShouldUpdate)( struct netchan_s * );
+ size_t (*Transmit)(struct netchan_s *, size_t, const void *, int);
+ size_t (*TransmitNextFragment)(struct netchan_s *);
+ qboolean (*Process)(struct netchan_s *);
+ qboolean (*ShouldUpdate)(struct netchan_s *);
} netchan_t;
extern cvar_t *net_qport;
extern cvar_t *net_maxmsglen;
extern cvar_t *net_chantype;
-void Netchan_Init( void );
-void Netchan_OutOfBand( netsrc_t sock, const netadr_t *adr,
- const char *format, ... ) q_printf( 3, 4 );
-netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
- const netadr_t *adr, int qport, size_t maxpacketlen, int protocol );
-void Netchan_Close( netchan_t *netchan );
+void Netchan_Init(void);
+void Netchan_OutOfBand(netsrc_t sock, const netadr_t *adr,
+ const char *format, ...) q_printf(3, 4);
+netchan_t *Netchan_Setup(netsrc_t sock, netchan_type_t type,
+ const netadr_t *adr, int qport, size_t maxpacketlen, int protocol);
+void Netchan_Close(netchan_t *netchan);
-#define OOB_PRINT( sock, addr, string ) \
- NET_SendPacket( sock, addr, sizeof( "\xff\xff\xff\xff" string ) - 1, "\xff\xff\xff\xff" string )
+#define OOB_PRINT(sock, addr, string) \
+ NET_SendPacket(sock, addr, sizeof("\xff\xff\xff\xff" string) - 1, "\xff\xff\xff\xff" string)
//============================================================================
diff --git a/src/net_common.c b/src/net_common.c
index 5e1fb25..84bce5a 100644
--- a/src/net_common.c
+++ b/src/net_common.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -44,10 +44,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define IOCTLSOCKET_PARAM u_long
#define SETSOCKOPT_PARAM BOOL
#ifdef _WIN32_WCE
-#define NET_GET_ERROR() ( net_error = GetLastError() )
+#define NET_GET_ERROR() (net_error = GetLastError())
#else
-#define NET_GET_ERROR() ( net_error = WSAGetLastError() )
-#define NET_WOULD_BLOCK() ( NET_GET_ERROR() == WSAEWOULDBLOCK )
+#define NET_GET_ERROR() (net_error = WSAGetLastError())
+#define NET_WOULD_BLOCK() (NET_GET_ERROR() == WSAEWOULDBLOCK)
#endif
#else // _WIN32
#include <unistd.h>
@@ -71,8 +71,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define ioctlsocket ioctl
#define IOCTLSOCKET_PARAM int
#define SETSOCKOPT_PARAM int
-#define NET_GET_ERROR() ( net_error = errno )
-#define NET_WOULD_BLOCK() ( NET_GET_ERROR() == EWOULDBLOCK )
+#define NET_GET_ERROR() (net_error = errno)
+#define NET_WOULD_BLOCK() (NET_GET_ERROR() == EWOULDBLOCK)
#endif // !_WIN32
#if USE_CLIENT
@@ -153,10 +153,11 @@ static uint64_t net_packets_sent;
NET_NetadrToSockadr
===================
*/
-static void NET_NetadrToSockadr( const netadr_t *a, struct sockaddr_in *s ) {
- memset( s, 0, sizeof( *s ) );
+static void NET_NetadrToSockadr(const netadr_t *a, struct sockaddr_in *s)
+{
+ memset(s, 0, sizeof(*s));
- switch( a->type ) {
+ switch (a->type) {
case NA_BROADCAST:
s->sin_family = AF_INET;
s->sin_addr.s_addr = INADDR_BROADCAST;
@@ -168,7 +169,7 @@ static void NET_NetadrToSockadr( const netadr_t *a, struct sockaddr_in *s ) {
s->sin_port = a->port;
break;
default:
- Com_Error( ERR_FATAL, "%s: bad address type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad address type", __func__);
break;
}
}
@@ -178,8 +179,9 @@ static void NET_NetadrToSockadr( const netadr_t *a, struct sockaddr_in *s ) {
NET_SockadrToNetadr
===================
*/
-static void NET_SockadrToNetadr( const struct sockaddr_in *s, netadr_t *a ) {
- memset( a, 0, sizeof( *a ) );
+static void NET_SockadrToNetadr(const struct sockaddr_in *s, netadr_t *a)
+{
+ memset(a, 0, sizeof(*a));
a->type = NA_IP;
a->ip.u32 = s->sin_addr.s_addr;
@@ -197,41 +199,42 @@ idnewt:28000
192.246.40.70:28000
=============
*/
-static qboolean NET_StringToSockaddr( const char *s, struct sockaddr_in *sadr ) {
+static qboolean NET_StringToSockaddr(const char *s, struct sockaddr_in *sadr)
+{
struct hostent *h;
char copy[MAX_QPATH], *p;
int dots;
- memset( sadr, 0, sizeof( *sadr ) );
+ memset(sadr, 0, sizeof(*sadr));
sadr->sin_family = AF_INET;
sadr->sin_port = 0;
- Q_strlcpy( copy, s, sizeof( copy ) );
+ Q_strlcpy(copy, s, sizeof(copy));
// strip off a trailing :port if present
- p = strchr( copy, ':' );
- if( p ) {
+ p = strchr(copy, ':');
+ if (p) {
*p = 0;
- sadr->sin_port = htons( ( u_short )atoi( p + 1 ) );
+ sadr->sin_port = htons((u_short)atoi(p + 1));
}
- for( p = copy, dots = 0; *p; p++ ) {
- if( *p == '.' ) {
+ for (p = copy, dots = 0; *p; p++) {
+ if (*p == '.') {
dots++;
- } else if( !Q_isdigit( *p ) ) {
+ } else if (!Q_isdigit(*p)) {
break;
}
}
- if( *p == 0 && dots <= 3 ) {
- uint32_t addr = inet_addr( copy );
+ if (*p == 0 && dots <= 3) {
+ uint32_t addr = inet_addr(copy);
- if( addr == INADDR_NONE ) {
+ if (addr == INADDR_NONE) {
return qfalse;
}
sadr->sin_addr.s_addr = addr;
} else {
- if( !( h = gethostbyname( copy ) ) )
+ if (!(h = gethostbyname(copy)))
return qfalse;
- sadr->sin_addr.s_addr = *( uint32_t * )h->h_addr_list[0];
+ sadr->sin_addr.s_addr = *(uint32_t *)h->h_addr_list[0];
}
return qtrue;
@@ -243,22 +246,23 @@ static qboolean NET_StringToSockaddr( const char *s, struct sockaddr_in *sadr )
NET_AdrToString
===================
*/
-char *NET_AdrToString( const netadr_t *a ) {
+char *NET_AdrToString(const netadr_t *a)
+{
static char s[MAX_QPATH];
const uint8_t *ip;
- switch( a->type ) {
+ switch (a->type) {
case NA_LOOPBACK:
- strcpy( s, "loopback" );
+ strcpy(s, "loopback");
return s;
case NA_IP:
case NA_BROADCAST:
ip = a->ip.u8;
- Q_snprintf( s, sizeof( s ), "%u.%u.%u.%u:%u",
- ip[0], ip[1], ip[2], ip[3], ntohs( a->port ) );
+ Q_snprintf(s, sizeof(s), "%u.%u.%u.%u:%u",
+ ip[0], ip[1], ip[2], ip[3], ntohs(a->port));
return s;
default:
- Com_Error( ERR_FATAL, "%s: bad address type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad address type", __func__);
break;
}
@@ -276,17 +280,18 @@ idnewt:28000
192.246.40.70:28000
=============
*/
-qboolean NET_StringToAdr( const char *s, netadr_t *a, int port ) {
+qboolean NET_StringToAdr(const char *s, netadr_t *a, int port)
+{
struct sockaddr_in sadr;
-
- if( !NET_StringToSockaddr( s, &sadr ) ) {
+
+ if (!NET_StringToSockaddr(s, &sadr)) {
return qfalse;
}
-
- NET_SockadrToNetadr( &sadr, a );
- if( !a->port ) {
- a->port = BigShort( port );
+ NET_SockadrToNetadr(&sadr, a);
+
+ if (!a->port) {
+ a->port = BigShort(port);
}
return qtrue;
@@ -296,54 +301,58 @@ qboolean NET_StringToAdr( const char *s, netadr_t *a, int port ) {
#ifdef _DEBUG
-static void logfile_close( void ) {
- if( !net_logFile ) {
+static void logfile_close(void)
+{
+ if (!net_logFile) {
return;
}
- Com_Printf( "Closing network log.\n" );
+ Com_Printf("Closing network log.\n");
- FS_FCloseFile( net_logFile );
+ FS_FCloseFile(net_logFile);
net_logFile = 0;
}
-static void logfile_open( void ) {
+static void logfile_open(void)
+{
char buffer[MAX_OSPATH];
unsigned mode;
qhandle_t f;
mode = net_log_enable->integer > 1 ? FS_MODE_APPEND : FS_MODE_WRITE;
- if( net_log_flush->integer > 0 ) {
- if( net_log_flush->integer > 1 ) {
+ if (net_log_flush->integer > 0) {
+ if (net_log_flush->integer > 1) {
mode |= FS_BUF_NONE;
} else {
mode |= FS_BUF_LINE;
}
}
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode | FS_FLAG_TEXT,
- "logs/", net_log_name->string, ".log" );
- if( !f ) {
- Cvar_Set( "net_log_enable", "0" );
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode | FS_FLAG_TEXT,
+ "logs/", net_log_name->string, ".log");
+ if (!f) {
+ Cvar_Set("net_log_enable", "0");
return;
}
net_logFile = f;
- Com_Printf( "Logging network packets to %s\n", buffer );
+ Com_Printf("Logging network packets to %s\n", buffer);
}
-static void net_log_enable_changed( cvar_t *self ) {
+static void net_log_enable_changed(cvar_t *self)
+{
logfile_close();
- if( self->integer ) {
+ if (self->integer) {
logfile_open();
- }
+ }
}
-static void net_log_param_changed( cvar_t *self ) {
- if( net_log_enable->integer ) {
+static void net_log_param_changed(cvar_t *self)
+{
+ if (net_log_enable->integer) {
logfile_close();
logfile_open();
- }
+ }
}
/*
@@ -351,55 +360,56 @@ static void net_log_param_changed( cvar_t *self ) {
NET_LogPacket
=============
*/
-static void NET_LogPacket( const netadr_t *address, const char *prefix,
- const byte *data, size_t length )
+static void NET_LogPacket(const netadr_t *address, const char *prefix,
+ const byte *data, size_t length)
{
int numRows;
int i, j, c;
- if( !net_logFile ) {
+ if (!net_logFile) {
return;
}
- FS_FPrintf( net_logFile, "%s : %s\n", prefix, NET_AdrToString( address ) );
+ FS_FPrintf(net_logFile, "%s : %s\n", prefix, NET_AdrToString(address));
- numRows = ( length + 15 ) / 16;
- for( i = 0; i < numRows; i++ ) {
- FS_FPrintf( net_logFile, "%04x : ", i * 16 );
- for( j = 0; j < 16; j++ ) {
- if( i * 16 + j < length ) {
- FS_FPrintf( net_logFile, "%02x ", data[i * 16 + j] );
+ numRows = (length + 15) / 16;
+ for (i = 0; i < numRows; i++) {
+ FS_FPrintf(net_logFile, "%04x : ", i * 16);
+ for (j = 0; j < 16; j++) {
+ if (i * 16 + j < length) {
+ FS_FPrintf(net_logFile, "%02x ", data[i * 16 + j]);
} else {
- FS_FPrintf( net_logFile, " " );
+ FS_FPrintf(net_logFile, " ");
}
}
- FS_FPrintf( net_logFile, ": " );
- for( j = 0; j < 16; j++ ) {
- if( i * 16 + j < length ) {
+ FS_FPrintf(net_logFile, ": ");
+ for (j = 0; j < 16; j++) {
+ if (i * 16 + j < length) {
c = data[i * 16 + j];
- FS_FPrintf( net_logFile, "%c", ( c < 32 || c > 127 ) ? '.' : c );
+ FS_FPrintf(net_logFile, "%c", (c < 32 || c > 127) ? '.' : c);
} else {
- FS_FPrintf( net_logFile, " " );
+ FS_FPrintf(net_logFile, " ");
}
}
- FS_FPrintf( net_logFile, "\n" );
+ FS_FPrintf(net_logFile, "\n");
}
- FS_FPrintf( net_logFile, "\n" );
+ FS_FPrintf(net_logFile, "\n");
}
#endif
#define RATE_SECS 3
-static void NET_UpdateStats( void ) {
+static void NET_UpdateStats(void)
+{
unsigned diff;
- if( net_rate_time > com_eventTime ) {
+ if (net_rate_time > com_eventTime) {
net_rate_time = com_eventTime;
}
diff = com_eventTime - net_rate_time;
- if( diff < RATE_SECS * 1000 ) {
+ if (diff < RATE_SECS * 1000) {
return;
}
net_rate_time = com_eventTime;
@@ -418,7 +428,8 @@ static void NET_UpdateStats( void ) {
NET_GetLoopPacket
=============
*/
-qboolean NET_GetLoopPacket( netsrc_t sock ) {
+qboolean NET_GetLoopPacket(netsrc_t sock)
+{
loopback_t *loop;
loopmsg_t *loopmsg;
@@ -426,29 +437,29 @@ qboolean NET_GetLoopPacket( netsrc_t sock ) {
loop = &loopbacks[sock];
- if( loop->send - loop->get > MAX_LOOPBACK - 1 ) {
+ if (loop->send - loop->get > MAX_LOOPBACK - 1) {
loop->get = loop->send - MAX_LOOPBACK + 1;
}
- if( loop->get >= loop->send ) {
+ if (loop->get >= loop->send) {
return qfalse;
}
- loopmsg = &loop->msgs[loop->get & (MAX_LOOPBACK-1)];
+ loopmsg = &loop->msgs[loop->get & (MAX_LOOPBACK - 1)];
loop->get++;
- memcpy( msg_read_buffer, loopmsg->data, loopmsg->datalen );
+ memcpy(msg_read_buffer, loopmsg->data, loopmsg->datalen);
#ifdef _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( &net_from, "LP recv", loopmsg->data, loopmsg->datalen );
+ if (net_log_enable->integer) {
+ NET_LogPacket(&net_from, "LP recv", loopmsg->data, loopmsg->datalen);
}
#endif
- if( sock == NS_CLIENT ) {
+ if (sock == NS_CLIENT) {
net_rate_rcvd += loopmsg->datalen;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = loopmsg->datalen;
return qtrue;
@@ -461,18 +472,19 @@ qboolean NET_GetLoopPacket( netsrc_t sock ) {
// prevents infinite retry loops caused by broken TCP/IP stacks
#define MAX_ERROR_RETRIES 64
-static void icmp_error_event( netsrc_t sock, int info ) {
- if( net_ignore_icmp->integer > 0 ) {
+static void icmp_error_event(netsrc_t sock, int info)
+{
+ if (net_ignore_icmp->integer > 0) {
return;
}
- Com_DPrintf( "%s: %s from %s\n", __func__,
- NET_ErrorString(), NET_AdrToString( &net_from ) );
+ Com_DPrintf("%s: %s from %s\n", __func__,
+ NET_ErrorString(), NET_AdrToString(&net_from));
net_icmp_errors++;
- switch( sock ) {
+ switch (sock) {
case NS_SERVER:
- SV_ErrorEvent( info );
+ SV_ErrorEvent(info);
break;
#if USE_CLIENT
case NS_CLIENT:
@@ -490,7 +502,8 @@ static void icmp_error_event( netsrc_t sock, int info ) {
// via IP_RECVERR cruft below... What about BSD?
//
// Returns true if failed socket operation should be retried, extremely hacky :/
-static qboolean process_error_queue( netsrc_t sock, struct sockaddr_in *to ) {
+static qboolean process_error_queue(netsrc_t sock, struct sockaddr_in *to)
+{
byte buffer[1024];
struct sockaddr_in from;
struct msghdr msg;
@@ -504,59 +517,57 @@ static qboolean process_error_queue( netsrc_t sock, struct sockaddr_in *to ) {
found = qfalse;
retry:
- memset( &from, 0, sizeof( from ) );
+ memset(&from, 0, sizeof(from));
- memset( &msg, 0, sizeof( msg ) );
+ memset(&msg, 0, sizeof(msg));
msg.msg_name = &from;
- msg.msg_namelen = sizeof( from );
+ msg.msg_namelen = sizeof(from);
msg.msg_control = buffer;
- msg.msg_controllen = sizeof( buffer );
+ msg.msg_controllen = sizeof(buffer);
- if( recvmsg( udp_sockets[sock], &msg, MSG_ERRQUEUE ) == -1 ) {
- if( NET_WOULD_BLOCK() ) {
+ if (recvmsg(udp_sockets[sock], &msg, MSG_ERRQUEUE) == -1) {
+ if (NET_WOULD_BLOCK()) {
// wouldblock is silent
goto finish;
}
- Com_EPrintf( "%s: %s\n", __func__, NET_ErrorString() );
+ Com_EPrintf("%s: %s\n", __func__, NET_ErrorString());
goto finish;
}
- if( !( msg.msg_flags & MSG_ERRQUEUE ) ) {
- Com_DPrintf( "%s: no extended error received\n", __func__ );
+ if (!(msg.msg_flags & MSG_ERRQUEUE)) {
+ Com_DPrintf("%s: no extended error received\n", __func__);
goto finish;
}
// find an ICMP error message
- for( cmsg = CMSG_FIRSTHDR( &msg );
- cmsg != NULL;
- cmsg = CMSG_NXTHDR( &msg, cmsg ) )
- {
- if( cmsg->cmsg_level != IPPROTO_IP ) {
+ for (cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level != IPPROTO_IP) {
continue;
}
- if( cmsg->cmsg_type != IP_RECVERR ) {
+ if (cmsg->cmsg_type != IP_RECVERR) {
continue;
}
- ee = ( struct sock_extended_err * )CMSG_DATA( cmsg );
- if( ee->ee_origin == SO_EE_ORIGIN_ICMP ) {
+ ee = (struct sock_extended_err *)CMSG_DATA(cmsg);
+ if (ee->ee_origin == SO_EE_ORIGIN_ICMP) {
break;
}
}
- if( !cmsg ) {
- Com_DPrintf( "%s: no ICMP error found\n", __func__ );
+ if (!cmsg) {
+ Com_DPrintf("%s: no ICMP error found\n", __func__);
goto finish;
}
- NET_SockadrToNetadr( &from, &net_from );
+ NET_SockadrToNetadr(&from, &net_from);
// check if this error was caused by a packet sent to the given address
// if so, do not retry send operation to prevent infinite loop
- if( to != NULL && from.sin_addr.s_addr == to->sin_addr.s_addr &&
- ( !from.sin_port || from.sin_port == to->sin_port ) )
- {
- Com_DPrintf( "%s: found offending address %s:%d\n",
- __func__, inet_ntoa( from.sin_addr ), BigShort( from.sin_port ) );
+ if (to != NULL && from.sin_addr.s_addr == to->sin_addr.s_addr &&
+ (!from.sin_port || from.sin_port == to->sin_port)) {
+ Com_DPrintf("%s: found offending address %s:%d\n",
+ __func__, inet_ntoa(from.sin_addr), BigShort(from.sin_port));
found = qtrue;
}
@@ -565,13 +576,13 @@ retry:
info = 0;
#if USE_PMTUDISC
// for EMSGSIZE ee_info should hold discovered MTU
- if( net_error == EMSGSIZE && ee->ee_info >= 576 && ee->ee_info < 4096 ) {
+ if (net_error == EMSGSIZE && ee->ee_info >= 576 && ee->ee_info < 4096) {
info = ee->ee_info;
}
#endif
- icmp_error_event( sock, info );
+ icmp_error_event(sock, info);
- if( ++tries < MAX_ERROR_RETRIES ) {
+ if (++tries < MAX_ERROR_RETRIES) {
goto retry;
}
@@ -591,7 +602,8 @@ Fills msg_read_buffer with packet contents,
net_from variable receives source address.
=============
*/
-qboolean NET_GetPacket( netsrc_t sock ) {
+qboolean NET_GetPacket(netsrc_t sock)
+{
struct sockaddr_in from;
socklen_t fromlen;
int ret;
@@ -603,14 +615,14 @@ qboolean NET_GetPacket( netsrc_t sock ) {
#endif
ioentry_t *e;
- if( udp_sockets[sock] == INVALID_SOCKET ) {
+ if (udp_sockets[sock] == INVALID_SOCKET) {
return qfalse;
}
NET_UpdateStats();
- e = IO_Get( udp_sockets[sock] );
- if( !e->canread ) {
+ e = IO_Get(udp_sockets[sock]);
+ if (!e->canread) {
return qfalse;
}
@@ -619,23 +631,23 @@ qboolean NET_GetPacket( netsrc_t sock ) {
retry:
#endif
- memset( &from, 0, sizeof( from ) );
+ memset(&from, 0, sizeof(from));
- fromlen = sizeof( from );
- ret = recvfrom( udp_sockets[sock], ( void * )msg_read_buffer,
- MAX_PACKETLEN, 0, ( struct sockaddr * )&from, &fromlen );
+ fromlen = sizeof(from);
+ ret = recvfrom(udp_sockets[sock], (void *)msg_read_buffer,
+ MAX_PACKETLEN, 0, (struct sockaddr *)&from, &fromlen);
- if( !ret ) {
+ if (!ret) {
return qfalse;
}
- NET_SockadrToNetadr( &from, &net_from );
+ NET_SockadrToNetadr(&from, &net_from);
- if( ret == -1 ) {
+ if (ret == -1) {
NET_GET_ERROR();
#ifdef _WIN32
- switch( net_error ) {
+ switch (net_error) {
case WSAEWOULDBLOCK:
// wouldblock is silent
e->canread = qfalse;
@@ -645,20 +657,20 @@ retry:
case WSAENETRESET:
// winsock has already provided us with
// a valid address from ICMP error packet
- icmp_error_event( sock, 0 );
- if( ++tries < MAX_ERROR_RETRIES ) {
+ icmp_error_event(sock, 0);
+ if (++tries < MAX_ERROR_RETRIES) {
goto retry;
}
// intentional fallthrough
#endif // USE_ICMP
default:
- Com_DPrintf( "%s: %s from %s\n", __func__,
- NET_ErrorString(), NET_AdrToString( &net_from ) );
+ Com_DPrintf("%s: %s from %s\n", __func__,
+ NET_ErrorString(), NET_AdrToString(&net_from));
net_recv_errors++;
break;
}
#else // _WIN32
- switch( net_error ) {
+ switch (net_error) {
case EWOULDBLOCK:
// wouldblock is silent
e->canread = qfalse;
@@ -668,15 +680,15 @@ retry:
saved_error = net_error;
// recvfrom() fails on Linux if there's an ICMP originated
// pending error on socket. suck up error queue and retry...
- if( process_error_queue( sock, NULL ) ) {
- if( ++tries < MAX_ERROR_RETRIES ) {
+ if (process_error_queue(sock, NULL)) {
+ if (++tries < MAX_ERROR_RETRIES) {
goto retry;
}
}
net_error = saved_error;
#endif
- Com_DPrintf( "%s: %s from %s\n", __func__,
- NET_ErrorString(), NET_AdrToString( &net_from ) );
+ Com_DPrintf("%s: %s from %s\n", __func__,
+ NET_ErrorString(), NET_AdrToString(&net_from));
net_recv_errors++;
break;
}
@@ -684,19 +696,19 @@ retry:
return qfalse;
}
- if( ret > MAX_PACKETLEN ) {
- Com_EPrintf( "%s: oversize packet from %s\n", __func__,
- NET_AdrToString( &net_from ) );
+ if (ret > MAX_PACKETLEN) {
+ Com_EPrintf("%s: oversize packet from %s\n", __func__,
+ NET_AdrToString(&net_from));
return qfalse;
}
#ifdef _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( &net_from, "UDP recv", msg_read_buffer, ret );
+ if (net_log_enable->integer) {
+ NET_LogPacket(&net_from, "UDP recv", msg_read_buffer, ret);
}
#endif
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = ret;
net_rate_rcvd += ret;
net_bytes_rcvd += ret;
@@ -713,99 +725,99 @@ NET_SendPacket
=============
*/
-qboolean NET_SendPacket( netsrc_t sock, const netadr_t *to, size_t length, const void *data ) {
+qboolean NET_SendPacket(netsrc_t sock, const netadr_t *to, size_t length, const void *data)
+{
struct sockaddr_in addr;
int ret;
-#if USE_ICMP && ( defined __linux__ )
+#if USE_ICMP && (defined __linux__)
int tries;
int saved_error;
#endif
- if( !length ) {
+ if (!length) {
return qfalse;
}
- if( length > MAX_PACKETLEN ) {
- Com_EPrintf( "%s: oversize packet to %s\n", __func__,
- NET_AdrToString( to ) );
+ if (length > MAX_PACKETLEN) {
+ Com_EPrintf("%s: oversize packet to %s\n", __func__,
+ NET_AdrToString(to));
return qfalse;
}
- switch( to->type ) {
+ switch (to->type) {
#if USE_CLIENT
case NA_LOOPBACK: {
- loopback_t *loop;
- loopmsg_t *msg;
+ loopback_t *loop;
+ loopmsg_t *msg;
- if( net_dropsim->integer > 0 &&
- ( rand() % 100 ) < net_dropsim->integer )
- {
- return NET_AGAIN;
- }
-
- loop = &loopbacks[sock ^ 1];
+ if (net_dropsim->integer > 0 &&
+ (rand() % 100) < net_dropsim->integer) {
+ return NET_AGAIN;
+ }
+
+ loop = &loopbacks[sock ^ 1];
+
+ msg = &loop->msgs[loop->send & (MAX_LOOPBACK - 1)];
+ loop->send++;
- msg = &loop->msgs[loop->send & ( MAX_LOOPBACK - 1 )];
- loop->send++;
-
- memcpy( msg->data, data, length );
- msg->datalen = length;
+ memcpy(msg->data, data, length);
+ msg->datalen = length;
#ifdef _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( to, "LB send", data, length );
- }
+ if (net_log_enable->integer) {
+ NET_LogPacket(to, "LB send", data, length);
+ }
#endif
- if( sock == NS_CLIENT ) {
- net_rate_sent += length;
- }
+ if (sock == NS_CLIENT) {
+ net_rate_sent += length;
}
- return qtrue;
+ }
+ return qtrue;
#endif
case NA_IP:
case NA_BROADCAST:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad address type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad address type", __func__);
break;
}
- if( udp_sockets[sock] == INVALID_SOCKET ) {
+ if (udp_sockets[sock] == INVALID_SOCKET) {
return qfalse;
}
- NET_NetadrToSockadr( to, &addr );
+ NET_NetadrToSockadr(to, &addr);
-#if USE_ICMP && ( defined __linux__ )
+#if USE_ICMP && (defined __linux__)
tries = 0;
retry:
#endif
- ret = sendto( udp_sockets[sock], data, length, 0,
- ( struct sockaddr * )&addr, sizeof( addr ) );
- if( ret == -1 ) {
+ ret = sendto(udp_sockets[sock], data, length, 0,
+ (struct sockaddr *)&addr, sizeof(addr));
+ if (ret == -1) {
NET_GET_ERROR();
#ifdef _WIN32
- switch( net_error ) {
+ switch (net_error) {
case WSAEWOULDBLOCK:
case WSAEINTR:
// wouldblock is silent
break;
case WSAEADDRNOTAVAIL:
// some PPP links do not allow broadcasts
- if( to->type == NA_BROADCAST ) {
+ if (to->type == NA_BROADCAST) {
break;
}
// intentional fallthrough
default:
- Com_DPrintf( "%s: %s to %s\n", __func__,
- NET_ErrorString(), NET_AdrToString( to ) );
+ Com_DPrintf("%s: %s to %s\n", __func__,
+ NET_ErrorString(), NET_AdrToString(to));
net_send_errors++;
break;
}
#else // _WIN32
- switch( net_error ) {
+ switch (net_error) {
case EWOULDBLOCK:
// wouldblock is silent
break;
@@ -818,7 +830,7 @@ retry:
// this one is especially lame - how do I distingiush between
// a failure caused by completely unrelated ICMP error sitting
// in the queue and an error explicit to this sendto() call?
- //
+ //
// on one hand, I don't want to drop packets to legitimate
// clients because of this, and have to retry sendto() after
// processing error queue, on another hand, infinite loop should be
@@ -828,15 +840,15 @@ retry:
// to process_error_queue() and checking if this address/port
// pair is found in the queue. if it is found, or the queue
// is empty, do not retry
- if( process_error_queue( sock, &addr ) ) {
- if( ++tries < MAX_ERROR_RETRIES ) {
+ if (process_error_queue(sock, &addr)) {
+ if (++tries < MAX_ERROR_RETRIES) {
goto retry;
}
}
net_error = saved_error;
#endif
- Com_DPrintf( "%s: %s to %s\n", __func__,
- NET_ErrorString(), NET_AdrToString( to ) );
+ Com_DPrintf("%s: %s to %s\n", __func__,
+ NET_ErrorString(), NET_AdrToString(to));
net_send_errors++;
break;
}
@@ -844,14 +856,14 @@ retry:
return qfalse;
}
- if( ret != length ) {
- Com_WPrintf( "%s: short send to %s\n", __func__,
- NET_AdrToString( to ) );
+ if (ret != length) {
+ Com_WPrintf("%s: short send to %s\n", __func__,
+ NET_AdrToString(to));
}
#ifdef _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( to, "UDP send", data, ret );
+ if (net_log_enable->integer) {
+ NET_LogPacket(to, "UDP send", data, ret);
}
#endif
net_rate_sent += ret;
@@ -864,9 +876,10 @@ retry:
//=============================================================================
-const char *NET_ErrorString( void ) {
+const char *NET_ErrorString(void)
+{
#ifdef _WIN32
- switch( net_error ) {
+ switch (net_error) {
case S_OK:
return "NO ERROR";
default:
@@ -874,38 +887,41 @@ const char *NET_ErrorString( void ) {
#include "wsaerr.h"
}
#else
- return strerror( net_error );
+ return strerror(net_error);
#endif
}
-static qboolean get_bind_addr( const char *iface, int port, struct sockaddr_in *sadr ) {
- if( *iface ) {
- if( !NET_StringToSockaddr( iface, sadr ) ) {
+static qboolean get_bind_addr(const char *iface, int port, struct sockaddr_in *sadr)
+{
+ if (*iface) {
+ if (!NET_StringToSockaddr(iface, sadr)) {
return qfalse;
}
} else {
- // empty string binds to all interfaces
- memset( sadr, 0, sizeof( *sadr ) );
+ // empty string binds to all interfaces
+ memset(sadr, 0, sizeof(*sadr));
sadr->sin_family = AF_INET;
sadr->sin_addr.s_addr = INADDR_ANY;
}
- if( port != PORT_ANY ) {
- sadr->sin_port = htons( ( u_short )port );
+ if (port != PORT_ANY) {
+ sadr->sin_port = htons((u_short)port);
}
return qtrue;
}
-static SOCKET create_socket( int type, int proto ) {
- SOCKET ret = socket( PF_INET, type, proto );
+static SOCKET create_socket(int type, int proto)
+{
+ SOCKET ret = socket(PF_INET, type, proto);
NET_GET_ERROR();
return ret;
}
-static int set_option( SOCKET s, int level, int optname, int value ) {
+static int set_option(SOCKET s, int level, int optname, int value)
+{
SETSOCKOPT_PARAM _value = value;
- int ret = setsockopt( s, level, optname, ( char * )&_value, sizeof( _value ) );
+ int ret = setsockopt(s, level, optname, (char *)&_value, sizeof(_value));
NET_GET_ERROR();
return ret;
@@ -913,48 +929,51 @@ static int set_option( SOCKET s, int level, int optname, int value ) {
#define enable_option(s,level,optname) set_option(s,level,optname,1)
-static int make_nonblock( SOCKET s ) {
+static int make_nonblock(SOCKET s)
+{
IOCTLSOCKET_PARAM _true = 1;
- int ret = ioctlsocket( s, FIONBIO, &_true );
+ int ret = ioctlsocket(s, FIONBIO, &_true);
NET_GET_ERROR();
return ret;
}
-static int bind_socket( SOCKET s, struct sockaddr_in *sadr ) {
- int ret = bind( s, ( struct sockaddr * )sadr, sizeof( *sadr ) );
+static int bind_socket(SOCKET s, struct sockaddr_in *sadr)
+{
+ int ret = bind(s, (struct sockaddr *)sadr, sizeof(*sadr));
NET_GET_ERROR();
return ret;
}
-static SOCKET UDP_OpenSocket( const char *iface, int port ) {
+static SOCKET UDP_OpenSocket(const char *iface, int port)
+{
SOCKET s;
struct sockaddr_in sadr;
#ifdef __linux__
int pmtudisc;
#endif
- Com_DPrintf( "Opening UDP socket: %s:%i\n", iface, port );
+ Com_DPrintf("Opening UDP socket: %s:%i\n", iface, port);
- s = create_socket( SOCK_DGRAM, IPPROTO_UDP );
- if( s == INVALID_SOCKET ) {
- Com_EPrintf( "%s: %s:%d: can't create socket: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ s = create_socket(SOCK_DGRAM, IPPROTO_UDP);
+ if (s == INVALID_SOCKET) {
+ Com_EPrintf("%s: %s:%d: can't create socket: %s\n",
+ __func__, iface, port, NET_ErrorString());
return INVALID_SOCKET;
}
// make it non-blocking
- if( make_nonblock( s ) == -1 ) {
- Com_EPrintf( "%s: %s:%d: can't make socket non-blocking: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (make_nonblock(s) == -1) {
+ Com_EPrintf("%s: %s:%d: can't make socket non-blocking: %s\n",
+ __func__, iface, port, NET_ErrorString());
goto fail;
}
// make it broadcast capable
- if( enable_option( s, SOL_SOCKET, SO_BROADCAST ) == -1 ) {
- Com_WPrintf( "%s: %s:%d: can't make socket broadcast capable: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (enable_option(s, SOL_SOCKET, SO_BROADCAST) == -1) {
+ Com_WPrintf("%s: %s:%d: can't make socket broadcast capable: %s\n",
+ __func__, iface, port, NET_ErrorString());
}
#ifdef __linux__
@@ -962,20 +981,20 @@ static SOCKET UDP_OpenSocket( const char *iface, int port ) {
#if USE_ICMP
// enable ICMP error queue
- if( net_ignore_icmp->integer <= 0 ) {
- if( enable_option( s, IPPROTO_IP, IP_RECVERR ) == -1 ) {
- Com_WPrintf( "%s: %s:%d: can't enable ICMP error queue: %s\n",
- __func__, iface, port, NET_ErrorString() );
- Cvar_Set( "net_ignore_icmp", "1" );
+ if (net_ignore_icmp->integer <= 0) {
+ if (enable_option(s, IPPROTO_IP, IP_RECVERR) == -1) {
+ Com_WPrintf("%s: %s:%d: can't enable ICMP error queue: %s\n",
+ __func__, iface, port, NET_ErrorString());
+ Cvar_Set("net_ignore_icmp", "1");
}
#if USE_PMTUDISC
// overload negative values to enable path MTU discovery
- switch( net_ignore_icmp->integer ) {
- case -1: pmtudisc = IP_PMTUDISC_WANT; break;
- case -2: pmtudisc = IP_PMTUDISC_DO; break;
+ switch (net_ignore_icmp->integer) {
+ case -1: pmtudisc = IP_PMTUDISC_WANT; break;
+ case -2: pmtudisc = IP_PMTUDISC_DO; break;
#ifdef IP_PMTUDISC_PROBE
- case -3: pmtudisc = IP_PMTUDISC_PROBE; break;
+ case -3: pmtudisc = IP_PMTUDISC_PROBE; break;
#endif
}
#endif // USE_PMTUDISC
@@ -983,213 +1002,219 @@ static SOCKET UDP_OpenSocket( const char *iface, int port ) {
#endif // USE_ICMP
// disable or enable path MTU discovery
- if( set_option( s, IPPROTO_IP, IP_MTU_DISCOVER, pmtudisc ) == -1 ) {
- Com_WPrintf( "%s: %s:%d: can't %sable path MTU discovery: %s\n",
- __func__, iface, port, pmtudisc == IP_PMTUDISC_DONT ? "dis" : "en",
- NET_ErrorString() );
+ if (set_option(s, IPPROTO_IP, IP_MTU_DISCOVER, pmtudisc) == -1) {
+ Com_WPrintf("%s: %s:%d: can't %sable path MTU discovery: %s\n",
+ __func__, iface, port, pmtudisc == IP_PMTUDISC_DONT ? "dis" : "en",
+ NET_ErrorString());
}
#endif // __linux__
// resolve iface sadr
- if( !get_bind_addr( iface, port, &sadr ) ) {
- Com_EPrintf( "%s: %s:%d: bad interface address\n",
- __func__, iface, port );
+ if (!get_bind_addr(iface, port, &sadr)) {
+ Com_EPrintf("%s: %s:%d: bad interface address\n",
+ __func__, iface, port);
goto fail;
}
- if( bind_socket( s, &sadr ) == -1 ) {
- Com_EPrintf( "%s: %s:%d: can't bind socket: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (bind_socket(s, &sadr) == -1) {
+ Com_EPrintf("%s: %s:%d: can't bind socket: %s\n",
+ __func__, iface, port, NET_ErrorString());
goto fail;
}
return s;
fail:
- closesocket( s );
+ closesocket(s);
return INVALID_SOCKET;
}
-static SOCKET TCP_OpenSocket( const char *iface, int port, netsrc_t who ) {
+static SOCKET TCP_OpenSocket(const char *iface, int port, netsrc_t who)
+{
SOCKET s;
struct sockaddr_in sadr;
- Com_DPrintf( "Opening TCP socket: %s:%i\n", iface, port );
+ Com_DPrintf("Opening TCP socket: %s:%i\n", iface, port);
- s = create_socket( SOCK_STREAM, IPPROTO_TCP );
- if( s == INVALID_SOCKET ) {
- Com_EPrintf( "%s: %s:%d: can't create socket: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ s = create_socket(SOCK_STREAM, IPPROTO_TCP);
+ if (s == INVALID_SOCKET) {
+ Com_EPrintf("%s: %s:%d: can't create socket: %s\n",
+ __func__, iface, port, NET_ErrorString());
return INVALID_SOCKET;
}
// make it non-blocking
- if( make_nonblock( s ) == -1 ) {
- Com_EPrintf( "%s: %s:%d: can't make socket non-blocking: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (make_nonblock(s) == -1) {
+ Com_EPrintf("%s: %s:%d: can't make socket non-blocking: %s\n",
+ __func__, iface, port, NET_ErrorString());
goto fail;
}
// give it a chance to reuse previous port
- if( who == NS_SERVER ) {
- if( enable_option( s, SOL_SOCKET, SO_REUSEADDR ) == -1 ) {
- Com_WPrintf( "%s: %s:%d: can't force socket to reuse address: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (who == NS_SERVER) {
+ if (enable_option(s, SOL_SOCKET, SO_REUSEADDR) == -1) {
+ Com_WPrintf("%s: %s:%d: can't force socket to reuse address: %s\n",
+ __func__, iface, port, NET_ErrorString());
}
}
- if( !get_bind_addr( iface, port, &sadr ) ) {
- Com_EPrintf( "%s: %s:%d: bad interface address\n",
- __func__, iface, port );
+ if (!get_bind_addr(iface, port, &sadr)) {
+ Com_EPrintf("%s: %s:%d: bad interface address\n",
+ __func__, iface, port);
goto fail;
}
- if( bind_socket( s, &sadr ) == -1 ) {
- Com_EPrintf( "%s: %s:%d: can't bind socket: %s\n",
- __func__, iface, port, NET_ErrorString() );
+ if (bind_socket(s, &sadr) == -1) {
+ Com_EPrintf("%s: %s:%d: can't bind socket: %s\n",
+ __func__, iface, port, NET_ErrorString());
goto fail;
}
return s;
fail:
- closesocket( s );
+ closesocket(s);
return INVALID_SOCKET;
}
-static void NET_OpenServer( void ) {
+static void NET_OpenServer(void)
+{
static int saved_port;
ioentry_t *e;
SOCKET s;
- s = UDP_OpenSocket( net_ip->string, net_port->integer );
- if( s != INVALID_SOCKET ) {
+ s = UDP_OpenSocket(net_ip->string, net_port->integer);
+ if (s != INVALID_SOCKET) {
saved_port = net_port->integer;
udp_sockets[NS_SERVER] = s;
- e = IO_Add( s );
+ e = IO_Add(s);
e->wantread = qtrue;
return;
}
- if( saved_port && saved_port != net_port->integer ) {
+ if (saved_port && saved_port != net_port->integer) {
// revert to the last valid port
- Com_Printf( "Reverting to the last valid port %d...\n", saved_port );
- Cbuf_AddText( &cmd_buffer, va( "set net_port %d\n", saved_port ) );
+ Com_Printf("Reverting to the last valid port %d...\n", saved_port);
+ Cbuf_AddText(&cmd_buffer, va("set net_port %d\n", saved_port));
return;
}
#if USE_CLIENT
- if( !dedicated->integer ) {
- Com_WPrintf( "Couldn't open server UDP port.\n" );
+ if (!dedicated->integer) {
+ Com_WPrintf("Couldn't open server UDP port.\n");
return;
}
#endif
- Com_Error( ERR_FATAL, "Couldn't open dedicated server UDP port" );
+ Com_Error(ERR_FATAL, "Couldn't open dedicated server UDP port");
}
#if USE_CLIENT
-static void NET_OpenClient( void ) {
+static void NET_OpenClient(void)
+{
ioentry_t *e;
SOCKET s;
struct sockaddr_in sadr;
socklen_t len;
- s = UDP_OpenSocket( net_ip->string, net_clientport->integer );
- if( s == INVALID_SOCKET ) {
+ s = UDP_OpenSocket(net_ip->string, net_clientport->integer);
+ if (s == INVALID_SOCKET) {
// now try with random port
- if( net_clientport->integer != PORT_ANY ) {
- s = UDP_OpenSocket( net_ip->string, PORT_ANY );
+ if (net_clientport->integer != PORT_ANY) {
+ s = UDP_OpenSocket(net_ip->string, PORT_ANY);
}
- if( s == INVALID_SOCKET ) {
- Com_WPrintf( "Couldn't open client UDP port.\n" );
+ if (s == INVALID_SOCKET) {
+ Com_WPrintf("Couldn't open client UDP port.\n");
return;
}
- len = sizeof( sadr );
- getsockname( s, ( struct sockaddr * )&sadr, &len );
- Com_WPrintf( "Client bound to UDP port %d.\n", ntohs( sadr.sin_port ) );
- Cvar_SetByVar( net_clientport, va( "%d", PORT_ANY ), FROM_CODE );
+ len = sizeof(sadr);
+ getsockname(s, (struct sockaddr *)&sadr, &len);
+ Com_WPrintf("Client bound to UDP port %d.\n", ntohs(sadr.sin_port));
+ Cvar_SetByVar(net_clientport, va("%d", PORT_ANY), FROM_CODE);
}
udp_sockets[NS_CLIENT] = s;
- e = IO_Add( s );
+ e = IO_Add(s);
e->wantread = qtrue;
}
#endif
//=============================================================================
-void NET_Close( netstream_t *s ) {
- if( !s->state ) {
+void NET_Close(netstream_t *s)
+{
+ if (!s->state) {
return;
}
- IO_Remove( s->socket );
- closesocket( s->socket );
+ IO_Remove(s->socket);
+ closesocket(s->socket);
s->socket = INVALID_SOCKET;
s->state = NS_DISCONNECTED;
}
-neterr_t NET_Listen( qboolean arg ) {
+neterr_t NET_Listen(qboolean arg)
+{
SOCKET s;
ioentry_t *e;
- if( !arg ) {
- if( tcp_socket != INVALID_SOCKET ) {
- IO_Remove( tcp_socket );
- closesocket( tcp_socket );
+ if (!arg) {
+ if (tcp_socket != INVALID_SOCKET) {
+ IO_Remove(tcp_socket);
+ closesocket(tcp_socket);
tcp_socket = INVALID_SOCKET;
}
return NET_OK;
}
- if( tcp_socket != INVALID_SOCKET ) {
+ if (tcp_socket != INVALID_SOCKET) {
return NET_OK;
}
- s = TCP_OpenSocket( net_tcp_ip->string,
- net_tcp_port->integer, NS_SERVER );
- if( s == INVALID_SOCKET ) {
+ s = TCP_OpenSocket(net_tcp_ip->string,
+ net_tcp_port->integer, NS_SERVER);
+ if (s == INVALID_SOCKET) {
return NET_ERROR;
}
- if( listen( s, net_tcp_backlog->integer ) == -1 ) {
+ if (listen(s, net_tcp_backlog->integer) == -1) {
NET_GET_ERROR();
- closesocket( s );
+ closesocket(s);
return NET_ERROR;
}
tcp_socket = s;
- e = IO_Add( s );
+ e = IO_Add(s);
e->wantread = qtrue;
return NET_OK;
}
// net_from variable receives source address
-neterr_t NET_Accept( netstream_t *s ) {
+neterr_t NET_Accept(netstream_t *s)
+{
struct sockaddr_in from;
socklen_t fromlen;
SOCKET newsocket;
ioentry_t *e;
- if( tcp_socket == INVALID_SOCKET ) {
+ if (tcp_socket == INVALID_SOCKET) {
return NET_AGAIN;
}
- e = IO_Get( tcp_socket );
- if( !e->canread ) {
+ e = IO_Get(tcp_socket);
+ if (!e->canread) {
return NET_AGAIN;
}
- memset( &from, 0, sizeof( from ) );
- fromlen = sizeof( from );
- newsocket = accept( tcp_socket, ( struct sockaddr * )&from, &fromlen );
+ memset(&from, 0, sizeof(from));
+ fromlen = sizeof(from);
+ newsocket = accept(tcp_socket, (struct sockaddr *)&from, &fromlen);
- NET_SockadrToNetadr( &from, &net_from );
+ NET_SockadrToNetadr(&from, &net_from);
- if( newsocket == -1 ) {
- if( NET_WOULD_BLOCK() ) {
+ if (newsocket == -1) {
+ if (NET_WOULD_BLOCK()) {
// wouldblock is silent
e->canread = qfalse;
return NET_AGAIN;
@@ -1198,26 +1223,27 @@ neterr_t NET_Accept( netstream_t *s ) {
}
// make it non-blocking
- if( make_nonblock( newsocket ) == -1 ) {
- closesocket( newsocket );
+ if (make_nonblock(newsocket) == -1) {
+ closesocket(newsocket);
return NET_ERROR;
}
// initialize stream
- memset( s, 0, sizeof( *s ) );
+ memset(s, 0, sizeof(*s));
s->socket = newsocket;
s->address = net_from;
s->state = NS_CONNECTED;
// initialize io entry
- e = IO_Add( newsocket );
+ e = IO_Add(newsocket);
//e->wantwrite = qtrue;
e->wantread = qtrue;
return NET_OK;
}
-neterr_t NET_Connect( const netadr_t *peer, netstream_t *s ) {
+neterr_t NET_Connect(const netadr_t *peer, netstream_t *s)
+{
SOCKET socket;
ioentry_t *e;
struct sockaddr_in sadr;
@@ -1225,34 +1251,34 @@ neterr_t NET_Connect( const netadr_t *peer, netstream_t *s ) {
// always bind to `net_ip' for outgoing TCP connections
// to avoid problems with AC or MVD/GTV auth on a multi IP system
- socket = TCP_OpenSocket( net_ip->string, PORT_ANY, NS_CLIENT );
- if( socket == INVALID_SOCKET ) {
+ socket = TCP_OpenSocket(net_ip->string, PORT_ANY, NS_CLIENT);
+ if (socket == INVALID_SOCKET) {
return NET_ERROR;
}
- NET_NetadrToSockadr( peer, &sadr );
+ NET_NetadrToSockadr(peer, &sadr);
- ret = connect( socket, ( struct sockaddr * )&sadr, sizeof( sadr ) );
- if( ret == -1 ) {
+ ret = connect(socket, (struct sockaddr *)&sadr, sizeof(sadr));
+ if (ret == -1) {
#ifdef _WIN32
- if( NET_GET_ERROR() != WSAEWOULDBLOCK ) {
+ if (NET_GET_ERROR() != WSAEWOULDBLOCK) {
#else
- if( NET_GET_ERROR() != EINPROGRESS ) {
+ if (NET_GET_ERROR() != EINPROGRESS) {
#endif
// wouldblock is silent
- closesocket( socket );
+ closesocket(socket);
return NET_ERROR;
}
}
// initialize stream
- memset( s, 0, sizeof( *s ) );
+ memset(s, 0, sizeof(*s));
s->state = NS_CONNECTING;
s->address = *peer;
s->socket = socket;
// initialize io entry
- e = IO_Add( socket );
+ e = IO_Add(socket);
e->wantwrite = qtrue;
#ifdef _WIN32
e->wantexcept = qtrue;
@@ -1261,31 +1287,31 @@ neterr_t NET_Connect( const netadr_t *peer, netstream_t *s ) {
return NET_OK;
}
-neterr_t NET_RunConnect( netstream_t *s ) {
+neterr_t NET_RunConnect(netstream_t *s)
+{
socklen_t len;
int ret, err;
ioentry_t *e;
- if( s->state != NS_CONNECTING ) {
+ if (s->state != NS_CONNECTING) {
return NET_AGAIN;
}
- e = IO_Get( s->socket );
- if( !e->canwrite
+ e = IO_Get(s->socket);
+ if (!e->canwrite
#ifdef _WIN32
&& !e->canexcept
#endif
- )
- {
+ ) {
return NET_AGAIN;
}
- len = sizeof( err );
- ret = getsockopt( s->socket, SOL_SOCKET, SO_ERROR, ( char * )&err, &len );
- if( ret == -1 ) {
+ len = sizeof(err);
+ ret = getsockopt(s->socket, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
+ if (ret == -1) {
goto error1;
}
- if( err ) {
+ if (err) {
net_error = err;
goto error2;
}
@@ -1311,56 +1337,58 @@ error2:
}
// updates wantread/wantwrite
-void NET_UpdateStream( netstream_t *s ) {
+void NET_UpdateStream(netstream_t *s)
+{
size_t len;
ioentry_t *e;
- if( s->state != NS_CONNECTED ) {
+ if (s->state != NS_CONNECTED) {
return;
}
- e = IO_Get( s->socket );
+ e = IO_Get(s->socket);
- FIFO_Reserve( &s->recv, &len );
+ FIFO_Reserve(&s->recv, &len);
e->wantread = len ? qtrue : qfalse;
- FIFO_Peek( &s->send, &len );
+ FIFO_Peek(&s->send, &len);
e->wantwrite = len ? qtrue : qfalse;
}
// returns NET_OK only when there was some data read
-neterr_t NET_RunStream( netstream_t *s ) {
+neterr_t NET_RunStream(netstream_t *s)
+{
int ret;
size_t len;
void *data;
neterr_t result = NET_AGAIN;
ioentry_t *e;
- if( s->state != NS_CONNECTED ) {
+ if (s->state != NS_CONNECTED) {
return result;
}
- e = IO_Get( s->socket );
- if( e->wantread && e->canread ) {
+ e = IO_Get(s->socket);
+ if (e->wantread && e->canread) {
// read as much as we can
- data = FIFO_Reserve( &s->recv, &len );
- if( len ) {
- ret = recv( s->socket, data, len, 0 );
- if( !ret ) {
+ data = FIFO_Reserve(&s->recv, &len);
+ if (len) {
+ ret = recv(s->socket, data, len, 0);
+ if (!ret) {
goto closed;
}
- if( ret == -1 ) {
- if( NET_WOULD_BLOCK() ) {
+ if (ret == -1) {
+ if (NET_WOULD_BLOCK()) {
// wouldblock is silent
e->canread = qfalse;
} else {
goto error;
}
} else {
- FIFO_Commit( &s->recv, ret );
+ FIFO_Commit(&s->recv, ret);
#if _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( &s->address, "TCP recv", data, ret );
+ if (net_log_enable->integer) {
+ NET_LogPacket(&s->address, "TCP recv", data, ret);
}
#endif
net_rate_rcvd += ret;
@@ -1369,34 +1397,34 @@ neterr_t NET_RunStream( netstream_t *s ) {
result = NET_OK;
// now see if there's more space to read
- FIFO_Reserve( &s->recv, &len );
- if( !len ) {
+ FIFO_Reserve(&s->recv, &len);
+ if (!len) {
e->wantread = qfalse;
}
}
}
}
- if( e->wantwrite && e->canwrite ) {
+ if (e->wantwrite && e->canwrite) {
// write as much as we can
- data = FIFO_Peek( &s->send, &len );
- if( len ) {
- ret = send( s->socket, data, len, 0 );
- if( !ret ) {
+ data = FIFO_Peek(&s->send, &len);
+ if (len) {
+ ret = send(s->socket, data, len, 0);
+ if (!ret) {
goto closed;
}
- if( ret == -1 ) {
- if( NET_WOULD_BLOCK() ) {
+ if (ret == -1) {
+ if (NET_WOULD_BLOCK()) {
// wouldblock is silent
e->canwrite = qfalse;
} else {
goto error;
}
} else {
- FIFO_Decommit( &s->send, ret );
+ FIFO_Decommit(&s->send, ret);
#if _DEBUG
- if( net_log_enable->integer ) {
- NET_LogPacket( &s->address, "TCP send", data, ret );
+ if (net_log_enable->integer) {
+ NET_LogPacket(&s->address, "TCP send", data, ret);
}
#endif
net_rate_sent += ret;
@@ -1405,8 +1433,8 @@ neterr_t NET_RunStream( netstream_t *s ) {
//result = NET_OK;
// now see if there's more data to write
- FIFO_Peek( &s->send, &len );
- if( !len ) {
+ FIFO_Peek(&s->send, &len);
+ if (!len) {
e->wantwrite = qfalse;
}
@@ -1435,37 +1463,38 @@ error:
NET_Stats_f
====================
*/
-static void NET_Stats_f( void ) {
- time_t diff, now = time( NULL );
+static void NET_Stats_f(void)
+{
+ time_t diff, now = time(NULL);
char buffer[MAX_QPATH];
- if( com_startTime > now ) {
+ if (com_startTime > now) {
com_startTime = now;
}
diff = now - com_startTime;
- if( diff < 1 ) {
+ if (diff < 1) {
diff = 1;
}
- Com_FormatTime( buffer, sizeof( buffer ), diff );
- Com_Printf( "Network uptime: %s\n", buffer );
- Com_Printf( "Bytes sent: %"PRIu64" (%"PRIu64" bytes/sec)\n",
- net_bytes_sent, net_bytes_sent / diff );
- Com_Printf( "Bytes rcvd: %"PRIu64" (%"PRIu64" bytes/sec)\n",
- net_bytes_rcvd, net_bytes_rcvd / diff );
- Com_Printf( "Packets sent: %"PRIu64" (%"PRIu64" packets/sec)\n",
- net_packets_sent, net_packets_sent / diff );
- Com_Printf( "Packets rcvd: %"PRIu64" (%"PRIu64" packets/sec)\n",
- net_packets_rcvd, net_packets_rcvd / diff );
+ Com_FormatTime(buffer, sizeof(buffer), diff);
+ Com_Printf("Network uptime: %s\n", buffer);
+ Com_Printf("Bytes sent: %"PRIu64" (%"PRIu64" bytes/sec)\n",
+ net_bytes_sent, net_bytes_sent / diff);
+ Com_Printf("Bytes rcvd: %"PRIu64" (%"PRIu64" bytes/sec)\n",
+ net_bytes_rcvd, net_bytes_rcvd / diff);
+ Com_Printf("Packets sent: %"PRIu64" (%"PRIu64" packets/sec)\n",
+ net_packets_sent, net_packets_sent / diff);
+ Com_Printf("Packets rcvd: %"PRIu64" (%"PRIu64" packets/sec)\n",
+ net_packets_rcvd, net_packets_rcvd / diff);
#if USE_ICMP
- Com_Printf( "Total errors: %"PRIu64"/%"PRIu64"/%"PRIu64" (send/recv/icmp)\n",
- net_send_errors, net_recv_errors, net_icmp_errors );
+ Com_Printf("Total errors: %"PRIu64"/%"PRIu64"/%"PRIu64" (send/recv/icmp)\n",
+ net_send_errors, net_recv_errors, net_icmp_errors);
#else
- Com_Printf( "Total errors: %"PRIu64"/%"PRIu64" (send/recv)\n",
- net_send_errors, net_recv_errors );
+ Com_Printf("Total errors: %"PRIu64"/%"PRIu64" (send/recv)\n",
+ net_send_errors, net_recv_errors);
#endif
- Com_Printf( "Current upload rate: %"PRIz" bytes/sec\n", net_rate_up );
- Com_Printf( "Current download rate: %"PRIz" bytes/sec\n", net_rate_dn );
+ Com_Printf("Current upload rate: %"PRIz" bytes/sec\n", net_rate_up);
+ Com_Printf("Current download rate: %"PRIz" bytes/sec\n", net_rate_dn);
}
/*
@@ -1473,37 +1502,39 @@ static void NET_Stats_f( void ) {
NET_DumpHostInfo
====================
*/
-static void NET_DumpHostInfo( struct hostent *h ) {
+static void NET_DumpHostInfo(struct hostent *h)
+{
byte **list;
int i;
- Com_Printf( "Hostname: %s\n", h->h_name );
+ Com_Printf("Hostname: %s\n", h->h_name);
- list = ( byte ** )h->h_aliases;
- for( i = 0; list[i]; i++ ) {
- Com_Printf( "Alias : %s\n", list[i] );
+ list = (byte **)h->h_aliases;
+ for (i = 0; list[i]; i++) {
+ Com_Printf("Alias : %s\n", list[i]);
}
- list = ( byte ** )h->h_addr_list;
- for( i = 0; list[i]; i++ ) {
- Com_Printf( "IP : %u.%u.%u.%u\n",
- list[i][0], list[i][1], list[i][2], list[i][3] );
+ list = (byte **)h->h_addr_list;
+ for (i = 0; list[i]; i++) {
+ Com_Printf("IP : %u.%u.%u.%u\n",
+ list[i][0], list[i][1], list[i][2], list[i][3]);
}
}
-static void dump_socket( SOCKET s, const char *s1, const char *s2 ) {
+static void dump_socket(SOCKET s, const char *s1, const char *s2)
+{
struct sockaddr_in sadr;
socklen_t len;
netadr_t adr;
- len = sizeof( sadr );
- if( getsockname( s, ( struct sockaddr * )&sadr, &len ) == -1 ) {
+ len = sizeof(sadr);
+ if (getsockname(s, (struct sockaddr *)&sadr, &len) == -1) {
NET_GET_ERROR();
- Com_EPrintf( "%s: getsockname: %s\n", __func__, NET_ErrorString() );
+ Com_EPrintf("%s: getsockname: %s\n", __func__, NET_ErrorString());
return;
}
- NET_SockadrToNetadr( &sadr, &adr );
- Com_Printf( "%s %s socket bound to %s\n", s1, s2, NET_AdrToString( &adr ) );
+ NET_SockadrToNetadr(&sadr, &adr);
+ Com_Printf("%s %s socket bound to %s\n", s1, s2, NET_AdrToString(&adr));
}
/*
@@ -1511,32 +1542,33 @@ static void dump_socket( SOCKET s, const char *s1, const char *s2 ) {
NET_ShowIP_f
====================
*/
-static void NET_ShowIP_f( void ) {
+static void NET_ShowIP_f(void)
+{
char buffer[256];
struct hostent *h;
netsrc_t sock;
- if( gethostname( buffer, sizeof( buffer ) ) == -1 ) {
+ if (gethostname(buffer, sizeof(buffer)) == -1) {
NET_GET_ERROR();
- Com_EPrintf( "%s: gethostname: %s\n", __func__, NET_ErrorString() );
+ Com_EPrintf("%s: gethostname: %s\n", __func__, NET_ErrorString());
return;
}
- if( !( h = gethostbyname( buffer ) ) ) {
+ if (!(h = gethostbyname(buffer))) {
NET_GET_ERROR();
- Com_EPrintf( "%s: gethostbyname: %s\n", __func__, NET_ErrorString() );
+ Com_EPrintf("%s: gethostbyname: %s\n", __func__, NET_ErrorString());
return;
}
- NET_DumpHostInfo( h );
+ NET_DumpHostInfo(h);
- for( sock = 0; sock < NS_COUNT; sock++ ) {
- if( udp_sockets[sock] != INVALID_SOCKET ) {
- dump_socket( udp_sockets[sock], socketNames[sock], "UDP" );
+ for (sock = 0; sock < NS_COUNT; sock++) {
+ if (udp_sockets[sock] != INVALID_SOCKET) {
+ dump_socket(udp_sockets[sock], socketNames[sock], "UDP");
}
}
- if( tcp_socket != INVALID_SOCKET ) {
- dump_socket( tcp_socket, socketNames[NS_SERVER], "TCP" );
+ if (tcp_socket != INVALID_SOCKET) {
+ dump_socket(tcp_socket, socketNames[NS_SERVER], "TCP");
}
}
@@ -1545,36 +1577,37 @@ static void NET_ShowIP_f( void ) {
NET_Dns_f
====================
*/
-static void NET_Dns_f( void ) {
+static void NET_Dns_f(void)
+{
char buffer[MAX_QPATH];
char *p;
struct hostent *h;
u_long address;
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <address>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <address>\n", Cmd_Argv(0));
return;
}
- Cmd_ArgvBuffer( 1, buffer, sizeof( buffer ) );
+ Cmd_ArgvBuffer(1, buffer, sizeof(buffer));
- if( ( p = strchr( buffer, ':' ) ) != NULL ) {
+ if ((p = strchr(buffer, ':')) != NULL) {
*p = 0;
}
- if( ( address = inet_addr( buffer ) ) != INADDR_NONE ) {
- h = gethostbyaddr( ( const char * )&address, sizeof( address ), AF_INET );
+ if ((address = inet_addr(buffer)) != INADDR_NONE) {
+ h = gethostbyaddr((const char *)&address, sizeof(address), AF_INET);
} else {
- h = gethostbyname( buffer );
+ h = gethostbyname(buffer);
}
- if( !h ) {
- Com_Printf( "Couldn't resolve %s\n", buffer );
+ if (!h) {
+ Com_Printf("Couldn't resolve %s\n", buffer);
return;
}
- NET_DumpHostInfo( h );
-
+ NET_DumpHostInfo(h);
+
}
/*
@@ -1582,19 +1615,20 @@ static void NET_Dns_f( void ) {
NET_Restart_f
====================
*/
-static void NET_Restart_f( void ) {
+static void NET_Restart_f(void)
+{
netflag_t flag = net_active;
qboolean listen = tcp_socket != INVALID_SOCKET;
- Com_DPrintf( "%s\n", __func__ );
+ Com_DPrintf("%s\n", __func__);
- if( listen ) {
- NET_Listen( qfalse );
+ if (listen) {
+ NET_Listen(qfalse);
}
- NET_Config( NET_NONE );
- NET_Config( flag );
- if( listen ) {
- NET_Listen( qtrue );
+ NET_Config(NET_NONE);
+ NET_Config(flag);
+ if (listen) {
+ NET_Listen(qtrue);
}
#if USE_SYSCON
@@ -1607,19 +1641,20 @@ static void NET_Restart_f( void ) {
NET_Config
====================
*/
-void NET_Config( netflag_t flag ) {
+void NET_Config(netflag_t flag)
+{
netsrc_t sock;
- if( flag == net_active ) {
+ if (flag == net_active) {
return;
}
- if( flag == NET_NONE ) {
+ if (flag == NET_NONE) {
// shut down any existing sockets
- for( sock = 0; sock < NS_COUNT; sock++ ) {
- if( udp_sockets[sock] != INVALID_SOCKET ) {
- IO_Remove( udp_sockets[sock] );
- closesocket( udp_sockets[sock] );
+ for (sock = 0; sock < NS_COUNT; sock++) {
+ if (udp_sockets[sock] != INVALID_SOCKET) {
+ IO_Remove(udp_sockets[sock]);
+ closesocket(udp_sockets[sock]);
udp_sockets[sock] = INVALID_SOCKET;
}
}
@@ -1628,61 +1663,66 @@ void NET_Config( netflag_t flag ) {
}
#if USE_CLIENT
- if( ( flag & NET_CLIENT ) && udp_sockets[NS_CLIENT] == INVALID_SOCKET ) {
+ if ((flag & NET_CLIENT) && udp_sockets[NS_CLIENT] == INVALID_SOCKET) {
NET_OpenClient();
}
#endif
- if( ( flag & NET_SERVER ) && udp_sockets[NS_SERVER] == INVALID_SOCKET ) {
+ if ((flag & NET_SERVER) && udp_sockets[NS_SERVER] == INVALID_SOCKET) {
NET_OpenServer();
}
net_active |= flag;
}
-qboolean NET_GetAddress( netsrc_t sock, netadr_t *adr ) {
+qboolean NET_GetAddress(netsrc_t sock, netadr_t *adr)
+{
struct sockaddr_in sadr;
socklen_t len;
SOCKET s = udp_sockets[sock];
- if( s == INVALID_SOCKET ) {
+ if (s == INVALID_SOCKET) {
return qfalse;
}
- len = sizeof( sadr );
- if( getsockname( s, ( struct sockaddr * )&sadr, &len ) == -1 ) {
+ len = sizeof(sadr);
+ if (getsockname(s, (struct sockaddr *)&sadr, &len) == -1) {
return qfalse;
}
- NET_SockadrToNetadr( &sadr, adr );
+ NET_SockadrToNetadr(&sadr, adr);
return qtrue;
}
-static size_t NET_UpRate_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%"PRIz, net_rate_up );
+static size_t NET_UpRate_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%"PRIz, net_rate_up);
}
-static size_t NET_DnRate_m( char *buffer, size_t size ) {
- return Q_scnprintf( buffer, size, "%"PRIz, net_rate_dn );
+static size_t NET_DnRate_m(char *buffer, size_t size)
+{
+ return Q_scnprintf(buffer, size, "%"PRIz, net_rate_dn);
}
-static void net_udp_param_changed( cvar_t *self ) {
+static void net_udp_param_changed(cvar_t *self)
+{
// keep TCP socket vars in sync unless modified by user
- if( !( net_tcp_ip->flags & CVAR_MODIFIED ) ) {
- Cvar_SetByVar( net_tcp_ip, net_ip->string, FROM_CODE );
+ if (!(net_tcp_ip->flags & CVAR_MODIFIED)) {
+ Cvar_SetByVar(net_tcp_ip, net_ip->string, FROM_CODE);
}
- if( !( net_tcp_port->flags & CVAR_MODIFIED ) ) {
- Cvar_SetByVar( net_tcp_port, net_port->string, FROM_CODE );
+ if (!(net_tcp_port->flags & CVAR_MODIFIED)) {
+ Cvar_SetByVar(net_tcp_port, net_port->string, FROM_CODE);
}
NET_Restart_f();
}
-static void net_tcp_param_changed( cvar_t *self ) {
- if( tcp_socket != INVALID_SOCKET ) {
- NET_Listen( qfalse );
- NET_Listen( qtrue );
+static void net_tcp_param_changed(cvar_t *self)
+{
+ if (tcp_socket != INVALID_SOCKET) {
+ NET_Listen(qfalse);
+ NET_Listen(qtrue);
}
}
@@ -1691,58 +1731,59 @@ static void net_tcp_param_changed( cvar_t *self ) {
NET_Init
====================
*/
-void NET_Init( void ) {
+void NET_Init(void)
+{
#ifdef _WIN32
WSADATA ws;
int ret;
- ret = WSAStartup( MAKEWORD( 1, 1 ), &ws );
- if( ret ) {
- Com_Error( ERR_FATAL, "Winsock initialization failed, returned %d", ret );
+ ret = WSAStartup(MAKEWORD(1, 1), &ws);
+ if (ret) {
+ Com_Error(ERR_FATAL, "Winsock initialization failed, returned %d", ret);
}
- Com_DPrintf( "Winsock Initialized\n" );
+ Com_DPrintf("Winsock Initialized\n");
#endif
- net_ip = Cvar_Get( "net_ip", "", 0 );
+ net_ip = Cvar_Get("net_ip", "", 0);
net_ip->changed = net_udp_param_changed;
- net_port = Cvar_Get( "net_port", PORT_SERVER_STRING, 0 );
+ net_port = Cvar_Get("net_port", PORT_SERVER_STRING, 0);
net_port->changed = net_udp_param_changed;
#if USE_CLIENT
- net_clientport = Cvar_Get( "net_clientport", PORT_ANY_STRING, 0 );
+ net_clientport = Cvar_Get("net_clientport", PORT_ANY_STRING, 0);
net_clientport->changed = net_udp_param_changed;
- net_dropsim = Cvar_Get( "net_dropsim", "0", 0 );
+ net_dropsim = Cvar_Get("net_dropsim", "0", 0);
#endif
#if _DEBUG
- net_log_enable = Cvar_Get( "net_log_enable", "0", 0 );
+ net_log_enable = Cvar_Get("net_log_enable", "0", 0);
net_log_enable->changed = net_log_enable_changed;
- net_log_name = Cvar_Get( "net_log_name", "network", 0 );
+ net_log_name = Cvar_Get("net_log_name", "network", 0);
net_log_name->changed = net_log_param_changed;
- net_log_flush = Cvar_Get( "net_log_flush", "0", 0 );
+ net_log_flush = Cvar_Get("net_log_flush", "0", 0);
net_log_flush->changed = net_log_param_changed;
#endif
#if USE_ICMP
- net_ignore_icmp = Cvar_Get( "net_ignore_icmp", "0", 0 );
+ net_ignore_icmp = Cvar_Get("net_ignore_icmp", "0", 0);
#endif
- net_tcp_ip = Cvar_Get( "net_tcp_ip", net_ip->string, 0 );
+ net_tcp_ip = Cvar_Get("net_tcp_ip", net_ip->string, 0);
net_tcp_ip->changed = net_tcp_param_changed;
- net_tcp_port = Cvar_Get( "net_tcp_port", net_port->string, 0 );
+ net_tcp_port = Cvar_Get("net_tcp_port", net_port->string, 0);
net_tcp_port->changed = net_tcp_param_changed;
- net_tcp_backlog = Cvar_Get( "net_tcp_backlog", "4", 0 );
+ net_tcp_backlog = Cvar_Get("net_tcp_backlog", "4", 0);
#if _DEBUG
- net_log_enable_changed( net_log_enable );
+ net_log_enable_changed(net_log_enable);
#endif
net_rate_time = com_eventTime;
- Cmd_AddCommand( "net_restart", NET_Restart_f );
- Cmd_AddCommand( "net_stats", NET_Stats_f );
- Cmd_AddCommand( "showip", NET_ShowIP_f );
- Cmd_AddCommand( "dns", NET_Dns_f );
+ Cmd_AddCommand("net_restart", NET_Restart_f);
+ Cmd_AddCommand("net_stats", NET_Stats_f);
+ Cmd_AddCommand("showip", NET_ShowIP_f);
+ Cmd_AddCommand("dns", NET_Dns_f);
- Cmd_AddMacro( "net_uprate", NET_UpRate_m );
- Cmd_AddMacro( "net_dnrate", NET_DnRate_m );
+ Cmd_AddMacro("net_uprate", NET_UpRate_m);
+ Cmd_AddMacro("net_dnrate", NET_DnRate_m);
}
/*
@@ -1750,24 +1791,25 @@ void NET_Init( void ) {
NET_Shutdown
====================
*/
-void NET_Shutdown( void ) {
+void NET_Shutdown(void)
+{
#if _DEBUG
- if( net_logFile ) {
- FS_FCloseFile( net_logFile );
+ if (net_logFile) {
+ FS_FCloseFile(net_logFile);
net_logFile = 0;
}
#endif
- NET_Listen( qfalse );
- NET_Config( NET_NONE );
+ NET_Listen(qfalse);
+ NET_Config(NET_NONE);
#ifdef _WIN32
WSACleanup();
#endif
- Cmd_RemoveCommand( "net_restart" );
- Cmd_RemoveCommand( "net_stats" );
- Cmd_RemoveCommand( "showip" );
- Cmd_RemoveCommand( "dns" );
+ Cmd_RemoveCommand("net_restart");
+ Cmd_RemoveCommand("net_stats");
+ Cmd_RemoveCommand("showip");
+ Cmd_RemoveCommand("dns");
}
diff --git a/src/net_sock.h b/src/net_sock.h
index 8fccacb..8e5a340 100644
--- a/src/net_sock.h
+++ b/src/net_sock.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,12 +26,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define PORT_SERVER 27910
#define PORT_SERVER_STRING "27910"
-#define MIN_PACKETLEN 512 // don't allow smaller packets
-#define MAX_PACKETLEN 4096 // max length of a single packet
-#define PACKET_HEADER 10 // two ints and a short (worst case)
-#define MAX_PACKETLEN_DEFAULT 1400 // default quake2 limit
-#define MAX_PACKETLEN_WRITABLE ( MAX_PACKETLEN - PACKET_HEADER )
-#define MAX_PACKETLEN_WRITABLE_DEFAULT ( MAX_PACKETLEN_DEFAULT - PACKET_HEADER )
+#define MIN_PACKETLEN 512 // don't allow smaller packets
+#define MAX_PACKETLEN 4096 // max length of a single packet
+#define PACKET_HEADER 10 // two ints and a short (worst case)
+#define MAX_PACKETLEN_DEFAULT 1400 // default quake2 limit
+#define MAX_PACKETLEN_WRITABLE (MAX_PACKETLEN - PACKET_HEADER)
+#define MAX_PACKETLEN_WRITABLE_DEFAULT (MAX_PACKETLEN_DEFAULT - PACKET_HEADER)
typedef enum {
NA_BAD,
@@ -48,8 +48,8 @@ typedef enum {
typedef enum {
NET_NONE = 0,
- NET_CLIENT = ( 1 << 0 ),
- NET_SERVER = ( 1 << 1 )
+ NET_CLIENT = (1 << 0),
+ NET_SERVER = (1 << 1)
} netflag_t;
typedef enum {
@@ -71,17 +71,18 @@ typedef struct {
uint16_t port;
} netadr_t;
-static inline qboolean NET_IsEqualAdr( const netadr_t *a, const netadr_t *b ) {
- if( a->type != b->type ) {
+static inline qboolean NET_IsEqualAdr(const netadr_t *a, const netadr_t *b)
+{
+ if (a->type != b->type) {
return qfalse;
}
- switch( a->type ) {
+ switch (a->type) {
case NA_LOOPBACK:
return qtrue;
case NA_IP:
case NA_BROADCAST:
- if( a->ip.u32 == b->ip.u32 && a->port == b->port ) {
+ if (a->ip.u32 == b->ip.u32 && a->port == b->port) {
return qtrue;
}
// fall through
@@ -92,17 +93,18 @@ static inline qboolean NET_IsEqualAdr( const netadr_t *a, const netadr_t *b ) {
return qfalse;
}
-static inline qboolean NET_IsEqualBaseAdr( const netadr_t *a, const netadr_t *b ) {
- if( a->type != b->type ) {
+static inline qboolean NET_IsEqualBaseAdr(const netadr_t *a, const netadr_t *b)
+{
+ if (a->type != b->type) {
return qfalse;
}
- switch( a->type ) {
+ switch (a->type) {
case NA_LOOPBACK:
return qtrue;
case NA_IP:
case NA_BROADCAST:
- if( a->ip.u32 == b->ip.u32 ) {
+ if (a->ip.u32 == b->ip.u32) {
return qtrue;
}
// fall through
@@ -113,18 +115,18 @@ static inline qboolean NET_IsEqualBaseAdr( const netadr_t *a, const netadr_t *b
return qfalse;
}
-static inline qboolean NET_IsLanAddress( const netadr_t *adr ) {
- switch( adr->type ) {
+static inline qboolean NET_IsLanAddress(const netadr_t *adr)
+{
+ switch (adr->type) {
case NA_LOOPBACK:
return qtrue;
case NA_IP:
case NA_BROADCAST:
- if( adr->ip.u8[0] == 127 || adr->ip.u8[0] == 10 ) {
+ if (adr->ip.u8[0] == 127 || adr->ip.u8[0] == 10) {
return qtrue;
}
- if( adr->ip.u16[0] == MakeRawShort( 192, 168 ) ||
- adr->ip.u16[0] == MakeRawShort( 172, 16 ) )
- {
+ if (adr->ip.u16[0] == MakeRawShort(192, 168) ||
+ adr->ip.u16[0] == MakeRawShort(172, 16)) {
return qtrue;
}
// fall through
@@ -135,26 +137,26 @@ static inline qboolean NET_IsLanAddress( const netadr_t *adr ) {
return qfalse;
}
-void NET_Init( void );
-void NET_Shutdown( void );
+void NET_Init(void);
+void NET_Shutdown(void);
-void NET_Config( netflag_t flag );
-qboolean NET_GetAddress( netsrc_t sock, netadr_t *adr );
+void NET_Config(netflag_t flag);
+qboolean NET_GetAddress(netsrc_t sock, netadr_t *adr);
-qboolean NET_GetPacket( netsrc_t sock );
-qboolean NET_SendPacket( netsrc_t sock, const netadr_t *to, size_t length, const void *data );
-qboolean NET_GetLoopPacket( netsrc_t sock );
+qboolean NET_GetPacket(netsrc_t sock);
+qboolean NET_SendPacket(netsrc_t sock, const netadr_t *to, size_t length, const void *data);
+qboolean NET_GetLoopPacket(netsrc_t sock);
-char *NET_AdrToString( const netadr_t *a );
-qboolean NET_StringToAdr( const char *s, netadr_t *a, int port );
+char *NET_AdrToString(const netadr_t *a);
+qboolean NET_StringToAdr(const char *s, netadr_t *a, int port);
#if USE_CLIENT && USE_SERVER
-#define NET_IsLocalAddress( adr ) ( (adr)->type == NA_LOOPBACK )
+#define NET_IsLocalAddress(adr) ((adr)->type == NA_LOOPBACK)
#else
-#define NET_IsLocalAddress( adr ) 0
+#define NET_IsLocalAddress(adr) 0
#endif
-const char *NET_ErrorString( void );
+const char *NET_ErrorString(void);
extern cvar_t *net_ip;
extern cvar_t *net_port;
diff --git a/src/net_stream.h b/src/net_stream.h
index 544cb92..7ccfae2 100644
--- a/src/net_stream.h
+++ b/src/net_stream.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,10 +34,10 @@ typedef struct netstream_s {
fifo_t send;
} netstream_t;
-void NET_Close( netstream_t *s );
-neterr_t NET_Listen( qboolean listen );
-neterr_t NET_Accept( netstream_t *s );
-neterr_t NET_Connect( const netadr_t *peer, netstream_t *s );
-neterr_t NET_RunConnect( netstream_t *s );
-neterr_t NET_RunStream( netstream_t *s );
-void NET_UpdateStream( netstream_t *s );
+void NET_Close(netstream_t *s);
+neterr_t NET_Listen(qboolean listen);
+neterr_t NET_Accept(netstream_t *s);
+neterr_t NET_Connect(const netadr_t *peer, netstream_t *s);
+neterr_t NET_RunConnect(netstream_t *s);
+neterr_t NET_RunStream(netstream_t *s);
+void NET_UpdateStream(netstream_t *s);
diff --git a/src/pmove.c b/src/pmove.c
index 2f2b8c9..ca67722 100644
--- a/src/pmove.c
+++ b/src/pmove.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,8 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// pmove, just to make damn sure we don't have
// any differences when running on client or server
-typedef struct
-{
+typedef struct {
vec3_t origin; // full float precision
vec3_t velocity; // full float precision
@@ -74,17 +73,16 @@ returns the blocked flags (1 = floor, 2 = step / wall)
*/
#define STOP_EPSILON 0.1
-static void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
+static void PM_ClipVelocity(vec3_t in, vec3_t normal, vec3_t out, float overbounce)
{
float backoff;
float change;
int i;
-
- backoff = DotProduct (in, normal) * overbounce;
- for (i=0 ; i<3 ; i++)
- {
- change = normal[i]*backoff;
+ backoff = DotProduct(in, normal) * overbounce;
+
+ for (i = 0; i < 3; i++) {
+ change = normal[i] * backoff;
out[i] = in[i] - change;
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
out[i] = 0;
@@ -107,7 +105,7 @@ Does not modify any world state?
*/
#define MIN_STEP_NORMAL 0.7 // can't step up onto very steep slopes
#define MAX_CLIP_PLANES 5
-static void PM_StepSlideMove_ (void)
+static void PM_StepSlideMove_(void)
{
int bumpcount, numbumps;
vec3_t dir;
@@ -119,101 +117,93 @@ static void PM_StepSlideMove_ (void)
trace_t trace;
vec3_t end;
float time_left;
-
+
numbumps = 4;
-
- VectorCopy (pml.velocity, primal_velocity);
+
+ VectorCopy(pml.velocity, primal_velocity);
numplanes = 0;
-
+
time_left = pml.frametime;
- for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++)
- {
- for (i=0 ; i<3 ; i++)
+ for (bumpcount = 0; bumpcount < numbumps; bumpcount++) {
+ for (i = 0; i < 3; i++)
end[i] = pml.origin[i] + time_left * pml.velocity[i];
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, end);
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, end);
- if (trace.allsolid)
- { // entity is trapped in another solid
+ if (trace.allsolid) {
+ // entity is trapped in another solid
pml.velocity[2] = 0; // don't build up falling damage
return;
}
- if (trace.fraction > 0)
- { // actually covered some distance
- VectorCopy (trace.endpos, pml.origin);
+ if (trace.fraction > 0) {
+ // actually covered some distance
+ VectorCopy(trace.endpos, pml.origin);
numplanes = 0;
}
if (trace.fraction == 1)
- break; // moved the entire distance
+ break; // moved the entire distance
// save entity for contact
- if (pm->numtouch < MAXTOUCH && trace.ent)
- {
+ if (pm->numtouch < MAXTOUCH && trace.ent) {
pm->touchents[pm->numtouch] = trace.ent;
pm->numtouch++;
}
-
+
time_left -= time_left * trace.fraction;
// slide along this plane
- if (numplanes >= MAX_CLIP_PLANES)
- { // this shouldn't really happen
- VectorCopy (vec3_origin, pml.velocity);
+ if (numplanes >= MAX_CLIP_PLANES) {
+ // this shouldn't really happen
+ VectorCopy(vec3_origin, pml.velocity);
break;
}
- VectorCopy (trace.plane.normal, planes[numplanes]);
+ VectorCopy(trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
- for (i=0 ; i<numplanes ; i++)
- {
- PM_ClipVelocity (pml.velocity, planes[i], pml.velocity, 1.01);
- for (j=0 ; j<numplanes ; j++)
- if (j != i)
- {
- if (DotProduct (pml.velocity, planes[j]) < 0)
+ for (i = 0; i < numplanes; i++) {
+ PM_ClipVelocity(pml.velocity, planes[i], pml.velocity, 1.01);
+ for (j = 0; j < numplanes; j++)
+ if (j != i) {
+ if (DotProduct(pml.velocity, planes[j]) < 0)
break; // not ok
}
if (j == numplanes)
break;
}
-
- if (i != numplanes)
- { // go along this plane
- }
- else
- { // go along the crease
- if (numplanes != 2)
- {
+
+ if (i != numplanes) {
+ // go along this plane
+ } else {
+ // go along the crease
+ if (numplanes != 2) {
// Con_Printf ("clip velocity, numplanes == %i\n",numplanes);
- VectorCopy (vec3_origin, pml.velocity);
+ VectorCopy(vec3_origin, pml.velocity);
break;
}
- CrossProduct (planes[0], planes[1], dir);
- d = DotProduct (dir, pml.velocity);
- VectorScale (dir, d, pml.velocity);
+ CrossProduct(planes[0], planes[1], dir);
+ d = DotProduct(dir, pml.velocity);
+ VectorScale(dir, d, pml.velocity);
}
//
// if velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
- if (DotProduct (pml.velocity, primal_velocity) <= 0)
- {
- VectorCopy (vec3_origin, pml.velocity);
+ if (DotProduct(pml.velocity, primal_velocity) <= 0) {
+ VectorCopy(vec3_origin, pml.velocity);
break;
}
}
- if (pm->s.pm_time)
- {
- VectorCopy (primal_velocity, pml.velocity);
+ if (pm->s.pm_time) {
+ VectorCopy(primal_velocity, pml.velocity);
}
}
@@ -223,7 +213,7 @@ PM_StepSlideMove
==================
*/
-static void PM_StepSlideMove (void)
+static void PM_StepSlideMove(void)
{
vec3_t start_o, start_v;
vec3_t down_o, down_v;
@@ -232,48 +222,46 @@ static void PM_StepSlideMove (void)
// vec3_t delta;
vec3_t up, down;
- VectorCopy (pml.origin, start_o);
- VectorCopy (pml.velocity, start_v);
+ VectorCopy(pml.origin, start_o);
+ VectorCopy(pml.velocity, start_v);
- PM_StepSlideMove_ ();
+ PM_StepSlideMove_();
- VectorCopy (pml.origin, down_o);
- VectorCopy (pml.velocity, down_v);
+ VectorCopy(pml.origin, down_o);
+ VectorCopy(pml.velocity, down_v);
- VectorCopy (start_o, up);
+ VectorCopy(start_o, up);
up[2] += STEPSIZE;
- trace = pm->trace (up, pm->mins, pm->maxs, up);
+ trace = pm->trace(up, pm->mins, pm->maxs, up);
if (trace.allsolid)
return; // can't step up
// try sliding above
- VectorCopy (up, pml.origin);
- VectorCopy (start_v, pml.velocity);
+ VectorCopy(up, pml.origin);
+ VectorCopy(start_v, pml.velocity);
- PM_StepSlideMove_ ();
+ PM_StepSlideMove_();
// push down the final amount
- VectorCopy (pml.origin, down);
+ VectorCopy(pml.origin, down);
down[2] -= STEPSIZE;
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, down);
- if (!trace.allsolid)
- {
- VectorCopy (trace.endpos, pml.origin);
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, down);
+ if (!trace.allsolid) {
+ VectorCopy(trace.endpos, pml.origin);
}
VectorCopy(pml.origin, up);
// decide which one went farther
- down_dist = (down_o[0] - start_o[0])*(down_o[0] - start_o[0])
- + (down_o[1] - start_o[1])*(down_o[1] - start_o[1]);
- up_dist = (up[0] - start_o[0])*(up[0] - start_o[0])
- + (up[1] - start_o[1])*(up[1] - start_o[1]);
-
- if (down_dist > up_dist || trace.plane.normal[2] < MIN_STEP_NORMAL)
- {
- VectorCopy (down_o, pml.origin);
- VectorCopy (down_v, pml.velocity);
+ down_dist = (down_o[0] - start_o[0]) * (down_o[0] - start_o[0])
+ + (down_o[1] - start_o[1]) * (down_o[1] - start_o[1]);
+ up_dist = (up[0] - start_o[0]) * (up[0] - start_o[0])
+ + (up[1] - start_o[1]) * (up[1] - start_o[1]);
+
+ if (down_dist > up_dist || trace.plane.normal[2] < MIN_STEP_NORMAL) {
+ VectorCopy(down_o, pml.origin);
+ VectorCopy(down_v, pml.velocity);
return;
}
//!! Special case
@@ -289,18 +277,17 @@ PM_Friction
Handles both ground friction and water friction
==================
*/
-static void PM_Friction (void)
+static void PM_Friction(void)
{
float *vel;
float speed, newspeed, control;
float friction;
float drop;
-
+
vel = pml.velocity;
-
- speed = sqrt(vel[0]*vel[0] +vel[1]*vel[1] + vel[2]*vel[2]);
- if (speed < 1)
- {
+
+ speed = sqrt(vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
+ if (speed < 1) {
vel[0] = 0;
vel[1] = 0;
return;
@@ -309,21 +296,19 @@ static void PM_Friction (void)
drop = 0;
// apply ground friction
- if ((pm->groundentity && pml.groundsurface && !(pml.groundsurface->flags & SURF_SLICK) ) || (pml.ladder) )
- {
+ if ((pm->groundentity && pml.groundsurface && !(pml.groundsurface->flags & SURF_SLICK)) || (pml.ladder)) {
friction = pmp->friction;
control = speed < pm_stopspeed ? pm_stopspeed : speed;
- drop += control*friction*pml.frametime;
+ drop += control * friction * pml.frametime;
}
// apply water friction
if (pm->waterlevel && !pml.ladder)
- drop += speed*pmp->waterfriction*pm->waterlevel*pml.frametime;
+ drop += speed * pmp->waterfriction * pm->waterlevel * pml.frametime;
// scale the velocity
newspeed = speed - drop;
- if (newspeed < 0)
- {
+ if (newspeed < 0) {
newspeed = 0;
}
newspeed /= speed;
@@ -341,40 +326,40 @@ PM_Accelerate
Handles user intended acceleration
==============
*/
-static void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
+static void PM_Accelerate(vec3_t wishdir, float wishspeed, float accel)
{
int i;
float addspeed, accelspeed, currentspeed;
- currentspeed = DotProduct (pml.velocity, wishdir);
+ currentspeed = DotProduct(pml.velocity, wishdir);
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
return;
- accelspeed = accel*pml.frametime*wishspeed;
+ accelspeed = accel * pml.frametime * wishspeed;
if (accelspeed > addspeed)
accelspeed = addspeed;
-
- for (i=0 ; i<3 ; i++)
- pml.velocity[i] += accelspeed*wishdir[i];
+
+ for (i = 0; i < 3; i++)
+ pml.velocity[i] += accelspeed * wishdir[i];
}
-static void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel)
+static void PM_AirAccelerate(vec3_t wishdir, float wishspeed, float accel)
{
int i;
float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
-
+
if (wishspd > 30)
wishspd = 30;
- currentspeed = DotProduct (pml.velocity, wishdir);
+ currentspeed = DotProduct(pml.velocity, wishdir);
addspeed = wishspd - currentspeed;
if (addspeed <= 0)
return;
accelspeed = accel * wishspeed * pml.frametime;
if (accelspeed > addspeed)
accelspeed = addspeed;
-
- for (i=0 ; i<3 ; i++)
- pml.velocity[i] += accelspeed*wishdir[i];
+
+ for (i = 0; i < 3; i++)
+ pml.velocity[i] += accelspeed * wishdir[i];
}
/*
@@ -382,7 +367,7 @@ static void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel)
PM_AddCurrents
=============
*/
-static void PM_AddCurrents (vec3_t wishvel)
+static void PM_AddCurrents(vec3_t wishvel)
{
vec3_t v;
float s;
@@ -391,8 +376,7 @@ static void PM_AddCurrents (vec3_t wishvel)
// account for ladders
//
- if (pml.ladder && fabs(pml.velocity[2]) <= 200)
- {
+ if (pml.ladder && fabs(pml.velocity[2]) <= 200) {
if ((pm->viewangles[PITCH] <= -15) && (pm->cmd.forwardmove > 0))
wishvel[2] = 200;
else if ((pm->viewangles[PITCH] >= 15) && (pm->cmd.forwardmove > 0))
@@ -421,9 +405,8 @@ static void PM_AddCurrents (vec3_t wishvel)
// add water currents
//
- if (pm->watertype & MASK_CURRENT)
- {
- VectorClear (v);
+ if (pm->watertype & MASK_CURRENT) {
+ VectorClear(v);
if (pm->watertype & CONTENTS_CURRENT_0)
v[0] += 1;
@@ -442,16 +425,15 @@ static void PM_AddCurrents (vec3_t wishvel)
if ((pm->waterlevel == 1) && (pm->groundentity))
s /= 2;
- VectorMA (wishvel, s, v, wishvel);
+ VectorMA(wishvel, s, v, wishvel);
}
//
// add conveyor belt velocities
//
- if (pm->groundentity)
- {
- VectorClear (v);
+ if (pm->groundentity) {
+ VectorClear(v);
if (pml.groundcontents & CONTENTS_CURRENT_0)
v[0] += 1;
@@ -466,7 +448,7 @@ static void PM_AddCurrents (vec3_t wishvel)
if (pml.groundcontents & CONTENTS_CURRENT_DOWN)
v[2] -= 1;
- VectorMA (wishvel, 100 /* pm->groundentity->speed */, v, wishvel);
+ VectorMA(wishvel, 100 /* pm->groundentity->speed */, v, wishvel);
}
}
@@ -477,7 +459,7 @@ PM_WaterMove
===================
*/
-static void PM_WaterMove (void)
+static void PM_WaterMove(void)
{
int i;
vec3_t wishvel;
@@ -487,29 +469,28 @@ static void PM_WaterMove (void)
//
// user intentions
//
- for (i=0 ; i<3 ; i++)
- wishvel[i] = pml.forward[i]*pm->cmd.forwardmove + pml.right[i]*pm->cmd.sidemove;
+ for (i = 0; i < 3; i++)
+ wishvel[i] = pml.forward[i] * pm->cmd.forwardmove + pml.right[i] * pm->cmd.sidemove;
if (!pm->cmd.forwardmove && !pm->cmd.sidemove && !pm->cmd.upmove)
wishvel[2] -= 60; // drift towards bottom
else
wishvel[2] += pm->cmd.upmove;
- PM_AddCurrents (wishvel);
+ PM_AddCurrents(wishvel);
- VectorCopy (wishvel, wishdir);
+ VectorCopy(wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
- if (wishspeed > pmp->maxspeed)
- {
- VectorScale (wishvel, pmp->maxspeed / wishspeed, wishvel);
+ if (wishspeed > pmp->maxspeed) {
+ VectorScale(wishvel, pmp->maxspeed / wishspeed, wishvel);
wishspeed = pmp->maxspeed;
}
wishspeed *= pmp->watermult;
- PM_Accelerate (wishdir, wishspeed, pm_wateraccelerate);
+ PM_Accelerate(wishdir, wishspeed, pm_wateraccelerate);
- PM_StepSlideMove ();
+ PM_StepSlideMove();
}
@@ -519,7 +500,7 @@ PM_AirMove
===================
*/
-static void PM_AirMove (void)
+static void PM_AirMove(void)
{
int i;
vec3_t wishvel;
@@ -530,22 +511,22 @@ static void PM_AirMove (void)
fmove = pm->cmd.forwardmove;
smove = pm->cmd.sidemove;
-
+
//!!!!! pitch should be 1/3 so this isn't needed??!
#if 0
pml.forward[2] = 0;
pml.right[2] = 0;
- VectorNormalize (pml.forward);
- VectorNormalize (pml.right);
+ VectorNormalize(pml.forward);
+ VectorNormalize(pml.right);
#endif
- for (i=0 ; i<2 ; i++)
- wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove;
+ for (i = 0; i < 2; i++)
+ wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove;
wishvel[2] = 0;
- PM_AddCurrents (wishvel);
+ PM_AddCurrents(wishvel);
- VectorCopy (wishvel, wishdir);
+ VectorCopy(wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
//
@@ -553,41 +534,34 @@ static void PM_AirMove (void)
//
maxspeed = (pm->s.pm_flags & PMF_DUCKED) ? pm_duckspeed : pmp->maxspeed;
- if (wishspeed > maxspeed)
- {
- VectorScale (wishvel, maxspeed/wishspeed, wishvel);
+ if (wishspeed > maxspeed) {
+ VectorScale(wishvel, maxspeed / wishspeed, wishvel);
wishspeed = maxspeed;
}
-
- if ( pml.ladder )
- {
- PM_Accelerate (wishdir, wishspeed, pm_accelerate);
- if (!wishvel[2])
- {
- if (pml.velocity[2] > 0)
- {
+
+ if (pml.ladder) {
+ PM_Accelerate(wishdir, wishspeed, pm_accelerate);
+ if (!wishvel[2]) {
+ if (pml.velocity[2] > 0) {
pml.velocity[2] -= pm->s.gravity * pml.frametime;
if (pml.velocity[2] < 0)
pml.velocity[2] = 0;
- }
- else
- {
+ } else {
pml.velocity[2] += pm->s.gravity * pml.frametime;
if (pml.velocity[2] > 0)
pml.velocity[2] = 0;
}
}
- PM_StepSlideMove ();
- }
- else if ( pm->groundentity )
- { // walking on ground
+ PM_StepSlideMove();
+ } else if (pm->groundentity) {
+ // walking on ground
pml.velocity[2] = 0; //!!! this is before the accel
- PM_Accelerate (wishdir, wishspeed, pm_accelerate);
+ PM_Accelerate(wishdir, wishspeed, pm_accelerate);
// PGM -- fix for negative trigger_gravity fields
// pml.velocity[2] = 0;
- if(pm->s.gravity > 0)
+ if (pm->s.gravity > 0)
pml.velocity[2] = 0;
else
pml.velocity[2] -= pm->s.gravity * pml.frametime;
@@ -595,17 +569,16 @@ static void PM_AirMove (void)
if (!pml.velocity[0] && !pml.velocity[1])
return;
- PM_StepSlideMove ();
- }
- else
- { // not on ground, so little effect on velocity
+ PM_StepSlideMove();
+ } else {
+ // not on ground, so little effect on velocity
if (pmp->airaccelerate)
- PM_AirAccelerate (wishdir, wishspeed, pm_accelerate);
+ PM_AirAccelerate(wishdir, wishspeed, pm_accelerate);
else
- PM_Accelerate (wishdir, wishspeed, 1);
+ PM_Accelerate(wishdir, wishspeed, 1);
// add gravity
pml.velocity[2] -= pm->s.gravity * pml.frametime;
- PM_StepSlideMove ();
+ PM_StepSlideMove();
}
}
@@ -616,7 +589,7 @@ static void PM_AirMove (void)
PM_CategorizePosition
=============
*/
-static void PM_CategorizePosition (void)
+static void PM_CategorizePosition(void)
{
vec3_t point;
int cont;
@@ -627,56 +600,47 @@ static void PM_CategorizePosition (void)
// if the player hull point one unit down is solid, the player
// is on ground
-// see if standing on something solid
+// see if standing on something solid
point[0] = pml.origin[0];
point[1] = pml.origin[1];
point[2] = pml.origin[2] - 0.25f;
- if (pml.velocity[2] > 180) //!!ZOID changed from 100 to 180 (ramp accel)
- {
+ if (pml.velocity[2] > 180) { //!!ZOID changed from 100 to 180 (ramp accel)
pm->s.pm_flags &= ~PMF_ON_GROUND;
pm->groundentity = NULL;
- }
- else
- {
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, point);
+ } else {
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, point);
pml.groundplane = trace.plane;
pml.groundsurface = trace.surface;
pml.groundcontents = trace.contents;
- if (!trace.ent || (trace.plane.normal[2] < 0.7 && !trace.startsolid) )
- {
+ if (!trace.ent || (trace.plane.normal[2] < 0.7 && !trace.startsolid)) {
pm->groundentity = NULL;
pm->s.pm_flags &= ~PMF_ON_GROUND;
- }
- else
- {
+ } else {
pm->groundentity = trace.ent;
// hitting solid ground will end a waterjump
- if (pm->s.pm_flags & PMF_TIME_WATERJUMP)
- {
+ if (pm->s.pm_flags & PMF_TIME_WATERJUMP) {
pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_time = 0;
}
- if (! (pm->s.pm_flags & PMF_ON_GROUND) )
- { // just hit the ground
+ if (!(pm->s.pm_flags & PMF_ON_GROUND)) {
+ // just hit the ground
pm->s.pm_flags |= PMF_ON_GROUND;
// don't do landing time if we were just going down a slope
- if (pml.velocity[2] < -200 && !pmp->strafehack )
- {
+ if (pml.velocity[2] < -200 && !pmp->strafehack) {
pm->s.pm_flags |= PMF_TIME_LAND;
// don't allow another jump for a little while
if (pml.velocity[2] < -400)
- pm->s.pm_time = 25;
+ pm->s.pm_time = 25;
else
pm->s.pm_time = 18;
}
}
}
- if (pm->numtouch < MAXTOUCH && trace.ent)
- {
+ if (pm->numtouch < MAXTOUCH && trace.ent) {
pm->touchents[pm->numtouch] = trace.ent;
pm->numtouch++;
}
@@ -691,20 +655,18 @@ static void PM_CategorizePosition (void)
sample2 = pm->viewheight - pm->mins[2];
sample1 = sample2 / 2;
- point[2] = pml.origin[2] + pm->mins[2] + 1;
- cont = pm->pointcontents (point);
+ point[2] = pml.origin[2] + pm->mins[2] + 1;
+ cont = pm->pointcontents(point);
- if (cont & MASK_WATER)
- {
+ if (cont & MASK_WATER) {
pm->watertype = cont;
pm->waterlevel = 1;
point[2] = pml.origin[2] + pm->mins[2] + sample1;
- cont = pm->pointcontents (point);
- if (cont & MASK_WATER)
- {
+ cont = pm->pointcontents(point);
+ if (cont & MASK_WATER) {
pm->waterlevel = 2;
point[2] = pml.origin[2] + pm->mins[2] + sample2;
- cont = pm->pointcontents (point);
+ cont = pm->pointcontents(point);
if (cont & MASK_WATER)
pm->waterlevel = 3;
}
@@ -718,15 +680,15 @@ static void PM_CategorizePosition (void)
PM_CheckJump
=============
*/
-static void PM_CheckJump (void)
+static void PM_CheckJump(void)
{
- if (pm->s.pm_flags & PMF_TIME_LAND)
- { // hasn't been long enough since landing to jump again
+ if (pm->s.pm_flags & PMF_TIME_LAND) {
+ // hasn't been long enough since landing to jump again
return;
}
- if (pm->cmd.upmove < 10)
- { // not holding jump
+ if (pm->cmd.upmove < 10) {
+ // not holding jump
pm->s.pm_flags &= ~PMF_JUMP_HELD;
return;
}
@@ -738,8 +700,8 @@ static void PM_CheckJump (void)
if (pm->s.pm_type == PM_DEAD)
return;
- if (pm->waterlevel >= 2)
- { // swimming, not jumping
+ if (pm->waterlevel >= 2) {
+ // swimming, not jumping
pm->groundentity = NULL;
if (pmp->waterhack)
@@ -777,7 +739,7 @@ static void PM_CheckJump (void)
PM_CheckSpecialMovement
=============
*/
-static void PM_CheckSpecialMovement (void)
+static void PM_CheckSpecialMovement(void)
{
vec3_t spot;
int cont;
@@ -793,10 +755,10 @@ static void PM_CheckSpecialMovement (void)
flatforward[0] = pml.forward[0];
flatforward[1] = pml.forward[1];
flatforward[2] = 0;
- VectorNormalize (flatforward);
+ VectorNormalize(flatforward);
- VectorMA (pml.origin, 1, flatforward, spot);
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, spot);
+ VectorMA(pml.origin, 1, flatforward, spot);
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, spot);
if ((trace.fraction < 1) && (trace.contents & CONTENTS_LADDER))
pml.ladder = qtrue;
@@ -804,18 +766,18 @@ static void PM_CheckSpecialMovement (void)
if (pm->waterlevel != 2)
return;
- VectorMA (pml.origin, 30, flatforward, spot);
+ VectorMA(pml.origin, 30, flatforward, spot);
spot[2] += 4;
- cont = pm->pointcontents (spot);
+ cont = pm->pointcontents(spot);
if (!(cont & CONTENTS_SOLID))
return;
spot[2] += 16;
- cont = pm->pointcontents (spot);
+ cont = pm->pointcontents(spot);
if (cont)
return;
// jump out of water
- VectorScale (flatforward, 50, pml.velocity);
+ VectorScale(flatforward, 50, pml.velocity);
pml.velocity[2] = 350;
pm->s.pm_flags |= PMF_TIME_WATERJUMP;
@@ -828,7 +790,7 @@ static void PM_CheckSpecialMovement (void)
PM_FlyMove
===============
*/
-static void PM_FlyMove (void)
+static void PM_FlyMove(void)
{
float speed, drop, friction, control, newspeed;
float currentspeed, addspeed, accelspeed;
@@ -842,18 +804,15 @@ static void PM_FlyMove (void)
// friction
- speed = VectorLength (pml.velocity);
- if (speed < 1)
- {
- VectorCopy (vec3_origin, pml.velocity);
- }
- else
- {
+ speed = VectorLength(pml.velocity);
+ if (speed < 1) {
+ VectorCopy(vec3_origin, pml.velocity);
+ } else {
drop = 0;
friction = pmp->flyfriction;
control = speed < pm_stopspeed ? pm_stopspeed : speed;
- drop += control*friction*pml.frametime;
+ drop += control * friction * pml.frametime;
// scale the velocity
newspeed = speed - drop;
@@ -861,29 +820,28 @@ static void PM_FlyMove (void)
newspeed = 0;
newspeed /= speed;
- VectorScale (pml.velocity, newspeed, pml.velocity);
+ VectorScale(pml.velocity, newspeed, pml.velocity);
}
// accelerate
fmove = pm->cmd.forwardmove;
smove = pm->cmd.sidemove;
-
- VectorNormalize (pml.forward);
- VectorNormalize (pml.right);
- for (i=0 ; i<3 ; i++)
- wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove;
+ VectorNormalize(pml.forward);
+ VectorNormalize(pml.right);
+
+ for (i = 0; i < 3; i++)
+ wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove;
wishvel[2] += pm->cmd.upmove;
- VectorCopy (wishvel, wishdir);
+ VectorCopy(wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
//
// clamp to server defined max speed
//
- if (wishspeed > pmp->maxspeed)
- {
- VectorScale (wishvel, pmp->maxspeed / wishspeed, wishvel);
+ if (wishspeed > pmp->maxspeed) {
+ VectorScale(wishvel, pmp->maxspeed / wishspeed, wishvel);
wishspeed = pmp->maxspeed;
}
@@ -894,27 +852,27 @@ static void PM_FlyMove (void)
return; // original buggy behaviour
}
} else {
- accelspeed = pm_accelerate*pml.frametime*wishspeed;
+ accelspeed = pm_accelerate * pml.frametime * wishspeed;
if (accelspeed > addspeed)
accelspeed = addspeed;
-
- for (i=0 ; i<3 ; i++)
- pml.velocity[i] += accelspeed*wishdir[i];
+
+ for (i = 0; i < 3; i++)
+ pml.velocity[i] += accelspeed * wishdir[i];
}
#if 0
if (doclip) {
- for (i=0 ; i<3 ; i++)
+ for (i = 0; i < 3; i++)
end[i] = pml.origin[i] + pml.frametime * pml.velocity[i];
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, end);
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, end);
- VectorCopy (trace.endpos, pml.origin);
+ VectorCopy(trace.endpos, pml.origin);
} else
#endif
{
// move
- VectorMA (pml.origin, pml.frametime, pml.velocity, pml.origin);
+ VectorMA(pml.origin, pml.frametime, pml.velocity, pml.origin);
}
}
@@ -926,7 +884,7 @@ PM_CheckDuck
Sets mins, maxs, and pm->viewheight
==============
*/
-static void PM_CheckDuck (void)
+static void PM_CheckDuck(void)
{
trace_t trace;
@@ -936,8 +894,7 @@ static void PM_CheckDuck (void)
pm->maxs[0] = 16;
pm->maxs[1] = 16;
- if (pm->s.pm_type == PM_GIB)
- {
+ if (pm->s.pm_type == PM_GIB) {
pm->mins[2] = 0;
pm->maxs[2] = 16;
pm->viewheight = 8;
@@ -946,33 +903,26 @@ static void PM_CheckDuck (void)
pm->mins[2] = -24;
- if (pm->s.pm_type == PM_DEAD)
- {
+ if (pm->s.pm_type == PM_DEAD) {
pm->s.pm_flags |= PMF_DUCKED;
- }
- else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND) )
- { // duck
+ } else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND)) {
+ // duck
pm->s.pm_flags |= PMF_DUCKED;
- }
- else
- { // stand up if possible
- if (pm->s.pm_flags & PMF_DUCKED)
- {
+ } else {
+ // stand up if possible
+ if (pm->s.pm_flags & PMF_DUCKED) {
// try to stand up
pm->maxs[2] = 32;
- trace = pm->trace (pml.origin, pm->mins, pm->maxs, pml.origin);
+ trace = pm->trace(pml.origin, pm->mins, pm->maxs, pml.origin);
if (!trace.allsolid)
pm->s.pm_flags &= ~PMF_DUCKED;
}
}
- if (pm->s.pm_flags & PMF_DUCKED)
- {
+ if (pm->s.pm_flags & PMF_DUCKED) {
pm->maxs[2] = 4;
pm->viewheight = -2;
- }
- else
- {
+ } else {
pm->maxs[2] = 32;
pm->viewheight = 22;
}
@@ -984,7 +934,7 @@ static void PM_CheckDuck (void)
PM_DeadMove
==============
*/
-static void PM_DeadMove (void)
+static void PM_DeadMove(void)
{
float forward;
@@ -993,21 +943,18 @@ static void PM_DeadMove (void)
// extra friction
- forward = VectorLength (pml.velocity);
+ forward = VectorLength(pml.velocity);
forward -= 20;
- if (forward <= 0)
- {
- VectorClear (pml.velocity);
- }
- else
- {
- VectorNormalize (pml.velocity);
- VectorScale (pml.velocity, forward, pml.velocity);
+ if (forward <= 0) {
+ VectorClear(pml.velocity);
+ } else {
+ VectorNormalize(pml.velocity);
+ VectorScale(pml.velocity, forward, pml.velocity);
}
}
-static qboolean PM_GoodPosition (void)
+static qboolean PM_GoodPosition(void)
{
trace_t trace;
vec3_t origin, end;
@@ -1016,9 +963,9 @@ static qboolean PM_GoodPosition (void)
if (pm->s.pm_type == PM_SPECTATOR)
return qtrue;
- for (i=0 ; i<3 ; i++)
- origin[i] = end[i] = pm->s.origin[i]*0.125;
- trace = pm->trace (origin, pm->mins, pm->maxs, end);
+ for (i = 0; i < 3; i++)
+ origin[i] = end[i] = pm->s.origin[i] * 0.125;
+ trace = pm->trace(origin, pm->mins, pm->maxs, end);
return !trace.allsolid;
}
@@ -1031,45 +978,43 @@ On exit, the origin will have a value that is pre-quantized to the 0.125
precision of the network channel and in a valid position.
================
*/
-static void PM_SnapPosition (void)
+static void PM_SnapPosition(void)
{
int sign[3];
int i, j, bits;
short base[3];
// try all single bits first
- static const byte jitterbits[8] = {0,4,1,2,3,5,6,7};
+ static const byte jitterbits[8] = {0, 4, 1, 2, 3, 5, 6, 7};
// snap velocity to eigths
- for (i=0 ; i<3 ; i++)
- pm->s.velocity[i] = (int)(pml.velocity[i]*8);
+ for (i = 0; i < 3; i++)
+ pm->s.velocity[i] = (int)(pml.velocity[i] * 8);
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
if (pml.origin[i] >= 0)
sign[i] = 1;
- else
+ else
sign[i] = -1;
- pm->s.origin[i] = (int)(pml.origin[i]*8);
- if (pm->s.origin[i]*0.125f == pml.origin[i])
+ pm->s.origin[i] = (int)(pml.origin[i] * 8);
+ if (pm->s.origin[i] * 0.125f == pml.origin[i])
sign[i] = 0;
}
- VectorCopy (pm->s.origin, base);
+ VectorCopy(pm->s.origin, base);
// try all combinations
- for (j=0 ; j<8 ; j++)
- {
+ for (j = 0; j < 8; j++) {
bits = jitterbits[j];
- VectorCopy (base, pm->s.origin);
- for (i=0 ; i<3 ; i++)
- if (bits & (1<<i) )
+ VectorCopy(base, pm->s.origin);
+ for (i = 0; i < 3; i++)
+ if (bits & (1 << i))
pm->s.origin[i] += sign[i];
- if (PM_GoodPosition ())
+ if (PM_GoodPosition())
return;
}
// go back to the last position
- VectorCopy( pml.previous_origin, pm->s.origin );
+ VectorCopy(pml.previous_origin, pm->s.origin);
}
#if 0
@@ -1080,34 +1025,33 @@ void PM_HackedSnapPosition(void)
static const int offset[3] = { 0, -1, 1 };
int i;
-
// snap velocity to eigths
- for (i=0 ; i<3 ; i++)
- pm->s.velocity[i] = Q_rint(pml.velocity[i]*8);
-
- for (i=0 ; i<3 ; i++)
- pm->s.origin[i] = Q_rint(pml.origin[i]*8);
-
- VectorCopy (pm->s.origin, base);
-
- for ( z = 0; z < 3; z++ ) {
- pm->s.origin[2] = base[2] + offset[ z ];
- for ( y = 0; y < 3; y++ ) {
- pm->s.origin[1] = base[1] + offset[ y ];
- for ( x = 0; x < 3; x++ ) {
- pm->s.origin[0] = base[0] + offset[ x ];
- if (PM_GoodPosition ()) {
- pml.origin[0] = pm->s.origin[0]*0.125;
- pml.origin[1] = pm->s.origin[1]*0.125;
- pml.origin[2] = pm->s.origin[2]*0.125;
- VectorCopy( pm->s.origin, pml.previous_origin );
+ for (i = 0; i < 3; i++)
+ pm->s.velocity[i] = Q_rint(pml.velocity[i] * 8);
+
+ for (i = 0; i < 3; i++)
+ pm->s.origin[i] = Q_rint(pml.origin[i] * 8);
+
+ VectorCopy(pm->s.origin, base);
+
+ for (z = 0; z < 3; z++) {
+ pm->s.origin[2] = base[2] + offset[z];
+ for (y = 0; y < 3; y++) {
+ pm->s.origin[1] = base[1] + offset[y];
+ for (x = 0; x < 3; x++) {
+ pm->s.origin[0] = base[0] + offset[x];
+ if (PM_GoodPosition()) {
+ pml.origin[0] = pm->s.origin[0] * 0.125;
+ pml.origin[1] = pm->s.origin[1] * 0.125;
+ pml.origin[2] = pm->s.origin[2] * 0.125;
+ VectorCopy(pm->s.origin, pml.previous_origin);
return;
}
}
}
}
- VectorCopy( pml.previous_origin, pm->s.origin );
+ VectorCopy(pml.previous_origin, pm->s.origin);
}
#endif
@@ -1125,19 +1069,19 @@ static void PM_InitialSnapPosition(void)
short base[3];
static const short offset[3] = { 0, -1, 1 };
- VectorCopy (pm->s.origin, base);
-
- for ( z = 0; z < 3; z++ ) {
- pm->s.origin[2] = base[2] + offset[ z ];
- for ( y = 0; y < 3; y++ ) {
- pm->s.origin[1] = base[1] + offset[ y ];
- for ( x = 0; x < 3; x++ ) {
- pm->s.origin[0] = base[0] + offset[ x ];
- if (PM_GoodPosition ()) {
- pml.origin[0] = pm->s.origin[0]*0.125;
- pml.origin[1] = pm->s.origin[1]*0.125;
- pml.origin[2] = pm->s.origin[2]*0.125;
- VectorCopy( pm->s.origin, pml.previous_origin );
+ VectorCopy(pm->s.origin, base);
+
+ for (z = 0; z < 3; z++) {
+ pm->s.origin[2] = base[2] + offset[z];
+ for (y = 0; y < 3; y++) {
+ pm->s.origin[1] = base[1] + offset[y];
+ for (x = 0; x < 3; x++) {
+ pm->s.origin[0] = base[0] + offset[x];
+ if (PM_GoodPosition()) {
+ pml.origin[0] = pm->s.origin[0] * 0.125;
+ pml.origin[1] = pm->s.origin[1] * 0.125;
+ pml.origin[2] = pm->s.origin[2] * 0.125;
+ VectorCopy(pm->s.origin, pml.previous_origin);
return;
}
}
@@ -1151,22 +1095,18 @@ PM_ClampAngles
================
*/
-static void PM_ClampAngles (void)
+static void PM_ClampAngles(void)
{
short temp;
int i;
- if (pm->s.pm_flags & PMF_TIME_TELEPORT)
- {
+ if (pm->s.pm_flags & PMF_TIME_TELEPORT) {
pm->viewangles[YAW] = SHORT2ANGLE(pm->cmd.angles[YAW] + pm->s.delta_angles[YAW]);
pm->viewangles[PITCH] = 0;
pm->viewangles[ROLL] = 0;
- }
- else
- {
+ } else {
// circularly clamp the angles with deltas
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
temp = pm->cmd.angles[i] + pm->s.delta_angles[i];
pm->viewangles[i] = SHORT2ANGLE(temp);
}
@@ -1177,7 +1117,7 @@ static void PM_ClampAngles (void)
else if (pm->viewangles[PITCH] < 271 && pm->viewangles[PITCH] >= 180)
pm->viewangles[PITCH] = 271;
}
- AngleVectors (pm->viewangles, pml.forward, pml.right, pml.up);
+ AngleVectors(pm->viewangles, pml.forward, pml.right, pml.up);
}
/*
@@ -1187,43 +1127,41 @@ Pmove
Can be called by either the server or the client
================
*/
-void Pmove( pmove_t *pmove, pmoveParams_t *params )
+void Pmove(pmove_t *pmove, pmoveParams_t *params)
{
pm = pmove;
pmp = params;
// clear results
pm->numtouch = 0;
- VectorClear (pm->viewangles);
+ VectorClear(pm->viewangles);
pm->viewheight = 0;
pm->groundentity = NULL;
pm->watertype = 0;
pm->waterlevel = 0;
// clear all pmove local vars
- memset (&pml, 0, sizeof(pml));
+ memset(&pml, 0, sizeof(pml));
// convert origin and velocity to float values
- VectorScale( pm->s.origin, 0.125f, pml.origin );
- VectorScale( pm->s.velocity, 0.125f, pml.velocity );
+ VectorScale(pm->s.origin, 0.125f, pml.origin);
+ VectorScale(pm->s.velocity, 0.125f, pml.velocity);
// save old org in case we get stuck
- VectorCopy (pm->s.origin, pml.previous_origin);
+ VectorCopy(pm->s.origin, pml.previous_origin);
- PM_ClampAngles ();
+ PM_ClampAngles();
- if (pm->s.pm_type == PM_SPECTATOR)
- {
+ if (pm->s.pm_type == PM_SPECTATOR) {
pml.frametime = pmp->speedmult * pm->cmd.msec * 0.001f;
- PM_FlyMove ();
- PM_SnapPosition ();
+ PM_FlyMove();
+ PM_SnapPosition();
return;
}
pml.frametime = pm->cmd.msec * 0.001f;
- if (pm->s.pm_type >= PM_DEAD)
- {
+ if (pm->s.pm_type >= PM_DEAD) {
pm->cmd.forwardmove = 0;
pm->cmd.sidemove = 0;
pm->cmd.upmove = 0;
@@ -1233,58 +1171,52 @@ void Pmove( pmove_t *pmove, pmoveParams_t *params )
return; // no movement at all
// set mins, maxs, and viewheight
- PM_CheckDuck ();
+ PM_CheckDuck();
if (pm->snapinitial)
- PM_InitialSnapPosition ();
+ PM_InitialSnapPosition();
// set groundentity, watertype, and waterlevel
- PM_CategorizePosition ();
+ PM_CategorizePosition();
if (pm->s.pm_type == PM_DEAD)
- PM_DeadMove ();
+ PM_DeadMove();
- PM_CheckSpecialMovement ();
+ PM_CheckSpecialMovement();
// drop timing counter
- if (pm->s.pm_time)
- {
+ if (pm->s.pm_time) {
int msec;
msec = pm->cmd.msec >> 3;
if (!msec)
msec = 1;
- if ( msec >= pm->s.pm_time)
- {
+ if (msec >= pm->s.pm_time) {
pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_time = 0;
- }
- else
+ } else
pm->s.pm_time -= msec;
}
- if (pm->s.pm_flags & PMF_TIME_TELEPORT)
- { // teleport pause stays exactly in place
- }
- else if (pm->s.pm_flags & PMF_TIME_WATERJUMP)
- { // waterjump has no control, but falls
+ if (pm->s.pm_flags & PMF_TIME_TELEPORT) {
+ // teleport pause stays exactly in place
+ } else if (pm->s.pm_flags & PMF_TIME_WATERJUMP) {
+ // waterjump has no control, but falls
pml.velocity[2] -= pm->s.gravity * pml.frametime;
- if (pml.velocity[2] < 0)
- { // cancel as soon as we are falling down again
+ if (pml.velocity[2] < 0) {
+ // cancel as soon as we are falling down again
pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_time = 0;
}
- PM_StepSlideMove ();
- }
- else
- {
- PM_CheckJump ();
+ PM_StepSlideMove();
+ } else {
+ PM_CheckJump();
- PM_Friction ();
+ PM_Friction();
if (pm->waterlevel >= 2)
- PM_WaterMove ();
+ PM_WaterMove();
else {
vec3_t angles;
@@ -1293,21 +1225,22 @@ void Pmove( pmove_t *pmove, pmoveParams_t *params )
angles[PITCH] = angles[PITCH] - 360;
angles[PITCH] /= 3;
- AngleVectors (angles, pml.forward, pml.right, pml.up);
+ AngleVectors(angles, pml.forward, pml.right, pml.up);
- PM_AirMove ();
+ PM_AirMove();
}
}
// set groundentity, watertype, and waterlevel for final spot
- PM_CategorizePosition ();
+ PM_CategorizePosition();
- PM_SnapPosition ();
+ PM_SnapPosition();
}
-void PmoveInit( pmoveParams_t *pmp ) {
+void PmoveInit(pmoveParams_t *pmp)
+{
// set up default pmove parameters
- memset( pmp, 0, sizeof( *pmp ) );
+ memset(pmp, 0, sizeof(*pmp));
pmp->speedmult = 1;
pmp->watermult = 0.5f;
@@ -1317,11 +1250,12 @@ void PmoveInit( pmoveParams_t *pmp ) {
pmp->flyfriction = 9;
}
-void PmoveEnableQW( pmoveParams_t *pmp ) {
+void PmoveEnableQW(pmoveParams_t *pmp)
+{
pmp->qwmode = qtrue;
pmp->watermult = 0.7f;
pmp->maxspeed = 320;
- //pmp->upspeed = ( sv_qwmod->integer > 1 ) ? 310 : 350;
+ //pmp->upspeed = (sv_qwmod->integer > 1) ? 310 : 350;
pmp->friction = 4;
pmp->waterfriction = 4;
pmp->airaccelerate = qtrue;
diff --git a/src/pmove.h b/src/pmove.h
index 4104a59..93c4070 100644
--- a/src/pmove.h
+++ b/src/pmove.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -42,7 +42,7 @@ typedef struct {
float flyfriction;
} pmoveParams_t;
-void Pmove( pmove_t *pmove, pmoveParams_t *params );
+void Pmove(pmove_t *pmove, pmoveParams_t *params);
-void PmoveInit( pmoveParams_t *pmp );
-void PmoveEnableQW( pmoveParams_t *pmp );
+void PmoveInit(pmoveParams_t *pmp);
+void PmoveEnableQW(pmoveParams_t *pmp);
diff --git a/src/prompt.c b/src/prompt.c
index 2bb7a7e..04e4350 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -30,8 +30,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static cvar_t *com_completion_mode;
static cvar_t *com_completion_treshold;
-static void Prompt_ShowMatches( commandPrompt_t *prompt, char **matches,
- int start, int end )
+static void Prompt_ShowMatches(commandPrompt_t *prompt, char **matches,
+ int start, int end)
{
int count = end - start;
int numCols = 7, numLines;
@@ -43,49 +43,49 @@ static void Prompt_ShowMatches( commandPrompt_t *prompt, char **matches,
// determine number of columns needed
do {
numCols--;
- numLines = ceil( ( float )count / numCols );
+ numLines = ceil((float)count / numCols);
total = 0;
- for( i = 0; i < numCols; i++ ) {
+ for (i = 0; i < numCols; i++) {
k = start + numLines * i;
- if( k >= end ) {
+ if (k >= end) {
break;
}
maxlen = 0;
- for( j = k; j < k + numLines && j < end; j++ ) {
- len = strlen( matches[j] );
- if( maxlen < len ) {
+ for (j = k; j < k + numLines && j < end; j++) {
+ len = strlen(matches[j]);
+ if (maxlen < len) {
maxlen = len;
}
}
maxlen += 2; // account for intercolumn spaces
- if( maxlen > prompt->widthInChars ) {
+ if (maxlen > prompt->widthInChars) {
maxlen = prompt->widthInChars;
}
colwidths[i] = maxlen;
total += maxlen;
}
- if( total < prompt->widthInChars ) {
+ if (total < prompt->widthInChars) {
break; // this number of columns does fit
}
- } while( numCols > 1 );
+ } while (numCols > 1);
- for( i = 0; i < numLines; i++ ) {
- for( j = 0; j < numCols; j++ ) {
+ for (i = 0; i < numLines; i++) {
+ for (j = 0; j < numCols; j++) {
k = start + j * numLines + i;
- if( k >= end ) {
+ if (k >= end) {
break;
}
match = matches[k];
- prompt->printf( "%s", match );
- len = strlen( match );
- if( len < colwidths[j] ) {
+ prompt->printf("%s", match);
+ len = strlen(match);
+ if (len < colwidths[j]) {
// pad with spaces
- for( k = 0; k < colwidths[j] - len; k++ ) {
- prompt->printf( " " );
+ for (k = 0; k < colwidths[j] - len; k++) {
+ prompt->printf(" ");
}
}
}
- prompt->printf( "\n" );
+ prompt->printf("\n");
}
}
@@ -94,84 +94,87 @@ static void Prompt_ShowIndividualMatches(
char **matches,
int numCommands,
int numAliases,
- int numCvars )
+ int numCvars)
{
int offset = 0;
- if( numCommands ) {
- qsort( matches + offset, numCommands, sizeof( matches[0] ), SortStrcmp );
+ if (numCommands) {
+ qsort(matches + offset, numCommands, sizeof(matches[0]), SortStrcmp);
- prompt->printf( "\n%i possible command%s:\n",
- numCommands, numCommands != 1 ? "s" : "" );
+ prompt->printf("\n%i possible command%s:\n",
+ numCommands, numCommands != 1 ? "s" : "");
- Prompt_ShowMatches( prompt, matches, offset, offset + numCommands );
+ Prompt_ShowMatches(prompt, matches, offset, offset + numCommands);
offset += numCommands;
}
- if( numCvars ) {
- qsort( matches + offset, numCvars, sizeof( matches[0] ), SortStrcmp );
+ if (numCvars) {
+ qsort(matches + offset, numCvars, sizeof(matches[0]), SortStrcmp);
- prompt->printf( "\n%i possible variable%s:\n",
- numCvars, numCvars != 1 ? "s" : "" );
+ prompt->printf("\n%i possible variable%s:\n",
+ numCvars, numCvars != 1 ? "s" : "");
- Prompt_ShowMatches( prompt, matches, offset, offset + numCvars );
+ Prompt_ShowMatches(prompt, matches, offset, offset + numCvars);
offset += numCvars;
}
- if( numAliases ) {
- qsort( matches + offset, numAliases, sizeof( matches[0] ), SortStrcmp );
+ if (numAliases) {
+ qsort(matches + offset, numAliases, sizeof(matches[0]), SortStrcmp);
- prompt->printf( "\n%i possible alias%s:\n",
- numAliases, numAliases != 1 ? "es" : "" );
+ prompt->printf("\n%i possible alias%s:\n",
+ numAliases, numAliases != 1 ? "es" : "");
- Prompt_ShowMatches( prompt, matches, offset, offset + numAliases );
+ Prompt_ShowMatches(prompt, matches, offset, offset + numAliases);
offset += numAliases;
}
}
-static qboolean find_dup( genctx_t *ctx, const char *s ) {
+static qboolean find_dup(genctx_t *ctx, const char *s)
+{
int i, r;
- for( i = 0; i < ctx->count; i++ ) {
- if( ctx->ignorecase )
- r = Q_strcasecmp( ctx->matches[i], s );
+ for (i = 0; i < ctx->count; i++) {
+ if (ctx->ignorecase)
+ r = Q_strcasecmp(ctx->matches[i], s);
else
- r = strcmp( ctx->matches[i], s );
+ r = strcmp(ctx->matches[i], s);
- if( !r )
+ if (!r)
return qtrue;
}
return qfalse;
}
-qboolean Prompt_AddMatch( genctx_t *ctx, const char *s ) {
+qboolean Prompt_AddMatch(genctx_t *ctx, const char *s)
+{
int r;
- if( ctx->count >= ctx->size )
+ if (ctx->count >= ctx->size)
return qfalse;
- if( ctx->ignorecase )
- r = Q_strncasecmp( ctx->partial, s, ctx->length );
+ if (ctx->ignorecase)
+ r = Q_strncasecmp(ctx->partial, s, ctx->length);
else
- r = strncmp( ctx->partial, s, ctx->length );
+ r = strncmp(ctx->partial, s, ctx->length);
- if( r )
+ if (r)
return qtrue;
- if( ctx->ignoredups && find_dup( ctx, s ) )
+ if (ctx->ignoredups && find_dup(ctx, s))
return qtrue;
- ctx->matches[ctx->count++] = Z_CopyString( s );
+ ctx->matches[ctx->count++] = Z_CopyString(s);
return qtrue;
}
-static qboolean needs_quotes( const char *s ) {
+static qboolean needs_quotes(const char *s)
+{
int c;
- while( *s ) {
+ while (*s) {
c = *s++;
- if( c == '$' || c == ';' || !Q_isgraph( c ) ) {
+ if (c == '$' || c == ';' || !Q_isgraph(c)) {
return qtrue;
}
}
@@ -184,7 +187,8 @@ static qboolean needs_quotes( const char *s ) {
Prompt_CompleteCommand
====================
*/
-void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
+void Prompt_CompleteCommand(commandPrompt_t *prompt, qboolean backslash)
+{
inputField_t *inputLine = &prompt->inputLine;
char *text, *partial, *s;
int i, argc, currentArg, argnum;
@@ -199,9 +203,9 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
pos = inputLine->cursorPos;
// prepend backslash if missing
- if( backslash ) {
- if( inputLine->text[0] != '\\' && inputLine->text[0] != '/' ) {
- memmove( inputLine->text + 1, inputLine->text, size - 1 );
+ if (backslash) {
+ if (inputLine->text[0] != '\\' && inputLine->text[0] != '/') {
+ memmove(inputLine->text + 1, inputLine->text, size - 1);
inputLine->text[0] = '\\';
}
text++;
@@ -210,94 +214,94 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
}
// parse the input line into tokens
- Cmd_TokenizeString( text, qfalse );
+ Cmd_TokenizeString(text, qfalse);
argc = Cmd_Argc();
// determine absolute argument number to be completed
- currentArg = Cmd_FindArgForOffset( pos );
- if( currentArg == argc - 1 && Cmd_WhiteSpaceTail() ) {
+ currentArg = Cmd_FindArgForOffset(pos);
+ if (currentArg == argc - 1 && Cmd_WhiteSpaceTail()) {
// start completing new argument if command line has trailing whitespace
currentArg++;
}
// determine relative argument number to be completed
argnum = 0;
- for( i = 0; i < currentArg; i++ ) {
- s = Cmd_Argv( i );
+ for (i = 0; i < currentArg; i++) {
+ s = Cmd_Argv(i);
argnum++;
- if( *s == ';' ) {
+ if (*s == ';') {
// semicolon starts a new command
argnum = 0;
}
}
// get the partial argument string to be completed
- partial = Cmd_Argv( currentArg );
- if( *partial == ';' ) {
+ partial = Cmd_Argv(currentArg);
+ if (*partial == ';') {
// semicolon starts a new command
currentArg++;
- partial = Cmd_Argv( currentArg );
+ partial = Cmd_Argv(currentArg);
argnum = 0;
}
// generate matches
- memset( &ctx, 0, sizeof( ctx ) );
+ memset(&ctx, 0, sizeof(ctx));
ctx.partial = partial;
- ctx.length = strlen( partial );
+ ctx.length = strlen(partial);
ctx.argnum = currentArg;
ctx.matches = matches;
ctx.size = MAX_MATCHES;
- if( argnum ) {
+ if (argnum) {
// complete a command/cvar argument
- Com_Generic_c( &ctx, argnum );
+ Com_Generic_c(&ctx, argnum);
numCommands = numCvars = numAliases = 0;
} else {
// complete a command/cvar/alias name
- Cmd_Command_g( &ctx );
+ Cmd_Command_g(&ctx);
numCommands = ctx.count;
- Cvar_Variable_g( &ctx );
+ Cvar_Variable_g(&ctx);
numCvars = ctx.count - numCommands;
- Cmd_Alias_g( &ctx );
+ Cmd_Alias_g(&ctx);
numAliases = ctx.count - numCvars - numCommands;
}
- if( !ctx.count ) {
- pos = strlen( inputLine->text );
+ if (!ctx.count) {
+ pos = strlen(inputLine->text);
prompt->tooMany = qfalse;
goto finish2; // nothing found
}
- pos = Cmd_ArgOffset( currentArg );
+ pos = Cmd_ArgOffset(currentArg);
text += pos;
size -= pos;
// append whitespace since Cmd_TokenizeString eats it
- if( currentArg == argc && Cmd_WhiteSpaceTail() ) {
+ if (currentArg == argc && Cmd_WhiteSpaceTail()) {
*text++ = ' ';
pos++;
size--;
}
- if( ctx.count == 1 ) {
+ if (ctx.count == 1) {
// we have finished completion!
- s = Cmd_RawArgsFrom( currentArg + 1 );
- if( needs_quotes( matches[0] ) ) {
- pos += Q_concat( text, size, "\"", matches[0], "\" ", s, NULL );
+ s = Cmd_RawArgsFrom(currentArg + 1);
+ if (needs_quotes(matches[0])) {
+ pos += Q_concat(text, size, "\"", matches[0], "\" ", s, NULL);
} else {
- pos += Q_concat( text, size, matches[0], " ", s, NULL );
+ pos += Q_concat(text, size, matches[0], " ", s, NULL);
}
pos++;
prompt->tooMany = qfalse;
goto finish1;
}
- if( ctx.count > com_completion_treshold->integer && !prompt->tooMany ) {
- prompt->printf( "Press TAB again to display all %d possibilities.\n", ctx.count );
- pos = strlen( inputLine->text );
+ if (ctx.count > com_completion_treshold->integer && !prompt->tooMany) {
+ prompt->printf("Press TAB again to display all %d possibilities.\n", ctx.count);
+ pos = strlen(inputLine->text);
prompt->tooMany = qtrue;
goto finish1;
}
@@ -305,101 +309,102 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
prompt->tooMany = qfalse;
// sort matches alphabethically
- for( i = 0; i < ctx.count; i++ ) {
+ for (i = 0; i < ctx.count; i++) {
sortedMatches[i] = matches[i];
}
- qsort( sortedMatches, ctx.count, sizeof( sortedMatches[0] ),
- ctx.ignorecase ? SortStricmp : SortStrcmp );
+ qsort(sortedMatches, ctx.count, sizeof(sortedMatches[0]),
+ ctx.ignorecase ? SortStricmp : SortStrcmp);
// copy matching part
first = sortedMatches[0];
- last = sortedMatches[ ctx.count - 1 ];
+ last = sortedMatches[ctx.count - 1];
len = 0;
do {
- if( *first != *last ) {
- if( !ctx.ignorecase || Q_tolower( *first ) != Q_tolower( *last ) ) {
+ if (*first != *last) {
+ if (!ctx.ignorecase || Q_tolower(*first) != Q_tolower(*last)) {
break;
}
}
text[len++] = *first;
- if( len == size - 1 ) {
+ if (len == size - 1) {
break;
}
first++;
last++;
- } while( *first );
+ } while (*first);
text[len] = 0;
pos += len;
size -= len;
// copy trailing arguments
- if( currentArg + 1 < argc ) {
- s = Cmd_RawArgsFrom( currentArg + 1 );
- pos += Q_concat( text + len, size, " ", s, NULL );
+ if (currentArg + 1 < argc) {
+ s = Cmd_RawArgsFrom(currentArg + 1);
+ pos += Q_concat(text + len, size, " ", s, NULL);
}
pos++;
- prompt->printf( "]\\%s\n", Cmd_ArgsFrom( 0 ) );
- if( argnum ) {
+ prompt->printf("]\\%s\n", Cmd_ArgsFrom(0));
+ if (argnum) {
goto multi;
}
-
- switch( com_completion_mode->integer ) {
+
+ switch (com_completion_mode->integer) {
case 0:
// print in solid list
- for( i = 0 ; i < ctx.count; i++ ) {
- prompt->printf( "%s\n", sortedMatches[i] );
+ for (i = 0; i < ctx.count; i++) {
+ prompt->printf("%s\n", sortedMatches[i]);
}
break;
case 1:
- multi:
+multi:
// print in multiple columns
- Prompt_ShowMatches( prompt, sortedMatches, 0, ctx.count );
+ Prompt_ShowMatches(prompt, sortedMatches, 0, ctx.count);
break;
case 2:
default:
// resort matches by type and print in multiple columns
- Prompt_ShowIndividualMatches( prompt, matches, numCommands, numAliases, numCvars );
+ Prompt_ShowIndividualMatches(prompt, matches, numCommands, numAliases, numCvars);
break;
}
finish1:
// free matches
- for( i = 0; i < ctx.count; i++ ) {
- Z_Free( matches[i] );
+ for (i = 0; i < ctx.count; i++) {
+ Z_Free(matches[i]);
}
finish2:
// move cursor
- if( pos >= inputLine->maxChars ) {
+ if (pos >= inputLine->maxChars) {
pos = inputLine->maxChars - 1;
}
inputLine->cursorPos = pos;
}
-void Prompt_CompleteHistory( commandPrompt_t *prompt, qboolean forward ) {
+void Prompt_CompleteHistory(commandPrompt_t *prompt, qboolean forward)
+{
char *s, *m = NULL;
int i, j;
- if( !prompt->search ) {
+ if (!prompt->search) {
s = prompt->inputLine.text;
- if( *s == '/' || *s == '\\' ) {
+ if (*s == '/' || *s == '\\') {
s++;
}
- if( !*s ) {
+ if (!*s) {
return;
}
- prompt->search = Z_CopyString( s );
+ prompt->search = Z_CopyString(s);
}
- if( forward ) {
- for( i = prompt->historyLineNum + 1; i < prompt->inputLineNum; i++ ) {
+ if (forward) {
+ for (i = prompt->historyLineNum + 1; i < prompt->inputLineNum; i++) {
s = prompt->history[i & HISTORY_MASK];
- if( s && strstr( s, prompt->search ) ) {
- if( strcmp( s, prompt->inputLine.text ) ) {
+ if (s && strstr(s, prompt->search)) {
+ if (strcmp(s, prompt->inputLine.text)) {
m = s;
break;
}
@@ -407,13 +412,13 @@ void Prompt_CompleteHistory( commandPrompt_t *prompt, qboolean forward ) {
}
} else {
j = prompt->inputLineNum - HISTORY_SIZE;
- if( j < 0 ) {
+ if (j < 0) {
j = 0;
}
- for( i = prompt->historyLineNum - 1; i >= j; i-- ) {
+ for (i = prompt->historyLineNum - 1; i >= j; i--) {
s = prompt->history[i & HISTORY_MASK];
- if( s && strstr( s, prompt->search ) ) {
- if( strcmp( s, prompt->inputLine.text ) ) {
+ if (s && strstr(s, prompt->search)) {
+ if (strcmp(s, prompt->inputLine.text)) {
m = s;
break;
}
@@ -421,18 +426,19 @@ void Prompt_CompleteHistory( commandPrompt_t *prompt, qboolean forward ) {
}
}
- if( !m ) {
+ if (!m) {
return;
}
prompt->historyLineNum = i;
- IF_Replace( &prompt->inputLine, prompt->history[i & HISTORY_MASK] );
+ IF_Replace(&prompt->inputLine, prompt->history[i & HISTORY_MASK]);
}
-void Prompt_ClearState( commandPrompt_t *prompt ) {
+void Prompt_ClearState(commandPrompt_t *prompt)
+{
prompt->tooMany = qfalse;
- if( prompt->search ) {
- Z_Free( prompt->search );
+ if (prompt->search) {
+ Z_Free(prompt->search);
prompt->search = NULL;
}
}
@@ -444,24 +450,25 @@ Prompt_Action
User just pressed enter
====================
*/
-char *Prompt_Action( commandPrompt_t *prompt ) {
+char *Prompt_Action(commandPrompt_t *prompt)
+{
char *s = prompt->inputLine.text;
int i, j;
-
- Prompt_ClearState( prompt );
- if( s[0] == 0 || ( ( s[0] == '/' || s[0] == '\\' ) && s[1] == 0 ) ) {
- IF_Clear( &prompt->inputLine );
+
+ Prompt_ClearState(prompt);
+ if (s[0] == 0 || ((s[0] == '/' || s[0] == '\\') && s[1] == 0)) {
+ IF_Clear(&prompt->inputLine);
return NULL; // empty line
}
// save current line in history
i = prompt->inputLineNum & HISTORY_MASK;
- j = ( prompt->inputLineNum - 1 ) & HISTORY_MASK;
- if( !prompt->history[j] || strcmp( prompt->history[j], s ) ) {
- if( prompt->history[i] ) {
- Z_Free( prompt->history[i] );
+ j = (prompt->inputLineNum - 1) & HISTORY_MASK;
+ if (!prompt->history[j] || strcmp(prompt->history[j], s)) {
+ if (prompt->history[i]) {
+ Z_Free(prompt->history[i]);
}
- prompt->history[i] = Z_CopyString( s );
+ prompt->history[i] = Z_CopyString(s);
prompt->inputLineNum++;
} else {
i = j;
@@ -469,8 +476,8 @@ char *Prompt_Action( commandPrompt_t *prompt ) {
// stop history search
prompt->historyLineNum = prompt->inputLineNum;
-
- IF_Clear( &prompt->inputLine );
+
+ IF_Clear(&prompt->inputLine);
return prompt->history[i];
}
@@ -480,28 +487,28 @@ char *Prompt_Action( commandPrompt_t *prompt ) {
Prompt_HistoryUp
====================
*/
-void Prompt_HistoryUp( commandPrompt_t *prompt ) {
+void Prompt_HistoryUp(commandPrompt_t *prompt)
+{
int i;
- Prompt_ClearState( prompt );
+ Prompt_ClearState(prompt);
- if( prompt->historyLineNum == prompt->inputLineNum ) {
+ if (prompt->historyLineNum == prompt->inputLineNum) {
// save current line in history
i = prompt->inputLineNum & HISTORY_MASK;
- if( prompt->history[i] ) {
- Z_Free( prompt->history[i] );
+ if (prompt->history[i]) {
+ Z_Free(prompt->history[i]);
}
- prompt->history[i] = Z_CopyString( prompt->inputLine.text );
+ prompt->history[i] = Z_CopyString(prompt->inputLine.text);
}
- if( prompt->inputLineNum - prompt->historyLineNum < HISTORY_SIZE &&
- prompt->historyLineNum > 0 )
- {
+ if (prompt->inputLineNum - prompt->historyLineNum < HISTORY_SIZE &&
+ prompt->historyLineNum > 0) {
prompt->historyLineNum--;
}
i = prompt->historyLineNum & HISTORY_MASK;
- IF_Replace( &prompt->inputLine, prompt->history[i] );
+ IF_Replace(&prompt->inputLine, prompt->history[i]);
}
/*
@@ -509,19 +516,20 @@ void Prompt_HistoryUp( commandPrompt_t *prompt ) {
Prompt_HistoryDown
====================
*/
-void Prompt_HistoryDown( commandPrompt_t *prompt ) {
+void Prompt_HistoryDown(commandPrompt_t *prompt)
+{
int i;
- Prompt_ClearState( prompt );
+ Prompt_ClearState(prompt);
- if( prompt->historyLineNum == prompt->inputLineNum ) {
+ if (prompt->historyLineNum == prompt->inputLineNum) {
return;
}
-
+
prompt->historyLineNum++;
-
+
i = prompt->historyLineNum & HISTORY_MASK;
- IF_Replace( &prompt->inputLine, prompt->history[i] );
+ IF_Replace(&prompt->inputLine, prompt->history[i]);
}
/*
@@ -529,74 +537,77 @@ void Prompt_HistoryDown( commandPrompt_t *prompt ) {
Prompt_Clear
====================
*/
-void Prompt_Clear( commandPrompt_t *prompt ) {
+void Prompt_Clear(commandPrompt_t *prompt)
+{
int i;
- Prompt_ClearState( prompt );
-
- for( i = 0; i < HISTORY_SIZE; i++ ) {
- if( prompt->history[i] ) {
- Z_Free( prompt->history[i] );
+ Prompt_ClearState(prompt);
+
+ for (i = 0; i < HISTORY_SIZE; i++) {
+ if (prompt->history[i]) {
+ Z_Free(prompt->history[i]);
prompt->history[i] = NULL;
}
}
-
+
prompt->historyLineNum = 0;
prompt->inputLineNum = 0;
-
- IF_Clear( &prompt->inputLine );
+
+ IF_Clear(&prompt->inputLine);
}
-void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename, int lines ) {
+void Prompt_SaveHistory(commandPrompt_t *prompt, const char *filename, int lines)
+{
qhandle_t f;
char *s;
int i;
- FS_FOpenFile( filename, &f, FS_MODE_WRITE|FS_PATH_BASE );
- if( !f ) {
+ FS_FOpenFile(filename, &f, FS_MODE_WRITE | FS_PATH_BASE);
+ if (!f) {
return;
}
- if( lines > HISTORY_SIZE ) {
+ if (lines > HISTORY_SIZE) {
lines = HISTORY_SIZE;
}
i = prompt->inputLineNum - lines;
- if( i < 0 ) {
+ if (i < 0) {
i = 0;
}
- for( ; i < prompt->inputLineNum; i++ ) {
+ for (; i < prompt->inputLineNum; i++) {
s = prompt->history[i & HISTORY_MASK];
- if( s ) {
- FS_FPrintf( f, "%s\n", s );
+ if (s) {
+ FS_FPrintf(f, "%s\n", s);
}
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
}
-void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
+void Prompt_LoadHistory(commandPrompt_t *prompt, const char *filename)
+{
char buffer[MAX_FIELD_TEXT];
qhandle_t f;
int i;
ssize_t len;
- FS_FOpenFile( filename, &f, FS_MODE_READ|FS_TYPE_REAL|FS_PATH_BASE );
- if( !f ) {
+ FS_FOpenFile(filename, &f, FS_MODE_READ | FS_TYPE_REAL | FS_PATH_BASE);
+ if (!f) {
return;
}
- for( i = 0; i < HISTORY_SIZE; i++ ) {
- if( ( len = FS_ReadLine( f, buffer, sizeof( buffer ) ) ) < 1 ) {
+ for (i = 0; i < HISTORY_SIZE; i++) {
+ if ((len = FS_ReadLine(f, buffer, sizeof(buffer))) < 1) {
break;
}
- if( prompt->history[i] ) {
- Z_Free( prompt->history[i] );
+ if (prompt->history[i]) {
+ Z_Free(prompt->history[i]);
}
- prompt->history[i] = memcpy( Z_Malloc( len + 1 ), buffer, len + 1 );
+ prompt->history[i] = memcpy(Z_Malloc(len + 1), buffer, len + 1);
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
prompt->historyLineNum = i;
prompt->inputLineNum = i;
@@ -607,8 +618,9 @@ void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
Prompt_Init
====================
*/
-void Prompt_Init( void ) {
- com_completion_mode = Cvar_Get( "com_completion_mode", "1", 0 );
- com_completion_treshold = Cvar_Get( "com_completion_treshold", "50", 0 );
+void Prompt_Init(void)
+{
+ com_completion_mode = Cvar_Get("com_completion_mode", "1", 0);
+ com_completion_treshold = Cvar_Get("com_completion_treshold", "50", 0);
}
diff --git a/src/prompt.h b/src/prompt.h
index 9caf34f..3d9fed5 100644
--- a/src/prompt.h
+++ b/src/prompt.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#define HISTORY_SIZE 128
-#define HISTORY_MASK ( HISTORY_SIZE - 1 )
+#define HISTORY_MASK (HISTORY_SIZE - 1)
#define MAX_MATCHES 1024
#define MAX_PARTIAL 32
@@ -39,17 +39,17 @@ typedef struct commandPrompt_s {
int widthInChars;
qboolean tooMany;
- void (* q_printf( 1, 2 ) printf)( const char *fmt, ... );
+ void (* q_printf(1, 2) printf)(const char *fmt, ...);
} commandPrompt_t;
-void Prompt_Init( void );
-void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash );
-void Prompt_CompleteHistory( commandPrompt_t *prompt, qboolean forward );
-void Prompt_ClearState( commandPrompt_t *prompt );
-char *Prompt_Action( commandPrompt_t *prompt );
-void Prompt_HistoryUp( commandPrompt_t *prompt );
-void Prompt_HistoryDown( commandPrompt_t *prompt );
-void Prompt_Clear( commandPrompt_t *prompt );
-void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename, int lines );
-void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename );
+void Prompt_Init(void);
+void Prompt_CompleteCommand(commandPrompt_t *prompt, qboolean backslash);
+void Prompt_CompleteHistory(commandPrompt_t *prompt, qboolean forward);
+void Prompt_ClearState(commandPrompt_t *prompt);
+char *Prompt_Action(commandPrompt_t *prompt);
+void Prompt_HistoryUp(commandPrompt_t *prompt);
+void Prompt_HistoryDown(commandPrompt_t *prompt);
+void Prompt_Clear(commandPrompt_t *prompt);
+void Prompt_SaveHistory(commandPrompt_t *prompt, const char *filename, int lines);
+void Prompt_LoadHistory(commandPrompt_t *prompt, const char *filename);
diff --git a/src/protocol.h b/src/protocol.h
index bd00c41..f0d18c9 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -49,40 +49,40 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define PROTOCOL_VERSION_MVD_CURRENT 2010 // r177
#define R1Q2_SUPPORTED(x) \
- ((x)>=PROTOCOL_VERSION_R1Q2_MINIMUM && \
- (x)<=PROTOCOL_VERSION_R1Q2_CURRENT)
+ ((x) >= PROTOCOL_VERSION_R1Q2_MINIMUM && \
+ (x) <= PROTOCOL_VERSION_R1Q2_CURRENT)
#define Q2PRO_SUPPORTED(x) \
- ((x)>=PROTOCOL_VERSION_Q2PRO_MINIMUM && \
- (x)<=PROTOCOL_VERSION_Q2PRO_CURRENT)
+ ((x) >= PROTOCOL_VERSION_Q2PRO_MINIMUM && \
+ (x) <= PROTOCOL_VERSION_Q2PRO_CURRENT)
#define MVD_SUPPORTED(x) \
- ((x)>=PROTOCOL_VERSION_MVD_MINIMUM && \
- (x)<=PROTOCOL_VERSION_MVD_CURRENT)
+ ((x) >= PROTOCOL_VERSION_MVD_MINIMUM && \
+ (x) <= PROTOCOL_VERSION_MVD_CURRENT)
//=========================================
#define UPDATE_BACKUP 16 // copies of entity_state_t to keep buffered
// must be power of two
-#define UPDATE_MASK (UPDATE_BACKUP-1)
+#define UPDATE_MASK (UPDATE_BACKUP - 1)
#define CMD_BACKUP 128 // allow a lot of command backups for very fast systems
// increased from 64
-#define CMD_MASK (CMD_BACKUP-1)
+#define CMD_MASK (CMD_BACKUP - 1)
#define SVCMD_BITS 5
-#define SVCMD_MASK ((1<<SVCMD_BITS)-1)
+#define SVCMD_MASK ((1 << SVCMD_BITS) - 1)
#define FRAMENUM_BITS 27
-#define FRAMENUM_MASK ((1<<FRAMENUM_BITS)-1)
+#define FRAMENUM_MASK ((1 << FRAMENUM_BITS) - 1)
#define SURPRESSCOUNT_BITS 4
-#define SURPRESSCOUNT_MASK ((1<<SURPRESSCOUNT_BITS)-1)
+#define SURPRESSCOUNT_MASK ((1 << SURPRESSCOUNT_BITS) - 1)
#define MAX_PACKET_ENTITIES 128
#define MAX_PARSE_ENTITIES 2048 // should be MAX_PACKET_ENTITIES * UPDATE_BACKUP
-#define PARSE_ENTITIES_MASK (MAX_PARSE_ENTITIES-1)
+#define PARSE_ENTITIES_MASK (MAX_PARSE_ENTITIES - 1)
#define MAX_PACKET_USERCMDS 32
#define MAX_PACKET_FRAMES 4
@@ -90,8 +90,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAX_PACKET_STRINGCMDS 8
#define MAX_PACKET_USERINFOS 8
-#define CS_BITMAP_BYTES (MAX_CONFIGSTRINGS/8) // 260
-#define CS_BITMAP_LONGS (CS_BITMAP_BYTES/4 )
+#define CS_BITMAP_BYTES (MAX_CONFIGSTRINGS / 8) // 260
+#define CS_BITMAP_LONGS (CS_BITMAP_BYTES / 4)
#define MVD_MAGIC MakeRawLong('M','V','D','2')
@@ -118,7 +118,7 @@ typedef enum {
// should be \n terminated
svc_serverdata, // [long] protocol ...
svc_configstring, // [short] [string]
- svc_spawnbaseline,
+ svc_spawnbaseline,
svc_centerprint, // [string] to put in center of the screen
svc_download, // [short] size [size bytes]
svc_playerinfo, // variable
@@ -177,7 +177,7 @@ typedef enum {
//
typedef enum {
clc_bad,
- clc_nop,
+ clc_nop,
clc_move, // [usercmd_t]
clc_userinfo, // [userinfo string]
clc_stringcmd, // [string] message
@@ -332,8 +332,8 @@ typedef enum {
// ==============================================================
-#define CLIENTNUM_NONE (MAX_CLIENTS-1)
-#define CLIENTNUM_RESERVED (MAX_CLIENTS-1)
+#define CLIENTNUM_NONE (MAX_CLIENTS - 1)
+#define CLIENTNUM_RESERVED (MAX_CLIENTS - 1)
// a SOLID_BBOX will never create this value
#define PACKED_BSP 31
diff --git a/src/q_field.c b/src/q_field.c
index 99b3d86..ab837ca 100644
--- a/src/q_field.c
+++ b/src/q_field.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,13 +34,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
IF_Init
================
*/
-void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars ) {
- memset( field, 0, sizeof( *field ) );
+void IF_Init(inputField_t *field, size_t visibleChars, size_t maxChars)
+{
+ memset(field, 0, sizeof(*field));
- if( maxChars >= sizeof( field->text ) ) {
- maxChars = sizeof( field->text ) - 1;
+ if (maxChars >= sizeof(field->text)) {
+ maxChars = sizeof(field->text) - 1;
}
- if( visibleChars > maxChars ) {
+ if (visibleChars > maxChars) {
visibleChars = maxChars;
}
@@ -53,8 +54,9 @@ void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars ) {
IF_Clear
================
*/
-void IF_Clear( inputField_t *field ) {
- memset( field->text, 0, sizeof( field->text ) );
+void IF_Clear(inputField_t *field)
+{
+ memset(field->text, 0, sizeof(field->text));
field->cursorPos = 0;
}
@@ -63,9 +65,10 @@ void IF_Clear( inputField_t *field ) {
IF_Replace
================
*/
-void IF_Replace( inputField_t *field, const char *text ) {
- if( field->maxChars && text ) {
- size_t len = Q_strlcpy( field->text, text, field->maxChars + 1 );
+void IF_Replace(inputField_t *field, const char *text)
+{
+ if (field->maxChars && text) {
+ size_t len = Q_strlcpy(field->text, text, field->maxChars + 1);
field->cursorPos = len >= field->maxChars ? field->maxChars - 1 : len;
} else {
field->text[0] = 0;
@@ -80,123 +83,124 @@ void IF_Replace( inputField_t *field, const char *text ) {
IF_KeyEvent
================
*/
-qboolean IF_KeyEvent( inputField_t *field, int key ) {
- if( !field->maxChars ) {
+qboolean IF_KeyEvent(inputField_t *field, int key)
+{
+ if (!field->maxChars) {
return qfalse;
}
- if( field->cursorPos >= field->maxChars ) {
- Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ );
+ if (field->cursorPos >= field->maxChars) {
+ Com_Error(ERR_FATAL, "%s: bad cursorPos", __func__);
}
- if( key == K_DEL ) {
- if( field->text[field->cursorPos] ) {
- memmove( field->text + field->cursorPos,
- field->text + field->cursorPos + 1,
- sizeof( field->text ) - field->cursorPos );
+ if (key == K_DEL) {
+ if (field->text[field->cursorPos]) {
+ memmove(field->text + field->cursorPos,
+ field->text + field->cursorPos + 1,
+ sizeof(field->text) - field->cursorPos);
}
return qtrue;
}
-
- if( key == K_BACKSPACE || ( key == 'h' && Key_IsDown( K_CTRL ) ) ) {
- if( field->cursorPos > 0 ) {
- memmove( field->text + field->cursorPos - 1,
- field->text + field->cursorPos,
- sizeof( field->text ) - field->cursorPos );
+
+ if (key == K_BACKSPACE || (key == 'h' && Key_IsDown(K_CTRL))) {
+ if (field->cursorPos > 0) {
+ memmove(field->text + field->cursorPos - 1,
+ field->text + field->cursorPos,
+ sizeof(field->text) - field->cursorPos);
field->cursorPos--;
}
return qtrue;
}
- if( key == 'w' && Key_IsDown( K_CTRL ) ) {
+ if (key == 'w' && Key_IsDown(K_CTRL)) {
size_t oldpos = field->cursorPos;
// kill trailing whitespace
- while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) {
+ while (field->cursorPos > 0 && field->text[field->cursorPos] <= 32) {
field->cursorPos--;
}
// kill this word
- while( field->cursorPos > 0 && field->text[ field->cursorPos - 1 ] > 32 ) {
+ while (field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32) {
field->cursorPos--;
}
- memmove( field->text + field->cursorPos, field->text + oldpos,
- sizeof( field->text ) - oldpos );
+ memmove(field->text + field->cursorPos, field->text + oldpos,
+ sizeof(field->text) - oldpos);
return qtrue;
}
- if( key == 'u' && Key_IsDown( K_CTRL ) ) {
- memmove( field->text, field->text + field->cursorPos,
- sizeof( field->text ) - field->cursorPos );
+ if (key == 'u' && Key_IsDown(K_CTRL)) {
+ memmove(field->text, field->text + field->cursorPos,
+ sizeof(field->text) - field->cursorPos);
field->cursorPos = 0;
return qtrue;
}
- if( key == 'k' && Key_IsDown( K_CTRL ) ) {
+ if (key == 'k' && Key_IsDown(K_CTRL)) {
field->text[field->cursorPos] = 0;
return qtrue;
}
- if( key == 'c' && Key_IsDown( K_CTRL ) ) {
- VID_SetClipboardData( field->text );
+ if (key == 'c' && Key_IsDown(K_CTRL)) {
+ VID_SetClipboardData(field->text);
return qtrue;
}
-
- if( key == K_LEFTARROW || ( key == 'b' && Key_IsDown( K_CTRL ) ) ) {
- if( field->cursorPos > 0 ) {
+
+ if (key == K_LEFTARROW || (key == 'b' && Key_IsDown(K_CTRL))) {
+ if (field->cursorPos > 0) {
field->cursorPos--;
}
return qtrue;
}
- if( key == K_RIGHTARROW || ( key == 'f' && Key_IsDown( K_CTRL ) ) ) {
- if( field->text[field->cursorPos] ) {
+ if (key == K_RIGHTARROW || (key == 'f' && Key_IsDown(K_CTRL))) {
+ if (field->text[field->cursorPos]) {
field->cursorPos++;
}
goto check;
}
- if( key == 'b' && Key_IsDown( K_ALT ) ) {
- if( field->cursorPos > 0 && field->text[field->cursorPos - 1] <= 32 ) {
+ if (key == 'b' && Key_IsDown(K_ALT)) {
+ if (field->cursorPos > 0 && field->text[field->cursorPos - 1] <= 32) {
field->cursorPos--;
}
- while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) {
+ while (field->cursorPos > 0 && field->text[field->cursorPos] <= 32) {
field->cursorPos--;
}
- while( field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32 ) {
+ while (field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32) {
field->cursorPos--;
}
return qtrue;
}
- if( key == 'f' && Key_IsDown( K_ALT ) ) {
- while( field->text[field->cursorPos] && field->text[field->cursorPos] <= 32 ) {
+ if (key == 'f' && Key_IsDown(K_ALT)) {
+ while (field->text[field->cursorPos] && field->text[field->cursorPos] <= 32) {
field->cursorPos++;
}
- while( field->text[field->cursorPos] > 32 ) {
+ while (field->text[field->cursorPos] > 32) {
field->cursorPos++;
}
goto check;
}
- if( key == K_HOME || ( key == 'a' && Key_IsDown( K_CTRL ) ) ) {
+ if (key == K_HOME || (key == 'a' && Key_IsDown(K_CTRL))) {
field->cursorPos = 0;
return qtrue;
}
- if( key == K_END || ( key == 'e' && Key_IsDown( K_CTRL ) ) ) {
- field->cursorPos = strlen( field->text );
+ if (key == K_END || (key == 'e' && Key_IsDown(K_CTRL))) {
+ field->cursorPos = strlen(field->text);
goto check;
}
- if( key == K_INS ) {
- Key_SetOverstrikeMode( Key_GetOverstrikeMode() ^ 1 );
+ if (key == K_INS) {
+ Key_SetOverstrikeMode(Key_GetOverstrikeMode() ^ 1);
return qtrue;
}
return qfalse;
check:
- if( field->cursorPos >= field->maxChars ) {
+ if (field->cursorPos >= field->maxChars) {
field->cursorPos = field->maxChars - 1;
}
@@ -208,34 +212,35 @@ check:
IF_CharEvent
================
*/
-qboolean IF_CharEvent( inputField_t *field, int key ) {
- if( !field->maxChars ) {
+qboolean IF_CharEvent(inputField_t *field, int key)
+{
+ if (!field->maxChars) {
return qfalse;
}
- if( field->cursorPos >= field->maxChars ) {
- Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ );
+ if (field->cursorPos >= field->maxChars) {
+ Com_Error(ERR_FATAL, "%s: bad cursorPos", __func__);
}
- if( key < 32 || key > 127 ) {
+ if (key < 32 || key > 127) {
return qfalse; // non printable
}
- if( field->cursorPos == field->maxChars - 1 ) {
+ if (field->cursorPos == field->maxChars - 1) {
// buffer limit was reached, just replace the last character
field->text[field->cursorPos] = key;
return qtrue;
}
- if( Key_GetOverstrikeMode() ) {
+ if (Key_GetOverstrikeMode()) {
// replace the character at cursor and advance
field->text[field->cursorPos++] = key;
return qtrue;
}
// insert new character at cursor position
- memmove( field->text + field->cursorPos + 1,
- field->text + field->cursorPos,
- sizeof( field->text ) - field->cursorPos - 1 );
+ memmove(field->text + field->cursorPos + 1,
+ field->text + field->cursorPos,
+ sizeof(field->text) - field->cursorPos - 1);
field->text[field->cursorPos++] = key;
return qtrue;
@@ -249,34 +254,35 @@ The input line scrolls horizontally if typing goes beyond the right edge.
Returns x offset of the rightmost character drawn.
================
*/
-int IF_Draw( inputField_t *field, int x, int y, int flags, qhandle_t font ) {
+int IF_Draw(inputField_t *field, int x, int y, int flags, qhandle_t font)
+{
char *text = field->text;
size_t cursorPos = field->cursorPos;
size_t offset = 0;
int ret;
- if( !field->maxChars || !field->visibleChars ) {
+ if (!field->maxChars || !field->visibleChars) {
return 0;
}
- if( cursorPos >= field->maxChars ) {
- Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ );
+ if (cursorPos >= field->maxChars) {
+ Com_Error(ERR_FATAL, "%s: bad cursorPos", __func__);
}
// scroll horizontally
- if( cursorPos >= field->visibleChars ) {
+ if (cursorPos >= field->visibleChars) {
cursorPos = field->visibleChars - 1;
offset = field->cursorPos - cursorPos;
}
-
+
// draw text
- ret = R_DrawString( x, y, flags, field->visibleChars, text + offset, font );
+ ret = R_DrawString(x, y, flags, field->visibleChars, text + offset, font);
- if( flags & UI_DRAWCURSOR ) {
- // draw blinking cursor
- if( ( com_localTime >> 8 ) & 1 ) {
+ if (flags & UI_DRAWCURSOR) {
+ // draw blinking cursor
+ if ((com_localTime >> 8) & 1) {
int c = Key_GetOverstrikeMode() ? 11 : '_';
- R_DrawChar( x + cursorPos * CHAR_WIDTH, y, flags, c, font );
+ R_DrawChar(x + cursorPos * CHAR_WIDTH, y, flags, c, font);
}
}
diff --git a/src/q_field.h b/src/q_field.h
index 7c0a6b8..1738e0e 100644
--- a/src/q_field.h
+++ b/src/q_field.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -36,10 +36,10 @@ typedef struct inputField_s {
size_t cursorPos;
} inputField_t;
-qboolean IF_KeyEvent( inputField_t *field, int key );
-qboolean IF_CharEvent( inputField_t *field, int key );
-void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars );
-void IF_Clear( inputField_t *field );
-void IF_Replace( inputField_t *field, const char *text );
-int IF_Draw( inputField_t *field, int x, int y, int flags, qhandle_t font );
+qboolean IF_KeyEvent(inputField_t *field, int key);
+qboolean IF_CharEvent(inputField_t *field, int key);
+void IF_Init(inputField_t *field, size_t visibleChars, size_t maxChars);
+void IF_Clear(inputField_t *field);
+void IF_Replace(inputField_t *field, const char *text);
+int IF_Draw(inputField_t *field, int x, int y, int flags, qhandle_t font);
diff --git a/src/q_fifo.h b/src/q_fifo.h
index 3bb5124..fbe0501 100644
--- a/src/q_fifo.h
+++ b/src/q_fifo.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,16 +28,17 @@ typedef struct {
size_t ax, ay, bs;
} fifo_t;
-static inline void *FIFO_Reserve( fifo_t *fifo, size_t *len ) {
+static inline void *FIFO_Reserve(fifo_t *fifo, size_t *len)
+{
size_t tail;
- if( fifo->bs ) {
+ if (fifo->bs) {
*len = fifo->ax - fifo->bs;
return fifo->data + fifo->bs;
}
tail = fifo->size - fifo->ay;
- if( tail ) {
+ if (tail) {
*len = tail;
return fifo->data + fifo->ay;
}
@@ -46,16 +47,17 @@ static inline void *FIFO_Reserve( fifo_t *fifo, size_t *len ) {
return fifo->data;
}
-static inline void FIFO_Commit( fifo_t *fifo, size_t len ) {
+static inline void FIFO_Commit(fifo_t *fifo, size_t len)
+{
size_t tail;
- if( fifo->bs ) {
+ if (fifo->bs) {
fifo->bs += len;
return;
}
tail = fifo->size - fifo->ay;
- if( tail ) {
+ if (tail) {
fifo->ay += len;
return;
}
@@ -63,13 +65,15 @@ static inline void FIFO_Commit( fifo_t *fifo, size_t len ) {
fifo->bs = len;
}
-static inline void *FIFO_Peek( fifo_t *fifo, size_t *len ) {
+static inline void *FIFO_Peek(fifo_t *fifo, size_t *len)
+{
*len = fifo->ay - fifo->ax;
return fifo->data + fifo->ax;
}
-static inline void FIFO_Decommit( fifo_t *fifo, size_t len ) {
- if( fifo->ax + len < fifo->ay ) {
+static inline void FIFO_Decommit(fifo_t *fifo, size_t len)
+{
+ if (fifo->ax + len < fifo->ay) {
fifo->ax += len;
return;
}
@@ -78,39 +82,44 @@ static inline void FIFO_Decommit( fifo_t *fifo, size_t len ) {
fifo->ax = fifo->bs = 0;
}
-static inline size_t FIFO_Usage( fifo_t *fifo ) {
+static inline size_t FIFO_Usage(fifo_t *fifo)
+{
return fifo->ay - fifo->ax + fifo->bs;
}
-static inline int FIFO_Percent( fifo_t *fifo ) {
- if( !fifo->size ) {
+static inline int FIFO_Percent(fifo_t *fifo)
+{
+ if (!fifo->size) {
return 0;
}
- return ( int )( FIFO_Usage( fifo ) * 100 / fifo->size );
+ return (int)(FIFO_Usage(fifo) * 100 / fifo->size);
}
-static inline void FIFO_Clear( fifo_t *fifo ) {
+static inline void FIFO_Clear(fifo_t *fifo)
+{
fifo->ax = fifo->ay = fifo->bs = 0;
}
-size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len );
-size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len );
+size_t FIFO_Read(fifo_t *fifo, void *buffer, size_t len);
+size_t FIFO_Write(fifo_t *fifo, const void *buffer, size_t len);
-static inline qboolean FIFO_TryRead( fifo_t *fifo, void *buffer, size_t len ) {
- if( FIFO_Read( fifo, NULL, len ) < len ) {
+static inline qboolean FIFO_TryRead(fifo_t *fifo, void *buffer, size_t len)
+{
+ if (FIFO_Read(fifo, NULL, len) < len) {
return qfalse;
}
- FIFO_Read( fifo, buffer, len );
+ FIFO_Read(fifo, buffer, len);
return qtrue;
}
-static inline qboolean FIFO_TryWrite( fifo_t *fifo, void *buffer, size_t len ) {
- if( FIFO_Write( fifo, NULL, len ) < len ) {
+static inline qboolean FIFO_TryWrite(fifo_t *fifo, void *buffer, size_t len)
+{
+ if (FIFO_Write(fifo, NULL, len) < len) {
return qfalse;
}
- FIFO_Write( fifo, buffer, len );
+ FIFO_Write(fifo, buffer, len);
return qtrue;
}
-qboolean FIFO_ReadMessage( fifo_t *fifo, size_t msglen );
+qboolean FIFO_ReadMessage(fifo_t *fifo, size_t msglen);
diff --git a/src/q_list.h b/src/q_list.h
index da194c7..7cff1c0 100644
--- a/src/q_list.h
+++ b/src/q_list.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,9 +27,9 @@ typedef struct list_s {
struct list_s *prev; // tail
} list_t;
-static inline void List_Link( list_t *prev,
- list_t *next,
- list_t *elem )
+static inline void List_Link(list_t *prev,
+ list_t *next,
+ list_t *elem)
{
prev->next = elem;
next->prev = elem;
@@ -37,103 +37,112 @@ static inline void List_Link( list_t *prev,
elem->next = next;
}
-static inline void List_Unlink( list_t *prev, list_t *next ) {
+static inline void List_Unlink(list_t *prev, list_t *next)
+{
prev->next = next;
next->prev = prev;
}
-static inline void List_Init( list_t *list ) {
+static inline void List_Init(list_t *list)
+{
list->prev = list->next = list;
}
-static inline void List_Append( list_t *tail, list_t *elem ) {
- List_Link( tail->prev, tail, elem );
+static inline void List_Append(list_t *tail, list_t *elem)
+{
+ List_Link(tail->prev, tail, elem);
}
-static inline void List_Insert( list_t *head, list_t *elem ) {
- List_Link( head, head->next, elem );
+static inline void List_Insert(list_t *head, list_t *elem)
+{
+ List_Link(head, head->next, elem);
}
-#define LIST_FOR_EACH_ELEM( cursor, list ) \
- for( cursor = (list)->next; cursor != list; cursor = (cursor)->next )
+#define LIST_FOR_EACH_ELEM(cursor, list) \
+ for (cursor = (list)->next; cursor != list; cursor = (cursor)->next)
// insert element into the sorted list of array elements
-static inline void List_SeqAdd( list_t *list, list_t *elem ) {
+static inline void List_SeqAdd(list_t *list, list_t *elem)
+{
list_t *cursor;
- LIST_FOR_EACH_ELEM( cursor, list ) {
- if( elem < cursor ) {
+ LIST_FOR_EACH_ELEM(cursor, list) {
+ if (elem < cursor) {
break;
}
}
- List_Append( cursor, elem );
+ List_Append(cursor, elem);
}
-static inline void List_Delete( list_t *elem ) {
- List_Unlink( elem->prev, elem->next );
- List_Init( elem );
+static inline void List_Delete(list_t *elem)
+{
+ List_Unlink(elem->prev, elem->next);
+ List_Init(elem);
}
-static inline void List_Remove( list_t *elem ) {
- List_Unlink( elem->prev, elem->next );
+static inline void List_Remove(list_t *elem)
+{
+ List_Unlink(elem->prev, elem->next);
}
-#define LIST_ENTRY( type, elem, member ) \
- (( type * )( ( unsigned char * )elem - q_offsetof( type, member ) ))
-
-#define LIST_EMPTY( list ) \
- ( (list)->next == list ) \
-
-#define LIST_SINGLE( list ) \
- ( !LIST_EMPTY( list ) && (list)->next == (list)->prev )
+#define LIST_ENTRY(type, elem, member) \
+ ((type *)((unsigned char *)elem - q_offsetof(type, member)))
-#define LIST_TERM( cursor, list, member ) \
- ( &(cursor)->member == list ) \
+#define LIST_EMPTY(list) \
+ ((list)->next == list)
+
+#define LIST_SINGLE(list) \
+ (!LIST_EMPTY(list) && (list)->next == (list)->prev)
-#define LIST_FIRST( type, list, member ) \
- LIST_ENTRY( type, (list)->next, member )
+#define LIST_TERM(cursor, list, member) \
+ (&(cursor)->member == list)
+
+#define LIST_FIRST(type, list, member) \
+ LIST_ENTRY(type, (list)->next, member)
-#define LIST_LAST( type, list, member ) \
- LIST_ENTRY( type, (list)->prev, member )
+#define LIST_LAST(type, list, member) \
+ LIST_ENTRY(type, (list)->prev, member)
-#define LIST_NEXT( type, entry, member ) \
- LIST_ENTRY( type, (entry)->member.next, member )
+#define LIST_NEXT(type, entry, member) \
+ LIST_ENTRY(type, (entry)->member.next, member)
-#define LIST_PREV( type, entry, member ) \
- LIST_ENTRY( type, (entry)->member.prev, member )
+#define LIST_PREV(type, entry, member) \
+ LIST_ENTRY(type, (entry)->member.prev, member)
-#define LIST_FOR_EACH( type, cursor, list, member ) \
- for( cursor = LIST_FIRST( type, list, member ); \
- !LIST_TERM( cursor, list, member ); \
- cursor = LIST_NEXT( type, cursor, member ) )
+#define LIST_FOR_EACH(type, cursor, list, member) \
+ for (cursor = LIST_FIRST(type, list, member); \
+ !LIST_TERM(cursor, list, member); \
+ cursor = LIST_NEXT(type, cursor, member))
-#define LIST_FOR_EACH_SAFE( type, cursor, next, list, member ) \
- for( cursor = LIST_FIRST( type, list, member ); \
- next = LIST_NEXT( type, cursor, member ), \
- !LIST_TERM( cursor, list, member ); \
- cursor = next )
+#define LIST_FOR_EACH_SAFE(type, cursor, next, list, member) \
+ for (cursor = LIST_FIRST(type, list, member); \
+ next = LIST_NEXT(type, cursor, member), \
+ !LIST_TERM(cursor, list, member); \
+ cursor = next)
-#define LIST_DECL( list ) list_t list = { &list, &list }
+#define LIST_DECL(list) list_t list = { &list, &list }
-static inline int List_Count( list_t *list ) {
+static inline int List_Count(list_t *list)
+{
int count = 0;
list_t *cursor;
- LIST_FOR_EACH_ELEM( cursor, list ) {
+ LIST_FOR_EACH_ELEM(cursor, list) {
count++;
}
return count;
}
-static inline void *List_Index( list_t *list, size_t offset, int index ) {
+static inline void *List_Index(list_t *list, size_t offset, int index)
+{
int count = 0;
list_t *cursor;
- LIST_FOR_EACH_ELEM( cursor, list ) {
- if( count == index ) {
- return ( unsigned char * )cursor - offset;
+ LIST_FOR_EACH_ELEM(cursor, list) {
+ if (count == index) {
+ return (unsigned char *)cursor - offset;
}
count++;
}
@@ -141,6 +150,6 @@ static inline void *List_Index( list_t *list, size_t offset, int index ) {
return NULL;
}
-#define LIST_INDEX( type, index, list, member ) \
- ( ( type * )List_Index( list, q_offsetof( type, member ), index ) )
+#define LIST_INDEX(type, index, list, member) \
+ ((type *)List_Index(list, q_offsetof(type, member), index))
diff --git a/src/q_msg.c b/src/q_msg.c
index 8c46dcd..8d0f7e0 100644
--- a/src/q_msg.c
+++ b/src/q_msg.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -47,11 +47,12 @@ const usercmd_t nullUserCmd;
MSG_Init
=============
*/
-void MSG_Init( void ) {
+void MSG_Init(void)
+{
// initialize default buffers
// don't allow them to overflow
- SZ_TagInit( &msg_read, msg_read_buffer, MAX_MSGLEN, SZ_MSG_READ );
- SZ_TagInit( &msg_write, msg_write_buffer, MAX_MSGLEN, SZ_MSG_WRITE );
+ SZ_TagInit(&msg_read, msg_read_buffer, MAX_MSGLEN, SZ_MSG_READ);
+ SZ_TagInit(&msg_write, msg_write_buffer, MAX_MSGLEN, SZ_MSG_WRITE);
}
@@ -64,7 +65,8 @@ void MSG_Init( void ) {
MSG_BeginWriting
=============
*/
-void MSG_BeginWriting( void ) {
+void MSG_BeginWriting(void)
+{
msg_write.cursize = 0;
msg_write.bitpos = 0;
msg_write.overflowed = qfalse;
@@ -75,15 +77,16 @@ void MSG_BeginWriting( void ) {
MSG_WriteChar
=============
*/
-void MSG_WriteChar( int c ) {
+void MSG_WriteChar(int c)
+{
byte *buf;
-
+
#ifdef PARANOID
- if( c < -128 || c > 127 )
- Com_Error( ERR_FATAL, "MSG_WriteChar: range error" );
+ if (c < -128 || c > 127)
+ Com_Error(ERR_FATAL, "MSG_WriteChar: range error");
#endif
- buf = SZ_GetSpace( &msg_write, 1 );
+ buf = SZ_GetSpace(&msg_write, 1);
buf[0] = c;
}
@@ -92,15 +95,16 @@ void MSG_WriteChar( int c ) {
MSG_WriteByte
=============
*/
-void MSG_WriteByte( int c ) {
+void MSG_WriteByte(int c)
+{
byte *buf;
-
+
#ifdef PARANOID
- if( c < 0 || c > 255 )
- Com_Error( ERR_FATAL, "MSG_WriteByte: range error" );
+ if (c < 0 || c > 255)
+ Com_Error(ERR_FATAL, "MSG_WriteByte: range error");
#endif
- buf = SZ_GetSpace( &msg_write, 1 );
+ buf = SZ_GetSpace(&msg_write, 1);
buf[0] = c;
}
@@ -109,15 +113,16 @@ void MSG_WriteByte( int c ) {
MSG_WriteShort
=============
*/
-void MSG_WriteShort( int c ) {
+void MSG_WriteShort(int c)
+{
byte *buf;
-
+
#ifdef PARANOID
if (c < ((short)0x8000) || c > (short)0x7fff)
- Com_Error (ERR_FATAL, "MSG_WriteShort: range error");
+ Com_Error(ERR_FATAL, "MSG_WriteShort: range error");
#endif
- buf = SZ_GetSpace( &msg_write, 2 );
+ buf = SZ_GetSpace(&msg_write, 2);
buf[0] = c & 0xff;
buf[1] = c >> 8;
}
@@ -127,13 +132,14 @@ void MSG_WriteShort( int c ) {
MSG_WriteLong
=============
*/
-void MSG_WriteLong( int c ) {
+void MSG_WriteLong(int c)
+{
byte *buf;
-
- buf = SZ_GetSpace( &msg_write, 4 );
+
+ buf = SZ_GetSpace(&msg_write, 4);
buf[0] = c & 0xff;
- buf[1] = ( c >> 8 ) & 0xff;
- buf[2] = ( c >> 16 ) & 0xff;
+ buf[1] = (c >> 8) & 0xff;
+ buf[2] = (c >> 16) & 0xff;
buf[3] = c >> 24;
}
@@ -142,22 +148,23 @@ void MSG_WriteLong( int c ) {
MSG_WriteString
=============
*/
-void MSG_WriteString( const char *string ) {
+void MSG_WriteString(const char *string)
+{
size_t length;
- if( !string ) {
- MSG_WriteByte( 0 );
+ if (!string) {
+ MSG_WriteByte(0);
return;
}
- length = strlen( string );
- if( length >= MAX_NET_STRING ) {
- Com_WPrintf( "%s: overflow: %"PRIz" chars", __func__, length );
- MSG_WriteByte( 0 );
+ length = strlen(string);
+ if (length >= MAX_NET_STRING) {
+ Com_WPrintf("%s: overflow: %"PRIz" chars", __func__, length);
+ MSG_WriteByte(0);
return;
}
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData(string, length + 1);
}
/*
@@ -169,8 +176,9 @@ MSG_WriteCoord
#define COORD2SHORT(x) ((int)((x)*8.0f))
#define SHORT2COORD(x) ((x)*(1.0f/8))
-static inline void MSG_WriteCoord( float f ) {
- MSG_WriteShort( COORD2SHORT(f) );
+static inline void MSG_WriteCoord(float f)
+{
+ MSG_WriteShort(COORD2SHORT(f));
}
/*
@@ -178,10 +186,11 @@ static inline void MSG_WriteCoord( float f ) {
MSG_WritePos
=============
*/
-void MSG_WritePos( const vec3_t pos ) {
- MSG_WriteCoord( pos[0] );
- MSG_WriteCoord( pos[1] );
- MSG_WriteCoord( pos[2] );
+void MSG_WritePos(const vec3_t pos)
+{
+ MSG_WriteCoord(pos[0]);
+ MSG_WriteCoord(pos[1]);
+ MSG_WriteCoord(pos[2]);
}
/*
@@ -193,8 +202,9 @@ MSG_WriteAngle
#define ANGLE2BYTE(x) ((int)((x)*256.0f/360)&255)
#define BYTE2ANGLE(x) ((x)*(360.0f/256))
-void MSG_WriteAngle( float f ) {
- MSG_WriteByte( ANGLE2BYTE( f ) );
+void MSG_WriteAngle(float f)
+{
+ MSG_WriteByte(ANGLE2BYTE(f));
}
/*
@@ -202,8 +212,9 @@ void MSG_WriteAngle( float f ) {
MSG_WriteAngle16
=============
*/
-static inline void MSG_WriteAngle16( float f ) {
- MSG_WriteShort( ANGLE2SHORT( f ) );
+static inline void MSG_WriteAngle16(float f)
+{
+ MSG_WriteShort(ANGLE2SHORT(f));
}
#if USE_CLIENT
@@ -213,10 +224,11 @@ static inline void MSG_WriteAngle16( float f ) {
MSG_WriteDeltaUsercmd
=============
*/
-int MSG_WriteDeltaUsercmd( const usercmd_t *from, const usercmd_t *cmd, int version ) {
+int MSG_WriteDeltaUsercmd(const usercmd_t *from, const usercmd_t *cmd, int version)
+{
int bits, buttons = cmd->buttons & BUTTON_MASK;
- if( !from ) {
+ if (!from) {
from = &nullUserCmd;
}
@@ -224,77 +236,77 @@ int MSG_WriteDeltaUsercmd( const usercmd_t *from, const usercmd_t *cmd, int vers
// send the movement message
//
bits = 0;
- if( cmd->angles[0] != from->angles[0] )
+ if (cmd->angles[0] != from->angles[0])
bits |= CM_ANGLE1;
- if( cmd->angles[1] != from->angles[1] )
+ if (cmd->angles[1] != from->angles[1])
bits |= CM_ANGLE2;
- if( cmd->angles[2] != from->angles[2] )
+ if (cmd->angles[2] != from->angles[2])
bits |= CM_ANGLE3;
- if( cmd->forwardmove != from->forwardmove )
+ if (cmd->forwardmove != from->forwardmove)
bits |= CM_FORWARD;
- if( cmd->sidemove != from->sidemove )
+ if (cmd->sidemove != from->sidemove)
bits |= CM_SIDE;
- if( cmd->upmove != from->upmove )
+ if (cmd->upmove != from->upmove)
bits |= CM_UP;
- if( cmd->buttons != from->buttons )
+ if (cmd->buttons != from->buttons)
bits |= CM_BUTTONS;
- if( cmd->impulse != from->impulse )
+ if (cmd->impulse != from->impulse)
bits |= CM_IMPULSE;
- MSG_WriteByte ( bits );
+ MSG_WriteByte(bits);
- if( version >= PROTOCOL_VERSION_R1Q2_UCMD ) {
- if( bits & CM_BUTTONS ) {
- if( ( bits & CM_FORWARD ) && !( cmd->forwardmove % 5 ) ) {
+ if (version >= PROTOCOL_VERSION_R1Q2_UCMD) {
+ if (bits & CM_BUTTONS) {
+ if ((bits & CM_FORWARD) && !(cmd->forwardmove % 5)) {
buttons |= BUTTON_FORWARD;
}
- if( ( bits & CM_SIDE ) && !( cmd->sidemove % 5 ) ) {
+ if ((bits & CM_SIDE) && !(cmd->sidemove % 5)) {
buttons |= BUTTON_SIDE;
}
- if( ( bits & CM_UP ) && !( cmd->upmove % 5 ) ) {
+ if ((bits & CM_UP) && !(cmd->upmove % 5)) {
buttons |= BUTTON_UP;
}
- MSG_WriteByte( buttons );
+ MSG_WriteByte(buttons);
}
}
- if( bits & CM_ANGLE1 )
- MSG_WriteShort( cmd->angles[0] );
- if( bits & CM_ANGLE2 )
- MSG_WriteShort( cmd->angles[1] );
- if( bits & CM_ANGLE3 )
- MSG_WriteShort( cmd->angles[2] );
-
- if( bits & CM_FORWARD ) {
- if( buttons & BUTTON_FORWARD ) {
- MSG_WriteChar( cmd->forwardmove / 5 );
+ if (bits & CM_ANGLE1)
+ MSG_WriteShort(cmd->angles[0]);
+ if (bits & CM_ANGLE2)
+ MSG_WriteShort(cmd->angles[1]);
+ if (bits & CM_ANGLE3)
+ MSG_WriteShort(cmd->angles[2]);
+
+ if (bits & CM_FORWARD) {
+ if (buttons & BUTTON_FORWARD) {
+ MSG_WriteChar(cmd->forwardmove / 5);
} else {
- MSG_WriteShort( cmd->forwardmove );
+ MSG_WriteShort(cmd->forwardmove);
}
}
- if( bits & CM_SIDE ) {
- if( buttons & BUTTON_SIDE ) {
- MSG_WriteChar( cmd->sidemove / 5 );
+ if (bits & CM_SIDE) {
+ if (buttons & BUTTON_SIDE) {
+ MSG_WriteChar(cmd->sidemove / 5);
} else {
- MSG_WriteShort( cmd->sidemove );
+ MSG_WriteShort(cmd->sidemove);
}
}
- if( bits & CM_UP ) {
- if( buttons & BUTTON_UP ) {
- MSG_WriteChar( cmd->upmove / 5 );
+ if (bits & CM_UP) {
+ if (buttons & BUTTON_UP) {
+ MSG_WriteChar(cmd->upmove / 5);
} else {
- MSG_WriteShort( cmd->upmove );
+ MSG_WriteShort(cmd->upmove);
}
}
- if( version < PROTOCOL_VERSION_R1Q2_UCMD ) {
- if( bits & CM_BUTTONS )
- MSG_WriteByte( cmd->buttons );
+ if (version < PROTOCOL_VERSION_R1Q2_UCMD) {
+ if (bits & CM_BUTTONS)
+ MSG_WriteByte(cmd->buttons);
}
- if( bits & CM_IMPULSE )
- MSG_WriteByte( cmd->impulse );
+ if (bits & CM_IMPULSE)
+ MSG_WriteByte(cmd->impulse);
- MSG_WriteByte( cmd->msec );
+ MSG_WriteByte(cmd->msec);
return bits;
}
@@ -304,48 +316,49 @@ int MSG_WriteDeltaUsercmd( const usercmd_t *from, const usercmd_t *cmd, int vers
MSG_WriteBits
=============
*/
-void MSG_WriteBits( int value, int bits ) {
+void MSG_WriteBits(int value, int bits)
+{
int i;
size_t bitpos;
- if( bits == 0 || bits < -31 || bits > 32 ) {
- Com_Error( ERR_FATAL, "MSG_WriteBits: bad bits: %d", bits );
+ if (bits == 0 || bits < -31 || bits > 32) {
+ Com_Error(ERR_FATAL, "MSG_WriteBits: bad bits: %d", bits);
}
- if( msg_write.maxsize - msg_write.cursize < 4 ) {
- Com_Error( ERR_FATAL, "MSG_WriteBits: overflow" );
+ if (msg_write.maxsize - msg_write.cursize < 4) {
+ Com_Error(ERR_FATAL, "MSG_WriteBits: overflow");
}
- if( bits < 0 ) {
+ if (bits < 0) {
bits = -bits;
}
bitpos = msg_write.bitpos;
- if( ( bitpos & 7 ) == 0 ) {
+ if ((bitpos & 7) == 0) {
// optimized case
- switch( bits ) {
+ switch (bits) {
case 8:
- MSG_WriteByte( value );
+ MSG_WriteByte(value);
return;
case 16:
- MSG_WriteShort( value );
+ MSG_WriteShort(value);
return;
case 32:
- MSG_WriteLong( value );
+ MSG_WriteLong(value);
return;
default:
break;
}
}
- for( i = 0; i < bits; i++, bitpos++ ) {
- if( ( bitpos & 7 ) == 0 ) {
- msg_write.data[ bitpos >> 3 ] = 0;
+ for (i = 0; i < bits; i++, bitpos++) {
+ if ((bitpos & 7) == 0) {
+ msg_write.data[bitpos >> 3] = 0;
}
- msg_write.data[ bitpos >> 3 ] |= ( value & 1 ) << ( bitpos & 7 );
+ msg_write.data[bitpos >> 3] |= (value & 1) << (bitpos & 7);
value >>= 1;
}
msg_write.bitpos = bitpos;
- msg_write.cursize = ( bitpos + 7 ) >> 3;
+ msg_write.cursize = (bitpos + 7) >> 3;
}
/*
@@ -353,13 +366,13 @@ void MSG_WriteBits( int value, int bits ) {
MSG_WriteDeltaUsercmd_Enhanced
=============
*/
-int MSG_WriteDeltaUsercmd_Enhanced( const usercmd_t *from,
- const usercmd_t *cmd,
- int version )
+int MSG_WriteDeltaUsercmd_Enhanced(const usercmd_t *from,
+ const usercmd_t *cmd,
+ int version)
{
int bits, delta, count;
- if( !from ) {
+ if (!from) {
from = &nullUserCmd;
}
@@ -367,77 +380,77 @@ int MSG_WriteDeltaUsercmd_Enhanced( const usercmd_t *from,
// send the movement message
//
bits = 0;
- if( cmd->angles[0] != from->angles[0] )
+ if (cmd->angles[0] != from->angles[0])
bits |= CM_ANGLE1;
- if( cmd->angles[1] != from->angles[1] )
+ if (cmd->angles[1] != from->angles[1])
bits |= CM_ANGLE2;
- if( cmd->angles[2] != from->angles[2] )
+ if (cmd->angles[2] != from->angles[2])
bits |= CM_ANGLE3;
- if( cmd->forwardmove != from->forwardmove )
+ if (cmd->forwardmove != from->forwardmove)
bits |= CM_FORWARD;
- if( cmd->sidemove != from->sidemove )
+ if (cmd->sidemove != from->sidemove)
bits |= CM_SIDE;
- if( cmd->upmove != from->upmove )
+ if (cmd->upmove != from->upmove)
bits |= CM_UP;
- if( cmd->buttons != from->buttons )
+ if (cmd->buttons != from->buttons)
bits |= CM_BUTTONS;
- if( cmd->msec != from->msec )
+ if (cmd->msec != from->msec)
bits |= CM_IMPULSE;
- if( !bits ) {
- MSG_WriteBits( 0, 1 );
+ if (!bits) {
+ MSG_WriteBits(0, 1);
return 0;
}
- MSG_WriteBits( 1, 1 );
- MSG_WriteBits( bits, 8 );
+ MSG_WriteBits(1, 1);
+ MSG_WriteBits(bits, 8);
- if( bits & CM_ANGLE1 ) {
+ if (bits & CM_ANGLE1) {
delta = cmd->angles[0] - from->angles[0];
- if( delta >= -128 && delta <= 127 ) {
- MSG_WriteBits( 1, 1 );
- MSG_WriteBits( delta, -8 );
+ if (delta >= -128 && delta <= 127) {
+ MSG_WriteBits(1, 1);
+ MSG_WriteBits(delta, -8);
} else {
- MSG_WriteBits( 0, 1 );
- MSG_WriteBits( cmd->angles[0], -16 );
+ MSG_WriteBits(0, 1);
+ MSG_WriteBits(cmd->angles[0], -16);
}
}
- if( bits & CM_ANGLE2 ) {
+ if (bits & CM_ANGLE2) {
delta = cmd->angles[1] - from->angles[1];
- if( delta >= -128 && delta <= 127 ) {
- MSG_WriteBits( 1, 1 );
- MSG_WriteBits( delta, -8 );
+ if (delta >= -128 && delta <= 127) {
+ MSG_WriteBits(1, 1);
+ MSG_WriteBits(delta, -8);
} else {
- MSG_WriteBits( 0, 1 );
- MSG_WriteBits( cmd->angles[1], -16 );
+ MSG_WriteBits(0, 1);
+ MSG_WriteBits(cmd->angles[1], -16);
}
}
- if( bits & CM_ANGLE3 ) {
- MSG_WriteBits( cmd->angles[2], -16 );
+ if (bits & CM_ANGLE3) {
+ MSG_WriteBits(cmd->angles[2], -16);
}
-
- if( version >= PROTOCOL_VERSION_Q2PRO_UCMD ) {
+
+ if (version >= PROTOCOL_VERSION_Q2PRO_UCMD) {
count = -10;
} else {
count = -16;
}
- if( bits & CM_FORWARD ) {
- MSG_WriteBits( cmd->forwardmove, count );
+ if (bits & CM_FORWARD) {
+ MSG_WriteBits(cmd->forwardmove, count);
}
- if( bits & CM_SIDE ) {
- MSG_WriteBits( cmd->sidemove, count );
+ if (bits & CM_SIDE) {
+ MSG_WriteBits(cmd->sidemove, count);
}
- if( bits & CM_UP ) {
- MSG_WriteBits( cmd->upmove, count );
+ if (bits & CM_UP) {
+ MSG_WriteBits(cmd->upmove, count);
}
- if( bits & CM_BUTTONS ) {
- int buttons = ( cmd->buttons & 3 ) | ( cmd->buttons >> 5 );
- MSG_WriteBits( buttons, 3 );
+ if (bits & CM_BUTTONS) {
+ int buttons = (cmd->buttons & 3) | (cmd->buttons >> 5);
+ MSG_WriteBits(buttons, 3);
}
- if( bits & CM_IMPULSE ) {
- MSG_WriteBits( cmd->msec, 8 );
+ if (bits & CM_IMPULSE) {
+ MSG_WriteBits(cmd->msec, 8);
}
return bits;
@@ -445,11 +458,12 @@ int MSG_WriteDeltaUsercmd_Enhanced( const usercmd_t *from,
#endif // USE_CLIENT
-void MSG_WriteDir( const vec3_t dir ) {
+void MSG_WriteDir(const vec3_t dir)
+{
int best;
-
- best = DirToByte( dir );
- MSG_WriteByte( best );
+
+ best = DirToByte(dir);
+ MSG_WriteByte(best);
}
// values transmitted over network are discrete, so
@@ -486,145 +500,145 @@ Writes part of a packetentities message.
Can delta from either a baseline or a previous packet_entity
==================
*/
-void MSG_WriteDeltaEntity( const entity_state_t *from,
- const entity_state_t *to,
- msgEsFlags_t flags )
+void MSG_WriteDeltaEntity(const entity_state_t *from,
+ const entity_state_t *to,
+ msgEsFlags_t flags)
{
unsigned bits, mask;
- if( !to ) {
- if( !from ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ if (!from) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
- if( from->number < 1 || from->number >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad number: %d", __func__, from->number );
+ if (from->number < 1 || from->number >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad number: %d", __func__, from->number);
}
bits = U_REMOVE;
- if( from->number >= 256 ) {
+ if (from->number >= 256) {
bits |= U_NUMBER16 | U_MOREBITS1;
}
- MSG_WriteByte( bits & 255 );
- if( bits & 0x0000ff00 )
- MSG_WriteByte( ( bits >> 8 ) & 255 );
+ MSG_WriteByte(bits & 255);
+ if (bits & 0x0000ff00)
+ MSG_WriteByte((bits >> 8) & 255);
- if( bits & U_NUMBER16 )
- MSG_WriteShort( from->number );
+ if (bits & U_NUMBER16)
+ MSG_WriteShort(from->number);
else
- MSG_WriteByte( from->number );
+ MSG_WriteByte(from->number);
return; // remove entity
}
- if( to->number < 1 || to->number >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad number: %d", __func__, to->number );
+ if (to->number < 1 || to->number >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad number: %d", __func__, to->number);
}
- if( !from ) {
+ if (!from) {
from = &nullEntityState;
}
// send an update
bits = 0;
- if( !( flags & MSG_ES_FIRSTPERSON ) ) {
- if( delta_coord( to->origin[0], from->origin[0] ) )
+ if (!(flags & MSG_ES_FIRSTPERSON)) {
+ if (delta_coord(to->origin[0], from->origin[0]))
bits |= U_ORIGIN1;
- if( delta_coord( to->origin[1], from->origin[1] ) )
+ if (delta_coord(to->origin[1], from->origin[1]))
bits |= U_ORIGIN2;
- if( delta_coord( to->origin[2], from->origin[2] ) )
+ if (delta_coord(to->origin[2], from->origin[2]))
bits |= U_ORIGIN3;
- if( flags & MSG_ES_SHORTANGLES ) {
- if( delta_angle16( to->angles[0], from->angles[0] ) )
- bits |= U_ANGLE1|U_ANGLE16;
- if( delta_angle16( to->angles[1], from->angles[1] ) )
- bits |= U_ANGLE2|U_ANGLE16;
- if( delta_angle16( to->angles[2], from->angles[2] ) )
- bits |= U_ANGLE3|U_ANGLE16;
+ if (flags & MSG_ES_SHORTANGLES) {
+ if (delta_angle16(to->angles[0], from->angles[0]))
+ bits |= U_ANGLE1 | U_ANGLE16;
+ if (delta_angle16(to->angles[1], from->angles[1]))
+ bits |= U_ANGLE2 | U_ANGLE16;
+ if (delta_angle16(to->angles[2], from->angles[2]))
+ bits |= U_ANGLE3 | U_ANGLE16;
} else {
- if( delta_angle( to->angles[0], from->angles[0] ) )
+ if (delta_angle(to->angles[0], from->angles[0]))
bits |= U_ANGLE1;
- if( delta_angle( to->angles[1], from->angles[1] ) )
+ if (delta_angle(to->angles[1], from->angles[1]))
bits |= U_ANGLE2;
- if( delta_angle( to->angles[2], from->angles[2] ) )
+ if (delta_angle(to->angles[2], from->angles[2]))
bits |= U_ANGLE3;
}
- if( flags & MSG_ES_NEWENTITY ) {
- if( delta_pos_v( to->old_origin, from->origin ) ) {
+ if (flags & MSG_ES_NEWENTITY) {
+ if (delta_pos_v(to->old_origin, from->origin)) {
bits |= U_OLDORIGIN;
}
}
}
- if( flags & MSG_ES_UMASK ) {
+ if (flags & MSG_ES_UMASK) {
mask = 0xffff0000;
} else {
mask = 0xffff8000; // don't confuse old clients
}
- if( to->skinnum != from->skinnum ) {
- if( to->skinnum & mask ) {
- bits |= U_SKIN8|U_SKIN16;
- } else if( to->skinnum & 0x0000ff00 ) {
+ if (to->skinnum != from->skinnum) {
+ if (to->skinnum & mask) {
+ bits |= U_SKIN8 | U_SKIN16;
+ } else if (to->skinnum & 0x0000ff00) {
bits |= U_SKIN16;
} else {
bits |= U_SKIN8;
}
}
-
- if( to->frame != from->frame ) {
- if( to->frame < 256 )
+
+ if (to->frame != from->frame) {
+ if (to->frame < 256)
bits |= U_FRAME8;
else
bits |= U_FRAME16;
}
- if( to->effects != from->effects ) {
- if( to->effects & mask ) {
- bits |= U_EFFECTS8|U_EFFECTS16;
- } else if( to->effects & 0x0000ff00 ) {
+ if (to->effects != from->effects) {
+ if (to->effects & mask) {
+ bits |= U_EFFECTS8 | U_EFFECTS16;
+ } else if (to->effects & 0x0000ff00) {
bits |= U_EFFECTS16;
} else {
bits |= U_EFFECTS8;
}
}
-
- if( to->renderfx != from->renderfx ) {
- if( to->renderfx & mask ) {
- bits |= U_RENDERFX8|U_RENDERFX16;
- } else if( to->renderfx & 0x0000ff00 ) {
+
+ if (to->renderfx != from->renderfx) {
+ if (to->renderfx & mask) {
+ bits |= U_RENDERFX8 | U_RENDERFX16;
+ } else if (to->renderfx & 0x0000ff00) {
bits |= U_RENDERFX16;
} else {
bits |= U_RENDERFX8;
}
}
-
- if( to->solid != from->solid )
+
+ if (to->solid != from->solid)
bits |= U_SOLID;
// event is not delta compressed, just 0 compressed
- if( to->event )
+ if (to->event)
bits |= U_EVENT;
-
- if( to->modelindex != from->modelindex )
+
+ if (to->modelindex != from->modelindex)
bits |= U_MODEL;
- if( to->modelindex2 != from->modelindex2 )
+ if (to->modelindex2 != from->modelindex2)
bits |= U_MODEL2;
- if( to->modelindex3 != from->modelindex3 )
+ if (to->modelindex3 != from->modelindex3)
bits |= U_MODEL3;
- if( to->modelindex4 != from->modelindex4 )
+ if (to->modelindex4 != from->modelindex4)
bits |= U_MODEL4;
- if( to->sound != from->sound )
+ if (to->sound != from->sound)
bits |= U_SOUND;
- if( to->renderfx & RF_FRAMELERP ) {
+ if (to->renderfx & RF_FRAMELERP) {
bits |= U_OLDORIGIN;
- } else if( to->renderfx & RF_BEAM ) {
- if( flags & MSG_ES_BEAMORIGIN ) {
- if( delta_pos_v( to->old_origin, from->old_origin ) )
+ } else if (to->renderfx & RF_BEAM) {
+ if (flags & MSG_ES_BEAMORIGIN) {
+ if (delta_pos_v(to->old_origin, from->old_origin))
bits |= U_OLDORIGIN;
} else {
bits |= U_OLDORIGIN;
@@ -634,10 +648,10 @@ void MSG_WriteDeltaEntity( const entity_state_t *from,
//
// write the message
//
- if( !bits && !( flags & MSG_ES_FORCE ) )
+ if (!bits && !(flags & MSG_ES_FORCE))
return; // nothing to send!
- if( flags & MSG_ES_REMOVE ) {
+ if (flags & MSG_ES_REMOVE) {
bits |= U_REMOVE; // used for MVD stream only
}
@@ -653,67 +667,67 @@ void MSG_WriteDeltaEntity( const entity_state_t *from,
else if (bits & 0x0000ff00)
bits |= U_MOREBITS1;
- MSG_WriteByte (bits&255 );
+ MSG_WriteByte(bits & 255);
if (bits & 0xff000000) {
- MSG_WriteByte ((bits>>8)&255 );
- MSG_WriteByte ((bits>>16)&255 );
- MSG_WriteByte ((bits>>24)&255 );
+ MSG_WriteByte((bits >> 8) & 255);
+ MSG_WriteByte((bits >> 16) & 255);
+ MSG_WriteByte((bits >> 24) & 255);
} else if (bits & 0x00ff0000) {
- MSG_WriteByte ((bits>>8)&255 );
- MSG_WriteByte ((bits>>16)&255 );
+ MSG_WriteByte((bits >> 8) & 255);
+ MSG_WriteByte((bits >> 16) & 255);
} else if (bits & 0x0000ff00) {
- MSG_WriteByte ((bits>>8)&255 );
+ MSG_WriteByte((bits >> 8) & 255);
}
//----------
if (bits & U_NUMBER16)
- MSG_WriteShort (to->number);
+ MSG_WriteShort(to->number);
else
- MSG_WriteByte (to->number);
+ MSG_WriteByte(to->number);
if (bits & U_MODEL)
- MSG_WriteByte (to->modelindex);
+ MSG_WriteByte(to->modelindex);
if (bits & U_MODEL2)
- MSG_WriteByte (to->modelindex2);
+ MSG_WriteByte(to->modelindex2);
if (bits & U_MODEL3)
- MSG_WriteByte (to->modelindex3);
+ MSG_WriteByte(to->modelindex3);
if (bits & U_MODEL4)
- MSG_WriteByte (to->modelindex4);
+ MSG_WriteByte(to->modelindex4);
if (bits & U_FRAME8)
- MSG_WriteByte (to->frame);
+ MSG_WriteByte(to->frame);
else if (bits & U_FRAME16)
- MSG_WriteShort (to->frame);
+ MSG_WriteShort(to->frame);
- if ((bits & (U_SKIN8|U_SKIN16)) == (U_SKIN8|U_SKIN16) ) //used for laser colors
- MSG_WriteLong (to->skinnum);
+ if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16)) //used for laser colors
+ MSG_WriteLong(to->skinnum);
else if (bits & U_SKIN8)
- MSG_WriteByte (to->skinnum);
+ MSG_WriteByte(to->skinnum);
else if (bits & U_SKIN16)
- MSG_WriteShort (to->skinnum);
+ MSG_WriteShort(to->skinnum);
- if ( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) )
- MSG_WriteLong (to->effects);
+ if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
+ MSG_WriteLong(to->effects);
else if (bits & U_EFFECTS8)
- MSG_WriteByte (to->effects);
+ MSG_WriteByte(to->effects);
else if (bits & U_EFFECTS16)
- MSG_WriteShort (to->effects);
+ MSG_WriteShort(to->effects);
- if ( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) )
- MSG_WriteLong (to->renderfx);
+ if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
+ MSG_WriteLong(to->renderfx);
else if (bits & U_RENDERFX8)
- MSG_WriteByte (to->renderfx);
+ MSG_WriteByte(to->renderfx);
else if (bits & U_RENDERFX16)
- MSG_WriteShort (to->renderfx);
+ MSG_WriteShort(to->renderfx);
if (bits & U_ORIGIN1)
- MSG_WriteCoord (to->origin[0]);
+ MSG_WriteCoord(to->origin[0]);
if (bits & U_ORIGIN2)
- MSG_WriteCoord (to->origin[1]);
+ MSG_WriteCoord(to->origin[1]);
if (bits & U_ORIGIN3)
- MSG_WriteCoord (to->origin[2]);
+ MSG_WriteCoord(to->origin[2]);
if ((flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16)) {
if (bits & U_ANGLE1)
@@ -732,17 +746,17 @@ void MSG_WriteDeltaEntity( const entity_state_t *from,
}
if (bits & U_OLDORIGIN)
- MSG_WritePos (to->old_origin);
+ MSG_WritePos(to->old_origin);
if (bits & U_SOUND)
- MSG_WriteByte (to->sound);
+ MSG_WriteByte(to->sound);
if (bits & U_EVENT)
- MSG_WriteByte (to->event);
+ MSG_WriteByte(to->event);
if (bits & U_SOLID) {
- if( flags & MSG_ES_LONGSOLID ) {
- MSG_WriteLong (to->solid);
+ if (flags & MSG_ES_LONGSOLID) {
+ MSG_WriteLong(to->solid);
} else {
- MSG_WriteShort (to->solid);
+ MSG_WriteShort(to->solid);
}
}
}
@@ -752,16 +766,17 @@ void MSG_WriteDeltaEntity( const entity_state_t *from,
MSG_WriteDeltaPlayerstate_Default
==================
*/
-void MSG_WriteDeltaPlayerstate_Default( const player_state_t *from, const player_state_t *to ) {
+void MSG_WriteDeltaPlayerstate_Default(const player_state_t *from, const player_state_t *to)
+{
int i;
int pflags;
int statbits;
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
- if( !from ) {
+ if (!from) {
from = &nullPlayerState;
}
@@ -770,168 +785,164 @@ void MSG_WriteDeltaPlayerstate_Default( const player_state_t *from, const player
//
pflags = 0;
- if( to->pmove.pm_type != from->pmove.pm_type )
+ if (to->pmove.pm_type != from->pmove.pm_type)
pflags |= PS_M_TYPE;
- if( to->pmove.origin[0] != from->pmove.origin[0] ||
+ if (to->pmove.origin[0] != from->pmove.origin[0] ||
to->pmove.origin[1] != from->pmove.origin[1] ||
- to->pmove.origin[2] != from->pmove.origin[2] )
- {
+ to->pmove.origin[2] != from->pmove.origin[2]) {
pflags |= PS_M_ORIGIN;
}
- if( to->pmove.velocity[0] != from->pmove.velocity[0] ||
+ if (to->pmove.velocity[0] != from->pmove.velocity[0] ||
to->pmove.velocity[1] != from->pmove.velocity[1] ||
- to->pmove.velocity[2] != from->pmove.velocity[2] )
- {
+ to->pmove.velocity[2] != from->pmove.velocity[2]) {
pflags |= PS_M_VELOCITY;
}
- if( to->pmove.pm_time != from->pmove.pm_time )
+ if (to->pmove.pm_time != from->pmove.pm_time)
pflags |= PS_M_TIME;
- if( to->pmove.pm_flags != from->pmove.pm_flags )
+ if (to->pmove.pm_flags != from->pmove.pm_flags)
pflags |= PS_M_FLAGS;
- if( to->pmove.gravity != from->pmove.gravity )
+ if (to->pmove.gravity != from->pmove.gravity)
pflags |= PS_M_GRAVITY;
- if( to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
+ if (to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
to->pmove.delta_angles[1] != from->pmove.delta_angles[1] ||
- to->pmove.delta_angles[2] != from->pmove.delta_angles[2] )
- {
+ to->pmove.delta_angles[2] != from->pmove.delta_angles[2]) {
pflags |= PS_M_DELTA_ANGLES;
}
- if( delta_ofs_v( to->viewoffset, from->viewoffset ) ) {
+ if (delta_ofs_v(to->viewoffset, from->viewoffset)) {
pflags |= PS_VIEWOFFSET;
}
- if( delta_angle16_v( to->viewangles, from->viewangles ) ) {
+ if (delta_angle16_v(to->viewangles, from->viewangles)) {
pflags |= PS_VIEWANGLES;
}
- if( delta_ofs_v( to->kick_angles, from->kick_angles ) ) {
+ if (delta_ofs_v(to->kick_angles, from->kick_angles)) {
pflags |= PS_KICKANGLES;
}
- if( delta_blend_v( to->blend, from->blend ) ) {
+ if (delta_blend_v(to->blend, from->blend)) {
pflags |= PS_BLEND;
}
- if( delta_fov( to->fov, from->fov ) )
+ if (delta_fov(to->fov, from->fov))
pflags |= PS_FOV;
- if( to->rdflags != from->rdflags )
+ if (to->rdflags != from->rdflags)
pflags |= PS_RDFLAGS;
- if( to->gunframe != from->gunframe ||
- delta_ofs_v( to->gunoffset, from->gunoffset ) ||
- delta_ofs_v( to->gunangles, from->gunangles ) )
- {
+ if (to->gunframe != from->gunframe ||
+ delta_ofs_v(to->gunoffset, from->gunoffset) ||
+ delta_ofs_v(to->gunangles, from->gunangles)) {
pflags |= PS_WEAPONFRAME;
}
- if( to->gunindex != from->gunindex )
+ if (to->gunindex != from->gunindex)
pflags |= PS_WEAPONINDEX;
//
// write it
//
- MSG_WriteShort( pflags );
+ MSG_WriteShort(pflags);
//
// write the pmove_state_t
//
- if( pflags & PS_M_TYPE )
- MSG_WriteByte( to->pmove.pm_type );
+ if (pflags & PS_M_TYPE)
+ MSG_WriteByte(to->pmove.pm_type);
- if( pflags & PS_M_ORIGIN ) {
- MSG_WriteShort( to->pmove.origin[0] );
- MSG_WriteShort( to->pmove.origin[1] );
- MSG_WriteShort( to->pmove.origin[2] );
+ if (pflags & PS_M_ORIGIN) {
+ MSG_WriteShort(to->pmove.origin[0]);
+ MSG_WriteShort(to->pmove.origin[1]);
+ MSG_WriteShort(to->pmove.origin[2]);
}
- if( pflags & PS_M_VELOCITY ) {
- MSG_WriteShort( to->pmove.velocity[0] );
- MSG_WriteShort( to->pmove.velocity[1] );
- MSG_WriteShort( to->pmove.velocity[2] );
+ if (pflags & PS_M_VELOCITY) {
+ MSG_WriteShort(to->pmove.velocity[0]);
+ MSG_WriteShort(to->pmove.velocity[1]);
+ MSG_WriteShort(to->pmove.velocity[2]);
}
- if( pflags & PS_M_TIME )
- MSG_WriteByte( to->pmove.pm_time );
+ if (pflags & PS_M_TIME)
+ MSG_WriteByte(to->pmove.pm_time);
- if( pflags & PS_M_FLAGS )
- MSG_WriteByte( to->pmove.pm_flags );
+ if (pflags & PS_M_FLAGS)
+ MSG_WriteByte(to->pmove.pm_flags);
- if( pflags & PS_M_GRAVITY )
- MSG_WriteShort( to->pmove.gravity );
+ if (pflags & PS_M_GRAVITY)
+ MSG_WriteShort(to->pmove.gravity);
- if( pflags & PS_M_DELTA_ANGLES ) {
- MSG_WriteShort( to->pmove.delta_angles[0] );
- MSG_WriteShort( to->pmove.delta_angles[1] );
- MSG_WriteShort( to->pmove.delta_angles[2] );
+ if (pflags & PS_M_DELTA_ANGLES) {
+ MSG_WriteShort(to->pmove.delta_angles[0]);
+ MSG_WriteShort(to->pmove.delta_angles[1]);
+ MSG_WriteShort(to->pmove.delta_angles[2]);
}
//
// write the rest of the player_state_t
//
- if( pflags & PS_VIEWOFFSET ) {
- MSG_WriteChar( to->viewoffset[0] * 4 );
- MSG_WriteChar( to->viewoffset[1] * 4 );
- MSG_WriteChar( to->viewoffset[2] * 4 );
+ if (pflags & PS_VIEWOFFSET) {
+ MSG_WriteChar(to->viewoffset[0] * 4);
+ MSG_WriteChar(to->viewoffset[1] * 4);
+ MSG_WriteChar(to->viewoffset[2] * 4);
}
- if( pflags & PS_VIEWANGLES ) {
- MSG_WriteAngle16( to->viewangles[0] );
- MSG_WriteAngle16( to->viewangles[1] );
- MSG_WriteAngle16( to->viewangles[2] );
+ if (pflags & PS_VIEWANGLES) {
+ MSG_WriteAngle16(to->viewangles[0]);
+ MSG_WriteAngle16(to->viewangles[1]);
+ MSG_WriteAngle16(to->viewangles[2]);
}
- if( pflags & PS_KICKANGLES ) {
- MSG_WriteChar( to->kick_angles[0] * 4 );
- MSG_WriteChar( to->kick_angles[1] * 4 );
- MSG_WriteChar( to->kick_angles[2] * 4 );
+ if (pflags & PS_KICKANGLES) {
+ MSG_WriteChar(to->kick_angles[0] * 4);
+ MSG_WriteChar(to->kick_angles[1] * 4);
+ MSG_WriteChar(to->kick_angles[2] * 4);
}
- if( pflags & PS_WEAPONINDEX ) {
- MSG_WriteByte( to->gunindex );
+ if (pflags & PS_WEAPONINDEX) {
+ MSG_WriteByte(to->gunindex);
}
- if( pflags & PS_WEAPONFRAME ) {
- MSG_WriteByte( to->gunframe );
- MSG_WriteChar( to->gunoffset[0] * 4 );
- MSG_WriteChar( to->gunoffset[1] * 4 );
- MSG_WriteChar( to->gunoffset[2] * 4 );
- MSG_WriteChar( to->gunangles[0] * 4 );
- MSG_WriteChar( to->gunangles[1] * 4 );
- MSG_WriteChar( to->gunangles[2] * 4 );
+ if (pflags & PS_WEAPONFRAME) {
+ MSG_WriteByte(to->gunframe);
+ MSG_WriteChar(to->gunoffset[0] * 4);
+ MSG_WriteChar(to->gunoffset[1] * 4);
+ MSG_WriteChar(to->gunoffset[2] * 4);
+ MSG_WriteChar(to->gunangles[0] * 4);
+ MSG_WriteChar(to->gunangles[1] * 4);
+ MSG_WriteChar(to->gunangles[2] * 4);
}
- if( pflags & PS_BLEND ) {
- MSG_WriteByte( to->blend[0] * 255 );
- MSG_WriteByte( to->blend[1] * 255 );
- MSG_WriteByte( to->blend[2] * 255 );
- MSG_WriteByte( to->blend[3] * 255 );
+ if (pflags & PS_BLEND) {
+ MSG_WriteByte(to->blend[0] * 255);
+ MSG_WriteByte(to->blend[1] * 255);
+ MSG_WriteByte(to->blend[2] * 255);
+ MSG_WriteByte(to->blend[3] * 255);
}
- if( pflags & PS_FOV )
- MSG_WriteByte( to->fov );
+ if (pflags & PS_FOV)
+ MSG_WriteByte(to->fov);
- if( pflags & PS_RDFLAGS )
- MSG_WriteByte( to->rdflags );
+ if (pflags & PS_RDFLAGS)
+ MSG_WriteByte(to->rdflags);
// send stats
statbits = 0;
- for( i = 0; i < MAX_STATS; i++ )
- if( to->stats[i] != from->stats[i] )
+ for (i = 0; i < MAX_STATS; i++)
+ if (to->stats[i] != from->stats[i])
statbits |= 1 << i;
- MSG_WriteLong( statbits );
- for( i = 0; i < MAX_STATS; i++ )
- if( statbits & ( 1 << i ) )
- MSG_WriteShort( to->stats[i] );
+ MSG_WriteLong(statbits);
+ for (i = 0; i < MAX_STATS; i++)
+ if (statbits & (1 << i))
+ MSG_WriteShort(to->stats[i]);
}
/*
@@ -939,19 +950,19 @@ void MSG_WriteDeltaPlayerstate_Default( const player_state_t *from, const player
MSG_WriteDeltaPlayerstate_Enhanced
==================
*/
-int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from,
- player_state_t *to,
- msgPsFlags_t flags )
+int MSG_WriteDeltaPlayerstate_Enhanced(const player_state_t *from,
+ player_state_t *to,
+ msgPsFlags_t flags)
{
int i;
int pflags, extraflags;
int statbits;
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
- if( !from ) {
+ if (!from) {
from = &nullPlayerState;
}
@@ -961,70 +972,66 @@ int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from,
pflags = 0;
extraflags = 0;
- if( to->pmove.pm_type != from->pmove.pm_type )
+ if (to->pmove.pm_type != from->pmove.pm_type)
pflags |= PS_M_TYPE;
- if( to->pmove.origin[0] != from->pmove.origin[0] ||
- to->pmove.origin[1] != from->pmove.origin[1] )
- {
+ if (to->pmove.origin[0] != from->pmove.origin[0] ||
+ to->pmove.origin[1] != from->pmove.origin[1]) {
pflags |= PS_M_ORIGIN;
}
- if( to->pmove.origin[2] != from->pmove.origin[2] ) {
+ if (to->pmove.origin[2] != from->pmove.origin[2]) {
extraflags |= EPS_M_ORIGIN2;
}
- if( !( flags & MSG_PS_IGNORE_PREDICTION ) ) {
- if( to->pmove.velocity[0] != from->pmove.velocity[0] ||
- to->pmove.velocity[1] != from->pmove.velocity[1] )
- {
+ if (!(flags & MSG_PS_IGNORE_PREDICTION)) {
+ if (to->pmove.velocity[0] != from->pmove.velocity[0] ||
+ to->pmove.velocity[1] != from->pmove.velocity[1]) {
pflags |= PS_M_VELOCITY;
}
- if( to->pmove.velocity[2] != from->pmove.velocity[2] ) {
+ if (to->pmove.velocity[2] != from->pmove.velocity[2]) {
extraflags |= EPS_M_VELOCITY2;
}
- if( to->pmove.pm_time != from->pmove.pm_time )
+ if (to->pmove.pm_time != from->pmove.pm_time)
pflags |= PS_M_TIME;
- if( to->pmove.pm_flags != from->pmove.pm_flags )
+ if (to->pmove.pm_flags != from->pmove.pm_flags)
pflags |= PS_M_FLAGS;
- if( to->pmove.gravity != from->pmove.gravity )
+ if (to->pmove.gravity != from->pmove.gravity)
pflags |= PS_M_GRAVITY;
} else {
// save previous state
- VectorCopy( from->pmove.velocity, to->pmove.velocity );
+ VectorCopy(from->pmove.velocity, to->pmove.velocity);
to->pmove.pm_time = from->pmove.pm_time;
to->pmove.pm_flags = from->pmove.pm_flags;
to->pmove.gravity = from->pmove.gravity;
}
- if( !( flags & MSG_PS_IGNORE_DELTAANGLES ) ) {
- if( to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
+ if (!(flags & MSG_PS_IGNORE_DELTAANGLES)) {
+ if (to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
to->pmove.delta_angles[1] != from->pmove.delta_angles[1] ||
- to->pmove.delta_angles[2] != from->pmove.delta_angles[2] )
- {
+ to->pmove.delta_angles[2] != from->pmove.delta_angles[2]) {
pflags |= PS_M_DELTA_ANGLES;
}
} else {
// save previous state
- VectorCopy( from->pmove.delta_angles, to->pmove.delta_angles );
+ VectorCopy(from->pmove.delta_angles, to->pmove.delta_angles);
}
- if( delta_ofs_v( from->viewoffset, to->viewoffset ) ) {
+ if (delta_ofs_v(from->viewoffset, to->viewoffset)) {
pflags |= PS_VIEWOFFSET;
}
- if( !( flags & MSG_PS_IGNORE_VIEWANGLES ) ) {
- if( delta_angle16( from->viewangles[0], to->viewangles[0] ) ||
- delta_angle16( from->viewangles[1], to->viewangles[1] ) )
- {
+ if (!(flags & MSG_PS_IGNORE_VIEWANGLES)) {
+ if (delta_angle16(from->viewangles[0], to->viewangles[0]) ||
+ delta_angle16(from->viewangles[1], to->viewangles[1])) {
pflags |= PS_VIEWANGLES;
}
- if( delta_angle16( from->viewangles[2], to->viewangles[2] ) ) {
+ if (delta_angle16(from->viewangles[2], to->viewangles[2])) {
extraflags |= EPS_VIEWANGLE2;
}
} else {
@@ -1034,12 +1041,12 @@ int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from,
to->viewangles[2] = from->viewangles[2];
}
- if( delta_ofs_v( from->kick_angles, to->kick_angles ) ) {
+ if (delta_ofs_v(from->kick_angles, to->kick_angles)) {
pflags |= PS_KICKANGLES;
}
- if( !( flags & MSG_PS_IGNORE_BLEND ) ) {
- if( delta_blend_v( from->blend, to->blend ) ) {
+ if (!(flags & MSG_PS_IGNORE_BLEND)) {
+ if (delta_blend_v(from->blend, to->blend)) {
pflags |= PS_BLEND;
}
} else {
@@ -1050,33 +1057,33 @@ int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from,
to->blend[3] = from->blend[3];
}
- if( delta_fov( from->fov, to->fov ) )
+ if (delta_fov(from->fov, to->fov))
pflags |= PS_FOV;
- if( to->rdflags != from->rdflags )
+ if (to->rdflags != from->rdflags)
pflags |= PS_RDFLAGS;
- if( !( flags & MSG_PS_IGNORE_GUNINDEX ) ) {
- if( to->gunindex != from->gunindex )
+ if (!(flags & MSG_PS_IGNORE_GUNINDEX)) {
+ if (to->gunindex != from->gunindex)
pflags |= PS_WEAPONINDEX;
} else {
// save previous state
to->gunindex = from->gunindex;
}
- if( !( flags & MSG_PS_IGNORE_GUNFRAMES ) ) {
- if( to->gunframe != from->gunframe )
+ if (!(flags & MSG_PS_IGNORE_GUNFRAMES)) {
+ if (to->gunframe != from->gunframe)
pflags |= PS_WEAPONFRAME;
- if( delta_ofs_v( from->gunoffset, to->gunoffset ) ) {
+ if (delta_ofs_v(from->gunoffset, to->gunoffset)) {
extraflags |= EPS_GUNOFFSET;
}
- if( delta_ofs_v( from->gunangles, to->gunangles ) ) {
+ if (delta_ofs_v(from->gunangles, to->gunangles)) {
extraflags |= EPS_GUNANGLES;
}
} else {
- // save previous state
+ // save previous state
to->gunframe = from->gunframe;
to->gunoffset[0] = from->gunoffset[0];
@@ -1089,127 +1096,127 @@ int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from,
}
statbits = 0;
- for( i = 0; i < MAX_STATS; i++ ) {
- if( to->stats[i] != from->stats[i] ) {
+ for (i = 0; i < MAX_STATS; i++) {
+ if (to->stats[i] != from->stats[i]) {
statbits |= 1 << i;
}
}
- if( statbits ) {
+ if (statbits) {
extraflags |= EPS_STATS;
}
//
// write it
//
- MSG_WriteShort( pflags );
+ MSG_WriteShort(pflags);
//
// write the pmove_state_t
//
- if( pflags & PS_M_TYPE )
- MSG_WriteByte( to->pmove.pm_type );
+ if (pflags & PS_M_TYPE)
+ MSG_WriteByte(to->pmove.pm_type);
- if( pflags & PS_M_ORIGIN ) {
- MSG_WriteShort( to->pmove.origin[0] );
- MSG_WriteShort( to->pmove.origin[1] );
+ if (pflags & PS_M_ORIGIN) {
+ MSG_WriteShort(to->pmove.origin[0]);
+ MSG_WriteShort(to->pmove.origin[1]);
}
- if( extraflags & EPS_M_ORIGIN2 ) {
- MSG_WriteShort( to->pmove.origin[2] );
+ if (extraflags & EPS_M_ORIGIN2) {
+ MSG_WriteShort(to->pmove.origin[2]);
}
- if( pflags & PS_M_VELOCITY ) {
- MSG_WriteShort( to->pmove.velocity[0] );
- MSG_WriteShort( to->pmove.velocity[1] );
+ if (pflags & PS_M_VELOCITY) {
+ MSG_WriteShort(to->pmove.velocity[0]);
+ MSG_WriteShort(to->pmove.velocity[1]);
}
- if( extraflags & EPS_M_VELOCITY2 ) {
- MSG_WriteShort( to->pmove.velocity[2] );
+ if (extraflags & EPS_M_VELOCITY2) {
+ MSG_WriteShort(to->pmove.velocity[2]);
}
- if( pflags & PS_M_TIME ) {
- MSG_WriteByte( to->pmove.pm_time );
+ if (pflags & PS_M_TIME) {
+ MSG_WriteByte(to->pmove.pm_time);
}
- if( pflags & PS_M_FLAGS ) {
- MSG_WriteByte( to->pmove.pm_flags );
+ if (pflags & PS_M_FLAGS) {
+ MSG_WriteByte(to->pmove.pm_flags);
}
- if( pflags & PS_M_GRAVITY ) {
- MSG_WriteShort( to->pmove.gravity );
+ if (pflags & PS_M_GRAVITY) {
+ MSG_WriteShort(to->pmove.gravity);
}
- if( pflags & PS_M_DELTA_ANGLES ) {
- MSG_WriteShort( to->pmove.delta_angles[0] );
- MSG_WriteShort( to->pmove.delta_angles[1] );
- MSG_WriteShort( to->pmove.delta_angles[2] );
+ if (pflags & PS_M_DELTA_ANGLES) {
+ MSG_WriteShort(to->pmove.delta_angles[0]);
+ MSG_WriteShort(to->pmove.delta_angles[1]);
+ MSG_WriteShort(to->pmove.delta_angles[2]);
}
//
// write the rest of the player_state_t
//
- if( pflags & PS_VIEWOFFSET ) {
- MSG_WriteChar( to->viewoffset[0] * 4 );
- MSG_WriteChar( to->viewoffset[1] * 4 );
- MSG_WriteChar( to->viewoffset[2] * 4 );
+ if (pflags & PS_VIEWOFFSET) {
+ MSG_WriteChar(to->viewoffset[0] * 4);
+ MSG_WriteChar(to->viewoffset[1] * 4);
+ MSG_WriteChar(to->viewoffset[2] * 4);
}
- if( pflags & PS_VIEWANGLES ) {
- MSG_WriteAngle16( to->viewangles[0] );
- MSG_WriteAngle16( to->viewangles[1] );
-
+ if (pflags & PS_VIEWANGLES) {
+ MSG_WriteAngle16(to->viewangles[0]);
+ MSG_WriteAngle16(to->viewangles[1]);
+
}
- if( extraflags & EPS_VIEWANGLE2 ) {
- MSG_WriteAngle16( to->viewangles[2] );
+ if (extraflags & EPS_VIEWANGLE2) {
+ MSG_WriteAngle16(to->viewangles[2]);
}
- if( pflags & PS_KICKANGLES ) {
- MSG_WriteChar( to->kick_angles[0] * 4 );
- MSG_WriteChar( to->kick_angles[1] * 4 );
- MSG_WriteChar( to->kick_angles[2] * 4 );
+ if (pflags & PS_KICKANGLES) {
+ MSG_WriteChar(to->kick_angles[0] * 4);
+ MSG_WriteChar(to->kick_angles[1] * 4);
+ MSG_WriteChar(to->kick_angles[2] * 4);
}
- if( pflags & PS_WEAPONINDEX ) {
- MSG_WriteByte( to->gunindex );
+ if (pflags & PS_WEAPONINDEX) {
+ MSG_WriteByte(to->gunindex);
}
- if( pflags & PS_WEAPONFRAME ) {
- MSG_WriteByte( to->gunframe );
+ if (pflags & PS_WEAPONFRAME) {
+ MSG_WriteByte(to->gunframe);
}
- if( extraflags & EPS_GUNOFFSET ) {
- MSG_WriteChar( to->gunoffset[0] * 4 );
- MSG_WriteChar( to->gunoffset[1] * 4 );
- MSG_WriteChar( to->gunoffset[2] * 4 );
+ if (extraflags & EPS_GUNOFFSET) {
+ MSG_WriteChar(to->gunoffset[0] * 4);
+ MSG_WriteChar(to->gunoffset[1] * 4);
+ MSG_WriteChar(to->gunoffset[2] * 4);
}
- if( extraflags & EPS_GUNANGLES ) {
- MSG_WriteChar( to->gunangles[0] * 4 );
- MSG_WriteChar( to->gunangles[1] * 4 );
- MSG_WriteChar( to->gunangles[2] * 4 );
+ if (extraflags & EPS_GUNANGLES) {
+ MSG_WriteChar(to->gunangles[0] * 4);
+ MSG_WriteChar(to->gunangles[1] * 4);
+ MSG_WriteChar(to->gunangles[2] * 4);
}
- if( pflags & PS_BLEND ) {
- MSG_WriteByte( to->blend[0] * 255 );
- MSG_WriteByte( to->blend[1] * 255 );
- MSG_WriteByte( to->blend[2] * 255 );
- MSG_WriteByte( to->blend[3] * 255 );
+ if (pflags & PS_BLEND) {
+ MSG_WriteByte(to->blend[0] * 255);
+ MSG_WriteByte(to->blend[1] * 255);
+ MSG_WriteByte(to->blend[2] * 255);
+ MSG_WriteByte(to->blend[3] * 255);
}
- if( pflags & PS_FOV )
- MSG_WriteByte( to->fov );
+ if (pflags & PS_FOV)
+ MSG_WriteByte(to->fov);
- if( pflags & PS_RDFLAGS )
- MSG_WriteByte( to->rdflags );
+ if (pflags & PS_RDFLAGS)
+ MSG_WriteByte(to->rdflags);
// send stats
- if( extraflags & EPS_STATS ) {
- MSG_WriteLong( statbits );
- for( i = 0; i < MAX_STATS; i++ ) {
- if( statbits & ( 1 << i ) ) {
- MSG_WriteShort( to->stats[i] );
+ if (extraflags & EPS_STATS) {
+ MSG_WriteLong(statbits);
+ for (i = 0; i < MAX_STATS; i++) {
+ if (statbits & (1 << i)) {
+ MSG_WriteShort(to->stats[i]);
}
}
}
@@ -1227,26 +1234,26 @@ Throw away most of the pmove_state_t fields as they are used only
for client prediction, and not needed in MVDs.
==================
*/
-void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from,
- const player_state_t *to,
- int number,
- msgPsFlags_t flags )
+void MSG_WriteDeltaPlayerstate_Packet(const player_state_t *from,
+ const player_state_t *to,
+ int number,
+ msgPsFlags_t flags)
{
int i;
int pflags;
int statbits;
- if( number < 0 || number >= MAX_CLIENTS ) {
- Com_Error( ERR_DROP, "%s: bad number: %d", __func__, number );
+ if (number < 0 || number >= MAX_CLIENTS) {
+ Com_Error(ERR_DROP, "%s: bad number: %d", __func__, number);
}
- if( !to ) {
- MSG_WriteByte( number );
- MSG_WriteShort( PPS_REMOVE );
+ if (!to) {
+ MSG_WriteByte(number);
+ MSG_WriteShort(PPS_REMOVE);
return;
}
- if( !from ) {
+ if (!from) {
from = &nullPlayerState;
}
@@ -1255,167 +1262,165 @@ void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from,
//
pflags = 0;
- if( to->pmove.pm_type != from->pmove.pm_type )
+ if (to->pmove.pm_type != from->pmove.pm_type)
pflags |= PPS_M_TYPE;
- if( to->pmove.origin[0] != from->pmove.origin[0] ||
- to->pmove.origin[1] != from->pmove.origin[1] )
- {
+ if (to->pmove.origin[0] != from->pmove.origin[0] ||
+ to->pmove.origin[1] != from->pmove.origin[1]) {
pflags |= PPS_M_ORIGIN;
}
- if( to->pmove.origin[2] != from->pmove.origin[2] ) {
+ if (to->pmove.origin[2] != from->pmove.origin[2]) {
pflags |= PPS_M_ORIGIN2;
}
- if( delta_ofs_v( from->viewoffset, to->viewoffset ) ) {
+ if (delta_ofs_v(from->viewoffset, to->viewoffset)) {
pflags |= PPS_VIEWOFFSET;
}
- if( delta_angle16( from->viewangles[0], to->viewangles[0] ) ||
- delta_angle16( from->viewangles[1], to->viewangles[1] ) )
- {
+ if (delta_angle16(from->viewangles[0], to->viewangles[0]) ||
+ delta_angle16(from->viewangles[1], to->viewangles[1])) {
pflags |= PPS_VIEWANGLES;
}
- if( delta_angle16( from->viewangles[2], to->viewangles[2] ) ) {
+ if (delta_angle16(from->viewangles[2], to->viewangles[2])) {
pflags |= PPS_VIEWANGLE2;
}
- if( delta_ofs_v( from->kick_angles, to->kick_angles ) ) {
+ if (delta_ofs_v(from->kick_angles, to->kick_angles)) {
pflags |= PPS_KICKANGLES;
}
- if( !( flags & MSG_PS_IGNORE_BLEND ) ) {
- if( delta_blend_v( from->blend, to->blend ) ) {
+ if (!(flags & MSG_PS_IGNORE_BLEND)) {
+ if (delta_blend_v(from->blend, to->blend)) {
pflags |= PPS_BLEND;
}
}
- if( delta_fov( from->fov, to->fov ) )
+ if (delta_fov(from->fov, to->fov))
pflags |= PPS_FOV;
- if( to->rdflags != from->rdflags )
+ if (to->rdflags != from->rdflags)
pflags |= PPS_RDFLAGS;
- if( !( flags & MSG_PS_IGNORE_GUNINDEX ) ) {
- if( to->gunindex != from->gunindex )
+ if (!(flags & MSG_PS_IGNORE_GUNINDEX)) {
+ if (to->gunindex != from->gunindex)
pflags |= PPS_WEAPONINDEX;
}
- if( !( flags & MSG_PS_IGNORE_GUNFRAMES ) ) {
- if( to->gunframe != from->gunframe )
+ if (!(flags & MSG_PS_IGNORE_GUNFRAMES)) {
+ if (to->gunframe != from->gunframe)
pflags |= PPS_WEAPONFRAME;
- if( delta_ofs_v( from->gunoffset, to->gunoffset ) ) {
+ if (delta_ofs_v(from->gunoffset, to->gunoffset)) {
pflags |= PPS_GUNOFFSET;
}
- if( delta_ofs_v( from->gunangles, to->gunangles ) ) {
+ if (delta_ofs_v(from->gunangles, to->gunangles)) {
pflags |= PPS_GUNANGLES;
}
}
statbits = 0;
- for( i = 0; i < MAX_STATS; i++ ) {
- if( to->stats[i] != from->stats[i] ) {
+ for (i = 0; i < MAX_STATS; i++) {
+ if (to->stats[i] != from->stats[i]) {
statbits |= 1 << i;
pflags |= PPS_STATS;
}
}
- if( !pflags && !( flags & MSG_PS_FORCE ) ) {
+ if (!pflags && !(flags & MSG_PS_FORCE)) {
return;
}
- if( flags & MSG_PS_REMOVE ) {
+ if (flags & MSG_PS_REMOVE) {
pflags |= PPS_REMOVE; // used for MVD stream only
}
//
// write it
//
- MSG_WriteByte( number );
- MSG_WriteShort( pflags );
+ MSG_WriteByte(number);
+ MSG_WriteShort(pflags);
//
// write some part of the pmove_state_t
//
- if( pflags & PPS_M_TYPE )
- MSG_WriteByte( to->pmove.pm_type );
+ if (pflags & PPS_M_TYPE)
+ MSG_WriteByte(to->pmove.pm_type);
- if( pflags & PPS_M_ORIGIN ) {
- MSG_WriteShort( to->pmove.origin[0] );
- MSG_WriteShort( to->pmove.origin[1] );
+ if (pflags & PPS_M_ORIGIN) {
+ MSG_WriteShort(to->pmove.origin[0]);
+ MSG_WriteShort(to->pmove.origin[1]);
}
- if( pflags & PPS_M_ORIGIN2 ) {
- MSG_WriteShort( to->pmove.origin[2] );
+ if (pflags & PPS_M_ORIGIN2) {
+ MSG_WriteShort(to->pmove.origin[2]);
}
//
// write the rest of the player_state_t
//
- if( pflags & PPS_VIEWOFFSET ) {
- MSG_WriteChar( to->viewoffset[0] * 4 );
- MSG_WriteChar( to->viewoffset[1] * 4 );
- MSG_WriteChar( to->viewoffset[2] * 4 );
+ if (pflags & PPS_VIEWOFFSET) {
+ MSG_WriteChar(to->viewoffset[0] * 4);
+ MSG_WriteChar(to->viewoffset[1] * 4);
+ MSG_WriteChar(to->viewoffset[2] * 4);
}
- if( pflags & PPS_VIEWANGLES ) {
- MSG_WriteAngle16( to->viewangles[0] );
- MSG_WriteAngle16( to->viewangles[1] );
+ if (pflags & PPS_VIEWANGLES) {
+ MSG_WriteAngle16(to->viewangles[0]);
+ MSG_WriteAngle16(to->viewangles[1]);
}
- if( pflags & PPS_VIEWANGLE2 ) {
- MSG_WriteAngle16( to->viewangles[2] );
+ if (pflags & PPS_VIEWANGLE2) {
+ MSG_WriteAngle16(to->viewangles[2]);
}
- if( pflags & PPS_KICKANGLES ) {
- MSG_WriteChar( to->kick_angles[0] * 4 );
- MSG_WriteChar( to->kick_angles[1] * 4 );
- MSG_WriteChar( to->kick_angles[2] * 4 );
+ if (pflags & PPS_KICKANGLES) {
+ MSG_WriteChar(to->kick_angles[0] * 4);
+ MSG_WriteChar(to->kick_angles[1] * 4);
+ MSG_WriteChar(to->kick_angles[2] * 4);
}
- if( pflags & PPS_WEAPONINDEX ) {
- MSG_WriteByte( to->gunindex );
+ if (pflags & PPS_WEAPONINDEX) {
+ MSG_WriteByte(to->gunindex);
}
- if( pflags & PPS_WEAPONFRAME ) {
- MSG_WriteByte( to->gunframe );
+ if (pflags & PPS_WEAPONFRAME) {
+ MSG_WriteByte(to->gunframe);
}
- if( pflags & PPS_GUNOFFSET ) {
- MSG_WriteChar( to->gunoffset[0] * 4 );
- MSG_WriteChar( to->gunoffset[1] * 4 );
- MSG_WriteChar( to->gunoffset[2] * 4 );
+ if (pflags & PPS_GUNOFFSET) {
+ MSG_WriteChar(to->gunoffset[0] * 4);
+ MSG_WriteChar(to->gunoffset[1] * 4);
+ MSG_WriteChar(to->gunoffset[2] * 4);
}
- if( pflags & PPS_GUNANGLES ) {
- MSG_WriteChar( to->gunangles[0] * 4 );
- MSG_WriteChar( to->gunangles[1] * 4 );
- MSG_WriteChar( to->gunangles[2] * 4 );
+ if (pflags & PPS_GUNANGLES) {
+ MSG_WriteChar(to->gunangles[0] * 4);
+ MSG_WriteChar(to->gunangles[1] * 4);
+ MSG_WriteChar(to->gunangles[2] * 4);
}
- if( pflags & PPS_BLEND ) {
- MSG_WriteByte( to->blend[0] * 255 );
- MSG_WriteByte( to->blend[1] * 255 );
- MSG_WriteByte( to->blend[2] * 255 );
- MSG_WriteByte( to->blend[3] * 255 );
+ if (pflags & PPS_BLEND) {
+ MSG_WriteByte(to->blend[0] * 255);
+ MSG_WriteByte(to->blend[1] * 255);
+ MSG_WriteByte(to->blend[2] * 255);
+ MSG_WriteByte(to->blend[3] * 255);
}
- if( pflags & PPS_FOV )
- MSG_WriteByte( to->fov );
+ if (pflags & PPS_FOV)
+ MSG_WriteByte(to->fov);
- if( pflags & PPS_RDFLAGS )
- MSG_WriteByte( to->rdflags );
+ if (pflags & PPS_RDFLAGS)
+ MSG_WriteByte(to->rdflags);
// send stats
- if( pflags & PPS_STATS ) {
- MSG_WriteLong( statbits );
- for( i = 0; i < MAX_STATS; i++ ) {
- if( statbits & ( 1 << i ) ) {
- MSG_WriteShort( to->stats[i] );
+ if (pflags & PPS_STATS) {
+ MSG_WriteLong(statbits);
+ for (i = 0; i < MAX_STATS; i++) {
+ if (statbits & (1 << i)) {
+ MSG_WriteShort(to->stats[i]);
}
}
}
@@ -1428,28 +1433,30 @@ void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from,
MSG_FlushTo
=============
*/
-void MSG_FlushTo( sizebuf_t *dest ) {
- memcpy( SZ_GetSpace( dest, msg_write.cursize ), msg_write.data, msg_write.cursize );
- SZ_Clear( &msg_write );
+void MSG_FlushTo(sizebuf_t *dest)
+{
+ memcpy(SZ_GetSpace(dest, msg_write.cursize), msg_write.data, msg_write.cursize);
+ SZ_Clear(&msg_write);
}
#if 0
// NOTE: does not NUL-terminate the string
-void MSG_Printf( const char *fmt, ... ) {
+void MSG_Printf(const char *fmt, ...)
+{
char buffer[MAX_STRING_CHARS];
va_list argptr;
size_t len;
- va_start( argptr, fmt );
- len = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(buffer, sizeof(buffer), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( buffer ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(buffer)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteData( buffer, len );
+ MSG_WriteData(buffer, len);
}
#endif
@@ -1459,20 +1466,22 @@ void MSG_Printf( const char *fmt, ... ) {
// reading functions
//
-void MSG_BeginReading( void ) {
+void MSG_BeginReading(void)
+{
msg_read.readcount = 0;
msg_read.bitpos = 0;
}
-byte *MSG_ReadData( size_t len ) {
+byte *MSG_ReadData(size_t len)
+{
byte *buf = msg_read.data + msg_read.readcount;
msg_read.readcount += len;
msg_read.bitpos = msg_read.readcount << 3;
- if( msg_read.readcount > msg_read.cursize ) {
- if( !msg_read.allowunderflow ) {
- Com_Error( ERR_DROP, "%s: read past end of message", __func__ );
+ if (msg_read.readcount > msg_read.cursize) {
+ if (!msg_read.allowunderflow) {
+ Com_Error(ERR_DROP, "%s: read past end of message", __func__);
}
return NULL;
}
@@ -1481,47 +1490,51 @@ byte *MSG_ReadData( size_t len ) {
}
// returns -1 if no more characters are available
-int MSG_ReadChar( void ) {
- byte *buf = MSG_ReadData( 1 );
+int MSG_ReadChar(void)
+{
+ byte *buf = MSG_ReadData(1);
int c;
-
+
if (!buf) {
c = -1;
} else {
c = (signed char)buf[0];
}
-
+
return c;
}
-int MSG_ReadByte( void ) {
- byte *buf = MSG_ReadData( 1 );
+int MSG_ReadByte(void)
+{
+ byte *buf = MSG_ReadData(1);
int c;
-
+
if (!buf) {
c = -1;
} else {
c = (unsigned char)buf[0];
}
-
+
return c;
}
-int MSG_ReadShort( void ) {
- byte *buf = MSG_ReadData( 2 );
+int MSG_ReadShort(void)
+{
+ byte *buf = MSG_ReadData(2);
int c;
-
+
if (!buf) {
c = -1;
} else {
c = (signed short)LittleShortMem(buf);
}
-
+
return c;
}
-int MSG_ReadWord( void ) {
- byte *buf = MSG_ReadData( 2 );
+int MSG_ReadWord(void)
+{
+ byte *buf = MSG_ReadData(2);
int c;
if (!buf) {
@@ -1529,14 +1542,15 @@ int MSG_ReadWord( void ) {
} else {
c = (unsigned short)LittleShortMem(buf);
}
-
+
return c;
}
-int MSG_ReadLong( void ) {
- byte *buf = MSG_ReadData( 4 );
+int MSG_ReadLong(void)
+{
+ byte *buf = MSG_ReadData(4);
int c;
-
+
if (!buf) {
c = -1;
} else {
@@ -1546,112 +1560,120 @@ int MSG_ReadLong( void ) {
return c;
}
-size_t MSG_ReadString( char *dest, size_t size ) {
+size_t MSG_ReadString(char *dest, size_t size)
+{
int c;
size_t len = 0;
- while( 1 ) {
+ while (1) {
c = MSG_ReadByte();
- if( c == -1 || c == 0 ) {
+ if (c == -1 || c == 0) {
break;
}
- if( len + 1 < size ) {
+ if (len + 1 < size) {
*dest++ = c;
}
len++;
}
- if( size ) {
+ if (size) {
*dest = 0;
}
return len;
}
-size_t MSG_ReadStringLine( char *dest, size_t size ) {
+size_t MSG_ReadStringLine(char *dest, size_t size)
+{
int c;
size_t len = 0;
- while( 1 ) {
+ while (1) {
c = MSG_ReadByte();
- if( c == -1 || c == 0 || c == '\n' ) {
+ if (c == -1 || c == 0 || c == '\n') {
break;
}
- if( len + 1 < size ) {
+ if (len + 1 < size) {
*dest++ = c;
}
len++;
}
- if( size ) {
+ if (size) {
*dest = 0;
}
return len;
}
-static inline float MSG_ReadCoord (void) {
+static inline float MSG_ReadCoord(void)
+{
return SHORT2COORD(MSG_ReadShort());
}
#if !USE_CLIENT
static inline
#endif
-void MSG_ReadPos( vec3_t pos ) {
+void MSG_ReadPos(vec3_t pos)
+{
pos[0] = MSG_ReadCoord();
pos[1] = MSG_ReadCoord();
pos[2] = MSG_ReadCoord();
}
-static inline float MSG_ReadAngle (void) {
+static inline float MSG_ReadAngle(void)
+{
return BYTE2ANGLE(MSG_ReadChar());
}
-static inline float MSG_ReadAngle16 (void) {
+static inline float MSG_ReadAngle16(void)
+{
return SHORT2ANGLE(MSG_ReadShort());
}
#if USE_CLIENT
-void MSG_ReadDir( vec3_t dir ) {
+void MSG_ReadDir(vec3_t dir)
+{
int b;
b = MSG_ReadByte();
- if( b < 0 || b >= NUMVERTEXNORMALS )
- Com_Error( ERR_DROP, "MSG_ReadDir: out of range" );
- VectorCopy( bytedirs[b], dir );
+ if (b < 0 || b >= NUMVERTEXNORMALS)
+ Com_Error(ERR_DROP, "MSG_ReadDir: out of range");
+ VectorCopy(bytedirs[b], dir);
}
#endif
-void MSG_ReadDeltaUsercmd( const usercmd_t *from, usercmd_t *to ) {
+void MSG_ReadDeltaUsercmd(const usercmd_t *from, usercmd_t *to)
+{
int bits;
- if( from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (from) {
+ memcpy(to, from, sizeof(*to));
} else {
- memset( to, 0, sizeof( *to ) );
+ memset(to, 0, sizeof(*to));
}
bits = MSG_ReadByte();
-
+
// read current angles
- if( bits & CM_ANGLE1 )
+ if (bits & CM_ANGLE1)
to->angles[0] = MSG_ReadShort();
- if( bits & CM_ANGLE2 )
+ if (bits & CM_ANGLE2)
to->angles[1] = MSG_ReadShort();
- if( bits & CM_ANGLE3 )
+ if (bits & CM_ANGLE3)
to->angles[2] = MSG_ReadShort();
-
+
// read movement
- if( bits & CM_FORWARD )
+ if (bits & CM_FORWARD)
to->forwardmove = MSG_ReadShort();
- if( bits & CM_SIDE )
+ if (bits & CM_SIDE)
to->sidemove = MSG_ReadShort();
- if( bits & CM_UP )
+ if (bits & CM_UP)
to->upmove = MSG_ReadShort();
-
+
// read buttons
- if( bits & CM_BUTTONS )
+ if (bits & CM_BUTTONS)
to->buttons = MSG_ReadByte();
- if( bits & CM_IMPULSE )
+ if (bits & CM_IMPULSE)
to->impulse = MSG_ReadByte();
// read time to run command
@@ -1661,65 +1683,66 @@ void MSG_ReadDeltaUsercmd( const usercmd_t *from, usercmd_t *to ) {
to->lightlevel = MSG_ReadByte();
}
-void MSG_ReadDeltaUsercmd_Hacked( const usercmd_t *from, usercmd_t *to ) {
+void MSG_ReadDeltaUsercmd_Hacked(const usercmd_t *from, usercmd_t *to)
+{
int bits, buttons = 0;
- if( from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (from) {
+ memcpy(to, from, sizeof(*to));
} else {
- memset( to, 0, sizeof( *to ) );
+ memset(to, 0, sizeof(*to));
}
bits = MSG_ReadByte();
// read buttons
- if( bits & CM_BUTTONS ) {
+ if (bits & CM_BUTTONS) {
buttons = MSG_ReadByte();
to->buttons = buttons & BUTTON_MASK;
}
// read current angles
- if( bits & CM_ANGLE1 ) {
- if( buttons & BUTTON_ANGLE1 ) {
+ if (bits & CM_ANGLE1) {
+ if (buttons & BUTTON_ANGLE1) {
to->angles[0] = MSG_ReadChar() * 64;
} else {
to->angles[0] = MSG_ReadShort();
}
}
- if( bits & CM_ANGLE2 ) {
- if( buttons & BUTTON_ANGLE2 ) {
+ if (bits & CM_ANGLE2) {
+ if (buttons & BUTTON_ANGLE2) {
to->angles[1] = MSG_ReadChar() * 256;
} else {
to->angles[1] = MSG_ReadShort();
}
}
- if( bits & CM_ANGLE3 )
+ if (bits & CM_ANGLE3)
to->angles[2] = MSG_ReadShort();
-
+
// read movement
- if( bits & CM_FORWARD ) {
- if( buttons & BUTTON_FORWARD ) {
+ if (bits & CM_FORWARD) {
+ if (buttons & BUTTON_FORWARD) {
to->forwardmove = MSG_ReadChar() * 5;
} else {
to->forwardmove = MSG_ReadShort();
}
}
- if( bits & CM_SIDE ) {
- if( buttons & BUTTON_SIDE ) {
+ if (bits & CM_SIDE) {
+ if (buttons & BUTTON_SIDE) {
to->sidemove = MSG_ReadChar() * 5;
} else {
to->sidemove = MSG_ReadShort();
}
}
- if( bits & CM_UP ) {
- if( buttons & BUTTON_UP ) {
+ if (bits & CM_UP) {
+ if (buttons & BUTTON_UP) {
to->upmove = MSG_ReadChar() * 5;
} else {
to->upmove = MSG_ReadShort();
}
}
-
- if( bits & CM_IMPULSE )
+
+ if (bits & CM_IMPULSE)
to->impulse = MSG_ReadByte();
// read time to run command
@@ -1729,20 +1752,21 @@ void MSG_ReadDeltaUsercmd_Hacked( const usercmd_t *from, usercmd_t *to ) {
to->lightlevel = MSG_ReadByte();
}
-int MSG_ReadBits( int bits ) {
+int MSG_ReadBits(int bits)
+{
int i, get;
size_t bitpos;
qboolean sgn;
int value;
- if( bits == 0 || bits < -31 || bits > 32 ) {
- Com_Error( ERR_FATAL, "MSG_ReadBits: bad bits: %d", bits );
+ if (bits == 0 || bits < -31 || bits > 32) {
+ Com_Error(ERR_FATAL, "MSG_ReadBits: bad bits: %d", bits);
}
bitpos = msg_read.bitpos;
- if( ( bitpos & 7 ) == 0 ) {
+ if ((bitpos & 7) == 0) {
// optimized case
- switch( bits ) {
+ switch (bits) {
case -8:
value = MSG_ReadChar();
return value;
@@ -1761,91 +1785,91 @@ int MSG_ReadBits( int bits ) {
}
sgn = qfalse;
- if( bits < 0 ) {
+ if (bits < 0) {
bits = -bits;
sgn = qtrue;
}
value = 0;
- for( i = 0; i < bits; i++, bitpos++ ) {
- get = ( msg_read.data[ bitpos >> 3 ] >> ( bitpos & 7 ) ) & 1;
+ for (i = 0; i < bits; i++, bitpos++) {
+ get = (msg_read.data[bitpos >> 3] >> (bitpos & 7)) & 1;
value |= get << i;
}
msg_read.bitpos = bitpos;
- msg_read.readcount = ( bitpos + 7 ) >> 3;
+ msg_read.readcount = (bitpos + 7) >> 3;
- if( sgn ) {
- if( value & ( 1 << ( bits - 1 ) ) ) {
- value |= -1 ^ ( ( 1 << bits ) - 1 );
+ if (sgn) {
+ if (value & (1 << (bits - 1))) {
+ value |= -1 ^((1 << bits) - 1);
}
}
return value;
}
-void MSG_ReadDeltaUsercmd_Enhanced( const usercmd_t *from,
- usercmd_t *to,
- int version )
+void MSG_ReadDeltaUsercmd_Enhanced(const usercmd_t *from,
+ usercmd_t *to,
+ int version)
{
int bits, count;
- if( from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (from) {
+ memcpy(to, from, sizeof(*to));
} else {
- memset( to, 0, sizeof( *to ) );
+ memset(to, 0, sizeof(*to));
}
- if( !MSG_ReadBits( 1 ) ) {
+ if (!MSG_ReadBits(1)) {
return;
}
- bits = MSG_ReadBits( 8 );
-
+ bits = MSG_ReadBits(8);
+
// read current angles
- if( bits & CM_ANGLE1 ) {
- if( MSG_ReadBits( 1 ) ) {
- to->angles[0] += MSG_ReadBits( -8 );
+ if (bits & CM_ANGLE1) {
+ if (MSG_ReadBits(1)) {
+ to->angles[0] += MSG_ReadBits(-8);
} else {
- to->angles[0] = MSG_ReadBits( -16 );
+ to->angles[0] = MSG_ReadBits(-16);
}
}
- if( bits & CM_ANGLE2 ) {
- if( MSG_ReadBits( 1 ) ) {
- to->angles[1] += MSG_ReadBits( -8 );
+ if (bits & CM_ANGLE2) {
+ if (MSG_ReadBits(1)) {
+ to->angles[1] += MSG_ReadBits(-8);
} else {
- to->angles[1] = MSG_ReadBits( -16 );
+ to->angles[1] = MSG_ReadBits(-16);
}
}
- if( bits & CM_ANGLE3 ) {
- to->angles[2] = MSG_ReadBits( -16 );
+ if (bits & CM_ANGLE3) {
+ to->angles[2] = MSG_ReadBits(-16);
}
// read movement
- if( version >= PROTOCOL_VERSION_Q2PRO_UCMD ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_UCMD) {
count = -10;
} else {
count = -16;
}
- if( bits & CM_FORWARD ) {
- to->forwardmove = MSG_ReadBits( count );
+ if (bits & CM_FORWARD) {
+ to->forwardmove = MSG_ReadBits(count);
}
- if( bits & CM_SIDE ) {
- to->sidemove = MSG_ReadBits( count );
+ if (bits & CM_SIDE) {
+ to->sidemove = MSG_ReadBits(count);
}
- if( bits & CM_UP ) {
- to->upmove = MSG_ReadBits( count );
+ if (bits & CM_UP) {
+ to->upmove = MSG_ReadBits(count);
}
-
+
// read buttons
- if( bits & CM_BUTTONS ) {
- int buttons = MSG_ReadBits( 3 );
- to->buttons = ( buttons & 3 ) | ( ( buttons & 4 ) << 5 );
+ if (bits & CM_BUTTONS) {
+ int buttons = MSG_ReadBits(3);
+ to->buttons = (buttons & 3) | ((buttons & 4) << 5);
}
// read time to run command
- if( bits & CM_IMPULSE ) {
- to->msec = MSG_ReadBits( 8 );
+ if (bits & CM_IMPULSE) {
+ to->msec = MSG_ReadBits(8);
}
}
@@ -1858,25 +1882,26 @@ MSG_ParseEntityBits
Returns the entity number and the header bits
=================
*/
-int MSG_ParseEntityBits( int *bits ) {
+int MSG_ParseEntityBits(int *bits)
+{
int b, total;
int number;
total = MSG_ReadByte();
- if( total & U_MOREBITS1 ) {
- b = MSG_ReadByte();
- total |= b<<8;
+ if (total & U_MOREBITS1) {
+ b = MSG_ReadByte();
+ total |= b << 8;
}
- if( total & U_MOREBITS2 ) {
+ if (total & U_MOREBITS2) {
b = MSG_ReadByte();
- total |= b<<16;
+ total |= b << 16;
}
- if( total & U_MOREBITS3 ) {
+ if (total & U_MOREBITS3) {
b = MSG_ReadByte();
- total |= b<<24;
+ total |= b << 24;
}
- if( total & U_NUMBER16 )
+ if (total & U_NUMBER16)
number = MSG_ReadShort();
else
number = MSG_ReadByte();
@@ -1893,113 +1918,113 @@ MSG_ParseDeltaEntity
Can go from either a baseline or a previous packet_entity
==================
*/
-void MSG_ParseDeltaEntity( const entity_state_t *from,
- entity_state_t *to,
- int number,
- int bits,
- msgEsFlags_t flags )
+void MSG_ParseDeltaEntity(const entity_state_t *from,
+ entity_state_t *to,
+ int number,
+ int bits,
+ msgEsFlags_t flags)
{
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
- if( number < 1 || number >= MAX_EDICTS ) {
- Com_Error( ERR_DROP, "%s: bad entity number: %d", __func__, number );
+ if (number < 1 || number >= MAX_EDICTS) {
+ Com_Error(ERR_DROP, "%s: bad entity number: %d", __func__, number);
}
// set everything to the state we are delta'ing from
- if( !from ) {
- memset( to, 0, sizeof( *to ) );
- } else if( to != from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (!from) {
+ memset(to, 0, sizeof(*to));
+ } else if (to != from) {
+ memcpy(to, from, sizeof(*to));
}
-
+
to->number = number;
to->event = 0;
- if( !bits ) {
+ if (!bits) {
return;
}
- if( bits & U_MODEL ) {
+ if (bits & U_MODEL) {
to->modelindex = MSG_ReadByte();
}
- if( bits & U_MODEL2 ) {
+ if (bits & U_MODEL2) {
to->modelindex2 = MSG_ReadByte();
}
- if( bits & U_MODEL3 ) {
+ if (bits & U_MODEL3) {
to->modelindex3 = MSG_ReadByte();
}
- if( bits & U_MODEL4 ) {
+ if (bits & U_MODEL4) {
to->modelindex4 = MSG_ReadByte();
}
-
- if( bits & U_FRAME8 )
+
+ if (bits & U_FRAME8)
to->frame = MSG_ReadByte();
- if( bits & U_FRAME16 )
+ if (bits & U_FRAME16)
to->frame = MSG_ReadShort();
- if( (bits & (U_SKIN8|U_SKIN16)) == (U_SKIN8|U_SKIN16) ) //used for laser colors
+ if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16)) //used for laser colors
to->skinnum = MSG_ReadLong();
- else if( bits & U_SKIN8 )
+ else if (bits & U_SKIN8)
to->skinnum = MSG_ReadByte();
- else if( bits & U_SKIN16 )
+ else if (bits & U_SKIN16)
to->skinnum = MSG_ReadWord();
- if( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) )
+ if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
to->effects = MSG_ReadLong();
- else if( bits & U_EFFECTS8 )
+ else if (bits & U_EFFECTS8)
to->effects = MSG_ReadByte();
- else if( bits & U_EFFECTS16 )
+ else if (bits & U_EFFECTS16)
to->effects = MSG_ReadWord();
- if( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) )
+ if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
to->renderfx = MSG_ReadLong();
- else if( bits & U_RENDERFX8 )
+ else if (bits & U_RENDERFX8)
to->renderfx = MSG_ReadByte();
- else if( bits & U_RENDERFX16 )
+ else if (bits & U_RENDERFX16)
to->renderfx = MSG_ReadWord();
- if( bits & U_ORIGIN1 ) {
+ if (bits & U_ORIGIN1) {
to->origin[0] = MSG_ReadCoord();
}
- if( bits & U_ORIGIN2 ) {
+ if (bits & U_ORIGIN2) {
to->origin[1] = MSG_ReadCoord();
}
- if( bits & U_ORIGIN3 ) {
+ if (bits & U_ORIGIN3) {
to->origin[2] = MSG_ReadCoord();
}
- if( (flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16) ) {
- if( bits & U_ANGLE1 )
+ if ((flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16)) {
+ if (bits & U_ANGLE1)
to->angles[0] = MSG_ReadAngle16();
- if( bits & U_ANGLE2 )
+ if (bits & U_ANGLE2)
to->angles[1] = MSG_ReadAngle16();
- if( bits & U_ANGLE3 )
+ if (bits & U_ANGLE3)
to->angles[2] = MSG_ReadAngle16();
} else {
- if( bits & U_ANGLE1 )
+ if (bits & U_ANGLE1)
to->angles[0] = MSG_ReadAngle();
- if( bits & U_ANGLE2 )
+ if (bits & U_ANGLE2)
to->angles[1] = MSG_ReadAngle();
- if( bits & U_ANGLE3 )
+ if (bits & U_ANGLE3)
to->angles[2] = MSG_ReadAngle();
}
- if( bits & U_OLDORIGIN ) {
- MSG_ReadPos( to->old_origin );
+ if (bits & U_OLDORIGIN) {
+ MSG_ReadPos(to->old_origin);
}
- if( bits & U_SOUND ) {
+ if (bits & U_SOUND) {
to->sound = MSG_ReadByte();
}
- if( bits & U_EVENT ) {
+ if (bits & U_EVENT) {
to->event = MSG_ReadByte();
}
- if( bits & U_SOLID ) {
- if( flags & MSG_ES_LONGSOLID ) {
+ if (bits & U_SOLID) {
+ if (flags & MSG_ES_LONGSOLID) {
to->solid = MSG_ReadLong();
} else {
to->solid = MSG_ReadWord();
@@ -2016,52 +2041,52 @@ void MSG_ParseDeltaEntity( const entity_state_t *from,
MSG_ParseDeltaPlayerstate_Default
===================
*/
-void MSG_ParseDeltaPlayerstate_Default( const player_state_t *from,
- player_state_t *to,
- int flags )
+void MSG_ParseDeltaPlayerstate_Default(const player_state_t *from,
+ player_state_t *to,
+ int flags)
{
int i;
int statbits;
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
// clear to old value before delta parsing
- if( !from ) {
- memset( to, 0, sizeof( *to ) );
- } else if( to != from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (!from) {
+ memset(to, 0, sizeof(*to));
+ } else if (to != from) {
+ memcpy(to, from, sizeof(*to));
}
//
// parse the pmove_state_t
//
- if( flags & PS_M_TYPE )
+ if (flags & PS_M_TYPE)
to->pmove.pm_type = MSG_ReadByte();
- if( flags & PS_M_ORIGIN ) {
+ if (flags & PS_M_ORIGIN) {
to->pmove.origin[0] = MSG_ReadShort();
to->pmove.origin[1] = MSG_ReadShort();
to->pmove.origin[2] = MSG_ReadShort();
}
- if( flags & PS_M_VELOCITY ) {
+ if (flags & PS_M_VELOCITY) {
to->pmove.velocity[0] = MSG_ReadShort();
to->pmove.velocity[1] = MSG_ReadShort();
to->pmove.velocity[2] = MSG_ReadShort();
}
- if( flags & PS_M_TIME )
+ if (flags & PS_M_TIME)
to->pmove.pm_time = MSG_ReadByte();
- if( flags & PS_M_FLAGS )
+ if (flags & PS_M_FLAGS)
to->pmove.pm_flags = MSG_ReadByte();
- if( flags & PS_M_GRAVITY )
+ if (flags & PS_M_GRAVITY)
to->pmove.gravity = MSG_ReadShort();
- if( flags & PS_M_DELTA_ANGLES ) {
+ if (flags & PS_M_DELTA_ANGLES) {
to->pmove.delta_angles[0] = MSG_ReadShort();
to->pmove.delta_angles[1] = MSG_ReadShort();
to->pmove.delta_angles[2] = MSG_ReadShort();
@@ -2070,29 +2095,29 @@ void MSG_ParseDeltaPlayerstate_Default( const player_state_t *from,
//
// parse the rest of the player_state_t
//
- if( flags & PS_VIEWOFFSET ) {
+ if (flags & PS_VIEWOFFSET) {
to->viewoffset[0] = MSG_ReadChar() * 0.25f;
to->viewoffset[1] = MSG_ReadChar() * 0.25f;
to->viewoffset[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_VIEWANGLES ) {
+ if (flags & PS_VIEWANGLES) {
to->viewangles[0] = MSG_ReadAngle16();
to->viewangles[1] = MSG_ReadAngle16();
to->viewangles[2] = MSG_ReadAngle16();
}
- if( flags & PS_KICKANGLES ) {
+ if (flags & PS_KICKANGLES) {
to->kick_angles[0] = MSG_ReadChar() * 0.25f;
to->kick_angles[1] = MSG_ReadChar() * 0.25f;
to->kick_angles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_WEAPONINDEX ) {
+ if (flags & PS_WEAPONINDEX) {
to->gunindex = MSG_ReadByte();
}
- if( flags & PS_WEAPONFRAME ) {
+ if (flags & PS_WEAPONFRAME) {
to->gunframe = MSG_ReadByte();
to->gunoffset[0] = MSG_ReadChar() * 0.25f;
to->gunoffset[1] = MSG_ReadChar() * 0.25f;
@@ -2102,23 +2127,23 @@ void MSG_ParseDeltaPlayerstate_Default( const player_state_t *from,
to->gunangles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_BLEND ) {
+ if (flags & PS_BLEND) {
to->blend[0] = MSG_ReadByte() / 255.0f;
to->blend[1] = MSG_ReadByte() / 255.0f;
to->blend[2] = MSG_ReadByte() / 255.0f;
to->blend[3] = MSG_ReadByte() / 255.0f;
}
- if( flags & PS_FOV )
+ if (flags & PS_FOV)
to->fov = MSG_ReadByte();
- if( flags & PS_RDFLAGS )
+ if (flags & PS_RDFLAGS)
to->rdflags = MSG_ReadByte();
// parse stats
statbits = MSG_ReadLong();
- for( i = 0; i < MAX_STATS; i++ )
- if( statbits & ( 1 << i ) )
+ for (i = 0; i < MAX_STATS; i++)
+ if (statbits & (1 << i))
to->stats[i] = MSG_ReadShort();
}
@@ -2128,59 +2153,59 @@ void MSG_ParseDeltaPlayerstate_Default( const player_state_t *from,
MSG_ParseDeltaPlayerstate_Default
===================
*/
-void MSG_ParseDeltaPlayerstate_Enhanced( const player_state_t *from,
- player_state_t *to,
- int flags,
- int extraflags )
+void MSG_ParseDeltaPlayerstate_Enhanced(const player_state_t *from,
+ player_state_t *to,
+ int flags,
+ int extraflags)
{
int i;
int statbits;
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
// clear to old value before delta parsing
- if( !from ) {
- memset( to, 0, sizeof( *to ) );
- } else if( to != from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (!from) {
+ memset(to, 0, sizeof(*to));
+ } else if (to != from) {
+ memcpy(to, from, sizeof(*to));
}
//
// parse the pmove_state_t
//
- if( flags & PS_M_TYPE )
+ if (flags & PS_M_TYPE)
to->pmove.pm_type = MSG_ReadByte();
- if( flags & PS_M_ORIGIN ) {
+ if (flags & PS_M_ORIGIN) {
to->pmove.origin[0] = MSG_ReadShort();
to->pmove.origin[1] = MSG_ReadShort();
}
- if( extraflags & EPS_M_ORIGIN2 ) {
+ if (extraflags & EPS_M_ORIGIN2) {
to->pmove.origin[2] = MSG_ReadShort();
}
- if( flags & PS_M_VELOCITY ) {
+ if (flags & PS_M_VELOCITY) {
to->pmove.velocity[0] = MSG_ReadShort();
to->pmove.velocity[1] = MSG_ReadShort();
}
- if( extraflags & EPS_M_VELOCITY2 ) {
+ if (extraflags & EPS_M_VELOCITY2) {
to->pmove.velocity[2] = MSG_ReadShort();
}
- if( flags & PS_M_TIME )
+ if (flags & PS_M_TIME)
to->pmove.pm_time = MSG_ReadByte();
- if( flags & PS_M_FLAGS )
+ if (flags & PS_M_FLAGS)
to->pmove.pm_flags = MSG_ReadByte();
- if( flags & PS_M_GRAVITY )
+ if (flags & PS_M_GRAVITY)
to->pmove.gravity = MSG_ReadShort();
- if( flags & PS_M_DELTA_ANGLES ) {
+ if (flags & PS_M_DELTA_ANGLES) {
to->pmove.delta_angles[0] = MSG_ReadShort();
to->pmove.delta_angles[1] = MSG_ReadShort();
to->pmove.delta_angles[2] = MSG_ReadShort();
@@ -2189,70 +2214,70 @@ void MSG_ParseDeltaPlayerstate_Enhanced( const player_state_t *from,
//
// parse the rest of the player_state_t
//
- if( flags & PS_VIEWOFFSET ) {
+ if (flags & PS_VIEWOFFSET) {
to->viewoffset[0] = MSG_ReadChar() * 0.25f;
to->viewoffset[1] = MSG_ReadChar() * 0.25f;
to->viewoffset[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_VIEWANGLES ) {
+ if (flags & PS_VIEWANGLES) {
to->viewangles[0] = MSG_ReadAngle16();
to->viewangles[1] = MSG_ReadAngle16();
}
- if( extraflags & EPS_VIEWANGLE2 ) {
+ if (extraflags & EPS_VIEWANGLE2) {
to->viewangles[2] = MSG_ReadAngle16();
}
- if( flags & PS_KICKANGLES ) {
+ if (flags & PS_KICKANGLES) {
to->kick_angles[0] = MSG_ReadChar() * 0.25f;
to->kick_angles[1] = MSG_ReadChar() * 0.25f;
to->kick_angles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_WEAPONINDEX ) {
+ if (flags & PS_WEAPONINDEX) {
to->gunindex = MSG_ReadByte();
}
- if( flags & PS_WEAPONFRAME ) {
+ if (flags & PS_WEAPONFRAME) {
to->gunframe = MSG_ReadByte();
}
- if( extraflags & EPS_GUNOFFSET ) {
+ if (extraflags & EPS_GUNOFFSET) {
to->gunoffset[0] = MSG_ReadChar() * 0.25f;
to->gunoffset[1] = MSG_ReadChar() * 0.25f;
to->gunoffset[2] = MSG_ReadChar() * 0.25f;
}
- if( extraflags & EPS_GUNANGLES ) {
+ if (extraflags & EPS_GUNANGLES) {
to->gunangles[0] = MSG_ReadChar() * 0.25f;
to->gunangles[1] = MSG_ReadChar() * 0.25f;
to->gunangles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PS_BLEND ) {
+ if (flags & PS_BLEND) {
to->blend[0] = MSG_ReadByte() / 255.0f;
to->blend[1] = MSG_ReadByte() / 255.0f;
to->blend[2] = MSG_ReadByte() / 255.0f;
to->blend[3] = MSG_ReadByte() / 255.0f;
}
- if( flags & PS_FOV )
+ if (flags & PS_FOV)
to->fov = MSG_ReadByte();
- if( flags & PS_RDFLAGS )
+ if (flags & PS_RDFLAGS)
to->rdflags = MSG_ReadByte();
// parse stats
- if( extraflags & EPS_STATS ) {
+ if (extraflags & EPS_STATS) {
statbits = MSG_ReadLong();
- for( i = 0; i < MAX_STATS; i++ ) {
- if( statbits & ( 1 << i ) ) {
+ for (i = 0; i < MAX_STATS; i++) {
+ if (statbits & (1 << i)) {
to->stats[i] = MSG_ReadShort();
}
}
}
-
+
}
#endif // USE_CLIENT
@@ -2264,101 +2289,101 @@ void MSG_ParseDeltaPlayerstate_Enhanced( const player_state_t *from,
MSG_ParseDeltaPlayerstate_Packet
===================
*/
-void MSG_ParseDeltaPlayerstate_Packet( const player_state_t *from,
- player_state_t *to,
- int flags )
+void MSG_ParseDeltaPlayerstate_Packet(const player_state_t *from,
+ player_state_t *to,
+ int flags)
{
int i;
int statbits;
- if( !to ) {
- Com_Error( ERR_DROP, "%s: NULL", __func__ );
+ if (!to) {
+ Com_Error(ERR_DROP, "%s: NULL", __func__);
}
// clear to old value before delta parsing
- if( !from ) {
- memset( to, 0, sizeof( *to ) );
- } else if( to != from ) {
- memcpy( to, from, sizeof( *to ) );
+ if (!from) {
+ memset(to, 0, sizeof(*to));
+ } else if (to != from) {
+ memcpy(to, from, sizeof(*to));
}
//
// parse the pmove_state_t
//
- if( flags & PPS_M_TYPE )
+ if (flags & PPS_M_TYPE)
to->pmove.pm_type = MSG_ReadByte();
- if( flags & PPS_M_ORIGIN ) {
+ if (flags & PPS_M_ORIGIN) {
to->pmove.origin[0] = MSG_ReadShort();
to->pmove.origin[1] = MSG_ReadShort();
}
- if( flags & PPS_M_ORIGIN2 ) {
+ if (flags & PPS_M_ORIGIN2) {
to->pmove.origin[2] = MSG_ReadShort();
}
//
// parse the rest of the player_state_t
//
- if( flags & PPS_VIEWOFFSET ) {
+ if (flags & PPS_VIEWOFFSET) {
to->viewoffset[0] = MSG_ReadChar() * 0.25f;
to->viewoffset[1] = MSG_ReadChar() * 0.25f;
to->viewoffset[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PPS_VIEWANGLES ) {
+ if (flags & PPS_VIEWANGLES) {
to->viewangles[0] = MSG_ReadAngle16();
to->viewangles[1] = MSG_ReadAngle16();
}
- if( flags & PPS_VIEWANGLE2 ) {
+ if (flags & PPS_VIEWANGLE2) {
to->viewangles[2] = MSG_ReadAngle16();
}
- if( flags & PPS_KICKANGLES ) {
+ if (flags & PPS_KICKANGLES) {
to->kick_angles[0] = MSG_ReadChar() * 0.25f;
to->kick_angles[1] = MSG_ReadChar() * 0.25f;
to->kick_angles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PPS_WEAPONINDEX ) {
+ if (flags & PPS_WEAPONINDEX) {
to->gunindex = MSG_ReadByte();
}
- if( flags & PPS_WEAPONFRAME ) {
+ if (flags & PPS_WEAPONFRAME) {
to->gunframe = MSG_ReadByte();
}
- if( flags & PPS_GUNOFFSET ) {
+ if (flags & PPS_GUNOFFSET) {
to->gunoffset[0] = MSG_ReadChar() * 0.25f;
to->gunoffset[1] = MSG_ReadChar() * 0.25f;
to->gunoffset[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PPS_GUNANGLES ) {
+ if (flags & PPS_GUNANGLES) {
to->gunangles[0] = MSG_ReadChar() * 0.25f;
to->gunangles[1] = MSG_ReadChar() * 0.25f;
to->gunangles[2] = MSG_ReadChar() * 0.25f;
}
- if( flags & PPS_BLEND ) {
+ if (flags & PPS_BLEND) {
to->blend[0] = MSG_ReadByte() / 255.0f;
to->blend[1] = MSG_ReadByte() / 255.0f;
to->blend[2] = MSG_ReadByte() / 255.0f;
to->blend[3] = MSG_ReadByte() / 255.0f;
}
- if( flags & PPS_FOV )
+ if (flags & PPS_FOV)
to->fov = MSG_ReadByte();
- if( flags & PPS_RDFLAGS )
+ if (flags & PPS_RDFLAGS)
to->rdflags = MSG_ReadByte();
// parse stats
- if( flags & PPS_STATS ) {
+ if (flags & PPS_STATS) {
statbits = MSG_ReadLong();
- for( i = 0; i < MAX_STATS; i++ ) {
- if( statbits & ( 1 << i ) ) {
+ for (i = 0; i < MAX_STATS; i++) {
+ if (statbits & (1 << i)) {
to->stats[i] = MSG_ReadShort();
}
}
@@ -2369,11 +2394,12 @@ void MSG_ParseDeltaPlayerstate_Packet( const player_state_t *from,
#ifdef _DEBUG
-#define SHOWBITS(x) Com_LPrintf( PRINT_DEVELOPER, x " " )
+#define SHOWBITS(x) Com_LPrintf(PRINT_DEVELOPER, x " ")
#if USE_CLIENT
-void MSG_ShowDeltaPlayerstateBits_Default( int flags ) {
+void MSG_ShowDeltaPlayerstateBits_Default(int flags)
+{
#define S(b,s) if(flags&PS_##b) SHOWBITS(s)
S(M_TYPE, "pmove.pm_type");
S(M_ORIGIN, "pmove.origin");
@@ -2393,7 +2419,8 @@ void MSG_ShowDeltaPlayerstateBits_Default( int flags ) {
#undef S
}
-void MSG_ShowDeltaPlayerstateBits_Enhanced( int flags ) {
+void MSG_ShowDeltaPlayerstateBits_Enhanced(int flags)
+{
int extraflags;
extraflags = flags >> PS_BITS;
@@ -2427,9 +2454,10 @@ void MSG_ShowDeltaPlayerstateBits_Enhanced( int flags ) {
}
-void MSG_ShowDeltaUsercmdBits_Enhanced( int bits ) {
- if( !bits ) {
- SHOWBITS( "<none>" );
+void MSG_ShowDeltaUsercmdBits_Enhanced(int bits)
+{
+ if (!bits) {
+ SHOWBITS("<none>");
return;
}
@@ -2449,38 +2477,39 @@ void MSG_ShowDeltaUsercmdBits_Enhanced( int bits ) {
#if USE_CLIENT || USE_MVD_CLIENT
-void MSG_ShowDeltaEntityBits( int bits ) {
+void MSG_ShowDeltaEntityBits(int bits)
+{
#define S(b,s) if(bits&U_##b) SHOWBITS(s)
S(MODEL, "modelindex");
S(MODEL2, "modelindex2");
S(MODEL3, "modelindex3");
S(MODEL4, "modelindex4");
- if( bits & U_FRAME8 )
- SHOWBITS( "frame8" );
- if( bits & U_FRAME16 )
- SHOWBITS( "frame16" );
-
- if( ( bits & ( U_SKIN8 | U_SKIN16 ) ) == ( U_SKIN8 | U_SKIN16 ) )
- SHOWBITS( "skinnum32" );
- else if( bits & U_SKIN8 )
- SHOWBITS( "skinnum8" );
- else if( bits & U_SKIN16 )
- SHOWBITS( "skinnum16" );
-
- if( ( bits & ( U_EFFECTS8 | U_EFFECTS16 ) ) == ( U_EFFECTS8 | U_EFFECTS16 ) )
- SHOWBITS( "effects32" );
- else if( bits & U_EFFECTS8 )
- SHOWBITS( "effects8" );
- else if( bits & U_EFFECTS16 )
- SHOWBITS( "effects16" );
-
- if( ( bits & ( U_RENDERFX8 | U_RENDERFX16 ) ) == ( U_RENDERFX8 | U_RENDERFX16 ) )
- SHOWBITS( "renderfx32" );
- else if( bits & U_RENDERFX8 )
- SHOWBITS( "renderfx8" );
- else if( bits & U_RENDERFX16 )
- SHOWBITS( "renderfx16" );
+ if (bits & U_FRAME8)
+ SHOWBITS("frame8");
+ if (bits & U_FRAME16)
+ SHOWBITS("frame16");
+
+ if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16))
+ SHOWBITS("skinnum32");
+ else if (bits & U_SKIN8)
+ SHOWBITS("skinnum8");
+ else if (bits & U_SKIN16)
+ SHOWBITS("skinnum16");
+
+ if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
+ SHOWBITS("effects32");
+ else if (bits & U_EFFECTS8)
+ SHOWBITS("effects8");
+ else if (bits & U_EFFECTS16)
+ SHOWBITS("effects16");
+
+ if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
+ SHOWBITS("renderfx32");
+ else if (bits & U_RENDERFX8)
+ SHOWBITS("renderfx8");
+ else if (bits & U_RENDERFX16)
+ SHOWBITS("renderfx16");
S(ORIGIN1, "origin[0]");
S(ORIGIN2, "origin[1]");
@@ -2488,14 +2517,15 @@ void MSG_ShowDeltaEntityBits( int bits ) {
S(ANGLE1, "angles[0]");
S(ANGLE2, "angles[1]");
S(ANGLE3, "angles[2]");
- S(OLDORIGIN,"old_origin");
+ S(OLDORIGIN, "old_origin");
S(SOUND, "sound");
S(EVENT, "event");
S(SOLID, "solid");
#undef S
}
-void MSG_ShowDeltaPlayerstateBits_Packet( int flags ) {
+void MSG_ShowDeltaPlayerstateBits_Packet(int flags)
+{
#define S(b,s) if(flags&PPS_##b) SHOWBITS(s)
S(M_TYPE, "pmove.pm_type");
S(M_ORIGIN, "pmove.origin[0,1]");
@@ -2515,10 +2545,11 @@ void MSG_ShowDeltaPlayerstateBits_Packet( int flags ) {
#undef S
}
-const char *MSG_ServerCommandString( int cmd ) {
- switch( cmd ) {
- case -1: return "END OF MESSAGE";
- default: return "UNKNOWN COMMAND";
+const char *MSG_ServerCommandString(int cmd)
+{
+ switch (cmd) {
+ case -1: return "END OF MESSAGE";
+ default: return "UNKNOWN COMMAND";
#define S(x) case svc_##x: return "svc_" #x;
S(bad)
S(muzzleflash)
@@ -2554,98 +2585,106 @@ const char *MSG_ServerCommandString( int cmd ) {
//===========================================================================
-void SZ_TagInit( sizebuf_t *buf, void *data, size_t length, uint32_t tag ) {
- memset( buf, 0, sizeof( *buf ) );
+void SZ_TagInit(sizebuf_t *buf, void *data, size_t length, uint32_t tag)
+{
+ memset(buf, 0, sizeof(*buf));
buf->data = data;
buf->maxsize = length;
buf->tag = tag;
}
-void SZ_Init( sizebuf_t *buf, void *data, size_t length ) {
- memset( buf, 0, sizeof( *buf ) );
+void SZ_Init(sizebuf_t *buf, void *data, size_t length)
+{
+ memset(buf, 0, sizeof(*buf));
buf->data = data;
buf->maxsize = length;
buf->allowoverflow = qtrue;
buf->allowunderflow = qtrue;
}
-void SZ_Clear( sizebuf_t *buf ) {
+void SZ_Clear(sizebuf_t *buf)
+{
buf->cursize = 0;
buf->readcount = 0;
buf->bitpos = 0;
buf->overflowed = qfalse;
}
-void *SZ_GetSpace( sizebuf_t *buf, size_t length ) {
+void *SZ_GetSpace(sizebuf_t *buf, size_t length)
+{
void *data;
-
- if( buf->cursize + length > buf->maxsize ) {
- if( !buf->allowoverflow ) {
- Com_Error( ERR_FATAL,
- "%s: %#x: overflow without allowoverflow set",
- __func__, buf->tag );
+
+ if (buf->cursize + length > buf->maxsize) {
+ if (!buf->allowoverflow) {
+ Com_Error(ERR_FATAL,
+ "%s: %#x: overflow without allowoverflow set",
+ __func__, buf->tag);
}
- if( length > buf->maxsize ) {
- Com_Error( ERR_FATAL,
- "%s: %#x: %"PRIz" is > full buffer size %"PRIz"",
- __func__, buf->tag, length, buf->maxsize );
+ if (length > buf->maxsize) {
+ Com_Error(ERR_FATAL,
+ "%s: %#x: %"PRIz" is > full buffer size %"PRIz"",
+ __func__, buf->tag, length, buf->maxsize);
}
- //Com_DPrintf( "%s: %#x: overflow\n", __func__, buf->tag );
- SZ_Clear( buf );
+ //Com_DPrintf("%s: %#x: overflow\n", __func__, buf->tag);
+ SZ_Clear(buf);
buf->overflowed = qtrue;
}
data = buf->data + buf->cursize;
buf->cursize += length;
buf->bitpos = buf->cursize << 3;
-
+
return data;
}
-void SZ_WriteByte( sizebuf_t *sb, int c ) {
+void SZ_WriteByte(sizebuf_t *sb, int c)
+{
byte *buf;
- buf = SZ_GetSpace( sb, 1 );
+ buf = SZ_GetSpace(sb, 1);
buf[0] = c;
}
-void SZ_WriteShort( sizebuf_t *sb, int c ) {
+void SZ_WriteShort(sizebuf_t *sb, int c)
+{
byte *buf;
- buf = SZ_GetSpace( sb, 2 );
+ buf = SZ_GetSpace(sb, 2);
buf[0] = c & 0xff;
buf[1] = c >> 8;
}
-void SZ_WriteLong( sizebuf_t *sb, int c ) {
+void SZ_WriteLong(sizebuf_t *sb, int c)
+{
byte *buf;
-
- buf = SZ_GetSpace( sb, 4 );
+
+ buf = SZ_GetSpace(sb, 4);
buf[0] = c & 0xff;
- buf[1] = ( c >> 8 ) & 0xff;
- buf[2] = ( c >> 16 ) & 0xff;
+ buf[1] = (c >> 8) & 0xff;
+ buf[2] = (c >> 16) & 0xff;
buf[3] = c >> 24;
}
#if USE_MVD_SERVER
-void SZ_WriteString( sizebuf_t *sb, const char *string ) {
+void SZ_WriteString(sizebuf_t *sb, const char *string)
+{
size_t length;
- if( !string ) {
- SZ_WriteByte( sb, 0 );
+ if (!string) {
+ SZ_WriteByte(sb, 0);
return;
}
- length = strlen( string );
- if( length >= MAX_NET_STRING ) {
- Com_WPrintf( "%s: overflow: %"PRIz" chars", __func__, length );
- SZ_WriteByte( sb, 0 );
+ length = strlen(string);
+ if (length >= MAX_NET_STRING) {
+ Com_WPrintf("%s: overflow: %"PRIz" chars", __func__, length);
+ SZ_WriteByte(sb, 0);
return;
}
- SZ_Write( sb, string, length + 1 );
+ SZ_Write(sb, string, length + 1);
}
#endif
diff --git a/src/q_msg.h b/src/q_msg.h
index ce874ce..9935db9 100644
--- a/src/q_msg.h
+++ b/src/q_msg.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,13 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// q_msg.h
//
-#define SZ_MSG_WRITE MakeRawLong( 'w', 'r', 'i', 't' )
-#define SZ_MSG_READ MakeRawLong( 'r', 'e', 'a', 'd' )
-#define SZ_NC_SEND_OLD MakeRawLong( 'n', 'c', '1', 's' )
-#define SZ_NC_SEND_NEW MakeRawLong( 'n', 'c', '2', 's' )
-#define SZ_NC_SEND_FRG MakeRawLong( 'n', 'c', '2', 'f' )
-#define SZ_NC_FRG_IN MakeRawLong( 'n', 'c', '2', 'i' )
-#define SZ_NC_FRG_OUT MakeRawLong( 'n', 'c', '2', 'o' )
+#define SZ_MSG_WRITE MakeRawLong('w', 'r', 'i', 't')
+#define SZ_MSG_READ MakeRawLong('r', 'e', 'a', 'd')
+#define SZ_NC_SEND_OLD MakeRawLong('n', 'c', '1', 's')
+#define SZ_NC_SEND_NEW MakeRawLong('n', 'c', '2', 's')
+#define SZ_NC_SEND_FRG MakeRawLong('n', 'c', '2', 'f')
+#define SZ_NC_FRG_IN MakeRawLong('n', 'c', '2', 'i')
+#define SZ_NC_FRG_OUT MakeRawLong('n', 'c', '2', 'o')
typedef struct sizebuf_s {
uint32_t tag;
@@ -42,44 +42,45 @@ typedef struct sizebuf_s {
size_t bitpos;
} sizebuf_t;
-void SZ_Init( sizebuf_t *buf, void *data, size_t length );
-void SZ_TagInit( sizebuf_t *buf, void *data, size_t length, uint32_t tag );
-void SZ_Clear( sizebuf_t *buf );
-void *SZ_GetSpace( sizebuf_t *buf, size_t length );
-void SZ_WriteByte( sizebuf_t *sb, int c );
-void SZ_WriteShort( sizebuf_t *sb, int c );
-void SZ_WriteLong( sizebuf_t *sb, int c );
-void SZ_WriteString( sizebuf_t *sb, const char *string );
-
-static inline void *SZ_Write( sizebuf_t *buf, const void *data, size_t length ) {
- return memcpy( SZ_GetSpace( buf, length ), data, length );
+void SZ_Init(sizebuf_t *buf, void *data, size_t length);
+void SZ_TagInit(sizebuf_t *buf, void *data, size_t length, uint32_t tag);
+void SZ_Clear(sizebuf_t *buf);
+void *SZ_GetSpace(sizebuf_t *buf, size_t length);
+void SZ_WriteByte(sizebuf_t *sb, int c);
+void SZ_WriteShort(sizebuf_t *sb, int c);
+void SZ_WriteLong(sizebuf_t *sb, int c);
+void SZ_WriteString(sizebuf_t *sb, const char *string);
+
+static inline void *SZ_Write(sizebuf_t *buf, const void *data, size_t length)
+{
+ return memcpy(SZ_GetSpace(buf, length), data, length);
}
//============================================================================
typedef enum {
- MSG_PS_IGNORE_GUNINDEX = ( 1 << 0 ),
- MSG_PS_IGNORE_GUNFRAMES = ( 1 << 1 ),
- MSG_PS_IGNORE_BLEND = ( 1 << 2 ),
- MSG_PS_IGNORE_VIEWANGLES = ( 1 << 3 ),
- MSG_PS_IGNORE_DELTAANGLES = ( 1 << 4 ),
- MSG_PS_IGNORE_PREDICTION = ( 1 << 5 ), // mutually exclusive with IGNORE_VIEWANGLES
- MSG_PS_FORCE = ( 1 << 7 ),
- MSG_PS_REMOVE = ( 1 << 8 )
+ MSG_PS_IGNORE_GUNINDEX = (1 << 0),
+ MSG_PS_IGNORE_GUNFRAMES = (1 << 1),
+ MSG_PS_IGNORE_BLEND = (1 << 2),
+ MSG_PS_IGNORE_VIEWANGLES = (1 << 3),
+ MSG_PS_IGNORE_DELTAANGLES = (1 << 4),
+ MSG_PS_IGNORE_PREDICTION = (1 << 5), // mutually exclusive with IGNORE_VIEWANGLES
+ MSG_PS_FORCE = (1 << 7),
+ MSG_PS_REMOVE = (1 << 8)
} msgPsFlags_t;
typedef enum {
- MSG_ES_FORCE = ( 1 << 0 ),
- MSG_ES_NEWENTITY = ( 1 << 1 ),
- MSG_ES_FIRSTPERSON = ( 1 << 2 ),
- MSG_ES_LONGSOLID = ( 1 << 3 ),
- MSG_ES_UMASK = ( 1 << 4 ),
- MSG_ES_BEAMORIGIN = ( 1 << 5 ),
- MSG_ES_SHORTANGLES = ( 1 << 6 ),
- MSG_ES_REMOVE = ( 1 << 7 )
+ MSG_ES_FORCE = (1 << 0),
+ MSG_ES_NEWENTITY = (1 << 1),
+ MSG_ES_FIRSTPERSON = (1 << 2),
+ MSG_ES_LONGSOLID = (1 << 3),
+ MSG_ES_UMASK = (1 << 4),
+ MSG_ES_BEAMORIGIN = (1 << 5),
+ MSG_ES_SHORTANGLES = (1 << 6),
+ MSG_ES_REMOVE = (1 << 7)
} msgEsFlags_t;
-
+
extern sizebuf_t msg_write;
extern byte msg_write_buffer[MAX_MSGLEN];
@@ -90,119 +91,123 @@ extern const entity_state_t nullEntityState;
extern const player_state_t nullPlayerState;
extern const usercmd_t nullUserCmd;
-void MSG_Init( void );
+void MSG_Init(void);
-void MSG_BeginWriting( void );
-void MSG_WriteChar( int c );
-void MSG_WriteByte( int c );
-void MSG_WriteShort( int c );
-void MSG_WriteLong( int c );
-void MSG_WriteString( const char *s );
-void MSG_WritePos( const vec3_t pos );
-void MSG_WriteAngle( float f );
+void MSG_BeginWriting(void);
+void MSG_WriteChar(int c);
+void MSG_WriteByte(int c);
+void MSG_WriteShort(int c);
+void MSG_WriteLong(int c);
+void MSG_WriteString(const char *s);
+void MSG_WritePos(const vec3_t pos);
+void MSG_WriteAngle(float f);
#if USE_CLIENT
-void MSG_WriteBits( int value, int bits );
-int MSG_WriteDeltaUsercmd( const usercmd_t *from, const usercmd_t *cmd, int version );
-int MSG_WriteDeltaUsercmd_Enhanced( const usercmd_t *from, const usercmd_t *cmd, int version );
+void MSG_WriteBits(int value, int bits);
+int MSG_WriteDeltaUsercmd(const usercmd_t *from, const usercmd_t *cmd, int version);
+int MSG_WriteDeltaUsercmd_Enhanced(const usercmd_t *from, const usercmd_t *cmd, int version);
#endif
-void MSG_WriteDir ( const vec3_t vector);
-void MSG_WriteDeltaEntity( const entity_state_t *from, const entity_state_t *to, msgEsFlags_t flags );
-void MSG_WriteDeltaPlayerstate_Default( const player_state_t *from, const player_state_t *to );
-int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from, player_state_t *to, msgPsFlags_t flags );
-void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from, const player_state_t *to, int number, msgPsFlags_t flags );
-void MSG_FlushTo( sizebuf_t *dest );
-void MSG_Printf( const char *fmt, ... ) q_printf( 1, 2 );
-
-static inline void *MSG_WriteData( const void *data, size_t length ) {
- return memcpy( SZ_GetSpace( &msg_write, length ), data, length );
+void MSG_WriteDir(const vec3_t vector);
+void MSG_WriteDeltaEntity(const entity_state_t *from, const entity_state_t *to, msgEsFlags_t flags);
+void MSG_WriteDeltaPlayerstate_Default(const player_state_t *from, const player_state_t *to);
+int MSG_WriteDeltaPlayerstate_Enhanced(const player_state_t *from, player_state_t *to, msgPsFlags_t flags);
+void MSG_WriteDeltaPlayerstate_Packet(const player_state_t *from, const player_state_t *to, int number, msgPsFlags_t flags);
+void MSG_FlushTo(sizebuf_t *dest);
+void MSG_Printf(const char *fmt, ...) q_printf(1, 2);
+
+static inline void *MSG_WriteData(const void *data, size_t length)
+{
+ return memcpy(SZ_GetSpace(&msg_write, length), data, length);
}
-void MSG_BeginReading( void );
-byte *MSG_ReadData( size_t len );
-int MSG_ReadChar( void );
-int MSG_ReadByte( void );
-int MSG_ReadShort( void );
-int MSG_ReadWord( void );
-int MSG_ReadLong( void );
-size_t MSG_ReadString( char *dest, size_t size );
-size_t MSG_ReadStringLine( char *dest, size_t size );
+void MSG_BeginReading(void);
+byte *MSG_ReadData(size_t len);
+int MSG_ReadChar(void);
+int MSG_ReadByte(void);
+int MSG_ReadShort(void);
+int MSG_ReadWord(void);
+int MSG_ReadLong(void);
+size_t MSG_ReadString(char *dest, size_t size);
+size_t MSG_ReadStringLine(char *dest, size_t size);
#if USE_CLIENT
-void MSG_ReadPos( vec3_t pos );
-void MSG_ReadDir( vec3_t vector );
+void MSG_ReadPos(vec3_t pos);
+void MSG_ReadDir(vec3_t vector);
#endif
-int MSG_ReadBits( int bits );
-void MSG_ReadDeltaUsercmd( const usercmd_t *from, usercmd_t *cmd );
-void MSG_ReadDeltaUsercmd_Hacked( const usercmd_t *from, usercmd_t *to );
-void MSG_ReadDeltaUsercmd_Enhanced( const usercmd_t *from, usercmd_t *to, int version );
-int MSG_ParseEntityBits( int *bits );
-void MSG_ParseDeltaEntity( const entity_state_t *from, entity_state_t *to, int number, int bits, msgEsFlags_t flags );
+int MSG_ReadBits(int bits);
+void MSG_ReadDeltaUsercmd(const usercmd_t *from, usercmd_t *cmd);
+void MSG_ReadDeltaUsercmd_Hacked(const usercmd_t *from, usercmd_t *to);
+void MSG_ReadDeltaUsercmd_Enhanced(const usercmd_t *from, usercmd_t *to, int version);
+int MSG_ParseEntityBits(int *bits);
+void MSG_ParseDeltaEntity(const entity_state_t *from, entity_state_t *to, int number, int bits, msgEsFlags_t flags);
#if USE_CLIENT
-void MSG_ParseDeltaPlayerstate_Default( const player_state_t *from, player_state_t *to, int flags );
-void MSG_ParseDeltaPlayerstate_Enhanced( const player_state_t *from, player_state_t *to, int flags, int extraflags );
+void MSG_ParseDeltaPlayerstate_Default(const player_state_t *from, player_state_t *to, int flags);
+void MSG_ParseDeltaPlayerstate_Enhanced(const player_state_t *from, player_state_t *to, int flags, int extraflags);
#endif
-void MSG_ParseDeltaPlayerstate_Packet( const player_state_t *from, player_state_t *to, int flags );
+void MSG_ParseDeltaPlayerstate_Packet(const player_state_t *from, player_state_t *to, int flags);
#ifdef _DEBUG
#if USE_CLIENT
-void MSG_ShowDeltaPlayerstateBits_Default( int flags );
-void MSG_ShowDeltaPlayerstateBits_Enhanced( int flags );
-void MSG_ShowDeltaUsercmdBits_Enhanced( int bits );
+void MSG_ShowDeltaPlayerstateBits_Default(int flags);
+void MSG_ShowDeltaPlayerstateBits_Enhanced(int flags);
+void MSG_ShowDeltaUsercmdBits_Enhanced(int bits);
#endif
#if USE_CLIENT || USE_MVD_CLIENT
-void MSG_ShowDeltaEntityBits( int bits );
-void MSG_ShowDeltaPlayerstateBits_Packet( int flags );
-const char *MSG_ServerCommandString( int cmd );
-#define MSG_ShowSVC( cmd ) \
- Com_LPrintf( PRINT_DEVELOPER, "%3"PRIz":%s\n", msg_read.readcount - 1, \
- MSG_ServerCommandString( cmd ) )
+void MSG_ShowDeltaEntityBits(int bits);
+void MSG_ShowDeltaPlayerstateBits_Packet(int flags);
+const char *MSG_ServerCommandString(int cmd);
+#define MSG_ShowSVC(cmd) \
+ Com_LPrintf(PRINT_DEVELOPER, "%3"PRIz":%s\n", msg_read.readcount - 1, \
+ MSG_ServerCommandString(cmd))
#endif // USE_CLIENT || USE_MVD_CLIENT
#endif // _DEBUG
//============================================================================
-static inline int MSG_PackSolid16( const vec3_t mins, const vec3_t maxs ) {
+static inline int MSG_PackSolid16(const vec3_t mins, const vec3_t maxs)
+{
int x, zd, zu;
// assume that x/y are equal and symetric
x = maxs[0] / 8;
- clamp( x, 1, 31 );
+ clamp(x, 1, 31);
// z is not symetric
zd = -mins[2] / 8;
- clamp( zd, 1, 31 );
+ clamp(zd, 1, 31);
// and z maxs can be negative...
- zu = ( maxs[2] + 32 ) / 8;
- clamp( zu, 1, 63 );
+ zu = (maxs[2] + 32) / 8;
+ clamp(zu, 1, 63);
- return ( zu << 10 ) | ( zd << 5 ) | x;
+ return (zu << 10) | (zd << 5) | x;
}
-static inline int MSG_PackSolid32( const vec3_t mins, const vec3_t maxs ) {
+static inline int MSG_PackSolid32(const vec3_t mins, const vec3_t maxs)
+{
int x, zd, zu;
// assume that x/y are equal and symetric
x = maxs[0];
- clamp( x, 1, 255 );
+ clamp(x, 1, 255);
// z is not symetric
zd = -mins[2];
- clamp( zd, 1, 255 );
+ clamp(zd, 1, 255);
// and z maxs can be negative...
zu = maxs[2] + 32768;
- clamp( zu, 1, 65535 );
+ clamp(zu, 1, 65535);
- return ( zu << 16 ) | ( zd << 8 ) | x;
+ return (zu << 16) | (zd << 8) | x;
}
-static inline void MSG_UnpackSolid16( int solid, vec3_t mins, vec3_t maxs ) {
+static inline void MSG_UnpackSolid16(int solid, vec3_t mins, vec3_t maxs)
+{
int x, zd, zu;
- x = 8 * ( solid & 31 );
- zd = 8 * ( ( solid >> 5 ) & 31 );
- zu = 8 * ( ( solid >> 10 ) & 63 ) - 32;
+ x = 8 * (solid & 31);
+ zd = 8 * ((solid >> 5) & 31);
+ zu = 8 * ((solid >> 10) & 63) - 32;
mins[0] = mins[1] = -x;
maxs[0] = maxs[1] = x;
@@ -210,12 +215,13 @@ static inline void MSG_UnpackSolid16( int solid, vec3_t mins, vec3_t maxs ) {
maxs[2] = zu;
}
-static inline void MSG_UnpackSolid32( int solid, vec3_t mins, vec3_t maxs ) {
+static inline void MSG_UnpackSolid32(int solid, vec3_t mins, vec3_t maxs)
+{
int x, zd, zu;
x = solid & 255;
- zd = ( solid >> 8 ) & 255;
- zu = ( ( solid >> 16 ) & 65535 ) - 32768;
+ zd = (solid >> 8) & 255;
+ zu = ((solid >> 16) & 65535) - 32768;
mins[0] = mins[1] = -x;
maxs[0] = maxs[1] = x;
diff --git a/src/q_shared.c b/src/q_shared.c
index a54765d..353993a 100644
--- a/src/q_shared.c
+++ b/src/q_shared.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,90 +23,86 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
vec3_t vec3_origin = { 0, 0, 0 };
-void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
+void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
{
float angle;
float sr, sp, sy, cr, cp, cy;
- angle = angles[YAW] * (M_PI*2 / 360);
+ angle = angles[YAW] * (M_PI * 2 / 360);
sy = sin(angle);
cy = cos(angle);
- angle = angles[PITCH] * (M_PI*2 / 360);
+ angle = angles[PITCH] * (M_PI * 2 / 360);
sp = sin(angle);
cp = cos(angle);
- angle = angles[ROLL] * (M_PI*2 / 360);
+ angle = angles[ROLL] * (M_PI * 2 / 360);
sr = sin(angle);
cr = cos(angle);
- if (forward)
- {
- forward[0] = cp*cy;
- forward[1] = cp*sy;
+ if (forward) {
+ forward[0] = cp * cy;
+ forward[1] = cp * sy;
forward[2] = -sp;
}
- if (right)
- {
- right[0] = (-1*sr*sp*cy+-1*cr*-sy);
- right[1] = (-1*sr*sp*sy+-1*cr*cy);
- right[2] = -1*sr*cp;
+ if (right) {
+ right[0] = (-1 * sr * sp * cy + -1 * cr * -sy);
+ right[1] = (-1 * sr * sp * sy + -1 * cr * cy);
+ right[2] = -1 * sr * cp;
}
- if (up)
- {
- up[0] = (cr*sp*cy+-sr*-sy);
- up[1] = (cr*sp*sy+-sr*cy);
- up[2] = cr*cp;
+ if (up) {
+ up[0] = (cr * sp * cy + -sr * -sy);
+ up[1] = (cr * sp * sy + -sr * cy);
+ up[2] = cr * cp;
}
}
-vec_t VectorNormalize (vec3_t v)
+vec_t VectorNormalize(vec3_t v)
{
float length, ilength;
- length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
- length = sqrt (length); // FIXME
+ length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+ length = sqrt(length); // FIXME
- if (length)
- {
- ilength = 1/length;
+ if (length) {
+ ilength = 1 / length;
v[0] *= ilength;
v[1] *= ilength;
v[2] *= ilength;
}
-
+
return length;
}
-vec_t VectorNormalize2 (vec3_t v, vec3_t out)
+vec_t VectorNormalize2(vec3_t v, vec3_t out)
{
float length, ilength;
- length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
- length = sqrt (length); // FIXME
+ length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+ length = sqrt(length); // FIXME
- if (length)
- {
- ilength = 1/length;
- out[0] = v[0]*ilength;
- out[1] = v[1]*ilength;
- out[2] = v[2]*ilength;
+ if (length) {
+ ilength = 1 / length;
+ out[0] = v[0] * ilength;
+ out[1] = v[1] * ilength;
+ out[2] = v[2] * ilength;
}
-
+
return length;
}
-void ClearBounds (vec3_t mins, vec3_t maxs) {
+void ClearBounds(vec3_t mins, vec3_t maxs)
+{
mins[0] = mins[1] = mins[2] = 99999;
maxs[0] = maxs[1] = maxs[2] = -99999;
}
-void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs) {
+void AddPointToBounds(const vec3_t v, vec3_t mins, vec3_t maxs)
+{
int i;
vec_t val;
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
val = v[i];
if (val < mins[i])
mins[i] = val;
@@ -115,7 +111,8 @@ void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs) {
}
}
-void UnionBounds( vec3_t a[2], vec3_t b[2], vec3_t c[2] ) {
+void UnionBounds(vec3_t a[2], vec3_t b[2], vec3_t c[2])
+{
c[0][0] = b[0][0] < a[0][0] ? b[0][0] : a[0][0];
c[0][1] = b[0][1] < a[0][1] ? b[0][1] : a[0][1];
c[0][2] = b[0][2] < a[0][2] ? b[0][2] : a[0][2];
@@ -130,19 +127,19 @@ void UnionBounds( vec3_t a[2], vec3_t b[2], vec3_t c[2] ) {
RadiusFromBounds
=================
*/
-vec_t RadiusFromBounds (const vec3_t mins, const vec3_t maxs) {
+vec_t RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
+{
int i;
vec3_t corner;
vec_t a, b;
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
a = Q_fabs(mins[i]);
b = Q_fabs(maxs[i]);
corner[i] = a > b ? a : b;
}
- return VectorLength (corner);
+ return VectorLength(corner);
}
//====================================================================================
@@ -154,16 +151,17 @@ static const char hexchars[] = "0123456789ABCDEF";
COM_SkipPath
============
*/
-char *COM_SkipPath( const char *pathname ) {
+char *COM_SkipPath(const char *pathname)
+{
char *last;
- if( !pathname ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!pathname) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
-
+
last = (char *)pathname;
- while( *pathname ) {
- if( *pathname == '/' )
+ while (*pathname) {
+ if (*pathname == '/')
last = (char *)pathname + 1;
pathname++;
}
@@ -175,18 +173,19 @@ char *COM_SkipPath( const char *pathname ) {
COM_StripExtension
============
*/
-void COM_StripExtension( const char *in, char *out, size_t size ) {
+void COM_StripExtension(const char *in, char *out, size_t size)
+{
char *s;
- Q_strlcpy( out, in, size );
+ Q_strlcpy(out, in, size);
- s = out + strlen( out );
-
- while( s != out ) {
- if( *s == '/' ) {
+ s = out + strlen(out);
+
+ while (s != out) {
+ if (*s == '/') {
break;
}
- if( *s == '.' ) {
+ if (*s == '.') {
*s = 0;
break;
}
@@ -199,22 +198,23 @@ void COM_StripExtension( const char *in, char *out, size_t size ) {
COM_FileExtension
============
*/
-char *COM_FileExtension( const char *in ) {
+char *COM_FileExtension(const char *in)
+{
const char *s;
const char *last;
- if( !in ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!in) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
- s = in + strlen( in );
+ s = in + strlen(in);
last = s;
-
- while( s != in ) {
- if( *s == '/' ) {
+
+ while (s != in) {
+ if (*s == '/') {
break;
}
- if( *s == '.' ) {
+ if (*s == '.') {
return (char *)s;
}
s--;
@@ -228,25 +228,24 @@ char *COM_FileExtension( const char *in ) {
COM_FileBase
============
*/
-void COM_FileBase (char *in, char *out)
+void COM_FileBase(char *in, char *out)
{
char *s, *s2;
-
+
s = in + strlen(in) - 1;
-
+
while (s != in && *s != '.')
s--;
-
- for (s2 = s ; s2 != in && *s2 != '/' ; s2--)
- ;
-
- if (s-s2 < 2)
+
+ for (s2 = s; s2 != in && *s2 != '/'; s2--)
+ ;
+
+ if (s - s2 < 2)
out[0] = 0;
- else
- {
+ else {
s--;
- strncpy (out,s2+1, s-s2);
- out[s-s2] = 0;
+ strncpy(out, s2 + 1, s - s2);
+ out[s - s2] = 0;
}
}
@@ -257,12 +256,13 @@ COM_FilePath
Returns the path up to, but not including the last /
============
*/
-void COM_FilePath( const char *in, char *out, size_t size ) {
+void COM_FilePath(const char *in, char *out, size_t size)
+{
char *s;
- Q_strlcpy( out, in, size );
- s = strrchr( out, '/' );
- if( s ) {
+ Q_strlcpy(out, in, size);
+ s = strrchr(out, '/');
+ if (s) {
*s = 0;
} else {
*out = 0;
@@ -278,22 +278,23 @@ if path doesn't have .EXT, append extension
(extension should include the .)
==================
*/
-size_t COM_DefaultExtension( char *path, const char *ext, size_t size ) {
+size_t COM_DefaultExtension(char *path, const char *ext, size_t size)
+{
char *src;
size_t len;
- if( *path ) {
- len = strlen( path );
+ if (*path) {
+ len = strlen(path);
src = path + len - 1;
- while( *src != '/' && src != path ) {
- if( *src == '.' )
+ while (*src != '/' && src != path) {
+ if (*src == '.')
return len; // it has an extension
src--;
}
}
- len = Q_strlcat( path, ext, size );
+ len = Q_strlcat(path, ext, size);
return len;
}
@@ -305,68 +306,72 @@ Returns true if the given string is valid representation
of floating point number.
==================
*/
-qboolean COM_IsFloat( const char *s ) {
+qboolean COM_IsFloat(const char *s)
+{
int c, dot = '.';
- if( *s == '-' ) {
+ if (*s == '-') {
s++;
}
- if( !*s ) {
+ if (!*s) {
return qfalse;
}
do {
c = *s++;
- if( c == dot ) {
+ if (c == dot) {
dot = 0;
- } else if( !Q_isdigit( c ) ) {
+ } else if (!Q_isdigit(c)) {
return qfalse;
}
- } while( *s );
+ } while (*s);
return qtrue;
}
-qboolean COM_IsUint( const char *s ) {
+qboolean COM_IsUint(const char *s)
+{
int c;
- if( !*s ) {
+ if (!*s) {
return qfalse;
}
do {
c = *s++;
- if( !Q_isdigit( c ) ) {
+ if (!Q_isdigit(c)) {
return qfalse;
}
- } while( *s );
+ } while (*s);
return qtrue;
}
-qboolean COM_IsPath( const char *s ) {
+qboolean COM_IsPath(const char *s)
+{
int c;
- if( !*s ) {
+ if (!*s) {
return qfalse;
}
do {
c = *s++;
- if( !Q_ispath( c ) ) {
+ if (!Q_ispath(c)) {
return qfalse;
}
- } while( *s );
+ } while (*s);
return qtrue;
}
-qboolean COM_IsWhite( const char *s ) {
+qboolean COM_IsWhite(const char *s)
+{
int c;
- while( *s ) {
+ while (*s) {
c = *s++;
- if( Q_isgraph( c ) ) {
+ if (Q_isgraph(c)) {
return qfalse;
}
}
@@ -374,12 +379,14 @@ qboolean COM_IsWhite( const char *s ) {
return qtrue;
}
-int QDECL SortStrcmp( const void *p1, const void *p2 ) {
- return strcmp( *( const char ** )p1, *( const char ** )p2 );
+int QDECL SortStrcmp(const void *p1, const void *p2)
+{
+ return strcmp(*(const char **)p1, *(const char **)p2);
}
-int QDECL SortStricmp( const void *p1, const void *p2 ) {
- return Q_stricmp( *( const char ** )p1, *( const char ** )p2 );
+int QDECL SortStricmp(const void *p1, const void *p2)
+{
+ return Q_stricmp(*(const char **)p1, *(const char **)p2);
}
/*
@@ -390,17 +397,18 @@ Operates inplace, normalizing high-bit and removing unprintable characters.
Returns final number of characters, not including the NUL character.
================
*/
-size_t COM_strclr( char *s ) {
+size_t COM_strclr(char *s)
+{
char *p;
int c;
size_t len;
p = s;
len = 0;
- while( *s ) {
+ while (*s) {
c = *s++;
c &= 127;
- if( Q_isprint( c ) ) {
+ if (Q_isprint(c)) {
*p++ = c;
len++;
}
@@ -420,18 +428,19 @@ varargs versions of all text functions.
FIXME: make this buffer size safe someday
============
*/
-char *va( const char *format, ... ) {
+char *va(const char *format, ...)
+{
va_list argptr;
static char buffers[2][0x2800];
static int index;
index ^= 1;
-
- va_start( argptr, format );
- Q_vsnprintf( buffers[index], sizeof( buffers[0] ), format, argptr );
- va_end( argptr );
- return buffers[index];
+ va_start(argptr, format);
+ Q_vsnprintf(buffers[index], sizeof(buffers[0]), format, argptr);
+ va_end(argptr);
+
+ return buffers[index];
}
static char com_token[4][MAX_TOKEN_CHARS];
@@ -445,7 +454,8 @@ Parse a token out of a string.
Handles C and C++ comments.
==============
*/
-char *COM_Parse( const char **data_p ) {
+char *COM_Parse(const char **data_p)
+{
int c;
int len;
const char *data;
@@ -454,35 +464,35 @@ char *COM_Parse( const char **data_p ) {
data = *data_p;
len = 0;
s[0] = 0;
-
- if( !data ) {
+
+ if (!data) {
*data_p = NULL;
return s;
}
-
+
// skip whitespace
skipwhite:
- while( ( c = *data ) <= ' ' ) {
- if( c == 0 ) {
+ while ((c = *data) <= ' ') {
+ if (c == 0) {
*data_p = NULL;
return s;
}
data++;
}
-
+
// skip // comments
- if( c == '/' && data[1] == '/' ) {
+ if (c == '/' && data[1] == '/') {
data += 2;
- while( *data && *data != '\n' )
+ while (*data && *data != '\n')
data++;
goto skipwhite;
}
// skip /* */ comments
- if( c == '/' && data[1] == '*' ) {
+ if (c == '/' && data[1] == '*') {
data += 2;
- while( *data ) {
- if( data[0] == '*' && data[1] == '/' ) {
+ while (*data) {
+ if (data[0] == '*' && data[1] == '/') {
data += 2;
break;
}
@@ -492,15 +502,15 @@ skipwhite:
}
// handle quoted strings specially
- if( c == '\"' ) {
+ if (c == '\"') {
data++;
- while( 1 ) {
+ while (1) {
c = *data++;
- if( c == '\"' || !c ) {
+ if (c == '\"' || !c) {
goto finish;
}
- if( len < MAX_TOKEN_CHARS - 1 ) {
+ if (len < MAX_TOKEN_CHARS - 1) {
s[len++] = c;
}
}
@@ -508,12 +518,12 @@ skipwhite:
// parse a regular word
do {
- if( len < MAX_TOKEN_CHARS - 1 ) {
+ if (len < MAX_TOKEN_CHARS - 1) {
s[len++] = c;
}
data++;
c = *data;
- } while( c > 32 );
+ } while (c > 32);
finish:
s[len] = 0;
@@ -532,41 +542,42 @@ Non-contiguous line feeds are preserved.
Returns resulting data length.
==============
*/
-int COM_Compress( char *data ) {
+int COM_Compress(char *data)
+{
int c, n = 0;
char *s = data, *d = data;
- while( *s ) {
- // skip whitespace
- if( *s <= ' ' ) {
+ while (*s) {
+ // skip whitespace
+ if (*s <= ' ') {
n = ' ';
do {
c = *s++;
- if( c == '\n' ) {
+ if (c == '\n') {
n = '\n';
}
- if( !c ) {
+ if (!c) {
goto finish;
}
- } while( *s <= ' ' );
+ } while (*s <= ' ');
}
-
+
// skip // comments
- if( s[0] == '/' && s[1] == '/' ) {
+ if (s[0] == '/' && s[1] == '/') {
n = ' ';
s += 2;
- while( *s && *s != '\n' ) {
+ while (*s && *s != '\n') {
s++;
}
continue;
}
// skip /* */ comments
- if( s[0] == '/' && s[1] == '*' ) {
+ if (s[0] == '/' && s[1] == '*') {
n = ' ';
s += 2;
- while( *s ) {
- if( s[0] == '*' && s[1] == '/' ) {
+ while (*s) {
+ if (s[0] == '*' && s[1] == '/') {
s += 2;
break;
}
@@ -576,27 +587,27 @@ int COM_Compress( char *data ) {
}
// add whitespace character
- if( n ) {
+ if (n) {
*d++ = n;
n = 0;
}
// handle quoted strings specially
- if( *s == '\"' ) {
+ if (*s == '\"') {
s++;
*d++ = '\"';
do {
c = *s++;
- if( !c ) {
+ if (!c) {
goto finish;
}
*d++ = c;
- } while( c != '\"' );
+ } while (c != '\"');
continue;
}
// handle line feed escape
- if( *s == '\\' && s[1] == '\n' ) {
+ if (*s == '\\' && s[1] == '\n') {
s += 2;
continue;
}
@@ -604,7 +615,7 @@ int COM_Compress( char *data ) {
// parse a regular word
do {
*d++ = *s++;
- } while( *s > ' ' );
+ } while (*s > ' ');
}
finish:
@@ -621,62 +632,65 @@ finish:
============================================================================
*/
-int Q_strncasecmp( const char *s1, const char *s2, size_t n ) {
+int Q_strncasecmp(const char *s1, const char *s2, size_t n)
+{
int c1, c2;
-
+
do {
c1 = *s1++;
c2 = *s2++;
- if( !n-- )
+ if (!n--)
return 0; /* strings are equal until end point */
-
- if( c1 != c2 ) {
- c1 = Q_tolower( c1 );
- c2 = Q_tolower( c2 );
- if( c1 < c2 )
+
+ if (c1 != c2) {
+ c1 = Q_tolower(c1);
+ c2 = Q_tolower(c2);
+ if (c1 < c2)
return -1;
- if( c1 > c2 )
+ if (c1 > c2)
return 1; /* strings not equal */
}
- } while( c1 );
-
+ } while (c1);
+
return 0; /* strings are equal */
}
-int Q_strcasecmp( const char *s1, const char *s2 ) {
+int Q_strcasecmp(const char *s1, const char *s2)
+{
int c1, c2;
-
+
do {
c1 = *s1++;
c2 = *s2++;
-
- if( c1 != c2 ) {
- c1 = Q_tolower( c1 );
- c2 = Q_tolower( c2 );
- if( c1 < c2 )
+
+ if (c1 != c2) {
+ c1 = Q_tolower(c1);
+ c2 = Q_tolower(c2);
+ if (c1 < c2)
return -1;
- if( c1 > c2 )
+ if (c1 > c2)
return 1; /* strings not equal */
}
- } while( c1 );
-
+ } while (c1);
+
return 0; /* strings are equal */
}
-char *Q_strcasestr( const char *s1, const char *s2 ) {
+char *Q_strcasestr(const char *s1, const char *s2)
+{
size_t l1, l2;
- l2 = strlen( s2 );
- if( !l2 ) {
- return ( char * )s1;
+ l2 = strlen(s2);
+ if (!l2) {
+ return (char *)s1;
}
- l1 = strlen( s1 );
- while( l1 >= l2 ) {
+ l1 = strlen(s1);
+ while (l1 >= l2) {
l1--;
- if( !Q_strncasecmp( s1, s2, l2 ) ) {
- return ( char * )s1;
+ if (!Q_strncasecmp(s1, s2, l2)) {
+ return (char *)s1;
}
s1++;
}
@@ -691,12 +705,13 @@ Q_strlcpy
Returns length of the source string.
===============
*/
-size_t Q_strlcpy( char *dst, const char *src, size_t size ) {
- size_t ret = strlen( src );
+size_t Q_strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t ret = strlen(src);
- if( size ) {
+ if (size) {
size_t len = ret >= size ? size - 1 : ret;
- memcpy( dst, src, len );
+ memcpy(dst, src, len);
dst[len] = 0;
}
@@ -710,14 +725,15 @@ Q_strlcat
Returns length of the source and destinations strings combined.
===============
*/
-size_t Q_strlcat( char *dst, const char *src, size_t size ) {
- size_t ret, len = strlen( dst );
+size_t Q_strlcat(char *dst, const char *src, size_t size)
+{
+ size_t ret, len = strlen(dst);
- if( len >= size ) {
- Com_Error( ERR_FATAL, "%s: already overflowed", __func__ );
+ if (len >= size) {
+ Com_Error(ERR_FATAL, "%s: already overflowed", __func__);
}
- ret = Q_strlcpy( dst + len, src, size - len );
+ ret = Q_strlcpy(dst + len, src, size - len);
ret += len;
return ret;
@@ -732,23 +748,24 @@ excluding trailing '\0'. If the returned value is equal to or greater than
buffer size, resulting string is truncated.
===============
*/
-size_t Q_concat( char *dest, size_t size, ... ) {
+size_t Q_concat(char *dest, size_t size, ...)
+{
va_list argptr;
const char *s;
size_t len, total = 0;
- va_start( argptr, size );
- while( ( s = va_arg( argptr, const char * ) ) != NULL ) {
- len = strlen( s );
- if( total + len < size ) {
- memcpy( dest, s, len );
+ va_start(argptr, size);
+ while ((s = va_arg(argptr, const char *)) != NULL) {
+ len = strlen(s);
+ if (total + len < size) {
+ memcpy(dest, s, len);
dest += len;
}
total += len;
}
- va_end( argptr );
+ va_end(argptr);
- if( size ) {
+ if (size) {
*dest = 0;
}
@@ -764,35 +781,36 @@ excluding trailing '\0'. If the returned value is equal to or greater than
buffer size, resulting string is truncated.
===============
*/
-size_t Q_vsnprintf( char *dest, size_t size, const char *fmt, va_list argptr ) {
+size_t Q_vsnprintf(char *dest, size_t size, const char *fmt, va_list argptr)
+{
int ret;
- if( size > INT_MAX ) {
- Com_Error( ERR_FATAL, "%s: bad buffer size", __func__ );
+ if (size > INT_MAX) {
+ Com_Error(ERR_FATAL, "%s: bad buffer size", __func__);
}
#ifdef _WIN32
// work around broken M$ C runtime semantics.
- if( !size ) {
+ if (!size) {
return 0;
}
- ret = _vsnprintf( dest, size - 1, fmt, argptr );
- if( ret >= size - 1 ) {
+ ret = _vsnprintf(dest, size - 1, fmt, argptr);
+ if (ret >= size - 1) {
dest[size - 1] = 0;
}
#else
- ret = vsnprintf( dest, size, fmt, argptr );
+ ret = vsnprintf(dest, size, fmt, argptr);
#endif
// this shouldn't happen
- if( ret < 0 ) {
- if( size ) {
+ if (ret < 0) {
+ if (size) {
*dest = 0;
}
ret = 0;
}
- return ( size_t )ret;
+ return (size_t)ret;
}
/*
@@ -804,14 +822,15 @@ excluding trailing '\0'. If buffer size is 0, this function does nothing
and returns 0.
===============
*/
-size_t Q_vscnprintf( char *dest, size_t size, const char *fmt, va_list argptr ) {
+size_t Q_vscnprintf(char *dest, size_t size, const char *fmt, va_list argptr)
+{
size_t ret;
-
- if( !size ) {
+
+ if (!size) {
return 0;
}
- ret = Q_vsnprintf( dest, size, fmt, argptr );
+ ret = Q_vsnprintf(dest, size, fmt, argptr);
return ret >= size ? size - 1 : ret;
}
@@ -825,13 +844,14 @@ excluding trailing '\0'. If the returned value is equal to or greater than
buffer size, resulting string is truncated.
===============
*/
-size_t Q_snprintf( char *dest, size_t size, const char *fmt, ... ) {
+size_t Q_snprintf(char *dest, size_t size, const char *fmt, ...)
+{
va_list argptr;
size_t ret;
- va_start( argptr, fmt );
- ret = Q_vsnprintf( dest, size, fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ ret = Q_vsnprintf(dest, size, fmt, argptr);
+ va_end(argptr);
return ret;
}
@@ -845,22 +865,24 @@ excluding trailing '\0'. If buffer size is 0, this function does nothing
and returns 0.
===============
*/
-size_t Q_scnprintf( char *dest, size_t size, const char *fmt, ... ) {
+size_t Q_scnprintf(char *dest, size_t size, const char *fmt, ...)
+{
va_list argptr;
size_t ret;
- va_start( argptr, fmt );
- ret = Q_vscnprintf( dest, size, fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ ret = Q_vscnprintf(dest, size, fmt, argptr);
+ va_end(argptr);
return ret;
}
-char *Q_strchrnul( const char *s, int c ) {
- while( *s && *s != c ) {
+char *Q_strchrnul(const char *s, int c)
+{
+ while (*s && *s != c) {
s++;
}
- return ( char * )s;
+ return (char *)s;
}
/*
@@ -871,12 +893,13 @@ Copies no more than 'size' bytes stopping when 'c' character is found.
Returns pointer to next byte after 'c' in 'dst', or NULL if 'c' was not found.
===============
*/
-void *Q_memccpy( void *dst, const void *src, int c, size_t size ) {
+void *Q_memccpy(void *dst, const void *src, int c, size_t size)
+{
byte *d = dst;
const byte *s = src;
- while( size-- ) {
- if( ( *d++ = *s++ ) == c ) {
+ while (size--) {
+ if ((*d++ = *s++) == c) {
return d;
}
}
@@ -884,21 +907,22 @@ void *Q_memccpy( void *dst, const void *src, int c, size_t size ) {
return NULL;
}
-void Q_setenv( const char *name, const char *value ) {
+void Q_setenv(const char *name, const char *value)
+{
#ifdef _WIN32
- if( !value ) {
+ if (!value) {
value = "";
}
-#if( _MSC_VER >= 1400 )
- _putenv_s( name, value );
+#if (_MSC_VER >= 1400)
+ _putenv_s(name, value);
#else
- _putenv( va( "%s=%s", name, value ) );
+ _putenv(va("%s=%s", name, value));
#endif
#else // _WIN32
- if( value ) {
- setenv( name, value, 1 );
+ if (value) {
+ setenv(name, value, 1);
} else {
- unsetenv( name );
+ unsetenv(name);
}
#endif // !_WIN32
}
@@ -919,20 +943,21 @@ Searches the string for the given
key and returns the associated value, or an empty string.
===============
*/
-char *Info_ValueForKey( const char *s, const char *key ) {
+char *Info_ValueForKey(const char *s, const char *key)
+{
static char value[4][MAX_INFO_STRING]; // use 4 buffers so compares
- // work without stomping on each other
+ // work without stomping on each other
static int valueindex;
char pkey[MAX_INFO_STRING];
char *o;
valueindex++;
- if( *s == '\\' )
+ if (*s == '\\')
s++;
- while( 1 ) {
+ while (1) {
o = pkey;
- while( *s != '\\' ) {
- if( !*s )
+ while (*s != '\\') {
+ if (!*s)
return "";
*o++ = *s++;
}
@@ -940,15 +965,15 @@ char *Info_ValueForKey( const char *s, const char *key ) {
s++;
o = value[valueindex & 3];
- while( *s != '\\' && *s ) {
+ while (*s != '\\' && *s) {
*o++ = *s++;
}
*o = 0;
- if( !strcmp( key, pkey ) )
+ if (!strcmp(key, pkey))
return value[valueindex & 3];
- if( !*s )
+ if (!*s)
return "";
s++;
}
@@ -961,31 +986,32 @@ char *Info_ValueForKey( const char *s, const char *key ) {
Info_RemoveKey
==================
*/
-void Info_RemoveKey( char *s, const char *key ) {
+void Info_RemoveKey(char *s, const char *key)
+{
char *start;
char pkey[MAX_INFO_STRING];
char *o;
- while( 1 ) {
+ while (1) {
start = s;
- if( *s == '\\' )
+ if (*s == '\\')
s++;
o = pkey;
- while( *s != '\\' ) {
- if( !*s )
+ while (*s != '\\') {
+ if (!*s)
return;
*o++ = *s++;
}
*o = 0;
s++;
- while( *s != '\\' && *s ) {
+ while (*s != '\\' && *s) {
s++;
}
- if( !strcmp( key, pkey ) ) {
+ if (!strcmp(key, pkey)) {
o = start; // remove this part
- while( *s ) {
+ while (*s) {
*o++ = *s++;
}
*o = 0;
@@ -993,7 +1019,7 @@ void Info_RemoveKey( char *s, const char *key ) {
continue; // search for duplicates
}
- if( !*s )
+ if (!*s)
return;
}
@@ -1009,37 +1035,38 @@ can mess up the server's parsing.
Also checks the length of keys/values and the whole string.
==================
*/
-qboolean Info_Validate( const char *s ) {
+qboolean Info_Validate(const char *s)
+{
size_t len, total;
int c;
-
+
total = 0;
- while( 1 ) {
+ while (1) {
//
// validate key
//
- if( *s == '\\' ) {
+ if (*s == '\\') {
s++;
- if( ++total == MAX_INFO_STRING ) {
+ if (++total == MAX_INFO_STRING) {
return qfalse; // oversize infostring
}
}
- if( !*s ) {
+ if (!*s) {
return qfalse; // missing key
}
len = 0;
- while( *s != '\\' ) {
+ while (*s != '\\') {
c = *s++;
- if( !Q_isprint( c ) || c == '\"' || c == ';' ) {
+ if (!Q_isprint(c) || c == '\"' || c == ';') {
return qfalse; // illegal characters
}
- if( ++len == MAX_INFO_KEY ) {
+ if (++len == MAX_INFO_KEY) {
return qfalse; // oversize key
}
- if( ++total == MAX_INFO_STRING ) {
+ if (++total == MAX_INFO_STRING) {
return qfalse; // oversize infostring
}
- if( !*s ) {
+ if (!*s) {
return qfalse; // missing value
}
}
@@ -1048,25 +1075,25 @@ qboolean Info_Validate( const char *s ) {
// validate value
//
s++;
- if( ++total == MAX_INFO_STRING ) {
+ if (++total == MAX_INFO_STRING) {
return qfalse; // oversize infostring
}
- if( !*s ) {
+ if (!*s) {
return qfalse; // missing value
}
len = 0;
- while( *s != '\\' ) {
+ while (*s != '\\') {
c = *s++;
- if( !Q_isprint( c ) || c == '\"' || c == ';' ) {
+ if (!Q_isprint(c) || c == '\"' || c == ';') {
return qfalse; // illegal characters
}
- if( ++len == MAX_INFO_VALUE ) {
+ if (++len == MAX_INFO_VALUE) {
return qfalse; // oversize value
}
- if( ++total == MAX_INFO_STRING ) {
+ if (++total == MAX_INFO_STRING) {
return qfalse; // oversize infostring
}
- if( !*s ) {
+ if (!*s) {
return qtrue; // end of string
}
}
@@ -1080,18 +1107,19 @@ qboolean Info_Validate( const char *s ) {
Info_SubValidate
============
*/
-size_t Info_SubValidate( const char *s ) {
+size_t Info_SubValidate(const char *s)
+{
size_t len;
int c;
len = 0;
- while( *s ) {
+ while (*s) {
c = *s++;
c &= 127; // strip high bits
- if( c == '\\' || c == '\"' || c == ';' ) {
+ if (c == '\\' || c == '\"' || c == ';') {
return SIZE_MAX; // illegal characters
}
- if( ++len == MAX_QPATH ) {
+ if (++len == MAX_QPATH) {
return MAX_QPATH; // oversize value
}
}
@@ -1104,45 +1132,46 @@ size_t Info_SubValidate( const char *s ) {
Info_SetValueForKey
==================
*/
-qboolean Info_SetValueForKey( char *s, const char *key, const char *value ) {
+qboolean Info_SetValueForKey(char *s, const char *key, const char *value)
+{
char newi[MAX_INFO_STRING], *v;
size_t l, kl, vl;
int c;
// validate key
- kl = Info_SubValidate( key );
- if( kl >= MAX_QPATH ) {
+ kl = Info_SubValidate(key);
+ if (kl >= MAX_QPATH) {
return qfalse;
}
// validate value
- vl = Info_SubValidate( value );
- if( vl >= MAX_QPATH ) {
+ vl = Info_SubValidate(value);
+ if (vl >= MAX_QPATH) {
return qfalse;
}
- Info_RemoveKey( s, key );
- if( !vl ) {
+ Info_RemoveKey(s, key);
+ if (!vl) {
return qtrue;
}
- l = strlen( s );
- if( l + kl + vl + 2 >= MAX_INFO_STRING ) {
+ l = strlen(s);
+ if (l + kl + vl + 2 >= MAX_INFO_STRING) {
return qfalse;
}
newi[0] = '\\';
- memcpy( newi + 1, key, kl );
+ memcpy(newi + 1, key, kl);
newi[kl + 1] = '\\';
- memcpy( newi + kl + 2, value, vl + 1 );
+ memcpy(newi + kl + 2, value, vl + 1);
// only copy ascii values
s += l;
v = newi;
- while( *v ) {
+ while (*v) {
c = *v++;
c &= 127; // strip high bits
- if( Q_isprint( c ) )
+ if (Q_isprint(c))
*s++ = c;
}
*s = 0;
@@ -1155,50 +1184,51 @@ qboolean Info_SetValueForKey( char *s, const char *key, const char *value ) {
Info_NextPair
==================
*/
-void Info_NextPair( const char **string, char *key, char *value ) {
+void Info_NextPair(const char **string, char *key, char *value)
+{
char *o;
const char *s;
*value = *key = 0;
s = *string;
- if( !s ) {
+ if (!s) {
return;
}
- if( *s == '\\' )
+ if (*s == '\\')
s++;
- if( !*s ) {
+ if (!*s) {
*string = NULL;
return;
}
-
+
o = key;
- while( *s && *s != '\\' ) {
+ while (*s && *s != '\\') {
*o++ = *s++;
}
-
+
*o = 0;
- if( !*s ) {
+ if (!*s) {
*string = NULL;
return;
}
o = value;
s++;
- while( *s && *s != '\\' ) {
+ while (*s && *s != '\\') {
*o++ = *s++;
}
*o = 0;
- if( *s ) {
+ if (*s) {
s++;
}
*string = s;
-
+
}
/*
@@ -1206,21 +1236,22 @@ void Info_NextPair( const char **string, char *key, char *value ) {
Info_Print
==================
*/
-void Info_Print( const char *infostring ) {
+void Info_Print(const char *infostring)
+{
char key[MAX_INFO_STRING];
char value[MAX_INFO_STRING];
- while( infostring ) {
- Info_NextPair( &infostring, key, value );
-
- if( !key[0] ) {
+ while (infostring) {
+ Info_NextPair(&infostring, key, value);
+
+ if (!key[0]) {
break;
}
- if( value[0] ) {
- Com_Printf( "%-20s %s\n", key, value );
+ if (value[0]) {
+ Com_Printf("%-20s %s\n", key, value);
} else {
- Com_Printf( "%-20s <MISSING VALUE>\n", key );
+ Com_Printf("%-20s <MISSING VALUE>\n", key);
}
}
}
diff --git a/src/q_shared.h b/src/q_shared.h
index e56cf30..501e9a9 100644
--- a/src/q_shared.h
+++ b/src/q_shared.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
+
// q_shared.h -- included first by ALL program modules
#include <math.h>
@@ -50,7 +50,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef __GNUC__
-#define q_printf( f, a ) __attribute__((format( printf, f, a )))
+#define q_printf(f, a) __attribute__((format(printf, f, a)))
#define q_noreturn __attribute__((noreturn))
#define q_malloc __attribute__((malloc))
#if __GNUC__ >= 4
@@ -59,25 +59,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define q_sentinel
#endif
-#define q_likely( x ) __builtin_expect( !!(x), 1 )
-#define q_unlikely( x ) __builtin_expect( !!(x), 0 )
+#define q_likely(x) __builtin_expect(!!(x), 1)
+#define q_unlikely(x) __builtin_expect(!!(x), 0)
#if __GNUC__ >= 4
-#define q_offsetof( t, m ) __builtin_offsetof( t, m )
+#define q_offsetof(t, m) __builtin_offsetof(t, m)
#else
-#define q_offsetof( t, m ) ((size_t)&((t *)0)->m)
+#define q_offsetof(t, m) ((size_t)&((t *)0)->m)
#endif
#else /* __GNUC__ */
-#define q_printf( f, a )
+#define q_printf(f, a)
#define q_noreturn
#define q_malloc
#define q_sentinel
#define q_packed
-#define q_likely( x ) !!(x)
-#define q_unlikely( x ) !!(x)
-#define q_offsetof( t, m ) ((size_t)&((t *)0)->m)
+#define q_likely(x) !!(x)
+#define q_unlikely(x) !!(x)
+#define q_offsetof(t, m) ((size_t)&((t *)0)->m)
#endif /* !__GNUC__ */
@@ -113,7 +113,7 @@ typedef int qerror_t;
#define MAX_SOUNDS 256 // so they cannot be blindly increased
#define MAX_IMAGES 256
#define MAX_ITEMS 256
-#define MAX_GENERAL (MAX_CLIENTS*2) // general config strings
+#define MAX_GENERAL (MAX_CLIENTS * 2) // general config strings
#define MAX_CLIENT_NAME 16
@@ -126,21 +126,21 @@ typedef enum {
typedef enum {
PRINT_ALL, // general messages
- PRINT_TALK, // print in green color
+ PRINT_TALK, // print in green color
PRINT_DEVELOPER, // only print when "developer 1"
PRINT_WARNING, // print in yellow color
PRINT_ERROR, // print in red color
PRINT_NOTICE // print in cyan color
} print_type_t;
-void Com_LPrintf( print_type_t type, const char *fmt, ... )
- q_printf( 2, 3 );
-void Com_Error( error_type_t code, const char *fmt, ... )
- q_noreturn q_printf( 2, 3 );
+void Com_LPrintf(print_type_t type, const char *fmt, ...)
+q_printf(2, 3);
+void Com_Error(error_type_t code, const char *fmt, ...)
+q_noreturn q_printf(2, 3);
-#define Com_Printf(...) Com_LPrintf( PRINT_ALL, __VA_ARGS__ )
-#define Com_WPrintf(...) Com_LPrintf( PRINT_WARNING, __VA_ARGS__ )
-#define Com_EPrintf(...) Com_LPrintf( PRINT_ERROR, __VA_ARGS__ )
+#define Com_Printf(...) Com_LPrintf(PRINT_ALL, __VA_ARGS__)
+#define Com_WPrintf(...) Com_LPrintf(PRINT_WARNING, __VA_ARGS__)
+#define Com_EPrintf(...) Com_LPrintf(PRINT_ERROR, __VA_ARGS__)
// game print flags
#define PRINT_LOW 0 // pickup messages
@@ -200,7 +200,8 @@ typedef struct vrect_s {
#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
// microsoft's fabs seems to be ungodly slow...
-static inline float Q_fabs( float f ) {
+static inline float Q_fabs(float f)
+{
union {
uint32_t l;
float f;
@@ -211,9 +212,9 @@ static inline float Q_fabs( float f ) {
return tmp.f;
}
-#define Q_ftol( f ) ((long)(f))
+#define Q_ftol(f) ((long)(f))
-#define DEG2RAD( a ) ( a * M_PI ) / 180.0F
+#define DEG2RAD(a) (a * M_PI) / 180.0F
#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
#define CrossProduct(v1,v2,cross) \
@@ -287,29 +288,31 @@ static inline float Q_fabs( float f ) {
#define Vector4Negate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2],(b)[3]=-(a)[3])
#define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3]=(d))
-void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
-vec_t VectorNormalize (vec3_t v); // returns vector length
-vec_t VectorNormalize2 (vec3_t v, vec3_t out);
-void ClearBounds (vec3_t mins, vec3_t maxs);
-void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs);
-vec_t RadiusFromBounds (const vec3_t mins, const vec3_t maxs);
-void UnionBounds( vec3_t a[2], vec3_t b[2], vec3_t c[2] );
+void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
+vec_t VectorNormalize(vec3_t v); // returns vector length
+vec_t VectorNormalize2(vec3_t v, vec3_t out);
+void ClearBounds(vec3_t mins, vec3_t maxs);
+void AddPointToBounds(const vec3_t v, vec3_t mins, vec3_t maxs);
+vec_t RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
+void UnionBounds(vec3_t a[2], vec3_t b[2], vec3_t c[2]);
-static inline unsigned npot32( unsigned k ) {
- if( k == 0 )
+static inline unsigned npot32(unsigned k)
+{
+ if (k == 0)
return 1;
k--;
- k = k | ( k >> 1 );
- k = k | ( k >> 2 );
- k = k | ( k >> 4 );
- k = k | ( k >> 8 );
- k = k | ( k >> 16 );
+ k = k | (k >> 1);
+ k = k | (k >> 2);
+ k = k | (k >> 4);
+ k = k | (k >> 8);
+ k = k | (k >> 16);
return k + 1;
}
-static inline float LerpAngle( float a2, float a1, float frac ) {
+static inline float LerpAngle(float a2, float a1, float frac)
+{
if (a1 - a2 > 180)
a1 -= 360;
if (a1 - a2 < -180)
@@ -317,29 +320,33 @@ static inline float LerpAngle( float a2, float a1, float frac ) {
return a2 + frac * (a1 - a2);
}
-static inline float anglemod( float a ) {
- a = (360.0f/65536) * ((int)(a*(65536/360.0f)) & 65535);
+static inline float anglemod(float a)
+{
+ a = (360.0f / 65536) * ((int)(a * (65536 / 360.0f)) & 65535);
return a;
}
-static inline int rand_byte( void ) {
+static inline int rand_byte(void)
+{
int r = rand();
- int b1 = ( r >> 24 ) & 255;
- int b2 = ( r >> 16 ) & 255;
- int b3 = ( r >> 8 ) & 255;
- int b4 = ( r ) & 255;
+ int b1 = (r >> 24) & 255;
+ int b2 = (r >> 16) & 255;
+ int b3 = (r >> 8) & 255;
+ int b4 = (r) & 255;
return b1 ^ b2 ^ b3 ^ b4;
}
-static inline int Q_align( int value, int align ) {
+static inline int Q_align(int value, int align)
+{
int mod = value % align;
return mod ? value + align - mod : value;
}
-static inline int Q_gcd( int a, int b ) {
- while( b != 0 ) {
+static inline int Q_gcd(int a, int b)
+{
+ while (b != 0) {
int t = b;
b = a % b;
a = t;
@@ -348,8 +355,8 @@ static inline int Q_gcd( int a, int b ) {
}
#define clamp(a,b,c) ((a)<(b)?(a)=(b):(a)>(c)?(a)=(c):(a))
-#define cclamp(a,b,c) ((b)>(c)?clamp(a,c,b):clamp(a,b,c))
-
+#define cclamp(a,b,c) ((b)>(c)?clamp(a,c,b):clamp(a,b,c))
+
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
@@ -358,94 +365,100 @@ static inline int Q_gcd( int a, int b ) {
#define min(a,b) ((a)<(b)?(a):(b))
#endif
-#define frand() ( ( rand() & 32767 ) * ( 1.0 / 32767 ) )
-#define crand() ( ( rand() & 32767 ) * ( 2.0 / 32767 ) - 1 )
+#define frand() ((rand() & 32767) * (1.0 / 32767))
+#define crand() ((rand() & 32767) * (2.0 / 32767) - 1)
#define Q_rint(x) ((x) < 0 ? ((int)((x) - 0.5f)) : ((int)((x) + 0.5f)))
-#define Q_IsBitSet( data, bit ) ( ( (data)[(bit) >> 3] & ( 1 << ( (bit) & 7 ) ) ) != 0 )
-#define Q_SetBit( data, bit ) ( (data)[(bit) >> 3] |= ( 1 << ( (bit) & 7 ) ) )
-#define Q_ClearBit( data, bit ) ( (data)[(bit) >> 3] &= ~( 1 << ( (bit) & 7 ) ) )
+#define Q_IsBitSet(data, bit) (((data)[(bit) >> 3] & (1 << ((bit) & 7))) != 0)
+#define Q_SetBit(data, bit) ((data)[(bit) >> 3] |= (1 << ((bit) & 7)))
+#define Q_ClearBit(data, bit) ((data)[(bit) >> 3] &= ~(1 << ((bit) & 7)))
//=============================================
// fast "C" macros
-#define Q_isupper( c ) ( (c) >= 'A' && (c) <= 'Z' )
-#define Q_islower( c ) ( (c) >= 'a' && (c) <= 'z' )
-#define Q_isdigit( c ) ( (c) >= '0' && (c) <= '9' )
-#define Q_isalpha( c ) ( Q_isupper( c ) || Q_islower( c ) )
-#define Q_isalnum( c ) ( Q_isalpha( c ) || Q_isdigit( c ) )
-#define Q_isprint( c ) ( (c) >= 32 && (c) < 127 )
-#define Q_isgraph( c ) ( (c) > 32 && (c) < 127 )
-#define Q_isspace( c ) ( c == ' ' || c == '\f' || c == '\n' || \
- c == '\r' || c == '\t' || c == '\v' )
+#define Q_isupper(c) ((c) >= 'A' && (c) <= 'Z')
+#define Q_islower(c) ((c) >= 'a' && (c) <= 'z')
+#define Q_isdigit(c) ((c) >= '0' && (c) <= '9')
+#define Q_isalpha(c) (Q_isupper(c) || Q_islower(c))
+#define Q_isalnum(c) (Q_isalpha(c) || Q_isdigit(c))
+#define Q_isprint(c) ((c) >= 32 && (c) < 127)
+#define Q_isgraph(c) ((c) > 32 && (c) < 127)
+#define Q_isspace(c) (c == ' ' || c == '\f' || c == '\n' || \
+ c == '\r' || c == '\t' || c == '\v')
// tests if specified character is valid quake path character
-#define Q_ispath( c ) ( Q_isalnum( c ) || (c) == '_' || (c) == '-' )
+#define Q_ispath(c) (Q_isalnum(c) || (c) == '_' || (c) == '-')
// tests if specified character has special meaning to quake console
-#define Q_isspecial( c ) ( (c) == '\r' || (c) == '\n' || (c) == 127 )
+#define Q_isspecial(c) ((c) == '\r' || (c) == '\n' || (c) == 127)
-static inline int Q_tolower( int c ) {
- if( Q_isupper( c ) ) {
- c += ( 'a' - 'A' );
+static inline int Q_tolower(int c)
+{
+ if (Q_isupper(c)) {
+ c += ('a' - 'A');
}
return c;
}
-static inline int Q_toupper( int c ) {
- if( Q_islower( c ) ) {
- c -= ( 'a' - 'A' );
+static inline int Q_toupper(int c)
+{
+ if (Q_islower(c)) {
+ c -= ('a' - 'A');
}
return c;
}
-static inline char *Q_strlwr( char *s ) {
+static inline char *Q_strlwr(char *s)
+{
char *p = s;
- while( *p ) {
- *p = Q_tolower( *p );
+ while (*p) {
+ *p = Q_tolower(*p);
p++;
}
return s;
}
-static inline char *Q_strupr( char *s ) {
+static inline char *Q_strupr(char *s)
+{
char *p = s;
- while( *p ) {
- *p = Q_toupper( *p );
+ while (*p) {
+ *p = Q_toupper(*p);
p++;
}
return s;
}
-static inline int Q_charhex( int c ) {
- if( c >= 'A' && c <= 'F' ) {
- return 10 + ( c - 'A' );
+static inline int Q_charhex(int c)
+{
+ if (c >= 'A' && c <= 'F') {
+ return 10 + (c - 'A');
}
- if( c >= 'a' && c <= 'f' ) {
- return 10 + ( c - 'a' );
+ if (c >= 'a' && c <= 'f') {
+ return 10 + (c - 'a');
}
- if( c >= '0' && c <= '9' ) {
+ if (c >= '0' && c <= '9') {
return c - '0';
}
return -1;
}
// converts quake char to ASCII equivalent
-static inline int Q_charascii( int c ) {
- if( Q_isspace( c ) ) {
+static inline int Q_charascii(int c)
+{
+ if (Q_isspace(c)) {
// white-space chars are output as-is
return c;
}
c &= 127; // strip high bits
- if( Q_isprint( c ) ) {
+ if (Q_isprint(c)) {
return c;
}
- switch( c ) {
+ switch (c) {
// handle bold brackets
case 16: return '[';
case 17: return ']';
@@ -454,84 +467,87 @@ static inline int Q_charascii( int c ) {
}
// portable case insensitive compare
-int Q_strcasecmp( const char *s1, const char *s2 );
-int Q_strncasecmp( const char *s1, const char *s2, size_t n );
-char *Q_strcasestr( const char *s1, const char *s2 );
+int Q_strcasecmp(const char *s1, const char *s2);
+int Q_strncasecmp(const char *s1, const char *s2, size_t n);
+char *Q_strcasestr(const char *s1, const char *s2);
#define Q_stricmp Q_strcasecmp
#define Q_stricmpn Q_strncasecmp
#define Q_stristr Q_strcasestr
#ifdef _WIN32
-#define Q_mkdir( p ) _mkdir( p )
-#define Q_unlink( p ) _unlink( p )
+#define Q_mkdir(p) _mkdir(p)
+#define Q_unlink(p) _unlink(p)
#else
-#define Q_mkdir( p ) mkdir( p, 0775 )
-#define Q_unlink( p ) unlink( p )
+#define Q_mkdir(p) mkdir(p, 0775)
+#define Q_unlink(p) unlink(p)
#endif
-char *Q_strchrnul( const char *s, int c );
-void *Q_memccpy( void *dst, const void *src, int c, size_t size );
-void Q_setenv( const char *name, const char *value );
+char *Q_strchrnul(const char *s, int c);
+void *Q_memccpy(void *dst, const void *src, int c, size_t size);
+void Q_setenv(const char *name, const char *value);
-char *COM_SkipPath( const char *pathname );
-void COM_StripExtension( const char *in, char *out, size_t size );
-void COM_FileBase (char *in, char *out);
-void COM_FilePath( const char *in, char *out, size_t size );
-size_t COM_DefaultExtension( char *path, const char *ext, size_t size );
-char *COM_FileExtension( const char *in );
+char *COM_SkipPath(const char *pathname);
+void COM_StripExtension(const char *in, char *out, size_t size);
+void COM_FileBase(char *in, char *out);
+void COM_FilePath(const char *in, char *out, size_t size);
+size_t COM_DefaultExtension(char *path, const char *ext, size_t size);
+char *COM_FileExtension(const char *in);
-#define COM_CompareExtension( in, ext ) \
- Q_strcasecmp( COM_FileExtension( in ), ext )
+#define COM_CompareExtension(in, ext) \
+ Q_strcasecmp(COM_FileExtension(in), ext)
-qboolean COM_IsFloat( const char *s );
-qboolean COM_IsUint( const char *s );
-qboolean COM_IsPath( const char *s );
-qboolean COM_IsWhite( const char *s );
+qboolean COM_IsFloat(const char *s);
+qboolean COM_IsUint(const char *s);
+qboolean COM_IsPath(const char *s);
+qboolean COM_IsWhite(const char *s);
-char *COM_Parse( const char **data_p );
+char *COM_Parse(const char **data_p);
// data is an in/out parm, returns a parsed out token
-int COM_Compress( char *data );
+int COM_Compress(char *data);
-int QDECL SortStrcmp( const void *p1, const void *p2 );
-int QDECL SortStricmp( const void *p1, const void *p2 );
+int QDECL SortStrcmp(const void *p1, const void *p2);
+int QDECL SortStricmp(const void *p1, const void *p2);
-size_t COM_strclr( char *s );
+size_t COM_strclr(char *s);
// buffer safe operations
-size_t Q_strlcpy( char *dst, const char *src, size_t size );
-size_t Q_strlcat( char *dst, const char *src, size_t size );
+size_t Q_strlcpy(char *dst, const char *src, size_t size);
+size_t Q_strlcat(char *dst, const char *src, size_t size);
-size_t Q_concat( char *dest, size_t size, ... ) q_sentinel;
+size_t Q_concat(char *dest, size_t size, ...) q_sentinel;
-size_t Q_vsnprintf( char *dest, size_t size, const char *fmt, va_list argptr );
-size_t Q_vscnprintf( char *dest, size_t size, const char *fmt, va_list argptr );
-size_t Q_snprintf( char *dest, size_t size, const char *fmt, ... ) q_printf( 3, 4 );
-size_t Q_scnprintf( char *dest, size_t size, const char *fmt, ... ) q_printf( 3, 4 );
+size_t Q_vsnprintf(char *dest, size_t size, const char *fmt, va_list argptr);
+size_t Q_vscnprintf(char *dest, size_t size, const char *fmt, va_list argptr);
+size_t Q_snprintf(char *dest, size_t size, const char *fmt, ...) q_printf(3, 4);
+size_t Q_scnprintf(char *dest, size_t size, const char *fmt, ...) q_printf(3, 4);
-char *va( const char *format, ... ) q_printf( 1, 2 );
+char *va(const char *format, ...) q_printf(1, 2);
//=============================================
-static inline uint16_t ShortSwap( uint16_t s ) {
- s = ( s >> 8 ) | ( s << 8 );
+static inline uint16_t ShortSwap(uint16_t s)
+{
+ s = (s >> 8) | (s << 8);
return s;
}
-static inline uint32_t LongSwap( uint32_t l ) {
- l = ( ( l >> 8 ) & 0x00ff00ff ) | ( ( l << 8 ) & 0xff00ff00 );
- l = ( l >> 16 ) | ( l << 16 );
+static inline uint32_t LongSwap(uint32_t l)
+{
+ l = ((l >> 8) & 0x00ff00ff) | ((l << 8) & 0xff00ff00);
+ l = (l >> 16) | (l << 16);
return l;
}
-static inline float FloatSwap( float f ) {
+static inline float FloatSwap(float f)
+{
union {
float f;
uint32_t l;
} dat1, dat2;
-
+
dat1.f = f;
- dat2.l = LongSwap( dat1.l );
+ dat2.l = LongSwap(dat1.l);
return dat2.f;
}
@@ -569,9 +585,9 @@ static inline float FloatSwap( float f ) {
(b)[2]=LittleFloat((a)[2]))
#if USE_BGRA
-#define MakeColor( r, g, b, a ) MakeRawLong( b, g, r, a )
+#define MakeColor(r, g, b, a) MakeRawLong(b, g, r, a)
#else
-#define MakeColor( r, g, b, a ) MakeRawLong( r, g, b, a )
+#define MakeColor(r, g, b, a) MakeRawLong(r, g, b, a)
#endif
//=============================================
@@ -583,13 +599,13 @@ static inline float FloatSwap( float f ) {
#define MAX_INFO_VALUE 64
#define MAX_INFO_STRING 512
-char *Info_ValueForKey( const char *s, const char *key );
-void Info_RemoveKey( char *s, const char *key );
-qboolean Info_SetValueForKey( char *s, const char *key, const char *value );
-qboolean Info_Validate( const char *s );
-size_t Info_SubValidate( const char *s );
-void Info_NextPair( const char **string, char *key, char *value );
-void Info_Print( const char *infostring );
+char *Info_ValueForKey(const char *s, const char *key);
+void Info_RemoveKey(char *s, const char *key);
+qboolean Info_SetValueForKey(char *s, const char *key, const char *value);
+qboolean Info_Validate(const char *s);
+size_t Info_SubValidate(const char *s);
+void Info_NextPair(const char **string, char *key, char *value);
+void Info_Print(const char *infostring);
/*
==========================================================
@@ -606,14 +622,14 @@ CVARS (console variables)
#define CVAR_USERINFO 2 // added to userinfo when changed
#define CVAR_SERVERINFO 4 // added to serverinfo when changed
#define CVAR_NOSET 8 // don't allow change from console at all,
- // but can be set from the command line
+// but can be set from the command line
#define CVAR_LATCH 16 // save changes until server restart
struct cvar_s;
struct genctx_s;
-typedef void (*xchanged_t)( struct cvar_s * );
-typedef void (*xgenerator_t)( struct genctx_s * );
+typedef void (*xchanged_t)(struct cvar_s *);
+typedef void (*xgenerator_t)(struct genctx_s *);
// nothing outside the cvar.*() functions should modify these fields!
typedef struct cvar_s {
@@ -711,8 +727,7 @@ COLLISION DETECTION
// plane_t structure
// !!! if this is changed, it must be changed in asm code too !!!
-typedef struct cplane_s
-{
+typedef struct cplane_s {
vec3_t normal;
float dist;
byte type; // for fast side tests
@@ -744,16 +759,14 @@ typedef struct cplane_s
#define CPLANE_PAD0 18
#define CPLANE_PAD1 19
-typedef struct csurface_s
-{
+typedef struct csurface_s {
char name[16];
int flags;
int value;
} csurface_t;
// a trace is returned when a box is swept through the world
-typedef struct
-{
+typedef struct {
qboolean allsolid; // if qtrue, plane is not valid
qboolean startsolid; // if qtrue, the initial point was in a solid area
float fraction; // time completed, 1.0 = didn't hit anything
@@ -766,8 +779,7 @@ typedef struct
// pmove_state_t is the information necessary for client side movement
// prediction
-typedef enum
-{
+typedef enum {
// can accelerate and turn
PM_NORMAL,
PM_SPECTATOR,
@@ -792,8 +804,7 @@ typedef enum
// prediction stays in sync, so no floats are used.
// if any part of the game code modifies this struct, it
// will result in a prediction error of some degree.
-typedef struct
-{
+typedef struct {
pmtype_t pm_type;
short origin[3]; // 12.3
@@ -802,7 +813,7 @@ typedef struct
byte pm_time; // each unit = 8 ms
short gravity;
short delta_angles[3]; // add to command angles to get view direction
- // changed by spawns, rotating objects, and teleporters
+ // changed by spawns, rotating objects, and teleporters
} pmove_state_t;
@@ -815,8 +826,7 @@ typedef struct
// usercmd_t is sent to the server each client frame
-typedef struct usercmd_s
-{
+typedef struct usercmd_s {
byte msec;
byte buttons;
short angles[3];
@@ -827,8 +837,7 @@ typedef struct usercmd_s
#define MAXTOUCH 32
-typedef struct
-{
+typedef struct {
// state (in / out)
pmove_state_t s;
@@ -850,8 +859,8 @@ typedef struct
int waterlevel;
// callbacks to test the world
- trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
- int (*pointcontents) (vec3_t point);
+ trace_t (*trace)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
+ int (*pointcontents)(vec3_t point);
} pmove_t;
@@ -1207,8 +1216,7 @@ extern const vec3_t monster_flash_offset [];
// at a location seperate from any existing entity.
// Temporary entity messages are explicitly constructed
// and broadcast.
-typedef enum
-{
+typedef enum {
TE_GUNSHOT,
TE_BLOOD,
TE_BLASTER,
@@ -1439,9 +1447,9 @@ ROGUE - VERSIONS
#define MAX_CONFIGSTRINGS (CS_GENERAL+MAX_GENERAL)
// Some mods actually exploit CS_STATUSBAR to take space up to CS_AIRACCEL
-#define CS_SIZE( cs ) \
- ( (cs) >= CS_STATUSBAR && (cs) < CS_AIRACCEL ? \
- MAX_QPATH * ( CS_AIRACCEL - (cs) ) : MAX_QPATH )
+#define CS_SIZE(cs) \
+ ((cs) >= CS_STATUSBAR && (cs) < CS_AIRACCEL ? \
+ MAX_QPATH * (CS_AIRACCEL - (cs)) : MAX_QPATH)
//==============================================
@@ -1451,8 +1459,7 @@ ROGUE - VERSIONS
// ertity events are for effects that take place reletive
// to an existing entities origin. Very network efficient.
// All muzzle flashes really should be converted to events...
-typedef enum
-{
+typedef enum {
EV_NONE,
EV_ITEM_RESPAWN,
EV_FOOTSTEP,
@@ -1467,8 +1474,7 @@ typedef enum
// entity_state_t is the information conveyed from the server
// in an update message about entities that the client will
// need to render in some way
-typedef struct entity_state_s
-{
+typedef struct entity_state_s {
int number; // edict index
vec3_t origin;
@@ -1496,8 +1502,7 @@ typedef struct entity_state_s
// to rendered a view. There will only be 10 player_state_t sent each second,
// but the number of pmove_state_t changes will be reletive to client
// frame rates
-typedef struct
-{
+typedef struct {
pmove_state_t pmove; // for prediction
// these fields do not need to be communicated bit-precise
@@ -1513,7 +1518,7 @@ typedef struct
int gunframe;
float blend[4]; // rgba full screen effect
-
+
float fov; // horizontal field of view
int rdflags; // refdef flags
diff --git a/src/qal_api.c b/src/qal_api.c
index 7ef77fe..b881db6 100644
--- a/src/qal_api.c
+++ b/src/qal_api.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,26 +24,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <AL/alc.h>
#define QALC_IMP \
- QAL( LPALCCREATECONTEXT, alcCreateContext ); \
- QAL( LPALCMAKECONTEXTCURRENT, alcMakeContextCurrent ); \
- QAL( LPALCPROCESSCONTEXT, alcProcessContext ); \
- QAL( LPALCSUSPENDCONTEXT, alcSuspendContext ); \
- QAL( LPALCDESTROYCONTEXT, alcDestroyContext ); \
- QAL( LPALCGETCURRENTCONTEXT, alcGetCurrentContext ); \
- QAL( LPALCGETCONTEXTSDEVICE, alcGetContextsDevice ); \
- QAL( LPALCOPENDEVICE, alcOpenDevice ); \
- QAL( LPALCCLOSEDEVICE, alcCloseDevice ); \
- QAL( LPALCGETERROR, alcGetError ); \
- QAL( LPALCISEXTENSIONPRESENT, alcIsExtensionPresent ); \
- QAL( LPALCGETPROCADDRESS, alcGetProcAddress ); \
- QAL( LPALCGETENUMVALUE, alcGetEnumValue ); \
- QAL( LPALCGETSTRING, alcGetString ); \
- QAL( LPALCGETINTEGERV, alcGetIntegerv ); \
- QAL( LPALCCAPTUREOPENDEVICE, alcCaptureOpenDevice ); \
- QAL( LPALCCAPTURECLOSEDEVICE, alcCaptureCloseDevice ); \
- QAL( LPALCCAPTURESTART, alcCaptureStart ); \
- QAL( LPALCCAPTURESTOP, alcCaptureStop ); \
- QAL( LPALCCAPTURESAMPLES, alcCaptureSamples );
+ QAL(LPALCCREATECONTEXT, alcCreateContext); \
+ QAL(LPALCMAKECONTEXTCURRENT, alcMakeContextCurrent); \
+ QAL(LPALCPROCESSCONTEXT, alcProcessContext); \
+ QAL(LPALCSUSPENDCONTEXT, alcSuspendContext); \
+ QAL(LPALCDESTROYCONTEXT, alcDestroyContext); \
+ QAL(LPALCGETCURRENTCONTEXT, alcGetCurrentContext); \
+ QAL(LPALCGETCONTEXTSDEVICE, alcGetContextsDevice); \
+ QAL(LPALCOPENDEVICE, alcOpenDevice); \
+ QAL(LPALCCLOSEDEVICE, alcCloseDevice); \
+ QAL(LPALCGETERROR, alcGetError); \
+ QAL(LPALCISEXTENSIONPRESENT, alcIsExtensionPresent); \
+ QAL(LPALCGETPROCADDRESS, alcGetProcAddress); \
+ QAL(LPALCGETENUMVALUE, alcGetEnumValue); \
+ QAL(LPALCGETSTRING, alcGetString); \
+ QAL(LPALCGETINTEGERV, alcGetIntegerv); \
+ QAL(LPALCCAPTUREOPENDEVICE, alcCaptureOpenDevice); \
+ QAL(LPALCCAPTURECLOSEDEVICE, alcCaptureCloseDevice); \
+ QAL(LPALCCAPTURESTART, alcCaptureStart); \
+ QAL(LPALCCAPTURESTOP, alcCaptureStop); \
+ QAL(LPALCCAPTURESAMPLES, alcCaptureSamples);
static cvar_t *al_driver;
static cvar_t *al_device;
@@ -60,62 +60,64 @@ QALC_IMP
QAL_IMP
#undef QAL
-void QAL_Shutdown( void ) {
- if( context ) {
- qalcMakeContextCurrent( NULL );
- qalcDestroyContext( context );
+void QAL_Shutdown(void)
+{
+ if (context) {
+ qalcMakeContextCurrent(NULL);
+ qalcDestroyContext(context);
context = NULL;
}
- if( device ) {
- qalcCloseDevice( device );
+ if (device) {
+ qalcCloseDevice(device);
device = NULL;
}
#define QAL(type,func) q##func = NULL;
-QALC_IMP
-QAL_IMP
+ QALC_IMP
+ QAL_IMP
#undef QAL
- Sys_FreeLibrary( handle );
+ Sys_FreeLibrary(handle);
handle = NULL;
al_driver->flags &= ~CVAR_SOUND;
al_device->flags &= ~CVAR_SOUND;
}
-qboolean QAL_Init( void ) {
- al_driver = Cvar_Get( "al_driver", DEFAULT_OPENAL_DRIVER, CVAR_SOUND );
- al_device = Cvar_Get( "al_device", "", CVAR_SOUND );
+qboolean QAL_Init(void)
+{
+ al_driver = Cvar_Get("al_driver", DEFAULT_OPENAL_DRIVER, CVAR_SOUND);
+ al_device = Cvar_Get("al_device", "", CVAR_SOUND);
- Sys_LoadLibrary( al_driver->string, NULL, &handle );
- if( !handle ) {
+ Sys_LoadLibrary(al_driver->string, NULL, &handle);
+ if (!handle) {
return qfalse;
}
-#define QAL(type,func) q##func = Sys_GetProcAddress( handle, #func );
-QALC_IMP
-QAL_IMP
+#define QAL(type, func) q##func = Sys_GetProcAddress(handle, #func);
+ QALC_IMP
+ QAL_IMP
#undef QAL
- Com_DPrintf( "...opening OpenAL device: " );
- device = qalcOpenDevice( al_device->string[0] ? al_device->string : NULL );
- if( !device ) {
+ Com_DPrintf("...opening OpenAL device: ");
+ device = qalcOpenDevice(al_device->string[0] ? al_device->string : NULL);
+ if (!device) {
goto fail;
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
- Com_DPrintf( "...creating OpenAL context: " );
- context = qalcCreateContext( device, NULL );
- if( !context ) {
+ Com_DPrintf("...creating OpenAL context: ");
+ context = qalcCreateContext(device, NULL);
+ if (!context) {
goto fail;
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
- Com_DPrintf( "...making context current: " );
- if( !qalcMakeContextCurrent( context ) ) {
+ Com_DPrintf("...making context current: ");
+ if (!qalcMakeContextCurrent(context)) {
goto fail;
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
al_driver->flags |= CVAR_SOUND;
al_device->flags |= CVAR_SOUND;
@@ -123,7 +125,7 @@ QAL_IMP
return qtrue;
fail:
- Com_DPrintf( "failed\n" );
+ Com_DPrintf("failed\n");
QAL_Shutdown();
return qfalse;
}
diff --git a/src/qal_api.h b/src/qal_api.h
index 4a1896e..d26e0a8 100644
--- a/src/qal_api.h
+++ b/src/qal_api.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,84 +22,84 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <AL/al.h>
#define QAL_IMP \
- QAL( LPALENABLE, alEnable ); \
- QAL( LPALDISABLE, alDisable ); \
- QAL( LPALISENABLED, alIsEnabled ); \
- QAL( LPALGETSTRING, alGetString ); \
- QAL( LPALGETBOOLEANV, alGetBooleanv ); \
- QAL( LPALGETINTEGERV, alGetIntegerv ); \
- QAL( LPALGETFLOATV, alGetFloatv ); \
- QAL( LPALGETDOUBLEV, alGetDoublev ); \
- QAL( LPALGETBOOLEAN, alGetBoolean ); \
- QAL( LPALGETINTEGER, alGetInteger ); \
- QAL( LPALGETFLOAT, alGetFloat ); \
- QAL( LPALGETDOUBLE, alGetDouble ); \
- QAL( LPALGETERROR, alGetError ); \
- QAL( LPALISEXTENSIONPRESENT, alIsExtensionPresent ); \
- QAL( LPALGETPROCADDRESS, alGetProcAddress ); \
- QAL( LPALGETENUMVALUE, alGetEnumValue ); \
- QAL( LPALLISTENERF, alListenerf ); \
- QAL( LPALLISTENER3F, alListener3f ); \
- QAL( LPALLISTENERFV, alListenerfv ); \
- QAL( LPALLISTENERI, alListeneri ); \
- QAL( LPALLISTENER3I, alListener3i ); \
- QAL( LPALLISTENERIV, alListeneriv ); \
- QAL( LPALGETLISTENERF, alGetListenerf ); \
- QAL( LPALGETLISTENER3F, alGetListener3f ); \
- QAL( LPALGETLISTENERFV, alGetListenerfv ); \
- QAL( LPALGETLISTENERI, alGetListeneri ); \
- QAL( LPALGETLISTENER3I, alGetListener3i ); \
- QAL( LPALGETLISTENERIV, alGetListeneriv ); \
- QAL( LPALGENSOURCES, alGenSources ); \
- QAL( LPALDELETESOURCES, alDeleteSources ); \
- QAL( LPALISSOURCE, alIsSource ); \
- QAL( LPALSOURCEF, alSourcef ); \
- QAL( LPALSOURCE3F, alSource3f ); \
- QAL( LPALSOURCEFV, alSourcefv ); \
- QAL( LPALSOURCEI, alSourcei ); \
- QAL( LPALSOURCE3I, alSource3i ); \
- QAL( LPALSOURCEIV, alSourceiv ); \
- QAL( LPALGETSOURCEF, alGetSourcef ); \
- QAL( LPALGETSOURCE3F, alGetSource3f ); \
- QAL( LPALGETSOURCEFV, alGetSourcefv ); \
- QAL( LPALGETSOURCEI, alGetSourcei ); \
- QAL( LPALGETSOURCE3I, alGetSource3i ); \
- QAL( LPALGETSOURCEIV, alGetSourceiv ); \
- QAL( LPALSOURCEPLAYV, alSourcePlayv ); \
- QAL( LPALSOURCESTOPV, alSourceStopv ); \
- QAL( LPALSOURCEREWINDV, alSourceRewindv ); \
- QAL( LPALSOURCEPAUSEV, alSourcePausev ); \
- QAL( LPALSOURCEPLAY, alSourcePlay ); \
- QAL( LPALSOURCESTOP, alSourceStop ); \
- QAL( LPALSOURCEREWIND, alSourceRewind ); \
- QAL( LPALSOURCEPAUSE, alSourcePause ); \
- QAL( LPALSOURCEQUEUEBUFFERS, alSourceQueueBuffers ); \
- QAL( LPALSOURCEUNQUEUEBUFFERS, alSourceUnqueueBuffers ); \
- QAL( LPALGENBUFFERS, alGenBuffers ); \
- QAL( LPALDELETEBUFFERS, alDeleteBuffers ); \
- QAL( LPALISBUFFER, alIsBuffer ); \
- QAL( LPALBUFFERDATA, alBufferData ); \
- QAL( LPALBUFFERF, alBufferf ); \
- QAL( LPALBUFFER3F, alBuffer3f ); \
- QAL( LPALBUFFERFV, alBufferfv ); \
- QAL( LPALBUFFERI, alBufferi ); \
- QAL( LPALBUFFER3I, alBuffer3i ); \
- QAL( LPALBUFFERIV, alBufferiv ); \
- QAL( LPALGETBUFFERF, alGetBufferf ); \
- QAL( LPALGETBUFFER3F, alGetBuffer3f ); \
- QAL( LPALGETBUFFERFV, alGetBufferfv ); \
- QAL( LPALGETBUFFERI, alGetBufferi ); \
- QAL( LPALGETBUFFER3I, alGetBuffer3i ); \
- QAL( LPALGETBUFFERIV, alGetBufferiv ); \
- QAL( LPALDOPPLERFACTOR, alDopplerFactor ); \
- QAL( LPALDOPPLERVELOCITY, alDopplerVelocity ); \
- QAL( LPALSPEEDOFSOUND, alSpeedOfSound ); \
- QAL( LPALDISTANCEMODEL, alDistanceModel );
+ QAL(LPALENABLE, alEnable); \
+ QAL(LPALDISABLE, alDisable); \
+ QAL(LPALISENABLED, alIsEnabled); \
+ QAL(LPALGETSTRING, alGetString); \
+ QAL(LPALGETBOOLEANV, alGetBooleanv); \
+ QAL(LPALGETINTEGERV, alGetIntegerv); \
+ QAL(LPALGETFLOATV, alGetFloatv); \
+ QAL(LPALGETDOUBLEV, alGetDoublev); \
+ QAL(LPALGETBOOLEAN, alGetBoolean); \
+ QAL(LPALGETINTEGER, alGetInteger); \
+ QAL(LPALGETFLOAT, alGetFloat); \
+ QAL(LPALGETDOUBLE, alGetDouble); \
+ QAL(LPALGETERROR, alGetError); \
+ QAL(LPALISEXTENSIONPRESENT, alIsExtensionPresent); \
+ QAL(LPALGETPROCADDRESS, alGetProcAddress); \
+ QAL(LPALGETENUMVALUE, alGetEnumValue); \
+ QAL(LPALLISTENERF, alListenerf); \
+ QAL(LPALLISTENER3F, alListener3f); \
+ QAL(LPALLISTENERFV, alListenerfv); \
+ QAL(LPALLISTENERI, alListeneri); \
+ QAL(LPALLISTENER3I, alListener3i); \
+ QAL(LPALLISTENERIV, alListeneriv); \
+ QAL(LPALGETLISTENERF, alGetListenerf); \
+ QAL(LPALGETLISTENER3F, alGetListener3f); \
+ QAL(LPALGETLISTENERFV, alGetListenerfv); \
+ QAL(LPALGETLISTENERI, alGetListeneri); \
+ QAL(LPALGETLISTENER3I, alGetListener3i); \
+ QAL(LPALGETLISTENERIV, alGetListeneriv); \
+ QAL(LPALGENSOURCES, alGenSources); \
+ QAL(LPALDELETESOURCES, alDeleteSources); \
+ QAL(LPALISSOURCE, alIsSource); \
+ QAL(LPALSOURCEF, alSourcef); \
+ QAL(LPALSOURCE3F, alSource3f); \
+ QAL(LPALSOURCEFV, alSourcefv); \
+ QAL(LPALSOURCEI, alSourcei); \
+ QAL(LPALSOURCE3I, alSource3i); \
+ QAL(LPALSOURCEIV, alSourceiv); \
+ QAL(LPALGETSOURCEF, alGetSourcef); \
+ QAL(LPALGETSOURCE3F, alGetSource3f); \
+ QAL(LPALGETSOURCEFV, alGetSourcefv); \
+ QAL(LPALGETSOURCEI, alGetSourcei); \
+ QAL(LPALGETSOURCE3I, alGetSource3i); \
+ QAL(LPALGETSOURCEIV, alGetSourceiv); \
+ QAL(LPALSOURCEPLAYV, alSourcePlayv); \
+ QAL(LPALSOURCESTOPV, alSourceStopv); \
+ QAL(LPALSOURCEREWINDV, alSourceRewindv); \
+ QAL(LPALSOURCEPAUSEV, alSourcePausev); \
+ QAL(LPALSOURCEPLAY, alSourcePlay); \
+ QAL(LPALSOURCESTOP, alSourceStop); \
+ QAL(LPALSOURCEREWIND, alSourceRewind); \
+ QAL(LPALSOURCEPAUSE, alSourcePause); \
+ QAL(LPALSOURCEQUEUEBUFFERS, alSourceQueueBuffers); \
+ QAL(LPALSOURCEUNQUEUEBUFFERS, alSourceUnqueueBuffers); \
+ QAL(LPALGENBUFFERS, alGenBuffers); \
+ QAL(LPALDELETEBUFFERS, alDeleteBuffers); \
+ QAL(LPALISBUFFER, alIsBuffer); \
+ QAL(LPALBUFFERDATA, alBufferData); \
+ QAL(LPALBUFFERF, alBufferf); \
+ QAL(LPALBUFFER3F, alBuffer3f); \
+ QAL(LPALBUFFERFV, alBufferfv); \
+ QAL(LPALBUFFERI, alBufferi); \
+ QAL(LPALBUFFER3I, alBuffer3i); \
+ QAL(LPALBUFFERIV, alBufferiv); \
+ QAL(LPALGETBUFFERF, alGetBufferf); \
+ QAL(LPALGETBUFFER3F, alGetBuffer3f); \
+ QAL(LPALGETBUFFERFV, alGetBufferfv); \
+ QAL(LPALGETBUFFERI, alGetBufferi); \
+ QAL(LPALGETBUFFER3I, alGetBuffer3i); \
+ QAL(LPALGETBUFFERIV, alGetBufferiv); \
+ QAL(LPALDOPPLERFACTOR, alDopplerFactor); \
+ QAL(LPALDOPPLERVELOCITY, alDopplerVelocity); \
+ QAL(LPALSPEEDOFSOUND, alSpeedOfSound); \
+ QAL(LPALDISTANCEMODEL, alDistanceModel);
#define QAL(type,func) extern type q##func;
QAL_IMP
#undef QAL
-qboolean QAL_Init( void );
-void QAL_Shutdown( void );
+qboolean QAL_Init(void);
+void QAL_Shutdown(void);
diff --git a/src/qgl_api.c b/src/qgl_api.c
index 359d956..c179ea5 100644
--- a/src/qgl_api.c
+++ b/src/qgl_api.c
@@ -35,99 +35,99 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static FILE *log_fp;
-void ( APIENTRY * qglAlphaFunc )(GLenum func, GLclampf ref);
-void ( APIENTRY * qglBindTexture )(GLenum target, GLuint texture);
-void ( APIENTRY * qglBlendFunc )(GLenum sfactor, GLenum dfactor);
-void ( APIENTRY * qglClear )(GLbitfield mask);
-void ( APIENTRY * qglClearColor )(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-void ( APIENTRY * qglClearDepth )(GLclampd depth);
-void ( APIENTRY * qglClearIndex )(GLfloat c);
-void ( APIENTRY * qglClearStencil )(GLint s);
-void ( APIENTRY * qglColor4f )(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-void ( APIENTRY * qglColor4fv )(const GLfloat *v);
-void ( APIENTRY * qglColor4ub )(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-void ( APIENTRY * qglColor4ubv )(const GLubyte *v);
-void ( APIENTRY * qglColorMask )(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-void ( APIENTRY * qglColorPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-void ( APIENTRY * qglCopyTexImage2D )(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
-void ( APIENTRY * qglCopyTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
-void ( APIENTRY * qglCullFace )(GLenum mode);
-void ( APIENTRY * qglDeleteTextures )(GLsizei n, const GLuint *textures);
-void ( APIENTRY * qglDepthFunc )(GLenum func);
-void ( APIENTRY * qglDepthMask )(GLboolean flag);
-void ( APIENTRY * qglDepthRange )(GLclampd zNear, GLclampd zFar);
-void ( APIENTRY * qglDisable )(GLenum cap);
-void ( APIENTRY * qglDisableClientState )(GLenum array);
-void ( APIENTRY * qglDrawArrays )(GLenum mode, GLint first, GLsizei count);
-void ( APIENTRY * qglDrawElements )(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
-void ( APIENTRY * qglEnable )(GLenum cap);
-void ( APIENTRY * qglEnableClientState )(GLenum array);
-void ( APIENTRY * qglFinish )(void);
-void ( APIENTRY * qglFlush )(void);
-void ( APIENTRY * qglFogf )(GLenum pname, GLfloat param);
-void ( APIENTRY * qglFogfv )(GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglFrontFace )(GLenum mode);
-void ( APIENTRY * qglFrustum )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-void ( APIENTRY * qglGenTextures )(GLsizei n, GLuint *textures);
-void ( APIENTRY * qglGetBooleanv )(GLenum pname, GLboolean *params);
-GLenum ( APIENTRY * qglGetError )(void);
-void ( APIENTRY * qglGetFloatv )(GLenum pname, GLfloat *params);
-void ( APIENTRY * qglGetIntegerv )(GLenum pname, GLint *params);
-void ( APIENTRY * qglGetLightfv )(GLenum light, GLenum pname, GLfloat *params);
-void ( APIENTRY * qglGetMaterialfv )(GLenum face, GLenum pname, GLfloat *params);
-void ( APIENTRY * qglGetPointerv )(GLenum pname, GLvoid* *params);
-const GLubyte * ( APIENTRY * qglGetString )(GLenum name);
-void ( APIENTRY * qglGetTexEnvfv )(GLenum target, GLenum pname, GLfloat *params);
-void ( APIENTRY * qglGetTexEnviv )(GLenum target, GLenum pname, GLint *params);
-void ( APIENTRY * qglGetTexParameterfv )(GLenum target, GLenum pname, GLfloat *params);
-void ( APIENTRY * qglGetTexParameteriv )(GLenum target, GLenum pname, GLint *params);
-void ( APIENTRY * qglHint )(GLenum target, GLenum mode);
-GLboolean ( APIENTRY * qglIsEnabled )(GLenum cap);
-GLboolean ( APIENTRY * qglIsTexture )(GLuint texture);
-void ( APIENTRY * qglLightModelf )(GLenum pname, GLfloat param);
-void ( APIENTRY * qglLightModelfv )(GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglLightf )(GLenum light, GLenum pname, GLfloat param);
-void ( APIENTRY * qglLightfv )(GLenum light, GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglLineWidth )(GLfloat width);
-void ( APIENTRY * qglLoadIdentity )(void);
-void ( APIENTRY * qglLoadMatrixf )(const GLfloat *m);
-void ( APIENTRY * qglLogicOp )(GLenum opcode);
-void ( APIENTRY * qglMaterialf )(GLenum face, GLenum pname, GLfloat param);
-void ( APIENTRY * qglMaterialfv )(GLenum face, GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglMatrixMode )(GLenum mode);
-void ( APIENTRY * qglMultMatrixf )(const GLfloat *m);
-void ( APIENTRY * qglNormal3f )(GLfloat nx, GLfloat ny, GLfloat nz);
-void ( APIENTRY * qglNormal3fv )(const GLfloat *v);
-void ( APIENTRY * qglNormalPointer )(GLenum type, GLsizei stride, const GLvoid *pointer);
-void ( APIENTRY * qglOrtho )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-void ( APIENTRY * qglPixelStorei )(GLenum pname, GLint param);
-void ( APIENTRY * qglPointSize )(GLfloat size);
-void ( APIENTRY * qglPolygonMode )(GLenum face, GLenum mode);
-void ( APIENTRY * qglPolygonOffset )(GLfloat factor, GLfloat units);
-void ( APIENTRY * qglPopMatrix )(void);
-void ( APIENTRY * qglPushMatrix )(void);
-void ( APIENTRY * qglReadPixels )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
-void ( APIENTRY * qglRotatef )(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-void ( APIENTRY * qglScalef )(GLfloat x, GLfloat y, GLfloat z);
-void ( APIENTRY * qglScissor )(GLint x, GLint y, GLsizei width, GLsizei height);
-void ( APIENTRY * qglShadeModel )(GLenum mode);
-void ( APIENTRY * qglStencilFunc )(GLenum func, GLint ref, GLuint mask);
-void ( APIENTRY * qglStencilMask )(GLuint mask);
-void ( APIENTRY * qglStencilOp )(GLenum fail, GLenum zfail, GLenum zpass);
-void ( APIENTRY * qglTexCoordPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-void ( APIENTRY * qglTexEnvf )(GLenum target, GLenum pname, GLfloat param);
-void ( APIENTRY * qglTexEnvfv )(GLenum target, GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglTexEnvi )(GLenum target, GLenum pname, GLint param);
-void ( APIENTRY * qglTexEnviv )(GLenum target, GLenum pname, const GLint *params);
-void ( APIENTRY * qglTexImage2D )(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-void ( APIENTRY * qglTexParameterf )(GLenum target, GLenum pname, GLfloat param);
-void ( APIENTRY * qglTexParameterfv )(GLenum target, GLenum pname, const GLfloat *params);
-void ( APIENTRY * qglTexParameteri )(GLenum target, GLenum pname, GLint param);
-void ( APIENTRY * qglTexParameteriv )(GLenum target, GLenum pname, const GLint *params);
-void ( APIENTRY * qglTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
-void ( APIENTRY * qglTranslatef )(GLfloat x, GLfloat y, GLfloat z);
-void ( APIENTRY * qglVertexPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-void ( APIENTRY * qglViewport )(GLint x, GLint y, GLsizei width, GLsizei height);
+void (APIENTRY * qglAlphaFunc)(GLenum func, GLclampf ref);
+void (APIENTRY * qglBindTexture)(GLenum target, GLuint texture);
+void (APIENTRY * qglBlendFunc)(GLenum sfactor, GLenum dfactor);
+void (APIENTRY * qglClear)(GLbitfield mask);
+void (APIENTRY * qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+void (APIENTRY * qglClearDepth)(GLclampd depth);
+void (APIENTRY * qglClearIndex)(GLfloat c);
+void (APIENTRY * qglClearStencil)(GLint s);
+void (APIENTRY * qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+void (APIENTRY * qglColor4fv)(const GLfloat *v);
+void (APIENTRY * qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
+void (APIENTRY * qglColor4ubv)(const GLubyte *v);
+void (APIENTRY * qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+void (APIENTRY * qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+void (APIENTRY * qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+void (APIENTRY * qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+void (APIENTRY * qglCullFace)(GLenum mode);
+void (APIENTRY * qglDeleteTextures)(GLsizei n, const GLuint *textures);
+void (APIENTRY * qglDepthFunc)(GLenum func);
+void (APIENTRY * qglDepthMask)(GLboolean flag);
+void (APIENTRY * qglDepthRange)(GLclampd zNear, GLclampd zFar);
+void (APIENTRY * qglDisable)(GLenum cap);
+void (APIENTRY * qglDisableClientState)(GLenum array);
+void (APIENTRY * qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
+void (APIENTRY * qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+void (APIENTRY * qglEnable)(GLenum cap);
+void (APIENTRY * qglEnableClientState)(GLenum array);
+void (APIENTRY * qglFinish)(void);
+void (APIENTRY * qglFlush)(void);
+void (APIENTRY * qglFogf)(GLenum pname, GLfloat param);
+void (APIENTRY * qglFogfv)(GLenum pname, const GLfloat *params);
+void (APIENTRY * qglFrontFace)(GLenum mode);
+void (APIENTRY * qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+void (APIENTRY * qglGenTextures)(GLsizei n, GLuint *textures);
+void (APIENTRY * qglGetBooleanv)(GLenum pname, GLboolean *params);
+GLenum (APIENTRY * qglGetError)(void);
+void (APIENTRY * qglGetFloatv)(GLenum pname, GLfloat *params);
+void (APIENTRY * qglGetIntegerv)(GLenum pname, GLint *params);
+void (APIENTRY * qglGetLightfv)(GLenum light, GLenum pname, GLfloat *params);
+void (APIENTRY * qglGetMaterialfv)(GLenum face, GLenum pname, GLfloat *params);
+void (APIENTRY * qglGetPointerv)(GLenum pname, GLvoid* *params);
+const GLubyte * (APIENTRY * qglGetString)(GLenum name);
+void (APIENTRY * qglGetTexEnvfv)(GLenum target, GLenum pname, GLfloat *params);
+void (APIENTRY * qglGetTexEnviv)(GLenum target, GLenum pname, GLint *params);
+void (APIENTRY * qglGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
+void (APIENTRY * qglGetTexParameteriv)(GLenum target, GLenum pname, GLint *params);
+void (APIENTRY * qglHint)(GLenum target, GLenum mode);
+GLboolean (APIENTRY * qglIsEnabled)(GLenum cap);
+GLboolean (APIENTRY * qglIsTexture)(GLuint texture);
+void (APIENTRY * qglLightModelf)(GLenum pname, GLfloat param);
+void (APIENTRY * qglLightModelfv)(GLenum pname, const GLfloat *params);
+void (APIENTRY * qglLightf)(GLenum light, GLenum pname, GLfloat param);
+void (APIENTRY * qglLightfv)(GLenum light, GLenum pname, const GLfloat *params);
+void (APIENTRY * qglLineWidth)(GLfloat width);
+void (APIENTRY * qglLoadIdentity)(void);
+void (APIENTRY * qglLoadMatrixf)(const GLfloat *m);
+void (APIENTRY * qglLogicOp)(GLenum opcode);
+void (APIENTRY * qglMaterialf)(GLenum face, GLenum pname, GLfloat param);
+void (APIENTRY * qglMaterialfv)(GLenum face, GLenum pname, const GLfloat *params);
+void (APIENTRY * qglMatrixMode)(GLenum mode);
+void (APIENTRY * qglMultMatrixf)(const GLfloat *m);
+void (APIENTRY * qglNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz);
+void (APIENTRY * qglNormal3fv)(const GLfloat *v);
+void (APIENTRY * qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer);
+void (APIENTRY * qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+void (APIENTRY * qglPixelStorei)(GLenum pname, GLint param);
+void (APIENTRY * qglPointSize)(GLfloat size);
+void (APIENTRY * qglPolygonMode)(GLenum face, GLenum mode);
+void (APIENTRY * qglPolygonOffset)(GLfloat factor, GLfloat units);
+void (APIENTRY * qglPopMatrix)(void);
+void (APIENTRY * qglPushMatrix)(void);
+void (APIENTRY * qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
+void (APIENTRY * qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+void (APIENTRY * qglScalef)(GLfloat x, GLfloat y, GLfloat z);
+void (APIENTRY * qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
+void (APIENTRY * qglShadeModel)(GLenum mode);
+void (APIENTRY * qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
+void (APIENTRY * qglStencilMask)(GLuint mask);
+void (APIENTRY * qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
+void (APIENTRY * qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+void (APIENTRY * qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
+void (APIENTRY * qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
+void (APIENTRY * qglTexEnvi)(GLenum target, GLenum pname, GLint param);
+void (APIENTRY * qglTexEnviv)(GLenum target, GLenum pname, const GLint *params);
+void (APIENTRY * qglTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+void (APIENTRY * qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
+void (APIENTRY * qglTexParameterfv)(GLenum target, GLenum pname, const GLfloat *params);
+void (APIENTRY * qglTexParameteri)(GLenum target, GLenum pname, GLint param);
+void (APIENTRY * qglTexParameteriv)(GLenum target, GLenum pname, const GLint *params);
+void (APIENTRY * qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+void (APIENTRY * qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
+void (APIENTRY * qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+void (APIENTRY * qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
//
// OS-specific
@@ -135,7 +135,7 @@ void ( APIENTRY * qglViewport )(GLint x, GLint y, GLsizei width, GLsizei height)
#ifdef _WIN32
// this one is defined in win_wgl.c
-extern PROC ( WINAPI * qwglGetProcAddress )( LPCSTR );
+extern PROC(WINAPI * qwglGetProcAddress)(LPCSTR);
#endif
//
@@ -143,693 +143,693 @@ extern PROC ( WINAPI * qwglGetProcAddress )( LPCSTR );
//
// GL_EXT_compiled_vertex_array
-void ( APIENTRY * qglLockArraysEXT )(GLint first, GLsizei count);
-void ( APIENTRY * qglUnlockArraysEXT )(void);
+void (APIENTRY * qglLockArraysEXT)(GLint first, GLsizei count);
+void (APIENTRY * qglUnlockArraysEXT)(void);
// GL_ARB_multitexture
-void ( APIENTRY * qglActiveTextureARB )(GLenum texture);
-void ( APIENTRY * qglClientActiveTextureARB )(GLenum texture);
+void (APIENTRY * qglActiveTextureARB)(GLenum texture);
+void (APIENTRY * qglClientActiveTextureARB)(GLenum texture);
// GL_ARB_fragment_program
-void ( APIENTRY * qglProgramStringARB )(GLenum target, GLenum format, GLsizei len, const GLvoid *string);
-void ( APIENTRY * qglBindProgramARB )(GLenum target, GLuint program);
-void ( APIENTRY * qglDeleteProgramsARB )(GLsizei n, const GLuint *programs);
-void ( APIENTRY * qglGenProgramsARB )(GLsizei n, GLuint *programs);
-void ( APIENTRY * qglProgramEnvParameter4fvARB )(GLenum target, GLuint index, const GLfloat *params);
-void ( APIENTRY * qglProgramLocalParameter4fvARB )(GLenum target, GLuint index, const GLfloat *params);
-void ( APIENTRY * qglGetProgramEnvParameterfvARB )(GLenum, GLuint, GLfloat *);
-void ( APIENTRY * qglGetProgramLocalParameterfvARB )(GLenum, GLuint, GLfloat *);
-void ( APIENTRY * qglGetProgramivARB )(GLenum, GLenum, GLint *);
-void ( APIENTRY * qglGetProgramStringARB )(GLenum, GLenum, GLvoid *);
-GLboolean ( APIENTRY * qglIsProgramARB )(GLuint);
+void (APIENTRY * qglProgramStringARB)(GLenum target, GLenum format, GLsizei len, const GLvoid *string);
+void (APIENTRY * qglBindProgramARB)(GLenum target, GLuint program);
+void (APIENTRY * qglDeleteProgramsARB)(GLsizei n, const GLuint *programs);
+void (APIENTRY * qglGenProgramsARB)(GLsizei n, GLuint *programs);
+void (APIENTRY * qglProgramEnvParameter4fvARB)(GLenum target, GLuint index, const GLfloat *params);
+void (APIENTRY * qglProgramLocalParameter4fvARB)(GLenum target, GLuint index, const GLfloat *params);
+void (APIENTRY * qglGetProgramEnvParameterfvARB)(GLenum, GLuint, GLfloat *);
+void (APIENTRY * qglGetProgramLocalParameterfvARB)(GLenum, GLuint, GLfloat *);
+void (APIENTRY * qglGetProgramivARB)(GLenum, GLenum, GLint *);
+void (APIENTRY * qglGetProgramStringARB)(GLenum, GLenum, GLvoid *);
+GLboolean (APIENTRY * qglIsProgramARB)(GLuint);
// GL_ARB_vertex_buffer_object
-void ( APIENTRY * qglBindBufferARB )(GLenum target, GLuint buffer);
-void ( APIENTRY * qglDeleteBuffersARB )(GLsizei n, const GLuint *buffers);
-void ( APIENTRY * qglGenBuffersARB )(GLsizei n, GLuint *buffers);
-GLboolean ( APIENTRY * qglIsBufferARB )(GLuint);
-void ( APIENTRY * qglBufferDataARB )(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
-void ( APIENTRY * qglBufferSubDataARB )(GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *);
-void ( APIENTRY * qglGetBufferSubDataARB )(GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *);
-GLvoid * ( APIENTRY * qglMapBufferARB )(GLenum target, GLenum access);
-GLboolean ( APIENTRY * qglUnmapBufferARB )(GLenum target);
-void ( APIENTRY * qglGetBufferParameterivARB )(GLenum, GLenum, GLint *);
-void ( APIENTRY * qglGetBufferPointervARB )(GLenum, GLenum, GLvoid* *);
+void (APIENTRY * qglBindBufferARB)(GLenum target, GLuint buffer);
+void (APIENTRY * qglDeleteBuffersARB)(GLsizei n, const GLuint *buffers);
+void (APIENTRY * qglGenBuffersARB)(GLsizei n, GLuint *buffers);
+GLboolean (APIENTRY * qglIsBufferARB)(GLuint);
+void (APIENTRY * qglBufferDataARB)(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
+void (APIENTRY * qglBufferSubDataARB)(GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *);
+void (APIENTRY * qglGetBufferSubDataARB)(GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *);
+GLvoid * (APIENTRY * qglMapBufferARB)(GLenum target, GLenum access);
+GLboolean (APIENTRY * qglUnmapBufferARB)(GLenum target);
+void (APIENTRY * qglGetBufferParameterivARB)(GLenum, GLenum, GLint *);
+void (APIENTRY * qglGetBufferPointervARB)(GLenum, GLenum, GLvoid* *);
// ==========================================================
-static void ( APIENTRY * dllAlphaFunc )(GLenum func, GLclampf ref);
-static void ( APIENTRY * dllBindTexture )(GLenum target, GLuint texture);
-static void ( APIENTRY * dllBlendFunc )(GLenum sfactor, GLenum dfactor);
-static void ( APIENTRY * dllClear )(GLbitfield mask);
-static void ( APIENTRY * dllClearColor )(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-static void ( APIENTRY * dllClearDepth )(GLclampd depth);
-static void ( APIENTRY * dllClearIndex )(GLfloat c);
-static void ( APIENTRY * dllClearStencil )(GLint s);
-static void ( APIENTRY * dllColor4f )(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-static void ( APIENTRY * dllColor4fv )(const GLfloat *v);
-static void ( APIENTRY * dllColor4ub )(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-static void ( APIENTRY * dllColor4ubv )(const GLubyte *v);
-static void ( APIENTRY * dllColorMask )(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-static void ( APIENTRY * dllColorPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-static void ( APIENTRY * dllCopyTexImage2D )(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
-static void ( APIENTRY * dllCopyTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
-static void ( APIENTRY * dllCullFace )(GLenum mode);
-static void ( APIENTRY * dllDeleteTextures )(GLsizei n, const GLuint *textures);
-static void ( APIENTRY * dllDepthFunc )(GLenum func);
-static void ( APIENTRY * dllDepthMask )(GLboolean flag);
-static void ( APIENTRY * dllDepthRange )(GLclampd zNear, GLclampd zFar);
-static void ( APIENTRY * dllDisable )(GLenum cap);
-static void ( APIENTRY * dllDisableClientState )(GLenum array);
-static void ( APIENTRY * dllDrawArrays )(GLenum mode, GLint first, GLsizei count);
-static void ( APIENTRY * dllDrawElements )(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
-static void ( APIENTRY * dllEnable )(GLenum cap);
-static void ( APIENTRY * dllEnableClientState )(GLenum array);
-static void ( APIENTRY * dllFinish )(void);
-static void ( APIENTRY * dllFlush )(void);
-static void ( APIENTRY * dllFogf )(GLenum pname, GLfloat param);
-static void ( APIENTRY * dllFogfv )(GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllFrontFace )(GLenum mode);
-static void ( APIENTRY * dllFrustum )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-static void ( APIENTRY * dllGenTextures )(GLsizei n, GLuint *textures);
-static void ( APIENTRY * dllGetBooleanv )(GLenum pname, GLboolean *params);
-GLenum ( APIENTRY * dllGetError )(void);
-static void ( APIENTRY * dllGetFloatv )(GLenum pname, GLfloat *params);
-static void ( APIENTRY * dllGetIntegerv )(GLenum pname, GLint *params);
-static void ( APIENTRY * dllGetLightfv )(GLenum light, GLenum pname, GLfloat *params);
-static void ( APIENTRY * dllGetMaterialfv )(GLenum face, GLenum pname, GLfloat *params);
-static void ( APIENTRY * dllGetPointerv )(GLenum pname, GLvoid* *params);
-const GLubyte * ( APIENTRY * dllGetString )(GLenum name);
-static void ( APIENTRY * dllGetTexEnvfv )(GLenum target, GLenum pname, GLfloat *params);
-static void ( APIENTRY * dllGetTexEnviv )(GLenum target, GLenum pname, GLint *params);
-static void ( APIENTRY * dllGetTexParameterfv )(GLenum target, GLenum pname, GLfloat *params);
-static void ( APIENTRY * dllGetTexParameteriv )(GLenum target, GLenum pname, GLint *params);
-static void ( APIENTRY * dllHint )(GLenum target, GLenum mode);
-GLboolean ( APIENTRY * dllIsEnabled )(GLenum cap);
-GLboolean ( APIENTRY * dllIsTexture )(GLuint texture);
-static void ( APIENTRY * dllLightModelf )(GLenum pname, GLfloat param);
-static void ( APIENTRY * dllLightModelfv )(GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllLightf )(GLenum light, GLenum pname, GLfloat param);
-static void ( APIENTRY * dllLightfv )(GLenum light, GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllLineWidth )(GLfloat width);
-static void ( APIENTRY * dllLoadIdentity )(void);
-static void ( APIENTRY * dllLoadMatrixf )(const GLfloat *m);
-static void ( APIENTRY * dllLogicOp )(GLenum opcode);
-static void ( APIENTRY * dllMaterialf )(GLenum face, GLenum pname, GLfloat param);
-static void ( APIENTRY * dllMaterialfv )(GLenum face, GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllMatrixMode )(GLenum mode);
-static void ( APIENTRY * dllMultMatrixf )(const GLfloat *m);
-static void ( APIENTRY * dllNormal3f )(GLfloat nx, GLfloat ny, GLfloat nz);
-static void ( APIENTRY * dllNormal3fv )(const GLfloat *v);
-static void ( APIENTRY * dllNormalPointer )(GLenum type, GLsizei stride, const GLvoid *pointer);
-static void ( APIENTRY * dllOrtho )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-static void ( APIENTRY * dllPixelStorei )(GLenum pname, GLint param);
-static void ( APIENTRY * dllPointSize )(GLfloat size);
-static void ( APIENTRY * dllPolygonMode )(GLenum face, GLenum mode);
-static void ( APIENTRY * dllPolygonOffset )(GLfloat factor, GLfloat units);
-static void ( APIENTRY * dllPopMatrix )(void);
-static void ( APIENTRY * dllPushMatrix )(void);
-static void ( APIENTRY * dllReadPixels )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
-static void ( APIENTRY * dllRotatef )(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-static void ( APIENTRY * dllScalef )(GLfloat x, GLfloat y, GLfloat z);
-static void ( APIENTRY * dllScissor )(GLint x, GLint y, GLsizei width, GLsizei height);
-static void ( APIENTRY * dllShadeModel )(GLenum mode);
-static void ( APIENTRY * dllStencilFunc )(GLenum func, GLint ref, GLuint mask);
-static void ( APIENTRY * dllStencilMask )(GLuint mask);
-static void ( APIENTRY * dllStencilOp )(GLenum fail, GLenum zfail, GLenum zpass);
-static void ( APIENTRY * dllTexCoordPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-static void ( APIENTRY * dllTexEnvf )(GLenum target, GLenum pname, GLfloat param);
-static void ( APIENTRY * dllTexEnvfv )(GLenum target, GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllTexEnvi )(GLenum target, GLenum pname, GLint param);
-static void ( APIENTRY * dllTexEnviv )(GLenum target, GLenum pname, const GLint *params);
-static void ( APIENTRY * dllTexImage2D )(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-static void ( APIENTRY * dllTexParameterf )(GLenum target, GLenum pname, GLfloat param);
-static void ( APIENTRY * dllTexParameterfv )(GLenum target, GLenum pname, const GLfloat *params);
-static void ( APIENTRY * dllTexParameteri )(GLenum target, GLenum pname, GLint param);
-static void ( APIENTRY * dllTexParameteriv )(GLenum target, GLenum pname, const GLint *params);
-static void ( APIENTRY * dllTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
-static void ( APIENTRY * dllTranslatef )(GLfloat x, GLfloat y, GLfloat z);
-static void ( APIENTRY * dllVertexPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-static void ( APIENTRY * dllViewport )(GLint x, GLint y, GLsizei width, GLsizei height);
-
-#define SIG( x ) fprintf( log_fp, x "\n" )
+static void (APIENTRY * dllAlphaFunc)(GLenum func, GLclampf ref);
+static void (APIENTRY * dllBindTexture)(GLenum target, GLuint texture);
+static void (APIENTRY * dllBlendFunc)(GLenum sfactor, GLenum dfactor);
+static void (APIENTRY * dllClear)(GLbitfield mask);
+static void (APIENTRY * dllClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+static void (APIENTRY * dllClearDepth)(GLclampd depth);
+static void (APIENTRY * dllClearIndex)(GLfloat c);
+static void (APIENTRY * dllClearStencil)(GLint s);
+static void (APIENTRY * dllColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+static void (APIENTRY * dllColor4fv)(const GLfloat *v);
+static void (APIENTRY * dllColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
+static void (APIENTRY * dllColor4ubv)(const GLubyte *v);
+static void (APIENTRY * dllColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+static void (APIENTRY * dllColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+static void (APIENTRY * dllCopyTexImage2D)(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+static void (APIENTRY * dllCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+static void (APIENTRY * dllCullFace)(GLenum mode);
+static void (APIENTRY * dllDeleteTextures)(GLsizei n, const GLuint *textures);
+static void (APIENTRY * dllDepthFunc)(GLenum func);
+static void (APIENTRY * dllDepthMask)(GLboolean flag);
+static void (APIENTRY * dllDepthRange)(GLclampd zNear, GLclampd zFar);
+static void (APIENTRY * dllDisable)(GLenum cap);
+static void (APIENTRY * dllDisableClientState)(GLenum array);
+static void (APIENTRY * dllDrawArrays)(GLenum mode, GLint first, GLsizei count);
+static void (APIENTRY * dllDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+static void (APIENTRY * dllEnable)(GLenum cap);
+static void (APIENTRY * dllEnableClientState)(GLenum array);
+static void (APIENTRY * dllFinish)(void);
+static void (APIENTRY * dllFlush)(void);
+static void (APIENTRY * dllFogf)(GLenum pname, GLfloat param);
+static void (APIENTRY * dllFogfv)(GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllFrontFace)(GLenum mode);
+static void (APIENTRY * dllFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+static void (APIENTRY * dllGenTextures)(GLsizei n, GLuint *textures);
+static void (APIENTRY * dllGetBooleanv)(GLenum pname, GLboolean *params);
+static GLenum (APIENTRY * dllGetError)(void);
+static void (APIENTRY * dllGetFloatv)(GLenum pname, GLfloat *params);
+static void (APIENTRY * dllGetIntegerv)(GLenum pname, GLint *params);
+static void (APIENTRY * dllGetLightfv)(GLenum light, GLenum pname, GLfloat *params);
+static void (APIENTRY * dllGetMaterialfv)(GLenum face, GLenum pname, GLfloat *params);
+static void (APIENTRY * dllGetPointerv)(GLenum pname, GLvoid* *params);
+static const GLubyte * (APIENTRY * dllGetString)(GLenum name);
+static void (APIENTRY * dllGetTexEnvfv)(GLenum target, GLenum pname, GLfloat *params);
+static void (APIENTRY * dllGetTexEnviv)(GLenum target, GLenum pname, GLint *params);
+static void (APIENTRY * dllGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
+static void (APIENTRY * dllGetTexParameteriv)(GLenum target, GLenum pname, GLint *params);
+static void (APIENTRY * dllHint)(GLenum target, GLenum mode);
+static GLboolean (APIENTRY * dllIsEnabled)(GLenum cap);
+static GLboolean (APIENTRY * dllIsTexture)(GLuint texture);
+static void (APIENTRY * dllLightModelf)(GLenum pname, GLfloat param);
+static void (APIENTRY * dllLightModelfv)(GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllLightf)(GLenum light, GLenum pname, GLfloat param);
+static void (APIENTRY * dllLightfv)(GLenum light, GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllLineWidth)(GLfloat width);
+static void (APIENTRY * dllLoadIdentity)(void);
+static void (APIENTRY * dllLoadMatrixf)(const GLfloat *m);
+static void (APIENTRY * dllLogicOp)(GLenum opcode);
+static void (APIENTRY * dllMaterialf)(GLenum face, GLenum pname, GLfloat param);
+static void (APIENTRY * dllMaterialfv)(GLenum face, GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllMatrixMode)(GLenum mode);
+static void (APIENTRY * dllMultMatrixf)(const GLfloat *m);
+static void (APIENTRY * dllNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz);
+static void (APIENTRY * dllNormal3fv)(const GLfloat *v);
+static void (APIENTRY * dllNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer);
+static void (APIENTRY * dllOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+static void (APIENTRY * dllPixelStorei)(GLenum pname, GLint param);
+static void (APIENTRY * dllPointSize)(GLfloat size);
+static void (APIENTRY * dllPolygonMode)(GLenum face, GLenum mode);
+static void (APIENTRY * dllPolygonOffset)(GLfloat factor, GLfloat units);
+static void (APIENTRY * dllPopMatrix)(void);
+static void (APIENTRY * dllPushMatrix)(void);
+static void (APIENTRY * dllReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
+static void (APIENTRY * dllRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+static void (APIENTRY * dllScalef)(GLfloat x, GLfloat y, GLfloat z);
+static void (APIENTRY * dllScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
+static void (APIENTRY * dllShadeModel)(GLenum mode);
+static void (APIENTRY * dllStencilFunc)(GLenum func, GLint ref, GLuint mask);
+static void (APIENTRY * dllStencilMask)(GLuint mask);
+static void (APIENTRY * dllStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
+static void (APIENTRY * dllTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+static void (APIENTRY * dllTexEnvf)(GLenum target, GLenum pname, GLfloat param);
+static void (APIENTRY * dllTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllTexEnvi)(GLenum target, GLenum pname, GLint param);
+static void (APIENTRY * dllTexEnviv)(GLenum target, GLenum pname, const GLint *params);
+static void (APIENTRY * dllTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+static void (APIENTRY * dllTexParameterf)(GLenum target, GLenum pname, GLfloat param);
+static void (APIENTRY * dllTexParameterfv)(GLenum target, GLenum pname, const GLfloat *params);
+static void (APIENTRY * dllTexParameteri)(GLenum target, GLenum pname, GLint param);
+static void (APIENTRY * dllTexParameteriv)(GLenum target, GLenum pname, const GLint *params);
+static void (APIENTRY * dllTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+static void (APIENTRY * dllTranslatef)(GLfloat x, GLfloat y, GLfloat z);
+static void (APIENTRY * dllVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+static void (APIENTRY * dllViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
+
+#define SIG(x) fprintf(log_fp, x "\n")
static void APIENTRY logAlphaFunc(GLenum func, GLclampf ref)
{
- fprintf( log_fp, "glAlphaFunc( 0x%x, %f )\n", func, ref );
- dllAlphaFunc( func, ref );
+ fprintf(log_fp, "glAlphaFunc( 0x%x, %f )\n", func, ref);
+ dllAlphaFunc(func, ref);
}
static void APIENTRY logBindTexture(GLenum target, GLuint texture)
{
- fprintf( log_fp, "glBindTexture( 0x%x, %u )\n", target, texture );
- dllBindTexture( target, texture );
+ fprintf(log_fp, "glBindTexture( 0x%x, %u )\n", target, texture);
+ dllBindTexture(target, texture);
}
static void APIENTRY logBlendFunc(GLenum sfactor, GLenum dfactor)
{
- fprintf( log_fp, "glBlendFunc( 0x%x, 0x%x )\n", sfactor, dfactor );
- dllBlendFunc( sfactor, dfactor );
+ fprintf(log_fp, "glBlendFunc( 0x%x, 0x%x )\n", sfactor, dfactor);
+ dllBlendFunc(sfactor, dfactor);
}
static void APIENTRY logClear(GLbitfield mask)
{
- fprintf( log_fp, "glClear\n" );
- dllClear( mask );
+ fprintf(log_fp, "glClear\n");
+ dllClear(mask);
}
static void APIENTRY logClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
- fprintf( log_fp, "glClearColor\n" );
- dllClearColor( red, green, blue, alpha );
+ fprintf(log_fp, "glClearColor\n");
+ dllClearColor(red, green, blue, alpha);
}
static void APIENTRY logClearDepth(GLclampd depth)
{
- fprintf( log_fp, "glClearDepth\n" );
- dllClearDepth( depth );
+ fprintf(log_fp, "glClearDepth\n");
+ dllClearDepth(depth);
}
static void APIENTRY logClearIndex(GLfloat c)
{
- fprintf( log_fp, "glClearIndex\n" );
- dllClearIndex( c );
+ fprintf(log_fp, "glClearIndex\n");
+ dllClearIndex(c);
}
static void APIENTRY logClearStencil(GLint s)
{
- fprintf( log_fp, "glClearStencil\n" );
- dllClearStencil( s );
+ fprintf(log_fp, "glClearStencil\n");
+ dllClearStencil(s);
}
static void APIENTRY logColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
{
- fprintf( log_fp, "glColor4f( %f,%f,%f,%f )\n", red, green, blue, alpha );
- dllColor4f( red, green, blue, alpha );
+ fprintf(log_fp, "glColor4f( %f,%f,%f,%f )\n", red, green, blue, alpha);
+ dllColor4f(red, green, blue, alpha);
}
static void APIENTRY logColor4fv(const GLfloat *v)
{
- fprintf( log_fp, "glColor4fv( %f,%f,%f,%f )\n", v[0], v[1], v[2], v[3] );
- dllColor4fv( v );
+ fprintf(log_fp, "glColor4fv( %f,%f,%f,%f )\n", v[0], v[1], v[2], v[3]);
+ dllColor4fv(v);
}
static void APIENTRY logColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
{
- SIG( "glColor4ub" );
- dllColor4ub( red, green, blue, alpha );
+ SIG("glColor4ub");
+ dllColor4ub(red, green, blue, alpha);
}
static void APIENTRY logColor4ubv(const GLubyte *v)
{
- SIG( "glColor4ubv" );
- dllColor4ubv( v );
+ SIG("glColor4ubv");
+ dllColor4ubv(v);
}
static void APIENTRY logColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
- SIG( "glColorMask" );
- dllColorMask( red, green, blue, alpha );
+ SIG("glColorMask");
+ dllColorMask(red, green, blue, alpha);
}
static void APIENTRY logColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
{
- SIG( "glColorPointer" );
- dllColorPointer( size, type, stride, pointer );
+ SIG("glColorPointer");
+ dllColorPointer(size, type, stride, pointer);
}
static void APIENTRY logCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
- SIG( "glCopyTexImage2D" );
- dllCopyTexImage2D( target, level, internalFormat, x, y, width, height, border );
+ SIG("glCopyTexImage2D");
+ dllCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
}
static void APIENTRY logCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
- SIG( "glCopyTexSubImage2D" );
- dllCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
+ SIG("glCopyTexSubImage2D");
+ dllCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
}
static void APIENTRY logCullFace(GLenum mode)
{
- SIG( "glCullFace" );
- dllCullFace( mode );
+ SIG("glCullFace");
+ dllCullFace(mode);
}
static void APIENTRY logDeleteTextures(GLsizei n, const GLuint *textures)
{
- SIG( "glDeleteTextures" );
- dllDeleteTextures( n, textures );
+ SIG("glDeleteTextures");
+ dllDeleteTextures(n, textures);
}
static void APIENTRY logDepthFunc(GLenum func)
{
- SIG( "glDepthFunc" );
- dllDepthFunc( func );
+ SIG("glDepthFunc");
+ dllDepthFunc(func);
}
static void APIENTRY logDepthMask(GLboolean flag)
{
- SIG( "glDepthMask" );
- dllDepthMask( flag );
+ SIG("glDepthMask");
+ dllDepthMask(flag);
}
static void APIENTRY logDepthRange(GLclampd zNear, GLclampd zFar)
{
- SIG( "glDepthRange" );
- dllDepthRange( zNear, zFar );
+ SIG("glDepthRange");
+ dllDepthRange(zNear, zFar);
}
static void APIENTRY logDisable(GLenum cap)
{
- fprintf( log_fp, "glDisable( 0x%x )\n", cap );
- dllDisable( cap );
+ fprintf(log_fp, "glDisable( 0x%x )\n", cap);
+ dllDisable(cap);
}
static void APIENTRY logDisableClientState(GLenum array)
{
- SIG( "glDisableClientState" );
- dllDisableClientState( array );
+ SIG("glDisableClientState");
+ dllDisableClientState(array);
}
static void APIENTRY logDrawArrays(GLenum mode, GLint first, GLsizei count)
{
- SIG( "glDrawArrays" );
- dllDrawArrays( mode, first, count );
+ SIG("glDrawArrays");
+ dllDrawArrays(mode, first, count);
}
static void APIENTRY logDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
{
- SIG( "glDrawElements" );
- dllDrawElements( mode, count, type, indices );
+ SIG("glDrawElements");
+ dllDrawElements(mode, count, type, indices);
}
static void APIENTRY logEnable(GLenum cap)
{
- fprintf( log_fp, "glEnable( 0x%x )\n", cap );
- dllEnable( cap );
+ fprintf(log_fp, "glEnable( 0x%x )\n", cap);
+ dllEnable(cap);
}
static void APIENTRY logEnableClientState(GLenum array)
{
- SIG( "glEnableClientState" );
- dllEnableClientState( array );
+ SIG("glEnableClientState");
+ dllEnableClientState(array);
}
static void APIENTRY logFinish(void)
{
- SIG( "glFinish" );
+ SIG("glFinish");
dllFinish();
}
static void APIENTRY logFlush(void)
{
- SIG( "glFlush" );
+ SIG("glFlush");
dllFlush();
}
static void APIENTRY logFogf(GLenum pname, GLfloat param)
{
- SIG( "glFogf" );
- dllFogf( pname, param );
+ SIG("glFogf");
+ dllFogf(pname, param);
}
static void APIENTRY logFogfv(GLenum pname, const GLfloat *params)
{
- SIG( "glFogfv" );
- dllFogfv( pname, params );
+ SIG("glFogfv");
+ dllFogfv(pname, params);
}
static void APIENTRY logFrontFace(GLenum mode)
{
- SIG( "glFrontFace" );
- dllFrontFace( mode );
+ SIG("glFrontFace");
+ dllFrontFace(mode);
}
static void APIENTRY logFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
{
- SIG( "glFrustum" );
- dllFrustum( left, right, bottom, top, zNear, zFar );
+ SIG("glFrustum");
+ dllFrustum(left, right, bottom, top, zNear, zFar);
}
static void APIENTRY logGenTextures(GLsizei n, GLuint *textures)
{
- SIG( "glGenTextures" );
- dllGenTextures( n, textures );
+ SIG("glGenTextures");
+ dllGenTextures(n, textures);
}
static void APIENTRY logGetBooleanv(GLenum pname, GLboolean *params)
{
- SIG( "glGetBooleanv" );
- dllGetBooleanv( pname, params );
+ SIG("glGetBooleanv");
+ dllGetBooleanv(pname, params);
}
static GLenum APIENTRY logGetError(void)
{
- SIG( "glGetError" );
+ SIG("glGetError");
return dllGetError();
}
static void APIENTRY logGetFloatv(GLenum pname, GLfloat *params)
{
- SIG( "glGetFloatv" );
- dllGetFloatv( pname, params );
+ SIG("glGetFloatv");
+ dllGetFloatv(pname, params);
}
static void APIENTRY logGetIntegerv(GLenum pname, GLint *params)
{
- SIG( "glGetIntegerv" );
- dllGetIntegerv( pname, params );
+ SIG("glGetIntegerv");
+ dllGetIntegerv(pname, params);
}
static void APIENTRY logGetLightfv(GLenum light, GLenum pname, GLfloat *params)
{
- SIG( "glGetLightfv" );
- dllGetLightfv( light, pname, params );
+ SIG("glGetLightfv");
+ dllGetLightfv(light, pname, params);
}
static void APIENTRY logGetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
{
- SIG( "glGetMaterialfv" );
- dllGetMaterialfv( face, pname, params );
+ SIG("glGetMaterialfv");
+ dllGetMaterialfv(face, pname, params);
}
static void APIENTRY logGetPointerv(GLenum pname, GLvoid* *params)
{
- SIG( "glGetPointerv" );
- dllGetPointerv( pname, params );
+ SIG("glGetPointerv");
+ dllGetPointerv(pname, params);
}
static const GLubyte * APIENTRY logGetString(GLenum name)
{
- SIG( "glGetString" );
- return dllGetString( name );
+ SIG("glGetString");
+ return dllGetString(name);
}
static void APIENTRY logGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
{
- SIG( "glGetTexEnvfv" );
- dllGetTexEnvfv( target, pname, params );
+ SIG("glGetTexEnvfv");
+ dllGetTexEnvfv(target, pname, params);
}
static void APIENTRY logGetTexEnviv(GLenum target, GLenum pname, GLint *params)
{
- SIG( "glGetTexEnviv" );
- dllGetTexEnviv( target, pname, params );
+ SIG("glGetTexEnviv");
+ dllGetTexEnviv(target, pname, params);
}
static void APIENTRY logGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
{
- SIG( "glGetTexParameterfv" );
- dllGetTexParameterfv( target, pname, params );
+ SIG("glGetTexParameterfv");
+ dllGetTexParameterfv(target, pname, params);
}
static void APIENTRY logGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
{
- SIG( "glGetTexParameteriv" );
- dllGetTexParameteriv( target, pname, params );
+ SIG("glGetTexParameteriv");
+ dllGetTexParameteriv(target, pname, params);
}
static void APIENTRY logHint(GLenum target, GLenum mode)
{
- fprintf( log_fp, "glHint( 0x%x, 0x%x )\n", target, mode );
- dllHint( target, mode );
+ fprintf(log_fp, "glHint( 0x%x, 0x%x )\n", target, mode);
+ dllHint(target, mode);
}
static GLboolean APIENTRY logIsEnabled(GLenum cap)
{
- SIG( "glIsEnabled" );
- return dllIsEnabled( cap );
+ SIG("glIsEnabled");
+ return dllIsEnabled(cap);
}
static GLboolean APIENTRY logIsTexture(GLuint texture)
{
- SIG( "glIsTexture" );
- return dllIsTexture( texture );
+ SIG("glIsTexture");
+ return dllIsTexture(texture);
}
static void APIENTRY logLightModelf(GLenum pname, GLfloat param)
{
- SIG( "glLightModelf" );
- dllLightModelf( pname, param );
+ SIG("glLightModelf");
+ dllLightModelf(pname, param);
}
static void APIENTRY logLightModelfv(GLenum pname, const GLfloat *params)
{
- SIG( "glLightModelfv" );
- dllLightModelfv( pname, params );
+ SIG("glLightModelfv");
+ dllLightModelfv(pname, params);
}
static void APIENTRY logLightf(GLenum light, GLenum pname, GLfloat param)
{
- SIG( "glLightf" );
- dllLightf( light, pname, param );
+ SIG("glLightf");
+ dllLightf(light, pname, param);
}
static void APIENTRY logLightfv(GLenum light, GLenum pname, const GLfloat *params)
{
- SIG( "glLightfv" );
- dllLightfv( light, pname, params );
+ SIG("glLightfv");
+ dllLightfv(light, pname, params);
}
static void APIENTRY logLineWidth(GLfloat width)
{
- SIG( "glLineWidth" );
- dllLineWidth( width );
+ SIG("glLineWidth");
+ dllLineWidth(width);
}
static void APIENTRY logLoadIdentity(void)
{
- SIG( "glLoadIdentity" );
+ SIG("glLoadIdentity");
dllLoadIdentity();
}
static void APIENTRY logLoadMatrixf(const GLfloat *m)
{
- SIG( "glLoadMatrixf" );
- dllLoadMatrixf( m );
+ SIG("glLoadMatrixf");
+ dllLoadMatrixf(m);
}
static void APIENTRY logLogicOp(GLenum opcode)
{
- SIG( "glLogicOp" );
- dllLogicOp( opcode );
+ SIG("glLogicOp");
+ dllLogicOp(opcode);
}
static void APIENTRY logMaterialf(GLenum face, GLenum pname, GLfloat param)
{
- SIG( "glMaterialf" );
- dllMaterialf( face, pname, param );
+ SIG("glMaterialf");
+ dllMaterialf(face, pname, param);
}
static void APIENTRY logMaterialfv(GLenum face, GLenum pname, const GLfloat *params)
{
- SIG( "glMaterialfv" );
- dllMaterialfv( face, pname, params );
+ SIG("glMaterialfv");
+ dllMaterialfv(face, pname, params);
}
static void APIENTRY logMatrixMode(GLenum mode)
{
- SIG( "glMatrixMode" );
- dllMatrixMode( mode );
+ SIG("glMatrixMode");
+ dllMatrixMode(mode);
}
static void APIENTRY logMultMatrixf(const GLfloat *m)
{
- SIG( "glMultMatrixf" );
- dllMultMatrixf( m );
+ SIG("glMultMatrixf");
+ dllMultMatrixf(m);
}
static void APIENTRY logNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
{
- SIG( "glNormal3f" );
- dllNormal3f( nx, ny, nz );
+ SIG("glNormal3f");
+ dllNormal3f(nx, ny, nz);
}
static void APIENTRY logNormal3fv(const GLfloat *v)
{
- SIG( "glNormal3fv" );
- dllNormal3fv( v );
+ SIG("glNormal3fv");
+ dllNormal3fv(v);
}
static void APIENTRY logNormalPointer(GLenum type, GLsizei stride, const void *pointer)
{
- SIG( "glNormalPointer" );
- dllNormalPointer( type, stride, pointer );
+ SIG("glNormalPointer");
+ dllNormalPointer(type, stride, pointer);
}
static void APIENTRY logOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
{
- SIG( "glOrtho" );
- dllOrtho( left, right, bottom, top, zNear, zFar );
+ SIG("glOrtho");
+ dllOrtho(left, right, bottom, top, zNear, zFar);
}
static void APIENTRY logPixelStorei(GLenum pname, GLint param)
{
- SIG( "glPixelStorei" );
- dllPixelStorei( pname, param );
+ SIG("glPixelStorei");
+ dllPixelStorei(pname, param);
}
static void APIENTRY logPointSize(GLfloat size)
{
- SIG( "glPointSize" );
- dllPointSize( size );
+ SIG("glPointSize");
+ dllPointSize(size);
}
static void APIENTRY logPolygonMode(GLenum face, GLenum mode)
{
- fprintf( log_fp, "glPolygonMode( 0x%x, 0x%x )\n", face, mode );
- dllPolygonMode( face, mode );
+ fprintf(log_fp, "glPolygonMode( 0x%x, 0x%x )\n", face, mode);
+ dllPolygonMode(face, mode);
}
static void APIENTRY logPolygonOffset(GLfloat factor, GLfloat units)
{
- SIG( "glPolygonOffset" );
- dllPolygonOffset( factor, units );
+ SIG("glPolygonOffset");
+ dllPolygonOffset(factor, units);
}
static void APIENTRY logPopMatrix(void)
{
- SIG( "glPopMatrix" );
+ SIG("glPopMatrix");
dllPopMatrix();
}
static void APIENTRY logPushMatrix(void)
{
- SIG( "glPushMatrix" );
+ SIG("glPushMatrix");
dllPushMatrix();
}
static void APIENTRY logReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels)
{
- SIG( "glReadPixels" );
- dllReadPixels( x, y, width, height, format, type, pixels );
+ SIG("glReadPixels");
+ dllReadPixels(x, y, width, height, format, type, pixels);
}
static void APIENTRY logRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
- SIG( "glRotatef" );
- dllRotatef( angle, x, y, z );
+ SIG("glRotatef");
+ dllRotatef(angle, x, y, z);
}
static void APIENTRY logScalef(GLfloat x, GLfloat y, GLfloat z)
{
- SIG( "glScalef" );
- dllScalef( x, y, z );
+ SIG("glScalef");
+ dllScalef(x, y, z);
}
static void APIENTRY logScissor(GLint x, GLint y, GLsizei width, GLsizei height)
{
- SIG( "glScissor" );
- dllScissor( x, y, width, height );
+ SIG("glScissor");
+ dllScissor(x, y, width, height);
}
static void APIENTRY logShadeModel(GLenum mode)
{
- SIG( "glShadeModel" );
- dllShadeModel( mode );
+ SIG("glShadeModel");
+ dllShadeModel(mode);
}
static void APIENTRY logStencilFunc(GLenum func, GLint ref, GLuint mask)
{
- SIG( "glStencilFunc" );
- dllStencilFunc( func, ref, mask );
+ SIG("glStencilFunc");
+ dllStencilFunc(func, ref, mask);
}
static void APIENTRY logStencilMask(GLuint mask)
{
- SIG( "glStencilMask" );
- dllStencilMask( mask );
+ SIG("glStencilMask");
+ dllStencilMask(mask);
}
static void APIENTRY logStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
{
- SIG( "glStencilOp" );
- dllStencilOp( fail, zfail, zpass );
+ SIG("glStencilOp");
+ dllStencilOp(fail, zfail, zpass);
}
static void APIENTRY logTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
{
- SIG( "glTexCoordPointer" );
- dllTexCoordPointer( size, type, stride, pointer );
+ SIG("glTexCoordPointer");
+ dllTexCoordPointer(size, type, stride, pointer);
}
static void APIENTRY logTexEnvf(GLenum target, GLenum pname, GLfloat param)
{
- fprintf( log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", target, pname, param );
- dllTexEnvf( target, pname, param );
+ fprintf(log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", target, pname, param);
+ dllTexEnvf(target, pname, param);
}
static void APIENTRY logTexEnvfv(GLenum target, GLenum pname, const GLfloat *params)
{
- SIG( "glTexEnvfv" );
- dllTexEnvfv( target, pname, params );
+ SIG("glTexEnvfv");
+ dllTexEnvfv(target, pname, params);
}
static void APIENTRY logTexEnvi(GLenum target, GLenum pname, GLint param)
{
- fprintf( log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", target, pname, param );
- dllTexEnvi( target, pname, param );
+ fprintf(log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", target, pname, param);
+ dllTexEnvi(target, pname, param);
}
static void APIENTRY logTexEnviv(GLenum target, GLenum pname, const GLint *params)
{
- SIG( "glTexEnviv" );
- dllTexEnviv( target, pname, params );
+ SIG("glTexEnviv");
+ dllTexEnviv(target, pname, params);
}
static void APIENTRY logTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
{
- SIG( "glTexImage2D" );
- dllTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
+ SIG("glTexImage2D");
+ dllTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
static void APIENTRY logTexParameterf(GLenum target, GLenum pname, GLfloat param)
{
- fprintf( log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", target, pname, param );
- dllTexParameterf( target, pname, param );
+ fprintf(log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", target, pname, param);
+ dllTexParameterf(target, pname, param);
}
static void APIENTRY logTexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
{
- SIG( "glTexParameterfv" );
- dllTexParameterfv( target, pname, params );
+ SIG("glTexParameterfv");
+ dllTexParameterfv(target, pname, params);
}
static void APIENTRY logTexParameteri(GLenum target, GLenum pname, GLint param)
{
- fprintf( log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", target, pname, param );
- dllTexParameteri( target, pname, param );
+ fprintf(log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", target, pname, param);
+ dllTexParameteri(target, pname, param);
}
static void APIENTRY logTexParameteriv(GLenum target, GLenum pname, const GLint *params)
{
- SIG( "glTexParameteriv" );
- dllTexParameteriv( target, pname, params );
+ SIG("glTexParameteriv");
+ dllTexParameteriv(target, pname, params);
}
static void APIENTRY logTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
{
- SIG( "glTexSubImage2D" );
- dllTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
+ SIG("glTexSubImage2D");
+ dllTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
static void APIENTRY logTranslatef(GLfloat x, GLfloat y, GLfloat z)
{
- SIG( "glTranslatef" );
- dllTranslatef( x, y, z );
+ SIG("glTranslatef");
+ dllTranslatef(x, y, z);
}
static void APIENTRY logVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
{
- SIG( "glVertexPointer" );
- dllVertexPointer( size, type, stride, pointer );
+ SIG("glVertexPointer");
+ dllVertexPointer(size, type, stride, pointer);
}
static void APIENTRY logViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
- SIG( "glViewport" );
- dllViewport( x, y, width, height );
+ SIG("glViewport");
+ dllViewport(x, y, width, height);
}
/*
@@ -837,7 +837,8 @@ static void APIENTRY logViewport(GLint x, GLint y, GLsizei width, GLsizei height
**
** Unloads the specified DLL then nulls out all the proc pointers.
*/
-void QGL_Shutdown( void ) {
+void QGL_Shutdown(void)
+{
qglAlphaFunc = NULL;
qglBindTexture = NULL;
qglBlendFunc = NULL;
@@ -932,21 +933,22 @@ void QGL_Shutdown( void ) {
qglVertexPointer = NULL;
qglViewport = NULL;
- QGL_ShutdownExtensions( ~0 );
+ QGL_ShutdownExtensions(~0);
}
-void QGL_ShutdownExtensions( unsigned mask ) {
- if( mask & QGL_EXT_compiled_vertex_array ) {
+void QGL_ShutdownExtensions(unsigned mask)
+{
+ if (mask & QGL_EXT_compiled_vertex_array) {
qglLockArraysEXT = NULL;
qglUnlockArraysEXT = NULL;
}
- if( mask & QGL_ARB_multitexture ) {
+ if (mask & QGL_ARB_multitexture) {
qglActiveTextureARB = NULL;
qglClientActiveTextureARB = NULL;
}
- if( mask & QGL_ARB_fragment_program ) {
+ if (mask & QGL_ARB_fragment_program) {
qglProgramStringARB = NULL;
qglBindProgramARB = NULL;
qglDeleteProgramsARB = NULL;
@@ -960,7 +962,7 @@ void QGL_ShutdownExtensions( unsigned mask ) {
qglIsProgramARB = NULL;
}
- if( mask & QGL_ARB_vertex_buffer_object ) {
+ if (mask & QGL_ARB_vertex_buffer_object) {
qglBindBufferARB = NULL;
qglDeleteBuffersARB = NULL;
qglGenBuffersARB = NULL;
@@ -975,7 +977,7 @@ void QGL_ShutdownExtensions( unsigned mask ) {
}
}
-#define GPA( a ) VID_GetProcAddr( a )
+#define GPA(a) VID_GetProcAddr(a)
/*
** QGL_Init
@@ -987,151 +989,154 @@ void QGL_ShutdownExtensions( unsigned mask ) {
** might be.
**
*/
-void QGL_Init( void ) {
- qglAlphaFunc = dllAlphaFunc = GPA( "glAlphaFunc" );
- qglBindTexture = dllBindTexture = GPA( "glBindTexture" );
- qglBlendFunc = dllBlendFunc = GPA( "glBlendFunc" );
- qglClear = dllClear = GPA( "glClear" );
- qglClearColor = dllClearColor = GPA( "glClearColor" );
- qglClearDepth = dllClearDepth = GPA( "glClearDepth" );
- qglClearIndex = dllClearIndex = GPA( "glClearIndex" );
- qglClearStencil = dllClearStencil = GPA( "glClearStencil" );
- qglColor4f = dllColor4f = GPA( "glColor4f" );
- qglColor4fv = dllColor4fv = GPA( "glColor4fv" );
- qglColor4ub = dllColor4ub = GPA( "glColor4ub" );
- qglColor4ubv = dllColor4ubv = GPA( "glColor4ubv" );
- qglColorMask = dllColorMask = GPA( "glColorMask" );
- qglColorPointer = dllColorPointer = GPA( "glColorPointer" );
- qglCopyTexImage2D = dllCopyTexImage2D = GPA( "glCopyTexImage2D" );
- qglCopyTexSubImage2D = dllCopyTexSubImage2D = GPA( "glCopyTexSubImage2D" );
- qglCullFace = dllCullFace = GPA( "glCullFace" );
- qglDeleteTextures = dllDeleteTextures = GPA( "glDeleteTextures" );
- qglDepthFunc = dllDepthFunc = GPA( "glDepthFunc" );
- qglDepthMask = dllDepthMask = GPA( "glDepthMask" );
- qglDepthRange = dllDepthRange = GPA( "glDepthRange" );
- qglDisable = dllDisable = GPA( "glDisable" );
- qglDisableClientState = dllDisableClientState = GPA( "glDisableClientState" );
- qglDrawArrays = dllDrawArrays = GPA( "glDrawArrays" );
- qglDrawElements = dllDrawElements = GPA( "glDrawElements" );
- qglEnable = dllEnable = GPA( "glEnable" );
- qglEnableClientState = dllEnableClientState = GPA( "glEnableClientState" );
- qglFinish = dllFinish = GPA( "glFinish" );
- qglFlush = dllFlush = GPA( "glFlush" );
- qglFogf = dllFogf = GPA( "glFogf" );
- qglFogfv = dllFogfv = GPA( "glFogfv" );
- qglFrontFace = dllFrontFace = GPA( "glFrontFace" );
- qglFrustum = dllFrustum = GPA( "glFrustum" );
- qglGenTextures = dllGenTextures = GPA( "glGenTextures" );
- qglGetBooleanv = dllGetBooleanv = GPA( "glGetBooleanv" );
- qglGetError = dllGetError = GPA( "glGetError" );
- qglGetFloatv = dllGetFloatv = GPA( "glGetFloatv" );
- qglGetIntegerv = dllGetIntegerv = GPA( "glGetIntegerv" );
- qglGetLightfv = dllGetLightfv = GPA( "glGetLightfv" );
- qglGetMaterialfv = dllGetMaterialfv = GPA( "glGetMaterialfv" );
- qglGetPointerv = dllGetPointerv = GPA( "glGetPointerv" );
- qglGetString = dllGetString = GPA( "glGetString" );
- qglGetTexEnvfv = dllGetTexEnvfv = GPA( "glGetTexEnvfv" );
- qglGetTexEnviv = dllGetTexEnviv = GPA( "glGetTexEnviv" );
- qglGetTexParameterfv = dllGetTexParameterfv = GPA( "glGetTexParameterfv" );
- qglGetTexParameteriv = dllGetTexParameteriv = GPA( "glGetTexParameteriv" );
- qglHint = dllHint = GPA( "glHint" );
- qglIsEnabled = dllIsEnabled = GPA( "glIsEnabled" );
- qglIsTexture = dllIsTexture = GPA( "glIsTexture" );
- qglLightModelf = dllLightModelf = GPA( "glLightModelf" );
- qglLightModelfv = dllLightModelfv = GPA( "glLightModelfv" );
- qglLightf = dllLightf = GPA( "glLightf" );
- qglLightfv = dllLightfv = GPA( "glLightfv" );
- qglLineWidth = dllLineWidth = GPA( "glLineWidth" );
- qglLoadIdentity = dllLoadIdentity = GPA( "glLoadIdentity" );
- qglLoadMatrixf = dllLoadMatrixf = GPA( "glLoadMatrixf" );
- qglLogicOp = dllLogicOp = GPA( "glLogicOp" );
- qglMaterialf = dllMaterialf = GPA( "glMaterialf" );
- qglMaterialfv = dllMaterialfv = GPA( "glMaterialfv" );
- qglMatrixMode = dllMatrixMode = GPA( "glMatrixMode" );
- qglMultMatrixf = dllMultMatrixf = GPA( "glMultMatrixf" );
- qglNormal3f = dllNormal3f = GPA( "glNormal3f" );
- qglNormal3fv = dllNormal3fv = GPA( "glNormal3fv" );
- qglNormalPointer = dllNormalPointer = GPA( "glNormalPointer" );
- qglOrtho = dllOrtho = GPA( "glOrtho" );
- qglPixelStorei = dllPixelStorei = GPA( "glPixelStorei" );
- qglPointSize = dllPointSize = GPA( "glPointSize" );
- qglPolygonMode = dllPolygonMode = GPA( "glPolygonMode" );
- qglPolygonOffset = dllPolygonOffset = GPA( "glPolygonOffset" );
- qglPopMatrix = dllPopMatrix = GPA( "glPopMatrix" );
- qglPushMatrix = dllPushMatrix = GPA( "glPushMatrix" );
- qglReadPixels = dllReadPixels = GPA( "glReadPixels" );
- qglRotatef = dllRotatef = GPA( "glRotatef" );
- qglScalef = dllScalef = GPA( "glScalef" );
- qglScissor = dllScissor = GPA( "glScissor" );
- qglShadeModel = dllShadeModel = GPA( "glShadeModel" );
- qglStencilFunc = dllStencilFunc = GPA( "glStencilFunc" );
- qglStencilMask = dllStencilMask = GPA( "glStencilMask" );
- qglStencilOp = dllStencilOp = GPA( "glStencilOp" );
- qglTexCoordPointer = dllTexCoordPointer = GPA( "glTexCoordPointer" );
- qglTexEnvf = dllTexEnvf = GPA( "glTexEnvf" );
- qglTexEnvfv = dllTexEnvfv = GPA( "glTexEnvfv" );
- qglTexEnvi = dllTexEnvi = GPA( "glTexEnvi" );
- qglTexEnviv = dllTexEnviv = GPA( "glTexEnviv" );
- qglTexImage2D = dllTexImage2D = GPA( "glTexImage2D" );
- qglTexParameterf = dllTexParameterf = GPA( "glTexParameterf" );
- qglTexParameterfv = dllTexParameterfv = GPA( "glTexParameterfv" );
- qglTexParameteri = dllTexParameteri = GPA( "glTexParameteri" );
- qglTexParameteriv = dllTexParameteriv = GPA( "glTexParameteriv" );
- qglTexSubImage2D = dllTexSubImage2D = GPA( "glTexSubImage2D" );
- qglTranslatef = dllTranslatef = GPA( "glTranslatef" );
- qglVertexPointer = dllVertexPointer = GPA( "glVertexPointer" );
- qglViewport = dllViewport = GPA( "glViewport" );
+void QGL_Init(void)
+{
+ qglAlphaFunc = dllAlphaFunc = GPA("glAlphaFunc");
+ qglBindTexture = dllBindTexture = GPA("glBindTexture");
+ qglBlendFunc = dllBlendFunc = GPA("glBlendFunc");
+ qglClear = dllClear = GPA("glClear");
+ qglClearColor = dllClearColor = GPA("glClearColor");
+ qglClearDepth = dllClearDepth = GPA("glClearDepth");
+ qglClearIndex = dllClearIndex = GPA("glClearIndex");
+ qglClearStencil = dllClearStencil = GPA("glClearStencil");
+ qglColor4f = dllColor4f = GPA("glColor4f");
+ qglColor4fv = dllColor4fv = GPA("glColor4fv");
+ qglColor4ub = dllColor4ub = GPA("glColor4ub");
+ qglColor4ubv = dllColor4ubv = GPA("glColor4ubv");
+ qglColorMask = dllColorMask = GPA("glColorMask");
+ qglColorPointer = dllColorPointer = GPA("glColorPointer");
+ qglCopyTexImage2D = dllCopyTexImage2D = GPA("glCopyTexImage2D");
+ qglCopyTexSubImage2D = dllCopyTexSubImage2D = GPA("glCopyTexSubImage2D");
+ qglCullFace = dllCullFace = GPA("glCullFace");
+ qglDeleteTextures = dllDeleteTextures = GPA("glDeleteTextures");
+ qglDepthFunc = dllDepthFunc = GPA("glDepthFunc");
+ qglDepthMask = dllDepthMask = GPA("glDepthMask");
+ qglDepthRange = dllDepthRange = GPA("glDepthRange");
+ qglDisable = dllDisable = GPA("glDisable");
+ qglDisableClientState = dllDisableClientState = GPA("glDisableClientState");
+ qglDrawArrays = dllDrawArrays = GPA("glDrawArrays");
+ qglDrawElements = dllDrawElements = GPA("glDrawElements");
+ qglEnable = dllEnable = GPA("glEnable");
+ qglEnableClientState = dllEnableClientState = GPA("glEnableClientState");
+ qglFinish = dllFinish = GPA("glFinish");
+ qglFlush = dllFlush = GPA("glFlush");
+ qglFogf = dllFogf = GPA("glFogf");
+ qglFogfv = dllFogfv = GPA("glFogfv");
+ qglFrontFace = dllFrontFace = GPA("glFrontFace");
+ qglFrustum = dllFrustum = GPA("glFrustum");
+ qglGenTextures = dllGenTextures = GPA("glGenTextures");
+ qglGetBooleanv = dllGetBooleanv = GPA("glGetBooleanv");
+ qglGetError = dllGetError = GPA("glGetError");
+ qglGetFloatv = dllGetFloatv = GPA("glGetFloatv");
+ qglGetIntegerv = dllGetIntegerv = GPA("glGetIntegerv");
+ qglGetLightfv = dllGetLightfv = GPA("glGetLightfv");
+ qglGetMaterialfv = dllGetMaterialfv = GPA("glGetMaterialfv");
+ qglGetPointerv = dllGetPointerv = GPA("glGetPointerv");
+ qglGetString = dllGetString = GPA("glGetString");
+ qglGetTexEnvfv = dllGetTexEnvfv = GPA("glGetTexEnvfv");
+ qglGetTexEnviv = dllGetTexEnviv = GPA("glGetTexEnviv");
+ qglGetTexParameterfv = dllGetTexParameterfv = GPA("glGetTexParameterfv");
+ qglGetTexParameteriv = dllGetTexParameteriv = GPA("glGetTexParameteriv");
+ qglHint = dllHint = GPA("glHint");
+ qglIsEnabled = dllIsEnabled = GPA("glIsEnabled");
+ qglIsTexture = dllIsTexture = GPA("glIsTexture");
+ qglLightModelf = dllLightModelf = GPA("glLightModelf");
+ qglLightModelfv = dllLightModelfv = GPA("glLightModelfv");
+ qglLightf = dllLightf = GPA("glLightf");
+ qglLightfv = dllLightfv = GPA("glLightfv");
+ qglLineWidth = dllLineWidth = GPA("glLineWidth");
+ qglLoadIdentity = dllLoadIdentity = GPA("glLoadIdentity");
+ qglLoadMatrixf = dllLoadMatrixf = GPA("glLoadMatrixf");
+ qglLogicOp = dllLogicOp = GPA("glLogicOp");
+ qglMaterialf = dllMaterialf = GPA("glMaterialf");
+ qglMaterialfv = dllMaterialfv = GPA("glMaterialfv");
+ qglMatrixMode = dllMatrixMode = GPA("glMatrixMode");
+ qglMultMatrixf = dllMultMatrixf = GPA("glMultMatrixf");
+ qglNormal3f = dllNormal3f = GPA("glNormal3f");
+ qglNormal3fv = dllNormal3fv = GPA("glNormal3fv");
+ qglNormalPointer = dllNormalPointer = GPA("glNormalPointer");
+ qglOrtho = dllOrtho = GPA("glOrtho");
+ qglPixelStorei = dllPixelStorei = GPA("glPixelStorei");
+ qglPointSize = dllPointSize = GPA("glPointSize");
+ qglPolygonMode = dllPolygonMode = GPA("glPolygonMode");
+ qglPolygonOffset = dllPolygonOffset = GPA("glPolygonOffset");
+ qglPopMatrix = dllPopMatrix = GPA("glPopMatrix");
+ qglPushMatrix = dllPushMatrix = GPA("glPushMatrix");
+ qglReadPixels = dllReadPixels = GPA("glReadPixels");
+ qglRotatef = dllRotatef = GPA("glRotatef");
+ qglScalef = dllScalef = GPA("glScalef");
+ qglScissor = dllScissor = GPA("glScissor");
+ qglShadeModel = dllShadeModel = GPA("glShadeModel");
+ qglStencilFunc = dllStencilFunc = GPA("glStencilFunc");
+ qglStencilMask = dllStencilMask = GPA("glStencilMask");
+ qglStencilOp = dllStencilOp = GPA("glStencilOp");
+ qglTexCoordPointer = dllTexCoordPointer = GPA("glTexCoordPointer");
+ qglTexEnvf = dllTexEnvf = GPA("glTexEnvf");
+ qglTexEnvfv = dllTexEnvfv = GPA("glTexEnvfv");
+ qglTexEnvi = dllTexEnvi = GPA("glTexEnvi");
+ qglTexEnviv = dllTexEnviv = GPA("glTexEnviv");
+ qglTexImage2D = dllTexImage2D = GPA("glTexImage2D");
+ qglTexParameterf = dllTexParameterf = GPA("glTexParameterf");
+ qglTexParameterfv = dllTexParameterfv = GPA("glTexParameterfv");
+ qglTexParameteri = dllTexParameteri = GPA("glTexParameteri");
+ qglTexParameteriv = dllTexParameteriv = GPA("glTexParameteriv");
+ qglTexSubImage2D = dllTexSubImage2D = GPA("glTexSubImage2D");
+ qglTranslatef = dllTranslatef = GPA("glTranslatef");
+ qglVertexPointer = dllVertexPointer = GPA("glVertexPointer");
+ qglViewport = dllViewport = GPA("glViewport");
}
#ifdef _WIN32
// hack, use ICD function for obtaining extensions
#undef GPA
-#define GPA( a ) ( void * )qwglGetProcAddress( a )
+#define GPA(a) (void *)qwglGetProcAddress(a)
#endif
-void QGL_InitExtensions( unsigned mask ) {
- if( mask & QGL_EXT_compiled_vertex_array ) {
- qglLockArraysEXT = GPA( "glLockArraysEXT" );
- qglUnlockArraysEXT = GPA( "glUnlockArraysEXT" );
+void QGL_InitExtensions(unsigned mask)
+{
+ if (mask & QGL_EXT_compiled_vertex_array) {
+ qglLockArraysEXT = GPA("glLockArraysEXT");
+ qglUnlockArraysEXT = GPA("glUnlockArraysEXT");
}
- if( mask & QGL_ARB_multitexture ) {
- qglActiveTextureARB = GPA( "glActiveTextureARB" );
- qglClientActiveTextureARB = GPA( "glClientActiveTextureARB" );
+ if (mask & QGL_ARB_multitexture) {
+ qglActiveTextureARB = GPA("glActiveTextureARB");
+ qglClientActiveTextureARB = GPA("glClientActiveTextureARB");
}
- if( mask & QGL_ARB_fragment_program ) {
- qglProgramStringARB = GPA( "glProgramStringARB" );
- qglBindProgramARB = GPA( "glBindProgramARB" );
- qglDeleteProgramsARB = GPA( "glDeleteProgramsARB" );
- qglGenProgramsARB = GPA( "glGenProgramsARB" );
- qglProgramEnvParameter4fvARB = GPA( "glProgramEnvParameter4fvARB" );
- qglProgramLocalParameter4fvARB = GPA( "glProgramLocalParameter4fvARB" );
- qglGetProgramEnvParameterfvARB = GPA( "glGetProgramEnvParameterfvARB" );
- qglGetProgramLocalParameterfvARB = GPA( "glGetProgramLocalParameterfvARB" );
- qglGetProgramivARB = GPA( "glGetProgramivARB" );
- qglGetProgramStringARB = GPA( "glGetProgramStringARB" );
- qglIsProgramARB = GPA( "glIsProgramARB" );
+ if (mask & QGL_ARB_fragment_program) {
+ qglProgramStringARB = GPA("glProgramStringARB");
+ qglBindProgramARB = GPA("glBindProgramARB");
+ qglDeleteProgramsARB = GPA("glDeleteProgramsARB");
+ qglGenProgramsARB = GPA("glGenProgramsARB");
+ qglProgramEnvParameter4fvARB = GPA("glProgramEnvParameter4fvARB");
+ qglProgramLocalParameter4fvARB = GPA("glProgramLocalParameter4fvARB");
+ qglGetProgramEnvParameterfvARB = GPA("glGetProgramEnvParameterfvARB");
+ qglGetProgramLocalParameterfvARB = GPA("glGetProgramLocalParameterfvARB");
+ qglGetProgramivARB = GPA("glGetProgramivARB");
+ qglGetProgramStringARB = GPA("glGetProgramStringARB");
+ qglIsProgramARB = GPA("glIsProgramARB");
}
- if( mask & QGL_ARB_vertex_buffer_object ) {
- qglBindBufferARB = GPA( "glBindBufferARB" );
- qglDeleteBuffersARB = GPA( "glDeleteBuffersARB" );
- qglGenBuffersARB = GPA( "glGenBuffersARB" );
- qglIsBufferARB = GPA( "glIsBufferARB" );
- qglBufferDataARB = GPA( "glBufferDataARB" );
- qglBufferSubDataARB = GPA( "glBufferSubDataARB" );
- qglGetBufferSubDataARB = GPA( "glGetBufferSubDataARB" );
- qglMapBufferARB = GPA( "glMapBufferARB" );
- qglUnmapBufferARB = GPA( "glUnmapBufferARB" );
- qglGetBufferParameterivARB = GPA( "glGetBufferParameterivARB" );
- qglGetBufferPointervARB = GPA( "glGetBufferPointervARB" );
+ if (mask & QGL_ARB_vertex_buffer_object) {
+ qglBindBufferARB = GPA("glBindBufferARB");
+ qglDeleteBuffersARB = GPA("glDeleteBuffersARB");
+ qglGenBuffersARB = GPA("glGenBuffersARB");
+ qglIsBufferARB = GPA("glIsBufferARB");
+ qglBufferDataARB = GPA("glBufferDataARB");
+ qglBufferSubDataARB = GPA("glBufferSubDataARB");
+ qglGetBufferSubDataARB = GPA("glGetBufferSubDataARB");
+ qglMapBufferARB = GPA("glMapBufferARB");
+ qglUnmapBufferARB = GPA("glUnmapBufferARB");
+ qglGetBufferParameterivARB = GPA("glGetBufferParameterivARB");
+ qglGetBufferPointervARB = GPA("glGetBufferPointervARB");
}
}
#undef GPA
-unsigned QGL_ParseExtensionString( const char *s ) {
+unsigned QGL_ParseExtensionString(const char *s)
+{
// must match defines in qgl_api.h!
static const char *const extnames[] = {
"GL_EXT_compiled_vertex_array",
@@ -1142,35 +1147,33 @@ unsigned QGL_ParseExtensionString( const char *s ) {
NULL
};
- return Com_ParseExtensionString( s, extnames );
+ return Com_ParseExtensionString(s, extnames);
}
-void QGL_EnableLogging( qboolean enable )
+void QGL_EnableLogging(qboolean enable)
{
- if ( enable )
- {
- if ( !log_fp )
- {
+ if (enable) {
+ if (!log_fp) {
extern char fs_gamedir[];
struct tm *newtime;
time_t aclock;
char buffer[MAX_OSPATH];
size_t len;
- time( &aclock );
+ time(&aclock);
- len = Q_snprintf( buffer, sizeof( buffer ), "%s/qgl.log", fs_gamedir );
- if( len >= sizeof( buffer ) ) {
+ len = Q_snprintf(buffer, sizeof(buffer), "%s/qgl.log", fs_gamedir);
+ if (len >= sizeof(buffer)) {
return;
}
- log_fp = fopen( buffer, "w" );
- if( !log_fp ) {
+ log_fp = fopen(buffer, "w");
+ if (!log_fp) {
return;
}
- newtime = localtime( &aclock );
- fprintf( log_fp, "%s\n", asctime( newtime ) );
+ newtime = localtime(&aclock);
+ fprintf(log_fp, "%s\n", asctime(newtime));
}
qglAlphaFunc = logAlphaFunc;
@@ -1266,12 +1269,10 @@ void QGL_EnableLogging( qboolean enable )
qglTranslatef = logTranslatef;
qglVertexPointer = logVertexPointer;
qglViewport = logViewport;
- }
- else
- {
- if( log_fp ) {
- fclose( log_fp );
- log_fp= NULL;
+ } else {
+ if (log_fp) {
+ fclose(log_fp);
+ log_fp = NULL;
}
qglAlphaFunc = dllAlphaFunc;
@@ -1370,10 +1371,10 @@ void QGL_EnableLogging( qboolean enable )
}
}
-void QGL_LogNewFrame( void )
+void QGL_LogNewFrame(void)
{
- if( log_fp ) {
- fprintf( log_fp, "\n*** NewFrame ***\n" );
+ if (log_fp) {
+ fprintf(log_fp, "\n*** NewFrame ***\n");
}
}
diff --git a/src/qgl_api.h b/src/qgl_api.h
index f2753f3..62cb707 100644
--- a/src/qgl_api.h
+++ b/src/qgl_api.h
@@ -30,145 +30,145 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define QGL_ARB_fragment_program (1<<3)
#define QGL_ARB_vertex_buffer_object (1<<4)
-void QGL_Init( void );
-void QGL_Shutdown( void );
-void QGL_InitExtensions( unsigned mask );
-void QGL_ShutdownExtensions( unsigned mask );
-unsigned QGL_ParseExtensionString( const char *s );
-void QGL_EnableLogging( qboolean enable );
-void QGL_LogNewFrame( void );
-
-extern void ( APIENTRY * qglAlphaFunc )(GLenum func, GLclampf ref);
-extern void ( APIENTRY * qglBindTexture )(GLenum target, GLuint texture);
-extern void ( APIENTRY * qglBlendFunc )(GLenum sfactor, GLenum dfactor);
-extern void ( APIENTRY * qglClear )(GLbitfield mask);
-extern void ( APIENTRY * qglClearColor )(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-extern void ( APIENTRY * qglClearDepth )(GLclampd depth);
-extern void ( APIENTRY * qglClearIndex )(GLfloat c);
-extern void ( APIENTRY * qglClearStencil )(GLint s);
-extern void ( APIENTRY * qglColor4f )(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-extern void ( APIENTRY * qglColor4fv )(const GLfloat *v);
-extern void ( APIENTRY * qglColor4ub )(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-extern void ( APIENTRY * qglColor4ubv )(const GLubyte *v);
-extern void ( APIENTRY * qglColorMask )(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-extern void ( APIENTRY * qglColorPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-extern void ( APIENTRY * qglCopyTexImage2D )(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
-extern void ( APIENTRY * qglCopyTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
-extern void ( APIENTRY * qglCullFace )(GLenum mode);
-extern void ( APIENTRY * qglDeleteTextures )(GLsizei n, const GLuint *textures);
-extern void ( APIENTRY * qglDepthFunc )(GLenum func);
-extern void ( APIENTRY * qglDepthMask )(GLboolean flag);
-extern void ( APIENTRY * qglDepthRange )(GLclampd zNear, GLclampd zFar);
-extern void ( APIENTRY * qglDisable )(GLenum cap);
-extern void ( APIENTRY * qglDisableClientState )(GLenum array);
-extern void ( APIENTRY * qglDrawArrays )(GLenum mode, GLint first, GLsizei count);
-extern void ( APIENTRY * qglDrawElements )(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
-extern void ( APIENTRY * qglEnable )(GLenum cap);
-extern void ( APIENTRY * qglEnableClientState )(GLenum array);
-extern void ( APIENTRY * qglFinish )(void);
-extern void ( APIENTRY * qglFlush )(void);
-extern void ( APIENTRY * qglFogf )(GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglFogfv )(GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglFrontFace )(GLenum mode);
-extern void ( APIENTRY * qglFrustum )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-extern void ( APIENTRY * qglGenTextures )(GLsizei n, GLuint *textures);
-extern void ( APIENTRY * qglGetBooleanv )(GLenum pname, GLboolean *params);
-extern GLenum ( APIENTRY * qglGetError )(void);
-extern void ( APIENTRY * qglGetFloatv )(GLenum pname, GLfloat *params);
-extern void ( APIENTRY * qglGetIntegerv )(GLenum pname, GLint *params);
-extern void ( APIENTRY * qglGetLightfv )(GLenum light, GLenum pname, GLfloat *params);
-extern void ( APIENTRY * qglGetMaterialfv )(GLenum face, GLenum pname, GLfloat *params);
-extern void ( APIENTRY * qglGetPointerv )(GLenum pname, GLvoid* *params);
-extern const GLubyte * ( APIENTRY * qglGetString )(GLenum name);
-extern void ( APIENTRY * qglGetTexEnvfv )(GLenum target, GLenum pname, GLfloat *params);
-extern void ( APIENTRY * qglGetTexEnviv )(GLenum target, GLenum pname, GLint *params);
-extern void ( APIENTRY * qglGetTexParameterfv )(GLenum target, GLenum pname, GLfloat *params);
-extern void ( APIENTRY * qglGetTexParameteriv )(GLenum target, GLenum pname, GLint *params);
-extern void ( APIENTRY * qglHint )(GLenum target, GLenum mode);
-extern GLboolean ( APIENTRY * qglIsEnabled )(GLenum cap);
-extern GLboolean ( APIENTRY * qglIsTexture )(GLuint texture);
-extern void ( APIENTRY * qglLightModelf )(GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglLightModelfv )(GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglLightf )(GLenum light, GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglLightfv )(GLenum light, GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglLineWidth )(GLfloat width);
-extern void ( APIENTRY * qglLoadIdentity )(void);
-extern void ( APIENTRY * qglLoadMatrixf )(const GLfloat *m);
-extern void ( APIENTRY * qglLogicOp )(GLenum opcode);
-extern void ( APIENTRY * qglMaterialf )(GLenum face, GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglMaterialfv )(GLenum face, GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglMatrixMode )(GLenum mode);
-extern void ( APIENTRY * qglMultMatrixf )(const GLfloat *m);
-extern void ( APIENTRY * qglNormal3f )(GLfloat nx, GLfloat ny, GLfloat nz);
-extern void ( APIENTRY * qglNormal3fv )(const GLfloat *v);
-extern void ( APIENTRY * qglNormalPointer )(GLenum type, GLsizei stride, const GLvoid *pointer);
-extern void ( APIENTRY * qglOrtho )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-extern void ( APIENTRY * qglPixelStorei )(GLenum pname, GLint param);
-extern void ( APIENTRY * qglPointSize )(GLfloat size);
-extern void ( APIENTRY * qglPolygonMode )(GLenum face, GLenum mode);
-extern void ( APIENTRY * qglPolygonOffset )(GLfloat factor, GLfloat units);
-extern void ( APIENTRY * qglPopMatrix )(void);
-extern void ( APIENTRY * qglPushMatrix )(void);
-extern void ( APIENTRY * qglReadPixels )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
-extern void ( APIENTRY * qglRotatef )(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-extern void ( APIENTRY * qglScalef )(GLfloat x, GLfloat y, GLfloat z);
-extern void ( APIENTRY * qglScissor )(GLint x, GLint y, GLsizei width, GLsizei height);
-extern void ( APIENTRY * qglShadeModel )(GLenum mode);
-extern void ( APIENTRY * qglStencilFunc )(GLenum func, GLint ref, GLuint mask);
-extern void ( APIENTRY * qglStencilMask )(GLuint mask);
-extern void ( APIENTRY * qglStencilOp )(GLenum fail, GLenum zfail, GLenum zpass);
-extern void ( APIENTRY * qglTexCoordPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-extern void ( APIENTRY * qglTexEnvf )(GLenum target, GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglTexEnvfv )(GLenum target, GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglTexEnvi )(GLenum target, GLenum pname, GLint param);
-extern void ( APIENTRY * qglTexEnviv )(GLenum target, GLenum pname, const GLint *params);
-extern void ( APIENTRY * qglTexImage2D )(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-extern void ( APIENTRY * qglTexParameterf )(GLenum target, GLenum pname, GLfloat param);
-extern void ( APIENTRY * qglTexParameterfv )(GLenum target, GLenum pname, const GLfloat *params);
-extern void ( APIENTRY * qglTexParameteri )(GLenum target, GLenum pname, GLint param);
-extern void ( APIENTRY * qglTexParameteriv )(GLenum target, GLenum pname, const GLint *params);
-extern void ( APIENTRY * qglTexSubImage2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
-extern void ( APIENTRY * qglTranslatef )(GLfloat x, GLfloat y, GLfloat z);
-extern void ( APIENTRY * qglVertexPointer )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-extern void ( APIENTRY * qglViewport )(GLint x, GLint y, GLsizei width, GLsizei height);
+void QGL_Init(void);
+void QGL_Shutdown(void);
+void QGL_InitExtensions(unsigned mask);
+void QGL_ShutdownExtensions(unsigned mask);
+unsigned QGL_ParseExtensionString(const char *s);
+void QGL_EnableLogging(qboolean enable);
+void QGL_LogNewFrame(void);
+
+extern void (APIENTRY * qglAlphaFunc)(GLenum func, GLclampf ref);
+extern void (APIENTRY * qglBindTexture)(GLenum target, GLuint texture);
+extern void (APIENTRY * qglBlendFunc)(GLenum sfactor, GLenum dfactor);
+extern void (APIENTRY * qglClear)(GLbitfield mask);
+extern void (APIENTRY * qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+extern void (APIENTRY * qglClearDepth)(GLclampd depth);
+extern void (APIENTRY * qglClearIndex)(GLfloat c);
+extern void (APIENTRY * qglClearStencil)(GLint s);
+extern void (APIENTRY * qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+extern void (APIENTRY * qglColor4fv)(const GLfloat *v);
+extern void (APIENTRY * qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
+extern void (APIENTRY * qglColor4ubv)(const GLubyte *v);
+extern void (APIENTRY * qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+extern void (APIENTRY * qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+extern void (APIENTRY * qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+extern void (APIENTRY * qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+extern void (APIENTRY * qglCullFace)(GLenum mode);
+extern void (APIENTRY * qglDeleteTextures)(GLsizei n, const GLuint *textures);
+extern void (APIENTRY * qglDepthFunc)(GLenum func);
+extern void (APIENTRY * qglDepthMask)(GLboolean flag);
+extern void (APIENTRY * qglDepthRange)(GLclampd zNear, GLclampd zFar);
+extern void (APIENTRY * qglDisable)(GLenum cap);
+extern void (APIENTRY * qglDisableClientState)(GLenum array);
+extern void (APIENTRY * qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
+extern void (APIENTRY * qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+extern void (APIENTRY * qglEnable)(GLenum cap);
+extern void (APIENTRY * qglEnableClientState)(GLenum array);
+extern void (APIENTRY * qglFinish)(void);
+extern void (APIENTRY * qglFlush)(void);
+extern void (APIENTRY * qglFogf)(GLenum pname, GLfloat param);
+extern void (APIENTRY * qglFogfv)(GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglFrontFace)(GLenum mode);
+extern void (APIENTRY * qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+extern void (APIENTRY * qglGenTextures)(GLsizei n, GLuint *textures);
+extern void (APIENTRY * qglGetBooleanv)(GLenum pname, GLboolean *params);
+extern GLenum (APIENTRY * qglGetError)(void);
+extern void (APIENTRY * qglGetFloatv)(GLenum pname, GLfloat *params);
+extern void (APIENTRY * qglGetIntegerv)(GLenum pname, GLint *params);
+extern void (APIENTRY * qglGetLightfv)(GLenum light, GLenum pname, GLfloat *params);
+extern void (APIENTRY * qglGetMaterialfv)(GLenum face, GLenum pname, GLfloat *params);
+extern void (APIENTRY * qglGetPointerv)(GLenum pname, GLvoid* *params);
+extern const GLubyte * (APIENTRY * qglGetString)(GLenum name);
+extern void (APIENTRY * qglGetTexEnvfv)(GLenum target, GLenum pname, GLfloat *params);
+extern void (APIENTRY * qglGetTexEnviv)(GLenum target, GLenum pname, GLint *params);
+extern void (APIENTRY * qglGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
+extern void (APIENTRY * qglGetTexParameteriv)(GLenum target, GLenum pname, GLint *params);
+extern void (APIENTRY * qglHint)(GLenum target, GLenum mode);
+extern GLboolean (APIENTRY * qglIsEnabled)(GLenum cap);
+extern GLboolean (APIENTRY * qglIsTexture)(GLuint texture);
+extern void (APIENTRY * qglLightModelf)(GLenum pname, GLfloat param);
+extern void (APIENTRY * qglLightModelfv)(GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglLightf)(GLenum light, GLenum pname, GLfloat param);
+extern void (APIENTRY * qglLightfv)(GLenum light, GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglLineWidth)(GLfloat width);
+extern void (APIENTRY * qglLoadIdentity)(void);
+extern void (APIENTRY * qglLoadMatrixf)(const GLfloat *m);
+extern void (APIENTRY * qglLogicOp)(GLenum opcode);
+extern void (APIENTRY * qglMaterialf)(GLenum face, GLenum pname, GLfloat param);
+extern void (APIENTRY * qglMaterialfv)(GLenum face, GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglMatrixMode)(GLenum mode);
+extern void (APIENTRY * qglMultMatrixf)(const GLfloat *m);
+extern void (APIENTRY * qglNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz);
+extern void (APIENTRY * qglNormal3fv)(const GLfloat *v);
+extern void (APIENTRY * qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer);
+extern void (APIENTRY * qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+extern void (APIENTRY * qglPixelStorei)(GLenum pname, GLint param);
+extern void (APIENTRY * qglPointSize)(GLfloat size);
+extern void (APIENTRY * qglPolygonMode)(GLenum face, GLenum mode);
+extern void (APIENTRY * qglPolygonOffset)(GLfloat factor, GLfloat units);
+extern void (APIENTRY * qglPopMatrix)(void);
+extern void (APIENTRY * qglPushMatrix)(void);
+extern void (APIENTRY * qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
+extern void (APIENTRY * qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+extern void (APIENTRY * qglScalef)(GLfloat x, GLfloat y, GLfloat z);
+extern void (APIENTRY * qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
+extern void (APIENTRY * qglShadeModel)(GLenum mode);
+extern void (APIENTRY * qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
+extern void (APIENTRY * qglStencilMask)(GLuint mask);
+extern void (APIENTRY * qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
+extern void (APIENTRY * qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+extern void (APIENTRY * qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
+extern void (APIENTRY * qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglTexEnvi)(GLenum target, GLenum pname, GLint param);
+extern void (APIENTRY * qglTexEnviv)(GLenum target, GLenum pname, const GLint *params);
+extern void (APIENTRY * qglTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+extern void (APIENTRY * qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
+extern void (APIENTRY * qglTexParameterfv)(GLenum target, GLenum pname, const GLfloat *params);
+extern void (APIENTRY * qglTexParameteri)(GLenum target, GLenum pname, GLint param);
+extern void (APIENTRY * qglTexParameteriv)(GLenum target, GLenum pname, const GLint *params);
+extern void (APIENTRY * qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+extern void (APIENTRY * qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
+extern void (APIENTRY * qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+extern void (APIENTRY * qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
//
// extensions
//
// GL_EXT_compiled_vertex_array
-extern void ( APIENTRY * qglLockArraysEXT )(GLint first, GLsizei count);
-extern void ( APIENTRY * qglUnlockArraysEXT )(void);
+extern void (APIENTRY * qglLockArraysEXT)(GLint first, GLsizei count);
+extern void (APIENTRY * qglUnlockArraysEXT)(void);
// GL_ARB_multitexture
-extern void ( APIENTRY * qglActiveTextureARB )(GLenum texture);
-extern void ( APIENTRY * qglClientActiveTextureARB )(GLenum texture);
+extern void (APIENTRY * qglActiveTextureARB)(GLenum texture);
+extern void (APIENTRY * qglClientActiveTextureARB)(GLenum texture);
// GL_ARB_fragment_program
-extern void ( APIENTRY * qglProgramStringARB )(GLenum target, GLenum format, GLsizei len, const GLvoid *string);
-extern void ( APIENTRY * qglBindProgramARB )(GLenum target, GLuint program);
-extern void ( APIENTRY * qglDeleteProgramsARB )(GLsizei n, const GLuint *programs);
-extern void ( APIENTRY * qglGenProgramsARB )(GLsizei n, GLuint *programs);
-extern void ( APIENTRY * qglProgramEnvParameter4fvARB )(GLenum target, GLuint index, const GLfloat *params);
-extern void ( APIENTRY * qglProgramLocalParameter4fvARB )(GLenum target, GLuint index, const GLfloat *params);
-extern void ( APIENTRY * qglGetProgramEnvParameterfvARB )(GLenum, GLuint, GLfloat *);
-extern void ( APIENTRY * qglGetProgramLocalParameterfvARB )(GLenum, GLuint, GLfloat *);
-extern void ( APIENTRY * qglGetProgramivARB )(GLenum, GLenum, GLint *);
-extern void ( APIENTRY * qglGetProgramStringARB )(GLenum, GLenum, GLvoid *);
-extern GLboolean ( APIENTRY * qglIsProgramARB )(GLuint);
+extern void (APIENTRY * qglProgramStringARB)(GLenum target, GLenum format, GLsizei len, const GLvoid *string);
+extern void (APIENTRY * qglBindProgramARB)(GLenum target, GLuint program);
+extern void (APIENTRY * qglDeleteProgramsARB)(GLsizei n, const GLuint *programs);
+extern void (APIENTRY * qglGenProgramsARB)(GLsizei n, GLuint *programs);
+extern void (APIENTRY * qglProgramEnvParameter4fvARB)(GLenum target, GLuint index, const GLfloat *params);
+extern void (APIENTRY * qglProgramLocalParameter4fvARB)(GLenum target, GLuint index, const GLfloat *params);
+extern void (APIENTRY * qglGetProgramEnvParameterfvARB)(GLenum, GLuint, GLfloat *);
+extern void (APIENTRY * qglGetProgramLocalParameterfvARB)(GLenum, GLuint, GLfloat *);
+extern void (APIENTRY * qglGetProgramivARB)(GLenum, GLenum, GLint *);
+extern void (APIENTRY * qglGetProgramStringARB)(GLenum, GLenum, GLvoid *);
+extern GLboolean (APIENTRY * qglIsProgramARB)(GLuint);
// GL_ARB_vertex_buffer_object
-extern void ( APIENTRY * qglBindBufferARB )(GLenum target, GLuint buffer);
-extern void ( APIENTRY * qglDeleteBuffersARB )(GLsizei n, const GLuint *buffers);
-extern void ( APIENTRY * qglGenBuffersARB )(GLsizei n, GLuint *buffers);
-extern GLboolean ( APIENTRY * qglIsBufferARB )(GLuint);
-extern void ( APIENTRY * qglBufferDataARB )(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
-extern void ( APIENTRY * qglBufferSubDataARB )(GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *);
-extern void ( APIENTRY * qglGetBufferSubDataARB )(GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *);
-extern GLvoid * ( APIENTRY * qglMapBufferARB )(GLenum target, GLenum access);
-extern GLboolean ( APIENTRY * qglUnmapBufferARB )(GLenum target);
-extern void ( APIENTRY * qglGetBufferParameterivARB )(GLenum, GLenum, GLint *);
-extern void ( APIENTRY * qglGetBufferPointervARB )(GLenum, GLenum, GLvoid* *);
+extern void (APIENTRY * qglBindBufferARB)(GLenum target, GLuint buffer);
+extern void (APIENTRY * qglDeleteBuffersARB)(GLsizei n, const GLuint *buffers);
+extern void (APIENTRY * qglGenBuffersARB)(GLsizei n, GLuint *buffers);
+extern GLboolean (APIENTRY * qglIsBufferARB)(GLuint);
+extern void (APIENTRY * qglBufferDataARB)(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
+extern void (APIENTRY * qglBufferSubDataARB)(GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *);
+extern void (APIENTRY * qglGetBufferSubDataARB)(GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *);
+extern GLvoid * (APIENTRY * qglMapBufferARB)(GLenum target, GLenum access);
+extern GLboolean (APIENTRY * qglUnmapBufferARB)(GLenum target);
+extern void (APIENTRY * qglGetBufferParameterivARB)(GLenum, GLenum, GLint *);
+extern void (APIENTRY * qglGetBufferPointervARB)(GLenum, GLenum, GLvoid* *);
#endif
diff --git a/src/r_images.c b/src/r_images.c
index a0656de..8add439 100644
--- a/src/r_images.c
+++ b/src/r_images.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -39,13 +39,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <setjmp.h>
#endif
-#define IMG_LOAD( x ) \
- static qerror_t IMG_Load##x( byte *rawdata, size_t rawlen, \
- const char *filename, byte **pic, int *width, int *height )
+#define IMG_LOAD(x) \
+ static qerror_t IMG_Load##x(byte *rawdata, size_t rawlen, \
+ const char *filename, byte **pic, int *width, int *height)
-#define IMG_SAVE( x ) \
- static qerror_t IMG_Save##x( qhandle_t f, const char *filename, \
- const byte *pic, int width, int height, int param )
+#define IMG_SAVE(x) \
+ static qerror_t IMG_Save##x(qhandle_t f, const char *filename, \
+ const byte *pic, int width, int height, int param)
/*
=================================================================
@@ -55,8 +55,8 @@ PCX LOADING
=================================================================
*/
-static qerror_t _IMG_LoadPCX( byte *rawdata, size_t rawlen,
- byte **pic, byte *palette, int *width, int *height )
+static qerror_t _IMG_LoadPCX(byte *rawdata, size_t rawlen,
+ byte **pic, byte *palette, int *width, int *height)
{
byte *raw, *end;
dpcx_t *pcx;
@@ -65,71 +65,71 @@ static qerror_t _IMG_LoadPCX( byte *rawdata, size_t rawlen,
byte *out, *pix;
qerror_t ret;
- if( pic ) {
+ if (pic) {
*pic = NULL;
}
//
// parse the PCX file
//
- if( rawlen < sizeof( dpcx_t ) ) {
+ if (rawlen < sizeof(dpcx_t)) {
return Q_ERR_FILE_TOO_SMALL;
}
- pcx = ( dpcx_t * )rawdata;
+ pcx = (dpcx_t *)rawdata;
- if( pcx->manufacturer != 0x0a || pcx->version != 5 ) {
+ if (pcx->manufacturer != 0x0a || pcx->version != 5) {
return Q_ERR_UNKNOWN_FORMAT;
}
- w = LittleShort( pcx->xmax ) + 1;
- h = LittleShort( pcx->ymax ) + 1;
- if( pcx->encoding != 1 || pcx->bits_per_pixel != 8 ) {
+ w = LittleShort(pcx->xmax) + 1;
+ h = LittleShort(pcx->ymax) + 1;
+ if (pcx->encoding != 1 || pcx->bits_per_pixel != 8) {
return Q_ERR_INVALID_FORMAT;
}
- if( w > 640 || h > 480 || w * h > MAX_PALETTED_PIXELS ) {
+ if (w > 640 || h > 480 || w * h > MAX_PALETTED_PIXELS) {
return Q_ERR_INVALID_FORMAT;
}
//
// get palette
//
- if( palette ) {
- if( rawlen < 768 ) {
+ if (palette) {
+ if (rawlen < 768) {
return Q_ERR_FILE_TOO_SMALL;
}
- memcpy( palette, ( byte * )pcx + rawlen - 768, 768 );
+ memcpy(palette, (byte *)pcx + rawlen - 768, 768);
}
//
// get pixels
//
- if( pic ) {
- pix = out = IMG_AllocPixels( w * h );
+ if (pic) {
+ pix = out = IMG_AllocPixels(w * h);
raw = pcx->data;
- end = ( byte * )pcx + rawlen;
+ end = (byte *)pcx + rawlen;
- for( y = 0; y < h; y++, pix += w ) {
- for( x = 0; x < w; ) {
- if( raw >= end ) {
+ for (y = 0; y < h; y++, pix += w) {
+ for (x = 0; x < w;) {
+ if (raw >= end) {
ret = Q_ERR_BAD_EXTENT;
goto fail;
}
dataByte = *raw++;
- if( ( dataByte & 0xC0 ) == 0xC0 ) {
+ if ((dataByte & 0xC0) == 0xC0) {
runLength = dataByte & 0x3F;
- if( x + runLength > w ) {
+ if (x + runLength > w) {
ret = Q_ERR_BAD_RLE_PACKET;
goto fail;
}
- if( raw >= end ) {
+ if (raw >= end) {
ret = Q_ERR_BAD_RLE_PACKET;
goto fail;
}
dataByte = *raw++;
- while( runLength-- ) {
+ while (runLength--) {
pix[x++] = dataByte;
}
} else {
@@ -141,25 +141,26 @@ static qerror_t _IMG_LoadPCX( byte *rawdata, size_t rawlen,
*pic = out;
}
- if( width )
+ if (width)
*width = w;
- if( height )
+ if (height)
*height = h;
return Q_ERR_SUCCESS;
fail:
- IMG_FreePixels( out );
+ IMG_FreePixels(out);
return ret;
}
-IMG_LOAD( PCX ) {
- return _IMG_LoadPCX( rawdata, rawlen, pic, NULL, width, height );
+IMG_LOAD(PCX)
+{
+ return _IMG_LoadPCX(rawdata, rawlen, pic, NULL, width, height);
}
#if USE_REF == REF_SOFT
-static qerror_t _IMG_SavePCX( qhandle_t f, const byte *data, \
- const byte *palette, int width, int height, int rowbytes )
+static qerror_t _IMG_SavePCX(qhandle_t f, const byte *data, \
+ const byte *palette, int width, int height, int rowbytes)
{
int i, j;
size_t len;
@@ -167,28 +168,28 @@ static qerror_t _IMG_SavePCX( qhandle_t f, const byte *data, \
byte *pack;
ssize_t ret;
- pcx = FS_AllocTempMem( width * height * 2 + 1000 );
+ pcx = FS_AllocTempMem(width * height * 2 + 1000);
pcx->manufacturer = 0x0a; // PCX id
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->xmin = 0;
pcx->ymin = 0;
- pcx->xmax = LittleShort( width - 1 );
- pcx->ymax = LittleShort( height - 1 );
- pcx->hres = LittleShort( width );
- pcx->vres = LittleShort( height );
- memset( pcx->palette, 0, sizeof( pcx->palette ) );
+ pcx->xmax = LittleShort(width - 1);
+ pcx->ymax = LittleShort(height - 1);
+ pcx->hres = LittleShort(width);
+ pcx->vres = LittleShort(height);
+ memset(pcx->palette, 0, sizeof(pcx->palette));
pcx->color_planes = 1; // chunky image
- pcx->bytes_per_line = LittleShort( width );
- pcx->palette_type = LittleShort( 2 ); // not a grey scale
- memset( pcx->filler, 0, sizeof( pcx->filler ) );
+ pcx->bytes_per_line = LittleShort(width);
+ pcx->palette_type = LittleShort(2); // not a grey scale
+ memset(pcx->filler, 0, sizeof(pcx->filler));
// pack the image
pack = pcx->data;
- for( i = 0; i < height; i++) {
- for( j = 0; j < width; j++) {
- if( ( *data & 0xc0 ) == 0xc0 ) {
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ if ((*data & 0xc0) == 0xc0) {
*pack++ = 0xc1;
}
*pack++ = *data++;
@@ -198,20 +199,20 @@ static qerror_t _IMG_SavePCX( qhandle_t f, const byte *data, \
// write the palette
*pack++ = 0x0c; // palette ID byte
- for( i = 0; i < 256; i++ ) {
+ for (i = 0; i < 256; i++) {
pack[0] = palette[0];
pack[1] = palette[1];
pack[2] = palette[2];
pack += 3;
palette += 4;
}
-
-// write output file
- len = pack - ( byte * )pcx;
- ret = FS_Write( pcx, len, f );
- FS_FreeTempMem( pcx );
- if( ret < 0 ) {
+// write output file
+ len = pack - (byte *)pcx;
+ ret = FS_Write(pcx, len, f);
+ FS_FreeTempMem(pcx);
+
+ if (ret < 0) {
return ret;
}
@@ -227,28 +228,29 @@ WAL LOADING
=================================================================
*/
-IMG_LOAD( WAL ) {
+IMG_LOAD(WAL)
+{
miptex_t *mt;
size_t w, h, offset, size, endpos;
- if( rawlen < sizeof( miptex_t ) ) {
+ if (rawlen < sizeof(miptex_t)) {
return Q_ERR_FILE_TOO_SMALL;
}
- mt = ( miptex_t * )rawdata;
+ mt = (miptex_t *)rawdata;
- w = LittleLong( mt->width );
- h = LittleLong( mt->height );
- offset = LittleLong( mt->offsets[0] );
+ w = LittleLong(mt->width);
+ h = LittleLong(mt->height);
+ offset = LittleLong(mt->offsets[0]);
- if( w < 1 || h < 1 || w > 512 || h > 512 || w * h > MAX_PALETTED_PIXELS ) {
+ if (w < 1 || h < 1 || w > 512 || h > 512 || w * h > MAX_PALETTED_PIXELS) {
return Q_ERR_INVALID_FORMAT;
}
size = w * h;
- size = MIPSIZE( size );
+ size = MIPSIZE(size);
endpos = offset + size;
- if( endpos < offset || endpos > rawlen ) {
+ if (endpos < offset || endpos > rawlen) {
return Q_ERR_BAD_EXTENT;
}
@@ -256,7 +258,7 @@ IMG_LOAD( WAL ) {
// taken from the file directly as an optimization
*width = w;
*height = h;
- *pic = ( byte * )mt + offset;
+ *pic = (byte *)mt + offset;
return Q_ERR_SUCCESS;
}
@@ -273,18 +275,19 @@ TARGA IMAGES
#define TARGA_HEADER_SIZE 18
-#define TGA_DECODE( x ) \
- static qerror_t tga_decode_##x( byte *in, byte *out, int cols, int rows, byte *max_in )
+#define TGA_DECODE(x) \
+ static qerror_t tga_decode_##x(byte *in, byte *out, int cols, int rows, byte *max_in)
-typedef qerror_t (*tga_decode_t)( byte *, byte *, int, int, byte * );
+typedef qerror_t (*tga_decode_t)(byte *, byte *, int, int, byte *);
-TGA_DECODE( bgr ) {
+TGA_DECODE(bgr)
+{
int col, row;
byte *out_row;
- for( row = rows - 1; row >= 0; row-- ) {
+ for (row = rows - 1; row >= 0; row--) {
out_row = out + row * cols * 4;
- for( col = 0; col < cols; col++, out_row += 4, in += 3 ) {
+ for (col = 0; col < cols; col++, out_row += 4, in += 3) {
out_row[0] = in[2];
out_row[1] = in[1];
out_row[2] = in[0];
@@ -295,13 +298,14 @@ TGA_DECODE( bgr ) {
return Q_ERR_SUCCESS;
}
-TGA_DECODE( bgra ) {
+TGA_DECODE(bgra)
+{
int col, row;
byte *out_row;
- for( row = rows - 1; row >= 0; row-- ) {
+ for (row = rows - 1; row >= 0; row--) {
out_row = out + row * cols * 4;
- for( col = 0; col < cols; col++, out_row += 4, in += 4 ) {
+ for (col = 0; col < cols; col++, out_row += 4, in += 4) {
out_row[0] = in[2];
out_row[1] = in[1];
out_row[2] = in[0];
@@ -312,10 +316,11 @@ TGA_DECODE( bgra ) {
return Q_ERR_SUCCESS;
}
-TGA_DECODE( bgr_flip ) {
+TGA_DECODE(bgr_flip)
+{
int i, count = rows * cols;
- for( i = 0; i < count; i++, out += 4, in += 3 ) {
+ for (i = 0; i < count; i++, out += 4, in += 3) {
out[0] = in[2];
out[1] = in[1];
out[2] = in[0];
@@ -325,10 +330,11 @@ TGA_DECODE( bgr_flip ) {
return Q_ERR_SUCCESS;
}
-TGA_DECODE( bgra_flip ) {
+TGA_DECODE(bgra_flip)
+{
int i, count = rows * cols;
- for( i = 0; i < count; i++, out += 4, in += 3 ) {
+ for (i = 0; i < count; i++, out += 4, in += 3) {
out[0] = in[2];
out[1] = in[1];
out[2] = in[0];
@@ -338,35 +344,36 @@ TGA_DECODE( bgra_flip ) {
return Q_ERR_SUCCESS;
}
-TGA_DECODE( bgr_rle ) {
+TGA_DECODE(bgr_rle)
+{
int col, row;
byte *out_row;
uint32_t color;
unsigned packet_header, packet_size;
int j;
- for( row = rows - 1; row >= 0; row-- ) {
+ for (row = rows - 1; row >= 0; row--) {
out_row = out + row * cols * 4;
- for( col = 0; col < cols; ) {
+ for (col = 0; col < cols;) {
packet_header = *in++;
- packet_size = 1 + ( packet_header & 0x7f );
+ packet_size = 1 + (packet_header & 0x7f);
- if( packet_header & 0x80 ) {
+ if (packet_header & 0x80) {
// run-length packet
- if( in + 3 > max_in ) {
+ if (in + 3 > max_in) {
return Q_ERR_BAD_RLE_PACKET;
}
- color = MakeColor( in[2], in[1], in[0], 255 );
+ color = MakeColor(in[2], in[1], in[0], 255);
in += 3;
- for( j = 0; j < packet_size; j++ ) {
+ for (j = 0; j < packet_size; j++) {
*(uint32_t *)out_row = color;
out_row += 4;
- if( ++col == cols ) {
+ if (++col == cols) {
// run spans across rows
col = 0;
- if( row > 0 )
+ if (row > 0)
row--;
else
goto break_out;
@@ -375,10 +382,10 @@ TGA_DECODE( bgr_rle ) {
}
} else {
// non run-length packet
- if( in + 3 * packet_size > max_in ) {
+ if (in + 3 * packet_size > max_in) {
return Q_ERR_BAD_RLE_PACKET;
}
- for( j = 0; j < packet_size; j++ ) {
+ for (j = 0; j < packet_size; j++) {
out_row[0] = in[2];
out_row[1] = in[1];
out_row[2] = in[0];
@@ -386,15 +393,15 @@ TGA_DECODE( bgr_rle ) {
out_row += 4;
in += 3;
- if( ++col == cols ) {
+ if (++col == cols) {
// run spans across rows
col = 0;
- if( row > 0 )
+ if (row > 0)
row--;
else
goto break_out;
out_row = out + row * cols * 4;
- }
+ }
}
}
}
@@ -404,35 +411,36 @@ break_out:
return Q_ERR_SUCCESS;
}
-TGA_DECODE( bgra_rle ) {
+TGA_DECODE(bgra_rle)
+{
int col, row;
byte *out_row;
uint32_t color;
unsigned packet_header, packet_size;
int j;
- for( row = rows - 1; row >= 0; row-- ) {
+ for (row = rows - 1; row >= 0; row--) {
out_row = out + row * cols * 4;
- for( col = 0; col < cols; ) {
+ for (col = 0; col < cols;) {
packet_header = *in++;
- packet_size = 1 + ( packet_header & 0x7f );
+ packet_size = 1 + (packet_header & 0x7f);
- if( packet_header & 0x80 ) {
+ if (packet_header & 0x80) {
// run-length packet
- if( in + 4 > max_in ) {
+ if (in + 4 > max_in) {
return Q_ERR_BAD_RLE_PACKET;
}
- color = MakeColor( in[2], in[1], in[0], in[3] );
+ color = MakeColor(in[2], in[1], in[0], in[3]);
in += 4;
- for( j = 0; j < packet_size; j++ ) {
+ for (j = 0; j < packet_size; j++) {
*(uint32_t *)out_row = color;
out_row += 4;
- if( ++col == cols ) {
+ if (++col == cols) {
// run spans across rows
col = 0;
- if( row > 0 )
+ if (row > 0)
row--;
else
goto break_out;
@@ -441,10 +449,10 @@ TGA_DECODE( bgra_rle ) {
}
} else {
// non run-length packet
- if( in + 4 * packet_size > max_in ) {
+ if (in + 4 * packet_size > max_in) {
return Q_ERR_BAD_RLE_PACKET;
}
- for( j = 0; j < packet_size; j++ ) {
+ for (j = 0; j < packet_size; j++) {
out_row[0] = in[2];
out_row[1] = in[1];
out_row[2] = in[0];
@@ -452,15 +460,15 @@ TGA_DECODE( bgra_rle ) {
out_row += 4;
in += 4;
- if( ++col == cols ) {
+ if (++col == cols) {
// run spans across rows
col = 0;
- if( row > 0 )
+ if (row > 0)
row--;
else
goto break_out;
out_row = out + row * cols * 4;
- }
+ }
}
}
}
@@ -470,7 +478,8 @@ break_out:
return Q_ERR_SUCCESS;
}
-IMG_LOAD( TGA ) {
+IMG_LOAD(TGA)
+{
size_t offset;
byte *pixels;
unsigned w, h, id_length, image_type, pixel_size, attributes, bpp;
@@ -479,73 +488,73 @@ IMG_LOAD( TGA ) {
*pic = NULL;
- if( rawlen < TARGA_HEADER_SIZE ) {
+ if (rawlen < TARGA_HEADER_SIZE) {
return Q_ERR_FILE_TOO_SMALL;
}
id_length = rawdata[0];
image_type = rawdata[2];
- w = LittleShortMem( &rawdata[12] );
- h = LittleShortMem( &rawdata[14] );
+ w = LittleShortMem(&rawdata[12]);
+ h = LittleShortMem(&rawdata[14]);
pixel_size = rawdata[16];
attributes = rawdata[17];
// skip TARGA image comment
offset = TARGA_HEADER_SIZE + id_length;
- if( offset + 4 > rawlen ) {
+ if (offset + 4 > rawlen) {
return Q_ERR_BAD_EXTENT;
}
- if( pixel_size == 32 ) {
+ if (pixel_size == 32) {
bpp = 4;
- } else if( pixel_size == 24 ) {
+ } else if (pixel_size == 24) {
bpp = 3;
} else {
- Com_DPrintf( "%s: %s: only 32 and 24 bit targa RGB images supported\n", __func__, filename );
+ Com_DPrintf("%s: %s: only 32 and 24 bit targa RGB images supported\n", __func__, filename);
return Q_ERR_INVALID_FORMAT;
}
- if( w < 1 || h < 1 || w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE ) {
- Com_DPrintf( "%s: %s: invalid image dimensions\n", __func__, filename );
+ if (w < 1 || h < 1 || w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE) {
+ Com_DPrintf("%s: %s: invalid image dimensions\n", __func__, filename);
return Q_ERR_INVALID_FORMAT;
}
- if( image_type == 2 ) {
- if( offset + w * h * bpp > rawlen ) {
+ if (image_type == 2) {
+ if (offset + w * h * bpp > rawlen) {
return Q_ERR_BAD_EXTENT;
}
- if( attributes & 32 ) {
- if( pixel_size == 32 ) {
+ if (attributes & 32) {
+ if (pixel_size == 32) {
decode = tga_decode_bgra_flip;
} else {
decode = tga_decode_bgr_flip;
}
} else {
- if( pixel_size == 32 ) {
+ if (pixel_size == 32) {
decode = tga_decode_bgra;
} else {
decode = tga_decode_bgr;
}
}
- } else if( image_type == 10 ) {
- if( attributes & 32 ) {
- Com_DPrintf( "%s: %s: vertically flipped, RLE encoded images are not supported\n", __func__, filename );
+ } else if (image_type == 10) {
+ if (attributes & 32) {
+ Com_DPrintf("%s: %s: vertically flipped, RLE encoded images are not supported\n", __func__, filename);
return Q_ERR_INVALID_FORMAT;
}
- if( pixel_size == 32 ) {
+ if (pixel_size == 32) {
decode = tga_decode_bgra_rle;
} else {
decode = tga_decode_bgr_rle;
}
} else {
- Com_DPrintf( "%s: %s: only type 2 and 10 targa RGB images supported\n", __func__, filename );
+ Com_DPrintf("%s: %s: only type 2 and 10 targa RGB images supported\n", __func__, filename);
return Q_ERR_INVALID_FORMAT;
}
- pixels = IMG_AllocPixels( w * h * 4 );
- ret = decode( rawdata + offset, pixels, w, h, rawdata + rawlen );
- if( ret < 0 ) {
- IMG_FreePixels( pixels );
+ pixels = IMG_AllocPixels(w * h * 4);
+ ret = decode(rawdata + offset, pixels, w, h, rawdata + rawlen);
+ if (ret < 0) {
+ IMG_FreePixels(pixels);
return ret;
}
@@ -556,12 +565,13 @@ IMG_LOAD( TGA ) {
return Q_ERR_SUCCESS;
}
-IMG_SAVE( TGA ) {
+IMG_SAVE(TGA)
+{
size_t len;
byte header[TARGA_HEADER_SIZE];
ssize_t ret;
-
- memset( &header, 0, sizeof( header ) );
+
+ memset(&header, 0, sizeof(header));
header[ 2] = 2; // uncompressed type
header[12] = width & 255;
header[13] = width >> 8;
@@ -569,14 +579,14 @@ IMG_SAVE( TGA ) {
header[15] = height >> 8;
header[16] = 24; // pixel size
- ret = FS_Write( &header, sizeof( header ), f );
- if( ret < 0 ) {
+ ret = FS_Write(&header, sizeof(header), f);
+ if (ret < 0) {
return ret;
}
len = width * height * 3;
- ret = FS_Write( pic, len, f );
- if( ret < 0 ) {
+ ret = FS_Write(pic, len, f);
+ if (ret < 0) {
return ret;
}
@@ -602,58 +612,63 @@ typedef struct my_error_mgr {
qerror_t error;
} *my_error_ptr;
-METHODDEF( void )my_output_message( j_common_ptr cinfo ) {
+METHODDEF(void) my_output_message(j_common_ptr cinfo)
+{
char buffer[JMSG_LENGTH_MAX];
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
- (*cinfo->err->format_message)( cinfo, buffer );
+ (*cinfo->err->format_message)(cinfo, buffer);
- Com_EPrintf( "libjpeg: %s: %s\n", jerr->filename, buffer );
+ Com_EPrintf("libjpeg: %s: %s\n", jerr->filename, buffer);
}
-METHODDEF( void )my_error_exit( j_common_ptr cinfo ) {
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+METHODDEF(void) my_error_exit(j_common_ptr cinfo)
+{
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
- (*cinfo->err->output_message)( cinfo );
+ (*cinfo->err->output_message)(cinfo);
jerr->error = Q_ERR_LIBRARY_ERROR;
- longjmp( jerr->setjmp_buffer, 1 );
+ longjmp(jerr->setjmp_buffer, 1);
}
#if JPEG_LIB_VERSION < 80
-METHODDEF( void )mem_init_source( j_decompress_ptr cinfo ) { }
+METHODDEF(void) mem_init_source(j_decompress_ptr cinfo) { }
-METHODDEF( boolean )mem_fill_input_buffer( j_decompress_ptr cinfo ) {
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+METHODDEF(boolean) mem_fill_input_buffer(j_decompress_ptr cinfo)
+{
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
jerr->error = Q_ERR_FILE_TOO_SMALL;
- longjmp( jerr->setjmp_buffer, 1 );
+ longjmp(jerr->setjmp_buffer, 1);
return TRUE;
}
-METHODDEF( void )mem_skip_input_data( j_decompress_ptr cinfo, long num_bytes ) {
+METHODDEF(void) mem_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
+{
struct jpeg_source_mgr *src = cinfo->src;
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
- if( num_bytes < 1 ) {
+ if (num_bytes < 1) {
return;
}
-
- if( src->bytes_in_buffer < num_bytes ) {
+
+ if (src->bytes_in_buffer < num_bytes) {
jerr->error = Q_ERR_FILE_TOO_SMALL;
- longjmp( jerr->setjmp_buffer, 1 );
+ longjmp(jerr->setjmp_buffer, 1);
}
-
- src->next_input_byte += ( size_t )num_bytes;
- src->bytes_in_buffer -= ( size_t )num_bytes;
+
+ src->next_input_byte += (size_t)num_bytes;
+ src->bytes_in_buffer -= (size_t)num_bytes;
}
-METHODDEF( void )mem_term_source( j_decompress_ptr cinfo ) { }
+METHODDEF(void) mem_term_source(j_decompress_ptr cinfo) { }
-METHODDEF( void )my_mem_src( j_decompress_ptr cinfo, byte *data, size_t size ) {
- cinfo->src = ( struct jpeg_source_mgr * )(*cinfo->mem->alloc_small)(
- ( j_common_ptr )cinfo, JPOOL_PERMANENT, sizeof( struct jpeg_source_mgr ) );
+METHODDEF(void) my_mem_src(j_decompress_ptr cinfo, byte *data, size_t size)
+{
+ cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)(
+ (j_common_ptr)cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr));
cinfo->src->init_source = mem_init_source;
cinfo->src->fill_input_buffer = mem_fill_input_buffer;
@@ -668,11 +683,12 @@ METHODDEF( void )my_mem_src( j_decompress_ptr cinfo, byte *data, size_t size ) {
#endif
-IMG_LOAD( JPG ) {
+IMG_LOAD(JPG)
+{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
JSAMPROW row_pointer;
- byte buffer[MAX_TEXTURE_SIZE*3];
+ byte buffer[MAX_TEXTURE_SIZE * 3];
byte *pixels;
byte *in, *out;
int i;
@@ -680,57 +696,57 @@ IMG_LOAD( JPG ) {
*pic = NULL;
- cinfo.err = jpeg_std_error( &jerr.pub );
+ cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
jerr.pub.output_message = my_output_message;
jerr.filename = filename;
jerr.error = Q_ERR_FAILURE;
- if( setjmp( jerr.setjmp_buffer ) ) {
+ if (setjmp(jerr.setjmp_buffer)) {
ret = jerr.error;
goto fail;
}
- jpeg_create_decompress( &cinfo );
+ jpeg_create_decompress(&cinfo);
- jpeg_mem_src( &cinfo, rawdata, rawlen );
- jpeg_read_header( &cinfo, TRUE );
+ jpeg_mem_src(&cinfo, rawdata, rawlen);
+ jpeg_read_header(&cinfo, TRUE);
- if( cinfo.out_color_space != JCS_RGB && cinfo.out_color_space != JCS_GRAYSCALE ) {
- Com_DPrintf( "%s: %s: invalid image color space\n", __func__, filename );
+ if (cinfo.out_color_space != JCS_RGB && cinfo.out_color_space != JCS_GRAYSCALE) {
+ Com_DPrintf("%s: %s: invalid image color space\n", __func__, filename);
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
- jpeg_start_decompress( &cinfo );
+ jpeg_start_decompress(&cinfo);
- if( cinfo.output_components != 3 && cinfo.output_components != 1 ) {
- Com_DPrintf( "%s: %s: invalid number of color components\n", __func__, filename );
+ if (cinfo.output_components != 3 && cinfo.output_components != 1) {
+ Com_DPrintf("%s: %s: invalid number of color components\n", __func__, filename);
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
- if( cinfo.output_width > MAX_TEXTURE_SIZE || cinfo.output_height > MAX_TEXTURE_SIZE ) {
- Com_DPrintf( "%s: %s: invalid image dimensions\n", __func__, filename );
+ if (cinfo.output_width > MAX_TEXTURE_SIZE || cinfo.output_height > MAX_TEXTURE_SIZE) {
+ Com_DPrintf("%s: %s: invalid image dimensions\n", __func__, filename);
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
- pixels = out = IMG_AllocPixels( cinfo.output_height * cinfo.output_width * 4 );
- row_pointer = ( JSAMPROW )buffer;
+ pixels = out = IMG_AllocPixels(cinfo.output_height * cinfo.output_width * 4);
+ row_pointer = (JSAMPROW)buffer;
- if( setjmp( jerr.setjmp_buffer ) ) {
- IMG_FreePixels( pixels );
+ if (setjmp(jerr.setjmp_buffer)) {
+ IMG_FreePixels(pixels);
ret = jerr.error;
goto fail;
}
- if( cinfo.output_components == 3 ) {
- while( cinfo.output_scanline < cinfo.output_height ) {
- jpeg_read_scanlines( &cinfo, &row_pointer, 1 );
+ if (cinfo.output_components == 3) {
+ while (cinfo.output_scanline < cinfo.output_height) {
+ jpeg_read_scanlines(&cinfo, &row_pointer, 1);
in = buffer;
- for( i = 0; i < cinfo.output_width; i++, out += 4, in += 3 ) {
+ for (i = 0; i < cinfo.output_width; i++, out += 4, in += 3) {
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
@@ -738,11 +754,11 @@ IMG_LOAD( JPG ) {
}
}
} else {
- while( cinfo.output_scanline < cinfo.output_height ) {
- jpeg_read_scanlines( &cinfo, &row_pointer, 1 );
+ while (cinfo.output_scanline < cinfo.output_height) {
+ jpeg_read_scanlines(&cinfo, &row_pointer, 1);
in = buffer;
- for( i = 0; i < cinfo.output_width; i++, out += 4, in += 1 ) {
+ for (i = 0; i < cinfo.output_width; i++, out += 4, in += 1) {
out[0] = out[1] = out[2] = in[0];
out[3] = 255;
}
@@ -752,13 +768,13 @@ IMG_LOAD( JPG ) {
*width = cinfo.output_width;
*height = cinfo.output_height;
- jpeg_finish_decompress( &cinfo );
+ jpeg_finish_decompress(&cinfo);
*pic = pixels;
ret = Q_ERR_SUCCESS;
fail:
- jpeg_destroy_decompress( &cinfo );
+ jpeg_destroy_decompress(&cinfo);
return ret;
}
@@ -771,26 +787,28 @@ typedef struct my_destination_mgr {
JOCTET *buffer;
} *my_dest_ptr;
-METHODDEF( void ) vfs_init_destination( j_compress_ptr cinfo ) {
- my_dest_ptr dest = ( my_dest_ptr )cinfo->dest;
+METHODDEF(void) vfs_init_destination(j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
// Allocate the output buffer --- it will be released when done with image
- dest->buffer = ( JOCTET * )(*cinfo->mem->alloc_small)
- ( ( j_common_ptr )cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * sizeof( JOCTET ) );
+ dest->buffer = (JOCTET *)(*cinfo->mem->alloc_small)
+ ((j_common_ptr)cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * sizeof(JOCTET));
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
}
-METHODDEF( boolean ) vfs_empty_output_buffer( j_compress_ptr cinfo ) {
- my_dest_ptr dest = ( my_dest_ptr )cinfo->dest;
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+METHODDEF(boolean) vfs_empty_output_buffer(j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
ssize_t ret;
- ret = FS_Write( dest->buffer, OUTPUT_BUF_SIZE, dest->f );
- if( ret != OUTPUT_BUF_SIZE ) {
+ ret = FS_Write(dest->buffer, OUTPUT_BUF_SIZE, dest->f);
+ if (ret != OUTPUT_BUF_SIZE) {
jerr->error = ret < 0 ? ret : Q_ERR_FAILURE;
- longjmp( jerr->setjmp_buffer, 1 );
+ longjmp(jerr->setjmp_buffer, 1);
}
dest->pub.next_output_byte = dest->buffer;
@@ -799,27 +817,29 @@ METHODDEF( boolean ) vfs_empty_output_buffer( j_compress_ptr cinfo ) {
return TRUE;
}
-METHODDEF( void ) vfs_term_destination( j_compress_ptr cinfo ) {
- my_dest_ptr dest = ( my_dest_ptr )cinfo->dest;
- my_error_ptr jerr = ( my_error_ptr )cinfo->err;
+METHODDEF(void) vfs_term_destination(j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
+ my_error_ptr jerr = (my_error_ptr)cinfo->err;
size_t remaining = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
ssize_t ret;
// Write any data remaining in the buffer
- if( remaining > 0 ) {
- ret = FS_Write( dest->buffer, remaining, dest->f );
- if( ret != remaining ) {
+ if (remaining > 0) {
+ ret = FS_Write(dest->buffer, remaining, dest->f);
+ if (ret != remaining) {
jerr->error = ret < 0 ? ret : Q_ERR_FAILURE;
- longjmp( jerr->setjmp_buffer, 1 );
+ longjmp(jerr->setjmp_buffer, 1);
}
}
}
-METHODDEF( void ) my_vfs_dst( j_compress_ptr cinfo, qhandle_t f ) {
+METHODDEF(void) my_vfs_dst(j_compress_ptr cinfo, qhandle_t f)
+{
my_dest_ptr dest;
- dest = ( my_dest_ptr )(*cinfo->mem->alloc_small)
- ( ( j_common_ptr )cinfo, JPOOL_PERMANENT, sizeof( struct my_destination_mgr ) );
+ dest = (my_dest_ptr)(*cinfo->mem->alloc_small)
+ ((j_common_ptr)cinfo, JPOOL_PERMANENT, sizeof(struct my_destination_mgr));
cinfo->dest = &dest->pub;
dest->pub.init_destination = vfs_init_destination;
@@ -828,7 +848,8 @@ METHODDEF( void ) my_vfs_dst( j_compress_ptr cinfo, qhandle_t f ) {
dest->f = f;
}
-IMG_SAVE( JPG ) {
+IMG_SAVE(JPG)
+{
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
JSAMPARRAY row_pointers;
@@ -836,52 +857,52 @@ IMG_SAVE( JPG ) {
qerror_t ret;
int i;
- cinfo.err = jpeg_std_error( &jerr.pub );
+ cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
jerr.filename = filename;
jerr.error = Q_ERR_FAILURE;
- if( setjmp( jerr.setjmp_buffer ) ) {
+ if (setjmp(jerr.setjmp_buffer)) {
ret = jerr.error;
goto fail1;
}
- jpeg_create_compress( &cinfo );
+ jpeg_create_compress(&cinfo);
- my_vfs_dst( &cinfo, f );
+ my_vfs_dst(&cinfo, f);
cinfo.image_width = width; // image width and height, in pixels
cinfo.image_height = height;
cinfo.input_components = 3; // # of color components per pixel
cinfo.in_color_space = JCS_RGB; // colorspace of input image
- jpeg_set_defaults( &cinfo );
- jpeg_set_quality( &cinfo, clamp( param, 0, 100 ), TRUE );
+ jpeg_set_defaults(&cinfo);
+ jpeg_set_quality(&cinfo, clamp(param, 0, 100), TRUE);
- jpeg_start_compress( &cinfo, TRUE );
+ jpeg_start_compress(&cinfo, TRUE);
- row_pointers = FS_AllocTempMem( sizeof( JSAMPROW ) * height );
+ row_pointers = FS_AllocTempMem(sizeof(JSAMPROW) * height);
row_stride = width * 3; // JSAMPLEs per row in image_buffer
- for( i = 0; i < height; i++ ) {
- row_pointers[i] = ( JSAMPROW )( pic + ( height - i - 1 ) * row_stride );
+ for (i = 0; i < height; i++) {
+ row_pointers[i] = (JSAMPROW)(pic + (height - i - 1) * row_stride);
}
- if( setjmp( jerr.setjmp_buffer ) ) {
+ if (setjmp(jerr.setjmp_buffer)) {
ret = jerr.error;
goto fail2;
}
- jpeg_write_scanlines( &cinfo, row_pointers, height );
+ jpeg_write_scanlines(&cinfo, row_pointers, height);
- jpeg_finish_compress( &cinfo );
+ jpeg_finish_compress(&cinfo);
ret = Q_ERR_SUCCESS;
fail2:
- FS_FreeTempMem( row_pointers );
+ FS_FreeTempMem(row_pointers);
fail1:
- jpeg_destroy_compress( &cinfo );
+ jpeg_destroy_compress(&cinfo);
return ret;
}
@@ -908,36 +929,40 @@ typedef struct {
qerror_t error;
} my_png_error;
-static void my_png_read_fn( png_structp png_ptr, png_bytep buf, png_size_t size ) {
- my_png_io *io = png_get_io_ptr( png_ptr );
+static void my_png_read_fn(png_structp png_ptr, png_bytep buf, png_size_t size)
+{
+ my_png_io *io = png_get_io_ptr(png_ptr);
- if( size > io->avail_in ) {
- my_png_error *err = png_get_error_ptr( png_ptr );
+ if (size > io->avail_in) {
+ my_png_error *err = png_get_error_ptr(png_ptr);
err->error = Q_ERR_FILE_TOO_SMALL;
- png_error( png_ptr, "read error" );
+ png_error(png_ptr, "read error");
} else {
- memcpy( buf, io->next_in, size );
+ memcpy(buf, io->next_in, size);
io->next_in += size;
io->avail_in -= size;
}
}
-static void my_png_error_fn( png_structp png_ptr, png_const_charp error_msg ) {
- my_png_error *err = png_get_error_ptr( png_ptr );
+static void my_png_error_fn(png_structp png_ptr, png_const_charp error_msg)
+{
+ my_png_error *err = png_get_error_ptr(png_ptr);
- if( err->error == Q_ERR_LIBRARY_ERROR ) {
- Com_EPrintf( "libpng: %s: %s\n", err->filename, error_msg );
+ if (err->error == Q_ERR_LIBRARY_ERROR) {
+ Com_EPrintf("libpng: %s: %s\n", err->filename, error_msg);
}
- longjmp( png_jmpbuf( png_ptr ), -1 );
+ longjmp(png_jmpbuf(png_ptr), -1);
}
-static void my_png_warning_fn( png_structp png_ptr, png_const_charp warning_msg ) {
- my_png_error *err = png_get_error_ptr( png_ptr );
+static void my_png_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
+{
+ my_png_error *err = png_get_error_ptr(png_ptr);
- Com_WPrintf( "libpng: %s: %s\n", err->filename, warning_msg );
+ Com_WPrintf("libpng: %s: %s\n", err->filename, warning_msg);
}
-IMG_LOAD( PNG ) {
+IMG_LOAD(PNG)
+{
byte *pixels;
png_bytep row_pointers[MAX_TEXTURE_SIZE];
png_uint_32 w, h, rowbytes, row;
@@ -953,84 +978,84 @@ IMG_LOAD( PNG ) {
my_err.filename = filename;
my_err.error = Q_ERR_LIBRARY_ERROR;
- png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,
- ( png_voidp )&my_err, my_png_error_fn, my_png_warning_fn );
- if( !png_ptr ) {
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ (png_voidp)&my_err, my_png_error_fn, my_png_warning_fn);
+ if (!png_ptr) {
return Q_ERR_LIBRARY_ERROR;
}
- info_ptr = png_create_info_struct( png_ptr );
- if( !info_ptr ) {
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
ret = Q_ERR_LIBRARY_ERROR;
goto fail;
}
- if( setjmp( png_jmpbuf( png_ptr ) ) ) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
ret = my_err.error;
goto fail;
}
my_io.next_in = rawdata;
my_io.avail_in = rawlen;
- png_set_read_fn( png_ptr, ( png_voidp )&my_io, my_png_read_fn );
+ png_set_read_fn(png_ptr, (png_voidp)&my_io, my_png_read_fn);
- png_read_info( png_ptr, info_ptr );
+ png_read_info(png_ptr, info_ptr);
- if( !png_get_IHDR( png_ptr, info_ptr, &w, &h, &bitdepth, &colortype, NULL, NULL, NULL ) ) {
+ if (!png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitdepth, &colortype, NULL, NULL, NULL)) {
ret = Q_ERR_LIBRARY_ERROR;
goto fail;
}
- if( w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE ) {
- Com_DPrintf( "%s: %s: invalid image dimensions\n", __func__, filename );
+ if (w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE) {
+ Com_DPrintf("%s: %s: invalid image dimensions\n", __func__, filename);
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
- switch( colortype ) {
+ switch (colortype) {
case PNG_COLOR_TYPE_PALETTE:
- png_set_palette_to_rgb( png_ptr );
+ png_set_palette_to_rgb(png_ptr);
break;
case PNG_COLOR_TYPE_GRAY:
- if( bitdepth < 8 ) {
- png_set_gray_1_2_4_to_8( png_ptr );
+ if (bitdepth < 8) {
+ png_set_gray_1_2_4_to_8(png_ptr);
}
// fall through
case PNG_COLOR_TYPE_GRAY_ALPHA:
- png_set_gray_to_rgb( png_ptr );
+ png_set_gray_to_rgb(png_ptr);
break;
}
- if( bitdepth < 8 ) {
- png_set_packing( png_ptr );
- } else if( bitdepth == 16 ) {
- png_set_strip_16( png_ptr );
+ if (bitdepth < 8) {
+ png_set_packing(png_ptr);
+ } else if (bitdepth == 16) {
+ png_set_strip_16(png_ptr);
}
- if( png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS ) ) {
- png_set_tRNS_to_alpha( png_ptr );
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_set_tRNS_to_alpha(png_ptr);
}
- png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
+ png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
- png_read_update_info( png_ptr, info_ptr );
+ png_read_update_info(png_ptr, info_ptr);
- rowbytes = png_get_rowbytes( png_ptr, info_ptr );
- pixels = IMG_AllocPixels( h * rowbytes );
+ rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ pixels = IMG_AllocPixels(h * rowbytes);
- for( row = 0; row < h; row++ ) {
+ for (row = 0; row < h; row++) {
row_pointers[row] = pixels + row * rowbytes;
}
- if( setjmp( png_jmpbuf( png_ptr ) ) ) {
- IMG_FreePixels( pixels );
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ IMG_FreePixels(pixels);
ret = my_err.error;
goto fail;
}
- png_read_image( png_ptr, row_pointers );
+ png_read_image(png_ptr, row_pointers);
- png_read_end( png_ptr, info_ptr );
+ png_read_end(png_ptr, info_ptr);
*pic = pixels;
*width = w;
@@ -1038,24 +1063,26 @@ IMG_LOAD( PNG ) {
ret = Q_ERR_SUCCESS;
fail:
- png_destroy_read_struct( &png_ptr, &info_ptr, NULL );
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return ret;
}
-static void my_png_write_fn( png_structp png_ptr, png_bytep buf, png_size_t size ) {
- qhandle_t *f = png_get_io_ptr( png_ptr );
- ssize_t ret = FS_Write( buf, size, *f );
+static void my_png_write_fn(png_structp png_ptr, png_bytep buf, png_size_t size)
+{
+ qhandle_t *f = png_get_io_ptr(png_ptr);
+ ssize_t ret = FS_Write(buf, size, *f);
- if( ret != size ) {
- my_png_error *err = png_get_error_ptr( png_ptr );
+ if (ret != size) {
+ my_png_error *err = png_get_error_ptr(png_ptr);
err->error = ret < 0 ? ret : Q_ERR_FAILURE;
- png_error( png_ptr, "write error" );
+ png_error(png_ptr, "write error");
}
}
-static void my_png_flush_fn( png_structp png_ptr ) { }
+static void my_png_flush_fn(png_structp png_ptr) { }
-IMG_SAVE( PNG ) {
+IMG_SAVE(PNG)
+{
png_structp png_ptr;
png_infop info_ptr;
png_bytepp row_pointers;
@@ -1066,54 +1093,54 @@ IMG_SAVE( PNG ) {
my_err.filename = filename;
my_err.error = Q_ERR_LIBRARY_ERROR;
- png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING,
- ( png_voidp )&my_err, my_png_error_fn, my_png_warning_fn );
- if( !png_ptr ) {
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
+ (png_voidp)&my_err, my_png_error_fn, my_png_warning_fn);
+ if (!png_ptr) {
return Q_ERR_LIBRARY_ERROR;
}
- info_ptr = png_create_info_struct( png_ptr );
- if( !info_ptr ) {
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
ret = Q_ERR_LIBRARY_ERROR;
goto fail1;
}
- if( setjmp( png_jmpbuf( png_ptr ) ) ) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
ret = my_err.error;
goto fail1;
}
- png_set_write_fn( png_ptr, ( png_voidp )&f,
- my_png_write_fn, my_png_flush_fn );
+ png_set_write_fn(png_ptr, (png_voidp)&f,
+ my_png_write_fn, my_png_flush_fn);
- png_set_IHDR( png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT );
+ png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- png_set_compression_level( png_ptr,
- clamp( param, Z_NO_COMPRESSION, Z_BEST_COMPRESSION ) );
+ png_set_compression_level(png_ptr,
+ clamp(param, Z_NO_COMPRESSION, Z_BEST_COMPRESSION));
- row_pointers = FS_AllocTempMem( sizeof( png_bytep ) * height );
+ row_pointers = FS_AllocTempMem(sizeof(png_bytep) * height);
row_stride = width * 3;
- for( i = 0; i < height; i++ ) {
- row_pointers[i] = ( png_bytep )pic + ( height - i - 1 ) * row_stride;
+ for (i = 0; i < height; i++) {
+ row_pointers[i] = (png_bytep)pic + (height - i - 1) * row_stride;
}
- if( setjmp( png_jmpbuf( png_ptr ) ) ) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
ret = my_err.error;
goto fail2;
}
- png_set_rows( png_ptr, info_ptr, row_pointers );
+ png_set_rows(png_ptr, info_ptr, row_pointers);
- png_write_png( png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL );
+ png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
ret = Q_ERR_SUCCESS;
fail2:
- FS_FreeTempMem( row_pointers );
+ FS_FreeTempMem(row_pointers);
fail1:
- png_destroy_write_struct( &png_ptr, &info_ptr );
+ png_destroy_write_struct(&png_ptr, &info_ptr);
return ret;
}
@@ -1138,43 +1165,43 @@ static cvar_t *r_screenshot_compression;
#endif
#if USE_TGA || USE_JPG || USE_PNG || USE_REF == REF_SOFT
-static qhandle_t create_screenshot( char *buffer, size_t size,
- const char *name, const char *ext )
+static qhandle_t create_screenshot(char *buffer, size_t size,
+ const char *name, const char *ext)
{
qhandle_t f;
qerror_t ret;
int i;
- if( name && *name ) {
+ if (name && *name) {
// save to user supplied name
- return FS_EasyOpenFile( buffer, size, FS_MODE_WRITE,
- SCREENSHOTS_DIRECTORY "/", name, ext );
+ return FS_EasyOpenFile(buffer, size, FS_MODE_WRITE,
+ SCREENSHOTS_DIRECTORY "/", name, ext);
}
// find a file name to save it to
- for( i = 0; i < 1000; i++ ) {
- Q_snprintf( buffer, size, SCREENSHOTS_DIRECTORY "/quake%03d%s", i, ext );
- ret = FS_FOpenFile( buffer, &f, FS_MODE_WRITE|FS_FLAG_EXCL );
- if( f ) {
+ for (i = 0; i < 1000; i++) {
+ Q_snprintf(buffer, size, SCREENSHOTS_DIRECTORY "/quake%03d%s", i, ext);
+ ret = FS_FOpenFile(buffer, &f, FS_MODE_WRITE | FS_FLAG_EXCL);
+ if (f) {
return f;
}
- if( ret != Q_ERR_EXIST ) {
- Com_EPrintf( "Couldn't exclusively open %s for writing: %s\n",
- buffer, Q_ErrorString( ret ) );
+ if (ret != Q_ERR_EXIST) {
+ Com_EPrintf("Couldn't exclusively open %s for writing: %s\n",
+ buffer, Q_ErrorString(ret));
return 0;
}
}
- Com_EPrintf( "All screenshot slots are full.\n" );
+ Com_EPrintf("All screenshot slots are full.\n");
return 0;
}
-static void make_screenshot( const char *name, const char *ext
+static void make_screenshot(const char *name, const char *ext
#if USE_REF == REF_GL
- , qerror_t (*save)( qhandle_t, const char *, const byte *, int, int, int ),
- qboolean reverse, int param
+ , qerror_t (*save)(qhandle_t, const char *, const byte *, int, int, int),
+ qboolean reverse, int param
#endif
- )
+ )
{
char buffer[MAX_OSPATH];
byte *pixels;
@@ -1186,26 +1213,26 @@ static void make_screenshot( const char *name, const char *ext
byte *palette;
#endif
- f = create_screenshot( buffer, sizeof( buffer ), name, ext );
- if( !f ) {
+ f = create_screenshot(buffer, sizeof(buffer), name, ext);
+ if (!f) {
return;
}
#if USE_REF == REF_GL
- pixels = IMG_ReadPixels( reverse, &w, &h );
- ret = save( f, buffer, pixels, w, h, param );
- FS_FreeTempMem( pixels );
+ pixels = IMG_ReadPixels(reverse, &w, &h);
+ ret = save(f, buffer, pixels, w, h, param);
+ FS_FreeTempMem(pixels);
#else
- pixels = IMG_ReadPixels( &palette, &w, &h, &rowbytes );
- ret = _IMG_SavePCX( f, pixels, palette, w, h, rowbytes );
+ pixels = IMG_ReadPixels(&palette, &w, &h, &rowbytes);
+ ret = _IMG_SavePCX(f, pixels, palette, w, h, rowbytes);
#endif
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- if( ret < 0 ) {
- Com_EPrintf( "Couldn't write %s: %s\n", buffer, Q_ErrorString( ret ) );
+ if (ret < 0) {
+ Com_EPrintf("Couldn't write %s: %s\n", buffer, Q_ErrorString(ret));
} else {
- Com_Printf( "Wrote %s\n", buffer );
+ Com_Printf("Wrote %s\n", buffer);
}
}
#endif // USE_TGA || USE_JPG || USE_PNG || USE_REF == REF_SOFT
@@ -1220,44 +1247,45 @@ specified. This function is always compiled in to give a meaningful warning
if no formats are available.
==================
*/
-static void IMG_ScreenShot_f( void ) {
+static void IMG_ScreenShot_f(void)
+{
#if USE_JPG || USE_PNG
const char *s;
- if( Cmd_Argc() > 2 ) {
- Com_Printf( "Usage: %s [format]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() > 2) {
+ Com_Printf("Usage: %s [format]\n", Cmd_Argv(0));
return;
}
- if( Cmd_Argc() > 1 ) {
- s = Cmd_Argv( 1 );
+ if (Cmd_Argc() > 1) {
+ s = Cmd_Argv(1);
} else {
s = r_screenshot_format->string;
}
#if USE_JPG
- if( *s == 'j' ) {
- make_screenshot( NULL, ".jpg", IMG_SaveJPG, qfalse,
- r_screenshot_quality->integer );
+ if (*s == 'j') {
+ make_screenshot(NULL, ".jpg", IMG_SaveJPG, qfalse,
+ r_screenshot_quality->integer);
return;
}
#endif
#if USE_PNG
- if( *s == 'p' ) {
- make_screenshot( NULL, ".png", IMG_SavePNG, qfalse,
- r_screenshot_compression->integer );
+ if (*s == 'p') {
+ make_screenshot(NULL, ".png", IMG_SavePNG, qfalse,
+ r_screenshot_compression->integer);
return;
}
#endif
#endif // USE_JPG || USE_PNG
#if USE_REF == REF_SOFT
- make_screenshot( NULL, ".pcx" );
+ make_screenshot(NULL, ".pcx");
#elif USE_TGA
- make_screenshot( NULL, ".tga", IMG_SaveTGA, qtrue, 0 );
+ make_screenshot(NULL, ".tga", IMG_SaveTGA, qtrue, 0);
#else
- Com_Printf( "Can't take screenshot, TGA format not available.\n" );
+ Com_Printf("Can't take screenshot, TGA format not available.\n");
#endif
}
@@ -1270,62 +1298,66 @@ can be also specified, as well as quality and compression options.
==================
*/
#if USE_REF == REF_SOFT
-static void IMG_ScreenShotPCX_f( void ) {
- if( Cmd_Argc() > 2 ) {
- Com_Printf( "Usage: %s [name]\n", Cmd_Argv( 0 ) );
+static void IMG_ScreenShotPCX_f(void)
+{
+ if (Cmd_Argc() > 2) {
+ Com_Printf("Usage: %s [name]\n", Cmd_Argv(0));
return;
}
- make_screenshot( Cmd_Argv( 1 ), ".pcx" );
+ make_screenshot(Cmd_Argv(1), ".pcx");
}
#endif
#if USE_TGA
-static void IMG_ScreenShotTGA_f( void ) {
- if( Cmd_Argc() > 2 ) {
- Com_Printf( "Usage: %s [name]\n", Cmd_Argv( 0 ) );
+static void IMG_ScreenShotTGA_f(void)
+{
+ if (Cmd_Argc() > 2) {
+ Com_Printf("Usage: %s [name]\n", Cmd_Argv(0));
return;
}
- make_screenshot( Cmd_Argv( 1 ), ".tga", IMG_SaveTGA, qtrue, 0 );
+ make_screenshot(Cmd_Argv(1), ".tga", IMG_SaveTGA, qtrue, 0);
}
#endif
#if USE_JPG
-static void IMG_ScreenShotJPG_f( void ) {
+static void IMG_ScreenShotJPG_f(void)
+{
int quality;
- if( Cmd_Argc() > 3 ) {
- Com_Printf( "Usage: %s [name] [quality]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() > 3) {
+ Com_Printf("Usage: %s [name] [quality]\n", Cmd_Argv(0));
return;
}
- if( Cmd_Argc() > 2 ) {
- quality = atoi( Cmd_Argv( 2 ) );
+ if (Cmd_Argc() > 2) {
+ quality = atoi(Cmd_Argv(2));
} else {
quality = r_screenshot_quality->integer;
}
- make_screenshot( Cmd_Argv( 1 ), ".jpg", IMG_SaveJPG, qfalse, quality );
+ make_screenshot(Cmd_Argv(1), ".jpg", IMG_SaveJPG, qfalse, quality);
}
#endif
#if USE_PNG
-static void IMG_ScreenShotPNG_f( void ) {
+static void IMG_ScreenShotPNG_f(void)
+{
int compression;
- if( Cmd_Argc() > 3 ) {
- Com_Printf( "Usage: %s [name] [compression]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() > 3) {
+ Com_Printf("Usage: %s [name] [compression]\n", Cmd_Argv(0));
return;
}
- if( Cmd_Argc() > 2 ) {
- compression = atoi( Cmd_Argv( 2 ) );
+ if (Cmd_Argc() > 2) {
+ compression = atoi(Cmd_Argv(2));
} else {
compression = r_screenshot_compression->integer;
}
- make_screenshot( Cmd_Argv( 1 ), ".png", IMG_SavePNG, qfalse, compression );
+ make_screenshot(Cmd_Argv(1), ".png", IMG_SavePNG, qfalse, compression);
}
#endif
@@ -1341,7 +1373,7 @@ IMAGE MANAGER
typedef struct {
char ext[4];
- qerror_t (*load)( byte *, size_t, const char *, byte **, int *, int * );
+ qerror_t (*load)(byte *, size_t, const char *, byte **, int *, int *);
} imageloader_t;
image_t r_images[MAX_RIMAGES];
@@ -1377,48 +1409,50 @@ static cvar_t *r_texture_formats;
IMG_List_f
===============
*/
-static void IMG_List_f( void ) {
+static void IMG_List_f(void)
+{
static const char types[8] = "MSWPYC?";
int i;
image_t *image;
int texels, count;
- Com_Printf( "------------------\n");
+ Com_Printf("------------------\n");
texels = count = 0;
- for( i = 1, image = r_images + 1; i < r_numImages; i++, image++ ) {
- if( !image->registration_sequence )
+ for (i = 1, image = r_images + 1; i < r_numImages; i++, image++) {
+ if (!image->registration_sequence)
continue;
- Com_Printf( "%c%c%c %4i %4i %s: %s\n",
- types[image->type],
- ( image->flags & if_transparent ) ? 'T' : ' ',
- ( image->flags & if_scrap ) ? 'S' : ' ',
- image->upload_width,
- image->upload_height,
- ( image->flags & if_paletted ) ? "PAL" : "RGB",
- image->name );
+ Com_Printf("%c%c%c %4i %4i %s: %s\n",
+ types[image->type],
+ (image->flags & if_transparent) ? 'T' : ' ',
+ (image->flags & if_scrap) ? 'S' : ' ',
+ image->upload_width,
+ image->upload_height,
+ (image->flags & if_paletted) ? "PAL" : "RGB",
+ image->name);
texels += image->upload_width * image->upload_height;
count++;
}
- Com_Printf( "Total images: %d (out of %d slots)\n", count, r_numImages );
- Com_Printf( "Total texels: %d (not counting mipmaps)\n", texels );
+ Com_Printf("Total images: %d (out of %d slots)\n", count, r_numImages);
+ Com_Printf("Total texels: %d (not counting mipmaps)\n", texels);
}
-static image_t *alloc_image( void ) {
+static image_t *alloc_image(void)
+{
int i;
image_t *image;
// find a free image_t slot
- for( i = 1, image = r_images + 1; i < r_numImages; i++, image++ ) {
- if( !image->registration_sequence )
+ for (i = 1, image = r_images + 1; i < r_numImages; i++, image++) {
+ if (!image->registration_sequence)
break;
}
- if( i == r_numImages ) {
- if( r_numImages == MAX_RIMAGES )
- Com_Error( ERR_FATAL, "%s: MAX_IMAGES exceeded", __func__ );
+ if (i == r_numImages) {
+ if (r_numImages == MAX_RIMAGES)
+ Com_Error(ERR_FATAL, "%s: MAX_IMAGES exceeded", __func__);
r_numImages++;
}
@@ -1427,20 +1461,20 @@ static image_t *alloc_image( void ) {
// finds the given image of the given type.
// case and extension insensitive.
-static image_t *lookup_image( const char *name,
- imagetype_t type, unsigned hash, size_t baselen )
+static image_t *lookup_image(const char *name,
+ imagetype_t type, unsigned hash, size_t baselen)
{
image_t *image;
// look for it
- LIST_FOR_EACH( image_t, image, &r_imageHash[hash], entry ) {
- if( image->type != type ) {
+ LIST_FOR_EACH(image_t, image, &r_imageHash[hash], entry) {
+ if (image->type != type) {
continue;
}
- if( image->baselen != baselen ) {
+ if (image->baselen != baselen) {
continue;
}
- if( !FS_pathcmpn( image->name, name, baselen ) ) {
+ if (!FS_pathcmpn(image->name, name, baselen)) {
return image;
}
}
@@ -1448,23 +1482,24 @@ static image_t *lookup_image( const char *name,
return NULL;
}
-static imageformat_t try_image_format( const imageloader_t *ldr,
- const char *filename, byte **pic, byte **tmp, int *width, int *height )
+static imageformat_t try_image_format(const imageloader_t *ldr,
+ const char *filename, byte **pic,
+ byte **tmp, int *width, int *height)
{
byte *data;
ssize_t len;
qerror_t ret;
// load the file
- len = FS_LoadFile( filename, ( void ** )&data );
- if( !data ) {
+ len = FS_LoadFile(filename, (void **)&data);
+ if (!data) {
return len;
}
// decompress the image
- ret = ldr->load( data, len, filename, pic, width, height );
- if( ret < 0 ) {
- FS_FreeFile( data );
+ ret = ldr->load(data, len, filename, pic, width, height);
+ if (ret < 0) {
+ FS_FreeFile(data);
return ret;
}
@@ -1473,8 +1508,8 @@ static imageformat_t try_image_format( const imageloader_t *ldr,
// unless this is a WAL texture, raw image data is
// no longer needed, free it now
- if( ret != im_wal ) {
- FS_FreeFile( data );
+ if (ret != im_wal) {
+ FS_FreeFile(data);
*tmp = NULL;
} else {
*tmp = data;
@@ -1486,8 +1521,9 @@ static imageformat_t try_image_format( const imageloader_t *ldr,
#if USE_PNG || USE_JPG || USE_TGA
// tries to load the image with a different extension
-static qerror_t try_other_formats( imageformat_t orig, imagetype_t type,
- char *buffer, char *ext, byte **pic, byte **tmp, int *width, int *height )
+static qerror_t try_other_formats(imageformat_t orig, imagetype_t type,
+ char *buffer, char *ext, byte **pic,
+ byte **tmp, int *width, int *height)
{
const imageloader_t *ldr;
imageformat_t fmt;
@@ -1495,19 +1531,19 @@ static qerror_t try_other_formats( imageformat_t orig, imagetype_t type,
int i;
// search through all the 32-bit formats
- for( i = 0; i < img_total; i++ ) {
+ for (i = 0; i < img_total; i++) {
fmt = img_search[i];
- if( fmt == orig ) {
+ if (fmt == orig) {
// don't retry twice
continue;
}
// replace the extension
ldr = &img_loaders[fmt];
- memcpy( ext, ldr->ext, 4 );
+ memcpy(ext, ldr->ext, 4);
- ret = try_image_format( ldr, buffer, pic, tmp, width, height );
- if( ret != Q_ERR_NOENT ) {
+ ret = try_image_format(ldr, buffer, pic, tmp, width, height);
+ if (ret != Q_ERR_NOENT) {
// found something
return ret;
}
@@ -1515,19 +1551,19 @@ static qerror_t try_other_formats( imageformat_t orig, imagetype_t type,
// fall back to 8-bit formats
fmt = type == it_wall ? im_wal : im_pcx;
- if( fmt == orig ) {
+ if (fmt == orig) {
// don't retry twice
return Q_ERR_NOENT;
}
ldr = &img_loaders[fmt];
- memcpy( ext, ldr->ext, 4 );
+ memcpy(ext, ldr->ext, 4);
- return try_image_format( ldr, buffer, pic, tmp, width, height );
+ return try_image_format(ldr, buffer, pic, tmp, width, height);
}
-static void get_image_dimensions( image_t *image,
- imageformat_t fmt, char *buffer, char *ext )
+static void get_image_dimensions(image_t *image,
+ imageformat_t fmt, char *buffer, char *ext)
{
ssize_t len;
miptex_t mt;
@@ -1536,31 +1572,31 @@ static void get_image_dimensions( image_t *image,
unsigned w, h;
w = h = 0;
- if( fmt == im_wal ) {
- memcpy( ext, "wal", 4 );
- FS_FOpenFile( buffer, &f, FS_MODE_READ );
- if( f ) {
- len = FS_Read( &mt, sizeof( mt ), f );
- if( len == sizeof( mt ) ) {
- w = LittleLong( mt.width );
- h = LittleLong( mt.height );
+ if (fmt == im_wal) {
+ memcpy(ext, "wal", 4);
+ FS_FOpenFile(buffer, &f, FS_MODE_READ);
+ if (f) {
+ len = FS_Read(&mt, sizeof(mt), f);
+ if (len == sizeof(mt)) {
+ w = LittleLong(mt.width);
+ h = LittleLong(mt.height);
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
}
} else {
- memcpy( ext, "pcx", 4 );
- FS_FOpenFile( buffer, &f, FS_MODE_READ );
- if( f ) {
- len = FS_Read( &pcx, sizeof( pcx ), f );
- if( len == sizeof( pcx ) ) {
- w = LittleShort( pcx.xmax ) + 1;
- h = LittleShort( pcx.ymax ) + 1;
+ memcpy(ext, "pcx", 4);
+ FS_FOpenFile(buffer, &f, FS_MODE_READ);
+ if (f) {
+ len = FS_Read(&pcx, sizeof(pcx), f);
+ if (len == sizeof(pcx)) {
+ w = LittleShort(pcx.xmax) + 1;
+ h = LittleShort(pcx.ymax) + 1;
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
}
}
- if( w < 1 || h < 1 || w > 512 || h > 512 || w * h > MAX_PALETTED_PIXELS ) {
+ if (w < 1 || h < 1 || w > 512 || h > 512 || w * h > MAX_PALETTED_PIXELS) {
return;
}
@@ -1568,7 +1604,8 @@ static void get_image_dimensions( image_t *image,
image->height = h;
}
-static void r_texture_formats_changed( cvar_t *self ) {
+static void r_texture_formats_changed(cvar_t *self)
+{
char *s;
int i;
@@ -1576,22 +1613,22 @@ static void r_texture_formats_changed( cvar_t *self ) {
img_total = 0;
// parse the string
- for( s = self->string; *s; s++ ) {
- switch( *s ) {
+ for (s = self->string; *s; s++) {
+ switch (*s) {
#if USE_TGA
- case 't': case 'T': i = im_tga; break;
+ case 't': case 'T': i = im_tga; break;
#endif
#if USE_JPG
- case 'j': case 'J': i = im_jpg; break;
+ case 'j': case 'J': i = im_jpg; break;
#endif
#if USE_PNG
- case 'p': case 'P': i = im_png; break;
+ case 'p': case 'P': i = im_png; break;
#endif
- default: continue;
+ default: continue;
}
img_search[img_total++] = i;
- if( img_total == im_unknown ) {
+ if (img_total == im_unknown) {
break;
}
}
@@ -1600,8 +1637,8 @@ static void r_texture_formats_changed( cvar_t *self ) {
#endif // USE_PNG || USE_JPG || USE_TGA
// finds or loads the given image, adding it to the hash table.
-static qerror_t find_or_load_image( const char *name,
- size_t len, imagetype_t type, image_t **image_p )
+static qerror_t find_or_load_image(const char *name,
+ size_t len, imagetype_t type, image_t **image_p)
{
image_t *image;
byte *pic, *tmp;
@@ -1614,31 +1651,31 @@ static qerror_t find_or_load_image( const char *name,
*image_p = NULL;
- // must have an extension and at least 1 char of base name
- if( len <= 4 ) {
+ // must have an extension and at least 1 char of base name
+ if (len <= 4) {
return Q_ERR_NAMETOOSHORT;
}
- if( name[len - 4] != '.' ) {
+ if (name[len - 4] != '.') {
return Q_ERR_INVALID_PATH;
}
- hash = FS_HashPathLen( name, len - 4, RIMAGES_HASH );
+ hash = FS_HashPathLen(name, len - 4, RIMAGES_HASH);
// look for it
- if( ( image = lookup_image( name, type, hash, len - 4 ) ) != NULL ) {
+ if ((image = lookup_image(name, type, hash, len - 4)) != NULL) {
image->registration_sequence = registration_sequence;
*image_p = image;
return Q_ERR_SUCCESS;
}
// copy filename off
- memcpy( buffer, name, len + 1 );
+ memcpy(buffer, name, len + 1);
ext = buffer + len - 3;
// find out original extension
- for( fmt = 0; fmt < im_unknown; fmt++ ) {
+ for (fmt = 0; fmt < im_unknown; fmt++) {
ldr = &img_loaders[fmt];
- if( !Q_stricmp( ext, ldr->ext ) ) {
+ if (!Q_stricmp(ext, ldr->ext)) {
break;
}
}
@@ -1646,50 +1683,50 @@ static qerror_t find_or_load_image( const char *name,
// load the pic from disk
pic = tmp = NULL;
#if USE_PNG || USE_JPG || USE_TGA
- if( fmt == im_unknown ) {
+ if (fmt == im_unknown) {
// unknown extension, but give it a chance to load anyway
- ret = try_other_formats( im_unknown, type,
- buffer, ext, &pic, &tmp, &width, &height );
- if( ret == Q_ERR_NOENT ) {
+ ret = try_other_formats(im_unknown, type,
+ buffer, ext, &pic, &tmp, &width, &height);
+ if (ret == Q_ERR_NOENT) {
// not found, change error to invalid path
ret = Q_ERR_INVALID_PATH;
}
- } else if( r_override_textures->integer ) {
+ } else if (r_override_textures->integer) {
// forcibly replace the extension
- ret = try_other_formats( im_unknown, type,
- buffer, ext, &pic, &tmp, &width, &height );
+ ret = try_other_formats(im_unknown, type,
+ buffer, ext, &pic, &tmp, &width, &height);
} else {
// first try with original extension
- ret = try_image_format( ldr, buffer, &pic, &tmp, &width, &height );
- if( ret == Q_ERR_NOENT ) {
+ ret = try_image_format(ldr, buffer, &pic, &tmp, &width, &height);
+ if (ret == Q_ERR_NOENT) {
// retry with remaining extensions
- ret = try_other_formats( fmt, type,
- buffer, ext, &pic, &tmp, &width, &height );
+ ret = try_other_formats(fmt, type,
+ buffer, ext, &pic, &tmp, &width, &height);
}
}
#else
- if( fmt == im_unknown ) {
+ if (fmt == im_unknown) {
return Q_ERR_INVALID_PATH;
}
- ret = try_image_format( ldr, buffer, &pic, &tmp, &width, &height );
+ ret = try_image_format(ldr, buffer, &pic, &tmp, &width, &height);
#endif
- if( ret < 0 ) {
+ if (ret < 0) {
return ret;
}
#if USE_REF == REF_GL
// don't need pics in memory after GL upload
- if( !tmp ) {
+ if (!tmp) {
tmp = pic;
}
#endif
// allocate image slot
image = alloc_image();
- memcpy( image->name, buffer, len + 1 );
+ memcpy(image->name, buffer, len + 1);
image->baselen = len - 4;
- List_Append( &r_imageHash[hash], &image->entry );
+ List_Append(&r_imageHash[hash], &image->entry);
// fill in some basic info
image->registration_sequence = registration_sequence;
@@ -1698,7 +1735,7 @@ static qerror_t find_or_load_image( const char *name,
image->width = width;
image->height = height;
- if( ret <= im_wal ) {
+ if (ret <= im_wal) {
image->flags |= if_paletted;
}
@@ -1706,45 +1743,46 @@ static qerror_t find_or_load_image( const char *name,
// if we are replacing 8-bit texture with a higher resolution 32-bit
// texture, we need to recover original image dimensions for proper
// texture alignment
- if( fmt <= im_wal && ret > im_wal ) {
- get_image_dimensions( image, fmt, buffer, ext );
+ if (fmt <= im_wal && ret > im_wal) {
+ get_image_dimensions(image, fmt, buffer, ext);
}
#endif
// upload the image to card
- IMG_Load( image, pic, width, height );
+ IMG_Load(image, pic, width, height);
// free any temp memory still remaining
- FS_FreeFile( tmp );
+ FS_FreeFile(tmp);
*image_p = image;
return Q_ERR_SUCCESS;
}
-image_t *IMG_Find( const char *name, imagetype_t type ) {
+image_t *IMG_Find(const char *name, imagetype_t type)
+{
image_t *image;
size_t len;
qerror_t ret;
- if( !name ) {
- Com_Error( ERR_FATAL, "%s: NULL", __func__ );
+ if (!name) {
+ Com_Error(ERR_FATAL, "%s: NULL", __func__);
}
// this should never happen
- len = strlen( name );
- if( len >= MAX_QPATH ) {
- Com_Error( ERR_FATAL, "%s: oversize name", __func__ );
+ len = strlen(name);
+ if (len >= MAX_QPATH) {
+ Com_Error(ERR_FATAL, "%s: oversize name", __func__);
}
- ret = find_or_load_image( name, len, type, &image );
- if( image ) {
+ ret = find_or_load_image(name, len, type, &image);
+ if (image) {
return image;
}
// don't spam about missing images
- if( ret != Q_ERR_NOENT ) {
- Com_EPrintf( "Couldn't load %s: %s\n", name, Q_ErrorString( ret ) );
+ if (ret != Q_ERR_NOENT) {
+ Com_EPrintf("Couldn't load %s: %s\n", name, Q_ErrorString(ret));
}
return R_NOTEXTURE;
@@ -1755,15 +1793,17 @@ image_t *IMG_Find( const char *name, imagetype_t type ) {
IMG_ForHandle
===============
*/
-image_t *IMG_ForHandle( qhandle_t h ) {
- if( h < 0 || h >= r_numImages ) {
- Com_Error( ERR_FATAL, "%s: %d out of range", __func__, h );
+image_t *IMG_ForHandle(qhandle_t h)
+{
+ if (h < 0 || h >= r_numImages) {
+ Com_Error(ERR_FATAL, "%s: %d out of range", __func__, h);
}
return &r_images[h];
}
-static qerror_t _register_image( const char *name, imagetype_t type, qhandle_t *handle ) {
+static qerror_t _register_image(const char *name, imagetype_t type, qhandle_t *handle)
+{
image_t *image;
char fullname[MAX_QPATH];
size_t len;
@@ -1771,53 +1811,54 @@ static qerror_t _register_image( const char *name, imagetype_t type, qhandle_t *
*handle = 0;
- if( !r_numImages ) {
+ if (!r_numImages) {
return Q_ERR_AGAIN;
}
- if( type == it_skin ) {
- len = FS_NormalizePathBuffer( fullname, name, sizeof( fullname ) );
- } else if( name[0] == '/' || name[0] == '\\' ) {
- len = FS_NormalizePathBuffer( fullname, name + 1, sizeof( fullname ) );
+ if (type == it_skin) {
+ len = FS_NormalizePathBuffer(fullname, name, sizeof(fullname));
+ } else if (name[0] == '/' || name[0] == '\\') {
+ len = FS_NormalizePathBuffer(fullname, name + 1, sizeof(fullname));
} else {
- len = Q_concat( fullname, sizeof( fullname ), "pics/", name, NULL );
- if( len >= sizeof( fullname ) ) {
+ len = Q_concat(fullname, sizeof(fullname), "pics/", name, NULL);
+ if (len >= sizeof(fullname)) {
return Q_ERR_NAMETOOLONG;
}
- FS_NormalizePath( fullname, fullname );
- len = COM_DefaultExtension( fullname, ".pcx", sizeof( fullname ) );
+ FS_NormalizePath(fullname, fullname);
+ len = COM_DefaultExtension(fullname, ".pcx", sizeof(fullname));
}
- if( len >= sizeof( fullname ) ) {
+ if (len >= sizeof(fullname)) {
return Q_ERR_NAMETOOLONG;
}
- ret = find_or_load_image( fullname, len, type, &image );
+ ret = find_or_load_image(fullname, len, type, &image);
- if( !image ) {
+ if (!image) {
return ret;
}
- *handle = ( image - r_images );
+ *handle = (image - r_images);
return Q_ERR_SUCCESS;
}
-static qhandle_t register_image( const char *name, imagetype_t type ) {
+static qhandle_t register_image(const char *name, imagetype_t type)
+{
qhandle_t handle;
qerror_t ret;
// empty names are legal, silently ignore them
- if( !*name )
+ if (!*name)
return 0;
- ret = _register_image( name, type, &handle );
- if( handle ) {
+ ret = _register_image(name, type, &handle);
+ if (handle) {
return handle;
}
// don't spam about missing images
- if( ret != Q_ERR_NOENT ) {
- Com_EPrintf( "Couldn't load %s: %s\n", name, Q_ErrorString( ret ) );
+ if (ret != Q_ERR_NOENT) {
+ Com_EPrintf("Couldn't load %s: %s\n", name, Q_ErrorString(ret));
}
return 0;
@@ -1828,8 +1869,9 @@ static qhandle_t register_image( const char *name, imagetype_t type ) {
R_RegisterSkin
===============
*/
-qhandle_t R_RegisterSkin( const char *name ) {
- return register_image( name, it_skin );
+qhandle_t R_RegisterSkin(const char *name)
+{
+ return register_image(name, it_skin);
}
/*
@@ -1837,12 +1879,14 @@ qhandle_t R_RegisterSkin( const char *name ) {
R_RegisterPic
================
*/
-qhandle_t R_RegisterPic( const char *name ) {
- return register_image( name, it_pic );
+qhandle_t R_RegisterPic(const char *name)
+{
+ return register_image(name, it_pic);
}
-qerror_t _R_RegisterPic( const char *name, qhandle_t *handle ) {
- return _register_image( name, it_pic, handle );
+qerror_t _R_RegisterPic(const char *name, qhandle_t *handle)
+{
+ return _register_image(name, it_pic, handle);
}
/*
@@ -1850,12 +1894,14 @@ qerror_t _R_RegisterPic( const char *name, qhandle_t *handle ) {
R_RegisterFont
================
*/
-qhandle_t R_RegisterFont( const char *name ) {
- return register_image( name, it_charset );
+qhandle_t R_RegisterFont(const char *name)
+{
+ return register_image(name, it_charset);
}
-qerror_t _R_RegisterFont( const char *name, qhandle_t *handle ) {
- return _register_image( name, it_charset, handle );
+qerror_t _R_RegisterFont(const char *name, qhandle_t *handle)
+{
+ return _register_image(name, it_charset, handle);
}
/*
@@ -1866,57 +1912,59 @@ Any image that was not touched on this registration sequence
will be freed.
================
*/
-void IMG_FreeUnused( void ) {
+void IMG_FreeUnused(void)
+{
image_t *image;
int i, count = 0;
- for( i = 1, image = r_images + 1; i < r_numImages; i++, image++ ) {
- if( image->registration_sequence == registration_sequence ) {
+ for (i = 1, image = r_images + 1; i < r_numImages; i++, image++) {
+ if (image->registration_sequence == registration_sequence) {
#if USE_REF == REF_SOFT
- Com_PageInMemory( image->pixels[0], image->width * image->height );
+ Com_PageInMemory(image->pixels[0], image->width * image->height);
#endif
continue; // used this sequence
}
- if( !image->registration_sequence )
+ if (!image->registration_sequence)
continue; // free image_t slot
- if( image->type == it_pic || image->type == it_charset )
+ if (image->type == it_pic || image->type == it_charset)
continue; // don't free pics
// delete it from hash table
- List_Remove( &image->entry );
+ List_Remove(&image->entry);
// free it
- IMG_Unload( image );
+ IMG_Unload(image);
- memset( image, 0, sizeof( *image ) );
+ memset(image, 0, sizeof(*image));
count++;
}
- if( count ) {
- Com_DPrintf( "%s: %i images freed\n", __func__, count );
+ if (count) {
+ Com_DPrintf("%s: %i images freed\n", __func__, count);
}
}
-void IMG_FreeAll( void ) {
+void IMG_FreeAll(void)
+{
image_t *image;
int i, count = 0;
- for( i = 1, image = r_images + 1; i < r_numImages; i++, image++ ) {
- if( !image->registration_sequence )
+ for (i = 1, image = r_images + 1; i < r_numImages; i++, image++) {
+ if (!image->registration_sequence)
continue; // free image_t slot
// free it
- IMG_Unload( image );
-
- memset( image, 0, sizeof( *image ) );
+ IMG_Unload(image);
+
+ memset(image, 0, sizeof(*image));
count++;
}
- if( count ) {
- Com_DPrintf( "%s: %i images freed\n", __func__, count );
+ if (count) {
+ Com_DPrintf("%s: %i images freed\n", __func__, count);
}
-
- for( i = 0; i < RIMAGES_HASH; i++ ) {
- List_Init( &r_imageHash[i] );
+
+ for (i = 0; i < RIMAGES_HASH; i++) {
+ List_Init(&r_imageHash[i]);
}
// &r_images[0] == R_NOTEXTURE
@@ -1931,7 +1979,8 @@ Reads the palette and (optionally) loads
the colormap for software renderer.
===============
*/
-byte *IMG_GetPalette( void ) {
+byte *IMG_GetPalette(void)
+{
static const char colormap[] = "pics/colormap.pcx";
byte pal[768], *src, *data, *pic;
qerror_t ret;
@@ -1942,43 +1991,43 @@ byte *IMG_GetPalette( void ) {
#endif
// get the palette
- len = FS_LoadFile( colormap, ( void ** )&data );
- if( !data ) {
+ len = FS_LoadFile(colormap, (void **)&data);
+ if (!data) {
ret = len;
goto fail;
}
#if USE_REF == REF_SOFT
- ret = _IMG_LoadPCX( data, len, &pic, pal, &w, &h );
+ ret = _IMG_LoadPCX(data, len, &pic, pal, &w, &h);
#else
- ret = _IMG_LoadPCX( data, len, NULL, pal, NULL, NULL );
+ ret = _IMG_LoadPCX(data, len, NULL, pal, NULL, NULL);
pic = NULL;
#endif
- FS_FreeFile( data );
+ FS_FreeFile(data);
- if( ret < 0 ) {
+ if (ret < 0) {
goto fail;
}
#if USE_REF == REF_SOFT
// check colormap size
- if( w != 256 || h != 320 ) {
+ if (w != 256 || h != 320) {
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
#endif
- for( i = 0, src = pal; i < 255; i++, src += 3 ) {
- d_8to24table[i] = MakeColor( src[0], src[1], src[2], 255 );
+ for (i = 0, src = pal; i < 255; i++, src += 3) {
+ d_8to24table[i] = MakeColor(src[0], src[1], src[2], 255);
}
// 255 is transparent
- d_8to24table[i] = MakeColor( src[0], src[1], src[2], 0 );
+ d_8to24table[i] = MakeColor(src[0], src[1], src[2], 0);
return pic;
fail:
- Com_Error( ERR_FATAL, "Couldn't load %s: %s", colormap, Q_ErrorString( ret ) );
+ Com_Error(ERR_FATAL, "Couldn't load %s: %s", colormap, Q_ErrorString(ret));
}
static const cmdreg_t img_cmd[] = {
@@ -2000,55 +2049,57 @@ static const cmdreg_t img_cmd[] = {
{ NULL }
};
-void IMG_Init( void ) {
+void IMG_Init(void)
+{
int i;
- if( r_numImages ) {
- Com_Error( ERR_FATAL, "%s: %d images not freed", __func__, r_numImages );
+ if (r_numImages) {
+ Com_Error(ERR_FATAL, "%s: %d images not freed", __func__, r_numImages);
}
#if USE_PNG || USE_JPG || USE_TGA
- r_override_textures = Cvar_Get( "r_override_textures", "1", CVAR_FILES );
- r_texture_formats = Cvar_Get( "r_texture_formats",
+ r_override_textures = Cvar_Get("r_override_textures", "1", CVAR_FILES);
+ r_texture_formats = Cvar_Get("r_texture_formats",
#if USE_PNG
- "p"
+ "p"
#endif
#if USE_JPG
- "j"
+ "j"
#endif
#if USE_TGA
- "t"
+ "t"
#endif
- , 0 );
+ , 0);
r_texture_formats->changed = r_texture_formats_changed;
- r_texture_formats_changed( r_texture_formats );
+ r_texture_formats_changed(r_texture_formats);
#if USE_JPG
- r_screenshot_format = Cvar_Get( "gl_screenshot_format", "jpg", 0 );
+ r_screenshot_format = Cvar_Get("gl_screenshot_format", "jpg", 0);
#elif USE_PNG
- r_screenshot_format = Cvar_Get( "gl_screenshot_format", "png", 0 );
+ r_screenshot_format = Cvar_Get("gl_screenshot_format", "png", 0);
#endif
#if USE_JPG
- r_screenshot_quality = Cvar_Get( "gl_screenshot_quality", "100", 0 );
+ r_screenshot_quality = Cvar_Get("gl_screenshot_quality", "100", 0);
#endif
#if USE_PNG
- r_screenshot_compression = Cvar_Get( "gl_screenshot_compression", "6", 0 );
+ r_screenshot_compression = Cvar_Get("gl_screenshot_compression", "6", 0);
#endif
#endif // USE_PNG || USE_JPG || USE_TGA
- Cmd_Register( img_cmd );
+ Cmd_Register(img_cmd);
- for( i = 0; i < RIMAGES_HASH; i++ ) {
- List_Init( &r_imageHash[i] );
+ for (i = 0; i < RIMAGES_HASH; i++) {
+ List_Init(&r_imageHash[i]);
}
// &r_images[0] == R_NOTEXTURE
r_numImages = 1;
}
-void IMG_Shutdown( void ) {
- Cmd_Deregister( img_cmd );
+void IMG_Shutdown(void)
+{
+ Cmd_Deregister(img_cmd);
r_numImages = 0;
}
diff --git a/src/r_models.c b/src/r_models.c
index 8cad2d0..d7bb37e 100644
--- a/src/r_models.c
+++ b/src/r_models.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -34,19 +34,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static model_t r_models[MAX_MODELS];
static int r_numModels;
-static model_t *MOD_Alloc( void ) {
+static model_t *MOD_Alloc(void)
+{
model_t *model;
int i;
- for( i = 0, model = r_models; i < r_numModels; i++, model++ ) {
- if( !model->type ) {
+ for (i = 0, model = r_models; i < r_numModels; i++, model++) {
+ if (!model->type) {
break;
}
}
- if( i == r_numModels ) {
- if( r_numModels == MAX_MODELS ) {
- Com_Error( ERR_DROP, "Model_Alloc: MAX_MODELS" );
+ if (i == r_numModels) {
+ if (r_numModels == MAX_MODELS) {
+ Com_Error(ERR_DROP, "Model_Alloc: MAX_MODELS");
}
r_numModels++;
}
@@ -54,15 +55,16 @@ static model_t *MOD_Alloc( void ) {
return model;
}
-static model_t *MOD_Find( const char *name ) {
+static model_t *MOD_Find(const char *name)
+{
model_t *model;
int i;
- for( i = 0, model = r_models; i < r_numModels; i++, model++ ) {
- if( !model->type ) {
+ for (i = 0, model = r_models; i < r_numModels; i++, model++) {
+ if (!model->type) {
continue;
}
- if( !FS_pathcmp( model->name, name ) ) {
+ if (!FS_pathcmp(model->name, name)) {
return model;
}
}
@@ -70,129 +72,134 @@ static model_t *MOD_Find( const char *name ) {
return NULL;
}
-static void MOD_List_f( void ) {
+static void MOD_List_f(void)
+{
static const char types[4] = "FASE";
int i, count;
model_t *model;
size_t bytes;
- Com_Printf( "------------------\n");
+ Com_Printf("------------------\n");
bytes = count = 0;
- for( i = 0, model = r_models; i < r_numModels; i++, model++ ) {
- if( !model->type ) {
+ for (i = 0, model = r_models; i < r_numModels; i++, model++) {
+ if (!model->type) {
continue;
}
- Com_Printf( "%c %8"PRIz" : %s\n", types[model->type],
- model->pool.mapped, model->name );
+ Com_Printf("%c %8"PRIz" : %s\n", types[model->type],
+ model->pool.mapped, model->name);
bytes += model->pool.mapped;
count++;
}
- Com_Printf( "Total models: %d (out of %d slots)\n", count, r_numModels );
- Com_Printf( "Total resident: %"PRIz"\n", bytes );
+ Com_Printf("Total models: %d (out of %d slots)\n", count, r_numModels);
+ Com_Printf("Total resident: %"PRIz"\n", bytes);
}
-void MOD_FreeUnused( void ) {
+void MOD_FreeUnused(void)
+{
model_t *model;
int i;
- for( i = 0, model = r_models; i < r_numModels; i++, model++ ) {
- if( !model->type ) {
+ for (i = 0, model = r_models; i < r_numModels; i++, model++) {
+ if (!model->type) {
continue;
}
- if( model->registration_sequence == registration_sequence ) {
+ if (model->registration_sequence == registration_sequence) {
// make sure it is paged in
- Com_PageInMemory( model->pool.base, model->pool.cursize );
+ Com_PageInMemory(model->pool.base, model->pool.cursize);
} else {
// don't need this model
- Hunk_Free( &model->pool );
- memset( model, 0, sizeof( *model ) );
+ Hunk_Free(&model->pool);
+ memset(model, 0, sizeof(*model));
}
}
}
-void MOD_FreeAll( void ) {
+void MOD_FreeAll(void)
+{
model_t *model;
int i;
- for( i = 0, model = r_models; i < r_numModels; i++, model++ ) {
- if( !model->type ) {
+ for (i = 0, model = r_models; i < r_numModels; i++, model++) {
+ if (!model->type) {
continue;
}
- Hunk_Free( &model->pool );
- memset( model, 0, sizeof( *model ) );
+ Hunk_Free(&model->pool);
+ memset(model, 0, sizeof(*model));
}
r_numModels = 0;
}
-qerror_t MOD_ValidateMD2( dmd2header_t *header, size_t length ) {
+qerror_t MOD_ValidateMD2(dmd2header_t *header, size_t length)
+{
size_t end;
// check ident and version
- if( header->ident != MD2_IDENT )
+ if (header->ident != MD2_IDENT)
return Q_ERR_UNKNOWN_FORMAT;
- if( header->version != MD2_VERSION )
+ if (header->version != MD2_VERSION)
return Q_ERR_UNKNOWN_FORMAT;
// check triangles
- if( header->num_tris < 1 )
+ if (header->num_tris < 1)
return Q_ERR_TOO_FEW;
- if( header->num_tris > MD2_MAX_TRIANGLES )
+ if (header->num_tris > MD2_MAX_TRIANGLES)
return Q_ERR_TOO_MANY;
-
- end = header->ofs_tris + sizeof( dmd2triangle_t ) * header->num_tris;
- if( header->ofs_tris < sizeof( header ) || end < header->ofs_tris || end > length )
+
+ end = header->ofs_tris + sizeof(dmd2triangle_t) * header->num_tris;
+ if (header->ofs_tris < sizeof(header) || end < header->ofs_tris || end > length)
return Q_ERR_BAD_EXTENT;
// check st
- if( header->num_st < 3 )
+ if (header->num_st < 3)
return Q_ERR_TOO_FEW;
- if( header->num_st > MD2_MAX_VERTS )
+ if (header->num_st > MD2_MAX_VERTS)
return Q_ERR_TOO_MANY;
- end = header->ofs_st + sizeof( dmd2stvert_t ) * header->num_st;
- if( header->ofs_st < sizeof( header ) || end < header->ofs_st || end > length )
+ end = header->ofs_st + sizeof(dmd2stvert_t) * header->num_st;
+ if (header->ofs_st < sizeof(header) || end < header->ofs_st || end > length)
return Q_ERR_BAD_EXTENT;
// check xyz and frames
- if( header->num_xyz < 3 )
+ if (header->num_xyz < 3)
return Q_ERR_TOO_FEW;
- if( header->num_xyz > MD2_MAX_VERTS )
+ if (header->num_xyz > MD2_MAX_VERTS)
return Q_ERR_TOO_MANY;
- if( header->num_frames < 1 )
+ if (header->num_frames < 1)
return Q_ERR_TOO_FEW;
- if( header->num_frames > MD2_MAX_FRAMES )
+ if (header->num_frames > MD2_MAX_FRAMES)
return Q_ERR_TOO_MANY;
- end = sizeof( dmd2frame_t ) + ( header->num_xyz - 1 ) * sizeof( dmd2trivertx_t );
- if( header->framesize < end || header->framesize > MD2_MAX_FRAMESIZE )
+ end = sizeof(dmd2frame_t) + (header->num_xyz - 1) * sizeof(dmd2trivertx_t);
+ if (header->framesize < end || header->framesize > MD2_MAX_FRAMESIZE)
return Q_ERR_BAD_EXTENT;
- end = header->ofs_frames + ( size_t )header->framesize * header->num_frames;
- if( header->ofs_frames < sizeof( header ) || end < header->ofs_frames || end > length )
+ end = header->ofs_frames + (size_t)header->framesize * header->num_frames;
+ if (header->ofs_frames < sizeof(header) || end < header->ofs_frames || end > length)
return Q_ERR_BAD_EXTENT;
// check skins
- if( header->num_skins ) {
- if( header->num_skins > MAX_ALIAS_SKINS )
+ if (header->num_skins) {
+ if (header->num_skins > MAX_ALIAS_SKINS)
return Q_ERR_TOO_MANY;
- end = header->ofs_skins + ( size_t )MD2_MAX_SKINNAME * header->num_skins;
- if( header->ofs_skins < sizeof( header ) || end < header->ofs_skins || end > length )
+ end = header->ofs_skins + (size_t)MD2_MAX_SKINNAME * header->num_skins;
+ if (header->ofs_skins < sizeof(header) || end < header->ofs_skins || end > length)
return Q_ERR_BAD_EXTENT;
}
- if( header->skinwidth < 1 || header->skinwidth > MD2_MAX_SKINWIDTH )
+ if (header->skinwidth < 1 || header->skinwidth > MD2_MAX_SKINWIDTH)
return Q_ERR_INVALID_FORMAT;
- if( header->skinheight < 1 || header->skinheight > MD2_MAX_SKINHEIGHT )
+ if (header->skinheight < 1 || header->skinheight > MD2_MAX_SKINHEIGHT)
return Q_ERR_INVALID_FORMAT;
return Q_ERR_SUCCESS;
}
-static qerror_t MOD_LoadSP2( model_t *model, const void *rawdata, size_t length ) {
+static qerror_t MOD_LoadSP2(model_t *model, const void *rawdata, size_t length)
+{
dsp2header_t header;
dsp2frame_t *src_frame;
mspriteframe_t *dst_frame;
@@ -200,42 +207,42 @@ static qerror_t MOD_LoadSP2( model_t *model, const void *rawdata, size_t length
char buffer[SP2_MAX_FRAMENAME];
int i;
- if( length < sizeof( header ) )
+ if (length < sizeof(header))
return Q_ERR_FILE_TOO_SMALL;
// byte swap the header
- header = *( dsp2header_t * )rawdata;
- for( i = 0; i < sizeof( header )/4; i++ ) {
- (( uint32_t * )&header)[i] = LittleLong( (( uint32_t * )&header)[i] );
+ header = *(dsp2header_t *)rawdata;
+ for (i = 0; i < sizeof(header) / 4; i++) {
+ ((uint32_t *)&header)[i] = LittleLong(((uint32_t *)&header)[i]);
}
- if( header.ident != SP2_IDENT )
+ if (header.ident != SP2_IDENT)
return Q_ERR_UNKNOWN_FORMAT;
- if( header.version != SP2_VERSION )
+ if (header.version != SP2_VERSION)
return Q_ERR_UNKNOWN_FORMAT;
- if( header.numframes < 1 ) {
+ if (header.numframes < 1) {
// empty models draw nothing
model->type = MOD_EMPTY;
return Q_ERR_SUCCESS;
}
- if( header.numframes > SP2_MAX_FRAMES )
+ if (header.numframes > SP2_MAX_FRAMES)
return Q_ERR_TOO_MANY;
- if( sizeof( dsp2header_t ) + sizeof( dsp2frame_t ) * header.numframes > length )
+ if (sizeof(dsp2header_t) + sizeof(dsp2frame_t) * header.numframes > length)
return Q_ERR_BAD_EXTENT;
- Hunk_Begin( &model->pool, 0x10000 );
+ Hunk_Begin(&model->pool, 0x10000);
model->type = MOD_SPRITE;
- model->spriteframes = MOD_Malloc( sizeof( mspriteframe_t ) * header.numframes );
+ model->spriteframes = MOD_Malloc(sizeof(mspriteframe_t) * header.numframes);
model->numframes = header.numframes;
- src_frame = ( dsp2frame_t * )( ( byte * )rawdata + sizeof( dsp2header_t ) );
+ src_frame = (dsp2frame_t *)((byte *)rawdata + sizeof(dsp2header_t));
dst_frame = model->spriteframes;
- for( i = 0; i < header.numframes; i++ ) {
- w = LittleLong( src_frame->width );
- h = LittleLong( src_frame->height );
- if( w < 1 || h < 1 || w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE ) {
- Com_WPrintf( "%s has bad frame dimensions\n", model->name );
+ for (i = 0; i < header.numframes; i++) {
+ w = LittleLong(src_frame->width);
+ h = LittleLong(src_frame->height);
+ if (w < 1 || h < 1 || w > MAX_TEXTURE_SIZE || h > MAX_TEXTURE_SIZE) {
+ Com_WPrintf("%s has bad frame dimensions\n", model->name);
w = 1;
h = 1;
}
@@ -243,33 +250,34 @@ static qerror_t MOD_LoadSP2( model_t *model, const void *rawdata, size_t length
dst_frame->height = h;
// FIXME: are these signed?
- x = LittleLong( src_frame->origin_x );
- y = LittleLong( src_frame->origin_y );
- if( x > 8192 || y > 8192 ) {
- Com_WPrintf( "%s has bad frame origin\n", model->name );
+ x = LittleLong(src_frame->origin_x);
+ y = LittleLong(src_frame->origin_y);
+ if (x > 8192 || y > 8192) {
+ Com_WPrintf("%s has bad frame origin\n", model->name);
x = y = 0;
}
dst_frame->origin_x = x;
dst_frame->origin_y = y;
- if( !Q_memccpy( buffer, src_frame->name, 0, sizeof( buffer ) ) ) {
- Com_WPrintf( "%s has bad frame name\n", model->name );
+ if (!Q_memccpy(buffer, src_frame->name, 0, sizeof(buffer))) {
+ Com_WPrintf("%s has bad frame name\n", model->name);
dst_frame->image = R_NOTEXTURE;
} else {
- FS_NormalizePath( buffer, buffer );
- dst_frame->image = IMG_Find( buffer, it_sprite );
+ FS_NormalizePath(buffer, buffer);
+ dst_frame->image = IMG_Find(buffer, it_sprite);
}
src_frame++;
dst_frame++;
}
- Hunk_End( &model->pool );
+ Hunk_End(&model->pool);
return Q_ERR_SUCCESS;
}
-qhandle_t R_RegisterModel( const char *name ) {
+qhandle_t R_RegisterModel(const char *name)
+{
char normalized[MAX_QPATH];
qhandle_t index;
size_t namelen;
@@ -281,39 +289,39 @@ qhandle_t R_RegisterModel( const char *name ) {
qerror_t ret;
// empty names are legal, silently ignore them
- if( !*name )
+ if (!*name)
return 0;
- if( *name == '*' ) {
+ if (*name == '*') {
// inline bsp model
- index = atoi( name + 1 );
+ index = atoi(name + 1);
return ~index;
}
// normalize the path
- namelen = FS_NormalizePathBuffer( normalized, name, MAX_QPATH );
+ namelen = FS_NormalizePathBuffer(normalized, name, MAX_QPATH);
// this should never happen
- if( namelen >= MAX_QPATH )
- Com_Error( ERR_DROP, "%s: oversize name", __func__ );
+ if (namelen >= MAX_QPATH)
+ Com_Error(ERR_DROP, "%s: oversize name", __func__);
// normalized to empty name?
- if( namelen == 0 ) {
- Com_DPrintf( "%s: empty name\n", __func__ );
+ if (namelen == 0) {
+ Com_DPrintf("%s: empty name\n", __func__);
return 0;
}
// see if it's already loaded
- model = MOD_Find( normalized );
- if( model ) {
- MOD_Reference( model );
+ model = MOD_Find(normalized);
+ if (model) {
+ MOD_Reference(model);
goto done;
}
- filelen = FS_LoadFile( normalized, ( void ** )&rawdata );
- if( !rawdata ) {
+ filelen = FS_LoadFile(normalized, (void **)&rawdata);
+ if (!rawdata) {
// don't spam about missing models
- if( filelen == Q_ERR_NOENT ) {
+ if (filelen == Q_ERR_NOENT) {
return 0;
}
@@ -321,14 +329,14 @@ qhandle_t R_RegisterModel( const char *name ) {
goto fail1;
}
- if( filelen < 4 ) {
+ if (filelen < 4) {
ret = Q_ERR_FILE_TOO_SMALL;
goto fail2;
}
// check ident
- ident = LittleLong( *( uint32_t * )rawdata );
- switch( ident ) {
+ ident = LittleLong(*(uint32_t *)rawdata);
+ switch (ident) {
case MD2_IDENT:
load = MOD_LoadMD2;
break;
@@ -346,58 +354,61 @@ qhandle_t R_RegisterModel( const char *name ) {
}
model = MOD_Alloc();
- memcpy( model->name, normalized, namelen + 1 );
+ memcpy(model->name, normalized, namelen + 1);
model->registration_sequence = registration_sequence;
- ret = load( model, rawdata, filelen );
+ ret = load(model, rawdata, filelen);
- FS_FreeFile( rawdata );
+ FS_FreeFile(rawdata);
- if( ret ) {
- memset( model, 0, sizeof( *model ) );
+ if (ret) {
+ memset(model, 0, sizeof(*model));
goto fail1;
}
done:
- index = ( model - r_models ) + 1;
+ index = (model - r_models) + 1;
return index;
fail2:
- FS_FreeFile( rawdata );
+ FS_FreeFile(rawdata);
fail1:
- Com_EPrintf( "Couldn't load %s: %s\n", normalized, Q_ErrorString( ret ) );
+ Com_EPrintf("Couldn't load %s: %s\n", normalized, Q_ErrorString(ret));
return 0;
}
-model_t *MOD_ForHandle( qhandle_t h ) {
+model_t *MOD_ForHandle(qhandle_t h)
+{
model_t *model;
- if( !h ) {
+ if (!h) {
return NULL;
}
- if( h < 0 || h > r_numModels ) {
- Com_Error( ERR_DROP, "%s: %d out of range", __func__, h );
+ if (h < 0 || h > r_numModels) {
+ Com_Error(ERR_DROP, "%s: %d out of range", __func__, h);
}
- model = &r_models[ h - 1 ];
- if( !model->type ) {
+ model = &r_models[h - 1];
+ if (!model->type) {
return NULL;
}
return model;
}
-void MOD_Init( void ) {
- if( r_numModels ) {
- Com_Error( ERR_FATAL, "%s: %d models not freed", __func__, r_numModels );
+void MOD_Init(void)
+{
+ if (r_numModels) {
+ Com_Error(ERR_FATAL, "%s: %d models not freed", __func__, r_numModels);
}
- Cmd_AddCommand( "modellist", MOD_List_f );
+ Cmd_AddCommand("modellist", MOD_List_f);
}
-void MOD_Shutdown( void ) {
+void MOD_Shutdown(void)
+{
MOD_FreeAll();
- Cmd_RemoveCommand( "modellist" );
+ Cmd_RemoveCommand("modellist");
}
diff --git a/src/r_models.h b/src/r_models.h
index ed62370..6887e58 100644
--- a/src/r_models.h
+++ b/src/r_models.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,7 +26,7 @@ MODEL MANAGER
=============================================================================
*/
-#define MOD_Malloc( size ) Hunk_Alloc( &model->pool, size )
+#define MOD_Malloc(size) Hunk_Alloc(&model->pool, size)
// FIXME: MD3 has 256 limit
#define MAX_ALIAS_SKINS 32
@@ -71,22 +71,22 @@ typedef struct model_s {
extern int registration_sequence;
// these are implemented in r_models.c
-void MOD_FreeUnused( void );
-void MOD_FreeAll( void );
-void MOD_Init( void );
-void MOD_Shutdown( void );
+void MOD_FreeUnused(void);
+void MOD_FreeAll(void);
+void MOD_Init(void);
+void MOD_Shutdown(void);
-model_t *MOD_ForHandle( qhandle_t h );
-qhandle_t R_RegisterModel( const char *name );
+model_t *MOD_ForHandle(qhandle_t h);
+qhandle_t R_RegisterModel(const char *name);
struct dmd2header_s;
-qerror_t MOD_ValidateMD2( struct dmd2header_s *header, size_t length );
+qerror_t MOD_ValidateMD2(struct dmd2header_s *header, size_t length);
// these are implemented in [gl,sw]_models.c
-typedef qerror_t (*mod_load_t)( model_t *, const void *, size_t );
-qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length );
+typedef qerror_t (*mod_load_t)(model_t *, const void *, size_t);
+qerror_t MOD_LoadMD2(model_t *model, const void *rawdata, size_t length);
#if USE_MD3
-qerror_t MOD_LoadMD3( model_t *model, const void *rawdata, size_t length );
+qerror_t MOD_LoadMD3(model_t *model, const void *rawdata, size_t length);
#endif
-void MOD_Reference( model_t *model );
+void MOD_Reference(model_t *model);
diff --git a/src/r_shared.h b/src/r_shared.h
index ebf66db..78a4cd9 100644
--- a/src/r_shared.h
+++ b/src/r_shared.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,19 +26,19 @@ IMAGE MANAGER
=============================================================================
*/
-#define R_Malloc( size ) Z_TagMalloc( size, TAG_RENDERER )
-#define R_Mallocz( size ) Z_TagMallocz( size, TAG_RENDERER )
+#define R_Malloc(size) Z_TagMalloc(size, TAG_RENDERER)
+#define R_Mallocz(size) Z_TagMallocz(size, TAG_RENDERER)
#if USE_REF == REF_GL
-#define IMG_AllocPixels( x ) FS_AllocTempMem( x )
-#define IMG_FreePixels( x ) FS_FreeTempMem( x )
+#define IMG_AllocPixels(x) FS_AllocTempMem(x)
+#define IMG_FreePixels(x) FS_FreeTempMem(x)
#else
-#define IMG_AllocPixels( x ) R_Malloc( x )
-#define IMG_FreePixels( x ) Z_Free( x )
+#define IMG_AllocPixels(x) R_Malloc(x)
+#define IMG_FreePixels(x) Z_Free(x)
#endif
#if USE_REF == REF_SOFT
-#define MIPSIZE(c) ((c)*(256+64+16+4)/256)
+#define MIPSIZE(c) ((c) * (256 + 64 + 16 + 4) / 256)
#else
#define MIPSIZE(c) (c)
#endif
@@ -51,7 +51,7 @@ IMAGE MANAGER
#endif
// size of GL_Upload8 internal buffer
-#define MAX_PALETTED_PIXELS (512*256)
+#define MAX_PALETTED_PIXELS (512 * 256)
/*
@@ -67,9 +67,9 @@ IMAGE MANAGER
*/
typedef enum {
- if_transparent = ( 1 << 0 ),
- if_paletted = ( 1 << 1 ),
- if_scrap = ( 1 << 2 )
+ if_transparent = (1 << 0),
+ if_paletted = (1 << 1),
+ if_scrap = (1 << 2)
} imageflags_t;
typedef enum {
@@ -125,26 +125,26 @@ extern int registration_sequence;
extern uint32_t d_8to24table[256];
// these are implemented in r_images.c
-image_t *IMG_Find( const char *name, imagetype_t type );
-void IMG_FreeUnused( void );
-void IMG_FreeAll( void );
-void IMG_Init( void );
-void IMG_Shutdown( void );
-byte *IMG_GetPalette( void );
-
-image_t *IMG_ForHandle( qhandle_t h );
-qhandle_t R_RegisterSkin( const char *name );
-qhandle_t R_RegisterPic( const char *name );
-qhandle_t R_RegisterFont( const char *name );
-qerror_t _R_RegisterPic( const char *name, qhandle_t *handle );
-qerror_t _R_RegisterFont( const char *name, qhandle_t *handle );
+image_t *IMG_Find(const char *name, imagetype_t type);
+void IMG_FreeUnused(void);
+void IMG_FreeAll(void);
+void IMG_Init(void);
+void IMG_Shutdown(void);
+byte *IMG_GetPalette(void);
+
+image_t *IMG_ForHandle(qhandle_t h);
+qhandle_t R_RegisterSkin(const char *name);
+qhandle_t R_RegisterPic(const char *name);
+qhandle_t R_RegisterFont(const char *name);
+qerror_t _R_RegisterPic(const char *name, qhandle_t *handle);
+qerror_t _R_RegisterFont(const char *name, qhandle_t *handle);
// these are implemented in [gl,sw]_images.c
-void IMG_Unload( image_t *image );
-void IMG_Load( image_t *image, byte *pic, int width, int height );
+void IMG_Unload(image_t *image);
+void IMG_Load(image_t *image, byte *pic, int width, int height);
#if USE_REF == REF_SOFT
-byte *IMG_ReadPixels( byte **palette, int *width, int *height, int *rowbytes );
+byte *IMG_ReadPixels(byte **palette, int *width, int *height, int *rowbytes);
#else
-byte *IMG_ReadPixels( qboolean reverse, int *width, int *height );
+byte *IMG_ReadPixels(qboolean reverse, int *width, int *height);
#endif
diff --git a/src/rand1k.h b/src/rand1k.h
index 41a54f7..e7cba34 100644
--- a/src/rand1k.h
+++ b/src/rand1k.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
// 1K random numbers in the range 0-255
0, 144, 49, 207, 149, 122, 89, 229, 210, 191,
44, 219, 181, 131, 77, 3, 23, 93, 37, 42,
diff --git a/src/ref_public.h b/src/ref_public.h
index 222b01e..51c76b4 100644
--- a/src/ref_public.h
+++ b/src/ref_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -133,10 +133,10 @@ typedef struct refdef_s {
} refdef_t;
typedef enum {
- QVF_ACCELERATED = ( 1 << 0 ),
- QVF_GAMMARAMP = ( 1 << 1 ),
- QVF_FULLSCREEN = ( 1 << 2 ),
- QVF_VIDEOSYNC = ( 1 << 3 )
+ QVF_ACCELERATED = (1 << 0),
+ QVF_GAMMARAMP = (1 << 1),
+ QVF_FULLSCREEN = (1 << 2),
+ QVF_VIDEOSYNC = (1 << 3)
} vidFlags_t;
typedef struct {
@@ -159,10 +159,10 @@ typedef struct {
} clipRect_t;
// called when the library is loaded
-qboolean R_Init( qboolean total );
+qboolean R_Init(qboolean total);
// called before the library is unloaded
-void R_Shutdown( qboolean total );
+void R_Shutdown(qboolean total);
// All data that will be used in a level should be
// registered before rendering any frames to prevent disk hits,
@@ -177,42 +177,42 @@ void R_Shutdown( qboolean total );
// are flood filled to eliminate mip map edge errors, and pics have
// an implicit "pics/" prepended to the name. (a pic name that starts with a
// slash will not use the "pics/" prefix or the ".pcx" postfix)
-void R_BeginRegistration( const char *map );
-qhandle_t R_RegisterModel( const char *name );
-qhandle_t R_RegisterSkin( const char *name );
-qhandle_t R_RegisterPic( const char *name );
-qhandle_t R_RegisterFont( const char *name );
-qerror_t _R_RegisterPic( const char *name, qhandle_t *handle );
-qerror_t _R_RegisterFont( const char *name, qhandle_t *handle );
-void R_SetSky( const char *name, float rotate, vec3_t axis );
-void R_EndRegistration( void );
-
-void R_RenderFrame( refdef_t *fd );
-void R_LightPoint( vec3_t origin, vec3_t light );
-
-void R_ClearColor( void );
-void R_SetAlpha( float clpha );
-void R_SetColor( uint32_t color );
-void R_SetClipRect( int flags, const clipRect_t *clip );
-void R_SetScale( float *scale );
-void R_DrawChar( int x, int y, int flags, int ch, qhandle_t font );
-int R_DrawString( int x, int y, int flags, size_t maxChars,
- const char *string, qhandle_t font ); // returns advanced x coord
-qboolean R_GetPicSize( int *w, int *h, qhandle_t pic ); // returns transparency bit
-void R_DrawPic( int x, int y, qhandle_t pic );
-void R_DrawStretchPic( int x, int y, int w, int h, qhandle_t pic );
-void R_DrawStretchPicST( int x, int y, int w, int h,
- float s1, float t1, float s2, float t2, qhandle_t pic );
-void R_TileClear( int x, int y, int w, int h, qhandle_t pic );
-void R_DrawFill8( int x, int y, int w, int h, int c );
-void R_DrawFill32( int x, int y, int w, int h, uint32_t color );
+void R_BeginRegistration(const char *map);
+qhandle_t R_RegisterModel(const char *name);
+qhandle_t R_RegisterSkin(const char *name);
+qhandle_t R_RegisterPic(const char *name);
+qhandle_t R_RegisterFont(const char *name);
+qerror_t _R_RegisterPic(const char *name, qhandle_t *handle);
+qerror_t _R_RegisterFont(const char *name, qhandle_t *handle);
+void R_SetSky(const char *name, float rotate, vec3_t axis);
+void R_EndRegistration(void);
+
+void R_RenderFrame(refdef_t *fd);
+void R_LightPoint(vec3_t origin, vec3_t light);
+
+void R_ClearColor(void);
+void R_SetAlpha(float clpha);
+void R_SetColor(uint32_t color);
+void R_SetClipRect(int flags, const clipRect_t *clip);
+void R_SetScale(float *scale);
+void R_DrawChar(int x, int y, int flags, int ch, qhandle_t font);
+int R_DrawString(int x, int y, int flags, size_t maxChars,
+ const char *string, qhandle_t font); // returns advanced x coord
+qboolean R_GetPicSize(int *w, int *h, qhandle_t pic); // returns transparency bit
+void R_DrawPic(int x, int y, qhandle_t pic);
+void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic);
+void R_DrawStretchPicST(int x, int y, int w, int h,
+ float s1, float t1, float s2, float t2, qhandle_t pic);
+void R_TileClear(int x, int y, int w, int h, qhandle_t pic);
+void R_DrawFill8(int x, int y, int w, int h, int c);
+void R_DrawFill32(int x, int y, int w, int h, uint32_t color);
// video mode and refresh state management entry points
-void R_BeginFrame( void );
-void R_EndFrame( void );
-void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels );
+void R_BeginFrame(void);
+void R_EndFrame(void);
+void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels);
#if 0
-void R_CinematicSetPalette( const byte *palette );
+void R_CinematicSetPalette(const byte *palette);
#endif
#endif // __REF_H
diff --git a/src/snd_al.c b/src/snd_al.c
index bb4f337..d91d966 100644
--- a/src/snd_al.c
+++ b/src/snd_al.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -32,48 +32,50 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static ALuint s_srcnums[MAX_CHANNELS];
static int s_framecount;
-void AL_SoundInfo( void ) {
- Com_Printf( "AL_VENDOR: %s\n", qalGetString( AL_VENDOR ) );
- Com_Printf( "AL_RENDERER: %s\n", qalGetString( AL_RENDERER ) );
- Com_Printf( "AL_VERSION: %s\n", qalGetString( AL_VERSION ) );
- Com_Printf( "AL_EXTENSIONS: %s\n", qalGetString( AL_EXTENSIONS ) );
- Com_Printf( "Number of sources: %d\n", s_numchannels );
+void AL_SoundInfo(void)
+{
+ Com_Printf("AL_VENDOR: %s\n", qalGetString(AL_VENDOR));
+ Com_Printf("AL_RENDERER: %s\n", qalGetString(AL_RENDERER));
+ Com_Printf("AL_VERSION: %s\n", qalGetString(AL_VERSION));
+ Com_Printf("AL_EXTENSIONS: %s\n", qalGetString(AL_EXTENSIONS));
+ Com_Printf("Number of sources: %d\n", s_numchannels);
}
-qboolean AL_Init( void ) {
+qboolean AL_Init(void)
+{
int i;
- Com_DPrintf( "Initializing OpenAL\n" );
+ Com_DPrintf("Initializing OpenAL\n");
- if( !QAL_Init() ) {
+ if (!QAL_Init()) {
return qfalse;
}
// check for linear distance extension
- if( !qalIsExtensionPresent( "AL_EXT_LINEAR_DISTANCE" ) ) {
- Com_DPrintf( "AL_EXT_LINEAR_DISTANCE extension is missing\n" );
+ if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) {
+ Com_DPrintf("AL_EXT_LINEAR_DISTANCE extension is missing\n");
goto fail;
}
// generate source names
qalGetError();
- for( i = 0; i < MAX_CHANNELS; i++ ) {
- qalGenSources( 1, &s_srcnums[i] );
- if( qalGetError() != AL_NO_ERROR ) {
+ for (i = 0; i < MAX_CHANNELS; i++) {
+ qalGenSources(1, &s_srcnums[i]);
+ if (qalGetError() != AL_NO_ERROR) {
break;
}
}
- Com_DPrintf( "Got %d AL sources\n", i );
+ Com_DPrintf("Got %d AL sources\n", i);
- if( i < MIN_CHANNELS ) {
- Com_DPrintf( "Insufficient number of sources\n" );
+ if (i < MIN_CHANNELS) {
+ Com_DPrintf("Insufficient number of sources\n");
goto fail;
}
s_numchannels = i;
- Com_Printf( "OpenAL initialized.\n" );
+ Com_Printf("OpenAL initialized.\n");
return qtrue;
fail:
@@ -81,40 +83,42 @@ fail:
return qfalse;
}
-void AL_Shutdown( void ) {
- Com_Printf( "Shutting down OpenAL.\n" );
+void AL_Shutdown(void)
+{
+ Com_Printf("Shutting down OpenAL.\n");
- if( s_numchannels ) {
+ if (s_numchannels) {
// delete source names
- qalDeleteSources( s_numchannels, s_srcnums );
- memset( s_srcnums, 0, sizeof( s_srcnums ) );
+ qalDeleteSources(s_numchannels, s_srcnums);
+ memset(s_srcnums, 0, sizeof(s_srcnums));
s_numchannels = 0;
}
QAL_Shutdown();
}
-sfxcache_t *AL_UploadSfx( sfx_t *s ) {
+sfxcache_t *AL_UploadSfx(sfx_t *s)
+{
sfxcache_t *sc;
ALsizei size = s_info.samples * s_info.width;
ALenum format = s_info.width == 2 ? AL_FORMAT_MONO16 : AL_FORMAT_MONO8;
ALuint name;
- if( !size ) {
+ if (!size) {
s->error = Q_ERR_TOO_FEW;
return NULL;
}
qalGetError();
- qalGenBuffers( 1, &name );
- qalBufferData( name, format, s_info.data, size, s_info.rate );
- if( qalGetError() != AL_NO_ERROR ) {
+ qalGenBuffers(1, &name);
+ qalBufferData(name, format, s_info.data, size, s_info.rate);
+ if (qalGetError() != AL_NO_ERROR) {
s->error = Q_ERR_LIBRARY_ERROR;
return NULL;
}
// allocate placeholder sfxcache
- sc = s->cache = S_Malloc( sizeof( *sc ) );
+ sc = s->cache = S_Malloc(sizeof(*sc));
sc->length = s_info.samples * 1000 / s_info.rate; // in msec
sc->loopstart = s_info.loopstart;
sc->width = s_info.width;
@@ -124,75 +128,80 @@ sfxcache_t *AL_UploadSfx( sfx_t *s ) {
return sc;
}
-void AL_DeleteSfx( sfx_t *s ) {
+void AL_DeleteSfx(sfx_t *s)
+{
sfxcache_t *sc;
ALuint name;
sc = s->cache;
- if( !sc ) {
+ if (!sc) {
return;
}
name = sc->bufnum;
- qalDeleteBuffers( 1, &name );
+ qalDeleteBuffers(1, &name);
}
-static void AL_Spatialize( channel_t *ch ) {
+static void AL_Spatialize(channel_t *ch)
+{
vec3_t origin;
// anything coming from the view entity will always be full volume
// no attenuation = no spatialization
- if( ch->entnum == -1 || ch->entnum == listener_entnum || !ch->dist_mult ) {
- VectorCopy( listener_origin, origin );
- } else if( ch->fixed_origin ) {
- VectorCopy( ch->origin, origin );
+ if (ch->entnum == -1 || ch->entnum == listener_entnum || !ch->dist_mult) {
+ VectorCopy(listener_origin, origin);
+ } else if (ch->fixed_origin) {
+ VectorCopy(ch->origin, origin);
} else {
- CL_GetEntitySoundOrigin( ch->entnum, origin );
+ CL_GetEntitySoundOrigin(ch->entnum, origin);
}
- qalSource3f( ch->srcnum, AL_POSITION, AL_UnpackVector( origin ) );
+ qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin));
}
-void AL_StopChannel( channel_t *ch ) {
+void AL_StopChannel(channel_t *ch)
+{
#ifdef _DEBUG
if (s_show->integer > 1)
- Com_Printf("%s: %s\n", __func__, ch->sfx->name );
+ Com_Printf("%s: %s\n", __func__, ch->sfx->name);
#endif
// stop it
- qalSourceStop( ch->srcnum );
- qalSourcei( ch->srcnum, AL_BUFFER, AL_NONE );
- memset (ch, 0, sizeof(*ch));
+ qalSourceStop(ch->srcnum);
+ qalSourcei(ch->srcnum, AL_BUFFER, AL_NONE);
+ memset(ch, 0, sizeof(*ch));
}
-void AL_PlayChannel( channel_t *ch ) {
+void AL_PlayChannel(channel_t *ch)
+{
sfxcache_t *sc = ch->sfx->cache;
#ifdef _DEBUG
if (s_show->integer > 1)
- Com_Printf("%s: %s\n", __func__, ch->sfx->name );
+ Com_Printf("%s: %s\n", __func__, ch->sfx->name);
#endif
ch->srcnum = s_srcnums[ch - channels];
qalGetError();
- qalSourcei( ch->srcnum, AL_BUFFER, sc->bufnum );
- //qalSourcei( ch->srcnum, AL_LOOPING, sc->loopstart == -1 ? AL_FALSE : AL_TRUE );
- qalSourcei( ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE );
- qalSourcef( ch->srcnum, AL_GAIN, ch->master_vol );
- qalSourcef( ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME );
- qalSourcef( ch->srcnum, AL_MAX_DISTANCE, 8192 );
- qalSourcef( ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * ( 8192 - SOUND_FULLVOLUME ) );
+ qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum);
+ //qalSourcei(ch->srcnum, AL_LOOPING, sc->loopstart == -1 ? AL_FALSE : AL_TRUE);
+ qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE);
+ qalSourcef(ch->srcnum, AL_GAIN, ch->master_vol);
+ qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME);
+ qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192);
+ qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME));
- AL_Spatialize( ch );
+ AL_Spatialize(ch);
// play it
- qalSourcePlay( ch->srcnum );
- if( qalGetError() != AL_NO_ERROR ) {
- AL_StopChannel( ch );
+ qalSourcePlay(ch->srcnum);
+ if (qalGetError() != AL_NO_ERROR) {
+ AL_StopChannel(ch);
}
}
-static void AL_IssuePlaysounds( void ) {
+static void AL_IssuePlaysounds(void)
+{
playsound_t *ps;
// start any playsounds
@@ -202,35 +211,37 @@ static void AL_IssuePlaysounds( void ) {
break; // no more pending sounds
if (ps->begin > paintedtime)
break;
- S_IssuePlaysound (ps);
+ S_IssuePlaysound(ps);
}
}
-void AL_StopAllChannels( void ) {
+void AL_StopAllChannels(void)
+{
int i;
channel_t *ch;
ch = channels;
- for( i = 0; i < s_numchannels; i++, ch++ ) {
+ for (i = 0; i < s_numchannels; i++, ch++) {
if (!ch->sfx)
continue;
- AL_StopChannel( ch );
+ AL_StopChannel(ch);
}
}
-static channel_t *AL_FindLoopingSound( int entnum, sfx_t *sfx ) {
+static channel_t *AL_FindLoopingSound(int entnum, sfx_t *sfx)
+{
int i;
channel_t *ch;
ch = channels;
- for( i = 0; i < s_numchannels; i++, ch++ ) {
- if( !ch->sfx )
+ for (i = 0; i < s_numchannels; i++, ch++) {
+ if (!ch->sfx)
continue;
- if( !ch->autosound )
+ if (!ch->autosound)
continue;
- if( ch->entnum != entnum )
+ if (ch->entnum != entnum)
continue;
- if( ch->sfx != sfx )
+ if (ch->sfx != sfx)
continue;
return ch;
}
@@ -238,7 +249,8 @@ static channel_t *AL_FindLoopingSound( int entnum, sfx_t *sfx ) {
return NULL;
}
-static void AL_AddLoopSounds( void ) {
+static void AL_AddLoopSounds(void)
+{
int i;
int sounds[MAX_PACKET_ENTITIES];
channel_t *ch;
@@ -247,28 +259,28 @@ static void AL_AddLoopSounds( void ) {
int num;
entity_state_t *ent;
- if( cls.state != ca_active || sv_paused->integer || !s_ambient->integer ) {
+ if (cls.state != ca_active || sv_paused->integer || !s_ambient->integer) {
return;
}
- S_BuildSoundList( sounds );
+ S_BuildSoundList(sounds);
- for( i = 0; i < cl.frame.numEntities; i++ ) {
+ for (i = 0; i < cl.frame.numEntities; i++) {
if (!sounds[i])
continue;
- sfx = S_SfxForHandle( cl.sound_precache[sounds[i]] );
+ sfx = S_SfxForHandle(cl.sound_precache[sounds[i]]);
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
if (!sc)
continue;
- num = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
- ch = AL_FindLoopingSound( ent->number, sfx );
- if( ch ) {
+ ch = AL_FindLoopingSound(ent->number, sfx);
+ if (ch) {
ch->autoframe = s_framecount;
ch->end = paintedtime + sc->length;
continue;
@@ -287,56 +299,57 @@ static void AL_AddLoopSounds( void ) {
ch->dist_mult = SOUND_LOOPATTENUATE;
ch->end = paintedtime + sc->length;
- AL_PlayChannel( ch );
+ AL_PlayChannel(ch);
}
}
-void AL_Update( void ) {
+void AL_Update(void)
+{
int i;
channel_t *ch;
vec_t orientation[6];
- if( !s_active ) {
+ if (!s_active) {
return;
}
paintedtime = cl.time;
// set listener parameters
- qalListener3f( AL_POSITION, AL_UnpackVector( listener_origin ) );
- AL_CopyVector( listener_forward, orientation );
- AL_CopyVector( listener_up, orientation + 3 );
- qalListenerfv( AL_ORIENTATION, orientation );
- qalListenerf( AL_GAIN, s_volume->value );
- qalDistanceModel( AL_LINEAR_DISTANCE_CLAMPED );
-
- // update spatialization for dynamic sounds
+ qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin));
+ AL_CopyVector(listener_forward, orientation);
+ AL_CopyVector(listener_up, orientation + 3);
+ qalListenerfv(AL_ORIENTATION, orientation);
+ qalListenerf(AL_GAIN, s_volume->value);
+ qalDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
+
+ // update spatialization for dynamic sounds
ch = channels;
- for( i = 0; i < s_numchannels; i++, ch++ ) {
- if( !ch->sfx )
+ for (i = 0; i < s_numchannels; i++, ch++) {
+ if (!ch->sfx)
continue;
- if( ch->autosound ) {
+ if (ch->autosound) {
// autosounds are regenerated fresh each frame
- if( ch->autoframe != s_framecount ) {
- AL_StopChannel( ch );
+ if (ch->autoframe != s_framecount) {
+ AL_StopChannel(ch);
continue;
}
} else {
ALenum state;
qalGetError();
- qalGetSourcei( ch->srcnum, AL_SOURCE_STATE, &state );
- if( qalGetError() != AL_NO_ERROR || state == AL_STOPPED ) {
- AL_StopChannel( ch );
+ qalGetSourcei(ch->srcnum, AL_SOURCE_STATE, &state);
+ if (qalGetError() != AL_NO_ERROR || state == AL_STOPPED) {
+ AL_StopChannel(ch);
continue;
}
}
#ifdef _DEBUG
if (s_show->integer) {
- Com_Printf ("%.1f %s\n", ch->master_vol, ch->sfx->name);
- // total++;
+ Com_Printf("%.1f %s\n", ch->master_vol, ch->sfx->name);
+ // total++;
}
#endif
@@ -346,7 +359,7 @@ void AL_Update( void ) {
s_framecount++;
// add loopsounds
- AL_AddLoopSounds ();
+ AL_AddLoopSounds();
AL_IssuePlaysounds();
}
diff --git a/src/snd_dma.c b/src/snd_dma.c
index 92e0dcd..b8df360 100644
--- a/src/snd_dma.c
+++ b/src/snd_dma.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -33,37 +33,39 @@ static cvar_t *s_mixahead;
static snddmaAPI_t snddma;
-void DMA_SoundInfo( void ) {
- Com_Printf( "%5d channels\n", dma.channels );
- Com_Printf( "%5d samples\n", dma.samples );
- Com_Printf( "%5d samplepos\n", dma.samplepos );
- Com_Printf( "%5d samplebits\n", dma.samplebits );
- Com_Printf( "%5d submission_chunk\n", dma.submission_chunk );
- Com_Printf( "%5d speed\n", dma.speed );
- Com_Printf( "%p dma buffer\n", dma.buffer );
+void DMA_SoundInfo(void)
+{
+ Com_Printf("%5d channels\n", dma.channels);
+ Com_Printf("%5d samples\n", dma.samples);
+ Com_Printf("%5d samplepos\n", dma.samplepos);
+ Com_Printf("%5d samplebits\n", dma.samplebits);
+ Com_Printf("%5d submission_chunk\n", dma.submission_chunk);
+ Com_Printf("%5d speed\n", dma.speed);
+ Com_Printf("%p dma buffer\n", dma.buffer);
}
-qboolean DMA_Init( void ) {
+qboolean DMA_Init(void)
+{
sndinitstat_t ret = SIS_FAILURE;
- s_khz = Cvar_Get( "s_khz", "22", CVAR_ARCHIVE|CVAR_SOUND );
- s_mixahead = Cvar_Get( "s_mixahead", "0.2", CVAR_ARCHIVE );
- s_testsound = Cvar_Get( "s_testsound", "0", 0 );
+ s_khz = Cvar_Get("s_khz", "22", CVAR_ARCHIVE | CVAR_SOUND);
+ s_mixahead = Cvar_Get("s_mixahead", "0.2", CVAR_ARCHIVE);
+ s_testsound = Cvar_Get("s_testsound", "0", 0);
#if USE_DSOUND
- s_direct = Cvar_Get( "s_direct", "1", CVAR_SOUND );
- if( s_direct->integer ) {
- DS_FillAPI( &snddma );
+ s_direct = Cvar_Get("s_direct", "1", CVAR_SOUND);
+ if (s_direct->integer) {
+ DS_FillAPI(&snddma);
ret = snddma.Init();
- if( ret != SIS_SUCCESS ) {
- Cvar_Set( "s_direct", "0" );
+ if (ret != SIS_SUCCESS) {
+ Cvar_Set("s_direct", "0");
}
}
#endif
- if( ret != SIS_SUCCESS ) {
- WAVE_FillAPI( &snddma );
+ if (ret != SIS_SUCCESS) {
+ WAVE_FillAPI(&snddma);
ret = snddma.Init();
- if( ret != SIS_SUCCESS ) {
+ if (ret != SIS_SUCCESS) {
return qfalse;
}
}
@@ -72,35 +74,38 @@ qboolean DMA_Init( void ) {
s_numchannels = MAX_CHANNELS;
- Com_Printf( "sound sampling rate: %i\n", dma.speed );
+ Com_Printf("sound sampling rate: %i\n", dma.speed);
return qtrue;
}
-void DMA_Shutdown( void ) {
+void DMA_Shutdown(void)
+{
snddma.Shutdown();
s_numchannels = 0;
}
-void DMA_Activate( void ) {
- if( snddma.Activate ) {
+void DMA_Activate(void)
+{
+ if (snddma.Activate) {
S_StopAllSounds();
- snddma.Activate( s_active );
+ snddma.Activate(s_active);
}
}
-int DMA_DriftBeginofs( float timeofs ) {
+int DMA_DriftBeginofs(float timeofs)
+{
static int s_beginofs;
int start;
// drift s_beginofs
start = cl.servertime * 0.001 * dma.speed + s_beginofs;
- if( start < paintedtime ) {
+ if (start < paintedtime) {
start = paintedtime;
- s_beginofs = start - ( cl.servertime * 0.001 * dma.speed );
- } else if ( start > paintedtime + 0.3 * dma.speed ) {
+ s_beginofs = start - (cl.servertime * 0.001 * dma.speed);
+ } else if (start > paintedtime + 0.3 * dma.speed) {
start = paintedtime + 0.1 * dma.speed;
- s_beginofs = start - ( cl.servertime * 0.001 * dma.speed );
+ s_beginofs = start - (cl.servertime * 0.001 * dma.speed);
} else {
s_beginofs -= 10;
}
@@ -108,21 +113,23 @@ int DMA_DriftBeginofs( float timeofs ) {
return timeofs ? start + timeofs * dma.speed : paintedtime;
}
-void DMA_ClearBuffer( void ) {
+void DMA_ClearBuffer(void)
+{
int clear;
-
+
if (dma.samplebits == 8)
clear = 0x80;
else
clear = 0;
- snddma.BeginPainting ();
+ snddma.BeginPainting();
if (dma.buffer)
- memset(dma.buffer, clear, dma.samples * dma.samplebits/8);
- snddma.Submit ();
+ memset(dma.buffer, clear, dma.samples * dma.samplebits / 8);
+ snddma.Submit();
}
-static int DMA_GetTime(void) {
+static int DMA_GetTime(void)
+{
static int buffers;
static int oldsamplepos;
int fullsamples = dma.samples / dma.channels;
@@ -140,14 +147,15 @@ static int DMA_GetTime(void) {
}
oldsamplepos = dma.samplepos;
- return buffers*fullsamples + dma.samplepos/dma.channels;
+ return buffers * fullsamples + dma.samplepos / dma.channels;
}
-void DMA_Update(void) {
+void DMA_Update(void)
+{
int soundtime, endtime;
int samps;
- snddma.BeginPainting ();
+ snddma.BeginPainting();
if (!dma.buffer)
return;
@@ -157,7 +165,7 @@ void DMA_Update(void) {
// check to make sure that we haven't overshot
if (paintedtime < soundtime) {
- Com_DPrintf ("S_Update_ : overflow\n");
+ Com_DPrintf("S_Update_ : overflow\n");
paintedtime = soundtime;
}
@@ -167,14 +175,14 @@ void DMA_Update(void) {
// mix to an even submission block size
endtime = (endtime + dma.submission_chunk - 1)
- & ~(dma.submission_chunk - 1);
- samps = dma.samples >> (dma.channels-1);
+ & ~(dma.submission_chunk - 1);
+ samps = dma.samples >> (dma.channels - 1);
if (endtime - soundtime > samps)
endtime = soundtime + samps;
- S_PaintChannels (endtime);
+ S_PaintChannels(endtime);
- snddma.Submit ();
+ snddma.Submit();
}
diff --git a/src/snd_dx.c b/src/snd_dx.c
index 46cc5b6..ff584a2 100644
--- a/src/snd_dx.c
+++ b/src/snd_dx.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <dsound.h>
#include "snd_local.h"
-typedef HRESULT (WINAPI *LPDIRECTSOUNDCREATE)( LPCGUID, LPDIRECTSOUND *, LPUNKNOWN );
+typedef HRESULT(WINAPI *LPDIRECTSOUNDCREATE)(LPCGUID, LPDIRECTSOUND *, LPUNKNOWN);
// 64K is > 1 second at 16-bit, 22050 Hz
#define WAV_BUFFERS 64
@@ -45,8 +45,9 @@ static HINSTANCE hInstDS;
static DWORD gSndBufSize;
-static const char *DSoundError( int error ) {
- switch ( error ) {
+static const char *DSoundError(int error)
+{
+ switch (error) {
case DSERR_BUFFERLOST:
return "DSERR_BUFFERLOST";
case DSERR_INVALIDCALL:
@@ -63,23 +64,24 @@ static const char *DSoundError( int error ) {
/*
** DS_DestroyBuffers
*/
-static void DS_DestroyBuffers( void ) {
- Com_DPrintf( "Destroying DS buffers\n" );
- if( pDS ) {
- Com_DPrintf( "...setting NORMAL coop level\n" );
- IDirectSound_SetCooperativeLevel( pDS, win.wnd, DSSCL_NORMAL );
+static void DS_DestroyBuffers(void)
+{
+ Com_DPrintf("Destroying DS buffers\n");
+ if (pDS) {
+ Com_DPrintf("...setting NORMAL coop level\n");
+ IDirectSound_SetCooperativeLevel(pDS, win.wnd, DSSCL_NORMAL);
}
- if( pDSBuf ) {
- Com_DPrintf( "...stopping and releasing sound buffer\n" );
- IDirectSoundBuffer_Stop( pDSBuf );
- IDirectSoundBuffer_Release( pDSBuf );
+ if (pDSBuf) {
+ Com_DPrintf("...stopping and releasing sound buffer\n");
+ IDirectSoundBuffer_Stop(pDSBuf);
+ IDirectSoundBuffer_Release(pDSBuf);
}
// only release primary buffer if it's not also the mixing buffer we just released
- if( pDSPBuf && ( pDSBuf != pDSPBuf ) ) {
- Com_DPrintf( "...releasing primary buffer\n" );
- IDirectSoundBuffer_Release( pDSPBuf );
+ if (pDSPBuf && (pDSBuf != pDSPBuf)) {
+ Com_DPrintf("...releasing primary buffer\n");
+ IDirectSoundBuffer_Release(pDSPBuf);
}
pDSBuf = NULL;
pDSPBuf = NULL;
@@ -94,19 +96,20 @@ DS_Shutdown
Reset the sound device for exiting
===============
*/
-static void DS_Shutdown(void) {
- Com_Printf( "Shutting down DirectSound\n" );
+static void DS_Shutdown(void)
+{
+ Com_Printf("Shutting down DirectSound\n");
- if( pDS ) {
+ if (pDS) {
DS_DestroyBuffers();
- Com_DPrintf( "...releasing DS object\n" );
- IDirectSound_Release( pDS );
+ Com_DPrintf("...releasing DS object\n");
+ IDirectSound_Release(pDS);
}
- if ( hInstDS ) {
- Com_DPrintf( "...freeing DSOUND.DLL\n" );
- FreeLibrary( hInstDS );
+ if (hInstDS) {
+ Com_DPrintf("...freeing DSOUND.DLL\n");
+ FreeLibrary(hInstDS);
hInstDS = NULL;
}
@@ -118,32 +121,33 @@ static void DS_Shutdown(void) {
/*
** DS_CreateBuffers
*/
-static qboolean DS_CreateBuffers( void ) {
+static qboolean DS_CreateBuffers(void)
+{
DSBUFFERDESC dsbuf;
DSBCAPS dsbcaps;
WAVEFORMATEX format;
DWORD dwWrite;
- memset (&format, 0, sizeof(format));
+ memset(&format, 0, sizeof(format));
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = dma.channels;
format.wBitsPerSample = dma.samplebits;
format.nSamplesPerSec = dma.speed;
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
- format.cbSize = sizeof( format );
- format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign;
+ format.cbSize = sizeof(format);
+ format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
- Com_DPrintf( "Creating DS buffer\n" );
+ Com_DPrintf("Creating DS buffer\n");
- Com_DPrintf("...setting PRIORITY coop level: " );
- if ( DS_OK != IDirectSound_SetCooperativeLevel( pDS, win.wnd, DSSCL_PRIORITY ) ) {
- Com_DPrintf ("failed\n");
+ Com_DPrintf("...setting PRIORITY coop level: ");
+ if (DS_OK != IDirectSound_SetCooperativeLevel(pDS, win.wnd, DSSCL_PRIORITY)) {
+ Com_DPrintf("failed\n");
return qfalse;
}
- Com_DPrintf("ok\n" );
+ Com_DPrintf("ok\n");
// create the secondary buffer we'll actually work with
- memset (&dsbuf, 0, sizeof(dsbuf));
+ memset(&dsbuf, 0, sizeof(dsbuf));
dsbuf.dwSize = sizeof(DSBUFFERDESC);
dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCHARDWARE;
dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
@@ -152,50 +156,50 @@ static qboolean DS_CreateBuffers( void ) {
memset(&dsbcaps, 0, sizeof(dsbcaps));
dsbcaps.dwSize = sizeof(dsbcaps);
- Com_DPrintf( "...creating secondary buffer: " );
+ Com_DPrintf("...creating secondary buffer: ");
if (DS_OK != IDirectSound_CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL)) {
dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCSOFTWARE;
if (DS_OK != IDirectSound_CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL)) {
- Com_DPrintf( "failed\n" );
+ Com_DPrintf("failed\n");
return qfalse;
}
- Com_DPrintf( "ok\n...forced to software\n" );
+ Com_DPrintf("ok\n...forced to software\n");
} else {
- Com_DPrintf( "ok\n...locked hardware\n" );
+ Com_DPrintf("ok\n...locked hardware\n");
}
dma.channels = format.nChannels;
dma.samplebits = format.wBitsPerSample;
dma.speed = format.nSamplesPerSec;
- if (DS_OK != IDirectSoundBuffer_GetCaps (pDSBuf, &dsbcaps)) {
- Com_DPrintf ("*** GetCaps failed ***\n");
+ if (DS_OK != IDirectSoundBuffer_GetCaps(pDSBuf, &dsbcaps)) {
+ Com_DPrintf("*** GetCaps failed ***\n");
return qfalse;
}
// Make sure mixer is active
- if (DS_OK != IDirectSoundBuffer_Play (pDSBuf, 0, 0, DSBPLAY_LOOPING)) {
- Com_DPrintf ("*** Play failed ***\n");
+ if (DS_OK != IDirectSoundBuffer_Play(pDSBuf, 0, 0, DSBPLAY_LOOPING)) {
+ Com_DPrintf("*** Play failed ***\n");
return qfalse;
}
- Com_DPrintf( " %d channel(s)\n"
- " %d bits/sample\n"
- " %d bytes/sec\n",
- dma.channels, dma.samplebits, dma.speed);
-
+ Com_DPrintf(" %d channel(s)\n"
+ " %d bits/sample\n"
+ " %d bytes/sec\n",
+ dma.channels, dma.samplebits, dma.speed);
+
gSndBufSize = dsbcaps.dwBufferBytes;
IDirectSoundBuffer_Stop(pDSBuf);
IDirectSoundBuffer_GetCurrentPosition(pDSBuf, &mmstarttime.u.sample, &dwWrite);
IDirectSoundBuffer_Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
- dma.samples = gSndBufSize/(dma.samplebits/8);
+ dma.samples = gSndBufSize / (dma.samplebits / 8);
dma.samplepos = 0;
dma.submission_chunk = 1;
dma.buffer = NULL;
- sample16 = (dma.samplebits/8) - 1;
+ sample16 = (dma.samplebits / 8) - 1;
return qtrue;
}
@@ -209,16 +213,17 @@ DS_Init
Direct-Sound support
==================
*/
-static sndinitstat_t DS_Init (void) {
+static sndinitstat_t DS_Init(void)
+{
DSCAPS dscaps;
HRESULT hresult;
LPDIRECTSOUNDCREATE pDirectSoundCreate;
- memset (&dma, 0, sizeof (dma));
+ memset(&dma, 0, sizeof(dma));
dma.channels = 2;
dma.samplebits = 16;
- switch( s_khz->integer ) {
+ switch (s_khz->integer) {
case 48:
dma.speed = 48000;
break;
@@ -233,64 +238,63 @@ static sndinitstat_t DS_Init (void) {
break;
}
- Com_DPrintf( "Initializing DirectSound\n");
+ Com_DPrintf("Initializing DirectSound\n");
- if ( !hInstDS ) {
- Com_DPrintf( "...loading dsound.dll: " );
+ if (!hInstDS) {
+ Com_DPrintf("...loading dsound.dll: ");
hInstDS = LoadLibrary("dsound.dll");
if (hInstDS == NULL) {
- Com_DPrintf ("failed\n");
+ Com_DPrintf("failed\n");
return SIS_FAILURE;
}
- Com_DPrintf ("ok\n");
+ Com_DPrintf("ok\n");
}
- pDirectSoundCreate = ( LPDIRECTSOUNDCREATE )
- GetProcAddress(hInstDS,"DirectSoundCreate");
+ pDirectSoundCreate = (LPDIRECTSOUNDCREATE)
+ GetProcAddress(hInstDS, "DirectSoundCreate");
if (!pDirectSoundCreate) {
- Com_DPrintf ("...couldn't get DS proc addr\n");
+ Com_DPrintf("...couldn't get DS proc addr\n");
return SIS_FAILURE;
}
- Com_DPrintf( "...creating DS object: " );
- while ( ( hresult = pDirectSoundCreate( NULL, &pDS, NULL ) ) != DS_OK ) {
+ Com_DPrintf("...creating DS object: ");
+ while ((hresult = pDirectSoundCreate(NULL, &pDS, NULL)) != DS_OK) {
if (hresult != DSERR_ALLOCATED) {
- Com_DPrintf( "failed\n" );
+ Com_DPrintf("failed\n");
return SIS_FAILURE;
}
- if (MessageBox (NULL,
- "The sound hardware is in use by another app.\n\n"
- "Select Retry to try to start sound again or Cancel to run " PRODUCT " with no sound.",
- "Sound not available",
- MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
- {
- Com_DPrintf ("failed, hardware already in use\n" );
+ if (MessageBox(NULL,
+ "The sound hardware is in use by another app.\n\n"
+ "Select Retry to try to start sound again or Cancel to run " PRODUCT " with no sound.",
+ "Sound not available",
+ MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY) {
+ Com_DPrintf("failed, hardware already in use\n");
return SIS_NOTAVAIL;
}
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
dscaps.dwSize = sizeof(dscaps);
- if( DS_OK != IDirectSound_GetCaps( pDS, &dscaps ) ) {
- Com_DPrintf ("...couldn't get DS caps\n");
+ if (DS_OK != IDirectSound_GetCaps(pDS, &dscaps)) {
+ Com_DPrintf("...couldn't get DS caps\n");
DS_Shutdown();
return SIS_FAILURE;
}
- if( dscaps.dwFlags & DSCAPS_EMULDRIVER ) {
- Com_DPrintf ("...no DSound driver found\n" );
+ if (dscaps.dwFlags & DSCAPS_EMULDRIVER) {
+ Com_DPrintf("...no DSound driver found\n");
DS_Shutdown();
return SIS_FAILURE;
}
- if( !DS_CreateBuffers() ) {
- DS_Shutdown ();
+ if (!DS_CreateBuffers()) {
+ DS_Shutdown();
return SIS_FAILURE;
}
- Com_Printf( "DirectSound initialized\n" );
+ Com_Printf("DirectSound initialized\n");
return SIS_SUCCESS;
}
@@ -306,7 +310,8 @@ inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
-static void DS_BeginPainting (void) {
+static void DS_BeginPainting(void)
+{
int reps, s;
DWORD dwSize2;
DWORD *pbuf, *pbuf2;
@@ -320,19 +325,19 @@ static void DS_BeginPainting (void) {
// get sample pos
mmtime.wType = TIME_SAMPLES;
IDirectSoundBuffer_GetCurrentPosition(pDSBuf, &mmtime.u.sample, &dwWrite);
- s = ( mmtime.u.sample - mmstarttime.u.sample ) >> sample16;
- dma.samplepos = s & ( dma.samples - 1 );
+ s = (mmtime.u.sample - mmstarttime.u.sample) >> sample16;
+ dma.samplepos = s & (dma.samples - 1);
// if the buffer was lost or stopped, restore it and/or restart it
- if (IDirectSoundBuffer_GetStatus (pDSBuf, &dwStatus) != DS_OK) {
- Com_EPrintf ("DS_BeginPainting: Couldn't get sound buffer status\n");
- DS_Shutdown ();
+ if (IDirectSoundBuffer_GetStatus(pDSBuf, &dwStatus) != DS_OK) {
+ Com_EPrintf("DS_BeginPainting: Couldn't get sound buffer status\n");
+ DS_Shutdown();
return;
}
-
+
if (dwStatus & DSBSTATUS_BUFFERLOST)
- IDirectSoundBuffer_Restore (pDSBuf);
-
+ IDirectSoundBuffer_Restore(pDSBuf);
+
if (!(dwStatus & DSBSTATUS_PLAYING))
IDirectSoundBuffer_Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
@@ -341,16 +346,15 @@ static void DS_BeginPainting (void) {
reps = 0;
dma.buffer = NULL;
- while ((hresult = IDirectSoundBuffer_Lock(pDSBuf, 0, gSndBufSize, ( void ** )&pbuf, &locksize,
- ( void ** )&pbuf2, &dwSize2, 0)) != DS_OK)
- {
+ while ((hresult = IDirectSoundBuffer_Lock(pDSBuf, 0, gSndBufSize, (void **)&pbuf, &locksize,
+ (void **)&pbuf2, &dwSize2, 0)) != DS_OK) {
if (hresult != DSERR_BUFFERLOST) {
- Com_EPrintf( "DS_BeginPainting: Lock failed with error '%s'\n", DSoundError( hresult ) );
- DS_Shutdown ();
+ Com_EPrintf("DS_BeginPainting: Lock failed with error '%s'\n", DSoundError(hresult));
+ DS_Shutdown();
return;
}
-
- IDirectSoundBuffer_Restore( pDSBuf );
+
+ IDirectSoundBuffer_Restore(pDSBuf);
if (++reps > 2)
return;
@@ -366,7 +370,8 @@ Send sound to device if buffer isn't really the dma buffer
Also unlocks the dsound buffer
===============
*/
-static void DS_Submit(void) {
+static void DS_Submit(void)
+{
if (!pDSBuf)
return;
@@ -383,13 +388,14 @@ The window have been destroyed and recreated
between a deactivate and an activate.
===========
*/
-static void DS_Activate (qboolean active) {
- if( !pDS ) {
+static void DS_Activate(qboolean active)
+{
+ if (!pDS) {
return;
}
- if( active ) {
- if( !DS_CreateBuffers() ) {
- Com_EPrintf( "DS_Activate: DS_CreateBuffers failed\n" );
+ if (active) {
+ if (!DS_CreateBuffers()) {
+ Com_EPrintf("DS_Activate: DS_CreateBuffers failed\n");
DS_Shutdown();
}
} else {
@@ -397,7 +403,8 @@ static void DS_Activate (qboolean active) {
}
}
-void DS_FillAPI( snddmaAPI_t *api ) {
+void DS_FillAPI(snddmaAPI_t *api)
+{
api->Init = DS_Init;
api->Shutdown = DS_Shutdown;
api->BeginPainting = DS_BeginPainting;
diff --git a/src/snd_local.h b/src/snd_local.h
index e271c95..59532ce 100644
--- a/src/snd_local.h
+++ b/src/snd_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,14 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// snd_loc.h -- private sound functions
// !!! if this is changed, the asm code must change !!!
-typedef struct samplepair_s
-{
+typedef struct samplepair_s {
int left;
int right;
} samplepair_t;
-typedef struct sfxcache_s
-{
+typedef struct sfxcache_s {
int length;
int loopstart;
int width;
@@ -38,8 +36,7 @@ typedef struct sfxcache_s
byte data[1]; // variable sized
} sfxcache_t;
-typedef struct sfx_s
-{
+typedef struct sfx_s {
char name[MAX_QPATH];
int registration_sequence;
sfxcache_t *cache;
@@ -50,8 +47,7 @@ typedef struct sfx_s
// a playsound_t will be generated by each call to S_StartSound,
// when the mixer reaches playsound->begin, the playsound will
// be assigned to a channel
-typedef struct playsound_s
-{
+typedef struct playsound_s {
struct playsound_s *prev, *next;
sfx_t *sfx;
float volume;
@@ -63,8 +59,7 @@ typedef struct playsound_s
unsigned begin; // begin on this sample
} playsound_t;
-typedef struct dma_s
-{
+typedef struct dma_s {
int channels;
int samples; // mono samples in buffer
int submission_chunk; // don't mix less than this #
@@ -75,8 +70,7 @@ typedef struct dma_s
} dma_t;
// !!! if this is changed, the asm code must change !!!
-typedef struct channel_s
-{
+typedef struct channel_s {
sfx_t *sfx; // sfx number
int leftvol; // 0-255 volume
int rightvol; // 0-255 volume
@@ -118,45 +112,45 @@ typedef enum { SIS_SUCCESS, SIS_FAILURE, SIS_NOTAVAIL } sndinitstat_t;
typedef struct snddmaAPI_s {
// initializes cycling through a DMA buffer and returns information on it
- sndinitstat_t (*Init)( void );
+ sndinitstat_t (*Init)(void);
// shutdown the DMA xfer.
- void (*Shutdown)( void );
+ void (*Shutdown)(void);
- void (*BeginPainting)( void );
- void (*Submit)( void );
- void (*Activate)( qboolean active );
+ void (*BeginPainting)(void);
+ void (*Submit)(void);
+ void (*Activate)(qboolean active);
} snddmaAPI_t;
-void WAVE_FillAPI( snddmaAPI_t *api );
+void WAVE_FillAPI(snddmaAPI_t *api);
#if USE_DSOUND
-void DS_FillAPI( snddmaAPI_t *api );
+void DS_FillAPI(snddmaAPI_t *api);
#endif
//extern snddmaAPI_t snddma;
extern dma_t dma;
-void DMA_SoundInfo( void );
-qboolean DMA_Init( void );
-void DMA_Shutdown( void );
-void DMA_Activate( void );
-int DMA_DriftBeginofs( float timeofs );
-void DMA_ClearBuffer( void );
-void DMA_Update( void );
+void DMA_SoundInfo(void);
+qboolean DMA_Init(void);
+void DMA_Shutdown(void);
+void DMA_Activate(void);
+int DMA_DriftBeginofs(float timeofs);
+void DMA_ClearBuffer(void);
+void DMA_Update(void);
#endif
#if USE_OPENAL
-void AL_SoundInfo( void );
-qboolean AL_Init( void );
-void AL_Shutdown( void );
-sfxcache_t *AL_UploadSfx( sfx_t *s );
-void AL_DeleteSfx( sfx_t *s );
-void AL_StopChannel( channel_t *ch );
-void AL_PlayChannel( channel_t *ch );
-void AL_StopAllChannels( void );
-void AL_Update( void );
+void AL_SoundInfo(void);
+qboolean AL_Init(void);
+void AL_Shutdown(void);
+sfxcache_t *AL_UploadSfx(sfx_t *s);
+void AL_DeleteSfx(sfx_t *s);
+void AL_StopChannel(channel_t *ch);
+void AL_PlayChannel(channel_t *ch);
+void AL_StopAllChannels(void);
+void AL_Update(void);
#endif
//====================================================================
@@ -202,16 +196,16 @@ extern cvar_t *s_testsound;
extern cvar_t *s_ambient;
extern cvar_t *s_show;
-#define S_Malloc( x ) Z_TagMalloc( x, TAG_SOUND )
-#define S_CopyString( x ) Z_TagCopyString( x, TAG_SOUND )
+#define S_Malloc(x) Z_TagMalloc(x, TAG_SOUND)
+#define S_CopyString(x) Z_TagCopyString(x, TAG_SOUND)
-sfx_t *S_SfxForHandle( qhandle_t hSfx );
-sfxcache_t *S_LoadSound (sfx_t *s);
-channel_t *S_PickChannel( int entnum, int entchannel );
-void S_IssuePlaysound (playsound_t *ps);
-void S_BuildSoundList( int *sounds );
+sfx_t *S_SfxForHandle(qhandle_t hSfx);
+sfxcache_t *S_LoadSound(sfx_t *s);
+channel_t *S_PickChannel(int entnum, int entchannel);
+void S_IssuePlaysound(playsound_t *ps);
+void S_BuildSoundList(int *sounds);
#if USE_SNDDMA
-void S_InitScaletable (void);
+void S_InitScaletable(void);
void S_PaintChannels(int endtime);
#endif
diff --git a/src/snd_main.c b/src/snd_main.c
index cc68b1d..61ce99b 100644
--- a/src/snd_main.c
+++ b/src/snd_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -70,56 +70,58 @@ static cvar_t *s_auto_focus;
// Console functions
// =======================================================================
-static void S_SoundInfo_f( void ) {
- if( !s_started ) {
- Com_Printf( "Sound system not started.\n" );
+static void S_SoundInfo_f(void)
+{
+ if (!s_started) {
+ Com_Printf("Sound system not started.\n");
return;
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_SoundInfo();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_SoundInfo();
#endif
}
-static void S_SoundList_f( void ) {
+static void S_SoundList_f(void)
+{
int i;
sfx_t *sfx;
sfxcache_t *sc;
int size, total;
total = 0;
- for( sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
sc = sfx->cache;
- if( sc ) {
+ if (sc) {
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
size = sc->size;
else
#endif
size = sc->length * sc->width;
total += size;
- if( sc->loopstart >= 0 )
- Com_Printf( "L" );
+ if (sc->loopstart >= 0)
+ Com_Printf("L");
else
- Com_Printf( " " );
- Com_Printf( "(%2db) %6i : %s\n", sc->width * 8, size, sfx->name) ;
+ Com_Printf(" ");
+ Com_Printf("(%2db) %6i : %s\n", sc->width * 8, size, sfx->name) ;
} else {
- if( sfx->name[0] == '*' )
- Com_Printf( " placeholder : %s\n", sfx->name );
+ if (sfx->name[0] == '*')
+ Com_Printf(" placeholder : %s\n", sfx->name);
else
- Com_Printf( " not loaded : %s (%s)\n",
- sfx->name, Q_ErrorString( sfx->error ) );
+ Com_Printf(" not loaded : %s (%s)\n",
+ sfx->name, Q_ErrorString(sfx->error));
}
}
- Com_Printf( "Total resident: %i\n", total );
+ Com_Printf("Total resident: %i\n", total);
}
static const cmdreg_t c_sound[] = {
@@ -134,7 +136,8 @@ static const cmdreg_t c_sound[] = {
// Init sound engine
// =======================================================================
-static void s_auto_focus_changed( cvar_t *self ) {
+static void s_auto_focus_changed(cvar_t *self)
+{
S_Activate();
}
@@ -143,48 +146,49 @@ static void s_auto_focus_changed( cvar_t *self ) {
S_Init
================
*/
-void S_Init( void ) {
- s_enable = Cvar_Get( "s_enable", "1", CVAR_SOUND );
- if( s_enable->integer <= SS_NOT ) {
- Com_Printf( "Sound initialization disabled.\n" );
+void S_Init(void)
+{
+ s_enable = Cvar_Get("s_enable", "1", CVAR_SOUND);
+ if (s_enable->integer <= SS_NOT) {
+ Com_Printf("Sound initialization disabled.\n");
return;
}
- Com_Printf( "------- S_Init -------\n" );
+ Com_Printf("------- S_Init -------\n");
- s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE );
- s_ambient = Cvar_Get( "s_ambient", "1", 0 );
+ s_volume = Cvar_Get("s_volume", "0.7", CVAR_ARCHIVE);
+ s_ambient = Cvar_Get("s_ambient", "1", 0);
#ifdef _DEBUG
- s_show = Cvar_Get( "s_show", "0", 0 );
+ s_show = Cvar_Get("s_show", "0", 0);
#endif
- s_auto_focus = Cvar_Get( "s_auto_focus", "0", 0 );
+ s_auto_focus = Cvar_Get("s_auto_focus", "0", 0);
// start one of available sound engines
s_started = SS_NOT;
#if USE_OPENAL
- if( s_started == SS_NOT && s_enable->integer >= SS_OAL && AL_Init() )
+ if (s_started == SS_NOT && s_enable->integer >= SS_OAL && AL_Init())
s_started = SS_OAL;
#endif
#if USE_SNDDMA
- if( s_started == SS_NOT && s_enable->integer >= SS_DMA && DMA_Init() )
+ if (s_started == SS_NOT && s_enable->integer >= SS_DMA && DMA_Init())
s_started = SS_DMA;
#endif
- if( s_started == SS_NOT ) {
- Com_EPrintf( "Sound failed to initialize.\n" );
+ if (s_started == SS_NOT) {
+ Com_EPrintf("Sound failed to initialize.\n");
goto fail;
}
- Cmd_Register( c_sound );
+ Cmd_Register(c_sound);
// init playsound list
// clear DMA buffer
S_StopAllSounds();
s_auto_focus->changed = s_auto_focus_changed;
- s_auto_focus_changed( s_auto_focus );
+ s_auto_focus_changed(s_auto_focus);
num_sfx = 0;
@@ -193,8 +197,8 @@ void S_Init( void ) {
s_registration_sequence = 1;
fail:
- Cvar_SetInteger( s_enable, s_started, FROM_CODE );
- Com_Printf( "----------------------\n" );
+ Cvar_SetInteger(s_enable, s_started, FROM_CODE);
+ Com_Printf("----------------------\n");
}
@@ -202,41 +206,44 @@ fail:
// Shutdown sound engine
// =======================================================================
-static void S_FreeSound( sfx_t *sfx ) {
+static void S_FreeSound(sfx_t *sfx)
+{
#if USE_OPENAL
- if( s_started == SS_OAL )
- AL_DeleteSfx( sfx );
+ if (s_started == SS_OAL)
+ AL_DeleteSfx(sfx);
#endif
- if( sfx->cache )
- Z_Free( sfx->cache );
- if( sfx->truename )
- Z_Free( sfx->truename );
- memset( sfx, 0, sizeof( *sfx ) );
+ if (sfx->cache)
+ Z_Free(sfx->cache);
+ if (sfx->truename)
+ Z_Free(sfx->truename);
+ memset(sfx, 0, sizeof(*sfx));
}
-void S_FreeAllSounds( void ) {
+void S_FreeAllSounds(void)
+{
int i;
sfx_t *sfx;
// free all sounds
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- S_FreeSound( sfx );
+ S_FreeSound(sfx);
}
num_sfx = 0;
}
-void S_Shutdown( void ) {
- if( !s_started )
+void S_Shutdown(void)
+{
+ if (!s_started)
return;
S_StopAllSounds();
S_FreeAllSounds();
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_Shutdown();
else
#endif
@@ -250,36 +257,37 @@ void S_Shutdown( void ) {
s_auto_focus->changed = NULL;
- Cmd_Deregister( c_sound );
+ Cmd_Deregister(c_sound);
- Z_LeakTest( TAG_SOUND );
+ Z_LeakTest(TAG_SOUND);
}
-void S_Activate( void ) {
+void S_Activate(void)
+{
qboolean active;
active_t level;
- if( !s_started )
+ if (!s_started)
return;
- level = Cvar_ClampInteger( s_auto_focus, ACT_MINIMIZED, ACT_ACTIVATED );
+ level = Cvar_ClampInteger(s_auto_focus, ACT_MINIMIZED, ACT_ACTIVATED);
active = cls.active >= level;
- if( active == s_active )
+ if (active == s_active)
return;
s_active = active;
- Com_DDDPrintf( "%s: %d\n", __func__, s_active );
+ Com_DDDPrintf("%s: %d\n", __func__, s_active);
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
S_StopAllSounds();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_Activate();
#endif
}
@@ -294,34 +302,36 @@ void S_Activate( void ) {
S_SfxForHandle
==================
*/
-sfx_t *S_SfxForHandle( qhandle_t hSfx ) {
- if( !hSfx ) {
+sfx_t *S_SfxForHandle(qhandle_t hSfx)
+{
+ if (!hSfx) {
return NULL;
}
- if( hSfx < 1 || hSfx > num_sfx ) {
- Com_Error( ERR_DROP, "S_SfxForHandle: %d out of range", hSfx );
+ if (hSfx < 1 || hSfx > num_sfx) {
+ Com_Error(ERR_DROP, "S_SfxForHandle: %d out of range", hSfx);
}
return &known_sfx[hSfx - 1];
}
-static sfx_t *S_AllocSfx( void ) {
+static sfx_t *S_AllocSfx(void)
+{
sfx_t *sfx;
int i;
// find a free sfx
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
break;
}
- if( i == num_sfx ) {
- if( num_sfx == MAX_SFX )
- Com_Error( ERR_DROP, "S_AllocSfx: out of sfx_t" );
+ if (i == num_sfx) {
+ if (num_sfx == MAX_SFX)
+ Com_Error(ERR_DROP, "S_AllocSfx: out of sfx_t");
num_sfx++;
}
-
+
return sfx;
}
@@ -331,13 +341,14 @@ S_FindName
==================
*/
-static sfx_t *S_FindName( const char *name, size_t namelen ) {
+static sfx_t *S_FindName(const char *name, size_t namelen)
+{
int i;
sfx_t *sfx;
// see if already loaded
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !FS_pathcmp( sfx->name, name ) ) {
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!FS_pathcmp(sfx->name, name)) {
sfx->registration_sequence = s_registration_sequence;
return sfx;
}
@@ -345,9 +356,9 @@ static sfx_t *S_FindName( const char *name, size_t namelen ) {
// allocate new one
sfx = S_AllocSfx();
- memcpy( sfx->name, name, namelen + 1 );
+ memcpy(sfx->name, name, namelen + 1);
sfx->registration_sequence = s_registration_sequence;
-
+
return sfx;
}
@@ -357,7 +368,8 @@ S_BeginRegistration
=====================
*/
-void S_BeginRegistration( void ) {
+void S_BeginRegistration(void)
+{
s_registration_sequence++;
s_registering = qtrue;
}
@@ -368,47 +380,48 @@ S_RegisterSound
==================
*/
-qhandle_t S_RegisterSound( const char *name ) {
+qhandle_t S_RegisterSound(const char *name)
+{
char buffer[MAX_QPATH];
sfx_t *sfx;
size_t len;
- if( !s_started )
+ if (!s_started)
return 0;
// empty names are legal, silently ignore them
- if( !*name )
+ if (!*name)
return 0;
- if( *name == '*' ) {
- len = Q_strlcpy( buffer, name, MAX_QPATH );
- } else if( *name == '#' ) {
- len = FS_NormalizePathBuffer( buffer, name + 1, MAX_QPATH );
+ if (*name == '*') {
+ len = Q_strlcpy(buffer, name, MAX_QPATH);
+ } else if (*name == '#') {
+ len = FS_NormalizePathBuffer(buffer, name + 1, MAX_QPATH);
} else {
- len = Q_concat( buffer, MAX_QPATH, "sound/", name, NULL );
- if( len < MAX_QPATH )
- len = FS_NormalizePath( buffer, buffer );
+ len = Q_concat(buffer, MAX_QPATH, "sound/", name, NULL);
+ if (len < MAX_QPATH)
+ len = FS_NormalizePath(buffer, buffer);
}
// this MAY happen after prepending "sound/"
- if( len >= MAX_QPATH ) {
- Com_DPrintf( "%s: oversize name\n", __func__ );
+ if (len >= MAX_QPATH) {
+ Com_DPrintf("%s: oversize name\n", __func__);
return 0;
}
// normalized to empty name?
- if( len == 0 ) {
- Com_DPrintf( "%s: empty name\n", __func__ );
+ if (len == 0) {
+ Com_DPrintf("%s: empty name\n", __func__);
return 0;
}
- sfx = S_FindName( buffer, len );
+ sfx = S_FindName(buffer, len);
- if( !s_registering ) {
- S_LoadSound( sfx );
+ if (!s_registering) {
+ S_LoadSound(sfx);
}
- return ( sfx - known_sfx ) + 1;
+ return (sfx - known_sfx) + 1;
}
/*
@@ -416,44 +429,45 @@ qhandle_t S_RegisterSound( const char *name ) {
S_RegisterSexedSound
====================
*/
-static sfx_t *S_RegisterSexedSound( int entnum, const char *base ) {
+static sfx_t *S_RegisterSexedSound(int entnum, const char *base)
+{
sfx_t *sfx;
char *model;
char buffer[MAX_QPATH];
size_t len;
// determine what model the client is using
- if( entnum > 0 && entnum <= MAX_CLIENTS )
- model = cl.clientinfo[ entnum - 1 ].model_name;
+ if (entnum > 0 && entnum <= MAX_CLIENTS)
+ model = cl.clientinfo[entnum - 1].model_name;
else
model = cl.baseclientinfo.model_name;
// if we can't figure it out, they're male
- if( !*model )
+ if (!*model)
model = "male";
// see if we already know of the model specific sound
- len = Q_concat( buffer, MAX_QPATH,
- "players/", model, "/", base + 1, NULL );
- if( len >= MAX_QPATH ) {
- len = Q_concat( buffer, MAX_QPATH,
- "players/", "male", "/", base + 1, NULL );
- if( len >= MAX_QPATH )
+ len = Q_concat(buffer, MAX_QPATH,
+ "players/", model, "/", base + 1, NULL);
+ if (len >= MAX_QPATH) {
+ len = Q_concat(buffer, MAX_QPATH,
+ "players/", "male", "/", base + 1, NULL);
+ if (len >= MAX_QPATH)
return NULL;
}
- len = FS_NormalizePath( buffer, buffer );
- sfx = S_FindName( buffer, len );
+ len = FS_NormalizePath(buffer, buffer);
+ sfx = S_FindName(buffer, len);
// see if it exists
- if( !sfx->truename && !S_LoadSound( sfx ) ) {
+ if (!sfx->truename && !S_LoadSound(sfx)) {
// no, revert to the male sound in the pak0.pak
- len = Q_concat( buffer, MAX_QPATH,
- "sound/player/male/", base + 1, NULL );
- if( len < MAX_QPATH ) {
- FS_NormalizePath( buffer, buffer );
+ len = Q_concat(buffer, MAX_QPATH,
+ "sound/player/male/", base + 1, NULL);
+ if (len < MAX_QPATH) {
+ FS_NormalizePath(buffer, buffer);
sfx->error = Q_ERR_SUCCESS;
- sfx->truename = S_CopyString( buffer );
+ sfx->truename = S_CopyString(buffer);
}
}
@@ -466,7 +480,8 @@ S_EndRegistration
=====================
*/
-void S_EndRegistration( void ) {
+void S_EndRegistration(void)
+{
int i;
sfx_t *sfx;
#if USE_SNDDMA
@@ -478,33 +493,33 @@ void S_EndRegistration( void ) {
S_StopAllSounds();
// free any sounds not from this registration sequence
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- if( sfx->registration_sequence != s_registration_sequence ) {
+ if (sfx->registration_sequence != s_registration_sequence) {
// don't need this sound
- S_FreeSound( sfx );
+ S_FreeSound(sfx);
continue;
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
continue;
#endif
#if USE_SNDDMA
// make sure it is paged in
sc = sfx->cache;
- if( sc ) {
+ if (sc) {
size = sc->length * sc->width;
- Com_PageInMemory( sc, size );
+ Com_PageInMemory(sc, size);
}
#endif
}
// load everything in
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- S_LoadSound( sfx );
+ S_LoadSound(sfx);
}
s_registering = qfalse;
@@ -520,23 +535,24 @@ S_PickChannel
picks a channel based on priorities, empty slots, number of channels
=================
*/
-channel_t *S_PickChannel( int entnum, int entchannel ) {
+channel_t *S_PickChannel(int entnum, int entchannel)
+{
int ch_idx;
int first_to_die;
int life_left;
channel_t *ch;
- if( entchannel < 0 )
- Com_Error( ERR_DROP, "S_PickChannel: entchannel < 0" );
+ if (entchannel < 0)
+ Com_Error(ERR_DROP, "S_PickChannel: entchannel < 0");
// Check for replacement sound, or find the best one to replace
first_to_die = -1;
life_left = 0x7fffffff;
- for( ch_idx = 0; ch_idx < s_numchannels; ch_idx++ ) {
+ for (ch_idx = 0; ch_idx < s_numchannels; ch_idx++) {
ch = &channels[ch_idx];
// channel 0 never overrides unless out of channels
- if( ch->entnum == entnum && ch->entchannel == entchannel && entchannel != 0 ) {
- if( entchannel == 256 && ch->sfx ) {
+ if (ch->entnum == entnum && ch->entchannel == entchannel && entchannel != 0) {
+ if (entchannel == 256 && ch->sfx) {
return NULL; // channel 256 never overrides
}
// always override sound from same entity
@@ -545,27 +561,27 @@ channel_t *S_PickChannel( int entnum, int entchannel ) {
}
// don't let monster sounds override player sounds
- if( ch->entnum == listener_entnum && entnum != listener_entnum && ch->sfx )
+ if (ch->entnum == listener_entnum && entnum != listener_entnum && ch->sfx)
continue;
- if( ch->end - paintedtime < life_left ) {
+ if (ch->end - paintedtime < life_left) {
life_left = ch->end - paintedtime;
first_to_die = ch_idx;
}
}
- if( first_to_die == -1 )
+ if (first_to_die == -1)
return NULL;
ch = &channels[first_to_die];
#if USE_OPENAL
- if( s_started == SS_OAL && ch->sfx )
- AL_StopChannel( ch );
+ if (s_started == SS_OAL && ch->sfx)
+ AL_StopChannel(ch);
#endif
- memset( ch, 0, sizeof( *ch ) );
+ memset(ch, 0, sizeof(*ch));
return ch;
-}
+}
#if USE_SNDDMA
@@ -576,47 +592,48 @@ S_SpatializeOrigin
Used for spatializing channels and autosounds
=================
*/
-static void S_SpatializeOrigin( const vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol ) {
+static void S_SpatializeOrigin(const vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol)
+{
vec_t dot;
vec_t dist;
vec_t lscale, rscale, scale;
vec3_t source_vec;
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
*left_vol = *right_vol = 255;
return;
}
// calculate stereo seperation and distance attenuation
- VectorSubtract( origin, listener_origin, source_vec );
+ VectorSubtract(origin, listener_origin, source_vec);
- dist = VectorNormalize( source_vec );
+ dist = VectorNormalize(source_vec);
dist -= SOUND_FULLVOLUME;
- if( dist < 0 )
+ if (dist < 0)
dist = 0; // close enough to be at full volume
dist *= dist_mult; // different attenuation levels
-
- dot = DotProduct( listener_right, source_vec );
- if( dma.channels == 1 || !dist_mult ) {
+ dot = DotProduct(listener_right, source_vec);
+
+ if (dma.channels == 1 || !dist_mult) {
// no attenuation = no spatialization
rscale = 1.0;
lscale = 1.0;
} else {
- rscale = 0.5 * ( 1.0 + dot );
- lscale = 0.5 * ( 1.0 - dot );
+ rscale = 0.5 * (1.0 + dot);
+ lscale = 0.5 * (1.0 - dot);
}
master_vol *= 255.0;
// add in distance effect
- scale = ( 1.0 - dist ) * rscale;
- *right_vol = (int)( master_vol * scale );
- if( *right_vol < 0 )
+ scale = (1.0 - dist) * rscale;
+ *right_vol = (int)(master_vol * scale);
+ if (*right_vol < 0)
*right_vol = 0;
- scale = ( 1.0 - dist ) * lscale;
- *left_vol = (int)( master_vol * scale );
+ scale = (1.0 - dist) * lscale;
+ *left_vol = (int)(master_vol * scale);
if (*left_vol < 0)
*left_vol = 0;
}
@@ -626,23 +643,24 @@ static void S_SpatializeOrigin( const vec3_t origin, float master_vol, float dis
S_Spatialize
=================
*/
-static void S_Spatialize( channel_t *ch ) {
+static void S_Spatialize(channel_t *ch)
+{
vec3_t origin;
// anything coming from the view entity will always be full volume
- if( ch->entnum == -1 || ch->entnum == listener_entnum ) {
+ if (ch->entnum == -1 || ch->entnum == listener_entnum) {
ch->leftvol = ch->master_vol * 255;
ch->rightvol = ch->master_vol * 255;
return;
}
- if( ch->fixed_origin ) {
- VectorCopy( ch->origin, origin );
+ if (ch->fixed_origin) {
+ VectorCopy(ch->origin, origin);
} else {
- CL_GetEntitySoundOrigin( ch->entnum, origin );
+ CL_GetEntitySoundOrigin(ch->entnum, origin);
}
- S_SpatializeOrigin( origin, ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol );
+ S_SpatializeOrigin(origin, ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol);
}
#endif
@@ -652,17 +670,18 @@ static void S_Spatialize( channel_t *ch ) {
S_AllocPlaysound
=================
*/
-static playsound_t *S_AllocPlaysound( void ) {
+static playsound_t *S_AllocPlaysound(void)
+{
playsound_t *ps;
ps = s_freeplays.next;
- if( ps == &s_freeplays )
+ if (ps == &s_freeplays)
return NULL; // no free playsounds
// unlink from freelist
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
-
+
return ps;
}
@@ -672,7 +691,8 @@ static playsound_t *S_AllocPlaysound( void ) {
S_FreePlaysound
=================
*/
-static void S_FreePlaysound( playsound_t *ps ) {
+static void S_FreePlaysound(playsound_t *ps)
+{
// unlink from channel
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
@@ -693,30 +713,31 @@ This is never called directly by S_Play*, but only
by the update loop.
===============
*/
-void S_IssuePlaysound( playsound_t *ps ) {
+void S_IssuePlaysound(playsound_t *ps)
+{
channel_t *ch;
sfxcache_t *sc;
#ifdef _DEBUG
- if( s_show->integer )
- Com_Printf( "Issue %i\n", ps->begin );
+ if (s_show->integer)
+ Com_Printf("Issue %i\n", ps->begin);
#endif
// pick a channel to play on
- ch = S_PickChannel( ps->entnum, ps->entchannel );
- if( !ch ) {
- S_FreePlaysound( ps );
+ ch = S_PickChannel(ps->entnum, ps->entchannel);
+ if (!ch) {
+ S_FreePlaysound(ps);
return;
}
- sc = S_LoadSound( ps->sfx );
- if( !sc ) {
- Com_Printf( "S_IssuePlaysound: couldn't load %s\n", ps->sfx->name );
- S_FreePlaysound( ps );
+ sc = S_LoadSound(ps->sfx);
+ if (!sc) {
+ Com_Printf("S_IssuePlaysound: couldn't load %s\n", ps->sfx->name);
+ S_FreePlaysound(ps);
return;
}
// spatialize
- if( ps->attenuation == ATTN_STATIC )
+ if (ps->attenuation == ATTN_STATIC)
ch->dist_mult = ps->attenuation * 0.001;
else
ch->dist_mult = ps->attenuation * 0.0005;
@@ -724,24 +745,24 @@ void S_IssuePlaysound( playsound_t *ps ) {
ch->entnum = ps->entnum;
ch->entchannel = ps->entchannel;
ch->sfx = ps->sfx;
- VectorCopy( ps->origin, ch->origin );
+ VectorCopy(ps->origin, ch->origin);
ch->fixed_origin = ps->fixed_origin;
#if USE_OPENAL
- if( s_started == SS_OAL )
- AL_PlayChannel( ch );
+ if (s_started == SS_OAL)
+ AL_PlayChannel(ch);
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
- S_Spatialize( ch );
+ if (s_started == SS_DMA)
+ S_Spatialize(ch);
#endif
ch->pos = 0;
ch->end = paintedtime + sc->length;
// free the playsound
- S_FreePlaysound( ps );
+ S_FreePlaysound(ps);
}
// =======================================================================
@@ -757,38 +778,39 @@ if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
-void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hSfx, float vol, float attenuation, float timeofs ) {
+void S_StartSound(const vec3_t origin, int entnum, int entchannel, qhandle_t hSfx, float vol, float attenuation, float timeofs)
+{
sfxcache_t *sc;
playsound_t *ps, *sort;
sfx_t *sfx;
- if( !s_started )
+ if (!s_started)
return;
- if( !s_active )
+ if (!s_active)
return;
- if( !( sfx = S_SfxForHandle( hSfx ) ) ) {
+ if (!(sfx = S_SfxForHandle(hSfx))) {
return;
}
- if( sfx->name[0] == '*' ) {
- sfx = S_RegisterSexedSound( entnum, sfx->name );
- if( !sfx )
+ if (sfx->name[0] == '*') {
+ sfx = S_RegisterSexedSound(entnum, sfx->name);
+ if (!sfx)
return;
}
// make sure the sound is loaded
- sc = S_LoadSound( sfx );
- if( !sc )
+ sc = S_LoadSound(sfx);
+ if (!sc)
return; // couldn't load the sound's data
// make the playsound_t
ps = S_AllocPlaysound();
- if( !ps )
+ if (!ps)
return;
- if( origin ) {
- VectorCopy( origin, ps->origin );
+ if (origin) {
+ VectorCopy(origin, ps->origin);
ps->fixed_origin = qtrue;
} else {
ps->fixed_origin = qfalse;
@@ -801,17 +823,17 @@ void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hS
ps->sfx = sfx;
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
ps->begin = paintedtime + timeofs * 1000;
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
- ps->begin = DMA_DriftBeginofs( timeofs );
+ if (s_started == SS_DMA)
+ ps->begin = DMA_DriftBeginofs(timeofs);
#endif
// sort into the pending sound list
- for( sort = s_pendingplays.next ; sort != &s_pendingplays && sort->begin < ps->begin ; sort = sort->next )
+ for (sort = s_pendingplays.next; sort != &s_pendingplays && sort->begin < ps->begin; sort = sort->next)
;
ps->next = sort;
@@ -821,20 +843,21 @@ void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hS
ps->prev->next = ps;
}
-void S_ParseStartSound( void ) {
+void S_ParseStartSound(void)
+{
qhandle_t handle = cl.sound_precache[snd.index];
- if( !handle )
+ if (!handle)
return;
#ifdef _DEBUG
- if( developer->integer && !( snd.flags & SND_POS ) )
- CL_CheckEntityPresent( snd.entity, "sound" );
+ if (developer->integer && !(snd.flags & SND_POS))
+ CL_CheckEntityPresent(snd.entity, "sound");
#endif
- S_StartSound( ( snd.flags & SND_POS ) ? snd.pos : NULL,
- snd.entity, snd.channel, handle,
- snd.volume, snd.attenuation, snd.timeofs );
+ S_StartSound((snd.flags & SND_POS) ? snd.pos : NULL,
+ snd.entity, snd.channel, handle,
+ snd.volume, snd.attenuation, snd.timeofs);
}
/*
@@ -842,17 +865,19 @@ void S_ParseStartSound( void ) {
S_StartLocalSound
==================
*/
-void S_StartLocalSound( const char *sound ) {
- if( s_started ) {
- qhandle_t sfx = S_RegisterSound( sound );
- S_StartSound( NULL, listener_entnum, 0, sfx, 1, 1, 0 );
+void S_StartLocalSound(const char *sound)
+{
+ if (s_started) {
+ qhandle_t sfx = S_RegisterSound(sound);
+ S_StartSound(NULL, listener_entnum, 0, sfx, 1, 1, 0);
}
}
-void S_StartLocalSound_( const char *sound ) {
- if( s_started ) {
- qhandle_t sfx = S_RegisterSound( sound );
- S_StartSound( NULL, listener_entnum, 256, sfx, 1, 1, 0 );
+void S_StartLocalSound_(const char *sound)
+{
+ if (s_started) {
+ qhandle_t sfx = S_RegisterSound(sound);
+ S_StartSound(NULL, listener_entnum, 256, sfx, 1, 1, 0);
}
}
@@ -873,8 +898,7 @@ void S_StopAllSounds(void)
s_freeplays.next = s_freeplays.prev = &s_freeplays;
s_pendingplays.next = s_pendingplays.prev = &s_pendingplays;
- for (i=0 ; i<MAX_PLAYSOUNDS ; i++)
- {
+ for (i = 0; i < MAX_PLAYSOUNDS; i++) {
s_playsounds[i].prev = &s_freeplays;
s_playsounds[i].next = s_freeplays.next;
s_playsounds[i].prev->next = &s_playsounds[i];
@@ -882,12 +906,12 @@ void S_StopAllSounds(void)
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_StopAllChannels();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_ClearBuffer();
#endif
@@ -899,17 +923,18 @@ void S_StopAllSounds(void)
// Update sound buffer
// =======================================================================
-void S_BuildSoundList( int *sounds ) {
+void S_BuildSoundList(int *sounds)
+{
int i;
int num;
entity_state_t *ent;
- for( i = 0; i < cl.frame.numEntities; i++ ) {
- num = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ for (i = 0; i < cl.frame.numEntities; i++) {
+ num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
- if( s_ambient->integer == 2 && !ent->modelindex ) {
+ if (s_ambient->integer == 2 && !ent->modelindex) {
sounds[i] = 0;
- } else if( s_ambient->integer == 3 && ent->number != listener_entnum ) {
+ } else if (s_ambient->integer == 3 && ent->number != listener_entnum) {
sounds[i] = 0;
} else {
sounds[i] = ent->sound;
@@ -928,7 +953,7 @@ that are automatically started, stopped, and merged together
as the entities are sent to the client
==================
*/
-static void S_AddLoopSounds (void)
+static void S_AddLoopSounds(void)
{
int i, j;
int sounds[MAX_PACKET_ENTITIES];
@@ -940,42 +965,41 @@ static void S_AddLoopSounds (void)
entity_state_t *ent;
vec3_t origin;
- if( cls.state != ca_active || !s_active || sv_paused->integer || !s_ambient->integer ) {
+ if (cls.state != ca_active || !s_active || sv_paused->integer || !s_ambient->integer) {
return;
}
- S_BuildSoundList( sounds );
+ S_BuildSoundList(sounds);
- for( i = 0; i < cl.frame.numEntities; i++ ) {
+ for (i = 0; i < cl.frame.numEntities; i++) {
if (!sounds[i])
continue;
- sfx = S_SfxForHandle( cl.sound_precache[sounds[i]] );
+ sfx = S_SfxForHandle(cl.sound_precache[sounds[i]]);
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
if (!sc)
continue;
- num = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
// find the total contribution of all sounds of this type
- CL_GetEntitySoundOrigin( ent->number, origin );
- S_SpatializeOrigin (origin, 1.0, SOUND_LOOPATTENUATE,
- &left_total, &right_total);
- for (j=i+1 ; j<cl.frame.numEntities ; j++)
- {
+ CL_GetEntitySoundOrigin(ent->number, origin);
+ S_SpatializeOrigin(origin, 1.0, SOUND_LOOPATTENUATE,
+ &left_total, &right_total);
+ for (j = i + 1; j < cl.frame.numEntities; j++) {
if (sounds[j] != sounds[i])
continue;
sounds[j] = 0; // don't check this again later
- num = ( cl.frame.firstEntity + j ) & PARSE_ENTITIES_MASK;
+ num = (cl.frame.firstEntity + j) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
- CL_GetEntitySoundOrigin( ent->number, origin );
- S_SpatializeOrigin (origin, 1.0, SOUND_LOOPATTENUATE,
- &left, &right);
+ CL_GetEntitySoundOrigin(ent->number, origin);
+ S_SpatializeOrigin(origin, 1.0, SOUND_LOOPATTENUATE,
+ &left, &right);
left_total += left;
right_total += right;
}
@@ -1010,14 +1034,15 @@ S_Update
Called once each time through the main loop
============
*/
-void S_Update( void ) {
+void S_Update(void)
+{
#if USE_SNDDMA
int i;
channel_t *ch;
#endif
- if( cvar_modified & CVAR_SOUND ) {
- Cbuf_AddText( &cmd_buffer, "snd_restart\n" );
+ if (cvar_modified & CVAR_SOUND) {
+ Cbuf_AddText(&cmd_buffer, "snd_restart\n");
cvar_modified &= ~CVAR_SOUND;
return;
}
@@ -1035,14 +1060,14 @@ void S_Update( void ) {
// set listener entity number
// other parameters should be already set up by CL_CalcViewValues
- if( cl.clientNum == -1 || cl.frame.clientNum == CLIENTNUM_NONE ) {
+ if (cl.clientNum == -1 || cl.frame.clientNum == CLIENTNUM_NONE) {
listener_entnum = -1;
} else {
listener_entnum = cl.frame.clientNum + 1;
}
#if USE_OPENAL
- if( s_started == SS_OAL ) {
+ if (s_started == SS_OAL) {
AL_Update();
return;
}
@@ -1051,47 +1076,43 @@ void S_Update( void ) {
#if USE_SNDDMA
// rebuild scale tables if volume is modified
if (s_volume->modified)
- S_InitScaletable ();
+ S_InitScaletable();
- // update spatialization for dynamic sounds
+ // update spatialization for dynamic sounds
ch = channels;
- for (i=0 ; i<s_numchannels; i++, ch++)
- {
+ for (i = 0; i < s_numchannels; i++, ch++) {
if (!ch->sfx)
continue;
- if (ch->autosound)
- { // autosounds are regenerated fresh each frame
- memset (ch, 0, sizeof(*ch));
+ if (ch->autosound) {
+ // autosounds are regenerated fresh each frame
+ memset(ch, 0, sizeof(*ch));
continue;
}
S_Spatialize(ch); // respatialize channel
- if (!ch->leftvol && !ch->rightvol)
- {
- memset (ch, 0, sizeof(*ch));
+ if (!ch->leftvol && !ch->rightvol) {
+ memset(ch, 0, sizeof(*ch));
continue;
}
}
// add loopsounds
- S_AddLoopSounds ();
+ S_AddLoopSounds();
#ifdef _DEBUG
//
// debugging output
//
- if (s_show->integer)
- {
+ if (s_show->integer) {
int total = 0;
ch = channels;
- for (i=0 ; i<s_numchannels; i++, ch++)
- if (ch->sfx && (ch->leftvol || ch->rightvol) )
- {
- Com_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
+ for (i = 0; i < s_numchannels; i++, ch++)
+ if (ch->sfx && (ch->leftvol || ch->rightvol)) {
+ Com_Printf("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
total++;
}
-
- if( s_show->integer > 1 || total ) {
- Com_Printf ("----(%i)---- painted: %i\n", total, paintedtime);
+
+ if (s_show->integer > 1 || total) {
+ Com_Printf("----(%i)---- painted: %i\n", total, paintedtime);
}
}
#endif
diff --git a/src/snd_mem.c b/src/snd_mem.c
index 07b999b..332a25e 100644
--- a/src/snd_mem.c
+++ b/src/snd_mem.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -30,7 +30,8 @@ wavinfo_t s_info;
ResampleSfx
================
*/
-static sfxcache_t *ResampleSfx( sfx_t *sfx ) {
+static sfxcache_t *ResampleSfx(sfx_t *sfx)
+{
int outcount;
int srcsample;
float stepscale;
@@ -38,17 +39,17 @@ static sfxcache_t *ResampleSfx( sfx_t *sfx ) {
int samplefrac, fracstep;
sfxcache_t *sc;
- stepscale = ( float )s_info.rate / dma.speed; // this is usually 0.5, 1, or 2
+ stepscale = (float)s_info.rate / dma.speed; // this is usually 0.5, 1, or 2
outcount = s_info.samples / stepscale;
- if( !outcount ) {
- Com_DPrintf( "%s resampled to zero length\n", s_info.name );
+ if (!outcount) {
+ Com_DPrintf("%s resampled to zero length\n", s_info.name);
sfx->error = Q_ERR_TOO_FEW;
return NULL;
}
- sc = sfx->cache = S_Malloc( outcount * s_info.width + sizeof( sfxcache_t ) - 1 );
-
+ sc = sfx->cache = S_Malloc(outcount * s_info.width + sizeof(sfxcache_t) - 1);
+
sc->length = outcount;
sc->loopstart = s_info.loopstart == -1 ? -1 : s_info.loopstart / stepscale;
sc->width = s_info.width;
@@ -57,22 +58,22 @@ static sfxcache_t *ResampleSfx( sfx_t *sfx ) {
//Com_Printf("%s: %f, %d\n",sfx->name,stepscale,sc->width);
if (stepscale == 1) {
// fast special case
- if( sc->width == 1 ) {
- memcpy( sc->data, s_info.data, outcount );
+ if (sc->width == 1) {
+ memcpy(sc->data, s_info.data, outcount);
} else {
#if __BYTE_ORDER == __LITTLE_ENDIAN
- memcpy( sc->data, s_info.data, outcount << 1 );
+ memcpy(sc->data, s_info.data, outcount << 1);
#else
- for(i = 0; i < outcount; i++) {
- ((uint16_t *)sc->data)[i] = LittleShort( (( uint16_t * )s_info.data)[i] );
+ for (i = 0; i < outcount; i++) {
+ ((uint16_t *)sc->data)[i] = LittleShort(((uint16_t *)s_info.data)[i]);
}
#endif
}
} else {
// general case
samplefrac = 0;
- fracstep = stepscale*256;
- if( sc->width == 1 ) {
+ fracstep = stepscale * 256;
+ if (sc->width == 1) {
for (i = 0; i < outcount; i++) {
srcsample = samplefrac >> 8;
samplefrac += fracstep;
@@ -82,7 +83,7 @@ static sfxcache_t *ResampleSfx( sfx_t *sfx ) {
for (i = 0; i < outcount; i++) {
srcsample = samplefrac >> 8;
samplefrac += fracstep;
- ((uint16_t *)sc->data)[i] = LittleShort( (( uint16_t * )s_info.data)[srcsample] );
+ ((uint16_t *)sc->data)[i] = LittleShort(((uint16_t *)s_info.data)[srcsample]);
}
}
}
@@ -104,132 +105,138 @@ static byte *iff_end;
static byte *iff_data;
static uint32_t iff_chunk_len;
-static int GetLittleShort( void ) {
+static int GetLittleShort(void)
+{
int val;
- if( data_p + 2 > iff_end ) {
+ if (data_p + 2 > iff_end) {
return -1;
}
- val = LittleShortMem( data_p );
+ val = LittleShortMem(data_p);
data_p += 2;
return val;
}
-static int GetLittleLong( void ) {
+static int GetLittleLong(void)
+{
int val;
- if( data_p + 4 > iff_end ) {
+ if (data_p + 4 > iff_end) {
return -1;
}
- val = LittleLongMem( data_p );
+ val = LittleLongMem(data_p);
data_p += 4;
return val;
}
-static int GetRawLong( void ) {
+static int GetRawLong(void)
+{
int val;
- if( data_p + 4 > iff_end ) {
+ if (data_p + 4 > iff_end) {
return -1;
}
- val = RawLongMem( data_p );
+ val = RawLongMem(data_p);
data_p += 4;
return val;
}
-static void FindNextChunk( uint32_t search ) {
+static void FindNextChunk(uint32_t search)
+{
uint32_t chunk, length;
int i;
- for( i = 0; i < 1000; i++ ) {
- if( data_p + 8 >= iff_end ) {
+ for (i = 0; i < 1000; i++) {
+ if (data_p + 8 >= iff_end) {
data_p = NULL;
return; // didn't find the chunk
}
chunk = GetRawLong();
iff_chunk_len = GetLittleLong();
- if( iff_chunk_len > iff_end - data_p ) {
- Com_DPrintf( "%s: oversize chunk %#x in %s\n",
- __func__, LittleLong( chunk ), s_info.name );
+ if (iff_chunk_len > iff_end - data_p) {
+ Com_DPrintf("%s: oversize chunk %#x in %s\n",
+ __func__, LittleLong(chunk), s_info.name);
data_p = NULL;
return;
}
- if( chunk == search ) {
+ if (chunk == search) {
return;
}
- length = ( iff_chunk_len + 1 ) & ~1;
+ length = (iff_chunk_len + 1) & ~1;
data_p += length;
}
- Com_DPrintf( "%s: too many iterations for chunk %#x in %s\n",
- __func__, search, s_info.name );
+ Com_DPrintf("%s: too many iterations for chunk %#x in %s\n",
+ __func__, search, s_info.name);
data_p = NULL;
}
-static void FindChunk( uint32_t search ) {
+static void FindChunk(uint32_t search)
+{
data_p = iff_data;
- FindNextChunk( search );
+ FindNextChunk(search);
}
-#define TAG_RIFF MakeRawLong( 'R', 'I', 'F', 'F' )
-#define TAG_WAVE MakeRawLong( 'W', 'A', 'V', 'E' )
-#define TAG_fmt MakeRawLong( 'f', 'm', 't', ' ' )
-#define TAG_cue MakeRawLong( 'c', 'u', 'e', ' ' )
-#define TAG_LIST MakeRawLong( 'L', 'I', 'S', 'T' )
-#define TAG_MARK MakeRawLong( 'M', 'A', 'R', 'K' )
-#define TAG_data MakeRawLong( 'd', 'a', 't', 'a' )
+#define TAG_RIFF MakeRawLong('R', 'I', 'F', 'F')
+#define TAG_WAVE MakeRawLong('W', 'A', 'V', 'E')
+#define TAG_fmt MakeRawLong('f', 'm', 't', ' ')
+#define TAG_cue MakeRawLong('c', 'u', 'e', ' ')
+#define TAG_LIST MakeRawLong('L', 'I', 'S', 'T')
+#define TAG_MARK MakeRawLong('M', 'A', 'R', 'K')
+#define TAG_data MakeRawLong('d', 'a', 't', 'a')
-static qboolean GetWavinfo( void ) {
+static qboolean GetWavinfo(void)
+{
int format;
int samples, width;
uint32_t chunk;
// find "RIFF" chunk
- FindChunk( TAG_RIFF );
- if( !data_p ) {
- Com_DPrintf( "%s has missing/invalid RIFF chunk\n", s_info.name );
+ FindChunk(TAG_RIFF);
+ if (!data_p) {
+ Com_DPrintf("%s has missing/invalid RIFF chunk\n", s_info.name);
return qfalse;
}
chunk = GetLittleLong();
- if( chunk != TAG_WAVE ) {
- Com_DPrintf( "%s has missing/invalid WAVE chunk\n", s_info.name );
+ if (chunk != TAG_WAVE) {
+ Com_DPrintf("%s has missing/invalid WAVE chunk\n", s_info.name);
return qfalse;
}
iff_data = data_p;
// get "fmt " chunk
- FindChunk( TAG_fmt );
- if( !data_p ) {
- Com_DPrintf("%s has missing/invalid fmt chunk\n", s_info.name );
+ FindChunk(TAG_fmt);
+ if (!data_p) {
+ Com_DPrintf("%s has missing/invalid fmt chunk\n", s_info.name);
return qfalse;
}
format = GetLittleShort();
- if( format != 1 ) {
- Com_DPrintf( "%s has non-Microsoft PCM format\n", s_info.name );
+ if (format != 1) {
+ Com_DPrintf("%s has non-Microsoft PCM format\n", s_info.name);
return qfalse;
}
format = GetLittleShort();
- if( format != 1 ) {
- Com_DPrintf( "%s has bad number of channels\n", s_info.name );
+ if (format != 1) {
+ Com_DPrintf("%s has bad number of channels\n", s_info.name);
return qfalse;
}
s_info.rate = GetLittleLong();
- if( s_info.rate < 8000 || s_info.rate > 48000 ) {
- Com_DPrintf( "%s has bad rate\n", s_info.name );
+ if (s_info.rate < 8000 || s_info.rate > 48000) {
+ Com_DPrintf("%s has bad rate\n", s_info.name);
return qfalse;
}
- data_p += 4+2;
+ data_p += 4 + 2;
width = GetLittleShort();
- switch( width ) {
+ switch (width) {
case 8:
s_info.width = 1;
break;
@@ -237,30 +244,30 @@ static qboolean GetWavinfo( void ) {
s_info.width = 2;
break;
default:
- Com_DPrintf( "%s has bad width\n", s_info.name );
+ Com_DPrintf("%s has bad width\n", s_info.name);
return qfalse;
}
// get cue chunk
- FindChunk( TAG_cue );
- if( data_p ) {
+ FindChunk(TAG_cue);
+ if (data_p) {
data_p += 24;
s_info.loopstart = GetLittleLong();
- if( s_info.loopstart < 0 || s_info.loopstart > INT_MAX ) {
- Com_DPrintf( "%s has bad loop start\n", s_info.name );
+ if (s_info.loopstart < 0 || s_info.loopstart > INT_MAX) {
+ Com_DPrintf("%s has bad loop start\n", s_info.name);
return qfalse;
}
- FindNextChunk( TAG_LIST );
- if( data_p ) {
+ FindNextChunk(TAG_LIST);
+ if (data_p) {
data_p += 20;
chunk = GetLittleLong();
- if( chunk == TAG_MARK ) {
- // this is not a proper parse, but it works with cooledit...
+ if (chunk == TAG_MARK) {
+ // this is not a proper parse, but it works with cooledit...
data_p += 16;
samples = GetLittleLong(); // samples in loop
- if( samples < 0 || samples > INT_MAX - s_info.loopstart ) {
- Com_DPrintf( "%s has bad loop length\n", s_info.name );
+ if (samples < 0 || samples > INT_MAX - s_info.loopstart) {
+ Com_DPrintf("%s has bad loop length\n", s_info.name);
return qfalse;
}
s_info.samples = s_info.loopstart + samples;
@@ -271,21 +278,21 @@ static qboolean GetWavinfo( void ) {
}
// find data chunk
- FindChunk( TAG_data );
- if( !data_p ) {
- Com_DPrintf( "%s has missing/invalid data chunk\n", s_info.name );
+ FindChunk(TAG_data);
+ if (!data_p) {
+ Com_DPrintf("%s has missing/invalid data chunk\n", s_info.name);
return qfalse;
}
samples = iff_chunk_len / s_info.width;
- if( !samples ) {
- Com_DPrintf( "%s has zero length\n", s_info.name );
+ if (!samples) {
+ Com_DPrintf("%s has zero length\n", s_info.name);
return qfalse;
}
- if( s_info.samples ) {
- if( samples < s_info.samples ) {
- Com_DPrintf( "%s has bad loop length\n", s_info.name );
+ if (s_info.samples) {
+ if (samples < s_info.samples) {
+ Com_DPrintf("%s has bad loop length\n", s_info.name);
return qfalse;
}
} else {
@@ -302,7 +309,8 @@ static qboolean GetWavinfo( void ) {
S_LoadSound
==============
*/
-sfxcache_t *S_LoadSound (sfx_t *s) {
+sfxcache_t *S_LoadSound(sfx_t *s)
+{
byte *data;
sfxcache_t *sc;
ssize_t len;
@@ -326,34 +334,34 @@ sfxcache_t *S_LoadSound (sfx_t *s) {
else
name = s->name;
- len = FS_LoadFile (name, (void **)&data);
+ len = FS_LoadFile(name, (void **)&data);
if (!data) {
s->error = len;
return NULL;
}
- memset( &s_info, 0, sizeof( s_info ) );
+ memset(&s_info, 0, sizeof(s_info));
s_info.name = name;
iff_data = data;
iff_end = data + len;
- if( !GetWavinfo() ) {
+ if (!GetWavinfo()) {
s->error = Q_ERR_INVALID_FORMAT;
goto fail;
}
#if USE_OPENAL
- if( s_started == SS_OAL ) {
- sc = AL_UploadSfx( s );
+ if (s_started == SS_OAL) {
+ sc = AL_UploadSfx(s);
} else
#endif
#if USE_SNDDMA
- sc = ResampleSfx( s )
+ sc = ResampleSfx(s)
#endif
- ;
+ ;
fail:
- FS_FreeFile( data );
+ FS_FreeFile(data);
return sc;
}
diff --git a/src/snd_mix.c b/src/snd_mix.c
index 4192163..712afb8 100644
--- a/src/snd_mix.c
+++ b/src/snd_mix.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,91 +27,95 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static int snd_scaletable[32][256];
static int snd_vol;
-static void WriteLinearBlast( int16_t *out, samplepair_t *samp, int count ) {
+static void WriteLinearBlast(int16_t *out, samplepair_t *samp, int count)
+{
int i, val;
- for( i = 0; i < count; i++, samp++, out += 2 ) {
+ for (i = 0; i < count; i++, samp++, out += 2) {
val = samp->left >> 8;
- out[0] = clamp( val, INT16_MIN, INT16_MAX );
+ out[0] = clamp(val, INT16_MIN, INT16_MAX);
val = samp->right >> 8;
- out[1] = clamp( val, INT16_MIN, INT16_MAX );
+ out[1] = clamp(val, INT16_MIN, INT16_MAX);
}
}
-static void TransferStereo16( samplepair_t *samp, int endtime ) {
+static void TransferStereo16(samplepair_t *samp, int endtime)
+{
int lpos;
int ltime;
int16_t *out;
int count;
-
- for( ltime = paintedtime; ltime < endtime; ) {
- // handle recirculating buffer issues
- lpos = ltime & ( ( dma.samples >> 1 ) - 1 );
- out = ( int16_t * )dma.buffer + ( lpos << 1 );
+ for (ltime = paintedtime; ltime < endtime;) {
+ // handle recirculating buffer issues
+ lpos = ltime & ((dma.samples >> 1) - 1);
- count = ( dma.samples >> 1 ) - lpos;
- if( ltime + count > endtime )
+ out = (int16_t *)dma.buffer + (lpos << 1);
+
+ count = (dma.samples >> 1) - lpos;
+ if (ltime + count > endtime)
count = endtime - ltime;
- // write a linear blast of samples
- WriteLinearBlast( out, samp, count );
+ // write a linear blast of samples
+ WriteLinearBlast(out, samp, count);
samp += count;
ltime += count;
}
}
-static void TransferStereo( samplepair_t *samp, int endtime ) {
+static void TransferStereo(samplepair_t *samp, int endtime)
+{
int out_idx, out_mask;
int count;
int *p, val;
int step;
- p = ( int * )samp;
+ p = (int *)samp;
count = (endtime - paintedtime) * dma.channels;
- out_mask = dma.samples - 1;
+ out_mask = dma.samples - 1;
out_idx = paintedtime * dma.channels & out_mask;
step = 3 - dma.channels;
if (dma.samplebits == 16) {
- int16_t *out = ( int16_t * )dma.buffer;
- while( count-- ) {
+ int16_t *out = (int16_t *)dma.buffer;
+ while (count--) {
val = *p >> 8;
p += step;
- clamp( val, INT16_MIN, INT16_MAX );
+ clamp(val, INT16_MIN, INT16_MAX);
out[out_idx] = val;
- out_idx = ( out_idx + 1 ) & out_mask;
+ out_idx = (out_idx + 1) & out_mask;
}
- } else if( dma.samplebits == 8 ) {
- uint8_t *out = ( uint8_t * )dma.buffer;
- while( count-- ) {
+ } else if (dma.samplebits == 8) {
+ uint8_t *out = (uint8_t *)dma.buffer;
+ while (count--) {
val = *p >> 8;
p += step;
- clamp( val, INT16_MIN, INT16_MAX );
- out[out_idx] = ( val >> 8 ) + 128;
- out_idx = ( out_idx + 1 ) & out_mask;
+ clamp(val, INT16_MIN, INT16_MAX);
+ out[out_idx] = (val >> 8) + 128;
+ out_idx = (out_idx + 1) & out_mask;
}
}
}
-static void TransferPaintBuffer( samplepair_t *samp, int endtime ) {
- if( s_testsound->integer ) {
+static void TransferPaintBuffer(samplepair_t *samp, int endtime)
+{
+ if (s_testsound->integer) {
int i;
// write a fixed sine wave
- for( i = paintedtime; i < endtime; i++ ) {
- samp[i].left = samp[i].right = sin( i * 0.1 ) * 20000 * 256;
+ for (i = paintedtime; i < endtime; i++) {
+ samp[i].left = samp[i].right = sin(i * 0.1) * 20000 * 256;
}
}
- if( dma.samplebits == 16 && dma.channels == 2 ) {
+ if (dma.samplebits == 16 && dma.channels == 2) {
// optimized case
- TransferStereo16( samp, endtime );
+ TransferStereo16(samp, endtime);
} else {
// general case
- TransferStereo( samp, endtime );
+ TransferStereo(samp, endtime);
}
}
@@ -124,7 +128,8 @@ CHANNEL MIXING
===============================================================================
*/
-static void Paint8( channel_t *ch, sfxcache_t *sc, int count, samplepair_t *samp ) {
+static void Paint8(channel_t *ch, sfxcache_t *sc, int count, samplepair_t *samp)
+{
int data;
int *lscale, *rscale;
uint8_t *sfx;
@@ -135,34 +140,35 @@ static void Paint8( channel_t *ch, sfxcache_t *sc, int count, samplepair_t *samp
if (ch->rightvol > 255)
ch->rightvol = 255;
- lscale = snd_scaletable[ ch->leftvol >> 3 ];
- rscale = snd_scaletable[ ch->rightvol >> 3 ];
- sfx = ( uint8_t * )sc->data + ch->pos;
+ lscale = snd_scaletable[ch->leftvol >> 3];
+ rscale = snd_scaletable[ch->rightvol >> 3];
+ sfx = (uint8_t *)sc->data + ch->pos;
- for( i = 0; i < count; i++, samp++ ) {
+ for (i = 0; i < count; i++, samp++) {
data = *sfx++;
samp->left += lscale[data];
samp->right += rscale[data];
}
-
+
ch->pos += count;
}
-static void Paint16( channel_t *ch, sfxcache_t *sc, int count, samplepair_t *samp ) {
+static void Paint16(channel_t *ch, sfxcache_t *sc, int count, samplepair_t *samp)
+{
int data;
int left, right;
int leftvol, rightvol;
int16_t *sfx;
int i;
- leftvol = ch->leftvol*snd_vol;
- rightvol = ch->rightvol*snd_vol;
- sfx = ( int16_t * )sc->data + ch->pos;
+ leftvol = ch->leftvol * snd_vol;
+ rightvol = ch->rightvol * snd_vol;
+ sfx = (int16_t *)sc->data + ch->pos;
- for( i = 0; i < count; i++, samp++ ) {
+ for (i = 0; i < count; i++, samp++) {
data = *sfx++;
- left = ( data * leftvol ) >> 8;
- right = ( data * rightvol ) >> 8;
+ left = (data * leftvol) >> 8;
+ right = (data * rightvol) >> 8;
samp->left += left;
samp->right += right;
}
@@ -170,7 +176,8 @@ static void Paint16( channel_t *ch, sfxcache_t *sc, int count, samplepair_t *sam
ch->pos += count;
}
-void S_PaintChannels(int endtime) {
+void S_PaintChannels(int endtime)
+{
samplepair_t paintbuffer[PAINTBUFFER_SIZE];
int i;
int end;
@@ -191,7 +198,7 @@ void S_PaintChannels(int endtime) {
if (ps == &s_pendingplays)
break; // no more pending sounds
if (ps->begin <= paintedtime) {
- S_IssuePlaysound (ps);
+ S_IssuePlaysound(ps);
continue;
}
@@ -205,11 +212,11 @@ void S_PaintChannels(int endtime) {
// paint in the channels.
ch = channels;
- for (i=0; i<s_numchannels ; i++, ch++) {
+ for (i = 0; i < s_numchannels; i++, ch++) {
ltime = paintedtime;
-
+
while (ltime < end) {
- if (!ch->sfx || (!ch->leftvol && !ch->rightvol) )
+ if (!ch->sfx || (!ch->leftvol && !ch->rightvol))
break;
// max painting is to the end of the buffer
@@ -218,18 +225,18 @@ void S_PaintChannels(int endtime) {
// might be stopped by running out of data
if (ch->end - ltime < count)
count = ch->end - ltime;
-
- sc = S_LoadSound (ch->sfx);
+
+ sc = S_LoadSound(ch->sfx);
if (!sc)
break;
- if (count > 0 && ch->sfx) {
+ if (count > 0 && ch->sfx) {
samplepair_t *samp = &paintbuffer[ltime - paintedtime];
if (sc->width == 1)
Paint8(ch, sc, count, samp);
else
Paint16(ch, sc, count, samp);
-
+
ltime += count;
}
@@ -248,7 +255,7 @@ void S_PaintChannels(int endtime) {
}
}
}
-
+
}
// transfer out according to DMA format
@@ -257,17 +264,18 @@ void S_PaintChannels(int endtime) {
}
}
-void S_InitScaletable( void ) {
+void S_InitScaletable(void)
+{
int i, j;
int scale;
- Cvar_ClampValue( s_volume, 0, 1 );
+ Cvar_ClampValue(s_volume, 0, 1);
snd_vol = s_volume->value * 256;
- for( i = 0; i < 32; i++ ) {
+ for (i = 0; i < 32; i++) {
scale = i * 8 * snd_vol;
- for ( j = 0; j < 256; j++ ) {
- snd_scaletable[i][j] = ( j - 128 ) * scale;
+ for (j = 0; j < 256; j++) {
+ snd_scaletable[i][j] = (j - 128) * scale;
}
}
diff --git a/src/snd_oss.c b/src/snd_oss.c
index d62030f..ec9f08f 100644
--- a/src/snd_oss.c
+++ b/src/snd_oss.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
-
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
+
See the GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+
*/
#include <unistd.h>
#include <fcntl.h>
@@ -45,41 +45,41 @@ static cvar_t *s_device;
static const int tryrates[] = { 22050, 11025, 44100, 48000, 8000 };
-static sndinitstat_t OSS_Init ( void ) {
+static sndinitstat_t OSS_Init(void)
+{
int rc;
int fmt;
int tmp;
int i;
int caps;
- if ( snd_inited )
+ if (snd_inited)
return SIS_SUCCESS;
- s_bits = Cvar_Get ( "s_bits", "16", CVAR_SOUND );
- s_channels = Cvar_Get ( "s_channels", "2", CVAR_SOUND );
- s_device = Cvar_Get ( "s_device", "/dev/dsp", CVAR_SOUND );
+ s_bits = Cvar_Get("s_bits", "16", CVAR_SOUND);
+ s_channels = Cvar_Get("s_channels", "2", CVAR_SOUND);
+ s_device = Cvar_Get("s_device", "/dev/dsp", CVAR_SOUND);
// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
- audio_fd = open ( s_device->string, O_RDWR );
+ audio_fd = open(s_device->string, O_RDWR);
- if ( audio_fd < 0 ) {
- Com_WPrintf ( "Could not open %s: %s\n", s_device->string,
- strerror ( errno ) );
+ if (audio_fd < 0) {
+ Com_WPrintf("Could not open %s: %s\n", s_device->string,
+ strerror(errno));
return SIS_FAILURE;
}
- if ( ioctl ( audio_fd, SNDCTL_DSP_GETCAPS, &caps ) == -1 ) {
- Com_WPrintf ( "Could not get caps of %s: %s\n", s_device->string,
- strerror ( errno ) );
+ if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps) == -1) {
+ Com_WPrintf("Could not get caps of %s: %s\n", s_device->string,
+ strerror(errno));
goto fail;
}
- if( ( caps & (DSP_CAP_TRIGGER|DSP_CAP_MMAP) ) !=
- (DSP_CAP_TRIGGER|DSP_CAP_MMAP) )
- {
- Com_WPrintf ( "%s does not support TRIGGER and/or MMAP capabilities\n",
- s_device->string );
+ if ((caps & (DSP_CAP_TRIGGER | DSP_CAP_MMAP)) !=
+ (DSP_CAP_TRIGGER | DSP_CAP_MMAP)) {
+ Com_WPrintf("%s does not support TRIGGER and/or MMAP capabilities\n",
+ s_device->string);
goto fail;
}
@@ -87,16 +87,16 @@ static sndinitstat_t OSS_Init ( void ) {
// set sample bits & speed
dma.samplebits = s_bits->integer;
- if ( dma.samplebits != 16 && dma.samplebits != 8 ) {
- ioctl ( audio_fd, SNDCTL_DSP_GETFMTS, &fmt );
- if ( fmt & AFMT_S16_LE ) {
+ if (dma.samplebits != 16 && dma.samplebits != 8) {
+ ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
+ if (fmt & AFMT_S16_LE) {
dma.samplebits = 16;
- } else if ( fmt & AFMT_U8 ) {
+ } else if (fmt & AFMT_U8) {
dma.samplebits = 8;
}
}
- switch( s_khz->integer ) {
+ switch (s_khz->integer) {
case 48:
dma.speed = 48000;
break;
@@ -110,12 +110,12 @@ static sndinitstat_t OSS_Init ( void ) {
dma.speed = 11025;
break;
default:
- for ( i = 0; i < sizeof ( tryrates ) / 4; i++ ) {
- if ( !ioctl ( audio_fd, SNDCTL_DSP_SPEED, &tryrates[i] ) )
+ for (i = 0; i < sizeof(tryrates) / 4; i++) {
+ if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
break;
}
- if ( i == sizeof ( tryrates ) / 4 ) {
- Com_WPrintf ( "%s supports no valid bitrates\n", s_device->string );
+ if (i == sizeof(tryrates) / 4) {
+ Com_WPrintf("%s supports no valid bitrates\n", s_device->string);
goto fail;
}
dma.speed = tryrates[i];
@@ -125,82 +125,82 @@ static sndinitstat_t OSS_Init ( void ) {
dma.channels = s_channels->integer;
tmp = 0;
- if ( dma.channels == 2 )
+ if (dma.channels == 2)
tmp = 1;
- rc = ioctl ( audio_fd, SNDCTL_DSP_STEREO, &tmp );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not set %s to %d channels: %s\n", s_device->string,
- dma.channels, strerror ( errno ) );
+ rc = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
+ if (rc < 0) {
+ Com_WPrintf("Could not set %s to %d channels: %s\n", s_device->string,
+ dma.channels, strerror(errno));
goto fail;
}
- if ( tmp )
+ if (tmp)
dma.channels = 2;
else
dma.channels = 1;
- rc = ioctl ( audio_fd, SNDCTL_DSP_SPEED, &dma.speed );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not set %s speed to %d: %s\n", s_device->string,
- dma.speed, strerror ( errno ) );
+ rc = ioctl(audio_fd, SNDCTL_DSP_SPEED, &dma.speed);
+ if (rc < 0) {
+ Com_WPrintf("Could not set %s speed to %d: %s\n", s_device->string,
+ dma.speed, strerror(errno));
goto fail;
}
- if ( dma.samplebits == 16 ) {
+ if (dma.samplebits == 16) {
rc = AFMT_S16_LE;
- rc = ioctl ( audio_fd, SNDCTL_DSP_SETFMT, &rc );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not support 16-bit data. Try 8-bit.\n" );
+ rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
+ if (rc < 0) {
+ Com_WPrintf("Could not support 16-bit data. Try 8-bit.\n");
goto fail;
}
- } else if ( dma.samplebits == 8 ) {
+ } else if (dma.samplebits == 8) {
rc = AFMT_U8;
- rc = ioctl ( audio_fd, SNDCTL_DSP_SETFMT, &rc );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not support 8-bit data.\n" );
+ rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
+ if (rc < 0) {
+ Com_WPrintf("Could not support 8-bit data.\n");
goto fail;
}
} else {
- Com_WPrintf ( "%d-bit sound not supported.\n", dma.samplebits );
+ Com_WPrintf("%d-bit sound not supported.\n", dma.samplebits);
goto fail;
}
- if ( ioctl ( audio_fd, SNDCTL_DSP_GETOSPACE, &info ) ==-1 ) {
- Com_WPrintf ( "Could not do GETOSPACE: %s\n", strerror ( errno ) );
+ if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == -1) {
+ Com_WPrintf("Could not do GETOSPACE: %s\n", strerror(errno));
goto fail;
}
- dma.samples = info.fragstotal * info.fragsize / ( dma.samplebits >> 3 );
+ dma.samples = info.fragstotal * info.fragsize / (dma.samplebits >> 3);
dma.submission_chunk = 1;
// memory map the dma buffer
- dma.buffer = ( byte * ) mmap ( NULL, info.fragstotal * info.fragsize,
- PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0 );
- if ( !dma.buffer ) {
- Com_WPrintf ( "Could not mmap %s: %s\n", s_device->string,
- strerror ( errno ) );
+ dma.buffer = (byte *) mmap(NULL, info.fragstotal * info.fragsize,
+ PROT_WRITE, MAP_FILE | MAP_SHARED, audio_fd, 0);
+ if (!dma.buffer) {
+ Com_WPrintf("Could not mmap %s: %s\n", s_device->string,
+ strerror(errno));
goto fail;
}
// toggle the trigger & start her up
tmp = 0;
- rc = ioctl ( audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not toggle (0): %s\n", strerror ( errno ) );
- munmap ( dma.buffer, info.fragstotal * info.fragsize );
+ rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
+ if (rc < 0) {
+ Com_WPrintf("Could not toggle (0): %s\n", strerror(errno));
+ munmap(dma.buffer, info.fragstotal * info.fragsize);
goto fail;
}
tmp = PCM_ENABLE_OUTPUT;
- rc = ioctl ( audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp );
- if ( rc < 0 ) {
- Com_WPrintf ( "Could not toggle (PCM_ENABLE_OUTPUT): %s\n",
- strerror ( errno ) );
- munmap ( dma.buffer, info.fragstotal * info.fragsize );
+ rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
+ if (rc < 0) {
+ Com_WPrintf("Could not toggle (PCM_ENABLE_OUTPUT): %s\n",
+ strerror(errno));
+ munmap(dma.buffer, info.fragstotal * info.fragsize);
goto fail;
}
- Com_Printf ( "OSS initialization succeeded\n" );
+ Com_Printf("OSS initialization succeeded\n");
dma.samplepos = 0;
@@ -208,39 +208,43 @@ static sndinitstat_t OSS_Init ( void ) {
return SIS_SUCCESS;
fail:
- close ( audio_fd );
+ close(audio_fd);
return SIS_FAILURE;
}
-static void OSS_Shutdown ( void ) {
- if ( snd_inited ) {
- Com_Printf ( "Shutting down OSS\n" );
- ioctl ( audio_fd, SNDCTL_DSP_RESET );
- munmap ( dma.buffer, info.fragstotal * info.fragsize );
- close ( audio_fd );
+static void OSS_Shutdown(void)
+{
+ if (snd_inited) {
+ Com_Printf("Shutting down OSS\n");
+ ioctl(audio_fd, SNDCTL_DSP_RESET);
+ munmap(dma.buffer, info.fragstotal * info.fragsize);
+ close(audio_fd);
snd_inited = qfalse;
}
}
-static void OSS_BeginPainting ( void ) {
+static void OSS_BeginPainting(void)
+{
struct count_info count;
- if ( !snd_inited )
+ if (!snd_inited)
return;
- if ( ioctl ( audio_fd, SNDCTL_DSP_GETOPTR, &count ) == -1 ) {
- Com_EPrintf ( "SNDCTL_DSP_GETOPTR failed on %s: %s\n",
- s_device->string, strerror ( errno ) );
+ if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
+ Com_EPrintf("SNDCTL_DSP_GETOPTR failed on %s: %s\n",
+ s_device->string, strerror(errno));
OSS_Shutdown();
return;
}
- dma.samplepos = count.ptr / ( dma.samplebits >> 3 );
+ dma.samplepos = count.ptr / (dma.samplebits >> 3);
}
-static void OSS_Submit ( void ) {
+static void OSS_Submit(void)
+{
}
-void DS_FillAPI ( snddmaAPI_t *api ) {
+void DS_FillAPI(snddmaAPI_t *api)
+{
api->Init = OSS_Init;
api->Shutdown = OSS_Shutdown;
api->BeginPainting = OSS_BeginPainting;
diff --git a/src/snd_public.h b/src/snd_public.h
index 2bf6910..27f0c98 100644
--- a/src/snd_public.h
+++ b/src/snd_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -18,24 +18,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-void S_Init (void);
-void S_Shutdown (void);
+void S_Init(void);
+void S_Shutdown(void);
// if origin is NULL, the sound will be dynamically sourced from the entity
-void S_StartSound (const vec3_t origin, int entnum, int entchannel, qhandle_t sfx, float fvol, float attenuation, float timeofs);
-void S_ParseStartSound( void );
-void S_StartLocalSound( const char *s );
-void S_StartLocalSound_( const char *s );
+void S_StartSound(const vec3_t origin, int entnum, int entchannel, qhandle_t sfx, float fvol, float attenuation, float timeofs);
+void S_ParseStartSound(void);
+void S_StartLocalSound(const char *s);
+void S_StartLocalSound_(const char *s);
-void S_FreeAllSounds( void );
+void S_FreeAllSounds(void);
void S_StopAllSounds(void);
-void S_Update (void);
+void S_Update(void);
-void S_Activate (void);
+void S_Activate(void);
-void S_BeginRegistration (void);
-qhandle_t S_RegisterSound (const char *sample);
-void S_EndRegistration (void);
+void S_BeginRegistration(void);
+qhandle_t S_RegisterSound(const char *sample);
+void S_EndRegistration(void);
extern vec3_t listener_origin;
extern vec3_t listener_forward;
diff --git a/src/snd_sdl.c b/src/snd_sdl.c
index 7122856..2e36e5e 100644
--- a/src/snd_sdl.c
+++ b/src/snd_sdl.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,55 +26,58 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "snd_local.h"
#include <SDL.h>
-static void Filler( void *userdata, Uint8 *stream, int len ) {
+static void Filler(void *userdata, Uint8 *stream, int len)
+{
int size = dma.samples << 1;
int pos = dma.samplepos << 1;
int wrapped = pos + len - size;
- if( wrapped < 0 ) {
- memcpy( stream, dma.buffer + pos, len );
+ if (wrapped < 0) {
+ memcpy(stream, dma.buffer + pos, len);
dma.samplepos += len >> 1;
} else {
int remaining = size - pos;
- memcpy( stream, dma.buffer + pos, remaining );
- memcpy( stream + remaining, dma.buffer, wrapped );
+ memcpy(stream, dma.buffer + pos, remaining);
+ memcpy(stream + remaining, dma.buffer, wrapped);
dma.samplepos = wrapped >> 1;
}
}
-static void Shutdown( void ) {
- Com_Printf( "Shutting down SDL audio.\n" );
+static void Shutdown(void)
+{
+ Com_Printf("Shutting down SDL audio.\n");
SDL_CloseAudio();
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_AUDIO ) {
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_AUDIO) {
SDL_Quit();
} else {
- SDL_QuitSubSystem( SDL_INIT_AUDIO );
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
- if( dma.buffer ) {
- Z_Free( dma.buffer );
+ if (dma.buffer) {
+ Z_Free(dma.buffer);
dma.buffer = NULL;
}
}
-static sndinitstat_t Init( void ) {
+static sndinitstat_t Init(void)
+{
SDL_AudioSpec desired, obtained;
char buffer[MAX_QPATH];
int ret;
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 ) {
- ret = SDL_Init( SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE );
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ ret = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
} else {
- ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
+ ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
}
- if( ret == -1 ) {
- Com_EPrintf( "Couldn't initialize SDL audio: %s\n", SDL_GetError() );
+ if (ret == -1) {
+ Com_EPrintf("Couldn't initialize SDL audio: %s\n", SDL_GetError());
return SIS_FAILURE;
}
- memset( &desired, 0, sizeof( desired ) );
- switch( s_khz->integer ) {
+ memset(&desired, 0, sizeof(desired));
+ switch (s_khz->integer) {
case 48:
desired.freq = 48000;
break;
@@ -93,14 +96,14 @@ static sndinitstat_t Init( void ) {
desired.samples = 512;
desired.channels = 2;
desired.callback = Filler;
- ret = SDL_OpenAudio( &desired, &obtained );
- if( ret == -1 ) {
- Com_EPrintf( "Couldn't open SDL audio: %s\n", SDL_GetError() );
+ ret = SDL_OpenAudio(&desired, &obtained);
+ if (ret == -1) {
+ Com_EPrintf("Couldn't open SDL audio: %s\n", SDL_GetError());
return SIS_FAILURE;
}
- if( obtained.format != AUDIO_S16LSB ) {
- Com_EPrintf( "SDL audio format %d unsupported.\n", obtained.format );
+ if (obtained.format != AUDIO_S16LSB) {
+ Com_EPrintf("SDL audio format %d unsupported.\n", obtained.format);
Shutdown();
return SIS_FAILURE;
}
@@ -110,34 +113,38 @@ static sndinitstat_t Init( void ) {
dma.samples = 2048 * obtained.channels;
dma.submission_chunk = 1;
dma.samplebits = 16;
- dma.buffer = Z_Mallocz( dma.samples * 2 );
+ dma.buffer = Z_Mallocz(dma.samples * 2);
dma.samplepos = 0;
- Com_Printf( "Using SDL audio driver: %s\n",
- SDL_AudioDriverName( buffer, sizeof( buffer ) ) );
+ Com_Printf("Using SDL audio driver: %s\n",
+ SDL_AudioDriverName(buffer, sizeof(buffer)));
- SDL_PauseAudio( 0 );
+ SDL_PauseAudio(0);
return SIS_SUCCESS;
}
-static void BeginPainting( void ) {
+static void BeginPainting(void)
+{
SDL_LockAudio();
}
-static void Submit( void ) {
+static void Submit(void)
+{
SDL_UnlockAudio();
}
-static void Activate( qboolean active ) {
- if( active ) {
- SDL_PauseAudio( 0 );
+static void Activate(qboolean active)
+{
+ if (active) {
+ SDL_PauseAudio(0);
} else {
- SDL_PauseAudio( 1 );
+ SDL_PauseAudio(1);
}
}
-void WAVE_FillAPI( snddmaAPI_t *api ) {
+void WAVE_FillAPI(snddmaAPI_t *api)
+{
api->Init = Init;
api->Shutdown = Shutdown;
api->BeginPainting = BeginPainting;
diff --git a/src/snd_wave.c b/src/snd_wave.c
index 713354f..d00d851 100644
--- a/src/snd_wave.c
+++ b/src/snd_wave.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// 64K is > 1 second at 16-bit, 22050 Hz
#define WAV_BUFFERS 64
-#define WAV_MASK ( WAV_BUFFERS - 1 )
+#define WAV_MASK (WAV_BUFFERS - 1)
#define WAV_BUFFER_SIZE 0x0400
static qboolean wav_init;
@@ -39,7 +39,7 @@ static HPSTR lpData;
static HGLOBAL hWaveHdr;
static LPWAVEHDR lpWaveHdr;
-static HWAVEOUT hWaveOut;
+static HWAVEOUT hWaveOut;
static DWORD gSndBufSize;
@@ -50,32 +50,33 @@ WAVE_Shutdown
Reset the sound device for exiting
===============
*/
-static void WAVE_Shutdown( void ) {
+static void WAVE_Shutdown(void)
+{
int i;
- Com_Printf( "Shutting down wave sound\n" );
+ Com_Printf("Shutting down wave sound\n");
- if( hWaveOut ) {
- Com_DPrintf( "...resetting waveOut\n" );
- waveOutReset (hWaveOut);
+ if (hWaveOut) {
+ Com_DPrintf("...resetting waveOut\n");
+ waveOutReset(hWaveOut);
if (lpWaveHdr) {
- Com_DPrintf( "...unpreparing headers\n" );
- for (i=0 ; i< WAV_BUFFERS ; i++)
- waveOutUnprepareHeader (hWaveOut, lpWaveHdr+i, sizeof(WAVEHDR));
+ Com_DPrintf("...unpreparing headers\n");
+ for (i = 0; i < WAV_BUFFERS; i++)
+ waveOutUnprepareHeader(hWaveOut, lpWaveHdr + i, sizeof(WAVEHDR));
}
- Com_DPrintf( "...closing waveOut\n" );
- waveOutClose (hWaveOut);
+ Com_DPrintf("...closing waveOut\n");
+ waveOutClose(hWaveOut);
if (hWaveHdr) {
- Com_DPrintf( "...freeing WAV header\n" );
+ Com_DPrintf("...freeing WAV header\n");
GlobalUnlock(hWaveHdr);
GlobalFree(hWaveHdr);
}
if (hData) {
- Com_DPrintf( "...freeing WAV buffer\n" );
+ Com_DPrintf("...freeing WAV buffer\n");
GlobalUnlock(hData);
GlobalFree(hData);
}
@@ -98,17 +99,18 @@ WAVE_Init
Crappy windows multimedia base
==================
*/
-static sndinitstat_t WAVE_Init (void) {
- WAVEFORMATEX format;
+static sndinitstat_t WAVE_Init(void)
+{
+ WAVEFORMATEX format;
int i;
HRESULT hr;
- Com_DPrintf( "Initializing wave sound\n" );
-
+ Com_DPrintf("Initializing wave sound\n");
+
snd_sent = 0;
snd_completed = 0;
- memset (&dma, 0, sizeof (dma));
+ memset(&dma, 0, sizeof(dma));
dma.channels = 2;
dma.samplebits = 16;
@@ -119,118 +121,109 @@ static sndinitstat_t WAVE_Init (void) {
else
dma.speed = 11025;
- memset (&format, 0, sizeof(format));
+ memset(&format, 0, sizeof(format));
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = dma.channels;
format.wBitsPerSample = dma.samplebits;
format.nSamplesPerSec = dma.speed;
- format.nBlockAlign = format.nChannels*format.wBitsPerSample / 8;
+ format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
format.cbSize = 0;
- format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign;
-
- /* Open a waveform device for output using window callback. */
- Com_DPrintf ("...opening waveform device: ");
- while ((hr = waveOutOpen((LPHWAVEOUT)&hWaveOut, WAVE_MAPPER,
- &format,
- 0, 0L, CALLBACK_NULL)) != MMSYSERR_NOERROR)
- {
- if (hr != MMSYSERR_ALLOCATED)
- {
- Com_DPrintf ("failed\n");
+ format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
+
+ /* Open a waveform device for output using window callback. */
+ Com_DPrintf("...opening waveform device: ");
+ while ((hr = waveOutOpen((LPHWAVEOUT)&hWaveOut, WAVE_MAPPER,
+ &format,
+ 0, 0L, CALLBACK_NULL)) != MMSYSERR_NOERROR) {
+ if (hr != MMSYSERR_ALLOCATED) {
+ Com_DPrintf("failed\n");
return SIS_FAILURE;
}
- if (MessageBox (NULL,
- _T("The sound hardware is in use by another app.\n\n")
- _T("Select Retry to try to start sound again or Cancel to run ") _T("q2pro") _T(" with no sound."),
- _T("Sound not available"),
- MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
- {
- Com_DPrintf ("hw in use\n" );
+ if (MessageBox(NULL,
+ _T("The sound hardware is in use by another app.\n\n")
+ _T("Select Retry to try to start sound again or Cancel to run ") _T("q2pro") _T(" with no sound."),
+ _T("Sound not available"),
+ MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY) {
+ Com_DPrintf("hw in use\n");
return SIS_NOTAVAIL;
}
- }
- Com_DPrintf( "ok\n" );
-
- /*
- * Allocate and lock memory for the waveform data. The memory
- * for waveform data must be globally allocated with
- * GMEM_MOVEABLE and GMEM_SHARE flags.
-
- */
- Com_DPrintf ("...allocating waveform buffer: ");
- gSndBufSize = WAV_BUFFERS*WAV_BUFFER_SIZE;
- hData = GlobalAlloc(GMEM_MOVEABLE /*| GMEM_SHARE*/, gSndBufSize);
- if (!hData)
- {
- Com_DPrintf( " failed with error %#lx\n", GetLastError() );
+ }
+ Com_DPrintf("ok\n");
+
+ /*
+ * Allocate and lock memory for the waveform data. The memory
+ * for waveform data must be globally allocated with
+ * GMEM_MOVEABLE and GMEM_SHARE flags.
+
+ */
+ Com_DPrintf("...allocating waveform buffer: ");
+ gSndBufSize = WAV_BUFFERS * WAV_BUFFER_SIZE;
+ hData = GlobalAlloc(GMEM_MOVEABLE /*| GMEM_SHARE*/, gSndBufSize);
+ if (!hData) {
+ Com_DPrintf(" failed with error %#lx\n", GetLastError());
WAVE_Shutdown();
return SIS_FAILURE;
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
- Com_DPrintf ("...locking waveform buffer: ");
+ Com_DPrintf("...locking waveform buffer: ");
lpData = GlobalLock(hData);
- if (!lpData)
- {
- Com_DPrintf( " failed with error %#lx\n", GetLastError() );
+ if (!lpData) {
+ Com_DPrintf(" failed with error %#lx\n", GetLastError());
WAVE_Shutdown();
return SIS_FAILURE;
- }
- memset (lpData, 0, gSndBufSize);
- Com_DPrintf( "ok\n" );
-
- /*
- * Allocate and lock memory for the header. This memory must
- * also be globally allocated with GMEM_MOVEABLE and
- * GMEM_SHARE flags.
- */
- Com_DPrintf ("...allocating waveform header: ");
- hWaveHdr = GlobalAlloc(GMEM_MOVEABLE /*| GMEM_SHARE*/,
- (DWORD) sizeof(WAVEHDR) * WAV_BUFFERS);
- if (hWaveHdr == NULL)
- {
- Com_DPrintf( "failed with error %#lx\n", GetLastError() );
+ }
+ memset(lpData, 0, gSndBufSize);
+ Com_DPrintf("ok\n");
+
+ /*
+ * Allocate and lock memory for the header. This memory must
+ * also be globally allocated with GMEM_MOVEABLE and
+ * GMEM_SHARE flags.
+ */
+ Com_DPrintf("...allocating waveform header: ");
+ hWaveHdr = GlobalAlloc(GMEM_MOVEABLE /*| GMEM_SHARE*/,
+ (DWORD) sizeof(WAVEHDR) * WAV_BUFFERS);
+ if (hWaveHdr == NULL) {
+ Com_DPrintf("failed with error %#lx\n", GetLastError());
WAVE_Shutdown();
return SIS_FAILURE;
- }
- Com_DPrintf( "ok\n" );
-
- Com_DPrintf ("...locking waveform header: ");
- lpWaveHdr = (LPWAVEHDR) GlobalLock(hWaveHdr);
- if (lpWaveHdr == NULL)
- {
- Com_DPrintf( "failed with error %#lx\n", GetLastError() );
+ }
+ Com_DPrintf("ok\n");
+
+ Com_DPrintf("...locking waveform header: ");
+ lpWaveHdr = (LPWAVEHDR) GlobalLock(hWaveHdr);
+ if (lpWaveHdr == NULL) {
+ Com_DPrintf("failed with error %#lx\n", GetLastError());
WAVE_Shutdown();
return SIS_FAILURE;
}
- memset (lpWaveHdr, 0, sizeof(WAVEHDR) * WAV_BUFFERS);
- Com_DPrintf( "ok\n" );
-
- /* After allocation, set up and prepare headers. */
- Com_DPrintf ("...preparing headers: ");
- for (i=0 ; i<WAV_BUFFERS ; i++)
- {
- lpWaveHdr[i].dwBufferLength = WAV_BUFFER_SIZE;
- lpWaveHdr[i].lpData = lpData + i*WAV_BUFFER_SIZE;
-
- if (waveOutPrepareHeader(hWaveOut, lpWaveHdr+i, sizeof(WAVEHDR)) !=
- MMSYSERR_NOERROR)
- {
- Com_DPrintf ("failed\n");
+ memset(lpWaveHdr, 0, sizeof(WAVEHDR) * WAV_BUFFERS);
+ Com_DPrintf("ok\n");
+
+ /* After allocation, set up and prepare headers. */
+ Com_DPrintf("...preparing headers: ");
+ for (i = 0; i < WAV_BUFFERS; i++) {
+ lpWaveHdr[i].dwBufferLength = WAV_BUFFER_SIZE;
+ lpWaveHdr[i].lpData = lpData + i * WAV_BUFFER_SIZE;
+
+ if (waveOutPrepareHeader(hWaveOut, lpWaveHdr + i, sizeof(WAVEHDR)) !=
+ MMSYSERR_NOERROR) {
+ Com_DPrintf("failed\n");
WAVE_Shutdown();
return SIS_FAILURE;
}
}
- Com_DPrintf ("ok\n");
+ Com_DPrintf("ok\n");
- dma.samples = gSndBufSize/(dma.samplebits/8);
+ dma.samples = gSndBufSize / (dma.samplebits / 8);
dma.samplepos = 0;
dma.submission_chunk = 512;
dma.buffer = (byte *) lpData;
- sample16 = (dma.samplebits/8) - 1;
+ sample16 = (dma.samplebits / 8) - 1;
- Com_Printf( "Wave sound initialized\n" );
+ Com_Printf("Wave sound initialized\n");
wav_init = qtrue;
return SIS_SUCCESS;
@@ -247,15 +240,16 @@ inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
-static void WAVE_BeginPainting (void) {
+static void WAVE_BeginPainting(void)
+{
int s;
- if( !wav_init ) {
+ if (!wav_init) {
return;
}
- s = ( snd_sent * WAV_BUFFER_SIZE ) >> sample16;
- dma.samplepos = s & ( dma.samples - 1 );
+ s = (snd_sent * WAV_BUFFER_SIZE) >> sample16;
+ dma.samplepos = s & (dma.samples - 1);
}
/*
@@ -266,7 +260,8 @@ Send sound to device if buffer isn't really the dma buffer
Also unlocks the dsound buffer
===============
*/
-static void WAVE_Submit(void) {
+static void WAVE_Submit(void)
+{
LPWAVEHDR h;
int wResult;
@@ -280,12 +275,12 @@ static void WAVE_Submit(void) {
// find which sound blocks have completed
//
while (1) {
- if ( snd_completed == snd_sent ) {
- Com_DPrintf ("WAVE_Submit: Sound overrun\n");
+ if (snd_completed == snd_sent) {
+ Com_DPrintf("WAVE_Submit: Sound overrun\n");
break;
}
- if ( !(lpWaveHdr[snd_completed & WAV_MASK].dwFlags & WHDR_DONE) ) {
+ if (!(lpWaveHdr[snd_completed & WAV_MASK].dwFlags & WHDR_DONE)) {
break;
}
@@ -296,22 +291,22 @@ static void WAVE_Submit(void) {
// submit a few new sound blocks
//
while (((snd_sent - snd_completed) >> sample16) < 8) {
- h = lpWaveHdr + ( snd_sent & WAV_MASK );
- if (paintedtime/256 <= snd_sent)
+ h = lpWaveHdr + (snd_sent & WAV_MASK);
+ if (paintedtime / 256 <= snd_sent)
break;
snd_sent++;
- /*
- * Now the data block can be sent to the output device. The
- * waveOutWrite function returns immediately and waveform
- * data is sent to the output device in the background.
- */
- wResult = waveOutWrite(hWaveOut, h, sizeof(WAVEHDR));
-
- if (wResult != MMSYSERR_NOERROR) {
- Com_EPrintf ("WAVE_Submit: Failed to write block to device\n");
- WAVE_Shutdown ();
- return;
- }
+ /*
+ * Now the data block can be sent to the output device. The
+ * waveOutWrite function returns immediately and waveform
+ * data is sent to the output device in the background.
+ */
+ wResult = waveOutWrite(hWaveOut, h, sizeof(WAVEHDR));
+
+ if (wResult != MMSYSERR_NOERROR) {
+ Com_EPrintf("WAVE_Submit: Failed to write block to device\n");
+ WAVE_Shutdown();
+ return;
+ }
}
}
@@ -325,10 +320,12 @@ The window have been destroyed and recreated
between a deactivate and an activate.
===========
*/
-static void WAVE_Activate (qboolean active) {
+static void WAVE_Activate(qboolean active)
+{
}
-void WAVE_FillAPI( snddmaAPI_t *api ) {
+void WAVE_FillAPI(snddmaAPI_t *api)
+{
api->Init = WAVE_Init;
api->Shutdown = WAVE_Shutdown;
api->BeginPainting = WAVE_BeginPainting;
diff --git a/src/sv_ac.c b/src/sv_ac.c
index 011d544..aa22724 100644
--- a/src/sv_ac.c
+++ b/src/sv_ac.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -113,10 +113,10 @@ typedef struct {
char hashlist_name[MAX_QPATH];
} ac_static_t;
-#define ACP_BLOCKPLAY ( 1 << 0 )
+#define ACP_BLOCKPLAY (1 << 0)
-#define ACH_REQUIRED ( 1 << 0 )
-#define ACH_NEGATIVE ( 1 << 1 )
+#define ACH_REQUIRED (1 << 0)
+#define ACH_NEGATIVE (1 << 1)
#define AC_PROTOCOL_VERSION 0xAC03
@@ -133,8 +133,8 @@ typedef struct {
static ac_locals_t ac;
static ac_static_t acs;
-static LIST_DECL( ac_required_list );
-static LIST_DECL( ac_exempt_list );
+static LIST_DECL(ac_required_list);
+static LIST_DECL(ac_exempt_list);
static byte ac_send_buffer[AC_SEND_SIZE];
static byte ac_recv_buffer[AC_RECV_SIZE];
@@ -159,7 +159,7 @@ static const char ac_clients[][8] = {
"Q2PRO"
};
-static const int ac_num_clients = sizeof( ac_clients ) / sizeof( ac_clients[0] );
+static const int ac_num_clients = sizeof(ac_clients) / sizeof(ac_clients[0]);
/*
@@ -176,7 +176,7 @@ FILE PARSING
#define AC_MAX_INCLUDES 16
-typedef void (*ac_parse_t)( char *, int, const char * );
+typedef void (*ac_parse_t)(char *, int, const char *);
typedef struct {
char str[4];
@@ -198,33 +198,35 @@ static const ac_cvarop_t ac_cvarops[] = {
{ "" }
};
-static char *AC_SimpleParse( char **data_p, size_t *len_p ) {
+static char *AC_SimpleParse(char **data_p, size_t *len_p)
+{
char *data, *p;
data = *data_p;
- if( !data ) {
- if( len_p ) {
+ if (!data) {
+ if (len_p) {
*len_p = 0;
}
return NULL;
}
- p = Q_strchrnul( data, '\t' );
- if( *p ) {
+ p = Q_strchrnul(data, '\t');
+ if (*p) {
*p = 0;
*data_p = p + 1;
} else {
*data_p = NULL;
}
- if( len_p ) {
+ if (len_p) {
*len_p = p - data;
}
return data;
}
-static void AC_ParseHash( char *data, int linenum, const char *path ) {
+static void AC_ParseHash(char *data, int linenum, const char *path)
+{
char *pstr, *hstr;
size_t pathlen, hashlen;
int flags;
@@ -232,63 +234,64 @@ static void AC_ParseHash( char *data, int linenum, const char *path ) {
ac_file_t *file;
int i;
- if( *data == '!' ) {
- Q_strlcpy( acs.hashlist_name, data + 1, sizeof( acs.hashlist_name ) );
+ if (*data == '!') {
+ Q_strlcpy(acs.hashlist_name, data + 1, sizeof(acs.hashlist_name));
return;
}
- pstr = AC_SimpleParse( &data, &pathlen );
- if( !data ) {
- Com_WPrintf( "ANTICHEAT: Incomplete line %d in %s\n", linenum, path );
+ pstr = AC_SimpleParse(&data, &pathlen);
+ if (!data) {
+ Com_WPrintf("ANTICHEAT: Incomplete line %d in %s\n", linenum, path);
return;
}
- hstr = AC_SimpleParse( &data, &hashlen );
+ hstr = AC_SimpleParse(&data, &hashlen);
- if( pathlen < 1 || pathlen >= MAX_QPATH ) {
- Com_WPrintf( "ANTICHEAT: Invalid quake path length on line %d in %s\n", linenum, path );
+ if (pathlen < 1 || pathlen >= MAX_QPATH) {
+ Com_WPrintf("ANTICHEAT: Invalid quake path length on line %d in %s\n", linenum, path);
return;
}
- if( strchr( pstr, '\\' ) || !Q_isalnum( pstr[0] ) ) {
- Com_WPrintf( "ANTICHEAT: Malformed quake path on line %d in %s\n", linenum, path );
+ if (strchr(pstr, '\\') || !Q_isalnum(pstr[0])) {
+ Com_WPrintf("ANTICHEAT: Malformed quake path on line %d in %s\n", linenum, path);
return;
}
- if( hashlen != 40 ) {
+ if (hashlen != 40) {
badhash:
- Com_WPrintf( "ANTICHEAT: Malformed hash on line %d in %s\n", linenum, path );
+ Com_WPrintf("ANTICHEAT: Malformed hash on line %d in %s\n", linenum, path);
return;
}
- for( i = 0; i < 20; i++, hstr += 2 ) {
- int c1 = Q_charhex( hstr[0] );
- int c2 = Q_charhex( hstr[1] );
- if( c1 == -1 || c2 == -1 ) {
+ for (i = 0; i < 20; i++, hstr += 2) {
+ int c1 = Q_charhex(hstr[0]);
+ int c2 = Q_charhex(hstr[1]);
+ if (c1 == -1 || c2 == -1) {
goto badhash;
}
- hash[i] = ( c1 << 4 ) | c2;
+ hash[i] = (c1 << 4) | c2;
}
-
+
// parse optional flags
flags = 0;
- if( data ) {
- if( strstr( data, "required" ) ) {
+ if (data) {
+ if (strstr(data, "required")) {
flags |= ACH_REQUIRED;
}
- if( strstr( data, "negative" ) ) {
+ if (strstr(data, "negative")) {
flags |= ACH_NEGATIVE;
}
}
- file = SV_Malloc( sizeof( *file ) + pathlen );
- memcpy( file->hash, hash, sizeof( file->hash ) );
- memcpy( file->path, pstr, pathlen + 1 );
+ file = SV_Malloc(sizeof(*file) + pathlen);
+ memcpy(file->hash, hash, sizeof(file->hash));
+ memcpy(file->path, pstr, pathlen + 1);
file->flags = flags;
file->next = acs.files;
acs.files = file;
acs.num_files++;
}
-static void AC_ParseCvar( char *data, int linenum, const char *path ) {
+static void AC_ParseCvar(char *data, int linenum, const char *path)
+{
char *values[256], *p;
byte lengths[256];
char *name, *opstr, *val, *def;
@@ -297,81 +300,81 @@ static void AC_ParseCvar( char *data, int linenum, const char *path ) {
const ac_cvarop_t *op;
int i, num_values;
- name = AC_SimpleParse( &data, &namelen );
- if( !data ) {
- Com_WPrintf( "ANTICHEAT: Incomplete line %d in %s\n", linenum, path );
+ name = AC_SimpleParse(&data, &namelen);
+ if (!data) {
+ Com_WPrintf("ANTICHEAT: Incomplete line %d in %s\n", linenum, path);
return;
}
- opstr = AC_SimpleParse( &data, NULL );
- if( !data ) {
- Com_WPrintf( "ANTICHEAT: Incomplete line %d in %s\n", linenum, path );
+ opstr = AC_SimpleParse(&data, NULL);
+ if (!data) {
+ Com_WPrintf("ANTICHEAT: Incomplete line %d in %s\n", linenum, path);
return;
}
- val = AC_SimpleParse( &data, &vallen );
- if( !data ) {
- Com_WPrintf( "ANTICHEAT: Incomplete line %d in %s\n", linenum, path );
+ val = AC_SimpleParse(&data, &vallen);
+ if (!data) {
+ Com_WPrintf("ANTICHEAT: Incomplete line %d in %s\n", linenum, path);
return;
}
- def = AC_SimpleParse( &data, &deflen );
+ def = AC_SimpleParse(&data, &deflen);
- if( namelen < 1 || namelen >= 64 ) {
- Com_WPrintf( "ANTICHEAT: Invalid cvar name length on line %d in %s\n", linenum, path );
+ if (namelen < 1 || namelen >= 64) {
+ Com_WPrintf("ANTICHEAT: Invalid cvar name length on line %d in %s\n", linenum, path);
return;
}
- if( deflen < 1 || deflen >= 64 ) {
- Com_WPrintf( "ANTICHEAT: Invalid default value length on line %d in %s\n", linenum, path );
+ if (deflen < 1 || deflen >= 64) {
+ Com_WPrintf("ANTICHEAT: Invalid default value length on line %d in %s\n", linenum, path);
return;
}
- for( op = ac_cvarops; op->str[0]; op++ ) {
- if( !strcmp( opstr, op->str ) ) {
+ for (op = ac_cvarops; op->str[0]; op++) {
+ if (!strcmp(opstr, op->str)) {
break;
}
}
- if( !op->str[0] ) {
- Com_WPrintf( "ANTICHEAT: Unknown opcode '%s' on line %d in %s\n", opstr, linenum, path );
+ if (!op->str[0]) {
+ Com_WPrintf("ANTICHEAT: Unknown opcode '%s' on line %d in %s\n", opstr, linenum, path);
return;
}
num_values = 0;
- while( 1 ) {
- if( num_values == op->max_values ) {
- Com_WPrintf( "ANTICHEAT: Too many values for opcode '%s' on line %d in %s\n", opstr, linenum, path );
+ while (1) {
+ if (num_values == op->max_values) {
+ Com_WPrintf("ANTICHEAT: Too many values for opcode '%s' on line %d in %s\n", opstr, linenum, path);
return;
}
- if( !val[0] ) {
- Com_WPrintf( "ANTICHEAT: Empty value on line %d in %s\n", linenum, path );
+ if (!val[0]) {
+ Com_WPrintf("ANTICHEAT: Empty value on line %d in %s\n", linenum, path);
return;
}
- p = strchr( val, ',' );
- if( p ) {
+ p = strchr(val, ',');
+ if (p) {
*p = 0;
}
- len = strlen( val );
- if( len >= 64 ) {
- Com_WPrintf( "ANTICHEAT: Too long value on line %d in %s\n", linenum, path );
+ len = strlen(val);
+ if (len >= 64) {
+ Com_WPrintf("ANTICHEAT: Too long value on line %d in %s\n", linenum, path);
return;
}
values[num_values] = val;
- lengths[num_values++] = ( byte )( len + 1 );
- if( !p ) {
+ lengths[num_values++] = (byte)(len + 1);
+ if (!p) {
break;
}
val = p + 1;
}
- Z_TagReserve( sizeof( *cvar ) + num_values * sizeof( char * ) +
- namelen + 1 + deflen + 1 + vallen + 1, TAG_SERVER );
- cvar = Z_ReservedAlloc( sizeof( *cvar ) );
- cvar->values = Z_ReservedAlloc( num_values * sizeof( char * ) );
- cvar->name = Z_ReservedAlloc( namelen + 1 );
- memcpy( cvar->name, name, namelen + 1 );
- cvar->def = Z_ReservedAlloc( deflen + 1 );
- memcpy( cvar->def, def, deflen + 1 );
+ Z_TagReserve(sizeof(*cvar) + num_values * sizeof(char *) +
+ namelen + 1 + deflen + 1 + vallen + 1, TAG_SERVER);
+ cvar = Z_ReservedAlloc(sizeof(*cvar));
+ cvar->values = Z_ReservedAlloc(num_values * sizeof(char *));
+ cvar->name = Z_ReservedAlloc(namelen + 1);
+ memcpy(cvar->name, name, namelen + 1);
+ cvar->def = Z_ReservedAlloc(deflen + 1);
+ memcpy(cvar->def, def, deflen + 1);
cvar->num_values = num_values;
- for( i = 0; i < num_values; i++ ) {
- cvar->values[i] = Z_ReservedAlloc( lengths[i] );
- memcpy( cvar->values[i], values[i], lengths[i] );
+ for (i = 0; i < num_values; i++) {
+ cvar->values[i] = Z_ReservedAlloc(lengths[i]);
+ memcpy(cvar->values[i], values[i], lengths[i]);
}
cvar->op = op->code;
cvar->next = acs.cvars;
@@ -379,62 +382,64 @@ static void AC_ParseCvar( char *data, int linenum, const char *path ) {
acs.num_cvars++;
}
-static void AC_ParseToken( char *data, int linenum, const char *path ) {
+static void AC_ParseToken(char *data, int linenum, const char *path)
+{
string_entry_t *tok;
- size_t len = strlen( data );
+ size_t len = strlen(data);
- tok = SV_Malloc( sizeof( *tok ) + len );
- memcpy( tok->string, data, len + 1 );
+ tok = SV_Malloc(sizeof(*tok) + len);
+ memcpy(tok->string, data, len + 1);
tok->next = acs.tokens;
acs.tokens = tok;
}
-static qboolean AC_ParseFile( const char *path, ac_parse_t parse, int depth ) {
+static qboolean AC_ParseFile(const char *path, ac_parse_t parse, int depth)
+{
char *raw, *data, *p;
int linenum = 1;
qerror_t ret;
- ret = FS_LoadFile( path, ( void ** )&raw );
- if( !raw ) {
- if( ret != Q_ERR_NOENT || depth ) {
- Com_WPrintf( "ANTICHEAT: Could not %s %s: %s\n",
- depth ? "include" : "load", path, Q_ErrorString( ret ) );
+ ret = FS_LoadFile(path, (void **)&raw);
+ if (!raw) {
+ if (ret != Q_ERR_NOENT || depth) {
+ Com_WPrintf("ANTICHEAT: Could not %s %s: %s\n",
+ depth ? "include" : "load", path, Q_ErrorString(ret));
}
return qfalse;
}
data = raw;
- while( *data ) {
- p = strchr( data, '\n' );
- if( p ) {
- if( p > data && *( p - 1 ) == '\r' ) {
- *( p - 1 ) = 0;
+ while (*data) {
+ p = strchr(data, '\n');
+ if (p) {
+ if (p > data && *(p - 1) == '\r') {
+ *(p - 1) = 0;
}
*p = 0;
}
- switch( *data ) {
+ switch (*data) {
case '/':
case '#':
case 0:
break;
case '\\':
- if( !strncmp( data + 1, "include ", 8 ) ) {
- if( depth == AC_MAX_INCLUDES ) {
- Com_WPrintf( "ANTICHEAT: Includes too deeply nested.\n" );
+ if (!strncmp(data + 1, "include ", 8)) {
+ if (depth == AC_MAX_INCLUDES) {
+ Com_WPrintf("ANTICHEAT: Includes too deeply nested.\n");
} else {
- AC_ParseFile( data + 9, parse, depth + 1 );
+ AC_ParseFile(data + 9, parse, depth + 1);
}
} else {
- Com_WPrintf( "ANTICHEAT: Unknown directive %s on line %d in %s\n", data + 1, linenum, path );
+ Com_WPrintf("ANTICHEAT: Unknown directive %s on line %d in %s\n", data + 1, linenum, path);
}
break;
default:
- parse( data, linenum, path );
+ parse(data, linenum, path);
break;
}
- if( !p ) {
+ if (!p) {
break;
}
@@ -442,56 +447,58 @@ static qboolean AC_ParseFile( const char *path, ac_parse_t parse, int depth ) {
data = p + 1;
}
- FS_FreeFile( raw );
+ FS_FreeFile(raw);
return qtrue;
}
-static void AC_LoadChecks( void ) {
- if( !AC_ParseFile( AC_HASHES_NAME, AC_ParseHash, 0 ) ) {
- Com_Printf( "ANTICHEAT: Missing " AC_HASHES_NAME ", "
- "not using any file checks.\n" );
- strcpy( acs.hashlist_name, "none" );
- } else if( !acs.num_files ) {
- Com_Printf( "ANTICHEAT: No file hashes were loaded, "
- "please check the " AC_HASHES_NAME ".\n" );
- strcpy( acs.hashlist_name, "none" );
- } else if( !acs.hashlist_name[0] ) {
- Q_snprintf( acs.hashlist_name, MAX_QPATH, "unknown (%d %s)",
- acs.num_files, acs.num_files == 1 ? "entry" : "entries" );
- }
-
- if( !AC_ParseFile( AC_CVARS_NAME, AC_ParseCvar, 0 ) ) {
- Com_Printf( "ANTICHEAT: Missing " AC_CVARS_NAME ", "
- "not using any cvar checks.\n" );
- } else if( !acs.num_cvars ) {
- Com_Printf( "ANTICHEAT: No cvar checks were loaded, "
- "please check the " AC_CVARS_NAME ".\n" );
- }
-
- AC_ParseFile( "anticheat-tokens.txt", AC_ParseToken, 0 );
+static void AC_LoadChecks(void)
+{
+ if (!AC_ParseFile(AC_HASHES_NAME, AC_ParseHash, 0)) {
+ Com_Printf("ANTICHEAT: Missing " AC_HASHES_NAME ", "
+ "not using any file checks.\n");
+ strcpy(acs.hashlist_name, "none");
+ } else if (!acs.num_files) {
+ Com_Printf("ANTICHEAT: No file hashes were loaded, "
+ "please check the " AC_HASHES_NAME ".\n");
+ strcpy(acs.hashlist_name, "none");
+ } else if (!acs.hashlist_name[0]) {
+ Q_snprintf(acs.hashlist_name, MAX_QPATH, "unknown (%d %s)",
+ acs.num_files, acs.num_files == 1 ? "entry" : "entries");
+ }
+
+ if (!AC_ParseFile(AC_CVARS_NAME, AC_ParseCvar, 0)) {
+ Com_Printf("ANTICHEAT: Missing " AC_CVARS_NAME ", "
+ "not using any cvar checks.\n");
+ } else if (!acs.num_cvars) {
+ Com_Printf("ANTICHEAT: No cvar checks were loaded, "
+ "please check the " AC_CVARS_NAME ".\n");
+ }
+
+ AC_ParseFile("anticheat-tokens.txt", AC_ParseToken, 0);
}
-static void AC_FreeChecks( void ) {
+static void AC_FreeChecks(void)
+{
ac_file_t *f, *fn;
ac_cvar_t *c, *cn;
string_entry_t *t, *tn;
- for( f = acs.files; f; f = fn ) {
+ for (f = acs.files; f; f = fn) {
fn = f->next;
- Z_Free( f );
+ Z_Free(f);
}
acs.files = NULL;
- for( c = acs.cvars; c; c = cn ) {
+ for (c = acs.cvars; c; c = cn) {
cn = c->next;
- Z_Free( c );
+ Z_Free(c);
}
acs.cvars = NULL;
- for( t = acs.tokens; t; t = tn ) {
+ for (t = acs.tokens; t; t = tn) {
tn = t->next;
- Z_Free( t );
+ Z_Free(t);
}
acs.tokens = NULL;
@@ -508,108 +515,113 @@ REPLY PARSING
==============================================================================
*/
-static void AC_Retry( void ) {
+static void AC_Retry(void)
+{
char buf[MAX_QPATH];
time_t clock;
- Com_FormatTimeLong( buf, sizeof( buf ), acs.retry_backoff );
- Com_Printf( "ANTICHEAT: Re%s in %s.\n",
- ac.connected ? "connecting" : "trying", buf );
- clock = time( NULL );
+ Com_FormatTimeLong(buf, sizeof(buf), acs.retry_backoff);
+ Com_Printf("ANTICHEAT: Re%s in %s.\n",
+ ac.connected ? "connecting" : "trying", buf);
+ clock = time(NULL);
acs.retry_time = clock + acs.retry_backoff;
}
-static void AC_Drop( void ) {
+static void AC_Drop(void)
+{
client_t *cl;
- NET_Close( &ac.stream );
+ NET_Close(&ac.stream);
- if( !ac.connected ) {
- Com_Printf( "ANTICHEAT: Server connection failed.\n" );
+ if (!ac.connected) {
+ Com_Printf("ANTICHEAT: Server connection failed.\n");
AC_Retry();
acs.retry_backoff += 5;
return;
}
- FOR_EACH_CLIENT( cl ) {
+ FOR_EACH_CLIENT(cl) {
cl->ac_valid = qfalse;
cl->ac_file_failures = 0;
}
// inform
- if( ac.ready ) {
- SV_BroadcastPrintf( PRINT_HIGH, AC_MESSAGE
- "This server has lost the connection to the anticheat server. "
- "Any anticheat clients are no longer valid.\n" );
-
- if( ac_required->integer == 2 ) {
- SV_BroadcastPrintf( PRINT_HIGH, AC_MESSAGE
- "You will need to reconnect once the server has "
- "re-established the anticheat connection.\n" );
+ if (ac.ready) {
+ SV_BroadcastPrintf(PRINT_HIGH, AC_MESSAGE
+ "This server has lost the connection to the anticheat server. "
+ "Any anticheat clients are no longer valid.\n");
+
+ if (ac_required->integer == 2) {
+ SV_BroadcastPrintf(PRINT_HIGH, AC_MESSAGE
+ "You will need to reconnect once the server has "
+ "re-established the anticheat connection.\n");
}
acs.retry_backoff = AC_DEFAULT_BACKOFF;
} else {
acs.retry_backoff += 30; // this generally indicates a server problem
}
- Com_WPrintf( "ANTICHEAT: Lost connection to anticheat server!\n" );
+ Com_WPrintf("ANTICHEAT: Lost connection to anticheat server!\n");
AC_Retry();
- memset( &ac, 0, sizeof( ac ) );
+ memset(&ac, 0, sizeof(ac));
}
-static void AC_Disable( void ) {
+static void AC_Disable(void)
+{
AC_Disconnect();
- Cvar_SetByVar( ac_required, "0", FROM_CODE );
+ Cvar_SetByVar(ac_required, "0", FROM_CODE);
}
-static void AC_Announce( client_t *client, const char *fmt, ... ) {
+static void AC_Announce(client_t *client, const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
size_t len;
-
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
+
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteData( AC_MESSAGE, sizeof( AC_MESSAGE ) - 1 );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteData(AC_MESSAGE, sizeof(AC_MESSAGE) - 1);
+ MSG_WriteData(string, len + 1);
- if( client->state == cs_spawned ) {
- FOR_EACH_CLIENT( client ) {
- if( client->state == cs_spawned ) {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ if (client->state == cs_spawned) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state == cs_spawned) {
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
}
} else {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-static client_t *AC_ParseClient( void ) {
+static client_t *AC_ParseClient(void)
+{
client_t *cl;
unsigned clientID;
unsigned challenge;
- if( msg_read.readcount + 6 > msg_read.cursize ) {
- Com_DPrintf( "ANTICHEAT: Message too short in %s\n", __func__ );
+ if (msg_read.readcount + 6 > msg_read.cursize) {
+ Com_DPrintf("ANTICHEAT: Message too short in %s\n", __func__);
return NULL;
}
clientID = MSG_ReadWord();
challenge = MSG_ReadLong();
- if( clientID >= sv_maxclients->integer ) {
- Com_WPrintf( "ANTICHEAT: Illegal client ID: %u\n", clientID );
+ if (clientID >= sv_maxclients->integer) {
+ Com_WPrintf("ANTICHEAT: Illegal client ID: %u\n", clientID);
return NULL;
}
@@ -617,114 +629,117 @@ static client_t *AC_ParseClient( void ) {
// we check challenge to ensure we don't get
// a race condition if a client reconnects.
- if( cl->challenge != challenge ) {
+ if (cl->challenge != challenge) {
return NULL;
}
- if( cl->state < cs_assigned ) {
+ if (cl->state < cs_assigned) {
return NULL;
}
return cl;
}
-static void AC_ParseViolation( void ) {
+static void AC_ParseViolation(void)
+{
client_t *cl;
char reason[32];
char clientreason[64];
cl = AC_ParseClient();
- if( !cl ) {
+ if (!cl) {
return;
}
- if( msg_read.readcount + 1 > msg_read.cursize ) {
- Com_DPrintf( "ANTICHEAT: Message too short in %s\n", __func__ );
+ if (msg_read.readcount + 1 > msg_read.cursize) {
+ Com_DPrintf("ANTICHEAT: Message too short in %s\n", __func__);
return;
}
- MSG_ReadString( reason, sizeof( reason ) );
+ MSG_ReadString(reason, sizeof(reason));
- if( msg_read.readcount < msg_read.cursize ) {
- MSG_ReadString( clientreason, sizeof( clientreason ) );
+ if (msg_read.readcount < msg_read.cursize) {
+ MSG_ReadString(clientreason, sizeof(clientreason));
} else {
clientreason[0] = 0;
}
- // FIXME: should we notify other players about anticheat violations
- // found before clientbegin? one side says yes to expose cheaters,
- // other side says no since client will have no previous message to
- // show that they're trying to join. currently showing messages only
+ // FIXME: should we notify other players about anticheat violations
+ // found before clientbegin? one side says yes to expose cheaters,
+ // other side says no since client will have no previous message to
+ // show that they're trying to join. currently showing messages only
// for spawned clients.
// fixme maybe
- if( strcmp( reason, "disconnected" ) ) {
+ if (strcmp(reason, "disconnected")) {
char showreason[32];
- if( ac_show_violation_reason->integer )
- Q_snprintf( showreason, sizeof( showreason ), " (%s)", reason );
+ if (ac_show_violation_reason->integer)
+ Q_snprintf(showreason, sizeof(showreason), " (%s)", reason);
else
showreason[0] = 0;
- AC_Announce( cl, "%s was kicked for anticheat violation%s\n",
- cl->name, showreason );
+ AC_Announce(cl, "%s was kicked for anticheat violation%s\n",
+ cl->name, showreason);
- Com_Printf( "ANTICHEAT VIOLATION: %s[%s] was kicked: %s\n",
- cl->name, NET_AdrToString( &cl->netchan->remote_address ), reason );
+ Com_Printf("ANTICHEAT VIOLATION: %s[%s] was kicked: %s\n",
+ cl->name, NET_AdrToString(&cl->netchan->remote_address), reason);
- if( clientreason[0] )
- SV_ClientPrintf( cl, PRINT_HIGH, "%s\n", clientreason );
+ if (clientreason[0])
+ SV_ClientPrintf(cl, PRINT_HIGH, "%s\n", clientreason);
// hack to fix late zombies race condition
cl->lastmessage = svs.realtime;
- SV_DropClient( cl, NULL );
+ SV_DropClient(cl, NULL);
return;
}
- if( !cl->ac_valid ) {
+ if (!cl->ac_valid) {
return;
}
- Com_Printf( "ANTICHEAT DISCONNECT: %s[%s] disconnected from "
- "anticheat server\n", cl->name,
- NET_AdrToString( &cl->netchan->remote_address ) );
+ Com_Printf("ANTICHEAT DISCONNECT: %s[%s] disconnected from "
+ "anticheat server\n", cl->name,
+ NET_AdrToString(&cl->netchan->remote_address));
- if( ac_client_disconnect_action->integer == 1 ) {
- AC_Announce( cl, "%s lost connection to anticheat server.\n", cl->name );
- SV_DropClient( cl, NULL );
+ if (ac_client_disconnect_action->integer == 1) {
+ AC_Announce(cl, "%s lost connection to anticheat server.\n", cl->name);
+ SV_DropClient(cl, NULL);
return;
}
- AC_Announce( cl, "%s lost connection to anticheat server, "
- "client is no longer valid.\n", cl->name );
+ AC_Announce(cl, "%s lost connection to anticheat server, "
+ "client is no longer valid.\n", cl->name);
cl->ac_valid = qfalse;
}
-static void AC_ParseClientAck( void ) {
+static void AC_ParseClientAck(void)
+{
client_t *cl;
cl = AC_ParseClient();
- if( !cl ) {
+ if (!cl) {
return;
}
- if( msg_read.readcount + 1 > msg_read.cursize ) {
- Com_DPrintf( "ANTICHEAT: Message too short in %s\n", __func__ );
+ if (msg_read.readcount + 1 > msg_read.cursize) {
+ Com_DPrintf("ANTICHEAT: Message too short in %s\n", __func__);
return;
}
- if( cl->state > cs_primed ) {
- Com_DPrintf( "ANTICHEAT: %s with client in state %d\n",
- __func__, cl->state );
+ if (cl->state > cs_primed) {
+ Com_DPrintf("ANTICHEAT: %s with client in state %d\n",
+ __func__, cl->state);
return;
}
- Com_DPrintf( "ANTICHEAT: %s for %s\n", __func__, cl->name );
+ Com_DPrintf("ANTICHEAT: %s for %s\n", __func__, cl->name);
cl->ac_client_type = MSG_ReadByte();
cl->ac_valid = qtrue;
}
-static void AC_ParseFileViolation( void ) {
+static void AC_ParseFileViolation(void)
+{
string_entry_t *bad;
client_t *cl;
char path[MAX_QPATH];
@@ -734,98 +749,100 @@ static void AC_ParseFileViolation( void ) {
ac_file_t *f;
cl = AC_ParseClient();
- if( !cl ) {
+ if (!cl) {
return;
}
- if( msg_read.readcount + 1 > msg_read.cursize ) {
- Com_DPrintf( "ANTICHEAT: Message too short in %s\n", __func__ );
+ if (msg_read.readcount + 1 > msg_read.cursize) {
+ Com_DPrintf("ANTICHEAT: Message too short in %s\n", __func__);
return;
}
- pathlen = MSG_ReadString( path, sizeof( path ) );
- if( pathlen >= sizeof( path ) ) {
- Com_WPrintf( "ANTICHEAT: Oversize path in %s\n", __func__ );
- pathlen = sizeof( path ) - 1;
+ pathlen = MSG_ReadString(path, sizeof(path));
+ if (pathlen >= sizeof(path)) {
+ Com_WPrintf("ANTICHEAT: Oversize path in %s\n", __func__);
+ pathlen = sizeof(path) - 1;
}
- if( msg_read.readcount < msg_read.cursize ) {
- MSG_ReadString( hash, sizeof( hash ) );
+ if (msg_read.readcount < msg_read.cursize) {
+ MSG_ReadString(hash, sizeof(hash));
} else {
- strcpy( hash, "no hash?" );
+ strcpy(hash, "no hash?");
}
cl->ac_file_failures++;
action = ac_badfile_action->integer;
- for( f = acs.files; f; f = f->next ) {
- if( !strcmp( f->path, path ) ) {
- if( f->flags & ACH_REQUIRED ) {
+ for (f = acs.files; f; f = f->next) {
+ if (!strcmp(f->path, path)) {
+ if (f->flags & ACH_REQUIRED) {
action = 1;
break;
}
}
}
- Com_Printf( "ANTICHEAT FILE VIOLATION: %s[%s] has a modified %s [%s]\n",
- cl->name, NET_AdrToString( &cl->netchan->remote_address ), path, hash );
- switch( action ) {
+ Com_Printf("ANTICHEAT FILE VIOLATION: %s[%s] has a modified %s [%s]\n",
+ cl->name, NET_AdrToString(&cl->netchan->remote_address), path, hash);
+ switch (action) {
case 0:
- AC_Announce( cl, "%s was kicked for modified %s\n", cl->name, path );
+ AC_Announce(cl, "%s was kicked for modified %s\n", cl->name, path);
break;
case 1:
- SV_ClientPrintf( cl, PRINT_HIGH, AC_MESSAGE
- "Your file %s has been modified. "
- "Please replace it with a known valid copy.\n", path );
+ SV_ClientPrintf(cl, PRINT_HIGH, AC_MESSAGE
+ "Your file %s has been modified. "
+ "Please replace it with a known valid copy.\n", path);
break;
case 2:
// spamalicious :)
- AC_Announce( cl, "%s has a modified %s\n", cl->name, path );
+ AC_Announce(cl, "%s has a modified %s\n", cl->name, path);
break;
}
// show custom msg
- if( ac_badfile_message->string[0] ) {
- SV_ClientPrintf( cl, PRINT_HIGH, "%s\n", ac_badfile_message->string );
+ if (ac_badfile_message->string[0]) {
+ SV_ClientPrintf(cl, PRINT_HIGH, "%s\n", ac_badfile_message->string);
}
- if( !action ) {
- SV_DropClient( cl, NULL );
+ if (!action) {
+ SV_DropClient(cl, NULL);
return;
}
- if( ac_badfile_max->integer > 0 && cl->ac_file_failures > ac_badfile_max->integer ) {
- AC_Announce( cl, "%s was kicked for too many modified files\n", cl->name );
- SV_DropClient( cl, NULL );
+ if (ac_badfile_max->integer > 0 && cl->ac_file_failures > ac_badfile_max->integer) {
+ AC_Announce(cl, "%s was kicked for too many modified files\n", cl->name);
+ SV_DropClient(cl, NULL);
return;
}
- bad = SV_Malloc( sizeof( *bad ) + pathlen );
- memcpy( bad->string, path, pathlen + 1 );
+ bad = SV_Malloc(sizeof(*bad) + pathlen);
+ memcpy(bad->string, path, pathlen + 1);
bad->next = cl->ac_bad_files;
cl->ac_bad_files = bad;
}
-static void AC_ParseReady( void ) {
+static void AC_ParseReady(void)
+{
ac.ready = qtrue;
ac.last_ping = svs.realtime;
acs.retry_backoff = AC_DEFAULT_BACKOFF;
- Com_Printf( "ANTICHEAT: Ready to serve anticheat clients.\n" );
- Cvar_FullSet( "anticheat", ac_required->string,
- CVAR_SERVERINFO | CVAR_ROM, FROM_CODE );
+ Com_Printf("ANTICHEAT: Ready to serve anticheat clients.\n");
+ Cvar_FullSet("anticheat", ac_required->string,
+ CVAR_SERVERINFO | CVAR_ROM, FROM_CODE);
}
-static void AC_ParseQueryReply( void ) {
+static void AC_ParseQueryReply(void)
+{
client_t *cl;
int type, valid;
cl = AC_ParseClient();
- if( !cl ) {
+ if (!cl) {
return;
}
- if( msg_read.readcount + 2 > msg_read.cursize ) {
- Com_DPrintf( "ANTICHEAT: Message too short in %s\n", __func__ );
+ if (msg_read.readcount + 2 > msg_read.cursize) {
+ Com_DPrintf("ANTICHEAT: Message too short in %s\n", __func__);
return;
}
@@ -833,19 +850,19 @@ static void AC_ParseQueryReply( void ) {
type = MSG_ReadByte();
cl->ac_query_sent = AC_QUERY_DONE;
- if( valid == 1 ) {
+ if (valid == 1) {
cl->ac_client_type = type;
cl->ac_valid = qtrue;
}
- if( cl->state < cs_connected || cl->state > cs_primed ) {
- Com_WPrintf( "ANTICHEAT: %s with client in state %d\n",
- __func__, cl->state );
- SV_DropClient( cl, NULL );
+ if (cl->state < cs_connected || cl->state > cs_primed) {
+ Com_WPrintf("ANTICHEAT: %s with client in state %d\n",
+ __func__, cl->state);
+ SV_DropClient(cl, NULL);
return;
}
- Com_DPrintf( "ANTICHEAT: %s for %s\n", __func__, cl->name );
+ Com_DPrintf("ANTICHEAT: %s for %s\n", __func__, cl->name);
// SV_Begin_f will handle possible map change
sv_client = cl;
@@ -855,44 +872,47 @@ static void AC_ParseQueryReply( void ) {
sv_player = NULL;
}
-// this is different from the violation "disconnected" as this message is
+// this is different from the violation "disconnected" as this message is
// only sent if the client manually disconnected and exists to prevent the
// race condition of the server seeing the disconnect violation before the
// udp message and thus showing "%s lost connection" right before the
// player leaves the server
-static void AC_ParseDisconnect ( void ) {
+static void AC_ParseDisconnect(void)
+{
client_t *cl;
cl = AC_ParseClient();
- if( cl ) {
- Com_Printf( "ANTICHEAT: Dropping %s, disconnect message.\n", cl->name );
- SV_DropClient( cl, NULL );
+ if (cl) {
+ Com_Printf("ANTICHEAT: Dropping %s, disconnect message.\n", cl->name);
+ SV_DropClient(cl, NULL);
}
}
-static void AC_ParseError( void ) {
+static void AC_ParseError(void)
+{
char string[MAX_STRING_CHARS];
- MSG_ReadString( string, sizeof( string ) );
- Com_EPrintf( "ANTICHEAT: %s\n", string );
+ MSG_ReadString(string, sizeof(string));
+ Com_EPrintf("ANTICHEAT: %s\n", string);
AC_Disable();
}
-static qboolean AC_ParseMessage( void ) {
+static qboolean AC_ParseMessage(void)
+{
uint16_t msglen;
int cmd;
// parse msglen
- if( !ac.msglen ) {
- if( !FIFO_TryRead( &ac.stream.recv, &msglen, 2 ) ) {
+ if (!ac.msglen) {
+ if (!FIFO_TryRead(&ac.stream.recv, &msglen, 2)) {
return qfalse;
}
- if( !msglen ) {
+ if (!msglen) {
return qtrue;
}
- msglen = LittleShort( msglen );
- if( msglen > AC_RECV_SIZE ) {
- Com_EPrintf( "ANTICHEAT: Oversize message: %u bytes\n", msglen );
+ msglen = LittleShort(msglen);
+ if (msglen > AC_RECV_SIZE) {
+ Com_EPrintf("ANTICHEAT: Oversize message: %u bytes\n", msglen);
AC_Drop();
return qfalse;
}
@@ -900,14 +920,14 @@ static qboolean AC_ParseMessage( void ) {
}
// read this message
- if( !FIFO_ReadMessage( &ac.stream.recv, ac.msglen ) ) {
+ if (!FIFO_ReadMessage(&ac.stream.recv, ac.msglen)) {
return qfalse;
}
ac.msglen = 0;
cmd = MSG_ReadByte();
- switch( cmd ) {
+ switch (cmd) {
case ACS_VIOLATION:
AC_ParseViolation();
break;
@@ -927,15 +947,15 @@ static qboolean AC_ParseMessage( void ) {
AC_ParseError();
return qfalse;
case ACS_NOACCESS:
- Com_WPrintf( "ANTICHEAT: You do not have permission to "
- "use the anticheat server. Anticheat disabled.\n" );
+ Com_WPrintf("ANTICHEAT: You do not have permission to "
+ "use the anticheat server. Anticheat disabled.\n");
AC_Disable();
return qfalse;
case ACS_UPDATE_REQUIRED:
- Com_WPrintf( "ANTICHEAT: The anticheat server is no longer "
- "compatible with this version of " APPLICATION ". "
- "Please make sure you are using the latest " APPLICATION " version. "
- "Anticheat disabled.\n" );
+ Com_WPrintf("ANTICHEAT: The anticheat server is no longer "
+ "compatible with this version of " APPLICATION ". "
+ "Please make sure you are using the latest " APPLICATION " version. "
+ "Anticheat disabled.\n");
AC_Disable();
return qfalse;
case ACS_DISCONNECT:
@@ -946,16 +966,16 @@ static qboolean AC_ParseMessage( void ) {
ac.last_ping = svs.realtime;
break;
default:
- Com_EPrintf( "ANTICHEAT: Unknown command byte %d, please make "
- "sure you are using the latest " APPLICATION " version. "
- "Anticheat disabled.\n", cmd );
+ Com_EPrintf("ANTICHEAT: Unknown command byte %d, please make "
+ "sure you are using the latest " APPLICATION " version. "
+ "Anticheat disabled.\n", cmd);
AC_Disable();
return qfalse;
}
- if( msg_read.readcount > msg_read.cursize ) {
- Com_WPrintf( "ANTICHEAT: Read %"PRIz" bytes past end of message %d\n",
- msg_read.readcount - msg_read.cursize, cmd );
+ if (msg_read.readcount > msg_read.cursize) {
+ Com_WPrintf("ANTICHEAT: Read %"PRIz" bytes past end of message %d\n",
+ msg_read.readcount - msg_read.cursize, cmd);
}
return qtrue;
@@ -969,184 +989,191 @@ IN-GAME QUERIES
==============================================================================
*/
-static void AC_Write( const char *func ) {
+static void AC_Write(const char *func)
+{
byte *src = msg_write.data;
size_t len = msg_write.cursize;
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- if( !FIFO_TryWrite( &ac.stream.send, src, len ) ) {
- Com_WPrintf( "ANTICHEAT: Send buffer exceeded in %s\n", func );
+ if (!FIFO_TryWrite(&ac.stream.send, src, len)) {
+ Com_WPrintf("ANTICHEAT: Send buffer exceeded in %s\n", func);
return;
}
- NET_UpdateStream( &ac.stream );
+ NET_UpdateStream(&ac.stream);
}
-static void AC_ClientQuery( client_t *cl ) {
+static void AC_ClientQuery(client_t *cl)
+{
cl->ac_query_sent = AC_QUERY_SENT;
cl->ac_query_time = svs.realtime;
- if( !ac.ready )
+ if (!ac.ready)
return;
- //if( ac_nag_time->integer )
+ //if (ac_nag_time->integer)
// cl->anticheat_nag_time = svs.realtime;
- MSG_WriteShort( 9 );
- MSG_WriteByte( ACC_QUERYCLIENT );
- MSG_WriteLong( cl->number );
- MSG_WriteLong( cl->challenge );
- AC_Write( __func__ );
+ MSG_WriteShort(9);
+ MSG_WriteByte(ACC_QUERYCLIENT);
+ MSG_WriteLong(cl->number);
+ MSG_WriteLong(cl->challenge);
+ AC_Write(__func__);
}
-qboolean AC_ClientBegin( client_t *cl ) {
- if( !ac_required->integer ) {
+qboolean AC_ClientBegin(client_t *cl)
+{
+ if (!ac_required->integer) {
return qtrue; // anticheat is not in use
}
- if( cl->ac_required == AC_EXEMPT ) {
+ if (cl->ac_required == AC_EXEMPT) {
return qtrue; // client is EXEMPT
}
- if( cl->ac_valid ) {
+ if (cl->ac_valid) {
return qtrue; // client is VALID
}
- if( cl->ac_query_sent == AC_QUERY_UNSENT && ac.ready ) {
- AC_ClientQuery( cl );
+ if (cl->ac_query_sent == AC_QUERY_UNSENT && ac.ready) {
+ AC_ClientQuery(cl);
return qfalse; // not yet QUERIED
}
- if( cl->ac_required != AC_REQUIRED ) {
+ if (cl->ac_required != AC_REQUIRED) {
return qtrue; // anticheat is NOT REQUIRED
}
- if( ac.ready ) {
+ if (ac.ready) {
// anticheat connection is UP, client is STILL INVALID
// AFTER QUERY, anticheat is REQUIRED
- Com_Printf( "ANTICHEAT: Rejected connecting client %s[%s], "
- "no anticheat response.\n", cl->name,
- NET_AdrToString( &cl->netchan->remote_address ) );
- SV_ClientPrintf( cl, PRINT_HIGH, "%s\n", ac_message->string );
- SV_DropClient( cl, NULL );
+ Com_Printf("ANTICHEAT: Rejected connecting client %s[%s], "
+ "no anticheat response.\n", cl->name,
+ NET_AdrToString(&cl->netchan->remote_address));
+ SV_ClientPrintf(cl, PRINT_HIGH, "%s\n", ac_message->string);
+ SV_DropClient(cl, NULL);
return qfalse;
}
- if( ac_error_action->integer == 0 ) {
+ if (ac_error_action->integer == 0) {
return qtrue; // error action is ALLOW
}
// anticheat server connection is DOWN, client is INVALID,
// anticheat is REQUIRED, error action is DENY
- Com_Printf( "ANTICHEAT: Rejected connecting client %s[%s], "
- "no connection to anticheat server.\n", cl->name,
- NET_AdrToString( &cl->netchan->remote_address ) );
- SV_ClientPrintf( cl, PRINT_HIGH,
- "This server is unable to take new connections right now. "
- "Please try again later.\n" );
- SV_DropClient( cl, NULL );
+ Com_Printf("ANTICHEAT: Rejected connecting client %s[%s], "
+ "no connection to anticheat server.\n", cl->name,
+ NET_AdrToString(&cl->netchan->remote_address));
+ SV_ClientPrintf(cl, PRINT_HIGH,
+ "This server is unable to take new connections right now. "
+ "Please try again later.\n");
+ SV_DropClient(cl, NULL);
return qfalse;
}
-void AC_ClientAnnounce( client_t *cl ) {
- if( !ac_required->integer ) {
+void AC_ClientAnnounce(client_t *cl)
+{
+ if (!ac_required->integer) {
return; // anticheat is not in use
}
- if( cl->state <= cs_zombie ) {
+ if (cl->state <= cs_zombie) {
return;
}
- if( cl->ac_required == AC_EXEMPT ) {
- SV_BroadcastPrintf( PRINT_MEDIUM, AC_MESSAGE
- "%s is exempt from using anticheat.\n", cl->name );
- } else if( cl->ac_valid ) {
- if( cl->ac_file_failures ) {
- SV_BroadcastPrintf( PRINT_MEDIUM, AC_MESSAGE
- "%s failed %d file check%s.\n",
- cl->name, cl->ac_file_failures,
- cl->ac_file_failures == 1 ? "" : "s" );
+ if (cl->ac_required == AC_EXEMPT) {
+ SV_BroadcastPrintf(PRINT_MEDIUM, AC_MESSAGE
+ "%s is exempt from using anticheat.\n", cl->name);
+ } else if (cl->ac_valid) {
+ if (cl->ac_file_failures) {
+ SV_BroadcastPrintf(PRINT_MEDIUM, AC_MESSAGE
+ "%s failed %d file check%s.\n",
+ cl->name, cl->ac_file_failures,
+ cl->ac_file_failures == 1 ? "" : "s");
}
} else {
- SV_BroadcastPrintf( PRINT_MEDIUM, AC_MESSAGE
- "%s is not using anticheat.\n", cl->name );
+ SV_BroadcastPrintf(PRINT_MEDIUM, AC_MESSAGE
+ "%s is not using anticheat.\n", cl->name);
}
}
-char *AC_ClientConnect( client_t *cl ) {
- if( !ac_required->integer ) {
+char *AC_ClientConnect(client_t *cl)
+{
+ if (!ac_required->integer) {
return ""; // anticheat is not in use
}
- if( SV_MatchAddress( &ac_exempt_list, &net_from ) ) {
+ if (SV_MatchAddress(&ac_exempt_list, &net_from)) {
cl->ac_required = AC_EXEMPT;
return "";
}
- if( ac_required->integer == 2 ) {
+ if (ac_required->integer == 2) {
// anticheat is required for everyone
cl->ac_required = AC_REQUIRED;
} else {
cl->ac_required = AC_NORMAL;
- if( SV_MatchAddress( &ac_required_list, &net_from ) ) {
+ if (SV_MatchAddress(&ac_required_list, &net_from)) {
cl->ac_required = AC_REQUIRED;
}
}
- if( ac.ready ) {
- MSG_WriteShort( 15 );
- MSG_WriteByte( ACC_REQUESTCHALLENGE );
- MSG_WriteData( net_from.ip.u8, 4 );
- MSG_WriteData( &net_from.port, 2 );
- MSG_WriteLong( cl->number );
- MSG_WriteLong( cl->challenge );
- AC_Write( __func__ );
+ if (ac.ready) {
+ MSG_WriteShort(15);
+ MSG_WriteByte(ACC_REQUESTCHALLENGE);
+ MSG_WriteData(net_from.ip.u8, 4);
+ MSG_WriteData(&net_from.port, 2);
+ MSG_WriteLong(cl->number);
+ MSG_WriteLong(cl->challenge);
+ AC_Write(__func__);
}
return " ac=1";
}
-void AC_ClientDisconnect( client_t *cl ) {
+void AC_ClientDisconnect(client_t *cl)
+{
cl->ac_query_sent = AC_QUERY_UNSENT;
cl->ac_valid = qfalse;
- if( !ac.ready )
+ if (!ac.ready)
return;
- MSG_WriteShort( 9 );
- MSG_WriteByte( ACC_CLIENTDISCONNECT );
- MSG_WriteLong( cl->number );
- MSG_WriteLong( cl->challenge );
- AC_Write( __func__ );
+ MSG_WriteShort(9);
+ MSG_WriteByte(ACC_CLIENTDISCONNECT);
+ MSG_WriteLong(cl->number);
+ MSG_WriteLong(cl->challenge);
+ AC_Write(__func__);
}
-void AC_ClientToken( client_t *cl, const char *token ) {
+void AC_ClientToken(client_t *cl, const char *token)
+{
string_entry_t *tok;
client_t *other;
- if( !ac_required->integer ) {
+ if (!ac_required->integer) {
return; // anticheat is not in use
}
- for( tok = acs.tokens; tok; tok = tok->next ) {
- if( !strcmp( tok->string, token ) ) {
+ for (tok = acs.tokens; tok; tok = tok->next) {
+ if (!strcmp(tok->string, token)) {
break;
}
}
- if( !tok ) {
+ if (!tok) {
return;
}
- FOR_EACH_CLIENT( other ) {
+ FOR_EACH_CLIENT(other) {
// FIXME: after `svacupdate' this check is incorrect
- if( other->ac_token == tok->string ) {
- SV_DropClient( other, "duplicate anticheat token" );
+ if (other->ac_token == tok->string) {
+ SV_DropClient(other, "duplicate anticheat token");
}
}
Com_Printf(
"ANTICHEAT: %s bypassed anticheat requirements with token '%s'\n",
- cl->name, tok->string );
+ cl->name, tok->string);
cl->ac_token = tok->string;
cl->ac_required = AC_EXEMPT;
}
@@ -1159,133 +1186,140 @@ STARTUP STUFF
==============================================================================
*/
-static void AC_Spin( void ) {
+static void AC_Spin(void)
+{
// sleep on stdin and AC server socket
- IO_Sleepv( 100,
+ IO_Sleepv(100,
#ifndef _WIN32
- 0,
+ 0,
#endif
- ac.stream.socket, -1 );
+ ac.stream.socket, -1);
#if USE_SYSCON
Sys_RunConsole();
#endif
AC_Run();
}
-static qboolean AC_Flush( void ) {
+static qboolean AC_Flush(void)
+{
byte *src = msg_write.data;
size_t ret, len = msg_write.cursize;
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- if( !ac.connected ) {
+ if (!ac.connected) {
return qfalse;
}
- while( 1 ) {
- ret = FIFO_Write( &ac.stream.send, src, len );
- NET_UpdateStream( &ac.stream );
+ while (1) {
+ ret = FIFO_Write(&ac.stream.send, src, len);
+ NET_UpdateStream(&ac.stream);
- if( ret == len ) {
+ if (ret == len) {
break;
}
len -= ret;
src += ret;
- Com_WPrintf( "ANTICHEAT: Send buffer length exceeded, "
- "server may be frozen for a short while!\n" );
+ Com_WPrintf("ANTICHEAT: Send buffer length exceeded, "
+ "server may be frozen for a short while!\n");
do {
AC_Spin();
- if( !ac.connected ) {
+ if (!ac.connected) {
return qfalse;
}
- } while( FIFO_Usage( &ac.stream.send ) > AC_SEND_SIZE / 2 );
+ } while (FIFO_Usage(&ac.stream.send) > AC_SEND_SIZE / 2);
}
return qtrue;
}
-static void AC_WriteString( const char *s ) {
- size_t len = strlen( s );
+static void AC_WriteString(const char *s)
+{
+ size_t len = strlen(s);
- if( len > 255 ) {
+ if (len > 255) {
len = 255;
}
- MSG_WriteByte( len );
- MSG_WriteData( s, len );
+ MSG_WriteByte(len);
+ MSG_WriteData(s, len);
}
-static void AC_SendChecks( void ) {
+static void AC_SendChecks(void)
+{
ac_file_t *f, *p;
ac_cvar_t *c;
int i;
- MSG_WriteShort( 9 );
- MSG_WriteByte( ACC_UPDATECHECKS );
- MSG_WriteLong( acs.num_files );
- MSG_WriteLong( acs.num_cvars );
+ MSG_WriteShort(9);
+ MSG_WriteByte(ACC_UPDATECHECKS);
+ MSG_WriteLong(acs.num_files);
+ MSG_WriteLong(acs.num_cvars);
AC_Flush();
- for( f = acs.files, p = NULL; f; p = f, f = f->next ) {
- MSG_WriteData( f->hash, sizeof( f->hash ) );
- MSG_WriteByte( f->flags );
- if( p && !strcmp( f->path, p->path ) ) {
- MSG_WriteByte( 0 );
+ for (f = acs.files, p = NULL; f; p = f, f = f->next) {
+ MSG_WriteData(f->hash, sizeof(f->hash));
+ MSG_WriteByte(f->flags);
+ if (p && !strcmp(f->path, p->path)) {
+ MSG_WriteByte(0);
} else {
- AC_WriteString( f->path );
+ AC_WriteString(f->path);
}
AC_Flush();
}
- for( c = acs.cvars; c; c = c->next ) {
- AC_WriteString( c->name );
- MSG_WriteByte( c->op );
- MSG_WriteByte( c->num_values );
- for( i = 0; i < c->num_values; i++ ) {
- AC_WriteString( c->values[i] );
+ for (c = acs.cvars; c; c = c->next) {
+ AC_WriteString(c->name);
+ MSG_WriteByte(c->op);
+ MSG_WriteByte(c->num_values);
+ for (i = 0; i < c->num_values; i++) {
+ AC_WriteString(c->values[i]);
}
- AC_WriteString( c->def );
+ AC_WriteString(c->def);
AC_Flush();
}
}
-static void AC_SendPrefs( void ) {
+static void AC_SendPrefs(void)
+{
int prefs = 0;
- if( ac_disable_play->integer ) {
+ if (ac_disable_play->integer) {
prefs |= ACP_BLOCKPLAY;
}
- MSG_WriteShort( 5 );
- MSG_WriteByte( ACC_SETPREFERENCES );
- MSG_WriteLong( prefs );
+ MSG_WriteShort(5);
+ MSG_WriteByte(ACC_SETPREFERENCES);
+ MSG_WriteLong(prefs);
AC_Flush();
}
-static void AC_SendPing( void ) {
+static void AC_SendPing(void)
+{
ac.last_ping = svs.realtime;
ac.ping_pending = qtrue;
- MSG_WriteShort( 1 );
- MSG_WriteByte( ACC_PING );
+ MSG_WriteShort(1);
+ MSG_WriteByte(ACC_PING);
AC_Flush();
}
-static void AC_SendHello( void ) {
- size_t hostlen = strlen( sv_hostname->string );
- size_t verlen = strlen( com_version->string );
-
- MSG_WriteByte( 0x02 );
- MSG_WriteShort( 22 + hostlen + verlen ); // why 22 instead of 9?
- MSG_WriteByte( ACC_VERSION );
- MSG_WriteShort( AC_PROTOCOL_VERSION );
- MSG_WriteShort( hostlen );
- MSG_WriteData( sv_hostname->string, hostlen );
- MSG_WriteShort( verlen );
- MSG_WriteData( com_version->string, verlen );
- MSG_WriteLong( net_port->integer );
+static void AC_SendHello(void)
+{
+ size_t hostlen = strlen(sv_hostname->string);
+ size_t verlen = strlen(com_version->string);
+
+ MSG_WriteByte(0x02);
+ MSG_WriteShort(22 + hostlen + verlen); // why 22 instead of 9?
+ MSG_WriteByte(ACC_VERSION);
+ MSG_WriteShort(AC_PROTOCOL_VERSION);
+ MSG_WriteShort(hostlen);
+ MSG_WriteData(sv_hostname->string, hostlen);
+ MSG_WriteShort(verlen);
+ MSG_WriteData(com_version->string, verlen);
+ MSG_WriteLong(net_port->integer);
AC_Flush();
AC_SendChecks();
@@ -1293,30 +1327,31 @@ static void AC_SendHello( void ) {
AC_SendPing();
}
-static void AC_CheckTimeouts( void ) {
+static void AC_CheckTimeouts(void)
+{
client_t *cl;
- if( ac.ping_pending ) {
- if( svs.realtime - ac.last_ping > AC_PING_TIMEOUT ) {
- Com_Printf( "ANTICHEAT: Server ping timeout, disconnecting.\n" );
+ if (ac.ping_pending) {
+ if (svs.realtime - ac.last_ping > AC_PING_TIMEOUT) {
+ Com_Printf("ANTICHEAT: Server ping timeout, disconnecting.\n");
AC_Drop();
return;
}
- } else if( ac.ready ) {
- if( svs.realtime - ac.last_ping > AC_PING_INTERVAL ) {
+ } else if (ac.ready) {
+ if (svs.realtime - ac.last_ping > AC_PING_INTERVAL) {
AC_SendPing();
}
}
- FOR_EACH_CLIENT( cl ) {
- if( cl->state < cs_connected || cl->state > cs_primed ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state < cs_connected || cl->state > cs_primed) {
continue;
}
- if( cl->ac_query_sent != AC_QUERY_SENT ) {
+ if (cl->ac_query_sent != AC_QUERY_SENT) {
continue;
}
- if( svs.realtime - cl->ac_query_time > 5000 ) {
- Com_WPrintf( "ANTICHEAT: Query timed out for %s, possible network problem.\n", cl->name );
+ if (svs.realtime - cl->ac_query_time > 5000) {
+ Com_WPrintf("ANTICHEAT: Query timed out for %s, possible network problem.\n", cl->name);
cl->ac_valid = qfalse;
sv_client = cl;
sv_player = cl->edict;
@@ -1327,18 +1362,19 @@ static void AC_CheckTimeouts( void ) {
}
}
-static qboolean AC_Reconnect( void ) {
+static qboolean AC_Reconnect(void)
+{
netadr_t address;
- if( !NET_StringToAdr( ac_server_address->string, &address, PORT_SERVER ) ) {
- Com_WPrintf( "ANTICHEAT: Unable to lookup %s.\n",
- ac_server_address->string );
+ if (!NET_StringToAdr(ac_server_address->string, &address, PORT_SERVER)) {
+ Com_WPrintf("ANTICHEAT: Unable to lookup %s.\n",
+ ac_server_address->string);
goto fail;
}
- if( NET_Connect( &address, &ac.stream ) == NET_ERROR ) {
- Com_EPrintf( "ANTICHEAT: %s to %s.\n",
- NET_ErrorString(), NET_AdrToString( &address ) );
+ if (NET_Connect(&address, &ac.stream) == NET_ERROR) {
+ Com_EPrintf("ANTICHEAT: %s to %s.\n",
+ NET_ErrorString(), NET_AdrToString(&address));
goto fail;
}
@@ -1356,46 +1392,47 @@ fail:
}
-void AC_Run( void ) {
+void AC_Run(void)
+{
neterr_t ret = NET_AGAIN;
time_t clock;
- if( acs.retry_time ) {
- clock = time( NULL );
- if( acs.retry_time < clock ) {
- Com_Printf( "ANTICHEAT: Attempting to reconnect to anticheat server...\n" );
+ if (acs.retry_time) {
+ clock = time(NULL);
+ if (acs.retry_time < clock) {
+ Com_Printf("ANTICHEAT: Attempting to reconnect to anticheat server...\n");
AC_Reconnect();
}
return;
}
- if( !ac.stream.state ) {
+ if (!ac.stream.state) {
return;
}
- if( !ac.connected ) {
- ret = NET_RunConnect( &ac.stream );
- if( ret == NET_OK ) {
- Com_Printf( "ANTICHEAT: Connected to anticheat server!\n" );
+ if (!ac.connected) {
+ ret = NET_RunConnect(&ac.stream);
+ if (ret == NET_OK) {
+ Com_Printf("ANTICHEAT: Connected to anticheat server!\n");
ac.connected = qtrue;
AC_SendHello();
}
}
- if( ac.connected ) {
- ret = NET_RunStream( &ac.stream );
- if( ret == NET_OK ) {
- while( AC_ParseMessage() )
+ if (ac.connected) {
+ ret = NET_RunStream(&ac.stream);
+ if (ret == NET_OK) {
+ while (AC_ParseMessage())
;
- NET_UpdateStream( &ac.stream );
+ NET_UpdateStream(&ac.stream);
}
AC_CheckTimeouts();
}
- switch( ret ) {
+ switch (ret) {
case NET_ERROR:
- Com_EPrintf( "ANTICHEAT: %s to %s.\n", NET_ErrorString(),
- NET_AdrToString( &ac.stream.address ) );
+ Com_EPrintf("ANTICHEAT: %s to %s.\n", NET_ErrorString(),
+ NET_AdrToString(&ac.stream.address));
case NET_CLOSED:
AC_Drop();
break;
@@ -1404,254 +1441,266 @@ void AC_Run( void ) {
}
}
-void AC_Connect( unsigned mvd_spawn ) {
+void AC_Connect(unsigned mvd_spawn)
+{
int attempts;
- if( !ac_required->integer ) {
+ if (!ac_required->integer) {
return;
}
#if USE_CLIENT
- if( !dedicated->integer ) {
- Com_Printf( "ANTICHEAT: Only supported on dedicated servers, disabling.\n" );
- Cvar_SetByVar( ac_required, "0", FROM_CODE );
+ if (!dedicated->integer) {
+ Com_Printf("ANTICHEAT: Only supported on dedicated servers, disabling.\n");
+ Cvar_SetByVar(ac_required, "0", FROM_CODE);
return;
}
#endif
- if( mvd_spawn ) {
- Com_Printf( "ANTICHEAT: Only supported on game servers, disabling.\n" );
- Cvar_SetByVar( ac_required, "0", FROM_CODE );
+ if (mvd_spawn) {
+ Com_Printf("ANTICHEAT: Only supported on game servers, disabling.\n");
+ Cvar_SetByVar(ac_required, "0", FROM_CODE);
return;
}
AC_LoadChecks();
- Com_Printf( "ANTICHEAT: Attempting to connect to %s...\n", ac_server_address->string );
+ Com_Printf("ANTICHEAT: Attempting to connect to %s...\n", ac_server_address->string);
#if USE_SYSCON
Sys_RunConsole();
#endif
acs.retry_backoff = AC_DEFAULT_BACKOFF;
- if( !AC_Reconnect() ) {
+ if (!AC_Reconnect()) {
return;
}
// synchronize startup
- for( attempts = 0; attempts < 50; attempts++ ) {
+ for (attempts = 0; attempts < 50; attempts++) {
AC_Spin();
- if( ac.ready || !ac.stream.state ) {
+ if (ac.ready || !ac.stream.state) {
return;
}
}
- Com_WPrintf( "ANTICHEAT: Still not ready, resuming server initialization.\n" );
+ Com_WPrintf("ANTICHEAT: Still not ready, resuming server initialization.\n");
}
-void AC_Disconnect( void ) {
- NET_Close( &ac.stream );
+void AC_Disconnect(void)
+{
+ NET_Close(&ac.stream);
AC_FreeChecks();
- memset( &ac, 0, sizeof( ac ) );
- memset( &acs, 0, sizeof( acs ) );
- Cvar_FullSet( "anticheat", "0", CVAR_ROM, FROM_CODE );
+ memset(&ac, 0, sizeof(ac));
+ memset(&acs, 0, sizeof(acs));
+ Cvar_FullSet("anticheat", "0", CVAR_ROM, FROM_CODE);
}
-void AC_List_f( void ) {
+void AC_List_f(void)
+{
client_t *cl;
char *sub;
int i;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( !ac_required->integer ) {
- Com_Printf( "The anticheat module is not in use on this server.\n"
- "For information on anticheat, please visit http://antiche.at/\n" );
+ if (!ac_required->integer) {
+ Com_Printf("The anticheat module is not in use on this server.\n"
+ "For information on anticheat, please visit http://antiche.at/\n");
return;
}
- sub = Cmd_Argv( 1 );
+ sub = Cmd_Argv(1);
Com_Printf(
"+----------------+--------+-----+------+\n"
"| Player Name |AC Valid|Files|Client|\n"
- "+----------------+--------+-----+------+\n" );
+ "+----------------+--------+-----+------+\n");
- FOR_EACH_CLIENT( cl ) {
- if( cl->state < cs_spawned ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state < cs_spawned) {
continue;
}
- if( *sub && !strstr( cl->name, sub ) ) {
+ if (*sub && !strstr(cl->name, sub)) {
continue;
}
- if( cl->ac_required == AC_EXEMPT ) {
- Com_Printf( "|%-16s| exempt | N/A | N/A |\n", cl->name );
- } else if( cl->ac_valid ) {
+ if (cl->ac_required == AC_EXEMPT) {
+ Com_Printf("|%-16s| exempt | N/A | N/A |\n", cl->name);
+ } else if (cl->ac_valid) {
i = cl->ac_client_type;
- if( i < 0 || i >= ac_num_clients ) {
+ if (i < 0 || i >= ac_num_clients) {
i = 0;
}
- Com_Printf( "|%-16s| yes | %3d |%-6s|\n", cl->name,
- cl->ac_file_failures, ac_clients[i] );
+ Com_Printf("|%-16s| yes | %3d |%-6s|\n", cl->name,
+ cl->ac_file_failures, ac_clients[i]);
} else {
- Com_Printf( "|%-16s| NO | N/A | N/A |\n", cl->name );
+ Com_Printf("|%-16s| NO | N/A | N/A |\n", cl->name);
}
}
- Com_Printf( "+----------------+--------+-----+------+\n" );
+ Com_Printf("+----------------+--------+-----+------+\n");
- if( ac.ready ) {
- Com_Printf( "File check list in use: %s\n", acs.hashlist_name );
+ if (ac.ready) {
+ Com_Printf("File check list in use: %s\n", acs.hashlist_name);
}
Com_Printf(
"This Quake II server is %sconnected to the anticheat server.\n"
"For information on anticheat, please visit http://antiche.at/\n",
- ac.ready ? "" : "NOT " );
+ ac.ready ? "" : "NOT ");
}
-void AC_Info_f( void ) {
+void AC_Info_f(void)
+{
client_t *cl;
string_entry_t *bad;
char *substring, *filesubstring;
int clientID;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( !ac_required->integer ) {
- Com_Printf( "The anticheat module is not in use on this server.\n"
- "For information on anticheat, please visit http://antiche.at/\n" );
+ if (!ac_required->integer) {
+ Com_Printf("The anticheat module is not in use on this server.\n"
+ "For information on anticheat, please visit http://antiche.at/\n");
return;
}
- if( Cmd_Argc() == 1 ) {
- if( !sv_client ) {
- Com_Printf( "Usage: %s [substring|id] [filesubstring]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() == 1) {
+ if (!sv_client) {
+ Com_Printf("Usage: %s [substring|id] [filesubstring]\n", Cmd_Argv(0));
return;
}
cl = sv_client;
filesubstring = "";
} else {
- substring = Cmd_Argv( 1 );
- filesubstring = Cmd_Argv( 2 );
+ substring = Cmd_Argv(1);
+ filesubstring = Cmd_Argv(2);
- if( COM_IsUint( substring ) ) {
- clientID = atoi( substring );
- if( clientID < 0 || clientID >= sv_maxclients->integer ) {
- Com_Printf( "Invalid client ID.\n" );
+ if (COM_IsUint(substring)) {
+ clientID = atoi(substring);
+ if (clientID < 0 || clientID >= sv_maxclients->integer) {
+ Com_Printf("Invalid client ID.\n");
return;
}
cl = &svs.client_pool[clientID];
- if( cl->state < cs_spawned ) {
- Com_Printf( "Player is not active.\n" );
+ if (cl->state < cs_spawned) {
+ Com_Printf("Player is not active.\n");
return;
}
} else {
- FOR_EACH_CLIENT( cl ) {
- if( cl->state < cs_spawned ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state < cs_spawned) {
continue;
}
- if( strstr( cl->name, substring ) ) {
+ if (strstr(cl->name, substring)) {
goto found;
}
}
- Com_Printf( "Player not found.\n" );
+ Com_Printf("Player not found.\n");
return;
}
}
found:
- if( !cl->ac_valid ) {
- Com_Printf( "%s is not using anticheat.\n", cl->name );
+ if (!cl->ac_valid) {
+ Com_Printf("%s is not using anticheat.\n", cl->name);
return;
}
-
- if( cl->ac_bad_files ) {
- Com_Printf( "File check failures for %s:\n", cl->name );
- for( bad = cl->ac_bad_files; bad; bad = bad->next ) {
- if( !filesubstring[0] || strstr( bad->string, filesubstring ) ) {
- Com_Printf( "%s\n", bad->string );
+
+ if (cl->ac_bad_files) {
+ Com_Printf("File check failures for %s:\n", cl->name);
+ for (bad = cl->ac_bad_files; bad; bad = bad->next) {
+ if (!filesubstring[0] || strstr(bad->string, filesubstring)) {
+ Com_Printf("%s\n", bad->string);
}
}
} else {
- Com_Printf( "%s has no file check failures.\n", cl->name );
+ Com_Printf("%s has no file check failures.\n", cl->name);
}
}
-static void AC_Invalidate_f( void ) {
+static void AC_Invalidate_f(void)
+{
client_t *cl;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( !ac.ready ) {
- Com_Printf( "Anticheat is not ready.\n" );
+ if (!ac.ready) {
+ Com_Printf("Anticheat is not ready.\n");
return;
}
-
- FOR_EACH_CLIENT( cl ) {
- if( cl->state > cs_connected ) {
- AC_ClientDisconnect( cl );
+
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state > cs_connected) {
+ AC_ClientDisconnect(cl);
}
}
- Com_Printf( "All clients marked as invalid.\n" );
+ Com_Printf("All clients marked as invalid.\n");
}
-static void AC_Update_f( void ) {
+static void AC_Update_f(void)
+{
client_t *cl;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( !ac_required->integer ) {
- Com_Printf( "Anticheat is not in use.\n" );
+ if (!ac_required->integer) {
+ Com_Printf("Anticheat is not in use.\n");
return;
}
AC_FreeChecks();
AC_LoadChecks();
- if( ac.connected ) {
+ if (ac.connected) {
AC_SendChecks();
}
// reset all tokens
- FOR_EACH_CLIENT( cl ) {
+ FOR_EACH_CLIENT(cl) {
cl->ac_token = NULL;
}
- Com_Printf( "Anticheat configuration updated.\n" );
+ Com_Printf("Anticheat configuration updated.\n");
}
-static void AC_AddException_f( void ) {
- SV_AddMatch_f( &ac_exempt_list );
+static void AC_AddException_f(void)
+{
+ SV_AddMatch_f(&ac_exempt_list);
}
-static void AC_DelException_f( void ) {
- SV_DelMatch_f( &ac_exempt_list );
+static void AC_DelException_f(void)
+{
+ SV_DelMatch_f(&ac_exempt_list);
}
-static void AC_ListExceptions_f( void ) {
- SV_ListMatches_f( &ac_exempt_list );
+static void AC_ListExceptions_f(void)
+{
+ SV_ListMatches_f(&ac_exempt_list);
}
-static void AC_AddRequirement_f( void ) {
- SV_AddMatch_f( &ac_required_list );
+static void AC_AddRequirement_f(void)
+{
+ SV_AddMatch_f(&ac_required_list);
}
-static void AC_DelRequirement_f( void ) {
- SV_DelMatch_f( &ac_required_list );
+static void AC_DelRequirement_f(void)
+{
+ SV_DelMatch_f(&ac_required_list);
}
-static void AC_ListRequirements_f( void ) {
- SV_ListMatches_f( &ac_required_list );
+static void AC_ListRequirements_f(void)
+{
+ SV_ListMatches_f(&ac_required_list);
}
static const cmdreg_t c_ac[] = {
@@ -1671,28 +1720,30 @@ static const cmdreg_t c_ac[] = {
{ NULL }
};
-static void ac_disable_play_changed( cvar_t *self ) {
- if( ac.connected ) {
+static void ac_disable_play_changed(cvar_t *self)
+{
+ if (ac.connected) {
AC_SendPrefs();
}
}
-void AC_Register( void ) {
- ac_required = Cvar_Get( "sv_anticheat_required", "0", CVAR_LATCH );
- ac_server_address = Cvar_Get( "sv_anticheat_server_address", "anticheat.r1ch.net", CVAR_LATCH );
- ac_error_action = Cvar_Get( "sv_anticheat_error_action", "0", 0 );
- ac_message = Cvar_Get( "sv_anticheat_message",
- "This server requires the r1ch.net anticheat module. "
- "Please see http://antiche.at/ for more details.", 0 );
- ac_badfile_action = Cvar_Get( "sv_anticheat_badfile_action", "0", 0 );
- ac_badfile_message = Cvar_Get( "sv_anticheat_badfile_message", "", 0 );
- ac_badfile_max = Cvar_Get( "sv_anticheat_badfile_max", "0", 0 );
- ac_show_violation_reason = Cvar_Get( "sv_anticheat_show_violation_reason", "0", 0 );
- ac_client_disconnect_action = Cvar_Get( "sv_anticheat_client_disconnect_action", "0", 0 );
- ac_disable_play = Cvar_Get( "sv_anticheat_disable_play", "0", 0 );
+void AC_Register(void)
+{
+ ac_required = Cvar_Get("sv_anticheat_required", "0", CVAR_LATCH);
+ ac_server_address = Cvar_Get("sv_anticheat_server_address", "anticheat.r1ch.net", CVAR_LATCH);
+ ac_error_action = Cvar_Get("sv_anticheat_error_action", "0", 0);
+ ac_message = Cvar_Get("sv_anticheat_message",
+ "This server requires the r1ch.net anticheat module. "
+ "Please see http://antiche.at/ for more details.", 0);
+ ac_badfile_action = Cvar_Get("sv_anticheat_badfile_action", "0", 0);
+ ac_badfile_message = Cvar_Get("sv_anticheat_badfile_message", "", 0);
+ ac_badfile_max = Cvar_Get("sv_anticheat_badfile_max", "0", 0);
+ ac_show_violation_reason = Cvar_Get("sv_anticheat_show_violation_reason", "0", 0);
+ ac_client_disconnect_action = Cvar_Get("sv_anticheat_client_disconnect_action", "0", 0);
+ ac_disable_play = Cvar_Get("sv_anticheat_disable_play", "0", 0);
ac_disable_play->changed = ac_disable_play_changed;
- Cmd_Register( c_ac );
+ Cmd_Register(c_ac);
}
diff --git a/src/sv_ccmds.c b/src/sv_ccmds.c
index a018052..995b584 100644
--- a/src/sv_ccmds.c
+++ b/src/sv_ccmds.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -36,7 +36,8 @@ SV_SetMaster_f
Specify a list of master servers
====================
*/
-static void SV_SetMaster_f( void ) {
+static void SV_SetMaster_f(void)
+{
netadr_t adr;
int i, total;
char *s;
@@ -45,173 +46,177 @@ static void SV_SetMaster_f( void ) {
#if USE_CLIENT
// only dedicated servers send heartbeats
- if( !dedicated->integer ) {
- Com_Printf( "Only dedicated servers use masters.\n" );
+ if (!dedicated->integer) {
+ Com_Printf("Only dedicated servers use masters.\n");
return;
}
#endif
// free old masters
- FOR_EACH_MASTER_SAFE( m, n ) {
- Z_Free( m );
+ FOR_EACH_MASTER_SAFE(m, n) {
+ Z_Free(m);
}
- List_Init( &sv_masterlist );
+ List_Init(&sv_masterlist);
total = 0;
- for( i = 1; i < Cmd_Argc(); i++ ) {
- if( total == MAX_MASTERS ) {
- Com_Printf( "Too many masters.\n" );
+ for (i = 1; i < Cmd_Argc(); i++) {
+ if (total == MAX_MASTERS) {
+ Com_Printf("Too many masters.\n");
break;
}
- s = Cmd_Argv( i );
- if( !NET_StringToAdr( s, &adr, PORT_MASTER ) ) {
- Com_Printf( "Bad master address: %s\n", s );
+ s = Cmd_Argv(i);
+ if (!NET_StringToAdr(s, &adr, PORT_MASTER)) {
+ Com_Printf("Bad master address: %s\n", s);
continue;
}
- FOR_EACH_MASTER( m ) {
- if( NET_IsEqualBaseAdr( &m->adr, &adr ) ) {
- Com_Printf( "Ignoring duplicate master at %s.\n", NET_AdrToString( &adr ) );
+ FOR_EACH_MASTER(m) {
+ if (NET_IsEqualBaseAdr(&m->adr, &adr)) {
+ Com_Printf("Ignoring duplicate master at %s.\n", NET_AdrToString(&adr));
goto out;
}
}
- Com_Printf( "Master server at %s.\n", NET_AdrToString( &adr ) );
- len = strlen( s );
- m = Z_Malloc( sizeof( *m ) + len );
- memcpy( m->name, s, len + 1 );
+ Com_Printf("Master server at %s.\n", NET_AdrToString(&adr));
+ len = strlen(s);
+ m = Z_Malloc(sizeof(*m) + len);
+ memcpy(m->name, s, len + 1);
m->adr = adr;
m->last_ack = 0;
- m->last_resolved = time( NULL );
- List_Append( &sv_masterlist, &m->entry );
+ m->last_resolved = time(NULL);
+ List_Append(&sv_masterlist, &m->entry);
total++;
out:;
}
- if( total ) {
+ if (total) {
// make sure the server is listed public
- Cvar_Set( "public", "1" );
+ Cvar_Set("public", "1");
- svs.last_heartbeat = svs.realtime - HEARTBEAT_SECONDS*1000;
+ svs.last_heartbeat = svs.realtime - HEARTBEAT_SECONDS * 1000;
}
}
-static void SV_ListMasters_f( void ) {
+static void SV_ListMasters_f(void)
+{
master_t *m;
char buf[8], *adr;
int i;
- if( LIST_EMPTY( &sv_masterlist ) ) {
- Com_Printf( "There are no masters.\n" );
+ if (LIST_EMPTY(&sv_masterlist)) {
+ Com_Printf("There are no masters.\n");
return;
}
- Com_Printf( "num hostname lastmsg address\n"
- "--- --------------------- ------- ---------------------\n" );
+ Com_Printf("num hostname lastmsg address\n"
+ "--- --------------------- ------- ---------------------\n");
i = 0;
- FOR_EACH_MASTER( m ) {
- if( !svs.initialized ) {
- strcpy( buf, "down" );
- } else if( !m->last_ack ) {
- strcpy( buf, "never" );
+ FOR_EACH_MASTER(m) {
+ if (!svs.initialized) {
+ strcpy(buf, "down");
+ } else if (!m->last_ack) {
+ strcpy(buf, "never");
} else {
- Q_snprintf( buf, sizeof( buf ), "%u", svs.realtime - m->last_ack );
+ Q_snprintf(buf, sizeof(buf), "%u", svs.realtime - m->last_ack);
}
- adr = m->adr.port ? NET_AdrToString( &m->adr ) : "error";
- Com_Printf( "%3d %-21.21s %7s %-21s\n", ++i, m->name, buf, adr );
+ adr = m->adr.port ? NET_AdrToString(&m->adr) : "error";
+ Com_Printf("%3d %-21.21s %7s %-21s\n", ++i, m->name, buf, adr);
}
}
-client_t *SV_GetPlayer( const char *s, qboolean partial ) {
+client_t *SV_GetPlayer(const char *s, qboolean partial)
+{
client_t *other, *match;
int i, count;
- if( !s[0] ) {
+ if (!s[0]) {
return NULL;
}
// numeric values are just slot numbers
- if( COM_IsUint( s ) ) {
- i = atoi( s );
- if( i < 0 || i >= sv_maxclients->integer ) {
- Com_Printf( "Bad client slot number: %d\n", i );
+ if (COM_IsUint(s)) {
+ i = atoi(s);
+ if (i < 0 || i >= sv_maxclients->integer) {
+ Com_Printf("Bad client slot number: %d\n", i);
return NULL;
}
other = &svs.client_pool[i];
- if( other->state <= cs_zombie ) {
- Com_Printf( "Client slot %d is not active.\n", i );
+ if (other->state <= cs_zombie) {
+ Com_Printf("Client slot %d is not active.\n", i);
return NULL;
}
return other;
}
// check for exact name match
- FOR_EACH_CLIENT( other ) {
- if( other->state <= cs_zombie ) {
+ FOR_EACH_CLIENT(other) {
+ if (other->state <= cs_zombie) {
continue;
}
- if( !strcmp( other->name, s ) ) {
+ if (!strcmp(other->name, s)) {
return other;
}
}
- if( !partial ) {
- Com_Printf( "Userid '%s' is not on the server.\n", s );
+ if (!partial) {
+ Com_Printf("Userid '%s' is not on the server.\n", s);
return NULL;
}
// check for partial, case insensitive name match
match = NULL;
count = 0;
- FOR_EACH_CLIENT( other ) {
- if( other->state <= cs_zombie ) {
+ FOR_EACH_CLIENT(other) {
+ if (other->state <= cs_zombie) {
continue;
}
- if( !Q_stricmp( other->name, s ) ) {
+ if (!Q_stricmp(other->name, s)) {
return other; // exact match
}
- if( Q_stristr( other->name, s ) ) {
+ if (Q_stristr(other->name, s)) {
match = other; // partial match
count++;
}
}
- if( !match ) {
- Com_Printf( "No clients matching '%s' found.\n", s );
+ if (!match) {
+ Com_Printf("No clients matching '%s' found.\n", s);
return NULL;
}
- if( count > 1 ) {
- Com_Printf( "'%s' matches multiple clients.\n", s );
+ if (count > 1) {
+ Com_Printf("'%s' matches multiple clients.\n", s);
return NULL;
}
return match;
}
-static void SV_Player_g( genctx_t *ctx ) {
+static void SV_Player_g(genctx_t *ctx)
+{
client_t *cl;
- if( !svs.initialized ) {
+ if (!svs.initialized) {
return;
}
-
- FOR_EACH_CLIENT( cl ) {
- if( cl->state <= cs_zombie ) {
+
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state <= cs_zombie) {
continue;
}
- if( !Prompt_AddMatch( ctx, cl->name ) ) {
+ if (!Prompt_AddMatch(ctx, cl->name)) {
break;
}
}
}
-static void SV_SetPlayer_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- SV_Player_g( ctx );
+static void SV_SetPlayer_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ SV_Player_g(ctx);
}
}
@@ -222,11 +227,12 @@ SV_SetPlayer
Sets sv_client and sv_player to the player with idnum Cmd_Argv(1)
==================
*/
-static qboolean SV_SetPlayer( void ) {
+static qboolean SV_SetPlayer(void)
+{
client_t *cl;
- cl = SV_GetPlayer( Cmd_Argv( 1 ), !!sv_enhanced_setplayer->integer );
- if( !cl ) {
+ cl = SV_GetPlayer(Cmd_Argv(1), !!sv_enhanced_setplayer->integer);
+ if (!cl) {
return qfalse;
}
@@ -253,7 +259,8 @@ another level:
map tram.cin+jail_e3
======================
*/
-static void SV_Map( int argnum, qboolean restart ) {
+static void SV_Map(int argnum, qboolean restart)
+{
char mapcmd[MAX_QPATH];
char expanded[MAX_QPATH];
char *s, *ch, *spawnpoint;
@@ -262,9 +269,9 @@ static void SV_Map( int argnum, qboolean restart ) {
size_t len;
// save the mapcmd
- len = Cmd_ArgvBuffer( argnum, mapcmd, sizeof( mapcmd ) );
- if( len >= sizeof( mapcmd ) ) {
- Com_Printf( "Refusing to process oversize level string.\n" );
+ len = Cmd_ArgvBuffer(argnum, mapcmd, sizeof(mapcmd));
+ if (len >= sizeof(mapcmd)) {
+ Com_Printf("Refusing to process oversize level string.\n");
return;
}
@@ -272,19 +279,19 @@ static void SV_Map( int argnum, qboolean restart ) {
// if there is a + in the map, set nextserver to the remainder
// we go directly to nextserver as we don't support cinematics
- ch = strchr( s, '+' );
- if( ch ) {
+ ch = strchr(s, '+');
+ if (ch) {
s = ch + 1;
}
// skip the end-of-unit flag if necessary
- if( *s == '*' ) {
+ if (*s == '*') {
s++;
}
// if there is a $, use the remainder as a spawnpoint
- ch = strchr( s, '$' );
- if( ch ) {
+ ch = strchr(s, '$');
+ if (ch) {
*ch = 0;
spawnpoint = ch + 1;
} else {
@@ -292,24 +299,24 @@ static void SV_Map( int argnum, qboolean restart ) {
}
// now expand and try to load the map
- len = Q_concat( expanded, sizeof( expanded ), "maps/", s, ".bsp", NULL );
- if( len >= sizeof( expanded ) ) {
+ len = Q_concat(expanded, sizeof(expanded), "maps/", s, ".bsp", NULL);
+ if (len >= sizeof(expanded)) {
ret = Q_ERR_NAMETOOLONG;
} else {
- ret = CM_LoadMap( &cm, expanded );
+ ret = CM_LoadMap(&cm, expanded);
}
- if( ret ) {
- Com_Printf( "Couldn't load %s: %s\n", expanded, Q_ErrorString( ret ) );
+ if (ret) {
+ Com_Printf("Couldn't load %s: %s\n", expanded, Q_ErrorString(ret));
return;
}
// any error will drop from this point
- if( sv.state != ss_game || restart ) {
- SV_InitGame( MVD_SPAWN_DISABLED ); // the game is just starting
+ if (sv.state != ss_game || restart) {
+ SV_InitGame(MVD_SPAWN_DISABLED); // the game is just starting
}
- SV_SpawnServer( &cm, s, spawnpoint );
+ SV_SpawnServer(&cm, s, spawnpoint);
}
/*
@@ -319,13 +326,14 @@ SV_DemoMap_f
Puts the server in demo mode on a specific map/cinematic
==================
*/
-static void SV_DemoMap_f( void ) {
- Com_Printf( "'%s' command is no longer supported.\n", Cmd_Argv( 0 ) );
+static void SV_DemoMap_f(void)
+{
+ Com_Printf("'%s' command is no longer supported.\n", Cmd_Argv(0));
#if USE_CLIENT
- Com_Printf( "To play a client demo, use 'demo' command instead.\n" );
+ Com_Printf("To play a client demo, use 'demo' command instead.\n");
#endif
#if USE_MVD_CLIENT
- Com_Printf( "To play a MVD, use 'mvdplay' command.\n" );
+ Com_Printf("To play a MVD, use 'mvdplay' command.\n");
#endif
}
@@ -347,24 +355,25 @@ Clears the archived maps, plays the inter.cin cinematic, then
goes to map jail.bsp.
==================
*/
-static void SV_GameMap_f( void ) {
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <mapname>\n", Cmd_Argv( 0 ) );
+static void SV_GameMap_f(void)
+{
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <mapname>\n", Cmd_Argv(0));
return;
}
#if !USE_CLIENT
// admin option to reload the game DLL or entire server
- if( sv_recycle->integer > 0 ) {
- if( sv_recycle->integer > 1 ) {
- Com_Quit( NULL, ERR_RECONNECT );
+ if (sv_recycle->integer > 0) {
+ if (sv_recycle->integer > 1) {
+ Com_Quit(NULL, ERR_RECONNECT);
}
- SV_Map( 1, qtrue );
+ SV_Map(1, qtrue);
return;
}
#endif
-
- SV_Map( 1, qfalse );
+
+ SV_Map(1, qfalse);
}
/*
@@ -375,67 +384,68 @@ Goes directly to a given map without any savegame archiving.
For development work
==================
*/
-static void SV_Map_f( void ) {
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <mapname>\n", Cmd_Argv( 0 ) );
+static void SV_Map_f(void)
+{
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <mapname>\n", Cmd_Argv(0));
return;
}
- if( sv.state == ss_game &&
+ if (sv.state == ss_game &&
sv_allow_map->integer != 1 &&
#if !USE_CLIENT
sv_recycle->integer == 0 &&
#endif
Cvar_CountLatchedVars() == 0 &&
- strcmp( Cmd_Argv( 2 ), "force" ) != 0 )
- {
- if( sv_allow_map->integer == 0 ) {
+ strcmp(Cmd_Argv(2), "force") != 0) {
+ if (sv_allow_map->integer == 0) {
static qboolean warned;
Com_Printf(
"Using '%s' command will cause full server restart, "
"which is likely not what you want. Use 'gamemap' "
- "command for changing maps.\n", Cmd_Argv( 0 ) );
- if( !warned ) {
+ "command for changing maps.\n", Cmd_Argv(0));
+ if (!warned) {
Com_Printf(
"(You can set 'sv_allow_map' to 1 "
- "if you wish to disable this check.)\n" );
+ "if you wish to disable this check.)\n");
warned = qtrue;
}
return;
}
- SV_Map( 1, qfalse );
+ SV_Map(1, qfalse);
return;
}
- SV_Map( 1, qtrue );
+ SV_Map(1, qtrue);
}
-static void SV_Map_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- FS_File_g( "maps", ".bsp", FS_SEARCH_STRIPEXT, ctx );
+static void SV_Map_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ FS_File_g("maps", ".bsp", FS_SEARCH_STRIPEXT, ctx);
}
}
-static void SV_DumpEnts_f( void ) {
+static void SV_DumpEnts_f(void)
+{
bsp_t *c = sv.cm.cache;
char buffer[MAX_OSPATH];
- if( !c || !c->entitystring ) {
- Com_Printf( "No map loaded.\n" );
+ if (!c || !c->entitystring) {
+ Com_Printf("No map loaded.\n");
return;
}
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- if( FS_EasyWriteFile( buffer, sizeof( buffer ), FS_MODE_WRITE,
- "maps/", Cmd_Argv( 1 ), ".ent", c->entitystring, c->numentitychars ) )
- {
- Com_Printf( "Dumped entity string to %s\n", buffer );
+ if (FS_EasyWriteFile(buffer, sizeof(buffer), FS_MODE_WRITE,
+ "maps/", Cmd_Argv(1), ".ent", c->entitystring, c->numentitychars)) {
+ Com_Printf("Dumped entity string to %s\n", buffer);
}
}
@@ -448,34 +458,35 @@ SV_Kick_f
Kick a user off of the server
==================
*/
-static void SV_Kick_f( void ) {
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+static void SV_Kick_f(void)
+{
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <userid>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <userid>\n", Cmd_Argv(0));
return;
}
- if( !SV_SetPlayer() )
+ if (!SV_SetPlayer())
return;
- SV_DropClient( sv_client, "?was kicked" );
+ SV_DropClient(sv_client, "?was kicked");
sv_client->lastmessage = svs.realtime; // min case there is a funny zombie
// optionally ban their IP address
- if( !strcmp( Cmd_Argv( 0 ), "kickban" ) ) {
+ if (!strcmp(Cmd_Argv(0), "kickban")) {
netadr_t *addr = &sv_client->netchan->remote_address;
- if( addr->type == NA_IP ) {
- addrmatch_t *match = Z_Malloc( sizeof( *match ) );
+ if (addr->type == NA_IP) {
+ addrmatch_t *match = Z_Malloc(sizeof(*match));
match->addr.u32 = addr->ip.u32;
match->mask = 0xffffffffU;
match->hits = 0;
match->time = 0;
match->comment[0] = 0;
- List_Append( &sv_banlist, &match->entry );
+ List_Append(&sv_banlist, &match->entry);
}
}
@@ -483,110 +494,115 @@ static void SV_Kick_f( void ) {
sv_player = NULL;
}
-static void dump_clients( void ) {
+static void dump_clients(void)
+{
client_t *client;
Com_Printf(
-"num score ping name lastmsg address rate pr fps\n"
-"--- ----- ---- --------------- ------- --------------------- ----- -- ---\n" );
- FOR_EACH_CLIENT( client ) {
- Com_Printf( "%3i %5i ", client->number,
- client->edict->client->ps.stats[STAT_FRAGS] );
+ "num score ping name lastmsg address rate pr fps\n"
+ "--- ----- ---- --------------- ------- --------------------- ----- -- ---\n");
+ FOR_EACH_CLIENT(client) {
+ Com_Printf("%3i %5i ", client->number,
+ client->edict->client->ps.stats[STAT_FRAGS]);
- switch( client->state ) {
+ switch (client->state) {
case cs_zombie:
- Com_Printf( "ZMBI " );
+ Com_Printf("ZMBI ");
break;
case cs_assigned:
- Com_Printf( "ASGN " );
+ Com_Printf("ASGN ");
break;
case cs_connected:
case cs_primed:
- if( client->download ) {
- Com_Printf( "DNLD " );
- } else if( client->http_download ) {
- Com_Printf( "HTTP " );
- } else if( client->state == cs_connected ) {
- Com_Printf( "CNCT " );
+ if (client->download) {
+ Com_Printf("DNLD ");
+ } else if (client->http_download) {
+ Com_Printf("HTTP ");
+ } else if (client->state == cs_connected) {
+ Com_Printf("CNCT ");
} else {
- Com_Printf( "PRIM " );
+ Com_Printf("PRIM ");
}
break;
default:
- Com_Printf( "%4i ", client->ping < 9999 ? client->ping : 9999 );
+ Com_Printf("%4i ", client->ping < 9999 ? client->ping : 9999);
break;
}
- Com_Printf( "%-15.15s ", client->name );
- Com_Printf( "%7u ", svs.realtime - client->lastmessage );
- Com_Printf( "%-21s ", NET_AdrToString(
- &client->netchan->remote_address ) );
- Com_Printf( "%5"PRIz" ", client->rate );
- Com_Printf( "%2i ", client->protocol );
- Com_Printf( "%3i ", client->fps );
- Com_Printf( "\n" );
+ Com_Printf("%-15.15s ", client->name);
+ Com_Printf("%7u ", svs.realtime - client->lastmessage);
+ Com_Printf("%-21s ", NET_AdrToString(
+ &client->netchan->remote_address));
+ Com_Printf("%5"PRIz" ", client->rate);
+ Com_Printf("%2i ", client->protocol);
+ Com_Printf("%3i ", client->fps);
+ Com_Printf("\n");
}
}
-static void dump_versions( void ) {
+static void dump_versions(void)
+{
client_t *client;
Com_Printf(
-"num name version\n"
-"--- --------------- -----------------------------------------\n" );
+ "num name version\n"
+ "--- --------------- -----------------------------------------\n");
- FOR_EACH_CLIENT( client ) {
- Com_Printf( "%3i %-15.15s %-40.40s\n",
- client->number, client->name,
- client->versionString ? client->versionString : "-" );
+ FOR_EACH_CLIENT(client) {
+ Com_Printf("%3i %-15.15s %-40.40s\n",
+ client->number, client->name,
+ client->versionString ? client->versionString : "-");
}
}
-static void dump_downloads( void ) {
+static void dump_downloads(void)
+{
client_t *client;
int size, percent;
char *name;
Com_Printf(
-"num name download size done\n"
-"--- --------------- ---------------------------------------- ------- ----\n" );
+ "num name download size done\n"
+ "--- --------------- ---------------------------------------- ------- ----\n");
- FOR_EACH_CLIENT( client ) {
- if( client->download ) {
+ FOR_EACH_CLIENT(client) {
+ if (client->download) {
name = client->downloadname;
size = client->downloadsize;
- if( !size )
+ if (!size)
size = 1;
- percent = client->downloadcount*100/size;
- } else if( client->http_download ) {
+ percent = client->downloadcount * 100 / size;
+ } else if (client->http_download) {
name = "<HTTP download>";
size = percent = 0;
} else {
continue;
}
- Com_Printf( "%3i %-15.15s %-40.40s %-7d %3d%%\n",
- client->number, client->name, name, size, percent );
+ Com_Printf("%3i %-15.15s %-40.40s %-7d %3d%%\n",
+ client->number, client->name, name, size, percent);
}
}
-static void dump_time( void ) {
+static void dump_time(void)
+{
client_t *client;
char buffer[MAX_QPATH];
- time_t clock = time( NULL );
+ time_t clock = time(NULL);
Com_Printf(
-"num name time\n"
-"--- --------------- --------\n" );
+ "num name time\n"
+ "--- --------------- --------\n");
- FOR_EACH_CLIENT( client ) {
- Com_TimeDiff( buffer, sizeof( buffer ),
- &client->connect_time, clock );
- Com_Printf( "%3i %-15.15s %s\n",
- client->number, client->name, buffer );
+ FOR_EACH_CLIENT(client) {
+ Com_TimeDiff(buffer, sizeof(buffer),
+ &client->connect_time, clock);
+ Com_Printf("%3i %-15.15s %s\n",
+ client->number, client->name, buffer);
}
}
-static void dump_lag( void ) {
+static void dump_lag(void)
+{
client_t *cl;
#ifdef USE_PACKETDUP
@@ -600,56 +616,58 @@ static void dump_lag( void ) {
#endif
Com_Printf(
-"num name PLs2c PLc2s Rmin Ravg Rmax"PD1"\n"
-"--- --------------- ----- ----- ---- ---- ----"PD2"\n" );
+ "num name PLs2c PLc2s Rmin Ravg Rmax"PD1"\n"
+ "--- --------------- ----- ----- ---- ---- ----"PD2"\n");
- FOR_EACH_CLIENT( cl ) {
- Com_Printf( "%3i %-15.15s %5.2f %5.2f %4d %4d %4d"PD3"\n",
- cl->number, cl->name, PL_S2C( cl ), PL_C2S( cl ),
- cl->min_ping, AVG_PING( cl ), cl->max_ping
+ FOR_EACH_CLIENT(cl) {
+ Com_Printf("%3i %-15.15s %5.2f %5.2f %4d %4d %4d"PD3"\n",
+ cl->number, cl->name, PL_S2C(cl), PL_C2S(cl),
+ cl->min_ping, AVG_PING(cl), cl->max_ping
#ifdef USE_PACKETDUP
- , cl->numpackets - 1
+ , cl->numpackets - 1
#endif
- );
+ );
}
}
-static void dump_protocols( void ) {
+static void dump_protocols(void)
+{
client_t *cl;
Com_Printf(
-"num name major minor msglen zlib chan\n"
-"--- --------------- ----- ----- ------ ---- ----\n" );
+ "num name major minor msglen zlib chan\n"
+ "--- --------------- ----- ----- ------ ---- ----\n");
- FOR_EACH_CLIENT( cl ) {
- Com_Printf( "%3i %-15.15s %5d %5d %6"PRIz" %s %s\n",
- cl->number, cl->name, cl->protocol, cl->version,
- cl->netchan->maxpacketlen,
- cl->has_zlib ? "yes" : "no ",
- cl->netchan->type ? "new" : "old" );
+ FOR_EACH_CLIENT(cl) {
+ Com_Printf("%3i %-15.15s %5d %5d %6"PRIz" %s %s\n",
+ cl->number, cl->name, cl->protocol, cl->version,
+ cl->netchan->maxpacketlen,
+ cl->has_zlib ? "yes" : "no ",
+ cl->netchan->type ? "new" : "old");
}
}
-static void dump_settings( void ) {
+static void dump_settings(void)
+{
client_t *cl;
char opt[8];
Com_Printf(
-"num name proto options upd fps\n"
-"--- --------------- ----- ------- --- ---\n" );
+ "num name proto options upd fps\n"
+ "--- --------------- ----- ------- --- ---\n");
opt[6] = ' ';
opt[7] = 0;
- FOR_EACH_CLIENT( cl ) {
+ FOR_EACH_CLIENT(cl) {
opt[0] = cl->settings[CLS_NOGUN] ? 'G' : ' ';
opt[1] = cl->settings[CLS_NOBLEND] ? 'B' : ' ';
opt[2] = cl->settings[CLS_RECORDING] ? 'R' : ' ';
opt[3] = cl->settings[CLS_NOGIBS] ? 'I' : ' ';
opt[4] = cl->settings[CLS_NOFOOTSTEPS] ? 'F' : ' ';
opt[5] = cl->settings[CLS_NOPREDICT] ? 'P' : ' ';
- Com_Printf( "%3i %-15.15s %5d %s %3d %3d\n",
- cl->number, cl->name, cl->protocol, opt,
- cl->settings[CLS_PLAYERUPDATES], cl->settings[CLS_FPS] );
+ Com_Printf("%3i %-15.15s %5d %s %3d %3d\n",
+ cl->number, cl->name, cl->protocol, opt,
+ cl->settings[CLS_PLAYERUPDATES], cl->settings[CLS_FPS]);
}
}
@@ -658,34 +676,35 @@ static void dump_settings( void ) {
SV_Status_f
================
*/
-static void SV_Status_f( void ) {
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+static void SV_Status_f(void)
+{
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( sv.name[0] ) {
- Com_Printf( "Current map: %s\n\n", sv.name );
+ if (sv.name[0]) {
+ Com_Printf("Current map: %s\n\n", sv.name);
}
- if( LIST_EMPTY( &sv_clientlist ) ) {
- Com_Printf( "No UDP clients.\n" );
+ if (LIST_EMPTY(&sv_clientlist)) {
+ Com_Printf("No UDP clients.\n");
} else {
- if( Cmd_Argc() > 1 ) {
- char *w = Cmd_Argv( 1 );
- switch( *w ) {
- case 't': dump_time(); break;
- case 'd': dump_downloads(); break;
- case 'l': dump_lag(); break;
- case 'p': dump_protocols(); break;
- case 's': dump_settings(); break;
- default: dump_versions(); break;
+ if (Cmd_Argc() > 1) {
+ char *w = Cmd_Argv(1);
+ switch (*w) {
+ case 't': dump_time(); break;
+ case 'd': dump_downloads(); break;
+ case 'l': dump_lag(); break;
+ case 'p': dump_protocols(); break;
+ case 's': dump_settings(); break;
+ default: dump_versions(); break;
}
} else {
dump_clients();
}
}
- Com_Printf( "\n" );
+ Com_Printf("\n");
#if USE_MVD_SERVER
SV_MvdStatus_f();
@@ -697,29 +716,30 @@ static void SV_Status_f( void ) {
SV_ConSay_f
==================
*/
-static void SV_ConSay_f( void ) {
+static void SV_ConSay_f(void)
+{
client_t *client;
char *s;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <raw text>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <raw text>\n", Cmd_Argv(0));
return;
}
s = Cmd_RawArgs();
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_spawned )
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_spawned)
continue;
- SV_ClientPrintf( client, PRINT_CHAT, "console: %s\n", s );
+ SV_ClientPrintf(client, PRINT_CHAT, "console: %s\n", s);
}
- if( Com_IsDedicated() ) {
- Com_LPrintf( PRINT_TALK, "console: %s\n", s );
+ if (Com_IsDedicated()) {
+ Com_LPrintf(PRINT_TALK, "console: %s\n", s);
}
}
@@ -729,8 +749,9 @@ static void SV_ConSay_f( void ) {
SV_Heartbeat_f
==================
*/
-static void SV_Heartbeat_f( void ) {
- svs.last_heartbeat = svs.realtime - HEARTBEAT_SECONDS*1000;
+static void SV_Heartbeat_f(void)
+{
+ svs.last_heartbeat = svs.realtime - HEARTBEAT_SECONDS * 1000;
}
@@ -741,40 +762,42 @@ SV_Serverinfo_f
Examine or change the serverinfo string
===========
*/
-static void SV_Serverinfo_f( void ) {
+static void SV_Serverinfo_f(void)
+{
char serverinfo[MAX_INFO_STRING];
- Cvar_BitInfo( serverinfo, CVAR_SERVERINFO );
+ Cvar_BitInfo(serverinfo, CVAR_SERVERINFO);
- Com_Printf( "Server info settings:\n" );
- Info_Print( serverinfo );
+ Com_Printf("Server info settings:\n");
+ Info_Print(serverinfo);
}
-void SV_PrintMiscInfo( void ) {
+void SV_PrintMiscInfo(void)
+{
char buffer[MAX_QPATH];
- Com_Printf( "version %s\n",
- sv_client->versionString ? sv_client->versionString : "-" );
- Com_Printf( "protocol (maj/min) %d/%d\n",
- sv_client->protocol, sv_client->version );
- Com_Printf( "maxmsglen %"PRIz"\n", sv_client->netchan->maxpacketlen );
- Com_Printf( "zlib support %s\n", sv_client->has_zlib ? "yes" : "no" );
- Com_Printf( "netchan type %s\n", sv_client->netchan->type ? "new" : "old" );
- Com_Printf( "ping %d\n", sv_client->ping );
- Com_Printf( "movement fps %d\n", sv_client->fps );
+ Com_Printf("version %s\n",
+ sv_client->versionString ? sv_client->versionString : "-");
+ Com_Printf("protocol (maj/min) %d/%d\n",
+ sv_client->protocol, sv_client->version);
+ Com_Printf("maxmsglen %"PRIz"\n", sv_client->netchan->maxpacketlen);
+ Com_Printf("zlib support %s\n", sv_client->has_zlib ? "yes" : "no");
+ Com_Printf("netchan type %s\n", sv_client->netchan->type ? "new" : "old");
+ Com_Printf("ping %d\n", sv_client->ping);
+ Com_Printf("movement fps %d\n", sv_client->fps);
#if USE_FPS
- Com_Printf( "update rate %d\n", sv_client->settings[CLS_FPS] );
+ Com_Printf("update rate %d\n", sv_client->settings[CLS_FPS]);
#endif
- Com_Printf( "RTT (min/avg/max) %d/%d/%d ms\n",
- sv_client->min_ping, AVG_PING( sv_client ), sv_client->max_ping );
- Com_Printf( "PL server to client %.2f%% (approx)\n", PL_S2C( sv_client ) );
- Com_Printf( "PL client to server %.2f%%\n", PL_C2S( sv_client ) );
+ Com_Printf("RTT (min/avg/max) %d/%d/%d ms\n",
+ sv_client->min_ping, AVG_PING(sv_client), sv_client->max_ping);
+ Com_Printf("PL server to client %.2f%% (approx)\n", PL_S2C(sv_client));
+ Com_Printf("PL client to server %.2f%%\n", PL_C2S(sv_client));
#ifdef USE_PACKETDUP
- Com_Printf( "packetdup %d\n", sv_client->numpackets - 1 );
+ Com_Printf("packetdup %d\n", sv_client->numpackets - 1);
#endif
- Com_TimeDiff( buffer, sizeof( buffer ),
- &sv_client->connect_time, time( NULL ) );
- Com_Printf( "connection time %s\n", buffer );
+ Com_TimeDiff(buffer, sizeof(buffer),
+ &sv_client->connect_time, time(NULL));
+ Com_Printf("connection time %s\n", buffer);
}
/*
@@ -784,26 +807,27 @@ SV_DumpUser_f
Examine all a users info strings
===========
*/
-static void SV_DumpUser_f( void ) {
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+static void SV_DumpUser_f(void)
+{
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <userid>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <userid>\n", Cmd_Argv(0));
return;
}
- if( !SV_SetPlayer() )
+ if (!SV_SetPlayer())
return;
- Com_Printf( "\nuserinfo\n" );
- Com_Printf( "--------\n" );
- Info_Print( sv_client->userinfo );
+ Com_Printf("\nuserinfo\n");
+ Com_Printf("--------\n");
+ Info_Print(sv_client->userinfo);
- Com_Printf( "\nmiscinfo\n" );
- Com_Printf( "--------\n" );
+ Com_Printf("\nmiscinfo\n");
+ Com_Printf("--------\n");
SV_PrintMiscInfo();
sv_client = NULL;
@@ -817,23 +841,24 @@ SV_Stuff_f
Stuff raw command string to the client.
==================
*/
-static void SV_Stuff_f( void ) {
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+static void SV_Stuff_f(void)
+{
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <userid> <raw text>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <userid> <raw text>\n", Cmd_Argv(0));
return;
}
- if( !SV_SetPlayer() )
+ if (!SV_SetPlayer())
return;
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( Cmd_RawArgsFrom( 2 ) );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(Cmd_RawArgsFrom(2));
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
sv_client = NULL;
sv_player = NULL;
@@ -846,59 +871,61 @@ SV_Stuff_f
Stuff raw command string to all clients.
==================
*/
-static void SV_Stuffall_f( void ) {
+static void SV_Stuffall_f(void)
+{
client_t *client;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <raw text>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <raw text>\n", Cmd_Argv(0));
return;
}
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( Cmd_RawArgsFrom( 1 ) );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(Cmd_RawArgsFrom(1));
- FOR_EACH_CLIENT( client ) {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ FOR_EACH_CLIENT(client) {
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-static void SV_PickClient_f( void ) {
+static void SV_PickClient_f(void)
+{
char *s;
netadr_t address;
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- if( sv_maxclients->integer == 1 ) {
- Com_Printf( "Single player server running.\n" );
+ if (sv_maxclients->integer == 1) {
+ Com_Printf("Single player server running.\n");
return;
}
- if ( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <address>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <address>\n", Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- if ( !NET_StringToAdr( s, &address, 0 ) ) {
- Com_Printf( "Bad client address: %s\n", s );
+ s = Cmd_Argv(1);
+ if (!NET_StringToAdr(s, &address, 0)) {
+ Com_Printf("Bad client address: %s\n", s);
return;
}
- if ( address.port == 0 ) {
- Com_Printf( "Please specify client port explicitly.\n" );
+ if (address.port == 0) {
+ Com_Printf("Please specify client port explicitly.\n");
return;
}
- OOB_PRINT( NS_SERVER, &address, "passive_connect\n" );
+ OOB_PRINT(NS_SERVER, &address, "passive_connect\n");
}
@@ -909,13 +936,14 @@ SV_KillServer_f
Kick everyone off, possibly in preparation for a new game
===============
*/
-static void SV_KillServer_f( void ) {
- if( !svs.initialized ) {
- Com_Printf( "No server running.\n" );
+static void SV_KillServer_f(void)
+{
+ if (!svs.initialized) {
+ Com_Printf("No server running.\n");
return;
}
- SV_Shutdown( "Server was killed.\n", ERR_DISCONNECT );
+ SV_Shutdown("Server was killed.\n", ERR_DISCONNECT);
}
/*
@@ -925,314 +953,331 @@ SV_ServerCommand_f
Let the game dll handle a command
===============
*/
-static void SV_ServerCommand_f( void ) {
- if( !ge ) {
- Com_Printf( "No game loaded.\n" );
+static void SV_ServerCommand_f(void)
+{
+ if (!ge) {
+ Com_Printf("No game loaded.\n");
return;
}
ge->ServerCommand();
}
-// ( ip & mask ) == ( addr & mask )
+// (ip & mask) == (addr & mask)
// bits = 32 --> mask = 255.255.255.255
// bits = 24 --> mask = 255.255.255.0
-static qboolean parse_mask( const char *s, uint32_t *addr, uint32_t *mask ) {
+static qboolean parse_mask(const char *s, uint32_t *addr, uint32_t *mask)
+{
netadr_t address;
char *p;
int bits;
- p = strchr( s, '/' );
- if( p ) {
+ p = strchr(s, '/');
+ if (p) {
*p++ = 0;
- if( *p == 0 ) {
- Com_Printf( "Please specify a mask after '/'.\n" );
+ if (*p == 0) {
+ Com_Printf("Please specify a mask after '/'.\n");
return qfalse;
}
- bits = atoi( p );
- if( bits < 1 || bits > 32 ) {
- Com_Printf( "Bad mask: %d bits\n", bits );
+ bits = atoi(p);
+ if (bits < 1 || bits > 32) {
+ Com_Printf("Bad mask: %d bits\n", bits);
return qfalse;
}
} else {
bits = 32;
}
- if( !NET_StringToAdr( s, &address, 0 ) ) {
- Com_Printf( "Bad address: %s\n", s );
+ if (!NET_StringToAdr(s, &address, 0)) {
+ Com_Printf("Bad address: %s\n", s);
return qfalse;
}
*addr = address.ip.u32;
- *mask = BigLong( ~( ( 1 << ( 32 - bits ) ) - 1 ) );
+ *mask = BigLong(~((1 << (32 - bits)) - 1));
return qtrue;
}
-static size_t format_mask( addrmatch_t *match, char *buf, size_t size ) {
+static size_t format_mask(addrmatch_t *match, char *buf, size_t size)
+{
uint8_t *ip = match->addr.u8;
- uint32_t mask = BigLong( match->mask );
+ uint32_t mask = BigLong(match->mask);
int i;
- for( i = 0; i < 32; i++ ) {
- if( mask & ( 1 << i ) ) {
+ for (i = 0; i < 32; i++) {
+ if (mask & (1 << i)) {
break;
}
}
- return Q_snprintf( buf, size, "%d.%d.%d.%d/%d",
- ip[0], ip[1], ip[2], ip[3], 32 - i );
+ return Q_snprintf(buf, size, "%d.%d.%d.%d/%d",
+ ip[0], ip[1], ip[2], ip[3], 32 - i);
}
-void SV_AddMatch_f( list_t *list ) {
+void SV_AddMatch_f(list_t *list)
+{
char *s, buf[32];
addrmatch_t *match;
uint32_t addr, mask;
size_t len;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <address[/mask]> [comment]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <address[/mask]> [comment]\n", Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- if( !parse_mask( s, &addr, &mask ) ) {
+ s = Cmd_Argv(1);
+ if (!parse_mask(s, &addr, &mask)) {
return;
}
- LIST_FOR_EACH( addrmatch_t, match, list, entry ) {
- if( match->addr.u32 == addr && match->mask == mask ) {
- format_mask( match, buf, sizeof( buf ) );
- Com_Printf( "Entry %s already exists.\n", buf );
+ LIST_FOR_EACH(addrmatch_t, match, list, entry) {
+ if (match->addr.u32 == addr && match->mask == mask) {
+ format_mask(match, buf, sizeof(buf));
+ Com_Printf("Entry %s already exists.\n", buf);
return;
}
}
- s = Cmd_ArgsFrom( 2 );
- len = strlen( s );
- match = Z_Malloc( sizeof( *match ) + len );
+ s = Cmd_ArgsFrom(2);
+ len = strlen(s);
+ match = Z_Malloc(sizeof(*match) + len);
match->addr.u32 = addr;
match->mask = mask;
match->hits = 0;
match->time = 0;
- memcpy( match->comment, s, len + 1 );
- List_Append( list, &match->entry );
+ memcpy(match->comment, s, len + 1);
+ List_Append(list, &match->entry);
}
-void SV_DelMatch_f( list_t *list ) {
+void SV_DelMatch_f(list_t *list)
+{
char *s;
addrmatch_t *match, *next;
uint32_t addr, mask;
int i;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <address[/mask]|id|all>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <address[/mask]|id|all>\n", Cmd_Argv(0));
return;
}
- if( LIST_EMPTY( list ) ) {
- Com_Printf( "Address list is empty.\n" );
+ if (LIST_EMPTY(list)) {
+ Com_Printf("Address list is empty.\n");
return;
}
- s = Cmd_Argv( 1 );
- if( !strcmp( s, "all" ) ) {
- LIST_FOR_EACH_SAFE( addrmatch_t, match, next, list, entry ) {
- Z_Free( match );
+ s = Cmd_Argv(1);
+ if (!strcmp(s, "all")) {
+ LIST_FOR_EACH_SAFE(addrmatch_t, match, next, list, entry) {
+ Z_Free(match);
}
- List_Init( list );
+ List_Init(list);
return;
}
// numeric values are just slot numbers
- if( COM_IsUint( s ) ) {
- i = atoi( s );
- if( i < 1 ) {
- Com_Printf( "Bad index: %d\n", i );
+ if (COM_IsUint(s)) {
+ i = atoi(s);
+ if (i < 1) {
+ Com_Printf("Bad index: %d\n", i);
return;
}
- match = LIST_INDEX( addrmatch_t, i - 1, list, entry );
- if( match ) {
+ match = LIST_INDEX(addrmatch_t, i - 1, list, entry);
+ if (match) {
goto remove;
}
- Com_Printf( "No such index: %d\n", i );
+ Com_Printf("No such index: %d\n", i);
return;
}
- if( !parse_mask( s, &addr, &mask ) ) {
+ if (!parse_mask(s, &addr, &mask)) {
return;
}
- LIST_FOR_EACH( addrmatch_t, match, list, entry ) {
- if( match->addr.u32 == addr && match->mask == mask ) {
+ LIST_FOR_EACH(addrmatch_t, match, list, entry) {
+ if (match->addr.u32 == addr && match->mask == mask) {
remove:
- List_Remove( &match->entry );
- Z_Free( match );
+ List_Remove(&match->entry);
+ Z_Free(match);
return;
}
}
- Com_Printf( "No such entry: %s\n", s );
+ Com_Printf("No such entry: %s\n", s);
}
-void SV_ListMatches_f( list_t *list ) {
+void SV_ListMatches_f(list_t *list)
+{
addrmatch_t *match;
char last[32];
char addr[32];
int count;
- if( LIST_EMPTY( list ) ) {
- Com_Printf( "Address list is empty.\n" );
+ if (LIST_EMPTY(list)) {
+ Com_Printf("Address list is empty.\n");
return;
}
- Com_Printf( "id address/mask hits last hit comment\n"
- "-- ------------------ ---- ------------ -------\n" );
+ Com_Printf("id address/mask hits last hit comment\n"
+ "-- ------------------ ---- ------------ -------\n");
count = 1;
- LIST_FOR_EACH( addrmatch_t, match, list, entry ) {
- format_mask( match, addr, sizeof( addr ) );
- if( !match->time ) {
- strcpy( last, "never" );
+ LIST_FOR_EACH(addrmatch_t, match, list, entry) {
+ format_mask(match, addr, sizeof(addr));
+ if (!match->time) {
+ strcpy(last, "never");
} else {
- strftime( last, sizeof( last ), "%d %b %H:%M",
- localtime( &match->time ) );
+ strftime(last, sizeof(last), "%d %b %H:%M",
+ localtime(&match->time));
}
- Com_Printf( "%-2d %-18s %-4u %-12s %s\n", count, addr,
- match->hits, last, match->comment );
+ Com_Printf("%-2d %-18s %-4u %-12s %s\n", count, addr,
+ match->hits, last, match->comment);
count++;
}
}
-static void SV_AddBan_f( void ) {
- SV_AddMatch_f( &sv_banlist );
+static void SV_AddBan_f(void)
+{
+ SV_AddMatch_f(&sv_banlist);
}
-static void SV_DelBan_f( void ) {
- SV_DelMatch_f( &sv_banlist );
+static void SV_DelBan_f(void)
+{
+ SV_DelMatch_f(&sv_banlist);
}
-static void SV_ListBans_f( void ) {
- SV_ListMatches_f( &sv_banlist );
+static void SV_ListBans_f(void)
+{
+ SV_ListMatches_f(&sv_banlist);
}
-static void SV_AddBlackHole_f( void ) {
- SV_AddMatch_f( &sv_blacklist );
+static void SV_AddBlackHole_f(void)
+{
+ SV_AddMatch_f(&sv_blacklist);
}
-static void SV_DelBlackHole_f( void ) {
- SV_DelMatch_f( &sv_blacklist );
+static void SV_DelBlackHole_f(void)
+{
+ SV_DelMatch_f(&sv_blacklist);
}
-static void SV_ListBlackHoles_f( void ) {
- SV_ListMatches_f( &sv_blacklist );
+static void SV_ListBlackHoles_f(void)
+{
+ SV_ListMatches_f(&sv_blacklist);
}
-static list_t *SV_FindStuffList( void ) {
- char *s = Cmd_Argv( 1 );
+static list_t *SV_FindStuffList(void)
+{
+ char *s = Cmd_Argv(1);
- if( !strcmp( s, "connect" ) ) {
+ if (!strcmp(s, "connect")) {
return &sv_cmdlist_connect;
}
- if( !strcmp( s, "begin" ) ) {
+ if (!strcmp(s, "begin")) {
return &sv_cmdlist_begin;
}
- Com_Printf( "Unknown stuffcmd list: %s\n", s );
+ Com_Printf("Unknown stuffcmd list: %s\n", s);
return NULL;
}
-static void SV_AddStuffCmd_f( void ) {
+static void SV_AddStuffCmd_f(void)
+{
char *s;
list_t *list;
stuffcmd_t *stuff;
int len;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <list> <command>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <list> <command>\n", Cmd_Argv(0));
return;
}
- if( ( list = SV_FindStuffList() ) == NULL ) {
+ if ((list = SV_FindStuffList()) == NULL) {
return;
}
- s = Cmd_ArgsFrom( 2 );
- len = strlen( s );
- stuff = Z_Malloc( sizeof( *stuff ) + len );
+ s = Cmd_ArgsFrom(2);
+ len = strlen(s);
+ stuff = Z_Malloc(sizeof(*stuff) + len);
stuff->len = len;
- memcpy( stuff->string, s, len + 1 );
- List_Append( list, &stuff->entry );
+ memcpy(stuff->string, s, len + 1);
+ List_Append(list, &stuff->entry);
}
-static void SV_DelStuffCmd_f( void ) {
+static void SV_DelStuffCmd_f(void)
+{
list_t *list;
stuffcmd_t *stuff, *next;
char *s;
int i;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <list> <id|all>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <list> <id|all>\n", Cmd_Argv(0));
return;
}
- if( ( list = SV_FindStuffList() ) == NULL ) {
+ if ((list = SV_FindStuffList()) == NULL) {
return;
}
- if( LIST_EMPTY( list ) ) {
- Com_Printf( "No stuffcmds registered.\n" );
+ if (LIST_EMPTY(list)) {
+ Com_Printf("No stuffcmds registered.\n");
return;
}
- s = Cmd_Argv( 2 );
- if( !strcmp( s, "all" ) ) {
- LIST_FOR_EACH_SAFE( stuffcmd_t, stuff, next, list, entry ) {
- Z_Free( stuff );
+ s = Cmd_Argv(2);
+ if (!strcmp(s, "all")) {
+ LIST_FOR_EACH_SAFE(stuffcmd_t, stuff, next, list, entry) {
+ Z_Free(stuff);
}
- List_Init( list );
+ List_Init(list);
return;
}
- i = atoi( s );
- if( i < 1 ) {
- Com_Printf( "Bad stuffcmd index: %d\n", i );
+ i = atoi(s);
+ if (i < 1) {
+ Com_Printf("Bad stuffcmd index: %d\n", i);
return;
}
- stuff = LIST_INDEX( stuffcmd_t, i - 1, list, entry );
- if( !stuff ) {
- Com_Printf( "No such stuffcmd index: %d\n", i );
+ stuff = LIST_INDEX(stuffcmd_t, i - 1, list, entry);
+ if (!stuff) {
+ Com_Printf("No such stuffcmd index: %d\n", i);
return;
}
- List_Remove( &stuff->entry );
- Z_Free( stuff );
+ List_Remove(&stuff->entry);
+ Z_Free(stuff);
}
-static void SV_ListStuffCmds_f( void ) {
+static void SV_ListStuffCmds_f(void)
+{
list_t *list;
stuffcmd_t *stuff;
int count;
- if( Cmd_Argc() != 2 ) {
- Com_Printf( "Usage: %s <list>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() != 2) {
+ Com_Printf("Usage: %s <list>\n", Cmd_Argv(0));
return;
}
- if( ( list = SV_FindStuffList() ) == NULL ) {
+ if ((list = SV_FindStuffList()) == NULL) {
return;
}
- if( LIST_EMPTY( list ) ) {
- Com_Printf( "No stuffcmds registered.\n" );
+ if (LIST_EMPTY(list)) {
+ Com_Printf("No stuffcmds registered.\n");
return;
}
- Com_Printf( "id command\n"
- "-- -------\n" );
+ Com_Printf("id command\n"
+ "-- -------\n");
count = 1;
- LIST_FOR_EACH( stuffcmd_t, stuff, list, entry ) {
- Com_Printf( "%-2d %s\n", count, stuff->string );
+ LIST_FOR_EACH(stuffcmd_t, stuff, list, entry) {
+ Com_Printf("%-2d %s\n", count, stuff->string);
count++;
}
}
-static void SV_StuffCmd_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- Prompt_AddMatch( ctx, "connect" );
- Prompt_AddMatch( ctx, "begin" );
+static void SV_StuffCmd_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ Prompt_AddMatch(ctx, "connect");
+ Prompt_AddMatch(ctx, "begin");
}
}
@@ -1240,144 +1285,149 @@ static const char filteractions[FA_MAX][8] = {
"ignore", "print", "stuff", "kick"
};
-static void SV_AddFilterCmd_f( void ) {
+static void SV_AddFilterCmd_f(void)
+{
char *s, *comment;
filtercmd_t *filter;
filteraction_t action;
size_t len;
- if( Cmd_Argc() < 2 ) {
+ if (Cmd_Argc() < 2) {
usage:
- Com_Printf( "Usage: %s <command> [ignore|print|stuff|kick] [comment]\n", Cmd_Argv( 0 ) );
+ Com_Printf("Usage: %s <command> [ignore|print|stuff|kick] [comment]\n", Cmd_Argv(0));
return;
}
- if( Cmd_Argc() > 2 ) {
- s = Cmd_Argv( 2 );
- for( action = 0; action < FA_MAX; action++ ) {
- if( !strcmp( s, filteractions[action] ) ) {
+ if (Cmd_Argc() > 2) {
+ s = Cmd_Argv(2);
+ for (action = 0; action < FA_MAX; action++) {
+ if (!strcmp(s, filteractions[action])) {
break;
}
}
- if( action == FA_MAX ) {
+ if (action == FA_MAX) {
goto usage;
}
- comment = Cmd_ArgsFrom( 3 );
+ comment = Cmd_ArgsFrom(3);
} else {
action = FA_IGNORE;
comment = NULL;
}
- s = Cmd_Argv( 1 );
- LIST_FOR_EACH( filtercmd_t, filter, &sv_filterlist, entry ) {
- if( !Q_stricmp( filter->string, s ) ) {
- Com_Printf( "Filtercmd already exists: %s\n", s );
+ s = Cmd_Argv(1);
+ LIST_FOR_EACH(filtercmd_t, filter, &sv_filterlist, entry) {
+ if (!Q_stricmp(filter->string, s)) {
+ Com_Printf("Filtercmd already exists: %s\n", s);
return;
}
}
- len = strlen( s );
- filter = Z_Malloc( sizeof( *filter ) + len );
- memcpy( filter->string, s, len + 1 );
+ len = strlen(s);
+ filter = Z_Malloc(sizeof(*filter) + len);
+ memcpy(filter->string, s, len + 1);
filter->action = action;
- filter->comment = Z_CopyString( comment );
- List_Append( &sv_filterlist, &filter->entry );
+ filter->comment = Z_CopyString(comment);
+ List_Append(&sv_filterlist, &filter->entry);
}
-static void SV_AddFilterCmd_c( genctx_t *ctx, int argnum ) {
+static void SV_AddFilterCmd_c(genctx_t *ctx, int argnum)
+{
filteraction_t action;
- if( argnum == 2 ) {
- for( action = 0; action < FA_MAX; action++ ) {
- Prompt_AddMatch( ctx, filteractions[action] );
+ if (argnum == 2) {
+ for (action = 0; action < FA_MAX; action++) {
+ Prompt_AddMatch(ctx, filteractions[action]);
}
}
}
-static void SV_DelFilterCmd_f( void ) {
+static void SV_DelFilterCmd_f(void)
+{
filtercmd_t *filter, *next;
char *s;
int i;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <id|cmd|all>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <id|cmd|all>\n", Cmd_Argv(0));
return;
}
- if( LIST_EMPTY( &sv_filterlist ) ) {
- Com_Printf( "No filtercmds registered.\n" );
+ if (LIST_EMPTY(&sv_filterlist)) {
+ Com_Printf("No filtercmds registered.\n");
return;
}
- s = Cmd_Argv( 1 );
- if( !strcmp( s, "all" ) ) {
- LIST_FOR_EACH_SAFE( filtercmd_t, filter, next, &sv_filterlist, entry ) {
- Z_Free( filter->comment );
- Z_Free( filter );
+ s = Cmd_Argv(1);
+ if (!strcmp(s, "all")) {
+ LIST_FOR_EACH_SAFE(filtercmd_t, filter, next, &sv_filterlist, entry) {
+ Z_Free(filter->comment);
+ Z_Free(filter);
}
- List_Init( &sv_filterlist );
+ List_Init(&sv_filterlist);
return;
}
- if( COM_IsUint( s ) ) {
- i = atoi( s );
- if( i < 1 ) {
- Com_Printf( "Bad filtercmd index: %d\n", i );
+ if (COM_IsUint(s)) {
+ i = atoi(s);
+ if (i < 1) {
+ Com_Printf("Bad filtercmd index: %d\n", i);
return;
}
- filter = LIST_INDEX( filtercmd_t, i - 1, &sv_filterlist, entry );
- if( !filter ) {
- Com_Printf( "No such filtercmd index: %d\n", i );
+ filter = LIST_INDEX(filtercmd_t, i - 1, &sv_filterlist, entry);
+ if (!filter) {
+ Com_Printf("No such filtercmd index: %d\n", i);
return;
}
} else {
- LIST_FOR_EACH( filtercmd_t, filter, &sv_filterlist, entry ) {
- if( !Q_stricmp( filter->string, s ) ) {
+ LIST_FOR_EACH(filtercmd_t, filter, &sv_filterlist, entry) {
+ if (!Q_stricmp(filter->string, s)) {
goto remove;
}
}
- Com_Printf( "No such filtercmd string: %s\n", s );
+ Com_Printf("No such filtercmd string: %s\n", s);
return;
}
remove:
- List_Remove( &filter->entry );
- Z_Free( filter->comment );
- Z_Free( filter );
+ List_Remove(&filter->entry);
+ Z_Free(filter->comment);
+ Z_Free(filter);
}
-static void SV_DelFilterCmd_c( genctx_t *ctx, int argnum ) {
+static void SV_DelFilterCmd_c(genctx_t *ctx, int argnum)
+{
filtercmd_t *filter;
- if( argnum == 1 ) {
- if( LIST_EMPTY( &sv_filterlist ) ) {
+ if (argnum == 1) {
+ if (LIST_EMPTY(&sv_filterlist)) {
return;
}
ctx->ignorecase = qtrue;
- Prompt_AddMatch( ctx, "all" );
- LIST_FOR_EACH( filtercmd_t, filter, &sv_filterlist, entry ) {
- if( !Prompt_AddMatch( ctx, filter->string ) ) {
+ Prompt_AddMatch(ctx, "all");
+ LIST_FOR_EACH(filtercmd_t, filter, &sv_filterlist, entry) {
+ if (!Prompt_AddMatch(ctx, filter->string)) {
break;
}
}
}
}
-static void SV_ListFilterCmds_f( void ) {
+static void SV_ListFilterCmds_f(void)
+{
filtercmd_t *filter;
int count;
- if( LIST_EMPTY( &sv_filterlist ) ) {
- Com_Printf( "No filtercmds registered.\n" );
+ if (LIST_EMPTY(&sv_filterlist)) {
+ Com_Printf("No filtercmds registered.\n");
return;
}
- Com_Printf( "id command action comment\n"
- "-- ---------------- ------ -------\n" );
+ Com_Printf("id command action comment\n"
+ "-- ---------------- ------ -------\n");
count = 1;
- LIST_FOR_EACH( filtercmd_t, filter, &sv_filterlist, entry ) {
- Com_Printf( "%-2d %-16s %-6s %s\n", count,
- filter->string, filteractions[filter->action],
- filter->comment ? filter->comment : "" );
+ LIST_FOR_EACH(filtercmd_t, filter, &sv_filterlist, entry) {
+ Com_Printf("%-2d %-16s %-6s %s\n", count,
+ filter->string, filteractions[filter->action],
+ filter->comment ? filter->comment : "");
count++;
}
}
@@ -1390,18 +1440,20 @@ const cmd_option_t o_record[] = {
{ NULL }
};
-static void SV_Record_c( genctx_t *ctx, int argnum ) {
+static void SV_Record_c(genctx_t *ctx, int argnum)
+{
#if USE_MVD_CLIENT
// TODO
- if( argnum == 1 ) {
- MVD_File_g( ctx );
+ if (argnum == 1) {
+ MVD_File_g(ctx);
}
#endif
}
-static void SV_Record_f( void ) {
+static void SV_Record_f(void)
+{
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
+ if (sv.state == ss_broadcast) {
MVD_StreamedRecord_f();
return;
}
@@ -1411,9 +1463,10 @@ static void SV_Record_f( void ) {
#endif
}
-static void SV_Stop_f( void ) {
+static void SV_Stop_f(void)
+{
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
+ if (sv.state == ss_broadcast) {
MVD_StreamedStop_f();
return;
}
@@ -1475,10 +1528,11 @@ static const cmdreg_t c_server[] = {
SV_InitOperatorCommands
==================
*/
-void SV_InitOperatorCommands( void ) {
- Cmd_Register( c_server );
+void SV_InitOperatorCommands(void)
+{
+ Cmd_Register(c_server);
- if ( Com_IsDedicated() )
- Cmd_AddCommand( "say", SV_ConSay_f );
+ if (Com_IsDedicated())
+ Cmd_AddCommand("say", SV_ConSay_f);
}
-
+
diff --git a/src/sv_ents.c b/src/sv_ents.c
index 9838c66..57bd728 100644
--- a/src/sv_ents.c
+++ b/src/sv_ents.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -39,10 +39,10 @@ SV_EmitPacketEntities
Writes a delta update of an entity_state_t list to the message.
=============
*/
-static void SV_EmitPacketEntities( client_t *client,
- client_frame_t *from,
- client_frame_t *to,
- int clientEntityNum )
+static void SV_EmitPacketEntities(client_t *client,
+ client_frame_t *from,
+ client_frame_t *to,
+ int clientEntityNum)
{
entity_state_t *newent;
const entity_state_t *oldent;
@@ -50,7 +50,7 @@ static void SV_EmitPacketEntities( client_t *client,
int oldnum, newnum;
msgEsFlags_t flags;
- if( !from )
+ if (!from)
from_num_entities = 0;
else
from_num_entities = from->num_entities;
@@ -58,84 +58,85 @@ static void SV_EmitPacketEntities( client_t *client,
newindex = 0;
oldindex = 0;
oldent = newent = NULL;
- while( newindex < to->num_entities || oldindex < from_num_entities ) {
- if( newindex >= to->num_entities ) {
+ while (newindex < to->num_entities || oldindex < from_num_entities) {
+ if (newindex >= to->num_entities) {
newnum = 9999;
} else {
- i = ( to->first_entity + newindex ) % svs.num_entities;
+ i = (to->first_entity + newindex) % svs.num_entities;
newent = &svs.entities[i];
newnum = newent->number;
}
- if( oldindex >= from_num_entities ) {
+ if (oldindex >= from_num_entities) {
oldnum = 9999;
} else {
- i = ( from->first_entity + oldindex ) % svs.num_entities;
+ i = (from->first_entity + oldindex) % svs.num_entities;
oldent = &svs.entities[i];
oldnum = oldent->number;
}
- if( newnum == oldnum ) {
+ if (newnum == oldnum) {
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the entity has not changed at all
// note that players are always 'newentities' in compatibility mode,
// this updates their oldorigin always and prevents warping
flags = client->esFlags;
- if( newnum <= client->maxclients && !Q2PRO_OPTIMIZE( client ) ) {
+ if (newnum <= client->maxclients && !Q2PRO_OPTIMIZE(client)) {
flags |= MSG_ES_NEWENTITY;
}
- if( newnum == clientEntityNum ) {
+ if (newnum == clientEntityNum) {
flags |= MSG_ES_FIRSTPERSON;
- VectorCopy( oldent->origin, newent->origin );
- VectorCopy( oldent->angles, newent->angles );
+ VectorCopy(oldent->origin, newent->origin);
+ VectorCopy(oldent->angles, newent->angles);
}
- if( Q2PRO_SHORTANGLES( client, newnum ) ) {
+ if (Q2PRO_SHORTANGLES(client, newnum)) {
flags |= MSG_ES_SHORTANGLES;
}
- MSG_WriteDeltaEntity( oldent, newent, flags );
+ MSG_WriteDeltaEntity(oldent, newent, flags);
oldindex++;
newindex++;
continue;
}
- if( newnum < oldnum ) {
+ if (newnum < oldnum) {
// this is a new entity, send it from the baseline
- flags = client->esFlags|MSG_ES_FORCE|MSG_ES_NEWENTITY;
+ flags = client->esFlags | MSG_ES_FORCE | MSG_ES_NEWENTITY;
oldent = client->baselines[newnum >> SV_BASELINES_SHIFT];
- if( oldent ) {
- oldent += ( newnum & SV_BASELINES_MASK );
+ if (oldent) {
+ oldent += (newnum & SV_BASELINES_MASK);
} else {
oldent = &nullEntityState;
}
- if( newnum == clientEntityNum ) {
+ if (newnum == clientEntityNum) {
flags |= MSG_ES_FIRSTPERSON;
- VectorCopy( oldent->origin, newent->origin );
- VectorCopy( oldent->angles, newent->angles );
+ VectorCopy(oldent->origin, newent->origin);
+ VectorCopy(oldent->angles, newent->angles);
}
- if( Q2PRO_SHORTANGLES( client, newnum ) ) {
+ if (Q2PRO_SHORTANGLES(client, newnum)) {
flags |= MSG_ES_SHORTANGLES;
}
- MSG_WriteDeltaEntity( oldent, newent, flags );
+ MSG_WriteDeltaEntity(oldent, newent, flags);
newindex++;
continue;
}
- if( newnum > oldnum ) {
+ if (newnum > oldnum) {
// the old entity isn't present in the new message
- MSG_WriteDeltaEntity( oldent, NULL, MSG_ES_FORCE );
+ MSG_WriteDeltaEntity(oldent, NULL, MSG_ES_FORCE);
oldindex++;
continue;
}
}
- MSG_WriteShort( 0 ); // end of packetentities
+ MSG_WriteShort(0); // end of packetentities
}
-static client_frame_t *get_last_frame( client_t *client ) {
+static client_frame_t *get_last_frame(client_t *client)
+{
client_frame_t *frame;
- if( client->lastframe <= 0 ) {
+ if (client->lastframe <= 0) {
// client is asking for a retransmit
client->frames_nodelta++;
return NULL;
@@ -143,23 +144,23 @@ static client_frame_t *get_last_frame( client_t *client ) {
client->frames_nodelta = 0;
- if( client->framenum - client->lastframe >= UPDATE_BACKUP ) {
+ if (client->framenum - client->lastframe >= UPDATE_BACKUP) {
// client hasn't gotten a good message through in a long time
- Com_DPrintf( "%s: delta request from out-of-date packet.\n", client->name );
+ Com_DPrintf("%s: delta request from out-of-date packet.\n", client->name);
return NULL;
}
// we have a valid message to delta from
frame = &client->frames[client->lastframe & UPDATE_MASK];
- if( frame->number != client->lastframe ) {
+ if (frame->number != client->lastframe) {
// but it got never sent
- Com_DPrintf( "%s: delta request from dropped frame.\n", client->name );
+ Com_DPrintf("%s: delta request from dropped frame.\n", client->name);
return NULL;
}
- if( svs.next_entity - frame->first_entity > svs.num_entities ) {
+ if (svs.next_entity - frame->first_entity > svs.num_entities) {
// but entities are too old
- Com_DPrintf( "%s: delta request from out-of-date entities.\n", client->name );
+ Com_DPrintf("%s: delta request from out-of-date entities.\n", client->name);
return NULL;
}
@@ -171,7 +172,8 @@ static client_frame_t *get_last_frame( client_t *client ) {
SV_WriteFrameToClient_Default
==================
*/
-void SV_WriteFrameToClient_Default( client_t *client ) {
+void SV_WriteFrameToClient_Default(client_t *client)
+{
client_frame_t *frame, *oldframe;
player_state_t *oldstate;
int lastframe;
@@ -180,8 +182,8 @@ void SV_WriteFrameToClient_Default( client_t *client ) {
frame = &client->frames[client->framenum & UPDATE_MASK];
// this is the frame we are delta'ing from
- oldframe = get_last_frame( client );
- if( oldframe ) {
+ oldframe = get_last_frame(client);
+ if (oldframe) {
oldstate = &oldframe->ps;
lastframe = client->lastframe;
} else {
@@ -189,24 +191,24 @@ void SV_WriteFrameToClient_Default( client_t *client ) {
lastframe = -1;
}
- MSG_WriteByte( svc_frame );
- MSG_WriteLong( client->framenum );
- MSG_WriteLong( lastframe ); // what we are delta'ing from
- MSG_WriteByte( client->surpressCount ); // rate dropped packets
+ MSG_WriteByte(svc_frame);
+ MSG_WriteLong(client->framenum);
+ MSG_WriteLong(lastframe); // what we are delta'ing from
+ MSG_WriteByte(client->surpressCount); // rate dropped packets
client->surpressCount = 0;
client->frameflags = 0;
// send over the areabits
- MSG_WriteByte( frame->areabytes );
- MSG_WriteData( frame->areabits, frame->areabytes );
+ MSG_WriteByte(frame->areabytes);
+ MSG_WriteData(frame->areabits, frame->areabytes);
// delta encode the playerstate
- MSG_WriteByte( svc_playerinfo );
- MSG_WriteDeltaPlayerstate_Default( oldstate, &frame->ps );
-
+ MSG_WriteByte(svc_playerinfo);
+ MSG_WriteDeltaPlayerstate_Default(oldstate, &frame->ps);
+
// delta encode the entities
- MSG_WriteByte( svc_packetentities );
- SV_EmitPacketEntities( client, oldframe, frame, 0 );
+ MSG_WriteByte(svc_packetentities);
+ SV_EmitPacketEntities(client, oldframe, frame, 0);
}
/*
@@ -214,7 +216,8 @@ void SV_WriteFrameToClient_Default( client_t *client ) {
SV_WriteFrameToClient_Enhanced
==================
*/
-void SV_WriteFrameToClient_Enhanced( client_t *client ) {
+void SV_WriteFrameToClient_Enhanced(client_t *client)
+{
client_frame_t *frame, *oldframe;
player_state_t *oldstate;
uint32_t extraflags;
@@ -227,8 +230,8 @@ void SV_WriteFrameToClient_Enhanced( client_t *client ) {
frame = &client->frames[client->framenum & UPDATE_MASK];
// this is the frame we are delta'ing from
- oldframe = get_last_frame( client );
- if( oldframe ) {
+ oldframe = get_last_frame(client);
+ if (oldframe) {
oldstate = &oldframe->ps;
delta = client->framenum - client->lastframe;
} else {
@@ -237,31 +240,31 @@ void SV_WriteFrameToClient_Enhanced( client_t *client ) {
}
// first byte to be patched
- b1 = SZ_GetSpace( &msg_write, 1 );
+ b1 = SZ_GetSpace(&msg_write, 1);
- MSG_WriteLong( ( client->framenum & FRAMENUM_MASK ) | ( delta << FRAMENUM_BITS ) );
+ MSG_WriteLong((client->framenum & FRAMENUM_MASK) | (delta << FRAMENUM_BITS));
// second byte to be patched
- b2 = SZ_GetSpace( &msg_write, 1 );
+ b2 = SZ_GetSpace(&msg_write, 1);
// send over the areabits
- MSG_WriteByte( frame->areabytes );
- MSG_WriteData( frame->areabits, frame->areabytes );
+ MSG_WriteByte(frame->areabytes);
+ MSG_WriteData(frame->areabits, frame->areabytes);
// ignore some parts of playerstate if not recording demo
psFlags = 0;
- if( !client->settings[CLS_RECORDING] ) {
- if( client->settings[CLS_NOGUN] ) {
+ if (!client->settings[CLS_RECORDING]) {
+ if (client->settings[CLS_NOGUN]) {
psFlags |= MSG_PS_IGNORE_GUNFRAMES;
- if( client->settings[CLS_NOGUN] != 2 ) {
+ if (client->settings[CLS_NOGUN] != 2) {
psFlags |= MSG_PS_IGNORE_GUNINDEX;
}
}
- if( client->settings[CLS_NOBLEND] ) {
+ if (client->settings[CLS_NOBLEND]) {
psFlags |= MSG_PS_IGNORE_BLEND;
}
- if( frame->ps.pmove.pm_type < PM_DEAD ) {
- if( !( frame->ps.pmove.pm_flags & PMF_NO_PREDICTION ) ) {
+ if (frame->ps.pmove.pm_type < PM_DEAD) {
+ if (!(frame->ps.pmove.pm_flags & PMF_NO_PREDICTION)) {
psFlags |= MSG_PS_IGNORE_VIEWANGLES;
}
} else {
@@ -271,11 +274,11 @@ void SV_WriteFrameToClient_Enhanced( client_t *client ) {
}
clientEntityNum = 0;
- if( client->protocol == PROTOCOL_VERSION_Q2PRO ) {
- if( frame->ps.pmove.pm_type < PM_DEAD && !client->settings[CLS_RECORDING] ) {
+ if (client->protocol == PROTOCOL_VERSION_Q2PRO) {
+ if (frame->ps.pmove.pm_type < PM_DEAD && !client->settings[CLS_RECORDING]) {
clientEntityNum = frame->clientNum + 1;
}
- if( client->settings[CLS_NOPREDICT] ) {
+ if (client->settings[CLS_NOPREDICT]) {
psFlags |= MSG_PS_IGNORE_PREDICTION;
}
surpressed = client->frameflags;
@@ -284,36 +287,36 @@ void SV_WriteFrameToClient_Enhanced( client_t *client ) {
}
// delta encode the playerstate
- extraflags = MSG_WriteDeltaPlayerstate_Enhanced( oldstate, &frame->ps, psFlags );
+ extraflags = MSG_WriteDeltaPlayerstate_Enhanced(oldstate, &frame->ps, psFlags);
- if( client->protocol == PROTOCOL_VERSION_Q2PRO ) {
+ if (client->protocol == PROTOCOL_VERSION_Q2PRO) {
// delta encode the clientNum
- if( client->version < PROTOCOL_VERSION_Q2PRO_CLIENTNUM_FIX ) {
- if( !oldframe || frame->clientNum != oldframe->clientNum ) {
+ if (client->version < PROTOCOL_VERSION_Q2PRO_CLIENTNUM_FIX) {
+ if (!oldframe || frame->clientNum != oldframe->clientNum) {
extraflags |= EPS_CLIENTNUM;
- MSG_WriteByte( frame->clientNum );
+ MSG_WriteByte(frame->clientNum);
}
} else {
int clientNum = oldframe ? oldframe->clientNum : 0;
- if( clientNum != frame->clientNum ) {
+ if (clientNum != frame->clientNum) {
extraflags |= EPS_CLIENTNUM;
- MSG_WriteByte( frame->clientNum );
+ MSG_WriteByte(frame->clientNum);
}
}
}
// save 3 high bits of extraflags
- *b1 = svc_frame | ( ( ( extraflags & 0x70 ) << 1 ) );
+ *b1 = svc_frame | (((extraflags & 0x70) << 1));
// save 4 low bits of extraflags
- *b2 = ( surpressed & SURPRESSCOUNT_MASK ) |
- ( ( extraflags & 0x0F ) << SURPRESSCOUNT_BITS );
+ *b2 = (surpressed & SURPRESSCOUNT_MASK) |
+ ((extraflags & 0x0F) << SURPRESSCOUNT_BITS);
client->surpressCount = 0;
client->frameflags = 0;
// delta encode the entities
- SV_EmitPacketEntities( client, oldframe, frame, clientEntityNum );
+ SV_EmitPacketEntities(client, oldframe, frame, clientEntityNum);
}
/*
@@ -324,20 +327,21 @@ Build a client frame structure
=============================================================================
*/
-qboolean SV_EdictPV( cm_t *cm, edict_t *ent, byte *mask ) {
+qboolean SV_EdictPV(cm_t *cm, edict_t *ent, byte *mask)
+{
mnode_t *node;
int i, l;
- if( ent->num_clusters == -1 ) {
+ if (ent->num_clusters == -1) {
// too many leafs for individual check, go by headnode
- node = CM_NodeNum( cm, ent->headnode );
- return CM_HeadnodeVisible( node, mask );
+ node = CM_NodeNum(cm, ent->headnode);
+ return CM_HeadnodeVisible(node, mask);
}
// check individual leafs
- for( i = 0; i < ent->num_clusters; i++ ) {
+ for (i = 0; i < ent->num_clusters; i++) {
l = ent->clusternums[i];
- if( Q_IsBitSet( mask, l ) ) {
+ if (Q_IsBitSet(mask, l)) {
return qtrue;
}
}
@@ -347,41 +351,41 @@ qboolean SV_EdictPV( cm_t *cm, edict_t *ent, byte *mask ) {
#if USE_FPS
static void
-fix_old_origin( client_t *client, entity_state_t *state, edict_t *ent, int e )
+fix_old_origin(client_t *client, entity_state_t *state, edict_t *ent, int e)
{
server_entity_t *sent = &sv.entities[e];
int i, j, k;
- if( ent->s.renderfx & RF_BEAM )
+ if (ent->s.renderfx & RF_BEAM)
return;
- if( !ent->linkcount )
+ if (!ent->linkcount)
return; // not linked in anywhere
- if( sent->create_framenum >= sv.framenum ) {
+ if (sent->create_framenum >= sv.framenum) {
// created this frame. unfortunate for projectiles: they will move only
// with 1/client->framediv fraction of their normal speed on the client
return;
}
- if( state->event == EV_PLAYER_TELEPORT && !Q2PRO_OPTIMIZE( client ) ) {
+ if (state->event == EV_PLAYER_TELEPORT && !Q2PRO_OPTIMIZE(client)) {
// other clients will lerp from old_origin on EV_PLAYER_TELEPORT...
- VectorCopy( state->origin, state->old_origin );
+ VectorCopy(state->origin, state->old_origin);
return;
}
- if( sent->create_framenum > sv.framenum - client->framediv ) {
+ if (sent->create_framenum > sv.framenum - client->framediv) {
// created between client frames
- VectorCopy( sent->create_origin, state->old_origin );
+ VectorCopy(sent->create_origin, state->old_origin);
return;
}
// find the oldest valid origin
- for( i = 0; i < client->framediv - 1; i++ ) {
- j = sv.framenum - ( client->framediv - i );
+ for (i = 0; i < client->framediv - 1; i++) {
+ j = sv.framenum - (client->framediv - i);
k = j & ENT_HISTORY_MASK;
- if( sent->history[k].framenum == j ) {
- VectorCopy( sent->history[k].origin, state->old_origin );
+ if (sent->history[k].framenum == j) {
+ VectorCopy(sent->history[k].origin, state->old_origin);
return;
}
}
@@ -398,7 +402,8 @@ Decides which entities are going to be visible to the client, and
copies off the playerstat and areabits.
=============
*/
-void SV_BuildClientFrame( client_t *client ) {
+void SV_BuildClientFrame(client_t *client)
+{
int e;
vec3_t org;
edict_t *ent;
@@ -413,7 +418,7 @@ void SV_BuildClientFrame( client_t *client ) {
byte clientpvs[VIS_MAX_BYTES];
clent = client->edict;
- if( !clent->client )
+ if (!clent->client)
return; // not in game yet
// this is the frame we are creating
@@ -426,15 +431,15 @@ void SV_BuildClientFrame( client_t *client ) {
// find the client's PVS
ps = &clent->client->ps;
- VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, org );
+ VectorMA(ps->viewoffset, 0.125f, ps->pmove.origin, org);
- leaf = CM_PointLeaf( client->cm, org );
- clientarea = CM_LeafArea( leaf );
- clientcluster = CM_LeafCluster( leaf );
+ leaf = CM_PointLeaf(client->cm, org);
+ clientarea = CM_LeafArea(leaf);
+ clientcluster = CM_LeafCluster(leaf);
// calculate the visible areas
- frame->areabytes = CM_WriteAreaBits( client->cm, frame->areabits, clientarea );
- if( !frame->areabytes && client->protocol != PROTOCOL_VERSION_Q2PRO ) {
+ frame->areabytes = CM_WriteAreaBits(client->cm, frame->areabits, clientarea);
+ if (!frame->areabytes && client->protocol != PROTOCOL_VERSION_Q2PRO) {
frame->areabits[0] = 255;
frame->areabytes = 1;
}
@@ -443,82 +448,82 @@ void SV_BuildClientFrame( client_t *client ) {
frame->ps = *ps;
// grab the current clientNum
- if( g_features->integer & GMF_CLIENTNUM ) {
+ if (g_features->integer & GMF_CLIENTNUM) {
frame->clientNum = clent->client->clientNum;
} else {
frame->clientNum = client->number;
}
- CM_FatPVS( client->cm, clientpvs, org );
- BSP_ClusterVis( client->cm->cache, clientphs, clientcluster, DVIS_PHS );
+ CM_FatPVS(client->cm, clientpvs, org);
+ BSP_ClusterVis(client->cm->cache, clientphs, clientcluster, DVIS_PHS);
// build up the list of visible entities
frame->num_entities = 0;
frame->first_entity = svs.next_entity;
- for( e = 1; e < client->pool->num_edicts; e++ ) {
- ent = EDICT_POOL( client, e );
+ for (e = 1; e < client->pool->num_edicts; e++) {
+ ent = EDICT_POOL(client, e);
// ignore entities not in use
- if( !ent->inuse && ( g_features->integer & GMF_PROPERINUSE ) ) {
+ if (!ent->inuse && (g_features->integer & GMF_PROPERINUSE)) {
continue;
}
// ignore ents without visible models
- if( ent->svflags & SVF_NOCLIENT )
+ if (ent->svflags & SVF_NOCLIENT)
continue;
// ignore ents without visible models unless they have an effect
- if( !ent->s.modelindex && !ent->s.effects && !ent->s.sound ) {
- if( !ent->s.event ) {
+ if (!ent->s.modelindex && !ent->s.effects && !ent->s.sound) {
+ if (!ent->s.event) {
continue;
}
- if( ent->s.event == EV_FOOTSTEP && client->settings[CLS_NOFOOTSTEPS] ) {
+ if (ent->s.event == EV_FOOTSTEP && client->settings[CLS_NOFOOTSTEPS]) {
continue;
}
}
- if( ( ent->s.effects & EF_GIB ) && client->settings[CLS_NOGIBS] ) {
+ if ((ent->s.effects & EF_GIB) && client->settings[CLS_NOGIBS]) {
continue;
}
// ignore if not touching a PV leaf
- if( ent != clent && !sv_novis->integer ) {
+ if (ent != clent && !sv_novis->integer) {
// check area
- if( !CM_AreasConnected( client->cm, clientarea, ent->areanum ) ) {
+ if (!CM_AreasConnected(client->cm, clientarea, ent->areanum)) {
// doors can legally straddle two areas, so
// we may need to check another one
- if( !CM_AreasConnected( client->cm, clientarea, ent->areanum2 ) ) {
+ if (!CM_AreasConnected(client->cm, clientarea, ent->areanum2)) {
continue; // blocked by a door
}
}
// beams just check one point for PHS
- if( ent->s.renderfx & RF_BEAM ) {
+ if (ent->s.renderfx & RF_BEAM) {
l = ent->clusternums[0];
- if( !Q_IsBitSet( clientphs, l ) )
+ if (!Q_IsBitSet(clientphs, l))
continue;
} else {
- if( !SV_EdictPV( client->cm, ent, clientpvs ) ) {
+ if (!SV_EdictPV(client->cm, ent, clientpvs)) {
continue;
}
- if( !ent->s.modelindex ) {
+ if (!ent->s.modelindex) {
// don't send sounds if they will be attenuated away
vec3_t delta;
float len;
- VectorSubtract( org, ent->s.origin, delta );
- len = VectorLength( delta );
- if( len > 400 )
+ VectorSubtract(org, ent->s.origin, delta);
+ len = VectorLength(delta);
+ if (len > 400)
continue;
}
}
}
- if( ent->s.number != e ) {
- Com_WPrintf( "%s: fixing ent->s.number: %d to %d\n",
- __func__, ent->s.number, e );
+ if (ent->s.number != e) {
+ Com_WPrintf("%s: fixing ent->s.number: %d to %d\n",
+ __func__, ent->s.number, e);
ent->s.number = e;
}
@@ -529,32 +534,31 @@ void SV_BuildClientFrame( client_t *client ) {
#if USE_FPS
// fix old entity origins for clients not running at
// full server frame rate
- if( client->framediv != 1 )
- fix_old_origin( client, state, ent, e );
+ if (client->framediv != 1)
+ fix_old_origin(client, state, ent, e);
#endif
// clear footsteps
- if( state->event == EV_FOOTSTEP && client->settings[CLS_NOFOOTSTEPS] ) {
+ if (state->event == EV_FOOTSTEP && client->settings[CLS_NOFOOTSTEPS]) {
state->event = 0;
}
// hide POV entity from renderer, unless this is player's own entity
- if( e == frame->clientNum + 1 && ent != clent &&
- ( g_features->integer & GMF_CLIENTNUM ) && !Q2PRO_OPTIMIZE( client ) )
- {
+ if (e == frame->clientNum + 1 && ent != clent &&
+ (g_features->integer & GMF_CLIENTNUM) && !Q2PRO_OPTIMIZE(client)) {
state->modelindex = 0;
}
// don't mark players missiles as solid
- if( ent->owner == clent ) {
+ if (ent->owner == clent) {
state->solid = 0;
- } else if( client->esFlags & MSG_ES_LONGSOLID ) {
+ } else if (client->esFlags & MSG_ES_LONGSOLID) {
state->solid = sv.entities[e].solid32;
}
svs.next_entity++;
- if( ++frame->num_entities == MAX_PACKET_ENTITIES ) {
+ if (++frame->num_entities == MAX_PACKET_ENTITIES) {
break;
}
}
diff --git a/src/sv_game.c b/src/sv_game.c
index d07533c..550b512 100644
--- a/src/sv_game.c
+++ b/src/sv_game.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
game_export_t *ge;
-static void PF_configstring( int index, const char *val );
+static void PF_configstring(int index, const char *val);
/*
================
@@ -31,41 +31,45 @@ PF_FindIndex
================
*/
-static int PF_FindIndex( const char *name, int start, int max ) {
+static int PF_FindIndex(const char *name, int start, int max)
+{
char *string;
int i;
-
- if( !name || !name[0] )
+
+ if (!name || !name[0])
return 0;
- for( i = 1; i < max; i++ ) {
+ for (i = 1; i < max; i++) {
string = sv.configstrings[start + i];
- if( !string[0] ) {
+ if (!string[0]) {
break;
}
- if( !strcmp( string, name ) ) {
+ if (!strcmp(string, name)) {
return i;
}
}
- if( i == max )
- Com_Error( ERR_DROP, "PF_FindIndex: overflow" );
+ if (i == max)
+ Com_Error(ERR_DROP, "PF_FindIndex: overflow");
- PF_configstring( i + start, name );
+ PF_configstring(i + start, name);
return i;
}
-static int PF_ModelIndex (const char *name) {
- return PF_FindIndex (name, CS_MODELS, MAX_MODELS);
+static int PF_ModelIndex(const char *name)
+{
+ return PF_FindIndex(name, CS_MODELS, MAX_MODELS);
}
-static int PF_SoundIndex (const char *name) {
- return PF_FindIndex (name, CS_SOUNDS, MAX_SOUNDS);
+static int PF_SoundIndex(const char *name)
+{
+ return PF_FindIndex(name, CS_SOUNDS, MAX_SOUNDS);
}
-static int PF_ImageIndex (const char *name) {
- return PF_FindIndex (name, CS_IMAGES, MAX_IMAGES);
+static int PF_ImageIndex(const char *name)
+{
+ return PF_FindIndex(name, CS_IMAGES, MAX_IMAGES);
}
/*
@@ -76,40 +80,41 @@ Sends the contents of the mutlicast buffer to a single client.
Archived in MVD stream.
===============
*/
-static void PF_Unicast( edict_t *ent, qboolean reliable ) {
+static void PF_Unicast(edict_t *ent, qboolean reliable)
+{
client_t *client;
int clientNum;
- if( !ent ) {
+ if (!ent) {
goto clear;
}
- clientNum = NUM_FOR_EDICT( ent ) - 1;
- if( clientNum < 0 || clientNum >= sv_maxclients->integer ) {
- Com_WPrintf( "%s to a non-client %d\n", __func__, clientNum );
+ clientNum = NUM_FOR_EDICT(ent) - 1;
+ if (clientNum < 0 || clientNum >= sv_maxclients->integer) {
+ Com_WPrintf("%s to a non-client %d\n", __func__, clientNum);
goto clear;
}
client = svs.client_pool + clientNum;
- if( client->state <= cs_zombie ) {
- Com_WPrintf( "%s to a free/zombie client %d\n", __func__, clientNum );
+ if (client->state <= cs_zombie) {
+ Com_WPrintf("%s to a free/zombie client %d\n", __func__, clientNum);
goto clear;
}
- SV_ClientAddMessage( client, reliable ? MSG_RELIABLE : 0 );
+ SV_ClientAddMessage(client, reliable ? MSG_RELIABLE : 0);
- if( msg_write.data[0] == svc_disconnect ) {
+ if (msg_write.data[0] == svc_disconnect) {
// fix anti-kicking exploit for broken mods
client->drop_hack = qtrue;
goto clear;
}
#if USE_MVD_SERVER
- SV_MvdUnicast( ent, clientNum, reliable );
+ SV_MvdUnicast(ent, clientNum, reliable);
#endif
clear:
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
/*
@@ -120,47 +125,48 @@ Sends text to all active clients.
Archived in MVD stream.
=================
*/
-static void PF_bprintf( int level, const char *fmt, ... ) {
+static void PF_bprintf(int level, const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
size_t len;
int i;
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
#if USE_MVD_SERVER
- SV_MvdBroadcastPrint( level, string );
+ SV_MvdBroadcastPrint(level, string);
#endif
- MSG_WriteByte( svc_print );
- MSG_WriteByte( level );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(level);
+ MSG_WriteData(string, len + 1);
// echo to console
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// mask off high bits
- for( i = 0; i < len; i++ )
+ for (i = 0; i < len; i++)
string[i] &= 127;
- Com_Printf( "%s", string );
+ Com_Printf("%s", string);
}
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_spawned )
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_spawned)
continue;
- if( level >= client->messagelevel ) {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ if (level >= client->messagelevel) {
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
@@ -171,15 +177,16 @@ PF_dprintf
Debug print to server console.
===============
*/
-static void PF_dprintf( const char *fmt, ... ) {
+static void PF_dprintf(const char *fmt, ...)
+{
char msg[MAXPRINTMSG];
va_list argptr;
-
- va_start( argptr, fmt );
- Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
- Com_Printf( "%s", msg );
+ va_start(argptr, fmt);
+ Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
+
+ Com_Printf("%s", msg);
}
@@ -191,51 +198,52 @@ Print to a single client if the level passes.
Archived in MVD stream.
===============
*/
-static void PF_cprintf( edict_t *ent, int level, const char *fmt, ... ) {
+static void PF_cprintf(edict_t *ent, int level, const char *fmt, ...)
+{
char msg[MAX_STRING_CHARS];
va_list argptr;
int clientNum;
size_t len;
client_t *client;
- va_start( argptr, fmt );
- len = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( msg ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(msg)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- if( !ent ) {
- Com_LPrintf( level == PRINT_CHAT ? PRINT_TALK : PRINT_ALL, "%s", msg );
+ if (!ent) {
+ Com_LPrintf(level == PRINT_CHAT ? PRINT_TALK : PRINT_ALL, "%s", msg);
return;
}
- clientNum = NUM_FOR_EDICT( ent ) - 1;
- if( clientNum < 0 || clientNum >= sv_maxclients->integer ) {
- Com_Error( ERR_DROP, "%s to a non-client %d", __func__, clientNum );
+ clientNum = NUM_FOR_EDICT(ent) - 1;
+ if (clientNum < 0 || clientNum >= sv_maxclients->integer) {
+ Com_Error(ERR_DROP, "%s to a non-client %d", __func__, clientNum);
}
client = svs.client_pool + clientNum;
- if( client->state <= cs_zombie ) {
- Com_WPrintf( "%s to a free/zombie client %d\n", __func__, clientNum );
+ if (client->state <= cs_zombie) {
+ Com_WPrintf("%s to a free/zombie client %d\n", __func__, clientNum);
return;
}
- MSG_WriteByte( svc_print );
- MSG_WriteByte( level );
- MSG_WriteData( msg, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(level);
+ MSG_WriteData(msg, len + 1);
- if( level >= client->messagelevel ) {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ if (level >= client->messagelevel) {
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
#if USE_MVD_SERVER
- SV_MvdUnicast( ent, clientNum, qtrue );
+ SV_MvdUnicast(ent, clientNum, qtrue);
#endif
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
@@ -247,35 +255,36 @@ Centerprint to a single client.
Archived in MVD stream.
===============
*/
-static void PF_centerprintf( edict_t *ent, const char *fmt, ... ) {
+static void PF_centerprintf(edict_t *ent, const char *fmt, ...)
+{
char msg[MAX_STRING_CHARS];
va_list argptr;
int n;
size_t len;
- if( !ent ) {
+ if (!ent) {
return;
}
-
- n = NUM_FOR_EDICT( ent );
- if( n < 1 || n > sv_maxclients->integer ) {
- Com_WPrintf( "%s to a non-client %d\n", __func__, n - 1 );
+
+ n = NUM_FOR_EDICT(ent);
+ if (n < 1 || n > sv_maxclients->integer) {
+ Com_WPrintf("%s to a non-client %d\n", __func__, n - 1);
return;
}
- va_start( argptr, fmt );
- len = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( msg ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(msg)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_centerprint );
- MSG_WriteData( msg, len + 1 );
+ MSG_WriteByte(svc_centerprint);
+ MSG_WriteData(msg, len + 1);
- PF_Unicast( ent, qtrue );
+ PF_Unicast(ent, qtrue);
}
@@ -286,15 +295,16 @@ PF_error
Abort the server with a game error
===============
*/
-static q_noreturn void PF_error (const char *fmt, ...) {
+static q_noreturn void PF_error(const char *fmt, ...)
+{
char msg[MAXERRORMSG];
va_list argptr;
-
- va_start (argptr,fmt);
- Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end (argptr);
- Com_Error (ERR_DROP, "Game Error: %s", msg);
+ va_start(argptr, fmt);
+ Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
+
+ Com_Error(ERR_DROP, "Game Error: %s", msg);
}
@@ -305,23 +315,24 @@ PF_setmodel
Also sets mins and maxs for inline bmodels
=================
*/
-static void PF_setmodel (edict_t *ent, const char *name) {
+static void PF_setmodel(edict_t *ent, const char *name)
+{
int i;
mmodel_t *mod;
if (!name)
- Com_Error (ERR_DROP, "PF_setmodel: NULL");
+ Com_Error(ERR_DROP, "PF_setmodel: NULL");
+
+ i = PF_ModelIndex(name);
- i = PF_ModelIndex (name);
-
ent->s.modelindex = i;
// if it is an inline model, get the size information for it
- if( name[0] == '*' ) {
- mod = CM_InlineModel (&sv.cm, name);
- VectorCopy (mod->mins, ent->mins);
- VectorCopy (mod->maxs, ent->maxs);
- PF_LinkEdict (ent);
+ if (name[0] == '*') {
+ mod = CM_InlineModel(&sv.cm, name);
+ VectorCopy(mod->mins, ent->mins);
+ VectorCopy(mod->maxs, ent->maxs);
+ PF_LinkEdict(ent);
}
}
@@ -334,95 +345,98 @@ If game is actively running, broadcasts configstring change.
Archived in MVD stream.
===============
*/
-static void PF_configstring( int index, const char *val ) {
+static void PF_configstring(int index, const char *val)
+{
size_t len, maxlen;
client_t *client;
char *dst;
- if( index < 0 || index >= MAX_CONFIGSTRINGS )
- Com_Error( ERR_DROP, "%s: bad index: %d", __func__, index );
+ if (index < 0 || index >= MAX_CONFIGSTRINGS)
+ Com_Error(ERR_DROP, "%s: bad index: %d", __func__, index);
- if( sv.state == ss_dead ) {
- Com_WPrintf( "%s: not yet initialized\n", __func__ );
+ if (sv.state == ss_dead) {
+ Com_WPrintf("%s: not yet initialized\n", __func__);
return;
}
- if( !val )
+ if (!val)
val = "";
// error out entirely if it exceedes array bounds
- len = strlen( val );
- maxlen = ( MAX_CONFIGSTRINGS - index ) * MAX_QPATH;
- if( len >= maxlen ) {
- Com_Error( ERR_DROP,
- "%s: index %d overflowed: %"PRIz" > %"PRIz,
- __func__, index, len, maxlen - 1 );
+ len = strlen(val);
+ maxlen = (MAX_CONFIGSTRINGS - index) * MAX_QPATH;
+ if (len >= maxlen) {
+ Com_Error(ERR_DROP,
+ "%s: index %d overflowed: %"PRIz" > %"PRIz,
+ __func__, index, len, maxlen - 1);
}
// print a warning and truncate everything else
- maxlen = CS_SIZE( index );
- if( len >= maxlen ) {
+ maxlen = CS_SIZE(index);
+ if (len >= maxlen) {
Com_WPrintf(
"%s: index %d overflowed: %"PRIz" > %"PRIz"\n",
- __func__, index, len, maxlen - 1 );
- len = maxlen - 1;
+ __func__, index, len, maxlen - 1);
+ len = maxlen - 1;
}
dst = sv.configstrings[index];
- if( !strncmp( dst, val, len ) ) {
+ if (!strncmp(dst, val, len)) {
return;
}
// change the string in sv
- memcpy( dst, val, len );
+ memcpy(dst, val, len);
dst[len] = 0;
- if( sv.state == ss_loading ) {
+ if (sv.state == ss_loading) {
return;
}
#if USE_MVD_SERVER
- SV_MvdConfigstring( index, val, len );
+ SV_MvdConfigstring(index, val, len);
#endif
// send the update to everyone
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( index );
- MSG_WriteData( val, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(index);
+ MSG_WriteData(val, len);
+ MSG_WriteByte(0);
- FOR_EACH_CLIENT( client ) {
- if( client->state < cs_primed ) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state < cs_primed) {
continue;
}
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-static void PF_WriteFloat( float f ) {
- Com_Error( ERR_DROP, "PF_WriteFloat not implemented" );
+static void PF_WriteFloat(float f)
+{
+ Com_Error(ERR_DROP, "PF_WriteFloat not implemented");
}
-static qboolean PF_inVIS( vec3_t p1, vec3_t p2, int vis ) {
+static qboolean PF_inVIS(vec3_t p1, vec3_t p2, int vis)
+{
mleaf_t *leaf1, *leaf2;
byte mask[VIS_MAX_BYTES];
bsp_t *bsp = sv.cm.cache;
-
- if( !bsp ) {
- Com_Error( ERR_DROP, "%s: no map loaded", __func__ );
+
+ if (!bsp) {
+ Com_Error(ERR_DROP, "%s: no map loaded", __func__);
}
- leaf1 = BSP_PointLeaf( bsp->nodes, p1 );
- BSP_ClusterVis( bsp, mask, leaf1->cluster, vis );
+ leaf1 = BSP_PointLeaf(bsp->nodes, p1);
+ BSP_ClusterVis(bsp, mask, leaf1->cluster, vis);
- leaf2 = BSP_PointLeaf( bsp->nodes, p2 );
- if( leaf2->cluster == -1 )
+ leaf2 = BSP_PointLeaf(bsp->nodes, p2);
+ if (leaf2->cluster == -1)
return qfalse;
- if( !Q_IsBitSet( mask, leaf2->cluster ) )
+ if (!Q_IsBitSet(mask, leaf2->cluster))
return qfalse;
- if( !CM_AreasConnected( &sv.cm, leaf1->area, leaf2->area ) )
+ if (!CM_AreasConnected(&sv.cm, leaf1->area, leaf2->area))
return qfalse; // a door blocks it
return qtrue;
}
@@ -434,8 +448,9 @@ PF_inPVS
Also checks portalareas so that doors block sight
=================
*/
-static qboolean PF_inPVS( vec3_t p1, vec3_t p2 ) {
- return PF_inVIS( p1, p2, DVIS_PVS );
+static qboolean PF_inPVS(vec3_t p1, vec3_t p2)
+{
+ return PF_inVIS(p1, p2, DVIS_PVS);
}
/*
@@ -445,11 +460,12 @@ PF_inPHS
Also checks portalareas so that doors block sound
=================
*/
-static qboolean PF_inPHS( vec3_t p1, vec3_t p2 ) {
- return PF_inVIS( p1, p2, DVIS_PHS );
+static qboolean PF_inPHS(vec3_t p1, vec3_t p2)
+{
+ return PF_inVIS(p1, p2, DVIS_PHS);
}
-/*
+/*
==================
PF_StartSound
@@ -475,20 +491,21 @@ If origin is NULL, the origin is determined from the entity origin
or the midpoint of the entity box for bmodels.
==================
*/
+
#define CHECK_PARAMS \
- if( volume < 0 || volume > 1.0 ) \
- Com_Error( ERR_DROP, "%s: volume = %f", __func__, volume ); \
- if( attenuation < 0 || attenuation > 4 ) \
- Com_Error( ERR_DROP, "%s: attenuation = %f", __func__, attenuation ); \
- if( timeofs < 0 || timeofs > 0.255 ) \
- Com_Error( ERR_DROP, "%s: timeofs = %f", __func__, timeofs ); \
- if( soundindex < 0 || soundindex >= MAX_SOUNDS ) \
- Com_Error( ERR_DROP, "%s: soundindex = %d", __func__, soundindex );
-
-static void PF_StartSound( edict_t *edict, int channel,
- int soundindex, float volume,
- float attenuation, float timeofs )
-{
+ if (volume < 0 || volume > 1.0) \
+ Com_Error(ERR_DROP, "%s: volume = %f", __func__, volume); \
+ if (attenuation < 0 || attenuation > 4) \
+ Com_Error(ERR_DROP, "%s: attenuation = %f", __func__, attenuation); \
+ if (timeofs < 0 || timeofs > 0.255) \
+ Com_Error(ERR_DROP, "%s: timeofs = %f", __func__, timeofs); \
+ if (soundindex < 0 || soundindex >= MAX_SOUNDS) \
+ Com_Error(ERR_DROP, "%s: soundindex = %d", __func__, soundindex);
+
+static void PF_StartSound(edict_t *edict, int channel,
+ int soundindex, float volume,
+ float attenuation, float timeofs)
+{
int sendchan;
int flags;
int ent;
@@ -501,107 +518,107 @@ static void PF_StartSound( edict_t *edict, int channel,
message_packet_t *msg;
int i;
- if( !edict )
+ if (!edict)
return;
CHECK_PARAMS
- ent = NUM_FOR_EDICT( edict );
+ ent = NUM_FOR_EDICT(edict);
- if( ( g_features->integer & GMF_PROPERINUSE ) && !edict->inuse ) {
- Com_DPrintf( "%s: entnum not in use: %d\n", __func__, ent );
+ if ((g_features->integer & GMF_PROPERINUSE) && !edict->inuse) {
+ Com_DPrintf("%s: entnum not in use: %d\n", __func__, ent);
return;
}
- sendchan = ( ent << 3 ) | ( channel & 7 );
+ sendchan = (ent << 3) | (channel & 7);
// always send the entity number for channel overrides
flags = SND_ENT;
- if( volume != DEFAULT_SOUND_PACKET_VOLUME )
+ if (volume != DEFAULT_SOUND_PACKET_VOLUME)
flags |= SND_VOLUME;
- if( attenuation != DEFAULT_SOUND_PACKET_ATTENUATION )
+ if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
flags |= SND_ATTENUATION;
- if( timeofs )
+ if (timeofs)
flags |= SND_OFFSET;
// if the sound doesn't attenuate,send it to everyone
// (global radio chatter, voiceovers, etc)
- if( attenuation == ATTN_NONE ) {
+ if (attenuation == ATTN_NONE) {
channel |= CHAN_NO_PHS_ADD;
}
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
// do not send sounds to connecting clients
- if( client->state != cs_spawned || client->download || client->nodata ) {
- continue;
+ if (client->state != cs_spawned || client->download || client->nodata) {
+ continue;
}
// PHS cull this sound
- if( !( channel & CHAN_NO_PHS_ADD ) ) {
+ if (!(channel & CHAN_NO_PHS_ADD)) {
// get client viewpos
ps = &client->edict->client->ps;
- VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, origin );
- leaf = CM_PointLeaf( &sv.cm, origin );
- area = CM_LeafArea( leaf );
- if( !CM_AreasConnected( &sv.cm, area, edict->areanum ) ) {
+ VectorMA(ps->viewoffset, 0.125f, ps->pmove.origin, origin);
+ leaf = CM_PointLeaf(&sv.cm, origin);
+ area = CM_LeafArea(leaf);
+ if (!CM_AreasConnected(&sv.cm, area, edict->areanum)) {
// doors can legally straddle two areas, so
// we may need to check another one
- if( !edict->areanum2 || !CM_AreasConnected( &sv.cm, area, edict->areanum2 ) ) {
+ if (!edict->areanum2 || !CM_AreasConnected(&sv.cm, area, edict->areanum2)) {
continue; // blocked by a door
}
}
- BSP_ClusterVis( sv.cm.cache, mask, leaf->cluster, DVIS_PHS );
- if( !SV_EdictPV( &sv.cm, edict, mask ) ) {
+ BSP_ClusterVis(sv.cm.cache, mask, leaf->cluster, DVIS_PHS);
+ if (!SV_EdictPV(&sv.cm, edict, mask)) {
continue; // not in PHS
}
}
// use the entity origin unless it is a bmodel
- if( edict->solid == SOLID_BSP ) {
- VectorAvg( edict->mins, edict->maxs, origin );
- VectorAdd( edict->s.origin, origin, origin );
+ if (edict->solid == SOLID_BSP) {
+ VectorAvg(edict->mins, edict->maxs, origin);
+ VectorAdd(edict->s.origin, origin, origin);
} else {
- VectorCopy( edict->s.origin, origin );
+ VectorCopy(edict->s.origin, origin);
}
// reliable sounds will always have position explicitly set,
// as no one gurantees reliables to be delivered in time
- if( channel & CHAN_RELIABLE ) {
- MSG_WriteByte( svc_sound );
- MSG_WriteByte( flags | SND_POS );
- MSG_WriteByte( soundindex );
-
- if( flags & SND_VOLUME )
- MSG_WriteByte( volume * 255 );
- if( flags & SND_ATTENUATION )
- MSG_WriteByte( attenuation * 64 );
- if( flags & SND_OFFSET )
- MSG_WriteByte( timeofs * 1000 );
-
- MSG_WriteShort( sendchan );
- MSG_WritePos( origin );
-
- SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
+ if (channel & CHAN_RELIABLE) {
+ MSG_WriteByte(svc_sound);
+ MSG_WriteByte(flags | SND_POS);
+ MSG_WriteByte(soundindex);
+
+ if (flags & SND_VOLUME)
+ MSG_WriteByte(volume * 255);
+ if (flags & SND_ATTENUATION)
+ MSG_WriteByte(attenuation * 64);
+ if (flags & SND_OFFSET)
+ MSG_WriteByte(timeofs * 1000);
+
+ MSG_WriteShort(sendchan);
+ MSG_WritePos(origin);
+
+ SV_ClientAddMessage(client, MSG_RELIABLE | MSG_CLEAR);
continue;
}
- if( LIST_EMPTY( &client->msg_free_list ) ) {
- Com_WPrintf( "%s: %s: out of message slots\n",
- __func__, client->name );
+ if (LIST_EMPTY(&client->msg_free_list)) {
+ Com_WPrintf("%s: %s: out of message slots\n",
+ __func__, client->name);
continue;
}
// send origin for invisible entities
- if( edict->svflags & SVF_NOCLIENT ) {
+ if (edict->svflags & SVF_NOCLIENT) {
flags |= SND_POS;
}
// default client doesn't know that bmodels have weird origins
- if( edict->solid == SOLID_BSP && client->protocol == PROTOCOL_VERSION_DEFAULT ) {
+ if (edict->solid == SOLID_BSP && client->protocol == PROTOCOL_VERSION_DEFAULT) {
flags |= SND_POS;
}
- msg = LIST_FIRST( message_packet_t, &client->msg_free_list, entry );
+ msg = LIST_FIRST(message_packet_t, &client->msg_free_list, entry);
msg->cursize = 0;
msg->flags = flags;
@@ -610,135 +627,143 @@ static void PF_StartSound( edict_t *edict, int channel,
msg->attenuation = attenuation * 64;
msg->timeofs = timeofs * 1000;
msg->sendchan = sendchan;
- for( i = 0; i < 3; i++ ) {
+ for (i = 0; i < 3; i++) {
msg->pos[i] = origin[i] * 8;
}
- List_Remove( &msg->entry );
- List_Append( &client->msg_unreliable_list, &msg->entry );
+ List_Remove(&msg->entry);
+ List_Append(&client->msg_unreliable_list, &msg->entry);
client->msg_unreliable_bytes += MAX_SOUND_PACKET;
flags &= ~SND_POS;
}
#if USE_MVD_SERVER
- SV_MvdStartSound( ent, channel, flags, soundindex,
- volume * 255, attenuation * 64, timeofs * 1000 );
+ SV_MvdStartSound(ent, channel, flags, soundindex,
+ volume * 255, attenuation * 64, timeofs * 1000);
#endif
}
-static void PF_PositionedSound( vec3_t origin, edict_t *entity, int channel,
- int soundindex, float volume,
- float attenuation, float timeofs )
-{
+static void PF_PositionedSound(vec3_t origin, edict_t *entity, int channel,
+ int soundindex, float volume,
+ float attenuation, float timeofs)
+{
int sendchan;
int flags;
int ent;
- if( !origin )
- Com_Error( ERR_DROP, "%s: NULL origin", __func__ );
+ if (!origin)
+ Com_Error(ERR_DROP, "%s: NULL origin", __func__);
CHECK_PARAMS
- ent = NUM_FOR_EDICT( entity );
+ ent = NUM_FOR_EDICT(entity);
- sendchan = ( ent << 3 ) | ( channel & 7 );
+ sendchan = (ent << 3) | (channel & 7);
// always send the entity number for channel overrides
- flags = SND_ENT|SND_POS;
- if( volume != DEFAULT_SOUND_PACKET_VOLUME )
+ flags = SND_ENT | SND_POS;
+ if (volume != DEFAULT_SOUND_PACKET_VOLUME)
flags |= SND_VOLUME;
- if( attenuation != DEFAULT_SOUND_PACKET_ATTENUATION )
+ if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
flags |= SND_ATTENUATION;
- if( timeofs )
+ if (timeofs)
flags |= SND_OFFSET;
- MSG_WriteByte( svc_sound );
- MSG_WriteByte( flags );
- MSG_WriteByte( soundindex );
+ MSG_WriteByte(svc_sound);
+ MSG_WriteByte(flags);
+ MSG_WriteByte(soundindex);
- if( flags & SND_VOLUME )
- MSG_WriteByte( volume * 255 );
- if( flags & SND_ATTENUATION )
- MSG_WriteByte( attenuation * 64 );
- if( flags & SND_OFFSET )
- MSG_WriteByte( timeofs * 1000 );
+ if (flags & SND_VOLUME)
+ MSG_WriteByte(volume * 255);
+ if (flags & SND_ATTENUATION)
+ MSG_WriteByte(attenuation * 64);
+ if (flags & SND_OFFSET)
+ MSG_WriteByte(timeofs * 1000);
- MSG_WriteShort( sendchan );
- MSG_WritePos( origin );
+ MSG_WriteShort(sendchan);
+ MSG_WritePos(origin);
// if the sound doesn't attenuate,send it to everyone
// (global radio chatter, voiceovers, etc)
- if( attenuation == ATTN_NONE || ( channel & CHAN_NO_PHS_ADD ) ) {
- if( channel & CHAN_RELIABLE ) {
- SV_Multicast( NULL, MULTICAST_ALL_R );
+ if (attenuation == ATTN_NONE || (channel & CHAN_NO_PHS_ADD)) {
+ if (channel & CHAN_RELIABLE) {
+ SV_Multicast(NULL, MULTICAST_ALL_R);
} else {
- SV_Multicast( NULL, MULTICAST_ALL );
+ SV_Multicast(NULL, MULTICAST_ALL);
}
} else {
- if( channel & CHAN_RELIABLE ) {
- SV_Multicast( origin, MULTICAST_PHS_R );
+ if (channel & CHAN_RELIABLE) {
+ SV_Multicast(origin, MULTICAST_PHS_R);
} else {
- SV_Multicast( origin, MULTICAST_PHS );
+ SV_Multicast(origin, MULTICAST_PHS);
}
}
}
-void PF_Pmove( pmove_t *pm ) {
- if( sv_client ) {
- Pmove( pm, &sv_client->pmp );
+void PF_Pmove(pmove_t *pm)
+{
+ if (sv_client) {
+ Pmove(pm, &sv_client->pmp);
} else {
- Pmove( pm, &sv_pmp );
+ Pmove(pm, &sv_pmp);
}
}
-static cvar_t *PF_cvar( const char *name, const char *value, int flags ) {
- if( flags & CVAR_EXTENDED_MASK ) {
- Com_WPrintf( "Game attemped to set extended flags on '%s', masked out.\n", name );
+static cvar_t *PF_cvar(const char *name, const char *value, int flags)
+{
+ if (flags & CVAR_EXTENDED_MASK) {
+ Com_WPrintf("Game attemped to set extended flags on '%s', masked out.\n", name);
flags &= ~CVAR_EXTENDED_MASK;
}
- return Cvar_Get( name, value, flags | CVAR_GAME );
+ return Cvar_Get(name, value, flags | CVAR_GAME);
}
-static void PF_AddCommandString( const char *string ) {
- Cbuf_AddText( &cmd_buffer, string );
+static void PF_AddCommandString(const char *string)
+{
+ Cbuf_AddText(&cmd_buffer, string);
}
-static void PF_SetAreaPortalState( int portalnum, qboolean open ) {
- if( !sv.cm.cache ) {
- Com_Error( ERR_DROP, "%s: no map loaded", __func__ );
+static void PF_SetAreaPortalState(int portalnum, qboolean open)
+{
+ if (!sv.cm.cache) {
+ Com_Error(ERR_DROP, "%s: no map loaded", __func__);
}
- CM_SetAreaPortalState( &sv.cm, portalnum, open );
+ CM_SetAreaPortalState(&sv.cm, portalnum, open);
}
-static qboolean PF_AreasConnected( int area1, int area2 ) {
- if( !sv.cm.cache ) {
- Com_Error( ERR_DROP, "%s: no map loaded", __func__ );
+static qboolean PF_AreasConnected(int area1, int area2)
+{
+ if (!sv.cm.cache) {
+ Com_Error(ERR_DROP, "%s: no map loaded", __func__);
}
- return CM_AreasConnected( &sv.cm, area1, area2 );
+ return CM_AreasConnected(&sv.cm, area1, area2);
}
-static void *PF_TagMalloc( size_t size, unsigned tag ) {
- if( tag + TAG_MAX < tag ) {
- Com_Error( ERR_FATAL, "%s: bad tag", __func__ );
+static void *PF_TagMalloc(size_t size, unsigned tag)
+{
+ if (tag + TAG_MAX < tag) {
+ Com_Error(ERR_FATAL, "%s: bad tag", __func__);
}
- if( !size ) {
+ if (!size) {
return NULL;
}
- return memset( Z_TagMalloc( size, tag + TAG_MAX ), 0, size );
+ return memset(Z_TagMalloc(size, tag + TAG_MAX), 0, size);
}
-static void PF_FreeTags( unsigned tag ) {
- if( tag + TAG_MAX < tag ) {
- Com_Error( ERR_FATAL, "%s: bad tag", __func__ );
+static void PF_FreeTags(unsigned tag)
+{
+ if (tag + TAG_MAX < tag) {
+ Com_Error(ERR_FATAL, "%s: bad tag", __func__);
}
- Z_FreeTags( tag + TAG_MAX );
+ Z_FreeTags(tag + TAG_MAX);
}
-static void PF_DebugGraph( float value, int color ) {
+static void PF_DebugGraph(float value, int color)
+{
#if (defined _DEBUG) && USE_CLIENT
- SCR_DebugGraph( value, color );
+ SCR_DebugGraph(value, color);
#endif
}
@@ -754,30 +779,32 @@ Called when either the entire server is being killed, or
it is changing to a different game directory.
===============
*/
-void SV_ShutdownGameProgs (void) {
- if( ge ) {
+void SV_ShutdownGameProgs(void)
+{
+ if (ge) {
ge->Shutdown();
ge = NULL;
}
- if( game_library ) {
- Sys_FreeLibrary( game_library );
+ if (game_library) {
+ Sys_FreeLibrary(game_library);
game_library = NULL;
}
- Cvar_Set( "g_features", "0" );
+ Cvar_Set("g_features", "0");
}
-static void *SV_LoadLibrary( const char *game ) {
+static void *SV_LoadLibrary(const char *game)
+{
char path[MAX_OSPATH];
size_t len;
- len = Q_concat( path, sizeof( path ), sys_libdir->string,
- PATH_SEP_STRING, game, PATH_SEP_STRING GAMELIB, NULL );
- if( len >= sizeof( path ) ) {
- Com_WPrintf( "Game library path length exceeded\n" );
+ len = Q_concat(path, sizeof(path), sys_libdir->string,
+ PATH_SEP_STRING, game, PATH_SEP_STRING GAMELIB, NULL);
+ if (len >= sizeof(path)) {
+ Com_WPrintf("Game library path length exceeded\n");
return NULL;
}
- return Sys_LoadLibrary( path, "GetGameAPI", &game_library );
+ return Sys_LoadLibrary(path, "GetGameAPI", &game_library);
}
/*
@@ -787,28 +814,29 @@ SV_InitGameProgs
Init the game subsystem for a new map
===============
*/
-void SV_InitGameProgs ( void ) {
+void SV_InitGameProgs(void)
+{
game_import_t import;
- game_export_t *(*entry)( game_import_t * ) = NULL;
+ game_export_t *(*entry)(game_import_t *) = NULL;
// unload anything we have now
- SV_ShutdownGameProgs ();
+ SV_ShutdownGameProgs();
// for debugging or `proxy' mods
- if( sys_forcegamelib->string[0] ) {
- entry = Sys_LoadLibrary( sys_forcegamelib->string,
- "GetGameAPI", &game_library );
+ if (sys_forcegamelib->string[0]) {
+ entry = Sys_LoadLibrary(sys_forcegamelib->string,
+ "GetGameAPI", &game_library);
}
- if( !entry ) {
+ if (!entry) {
// try game first
- if( fs_game->string[0] ) {
- entry = SV_LoadLibrary( fs_game->string );
+ if (fs_game->string[0]) {
+ entry = SV_LoadLibrary(fs_game->string);
}
- if( !entry ) {
+ if (!entry) {
// then try baseq2
- entry = SV_LoadLibrary( BASEGAME );
- if( !entry ) {
- Com_Error( ERR_DROP, "Failed to load game library" );
+ entry = SV_LoadLibrary(BASEGAME);
+ if (!entry) {
+ Com_Error(ERR_DROP, "Failed to load game library");
}
}
}
@@ -827,13 +855,13 @@ void SV_InitGameProgs ( void ) {
import.BoxEdicts = SV_AreaEdicts;
#ifdef _WIN32
#ifdef __GNUC__
- import.trace = ( sv_trace_t )SV_Trace;
+ import.trace = (sv_trace_t)SV_Trace;
#else
import.trace = SV_Trace_Native;
#endif
#else // _WIN32
- if( sv_oldgame_hack->integer ) {
- import.trace = ( sv_trace_t )SV_Trace;
+ if (sv_oldgame_hack->integer) {
+ import.trace = (sv_trace_t)SV_Trace;
} else {
import.trace = SV_Trace_Native;
}
@@ -880,21 +908,21 @@ void SV_InitGameProgs ( void ) {
import.SetAreaPortalState = PF_SetAreaPortalState;
import.AreasConnected = PF_AreasConnected;
- ge = entry( &import );
+ ge = entry(&import);
if (!ge) {
- Com_Error (ERR_DROP, "Game DLL returned NULL exports");
+ Com_Error(ERR_DROP, "Game DLL returned NULL exports");
}
if (ge->apiversion != GAME_API_VERSION) {
- Com_Error (ERR_DROP, "Game DLL is version %d, expected %d",
- ge->apiversion, GAME_API_VERSION);
+ Com_Error(ERR_DROP, "Game DLL is version %d, expected %d",
+ ge->apiversion, GAME_API_VERSION);
}
// initialize
- ge->Init ();
+ ge->Init();
// sanitize max_edicts
- if( ge->max_edicts <= sv_maxclients->integer || ge->max_edicts > MAX_EDICTS ) {
- Com_Error (ERR_DROP, "Game DLL returned bad number of max_edicts");
+ if (ge->max_edicts <= sv_maxclients->integer || ge->max_edicts > MAX_EDICTS) {
+ Com_Error(ERR_DROP, "Game DLL returned bad number of max_edicts");
}
}
diff --git a/src/sv_init.c b/src/sv_init.c
index 959cdfd..32c5c75 100644
--- a/src/sv_init.c
+++ b/src/sv_init.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,8 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
server_static_t svs; // persistant server info
server_t sv; // local server
-void SV_ClientReset( client_t *client ) {
- if( client->state < cs_connected ) {
+void SV_ClientReset(client_t *client)
+{
+ if (client->state < cs_connected) {
return;
}
@@ -35,94 +36,97 @@ void SV_ClientReset( client_t *client ) {
client->frames_nodelta = 0;
client->send_delta = 0;
client->surpressCount = 0;
- memset( &client->lastcmd, 0, sizeof( client->lastcmd ) );
+ memset(&client->lastcmd, 0, sizeof(client->lastcmd));
}
#if USE_FPS
-static void set_frame_time( void ) {
+static void set_frame_time(void)
+{
int framediv;
- if( g_features->integer & GMF_VARIABLE_FPS )
+ if (g_features->integer & GMF_VARIABLE_FPS)
framediv = sv_fps->integer / BASE_FRAMERATE;
else
framediv = 1;
- clamp( framediv, 1, MAX_FRAMEDIV );
+ clamp(framediv, 1, MAX_FRAMEDIV);
sv.framerate = framediv * BASE_FRAMERATE;
sv.frametime = BASE_FRAMETIME / framediv;
sv.framediv = framediv;
- Cvar_SetInteger( sv_fps, sv.framerate, FROM_CODE );
+ Cvar_SetInteger(sv_fps, sv.framerate, FROM_CODE);
}
#endif
#if !USE_CLIENT
-static void resolve_masters( void ) {
+static void resolve_masters(void)
+{
master_t *m;
time_t now, delta;
- now = time( NULL );
- FOR_EACH_MASTER( m ) {
+ now = time(NULL);
+ FOR_EACH_MASTER(m) {
// re-resolve valid address after one day,
// resolve invalid address after three hours
- delta = m->adr.port ? 24*60*60 : 3*60*60;
- if( now < m->last_resolved ) {
+ delta = m->adr.port ? 24 * 60 * 60 : 3 * 60 * 60;
+ if (now < m->last_resolved) {
m->last_resolved = now;
continue;
}
- if( now - m->last_resolved < delta ) {
+ if (now - m->last_resolved < delta) {
continue;
}
- if( NET_StringToAdr( m->name, &m->adr, PORT_MASTER ) ) {
- Com_DPrintf( "Master server at %s.\n", NET_AdrToString( &m->adr ) );
+ if (NET_StringToAdr(m->name, &m->adr, PORT_MASTER)) {
+ Com_DPrintf("Master server at %s.\n", NET_AdrToString(&m->adr));
} else {
- Com_WPrintf( "Couldn't resolve master: %s\n", m->name );
+ Com_WPrintf("Couldn't resolve master: %s\n", m->name);
m->adr.port = 0;
}
- m->last_resolved = now = time( NULL );
+ m->last_resolved = now = time(NULL);
}
}
#endif
// optionally load the entity string from external source
-static void override_entity_string( const char *server ) {
+static void override_entity_string(const char *server)
+{
char *path = map_override_path->string;
char buffer[MAX_QPATH], *str;
ssize_t len;
- if( !*path ) {
+ if (!*path) {
return;
}
- len = Q_concat( buffer, sizeof( buffer ), path, server, ".ent", NULL );
- if( len >= sizeof( buffer ) ) {
+ len = Q_concat(buffer, sizeof(buffer), path, server, ".ent", NULL);
+ if (len >= sizeof(buffer)) {
len = Q_ERR_NAMETOOLONG;
goto fail1;
}
- len = SV_LoadFile( buffer, ( void ** )&str );
- if( !str ) {
- if( len == Q_ERR_NOENT ) {
+ len = SV_LoadFile(buffer, (void **)&str);
+ if (!str) {
+ if (len == Q_ERR_NOENT) {
return;
}
goto fail1;
}
- if( len > MAX_MAP_ENTSTRING ) {
+ if (len > MAX_MAP_ENTSTRING) {
len = Q_ERR_FBIG;
goto fail2;
}
- Com_Printf( "Loaded entity string from %s\n", buffer );
+ Com_Printf("Loaded entity string from %s\n", buffer);
sv.entitystring = str;
return;
fail2:
- SV_FreeFile( str );
+ SV_FreeFile(str);
fail1:
- Com_EPrintf( "Couldn't load entity string from %s: %s\n",
- buffer, Q_ErrorString( len ) );
+ Com_EPrintf("Couldn't load entity string from %s: %s\n",
+ buffer, Q_ErrorString(len));
}
@@ -134,7 +138,8 @@ Change the server to a new map, taking all connected
clients along with it.
================
*/
-void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
+void SV_SpawnServer(cm_t *cm, const char *server, const char *spawnpoint)
+{
int i;
client_t *client;
@@ -142,29 +147,29 @@ void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
SCR_BeginLoadingPlaque(); // for local system
#endif
- Com_Printf( "------- Server Initialization -------\n" );
- Com_Printf( "SpawnServer: %s\n", server );
+ Com_Printf("------- Server Initialization -------\n");
+ Com_Printf("SpawnServer: %s\n", server);
// everyone needs to reconnect
- FOR_EACH_CLIENT( client ) {
- SV_ClientReset( client );
+ FOR_EACH_CLIENT(client) {
+ SV_ClientReset(client);
}
- SV_BroadcastCommand( "changing map=%s\n", server );
+ SV_BroadcastCommand("changing map=%s\n", server);
SV_SendClientMessages();
SV_SendAsyncPackets();
// free current level
- CM_FreeMap( &sv.cm );
- SV_FreeFile( sv.entitystring );
-
+ CM_FreeMap(&sv.cm);
+ SV_FreeFile(sv.entitystring);
+
// wipe the entire per-level structure
- memset( &sv, 0, sizeof( sv ) );
- sv.spawncount = ( rand() | ( rand() << 16 ) ) ^ Sys_Milliseconds();
+ memset(&sv, 0, sizeof(sv));
+ sv.spawncount = (rand() | (rand() << 16)) ^ Sys_Milliseconds();
sv.spawncount &= 0x7FFFFFFF;
// set legacy spawncounts
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
client->spawncount = sv.spawncount;
}
@@ -177,29 +182,29 @@ void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
#endif
// save name for levels that don't set message
- Q_strlcpy( sv.configstrings[CS_NAME], server, MAX_QPATH );
- Q_strlcpy( sv.name, server, sizeof( sv.name ) );
-
- if( Cvar_VariableInteger( "deathmatch" ) ) {
- sprintf( sv.configstrings[CS_AIRACCEL],
- "%d", sv_airaccelerate->integer );
+ Q_strlcpy(sv.configstrings[CS_NAME], server, MAX_QPATH);
+ Q_strlcpy(sv.name, server, sizeof(sv.name));
+
+ if (Cvar_VariableInteger("deathmatch")) {
+ sprintf(sv.configstrings[CS_AIRACCEL],
+ "%d", sv_airaccelerate->integer);
} else {
- strcpy( sv.configstrings[CS_AIRACCEL], "0" );
+ strcpy(sv.configstrings[CS_AIRACCEL], "0");
}
#if !USE_CLIENT
resolve_masters();
#endif
- override_entity_string( server );
+ override_entity_string(server);
sv.cm = *cm;
- sprintf( sv.configstrings[CS_MAPCHECKSUM], "%d", ( int )cm->cache->checksum );
+ sprintf(sv.configstrings[CS_MAPCHECKSUM], "%d", (int)cm->cache->checksum);
// set inline model names
- Q_concat( sv.configstrings[CS_MODELS + 1], MAX_QPATH, "maps/", server, ".bsp", NULL );
- for( i = 1; i < cm->cache->nummodels; i++ ) {
- sprintf( sv.configstrings[ CS_MODELS + 1 + i ], "*%d", i );
+ Q_concat(sv.configstrings[CS_MODELS + 1], MAX_QPATH, "maps/", server, ".bsp", NULL);
+ for (i = 1; i < cm->cache->nummodels; i++) {
+ sprintf(sv.configstrings[CS_MODELS + 1 + i], "*%d", i);
}
//
@@ -209,7 +214,7 @@ void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
//
// spawn the rest of the entities on the map
- //
+ //
// precache and static commands can be issued during
// map initialization
@@ -219,17 +224,17 @@ void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
X86_SINGLE_FPCW;
// load and spawn all other entities
- ge->SpawnEntities ( sv.name, sv.entitystring ?
- sv.entitystring : cm->cache->entitystring, spawnpoint );
+ ge->SpawnEntities(sv.name, sv.entitystring ?
+ sv.entitystring : cm->cache->entitystring, spawnpoint);
// run two frames to allow everything to settle
- ge->RunFrame (); sv.framenum++;
- ge->RunFrame (); sv.framenum++;
+ ge->RunFrame(); sv.framenum++;
+ ge->RunFrame(); sv.framenum++;
X86_POP_FPCW;
// make sure maxclients string is correct
- sprintf( sv.configstrings[CS_MAXCLIENTS], "%d", sv_maxclients->integer );
+ sprintf(sv.configstrings[CS_MAXCLIENTS], "%d", sv_maxclients->integer);
// all precaches are complete
sv.state = ss_game;
@@ -240,22 +245,22 @@ void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint ) {
#endif
// set serverinfo variable
- SV_InfoSet( "mapname", sv.name );
- SV_InfoSet( "port", net_port->string );
+ SV_InfoSet("mapname", sv.name);
+ SV_InfoSet("port", net_port->string);
- Cvar_SetInteger( sv_running, ss_game, FROM_CODE );
- Cvar_Set( "sv_paused", "0" );
- Cvar_Set( "timedemo", "0" );
+ Cvar_SetInteger(sv_running, ss_game, FROM_CODE);
+ Cvar_Set("sv_paused", "0");
+ Cvar_Set("timedemo", "0");
- EXEC_TRIGGER( sv_changemapcmd );
+ EXEC_TRIGGER(sv_changemapcmd);
#if USE_SYSCON
SV_SetConsoleTitle();
#endif
- SV_BroadcastCommand( "reconnect\n" );
+ SV_BroadcastCommand("reconnect\n");
- Com_Printf ("-------------------------------------\n");
+ Com_Printf("-------------------------------------\n");
}
/*
@@ -266,24 +271,25 @@ A brand new game has been started.
If mvd_spawn is non-zero, load the built-in MVD game module.
==============
*/
-void SV_InitGame( unsigned mvd_spawn ) {
+void SV_InitGame(unsigned mvd_spawn)
+{
int i, entnum;
edict_t *ent;
client_t *client;
- if( svs.initialized ) {
+ if (svs.initialized) {
// cause any connected clients to reconnect
- SV_Shutdown( "Server restarted\n", ERR_RECONNECT | mvd_spawn );
+ SV_Shutdown("Server restarted\n", ERR_RECONNECT | mvd_spawn);
} else {
#if USE_CLIENT
// make sure the client is down
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
SCR_BeginLoadingPlaque();
#endif
- CM_FreeMap( &sv.cm );
- SV_FreeFile( sv.entitystring );
- memset( &sv, 0, sizeof( sv ) );
+ CM_FreeMap(&sv.cm);
+ SV_FreeFile(sv.entitystring);
+ memset(&sv, 0, sizeof(sv));
#if USE_FPS
// set up default frametime for main loop
@@ -292,78 +298,76 @@ void SV_InitGame( unsigned mvd_spawn ) {
}
// get any latched variable changes (maxclients, etc)
- Cvar_GetLatchedVars ();
+ Cvar_GetLatchedVars();
#if !USE_CLIENT
- Cvar_Reset( sv_recycle );
+ Cvar_Reset(sv_recycle);
#endif
- if( mvd_spawn ) {
- Cvar_Set( "deathmatch", "1" );
- Cvar_Set( "coop", "0" );
+ if (mvd_spawn) {
+ Cvar_Set("deathmatch", "1");
+ Cvar_Set("coop", "0");
} else {
- if( Cvar_VariableInteger( "coop" ) &&
- Cvar_VariableInteger( "deathmatch" ) )
- {
- Com_Printf( "Deathmatch and Coop both set, disabling Coop\n" );
- Cvar_Set( "coop", "0" );
+ if (Cvar_VariableInteger("coop") &&
+ Cvar_VariableInteger("deathmatch")) {
+ Com_Printf("Deathmatch and Coop both set, disabling Coop\n");
+ Cvar_Set("coop", "0");
}
// dedicated servers can't be single player and are usually DM
// so unless they explicity set coop, force it to deathmatch
- if( Com_IsDedicated() ) {
- if( !Cvar_VariableInteger( "coop" ) )
- Cvar_Set( "deathmatch", "1" );
+ if (Com_IsDedicated()) {
+ if (!Cvar_VariableInteger("coop"))
+ Cvar_Set("deathmatch", "1");
}
}
// init clients
- if( Cvar_VariableInteger( "deathmatch" ) ) {
- if( sv_maxclients->integer <= 1 ) {
- Cvar_SetInteger( sv_maxclients, 8, FROM_CODE );
- } else if( sv_maxclients->integer > CLIENTNUM_RESERVED ) {
- Cvar_SetInteger( sv_maxclients, CLIENTNUM_RESERVED, FROM_CODE );
+ if (Cvar_VariableInteger("deathmatch")) {
+ if (sv_maxclients->integer <= 1) {
+ Cvar_SetInteger(sv_maxclients, 8, FROM_CODE);
+ } else if (sv_maxclients->integer > CLIENTNUM_RESERVED) {
+ Cvar_SetInteger(sv_maxclients, CLIENTNUM_RESERVED, FROM_CODE);
}
- } else if( Cvar_VariableInteger( "coop" ) ) {
- if( sv_maxclients->integer <= 1 || sv_maxclients->integer > 4 )
- Cvar_Set( "maxclients", "4" );
+ } else if (Cvar_VariableInteger("coop")) {
+ if (sv_maxclients->integer <= 1 || sv_maxclients->integer > 4)
+ Cvar_Set("maxclients", "4");
} else { // non-deathmatch, non-coop is one player
- Cvar_FullSet( "maxclients", "1", CVAR_SERVERINFO|CVAR_LATCH, FROM_CODE );
+ Cvar_FullSet("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH, FROM_CODE);
}
// enable networking
- if( sv_maxclients->integer > 1 ) {
- NET_Config( NET_SERVER );
+ if (sv_maxclients->integer > 1) {
+ NET_Config(NET_SERVER);
}
- svs.client_pool = SV_Mallocz( sizeof( client_t ) * sv_maxclients->integer );
+ svs.client_pool = SV_Mallocz(sizeof(client_t) * sv_maxclients->integer);
svs.num_entities = sv_maxclients->integer * UPDATE_BACKUP * MAX_PACKET_ENTITIES;
- svs.entities = SV_Mallocz( sizeof( entity_state_t ) * svs.num_entities );
+ svs.entities = SV_Mallocz(sizeof(entity_state_t) * svs.num_entities);
#if USE_MVD_SERVER
// initialize MVD server
- if( !mvd_spawn ) {
+ if (!mvd_spawn) {
SV_MvdInit();
}
#endif
- Cvar_ClampInteger( sv_reserved_slots, 0, sv_maxclients->integer - 1 );
+ Cvar_ClampInteger(sv_reserved_slots, 0, sv_maxclients->integer - 1);
#if USE_ZLIB
svs.z.zalloc = SV_Zalloc;
svs.z.zfree = SV_Zfree;
- if( deflateInit2( &svs.z, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
- -MAX_WBITS, 9, Z_DEFAULT_STRATEGY ) != Z_OK )
- {
- Com_Error( ERR_FATAL, "%s: deflateInit2() failed", __func__ );
+ if (deflateInit2(&svs.z, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ -MAX_WBITS, 9, Z_DEFAULT_STRATEGY) != Z_OK) {
+ Com_Error(ERR_FATAL, "%s: deflateInit2() failed", __func__);
}
#endif
// init game
#if USE_MVD_CLIENT
- if( mvd_spawn ) {
- if( ge ) {
+ if (mvd_spawn) {
+ if (ge) {
SV_ShutdownGameProgs();
}
ge = &mvd_ge;
@@ -373,19 +377,19 @@ void SV_InitGame( unsigned mvd_spawn ) {
SV_InitGameProgs();
// send heartbeat very soon
- svs.last_heartbeat = -(HEARTBEAT_SECONDS-5)*1000;
+ svs.last_heartbeat = -(HEARTBEAT_SECONDS - 5) * 1000;
- for( i = 0; i < sv_maxclients->integer; i++ ) {
+ for (i = 0; i < sv_maxclients->integer; i++) {
client = svs.client_pool + i;
entnum = i + 1;
- ent = EDICT_NUM( entnum );
+ ent = EDICT_NUM(entnum);
ent->s.number = entnum;
client->edict = ent;
client->number = i;
}
#if USE_AC_SERVER
- AC_Connect( mvd_spawn );
+ AC_Connect(mvd_spawn);
#endif
svs.initialized = qtrue;
diff --git a/src/sv_local.h b/src/sv_local.h
index 70b5de3..fbcd040 100644
--- a/src/sv_local.h
+++ b/src/sv_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -47,27 +47,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//=============================================================================
-#define SV_Malloc( size ) Z_TagMalloc( size, TAG_SERVER )
-#define SV_Mallocz( size ) Z_TagMallocz( size, TAG_SERVER )
-#define SV_CopyString( s ) Z_TagCopyString( s, TAG_SERVER )
-#define SV_LoadFile( path, buf ) FS_LoadFileEx( path, buf, 0, TAG_SERVER )
-#define SV_FreeFile( buf ) Z_Free( buf )
+#define SV_Malloc(size) Z_TagMalloc(size, TAG_SERVER)
+#define SV_Mallocz(size) Z_TagMallocz(size, TAG_SERVER)
+#define SV_CopyString(s) Z_TagCopyString(s, TAG_SERVER)
+#define SV_LoadFile(path, buf) FS_LoadFileEx(path, buf, 0, TAG_SERVER)
+#define SV_FreeFile(buf) Z_Free(buf)
#ifdef _DEBUG
#define SV_DPrintf(level,...) \
- if( sv_debug && sv_debug->integer > level ) \
- Com_LPrintf( PRINT_DEVELOPER, __VA_ARGS__ )
+ if (sv_debug && sv_debug->integer > level) \
+ Com_LPrintf(PRINT_DEVELOPER, __VA_ARGS__)
#else
#define SV_DPrintf(...)
#endif
-#define SV_BASELINES_SHIFT 6
-#define SV_BASELINES_PER_CHUNK ( 1 << SV_BASELINES_SHIFT )
-#define SV_BASELINES_MASK ( SV_BASELINES_PER_CHUNK - 1 )
-#define SV_BASELINES_CHUNKS ( MAX_EDICTS >> SV_BASELINES_SHIFT )
+#define SV_BASELINES_SHIFT 6
+#define SV_BASELINES_PER_CHUNK (1 << SV_BASELINES_SHIFT)
+#define SV_BASELINES_MASK (SV_BASELINES_PER_CHUNK - 1)
+#define SV_BASELINES_CHUNKS (MAX_EDICTS >> SV_BASELINES_SHIFT)
-#define SV_InfoSet( var, val ) \
- Cvar_FullSet( var, val, CVAR_SERVERINFO|CVAR_ROM, FROM_CODE )
+#define SV_InfoSet(var, val) \
+ Cvar_FullSet(var, val, CVAR_SERVERINFO|CVAR_ROM, FROM_CODE)
#if USE_CLIENT
#define SV_PAUSED (sv_paused->integer != 0)
@@ -82,8 +82,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
// game features this server supports
-#define SV_FEATURES (GMF_CLIENTNUM|GMF_PROPERINUSE|GMF_MVDSPEC|\
- GMF_WANT_ALL_DISCONNECTS|GMF_ENHANCED_SAVEGAMES|\
+#define SV_FEATURES (GMF_CLIENTNUM | GMF_PROPERINUSE | GMF_MVDSPEC | \
+ GMF_WANT_ALL_DISCONNECTS | GMF_ENHANCED_SAVEGAMES | \
SV_GMF_VARIABLE_FPS)
// ugly hack for SV_Shutdown
@@ -111,7 +111,7 @@ typedef struct {
// must be > MAX_FRAMEDIV
#define ENT_HISTORY_SIZE 8
-#define ENT_HISTORY_MASK (ENT_HISTORY_SIZE-1)
+#define ENT_HISTORY_MASK (ENT_HISTORY_SIZE - 1)
struct {
vec3_t origin;
@@ -162,19 +162,19 @@ typedef struct {
unsigned tracecount;
} server_t;
-#define EDICT_POOL(c,n) ((edict_t *)((byte *)(c)->pool->edicts + (c)->pool->edict_size*(n)))
+#define EDICT_POOL(c, n) ((edict_t *)((byte *)(c)->pool->edicts + (c)->pool->edict_size*(n)))
#define EDICT_NUM(n) ((edict_t *)((byte *)ge->edicts + ge->edict_size*(n)))
-#define NUM_FOR_EDICT(e) ((int)(((byte *)(e)-(byte *)ge->edicts ) / ge->edict_size))
+#define NUM_FOR_EDICT(e) ((int)(((byte *)(e) - (byte *)ge->edicts) / ge->edict_size))
#define MAX_TOTAL_ENT_LEAFS 128
// hack for smooth BSP model rotation
-#define Q2PRO_SHORTANGLES(c,e) \
+#define Q2PRO_SHORTANGLES(c, e) \
((c)->protocol == PROTOCOL_VERSION_Q2PRO && \
(c)->version >= PROTOCOL_VERSION_Q2PRO_SHORT_ANGLES && \
sv.state == ss_game && \
- EDICT_POOL(c,e)->solid == SOLID_BSP)
+ EDICT_POOL(c, e)->solid == SOLID_BSP)
typedef enum {
cs_free, // can be reused for a new connection
@@ -203,7 +203,7 @@ typedef enum {
#endif // USE_AC_SERVER
#define MSG_POOLSIZE 1024
-#define MSG_TRESHOLD ( 64 - 10 ) // keep pmsg_s 64 bytes aligned
+#define MSG_TRESHOLD (64 - 10) // keep pmsg_s 64 bytes aligned
#define MSG_RELIABLE 1
#define MSG_CLEAR 2
@@ -229,15 +229,15 @@ typedef struct {
#define RATE_MESSAGES 10
-#define FOR_EACH_CLIENT( client ) \
- LIST_FOR_EACH( client_t, client, &sv_clientlist, entry )
+#define FOR_EACH_CLIENT(client) \
+ LIST_FOR_EACH(client_t, client, &sv_clientlist, entry)
#define PL_S2C(cl) (cl->frames_sent ? \
- (1.0f-(float)cl->frames_acked/cl->frames_sent)*100.0f : 0.0f)
+ (1.0f - (float)cl->frames_acked / cl->frames_sent) * 100.0f : 0.0f)
#define PL_C2S(cl) (cl->netchan->total_received ? \
- ((float)cl->netchan->total_dropped/cl->netchan->total_received)*100.0f : 0.0f)
+ ((float)cl->netchan->total_dropped / cl->netchan->total_received) * 100.0f : 0.0f)
#define AVG_PING(cl) (cl->avg_ping_count ? \
- cl->avg_ping_time/cl->avg_ping_count : cl->ping)
+ cl->avg_ping_time / cl->avg_ping_count : cl->ping)
typedef struct client_s {
list_t entry;
@@ -260,8 +260,8 @@ typedef struct client_s {
char reconnect_var[16];
char reconnect_val[16];
- int lastframe; // for delta compression
- usercmd_t lastcmd; // for filling in big drops
+ int lastframe; // for delta compression
+ usercmd_t lastcmd; // for filling in big drops
int commandMsec; // every seconds this is reset, if user
// commands exhaust it, assume time cheating
@@ -279,7 +279,7 @@ typedef struct client_s {
edict_t *edict; // EDICT_NUM(clientnum+1)
char name[MAX_CLIENT_NAME]; // extracted from userinfo,
- // high bits masked
+ // high bits masked
int messagelevel; // for filtering printed messages
int number; // client slot number
@@ -331,9 +331,9 @@ typedef struct client_s {
int maxclients;
// netchan type dependent methods
- void (*AddMessage)( struct client_s *, byte *, size_t, qboolean );
- void (*WriteFrame)( struct client_s * );
- void (*WriteDatagram)( struct client_s * );
+ void (*AddMessage)(struct client_s *, byte *, size_t, qboolean);
+ void (*WriteFrame)(struct client_s *);
+ void (*WriteDatagram)(struct client_s *);
netchan_t *netchan;
int numpackets; // for that nasty packetdup hack
@@ -418,10 +418,10 @@ typedef struct {
char name[1];
} master_t;
-#define FOR_EACH_MASTER( m ) \
- LIST_FOR_EACH( master_t, m, &sv_masterlist, entry )
-#define FOR_EACH_MASTER_SAFE( m, n ) \
- LIST_FOR_EACH_SAFE( master_t, m, n, &sv_masterlist, entry )
+#define FOR_EACH_MASTER(m) \
+ LIST_FOR_EACH(master_t, m, &sv_masterlist, entry)
+#define FOR_EACH_MASTER_SAFE(m, n) \
+ LIST_FOR_EACH_SAFE(master_t, m, n, &sv_masterlist, entry)
typedef struct server_static_s {
qboolean initialized; // sv_init has completed
@@ -466,7 +466,7 @@ extern cvar_t *sv_maxclients;
extern cvar_t *sv_password;
extern cvar_t *sv_reserved_slots;
extern cvar_t *sv_airaccelerate; // development tool
-extern cvar_t *sv_qwmod; // atu QW Physics modificator
+extern cvar_t *sv_qwmod; // atu QW Physics modificator
extern cvar_t *sv_enforcetime;
#if USE_FPS
extern cvar_t *sv_fps;
@@ -519,117 +519,117 @@ extern edict_t *sv_player;
//
// sv_main.c
//
-void SV_DropClient( client_t *drop, const char *reason );
-void SV_RemoveClient( client_t *client );
-void SV_CleanClient( client_t *client );
+void SV_DropClient(client_t *drop, const char *reason);
+void SV_RemoveClient(client_t *client);
+void SV_CleanClient(client_t *client);
-void SV_InitOperatorCommands (void);
+void SV_InitOperatorCommands(void);
-void SV_UserinfoChanged (client_t *cl);
+void SV_UserinfoChanged(client_t *cl);
-//qboolean SV_RateLimited( ratelimit_t *r );
-//void SV_RateInit( ratelimit_t *r, const char *s );
+//qboolean SV_RateLimited(ratelimit_t *r);
+//void SV_RateInit(ratelimit_t *r, const char *s);
-addrmatch_t *SV_MatchAddress( list_t *list, netadr_t *address );
+addrmatch_t *SV_MatchAddress(list_t *list, netadr_t *address);
-int SV_CountClients( void );
+int SV_CountClients(void);
#if USE_ZLIB
-voidpf SV_Zalloc OF(( voidpf opaque, uInt items, uInt size ));
-void SV_Zfree OF(( voidpf opaque, voidpf address ));
+voidpf SV_Zalloc OF((voidpf opaque, uInt items, uInt size));
+void SV_Zfree OF((voidpf opaque, voidpf address));
#endif
-void Master_Heartbeat (void);
-void Master_Packet (void);
+void Master_Heartbeat(void);
+void Master_Packet(void);
//
// sv_init.c
//
-void SV_ClientReset( client_t *client );
-void SV_SpawnServer( cm_t *cm, const char *server, const char *spawnpoint );
-void SV_InitGame( unsigned mvd_spawn );
+void SV_ClientReset(client_t *client);
+void SV_SpawnServer(cm_t *cm, const char *server, const char *spawnpoint);
+void SV_InitGame(unsigned mvd_spawn);
//
// sv_send.c
//
typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
-#define SV_OUTPUTBUF_LENGTH (MAX_PACKETLEN_DEFAULT - 16)
+#define SV_OUTPUTBUF_LENGTH (MAX_PACKETLEN_DEFAULT - 16)
-#define SV_BeginRedirect( target ) \
- Com_BeginRedirect( target, sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect )
+#define SV_BeginRedirect(target) \
+ Com_BeginRedirect(target, sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect)
-extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
+extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
-void SV_FlushRedirect( int redirected, char *outputbuf, size_t len );
+void SV_FlushRedirect(int redirected, char *outputbuf, size_t len);
-void SV_SendClientMessages (void);
-void SV_SendAsyncPackets( void );
+void SV_SendClientMessages(void);
+void SV_SendAsyncPackets(void);
-void SV_Multicast (vec3_t origin, multicast_t to);
-void SV_ClientPrintf( client_t *cl, int level, const char *fmt, ... ) q_printf( 3, 4 );
-void SV_BroadcastPrintf( int level, const char *fmt, ... ) q_printf( 2, 3 );
-void SV_ClientCommand( client_t *cl, const char *fmt, ... ) q_printf( 2, 3 );
-void SV_BroadcastCommand( const char *fmt, ... ) q_printf( 1, 2 );
-void SV_ClientAddMessage( client_t *client, int flags );
-void SV_ShutdownClientSend( client_t *client );
-void SV_InitClientSend( client_t *newcl );
+void SV_Multicast(vec3_t origin, multicast_t to);
+void SV_ClientPrintf(client_t *cl, int level, const char *fmt, ...) q_printf(3, 4);
+void SV_BroadcastPrintf(int level, const char *fmt, ...) q_printf(2, 3);
+void SV_ClientCommand(client_t *cl, const char *fmt, ...) q_printf(2, 3);
+void SV_BroadcastCommand(const char *fmt, ...) q_printf(1, 2);
+void SV_ClientAddMessage(client_t *client, int flags);
+void SV_ShutdownClientSend(client_t *client);
+void SV_InitClientSend(client_t *newcl);
#if USE_MVD_SERVER
//
// sv_mvd.c
//
-void SV_MvdRegister( void );
-void SV_MvdInit( void );
-void SV_MvdShutdown( error_type_t type );
-void SV_MvdBeginFrame( void );
-void SV_MvdEndFrame( void );
-void SV_MvdRunClients( void );
-void SV_MvdStatus_f( void );
-void SV_MvdMapChanged( void );
-void SV_MvdClientDropped( client_t *client );
-
-void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable );
-void SV_MvdMulticast( int leafnum, multicast_t to );
-void SV_MvdConfigstring( int index, const char *string, size_t len );
-void SV_MvdBroadcastPrint( int level, const char *string );
-void SV_MvdStartSound( int entnum, int channel, int flags,
- int soundindex, int volume,
- int attenuation, int timeofs );
-
-void SV_MvdRecord_f( void );
-void SV_MvdStop_f( void );
+void SV_MvdRegister(void);
+void SV_MvdInit(void);
+void SV_MvdShutdown(error_type_t type);
+void SV_MvdBeginFrame(void);
+void SV_MvdEndFrame(void);
+void SV_MvdRunClients(void);
+void SV_MvdStatus_f(void);
+void SV_MvdMapChanged(void);
+void SV_MvdClientDropped(client_t *client);
+
+void SV_MvdUnicast(edict_t *ent, int clientNum, qboolean reliable);
+void SV_MvdMulticast(int leafnum, multicast_t to);
+void SV_MvdConfigstring(int index, const char *string, size_t len);
+void SV_MvdBroadcastPrint(int level, const char *string);
+void SV_MvdStartSound(int entnum, int channel, int flags,
+ int soundindex, int volume,
+ int attenuation, int timeofs);
+
+void SV_MvdRecord_f(void);
+void SV_MvdStop_f(void);
#endif // USE_MVD_SERVER
#if USE_AC_SERVER
-//
+//
// sv_ac.c
//
-char *AC_ClientConnect( client_t *cl );
-void AC_ClientDisconnect( client_t *cl );
-qboolean AC_ClientBegin( client_t *cl );
-void AC_ClientAnnounce( client_t *cl );
-void AC_ClientToken( client_t *cl, const char *token );
+char *AC_ClientConnect(client_t *cl);
+void AC_ClientDisconnect(client_t *cl);
+qboolean AC_ClientBegin(client_t *cl);
+void AC_ClientAnnounce(client_t *cl);
+void AC_ClientToken(client_t *cl, const char *token);
-void AC_Register( void );
-void AC_Disconnect( void );
-void AC_Connect( unsigned mvd_spawn );
-void AC_Run( void );
+void AC_Register(void);
+void AC_Disconnect(void);
+void AC_Connect(unsigned mvd_spawn);
+void AC_Run(void);
-void AC_List_f( void );
-void AC_Info_f( void );
+void AC_List_f(void);
+void AC_Info_f(void);
#endif // USE_AC_SERVER
//
// sv_user.c
//
-void SV_New_f( void );
-void SV_Begin_f( void );
-void SV_Nextserver (void);
-void SV_ExecuteClientMessage (client_t *cl);
-void SV_CloseDownload( client_t *client );
+void SV_New_f(void);
+void SV_Begin_f(void);
+void SV_Nextserver(void);
+void SV_ExecuteClientMessage(client_t *cl);
+void SV_CloseDownload(client_t *client);
//
// sv_ccmds.c
@@ -638,42 +638,42 @@ void SV_CloseDownload( client_t *client );
extern const cmd_option_t o_record[];
#endif
-void SV_AddMatch_f( list_t *list );
-void SV_DelMatch_f( list_t *list );
-void SV_ListMatches_f( list_t *list );
-client_t *SV_GetPlayer( const char *s, qboolean partial );
-void SV_PrintMiscInfo( void );
+void SV_AddMatch_f(list_t *list);
+void SV_DelMatch_f(list_t *list);
+void SV_ListMatches_f(list_t *list);
+client_t *SV_GetPlayer(const char *s, qboolean partial);
+void SV_PrintMiscInfo(void);
//
// sv_ents.c
//
-#define ES_INUSE( s ) \
- ( (s)->modelindex || (s)->effects || (s)->sound || (s)->event )
+#define ES_INUSE(s) \
+ ((s)->modelindex || (s)->effects || (s)->sound || (s)->event)
-void SV_BuildProxyClientFrame( client_t *client );
-void SV_BuildClientFrame( client_t *client );
-void SV_WriteFrameToClient_Default( client_t *client );
-void SV_WriteFrameToClient_Enhanced( client_t *client );
-qboolean SV_EdictPV( cm_t *cm, edict_t *ent, byte *mask );
+void SV_BuildProxyClientFrame(client_t *client);
+void SV_BuildClientFrame(client_t *client);
+void SV_WriteFrameToClient_Default(client_t *client);
+void SV_WriteFrameToClient_Enhanced(client_t *client);
+qboolean SV_EdictPV(cm_t *cm, edict_t *ent, byte *mask);
//
// sv_game.c
//
extern game_export_t *ge;
-void SV_InitGameProgs( void );
-void SV_ShutdownGameProgs (void);
-void SV_InitEdict (edict_t *e);
+void SV_InitGameProgs(void);
+void SV_ShutdownGameProgs(void);
+void SV_InitEdict(edict_t *e);
-void PF_Pmove( pmove_t *pm );
+void PF_Pmove(pmove_t *pm);
#if USE_CLIENT
//
// sv_save.c
//
-void SV_Savegame_f( void );
-void SV_Loadgame_f( void );
+void SV_Savegame_f(void);
+void SV_Loadgame_f(void);
#endif
//============================================================
@@ -682,22 +682,22 @@ void SV_Loadgame_f( void );
// high level object sorting to reduce interaction tests
//
-void SV_ClearWorld (void);
+void SV_ClearWorld(void);
// called after the world model has been loaded, before linking any entities
-void PF_UnlinkEdict (edict_t *ent);
+void PF_UnlinkEdict(edict_t *ent);
// call before removing an entity, and before trying to move one,
// so it doesn't clip against itself
-void SV_LinkEdict( cm_t *cm, edict_t *ent );
-void PF_LinkEdict (edict_t *ent);
+void SV_LinkEdict(cm_t *cm, edict_t *ent);
+void PF_LinkEdict(edict_t *ent);
// Needs to be called any time an entity changes origin, mins, maxs,
// or solid. Automatically unlinks if needed.
// sets ent->v.absmin and ent->v.absmax
// sets ent->leafnums[] for pvs determination even if the entity
// is not solid
-int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
+int SV_AreaEdicts(vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
// fills in a table of edict pointers with edicts that have bounding boxes
// that intersect the given area. It is possible for a non-axial bmodel
// to be returned that doesn't actually intersect the area on an exact
@@ -710,16 +710,16 @@ int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int a
//
// functions that interact with everything apropriate
//
-int SV_PointContents (vec3_t p);
+int SV_PointContents(vec3_t p);
// returns the CONTENTS_* value from the world at the given point.
// Quake 2 extends this to also check entities, to allow moving liquids
-typedef trace_t (*sv_trace_t)( vec3_t, vec3_t, vec3_t, vec3_t, edict_t *, int );
+typedef trace_t (*sv_trace_t)(vec3_t, vec3_t, vec3_t, vec3_t, edict_t *, int);
-trace_t SV_Trace_Native (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
- edict_t *passedict, int contentmask);
-trace_t *SV_Trace (trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
- edict_t *passedict, int contentmask);
+trace_t SV_Trace_Native(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
+ edict_t *passedict, int contentmask);
+trace_t *SV_Trace(trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
+ edict_t *passedict, int contentmask);
// mins and maxs are relative
// if the entire move stays in a solid volume, trace.allsolid will be set,
diff --git a/src/sv_main.c b/src/sv_main.c
index 671acf6..9c9b503 100644
--- a/src/sv_main.c
+++ b/src/sv_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,13 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
pmoveParams_t sv_pmp;
-LIST_DECL( sv_masterlist ); // address of group servers
-LIST_DECL( sv_banlist );
-LIST_DECL( sv_blacklist );
-LIST_DECL( sv_cmdlist_connect );
-LIST_DECL( sv_cmdlist_begin );
-LIST_DECL( sv_filterlist );
-LIST_DECL( sv_clientlist ); // linked list of non-free clients
+LIST_DECL(sv_masterlist); // address of group servers
+LIST_DECL(sv_banlist);
+LIST_DECL(sv_blacklist);
+LIST_DECL(sv_cmdlist_connect);
+LIST_DECL(sv_cmdlist_begin);
+LIST_DECL(sv_filterlist);
+LIST_DECL(sv_clientlist); // linked list of non-free clients
client_t *sv_client; // current client
edict_t *sv_player; // current client edict
@@ -100,57 +100,59 @@ qboolean sv_registered;
//============================================================================
-void SV_RemoveClient( client_t *client ) {
- if( client->msg_pool ) {
- SV_ShutdownClientSend( client );
+void SV_RemoveClient(client_t *client)
+{
+ if (client->msg_pool) {
+ SV_ShutdownClientSend(client);
}
- if( client->netchan ) {
- Netchan_Close( client->netchan );
+ if (client->netchan) {
+ Netchan_Close(client->netchan);
client->netchan = NULL;
}
// unlink them from active client list, but don't clear the list entry
// itself to make code that traverses client list in a loop happy!
- List_Remove( &client->entry );
+ List_Remove(&client->entry);
#if USE_MVD_CLIENT
// unlink them from MVD client list
- if( sv.state == ss_broadcast ) {
- MVD_RemoveClient( client );
+ if (sv.state == ss_broadcast) {
+ MVD_RemoveClient(client);
}
#endif
- Com_DPrintf( "Going from cs_zombie to cs_free for %s\n", client->name );
+ Com_DPrintf("Going from cs_zombie to cs_free for %s\n", client->name);
client->state = cs_free; // can now be reused
client->name[0] = 0;
}
-void SV_CleanClient( client_t *client ) {
+void SV_CleanClient(client_t *client)
+{
int i;
#if USE_AC_SERVER
string_entry_t *bad, *next;
- for( bad = client->ac_bad_files; bad; bad = next ) {
+ for (bad = client->ac_bad_files; bad; bad = next) {
next = bad->next;
- Z_Free( bad );
+ Z_Free(bad);
}
client->ac_bad_files = NULL;
#endif
// close any existing donwload
- SV_CloseDownload( client );
+ SV_CloseDownload(client);
- if( client->versionString ) {
- Z_Free( client->versionString );
+ if (client->versionString) {
+ Z_Free(client->versionString);
client->versionString = NULL;
}
// free baselines allocated for this client
- for( i = 0; i < SV_BASELINES_CHUNKS; i++ ) {
- if( client->baselines[i] ) {
- Z_Free( client->baselines[i] );
+ for (i = 0; i < SV_BASELINES_CHUNKS; i++) {
+ if (client->baselines[i]) {
+ Z_Free(client->baselines[i]);
client->baselines[i] = NULL;
}
}
@@ -165,73 +167,74 @@ or unwillingly. This is NOT called if the entire server is quiting
or crashing.
=====================
*/
-void SV_DropClient( client_t *client, const char *reason ) {
+void SV_DropClient(client_t *client, const char *reason)
+{
int oldstate = client->state;
- if( client->state <= cs_zombie ) {
+ if (client->state <= cs_zombie) {
return; // called recursively?
}
client->state = cs_zombie; // become free in a few seconds
client->lastmessage = svs.realtime;
- if( reason ) {
+ if (reason) {
qboolean announce = oldstate == cs_spawned ? 2 : 1;
const char *prefix = " was dropped: ";
// parse flags
- if( *reason == '!' ) {
+ if (*reason == '!') {
reason++;
announce = 0;
}
- if( *reason == '?' ) {
+ if (*reason == '?') {
reason++;
prefix = " ";
}
- if( announce == 2 ) {
+ if (announce == 2) {
// announce to others
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast )
- MVD_GameClientDrop( client->edict, prefix, reason );
+ if (sv.state == ss_broadcast)
+ MVD_GameClientDrop(client->edict, prefix, reason);
else
#endif
- SV_BroadcastPrintf( PRINT_HIGH, "%s%s%s\n",
- client->name, prefix, reason );
+ SV_BroadcastPrintf(PRINT_HIGH, "%s%s%s\n",
+ client->name, prefix, reason);
}
- if( announce )
+ if (announce)
// print this to client as they will not receive broadcast
- SV_ClientPrintf( client, PRINT_HIGH, "%s%s%s\n",
- client->name, prefix, reason );
+ SV_ClientPrintf(client, PRINT_HIGH, "%s%s%s\n",
+ client->name, prefix, reason);
// print to server console
- if( Com_IsDedicated() && client->netchan )
- Com_Printf( "%s[%s]%s%s\n", client->name,
- NET_AdrToString( &client->netchan->remote_address ), prefix, reason );
+ if (Com_IsDedicated() && client->netchan)
+ Com_Printf("%s[%s]%s%s\n", client->name,
+ NET_AdrToString(&client->netchan->remote_address), prefix, reason);
}
// add the disconnect
- MSG_WriteByte( svc_disconnect );
- SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_disconnect);
+ SV_ClientAddMessage(client, MSG_RELIABLE | MSG_CLEAR);
- if( oldstate == cs_spawned || ( g_features->integer & GMF_WANT_ALL_DISCONNECTS ) ) {
+ if (oldstate == cs_spawned || (g_features->integer & GMF_WANT_ALL_DISCONNECTS)) {
// call the prog function for removing a client
// this will remove the body, among other things
- ge->ClientDisconnect( client->edict );
+ ge->ClientDisconnect(client->edict);
}
#if USE_AC_SERVER
- AC_ClientDisconnect( client );
+ AC_ClientDisconnect(client);
#endif
- SV_CleanClient( client );
+ SV_CleanClient(client);
- Com_DPrintf( "Going to cs_zombie for %s\n", client->name );
+ Com_DPrintf("Going to cs_zombie for %s\n", client->name);
#if USE_MVD_SERVER
// give MVD server a chance to detect if it's dummy client was dropped
- SV_MvdClientDropped( client );
+ SV_MvdClientDropped(client);
#endif
}
@@ -244,17 +247,18 @@ CONNECTIONLESS COMMANDS
==============================================================================
*/
-static qboolean SV_RateLimited( ratelimit_t *r ) {
- if( !r->limit ) {
+static qboolean SV_RateLimited(ratelimit_t *r)
+{
+ if (!r->limit) {
return qfalse;
}
- if( svs.realtime - r->time > r->period ) {
+ if (svs.realtime - r->time > r->period) {
r->count = 0;
r->time = svs.realtime;
return qfalse;
}
- if( r->count < r->limit ) {
+ if (r->count < r->limit) {
return qfalse;
}
@@ -262,28 +266,29 @@ static qboolean SV_RateLimited( ratelimit_t *r ) {
}
// <limit>[/<period>[sec|min|hour]]
-static void SV_RateInit( ratelimit_t *r, const char *s ) {
+static void SV_RateInit(ratelimit_t *r, const char *s)
+{
unsigned limit;
unsigned period, scale;
char *p;
- limit = strtoul( s, &p, 10 );
- if( *p == '/' ) {
- period = strtoul( p + 1, &p, 10 );
- if( *p == 0 || *p == 's' || *p == 'S' ) {
+ limit = strtoul(s, &p, 10);
+ if (*p == '/') {
+ period = strtoul(p + 1, &p, 10);
+ if (*p == 0 || *p == 's' || *p == 'S') {
scale = 1000;
- } else if( *p == 'm' || *p == 'M' ) {
- scale = 60*1000;
- } else if( *p == 'h' || *p == 'H' ) {
- scale = 60*60*1000;
+ } else if (*p == 'm' || *p == 'M') {
+ scale = 60 * 1000;
+ } else if (*p == 'h' || *p == 'H') {
+ scale = 60 * 60 * 1000;
} else {
// everything else is milliseconds
scale = 1;
}
- if( period > UINT_MAX / scale ) {
+ if (period > UINT_MAX / scale) {
period = UINT_MAX;
} else {
- if( !period ) {
+ if (!period) {
period = 1;
}
period *= scale;
@@ -299,13 +304,14 @@ static void SV_RateInit( ratelimit_t *r, const char *s ) {
r->period = period;
}
-addrmatch_t *SV_MatchAddress( list_t *list, netadr_t *addr ) {
+addrmatch_t *SV_MatchAddress(list_t *list, netadr_t *addr)
+{
addrmatch_t *match;
- LIST_FOR_EACH( addrmatch_t, match, list, entry ) {
- if( ( addr->ip.u32 & match->mask ) == ( match->addr.u32 & match->mask ) ) {
+ LIST_FOR_EACH(addrmatch_t, match, list, entry) {
+ if ((addr->ip.u32 & match->mask) == (match->addr.u32 & match->mask)) {
match->hits++;
- match->time = time( NULL );
+ match->time = time(NULL);
return match;
}
}
@@ -321,34 +327,35 @@ Builds the string that is sent as heartbeats and status replies.
It is assumed that size of status buffer is at least SV_OUTPUTBUF_LENGTH!
===============
*/
-static size_t SV_StatusString( char *status ) {
+static size_t SV_StatusString(char *status)
+{
char entry[MAX_STRING_CHARS];
client_t *cl;
size_t total, len;
char *tmp = sv_maxclients->string;
// XXX: ugly hack to hide reserved slots
- if( sv_reserved_slots->integer ) {
- Q_snprintf( entry, sizeof( entry ), "%d",
- sv_maxclients->integer - sv_reserved_slots->integer );
+ if (sv_reserved_slots->integer) {
+ Q_snprintf(entry, sizeof(entry), "%d",
+ sv_maxclients->integer - sv_reserved_slots->integer);
sv_maxclients->string = entry;
}
// add server info
- total = Cvar_BitInfo( status, CVAR_SERVERINFO );
+ total = Cvar_BitInfo(status, CVAR_SERVERINFO);
sv_maxclients->string = tmp;
// add uptime
- if( sv_uptime->integer > 0 ) {
- if( sv_uptime->integer > 1 ) {
- len = Com_UptimeLong_m( entry, MAX_INFO_VALUE );
+ if (sv_uptime->integer > 0) {
+ if (sv_uptime->integer > 1) {
+ len = Com_UptimeLong_m(entry, MAX_INFO_VALUE);
} else {
- len = Com_Uptime_m( entry, MAX_INFO_VALUE );
+ len = Com_Uptime_m(entry, MAX_INFO_VALUE);
}
- if( total + 8 + len < MAX_INFO_STRING ) {
- memcpy( status + total, "\\uptime\\", 8 );
- memcpy( status + total + 8, entry, len );
+ if (total + 8 + len < MAX_INFO_STRING) {
+ memcpy(status + total, "\\uptime\\", 8);
+ memcpy(status + total + 8, entry, len);
total += 8 + len;
}
}
@@ -356,22 +363,22 @@ static size_t SV_StatusString( char *status ) {
status[total++] = '\n';
// add player list
- if( sv_status_show->integer > 1 ) {
- FOR_EACH_CLIENT( cl ) {
- if( cl->state == cs_zombie ) {
+ if (sv_status_show->integer > 1) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state == cs_zombie) {
continue;
}
- len = Q_snprintf( entry, sizeof( entry ),
- "%i %i \"%s\"\n",
- cl->edict->client->ps.stats[STAT_FRAGS],
- cl->ping, cl->name );
- if( len >= sizeof( entry ) ) {
+ len = Q_snprintf(entry, sizeof(entry),
+ "%i %i \"%s\"\n",
+ cl->edict->client->ps.stats[STAT_FRAGS],
+ cl->ping, cl->name);
+ if (len >= sizeof(entry)) {
continue;
}
- if( total + len >= SV_OUTPUTBUF_LENGTH ) {
+ if (total + len >= SV_OUTPUTBUF_LENGTH) {
break; // can't hold any more
}
- memcpy( status + total, entry, len );
+ memcpy(status + total, entry, len);
total += len;
}
}
@@ -388,30 +395,31 @@ SVC_Status
Responds with all the info that qplug or qspy can see
================
*/
-static void SVC_Status( void ) {
+static void SVC_Status(void)
+{
char buffer[MAX_PACKETLEN_DEFAULT];
size_t len;
- if( !sv_status_show->integer ) {
+ if (!sv_status_show->integer) {
return;
}
- if( SV_RateLimited( &svs.ratelimit_status ) ) {
- Com_DPrintf( "Dropping status request from %s\n",
- NET_AdrToString( &net_from ) );
+ if (SV_RateLimited(&svs.ratelimit_status)) {
+ Com_DPrintf("Dropping status request from %s\n",
+ NET_AdrToString(&net_from));
return;
}
svs.ratelimit_status.count++;
// write the packet header
- memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
+ memcpy(buffer, "\xff\xff\xff\xffprint\n", 10);
len = 10;
- len += SV_StatusString( buffer + len );
+ len += SV_StatusString(buffer + len);
// send the datagram
- NET_SendPacket( NS_SERVER, &net_from, len, buffer );
+ NET_SendPacket(NS_SERVER, &net_from, len, buffer);
}
/*
@@ -420,16 +428,17 @@ SVC_Ack
================
*/
-static void SVC_Ack( void ) {
+static void SVC_Ack(void)
+{
master_t *m;
- FOR_EACH_MASTER( m ) {
- if( !m->adr.port ) {
+ FOR_EACH_MASTER(m) {
+ if (!m->adr.port) {
continue;
}
- if( NET_IsEqualBaseAdr( &m->adr, &net_from ) ) {
- Com_DPrintf( "Ping acknowledge from %s\n",
- NET_AdrToString( &net_from ) );
+ if (NET_IsEqualBaseAdr(&m->adr, &net_from)) {
+ Com_DPrintf("Ping acknowledge from %s\n",
+ NET_AdrToString(&net_from));
m->last_ack = svs.realtime;
break;
}
@@ -444,7 +453,8 @@ Responds with short info for broadcast scans
The second parameter should be the current protocol version number.
================
*/
-static void SVC_Info( void ) {
+static void SVC_Info(void)
+{
char string[MAX_QPATH];
size_t len;
int count;
@@ -453,23 +463,23 @@ static void SVC_Info( void ) {
if (sv_maxclients->integer == 1)
return; // ignore in single player
- version = atoi (Cmd_Argv(1));
+ version = atoi(Cmd_Argv(1));
if (version != PROTOCOL_VERSION_DEFAULT) {
return;
}
-
+
count = SV_CountClients();
- len = Q_snprintf (string, sizeof(string),
- "\xff\xff\xff\xffinfo\n%16s %8s %2i/%2i\n",
- sv_hostname->string, sv.name, count, sv_maxclients->integer -
- sv_reserved_slots->integer );
- if( len >= sizeof( string ) ) {
+ len = Q_snprintf(string, sizeof(string),
+ "\xff\xff\xff\xffinfo\n%16s %8s %2i/%2i\n",
+ sv_hostname->string, sv.name, count, sv_maxclients->integer -
+ sv_reserved_slots->integer);
+ if (len >= sizeof(string)) {
return;
}
-
- NET_SendPacket( NS_SERVER, &net_from, len, string );
+
+ NET_SendPacket(NS_SERVER, &net_from, len, string);
}
/*
@@ -479,8 +489,9 @@ SVC_Ping
Just responds with an acknowledgement
================
*/
-static void SVC_Ping( void ) {
- OOB_PRINT( NS_SERVER, &net_from, "ack" );
+static void SVC_Ping(void)
+{
+ OOB_PRINT(NS_SERVER, &net_from, "ack");
}
/*
@@ -494,7 +505,8 @@ flood the server with invalid connection IPs. With a
challenge, they must give a valid IP address.
=================
*/
-static void SVC_GetChallenge( void ) {
+static void SVC_GetChallenge(void)
+{
int i, oldest;
unsigned challenge;
unsigned oldestTime;
@@ -503,20 +515,20 @@ static void SVC_GetChallenge( void ) {
oldestTime = 0xffffffff;
// see if we already have a challenge for this ip
- for( i = 0; i < MAX_CHALLENGES; i++ ) {
- if( NET_IsEqualBaseAdr( &net_from, &svs.challenges[i].adr ) )
+ for (i = 0; i < MAX_CHALLENGES; i++) {
+ if (NET_IsEqualBaseAdr(&net_from, &svs.challenges[i].adr))
break;
- if( svs.challenges[i].time > com_eventTime ) {
+ if (svs.challenges[i].time > com_eventTime) {
svs.challenges[i].time = com_eventTime;
}
- if( svs.challenges[i].time < oldestTime ) {
+ if (svs.challenges[i].time < oldestTime) {
oldestTime = svs.challenges[i].time;
oldest = i;
}
}
- challenge = ( ( rand() << 16 ) | rand() ) & 0x7fffffff;
- if( i == MAX_CHALLENGES ) {
+ challenge = ((rand() << 16) | rand()) & 0x7fffffff;
+ if (i == MAX_CHALLENGES) {
// overwrite the oldest
svs.challenges[oldest].challenge = challenge;
svs.challenges[oldest].adr = net_from;
@@ -527,23 +539,24 @@ static void SVC_GetChallenge( void ) {
}
// send it back
- Netchan_OutOfBand( NS_SERVER, &net_from,
- "challenge %u p=34,35,36", challenge );
+ Netchan_OutOfBand(NS_SERVER, &net_from,
+ "challenge %u p=34,35,36", challenge);
}
-static void send_redirect_hack( const char *addr ) {
- Netchan_OutOfBand( NS_SERVER, &net_from, "client_connect" );
-
- MSG_WriteLong( 1 );
- MSG_WriteLong( 0 );
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteString( va( "Server is full. Redirecting you to %s...\n", addr ) );
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( va( "connect %s\n", addr ) );
-
- NET_SendPacket( NS_SERVER, &net_from, msg_write.cursize, msg_write.data );
- SZ_Clear( &msg_write );
+static void send_redirect_hack(const char *addr)
+{
+ Netchan_OutOfBand(NS_SERVER, &net_from, "client_connect");
+
+ MSG_WriteLong(1);
+ MSG_WriteLong(0);
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteString(va("Server is full. Redirecting you to %s...\n", addr));
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(va("connect %s\n", addr));
+
+ NET_SendPacket(NS_SERVER, &net_from, msg_write.cursize, msg_write.data);
+ SZ_Clear(&msg_write);
}
#define SV_OobPrintf(...) \
@@ -556,7 +569,8 @@ SVC_DirectConnect
A connection request that did not come from the master
==================
*/
-static void SVC_DirectConnect( void ) {
+static void SVC_DirectConnect(void)
+{
char userinfo[MAX_INFO_STRING];
char reconnect_var[16];
char reconnect_val[16];
@@ -574,69 +588,67 @@ static void SVC_DirectConnect( void ) {
int reserved;
qboolean has_zlib;
- protocol = atoi( Cmd_Argv( 1 ) );
- qport = atoi( Cmd_Argv( 2 ) ) ;
- challenge = atoi( Cmd_Argv( 3 ) );
+ protocol = atoi(Cmd_Argv(1));
+ qport = atoi(Cmd_Argv(2)) ;
+ challenge = atoi(Cmd_Argv(3));
- Com_DPrintf( "%s: protocol=%i, qport=%i, challenge=%i\n",
- __func__, protocol, qport, challenge );
+ Com_DPrintf("%s: protocol=%i, qport=%i, challenge=%i\n",
+ __func__, protocol, qport, challenge);
- if( protocol < PROTOCOL_VERSION_DEFAULT ||
- protocol > PROTOCOL_VERSION_Q2PRO )
- {
- SV_OobPrintf( "Unsupported protocol version %d.\n", protocol );
- Com_DPrintf( " rejected connect with protocol %i\n", protocol );
+ if (protocol < PROTOCOL_VERSION_DEFAULT ||
+ protocol > PROTOCOL_VERSION_Q2PRO) {
+ SV_OobPrintf("Unsupported protocol version %d.\n", protocol);
+ Com_DPrintf(" rejected connect with protocol %i\n", protocol);
return;
}
- if( !NET_IsLocalAddress( &net_from ) ) {
+ if (!NET_IsLocalAddress(&net_from)) {
addrmatch_t *match;
// see if the challenge is valid
- for( i = 0; i < MAX_CHALLENGES; i++ ) {
- if( !svs.challenges[i].challenge ) {
+ for (i = 0; i < MAX_CHALLENGES; i++) {
+ if (!svs.challenges[i].challenge) {
continue;
}
- if( NET_IsEqualBaseAdr( &net_from, &svs.challenges[i].adr ) ) {
- if( svs.challenges[i].challenge == challenge )
+ if (NET_IsEqualBaseAdr(&net_from, &svs.challenges[i].adr)) {
+ if (svs.challenges[i].challenge == challenge)
break; // good
- SV_OobPrintf( "Bad challenge.\n" );
- Com_DPrintf( " rejected - bad challenge.\n" );
+ SV_OobPrintf("Bad challenge.\n");
+ Com_DPrintf(" rejected - bad challenge.\n");
return;
}
}
- if( i == MAX_CHALLENGES ) {
- SV_OobPrintf( "No challenge for address.\n" );
- Com_DPrintf( " rejected - no challenge.\n" );
+ if (i == MAX_CHALLENGES) {
+ SV_OobPrintf("No challenge for address.\n");
+ Com_DPrintf(" rejected - no challenge.\n");
return;
}
svs.challenges[i].challenge = 0;
// check for banned address
- if( ( match = SV_MatchAddress( &sv_banlist, &net_from ) ) != NULL ) {
+ if ((match = SV_MatchAddress(&sv_banlist, &net_from)) != NULL) {
s = match->comment;
- if( !*s ) {
+ if (!*s) {
s = "Your IP address is banned from this server.";
}
- SV_OobPrintf( "%s\nConnection refused.\n", s );
- Com_DPrintf( " rejected connect from banned IP\n" );
+ SV_OobPrintf("%s\nConnection refused.\n", s);
+ Com_DPrintf(" rejected connect from banned IP\n");
return;
}
- if( sv_locked->integer ) {
- SV_OobPrintf( "Server is locked.\n" );
- Com_DPrintf( " rejected - server is locked.\n" );
+ if (sv_locked->integer) {
+ SV_OobPrintf("Server is locked.\n");
+ Com_DPrintf(" rejected - server is locked.\n");
return;
}
// limit number of connections from single IP
- if( sv_iplimit->integer > 0 ) {
+ if (sv_iplimit->integer > 0) {
count = 0;
- FOR_EACH_CLIENT( cl ) {
- if( NET_IsEqualBaseAdr( &net_from,
- &cl->netchan->remote_address ) )
- {
- if( cl->state == cs_zombie ) {
+ FOR_EACH_CLIENT(cl) {
+ if (NET_IsEqualBaseAdr(&net_from,
+ &cl->netchan->remote_address)) {
+ if (cl->state == cs_zombie) {
count++;
} else {
count += 2;
@@ -644,9 +656,9 @@ static void SVC_DirectConnect( void ) {
}
}
count >>= 1;
- if( count >= sv_iplimit->integer ) {
- SV_OobPrintf( "Too many connections from your IP address.\n" );
- Com_DPrintf( " rejected - %d connections from this IP.\n", count );
+ if (count >= sv_iplimit->integer) {
+ SV_OobPrintf("Too many connections from your IP address.\n");
+ Com_DPrintf(" rejected - %d connections from this IP.\n", count);
return;
}
}
@@ -655,55 +667,55 @@ static void SVC_DirectConnect( void ) {
// set maximum message length
maxlength = MAX_PACKETLEN_WRITABLE_DEFAULT;
has_zlib = qfalse;
- if( protocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol >= PROTOCOL_VERSION_R1Q2) {
has_zlib = qtrue;
- s = Cmd_Argv( 5 );
- if( *s ) {
- maxlength = atoi( s );
- if( maxlength < 0 || maxlength > MAX_PACKETLEN_WRITABLE ) {
- SV_OobPrintf( "Invalid maximum message length.\n" );
- Com_DPrintf( " rejected - bad maxmsglen.\n" );
+ s = Cmd_Argv(5);
+ if (*s) {
+ maxlength = atoi(s);
+ if (maxlength < 0 || maxlength > MAX_PACKETLEN_WRITABLE) {
+ SV_OobPrintf("Invalid maximum message length.\n");
+ Com_DPrintf(" rejected - bad maxmsglen.\n");
return;
}
- if( !maxlength ) {
+ if (!maxlength) {
maxlength = MAX_PACKETLEN_WRITABLE;
- } else if( maxlength < MIN_PACKETLEN ) {
+ } else if (maxlength < MIN_PACKETLEN) {
maxlength = MIN_PACKETLEN;
}
}
}
- if( !NET_IsLocalAddress( &net_from ) ) {
+ if (!NET_IsLocalAddress(&net_from)) {
// cap maximum message length for real connections
- if( net_maxmsglen->integer > 0 && maxlength > net_maxmsglen->integer ) {
+ if (net_maxmsglen->integer > 0 && maxlength > net_maxmsglen->integer) {
maxlength = net_maxmsglen->integer;
}
}
- if( protocol == PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol == PROTOCOL_VERSION_R1Q2) {
// set minor protocol version
- s = Cmd_Argv( 6 );
- if( *s ) {
- version = atoi( s );
- clamp( version, PROTOCOL_VERSION_R1Q2_MINIMUM,
- PROTOCOL_VERSION_R1Q2_CURRENT );
+ s = Cmd_Argv(6);
+ if (*s) {
+ version = atoi(s);
+ clamp(version, PROTOCOL_VERSION_R1Q2_MINIMUM,
+ PROTOCOL_VERSION_R1Q2_CURRENT);
} else {
version = PROTOCOL_VERSION_R1Q2_MINIMUM;
}
nctype = NETCHAN_OLD;
ncstring = "";
- } else if( protocol == PROTOCOL_VERSION_Q2PRO ) {
+ } else if (protocol == PROTOCOL_VERSION_Q2PRO) {
// set netchan type
- s = Cmd_Argv( 6 );
- if( *s ) {
- nctype = atoi( s );
- if( nctype == NETCHAN_OLD ) {
+ s = Cmd_Argv(6);
+ if (*s) {
+ nctype = atoi(s);
+ if (nctype == NETCHAN_OLD) {
ncstring = " nc=0";
- } else if( nctype == NETCHAN_NEW ) {
+ } else if (nctype == NETCHAN_NEW) {
ncstring = " nc=1";
} else {
- SV_OobPrintf( "Invalid netchan type.\n" );
- Com_DPrintf( " rejected - bad nctype.\n" );
+ SV_OobPrintf("Invalid netchan type.\n");
+ Com_DPrintf(" rejected - bad nctype.\n");
return;
}
} else {
@@ -712,18 +724,18 @@ static void SVC_DirectConnect( void ) {
}
// set zlib
- s = Cmd_Argv( 7 );
- if( *s && !atoi( s ) ) {
+ s = Cmd_Argv(7);
+ if (*s && !atoi(s)) {
has_zlib = qfalse;
}
// set minor protocol version
- s = Cmd_Argv( 8 );
- if( *s ) {
- version = atoi( s );
- clamp( version, PROTOCOL_VERSION_Q2PRO_MINIMUM,
- PROTOCOL_VERSION_Q2PRO_CURRENT );
- if( version == PROTOCOL_VERSION_Q2PRO_RESERVED ) {
+ s = Cmd_Argv(8);
+ if (*s) {
+ version = atoi(s);
+ clamp(version, PROTOCOL_VERSION_Q2PRO_MINIMUM,
+ PROTOCOL_VERSION_Q2PRO_CURRENT);
+ if (version == PROTOCOL_VERSION_Q2PRO_RESERVED) {
version--; // never use this version
}
} else {
@@ -736,70 +748,69 @@ static void SVC_DirectConnect( void ) {
}
// validate userinfo
- info = Cmd_Argv( 4 );
- if( !info[0] ) {
- SV_OobPrintf( "Empty userinfo string.\n" );
- Com_DPrintf( " rejected - empty userinfo.\n" );
+ info = Cmd_Argv(4);
+ if (!info[0]) {
+ SV_OobPrintf("Empty userinfo string.\n");
+ Com_DPrintf(" rejected - empty userinfo.\n");
return;
}
- if( !Info_Validate( info ) ) {
- SV_OobPrintf( "Malformed userinfo string.\n" );
- Com_DPrintf( " rejected - malformed userinfo.\n" );
+ if (!Info_Validate(info)) {
+ SV_OobPrintf("Malformed userinfo string.\n");
+ Com_DPrintf(" rejected - malformed userinfo.\n");
return;
}
- s = Info_ValueForKey( info, "name" );
- if( COM_IsWhite( s ) ) {
- SV_OobPrintf( "Please set your name before connecting.\n" );
- Com_DPrintf( " rejected - empty name.\n" );
+ s = Info_ValueForKey(info, "name");
+ if (COM_IsWhite(s)) {
+ SV_OobPrintf("Please set your name before connecting.\n");
+ Com_DPrintf(" rejected - empty name.\n");
return;
}
// check password
- s = Info_ValueForKey( info, "password" );
+ s = Info_ValueForKey(info, "password");
reserved = 0;
- if( sv_password->string[0] ) {
- if( !s[0] ) {
- SV_OobPrintf( "Please set your password before connecting.\n" );
- Com_DPrintf( " rejected - empty password.\n" );
+ if (sv_password->string[0]) {
+ if (!s[0]) {
+ SV_OobPrintf("Please set your password before connecting.\n");
+ Com_DPrintf(" rejected - empty password.\n");
return;
}
- if( SV_RateLimited( &svs.ratelimit_auth ) ) {
- SV_OobPrintf( "Invalid password.\n" );
- Com_DPrintf( " rejected - auth attempt limit exceeded.\n" );
+ if (SV_RateLimited(&svs.ratelimit_auth)) {
+ SV_OobPrintf("Invalid password.\n");
+ Com_DPrintf(" rejected - auth attempt limit exceeded.\n");
return;
}
- if( strcmp( sv_password->string, s ) ) {
+ if (strcmp(sv_password->string, s)) {
svs.ratelimit_auth.count++;
- SV_OobPrintf( "Invalid password.\n" );
- Com_DPrintf( " rejected - invalid password.\n" );
+ SV_OobPrintf("Invalid password.\n");
+ Com_DPrintf(" rejected - invalid password.\n");
return;
}
// allow them to use reserved slots
- } else if( !sv_reserved_password->string[0] ||
- strcmp( sv_reserved_password->string, s ) )
- {
+ } else if (!sv_reserved_password->string[0] ||
+ strcmp(sv_reserved_password->string, s)) {
// in no reserved password is set on the server, do not allow
// anyone to access reserved slots at all
reserved = sv_reserved_slots->integer;
}
- Q_strlcpy( userinfo, info, sizeof( userinfo ) );
+ Q_strlcpy(userinfo, info, sizeof(userinfo));
// make sure mvdspec key is not set
- Info_RemoveKey( userinfo, "mvdspec" );
+ Info_RemoveKey(userinfo, "mvdspec");
- if( sv_password->string[0] || sv_reserved_password->string[0] ) {
+ if (sv_password->string[0] || sv_reserved_password->string[0]) {
// unset password key to make game mod happy
- Info_RemoveKey( userinfo, "password" );
+ Info_RemoveKey(userinfo, "password");
}
// force the IP key/value pair so the game can filter based on ip
- s = NET_AdrToString( &net_from );
- if( !Info_SetValueForKey( userinfo, "ip", s ) ) {
- SV_OobPrintf( "Oversize userinfo string.\n" );
- Com_DPrintf( " rejected - oversize userinfo.\n" );
+ s = NET_AdrToString(&net_from);
+ if (!Info_SetValueForKey(userinfo, "ip", s)) {
+ SV_OobPrintf("Oversize userinfo string.\n");
+ Com_DPrintf(" rejected - oversize userinfo.\n");
return;
}
@@ -808,50 +819,49 @@ static void SVC_DirectConnect( void ) {
reconnect_val[0] = 0;
// if there is already a slot for this ip, reuse it
- FOR_EACH_CLIENT( cl ) {
- if( NET_IsEqualAdr( &net_from, &cl->netchan->remote_address ) ) {
- if( cl->state == cs_zombie ) {
- strcpy( reconnect_var, cl->reconnect_var );
- strcpy( reconnect_val, cl->reconnect_val );
+ FOR_EACH_CLIENT(cl) {
+ if (NET_IsEqualAdr(&net_from, &cl->netchan->remote_address)) {
+ if (cl->state == cs_zombie) {
+ strcpy(reconnect_var, cl->reconnect_var);
+ strcpy(reconnect_val, cl->reconnect_val);
} else {
- SV_DropClient( cl, "reconnected" );
+ SV_DropClient(cl, "reconnected");
}
- Com_DPrintf( "%s: reconnect\n", NET_AdrToString( &net_from ) );
- SV_RemoveClient( cl );
+ Com_DPrintf("%s: reconnect\n", NET_AdrToString(&net_from));
+ SV_RemoveClient(cl);
newcl = cl;
break;
}
}
// find a client slot
- if( !newcl ) {
+ if (!newcl) {
// check for forced redirect to a different address
- if( sv_redirect_address->string[0] == '!' &&
- ( !sv_reserved_slots->integer || reserved ) )
- {
- send_redirect_hack( sv_redirect_address->string + 1 );
- Com_DPrintf( " rejected - forced redirect.\n" );
+ if (sv_redirect_address->string[0] == '!' &&
+ (!sv_reserved_slots->integer || reserved)) {
+ send_redirect_hack(sv_redirect_address->string + 1);
+ Com_DPrintf(" rejected - forced redirect.\n");
return;
}
lastcl = svs.client_pool + sv_maxclients->integer - reserved;
- for( newcl = svs.client_pool; newcl < lastcl; newcl++ ) {
- if( !newcl->state ) {
+ for (newcl = svs.client_pool; newcl < lastcl; newcl++) {
+ if (!newcl->state) {
break;
}
}
- if( newcl == lastcl ) {
- if( sv_reserved_slots->integer && !reserved ) {
- SV_OobPrintf( "Server and reserved slots are full.\n" );
- Com_DPrintf( " rejected - reserved slots are full.\n" );
+ if (newcl == lastcl) {
+ if (sv_reserved_slots->integer && !reserved) {
+ SV_OobPrintf("Server and reserved slots are full.\n");
+ Com_DPrintf(" rejected - reserved slots are full.\n");
} else {
// optionally redirect them to a different address
- if( sv_redirect_address->string[0] ) {
- send_redirect_hack( sv_redirect_address->string );
+ if (sv_redirect_address->string[0]) {
+ send_redirect_hack(sv_redirect_address->string);
} else {
- SV_OobPrintf( "Server is full.\n" );
+ SV_OobPrintf("Server is full.\n");
}
- Com_DPrintf( " rejected - server is full.\n" );
+ Com_DPrintf(" rejected - server is full.\n");
}
return;
}
@@ -860,23 +870,23 @@ static void SVC_DirectConnect( void ) {
// build a new connection
// accept the new client
// this is the only place a client_t is ever initialized
- memset( newcl, 0, sizeof( *newcl ) );
+ memset(newcl, 0, sizeof(*newcl));
number = newcl - svs.client_pool;
newcl->number = newcl->slot = number;
newcl->challenge = challenge; // save challenge for checksumming
newcl->protocol = protocol;
newcl->version = version;
newcl->has_zlib = has_zlib;
- newcl->edict = EDICT_NUM( number + 1 );
+ newcl->edict = EDICT_NUM(number + 1);
newcl->gamedir = fs_game->string;
newcl->mapname = sv.name;
- newcl->configstrings = ( char * )sv.configstrings;
- newcl->pool = ( edict_pool_t * )&ge->edicts;
+ newcl->configstrings = (char *)sv.configstrings;
+ newcl->pool = (edict_pool_t *)&ge->edicts;
newcl->cm = &sv.cm;
newcl->spawncount = sv.spawncount;
newcl->maxclients = sv_maxclients->integer;
- strcpy( newcl->reconnect_var, reconnect_var );
- strcpy( newcl->reconnect_val, reconnect_val );
+ strcpy(newcl->reconnect_var, reconnect_var);
+ strcpy(newcl->reconnect_val, reconnect_val);
#if USE_FPS
newcl->framediv = sv.framediv;
newcl->settings[CLS_FPS] = BASE_FRAMERATE;
@@ -888,37 +898,36 @@ static void SVC_DirectConnect( void ) {
// r1q2 extensions
i = 2;
- if( protocol == PROTOCOL_VERSION_R1Q2 ||
- protocol == PROTOCOL_VERSION_Q2PRO )
- {
+ if (protocol == PROTOCOL_VERSION_R1Q2 ||
+ protocol == PROTOCOL_VERSION_Q2PRO) {
newcl->pmp.speedmult = 2;
i = 1;
}
newcl->pmp.strafehack = sv_strafejump_hack->integer >= i ? qtrue : qfalse;
- if( protocol == PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol == PROTOCOL_VERSION_R1Q2) {
newcl->esFlags |= MSG_ES_BEAMORIGIN;
- if( version >= PROTOCOL_VERSION_R1Q2_LONG_SOLID ) {
+ if (version >= PROTOCOL_VERSION_R1Q2_LONG_SOLID) {
newcl->esFlags |= MSG_ES_LONGSOLID;
}
}
// q2pro extensions
i = 2;
- if( protocol == PROTOCOL_VERSION_Q2PRO ) {
- if( sv_qwmod->integer ) {
- PmoveEnableQW( &newcl->pmp );
+ if (protocol == PROTOCOL_VERSION_Q2PRO) {
+ if (sv_qwmod->integer) {
+ PmoveEnableQW(&newcl->pmp);
}
newcl->pmp.flyhack = qtrue;
newcl->pmp.flyfriction = 4;
newcl->esFlags |= MSG_ES_UMASK;
- if( version >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID) {
newcl->esFlags |= MSG_ES_LONGSOLID;
}
- if( version >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN) {
newcl->esFlags |= MSG_ES_BEAMORIGIN;
}
- if( version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK) {
i = 1;
}
}
@@ -927,68 +936,68 @@ static void SVC_DirectConnect( void ) {
// get the game a chance to reject this connection or modify the userinfo
sv_client = newcl;
sv_player = newcl->edict;
- allow = ge->ClientConnect( newcl->edict, userinfo );
+ allow = ge->ClientConnect(newcl->edict, userinfo);
sv_client = NULL;
sv_player = NULL;
- if ( !allow ) {
+ if (!allow) {
char *reason;
- reason = Info_ValueForKey( userinfo, "rejmsg" );
- if( *reason ) {
- SV_OobPrintf( "%s\nConnection refused.\n", reason );
+ reason = Info_ValueForKey(userinfo, "rejmsg");
+ if (*reason) {
+ SV_OobPrintf("%s\nConnection refused.\n", reason);
} else {
- SV_OobPrintf( "Connection refused.\n" );
+ SV_OobPrintf("Connection refused.\n");
}
- Com_DPrintf( " game rejected a connection.\n" );
+ Com_DPrintf(" game rejected a connection.\n");
return;
}
-
+
// setup netchan
- newcl->netchan = Netchan_Setup( NS_SERVER, nctype, &net_from,
- qport, maxlength, protocol );
+ newcl->netchan = Netchan_Setup(NS_SERVER, nctype, &net_from,
+ qport, maxlength, protocol);
newcl->numpackets = 1;
// parse some info from the info strings
- Q_strlcpy( newcl->userinfo, userinfo, sizeof( newcl->userinfo ) );
- SV_UserinfoChanged( newcl );
+ Q_strlcpy(newcl->userinfo, userinfo, sizeof(newcl->userinfo));
+ SV_UserinfoChanged(newcl);
#if USE_AC_SERVER
- if( !sv_force_reconnect->string[0] || reconnect_var[0] ) {
- acstring = AC_ClientConnect( newcl );
+ if (!sv_force_reconnect->string[0] || reconnect_var[0]) {
+ acstring = AC_ClientConnect(newcl);
} else
#endif
{
acstring = "";
}
- if( sv_downloadserver->string[0] ) {
- Q_snprintf( dlstring, sizeof( dlstring ), " dlserver=%s",
- sv_downloadserver->string );
+ if (sv_downloadserver->string[0]) {
+ Q_snprintf(dlstring, sizeof(dlstring), " dlserver=%s",
+ sv_downloadserver->string);
} else {
dlstring[0] = 0;
}
// send the connect packet to the client
- Netchan_OutOfBand( NS_SERVER, &net_from, "client_connect%s%s%s map=%s",
- ncstring, acstring, dlstring, newcl->mapname );
+ Netchan_OutOfBand(NS_SERVER, &net_from, "client_connect%s%s%s map=%s",
+ ncstring, acstring, dlstring, newcl->mapname);
- SV_InitClientSend( newcl );
+ SV_InitClientSend(newcl);
- if( protocol == PROTOCOL_VERSION_DEFAULT ) {
+ if (protocol == PROTOCOL_VERSION_DEFAULT) {
newcl->WriteFrame = SV_WriteFrameToClient_Default;
} else {
newcl->WriteFrame = SV_WriteFrameToClient_Enhanced;
}
// loopback client doesn't need to reconnect
- if( NET_IsLocalAddress( &net_from ) ) {
+ if (NET_IsLocalAddress(&net_from)) {
newcl->reconnected = qtrue;
}
// add them to the linked list of connected clients
- List_SeqAdd( &sv_clientlist, &newcl->entry );
+ List_SeqAdd(&sv_clientlist, &newcl->entry);
- Com_DPrintf( "Going from cs_free to cs_assigned for %s\n", newcl->name );
+ Com_DPrintf("Going from cs_free to cs_assigned for %s\n", newcl->name);
newcl->state = cs_assigned;
newcl->framenum = 1; // frame 0 can't be used
newcl->lastframe = -1;
@@ -996,12 +1005,12 @@ static void SVC_DirectConnect( void ) {
newcl->min_ping = 9999;
}
-static int Rcon_Validate (void)
+static int Rcon_Validate(void)
{
if (!rcon_password->string[0])
return 0;
- if (strcmp (Cmd_Argv(1), rcon_password->string) )
+ if (strcmp(Cmd_Argv(1), rcon_password->string))
return 0;
return 1;
@@ -1015,32 +1024,33 @@ A client issued an rcon command.
Redirect all printfs.
===============
*/
-static void SVC_RemoteCommand( void ) {
+static void SVC_RemoteCommand(void)
+{
int i;
char *string;
- if( SV_RateLimited( &svs.ratelimit_rcon ) ) {
- Com_DPrintf( "Dropping rcon from %s\n",
- NET_AdrToString( &net_from ) );
+ if (SV_RateLimited(&svs.ratelimit_rcon)) {
+ Com_DPrintf("Dropping rcon from %s\n",
+ NET_AdrToString(&net_from));
return;
}
i = Rcon_Validate();
- string = Cmd_RawArgsFrom( 2 );
- if( i == 0 ) {
- Com_Printf( "Invalid rcon from %s:\n%s\n",
- NET_AdrToString( &net_from ), string );
- SV_OobPrintf( "Bad rcon_password.\n" );
+ string = Cmd_RawArgsFrom(2);
+ if (i == 0) {
+ Com_Printf("Invalid rcon from %s:\n%s\n",
+ NET_AdrToString(&net_from), string);
+ SV_OobPrintf("Bad rcon_password.\n");
svs.ratelimit_rcon.count++;
return;
}
- Com_Printf( "Rcon from %s:\n%s\n",
- NET_AdrToString( &net_from ), string );
+ Com_Printf("Rcon from %s:\n%s\n",
+ NET_AdrToString(&net_from), string);
- SV_BeginRedirect( RD_PACKET );
+ SV_BeginRedirect(RD_PACKET);
- Cmd_ExecuteString( &cmd_buffer, string );
+ Cmd_ExecuteString(&cmd_buffer, string);
Com_EndRedirect();
}
@@ -1065,60 +1075,62 @@ Clients that are in the game can still send
connectionless packets.
=================
*/
-static void SV_ConnectionlessPacket( void ) {
+static void SV_ConnectionlessPacket(void)
+{
char string[MAX_STRING_CHARS];
char *c;
int i;
size_t len;
- if( SV_MatchAddress( &sv_blacklist, &net_from ) ) {
- Com_DPrintf( "ignored blackholed connectionless packet\n" );
+ if (SV_MatchAddress(&sv_blacklist, &net_from)) {
+ Com_DPrintf("ignored blackholed connectionless packet\n");
return;
}
MSG_BeginReading();
MSG_ReadLong(); // skip the -1 marker
- len = MSG_ReadStringLine( string, sizeof( string ) );
- if( len >= sizeof( string ) ) {
- Com_DPrintf( "ignored oversize connectionless packet\n" );
+ len = MSG_ReadStringLine(string, sizeof(string));
+ if (len >= sizeof(string)) {
+ Com_DPrintf("ignored oversize connectionless packet\n");
return;
}
- Cmd_TokenizeString( string, qfalse );
+ Cmd_TokenizeString(string, qfalse);
- c = Cmd_Argv( 0 );
- Com_DPrintf( "ServerPacket[%s]: %s\n", NET_AdrToString( &net_from ), c );
+ c = Cmd_Argv(0);
+ Com_DPrintf("ServerPacket[%s]: %s\n", NET_AdrToString(&net_from), c);
- if( !strcmp( c, "rcon" ) ) {
+ if (!strcmp(c, "rcon")) {
SVC_RemoteCommand();
return; // accept rcon commands even if not active
}
- if( !svs.initialized ) {
- Com_DPrintf( "ignored connectionless packet\n" );
+ if (!svs.initialized) {
+ Com_DPrintf("ignored connectionless packet\n");
return;
}
- for( i = 0; svcmds[i].name; i++ ) {
- if( !strcmp( c, svcmds[i].name ) ) {
+ for (i = 0; svcmds[i].name; i++) {
+ if (!strcmp(c, svcmds[i].name)) {
svcmds[i].func();
return;
}
}
- Com_DPrintf( "bad connectionless packet\n" );
+ Com_DPrintf("bad connectionless packet\n");
}
//============================================================================
-int SV_CountClients( void ) {
+int SV_CountClients(void)
+{
client_t *cl;
int count = 0;
- FOR_EACH_CLIENT( cl ) {
- if( cl->state > cs_zombie ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state > cs_zombie) {
count++;
}
}
@@ -1126,38 +1138,41 @@ int SV_CountClients( void ) {
return count;
}
-static int ping_nop( client_t *cl ) {
+static int ping_nop(client_t *cl)
+{
return 0;
}
-static int ping_min( client_t *cl ) {
+static int ping_min(client_t *cl)
+{
client_frame_t *frame;
int i, j, count = INT_MAX;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
+ for (i = 0; i < UPDATE_BACKUP; i++) {
j = cl->framenum - i - 1;
frame = &cl->frames[j & UPDATE_MASK];
- if( frame->number != j )
+ if (frame->number != j)
continue;
- if( frame->latency == -1 )
+ if (frame->latency == -1)
continue;
- if( count > frame->latency )
+ if (count > frame->latency)
count = frame->latency;
}
return count == INT_MAX ? 0 : count;
}
-static int ping_avg( client_t *cl ) {
+static int ping_avg(client_t *cl)
+{
client_frame_t *frame;
int i, j, total = 0, count = 0;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
+ for (i = 0; i < UPDATE_BACKUP; i++) {
j = cl->framenum - i - 1;
frame = &cl->frames[j & UPDATE_MASK];
- if( frame->number != j )
+ if (frame->number != j)
continue;
- if( frame->latency == -1 )
+ if (frame->latency == -1)
continue;
count++;
total += frame->latency;
@@ -1173,35 +1188,36 @@ SV_CalcPings
Updates the cl->ping and cl->fps variables
===================
*/
-static void SV_CalcPings( void ) {
+static void SV_CalcPings(void)
+{
client_t *cl;
- int (*calc)( client_t * );
+ int (*calc)(client_t *);
int res;
- switch( sv_calcpings_method->integer ) {
+ switch (sv_calcpings_method->integer) {
case 0: calc = ping_nop; break;
case 2: calc = ping_min; break;
default: calc = ping_avg; break;
}
// update avg ping and fps every 10 seconds
- res = sv.framenum % ( 10 * SV_FRAMERATE );
+ res = sv.framenum % (10 * SV_FRAMERATE);
- FOR_EACH_CLIENT( cl ) {
- if( cl->state == cs_spawned ) {
- cl->ping = calc( cl );
- if( cl->ping ) {
- if( cl->ping < cl->min_ping ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state == cs_spawned) {
+ cl->ping = calc(cl);
+ if (cl->ping) {
+ if (cl->ping < cl->min_ping) {
cl->min_ping = cl->ping;
- } else if( cl->ping > cl->max_ping ) {
+ } else if (cl->ping > cl->max_ping) {
cl->max_ping = cl->ping;
}
- if( !res ) {
+ if (!res) {
cl->avg_ping_time += cl->ping;
cl->avg_ping_count++;
}
}
- if( !res ) {
+ if (!res) {
cl->fps = cl->numMoves / 10;
cl->numMoves = 0;
}
@@ -1225,13 +1241,14 @@ Every few frames, gives all clients an allotment of milliseconds
for their command moves. If they exceed it, assume cheating.
===================
*/
-static void SV_GiveMsec( void ) {
+static void SV_GiveMsec(void)
+{
client_t *cl;
- if( sv.framenum % ( 16 * SV_FRAMEDIV ) )
+ if (sv.framenum % (16 * SV_FRAMEDIV))
return;
- FOR_EACH_CLIENT( cl ) {
+ FOR_EACH_CLIENT(cl) {
cl->commandMsec = 1800; // 1600 + some slop
}
}
@@ -1242,57 +1259,58 @@ static void SV_GiveMsec( void ) {
SV_PacketEvent
=================
*/
-static void SV_PacketEvent( void ) {
+static void SV_PacketEvent(void)
+{
client_t *client;
netchan_t *netchan;
int qport;
-
+
// check for connectionless packet (0xffffffff) first
// connectionless packets are processed even if the server is down
- if( *( int * )msg_read.data == -1 ) {
+ if (*(int *)msg_read.data == -1) {
SV_ConnectionlessPacket();
return;
}
- if( !svs.initialized ) {
+ if (!svs.initialized) {
return;
}
// check for packets from connected clients
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
netchan = client->netchan;
- if( !NET_IsEqualBaseAdr( &net_from, &netchan->remote_address ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &netchan->remote_address)) {
continue;
}
// read the qport out of the message so we can fix up
// stupid address translating routers
- if( client->protocol == PROTOCOL_VERSION_DEFAULT ) {
- qport = msg_read.data[8] | ( msg_read.data[9] << 8 );
- if( netchan->qport != qport ) {
+ if (client->protocol == PROTOCOL_VERSION_DEFAULT) {
+ qport = msg_read.data[8] | (msg_read.data[9] << 8);
+ if (netchan->qport != qport) {
continue;
}
- } else if( netchan->qport ) {
+ } else if (netchan->qport) {
qport = msg_read.data[8];
- if( netchan->qport != qport ) {
+ if (netchan->qport != qport) {
continue;
}
} else {
- if( netchan->remote_address.port != net_from.port ) {
+ if (netchan->remote_address.port != net_from.port) {
continue;
}
}
- if( netchan->remote_address.port != net_from.port ) {
- Com_DPrintf( "Fixing up a translated port for %s: %d --> %d\n",
- client->name, netchan->remote_address.port, net_from.port );
+ if (netchan->remote_address.port != net_from.port) {
+ Com_DPrintf("Fixing up a translated port for %s: %d --> %d\n",
+ client->name, netchan->remote_address.port, net_from.port);
netchan->remote_address.port = net_from.port;
}
- if( !netchan->Process( netchan ) )
+ if (!netchan->Process(netchan))
break;
- if( client->state == cs_zombie )
+ if (client->state == cs_zombie)
break;
// this is a valid, sequenced packet, so process it
@@ -1300,10 +1318,10 @@ static void SV_PacketEvent( void ) {
#if USE_ICMP
client->unreachable = qfalse; // don't drop
#endif
- if( netchan->dropped > 0 )
+ if (netchan->dropped > 0)
client->frameflags |= FF_CLIENTDROP;
- SV_ExecuteClientMessage( client );
+ SV_ExecuteClientMessage(client);
break;
}
}
@@ -1314,42 +1332,42 @@ static void SV_PacketEvent( void ) {
SV_ErrorEvent
=================
*/
-void SV_ErrorEvent( int info ) {
+void SV_ErrorEvent(int info)
+{
client_t *client;
netchan_t *netchan;
- if( !svs.initialized ) {
+ if (!svs.initialized) {
return;
}
// check for errors from connected clients
- FOR_EACH_CLIENT( client ) {
- if( client->state == cs_zombie ) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state == cs_zombie) {
continue; // already a zombie
}
netchan = client->netchan;
- if( !NET_IsEqualBaseAdr( &net_from, &netchan->remote_address ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &netchan->remote_address)) {
continue;
}
- if( net_from.port && netchan->remote_address.port != net_from.port ) {
+ if (net_from.port && netchan->remote_address.port != net_from.port) {
continue;
}
#if USE_PMTUDISC
- if( info ) {
+ if (info) {
// we are doing path MTU discovery and got ICMP fragmentation-needed
// update MTU only for connecting clients to minimize spoofed ICMP interference
// MTU info has already been sanity checked for us by network code
// assume total 64 bytes of headers
- if( client->state == cs_primed &&
+ if (client->state == cs_primed &&
netchan->reliable_length &&
- info < netchan->maxpacketlen + 64 )
- {
- if( netchan->type == NETCHAN_OLD ) {
+ info < netchan->maxpacketlen + 64) {
+ if (netchan->type == NETCHAN_OLD) {
// TODO: old clients require entire queue flush :(
continue;
}
- Com_Printf( "Fixing up maxmsglen for %s: %d --> %d\n",
- client->name, (int)netchan->maxpacketlen, info - 64 );
+ Com_Printf("Fixing up maxmsglen for %s: %d --> %d\n",
+ client->name, (int)netchan->maxpacketlen, info - 64);
netchan->maxpacketlen = info - 64;
}
continue;
@@ -1361,19 +1379,20 @@ void SV_ErrorEvent( int info ) {
}
#endif
-static void SV_ReadPackets( void ) {
+static void SV_ReadPackets(void)
+{
#if USE_CLIENT
- memset( &net_from, 0, sizeof( net_from ) );
+ memset(&net_from, 0, sizeof(net_from));
net_from.type = NA_LOOPBACK;
// process loopback packets
- while( NET_GetLoopPacket( NS_SERVER ) ) {
+ while (NET_GetLoopPacket(NS_SERVER)) {
SV_PacketEvent();
}
#endif
// process network packets
- while( NET_GetPacket( NS_SERVER ) ) {
+ while (NET_GetPacket(NS_SERVER)) {
SV_PacketEvent();
}
}
@@ -1391,47 +1410,48 @@ for a few seconds to make sure any final reliable message gets resent
if necessary
==================
*/
-static void SV_CheckTimeouts( void ) {
+static void SV_CheckTimeouts(void)
+{
client_t *client;
unsigned zombie_time = 1000 * sv_zombietime->value;
unsigned drop_time = 1000 * sv_timeout->value;
unsigned ghost_time = 1000 * sv_ghostime->value;
unsigned delta;
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
// never timeout local clients
- if( NET_IsLocalAddress( &client->netchan->remote_address ) ) {
+ if (NET_IsLocalAddress(&client->netchan->remote_address)) {
continue;
}
// NOTE: delta calculated this way is not sensitive to overflow
delta = svs.realtime - client->lastmessage;
- if( client->state == cs_zombie ) {
- if( delta > zombie_time ) {
- SV_RemoveClient( client );
+ if (client->state == cs_zombie) {
+ if (delta > zombie_time) {
+ SV_RemoveClient(client);
}
continue;
}
- if( client->drop_hack ) {
- SV_DropClient( client, NULL );
+ if (client->drop_hack) {
+ SV_DropClient(client, NULL);
continue;
}
#if USE_ICMP
- if( client->unreachable ) {
- if( delta > ghost_time ) {
- SV_DropClient( client, "connection reset by peer" );
- SV_RemoveClient( client ); // don't bother with zombie state
+ if (client->unreachable) {
+ if (delta > ghost_time) {
+ SV_DropClient(client, "connection reset by peer");
+ SV_RemoveClient(client); // don't bother with zombie state
continue;
}
}
#endif
- if( delta > drop_time || ( client->state == cs_assigned && delta > ghost_time ) ) {
- SV_DropClient( client, "?timed out" );
- SV_RemoveClient( client ); // don't bother with zombie state
+ if (delta > drop_time || (client->state == cs_assigned && delta > ghost_time)) {
+ SV_DropClient(client, "?timed out");
+ SV_RemoveClient(client); // don't bother with zombie state
continue;
}
- if( client->frames_nodelta > 64 && !sv_allow_nodelta->integer ) {
- SV_DropClient( client, "too many nodelta frames" );
+ if (client->frames_nodelta > 64 && !sv_allow_nodelta->integer) {
+ SV_DropClient(client, "too many nodelta frames");
continue;
}
}
@@ -1445,12 +1465,13 @@ This has to be done before the world logic, because
player processing happens outside RunWorldFrame
================
*/
-static void SV_PrepWorldFrame( void ) {
+static void SV_PrepWorldFrame(void)
+{
edict_t *ent;
int i;
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
+ if (sv.state == ss_broadcast) {
MVD_PrepWorldFrame();
return;
}
@@ -1458,47 +1479,48 @@ static void SV_PrepWorldFrame( void ) {
sv.tracecount = 0;
- if( !SV_FRAMESYNC )
+ if (!SV_FRAMESYNC)
return;
- for( i = 1; i < ge->num_edicts; i++ ) {
- ent = EDICT_NUM( i );
+ for (i = 1; i < ge->num_edicts; i++) {
+ ent = EDICT_NUM(i);
// events only last for a single keyframe
ent->s.event = 0;
- }
+ }
}
// pause if there is only local client on the server
-static inline qboolean check_paused( void ) {
+static inline qboolean check_paused(void)
+{
#if USE_CLIENT
- if( dedicated->integer )
+ if (dedicated->integer)
goto resume;
- if( !cl_paused->integer )
+ if (!cl_paused->integer)
goto resume;
- if( com_timedemo->integer )
+ if (com_timedemo->integer)
goto resume;
- if( !LIST_SINGLE( &sv_clientlist ) )
+ if (!LIST_SINGLE(&sv_clientlist))
goto resume;
#if USE_MVD_CLIENT
- if( !LIST_EMPTY( &mvd_gtv_list ) )
+ if (!LIST_EMPTY(&mvd_gtv_list))
goto resume;
#endif
- if( !sv_paused->integer ) {
- Cvar_Set( "sv_paused", "1" );
+ if (!sv_paused->integer) {
+ Cvar_Set("sv_paused", "1");
IN_Activate();
}
return qtrue; // don't run if paused
resume:
- if( sv_paused->integer ) {
- Cvar_Set( "sv_paused", "0" );
+ if (sv_paused->integer) {
+ Cvar_Set("sv_paused", "0");
IN_Activate();
}
#endif
@@ -1511,14 +1533,15 @@ resume:
SV_RunGameFrame
=================
*/
-static void SV_RunGameFrame( void ) {
+static void SV_RunGameFrame(void)
+{
#if USE_MVD_SERVER
// save the entire world state if recording a serverdemo
SV_MvdBeginFrame();
#endif
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_before_game = Sys_Milliseconds();
#endif
@@ -1530,15 +1553,15 @@ static void SV_RunGameFrame( void ) {
X86_POP_FPCW;
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_after_game = Sys_Milliseconds();
#endif
- if( msg_write.cursize ) {
- Com_WPrintf( "Game left %"PRIz" bytes "
- "in multicast buffer, cleared.\n",
- msg_write.cursize );
- SZ_Clear( &msg_write );
+ if (msg_write.cursize) {
+ Com_WPrintf("Game left %"PRIz" bytes "
+ "in multicast buffer, cleared.\n",
+ msg_write.cursize);
+ SZ_Clear(&msg_write);
}
#if USE_MVD_SERVER
@@ -1555,35 +1578,36 @@ Send a message to the master every few minutes to
let it know we are alive, and log information
================
*/
-static void SV_MasterHeartbeat( void ) {
+static void SV_MasterHeartbeat(void)
+{
char buffer[MAX_PACKETLEN_DEFAULT];
size_t len;
master_t *m;
- if( !Com_IsDedicated() )
+ if (!Com_IsDedicated())
return; // only dedicated servers send heartbeats
- if( !sv_public->integer )
+ if (!sv_public->integer)
return; // a private dedicated game
- if( svs.realtime - svs.last_heartbeat < HEARTBEAT_SECONDS*1000 )
+ if (svs.realtime - svs.last_heartbeat < HEARTBEAT_SECONDS * 1000)
return; // not time to send yet
svs.last_heartbeat = svs.realtime;
// write the packet header
- memcpy( buffer, "\xff\xff\xff\xffheartbeat\n", 14 );
+ memcpy(buffer, "\xff\xff\xff\xffheartbeat\n", 14);
len = 14;
// send the same string that we would give for a status OOB command
- len += SV_StatusString( buffer + len );
+ len += SV_StatusString(buffer + len);
// send to group master
- FOR_EACH_MASTER( m ) {
- if( m->adr.port ) {
- Com_DPrintf( "Sending heartbeat to %s\n",
- NET_AdrToString( &m->adr ) );
- NET_SendPacket( NS_SERVER, &m->adr, len, buffer );
+ FOR_EACH_MASTER(m) {
+ if (m->adr.port) {
+ Com_DPrintf("Sending heartbeat to %s\n",
+ NET_AdrToString(&m->adr));
+ NET_SendPacket(NS_SERVER, &m->adr, len, buffer);
}
}
}
@@ -1595,26 +1619,27 @@ SV_MasterShutdown
Informs all masters that this server is going down
=================
*/
-static void SV_MasterShutdown( void ) {
+static void SV_MasterShutdown(void)
+{
master_t *m;
// reset ack times
- FOR_EACH_MASTER( m ) {
+ FOR_EACH_MASTER(m) {
m->last_ack = 0;
}
- if( !Com_IsDedicated() )
+ if (!Com_IsDedicated())
return; // only dedicated servers send heartbeats
- if( !sv_public || !sv_public->integer )
+ if (!sv_public || !sv_public->integer)
return; // a private dedicated game
// send to group master
- FOR_EACH_MASTER( m ) {
- if( m->adr.port ) {
- Com_DPrintf( "Sending shutdown to %s\n",
- NET_AdrToString( &m->adr ) );
- OOB_PRINT( NS_SERVER, &m->adr, "shutdown" );
+ FOR_EACH_MASTER(m) {
+ if (m->adr.port) {
+ Com_DPrintf("Sending shutdown to %s\n",
+ NET_AdrToString(&m->adr));
+ OOB_PRINT(NS_SERVER, &m->adr, "shutdown");
}
}
}
@@ -1629,7 +1654,8 @@ processing are run even when server is not yet initalized.
Returns amount of extra frametime available for sleeping on IO.
==================
*/
-unsigned SV_Frame( unsigned msec ) {
+unsigned SV_Frame(unsigned msec)
+{
#if USE_CLIENT
time_before_game = time_after_game = 0;
#endif
@@ -1637,9 +1663,9 @@ unsigned SV_Frame( unsigned msec ) {
// advance local server time
svs.realtime += msec;
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// process console commands if not running a client
- Cbuf_Execute( &cmd_buffer );
+ Cbuf_Execute(&cmd_buffer);
}
#if USE_MVD_CLIENT
@@ -1650,7 +1676,7 @@ unsigned SV_Frame( unsigned msec ) {
// read packets from UDP clients
SV_ReadPackets();
- if( svs.initialized ) {
+ if (svs.initialized) {
#if USE_AC_SERVER
// run connection to the anticheat server
AC_Run();
@@ -1667,11 +1693,11 @@ unsigned SV_Frame( unsigned msec ) {
// move autonomous things around if enough time has passed
sv.frameresidual += msec;
- if( sv.frameresidual < SV_FRAMETIME ) {
+ if (sv.frameresidual < SV_FRAMETIME) {
return SV_FRAMETIME - sv.frameresidual;
}
- if( svs.initialized && !check_paused() ) {
+ if (svs.initialized && !check_paused()) {
// check timeouts
SV_CheckTimeouts();
@@ -1697,22 +1723,22 @@ unsigned SV_Frame( unsigned msec ) {
sv.framenum++;
}
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// run cmd buffer in dedicated mode
- if( cmd_buffer.waitCount > 0 ) {
+ if (cmd_buffer.waitCount > 0) {
cmd_buffer.waitCount--;
}
}
// decide how long to sleep next frame
sv.frameresidual -= SV_FRAMETIME;
- if( sv.frameresidual < SV_FRAMETIME ) {
+ if (sv.frameresidual < SV_FRAMETIME) {
return SV_FRAMETIME - sv.frameresidual;
}
// don't accumulate bogus residual
- if( sv.frameresidual > 250 ) {
- Com_DDDPrintf( "Reset residual %u\n", sv.frameresidual );
+ if (sv.frameresidual > 250) {
+ Com_DDDPrintf("Reset residual %u\n", sv.frameresidual);
sv.frameresidual = 100;
}
@@ -1729,67 +1755,67 @@ Pull specific info from a newly changed userinfo string
into a more C freindly form.
=================
*/
-void SV_UserinfoChanged( client_t *cl ) {
+void SV_UserinfoChanged(client_t *cl)
+{
char name[MAX_CLIENT_NAME];
char *val;
size_t len;
int i;
// call prog code to allow overrides
- ge->ClientUserinfoChanged( cl->edict, cl->userinfo );
+ ge->ClientUserinfoChanged(cl->edict, cl->userinfo);
// name for C code
- val = Info_ValueForKey( cl->userinfo, "name" );
- len = Q_strlcpy( name, val, sizeof( name ) );
- if( len >= sizeof( name ) ) {
- len = sizeof( name ) - 1;
+ val = Info_ValueForKey(cl->userinfo, "name");
+ len = Q_strlcpy(name, val, sizeof(name));
+ if (len >= sizeof(name)) {
+ len = sizeof(name) - 1;
}
// mask off high bit
- for( i = 0; i < len; i++ )
+ for (i = 0; i < len; i++)
name[i] &= 127;
- if( cl->name[0] && strcmp( cl->name, name ) ) {
- if( Com_IsDedicated() ) {
- Com_Printf( "%s[%s] changed name to %s\n", cl->name,
- NET_AdrToString( &cl->netchan->remote_address ), name );
+ if (cl->name[0] && strcmp(cl->name, name)) {
+ if (Com_IsDedicated()) {
+ Com_Printf("%s[%s] changed name to %s\n", cl->name,
+ NET_AdrToString(&cl->netchan->remote_address), name);
}
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
- MVD_GameClientNameChanged( cl->edict, name );
+ if (sv.state == ss_broadcast) {
+ MVD_GameClientNameChanged(cl->edict, name);
} else
#endif
- if( sv_show_name_changes->integer ) {
- SV_BroadcastPrintf( PRINT_HIGH, "%s changed name to %s\n",
- cl->name, name );
- }
+ if (sv_show_name_changes->integer) {
+ SV_BroadcastPrintf(PRINT_HIGH, "%s changed name to %s\n",
+ cl->name, name);
+ }
}
- memcpy( cl->name, name, len + 1 );
+ memcpy(cl->name, name, len + 1);
// rate command
- val = Info_ValueForKey( cl->userinfo, "rate" );
- if( *val ) {
- cl->rate = atoi( val );
- clamp( cl->rate, 100, 15000 );
+ val = Info_ValueForKey(cl->userinfo, "rate");
+ if (*val) {
+ cl->rate = atoi(val);
+ clamp(cl->rate, 100, 15000);
} else {
cl->rate = 5000;
}
// never drop over the loopback
- if( NET_IsLocalAddress( &cl->netchan->remote_address ) ) {
+ if (NET_IsLocalAddress(&cl->netchan->remote_address)) {
cl->rate = 0;
}
// don't drop over LAN connections
- if( sv_lan_force_rate->integer &&
- NET_IsLanAddress( &cl->netchan->remote_address ) )
- {
+ if (sv_lan_force_rate->integer &&
+ NET_IsLanAddress(&cl->netchan->remote_address)) {
cl->rate = 0;
}
// msg command
- val = Info_ValueForKey( cl->userinfo, "msg" );
- if( *val ) {
- cl->messagelevel = atoi( val );
- clamp( cl->messagelevel, PRINT_LOW, PRINT_CHAT + 1 );
+ val = Info_ValueForKey(cl->userinfo, "msg");
+ if (*val) {
+ cl->messagelevel = atoi(val);
+ clamp(cl->messagelevel, PRINT_LOW, PRINT_CHAT + 1);
}
}
@@ -1797,45 +1823,53 @@ void SV_UserinfoChanged( client_t *cl ) {
//============================================================================
#if USE_SYSCON
-void SV_SetConsoleTitle( void ) {
+void SV_SetConsoleTitle(void)
+{
char buffer[MAX_STRING_CHARS];
- Q_snprintf( buffer, sizeof( buffer ), "%s (port %d%s)",
- sv_hostname->string, net_port->integer,
- sv_running->integer ? "" : ", down" );
+ Q_snprintf(buffer, sizeof(buffer), "%s (port %d%s)",
+ sv_hostname->string, net_port->integer,
+ sv_running->integer ? "" : ", down");
- Sys_SetConsoleTitle( buffer );
+ Sys_SetConsoleTitle(buffer);
}
#endif
-static void sv_status_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_status, self->string );
+static void sv_status_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_status, self->string);
}
-static void sv_auth_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_auth, self->string );
+static void sv_auth_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_auth, self->string);
}
-static void sv_rcon_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_rcon, self->string );
+static void sv_rcon_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_rcon, self->string);
}
-static void init_rate_limits( void ) {
- SV_RateInit( &svs.ratelimit_status, sv_status_limit->string );
- SV_RateInit( &svs.ratelimit_auth, sv_auth_limit->string );
- SV_RateInit( &svs.ratelimit_rcon, sv_rcon_limit->string );
+static void init_rate_limits(void)
+{
+ SV_RateInit(&svs.ratelimit_status, sv_status_limit->string);
+ SV_RateInit(&svs.ratelimit_auth, sv_auth_limit->string);
+ SV_RateInit(&svs.ratelimit_rcon, sv_rcon_limit->string);
}
#if USE_SYSCON
-static void sv_hostname_changed( cvar_t *self ) {
+static void sv_hostname_changed(cvar_t *self)
+{
SV_SetConsoleTitle();
}
#endif
#if USE_ZLIB
-voidpf SV_Zalloc OF(( voidpf opaque, uInt items, uInt size )) {
- return SV_Malloc( items * size );
+voidpf SV_Zalloc OF((voidpf opaque, uInt items, uInt size))
+{
+ return SV_Malloc(items * size);
}
-void SV_Zfree OF(( voidpf opaque, voidpf address )) {
- Z_Free( address );
+void SV_Zfree OF((voidpf opaque, voidpf address))
+{
+ Z_Free(address);
}
#endif
@@ -1846,7 +1880,8 @@ SV_Init
Only called at quake2.exe startup, not for each game
===============
*/
-void SV_Init( void ) {
+void SV_Init(void)
+{
SV_InitOperatorCommands();
#if USE_MVD_SERVER
@@ -1861,89 +1896,89 @@ void SV_Init( void ) {
AC_Register();
#endif
- Cvar_Get( "protocol", va( "%i", PROTOCOL_VERSION_DEFAULT ), CVAR_SERVERINFO|CVAR_ROM );
-
- Cvar_Get( "skill", "1", CVAR_LATCH );
- Cvar_Get( "deathmatch", "1", CVAR_SERVERINFO|CVAR_LATCH );
- Cvar_Get( "coop", "0", /*CVAR_SERVERINFO|*/CVAR_LATCH );
- Cvar_Get( "cheats", "0", CVAR_SERVERINFO|CVAR_LATCH );
- Cvar_Get( "dmflags", va( "%i", DF_INSTANT_ITEMS ), CVAR_SERVERINFO );
- Cvar_Get( "fraglimit", "0", CVAR_SERVERINFO );
- Cvar_Get( "timelimit", "0", CVAR_SERVERINFO );
-
- sv_maxclients = Cvar_Get( "maxclients", "8", CVAR_SERVERINFO|CVAR_LATCH );
- sv_reserved_slots = Cvar_Get( "sv_reserved_slots", "0", CVAR_LATCH );
- sv_hostname = Cvar_Get( "hostname", "noname", CVAR_SERVERINFO|CVAR_ARCHIVE );
+ Cvar_Get("protocol", va("%i", PROTOCOL_VERSION_DEFAULT), CVAR_SERVERINFO | CVAR_ROM);
+
+ Cvar_Get("skill", "1", CVAR_LATCH);
+ Cvar_Get("deathmatch", "1", CVAR_SERVERINFO | CVAR_LATCH);
+ Cvar_Get("coop", "0", /*CVAR_SERVERINFO|*/CVAR_LATCH);
+ Cvar_Get("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
+ Cvar_Get("dmflags", va("%i", DF_INSTANT_ITEMS), CVAR_SERVERINFO);
+ Cvar_Get("fraglimit", "0", CVAR_SERVERINFO);
+ Cvar_Get("timelimit", "0", CVAR_SERVERINFO);
+
+ sv_maxclients = Cvar_Get("maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
+ sv_reserved_slots = Cvar_Get("sv_reserved_slots", "0", CVAR_LATCH);
+ sv_hostname = Cvar_Get("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
#if USE_SYSCON
sv_hostname->changed = sv_hostname_changed;
#endif
- sv_timeout = Cvar_Get( "timeout", "90", 0 );
- sv_zombietime = Cvar_Get( "zombietime", "2", 0 );
- sv_ghostime = Cvar_Get( "sv_ghostime", "6", 0 );
- sv_showclamp = Cvar_Get( "showclamp", "0", 0 );
- sv_enforcetime = Cvar_Get( "sv_enforcetime", "1", 0 );
- sv_allow_nodelta = Cvar_Get( "sv_allow_nodelta", "1", 0 );
+ sv_timeout = Cvar_Get("timeout", "90", 0);
+ sv_zombietime = Cvar_Get("zombietime", "2", 0);
+ sv_ghostime = Cvar_Get("sv_ghostime", "6", 0);
+ sv_showclamp = Cvar_Get("showclamp", "0", 0);
+ sv_enforcetime = Cvar_Get("sv_enforcetime", "1", 0);
+ sv_allow_nodelta = Cvar_Get("sv_allow_nodelta", "1", 0);
#if USE_FPS
- sv_fps = Cvar_Get( "sv_fps", "10", CVAR_LATCH );
+ sv_fps = Cvar_Get("sv_fps", "10", CVAR_LATCH);
#endif
- sv_force_reconnect = Cvar_Get( "sv_force_reconnect", "", CVAR_LATCH );
- sv_show_name_changes = Cvar_Get( "sv_show_name_changes", "0", 0 );
+ sv_force_reconnect = Cvar_Get("sv_force_reconnect", "", CVAR_LATCH);
+ sv_show_name_changes = Cvar_Get("sv_show_name_changes", "0", 0);
sv_airaccelerate = Cvar_Get("sv_airaccelerate", "0", CVAR_LATCH);
- sv_qwmod = Cvar_Get( "sv_qwmod", "0", CVAR_LATCH ); //atu QWMod
- sv_public = Cvar_Get( "public", "0", CVAR_LATCH );
- sv_password = Cvar_Get( "sv_password", "", CVAR_PRIVATE );
- sv_reserved_password = Cvar_Get( "sv_reserved_password", "", CVAR_PRIVATE );
- sv_locked = Cvar_Get( "sv_locked", "0", 0 );
- sv_novis = Cvar_Get ("sv_novis", "0", 0);
- sv_downloadserver = Cvar_Get( "sv_downloadserver", "", 0 );
- sv_redirect_address = Cvar_Get( "sv_redirect_address", "", 0 );
+ sv_qwmod = Cvar_Get("sv_qwmod", "0", CVAR_LATCH); //atu QWMod
+ sv_public = Cvar_Get("public", "0", CVAR_LATCH);
+ sv_password = Cvar_Get("sv_password", "", CVAR_PRIVATE);
+ sv_reserved_password = Cvar_Get("sv_reserved_password", "", CVAR_PRIVATE);
+ sv_locked = Cvar_Get("sv_locked", "0", 0);
+ sv_novis = Cvar_Get("sv_novis", "0", 0);
+ sv_downloadserver = Cvar_Get("sv_downloadserver", "", 0);
+ sv_redirect_address = Cvar_Get("sv_redirect_address", "", 0);
#ifdef _DEBUG
- sv_debug = Cvar_Get( "sv_debug", "0", 0 );
- sv_pad_packets = Cvar_Get( "sv_pad_packets", "0", 0 );
+ sv_debug = Cvar_Get("sv_debug", "0", 0);
+ sv_pad_packets = Cvar_Get("sv_pad_packets", "0", 0);
#endif
- sv_lan_force_rate = Cvar_Get( "sv_lan_force_rate", "0", CVAR_LATCH );
- sv_calcpings_method = Cvar_Get( "sv_calcpings_method", "1", 0 );
- sv_changemapcmd = Cvar_Get( "sv_changemapcmd", "", 0 );
+ sv_lan_force_rate = Cvar_Get("sv_lan_force_rate", "0", CVAR_LATCH);
+ sv_calcpings_method = Cvar_Get("sv_calcpings_method", "1", 0);
+ sv_changemapcmd = Cvar_Get("sv_changemapcmd", "", 0);
- sv_strafejump_hack = Cvar_Get( "sv_strafejump_hack", "1", CVAR_LATCH );
- sv_waterjump_hack = Cvar_Get( "sv_waterjump_hack", "0", CVAR_LATCH );
+ sv_strafejump_hack = Cvar_Get("sv_strafejump_hack", "1", CVAR_LATCH);
+ sv_waterjump_hack = Cvar_Get("sv_waterjump_hack", "0", CVAR_LATCH);
#ifndef _WIN32
- sv_oldgame_hack = Cvar_Get( "sv_oldgame_hack", "0", CVAR_LATCH );
+ sv_oldgame_hack = Cvar_Get("sv_oldgame_hack", "0", CVAR_LATCH);
#endif
#if USE_PACKETDUP
- sv_packetdup_hack = Cvar_Get( "sv_packetdup_hack", "0", 0 );
+ sv_packetdup_hack = Cvar_Get("sv_packetdup_hack", "0", 0);
#endif
- sv_allow_map = Cvar_Get( "sv_allow_map", "0", 0 );
+ sv_allow_map = Cvar_Get("sv_allow_map", "0", 0);
#if !USE_CLIENT
- sv_recycle = Cvar_Get( "sv_recycle", "0", 0 );
+ sv_recycle = Cvar_Get("sv_recycle", "0", 0);
#endif
- sv_enhanced_setplayer = Cvar_Get( "sv_enhanced_setplayer", "0", 0 );
+ sv_enhanced_setplayer = Cvar_Get("sv_enhanced_setplayer", "0", 0);
- sv_iplimit = Cvar_Get( "sv_iplimit", "3", 0 );
+ sv_iplimit = Cvar_Get("sv_iplimit", "3", 0);
- sv_status_show = Cvar_Get( "sv_status_show", "2", 0 );
+ sv_status_show = Cvar_Get("sv_status_show", "2", 0);
- sv_status_limit = Cvar_Get( "sv_status_limit", "15", 0 );
+ sv_status_limit = Cvar_Get("sv_status_limit", "15", 0);
sv_status_limit->changed = sv_status_limit_changed;
- sv_uptime = Cvar_Get( "sv_uptime", "0", 0 );
+ sv_uptime = Cvar_Get("sv_uptime", "0", 0);
- sv_auth_limit = Cvar_Get( "sv_auth_limit", "1", 0 );
+ sv_auth_limit = Cvar_Get("sv_auth_limit", "1", 0);
sv_auth_limit->changed = sv_auth_limit_changed;
- sv_rcon_limit = Cvar_Get( "sv_rcon_limit", "1", 0 );
+ sv_rcon_limit = Cvar_Get("sv_rcon_limit", "1", 0);
sv_rcon_limit->changed = sv_rcon_limit_changed;
- Cvar_Get( "sv_features", va( "%d", SV_FEATURES ), CVAR_ROM );
- g_features = Cvar_Get( "g_features", "0", CVAR_ROM );
+ Cvar_Get("sv_features", va("%d", SV_FEATURES), CVAR_ROM);
+ g_features = Cvar_Get("g_features", "0", CVAR_ROM);
- map_override_path = Cvar_Get( "map_override_path", "", 0 );
+ map_override_path = Cvar_Get("map_override_path", "", 0);
init_rate_limits();
@@ -1953,7 +1988,7 @@ void SV_Init( void ) {
#endif
// set up default pmove parameters
- PmoveInit( &sv_pmp );
+ PmoveInit(&sv_pmp);
#if USE_SYSCON
SV_SetConsoleTitle();
@@ -1974,51 +2009,52 @@ server is going to totally exit after returning from this function.
Also resposible for freeing all clients.
==================
*/
-static void SV_FinalMessage( const char *message, error_type_t type ) {
+static void SV_FinalMessage(const char *message, error_type_t type)
+{
client_t *client;
netchan_t *netchan;
int i;
- if( LIST_EMPTY( &sv_clientlist ) )
+ if (LIST_EMPTY(&sv_clientlist))
return;
- if( message ) {
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteString( message );
+ if (message) {
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteString(message);
}
- if( type == ERR_RECONNECT )
- MSG_WriteByte( svc_reconnect );
+ if (type == ERR_RECONNECT)
+ MSG_WriteByte(svc_reconnect);
else
- MSG_WriteByte( svc_disconnect );
+ MSG_WriteByte(svc_disconnect);
// send it twice
// stagger the packets to crutch operating system limited buffers
- for( i = 0; i < 2; i++ ) {
- FOR_EACH_CLIENT( client ) {
- if( client->state == cs_zombie ) {
+ for (i = 0; i < 2; i++) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state == cs_zombie) {
continue;
}
netchan = client->netchan;
- while( netchan->fragment_pending ) {
- netchan->TransmitNextFragment( netchan );
+ while (netchan->fragment_pending) {
+ netchan->TransmitNextFragment(netchan);
}
- netchan->Transmit( netchan, msg_write.cursize, msg_write.data, 1 );
+ netchan->Transmit(netchan, msg_write.cursize, msg_write.data, 1);
}
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
// free any data dynamically allocated
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_zombie ) {
- SV_CleanClient( client );
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_zombie) {
+ SV_CleanClient(client);
}
- SV_RemoveClient( client );
+ SV_RemoveClient(client);
}
- List_Init( &sv_clientlist );
+ List_Init(&sv_clientlist);
}
/*
@@ -2029,12 +2065,13 @@ Called when each game quits, from Com_Quit or Com_Error.
Should be safe to call even if server is not fully initalized yet.
================
*/
-void SV_Shutdown( const char *finalmsg, error_type_t type ) {
- if( !sv_registered )
+void SV_Shutdown(const char *finalmsg, error_type_t type)
+{
+ if (!sv_registered)
return;
#if USE_MVD_CLIENT
- if( ge != &mvd_ge && !(type & MVD_SPAWN_INTERNAL) ) {
+ if (ge != &mvd_ge && !(type & MVD_SPAWN_INTERNAL)) {
// shutdown MVD client now if not already running the built-in MVD game module
// don't shutdown if called from internal MVD spawn function (ugly hack)!
MVD_Shutdown();
@@ -2047,25 +2084,25 @@ void SV_Shutdown( const char *finalmsg, error_type_t type ) {
#endif
#if USE_MVD_SERVER
- SV_MvdShutdown( type );
+ SV_MvdShutdown(type);
#endif
- SV_FinalMessage( finalmsg, type );
+ SV_FinalMessage(finalmsg, type);
SV_MasterShutdown();
SV_ShutdownGameProgs();
// free current level
- CM_FreeMap( &sv.cm );
- SV_FreeFile( sv.entitystring );
- memset( &sv, 0, sizeof( sv ) );
+ CM_FreeMap(&sv.cm);
+ SV_FreeFile(sv.entitystring);
+ memset(&sv, 0, sizeof(sv));
// free server static data
- Z_Free( svs.client_pool );
- Z_Free( svs.entities );
+ Z_Free(svs.client_pool);
+ Z_Free(svs.entities);
#if USE_ZLIB
- deflateEnd( &svs.z );
+ deflateEnd(&svs.z);
#endif
- memset( &svs, 0, sizeof( svs ) );
+ memset(&svs, 0, sizeof(svs));
// reset rate limits
init_rate_limits();
@@ -2078,13 +2115,13 @@ void SV_Shutdown( const char *finalmsg, error_type_t type ) {
sv_client = NULL;
sv_player = NULL;
- Cvar_Set( "sv_running", "0" );
- Cvar_Set( "sv_paused", "0" );
+ Cvar_Set("sv_running", "0");
+ Cvar_Set("sv_paused", "0");
#if USE_SYSCON
SV_SetConsoleTitle();
#endif
- Z_LeakTest( TAG_SERVER );
+ Z_LeakTest(TAG_SERVER);
}
diff --git a/src/sv_mvd.c b/src/sv_mvd.c
index 5c06e81..3707c4c 100644
--- a/src/sv_mvd.c
+++ b/src/sv_mvd.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,11 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "net_stream.h"
#include "mvd_gtv.h"
-#define FOR_EACH_GTV( client ) \
- LIST_FOR_EACH( gtv_client_t, client, &gtv_client_list, entry )
+#define FOR_EACH_GTV(client) \
+ LIST_FOR_EACH(gtv_client_t, client, &gtv_client_list, entry)
-#define FOR_EACH_ACTIVE_GTV( client ) \
- LIST_FOR_EACH( gtv_client_t, client, &gtv_active_list, active )
+#define FOR_EACH_ACTIVE_GTV(client) \
+ LIST_FOR_EACH(gtv_client_t, client, &gtv_active_list, active)
typedef struct {
list_t entry;
@@ -42,13 +42,13 @@ typedef struct {
z_stream z;
#endif
unsigned msglen;
- unsigned lastmessage;
+ unsigned lastmessage;
unsigned flags;
unsigned maxbuf;
unsigned bufcount;
- byte buffer[MAX_GTC_MSGLEN+4]; // recv buffer
+ byte buffer[MAX_GTC_MSGLEN + 4]; // recv buffer
byte *data; // send buffer
char name[MAX_CLIENT_NAME];
@@ -73,7 +73,7 @@ typedef struct {
entity_state_t *entities; // [MAX_EDICTS]
// local recorder
- qhandle_t recording;
+ qhandle_t recording;
int numlevels; // stop after that many levels
int numframes; // stop after that many frames
@@ -84,10 +84,10 @@ typedef struct {
static mvd_server_t mvd;
// TCP client lists
-static LIST_DECL( gtv_client_list );
-static LIST_DECL( gtv_active_list );
+static LIST_DECL(gtv_client_list);
+static LIST_DECL(gtv_active_list);
-static LIST_DECL( gtv_host_list );
+static LIST_DECL(gtv_host_list);
static cvar_t *sv_mvd_enable;
static cvar_t *sv_mvd_maxclients;
@@ -107,20 +107,20 @@ static cvar_t *sv_mvd_disconnect_time;
static cvar_t *sv_mvd_suspend_time;
static cvar_t *sv_mvd_allow_stufftext;
-static qboolean mvd_enable( void );
-static void mvd_disable( void );
-static void mvd_drop( gtv_serverop_t op );
+static qboolean mvd_enable(void);
+static void mvd_disable(void);
+static void mvd_drop(gtv_serverop_t op);
-static void write_stream( gtv_client_t *client, void *data, size_t len );
-static void write_message( gtv_client_t *client, gtv_serverop_t op );
+static void write_stream(gtv_client_t *client, void *data, size_t len);
+static void write_message(gtv_client_t *client, gtv_serverop_t op);
#if USE_ZLIB
-static void flush_stream( gtv_client_t *client, int flush );
+static void flush_stream(gtv_client_t *client, int flush);
#endif
-static void rec_stop( void );
-static qboolean rec_allowed( void );
-static void rec_start( qhandle_t demofile );
-static void rec_write( void );
+static void rec_stop(void);
+static qboolean rec_allowed(void);
+static void rec_start(qhandle_t demofile);
+static void rec_write(void);
/*
@@ -138,73 +138,78 @@ for freefloat observers, receive scoreboard updates and text messages, etc.
static cmdbuf_t dummy_buffer;
static char dummy_buffer_text[MAX_STRING_CHARS];
-static void dummy_wait_f( void ) {
- int count = atoi( Cmd_Argv( 1 ) );
+static void dummy_wait_f(void)
+{
+ int count = atoi(Cmd_Argv(1));
- if( count < 1 ) {
+ if (count < 1) {
count = 1;
}
dummy_buffer.waitCount = count;
}
-static void dummy_command( void ) {
+static void dummy_command(void)
+{
sv_client = mvd.dummy;
sv_player = sv_client->edict;
- ge->ClientCommand( sv_player );
+ ge->ClientCommand(sv_player);
sv_client = NULL;
sv_player = NULL;
}
-static void dummy_forward_f( void ) {
+static void dummy_forward_f(void)
+{
Cmd_Shift();
- Com_DPrintf( "dummy cmd: %s %s\n", Cmd_Argv( 0 ), Cmd_Args() );
+ Com_DPrintf("dummy cmd: %s %s\n", Cmd_Argv(0), Cmd_Args());
dummy_command();
}
-static void dummy_record_f( void ) {
+static void dummy_record_f(void)
+{
char buffer[MAX_OSPATH];
qhandle_t f;
- if( !sv_mvd_autorecord->integer ) {
+ if (!sv_mvd_autorecord->integer) {
return;
}
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- if( !rec_allowed() ) {
+ if (!rec_allowed()) {
return;
}
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), FS_MODE_WRITE,
- "demos/", Cmd_Argv( 1 ), ".mvd2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), FS_MODE_WRITE,
+ "demos/", Cmd_Argv(1), ".mvd2");
+ if (!f) {
return;
}
- if( !mvd_enable() ) {
- FS_FCloseFile( f );
+ if (!mvd_enable()) {
+ FS_FCloseFile(f);
return;
}
- Com_Printf( "Auto-recording local MVD to %s\n", buffer );
+ Com_Printf("Auto-recording local MVD to %s\n", buffer);
- rec_start( f );
+ rec_start(f);
}
-static void dummy_stop_f( void ) {
- if( !sv_mvd_autorecord->integer ) {
+static void dummy_stop_f(void)
+{
+ if (!sv_mvd_autorecord->integer) {
return;
}
- if( !mvd.recording ) {
- Com_Printf( "Not recording a local MVD.\n" );
+ if (!mvd.recording) {
+ Com_Printf("Not recording a local MVD.\n");
return;
}
- Com_Printf( "Stopped local MVD auto-recording.\n" );
+ Com_Printf("Stopped local MVD auto-recording.\n");
rec_stop();
}
@@ -222,76 +227,78 @@ static const ucmd_t dummy_cmds[] = {
{ NULL, NULL }
};
-static void dummy_exec_string( cmdbuf_t *buf, const char *line ) {
+static void dummy_exec_string(cmdbuf_t *buf, const char *line)
+{
char *cmd, *alias;
const ucmd_t *u;
cvar_t *v;
- if( !line[0] ) {
+ if (!line[0]) {
return;
}
- Cmd_TokenizeString( line, qtrue );
+ Cmd_TokenizeString(line, qtrue);
- cmd = Cmd_Argv( 0 );
- if( !cmd[0] ) {
+ cmd = Cmd_Argv(0);
+ if (!cmd[0]) {
return;
}
- if( ( u = Com_Find( dummy_cmds, cmd ) ) != NULL ) {
- if( u->func ) {
+ if ((u = Com_Find(dummy_cmds, cmd)) != NULL) {
+ if (u->func) {
u->func();
}
return;
}
- alias = Cmd_AliasCommand( cmd );
- if( alias ) {
- if( ++dummy_buffer.aliasCount == ALIAS_LOOP_COUNT ) {
- Com_WPrintf( "%s: runaway alias loop\n", __func__ );
+ alias = Cmd_AliasCommand(cmd);
+ if (alias) {
+ if (++dummy_buffer.aliasCount == ALIAS_LOOP_COUNT) {
+ Com_WPrintf("%s: runaway alias loop\n", __func__);
return;
}
- Cbuf_InsertText( &dummy_buffer, alias );
+ Cbuf_InsertText(&dummy_buffer, alias);
return;
}
- v = Cvar_FindVar( cmd );
- if( v ) {
- Cvar_Command( v );
+ v = Cvar_FindVar(cmd);
+ if (v) {
+ Cvar_Command(v);
return;
}
- Com_DPrintf( "dummy forward: %s\n", line );
+ Com_DPrintf("dummy forward: %s\n", line);
dummy_command();
}
-static void dummy_add_message( client_t *client, byte *data,
- size_t length, qboolean reliable )
+static void dummy_add_message(client_t *client, byte *data,
+ size_t length, qboolean reliable)
{
char *text;
- if( !length || !reliable || data[0] != svc_stufftext ) {
+ if (!length || !reliable || data[0] != svc_stufftext) {
return; // not interesting
}
- if( sv_mvd_allow_stufftext->integer <= 0 ) {
+ if (sv_mvd_allow_stufftext->integer <= 0) {
return; // not allowed
}
data[length] = 0;
- text = ( char * )( data + 1 );
- Com_DPrintf( "dummy stufftext: %s\n", text );
- Cbuf_AddText( &dummy_buffer, text );
+ text = (char *)(data + 1);
+ Com_DPrintf("dummy stufftext: %s\n", text);
+ Cbuf_AddText(&dummy_buffer, text);
}
-static void dummy_spawn( void ) {
+static void dummy_spawn(void)
+{
sv_client = mvd.dummy;
sv_player = sv_client->edict;
- ge->ClientBegin( sv_player );
+ ge->ClientBegin(sv_player);
sv_client = NULL;
sv_player = NULL;
- if( sv_mvd_begincmd->string[0] ) {
- Cbuf_AddText( &dummy_buffer, sv_mvd_begincmd->string );
+ if (sv_mvd_begincmd->string[0]) {
+ Cbuf_AddText(&dummy_buffer, sv_mvd_begincmd->string);
}
mvd.layout_time = svs.realtime;
@@ -299,23 +306,24 @@ static void dummy_spawn( void ) {
mvd.dummy->state = cs_spawned;
}
-static client_t *dummy_find_slot( void ) {
+static client_t *dummy_find_slot(void)
+{
client_t *c;
int i, j;
// first check if there is a free reserved slot
j = sv_maxclients->integer - sv_reserved_slots->integer;
- for( i = j; i < sv_maxclients->integer; i++ ) {
+ for (i = j; i < sv_maxclients->integer; i++) {
c = &svs.client_pool[i];
- if( !c->state ) {
+ if (!c->state) {
return c;
}
}
// then check regular slots
- for( i = 0; i < j; i++ ) {
+ for (i = 0; i < j; i++) {
c = &svs.client_pool[i];
- if( !c->state ) {
+ if (!c->state) {
return c;
}
}
@@ -323,7 +331,8 @@ static client_t *dummy_find_slot( void ) {
return NULL;
}
-static qboolean dummy_create( void ) {
+static qboolean dummy_create(void)
+{
client_t *newcl;
char userinfo[MAX_INFO_STRING];
char *s;
@@ -332,73 +341,74 @@ static qboolean dummy_create( void ) {
// find a free client slot
newcl = dummy_find_slot();
- if( !newcl ) {
- Com_EPrintf( "No slot for dummy MVD client\n" );
+ if (!newcl) {
+ Com_EPrintf("No slot for dummy MVD client\n");
return qfalse;
}
- memset( newcl, 0, sizeof( *newcl ) );
+ memset(newcl, 0, sizeof(*newcl));
number = newcl - svs.client_pool;
newcl->number = newcl->slot = number;
newcl->protocol = -1;
newcl->state = cs_connected;
newcl->AddMessage = dummy_add_message;
- newcl->edict = EDICT_NUM( number + 1 );
- newcl->netchan = SV_Mallocz( sizeof( netchan_t ) );
+ newcl->edict = EDICT_NUM(number + 1);
+ newcl->netchan = SV_Mallocz(sizeof(netchan_t));
newcl->netchan->remote_address.type = NA_LOOPBACK;
- List_Init( &newcl->entry );
+ List_Init(&newcl->entry);
- Q_snprintf( userinfo, sizeof( userinfo ),
- "\\name\\[MVDSPEC]\\skin\\male/grunt\\mvdspec\\%d\\ip\\loopback",
- PROTOCOL_VERSION_MVD_CURRENT );
+ Q_snprintf(userinfo, sizeof(userinfo),
+ "\\name\\[MVDSPEC]\\skin\\male/grunt\\mvdspec\\%d\\ip\\loopback",
+ PROTOCOL_VERSION_MVD_CURRENT);
mvd.dummy = newcl;
// get the game a chance to reject this connection or modify the userinfo
sv_client = newcl;
sv_player = newcl->edict;
- allow = ge->ClientConnect( newcl->edict, userinfo );
+ allow = ge->ClientConnect(newcl->edict, userinfo);
sv_client = NULL;
sv_player = NULL;
- if ( !allow ) {
- s = Info_ValueForKey( userinfo, "rejmsg" );
- if( *s ) {
- Com_EPrintf( "Dummy MVD client rejected by game DLL: %s\n", s );
+ if (!allow) {
+ s = Info_ValueForKey(userinfo, "rejmsg");
+ if (*s) {
+ Com_EPrintf("Dummy MVD client rejected by game DLL: %s\n", s);
}
mvd.dummy = NULL;
return qfalse;
}
// parse some info from the info strings
- strcpy( newcl->userinfo, userinfo );
- SV_UserinfoChanged( newcl );
+ strcpy(newcl->userinfo, userinfo);
+ SV_UserinfoChanged(newcl);
return qtrue;
}
-static void dummy_run( void ) {
+static void dummy_run(void)
+{
usercmd_t cmd;
- Cbuf_Execute( &dummy_buffer );
- if( dummy_buffer.waitCount > 0 ) {
+ Cbuf_Execute(&dummy_buffer);
+ if (dummy_buffer.waitCount > 0) {
dummy_buffer.waitCount--;
}
// run ClientThink to prevent timeouts, etc
- memset( &cmd, 0, sizeof( cmd ) );
+ memset(&cmd, 0, sizeof(cmd));
cmd.msec = BASE_FRAMETIME;
sv_client = mvd.dummy;
sv_player = sv_client->edict;
- ge->ClientThink( sv_player, &cmd );
+ ge->ClientThink(sv_player, &cmd);
sv_client = NULL;
sv_player = NULL;
// check if the layout is constantly updated. if not,
// game mod has probably closed the scoreboard, open it again
- if( mvd.active && sv_mvd_scorecmd->string[0] ) {
- if( svs.realtime - mvd.layout_time > 9000 ) {
- Cbuf_AddText( &dummy_buffer, sv_mvd_scorecmd->string );
+ if (mvd.active && sv_mvd_scorecmd->string[0]) {
+ if (svs.realtime - mvd.layout_time > 9000) {
+ Cbuf_AddText(&dummy_buffer, sv_mvd_scorecmd->string);
mvd.layout_time = svs.realtime;
}
}
@@ -438,66 +448,67 @@ Entire function is a nasty hack. Ideally a compatible game DLL
should do it for us by providing some SVF_* flag or something.
==================
*/
-static qboolean player_is_active( const edict_t *ent ) {
+static qboolean player_is_active(const edict_t *ent)
+{
int num;
- if( ( g_features->integer & GMF_PROPERINUSE ) && !ent->inuse ) {
+ if ((g_features->integer & GMF_PROPERINUSE) && !ent->inuse) {
return qfalse;
}
// not a client at all?
- if( !ent->client ) {
+ if (!ent->client) {
return qfalse;
}
- num = NUM_FOR_EDICT( ent ) - 1;
- if( num < 0 || num >= sv_maxclients->integer ) {
+ num = NUM_FOR_EDICT(ent) - 1;
+ if (num < 0 || num >= sv_maxclients->integer) {
return qfalse;
}
// by default, check if client is actually connected
// it may not be the case for bots!
- if( sv_mvd_capture_flags->integer & 1 ) {
- if( svs.client_pool[num].state != cs_spawned ) {
+ if (sv_mvd_capture_flags->integer & 1) {
+ if (svs.client_pool[num].state != cs_spawned) {
return qfalse;
}
}
// first of all, make sure player_state_t is valid
- if( !ent->client->ps.fov ) {
+ if (!ent->client->ps.fov) {
return qfalse;
}
// always capture dummy MVD client
- if( ent == mvd.dummy->edict ) {
+ if (ent == mvd.dummy->edict) {
return qtrue;
}
// never capture spectators
- if( ent->client->ps.pmove.pm_type == PM_SPECTATOR ) {
+ if (ent->client->ps.pmove.pm_type == PM_SPECTATOR) {
return qfalse;
}
// check entity visibility
- if( ( ent->svflags & SVF_NOCLIENT ) || !ES_INUSE( &ent->s ) ) {
+ if ((ent->svflags & SVF_NOCLIENT) || !ES_INUSE(&ent->s)) {
// never capture invisible entities
- if( sv_mvd_capture_flags->integer & 2 ) {
+ if (sv_mvd_capture_flags->integer & 2) {
return qfalse;
}
} else {
// always capture visible entities (default)
- if( sv_mvd_capture_flags->integer & 4 ) {
+ if (sv_mvd_capture_flags->integer & 4) {
return qtrue;
}
}
// they are likely following someone in case of PM_FREEZE
- if( ent->client->ps.pmove.pm_type == PM_FREEZE ) {
+ if (ent->client->ps.pmove.pm_type == PM_FREEZE) {
return qfalse;
}
- // they are likely following someone if PMF_NO_PREDICTION is set
- if( ent->client->ps.pmove.pm_flags & PMF_NO_PREDICTION ) {
+ // they are likely following someone if PMF_NO_PREDICTION is set
+ if (ent->client->ps.pmove.pm_flags & PMF_NO_PREDICTION) {
return qfalse;
}
@@ -511,33 +522,34 @@ build_gamestate
Initialize MVD delta compressor for the first time on the given map.
==================
*/
-static void build_gamestate( void ) {
+static void build_gamestate(void)
+{
player_state_t *ps;
entity_state_t *es;
edict_t *ent;
int i;
- memset( mvd.players, 0, sizeof( player_state_t ) * sv_maxclients->integer );
- memset( mvd.entities, 0, sizeof( entity_state_t ) * MAX_EDICTS );
+ memset(mvd.players, 0, sizeof(player_state_t) * sv_maxclients->integer);
+ memset(mvd.entities, 0, sizeof(entity_state_t) * MAX_EDICTS);
// set base player states
- for( i = 0; i < sv_maxclients->integer; i++ ) {
- ent = EDICT_NUM( i + 1 );
+ for (i = 0; i < sv_maxclients->integer; i++) {
+ ent = EDICT_NUM(i + 1);
- if( !player_is_active( ent ) ) {
+ if (!player_is_active(ent)) {
continue;
}
ps = &mvd.players[i];
*ps = ent->client->ps;
- PPS_INUSE( ps ) = qtrue;
+ PPS_INUSE(ps) = qtrue;
}
// set base entity states
- for( i = 1; i < ge->num_edicts; i++ ) {
- ent = EDICT_NUM( i );
+ for (i = 1; i < ge->num_edicts; i++) {
+ ent = EDICT_NUM(i);
- if( ( ent->svflags & SVF_NOCLIENT ) || !ES_INUSE( &ent->s ) ) {
+ if ((ent->svflags & SVF_NOCLIENT) || !ES_INUSE(&ent->s)) {
continue;
}
@@ -556,7 +568,8 @@ Writes a single giant message with all the startup info,
followed by an uncompressed (baseline) frame.
==================
*/
-static void emit_gamestate( void ) {
+static void emit_gamestate(void)
+{
char *string;
int i, j;
player_state_t *ps;
@@ -567,64 +580,64 @@ static void emit_gamestate( void ) {
// pack MVD stream flags into extra bits
extra = 0;
- if( sv_mvd_nomsgs->integer ) {
+ if (sv_mvd_nomsgs->integer) {
extra |= MVF_NOMSGS << SVCMD_BITS;
}
// send the serverdata
- MSG_WriteByte( mvd_serverdata | extra );
- MSG_WriteLong( PROTOCOL_VERSION_MVD );
- MSG_WriteShort( PROTOCOL_VERSION_MVD_CURRENT );
- MSG_WriteLong( sv.spawncount );
- MSG_WriteString( fs_game->string );
- MSG_WriteShort( mvd.dummy->number );
+ MSG_WriteByte(mvd_serverdata | extra);
+ MSG_WriteLong(PROTOCOL_VERSION_MVD);
+ MSG_WriteShort(PROTOCOL_VERSION_MVD_CURRENT);
+ MSG_WriteLong(sv.spawncount);
+ MSG_WriteString(fs_game->string);
+ MSG_WriteShort(mvd.dummy->number);
// send configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
string = sv.configstrings[i];
- if( !string[0] ) {
+ if (!string[0]) {
continue;
}
- length = strlen( string );
- if( length > MAX_QPATH ) {
+ length = strlen(string);
+ if (length > MAX_QPATH) {
length = MAX_QPATH;
}
- MSG_WriteShort( i );
- MSG_WriteData( string, length );
- MSG_WriteByte( 0 );
+ MSG_WriteShort(i);
+ MSG_WriteData(string, length);
+ MSG_WriteByte(0);
}
- MSG_WriteShort( MAX_CONFIGSTRINGS );
+ MSG_WriteShort(MAX_CONFIGSTRINGS);
// send baseline frame
- portalbytes = CM_WritePortalBits( &sv.cm, portalbits );
- MSG_WriteByte( portalbytes );
- MSG_WriteData( portalbits, portalbytes );
-
+ portalbytes = CM_WritePortalBits(&sv.cm, portalbits);
+ MSG_WriteByte(portalbytes);
+ MSG_WriteData(portalbits, portalbytes);
+
// send player states
flags = 0;
- if( sv_mvd_noblend->integer ) {
+ if (sv_mvd_noblend->integer) {
flags |= MSG_PS_IGNORE_BLEND;
}
- if( sv_mvd_nogun->integer ) {
- flags |= MSG_PS_IGNORE_GUNINDEX|MSG_PS_IGNORE_GUNFRAMES;
+ if (sv_mvd_nogun->integer) {
+ flags |= MSG_PS_IGNORE_GUNINDEX | MSG_PS_IGNORE_GUNFRAMES;
}
- for( i = 0, ps = mvd.players; i < sv_maxclients->integer; i++, ps++ ) {
+ for (i = 0, ps = mvd.players; i < sv_maxclients->integer; i++, ps++) {
extra = 0;
- if( !PPS_INUSE( ps ) ) {
+ if (!PPS_INUSE(ps)) {
extra |= MSG_PS_REMOVE;
}
- MSG_WriteDeltaPlayerstate_Packet( NULL, ps, i, flags | extra );
+ MSG_WriteDeltaPlayerstate_Packet(NULL, ps, i, flags | extra);
}
- MSG_WriteByte( CLIENTNUM_NONE );
+ MSG_WriteByte(CLIENTNUM_NONE);
// send entity states
- for( i = 1, es = mvd.entities + 1; i < ge->num_edicts; i++, es++ ) {
+ for (i = 1, es = mvd.entities + 1; i < ge->num_edicts; i++, es++) {
flags = MSG_ES_UMASK;
- if( ( j = es->number ) != 0 ) {
- if( i <= sv_maxclients->integer ) {
- ps = &mvd.players[ i - 1 ];
- if( PPS_INUSE( ps ) && ps->pmove.pm_type == PM_NORMAL ) {
+ if ((j = es->number) != 0) {
+ if (i <= sv_maxclients->integer) {
+ ps = &mvd.players[i - 1];
+ if (PPS_INUSE(ps) && ps->pmove.pm_type == PM_NORMAL) {
flags |= MSG_ES_FIRSTPERSON;
}
}
@@ -632,18 +645,19 @@ static void emit_gamestate( void ) {
flags |= MSG_ES_REMOVE;
}
es->number = i;
- MSG_WriteDeltaEntity( NULL, es, flags );
+ MSG_WriteDeltaEntity(NULL, es, flags);
es->number = j;
}
- MSG_WriteShort( 0 );
+ MSG_WriteShort(0);
}
-static void copy_entity_state( entity_state_t *dst, const entity_state_t *src, int flags ) {
- if( !( flags & MSG_ES_FIRSTPERSON ) ) {
- VectorCopy( src->origin, dst->origin );
- VectorCopy( src->angles, dst->angles );
- VectorCopy( src->old_origin, dst->old_origin );
+static void copy_entity_state(entity_state_t *dst, const entity_state_t *src, int flags)
+{
+ if (!(flags & MSG_ES_FIRSTPERSON)) {
+ VectorCopy(src->origin, dst->origin);
+ VectorCopy(src->angles, dst->angles);
+ VectorCopy(src->old_origin, dst->old_origin);
}
dst->modelindex = src->modelindex;
dst->modelindex2 = src->modelindex2;
@@ -667,7 +681,8 @@ and calculating portalbits. The same frame is used for all MVD
clients, as well as local recorder.
==================
*/
-static void emit_frame( void ) {
+static void emit_frame(void)
+{
player_state_t *oldps, *newps;
entity_state_t *oldes, *newes;
edict_t *ent;
@@ -675,156 +690,159 @@ static void emit_frame( void ) {
byte portalbits[MAX_MAP_PORTAL_BYTES];
int i;
- MSG_WriteByte( mvd_frame );
+ MSG_WriteByte(mvd_frame);
// send portal bits
- portalbytes = CM_WritePortalBits( &sv.cm, portalbits );
- MSG_WriteByte( portalbytes );
- MSG_WriteData( portalbits, portalbytes );
-
- flags = MSG_PS_IGNORE_PREDICTION|MSG_PS_IGNORE_DELTAANGLES;
- if( sv_mvd_noblend->integer ) {
+ portalbytes = CM_WritePortalBits(&sv.cm, portalbits);
+ MSG_WriteByte(portalbytes);
+ MSG_WriteData(portalbits, portalbytes);
+
+ flags = MSG_PS_IGNORE_PREDICTION | MSG_PS_IGNORE_DELTAANGLES;
+ if (sv_mvd_noblend->integer) {
flags |= MSG_PS_IGNORE_BLEND;
}
- if( sv_mvd_nogun->integer ) {
- flags |= MSG_PS_IGNORE_GUNINDEX|MSG_PS_IGNORE_GUNFRAMES;
+ if (sv_mvd_nogun->integer) {
+ flags |= MSG_PS_IGNORE_GUNINDEX | MSG_PS_IGNORE_GUNFRAMES;
}
// send player states
- for( i = 0; i < sv_maxclients->integer; i++ ) {
- ent = EDICT_NUM( i + 1 );
+ for (i = 0; i < sv_maxclients->integer; i++) {
+ ent = EDICT_NUM(i + 1);
oldps = &mvd.players[i];
newps = &ent->client->ps;
- if( !player_is_active( ent ) ) {
- if( PPS_INUSE( oldps ) ) {
+ if (!player_is_active(ent)) {
+ if (PPS_INUSE(oldps)) {
// the old player isn't present in the new message
- MSG_WriteDeltaPlayerstate_Packet( NULL, NULL, i, flags );
- PPS_INUSE( oldps ) = qfalse;
+ MSG_WriteDeltaPlayerstate_Packet(NULL, NULL, i, flags);
+ PPS_INUSE(oldps) = qfalse;
}
continue;
}
- if( PPS_INUSE( oldps ) ) {
+ if (PPS_INUSE(oldps)) {
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the player has not changed at all
- MSG_WriteDeltaPlayerstate_Packet( oldps, newps, i, flags );
+ MSG_WriteDeltaPlayerstate_Packet(oldps, newps, i, flags);
} else {
// this is a new player, send it from the last state
- MSG_WriteDeltaPlayerstate_Packet( oldps, newps, i,
- flags | MSG_PS_FORCE );
+ MSG_WriteDeltaPlayerstate_Packet(oldps, newps, i,
+ flags | MSG_PS_FORCE);
}
// shuffle current state to previous
*oldps = *newps;
- PPS_INUSE( oldps ) = qtrue;
+ PPS_INUSE(oldps) = qtrue;
}
- MSG_WriteByte( CLIENTNUM_NONE ); // end of packetplayers
+ MSG_WriteByte(CLIENTNUM_NONE); // end of packetplayers
// send entity states
- for( i = 1; i < ge->num_edicts; i++ ) {
- ent = EDICT_NUM( i );
+ for (i = 1; i < ge->num_edicts; i++) {
+ ent = EDICT_NUM(i);
oldes = &mvd.entities[i];
newes = &ent->s;
- if( ( ent->svflags & SVF_NOCLIENT ) || !ES_INUSE( newes ) ) {
- if( oldes->number ) {
+ if ((ent->svflags & SVF_NOCLIENT) || !ES_INUSE(newes)) {
+ if (oldes->number) {
// the old entity isn't present in the new message
- MSG_WriteDeltaEntity( oldes, NULL, MSG_ES_FORCE );
+ MSG_WriteDeltaEntity(oldes, NULL, MSG_ES_FORCE);
oldes->number = 0;
}
continue;
}
- if( newes->number != i ) {
- Com_WPrintf( "%s: fixing ent->s.number: %d to %d\n",
- __func__, newes->number, i );
+ if (newes->number != i) {
+ Com_WPrintf("%s: fixing ent->s.number: %d to %d\n",
+ __func__, newes->number, i);
newes->number = i;
}
// calculate flags
flags = MSG_ES_UMASK;
- if( i <= sv_maxclients->integer ) {
- oldps = &mvd.players[ i - 1 ];
- if( PPS_INUSE( oldps ) && oldps->pmove.pm_type == PM_NORMAL ) {
+ if (i <= sv_maxclients->integer) {
+ oldps = &mvd.players[i - 1];
+ if (PPS_INUSE(oldps) && oldps->pmove.pm_type == PM_NORMAL) {
// do not waste bandwidth on origin/angle updates,
// client will recover them from player state
flags |= MSG_ES_FIRSTPERSON;
}
}
-
- if( !oldes->number ) {
+
+ if (!oldes->number) {
// this is a new entity, send it from the last state
- flags |= MSG_ES_FORCE|MSG_ES_NEWENTITY;
+ flags |= MSG_ES_FORCE | MSG_ES_NEWENTITY;
}
-
- MSG_WriteDeltaEntity( oldes, newes, flags );
+
+ MSG_WriteDeltaEntity(oldes, newes, flags);
// shuffle current state to previous
- copy_entity_state( oldes, newes, flags );
+ copy_entity_state(oldes, newes, flags);
oldes->number = i;
}
- MSG_WriteShort( 0 ); // end of packetentities
+ MSG_WriteShort(0); // end of packetentities
}
-static void suspend_streams( void ) {
+static void suspend_streams(void)
+{
gtv_client_t *client;
- FOR_EACH_ACTIVE_GTV( client ) {
+ FOR_EACH_ACTIVE_GTV(client) {
// send stream suspend marker
- write_message( client, GTS_STREAM_DATA );
+ write_message(client, GTS_STREAM_DATA);
#if USE_ZLIB
- flush_stream( client, Z_SYNC_FLUSH );
+ flush_stream(client, Z_SYNC_FLUSH);
#endif
- NET_UpdateStream( &client->stream );
+ NET_UpdateStream(&client->stream);
}
- Com_DPrintf( "Suspending MVD streams.\n" );
+ Com_DPrintf("Suspending MVD streams.\n");
mvd.active = qfalse;
}
-static void resume_streams( void ) {
+static void resume_streams(void)
+{
gtv_client_t *client;
// build and emit gamestate
build_gamestate();
emit_gamestate();
- FOR_EACH_ACTIVE_GTV( client ) {
+ FOR_EACH_ACTIVE_GTV(client) {
// send gamestate
- write_message( client, GTS_STREAM_DATA );
+ write_message(client, GTS_STREAM_DATA);
#if USE_ZLIB
- flush_stream( client, Z_SYNC_FLUSH );
+ flush_stream(client, Z_SYNC_FLUSH);
#endif
- NET_UpdateStream( &client->stream );
+ NET_UpdateStream(&client->stream);
}
// write it to demofile
- if( mvd.recording ) {
+ if (mvd.recording) {
rec_write();
}
// clear gamestate
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- SZ_Clear( &mvd.datagram );
- SZ_Clear( &mvd.message );
+ SZ_Clear(&mvd.datagram);
+ SZ_Clear(&mvd.message);
- Com_DPrintf( "Resuming MVD streams.\n" );
+ Com_DPrintf("Resuming MVD streams.\n");
mvd.active = qtrue;
}
-static qboolean players_active( void ) {
+static qboolean players_active(void)
+{
int i;
edict_t *ent;
- for( i = 0; i < sv_maxclients->integer; i++ ) {
- ent = EDICT_NUM( i + 1 );
- if( ent != mvd.dummy->edict && player_is_active( ent ) ) {
+ for (i = 0; i < sv_maxclients->integer; i++) {
+ ent = EDICT_NUM(i + 1);
+ if (ent != mvd.dummy->edict && player_is_active(ent)) {
return qtrue;
}
}
@@ -836,11 +854,12 @@ static qboolean players_active( void ) {
SV_MvdBeginFrame
==================
*/
-void SV_MvdBeginFrame( void ) {
+void SV_MvdBeginFrame(void)
+{
unsigned delta;
// do nothing if not enabled
- if( !mvd.dummy ) {
+ if (!mvd.dummy) {
return;
}
@@ -848,62 +867,61 @@ void SV_MvdBeginFrame( void ) {
// disconnect MVD dummy if no MVD clients are active for some time
// FIXME: should not really count unauthenticated/zombie clients
- if( !delta || mvd.recording || !LIST_EMPTY( &gtv_client_list ) ) {
+ if (!delta || mvd.recording || !LIST_EMPTY(&gtv_client_list)) {
mvd.clients_active = svs.realtime;
- } else if( svs.realtime - mvd.clients_active > delta ) {
- Com_DPrintf( "Disconnecting dummy MVD client.\n" );
- SV_DropClient( mvd.dummy, NULL );
+ } else if (svs.realtime - mvd.clients_active > delta) {
+ Com_DPrintf("Disconnecting dummy MVD client.\n");
+ SV_DropClient(mvd.dummy, NULL);
return;
}
delta = sv_mvd_suspend_time->value * 60 * 1000;
// suspend/resume MVD streams depending on players activity
- if( !delta || players_active() ) {
+ if (!delta || players_active()) {
mvd.players_active = svs.realtime;
- if( !mvd.active ) {
+ if (!mvd.active) {
resume_streams();
}
- } else if( mvd.active ) {
- if( svs.realtime - mvd.players_active > delta ) {
+ } else if (mvd.active) {
+ if (svs.realtime - mvd.players_active > delta) {
suspend_streams();
}
}
}
-static void rec_frame( size_t total ) {
+static void rec_frame(size_t total)
+{
uint16_t msglen;
ssize_t ret;
- if( !total )
+ if (!total)
return;
- msglen = LittleShort( total );
- ret = FS_Write( &msglen, 2, mvd.recording );
- if( ret != 2 )
+ msglen = LittleShort(total);
+ ret = FS_Write(&msglen, 2, mvd.recording);
+ if (ret != 2)
goto fail;
- ret = FS_Write( mvd.message.data, mvd.message.cursize, mvd.recording );
- if( ret != mvd.message.cursize )
+ ret = FS_Write(mvd.message.data, mvd.message.cursize, mvd.recording);
+ if (ret != mvd.message.cursize)
goto fail;
- ret = FS_Write( msg_write.data, msg_write.cursize, mvd.recording );
- if( ret != msg_write.cursize )
+ ret = FS_Write(msg_write.data, msg_write.cursize, mvd.recording);
+ if (ret != msg_write.cursize)
goto fail;
- ret = FS_Write( mvd.datagram.data, mvd.datagram.cursize, mvd.recording );
- if( ret != mvd.datagram.cursize )
+ ret = FS_Write(mvd.datagram.data, mvd.datagram.cursize, mvd.recording);
+ if (ret != mvd.datagram.cursize)
goto fail;
- if( sv_mvd_maxsize->value > 0 &&
- FS_Tell( mvd.recording ) > sv_mvd_maxsize->value * 1000 )
- {
- Com_Printf( "Stopping MVD recording, maximum size reached.\n" );
+ if (sv_mvd_maxsize->value > 0 &&
+ FS_Tell(mvd.recording) > sv_mvd_maxsize->value * 1000) {
+ Com_Printf("Stopping MVD recording, maximum size reached.\n");
rec_stop();
return;
}
- if( sv_mvd_maxtime->value > 0 &&
- ++mvd.numframes > sv_mvd_maxtime->value * 600 )
- {
- Com_Printf( "Stopping MVD recording, maximum duration reached.\n" );
+ if (sv_mvd_maxtime->value > 0 &&
+ ++mvd.numframes > sv_mvd_maxtime->value * 600) {
+ Com_Printf("Stopping MVD recording, maximum duration reached.\n");
rec_stop();
return;
}
@@ -911,7 +929,7 @@ static void rec_frame( size_t total ) {
return;
fail:
- Com_EPrintf( "Couldn't write local MVD: %s\n", Q_ErrorString( ret ) );
+ Com_EPrintf("Couldn't write local MVD: %s\n", Q_ErrorString(ret));
rec_stop();
}
@@ -920,86 +938,87 @@ fail:
SV_MvdEndFrame
==================
*/
-void SV_MvdEndFrame( void ) {
+void SV_MvdEndFrame(void)
+{
gtv_client_t *client;
size_t total;
byte header[3];
- if( !SV_FRAMESYNC )
+ if (!SV_FRAMESYNC)
return;
// do nothing if not enabled
- if( !mvd.dummy ) {
+ if (!mvd.dummy) {
return;
}
dummy_run();
// do nothing if not active
- if( !mvd.active ) {
+ if (!mvd.active) {
return;
}
// if reliable message overflowed, kick all clients
- if( mvd.message.overflowed ) {
- Com_EPrintf( "Reliable MVD message overflowed!\n" );
- SV_DropClient( mvd.dummy, NULL );
+ if (mvd.message.overflowed) {
+ Com_EPrintf("Reliable MVD message overflowed!\n");
+ SV_DropClient(mvd.dummy, NULL);
return;
}
- if( mvd.datagram.overflowed ) {
- Com_WPrintf( "Unreliable MVD datagram overflowed.\n" );
- SZ_Clear( &mvd.datagram );
+ if (mvd.datagram.overflowed) {
+ Com_WPrintf("Unreliable MVD datagram overflowed.\n");
+ SZ_Clear(&mvd.datagram);
}
// emit a delta update common to all clients
emit_frame();
// if reliable message and frame update don't fit, kick all clients
- if( mvd.message.cursize + msg_write.cursize >= MAX_MSGLEN ) {
- Com_EPrintf( "MVD frame overflowed!\n" );
- SZ_Clear( &msg_write );
- SV_DropClient( mvd.dummy, NULL );
+ if (mvd.message.cursize + msg_write.cursize >= MAX_MSGLEN) {
+ Com_EPrintf("MVD frame overflowed!\n");
+ SZ_Clear(&msg_write);
+ SV_DropClient(mvd.dummy, NULL);
return;
}
// check if unreliable datagram fits
- if( mvd.message.cursize + msg_write.cursize + mvd.datagram.cursize >= MAX_MSGLEN ) {
- Com_WPrintf( "Dumping unreliable MVD datagram.\n" );
- SZ_Clear( &mvd.datagram );
+ if (mvd.message.cursize + msg_write.cursize + mvd.datagram.cursize >= MAX_MSGLEN) {
+ Com_WPrintf("Dumping unreliable MVD datagram.\n");
+ SZ_Clear(&mvd.datagram);
}
// build message header
total = mvd.message.cursize + msg_write.cursize + mvd.datagram.cursize + 1;
header[0] = total & 255;
- header[1] = ( total >> 8 ) & 255;
+ header[1] = (total >> 8) & 255;
header[2] = GTS_STREAM_DATA;
// send frame to clients
- FOR_EACH_ACTIVE_GTV( client ) {
- write_stream( client, header, sizeof( header ) );
- write_stream( client, mvd.message.data, mvd.message.cursize );
- write_stream( client, msg_write.data, msg_write.cursize );
- write_stream( client, mvd.datagram.data, mvd.datagram.cursize );
+ FOR_EACH_ACTIVE_GTV(client) {
+ write_stream(client, header, sizeof(header));
+ write_stream(client, mvd.message.data, mvd.message.cursize);
+ write_stream(client, msg_write.data, msg_write.cursize);
+ write_stream(client, mvd.datagram.data, mvd.datagram.cursize);
#if USE_ZLIB
- if( ++client->bufcount > client->maxbuf ) {
- flush_stream( client, Z_SYNC_FLUSH );
+ if (++client->bufcount > client->maxbuf) {
+ flush_stream(client, Z_SYNC_FLUSH);
}
#endif
- NET_UpdateStream( &client->stream );
+ NET_UpdateStream(&client->stream);
}
// write frame to demofile
- if( mvd.recording ) {
- rec_frame( total - 1 );
+ if (mvd.recording) {
+ rec_frame(total - 1);
}
// clear frame
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
// clear datagrams
- SZ_Clear( &mvd.datagram );
- SZ_Clear( &mvd.message );
+ SZ_Clear(&mvd.datagram);
+ SZ_Clear(&mvd.message);
}
@@ -1024,28 +1043,29 @@ into one larger message to save space (useful for shotgun patterns
as they often occur in the same BSP leaf)
==============
*/
-void SV_MvdMulticast( int leafnum, multicast_t to ) {
+void SV_MvdMulticast(int leafnum, multicast_t to)
+{
mvd_ops_t op;
sizebuf_t *buf;
int bits;
-
+
// do nothing if not active
- if( !mvd.active ) {
+ if (!mvd.active) {
return;
}
op = mvd_multicast_all + to;
buf = to < MULTICAST_ALL_R ? &mvd.datagram : &mvd.message;
- bits = ( msg_write.cursize >> 8 ) & 7;
+ bits = (msg_write.cursize >> 8) & 7;
- SZ_WriteByte( buf, op | ( bits << SVCMD_BITS ) );
- SZ_WriteByte( buf, msg_write.cursize & 255 );
+ SZ_WriteByte(buf, op | (bits << SVCMD_BITS));
+ SZ_WriteByte(buf, msg_write.cursize & 255);
- if( op != mvd_multicast_all && op != mvd_multicast_all_r ) {
- SZ_WriteShort( buf, leafnum );
+ if (op != mvd_multicast_all && op != mvd_multicast_all_r) {
+ SZ_WriteShort(buf, leafnum);
}
-
- SZ_Write( buf, msg_write.data, msg_write.cursize );
+
+ SZ_Write(buf, msg_write.data, msg_write.cursize);
}
/*
@@ -1056,24 +1076,25 @@ Performs some basic filtering of the unicast data that would be
otherwise discarded by the MVD client.
==============
*/
-void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable ) {
+void SV_MvdUnicast(edict_t *ent, int clientNum, qboolean reliable)
+{
mvd_ops_t op;
sizebuf_t *buf;
int bits;
// do nothing if not active
- if( !mvd.active ) {
+ if (!mvd.active) {
return;
}
// discard any data to players not in the game
- if( !player_is_active( ent ) ) {
+ if (!player_is_active(ent)) {
return;
}
- switch( msg_write.data[0] ) {
+ switch (msg_write.data[0]) {
case svc_layout:
- if( ent == mvd.dummy->edict ) {
+ if (ent == mvd.dummy->edict) {
// special case, send to all observers
mvd.layout_time = svs.realtime;
} else {
@@ -1082,13 +1103,13 @@ void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable ) {
}
break;
case svc_stufftext:
- if( memcmp( msg_write.data + 1, "play ", 5 ) ) {
+ if (memcmp(msg_write.data + 1, "play ", 5)) {
// discard any stufftexts, except of play sound hacks
return;
}
break;
case svc_print:
- if( ent != mvd.dummy->edict && sv_mvd_nomsgs->integer ) {
+ if (ent != mvd.dummy->edict && sv_mvd_nomsgs->integer) {
// optionally discard text messages to players
return;
}
@@ -1096,7 +1117,7 @@ void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable ) {
}
// decide where should it go
- if( reliable ) {
+ if (reliable) {
op = mvd_unicast_r;
buf = &mvd.message;
} else {
@@ -1105,11 +1126,11 @@ void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable ) {
}
// write it
- bits = ( msg_write.cursize >> 8 ) & 7;
- SZ_WriteByte( buf, op | ( bits << SVCMD_BITS ) );
- SZ_WriteByte( buf, msg_write.cursize & 255 );
- SZ_WriteByte( buf, clientNum );
- SZ_Write( buf, msg_write.data, msg_write.cursize );
+ bits = (msg_write.cursize >> 8) & 7;
+ SZ_WriteByte(buf, op | (bits << SVCMD_BITS));
+ SZ_WriteByte(buf, msg_write.cursize & 255);
+ SZ_WriteByte(buf, clientNum);
+ SZ_Write(buf, msg_write.data, msg_write.cursize);
}
/*
@@ -1117,12 +1138,13 @@ void SV_MvdUnicast( edict_t *ent, int clientNum, qboolean reliable ) {
SV_MvdConfigstring
==============
*/
-void SV_MvdConfigstring( int index, const char *string, size_t len ) {
- if( mvd.active ) {
- SZ_WriteByte( &mvd.message, mvd_configstring );
- SZ_WriteShort( &mvd.message, index );
- SZ_Write( &mvd.message, string, len );
- SZ_WriteByte( &mvd.message, 0 );
+void SV_MvdConfigstring(int index, const char *string, size_t len)
+{
+ if (mvd.active) {
+ SZ_WriteByte(&mvd.message, mvd_configstring);
+ SZ_WriteShort(&mvd.message, index);
+ SZ_Write(&mvd.message, string, len);
+ SZ_WriteByte(&mvd.message, 0);
}
}
@@ -1131,11 +1153,12 @@ void SV_MvdConfigstring( int index, const char *string, size_t len ) {
SV_MvdBroadcastPrint
==============
*/
-void SV_MvdBroadcastPrint( int level, const char *string ) {
- if( mvd.active ) {
- SZ_WriteByte( &mvd.message, mvd_print );
- SZ_WriteByte( &mvd.message, level );
- SZ_WriteString( &mvd.message, string );
+void SV_MvdBroadcastPrint(int level, const char *string)
+{
+ if (mvd.active) {
+ SZ_WriteByte(&mvd.message, mvd_print);
+ SZ_WriteByte(&mvd.message, level);
+ SZ_WriteString(&mvd.message, string);
}
}
@@ -1146,39 +1169,39 @@ SV_MvdStartSound
FIXME: origin will be incorrect on entities not captured this frame
==============
*/
-void SV_MvdStartSound( int entnum, int channel, int flags,
- int soundindex, int volume,
- int attenuation, int timeofs )
+void SV_MvdStartSound(int entnum, int channel, int flags,
+ int soundindex, int volume,
+ int attenuation, int timeofs)
{
int extrabits, sendchan;
// do nothing if not active
- if( !mvd.active ) {
+ if (!mvd.active) {
return;
}
extrabits = 0;
- if( channel & CHAN_NO_PHS_ADD ) {
+ if (channel & CHAN_NO_PHS_ADD) {
extrabits |= 1 << SVCMD_BITS;
}
- if( channel & CHAN_RELIABLE ) {
+ if (channel & CHAN_RELIABLE) {
// FIXME: write to mvd.message
extrabits |= 2 << SVCMD_BITS;
}
- SZ_WriteByte( &mvd.datagram, mvd_sound | extrabits );
- SZ_WriteByte( &mvd.datagram, flags );
- SZ_WriteByte( &mvd.datagram, soundindex );
+ SZ_WriteByte(&mvd.datagram, mvd_sound | extrabits);
+ SZ_WriteByte(&mvd.datagram, flags);
+ SZ_WriteByte(&mvd.datagram, soundindex);
- if( flags & SND_VOLUME )
- SZ_WriteByte( &mvd.datagram, volume );
- if( flags & SND_ATTENUATION )
- SZ_WriteByte( &mvd.datagram, attenuation );
- if( flags & SND_OFFSET )
- SZ_WriteByte( &mvd.datagram, timeofs );
+ if (flags & SND_VOLUME)
+ SZ_WriteByte(&mvd.datagram, volume);
+ if (flags & SND_ATTENUATION)
+ SZ_WriteByte(&mvd.datagram, attenuation);
+ if (flags & SND_OFFSET)
+ SZ_WriteByte(&mvd.datagram, timeofs);
- sendchan = ( entnum << 3 ) | ( channel & 7 );
- SZ_WriteShort( &mvd.datagram, sendchan );
+ sendchan = (entnum << 3) | (channel & 7);
+ SZ_WriteShort(&mvd.datagram, sendchan);
}
@@ -1191,28 +1214,30 @@ TCP CLIENTS HANDLING
*/
-static void remove_client( gtv_client_t *client ) {
- NET_Close( &client->stream );
- List_Remove( &client->entry );
- if( client->data ) {
- Z_Free( client->data );
+static void remove_client(gtv_client_t *client)
+{
+ NET_Close(&client->stream);
+ List_Remove(&client->entry);
+ if (client->data) {
+ Z_Free(client->data);
client->data = NULL;
}
client->state = cs_free;
}
#if USE_ZLIB
-static void flush_stream( gtv_client_t *client, int flush ) {
+static void flush_stream(gtv_client_t *client, int flush)
+{
fifo_t *fifo = &client->stream.send;
z_streamp z = &client->z;
byte *data;
size_t len;
int ret;
- if( client->state <= cs_zombie ) {
+ if (client->state <= cs_zombie) {
return;
}
- if( !z->state ) {
+ if (!z->state) {
return;
}
@@ -1220,161 +1245,166 @@ static void flush_stream( gtv_client_t *client, int flush ) {
z->avail_in = 0;
do {
- data = FIFO_Reserve( fifo, &len );
- if( !len ) {
+ data = FIFO_Reserve(fifo, &len);
+ if (!len) {
// FIXME: this is not an error when flushing
return;
}
z->next_out = data;
- z->avail_out = ( uInt )len;
+ z->avail_out = (uInt)len;
- ret = deflate( z, flush );
+ ret = deflate(z, flush);
len -= z->avail_out;
- if( len ) {
- FIFO_Commit( fifo, len );
+ if (len) {
+ FIFO_Commit(fifo, len);
client->bufcount = 0;
}
- } while( ret == Z_OK );
+ } while (ret == Z_OK);
}
#endif
-static void drop_client( gtv_client_t *client, const char *error ) {
- if( client->state <= cs_zombie ) {
+static void drop_client(gtv_client_t *client, const char *error)
+{
+ if (client->state <= cs_zombie) {
return;
}
- if( error ) {
+ if (error) {
// notify console
- Com_Printf( "TCP client %s[%s] dropped: %s\n", client->name,
- NET_AdrToString( &client->stream.address ), error );
+ Com_Printf("TCP client %s[%s] dropped: %s\n", client->name,
+ NET_AdrToString(&client->stream.address), error);
}
#if USE_ZLIB
- if( client->z.state ) {
+ if (client->z.state) {
// finish zlib stream
- flush_stream( client, Z_FINISH );
- deflateEnd( &client->z );
+ flush_stream(client, Z_FINISH);
+ deflateEnd(&client->z);
}
#endif
- List_Remove( &client->active );
+ List_Remove(&client->active);
client->state = cs_zombie;
client->lastmessage = svs.realtime;
}
-static void write_stream( gtv_client_t *client, void *data, size_t len ) {
+static void write_stream(gtv_client_t *client, void *data, size_t len)
+{
fifo_t *fifo = &client->stream.send;
- if( client->state <= cs_zombie ) {
+ if (client->state <= cs_zombie) {
return;
}
- if( !len ) {
+ if (!len) {
return;
}
#if USE_ZLIB
- if( client->z.state ) {
+ if (client->z.state) {
z_streamp z = &client->z;
z->next_in = data;
- z->avail_in = ( uInt )len;
+ z->avail_in = (uInt)len;
do {
- data = FIFO_Reserve( fifo, &len );
- if( !len ) {
- drop_client( client, "overflowed" );
+ data = FIFO_Reserve(fifo, &len);
+ if (!len) {
+ drop_client(client, "overflowed");
return;
}
z->next_out = data;
- z->avail_out = ( uInt )len;
+ z->avail_out = (uInt)len;
- if( deflate( z, Z_NO_FLUSH ) != Z_OK ) {
- drop_client( client, "deflate() failed" );
+ if (deflate(z, Z_NO_FLUSH) != Z_OK) {
+ drop_client(client, "deflate() failed");
return;
}
len -= z->avail_out;
- if( len ) {
- FIFO_Commit( fifo, len );
+ if (len) {
+ FIFO_Commit(fifo, len);
client->bufcount = 0;
}
- } while( z->avail_in );
+ } while (z->avail_in);
} else
#endif
- if( FIFO_Write( fifo, data, len ) != len ) {
- drop_client( client, "overflowed" );
- }
+ if (FIFO_Write(fifo, data, len) != len) {
+ drop_client(client, "overflowed");
+ }
}
-static void write_message( gtv_client_t *client, gtv_serverop_t op ) {
+static void write_message(gtv_client_t *client, gtv_serverop_t op)
+{
byte header[3];
size_t len = msg_write.cursize + 1;
header[0] = len & 255;
- header[1] = ( len >> 8 ) & 255;
+ header[1] = (len >> 8) & 255;
header[2] = op;
- write_stream( client, header, sizeof( header ) );
+ write_stream(client, header, sizeof(header));
- write_stream( client, msg_write.data, msg_write.cursize );
+ write_stream(client, msg_write.data, msg_write.cursize);
}
-static qboolean auth_client( gtv_client_t *client, const char *password ) {
- if( SV_MatchAddress( &gtv_host_list, &client->stream.address ) ) {
+static qboolean auth_client(gtv_client_t *client, const char *password)
+{
+ if (SV_MatchAddress(&gtv_host_list, &client->stream.address)) {
return qtrue; // dedicated GTV hosts don't need password
}
- if( !sv_mvd_password->string[0] ) {
+ if (!sv_mvd_password->string[0]) {
return qfalse; // no password set on the server
}
- if( strcmp( sv_mvd_password->string, password ) ) {
+ if (strcmp(sv_mvd_password->string, password)) {
return qfalse; // password doesn't match
}
return qtrue;
}
-static void parse_hello( gtv_client_t *client ) {
+static void parse_hello(gtv_client_t *client)
+{
char password[MAX_QPATH];
int protocol, flags;
size_t size;
byte *data;
- if( client->state >= cs_primed ) {
- drop_client( client, "duplicated hello message" );
+ if (client->state >= cs_primed) {
+ drop_client(client, "duplicated hello message");
return;
}
// client should have already consumed the magic
- if( FIFO_Usage( &client->stream.send ) ) {
- drop_client( client, "send buffer not empty" );
+ if (FIFO_Usage(&client->stream.send)) {
+ drop_client(client, "send buffer not empty");
return;
}
protocol = MSG_ReadWord();
- if( protocol != GTV_PROTOCOL_VERSION ) {
- write_message( client, GTS_BADREQUEST );
- drop_client( client, "bad protocol version" );
+ if (protocol != GTV_PROTOCOL_VERSION) {
+ write_message(client, GTS_BADREQUEST);
+ drop_client(client, "bad protocol version");
return;
}
flags = MSG_ReadLong();
MSG_ReadLong();
- MSG_ReadString( client->name, sizeof( client->name ) );
- MSG_ReadString( password, sizeof( password ) );
- MSG_ReadString( client->version, sizeof( client->version ) );
+ MSG_ReadString(client->name, sizeof(client->name));
+ MSG_ReadString(password, sizeof(password));
+ MSG_ReadString(client->version, sizeof(client->version));
// authorize access
- if( !auth_client( client, password ) ) {
- write_message( client, GTS_NOACCESS );
- drop_client( client, "not authorized" );
+ if (!auth_client(client, password)) {
+ write_message(client, GTS_NOACCESS);
+ drop_client(client, "not authorized");
return;
}
- if( sv_mvd_allow_stufftext->integer >= 0 ) {
+ if (sv_mvd_allow_stufftext->integer >= 0) {
flags &= ~GTF_STRINGCMDS;
}
@@ -1382,11 +1412,11 @@ static void parse_hello( gtv_client_t *client ) {
flags &= ~GTF_DEFLATE;
#endif
- Cvar_ClampInteger( sv_mvd_bufsize, 1, 4 );
+ Cvar_ClampInteger(sv_mvd_bufsize, 1, 4);
// allocate larger send buffer
size = MAX_GTS_MSGLEN * sv_mvd_bufsize->integer;
- data = SV_Malloc( size );
+ data = SV_Malloc(size);
client->stream.send.data = data;
client->stream.send.size = size;
client->data = data;
@@ -1394,245 +1424,252 @@ static void parse_hello( gtv_client_t *client ) {
client->state = cs_primed;
// send hello
- MSG_WriteLong( flags );
- write_message( client, GTS_HELLO );
- SZ_Clear( &msg_write );
+ MSG_WriteLong(flags);
+ write_message(client, GTS_HELLO);
+ SZ_Clear(&msg_write);
#if USE_ZLIB
// the rest of the stream will be deflated
- if( flags & GTF_DEFLATE ) {
+ if (flags & GTF_DEFLATE) {
client->z.zalloc = SV_Zalloc;
client->z.zfree = SV_Zfree;
- if( deflateInit( &client->z, Z_DEFAULT_COMPRESSION ) != Z_OK ) {
- drop_client( client, "deflateInit failed" );
+ if (deflateInit(&client->z, Z_DEFAULT_COMPRESSION) != Z_OK) {
+ drop_client(client, "deflateInit failed");
return;
}
}
#endif
- Com_Printf( "Accepted MVD client %s[%s]\n", client->name,
- NET_AdrToString( &client->stream.address ) );
+ Com_Printf("Accepted MVD client %s[%s]\n", client->name,
+ NET_AdrToString(&client->stream.address));
}
-static void parse_ping( gtv_client_t *client ) {
- if( client->state < cs_primed ) {
+static void parse_ping(gtv_client_t *client)
+{
+ if (client->state < cs_primed) {
return;
}
// send ping reply
- write_message( client, GTS_PONG );
+ write_message(client, GTS_PONG);
#if USE_ZLIB
- flush_stream( client, Z_SYNC_FLUSH );
+ flush_stream(client, Z_SYNC_FLUSH);
#endif
}
-static void parse_stream_start( gtv_client_t *client ) {
+static void parse_stream_start(gtv_client_t *client)
+{
int maxbuf;
- if( client->state != cs_primed ) {
- drop_client( client, "unexpected stream start message" );
+ if (client->state != cs_primed) {
+ drop_client(client, "unexpected stream start message");
return;
}
- if( !mvd_enable() ) {
- write_message( client, GTS_ERROR );
- drop_client( client, "couldn't create MVD dummy" );
+ if (!mvd_enable()) {
+ write_message(client, GTS_ERROR);
+ drop_client(client, "couldn't create MVD dummy");
return;
}
maxbuf = MSG_ReadShort();
- if( maxbuf < 10 ) {
+ if (maxbuf < 10) {
maxbuf = 10;
}
client->maxbuf = maxbuf;
client->state = cs_spawned;
- List_Append( &gtv_active_list, &client->active );
+ List_Append(&gtv_active_list, &client->active);
// send ack to client
- write_message( client, GTS_STREAM_START );
+ write_message(client, GTS_STREAM_START);
// send gamestate if active
- if( mvd.active ) {
+ if (mvd.active) {
emit_gamestate();
- write_message( client, GTS_STREAM_DATA );
- SZ_Clear( &msg_write );
+ write_message(client, GTS_STREAM_DATA);
+ SZ_Clear(&msg_write);
} else {
// send stream suspend marker
- write_message( client, GTS_STREAM_DATA );
+ write_message(client, GTS_STREAM_DATA);
}
#if USE_ZLIB
- flush_stream( client, Z_SYNC_FLUSH );
+ flush_stream(client, Z_SYNC_FLUSH);
#endif
}
-static void parse_stream_stop( gtv_client_t *client ) {
- if( client->state != cs_spawned ) {
- drop_client( client, "unexpected stream stop message" );
+static void parse_stream_stop(gtv_client_t *client)
+{
+ if (client->state != cs_spawned) {
+ drop_client(client, "unexpected stream stop message");
return;
}
client->state = cs_primed;
- List_Delete( &client->active );
+ List_Delete(&client->active);
// send ack to client
- write_message( client, GTS_STREAM_STOP );
+ write_message(client, GTS_STREAM_STOP);
#if USE_ZLIB
- flush_stream( client, Z_SYNC_FLUSH );
+ flush_stream(client, Z_SYNC_FLUSH);
#endif
}
-static void parse_stringcmd( gtv_client_t *client ) {
+static void parse_stringcmd(gtv_client_t *client)
+{
char string[MAX_GTC_MSGLEN];
- if( client->state < cs_primed ) {
- drop_client( client, "unexpected stringcmd message" );
+ if (client->state < cs_primed) {
+ drop_client(client, "unexpected stringcmd message");
return;
}
- if( !mvd.dummy || !( client->flags & GTF_STRINGCMDS ) ) {
- Com_DPrintf( "ignored stringcmd from %s[%s]\n", client->name,
- NET_AdrToString( &client->stream.address ) );
+ if (!mvd.dummy || !(client->flags & GTF_STRINGCMDS)) {
+ Com_DPrintf("ignored stringcmd from %s[%s]\n", client->name,
+ NET_AdrToString(&client->stream.address));
return;
}
- MSG_ReadString( string, sizeof( string ) );
+ MSG_ReadString(string, sizeof(string));
- Cmd_TokenizeString( string, qfalse );
+ Cmd_TokenizeString(string, qfalse);
- Com_DPrintf( "dummy stringcmd from %s[%s]: %s\n", client->name,
- NET_AdrToString( &client->stream.address ), string );
+ Com_DPrintf("dummy stringcmd from %s[%s]: %s\n", client->name,
+ NET_AdrToString(&client->stream.address), string);
dummy_command();
}
-static qboolean parse_message( gtv_client_t *client ) {
+static qboolean parse_message(gtv_client_t *client)
+{
uint32_t magic;
uint16_t msglen;
int cmd;
- if( client->state <= cs_zombie ) {
+ if (client->state <= cs_zombie) {
return qfalse;
}
// check magic
- if( client->state < cs_connected ) {
- if( !FIFO_TryRead( &client->stream.recv, &magic, 4 ) ) {
+ if (client->state < cs_connected) {
+ if (!FIFO_TryRead(&client->stream.recv, &magic, 4)) {
return qfalse;
}
- if( magic != MVD_MAGIC ) {
- drop_client( client, "not a MVD/GTV stream" );
+ if (magic != MVD_MAGIC) {
+ drop_client(client, "not a MVD/GTV stream");
return qfalse;
}
client->state = cs_connected;
// send it back
- write_stream( client, &magic, 4 );
+ write_stream(client, &magic, 4);
return qfalse;
}
// parse msglen
- if( !client->msglen ) {
- if( !FIFO_TryRead( &client->stream.recv, &msglen, 2 ) ) {
+ if (!client->msglen) {
+ if (!FIFO_TryRead(&client->stream.recv, &msglen, 2)) {
return qfalse;
}
- msglen = LittleShort( msglen );
- if( !msglen ) {
- drop_client( client, "end of stream" );
+ msglen = LittleShort(msglen);
+ if (!msglen) {
+ drop_client(client, "end of stream");
return qfalse;
}
- if( msglen > MAX_GTC_MSGLEN ) {
- drop_client( client, "oversize message" );
+ if (msglen > MAX_GTC_MSGLEN) {
+ drop_client(client, "oversize message");
return qfalse;
}
client->msglen = msglen;
}
// read this message
- if( !FIFO_ReadMessage( &client->stream.recv, client->msglen ) ) {
+ if (!FIFO_ReadMessage(&client->stream.recv, client->msglen)) {
return qfalse;
}
client->msglen = 0;
cmd = MSG_ReadByte();
- switch( cmd ) {
+ switch (cmd) {
case GTC_HELLO:
- parse_hello( client );
+ parse_hello(client);
break;
case GTC_PING:
- parse_ping( client );
+ parse_ping(client);
break;
case GTC_STREAM_START:
- parse_stream_start( client );
+ parse_stream_start(client);
break;
case GTC_STREAM_STOP:
- parse_stream_stop( client );
+ parse_stream_stop(client);
break;
case GTC_STRINGCMD:
- parse_stringcmd( client );
+ parse_stringcmd(client);
break;
default:
- drop_client( client, "unknown command byte" );
+ drop_client(client, "unknown command byte");
return qfalse;
}
- if( msg_read.readcount > msg_read.cursize ) {
- drop_client( client, "read past end of message" );
+ if (msg_read.readcount > msg_read.cursize) {
+ drop_client(client, "read past end of message");
return qfalse;
}
-
+
client->lastmessage = svs.realtime; // don't timeout
return qtrue;
}
-static gtv_client_t *find_slot( void ) {
+static gtv_client_t *find_slot(void)
+{
gtv_client_t *client;
int i;
- for( i = 0; i < sv_mvd_maxclients->integer; i++ ) {
+ for (i = 0; i < sv_mvd_maxclients->integer; i++) {
client = &mvd.clients[i];
- if( !client->state ) {
+ if (!client->state) {
return client;
}
}
return NULL;
}
-static void accept_client( netstream_t *stream ) {
+static void accept_client(netstream_t *stream)
+{
gtv_client_t *client;
netstream_t *s;
// limit number of connections from single IP
- if( sv_iplimit->integer > 0 ) {
+ if (sv_iplimit->integer > 0) {
int count = 0;
- FOR_EACH_GTV( client ) {
- if( NET_IsEqualBaseAdr( &client->stream.address, &stream->address ) ) {
+ FOR_EACH_GTV(client) {
+ if (NET_IsEqualBaseAdr(&client->stream.address, &stream->address)) {
count++;
}
}
- if( count >= sv_iplimit->integer ) {
- Com_Printf( "TCP client [%s] rejected: too many connections\n",
- NET_AdrToString( &stream->address ) );
- NET_Close( stream );
+ if (count >= sv_iplimit->integer) {
+ Com_Printf("TCP client [%s] rejected: too many connections\n",
+ NET_AdrToString(&stream->address));
+ NET_Close(stream);
return;
}
}
// find a free client slot
client = find_slot();
- if( !client ) {
- Com_Printf( "TCP client [%s] rejected: no free slots\n",
- NET_AdrToString( &stream->address ) );
- NET_Close( stream );
+ if (!client) {
+ Com_Printf("TCP client [%s] rejected: no free slots\n",
+ NET_AdrToString(&stream->address));
+ NET_Close(stream);
return;
}
- memset( client, 0, sizeof( *client ) );
+ memset(client, 0, sizeof(*client));
s = &client->stream;
s->recv.data = client->buffer;
@@ -1645,14 +1682,15 @@ static void accept_client( netstream_t *stream ) {
client->lastmessage = svs.realtime;
client->state = cs_assigned;
- List_SeqAdd( &gtv_client_list, &client->entry );
- List_Init( &client->active );
+ List_SeqAdd(&gtv_client_list, &client->entry);
+ List_Init(&client->active);
- Com_DPrintf( "TCP client [%s] accepted\n",
- NET_AdrToString( &stream->address ) );
+ Com_DPrintf("TCP client [%s] accepted\n",
+ NET_AdrToString(&stream->address));
}
-void SV_MvdRunClients( void ) {
+void SV_MvdRunClients(void)
+{
gtv_client_t *client;
neterr_t ret;
netstream_t stream;
@@ -1662,165 +1700,170 @@ void SV_MvdRunClients( void ) {
unsigned delta;
// accept new connections
- ret = NET_Accept( &stream );
- if( ret == NET_ERROR ) {
- Com_DPrintf( "%s from %s, ignored\n", NET_ErrorString(),
- NET_AdrToString( &net_from ) );
- } else if( ret == NET_OK ) {
- accept_client( &stream );
+ ret = NET_Accept(&stream);
+ if (ret == NET_ERROR) {
+ Com_DPrintf("%s from %s, ignored\n", NET_ErrorString(),
+ NET_AdrToString(&net_from));
+ } else if (ret == NET_OK) {
+ accept_client(&stream);
}
// run existing connections
- FOR_EACH_GTV( client ) {
+ FOR_EACH_GTV(client) {
// check timeouts
delta = svs.realtime - client->lastmessage;
- switch( client->state ) {
+ switch (client->state) {
case cs_zombie:
- if( delta > zombie_time || !FIFO_Usage( &client->stream.send ) ) {
- remove_client( client );
+ if (delta > zombie_time || !FIFO_Usage(&client->stream.send)) {
+ remove_client(client);
continue;
}
break;
case cs_assigned:
case cs_connected:
- if( delta > ghost_time || delta > drop_time ) {
- drop_client( client, "request timed out" );
- remove_client( client );
+ if (delta > ghost_time || delta > drop_time) {
+ drop_client(client, "request timed out");
+ remove_client(client);
continue;
}
break;
default:
- if( delta > drop_time ) {
- drop_client( client, "connection timed out" );
- remove_client( client );
+ if (delta > drop_time) {
+ drop_client(client, "connection timed out");
+ remove_client(client);
continue;
}
break;
}
// run network stream
- ret = NET_RunStream( &client->stream );
- switch( ret ) {
+ ret = NET_RunStream(&client->stream);
+ switch (ret) {
case NET_AGAIN:
break;
case NET_OK:
// parse the message
- while( parse_message( client ) )
+ while (parse_message(client))
;
- NET_UpdateStream( &client->stream );
+ NET_UpdateStream(&client->stream);
break;
case NET_CLOSED:
- drop_client( client, "EOF from client" );
- remove_client( client );
+ drop_client(client, "EOF from client");
+ remove_client(client);
break;
case NET_ERROR:
- drop_client( client, "connection reset by peer" );
- remove_client( client );
+ drop_client(client, "connection reset by peer");
+ remove_client(client);
break;
}
}
}
-static void dump_clients( void ) {
+static void dump_clients(void)
+{
gtv_client_t *client;
int count;
Com_Printf(
-"num name buf lastmsg address state\n"
-"--- ---------------- --- ------- --------------------- -----\n" );
+ "num name buf lastmsg address state\n"
+ "--- ---------------- --- ------- --------------------- -----\n");
count = 0;
- FOR_EACH_GTV( client ) {
- Com_Printf( "%3d %-16.16s %3"PRIz" %7u %-21s ",
- count, client->name, FIFO_Usage( &client->stream.send ),
- svs.realtime - client->lastmessage,
- NET_AdrToString( &client->stream.address ) );
+ FOR_EACH_GTV(client) {
+ Com_Printf("%3d %-16.16s %3"PRIz" %7u %-21s ",
+ count, client->name, FIFO_Usage(&client->stream.send),
+ svs.realtime - client->lastmessage,
+ NET_AdrToString(&client->stream.address));
- switch( client->state ) {
+ switch (client->state) {
case cs_zombie:
- Com_Printf( "ZMBI " );
+ Com_Printf("ZMBI ");
break;
case cs_assigned:
- Com_Printf( "ASGN " );
+ Com_Printf("ASGN ");
break;
case cs_connected:
- Com_Printf( "CNCT " );
+ Com_Printf("CNCT ");
break;
case cs_primed:
- Com_Printf( "PRIM " );
+ Com_Printf("PRIM ");
break;
default:
- Com_Printf( "SEND " );
+ Com_Printf("SEND ");
break;
}
- Com_Printf( "\n" );
+ Com_Printf("\n");
count++;
}
}
-static void dump_versions( void ) {
+static void dump_versions(void)
+{
gtv_client_t *client;
int count;
Com_Printf(
-"num name version\n"
-"--- ---------------- -----------------------------------------\n" );
+ "num name version\n"
+ "--- ---------------- -----------------------------------------\n");
- FOR_EACH_GTV( client ) {
- count = 0;
- Com_Printf( "%3i %-16.16s %-40.40s\n",
- count, client->name, client->version );
+ FOR_EACH_GTV(client) {
+ count = 0;
+ Com_Printf("%3i %-16.16s %-40.40s\n",
+ count, client->name, client->version);
count++;
}
}
-void SV_MvdStatus_f( void ) {
- if( LIST_EMPTY( &gtv_client_list ) ) {
- Com_Printf( "No TCP clients.\n" );
+void SV_MvdStatus_f(void)
+{
+ if (LIST_EMPTY(&gtv_client_list)) {
+ Com_Printf("No TCP clients.\n");
} else {
- if( Cmd_Argc() > 1 ) {
+ if (Cmd_Argc() > 1) {
dump_versions();
} else {
dump_clients();
}
}
- Com_Printf( "\n" );
+ Com_Printf("\n");
}
-static void mvd_disable( void ) {
+static void mvd_disable(void)
+{
// remove MVD dummy
- if( mvd.dummy ) {
- SV_RemoveClient( mvd.dummy );
+ if (mvd.dummy) {
+ SV_RemoveClient(mvd.dummy);
mvd.dummy = NULL;
}
- SZ_Clear( &mvd.datagram );
- SZ_Clear( &mvd.message );
+ SZ_Clear(&mvd.datagram);
+ SZ_Clear(&mvd.message);
mvd.active = qfalse;
}
// something bad happened, remove all clients
-static void mvd_drop( gtv_serverop_t op ) {
+static void mvd_drop(gtv_serverop_t op)
+{
gtv_client_t *client;
// stop recording
rec_stop();
// drop GTV clients
- FOR_EACH_GTV( client ) {
- switch( client->state ) {
+ FOR_EACH_GTV(client) {
+ switch (client->state) {
case cs_spawned:
case cs_primed:
- write_message( client, op );
- drop_client( client, NULL );
- NET_RunStream( &client->stream );
- NET_RunStream( &client->stream );
- remove_client( client );
+ write_message(client, op);
+ drop_client(client, NULL);
+ NET_RunStream(&client->stream);
+ NET_RunStream(&client->stream);
+ remove_client(client);
break;
default:
- drop_client( client, NULL );
- remove_client( client );
+ drop_client(client, NULL);
+ remove_client(client);
break;
}
}
@@ -1829,9 +1872,10 @@ static void mvd_drop( gtv_serverop_t op ) {
}
// if dummy is not yet connected, create and spawn it
-static qboolean mvd_enable( void ) {
- if( !mvd.dummy ) {
- if( !dummy_create() ) {
+static qboolean mvd_enable(void)
+{
+ if (!mvd.dummy) {
+ if (!dummy_create()) {
return qfalse;
}
@@ -1864,57 +1908,58 @@ SV_MvdMapChanged
Server has just changed the map, spawn the MVD dummy and go!
==================
*/
-void SV_MvdMapChanged( void ) {
+void SV_MvdMapChanged(void)
+{
gtv_client_t *client;
- if( !sv_mvd_enable->integer ) {
+ if (!sv_mvd_enable->integer) {
return; // do noting if disabled
}
- if( !mvd.dummy ) {
- if( !sv_mvd_autorecord->integer ) {
+ if (!mvd.dummy) {
+ if (!sv_mvd_autorecord->integer) {
return; // not listening for autorecord command
}
- if( !dummy_create() ) {
+ if (!dummy_create()) {
return;
}
- Com_Printf( "Spawning MVD dummy for auto-recording\n" );
- Cvar_Set( "sv_mvd_suspend_time", "0" );
+ Com_Printf("Spawning MVD dummy for auto-recording\n");
+ Cvar_Set("sv_mvd_suspend_time", "0");
}
dummy_spawn();
- if( mvd.active ) {
+ if (mvd.active) {
// build and emit gamestate
build_gamestate();
emit_gamestate();
// send gamestate to all MVD clients
- FOR_EACH_ACTIVE_GTV( client ) {
- write_message( client, GTS_STREAM_DATA );
- NET_UpdateStream( &client->stream );
+ FOR_EACH_ACTIVE_GTV(client) {
+ write_message(client, GTS_STREAM_DATA);
+ NET_UpdateStream(&client->stream);
}
}
- if( mvd.recording ) {
+ if (mvd.recording) {
int maxlevels = sv_mvd_maxmaps->integer;
-
+
// check if it is time to stop recording
- if( maxlevels > 0 && ++mvd.numlevels >= maxlevels ) {
- Com_Printf( "Stopping MVD recording, "
- "maximum number of level changes reached.\n" );
+ if (maxlevels > 0 && ++mvd.numlevels >= maxlevels) {
+ Com_Printf("Stopping MVD recording, "
+ "maximum number of level changes reached.\n");
rec_stop();
- } else if( mvd.active ) {
+ } else if (mvd.active) {
// write gamestate to demofile
rec_write();
}
}
// clear gamestate
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- SZ_Clear( &mvd.datagram );
- SZ_Clear( &mvd.message );
+ SZ_Clear(&mvd.datagram);
+ SZ_Clear(&mvd.message);
}
/*
@@ -1924,9 +1969,10 @@ SV_MvdClientDropped
Server has just dropped a client, check if that was our MVD dummy client.
==================
*/
-void SV_MvdClientDropped( client_t *client ) {
- if( client == mvd.dummy ) {
- mvd_drop( GTS_ERROR );
+void SV_MvdClientDropped(client_t *client)
+{
+ if (client == mvd.dummy) {
+ mvd_drop(GTS_ERROR);
}
}
@@ -1937,39 +1983,40 @@ SV_MvdInit
Server is initializing, prepare MVD server for this game.
==================
*/
-void SV_MvdInit( void ) {
- if( !sv_mvd_enable->integer ) {
+void SV_MvdInit(void)
+{
+ if (!sv_mvd_enable->integer) {
return; // do nothing if disabled
}
// allocate buffers
- Z_TagReserve( sizeof( player_state_t ) * sv_maxclients->integer +
- sizeof( entity_state_t ) * MAX_EDICTS + MAX_MSGLEN * 2, TAG_SERVER );
- SZ_Init( &mvd.message, Z_ReservedAlloc( MAX_MSGLEN ), MAX_MSGLEN );
- SZ_Init( &mvd.datagram, Z_ReservedAlloc( MAX_MSGLEN ), MAX_MSGLEN );
- mvd.players = Z_ReservedAlloc( sizeof( player_state_t ) * sv_maxclients->integer );
- mvd.entities = Z_ReservedAlloc( sizeof( entity_state_t ) * MAX_EDICTS );
+ Z_TagReserve(sizeof(player_state_t) * sv_maxclients->integer +
+ sizeof(entity_state_t) * MAX_EDICTS + MAX_MSGLEN * 2, TAG_SERVER);
+ SZ_Init(&mvd.message, Z_ReservedAlloc(MAX_MSGLEN), MAX_MSGLEN);
+ SZ_Init(&mvd.datagram, Z_ReservedAlloc(MAX_MSGLEN), MAX_MSGLEN);
+ mvd.players = Z_ReservedAlloc(sizeof(player_state_t) * sv_maxclients->integer);
+ mvd.entities = Z_ReservedAlloc(sizeof(entity_state_t) * MAX_EDICTS);
// reserve the slot for dummy MVD client
- if( !sv_reserved_slots->integer ) {
- Cvar_Set( "sv_reserved_slots", "1" );
+ if (!sv_reserved_slots->integer) {
+ Cvar_Set("sv_reserved_slots", "1");
}
- Cvar_ClampInteger( sv_mvd_maxclients, 1, 256 );
+ Cvar_ClampInteger(sv_mvd_maxclients, 1, 256);
// open server TCP socket
- if( sv_mvd_enable->integer > 1 ) {
- if( NET_Listen( qtrue ) == NET_OK ) {
- mvd.clients = SV_Mallocz( sizeof( gtv_client_t ) * sv_mvd_maxclients->integer );
+ if (sv_mvd_enable->integer > 1) {
+ if (NET_Listen(qtrue) == NET_OK) {
+ mvd.clients = SV_Mallocz(sizeof(gtv_client_t) * sv_mvd_maxclients->integer);
} else {
- Com_EPrintf( "%s while opening server TCP port.\n", NET_ErrorString() );
- Cvar_Set( "sv_mvd_enable", "1" );
+ Com_EPrintf("%s while opening server TCP port.\n", NET_ErrorString());
+ Cvar_Set("sv_mvd_enable", "1");
}
}
dummy_buffer.from = FROM_CONSOLE;
dummy_buffer.text = dummy_buffer_text;
- dummy_buffer.maxsize = sizeof( dummy_buffer_text );
+ dummy_buffer.maxsize = sizeof(dummy_buffer_text);
dummy_buffer.exec = dummy_exec_string;
}
@@ -1980,20 +2027,21 @@ SV_MvdShutdown
Server is shutting down, clean everything up.
==================
*/
-void SV_MvdShutdown( error_type_t type ) {
+void SV_MvdShutdown(error_type_t type)
+{
// drop all clients
- mvd_drop( type == ERR_RECONNECT ? GTS_RECONNECT : GTS_DISCONNECT );
+ mvd_drop(type == ERR_RECONNECT ? GTS_RECONNECT : GTS_DISCONNECT);
// free static data
- Z_Free( mvd.message.data );
- Z_Free( mvd.clients );
+ Z_Free(mvd.message.data);
+ Z_Free(mvd.clients);
// close server TCP socket
- NET_Listen( qfalse );
+ NET_Listen(qfalse);
- memset( &mvd, 0, sizeof( mvd ) );
+ memset(&mvd, 0, sizeof(mvd));
- memset( &dummy_buffer, 0, sizeof( dummy_buffer ) );
+ memset(&dummy_buffer, 0, sizeof(dummy_buffer));
}
@@ -2005,23 +2053,24 @@ LOCAL MVD RECORDER
==============================================================================
*/
-static void rec_write( void ) {
+static void rec_write(void)
+{
uint16_t msglen;
ssize_t ret;
- if( !msg_write.cursize )
+ if (!msg_write.cursize)
return;
- msglen = LittleShort( msg_write.cursize );
- ret = FS_Write( &msglen, 2, mvd.recording );
- if( ret != 2 )
+ msglen = LittleShort(msg_write.cursize);
+ ret = FS_Write(&msglen, 2, mvd.recording);
+ if (ret != 2)
goto fail;
- ret = FS_Write( msg_write.data, msg_write.cursize, mvd.recording );
- if( ret == msg_write.cursize )
+ ret = FS_Write(msg_write.data, msg_write.cursize, mvd.recording);
+ if (ret == msg_write.cursize)
return;
fail:
- Com_EPrintf( "Couldn't write local MVD: %s\n", Q_ErrorString( ret ) );
+ Com_EPrintf("Couldn't write local MVD: %s\n", Q_ErrorString(ret));
rec_stop();
}
@@ -2032,48 +2081,51 @@ rec_stop
Stops server local MVD recording.
==============
*/
-static void rec_stop( void ) {
+static void rec_stop(void)
+{
uint16_t msglen;
- if( !mvd.recording ) {
+ if (!mvd.recording) {
return;
}
-
+
// write demo EOF marker
msglen = 0;
- FS_Write( &msglen, 2, mvd.recording );
+ FS_Write(&msglen, 2, mvd.recording);
- FS_FCloseFile( mvd.recording );
+ FS_FCloseFile(mvd.recording);
mvd.recording = 0;
}
-static qboolean rec_allowed( void ) {
- if( !mvd.entities ) {
- Com_Printf( "MVD recording is disabled on this server.\n" );
+static qboolean rec_allowed(void)
+{
+ if (!mvd.entities) {
+ Com_Printf("MVD recording is disabled on this server.\n");
return qfalse;
}
- if( mvd.recording ) {
- Com_Printf( "Already recording a local MVD.\n" );
+ if (mvd.recording) {
+ Com_Printf("Already recording a local MVD.\n");
return qfalse;
}
return qtrue;
}
-static void rec_start( qhandle_t demofile ) {
+static void rec_start(qhandle_t demofile)
+{
uint32_t magic;
mvd.recording = demofile;
mvd.numlevels = 0;
mvd.numframes = 0;
mvd.clients_active = svs.realtime;
-
+
magic = MVD_MAGIC;
- FS_Write( &magic, 4, demofile );
+ FS_Write(&magic, 4, demofile);
- if( mvd.active ) {
+ if (mvd.active) {
emit_gamestate();
rec_write();
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
}
@@ -2085,23 +2137,24 @@ Begins server MVD recording.
Every entity, every playerinfo and every message will be recorded.
==============
*/
-void SV_MvdRecord_f( void ) {
+void SV_MvdRecord_f(void)
+{
char buffer[MAX_OSPATH];
qhandle_t f;
unsigned mode = FS_MODE_WRITE;
int c;
- if( sv.state != ss_game ) {
- Com_Printf( "No server running.\n" );
+ if (sv.state != ss_game) {
+ Com_Printf("No server running.\n");
return;
}
- while( ( c = Cmd_ParseOptions( o_record ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_record)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_record, "<filename>" );
- Com_Printf( "Begin local MVD recording.\n" );
- Cmd_PrintHelp( o_record );
+ Cmd_PrintUsage(o_record, "<filename>");
+ Com_Printf("Begin local MVD recording.\n");
+ Cmd_PrintHelp(o_record);
return;
case 'z':
mode |= FS_FLAG_GZIP;
@@ -2111,33 +2164,33 @@ void SV_MvdRecord_f( void ) {
}
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
- if( !rec_allowed() ) {
+ if (!rec_allowed()) {
return;
}
//
// open the demo file
//
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode,
- "demos/", cmd_optarg, ".mvd2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode,
+ "demos/", cmd_optarg, ".mvd2");
+ if (!f) {
return;
}
- if( !mvd_enable() ) {
- FS_FCloseFile( f );
+ if (!mvd_enable()) {
+ FS_FCloseFile(f);
return;
}
- Com_Printf( "Recording local MVD to %s\n", buffer );
+ Com_Printf("Recording local MVD to %s\n", buffer);
- rec_start( f );
+ rec_start(f);
}
@@ -2148,33 +2201,38 @@ SV_MvdStop_f
Ends server MVD recording
==============
*/
-void SV_MvdStop_f( void ) {
- if( !mvd.recording ) {
- Com_Printf( "Not recording a local MVD.\n" );
+void SV_MvdStop_f(void)
+{
+ if (!mvd.recording) {
+ Com_Printf("Not recording a local MVD.\n");
return;
}
- Com_Printf( "Stopped local MVD recording.\n" );
+ Com_Printf("Stopped local MVD recording.\n");
rec_stop();
}
-static void SV_MvdStuff_f( void ) {
- if( mvd.dummy ) {
- Cbuf_AddText( &dummy_buffer, Cmd_RawArgs() );
- Cbuf_AddText( &dummy_buffer, "\n" );
+static void SV_MvdStuff_f(void)
+{
+ if (mvd.dummy) {
+ Cbuf_AddText(&dummy_buffer, Cmd_RawArgs());
+ Cbuf_AddText(&dummy_buffer, "\n");
} else {
- Com_Printf( "Can't '%s', dummy MVD client is not active\n", Cmd_Argv( 0 ) );
+ Com_Printf("Can't '%s', dummy MVD client is not active\n", Cmd_Argv(0));
}
}
-static void SV_AddGtvHost_f( void ) {
- SV_AddMatch_f( &gtv_host_list );
+static void SV_AddGtvHost_f(void)
+{
+ SV_AddMatch_f(&gtv_host_list);
}
-static void SV_DelGtvHost_f( void ) {
- SV_DelMatch_f( &gtv_host_list );
+static void SV_DelGtvHost_f(void)
+{
+ SV_DelMatch_f(&gtv_host_list);
}
-static void SV_ListGtvHosts_f( void ) {
- SV_ListMatches_f( &gtv_host_list );
+static void SV_ListGtvHosts_f(void)
+{
+ SV_ListMatches_f(&gtv_host_list);
}
static const cmdreg_t c_svmvd[] = {
@@ -2186,27 +2244,28 @@ static const cmdreg_t c_svmvd[] = {
{ NULL }
};
-void SV_MvdRegister( void ) {
- sv_mvd_enable = Cvar_Get( "sv_mvd_enable", "0", CVAR_LATCH );
- sv_mvd_maxclients = Cvar_Get( "sv_mvd_maxclients", "8", CVAR_LATCH );
- sv_mvd_bufsize = Cvar_Get( "sv_mvd_bufsize", "2", CVAR_LATCH );
- sv_mvd_password = Cvar_Get( "sv_mvd_password", "", CVAR_PRIVATE );
- sv_mvd_maxsize = Cvar_Get( "sv_mvd_maxsize", "0", 0 );
- sv_mvd_maxtime = Cvar_Get( "sv_mvd_maxtime", "0", 0 );
- sv_mvd_maxmaps = Cvar_Get( "sv_mvd_maxmaps", "1", 0 );
- sv_mvd_noblend = Cvar_Get( "sv_mvd_noblend", "0", CVAR_LATCH );
- sv_mvd_nogun = Cvar_Get( "sv_mvd_nogun", "1", CVAR_LATCH );
- sv_mvd_nomsgs = Cvar_Get( "sv_mvd_nomsgs", "1", CVAR_LATCH );
- sv_mvd_begincmd = Cvar_Get( "sv_mvd_begincmd",
- "wait 50; putaway; wait 10; help;", 0 );
- sv_mvd_scorecmd = Cvar_Get( "sv_mvd_scorecmd",
- "putaway; wait 10; help;", 0 );
- sv_mvd_autorecord = Cvar_Get( "sv_mvd_autorecord", "0", CVAR_LATCH );
- sv_mvd_capture_flags = Cvar_Get( "sv_mvd_capture_flags", "5", 0 );
- sv_mvd_disconnect_time = Cvar_Get( "sv_mvd_disconnect_time", "15", 0 );
- sv_mvd_suspend_time = Cvar_Get( "sv_mvd_suspend_time", "5", 0 );
- sv_mvd_allow_stufftext = Cvar_Get( "sv_mvd_allow_stufftext", "0", CVAR_LATCH );
-
- Cmd_Register( c_svmvd );
+void SV_MvdRegister(void)
+{
+ sv_mvd_enable = Cvar_Get("sv_mvd_enable", "0", CVAR_LATCH);
+ sv_mvd_maxclients = Cvar_Get("sv_mvd_maxclients", "8", CVAR_LATCH);
+ sv_mvd_bufsize = Cvar_Get("sv_mvd_bufsize", "2", CVAR_LATCH);
+ sv_mvd_password = Cvar_Get("sv_mvd_password", "", CVAR_PRIVATE);
+ sv_mvd_maxsize = Cvar_Get("sv_mvd_maxsize", "0", 0);
+ sv_mvd_maxtime = Cvar_Get("sv_mvd_maxtime", "0", 0);
+ sv_mvd_maxmaps = Cvar_Get("sv_mvd_maxmaps", "1", 0);
+ sv_mvd_noblend = Cvar_Get("sv_mvd_noblend", "0", CVAR_LATCH);
+ sv_mvd_nogun = Cvar_Get("sv_mvd_nogun", "1", CVAR_LATCH);
+ sv_mvd_nomsgs = Cvar_Get("sv_mvd_nomsgs", "1", CVAR_LATCH);
+ sv_mvd_begincmd = Cvar_Get("sv_mvd_begincmd",
+ "wait 50; putaway; wait 10; help;", 0);
+ sv_mvd_scorecmd = Cvar_Get("sv_mvd_scorecmd",
+ "putaway; wait 10; help;", 0);
+ sv_mvd_autorecord = Cvar_Get("sv_mvd_autorecord", "0", CVAR_LATCH);
+ sv_mvd_capture_flags = Cvar_Get("sv_mvd_capture_flags", "5", 0);
+ sv_mvd_disconnect_time = Cvar_Get("sv_mvd_disconnect_time", "15", 0);
+ sv_mvd_suspend_time = Cvar_Get("sv_mvd_suspend_time", "5", 0);
+ sv_mvd_allow_stufftext = Cvar_Get("sv_mvd_allow_stufftext", "0", CVAR_LATCH);
+
+ Cmd_Register(c_svmvd);
}
diff --git a/src/sv_public.h b/src/sv_public.h
index 82b1307..9b54e0b 100644
--- a/src/sv_public.h
+++ b/src/sv_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,17 +28,17 @@ typedef enum {
} server_state_t;
#if USE_ICMP
-void SV_ErrorEvent( int info );
+void SV_ErrorEvent(int info);
#endif
-void SV_Init (void);
-void SV_Shutdown( const char *finalmsg, error_type_t type );
-unsigned SV_Frame (unsigned msec);
+void SV_Init(void);
+void SV_Shutdown(const char *finalmsg, error_type_t type);
+unsigned SV_Frame(unsigned msec);
#if USE_SYSCON
-void SV_SetConsoleTitle( void );
+void SV_SetConsoleTitle(void);
#endif
-//void SV_ConsoleOutput( const char *msg );
+//void SV_ConsoleOutput(const char *msg);
#if USE_MVD_CLIENT && USE_CLIENT
-int MVD_GetDemoPercent( qboolean *paused, int *framenum );
+int MVD_GetDemoPercent(qboolean *paused, int *framenum);
#endif
diff --git a/src/sv_save.c b/src/sv_save.c
index ba91721..e946fae 100644
--- a/src/sv_save.c
+++ b/src/sv_save.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -35,57 +35,59 @@ SAVEGAME FILES
===============================================================================
*/
-static qerror_t write_server_file( qboolean autosave ) {
+static qerror_t write_server_file(qboolean autosave)
+{
char name[MAX_OSPATH];
cvar_t *var;
size_t len;
qerror_t ret;
// write magic
- MSG_WriteLong( SAVE_MAGIC1 );
- MSG_WriteLong( SAVE_VERSION );
+ MSG_WriteLong(SAVE_MAGIC1);
+ MSG_WriteLong(SAVE_VERSION);
// write the comment field
- MSG_WriteByte( autosave );
- MSG_WriteString( sv.configstrings[CS_NAME] );
+ MSG_WriteByte(autosave);
+ MSG_WriteString(sv.configstrings[CS_NAME]);
// write the mapcmd
- MSG_WriteString( sv.name );
+ MSG_WriteString(sv.name);
// write all CVAR_LATCH cvars
// these will be things like coop, skill, deathmatch, etc
- for( var = cvar_vars; var; var = var->next ) {
+ for (var = cvar_vars; var; var = var->next) {
if (!(var->flags & CVAR_LATCH))
continue;
if (var->flags & CVAR_PRIVATE)
continue;
- MSG_WriteString( var->name );
- MSG_WriteString( var->string );
+ MSG_WriteString(var->name);
+ MSG_WriteString(var->string);
}
- MSG_WriteString( NULL );
+ MSG_WriteString(NULL);
// write server state
- ret = FS_WriteFile( "save/" SAVE_CURRENT "/server.state",
- msg_write.data, msg_write.cursize );
+ ret = FS_WriteFile("save/" SAVE_CURRENT "/server.state",
+ msg_write.data, msg_write.cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- if( ret < 0 ) {
+ if (ret < 0) {
return ret;
}
// write game state
- len = Q_snprintf( name, sizeof( name ),
- "%s/save/" SAVE_CURRENT "/game.state", fs_gamedir );
- if( len >= sizeof( name ) ) {
+ len = Q_snprintf(name, sizeof(name),
+ "%s/save/" SAVE_CURRENT "/game.state", fs_gamedir);
+ if (len >= sizeof(name)) {
return Q_ERR_NAMETOOLONG;
}
- ge->WriteGame (name, autosave);
+ ge->WriteGame(name, autosave);
return Q_ERR_SUCCESS;
}
-static qerror_t write_level_file( void ) {
+static qerror_t write_level_file(void)
+{
char name[MAX_OSPATH];
int i;
char *s;
@@ -94,130 +96,134 @@ static qerror_t write_level_file( void ) {
qerror_t ret;
// write magic
- MSG_WriteLong( SAVE_MAGIC2 );
- MSG_WriteLong( SAVE_VERSION );
+ MSG_WriteLong(SAVE_MAGIC2);
+ MSG_WriteLong(SAVE_VERSION);
// write configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
s = sv.configstrings[i];
- if( !s[0] ) {
+ if (!s[0]) {
continue;
}
- len = strlen( s );
- if( len > MAX_QPATH ) {
+ len = strlen(s);
+ if (len > MAX_QPATH) {
len = MAX_QPATH;
}
- MSG_WriteShort( i );
- MSG_WriteData( s, len );
- MSG_WriteByte( 0 );
+ MSG_WriteShort(i);
+ MSG_WriteData(s, len);
+ MSG_WriteByte(0);
}
- MSG_WriteShort( MAX_CONFIGSTRINGS );
+ MSG_WriteShort(MAX_CONFIGSTRINGS);
- len = CM_WritePortalBits( &sv.cm, portalbits );
- MSG_WriteByte( len );
- MSG_WriteData( portalbits, len );
+ len = CM_WritePortalBits(&sv.cm, portalbits);
+ MSG_WriteByte(len);
+ MSG_WriteData(portalbits, len);
- ret = FS_WriteFile( "save/" SAVE_CURRENT "/server.level",
- msg_write.data, msg_write.cursize );
+ ret = FS_WriteFile("save/" SAVE_CURRENT "/server.level",
+ msg_write.data, msg_write.cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
- if( ret < 0 ) {
+ if (ret < 0) {
return ret;
}
// write game level
- len = Q_snprintf( name, sizeof( name ),
- "%s/save/" SAVE_CURRENT "/game.level", fs_gamedir );
- if( len >= sizeof( name ) ) {
+ len = Q_snprintf(name, sizeof(name),
+ "%s/save/" SAVE_CURRENT "/game.level", fs_gamedir);
+ if (len >= sizeof(name)) {
return Q_ERR_NAMETOOLONG;
}
- ge->WriteLevel( name );
+ ge->WriteLevel(name);
return Q_ERR_SUCCESS;
}
-static qerror_t rename_file( const char *dir, const char *base, const char *suf ) {
+static qerror_t rename_file(const char *dir, const char *base, const char *suf)
+{
char from[MAX_QPATH];
char to[MAX_QPATH];
size_t len;
- len = Q_snprintf( from, sizeof( from ), "save/%s/%s%s", SAVE_CURRENT, base, suf );
- if( len >= sizeof( from ) )
+ len = Q_snprintf(from, sizeof(from), "save/%s/%s%s", SAVE_CURRENT, base, suf);
+ if (len >= sizeof(from))
return Q_ERR_NAMETOOLONG;
- len = Q_snprintf( to, sizeof( to ), "save/%s/%s%s", dir, base, suf );
- if( len >= sizeof( to ) )
+ len = Q_snprintf(to, sizeof(to), "save/%s/%s%s", dir, base, suf);
+ if (len >= sizeof(to))
return Q_ERR_NAMETOOLONG;
- return FS_RenameFile( from, to );
+ return FS_RenameFile(from, to);
}
-static qerror_t move_files( const char *dir ) {
+static qerror_t move_files(const char *dir)
+{
char name[MAX_OSPATH];
size_t len;
qerror_t ret;
- len = Q_snprintf( name, sizeof( name ), "%s/save/%s/", fs_gamedir, dir );
- if( len >= sizeof( name ) )
+ len = Q_snprintf(name, sizeof(name), "%s/save/%s/", fs_gamedir, dir);
+ if (len >= sizeof(name))
return Q_ERR_NAMETOOLONG;
- ret = FS_CreatePath( name );
- if( ret )
+ ret = FS_CreatePath(name);
+ if (ret)
return ret;
- ret = rename_file( dir, "game", ".level" );
- if( ret )
+ ret = rename_file(dir, "game", ".level");
+ if (ret)
return ret;
- ret = rename_file( dir, "server", ".level" );
- if( ret )
+ ret = rename_file(dir, "server", ".level");
+ if (ret)
return ret;
- ret = rename_file( dir, "game", ".state" );
- if( ret )
+ ret = rename_file(dir, "game", ".state");
+ if (ret)
return ret;
- ret = rename_file( dir, "server", ".state" );
- if( ret )
+ ret = rename_file(dir, "server", ".state");
+ if (ret)
return ret;
return Q_ERR_SUCCESS;
}
-static qerror_t read_binary_file( const char *name ) {
+static qerror_t read_binary_file(const char *name)
+{
qhandle_t f;
ssize_t len, read;
qerror_t ret;
- len = FS_FOpenFile( name, &f,
- FS_MODE_READ | FS_TYPE_REAL | FS_PATH_GAME );
- if( !f ) {
+ len = FS_FOpenFile(name, &f,
+ FS_MODE_READ | FS_TYPE_REAL | FS_PATH_GAME);
+ if (!f) {
return len;
}
- if( len > MAX_MSGLEN ) {
+ if (len > MAX_MSGLEN) {
ret = Q_ERR_FBIG;
goto fail;
}
- read = FS_Read( msg_read_buffer, len, f );
- if( read != len ) {
+ read = FS_Read(msg_read_buffer, len, f);
+ if (read != len) {
ret = read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
goto fail;
}
- SZ_Init( &msg_read, msg_read_buffer, len );
+ SZ_Init(&msg_read, msg_read_buffer, len);
msg_read.cursize = len;
ret = Q_ERR_SUCCESS;
fail:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return ret;
}
-static qerror_t read_server_file( const char *dir ) {
+static qerror_t read_server_file(const char *dir)
+{
char name[MAX_OSPATH], string[MAX_STRING_CHARS];
char mapcmd[MAX_QPATH];
char *s, *ch, *spawnpoint;
@@ -227,30 +233,30 @@ static qerror_t read_server_file( const char *dir ) {
// errors like missing file, bad version, etc are
// non-fatal and just return to the command handler
- len = Q_snprintf( name, MAX_QPATH, "save/%s/server.state", dir );
- if( len >= MAX_QPATH ) {
+ len = Q_snprintf(name, MAX_QPATH, "save/%s/server.state", dir);
+ if (len >= MAX_QPATH) {
return Q_ERR_NAMETOOLONG;
}
- ret = read_binary_file( name );
- if( ret ) {
+ ret = read_binary_file(name);
+ if (ret) {
return ret;
}
- if( MSG_ReadLong() != SAVE_MAGIC1 ) {
+ if (MSG_ReadLong() != SAVE_MAGIC1) {
return Q_ERR_UNKNOWN_FORMAT;
}
- if( MSG_ReadLong() != SAVE_VERSION ) {
+ if (MSG_ReadLong() != SAVE_VERSION) {
return Q_ERR_INVALID_FORMAT;
}
// read the comment field
MSG_ReadByte();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
// read the mapcmd
- len = MSG_ReadString( mapcmd, sizeof( mapcmd ) );
- if( len >= sizeof( mapcmd ) ) {
+ len = MSG_ReadString(mapcmd, sizeof(mapcmd));
+ if (len >= sizeof(mapcmd)) {
return Q_ERR_STRING_TRUNCATED;
}
@@ -258,19 +264,19 @@ static qerror_t read_server_file( const char *dir ) {
// if there is a + in the map, set nextserver to the remainder
// we go directly to nextserver as we don't support cinematics
- ch = strchr( s, '+' );
- if( ch ) {
+ ch = strchr(s, '+');
+ if (ch) {
s = ch + 1;
}
// skip the end-of-unit flag if necessary
- if( *s == '*' ) {
+ if (*s == '*') {
s++;
}
// if there is a $, use the remainder as a spawnpoint
- ch = strchr( s, '$' );
- if( ch ) {
+ ch = strchr(s, '$');
+ if (ch) {
*ch = 0;
spawnpoint = ch + 1;
} else {
@@ -278,89 +284,90 @@ static qerror_t read_server_file( const char *dir ) {
}
// now expand and try to load the map
- len = Q_concat( name, MAX_QPATH, "maps/", s, ".bsp", NULL );
- if( len >= MAX_QPATH ) {
+ len = Q_concat(name, MAX_QPATH, "maps/", s, ".bsp", NULL);
+ if (len >= MAX_QPATH) {
return Q_ERR_NAMETOOLONG;
}
- ret = CM_LoadMap( &cm, name );
- if( ret ) {
+ ret = CM_LoadMap(&cm, name);
+ if (ret) {
return ret;
}
// any error will drop from this point
- SV_Shutdown( "Server restarted\n", ERR_RECONNECT );
+ SV_Shutdown("Server restarted\n", ERR_RECONNECT);
// the rest can't underflow
msg_read.allowunderflow = qfalse;
// read all CVAR_LATCH cvars
// these will be things like coop, skill, deathmatch, etc
- while( 1 ) {
- len = MSG_ReadString( name, MAX_QPATH );
- if( !len )
+ while (1) {
+ len = MSG_ReadString(name, MAX_QPATH);
+ if (!len)
break;
- if( len >= MAX_QPATH ) {
+ if (len >= MAX_QPATH) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
- len = MSG_ReadString( string, sizeof( string ) );
- if( len >= sizeof( string ) ) {
+ len = MSG_ReadString(string, sizeof(string));
+ if (len >= sizeof(string)) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
- Cvar_UserSet( name, string );
+ Cvar_UserSet(name, string);
}
// start a new game fresh with new cvars
- SV_InitGame( MVD_SPAWN_DISABLED );
+ SV_InitGame(MVD_SPAWN_DISABLED);
// error out immediately if game doesn't support safe savegames
- if( !( g_features->integer & GMF_ENHANCED_SAVEGAMES ) ) {
- Com_Error( ERR_DROP, "Game does not support enhanced savegames" );
+ if (!(g_features->integer & GMF_ENHANCED_SAVEGAMES)) {
+ Com_Error(ERR_DROP, "Game does not support enhanced savegames");
}
// read game state
- len = Q_snprintf( name, sizeof( name ), "%s/save/%s/game.state", fs_gamedir, dir );
- if( len >= sizeof( name ) ) {
+ len = Q_snprintf(name, sizeof(name), "%s/save/%s/game.state", fs_gamedir, dir);
+ if (len >= sizeof(name)) {
ret = Q_ERR_NAMETOOLONG;
goto fail;
}
- ge->ReadGame (name);
+ ge->ReadGame(name);
// go to the map
- SV_SpawnServer( &cm, s, spawnpoint );
+ SV_SpawnServer(&cm, s, spawnpoint);
return Q_ERR_SUCCESS;
fail:
- Com_Error( ERR_DROP, "Couldn't load %s: %s", dir, Q_ErrorString( ret ) );
+ Com_Error(ERR_DROP, "Couldn't load %s: %s", dir, Q_ErrorString(ret));
}
-static void read_level_file( const char *dir ) {
+static void read_level_file(const char *dir)
+{
char name[MAX_OSPATH];
size_t len, maxlen;
qerror_t ret;
int index;
- len = Q_snprintf( name, MAX_QPATH, "save/%s/server.level", dir );
- if( len >= MAX_QPATH ) {
+ len = Q_snprintf(name, MAX_QPATH, "save/%s/server.level", dir);
+ if (len >= MAX_QPATH) {
ret = Q_ERR_NAMETOOLONG;
goto fail;
}
- ret = read_binary_file( name );
- if( ret ) {
+ ret = read_binary_file(name);
+ if (ret) {
goto fail;
}
- if( MSG_ReadLong() != SAVE_MAGIC2 ) {
+ if (MSG_ReadLong() != SAVE_MAGIC2) {
ret = Q_ERR_UNKNOWN_FORMAT;
goto fail;
}
- if( MSG_ReadLong() != SAVE_VERSION ) {
+ if (MSG_ReadLong() != SAVE_VERSION) {
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
@@ -368,49 +375,49 @@ static void read_level_file( const char *dir ) {
// the rest can't underflow
msg_read.allowunderflow = qfalse;
- while( 1 ) {
+ while (1) {
index = MSG_ReadShort();
- if( index == MAX_CONFIGSTRINGS ) {
+ if (index == MAX_CONFIGSTRINGS) {
break;
}
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
ret = Q_ERR_BAD_INDEX;
goto fail;
}
- maxlen = CS_SIZE( index );
- len = MSG_ReadString( sv.configstrings[index], maxlen );
- if( len >= maxlen ) {
+ maxlen = CS_SIZE(index);
+ len = MSG_ReadString(sv.configstrings[index], maxlen);
+ if (len >= maxlen) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
}
len = MSG_ReadByte();
- if( len > MAX_MAP_PORTAL_BYTES ) {
+ if (len > MAX_MAP_PORTAL_BYTES) {
ret = Q_ERR_INVALID_FORMAT;
goto fail;
}
SV_ClearWorld();
- CM_SetPortalStates( &sv.cm, MSG_ReadData( len ), len );
+ CM_SetPortalStates(&sv.cm, MSG_ReadData(len), len);
// read game level
- len = Q_snprintf( name, sizeof( name ), "%s/save/%s/game.level", fs_gamedir, dir );
- if( len >= sizeof( name ) ) {
+ len = Q_snprintf(name, sizeof(name), "%s/save/%s/game.level", fs_gamedir, dir);
+ if (len >= sizeof(name)) {
ret = Q_ERR_NAMETOOLONG;
goto fail;
}
- ge->ReadLevel( name );
+ ge->ReadLevel(name);
ge->RunFrame();
ge->RunFrame();
return;
fail:
- Com_Error( ERR_DROP, "Couldn't load %s: %s", dir, Q_ErrorString( ret ) );
+ Com_Error(ERR_DROP, "Couldn't load %s: %s", dir, Q_ErrorString(ret));
}
@@ -420,33 +427,34 @@ SV_Loadgame_f
==============
*/
-void SV_Loadgame_f (void) {
+void SV_Loadgame_f(void)
+{
char *dir;
qerror_t ret;
if (Cmd_Argc() != 2) {
- Com_Printf ("Usage: %s <directory>\n", Cmd_Argv(0));
+ Com_Printf("Usage: %s <directory>\n", Cmd_Argv(0));
return;
}
- if( dedicated->integer ) {
- Com_Printf ("Savegames are for listen servers only\n");
+ if (dedicated->integer) {
+ Com_Printf("Savegames are for listen servers only\n");
return;
}
dir = Cmd_Argv(1);
- if (!COM_IsPath(dir) ) {
- Com_Printf ("Bad savedir.\n");
+ if (!COM_IsPath(dir)) {
+ Com_Printf("Bad savedir.\n");
return;
}
- ret = read_server_file( dir );
- if( ret ) {
- Com_Printf( "Couldn't load %s: %s\n", dir, Q_ErrorString( ret ) );
+ ret = read_server_file(dir);
+ if (ret) {
+ Com_Printf("Couldn't load %s: %s\n", dir, Q_ErrorString(ret));
return;
}
- read_level_file( dir );
+ read_level_file(dir);
}
@@ -456,44 +464,45 @@ SV_Savegame_f
==============
*/
-void SV_Savegame_f( void ) {
+void SV_Savegame_f(void)
+{
char *dir;
qerror_t ret;
if (sv.state != ss_game) {
- Com_Printf ("You must be in a game to save.\n");
+ Com_Printf("You must be in a game to save.\n");
return;
}
- if( dedicated->integer ) {
- Com_Printf ("Savegames are for listen servers only\n");
+ if (dedicated->integer) {
+ Com_Printf("Savegames are for listen servers only\n");
return;
}
-
+
// don't bother saving if we can't read them back!
- if( !( g_features->integer & GMF_ENHANCED_SAVEGAMES ) ) {
- Com_Printf ("Game does not support enhanced savegames\n");
+ if (!(g_features->integer & GMF_ENHANCED_SAVEGAMES)) {
+ Com_Printf("Game does not support enhanced savegames\n");
return;
}
if (Cvar_VariableInteger("deathmatch")) {
- Com_Printf ("Can't savegame in a deathmatch\n");
+ Com_Printf("Can't savegame in a deathmatch\n");
return;
}
if (sv_maxclients->integer == 1 && svs.client_pool[0].edict->client->ps.stats[STAT_HEALTH] <= 0) {
- Com_Printf ("Can't savegame while dead!\n");
+ Com_Printf("Can't savegame while dead!\n");
return;
}
if (Cmd_Argc() != 2) {
- Com_Printf ("Usage: %s <directory>\n", Cmd_Argv(0));
+ Com_Printf("Usage: %s <directory>\n", Cmd_Argv(0));
return;
}
dir = Cmd_Argv(1);
- if (!COM_IsPath(dir) ) {
- Com_Printf ("Bad savedir.\n");
+ if (!COM_IsPath(dir)) {
+ Com_Printf("Bad savedir.\n");
return;
}
@@ -501,23 +510,23 @@ void SV_Savegame_f( void ) {
// when the level is reloaded, they will be shells awaiting
// a connecting client
ret = write_level_file();
- if( ret )
+ if (ret)
goto fail;
// save server state
- ret = write_server_file( qfalse );
- if( ret )
+ ret = write_server_file(qfalse);
+ if (ret)
goto fail;
// rename all stuff
- ret = move_files( dir );
- if( ret )
+ ret = move_files(dir);
+ if (ret)
goto fail;
- Com_Printf ("Game saved.\n");
+ Com_Printf("Game saved.\n");
return;
fail:
- Com_EPrintf( "Couldn't write %s: %s\n", dir, Q_ErrorString( ret ) );
+ Com_EPrintf("Couldn't write %s: %s\n", dir, Q_ErrorString(ret));
}
diff --git a/src/sv_send.c b/src/sv_send.c
index aeb4fb0..193e399 100644
--- a/src/sv_send.c
+++ b/src/sv_send.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -31,20 +31,21 @@ MISC
char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
-void SV_FlushRedirect( int redirected, char *outputbuf, size_t len ) {
+void SV_FlushRedirect(int redirected, char *outputbuf, size_t len)
+{
byte buffer[MAX_PACKETLEN_DEFAULT];
- if( redirected == RD_PACKET ) {
- memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
- memcpy( buffer + 10, outputbuf, len );
- NET_SendPacket( NS_SERVER, &net_from, len + 10, buffer );
- } else if( redirected == RD_CLIENT ) {
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteData( outputbuf, len );
- MSG_WriteByte( 0 );
+ if (redirected == RD_PACKET) {
+ memcpy(buffer, "\xff\xff\xff\xffprint\n", 10);
+ memcpy(buffer + 10, outputbuf, len);
+ NET_SendPacket(NS_SERVER, &net_from, len + 10, buffer);
+ } else if (redirected == RD_CLIENT) {
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteData(outputbuf, len);
+ MSG_WriteByte(0);
//Sys_Printf("redirect: %d bytes: %s", outputbuf);
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
}
@@ -56,17 +57,18 @@ Returns qtrue if the client is over its current
bandwidth estimation and should not be sent another packet
=======================
*/
-static qboolean SV_RateDrop( client_t *client ) {
+static qboolean SV_RateDrop(client_t *client)
+{
size_t total;
int i;
// never drop over the loopback
- if( !client->rate ) {
+ if (!client->rate) {
return qfalse;
}
total = 0;
- for( i = 0; i < RATE_MESSAGES; i++ ) {
+ for (i = 0; i < RATE_MESSAGES; i++) {
total += client->message_size[i];
}
@@ -74,9 +76,9 @@ static qboolean SV_RateDrop( client_t *client ) {
total = total * sv.framediv / client->framediv;
#endif
- if( total > client->rate ) {
- SV_DPrintf( 0, "Frame %d surpressed for %s (total = %"PRIz")\n",
- client->framenum, client->name, total );
+ if (total > client->rate) {
+ SV_DPrintf(0, "Frame %d surpressed for %s (total = %"PRIz")\n",
+ client->framenum, client->name, total);
client->frameflags |= FF_SURPRESSED;
client->surpressCount++;
client->message_size[client->framenum % RATE_MESSAGES] = 0;
@@ -86,15 +88,16 @@ static qboolean SV_RateDrop( client_t *client ) {
return qfalse;
}
-static void SV_CalcSendTime( client_t *client, size_t size ) {
+static void SV_CalcSendTime(client_t *client, size_t size)
+{
// never drop over the loopback
- if( !client->rate ) {
+ if (!client->rate) {
client->send_time = svs.realtime;
client->send_delta = 0;
return;
}
- if( client->state == cs_spawned )
+ if (client->state == cs_spawned)
client->message_size[client->framenum % RATE_MESSAGES] = size;
client->send_time = svs.realtime;
@@ -118,28 +121,29 @@ Sends text across to be displayed if the level passes.
NOT archived in MVD stream.
=================
*/
-void SV_ClientPrintf( client_t *client, int level, const char *fmt, ... ) {
+void SV_ClientPrintf(client_t *client, int level, const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
size_t len;
-
- if( level < client->messagelevel )
+
+ if (level < client->messagelevel)
return;
-
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
+
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_print );
- MSG_WriteByte( level );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(level);
+ MSG_WriteData(string, len + 1);
- SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(client, MSG_RELIABLE | MSG_CLEAR);
}
/*
@@ -150,54 +154,56 @@ Sends text to all active clients.
NOT archived in MVD stream.
=================
*/
-void SV_BroadcastPrintf( int level, const char *fmt, ... ) {
+void SV_BroadcastPrintf(int level, const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
size_t len;
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_print );
- MSG_WriteByte( level );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(level);
+ MSG_WriteData(string, len + 1);
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_spawned )
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_spawned)
continue;
- if( level < client->messagelevel )
+ if (level < client->messagelevel)
continue;
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
-void SV_ClientCommand( client_t *client, const char *fmt, ... ) {
+void SV_ClientCommand(client_t *client, const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
size_t len;
-
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
+
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_stufftext );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteData(string, len + 1);
- SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(client, MSG_RELIABLE | MSG_CLEAR);
}
/*
@@ -208,29 +214,30 @@ Sends command to all active clients.
NOT archived in MVD stream.
=================
*/
-void SV_BroadcastCommand( const char *fmt, ... ) {
+void SV_BroadcastCommand(const char *fmt, ...)
+{
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
size_t len;
-
- va_start( argptr, fmt );
- len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
- va_end( argptr );
- if( len >= sizeof( string ) ) {
- Com_WPrintf( "%s: overflow\n", __func__ );
+ va_start(argptr, fmt);
+ len = Q_vsnprintf(string, sizeof(string), fmt, argptr);
+ va_end(argptr);
+
+ if (len >= sizeof(string)) {
+ Com_WPrintf("%s: overflow\n", __func__);
return;
}
- MSG_WriteByte( svc_stufftext );
- MSG_WriteData( string, len + 1 );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteData(string, len + 1);
- FOR_EACH_CLIENT( client ) {
- SV_ClientAddMessage( client, MSG_RELIABLE );
+ FOR_EACH_CLIENT(client) {
+ SV_ClientAddMessage(client, MSG_RELIABLE);
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
@@ -248,7 +255,8 @@ MULTICAST_PVS send to clients potentially visible from org
MULTICAST_PHS send to clients potentially hearable from org
=================
*/
-void SV_Multicast( vec3_t origin, multicast_t to ) {
+void SV_Multicast(vec3_t origin, multicast_t to)
+{
client_t *client;
byte mask[VIS_MAX_BYTES];
mleaf_t *leaf1, *leaf2;
@@ -258,9 +266,9 @@ void SV_Multicast( vec3_t origin, multicast_t to ) {
flags = 0;
- switch( to ) {
+ switch (to) {
case MULTICAST_ALL_R:
- flags |= MSG_RELIABLE;
+ flags |= MSG_RELIABLE;
// intentional fallthrough
case MULTICAST_ALL:
leaf1 = NULL;
@@ -270,63 +278,62 @@ void SV_Multicast( vec3_t origin, multicast_t to ) {
flags |= MSG_RELIABLE;
// intentional fallthrough
case MULTICAST_PHS:
- leaf1 = CM_PointLeaf( &sv.cm, origin );
+ leaf1 = CM_PointLeaf(&sv.cm, origin);
leafnum = leaf1 - sv.cm.cache->leafs;
- BSP_ClusterVis( sv.cm.cache, mask, leaf1->cluster, DVIS_PHS );
+ BSP_ClusterVis(sv.cm.cache, mask, leaf1->cluster, DVIS_PHS);
break;
case MULTICAST_PVS_R:
flags |= MSG_RELIABLE;
// intentional fallthrough
case MULTICAST_PVS:
- leaf1 = CM_PointLeaf( &sv.cm, origin );
+ leaf1 = CM_PointLeaf(&sv.cm, origin);
leafnum = leaf1 - sv.cm.cache->leafs;
- BSP_ClusterVis( sv.cm.cache, mask, leaf1->cluster, DVIS_PVS );
+ BSP_ClusterVis(sv.cm.cache, mask, leaf1->cluster, DVIS_PVS);
break;
default:
- Com_Error( ERR_DROP, "SV_Multicast: bad to: %i", to );
+ Com_Error(ERR_DROP, "SV_Multicast: bad to: %i", to);
}
// send the data to all relevent clients
- FOR_EACH_CLIENT( client ) {
- if( client->state < cs_primed ) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state < cs_primed) {
continue;
}
// do not send unreliables to connecting clients
- if( !( flags & MSG_RELIABLE ) && ( client->state != cs_spawned ||
- client->download || client->nodata ) )
- {
- continue;
+ if (!(flags & MSG_RELIABLE) && (client->state != cs_spawned ||
+ client->download || client->nodata)) {
+ continue;
}
- if( leaf1 ) {
+ if (leaf1) {
// find the client's PVS
#if 0
player_state_t *ps = &client->edict->client->ps;
- VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, org );
+ VectorMA(ps->viewoffset, 0.125f, ps->pmove.origin, org);
#else
// FIXME: for some strange reason, game code assumes the server
// uses entity origin for PVS/PHS culling, not the view origin
- VectorCopy( client->edict->s.origin, org );
+ VectorCopy(client->edict->s.origin, org);
#endif
- leaf2 = CM_PointLeaf( &sv.cm, org );
- if( !CM_AreasConnected( &sv.cm, leaf1->area, leaf2->area ) )
+ leaf2 = CM_PointLeaf(&sv.cm, org);
+ if (!CM_AreasConnected(&sv.cm, leaf1->area, leaf2->area))
continue;
- if( leaf2->cluster == -1 )
+ if (leaf2->cluster == -1)
continue;
- if( !Q_IsBitSet( mask, leaf2->cluster ) )
+ if (!Q_IsBitSet(mask, leaf2->cluster))
continue;
}
- SV_ClientAddMessage( client, flags );
+ SV_ClientAddMessage(client, flags);
}
#if USE_MVD_SERVER
// add to MVD datagram
- SV_MvdMulticast( leafnum, to );
+ SV_MvdMulticast(leafnum, to);
#endif
- // clear the buffer
- SZ_Clear( &msg_write );
+ // clear the buffer
+ SZ_Clear(&msg_write);
}
@@ -340,21 +347,20 @@ Does NOT clean the buffer for multicast delivery purpose,
unless told otherwise.
=======================
*/
-void SV_ClientAddMessage( client_t *client, int flags ) {
- SV_DPrintf( 1, "Added %sreliable message to %s: %"PRIz" bytes\n",
- ( flags & MSG_RELIABLE ) ? "" : "un", client->name, msg_write.cursize );
+void SV_ClientAddMessage(client_t *client, int flags)
+{
+ SV_DPrintf(1, "Added %sreliable message to %s: %"PRIz" bytes\n",
+ (flags & MSG_RELIABLE) ? "" : "un", client->name, msg_write.cursize);
- if( !msg_write.cursize ) {
+ if (!msg_write.cursize) {
return;
}
-// if( client->state > cs_zombie ) {
- client->AddMessage( client, msg_write.data, msg_write.cursize,
- ( flags & MSG_RELIABLE ) ? qtrue : qfalse );
- // }
+ client->AddMessage(client, msg_write.data, msg_write.cursize,
+ (flags & MSG_RELIABLE) ? qtrue : qfalse);
- if( flags & MSG_CLEAR ) {
- SZ_Clear( &msg_write );
+ if (flags & MSG_CLEAR) {
+ SZ_Clear(&msg_write);
}
}
@@ -366,99 +372,102 @@ FRAME UPDATES - COMMON
===============================================================================
*/
-static inline void free_msg_packet( client_t *client, message_packet_t *msg ) {
- List_Remove( &msg->entry );
+static inline void free_msg_packet(client_t *client, message_packet_t *msg)
+{
+ List_Remove(&msg->entry);
- if( msg->cursize > MSG_TRESHOLD ) {
- if( msg->cursize > client->msg_dynamic_bytes ) {
- Com_Error( ERR_FATAL, "%s: bad packet size", __func__ );
+ if (msg->cursize > MSG_TRESHOLD) {
+ if (msg->cursize > client->msg_dynamic_bytes) {
+ Com_Error(ERR_FATAL, "%s: bad packet size", __func__);
}
client->msg_dynamic_bytes -= msg->cursize;
- Z_Free( msg );
+ Z_Free(msg);
} else {
- List_Insert( &client->msg_free_list, &msg->entry );
+ List_Insert(&client->msg_free_list, &msg->entry);
}
}
-#define FOR_EACH_MSG_SAFE( list ) \
- LIST_FOR_EACH_SAFE( message_packet_t, msg, next, list, entry )
-#define MSG_FIRST( list ) \
- LIST_FIRST( message_packet_t, list, entry )
+#define FOR_EACH_MSG_SAFE(list) \
+ LIST_FOR_EACH_SAFE(message_packet_t, msg, next, list, entry)
+#define MSG_FIRST(list) \
+ LIST_FIRST(message_packet_t, list, entry)
-static void free_all_messages( client_t *client ) {
+static void free_all_messages(client_t *client)
+{
message_packet_t *msg, *next;
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- free_msg_packet( client, msg );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ free_msg_packet(client, msg);
}
- FOR_EACH_MSG_SAFE( &client->msg_reliable_list ) {
- free_msg_packet( client, msg );
+ FOR_EACH_MSG_SAFE(&client->msg_reliable_list) {
+ free_msg_packet(client, msg);
}
client->msg_unreliable_bytes = 0;
client->msg_dynamic_bytes = 0;
}
-static void add_msg_packet( client_t *client,
- byte *data,
- size_t len,
- qboolean reliable )
+static void add_msg_packet(client_t *client,
+ byte *data,
+ size_t len,
+ qboolean reliable)
{
message_packet_t *msg;
- if( !client->msg_pool ) {
+ if (!client->msg_pool) {
return; // already dropped
}
- if( len > MSG_TRESHOLD ) {
- if( len > MAX_MSGLEN ) {
- Com_Error( ERR_FATAL, "%s: oversize packet", __func__ );
+ if (len > MSG_TRESHOLD) {
+ if (len > MAX_MSGLEN) {
+ Com_Error(ERR_FATAL, "%s: oversize packet", __func__);
}
- if( client->msg_dynamic_bytes + len > MAX_MSGLEN ) {
- Com_WPrintf( "%s: %s: out of dynamic memory\n",
- __func__, client->name );
+ if (client->msg_dynamic_bytes + len > MAX_MSGLEN) {
+ Com_WPrintf("%s: %s: out of dynamic memory\n",
+ __func__, client->name);
goto overflowed;
}
- msg = SV_Malloc( sizeof( *msg ) + len - MSG_TRESHOLD );
+ msg = SV_Malloc(sizeof(*msg) + len - MSG_TRESHOLD);
client->msg_dynamic_bytes += len;
} else {
- if( LIST_EMPTY( &client->msg_free_list ) ) {
- Com_WPrintf( "%s: %s: out of message slots\n",
- __func__, client->name );
+ if (LIST_EMPTY(&client->msg_free_list)) {
+ Com_WPrintf("%s: %s: out of message slots\n",
+ __func__, client->name);
goto overflowed;
}
- msg = MSG_FIRST( &client->msg_free_list );
- List_Remove( &msg->entry );
+ msg = MSG_FIRST(&client->msg_free_list);
+ List_Remove(&msg->entry);
}
- memcpy( msg->data, data, len );
- msg->cursize = ( uint16_t )len;
+ memcpy(msg->data, data, len);
+ msg->cursize = (uint16_t)len;
- if( reliable ) {
- List_Append( &client->msg_reliable_list, &msg->entry );
+ if (reliable) {
+ List_Append(&client->msg_reliable_list, &msg->entry);
} else {
- List_Append( &client->msg_unreliable_list, &msg->entry );
+ List_Append(&client->msg_unreliable_list, &msg->entry);
client->msg_unreliable_bytes += len;
}
return;
overflowed:
- if( reliable ) {
- free_all_messages( client );
- SV_DropClient( client, "reliable queue overflowed" );
+ if (reliable) {
+ free_all_messages(client);
+ SV_DropClient(client, "reliable queue overflowed");
}
}
// check if this entity is present in current client frame
-static qboolean check_entity( client_t *client, int entnum ) {
+static qboolean check_entity(client_t *client, int entnum)
+{
client_frame_t *frame;
unsigned i, j;
frame = &client->frames[client->framenum & UPDATE_MASK];
- for( i = 0; i < frame->num_entities; i++ ) {
- j = ( frame->first_entity + i ) % svs.num_entities;
- if( svs.entities[j].number == entnum ) {
+ for (i = 0; i < frame->num_entities; i++) {
+ j = (frame->first_entity + i) % svs.num_entities;
+ if (svs.entities[j].number == entnum) {
return qtrue;
}
}
@@ -467,7 +476,8 @@ static qboolean check_entity( client_t *client, int entnum ) {
}
// sounds reliative to entities are handled specially
-static void emit_snd( client_t *client, message_packet_t *msg ) {
+static void emit_snd(client_t *client, message_packet_t *msg)
+{
int flags, entnum;
int i;
@@ -475,57 +485,60 @@ static void emit_snd( client_t *client, message_packet_t *msg ) {
flags = msg->flags;
// check if position needs to be explicitly sent
- if( !( flags & SND_POS ) && !check_entity( client, entnum ) ) {
- SV_DPrintf( 0, "Forcing position on entity %d for %s\n",
- entnum, client->name );
+ if (!(flags & SND_POS) && !check_entity(client, entnum)) {
+ SV_DPrintf(0, "Forcing position on entity %d for %s\n",
+ entnum, client->name);
flags |= SND_POS; // entity is not present in frame
}
- MSG_WriteByte( svc_sound );
- MSG_WriteByte( flags );
- MSG_WriteByte( msg->index );
+ MSG_WriteByte(svc_sound);
+ MSG_WriteByte(flags);
+ MSG_WriteByte(msg->index);
- if( flags & SND_VOLUME )
- MSG_WriteByte( msg->volume );
- if( flags & SND_ATTENUATION )
- MSG_WriteByte( msg->attenuation );
- if( flags & SND_OFFSET )
- MSG_WriteByte( msg->timeofs );
+ if (flags & SND_VOLUME)
+ MSG_WriteByte(msg->volume);
+ if (flags & SND_ATTENUATION)
+ MSG_WriteByte(msg->attenuation);
+ if (flags & SND_OFFSET)
+ MSG_WriteByte(msg->timeofs);
- MSG_WriteShort( msg->sendchan );
+ MSG_WriteShort(msg->sendchan);
- if( flags & SND_POS ) {
- for( i = 0; i < 3; i++ ) {
- MSG_WriteShort( msg->pos[i] );
+ if (flags & SND_POS) {
+ for (i = 0; i < 3; i++) {
+ MSG_WriteShort(msg->pos[i]);
}
}
}
-static inline void write_snd( client_t *client, message_packet_t *msg, size_t maxsize ) {
+static inline void write_snd(client_t *client, message_packet_t *msg, size_t maxsize)
+{
// if this msg fits, write it
- if( msg_write.cursize + MAX_SOUND_PACKET <= maxsize ) {
- emit_snd( client, msg );
+ if (msg_write.cursize + MAX_SOUND_PACKET <= maxsize) {
+ emit_snd(client, msg);
}
- List_Remove( &msg->entry );
- List_Insert( &client->msg_free_list, &msg->entry );
+ List_Remove(&msg->entry);
+ List_Insert(&client->msg_free_list, &msg->entry);
}
-static inline void write_msg( client_t *client, message_packet_t *msg, size_t maxsize ) {
+static inline void write_msg(client_t *client, message_packet_t *msg, size_t maxsize)
+{
// if this msg fits, write it
- if( msg_write.cursize + msg->cursize <= maxsize ) {
- MSG_WriteData( msg->data, msg->cursize );
+ if (msg_write.cursize + msg->cursize <= maxsize) {
+ MSG_WriteData(msg->data, msg->cursize);
}
- free_msg_packet( client, msg );
+ free_msg_packet(client, msg);
}
-static inline void write_unreliables( client_t *client, size_t maxsize ) {
+static inline void write_unreliables(client_t *client, size_t maxsize)
+{
message_packet_t *msg, *next;
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- if( msg->cursize ) {
- write_msg( client, msg, maxsize );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ if (msg->cursize) {
+ write_msg(client, msg, maxsize);
} else {
- write_snd( client, msg, maxsize );
+ write_snd(client, msg, maxsize);
}
}
}
@@ -538,159 +551,161 @@ FRAME UPDATES - OLD NETCHAN
===============================================================================
*/
-static void add_message_old( client_t *client, byte *data,
- size_t len, qboolean reliable )
+static void add_message_old(client_t *client, byte *data,
+ size_t len, qboolean reliable)
{
- if( len > client->netchan->maxpacketlen ) {
- if( reliable ) {
- SV_DropClient( client, "oversize reliable message" );
+ if (len > client->netchan->maxpacketlen) {
+ if (reliable) {
+ SV_DropClient(client, "oversize reliable message");
} else {
- Com_DPrintf( "Dumped oversize unreliable for %s\n", client->name );
+ Com_DPrintf("Dumped oversize unreliable for %s\n", client->name);
}
return;
}
- add_msg_packet( client, data, len, reliable );
+ add_msg_packet(client, data, len, reliable);
}
// this should be the only place data is ever written to netchan message for old clients
-static void write_reliables_old( client_t *client, size_t maxsize ) {
+static void write_reliables_old(client_t *client, size_t maxsize)
+{
message_packet_t *msg, *next;
int count;
- if( client->netchan->reliable_length ) {
- SV_DPrintf( 1, "%s to %s: unacked\n", __func__, client->name );
+ if (client->netchan->reliable_length) {
+ SV_DPrintf(1, "%s to %s: unacked\n", __func__, client->name);
return; // there is still outgoing reliable message pending
}
// find at least one reliable message to send
count = 0;
- FOR_EACH_MSG_SAFE( &client->msg_reliable_list ) {
+ FOR_EACH_MSG_SAFE(&client->msg_reliable_list) {
// stop if this msg doesn't fit (reliables must be delivered in order)
- if( client->netchan->message.cursize + msg->cursize > maxsize ) {
- if( !count ) {
+ if (client->netchan->message.cursize + msg->cursize > maxsize) {
+ if (!count) {
// this should never happen
- Com_WPrintf( "%s to %s: overflow on the first message\n",
- __func__, client->name );
+ Com_WPrintf("%s to %s: overflow on the first message\n",
+ __func__, client->name);
}
break;
}
- SV_DPrintf( 1, "%s to %s: writing msg %d: %d bytes\n",
- __func__, client->name, count, msg->cursize );
+ SV_DPrintf(1, "%s to %s: writing msg %d: %d bytes\n",
+ __func__, client->name, count, msg->cursize);
- SZ_Write( &client->netchan->message, msg->data, msg->cursize );
- free_msg_packet( client, msg );
+ SZ_Write(&client->netchan->message, msg->data, msg->cursize);
+ free_msg_packet(client, msg);
count++;
}
}
// unreliable portion doesn't fit, then throw out low priority effects
-static void repack_unreliables( client_t *client, size_t maxsize ) {
+static void repack_unreliables(client_t *client, size_t maxsize)
+{
message_packet_t *msg, *next;
- if( msg_write.cursize + 4 > maxsize ) {
+ if (msg_write.cursize + 4 > maxsize) {
return;
}
// temp entities first
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- if( !msg->cursize || msg->data[0] != svc_temp_entity ) {
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ if (!msg->cursize || msg->data[0] != svc_temp_entity) {
continue;
}
// ignore some low-priority effects, these checks come from r1q2
- if( msg->data[1] == TE_BLOOD || msg->data[1] == TE_SPLASH ||
+ if (msg->data[1] == TE_BLOOD || msg->data[1] == TE_SPLASH ||
msg->data[1] == TE_GUNSHOT || msg->data[1] == TE_BULLET_SPARKS ||
- msg->data[1] == TE_SHOTGUN )
- {
+ msg->data[1] == TE_SHOTGUN) {
continue;
}
- write_msg( client, msg, maxsize );
+ write_msg(client, msg, maxsize);
}
- if( msg_write.cursize + 4 > maxsize ) {
+ if (msg_write.cursize + 4 > maxsize) {
return;
}
// then entity sounds
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- if( !msg->cursize ) {
- write_snd( client, msg, maxsize );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ if (!msg->cursize) {
+ write_snd(client, msg, maxsize);
}
}
- if( msg_write.cursize + 4 > maxsize ) {
+ if (msg_write.cursize + 4 > maxsize) {
return;
}
// then positioned sounds
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- if( msg->cursize && msg->data[0] == svc_sound ) {
- write_msg( client, msg, maxsize );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ if (msg->cursize && msg->data[0] == svc_sound) {
+ write_msg(client, msg, maxsize);
}
}
- if( msg_write.cursize + 4 > maxsize ) {
+ if (msg_write.cursize + 4 > maxsize) {
return;
}
// then everything else left
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- if( msg->cursize ) {
- write_msg( client, msg, maxsize );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ if (msg->cursize) {
+ write_msg(client, msg, maxsize);
}
}
}
-static void write_datagram_old( client_t *client ) {
+static void write_datagram_old(client_t *client)
+{
message_packet_t *msg;
size_t maxsize, cursize;
// determine how much space is left for unreliable data
maxsize = client->netchan->maxpacketlen;
- if( client->netchan->reliable_length ) {
+ if (client->netchan->reliable_length) {
// there is still unacked reliable message pending
maxsize -= client->netchan->reliable_length;
} else {
// find at least one reliable message to send
// and make sure to reserve space for it
- if( !LIST_EMPTY( &client->msg_reliable_list ) ) {
- msg = MSG_FIRST( &client->msg_reliable_list );
+ if (!LIST_EMPTY(&client->msg_reliable_list)) {
+ msg = MSG_FIRST(&client->msg_reliable_list);
maxsize -= msg->cursize;
}
}
// send over all the relevant entity_state_t
// and the player_state_t
- client->WriteFrame( client );
- if( msg_write.cursize > maxsize ) {
- SV_DPrintf( 0, "Frame %d overflowed for %s: %"PRIz" > %"PRIz"\n",
- client->framenum, client->name, msg_write.cursize, maxsize );
- SZ_Clear( &msg_write );
+ client->WriteFrame(client);
+ if (msg_write.cursize > maxsize) {
+ SV_DPrintf(0, "Frame %d overflowed for %s: %"PRIz" > %"PRIz"\n",
+ client->framenum, client->name, msg_write.cursize, maxsize);
+ SZ_Clear(&msg_write);
}
// now write unreliable messages
// it is necessary for this to be after the WriteFrame
// so that entity references will be current
- if( msg_write.cursize + client->msg_unreliable_bytes > maxsize ) {
+ if (msg_write.cursize + client->msg_unreliable_bytes > maxsize) {
// throw out some low priority effects
- repack_unreliables( client, maxsize );
+ repack_unreliables(client, maxsize);
} else {
// all messages fit, write them in order
- write_unreliables( client, maxsize );
+ write_unreliables(client, maxsize);
}
// write at least one reliable message
- write_reliables_old( client, client->netchan->maxpacketlen - msg_write.cursize );
+ write_reliables_old(client, client->netchan->maxpacketlen - msg_write.cursize);
// send the datagram
- cursize = client->netchan->Transmit( client->netchan,
- msg_write.cursize, msg_write.data, client->numpackets );
+ cursize = client->netchan->Transmit(client->netchan,
+ msg_write.cursize, msg_write.data, client->numpackets);
// record the size for rate estimation
- SV_CalcSendTime( client, cursize );
+ SV_CalcSendTime(client, cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
/*
@@ -701,63 +716,64 @@ FRAME UPDATES - NEW NETCHAN
===============================================================================
*/
-static void add_message_new( client_t *client, byte *data,
- size_t len, qboolean reliable )
+static void add_message_new(client_t *client, byte *data,
+ size_t len, qboolean reliable)
{
- if( reliable ) {
+ if (reliable) {
// don't packetize, netchan level will do fragmentation as needed
- SZ_Write( &client->netchan->message, data, len );
+ SZ_Write(&client->netchan->message, data, len);
} else {
// still have to packetize, relative sounds need special processing
- add_msg_packet( client, data, len, qfalse );
+ add_msg_packet(client, data, len, qfalse);
}
}
-static void write_datagram_new( client_t *client ) {
+static void write_datagram_new(client_t *client)
+{
size_t cursize;
// send over all the relevant entity_state_t
// and the player_state_t
- client->WriteFrame( client );
+ client->WriteFrame(client);
- if( msg_write.overflowed ) {
+ if (msg_write.overflowed) {
// should never really happen
- Com_WPrintf( "Frame overflowed for %s\n", client->name );
- SZ_Clear( &msg_write );
+ Com_WPrintf("Frame overflowed for %s\n", client->name);
+ SZ_Clear(&msg_write);
}
// now write unreliable messages
// for this client out to the message
// it is necessary for this to be after the WriteFrame
// so that entity references will be current
- if( msg_write.cursize + client->msg_unreliable_bytes > msg_write.maxsize ) {
- Com_WPrintf( "Dumping datagram for %s\n", client->name );
+ if (msg_write.cursize + client->msg_unreliable_bytes > msg_write.maxsize) {
+ Com_WPrintf("Dumping datagram for %s\n", client->name);
} else {
- write_unreliables( client, msg_write.maxsize );
+ write_unreliables(client, msg_write.maxsize);
}
#ifdef _DEBUG
- if( sv_pad_packets->integer ) {
+ if (sv_pad_packets->integer) {
size_t pad = msg_write.cursize + sv_pad_packets->integer;
- if( pad > msg_write.maxsize ) {
+ if (pad > msg_write.maxsize) {
pad = msg_write.maxsize;
}
- for( ; pad > 0; pad-- ) {
- MSG_WriteByte( svc_nop );
+ for (; pad > 0; pad--) {
+ MSG_WriteByte(svc_nop);
}
}
#endif
// send the datagram
- cursize = client->netchan->Transmit( client->netchan,
- msg_write.cursize, msg_write.data, client->numpackets );
+ cursize = client->netchan->Transmit(client->netchan,
+ msg_write.cursize, msg_write.data, client->numpackets);
// record the size for rate estimation
- SV_CalcSendTime( client, cursize );
+ SV_CalcSendTime(client, cursize);
// clear the write buffer
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
@@ -769,25 +785,27 @@ COMMON STUFF
===============================================================================
*/
-static void finish_frame( client_t *client ) {
+static void finish_frame(client_t *client)
+{
message_packet_t *msg, *next;
- FOR_EACH_MSG_SAFE( &client->msg_unreliable_list ) {
- free_msg_packet( client, msg );
+ FOR_EACH_MSG_SAFE(&client->msg_unreliable_list) {
+ free_msg_packet(client, msg);
}
client->msg_unreliable_bytes = 0;
}
#if (defined _DEBUG) && USE_FPS
-static void check_key_sync( client_t *client ) {
+static void check_key_sync(client_t *client)
+{
int div = sv.framediv / client->framediv;
- int key1 = !( sv.framenum % sv.framediv );
- int key2 = !( client->framenum % div );
+ int key1 = !(sv.framenum % sv.framediv);
+ int key2 = !(client->framenum % div);
- if( key1 != key2 ) {
- Com_LPrintf( PRINT_DEVELOPER,
- "[%d] frame %d for %s not synced (%d != %d)\n",
- sv.framenum, client->framenum, client->name, key1, key2 );
+ if (key1 != key2) {
+ Com_LPrintf(PRINT_DEVELOPER,
+ "[%d] frame %d for %s not synced (%d != %d)\n",
+ sv.framenum, client->framenum, client->name, key1, key2);
}
}
#endif
@@ -800,46 +818,47 @@ Called each game frame, sends svc_frame messages to spawned clients only.
Clients in earlier connection state are handled in SV_SendAsyncPackets.
=======================
*/
-void SV_SendClientMessages( void ) {
+void SV_SendClientMessages(void)
+{
client_t *client;
size_t cursize;
// send a message to each connected client
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_spawned || client->download || client->nodata )
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_spawned || client->download || client->nodata)
goto finish;
- if( !SV_CLIENTSYNC( client ) )
+ if (!SV_CLIENTSYNC(client))
continue;
#if (defined _DEBUG) && USE_FPS
- if( developer->integer )
- check_key_sync( client );
+ if (developer->integer)
+ check_key_sync(client);
#endif
// if the reliable message overflowed,
// drop the client (should never happen)
- if( client->netchan->message.overflowed ) {
- SZ_Clear( &client->netchan->message );
- SV_DropClient( client, "reliable message overflowed" );
+ if (client->netchan->message.overflowed) {
+ SZ_Clear(&client->netchan->message);
+ SV_DropClient(client, "reliable message overflowed");
goto finish;
}
// don't overrun bandwidth
- if( SV_RateDrop( client ) )
+ if (SV_RateDrop(client))
goto advance;
// don't write any frame data until all fragments are sent
- if( client->netchan->fragment_pending ) {
+ if (client->netchan->fragment_pending) {
client->frameflags |= FF_SURPRESSED;
- cursize = client->netchan->TransmitNextFragment( client->netchan );
- SV_CalcSendTime( client, cursize );
+ cursize = client->netchan->TransmitNextFragment(client->netchan);
+ SV_CalcSendTime(client, cursize);
goto advance;
}
// build the new frame and write it
- SV_BuildClientFrame( client );
- client->WriteDatagram( client );
+ SV_BuildClientFrame(client);
+ client->WriteDatagram(client);
advance:
// advance for next frame
@@ -847,7 +866,7 @@ advance:
finish:
// clear all unreliable messages still left
- finish_frame( client );
+ finish_frame(client);
}
}
@@ -863,69 +882,70 @@ For spawned clients, this is not used, as we are forced to send svc_frame
packets synchronously with game DLL ticks.
==================
*/
-void SV_SendAsyncPackets( void ) {
+void SV_SendAsyncPackets(void)
+{
qboolean retransmit;
client_t *client;
netchan_t *netchan;
size_t cursize;
-
- FOR_EACH_CLIENT( client ) {
+
+ FOR_EACH_CLIENT(client) {
// don't overrun bandwidth
- if( svs.realtime - client->send_time < client->send_delta ) {
+ if (svs.realtime - client->send_time < client->send_delta) {
continue;
}
netchan = client->netchan;
-
+
// make sure all fragments are transmitted first
- if( netchan->fragment_pending ) {
- cursize = netchan->TransmitNextFragment( netchan );
- SV_DPrintf( 0, "%s: frag: %"PRIz"\n", client->name, cursize );
+ if (netchan->fragment_pending) {
+ cursize = netchan->TransmitNextFragment(netchan);
+ SV_DPrintf(0, "%s: frag: %"PRIz"\n", client->name, cursize);
goto calctime;
}
// spawned clients are handled elsewhere
- if( client->state == cs_spawned && !client->download && !client->nodata && !SV_PAUSED ) {
+ if (client->state == cs_spawned && !client->download && !client->nodata && !SV_PAUSED) {
continue;
}
// see if it's time to resend a (possibly dropped) packet
- retransmit = ( com_localTime - netchan->last_sent > 1000 );
+ retransmit = (com_localTime - netchan->last_sent > 1000);
// don't write new reliables if not yet acknowledged
- if( netchan->reliable_length && !retransmit && client->state != cs_zombie ) {
+ if (netchan->reliable_length && !retransmit && client->state != cs_zombie) {
continue;
}
// just update reliable if needed
- if( netchan->type == NETCHAN_OLD ) {
- write_reliables_old( client, netchan->maxpacketlen );
+ if (netchan->type == NETCHAN_OLD) {
+ write_reliables_old(client, netchan->maxpacketlen);
}
- if( netchan->message.cursize || netchan->reliable_ack_pending ||
- netchan->reliable_length || retransmit )
- {
- cursize = netchan->Transmit( netchan, 0, NULL, 1 );
- SV_DPrintf( 0, "%s: send: %"PRIz"\n", client->name, cursize );
+ if (netchan->message.cursize || netchan->reliable_ack_pending ||
+ netchan->reliable_length || retransmit) {
+ cursize = netchan->Transmit(netchan, 0, NULL, 1);
+ SV_DPrintf(0, "%s: send: %"PRIz"\n", client->name, cursize);
calctime:
- SV_CalcSendTime( client, cursize );
+ SV_CalcSendTime(client, cursize);
}
}
}
-void SV_InitClientSend( client_t *newcl ) {
+void SV_InitClientSend(client_t *newcl)
+{
int i;
- List_Init( &newcl->msg_free_list );
- List_Init( &newcl->msg_unreliable_list );
- List_Init( &newcl->msg_reliable_list );
+ List_Init(&newcl->msg_free_list);
+ List_Init(&newcl->msg_unreliable_list);
+ List_Init(&newcl->msg_reliable_list);
- newcl->msg_pool = SV_Malloc( sizeof( message_packet_t ) * MSG_POOLSIZE );
- for( i = 0; i < MSG_POOLSIZE; i++ ) {
- List_Append( &newcl->msg_free_list, &newcl->msg_pool[i].entry );
+ newcl->msg_pool = SV_Malloc(sizeof(message_packet_t) * MSG_POOLSIZE);
+ for (i = 0; i < MSG_POOLSIZE; i++) {
+ List_Append(&newcl->msg_free_list, &newcl->msg_pool[i].entry);
}
// setup protocol
- if( newcl->netchan->type == NETCHAN_NEW ) {
+ if (newcl->netchan->type == NETCHAN_NEW) {
newcl->AddMessage = add_message_new;
newcl->WriteDatagram = write_datagram_new;
} else {
@@ -934,12 +954,13 @@ void SV_InitClientSend( client_t *newcl ) {
}
}
-void SV_ShutdownClientSend( client_t *client ) {
- free_all_messages( client );
+void SV_ShutdownClientSend(client_t *client)
+{
+ free_all_messages(client);
- Z_Free( client->msg_pool );
+ Z_Free(client->msg_pool);
client->msg_pool = NULL;
- List_Init( &client->msg_free_list );
+ List_Init(&client->msg_free_list);
}
diff --git a/src/sv_user.c b/src/sv_user.c
index c2d09a0..480d0f1 100644
--- a/src/sv_user.c
+++ b/src/sv_user.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sv_local.h"
#if USE_FPS
-static void align_key_frames( void );
+static void align_key_frames(void);
#endif
/*
@@ -43,117 +43,122 @@ to the clients -- only the fields that differ from the
baseline will be transmitted
================
*/
-static void create_baselines( void ) {
+static void create_baselines(void)
+{
int i;
edict_t *ent;
entity_state_t *base, **chunk;
// clear baselines from previous level
- for( i = 0; i < SV_BASELINES_CHUNKS; i++ ) {
+ for (i = 0; i < SV_BASELINES_CHUNKS; i++) {
base = sv_client->baselines[i];
- if( !base ) {
+ if (!base) {
continue;
- }
- memset( base, 0, sizeof( *base ) * SV_BASELINES_PER_CHUNK );
+ }
+ memset(base, 0, sizeof(*base) * SV_BASELINES_PER_CHUNK);
}
- for( i = 1; i < sv_client->pool->num_edicts; i++ ) {
- ent = EDICT_POOL( sv_client, i );
+ for (i = 1; i < sv_client->pool->num_edicts; i++) {
+ ent = EDICT_POOL(sv_client, i);
- if( ( g_features->integer & GMF_PROPERINUSE ) && !ent->inuse ) {
+ if ((g_features->integer & GMF_PROPERINUSE) && !ent->inuse) {
continue;
}
- if( !ES_INUSE( &ent->s ) ) {
+ if (!ES_INUSE(&ent->s)) {
continue;
}
ent->s.number = i;
chunk = &sv_client->baselines[i >> SV_BASELINES_SHIFT];
- if( *chunk == NULL ) {
- *chunk = SV_Mallocz( sizeof( *base ) * SV_BASELINES_PER_CHUNK );
+ if (*chunk == NULL) {
+ *chunk = SV_Mallocz(sizeof(*base) * SV_BASELINES_PER_CHUNK);
}
- base = *chunk + ( i & SV_BASELINES_MASK );
+ base = *chunk + (i & SV_BASELINES_MASK);
*base = ent->s;
- if( sv_client->esFlags & MSG_ES_LONGSOLID ) {
+ if (sv_client->esFlags & MSG_ES_LONGSOLID) {
base->solid = sv.entities[i].solid32;
}
}
}
-static void write_plain_configstrings( void ) {
+static void write_plain_configstrings(void)
+{
int i;
char *string;
size_t length;
// write a packet full of data
string = sv_client->configstrings;
- for( i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH ) {
- if( !string[0] ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH) {
+ if (!string[0]) {
continue;
}
- length = strlen( string );
- if( length > MAX_QPATH ) {
+ length = strlen(string);
+ if (length > MAX_QPATH) {
length = MAX_QPATH;
}
// check if this configstring will overflow
- if( msg_write.cursize + length + 64 > sv_client->netchan->maxpacketlen ) {
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ if (msg_write.cursize + length + 64 > sv_client->netchan->maxpacketlen) {
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( string, length );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(string, length);
+ MSG_WriteByte(0);
}
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
-static void write_baseline( entity_state_t *base ) {
+static void write_baseline(entity_state_t *base)
+{
msgEsFlags_t flags = sv_client->esFlags | MSG_ES_FORCE;
- if( Q2PRO_SHORTANGLES( sv_client, base->number ) ) {
+ if (Q2PRO_SHORTANGLES(sv_client, base->number)) {
flags |= MSG_ES_SHORTANGLES;
}
- MSG_WriteDeltaEntity( NULL, base, flags );
+ MSG_WriteDeltaEntity(NULL, base, flags);
}
-static void write_plain_baselines( void ) {
+static void write_plain_baselines(void)
+{
int i, j;
entity_state_t *base;
// write a packet full of data
- for( i = 0; i < SV_BASELINES_CHUNKS; i++ ) {
+ for (i = 0; i < SV_BASELINES_CHUNKS; i++) {
base = sv_client->baselines[i];
- if( !base ) {
+ if (!base) {
continue;
}
- for( j = 0; j < SV_BASELINES_PER_CHUNK; j++ ) {
- if( base->number ) {
+ for (j = 0; j < SV_BASELINES_PER_CHUNK; j++) {
+ if (base->number) {
// check if this baseline will overflow
- if( msg_write.cursize + 64 > sv_client->netchan->maxpacketlen ) {
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ if (msg_write.cursize + 64 > sv_client->netchan->maxpacketlen) {
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
- MSG_WriteByte( svc_spawnbaseline );
- write_baseline( base );
+ MSG_WriteByte(svc_spawnbaseline);
+ write_baseline(base);
}
base++;
}
}
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
#if USE_ZLIB
-static void write_compressed_gamestate( void ) {
+static void write_compressed_gamestate(void)
+{
sizebuf_t *buf = &sv_client->netchan->message;
entity_state_t *base;
int i, j;
@@ -161,187 +166,192 @@ static void write_compressed_gamestate( void ) {
uint8_t *patch;
char *string;
- MSG_WriteByte( svc_gamestate );
+ MSG_WriteByte(svc_gamestate);
// write configstrings
string = sv_client->configstrings;
- for( i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH ) {
- if( !string[0] ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH) {
+ if (!string[0]) {
continue;
}
- length = strlen( string );
- if( length > MAX_QPATH ) {
+ length = strlen(string);
+ if (length > MAX_QPATH) {
length = MAX_QPATH;
}
- MSG_WriteShort( i );
- MSG_WriteData( string, length );
- MSG_WriteByte( 0 );
+ MSG_WriteShort(i);
+ MSG_WriteData(string, length);
+ MSG_WriteByte(0);
}
- MSG_WriteShort( MAX_CONFIGSTRINGS ); // end of configstrings
+ MSG_WriteShort(MAX_CONFIGSTRINGS); // end of configstrings
// write baselines
- for( i = 0; i < SV_BASELINES_CHUNKS; i++ ) {
+ for (i = 0; i < SV_BASELINES_CHUNKS; i++) {
base = sv_client->baselines[i];
- if( !base ) {
+ if (!base) {
continue;
}
- for( j = 0; j < SV_BASELINES_PER_CHUNK; j++ ) {
- if( base->number ) {
- write_baseline( base );
+ for (j = 0; j < SV_BASELINES_PER_CHUNK; j++) {
+ if (base->number) {
+ write_baseline(base);
}
base++;
}
}
- MSG_WriteShort( 0 ); // end of baselines
+ MSG_WriteShort(0); // end of baselines
- SZ_WriteByte( buf, svc_zpacket );
- patch = SZ_GetSpace( buf, 2 );
- SZ_WriteShort( buf, msg_write.cursize );
+ SZ_WriteByte(buf, svc_zpacket);
+ patch = SZ_GetSpace(buf, 2);
+ SZ_WriteShort(buf, msg_write.cursize);
- deflateReset( &svs.z );
+ deflateReset(&svs.z);
svs.z.next_in = msg_write.data;
- svs.z.avail_in = ( uInt )msg_write.cursize;
+ svs.z.avail_in = (uInt)msg_write.cursize;
svs.z.next_out = buf->data + buf->cursize;
- svs.z.avail_out = ( uInt )( buf->maxsize - buf->cursize );
- SZ_Clear( &msg_write );
+ svs.z.avail_out = (uInt)(buf->maxsize - buf->cursize);
+ SZ_Clear(&msg_write);
- if( deflate( &svs.z, Z_FINISH ) != Z_STREAM_END ) {
- SV_DropClient( sv_client, "deflate() failed on gamestate" );
+ if (deflate(&svs.z, Z_FINISH) != Z_STREAM_END) {
+ SV_DropClient(sv_client, "deflate() failed on gamestate");
return;
}
- SV_DPrintf( 0, "%s: comp: %lu into %lu\n",
- sv_client->name, svs.z.total_in, svs.z.total_out );
+ SV_DPrintf(0, "%s: comp: %lu into %lu\n",
+ sv_client->name, svs.z.total_in, svs.z.total_out);
patch[0] = svs.z.total_out & 255;
- patch[1] = ( svs.z.total_out >> 8 ) & 255;
+ patch[1] = (svs.z.total_out >> 8) & 255;
buf->cursize += svs.z.total_out;
}
-static inline int z_flush( byte *buffer ) {
+static inline int z_flush(byte *buffer)
+{
int ret;
- ret = deflate( &svs.z, Z_FINISH );
- if( ret != Z_STREAM_END ) {
+ ret = deflate(&svs.z, Z_FINISH);
+ if (ret != Z_STREAM_END) {
return ret;
}
- SV_DPrintf( 0, "%s: comp: %lu into %lu\n",
- sv_client->name, svs.z.total_in, svs.z.total_out );
+ SV_DPrintf(0, "%s: comp: %lu into %lu\n",
+ sv_client->name, svs.z.total_in, svs.z.total_out);
+
+ MSG_WriteByte(svc_zpacket);
+ MSG_WriteShort(svs.z.total_out);
+ MSG_WriteShort(svs.z.total_in);
+ MSG_WriteData(buffer, svs.z.total_out);
- MSG_WriteByte( svc_zpacket );
- MSG_WriteShort( svs.z.total_out );
- MSG_WriteShort( svs.z.total_in );
- MSG_WriteData( buffer, svs.z.total_out );
-
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
return ret;
}
-static inline void z_reset( byte *buffer ) {
- deflateReset( &svs.z );
+static inline void z_reset(byte *buffer)
+{
+ deflateReset(&svs.z);
svs.z.next_out = buffer;
- svs.z.avail_out = ( uInt )( sv_client->netchan->maxpacketlen - 5 );
+ svs.z.avail_out = (uInt)(sv_client->netchan->maxpacketlen - 5);
}
-static void write_compressed_configstrings( void ) {
+static void write_compressed_configstrings(void)
+{
int i;
size_t length;
byte buffer[MAX_PACKETLEN_WRITABLE];
char *string;
- z_reset( buffer );
+ z_reset(buffer);
// write a packet full of data
string = sv_client->configstrings;
- for( i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH ) {
- if( !string[0] ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++, string += MAX_QPATH) {
+ if (!string[0]) {
continue;
}
- length = strlen( string );
- if( length > MAX_QPATH ) {
+ length = strlen(string);
+ if (length > MAX_QPATH) {
length = MAX_QPATH;
}
// check if this configstring will overflow
- if( svs.z.avail_out < length + 32 ) {
+ if (svs.z.avail_out < length + 32) {
// then flush compressed data
- if( z_flush( buffer ) != Z_STREAM_END ) {
+ if (z_flush(buffer) != Z_STREAM_END) {
goto fail;
}
- z_reset( buffer );
+ z_reset(buffer);
}
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( string, length );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(string, length);
+ MSG_WriteByte(0);
svs.z.next_in = msg_write.data;
- svs.z.avail_in = ( uInt )msg_write.cursize;
- SZ_Clear( &msg_write );
+ svs.z.avail_in = (uInt)msg_write.cursize;
+ SZ_Clear(&msg_write);
- if( deflate( &svs.z, Z_SYNC_FLUSH ) != Z_OK ) {
+ if (deflate(&svs.z, Z_SYNC_FLUSH) != Z_OK) {
goto fail;
}
}
// finally flush all remaining compressed data
- if( z_flush( buffer ) != Z_STREAM_END ) {
+ if (z_flush(buffer) != Z_STREAM_END) {
fail:
- SV_DropClient( sv_client, "deflate() failed on configstrings" );
+ SV_DropClient(sv_client, "deflate() failed on configstrings");
}
}
#endif // USE_ZLIB
-static void stuff_cmds( list_t *list ) {
+static void stuff_cmds(list_t *list)
+{
stuffcmd_t *stuff;
- LIST_FOR_EACH( stuffcmd_t, stuff, list, entry ) {
- MSG_WriteByte( svc_stufftext );
- MSG_WriteData( stuff->string, stuff->len );
- MSG_WriteByte( '\n' );
- MSG_WriteByte( 0 );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ LIST_FOR_EACH(stuffcmd_t, stuff, list, entry) {
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteData(stuff->string, stuff->len);
+ MSG_WriteByte('\n');
+ MSG_WriteByte(0);
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
}
-static void stuff_junk( void ) {
+static void stuff_junk(void)
+{
static const char junkchars[] =
"!~#``&'()*`+,-./~01~2`3`4~5`67`89:~<=`>?@~ab~c"
"d`ef~j~k~lm`no~pq`rst`uv`w``x`yz[`\\]^_`|~";
char junk[8][16];
int i, j, k;
- for( i = 0; i < 8; i++ ) {
- for( j = 0; j < 15; j++ ) {
- k = rand_byte() % ( sizeof( junkchars ) - 1 );
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 15; j++) {
+ k = rand_byte() % (sizeof(junkchars) - 1);
junk[i][j] = junkchars[k];
}
junk[i][15] = 0;
}
- strcpy( sv_client->reconnect_var, junk[2] );
- strcpy( sv_client->reconnect_val, junk[3] );
+ strcpy(sv_client->reconnect_var, junk[2]);
+ strcpy(sv_client->reconnect_val, junk[3]);
- SV_ClientCommand( sv_client, "set %s set\n", junk[0] );
- SV_ClientCommand( sv_client, "$%s %s connect\n", junk[0], junk[1] );
- if( rand_byte() & 1 ) {
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[2], junk[3] );
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[4],
- sv_force_reconnect->string );
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[5], junk[6] );
+ SV_ClientCommand(sv_client, "set %s set\n", junk[0]);
+ SV_ClientCommand(sv_client, "$%s %s connect\n", junk[0], junk[1]);
+ if (rand_byte() & 1) {
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[2], junk[3]);
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[4],
+ sv_force_reconnect->string);
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[5], junk[6]);
} else {
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[4],
- sv_force_reconnect->string );
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[5], junk[6] );
- SV_ClientCommand( sv_client, "$%s %s %s\n", junk[0], junk[2], junk[3] );
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[4],
+ sv_force_reconnect->string);
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[5], junk[6]);
+ SV_ClientCommand(sv_client, "$%s %s %s\n", junk[0], junk[2], junk[3]);
}
- SV_ClientCommand( sv_client, "$%s %s \"\"\n", junk[0], junk[0] );
- SV_ClientCommand( sv_client, "$%s $%s\n", junk[1], junk[4] );
+ SV_ClientCommand(sv_client, "$%s %s \"\"\n", junk[0], junk[0]);
+ SV_ClientCommand(sv_client, "$%s $%s\n", junk[1], junk[4]);
}
/*
@@ -352,101 +362,101 @@ Sends the first message from the server to a connected client.
This will be sent on the initial connection and upon each server load.
================
*/
-void SV_New_f( void ) {
+void SV_New_f(void)
+{
clstate_t oldstate;
- Com_DPrintf( "New() from %s\n", sv_client->name );
+ Com_DPrintf("New() from %s\n", sv_client->name);
oldstate = sv_client->state;
- if( sv_client->state < cs_connected ) {
- Com_DPrintf( "Going from cs_assigned to cs_connected for %s\n",
- sv_client->name );
+ if (sv_client->state < cs_connected) {
+ Com_DPrintf("Going from cs_assigned to cs_connected for %s\n",
+ sv_client->name);
sv_client->state = cs_connected;
sv_client->lastmessage = svs.realtime; // don't timeout
- time( &sv_client->connect_time );
- } else if( sv_client->state > cs_connected ) {
- Com_DPrintf( "New not valid -- already primed\n" );
+ time(&sv_client->connect_time);
+ } else if (sv_client->state > cs_connected) {
+ Com_DPrintf("New not valid -- already primed\n");
return;
}
// stuff some junk, drop them and expect them to be back soon
- if( sv_force_reconnect->string[0] && !sv_client->reconnect_var[0] &&
- !NET_IsLocalAddress( &sv_client->netchan->remote_address ) )
- {
+ if (sv_force_reconnect->string[0] && !sv_client->reconnect_var[0] &&
+ !NET_IsLocalAddress(&sv_client->netchan->remote_address)) {
stuff_junk();
- SV_DropClient( sv_client, NULL );
+ SV_DropClient(sv_client, NULL);
return;
}
- SV_ClientCommand( sv_client, "\n" );
+ SV_ClientCommand(sv_client, "\n");
//
// serverdata needs to go over for all types of servers
// to make sure the protocol is right, and to set the gamedir
//
-
+
// create baselines for this client
create_baselines();
// send the serverdata
- MSG_WriteByte( svc_serverdata );
- MSG_WriteLong( sv_client->protocol );
- MSG_WriteLong( sv_client->spawncount );
- MSG_WriteByte( 0 ); // no attract loop
- MSG_WriteString( sv_client->gamedir );
- MSG_WriteShort( sv_client->slot );
- MSG_WriteString( &sv_client->configstrings[CS_NAME*MAX_QPATH] );
+ MSG_WriteByte(svc_serverdata);
+ MSG_WriteLong(sv_client->protocol);
+ MSG_WriteLong(sv_client->spawncount);
+ MSG_WriteByte(0); // no attract loop
+ MSG_WriteString(sv_client->gamedir);
+ MSG_WriteShort(sv_client->slot);
+ MSG_WriteString(&sv_client->configstrings[CS_NAME * MAX_QPATH]);
// send protocol specific stuff
- switch( sv_client->protocol ) {
+ switch (sv_client->protocol) {
case PROTOCOL_VERSION_R1Q2:
- MSG_WriteByte( 0 ); // not enhanced
- MSG_WriteShort( sv_client->version );
- MSG_WriteByte( 0 ); // no advanced deltas
- MSG_WriteByte( sv_client->pmp.strafehack );
+ MSG_WriteByte(0); // not enhanced
+ MSG_WriteShort(sv_client->version);
+ MSG_WriteByte(0); // no advanced deltas
+ MSG_WriteByte(sv_client->pmp.strafehack);
break;
case PROTOCOL_VERSION_Q2PRO:
- MSG_WriteShort( sv_client->version );
- MSG_WriteByte( 2 ); // used to be GT_DEATHMATCH
- MSG_WriteByte( sv_client->pmp.strafehack );
- MSG_WriteByte( sv_client->pmp.qwmode );
- if( sv_client->version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK ) {
- MSG_WriteByte( sv_client->pmp.waterhack );
+ MSG_WriteShort(sv_client->version);
+ MSG_WriteByte(2); // used to be GT_DEATHMATCH
+ MSG_WriteByte(sv_client->pmp.strafehack);
+ MSG_WriteByte(sv_client->pmp.qwmode);
+ if (sv_client->version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK) {
+ MSG_WriteByte(sv_client->pmp.waterhack);
}
break;
default:
break;
}
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
- SV_ClientCommand( sv_client, "\n" );
+ SV_ClientCommand(sv_client, "\n");
// send version string request
- if( oldstate == cs_assigned ) {
- SV_ClientCommand( sv_client, "cmd \177c version $version\n"
+ if (oldstate == cs_assigned) {
+ SV_ClientCommand(sv_client, "cmd \177c version $version\n"
#if USE_AC_SERVER
- "cmd \177c actoken $actoken\n"
+ "cmd \177c actoken $actoken\n"
#endif
- );
- stuff_cmds( &sv_cmdlist_connect );
+ );
+ stuff_cmds(&sv_cmdlist_connect);
}
// send reconnect var request
- if( sv_force_reconnect->string[0] && !sv_client->reconnected ) {
- SV_ClientCommand( sv_client, "cmd \177c connect $%s\n",
- sv_client->reconnect_var );
+ if (sv_force_reconnect->string[0] && !sv_client->reconnected) {
+ SV_ClientCommand(sv_client, "cmd \177c connect $%s\n",
+ sv_client->reconnect_var);
}
- Com_DPrintf( "Going from cs_connected to cs_primed for %s\n",
- sv_client->name );
+ Com_DPrintf("Going from cs_connected to cs_primed for %s\n",
+ sv_client->name);
sv_client->state = cs_primed;
- memset( &sv_client->lastcmd, 0, sizeof( sv_client->lastcmd ) );
+ memset(&sv_client->lastcmd, 0, sizeof(sv_client->lastcmd));
#if USE_ZLIB
- if( sv_client->has_zlib ) {
- if( sv_client->netchan->type == NETCHAN_NEW ) {
+ if (sv_client->has_zlib) {
+ if (sv_client->netchan->type == NETCHAN_NEW) {
write_compressed_gamestate();
} else {
// FIXME: Z_SYNC_FLUSH is not efficient for baselines
@@ -461,7 +471,7 @@ void SV_New_f( void ) {
}
// send next command
- SV_ClientCommand( sv_client, "precache %i\n", sv_client->spawncount );
+ SV_ClientCommand(sv_client, "precache %i\n", sv_client->spawncount);
}
/*
@@ -469,38 +479,39 @@ void SV_New_f( void ) {
SV_Begin_f
==================
*/
-void SV_Begin_f( void ) {
- Com_DPrintf( "Begin() from %s\n", sv_client->name );
+void SV_Begin_f(void)
+{
+ Com_DPrintf("Begin() from %s\n", sv_client->name);
// handle the case of a level changing while a client was connecting
- if( sv_client->state < cs_primed ) {
- Com_DPrintf( "Begin not valid -- not yet primed\n" );
+ if (sv_client->state < cs_primed) {
+ Com_DPrintf("Begin not valid -- not yet primed\n");
SV_New_f();
return;
}
- if( sv_client->state > cs_primed ) {
- Com_DPrintf( "Begin not valid -- already spawned\n" );
+ if (sv_client->state > cs_primed) {
+ Com_DPrintf("Begin not valid -- already spawned\n");
return;
}
- if( !sv_client->versionString ) {
- SV_DropClient( sv_client, "!failed version probe" );
+ if (!sv_client->versionString) {
+ SV_DropClient(sv_client, "!failed version probe");
return;
}
- if( sv_force_reconnect->string[0] && !sv_client->reconnected ) {
- SV_DropClient( sv_client, "!failed to reconnect" );
+ if (sv_force_reconnect->string[0] && !sv_client->reconnected) {
+ SV_DropClient(sv_client, "!failed to reconnect");
return;
}
#if USE_AC_SERVER
- if( !AC_ClientBegin( sv_client ) ) {
+ if (!AC_ClientBegin(sv_client)) {
return;
}
#endif
- Com_DPrintf( "Going from cs_primed to cs_spawned for %s\n",
- sv_client->name );
+ Com_DPrintf("Going from cs_primed to cs_spawned for %s\n",
+ sv_client->name);
sv_client->state = cs_spawned;
sv_client->send_delta = 0;
sv_client->commandMsec = 1800;
@@ -510,13 +521,13 @@ void SV_Begin_f( void ) {
align_key_frames();
#endif
- stuff_cmds( &sv_cmdlist_begin );
-
+ stuff_cmds(&sv_cmdlist_begin);
+
// call the game begin function
- ge->ClientBegin( sv_player );
+ ge->ClientBegin(sv_player);
#if USE_AC_SERVER
- AC_ClientAnnounce( sv_client );
+ AC_ClientAnnounce(sv_client);
#endif
}
@@ -524,13 +535,14 @@ void SV_Begin_f( void ) {
#define MAX_DOWNLOAD_CHUNK 1024
-void SV_CloseDownload( client_t *client ) {
- if( client->download ) {
- Z_Free( client->download );
+void SV_CloseDownload(client_t *client)
+{
+ if (client->download) {
+ Z_Free(client->download);
client->download = NULL;
}
- if( client->downloadname ) {
- Z_Free( client->downloadname );
+ if (client->downloadname) {
+ Z_Free(client->downloadname);
client->downloadname = NULL;
}
client->downloadsize = 0;
@@ -542,38 +554,39 @@ void SV_CloseDownload( client_t *client ) {
SV_NextDownload_f
==================
*/
-static void SV_NextDownload_f( void ) {
+static void SV_NextDownload_f(void)
+{
int r;
int percent;
int size;
- if ( !sv_client->download )
+ if (!sv_client->download)
return;
r = sv_client->downloadsize - sv_client->downloadcount;
- if ( r > MAX_DOWNLOAD_CHUNK )
+ if (r > MAX_DOWNLOAD_CHUNK)
r = MAX_DOWNLOAD_CHUNK;
- MSG_WriteByte( svc_download );
- MSG_WriteShort( r );
+ MSG_WriteByte(svc_download);
+ MSG_WriteShort(r);
sv_client->downloadcount += r;
size = sv_client->downloadsize;
- if( !size )
+ if (!size)
size = 1;
- percent = sv_client->downloadcount*100/size;
- MSG_WriteByte( percent );
- MSG_WriteData( sv_client->download + sv_client->downloadcount - r, r );
+ percent = sv_client->downloadcount * 100 / size;
+ MSG_WriteByte(percent);
+ MSG_WriteData(sv_client->download + sv_client->downloadcount - r, r);
- if( sv_client->downloadcount == sv_client->downloadsize ) {
- SV_CloseDownload( sv_client );
+ if (sv_client->downloadcount == sv_client->downloadsize) {
+ SV_CloseDownload(sv_client);
#if USE_FPS
- if( sv_client->state == cs_spawned )
+ if (sv_client->state == cs_spawned)
align_key_frames();
#endif
}
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
/*
@@ -581,7 +594,8 @@ static void SV_NextDownload_f( void ) {
SV_BeginDownload_f
==================
*/
-static void SV_BeginDownload_f( void ) {
+static void SV_BeginDownload_f(void)
+{
char name[MAX_QPATH];
byte *download;
ssize_t downloadsize, maxdownloadsize, result;
@@ -591,170 +605,170 @@ static void SV_BeginDownload_f( void ) {
unsigned flags;
qhandle_t f;
- len = Cmd_ArgvBuffer( 1, name, sizeof( name ) );
- if( len >= MAX_QPATH ) {
+ len = Cmd_ArgvBuffer(1, name, sizeof(name));
+ if (len >= MAX_QPATH) {
goto fail1;
}
// hack for 'status' command
- if( !strcmp( name, "http" ) ) {
+ if (!strcmp(name, "http")) {
sv_client->http_download = qtrue;
return;
}
- len = FS_NormalizePath( name, name );
+ len = FS_NormalizePath(name, name);
- if( Cmd_Argc() > 2 )
- offset = atoi( Cmd_Argv( 2 ) ); // downloaded offset
+ if (Cmd_Argc() > 2)
+ offset = atoi(Cmd_Argv(2)); // downloaded offset
// hacked by zoid to allow more conrol over download
// first off, no .. or global allow check
- if( !allow_download->integer
+ if (!allow_download->integer
// check for empty paths
|| !len
// check for illegal negative offsets
|| offset < 0
// don't allow anything with .. path
- || strstr( name, ".." )
+ || strstr(name, "..")
// leading dots, slashes, etc are no good
- || !Q_ispath( name[0] )
+ || !Q_ispath(name[0])
// trailing dots, slashes, etc are no good
- || !Q_ispath( name[ len - 1 ] )
- // MUST be in a subdirectory
- || !strchr( name, '/' ) )
- {
- Com_DPrintf( "Refusing download of %s to %s\n", name, sv_client->name );
+ || !Q_ispath(name[len - 1])
+ // MUST be in a subdirectory
+ || !strchr(name, '/')) {
+ Com_DPrintf("Refusing download of %s to %s\n", name, sv_client->name);
goto fail1;
}
- if( FS_pathcmpn( name, CONST_STR_LEN( "players/" ) ) == 0 ) {
+ if (FS_pathcmpn(name, CONST_STR_LEN("players/")) == 0) {
allow = allow_download_players;
- } else if( FS_pathcmpn( name, CONST_STR_LEN( "models/" ) ) == 0 ||
- FS_pathcmpn( name, CONST_STR_LEN( "sprites/" ) ) == 0 )
- {
+ } else if (FS_pathcmpn(name, CONST_STR_LEN("models/")) == 0 ||
+ FS_pathcmpn(name, CONST_STR_LEN("sprites/")) == 0) {
allow = allow_download_models;
- } else if( FS_pathcmpn( name, CONST_STR_LEN( "sound/" ) ) == 0 ) {
+ } else if (FS_pathcmpn(name, CONST_STR_LEN("sound/")) == 0) {
allow = allow_download_sounds;
- } else if( FS_pathcmpn( name, CONST_STR_LEN( "maps/" ) ) == 0 ) {
+ } else if (FS_pathcmpn(name, CONST_STR_LEN("maps/")) == 0) {
allow = allow_download_maps;
- } else if( FS_pathcmpn( name, CONST_STR_LEN( "textures/" ) ) == 0 ||
- FS_pathcmpn( name, CONST_STR_LEN( "env/" ) ) == 0 )
- {
+ } else if (FS_pathcmpn(name, CONST_STR_LEN("textures/")) == 0 ||
+ FS_pathcmpn(name, CONST_STR_LEN("env/")) == 0) {
allow = allow_download_textures;
- } else if( FS_pathcmpn( name, CONST_STR_LEN( "pics/" ) ) == 0 ) {
+ } else if (FS_pathcmpn(name, CONST_STR_LEN("pics/")) == 0) {
allow = allow_download_pics;
} else {
allow = allow_download_others;
}
- if( !allow->integer ) {
- Com_DPrintf( "Refusing download of %s to %s\n", name, sv_client->name );
+ if (!allow->integer) {
+ Com_DPrintf("Refusing download of %s to %s\n", name, sv_client->name);
goto fail1;
}
- if( sv_client->download ) {
- Com_DPrintf( "Closing existing download for %s (should not happen)\n", sv_client->name );
- SV_CloseDownload( sv_client );
+ if (sv_client->download) {
+ Com_DPrintf("Closing existing download for %s (should not happen)\n", sv_client->name);
+ SV_CloseDownload(sv_client);
}
flags = FS_MODE_READ;
// special check for maps, if it came from a pak file, don't allow
// download ZOID
- if( allow == allow_download_maps && allow->integer < 2 ) {
+ if (allow == allow_download_maps && allow->integer < 2) {
flags |= FS_TYPE_REAL;
}
- downloadsize = FS_FOpenFile( name, &f, flags );
- if( !f ) {
- Com_DPrintf( "Couldn't download %s to %s\n", name, sv_client->name );
+ downloadsize = FS_FOpenFile(name, &f, flags);
+ if (!f) {
+ Com_DPrintf("Couldn't download %s to %s\n", name, sv_client->name);
goto fail1;
}
maxdownloadsize = MAX_LOADFILE;
-// if( sv_max_download_size->integer ) {
-// maxdownloadsize = Cvar_ClampInteger( sv_max_download_size, 1, MAX_LOADFILE );
-// }
+#if 0
+ if (sv_max_download_size->integer) {
+ maxdownloadsize = Cvar_ClampInteger(sv_max_download_size, 1, MAX_LOADFILE);
+ }
+#endif
- if( downloadsize > maxdownloadsize ) {
- Com_DPrintf( "Refusing oversize download of %s to %s\n", name, sv_client->name );
+ if (downloadsize > maxdownloadsize) {
+ Com_DPrintf("Refusing oversize download of %s to %s\n", name, sv_client->name);
goto fail2;
}
- if( offset > downloadsize ) {
- Com_DPrintf( "Refusing download, %s has wrong version of %s (%d > %d)\n",
- sv_client->name, name, offset, (int)downloadsize );
- SV_ClientPrintf( sv_client, PRINT_HIGH, "File size differs from server.\n"
- "Please delete the corresponding .tmp file from your system.\n" );
+ if (offset > downloadsize) {
+ Com_DPrintf("Refusing download, %s has wrong version of %s (%d > %d)\n",
+ sv_client->name, name, offset, (int)downloadsize);
+ SV_ClientPrintf(sv_client, PRINT_HIGH, "File size differs from server.\n"
+ "Please delete the corresponding .tmp file from your system.\n");
goto fail2;
}
- if( offset == downloadsize ) {
- Com_DPrintf( "Refusing download, %s already has %s (%d bytes)\n",
- sv_client->name, name, offset );
- FS_FCloseFile( f );
- MSG_WriteByte( svc_download );
- MSG_WriteShort( 0 );
- MSG_WriteByte( 100 );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ if (offset == downloadsize) {
+ Com_DPrintf("Refusing download, %s already has %s (%d bytes)\n",
+ sv_client->name, name, offset);
+ FS_FCloseFile(f);
+ MSG_WriteByte(svc_download);
+ MSG_WriteShort(0);
+ MSG_WriteByte(100);
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
return;
}
- download = SV_Malloc( downloadsize );
- result = FS_Read( download, downloadsize, f );
- if( result != downloadsize ) {
- Com_DPrintf( "Couldn't download %s to %s\n", name, sv_client->name );
+ download = SV_Malloc(downloadsize);
+ result = FS_Read(download, downloadsize, f);
+ if (result != downloadsize) {
+ Com_DPrintf("Couldn't download %s to %s\n", name, sv_client->name);
goto fail3;
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
sv_client->download = download;
sv_client->downloadsize = downloadsize;
sv_client->downloadcount = offset;
- sv_client->downloadname = SV_CopyString( name );
+ sv_client->downloadname = SV_CopyString(name);
- Com_DPrintf( "Downloading %s to %s\n", name, sv_client->name );
+ Com_DPrintf("Downloading %s to %s\n", name, sv_client->name);
SV_NextDownload_f();
return;
fail3:
- Z_Free( download );
+ Z_Free(download);
fail2:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
fail1:
- MSG_WriteByte( svc_download );
- MSG_WriteShort( -1 );
- MSG_WriteByte( 0 );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_download);
+ MSG_WriteShort(-1);
+ MSG_WriteByte(0);
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
-static void SV_StopDownload_f( void ) {
+static void SV_StopDownload_f(void)
+{
int size, percent;
- if( !sv_client->download ) {
+ if (!sv_client->download) {
return;
}
size = sv_client->downloadsize;
- if( !size ) {
+ if (!size) {
percent = 0;
} else {
- percent = sv_client->downloadcount*100/size;
+ percent = sv_client->downloadcount * 100 / size;
}
- MSG_WriteByte( svc_download );
- MSG_WriteShort( -1 );
- MSG_WriteByte( percent );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_download);
+ MSG_WriteShort(-1);
+ MSG_WriteByte(percent);
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
- Com_DPrintf( "Download of %s to %s stopped by user request\n",
- sv_client->downloadname, sv_client->name );
- SV_CloseDownload( sv_client );
+ Com_DPrintf("Download of %s to %s stopped by user request\n",
+ sv_client->downloadname, sv_client->name);
+ SV_CloseDownload(sv_client);
#if USE_FPS
- if( sv_client->state == cs_spawned )
+ if (sv_client->state == cs_spawned)
align_key_frames();
#endif
}
@@ -762,128 +776,138 @@ static void SV_StopDownload_f( void ) {
//============================================================================
// the client is going to disconnect, so remove the connection immediately
-static void SV_Disconnect_f( void ) {
- SV_DropClient( sv_client, "!?disconnected" );
- SV_RemoveClient( sv_client ); // don't bother with zombie state
+static void SV_Disconnect_f(void)
+{
+ SV_DropClient(sv_client, "!?disconnected");
+ SV_RemoveClient(sv_client); // don't bother with zombie state
}
// dumps the serverinfo info string
-static void SV_ShowServerInfo_f( void ) {
+static void SV_ShowServerInfo_f(void)
+{
char serverinfo[MAX_INFO_STRING];
- Cvar_BitInfo( serverinfo, CVAR_SERVERINFO );
+ Cvar_BitInfo(serverinfo, CVAR_SERVERINFO);
- SV_BeginRedirect( RD_CLIENT );
- Info_Print( serverinfo );
+ SV_BeginRedirect(RD_CLIENT);
+ Info_Print(serverinfo);
Com_EndRedirect();
}
// dumps misc protocol info
-static void SV_ShowMiscInfo_f( void ) {
- SV_BeginRedirect( RD_CLIENT );
+static void SV_ShowMiscInfo_f(void)
+{
+ SV_BeginRedirect(RD_CLIENT);
SV_PrintMiscInfo();
Com_EndRedirect();
}
-static void SV_NoGameData_f( void ) {
+static void SV_NoGameData_f(void)
+{
sv_client->nodata ^= 1;
#if USE_FPS
- if( sv_client->state == cs_spawned )
+ if (sv_client->state == cs_spawned)
align_key_frames();
#endif
}
-static void SV_Lag_f( void ) {
+static void SV_Lag_f(void)
+{
client_t *cl;
- if( Cmd_Argc() > 1 ) {
- SV_BeginRedirect( RD_CLIENT );
- cl = SV_GetPlayer( Cmd_Argv( 1 ), qtrue );
+ if (Cmd_Argc() > 1) {
+ SV_BeginRedirect(RD_CLIENT);
+ cl = SV_GetPlayer(Cmd_Argv(1), qtrue);
Com_EndRedirect();
- if( !cl ) {
+ if (!cl) {
return;
}
} else {
cl = sv_client;
}
- SV_ClientPrintf( sv_client, PRINT_HIGH,
- "Lag stats for: %s\n"
- "RTT (min/avg/max): %d/%d/%d ms\n"
- "Server to client PL: %.2f%% (approx)\n"
- "Client to server PL: %.2f%%\n",
- cl->name, cl->min_ping, AVG_PING( cl ), cl->max_ping,
- PL_S2C( cl ), PL_C2S( cl ) );
+ SV_ClientPrintf(sv_client, PRINT_HIGH,
+ "Lag stats for: %s\n"
+ "RTT (min/avg/max): %d/%d/%d ms\n"
+ "Server to client PL: %.2f%% (approx)\n"
+ "Client to server PL: %.2f%%\n",
+ cl->name, cl->min_ping, AVG_PING(cl), cl->max_ping,
+ PL_S2C(cl), PL_C2S(cl));
}
#if USE_PACKETDUP
-static void SV_PacketdupHack_f( void ) {
+static void SV_PacketdupHack_f(void)
+{
int numdups = sv_client->numpackets - 1;
- if( Cmd_Argc() > 1 ) {
- numdups = atoi( Cmd_Argv( 1 ) );
- if( numdups < 0 || numdups > sv_packetdup_hack->integer ) {
- SV_ClientPrintf( sv_client, PRINT_HIGH,
- "Packetdup of %d is not allowed on this server.\n", numdups );
+ if (Cmd_Argc() > 1) {
+ numdups = atoi(Cmd_Argv(1));
+ if (numdups < 0 || numdups > sv_packetdup_hack->integer) {
+ SV_ClientPrintf(sv_client, PRINT_HIGH,
+ "Packetdup of %d is not allowed on this server.\n", numdups);
return;
}
sv_client->numpackets = numdups + 1;
}
- SV_ClientPrintf( sv_client, PRINT_HIGH,
- "Server is sending %d duplicate packet%s to you.\n",
- numdups, numdups == 1 ? "" : "s" );
+ SV_ClientPrintf(sv_client, PRINT_HIGH,
+ "Server is sending %d duplicate packet%s to you.\n",
+ numdups, numdups == 1 ? "" : "s");
}
#endif
-static void SV_CvarResult_f( void ) {
+static void SV_CvarResult_f(void)
+{
char *c, *v;
- c = Cmd_Argv( 1 );
- if( !strcmp( c, "version" ) ) {
- if( !sv_client->versionString ) {
- v = Cmd_RawArgsFrom( 2 );
- if( Com_IsDedicated() ) {
- Com_Printf( "%s[%s]: %s\n", sv_client->name,
- NET_AdrToString( &sv_client->netchan->remote_address ), v );
+ c = Cmd_Argv(1);
+ if (!strcmp(c, "version")) {
+ if (!sv_client->versionString) {
+ v = Cmd_RawArgsFrom(2);
+ if (Com_IsDedicated()) {
+ Com_Printf("%s[%s]: %s\n", sv_client->name,
+ NET_AdrToString(&sv_client->netchan->remote_address), v);
}
- sv_client->versionString = SV_CopyString( v );
+ sv_client->versionString = SV_CopyString(v);
}
- } else if( !strcmp( c, "connect" ) ) {
- if( sv_client->reconnect_var[0] ) {
- v = Cmd_Argv( 2 );
- if( !strcmp( v, sv_client->reconnect_val ) ) {
+ } else if (!strcmp(c, "connect")) {
+ if (sv_client->reconnect_var[0]) {
+ v = Cmd_Argv(2);
+ if (!strcmp(v, sv_client->reconnect_val)) {
sv_client->reconnected = qtrue;
}
}
}
#if USE_AC_SERVER
- else if( !strcmp( c, "actoken" ) ) {
- AC_ClientToken( sv_client, Cmd_Argv( 2 ) );
+ else if (!strcmp(c, "actoken")) {
+ AC_ClientToken(sv_client, Cmd_Argv(2));
}
#endif
}
#if USE_AC_SERVER
-static void SV_AC_List_f( void ) {
- SV_BeginRedirect( RD_CLIENT );
+static void SV_AC_List_f(void)
+{
+ SV_BeginRedirect(RD_CLIENT);
AC_List_f();
Com_EndRedirect();
}
-static void SV_AC_Info_f( void ) {
- SV_BeginRedirect( RD_CLIENT );
+static void SV_AC_Info_f(void)
+{
+ SV_BeginRedirect(RD_CLIENT);
AC_Info_f();
Com_EndRedirect();
}
#else
-static void SV_AC_Null_f( void ) {
- SV_ClientPrintf( sv_client, PRINT_HIGH,
- "This server does not support anticheat.\n" );
+static void SV_AC_Null_f(void)
+{
+ SV_ClientPrintf(sv_client, PRINT_HIGH,
+ "This server does not support anticheat.\n");
}
#endif
@@ -897,7 +921,7 @@ static const ucmd_t ucmds[] = {
{ "nextserver", NULL },
{ "disconnect", SV_Disconnect_f },
- // issued by hand at client consoles
+ // issued by hand at client consoles
{ "info", SV_ShowServerInfo_f },
{ "sinfo", SV_ShowMiscInfo_f },
@@ -922,31 +946,32 @@ static const ucmd_t ucmds[] = {
{ NULL, NULL }
};
-static void handle_filtercmd( filtercmd_t *filter ) {
+static void handle_filtercmd(filtercmd_t *filter)
+{
size_t len;
- switch( filter->action ) {
+ switch (filter->action) {
case FA_PRINT:
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
break;
case FA_STUFF:
- MSG_WriteByte( svc_stufftext );
+ MSG_WriteByte(svc_stufftext);
break;
case FA_KICK:
- SV_DropClient( sv_client, filter->comment[0] ?
- filter->comment : "issued banned command" );
+ SV_DropClient(sv_client, filter->comment[0] ?
+ filter->comment : "issued banned command");
// fall through
default:
return;
}
- len = strlen( filter->comment );
- MSG_WriteData( filter->comment, len );
- MSG_WriteByte( '\n' );
- MSG_WriteByte( 0 );
+ len = strlen(filter->comment);
+ MSG_WriteData(filter->comment, len);
+ MSG_WriteByte('\n');
+ MSG_WriteByte(0);
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
/*
@@ -954,35 +979,36 @@ static void handle_filtercmd( filtercmd_t *filter ) {
SV_ExecuteUserCommand
==================
*/
-static void SV_ExecuteUserCommand( const char *s ) {
+static void SV_ExecuteUserCommand(const char *s)
+{
const ucmd_t *u;
filtercmd_t *filter;
char *c;
-
- Cmd_TokenizeString( s, qfalse );
+
+ Cmd_TokenizeString(s, qfalse);
sv_player = sv_client->edict;
- c = Cmd_Argv( 0 );
- if( !c[0] ) {
+ c = Cmd_Argv(0);
+ if (!c[0]) {
return;
}
- if( ( u = Com_Find( ucmds, c ) ) != NULL ) {
- if( u->func ) {
+ if ((u = Com_Find(ucmds, c)) != NULL) {
+ if (u->func) {
u->func();
}
return;
}
- if( sv.state < ss_game ) {
+ if (sv.state < ss_game) {
return;
}
- LIST_FOR_EACH( filtercmd_t, filter, &sv_filterlist, entry ) {
- if( !Q_stricmp( filter->string, c ) ) {
- handle_filtercmd( filter );
+ LIST_FOR_EACH(filtercmd_t, filter, &sv_filterlist, entry) {
+ if (!Q_stricmp(filter->string, c)) {
+ handle_filtercmd(filter);
return;
}
}
- ge->ClientCommand( sv_player );
+ ge->ClientCommand(sv_player);
}
/*
@@ -1002,35 +1028,37 @@ static int userinfoUpdateCount;
SV_ClientThink
==================
*/
-static inline void SV_ClientThink( usercmd_t *cmd ) {
+static inline void SV_ClientThink(usercmd_t *cmd)
+{
sv_client->commandMsec -= cmd->msec;
sv_client->numMoves++;
- if( sv_client->commandMsec < 0 && sv_enforcetime->integer ) {
- Com_DPrintf( "commandMsec underflow from %s: %d\n",
- sv_client->name, sv_client->commandMsec );
+ if (sv_client->commandMsec < 0 && sv_enforcetime->integer) {
+ Com_DPrintf("commandMsec underflow from %s: %d\n",
+ sv_client->name, sv_client->commandMsec);
return;
}
- ge->ClientThink( sv_player, cmd );
+ ge->ClientThink(sv_player, cmd);
}
-static void SV_SetLastFrame( int lastframe ) {
+static void SV_SetLastFrame(int lastframe)
+{
client_frame_t *frame;
- if( lastframe > 0 ) {
- if( lastframe >= sv_client->framenum )
+ if (lastframe > 0) {
+ if (lastframe >= sv_client->framenum)
return; // ignore invalid acks
- if( lastframe <= sv_client->lastframe )
+ if (lastframe <= sv_client->lastframe)
return; // ignore duplicate acks
- if( sv_client->framenum - lastframe <= UPDATE_BACKUP ) {
+ if (sv_client->framenum - lastframe <= UPDATE_BACKUP) {
frame = &sv_client->frames[lastframe & UPDATE_MASK];
- if( frame->number == lastframe ) {
+ if (frame->number == lastframe) {
// save time for ping calc
- if( frame->sentTime <= com_eventTime )
+ if (frame->sentTime <= com_eventTime)
frame->latency = com_eventTime - frame->sentTime;
}
}
@@ -1047,66 +1075,66 @@ static void SV_SetLastFrame( int lastframe ) {
SV_OldClientExecuteMove
==================
*/
-static void SV_OldClientExecuteMove( void ) {
+static void SV_OldClientExecuteMove(void)
+{
usercmd_t oldest, oldcmd, newcmd;
int lastframe;
int net_drop;
- if( moveIssued ) {
- SV_DropClient( sv_client, "multiple clc_move commands in packet" );
+ if (moveIssued) {
+ SV_DropClient(sv_client, "multiple clc_move commands in packet");
return; // someone is trying to cheat...
}
moveIssued = qtrue;
- if( sv_client->protocol == PROTOCOL_VERSION_DEFAULT ) {
+ if (sv_client->protocol == PROTOCOL_VERSION_DEFAULT) {
MSG_ReadByte(); // skip over checksum
}
-
+
lastframe = MSG_ReadLong();
// read all cmds
- if( sv_client->protocol == PROTOCOL_VERSION_R1Q2 &&
- sv_client->version >= PROTOCOL_VERSION_R1Q2_UCMD )
- {
- MSG_ReadDeltaUsercmd_Hacked( NULL, &oldest );
- MSG_ReadDeltaUsercmd_Hacked( &oldest, &oldcmd );
- MSG_ReadDeltaUsercmd_Hacked( &oldcmd, &newcmd );
+ if (sv_client->protocol == PROTOCOL_VERSION_R1Q2 &&
+ sv_client->version >= PROTOCOL_VERSION_R1Q2_UCMD) {
+ MSG_ReadDeltaUsercmd_Hacked(NULL, &oldest);
+ MSG_ReadDeltaUsercmd_Hacked(&oldest, &oldcmd);
+ MSG_ReadDeltaUsercmd_Hacked(&oldcmd, &newcmd);
} else {
- MSG_ReadDeltaUsercmd( NULL, &oldest );
- MSG_ReadDeltaUsercmd( &oldest, &oldcmd );
- MSG_ReadDeltaUsercmd( &oldcmd, &newcmd );
+ MSG_ReadDeltaUsercmd(NULL, &oldest);
+ MSG_ReadDeltaUsercmd(&oldest, &oldcmd);
+ MSG_ReadDeltaUsercmd(&oldcmd, &newcmd);
}
- if( sv_client->state != cs_spawned ) {
- SV_SetLastFrame( -1 );
+ if (sv_client->state != cs_spawned) {
+ SV_SetLastFrame(-1);
return;
}
- SV_SetLastFrame( lastframe );
+ SV_SetLastFrame(lastframe);
net_drop = sv_client->netchan->dropped;
- if( net_drop > 2 ) {
+ if (net_drop > 2) {
sv_client->frameflags |= FF_CLIENTPRED;
- }
+ }
- if( net_drop < 20 ) {
+ if (net_drop < 20) {
// run lastcmd multiple times if no backups available
- while( net_drop > 2 ) {
- SV_ClientThink( &sv_client->lastcmd );
+ while (net_drop > 2) {
+ SV_ClientThink(&sv_client->lastcmd);
net_drop--;
}
// run backup cmds
- if( net_drop > 1 )
- SV_ClientThink( &oldest );
- if( net_drop > 0 )
- SV_ClientThink( &oldcmd );
+ if (net_drop > 1)
+ SV_ClientThink(&oldest);
+ if (net_drop > 0)
+ SV_ClientThink(&oldcmd);
}
// run new cmd
- SV_ClientThink( &newcmd );
-
+ SV_ClientThink(&newcmd);
+
sv_client->lastcmd = newcmd;
}
@@ -1115,7 +1143,8 @@ static void SV_OldClientExecuteMove( void ) {
SV_NewClientExecuteMove
==================
*/
-static void SV_NewClientExecuteMove( int c ) {
+static void SV_NewClientExecuteMove(int c)
+{
usercmd_t cmds[MAX_PACKET_FRAMES][MAX_PACKET_USERCMDS];
usercmd_t *lastcmd, *cmd;
int lastframe;
@@ -1123,8 +1152,8 @@ static void SV_NewClientExecuteMove( int c ) {
int i, j, lightlevel;
int net_drop;
- if( moveIssued ) {
- SV_DropClient( sv_client, "multiple clc_move commands in packet" );
+ if (moveIssued) {
+ SV_DropClient(sv_client, "multiple clc_move commands in packet");
return; // someone is trying to cheat...
}
@@ -1133,12 +1162,12 @@ static void SV_NewClientExecuteMove( int c ) {
numDups = c >> SVCMD_BITS;
c &= SVCMD_MASK;
- if( numDups >= MAX_PACKET_FRAMES ) {
- SV_DropClient( sv_client, "too many frames in packet" );
+ if (numDups >= MAX_PACKET_FRAMES) {
+ SV_DropClient(sv_client, "too many frames in packet");
return;
}
- if( c == clc_move_nodelta ) {
+ if (c == clc_move_nodelta) {
lastframe = -1;
} else {
lastframe = MSG_ReadLong();
@@ -1148,56 +1177,56 @@ static void SV_NewClientExecuteMove( int c ) {
// read all cmds
lastcmd = NULL;
- for( i = 0; i <= numDups; i++ ) {
- numCmds[i] = MSG_ReadBits( 5 );
- if( numCmds[i] == -1 ) {
- SV_DropClient( sv_client, "read past end of message" );
+ for (i = 0; i <= numDups; i++) {
+ numCmds[i] = MSG_ReadBits(5);
+ if (numCmds[i] == -1) {
+ SV_DropClient(sv_client, "read past end of message");
return;
}
- if( numCmds[i] >= MAX_PACKET_USERCMDS ) {
- SV_DropClient( sv_client, "too many usercmds in frame" );
+ if (numCmds[i] >= MAX_PACKET_USERCMDS) {
+ SV_DropClient(sv_client, "too many usercmds in frame");
return;
}
- for( j = 0; j < numCmds[i]; j++ ) {
- if( msg_read.readcount > msg_read.cursize ) {
- SV_DropClient( sv_client, "read past end of message" );
+ for (j = 0; j < numCmds[i]; j++) {
+ if (msg_read.readcount > msg_read.cursize) {
+ SV_DropClient(sv_client, "read past end of message");
return;
}
cmd = &cmds[i][j];
- MSG_ReadDeltaUsercmd_Enhanced( lastcmd, cmd, sv_client->version );
+ MSG_ReadDeltaUsercmd_Enhanced(lastcmd, cmd, sv_client->version);
cmd->lightlevel = lightlevel;
lastcmd = cmd;
}
}
- if( sv_client->state != cs_spawned ) {
- SV_SetLastFrame( -1 );
+ if (sv_client->state != cs_spawned) {
+ SV_SetLastFrame(-1);
return;
}
- SV_SetLastFrame( lastframe );
+ SV_SetLastFrame(lastframe);
- if( q_unlikely( !lastcmd ) ) {
+ if (q_unlikely(!lastcmd)) {
return; // should never happen
}
net_drop = sv_client->netchan->dropped;
- if( net_drop > numDups ) {
+ if (net_drop > numDups) {
sv_client->frameflags |= FF_CLIENTPRED;
- }
+ }
- if( net_drop < 20 ) {
+ if (net_drop < 20) {
// run lastcmd multiple times if no backups available
- while( net_drop > numDups ) {
- SV_ClientThink( &sv_client->lastcmd );
+ while (net_drop > numDups) {
+ SV_ClientThink(&sv_client->lastcmd);
net_drop--;
}
// run backup cmds, if any
- while( net_drop > 0 ) {
+ while (net_drop > 0) {
i = numDups - net_drop;
- for( j = 0; j < numCmds[i]; j++ ) {
- SV_ClientThink( &cmds[i][j] );
+ for (j = 0; j < numCmds[i]; j++) {
+ SV_ClientThink(&cmds[i][j]);
}
net_drop--;
}
@@ -1205,10 +1234,10 @@ static void SV_NewClientExecuteMove( int c ) {
}
// run new cmds
- for( j = 0; j < numCmds[numDups]; j++ ) {
- SV_ClientThink( &cmds[numDups][j] );
+ for (j = 0; j < numCmds[numDups]; j++) {
+ SV_ClientThink(&cmds[numDups][j]);
}
-
+
sv_client->lastcmd = *lastcmd;
}
@@ -1219,110 +1248,113 @@ SV_UpdateUserinfo
Ensures that name and ip are properly set.
=================
*/
-static void SV_UpdateUserinfo( void ) {
+static void SV_UpdateUserinfo(void)
+{
char *s;
- if( !sv_client->userinfo[0] ) {
- SV_DropClient( sv_client, "empty userinfo" );
+ if (!sv_client->userinfo[0]) {
+ SV_DropClient(sv_client, "empty userinfo");
return;
}
- if( !Info_Validate( sv_client->userinfo ) ) {
- SV_DropClient( sv_client, "malformed userinfo" );
+ if (!Info_Validate(sv_client->userinfo)) {
+ SV_DropClient(sv_client, "malformed userinfo");
return;
}
// validate name
- s = Info_ValueForKey( sv_client->userinfo, "name" );
- if( COM_IsWhite( s ) ) {
- if( !sv_client->name[0] ) {
- SV_DropClient( sv_client, "malformed name" );
+ s = Info_ValueForKey(sv_client->userinfo, "name");
+ if (COM_IsWhite(s)) {
+ if (!sv_client->name[0]) {
+ SV_DropClient(sv_client, "malformed name");
return;
}
- if( !Info_SetValueForKey( sv_client->userinfo, "name", sv_client->name ) ) {
- SV_DropClient( sv_client, "oversize userinfo" );
+ if (!Info_SetValueForKey(sv_client->userinfo, "name", sv_client->name)) {
+ SV_DropClient(sv_client, "oversize userinfo");
return;
}
- SV_ClientCommand( sv_client, "set name \"%s\"\n", sv_client->name );
+ SV_ClientCommand(sv_client, "set name \"%s\"\n", sv_client->name);
}
// force the IP key/value pair so the game can filter based on ip
- s = NET_AdrToString( &sv_client->netchan->remote_address );
- if( !Info_SetValueForKey( sv_client->userinfo, "ip", s ) ) {
- SV_DropClient( sv_client, "oversize userinfo" );
+ s = NET_AdrToString(&sv_client->netchan->remote_address);
+ if (!Info_SetValueForKey(sv_client->userinfo, "ip", s)) {
+ SV_DropClient(sv_client, "oversize userinfo");
return;
}
- SV_UserinfoChanged( sv_client );
+ SV_UserinfoChanged(sv_client);
}
-static void SV_ParseFullUserinfo( void ) {
+static void SV_ParseFullUserinfo(void)
+{
size_t len;
// malicious users may try sending too many userinfo updates
- if( userinfoUpdateCount >= MAX_PACKET_USERINFOS ) {
- Com_DPrintf( "Too many userinfos from %s\n", sv_client->name );
- MSG_ReadString( NULL, 0 );
+ if (userinfoUpdateCount >= MAX_PACKET_USERINFOS) {
+ Com_DPrintf("Too many userinfos from %s\n", sv_client->name);
+ MSG_ReadString(NULL, 0);
return;
}
- len = MSG_ReadString( sv_client->userinfo, sizeof( sv_client->userinfo ) );
- if( len >= sizeof( sv_client->userinfo ) ) {
- SV_DropClient( sv_client, "oversize userinfo" );
+ len = MSG_ReadString(sv_client->userinfo, sizeof(sv_client->userinfo));
+ if (len >= sizeof(sv_client->userinfo)) {
+ SV_DropClient(sv_client, "oversize userinfo");
return;
}
- Com_DDPrintf( "%s(%s): %s [%d]\n", __func__,
- sv_client->name, sv_client->userinfo, userinfoUpdateCount );
+ Com_DDPrintf("%s(%s): %s [%d]\n", __func__,
+ sv_client->name, sv_client->userinfo, userinfoUpdateCount);
SV_UpdateUserinfo();
userinfoUpdateCount++;
}
-static void SV_ParseDeltaUserinfo( void ) {
+static void SV_ParseDeltaUserinfo(void)
+{
char key[MAX_INFO_KEY], value[MAX_INFO_VALUE];
size_t len;
// malicious users may try sending too many userinfo updates
- if( userinfoUpdateCount >= MAX_PACKET_USERINFOS ) {
- Com_DPrintf( "Too many userinfos from %s\n", sv_client->name );
- MSG_ReadString( NULL, 0 );
- MSG_ReadString( NULL, 0 );
+ if (userinfoUpdateCount >= MAX_PACKET_USERINFOS) {
+ Com_DPrintf("Too many userinfos from %s\n", sv_client->name);
+ MSG_ReadString(NULL, 0);
+ MSG_ReadString(NULL, 0);
return;
}
// optimize by combining multiple delta updates into one (hack)
- while( 1 ) {
- len = MSG_ReadString( key, sizeof( key ) );
- if( len >= sizeof( key ) ) {
- SV_DropClient( sv_client, "oversize delta key" );
+ while (1) {
+ len = MSG_ReadString(key, sizeof(key));
+ if (len >= sizeof(key)) {
+ SV_DropClient(sv_client, "oversize delta key");
return;
}
- len = MSG_ReadString( value, sizeof( value ) );
- if( len >= sizeof( value ) ) {
- SV_DropClient( sv_client, "oversize delta value" );
+ len = MSG_ReadString(value, sizeof(value));
+ if (len >= sizeof(value)) {
+ SV_DropClient(sv_client, "oversize delta value");
return;
}
- if( userinfoUpdateCount < MAX_PACKET_USERINFOS ) {
- if( !Info_SetValueForKey( sv_client->userinfo, key, value ) ) {
- SV_DropClient( sv_client, "malformed userinfo" );
+ if (userinfoUpdateCount < MAX_PACKET_USERINFOS) {
+ if (!Info_SetValueForKey(sv_client->userinfo, key, value)) {
+ SV_DropClient(sv_client, "malformed userinfo");
return;
}
- Com_DDPrintf( "%s(%s): %s %s [%d]\n", __func__,
- sv_client->name, key, value, userinfoUpdateCount );
+ Com_DDPrintf("%s(%s): %s %s [%d]\n", __func__,
+ sv_client->name, key, value, userinfoUpdateCount);
userinfoUpdateCount++;
} else {
- Com_DPrintf( "Too many userinfos from %s\n", sv_client->name );
+ Com_DPrintf("Too many userinfos from %s\n", sv_client->name);
}
- if( msg_read.readcount >= msg_read.cursize )
+ if (msg_read.readcount >= msg_read.cursize)
break; // end of message
- if( msg_read.data[msg_read.readcount] != clc_userinfo_delta )
+ if (msg_read.data[msg_read.readcount] != clc_userinfo_delta)
break; // not delta userinfo
msg_read.readcount++;
@@ -1332,87 +1364,91 @@ static void SV_ParseDeltaUserinfo( void ) {
}
#if USE_FPS
-static void align_key_frames( void ) {
+static void align_key_frames(void)
+{
int framediv = sv.framediv / sv_client->framediv;
int framenum = sv.framenum / sv_client->framediv;
int frameofs = framenum % framediv;
- int newnum = frameofs + Q_align( sv_client->framenum, framediv );
+ int newnum = frameofs + Q_align(sv_client->framenum, framediv);
- Com_DPrintf( "[%d] align %d --> %d (num = %d, div = %d, ofs = %d)\n",
- sv.framenum, sv_client->framenum, newnum, framenum, framediv, frameofs );
+ Com_DPrintf("[%d] align %d --> %d (num = %d, div = %d, ofs = %d)\n",
+ sv.framenum, sv_client->framenum, newnum, framenum, framediv, frameofs);
sv_client->framenum = newnum;
}
-static void set_client_fps( int value ) {
+static void set_client_fps(int value)
+{
int framediv, framerate;
// 0 means highest
- if( !value )
+ if (!value)
value = sv.framerate;
framediv = value / BASE_FRAMERATE;
- clamp( framediv, 1, MAX_FRAMEDIV );
+ clamp(framediv, 1, MAX_FRAMEDIV);
- framediv = sv.framediv / Q_gcd( sv.framediv, framediv );
+ framediv = sv.framediv / Q_gcd(sv.framediv, framediv);
framerate = sv.framerate / framediv;
- Com_DPrintf( "[%d] client div=%d, server div=%d, rate=%d\n",
- sv.framenum, framediv, sv.framediv, framerate );
+ Com_DPrintf("[%d] client div=%d, server div=%d, rate=%d\n",
+ sv.framenum, framediv, sv.framediv, framerate);
sv_client->framediv = framediv;
- if( sv_client->state == cs_spawned )
+ if (sv_client->state == cs_spawned)
align_key_frames();
// save for status inspection
sv_client->settings[CLS_FPS] = framerate;
- MSG_WriteByte( svc_setting );
- MSG_WriteLong( SVS_FPS );
- MSG_WriteLong( framerate );
- SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_setting);
+ MSG_WriteLong(SVS_FPS);
+ MSG_WriteLong(framerate);
+ SV_ClientAddMessage(sv_client, MSG_RELIABLE | MSG_CLEAR);
}
#endif
-static void SV_ParseClientSetting( void ) {
+static void SV_ParseClientSetting(void)
+{
int idx, value;
idx = MSG_ReadShort();
value = MSG_ReadShort();
- Com_DDPrintf( "%s(%s): [%d] = %d\n", __func__, sv_client->name, idx, value );
+ Com_DDPrintf("%s(%s): [%d] = %d\n", __func__, sv_client->name, idx, value);
- if( idx < 0 || idx >= CLS_MAX )
+ if (idx < 0 || idx >= CLS_MAX)
return;
sv_client->settings[idx] = value;
#if USE_FPS
- if( idx == CLS_FPS && sv_client->protocol == PROTOCOL_VERSION_Q2PRO )
- set_client_fps( value );
+ if (idx == CLS_FPS && sv_client->protocol == PROTOCOL_VERSION_Q2PRO)
+ set_client_fps(value);
#endif
}
-static void SV_ParseClientCommand( void ) {
+static void SV_ParseClientCommand(void)
+{
char buffer[MAX_STRING_CHARS];
size_t len;
- len = MSG_ReadString( buffer, sizeof( buffer ) );
- if( len >= sizeof( buffer ) ) {
- SV_DropClient( sv_client, "oversize stringcmd" );
+ len = MSG_ReadString(buffer, sizeof(buffer));
+ if (len >= sizeof(buffer)) {
+ SV_DropClient(sv_client, "oversize stringcmd");
return;
}
// malicious users may try using too many string commands
- if( stringCmdCount >= MAX_PACKET_STRINGCMDS ) {
- Com_DPrintf( "Too many stringcmds from %s\n", sv_client->name );
+ if (stringCmdCount >= MAX_PACKET_STRINGCMDS) {
+ Com_DPrintf("Too many stringcmds from %s\n", sv_client->name);
return;
}
- Com_DDPrintf( "%s(%s): %s\n", __func__, sv_client->name, buffer );
+ Com_DDPrintf("%s(%s): %s\n", __func__, sv_client->name, buffer);
- SV_ExecuteUserCommand( buffer );
+ SV_ExecuteUserCommand(buffer);
stringCmdCount++;
}
@@ -1423,7 +1459,8 @@ SV_ExecuteClientMessage
The current net_message is parsed for the given client
===================
*/
-void SV_ExecuteClientMessage( client_t *client ) {
+void SV_ExecuteClientMessage(client_t *client)
+{
int c;
X86_PUSH_FPCW;
@@ -1437,22 +1474,22 @@ void SV_ExecuteClientMessage( client_t *client ) {
stringCmdCount = 0;
userinfoUpdateCount = 0;
- while( 1 ) {
- if( msg_read.readcount > msg_read.cursize ) {
- SV_DropClient( client, "read past end of message" );
+ while (1) {
+ if (msg_read.readcount > msg_read.cursize) {
+ SV_DropClient(client, "read past end of message");
break;
- }
+ }
c = MSG_ReadByte();
- if( c == -1 )
+ if (c == -1)
break;
-
- switch( c & SVCMD_MASK ) {
+
+ switch (c & SVCMD_MASK) {
default:
- badbyte:
- SV_DropClient( client, "unknown command byte" );
+badbyte:
+ SV_DropClient(client, "unknown command byte");
break;
-
+
case clc_nop:
break;
@@ -1469,7 +1506,7 @@ void SV_ExecuteClientMessage( client_t *client ) {
break;
case clc_setting:
- if( client->protocol < PROTOCOL_VERSION_R1Q2 )
+ if (client->protocol < PROTOCOL_VERSION_R1Q2)
goto badbyte;
SV_ParseClientSetting();
@@ -1477,21 +1514,21 @@ void SV_ExecuteClientMessage( client_t *client ) {
case clc_move_nodelta:
case clc_move_batched:
- if( client->protocol != PROTOCOL_VERSION_Q2PRO )
+ if (client->protocol != PROTOCOL_VERSION_Q2PRO)
goto badbyte;
- SV_NewClientExecuteMove( c );
+ SV_NewClientExecuteMove(c);
break;
case clc_userinfo_delta:
- if( client->protocol != PROTOCOL_VERSION_Q2PRO )
+ if (client->protocol != PROTOCOL_VERSION_Q2PRO)
goto badbyte;
SV_ParseDeltaUserinfo();
break;
}
- if( client->state <= cs_zombie )
+ if (client->state <= cs_zombie)
break; // disconnect command
}
diff --git a/src/sv_world.c b/src/sv_world.c
index 9f7e767..47aed67 100644
--- a/src/sv_world.c
+++ b/src/sv_world.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -56,7 +56,8 @@ SV_CreateAreaNode
Builds a uniformly subdivided tree for the given world size
===============
*/
-static areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs) {
+static areanode_t *SV_CreateAreaNode(int depth, vec3_t mins, vec3_t maxs)
+{
areanode_t *anode;
vec3_t size;
vec3_t mins1, maxs1, mins2, maxs2;
@@ -64,32 +65,31 @@ static areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs) {
anode = &sv_areanodes[sv_numareanodes];
sv_numareanodes++;
- List_Init (&anode->trigger_edicts);
- List_Init (&anode->solid_edicts);
-
- if (depth == AREA_DEPTH)
- {
+ List_Init(&anode->trigger_edicts);
+ List_Init(&anode->solid_edicts);
+
+ if (depth == AREA_DEPTH) {
anode->axis = -1;
anode->children[0] = anode->children[1] = NULL;
return anode;
}
-
- VectorSubtract (maxs, mins, size);
+
+ VectorSubtract(maxs, mins, size);
if (size[0] > size[1])
anode->axis = 0;
else
anode->axis = 1;
-
+
anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
- VectorCopy (mins, mins1);
- VectorCopy (mins, mins2);
- VectorCopy (maxs, maxs1);
- VectorCopy (maxs, maxs2);
-
+ VectorCopy(mins, mins1);
+ VectorCopy(mins, mins2);
+ VectorCopy(maxs, maxs1);
+ VectorCopy(maxs, maxs2);
+
maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
-
- anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
- anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
+
+ anode->children[0] = SV_CreateAreaNode(depth + 1, mins2, maxs2);
+ anode->children[1] = SV_CreateAreaNode(depth + 1, mins1, maxs1);
return anode;
}
@@ -100,22 +100,23 @@ SV_ClearWorld
===============
*/
-void SV_ClearWorld( void ) {
+void SV_ClearWorld(void)
+{
mmodel_t *cm;
edict_t *ent;
int i;
- memset( sv_areanodes, 0, sizeof( sv_areanodes ) );
+ memset(sv_areanodes, 0, sizeof(sv_areanodes));
sv_numareanodes = 0;
- if( sv.cm.cache ) {
+ if (sv.cm.cache) {
cm = &sv.cm.cache->models[0];
- SV_CreateAreaNode( 0, cm->mins, cm->maxs );
+ SV_CreateAreaNode(0, cm->mins, cm->maxs);
}
// make sure all entities are unlinked
- for( i = 0; i < ge->max_edicts; i++ ) {
- ent = EDICT_NUM( i );
+ for (i = 0; i < ge->max_edicts; i++) {
+ ent = EDICT_NUM(i);
ent->area.prev = ent->area.next = NULL;
}
}
@@ -129,7 +130,8 @@ General purpose routine shared between game DLL and MVD code.
Links entity to PVS leafs.
===============
*/
-void SV_LinkEdict( cm_t *cm, edict_t *ent ) {
+void SV_LinkEdict(cm_t *cm, edict_t *ent)
+{
mleaf_t *leafs[MAX_TOTAL_ENT_LEAFS];
int clusters[MAX_TOTAL_ENT_LEAFS];
int num_leafs;
@@ -138,34 +140,32 @@ void SV_LinkEdict( cm_t *cm, edict_t *ent ) {
mnode_t *topnode;
// set the size
- VectorSubtract (ent->maxs, ent->mins, ent->size);
+ VectorSubtract(ent->maxs, ent->mins, ent->size);
// set the abs box
if (ent->solid == SOLID_BSP &&
- (ent->s.angles[0] || ent->s.angles[1] || ent->s.angles[2]) )
- { // expand for rotation
- float max, v;
- int i;
+ (ent->s.angles[0] || ent->s.angles[1] || ent->s.angles[2])) {
+ // expand for rotation
+ float max, v;
+ int i;
max = 0;
- for (i=0 ; i<3 ; i++) {
- v = Q_fabs( ent->mins[i]);
+ for (i = 0; i < 3; i++) {
+ v = Q_fabs(ent->mins[i]);
if (v > max)
max = v;
- v = Q_fabs( ent->maxs[i]);
+ v = Q_fabs(ent->maxs[i]);
if (v > max)
max = v;
}
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
ent->absmin[i] = ent->s.origin[i] - max;
ent->absmax[i] = ent->s.origin[i] + max;
}
- }
- else
- { // normal
- VectorAdd (ent->s.origin, ent->mins, ent->absmin);
- VectorAdd (ent->s.origin, ent->maxs, ent->absmax);
+ } else {
+ // normal
+ VectorAdd(ent->s.origin, ent->mins, ent->absmin);
+ VectorAdd(ent->s.origin, ent->maxs, ent->absmax);
}
// because movement is clipped an epsilon away from an actual edge,
@@ -183,52 +183,44 @@ void SV_LinkEdict( cm_t *cm, edict_t *ent ) {
ent->areanum2 = 0;
//get all leafs, including solids
- num_leafs = CM_BoxLeafs( cm, ent->absmin, ent->absmax,
- leafs, MAX_TOTAL_ENT_LEAFS, &topnode);
+ num_leafs = CM_BoxLeafs(cm, ent->absmin, ent->absmax,
+ leafs, MAX_TOTAL_ENT_LEAFS, &topnode);
// set areas
- for (i=0 ; i<num_leafs ; i++)
- {
- clusters[i] = CM_LeafCluster (leafs[i]);
- area = CM_LeafArea (leafs[i]);
- if (area)
- { // doors may legally straggle two areas,
+ for (i = 0; i < num_leafs; i++) {
+ clusters[i] = CM_LeafCluster(leafs[i]);
+ area = CM_LeafArea(leafs[i]);
+ if (area) {
+ // doors may legally straggle two areas,
// but nothing should evern need more than that
- if (ent->areanum && ent->areanum != area)
- {
- if (ent->areanum2 && ent->areanum2 != area && sv.state == ss_loading)
- {
- Com_DPrintf ("Object touching 3 areas at %f %f %f\n",
- ent->absmin[0], ent->absmin[1], ent->absmin[2]);
+ if (ent->areanum && ent->areanum != area) {
+ if (ent->areanum2 && ent->areanum2 != area && sv.state == ss_loading) {
+ Com_DPrintf("Object touching 3 areas at %f %f %f\n",
+ ent->absmin[0], ent->absmin[1], ent->absmin[2]);
}
ent->areanum2 = area;
- }
- else
+ } else
ent->areanum = area;
}
}
- if (num_leafs >= MAX_TOTAL_ENT_LEAFS)
- { // assume we missed some leafs, and mark by headnode
+ if (num_leafs >= MAX_TOTAL_ENT_LEAFS) {
+ // assume we missed some leafs, and mark by headnode
ent->num_clusters = -1;
- ent->headnode = CM_NumNode( cm, topnode );
- }
- else
- {
+ ent->headnode = CM_NumNode(cm, topnode);
+ } else {
ent->num_clusters = 0;
- for (i=0 ; i<num_leafs ; i++)
- {
+ for (i = 0; i < num_leafs; i++) {
if (clusters[i] == -1)
continue; // not a visible leaf
- for (j=0 ; j<i ; j++)
+ for (j = 0; j < i; j++)
if (clusters[j] == clusters[i])
break;
- if (j == i)
- {
- if (ent->num_clusters == MAX_ENT_CLUSTERS)
- { // assume we missed some leafs, and mark by headnode
+ if (j == i) {
+ if (ent->num_clusters == MAX_ENT_CLUSTERS) {
+ // assume we missed some leafs, and mark by headnode
ent->num_clusters = -1;
- ent->headnode = CM_NumNode( cm, topnode );
+ ent->headnode = CM_NumNode(cm, topnode);
break;
}
@@ -238,14 +230,16 @@ void SV_LinkEdict( cm_t *cm, edict_t *ent ) {
}
}
-void PF_UnlinkEdict (edict_t *ent) {
+void PF_UnlinkEdict(edict_t *ent)
+{
if (!ent->area.prev)
return; // not linked in anywhere
- List_Remove (&ent->area);
+ List_Remove(&ent->area);
ent->area.prev = ent->area.next = NULL;
}
-void PF_LinkEdict (edict_t *ent) {
+void PF_LinkEdict(edict_t *ent)
+{
areanode_t *node;
server_entity_t *sent;
int entnum;
@@ -254,32 +248,32 @@ void PF_LinkEdict (edict_t *ent) {
#endif
if (ent->area.prev)
- PF_UnlinkEdict (ent); // unlink from old position
-
+ PF_UnlinkEdict(ent); // unlink from old position
+
if (ent == ge->edicts)
return; // don't add the world
if (!ent->inuse) {
- Com_DPrintf( "%s: entity %d is not in use\n", __func__, NUM_FOR_EDICT( ent ) );
+ Com_DPrintf("%s: entity %d is not in use\n", __func__, NUM_FOR_EDICT(ent));
return;
}
- if( !sv.cm.cache ) {
+ if (!sv.cm.cache) {
return;
}
- entnum = NUM_FOR_EDICT( ent );
+ entnum = NUM_FOR_EDICT(ent);
sent = &sv.entities[entnum];
// encode the size into the entity_state for client prediction
- switch( ent->solid ) {
+ switch (ent->solid) {
case SOLID_BBOX:
- if( ( ent->svflags & SVF_DEADMONSTER ) || VectorCompare( ent->mins, ent->maxs ) ) {
+ if ((ent->svflags & SVF_DEADMONSTER) || VectorCompare(ent->mins, ent->maxs)) {
ent->s.solid = 0;
sent->solid32 = 0;
} else {
- ent->s.solid = MSG_PackSolid16( ent->mins, ent->maxs );
- sent->solid32 = MSG_PackSolid32( ent->mins, ent->maxs );
+ ent->s.solid = MSG_PackSolid16(ent->mins, ent->maxs);
+ sent->solid32 = MSG_PackSolid32(ent->mins, ent->maxs);
}
break;
case SOLID_BSP:
@@ -292,13 +286,13 @@ void PF_LinkEdict (edict_t *ent) {
break;
}
- SV_LinkEdict( &sv.cm, ent );
+ SV_LinkEdict(&sv.cm, ent);
// if first time, make sure old_origin is valid
if (!ent->linkcount) {
- VectorCopy (ent->s.origin, ent->s.old_origin);
+ VectorCopy(ent->s.origin, ent->s.old_origin);
#if USE_FPS
- VectorCopy( ent->s.origin, sent->create_origin );
+ VectorCopy(ent->s.origin, sent->create_origin);
sent->create_framenum = sv.framenum;
#endif
}
@@ -307,7 +301,7 @@ void PF_LinkEdict (edict_t *ent) {
#if USE_FPS
// save origin for later recovery
i = sv.framenum & ENT_HISTORY_MASK;
- VectorCopy( ent->s.origin, sent->history[i].origin );
+ VectorCopy(ent->s.origin, sent->history[i].origin);
sent->history[i].framenum = sv.framenum;
#endif
@@ -316,8 +310,7 @@ void PF_LinkEdict (edict_t *ent) {
// find the first node that the ent's box crosses
node = sv_areanodes;
- while (1)
- {
+ while (1) {
if (node->axis == -1)
break;
if (ent->absmin[node->axis] > node->dist)
@@ -327,12 +320,12 @@ void PF_LinkEdict (edict_t *ent) {
else
break; // crosses the node
}
-
- // link it in
+
+ // link it in
if (ent->solid == SOLID_TRIGGER)
- List_Append( &node->trigger_edicts, &ent->area );
+ List_Append(&node->trigger_edicts, &ent->area);
else
- List_Append( &node->solid_edicts, &ent->area );
+ List_Append(&node->solid_edicts, &ent->area);
}
@@ -342,7 +335,8 @@ SV_AreaEdicts_r
====================
*/
-static void SV_AreaEdicts_r (areanode_t *node) {
+static void SV_AreaEdicts_r(areanode_t *node)
+{
list_t *start;
edict_t *check;
@@ -352,34 +346,34 @@ static void SV_AreaEdicts_r (areanode_t *node) {
else
start = &node->trigger_edicts;
- LIST_FOR_EACH( edict_t, check, start, area ) {
+ LIST_FOR_EACH(edict_t, check, start, area) {
if (check->solid == SOLID_NOT)
continue; // deactivated
if (check->absmin[0] > area_maxs[0]
- || check->absmin[1] > area_maxs[1]
- || check->absmin[2] > area_maxs[2]
- || check->absmax[0] < area_mins[0]
- || check->absmax[1] < area_mins[1]
- || check->absmax[2] < area_mins[2])
+ || check->absmin[1] > area_maxs[1]
+ || check->absmin[2] > area_maxs[2]
+ || check->absmax[0] < area_mins[0]
+ || check->absmax[1] < area_mins[1]
+ || check->absmax[2] < area_mins[2])
continue; // not touching
if (area_count == area_maxcount) {
- Com_WPrintf ("SV_AreaEdicts: MAXCOUNT\n");
+ Com_WPrintf("SV_AreaEdicts: MAXCOUNT\n");
return;
}
area_list[area_count] = check;
area_count++;
}
-
+
if (node->axis == -1)
return; // terminal node
// recurse down both sides
- if ( area_maxs[node->axis] > node->dist )
- SV_AreaEdicts_r ( node->children[0] );
- if ( area_mins[node->axis] < node->dist )
- SV_AreaEdicts_r ( node->children[1] );
+ if (area_maxs[node->axis] > node->dist)
+ SV_AreaEdicts_r(node->children[0]);
+ if (area_mins[node->axis] < node->dist)
+ SV_AreaEdicts_r(node->children[1]);
}
/*
@@ -387,8 +381,8 @@ static void SV_AreaEdicts_r (areanode_t *node) {
SV_AreaEdicts
================
*/
-int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list,
- int maxcount, int areatype)
+int SV_AreaEdicts(vec3_t mins, vec3_t maxs, edict_t **list,
+ int maxcount, int areatype)
{
area_mins = mins;
area_maxs = maxs;
@@ -397,7 +391,7 @@ int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list,
area_maxcount = maxcount;
area_type = areatype;
- SV_AreaEdicts_r (sv_areanodes);
+ SV_AreaEdicts_r(sv_areanodes);
return area_count;
}
@@ -413,16 +407,17 @@ Returns a headnode that can be used for testing or clipping an
object of mins/maxs size.
================
*/
-static mnode_t *SV_HullForEntity( edict_t *ent ) {
+static mnode_t *SV_HullForEntity(edict_t *ent)
+{
mmodel_t *model;
- if( ent->solid == SOLID_BSP ) {
+ if (ent->solid == SOLID_BSP) {
int index = ent->s.modelindex - 1;
// explicit hulls in the BSP model
- if( index <= 0 || index >= sv.cm.cache->nummodels ) {
- Com_Error( ERR_DROP, "%s: inline model %d out of range",
- __func__, index );
+ if (index <= 0 || index >= sv.cm.cache->nummodels) {
+ Com_Error(ERR_DROP, "%s: inline model %d out of range",
+ __func__, index);
}
model = &sv.cm.cache->models[index];
@@ -430,7 +425,7 @@ static mnode_t *SV_HullForEntity( edict_t *ent ) {
}
// create a temp hull from bounding box sizes
- return CM_HeadnodeForBox( ent->mins, ent->maxs );
+ return CM_HeadnodeForBox(ent->mins, ent->maxs);
}
/*
@@ -438,32 +433,31 @@ static mnode_t *SV_HullForEntity( edict_t *ent ) {
SV_PointContents
=============
*/
-int SV_PointContents (vec3_t p)
+int SV_PointContents(vec3_t p)
{
edict_t *touch[MAX_EDICTS], *hit;
int i, num;
int contents, c2;
mnode_t *headnode;
- if( !sv.cm.cache ) {
- Com_Error( ERR_DROP, "%s: no map loaded", __func__ );
+ if (!sv.cm.cache) {
+ Com_Error(ERR_DROP, "%s: no map loaded", __func__);
}
// get base contents from world
- contents = CM_PointContents (p, sv.cm.cache->nodes);
+ contents = CM_PointContents(p, sv.cm.cache->nodes);
// or in contents from all the other entities
- num = SV_AreaEdicts (p, p, touch, MAX_EDICTS, AREA_SOLID);
+ num = SV_AreaEdicts(p, p, touch, MAX_EDICTS, AREA_SOLID);
- for (i=0 ; i<num ; i++)
- {
+ for (i = 0; i < num; i++) {
hit = touch[i];
// might intersect, so do an exact clip
- headnode = SV_HullForEntity (hit);
+ headnode = SV_HullForEntity(hit);
- c2 = CM_TransformedPointContents (p, headnode,
- hit->s.origin, hit->s.angles);
+ c2 = CM_TransformedPointContents(p, headnode,
+ hit->s.origin, hit->s.angles);
contents |= c2;
}
@@ -488,19 +482,19 @@ SV_ClipMoveToEntities
====================
*/
-static void SV_ClipMoveToEntities( moveclip_t *clip ) {
+static void SV_ClipMoveToEntities(moveclip_t *clip)
+{
int i, num;
edict_t *touchlist[MAX_EDICTS], *touch;
trace_t trace;
mnode_t *headnode;
- num = SV_AreaEdicts (clip->boxmins, clip->boxmaxs, touchlist
- , MAX_EDICTS, AREA_SOLID);
+ num = SV_AreaEdicts(clip->boxmins, clip->boxmaxs, touchlist
+ , MAX_EDICTS, AREA_SOLID);
// be careful, it is possible to have an entity in this
// list removed before we get to it (killtriggered)
- for (i=0 ; i<num ; i++)
- {
+ for (i = 0; i < num; i++) {
touch = touchlist[i];
if (touch->solid == SOLID_NOT)
continue;
@@ -508,26 +502,25 @@ static void SV_ClipMoveToEntities( moveclip_t *clip ) {
continue;
if (clip->trace->allsolid)
return;
- if (clip->passedict)
- {
- if (touch->owner == clip->passedict)
+ if (clip->passedict) {
+ if (touch->owner == clip->passedict)
continue; // don't clip against own missiles
if (clip->passedict->owner == touch)
continue; // don't clip against owner
}
- if ( !(clip->contentmask & CONTENTS_DEADMONSTER)
- && (touch->svflags & SVF_DEADMONSTER) )
- continue;
+ if (!(clip->contentmask & CONTENTS_DEADMONSTER)
+ && (touch->svflags & SVF_DEADMONSTER))
+ continue;
// might intersect, so do an exact clip
- headnode = SV_HullForEntity (touch);
+ headnode = SV_HullForEntity(touch);
- CM_TransformedBoxTrace (&trace, clip->start, clip->end,
- clip->mins, clip->maxs, headnode, clip->contentmask,
- touch->s.origin, touch->s.angles);
+ CM_TransformedBoxTrace(&trace, clip->start, clip->end,
+ clip->mins, clip->maxs, headnode, clip->contentmask,
+ touch->s.origin, touch->s.angles);
- CM_ClipEntity( clip->trace, &trace, touch );
+ CM_ClipEntity(clip->trace, &trace, touch);
}
}
@@ -537,10 +530,11 @@ static void SV_ClipMoveToEntities( moveclip_t *clip ) {
SV_TraceBounds
==================
*/
-static void SV_TraceBounds (moveclip_t *clip) {
+static void SV_TraceBounds(moveclip_t *clip)
+{
int i;
-
- for (i=0 ; i<3 ; i++) {
+
+ for (i = 0; i < 3; i++) {
if (clip->end[i] > clip->start[i]) {
clip->boxmins[i] = clip->start[i] + clip->mins[i] - 1;
clip->boxmaxs[i] = clip->end[i] + clip->maxs[i] + 1;
@@ -560,26 +554,26 @@ Moves the given mins/maxs volume through the world from start to end.
Passedict and edicts owned by passedict are explicitly not checked.
==================
*/
-trace_t *SV_Trace( trace_t *trace,
- vec3_t start,
- vec3_t mins,
- vec3_t maxs,
- vec3_t end,
- edict_t *passedict,
- int contentmask )
+trace_t *SV_Trace(trace_t *trace,
+ vec3_t start,
+ vec3_t mins,
+ vec3_t maxs,
+ vec3_t end,
+ edict_t *passedict,
+ int contentmask)
{
moveclip_t clip;
- if( !sv.cm.cache ) {
- Com_Error( ERR_DROP, "%s: no map loaded", __func__ );
+ if (!sv.cm.cache) {
+ Com_Error(ERR_DROP, "%s: no map loaded", __func__);
}
- if( ++sv.tracecount > 10000 ) {
- Com_EPrintf( "%s: game DLL caught in infinite loop!\n", __func__ );
- memset( trace, 0, sizeof( *trace ) );
+ if (++sv.tracecount > 10000) {
+ Com_EPrintf("%s: game DLL caught in infinite loop!\n", __func__);
+ memset(trace, 0, sizeof(*trace));
trace->fraction = 1;
trace->ent = ge->edicts;
- VectorCopy( end, trace->endpos );
+ VectorCopy(end, trace->endpos);
sv.tracecount = 0;
return trace;
}
@@ -590,14 +584,14 @@ trace_t *SV_Trace( trace_t *trace,
maxs = vec3_origin;
// clip to world
- CM_BoxTrace( trace, start, end, mins, maxs,
- sv.cm.cache->nodes, contentmask );
+ CM_BoxTrace(trace, start, end, mins, maxs,
+ sv.cm.cache->nodes, contentmask);
trace->ent = ge->edicts;
if (trace->fraction == 0) {
return trace; // blocked by the world
}
- memset( &clip, 0, sizeof( clip ) );
+ memset(&clip, 0, sizeof(clip));
clip.trace = trace;
clip.contentmask = contentmask;
clip.start = start;
@@ -605,12 +599,12 @@ trace_t *SV_Trace( trace_t *trace,
clip.mins = mins;
clip.maxs = maxs;
clip.passedict = passedict;
-
+
// create the bounding box of the entire move
- SV_TraceBounds( &clip );
+ SV_TraceBounds(&clip);
// clip to other solid entities
- SV_ClipMoveToEntities( &clip );
+ SV_ClipMoveToEntities(&clip);
return trace;
}
@@ -622,10 +616,11 @@ SV_Trace_Native
Variant of SV_Trace for native game ABI
==================
*/
-trace_t SV_Trace_Native (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask) {
+trace_t SV_Trace_Native(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask)
+{
trace_t trace;
- SV_Trace( &trace, start, mins, maxs, end, passedict, contentmask );
+ SV_Trace(&trace, start, mins, maxs, end, passedict, contentmask);
return trace;
}
diff --git a/src/sw_aclip.c b/src/sw_aclip.c
index d3c0aae..45dbfa2 100644
--- a/src/sw_aclip.c
+++ b/src/sw_aclip.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static finalvert_t fv[2][8];
-void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv);
+void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv);
/*
@@ -33,7 +33,7 @@ R_Alias_clip_z
pfv0 is the unclipped vertex, pfv1 is the z-clipped vertex
================
*/
-static void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
+static void R_Alias_clip_z(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@@ -48,162 +48,148 @@ static void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *o
out->t = pfv0->t + (pfv1->t - pfv0->t) * scale;
out->l = pfv0->l + (pfv1->l - pfv0->l) * scale;
- R_AliasProjectAndClipTestFinalVert (out);
+ R_AliasProjectAndClipTestFinalVert(out);
}
#if USE_ASM
-void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1,
- finalvert_t *out);
-void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
- finalvert_t *out);
-void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1,
- finalvert_t *out);
-void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1,
- finalvert_t *out);
+void R_Alias_clip_top(finalvert_t *pfv0, finalvert_t *pfv1,
+ finalvert_t *out);
+void R_Alias_clip_bottom(finalvert_t *pfv0, finalvert_t *pfv1,
+ finalvert_t *out);
+void R_Alias_clip_left(finalvert_t *pfv0, finalvert_t *pfv1,
+ finalvert_t *out);
+void R_Alias_clip_right(finalvert_t *pfv0, finalvert_t *pfv1,
+ finalvert_t *out);
#else
-static void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
+static void R_Alias_clip_left(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
- if (pfv0->v >= pfv1->v )
- {
+ if (pfv0->v >= pfv1->v) {
scale = (float)(r_refdef.aliasvrect.x - pfv0->u) /
(pfv1->u - pfv0->u);
- out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
- out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
- out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
- out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
- out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
- out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
- }
- else
- {
+ out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
+ out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
+ out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
+ out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
+ out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
+ out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
+ } else {
scale = (float)(r_refdef.aliasvrect.x - pfv1->u) /
(pfv0->u - pfv1->u);
- out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
- out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
- out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
- out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
- out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
- out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
+ out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
+ out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
+ out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
+ out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
+ out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
+ out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
-static void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
+static void R_Alias_clip_right(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
- if ( pfv0->v >= pfv1->v )
- {
- scale = (float)(r_refdef.aliasvrectright - pfv0->u ) /
- (pfv1->u - pfv0->u );
- out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
- out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
- out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
- out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
- out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
- out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
- }
- else
- {
- scale = (float)(r_refdef.aliasvrectright - pfv1->u ) /
- (pfv0->u - pfv1->u );
- out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
- out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
- out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
- out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
- out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
- out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
+ if (pfv0->v >= pfv1->v) {
+ scale = (float)(r_refdef.aliasvrectright - pfv0->u) /
+ (pfv1->u - pfv0->u);
+ out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
+ out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
+ out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
+ out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
+ out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
+ out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
+ } else {
+ scale = (float)(r_refdef.aliasvrectright - pfv1->u) /
+ (pfv0->u - pfv1->u);
+ out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
+ out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
+ out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
+ out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
+ out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
+ out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
-static void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
+static void R_Alias_clip_top(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
- if (pfv0->v >= pfv1->v)
- {
+ if (pfv0->v >= pfv1->v) {
scale = (float)(r_refdef.aliasvrect.y - pfv0->v) /
(pfv1->v - pfv0->v);
- out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
- out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
- out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
- out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
- out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
- out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
- }
- else
- {
+ out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
+ out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
+ out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
+ out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
+ out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
+ out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
+ } else {
scale = (float)(r_refdef.aliasvrect.y - pfv1->v) /
(pfv0->v - pfv1->v);
- out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
- out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
- out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
- out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
- out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
- out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
+ out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
+ out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
+ out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
+ out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
+ out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
+ out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
-static void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
- finalvert_t *out)
+static void R_Alias_clip_bottom(finalvert_t *pfv0, finalvert_t *pfv1,
+ finalvert_t *out)
{
float scale;
- if (pfv0->v >= pfv1->v)
- {
+ if (pfv0->v >= pfv1->v) {
scale = (float)(r_refdef.aliasvrectbottom - pfv0->v) /
(pfv1->v - pfv0->v);
- out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
- out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
- out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
- out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
- out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
- out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
- }
- else
- {
+ out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
+ out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
+ out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
+ out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
+ out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
+ out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
+ } else {
scale = (float)(r_refdef.aliasvrectbottom - pfv1->v) /
(pfv0->v - pfv1->v);
- out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
- out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
- out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
- out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
- out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
- out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
+ out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
+ out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
+ out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
+ out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
+ out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
+ out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
#endif
-static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
- void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) )
+static int R_AliasClip(finalvert_t *in, finalvert_t *out, int flag, int count,
+ void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out))
{
- int i,j,k;
+ int i, j, k;
int flags, oldflags;
-
- j = count-1;
+
+ j = count - 1;
k = 0;
- for (i=0 ; i<count ; j = i, i++)
- {
+ for (i = 0; i < count; j = i, i++) {
oldflags = in[j].flags & flag;
flags = in[i].flags & flag;
if (flags && oldflags)
continue;
- if (oldflags ^ flags)
- {
- clip (&in[j], &in[i], &out[k]);
+ if (oldflags ^ flags) {
+ clip(&in[j], &in[i], &out[k]);
out[k].flags = 0;
if (out[k].u < r_refdef.aliasvrect.x)
out[k].flags |= ALIAS_LEFT_CLIP;
@@ -212,16 +198,15 @@ static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
if (out[k].u > r_refdef.aliasvrectright)
out[k].flags |= ALIAS_RIGHT_CLIP;
if (out[k].v > r_refdef.aliasvrectbottom)
- out[k].flags |= ALIAS_BOTTOM_CLIP;
+ out[k].flags |= ALIAS_BOTTOM_CLIP;
k++;
}
- if (!flags)
- {
+ if (!flags) {
out[k] = in[i];
k++;
}
}
-
+
return k;
}
@@ -231,7 +216,7 @@ static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
R_AliasClipTriangle
================
*/
-void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2)
+void R_AliasClipTriangle(finalvert_t *index0, finalvert_t *index1, finalvert_t *index2)
{
int i, k, pingpong;
unsigned clipflags;
@@ -244,63 +229,55 @@ void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t
// clip
clipflags = fv[0][0].flags | fv[0][1].flags | fv[0][2].flags;
- if (clipflags & ALIAS_Z_CLIP)
- {
- k = R_AliasClip (fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z);
+ if (clipflags & ALIAS_Z_CLIP) {
+ k = R_AliasClip(fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z);
if (k == 0)
return;
pingpong = 1;
clipflags = fv[1][0].flags | fv[1][1].flags | fv[1][2].flags;
- }
- else
- {
+ } else {
pingpong = 0;
k = 3;
}
- if (clipflags & ALIAS_LEFT_CLIP)
- {
- k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
- ALIAS_LEFT_CLIP, k, R_Alias_clip_left);
+ if (clipflags & ALIAS_LEFT_CLIP) {
+ k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
+ ALIAS_LEFT_CLIP, k, R_Alias_clip_left);
if (k == 0)
return;
pingpong ^= 1;
}
- if (clipflags & ALIAS_RIGHT_CLIP)
- {
- k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
- ALIAS_RIGHT_CLIP, k, R_Alias_clip_right);
+ if (clipflags & ALIAS_RIGHT_CLIP) {
+ k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
+ ALIAS_RIGHT_CLIP, k, R_Alias_clip_right);
if (k == 0)
return;
pingpong ^= 1;
}
- if (clipflags & ALIAS_BOTTOM_CLIP)
- {
- k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
- ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom);
+ if (clipflags & ALIAS_BOTTOM_CLIP) {
+ k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
+ ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom);
if (k == 0)
return;
pingpong ^= 1;
}
- if (clipflags & ALIAS_TOP_CLIP)
- {
- k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
- ALIAS_TOP_CLIP, k, R_Alias_clip_top);
+ if (clipflags & ALIAS_TOP_CLIP) {
+ k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
+ ALIAS_TOP_CLIP, k, R_Alias_clip_top);
if (k == 0)
return;
pingpong ^= 1;
}
- for (i=0 ; i<k ; i++)
- {
+ for (i = 0; i < k; i++) {
if (fv[pingpong][i].u < r_refdef.aliasvrect.x)
fv[pingpong][i].u = r_refdef.aliasvrect.x;
else if (fv[pingpong][i].u > r_refdef.aliasvrectright)
@@ -315,11 +292,10 @@ void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t
}
// draw triangles
- for (i=1 ; i<k-1 ; i++)
- {
+ for (i = 1; i < k - 1; i++) {
aliastriangleparms.a = &fv[pingpong][0];
aliastriangleparms.b = &fv[pingpong][i];
- aliastriangleparms.c = &fv[pingpong][i+1];
+ aliastriangleparms.c = &fv[pingpong][i + 1];
R_DrawTriangle();
}
}
diff --git a/src/sw_alias.c b/src/sw_alias.c
index 33f52b6..3a12923 100644
--- a/src/sw_alias.c
+++ b/src/sw_alias.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sw_local.h"
#define LIGHT_MIN 5 // lowest light value we'll allow, to avoid the
- // need for inner-loop light clamping
+// need for inner-loop light clamping
//PGM
extern byte iractive;
@@ -63,7 +63,7 @@ static vec3_t s_alias_forward, s_alias_right, s_alias_up;
R_AliasTransformVector
================
*/
-void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4] )
+void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4])
{
out[0] = DotProduct(in, xf[0]) + xf[0][3];
out[1] = DotProduct(in, xf[1]) + xf[1][3];
@@ -76,9 +76,9 @@ void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4] )
**
** Checks a specific alias frame bounding box
*/
-unsigned long R_AliasCheckFrameBBox( maliasframe_t *frame, float worldxf[3][4] )
+unsigned long R_AliasCheckFrameBBox(maliasframe_t *frame, float worldxf[3][4])
{
- unsigned long aggregate_and_clipcode = ~0U,
+ unsigned long aggregate_and_clipcode = ~0U,
aggregate_or_clipcode = 0;
int i;
vec3_t mins, maxs;
@@ -88,63 +88,58 @@ unsigned long R_AliasCheckFrameBBox( maliasframe_t *frame, float worldxf[3][4] )
/*
** get the exact frame bounding box
*/
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
mins[i] = frame->translate[i];
- maxs[i] = mins[i] + frame->scale[i]*255;
+ maxs[i] = mins[i] + frame->scale[i] * 255;
}
/*
** transform the min and max values into view space
*/
- R_AliasTransformVector( mins, transformed_min, aliastransform );
- R_AliasTransformVector( maxs, transformed_max, aliastransform );
+ R_AliasTransformVector(mins, transformed_min, aliastransform);
+ R_AliasTransformVector(maxs, transformed_max, aliastransform);
- if ( transformed_min[2] >= ALIAS_Z_CLIP_PLANE )
+ if (transformed_min[2] >= ALIAS_Z_CLIP_PLANE)
zfullyclipped = qfalse;
- if ( transformed_max[2] >= ALIAS_Z_CLIP_PLANE )
+ if (transformed_max[2] >= ALIAS_Z_CLIP_PLANE)
zfullyclipped = qfalse;
- if ( zfullyclipped )
- {
+ if (zfullyclipped) {
return BBOX_TRIVIAL_REJECT;
}
- if ( zclipped )
- {
- return ( BBOX_MUST_CLIP_XY | BBOX_MUST_CLIP_Z );
+ if (zclipped) {
+ return (BBOX_MUST_CLIP_XY | BBOX_MUST_CLIP_Z);
}
/*
** build a transformed bounding box from the given min and max
*/
- for ( i = 0; i < 8; i++ )
- {
+ for (i = 0; i < 8; i++) {
int j;
vec3_t tmp, transformed;
unsigned long clipcode = 0;
- if ( i & 1 )
+ if (i & 1)
tmp[0] = mins[0];
else
tmp[0] = maxs[0];
- if ( i & 2 )
+ if (i & 2)
tmp[1] = mins[1];
else
tmp[1] = maxs[1];
- if ( i & 4 )
+ if (i & 4)
tmp[2] = mins[2];
else
tmp[2] = maxs[2];
- R_AliasTransformVector( tmp, transformed, worldxf );
+ R_AliasTransformVector(tmp, transformed, worldxf);
- for ( j = 0; j < 4; j++ )
- {
- float dp = DotProduct( transformed, view_clipplanes[j].normal );
+ for (j = 0; j < 4; j++) {
+ float dp = DotProduct(transformed, view_clipplanes[j].normal);
- if ( ( dp - view_clipplanes[j].dist ) < 0.0F )
+ if ((dp - view_clipplanes[j].dist) < 0.0F)
clipcode |= 1 << j;
}
@@ -152,12 +147,10 @@ unsigned long R_AliasCheckFrameBBox( maliasframe_t *frame, float worldxf[3][4] )
aggregate_or_clipcode |= clipcode;
}
- if ( aggregate_and_clipcode )
- {
+ if (aggregate_and_clipcode) {
return BBOX_TRIVIAL_REJECT;
}
- if ( !aggregate_or_clipcode )
- {
+ if (!aggregate_or_clipcode) {
return BBOX_TRIVIAL_ACCEPT;
}
@@ -169,33 +162,32 @@ unsigned long R_AliasCheckFrameBBox( maliasframe_t *frame, float worldxf[3][4] )
R_AliasCheckBBox
================
*/
-qboolean R_AliasCheckBBox (void)
+qboolean R_AliasCheckBBox(void)
{
unsigned long ccodes[2] = { 0, 0 };
- ccodes[0] = R_AliasCheckFrameBBox( r_thisframe, aliasworldtransform );
+ ccodes[0] = R_AliasCheckFrameBBox(r_thisframe, aliasworldtransform);
/*
** non-lerping model
*/
- if ( currententity->backlerp == 0 )
- {
- if ( ccodes[0] == BBOX_TRIVIAL_ACCEPT )
+ if (currententity->backlerp == 0) {
+ if (ccodes[0] == BBOX_TRIVIAL_ACCEPT)
return BBOX_TRIVIAL_ACCEPT;
- else if ( ccodes[0] & BBOX_TRIVIAL_REJECT )
+ else if (ccodes[0] & BBOX_TRIVIAL_REJECT)
return BBOX_TRIVIAL_REJECT;
else
- return ( ccodes[0] & ~BBOX_TRIVIAL_REJECT );
+ return (ccodes[0] & ~BBOX_TRIVIAL_REJECT);
}
- ccodes[1] = R_AliasCheckFrameBBox( r_lastframe, aliasoldworldtransform );
+ ccodes[1] = R_AliasCheckFrameBBox(r_lastframe, aliasoldworldtransform);
- if ( ( ccodes[0] | ccodes[1] ) == BBOX_TRIVIAL_ACCEPT )
+ if ((ccodes[0] | ccodes[1]) == BBOX_TRIVIAL_ACCEPT)
return BBOX_TRIVIAL_ACCEPT;
- else if ( ( ccodes[0] & ccodes[1] ) & BBOX_TRIVIAL_REJECT )
+ else if ((ccodes[0] & ccodes[1]) & BBOX_TRIVIAL_REJECT)
return BBOX_TRIVIAL_REJECT;
else
- return ( ccodes[0] | ccodes[1] ) & ~BBOX_TRIVIAL_REJECT;
+ return (ccodes[0] | ccodes[1]) & ~BBOX_TRIVIAL_REJECT;
}
@@ -204,7 +196,7 @@ qboolean R_AliasCheckBBox (void)
R_AliasProjectAndClipTestFinalVert
================
*/
-void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
+void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv)
{
float zi;
float x, y, z;
@@ -227,7 +219,7 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
if (fv->u > r_refdef.aliasvrectright)
fv->flags |= ALIAS_RIGHT_CLIP;
if (fv->v > r_refdef.aliasvrectbottom)
- fv->flags |= ALIAS_BOTTOM_CLIP;
+ fv->flags |= ALIAS_BOTTOM_CLIP;
}
/*
@@ -235,26 +227,24 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
R_AliasTransformFinalVerts
================
*/
-static void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, maliasvert_t *oldv, maliasvert_t *newv )
+static void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, maliasvert_t *oldv, maliasvert_t *newv)
{
int i;
- for ( i = 0; i < numpoints; i++, fv++, oldv++, newv++ )
- {
+ for (i = 0; i < numpoints; i++, fv++, oldv++, newv++) {
int temp;
float lightcos;
const vec_t *plightnormal;
vec3_t lerped_vert;
- lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0];
- lerped_vert[1] = r_lerp_move[1] + oldv->v[1]*r_lerp_backv[1] + newv->v[1]*r_lerp_frontv[1];
- lerped_vert[2] = r_lerp_move[2] + oldv->v[2]*r_lerp_backv[2] + newv->v[2]*r_lerp_frontv[2];
+ lerped_vert[0] = r_lerp_move[0] + oldv->v[0] * r_lerp_backv[0] + newv->v[0] * r_lerp_frontv[0];
+ lerped_vert[1] = r_lerp_move[1] + oldv->v[1] * r_lerp_backv[1] + newv->v[1] * r_lerp_frontv[1];
+ lerped_vert[2] = r_lerp_move[2] + oldv->v[2] * r_lerp_backv[2] + newv->v[2] * r_lerp_frontv[2];
plightnormal = bytedirs[newv->lightnormalindex];
// PMM - added double damage shell
- if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) )
- {
+ if (currententity->flags & (RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM)) {
lerped_vert[0] += plightnormal[0] * POWERSUIT_SCALE;
lerped_vert[1] += plightnormal[1] * POWERSUIT_SCALE;
lerped_vert[2] += plightnormal[2] * POWERSUIT_SCALE;
@@ -267,11 +257,10 @@ static void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, maliasve
fv->flags = 0;
// lighting
- lightcos = DotProduct (plightnormal, r_plightvec);
+ lightcos = DotProduct(plightnormal, r_plightvec);
temp = r_ambientlight;
- if (lightcos < 0)
- {
+ if (lightcos < 0) {
temp += (int)(r_shadelight * lightcos);
// clamp; because we limited the minimum ambient and shading light, we
@@ -282,13 +271,10 @@ static void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, maliasve
fv->l = temp;
- if ( fv->xyz[2] < ALIAS_Z_CLIP_PLANE )
- {
+ if (fv->xyz[2] < ALIAS_Z_CLIP_PLANE) {
fv->flags |= ALIAS_Z_CLIP;
- }
- else
- {
- R_AliasProjectAndClipTestFinalVert( fv );
+ } else {
+ R_AliasProjectAndClipTestFinalVert(fv);
}
}
}
@@ -301,13 +287,14 @@ R_AliasPreparePoints
General clipped case
================
*/
-static void R_AliasPreparePoints (void) {
+static void R_AliasPreparePoints(void)
+{
int i;
maliasst_t *pstverts;
maliastri_t *ptri;
finalvert_t *pfv[3];
finalvert_t finalverts[MAXALIASVERTS +
- ((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 3];
+ ((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 3];
finalvert_t *pfinalverts;
//PGM
@@ -319,25 +306,23 @@ static void R_AliasPreparePoints (void) {
// put work vertexes on stack, cache aligned
pfinalverts = (finalvert_t *)
- (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
- R_AliasTransformFinalVerts( currentmodel->numverts, pfinalverts,
- r_lastframe->verts, r_thisframe->verts );
+ R_AliasTransformFinalVerts(currentmodel->numverts, pfinalverts,
+ r_lastframe->verts, r_thisframe->verts);
// clip and draw all triangles
//
pstverts = currentmodel->sts;
ptri = currentmodel->tris;
- if ( ( currententity->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) == (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
- for (i=0 ; i<currentmodel->numtris ; i++, ptri++)
- {
+ if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) {
+ for (i = 0; i < currentmodel->numtris; i++, ptri++) {
pfv[0] = &pfinalverts[ptri->index_xyz[0]];
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
- if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
+ if (pfv[0]->flags & pfv[1]->flags & pfv[2]->flags)
continue; // completely clipped
// insert s/t coordinates
@@ -350,29 +335,24 @@ static void R_AliasPreparePoints (void) {
pfv[2]->s = pstverts[ptri->index_st[2]].s << 16;
pfv[2]->t = pstverts[ptri->index_st[2]].t << 16;
- if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
- { // totally unclipped
+ if (!(pfv[0]->flags | pfv[1]->flags | pfv[2]->flags)) {
+ // totally unclipped
aliastriangleparms.a = pfv[2];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[0];
R_DrawTriangle();
- }
- else
- {
- R_AliasClipTriangle (pfv[2], pfv[1], pfv[0]);
+ } else {
+ R_AliasClipTriangle(pfv[2], pfv[1], pfv[0]);
}
}
- }
- else
- {
- for (i=0 ; i<currentmodel->numtris ; i++, ptri++)
- {
+ } else {
+ for (i = 0; i < currentmodel->numtris; i++, ptri++) {
pfv[0] = &pfinalverts[ptri->index_xyz[0]];
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
- if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
+ if (pfv[0]->flags & pfv[1]->flags & pfv[2]->flags)
continue; // completely clipped
// insert s/t coordinates
@@ -385,17 +365,16 @@ static void R_AliasPreparePoints (void) {
pfv[2]->s = pstverts[ptri->index_st[2]].s << 16;
pfv[2]->t = pstverts[ptri->index_st[2]].t << 16;
- if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
- { // totally unclipped
+ if (!(pfv[0]->flags | pfv[1]->flags | pfv[2]->flags)) {
+ // totally unclipped
aliastriangleparms.a = pfv[0];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[2];
R_DrawTriangle();
- }
- else
- { // partially clipped
- R_AliasClipTriangle (pfv[0], pfv[1], pfv[2]);
+ } else {
+ // partially clipped
+ R_AliasClipTriangle(pfv[0], pfv[1], pfv[2]);
}
}
}
@@ -407,7 +386,7 @@ static void R_AliasPreparePoints (void) {
R_AliasSetUpTransform
================
*/
-static void R_AliasSetUpTransform (void)
+static void R_AliasSetUpTransform(void)
{
int i;
static float viewmatrix[3][4];
@@ -416,50 +395,49 @@ static void R_AliasSetUpTransform (void)
// TODO: should really be stored with the entity instead of being reconstructed
// TODO: should use a look-up table
// TODO: could cache lazily, stored in the entity
-//
+//
angles[ROLL] = currententity->angles[ROLL];
angles[PITCH] = currententity->angles[PITCH];
angles[YAW] = currententity->angles[YAW];
- AngleVectors( angles, s_alias_forward, s_alias_right, s_alias_up );
+ AngleVectors(angles, s_alias_forward, s_alias_right, s_alias_up);
// TODO: can do this with simple matrix rearrangement
- memset( aliasworldtransform, 0, sizeof( aliasworldtransform ) );
- memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform ) );
+ memset(aliasworldtransform, 0, sizeof(aliasworldtransform));
+ memset(aliasoldworldtransform, 0, sizeof(aliasworldtransform));
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][1] = -s_alias_right[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i];
}
- aliasworldtransform[0][3] = currententity->origin[0]-r_origin[0];
- aliasworldtransform[1][3] = currententity->origin[1]-r_origin[1];
- aliasworldtransform[2][3] = currententity->origin[2]-r_origin[2];
+ aliasworldtransform[0][3] = currententity->origin[0] - r_origin[0];
+ aliasworldtransform[1][3] = currententity->origin[1] - r_origin[1];
+ aliasworldtransform[2][3] = currententity->origin[2] - r_origin[2];
- aliasoldworldtransform[0][3] = currententity->oldorigin[0]-r_origin[0];
- aliasoldworldtransform[1][3] = currententity->oldorigin[1]-r_origin[1];
- aliasoldworldtransform[2][3] = currententity->oldorigin[2]-r_origin[2];
+ aliasoldworldtransform[0][3] = currententity->oldorigin[0] - r_origin[0];
+ aliasoldworldtransform[1][3] = currententity->oldorigin[1] - r_origin[1];
+ aliasoldworldtransform[2][3] = currententity->oldorigin[2] - r_origin[2];
// FIXME: can do more efficiently than full concatenation
-// memcpy( rotationmatrix, t2matrix, sizeof( rotationmatrix ) );
+// memcpy(rotationmatrix, t2matrix, sizeof(rotationmatrix));
-// R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix);
+// R_ConcatTransforms(t2matrix, tmatrix, rotationmatrix);
// TODO: should be global, set when vright, etc., set
- VectorCopy (vright, viewmatrix[0]);
- VectorCopy (vup, viewmatrix[1]);
- VectorNegate (viewmatrix[1], viewmatrix[1]);
- VectorCopy (vpn, viewmatrix[2]);
+ VectorCopy(vright, viewmatrix[0]);
+ VectorCopy(vup, viewmatrix[1]);
+ VectorNegate(viewmatrix[1], viewmatrix[1]);
+ VectorCopy(vpn, viewmatrix[2]);
viewmatrix[0][3] = 0;
viewmatrix[1][3] = 0;
viewmatrix[2][3] = 0;
-// memcpy( aliasworldtransform, rotationmatrix, sizeof( aliastransform ) );
+// memcpy(aliasworldtransform, rotationmatrix, sizeof(aliastransform));
- R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform);
+ R_ConcatTransforms(viewmatrix, aliasworldtransform, aliastransform);
aliasworldtransform[0][3] = currententity->origin[0];
aliasworldtransform[1][3] = currententity->origin[1];
@@ -475,34 +453,32 @@ static void R_AliasSetUpTransform (void)
R_AliasSetupSkin
===============
*/
-static qboolean R_AliasSetupSkin (void)
+static qboolean R_AliasSetupSkin(void)
{
int skinnum;
image_t *pskindesc;
if (currententity->skin)
- pskindesc = IMG_ForHandle( currententity->skin );
- else
- {
+ pskindesc = IMG_ForHandle(currententity->skin);
+ else {
skinnum = currententity->skinnum;
- if ((skinnum >= currentmodel->numskins) || (skinnum < 0))
- {
- Com_DPrintf( "R_AliasSetupSkin %s: no such skin # %d\n",
- currentmodel->name, skinnum);
+ if ((skinnum >= currentmodel->numskins) || (skinnum < 0)) {
+ Com_DPrintf("R_AliasSetupSkin %s: no such skin # %d\n",
+ currentmodel->name, skinnum);
skinnum = 0;
}
pskindesc = currentmodel->skins[skinnum];
}
- if ( !pskindesc )
+ if (!pskindesc)
return qfalse;
r_affinetridesc.pskin = pskindesc->pixels[0];
r_affinetridesc.skinwidth = pskindesc->width;
r_affinetridesc.skinheight = pskindesc->height;
- R_PolysetUpdateTables (); // FIXME: precalc edge lookups
+ R_PolysetUpdateTables(); // FIXME: precalc edge lookups
return qtrue;
}
@@ -515,40 +491,35 @@ R_AliasSetupLighting
FIXME: put lighting into tables
================
*/
-static void R_AliasSetupLighting (void)
+static void R_AliasSetupLighting(void)
{
alight_t lighting;
- float lightvec[3] = {-1, 0, 0};
+ float lightvec[3] = { -1, 0, 0};
vec3_t light;
int i, j;
// all components of light should be identical in software
- if ( currententity->flags & RF_FULLBRIGHT )
- {
- for (i=0 ; i<3 ; i++)
+ if (currententity->flags & RF_FULLBRIGHT) {
+ for (i = 0; i < 3; i++)
light[i] = 1.0;
- }
- else
- {
- R_LightPoint (currententity->origin, light);
+ } else {
+ R_LightPoint(currententity->origin, light);
}
- if ( currententity->flags & RF_MINLIGHT )
- {
- for (i=0 ; i<3 ; i++)
+ if (currententity->flags & RF_MINLIGHT) {
+ for (i = 0; i < 3; i++)
if (light[i] < 0.1)
light[i] = 0.1;
}
- if ( currententity->flags & RF_GLOW )
- { // bonus items will pulse with time
+ if (currententity->flags & RF_GLOW) {
+ // bonus items will pulse with time
float scale;
float min;
- scale = 0.1 * sin(r_newrefdef.time*7);
- for (i=0 ; i<3 ; i++)
- {
+ scale = 0.1 * sin(r_newrefdef.time * 7);
+ for (i = 0; i < 3; i++) {
min = light[i] * 0.8;
light[i] += scale;
if (light[i] < min)
@@ -556,7 +527,7 @@ static void R_AliasSetupLighting (void)
}
}
- j = (light[0] + light[1] + light[2])*0.3333*255;
+ j = (light[0] + light[1] + light[2]) * 0.3333 * 255;
lighting.ambientlight = j;
lighting.shadelight = j;
@@ -589,9 +560,9 @@ static void R_AliasSetupLighting (void)
r_shadelight *= VID_GRADES;
// rotate the lighting vector into the model's frame of reference
- r_plightvec[0] = DotProduct( lighting.plightvec, s_alias_forward );
- r_plightvec[1] = -DotProduct( lighting.plightvec, s_alias_right );
- r_plightvec[2] = DotProduct( lighting.plightvec, s_alias_up );
+ r_plightvec[0] = DotProduct(lighting.plightvec, s_alias_forward);
+ r_plightvec[1] = -DotProduct(lighting.plightvec, s_alias_right);
+ r_plightvec[2] = DotProduct(lighting.plightvec, s_alias_up);
}
@@ -601,18 +572,19 @@ R_AliasSetupFrames
=================
*/
-static void R_AliasSetupFrames( void ) {
+static void R_AliasSetupFrames(void)
+{
int thisframe = currententity->frame;
int lastframe = currententity->oldframe;
- if( thisframe >= currentmodel->numframes || thisframe < 0 ) {
- Com_DPrintf( "%s: %s: no such thisframe %d\n",
- __func__, currentmodel->name, thisframe);
+ if (thisframe >= currentmodel->numframes || thisframe < 0) {
+ Com_DPrintf("%s: %s: no such thisframe %d\n",
+ __func__, currentmodel->name, thisframe);
thisframe = 0;
}
- if( lastframe >= currentmodel->numframes || lastframe < 0 ) {
- Com_DPrintf( "%s: %s: no such lastframe %d\n",
- __func__, currentmodel->name, lastframe);
+ if (lastframe >= currentmodel->numframes || lastframe < 0) {
+ Com_DPrintf("%s: %s: no such lastframe %d\n",
+ __func__, currentmodel->name, lastframe);
lastframe = 0;
}
@@ -625,7 +597,7 @@ static void R_AliasSetupFrames( void ) {
**
** Precomputes lerp coefficients used for the whole frame.
*/
-static void R_AliasSetUpLerpData( float backlerp )
+static void R_AliasSetUpLerpData(float backlerp)
{
float frontlerp;
vec3_t translation, vectors[3];
@@ -636,12 +608,12 @@ static void R_AliasSetUpLerpData( float backlerp )
/*
** convert entity's angles into discrete vectors for R, U, and F
*/
- AngleVectors (currententity->angles, vectors[0], vectors[1], vectors[2]);
+ AngleVectors(currententity->angles, vectors[0], vectors[1], vectors[2]);
/*
** translation is the vector from last position to this position
*/
- VectorSubtract (currententity->oldorigin, currententity->origin, translation);
+ VectorSubtract(currententity->oldorigin, currententity->origin, translation);
/*
** move should be the delta back to the previous frame * backlerp
@@ -650,27 +622,26 @@ static void R_AliasSetUpLerpData( float backlerp )
r_lerp_move[1] = -DotProduct(translation, vectors[1]); // left
r_lerp_move[2] = DotProduct(translation, vectors[2]); // up
- VectorAdd( r_lerp_move, r_lastframe->translate, r_lerp_move );
+ VectorAdd(r_lerp_move, r_lastframe->translate, r_lerp_move);
- for (i=0 ; i<3 ; i++)
- {
- r_lerp_move[i] = backlerp*r_lerp_move[i] + frontlerp * r_thisframe->translate[i];
+ for (i = 0; i < 3; i++) {
+ r_lerp_move[i] = backlerp * r_lerp_move[i] + frontlerp * r_thisframe->translate[i];
}
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
r_lerp_frontv[i] = frontlerp * r_thisframe->scale[i];
r_lerp_backv[i] = backlerp * r_lastframe->scale[i];
}
}
-static void R_AliasSetupBlend( void ) {
- extern void (*d_pdrawspans)( void * );
- extern void R_PolysetDrawSpans8_Opaque( void * );
- extern void R_PolysetDrawSpans8_33( void * );
- extern void R_PolysetDrawSpans8_66( void * );
- extern void R_PolysetDrawSpansConstant8_33( void * );
- extern void R_PolysetDrawSpansConstant8_66( void * );
+static void R_AliasSetupBlend(void)
+{
+ extern void (*d_pdrawspans)(void *);
+ extern void R_PolysetDrawSpans8_Opaque(void *);
+ extern void R_PolysetDrawSpans8_33(void *);
+ extern void R_PolysetDrawSpans8_66(void *);
+ extern void R_PolysetDrawSpansConstant8_33(void *);
+ extern void R_PolysetDrawSpansConstant8_66(void *);
int color;
@@ -679,50 +650,45 @@ static void R_AliasSetupBlend( void ) {
*/
// PMM - added double damage shell
// PMM - reordered to handle blending
- color = currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM);
- if ( color )
- {
+ color = currententity->flags & (RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM);
+ if (color) {
// PMM - added double
// PMM - reordered, new shells after old shells (so they get overriden)
- if ( color == RF_SHELL_RED )
+ if (color == RF_SHELL_RED)
r_aliasblendcolor = SHELL_RED_COLOR;
- else if ( color == RF_SHELL_GREEN )
+ else if (color == RF_SHELL_GREEN)
r_aliasblendcolor = SHELL_GREEN_COLOR;
- else if ( color == RF_SHELL_BLUE )
+ else if (color == RF_SHELL_BLUE)
r_aliasblendcolor = SHELL_BLUE_COLOR;
- else if ( color == (RF_SHELL_RED | RF_SHELL_GREEN) )
+ else if (color == (RF_SHELL_RED | RF_SHELL_GREEN))
r_aliasblendcolor = SHELL_RG_COLOR;
- else if ( color == (RF_SHELL_RED | RF_SHELL_BLUE) )
+ else if (color == (RF_SHELL_RED | RF_SHELL_BLUE))
r_aliasblendcolor = SHELL_RB_COLOR;
- else if ( color == (RF_SHELL_BLUE | RF_SHELL_GREEN) )
+ else if (color == (RF_SHELL_BLUE | RF_SHELL_GREEN))
r_aliasblendcolor = SHELL_BG_COLOR;
// PMM - added this .. it's yellowish
- else if ( color == (RF_SHELL_DOUBLE) )
+ else if (color == (RF_SHELL_DOUBLE))
r_aliasblendcolor = SHELL_DOUBLE_COLOR;
- else if ( color == (RF_SHELL_HALF_DAM) )
+ else if (color == (RF_SHELL_HALF_DAM))
r_aliasblendcolor = SHELL_HALF_DAM_COLOR;
// pmm
else
r_aliasblendcolor = SHELL_WHITE_COLOR;
- if ( currententity->alpha > 0.33 )
+ if (currententity->alpha > 0.33)
d_pdrawspans = R_PolysetDrawSpansConstant8_66;
else
d_pdrawspans = R_PolysetDrawSpansConstant8_33;
- }
- else if ( currententity->flags & RF_TRANSLUCENT )
- {
- if ( currententity->alpha > 0.66 )
+ } else if (currententity->flags & RF_TRANSLUCENT) {
+ if (currententity->alpha > 0.66)
d_pdrawspans = R_PolysetDrawSpans8_Opaque;
- else if ( currententity->alpha > 0.33 )
+ else if (currententity->alpha > 0.33)
d_pdrawspans = R_PolysetDrawSpans8_66;
else
d_pdrawspans = R_PolysetDrawSpans8_33;
- }
- else
- {
+ } else {
d_pdrawspans = R_PolysetDrawSpans8_Opaque;
}
}
@@ -732,13 +698,12 @@ static void R_AliasSetupBlend( void ) {
R_AliasDrawModel
================
*/
-void R_AliasDrawModel (void)
+void R_AliasDrawModel(void)
{
- if ( r_lerpmodels->value == 0 )
+ if (r_lerpmodels->value == 0)
currententity->backlerp = 0;
- if ( ( currententity->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) == (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
+ if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) {
aliasxscale = -aliasxscale;
}
@@ -751,42 +716,38 @@ void R_AliasDrawModel (void)
// see if the bounding box lets us trivially reject, also sets
// trivial accept status
- if ( R_AliasCheckBBox() == BBOX_TRIVIAL_REJECT )
- {
- if ( ( currententity->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) == (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
+ if (R_AliasCheckBBox() == BBOX_TRIVIAL_REJECT) {
+ if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) {
aliasxscale = -aliasxscale;
}
return;
}
// set up the skin and verify it exists
- if ( !R_AliasSetupSkin () )
- {
- Com_DPrintf( "R_AliasDrawModel %s: NULL skin found\n",
- currentmodel->name);
+ if (!R_AliasSetupSkin()) {
+ Com_DPrintf("R_AliasDrawModel %s: NULL skin found\n",
+ currentmodel->name);
return;
}
r_amodels_drawn++;
- R_AliasSetupLighting ();
+ R_AliasSetupLighting();
R_AliasSetupBlend();
-
+
/*
** compute this_frame and old_frame addresses
*/
- R_AliasSetUpLerpData( currententity->backlerp );
+ R_AliasSetUpLerpData(currententity->backlerp);
if (currententity->flags & RF_DEPTHHACK)
s_ziscale = (float)0x8000 * (float)0x10000 * 3.0;
else
s_ziscale = (float)0x8000 * (float)0x10000;
- R_AliasPreparePoints ();
+ R_AliasPreparePoints();
- if ( ( currententity->flags & (RF_WEAPONMODEL|RF_LEFTHAND) ) == (RF_WEAPONMODEL|RF_LEFTHAND) )
- {
+ if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) {
aliasxscale = -aliasxscale;
}
}
diff --git a/src/sw_block.h b/src/sw_block.h
index 3544fb7..85ae441 100644
--- a/src/sw_block.h
+++ b/src/sw_block.h
@@ -1,37 +1,35 @@
-#define BLOCK_SIZE ( 1 << BLOCK_SHIFT )
+#define BLOCK_SIZE (1 << BLOCK_SHIFT)
-void BLOCK_FUNC( void ){
+void BLOCK_FUNC(void)
+{
int v, i, b, lightstep, lighttemp, light;
byte pix, *psource, *prowdest;
psource = pbasesource;
prowdest = prowdestbase;
- for (v=0 ; v<r_numvblocks ; v++)
- {
- // FIXME: make these locals?
- // FIXME: use delta rather than both right and left, like ASM?
+ for (v = 0 ; v < r_numvblocks ; v++) {
+ // FIXME: make these locals?
+ // FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> BLOCK_SHIFT;
lightrightstep = (r_lightptr[1] - lightright) >> BLOCK_SHIFT;
- for (i=0 ; i<BLOCK_SIZE ; i++)
- {
+ for (i = 0 ; i < BLOCK_SIZE ; i++) {
lighttemp = lightleft - lightright;
lightstep = lighttemp >> BLOCK_SHIFT;
light = lightright;
- for (b=BLOCK_SIZE-1; b>=0; b--)
- {
+ for (b = BLOCK_SIZE - 1; b >= 0; b--) {
pix = psource[b];
prowdest[b] = ((unsigned char *)vid.colormap)
- [(light & 0xFF00) + pix];
+ [(light & 0xFF00) + pix];
light += lightstep;
}
-
+
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
diff --git a/src/sw_bsp.c b/src/sw_bsp.c
index 05d1189..9e55361 100644
--- a/src/sw_bsp.c
+++ b/src/sw_bsp.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,16 +27,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
qboolean insubmodel;
entity_t *currententity;
vec3_t modelorg; // modelorg is the viewpoint reletive to
- // the currently rendering entity
+// the currently rendering entity
vec3_t r_entorigin; // the currently rendering entity in world
- // coordinates
+// coordinates
float entity_rotation[3][3];
int r_currentbkey;
-typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t;
-
#define MAX_BMODEL_VERTS 500 // 6K
#define MAX_BMODEL_EDGES 1000 // 12K
@@ -56,14 +54,14 @@ static qboolean makeclippededge;
R_EntityRotate
================
*/
-void R_EntityRotate (vec3_t vec)
+void R_EntityRotate(vec3_t vec)
{
vec3_t tvec;
- VectorCopy (vec, tvec);
- vec[0] = DotProduct (entity_rotation[0], tvec);
- vec[1] = DotProduct (entity_rotation[1], tvec);
- vec[2] = DotProduct (entity_rotation[2], tvec);
+ VectorCopy(vec, tvec);
+ vec[0] = DotProduct(entity_rotation[0], tvec);
+ vec[1] = DotProduct(entity_rotation[1], tvec);
+ vec[2] = DotProduct(entity_rotation[2], tvec);
}
@@ -72,7 +70,7 @@ void R_EntityRotate (vec3_t vec)
R_RotateBmodel
================
*/
-void R_RotateBmodel (void)
+void R_RotateBmodel(void)
{
float angle, s, c, temp1[3][3], temp2[3][3], temp3[3][3];
@@ -82,8 +80,8 @@ void R_RotateBmodel (void)
// TODO: share work with R_SetUpAliasTransform
// yaw
- angle = currententity->angles[YAW];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[YAW];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -99,8 +97,8 @@ void R_RotateBmodel (void)
// pitch
- angle = currententity->angles[PITCH];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[PITCH];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -114,11 +112,11 @@ void R_RotateBmodel (void)
temp2[2][1] = 0;
temp2[2][2] = c;
- R_ConcatRotations (temp2, temp1, temp3);
+ R_ConcatRotations(temp2, temp1, temp3);
// roll
- angle = currententity->angles[ROLL];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[ROLL];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -132,17 +130,17 @@ void R_RotateBmodel (void)
temp1[2][1] = -s;
temp1[2][2] = c;
- R_ConcatRotations (temp1, temp3, entity_rotation);
+ R_ConcatRotations(temp1, temp3, entity_rotation);
//
// rotate modelorg and the transformation matrix
//
- R_EntityRotate (modelorg);
- R_EntityRotate (vpn);
- R_EntityRotate (vright);
- R_EntityRotate (vup);
+ R_EntityRotate(modelorg);
+ R_EntityRotate(vpn);
+ R_EntityRotate(vright);
+ R_EntityRotate(vup);
- R_TransformFrustum ();
+ R_TransformFrustum();
}
@@ -153,7 +151,7 @@ R_RecursiveClipBPoly
Clip a bmodel poly down the world bsp tree
================
*/
-void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
+void R_RecursiveClipBPoly(bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
{
bedge_t *psideedges[2], *pnextedge, *ptedge;
int i, side, lastside;
@@ -171,19 +169,18 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
// FIXME: cache these?
splitplane = pnode->plane;
tplane.dist = -PlaneDiff(r_entorigin, splitplane);
- tplane.normal[0] = DotProduct (entity_rotation[0], splitplane->normal);
- tplane.normal[1] = DotProduct (entity_rotation[1], splitplane->normal);
- tplane.normal[2] = DotProduct (entity_rotation[2], splitplane->normal);
+ tplane.normal[0] = DotProduct(entity_rotation[0], splitplane->normal);
+ tplane.normal[1] = DotProduct(entity_rotation[1], splitplane->normal);
+ tplane.normal[2] = DotProduct(entity_rotation[2], splitplane->normal);
// clip edges to BSP plane
- for ( ; pedges ; pedges = pnextedge)
- {
+ for (; pedges; pedges = pnextedge) {
pnextedge = pedges->pnext;
- // set the status for the last point as the previous point
- // FIXME: cache this stuff somehow?
+ // set the status for the last point as the previous point
+ // FIXME: cache this stuff somehow?
plastvert = pedges->v[0];
- lastdist = PlaneDiff (plastvert->point, &tplane);
+ lastdist = PlaneDiff(plastvert->point, &tplane);
if (lastdist > 0)
lastside = 0;
@@ -191,37 +188,35 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
lastside = 1;
pvert = pedges->v[1];
- dist = PlaneDiff (pvert->point, &tplane);
+ dist = PlaneDiff(pvert->point, &tplane);
if (dist > 0)
side = 0;
else
side = 1;
- if (side != lastside)
- {
- // clipped
+ if (side != lastside) {
+ // clipped
if (numbverts >= MAX_BMODEL_VERTS)
return;
- // generate the clipped vertex
+ // generate the clipped vertex
frac = lastdist / (lastdist - dist);
ptvert = &pbverts[numbverts++];
ptvert->point[0] = plastvert->point[0] +
- frac * (pvert->point[0] -
- plastvert->point[0]);
+ frac * (pvert->point[0] -
+ plastvert->point[0]);
ptvert->point[1] = plastvert->point[1] +
- frac * (pvert->point[1] -
- plastvert->point[1]);
+ frac * (pvert->point[1] -
+ plastvert->point[1]);
ptvert->point[2] = plastvert->point[2] +
- frac * (pvert->point[2] -
- plastvert->point[2]);
-
- // split into two edges, one on each side, and remember entering
- // and exiting points
- // FIXME: share the clip edge by having a winding direction flag?
- if (numbedges >= (MAX_BMODEL_EDGES - 1))
- {
+ frac * (pvert->point[2] -
+ plastvert->point[2]);
+
+ // split into two edges, one on each side, and remember entering
+ // and exiting points
+ // FIXME: share the clip edge by having a winding direction flag?
+ if (numbedges >= (MAX_BMODEL_EDGES - 1)) {
Com_Printf("Out of edges for bmodel\n");
return;
}
@@ -240,21 +235,16 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
numbedges += 2;
- if (side == 0)
- {
- // entering for front, exiting for back
+ if (side == 0) {
+ // entering for front, exiting for back
pfrontenter = ptvert;
makeclippededge = qtrue;
- }
- else
- {
+ } else {
pfrontexit = ptvert;
makeclippededge = qtrue;
}
- }
- else
- {
- // add the edge to the appropriate side
+ } else {
+ // add the edge to the appropriate side
pedges->pnext = psideedges[side];
psideedges[side] = pedges;
}
@@ -262,11 +252,9 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
// if anything was clipped, reconstitute and add the edges along the clip
// plane to both sides (but in opposite directions)
- if (makeclippededge)
- {
- if (numbedges >= (MAX_BMODEL_EDGES - 2))
- {
- Com_Error( ERR_DROP, "Out of edges for bmodel" );
+ if (makeclippededge) {
+ if (numbedges >= (MAX_BMODEL_EDGES - 2)) {
+ Com_Error(ERR_DROP, "Out of edges for bmodel");
}
ptedge = &pbedges[numbedges];
@@ -285,37 +273,29 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
}
// draw or recurse further
- for (i=0 ; i<2 ; i++)
- {
- if (psideedges[i])
- {
- // draw if we've reached a non-solid leaf, done if all that's left is a
- // solid leaf, and continue down the tree if it's not a leaf
+ for (i = 0; i < 2; i++) {
+ if (psideedges[i]) {
+ // draw if we've reached a non-solid leaf, done if all that's left is a
+ // solid leaf, and continue down the tree if it's not a leaf
pn = pnode->children[i];
- // we're done with this branch if the node or leaf isn't in the PVS
- if (pn->visframe == r_visframecount)
- {
- if (!pn->plane)
- {
- mleaf_t *pl = ( mleaf_t * )pn;
- if (pl->contents != CONTENTS_SOLID)
- {
- if (r_newrefdef.areabits)
- {
+ // we're done with this branch if the node or leaf isn't in the PVS
+ if (pn->visframe == r_visframecount) {
+ if (!pn->plane) {
+ mleaf_t *pl = (mleaf_t *)pn;
+ if (pl->contents != CONTENTS_SOLID) {
+ if (r_newrefdef.areabits) {
area = pl->area;
- if (!Q_IsBitSet(r_newrefdef.areabits, area) )
+ if (!Q_IsBitSet(r_newrefdef.areabits, area))
continue; // not visible
}
r_currentbkey = pl->key;
- R_RenderBmodelFace (psideedges[i], psurf);
+ R_RenderBmodelFace(psideedges[i], psurf);
}
- }
- else
- {
- R_RecursiveClipBPoly (psideedges[i], pnode->children[i],
- psurf);
+ } else {
+ R_RecursiveClipBPoly(psideedges[i], pnode->children[i],
+ psurf);
}
}
}
@@ -330,7 +310,7 @@ R_DrawSolidClippedSubmodelPolygons
Bmodel crosses multiple leafs
================
*/
-void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
+void R_DrawSolidClippedSubmodelPolygons(mmodel_t *pmodel, mnode_t *topnode)
{
int i, j;
vec_t dot;
@@ -346,24 +326,23 @@ void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
psurf = pmodel->firstface;
numsurfaces = pmodel->numfaces;
- for (i=0 ; i<numsurfaces ; i++, psurf++)
- {
- // find which side of the node we are on
+ for (i = 0; i < numsurfaces; i++, psurf++) {
+ // find which side of the node we are on
pplane = psurf->plane;
- dot = PlaneDiff (modelorg, pplane);
+ dot = PlaneDiff(modelorg, pplane);
- // draw the polygon
- if (( !(psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
+ // draw the polygon
+ if ((!(psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
((psurf->drawflags & DSURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
continue;
- // FIXME: use bounding-box-based frustum clipping info?
+ // FIXME: use bounding-box-based frustum clipping info?
- // copy the edges to bedges, flipping if necessary so always
- // clockwise winding
- // FIXME: if edges and vertices get caches, these assignments must move
- // outside the loop, and overflow checking must be done here
+ // copy the edges to bedges, flipping if necessary so always
+ // clockwise winding
+ // FIXME: if edges and vertices get caches, these assignments must move
+ // outside the loop, and overflow checking must be done here
pbverts = bverts;
pbedges = bedges;
numbverts = numbedges = 0;
@@ -371,19 +350,18 @@ void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
numbedges += psurf->numsurfedges;
surfedge = psurf->firstsurfedge;
- for (j=0 ; j<psurf->numsurfedges ; j++, surfedge++)
- {
+ for (j = 0; j < psurf->numsurfedges; j++, surfedge++) {
pbedge[j].v[0] = surfedge->edge->v[surfedge->vert ];
pbedge[j].v[1] = surfedge->edge->v[surfedge->vert ^ 1];
- pbedge[j].pnext = &pbedge[j+1];
+ pbedge[j].pnext = &pbedge[j + 1];
}
- pbedge[j-1].pnext = NULL; // mark end of edges
+ pbedge[j - 1].pnext = NULL; // mark end of edges
- if ( !( psurf->texinfo->c.flags & ( SURF_TRANS66 | SURF_TRANS33 ) ) )
- R_RecursiveClipBPoly (pbedge, topnode, psurf);
+ if (!(psurf->texinfo->c.flags & (SURF_TRANS66 | SURF_TRANS33)))
+ R_RecursiveClipBPoly(pbedge, topnode, psurf);
else
- R_RenderBmodelFace( pbedge, psurf );
+ R_RenderBmodelFace(pbedge, psurf);
}
}
@@ -395,7 +373,7 @@ R_DrawSubmodelPolygons
All in one leaf
================
*/
-void R_DrawSubmodelPolygons (mmodel_t *pmodel, int clipflags, mnode_t *topnode)
+void R_DrawSubmodelPolygons(mmodel_t *pmodel, int clipflags, mnode_t *topnode)
{
int i;
vec_t dot;
@@ -408,21 +386,19 @@ void R_DrawSubmodelPolygons (mmodel_t *pmodel, int clipflags, mnode_t *topnode)
psurf = pmodel->firstface;
numsurfaces = pmodel->numfaces;
- for (i=0 ; i<numsurfaces ; i++, psurf++)
- {
- // find which side of the node we are on
+ for (i = 0; i < numsurfaces; i++, psurf++) {
+ // find which side of the node we are on
pplane = psurf->plane;
- dot = PlaneDiff (modelorg, pplane);
+ dot = PlaneDiff(modelorg, pplane);
- // draw the polygon
+ // draw the polygon
if (((psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
- (!(psurf->drawflags & DSURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
- {
+ (!(psurf->drawflags & DSURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
r_currentkey = ((mleaf_t *)topnode)->key;
- // FIXME: use bounding-box-based frustum clipping info?
- R_RenderFace (psurf, clipflags);
+ // FIXME: use bounding-box-based frustum clipping info?
+ R_RenderFace(psurf, clipflags);
}
}
}
@@ -435,7 +411,8 @@ int c_drawnode;
R_RecursiveWorldNode
================
*/
-void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
+void R_RecursiveWorldNode(mnode_t *node, int clipflags)
+{
int i, c, side, *pindex;
vec3_t acceptpt, rejectpt;
cplane_t *plane;
@@ -443,42 +420,42 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
float d, dot;
mleaf_t *pleaf;
- while( node->visframe == r_visframecount) {
- // cull the clipping planes if not trivial accept
- // FIXME: the compiler is doing a lousy job of optimizing here; it could be
- // twice as fast in ASM
+ while (node->visframe == r_visframecount) {
+ // cull the clipping planes if not trivial accept
+ // FIXME: the compiler is doing a lousy job of optimizing here; it could be
+ // twice as fast in ASM
if (clipflags) {
- for (i=0 ; i<4 ; i++) {
- if (! (clipflags & (1<<i)) )
+ for (i = 0; i < 4; i++) {
+ if (!(clipflags & (1 << i)))
continue; // don't need to clip against it
- // generate accept and reject points
- // FIXME: do with fast look-ups or integer tests based on the sign bit
- // of the floating point values
+ // generate accept and reject points
+ // FIXME: do with fast look-ups or integer tests based on the sign bit
+ // of the floating point values
pindex = pfrustum_indexes[i];
rejectpt[0] = (float)node->minmaxs[pindex[0]];
rejectpt[1] = (float)node->minmaxs[pindex[1]];
rejectpt[2] = (float)node->minmaxs[pindex[2]];
-
+
d = PlaneDiff(rejectpt, &view_clipplanes[i]);
if (d <= 0)
return;
- acceptpt[0] = (float)node->minmaxs[pindex[3+0]];
- acceptpt[1] = (float)node->minmaxs[pindex[3+1]];
- acceptpt[2] = (float)node->minmaxs[pindex[3+2]];
+ acceptpt[0] = (float)node->minmaxs[pindex[3 + 0]];
+ acceptpt[1] = (float)node->minmaxs[pindex[3 + 1]];
+ acceptpt[2] = (float)node->minmaxs[pindex[3 + 2]];
- d = PlaneDiff (acceptpt, &view_clipplanes[i]);
+ d = PlaneDiff(acceptpt, &view_clipplanes[i]);
if (d >= 0)
- clipflags &= ~(1<<i); // node is entirely on screen
+ clipflags &= ~(1 << i); // node is entirely on screen
}
}
c_drawnode++;
- // if a leaf node, draw stuff
+ // if a leaf node, draw stuff
if (!node->plane) {
pleaf = (mleaf_t *)node;
@@ -487,15 +464,14 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
// check for door connected areas
if (r_newrefdef.areabits) {
- if (! Q_IsBitSet(r_newrefdef.areabits, pleaf->area ) )
+ if (! Q_IsBitSet(r_newrefdef.areabits, pleaf->area))
return; // not visible
}
mark = pleaf->firstleafface;
c = pleaf->numleaffaces;
if (c) {
- do
- {
+ do {
(*mark)->drawframe = r_framecount;
mark++;
} while (--c);
@@ -505,51 +481,49 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
r_currentkey++; // all bmodels in a leaf share the same key
return;
}
- // node is just a decision point, so go down the apropriate sides
+ // node is just a decision point, so go down the apropriate sides
- // find which side of the node we are on
+ // find which side of the node we are on
plane = node->plane;
- dot = PlaneDiffFast( modelorg, plane );
-
+ dot = PlaneDiffFast(modelorg, plane);
+
if (dot >= 0)
side = 0;
else
side = 1;
- // recurse down the children, front side first
- R_RecursiveWorldNode (node->children[side], clipflags);
+ // recurse down the children, front side first
+ R_RecursiveWorldNode(node->children[side], clipflags);
- // draw stuff
+ // draw stuff
c = node->numfaces;
if (c) {
surf = node->firstface;
if (dot < -BACKFACE_EPSILON) {
do {
if ((surf->drawflags & DSURF_PLANEBACK) &&
- (surf->drawframe == r_framecount))
- {
- R_RenderFace (surf, clipflags);
+ (surf->drawframe == r_framecount)) {
+ R_RenderFace(surf, clipflags);
}
surf++;
} while (--c);
} else if (dot > BACKFACE_EPSILON) {
do {
if (!(surf->drawflags & DSURF_PLANEBACK) &&
- (surf->drawframe == r_framecount))
- {
- R_RenderFace (surf, clipflags);
+ (surf->drawframe == r_framecount)) {
+ R_RenderFace(surf, clipflags);
}
surf++;
} while (--c);
}
- // all surfaces on the same node share the same sequence number
+ // all surfaces on the same node share the same sequence number
r_currentkey++;
}
- // recurse down the back side
- node = node->children[side^1];
+ // recurse down the back side
+ node = node->children[side ^ 1];
}
}
@@ -560,23 +534,23 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
R_RenderWorld
================
*/
-void R_RenderWorld (void)
+void R_RenderWorld(void)
{
if (!r_drawworld->integer)
return;
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
return;
- c_drawnode=0;
+ c_drawnode = 0;
// auto cycle the world frame for texture animation
- r_worldentity.frame = (int)(r_newrefdef.time*2);
+ r_worldentity.frame = (int)(r_newrefdef.time * 2);
currententity = &r_worldentity;
- VectorCopy (r_origin, modelorg);
+ VectorCopy(r_origin, modelorg);
- R_RecursiveWorldNode (r_worldmodel->nodes, 15);
+ R_RecursiveWorldNode(r_worldmodel->nodes, 15);
}
diff --git a/src/sw_draw.c b/src/sw_draw.c
index 4c18e0c..50279ac 100644
--- a/src/sw_draw.c
+++ b/src/sw_draw.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,28 +29,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DOSTEP do { \
tbyte = *src++; \
- if( tbyte != 255 ) \
+ if (tbyte != 255) \
*dst = tbyte; \
dst++; \
- } while( 0 )
+ } while (0)
#define DOMSTEP do { \
- if( *src++ != 255 ) \
+ if (*src++ != 255) \
*dst = tbyte; \
dst++; \
- } while( 0 )
+ } while (0)
#define DOSTRETCH do { \
tbyte = src[u >> 16]; \
- if( tbyte != 255 ) \
+ if (tbyte != 255) \
*dst = tbyte; \
dst++; \
u += ustep; \
- } while( 0 )
+ } while (0)
#define ROW1 do { \
DOSTEP; \
- } while( --count );
+ } while (--count);
#define ROW4 do { \
DOSTEP; \
@@ -59,7 +59,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DOSTEP; \
\
count -= 4; \
- } while( count );
+ } while (count);
#define ROW8 do { \
DOSTEP; \
@@ -72,7 +72,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DOSTEP; \
\
count -= 8; \
- } while( count );
+ } while (count);
#define MROW8 do { \
DOMSTEP; \
@@ -85,11 +85,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DOMSTEP; \
\
count -= 8; \
- } while( count );
+ } while (count);
#define STRETCH1 do { \
DOSTRETCH; \
- } while( --count );
+ } while (--count);
#define STRETCH4 do { \
DOSTRETCH; \
@@ -98,7 +98,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DOSTRETCH; \
\
count -= 4; \
- } while( count );
+ } while (count);
#define STRETCH8 do { \
DOSTRETCH; \
@@ -111,7 +111,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DOSTRETCH; \
\
count -= 8; \
- } while( count );
+ } while (count);
typedef struct {
int colorIndex;
@@ -124,38 +124,44 @@ static drawStatic_t draw;
static int colorIndices[8];
-void R_SetScale( float *scale ) {
- if( scale ) {
+void R_SetScale(float *scale)
+{
+ if (scale) {
*scale = 1;
}
}
-void R_InitDraw( void ) {
+void R_InitDraw(void)
+{
int i;
- memset( &draw, 0, sizeof( draw ) );
+ memset(&draw, 0, sizeof(draw));
draw.colorIndex = -1;
- for( i = 0; i < 8; i++ ) {
- colorIndices[i] = R_IndexForColor( colorTable[i] );
+ for (i = 0; i < 8; i++) {
+ colorIndices[i] = R_IndexForColor(colorTable[i]);
}
}
-void R_ClearColor( void ) {
+void R_ClearColor(void)
+{
draw.colorIndex = -1;
}
-void R_SetAlpha( float alpha ) {
+void R_SetAlpha(float alpha)
+{
}
-void R_SetColor( uint32_t color ) {
- draw.colorIndex = R_IndexForColor( color );
+void R_SetColor(uint32_t color)
+{
+ draw.colorIndex = R_IndexForColor(color);
}
-void R_SetClipRect( int flags, const clipRect_t *clip ) {
+void R_SetClipRect(int flags, const clipRect_t *clip)
+{
draw.flags &= ~DRAW_CLIP_MASK;
- if( flags == DRAW_CLIP_DISABLED ) {
+ if (flags == DRAW_CLIP_DISABLED) {
return;
}
draw.flags |= flags;
@@ -167,13 +173,14 @@ void R_SetClipRect( int flags, const clipRect_t *clip ) {
R_GetPicSize
=============
*/
-qboolean R_GetPicSize( int *w, int *h, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+qboolean R_GetPicSize(int *w, int *h, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- if( w ) {
+ if (w) {
*w = image->width;
}
- if( h ) {
+ if (h) {
*h = image->height;
}
return image->flags & if_transparent;
@@ -184,8 +191,8 @@ qboolean R_GetPicSize( int *w, int *h, qhandle_t pic ) {
R_DrawStretchData
=============
*/
-static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
- int ww, int hh, int pitch, byte *data )
+static void R_DrawStretchData(int x, int y, int w, int h, int xx, int yy,
+ int ww, int hh, int pitch, byte *data)
{
byte *srcpixels, *dstpixels, *dst, *src;
int v, u;
@@ -199,13 +206,13 @@ static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
width = w;
height = h;
- if( draw.flags & DRAW_CLIP_MASK ) {
+ if (draw.flags & DRAW_CLIP_MASK) {
clipRect_t *clip = &draw.clipRect;
- if( draw.flags & DRAW_CLIP_LEFT ) {
- if( x < clip->left ) {
+ if (draw.flags & DRAW_CLIP_LEFT) {
+ if (x < clip->left) {
skipu = clip->left - x;
- if( w <= skipu ) {
+ if (w <= skipu) {
return;
}
w -= skipu;
@@ -213,19 +220,19 @@ static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
}
}
- if( draw.flags & DRAW_CLIP_RIGHT ) {
- if( x >= clip->right ) {
+ if (draw.flags & DRAW_CLIP_RIGHT) {
+ if (x >= clip->right) {
return;
}
- if( x + w > clip->right ) {
+ if (x + w > clip->right) {
w = clip->right - x;
}
}
- if( draw.flags & DRAW_CLIP_TOP ) {
- if( y < clip->top ) {
+ if (draw.flags & DRAW_CLIP_TOP) {
+ if (y < clip->top) {
skipv = clip->top - y;
- if( h <= skipv ) {
+ if (h <= skipv) {
return;
}
h -= skipv;
@@ -233,11 +240,11 @@ static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
}
}
- if( draw.flags & DRAW_CLIP_BOTTOM ) {
- if( y >= clip->bottom ) {
+ if (draw.flags & DRAW_CLIP_BOTTOM) {
+ if (y >= clip->bottom) {
return;
}
- if( y + h > clip->bottom ) {
+ if (y + h > clip->bottom) {
h = clip->bottom - y;
}
}
@@ -247,46 +254,46 @@ static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
dstpixels = vid.buffer + y * vid.rowbytes + x;
vstep = hh * 0x10000 / height;
-
+
v = skipv * vstep;
- if( width == ww ) {
+ if (width == ww) {
dstpixels += skipu;
do {
- src = &srcpixels[( v >> 16 ) * pitch];
+ src = &srcpixels[(v >> 16) * pitch];
dst = dstpixels;
count = w;
-
- if( !( w & 7 ) ) {
+
+ if (!(w & 7)) {
ROW8;
- } else if( !( w & 3 ) ) {
+ } else if (!(w & 3)) {
ROW4;
} else {
ROW1;
}
-
+
v += vstep;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
} else {
ustep = ww * 0x10000 / width;
skipu = skipu * ustep;
do {
- src = &srcpixels[( v >> 16 ) * pitch];
+ src = &srcpixels[(v >> 16) * pitch];
dst = dstpixels;
count = w;
u = skipu;
- if( !( w & 7 ) ) {
+ if (!(w & 7)) {
STRETCH8;
- } else if( !( w & 3 ) ) {
+ } else if (!(w & 3)) {
STRETCH4;
} else {
STRETCH1;
}
-
+
v += vstep;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
}
}
@@ -296,8 +303,8 @@ static void R_DrawStretchData( int x, int y, int w, int h, int xx, int yy,
R_DrawFixedData
=============
*/
-static void R_DrawFixedData( int x, int y, int w, int h,
- int pitch, byte *data )
+static void R_DrawFixedData(int x, int y, int w, int h,
+ int pitch, byte *data)
{
byte *srcpixels, *dstpixels;
byte *dst, *src;
@@ -307,13 +314,13 @@ static void R_DrawFixedData( int x, int y, int w, int h,
skipv = skipu = 0;
- if( draw.flags & DRAW_CLIP_MASK ) {
+ if (draw.flags & DRAW_CLIP_MASK) {
clipRect_t *clip = &draw.clipRect;
- if( draw.flags & DRAW_CLIP_LEFT ) {
- if( x < clip->left ) {
+ if (draw.flags & DRAW_CLIP_LEFT) {
+ if (x < clip->left) {
skipu = clip->left - x;
- if( w <= skipu ) {
+ if (w <= skipu) {
return;
}
w -= skipu;
@@ -321,19 +328,19 @@ static void R_DrawFixedData( int x, int y, int w, int h,
}
}
- if( draw.flags & DRAW_CLIP_RIGHT ) {
- if( x >= clip->right ) {
+ if (draw.flags & DRAW_CLIP_RIGHT) {
+ if (x >= clip->right) {
return;
}
- if( x + w > clip->right ) {
+ if (x + w > clip->right) {
w = clip->right - x;
}
}
- if( draw.flags & DRAW_CLIP_TOP ) {
- if( y < clip->top ) {
+ if (draw.flags & DRAW_CLIP_TOP) {
+ if (y < clip->top) {
skipv = clip->top - y;
- if( h <= skipv ) {
+ if (h <= skipv) {
return;
}
h -= skipv;
@@ -341,11 +348,11 @@ static void R_DrawFixedData( int x, int y, int w, int h,
}
}
- if( draw.flags & DRAW_CLIP_BOTTOM ) {
- if( y >= clip->bottom ) {
+ if (draw.flags & DRAW_CLIP_BOTTOM) {
+ if (y >= clip->bottom) {
return;
}
- if( y + h > clip->bottom ) {
+ if (y + h > clip->bottom) {
h = clip->bottom - y;
}
}
@@ -354,22 +361,22 @@ static void R_DrawFixedData( int x, int y, int w, int h,
srcpixels = data + skipv * pitch + skipu;
dstpixels = vid.buffer + y * vid.rowbytes + x;
- if( !( w & 7 ) ) {
+ if (!(w & 7)) {
do {
src = srcpixels;
dst = dstpixels;
count = w; ROW8;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
- } else if( !( w & 3 ) ) {
+ } while (--h);
+ } else if (!(w & 3)) {
do {
src = srcpixels;
dst = dstpixels;
count = w; ROW4;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
} else {
do {
src = srcpixels;
@@ -377,13 +384,13 @@ static void R_DrawFixedData( int x, int y, int w, int h,
count = w; ROW1;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
}
}
-static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
- int pitch, byte *data, byte tbyte )
+static void R_DrawFixedDataAsMask(int x, int y, int w, int h,
+ int pitch, byte *data, byte tbyte)
{
byte *srcpixels, *dstpixels;
byte *dst, *src;
@@ -392,13 +399,13 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
skipv = skipu = 0;
- if( draw.flags & DRAW_CLIP_MASK ) {
+ if (draw.flags & DRAW_CLIP_MASK) {
clipRect_t *clip = &draw.clipRect;
- if( draw.flags & DRAW_CLIP_LEFT ) {
- if( x < clip->left ) {
+ if (draw.flags & DRAW_CLIP_LEFT) {
+ if (x < clip->left) {
skipu = clip->left - x;
- if( w <= skipu ) {
+ if (w <= skipu) {
return;
}
w -= skipu;
@@ -406,19 +413,19 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
}
}
- if( draw.flags & DRAW_CLIP_RIGHT ) {
- if( x >= clip->right ) {
+ if (draw.flags & DRAW_CLIP_RIGHT) {
+ if (x >= clip->right) {
return;
}
- if( x + w > clip->right ) {
+ if (x + w > clip->right) {
w = clip->right - x;
}
}
- if( draw.flags & DRAW_CLIP_TOP ) {
- if( y < clip->top ) {
+ if (draw.flags & DRAW_CLIP_TOP) {
+ if (y < clip->top) {
skipv = clip->top - y;
- if( h <= skipv ) {
+ if (h <= skipv) {
return;
}
h -= skipv;
@@ -426,11 +433,11 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
}
}
- if( draw.flags & DRAW_CLIP_BOTTOM ) {
- if( y <= clip->bottom ) {
+ if (draw.flags & DRAW_CLIP_BOTTOM) {
+ if (y <= clip->bottom) {
return;
}
- if( y + h > clip->bottom ) {
+ if (y + h > clip->bottom) {
h = clip->bottom - y;
}
}
@@ -439,22 +446,22 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
srcpixels = data + skipv * pitch + skipu;
dstpixels = vid.buffer + y * vid.rowbytes + x;
- if( !( w & 7 ) ) {
+ if (!(w & 7)) {
do {
src = srcpixels;
dst = dstpixels;
count = w; MROW8;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
- } else if( !( w & 3 ) ) {
+ } while (--h);
+ } else if (!(w & 3)) {
do {
src = srcpixels;
dst = dstpixels;
count = w; ROW4;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
} else {
do {
src = srcpixels;
@@ -462,7 +469,7 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
count = w; ROW1;
srcpixels += pitch;
dstpixels += vid.rowbytes;
- } while( --h );
+ } while (--h);
}
}
@@ -472,19 +479,19 @@ static void R_DrawFixedDataAsMask( int x, int y, int w, int h,
R_DrawStretcpic
=============
*/
-void R_DrawStretcPicST( int x, int y, int w, int h, float s1, float t1,
- float s2, float t2, qhandle_t pic )
+void R_DrawStretcPicST(int x, int y, int w, int h, float s1, float t1,
+ float s2, float t2, qhandle_t pic)
{
- image_t *image = IMG_ForHandle( pic );
+ image_t *image = IMG_ForHandle(pic);
int xx, yy, ww, hh;
xx = image->width * s1;
yy = image->height * t1;
- ww = image->width * ( s2 - s1 );
- hh = image->height * ( t2 - t1 );
+ ww = image->width * (s2 - s1);
+ hh = image->height * (t2 - t1);
- R_DrawStretchData( x, y, w, h, xx, yy, ww, hh,
- image->width, image->pixels[0] );
+ R_DrawStretchData(x, y, w, h, xx, yy, ww, hh,
+ image->width, image->pixels[0]);
}
/*
@@ -492,17 +499,18 @@ void R_DrawStretcPicST( int x, int y, int w, int h, float s1, float t1,
R_DrawStretchPic
=============
*/
-void R_DrawStretchPic( int x, int y, int w, int h, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- if( w == image->width && h == image->height ) {
- R_DrawFixedData( x, y, image->width, image->height,
- image->width, image->pixels[0] );
+ if (w == image->width && h == image->height) {
+ R_DrawFixedData(x, y, image->width, image->height,
+ image->width, image->pixels[0]);
return;
}
- R_DrawStretchData( x, y, w, h, 0, 0, image->width, image->height,
- image->width, image->pixels[0] );
+ R_DrawStretchData(x, y, w, h, 0, 0, image->width, image->height,
+ image->width, image->pixels[0]);
}
/*
@@ -510,33 +518,35 @@ void R_DrawStretchPic( int x, int y, int w, int h, qhandle_t pic ) {
R_DrawStretcpic
=============
*/
-void R_DrawPic( int x, int y, qhandle_t pic ) {
- image_t *image = IMG_ForHandle( pic );
+void R_DrawPic(int x, int y, qhandle_t pic)
+{
+ image_t *image = IMG_ForHandle(pic);
- R_DrawFixedData( x, y, image->width, image->height,
- image->width, image->pixels[0] );
+ R_DrawFixedData(x, y, image->width, image->height,
+ image->width, image->pixels[0]);
}
-void R_DrawChar( int x, int y, int flags, int ch, qhandle_t font ) {
+void R_DrawChar(int x, int y, int flags, int ch, qhandle_t font)
+{
image_t *image;
int xx, yy;
byte *data;
- if( !font ) {
+ if (!font) {
return;
}
- image = IMG_ForHandle( font );
- if( image->width != 128 || image->height != 128 ) {
+ image = IMG_ForHandle(font);
+ if (image->width != 128 || image->height != 128) {
return;
}
- xx = ( ch & 15 ) << 3;
- yy = ( ( ch >> 4 ) & 15 ) << 3;
+ xx = (ch & 15) << 3;
+ yy = ((ch >> 4) & 15) << 3;
data = image->pixels[0] + yy * image->width + xx;
- if( draw.colorIndex != -1 && !( ch & 128 ) ) {
- R_DrawFixedDataAsMask( x, y, 8, 8, image->width, data, draw.colorIndex );
+ if (draw.colorIndex != -1 && !(ch & 128)) {
+ R_DrawFixedDataAsMask(x, y, 8, 8, image->width, data, draw.colorIndex);
} else {
- R_DrawFixedData( x, y, 8, 8, image->width, data );
+ R_DrawFixedData(x, y, 8, 8, image->width, data);
}
}
@@ -545,8 +555,8 @@ void R_DrawChar( int x, int y, int flags, int ch, qhandle_t font ) {
R_DrawString
===============
*/
-int R_DrawString( int x, int y, int flags, size_t maxChars,
- const char *string, qhandle_t font )
+int R_DrawString(int x, int y, int flags, size_t maxChars,
+ const char *string, qhandle_t font)
{
image_t *image;
byte c, *data;
@@ -554,33 +564,33 @@ int R_DrawString( int x, int y, int flags, size_t maxChars,
int color;
qboolean alt;
- if( !font ) {
+ if (!font) {
return x;
}
- image = IMG_ForHandle( font );
- if( image->width != 128 || image->height != 128 ) {
+ image = IMG_ForHandle(font);
+ if (image->width != 128 || image->height != 128) {
return x;
}
- alt = ( flags & UI_ALTCOLOR ) ? qtrue : qfalse;
+ alt = (flags & UI_ALTCOLOR) ? qtrue : qfalse;
color = draw.colorIndex;
- while( maxChars-- && *string ) {
+ while (maxChars-- && *string) {
c = *string++;
- if( ( c & 127 ) == 32 ) {
+ if ((c & 127) == 32) {
x += 8;
continue;
}
c |= alt << 7;
- xx = ( c & 15 ) << 3;
- yy = ( c >> 4 ) << 3;
+ xx = (c & 15) << 3;
+ yy = (c >> 4) << 3;
data = image->pixels[0] + yy * image->width + xx;
- if( color != -1 && !( c & 128 ) ) {
- R_DrawFixedDataAsMask( x, y, 8, 8, image->width, data, color );
+ if (color != -1 && !(c & 128)) {
+ R_DrawFixedDataAsMask(x, y, 8, 8, image->width, data, color);
} else {
- R_DrawFixedData( x, y, 8, 8, image->width, data );
+ R_DrawFixedData(x, y, 8, 8, image->width, data);
}
x += 8;
@@ -596,14 +606,15 @@ This repeats a 64*64 tile graphic to fill the screen around a sized down
refresh window.
=============
*/
-void R_TileClear( int x, int y, int w, int h, qhandle_t pic ) {
+void R_TileClear(int x, int y, int w, int h, qhandle_t pic)
+{
int i, j;
byte *psrc;
byte *pdest;
image_t *image;
int x2;
- if( !pic ) {
+ if (!pic) {
return;
}
@@ -622,16 +633,16 @@ void R_TileClear( int x, int y, int w, int h, qhandle_t pic ) {
if (w <= 0 || h <= 0)
return;
- image = IMG_ForHandle( pic );
- if( image->width != 64 || image->height != 64 ) {
+ image = IMG_ForHandle(pic);
+ if (image->width != 64 || image->height != 64) {
return;
}
x2 = x + w;
- pdest = vid.buffer + y*vid.rowbytes;
- for (i=0 ; i<h ; i++, pdest += vid.rowbytes) {
- psrc = image->pixels[0] + image->width * ((i+y)&63);
- for (j=x ; j<x2 ; j++)
- pdest[j] = psrc[j&63];
+ pdest = vid.buffer + y * vid.rowbytes;
+ for (i = 0; i < h; i++, pdest += vid.rowbytes) {
+ psrc = image->pixels[0] + image->width * ((i + y) & 63);
+ for (j = x; j < x2; j++)
+ pdest[j] = psrc[j & 63];
}
}
@@ -643,73 +654,75 @@ R_DrawFill
Fills a box of pixels with a single color
=============
*/
-void R_DrawFill8( int x, int y, int w, int h, int c ) {
+void R_DrawFill8(int x, int y, int w, int h, int c)
+{
byte *dest;
int u, v;
- if( x + w > vid.width )
+ if (x + w > vid.width)
w = vid.width - x;
- if( y + h > vid.height )
+ if (y + h > vid.height)
h = vid.height - y;
- if( x < 0 ) {
+ if (x < 0) {
w += x;
x = 0;
}
- if( y < 0 ) {
+ if (y < 0) {
h += y;
y = 0;
}
- if( w < 0 || h < 0 )
+ if (w < 0 || h < 0)
return;
dest = vid.buffer + y * vid.rowbytes + x;
- for( v = 0; v < h; v++, dest += vid.rowbytes )
- for( u = 0; u < w; u++ )
+ for (v = 0; v < h; v++, dest += vid.rowbytes)
+ for (u = 0; u < w; u++)
dest[u] = c;
}
-void R_DrawFill32( int x, int y, int w, int h, uint32_t color ) {
+void R_DrawFill32(int x, int y, int w, int h, uint32_t color)
+{
int c;
byte *dest;
int u, v;
int alpha;
- if( x + w > vid.width )
+ if (x + w > vid.width)
w = vid.width - x;
- if( y + h > vid.height )
+ if (y + h > vid.height)
h = vid.height - y;
- if( x < 0 ) {
+ if (x < 0) {
w += x;
x = 0;
}
- if( y < 0 ) {
+ if (y < 0) {
h += y;
y = 0;
}
- if( w < 0 || h < 0 )
+ if (w < 0 || h < 0)
return;
- c = R_IndexForColor( color );
- alpha = ( LittleLong( color ) >> 24 ) & 0xff;
+ c = R_IndexForColor(color);
+ alpha = (LittleLong(color) >> 24) & 0xff;
dest = vid.buffer + y * vid.rowbytes + x;
- if( alpha < 172 ) {
- if( alpha > 84 ) {
- for( v = 0; v < h; v++, dest += vid.rowbytes ) {
- for( u = 0 ; u < w; u++ ) {
+ if (alpha < 172) {
+ if (alpha > 84) {
+ for (v = 0; v < h; v++, dest += vid.rowbytes) {
+ for (u = 0; u < w; u++) {
dest[u] = vid.alphamap[c * 256 + dest[u]];
}
}
} else {
- for( v = 0; v < h; v++, dest += vid.rowbytes ) {
- for( u = 0 ; u < w; u++ ) {
+ for (v = 0; v < h; v++, dest += vid.rowbytes) {
+ for (u = 0; u < w; u++) {
dest[u] = vid.alphamap[c + dest[u] * 256];
}
}
}
} else {
- for( v = 0; v < h; v++, dest += vid.rowbytes ) {
- for( u = 0 ; u < w; u++ ) {
+ for (v = 0; v < h; v++, dest += vid.rowbytes) {
+ for (u = 0; u < w; u++) {
dest[u] = c;
}
}
@@ -725,19 +738,17 @@ R_DrawFadeScreen
================
*/
-void R_DrawFadeScreen (void)
+void R_DrawFadeScreen(void)
{
- int x,y;
+ int x, y;
byte *pbuf;
int t;
- for (y=0 ; y<vid.height ; y++)
- {
- pbuf = (byte *)(vid.buffer + vid.rowbytes*y);
+ for (y = 0; y < vid.height; y++) {
+ pbuf = (byte *)(vid.buffer + vid.rowbytes * y);
t = (y & 1) << 1;
- for (x=0 ; x<vid.width ; x++)
- {
+ for (x = 0; x < vid.width; x++) {
if ((x & 3) != t)
pbuf[x] = 0;
}
diff --git a/src/sw_edge.c b/src/sw_edge.c
index 017783e..860b09b 100644
--- a/src/sw_edge.c
+++ b/src/sw_edge.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,15 +22,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sw_local.h"
#if !USE_ASM
-void R_SurfacePatch (void)
+void R_SurfacePatch(void)
{
}
-void R_EdgeCodeStart (void)
+void R_EdgeCodeStart(void)
{
}
-void R_EdgeCodeEnd (void)
+void R_EdgeCodeEnd(void)
{
}
#endif
@@ -80,17 +80,17 @@ float scale_for_mip;
int ubasestep, errorterm, erroradjustup, erroradjustdown;
// FIXME: should go away
-extern void R_RotateBmodel (void);
-extern void R_TransformFrustum (void);
+extern void R_RotateBmodel(void);
+extern void R_TransformFrustum(void);
-void R_GenerateSpans (void);
-void R_GenerateSpansBackward (void);
+void R_GenerateSpans(void);
+void R_GenerateSpansBackward(void);
-void R_LeadingEdge (edge_t *edge);
-void R_LeadingEdgeBackwards (edge_t *edge);
-void R_TrailingEdge (surf_t *surf, edge_t *edge);
+void R_LeadingEdge(edge_t *edge);
+void R_LeadingEdgeBackwards(edge_t *edge);
+void R_TrailingEdge(surf_t *surf, edge_t *edge);
/*
@@ -106,7 +106,7 @@ EDGE SCANNING
R_BeginEdgeFrame
==============
*/
-void R_BeginEdgeFrame (void)
+void R_BeginEdgeFrame(void)
{
int v;
@@ -114,27 +114,23 @@ void R_BeginEdgeFrame (void)
edge_max = &r_edges[r_numallocatededges];
surface_p = &surfaces[2]; // background is surface 1,
- // surface 0 is a dummy
+ // surface 0 is a dummy
surfaces[1].spans = NULL; // no background spans yet
surfaces[1].flags = DSURF_BACKGROUND;
// put the background behind everything in the world
- if (sw_draworder->value)
- {
+ if (sw_draworder->value) {
pdrawfunc = R_GenerateSpansBackward;
surfaces[1].key = 0;
r_currentkey = 1;
- }
- else
- {
+ } else {
pdrawfunc = R_GenerateSpans;
surfaces[1].key = 0x7FFFFFFF;
r_currentkey = 0;
}
// FIXME: set with memset
- for (v=r_refdef.vrect.y ; v<r_refdef.vrectbottom ; v++)
- {
+ for (v = r_refdef.vrect.y; v < r_refdef.vrectbottom; v++) {
newedges[v] = removeedges[v] = NULL;
}
}
@@ -152,29 +148,28 @@ sentinel at the end (actually, this is the active edge table starting at
edge_head.next).
==============
*/
-void R_InsertNewEdges (edge_t *edgestoadd, edge_t *edgelist)
+void R_InsertNewEdges(edge_t *edgestoadd, edge_t *edgelist)
{
edge_t *next_edge;
- do
- {
+ do {
next_edge = edgestoadd->next;
edgesearch:
if (edgelist->u >= edgestoadd->u)
goto addedge;
- edgelist=edgelist->next;
+ edgelist = edgelist->next;
if (edgelist->u >= edgestoadd->u)
goto addedge;
- edgelist=edgelist->next;
+ edgelist = edgelist->next;
if (edgelist->u >= edgestoadd->u)
goto addedge;
- edgelist=edgelist->next;
+ edgelist = edgelist->next;
if (edgelist->u >= edgestoadd->u)
goto addedge;
- edgelist=edgelist->next;
+ edgelist = edgelist->next;
goto edgesearch;
- // insert edgestoadd before edgelist
+ // insert edgestoadd before edgelist
addedge:
edgestoadd->next = edgelist;
edgestoadd->prev = edgelist->prev;
@@ -188,11 +183,10 @@ addedge:
R_RemoveEdges
==============
*/
-void R_RemoveEdges (edge_t *pedge)
+void R_RemoveEdges(edge_t *pedge)
{
- do
- {
+ do {
pedge->next->prev = pedge->prev;
pedge->prev->next = pedge->next;
} while ((pedge = pedge->nextremove) != NULL);
@@ -203,55 +197,53 @@ void R_RemoveEdges (edge_t *pedge)
R_StepActiveU
==============
*/
-void R_StepActiveU (edge_t *pedge)
+void R_StepActiveU(edge_t *pedge)
{
edge_t *pnext_edge, *pwedge;
- while (1)
- {
+ while (1) {
nextedge:
pedge->u += pedge->u_step;
if (pedge->u < pedge->prev->u)
goto pushback;
pedge = pedge->next;
-
+
pedge->u += pedge->u_step;
if (pedge->u < pedge->prev->u)
goto pushback;
pedge = pedge->next;
-
+
pedge->u += pedge->u_step;
if (pedge->u < pedge->prev->u)
goto pushback;
pedge = pedge->next;
-
+
pedge->u += pedge->u_step;
if (pedge->u < pedge->prev->u)
goto pushback;
pedge = pedge->next;
-
- goto nextedge;
-
+
+ goto nextedge;
+
pushback:
if (pedge == &edge_aftertail)
return;
-
- // push it back to keep it sorted
+
+ // push it back to keep it sorted
pnext_edge = pedge->next;
- // pull the edge out of the edge list
+ // pull the edge out of the edge list
pedge->next->prev = pedge->prev;
pedge->prev->next = pedge->next;
- // find out where the edge goes in the edge list
+ // find out where the edge goes in the edge list
pwedge = pedge->prev->prev;
- while (pwedge->u > pedge->u)
- {
+ while (pwedge->u > pedge->u) {
pwedge = pwedge->prev;
}
- // put the edge back into the edge list
+ // put the edge back into the edge list
pedge->next = pwedge->next;
pedge->prev = pwedge;
pedge->next->prev = pedge;
@@ -271,7 +263,7 @@ pushback:
R_CleanupSpan
==============
*/
-void R_CleanupSpan (void)
+void R_CleanupSpan(void)
{
surf_t *surf;
int iu;
@@ -281,8 +273,7 @@ void R_CleanupSpan (void)
// unfinished surfaces, so emit a span for whatever's on top
surf = surfaces[1].next;
iu = edge_tail_u_shift20;
- if (iu > surf->last_u)
- {
+ if (iu > surf->last_u) {
span = span_p++;
span->u = surf->last_u;
span->count = iu - span->u;
@@ -292,8 +283,7 @@ void R_CleanupSpan (void)
}
// reset spanstate for all surfaces in the surface stack
- do
- {
+ do {
surf->spanstate = 0;
surf = surf->next;
} while (surf != &surfaces[1]);
@@ -305,7 +295,7 @@ void R_CleanupSpan (void)
R_LeadingEdgeBackwards
==============
*/
-void R_LeadingEdgeBackwards (edge_t *edge)
+void R_LeadingEdgeBackwards(edge_t *edge)
{
espan_t *span;
surf_t *surf, *surf2;
@@ -317,48 +307,43 @@ void R_LeadingEdgeBackwards (edge_t *edge)
// don't start a span if this is an inverted span, with the end
// edge preceding the start edge (that is, we've already seen the
// end edge)
- if (++surf->spanstate == 1)
- {
+ if (++surf->spanstate == 1) {
surf2 = surfaces[1].next;
if (surf->key > surf2->key)
goto newtop;
- // if it's two surfaces on the same plane, the one that's already
- // active is in front, so keep going unless it's a bmodel
- if (surf->insubmodel && (surf->key == surf2->key))
- {
- // must be two bmodels in the same leaf; don't care, because they'll
- // never be farthest anyway
+ // if it's two surfaces on the same plane, the one that's already
+ // active is in front, so keep going unless it's a bmodel
+ if (surf->insubmodel && (surf->key == surf2->key)) {
+ // must be two bmodels in the same leaf; don't care, because they'll
+ // never be farthest anyway
goto newtop;
}
continue_search:
- do
- {
+ do {
surf2 = surf2->next;
} while (surf->key < surf2->key);
- if (surf->key == surf2->key)
- {
- // if it's two surfaces on the same plane, the one that's already
- // active is in front, so keep going unless it's a bmodel
+ if (surf->key == surf2->key) {
+ // if it's two surfaces on the same plane, the one that's already
+ // active is in front, so keep going unless it's a bmodel
if (!surf->insubmodel)
goto continue_search;
- // must be two bmodels in the same leaf; don't care which is really
- // in front, because they'll never be farthest anyway
+ // must be two bmodels in the same leaf; don't care which is really
+ // in front, because they'll never be farthest anyway
}
goto gotposition;
newtop:
- // emit a span (obscures current top)
+ // emit a span (obscures current top)
iu = edge->u >> 20;
- if (iu > surf2->last_u)
- {
+ if (iu > surf2->last_u) {
span = span_p++;
span->u = surf2->last_u;
span->count = iu - span->u;
@@ -369,9 +354,9 @@ newtop:
// set last_u on the new span
surf->last_u = iu;
-
+
gotposition:
- // insert before surf2
+ // insert before surf2
surf->next = surf2;
surf->prev = surf2->prev;
surf2->prev->next = surf;
@@ -385,7 +370,7 @@ gotposition:
R_TrailingEdge
==============
*/
-void R_TrailingEdge (surf_t *surf, edge_t *edge)
+void R_TrailingEdge(surf_t *surf, edge_t *edge)
{
espan_t *span;
int iu;
@@ -393,14 +378,11 @@ void R_TrailingEdge (surf_t *surf, edge_t *edge)
// don't generate a span if this is an inverted span, with the end
// edge preceding the start edge (that is, we haven't seen the
// start edge yet)
- if (--surf->spanstate == 0)
- {
- if (surf == surfaces[1].next)
- {
- // emit a span (current top going away)
+ if (--surf->spanstate == 0) {
+ if (surf == surfaces[1].next) {
+ // emit a span (current top going away)
iu = edge->u >> 20;
- if (iu > surf->last_u)
- {
+ if (iu > surf->last_u) {
span = span_p++;
span->u = surf->last_u;
span->count = iu - span->u;
@@ -409,7 +391,7 @@ void R_TrailingEdge (surf_t *surf, edge_t *edge)
surf->spans = span;
}
- // set last_u on the surface below
+ // set last_u on the surface below
surf->next->last_u = iu;
}
@@ -426,51 +408,45 @@ void R_TrailingEdge (surf_t *surf, edge_t *edge)
R_LeadingEdge
==============
*/
-void R_LeadingEdge (edge_t *edge)
+void R_LeadingEdge(edge_t *edge)
{
espan_t *span;
surf_t *surf, *surf2;
int iu;
float fu, newzi, testzi, newzitop, newzibottom;
- if (edge->surfs[1])
- {
- // it's adding a new surface in, so find the correct place
+ if (edge->surfs[1]) {
+ // it's adding a new surface in, so find the correct place
surf = &surfaces[edge->surfs[1]];
- // don't start a span if this is an inverted span, with the end
- // edge preceding the start edge (that is, we've already seen the
- // end edge)
- if (++surf->spanstate == 1)
- {
+ // don't start a span if this is an inverted span, with the end
+ // edge preceding the start edge (that is, we've already seen the
+ // end edge)
+ if (++surf->spanstate == 1) {
surf2 = surfaces[1].next;
if (surf->key < surf2->key)
goto newtop;
- // if it's two surfaces on the same plane, the one that's already
- // active is in front, so keep going unless it's a bmodel
- if (surf->insubmodel && (surf->key == surf2->key))
- {
- // must be two bmodels in the same leaf; sort on 1/z
+ // if it's two surfaces on the same plane, the one that's already
+ // active is in front, so keep going unless it's a bmodel
+ if (surf->insubmodel && (surf->key == surf2->key)) {
+ // must be two bmodels in the same leaf; sort on 1/z
fu = (float)(edge->u - 0xFFFFF) * (1.0 / 0x100000);
- newzi = surf->d_ziorigin + fv*surf->d_zistepv +
- fu*surf->d_zistepu;
+ newzi = surf->d_ziorigin + fv * surf->d_zistepv +
+ fu * surf->d_zistepu;
newzibottom = newzi * 0.99;
- testzi = surf2->d_ziorigin + fv*surf2->d_zistepv +
- fu*surf2->d_zistepu;
+ testzi = surf2->d_ziorigin + fv * surf2->d_zistepv +
+ fu * surf2->d_zistepu;
- if (newzibottom >= testzi)
- {
+ if (newzibottom >= testzi) {
goto newtop;
}
newzitop = newzi * 1.01;
- if (newzitop >= testzi)
- {
- if (surf->d_zistepu >= surf2->d_zistepu)
- {
+ if (newzitop >= testzi) {
+ if (surf->d_zistepu >= surf2->d_zistepu) {
goto newtop;
}
}
@@ -478,37 +454,32 @@ void R_LeadingEdge (edge_t *edge)
continue_search:
- do
- {
+ do {
surf2 = surf2->next;
} while (surf->key > surf2->key);
- if (surf->key == surf2->key)
- {
- // if it's two surfaces on the same plane, the one that's already
- // active is in front, so keep going unless it's a bmodel
+ if (surf->key == surf2->key) {
+ // if it's two surfaces on the same plane, the one that's already
+ // active is in front, so keep going unless it's a bmodel
if (!surf->insubmodel)
goto continue_search;
- // must be two bmodels in the same leaf; sort on 1/z
+ // must be two bmodels in the same leaf; sort on 1/z
fu = (float)(edge->u - 0xFFFFF) * (1.0 / 0x100000);
- newzi = surf->d_ziorigin + fv*surf->d_zistepv +
- fu*surf->d_zistepu;
+ newzi = surf->d_ziorigin + fv * surf->d_zistepv +
+ fu * surf->d_zistepu;
newzibottom = newzi * 0.99;
- testzi = surf2->d_ziorigin + fv*surf2->d_zistepv +
- fu*surf2->d_zistepu;
+ testzi = surf2->d_ziorigin + fv * surf2->d_zistepv +
+ fu * surf2->d_zistepu;
- if (newzibottom >= testzi)
- {
+ if (newzibottom >= testzi) {
goto gotposition;
}
newzitop = newzi * 1.01;
- if (newzitop >= testzi)
- {
- if (surf->d_zistepu >= surf2->d_zistepu)
- {
+ if (newzitop >= testzi) {
+ if (surf->d_zistepu >= surf2->d_zistepu) {
goto gotposition;
}
}
@@ -519,11 +490,10 @@ continue_search:
goto gotposition;
newtop:
- // emit a span (obscures current top)
+ // emit a span (obscures current top)
iu = edge->u >> 20;
- if (iu > surf2->last_u)
- {
+ if (iu > surf2->last_u) {
span = span_p++;
span->u = surf2->last_u;
span->count = iu - span->u;
@@ -534,9 +504,9 @@ newtop:
// set last_u on the new span
surf->last_u = iu;
-
+
gotposition:
- // insert before surf2
+ // insert before surf2
surf->next = surf2;
surf->prev = surf2->prev;
surf2->prev->next = surf;
@@ -551,7 +521,7 @@ gotposition:
R_GenerateSpans
==============
*/
-void R_GenerateSpans (void)
+void R_GenerateSpans(void)
{
edge_t *edge;
surf_t *surf;
@@ -561,23 +531,21 @@ void R_GenerateSpans (void)
surfaces[1].last_u = edge_head_u_shift20;
// generate spans
- for (edge=edge_head.next ; edge != &edge_tail; edge=edge->next)
- {
- if (edge->surfs[0])
- {
- // it has a left surface, so a surface is going away for this span
+ for (edge = edge_head.next; edge != &edge_tail; edge = edge->next) {
+ if (edge->surfs[0]) {
+ // it has a left surface, so a surface is going away for this span
surf = &surfaces[edge->surfs[0]];
- R_TrailingEdge (surf, edge);
+ R_TrailingEdge(surf, edge);
if (!edge->surfs[1])
continue;
}
- R_LeadingEdge (edge);
+ R_LeadingEdge(edge);
}
- R_CleanupSpan ();
+ R_CleanupSpan();
}
#endif // !USE_ASM
@@ -588,7 +556,7 @@ void R_GenerateSpans (void)
R_GenerateSpansBackward
==============
*/
-void R_GenerateSpansBackward (void)
+void R_GenerateSpansBackward(void)
{
edge_t *edge;
@@ -597,16 +565,15 @@ void R_GenerateSpansBackward (void)
surfaces[1].last_u = edge_head_u_shift20;
// generate spans
- for (edge=edge_head.next ; edge != &edge_tail; edge=edge->next)
- {
+ for (edge = edge_head.next; edge != &edge_tail; edge = edge->next) {
if (edge->surfs[0])
- R_TrailingEdge (&surfaces[edge->surfs[0]], edge);
+ R_TrailingEdge(&surfaces[edge->surfs[0]], edge);
if (edge->surfs[1])
- R_LeadingEdgeBackwards (edge);
+ R_LeadingEdgeBackwards(edge);
}
- R_CleanupSpan ();
+ R_CleanupSpan();
}
@@ -614,7 +581,7 @@ void R_GenerateSpansBackward (void)
==============
R_ScanEdges
-Input:
+Input:
newedges[] array
this has links to edges, which have links to surfaces
@@ -622,15 +589,15 @@ Output:
Each surface has a linked list of its visible spans
==============
*/
-void R_ScanEdges (void)
+void R_ScanEdges(void)
{
int iv, bottom;
- byte basespans[MAXSPANS*sizeof(espan_t)+CACHE_SIZE];
+ byte basespans[MAXSPANS * sizeof(espan_t) + CACHE_SIZE];
espan_t *basespan_p;
surf_t *s;
basespan_p = (espan_t *)
- ((long)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ ((long)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
max_span_p = &basespan_p[MAXSPANS - r_refdef.vrect.width];
span_p = basespan_p;
@@ -644,7 +611,7 @@ void R_ScanEdges (void)
edge_head.next = &edge_tail;
edge_head.surfs[0] = 0;
edge_head.surfs[1] = 1;
-
+
edge_tail.u = (r_refdef.vrectright << 20) + 0xFFFFF;
edge_tail_u_shift20 = edge_tail.u >> 20;
edge_tail.u_step = 0;
@@ -652,7 +619,7 @@ void R_ScanEdges (void)
edge_tail.next = &edge_aftertail;
edge_tail.surfs[0] = 1;
edge_tail.surfs[1] = 0;
-
+
edge_aftertail.u = -1; // force a move
edge_aftertail.u_step = 0;
edge_aftertail.next = &edge_sentinel;
@@ -662,44 +629,41 @@ void R_ScanEdges (void)
edge_sentinel.u = 2000 << 24; // make sure nothing sorts past this
edge_sentinel.prev = &edge_aftertail;
-//
+//
// process all scan lines
//
bottom = r_refdef.vrectbottom - 1;
- for (iv=r_refdef.vrect.y ; iv<bottom ; iv++)
- {
+ for (iv = r_refdef.vrect.y; iv < bottom; iv++) {
current_iv = iv;
fv = (float)iv;
- // mark that the head (background start) span is pre-included
+ // mark that the head (background start) span is pre-included
surfaces[1].spanstate = 1;
- if (newedges[iv])
- {
- R_InsertNewEdges (newedges[iv], edge_head.next);
+ if (newedges[iv]) {
+ R_InsertNewEdges(newedges[iv], edge_head.next);
}
- (*pdrawfunc) ();
+ (*pdrawfunc)();
- // flush the span list if we can't be sure we have enough spans left for
- // the next scan
- if (span_p > max_span_p)
- {
- D_DrawSurfaces ();
+ // flush the span list if we can't be sure we have enough spans left for
+ // the next scan
+ if (span_p > max_span_p) {
+ D_DrawSurfaces();
- // clear the surface span pointers
- for (s = &surfaces[1] ; s<surface_p ; s++)
+ // clear the surface span pointers
+ for (s = &surfaces[1]; s < surface_p; s++)
s->spans = NULL;
span_p = basespan_p;
}
if (removeedges[iv])
- R_RemoveEdges (removeedges[iv]);
+ R_RemoveEdges(removeedges[iv]);
if (edge_head.next != &edge_tail)
- R_StepActiveU (edge_head.next);
+ R_StepActiveU(edge_head.next);
}
// do the last scan (no need to step or sort or remove on the last scan)
@@ -711,12 +675,12 @@ void R_ScanEdges (void)
surfaces[1].spanstate = 1;
if (newedges[iv])
- R_InsertNewEdges (newedges[iv], edge_head.next);
+ R_InsertNewEdges(newedges[iv], edge_head.next);
- (*pdrawfunc) ();
+ (*pdrawfunc)();
// draw whatever's left in the span list
- D_DrawSurfaces ();
+ D_DrawSurfaces();
}
@@ -739,15 +703,15 @@ vec3_t local_modelorg;
D_MipLevelForScale
=============
*/
-int D_MipLevelForScale (float scale)
+int D_MipLevelForScale(float scale)
{
int lmiplevel;
- if (scale >= d_scalemip[0] )
+ if (scale >= d_scalemip[0])
lmiplevel = 0;
- else if (scale >= d_scalemip[1] )
+ else if (scale >= d_scalemip[1])
lmiplevel = 1;
- else if (scale >= d_scalemip[2] )
+ else if (scale >= d_scalemip[2])
lmiplevel = 2;
else
lmiplevel = 3;
@@ -766,18 +730,19 @@ D_FlatFillSurface
Simple single color fill with no texture mapping
==============
*/
-void D_FlatFillSurface( surf_t *surf, uint32_t color ) {
+void D_FlatFillSurface(surf_t *surf, uint32_t color)
+{
espan_t *span;
byte *pdest;
int count;
-
- for( span = surf->spans; span; span = span->pnext ) {
- pdest = ( byte * )d_viewbuffer +
- r_screenwidth * span->v + span->u;
+
+ for (span = surf->spans; span; span = span->pnext) {
+ pdest = (byte *)d_viewbuffer +
+ r_screenwidth * span->v + span->u;
count = span->count;
do {
*pdest++ = color & 0xff;
- } while( --count );
+ } while (--count);
}
}
@@ -787,7 +752,7 @@ void D_FlatFillSurface( surf_t *surf, uint32_t color ) {
D_CalcGradients
==============
*/
-void D_CalcGradients (mface_t *pface)
+void D_CalcGradients(mface_t *pface)
{
cplane_t *pplane;
float mipscale;
@@ -799,8 +764,8 @@ void D_CalcGradients (mface_t *pface)
mipscale = 1.0 / (float)(1 << miplevel);
- TransformVector (pface->texinfo->axis[0], p_saxis);
- TransformVector (pface->texinfo->axis[1], p_taxis);
+ TransformVector(pface->texinfo->axis[0], p_saxis);
+ TransformVector(pface->texinfo->axis[1], p_taxis);
t = xscaleinv * mipscale;
d_sdivzstepu = p_saxis[0] * t;
@@ -811,27 +776,26 @@ void D_CalcGradients (mface_t *pface)
d_tdivzstepv = -p_taxis[1] * t;
d_sdivzorigin = p_saxis[2] * mipscale - xcenter * d_sdivzstepu -
- ycenter * d_sdivzstepv;
+ ycenter * d_sdivzstepv;
d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu -
- ycenter * d_tdivzstepv;
+ ycenter * d_tdivzstepv;
- VectorScale (transformed_modelorg, mipscale, p_temp1);
+ VectorScale(transformed_modelorg, mipscale, p_temp1);
- t = 0x10000*mipscale;
- sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
- ((pface->texturemins[0] << 16) >> miplevel)
- + pface->texinfo->offset[0]*t;
- tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
- ((pface->texturemins[1] << 16) >> miplevel)
- + pface->texinfo->offset[1]*t;
+ t = 0x10000 * mipscale;
+ sadjust = ((fixed16_t)(DotProduct(p_temp1, p_saxis) * 0x10000 + 0.5)) -
+ ((pface->texturemins[0] << 16) >> miplevel)
+ + pface->texinfo->offset[0] * t;
+ tadjust = ((fixed16_t)(DotProduct(p_temp1, p_taxis) * 0x10000 + 0.5)) -
+ ((pface->texturemins[1] << 16) >> miplevel)
+ + pface->texinfo->offset[1] * t;
// PGM - changing flow speed for non-warping textures.
- if (pface->texinfo->c.flags & SURF_FLOWING)
- {
- if(pface->texinfo->c.flags & SURF_WARP)
- sadjust += 0x10000 * (-128 * ( (r_newrefdef.time * 0.25) - (int)(r_newrefdef.time * 0.25) ));
+ if (pface->texinfo->c.flags & SURF_FLOWING) {
+ if (pface->texinfo->c.flags & SURF_WARP)
+ sadjust += 0x10000 * (-128 * ((r_newrefdef.time * 0.25) - (int)(r_newrefdef.time * 0.25)));
else
- sadjust += 0x10000 * (-128 * ( (r_newrefdef.time * 0.77) - (int)(r_newrefdef.time * 0.77) ));
+ sadjust += 0x10000 * (-128 * ((r_newrefdef.time * 0.77) - (int)(r_newrefdef.time * 0.77)));
}
// PGM
@@ -850,7 +814,7 @@ D_BackgroundSurf
The grey background filler seen when there is a hole in the map
==============
*/
-void D_BackgroundSurf (surf_t *s)
+void D_BackgroundSurf(surf_t *s)
{
// set up a gradient for the background surface that places it
// effectively at infinity distance from the viewpoint
@@ -858,8 +822,8 @@ void D_BackgroundSurf (surf_t *s)
d_zistepv = 0;
d_ziorigin = -0.9;
- D_FlatFillSurface (s, sw_clearcolor->integer & 0xFF);
- D_DrawZSpans (s->spans);
+ D_FlatFillSurface(s, sw_clearcolor->integer & 0xFF);
+ D_DrawZSpans(s->spans);
}
/*
@@ -867,7 +831,7 @@ void D_BackgroundSurf (surf_t *s)
D_TurbulentSurf
=================
*/
-void D_TurbulentSurf (surf_t *s)
+void D_TurbulentSurf(surf_t *s)
{
d_zistepu = s->d_zistepu;
d_zistepv = s->d_zistepv;
@@ -878,48 +842,46 @@ void D_TurbulentSurf (surf_t *s)
cacheblock = pface->texinfo->image->pixels[0];
cachewidth = 64;
- if (s->insubmodel)
- {
- // FIXME: we don't want to do all this for every polygon!
- // TODO: store once at start of frame
+ if (s->insubmodel) {
+ // FIXME: we don't want to do all this for every polygon!
+ // TODO: store once at start of frame
currententity = s->entity; //FIXME: make this passed in to
- // R_RotateBmodel ()
- VectorSubtract (r_origin, currententity->origin,
- local_modelorg);
- TransformVector (local_modelorg, transformed_modelorg);
+ // R_RotateBmodel ()
+ VectorSubtract(r_origin, currententity->origin,
+ local_modelorg);
+ TransformVector(local_modelorg, transformed_modelorg);
- R_RotateBmodel (); // FIXME: don't mess with the frustum,
- // make entity passed in
+ R_RotateBmodel(); // FIXME: don't mess with the frustum,
+ // make entity passed in
}
- D_CalcGradients (pface);
+ D_CalcGradients(pface);
//============
//PGM
// textures that aren't warping are just flowing. Use NonTurbulent8 instead
- if(!(pface->texinfo->c.flags & SURF_WARP))
- NonTurbulent8 (s->spans);
+ if (!(pface->texinfo->c.flags & SURF_WARP))
+ NonTurbulent8(s->spans);
else
- Turbulent8 (s->spans);
+ Turbulent8(s->spans);
//PGM
//============
- D_DrawZSpans (s->spans);
+ D_DrawZSpans(s->spans);
- if (s->insubmodel)
- {
- //
- // restore the old drawing state
- // FIXME: we don't want to do this every time!
- // TODO: speed up
- //
+ if (s->insubmodel) {
+ //
+ // restore the old drawing state
+ // FIXME: we don't want to do this every time!
+ // TODO: speed up
+ //
currententity = NULL; // &r_worldentity;
- VectorCopy (world_transformed_modelorg,
- transformed_modelorg);
- VectorCopy (base_vpn, vpn);
- VectorCopy (base_vup, vup);
- VectorCopy (base_vright, vright);
- R_TransformFrustum ();
+ VectorCopy(world_transformed_modelorg,
+ transformed_modelorg);
+ VectorCopy(base_vpn, vpn);
+ VectorCopy(base_vup, vup);
+ VectorCopy(base_vright, vright);
+ R_TransformFrustum();
}
}
@@ -928,7 +890,7 @@ void D_TurbulentSurf (surf_t *s)
D_SkySurf
==============
*/
-void D_SkySurf (surf_t *s)
+void D_SkySurf(surf_t *s)
{
pface = s->msurf;
miplevel = 0;
@@ -938,14 +900,14 @@ void D_SkySurf (surf_t *s)
d_ziorigin = s->d_ziorigin;
if (!pface->texinfo->image) {
- D_FlatFillSurface (s, 0);
+ D_FlatFillSurface(s, 0);
} else {
cacheblock = pface->texinfo->image->pixels[0];
cachewidth = 256;
- D_CalcGradients (pface);
+ D_CalcGradients(pface);
- D_DrawSpans16 (s->spans);
+ D_DrawSpans16(s->spans);
}
// set up a gradient for the background surface that places it
@@ -954,7 +916,7 @@ void D_SkySurf (surf_t *s)
d_zistepv = 0;
d_ziorigin = -0.9;
- D_DrawZSpans (s->spans);
+ D_DrawZSpans(s->spans);
}
/*
@@ -964,25 +926,23 @@ D_SolidSurf
Normal surface cached, texture mapped surface
==============
*/
-void D_SolidSurf (surf_t *s)
+void D_SolidSurf(surf_t *s)
{
d_zistepu = s->d_zistepu;
d_zistepv = s->d_zistepv;
d_ziorigin = s->d_ziorigin;
- if (s->insubmodel)
- {
- // FIXME: we don't want to do all this for every polygon!
- // TODO: store once at start of frame
+ if (s->insubmodel) {
+ // FIXME: we don't want to do all this for every polygon!
+ // TODO: store once at start of frame
currententity = s->entity; //FIXME: make this passed in to
- // R_RotateBmodel ()
- VectorSubtract (r_origin, currententity->origin, local_modelorg);
- TransformVector (local_modelorg, transformed_modelorg);
+ // R_RotateBmodel ()
+ VectorSubtract(r_origin, currententity->origin, local_modelorg);
+ TransformVector(local_modelorg, transformed_modelorg);
- R_RotateBmodel (); // FIXME: don't mess with the frustum,
- // make entity passed in
- }
- else
+ R_RotateBmodel(); // FIXME: don't mess with the frustum,
+ // make entity passed in
+ } else
currententity = &r_worldentity;
pface = s->msurf;
@@ -991,30 +951,29 @@ void D_SolidSurf (surf_t *s)
// FIXME: make this passed in to D_CacheSurface
- pcurrentcache = D_CacheSurface (pface, miplevel);
+ pcurrentcache = D_CacheSurface(pface, miplevel);
cacheblock = (pixel_t *)pcurrentcache->data;
cachewidth = pcurrentcache->width;
- D_CalcGradients (pface);
-
- D_DrawSpans16 (s->spans);
-
- D_DrawZSpans (s->spans);
-
- if (s->insubmodel)
- {
- //
- // restore the old drawing state
- // FIXME: we don't want to do this every time!
- // TODO: speed up
- //
- VectorCopy (world_transformed_modelorg,
- transformed_modelorg);
- VectorCopy (base_vpn, vpn);
- VectorCopy (base_vup, vup);
- VectorCopy (base_vright, vright);
- R_TransformFrustum ();
+ D_CalcGradients(pface);
+
+ D_DrawSpans16(s->spans);
+
+ D_DrawZSpans(s->spans);
+
+ if (s->insubmodel) {
+ //
+ // restore the old drawing state
+ // FIXME: we don't want to do this every time!
+ // TODO: speed up
+ //
+ VectorCopy(world_transformed_modelorg,
+ transformed_modelorg);
+ VectorCopy(base_vpn, vpn);
+ VectorCopy(base_vup, vup);
+ VectorCopy(base_vright, vright);
+ R_TransformFrustum();
currententity = NULL; //&r_worldentity;
}
}
@@ -1026,12 +985,11 @@ D_DrawflatSurfaces
To allow developers to see the polygon carving of the world
=============
*/
-void D_DrawflatSurfaces (void)
+void D_DrawflatSurfaces(void)
{
surf_t *s;
- for (s = &surfaces[1] ; s<surface_p ; s++)
- {
+ for (s = &surfaces[1]; s < surface_p; s++) {
if (!s->spans)
continue;
@@ -1041,8 +999,8 @@ void D_DrawflatSurfaces (void)
// make a stable color for each surface by taking the low
// bits of the msurface pointer
- D_FlatFillSurface (s, (uint32_t)((intptr_t)s->msurf));
- D_DrawZSpans (s->spans);
+ D_FlatFillSurface(s, (uint32_t)((intptr_t)s->msurf));
+ D_DrawZSpans(s->spans);
}
}
@@ -1052,12 +1010,11 @@ D_DrawZSurfaces
=============
*/
-void D_DrawZSurfaces (void)
+void D_DrawZSurfaces(void)
{
surf_t *s;
- for (s = &surfaces[1] ; s<surface_p ; s++)
- {
+ for (s = &surfaces[1]; s < surface_p; s++) {
if (!s->spans)
continue;
@@ -1065,7 +1022,7 @@ void D_DrawZSurfaces (void)
d_zistepv = s->d_zistepv;
d_ziorigin = s->d_ziorigin;
- D_DrawZSpans (s->spans);
+ D_DrawZSpans(s->spans);
}
}
@@ -1077,40 +1034,39 @@ Rasterize all the span lists. Guaranteed zero overdraw.
May be called more than once a frame if the surf list overflows (higher res)
==============
*/
-void D_DrawSurfaces (void)
+void D_DrawSurfaces(void)
{
surf_t *s;
// currententity = NULL; //&r_worldentity;
- VectorSubtract (r_origin, vec3_origin, modelorg);
- TransformVector (modelorg, transformed_modelorg);
- VectorCopy (transformed_modelorg, world_transformed_modelorg);
+ VectorSubtract(r_origin, vec3_origin, modelorg);
+ TransformVector(modelorg, transformed_modelorg);
+ VectorCopy(transformed_modelorg, world_transformed_modelorg);
- if( sw_drawsird->integer ) {
+ if (sw_drawsird->integer) {
D_DrawZSurfaces();
- } else if( sw_drawflat->integer ) {
- D_DrawflatSurfaces ();
+ } else if (sw_drawflat->integer) {
+ D_DrawflatSurfaces();
} else {
- for (s = &surfaces[1] ; s<surface_p ; s++)
- {
+ for (s = &surfaces[1]; s < surface_p; s++) {
if (!s->spans)
continue;
r_drawnpolycount++;
if (s->flags & DSURF_SKY)
- D_SkySurf (s);
+ D_SkySurf(s);
else if (s->flags & DSURF_BACKGROUND)
- D_BackgroundSurf (s);
+ D_BackgroundSurf(s);
else if (s->flags & DSURF_TURB)
- D_TurbulentSurf (s);
+ D_TurbulentSurf(s);
else
- D_SolidSurf (s);
+ D_SolidSurf(s);
}
}
currententity = NULL; //&r_worldentity;
- VectorSubtract (r_origin, vec3_origin, modelorg);
- R_TransformFrustum ();
+ VectorSubtract(r_origin, vec3_origin, modelorg);
+ R_TransformFrustum();
}
diff --git a/src/sw_image.c b/src/sw_image.c
index 408836d..493ac0a 100644
--- a/src/sw_image.c
+++ b/src/sw_image.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,8 +27,9 @@ byte d_16to8table[65536];
IMG_Unload
================
*/
-void IMG_Unload( image_t *image ) {
- Z_Free( image->pixels[0] );
+void IMG_Unload(image_t *image)
+{
+ Z_Free(image->pixels[0]);
image->pixels[0] = NULL;
}
@@ -37,54 +38,57 @@ void IMG_Unload( image_t *image ) {
IMG_Load
================
*/
-void IMG_Load( image_t *image, byte *pic, int width, int height ) {
+void IMG_Load(image_t *image, byte *pic, int width, int height)
+{
int i, c, b;
image->upload_width = width;
image->upload_height = height;
c = width * height;
- if( image->type == it_wall ) {
- size_t size = MIPSIZE( c );
+ if (image->type == it_wall) {
+ size_t size = MIPSIZE(c);
- image->pixels[0] = R_Malloc( size );
+ image->pixels[0] = R_Malloc(size);
image->pixels[1] = image->pixels[0] + c;
image->pixels[2] = image->pixels[1] + c / 4;
image->pixels[3] = image->pixels[2] + c / 16;
- memcpy( image->pixels[0], pic, size );
+ memcpy(image->pixels[0], pic, size);
} else {
image->pixels[0] = pic;
- for( i = 0; i < c; i++ ) {
+ for (i = 0; i < c; i++) {
b = pic[i];
- if( b == 255 ) {
+ if (b == 255) {
image->flags |= if_transparent;
}
}
}
}
-void R_BuildGammaTable( void ) {
+void R_BuildGammaTable(void)
+{
int i, inf;
float g = vid_gamma->value;
- if( g == 1.0 ) {
- for ( i = 0; i < 256; i++)
+ if (g == 1.0) {
+ for (i = 0; i < 256; i++)
sw_state.gammatable[i] = i;
return;
}
- for( i = 0; i < 256; i++ ) {
- inf = 255 * pow ( ( i + 0.5 ) / 255.5 , g ) + 0.5;
- sw_state.gammatable[i] = clamp( inf, 0, 255 );
+ for (i = 0; i < 256; i++) {
+ inf = 255 * pow((i + 0.5) / 255.5 , g) + 0.5;
+ sw_state.gammatable[i] = clamp(inf, 0, 255);
}
}
#define NTX 16
-static void R_CreateNotexture( void ) {
- static byte buffer[MIPSIZE( NTX * NTX )];
+static void R_CreateNotexture(void)
+{
+ static byte buffer[MIPSIZE(NTX * NTX)];
int x, y, m;
byte *p;
image_t *ntx;
@@ -100,58 +104,60 @@ static void R_CreateNotexture( void ) {
ntx->pixels[2] = ntx->pixels[1] + NTX * NTX / 4;
ntx->pixels[3] = ntx->pixels[2] + NTX * NTX / 16;
- for( m = 0; m < 4; m++ ) {
+ for (m = 0; m < 4; m++) {
p = ntx->pixels[m];
- for ( y = 0; y < ( 16 >> m ); y++ ) {
- for( x = 0; x < ( 16 >> m ); x++ ) {
- if( ( y < ( 8 >> m ) ) ^ ( x < ( 8 >> m ) ) )
+ for (y = 0; y < (16 >> m); y++) {
+ for (x = 0; x < (16 >> m); x++) {
+ if ((y < (8 >> m)) ^(x < (8 >> m)))
*p++ = 0;
else
*p++ = 1;
}
}
- }
+ }
}
-int R_IndexForColor( uint32_t color ) {
+int R_IndexForColor(uint32_t color)
+{
unsigned int r, g, b, c;
color_t tmp = { color };
- r = ( tmp.u8[0] >> 3 ) & 31;
- g = ( tmp.u8[1] >> 2 ) & 63;
- b = ( tmp.u8[2] >> 3 ) & 31;
+ r = (tmp.u8[0] >> 3) & 31;
+ g = (tmp.u8[1] >> 2) & 63;
+ b = (tmp.u8[2] >> 3) & 31;
- c = r | ( g << 5 ) | ( b << 11 );
+ c = r | (g << 5) | (b << 11);
return d_16to8table[c];
}
-static void R_Get16to8( void ) {
+static void R_Get16to8(void)
+{
static const char colormap[] = "pics/16to8.dat";
qhandle_t f;
ssize_t ret;
- ret = FS_FOpenFile( colormap, &f, FS_MODE_READ );
- if( !f ) {
+ ret = FS_FOpenFile(colormap, &f, FS_MODE_READ);
+ if (!f) {
goto fail;
}
- ret = FS_Read( d_16to8table, sizeof( d_16to8table ), f );
+ ret = FS_Read(d_16to8table, sizeof(d_16to8table), f);
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
- if( ret < 0 ) {
+ if (ret < 0) {
goto fail;
}
- if( ret == sizeof( d_16to8table ) ) {
+ if (ret == sizeof(d_16to8table)) {
return; // success
}
ret = Q_ERR_FILE_TOO_SMALL;
fail:
- Com_Error( ERR_FATAL, "Couldn't load %s: %s",
- colormap, Q_ErrorString( ret ) );
+ Com_Error(ERR_FATAL, "Couldn't load %s: %s",
+ colormap, Q_ErrorString(ret));
}
/*
@@ -159,7 +165,8 @@ fail:
R_InitImages
===============
*/
-void R_InitImages( void ) {
+void R_InitImages(void)
+{
registration_sequence = 1;
vid.colormap = IMG_GetPalette();
@@ -185,9 +192,10 @@ void R_InitImages( void ) {
R_ShutdownImages
===============
*/
-void R_ShutdownImages( void ) {
- if( vid.colormap ) {
- Z_Free( vid.colormap );
+void R_ShutdownImages(void)
+{
+ if (vid.colormap) {
+ Z_Free(vid.colormap);
vid.colormap = NULL;
}
diff --git a/src/sw_light.c b/src/sw_light.c
index 6babb19..80b1231 100644
--- a/src/sw_light.c
+++ b/src/sw_light.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -37,52 +37,48 @@ DYNAMIC LIGHTS
R_MarkLights
=============
*/
-void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
+void R_MarkLights(dlight_t *light, int bit, mnode_t *node)
{
cplane_t *splitplane;
float dist;
mface_t *surf;
int i;
-
+
if (!node->plane)
return;
splitplane = node->plane;
- dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
-
+ dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
+
//=====
//PGM
- i=light->intensity;
- if(i<0)
- i=-i;
+ i = light->intensity;
+ if (i < 0)
+ i = -i;
//PGM
//=====
- if (dist > i) // PGM (dist > light->intensity)
- {
- R_MarkLights (light, bit, node->children[0]);
+ if (dist > i) { // PGM (dist > light->intensity)
+ R_MarkLights(light, bit, node->children[0]);
return;
}
- if (dist < -i) // PGM (dist < -light->intensity)
- {
- R_MarkLights (light, bit, node->children[1]);
+ if (dist < -i) { // PGM (dist < -light->intensity)
+ R_MarkLights(light, bit, node->children[1]);
return;
}
-
+
// mark the polygons
surf = node->firstface;
- for (i=0 ; i<node->numfaces ; i++, surf++)
- {
- if (surf->dlightframe != r_dlightframecount)
- {
+ for (i = 0; i < node->numfaces; i++, surf++) {
+ if (surf->dlightframe != r_dlightframecount) {
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
surf->dlightbits |= bit;
}
- R_MarkLights (light, bit, node->children[0]);
- R_MarkLights (light, bit, node->children[1]);
+ R_MarkLights(light, bit, node->children[0]);
+ R_MarkLights(light, bit, node->children[1]);
}
@@ -91,15 +87,14 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
R_PushDlights
=============
*/
-void R_PushDlights (mnode_t *headnode)
+void R_PushDlights(mnode_t *headnode)
{
int i;
dlight_t *l;
r_dlightframecount = r_framecount;
- for (i=0, l = r_newrefdef.dlights ; i<r_newrefdef.num_dlights ; i++, l++)
- {
- R_MarkLights ( l, 1 << i, headnode);
+ for (i = 0, l = r_newrefdef.dlights; i < r_newrefdef.num_dlights; i++, l++) {
+ R_MarkLights(l, 1 << i, headnode);
}
}
@@ -112,7 +107,8 @@ LIGHT SAMPLING
=============================================================================
*/
-static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
+static qboolean RecursiveLightPoint(vec3_t p, vec3_t color)
+{
mface_t *surf;
int ds, dt;
byte *lightmap;
@@ -125,8 +121,8 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
end[1] = p[1];
end[2] = p[2] - 2048;
- surf = BSP_LightPoint( r_worldmodel->nodes, p, end, &ds, &dt );
- if( !surf ) {
+ surf = BSP_LightPoint(r_worldmodel->nodes, p, end, &ds, &dt);
+ if (!surf) {
return qfalse;
}
@@ -136,11 +132,10 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
lightmap = surf->lightmap;
lightmap += dt * S_MAX(surf) + ds;
- for (maps = 0 ; maps < surf->numstyles ; maps++)
- {
- samp = *lightmap * (1.0/255); // adjust for gl scale
+ for (maps = 0; maps < surf->numstyles; maps++) {
+ samp = *lightmap * (1.0 / 255); // adjust for gl scale
scales = r_newrefdef.lightstyles[surf->styles[maps]].rgb;
- VectorMA (color, samp, scales, color);
+ VectorMA(color, samp, scales, color);
lightmap += S_MAX(surf) * T_MAX(surf);
}
return qtrue;
@@ -151,39 +146,36 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
R_LightPoint
===============
*/
-void R_LightPoint (vec3_t p, vec3_t color)
+void R_LightPoint(vec3_t p, vec3_t color)
{
int lnum;
dlight_t *dl;
float light;
vec3_t dist;
float add;
-
- if (!r_worldmodel || !r_worldmodel->lightmap || !r_newrefdef.lightstyles)
- {
+
+ if (!r_worldmodel || !r_worldmodel->lightmap || !r_newrefdef.lightstyles) {
color[0] = color[1] = color[2] = 1.0;
return;
}
-
- VectorClear( color );
- RecursiveLightPoint (p, color);
+ VectorClear(color);
+
+ RecursiveLightPoint(p, color);
//
// add dynamic lights
//
light = 0;
- for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
- {
+ for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) {
dl = &r_newrefdef.dlights[lnum];
- VectorSubtract (p,
- dl->origin,
- dist);
+ VectorSubtract(p,
+ dl->origin,
+ dist);
add = dl->intensity - VectorLength(dist);
- add *= (1.0/256);
- if (add > 0)
- {
- VectorMA (color, add, dl->color, color);
+ add *= (1.0 / 256);
+ if (add > 0) {
+ VectorMA(color, add, dl->color, color);
}
}
}
@@ -197,7 +189,8 @@ blocklight_t blocklights[MAX_BLOCKLIGHTS];
R_AddDynamicLights
===============
*/
-static void R_AddDynamicLights( void ) {
+static void R_AddDynamicLights(void)
+{
mface_t *surf;
int lnum;
int sd, td;
@@ -215,57 +208,57 @@ static void R_AddDynamicLights( void ) {
tmax = T_MAX(surf);
tex = surf->texinfo;
- for ( lnum = 0; lnum < r_newrefdef.num_dlights; lnum++ ) {
- if ( !(surf->dlightbits & (1<<lnum) ) )
+ for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) {
+ if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
dl = &r_newrefdef.dlights[lnum];
rad = dl->intensity;
negativeLight = 0;
- if(rad < 0) {
+ if (rad < 0) {
negativeLight = 1;
rad = -rad;
}
- dist = PlaneDiffFast (dl->origin, surf->plane);
+ dist = PlaneDiffFast(dl->origin, surf->plane);
rad -= fabs(dist);
minlight = 32; // dl->minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;
- for (i=0 ; i<3 ; i++) {
- impact[i] = dl->origin[i] - surf->plane->normal[i]*dist;
+ for (i = 0; i < 3; i++) {
+ impact[i] = dl->origin[i] - surf->plane->normal[i] * dist;
}
- local[0] = DotProduct (impact, tex->axis[0]) + tex->offset[0];
- local[1] = DotProduct (impact, tex->axis[1]) + tex->offset[1];
+ local[0] = DotProduct(impact, tex->axis[0]) + tex->offset[0];
+ local[1] = DotProduct(impact, tex->axis[1]) + tex->offset[1];
local[0] -= surf->texturemins[0];
local[1] -= surf->texturemins[1];
-
- for (t = 0 ; t<tmax ; t++) {
- td = local[1] - t*16;
+
+ for (t = 0; t < tmax; t++) {
+ td = local[1] - t * 16;
if (td < 0)
td = -td;
- for (s=0 ; s<smax ; s++) {
- sd = local[0] - s*16;
+ for (s = 0; s < smax; s++) {
+ sd = local[0] - s * 16;
if (sd < 0)
sd = -sd;
/*if (sd > td)
dist = sd + (td>>1);
else
dist = td + (sd>>1);*/
- dist = sqrt( sd * sd + td * td );
- if(!negativeLight) {
+ dist = sqrt(sd * sd + td * td);
+ if (!negativeLight) {
if (dist < minlight)
- blocklights[t*smax + s] += (rad - dist)*256;
+ blocklights[t * smax + s] += (rad - dist) * 256;
} else {
if (dist < minlight)
- blocklights[t*smax + s] -= (rad - dist)*256;
- if(blocklights[t*smax + s] < minlight)
- blocklights[t*smax + s] = minlight;
+ blocklights[t * smax + s] -= (rad - dist) * 256;
+ if (blocklights[t * smax + s] < minlight)
+ blocklights[t * smax + s] = minlight;
}
}
}
@@ -281,7 +274,8 @@ Combine and scale multiple lightmaps into the 8.8 format in blocklights
===============
*/
-void R_BuildLightMap( void ) {
+void R_BuildLightMap(void)
+{
int smax, tmax;
blocklight_t t;
int i, size;
@@ -292,32 +286,32 @@ void R_BuildLightMap( void ) {
surf = r_drawsurf.surf;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax;
- if( size > MAX_BLOCKLIGHTS ) {
- Com_Error( ERR_DROP, "R_BuildLightMap: surface blocklights size %i > %i", size, MAX_BLOCKLIGHTS );
+ if (size > MAX_BLOCKLIGHTS) {
+ Com_Error(ERR_DROP, "R_BuildLightMap: surface blocklights size %i > %i", size, MAX_BLOCKLIGHTS);
}
// clear to no light
dst = blocklights;
- for( i = 0; i < size; i++ ) {
+ for (i = 0; i < size; i++) {
*dst++ = 0;
}
-
- if( r_fullbright->integer || !r_worldmodel->lightmap ) {
+
+ if (r_fullbright->integer || !r_worldmodel->lightmap) {
return;
}
// add all the lightmaps
lightmap = surf->lightmap;
- if( lightmap ) {
- for( maps = 0; maps < surf->numstyles; maps++ ) {
+ if (lightmap) {
+ for (maps = 0; maps < surf->numstyles; maps++) {
fixed8_t scale;
-
+
dst = blocklights;
- scale = r_drawsurf.lightadj[maps]; // 8.8 fraction
- for( i = 0; i < size; i++ ) {
+ scale = r_drawsurf.lightadj[maps]; // 8.8 fraction
+ for (i = 0; i < size; i++) {
blocklights[i] += lightmap[0] * scale;
lightmap++; dst++;
@@ -326,18 +320,18 @@ void R_BuildLightMap( void ) {
}
// add all the dynamic lights
- if( surf->dlightframe == r_framecount )
+ if (surf->dlightframe == r_framecount)
R_AddDynamicLights();
// bound, invert, and shift
- for( i = 0; i < size; i++ ) {
+ for (i = 0; i < size; i++) {
t = blocklights[i];
- if( t < 0 )
+ if (t < 0)
t = 0;
- t = ( 255 * 256 - t ) >> ( 8 - VID_CBITS );
+ t = (255 * 256 - t) >> (8 - VID_CBITS);
- if( t < ( 1 << 6 ) )
- t = ( 1 << 6 );
+ if (t < (1 << 6))
+ t = (1 << 6);
blocklights[i] = t;
}
diff --git a/src/sw_local.h b/src/sw_local.h
index db232ae..d38720a 100644
--- a/src/sw_local.h
+++ b/src/sw_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -46,9 +46,9 @@ typedef struct {
pixel_t *buffer; // invisible buffer
pixel_t *colormap; // 256 * VID_GRADES size
pixel_t *alphamap; // 256 * 256 translucency map
- int rowbytes; // may be > width if displayed in a window
- // can be negative for stupid dibs
- int width;
+ int rowbytes; // may be > width if displayed in a window
+ // can be negative for stupid dibs
+ int width;
int height;
} viddef_t;
@@ -56,30 +56,29 @@ extern viddef_t vid;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct {
- vrectSoft_t vrect; // subwindow in video for refresh
- // FIXME: not need vrect next field here?
- vrectSoft_t aliasvrect; // scaled Alias version
- int vrectright, vrectbottom; // right & bottom screen coords
- int aliasvrectright, aliasvrectbottom; // scaled Alias versions
+ vrectSoft_t vrect; // subwindow in video for refresh
+ // FIXME: not need vrect next field here?
+ vrectSoft_t aliasvrect; // scaled Alias version
+ int vrectright, vrectbottom; // right & bottom screen coords
+ int aliasvrectright, aliasvrectbottom; // scaled Alias versions
float vrectrightedge; // rightmost right edge we care about,
- // for use in edge list
+ // for use in edge list
float fvrectx, fvrecty; // for floating-point compares
- float fvrectx_adj, fvrecty_adj; // left and top edges, for clamping
- int vrect_x_adj_shift20; // (vrect.x + 0.5 - epsilon) << 20
- int vrectright_adj_shift20; // (vrectright + 0.5 - epsilon) << 20
- float fvrectright_adj, fvrectbottom_adj;
- // right and bottom edges, for clamping
+ float fvrectx_adj, fvrecty_adj; // left and top edges, for clamping
+ int vrect_x_adj_shift20; // (vrect.x + 0.5 - epsilon) << 20
+ int vrectright_adj_shift20; // (vrectright + 0.5 - epsilon) << 20
+ float fvrectright_adj, fvrectbottom_adj; // right and bottom edges, for clamping
float fvrectright; // rightmost edge, for Alias clamping
float fvrectbottom; // bottommost edge, for Alias clamping
- float horizontalFieldOfView; // at Z = 1.0, this many X is visible
- // 2.0 = 90 degrees
+ float horizontalFieldOfView; // at Z = 1.0, this many X is visible
+ // 2.0 = 90 degrees
float xOrigin; // should probably always be 0.5
float yOrigin; // between be around 0.3 to 0.5
vec3_t vieworg;
vec3_t viewangles;
-
- int ambientlight;
+
+ int ambientlight;
} oldrefdef_t;
extern oldrefdef_t r_refdef;
@@ -103,21 +102,22 @@ extern oldrefdef_t r_refdef;
#define MAXVERTS 64 // max points in a surface polygon
-#define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate
- // polygon (while processing)
+#define MAXWORKINGVERTS (MAXVERTS + 4) // max points in an intermediate
+ // polygon (while processing)
+
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
#define MAXHEIGHT 1200
#define MAXWIDTH 1600
-#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to
- // be farther away than anything in
- // the scene
+#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to
+ // be farther away than anything in
+ // the scene
// d_iface.h: interface header file for rasterization driver modules
-#define WARP_WIDTH 320
-#define WARP_HEIGHT 240
+#define WARP_WIDTH 320
+#define WARP_HEIGHT 240
#define MAX_LBM_HEIGHT 480
@@ -129,33 +129,33 @@ extern oldrefdef_t r_refdef;
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
-#define TURB_TEX_SIZE 64 // base turbulent texture size
+#define TURB_TEX_SIZE 64 // base turbulent texture size
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
-#define CYCLE 128 // turbulent cycle size
+#define CYCLE 128 // turbulent cycle size
#define SCANBUFFERPAD 0x1000
#define DS_SPAN_LIST_END -128
#define NUMSTACKEDGES 3000
-#define MINEDGES NUMSTACKEDGES
+#define MINEDGES NUMSTACKEDGES
#define NUMSTACKSURFACES 1000
-#define MINSURFACES NUMSTACKSURFACES
-#define MAXSPANS 3000
+#define MINSURFACES NUMSTACKSURFACES
+#define MAXSPANS 3000
// flags in finalvert_t.flags
-#define ALIAS_LEFT_CLIP 0x0001
-#define ALIAS_TOP_CLIP 0x0002
-#define ALIAS_RIGHT_CLIP 0x0004
-#define ALIAS_BOTTOM_CLIP 0x0008
-#define ALIAS_Z_CLIP 0x0010
-#define ALIAS_XY_CLIP_MASK 0x000F
+#define ALIAS_LEFT_CLIP 0x0001
+#define ALIAS_TOP_CLIP 0x0002
+#define ALIAS_RIGHT_CLIP 0x0004
+#define ALIAS_BOTTOM_CLIP 0x0008
+#define ALIAS_Z_CLIP 0x0010
+#define ALIAS_XY_CLIP_MASK 0x000F
-#define SURFCACHE_SIZE_AT_320X240 1024*768
+#define SURFCACHE_SIZE_AT_320X240 1024*768
-#define BMODEL_FULLY_CLIPPED 0x10 // value returned by R_BmodelCheckBBox ()
- // if bbox is trivially rejected
+#define BMODEL_FULLY_CLIPPED 0x10 // value returned by R_BmodelCheckBBox ()
+ // if bbox is trivially rejected
#define XCENTERING (1.0 / 2.0)
#define YCENTERING (1.0 / 2.0)
@@ -173,7 +173,7 @@ extern oldrefdef_t r_refdef;
// turbulence stuff
-#define AMP 8*0x10000
+#define AMP 8*0x10000
#define AMP2 3
#define SPEED 20
@@ -186,9 +186,9 @@ TYPES
====================================================
*/
-#define DSURF_SKY 2
-#define DSURF_TURB 4
-#define DSURF_BACKGROUND 8
+#define DSURF_SKY 2
+#define DSURF_TURB 4
+#define DSURF_BACKGROUND 8
typedef struct {
float u, v;
@@ -201,10 +201,10 @@ typedef struct {
** listed after it!
*/
typedef struct finalvert_s {
- int u, v, s, t;
- int l;
- int zi;
- int flags;
+ int u, v, s, t;
+ int l;
+ int zi;
+ int flags;
float xyz[3]; // eye space
} finalvert_t;
@@ -221,54 +221,53 @@ typedef struct finalvert_s {
#define FINALVERT_SIZE 40
typedef struct {
- void *pskin;
- int pskindesc;
- int skinwidth;
- int skinheight;
-// dtriangle_t *ptriangles;
- void *unused;
- finalvert_t *pfinalverts;
- int numtriangles;
- int drawtype;
- int seamfixupX16;
- qboolean do_vis_thresh;
- int vis_thresh;
+ void *pskin;
+ int pskindesc;
+ int skinwidth;
+ int skinheight;
+// dtriangle_t *ptriangles;
+ void *unused;
+ finalvert_t *pfinalverts;
+ int numtriangles;
+ int drawtype;
+ int seamfixupX16;
+ qboolean do_vis_thresh;
+ int vis_thresh;
} affinetridesc_t;
typedef struct drawsurf_s {
- byte *surfdat; // destination for generated surface
- int rowbytes; // destination logical width in bytes
- mface_t *surf; // description for surface to generate
- fixed8_t lightadj[MAX_LIGHTMAPS];
- // adjust for lightmap levels for dynamic lighting
- image_t *image;
- int surfmip; // mipmapped ratio of surface texels / world pixels
- int surfwidth; // in mipmapped texels
- int surfheight; // in mipmapped texels
+ byte *surfdat; // destination for generated surface
+ int rowbytes; // destination logical width in bytes
+ mface_t *surf; // description for surface to generate
+ fixed8_t lightadj[MAX_LIGHTMAPS]; // adjust for lightmap levels for dynamic lighting
+ image_t *image;
+ int surfmip; // mipmapped ratio of surface texels / world pixels
+ int surfwidth; // in mipmapped texels
+ int surfheight; // in mipmapped texels
} drawsurf_t;
typedef struct {
- int ambientlight;
- int shadelight;
- float *plightvec;
+ int ambientlight;
+ int shadelight;
+ float *plightvec;
} alight_t;
// clipped bmodel edges
typedef struct bedge_s {
- mvertex_t *v[2];
+ mvertex_t *v[2];
struct bedge_s *pnext;
} bedge_t;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct clipplane_s {
- vec3_t normal;
- float dist;
- struct clipplane_s *next;
- byte leftedge;
- byte rightedge;
- byte reserved[2];
+ vec3_t normal;
+ float dist;
+ struct clipplane_s *next;
+ byte leftedge;
+ byte rightedge;
+ byte reserved[2];
} clipplane_t;
#define MAX_BLOCKLIGHTS 1024
@@ -297,50 +296,49 @@ typedef struct espan_s {
// used by the polygon drawer (R_POLY.C) and sprite setup code (R_SPRITE.C)
typedef struct {
- int nump;
- emitpoint_t *pverts;
- byte *pixels; // image
- int pixel_width; // image width
- int pixel_height; // image height
- vec3_t vup, vright, vpn; // in worldspace, for plane eq
+ int nump;
+ emitpoint_t *pverts;
+ byte *pixels; // image
+ int pixel_width; // image width
+ int pixel_height; // image height
+ vec3_t vup, vright, vpn; // in worldspace, for plane eq
float dist;
float s_offset, t_offset;
float viewer_position[3];
- void (*drawspanlet)( void );
+ void (*drawspanlet)(void);
int stipple_parity;
} polydesc_t;
// FIXME: compress, make a union if that will help
// insubmodel is only 1, flags is fewer than 32, spanstate could be a byte
typedef struct surf_s {
- struct surf_s *next; // active surface stack in r_edge.c
- struct surf_s *prev; // used in r_edge.c for active surf stack
- struct espan_s *spans; // pointer to linked list of spans to draw
- int key; // sorting key (BSP order)
- int last_u; // set during tracing
- int spanstate; // 0 = not in span
+ struct surf_s *next; // active surface stack in r_edge.c
+ struct surf_s *prev; // used in r_edge.c for active surf stack
+ struct espan_s *spans; // pointer to linked list of spans to draw
+ int key; // sorting key (BSP order)
+ int last_u; // set during tracing
+ int spanstate; // 0 = not in span
// 1 = in span
- // -1 = in inverted span (end before
- // start)
- int flags; // currentface flags
- mface_t *msurf;
+ // -1 = in inverted span (end before start)
+ int flags; // currentface flags
+ mface_t *msurf;
entity_t *entity;
- float nearzi; // nearest 1/z on surface, for mipmapping
+ float nearzi; // nearest 1/z on surface, for mipmapping
qboolean insubmodel;
float d_ziorigin, d_zistepu, d_zistepv;
- int pad[2]; // to 64 bytes
+ int pad[2]; // to 64 bytes
} surf_t;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct edge_s {
- fixed16_t u;
- fixed16_t u_step;
+ fixed16_t u;
+ fixed16_t u_step;
struct edge_s *prev, *next;
- uint16_t surfs[2];
+ uint16_t surfs[2];
struct edge_s *nextremove;
- float nearzi;
- medge_t *owner;
+ float nearzi;
+ medge_t *owner;
} edge_t;
typedef struct maliasst_s {
@@ -375,21 +373,20 @@ VARS
====================================================
*/
-extern int d_spanpixcount;
-extern int r_framecount; // sequence # of current frame since Quake
- // started
-extern float r_aliasuvscale; // scale-up factor for screen u and v
- // on Alias vertices passed to driver
+extern int d_spanpixcount;
+extern int r_framecount; // sequence # of current frame since Quake started
+extern float r_aliasuvscale; // scale-up factor for screen u and v
+ // on Alias vertices passed to driver
extern qboolean r_dowarp;
extern affinetridesc_t r_affinetridesc;
extern vec3_t r_pright, r_pup, r_ppn;
-void D_DrawSurfaces (void);
-void D_ViewChanged (void);
-void D_WarpScreen (void);
-void R_PolysetUpdateTables (void);
+void D_DrawSurfaces(void);
+void D_ViewChanged(void);
+void D_WarpScreen(void);
+void R_PolysetUpdateTables(void);
//=======================================================================//
@@ -397,7 +394,7 @@ void R_PolysetUpdateTables (void);
extern drawsurf_t r_drawsurf;
-void R_DrawSurface (void);
+void R_DrawSurface(void);
extern int c_surf;
@@ -413,16 +410,16 @@ extern float d_sdivzstepu, d_tdivzstepu, d_zistepu;
extern float d_sdivzstepv, d_tdivzstepv, d_zistepv;
extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
-extern fixed16_t sadjust, tadjust;
-extern fixed16_t bbextents, bbextentt;
+extern fixed16_t sadjust, tadjust;
+extern fixed16_t bbextents, bbextentt;
-void D_DrawSpans16 (espan_t *pspans);
-void D_DrawZSpans (espan_t *pspans);
-void Turbulent8 (espan_t *pspan);
-void NonTurbulent8 (espan_t *pspan); //PGM
+void D_DrawSpans16(espan_t *pspans);
+void D_DrawZSpans(espan_t *pspans);
+void Turbulent8(espan_t *pspan);
+void NonTurbulent8(espan_t *pspan); //PGM
-surfcache_t *D_CacheSurface (mface_t *surface, int miplevel);
+surfcache_t *D_CacheSurface(mface_t *surface, int miplevel);
extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
@@ -434,26 +431,26 @@ extern unsigned int d_zrowbytes, d_zwidth;
extern short *zspantable[MAXHEIGHT];
extern int d_scantable[MAXHEIGHT];
-extern int d_minmip;
+extern int d_minmip;
extern float d_scalemip[3];
//===================================================================
-extern int cachewidth;
+extern int cachewidth;
extern pixel_t *cacheblock;
-extern int r_screenwidth;
+extern int r_screenwidth;
-extern int r_drawnpolycount;
+extern int r_drawnpolycount;
-extern int sintable[CYCLE*2];
-extern int intsintable[CYCLE*2];
-extern int blanktable[CYCLE*2]; // PGM
+extern int sintable[CYCLE * 2];
+extern int intsintable[CYCLE * 2];
+extern int blanktable[CYCLE * 2]; // PGM
-extern vec3_t vup, base_vup;
-extern vec3_t vpn, base_vpn;
-extern vec3_t vright, base_vright;
+extern vec3_t vup, base_vup;
+extern vec3_t vpn, base_vpn;
+extern vec3_t vright, base_vright;
-extern surf_t *surfaces, *surface_p, *surf_max;
+extern surf_t *surfaces, *surface_p, *surf_max;
// surfaces are generated in back to front order by the bsp, so if a surf
// pointer is greater than another one, it should be drawn in front
@@ -466,14 +463,14 @@ extern surf_t *surfaces, *surface_p, *surf_max;
extern vec3_t sxformaxis[4]; // s axis transformed into viewspace
extern vec3_t txformaxis[4]; // t axis transformed into viewspac
-extern float xcenter, ycenter;
-extern float xscale, yscale;
-extern float xscaleinv, yscaleinv;
-extern float xscaleshrink, yscaleshrink;
+extern float xcenter, ycenter;
+extern float xscale, yscale;
+extern float xscaleinv, yscaleinv;
+extern float xscaleshrink, yscaleshrink;
-extern void TransformVector (vec3_t in, vec3_t out);
+extern void TransformVector(vec3_t in, vec3_t out);
extern void SetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
- fixed8_t endvertu, fixed8_t endvertv);
+ fixed8_t endvertu, fixed8_t endvertv);
extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
@@ -504,125 +501,125 @@ extern cvar_t *r_lerpmodels;
extern cvar_t *r_speeds;
extern cvar_t *vid_fullscreen;
-extern cvar_t *vid_gamma;
+extern cvar_t *vid_gamma;
-extern clipplane_t view_clipplanes[4];
-extern int *pfrustum_indexes[4];
+extern clipplane_t view_clipplanes[4];
+extern int *pfrustum_indexes[4];
//=============================================================================
-void R_RenderWorld (void);
+void R_RenderWorld(void);
//=============================================================================
-extern cplane_t screenedge[4];
+extern cplane_t screenedge[4];
-extern vec3_t r_origin;
+extern vec3_t r_origin;
-extern entity_t r_worldentity;
-extern model_t *currentmodel;
-extern entity_t *currententity;
-extern vec3_t modelorg;
-extern vec3_t r_entorigin;
+extern entity_t r_worldentity;
+extern model_t *currentmodel;
+extern entity_t *currententity;
+extern vec3_t modelorg;
+extern vec3_t r_entorigin;
-extern float verticalFieldOfView;
-extern float xOrigin, yOrigin;
+extern float verticalFieldOfView;
+extern float xOrigin, yOrigin;
-extern int r_visframecount;
+extern int r_visframecount;
-extern mface_t *r_alpha_surfaces;
+extern mface_t *r_alpha_surfaces;
//=============================================================================
-void R_ClearPolyList (void);
-void R_DrawPolyList (void);
+void R_ClearPolyList(void);
+void R_DrawPolyList(void);
//
// current entity info
//
-extern qboolean insubmodel;
-
-void R_DrawAlphaSurfaces( void );
-
-void R_DrawSprite (void);
-void R_DrawBeam( entity_t *e );
-
-void R_RenderFace (mface_t *fa, int clipflags);
-void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf);
-void R_TransformPlane (cplane_t *p, float *normal, float *dist);
-void R_TransformFrustum (void);
-void R_DrawSurfaceBlock16 (void);
-void R_DrawSurfaceBlock8 (void);
-
-void R_Surf8Patch (void);
-void R_Surf16Patch (void);
-void R_DrawSubmodelPolygons (mmodel_t *pmodel, int clipflags, mnode_t *topnode);
-void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode);
-
-void R_AddPolygonEdges (emitpoint_t *pverts, int numverts, int miplevel);
-surf_t *R_GetSurf (void);
-void R_AliasDrawModel (void);
-void R_BeginEdgeFrame (void);
-void R_ScanEdges (void);
-void D_DrawSurfaces (void);
-void R_InsertNewEdges (edge_t *edgestoadd, edge_t *edgelist);
-void R_StepActiveU (edge_t *pedge);
-void R_RemoveEdges (edge_t *pedge);
-void R_PushDlights (mnode_t *headnode);
-
-extern void R_Surf8Start (void);
-extern void R_Surf8End (void);
-extern void R_Surf16Start (void);
-extern void R_Surf16End (void);
-extern void R_EdgeCodeStart (void);
-extern void R_EdgeCodeEnd (void);
-
-extern void R_RotateBmodel (void);
+extern qboolean insubmodel;
+
+void R_DrawAlphaSurfaces(void);
+
+void R_DrawSprite(void);
+void R_DrawBeam(entity_t *e);
+
+void R_RenderFace(mface_t *fa, int clipflags);
+void R_RenderBmodelFace(bedge_t *pedges, mface_t *psurf);
+void R_TransformPlane(cplane_t *p, float *normal, float *dist);
+void R_TransformFrustum(void);
+void R_DrawSurfaceBlock16(void);
+void R_DrawSurfaceBlock8(void);
+
+void R_Surf8Patch(void);
+void R_Surf16Patch(void);
+void R_DrawSubmodelPolygons(mmodel_t *pmodel, int clipflags, mnode_t *topnode);
+void R_DrawSolidClippedSubmodelPolygons(mmodel_t *pmodel, mnode_t *topnode);
+
+void R_AddPolygonEdges(emitpoint_t *pverts, int numverts, int miplevel);
+surf_t *R_GetSurf(void);
+void R_AliasDrawModel(void);
+void R_BeginEdgeFrame(void);
+void R_ScanEdges(void);
+void D_DrawSurfaces(void);
+void R_InsertNewEdges(edge_t *edgestoadd, edge_t *edgelist);
+void R_StepActiveU(edge_t *pedge);
+void R_RemoveEdges(edge_t *pedge);
+void R_PushDlights(mnode_t *headnode);
+
+extern void R_Surf8Start(void);
+extern void R_Surf8End(void);
+extern void R_Surf16Start(void);
+extern void R_Surf16End(void);
+extern void R_EdgeCodeStart(void);
+extern void R_EdgeCodeEnd(void);
+
+extern void R_RotateBmodel(void);
extern int c_faceclip;
extern int r_polycount;
extern int r_wholepolycount;
-extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
+extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
-extern fixed16_t sadjust, tadjust;
-extern fixed16_t bbextents, bbextentt;
+extern fixed16_t sadjust, tadjust;
+extern fixed16_t bbextents, bbextentt;
-extern mvertex_t *r_ptverts, *r_ptvertsmax;
+extern mvertex_t *r_ptverts, *r_ptvertsmax;
-extern float entity_rotation[3][3];
+extern float entity_rotation[3][3];
-extern int r_currentkey;
-extern int r_currentbkey;
+extern int r_currentkey;
+extern int r_currentbkey;
-void R_InitTurb (void);
+void R_InitTurb(void);
-void R_DrawParticles (void);
-void R_SurfacePatch (void);
+void R_DrawParticles(void);
+void R_SurfacePatch(void);
-extern int r_amodels_drawn;
-extern edge_t *auxedges;
-extern int r_numallocatededges;
-extern edge_t *r_edges, *edge_p, *edge_max;
+extern int r_amodels_drawn;
+extern edge_t *auxedges;
+extern int r_numallocatededges;
+extern edge_t *r_edges, *edge_p, *edge_max;
-extern edge_t *newedges[MAXHEIGHT];
-extern edge_t *removeedges[MAXHEIGHT];
+extern edge_t *newedges[MAXHEIGHT];
+extern edge_t *removeedges[MAXHEIGHT];
// FIXME: make stack vars when debugging done
-extern edge_t edge_head;
-extern edge_t edge_tail;
-extern edge_t edge_aftertail;
+extern edge_t edge_head;
+extern edge_t edge_tail;
+extern edge_t edge_aftertail;
-extern int r_aliasblendcolor;
+extern int r_aliasblendcolor;
extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter;
-extern int r_outofsurfaces;
-extern int r_outofedges;
+extern int r_outofsurfaces;
+extern int r_outofedges;
-extern int r_maxvalidedgeoffset;
+extern int r_maxvalidedgeoffset;
typedef struct {
finalvert_t *a, *b, *c;
@@ -630,99 +627,96 @@ typedef struct {
extern aliastriangleparms_t aliastriangleparms;
-void R_DrawTriangle( void );
-void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2);
+void R_DrawTriangle(void);
+void R_AliasClipTriangle(finalvert_t *index0, finalvert_t *index1, finalvert_t *index2);
extern float r_time1;
extern float da_time1, da_time2;
extern float dp_time1, dp_time2, db_time1, db_time2, rw_time1, rw_time2;
extern float se_time1, se_time2, de_time1, de_time2, dv_time1, dv_time2;
-extern int r_frustum_indexes[4*6];
-extern int r_maxsurfsseen, r_maxedgesseen, r_cnumsurfs;
+extern int r_frustum_indexes[4 * 6];
+extern int r_maxsurfsseen, r_maxedgesseen, r_cnumsurfs;
extern qboolean r_surfsonstack;
-extern mleaf_t *r_viewleaf;
-extern int r_viewcluster, r_oldviewcluster;
+extern mleaf_t *r_viewleaf;
+extern int r_viewcluster, r_oldviewcluster;
-extern int r_clipflags;
-extern int r_dlightframecount;
+extern int r_clipflags;
+extern int r_dlightframecount;
-extern bsp_t *r_worldmodel;
+extern bsp_t *r_worldmodel;
-void R_PrintAliasStats (void);
-void R_PrintTimes (void);
-void R_PrintDSpeeds (void);
-void R_AnimateLight (void);
-void R_LightPoint (vec3_t p, vec3_t color);
-void R_SetupFrame (void);
-void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);
-void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
+void R_PrintAliasStats(void);
+void R_PrintTimes(void);
+void R_PrintDSpeeds(void);
+void R_AnimateLight(void);
+void R_LightPoint(vec3_t p, vec3_t color);
+void R_SetupFrame(void);
+void R_EmitEdge(mvertex_t *pv0, mvertex_t *pv1);
+void R_ClipEdge(mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
-extern refdef_t r_newrefdef;
+extern refdef_t r_newrefdef;
-extern surfcache_t *sc_rover, *sc_base;
+extern surfcache_t *sc_rover, *sc_base;
//====================================================================
-void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
+void R_RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees);
-void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
-void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
+void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
+void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
-void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
-void PerpendicularVector( vec3_t dst, const vec3_t src );
+void ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal);
+void PerpendicularVector(vec3_t dst, const vec3_t src);
-float R_DLightPoint (vec3_t p);
+float R_DLightPoint(vec3_t p);
-void R_NewMap (void);
-void R_Register (void);
-void R_UnRegister (void);
-void Draw_Init (void);
-qboolean R_Init( qboolean total );
-void R_Shutdown( qboolean total );
-void R_InitCaches (void);
-void D_FlushCaches (void);
+void R_NewMap(void);
+void R_Register(void);
+void R_UnRegister(void);
+void Draw_Init(void);
+qboolean R_Init(qboolean total);
+void R_Shutdown(qboolean total);
+void R_InitCaches(void);
+void D_FlushCaches(void);
-qhandle_t R_RegisterModel( const char *name );
+qhandle_t R_RegisterModel(const char *name);
-void R_ScreenShot_f( void );
+void R_ScreenShot_f(void);
-void R_RenderFrame (refdef_t *fd);
+void R_RenderFrame(refdef_t *fd);
-void R_BeginFrame( void );
+void R_BeginFrame(void);
-//void R_CinematicSetPalette( const unsigned char *palette );
+//void R_CinematicSetPalette(const unsigned char *palette);
-void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
+void Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length);
-void R_InitImages (void);
-void R_ShutdownImages (void);
+void R_InitImages(void);
+void R_ShutdownImages(void);
-void R_BuildGammaTable( void );
-void R_GammaCorrectAndSetPalette( const byte *pal );
+void R_BuildGammaTable(void);
+void R_GammaCorrectAndSetPalette(const byte *pal);
-void R_InitSkyBox( void );
-void R_EmitSkyBox( void );
+void R_InitSkyBox(void);
+void R_EmitSkyBox(void);
-void R_ApplySIRDAlgorithum( void );
+void R_ApplySIRDAlgorithum(void);
typedef struct swstate_s {
- qboolean fullscreen;
- int prev_mode; // last valid SW mode
+ qboolean fullscreen;
+ int prev_mode; // last valid SW mode
byte gammatable[256];
byte currentpalette[1024];
} swstate_t;
-void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha );
+void R_IMFlatShadedQuad(vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha);
-int R_IndexForColor( uint32_t color );
+int R_IndexForColor(uint32_t color);
-void R_InitDraw( void );
+void R_InitDraw(void);
extern swstate_t sw_state;
-
-
-
diff --git a/src/sw_main.c b/src/sw_main.c
index 7b9f01e..59390f6 100644
--- a/src/sw_main.c
+++ b/src/sw_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -87,7 +87,7 @@ int r_drawnpolycount;
int r_wholepolycount;
int *pfrustum_indexes[4];
-int r_frustum_indexes[4*6];
+int r_frustum_indexes[4 * 6];
mleaf_t *r_viewleaf;
int r_viewcluster, r_oldviewcluster;
@@ -95,7 +95,7 @@ int r_viewcluster, r_oldviewcluster;
float da_time1, da_time2, dp_time1, dp_time2, db_time1, db_time2, rw_time1, rw_time2;
float se_time1, se_time2, de_time1, de_time2;
-void R_MarkLeaves (void);
+void R_MarkLeaves(void);
cvar_t *sw_aliasstats;
cvar_t *sw_allow_modex;
@@ -162,74 +162,74 @@ unsigned int d_zwidth;
#endif // !USE_ASM
-int sintable[CYCLE*2];
-int intsintable[CYCLE*2];
-int blanktable[CYCLE*2]; // PGM
+int sintable[CYCLE * 2];
+int intsintable[CYCLE * 2];
+int blanktable[CYCLE * 2]; // PGM
/*
================
R_InitTurb
================
*/
-void R_InitTurb (void)
+void R_InitTurb(void)
{
int i;
-
- for (i=0 ; i<CYCLE*2 ; i++)
- {
- sintable[i] = AMP + sin(i*M_PI*2/CYCLE)*AMP;
- intsintable[i] = AMP2 + sin(i*M_PI*2/CYCLE)*AMP2; // AMP2, not 20
+
+ for (i = 0; i < CYCLE * 2; i++) {
+ sintable[i] = AMP + sin(i * M_PI * 2 / CYCLE) * AMP;
+ intsintable[i] = AMP2 + sin(i * M_PI * 2 / CYCLE) * AMP2; // AMP2, not 20
blanktable[i] = 0; //PGM
}
}
-void D_SCDump_f (void);
+void D_SCDump_f(void);
-void R_Register (void)
+void R_Register(void)
{
- sw_aliasstats = Cvar_Get ("sw_polymodelstats", "0", 0);
- sw_allow_modex = Cvar_Get( "sw_allow_modex", "1", CVAR_ARCHIVE );
- sw_clearcolor = Cvar_Get ("sw_clearcolor", "2", 0);
- sw_drawflat = Cvar_Get ("sw_drawflat", "0", CVAR_CHEAT);
- sw_draworder = Cvar_Get ("sw_draworder", "0", CVAR_CHEAT);
- sw_maxedges = Cvar_Get ("sw_maxedges", va( "%i", NUMSTACKEDGES ), 0);
- sw_maxsurfs = Cvar_Get ("sw_maxsurfs", va( "%i", NUMSTACKSURFACES ), 0);
- sw_mipcap = Cvar_Get ("sw_mipcap", "0", 0);
- sw_mipscale = Cvar_Get ("sw_mipscale", "1", 0);
- sw_reportedgeout = Cvar_Get ("sw_reportedgeout", "0", 0);
- sw_reportsurfout = Cvar_Get ("sw_reportsurfout", "0", 0);
- sw_stipplealpha = Cvar_Get( "sw_stipplealpha", "0", CVAR_ARCHIVE );
- sw_waterwarp = Cvar_Get ("sw_waterwarp", "1", 0);
+ sw_aliasstats = Cvar_Get("sw_polymodelstats", "0", 0);
+ sw_allow_modex = Cvar_Get("sw_allow_modex", "1", CVAR_ARCHIVE);
+ sw_clearcolor = Cvar_Get("sw_clearcolor", "2", 0);
+ sw_drawflat = Cvar_Get("sw_drawflat", "0", CVAR_CHEAT);
+ sw_draworder = Cvar_Get("sw_draworder", "0", CVAR_CHEAT);
+ sw_maxedges = Cvar_Get("sw_maxedges", va("%i", NUMSTACKEDGES), 0);
+ sw_maxsurfs = Cvar_Get("sw_maxsurfs", va("%i", NUMSTACKSURFACES), 0);
+ sw_mipcap = Cvar_Get("sw_mipcap", "0", 0);
+ sw_mipscale = Cvar_Get("sw_mipscale", "1", 0);
+ sw_reportedgeout = Cvar_Get("sw_reportedgeout", "0", 0);
+ sw_reportsurfout = Cvar_Get("sw_reportsurfout", "0", 0);
+ sw_stipplealpha = Cvar_Get("sw_stipplealpha", "0", CVAR_ARCHIVE);
+ sw_waterwarp = Cvar_Get("sw_waterwarp", "1", 0);
//Start Added by Lewey
- sw_drawsird = Cvar_Get ("sw_drawsird", "0", 0);
+ sw_drawsird = Cvar_Get("sw_drawsird", "0", 0);
//End Added by Lewey
- r_speeds = Cvar_Get ("r_speeds", "0", 0);
- r_fullbright = Cvar_Get ("r_fullbright", "0", CVAR_CHEAT);
- r_drawentities = Cvar_Get ("r_drawentities", "1", 0);
- r_drawworld = Cvar_Get ("r_drawworld", "1", CVAR_CHEAT);
- r_dspeeds = Cvar_Get ("r_dspeeds", "0", 0);
- r_lerpmodels = Cvar_Get( "r_lerpmodels", "1", 0 );
- r_novis = Cvar_Get( "r_novis", "0", 0 );
+ r_speeds = Cvar_Get("r_speeds", "0", 0);
+ r_fullbright = Cvar_Get("r_fullbright", "0", CVAR_CHEAT);
+ r_drawentities = Cvar_Get("r_drawentities", "1", 0);
+ r_drawworld = Cvar_Get("r_drawworld", "1", CVAR_CHEAT);
+ r_dspeeds = Cvar_Get("r_dspeeds", "0", 0);
+ r_lerpmodels = Cvar_Get("r_lerpmodels", "1", 0);
+ r_novis = Cvar_Get("r_novis", "0", 0);
- vid_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE );
+ vid_gamma = Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE);
- Cmd_AddCommand( "scdump", D_SCDump_f );
+ Cmd_AddCommand("scdump", D_SCDump_f);
//PGM
- sw_lockpvs = Cvar_Get ("sw_lockpvs", "0", 0);
+ sw_lockpvs = Cvar_Get("sw_lockpvs", "0", 0);
//PGM
}
-void R_UnRegister (void)
+void R_UnRegister(void)
{
- Cmd_RemoveCommand( "screenshot" );
- Cmd_RemoveCommand( "scdump" );
+ Cmd_RemoveCommand("screenshot");
+ Cmd_RemoveCommand("scdump");
}
-void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels ) {
+void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels)
+{
vid.width = width > MAXWIDTH ? MAXWIDTH : width;
vid.height = height > MAXHEIGHT ? MAXHEIGHT : height;
vid.buffer = pixels;
@@ -239,26 +239,26 @@ void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels
r_config.height = vid.height;
r_config.flags = flags;
- sw_surfcacheoverride = Cvar_Get ("sw_surfcacheoverride", "0", 0);
+ sw_surfcacheoverride = Cvar_Get("sw_surfcacheoverride", "0", 0);
D_FlushCaches();
- if( d_pzbuffer ) {
- Z_Free( d_pzbuffer );
+ if (d_pzbuffer) {
+ Z_Free(d_pzbuffer);
d_pzbuffer = NULL;
}
// free surface cache
- if( sc_base ) {
- Z_Free( sc_base );
+ if (sc_base) {
+ Z_Free(sc_base);
sc_base = NULL;
}
- d_pzbuffer = R_Mallocz( vid.width * vid.height * 2 );
+ d_pzbuffer = R_Mallocz(vid.width * vid.height * 2);
R_InitCaches();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
/*
@@ -266,27 +266,28 @@ void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels
R_Init
===============
*/
-qboolean R_Init( qboolean total ) {
- Com_DPrintf( "R_Init( %i )\n", total );
+qboolean R_Init(qboolean total)
+{
+ Com_DPrintf("R_Init( %i )\n", total);
- if( !total ) {
+ if (!total) {
R_InitImages();
R_InitDraw();
MOD_Init();
return qtrue;
}
- Com_Printf( "ref_soft " VERSION ", " __DATE__ "\n" );
+ Com_Printf("ref_soft " VERSION ", " __DATE__ "\n");
// TODO: collect 386-specific code in one place
#if USE_ASM
- Sys_MakeCodeWriteable( ( long )R_EdgeCodeStart, ( long )R_EdgeCodeEnd - ( long )R_EdgeCodeStart );
+ Sys_MakeCodeWriteable((long)R_EdgeCodeStart, (long)R_EdgeCodeEnd - (long)R_EdgeCodeStart);
#endif // USE_ASM
r_aliasuvscale = 1.0;
// create the window
- if( !VID_Init() ) {
+ if (!VID_Init()) {
return qfalse;
}
@@ -303,18 +304,18 @@ qboolean R_Init( qboolean total ) {
view_clipplanes[0].leftedge = qtrue;
view_clipplanes[1].rightedge = qtrue;
view_clipplanes[1].leftedge =
- view_clipplanes[2].leftedge =
- view_clipplanes[3].leftedge = qfalse;
+ view_clipplanes[2].leftedge =
+ view_clipplanes[3].leftedge = qfalse;
view_clipplanes[0].rightedge =
- view_clipplanes[2].rightedge =
- view_clipplanes[3].rightedge = qfalse;
+ view_clipplanes[2].rightedge =
+ view_clipplanes[3].rightedge = qfalse;
r_refdef.xOrigin = XCENTERING;
r_refdef.yOrigin = YCENTERING;
R_InitTurb();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
vid_gamma->modified = qfalse;
return qtrue;
@@ -325,8 +326,9 @@ qboolean R_Init( qboolean total ) {
R_Shutdown
===============
*/
-void R_Shutdown( qboolean total ) {
- Com_DPrintf( "R_Shutdown( %i )\n", total );
+void R_Shutdown(qboolean total)
+{
+ Com_DPrintf("R_Shutdown( %i )\n", total);
D_FlushCaches();
@@ -335,30 +337,30 @@ void R_Shutdown( qboolean total ) {
R_ShutdownImages();
// free world model
- if( r_worldmodel ) {
- BSP_Free( r_worldmodel );
+ if (r_worldmodel) {
+ BSP_Free(r_worldmodel);
r_worldmodel = NULL;
}
- if( !total ) {
+ if (!total) {
return;
}
// free z buffer
- if( d_pzbuffer ) {
- Z_Free( d_pzbuffer );
+ if (d_pzbuffer) {
+ Z_Free(d_pzbuffer);
d_pzbuffer = NULL;
}
// free surface cache
- if( sc_base ) {
- Z_Free( sc_base );
+ if (sc_base) {
+ Z_Free(sc_base);
sc_base = NULL;
}
// free colormap
- if( vid.colormap ) {
- Z_Free( vid.colormap );
+ if (vid.colormap) {
+ Z_Free(vid.colormap);
vid.colormap = NULL;
}
@@ -374,7 +376,7 @@ void R_Shutdown( qboolean total ) {
R_NewMap
===============
*/
-void R_NewMap (void)
+void R_NewMap(void)
{
r_viewcluster = -1;
@@ -383,19 +385,16 @@ void R_NewMap (void)
if (r_cnumsurfs <= MINSURFACES)
r_cnumsurfs = MINSURFACES;
- if (r_cnumsurfs > NUMSTACKSURFACES)
- {
- surfaces = R_Mallocz (r_cnumsurfs * sizeof(surf_t));
+ if (r_cnumsurfs > NUMSTACKSURFACES) {
+ surfaces = R_Mallocz(r_cnumsurfs * sizeof(surf_t));
surface_p = surfaces;
surf_max = &surfaces[r_cnumsurfs];
r_surfsonstack = qfalse;
- // surface 0 doesn't really exist; it's just a dummy because index 0
- // is used to indicate no edge attached to surface
+ // surface 0 doesn't really exist; it's just a dummy because index 0
+ // is used to indicate no edge attached to surface
surfaces--;
- R_SurfacePatch ();
- }
- else
- {
+ R_SurfacePatch();
+ } else {
r_surfsonstack = qtrue;
}
@@ -407,13 +406,10 @@ void R_NewMap (void)
if (r_numallocatededges < MINEDGES)
r_numallocatededges = MINEDGES;
- if (r_numallocatededges <= NUMSTACKEDGES)
- {
+ if (r_numallocatededges <= NUMSTACKEDGES) {
auxedges = NULL;
- }
- else
- {
- auxedges = R_Mallocz (r_numallocatededges * sizeof(edge_t));
+ } else {
+ auxedges = R_Mallocz(r_numallocatededges * sizeof(edge_t));
}
}
@@ -426,7 +422,7 @@ Mark the leaves and nodes that are in the PVS for the current
cluster
===============
*/
-void R_MarkLeaves (void)
+void R_MarkLeaves(void)
{
byte vis[VIS_MAX_BYTES];
mnode_t *node;
@@ -435,11 +431,10 @@ void R_MarkLeaves (void)
int cluster;
if (r_oldviewcluster == r_viewcluster && !r_novis->integer &&
- r_viewcluster != -1)
- {
+ r_viewcluster != -1) {
return;
}
-
+
// development aid to let you run around and see exactly where
// the pvs ends
if (sw_lockpvs->integer)
@@ -448,28 +443,24 @@ void R_MarkLeaves (void)
r_visframecount++;
r_oldviewcluster = r_viewcluster;
- if (r_novis->integer || r_viewcluster == -1 || !r_worldmodel->vis)
- {
+ if (r_novis->integer || r_viewcluster == -1 || !r_worldmodel->vis) {
// mark everything
- for (i=0 ; i<r_worldmodel->numleafs ; i++)
+ for (i = 0; i < r_worldmodel->numleafs; i++)
r_worldmodel->leafs[i].visframe = r_visframecount;
- for (i=0 ; i<r_worldmodel->numnodes ; i++)
+ for (i = 0; i < r_worldmodel->numnodes; i++)
r_worldmodel->nodes[i].visframe = r_visframecount;
return;
}
- BSP_ClusterVis (r_worldmodel, vis, r_viewcluster, DVIS_PVS);
-
- for (i=0,leaf=r_worldmodel->leafs ; i<r_worldmodel->numleafs ; i++, leaf++)
- {
+ BSP_ClusterVis(r_worldmodel, vis, r_viewcluster, DVIS_PVS);
+
+ for (i = 0, leaf = r_worldmodel->leafs; i < r_worldmodel->numleafs; i++, leaf++) {
cluster = leaf->cluster;
if (cluster == -1)
continue;
- if (Q_IsBitSet( vis, cluster ))
- {
+ if (Q_IsBitSet(vis, cluster)) {
node = (mnode_t *)leaf;
- do
- {
+ do {
if (node->visframe == r_visframecount)
break;
node->visframe = r_visframecount;
@@ -485,41 +476,43 @@ void R_MarkLeaves (void)
**
** IMPLEMENT THIS!
*/
-static void R_DrawNullModel( void ) {
+static void R_DrawNullModel(void)
+{
}
-static int R_DrawEntities( int translucent ) {
+static int R_DrawEntities(int translucent)
+{
int i;
qboolean translucent_entities = 0;
// all bmodels have already been drawn by the edge list
- for( i = 0; i < r_newrefdef.num_entities; i++ ){
+ for (i = 0; i < r_newrefdef.num_entities; i++) {
currententity = &r_newrefdef.entities[i];
- if( ( currententity->flags & RF_TRANSLUCENT ) == translucent ) {
+ if ((currententity->flags & RF_TRANSLUCENT) == translucent) {
translucent_entities++;
continue;
}
- if( currententity->flags & RF_BEAM ) {
+ if (currententity->flags & RF_BEAM) {
modelorg[0] = -r_origin[0];
modelorg[1] = -r_origin[1];
modelorg[2] = -r_origin[2];
- VectorCopy( vec3_origin, r_entorigin );
- R_DrawBeam( currententity );
+ VectorCopy(vec3_origin, r_entorigin);
+ R_DrawBeam(currententity);
} else {
- if( currententity->model & 0x80000000 ) {
+ if (currententity->model & 0x80000000) {
continue;
}
- currentmodel = MOD_ForHandle( currententity->model );
- if( !currentmodel ) {
+ currentmodel = MOD_ForHandle(currententity->model);
+ if (!currentmodel) {
R_DrawNullModel();
continue;
}
- VectorCopy (currententity->origin, r_entorigin);
- VectorSubtract (r_origin, r_entorigin, modelorg);
+ VectorCopy(currententity->origin, r_entorigin);
+ VectorSubtract(r_origin, r_entorigin, modelorg);
- switch( currentmodel->type ) {
+ switch (currentmodel->type) {
case MOD_ALIAS:
R_AliasDrawModel();
break;
@@ -529,7 +522,7 @@ static int R_DrawEntities( int translucent ) {
case MOD_EMPTY:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad model type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad model type", __func__);
}
}
}
@@ -541,15 +534,16 @@ static int R_DrawEntities( int translucent ) {
R_DrawEntitiesOnList
=============
*/
-static void R_DrawEntitiesOnList( void ) {
+static void R_DrawEntitiesOnList(void)
+{
int translucent_entities;
- if( !r_drawentities->integer )
+ if (!r_drawentities->integer)
return;
- translucent_entities = R_DrawEntities( RF_TRANSLUCENT );
- if( translucent_entities ) {
- R_DrawEntities( 0 );
+ translucent_entities = R_DrawEntities(RF_TRANSLUCENT);
+ if (translucent_entities) {
+ R_DrawEntities(0);
}
}
@@ -559,7 +553,7 @@ static void R_DrawEntitiesOnList( void ) {
R_BmodelCheckBBox
=============
*/
-int R_BmodelCheckBBox (float *minmaxs)
+int R_BmodelCheckBBox(float *minmaxs)
{
int i, *pindex, clipflags;
vec3_t acceptpt, rejectpt;
@@ -567,33 +561,32 @@ int R_BmodelCheckBBox (float *minmaxs)
clipflags = 0;
- for (i=0 ; i<4 ; i++)
- {
- // generate accept and reject points
- // FIXME: do with fast look-ups or integer tests based on the sign bit
- // of the floating point values
+ for (i = 0; i < 4; i++) {
+ // generate accept and reject points
+ // FIXME: do with fast look-ups or integer tests based on the sign bit
+ // of the floating point values
pindex = pfrustum_indexes[i];
rejectpt[0] = minmaxs[pindex[0]];
rejectpt[1] = minmaxs[pindex[1]];
rejectpt[2] = minmaxs[pindex[2]];
-
- d = DotProduct (rejectpt, view_clipplanes[i].normal);
+
+ d = DotProduct(rejectpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
if (d <= 0)
return BMODEL_FULLY_CLIPPED;
- acceptpt[0] = minmaxs[pindex[3+0]];
- acceptpt[1] = minmaxs[pindex[3+1]];
- acceptpt[2] = minmaxs[pindex[3+2]];
+ acceptpt[0] = minmaxs[pindex[3 + 0]];
+ acceptpt[1] = minmaxs[pindex[3 + 1]];
+ acceptpt[2] = minmaxs[pindex[3 + 2]];
- d = DotProduct (acceptpt, view_clipplanes[i].normal);
+ d = DotProduct(acceptpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
if (d <= 0)
- clipflags |= (1<<i);
+ clipflags |= (1 << i);
}
return clipflags;
@@ -607,27 +600,27 @@ R_FindTopnode
Find the first node that splits the given box
===================
*/
-mnode_t *R_FindTopnode (vec3_t mins, vec3_t maxs)
+mnode_t *R_FindTopnode(vec3_t mins, vec3_t maxs)
{
int sides;
mnode_t *node;
node = r_worldmodel->nodes;
- while (node->visframe == r_visframecount) {
+ while (node->visframe == r_visframecount) {
if (!node->plane) {
- if (((mleaf_t * )node)->contents != CONTENTS_SOLID)
+ if (((mleaf_t *)node)->contents != CONTENTS_SOLID)
return node; // we've reached a non-solid leaf, so it's
- // visible and not BSP clipped
+ // visible and not BSP clipped
return NULL; // in solid, so not visible
}
-
+
sides = BoxOnPlaneSideFast(mins, maxs, node->plane);
-
+
if (sides == 3)
return node; // this is the splitter
-
- // not split yet; recurse down the contacted side
+
+ // not split yet; recurse down the contacted side
if (sides & 1)
node = node->children[0];
else
@@ -645,52 +638,48 @@ RotatedBBox
Returns an axially aligned box that contains the input box at the given rotation
=============
*/
-void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles,
- vec3_t tmins, vec3_t tmaxs)
+void RotatedBBox(vec3_t mins, vec3_t maxs, vec3_t angles,
+ vec3_t tmins, vec3_t tmaxs)
{
vec3_t tmp, v;
int i, j;
vec3_t forward, right, up;
- if (!angles[0] && !angles[1] && !angles[2])
- {
- VectorCopy (mins, tmins);
- VectorCopy (maxs, tmaxs);
+ if (!angles[0] && !angles[1] && !angles[2]) {
+ VectorCopy(mins, tmins);
+ VectorCopy(maxs, tmaxs);
return;
}
- for (i=0 ; i<3 ; i++)
- {
+ for (i = 0; i < 3; i++) {
tmins[i] = 99999;
tmaxs[i] = -99999;
}
- AngleVectors (angles, forward, right, up);
+ AngleVectors(angles, forward, right, up);
- for ( i = 0; i < 8; i++ )
- {
- if ( i & 1 )
+ for (i = 0; i < 8; i++) {
+ if (i & 1)
tmp[0] = mins[0];
else
tmp[0] = maxs[0];
- if ( i & 2 )
+ if (i & 2)
tmp[1] = mins[1];
else
tmp[1] = maxs[1];
- if ( i & 4 )
+ if (i & 4)
tmp[2] = mins[2];
else
tmp[2] = maxs[2];
- VectorScale (forward, tmp[0], v);
- VectorMA (v, -tmp[1], right, v);
- VectorMA (v, tmp[2], up, v);
+ VectorScale(forward, tmp[0], v);
+ VectorMA(v, -tmp[1], right, v);
+ VectorMA(v, tmp[2], up, v);
- for (j=0 ; j<3 ; j++)
- {
+ for (j = 0; j < 3; j++) {
if (v[j] < tmins[j])
tmins[j] = v[j];
if (v[j] > tmaxs[j])
@@ -704,7 +693,7 @@ void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles,
R_DrawBEntitiesOnList
=============
*/
-void R_DrawBEntitiesOnList (void)
+void R_DrawBEntitiesOnList(void)
{
int i, index, clipflags;
vec3_t oldorigin;
@@ -716,72 +705,68 @@ void R_DrawBEntitiesOnList (void)
if (!r_drawentities->value)
return;
- VectorCopy (modelorg, oldorigin);
+ VectorCopy(modelorg, oldorigin);
insubmodel = qtrue;
r_dlightframecount = r_framecount;
- for (i=0 ; i<r_newrefdef.num_entities ; i++)
- {
+ for (i = 0; i < r_newrefdef.num_entities; i++) {
currententity = &r_newrefdef.entities[i];
index = currententity->model;
- if( !( index & 0x80000000 ) ) {
+ if (!(index & 0x80000000)) {
continue;
}
index = ~index;
- if( index < 1 || index >= r_worldmodel->nummodels ) {
- Com_Error( ERR_DROP, "%s: inline model %d out of range",
- __func__, index );
+ if (index < 1 || index >= r_worldmodel->nummodels) {
+ Com_Error(ERR_DROP, "%s: inline model %d out of range",
+ __func__, index);
}
model = &r_worldmodel->models[index];
if (model->numfaces == 0)
continue; // clip brush only
- if ( currententity->flags & RF_BEAM )
+ if (currententity->flags & RF_BEAM)
continue;
- // see if the bounding box lets us trivially reject, also sets
- // trivial accept status
- RotatedBBox (model->mins, model->maxs,
- currententity->angles, mins, maxs);
- VectorAdd (mins, currententity->origin, minmaxs);
- VectorAdd (maxs, currententity->origin, (minmaxs+3));
-
- clipflags = R_BmodelCheckBBox (minmaxs);
+ // see if the bounding box lets us trivially reject, also sets
+ // trivial accept status
+ RotatedBBox(model->mins, model->maxs,
+ currententity->angles, mins, maxs);
+ VectorAdd(mins, currententity->origin, minmaxs);
+ VectorAdd(maxs, currententity->origin, (minmaxs + 3));
+
+ clipflags = R_BmodelCheckBBox(minmaxs);
if (clipflags == BMODEL_FULLY_CLIPPED)
continue; // off the edge of the screen
- topnode = R_FindTopnode (minmaxs, minmaxs+3);
+ topnode = R_FindTopnode(minmaxs, minmaxs + 3);
if (!topnode)
continue; // no part in a visible leaf
- VectorCopy (currententity->origin, r_entorigin);
- VectorSubtract (r_origin, r_entorigin, modelorg);
+ VectorCopy(currententity->origin, r_entorigin);
+ VectorSubtract(r_origin, r_entorigin, modelorg);
- // FIXME: stop transforming twice
- R_RotateBmodel ();
+ // FIXME: stop transforming twice
+ R_RotateBmodel();
- // calculate dynamic lighting for bmodel
- R_PushDlights (model->headnode);
+ // calculate dynamic lighting for bmodel
+ R_PushDlights(model->headnode);
- if (topnode->plane)
- {
- // not a leaf; has to be clipped to the world BSP
+ if (topnode->plane) {
+ // not a leaf; has to be clipped to the world BSP
r_clipflags = clipflags;
- R_DrawSolidClippedSubmodelPolygons (model, topnode);
- }
- else
- {
- // falls entirely in one leaf, so we just put all the
- // edges in the edge list and let 1/z sorting handle
- // drawing order
- R_DrawSubmodelPolygons (model, clipflags, topnode);
+ R_DrawSolidClippedSubmodelPolygons(model, topnode);
+ } else {
+ // falls entirely in one leaf, so we just put all the
+ // edges in the edge list and let 1/z sorting handle
+ // drawing order
+ R_DrawSubmodelPolygons(model, clipflags, topnode);
}
- // put back world rotation and frustum clipping
- // FIXME: R_RotateBmodel should just work off base_vxx
- VectorCopy (base_vpn, vpn);
- VectorCopy (base_vup, vup);
- VectorCopy (base_vright, vright);
- VectorCopy (oldorigin, modelorg);
- R_TransformFrustum ();
+ // put back world rotation and frustum clipping
+ // FIXME: R_RotateBmodel should just work off base_vxx
+ VectorCopy(base_vpn, vpn);
+ VectorCopy(base_vup, vup);
+ VectorCopy(base_vright, vright);
+ VectorCopy(oldorigin, modelorg);
+ R_TransformFrustum();
}
insubmodel = qfalse;
@@ -793,61 +778,54 @@ void R_DrawBEntitiesOnList (void)
R_EdgeDrawing
================
*/
-void R_EdgeDrawing (void)
+void R_EdgeDrawing(void)
{
edge_t ledges[NUMSTACKEDGES +
- ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1];
+ ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1];
surf_t lsurfs[NUMSTACKSURFACES +
- ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1];
+ ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1];
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
return;
- if (auxedges)
- {
+ if (auxedges) {
r_edges = auxedges;
- }
- else
- {
- r_edges = (edge_t *)
- (((long)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ } else {
+ r_edges = (edge_t *)
+ (((long)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
}
- if (r_surfsonstack)
- {
- surfaces = (surf_t *)
- (((long)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ if (r_surfsonstack) {
+ surfaces = (surf_t *)
+ (((long)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
surf_max = &surfaces[r_cnumsurfs];
- // surface 0 doesn't really exist; it's just a dummy because index 0
- // is used to indicate no edge attached to surface
+ // surface 0 doesn't really exist; it's just a dummy because index 0
+ // is used to indicate no edge attached to surface
surfaces--;
- R_SurfacePatch ();
+ R_SurfacePatch();
}
- R_BeginEdgeFrame ();
+ R_BeginEdgeFrame();
- if (r_dspeeds->integer)
- {
- rw_time1 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ rw_time1 = Sys_Milliseconds();
}
- R_RenderWorld ();
+ R_RenderWorld();
- if (r_dspeeds->integer)
- {
- rw_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ rw_time2 = Sys_Milliseconds();
db_time1 = rw_time2;
}
- R_DrawBEntitiesOnList ();
+ R_DrawBEntitiesOnList();
- if (r_dspeeds->integer)
- {
- db_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ db_time2 = Sys_Milliseconds();
se_time1 = db_time2;
}
- R_ScanEdges ();
+ R_ScanEdges();
}
//=======================================================================
@@ -859,21 +837,21 @@ R_CalcPalette
=============
*/
-void R_CalcPalette (void)
+void R_CalcPalette(void)
{
static qboolean modified;
- byte palette[256*4], *in, *out;
+ byte palette[256 * 4], *in, *out;
int i;
float alpha, one_minus_alpha;
vec3_t premult;
int r, g, b;
alpha = r_newrefdef.blend[3];
- if( alpha <= 0 ) {
+ if (alpha <= 0) {
if (modified) {
// set back to default
modified = qfalse;
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
return;
}
@@ -882,31 +860,32 @@ void R_CalcPalette (void)
if (alpha > 1)
alpha = 1;
- premult[0] = r_newrefdef.blend[0]*alpha*255;
- premult[1] = r_newrefdef.blend[1]*alpha*255;
- premult[2] = r_newrefdef.blend[2]*alpha*255;
+ premult[0] = r_newrefdef.blend[0] * alpha * 255;
+ premult[1] = r_newrefdef.blend[1] * alpha * 255;
+ premult[2] = r_newrefdef.blend[2] * alpha * 255;
one_minus_alpha = (1.0 - alpha);
- in = ( byte * )d_8to24table;
+ in = (byte *)d_8to24table;
out = palette;
- for( i = 0; i < 256; i++, in += 4, out += 4 ) {
+ for (i = 0; i < 256; i++, in += 4, out += 4) {
r = premult[0] + one_minus_alpha * in[0];
g = premult[1] + one_minus_alpha * in[1];
b = premult[2] + one_minus_alpha * in[2];
- if ( r > 255 ) r = 255;
- if ( g > 255 ) g = 255;
- if ( b > 255 ) b = 255;
+ if (r > 255) r = 255;
+ if (g > 255) g = 255;
+ if (b > 255) b = 255;
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = 255;
}
- R_GammaCorrectAndSetPalette( palette );
+ R_GammaCorrectAndSetPalette(palette);
}
-byte *IMG_ReadPixels( byte **palette, int *width, int *height, int *rowbytes ) {
+byte *IMG_ReadPixels(byte **palette, int *width, int *height, int *rowbytes)
+{
*palette = sw_state.currentpalette;
*width = vid.width;
*height = vid.height;
@@ -922,78 +901,73 @@ R_RenderFrame
@@@@@@@@@@@@@@@@
*/
-void R_RenderFrame (refdef_t *fd)
+void R_RenderFrame(refdef_t *fd)
{
r_newrefdef = *fd;
- if (!r_worldmodel && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- Com_Error (ERR_FATAL,"R_RenderView: NULL worldmodel");
+ if (!r_worldmodel && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
+ Com_Error(ERR_FATAL, "R_RenderView: NULL worldmodel");
- VectorCopy (fd->vieworg, r_refdef.vieworg);
- VectorCopy (fd->viewangles, r_refdef.viewangles);
+ VectorCopy(fd->vieworg, r_refdef.vieworg);
+ VectorCopy(fd->viewangles, r_refdef.viewangles);
if (r_speeds->integer || r_dspeeds->integer)
- r_time1 = Sys_Milliseconds ();
+ r_time1 = Sys_Milliseconds();
- R_SetupFrame ();
+ R_SetupFrame();
- R_MarkLeaves (); // done here so we know if we're in water
+ R_MarkLeaves(); // done here so we know if we're in water
- R_PushDlights (r_worldmodel->nodes);
+ R_PushDlights(r_worldmodel->nodes);
- R_EdgeDrawing ();
+ R_EdgeDrawing();
- if (r_dspeeds->integer)
- {
- se_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ se_time2 = Sys_Milliseconds();
de_time1 = se_time2;
}
- R_DrawEntitiesOnList ();
+ R_DrawEntitiesOnList();
- if (r_dspeeds->integer)
- {
- de_time2 = Sys_Milliseconds ();
- dp_time1 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ de_time2 = Sys_Milliseconds();
+ dp_time1 = Sys_Milliseconds();
}
- R_DrawParticles ();
+ R_DrawParticles();
if (r_dspeeds->integer)
- dp_time2 = Sys_Milliseconds ();
+ dp_time2 = Sys_Milliseconds();
R_DrawAlphaSurfaces();
//Start Replaced by Lewey
- if( sw_drawsird->integer && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- {
+ if (sw_drawsird->integer && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) {
R_ApplySIRDAlgorithum();
- }
- else
- {
+ } else {
//don't do warp if we are doing SIRD because the warp
//would make the SIRD impossible to see.
if (r_dowarp)
- D_WarpScreen ();
+ D_WarpScreen();
}
//End Replaced by Lewey
if (r_dspeeds->integer)
- da_time1 = Sys_Milliseconds ();
+ da_time1 = Sys_Milliseconds();
if (r_dspeeds->integer)
- da_time2 = Sys_Milliseconds ();
+ da_time2 = Sys_Milliseconds();
- R_CalcPalette ();
+ R_CalcPalette();
if (sw_aliasstats->integer)
- R_PrintAliasStats ();
-
+ R_PrintAliasStats();
+
if (r_speeds->integer)
- R_PrintTimes ();
+ R_PrintTimes();
if (r_dspeeds->integer)
- R_PrintDSpeeds ();
+ R_PrintDSpeeds();
if (sw_reportsurfout->integer && r_outofsurfaces)
Com_Printf("Short %d surfaces\n", r_outofsurfaces);
@@ -1005,14 +979,16 @@ void R_RenderFrame (refdef_t *fd)
/*
** R_BeginFrame
*/
-void R_BeginFrame( void ) {
+void R_BeginFrame(void)
+{
VID_BeginFrame();
}
-void R_EndFrame( void ) {
- if( vid_gamma->modified ) {
+void R_EndFrame(void)
+{
+ if (vid_gamma->modified) {
R_BuildGammaTable();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
vid_gamma->modified = qfalse;
}
@@ -1022,57 +998,53 @@ void R_EndFrame( void ) {
/*
** R_GammaCorrectAndSetPalette
*/
-void R_GammaCorrectAndSetPalette( const byte *palette ) {
+void R_GammaCorrectAndSetPalette(const byte *palette)
+{
int i;
byte *dest;
dest = sw_state.currentpalette;
- for( i = 0; i < 256; i++ ) {
- dest[0] = sw_state.gammatable[ palette[0] ];
- dest[1] = sw_state.gammatable[ palette[1] ];
- dest[2] = sw_state.gammatable[ palette[2] ];
+ for (i = 0; i < 256; i++) {
+ dest[0] = sw_state.gammatable[palette[0]];
+ dest[1] = sw_state.gammatable[palette[1]];
+ dest[2] = sw_state.gammatable[palette[2]];
palette += 4; dest += 4;
}
- VID_UpdatePalette( sw_state.currentpalette );
+ VID_UpdatePalette(sw_state.currentpalette);
}
#if 0
/*
** R_CinematicSetPalette
*/
-void R_CinematicSetPalette( const byte *palette )
+void R_CinematicSetPalette(const byte *palette)
{
byte palette32[1024];
int i, j, w;
int *d;
// clear screen to black to avoid any palette flash
- w = abs(vid.rowbytes)>>2; // stupid negative pitch win32 stuff...
- for (i=0 ; i<vid.height ; i++, d+=w)
- {
- d = (int *)(vid.buffer + i*vid.rowbytes);
- for (j=0 ; j<w ; j++)
+ w = abs(vid.rowbytes) >> 2; // stupid negative pitch win32 stuff...
+ for (i = 0; i < vid.height; i++, d += w) {
+ d = (int *)(vid.buffer + i * vid.rowbytes);
+ for (j = 0; j < w; j++)
d[j] = 0;
}
// flush it to the screen
- R_EndFrame ();
-
- if ( palette )
- {
- for ( i = 0; i < 256; i++ )
- {
- palette32[i*4+0] = palette[i*3+0];
- palette32[i*4+1] = palette[i*3+1];
- palette32[i*4+2] = palette[i*3+2];
- palette32[i*4+3] = 0xFF;
+ R_EndFrame();
+
+ if (palette) {
+ for (i = 0; i < 256; i++) {
+ palette32[i * 4 + 0] = palette[i * 3 + 0];
+ palette32[i * 4 + 1] = palette[i * 3 + 1];
+ palette32[i * 4 + 2] = palette[i * 3 + 2];
+ palette32[i * 4 + 3] = 0xFF;
}
- R_GammaCorrectAndSetPalette( palette32 );
- }
- else
- {
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette(palette32);
+ } else {
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
}
#endif
@@ -1080,7 +1052,7 @@ void R_CinematicSetPalette( const byte *palette )
/*
** R_DrawBeam
*/
-void R_DrawBeam( entity_t *e )
+void R_DrawBeam(entity_t *e)
{
#define NUM_BEAM_SEGS 6
@@ -1103,28 +1075,26 @@ void R_DrawBeam( entity_t *e )
normalized_direction[1] = direction[1] = oldorigin[1] - origin[1];
normalized_direction[2] = direction[2] = oldorigin[2] - origin[2];
- if ( VectorNormalize( normalized_direction ) == 0 )
+ if (VectorNormalize(normalized_direction) == 0)
return;
- PerpendicularVector( perpvec, normalized_direction );
- VectorScale( perpvec, e->frame / 2, perpvec );
+ PerpendicularVector(perpvec, normalized_direction);
+ VectorScale(perpvec, e->frame / 2, perpvec);
- for ( i = 0; i < NUM_BEAM_SEGS; i++ )
- {
- R_RotatePointAroundVector( start_points[i], normalized_direction,
- perpvec, (360.0/NUM_BEAM_SEGS)*i );
- VectorAdd( start_points[i], origin, start_points[i] );
- VectorAdd( start_points[i], direction, end_points[i] );
+ for (i = 0; i < NUM_BEAM_SEGS; i++) {
+ R_RotatePointAroundVector(start_points[i], normalized_direction,
+ perpvec, (360.0 / NUM_BEAM_SEGS)*i);
+ VectorAdd(start_points[i], origin, start_points[i]);
+ VectorAdd(start_points[i], direction, end_points[i]);
}
- for ( i = 0; i < NUM_BEAM_SEGS; i++ )
- {
- R_IMFlatShadedQuad( start_points[i],
- end_points[i],
- end_points[(i+1)%NUM_BEAM_SEGS],
- start_points[(i+1)%NUM_BEAM_SEGS],
- e->skinnum & 0xFF,
- e->alpha );
+ for (i = 0; i < NUM_BEAM_SEGS; i++) {
+ R_IMFlatShadedQuad(start_points[i],
+ end_points[i],
+ end_points[(i + 1) % NUM_BEAM_SEGS],
+ start_points[(i + 1) % NUM_BEAM_SEGS],
+ e->skinnum & 0xFF,
+ e->alpha);
}
}
diff --git a/src/sw_misc.c b/src/sw_misc.c
index 0a00d04..5e0ede5 100644
--- a/src/sw_misc.c
+++ b/src/sw_misc.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,9 +29,9 @@ cvar_t *sw_mipscale;
surfcache_t *d_initial_rover;
qboolean d_roverwrapped;
int d_minmip;
-float d_scalemip[NUM_MIPS-1];
+float d_scalemip[NUM_MIPS - 1];
-static float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
+static float basemip[NUM_MIPS - 1] = {1.0, 0.5 * 0.8, 0.25 * 0.8};
extern int d_aflatcolor;
@@ -40,30 +40,29 @@ int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
int d_pix_min, d_pix_max, d_pix_shift;
int d_scantable[MAXHEIGHT];
-short *zspantable[MAXHEIGHT];
+short *zspantable[MAXHEIGHT];
/*
================
D_Patch
================
*/
-void D_Patch (void)
+void D_Patch(void)
{
#if USE_ASM
- extern void D_Aff8Patch( void );
+ extern void D_Aff8Patch(void);
static qboolean protectset8 = qfalse;
- extern void D_PolysetAff8Start( void );
-
- if (!protectset8)
- {
- Sys_MakeCodeWriteable ((int)D_PolysetAff8Start,
- (int)D_Aff8Patch - (int)D_PolysetAff8Start);
- Sys_MakeCodeWriteable ((long)R_Surf8Start,
- (long)R_Surf8End - (long)R_Surf8Start);
+ extern void D_PolysetAff8Start(void);
+
+ if (!protectset8) {
+ Sys_MakeCodeWriteable((int)D_PolysetAff8Start,
+ (int)D_Aff8Patch - (int)D_PolysetAff8Start);
+ Sys_MakeCodeWriteable((long)R_Surf8Start,
+ (long)R_Surf8End - (long)R_Surf8Start);
protectset8 = qtrue;
}
- R_Surf8Patch ();
+ R_Surf8Patch();
D_Aff8Patch();
#endif
}
@@ -72,7 +71,7 @@ void D_Patch (void)
D_ViewChanged
================
*/
-void D_ViewChanged (void)
+void D_ViewChanged(void)
{
int i;
@@ -96,24 +95,22 @@ void D_ViewChanged (void)
d_vrecty = r_refdef.vrect.y;
d_vrectright_particle = r_refdef.vrectright - d_pix_max;
d_vrectbottom_particle =
- r_refdef.vrectbottom - d_pix_max;
+ r_refdef.vrectbottom - d_pix_max;
- for (i=0 ; i<vid.height; i++)
- {
- d_scantable[i] = i*r_screenwidth;
- zspantable[i] = d_pzbuffer + i*d_zwidth;
+ for (i = 0; i < vid.height; i++) {
+ d_scantable[i] = i * r_screenwidth;
+ zspantable[i] = d_pzbuffer + i * d_zwidth;
}
/*
** clear Z-buffer and color-buffers if we're doing the gallery
*/
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
- {
- memset( d_pzbuffer, 0xff, vid.width * vid.height * sizeof( d_pzbuffer[0] ) );
- R_DrawFill8( r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*( int ) sw_clearcolor->value & 0xff*/0 );
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL) {
+ memset(d_pzbuffer, 0xff, vid.width * vid.height * sizeof(d_pzbuffer[0]));
+ R_DrawFill8(r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*(int)sw_clearcolor->value & 0xff*/0);
}
- D_Patch ();
+ D_Patch();
}
@@ -123,17 +120,17 @@ void D_ViewChanged (void)
R_PrintTimes
=============
*/
-void R_PrintTimes (void)
+void R_PrintTimes(void)
{
int r_time2;
int ms;
- r_time2 = Sys_Milliseconds ();
+ r_time2 = Sys_Milliseconds();
ms = r_time2 - r_time1;
-
+
Com_Printf("%5i ms %3i/%3i/%3i poly %3i surf\n",
- ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
+ ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
c_surf = 0;
}
@@ -143,11 +140,11 @@ void R_PrintTimes (void)
R_PrintDSpeeds
=============
*/
-void R_PrintDSpeeds (void)
+void R_PrintDSpeeds(void)
{
int ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, da_time;
- r_time2 = Sys_Milliseconds ();
+ r_time2 = Sys_Milliseconds();
da_time = (da_time2 - da_time1);
dp_time = (dp_time2 - dp_time1);
@@ -158,7 +155,7 @@ void R_PrintDSpeeds (void)
ms = (r_time2 - r_time1);
Com_Printf("%3i %2ip %2iw %2ib %2is %2ie %2ia\n",
- ms, dp_time, rw_time, db_time, se_time, de_time, da_time);
+ ms, dp_time, rw_time, db_time, se_time, de_time, da_time);
}
@@ -167,7 +164,7 @@ void R_PrintDSpeeds (void)
R_PrintAliasStats
=============
*/
-void R_PrintAliasStats (void)
+void R_PrintAliasStats(void)
{
Com_Printf("%3i polygon model drawn\n", r_amodels_drawn);
}
@@ -179,24 +176,23 @@ void R_PrintAliasStats (void)
R_TransformFrustum
===================
*/
-void R_TransformFrustum (void)
+void R_TransformFrustum(void)
{
int i;
vec3_t v, v2;
-
- for (i=0 ; i<4 ; i++)
- {
+
+ for (i = 0; i < 4; i++) {
v[0] = screenedge[i].normal[2];
v[1] = -screenedge[i].normal[0];
v[2] = screenedge[i].normal[1];
- v2[0] = v[1]*vright[0] + v[2]*vup[0] + v[0]*vpn[0];
- v2[1] = v[1]*vright[1] + v[2]*vup[1] + v[0]*vpn[1];
- v2[2] = v[1]*vright[2] + v[2]*vup[2] + v[0]*vpn[2];
+ v2[0] = v[1] * vright[0] + v[2] * vup[0] + v[0] * vpn[0];
+ v2[1] = v[1] * vright[1] + v[2] * vup[1] + v[0] * vpn[1];
+ v2[2] = v[1] * vright[2] + v[2] * vup[2] + v[0] * vpn[2];
- VectorCopy (v2, view_clipplanes[i].normal);
+ VectorCopy(v2, view_clipplanes[i].normal);
- view_clipplanes[i].dist = DotProduct (modelorg, v2);
+ view_clipplanes[i].dist = DotProduct(modelorg, v2);
}
}
@@ -206,11 +202,11 @@ void R_TransformFrustum (void)
TransformVector
================
*/
-void TransformVector (vec3_t in, vec3_t out)
+void TransformVector(vec3_t in, vec3_t out)
{
- out[0] = DotProduct(in,vright);
- out[1] = DotProduct(in,vup);
- out[2] = DotProduct(in,vpn);
+ out[0] = DotProduct(in, vright);
+ out[1] = DotProduct(in, vup);
+ out[2] = DotProduct(in, vpn);
}
/*
@@ -218,14 +214,14 @@ void TransformVector (vec3_t in, vec3_t out)
R_TransformPlane
================
*/
-void R_TransformPlane (cplane_t *p, float *normal, float *dist)
+void R_TransformPlane(cplane_t *p, float *normal, float *dist)
{
float d;
-
- d = DotProduct (r_origin, p->normal);
+
+ d = DotProduct(r_origin, p->normal);
*dist = p->dist - d;
// TODO: when we have rotating entities, this will need to use the view matrix
- TransformVector (p->normal, normal);
+ TransformVector(p->normal, normal);
}
@@ -234,29 +230,24 @@ void R_TransformPlane (cplane_t *p, float *normal, float *dist)
R_SetUpFrustumIndexes
===============
*/
-void R_SetUpFrustumIndexes (void)
+void R_SetUpFrustumIndexes(void)
{
int i, j, *pindex;
pindex = r_frustum_indexes;
- for (i=0 ; i<4 ; i++)
- {
- for (j=0 ; j<3 ; j++)
- {
- if (view_clipplanes[i].normal[j] < 0)
- {
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 3; j++) {
+ if (view_clipplanes[i].normal[j] < 0) {
pindex[j] = j;
- pindex[j+3] = j+3;
- }
- else
- {
- pindex[j] = j+3;
- pindex[j+3] = j;
+ pindex[j + 3] = j + 3;
+ } else {
+ pindex[j] = j + 3;
+ pindex[j + 3] = j;
}
}
- // FIXME: do just once at start
+ // FIXME: do just once at start
pfrustum_indexes[i] = pindex;
pindex += 6;
}
@@ -270,22 +261,22 @@ Called every time the vid structure or r_refdef changes.
Guaranteed to be called before the first refresh
===============
*/
-void R_ViewChanged (vrectSoft_t *vr)
+void R_ViewChanged(vrectSoft_t *vr)
{
int i;
r_refdef.vrect = *vr;
- r_refdef.horizontalFieldOfView = 2*tan((float)r_newrefdef.fov_x/360*M_PI);;
- verticalFieldOfView = 2*tan((float)r_newrefdef.fov_y/360*M_PI);
+ r_refdef.horizontalFieldOfView = 2 * tan((float)r_newrefdef.fov_x / 360 * M_PI);
+ verticalFieldOfView = 2 * tan((float)r_newrefdef.fov_y / 360 * M_PI);
r_refdef.fvrectx = (float)r_refdef.vrect.x;
r_refdef.fvrectx_adj = (float)r_refdef.vrect.x - 0.5;
- r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x<<20) + (1<<19) - 1;
+ r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x << 20) + (1 << 19) - 1;
r_refdef.fvrecty = (float)r_refdef.vrect.y;
r_refdef.fvrecty_adj = (float)r_refdef.vrect.y - 0.5;
r_refdef.vrectright = r_refdef.vrect.x + r_refdef.vrect.width;
- r_refdef.vrectright_adj_shift20 = (r_refdef.vrectright<<20) + (1<<19) - 1;
+ r_refdef.vrectright_adj_shift20 = (r_refdef.vrectright << 20) + (1 << 19) - 1;
r_refdef.fvrectright = (float)r_refdef.vrectright;
r_refdef.fvrectright_adj = (float)r_refdef.vrectright - 0.5;
r_refdef.vrectrightedge = (float)r_refdef.vrectright - 0.99;
@@ -298,13 +289,13 @@ void R_ViewChanged (vrectSoft_t *vr)
r_refdef.aliasvrect.width = (int)(r_refdef.vrect.width * r_aliasuvscale);
r_refdef.aliasvrect.height = (int)(r_refdef.vrect.height * r_aliasuvscale);
r_refdef.aliasvrectright = r_refdef.aliasvrect.x +
- r_refdef.aliasvrect.width;
+ r_refdef.aliasvrect.width;
r_refdef.aliasvrectbottom = r_refdef.aliasvrect.y +
- r_refdef.aliasvrect.height;
+ r_refdef.aliasvrect.height;
xOrigin = r_refdef.xOrigin;
yOrigin = r_refdef.yOrigin;
-
+
// values for perspective projection
// if math were exact, the values would range from 0.5 to to range+0.5
// hopefully they wll be in the 0.000001 to range+.999999 and truncate
@@ -312,10 +303,10 @@ void R_ViewChanged (vrectSoft_t *vr)
// but will definately render in the [range] row and column, so adjust the
// buffer origin to get an exact edge to edge fill
xcenter = ((float)r_refdef.vrect.width * XCENTERING) +
- r_refdef.vrect.x - 0.5;
+ r_refdef.vrect.x - 0.5;
aliasxcenter = xcenter * r_aliasuvscale;
ycenter = ((float)r_refdef.vrect.height * YCENTERING) +
- r_refdef.vrect.y - 0.5;
+ r_refdef.vrect.y - 0.5;
aliasycenter = ycenter * r_aliasuvscale;
xscale = r_refdef.vrect.width / r_refdef.horizontalFieldOfView;
@@ -325,38 +316,38 @@ void R_ViewChanged (vrectSoft_t *vr)
yscale = xscale;
aliasyscale = yscale * r_aliasuvscale;
yscaleinv = 1.0 / yscale;
- xscaleshrink = (r_refdef.vrect.width-6)/r_refdef.horizontalFieldOfView;
+ xscaleshrink = (r_refdef.vrect.width - 6) / r_refdef.horizontalFieldOfView;
yscaleshrink = xscaleshrink;
// left side clip
- screenedge[0].normal[0] = -1.0 / (xOrigin*r_refdef.horizontalFieldOfView);
+ screenedge[0].normal[0] = -1.0 / (xOrigin * r_refdef.horizontalFieldOfView);
screenedge[0].normal[1] = 0;
screenedge[0].normal[2] = 1;
screenedge[0].type = PLANE_ANYZ;
-
+
// right side clip
screenedge[1].normal[0] =
- 1.0 / ((1.0-xOrigin)*r_refdef.horizontalFieldOfView);
+ 1.0 / ((1.0 - xOrigin) * r_refdef.horizontalFieldOfView);
screenedge[1].normal[1] = 0;
screenedge[1].normal[2] = 1;
screenedge[1].type = PLANE_ANYZ;
-
+
// top side clip
screenedge[2].normal[0] = 0;
- screenedge[2].normal[1] = -1.0 / (yOrigin*verticalFieldOfView);
+ screenedge[2].normal[1] = -1.0 / (yOrigin * verticalFieldOfView);
screenedge[2].normal[2] = 1;
screenedge[2].type = PLANE_ANYZ;
-
+
// bottom side clip
screenedge[3].normal[0] = 0;
- screenedge[3].normal[1] = 1.0 / ((1.0-yOrigin)*verticalFieldOfView);
- screenedge[3].normal[2] = 1;
+ screenedge[3].normal[1] = 1.0 / ((1.0 - yOrigin) * verticalFieldOfView);
+ screenedge[3].normal[2] = 1;
screenedge[3].type = PLANE_ANYZ;
-
- for (i=0 ; i<4 ; i++)
- VectorNormalize (screenedge[i].normal);
- D_ViewChanged ();
+ for (i = 0; i < 4; i++)
+ VectorNormalize(screenedge[i].normal);
+
+ D_ViewChanged();
}
@@ -365,40 +356,38 @@ void R_ViewChanged (vrectSoft_t *vr)
R_SetupFrame
===============
*/
-void R_SetupFrame (void)
+void R_SetupFrame(void)
{
int i;
vrectSoft_t vrect;
- if (r_fullbright->modified)
- {
+ if (r_fullbright->modified) {
r_fullbright->modified = qfalse;
- D_FlushCaches (); // so all lighting changes
+ D_FlushCaches(); // so all lighting changes
}
-
+
r_framecount++;
// build the transformation matrix for the given view angles
- VectorCopy (r_refdef.vieworg, modelorg);
- VectorCopy (r_refdef.vieworg, r_origin);
+ VectorCopy(r_refdef.vieworg, modelorg);
+ VectorCopy(r_refdef.vieworg, r_origin);
- AngleVectors (r_refdef.viewangles, vpn, vright, vup);
+ AngleVectors(r_refdef.viewangles, vpn, vright, vup);
// current viewleaf
- if ( !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- {
- r_viewleaf = BSP_PointLeaf (r_worldmodel->nodes, r_origin);
+ if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) {
+ r_viewleaf = BSP_PointLeaf(r_worldmodel->nodes, r_origin);
r_viewcluster = r_viewleaf->cluster;
}
- if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER) )
+ if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER))
r_dowarp = qtrue;
else
r_dowarp = qfalse;
- if (r_dowarp)
- { // warp into off screen buffer
+ if (r_dowarp) {
+ // warp into off screen buffer
vrect.x = 0;
vrect.y = 0;
vrect.width = r_newrefdef.width < WARP_WIDTH ? r_newrefdef.width : WARP_WIDTH;
@@ -406,9 +395,7 @@ void R_SetupFrame (void)
d_viewbuffer = r_warpbuffer;
r_screenwidth = WARP_WIDTH;
- }
- else
- {
+ } else {
vrect.x = r_newrefdef.x;
vrect.y = r_newrefdef.y;
vrect.width = r_newrefdef.width;
@@ -417,17 +404,17 @@ void R_SetupFrame (void)
d_viewbuffer = (void *)vid.buffer;
r_screenwidth = vid.rowbytes;
}
-
- R_ViewChanged (&vrect);
+
+ R_ViewChanged(&vrect);
// start off with just the four screen edge clip planes
- R_TransformFrustum ();
- R_SetUpFrustumIndexes ();
+ R_TransformFrustum();
+ R_SetUpFrustumIndexes();
// save base values
- VectorCopy (vpn, base_vpn);
- VectorCopy (vright, base_vright);
- VectorCopy (vup, base_vup);
+ VectorCopy(vpn, base_vpn);
+ VectorCopy(vright, base_vright);
+ VectorCopy(vup, base_vup);
// clear frame counts
c_faceclip = 0;
@@ -449,26 +436,26 @@ void R_SetupFrame (void)
else if (d_minmip < 0)
d_minmip = 0;
- for (i=0 ; i<(NUM_MIPS-1) ; i++)
+ for (i = 0; i < (NUM_MIPS - 1); i++)
d_scalemip[i] = basemip[i] * sw_mipscale->value;
d_aflatcolor = 0;
}
-/*
-==============================================================================
-
+/*
+==============================================================================
+
MATH
-
-==============================================================================
-*/
+
+==============================================================================
+*/
/*
================
R_ConcatRotations
================
*/
-void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
+void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
in1[0][2] * in2[2][0];
@@ -496,7 +483,7 @@ void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
R_ConcatTransforms
================
*/
-void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
+void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
in1[0][2] * in2[2][0];
@@ -524,7 +511,7 @@ void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
in1[2][2] * in2[2][3] + in1[2][3];
}
-void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
+void R_RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
{
float m[3][3];
float im[3][3];
@@ -538,8 +525,8 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
vf[1] = dir[1];
vf[2] = dir[2];
- PerpendicularVector( vr, dir );
- CrossProduct( vr, vf, vup );
+ PerpendicularVector(vr, dir);
+ CrossProduct(vr, vf, vup);
m[0][0] = vr[0];
m[1][0] = vr[1];
@@ -553,7 +540,7 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
m[1][2] = vf[1];
m[2][2] = vf[2];
- memcpy( im, m, sizeof( im ) );
+ memcpy(im, m, sizeof(im));
im[0][1] = m[1][0];
im[0][2] = m[2][0];
@@ -562,32 +549,31 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
im[2][0] = m[0][2];
im[2][1] = m[1][2];
- memset( zrot, 0, sizeof( zrot ) );
+ memset(zrot, 0, sizeof(zrot));
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
- zrot[0][0] = cos( DEG2RAD( degrees ) );
- zrot[0][1] = sin( DEG2RAD( degrees ) );
- zrot[1][0] = -sin( DEG2RAD( degrees ) );
- zrot[1][1] = cos( DEG2RAD( degrees ) );
+ zrot[0][0] = cos(DEG2RAD(degrees));
+ zrot[0][1] = sin(DEG2RAD(degrees));
+ zrot[1][0] = -sin(DEG2RAD(degrees));
+ zrot[1][1] = cos(DEG2RAD(degrees));
- R_ConcatRotations( m, zrot, tmpmat );
- R_ConcatRotations( tmpmat, im, rot );
+ R_ConcatRotations(m, zrot, tmpmat);
+ R_ConcatRotations(tmpmat, im, rot);
- for ( i = 0; i < 3; i++ )
- {
+ for (i = 0; i < 3; i++) {
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}
-void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
+void ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal)
{
float d;
vec3_t n;
float inv_denom;
- inv_denom = 1.0F / DotProduct( normal, normal );
+ inv_denom = 1.0F / DotProduct(normal, normal);
- d = DotProduct( normal, p ) * inv_denom;
+ d = DotProduct(normal, p) * inv_denom;
n[0] = normal[0] * inv_denom;
n[1] = normal[1] * inv_denom;
@@ -601,7 +587,7 @@ void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
/*
** assumes "src" is normalized
*/
-void PerpendicularVector( vec3_t dst, const vec3_t src )
+void PerpendicularVector(vec3_t dst, const vec3_t src)
{
int pos;
int i;
@@ -611,12 +597,10 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
/*
** find the smallest magnitude axially aligned vector
*/
- for ( pos = 0, i = 0; i < 3; i++ )
- {
- if ( fabs( src[i] ) < minelem )
- {
+ for (pos = 0, i = 0; i < 3; i++) {
+ if (fabs(src[i]) < minelem) {
pos = i;
- minelem = fabs( src[i] );
+ minelem = fabs(src[i]);
}
}
tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
@@ -625,11 +609,11 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
/*
** project the point onto the plane defined by src
*/
- ProjectPointOnPlane( dst, tempvec, src );
+ ProjectPointOnPlane(dst, tempvec, src);
/*
** normalize the result
*/
- VectorNormalize( dst );
+ VectorNormalize(dst);
}
diff --git a/src/sw_model.c b/src/sw_model.c
index b792204..60a0ebe 100644
--- a/src/sw_model.c
+++ b/src/sw_model.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -31,29 +31,30 @@ int registration_sequence;
ProcessTexinfo
=================
*/
-static void ProcessTexinfo( bsp_t *bsp ) {
+static void ProcessTexinfo(bsp_t *bsp)
+{
mtexinfo_t *tex;
int i;
vec_t len1, len2;
char name[MAX_QPATH];
tex = bsp->texinfo;
- for( i = 0; i < bsp->numtexinfo; i++, tex++ ) {
- len1 = VectorLength( tex->axis[0] );
- len2 = VectorLength( tex->axis[1] );
- len1 = ( len1 + len2 ) / 2;
- if( len1 < 0.32 )
+ for (i = 0; i < bsp->numtexinfo; i++, tex++) {
+ len1 = VectorLength(tex->axis[0]);
+ len2 = VectorLength(tex->axis[1]);
+ len1 = (len1 + len2) / 2;
+ if (len1 < 0.32)
tex->mipadjust = 4;
- else if( len1 < 0.49 )
+ else if (len1 < 0.49)
tex->mipadjust = 3;
- else if( len1 < 0.99 )
+ else if (len1 < 0.99)
tex->mipadjust = 2;
else
tex->mipadjust = 1;
- Q_concat( name, sizeof( name ), "textures/", tex->name, ".wal", NULL );
- FS_NormalizePath( name, name );
- tex->image = IMG_Find( name, it_wall );
+ Q_concat(name, sizeof(name), "textures/", tex->name, ".wal", NULL);
+ FS_NormalizePath(name, name);
+ tex->image = IMG_Find(name, it_wall);
}
}
@@ -64,7 +65,8 @@ CalcSurfaceExtents
Fills in s->texturemins[] and s->extents[]
================
*/
-static void CalcSurfaceExtents( mface_t *s ) {
+static void CalcSurfaceExtents(mface_t *s)
+{
vec_t mins[2], maxs[2], val;
int i, j;
msurfedge_t *e;
@@ -77,27 +79,27 @@ static void CalcSurfaceExtents( mface_t *s ) {
tex = s->texinfo;
e = s->firstsurfedge;
- for( i = 0; i < s->numsurfedges; i++, e++ ) {
- v = e->edge->v[e->vert];
- for( j = 0; j < 2; j++ ) {
- val = DotProduct( v->point, tex->axis[j] ) + tex->offset[j];
- if( val < mins[j] )
+ for (i = 0; i < s->numsurfedges; i++, e++) {
+ v = e->edge->v[e->vert];
+ for (j = 0; j < 2; j++) {
+ val = DotProduct(v->point, tex->axis[j]) + tex->offset[j];
+ if (val < mins[j])
mins[j] = val;
- if( val > maxs[j] )
+ if (val > maxs[j])
maxs[j] = val;
}
}
- for( i = 0; i < 2; i++ ) {
- bmins[i] = floor( mins[i] / 16 );
- bmaxs[i] = ceil( maxs[i] / 16 );
+ for (i = 0; i < 2; i++) {
+ bmins[i] = floor(mins[i] / 16);
+ bmaxs[i] = ceil(maxs[i] / 16);
s->texturemins[i] = bmins[i] << 4;
- s->extents[i] = ( bmaxs[i] - bmins[i] ) << 4;
- if( s->extents[i] < 16 ) {
+ s->extents[i] = (bmaxs[i] - bmins[i]) << 4;
+ if (s->extents[i] < 16) {
s->extents[i] = 16; // take at least one cache block
- } else if( s->extents[i] > 256 ) {
- Com_Error( ERR_DROP, "Bad surface extents" );
+ } else if (s->extents[i] > 256) {
+ Com_Error(ERR_DROP, "Bad surface extents");
}
}
}
@@ -108,25 +110,26 @@ static void CalcSurfaceExtents( mface_t *s ) {
ProcessFaces
=================
*/
-static void ProcessFaces( bsp_t *bsp ) {
+static void ProcessFaces(bsp_t *bsp)
+{
mface_t *s;
int i, j;
s = bsp->faces;
- for( i = 0; i < bsp->numfaces; i++, s++ ) {
- // set the drawing flags
- if( s->texinfo->c.flags & SURF_SKY ) {
+ for (i = 0; i < bsp->numfaces; i++, s++) {
+ // set the drawing flags
+ if (s->texinfo->c.flags & SURF_SKY) {
continue;
}
- if( s->texinfo->c.flags & (SURF_WARP|SURF_FLOWING) ) {
+ if (s->texinfo->c.flags & (SURF_WARP | SURF_FLOWING)) {
s->drawflags |= DSURF_TURB;
- for( j = 0; j < 2; j++ ) {
+ for (j = 0; j < 2; j++) {
s->extents[j] = 16384;
s->texturemins[j] = -8192;
}
continue;
}
- CalcSurfaceExtents( s );
+ CalcSurfaceExtents(s);
}
}
@@ -146,7 +149,8 @@ ALIAS MODELS
Mod_LoadAliasModel
=================
*/
-qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
+qerror_t MOD_LoadMD2(model_t *model, const void *rawdata, size_t length)
+{
dmd2header_t header;
dmd2frame_t *src_frame;
//dmd2trivertx_t *src_vert;
@@ -161,20 +165,20 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
int i, j;
qerror_t ret;
- if( length < sizeof( header ) ) {
+ if (length < sizeof(header)) {
return Q_ERR_FILE_TOO_SMALL;
}
// byte swap the header
- header = *( dmd2header_t * )rawdata;
- for( i = 0; i < sizeof( header )/4; i++ ) {
- (( uint32_t * )&header)[i] = LittleLong( (( uint32_t * )&header)[i] );
+ header = *(dmd2header_t *)rawdata;
+ for (i = 0; i < sizeof(header) / 4; i++) {
+ ((uint32_t *)&header)[i] = LittleLong(((uint32_t *)&header)[i]);
}
// validate the header
- ret = MOD_ValidateMD2( &header, length );
- if( ret ) {
- if( ret == Q_ERR_TOO_FEW ) {
+ ret = MOD_ValidateMD2(&header, length);
+ if (ret) {
+ if (ret == Q_ERR_TOO_FEW) {
// empty models draw nothing
model->type = MOD_EMPTY;
return Q_ERR_SUCCESS;
@@ -182,102 +186,103 @@ qerror_t MOD_LoadMD2( model_t *model, const void *rawdata, size_t length ) {
return ret;
}
- Hunk_Begin( &model->pool, 0x400000 );
+ Hunk_Begin(&model->pool, 0x400000);
model->type = MOD_ALIAS;
// load triangle indices
- model->tris = MOD_Malloc( header.num_tris * sizeof( maliastri_t ) );
- model->numtris = header.num_tris;
+ model->tris = MOD_Malloc(header.num_tris * sizeof(maliastri_t));
+ model->numtris = header.num_tris;
- src_tri = ( dmd2triangle_t * )( ( byte * )rawdata + header.ofs_tris );
+ src_tri = (dmd2triangle_t *)((byte *)rawdata + header.ofs_tris);
dst_tri = model->tris;
- for( i = 0; i < header.num_tris; i++, src_tri++, dst_tri++ ) {
- for( j = 0; j < 3; j++ ) {
- unsigned idx_xyz = LittleShort( src_tri->index_xyz[j] );
- unsigned idx_st = LittleShort( src_tri->index_st[j] );
+ for (i = 0; i < header.num_tris; i++, src_tri++, dst_tri++) {
+ for (j = 0; j < 3; j++) {
+ unsigned idx_xyz = LittleShort(src_tri->index_xyz[j]);
+ unsigned idx_st = LittleShort(src_tri->index_st[j]);
- if( idx_xyz >= header.num_xyz || idx_st >= header.num_st ) {
+ if (idx_xyz >= header.num_xyz || idx_st >= header.num_st) {
ret = Q_ERR_BAD_INDEX;
goto fail;
}
- dst_tri->index_xyz[j] = idx_xyz;
+ dst_tri->index_xyz[j] = idx_xyz;
dst_tri->index_st[j] = idx_st;
}
}
// load base s and t vertices
- model->sts = MOD_Malloc( header.num_st * sizeof( maliasst_t ) );
+ model->sts = MOD_Malloc(header.num_st * sizeof(maliasst_t));
model->numsts = header.num_st;
- src_st = ( dmd2stvert_t * )( ( byte * )rawdata + header.ofs_st );
+ src_st = (dmd2stvert_t *)((byte *)rawdata + header.ofs_st);
dst_st = model->sts;
- for( i = 0; i < header.num_st; i++, src_st++, dst_st++ ) {
- dst_st->s = ( int16_t )LittleShort( src_st->s );
- dst_st->t = ( int16_t )LittleShort( src_st->t );
+ for (i = 0; i < header.num_st; i++, src_st++, dst_st++) {
+ dst_st->s = (int16_t)LittleShort(src_st->s);
+ dst_st->t = (int16_t)LittleShort(src_st->t);
}
// load the frames
- model->frames = MOD_Malloc( header.num_frames * sizeof( maliasframe_t ) );
+ model->frames = MOD_Malloc(header.num_frames * sizeof(maliasframe_t));
model->numframes = header.num_frames;
model->numverts = header.num_xyz;
- src_frame = ( dmd2frame_t * )( ( byte * )rawdata + header.ofs_frames );
+ src_frame = (dmd2frame_t *)((byte *)rawdata + header.ofs_frames);
dst_frame = model->frames;
- for( i = 0; i < header.num_frames; i++, dst_frame++ ) {
- for( j = 0; j < 3; j++ ) {
- dst_frame->scale[j] = LittleFloat( src_frame->scale[j] );
- dst_frame->translate[j] = LittleFloat( src_frame->translate[j] );
+ for (i = 0; i < header.num_frames; i++, dst_frame++) {
+ for (j = 0; j < 3; j++) {
+ dst_frame->scale[j] = LittleFloat(src_frame->scale[j]);
+ dst_frame->translate[j] = LittleFloat(src_frame->translate[j]);
}
// verts are all 8 bit, so no swapping needed
- dst_frame->verts = MOD_Malloc( header.num_xyz * sizeof( maliasvert_t ) );
-
+ dst_frame->verts = MOD_Malloc(header.num_xyz * sizeof(maliasvert_t));
+
// TODO: check normal indices
- memcpy( dst_frame->verts, src_frame->verts, header.num_xyz * sizeof( maliasvert_t ) );
+ memcpy(dst_frame->verts, src_frame->verts, header.num_xyz * sizeof(maliasvert_t));
- src_frame = ( dmd2frame_t * )( ( byte * )src_frame + header.framesize );
+ src_frame = (dmd2frame_t *)((byte *)src_frame + header.framesize);
}
// register all skins
- src_skin = ( char * )rawdata + header.ofs_skins;
- for( i = 0; i < header.num_skins; i++ ) {
- if( !Q_memccpy( skinname, src_skin, 0, sizeof( skinname ) ) ) {
+ src_skin = (char *)rawdata + header.ofs_skins;
+ for (i = 0; i < header.num_skins; i++) {
+ if (!Q_memccpy(skinname, src_skin, 0, sizeof(skinname))) {
ret = Q_ERR_STRING_TRUNCATED;
goto fail;
}
- FS_NormalizePath( skinname, skinname );
- model->skins[i] = IMG_Find( skinname, it_skin );
+ FS_NormalizePath(skinname, skinname);
+ model->skins[i] = IMG_Find(skinname, it_skin);
src_skin += MD2_MAX_SKINNAME;
}
model->numskins = header.num_skins;
- Hunk_End( &model->pool );
+ Hunk_End(&model->pool);
return Q_ERR_SUCCESS;
fail:
- Hunk_Free( &model->pool );
+ Hunk_Free(&model->pool);
return ret;
}
-void MOD_Reference( model_t *model ) {
+void MOD_Reference(model_t *model)
+{
int i;
// register any images used by the models
- switch( model->type ) {
+ switch (model->type) {
case MOD_ALIAS:
- for( i = 0; i < model->numskins; i++ ) {
+ for (i = 0; i < model->numskins; i++) {
model->skins[i]->registration_sequence = registration_sequence;
}
break;
case MOD_SPRITE:
- for( i = 0; i < model->numframes; i++ ) {
+ for (i = 0; i < model->numframes; i++) {
model->spriteframes[i].image->registration_sequence = registration_sequence;
}
break;
case MOD_EMPTY:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad model type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad model type", __func__);
}
model->registration_sequence = registration_sequence;
@@ -290,34 +295,35 @@ R_BeginRegistration
Specifies the model that will be used as the world
@@@@@@@@@@@@@@@@@@@@@
*/
-void R_BeginRegistration( const char *model ) {
+void R_BeginRegistration(const char *model)
+{
char fullname[MAX_QPATH];
bsp_t *bsp;
registration_sequence++;
r_oldviewcluster = -1; // force markleafs
- Q_concat( fullname, sizeof( fullname ), "maps/", model, ".bsp", NULL );
+ Q_concat(fullname, sizeof(fullname), "maps/", model, ".bsp", NULL);
- D_FlushCaches ();
- BSP_Load( fullname, &bsp );
- if( bsp == r_worldmodel ) {
+ D_FlushCaches();
+ BSP_Load(fullname, &bsp);
+ if (bsp == r_worldmodel) {
mtexinfo_t *tex = bsp->texinfo;
int i;
- for( i = 0; i < bsp->numtexinfo; i++, tex++ ) {
+ for (i = 0; i < bsp->numtexinfo; i++, tex++) {
tex->image->registration_sequence = registration_sequence;
}
bsp->refcount--;
return;
}
- BSP_Free( r_worldmodel );
+ BSP_Free(r_worldmodel);
r_worldmodel = bsp;
- ProcessTexinfo( bsp );
- ProcessFaces( bsp );
+ ProcessTexinfo(bsp);
+ ProcessFaces(bsp);
// TODO
- R_NewMap ();
+ R_NewMap();
}
/*
@@ -326,7 +332,8 @@ R_EndRegistration
@@@@@@@@@@@@@@@@@@@@@
*/
-void R_EndRegistration (void) {
+void R_EndRegistration(void)
+{
MOD_FreeUnused();
IMG_FreeUnused();
}
diff --git a/src/sw_part.c b/src/sw_part.c
index 0fe15f6..8095ec0 100644
--- a/src/sw_part.c
+++ b/src/sw_part.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,8 +25,7 @@ vec3_t r_pright, r_pup, r_ppn;
#define PARTICLE_66 1
#define PARTICLE_OPAQUE 2
-typedef struct
-{
+typedef struct {
particle_t *particle;
int level;
int color;
@@ -43,11 +42,11 @@ static partparms_t partparms;
** executed is if we're debugging on x86 or if we're
** recompiling and deploying on a non-x86 platform.
**
-** To minimize error and improve readability I went the
+** To minimize error and improve readability I went the
** function pointer route. This exacts some overhead, but
** it pays off in clean and easy to understand code.
*/
-static void R_DrawParticle( void )
+static void R_DrawParticle(void)
{
particle_t *pparticle = partparms.particle;
int level = partparms.level;
@@ -61,11 +60,11 @@ static void R_DrawParticle( void )
/*
** transform the particle
*/
- VectorSubtract (pparticle->origin, r_origin, local);
+ VectorSubtract(pparticle->origin, r_origin, local);
transformed[0] = DotProduct(local, r_pright);
transformed[1] = DotProduct(local, r_pup);
- transformed[2] = DotProduct(local, r_ppn);
+ transformed[2] = DotProduct(local, r_ppn);
if (transformed[2] < PARTICLE_Z_CLIP)
return;
@@ -78,16 +77,15 @@ static void R_DrawParticle( void )
u = (int)(xcenter + zi * transformed[0] + 0.5);
v = (int)(ycenter - zi * transformed[1] + 0.5);
- if ((v > d_vrectbottom_particle) ||
+ if ((v > d_vrectbottom_particle) ||
(u > d_vrectright_particle) ||
(v < d_vrecty) ||
- (u < d_vrectx))
- {
+ (u < d_vrectx)) {
return;
}
/*
- ** compute addresses of zbuffer, framebuffer, and
+ ** compute addresses of zbuffer, framebuffer, and
** compute the Z-buffer reference value.
*/
pz = d_pzbuffer + (d_zwidth * v) + u;
@@ -111,41 +109,32 @@ static void R_DrawParticle( void )
switch (level) {
case PARTICLE_33 :
- for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
- {
+ for (; count; count--, pz += d_zwidth, pdest += r_screenwidth) {
//FIXME--do it in blocks of 8?
- for (i=0 ; i<pix ; i++)
- {
- if (pz[i] <= izi)
- {
+ for (i = 0; i < pix; i++) {
+ if (pz[i] <= izi) {
pz[i] = izi;
- pdest[i] = vid.alphamap[color + ((int)pdest[i]<<8)];
+ pdest[i] = vid.alphamap[color + ((int)pdest[i] << 8)];
}
}
}
break;
case PARTICLE_66 :
- for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
- {
- for (i=0 ; i<pix ; i++)
- {
- if (pz[i] <= izi)
- {
+ for (; count; count--, pz += d_zwidth, pdest += r_screenwidth) {
+ for (i = 0; i < pix; i++) {
+ if (pz[i] <= izi) {
pz[i] = izi;
- pdest[i] = vid.alphamap[(color<<8) + (int)pdest[i]];
+ pdest[i] = vid.alphamap[(color << 8) + (int)pdest[i]];
}
}
}
break;
default: //100
- for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
- {
- for (i=0 ; i<pix ; i++)
- {
- if (pz[i] <= izi)
- {
+ for (; count; count--, pz += d_zwidth, pdest += r_screenwidth) {
+ for (i = 0; i < pix; i++) {
+ if (pz[i] <= izi) {
pz[i] = izi;
pdest[i] = color;
}
@@ -163,21 +152,20 @@ static void R_DrawParticle( void )
** if we're using the asm path, it simply assigns a function pointer
** and goes.
*/
-void R_DrawParticles (void)
+void R_DrawParticles(void)
{
particle_t *p;
int i;
- VectorScale( vright, xscaleshrink, r_pright );
- VectorScale( vup, yscaleshrink, r_pup );
- VectorCopy( vpn, r_ppn );
+ VectorScale(vright, xscaleshrink, r_pright);
+ VectorScale(vup, yscaleshrink, r_pup);
+ VectorCopy(vpn, r_ppn);
- for (p=r_newrefdef.particles, i=0 ; i<r_newrefdef.num_particles ; i++,p++)
- {
+ for (p = r_newrefdef.particles, i = 0; i < r_newrefdef.num_particles; i++, p++) {
- if ( p->alpha > 0.66 )
+ if (p->alpha > 0.66)
partparms.level = PARTICLE_OPAQUE;
- else if ( p->alpha > 0.33 )
+ else if (p->alpha > 0.33)
partparms.level = PARTICLE_66;
else
partparms.level = PARTICLE_33;
diff --git a/src/sw_poly.c b/src/sw_poly.c
index 16d1ee2..b26de62 100644
--- a/src/sw_poly.c
+++ b/src/sw_poly.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,8 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define AFFINE_SPANLET_SIZE 16
#define AFFINE_SPANLET_SIZE_BITS 4
-typedef struct
-{
+typedef struct {
byte *pbase, *pdest;
short *pz;
fixed16_t s, t;
@@ -46,31 +45,28 @@ mface_t *r_alpha_surfaces;
extern int *r_turb_turb;
static int clip_current;
-static vec5_t r_clip_verts[2][MAXWORKINGVERTS+2];
+static vec5_t r_clip_verts[2][MAXWORKINGVERTS + 2];
static int s_minindex, s_maxindex;
-static void R_DrawPoly( int iswater );
+static void R_DrawPoly(int iswater);
/*
** R_DrawSpanletOpaque
*/
-static void R_DrawSpanletOpaque( void )
+static void R_DrawSpanletOpaque(void)
{
unsigned btemp;
- do
- {
+ do {
unsigned ts, tt;
ts = s_spanletvars.s >> 16;
tt = s_spanletvars.t >> 16;
btemp = *(s_spanletvars.pbase + (ts) + (tt) * cachewidth);
- if (btemp != 255)
- {
- if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
- {
+ if (btemp != 255) {
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16)) {
*s_spanletvars.pz = s_spanletvars.izi >> 16;
*s_spanletvars.pdest = btemp;
}
@@ -87,26 +83,24 @@ static void R_DrawSpanletOpaque( void )
/*
** R_DrawSpanletTurbulentStipple33
*/
-static void R_DrawSpanletTurbulentStipple33( void )
+static void R_DrawSpanletTurbulentStipple33(void)
{
unsigned btemp;
int sturb, tturb;
byte *pdest = s_spanletvars.pdest;
short *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
-
- if ( s_spanletvars.v & 1 )
- {
+
+ if (s_spanletvars.v & 1) {
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
- if ( s_spanletvars.spancount == AFFINE_SPANLET_SIZE )
+ if (s_spanletvars.spancount == AFFINE_SPANLET_SIZE)
s_spanletvars.izi += s_spanletvars.izistep << AFFINE_SPANLET_SIZE_BITS;
else
s_spanletvars.izi += s_spanletvars.izistep * s_spanletvars.izistep;
-
- if ( s_spanletvars.u & 1 )
- {
+
+ if (s_spanletvars.u & 1) {
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
@@ -119,23 +113,22 @@ static void R_DrawSpanletTurbulentStipple33( void )
s_spanletvars.sstep *= 2;
s_spanletvars.tstep *= 2;
- while ( s_spanletvars.spancount > 0 )
- {
- sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s>>16)&(CYCLE-1)])>>16)&63;
-
- btemp = *( s_spanletvars.pbase + ( sturb ) + ( tturb << 6 ) );
-
- if ( *pz <= ( izi >> 16 ) )
+ while (s_spanletvars.spancount > 0) {
+ sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s >> 16) & (CYCLE - 1)]) >> 16) & 63;
+
+ btemp = *(s_spanletvars.pbase + (sturb) + (tturb << 6));
+
+ if (*pz <= (izi >> 16))
*pdest = btemp;
-
+
izi += s_spanletvars.izistep_times_2;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest += 2;
pz += 2;
-
+
s_spanletvars.spancount -= 2;
}
}
@@ -144,26 +137,24 @@ static void R_DrawSpanletTurbulentStipple33( void )
/*
** R_DrawSpanletTurbulentStipple66
*/
-static void R_DrawSpanletTurbulentStipple66( void )
+static void R_DrawSpanletTurbulentStipple66(void)
{
unsigned btemp;
int sturb, tturb;
byte *pdest = s_spanletvars.pdest;
short *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
-
- if ( !( s_spanletvars.v & 1 ) )
- {
+
+ if (!(s_spanletvars.v & 1)) {
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
- if ( s_spanletvars.spancount == AFFINE_SPANLET_SIZE )
+ if (s_spanletvars.spancount == AFFINE_SPANLET_SIZE)
s_spanletvars.izi += s_spanletvars.izistep << AFFINE_SPANLET_SIZE_BITS;
else
s_spanletvars.izi += s_spanletvars.izistep * s_spanletvars.izistep;
-
- if ( s_spanletvars.u & 1 )
- {
+
+ if (s_spanletvars.u & 1) {
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
@@ -176,53 +167,49 @@ static void R_DrawSpanletTurbulentStipple66( void )
s_spanletvars.sstep *= 2;
s_spanletvars.tstep *= 2;
- while ( s_spanletvars.spancount > 0 )
- {
- sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s>>16)&(CYCLE-1)])>>16)&63;
-
- btemp = *( s_spanletvars.pbase + ( sturb ) + ( tturb << 6 ) );
-
- if ( *pz <= ( izi >> 16 ) )
+ while (s_spanletvars.spancount > 0) {
+ sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s >> 16) & (CYCLE - 1)]) >> 16) & 63;
+
+ btemp = *(s_spanletvars.pbase + (sturb) + (tturb << 6));
+
+ if (*pz <= (izi >> 16))
*pdest = btemp;
-
+
izi += s_spanletvars.izistep_times_2;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest += 2;
pz += 2;
-
+
s_spanletvars.spancount -= 2;
}
- }
- else
- {
+ } else {
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
- if ( s_spanletvars.spancount == AFFINE_SPANLET_SIZE )
+ if (s_spanletvars.spancount == AFFINE_SPANLET_SIZE)
s_spanletvars.izi += s_spanletvars.izistep << AFFINE_SPANLET_SIZE_BITS;
else
s_spanletvars.izi += s_spanletvars.izistep * s_spanletvars.izistep;
-
- while ( s_spanletvars.spancount > 0 )
- {
- sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s>>16)&(CYCLE-1)])>>16)&63;
-
- btemp = *( s_spanletvars.pbase + ( sturb ) + ( tturb << 6 ) );
-
- if ( *pz <= ( izi >> 16 ) )
+
+ while (s_spanletvars.spancount > 0) {
+ sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s >> 16) & (CYCLE - 1)]) >> 16) & 63;
+
+ btemp = *(s_spanletvars.pbase + (sturb) + (tturb << 6));
+
+ if (*pz <= (izi >> 16))
*pdest = btemp;
-
+
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest++;
pz++;
-
+
s_spanletvars.spancount--;
}
}
@@ -231,20 +218,19 @@ static void R_DrawSpanletTurbulentStipple66( void )
/*
** R_DrawSpanletTurbulentBlended
*/
-static void R_DrawSpanletTurbulentBlended66( void )
+static void R_DrawSpanletTurbulentBlended66(void)
{
unsigned btemp;
int sturb, tturb;
- do
- {
- sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s>>16)&(CYCLE-1)])>>16)&63;
+ do {
+ sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s >> 16) & (CYCLE - 1)]) >> 16) & 63;
- btemp = *( s_spanletvars.pbase + ( sturb ) + ( tturb << 6 ) );
+ btemp = *(s_spanletvars.pbase + (sturb) + (tturb << 6));
- if ( *s_spanletvars.pz <= ( s_spanletvars.izi >> 16 ) )
- *s_spanletvars.pdest = vid.alphamap[btemp*256+*s_spanletvars.pdest];
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
+ *s_spanletvars.pdest = vid.alphamap[btemp * 256 + *s_spanletvars.pdest];
s_spanletvars.izi += s_spanletvars.izistep;
s_spanletvars.pdest++;
@@ -252,23 +238,22 @@ static void R_DrawSpanletTurbulentBlended66( void )
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
- } while ( --s_spanletvars.spancount > 0 );
+ } while (--s_spanletvars.spancount > 0);
}
-static void R_DrawSpanletTurbulentBlended33( void )
+static void R_DrawSpanletTurbulentBlended33(void)
{
unsigned btemp;
int sturb, tturb;
- do
- {
- sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s>>16)&(CYCLE-1)])>>16)&63;
+ do {
+ sturb = ((s_spanletvars.s + r_turb_turb[(s_spanletvars.t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((s_spanletvars.t + r_turb_turb[(s_spanletvars.s >> 16) & (CYCLE - 1)]) >> 16) & 63;
- btemp = *( s_spanletvars.pbase + ( sturb ) + ( tturb << 6 ) );
+ btemp = *(s_spanletvars.pbase + (sturb) + (tturb << 6));
- if ( *s_spanletvars.pz <= ( s_spanletvars.izi >> 16 ) )
- *s_spanletvars.pdest = vid.alphamap[btemp+*s_spanletvars.pdest*256];
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
+ *s_spanletvars.pdest = vid.alphamap[btemp + *s_spanletvars.pdest * 256];
s_spanletvars.izi += s_spanletvars.izistep;
s_spanletvars.pdest++;
@@ -276,18 +261,17 @@ static void R_DrawSpanletTurbulentBlended33( void )
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
- } while ( --s_spanletvars.spancount > 0 );
+ } while (--s_spanletvars.spancount > 0);
}
/*
** R_DrawSpanlet33
*/
-static void R_DrawSpanlet33( void )
+static void R_DrawSpanlet33(void)
{
unsigned btemp;
- do
- {
+ do {
unsigned ts, tt;
ts = s_spanletvars.s >> 16;
@@ -295,11 +279,9 @@ static void R_DrawSpanlet33( void )
btemp = *(s_spanletvars.pbase + (ts) + (tt) * cachewidth);
- if ( btemp != 255 )
- {
- if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
- {
- *s_spanletvars.pdest = vid.alphamap[btemp+*s_spanletvars.pdest*256];
+ if (btemp != 255) {
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16)) {
+ *s_spanletvars.pdest = vid.alphamap[btemp + *s_spanletvars.pdest * 256];
}
}
@@ -311,13 +293,11 @@ static void R_DrawSpanlet33( void )
} while (--s_spanletvars.spancount > 0);
}
-static void R_DrawSpanletConstant33( void )
+static void R_DrawSpanletConstant33(void)
{
- do
- {
- if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
- {
- *s_spanletvars.pdest = vid.alphamap[r_polyblendcolor+*s_spanletvars.pdest*256];
+ do {
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16)) {
+ *s_spanletvars.pdest = vid.alphamap[r_polyblendcolor + *s_spanletvars.pdest * 256];
}
s_spanletvars.izi += s_spanletvars.izistep;
@@ -329,12 +309,11 @@ static void R_DrawSpanletConstant33( void )
/*
** R_DrawSpanlet66
*/
-static void R_DrawSpanlet66( void )
+static void R_DrawSpanlet66(void)
{
unsigned btemp;
- do
- {
+ do {
unsigned ts, tt;
ts = s_spanletvars.s >> 16;
@@ -342,11 +321,9 @@ static void R_DrawSpanlet66( void )
btemp = *(s_spanletvars.pbase + (ts) + (tt) * cachewidth);
- if ( btemp != 255 )
- {
- if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16))
- {
- *s_spanletvars.pdest = vid.alphamap[btemp*256+*s_spanletvars.pdest];
+ if (btemp != 255) {
+ if (*s_spanletvars.pz <= (s_spanletvars.izi >> 16)) {
+ *s_spanletvars.pdest = vid.alphamap[btemp * 256 + *s_spanletvars.pdest];
}
}
@@ -361,25 +338,23 @@ static void R_DrawSpanlet66( void )
/*
** R_DrawSpanlet33Stipple
*/
-static void R_DrawSpanlet33Stipple( void )
+static void R_DrawSpanlet33Stipple(void)
{
unsigned btemp;
byte *pdest = s_spanletvars.pdest;
short *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
-
- if ( r_polydesc.stipple_parity ^ ( s_spanletvars.v & 1 ) )
- {
+
+ if (r_polydesc.stipple_parity ^(s_spanletvars.v & 1)) {
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
- if ( s_spanletvars.spancount == AFFINE_SPANLET_SIZE )
+ if (s_spanletvars.spancount == AFFINE_SPANLET_SIZE)
s_spanletvars.izi += s_spanletvars.izistep << AFFINE_SPANLET_SIZE_BITS;
else
s_spanletvars.izi += s_spanletvars.izistep * s_spanletvars.izistep;
-
- if ( r_polydesc.stipple_parity ^ ( s_spanletvars.u & 1 ) )
- {
+
+ if (r_polydesc.stipple_parity ^(s_spanletvars.u & 1)) {
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
@@ -392,26 +367,24 @@ static void R_DrawSpanlet33Stipple( void )
s_spanletvars.sstep *= 2;
s_spanletvars.tstep *= 2;
- while ( s_spanletvars.spancount > 0 )
- {
+ while (s_spanletvars.spancount > 0) {
unsigned s = s_spanletvars.s >> 16;
unsigned t = s_spanletvars.t >> 16;
- btemp = *( s_spanletvars.pbase + ( s ) + ( t * cachewidth ) );
-
- if ( btemp != 255 )
- {
- if ( *pz <= ( izi >> 16 ) )
+ btemp = *(s_spanletvars.pbase + (s) + (t * cachewidth));
+
+ if (btemp != 255) {
+ if (*pz <= (izi >> 16))
*pdest = btemp;
}
-
+
izi += s_spanletvars.izistep_times_2;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest += 2;
pz += 2;
-
+
s_spanletvars.spancount -= 2;
}
}
@@ -420,7 +393,7 @@ static void R_DrawSpanlet33Stipple( void )
/*
** R_DrawSpanlet66Stipple
*/
-static void R_DrawSpanlet66Stipple( void )
+static void R_DrawSpanlet66Stipple(void)
{
unsigned btemp;
byte *pdest = s_spanletvars.pdest;
@@ -430,15 +403,13 @@ static void R_DrawSpanlet66Stipple( void )
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
- if ( s_spanletvars.spancount == AFFINE_SPANLET_SIZE )
+ if (s_spanletvars.spancount == AFFINE_SPANLET_SIZE)
s_spanletvars.izi += s_spanletvars.izistep << AFFINE_SPANLET_SIZE_BITS;
else
s_spanletvars.izi += s_spanletvars.izistep * s_spanletvars.izistep;
- if ( r_polydesc.stipple_parity ^ ( s_spanletvars.v & 1 ) )
- {
- if ( r_polydesc.stipple_parity ^ ( s_spanletvars.u & 1 ) )
- {
+ if (r_polydesc.stipple_parity ^(s_spanletvars.v & 1)) {
+ if (r_polydesc.stipple_parity ^(s_spanletvars.u & 1)) {
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
@@ -451,51 +422,45 @@ static void R_DrawSpanlet66Stipple( void )
s_spanletvars.sstep *= 2;
s_spanletvars.tstep *= 2;
- while ( s_spanletvars.spancount > 0 )
- {
+ while (s_spanletvars.spancount > 0) {
unsigned s = s_spanletvars.s >> 16;
unsigned t = s_spanletvars.t >> 16;
-
- btemp = *( s_spanletvars.pbase + ( s ) + ( t * cachewidth ) );
- if ( btemp != 255 )
- {
- if ( *pz <= ( izi >> 16 ) )
+ btemp = *(s_spanletvars.pbase + (s) + (t * cachewidth));
+
+ if (btemp != 255) {
+ if (*pz <= (izi >> 16))
*pdest = btemp;
}
-
+
izi += s_spanletvars.izistep_times_2;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest += 2;
pz += 2;
-
+
s_spanletvars.spancount -= 2;
}
- }
- else
- {
- while ( s_spanletvars.spancount > 0 )
- {
+ } else {
+ while (s_spanletvars.spancount > 0) {
unsigned s = s_spanletvars.s >> 16;
unsigned t = s_spanletvars.t >> 16;
-
- btemp = *( s_spanletvars.pbase + ( s ) + ( t * cachewidth ) );
-
- if ( btemp != 255 )
- {
- if ( *pz <= ( izi >> 16 ) )
+
+ btemp = *(s_spanletvars.pbase + (s) + (t * cachewidth));
+
+ if (btemp != 255) {
+ if (*pz <= (izi >> 16))
*pdest = btemp;
}
-
+
izi += s_spanletvars.izistep;
s_spanletvars.s += s_spanletvars.sstep;
s_spanletvars.t += s_spanletvars.tstep;
-
+
pdest++;
pz++;
-
+
s_spanletvars.spancount--;
}
}
@@ -507,75 +472,69 @@ static void R_DrawSpanlet66Stipple( void )
** Clips the winding at clip_verts[clip_current] and changes clip_current
** Throws out the back side
*/
-static int R_ClipPolyFace (int nump, clipplane_t *pclipplane)
+static int R_ClipPolyFace(int nump, clipplane_t *pclipplane)
{
int i, outcount;
- float dists[MAXWORKINGVERTS+3];
+ float dists[MAXWORKINGVERTS + 3];
float frac, clipdist, *pclipnormal;
float *in, *instep, *outstep, *vert2;
clipdist = pclipplane->dist;
pclipnormal = pclipplane->normal;
-
+
// calc dists
- if (clip_current)
- {
+ if (clip_current) {
in = r_clip_verts[1][0];
outstep = r_clip_verts[0][0];
clip_current = 0;
- }
- else
- {
+ } else {
in = r_clip_verts[0][0];
outstep = r_clip_verts[1][0];
clip_current = 1;
}
-
+
instep = in;
- for (i=0 ; i<nump ; i++, instep += sizeof (vec5_t) / sizeof (float))
- {
- dists[i] = DotProduct (instep, pclipnormal) - clipdist;
+ for (i = 0; i < nump; i++, instep += sizeof(vec5_t) / sizeof(float)) {
+ dists[i] = DotProduct(instep, pclipnormal) - clipdist;
}
-
+
// handle wraparound case
dists[nump] = dists[0];
- memcpy (instep, in, sizeof (vec5_t));
+ memcpy(instep, in, sizeof(vec5_t));
// clip the winding
instep = in;
outcount = 0;
- for (i=0 ; i<nump ; i++, instep += sizeof (vec5_t) / sizeof (float))
- {
- if (dists[i] >= 0)
- {
- memcpy (outstep, instep, sizeof (vec5_t));
- outstep += sizeof (vec5_t) / sizeof (float);
+ for (i = 0; i < nump; i++, instep += sizeof(vec5_t) / sizeof(float)) {
+ if (dists[i] >= 0) {
+ memcpy(outstep, instep, sizeof(vec5_t));
+ outstep += sizeof(vec5_t) / sizeof(float);
outcount++;
}
- if (dists[i] == 0 || dists[i+1] == 0)
+ if (dists[i] == 0 || dists[i + 1] == 0)
continue;
- if ( (dists[i] > 0) == (dists[i+1] > 0) )
+ if ((dists[i] > 0) == (dists[i + 1] > 0))
continue;
-
- // split it into a new vertex
- frac = dists[i] / (dists[i] - dists[i+1]);
-
- vert2 = instep + sizeof (vec5_t) / sizeof (float);
-
- outstep[0] = instep[0] + frac*(vert2[0] - instep[0]);
- outstep[1] = instep[1] + frac*(vert2[1] - instep[1]);
- outstep[2] = instep[2] + frac*(vert2[2] - instep[2]);
- outstep[3] = instep[3] + frac*(vert2[3] - instep[3]);
- outstep[4] = instep[4] + frac*(vert2[4] - instep[4]);
-
- outstep += sizeof (vec5_t) / sizeof (float);
+
+ // split it into a new vertex
+ frac = dists[i] / (dists[i] - dists[i + 1]);
+
+ vert2 = instep + sizeof(vec5_t) / sizeof(float);
+
+ outstep[0] = instep[0] + frac * (vert2[0] - instep[0]);
+ outstep[1] = instep[1] + frac * (vert2[1] - instep[1]);
+ outstep[2] = instep[2] + frac * (vert2[2] - instep[2]);
+ outstep[3] = instep[3] + frac * (vert2[3] - instep[3]);
+ outstep[4] = instep[4] + frac * (vert2[4] - instep[4]);
+
+ outstep += sizeof(vec5_t) / sizeof(float);
outcount++;
- }
-
+ }
+
return outcount;
}
@@ -583,7 +542,7 @@ static int R_ClipPolyFace (int nump, clipplane_t *pclipplane)
** R_PolygonDrawSpans
*/
// PGM - iswater was qboolean. changed to allow passing more flags
-static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
+static void R_PolygonDrawSpans(espan_t *pspan, int iswater)
{
int count;
fixed16_t snext, tnext;
@@ -593,8 +552,8 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
s_spanletvars.pbase = cacheblock;
//PGM
- if ( iswater & SURF_WARP)
- r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
+ if (iswater & SURF_WARP)
+ r_turb_turb = sintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1));
else if (iswater & SURF_FLOWING)
r_turb_turb = blanktable;
//PGM
@@ -609,9 +568,8 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
s_spanletvars.pz = 0;
- do
- {
- s_spanletvars.pdest = (byte *)d_viewbuffer + ( d_scantable[pspan->v] /*r_screenwidth * pspan->v*/) + pspan->u;
+ do {
+ s_spanletvars.pdest = (byte *)d_viewbuffer + (d_scantable[pspan->v] /*r_screenwidth * pspan->v*/) + pspan->u;
s_spanletvars.pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u;
s_spanletvars.u = pspan->u;
s_spanletvars.v = pspan->v;
@@ -621,23 +579,22 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
if (count <= 0)
goto NextSpan;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
- // we count on FP exceptions being turned off to avoid range problems
+ // we count on FP exceptions being turned off to avoid range problems
s_spanletvars.izi = (int)(zi * 0x8000 * 0x10000);
s_spanletvars.s = (int)(sdivz * z) + sadjust;
s_spanletvars.t = (int)(tdivz * z) + tadjust;
- if ( !iswater )
- {
+ if (!iswater) {
if (s_spanletvars.s > bbextents)
s_spanletvars.s = bbextents;
else if (s_spanletvars.s < 0)
@@ -649,20 +606,18 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
s_spanletvars.t = 0;
}
- do
- {
- // calculate s and t at the far end of the span
- if (count >= AFFINE_SPANLET_SIZE )
+ do {
+ // calculate s and t at the far end of the span
+ if (count >= AFFINE_SPANLET_SIZE)
s_spanletvars.spancount = AFFINE_SPANLET_SIZE;
else
s_spanletvars.spancount = count;
count -= s_spanletvars.spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivzspanletstepu;
tdivz += tdivzspanletstepu;
zi += zispanletstepu;
@@ -671,14 +626,13 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
snext = (int)(sdivz * z) + sadjust;
tnext = (int)(tdivz * z) + tadjust;
- if ( !iswater )
- {
+ if (!iswater) {
if (snext > bbextents)
snext = bbextents;
else if (snext < AFFINE_SPANLET_SIZE)
snext = AFFINE_SPANLET_SIZE; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
if (tnext > bbextentt)
tnext = bbextentt;
@@ -688,13 +642,11 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
s_spanletvars.sstep = (snext - s_spanletvars.s) >> AFFINE_SPANLET_SIZE_BITS;
s_spanletvars.tstep = (tnext - s_spanletvars.t) >> AFFINE_SPANLET_SIZE_BITS;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(s_spanletvars.spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -703,14 +655,13 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
snext = (int)(sdivz * z) + sadjust;
tnext = (int)(tdivz * z) + tadjust;
- if ( !iswater )
- {
+ if (!iswater) {
if (snext > bbextents)
snext = bbextents;
else if (snext < AFFINE_SPANLET_SIZE)
snext = AFFINE_SPANLET_SIZE; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
if (tnext > bbextentt)
tnext = bbextentt;
@@ -718,17 +669,15 @@ static void R_PolygonDrawSpans(espan_t *pspan, int iswater )
tnext = AFFINE_SPANLET_SIZE; // guard against round-off error on <0 steps
}
- if (s_spanletvars.spancount > 1)
- {
+ if (s_spanletvars.spancount > 1) {
s_spanletvars.sstep = (snext - s_spanletvars.s) / (s_spanletvars.spancount - 1);
s_spanletvars.tstep = (tnext - s_spanletvars.t) / (s_spanletvars.spancount - 1);
}
}
- if ( iswater )
- {
- s_spanletvars.s = s_spanletvars.s & ((CYCLE<<16)-1);
- s_spanletvars.t = s_spanletvars.t & ((CYCLE<<16)-1);
+ if (iswater) {
+ s_spanletvars.s = s_spanletvars.s & ((CYCLE << 16) - 1);
+ s_spanletvars.t = s_spanletvars.t & ((CYCLE << 16) - 1);
}
r_polydesc.drawspanlet();
@@ -748,10 +697,10 @@ NextSpan:
**
** R_PolygonScanLeftEdge
**
-** Goes through the polygon and scans the left edge, filling in
+** Goes through the polygon and scans the left edge, filling in
** screen coordinate data for the spans
*/
-static void R_PolygonScanLeftEdge (void)
+static void R_PolygonScanLeftEdge(void)
{
int i, v, itop, ibottom, lmaxindex;
emitpoint_t *pvert, *pnext;
@@ -768,30 +717,27 @@ static void R_PolygonScanLeftEdge (void)
if (lmaxindex == 0)
lmaxindex = r_polydesc.nump;
- vtop = ceil (r_polydesc.pverts[i].v);
+ vtop = ceil(r_polydesc.pverts[i].v);
- do
- {
+ do {
pvert = &r_polydesc.pverts[i];
pnext = pvert - 1;
- vbottom = ceil (pnext->v);
+ vbottom = ceil(pnext->v);
- if (vtop < vbottom)
- {
+ if (vtop < vbottom) {
du = pnext->u - pvert->u;
dv = pnext->v - pvert->v;
slope = du / dv;
u_step = (int)(slope * 0x10000);
- // adjust u to ceil the integer portion
+ // adjust u to ceil the integer portion
u = (int)((pvert->u + (slope * (vtop - pvert->v))) * 0x10000) +
- (0x10000 - 1);
+ (0x10000 - 1);
itop = (int)vtop;
ibottom = (int)vbottom;
- for (v=itop ; v<ibottom ; v++)
- {
+ for (v = itop; v < ibottom; v++) {
pspan->u = u >> 16;
pspan->v = v;
u += u_step;
@@ -814,7 +760,7 @@ static void R_PolygonScanLeftEdge (void)
** Goes through the polygon and scans the right edge, filling in
** count values.
*/
-static void R_PolygonScanRightEdge (void)
+static void R_PolygonScanRightEdge(void)
{
int i, v, itop, ibottom;
emitpoint_t *pvert, *pnext;
@@ -831,10 +777,9 @@ static void R_PolygonScanRightEdge (void)
if (vvert > r_refdef.fvrectbottom_adj)
vvert = r_refdef.fvrectbottom_adj;
- vtop = ceil (vvert);
+ vtop = ceil(vvert);
- do
- {
+ do {
pvert = &r_polydesc.pverts[i];
pnext = pvert + 1;
@@ -844,10 +789,9 @@ static void R_PolygonScanRightEdge (void)
if (vnext > r_refdef.fvrectbottom_adj)
vnext = r_refdef.fvrectbottom_adj;
- vbottom = ceil (vnext);
+ vbottom = ceil(vnext);
- if (vtop < vbottom)
- {
+ if (vtop < vbottom) {
uvert = pvert->u;
if (uvert < r_refdef.fvrectx_adj)
uvert = r_refdef.fvrectx_adj;
@@ -864,14 +808,13 @@ static void R_PolygonScanRightEdge (void)
dv = vnext - vvert;
slope = du / dv;
u_step = (int)(slope * 0x10000);
- // adjust u to ceil the integer portion
+ // adjust u to ceil the integer portion
u = (int)((uvert + (slope * (vtop - vvert))) * 0x10000) +
- (0x10000 - 1);
+ (0x10000 - 1);
itop = (int)vtop;
ibottom = (int)vbottom;
- for (v=itop ; v<ibottom ; v++)
- {
+ for (v = itop; v < ibottom; v++) {
pspan->count = (u >> 16) - pspan->u;
u += u_step;
pspan++;
@@ -887,70 +830,55 @@ static void R_PolygonScanRightEdge (void)
} while (i != s_maxindex);
- pspan->count = DS_SPAN_LIST_END; // mark the end of the span list
+ pspan->count = DS_SPAN_LIST_END; // mark the end of the span list
}
/*
** R_ClipAndDrawPoly
*/
// PGM - isturbulent was qboolean. changed to int to allow passing more flags
-static void R_ClipAndDrawPoly ( float alpha, int isturbulent, qboolean textured )
+static void R_ClipAndDrawPoly(float alpha, int isturbulent, qboolean textured)
{
- emitpoint_t outverts[MAXWORKINGVERTS+3], *pout;
+ emitpoint_t outverts[MAXWORKINGVERTS + 3], *pout;
float *pv;
int i, nump;
float scale;
vec3_t transformed, local;
- if ( !textured )
- {
+ if (!textured) {
r_polydesc.drawspanlet = R_DrawSpanletConstant33;
- }
- else
- {
+ } else {
/*
** choose the correct spanlet routine based on alpha
*/
- if ( alpha == 1 )
- {
+ if (alpha == 1) {
// isturbulent is ignored because we know that turbulent surfaces
// can't be opaque
r_polydesc.drawspanlet = R_DrawSpanletOpaque;
- }
- else
- {
- if ( sw_stipplealpha->integer )
- {
- if ( isturbulent )
- {
- if ( alpha > 0.33 )
+ } else {
+ if (sw_stipplealpha->integer) {
+ if (isturbulent) {
+ if (alpha > 0.33)
r_polydesc.drawspanlet = R_DrawSpanletTurbulentStipple66;
- else
+ else
r_polydesc.drawspanlet = R_DrawSpanletTurbulentStipple33;
- }
- else
- {
- if ( alpha > 0.33 )
+ } else {
+ if (alpha > 0.33)
r_polydesc.drawspanlet = R_DrawSpanlet66Stipple;
- else
+ else
r_polydesc.drawspanlet = R_DrawSpanlet33Stipple;
}
- }
- else
- {
- if ( isturbulent )
- {
- if ( alpha > 0.33 )
+ } else {
+ if (isturbulent) {
+ if (alpha > 0.33)
r_polydesc.drawspanlet = R_DrawSpanletTurbulentBlended66;
else
r_polydesc.drawspanlet = R_DrawSpanletTurbulentBlended33;
- }
- else
- {
- if ( alpha > 0.33 )
+ } else {
+ if (alpha > 0.33)
r_polydesc.drawspanlet = R_DrawSpanlet66;
- else
+ else
r_polydesc.drawspanlet = R_DrawSpanlet33;
}
}
@@ -961,22 +889,20 @@ static void R_ClipAndDrawPoly ( float alpha, int isturbulent, qboolean textured
nump = r_polydesc.nump;
clip_current = 0;
- for (i=0 ; i<4 ; i++)
- {
- nump = R_ClipPolyFace (nump, &view_clipplanes[i]);
+ for (i = 0; i < 4; i++) {
+ nump = R_ClipPolyFace(nump, &view_clipplanes[i]);
if (nump < 3)
return;
if (nump > MAXWORKINGVERTS)
- Com_Error(ERR_DROP, "R_ClipAndDrawPoly: too many points: %d", nump );
+ Com_Error(ERR_DROP, "R_ClipAndDrawPoly: too many points: %d", nump);
}
// transform vertices into viewspace and project
pv = &r_clip_verts[clip_current][0][0];
- for (i=0 ; i<nump ; i++)
- {
- VectorSubtract (pv, r_origin, local);
- TransformVector (local, transformed);
+ for (i = 0; i < nump; i++) {
+ VectorSubtract(pv, r_origin, local);
+ TransformVector(local, transformed);
if (transformed[2] < NEAR_CLIP)
transformed[2] = NEAR_CLIP;
@@ -986,21 +912,21 @@ static void R_ClipAndDrawPoly ( float alpha, int isturbulent, qboolean textured
pout->s = pv[3];
pout->t = pv[4];
-
+
scale = xscale * pout->zi;
pout->u = (xcenter + scale * transformed[0]);
scale = yscale * pout->zi;
pout->v = (ycenter - scale * transformed[1]);
- pv += sizeof (vec5_t) / sizeof (vec_t);
+ pv += sizeof(vec5_t) / sizeof(vec_t);
}
// draw it
r_polydesc.nump = nump;
r_polydesc.pverts = outverts;
- R_DrawPoly( isturbulent );
+ R_DrawPoly(isturbulent);
}
/*
@@ -1026,35 +952,31 @@ static void R_BuildPolygonFromSurface(mface_t *fa)
pverts = r_clip_verts[0];
surfedge = fa->firstsurfedge;
- for (i=0 ; i<lnumverts ; i++, surfedge++)
- {
+ for (i = 0; i < lnumverts; i++, surfedge++) {
vec = surfedge->edge->v[surfedge->vert]->point;
- VectorCopy (vec, pverts[i] );
+ VectorCopy(vec, pverts[i]);
}
- VectorCopy( fa->texinfo->axis[0], r_polydesc.vright );
- VectorCopy( fa->texinfo->axis[1], r_polydesc.vup );
- VectorCopy( fa->plane->normal, r_polydesc.vpn );
- VectorCopy( r_origin, r_polydesc.viewer_position );
+ VectorCopy(fa->texinfo->axis[0], r_polydesc.vright);
+ VectorCopy(fa->texinfo->axis[1], r_polydesc.vup);
+ VectorCopy(fa->plane->normal, r_polydesc.vpn);
+ VectorCopy(r_origin, r_polydesc.viewer_position);
- if ( fa->drawflags & DSURF_PLANEBACK )
- {
- VectorInverse( r_polydesc.vpn );
+ if (fa->drawflags & DSURF_PLANEBACK) {
+ VectorInverse(r_polydesc.vpn);
}
// PGM 09/16/98
- if ( fa->texinfo->c.flags & (SURF_WARP|SURF_FLOWING) )
- {
+ if (fa->texinfo->c.flags & (SURF_WARP | SURF_FLOWING)) {
r_polydesc.pixels = fa->texinfo->image->pixels[0];
r_polydesc.pixel_width = fa->texinfo->image->width;
r_polydesc.pixel_height = fa->texinfo->image->height;
}
// PGM 09/16/98
- else
- {
+ else {
surfcache_t *scache;
- scache = D_CacheSurface( fa, 0 );
+ scache = D_CacheSurface(fa, 0);
r_polydesc.pixels = scache->data;
r_polydesc.pixel_width = scache->width;
@@ -1064,15 +986,14 @@ static void R_BuildPolygonFromSurface(mface_t *fa)
tmins[1] = fa->texturemins[1];
}
- r_polydesc.dist = DotProduct( r_polydesc.vpn, pverts[0] );
+ r_polydesc.dist = DotProduct(r_polydesc.vpn, pverts[0]);
r_polydesc.s_offset = fa->texinfo->offset[0] - tmins[0];
r_polydesc.t_offset = fa->texinfo->offset[1] - tmins[1];
// scrolling texture addition
- if (fa->texinfo->c.flags & SURF_FLOWING)
- {
- r_polydesc.s_offset += -128 * ( (r_newrefdef.time*0.25) - (int)(r_newrefdef.time*0.25) );
+ if (fa->texinfo->c.flags & SURF_FLOWING) {
+ r_polydesc.s_offset += -128 * ((r_newrefdef.time * 0.25) - (int)(r_newrefdef.time * 0.25));
}
r_polydesc.nump = lnumverts;
@@ -1081,16 +1002,16 @@ static void R_BuildPolygonFromSurface(mface_t *fa)
/*
** R_PolygonCalculateGradients
*/
-static void R_PolygonCalculateGradients (void)
+static void R_PolygonCalculateGradients(void)
{
vec3_t p_normal, p_saxis, p_taxis;
float distinv;
- TransformVector (r_polydesc.vpn, p_normal);
- TransformVector (r_polydesc.vright, p_saxis);
- TransformVector (r_polydesc.vup, p_taxis);
+ TransformVector(r_polydesc.vpn, p_normal);
+ TransformVector(r_polydesc.vright, p_saxis);
+ TransformVector(r_polydesc.vup, p_taxis);
- distinv = 1.0 / (-(DotProduct (r_polydesc.viewer_position, r_polydesc.vpn)) + r_polydesc.dist );
+ distinv = 1.0 / (-(DotProduct(r_polydesc.viewer_position, r_polydesc.vpn)) + r_polydesc.dist);
d_sdivzstepu = p_saxis[0] * xscaleinv;
d_sdivzstepv = -p_saxis[1] * yscaleinv;
@@ -1104,8 +1025,8 @@ static void R_PolygonCalculateGradients (void)
d_zistepv = -p_normal[1] * yscaleinv * distinv;
d_ziorigin = p_normal[2] * distinv - xcenter * d_zistepu - ycenter * d_zistepv;
- sadjust = (fixed16_t) ( ( DotProduct( r_polydesc.viewer_position, r_polydesc.vright) + r_polydesc.s_offset ) * 0x10000 );
- tadjust = (fixed16_t) ( ( DotProduct( r_polydesc.viewer_position, r_polydesc.vup ) + r_polydesc.t_offset ) * 0x10000 );
+ sadjust = (fixed16_t)((DotProduct(r_polydesc.viewer_position, r_polydesc.vright) + r_polydesc.s_offset) * 0x10000);
+ tadjust = (fixed16_t)((DotProduct(r_polydesc.viewer_position, r_polydesc.vup) + r_polydesc.t_offset) * 0x10000);
// -1 (-epsilon) so we never wander off the edge of the texture
bbextents = (r_polydesc.pixel_width << 16) - 1;
@@ -1121,12 +1042,12 @@ static void R_PolygonCalculateGradients (void)
** This should NOT be called externally since it doesn't do clipping!
*/
// PGM - iswater was qboolean. changed to support passing more flags
-static void R_DrawPoly( int iswater )
+static void R_DrawPoly(int iswater)
{
int i, nump;
float ymin, ymax;
emitpoint_t *pverts;
- espan_t spans[MAXHEIGHT+1];
+ espan_t spans[MAXHEIGHT + 1];
s_polygon_spans = spans;
@@ -1136,16 +1057,13 @@ static void R_DrawPoly( int iswater )
ymax = -999999.9;
pverts = r_polydesc.pverts;
- for (i=0 ; i<r_polydesc.nump ; i++)
- {
- if (pverts->v < ymin)
- {
+ for (i = 0; i < r_polydesc.nump; i++) {
+ if (pverts->v < ymin) {
ymin = pverts->v;
s_minindex = i;
}
- if (pverts->v > ymax)
- {
+ if (pverts->v > ymax) {
ymax = pverts->v;
s_maxindex = i;
}
@@ -1153,8 +1071,8 @@ static void R_DrawPoly( int iswater )
pverts++;
}
- ymin = ceil (ymin);
- ymax = ceil (ymax);
+ ymin = ceil(ymin);
+ ymax = ceil(ymax);
if (ymin >= ymax)
return; // doesn't cross any scans at all
@@ -1168,17 +1086,17 @@ static void R_DrawPoly( int iswater )
pverts = r_polydesc.pverts;
pverts[nump] = pverts[0];
- R_PolygonCalculateGradients ();
- R_PolygonScanLeftEdge ();
- R_PolygonScanRightEdge ();
+ R_PolygonCalculateGradients();
+ R_PolygonScanLeftEdge();
+ R_PolygonScanRightEdge();
- R_PolygonDrawSpans( s_polygon_spans, iswater );
+ R_PolygonDrawSpans(s_polygon_spans, iswater);
}
/*
** R_DrawAlphaSurfaces
*/
-void R_DrawAlphaSurfaces( void )
+void R_DrawAlphaSurfaces(void)
{
mface_t *s = r_alpha_surfaces;
@@ -1188,45 +1106,44 @@ void R_DrawAlphaSurfaces( void )
modelorg[1] = -r_origin[1];
modelorg[2] = -r_origin[2];
- while ( s )
- {
- R_BuildPolygonFromSurface( s );
+ while (s) {
+ R_BuildPolygonFromSurface(s);
//=======
//PGM
// if (s->texinfo->flags & SURF_TRANS66)
-// R_ClipAndDrawPoly( 0.60f, ( s->texinfo->flags & SURF_WARP) != 0, qtrue );
+// R_ClipAndDrawPoly(0.60f, (s->texinfo->flags & SURF_WARP) != 0, qtrue);
// else
-// R_ClipAndDrawPoly( 0.30f, ( s->texinfo->flags & SURF_WARP) != 0, qtrue );
+// R_ClipAndDrawPoly(0.30f, (s->texinfo->flags & SURF_WARP) != 0, qtrue);
// PGM - pass down all the texinfo flags, not just SURF_WARP.
if (s->texinfo->c.flags & SURF_TRANS66)
- R_ClipAndDrawPoly( 0.60f, (s->texinfo->c.flags & (SURF_WARP|SURF_FLOWING)), qtrue );
+ R_ClipAndDrawPoly(0.60f, (s->texinfo->c.flags & (SURF_WARP | SURF_FLOWING)), qtrue);
else
- R_ClipAndDrawPoly( 0.30f, (s->texinfo->c.flags & (SURF_WARP|SURF_FLOWING)), qtrue );
+ R_ClipAndDrawPoly(0.30f, (s->texinfo->c.flags & (SURF_WARP | SURF_FLOWING)), qtrue);
//PGM
//=======
s = s->next;
}
-
+
r_alpha_surfaces = NULL;
}
/*
** R_IMFlatShadedQuad
*/
-void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha )
+void R_IMFlatShadedQuad(vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha)
{
vec3_t s0, s1;
r_polydesc.nump = 4;
- VectorCopy( r_origin, r_polydesc.viewer_position );
+ VectorCopy(r_origin, r_polydesc.viewer_position);
- VectorCopy( a, r_clip_verts[0][0] );
- VectorCopy( b, r_clip_verts[0][1] );
- VectorCopy( c, r_clip_verts[0][2] );
- VectorCopy( d, r_clip_verts[0][3] );
+ VectorCopy(a, r_clip_verts[0][0]);
+ VectorCopy(b, r_clip_verts[0][1]);
+ VectorCopy(c, r_clip_verts[0][2]);
+ VectorCopy(d, r_clip_verts[0][3]);
r_clip_verts[0][0][3] = 0;
r_clip_verts[0][1][3] = 0;
@@ -1238,16 +1155,16 @@ void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, floa
r_clip_verts[0][2][4] = 0;
r_clip_verts[0][3][4] = 0;
- VectorSubtract( d, c, s0 );
- VectorSubtract( c, b, s1 );
- CrossProduct( s0, s1, r_polydesc.vpn );
- VectorNormalize( r_polydesc.vpn );
+ VectorSubtract(d, c, s0);
+ VectorSubtract(c, b, s1);
+ CrossProduct(s0, s1, r_polydesc.vpn);
+ VectorNormalize(r_polydesc.vpn);
- r_polydesc.dist = DotProduct( r_polydesc.vpn, r_clip_verts[0][0] );
+ r_polydesc.dist = DotProduct(r_polydesc.vpn, r_clip_verts[0][0]);
r_polyblendcolor = color;
- R_ClipAndDrawPoly( alpha, qfalse, qfalse );
+ R_ClipAndDrawPoly(alpha, qfalse, qfalse);
}
/*
@@ -1256,14 +1173,14 @@ void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, floa
** Draw currententity / currentmodel as a single texture
** mapped polygon
*/
-void R_DrawSprite (void)
+void R_DrawSprite(void)
{
vec5_t *pverts;
vec3_t left, up, right, down;
mspriteframe_t *frame;
frame = &currentmodel->spriteframes[
- currententity->frame % currentmodel->numframes];
+ currententity->frame % currentmodel->numframes];
r_polydesc.pixels = frame->image->pixels[0];
r_polydesc.pixel_width = frame->width;
@@ -1271,22 +1188,22 @@ void R_DrawSprite (void)
r_polydesc.dist = 0;
// generate the sprite's axes, completely parallel to the viewplane.
- VectorCopy (vup, r_polydesc.vup);
- VectorCopy (vright, r_polydesc.vright);
- VectorCopy (vpn, r_polydesc.vpn);
+ VectorCopy(vup, r_polydesc.vup);
+ VectorCopy(vright, r_polydesc.vright);
+ VectorCopy(vpn, r_polydesc.vpn);
// build the sprite poster in worldspace
- VectorScale (r_polydesc.vright,
- frame->width - frame->origin_x, right);
- VectorScale (r_polydesc.vup,
- frame->height - frame->origin_y, up);
- VectorScale (r_polydesc.vright,
- -frame->origin_x, left);
- VectorScale (r_polydesc.vup,
- -frame->origin_y, down);
+ VectorScale(r_polydesc.vright,
+ frame->width - frame->origin_x, right);
+ VectorScale(r_polydesc.vup,
+ frame->height - frame->origin_y, up);
+ VectorScale(r_polydesc.vright,
+ -frame->origin_x, left);
+ VectorScale(r_polydesc.vup,
+ -frame->origin_y, down);
// invert UP vector for sprites
- VectorNegate( r_polydesc.vup, r_polydesc.vup );
+ VectorNegate(r_polydesc.vup, r_polydesc.vup);
pverts = r_clip_verts[0];
@@ -1315,15 +1232,15 @@ void R_DrawSprite (void)
pverts[3][4] = frame->height;
r_polydesc.nump = 4;
- r_polydesc.s_offset = ( r_polydesc.pixel_width >> 1);
- r_polydesc.t_offset = ( r_polydesc.pixel_height >> 1);
- VectorCopy( modelorg, r_polydesc.viewer_position );
+ r_polydesc.s_offset = (r_polydesc.pixel_width >> 1);
+ r_polydesc.t_offset = (r_polydesc.pixel_height >> 1);
+ VectorCopy(modelorg, r_polydesc.viewer_position);
r_polydesc.stipple_parity = 1;
- if ( currententity->flags & RF_TRANSLUCENT )
- R_ClipAndDrawPoly ( currententity->alpha, qfalse, qtrue );
+ if (currententity->flags & RF_TRANSLUCENT)
+ R_ClipAndDrawPoly(currententity->alpha, qfalse, qtrue);
else
- R_ClipAndDrawPoly ( 1.0F, qfalse, qtrue );
+ R_ClipAndDrawPoly(1.0F, qfalse, qtrue);
r_polydesc.stipple_parity = 0;
}
diff --git a/src/sw_polyse.c b/src/sw_polyse.c
index 0e39b4f..93e2187 100644
--- a/src/sw_polyse.c
+++ b/src/sw_polyse.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -32,8 +32,8 @@ int rand1k_index = 0;
// TODO: put in span spilling to shrink list size
// !!! if this is changed, it must be changed in d_polysa.s too !!!
-#define DPS_MAXSPANS MAXHEIGHT+1
- // 1 extra for spanpackage that marks end
+#define DPS_MAXSPANS MAXHEIGHT+1
+// 1 extra for spanpackage that marks end
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct {
@@ -104,7 +104,7 @@ typedef struct {
int remainder;
} adivtab_t;
-static adivtab_t adivtab[32*32] = {
+static adivtab_t adivtab[32 * 32] = {
#include "adivtab.h"
};
@@ -112,17 +112,17 @@ byte *skintable[MAX_LBM_HEIGHT];
int skinwidth;
byte *skinstart;
-void (*d_pdrawspans)(spanpackage_t *pspanpackage);
+void (*d_pdrawspans)(spanpackage_t *pspanpackage);
-void R_PolysetDrawSpans8_33 (spanpackage_t *pspanpackage);
-void R_PolysetDrawSpans8_66 (spanpackage_t *pspanpackage);
-void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage);
+void R_PolysetDrawSpans8_33(spanpackage_t *pspanpackage);
+void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage);
+void R_PolysetDrawSpans8_Opaque(spanpackage_t *pspanpackage);
-void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage);
-void R_PolysetCalcGradients (int skinwidth);
-void R_DrawNonSubdiv (void);
-void R_PolysetSetEdgeTable (void);
-void R_RasterizeAliasPolySmooth (void);
+void R_PolysetDrawThreshSpans8(spanpackage_t *pspanpackage);
+void R_PolysetCalcGradients(int skinwidth);
+void R_DrawNonSubdiv(void);
+void R_PolysetSetEdgeTable(void);
+void R_RasterizeAliasPolySmooth(void);
void R_PolysetScanLeftEdge(int height);
void R_PolysetScanLeftEdge_C(int height);
@@ -139,7 +139,7 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 208, 208, 208, 208, 208, 208, // unused?'
64, 66, 68, 70, 72, 74, 76, 78, // dark yellow
-
+
64, 65, 66, 67, 68, 69, 70, 71, // dark red
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // grey/tan
@@ -148,7 +148,7 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
64, 66, 68, 70, 72, 74, 76, 78, // chocolate
68, 67, 66, 65, 64, 65, 66, 67, // mauve / teal
68, 69, 70, 71, 72, 73, 74, 75,
- 76, 76, 77, 77, 78, 78, 79, 79,
+ 76, 76, 77, 77, 78, 78, 79, 79,
64, 65, 66, 67, 68, 69, 70, 71, // more mauve
72, 73, 74, 75, 76, 77, 78, 79,
@@ -159,7 +159,7 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // sky blue
72, 73, 74, 75, 76, 77, 78, 79,
-
+
64, 65, 66, 67, 68, 69, 70, 71, // olive again
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // nuclear green
@@ -168,7 +168,8 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
64, 65, 66, 67, 68, 69, 70, 71, // fire colors
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 64, 64, 70, 71, 72, 64, // mishmash1
- 66, 68, 70, 64, 65, 66, 67, 68}; // mishmash2
+ 66, 68, 70, 64, 65, 66, 67, 68
+ }; // mishmash2
// PGM
// ======================
@@ -177,18 +178,17 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
R_PolysetUpdateTables
================
*/
-void R_PolysetUpdateTables (void)
+void R_PolysetUpdateTables(void)
{
int i;
byte *s;
-
+
if (r_affinetridesc.skinwidth != skinwidth ||
- r_affinetridesc.pskin != skinstart)
- {
+ r_affinetridesc.pskin != skinstart) {
skinwidth = r_affinetridesc.skinwidth;
skinstart = r_affinetridesc.pskin;
s = skinstart;
- for (i=0 ; i<MAX_LBM_HEIGHT ; i++, s+=skinwidth)
+ for (i = 0; i < MAX_LBM_HEIGHT; i++, s += skinwidth)
skintable[i] = s;
}
}
@@ -199,7 +199,7 @@ void R_PolysetUpdateTables (void)
R_DrawTriangle
================
*/
-void R_DrawTriangle( void )
+void R_DrawTriangle(void)
{
spanpackage_t spans[DPS_MAXSPANS];
@@ -207,26 +207,25 @@ void R_DrawTriangle( void )
int dv0_ab, dv1_ac;
/*
- d_xdenom = ( aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1] ) * ( aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0] ) -
- ( aliastriangleparms.a->v[0] - aliastriangleparms.b->v[0] ) * ( aliastriangleparms.a->v[1] - aliastriangleparms.c->v[1] );
+ d_xdenom = (aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1]) * (aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0]) -
+ (aliastriangleparms.a->v[0] - aliastriangleparms.b->v[0]) * (aliastriangleparms.a->v[1] - aliastriangleparms.c->v[1]);
*/
dv0_ab = aliastriangleparms.a->u - aliastriangleparms.b->u;
dv1_ab = aliastriangleparms.a->v - aliastriangleparms.b->v;
- if ( !( dv0_ab | dv1_ab ) )
+ if (!(dv0_ab | dv1_ab))
return;
dv0_ac = aliastriangleparms.a->u - aliastriangleparms.c->u;
dv1_ac = aliastriangleparms.a->v - aliastriangleparms.c->v;
- if ( !( dv0_ac | dv1_ac ) )
+ if (!(dv0_ac | dv1_ac))
return;
- d_xdenom = ( dv0_ac * dv1_ab ) - ( dv0_ab * dv1_ac );
+ d_xdenom = (dv0_ac * dv1_ab) - (dv0_ab * dv1_ac);
- if ( d_xdenom < 0 )
- {
+ if (d_xdenom < 0) {
a_spans = spans;
r_p0[0] = aliastriangleparms.a->u; // u
@@ -250,8 +249,8 @@ void R_DrawTriangle( void )
r_p2[4] = aliastriangleparms.c->l;
r_p2[5] = aliastriangleparms.c->zi;
- R_PolysetSetEdgeTable ();
- R_RasterizeAliasPolySmooth ();
+ R_PolysetSetEdgeTable();
+ R_RasterizeAliasPolySmooth();
}
}
@@ -263,8 +262,7 @@ R_PolysetScanLeftEdge_C
*/
void R_PolysetScanLeftEdge_C(int height)
{
- do
- {
+ do {
d_pedgespanpackage->pdest = d_pdest;
d_pedgespanpackage->pz = d_pz;
d_pedgespanpackage->count = d_aspancount;
@@ -273,15 +271,14 @@ void R_PolysetScanLeftEdge_C(int height)
d_pedgespanpackage->sfrac = d_sfrac;
d_pedgespanpackage->tfrac = d_tfrac;
- // FIXME: need to clamp l, s, t, at both ends?
+ // FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_pdest += d_pdestextrastep;
d_pz += d_pzextrastep;
d_aspancount += d_countextrastep;
@@ -291,17 +288,14 @@ void R_PolysetScanLeftEdge_C(int height)
d_sfrac &= 0xFFFF;
d_tfrac += d_tfracextrastep;
- if (d_tfrac & 0x10000)
- {
+ if (d_tfrac & 0x10000) {
d_ptex += r_affinetridesc.skinwidth;
d_tfrac &= 0xFFFF;
}
d_light += d_lightextrastep;
d_zi += d_ziextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_pdest += d_pdestbasestep;
d_pz += d_pzbasestep;
d_aspancount += ubasestep;
@@ -310,8 +304,7 @@ void R_PolysetScanLeftEdge_C(int height)
d_ptex += d_sfrac >> 16;
d_sfrac &= 0xFFFF;
d_tfrac += d_tfracbasestep;
- if (d_tfrac & 0x10000)
- {
+ if (d_tfrac & 0x10000) {
d_ptex += r_affinetridesc.skinwidth;
d_tfrac &= 0xFFFF;
}
@@ -331,29 +324,25 @@ quotient must fit in 32 bits.
FIXME: GET RID OF THIS! (FloorDivMod)
====================
*/
-void FloorDivMod (float numer, float denom, int *quotient,
- int *rem)
+void FloorDivMod(float numer, float denom, int *quotient,
+ int *rem)
{
int q, r;
float x;
- if (numer >= 0.0)
- {
+ if (numer >= 0.0) {
x = floor(numer / denom);
q = (int)x;
r = (int)floor(numer - (x * denom));
- }
- else
- {
- //
- // perform operations with positive values, and fix mod to make floor-based
- //
+ } else {
+ //
+ // perform operations with positive values, and fix mod to make floor-based
+ //
x = floor(-numer / denom);
q = -(int)x;
r = (int)floor(-numer - (x * denom));
- if (r != 0)
- {
+ if (r != 0) {
q--;
r = (int)denom - r;
}
@@ -370,7 +359,7 @@ R_PolysetSetUpForLineScan
====================
*/
void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
- fixed8_t endvertu, fixed8_t endvertv)
+ fixed8_t endvertu, fixed8_t endvertv)
{
float dm, dn;
int tm, tn;
@@ -384,19 +373,16 @@ void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
tn = endvertv - startvertv;
if (((tm <= 16) && (tm >= -15)) &&
- ((tn <= 16) && (tn >= -15)))
- {
- ptemp = &adivtab[((tm+15) << 5) + (tn+15)];
+ ((tn <= 16) && (tn >= -15))) {
+ ptemp = &adivtab[((tm + 15) << 5) + (tn + 15)];
ubasestep = ptemp->quotient;
erroradjustup = ptemp->remainder;
erroradjustdown = tn;
- }
- else
- {
+ } else {
dm = tm;
dn = tn;
- FloorDivMod (dm, dn, &ubasestep, &erroradjustup);
+ FloorDivMod(dm, dn, &ubasestep, &erroradjustup);
erroradjustdown = dn;
}
@@ -408,7 +394,7 @@ R_PolysetCalcGradients
================
*/
-void R_PolysetCalcGradients (int skinwidth)
+void R_PolysetCalcGradients(int skinwidth)
{
float xstepdenominv, ystepdenominv, t0, t1;
float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20;
@@ -428,38 +414,36 @@ void R_PolysetCalcGradients (int skinwidth)
t0 = r_p0[4] - r_p2[4];
t1 = r_p1[4] - r_p2[4];
r_lstepx = (int)
- ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv);
+ ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv);
r_lstepy = (int)
- ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv);
+ ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv);
t0 = r_p0[2] - r_p2[2];
t1 = r_p1[2] - r_p2[2];
r_sstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
- xstepdenominv);
- r_sstepy = (int)((t1 * p00_minus_p20 - t0* p10_minus_p20) *
- ystepdenominv);
+ xstepdenominv);
+ r_sstepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
+ ystepdenominv);
t0 = r_p0[3] - r_p2[3];
t1 = r_p1[3] - r_p2[3];
r_tstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
- xstepdenominv);
+ xstepdenominv);
r_tstepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
- ystepdenominv);
+ ystepdenominv);
t0 = r_p0[5] - r_p2[5];
t1 = r_p1[5] - r_p2[5];
r_zistepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
- xstepdenominv);
+ xstepdenominv);
r_zistepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
- ystepdenominv);
+ ystepdenominv);
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
a_sstepxfrac = r_sstepx << 16;
a_tstepxfrac = r_tstepx << 16;
- }
- else
+ } else
#endif
{
a_sstepxfrac = r_sstepx & 0xFFFF;
@@ -476,7 +460,7 @@ R_PolysetDrawThreshSpans8
Random fizzle fade rasterizer
================
*/
-void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage)
+void R_PolysetDrawThreshSpans8(spanpackage_t *pspanpackage)
{
int lcount;
byte *lpdest;
@@ -486,23 +470,18 @@ void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage)
int lzi;
short *lpz;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
@@ -511,14 +490,11 @@ void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage)
llight = pspanpackage->light;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
+ do {
+ if ((lzi >> 16) >= *lpz) {
rand1k_index = (rand1k_index + 1) & MASK_1K;
- if (rand1k[rand1k_index] <= r_affinetridesc.vis_thresh)
- {
+ if (rand1k[rand1k_index] <= r_affinetridesc.vis_thresh) {
*lpdest = ((byte *)vid.colormap)[*lptex + (llight & 0xFF00)];
*lpz = lzi >> 16;
}
@@ -533,8 +509,7 @@ void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage)
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
- if (ltfrac & 0x10000)
- {
+ if (ltfrac & 0x10000) {
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
@@ -551,7 +526,7 @@ void R_PolysetDrawThreshSpans8 (spanpackage_t *pspanpackage)
R_PolysetDrawSpans8
================
*/
-void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
+void R_PolysetDrawSpans8_33(spanpackage_t *pspanpackage)
{
int lcount;
byte *lpdest;
@@ -561,23 +536,18 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
int lzi;
short *lpz;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
@@ -586,13 +556,11 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
llight = pspanpackage->light;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
- int temp = vid.colormap[*lptex + ( llight & 0xFF00 )];
+ do {
+ if ((lzi >> 16) >= *lpz) {
+ int temp = vid.colormap[*lptex + (llight & 0xFF00)];
- *lpdest = vid.alphamap[temp+ *lpdest*256];
+ *lpdest = vid.alphamap[temp + *lpdest * 256];
}
lpdest++;
lzi += r_zistepx;
@@ -603,8 +571,7 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
- if (ltfrac & 0x10000)
- {
+ if (ltfrac & 0x10000) {
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
@@ -615,39 +582,32 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
} while (pspanpackage->count != -999999);
}
-void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage)
+void R_PolysetDrawSpansConstant8_33(spanpackage_t *pspanpackage)
{
int lcount;
byte *lpdest;
int lzi;
short *lpz;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
lpz = pspanpackage->pz;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
- *lpdest = vid.alphamap[r_aliasblendcolor + *lpdest*256];
+ do {
+ if ((lzi >> 16) >= *lpz) {
+ *lpdest = vid.alphamap[r_aliasblendcolor + *lpdest * 256];
}
lpdest++;
lzi += r_zistepx;
@@ -669,23 +629,18 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage)
int lzi;
short *lpz;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
@@ -694,13 +649,11 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage)
llight = pspanpackage->light;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
- int temp = vid.colormap[*lptex + ( llight & 0xFF00 )];
+ do {
+ if ((lzi >> 16) >= *lpz) {
+ int temp = vid.colormap[*lptex + (llight & 0xFF00)];
- *lpdest = vid.alphamap[temp*256 + *lpdest];
+ *lpdest = vid.alphamap[temp * 256 + *lpdest];
*lpz = lzi >> 16;
}
lpdest++;
@@ -712,8 +665,7 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage)
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
- if (ltfrac & 0x10000)
- {
+ if (ltfrac & 0x10000) {
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
@@ -724,39 +676,32 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage)
} while (pspanpackage->count != -999999);
}
-void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage)
+void R_PolysetDrawSpansConstant8_66(spanpackage_t *pspanpackage)
{
int lcount;
byte *lpdest;
int lzi;
short *lpz;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
lpz = pspanpackage->pz;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
- *lpdest = vid.alphamap[r_aliasblendcolor*256 + *lpdest];
+ do {
+ if ((lzi >> 16) >= *lpz) {
+ *lpdest = vid.alphamap[r_aliasblendcolor * 256 + *lpdest];
}
lpdest++;
lzi += r_zistepx;
@@ -769,27 +714,22 @@ void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage)
}
#if !USE_ASM
-void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
+void R_PolysetDrawSpans8_Opaque(spanpackage_t *pspanpackage)
{
int lcount;
- do
- {
+ do {
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
- if (errorterm >= 0)
- {
+ if (errorterm >= 0) {
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
- }
- else
- {
+ } else {
d_aspancount += ubasestep;
}
- if (lcount)
- {
+ if (lcount) {
int lsfrac, ltfrac;
byte *lpdest;
byte *lptex;
@@ -805,12 +745,10 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
llight = pspanpackage->light;
lzi = pspanpackage->zi;
- do
- {
- if ((lzi >> 16) >= *lpz)
- {
+ do {
+ if ((lzi >> 16) >= *lpz) {
//PGM
- if(iractive)
+ if (iractive)
*lpdest = ((byte *)vid.colormap)[irtable[*lptex]];
else
*lpdest = ((byte *)vid.colormap)[*lptex + (llight & 0xFF00)];
@@ -826,8 +764,7 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
- if (ltfrac & 0x10000)
- {
+ if (ltfrac & 0x10000) {
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
@@ -845,7 +782,7 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
R_PolysetFillSpans8
================
*/
-void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
+void R_PolysetFillSpans8(spanpackage_t *pspanpackage)
{
int color;
@@ -853,8 +790,7 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
color = d_aflatcolor++;
- while (1)
- {
+ while (1) {
int lcount;
byte *lpdest;
@@ -863,12 +799,10 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
if (lcount == -1)
return;
- if (lcount)
- {
+ if (lcount) {
lpdest = pspanpackage->pdest;
- do
- {
+ do {
*lpdest++ = color;
} while (--lcount);
}
@@ -882,7 +816,7 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
R_RasterizeAliasPolySmooth
================
*/
-void R_RasterizeAliasPolySmooth (void)
+void R_RasterizeAliasPolySmooth(void)
{
int initialleftheight, initialrightheight;
int *plefttop, *prighttop, *pleftbottom, *prightbottom;
@@ -901,7 +835,7 @@ void R_RasterizeAliasPolySmooth (void)
// set the s, t, and light gradients, which are consistent across the triangle
// because being a triangle, things are affine
//
- R_PolysetCalcGradients (r_affinetridesc.skinwidth);
+ R_PolysetCalcGradients(r_affinetridesc.skinwidth);
//
// rasterize the polygon
//
@@ -915,14 +849,12 @@ void R_RasterizeAliasPolySmooth (void)
d_aspancount = plefttop[0] - prighttop[0];
d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
- (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
+ (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
d_sfrac = (plefttop[2] & 0xFFFF) << 16;
d_tfrac = (plefttop[3] & 0xFFFF) << 16;
- }
- else
+ } else
#endif
{
d_sfrac = plefttop[2] & 0xFFFF;
@@ -932,11 +864,10 @@ void R_RasterizeAliasPolySmooth (void)
d_zi = plefttop[5];
d_pdest = (byte *)d_viewbuffer +
- ystart * r_screenwidth + plefttop[0];
+ ystart * r_screenwidth + plefttop[0];
d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
- if (initialleftheight == 1)
- {
+ if (initialleftheight == 1) {
d_pedgespanpackage->pdest = d_pdest;
d_pedgespanpackage->pz = d_pz;
d_pedgespanpackage->count = d_aspancount;
@@ -945,24 +876,20 @@ void R_RasterizeAliasPolySmooth (void)
d_pedgespanpackage->sfrac = d_sfrac;
d_pedgespanpackage->tfrac = d_tfrac;
- // FIXME: need to clamp l, s, t, at both ends?
+ // FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
- }
- else
- {
+ } else {
R_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
- pleftbottom[0], pleftbottom[1]);
+ pleftbottom[0], pleftbottom[1]);
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
d_pzbasestep = (d_zwidth + ubasestep) << 1;
d_pzextrastep = d_pzbasestep + 2;
- }
- else
+ } else
#endif
{
d_pzbasestep = d_zwidth + ubasestep;
@@ -972,11 +899,11 @@ void R_RasterizeAliasPolySmooth (void)
d_pdestbasestep = r_screenwidth + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
- // TODO: can reuse partial expressions here
+ // TODO: can reuse partial expressions here
- // for negative steps in x along left edge, bias toward overflow rather than
- // underflow (sort of turning the floor () we did in the gradient calcs into
- // ceil (), but plus a little bit)
+ // for negative steps in x along left edge, bias toward overflow rather than
+ // underflow (sort of turning the floor () we did in the gradient calcs into
+ // ceil (), but plus a little bit)
if (ubasestep < 0)
working_lstepx = r_lstepx - 1;
else
@@ -984,15 +911,13 @@ void R_RasterizeAliasPolySmooth (void)
d_countextrastep = ubasestep + 1;
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
- ((r_tstepy + r_tstepx * ubasestep) >> 16) *
- r_affinetridesc.skinwidth;
+ ((r_tstepy + r_tstepx * ubasestep) >> 16) *
+ r_affinetridesc.skinwidth;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
- }
- else
+ } else
#endif
{
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
@@ -1002,29 +927,25 @@ void R_RasterizeAliasPolySmooth (void)
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
- ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
- r_affinetridesc.skinwidth;
+ ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
+ r_affinetridesc.skinwidth;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
- d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) << 16;
- d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) << 16;
- }
- else
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
+ d_sfracextrastep = (r_sstepy + r_sstepx * d_countextrastep) << 16;
+ d_tfracextrastep = (r_tstepy + r_tstepx * d_countextrastep) << 16;
+ } else
#endif
{
- d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) & 0xFFFF;
- d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) & 0xFFFF;
+ d_sfracextrastep = (r_sstepy + r_sstepx * d_countextrastep) & 0xFFFF;
+ d_tfracextrastep = (r_tstepy + r_tstepx * d_countextrastep) & 0xFFFF;
}
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
- R_PolysetScanLeftEdge (initialleftheight);
- }
- else
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
+ R_PolysetScanLeftEdge(initialleftheight);
+ } else
#endif
{
R_PolysetScanLeftEdge_C(initialleftheight);
@@ -1034,8 +955,7 @@ void R_RasterizeAliasPolySmooth (void)
//
// scan out the bottom part of the left edge, if it exists
//
- if (pedgetable->numleftedges == 2)
- {
+ if (pedgetable->numleftedges == 2) {
int height;
plefttop = pleftbottom;
@@ -1048,7 +968,7 @@ void R_RasterizeAliasPolySmooth (void)
ystart = plefttop[1];
d_aspancount = plefttop[0] - prighttop[0];
d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
- (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
+ (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
d_sfrac = 0;
d_tfrac = 0;
d_light = plefttop[4];
@@ -1057,8 +977,7 @@ void R_RasterizeAliasPolySmooth (void)
d_pdest = (byte *)d_viewbuffer + ystart * r_screenwidth + plefttop[0];
d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
- if (height == 1)
- {
+ if (height == 1) {
d_pedgespanpackage->pdest = d_pdest;
d_pedgespanpackage->pz = d_pz;
d_pedgespanpackage->count = d_aspancount;
@@ -1067,27 +986,23 @@ void R_RasterizeAliasPolySmooth (void)
d_pedgespanpackage->sfrac = d_sfrac;
d_pedgespanpackage->tfrac = d_tfrac;
- // FIXME: need to clamp l, s, t, at both ends?
+ // FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
- }
- else
- {
+ } else {
R_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
- pleftbottom[0], pleftbottom[1]);
+ pleftbottom[0], pleftbottom[1]);
d_pdestbasestep = r_screenwidth + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
d_pzbasestep = (d_zwidth + ubasestep) << 1;
d_pzextrastep = d_pzbasestep + 2;
- }
- else
+ } else
#endif
{
d_pzbasestep = d_zwidth + ubasestep;
@@ -1101,15 +1016,13 @@ void R_RasterizeAliasPolySmooth (void)
d_countextrastep = ubasestep + 1;
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
- ((r_tstepy + r_tstepx * ubasestep) >> 16) *
- r_affinetridesc.skinwidth;
+ ((r_tstepy + r_tstepx * ubasestep) >> 16) *
+ r_affinetridesc.skinwidth;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
- }
- else
+ } else
#endif
{
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
@@ -1119,29 +1032,25 @@ void R_RasterizeAliasPolySmooth (void)
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
- ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
- r_affinetridesc.skinwidth;
+ ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
+ r_affinetridesc.skinwidth;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
- d_sfracextrastep = ((r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF)<<16;
- d_tfracextrastep = ((r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF)<<16;
- }
- else
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
+ d_sfracextrastep = ((r_sstepy + r_sstepx * d_countextrastep) & 0xFFFF) << 16;
+ d_tfracextrastep = ((r_tstepy + r_tstepx * d_countextrastep) & 0xFFFF) << 16;
+ } else
#endif
{
- d_sfracextrastep = (r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF;
- d_tfracextrastep = (r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF;
+ d_sfracextrastep = (r_sstepy + r_sstepx * d_countextrastep) & 0xFFFF;
+ d_tfracextrastep = (r_tstepy + r_tstepx * d_countextrastep) & 0xFFFF;
}
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
#if USE_ASM
- if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
- {
- R_PolysetScanLeftEdge (height);
- }
- else
+ if (d_pdrawspans == R_PolysetDrawSpans8_Opaque) {
+ R_PolysetScanLeftEdge(height);
+ } else
#endif
{
R_PolysetScanLeftEdge_C(height);
@@ -1154,16 +1063,15 @@ void R_RasterizeAliasPolySmooth (void)
d_pedgespanpackage = a_spans;
R_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
- prightbottom[0], prightbottom[1]);
+ prightbottom[0], prightbottom[1]);
d_aspancount = 0;
d_countextrastep = ubasestep + 1;
originalcount = a_spans[initialrightheight].count;
a_spans[initialrightheight].count = -999999; // mark end of the spanpackages
- (*d_pdrawspans) (a_spans);
+ (*d_pdrawspans)(a_spans);
// scan out the bottom part of the right edge, if it exists
- if (pedgetable->numrightedges == 2)
- {
+ if (pedgetable->numrightedges == 2) {
int height;
spanpackage_t *pstart;
@@ -1178,12 +1086,12 @@ void R_RasterizeAliasPolySmooth (void)
height = prightbottom[1] - prighttop[1];
R_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
- prightbottom[0], prightbottom[1]);
+ prightbottom[0], prightbottom[1]);
d_countextrastep = ubasestep + 1;
a_spans[initialrightheight + height].count = -999999;
- // mark end of the spanpackages
- (*d_pdrawspans) (pstart);
+ // mark end of the spanpackages
+ (*d_pdrawspans)(pstart);
}
}
@@ -1193,45 +1101,38 @@ void R_RasterizeAliasPolySmooth (void)
R_PolysetSetEdgeTable
================
*/
-void R_PolysetSetEdgeTable (void)
+void R_PolysetSetEdgeTable(void)
{
int edgetableindex;
edgetableindex = 0; // assume the vertices are already in
- // top to bottom order
+ // top to bottom order
//
// determine which edges are right & left, and the order in which
// to rasterize them
//
- if (r_p0[1] >= r_p1[1])
- {
- if (r_p0[1] == r_p1[1])
- {
+ if (r_p0[1] >= r_p1[1]) {
+ if (r_p0[1] == r_p1[1]) {
if (r_p0[1] < r_p2[1])
pedgetable = &edgetables[2];
else
pedgetable = &edgetables[5];
return;
- }
- else
- {
+ } else {
edgetableindex = 1;
}
}
- if (r_p0[1] == r_p2[1])
- {
+ if (r_p0[1] == r_p2[1]) {
if (edgetableindex)
pedgetable = &edgetables[8];
else
pedgetable = &edgetables[9];
return;
- }
- else if (r_p1[1] == r_p2[1])
- {
+ } else if (r_p1[1] == r_p2[1]) {
if (edgetableindex)
pedgetable = &edgetables[10];
else
diff --git a/src/sw_protect.c b/src/sw_protect.c
index 6b9ce40..d144e97 100644
--- a/src/sw_protect.c
+++ b/src/sw_protect.c
@@ -14,7 +14,8 @@
Sys_MakeCodeWriteable
================
*/
-void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) {
+void Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length)
+{
#ifdef _WIN32
DWORD flOldProtect;
@@ -25,11 +26,11 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) {
unsigned long addr;
int psize = getpagesize();
- addr = (startaddr & ~(psize-1)) - psize;
+ addr = (startaddr & ~(psize - 1)) - psize;
r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
if (r < 0)
- Com_Error( ERR_FATAL, "Protection change failed\n");
+ Com_Error(ERR_FATAL, "Protection change failed\n");
#endif
}
diff --git a/src/sw_rast.c b/src/sw_rast.c
index c563fb8..8b70c9c 100644
--- a/src/sw_rast.c
+++ b/src/sw_rast.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -57,7 +57,7 @@ qboolean r_lastvertvalid;
R_EmitEdge
================
*/
-void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
+void R_EmitEdge(mvertex_t *pv0, mvertex_t *pv1)
{
edge_t *edge, *pcheck;
int u_check;
@@ -68,49 +68,46 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
float scale, lzi0, u0, v0;
int side;
- if (r_lastvertvalid)
- {
+ if (r_lastvertvalid) {
u0 = r_u1;
v0 = r_v1;
lzi0 = r_lzi1;
ceilv0 = r_ceilv1;
- }
- else
- {
+ } else {
world = &pv0->point[0];
-
- // transform and project
- VectorSubtract (world, modelorg, local);
- TransformVector (local, transformed);
-
+
+ // transform and project
+ VectorSubtract(world, modelorg, local);
+ TransformVector(local, transformed);
+
if (transformed[2] < NEAR_CLIP)
transformed[2] = NEAR_CLIP;
-
+
lzi0 = 1.0 / transformed[2];
-
- // FIXME: build x/yscale into transform?
+
+ // FIXME: build x/yscale into transform?
scale = xscale * lzi0;
- u0 = (xcenter + scale*transformed[0]);
+ u0 = (xcenter + scale * transformed[0]);
if (u0 < r_refdef.fvrectx_adj)
u0 = r_refdef.fvrectx_adj;
if (u0 > r_refdef.fvrectright_adj)
u0 = r_refdef.fvrectright_adj;
-
+
scale = yscale * lzi0;
- v0 = (ycenter - scale*transformed[1]);
+ v0 = (ycenter - scale * transformed[1]);
if (v0 < r_refdef.fvrecty_adj)
v0 = r_refdef.fvrecty_adj;
if (v0 > r_refdef.fvrectbottom_adj)
v0 = r_refdef.fvrectbottom_adj;
-
+
ceilv0 = (int) ceil(v0);
}
world = &pv1->point[0];
// transform and project
- VectorSubtract (world, modelorg, local);
- TransformVector (local, transformed);
+ VectorSubtract(world, modelorg, local);
+ TransformVector(local, transformed);
if (transformed[2] < NEAR_CLIP)
transformed[2] = NEAR_CLIP;
@@ -118,14 +115,14 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
r_lzi1 = 1.0 / transformed[2];
scale = xscale * r_lzi1;
- r_u1 = (xcenter + scale*transformed[0]);
+ r_u1 = (xcenter + scale * transformed[0]);
if (r_u1 < r_refdef.fvrectx_adj)
r_u1 = r_refdef.fvrectx_adj;
if (r_u1 > r_refdef.fvrectright_adj)
r_u1 = r_refdef.fvrectright_adj;
scale = yscale * r_lzi1;
- r_v1 = (ycenter - scale*transformed[1]);
+ r_v1 = (ycenter - scale * transformed[1]);
if (r_v1 < r_refdef.fvrecty_adj)
r_v1 = r_refdef.fvrecty_adj;
if (r_v1 > r_refdef.fvrectbottom_adj)
@@ -147,13 +144,11 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
// create the edge
- if (ceilv0 == r_ceilv1)
- {
- // we cache unclipped horizontal edges as fully clipped
- if (cacheoffset != 0x7FFFFFFF)
- {
+ if (ceilv0 == r_ceilv1) {
+ // we cache unclipped horizontal edges as fully clipped
+ if (cacheoffset != 0x7FFFFFFF) {
cacheoffset = FULLY_CLIPPED_CACHED |
- (r_framecount & FRAMECOUNT_MASK);
+ (r_framecount & FRAMECOUNT_MASK);
}
return; // horizontal edge
@@ -167,9 +162,8 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
edge->nearzi = lzi0;
- if (side == 0)
- {
- // trailing edge (go from p1 to p2)
+ if (side == 0) {
+ // trailing edge (go from p1 to p2)
v = ceilv0;
v2 = r_ceilv1 - 1;
@@ -178,10 +172,8 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
u_step = ((r_u1 - u0) / (r_v1 - v0));
u = u0 + ((float)v - v0) * u_step;
- }
- else
- {
- // leading edge (go from p2 to p1)
+ } else {
+ // leading edge (go from p2 to p1)
v2 = ceilv0 - 1;
v = r_ceilv1;
@@ -192,8 +184,8 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
u = r_u1 + ((float)v - r_v1) * u_step;
}
- edge->u_step = u_step*0x100000;
- edge->u = u*0x100000 + 0xFFFFF;
+ edge->u_step = u_step * 0x100000;
+ edge->u = u * 0x100000 + 0xFFFFF;
// we need to do this to avoid stepping off the edges if a very nearly
// horizontal edge is less than epsilon above a scan, and numeric error causes
@@ -212,13 +204,10 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
if (edge->surfs[0])
u_check++; // sort trailers after leaders
- if (!newedges[v] || newedges[v]->u >= u_check)
- {
+ if (!newedges[v] || newedges[v]->u >= u_check) {
edge->next = newedges[v];
newedges[v] = edge;
- }
- else
- {
+ } else {
pcheck = newedges[v];
while (pcheck->next && pcheck->next->u < u_check)
pcheck = pcheck->next;
@@ -236,96 +225,85 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
R_ClipEdge
================
*/
-void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip)
+void R_ClipEdge(mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip)
{
float d0, d1, f;
mvertex_t clipvert;
- for( ; clip; clip = clip->next ) {
- d0 = DotProduct (pv0->point, clip->normal) - clip->dist;
- d1 = DotProduct (pv1->point, clip->normal) - clip->dist;
+ for (; clip; clip = clip->next) {
+ d0 = DotProduct(pv0->point, clip->normal) - clip->dist;
+ d1 = DotProduct(pv1->point, clip->normal) - clip->dist;
- if (d0 >= 0)
- {
- // point 0 is unclipped
- if (d1 >= 0)
- {
- // both points are unclipped
+ if (d0 >= 0) {
+ // point 0 is unclipped
+ if (d1 >= 0) {
+ // both points are unclipped
continue;
}
- // only point 1 is clipped
+ // only point 1 is clipped
- // we don't cache clipped edges
+ // we don't cache clipped edges
cacheoffset = 0x7FFFFFFF;
f = d0 / (d0 - d1);
clipvert.point[0] = pv0->point[0] +
- f * (pv1->point[0] - pv0->point[0]);
+ f * (pv1->point[0] - pv0->point[0]);
clipvert.point[1] = pv0->point[1] +
- f * (pv1->point[1] - pv0->point[1]);
+ f * (pv1->point[1] - pv0->point[1]);
clipvert.point[2] = pv0->point[2] +
- f * (pv1->point[2] - pv0->point[2]);
+ f * (pv1->point[2] - pv0->point[2]);
- if (clip->leftedge)
- {
+ if (clip->leftedge) {
r_leftclipped = qtrue;
r_leftexit = clipvert;
- }
- else if (clip->rightedge)
- {
+ } else if (clip->rightedge) {
r_rightclipped = qtrue;
r_rightexit = clipvert;
}
- R_ClipEdge (pv0, &clipvert, clip->next);
+ R_ClipEdge(pv0, &clipvert, clip->next);
return;
- }
- else
- {
- // point 0 is clipped
- if (d1 < 0)
- {
- // both points are clipped
- // we do cache fully clipped edges
+ } else {
+ // point 0 is clipped
+ if (d1 < 0) {
+ // both points are clipped
+ // we do cache fully clipped edges
if (!r_leftclipped)
cacheoffset = FULLY_CLIPPED_CACHED |
- (r_framecount & FRAMECOUNT_MASK);
+ (r_framecount & FRAMECOUNT_MASK);
return;
}
- // only point 0 is clipped
+ // only point 0 is clipped
r_lastvertvalid = qfalse;
- // we don't cache partially clipped edges
+ // we don't cache partially clipped edges
cacheoffset = 0x7FFFFFFF;
f = d0 / (d0 - d1);
clipvert.point[0] = pv0->point[0] +
- f * (pv1->point[0] - pv0->point[0]);
+ f * (pv1->point[0] - pv0->point[0]);
clipvert.point[1] = pv0->point[1] +
- f * (pv1->point[1] - pv0->point[1]);
+ f * (pv1->point[1] - pv0->point[1]);
clipvert.point[2] = pv0->point[2] +
- f * (pv1->point[2] - pv0->point[2]);
+ f * (pv1->point[2] - pv0->point[2]);
- if (clip->leftedge)
- {
+ if (clip->leftedge) {
r_leftclipped = qtrue;
r_leftenter = clipvert;
- }
- else if (clip->rightedge)
- {
+ } else if (clip->rightedge) {
r_rightclipped = qtrue;
r_rightenter = clipvert;
}
- R_ClipEdge (&clipvert, pv1, clip->next);
+ R_ClipEdge(&clipvert, pv1, clip->next);
return;
}
}
// add the edge
- R_EmitEdge (pv0, pv1);
+ R_EmitEdge(pv0, pv1);
}
#endif // !USE_ASM
@@ -336,7 +314,7 @@ void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip)
R_EmitCachedEdge
================
*/
-void R_EmitCachedEdge (void)
+void R_EmitCachedEdge(void)
{
edge_t *pedge_t;
@@ -359,7 +337,7 @@ void R_EmitCachedEdge (void)
R_RenderFace
================
*/
-void R_RenderFace (mface_t *fa, int clipflags)
+void R_RenderFace(mface_t *fa, int clipflags)
{
int i;
unsigned mask;
@@ -372,8 +350,7 @@ void R_RenderFace (mface_t *fa, int clipflags)
qboolean makeleftedge, makerightedge;
// translucent surfaces are not drawn by the edge renderer
- if (fa->texinfo->c.flags & (SURF_TRANS33|SURF_TRANS66))
- {
+ if (fa->texinfo->c.flags & (SURF_TRANS33 | SURF_TRANS66)) {
fa->next = r_alpha_surfaces;
r_alpha_surfaces = fa;
return;
@@ -381,22 +358,19 @@ void R_RenderFace (mface_t *fa, int clipflags)
// sky surfaces encountered in the world will cause the
// environment box surfaces to be emited
- if ( fa->texinfo->c.flags & SURF_SKY )
- {
- R_EmitSkyBox ();
+ if (fa->texinfo->c.flags & SURF_SKY) {
+ R_EmitSkyBox();
return;
}
// skip out if no more surfs
- if ((surface_p) >= surf_max)
- {
+ if ((surface_p) >= surf_max) {
r_outofsurfaces++;
return;
}
// ditto if not enough edges left, or switch to auxedges if possible
- if ((edge_p + fa->numsurfedges + 4) >= edge_max)
- {
+ if ((edge_p + fa->numsurfedges + 4) >= edge_max) {
r_outofedges += fa->numsurfedges;
return;
}
@@ -406,10 +380,8 @@ void R_RenderFace (mface_t *fa, int clipflags)
// set up clip planes
pclip = NULL;
- for (i=3, mask = 0x08 ; i>=0 ; i--, mask >>= 1)
- {
- if (clipflags & mask)
- {
+ for (i = 3, mask = 0x08; i >= 0; i--, mask >>= 1) {
+ if (clipflags & mask) {
view_clipplanes[i].next = pclip;
pclip = &view_clipplanes[i];
}
@@ -423,42 +395,35 @@ void R_RenderFace (mface_t *fa, int clipflags)
r_lastvertvalid = qfalse;
surfedge = fa->firstsurfedge;
- for (i=0 ; i<fa->numsurfedges ; i++, surfedge++)
- {
+ for (i = 0; i < fa->numsurfedges; i++, surfedge++) {
r_pedge = surfedge->edge;
- // if the edge is cached, we can just reuse the edge
- if (!insubmodel)
- {
- if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED)
- {
+ // if the edge is cached, we can just reuse the edge
+ if (!insubmodel) {
+ if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED) {
if ((r_pedge->cachededgeoffset & FRAMECOUNT_MASK) ==
- r_framecount)
- {
+ r_framecount) {
r_lastvertvalid = qfalse;
continue;
}
- }
- else
- {
+ } else {
if ((((unsigned long)edge_p - (unsigned long)r_edges) >
r_pedge->cachededgeoffset) &&
(((edge_t *)((unsigned long)r_edges +
- r_pedge->cachededgeoffset))->owner == r_pedge))
- {
- R_EmitCachedEdge ();
+ r_pedge->cachededgeoffset))->owner == r_pedge)) {
+ R_EmitCachedEdge();
r_lastvertvalid = qfalse;
continue;
}
}
}
- // assume it's cacheable
+ // assume it's cacheable
cacheoffset = (byte *)edge_p - (byte *)r_edges;
r_leftclipped = r_rightclipped = qfalse;
- R_ClipEdge (r_pedge->v[surfedge->vert ],
- r_pedge->v[surfedge->vert ^ 1],
- pclip);
+ R_ClipEdge(r_pedge->v[surfedge->vert ],
+ r_pedge->v[surfedge->vert ^ 1],
+ pclip);
r_pedge->cachededgeoffset = cacheoffset;
if (r_leftclipped)
@@ -471,20 +436,18 @@ void R_RenderFace (mface_t *fa, int clipflags)
// if there was a clip off the left edge, add that edge too
// FIXME: faster to do in screen space?
// FIXME: share clipped edges?
- if (makeleftedge)
- {
+ if (makeleftedge) {
r_pedge = &tedge;
r_lastvertvalid = qfalse;
- R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next);
+ R_ClipEdge(&r_leftexit, &r_leftenter, pclip->next);
}
// if there was a clip off the right edge, get the right r_nearzi
- if (makerightedge)
- {
+ if (makerightedge) {
r_pedge = &tedge;
r_lastvertvalid = qfalse;
r_nearzionly = qtrue;
- R_ClipEdge (&r_rightexit, &r_rightenter, view_clipplanes[1].next);
+ R_ClipEdge(&r_rightexit, &r_rightenter, view_clipplanes[1].next);
}
// if no edges made it out, return without posting the surface
@@ -504,15 +467,15 @@ void R_RenderFace (mface_t *fa, int clipflags)
pplane = fa->plane;
// FIXME: cache this?
- TransformVector (pplane->normal, p_normal);
+ TransformVector(pplane->normal, p_normal);
// FIXME: cache this?
- distinv = 1.0 / (pplane->dist - DotProduct (modelorg, pplane->normal));
+ distinv = 1.0 / (pplane->dist - DotProduct(modelorg, pplane->normal));
surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv;
surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv;
surface_p->d_ziorigin = p_normal[2] * distinv -
- xcenter * surface_p->d_zistepu -
- ycenter * surface_p->d_zistepv;
+ xcenter * surface_p->d_zistepu -
+ ycenter * surface_p->d_zistepv;
surface_p++;
}
@@ -523,7 +486,7 @@ void R_RenderFace (mface_t *fa, int clipflags)
R_RenderBmodelFace
================
*/
-void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
+void R_RenderBmodelFace(bedge_t *pedges, mface_t *psurf)
{
int i;
unsigned mask;
@@ -534,23 +497,20 @@ void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
clipplane_t *pclip;
qboolean makeleftedge, makerightedge;
- if (psurf->texinfo->c.flags & (SURF_TRANS33|SURF_TRANS66))
- {
+ if (psurf->texinfo->c.flags & (SURF_TRANS33 | SURF_TRANS66)) {
psurf->next = r_alpha_surfaces;
r_alpha_surfaces = psurf;
return;
}
// skip out if no more surfs
- if (surface_p >= surf_max)
- {
+ if (surface_p >= surf_max) {
r_outofsurfaces++;
return;
}
// ditto if not enough edges left, or switch to auxedges if possible
- if ((edge_p + psurf->numsurfedges + 4) >= edge_max)
- {
+ if ((edge_p + psurf->numsurfedges + 4) >= edge_max) {
r_outofedges += psurf->numsurfedges;
return;
}
@@ -563,10 +523,8 @@ void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
// set up clip planes
pclip = NULL;
- for (i=3, mask = 0x08 ; i>=0 ; i--, mask >>= 1)
- {
- if (r_clipflags & mask)
- {
+ for (i = 3, mask = 0x08; i >= 0; i--, mask >>= 1) {
+ if (r_clipflags & mask) {
view_clipplanes[i].next = pclip;
pclip = &view_clipplanes[i];
}
@@ -581,10 +539,9 @@ void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
// can be used?
r_lastvertvalid = qfalse;
- for ( ; pedges ; pedges = pedges->pnext)
- {
+ for (; pedges; pedges = pedges->pnext) {
r_leftclipped = r_rightclipped = qfalse;
- R_ClipEdge (pedges->v[0], pedges->v[1], pclip);
+ R_ClipEdge(pedges->v[0], pedges->v[1], pclip);
if (r_leftclipped)
makeleftedge = qtrue;
@@ -595,18 +552,16 @@ void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
// if there was a clip off the left edge, add that edge too
// FIXME: faster to do in screen space?
// FIXME: share clipped edges?
- if (makeleftedge)
- {
+ if (makeleftedge) {
r_pedge = &tedge;
- R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next);
+ R_ClipEdge(&r_leftexit, &r_leftenter, pclip->next);
}
// if there was a clip off the right edge, get the right r_nearzi
- if (makerightedge)
- {
+ if (makerightedge) {
r_pedge = &tedge;
r_nearzionly = qtrue;
- R_ClipEdge (&r_rightexit, &r_rightenter, view_clipplanes[1].next);
+ R_ClipEdge(&r_rightexit, &r_rightenter, view_clipplanes[1].next);
}
// if no edges made it out, return without posting the surface
@@ -626,15 +581,15 @@ void R_RenderBmodelFace (bedge_t *pedges, mface_t *psurf)
pplane = psurf->plane;
// FIXME: cache this?
- TransformVector (pplane->normal, p_normal);
+ TransformVector(pplane->normal, p_normal);
// FIXME: cache this?
- distinv = 1.0 / (pplane->dist - DotProduct (modelorg, pplane->normal));
+ distinv = 1.0 / (pplane->dist - DotProduct(modelorg, pplane->normal));
surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv;
surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv;
surface_p->d_ziorigin = p_normal[2] * distinv -
- xcenter * surface_p->d_zistepu -
- ycenter * surface_p->d_zistepv;
+ xcenter * surface_p->d_zistepu -
+ ycenter * surface_p->d_zistepv;
surface_p++;
}
diff --git a/src/sw_scan.c b/src/sw_scan.c
index 16754ed..1687bf9 100644
--- a/src/sw_scan.c
+++ b/src/sw_scan.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
int *r_turb_turb;
int r_turb_spancount;
-void D_DrawTurbulent8Span (void);
+void D_DrawTurbulent8Span(void);
/*
@@ -39,54 +39,49 @@ this performs a slight compression of the screen at the same time as
the sine warp, to keep the edges from wrapping
=============
*/
-void D_WarpScreen (void)
+void D_WarpScreen(void)
{
int w, h;
- int u,v, u2, v2;
+ int u, v, u2, v2;
byte *dest;
int *turb;
int *col;
byte **row;
static int cached_width, cached_height;
- static byte *rowptr[MAXHEIGHT*2+AMP2*2];
- static int column[MAXWIDTH*2+AMP2*2];
+ static byte *rowptr[MAXHEIGHT * 2 + AMP2 * 2];
+ static int column[MAXWIDTH * 2 + AMP2 * 2];
//
// these are constant over resolutions, and can be saved
//
w = r_newrefdef.width;
h = r_newrefdef.height;
- if (w != cached_width || h != cached_height)
- {
+ if (w != cached_width || h != cached_height) {
cached_width = w;
cached_height = h;
- for (v=0 ; v<h+AMP2*2 ; v++)
- {
- v2 = (int)((float)v/(h + AMP2 * 2) * r_refdef.vrect.height);
+ for (v = 0; v < h + AMP2 * 2; v++) {
+ v2 = (int)((float)v / (h + AMP2 * 2) * r_refdef.vrect.height);
rowptr[v] = r_warpbuffer + (WARP_WIDTH * v2);
}
- for (u=0 ; u<w+AMP2*2 ; u++)
- {
- u2 = (int)((float)u/(w + AMP2 * 2) * r_refdef.vrect.width);
+ for (u = 0; u < w + AMP2 * 2; u++) {
+ u2 = (int)((float)u / (w + AMP2 * 2) * r_refdef.vrect.width);
column[u] = u2;
}
}
- turb = intsintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
+ turb = intsintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1));
dest = vid.buffer + r_newrefdef.y * vid.rowbytes + r_newrefdef.x;
- for (v=0 ; v<h ; v++, dest += vid.rowbytes)
- {
- col = &column[turb[v&(CYCLE-1)]];
+ for (v = 0; v < h; v++, dest += vid.rowbytes) {
+ col = &column[turb[v & (CYCLE - 1)]];
row = &rowptr[v];
- for (u=0 ; u<w ; u+=4)
- {
- dest[u+0] = row[turb[(u+0)&(CYCLE-1)]][col[u+0]];
- dest[u+1] = row[turb[(u+1)&(CYCLE-1)]][col[u+1]];
- dest[u+2] = row[turb[(u+2)&(CYCLE-1)]][col[u+2]];
- dest[u+3] = row[turb[(u+3)&(CYCLE-1)]][col[u+3]];
+ for (u = 0; u < w; u += 4) {
+ dest[u + 0] = row[turb[(u + 0) & (CYCLE - 1)]][col[u + 0]];
+ dest[u + 1] = row[turb[(u + 1) & (CYCLE - 1)]][col[u + 1]];
+ dest[u + 2] = row[turb[(u + 2) & (CYCLE - 1)]][col[u + 2]];
+ dest[u + 3] = row[turb[(u + 3) & (CYCLE - 1)]][col[u + 3]];
}
}
}
@@ -99,15 +94,14 @@ void D_WarpScreen (void)
D_DrawTurbulent8Span
=============
*/
-void D_DrawTurbulent8Span (void)
+void D_DrawTurbulent8Span(void)
{
int sturb, tturb;
- do
- {
- sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63;
- *r_turb_pdest++ = *(r_turb_pbase + (tturb<<6) + sturb);
+ do {
+ sturb = ((r_turb_s + r_turb_turb[(r_turb_t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((r_turb_t + r_turb_turb[(r_turb_s >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ *r_turb_pdest++ = *(r_turb_pbase + (tturb << 6) + sturb);
r_turb_s += r_turb_sstep;
r_turb_t += r_turb_tstep;
} while (--r_turb_spancount > 0);
@@ -121,14 +115,14 @@ void D_DrawTurbulent8Span (void)
Turbulent8
=============
*/
-void Turbulent8 (espan_t *pspan)
+void Turbulent8(espan_t *pspan)
{
int count;
fixed16_t snext, tnext;
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
-
- r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
+
+ r_turb_turb = sintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1));
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
@@ -139,20 +133,19 @@ void Turbulent8 (espan_t *pspan)
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
- do
- {
+ do {
r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
r_turb_s = (int)(sdivz * z) + sadjust;
@@ -167,9 +160,8 @@ void Turbulent8 (espan_t *pspan)
else if (r_turb_t < 0)
r_turb_t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
else
@@ -177,10 +169,9 @@ void Turbulent8 (espan_t *pspan)
count -= r_turb_spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
@@ -191,8 +182,8 @@ void Turbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -202,13 +193,11 @@ void Turbulent8 (espan_t *pspan)
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(r_turb_spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -219,8 +208,8 @@ void Turbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -228,17 +217,16 @@ void Turbulent8 (espan_t *pspan)
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
- if (r_turb_spancount > 1)
- {
+ if (r_turb_spancount > 1) {
r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
}
}
- r_turb_s = r_turb_s & ((CYCLE<<16)-1);
- r_turb_t = r_turb_t & ((CYCLE<<16)-1);
+ r_turb_s = r_turb_s & ((CYCLE << 16) - 1);
+ r_turb_t = r_turb_t & ((CYCLE << 16) - 1);
- D_DrawTurbulent8Span ();
+ D_DrawTurbulent8Span();
r_turb_s = snext;
r_turb_t = tnext;
@@ -256,13 +244,13 @@ NonTurbulent8 - this is for drawing scrolling textures. they're warping water te
but the turbulence is automatically 0.
=============
*/
-void NonTurbulent8 (espan_t *pspan)
+void NonTurbulent8(espan_t *pspan)
{
int count;
fixed16_t snext, tnext;
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
-
+
// r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
r_turb_turb = blanktable;
@@ -275,20 +263,19 @@ void NonTurbulent8 (espan_t *pspan)
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
- do
- {
+ do {
r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
r_turb_s = (int)(sdivz * z) + sadjust;
@@ -303,9 +290,8 @@ void NonTurbulent8 (espan_t *pspan)
else if (r_turb_t < 0)
r_turb_t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
else
@@ -313,10 +299,9 @@ void NonTurbulent8 (espan_t *pspan)
count -= r_turb_spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
@@ -327,8 +312,8 @@ void NonTurbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -338,13 +323,11 @@ void NonTurbulent8 (espan_t *pspan)
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(r_turb_spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -355,8 +338,8 @@ void NonTurbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -364,17 +347,16 @@ void NonTurbulent8 (espan_t *pspan)
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
- if (r_turb_spancount > 1)
- {
+ if (r_turb_spancount > 1) {
r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
}
}
- r_turb_s = r_turb_s & ((CYCLE<<16)-1);
- r_turb_t = r_turb_t & ((CYCLE<<16)-1);
+ r_turb_s = r_turb_s & ((CYCLE << 16) - 1);
+ r_turb_t = r_turb_t & ((CYCLE << 16) - 1);
- D_DrawTurbulent8Span ();
+ D_DrawTurbulent8Span();
r_turb_s = snext;
r_turb_t = tnext;
@@ -396,7 +378,7 @@ D_DrawSpans16
FIXME: actually make this subdivide by 16 instead of 8!!!
=============
*/
-void D_DrawSpans16 (espan_t *pspan)
+void D_DrawSpans16(espan_t *pspan)
{
int count, spancount;
unsigned char *pbase, *pdest;
@@ -413,20 +395,19 @@ void D_DrawSpans16 (espan_t *pspan)
tdivz8stepu = d_tdivzstepu * 8;
zi8stepu = d_zistepu * 8;
- do
- {
+ do {
pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
s = (int)(sdivz * z) + sadjust;
@@ -441,9 +422,8 @@ void D_DrawSpans16 (espan_t *pspan)
else if (t < 0)
t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 8)
spancount = 8;
else
@@ -451,10 +431,9 @@ void D_DrawSpans16 (espan_t *pspan)
count -= spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz8stepu;
tdivz += tdivz8stepu;
zi += zi8stepu;
@@ -465,8 +444,8 @@ void D_DrawSpans16 (espan_t *pspan)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -476,13 +455,11 @@ void D_DrawSpans16 (espan_t *pspan)
sstep = (snext - s) >> 3;
tstep = (tnext - t) >> 3;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -493,8 +470,8 @@ void D_DrawSpans16 (espan_t *pspan)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -502,15 +479,13 @@ void D_DrawSpans16 (espan_t *pspan)
else if (tnext < 8)
tnext = 8; // guard against round-off error on <0 steps
- if (spancount > 1)
- {
+ if (spancount > 1) {
sstep = (snext - s) / (spancount - 1);
tstep = (tnext - t) / (spancount - 1);
}
}
- do
- {
+ do {
*pdest++ = *(pbase + (s >> 16) + (t >> 16) * cachewidth);
s += sstep;
t += tstep;
@@ -530,7 +505,7 @@ void D_DrawSpans16 (espan_t *pspan)
D_DrawZSpans
=============
*/
-void D_DrawZSpans (espan_t *pspan)
+void D_DrawZSpans(espan_t *pspan)
{
int count, doublecount, izistep;
int izi;
@@ -543,31 +518,27 @@ void D_DrawZSpans (espan_t *pspan)
// we count on FP exceptions being turned off to avoid range problems
izistep = (int)(d_zistepu * 0x8000 * 0x10000);
- do
- {
+ do {
pdest = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u;
count = pspan->count;
- // calculate the initial 1/z
+ // calculate the initial 1/z
du = (float)pspan->u;
dv = (float)pspan->v;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
- // we count on FP exceptions being turned off to avoid range problems
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
+ // we count on FP exceptions being turned off to avoid range problems
izi = (int)(zi * 0x8000 * 0x10000);
- if ((long)pdest & 0x02)
- {
+ if ((long)pdest & 0x02) {
*pdest++ = (short)(izi >> 16);
izi += izistep;
count--;
}
- if ((doublecount = count >> 1) > 0)
- {
- do
- {
+ if ((doublecount = count >> 1) > 0) {
+ do {
ltemp = izi >> 16;
izi += izistep;
ltemp |= izi & 0xFFFF0000;
diff --git a/src/sw_sird.c b/src/sw_sird.c
index 8e376d0..2213aac 100644
--- a/src/sw_sird.c
+++ b/src/sw_sird.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -79,22 +79,18 @@ byte r_SIRDrandValues[] = {
// search to find the index of the highest set bit.
//You could also expand the loop 4 times to remove
// the 'while'
-#if !id386 || !( defined _MSC_VER )
+#if !id386 || !(defined _MSC_VER)
int UShortLog(int val)
{
int mask = 0xff00;
int p = 0;
int b = 8;
- while (b)
- {
- if (val & mask)
- {
+ while (b) {
+ if (val & mask) {
p += b;
b >>= 1;
mask &= (mask << b);
- }
- else
- {
+ } else {
mask &= (mask << (b >> 1));
mask >>= b;
b >>= 1;
@@ -112,15 +108,13 @@ int R_SIRDZFunc(int sub)
if (sub == R_SIRD_ZofSky)
return 0;
-#if id386 && ( defined _MSC_VER )
+#if id386 && (defined _MSC_VER)
e = sub;
//calculate the log (base 2) of the number. In other
//words the index of the highest set bit. bsr is undefined
//if it's input is 0, so special case that.
- if (e!=0)
- {
- __asm
- {
+ if (e != 0) {
+ __asm {
mov ebx, e
bsr eax, ebx
mov e, eax
@@ -137,15 +131,11 @@ int R_SIRDZFunc(int sub)
// based on the power, shift the z so that
// it's as high as it can get while still staying
// under 0x100
- if (e > 8)
- {
- sub >>= (e-8);
- }
- else
- {
- if (e < 8)
- {
- sub <<= (8-e);
+ if (e > 8) {
+ sub >>= (e - 8);
+ } else {
+ if (e < 8) {
+ sub <<= (8 - e);
}
}
@@ -161,10 +151,10 @@ int R_SIRDZFunc(int sub)
e += ((sub * R_SIRDstepsPerExponent) >> 8);
//make sure we stay under maximum height.
- return ((e<=R_SIRDmaxDiff)? e : R_SIRDmaxDiff );
+ return ((e <= R_SIRDmaxDiff) ? e : R_SIRDmaxDiff);
}
-void R_ApplySIRDAlgorithum( void )
+void R_ApplySIRDAlgorithum(void)
{
short* curz, *oldz;
short cz = 0, lastz = 0;
@@ -182,20 +172,17 @@ void R_ApplySIRDAlgorithum( void )
//basically done by shifting the values around
//each time and xoring them with a randomly
//selected pixel
- for (i=0; i<R_SIRDw * R_SIRDh; i++)
- {
- if ((i%R_SIRDnumRand)==0)
- {
- ji++;
+ for (i = 0; i < R_SIRDw * R_SIRDh; i++) {
+ if ((i % R_SIRDnumRand) == 0) {
+ ji++;
ji %= R_SIRDnumRand;
j = r_SIRDrandValues[r_SIRDrandValues[ji] % R_SIRDnumRand];
}
- r_SIRDBackground[i] = r_SIRDrandValues[ (i%R_SIRDnumRand) ] ^ j;
+ r_SIRDBackground[i] = r_SIRDrandValues[(i % R_SIRDnumRand) ] ^ j;
}
//if we are under water:
- if ((r_dowarp) && (vid.width != WARP_WIDTH))
- {
+ if ((r_dowarp) && (vid.width != WARP_WIDTH)) {
//the rendering is only in the top left
//WARP_WIDTH by WARP_HEIGHT area, so scale the z-values
//to span over the whole screen
@@ -205,14 +192,12 @@ void R_ApplySIRDAlgorithum( void )
//values before we read from them
zinc = ((WARP_WIDTH * 0x10000) / vid.width);
- for (y=vid.height-1; y>=0; y--)
- {
+ for (y = vid.height - 1; y >= 0; y--) {
curz = (d_pzbuffer + (vid.width * y));
- oldz = (d_pzbuffer + (vid.width * ((y*WARP_HEIGHT)/vid.height) ));
- k = (zinc * (vid.width-1));
+ oldz = (d_pzbuffer + (vid.width * ((y * WARP_HEIGHT) / vid.height)));
+ k = (zinc * (vid.width - 1));
- for (x=vid.width-1; x>=0; x--)
- {
+ for (x = vid.width - 1; x >= 0; x--) {
curz[x] = oldz[k >> 16];
k -= zinc;
}
@@ -221,22 +206,19 @@ void R_ApplySIRDAlgorithum( void )
//SIRDify each line
- for (y=0; y<vid.height; y++)
- {
+ for (y = 0; y < vid.height; y++) {
curp = (vid.buffer + (vid.rowbytes * y));
- curz = (d_pzbuffer + (vid.width * y ));
+ curz = (d_pzbuffer + (vid.width * y));
- if (mode != 3)
- {
+ if (mode != 3) {
// draw the SIRD
// copy the background into the left most column
curbp = &(r_SIRDBackground[ R_SIRDw * (y % R_SIRDh) ]);
- for (x=0; x<R_SIRDw; x++)
- {
+ for (x = 0; x < R_SIRDw; x++) {
*curp = *curbp;
curp++;
- curbp++;
+ curbp++;
}
lastz = 0;
@@ -245,20 +227,18 @@ void R_ApplySIRDAlgorithum( void )
curbp = curp - R_SIRDw;
// now calculate the SIRD
- for (x=R_SIRDw; x<vid.width; x++)
- {
+ for (x = R_SIRDw; x < vid.width; x++) {
//only call the z-function with a new
//value, it is slow so this saves quite
//some time.
- if (lastz != *curz)
- {
+ if (lastz != *curz) {
lastz = *curz;
//convert from z to height offset
- cz = ( mode == 2 ) ? R_SIRDmaxDiff - R_SIRDZFunc(lastz) : R_SIRDZFunc(lastz);
+ cz = (mode == 2) ? R_SIRDmaxDiff - R_SIRDZFunc(lastz) : R_SIRDZFunc(lastz);
//the "height offset" used in making SIRDS
- //can be considered an adjustment of the
+ //can be considered an adjustment of the
//frequency of repetition in the pattern.
//so here we are copying from bp to p, and so
//it simply increases or decreases the distance
@@ -272,9 +252,7 @@ void R_ApplySIRDAlgorithum( void )
curbp++;
curz++;
}
- }
- else
- {
+ } else {
//if we are just drawing the height map
//this lets you see which layers are used to
//create the SIRD
@@ -284,10 +262,8 @@ void R_ApplySIRDAlgorithum( void )
//coincidence because of how the colours are
//organized in the pallette.
- for (x=0; x<vid.width; x++)
- {
- if (lastz != *curz)
- {
+ for (x = 0; x < vid.width; x++) {
+ if (lastz != *curz) {
lastz = *curz;
cz = R_SIRDZFunc(*curz);
}
diff --git a/src/sw_sky.c b/src/sw_sky.c
index 92f8fff..5db98ac 100644
--- a/src/sw_sky.c
+++ b/src/sw_sky.c
@@ -9,7 +9,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -38,37 +38,37 @@ static const int r_skysideimage[6] = { 5, 2, 4, 1, 0, 3 };
// I just copied this data from a box map...
static const int box_planes[12] = {
- 2,-128, 0,-128, 2,128, 1,128, 0,128, 1,-128
+ 2, -128, 0, -128, 2, 128, 1, 128, 0, 128, 1, -128
};
static const int box_surfedges[24] = {
- 1,2,3,4, 1,5,6,7, 8,9,6,10, 2,7,9,11, 12,3,11,8, 12,10,5,4
+ 1, 2, 3, 4, 1, 5, 6, 7, 8, 9, 6, 10, 2, 7, 9, 11, 12, 3, 11, 8, 12, 10, 5, 4
};
static const int box_surfverts[24] = {
- 0,0,0,0, 1,0,0,0, 0,0,1,0, 1,1,1,0, 0,1,1,1, 1,1,1,1
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1
};
static const int box_edges[24] = {
- 1,2, 2,3, 3,4, 4,1, 1,5, 5,6, 6,2, 7,8, 8,6, 5,7, 8,3, 7,4
+ 1, 2, 2, 3, 3, 4, 4, 1, 1, 5, 5, 6, 6, 2, 7, 8, 8, 6, 5, 7, 8, 3, 7, 4
};
static const int box_flags[6] = {
0, 0, 1, 1, 1, 0
};
static const vec3_t box_axis[6][2] = {
- { {0,-1,0}, {-1,0,0} },
- { {0,1,0}, {0,0,-1} },
- { {0,-1,0}, {1,0,0} },
- { {1,0,0}, {0,0,-1} },
- { {0,-1,0}, {0,0,-1} },
- { {-1,0,0}, {0,0,-1} }
+ { {0, -1, 0}, { -1, 0, 0} },
+ { {0, 1, 0}, {0, 0, -1} },
+ { {0, -1, 0}, {1, 0, 0} },
+ { {1, 0, 0}, {0, 0, -1} },
+ { {0, -1, 0}, {0, 0, -1} },
+ { { -1, 0, 0}, {0, 0, -1} }
};
static const vec3_t box_verts[8] = {
- {-1,-1,-1},
- {-1,1,-1},
- {1,1,-1},
- {1,-1,-1},
- {-1,-1,1},
- {-1,1,1},
- {1,-1,1},
- {1,1,1}
+ { -1, -1, -1},
+ { -1, 1, -1},
+ {1, 1, -1},
+ {1, -1, -1},
+ { -1, -1, 1},
+ { -1, 1, 1},
+ {1, -1, 1},
+ {1, 1, 1}
};
/*
@@ -76,20 +76,21 @@ static const vec3_t box_verts[8] = {
R_InitSkyBox
================
*/
-void R_InitSkyBox( void ) {
+void R_InitSkyBox(void)
+{
int i;
- for( i = 0; i < 6; i++ ) {
- r_skyplanes[i].normal[box_planes[i*2]] = 1;
- r_skyplanes[i].dist = box_planes[i*2+1];
+ for (i = 0; i < 6; i++) {
+ r_skyplanes[i].normal[box_planes[i * 2]] = 1;
+ r_skyplanes[i].dist = box_planes[i * 2 + 1];
- VectorCopy( box_axis[i][0], r_skytexinfo[i].axis[0] );
- VectorCopy( box_axis[i][1], r_skytexinfo[i].axis[1] );
+ VectorCopy(box_axis[i][0], r_skytexinfo[i].axis[0]);
+ VectorCopy(box_axis[i][1], r_skytexinfo[i].axis[1]);
r_skyfaces[i].plane = &r_skyplanes[i];
r_skyfaces[i].drawflags = box_flags[i] | DSURF_SKY;
r_skyfaces[i].numsurfedges = 4;
- r_skyfaces[i].firstsurfedge = &r_skysurfedges[i*4];
+ r_skyfaces[i].firstsurfedge = &r_skysurfedges[i * 4];
r_skyfaces[i].texinfo = &r_skytexinfo[i];
r_skyfaces[i].texturemins[0] = -128;
r_skyfaces[i].texturemins[1] = -128;
@@ -97,14 +98,14 @@ void R_InitSkyBox( void ) {
r_skyfaces[i].extents[1] = 256;
}
- for( i = 0; i < 24; i++ ) {
- r_skysurfedges[i].edge = &r_skyedges[box_surfedges[i]-1];
+ for (i = 0; i < 24; i++) {
+ r_skysurfedges[i].edge = &r_skyedges[box_surfedges[i] - 1];
r_skysurfedges[i].vert = box_surfverts[i];
}
- for( i = 0; i < 12; i++ ) {
- r_skyedges[i].v[0] = &r_skyverts[box_edges[i*2+0]-1];
- r_skyedges[i].v[1] = &r_skyverts[box_edges[i*2+1]-1];
+ for (i = 0; i < 12; i++) {
+ r_skyedges[i].v[0] = &r_skyverts[box_edges[i * 2 + 0] - 1];
+ r_skyedges[i].v[1] = &r_skyverts[box_edges[i * 2 + 1] - 1];
r_skyedges[i].cachededgeoffset = 0;
}
}
@@ -114,7 +115,8 @@ void R_InitSkyBox( void ) {
R_EmitSkyBox
================
*/
-void R_EmitSkyBox( void ) {
+void R_EmitSkyBox(void)
+{
int i, j;
int oldkey;
@@ -126,28 +128,28 @@ void R_EmitSkyBox( void ) {
r_skyframe = r_framecount;
// set the eight fake vertexes
- for( i = 0; i < 8; i++ )
- for( j = 0; j < 3; j++ )
- r_skyverts[i].point[j] = r_origin[j] + box_verts[i][j]*128;
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < 3; j++)
+ r_skyverts[i].point[j] = r_origin[j] + box_verts[i][j] * 128;
// set the six fake planes
- for( i = 0; i < 6; i++ )
- if (box_planes[i*2+1] > 0)
- r_skyplanes[i].dist = r_origin[box_planes[i*2]]+128;
+ for (i = 0; i < 6; i++)
+ if (box_planes[i * 2 + 1] > 0)
+ r_skyplanes[i].dist = r_origin[box_planes[i * 2]] + 128;
else
- r_skyplanes[i].dist = r_origin[box_planes[i*2]]-128;
+ r_skyplanes[i].dist = r_origin[box_planes[i * 2]] - 128;
// fix texture offsets
- for( i = 0; i < 6; i++ ) {
- r_skytexinfo[i].offset[0] = -DotProduct( r_origin, r_skytexinfo[i].axis[0] );
- r_skytexinfo[i].offset[1] = -DotProduct( r_origin, r_skytexinfo[i].axis[1] );
+ for (i = 0; i < 6; i++) {
+ r_skytexinfo[i].offset[0] = -DotProduct(r_origin, r_skytexinfo[i].axis[0]);
+ r_skytexinfo[i].offset[1] = -DotProduct(r_origin, r_skytexinfo[i].axis[1]);
}
// emit the six faces
oldkey = r_currentkey;
r_currentkey = 0x7ffffff0;
- for( i = 0; i < 6; i++ ) {
- R_RenderFace( &r_skyfaces[i], 15 );
+ for (i = 0; i < 6; i++) {
+ R_RenderFace(&r_skyfaces[i], 15);
}
r_currentkey = oldkey; // bsp sorting order
}
@@ -157,18 +159,19 @@ void R_EmitSkyBox( void ) {
R_SetSky
============
*/
-void R_SetSky( const char *name, float rotate, vec3_t axis ) {
+void R_SetSky(const char *name, float rotate, vec3_t axis)
+{
int i;
char path[MAX_QPATH];
// sky_rotate = rotate;
-// VectorCopy( axis, sky_axis );
+// VectorCopy(axis, sky_axis);
- for( i = 0; i < 6; i++ ) {
- Q_concat( path, sizeof( path ), "env/", name,
- r_skysidenames[r_skysideimage[i]], ".pcx", NULL );
- FS_NormalizePath( path, path );
- r_skytexinfo[i].image = IMG_Find( path, it_sky );
+ for (i = 0; i < 6; i++) {
+ Q_concat(path, sizeof(path), "env/", name,
+ r_skysidenames[r_skysideimage[i]], ".pcx", NULL);
+ FS_NormalizePath(path, path);
+ r_skytexinfo[i].image = IMG_Find(path, it_sky);
}
}
diff --git a/src/sw_surf.c b/src/sw_surf.c
index db55a6b..04b9c59 100644
--- a/src/sw_surf.c
+++ b/src/sw_surf.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -36,10 +36,10 @@ int r_lightwidth;
int r_numhblocks, r_numvblocks;
unsigned char *r_source, *r_sourcemax;
-void R_DrawSurfaceBlock8_mip0 (void);
-void R_DrawSurfaceBlock8_mip1 (void);
-void R_DrawSurfaceBlock8_mip2 (void);
-void R_DrawSurfaceBlock8_mip3 (void);
+void R_DrawSurfaceBlock8_mip0(void);
+void R_DrawSurfaceBlock8_mip1(void);
+void R_DrawSurfaceBlock8_mip2(void);
+void R_DrawSurfaceBlock8_mip3(void);
static void (*surfmiptable[4])(void) = {
R_DrawSurfaceBlock8_mip0,
@@ -48,7 +48,7 @@ static void (*surfmiptable[4])(void) = {
R_DrawSurfaceBlock8_mip3
};
-void R_BuildLightMap (void);
+void R_BuildLightMap(void);
extern blocklight_t blocklights[MAX_BLOCKLIGHTS]; // allow some very large lightmaps
float surfscale;
@@ -64,7 +64,7 @@ R_TextureAnimation
Returns the proper texture for a given time and base texture
===============
*/
-image_t *R_TextureAnimation (mtexinfo_t *tex)
+image_t *R_TextureAnimation(mtexinfo_t *tex)
{
int c;
@@ -72,8 +72,7 @@ image_t *R_TextureAnimation (mtexinfo_t *tex)
return tex->image;
c = currententity->frame % tex->numframes;
- while (c)
- {
+ while (c) {
tex = tex->next;
c--;
}
@@ -86,33 +85,34 @@ image_t *R_TextureAnimation (mtexinfo_t *tex)
R_DrawSurface
===============
*/
-void R_DrawSurface( void ) {
+void R_DrawSurface(void)
+{
byte *basetptr;
int smax, tmax, twidth;
int u;
int soffset, toffset;
int horzblockstep;
byte *pcolumndest;
- void (*pblockdrawer)(void);
+ void (*pblockdrawer)(void);
image_t *mt;
surfrowbytes = r_drawsurf.rowbytes;
mt = r_drawsurf.image;
-
+
r_source = mt->pixels[r_drawsurf.surfmip];
-
+
// the fractional light values should range from 0 to (VID_GRADES - 1) << 16
// from a source range of 0 - 255
-
+
/* width in bytes */
twidth = mt->upload_width >> r_drawsurf.surfmip;
blocksize = 16 >> r_drawsurf.surfmip;
blockdivshift = 4 - r_drawsurf.surfmip;
blockdivmask = (1 << blockdivshift) - 1;
-
- r_lightwidth = S_MAX(r_drawsurf.surf)*LIGHTMAP_BYTES;
+
+ r_lightwidth = S_MAX(r_drawsurf.surf) * LIGHTMAP_BYTES;
r_numhblocks = r_drawsurf.surfwidth >> blockdivshift;
r_numvblocks = r_drawsurf.surfheight >> blockdivshift;
@@ -141,8 +141,8 @@ void R_DrawSurface( void ) {
pcolumndest = r_drawsurf.surfdat;
- for( u = 0; u < r_numhblocks; u++ ) {
- r_lightptr = ( unsigned * )blocklights + u * LIGHTMAP_BYTES;
+ for (u = 0; u < r_numhblocks; u++) {
+ r_lightptr = (unsigned *)blocklights + u * LIGHTMAP_BYTES;
prowdestbase = pcolumndest;
@@ -151,7 +151,7 @@ void R_DrawSurface( void ) {
(*pblockdrawer)();
soffset += blocksize;
- if( soffset >= smax )
+ if (soffset >= smax)
soffset = 0;
pcolumndest += horzblockstep;
@@ -189,34 +189,31 @@ R_InitCaches
================
*/
-void R_InitCaches (void)
+void R_InitCaches(void)
{
int size;
int pix;
// calculate size to allocate
- if (sw_surfcacheoverride->integer)
- {
+ if (sw_surfcacheoverride->integer) {
size = sw_surfcacheoverride->integer;
- }
- else
- {
+ } else {
size = SURFCACHE_SIZE_AT_320X240;
- pix = vid.width*vid.height;
+ pix = vid.width * vid.height;
if (pix > 64000)
- size += (pix-64000)*3;
- }
+ size += (pix - 64000) * 3;
+ }
// round up to page size
size = (size + 8191) & ~8191;
- Com_Printf("%ik surface cache\n", size/1024);
+ Com_Printf("%ik surface cache\n", size / 1024);
sc_size = size;
sc_base = (surfcache_t *)R_Malloc(size);
sc_rover = sc_base;
-
+
sc_base->next = NULL;
sc_base->owner = NULL;
sc_base->size = sc_size;
@@ -228,20 +225,19 @@ void R_InitCaches (void)
D_FlushCaches
==================
*/
-void D_FlushCaches (void)
+void D_FlushCaches(void)
{
surfcache_t *c;
-
+
if (!sc_base)
return;
- for (c = sc_base ; c ; c = c->next)
- {
- if (c->owner){
+ for (c = sc_base; c; c = c->next) {
+ if (c->owner) {
*c->owner = NULL;
}
}
-
+
sc_rover = sc_base;
sc_base->next = NULL;
sc_base->owner = NULL;
@@ -253,66 +249,61 @@ void D_FlushCaches (void)
D_SCAlloc
=================
*/
-surfcache_t *D_SCAlloc (int width, int size)
+surfcache_t *D_SCAlloc(int width, int size)
{
surfcache_t *new;
qboolean wrapped_this_time;
if ((width < 0) || (width > 256))
- Com_Error (ERR_FATAL,"D_SCAlloc: bad cache width %d\n", width);
+ Com_Error(ERR_FATAL, "D_SCAlloc: bad cache width %d\n", width);
if ((size <= 0) || (size > 0x10000))
- Com_Error (ERR_FATAL,"D_SCAlloc: bad cache size %d\n", size);
-
- size += sizeof( surfcache_t ) - 4;
+ Com_Error(ERR_FATAL, "D_SCAlloc: bad cache size %d\n", size);
+
+ size += sizeof(surfcache_t) - 4;
size = (size + 3) & ~3;
if (size > sc_size)
- Com_Error (ERR_FATAL,"D_SCAlloc: %i > cache size of %i",size, sc_size);
+ Com_Error(ERR_FATAL, "D_SCAlloc: %i > cache size of %i", size, sc_size);
// if there is not size bytes after the rover, reset to the start
wrapped_this_time = qfalse;
- if ( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size)
- {
- if (sc_rover)
- {
+ if (!sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size) {
+ if (sc_rover) {
wrapped_this_time = qtrue;
}
sc_rover = sc_base;
}
-
+
// colect and free surfcache_t blocks until the rover block is large enough
new = sc_rover;
if (sc_rover->owner)
*sc_rover->owner = NULL;
-
- while (new->size < size)
- {
- // free another
+
+ while (new->size < size) {
+ // free another
sc_rover = sc_rover->next;
if (!sc_rover)
- Com_Error (ERR_FATAL,"D_SCAlloc: hit the end of memory");
+ Com_Error(ERR_FATAL, "D_SCAlloc: hit the end of memory");
if (sc_rover->owner)
*sc_rover->owner = NULL;
-
+
new->size += sc_rover->size;
new->next = sc_rover->next;
}
// create a fragment out of any leftovers
- if (new->size - size > 256)
- {
- sc_rover = (surfcache_t *)( (byte *)new + size);
+ if (new->size - size > 256) {
+ sc_rover = (surfcache_t *)((byte *)new + size);
sc_rover->size = new->size - size;
sc_rover->next = new->next;
sc_rover->width = 0;
sc_rover->owner = NULL;
new->next = sc_rover;
new->size = size;
- }
- else
+ } else
sc_rover = new->next;
-
+
new->width = width;
// DEBUG
if (width > 0)
@@ -320,13 +311,10 @@ surfcache_t *D_SCAlloc (int width, int size)
new->owner = NULL; // should be set properly after return
- if (d_roverwrapped)
- {
+ if (d_roverwrapped) {
if (wrapped_this_time || (sc_rover >= d_initial_rover))
r_cache_thrash = qtrue;
- }
- else if (wrapped_this_time)
- {
+ } else if (wrapped_this_time) {
d_roverwrapped = qtrue;
}
@@ -339,16 +327,15 @@ surfcache_t *D_SCAlloc (int width, int size)
D_SCDump
=================
*/
-void D_SCDump_f (void)
+void D_SCDump_f(void)
{
surfcache_t *test;
- for (test = sc_base ; test ; test = test->next)
- {
+ for (test = sc_base; test; test = test->next) {
if (test == sc_rover)
Com_Printf("ROVER:\n");
Com_Printf("%p : %i bytes %i width\n", test, test->size,
- test->width);
+ test->width);
}
}
@@ -359,60 +346,59 @@ void D_SCDump_f (void)
D_CacheSurface
================
*/
-surfcache_t *D_CacheSurface (mface_t *surface, int miplevel)
+surfcache_t *D_CacheSurface(mface_t *surface, int miplevel)
{
surfcache_t *cache;
//
// if the surface is animating or flashing, flush the cache
//
- r_drawsurf.image = R_TextureAnimation (surface->texinfo);
- r_drawsurf.lightadj[0] = r_newrefdef.lightstyles[surface->styles[0]].white*256;
- r_drawsurf.lightadj[1] = r_newrefdef.lightstyles[surface->styles[1]].white*256;
- r_drawsurf.lightadj[2] = r_newrefdef.lightstyles[surface->styles[2]].white*256;
- r_drawsurf.lightadj[3] = r_newrefdef.lightstyles[surface->styles[3]].white*256;
-
+ r_drawsurf.image = R_TextureAnimation(surface->texinfo);
+ r_drawsurf.lightadj[0] = r_newrefdef.lightstyles[surface->styles[0]].white * 256;
+ r_drawsurf.lightadj[1] = r_newrefdef.lightstyles[surface->styles[1]].white * 256;
+ r_drawsurf.lightadj[2] = r_newrefdef.lightstyles[surface->styles[2]].white * 256;
+ r_drawsurf.lightadj[3] = r_newrefdef.lightstyles[surface->styles[3]].white * 256;
+
//
// see if the cache holds apropriate data
//
cache = surface->cachespots[miplevel];
if (cache && !cache->dlight && surface->dlightframe != r_framecount
- && cache->image == r_drawsurf.image
- && cache->lightadj[0] == r_drawsurf.lightadj[0]
- && cache->lightadj[1] == r_drawsurf.lightadj[1]
- && cache->lightadj[2] == r_drawsurf.lightadj[2]
- && cache->lightadj[3] == r_drawsurf.lightadj[3] )
+ && cache->image == r_drawsurf.image
+ && cache->lightadj[0] == r_drawsurf.lightadj[0]
+ && cache->lightadj[1] == r_drawsurf.lightadj[1]
+ && cache->lightadj[2] == r_drawsurf.lightadj[2]
+ && cache->lightadj[3] == r_drawsurf.lightadj[3])
return cache;
//
// determine shape of surface
//
- surfscale = 1.0 / (1<<miplevel);
+ surfscale = 1.0 / (1 << miplevel);
r_drawsurf.surfmip = miplevel;
r_drawsurf.surfwidth = surface->extents[0] >> miplevel;
r_drawsurf.rowbytes = r_drawsurf.surfwidth;
r_drawsurf.surfheight = surface->extents[1] >> miplevel;
-
+
//
// allocate memory if needed
//
- if (!cache) // if a texture just animated, don't reallocate it
- {
- cache = D_SCAlloc (r_drawsurf.surfwidth,
- r_drawsurf.surfwidth * r_drawsurf.surfheight);
+ if (!cache) { // if a texture just animated, don't reallocate it
+ cache = D_SCAlloc(r_drawsurf.surfwidth,
+ r_drawsurf.surfwidth * r_drawsurf.surfheight);
surface->cachespots[miplevel] = cache;
cache->owner = &surface->cachespots[miplevel];
cache->mipscale = surfscale;
}
-
+
if (surface->dlightframe == r_framecount)
cache->dlight = 1;
else
cache->dlight = 0;
r_drawsurf.surfdat = (pixel_t *)cache->data;
-
+
cache->image = r_drawsurf.image;
cache->lightadj[0] = r_drawsurf.lightadj[0];
cache->lightadj[1] = r_drawsurf.lightadj[1];
@@ -427,10 +413,10 @@ surfcache_t *D_CacheSurface (mface_t *surface, int miplevel)
c_surf++;
// calculate the lightings
- R_BuildLightMap ();
-
+ R_BuildLightMap();
+
// rasterize the surface into the cache
- R_DrawSurface ();
+ R_DrawSurface();
return cache;
}
diff --git a/src/sys_public.h b/src/sys_public.h
index 2a81f3e..4a51125 100644
--- a/src/sys_public.h
+++ b/src/sys_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -26,43 +26,43 @@ typedef struct {
} mempool_t;
// loads the dll and returns entry pointer
-void *Sys_LoadLibrary( const char *path, const char *sym, void **handle );
-void Sys_FreeLibrary( void *handle );
-void *Sys_GetProcAddress( void *handle, const char *sym );
+void *Sys_LoadLibrary(const char *path, const char *sym, void **handle);
+void Sys_FreeLibrary(void *handle);
+void *Sys_GetProcAddress(void *handle, const char *sym);
-unsigned Sys_Milliseconds( void );
-void Sys_Sleep( int msec );
+unsigned Sys_Milliseconds(void);
+void Sys_Sleep(int msec);
-void Hunk_Begin( mempool_t *pool, size_t maxsize );
-void *Hunk_Alloc( mempool_t *pool, size_t size );
-void Hunk_End( mempool_t *pool );
-void Hunk_Free( mempool_t *pool );
+void Hunk_Begin(mempool_t *pool, size_t maxsize);
+void *Hunk_Alloc(mempool_t *pool, size_t size);
+void Hunk_End(mempool_t *pool);
+void Hunk_Free(mempool_t *pool);
-void Sys_Init( void );
-void Sys_AddDefaultConfig( void );
+void Sys_Init(void);
+void Sys_AddDefaultConfig(void);
#if USE_SYSCON
-void Sys_RunConsole( void );
-void Sys_ConsoleOutput( const char *string );
-void Sys_SetConsoleTitle( const char *title );
-void Sys_SetConsoleColor( color_index_t color );
-void Sys_Printf( const char *fmt, ... ) q_printf( 1, 2 );
+void Sys_RunConsole(void);
+void Sys_ConsoleOutput(const char *string);
+void Sys_SetConsoleTitle(const char *title);
+void Sys_SetConsoleColor(color_index_t color);
+void Sys_Printf(const char *fmt, ...) q_printf(1, 2);
#endif
-void Sys_Error( const char *error, ... ) q_noreturn q_printf( 1, 2 );
-void Sys_Quit( void ) q_noreturn;
+void Sys_Error(const char *error, ...) q_noreturn q_printf(1, 2);
+void Sys_Quit(void) q_noreturn;
-void Sys_ListFiles_r( const char *path, const char *filter,
- unsigned flags, size_t baselen, int *count_p, void **files, int depth );
+void Sys_ListFiles_r(const char *path, const char *filter,
+ unsigned flags, size_t baselen, int *count_p, void **files, int depth);
struct file_info_s;
-qerror_t Sys_GetPathInfo( const char *path, struct file_info_s *info );
-qerror_t Sys_GetFileInfo( FILE *fp, struct file_info_s *info );
+qerror_t Sys_GetPathInfo(const char *path, struct file_info_s *info);
+qerror_t Sys_GetFileInfo(FILE *fp, struct file_info_s *info);
-void Sys_DebugBreak( void );
+void Sys_DebugBreak(void);
#if USE_AC_CLIENT
-qboolean Sys_GetAntiCheatAPI( void );
+qboolean Sys_GetAntiCheatAPI(void);
#endif
extern cvar_t *sys_basedir;
diff --git a/src/sys_unix.c b/src/sys_unix.c
index 4f80593..d1d7dee 100644
--- a/src/sys_unix.c
+++ b/src/sys_unix.c
@@ -123,7 +123,7 @@ static void stdout_write(const void *buf, size_t len)
tty_enabled = qfalse;
Com_Error(ERR_FATAL, "%s: %s() failed: %s",
- __func__, what, strerror(errno));
+ __func__, what, strerror(errno));
}
buf += ret;
@@ -131,55 +131,58 @@ static void stdout_write(const void *buf, size_t len)
}
}
-static void tty_hide_input( void ) {
+static void tty_hide_input(void)
+{
int i;
- if( !tty_hidden ) {
- for( i = 0; i <= tty_prompt.inputLine.cursorPos; i++ ) {
- stdout_write( "\b \b", 3 );
+ if (!tty_hidden) {
+ for (i = 0; i <= tty_prompt.inputLine.cursorPos; i++) {
+ stdout_write("\b \b", 3);
}
}
tty_hidden++;
}
-static void tty_show_input( void ) {
- if( !tty_hidden ) {
+static void tty_show_input(void)
+{
+ if (!tty_hidden) {
return;
}
tty_hidden--;
- if( !tty_hidden ) {
- stdout_write( "]", 1 );
- stdout_write( tty_prompt.inputLine.text,
- tty_prompt.inputLine.cursorPos );
+ if (!tty_hidden) {
+ stdout_write("]", 1);
+ stdout_write(tty_prompt.inputLine.text,
+ tty_prompt.inputLine.cursorPos);
}
}
-static void tty_init_input( void ) {
+static void tty_init_input(void)
+{
struct termios tty;
#ifdef TIOCGWINSZ
struct winsize ws;
#endif
int width;
- if( !isatty( STDIN_FILENO ) || !isatty( STDOUT_FILENO ) ) {
- Com_Printf( "stdin/stdout don't both refer to a TTY\n" );
- Cvar_Set( "sys_console", "1" );
+ if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
+ Com_Printf("stdin/stdout don't both refer to a TTY\n");
+ Cvar_Set("sys_console", "1");
return;
}
- tcgetattr( STDIN_FILENO, &tty_orig );
+ tcgetattr(STDIN_FILENO, &tty_orig);
tty = tty_orig;
- tty.c_lflag &= ~( ECHO | ICANON | INPCK | ISTRIP );
+ tty.c_lflag &= ~(ECHO | ICANON | INPCK | ISTRIP);
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 0;
- tcsetattr( STDIN_FILENO, TCSADRAIN, &tty );
+ tcsetattr(STDIN_FILENO, TCSADRAIN, &tty);
// determine terminal width
width = 80;
#ifdef TIOCGWINSZ
- if( ioctl( STDIN_FILENO, TIOCGWINSZ, &ws ) == 0 ) {
- if( ws.ws_col ) {
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == 0) {
+ if (ws.ws_col) {
width = ws.ws_col;
}
}
@@ -190,44 +193,46 @@ static void tty_init_input( void ) {
// figure out input line width
width--;
- if( width > MAX_FIELD_TEXT - 1 ) {
+ if (width > MAX_FIELD_TEXT - 1) {
width = MAX_FIELD_TEXT - 1;
}
- IF_Init( &tty_prompt.inputLine, width, width );
+ IF_Init(&tty_prompt.inputLine, width, width);
// display command prompt
- stdout_write( "]", 1 );
+ stdout_write("]", 1);
}
-static void tty_shutdown_input( void ) {
- if( tty_io ) {
- IO_Remove( STDIN_FILENO );
+static void tty_shutdown_input(void)
+{
+ if (tty_io) {
+ IO_Remove(STDIN_FILENO);
tty_io = NULL;
}
- if( tty_enabled ) {
+ if (tty_enabled) {
tty_hide_input();
- tcsetattr( STDIN_FILENO, TCSADRAIN, &tty_orig );
+ tcsetattr(STDIN_FILENO, TCSADRAIN, &tty_orig);
tty_enabled = qfalse;
}
}
-void Sys_SetConsoleColor( color_index_t color ) {
+void Sys_SetConsoleColor(color_index_t color)
+{
static const char color_to_ansi[8] =
- { '0', '1', '2', '3', '4', '6', '5', '7' };
+ { '0', '1', '2', '3', '4', '6', '5', '7' };
char buf[5];
size_t len;
- if( !sys_console || !sys_console->integer ) {
+ if (!sys_console || !sys_console->integer) {
return;
}
- if( !tty_enabled ) {
+ if (!tty_enabled) {
return;
}
buf[0] = '\033';
buf[1] = '[';
- switch( color ) {
+ switch (color) {
case COLOR_NONE:
buf[2] = '0';
buf[3] = 'm';
@@ -247,28 +252,29 @@ void Sys_SetConsoleColor( color_index_t color ) {
break;
}
- if( color != COLOR_NONE ) {
+ if (color != COLOR_NONE) {
tty_hide_input();
}
- stdout_write( buf, len );
- if( color == COLOR_NONE ) {
+ stdout_write(buf, len);
+ if (color == COLOR_NONE) {
tty_show_input();
}
}
-static void tty_write_output( const char *text ) {
+static void tty_write_output(const char *text)
+{
char buf[MAXPRINTMSG];
size_t len;
- for( len = 0; len < MAXPRINTMSG; len++ ) {
+ for (len = 0; len < MAXPRINTMSG; len++) {
int c = *text++;
- if( !c ) {
+ if (!c) {
break;
}
- buf[len] = Q_charascii( c );
+ buf[len] = Q_charascii(c);
}
- stdout_write( buf, len );
+ stdout_write(buf, len);
}
/*
@@ -276,29 +282,31 @@ static void tty_write_output( const char *text ) {
Sys_ConsoleOutput
=================
*/
-void Sys_ConsoleOutput( const char *text ) {
- if( !sys_console || !sys_console->integer ) {
+void Sys_ConsoleOutput(const char *text)
+{
+ if (!sys_console || !sys_console->integer) {
return;
}
- if( !tty_enabled ) {
- tty_write_output( text );
+ if (!tty_enabled) {
+ tty_write_output(text);
} else {
tty_hide_input();
- tty_write_output( text );
+ tty_write_output(text);
tty_show_input();
}
}
-void Sys_SetConsoleTitle( const char *title ) {
+void Sys_SetConsoleTitle(const char *title)
+{
char buf[MAX_STRING_CHARS];
size_t len;
- if( !sys_console || !sys_console->integer ) {
+ if (!sys_console || !sys_console->integer) {
return;
}
- if( !tty_enabled ) {
+ if (!tty_enabled) {
return;
}
@@ -307,108 +315,109 @@ void Sys_SetConsoleTitle( const char *title ) {
buf[2] = '0';
buf[3] = ';';
- for( len = 4; len < MAX_STRING_CHARS - 1; len++ ) {
+ for (len = 4; len < MAX_STRING_CHARS - 1; len++) {
int c = *title++;
- if( !c ) {
+ if (!c) {
break;
}
- buf[len] = Q_charascii( c );
+ buf[len] = Q_charascii(c);
}
buf[len++] = '\007';
- stdout_write( buf, len );
+ stdout_write(buf, len);
}
-static void tty_parse_input( const char *text ) {
+static void tty_parse_input(const char *text)
+{
inputField_t *f;
char *s;
int i, key;
f = &tty_prompt.inputLine;
- while( *text ) {
+ while (*text) {
key = *text++;
- if( key == tty_orig.c_cc[VERASE] || key == 127 || key == 8 ) {
- if( f->cursorPos ) {
+ if (key == tty_orig.c_cc[VERASE] || key == 127 || key == 8) {
+ if (f->cursorPos) {
f->text[--f->cursorPos] = 0;
- stdout_write( "\b \b", 3 );
+ stdout_write("\b \b", 3);
}
continue;
}
- if( key == tty_orig.c_cc[VKILL] ) {
- for( i = 0; i < f->cursorPos; i++ ) {
- stdout_write( "\b \b", 3 );
+ if (key == tty_orig.c_cc[VKILL]) {
+ for (i = 0; i < f->cursorPos; i++) {
+ stdout_write("\b \b", 3);
}
f->cursorPos = 0;
continue;
}
- if( key >= 32 ) {
- if( f->cursorPos == f->maxChars - 1 ) {
- stdout_write( va( "\b \b%c", key ), 4 );
- f->text[f->cursorPos+0] = key;
- f->text[f->cursorPos+1] = 0;
+ if (key >= 32) {
+ if (f->cursorPos == f->maxChars - 1) {
+ stdout_write(va("\b \b%c", key), 4);
+ f->text[f->cursorPos + 0] = key;
+ f->text[f->cursorPos + 1] = 0;
} else {
- stdout_write( va( "%c", key ), 1 );
- f->text[f->cursorPos+0] = key;
- f->text[f->cursorPos+1] = 0;
+ stdout_write(va("%c", key), 1);
+ f->text[f->cursorPos + 0] = key;
+ f->text[f->cursorPos + 1] = 0;
f->cursorPos++;
}
continue;
}
- if( key == '\n' ) {
+ if (key == '\n') {
tty_hide_input();
- s = Prompt_Action( &tty_prompt );
- if( s ) {
- if( *s == '\\' || *s == '/' ) {
+ s = Prompt_Action(&tty_prompt);
+ if (s) {
+ if (*s == '\\' || *s == '/') {
s++;
}
- Sys_Printf( "]%s\n", s );
- Cbuf_AddText( &cmd_buffer, s );
+ Sys_Printf("]%s\n", s);
+ Cbuf_AddText(&cmd_buffer, s);
} else {
- stdout_write( "]\n", 2 );
+ stdout_write("]\n", 2);
}
tty_show_input();
continue;
}
- if( key == '\t' ) {
+ if (key == '\t') {
tty_hide_input();
- Prompt_CompleteCommand( &tty_prompt, qfalse );
- f->cursorPos = strlen( f->text ); // FIXME
+ Prompt_CompleteCommand(&tty_prompt, qfalse);
+ f->cursorPos = strlen(f->text); // FIXME
tty_show_input();
continue;
}
- if( *text ) {
+ if (*text) {
key = *text++;
- if( key == '[' || key == 'O' ) {
- if( *text ) {
+ if (key == '[' || key == 'O') {
+ if (*text) {
key = *text++;
- switch( key ) {
+ switch (key) {
case 'A':
tty_hide_input();
- Prompt_HistoryUp( &tty_prompt );
+ Prompt_HistoryUp(&tty_prompt);
tty_show_input();
break;
case 'B':
tty_hide_input();
- Prompt_HistoryDown( &tty_prompt );
+ Prompt_HistoryDown(&tty_prompt);
tty_show_input();
break;
#if 0
case 'C':
- if( f->text[f->cursorPos] ) {
- Sys_ConsoleWrite( "\033[C", 3 );
+ if (f->text[f->cursorPos]) {
+ Sys_ConsoleWrite("\033[C", 3);
f->cursorPos++;
}
break;
case 'D':
- if( f->cursorPos ) {
- Sys_ConsoleWrite( "\033[D", 3 );
+ if (f->cursorPos) {
+ Sys_ConsoleWrite("\033[D", 3);
f->cursorPos--;
}
break;
@@ -420,45 +429,46 @@ static void tty_parse_input( const char *text ) {
}
}
-void Sys_RunConsole( void ) {
+void Sys_RunConsole(void)
+{
char text[MAX_STRING_CHARS];
ssize_t ret;
- if( !sys_console || !sys_console->integer ) {
+ if (!sys_console || !sys_console->integer) {
return;
}
- if( !tty_io || !tty_io->canread ) {
+ if (!tty_io || !tty_io->canread) {
return;
}
- ret = read( STDIN_FILENO, text, sizeof( text ) - 1 );
- if( !ret ) {
- Com_DPrintf( "Read EOF from stdin.\n" );
+ ret = read(STDIN_FILENO, text, sizeof(text) - 1);
+ if (!ret) {
+ Com_DPrintf("Read EOF from stdin.\n");
tty_shutdown_input();
- Cvar_Set( "sys_console", "0" );
+ Cvar_Set("sys_console", "0");
return;
}
// make sure the next call will not block
tty_io->canread = qfalse;
- if( ret < 0 ) {
- if( errno == EAGAIN || errno == EINTR ) {
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR) {
return;
}
- Com_Error( ERR_FATAL, "%s: read() failed: %s",
- __func__, strerror( errno ) );
+ Com_Error(ERR_FATAL, "%s: read() failed: %s",
+ __func__, strerror(errno));
}
text[ret] = 0;
- if( !tty_enabled ) {
- Cbuf_AddText( &cmd_buffer, text );
+ if (!tty_enabled) {
+ Cbuf_AddText(&cmd_buffer, text);
return;
}
- tty_parse_input( text );
+ tty_parse_input(text);
}
#endif // USE_SYSCON
@@ -471,67 +481,71 @@ HUNK
===============================================================================
*/
-void Hunk_Begin( mempool_t *pool, size_t maxsize ) {
+void Hunk_Begin(mempool_t *pool, size_t maxsize)
+{
void *buf;
// reserve a huge chunk of memory, but don't commit any yet
- pool->maxsize = ( maxsize + 4095 ) & ~4095;
+ pool->maxsize = (maxsize + 4095) & ~4095;
pool->cursize = 0;
- buf = mmap( NULL, pool->maxsize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANON, -1, 0 );
- if( buf == NULL || buf == ( void * )-1 ) {
- Com_Error( ERR_FATAL, "%s: unable to reserve %"PRIz" bytes: %s",
- __func__, pool->maxsize, strerror( errno ) );
+ buf = mmap(NULL, pool->maxsize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (buf == NULL || buf == (void *) - 1) {
+ Com_Error(ERR_FATAL, "%s: unable to reserve %"PRIz" bytes: %s",
+ __func__, pool->maxsize, strerror(errno));
}
pool->base = buf;
pool->mapped = pool->maxsize;
}
-void *Hunk_Alloc( mempool_t *pool, size_t size ) {
+void *Hunk_Alloc(mempool_t *pool, size_t size)
+{
void *buf;
// round to cacheline
- size = ( size + 63 ) & ~63;
- if( pool->cursize + size > pool->maxsize ) {
- Com_Error( ERR_FATAL, "%s: unable to allocate %"PRIz" bytes out of %"PRIz,
- __func__, size, pool->maxsize );
+ size = (size + 63) & ~63;
+ if (pool->cursize + size > pool->maxsize) {
+ Com_Error(ERR_FATAL, "%s: unable to allocate %"PRIz" bytes out of %"PRIz,
+ __func__, size, pool->maxsize);
}
- buf = ( byte * )pool->base + pool->cursize;
+ buf = (byte *)pool->base + pool->cursize;
pool->cursize += size;
return buf;
}
-void Hunk_End( mempool_t *pool ) {
- size_t newsize = ( pool->cursize + 4095 ) & ~4095;
+void Hunk_End(mempool_t *pool)
+{
+ size_t newsize = (pool->cursize + 4095) & ~4095;
- if( newsize > pool->maxsize ) {
- Com_Error( ERR_FATAL, "%s: newsize > maxsize", __func__ );
+ if (newsize > pool->maxsize) {
+ Com_Error(ERR_FATAL, "%s: newsize > maxsize", __func__);
}
- if( newsize < pool->maxsize ) {
+ if (newsize < pool->maxsize) {
#ifdef _GNU_SOURCE
- void *buf = mremap( pool->base, pool->maxsize, newsize, 0 );
+ void *buf = mremap(pool->base, pool->maxsize, newsize, 0);
#else
- void *unmap_base = ( byte * )pool->base + newsize;
+ void *unmap_base = (byte *)pool->base + newsize;
size_t unmap_len = pool->maxsize - newsize;
- void *buf = munmap( unmap_base, unmap_len ) + pool->base;
+ void *buf = munmap(unmap_base, unmap_len) + pool->base;
#endif
- if( buf != pool->base ) {
- Com_Error( ERR_FATAL, "%s: could not remap virtual block: %s",
- __func__, strerror( errno ) );
+ if (buf != pool->base) {
+ Com_Error(ERR_FATAL, "%s: could not remap virtual block: %s",
+ __func__, strerror(errno));
}
}
pool->mapped = newsize;
}
-void Hunk_Free( mempool_t *pool ) {
- if( pool->base ) {
- if( munmap( pool->base, pool->mapped ) ) {
- Com_Error( ERR_FATAL, "%s: munmap failed: %s",
- __func__, strerror( errno ) );
+void Hunk_Free(mempool_t *pool)
+{
+ if (pool->base) {
+ if (munmap(pool->base, pool->mapped)) {
+ Com_Error(ERR_FATAL, "%s: munmap failed: %s",
+ __func__, strerror(errno));
}
}
- memset( pool, 0, sizeof( *pool ) );
+ memset(pool, 0, sizeof(*pool));
}
/*
@@ -542,15 +556,17 @@ GENERAL ROUTINES
===============================================================================
*/
-void Sys_DebugBreak( void ) {
- raise( SIGTRAP );
+void Sys_DebugBreak(void)
+{
+ raise(SIGTRAP);
}
-unsigned Sys_Milliseconds( void ) {
+unsigned Sys_Milliseconds(void)
+{
struct timeval tp;
unsigned time;
- gettimeofday( &tp, NULL );
+ gettimeofday(&tp, NULL);
time = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return time;
}
@@ -560,18 +576,19 @@ unsigned Sys_Milliseconds( void ) {
Sys_GetPathInfo
================
*/
-qerror_t Sys_GetPathInfo( const char *path, file_info_t *info ) {
+qerror_t Sys_GetPathInfo(const char *path, file_info_t *info)
+{
struct stat st;
- if( stat( path, &st ) == -1 ) {
+ if (stat(path, &st) == -1) {
return Q_ERR(errno);
}
- if( !S_ISREG( st.st_mode ) ) {
+ if (!S_ISREG(st.st_mode)) {
return Q_ERR_ISDIR;
}
- if( info ) {
+ if (info) {
info->size = st.st_size;
info->ctime = st.st_ctime;
info->mtime = st.st_mtime;
@@ -580,18 +597,19 @@ qerror_t Sys_GetPathInfo( const char *path, file_info_t *info ) {
return Q_ERR_SUCCESS;
}
-qerror_t Sys_GetFileInfo( FILE *fp, file_info_t *info ) {
+qerror_t Sys_GetFileInfo(FILE *fp, file_info_t *info)
+{
struct stat st;
- if( fstat( fileno( fp ), &st ) == -1 ) {
+ if (fstat(fileno(fp), &st) == -1) {
return Q_ERR(errno);
}
- if( !S_ISREG( st.st_mode ) ) {
+ if (!S_ISREG(st.st_mode)) {
return Q_ERR_ISDIR;
}
- if( info ) {
+ if (info) {
info->size = st.st_size;
info->ctime = st.st_ctime;
info->mtime = st.st_mtime;
@@ -607,72 +625,79 @@ Sys_Quit
This function never returns.
=================
*/
-void Sys_Quit( void ) {
+void Sys_Quit(void)
+{
#if USE_SYSCON
tty_shutdown_input();
#endif
- exit( EXIT_SUCCESS );
+ exit(EXIT_SUCCESS);
}
-void Sys_AddDefaultConfig( void ) {
+void Sys_AddDefaultConfig(void)
+{
FILE *fp;
struct stat st;
size_t len, r;
- fp = fopen( SYS_SITECFG_NAME, "r" );
- if( !fp ) {
+ fp = fopen(SYS_SITECFG_NAME, "r");
+ if (!fp) {
return;
}
- if( fstat( fileno( fp ), &st ) == 0 ) {
+ if (fstat(fileno(fp), &st) == 0) {
len = st.st_size;
- if( len >= cmd_buffer.maxsize ) {
+ if (len >= cmd_buffer.maxsize) {
len = cmd_buffer.maxsize - 1;
}
- r = fread( cmd_buffer.text, 1, len, fp );
+ r = fread(cmd_buffer.text, 1, len, fp);
cmd_buffer.text[r] = 0;
- cmd_buffer.cursize = COM_Compress( cmd_buffer.text );
+ cmd_buffer.cursize = COM_Compress(cmd_buffer.text);
}
- fclose( fp );
+ fclose(fp);
- if( cmd_buffer.cursize ) {
- Com_Printf( "Execing %s\n", SYS_SITECFG_NAME );
- Cbuf_Execute( &cmd_buffer );
+ if (cmd_buffer.cursize) {
+ Com_Printf("Execing %s\n", SYS_SITECFG_NAME);
+ Cbuf_Execute(&cmd_buffer);
}
}
-void Sys_Sleep( int msec ) {
+void Sys_Sleep(int msec)
+{
struct timespec req;
req.tv_sec = msec / 1000;
- req.tv_nsec = ( msec % 1000 ) * 1000000;
- nanosleep( &req, NULL );
+ req.tv_nsec = (msec % 1000) * 1000000;
+ nanosleep(&req, NULL);
}
#if USE_AC_CLIENT
-qboolean Sys_GetAntiCheatAPI( void ) {
- Sys_Sleep( 1500 );
+qboolean Sys_GetAntiCheatAPI(void)
+{
+ Sys_Sleep(1500);
return qfalse;
}
#endif
-static void hup_handler( int signum ) {
+static void hup_handler(int signum)
+{
Com_FlushLogs();
}
-static void term_handler( int signum ) {
+static void term_handler(int signum)
+{
#ifdef _GNU_SOURCE
- Com_Printf( "%s\n", strsignal( signum ) );
+ Com_Printf("%s\n", strsignal(signum));
#else
- Com_Printf( "Received signal %d, exiting\n", signum );
+ Com_Printf("Received signal %d, exiting\n", signum);
#endif
- Com_Quit( NULL, ERR_DISCONNECT );
+ Com_Quit(NULL, ERR_DISCONNECT);
}
-static void kill_handler( int signum ) {
+static void kill_handler(int signum)
+{
#if USE_SYSCON
tty_shutdown_input();
#endif
@@ -682,12 +707,12 @@ static void kill_handler( int signum ) {
#endif
#ifdef _GNU_SOURCE
- fprintf( stderr, "%s\n", strsignal( signum ) );
+ fprintf(stderr, "%s\n", strsignal(signum));
#else
- fprintf( stderr, "Received signal %d, aborting\n", signum );
+ fprintf(stderr, "Received signal %d, aborting\n", signum);
#endif
- exit( EXIT_FAILURE );
+ exit(EXIT_FAILURE);
}
/*
@@ -695,78 +720,79 @@ static void kill_handler( int signum ) {
Sys_Init
=================
*/
-void Sys_Init( void ) {
+void Sys_Init(void)
+{
char *homedir;
- signal( SIGTERM, term_handler );
- signal( SIGINT, term_handler );
- signal( SIGTTIN, SIG_IGN );
- signal( SIGTTOU, SIG_IGN );
- signal( SIGUSR1, hup_handler );
+ signal(SIGTERM, term_handler);
+ signal(SIGINT, term_handler);
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGUSR1, hup_handler);
// basedir <path>
// allows the game to run from outside the data tree
- sys_basedir = Cvar_Get( "basedir", DATADIR, CVAR_NOSET );
+ sys_basedir = Cvar_Get("basedir", DATADIR, CVAR_NOSET);
// homedir <path>
// specifies per-user writable directory for demos, screenshots, etc
- if( HOMEDIR[0] == '~' ) {
- char *s = getenv( "HOME" );
- if( s && *s ) {
- homedir = va( "%s%s", s, HOMEDIR + 1 );
+ if (HOMEDIR[0] == '~') {
+ char *s = getenv("HOME");
+ if (s && *s) {
+ homedir = va("%s%s", s, HOMEDIR + 1);
} else {
homedir = "";
}
} else {
homedir = HOMEDIR;
}
- sys_homedir = Cvar_Get( "homedir", homedir, CVAR_NOSET );
- sys_libdir = Cvar_Get( "libdir", LIBDIR, CVAR_NOSET );
- sys_forcegamelib = Cvar_Get( "sys_forcegamelib", "", CVAR_NOSET );
+ sys_homedir = Cvar_Get("homedir", homedir, CVAR_NOSET);
+ sys_libdir = Cvar_Get("libdir", LIBDIR, CVAR_NOSET);
+ sys_forcegamelib = Cvar_Get("sys_forcegamelib", "", CVAR_NOSET);
#if USE_SYSCON
// we want TTY support enabled if started from terminal,
// but don't want any output by default if launched without one
// (from X session for example)
- sys_console = Cvar_Get( "sys_console", isatty( STDIN_FILENO ) &&
- isatty( STDOUT_FILENO ) ? "2" : "0", CVAR_NOSET );
+ sys_console = Cvar_Get("sys_console", isatty(STDIN_FILENO) &&
+ isatty(STDOUT_FILENO) ? "2" : "0", CVAR_NOSET);
- if( sys_console->integer > 0 ) {
+ if (sys_console->integer > 0) {
int ret;
// change stdin to non-blocking
- ret = fcntl( STDIN_FILENO, F_GETFL, 0 );
- if( !(ret & O_NONBLOCK) )
- fcntl( STDIN_FILENO, F_SETFL, ret | O_NONBLOCK );
+ ret = fcntl(STDIN_FILENO, F_GETFL, 0);
+ if (!(ret & O_NONBLOCK))
+ fcntl(STDIN_FILENO, F_SETFL, ret | O_NONBLOCK);
// change stdout to non-blocking
- ret = fcntl( STDOUT_FILENO, F_GETFL, 0 );
- if( !(ret & O_NONBLOCK) )
- fcntl( STDOUT_FILENO, F_SETFL, ret | O_NONBLOCK );
+ ret = fcntl(STDOUT_FILENO, F_GETFL, 0);
+ if (!(ret & O_NONBLOCK))
+ fcntl(STDOUT_FILENO, F_SETFL, ret | O_NONBLOCK);
// add stdin to the list of descriptors to wait on
- tty_io = IO_Add( STDIN_FILENO );
+ tty_io = IO_Add(STDIN_FILENO);
tty_io->wantread = qtrue;
// init optional TTY support
- if( sys_console->integer > 1 )
+ if (sys_console->integer > 1)
tty_init_input();
- signal( SIGHUP, term_handler );
+ signal(SIGHUP, term_handler);
} else
#endif
- if( Com_IsDedicated() ) {
- signal( SIGHUP, hup_handler );
- }
+ if (Com_IsDedicated()) {
+ signal(SIGHUP, hup_handler);
+ }
- sys_parachute = Cvar_Get( "sys_parachute", "1", CVAR_NOSET );
+ sys_parachute = Cvar_Get("sys_parachute", "1", CVAR_NOSET);
- if( sys_parachute->integer ) {
+ if (sys_parachute->integer) {
// perform some cleanup when crashing
- signal( SIGSEGV, kill_handler );
- signal( SIGILL, kill_handler );
- signal( SIGFPE, kill_handler );
- signal( SIGTRAP, kill_handler );
+ signal(SIGSEGV, kill_handler);
+ signal(SIGILL, kill_handler);
+ signal(SIGFPE, kill_handler);
+ signal(SIGTRAP, kill_handler);
}
}
@@ -776,15 +802,16 @@ void Sys_Init( void ) {
Sys_Printf
================
*/
-void Sys_Printf( const char *fmt, ... ) {
+void Sys_Printf(const char *fmt, ...)
+{
va_list argptr;
char msg[MAXPRINTMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- Sys_ConsoleOutput( msg );
+ Sys_ConsoleOutput(msg);
}
#endif
@@ -793,7 +820,8 @@ void Sys_Printf( const char *fmt, ... ) {
Sys_Error
=================
*/
-void Sys_Error( const char *error, ... ) {
+void Sys_Error(const char *error, ...)
+{
va_list argptr;
char text[MAXERRORMSG];
@@ -805,14 +833,14 @@ void Sys_Error( const char *error, ... ) {
VID_FatalShutdown();
#endif
- va_start( argptr, error );
- Q_vsnprintf( text, sizeof( text ), error, argptr );
- va_end( argptr );
+ va_start(argptr, error);
+ Q_vsnprintf(text, sizeof(text), error, argptr);
+ va_end(argptr);
- fprintf( stderr, "********************\n"
- "FATAL: %s\n"
- "********************\n", text );
- exit( EXIT_FAILURE );
+ fprintf(stderr, "********************\n"
+ "FATAL: %s\n"
+ "********************\n", text);
+ exit(EXIT_FAILURE);
}
/*
@@ -828,9 +856,10 @@ DLL LOADING
Sys_FreeLibrary
=================
*/
-void Sys_FreeLibrary( void *handle ) {
- if( handle && dlclose( handle ) ) {
- Com_Error( ERR_FATAL, "dlclose failed on %p: %s", handle, dlerror() );
+void Sys_FreeLibrary(void *handle)
+{
+ if (handle && dlclose(handle)) {
+ Com_Error(ERR_FATAL, "dlclose failed on %p: %s", handle, dlerror());
}
}
@@ -839,37 +868,39 @@ void Sys_FreeLibrary( void *handle ) {
Sys_LoadLibrary
=================
*/
-void *Sys_LoadLibrary( const char *path, const char *sym, void **handle ) {
+void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
+{
void *module, *entry;
*handle = NULL;
- module = dlopen( path, RTLD_LAZY );
- if( !module ) {
- Com_DPrintf( "%s failed: %s\n", __func__, dlerror() );
+ module = dlopen(path, RTLD_LAZY);
+ if (!module) {
+ Com_DPrintf("%s failed: %s\n", __func__, dlerror());
return NULL;
}
- if( sym ) {
- entry = dlsym( module, sym );
- if( !entry ) {
- Com_DPrintf( "%s failed: %s\n", __func__, dlerror() );
- dlclose( module );
+ if (sym) {
+ entry = dlsym(module, sym);
+ if (!entry) {
+ Com_DPrintf("%s failed: %s\n", __func__, dlerror());
+ dlclose(module);
return NULL;
}
} else {
entry = NULL;
}
- Com_DPrintf( "%s succeeded: %s\n", __func__, path );
+ Com_DPrintf("%s succeeded: %s\n", __func__, path);
*handle = module;
return entry;
}
-void *Sys_GetProcAddress( void *handle, const char *sym ) {
- return dlsym( handle, sym );
+void *Sys_GetProcAddress(void *handle, const char *sym)
+{
+ return dlsym(handle, sym);
}
/*
@@ -880,8 +911,9 @@ MISC
===============================================================================
*/
-static void *copy_info( const char *name, const struct stat *st ) {
- return FS_CopyInfo( name, st->st_size, st->st_ctime, st->st_mtime );
+static void *copy_info(const char *name, const struct stat *st)
+{
+ return FS_CopyInfo(name, st->st_size, st->st_ctime, st->st_mtime);
}
/*
@@ -894,13 +926,13 @@ Internal function to filesystem. Conventions apply:
- depth must be 0 on the first call
=================
*/
-void Sys_ListFiles_r( const char *path,
- const char *filter,
- unsigned flags,
- size_t baselen,
- int *count_p,
- void **files,
- int depth )
+void Sys_ListFiles_r(const char *path,
+ const char *filter,
+ unsigned flags,
+ size_t baselen,
+ int *count_p,
+ void **files,
+ int depth)
{
struct dirent *ent;
DIR *dir;
@@ -910,93 +942,92 @@ void Sys_ListFiles_r( const char *path,
size_t len;
void *info;
- if( ( dir = opendir( path ) ) == NULL ) {
+ if ((dir = opendir(path)) == NULL) {
return;
}
- while( ( ent = readdir( dir ) ) != NULL ) {
- if( ent->d_name[0] == '.' ) {
+ while ((ent = readdir(dir)) != NULL) {
+ if (ent->d_name[0] == '.') {
continue; // ignore dotfiles
}
- len = Q_concat( fullpath, sizeof( fullpath ),
- path, "/", ent->d_name, NULL );
- if( len >= sizeof( fullpath ) ) {
+ len = Q_concat(fullpath, sizeof(fullpath),
+ path, "/", ent->d_name, NULL);
+ if (len >= sizeof(fullpath)) {
continue;
}
- if( stat( fullpath, &st ) == -1 ) {
+ if (stat(fullpath, &st) == -1) {
continue;
}
// pattern search implies recursive search
- if( ( flags & FS_SEARCH_BYFILTER ) &&
- S_ISDIR( st.st_mode ) && depth < MAX_LISTED_DEPTH )
- {
- Sys_ListFiles_r( fullpath, filter, flags, baselen,
- count_p, files, depth + 1 );
+ if ((flags & FS_SEARCH_BYFILTER) &&
+ S_ISDIR(st.st_mode) && depth < MAX_LISTED_DEPTH) {
+ Sys_ListFiles_r(fullpath, filter, flags, baselen,
+ count_p, files, depth + 1);
// re-check count
- if( *count_p >= MAX_LISTED_FILES ) {
+ if (*count_p >= MAX_LISTED_FILES) {
break;
}
}
// check type
- if( flags & FS_SEARCH_DIRSONLY ) {
- if( !S_ISDIR( st.st_mode ) ) {
+ if (flags & FS_SEARCH_DIRSONLY) {
+ if (!S_ISDIR(st.st_mode)) {
continue;
}
} else {
- if( !S_ISREG( st.st_mode ) ) {
+ if (!S_ISREG(st.st_mode)) {
continue;
}
}
// check filter
- if( filter ) {
- if( flags & FS_SEARCH_BYFILTER ) {
- if( !FS_WildCmp( filter, fullpath + baselen ) ) {
+ if (filter) {
+ if (flags & FS_SEARCH_BYFILTER) {
+ if (!FS_WildCmp(filter, fullpath + baselen)) {
continue;
}
} else {
- if( !FS_ExtCmp( filter, ent->d_name ) ) {
+ if (!FS_ExtCmp(filter, ent->d_name)) {
continue;
}
}
}
// strip path
- if( flags & FS_SEARCH_SAVEPATH ) {
+ if (flags & FS_SEARCH_SAVEPATH) {
name = fullpath + baselen;
} else {
name = ent->d_name;
}
// strip extension
- if( flags & FS_SEARCH_STRIPEXT ) {
- *COM_FileExtension( name ) = 0;
+ if (flags & FS_SEARCH_STRIPEXT) {
+ *COM_FileExtension(name) = 0;
- if( !*name ) {
+ if (!*name) {
continue;
}
}
// copy info off
- if( flags & FS_SEARCH_EXTRAINFO ) {
- info = copy_info( name, &st );
+ if (flags & FS_SEARCH_EXTRAINFO) {
+ info = copy_info(name, &st);
} else {
- info = FS_CopyString( name );
+ info = FS_CopyString(name);
}
files[(*count_p)++] = info;
- if( *count_p >= MAX_LISTED_FILES ) {
+ if (*count_p >= MAX_LISTED_FILES) {
break;
}
}
- closedir( dir );
+ closedir(dir);
}
/*
@@ -1004,26 +1035,27 @@ void Sys_ListFiles_r( const char *path,
main
=================
*/
-int main( int argc, char **argv ) {
- if( argc > 1 ) {
- if( !strcmp( argv[1], "-v" ) || !strcmp( argv[1], "--version" ) ) {
- fprintf( stderr, "%s\n", com_version_string );
+int main(int argc, char **argv)
+{
+ if (argc > 1) {
+ if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
+ fprintf(stderr, "%s\n", com_version_string);
return 0;
}
- if( !strcmp( argv[1], "-h" ) || !strcmp( argv[1], "--help" ) ) {
- fprintf( stderr, "Usage: %s [+command arguments] [...]\n", argv[0] );
+ if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
+ fprintf(stderr, "Usage: %s [+command arguments] [...]\n", argv[0]);
return 0;
}
}
- if( !getuid() || !geteuid() ) {
- fprintf( stderr, "You can not run " PRODUCT " as superuser "
- "for security reasons!\n" );
+ if (!getuid() || !geteuid()) {
+ fprintf(stderr, "You can not run " PRODUCT " as superuser "
+ "for security reasons!\n");
return 1;
}
- Qcommon_Init( argc, argv );
- while( 1 ) {
+ Qcommon_Init(argc, argv);
+ while (1) {
Qcommon_Frame();
}
diff --git a/src/sys_win.c b/src/sys_win.c
index 31961f9..844c92a 100644
--- a/src/sys_win.c
+++ b/src/sys_win.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -78,32 +78,35 @@ static int sys_hidden;
static CONSOLE_SCREEN_BUFFER_INFO sbinfo;
static qboolean gotConsole;
-static void write_console_data( void *data, size_t len ) {
+static void write_console_data(void *data, size_t len)
+{
DWORD dummy;
- WriteFile( houtput, data, len, &dummy, NULL );
+ WriteFile(houtput, data, len, &dummy, NULL);
}
-static void hide_console_input( void ) {
+static void hide_console_input(void)
+{
int i;
- if( !sys_hidden ) {
- for( i = 0; i <= sys_con.inputLine.cursorPos; i++ ) {
- write_console_data( "\b \b", 3 );
+ if (!sys_hidden) {
+ for (i = 0; i <= sys_con.inputLine.cursorPos; i++) {
+ write_console_data("\b \b", 3);
}
}
sys_hidden++;
}
-static void show_console_input( void ) {
- if( !sys_hidden ) {
+static void show_console_input(void)
+{
+ if (!sys_hidden) {
return;
}
sys_hidden--;
- if( !sys_hidden ) {
- write_console_data( "]", 1 );
- write_console_data( sys_con.inputLine.text, sys_con.inputLine.cursorPos );
+ if (!sys_hidden) {
+ write_console_data("]", 1);
+ write_console_data(sys_con.inputLine.text, sys_con.inputLine.cursorPos);
}
}
@@ -112,7 +115,8 @@ static void show_console_input( void ) {
Sys_ConsoleInput
================
*/
-void Sys_RunConsole( void ) {
+void Sys_RunConsole(void)
+{
INPUT_RECORD recs[MAX_CONSOLE_INPUT_EVENTS];
int ch;
DWORD numread, numevents;
@@ -120,118 +124,118 @@ void Sys_RunConsole( void ) {
inputField_t *f;
char *s;
- if( hinput == INVALID_HANDLE_VALUE ) {
+ if (hinput == INVALID_HANDLE_VALUE) {
return;
}
- if( !gotConsole ) {
+ if (!gotConsole) {
return;
}
f = &sys_con.inputLine;
- while( 1 ) {
- if( !GetNumberOfConsoleInputEvents( hinput, &numevents ) ) {
- Com_EPrintf( "Error %lu getting number of console events.\n", GetLastError() );
+ while (1) {
+ if (!GetNumberOfConsoleInputEvents(hinput, &numevents)) {
+ Com_EPrintf("Error %lu getting number of console events.\n", GetLastError());
gotConsole = qfalse;
return;
}
- if( numevents <= 0 )
+ if (numevents <= 0)
break;
- if( numevents > MAX_CONSOLE_INPUT_EVENTS ) {
+ if (numevents > MAX_CONSOLE_INPUT_EVENTS) {
numevents = MAX_CONSOLE_INPUT_EVENTS;
}
- if( !ReadConsoleInput( hinput, recs, numevents, &numread ) ) {
- Com_EPrintf( "Error %lu reading console input.\n", GetLastError() );
+ if (!ReadConsoleInput(hinput, recs, numevents, &numread)) {
+ Com_EPrintf("Error %lu reading console input.\n", GetLastError());
gotConsole = qfalse;
return;
}
-
- for( i = 0; i < numread; i++ ) {
- if( recs[i].EventType == WINDOW_BUFFER_SIZE_EVENT ) {
+
+ for (i = 0; i < numread; i++) {
+ if (recs[i].EventType == WINDOW_BUFFER_SIZE_EVENT) {
// determine terminal width
size_t width = recs[i].Event.WindowBufferSizeEvent.dwSize.X;
- if( !width ) {
- Com_EPrintf( "Invalid console buffer width.\n" );
+ if (!width) {
+ Com_EPrintf("Invalid console buffer width.\n");
gotConsole = qfalse;
return;
}
-
+
sys_con.widthInChars = width;
-
+
// figure out input line width
width--;
- if( width > MAX_FIELD_TEXT - 1 ) {
+ if (width > MAX_FIELD_TEXT - 1) {
width = MAX_FIELD_TEXT - 1;
}
hide_console_input();
- IF_Init( &sys_con.inputLine, width, width );
+ IF_Init(&sys_con.inputLine, width, width);
show_console_input();
continue;
}
- if( recs[i].EventType != KEY_EVENT ) {
+ if (recs[i].EventType != KEY_EVENT) {
continue;
}
-
- if( !recs[i].Event.KeyEvent.bKeyDown ) {
+
+ if (!recs[i].Event.KeyEvent.bKeyDown) {
continue;
}
- switch( recs[i].Event.KeyEvent.wVirtualKeyCode ) {
+ switch (recs[i].Event.KeyEvent.wVirtualKeyCode) {
case VK_UP:
hide_console_input();
- Prompt_HistoryUp( &sys_con );
+ Prompt_HistoryUp(&sys_con);
show_console_input();
break;
case VK_DOWN:
hide_console_input();
- Prompt_HistoryDown( &sys_con );
+ Prompt_HistoryDown(&sys_con);
show_console_input();
break;
case VK_RETURN:
hide_console_input();
- s = Prompt_Action( &sys_con );
- if( s ) {
- if( *s == '\\' || *s == '/' ) {
+ s = Prompt_Action(&sys_con);
+ if (s) {
+ if (*s == '\\' || *s == '/') {
s++;
}
- Sys_Printf( "]%s\n", s );
- Cbuf_AddText( &cmd_buffer, s );
- Cbuf_AddText( &cmd_buffer, "\n" );
+ Sys_Printf("]%s\n", s);
+ Cbuf_AddText(&cmd_buffer, s);
+ Cbuf_AddText(&cmd_buffer, "\n");
} else {
- write_console_data( "\n", 1 );
+ write_console_data("\n", 1);
}
show_console_input();
break;
case VK_BACK:
- if( f->cursorPos ) {
+ if (f->cursorPos) {
f->text[--f->cursorPos] = 0;
- write_console_data( "\b \b", 3 );
+ write_console_data("\b \b", 3);
}
break;
case VK_TAB:
hide_console_input();
- Prompt_CompleteCommand( &sys_con, qfalse );
- f->cursorPos = strlen( f->text );
+ Prompt_CompleteCommand(&sys_con, qfalse);
+ f->cursorPos = strlen(f->text);
show_console_input();
break;
default:
ch = recs[i].Event.KeyEvent.uChar.AsciiChar;
- if( ch < 32 ) {
+ if (ch < 32) {
break;
}
- if( f->cursorPos < f->maxChars - 1 ) {
- write_console_data( &ch, 1 );
+ if (f->cursorPos < f->maxChars - 1) {
+ write_console_data(&ch, 1);
f->text[f->cursorPos] = ch;
f->text[++f->cursorPos] = 0;
}
break;
}
}
- }
+ }
}
#define FOREGROUND_BLACK 0
@@ -241,27 +245,28 @@ static const WORD textColors[8] = {
FOREGROUND_BLACK,
FOREGROUND_RED,
FOREGROUND_GREEN,
- FOREGROUND_RED|FOREGROUND_GREEN,
+ FOREGROUND_RED | FOREGROUND_GREEN,
FOREGROUND_BLUE,
- FOREGROUND_BLUE|FOREGROUND_GREEN,
- FOREGROUND_RED|FOREGROUND_BLUE,
+ FOREGROUND_BLUE | FOREGROUND_GREEN,
+ FOREGROUND_RED | FOREGROUND_BLUE,
FOREGROUND_WHITE
};
-void Sys_SetConsoleColor( color_index_t color ) {
+void Sys_SetConsoleColor(color_index_t color)
+{
WORD attr, w;
- if( houtput == INVALID_HANDLE_VALUE ) {
+ if (houtput == INVALID_HANDLE_VALUE) {
return;
}
- if( !gotConsole ) {
+ if (!gotConsole) {
return;
}
attr = sbinfo.wAttributes & ~FOREGROUND_WHITE;
- switch( color ) {
+ switch (color) {
case COLOR_NONE:
w = sbinfo.wAttributes;
break;
@@ -273,28 +278,29 @@ void Sys_SetConsoleColor( color_index_t color ) {
break;
}
- if( color != COLOR_NONE ) {
+ if (color != COLOR_NONE) {
hide_console_input();
}
- SetConsoleTextAttribute( houtput, w );
- if( color == COLOR_NONE ) {
+ SetConsoleTextAttribute(houtput, w);
+ if (color == COLOR_NONE) {
show_console_input();
}
}
-static void write_console_output( const char *text ) {
+static void write_console_output(const char *text)
+{
char buf[MAXPRINTMSG];
size_t len;
- for( len = 0; len < MAXPRINTMSG; len++ ) {
+ for (len = 0; len < MAXPRINTMSG; len++) {
int c = *text++;
- if( !c ) {
+ if (!c) {
break;
}
- buf[len] = Q_charascii( c );
+ buf[len] = Q_charascii(c);
}
- write_console_data( buf, len );
+ write_console_data(buf, len);
}
/*
@@ -304,81 +310,85 @@ Sys_ConsoleOutput
Print text to the dedicated console
================
*/
-void Sys_ConsoleOutput( const char *text ) {
- if( houtput == INVALID_HANDLE_VALUE ) {
+void Sys_ConsoleOutput(const char *text)
+{
+ if (houtput == INVALID_HANDLE_VALUE) {
return;
}
- if( !gotConsole ) {
- write_console_output( text );
+ if (!gotConsole) {
+ write_console_output(text);
} else {
hide_console_input();
- write_console_output( text );
+ write_console_output(text);
show_console_input();
}
}
-void Sys_SetConsoleTitle( const char *title ) {
- if( gotConsole ) {
- SetConsoleTitle( title );
+void Sys_SetConsoleTitle(const char *title)
+{
+ if (gotConsole) {
+ SetConsoleTitle(title);
}
}
-static BOOL WINAPI Sys_ConsoleCtrlHandler( DWORD dwCtrlType ) {
- if( errorEntered ) {
- exit( 1 );
+static BOOL WINAPI Sys_ConsoleCtrlHandler(DWORD dwCtrlType)
+{
+ if (errorEntered) {
+ exit(1);
}
shouldExit = SE_FULL;
return TRUE;
}
-static void Sys_ConsoleInit( void ) {
+static void Sys_ConsoleInit(void)
+{
DWORD mode;
size_t width;
#if USE_CLIENT
- if( !AllocConsole() ) {
- Com_EPrintf( "Couldn't create system console.\n" );
+ if (!AllocConsole()) {
+ Com_EPrintf("Couldn't create system console.\n");
return;
}
#elif USE_WINSVC
- if( statusHandle ) {
+ if (statusHandle) {
return;
}
#endif
- hinput = GetStdHandle( STD_INPUT_HANDLE );
- houtput = GetStdHandle( STD_OUTPUT_HANDLE );
- if( !GetConsoleScreenBufferInfo( houtput, &sbinfo ) ) {
- Com_EPrintf( "Couldn't get console buffer info.\n" );
+ hinput = GetStdHandle(STD_INPUT_HANDLE);
+ houtput = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (!GetConsoleScreenBufferInfo(houtput, &sbinfo)) {
+ Com_EPrintf("Couldn't get console buffer info.\n");
return;
}
// determine terminal width
width = sbinfo.dwSize.X;
- if( !width ) {
- Com_EPrintf( "Invalid console buffer width.\n" );
+ if (!width) {
+ Com_EPrintf("Invalid console buffer width.\n");
return;
}
sys_con.widthInChars = width;
sys_con.printf = Sys_Printf;
gotConsole = qtrue;
- SetConsoleTitle( PRODUCT " console" );
- SetConsoleCtrlHandler( Sys_ConsoleCtrlHandler, TRUE );
- GetConsoleMode( hinput, &mode );
+ SetConsoleTitle(PRODUCT " console");
+ SetConsoleCtrlHandler(Sys_ConsoleCtrlHandler, TRUE);
+ GetConsoleMode(hinput, &mode);
mode |= ENABLE_WINDOW_INPUT;
- SetConsoleMode( hinput, mode );
+ SetConsoleMode(hinput, mode);
// figure out input line width
width--;
- if( width > MAX_FIELD_TEXT - 1 ) {
+ if (width > MAX_FIELD_TEXT - 1) {
width = MAX_FIELD_TEXT - 1;
}
- IF_Init( &sys_con.inputLine, width, width );
+ IF_Init(&sys_con.inputLine, width, width);
- Com_DPrintf( "System console initialized (%d cols, %d rows).\n",
- sbinfo.dwSize.X, sbinfo.dwSize.Y );
+ Com_DPrintf("System console initialized (%d cols, %d rows).\n",
+ sbinfo.dwSize.X, sbinfo.dwSize.Y);
}
#endif // USE_SYSCON
@@ -393,133 +403,135 @@ SERVICE CONTROL
#if USE_WINSVC
-static void Sys_InstallService_f( void ) {
+static void Sys_InstallService_f(void)
+{
char servicePath[256];
char serviceName[1024];
SC_HANDLE scm, service;
DWORD error, length;
char *commandline;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <servicename> <+command> [...]\n"
- "Example: %s test +set net_port 27910 +map q2dm1\n",
- Cmd_Argv( 0 ), Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <servicename> <+command> [...]\n"
+ "Example: %s test +set net_port 27910 +map q2dm1\n",
+ Cmd_Argv(0), Cmd_Argv(0));
return;
}
- scm = OpenSCManager( NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS );
- if( !scm ) {
+ scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
+ if (!scm) {
error = GetLastError();
- if( error == ERROR_ACCESS_DENIED ) {
- Com_Printf( "Insufficient privileges for opening Service Control Manager.\n" );
+ if (error == ERROR_ACCESS_DENIED) {
+ Com_Printf("Insufficient privileges for opening Service Control Manager.\n");
} else {
- Com_EPrintf( "%#lx opening Service Control Manager.\n", error );
+ Com_EPrintf("%#lx opening Service Control Manager.\n", error);
}
return;
}
- Q_concat( serviceName, sizeof( serviceName ), "Q2PRO - ", Cmd_Argv( 1 ), NULL );
+ Q_concat(serviceName, sizeof(serviceName), "Q2PRO - ", Cmd_Argv(1), NULL);
- length = GetModuleFileName( NULL, servicePath, MAX_PATH );
- if( !length ) {
+ length = GetModuleFileName(NULL, servicePath, MAX_PATH);
+ if (!length) {
error = GetLastError();
- Com_EPrintf( "%#lx getting module file name.\n", error );
+ Com_EPrintf("%#lx getting module file name.\n", error);
goto fail;
}
- commandline = Cmd_RawArgsFrom( 2 );
- if( length + strlen( commandline ) + 10 > sizeof( servicePath ) - 1 ) {
- Com_Printf( "Oversize service command line.\n" );
+ commandline = Cmd_RawArgsFrom(2);
+ if (length + strlen(commandline) + 10 > sizeof(servicePath) - 1) {
+ Com_Printf("Oversize service command line.\n");
goto fail;
}
- strcpy( servicePath + length, " -service " );
- strcpy( servicePath + length + 10, commandline );
+ strcpy(servicePath + length, " -service ");
+ strcpy(servicePath + length + 10, commandline);
service = CreateService(
- scm,
- serviceName,
- serviceName,
- SERVICE_START,
- SERVICE_WIN32_OWN_PROCESS,
- SERVICE_AUTO_START,
- SERVICE_ERROR_IGNORE,
- servicePath,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL );
-
- if( !service ) {
+ scm,
+ serviceName,
+ serviceName,
+ SERVICE_START,
+ SERVICE_WIN32_OWN_PROCESS,
+ SERVICE_AUTO_START,
+ SERVICE_ERROR_IGNORE,
+ servicePath,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+
+ if (!service) {
error = GetLastError();
- if( error == ERROR_SERVICE_EXISTS || error == ERROR_DUPLICATE_SERVICE_NAME ) {
- Com_Printf( "Service already exists.\n" );
+ if (error == ERROR_SERVICE_EXISTS || error == ERROR_DUPLICATE_SERVICE_NAME) {
+ Com_Printf("Service already exists.\n");
} else {
- Com_EPrintf( "%#lx creating service.\n", error );
+ Com_EPrintf("%#lx creating service.\n", error);
}
goto fail;
}
- Com_Printf( "Service created successfully.\n" );
+ Com_Printf("Service created successfully.\n");
- CloseServiceHandle( service );
+ CloseServiceHandle(service);
fail:
- CloseServiceHandle( scm );
+ CloseServiceHandle(scm);
}
-static void Sys_DeleteService_f( void ) {
+static void Sys_DeleteService_f(void)
+{
char serviceName[256];
SC_HANDLE scm, service;
DWORD error;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <servicename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <servicename>\n", Cmd_Argv(0));
return;
}
- scm = OpenSCManager( NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS );
- if( !scm ) {
+ scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
+ if (!scm) {
error = GetLastError();
- if( error == ERROR_ACCESS_DENIED ) {
- Com_Printf( "Insufficient privileges for opening Service Control Manager.\n" );
+ if (error == ERROR_ACCESS_DENIED) {
+ Com_Printf("Insufficient privileges for opening Service Control Manager.\n");
} else {
- Com_EPrintf( "%#lx opening Service Control Manager.\n", error );
+ Com_EPrintf("%#lx opening Service Control Manager.\n", error);
}
return;
}
- Q_concat( serviceName, sizeof( serviceName ), "Q2PRO - ", Cmd_Argv( 1 ), NULL );
+ Q_concat(serviceName, sizeof(serviceName), "Q2PRO - ", Cmd_Argv(1), NULL);
service = OpenService(
- scm,
- serviceName,
- DELETE );
+ scm,
+ serviceName,
+ DELETE);
- if( !service ) {
+ if (!service) {
error = GetLastError();
- if( error == ERROR_SERVICE_DOES_NOT_EXIST ) {
- Com_Printf( "Service doesn't exist.\n" );
+ if (error == ERROR_SERVICE_DOES_NOT_EXIST) {
+ Com_Printf("Service doesn't exist.\n");
} else {
- Com_EPrintf( "%#lx opening service.\n", error );
+ Com_EPrintf("%#lx opening service.\n", error);
}
goto fail;
}
- if( !DeleteService( service ) ) {
+ if (!DeleteService(service)) {
error = GetLastError();
- if( error == ERROR_SERVICE_MARKED_FOR_DELETE ) {
- Com_Printf( "Service has already been marked for deletion.\n" );
+ if (error == ERROR_SERVICE_MARKED_FOR_DELETE) {
+ Com_Printf("Service has already been marked for deletion.\n");
} else {
- Com_EPrintf( "%#lx deleting service.\n", error );
+ Com_EPrintf("%#lx deleting service.\n", error);
}
} else {
- Com_Printf( "Service deleted successfully.\n" );
+ Com_Printf("Service deleted successfully.\n");
}
- CloseServiceHandle( service );
+ CloseServiceHandle(service);
fail:
- CloseServiceHandle( scm );
+ CloseServiceHandle(scm);
}
#endif // USE_WINSVC
@@ -532,53 +544,57 @@ HUNK
===============================================================================
*/
-void Hunk_Begin( mempool_t *pool, size_t maxsize ) {
+void Hunk_Begin(mempool_t *pool, size_t maxsize)
+{
// reserve a huge chunk of memory, but don't commit any yet
pool->cursize = 0;
- pool->maxsize = ( maxsize + 4095 ) & ~4095;
- pool->base = VirtualAlloc( NULL, pool->maxsize, MEM_RESERVE, PAGE_NOACCESS );
- if( !pool->base ) {
- Com_Error( ERR_FATAL,
- "VirtualAlloc reserve %"PRIz" bytes failed. GetLastError() = %lu",
- pool->maxsize, GetLastError() );
+ pool->maxsize = (maxsize + 4095) & ~4095;
+ pool->base = VirtualAlloc(NULL, pool->maxsize, MEM_RESERVE, PAGE_NOACCESS);
+ if (!pool->base) {
+ Com_Error(ERR_FATAL,
+ "VirtualAlloc reserve %"PRIz" bytes failed. GetLastError() = %lu",
+ pool->maxsize, GetLastError());
}
}
-void *Hunk_Alloc( mempool_t *pool, size_t size ) {
+void *Hunk_Alloc(mempool_t *pool, size_t size)
+{
void *buf;
// round to cacheline
- size = ( size + 63 ) & ~63;
+ size = (size + 63) & ~63;
pool->cursize += size;
- if( pool->cursize > pool->maxsize )
- Com_Error( ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size );
+ if (pool->cursize > pool->maxsize)
+ Com_Error(ERR_FATAL, "%s: couldn't allocate %"PRIz" bytes", __func__, size);
// commit pages as needed
- buf = VirtualAlloc( pool->base, pool->cursize, MEM_COMMIT, PAGE_READWRITE );
- if( !buf ) {
- Com_Error( ERR_FATAL,
- "VirtualAlloc commit %"PRIz" bytes failed. GetLastError() = %lu",
- pool->cursize, GetLastError() );
+ buf = VirtualAlloc(pool->base, pool->cursize, MEM_COMMIT, PAGE_READWRITE);
+ if (!buf) {
+ Com_Error(ERR_FATAL,
+ "VirtualAlloc commit %"PRIz" bytes failed. GetLastError() = %lu",
+ pool->cursize, GetLastError());
}
- return ( byte * )pool->base + pool->cursize - size;
+ return (byte *)pool->base + pool->cursize - size;
}
-void Hunk_End( mempool_t *pool ) {
+void Hunk_End(mempool_t *pool)
+{
// for statistics
- pool->mapped = ( pool->cursize + 4095 ) & ~4095;
+ pool->mapped = (pool->cursize + 4095) & ~4095;
}
-void Hunk_Free( mempool_t *pool ) {
- if( pool->base ) {
- if( !VirtualFree( pool->base, 0, MEM_RELEASE ) ) {
- Com_Error( ERR_FATAL, "VirtualFree failed. GetLastError() = %lu",
- GetLastError() );
+void Hunk_Free(mempool_t *pool)
+{
+ if (pool->base) {
+ if (!VirtualFree(pool->base, 0, MEM_RELEASE)) {
+ Com_Error(ERR_FATAL, "VirtualFree failed. GetLastError() = %lu",
+ GetLastError());
}
}
- memset( pool, 0, sizeof( *pool ) );
+ memset(pool, 0, sizeof(*pool));
}
/*
@@ -595,15 +611,16 @@ MISC
Sys_Printf
================
*/
-void Sys_Printf( const char *fmt, ... ) {
+void Sys_Printf(const char *fmt, ...)
+{
va_list argptr;
char msg[MAXPRINTMSG];
- va_start( argptr, fmt );
- Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
+ va_end(argptr);
- Sys_ConsoleOutput( msg );
+ Sys_ConsoleOutput(msg);
}
#endif
@@ -612,37 +629,38 @@ void Sys_Printf( const char *fmt, ... ) {
Sys_Error
================
*/
-void Sys_Error( const char *error, ... ) {
+void Sys_Error(const char *error, ...)
+{
va_list argptr;
char text[MAXERRORMSG];
- va_start( argptr, error );
- Q_vsnprintf( text, sizeof( text ), error, argptr );
- va_end( argptr );
+ va_start(argptr, error);
+ Q_vsnprintf(text, sizeof(text), error, argptr);
+ va_end(argptr);
errorEntered = qtrue;
#if USE_SYSCON
- Sys_SetConsoleColor( COLOR_RED );
- Sys_Printf( "********************\n"
- "FATAL: %s\n"
- "********************\n", text );
- Sys_SetConsoleColor( COLOR_NONE );
+ Sys_SetConsoleColor(COLOR_RED);
+ Sys_Printf("********************\n"
+ "FATAL: %s\n"
+ "********************\n", text);
+ Sys_SetConsoleColor(COLOR_NONE);
#endif
#if USE_WINSVC
- if( !statusHandle )
+ if (!statusHandle)
#endif
{
#if USE_SYSCON
- if( gotConsole ) {
- Sleep( INFINITE );
+ if (gotConsole) {
+ Sleep(INFINITE);
}
#endif
- MessageBoxA( NULL, text, PRODUCT " Fatal Error", MB_ICONERROR | MB_OK );
+ MessageBoxA(NULL, text, PRODUCT " Fatal Error", MB_ICONERROR | MB_OK);
}
- exit( 1 );
+ exit(1);
}
/*
@@ -652,38 +670,43 @@ Sys_Quit
This function never returns.
================
*/
-void Sys_Quit( void ) {
- timeEndPeriod( 1 );
+void Sys_Quit(void)
+{
+ timeEndPeriod(1);
#if USE_CLIENT
#if USE_SYSCON
- if( dedicated && dedicated->integer ) {
+ if (dedicated && dedicated->integer) {
FreeConsole();
}
#endif
#elif USE_WINSVC
- if( statusHandle && !shouldExit ) {
+ if (statusHandle && !shouldExit) {
shouldExit = SE_YES;
Com_AbortFrame();
}
#endif
- exit( 0 );
+ exit(0);
}
-void Sys_DebugBreak( void ) {
+void Sys_DebugBreak(void)
+{
DebugBreak();
}
-unsigned Sys_Milliseconds( void ) {
+unsigned Sys_Milliseconds(void)
+{
return timeGetTime();
}
-void Sys_AddDefaultConfig( void ) {
+void Sys_AddDefaultConfig(void)
+{
}
-void Sys_Sleep( int msec ) {
- Sleep( msec );
+void Sys_Sleep(int msec)
+{
+ Sleep(msec);
}
/*
@@ -691,79 +714,80 @@ void Sys_Sleep( int msec ) {
Sys_Init
================
*/
-void Sys_Init( void ) {
+void Sys_Init(void)
+{
OSVERSIONINFO vinfo;
#ifndef _WIN64
HMODULE module;
- BOOL (WINAPI *pSetProcessDEPPolicy)( DWORD );
+ BOOL (WINAPI * pSetProcessDEPPolicy)(DWORD);
#endif
cvar_t *var = NULL;
- timeBeginPeriod( 1 );
+ timeBeginPeriod(1);
// check windows version
- vinfo.dwOSVersionInfoSize = sizeof( vinfo );
- if( !GetVersionEx( &vinfo ) ) {
- Sys_Error( "Couldn't get OS info" );
+ vinfo.dwOSVersionInfoSize = sizeof(vinfo);
+ if (!GetVersionEx(&vinfo)) {
+ Sys_Error("Couldn't get OS info");
}
- if( vinfo.dwPlatformId != VER_PLATFORM_WIN32_NT ) {
- Sys_Error( PRODUCT " requires Windows NT" );
+ if (vinfo.dwPlatformId != VER_PLATFORM_WIN32_NT) {
+ Sys_Error(PRODUCT " requires Windows NT");
}
- if( vinfo.dwMajorVersion < 5 ) {
- Sys_Error( PRODUCT " requires Windows 2000 or greater" );
+ if (vinfo.dwMajorVersion < 5) {
+ Sys_Error(PRODUCT " requires Windows 2000 or greater");
}
// basedir <path>
// allows the game to run from outside the data tree
- sys_basedir = Cvar_Get( "basedir", currentDirectory, CVAR_NOSET );
- sys_libdir = Cvar_Get( "libdir", currentDirectory, CVAR_NOSET );
-
+ sys_basedir = Cvar_Get("basedir", currentDirectory, CVAR_NOSET);
+ sys_libdir = Cvar_Get("libdir", currentDirectory, CVAR_NOSET);
+
// homedir <path>
// specifies per-user writable directory for demos, screenshots, etc
- sys_homedir = Cvar_Get( "homedir", "", CVAR_NOSET );
+ sys_homedir = Cvar_Get("homedir", "", CVAR_NOSET);
- sys_forcegamelib = Cvar_Get( "sys_forcegamelib", "", CVAR_NOSET );
+ sys_forcegamelib = Cvar_Get("sys_forcegamelib", "", CVAR_NOSET);
#if USE_WINSVC
- Cmd_AddCommand( "installservice", Sys_InstallService_f );
- Cmd_AddCommand( "deleteservice", Sys_DeleteService_f );
+ Cmd_AddCommand("installservice", Sys_InstallService_f);
+ Cmd_AddCommand("deleteservice", Sys_DeleteService_f);
#endif
#if USE_SYSCON
- houtput = GetStdHandle( STD_OUTPUT_HANDLE );
+ houtput = GetStdHandle(STD_OUTPUT_HANDLE);
#if USE_CLIENT
- sys_viewlog = Cvar_Get( "sys_viewlog", "0", CVAR_NOSET );
+ sys_viewlog = Cvar_Get("sys_viewlog", "0", CVAR_NOSET);
- if( dedicated->integer || sys_viewlog->integer )
+ if (dedicated->integer || sys_viewlog->integer)
#endif
Sys_ConsoleInit();
#endif // USE_SYSCON
#if USE_DBGHELP
- var = Cvar_Get( "sys_disablecrashdump", "0", CVAR_NOSET );
+ var = Cvar_Get("sys_disablecrashdump", "0", CVAR_NOSET);
// install our exception filter
- if( !var->integer ) {
+ if (!var->integer) {
mainProcessThread = GetCurrentThread();
prevExceptionFilter = SetUnhandledExceptionFilter(
- Sys_ExceptionFilter );
+ Sys_ExceptionFilter);
}
#endif
#ifndef _WIN64
- module = GetModuleHandle( "kernel32.dll" );
- if( module ) {
- pSetProcessDEPPolicy = GetProcAddress( module, "SetProcessDEPPolicy" );
- if( pSetProcessDEPPolicy ) {
- var = Cvar_Get( "sys_disabledep", "0", CVAR_NOSET );
+ module = GetModuleHandle("kernel32.dll");
+ if (module) {
+ pSetProcessDEPPolicy = GetProcAddress(module, "SetProcessDEPPolicy");
+ if (pSetProcessDEPPolicy) {
+ var = Cvar_Get("sys_disabledep", "0", CVAR_NOSET);
// opt-in or opt-out for DEP
- if( !var->integer ) {
+ if (!var->integer) {
pSetProcessDEPPolicy(
PROCESS_DEP_ENABLE |
- PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION );
- } else if( var->integer == 2 ) {
- pSetProcessDEPPolicy( 0 );
+ PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
+ } else if (var->integer == 2) {
+ pSetProcessDEPPolicy(0);
}
}
}
@@ -778,34 +802,36 @@ DLL LOADING
========================================================================
*/
-void Sys_FreeLibrary( void *handle ) {
- if( !handle ) {
+void Sys_FreeLibrary(void *handle)
+{
+ if (!handle) {
return;
}
- if( !FreeLibrary( handle ) ) {
- Com_Error( ERR_FATAL, "FreeLibrary failed on %p", handle );
+ if (!FreeLibrary(handle)) {
+ Com_Error(ERR_FATAL, "FreeLibrary failed on %p", handle);
}
}
-void *Sys_LoadLibrary( const char *path, const char *sym, void **handle ) {
+void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
+{
HMODULE module;
void *entry;
*handle = NULL;
- module = LoadLibraryA( path );
- if( !module ) {
- Com_DPrintf( "%s failed: LoadLibrary returned %lu on %s\n",
- __func__, GetLastError(), path );
+ module = LoadLibraryA(path);
+ if (!module) {
+ Com_DPrintf("%s failed: LoadLibrary returned %lu on %s\n",
+ __func__, GetLastError(), path);
return NULL;
}
- if( sym ) {
- entry = GetProcAddress( module, sym );
- if( !entry ) {
- Com_DPrintf( "%s failed: GetProcAddress returned %lu on %s\n",
- __func__, GetLastError(), path );
- FreeLibrary( module );
+ if (sym) {
+ entry = GetProcAddress(module, sym);
+ if (!entry) {
+ Com_DPrintf("%s failed: GetProcAddress returned %lu on %s\n",
+ __func__, GetLastError(), path);
+ FreeLibrary(module);
return NULL;
}
} else {
@@ -814,13 +840,14 @@ void *Sys_LoadLibrary( const char *path, const char *sym, void **handle ) {
*handle = module;
- Com_DPrintf( "%s succeeded: %s\n", __func__, path );
+ Com_DPrintf("%s succeeded: %s\n", __func__, path);
return entry;
}
-void *Sys_GetProcAddress( void *handle, const char *sym ) {
- return GetProcAddress( handle, sym );
+void *Sys_GetProcAddress(void *handle, const char *sym)
+{
+ return GetProcAddress(handle, sym);
}
/*
@@ -831,9 +858,10 @@ FILESYSTEM
========================================================================
*/
-static inline time_t file_time_to_unix( FILETIME *f ) {
- ULARGE_INTEGER u = *( ULARGE_INTEGER * )f;
- return ( time_t )( ( u.QuadPart - 116444736000000000ULL ) / 10000000 );
+static inline time_t file_time_to_unix(FILETIME *f)
+{
+ ULARGE_INTEGER u = *(ULARGE_INTEGER *)f;
+ return (time_t)((u.QuadPart - 116444736000000000ULL) / 10000000);
}
/*
@@ -841,30 +869,32 @@ static inline time_t file_time_to_unix( FILETIME *f ) {
Sys_GetPathInfo
================
*/
-qerror_t Sys_GetPathInfo( const char *path, file_info_t *info ) {
+qerror_t Sys_GetPathInfo(const char *path, file_info_t *info)
+{
WIN32_FILE_ATTRIBUTE_DATA data;
- if( !GetFileAttributesExA( path, GetFileExInfoStandard, &data ) ) {
+ if (!GetFileAttributesExA(path, GetFileExInfoStandard, &data)) {
return Q_ERR_NOENT; // TODO: return proper error code
}
- if( info ) {
+ if (info) {
info->size = data.nFileSizeLow;
- info->ctime = file_time_to_unix( &data.ftCreationTime );
- info->mtime = file_time_to_unix( &data.ftLastWriteTime );
+ info->ctime = file_time_to_unix(&data.ftCreationTime);
+ info->mtime = file_time_to_unix(&data.ftLastWriteTime);
}
return Q_ERR_SUCCESS;
}
-qerror_t Sys_GetFileInfo( FILE *fp, file_info_t *info ) {
+qerror_t Sys_GetFileInfo(FILE *fp, file_info_t *info)
+{
int pos, end;
// TODO: check for errors
- pos = ftell( fp );
- fseek( fp, 0, SEEK_END );
- end = ftell( fp );
- fseek( fp, pos, SEEK_SET );
+ pos = ftell(fp);
+ fseek(fp, 0, SEEK_END);
+ end = ftell(fp);
+ fseek(fp, pos, SEEK_SET);
info->size = end;
info->ctime = 0;
@@ -873,11 +903,12 @@ qerror_t Sys_GetFileInfo( FILE *fp, file_info_t *info ) {
return Q_ERR_SUCCESS;
}
-static void *copy_info( const char *name, const LPWIN32_FIND_DATAA data ) {
- time_t ctime = file_time_to_unix( &data->ftCreationTime );
- time_t mtime = file_time_to_unix( &data->ftLastWriteTime );
+static void *copy_info(const char *name, const LPWIN32_FIND_DATAA data)
+{
+ time_t ctime = file_time_to_unix(&data->ftCreationTime);
+ time_t mtime = file_time_to_unix(&data->ftLastWriteTime);
- return FS_CopyInfo( name, data->nFileSizeLow, ctime, mtime );
+ return FS_CopyInfo(name, data->nFileSizeLow, ctime, mtime);
}
/*
@@ -890,13 +921,13 @@ Internal function to filesystem. Conventions apply:
- depth must be 0 on the first call
=================
*/
-void Sys_ListFiles_r( const char *path,
- const char *filter,
- unsigned flags,
- size_t baselen,
- int *count_p,
- void **files,
- int depth )
+void Sys_ListFiles_r(const char *path,
+ const char *filter,
+ unsigned flags,
+ size_t baselen,
+ int *count_p,
+ void **files,
+ int depth)
{
WIN32_FIND_DATAA data;
HANDLE handle;
@@ -906,121 +937,118 @@ void Sys_ListFiles_r( const char *path,
void *info;
// optimize single extension search
- if( !( flags & FS_SEARCH_BYFILTER ) &&
- filter && !strchr( filter, ';' ) )
- {
- if( *filter == '.' ) {
+ if (!(flags & FS_SEARCH_BYFILTER) &&
+ filter && !strchr(filter, ';')) {
+ if (*filter == '.') {
filter++;
}
- len = Q_concat( fullpath, sizeof( fullpath ),
- path, "\\*.", filter, NULL );
+ len = Q_concat(fullpath, sizeof(fullpath),
+ path, "\\*.", filter, NULL);
filter = NULL; // do not check it later
} else {
- len = Q_concat( fullpath, sizeof( fullpath ),
- path, "\\*", NULL );
+ len = Q_concat(fullpath, sizeof(fullpath),
+ path, "\\*", NULL);
}
- if( len >= sizeof( fullpath ) ) {
+ if (len >= sizeof(fullpath)) {
return;
}
// format path to windows style
// done on the first run only
- if( !depth ) {
- FS_ReplaceSeparators( fullpath, '\\' );
+ if (!depth) {
+ FS_ReplaceSeparators(fullpath, '\\');
}
- handle = FindFirstFileA( fullpath, &data );
- if( handle == INVALID_HANDLE_VALUE ) {
+ handle = FindFirstFileA(fullpath, &data);
+ if (handle == INVALID_HANDLE_VALUE) {
return;
}
// make it point right after the slash
- pathlen = strlen( path ) + 1;
+ pathlen = strlen(path) + 1;
do {
- if( !strcmp( data.cFileName, "." ) ||
- !strcmp( data.cFileName, ".." ) )
- {
+ if (!strcmp(data.cFileName, ".") ||
+ !strcmp(data.cFileName, "..")) {
continue; // ignore special entries
}
// construct full path
- len = strlen( data.cFileName );
- if( pathlen + len >= sizeof( fullpath ) ) {
+ len = strlen(data.cFileName);
+ if (pathlen + len >= sizeof(fullpath)) {
continue;
}
- memcpy( fullpath + pathlen, data.cFileName, len + 1 );
+ memcpy(fullpath + pathlen, data.cFileName, len + 1);
- if( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
+ if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
mask = FS_SEARCH_DIRSONLY;
} else {
mask = 0;
}
// pattern search implies recursive search
- if( ( flags & FS_SEARCH_BYFILTER ) && mask &&
- depth < MAX_LISTED_DEPTH )
- {
- Sys_ListFiles_r( fullpath, filter, flags, baselen,
- count_p, files, depth + 1 );
+ if ((flags & FS_SEARCH_BYFILTER) && mask &&
+ depth < MAX_LISTED_DEPTH) {
+ Sys_ListFiles_r(fullpath, filter, flags, baselen,
+ count_p, files, depth + 1);
// re-check count
- if( *count_p >= MAX_LISTED_FILES ) {
+ if (*count_p >= MAX_LISTED_FILES) {
break;
}
}
// check type
- if( ( flags & FS_SEARCH_DIRSONLY ) != mask ) {
+ if ((flags & FS_SEARCH_DIRSONLY) != mask) {
continue;
}
// check filter
- if( filter ) {
- if( flags & FS_SEARCH_BYFILTER ) {
- if( !FS_WildCmp( filter, fullpath + baselen ) ) {
+ if (filter) {
+ if (flags & FS_SEARCH_BYFILTER) {
+ if (!FS_WildCmp(filter, fullpath + baselen)) {
continue;
}
} else {
- if( !FS_ExtCmp( filter, data.cFileName ) ) {
+ if (!FS_ExtCmp(filter, data.cFileName)) {
continue;
}
}
}
// strip path
- if( flags & FS_SEARCH_SAVEPATH ) {
+ if (flags & FS_SEARCH_SAVEPATH) {
name = fullpath + baselen;
} else {
name = data.cFileName;
}
// reformat it back to quake filesystem style
- FS_ReplaceSeparators( name, '/' );
+ FS_ReplaceSeparators(name, '/');
// strip extension
- if( flags & FS_SEARCH_STRIPEXT ) {
- *COM_FileExtension( name ) = 0;
+ if (flags & FS_SEARCH_STRIPEXT) {
+ *COM_FileExtension(name) = 0;
- if( !*name ) {
+ if (!*name) {
continue;
}
}
// copy info off
- if( flags & FS_SEARCH_EXTRAINFO ) {
- info = copy_info( name, &data );
+ if (flags & FS_SEARCH_EXTRAINFO) {
+ info = copy_info(name, &data);
} else {
- info = FS_CopyString( name );
+ info = FS_CopyString(name);
}
files[(*count_p)++] = info;
- } while( *count_p < MAX_LISTED_FILES &&
- FindNextFileA( handle, &data ) != FALSE );
+ } while (*count_p < MAX_LISTED_FILES &&
+ FindNextFileA(handle, &data) != FALSE);
- FindClose( handle );
+ FindClose(handle);
}
/*
@@ -1031,19 +1059,20 @@ MAIN
========================================================================
*/
-static BOOL fix_current_directory( void ) {
+static BOOL fix_current_directory(void)
+{
char *p;
- if( !GetModuleFileNameA( NULL, currentDirectory, sizeof( currentDirectory ) - 1 ) ) {
+ if (!GetModuleFileNameA(NULL, currentDirectory, sizeof(currentDirectory) - 1)) {
return FALSE;
}
- if( ( p = strrchr( currentDirectory, '\\' ) ) != NULL ) {
+ if ((p = strrchr(currentDirectory, '\\')) != NULL) {
*p = 0;
}
#ifndef UNDER_CE
- if( !SetCurrentDirectoryA( currentDirectory ) ) {
+ if (!SetCurrentDirectoryA(currentDirectory)) {
return FALSE;
}
#endif
@@ -1051,34 +1080,36 @@ static BOOL fix_current_directory( void ) {
return TRUE;
}
-#if ( _MSC_VER >= 1400 )
-static void msvcrt_sucks( const wchar_t *expr, const wchar_t *func,
- const wchar_t *file, unsigned int line, uintptr_t unused ) {
+#if (_MSC_VER >= 1400)
+static void msvcrt_sucks(const wchar_t *expr, const wchar_t *func,
+ const wchar_t *file, unsigned int line, uintptr_t unused)
+{
}
#endif
-static int Sys_Main( int argc, char **argv ) {
+static int Sys_Main(int argc, char **argv)
+{
// fix current directory to point to the basedir
- if( !fix_current_directory() ) {
+ if (!fix_current_directory()) {
return 1;
}
-#if ( _MSC_VER >= 1400 )
+#if (_MSC_VER >= 1400)
// work around strftime given invalid format string
// killing the whole fucking process :((
- _set_invalid_parameter_handler( msvcrt_sucks );
+ _set_invalid_parameter_handler(msvcrt_sucks);
#endif
- Qcommon_Init( argc, argv );
+ Qcommon_Init(argc, argv);
// main program loop
- while( 1 ) {
+ while (1) {
Qcommon_Frame();
- if( shouldExit ) {
+ if (shouldExit) {
#if USE_WINSVC
- if( shouldExit == SE_FULL )
+ if (shouldExit == SE_FULL)
#endif
- Com_Quit( NULL, ERR_DISCONNECT );
+ Com_Quit(NULL, ERR_DISCONNECT);
break;
}
}
@@ -1100,25 +1131,26 @@ Sys_ParseCommandLine
===============
*/
-static void Sys_ParseCommandLine( char *line ) {
+static void Sys_ParseCommandLine(char *line)
+{
sys_argc = 1;
sys_argv[0] = APPLICATION;
- while( *line ) {
- while( *line && *line <= 32 ) {
+ while (*line) {
+ while (*line && *line <= 32) {
line++;
}
- if( *line == 0 ) {
+ if (*line == 0) {
break;
}
sys_argv[sys_argc++] = line;
- while( *line > 32 ) {
+ while (*line > 32) {
line++;
}
- if( *line == 0 ) {
+ if (*line == 0) {
break;
}
*line = 0;
- if( sys_argc == MAX_LINE_TOKENS ) {
+ if (sys_argc == MAX_LINE_TOKENS) {
break;
}
line++;
@@ -1131,18 +1163,19 @@ WinMain
==================
*/
-int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) {
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
+{
// previous instances do not exist in Win32
- if( hPrevInstance ) {
+ if (hPrevInstance) {
return 1;
}
hGlobalInstance = hInstance;
#ifndef UNICODE
// TODO: wince support
- Sys_ParseCommandLine( lpCmdLine );
+ Sys_ParseCommandLine(lpCmdLine);
#endif
- return Sys_Main( sys_argc, sys_argv );
+ return Sys_Main(sys_argc, sys_argv);
}
#else // USE_CLIENT
@@ -1152,31 +1185,33 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLi
static char **sys_argv;
static int sys_argc;
-static VOID WINAPI ServiceHandler( DWORD fdwControl ) {
- if( fdwControl == SERVICE_CONTROL_STOP ) {
+static VOID WINAPI ServiceHandler(DWORD fdwControl)
+{
+ if (fdwControl == SERVICE_CONTROL_STOP) {
shouldExit = SE_FULL;
}
}
-static VOID WINAPI ServiceMain( DWORD argc, LPTSTR *argv ) {
+static VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
+{
SERVICE_STATUS status;
- statusHandle = RegisterServiceCtrlHandler( APPLICATION, ServiceHandler );
- if( !statusHandle ) {
+ statusHandle = RegisterServiceCtrlHandler(APPLICATION, ServiceHandler);
+ if (!statusHandle) {
return;
}
- memset( &status, 0, sizeof( status ) );
+ memset(&status, 0, sizeof(status));
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
status.dwCurrentState = SERVICE_RUNNING;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
- SetServiceStatus( statusHandle, &status );
+ SetServiceStatus(statusHandle, &status);
- Sys_Main( sys_argc, sys_argv );
+ Sys_Main(sys_argc, sys_argv);
status.dwCurrentState = SERVICE_STOPPED;
status.dwControlsAccepted = 0;
- SetServiceStatus( statusHandle, &status );
+ SetServiceStatus(statusHandle, &status);
}
static SERVICE_TABLE_ENTRY serviceTable[] = {
@@ -1192,31 +1227,32 @@ main
==================
*/
-int QDECL main( int argc, char **argv ) {
+int QDECL main(int argc, char **argv)
+{
#if USE_WINSVC
int i;
#endif
- hGlobalInstance = GetModuleHandle( NULL );
+ hGlobalInstance = GetModuleHandle(NULL);
#if USE_WINSVC
- for( i = 1; i < argc; i++ ) {
- if( !strcmp( argv[i], "-service" ) ) {
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-service")) {
argv[i] = NULL;
sys_argc = argc;
sys_argv = argv;
- if( StartServiceCtrlDispatcher( serviceTable ) ) {
+ if (StartServiceCtrlDispatcher(serviceTable)) {
return 0;
}
- if( GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ) {
+ if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
break; // fall back to normal server startup
}
return 1;
}
}
#endif
-
- return Sys_Main( argc, argv );
+
+ return Sys_Main(argc, argv);
}
#endif // !USE_CLIENT
diff --git a/src/tests.c b/src/tests.c
index 57692ea..5108e42 100644
--- a/src/tests.c
+++ b/src/tests.c
@@ -25,70 +25,75 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "bsp.h"
// test error shutdown procedures
-static void Com_Error_f( void ) {
- Com_Error( ERR_FATAL, "%s", Cmd_Argv( 1 ) );
+static void Com_Error_f(void)
+{
+ Com_Error(ERR_FATAL, "%s", Cmd_Argv(1));
}
-static void Com_ErrorDrop_f( void ) {
- Com_Error( ERR_DROP, "%s", Cmd_Argv( 1 ) );
+static void Com_ErrorDrop_f(void)
+{
+ Com_Error(ERR_DROP, "%s", Cmd_Argv(1));
}
-static void Com_Freeze_f( void ) {
+static void Com_Freeze_f(void)
+{
unsigned time, msec;
float seconds;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <seconds>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <seconds>\n", Cmd_Argv(0));
return;
}
- seconds = atof( Cmd_Argv( 1 ) );
- if( seconds < 0 ) {
+ seconds = atof(Cmd_Argv(1));
+ if (seconds < 0) {
return;
}
time = Sys_Milliseconds();
msec = seconds * 1000;
- while( Sys_Milliseconds() - time < msec )
+ while (Sys_Milliseconds() - time < msec)
;
}
// test crash dumps and NX support
-static void Com_Crash_f( void ) {
+static void Com_Crash_f(void)
+{
static byte buf1[16];
byte buf2[16], *buf3;
- int i = atoi( Cmd_Argv( 1 ) );
+ int i = atoi(Cmd_Argv(1));
- switch( i ) {
+ switch (i) {
case 1:
// data
- memset( buf1, 0xcc, 16 );
+ memset(buf1, 0xcc, 16);
buf1[0] = 0xc3;
((void (*)(void))buf1)();
break;
case 2:
// stack
- memset( buf2, 0xcc, 16 );
+ memset(buf2, 0xcc, 16);
buf2[0] = 0xc3;
((void (*)(void))buf2)();
break;
case 3:
// heap
- buf3 = Z_Malloc( 16 );
- memset( buf3, 0xcc, 16 );
+ buf3 = Z_Malloc(16);
+ memset(buf3, 0xcc, 16);
buf3[0] = 0xc3;
((void (*)(void))buf3)();
- Z_Free( buf3 );
+ Z_Free(buf3);
break;
default:
- *( uint32_t * )1024 = 0x123456;
+ *(uint32_t *)1024 = 0x123456;
break;
}
}
// use twice normal print buffer size to test for overflows, etc
-static void Com_PrintJunk_f( void ) {
- char buf[MAXPRINTMSG*2];
+static void Com_PrintJunk_f(void)
+{
+ char buf[MAXPRINTMSG * 2];
int i, count;
// generate some junk
@@ -110,7 +115,8 @@ static void Com_PrintJunk_f( void ) {
Com_Printf("\n");
}
-static void BSP_Test_f( void ) {
+static void BSP_Test_f(void)
+{
void **list;
char *name;
int i, count, errors;
@@ -118,34 +124,34 @@ static void BSP_Test_f( void ) {
qerror_t ret;
unsigned start, end;
- list = FS_ListFiles( "maps", ".bsp", FS_SEARCH_SAVEPATH, &count );
- if( !list ) {
- Com_Printf( "No maps found\n" );
+ list = FS_ListFiles("maps", ".bsp", FS_SEARCH_SAVEPATH, &count);
+ if (!list) {
+ Com_Printf("No maps found\n");
return;
}
start = Sys_Milliseconds();
errors = 0;
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
name = list[i];
- ret = BSP_Load( name, &bsp );
- if( !bsp ) {
- Com_EPrintf( "%s: %s\n", name, Q_ErrorString( ret ) );
+ ret = BSP_Load(name, &bsp);
+ if (!bsp) {
+ Com_EPrintf("%s: %s\n", name, Q_ErrorString(ret));
errors++;
continue;
}
- Com_DPrintf( "%s: success\n", name );
- BSP_Free( bsp );
+ Com_DPrintf("%s: success\n", name);
+ BSP_Free(bsp);
}
end = Sys_Milliseconds();
- Com_Printf( "%d msec, %d failures, %d maps tested\n",
- end - start, errors, count );
+ Com_Printf("%d msec, %d failures, %d maps tested\n",
+ end - start, errors, count);
- FS_FreeList( list );
+ FS_FreeList(list);
}
typedef struct {
@@ -173,27 +179,28 @@ static const wildtest_t wildtests[] = {
{ "\\a\\b\\c", "abc", 1 },
};
-static const int numwildtests = sizeof( wildtests ) / sizeof( wildtests[0] );
+static const int numwildtests = sizeof(wildtests) / sizeof(wildtests[0]);
-static void Com_TestWild_f( void ) {
+static void Com_TestWild_f(void)
+{
const wildtest_t *w;
qboolean match;
int i, errors;
errors = 0;
- for( i = 0; i < numwildtests; i++ ) {
+ for (i = 0; i < numwildtests; i++) {
w = &wildtests[i];
- match = Com_WildCmp( w->filter, w->string );
- if( match != w->result ) {
+ match = Com_WildCmp(w->filter, w->string);
+ if (match != w->result) {
Com_EPrintf(
"Com_WildCmp( \"%s\", \"%s\" ) == %d, expected %d\n",
- w->filter, w->string, match, w->result );
+ w->filter, w->string, match, w->result);
errors++;
}
}
- Com_Printf( "%d failures, %d patterns tested\n",
- errors, numwildtests );
+ Com_Printf("%d failures, %d patterns tested\n",
+ errors, numwildtests);
}
typedef struct {
@@ -247,47 +254,49 @@ static const normtest_t normtests[] = {
{ "foo/bar/../../../../baz/abc/../../zzz/../def/ghi", "def/ghi" },
};
-static const int numnormtests = sizeof( normtests ) / sizeof( normtests[0] );
+static const int numnormtests = sizeof(normtests) / sizeof(normtests[0]);
-static void Com_TestNorm_f( void ) {
+static void Com_TestNorm_f(void)
+{
const normtest_t *n;
char buffer[MAX_QPATH];
int i, errors, pass;
- for( pass = 0; pass < 2; pass++ ) {
+ for (pass = 0; pass < 2; pass++) {
errors = 0;
- for( i = 0; i < numnormtests; i++ ) {
+ for (i = 0; i < numnormtests; i++) {
n = &normtests[i];
- if( pass == 0 ) {
- FS_NormalizePath( buffer, n->in );
+ if (pass == 0) {
+ FS_NormalizePath(buffer, n->in);
} else {
// test in place operation
- strcpy( buffer, n->in );
- FS_NormalizePath( buffer, buffer );
+ strcpy(buffer, n->in);
+ FS_NormalizePath(buffer, buffer);
}
- if( strcmp( n->out, buffer ) ) {
+ if (strcmp(n->out, buffer)) {
Com_EPrintf(
"FS_NormalizePath( \"%s\" ) == \"%s\", expected \"%s\" (pass %d)\n",
- n->in, buffer, n->out, pass );
+ n->in, buffer, n->out, pass);
errors++;
}
}
- if( errors )
+ if (errors)
break;
}
- Com_Printf( "%d failures, %d paths tested (%d passes)\n",
- errors, numnormtests, pass );
+ Com_Printf("%d failures, %d paths tested (%d passes)\n",
+ errors, numnormtests, pass);
}
-void Com_InitTests( void ) {
- Cmd_AddCommand( "error", Com_Error_f );
- Cmd_AddCommand( "errordrop", Com_ErrorDrop_f );
- Cmd_AddCommand( "freeze", Com_Freeze_f );
- Cmd_AddCommand( "crash", Com_Crash_f );
- Cmd_AddCommand( "printjunk", Com_PrintJunk_f );
- Cmd_AddCommand( "bsptest", BSP_Test_f );
- Cmd_AddCommand( "wildtest", Com_TestWild_f );
- Cmd_AddCommand( "normtest", Com_TestNorm_f );
+void Com_InitTests(void)
+{
+ Cmd_AddCommand("error", Com_Error_f);
+ Cmd_AddCommand("errordrop", Com_ErrorDrop_f);
+ Cmd_AddCommand("freeze", Com_Freeze_f);
+ Cmd_AddCommand("crash", Com_Crash_f);
+ Cmd_AddCommand("printjunk", Com_PrintJunk_f);
+ Cmd_AddCommand("bsptest", BSP_Test_f);
+ Cmd_AddCommand("wildtest", Com_TestWild_f);
+ Cmd_AddCommand("normtest", Com_TestNorm_f);
}
diff --git a/src/ui_atoms.c b/src/ui_atoms.c
index 4fb848b..5f9c004 100644
--- a/src/ui_atoms.c
+++ b/src/ui_atoms.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
uiStatic_t uis;
-LIST_DECL( ui_menus );
+LIST_DECL(ui_menus);
cvar_t *ui_debug;
static cvar_t *ui_open;
@@ -35,49 +35,50 @@ static cvar_t *ui_scale;
UI_PushMenu
=================
*/
-void UI_PushMenu( menuFrameWork_t *menu ) {
+void UI_PushMenu(menuFrameWork_t *menu)
+{
int i, j;
- if( !menu ) {
+ if (!menu) {
return;
}
// if this menu is already present, drop back to that level
// to avoid stacking menus by hotkeys
- for( i = 0; i < uis.menuDepth; i++ ) {
- if( uis.layers[i] == menu ) {
+ for (i = 0; i < uis.menuDepth; i++) {
+ if (uis.layers[i] == menu) {
break;
}
}
- if( i == uis.menuDepth ) {
- if( uis.menuDepth >= MAX_MENU_DEPTH ) {
- Com_EPrintf( "UI_PushMenu: MAX_MENU_DEPTH exceeded\n" );
+ if (i == uis.menuDepth) {
+ if (uis.menuDepth >= MAX_MENU_DEPTH) {
+ Com_EPrintf("UI_PushMenu: MAX_MENU_DEPTH exceeded\n");
return;
}
uis.layers[uis.menuDepth++] = menu;
} else {
- for( j = i; j < uis.menuDepth; j++ ) {
+ for (j = i; j < uis.menuDepth; j++) {
UI_PopMenu();
}
uis.menuDepth = i + 1;
}
- if( menu->push ) {
- if( !menu->push( menu ) ) {
+ if (menu->push) {
+ if (!menu->push(menu)) {
return;
}
}
- Menu_Init( menu );
+ Menu_Init(menu);
- Key_SetDest( ( Key_GetDest() & ~KEY_CONSOLE ) | KEY_MENU );
+ Key_SetDest((Key_GetDest() & ~KEY_CONSOLE) | KEY_MENU);
- Con_Close( qtrue );
+ Con_Close(qtrue);
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
// opening menu moves cursor to the nice location
- IN_WarpMouse( menu->mins[0] / uis.scale, menu->mins[1] / uis.scale );
+ IN_WarpMouse(menu->mins[0] / uis.scale, menu->mins[1] / uis.scale);
uis.mouseCoords[0] = menu->mins[0];
uis.mouseCoords[1] = menu->mins[1];
@@ -90,12 +91,13 @@ void UI_PushMenu( menuFrameWork_t *menu ) {
UI_DoHitTest();
- if( menu->expose ) {
- menu->expose( menu );
+ if (menu->expose) {
+ menu->expose(menu);
}
}
-static void UI_Resize( void ) {
+static void UI_Resize(void)
+{
int i;
#if USE_REF == REF_SOFT
@@ -107,17 +109,17 @@ static void UI_Resize( void ) {
uis.width = r_config.width;
uis.height = r_config.height;
#else
- Cvar_ClampValue( ui_scale, 1, 9 );
+ Cvar_ClampValue(ui_scale, 1, 9);
uis.scale = 1 / ui_scale->value;
uis.width = r_config.width * uis.scale;
uis.height = r_config.height * uis.scale;
#endif
- for( i = 0; i < uis.menuDepth; i++ ) {
- Menu_Init( uis.layers[i] );
+ for (i = 0; i < uis.menuDepth; i++) {
+ Menu_Init(uis.layers[i]);
}
- //CL_WarpMouse( 0, 0 );
+ //CL_WarpMouse(0, 0);
}
@@ -126,18 +128,19 @@ static void UI_Resize( void ) {
UI_ForceMenuOff
=================
*/
-void UI_ForceMenuOff( void ) {
+void UI_ForceMenuOff(void)
+{
menuFrameWork_t *menu;
int i;
- for( i = 0; i < uis.menuDepth; i++ ) {
+ for (i = 0; i < uis.menuDepth; i++) {
menu = uis.layers[i];
- if( menu->pop ) {
- menu->pop( menu );
+ if (menu->pop) {
+ menu->pop(menu);
}
}
- Key_SetDest( Key_GetDest() & ~KEY_MENU );
+ Key_SetDest(Key_GetDest() & ~KEY_MENU);
uis.menuDepth = 0;
uis.activeMenu = NULL;
uis.transparent = qfalse;
@@ -148,19 +151,20 @@ void UI_ForceMenuOff( void ) {
UI_PopMenu
=================
*/
-void UI_PopMenu( void ) {
+void UI_PopMenu(void)
+{
menuFrameWork_t *menu;
int i;
- if( uis.menuDepth < 1 )
- Com_Error( ERR_FATAL, "UI_PopMenu: depth < 1" );
+ if (uis.menuDepth < 1)
+ Com_Error(ERR_FATAL, "UI_PopMenu: depth < 1");
menu = uis.layers[--uis.menuDepth];
- if( menu->pop ) {
- menu->pop( menu );
+ if (menu->pop) {
+ menu->pop(menu);
}
- if( !uis.menuDepth ) {
+ if (!uis.menuDepth) {
UI_ForceMenuOff();
return;
}
@@ -168,8 +172,8 @@ void UI_PopMenu( void ) {
uis.activeMenu = uis.layers[uis.menuDepth - 1];
uis.transparent = qfalse;
- for( i = uis.menuDepth - 1; i >= 0; i-- ) {
- if( uis.layers[i]->transparent ) {
+ for (i = uis.menuDepth - 1; i >= 0; i--) {
+ if (uis.layers[i]->transparent) {
uis.transparent = qtrue;
break;
}
@@ -183,23 +187,25 @@ void UI_PopMenu( void ) {
UI_IsTransparent
=================
*/
-qboolean UI_IsTransparent( void ) {
- if( !( Key_GetDest() & KEY_MENU ) ) {
+qboolean UI_IsTransparent(void)
+{
+ if (!(Key_GetDest() & KEY_MENU)) {
return qtrue;
}
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
return qtrue;
}
return uis.transparent;
}
-menuFrameWork_t *UI_FindMenu( const char *name ) {
+menuFrameWork_t *UI_FindMenu(const char *name)
+{
menuFrameWork_t *menu;
- LIST_FOR_EACH( menuFrameWork_t, menu, &ui_menus, entry ) {
- if( !strcmp( menu->name, name ) ) {
+ LIST_FOR_EACH(menuFrameWork_t, menu, &ui_menus, entry) {
+ if (!strcmp(menu->name, name)) {
return menu;
}
}
@@ -211,39 +217,40 @@ menuFrameWork_t *UI_FindMenu( const char *name ) {
UI_OpenMenu
=================
*/
-void UI_OpenMenu( uiMenu_t type ) {
+void UI_OpenMenu(uiMenu_t type)
+{
menuFrameWork_t *menu = NULL;
- if( !uis.initialized ) {
+ if (!uis.initialized) {
return;
}
// close any existing menus
UI_ForceMenuOff();
- switch( type ) {
+ switch (type) {
case UIMENU_DEFAULT:
- if( ui_open->integer ) {
- menu = UI_FindMenu( "main" );
+ if (ui_open->integer) {
+ menu = UI_FindMenu("main");
}
break;
case UIMENU_MAIN:
- menu = UI_FindMenu( "main" );
+ menu = UI_FindMenu("main");
break;
case UIMENU_GAME:
- menu = UI_FindMenu( "game" );
- if( !menu ) {
- menu = UI_FindMenu( "main" );
+ menu = UI_FindMenu("game");
+ if (!menu) {
+ menu = UI_FindMenu("main");
}
break;
case UIMENU_NONE:
break;
default:
- Com_Error( ERR_FATAL, "UI_OpenMenu: bad menu" );
+ Com_Error(ERR_FATAL, "UI_OpenMenu: bad menu");
break;
}
- UI_PushMenu( menu );
+ UI_PushMenu(menu);
}
//=============================================================================
@@ -253,7 +260,8 @@ void UI_OpenMenu( uiMenu_t type ) {
UI_FormatColumns
=================
*/
-void *UI_FormatColumns( int extrasize, ... ) {
+void *UI_FormatColumns(int extrasize, ...)
+{
va_list argptr;
char *buffer, *p;
int i, j;
@@ -261,20 +269,20 @@ void *UI_FormatColumns( int extrasize, ... ) {
char *strings[MAX_COLUMNS];
size_t lengths[MAX_COLUMNS];
- va_start( argptr, extrasize );
- for( i = 0; i < MAX_COLUMNS; i++ ) {
- if( ( p = va_arg( argptr, char * ) ) == NULL ) {
+ va_start(argptr, extrasize);
+ for (i = 0; i < MAX_COLUMNS; i++) {
+ if ((p = va_arg(argptr, char *)) == NULL) {
break;
}
strings[i] = p;
- total += lengths[i] = strlen( p ) + 1;
+ total += lengths[i] = strlen(p) + 1;
}
- va_end( argptr );
+ va_end(argptr);
- buffer = UI_Malloc( extrasize + total + 1 );
+ buffer = UI_Malloc(extrasize + total + 1);
p = buffer + extrasize;
- for( j = 0; j < i; j++ ) {
- memcpy( p, strings[j], lengths[j] );
+ for (j = 0; j < i; j++) {
+ memcpy(p, strings[j], lengths[j]);
p += lengths[j];
}
*p = 0;
@@ -282,11 +290,12 @@ void *UI_FormatColumns( int extrasize, ... ) {
return buffer;
}
-char *UI_GetColumn( char *s, int n ) {
+char *UI_GetColumn(char *s, int n)
+{
int i;
- for( i = 0; i < n && *s; i++ ) {
- s += strlen( s ) + 1;
+ for (i = 0; i < n && *s; i++) {
+ s += strlen(s) + 1;
}
return s;
@@ -297,60 +306,66 @@ char *UI_GetColumn( char *s, int n ) {
UI_CursorInRect
=================
*/
-qboolean UI_CursorInRect( vrect_t *rect ) {
- if( uis.mouseCoords[0] < rect->x ) {
+qboolean UI_CursorInRect(vrect_t *rect)
+{
+ if (uis.mouseCoords[0] < rect->x) {
return qfalse;
}
- if( uis.mouseCoords[0] >= rect->x + rect->width ) {
+ if (uis.mouseCoords[0] >= rect->x + rect->width) {
return qfalse;
}
- if( uis.mouseCoords[1] < rect->y ) {
+ if (uis.mouseCoords[1] < rect->y) {
return qfalse;
}
- if( uis.mouseCoords[1] >= rect->y + rect->height ) {
+ if (uis.mouseCoords[1] >= rect->y + rect->height) {
return qfalse;
}
return qtrue;
}
-void UI_DrawString( int x, int y, int flags, const char *string ) {
- if( ( flags & UI_CENTER ) == UI_CENTER ) {
- x -= strlen( string ) * CHAR_WIDTH / 2;
- } else if( flags & UI_RIGHT ) {
- x -= strlen( string ) * CHAR_WIDTH;
+void UI_DrawString(int x, int y, int flags, const char *string)
+{
+ if ((flags & UI_CENTER) == UI_CENTER) {
+ x -= strlen(string) * CHAR_WIDTH / 2;
+ } else if (flags & UI_RIGHT) {
+ x -= strlen(string) * CHAR_WIDTH;
}
- R_DrawString( x, y, flags, MAX_STRING_CHARS, string, uis.fontHandle );
+ R_DrawString(x, y, flags, MAX_STRING_CHARS, string, uis.fontHandle);
}
-void UI_DrawChar( int x, int y, int flags, int ch ) {
- R_DrawChar( x, y, flags, ch, uis.fontHandle );
+void UI_DrawChar(int x, int y, int flags, int ch)
+{
+ R_DrawChar(x, y, flags, ch, uis.fontHandle);
}
-void UI_StringDimensions( vrect_t *rc, int flags, const char *string ) {
+void UI_StringDimensions(vrect_t *rc, int flags, const char *string)
+{
rc->height = CHAR_HEIGHT;
- rc->width = CHAR_WIDTH * strlen( string );
+ rc->width = CHAR_WIDTH * strlen(string);
- if( ( flags & UI_CENTER ) == UI_CENTER ) {
+ if ((flags & UI_CENTER) == UI_CENTER) {
rc->x -= rc->width / 2;
- } else if( flags & UI_RIGHT ) {
+ } else if (flags & UI_RIGHT) {
rc->x -= rc->width;
- }
+ }
}
-void UI_DrawRect8( const vrect_t *rc, int border, int c ) {
- R_DrawFill8( rc->x, rc->y, border, rc->height, c ); // left
- R_DrawFill8( rc->x + rc->width - border, rc->y, border, rc->height, c ); // right
- R_DrawFill8( rc->x + border, rc->y, rc->width - border * 2, border, c ); // top
- R_DrawFill8( rc->x + border, rc->y + rc->height - border, rc->width - border * 2, border, c ); // bottom
+void UI_DrawRect8(const vrect_t *rc, int border, int c)
+{
+ R_DrawFill8(rc->x, rc->y, border, rc->height, c); // left
+ R_DrawFill8(rc->x + rc->width - border, rc->y, border, rc->height, c); // right
+ R_DrawFill8(rc->x + border, rc->y, rc->width - border * 2, border, c); // top
+ R_DrawFill8(rc->x + border, rc->y + rc->height - border, rc->width - border * 2, border, c); // bottom
}
#if 0
-void UI_DrawRect32( const vrect_t *rc, int border, uint32_t color ) {
- R_DrawFill32( rc->x, rc->y, border, rc->height, color ); // left
- R_DrawFill32( rc->x + rc->width - border, rc->y, border, rc->height, color ); // right
- R_DrawFill32( rc->x + border, rc->y, rc->width - border * 2, border, color ); // top
- R_DrawFill32( rc->x + border, rc->y + rc->height - border, rc->width - border * 2, border, color ); // bottom
+void UI_DrawRect32(const vrect_t *rc, int border, uint32_t color)
+{
+ R_DrawFill32(rc->x, rc->y, border, rc->height, color); // left
+ R_DrawFill32(rc->x + rc->width - border, rc->y, border, rc->height, color); // right
+ R_DrawFill32(rc->x + border, rc->y, rc->width - border * 2, border, color); // top
+ R_DrawFill32(rc->x + border, rc->y + rc->height - border, rc->width - border * 2, border, color); // bottom
}
#endif
@@ -362,28 +377,29 @@ void UI_DrawRect32( const vrect_t *rc, int border, uint32_t color ) {
UI_DoHitTest
=================
*/
-qboolean UI_DoHitTest( void ) {
+qboolean UI_DoHitTest(void)
+{
menuCommon_t *item;
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
return qfalse;
}
- if( !( item = Menu_HitTest( uis.activeMenu ) ) ) {
+ if (!(item = Menu_HitTest(uis.activeMenu))) {
return qfalse;
}
- if( !UI_IsItemSelectable( item ) ) {
+ if (!UI_IsItemSelectable(item)) {
return qfalse;
}
- Menu_MouseMove( item );
+ Menu_MouseMove(item);
- if( item->flags & QMF_HASFOCUS ) {
+ if (item->flags & QMF_HASFOCUS) {
return qfalse;
}
- Menu_SetFocus( item );
-
+ Menu_SetFocus(item);
+
return qtrue;
}
@@ -392,12 +408,13 @@ qboolean UI_DoHitTest( void ) {
UI_MouseEvent
=================
*/
-void UI_MouseEvent( int x, int y ) {
- clamp( x, 0, r_config.width - 1 );
- clamp( y, 0, r_config.height - 1 );
+void UI_MouseEvent(int x, int y)
+{
+ clamp(x, 0, r_config.width - 1);
+ clamp(y, 0, r_config.height - 1);
- uis.mouseCoords[0] = Q_rint( x * uis.scale );
- uis.mouseCoords[1] = Q_rint( y * uis.scale );
+ uis.mouseCoords[0] = Q_rint(x * uis.scale);
+ uis.mouseCoords[1] = Q_rint(y * uis.scale);
UI_DoHitTest();
}
@@ -407,84 +424,86 @@ void UI_MouseEvent( int x, int y ) {
UI_Draw
=================
*/
-void UI_Draw( int realtime ) {
+void UI_Draw(int realtime)
+{
int i;
uis.realtime = realtime;
- if( !( Key_GetDest() & KEY_MENU ) ) {
+ if (!(Key_GetDest() & KEY_MENU)) {
return;
}
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
return;
}
R_ClearColor();
#if USE_REF == REF_SOFT
- R_SetClipRect( DRAW_CLIP_MASK, &uis.clipRect );
+ R_SetClipRect(DRAW_CLIP_MASK, &uis.clipRect);
#else
- R_SetScale( &uis.scale );
+ R_SetScale(&uis.scale);
#endif
- if( !uis.transparent ) {
+ if (!uis.transparent) {
// draw top menu
- if( uis.activeMenu->draw ) {
- uis.activeMenu->draw( uis.activeMenu );
+ if (uis.activeMenu->draw) {
+ uis.activeMenu->draw(uis.activeMenu);
} else {
- Menu_Draw( uis.activeMenu );
+ Menu_Draw(uis.activeMenu);
}
} else {
// draw all layers
- for( i = 0; i < uis.menuDepth; i++ ) {
- if( uis.layers[i]->draw ) {
- uis.layers[i]->draw( uis.layers[i] );
+ for (i = 0; i < uis.menuDepth; i++) {
+ if (uis.layers[i]->draw) {
+ uis.layers[i]->draw(uis.layers[i]);
} else {
- Menu_Draw( uis.layers[i] );
+ Menu_Draw(uis.layers[i]);
}
}
}
// draw custom cursor in fullscreen mode
- if( r_config.flags & QVF_FULLSCREEN ) {
- R_DrawPic( uis.mouseCoords[0] - uis.cursorWidth / 2,
- uis.mouseCoords[1] - uis.cursorHeight / 2, uis.cursorHandle );
+ if (r_config.flags & QVF_FULLSCREEN) {
+ R_DrawPic(uis.mouseCoords[0] - uis.cursorWidth / 2,
+ uis.mouseCoords[1] - uis.cursorHeight / 2, uis.cursorHandle);
}
- if( ui_debug->integer ) {
- UI_DrawString( uis.width - 4, 4, UI_RIGHT,
- va( "%3i %3i", uis.mouseCoords[0], uis.mouseCoords[1] ) );
+ if (ui_debug->integer) {
+ UI_DrawString(uis.width - 4, 4, UI_RIGHT,
+ va("%3i %3i", uis.mouseCoords[0], uis.mouseCoords[1]));
}
// delay playing the enter sound until after the
// menu has been drawn, to avoid delay while
// caching images
- if( uis.entersound ) {
+ if (uis.entersound) {
uis.entersound = qfalse;
- S_StartLocalSound( "misc/menu1.wav" );
+ S_StartLocalSound("misc/menu1.wav");
}
#if USE_REF == REF_SOFT
- R_SetClipRect( DRAW_CLIP_DISABLED, NULL );
+ R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
#else
- R_SetScale( NULL );
+ R_SetScale(NULL);
#endif
R_ClearColor();
}
-void UI_StartSound( menuSound_t sound ) {
- switch( sound ) {
+void UI_StartSound(menuSound_t sound)
+{
+ switch (sound) {
case QMS_IN:
- S_StartLocalSound( "misc/menu1.wav" );
+ S_StartLocalSound("misc/menu1.wav");
break;
case QMS_MOVE:
- S_StartLocalSound( "misc/menu2.wav" );
+ S_StartLocalSound("misc/menu2.wav");
break;
case QMS_OUT:
- S_StartLocalSound( "misc/menu3.wav" );
+ S_StartLocalSound("misc/menu3.wav");
break;
case QMS_BEEP:
- S_StartLocalSound( "misc/talk1.wav" );
+ S_StartLocalSound("misc/talk1.wav");
break;
default:
break;
@@ -496,16 +515,17 @@ void UI_StartSound( menuSound_t sound ) {
UI_Keydown
=================
*/
-void UI_Keydown( int key ) {
+void UI_Keydown(int key)
+{
menuSound_t sound;
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
return;
}
- sound = Menu_Keydown( uis.activeMenu, key );
+ sound = Menu_Keydown(uis.activeMenu, key);
- UI_StartSound( sound );
+ UI_StartSound(sound);
}
/*
@@ -513,58 +533,62 @@ void UI_Keydown( int key ) {
UI_CharEvent
=================
*/
-void UI_CharEvent( int key ) {
+void UI_CharEvent(int key)
+{
menuCommon_t *item;
menuSound_t sound;
- if( !uis.activeMenu ) {
+ if (!uis.activeMenu) {
return;
}
- if( ( item = Menu_ItemAtCursor( uis.activeMenu ) ) == NULL ||
- ( sound = Menu_CharEvent( item, key ) ) == QMS_NOTHANDLED )
- {
+ if ((item = Menu_ItemAtCursor(uis.activeMenu)) == NULL ||
+ (sound = Menu_CharEvent(item, key)) == QMS_NOTHANDLED) {
return;
}
- UI_StartSound( sound );
+ UI_StartSound(sound);
}
-static void UI_Menu_g( genctx_t *ctx ) {
+static void UI_Menu_g(genctx_t *ctx)
+{
menuFrameWork_t *menu;
- LIST_FOR_EACH( menuFrameWork_t, menu, &ui_menus, entry ) {
- if( !Prompt_AddMatch( ctx, menu->name ) ) {
+ LIST_FOR_EACH(menuFrameWork_t, menu, &ui_menus, entry) {
+ if (!Prompt_AddMatch(ctx, menu->name)) {
break;
}
}
}
-static void UI_PushMenu_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- UI_Menu_g( ctx );
+static void UI_PushMenu_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ UI_Menu_g(ctx);
}
}
-static void UI_PushMenu_f( void ) {
+static void UI_PushMenu_f(void)
+{
menuFrameWork_t *menu;
char *s;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <menu>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <menu>\n", Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- menu = UI_FindMenu( s );
- if( menu ) {
- UI_PushMenu( menu );
+ s = Cmd_Argv(1);
+ menu = UI_FindMenu(s);
+ if (menu) {
+ UI_PushMenu(menu);
} else {
- Com_Printf( "No such menu: %s\n", s );
+ Com_Printf("No such menu: %s\n", s);
}
}
-static void UI_PopMenu_f( void ) {
- if( uis.activeMenu ) {
+static void UI_PopMenu_f(void)
+{
+ if (uis.activeMenu) {
UI_PopMenu();
}
}
@@ -578,25 +602,28 @@ static const cmdreg_t c_ui[] = {
{ NULL, NULL }
};
-static void ui_scale_changed( cvar_t *self ) {
+static void ui_scale_changed(cvar_t *self)
+{
UI_Resize();
}
-void UI_ModeChanged( void ) {
- ui_scale = Cvar_Get( "ui_scale", "1", 0 );
+void UI_ModeChanged(void)
+{
+ ui_scale = Cvar_Get("ui_scale", "1", 0);
ui_scale->changed = ui_scale_changed;
UI_Resize();
}
-static void UI_FreeMenus( void ) {
+static void UI_FreeMenus(void)
+{
menuFrameWork_t *menu, *next;
- LIST_FOR_EACH_SAFE( menuFrameWork_t, menu, next, &ui_menus, entry ) {
- if( menu->free ) {
- menu->free( menu );
+ LIST_FOR_EACH_SAFE(menuFrameWork_t, menu, next, &ui_menus, entry) {
+ if (menu->free) {
+ menu->free(menu);
}
}
- List_Init( &ui_menus );
+ List_Init(&ui_menus);
}
@@ -605,33 +632,34 @@ static void UI_FreeMenus( void ) {
UI_Init
=================
*/
-qboolean UI_Init( void ) {
+qboolean UI_Init(void)
+{
char buffer[MAX_QPATH];
int i;
- Cmd_Register( c_ui );
+ Cmd_Register(c_ui);
- ui_debug = Cvar_Get( "ui_debug", "0", 0 );
- ui_open = Cvar_Get( "ui_open", "0", 0 );
+ ui_debug = Cvar_Get("ui_debug", "0", 0);
+ ui_open = Cvar_Get("ui_open", "0", 0);
UI_ModeChanged();
- uis.fontHandle = R_RegisterFont( "conchars" );
- uis.cursorHandle = R_RegisterPic( "ch1" );
- R_GetPicSize( &uis.cursorWidth, &uis.cursorHeight, uis.cursorHandle );
+ uis.fontHandle = R_RegisterFont("conchars");
+ uis.cursorHandle = R_RegisterPic("ch1");
+ R_GetPicSize(&uis.cursorWidth, &uis.cursorHeight, uis.cursorHandle);
- for( i = 0; i < NUM_CURSOR_FRAMES; i++ ) {
- Q_snprintf( buffer, sizeof( buffer ), "m_cursor%d", i );
- uis.bitmapCursors[i] = R_RegisterPic( buffer );
+ for (i = 0; i < NUM_CURSOR_FRAMES; i++) {
+ Q_snprintf(buffer, sizeof(buffer), "m_cursor%d", i);
+ uis.bitmapCursors[i] = R_RegisterPic(buffer);
}
- uis.color.background.u32 = MakeColor( 0, 0, 0, 255 );
- uis.color.normal.u32 = MakeColor( 15, 128, 235, 100 );
- uis.color.active.u32 = MakeColor( 15, 128, 235, 100 );
- uis.color.selection.u32 = MakeColor( 15, 128, 235, 100 );
- uis.color.disabled.u32 = MakeColor( 127, 127, 127, 255 );
+ uis.color.background.u32 = MakeColor(0, 0, 0, 255);
+ uis.color.normal.u32 = MakeColor(15, 128, 235, 100);
+ uis.color.active.u32 = MakeColor(15, 128, 235, 100);
+ uis.color.selection.u32 = MakeColor(15, 128, 235, 100);
+ uis.color.disabled.u32 = MakeColor(127, 127, 127, 255);
- strcpy( uis.weaponModel, "w_railgun.md2" );
+ strcpy(uis.weaponModel, "w_railgun.md2");
// load custom menus
UI_LoadScript();
@@ -641,7 +669,7 @@ qboolean UI_Init( void ) {
M_Menu_Servers();
M_Menu_Demos();
- Com_DPrintf( "Registered %d menus.\n", List_Count( &ui_menus ) );
+ Com_DPrintf("Registered %d menus.\n", List_Count(&ui_menus));
uis.initialized = qtrue;
@@ -653,8 +681,9 @@ qboolean UI_Init( void ) {
UI_Shutdown
=================
*/
-void UI_Shutdown( void ) {
- if( !uis.initialized ) {
+void UI_Shutdown(void)
+{
+ if (!uis.initialized) {
return;
}
UI_ForceMenuOff();
@@ -665,11 +694,11 @@ void UI_Shutdown( void ) {
UI_FreeMenus();
- Cmd_Deregister( c_ui );
+ Cmd_Deregister(c_ui);
- memset( &uis, 0, sizeof( uis ) );
+ memset(&uis, 0, sizeof(uis));
- Z_LeakTest( TAG_UI );
+ Z_LeakTest(TAG_UI);
}
diff --git a/src/ui_demos.c b/src/ui_demos.c
index dd322b9..cec1608 100644
--- a/src/ui_demos.c
+++ b/src/ui_demos.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -32,7 +32,7 @@ DEMOS MENU
#define DEMO_EXTENSIONS ".dm2;.dm2.gz;.mvd2;.mvd2.gz"
-#define DEMO_EXTRASIZE q_offsetof( demoEntry_t, name )
+#define DEMO_EXTRASIZE q_offsetof(demoEntry_t, name)
#define DEMO_MVD_POV "\x90\xcd\xd6\xc4\x91" // [MVD]
#define DEMO_DIR_SIZE "\x90\xc4\xc9\xd2\x91" // [DIR]
@@ -73,7 +73,8 @@ static m_demos_t m_demos;
static cvar_t *ui_sortdemos;
static cvar_t *ui_listalldemos;
-static void BuildName( const file_info_t *info, char **cache ) {
+static void BuildName(const file_info_t *info, char **cache)
+{
char buffer[MAX_OSPATH];
char date[MAX_QPATH];
demoInfo_t demo;
@@ -81,62 +82,62 @@ static void BuildName( const file_info_t *info, char **cache ) {
struct tm *tm;
size_t len;
- memset( &demo, 0, sizeof( demo ) );
- strcpy( demo.map, "???" );
- strcpy( demo.pov, "???" );
+ memset(&demo, 0, sizeof(demo));
+ strcpy(demo.map, "???");
+ strcpy(demo.pov, "???");
- if( cache ) {
+ if (cache) {
char *s = *cache;
- char *p = strchr( s, '\\' );
- if( p ) {
+ char *p = strchr(s, '\\');
+ if (p) {
*p = 0;
- Q_strlcpy( demo.map, s, sizeof( demo.map ) );
+ Q_strlcpy(demo.map, s, sizeof(demo.map));
s = p + 1;
- p = strchr( s, '\\' );
- if( p ) {
+ p = strchr(s, '\\');
+ if (p) {
*p = 0;
- Q_strlcpy( demo.pov, s, sizeof( demo.pov ) );
+ Q_strlcpy(demo.pov, s, sizeof(demo.pov));
s = p + 1;
}
}
*cache = s;
} else {
- Q_concat( buffer, sizeof( buffer ), m_demos.browse, "/", info->name, NULL );
- CL_GetDemoInfo( buffer, &demo );
- if( demo.mvd ) {
- strcpy( demo.pov, DEMO_MVD_POV );
+ Q_concat(buffer, sizeof(buffer), m_demos.browse, "/", info->name, NULL);
+ CL_GetDemoInfo(buffer, &demo);
+ if (demo.mvd) {
+ strcpy(demo.pov, DEMO_MVD_POV);
}
}
// resize columns
- len = strlen( demo.map );
- if( len > 8 ) {
+ len = strlen(demo.map);
+ if (len > 8) {
len = 8;
}
- if( len > m_demos.widest_map ) {
+ if (len > m_demos.widest_map) {
m_demos.widest_map = len;
}
- len = strlen( demo.pov );
- if( len > m_demos.widest_pov ) {
+ len = strlen(demo.pov);
+ if (len > m_demos.widest_pov) {
m_demos.widest_pov = len;
}
// format date
- if( ( tm = localtime( &info->mtime ) ) != NULL ) {
- if( tm->tm_year == m_demos.year ) {
- strftime( date, sizeof( date ), "%b %d %H:%M", tm );
+ if ((tm = localtime(&info->mtime)) != NULL) {
+ if (tm->tm_year == m_demos.year) {
+ strftime(date, sizeof(date), "%b %d %H:%M", tm);
} else {
- strftime( date, sizeof( date ), "%b %d %Y", tm );
+ strftime(date, sizeof(date), "%b %d %Y", tm);
}
} else {
- strcpy( date, "???" );
+ strcpy(date, "???");
}
- Com_FormatSize( buffer, sizeof( buffer ), info->size );
+ Com_FormatSize(buffer, sizeof(buffer), info->size);
- e = UI_FormatColumns( DEMO_EXTRASIZE,
- info->name, date, buffer, demo.map, demo.pov, NULL );
+ e = UI_FormatColumns(DEMO_EXTRASIZE,
+ info->name, date, buffer, demo.map, demo.pov, NULL);
e->type = ENTRY_DEMO;
e->size = info->size;
e->mtime = info->mtime;
@@ -146,8 +147,9 @@ static void BuildName( const file_info_t *info, char **cache ) {
m_demos.list.items[m_demos.list.numItems++] = e;
}
-static void BuildDir( const char *name, int type ) {
- demoEntry_t *e = UI_FormatColumns( DEMO_EXTRASIZE, name, "-", DEMO_DIR_SIZE, "-", "-", NULL );
+static void BuildDir(const char *name, int type)
+{
+ demoEntry_t *e = UI_FormatColumns(DEMO_EXTRASIZE, name, "-", DEMO_DIR_SIZE, "-", "-", NULL);
e->type = type;
e->size = 0;
@@ -156,47 +158,49 @@ static void BuildDir( const char *name, int type ) {
m_demos.list.items[m_demos.list.numItems++] = e;
}
-static char *LoadCache( void **list ) {
+static char *LoadCache(void **list)
+{
char buffer[MAX_OSPATH], *cache;
int i;
size_t len;
uint8_t hash[16];
- len = Q_concat( buffer, sizeof( buffer ), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL );
- if( len >= sizeof( buffer ) ) {
+ len = Q_concat(buffer, sizeof(buffer), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL);
+ if (len >= sizeof(buffer)) {
return NULL;
}
- len = FS_LoadFileEx( buffer, ( void ** )&cache, FS_TYPE_REAL | FS_PATH_GAME, TAG_FILESYSTEM );
- if( !cache ) {
+ len = FS_LoadFileEx(buffer, (void **)&cache, FS_TYPE_REAL | FS_PATH_GAME, TAG_FILESYSTEM);
+ if (!cache) {
return NULL;
}
- if( len < 33 ) {
+ if (len < 33) {
goto fail;
}
- for( i = 0; i < 16; i++ ) {
- int c1 = Q_charhex( cache[i*2+0] );
- int c2 = Q_charhex( cache[i*2+1] );
- hash[i] = ( c1 << 4 ) | c2;
+ for (i = 0; i < 16; i++) {
+ int c1 = Q_charhex(cache[i * 2 + 0]);
+ int c2 = Q_charhex(cache[i * 2 + 1]);
+ hash[i] = (c1 << 4) | c2;
}
- if( cache[32] != '\\' ) {
+ if (cache[32] != '\\') {
goto fail;
}
- if( memcmp( hash, m_demos.hash, 16 ) ) {
+ if (memcmp(hash, m_demos.hash, 16)) {
goto fail;
}
- Com_DPrintf( "%s: loading from cache\n", __func__ );
+ Com_DPrintf("%s: loading from cache\n", __func__);
return cache;
fail:
- FS_FreeFile( cache );
+ FS_FreeFile(cache);
return NULL;
}
-static void WriteCache( void ) {
+static void WriteCache(void)
+{
char buffer[MAX_OSPATH];
qhandle_t f;
int i;
@@ -204,51 +208,53 @@ static void WriteCache( void ) {
demoEntry_t *e;
size_t len;
- if( m_demos.list.numItems == m_demos.numDirs ) {
+ if (m_demos.list.numItems == m_demos.numDirs) {
return;
}
- len = Q_concat( buffer, sizeof( buffer ), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL );
- if( len >= sizeof( buffer ) ) {
+ len = Q_concat(buffer, sizeof(buffer), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL);
+ if (len >= sizeof(buffer)) {
return;
}
- FS_FOpenFile( buffer, &f, FS_MODE_WRITE );
- if( !f ) {
+ FS_FOpenFile(buffer, &f, FS_MODE_WRITE);
+ if (!f) {
return;
}
- for( i = 0; i < 16; i++ ) {
- FS_FPrintf( f, "%02x", m_demos.hash[i] );
+ for (i = 0; i < 16; i++) {
+ FS_FPrintf(f, "%02x", m_demos.hash[i]);
}
- FS_FPrintf( f, "\\" );
+ FS_FPrintf(f, "\\");
- for( i = m_demos.numDirs; i < m_demos.list.numItems; i++ ) {
+ for (i = m_demos.numDirs; i < m_demos.list.numItems; i++) {
e = m_demos.list.items[i];
- map = UI_GetColumn( e->name, COL_MAP );
- pov = UI_GetColumn( e->name, COL_POV );
- FS_FPrintf( f, "%s\\%s\\", map, pov );
+ map = UI_GetColumn(e->name, COL_MAP);
+ pov = UI_GetColumn(e->name, COL_POV);
+ FS_FPrintf(f, "%s\\%s\\", map, pov);
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
}
-static void CalcHash( void **list ) {
+static void CalcHash(void **list)
+{
struct mdfour md;
file_info_t *info;
size_t len;
- mdfour_begin( &md );
- while( *list ) {
+ mdfour_begin(&md);
+ while (*list) {
info = *list++;
- len = sizeof( *info ) + strlen( info->name ) - 1;
- mdfour_update( &md, ( uint8_t * )info, len );
+ len = sizeof(*info) + strlen(info->name) - 1;
+ mdfour_update(&md, (uint8_t *)info, len);
}
- mdfour_result( &md, m_demos.hash );
+ mdfour_result(&md, m_demos.hash);
}
-static menuSound_t Change( menuCommon_t *self ) {
+static menuSound_t Change(menuCommon_t *self)
+{
demoEntry_t *e = m_demos.list.items[m_demos.list.curvalue];
- switch( e->type ) {
+ switch (e->type) {
case ENTRY_DEMO:
m_demos.menu.status = "Press Enter to play demo";
break;
@@ -259,7 +265,8 @@ static menuSound_t Change( menuCommon_t *self ) {
return QMS_SILENT;
}
-static void BuildList( void ) {
+static void BuildList(void)
+{
int numDirs, numDemos;
void **dirlist, **demolist;
char *cache, *p;
@@ -274,13 +281,13 @@ static void BuildList( void ) {
// list files
flags = ui_listalldemos->integer ? 0 : FS_TYPE_REAL | FS_PATH_GAME;
- dirlist = FS_ListFiles( m_demos.browse, NULL, flags |
- FS_SEARCH_DIRSONLY, &numDirs );
- demolist = FS_ListFiles( m_demos.browse, DEMO_EXTENSIONS, flags |
- FS_SEARCH_EXTRAINFO, &numDemos );
+ dirlist = FS_ListFiles(m_demos.browse, NULL, flags |
+ FS_SEARCH_DIRSONLY, &numDirs);
+ demolist = FS_ListFiles(m_demos.browse, DEMO_EXTENSIONS, flags |
+ FS_SEARCH_EXTRAINFO, &numDemos);
// alloc entries
- m_demos.list.items = UI_Malloc( sizeof( demoEntry_t * ) * ( numDirs + numDemos + 1 ) );
+ m_demos.list.items = UI_Malloc(sizeof(demoEntry_t *) * (numDirs + numDemos + 1));
m_demos.list.numItems = 0;
m_demos.list.curvalue = 0;
m_demos.list.prestep = 0;
@@ -290,84 +297,86 @@ static void BuildList( void ) {
m_demos.total_bytes = 0;
// start with minimum size
- m_demos.menu.size( &m_demos.menu );
+ m_demos.menu.size(&m_demos.menu);
- if( m_demos.browse[0] ) {
- BuildDir( "..", ENTRY_UP );
+ if (m_demos.browse[0]) {
+ BuildDir("..", ENTRY_UP);
}
// add directories
- if( dirlist ) {
- for( i = 0; i < numDirs; i++ ) {
- BuildDir( dirlist[i], ENTRY_DN );
+ if (dirlist) {
+ for (i = 0; i < numDirs; i++) {
+ BuildDir(dirlist[i], ENTRY_DN);
}
- FS_FreeList( dirlist );
- }
+ FS_FreeList(dirlist);
+ }
m_demos.numDirs = m_demos.list.numItems;
// add demos
- if( demolist ) {
- CalcHash( demolist );
- if( ( cache = LoadCache( demolist ) ) != NULL ) {
+ if (demolist) {
+ CalcHash(demolist);
+ if ((cache = LoadCache(demolist)) != NULL) {
p = cache + 32 + 1;
- for( i = 0; i < numDemos; i++ ) {
- BuildName( demolist[i], &p );
+ for (i = 0; i < numDemos; i++) {
+ BuildName(demolist[i], &p);
}
- FS_FreeFile( cache );
+ FS_FreeFile(cache);
} else {
- for( i = 0; i < numDemos; i++ ) {
- BuildName( demolist[i], NULL );
- if( ( i & 7 ) == 0 ) {
- m_demos.menu.size( &m_demos.menu );
+ for (i = 0; i < numDemos; i++) {
+ BuildName(demolist[i], NULL);
+ if ((i & 7) == 0) {
+ m_demos.menu.size(&m_demos.menu);
SCR_UpdateScreen();
}
}
}
WriteCache();
- FS_FreeList( demolist );
+ FS_FreeList(demolist);
}
// update status line and sort
- if( m_demos.list.numItems ) {
- Change( &m_demos.list.generic );
- if( m_demos.list.sortdir ) {
- m_demos.list.sort( &m_demos.list, m_demos.list.sortcol );
+ if (m_demos.list.numItems) {
+ Change(&m_demos.list.generic);
+ if (m_demos.list.sortdir) {
+ m_demos.list.sort(&m_demos.list, m_demos.list.sortcol);
}
}
// resize columns
- m_demos.menu.size( &m_demos.menu );
+ m_demos.menu.size(&m_demos.menu);
// format our extra status line
i = m_demos.list.numItems - m_demos.numDirs;
- len = Q_scnprintf( m_demos.status, sizeof( m_demos.status ),
- "%d demo%s, ", i, i == 1 ? "" : "s" );
- Com_FormatSizeLong( m_demos.status + len, sizeof( m_demos.status ) - len,
- m_demos.total_bytes );
-
+ len = Q_scnprintf(m_demos.status, sizeof(m_demos.status),
+ "%d demo%s, ", i, i == 1 ? "" : "s");
+ Com_FormatSizeLong(m_demos.status + len, sizeof(m_demos.status) - len,
+ m_demos.total_bytes);
+
SCR_UpdateScreen();
}
-static void FreeList( void ) {
+static void FreeList(void)
+{
int i;
- if( m_demos.list.items ) {
- for( i = 0; i < m_demos.list.numItems; i++ ) {
- Z_Free( m_demos.list.items[i] );
+ if (m_demos.list.items) {
+ for (i = 0; i < m_demos.list.numItems; i++) {
+ Z_Free(m_demos.list.items[i]);
}
- Z_Free( m_demos.list.items );
+ Z_Free(m_demos.list.items);
m_demos.list.items = NULL;
m_demos.list.numItems = 0;
}
}
-static void LeaveDirectory( void ) {
+static void LeaveDirectory(void)
+{
char *s;
int i;
- s = strrchr( m_demos.browse, '/' );
- if( !s ) {
+ s = strrchr(m_demos.browse, '/');
+ if (!s) {
return;
}
*s = 0;
@@ -375,188 +384,200 @@ static void LeaveDirectory( void ) {
// rebuild list
FreeList();
BuildList();
- MenuList_Init( &m_demos.list );
+ MenuList_Init(&m_demos.list);
// move cursor to the previous directory
- for( i = 0; i < m_demos.numDirs; i++ ) {
+ for (i = 0; i < m_demos.numDirs; i++) {
demoEntry_t *e = m_demos.list.items[i];
- if( !strcmp( e->name, s + 1 ) ) {
- MenuList_SetValue( &m_demos.list, i );
+ if (!strcmp(e->name, s + 1)) {
+ MenuList_SetValue(&m_demos.list, i);
break;
}
}
- if( s == m_demos.browse ) {
+ if (s == m_demos.browse) {
m_demos.browse[0] = '/';
m_demos.browse[1] = 0;
}
}
-static menuSound_t Activate( menuCommon_t *self ) {
+static menuSound_t Activate(menuCommon_t *self)
+{
size_t len, baselen;
demoEntry_t *e = m_demos.list.items[m_demos.list.curvalue];
- switch( e->type ) {
+ switch (e->type) {
case ENTRY_UP:
LeaveDirectory();
return QMS_OUT;
case ENTRY_DN:
- baselen = strlen( m_demos.browse );
- len = strlen( e->name );
- if( baselen + 1 + len >= sizeof( m_demos.browse ) ) {
+ baselen = strlen(m_demos.browse);
+ len = strlen(e->name);
+ if (baselen + 1 + len >= sizeof(m_demos.browse)) {
return QMS_BEEP;
}
- if( !baselen || m_demos.browse[ baselen - 1 ] != '/' ) {
- m_demos.browse[ baselen++ ] = '/';
+ if (!baselen || m_demos.browse[baselen - 1] != '/') {
+ m_demos.browse[baselen++] = '/';
}
- memcpy( m_demos.browse + baselen, e->name, len + 1 );
-
+ memcpy(m_demos.browse + baselen, e->name, len + 1);
+
// rebuild list
FreeList();
BuildList();
- MenuList_Init( &m_demos.list );
+ MenuList_Init(&m_demos.list);
return QMS_IN;
case ENTRY_DEMO:
- Cbuf_AddText( &cmd_buffer, va( "demo \"%s/%s\"\n", m_demos.browse[1] ?
- m_demos.browse : "", e->name ) );
+ Cbuf_AddText(&cmd_buffer, va("demo \"%s/%s\"\n", m_demos.browse[1] ?
+ m_demos.browse : "", e->name));
return QMS_SILENT;
}
return QMS_NOTHANDLED;
}
-static int sizecmp( const void *p1, const void *p2 ) {
- demoEntry_t *e1 = *( demoEntry_t ** )p1;
- demoEntry_t *e2 = *( demoEntry_t ** )p2;
+static int sizecmp(const void *p1, const void *p2)
+{
+ demoEntry_t *e1 = *(demoEntry_t **)p1;
+ demoEntry_t *e2 = *(demoEntry_t **)p2;
- if( e1->size > e2->size ) {
+ if (e1->size > e2->size) {
return m_demos.list.sortdir;
}
- if( e1->size < e2->size ) {
+ if (e1->size < e2->size) {
return -m_demos.list.sortdir;
}
return 0;
}
-static int timecmp( const void *p1, const void *p2 ) {
- demoEntry_t *e1 = *( demoEntry_t ** )p1;
- demoEntry_t *e2 = *( demoEntry_t ** )p2;
+static int timecmp(const void *p1, const void *p2)
+{
+ demoEntry_t *e1 = *(demoEntry_t **)p1;
+ demoEntry_t *e2 = *(demoEntry_t **)p2;
- if( e1->mtime > e2->mtime ) {
+ if (e1->mtime > e2->mtime) {
return m_demos.list.sortdir;
}
- if( e1->mtime < e2->mtime ) {
+ if (e1->mtime < e2->mtime) {
return -m_demos.list.sortdir;
}
return 0;
}
-static int namecmp( const void *p1, const void *p2 ) {
- demoEntry_t *e1 = *( demoEntry_t ** )p1;
- demoEntry_t *e2 = *( demoEntry_t ** )p2;
- char *s1 = UI_GetColumn( e1->name, m_demos.list.sortcol );
- char *s2 = UI_GetColumn( e2->name, m_demos.list.sortcol );
+static int namecmp(const void *p1, const void *p2)
+{
+ demoEntry_t *e1 = *(demoEntry_t **)p1;
+ demoEntry_t *e2 = *(demoEntry_t **)p2;
+ char *s1 = UI_GetColumn(e1->name, m_demos.list.sortcol);
+ char *s2 = UI_GetColumn(e2->name, m_demos.list.sortcol);
- return Q_stricmp( s1, s2 ) * m_demos.list.sortdir;
+ return Q_stricmp(s1, s2) * m_demos.list.sortdir;
}
-static menuSound_t Sort( menuList_t *self, int column ) {
- switch( column ) {
+static menuSound_t Sort(menuList_t *self, int column)
+{
+ switch (column) {
case COL_NAME:
case COL_MAP:
case COL_POV:
- MenuList_Sort( &m_demos.list, m_demos.numDirs, namecmp );
+ MenuList_Sort(&m_demos.list, m_demos.numDirs, namecmp);
break;
case COL_DATE:
- MenuList_Sort( &m_demos.list, m_demos.numDirs, timecmp );
+ MenuList_Sort(&m_demos.list, m_demos.numDirs, timecmp);
break;
case COL_SIZE:
- MenuList_Sort( &m_demos.list, m_demos.numDirs, sizecmp );
+ MenuList_Sort(&m_demos.list, m_demos.numDirs, sizecmp);
break;
}
return QMS_SILENT;
}
-static void Size( menuFrameWork_t *self ) {
+static void Size(menuFrameWork_t *self)
+{
int w1, w2;
m_demos.list.generic.x = 0;
m_demos.list.generic.y = CHAR_HEIGHT;
m_demos.list.generic.width = 0;
- m_demos.list.generic.height = uis.height - CHAR_HEIGHT*2 - 1;
+ m_demos.list.generic.height = uis.height - CHAR_HEIGHT * 2 - 1;
w1 = 17 + m_demos.widest_map + m_demos.widest_pov;
- w2 = uis.width - ( w1 + 2 ) * CHAR_WIDTH - MLIST_SCROLLBAR_WIDTH;
- if( w2 > 8 * CHAR_WIDTH ) {
+ w2 = uis.width - (w1 + 2) * CHAR_WIDTH - MLIST_SCROLLBAR_WIDTH;
+ if (w2 > 8 * CHAR_WIDTH) {
// everything fits
m_demos.list.columns[0].width = w2;
- m_demos.list.columns[1].width = 12*CHAR_WIDTH+CHAR_WIDTH/2;
- m_demos.list.columns[2].width = 5*CHAR_WIDTH+CHAR_WIDTH/2;
- m_demos.list.columns[3].width = m_demos.widest_map*CHAR_WIDTH+CHAR_WIDTH/2;
- m_demos.list.columns[4].width = m_demos.widest_pov*CHAR_WIDTH+CHAR_WIDTH/2;
+ m_demos.list.columns[1].width = 12 * CHAR_WIDTH + CHAR_WIDTH / 2;
+ m_demos.list.columns[2].width = 5 * CHAR_WIDTH + CHAR_WIDTH / 2;
+ m_demos.list.columns[3].width = m_demos.widest_map * CHAR_WIDTH + CHAR_WIDTH / 2;
+ m_demos.list.columns[4].width = m_demos.widest_pov * CHAR_WIDTH + CHAR_WIDTH / 2;
m_demos.list.numcolumns = COL_MAX;
} else {
// map and pov don't fit
- w2 = uis.width - ( 17 + 1 ) * CHAR_WIDTH - MLIST_SCROLLBAR_WIDTH;
+ w2 = uis.width - (17 + 1) * CHAR_WIDTH - MLIST_SCROLLBAR_WIDTH;
m_demos.list.columns[0].width = w2;
- m_demos.list.columns[1].width = 12*CHAR_WIDTH+CHAR_WIDTH/2;
- m_demos.list.columns[2].width = 5*CHAR_WIDTH+CHAR_WIDTH/2;
+ m_demos.list.columns[1].width = 12 * CHAR_WIDTH + CHAR_WIDTH / 2;
+ m_demos.list.columns[2].width = 5 * CHAR_WIDTH + CHAR_WIDTH / 2;
m_demos.list.columns[3].width = 0;
m_demos.list.columns[4].width = 0;
m_demos.list.numcolumns = COL_MAX - 2;
}
}
-static menuSound_t Keydown( menuFrameWork_t *self, int key ) {
- if( key == K_BACKSPACE ) {
+static menuSound_t Keydown(menuFrameWork_t *self, int key)
+{
+ if (key == K_BACKSPACE) {
LeaveDirectory();
return QMS_OUT;
}
return QMS_NOTHANDLED;
}
-static void Draw( menuFrameWork_t *self ) {
- Menu_Draw( self );
- if( uis.width >= 640 ) {
- UI_DrawString( uis.width, uis.height - CHAR_HEIGHT,
- UI_RIGHT, m_demos.status );
+static void Draw(menuFrameWork_t *self)
+{
+ Menu_Draw(self);
+ if (uis.width >= 640) {
+ UI_DrawString(uis.width, uis.height - CHAR_HEIGHT,
+ UI_RIGHT, m_demos.status);
}
}
-static void Pop( menuFrameWork_t *self ) {
+static void Pop(menuFrameWork_t *self)
+{
// save previous position
m_demos.selection = m_demos.list.curvalue;
FreeList();
}
-static void Expose( menuFrameWork_t *self ) {
- time_t now = time( NULL );
- struct tm *tm = localtime( &now );
+static void Expose(menuFrameWork_t *self)
+{
+ time_t now = time(NULL);
+ struct tm *tm = localtime(&now);
- if( tm ) {
+ if (tm) {
m_demos.year = tm->tm_year;
}
BuildList();
// move cursor to previous position
- MenuList_SetValue( &m_demos.list, m_demos.selection );
+ MenuList_SetValue(&m_demos.list, m_demos.selection);
}
-static void Free( menuFrameWork_t *self ) {
- memset( &m_demos, 0, sizeof( m_demos ) );
+static void Free(menuFrameWork_t *self)
+{
+ memset(&m_demos, 0, sizeof(m_demos));
}
-static void ui_sortdemos_changed( cvar_t *self ) {
- int i = Cvar_ClampInteger( self, -COL_MAX, COL_MAX );
+static void ui_sortdemos_changed(cvar_t *self)
+{
+ int i = Cvar_ClampInteger(self, -COL_MAX, COL_MAX);
- if( i > 0 ) {
+ if (i > 0) {
// ascending
m_demos.list.sortdir = 1;
m_demos.list.sortcol = i - 1;
- } else if( i < 0 ) {
+ } else if (i < 0) {
// descending
m_demos.list.sortdir = -1;
m_demos.list.sortcol = -i - 1;
@@ -566,21 +587,22 @@ static void ui_sortdemos_changed( cvar_t *self ) {
m_demos.list.sortcol = 0;
}
- if( m_demos.list.items && m_demos.list.sortdir ) {
- m_demos.list.sort( &m_demos.list, m_demos.list.sortcol );
+ if (m_demos.list.items && m_demos.list.sortdir) {
+ m_demos.list.sort(&m_demos.list, m_demos.list.sortcol);
}
}
-void M_Menu_Demos( void ) {
- ui_sortdemos = Cvar_Get( "ui_sortdemos", "1", 0 );
+void M_Menu_Demos(void)
+{
+ ui_sortdemos = Cvar_Get("ui_sortdemos", "1", 0);
ui_sortdemos->changed = ui_sortdemos_changed;
- ui_listalldemos = Cvar_Get( "ui_listalldemos", "0", 0 );
+ ui_listalldemos = Cvar_Get("ui_listalldemos", "0", 0);
m_demos.menu.name = "demos";
m_demos.menu.title = "Demo Browser";
- strcpy( m_demos.browse, "/demos" );
+ strcpy(m_demos.browse, "/demos");
m_demos.menu.draw = Draw;
m_demos.menu.expose = Expose;
@@ -612,11 +634,11 @@ void M_Menu_Demos( void ) {
m_demos.list.columns[4].name = "POV";
m_demos.list.columns[4].uiFlags = UI_CENTER;
- ui_sortdemos_changed( ui_sortdemos );
+ ui_sortdemos_changed(ui_sortdemos);
- Menu_AddItem( &m_demos.menu, &m_demos.list );
+ Menu_AddItem(&m_demos.menu, &m_demos.list);
- List_Append( &ui_menus, &m_demos.menu.entry );
+ List_Append(&ui_menus, &m_demos.menu.entry);
}
diff --git a/src/ui_local.h b/src/ui_local.h
index ef860c3..8b80f66 100644
--- a/src/ui_local.h
+++ b/src/ui_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,9 +27,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_public.h"
#include "ui_public.h"
-#define UI_Malloc( s ) Z_TagMalloc( s, TAG_UI )
-#define UI_Mallocz( s ) Z_TagMallocz( s, TAG_UI )
-#define UI_CopyString( s ) Z_TagCopyString( s, TAG_UI )
+#define UI_Malloc(s) Z_TagMalloc(s, TAG_UI)
+#define UI_Mallocz(s) Z_TagMallocz(s, TAG_UI)
+#define UI_CopyString(s) Z_TagCopyString(s, TAG_UI)
#define MAXMENUITEMS 64
@@ -68,21 +68,21 @@ typedef enum {
QMS_BEEP
} menuSound_t;
-#define RCOLUMN_OFFSET (CHAR_WIDTH*2)
+#define RCOLUMN_OFFSET (CHAR_WIDTH * 2)
#define LCOLUMN_OFFSET -RCOLUMN_OFFSET
-#define GENERIC_SPACING(x) ((x)+(x)/4)
+#define GENERIC_SPACING(x) ((x) + (x) / 4)
#define MENU_SPACING GENERIC_SPACING(CHAR_HEIGHT)
#define DOUBLE_CLICK_DELAY 300
-#define UI_IsItemSelectable( item ) \
- ( (item)->type != MTYPE_SEPARATOR && \
- (item)->type != MTYPE_STATIC && \
- !( (item)->flags & (QMF_GRAYED|QMF_HIDDEN|QMF_DISABLED) ) )
+#define UI_IsItemSelectable(item) \
+ ((item)->type != MTYPE_SEPARATOR && \
+ (item)->type != MTYPE_STATIC && \
+ !((item)->flags & (QMF_GRAYED | QMF_HIDDEN | QMF_DISABLED)))
-typedef void (*confirmAction_t)( qboolean );
+typedef void (*confirmAction_t)(qboolean);
typedef struct menuFrameWork_s {
list_t entry;
@@ -111,13 +111,13 @@ typedef struct menuFrameWork_s {
qhandle_t logo;
vrect_t logo_rc;
- qboolean (*push)( struct menuFrameWork_s * );
- void (*pop)( struct menuFrameWork_s * );
- void (*expose)( struct menuFrameWork_s * );
- void (*draw)( struct menuFrameWork_s * );
- void (*size)( struct menuFrameWork_s * );
- void (*free)( struct menuFrameWork_s * );
- menuSound_t (*keydown)( struct menuFrameWork_s *, int );
+ qboolean (*push)(struct menuFrameWork_s *);
+ void (*pop)(struct menuFrameWork_s *);
+ void (*expose)(struct menuFrameWork_s *);
+ void (*draw)(struct menuFrameWork_s *);
+ void (*size)(struct menuFrameWork_s *);
+ void (*free)(struct menuFrameWork_s *);
+ menuSound_t (*keydown)(struct menuFrameWork_s *, int);
} menuFrameWork_t;
typedef struct menuCommon_s {
@@ -135,10 +135,10 @@ typedef struct menuCommon_s {
int flags;
int uiFlags;
- menuSound_t (*activate)( struct menuCommon_s * );
- menuSound_t (*change)( struct menuCommon_s * );
- menuSound_t (*keydown)( struct menuCommon_s *, int key );
- menuSound_t (*focus)( struct menuCommon_s *, qboolean gain );
+ menuSound_t (*activate)(struct menuCommon_s *);
+ menuSound_t (*change)(struct menuCommon_s *);
+ menuSound_t (*keydown)(struct menuCommon_s *, int key);
+ menuSound_t (*focus)(struct menuCommon_s *, qboolean gain);
} menuCommon_t;
typedef struct menuField_s {
@@ -199,7 +199,7 @@ typedef struct menuList_s {
int numcolumns;
int sortdir, sortcol;
- menuSound_t (*sort)( struct menuList_s *, int column );
+ menuSound_t (*sort)(struct menuList_s *, int column);
} menuList_t;
typedef struct menuSpinControl_s {
@@ -252,8 +252,8 @@ typedef struct playerModelInfo_s {
char directory[MAX_QPATH];
} playerModelInfo_t;
-void PlayerModel_Load( void );
-void PlayerModel_Free( void );
+void PlayerModel_Load(void);
+void PlayerModel_Free(void);
#define MAX_MENU_DEPTH 8
@@ -274,7 +274,7 @@ typedef struct uiStatic_s {
menuFrameWork_t *activeMenu;
int mouseCoords[2];
qboolean entersound; // play after drawing a frame, so caching
- // won't disrupt the sound
+ // won't disrupt the sound
qboolean transparent;
int numPlayerModels;
playerModelInfo_t pmi[MAX_PLAYERMODELS];
@@ -302,48 +302,48 @@ extern list_t ui_menus;
extern cvar_t *ui_debug;
-void UI_PushMenu( menuFrameWork_t *menu );
-void UI_ForceMenuOff( void );
-void UI_PopMenu( void );
-void UI_StartSound( menuSound_t sound );
-qboolean UI_DoHitTest( void );
-qboolean UI_CursorInRect( vrect_t *rect );
-void *UI_FormatColumns( int extrasize, ... ) q_sentinel;
-char *UI_GetColumn( char *s, int n );
-void UI_AddToServerList( const serverStatus_t *status );
-void UI_DrawString( int x, int y, int flags, const char *string );
-void UI_DrawChar( int x, int y, int flags, int ch );
-void UI_DrawRect8( const vrect_t *rect, int border, int c );
-//void UI_DrawRect32( const vrect_t *rect, int border, uint32_t color );
-void UI_StringDimensions( vrect_t *rc, int flags, const char *string );
-
-void UI_LoadScript( void );
-menuFrameWork_t *UI_FindMenu( const char *name );
-
-void Menu_Init( menuFrameWork_t *menu );
-void Menu_Size( menuFrameWork_t *menu );
-void Menu_Draw( menuFrameWork_t *menu );
-void Menu_AddItem( menuFrameWork_t *menu, void *item );
-menuSound_t Menu_SelectItem( menuFrameWork_t *menu );
-menuSound_t Menu_SlideItem( menuFrameWork_t *menu, int dir );
-menuSound_t Menu_KeyEvent( menuCommon_t *item, int key );
-menuSound_t Menu_CharEvent( menuCommon_t *item, int key );
-menuSound_t Menu_MouseMove( menuCommon_t *item );
-menuSound_t Menu_Keydown( menuFrameWork_t *menu, int key );
-void Menu_SetFocus( menuCommon_t *item );
-menuSound_t Menu_AdjustCursor( menuFrameWork_t *menu, int dir );
-menuCommon_t *Menu_ItemAtCursor( menuFrameWork_t *menu );
-menuCommon_t *Menu_HitTest( menuFrameWork_t *menu );
-void MenuList_Init( menuList_t *l );
-void MenuList_SetValue( menuList_t *l, int value );
-void MenuList_Sort( menuList_t *l, int offset,
- int (*cmpfunc)( const void *, const void * ) );
-void SpinControl_Init( menuSpinControl_t *s );
-qboolean Menu_Push( menuFrameWork_t *menu );
-void Menu_Pop( menuFrameWork_t *menu );
-void Menu_Free( menuFrameWork_t *menu );
-
-void M_Menu_PlayerConfig( void );
-void M_Menu_Demos( void );
-void M_Menu_Servers( void );
+void UI_PushMenu(menuFrameWork_t *menu);
+void UI_ForceMenuOff(void);
+void UI_PopMenu(void);
+void UI_StartSound(menuSound_t sound);
+qboolean UI_DoHitTest(void);
+qboolean UI_CursorInRect(vrect_t *rect);
+void *UI_FormatColumns(int extrasize, ...) q_sentinel;
+char *UI_GetColumn(char *s, int n);
+void UI_AddToServerList(const serverStatus_t *status);
+void UI_DrawString(int x, int y, int flags, const char *string);
+void UI_DrawChar(int x, int y, int flags, int ch);
+void UI_DrawRect8(const vrect_t *rect, int border, int c);
+//void UI_DrawRect32(const vrect_t *rect, int border, uint32_t color);
+void UI_StringDimensions(vrect_t *rc, int flags, const char *string);
+
+void UI_LoadScript(void);
+menuFrameWork_t *UI_FindMenu(const char *name);
+
+void Menu_Init(menuFrameWork_t *menu);
+void Menu_Size(menuFrameWork_t *menu);
+void Menu_Draw(menuFrameWork_t *menu);
+void Menu_AddItem(menuFrameWork_t *menu, void *item);
+menuSound_t Menu_SelectItem(menuFrameWork_t *menu);
+menuSound_t Menu_SlideItem(menuFrameWork_t *menu, int dir);
+menuSound_t Menu_KeyEvent(menuCommon_t *item, int key);
+menuSound_t Menu_CharEvent(menuCommon_t *item, int key);
+menuSound_t Menu_MouseMove(menuCommon_t *item);
+menuSound_t Menu_Keydown(menuFrameWork_t *menu, int key);
+void Menu_SetFocus(menuCommon_t *item);
+menuSound_t Menu_AdjustCursor(menuFrameWork_t *menu, int dir);
+menuCommon_t *Menu_ItemAtCursor(menuFrameWork_t *menu);
+menuCommon_t *Menu_HitTest(menuFrameWork_t *menu);
+void MenuList_Init(menuList_t *l);
+void MenuList_SetValue(menuList_t *l, int value);
+void MenuList_Sort(menuList_t *l, int offset,
+ int (*cmpfunc)(const void *, const void *));
+void SpinControl_Init(menuSpinControl_t *s);
+qboolean Menu_Push(menuFrameWork_t *menu);
+void Menu_Pop(menuFrameWork_t *menu);
+void Menu_Free(menuFrameWork_t *menu);
+
+void M_Menu_PlayerConfig(void);
+void M_Menu_Demos(void);
+void M_Menu_Servers(void);
diff --git a/src/ui_menu.c b/src/ui_menu.c
index 9611fb0..a931620 100644
--- a/src/ui_menu.c
+++ b/src/ui_menu.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,10 +28,11 @@ ACTION CONTROL
===================================================================
*/
-static void Action_Free( menuAction_t *a ) {
- Z_Free( a->generic.name );
- Z_Free( a->cmd );
- Z_Free( a );
+static void Action_Free(menuAction_t *a)
+{
+ Z_Free(a->generic.name);
+ Z_Free(a->cmd);
+ Z_Free(a);
}
/*
@@ -39,18 +40,19 @@ static void Action_Free( menuAction_t *a ) {
Action_Init
=================
*/
-static void Action_Init( menuAction_t *a ) {
- if( !a->generic.name ) {
- Com_Error( ERR_FATAL, "Action_Init: NULL a->generic.name" );
+static void Action_Init(menuAction_t *a)
+{
+ if (!a->generic.name) {
+ Com_Error(ERR_FATAL, "Action_Init: NULL a->generic.name");
}
- if( ( a->generic.uiFlags & UI_CENTER ) != UI_CENTER ) {
+ if ((a->generic.uiFlags & UI_CENTER) != UI_CENTER) {
a->generic.x += RCOLUMN_OFFSET;
}
a->generic.rect.x = a->generic.x;
a->generic.rect.y = a->generic.y;
- UI_StringDimensions( &a->generic.rect, a->generic.uiFlags, a->generic.name );
+ UI_StringDimensions(&a->generic.rect, a->generic.uiFlags, a->generic.name);
}
@@ -59,24 +61,25 @@ static void Action_Init( menuAction_t *a ) {
Action_Draw
=================
*/
-static void Action_Draw( menuAction_t *a ) {
+static void Action_Draw(menuAction_t *a)
+{
int flags;
flags = a->generic.uiFlags;
- if( a->generic.flags & QMF_HASFOCUS ) {
- if( ( a->generic.uiFlags & UI_CENTER ) != UI_CENTER ) {
- if( ( uis.realtime >> 8 ) & 1 ) {
- UI_DrawChar( a->generic.x - RCOLUMN_OFFSET / 2, a->generic.y, a->generic.uiFlags | UI_RIGHT, 13 );
+ if (a->generic.flags & QMF_HASFOCUS) {
+ if ((a->generic.uiFlags & UI_CENTER) != UI_CENTER) {
+ if ((uis.realtime >> 8) & 1) {
+ UI_DrawChar(a->generic.x - RCOLUMN_OFFSET / 2, a->generic.y, a->generic.uiFlags | UI_RIGHT, 13);
}
} else {
flags |= UI_ALTCOLOR;
- if( ( uis.realtime >> 8 ) & 1 ) {
- UI_DrawChar( a->generic.x - strlen( a->generic.name ) * CHAR_WIDTH / 2 - CHAR_WIDTH, a->generic.y, flags, 13 );
+ if ((uis.realtime >> 8) & 1) {
+ UI_DrawChar(a->generic.x - strlen(a->generic.name) * CHAR_WIDTH / 2 - CHAR_WIDTH, a->generic.y, flags, 13);
}
}
}
- UI_DrawString( a->generic.x, a->generic.y, flags, a->generic.name );
+ UI_DrawString(a->generic.x, a->generic.y, flags, a->generic.name);
}
/*
@@ -92,20 +95,21 @@ STATIC CONTROL
Static_Init
=================
*/
-static void Static_Init( menuStatic_t *s ) {
- if( !s->generic.name ) {
- Com_Error( ERR_FATAL, "Static_Init: NULL s->generic.name" );
+static void Static_Init(menuStatic_t *s)
+{
+ if (!s->generic.name) {
+ Com_Error(ERR_FATAL, "Static_Init: NULL s->generic.name");
}
- if( !s->maxChars ) {
+ if (!s->maxChars) {
s->maxChars = MAX_STRING_CHARS;
}
s->generic.rect.x = s->generic.x;
s->generic.rect.y = s->generic.y;
- UI_StringDimensions( &s->generic.rect,
- s->generic.uiFlags, s->generic.name );
+ UI_StringDimensions(&s->generic.rect,
+ s->generic.uiFlags, s->generic.name);
}
/*
@@ -113,12 +117,13 @@ static void Static_Init( menuStatic_t *s ) {
Static_Draw
=================
*/
-static void Static_Draw( menuStatic_t *s ) {
- if( s->generic.flags & QMF_CUSTOM_COLOR ) {
- R_SetColor( s->generic.color.u32 );
+static void Static_Draw(menuStatic_t *s)
+{
+ if (s->generic.flags & QMF_CUSTOM_COLOR) {
+ R_SetColor(s->generic.color.u32);
}
- UI_DrawString( s->generic.x, s->generic.y, s->generic.uiFlags, s->generic.name );
- if( s->generic.flags & QMF_CUSTOM_COLOR ) {
+ UI_DrawString(s->generic.x, s->generic.y, s->generic.uiFlags, s->generic.name);
+ if (s->generic.flags & QMF_CUSTOM_COLOR) {
R_ClearColor();
}
}
@@ -131,25 +136,28 @@ BITMAP CONTROL
===================================================================
*/
-static void Bitmap_Free( menuBitmap_t *b ) {
- Z_Free( b->cmd );
- Z_Free( b );
+static void Bitmap_Free(menuBitmap_t *b)
+{
+ Z_Free(b->cmd);
+ Z_Free(b);
}
-static void Bitmap_Init( menuBitmap_t *b ) {
+static void Bitmap_Init(menuBitmap_t *b)
+{
b->generic.rect.x = b->generic.x;
b->generic.rect.y = b->generic.y;
b->generic.rect.width = b->generic.width;
b->generic.rect.height = b->generic.height;
}
-static void Bitmap_Draw( menuBitmap_t *b ) {
- if( b->generic.flags & QMF_HASFOCUS ) {
- unsigned frame = ( uis.realtime / 100 ) % NUM_CURSOR_FRAMES;
- R_DrawPic( b->generic.x - CURSOR_OFFSET, b->generic.y, uis.bitmapCursors[frame] );
- R_DrawPic( b->generic.x, b->generic.y, b->pics[1] );
+static void Bitmap_Draw(menuBitmap_t *b)
+{
+ if (b->generic.flags & QMF_HASFOCUS) {
+ unsigned frame = (uis.realtime / 100) % NUM_CURSOR_FRAMES;
+ R_DrawPic(b->generic.x - CURSOR_OFFSET, b->generic.y, uis.bitmapCursors[frame]);
+ R_DrawPic(b->generic.x, b->generic.y, b->pics[1]);
} else {
- R_DrawPic( b->generic.x, b->generic.y, b->pics[0] );
+ R_DrawPic(b->generic.x, b->generic.y, b->pics[0]);
}
}
@@ -161,10 +169,11 @@ KEYBIND CONTROL
===================================================================
*/
-static void Keybind_Free( menuKeybind_t *k ) {
- Z_Free( k->generic.name );
- Z_Free( k->cmd );
- Z_Free( k );
+static void Keybind_Free(menuKeybind_t *k)
+{
+ Z_Free(k->generic.name);
+ Z_Free(k->cmd);
+ Z_Free(k);
}
/*
@@ -172,21 +181,22 @@ static void Keybind_Free( menuKeybind_t *k ) {
Keybind_Init
=================
*/
-static void Keybind_Init( menuKeybind_t *k ) {
- if( !k->generic.name ) {
- Com_Error( ERR_FATAL, "Keybind_Init: NULL k->generic.name" );
+static void Keybind_Init(menuKeybind_t *k)
+{
+ if (!k->generic.name) {
+ Com_Error(ERR_FATAL, "Keybind_Init: NULL k->generic.name");
}
- k->generic.uiFlags &= ~( UI_LEFT | UI_RIGHT );
+ k->generic.uiFlags &= ~(UI_LEFT | UI_RIGHT);
k->generic.rect.x = k->generic.x + LCOLUMN_OFFSET;
k->generic.rect.y = k->generic.y;
- UI_StringDimensions( &k->generic.rect,
- k->generic.uiFlags | UI_RIGHT, k->generic.name );
+ UI_StringDimensions(&k->generic.rect,
+ k->generic.uiFlags | UI_RIGHT, k->generic.name);
- k->generic.rect.width += ( RCOLUMN_OFFSET - LCOLUMN_OFFSET ) +
- strlen( k->binding ) * CHAR_WIDTH;
+ k->generic.rect.width += (RCOLUMN_OFFSET - LCOLUMN_OFFSET) +
+ strlen(k->binding) * CHAR_WIDTH;
}
/*
@@ -194,130 +204,139 @@ static void Keybind_Init( menuKeybind_t *k ) {
Keybind_Draw
=================
*/
-static void Keybind_Draw( menuKeybind_t *k ) {
+static void Keybind_Draw(menuKeybind_t *k)
+{
char string[MAX_STRING_CHARS];
int flags;
flags = UI_ALTCOLOR;
- if( k->generic.flags & QMF_HASFOCUS ) {
- /*if( k->generic.parent->keywait ) {
- UI_DrawChar( k->generic.x + RCOLUMN_OFFSET / 2, k->generic.y, k->generic.uiFlags | UI_RIGHT, '=' );
- } else*/ if( ( uis.realtime >> 8 ) & 1 ) {
- UI_DrawChar( k->generic.x + RCOLUMN_OFFSET / 2, k->generic.y, k->generic.uiFlags | UI_RIGHT, 13 );
+ if (k->generic.flags & QMF_HASFOCUS) {
+ /*if(k->generic.parent->keywait) {
+ UI_DrawChar(k->generic.x + RCOLUMN_OFFSET / 2, k->generic.y, k->generic.uiFlags | UI_RIGHT, '=');
+ } else*/ if ((uis.realtime >> 8) & 1) {
+ UI_DrawChar(k->generic.x + RCOLUMN_OFFSET / 2, k->generic.y, k->generic.uiFlags | UI_RIGHT, 13);
}
} else {
- if( k->generic.parent->keywait ) {
- R_SetColor( uis.color.disabled.u32 );
+ if (k->generic.parent->keywait) {
+ R_SetColor(uis.color.disabled.u32);
flags = 0;
}
}
- UI_DrawString( k->generic.x + LCOLUMN_OFFSET, k->generic.y,
- k->generic.uiFlags | UI_RIGHT | flags, k->generic.name );
+ UI_DrawString(k->generic.x + LCOLUMN_OFFSET, k->generic.y,
+ k->generic.uiFlags | UI_RIGHT | flags, k->generic.name);
- if( k->altbinding[0] ) {
- Q_concat( string, sizeof( string ), k->binding, " or ", k->altbinding, NULL );
- } else if( k->binding[0] ) {
- strcpy( string, k->binding );
+ if (k->altbinding[0]) {
+ Q_concat(string, sizeof(string), k->binding, " or ", k->altbinding, NULL);
+ } else if (k->binding[0]) {
+ strcpy(string, k->binding);
} else {
- strcpy( string, "???" );
+ strcpy(string, "???");
}
- UI_DrawString( k->generic.x + RCOLUMN_OFFSET, k->generic.y,
- k->generic.uiFlags | UI_LEFT, string );
+ UI_DrawString(k->generic.x + RCOLUMN_OFFSET, k->generic.y,
+ k->generic.uiFlags | UI_LEFT, string);
R_ClearColor();
}
-static void Keybind_Push( menuKeybind_t *k ) {
- int key = Key_EnumBindings( 0, k->cmd );
+static void Keybind_Push(menuKeybind_t *k)
+{
+ int key = Key_EnumBindings(0, k->cmd);
+
k->altbinding[0] = 0;
- if( key == -1 ) {
- strcpy( k->binding, "???" );
+ if (key == -1) {
+ strcpy(k->binding, "???");
} else {
- strcpy( k->binding, Key_KeynumToString( key ) );
- key = Key_EnumBindings( key + 1, k->cmd );
- if( key != -1 ) {
- strcpy( k->altbinding, Key_KeynumToString( key ) );
+ strcpy(k->binding, Key_KeynumToString(key));
+ key = Key_EnumBindings(key + 1, k->cmd);
+ if (key != -1) {
+ strcpy(k->altbinding, Key_KeynumToString(key));
}
}
}
-static void Keybind_Pop( menuKeybind_t *k ) {
- Key_WaitKey( NULL, NULL );
+static void Keybind_Pop(menuKeybind_t *k)
+{
+ Key_WaitKey(NULL, NULL);
}
-static void Keybind_Update( menuFrameWork_t *menu ) {
+static void Keybind_Update(menuFrameWork_t *menu)
+{
menuKeybind_t *k;
int i;
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
k = menu->items[i];
- if( k->generic.type == MTYPE_KEYBIND ) {
- Keybind_Push( k );
+ if (k->generic.type == MTYPE_KEYBIND) {
+ Keybind_Push(k);
}
}
}
-static void Keybind_Remove( const char *cmd ) {
+static void Keybind_Remove(const char *cmd)
+{
int key;
- for( key = 0; ; key++ ) {
- key = Key_EnumBindings( key, cmd );
- if( key == -1 ) {
+ for (key = 0; ; key++) {
+ key = Key_EnumBindings(key, cmd);
+ if (key == -1) {
break;
}
- Key_SetBinding( key, NULL );
+ Key_SetBinding(key, NULL);
}
}
-static qboolean keybind_cb( void *arg, int key ) {
+static qboolean keybind_cb(void *arg, int key)
+{
menuKeybind_t *k = arg;
menuFrameWork_t *menu = k->generic.parent;
// console key is hardcoded
- if( key == '`' ) {
- UI_StartSound( QMS_BEEP );
+ if (key == '`') {
+ UI_StartSound(QMS_BEEP);
return qfalse;
}
// menu key is hardcoded
- if( key != K_ESCAPE ) {
- if( k->altbinding[0] ) {
- Keybind_Remove( k->cmd );
+ if (key != K_ESCAPE) {
+ if (k->altbinding[0]) {
+ Keybind_Remove(k->cmd);
}
- Key_SetBinding( key, k->cmd );
+ Key_SetBinding(key, k->cmd);
}
- Keybind_Update( menu );
+ Keybind_Update(menu);
menu->keywait = qfalse;
menu->status = "Press Enter to change, Backspace to clear";
- Key_WaitKey( NULL, NULL );
+ Key_WaitKey(NULL, NULL);
- UI_StartSound( QMS_OUT );
+ UI_StartSound(QMS_OUT);
return qfalse;
}
-static menuSound_t Keybind_DoEnter( menuKeybind_t *k ) {
+static menuSound_t Keybind_DoEnter(menuKeybind_t *k)
+{
menuFrameWork_t *menu = k->generic.parent;
menu->keywait = qtrue;
menu->status = "Press the desired key, Escape to cancel";
- Key_WaitKey( keybind_cb, k );
+ Key_WaitKey(keybind_cb, k);
return QMS_IN;
}
-static menuSound_t Keybind_Key( menuKeybind_t *k, int key ) {
+static menuSound_t Keybind_Key(menuKeybind_t *k, int key)
+{
menuFrameWork_t *menu = k->generic.parent;
- if( menu->keywait ) {
+ if (menu->keywait) {
return QMS_OUT; // never gets there
}
-
- if( key == K_BACKSPACE || key == K_DEL ) {
- Keybind_Remove( k->cmd );
- Keybind_Update( menu );
+
+ if (key == K_BACKSPACE || key == K_DEL) {
+ Keybind_Remove(k->cmd);
+ Keybind_Update(menu);
return QMS_IN;
}
@@ -333,19 +352,22 @@ FIELD CONTROL
===================================================================
*/
-static void Field_Push( menuField_t *f ) {
- IF_Init( &f->field, f->width, f->width );
- IF_Replace( &f->field, f->cvar->string );
+static void Field_Push(menuField_t *f)
+{
+ IF_Init(&f->field, f->width, f->width);
+ IF_Replace(&f->field, f->cvar->string);
}
-static void Field_Pop( menuField_t *f ) {
- Cvar_SetByVar( f->cvar, f->field.text, FROM_MENU );
+static void Field_Pop(menuField_t *f)
+{
+ Cvar_SetByVar(f->cvar, f->field.text, FROM_MENU);
}
-static void Field_Free( menuField_t *f ) {
- Z_Free( f->generic.name );
- Z_Free( f->generic.status );
- Z_Free( f );
+static void Field_Free(menuField_t *f)
+{
+ Z_Free(f->generic.name);
+ Z_Free(f->generic.status);
+ Z_Free(f);
}
/*
@@ -353,17 +375,18 @@ static void Field_Free( menuField_t *f ) {
Field_Init
=================
*/
-static void Field_Init( menuField_t *f ) {
+static void Field_Init(menuField_t *f)
+{
int w = f->width * CHAR_WIDTH;
- f->generic.uiFlags &= ~( UI_LEFT | UI_RIGHT );
-
- if( f->generic.name ) {
+ f->generic.uiFlags &= ~(UI_LEFT | UI_RIGHT);
+
+ if (f->generic.name) {
f->generic.rect.x = f->generic.x + LCOLUMN_OFFSET;
f->generic.rect.y = f->generic.y;
- UI_StringDimensions( &f->generic.rect,
- f->generic.uiFlags | UI_RIGHT, f->generic.name );
- f->generic.rect.width += ( RCOLUMN_OFFSET - LCOLUMN_OFFSET ) + w;
+ UI_StringDimensions(&f->generic.rect,
+ f->generic.uiFlags | UI_RIGHT, f->generic.name);
+ f->generic.rect.width += (RCOLUMN_OFFSET - LCOLUMN_OFFSET) + w;
} else {
f->generic.rect.x = f->generic.x - w / 2;
f->generic.rect.y = f->generic.y;
@@ -378,30 +401,31 @@ static void Field_Init( menuField_t *f ) {
Field_Draw
=================
*/
-static void Field_Draw( menuField_t *f ) {
+static void Field_Draw(menuField_t *f)
+{
int flags = f->generic.uiFlags;
uint32_t color = uis.color.normal.u32;
- if( f->generic.flags & QMF_HASFOCUS ) {
+ if (f->generic.flags & QMF_HASFOCUS) {
flags |= UI_DRAWCURSOR;
color = uis.color.active.u32;
}
- if( f->generic.name ) {
- UI_DrawString( f->generic.x + LCOLUMN_OFFSET, f->generic.y,
- f->generic.uiFlags | UI_RIGHT | UI_ALTCOLOR, f->generic.name );
+ if (f->generic.name) {
+ UI_DrawString(f->generic.x + LCOLUMN_OFFSET, f->generic.y,
+ f->generic.uiFlags | UI_RIGHT | UI_ALTCOLOR, f->generic.name);
- R_DrawFill32( f->generic.x + RCOLUMN_OFFSET, f->generic.y - 1,
- f->field.visibleChars * CHAR_WIDTH, CHAR_HEIGHT + 2, color );
+ R_DrawFill32(f->generic.x + RCOLUMN_OFFSET, f->generic.y - 1,
+ f->field.visibleChars * CHAR_WIDTH, CHAR_HEIGHT + 2, color);
- IF_Draw( &f->field, f->generic.x + RCOLUMN_OFFSET, f->generic.y,
- flags, uis.fontHandle );
+ IF_Draw(&f->field, f->generic.x + RCOLUMN_OFFSET, f->generic.y,
+ flags, uis.fontHandle);
} else {
- R_DrawFill32( f->generic.rect.x, f->generic.rect.y - 1,
- f->generic.rect.width, CHAR_HEIGHT + 2, color );
+ R_DrawFill32(f->generic.rect.x, f->generic.rect.y - 1,
+ f->generic.rect.width, CHAR_HEIGHT + 2, color);
- IF_Draw( &f->field, f->generic.rect.x, f->generic.rect.y,
- flags, uis.fontHandle );
+ IF_Draw(&f->field, f->generic.rect.x, f->generic.rect.y,
+ flags, uis.fontHandle);
}
}
@@ -410,19 +434,20 @@ static void Field_Draw( menuField_t *f ) {
Field_Key
=================
*/
-static int Field_Key( menuField_t *f, int key ) {
+static int Field_Key(menuField_t *f, int key)
+{
qboolean ret;
- ret = IF_KeyEvent( &f->field, key );
- if( ret ) {
+ ret = IF_KeyEvent(&f->field, key);
+ if (ret) {
return QMS_SILENT;
}
- if( f->generic.flags & QMF_NUMBERSONLY ) {
- if( Q_isdigit( key ) ) {
+ if (f->generic.flags & QMF_NUMBERSONLY) {
+ if (Q_isdigit(key)) {
return QMS_SILENT;
}
} else {
- if( key >= 32 && key < 127 ) {
+ if (key >= 32 && key < 127) {
return QMS_SILENT;
}
}
@@ -434,18 +459,19 @@ static int Field_Key( menuField_t *f, int key ) {
Field_Char
=================
*/
-static int Field_Char( menuField_t *f, int key ) {
+static int Field_Char(menuField_t *f, int key)
+{
int ret;
- if( f->generic.flags & QMF_NUMBERSONLY ) {
- if( key < '0' || key > '9' ) {
+ if (f->generic.flags & QMF_NUMBERSONLY) {
+ if (key < '0' || key > '9') {
return QMS_BEEP;
}
}
- ret = IF_CharEvent( &f->field, key );
- if( f->generic.change ) {
- f->generic.change( &f->generic );
+ ret = IF_CharEvent(&f->field, key);
+ if (f->generic.change) {
+ f->generic.change(&f->generic);
}
return ret ? QMS_SILENT : QMS_NOTHANDLED;
@@ -459,25 +485,28 @@ SPIN CONTROL
===================================================================
*/
-static void SpinControl_Push( menuSpinControl_t *s ) {
+static void SpinControl_Push(menuSpinControl_t *s)
+{
int val = s->cvar->integer;
- clamp( val, 0, s->numItems - 1 );
+ clamp(val, 0, s->numItems - 1);
s->curvalue = val;
}
-static void SpinControl_Pop( menuSpinControl_t *s ) {
- Cvar_SetInteger( s->cvar, s->curvalue, FROM_MENU );
+static void SpinControl_Pop(menuSpinControl_t *s)
+{
+ Cvar_SetInteger(s->cvar, s->curvalue, FROM_MENU);
}
-static void SpinControl_Free( menuSpinControl_t *s ) {
+static void SpinControl_Free(menuSpinControl_t *s)
+{
int i;
- Z_Free( s->generic.name );
- for( i = 0; i < s->numItems; i++ ) {
- Z_Free( s->itemnames[i] );
+ Z_Free(s->generic.name);
+ for (i = 0; i < s->numItems; i++) {
+ Z_Free(s->itemnames[i]);
}
- Z_Free( s->itemnames );
- Z_Free( s );
+ Z_Free(s->itemnames);
+ Z_Free(s);
}
@@ -486,33 +515,34 @@ static void SpinControl_Free( menuSpinControl_t *s ) {
SpinControl_Init
=================
*/
-void SpinControl_Init( menuSpinControl_t *s ) {
+void SpinControl_Init(menuSpinControl_t *s)
+{
char **n;
int maxLength, length;
- s->generic.uiFlags &= ~( UI_LEFT | UI_RIGHT );
+ s->generic.uiFlags &= ~(UI_LEFT | UI_RIGHT);
s->generic.rect.x = s->generic.x + LCOLUMN_OFFSET;
s->generic.rect.y = s->generic.y;
- UI_StringDimensions( &s->generic.rect,
- s->generic.uiFlags | UI_RIGHT, s->generic.name );
+ UI_StringDimensions(&s->generic.rect,
+ s->generic.uiFlags | UI_RIGHT, s->generic.name);
maxLength = 0;
s->numItems = 0;
n = s->itemnames;
- while( *n ) {
- length = strlen( *n );
-
- if( maxLength < length ) {
+ while (*n) {
+ length = strlen(*n);
+
+ if (maxLength < length) {
maxLength = length;
}
s->numItems++;
n++;
}
- s->generic.rect.width += ( RCOLUMN_OFFSET - LCOLUMN_OFFSET ) +
- maxLength * CHAR_WIDTH;
+ s->generic.rect.width += (RCOLUMN_OFFSET - LCOLUMN_OFFSET) +
+ maxLength * CHAR_WIDTH;
}
/*
@@ -520,14 +550,15 @@ void SpinControl_Init( menuSpinControl_t *s ) {
SpinControl_DoEnter
=================
*/
-static int SpinControl_DoEnter( menuSpinControl_t *s ) {
+static int SpinControl_DoEnter(menuSpinControl_t *s)
+{
s->curvalue++;
- if( s->curvalue >= s->numItems )
+ if (s->curvalue >= s->numItems)
s->curvalue = 0;
- if( s->generic.change ) {
- s->generic.change( &s->generic );
+ if (s->generic.change) {
+ s->generic.change(&s->generic);
}
return QMS_MOVE;
@@ -538,17 +569,18 @@ static int SpinControl_DoEnter( menuSpinControl_t *s ) {
SpinControl_DoSlide
=================
*/
-static int SpinControl_DoSlide( menuSpinControl_t *s, int dir ) {
+static int SpinControl_DoSlide(menuSpinControl_t *s, int dir)
+{
s->curvalue += dir;
- if( s->curvalue < 0 ) {
+ if (s->curvalue < 0) {
s->curvalue = s->numItems - 1;
- } else if( s->curvalue >= s->numItems ) {
+ } else if (s->curvalue >= s->numItems) {
s->curvalue = 0;
}
- if( s->generic.change ) {
- s->generic.change( &s->generic );
+ if (s->generic.change) {
+ s->generic.change(&s->generic);
}
return QMS_MOVE;
@@ -559,19 +591,20 @@ static int SpinControl_DoSlide( menuSpinControl_t *s, int dir ) {
SpinControl_Draw
=================
*/
-static void SpinControl_Draw( menuSpinControl_t *s ) {
- UI_DrawString( s->generic.x + LCOLUMN_OFFSET, s->generic.y,
- s->generic.uiFlags | UI_RIGHT | UI_ALTCOLOR, s->generic.name );
+static void SpinControl_Draw(menuSpinControl_t *s)
+{
+ UI_DrawString(s->generic.x + LCOLUMN_OFFSET, s->generic.y,
+ s->generic.uiFlags | UI_RIGHT | UI_ALTCOLOR, s->generic.name);
- if( s->generic.flags & QMF_HASFOCUS ) {
- if( ( uis.realtime >> 8 ) & 1 ) {
- UI_DrawChar( s->generic.x + RCOLUMN_OFFSET / 2, s->generic.y,
- s->generic.uiFlags | UI_RIGHT, 13 );
+ if (s->generic.flags & QMF_HASFOCUS) {
+ if ((uis.realtime >> 8) & 1) {
+ UI_DrawChar(s->generic.x + RCOLUMN_OFFSET / 2, s->generic.y,
+ s->generic.uiFlags | UI_RIGHT, 13);
}
}
- UI_DrawString( s->generic.x + RCOLUMN_OFFSET, s->generic.y,
- s->generic.uiFlags, s->itemnames[s->curvalue] );
+ UI_DrawString(s->generic.x + RCOLUMN_OFFSET, s->generic.y,
+ s->generic.uiFlags, s->itemnames[s->curvalue]);
}
/*
@@ -582,28 +615,31 @@ BITFIELD CONTROL
===================================================================
*/
-static void BitField_Push( menuSpinControl_t *s ) {
- if( s->cvar->integer & s->mask ) {
+static void BitField_Push(menuSpinControl_t *s)
+{
+ if (s->cvar->integer & s->mask) {
s->curvalue = 1 ^ s->negate;
} else {
s->curvalue = 0 ^ s->negate;
}
}
-static void BitField_Pop( menuSpinControl_t *s ) {
+static void BitField_Pop(menuSpinControl_t *s)
+{
int val = s->cvar->integer;
- if( s->curvalue ^ s->negate ) {
+ if (s->curvalue ^ s->negate) {
val |= s->mask;
} else {
val &= ~s->mask;
}
- Cvar_SetInteger( s->cvar, val, FROM_MENU );
+ Cvar_SetInteger(s->cvar, val, FROM_MENU);
}
-static void BitField_Free( menuSpinControl_t *s ) {
- Z_Free( s->generic.name );
- Z_Free( s );
+static void BitField_Free(menuSpinControl_t *s)
+{
+ Z_Free(s->generic.name);
+ Z_Free(s);
}
/*
@@ -614,32 +650,35 @@ PAIRS CONTROL
===================================================================
*/
-static void Pairs_Push( menuSpinControl_t *s ) {
+static void Pairs_Push(menuSpinControl_t *s)
+{
int i;
- for( i = 0; i < s->numItems; i++ ) {
- if( !Q_stricmp( s->itemvalues[i], s->cvar->string ) ) {
+ for (i = 0; i < s->numItems; i++) {
+ if (!Q_stricmp(s->itemvalues[i], s->cvar->string)) {
s->curvalue = i;
break;
}
}
}
-static void Pairs_Pop( menuSpinControl_t *s ) {
- Cvar_SetByVar( s->cvar, s->itemvalues[s->curvalue], FROM_MENU );
+static void Pairs_Pop(menuSpinControl_t *s)
+{
+ Cvar_SetByVar(s->cvar, s->itemvalues[s->curvalue], FROM_MENU);
}
-static void Pairs_Free( menuSpinControl_t *s ) {
+static void Pairs_Free(menuSpinControl_t *s)
+{
int i;
- Z_Free( s->generic.name );
- for( i = 0; i < s->numItems; i++ ) {
- Z_Free( s->itemnames[i] );
- Z_Free( s->itemvalues[i] );
+ Z_Free(s->generic.name);
+ for (i = 0; i < s->numItems; i++) {
+ Z_Free(s->itemnames[i]);
+ Z_Free(s->itemvalues[i]);
}
- Z_Free( s->itemnames );
- Z_Free( s->itemvalues );
- Z_Free( s );
+ Z_Free(s->itemnames);
+ Z_Free(s->itemvalues);
+ Z_Free(s);
}
/*
@@ -650,19 +689,21 @@ STRINGS CONTROL
===================================================================
*/
-static void Strings_Push( menuSpinControl_t *s ) {
+static void Strings_Push(menuSpinControl_t *s)
+{
int i;
- for( i = 0; i < s->numItems; i++ ) {
- if( !Q_stricmp( s->itemnames[i], s->cvar->string ) ) {
+ for (i = 0; i < s->numItems; i++) {
+ if (!Q_stricmp(s->itemnames[i], s->cvar->string)) {
s->curvalue = i;
break;
}
}
}
-static void Strings_Pop( menuSpinControl_t *s ) {
- Cvar_SetByVar( s->cvar, s->itemnames[s->curvalue], FROM_MENU );
+static void Strings_Pop(menuSpinControl_t *s)
+{
+ Cvar_SetByVar(s->cvar, s->itemnames[s->curvalue], FROM_MENU);
}
/*
@@ -673,8 +714,9 @@ TOGGLE CONTROL
===================================================================
*/
-static void Toggle_Push( menuSpinControl_t *s ) {
- s->curvalue = ( s->cvar->integer ? 1 : 0 ) ^ s->negate;
+static void Toggle_Push(menuSpinControl_t *s)
+{
+ s->curvalue = (s->cvar->integer ? 1 : 0) ^ s->negate;
}
/*
@@ -690,20 +732,22 @@ LIST CONTROL
MenuList_ValidatePrestep
=================
*/
-static void MenuList_ValidatePrestep( menuList_t *l ) {
- if( l->prestep > l->numItems - l->maxItems ) {
+static void MenuList_ValidatePrestep(menuList_t *l)
+{
+ if (l->prestep > l->numItems - l->maxItems) {
l->prestep = l->numItems - l->maxItems;
}
- if( l->prestep < 0 ) {
+ if (l->prestep < 0) {
l->prestep = 0;
}
}
-static void MenuList_AdjustPrestep( menuList_t *l ) {
- if( l->numItems > l->maxItems ) {
- if( l->prestep > l->curvalue ) {
+static void MenuList_AdjustPrestep(menuList_t *l)
+{
+ if (l->numItems > l->maxItems) {
+ if (l->prestep > l->curvalue) {
l->prestep = l->curvalue;
- } else if( l->prestep < l->curvalue - l->maxItems + 1 ) {
+ } else if (l->prestep < l->curvalue - l->maxItems + 1) {
l->prestep = l->curvalue - l->maxItems + 1;
}
} else {
@@ -716,26 +760,27 @@ static void MenuList_AdjustPrestep( menuList_t *l ) {
MenuList_Init
=================
*/
-void MenuList_Init( menuList_t *l ) {
+void MenuList_Init(menuList_t *l)
+{
int height;
int i;
height = l->generic.height;
- if( !( l->mlFlags & MLF_HIDE_HEADER ) ) {
+ if (!(l->mlFlags & MLF_HIDE_HEADER)) {
height -= MLIST_SPACING;
}
l->maxItems = height / MLIST_SPACING;
- clamp( l->curvalue, 0, l->numItems - 1 );
+ clamp(l->curvalue, 0, l->numItems - 1);
- MenuList_ValidatePrestep( l );
+ MenuList_ValidatePrestep(l);
l->generic.rect.x = l->generic.x;
l->generic.rect.y = l->generic.y;
l->generic.rect.width = 0;
- for( i = 0; i < l->numcolumns; i++ ) {
+ for (i = 0; i < l->numcolumns; i++) {
l->generic.rect.width += l->columns[i].width;
}
@@ -745,8 +790,8 @@ void MenuList_Init( menuList_t *l ) {
l->generic.rect.height = l->generic.height;
- if( l->sortdir && l->sort ) {
- l->sort( l, l->sortcol );
+ if (l->sortdir && l->sort) {
+ l->sort(l, l->sortcol);
}
}
@@ -755,28 +800,30 @@ void MenuList_Init( menuList_t *l ) {
MenuList_SetValue
=================
*/
-void MenuList_SetValue( menuList_t *l, int value ) {
- clamp( value, 0, l->numItems - 1 );
+void MenuList_SetValue(menuList_t *l, int value)
+{
+ clamp(value, 0, l->numItems - 1);
- if( value != l->curvalue ) {
+ if (value != l->curvalue) {
l->curvalue = value;
- if( l->generic.change ) {
- l->generic.change( &l->generic );
+ if (l->generic.change) {
+ l->generic.change(&l->generic);
}
}
- MenuList_AdjustPrestep( l );
+ MenuList_AdjustPrestep(l);
}
-static int MenuList_SetColumn( menuList_t *l, int value ) {
- if( l->sortcol == value ) {
+static int MenuList_SetColumn(menuList_t *l, int value)
+{
+ if (l->sortcol == value) {
l->sortdir = -l->sortdir;
} else {
l->sortcol = value;
l->sortdir = 1;
}
- if( l->sort ) {
- l->sort( l, l->sortcol );
+ if (l->sort) {
+ l->sort(l, l->sortcol);
}
return QMS_SILENT;
}
@@ -787,11 +834,12 @@ static int MenuList_SetColumn( menuList_t *l, int value ) {
MenuList_Click
=================
*/
-static int MenuList_Click( menuList_t *l ) {
+static int MenuList_Click(menuList_t *l)
+{
int i, j;
vrect_t rect;
- if( !l->items ) {
+ if (!l->items) {
return QMS_SILENT;
}
@@ -801,12 +849,12 @@ static int MenuList_Click( menuList_t *l ) {
rect.height = MLIST_SPACING;
// click on header
- if( !( l->mlFlags & MLF_HIDE_HEADER ) ) {
- if( l->sortdir && UI_CursorInRect( &rect ) ) {
- for( j = 0; j < l->numcolumns; j++ ) {
+ if (!(l->mlFlags & MLF_HIDE_HEADER)) {
+ if (l->sortdir && UI_CursorInRect(&rect)) {
+ for (j = 0; j < l->numcolumns; j++) {
rect.width = l->columns[j].width;
- if( UI_CursorInRect( &rect ) ) {
- return MenuList_SetColumn( l, j );
+ if (UI_CursorInRect(&rect)) {
+ return MenuList_SetColumn(l, j);
}
rect.x += rect.width;
}
@@ -816,21 +864,20 @@ static int MenuList_Click( menuList_t *l ) {
}
// click on item
- j = min( l->numItems, l->prestep + l->maxItems );
- for( i = l->prestep; i < j; i++ ) {
- if( UI_CursorInRect( &rect ) ) {
- if( l->curvalue == i && uis.realtime -
- l->clickTime < DOUBLE_CLICK_DELAY )
- {
- if( l->generic.activate ) {
- return l->generic.activate( &l->generic );
+ j = min(l->numItems, l->prestep + l->maxItems);
+ for (i = l->prestep; i < j; i++) {
+ if (UI_CursorInRect(&rect)) {
+ if (l->curvalue == i && uis.realtime -
+ l->clickTime < DOUBLE_CLICK_DELAY) {
+ if (l->generic.activate) {
+ return l->generic.activate(&l->generic);
}
return QMS_SILENT;
}
l->clickTime = uis.realtime;
l->curvalue = i;
- if( l->generic.change ) {
- return l->generic.change( &l->generic );
+ if (l->generic.change) {
+ return l->generic.change(&l->generic);
}
return QMS_SILENT;
}
@@ -845,29 +892,30 @@ static int MenuList_Click( menuList_t *l ) {
MenuList_Key
=================
*/
-static int MenuList_Key( menuList_t *l, int key ) {
+static int MenuList_Key(menuList_t *l, int key)
+{
//int i;
- if( !l->items ) {
+ if (!l->items) {
return QMS_NOTHANDLED;
}
- if( Key_IsDown( K_ALT ) && Q_isdigit( key ) ) {
+ if (Key_IsDown(K_ALT) && Q_isdigit(key)) {
int col = key == '0' ? 9 : key - '0' - 1;
- if( l->sortdir && col < l->numcolumns ) {
- return MenuList_SetColumn( l, col );
+ if (l->sortdir && col < l->numcolumns) {
+ return MenuList_SetColumn(l, col);
}
return QMS_NOTHANDLED;
}
#if 0
- if( key > 32 && key < 127 ) {
- if( uis.realtime > l->scratchTime + 1300 ) {
+ if (key > 32 && key < 127) {
+ if (uis.realtime > l->scratchTime + 1300) {
l->scratchCount = 0;
l->scratchTime = uis.realtime;
}
- if( l->scratchCount >= sizeof( l->scratch ) - 1 ) {
+ if (l->scratchCount >= sizeof(l->scratch) - 1) {
return QMS_NOTHANDLED;
}
@@ -876,15 +924,14 @@ static int MenuList_Key( menuList_t *l, int key ) {
//l->scratchTime = uis.realtime;
- if( !Q_stricmpn( UI_GetColumn( ( char * )l->items[l->curvalue] + l->extrasize, l->sortcol ),
- l->scratch, l->scratchCount ) )
- {
+ if (!Q_stricmpn(UI_GetColumn((char *)l->items[l->curvalue] + l->extrasize, l->sortcol),
+ l->scratch, l->scratchCount)) {
return QMS_NOTHANDLED;
}
- for( i = 0; i < l->numItems; i++ ) {
- if( !Q_stricmpn( UI_GetColumn( ( char * )l->items[i] + l->extrasize, l->sortcol ), l->scratch, l->scratchCount ) ) {
- MenuList_SetValue( l, i );
+ for (i = 0; i < l->numItems; i++) {
+ if (!Q_stricmpn(UI_GetColumn((char *)l->items[i] + l->extrasize, l->sortcol), l->scratch, l->scratchCount)) {
+ MenuList_SetValue(l, i);
return QMS_SILENT;
}
i++;
@@ -896,34 +943,34 @@ static int MenuList_Key( menuList_t *l, int key ) {
l->scratchCount = 0;
- switch( key ) {
+ switch (key) {
case K_LEFTARROW:
case 'h':
- if( l->sortdir ) {
- if( l->sortcol > 0 ) {
- return MenuList_SetColumn( l, l->sortcol - 1 );
+ if (l->sortdir) {
+ if (l->sortcol > 0) {
+ return MenuList_SetColumn(l, l->sortcol - 1);
}
- return MenuList_SetColumn( l, l->numcolumns - 1 );
+ return MenuList_SetColumn(l, l->numcolumns - 1);
}
break;
case K_RIGHTARROW:
case 'l':
- if( l->sortdir ) {
- if( l->sortcol < l->numcolumns - 1 ) {
- return MenuList_SetColumn( l, l->sortcol + 1 );
+ if (l->sortdir) {
+ if (l->sortcol < l->numcolumns - 1) {
+ return MenuList_SetColumn(l, l->sortcol + 1);
}
- return MenuList_SetColumn( l, 0 );
+ return MenuList_SetColumn(l, 0);
}
break;
case K_UPARROW:
case K_KP_UPARROW:
case 'k':
- if( l->curvalue > 0 ) {
+ if (l->curvalue > 0) {
l->curvalue--;
- if( l->generic.change ) {
- l->generic.change( &l->generic );
+ if (l->generic.change) {
+ l->generic.change(&l->generic);
}
- MenuList_AdjustPrestep( l );
+ MenuList_AdjustPrestep(l);
return QMS_MOVE;
}
return QMS_BEEP;
@@ -931,12 +978,12 @@ static int MenuList_Key( menuList_t *l, int key ) {
case K_DOWNARROW:
case K_KP_DOWNARROW:
case 'j':
- if( l->curvalue < l->numItems - 1 ) {
+ if (l->curvalue < l->numItems - 1) {
l->curvalue++;
- if( l->generic.change ) {
- l->generic.change( &l->generic );
+ if (l->generic.change) {
+ l->generic.change(&l->generic);
}
- MenuList_AdjustPrestep( l );
+ MenuList_AdjustPrestep(l);
return QMS_MOVE;
}
return QMS_BEEP;
@@ -945,56 +992,56 @@ static int MenuList_Key( menuList_t *l, int key ) {
case K_KP_HOME:
l->prestep = 0;
l->curvalue = 0;
- if( l->generic.change ) {
- l->generic.change( &l->generic );
+ if (l->generic.change) {
+ l->generic.change(&l->generic);
}
return QMS_MOVE;
case K_END:
case K_KP_END:
- if( l->numItems > l->maxItems ) {
+ if (l->numItems > l->maxItems) {
l->prestep = l->numItems - l->maxItems;
}
l->curvalue = l->numItems - 1;
- if( l->generic.change ) {
- l->generic.change( &l->generic );
+ if (l->generic.change) {
+ l->generic.change(&l->generic);
}
return QMS_MOVE;
case K_MWHEELUP:
- if( Key_IsDown( K_CTRL ) ) {
+ if (Key_IsDown(K_CTRL)) {
l->prestep -= 4;
} else {
l->prestep -= 2;
}
- MenuList_ValidatePrestep( l );
+ MenuList_ValidatePrestep(l);
return QMS_SILENT;
case K_MWHEELDOWN:
- if( Key_IsDown( K_CTRL ) ) {
+ if (Key_IsDown(K_CTRL)) {
l->prestep += 4;
} else {
l->prestep += 2;
}
- MenuList_ValidatePrestep( l );
+ MenuList_ValidatePrestep(l);
return QMS_SILENT;
case K_PGUP:
case K_KP_PGUP:
l->prestep -= l->maxItems;
- MenuList_ValidatePrestep( l );
+ MenuList_ValidatePrestep(l);
return QMS_SILENT;
case K_PGDN:
case K_KP_PGDN:
l->prestep += l->maxItems;
- MenuList_ValidatePrestep( l );
+ MenuList_ValidatePrestep(l);
return QMS_SILENT;
case K_MOUSE1:
case K_MOUSE2:
//case K_MOUSE3:
- return MenuList_Click( l );
+ return MenuList_Click(l);
}
return QMS_NOTHANDLED;
@@ -1005,9 +1052,9 @@ static int MenuList_Key( menuList_t *l, int key ) {
MenuList_DrawString
=================
*/
-static void MenuList_DrawString( int x, int y, int flags,
- menuListColumn_t *column,
- const char *string )
+static void MenuList_DrawString(int x, int y, int flags,
+ menuListColumn_t *column,
+ const char *string)
{
clipRect_t rc;
@@ -1016,20 +1063,20 @@ static void MenuList_DrawString( int x, int y, int flags,
rc.top = 0;
rc.bottom = 0;
- if( ( column->uiFlags & UI_CENTER ) == UI_CENTER ) {
+ if ((column->uiFlags & UI_CENTER) == UI_CENTER) {
x += column->width / 2;
- } else if( column->uiFlags & UI_RIGHT ) {
+ } else if (column->uiFlags & UI_RIGHT) {
x += column->width - MLIST_PRESTEP;
} else {
x += MLIST_PRESTEP;
}
- R_SetClipRect( DRAW_CLIP_RIGHT|DRAW_CLIP_LEFT, &rc );
- UI_DrawString( x, y + 1, column->uiFlags | flags, string );
+ R_SetClipRect(DRAW_CLIP_RIGHT | DRAW_CLIP_LEFT, &rc);
+ UI_DrawString(x, y + 1, column->uiFlags | flags, string);
#if USE_REF == REF_SOFT
- R_SetClipRect( DRAW_CLIP_MASK, &uis.clipRect );
+ R_SetClipRect(DRAW_CLIP_MASK, &uis.clipRect);
#else
- R_SetClipRect( DRAW_CLIP_DISABLED, NULL );
+ R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
#endif
}
@@ -1038,7 +1085,8 @@ static void MenuList_DrawString( int x, int y, int flags,
MenuList_Draw
=================
*/
-static void MenuList_Draw( menuList_t *l ) {
+static void MenuList_Draw(menuList_t *l)
+{
char *s;
int x, y, xx, yy;
int i, j, k;
@@ -1052,24 +1100,24 @@ static void MenuList_Draw( menuList_t *l ) {
height = l->generic.rect.height;
// draw header
- if( !( l->mlFlags & MLF_HIDE_HEADER ) ) {
+ if (!(l->mlFlags & MLF_HIDE_HEADER)) {
xx = x;
- for( j = 0; j < l->numcolumns; j++ ) {
+ for (j = 0; j < l->numcolumns; j++) {
int flags = UI_ALTCOLOR;
uint32_t color = uis.color.normal.u32;
- if( l->sortcol == j && l->sortdir ) {
+ if (l->sortcol == j && l->sortdir) {
flags = 0;
- if( l->generic.flags & QMF_HASFOCUS ) {
+ if (l->generic.flags & QMF_HASFOCUS) {
color = uis.color.active.u32;
}
}
- R_DrawFill32( xx, y, l->columns[j].width - 1,
- MLIST_SPACING - 1, color );
+ R_DrawFill32(xx, y, l->columns[j].width - 1,
+ MLIST_SPACING - 1, color);
- if( l->columns[j].name ) {
- MenuList_DrawString( xx, y, flags,
- &l->columns[j], l->columns[j].name );
+ if (l->columns[j].name) {
+ MenuList_DrawString(xx, y, flags,
+ &l->columns[j], l->columns[j].name);
}
xx += l->columns[j].width;
}
@@ -1077,100 +1125,100 @@ static void MenuList_Draw( menuList_t *l ) {
height -= MLIST_SPACING;
}
- if( !( l->mlFlags & MLF_HIDE_SCROLLBAR ) &&
- ( !( l->mlFlags & MLF_HIDE_SCROLLBAR_EMPTY ) || l->numItems > l->maxItems ) )
- {
+ if (!(l->mlFlags & MLF_HIDE_SCROLLBAR) &&
+ (!(l->mlFlags & MLF_HIDE_SCROLLBAR_EMPTY) || l->numItems > l->maxItems)) {
barHeight = height - MLIST_SPACING * 2;
yy = y + MLIST_SPACING;
// draw scrollbar background
- if( !( l->mlFlags & MLF_HIDE_BACKGROUND ) ) {
- R_DrawFill32( x + width, yy, MLIST_SCROLLBAR_WIDTH - 1,
- barHeight, uis.color.normal.u32 );
+ if (!(l->mlFlags & MLF_HIDE_BACKGROUND)) {
+ R_DrawFill32(x + width, yy, MLIST_SCROLLBAR_WIDTH - 1,
+ barHeight, uis.color.normal.u32);
}
- if( l->numItems > l->maxItems ) {
- pageFrac = ( float )l->maxItems / l->numItems;
- prestepFrac = ( float )l->prestep / l->numItems;
+ if (l->numItems > l->maxItems) {
+ pageFrac = (float)l->maxItems / l->numItems;
+ prestepFrac = (float)l->prestep / l->numItems;
} else {
pageFrac = 1;
prestepFrac = 0;
}
// draw scrollbar thumb
- R_DrawFill32( x + width,
- yy + Q_rint( barHeight * prestepFrac ),
- MLIST_SCROLLBAR_WIDTH - 1,
- Q_rint( barHeight * pageFrac ),
- uis.color.selection.u32 );
+ R_DrawFill32(x + width,
+ yy + Q_rint(barHeight * prestepFrac),
+ MLIST_SCROLLBAR_WIDTH - 1,
+ Q_rint(barHeight * pageFrac),
+ uis.color.selection.u32);
}
xx = x;
- for( j = 0; j < l->numcolumns; j++ ) {
+ for (j = 0; j < l->numcolumns; j++) {
uint32_t color = uis.color.normal.u32;
- if( l->sortcol == j && l->sortdir ) {
- if( l->generic.flags & QMF_HASFOCUS ) {
+ if (l->sortcol == j && l->sortdir) {
+ if (l->generic.flags & QMF_HASFOCUS) {
color = uis.color.active.u32;
}
}
- R_DrawFill32( xx, y, l->columns[j].width - 1,
- height, color );
+ R_DrawFill32(xx, y, l->columns[j].width - 1,
+ height, color);
xx += l->columns[j].width;
}
yy = y;
- k = min( l->numItems, l->prestep + l->maxItems );
- for( i = l->prestep; i < k; i++ ) {
+ k = min(l->numItems, l->prestep + l->maxItems);
+ for (i = l->prestep; i < k; i++) {
// draw selection
- if( !( l->generic.flags & QMF_DISABLED ) && i == l->curvalue ) {
+ if (!(l->generic.flags & QMF_DISABLED) && i == l->curvalue) {
xx = x;
- for( j = 0; j < l->numcolumns; j++ ) {
- R_DrawFill32( xx, yy, l->columns[j].width - 1,
- MLIST_SPACING, uis.color.selection.u32 );
+ for (j = 0; j < l->numcolumns; j++) {
+ R_DrawFill32(xx, yy, l->columns[j].width - 1,
+ MLIST_SPACING, uis.color.selection.u32);
xx += l->columns[j].width;
}
}
// draw contents
- s = ( char * )l->items[i] + l->extrasize;
+ s = (char *)l->items[i] + l->extrasize;
xx = x;
- for( j = 0; j < l->numcolumns; j++ ) {
- if( !*s ) {
+ for (j = 0; j < l->numcolumns; j++) {
+ if (!*s) {
break;
}
-
- MenuList_DrawString( xx, yy, 0, &l->columns[j], s );
-
+
+ MenuList_DrawString(xx, yy, 0, &l->columns[j], s);
+
xx += l->columns[j].width;
- s += strlen( s ) + 1;
+ s += strlen(s) + 1;
}
yy += MLIST_SPACING;
}
}
-void MenuList_Sort( menuList_t *l, int offset, int (*cmpfunc)( const void *, const void * ) ) {
+void MenuList_Sort(menuList_t *l, int offset, int (*cmpfunc)(const void *, const void *))
+{
void *n;
int i;
- if( !l->items ) {
+ if (!l->items) {
return;
}
n = l->items[l->curvalue];
- qsort( l->items + offset, l->numItems - offset, sizeof( char * ), cmpfunc );
+ qsort(l->items + offset, l->numItems - offset, sizeof(char *), cmpfunc);
- for( i = 0; i < l->numItems; i++ ) {
- if( l->items[i] == n ) {
+ for (i = 0; i < l->numItems; i++) {
+ if (l->items[i] == n) {
l->curvalue = i;
break;
}
}
- MenuList_AdjustPrestep( l );
+ MenuList_AdjustPrestep(l);
}
/*
@@ -1181,33 +1229,38 @@ SLIDER CONTROL
===================================================================
*/
-static void Slider_Push( menuSlider_t *s ) {
+static void Slider_Push(menuSlider_t *s)
+{
s->curvalue = s->cvar->value;
- cclamp( s->curvalue, s->minvalue, s->maxvalue );
+ cclamp(s->curvalue, s->minvalue, s->maxvalue);
}
-static void Slider_Pop( menuSlider_t *s ) {
- Cvar_SetValue( s->cvar, s->curvalue, FROM_MENU );
+static void Slider_Pop(menuSlider_t *s)
+{
+ Cvar_SetValue(s->cvar, s->curvalue, FROM_MENU);
}
-static void Slider_Free( menuSlider_t *s ) {
- Z_Free( s->generic.name );
- Z_Free( s );
+static void Slider_Free(menuSlider_t *s)
+{
+ Z_Free(s->generic.name);
+ Z_Free(s);
}
-static void Slider_Init( menuSlider_t *s ) {
- int len = strlen( s->generic.name ) * CHAR_WIDTH;
+static void Slider_Init(menuSlider_t *s)
+{
+ int len = strlen(s->generic.name) * CHAR_WIDTH;
s->generic.rect.x = s->generic.x + LCOLUMN_OFFSET - len;
s->generic.rect.y = s->generic.y;
- s->generic.rect.width = ( RCOLUMN_OFFSET - LCOLUMN_OFFSET ) +
- len + ( SLIDER_RANGE + 2 ) * CHAR_WIDTH;
+ s->generic.rect.width = (RCOLUMN_OFFSET - LCOLUMN_OFFSET) +
+ len + (SLIDER_RANGE + 2) * CHAR_WIDTH;
s->generic.rect.height = CHAR_HEIGHT;
}
-static int Slider_Key( menuSlider_t *s, int key ) {
- switch( key ) {
+static int Slider_Key(menuSlider_t *s, int key)
+{
+ switch (key) {
case K_END:
s->curvalue = s->maxvalue;
return QMS_MOVE;
@@ -1225,14 +1278,15 @@ static int Slider_Key( menuSlider_t *s, int key ) {
Slider_DoSlide
=================
*/
-static int Slider_DoSlide( menuSlider_t *s, int dir ) {
+static int Slider_DoSlide(menuSlider_t *s, int dir)
+{
s->curvalue += dir * s->step;
- cclamp( s->curvalue, s->minvalue, s->maxvalue );
+ cclamp(s->curvalue, s->minvalue, s->maxvalue);
- if( s->generic.change ) {
- menuSound_t sound = s->generic.change( &s->generic );
- if( sound != QMS_NOTHANDLED ) {
+ if (s->generic.change) {
+ menuSound_t sound = s->generic.change(&s->generic);
+ if (sound != QMS_NOTHANDLED) {
return sound;
}
}
@@ -1245,32 +1299,33 @@ static int Slider_DoSlide( menuSlider_t *s, int dir ) {
Slider_Draw
=================
*/
-static void Slider_Draw( menuSlider_t *s ) {
+static void Slider_Draw(menuSlider_t *s)
+{
int i, flags;
float pos;
- flags = s->generic.uiFlags & ~( UI_LEFT | UI_RIGHT );
+ flags = s->generic.uiFlags & ~(UI_LEFT | UI_RIGHT);
- if( s->generic.flags & QMF_HASFOCUS ) {
- if( ( uis.realtime >> 8 ) & 1 ) {
- UI_DrawChar( s->generic.x + RCOLUMN_OFFSET / 2, s->generic.y, s->generic.uiFlags | UI_RIGHT, 13 );
+ if (s->generic.flags & QMF_HASFOCUS) {
+ if ((uis.realtime >> 8) & 1) {
+ UI_DrawChar(s->generic.x + RCOLUMN_OFFSET / 2, s->generic.y, s->generic.uiFlags | UI_RIGHT, 13);
}
}
- UI_DrawString( s->generic.x + LCOLUMN_OFFSET, s->generic.y,
- flags | UI_RIGHT | UI_ALTCOLOR, s->generic.name );
+ UI_DrawString(s->generic.x + LCOLUMN_OFFSET, s->generic.y,
+ flags | UI_RIGHT | UI_ALTCOLOR, s->generic.name);
- UI_DrawChar( s->generic.x + RCOLUMN_OFFSET, s->generic.y, flags | UI_LEFT, 128 );
+ UI_DrawChar(s->generic.x + RCOLUMN_OFFSET, s->generic.y, flags | UI_LEFT, 128);
- for( i = 0 ; i < SLIDER_RANGE ; i++ )
- UI_DrawChar( RCOLUMN_OFFSET + s->generic.x + i * CHAR_WIDTH + CHAR_WIDTH, s->generic.y, flags | UI_LEFT, 129 );
+ for (i = 0; i < SLIDER_RANGE; i++)
+ UI_DrawChar(RCOLUMN_OFFSET + s->generic.x + i * CHAR_WIDTH + CHAR_WIDTH, s->generic.y, flags | UI_LEFT, 129);
- UI_DrawChar( RCOLUMN_OFFSET + s->generic.x + i * CHAR_WIDTH + CHAR_WIDTH, s->generic.y, flags | UI_LEFT, 130 );
+ UI_DrawChar(RCOLUMN_OFFSET + s->generic.x + i * CHAR_WIDTH + CHAR_WIDTH, s->generic.y, flags | UI_LEFT, 130);
- pos = ( s->curvalue - s->minvalue ) / ( s->maxvalue - s->minvalue );
- clamp( pos, 0, 1 );
+ pos = (s->curvalue - s->minvalue) / (s->maxvalue - s->minvalue);
+ clamp(pos, 0, 1);
- UI_DrawChar( CHAR_WIDTH + RCOLUMN_OFFSET + s->generic.x + ( SLIDER_RANGE - 1 ) * CHAR_WIDTH * pos, s->generic.y, flags | UI_LEFT, 131 );
+ UI_DrawChar(CHAR_WIDTH + RCOLUMN_OFFSET + s->generic.x + (SLIDER_RANGE - 1) * CHAR_WIDTH * pos, s->generic.y, flags | UI_LEFT, 131);
}
/*
@@ -1286,7 +1341,8 @@ SEPARATOR CONTROL
Separator_Init
=================
*/
-static void Separator_Init( menuSeparator_t *s ) {
+static void Separator_Init(menuSeparator_t *s)
+{
s->generic.rect.x = s->generic.rect.y = 999999;
s->generic.rect.width = s->generic.rect.height = -999999;
}
@@ -1296,9 +1352,10 @@ static void Separator_Init( menuSeparator_t *s ) {
Separator_Draw
=================
*/
-static void Separator_Draw( menuSeparator_t *s ) {
- if( s->generic.name )
- UI_DrawString( s->generic.x, s->generic.y, UI_RIGHT, s->generic.name );
+static void Separator_Draw(menuSeparator_t *s)
+{
+ if (s->generic.name)
+ UI_DrawString(s->generic.x, s->generic.y, UI_RIGHT, s->generic.name);
}
/*
@@ -1314,10 +1371,11 @@ MISC
Common_DoEnter
=================
*/
-static int Common_DoEnter( menuCommon_t *item ) {
- if( item->activate ) {
- menuSound_t sound = item->activate( item );
- if( sound != QMS_NOTHANDLED ) {
+static int Common_DoEnter(menuCommon_t *item)
+{
+ if (item->activate) {
+ menuSound_t sound = item->activate(item);
+ if (sound != QMS_NOTHANDLED) {
return sound;
}
}
@@ -1331,35 +1389,39 @@ static int Common_DoEnter( menuCommon_t *item ) {
Menu_AddItem
=================
*/
-void Menu_AddItem( menuFrameWork_t *menu, void *item ) {
- if( menu->nitems >= MAXMENUITEMS ) {
- Com_Error( ERR_FATAL, "Menu_AddItem: too many items" );
+void Menu_AddItem(menuFrameWork_t *menu, void *item)
+{
+ if (menu->nitems >= MAXMENUITEMS) {
+ Com_Error(ERR_FATAL, "Menu_AddItem: too many items");
}
menu->items[menu->nitems++] = item;
((menuCommon_t *)item)->parent = menu;
}
-static void UI_ClearBounds( int mins[2], int maxs[2] ) {
+static void UI_ClearBounds(int mins[2], int maxs[2])
+{
mins[0] = mins[1] = 9999;
maxs[0] = maxs[1] = -9999;
}
-static void UI_AddRectToBounds( const vrect_t *rc, int mins[2], int maxs[2] ) {
- if( mins[0] > rc->x ) {
+static void UI_AddRectToBounds(const vrect_t *rc, int mins[2], int maxs[2])
+{
+ if (mins[0] > rc->x) {
mins[0] = rc->x;
- } else if( maxs[0] < rc->x + rc->width ) {
+ } else if (maxs[0] < rc->x + rc->width) {
maxs[0] = rc->x + rc->width;
}
- if( mins[1] > rc->y ) {
+ if (mins[1] > rc->y) {
mins[1] = rc->y;
- } else if( maxs[1] < rc->y + rc->height ) {
+ } else if (maxs[1] < rc->y + rc->height) {
maxs[1] = rc->y + rc->height;
}
}
-void Menu_Init( menuFrameWork_t *menu ) {
+void Menu_Init(menuFrameWork_t *menu)
+{
void *item;
int i;
int focus = 0;
@@ -1368,24 +1430,24 @@ void Menu_Init( menuFrameWork_t *menu ) {
menu->y1 = 0;
menu->y2 = uis.height;
- if( !menu->size ) {
+ if (!menu->size) {
menu->size = Menu_Size;
}
- menu->size( menu );
+ menu->size(menu);
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
focus |= ((menuCommon_t *)item)->flags & QMF_HASFOCUS;
- switch( ((menuCommon_t *)item)->type ) {
+ switch (((menuCommon_t *)item)->type) {
case MTYPE_FIELD:
- Field_Init( item );
+ Field_Init(item);
break;
case MTYPE_SLIDER:
- Slider_Init( item );
+ Slider_Init(item);
break;
case MTYPE_LIST:
- MenuList_Init( item );
+ MenuList_Init(item);
break;
case MTYPE_SPINCONTROL:
case MTYPE_BITFIELD:
@@ -1393,43 +1455,43 @@ void Menu_Init( menuFrameWork_t *menu ) {
case MTYPE_VALUES:
case MTYPE_STRINGS:
case MTYPE_TOGGLE:
- SpinControl_Init( item );
+ SpinControl_Init(item);
break;
case MTYPE_ACTION:
- Action_Init( item );
+ Action_Init(item);
break;
case MTYPE_SEPARATOR:
- Separator_Init( item );
+ Separator_Init(item);
break;
case MTYPE_STATIC:
- Static_Init( item );
+ Static_Init(item);
break;
case MTYPE_KEYBIND:
- Keybind_Init( item );
+ Keybind_Init(item);
break;
case MTYPE_BITMAP:
- Bitmap_Init( item );
+ Bitmap_Init(item);
break;
default:
- Com_Error( ERR_FATAL, "Menu_Init: unknown item type" );
+ Com_Error(ERR_FATAL, "Menu_Init: unknown item type");
break;
}
}
// set focus to the first item by default
- if( !focus && menu->nitems ) {
+ if (!focus && menu->nitems) {
item = menu->items[0];
((menuCommon_t *)item)->flags |= QMF_HASFOCUS;
}
// calc menu bounding box
- UI_ClearBounds( menu->mins, menu->maxs );
+ UI_ClearBounds(menu->mins, menu->maxs);
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
rc = &((menuCommon_t *)item)->rect;
- UI_AddRectToBounds( rc, menu->mins, menu->maxs );
+ UI_AddRectToBounds(rc, menu->mins, menu->maxs);
}
// expand
@@ -1439,26 +1501,27 @@ void Menu_Init( menuFrameWork_t *menu ) {
menu->maxs[1] += MENU_SPACING;
// clamp
- if( menu->mins[0] < 0 ) menu->mins[0] = 0;
- if( menu->mins[1] < 0 ) menu->mins[1] = 0;
- if( menu->maxs[0] > uis.width ) menu->maxs[0] = uis.width;
- if( menu->maxs[1] > uis.height ) menu->maxs[1] = uis.height;
+ if (menu->mins[0] < 0) menu->mins[0] = 0;
+ if (menu->mins[1] < 0) menu->mins[1] = 0;
+ if (menu->maxs[0] > uis.width) menu->maxs[0] = uis.width;
+ if (menu->maxs[1] > uis.height) menu->maxs[1] = uis.height;
}
-void Menu_Size( menuFrameWork_t *menu ) {
+void Menu_Size(menuFrameWork_t *menu)
+{
menuCommon_t *item;
int x, y, w, h;
int i, widest = -1;
// count visible items
- for( i = 0, h = 0; i < menu->nitems; i++ ) {
+ for (i = 0, h = 0; i < menu->nitems; i++) {
item = menu->items[i];
- if( item->flags & QMF_HIDDEN ) {
+ if (item->flags & QMF_HIDDEN) {
continue;
}
- if( item->type == MTYPE_BITMAP ) {
- h += GENERIC_SPACING( item->height );
- if( widest < item->width ) {
+ if (item->type == MTYPE_BITMAP) {
+ h += GENERIC_SPACING(item->height);
+ if (widest < item->width) {
widest = item->width;
}
} else {
@@ -1467,75 +1530,75 @@ void Menu_Size( menuFrameWork_t *menu ) {
}
// account for banner
- if( menu->banner ) {
- h += GENERIC_SPACING( menu->banner_rc.height );
+ if (menu->banner) {
+ h += GENERIC_SPACING(menu->banner_rc.height);
}
// set menu top/bottom
- if( menu->transparent ) {
- menu->y1 = ( uis.height - h ) / 2 - MENU_SPACING;
- menu->y2 = ( uis.height + h ) / 2 + MENU_SPACING;
+ if (menu->transparent) {
+ menu->y1 = (uis.height - h) / 2 - MENU_SPACING;
+ menu->y2 = (uis.height + h) / 2 + MENU_SPACING;
} else {
menu->y1 = 0;
menu->y2 = uis.height;
}
// set menu horizontal base
- if( widest == -1 ) {
+ if (widest == -1) {
x = uis.width / 2;
} else {
// if menu has bitmaps, it is expected to have plaque and logo
// align them horizontally to avoid going off screen on small resolution
- w = widest + CURSOR_WIDTH;
- if( menu->plaque_rc.width > menu->logo_rc.width ) {
+ w = widest + CURSOR_WIDTH;
+ if (menu->plaque_rc.width > menu->logo_rc.width) {
w += menu->plaque_rc.width;
} else {
w += menu->logo_rc.width;
}
- x = ( uis.width + w ) / 2 - widest;
+ x = (uis.width + w) / 2 - widest;
}
// set menu vertical base
- y = ( uis.height - h ) / 2;
+ y = (uis.height - h) / 2;
// banner is horizontally centered and
// positioned on top of all menu items
- if( menu->banner ) {
- menu->banner_rc.x = ( uis.width - menu->banner_rc.width ) / 2;
+ if (menu->banner) {
+ menu->banner_rc.x = (uis.width - menu->banner_rc.width) / 2;
menu->banner_rc.y = y;
- y += GENERIC_SPACING( menu->banner_rc.height );
+ y += GENERIC_SPACING(menu->banner_rc.height);
}
// plaque and logo are vertically centered and
// positioned to the left of bitmaps and cursor
h = 0;
- if( menu->plaque ) {
+ if (menu->plaque) {
h += menu->plaque_rc.height;
}
- if( menu->logo ) {
+ if (menu->logo) {
h += menu->logo_rc.height + 5;
}
- if( menu->plaque ) {
+ if (menu->plaque) {
menu->plaque_rc.x = x - CURSOR_WIDTH - menu->plaque_rc.width;
- menu->plaque_rc.y = ( uis.height - h ) / 2;
+ menu->plaque_rc.y = (uis.height - h) / 2;
}
- if( menu->logo ) {
+ if (menu->logo) {
menu->logo_rc.x = x - CURSOR_WIDTH - menu->logo_rc.width;
- menu->logo_rc.y = ( uis.height + h ) / 2 - menu->logo_rc.height;
+ menu->logo_rc.y = (uis.height + h) / 2 - menu->logo_rc.height;
}
// align items
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- if( item->flags & QMF_HIDDEN ) {
+ if (item->flags & QMF_HIDDEN) {
continue;
}
item->x = x;
item->y = y;
- if( item->type == MTYPE_BITMAP ) {
- y += GENERIC_SPACING( item->height );
+ if (item->type == MTYPE_BITMAP) {
+ y += GENERIC_SPACING(item->height);
} else {
y += MENU_SPACING;
}
@@ -1543,14 +1606,14 @@ void Menu_Size( menuFrameWork_t *menu ) {
}
-
-menuCommon_t *Menu_ItemAtCursor( menuFrameWork_t *m ) {
+menuCommon_t *Menu_ItemAtCursor(menuFrameWork_t *m)
+{
menuCommon_t *item;
int i;
- for( i = 0; i < m->nitems; i++ ) {
+ for (i = 0; i < m->nitems; i++) {
item = m->items[i];
- if( item->flags & QMF_HASFOCUS ) {
+ if (item->flags & QMF_HASFOCUS) {
return item;
}
}
@@ -1558,32 +1621,33 @@ menuCommon_t *Menu_ItemAtCursor( menuFrameWork_t *m ) {
return NULL;
}
-void Menu_SetFocus( menuCommon_t *focus ) {
+void Menu_SetFocus(menuCommon_t *focus)
+{
menuFrameWork_t *menu;
menuCommon_t *item;
int i;
- if( focus->flags & QMF_HASFOCUS ) {
+ if (focus->flags & QMF_HASFOCUS) {
return;
}
menu = focus->parent;
- for( i = 0; i < menu->nitems ; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = (menuCommon_t *)menu->items[i];
- if( item == focus ) {
+ if (item == focus) {
item->flags |= QMF_HASFOCUS;
- if( item->focus ) {
- item->focus( item, qtrue );
- } else if( item->status ) {
+ if (item->focus) {
+ item->focus(item, qtrue);
+ } else if (item->status) {
menu->status = item->status;
}
- } else if( item->flags & QMF_HASFOCUS ) {
+ } else if (item->flags & QMF_HASFOCUS) {
item->flags &= ~QMF_HASFOCUS;
- if( item->focus ) {
- item->focus( item, qfalse );
- } else if( menu->status == item->status ) {
+ if (item->focus) {
+ item->focus(item, qfalse);
+ } else if (menu->status == item->status) {
menu->status = NULL;
}
}
@@ -1600,16 +1664,17 @@ to adjust the menu's cursor so that it's at the next available
slot.
=================
*/
-menuSound_t Menu_AdjustCursor( menuFrameWork_t *m, int dir ) {
+menuSound_t Menu_AdjustCursor(menuFrameWork_t *m, int dir)
+{
menuCommon_t *item;
int cursor, pos;
int i;
pos = 0;
- for( i=0 ; i<m->nitems ; i++ ) {
+ for (i = 0; i < m->nitems; i++) {
item = (menuCommon_t *)m->items[i];
- if( item->flags & QMF_HASFOCUS ) {
+ if (item->flags & QMF_HASFOCUS) {
pos = i;
break;
}
@@ -1619,29 +1684,29 @@ menuSound_t Menu_AdjustCursor( menuFrameWork_t *m, int dir ) {
** crawl in the direction indicated until we find a valid spot
*/
cursor = pos;
- if( dir == 1 ) {
+ if (dir == 1) {
do {
cursor++;
- if( cursor >= m->nitems )
+ if (cursor >= m->nitems)
cursor = 0;
item = (menuCommon_t *)m->items[cursor];
- if( UI_IsItemSelectable( item ) )
+ if (UI_IsItemSelectable(item))
break;
- } while( cursor != pos );
+ } while (cursor != pos);
} else {
do {
cursor--;
- if( cursor < 0 )
+ if (cursor < 0)
cursor = m->nitems - 1;
item = (menuCommon_t *)m->items[cursor];
- if( UI_IsItemSelectable( item ) )
+ if (UI_IsItemSelectable(item))
break;
- } while( cursor != pos );
+ } while (cursor != pos);
}
- Menu_SetFocus( item );
+ Menu_SetFocus(item);
return QMS_MOVE;
}
@@ -1651,60 +1716,61 @@ menuSound_t Menu_AdjustCursor( menuFrameWork_t *m, int dir ) {
Menu_Draw
=================
*/
-void Menu_Draw( menuFrameWork_t *menu ) {
+void Menu_Draw(menuFrameWork_t *menu)
+{
void *item;
int i;
//
// draw background
//
- if( menu->image ) {
- R_DrawStretchPic( 0, menu->y1, uis.width,
- menu->y2 - menu->y1, menu->image );
+ if (menu->image) {
+ R_DrawStretchPic(0, menu->y1, uis.width,
+ menu->y2 - menu->y1, menu->image);
} else {
- R_DrawFill32( 0, menu->y1, uis.width,
- menu->y2 - menu->y1, menu->color.u32 );
+ R_DrawFill32(0, menu->y1, uis.width,
+ menu->y2 - menu->y1, menu->color.u32);
}
//
// draw title bar
//
- if( menu->title ) {
- UI_DrawString( uis.width / 2, menu->y1,
- UI_CENTER|UI_ALTCOLOR, menu->title );
+ if (menu->title) {
+ UI_DrawString(uis.width / 2, menu->y1,
+ UI_CENTER | UI_ALTCOLOR, menu->title);
}
//
// draw banner, plaque and logo
//
- if( menu->banner ) {
- R_DrawPic( menu->banner_rc.x, menu->banner_rc.y, menu->banner );
+ if (menu->banner) {
+ R_DrawPic(menu->banner_rc.x, menu->banner_rc.y, menu->banner);
}
- if( menu->plaque ) {
- R_DrawPic( menu->plaque_rc.x, menu->plaque_rc.y, menu->plaque );
+ if (menu->plaque) {
+ R_DrawPic(menu->plaque_rc.x, menu->plaque_rc.y, menu->plaque);
}
- if( menu->logo ) {
- R_DrawPic( menu->logo_rc.x, menu->logo_rc.y, menu->logo );
+ if (menu->logo) {
+ R_DrawPic(menu->logo_rc.x, menu->logo_rc.y, menu->logo);
}
//
// draw contents
//
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- if( (( menuCommon_t * )item)->flags & QMF_HIDDEN ) {
+ if (((menuCommon_t *)item)->flags & QMF_HIDDEN) {
continue;
}
- switch( (( menuCommon_t * )item)->type ) {
+ switch (((menuCommon_t *)item)->type) {
case MTYPE_FIELD:
- Field_Draw( item );
+ Field_Draw(item);
break;
case MTYPE_SLIDER:
- Slider_Draw( item );
+ Slider_Draw(item);
break;
case MTYPE_LIST:
- MenuList_Draw( item );
+ MenuList_Draw(item);
break;
case MTYPE_SPINCONTROL:
case MTYPE_BITFIELD:
@@ -1712,133 +1778,139 @@ void Menu_Draw( menuFrameWork_t *menu ) {
case MTYPE_VALUES:
case MTYPE_STRINGS:
case MTYPE_TOGGLE:
- SpinControl_Draw( item );
+ SpinControl_Draw(item);
break;
case MTYPE_ACTION:
- Action_Draw( item );
+ Action_Draw(item);
break;
case MTYPE_SEPARATOR:
- Separator_Draw( item );
+ Separator_Draw(item);
break;
case MTYPE_STATIC:
- Static_Draw( item );
+ Static_Draw(item);
break;
case MTYPE_KEYBIND:
- Keybind_Draw( item );
+ Keybind_Draw(item);
break;
case MTYPE_BITMAP:
- Bitmap_Draw( item );
+ Bitmap_Draw(item);
break;
default:
- Com_Error( ERR_FATAL, "Menu_Draw: unknown item type" );
+ Com_Error(ERR_FATAL, "Menu_Draw: unknown item type");
break;
}
- if( ui_debug->integer ) {
- UI_DrawRect8( &(( menuCommon_t * )item)->rect, 1, 223 );
+ if (ui_debug->integer) {
+ UI_DrawRect8(&((menuCommon_t *)item)->rect, 1, 223);
}
}
//
// draw status bar
//
- if( menu->status ) {
- R_DrawFill8( 0, menu->y2 - CHAR_HEIGHT, uis.width, CHAR_HEIGHT, 4 );
- UI_DrawString( uis.width / 2, menu->y2 - CHAR_HEIGHT,
- UI_CENTER, menu->status );
+ if (menu->status) {
+ R_DrawFill8(0, menu->y2 - CHAR_HEIGHT, uis.width, CHAR_HEIGHT, 4);
+ UI_DrawString(uis.width / 2, menu->y2 - CHAR_HEIGHT,
+ UI_CENTER, menu->status);
}
}
-menuSound_t Menu_SelectItem( menuFrameWork_t *s ) {
+menuSound_t Menu_SelectItem(menuFrameWork_t *s)
+{
menuCommon_t *item;
- if( !( item = Menu_ItemAtCursor( s ) ) ) {
+ if (!(item = Menu_ItemAtCursor(s))) {
return QMS_NOTHANDLED;
}
- switch( item->type ) {
+ switch (item->type) {
//case MTYPE_SLIDER:
- // return Slider_DoSlide( (menuSlider_t *)item, 1 );
+ // return Slider_DoSlide((menuSlider_t *)item, 1);
case MTYPE_SPINCONTROL:
case MTYPE_BITFIELD:
case MTYPE_PAIRS:
case MTYPE_VALUES:
case MTYPE_STRINGS:
case MTYPE_TOGGLE:
- return SpinControl_DoEnter( (menuSpinControl_t *)item );
+ return SpinControl_DoEnter((menuSpinControl_t *)item);
case MTYPE_KEYBIND:
- return Keybind_DoEnter( ( menuKeybind_t * )item );
+ return Keybind_DoEnter((menuKeybind_t *)item);
case MTYPE_FIELD:
case MTYPE_ACTION:
case MTYPE_LIST:
case MTYPE_BITMAP:
- return Common_DoEnter( item );
+ return Common_DoEnter(item);
default:
return QMS_NOTHANDLED;
}
}
-menuSound_t Menu_SlideItem( menuFrameWork_t *s, int dir ) {
+menuSound_t Menu_SlideItem(menuFrameWork_t *s, int dir)
+{
menuCommon_t *item;
- if( !( item = Menu_ItemAtCursor( s ) ) ) {
+ if (!(item = Menu_ItemAtCursor(s))) {
return QMS_NOTHANDLED;
}
- switch( item->type ) {
+ switch (item->type) {
case MTYPE_SLIDER:
- return Slider_DoSlide( (menuSlider_t *)item, dir );
+ return Slider_DoSlide((menuSlider_t *)item, dir);
case MTYPE_SPINCONTROL:
case MTYPE_BITFIELD:
case MTYPE_PAIRS:
case MTYPE_VALUES:
case MTYPE_STRINGS:
case MTYPE_TOGGLE:
- return SpinControl_DoSlide( (menuSpinControl_t *)item, dir );
+ return SpinControl_DoSlide((menuSpinControl_t *)item, dir);
default:
return QMS_NOTHANDLED;
}
}
-menuSound_t Menu_KeyEvent( menuCommon_t *item, int key ) {
- if( item->keydown ) {
- menuSound_t sound = item->keydown( item, key );
- if( sound != QMS_NOTHANDLED ) {
+menuSound_t Menu_KeyEvent(menuCommon_t *item, int key)
+{
+ if (item->keydown) {
+ menuSound_t sound = item->keydown(item, key);
+ if (sound != QMS_NOTHANDLED) {
return sound;
}
}
- switch( item->type ) {
+ switch (item->type) {
case MTYPE_FIELD:
- return Field_Key( ( menuField_t * )item, key );
+ return Field_Key((menuField_t *)item, key);
case MTYPE_LIST:
- return MenuList_Key( ( menuList_t * )item, key );
+ return MenuList_Key((menuList_t *)item, key);
case MTYPE_SLIDER:
- return Slider_Key( ( menuSlider_t * )item, key );
+ return Slider_Key((menuSlider_t *)item, key);
case MTYPE_KEYBIND:
- return Keybind_Key( ( menuKeybind_t * )item, key );
+ return Keybind_Key((menuKeybind_t *)item, key);
default:
return QMS_NOTHANDLED;
}
}
-menuSound_t Menu_CharEvent( menuCommon_t *item, int key ) {
- switch( item->type ) {
+menuSound_t Menu_CharEvent(menuCommon_t *item, int key)
+{
+ switch (item->type) {
case MTYPE_FIELD:
- return Field_Char( (menuField_t *)item, key );
+ return Field_Char((menuField_t *)item, key);
default:
return QMS_NOTHANDLED;
}
}
-menuSound_t Menu_MouseMove( menuCommon_t *item ) {
+menuSound_t Menu_MouseMove(menuCommon_t *item)
+{
return QMS_NOTHANDLED;
}
-static menuSound_t Menu_DefaultKey( menuFrameWork_t *m, int key ) {
+static menuSound_t Menu_DefaultKey(menuFrameWork_t *m, int key)
+{
menuCommon_t *item;
-
- switch( key ) {
+
+ switch (key) {
case K_ESCAPE:
UI_PopMenu();
return QMS_OUT;
@@ -1846,89 +1918,91 @@ static menuSound_t Menu_DefaultKey( menuFrameWork_t *m, int key ) {
case K_KP_UPARROW:
case K_UPARROW:
case 'k':
- return Menu_AdjustCursor( m, -1 );
-
+ return Menu_AdjustCursor(m, -1);
+
case K_KP_DOWNARROW:
case K_DOWNARROW:
case K_TAB:
case 'j':
- return Menu_AdjustCursor( m, 1 );
+ return Menu_AdjustCursor(m, 1);
case K_KP_LEFTARROW:
case K_LEFTARROW:
case K_MWHEELDOWN:
case 'h':
- return Menu_SlideItem( m, -1 );
+ return Menu_SlideItem(m, -1);
case K_KP_RIGHTARROW:
case K_RIGHTARROW:
case K_MWHEELUP:
case 'l':
- return Menu_SlideItem( m, 1 );
+ return Menu_SlideItem(m, 1);
case K_MOUSE1:
case K_MOUSE2:
case K_MOUSE3:
- item = Menu_HitTest( m );
- if( !item ) {
+ item = Menu_HitTest(m);
+ if (!item) {
return QMS_NOTHANDLED;
}
-
- if( !( item->flags & QMF_HASFOCUS ) ) {
+
+ if (!(item->flags & QMF_HASFOCUS)) {
return QMS_NOTHANDLED;
}
// fall through
case K_KP_ENTER:
case K_ENTER:
- return Menu_SelectItem( m );
+ return Menu_SelectItem(m);
}
return QMS_NOTHANDLED;
}
-menuSound_t Menu_Keydown( menuFrameWork_t *menu, int key ) {
+menuSound_t Menu_Keydown(menuFrameWork_t *menu, int key)
+{
menuCommon_t *item;
menuSound_t sound;
- if( menu->keywait ) {
+ if (menu->keywait) {
}
- if( menu->keydown ) {
- sound = menu->keydown( menu, key );
- if( sound != QMS_NOTHANDLED ) {
+ if (menu->keydown) {
+ sound = menu->keydown(menu, key);
+ if (sound != QMS_NOTHANDLED) {
return sound;
}
}
- item = Menu_ItemAtCursor( menu );
- if( item ) {
- sound = Menu_KeyEvent( item, key );
- if( sound != QMS_NOTHANDLED ) {
+ item = Menu_ItemAtCursor(menu);
+ if (item) {
+ sound = Menu_KeyEvent(item, key);
+ if (sound != QMS_NOTHANDLED) {
return sound;
}
}
-
- sound = Menu_DefaultKey( menu, key );
+
+ sound = Menu_DefaultKey(menu, key);
return sound;
}
-menuCommon_t *Menu_HitTest( menuFrameWork_t *menu ) {
+menuCommon_t *Menu_HitTest(menuFrameWork_t *menu)
+{
int i;
menuCommon_t *item;
- if( menu->keywait ) {
+ if (menu->keywait) {
return NULL;
}
-
- for( i = 0; i < menu->nitems; i++ ) {
+
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- if( item->flags & QMF_HIDDEN ) {
+ if (item->flags & QMF_HIDDEN) {
continue;
}
- if( UI_CursorInRect( &item->rect ) ) {
+ if (UI_CursorInRect(&item->rect)) {
return item;
}
}
@@ -1936,37 +2010,38 @@ menuCommon_t *Menu_HitTest( menuFrameWork_t *menu ) {
return NULL;
}
-qboolean Menu_Push( menuFrameWork_t *menu ) {
+qboolean Menu_Push(menuFrameWork_t *menu)
+{
void *item;
int i;
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- switch( ((menuCommon_t *)item)->type ) {
+ switch (((menuCommon_t *)item)->type) {
case MTYPE_SLIDER:
- Slider_Push( item );
+ Slider_Push(item);
break;
case MTYPE_BITFIELD:
- BitField_Push( item );
+ BitField_Push(item);
break;
case MTYPE_PAIRS:
- Pairs_Push( item );
+ Pairs_Push(item);
break;
case MTYPE_STRINGS:
- Strings_Push( item );
+ Strings_Push(item);
break;
case MTYPE_SPINCONTROL:
- SpinControl_Push( item );
+ SpinControl_Push(item);
break;
case MTYPE_TOGGLE:
- Toggle_Push( item );
+ Toggle_Push(item);
break;
case MTYPE_KEYBIND:
- Keybind_Push( item );
+ Keybind_Push(item);
break;
case MTYPE_FIELD:
- Field_Push( item );
+ Field_Push(item);
break;
default:
break;
@@ -1975,35 +2050,36 @@ qboolean Menu_Push( menuFrameWork_t *menu ) {
return qtrue;
}
-void Menu_Pop( menuFrameWork_t *menu ) {
+void Menu_Pop(menuFrameWork_t *menu)
+{
void *item;
int i;
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- switch( ((menuCommon_t *)item)->type ) {
+ switch (((menuCommon_t *)item)->type) {
case MTYPE_SLIDER:
- Slider_Pop( item );
+ Slider_Pop(item);
break;
case MTYPE_BITFIELD:
- BitField_Pop( item );
+ BitField_Pop(item);
break;
case MTYPE_PAIRS:
- Pairs_Pop( item );
+ Pairs_Pop(item);
break;
case MTYPE_STRINGS:
- Strings_Pop( item );
+ Strings_Pop(item);
break;
case MTYPE_SPINCONTROL:
case MTYPE_TOGGLE:
- SpinControl_Pop( item );
+ SpinControl_Pop(item);
break;
case MTYPE_KEYBIND:
- Keybind_Pop( item );
+ Keybind_Pop(item);
break;
case MTYPE_FIELD:
- Field_Pop( item );
+ Field_Pop(item);
break;
default:
break;
@@ -2011,50 +2087,51 @@ void Menu_Pop( menuFrameWork_t *menu ) {
}
}
-void Menu_Free( menuFrameWork_t *menu ) {
+void Menu_Free(menuFrameWork_t *menu)
+{
void *item;
int i;
- for( i = 0; i < menu->nitems; i++ ) {
+ for (i = 0; i < menu->nitems; i++) {
item = menu->items[i];
- switch( ((menuCommon_t *)item)->type ) {
+ switch (((menuCommon_t *)item)->type) {
case MTYPE_ACTION:
- Action_Free( item );
+ Action_Free(item);
break;
case MTYPE_SLIDER:
- Slider_Free( item );
+ Slider_Free(item);
break;
case MTYPE_BITFIELD:
case MTYPE_TOGGLE:
- BitField_Free( item );
+ BitField_Free(item);
break;
case MTYPE_PAIRS:
- Pairs_Free( item );
+ Pairs_Free(item);
break;
case MTYPE_SPINCONTROL:
case MTYPE_STRINGS:
- SpinControl_Free( item );
+ SpinControl_Free(item);
break;
case MTYPE_KEYBIND:
- Keybind_Free( item );
+ Keybind_Free(item);
break;
case MTYPE_FIELD:
- Field_Free( item );
+ Field_Free(item);
break;
case MTYPE_SEPARATOR:
- Z_Free( item );
+ Z_Free(item);
break;
case MTYPE_BITMAP:
- Bitmap_Free( item );
+ Bitmap_Free(item);
break;
default:
break;
}
}
- Z_Free( menu->title );
- Z_Free( menu->name );
- Z_Free( menu );
+ Z_Free(menu->title);
+ Z_Free(menu->name);
+ Z_Free(menu);
}
diff --git a/src/ui_multiplayer.c b/src/ui_multiplayer.c
index d902286..43434c4 100644
--- a/src/ui_multiplayer.c
+++ b/src/ui_multiplayer.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -57,17 +57,18 @@ typedef struct m_joinServer_s {
static m_joinServer_t m_join;
-static void UpdateSelection( void ) {
+static void UpdateSelection(void)
+{
serverSlot_t *s = &m_join.servers[m_join.list.curvalue];
- if( s->valid ) {
+ if (s->valid) {
m_join.info.generic.flags &= ~QMF_HIDDEN;
- m_join.info.items = ( void ** )s->rules;
+ m_join.info.items = (void **)s->rules;
m_join.info.numItems = s->numRules;
- if( s->numPlayers ) {
+ if (s->numPlayers) {
m_join.players.generic.flags &= ~QMF_HIDDEN;
- m_join.players.items = ( void ** )s->players;
+ m_join.players.items = (void **)s->players;
m_join.players.numItems = s->numPlayers;
} else {
m_join.players.generic.flags |= QMF_HIDDEN;
@@ -85,29 +86,31 @@ static void UpdateSelection( void ) {
m_join.players.items = NULL;
m_join.players.numItems = 0;
- if( m_join.list.numItems )
+ if (m_join.list.numItems)
m_join.menu.status = "Press Space to refresh; Hold ALT to refresh all";
else
m_join.menu.status = "No servers found; Press Space to refresh";
}
}
-static void ClearSlot( serverSlot_t *slot ) {
+static void ClearSlot(serverSlot_t *slot)
+{
int i;
- for( i = 0; i < slot->numRules; i++ ) {
- Z_Free( slot->rules[i] );
+ for (i = 0; i < slot->numRules; i++) {
+ Z_Free(slot->rules[i]);
slot->rules[i] = NULL;
}
- for( i = 0; i < slot->numPlayers; i++ ) {
- Z_Free( slot->players[i] );
+ for (i = 0; i < slot->numPlayers; i++) {
+ Z_Free(slot->players[i]);
slot->players[i] = NULL;
}
slot->numRules = slot->numPlayers = 0;
slot->valid = qfalse;
}
-void UI_AddToServerList( const serverStatus_t *status ) {
+void UI_AddToServerList(const serverStatus_t *status)
+{
serverSlot_t *slot;
int i, j, k;
char *host, *map;
@@ -116,25 +119,25 @@ void UI_AddToServerList( const serverStatus_t *status ) {
char value[MAX_STRING_CHARS];
const playerStatus_t *player;
- if( !m_join.active ) {
+ if (!m_join.active) {
return;
}
// see if already added
- for( i = 0, slot = m_join.servers; i < m_join.list.numItems; i++, slot++ ) {
- if( !strcmp( status->address, slot->realAddress ) ) {
+ for (i = 0, slot = m_join.servers; i < m_join.list.numItems; i++, slot++) {
+ if (!strcmp(status->address, slot->realAddress)) {
break;
}
}
- if( i == m_join.list.numItems ) {
+ if (i == m_join.list.numItems) {
// create new slot
- if( m_join.list.numItems == MAX_STATUS_SERVERS ) {
+ if (m_join.list.numItems == MAX_STATUS_SERVERS) {
return;
}
- strcpy( slot->realAddress, status->address );
- strcpy( slot->address, status->address );
- if( !m_join.cursorSet ) {
+ strcpy(slot->realAddress, status->address);
+ strcpy(slot->address, status->address);
+ if (!m_join.cursorSet) {
m_join.list.curvalue = i;
m_join.cursorSet = qtrue;
}
@@ -142,13 +145,13 @@ void UI_AddToServerList( const serverStatus_t *status ) {
m_join.names[m_join.list.numItems] = NULL;
}
- host = Info_ValueForKey( info, "hostname" );
- if( !host[0] ) {
+ host = Info_ValueForKey(info, "hostname");
+ if (!host[0]) {
host = slot->address;
}
- map = Info_ValueForKey( info, "mapname" );
- if( !map[0] ) {
+ map = Info_ValueForKey(info, "mapname");
+ if (!map[0]) {
map = "???";
} /*else {
Q_snprintf( value, sizeof( value ), "maps/%s.bsp", map );
@@ -158,33 +161,33 @@ void UI_AddToServerList( const serverStatus_t *status ) {
}
}*/
- j = atoi( Info_ValueForKey( info, "maxclients" ) );
- k = atoi( Info_ValueForKey( info, "needpass" ) );
- Q_snprintf( key, sizeof( key ), "%d/%d",
- //status->numPlayers < j ? k > 0 ? S_COLOR_YELLOW : "" : S_COLOR_RED,
- status->numPlayers, j );
+ j = atoi(Info_ValueForKey(info, "maxclients"));
+ k = atoi(Info_ValueForKey(info, "needpass"));
+ Q_snprintf(key, sizeof(key), "%d/%d",
+ //status->numPlayers < j ? k > 0 ? S_COLOR_YELLOW : "" : S_COLOR_RED,
+ status->numPlayers, j);
- if( m_join.names[i] ) {
- Z_Free( m_join.names[i] );
+ if (m_join.names[i]) {
+ Z_Free(m_join.names[i]);
}
- m_join.names[i] = UI_FormatColumns( 0, host, map, key, NULL );
+ m_join.names[i] = UI_FormatColumns(0, host, map, key, NULL);
- ClearSlot( slot );
+ ClearSlot(slot);
do {
- Info_NextPair( &info, key, value );
- if( !key[0] ) {
+ Info_NextPair(&info, key, value);
+ if (!key[0]) {
break;
}
slot->rules[slot->numRules++] =
- UI_FormatColumns( 0, key, value, NULL );
- } while( info && slot->numRules < MAX_STATUS_RULES );
-
- for( i = 0, player = status->players ; i < status->numPlayers; i++, player++ ) {
- Q_snprintf( key, sizeof( key ), "%d", player->score );
- Q_snprintf( value, sizeof( value ), "%d", player->ping );
- slot->players[i] = UI_FormatColumns( 0,
- key, value, player->name, NULL );
+ UI_FormatColumns(0, key, value, NULL);
+ } while (info && slot->numRules < MAX_STATUS_RULES);
+
+ for (i = 0, player = status->players; i < status->numPlayers; i++, player++) {
+ Q_snprintf(key, sizeof(key), "%d", player->score);
+ Q_snprintf(value, sizeof(value), "%d", player->ping);
+ slot->players[i] = UI_FormatColumns(0,
+ key, value, player->name, NULL);
}
slot->numPlayers = status->numPlayers;
@@ -193,84 +196,87 @@ void UI_AddToServerList( const serverStatus_t *status ) {
UpdateSelection();
}
-static void PingSelected( void ) {
+static void PingSelected(void)
+{
serverSlot_t *s = &m_join.servers[m_join.list.curvalue];
- if( m_join.names[m_join.list.curvalue] ) {
- Z_Free( m_join.names[m_join.list.curvalue] );
+ if (m_join.names[m_join.list.curvalue]) {
+ Z_Free(m_join.names[m_join.list.curvalue]);
}
- m_join.names[m_join.list.curvalue] = UI_FormatColumns( 0,
- s->address, "???", "?/?", NULL );
-
- ClearSlot( s );
-
+ m_join.names[m_join.list.curvalue] = UI_FormatColumns(0,
+ s->address, "???", "?/?", NULL);
+
+ ClearSlot(s);
+
UpdateSelection();
m_join.menu.status = "Pinging servers, please wait...";
SCR_UpdateScreen();
-
- CL_SendStatusRequest( s->realAddress, 0 );
+
+ CL_SendStatusRequest(s->realAddress, 0);
UpdateSelection();
}
-static void AddUnlistedServers( void ) {
+static void AddUnlistedServers(void)
+{
serverSlot_t *slot;
cvar_t *var;
int i, j;
-
+
m_join.active = qtrue;
// ping broadcast
- CL_SendStatusRequest( NULL, 0 );
+ CL_SendStatusRequest(NULL, 0);
- for( i = 0; i < MAX_STATUS_SERVERS; i++ ) {
- var = Cvar_FindVar( va( "adr%i", i ) );
- if( !var ) {
+ for (i = 0; i < MAX_STATUS_SERVERS; i++) {
+ var = Cvar_FindVar(va("adr%i", i));
+ if (!var) {
break;
}
- if( !var->string[0] ) {
+ if (!var->string[0]) {
continue;
}
// ignore if already listed
- for( j = 0, slot = m_join.servers; j < m_join.list.numItems; j++, slot++ ) {
- if( !Q_stricmp( var->string, slot->address ) ) {
+ for (j = 0, slot = m_join.servers; j < m_join.list.numItems; j++, slot++) {
+ if (!Q_stricmp(var->string, slot->address)) {
break;
}
}
- if( j != m_join.list.numItems ) {
+ if (j != m_join.list.numItems) {
continue;
}
- if( m_join.list.numItems == MAX_STATUS_SERVERS ) {
+ if (m_join.list.numItems == MAX_STATUS_SERVERS) {
break;
}
// save original address
- Q_strlcpy( slot->address, var->string, sizeof( slot->address ) );
- Q_strlcpy( slot->realAddress, var->string, sizeof( slot->realAddress ) );
+ Q_strlcpy(slot->address, var->string, sizeof(slot->address));
+ Q_strlcpy(slot->realAddress, var->string, sizeof(slot->realAddress));
- m_join.names[m_join.list.numItems++] = UI_FormatColumns( 0,
- slot->address, "???", "?/?", NULL );
+ m_join.names[m_join.list.numItems++] = UI_FormatColumns(0,
+ slot->address, "???", "?/?", NULL);
// ping and resolve real ip
- CL_SendStatusRequest( slot->realAddress, sizeof( slot->realAddress ) );
+ CL_SendStatusRequest(slot->realAddress, sizeof(slot->realAddress));
SCR_UpdateScreen();
}
}
-static void FreeListedServers( void ) {
+static void FreeListedServers(void)
+{
int i;
- for( i = 0; i < m_join.list.numItems; i++ ) {
- ClearSlot( &m_join.servers[i] );
+ for (i = 0; i < m_join.list.numItems; i++) {
+ ClearSlot(&m_join.servers[i]);
}
- for( i = 0; i < m_join.list.numItems; i++ ) {
- if( m_join.names[i] ) {
- Z_Free( m_join.names[i] );
+ for (i = 0; i < m_join.list.numItems; i++) {
+ if (m_join.names[i]) {
+ Z_Free(m_join.names[i]);
m_join.names[i] = NULL;
}
}
@@ -284,7 +290,8 @@ static void FreeListedServers( void ) {
}
-static void PingServers( void ) {
+static void PingServers(void)
+{
FreeListedServers();
S_StopAllSounds();
UpdateSelection();
@@ -294,23 +301,26 @@ static void PingServers( void ) {
// send out info packets
AddUnlistedServers();
-
+
UpdateSelection();
}
-static menuSound_t Connect( menuCommon_t *self ) {
+static menuSound_t Connect(menuCommon_t *self)
+{
serverSlot_t *s = &m_join.servers[m_join.list.curvalue];
- Cbuf_AddText( &cmd_buffer, va( "connect \"%s\"\n", s->realAddress ) );
+ Cbuf_AddText(&cmd_buffer, va("connect \"%s\"\n", s->realAddress));
return QMS_SILENT;
}
-static menuSound_t Change( menuCommon_t *self ) {
+static menuSound_t Change(menuCommon_t *self)
+{
UpdateSelection();
return QMS_MOVE;
}
-static void Size( menuFrameWork_t *self ) {
+static void Size(menuFrameWork_t *self)
+{
int w1 = uis.width * 0.75f;
int w2 = uis.width * 0.25f;
@@ -321,9 +331,9 @@ static void Size( menuFrameWork_t *self ) {
m_join.list.generic.y = CHAR_HEIGHT;
m_join.list.generic.height = uis.height / 2 - CHAR_HEIGHT;
- m_join.list.columns[0].width = w1 - 18*CHAR_WIDTH;
- m_join.list.columns[1].width = 10*CHAR_WIDTH;
- m_join.list.columns[2].width = 8*CHAR_WIDTH;
+ m_join.list.columns[0].width = w1 - 18 * CHAR_WIDTH;
+ m_join.list.columns[1].width = 10 * CHAR_WIDTH;
+ m_join.list.columns[2].width = 8 * CHAR_WIDTH;
//
// server info
@@ -339,23 +349,24 @@ static void Size( menuFrameWork_t *self ) {
//
m_join.players.generic.x = w1 + MLIST_SCROLLBAR_WIDTH;
m_join.players.generic.y = CHAR_HEIGHT;
- m_join.players.generic.height = uis.height - CHAR_HEIGHT*2 - 1;
+ m_join.players.generic.height = uis.height - CHAR_HEIGHT * 2 - 1;
- m_join.players.columns[0].width = 4*CHAR_WIDTH;
- m_join.players.columns[1].width = 4*CHAR_WIDTH;
- m_join.players.columns[2].width = w2 - MLIST_SCROLLBAR_WIDTH - 8*CHAR_WIDTH;
+ m_join.players.columns[0].width = 4 * CHAR_WIDTH;
+ m_join.players.columns[1].width = 4 * CHAR_WIDTH;
+ m_join.players.columns[2].width = w2 - MLIST_SCROLLBAR_WIDTH - 8 * CHAR_WIDTH;
}
-static menuSound_t Keydown( menuFrameWork_t *self, int key ) {
+static menuSound_t Keydown(menuFrameWork_t *self, int key)
+{
serverSlot_t *s = &m_join.servers[m_join.list.curvalue];
- switch( key ) {
+ switch (key) {
case 'r':
- Cvar_Set( "rcon_address", s->realAddress );
+ Cvar_Set("rcon_address", s->realAddress);
return QMS_SILENT;
case ' ':
- if( !Key_IsDown( K_ALT ) && m_join.list.numItems ) {
+ if (!Key_IsDown(K_ALT) && m_join.list.numItems) {
PingSelected();
} else {
PingServers();
@@ -366,19 +377,23 @@ static menuSound_t Keydown( menuFrameWork_t *self, int key ) {
}
}
-static void Pop( menuFrameWork_t *self ) {
+static void Pop(menuFrameWork_t *self)
+{
FreeListedServers();
}
-static void Expose( menuFrameWork_t *self ) {
+static void Expose(menuFrameWork_t *self)
+{
PingServers();
}
-static void Free( menuFrameWork_t *self ) {
- memset( &m_join, 0, sizeof( m_join ) );
+static void Free(menuFrameWork_t *self)
+{
+ memset(&m_join, 0, sizeof(m_join));
}
-void M_Menu_Servers( void ) {
+void M_Menu_Servers(void)
+{
m_join.menu.name = "servers";
m_join.menu.title = "Server Browser";
@@ -394,10 +409,10 @@ void M_Menu_Servers( void ) {
// server list
//
m_join.list.generic.type = MTYPE_LIST;
- m_join.list.generic.flags = QMF_LEFT_JUSTIFY|QMF_HASFOCUS;
+ m_join.list.generic.flags = QMF_LEFT_JUSTIFY | QMF_HASFOCUS;
m_join.list.generic.activate = Connect;
m_join.list.generic.change = Change;
- m_join.list.items = ( void ** )m_join.names;
+ m_join.list.items = (void **)m_join.names;
m_join.list.numcolumns = 3;
m_join.list.columns[0].uiFlags = UI_LEFT;
@@ -411,7 +426,7 @@ void M_Menu_Servers( void ) {
// server info
//
m_join.info.generic.type = MTYPE_LIST;
- m_join.info.generic.flags = QMF_LEFT_JUSTIFY|QMF_HIDDEN;
+ m_join.info.generic.flags = QMF_LEFT_JUSTIFY | QMF_HIDDEN;
m_join.info.numcolumns = 2;
m_join.info.columns[0].uiFlags = UI_LEFT;
@@ -423,7 +438,7 @@ void M_Menu_Servers( void ) {
// player list
//
m_join.players.generic.type = MTYPE_LIST;
- m_join.players.generic.flags = QMF_LEFT_JUSTIFY|QMF_HIDDEN|QMF_DISABLED;
+ m_join.players.generic.flags = QMF_LEFT_JUSTIFY | QMF_HIDDEN | QMF_DISABLED;
m_join.players.mlFlags = MLF_HIDE_SCROLLBAR;
m_join.players.numcolumns = 3;
@@ -434,10 +449,10 @@ void M_Menu_Servers( void ) {
m_join.players.columns[2].uiFlags = UI_LEFT;
m_join.players.columns[2].name = "Name";
- Menu_AddItem( &m_join.menu, &m_join.list );
- Menu_AddItem( &m_join.menu, &m_join.info );
- Menu_AddItem( &m_join.menu, &m_join.players );
+ Menu_AddItem(&m_join.menu, &m_join.list);
+ Menu_AddItem(&m_join.menu, &m_join.info);
+ Menu_AddItem(&m_join.menu, &m_join.players);
- List_Append( &ui_menus, &m_join.menu.entry );
+ List_Append(&ui_menus, &m_join.menu.entry);
}
diff --git a/src/ui_playerconfig.c b/src/ui_playerconfig.c
index ac41268..1b22a89 100644
--- a/src/ui_playerconfig.c
+++ b/src/ui_playerconfig.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -57,45 +57,48 @@ static const char *handedness[] = {
0
};
-static void ReloadMedia( void ) {
+static void ReloadMedia(void)
+{
char scratch[MAX_QPATH];
char *model = uis.pmi[m_player.model.curvalue].directory;
char *skin = uis.pmi[m_player.model.curvalue].skindisplaynames[m_player.skin.curvalue];
- Q_concat( scratch, sizeof( scratch ), "players/", model, "/tris.md2", NULL );
- m_player.entities[0].model = R_RegisterModel( scratch );
+ Q_concat(scratch, sizeof(scratch), "players/", model, "/tris.md2", NULL);
+ m_player.entities[0].model = R_RegisterModel(scratch);
- Q_concat( scratch, sizeof( scratch ), "players/", model, "/", skin, ".pcx", NULL );
- m_player.entities[0].skin = R_RegisterSkin( scratch );
+ Q_concat(scratch, sizeof(scratch), "players/", model, "/", skin, ".pcx", NULL);
+ m_player.entities[0].skin = R_RegisterSkin(scratch);
- if( uis.weaponModel[0] ) {
- Q_concat( scratch, sizeof( scratch ), "players/", model, "/", uis.weaponModel, NULL );
- m_player.entities[1].model = R_RegisterModel( scratch );
+ if (uis.weaponModel[0]) {
+ Q_concat(scratch, sizeof(scratch), "players/", model, "/", uis.weaponModel, NULL);
+ m_player.entities[1].model = R_RegisterModel(scratch);
}
}
-static void RunFrame( void ) {
+static void RunFrame(void)
+{
int frame;
int i;
- if( m_player.time < uis.realtime ) {
+ if (m_player.time < uis.realtime) {
m_player.oldTime = m_player.time;
m_player.time += 120;
- if( m_player.time < uis.realtime ) {
+ if (m_player.time < uis.realtime) {
m_player.time = uis.realtime;
}
- frame = ( m_player.time / 120 ) % 40;
+ frame = (m_player.time / 120) % 40;
- for( i = 0; i < m_player.refdef.num_entities; i++ ) {
+ for (i = 0; i < m_player.refdef.num_entities; i++) {
m_player.entities[i].oldframe = m_player.entities[i].frame;
m_player.entities[i].frame = frame;
}
}
}
-static void Draw( menuFrameWork_t *self ) {
+static void Draw(menuFrameWork_t *self)
+{
float backlerp;
int i;
@@ -103,23 +106,24 @@ static void Draw( menuFrameWork_t *self ) {
RunFrame();
- if( m_player.time == m_player.oldTime ) {
+ if (m_player.time == m_player.oldTime) {
backlerp = 0;
} else {
- backlerp = 1 - ( float )( uis.realtime - m_player.oldTime ) /
- ( float )( m_player.time - m_player.oldTime );
+ backlerp = 1 - (float)(uis.realtime - m_player.oldTime) /
+ (float)(m_player.time - m_player.oldTime);
}
- for( i = 0; i < m_player.refdef.num_entities; i++ ) {
+ for (i = 0; i < m_player.refdef.num_entities; i++) {
m_player.entities[i].backlerp = backlerp;
}
- Menu_Draw( self );
+ Menu_Draw(self);
- R_RenderFrame( &m_player.refdef );
+ R_RenderFrame(&m_player.refdef);
}
-static void Size( menuFrameWork_t *self ) {
+static void Size(menuFrameWork_t *self)
+{
int x = uis.width / 2 - 130;
int y = uis.height / 2 - 97;
@@ -129,8 +133,8 @@ static void Size( menuFrameWork_t *self ) {
m_player.refdef.height = uis.height / uis.scale - 122;
m_player.refdef.fov_x = 40;
- m_player.refdef.fov_y = V_CalcFov( m_player.refdef.fov_x,
- m_player.refdef.width, m_player.refdef.height );
+ m_player.refdef.fov_y = V_CalcFov(m_player.refdef.fov_x,
+ m_player.refdef.width, m_player.refdef.height);
m_player.name.generic.x = x;
m_player.name.generic.y = y;
@@ -148,13 +152,14 @@ static void Size( menuFrameWork_t *self ) {
m_player.hand.generic.y = y;
}
-static menuSound_t Change( menuCommon_t *self ) {
- switch( self->id ) {
+static menuSound_t Change(menuCommon_t *self)
+{
+ switch (self->id) {
case ID_MODEL:
m_player.skin.itemnames =
uis.pmi[m_player.model.curvalue].skindisplaynames;
m_player.skin.curvalue = 0;
- SpinControl_Init( &m_player.skin );
+ SpinControl_Init(&m_player.skin);
// fall through
case ID_SKIN:
ReloadMedia();
@@ -165,21 +170,23 @@ static menuSound_t Change( menuCommon_t *self ) {
return QMS_MOVE;
}
-static void Pop( menuFrameWork_t *self ) {
+static void Pop(menuFrameWork_t *self)
+{
char scratch[MAX_OSPATH];
- Cvar_SetEx( "name", m_player.name.field.text, FROM_CONSOLE );
+ Cvar_SetEx("name", m_player.name.field.text, FROM_CONSOLE);
- Q_concat( scratch, sizeof( scratch ),
- uis.pmi[m_player.model.curvalue].directory, "/",
- uis.pmi[m_player.model.curvalue].skindisplaynames[m_player.skin.curvalue], NULL );
+ Q_concat(scratch, sizeof(scratch),
+ uis.pmi[m_player.model.curvalue].directory, "/",
+ uis.pmi[m_player.model.curvalue].skindisplaynames[m_player.skin.curvalue], NULL);
- Cvar_SetEx( "skin", scratch, FROM_CONSOLE );
+ Cvar_SetEx("skin", scratch, FROM_CONSOLE);
- Cvar_SetEx( "hand", va( "%d", m_player.hand.curvalue ), FROM_CONSOLE );
+ Cvar_SetEx("hand", va("%d", m_player.hand.curvalue), FROM_CONSOLE);
}
-static qboolean Push( menuFrameWork_t *self ) {
+static qboolean Push(menuFrameWork_t *self)
+{
char currentdirectory[MAX_QPATH];
char currentskin[MAX_QPATH];
int i, j;
@@ -188,30 +195,30 @@ static qboolean Push( menuFrameWork_t *self ) {
char *p;
// find and register all player models
- if( !uis.numPlayerModels ) {
+ if (!uis.numPlayerModels) {
PlayerModel_Load();
- if( !uis.numPlayerModels ) {
+ if (!uis.numPlayerModels) {
return qfalse;
}
}
- Cvar_VariableStringBuffer( "skin", currentdirectory, sizeof( currentdirectory ) );
+ Cvar_VariableStringBuffer("skin", currentdirectory, sizeof(currentdirectory));
- if( ( p = strchr( currentdirectory, '/' ) ) || ( p = strchr( currentdirectory, '\\' ) ) ) {
+ if ((p = strchr(currentdirectory, '/')) || (p = strchr(currentdirectory, '\\'))) {
*p++ = 0;
- Q_strlcpy( currentskin, p, sizeof( currentskin ) );
+ Q_strlcpy(currentskin, p, sizeof(currentskin));
} else {
- strcpy( currentdirectory, "male" );
- strcpy( currentskin, "grunt" );
+ strcpy(currentdirectory, "male");
+ strcpy(currentskin, "grunt");
}
- for( i = 0 ; i < uis.numPlayerModels ; i++ ) {
+ for (i = 0; i < uis.numPlayerModels; i++) {
m_player.pmnames[i] = uis.pmi[i].directory;
- if( Q_stricmp( uis.pmi[i].directory, currentdirectory ) == 0 ) {
+ if (Q_stricmp(uis.pmi[i].directory, currentdirectory) == 0) {
currentdirectoryindex = i;
- for( j = 0 ; j < uis.pmi[i].nskins ; j++ ) {
- if( Q_stricmp( uis.pmi[i].skindisplaynames[j], currentskin ) == 0 ) {
+ for (j = 0; j < uis.pmi[i].nskins; j++) {
+ if (Q_stricmp(uis.pmi[i].skindisplaynames[j], currentskin) == 0) {
currentskinindex = j;
break;
}
@@ -219,8 +226,8 @@ static qboolean Push( menuFrameWork_t *self ) {
}
}
- IF_Init( &m_player.name.field, 15, 15 );
- IF_Replace( &m_player.name.field, Cvar_VariableString( "name" ) );
+ IF_Init(&m_player.name.field, 15, 15);
+ IF_Replace(&m_player.name.field, Cvar_VariableString("name"));
m_player.model.curvalue = currentdirectoryindex;
m_player.model.itemnames = m_player.pmnames;
@@ -228,8 +235,8 @@ static qboolean Push( menuFrameWork_t *self ) {
m_player.skin.curvalue = currentskinindex;
m_player.skin.itemnames = uis.pmi[currentdirectoryindex].skindisplaynames;
- m_player.hand.curvalue = Cvar_VariableInteger( "hand" );
- clamp( m_player.hand.curvalue, 0, 2 );
+ m_player.hand.curvalue = Cvar_VariableInteger("hand");
+ clamp(m_player.hand.curvalue, 0, 2);
ReloadMedia();
@@ -241,11 +248,13 @@ static qboolean Push( menuFrameWork_t *self ) {
return qtrue;
}
-static void Free( menuFrameWork_t *self ) {
- memset( &m_player, 0, sizeof( m_player ) );
+static void Free(menuFrameWork_t *self)
+{
+ memset(&m_player, 0, sizeof(m_player));
}
-void M_Menu_PlayerConfig( void ) {
+void M_Menu_PlayerConfig(void)
+{
static const vec3_t origin = { 80.0f, 5.0f, 0.0f };
static const vec3_t angles = { 0.0f, 260.0f, 0.0f };
@@ -260,17 +269,17 @@ void M_Menu_PlayerConfig( void ) {
m_player.menu.color.u32 = uis.color.background.u32;
m_player.entities[0].flags = RF_FULLBRIGHT;
- VectorCopy( angles, m_player.entities[0].angles );
- VectorCopy( origin, m_player.entities[0].origin );
- VectorCopy( origin, m_player.entities[0].oldorigin );
+ VectorCopy(angles, m_player.entities[0].angles);
+ VectorCopy(origin, m_player.entities[0].origin);
+ VectorCopy(origin, m_player.entities[0].oldorigin);
m_player.entities[1].flags = RF_FULLBRIGHT;
- VectorCopy( angles, m_player.entities[1].angles );
- VectorCopy( origin, m_player.entities[1].origin );
- VectorCopy( origin, m_player.entities[1].oldorigin );
+ VectorCopy(angles, m_player.entities[1].angles);
+ VectorCopy(origin, m_player.entities[1].origin);
+ VectorCopy(origin, m_player.entities[1].oldorigin);
m_player.refdef.num_entities = 1;
- if( uis.weaponModel[0] ) {
+ if (uis.weaponModel[0]) {
m_player.refdef.num_entities++;
}
@@ -293,13 +302,13 @@ void M_Menu_PlayerConfig( void ) {
m_player.hand.generic.type = MTYPE_SPINCONTROL;
m_player.hand.generic.name = "handedness";
- m_player.hand.itemnames = ( char ** )handedness;
+ m_player.hand.itemnames = (char **)handedness;
- Menu_AddItem( &m_player.menu, &m_player.name );
- Menu_AddItem( &m_player.menu, &m_player.model );
- Menu_AddItem( &m_player.menu, &m_player.skin );
- Menu_AddItem( &m_player.menu, &m_player.hand );
+ Menu_AddItem(&m_player.menu, &m_player.name);
+ Menu_AddItem(&m_player.menu, &m_player.model);
+ Menu_AddItem(&m_player.menu, &m_player.skin);
+ Menu_AddItem(&m_player.menu, &m_player.hand);
- List_Append( &ui_menus, &m_player.menu.entry );
+ List_Append(&ui_menus, &m_player.menu.entry);
}
diff --git a/src/ui_playermodels.c b/src/ui_playermodels.c
index 720324e..5184889 100644
--- a/src/ui_playermodels.c
+++ b/src/ui_playermodels.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -42,44 +42,47 @@ static const char *const baseWeaponNames[] = {
"w_sshotgun.md2"
};
-static const int numBaseWeaponNames = sizeof( baseWeaponNames ) / sizeof( baseWeaponNames[0] );
+static const int numBaseWeaponNames = sizeof(baseWeaponNames) / sizeof(baseWeaponNames[0]);
-static qboolean IconOfSkinExists( char *skin, char **pcxfiles, int npcxfiles ) {
+static qboolean IconOfSkinExists(char *skin, char **pcxfiles, int npcxfiles)
+{
int i;
char scratch[MAX_OSPATH];
- COM_StripExtension( skin, scratch, sizeof( scratch ) );
- Q_strlcat( scratch, "_i.pcx", sizeof( scratch ) );
+ COM_StripExtension(skin, scratch, sizeof(scratch));
+ Q_strlcat(scratch, "_i.pcx", sizeof(scratch));
- for( i = 0 ; i < npcxfiles ; i++ ) {
- if( strcmp( pcxfiles[i], scratch ) == 0 )
+ for (i = 0; i < npcxfiles; i++) {
+ if (strcmp(pcxfiles[i], scratch) == 0)
return qtrue;
}
return qfalse;
}
-static int QDECL pmicmpfnc( const void *_a, const void *_b ) {
+static int QDECL pmicmpfnc(const void *_a, const void *_b)
+{
const playerModelInfo_t *a = (const playerModelInfo_t *)_a;
const playerModelInfo_t *b = (const playerModelInfo_t *)_b;
/*
** sort by male, female, then alphabetical
*/
- if( strcmp( a->directory, "male" ) == 0 )
+ if (strcmp(a->directory, "male") == 0)
return -1;
- else if( strcmp( b->directory, "male" ) == 0 )
+ else if (strcmp(b->directory, "male") == 0)
return 1;
- if( strcmp( a->directory, "female" ) == 0 )
+ if (strcmp(a->directory, "female") == 0)
return -1;
- else if( strcmp( b->directory, "female" ) == 0 )
+ else if (strcmp(b->directory, "female") == 0)
return 1;
- return strcmp( a->directory, b->directory );
+ return strcmp(a->directory, b->directory);
}
-void PlayerModel_Load( void ) {
+void PlayerModel_Load(void)
+{
char scratch[MAX_QPATH];
int ndirs = 0;
char *dirnames[MAX_PLAYERMODELS];
@@ -94,35 +97,35 @@ void PlayerModel_Load( void ) {
/*
** get a list of directories
*/
- if( !( list = ( char ** )FS_ListFiles( NULL, "players/*/*", FS_SEARCH_BYFILTER|FS_SEARCH_SAVEPATH, &numFiles ) ) ) {
+ if (!(list = (char **)FS_ListFiles(NULL, "players/*/*", FS_SEARCH_BYFILTER | FS_SEARCH_SAVEPATH, &numFiles))) {
return;
}
- for( i = 0; i < numFiles; i++ ) {
- Q_strlcpy( scratch, list[i] + 8, sizeof( scratch ) );
- if( ( p = strchr( scratch, '/' ) ) ) {
+ for (i = 0; i < numFiles; i++) {
+ Q_strlcpy(scratch, list[i] + 8, sizeof(scratch));
+ if ((p = strchr(scratch, '/'))) {
*p = 0;
}
- for( j = 0; j < ndirs; j++ ) {
- if( !strcmp( dirnames[j], scratch ) ) {
+ for (j = 0; j < ndirs; j++) {
+ if (!strcmp(dirnames[j], scratch)) {
break;
}
}
- if( j != ndirs ) {
+ if (j != ndirs) {
continue;
}
-
- dirnames[ndirs++] = UI_CopyString( scratch );
- if( ndirs == MAX_PLAYERMODELS ) {
+
+ dirnames[ndirs++] = UI_CopyString(scratch);
+ if (ndirs == MAX_PLAYERMODELS) {
break;
}
}
- FS_FreeList( ( void ** )list );
+ FS_FreeList((void **)list);
- if( !ndirs ) {
+ if (!ndirs) {
return;
}
@@ -130,7 +133,7 @@ void PlayerModel_Load( void ) {
** go through the subdirectories
*/
- for( i = 0; i < ndirs; i++ ) {
+ for (i = 0; i < ndirs; i++) {
int k, s;
char **pcxnames;
char **skinnames;
@@ -140,67 +143,67 @@ void PlayerModel_Load( void ) {
char **weaponNames;
// verify the existence of tris.md2
- Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/tris.md2", NULL );
- if( !FS_FileExists( scratch ) ) {
+ Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], "/tris.md2", NULL);
+ if (!FS_FileExists(scratch)) {
continue;
}
// verify the existence of at least one pcx skin
- Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], NULL );
- pcxnames = ( char ** )FS_ListFiles( scratch, ".pcx", 0, &npcxfiles );
- if( !pcxnames ) {
+ Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], NULL);
+ pcxnames = (char **)FS_ListFiles(scratch, ".pcx", 0, &npcxfiles);
+ if (!pcxnames) {
continue;
}
// count valid skins, which consist of a skin with a matching "_i" icon
- for( k = 0; k < npcxfiles; k++ ) {
- if( !strstr( pcxnames[k], "_i.pcx" ) ) {
- if( IconOfSkinExists( pcxnames[k], pcxnames, npcxfiles ) ) {
+ for (k = 0; k < npcxfiles; k++) {
+ if (!strstr(pcxnames[k], "_i.pcx")) {
+ if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
nskins++;
}
}
}
- if( !nskins ) {
- FS_FreeList( ( void ** )pcxnames );
+ if (!nskins) {
+ FS_FreeList((void **)pcxnames);
continue;
}
- skinnames = UI_Malloc( sizeof( char * ) * ( nskins + 1 ) );
+ skinnames = UI_Malloc(sizeof(char *) * (nskins + 1));
skinnames[nskins] = NULL;
// copy the valid skins
- for( s = 0, k = 0; k < npcxfiles; k++ ) {
- if( !strstr( pcxnames[k], "_i.pcx" ) ) {
- if( IconOfSkinExists( pcxnames[k], pcxnames, npcxfiles ) ) {
- COM_StripExtension( pcxnames[k], scratch, sizeof( scratch ) );
- skinnames[s++] = UI_CopyString( scratch );
+ for (s = 0, k = 0; k < npcxfiles; k++) {
+ if (!strstr(pcxnames[k], "_i.pcx")) {
+ if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
+ COM_StripExtension(pcxnames[k], scratch, sizeof(scratch));
+ skinnames[s++] = UI_CopyString(scratch);
}
}
}
- FS_FreeList( ( void ** )pcxnames );
+ FS_FreeList((void **)pcxnames);
// load vweap models
- Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/w_*.md2", NULL );
- weaponNames = ( char ** )FS_ListFiles( NULL, scratch, FS_SEARCH_BYFILTER, &numWeapons );
+ Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], "/w_*.md2", NULL);
+ weaponNames = (char **)FS_ListFiles(NULL, scratch, FS_SEARCH_BYFILTER, &numWeapons);
pmi = &uis.pmi[uis.numPlayerModels++];
pmi->numWeapons = 0;
- if( weaponNames ) {
- pmi->weaponNames = UI_Malloc( sizeof( char * ) * numWeapons );
+ if (weaponNames) {
+ pmi->weaponNames = UI_Malloc(sizeof(char *) * numWeapons);
- for( j = 0; j < numWeapons ; j++ ) {
- for( k = 0; k < numBaseWeaponNames; k++ ) {
- if( !strcmp( weaponNames[j], baseWeaponNames[k] ) ) {
- pmi->weaponNames[pmi->numWeapons++] = UI_CopyString( weaponNames[j] );
+ for (j = 0; j < numWeapons; j++) {
+ for (k = 0; k < numBaseWeaponNames; k++) {
+ if (!strcmp(weaponNames[j], baseWeaponNames[k])) {
+ pmi->weaponNames[pmi->numWeapons++] = UI_CopyString(weaponNames[j]);
break;
}
}
}
- FS_FreeList( ( void ** )weaponNames );
+ FS_FreeList((void **)weaponNames);
}
// at this point we have a valid player model
@@ -208,38 +211,39 @@ void PlayerModel_Load( void ) {
pmi->skindisplaynames = skinnames;
// make short name for the model
- strcpy( pmi->directory, dirnames[i] );
+ strcpy(pmi->directory, dirnames[i]);
}
- for( i = 0; i < ndirs; i++ ) {
- Z_Free( dirnames[i] );
+ for (i = 0; i < ndirs; i++) {
+ Z_Free(dirnames[i]);
}
- qsort( uis.pmi, uis.numPlayerModels, sizeof( uis.pmi[0] ), pmicmpfnc );
+ qsort(uis.pmi, uis.numPlayerModels, sizeof(uis.pmi[0]), pmicmpfnc);
}
-void PlayerModel_Free( void ) {
+void PlayerModel_Free(void)
+{
playerModelInfo_t *pmi;
int i, j;
- for( i = 0, pmi = uis.pmi; i < uis.numPlayerModels; i++, pmi++ ) {
- if( pmi->skindisplaynames ) {
- for( j = 0; j < pmi->nskins; j++ ) {
- Z_Free( pmi->skindisplaynames[j] );
+ for (i = 0, pmi = uis.pmi; i < uis.numPlayerModels; i++, pmi++) {
+ if (pmi->skindisplaynames) {
+ for (j = 0; j < pmi->nskins; j++) {
+ Z_Free(pmi->skindisplaynames[j]);
}
- Z_Free( pmi->skindisplaynames );
+ Z_Free(pmi->skindisplaynames);
}
- if( pmi->weaponNames ) {
- for( j = 0; j < pmi->numWeapons; j++ ) {
- Z_Free( pmi->weaponNames[j] );
+ if (pmi->weaponNames) {
+ for (j = 0; j < pmi->numWeapons; j++) {
+ Z_Free(pmi->weaponNames[j]);
}
- Z_Free( pmi->weaponNames );
+ Z_Free(pmi->weaponNames);
}
- memset( pmi, 0, sizeof( *pmi ) );
+ memset(pmi, 0, sizeof(*pmi));
}
uis.numPlayerModels = 0;
}
-
+
diff --git a/src/ui_public.h b/src/ui_public.h
index 5c18af5..d5edf3a 100644
--- a/src/ui_public.h
+++ b/src/ui_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,14 +25,14 @@ typedef enum {
UIMENU_GAME
} uiMenu_t;
-qboolean UI_Init( void );
-void UI_Shutdown( void );
-void UI_ModeChanged( void );
-void UI_Keydown( int key );
-void UI_CharEvent( int key );
-void UI_Draw( int realtime );
-void UI_OpenMenu( uiMenu_t menu );
-void UI_AddToServerList( const serverStatus_t *status );
-void UI_MouseEvent( int x, int y );
-qboolean UI_IsTransparent( void );
+qboolean UI_Init(void);
+void UI_Shutdown(void);
+void UI_ModeChanged(void);
+void UI_Keydown(int key);
+void UI_CharEvent(int key);
+void UI_Draw(int realtime);
+void UI_OpenMenu(uiMenu_t menu);
+void UI_AddToServerList(const serverStatus_t *status);
+void UI_MouseEvent(int x, int y);
+qboolean UI_IsTransparent(void);
diff --git a/src/ui_script.c b/src/ui_script.c
index 486db51..c2306b2 100644
--- a/src/ui_script.c
+++ b/src/ui_script.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,103 +21,108 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ui_local.h"
#include "files.h"
-static menuSound_t Activate( menuCommon_t *self ) {
- if( self->type == MTYPE_ACTION ) {
- Cbuf_AddText( &cmd_buffer, (( menuAction_t * )self)->cmd );
- } else if( self->type == MTYPE_BITMAP ) {
- Cbuf_AddText( &cmd_buffer, (( menuBitmap_t * )self)->cmd );
+static menuSound_t Activate(menuCommon_t *self)
+{
+ if (self->type == MTYPE_ACTION) {
+ Cbuf_AddText(&cmd_buffer, ((menuAction_t *)self)->cmd);
+ } else if (self->type == MTYPE_BITMAP) {
+ Cbuf_AddText(&cmd_buffer, ((menuBitmap_t *)self)->cmd);
}
return QMS_NOTHANDLED;
}
#define CHECK_NITEMS \
- if( menu->nitems >= MAXMENUITEMS ) { \
- Com_Printf( "Too many items\n" ); \
+ if (menu->nitems >= MAXMENUITEMS) { \
+ Com_Printf("Too many items\n"); \
return; \
}
-static void Parse_Spin( menuFrameWork_t *menu, menuType_t type ) {
+static void Parse_Spin(menuFrameWork_t *menu, menuType_t type)
+{
menuSpinControl_t *s;
int numItems = Cmd_Argc() - 3;
int i;
- if( numItems < 1 ) {
- Com_Printf( "Usage: %s <name> <cvar> <desc1> [...]\n", Cmd_Argv( 0 ) );
+ if (numItems < 1) {
+ Com_Printf("Usage: %s <name> <cvar> <desc1> [...]\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- s = UI_Mallocz( sizeof( *s ) );
+ s = UI_Mallocz(sizeof(*s));
s->generic.type = type;
- s->generic.name = UI_CopyString( Cmd_Argv( 1 ) );
- s->cvar = Cvar_WeakGet( Cmd_Argv( 2 ) );
- s->itemnames = UI_Mallocz( sizeof( char * ) * ( numItems + 1 ) );
- for( i = 0; i < numItems; i++ ) {
- s->itemnames[i] = UI_CopyString( Cmd_Argv( 3 + i ) );
+ s->generic.name = UI_CopyString(Cmd_Argv(1));
+ s->cvar = Cvar_WeakGet(Cmd_Argv(2));
+ s->itemnames = UI_Mallocz(sizeof(char *) * (numItems + 1));
+ for (i = 0; i < numItems; i++) {
+ s->itemnames[i] = UI_CopyString(Cmd_Argv(3 + i));
}
s->numItems = numItems;
- Menu_AddItem( menu, s );
+ Menu_AddItem(menu, s);
}
-static void Parse_Pairs( menuFrameWork_t *menu ) {
+static void Parse_Pairs(menuFrameWork_t *menu)
+{
menuSpinControl_t *s;
int numItems = Cmd_Argc() - 3;
int i;
- if( numItems < 2 || ( numItems & 1 ) ) {
- Com_Printf( "Usage: %s <name> <cvar> <desc1> <value1> [...]\n", Cmd_Argv( 0 ) );
+ if (numItems < 2 || (numItems & 1)) {
+ Com_Printf("Usage: %s <name> <cvar> <desc1> <value1> [...]\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- s = UI_Mallocz( sizeof( *s ) );
+ s = UI_Mallocz(sizeof(*s));
s->generic.type = MTYPE_PAIRS;
- s->generic.name = UI_CopyString( Cmd_Argv( 1 ) );
- s->cvar = Cvar_WeakGet( Cmd_Argv( 2 ) );
+ s->generic.name = UI_CopyString(Cmd_Argv(1));
+ s->cvar = Cvar_WeakGet(Cmd_Argv(2));
numItems >>= 1;
- s->itemnames = UI_Mallocz( sizeof( char * ) * ( numItems + 1 ) );
- for( i = 0; i < numItems; i++ ) {
- s->itemnames[i] = UI_CopyString( Cmd_Argv( 3 + i*2 ) );
+ s->itemnames = UI_Mallocz(sizeof(char *) * (numItems + 1));
+ for (i = 0; i < numItems; i++) {
+ s->itemnames[i] = UI_CopyString(Cmd_Argv(3 + i * 2));
}
- s->itemvalues = UI_Mallocz( sizeof( char * ) * ( numItems + 1 ) );
- for( i = 0; i < numItems; i++ ) {
- s->itemvalues[i] = UI_CopyString( Cmd_Argv( 4 + i*2 ) );
+ s->itemvalues = UI_Mallocz(sizeof(char *) * (numItems + 1));
+ for (i = 0; i < numItems; i++) {
+ s->itemvalues[i] = UI_CopyString(Cmd_Argv(4 + i * 2));
}
s->numItems = numItems;
- Menu_AddItem( menu, s );
+ Menu_AddItem(menu, s);
}
-static void Parse_Range( menuFrameWork_t *menu ) {
+static void Parse_Range(menuFrameWork_t *menu)
+{
menuSlider_t *s;
- if( Cmd_Argc() < 5 ) {
- Com_Printf( "Usage: %s <name> <cvar> <min> <max> [step]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 5) {
+ Com_Printf("Usage: %s <name> <cvar> <min> <max> [step]\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- s = UI_Mallocz( sizeof( *s ) );
+ s = UI_Mallocz(sizeof(*s));
s->generic.type = MTYPE_SLIDER;
- s->generic.name = UI_CopyString( Cmd_Argv( 1 ) );
- s->cvar = Cvar_WeakGet( Cmd_Argv( 2 ) );
- s->minvalue = atof( Cmd_Argv( 3 ) );
- s->maxvalue = atof( Cmd_Argv( 4 ) );
- if( Cmd_Argc() > 5 ) {
- s->step = atof( Cmd_Argv( 5 ) );
+ s->generic.name = UI_CopyString(Cmd_Argv(1));
+ s->cvar = Cvar_WeakGet(Cmd_Argv(2));
+ s->minvalue = atof(Cmd_Argv(3));
+ s->maxvalue = atof(Cmd_Argv(4));
+ if (Cmd_Argc() > 5) {
+ s->step = atof(Cmd_Argv(5));
} else {
- s->step = ( s->maxvalue - s->minvalue ) / SLIDER_RANGE;
+ s->step = (s->maxvalue - s->minvalue) / SLIDER_RANGE;
}
- Menu_AddItem( menu, s );
+ Menu_AddItem(menu, s);
}
-static void Parse_Action( menuFrameWork_t *menu ) {
+static void Parse_Action(menuFrameWork_t *menu)
+{
static const cmd_option_t options[] = {
{ "a", "align" },
{ "s:", "status" },
@@ -128,10 +133,10 @@ static void Parse_Action( menuFrameWork_t *menu ) {
char *status = NULL;
int c;
- while( ( c = Cmd_ParseOptions( options ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(options)) != -1) {
+ switch (c) {
case 'a':
- uiFlags = UI_LEFT|UI_ALTCOLOR;
+ uiFlags = UI_LEFT | UI_ALTCOLOR;
break;
case 's':
status = cmd_optarg;
@@ -141,72 +146,75 @@ static void Parse_Action( menuFrameWork_t *menu ) {
}
}
- if( Cmd_Argc() - cmd_optind < 2 ) {
- Com_Printf( "Usage: %s <name> <command>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() - cmd_optind < 2) {
+ Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- a = UI_Mallocz( sizeof( *a ) );
+ a = UI_Mallocz(sizeof(*a));
a->generic.type = MTYPE_ACTION;
- a->generic.name = UI_CopyString( Cmd_Argv( cmd_optind ) );
+ a->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
a->generic.activate = Activate;
a->generic.uiFlags = uiFlags;
- a->generic.status = UI_CopyString( status );
- a->cmd = UI_CopyString( Cmd_ArgsFrom( cmd_optind + 1 ) );
+ a->generic.status = UI_CopyString(status);
+ a->cmd = UI_CopyString(Cmd_ArgsFrom(cmd_optind + 1));
- Menu_AddItem( menu, a );
+ Menu_AddItem(menu, a);
}
-static void Parse_Bitmap( menuFrameWork_t *menu ) {
+static void Parse_Bitmap(menuFrameWork_t *menu)
+{
char buffer[MAX_QPATH];
menuBitmap_t *b;
char *name;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <name> <command>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- b = UI_Mallocz( sizeof( *b ) );
+ b = UI_Mallocz(sizeof(*b));
b->generic.type = MTYPE_BITMAP;
b->generic.activate = Activate;
- b->cmd = UI_CopyString( Cmd_ArgsFrom( 2 ) );
+ b->cmd = UI_CopyString(Cmd_ArgsFrom(2));
- name = Cmd_Argv( 1 );
- b->pics[0] = R_RegisterPic( name );
+ name = Cmd_Argv(1);
+ b->pics[0] = R_RegisterPic(name);
- Q_snprintf( buffer, sizeof( buffer ), "%s_sel", name );
- b->pics[1] = R_RegisterPic( buffer );
+ Q_snprintf(buffer, sizeof(buffer), "%s_sel", name);
+ b->pics[1] = R_RegisterPic(buffer);
- R_GetPicSize( &b->generic.width, &b->generic.height, b->pics[0] );
+ R_GetPicSize(&b->generic.width, &b->generic.height, b->pics[0]);
- Menu_AddItem( menu, b );
+ Menu_AddItem(menu, b);
}
-static void Parse_Bind( menuFrameWork_t *menu ) {
+static void Parse_Bind(menuFrameWork_t *menu)
+{
menuKeybind_t *k;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <name> <command>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
return;
}
CHECK_NITEMS
- k = UI_Mallocz( sizeof( *k ) );
+ k = UI_Mallocz(sizeof(*k));
k->generic.type = MTYPE_KEYBIND;
- k->generic.name = UI_CopyString( Cmd_Argv( 1 ) );
+ k->generic.name = UI_CopyString(Cmd_Argv(1));
k->generic.uiFlags = UI_CENTER;
- k->cmd = UI_CopyString( Cmd_ArgsFrom( 2 ) );
+ k->cmd = UI_CopyString(Cmd_ArgsFrom(2));
- Menu_AddItem( menu, k );
+ Menu_AddItem(menu, k);
}
-static void Parse_Toggle( menuFrameWork_t *menu ) {
+static void Parse_Toggle(menuFrameWork_t *menu)
+{
static const char *yes_no_names[] = { "no", "yes", NULL };
menuSpinControl_t *s;
qboolean negate = qfalse;
@@ -214,20 +222,20 @@ static void Parse_Toggle( menuFrameWork_t *menu ) {
int bit = 0;
char *b;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <name> <cvar> [~][bit]\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <name> <cvar> [~][bit]\n", Cmd_Argv(0));
return;
}
- b = Cmd_Argv( 3 );
- if( *b == '~' ) {
+ b = Cmd_Argv(3);
+ if (*b == '~') {
negate = qtrue;
b++;
}
- if( *b ) {
- bit = atoi( b );
- if( bit < 0 || bit >= 32 ) {
- Com_Printf( "Invalid bit number: %d\n", bit );
+ if (*b) {
+ bit = atoi(b);
+ if (bit < 0 || bit >= 32) {
+ Com_Printf("Invalid bit number: %d\n", bit);
return;
}
type = MTYPE_BITFIELD;
@@ -235,19 +243,20 @@ static void Parse_Toggle( menuFrameWork_t *menu ) {
CHECK_NITEMS
- s = UI_Mallocz( sizeof( *s ) );
+ s = UI_Mallocz(sizeof(*s));
s->generic.type = type;
- s->generic.name = UI_CopyString( Cmd_Argv( 1 ) );
- s->cvar = Cvar_WeakGet( Cmd_Argv( 2 ) );
- s->itemnames = ( char ** )yes_no_names;
+ s->generic.name = UI_CopyString(Cmd_Argv(1));
+ s->cvar = Cvar_WeakGet(Cmd_Argv(2));
+ s->itemnames = (char **)yes_no_names;
s->numItems = 2;
s->negate = negate;
s->mask = 1 << bit;
- Menu_AddItem( menu, s );
+ Menu_AddItem(menu, s);
}
-static void Parse_Field( menuFrameWork_t *menu ) {
+static void Parse_Field(menuFrameWork_t *menu)
+{
static const cmd_option_t o_field[] = {
{ "c", "center" },
{ "i", "integer" },
@@ -262,8 +271,8 @@ static void Parse_Field( menuFrameWork_t *menu ) {
int width = 16;
int c;
- while( ( c = Cmd_ParseOptions( o_field ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_field)) != -1) {
+ switch (c) {
case 'c':
center = qtrue;
break;
@@ -274,9 +283,9 @@ static void Parse_Field( menuFrameWork_t *menu ) {
status = cmd_optarg;
break;
case 'w':
- width = atoi( cmd_optarg );
- if( width < 1 || width > 32 ) {
- Com_Printf( "Invalid width\n" );
+ width = atoi(cmd_optarg);
+ if (width < 1 || width > 32) {
+ Com_Printf("Invalid width\n");
return;
}
break;
@@ -287,247 +296,254 @@ static void Parse_Field( menuFrameWork_t *menu ) {
CHECK_NITEMS
- f = UI_Mallocz( sizeof( *f ) );
+ f = UI_Mallocz(sizeof(*f));
f->generic.type = MTYPE_FIELD;
- f->generic.name = center ? NULL : UI_CopyString( Cmd_Argv( cmd_optind ) );
- f->generic.status = UI_CopyString( status );
+ f->generic.name = center ? NULL : UI_CopyString(Cmd_Argv(cmd_optind));
+ f->generic.status = UI_CopyString(status);
f->generic.flags = flags;
- f->cvar = Cvar_WeakGet( Cmd_Argv( center ? cmd_optind : cmd_optind + 1 ) );
+ f->cvar = Cvar_WeakGet(Cmd_Argv(center ? cmd_optind : cmd_optind + 1));
f->width = width;
- Menu_AddItem( menu, f );
+ Menu_AddItem(menu, f);
}
-static void Parse_Blank( menuFrameWork_t *menu ) {
+static void Parse_Blank(menuFrameWork_t *menu)
+{
menuSeparator_t *s;
CHECK_NITEMS
- s = UI_Mallocz( sizeof( *s ) );
+ s = UI_Mallocz(sizeof(*s));
s->generic.type = MTYPE_SEPARATOR;
- Menu_AddItem( menu, s );
+ Menu_AddItem(menu, s);
}
-static void Parse_Background( menuFrameWork_t *menu ) {
- char *s = Cmd_Argv( 1 );
+static void Parse_Background(menuFrameWork_t *menu)
+{
+ char *s = Cmd_Argv(1);
- if( SCR_ParseColor( s, &menu->color ) ) {
+ if (SCR_ParseColor(s, &menu->color)) {
menu->image = 0;
- if( menu->color.u8[3] != 255 ) {
+ if (menu->color.u8[3] != 255) {
menu->transparent = qtrue;
}
} else {
- menu->image = R_RegisterPic( s );
- menu->transparent = R_GetPicSize( NULL, NULL, menu->image );
+ menu->image = R_RegisterPic(s);
+ menu->transparent = R_GetPicSize(NULL, NULL, menu->image);
}
}
-static void Parse_Color( void ) {
+static void Parse_Color(void)
+{
char *s, *c;
- if( Cmd_Argc() < 3 ) {
- Com_Printf( "Usage: %s <state> <color>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 3) {
+ Com_Printf("Usage: %s <state> <color>\n", Cmd_Argv(0));
return;
}
- s = Cmd_Argv( 1 );
- c = Cmd_Argv( 2 );
-
- if( !strcmp( s, "normal" ) ) {
- SCR_ParseColor( c, &uis.color.normal );
- } else if( !strcmp( s, "active" ) ) {
- SCR_ParseColor( c, &uis.color.active );
- } else if( !strcmp( s, "selection" ) ) {
- SCR_ParseColor( c, &uis.color.selection );
- } else if( !strcmp( s, "disabled" ) ) {
- SCR_ParseColor( c, &uis.color.disabled );
+ s = Cmd_Argv(1);
+ c = Cmd_Argv(2);
+
+ if (!strcmp(s, "normal")) {
+ SCR_ParseColor(c, &uis.color.normal);
+ } else if (!strcmp(s, "active")) {
+ SCR_ParseColor(c, &uis.color.active);
+ } else if (!strcmp(s, "selection")) {
+ SCR_ParseColor(c, &uis.color.selection);
+ } else if (!strcmp(s, "disabled")) {
+ SCR_ParseColor(c, &uis.color.disabled);
} else {
- Com_Printf( "Unknown state '%s'\n", s );
+ Com_Printf("Unknown state '%s'\n", s);
}
}
-static void Parse_Plaque( menuFrameWork_t *menu ) {
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <plaque> [logo]\n", Cmd_Argv( 0 ) );
+static void Parse_Plaque(menuFrameWork_t *menu)
+{
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <plaque> [logo]\n", Cmd_Argv(0));
return;
}
- menu->plaque = R_RegisterPic( Cmd_Argv( 1 ) );
- if( menu->plaque ) {
- R_GetPicSize( &menu->plaque_rc.width,
- &menu->plaque_rc.height, menu->plaque );
+ menu->plaque = R_RegisterPic(Cmd_Argv(1));
+ if (menu->plaque) {
+ R_GetPicSize(&menu->plaque_rc.width,
+ &menu->plaque_rc.height, menu->plaque);
}
- if( Cmd_Argc() > 2 ) {
- menu->logo = R_RegisterPic( Cmd_Argv( 2 ) );
- if( menu->logo ) {
- R_GetPicSize( &menu->logo_rc.width,
- &menu->logo_rc.height, menu->logo );
+ if (Cmd_Argc() > 2) {
+ menu->logo = R_RegisterPic(Cmd_Argv(2));
+ if (menu->logo) {
+ R_GetPicSize(&menu->logo_rc.width,
+ &menu->logo_rc.height, menu->logo);
}
}
}
-static void Parse_Banner( menuFrameWork_t *menu ) {
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <banner>\n", Cmd_Argv( 0 ) );
+static void Parse_Banner(menuFrameWork_t *menu)
+{
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <banner>\n", Cmd_Argv(0));
return;
}
- menu->banner = R_RegisterPic( Cmd_Argv( 1 ) );
- if( menu->banner ) {
- R_GetPicSize( &menu->banner_rc.width,
- &menu->banner_rc.height, menu->banner );
+ menu->banner = R_RegisterPic(Cmd_Argv(1));
+ if (menu->banner) {
+ R_GetPicSize(&menu->banner_rc.width,
+ &menu->banner_rc.height, menu->banner);
}
}
-static qboolean Parse_File( const char *path, int depth ) {
+static qboolean Parse_File(const char *path, int depth)
+{
char *raw, *data, *p, *cmd;
int argc;
menuFrameWork_t *menu = NULL;
qerror_t ret;
- ret = FS_LoadFile( path, ( void ** )&raw );
- if( !raw ) {
- if( ret != Q_ERR_NOENT || depth ) {
- Com_WPrintf( "Couldn't %s %s: %s\n", depth ? "include" : "load",
- path, Q_ErrorString( ret ) );
+ ret = FS_LoadFile(path, (void **)&raw);
+ if (!raw) {
+ if (ret != Q_ERR_NOENT || depth) {
+ Com_WPrintf("Couldn't %s %s: %s\n", depth ? "include" : "load",
+ path, Q_ErrorString(ret));
}
return qfalse;
}
data = raw;
- COM_Compress( data );
+ COM_Compress(data);
- while( *data ) {
- p = strchr( data, '\n' );
- if( p ) {
+ while (*data) {
+ p = strchr(data, '\n');
+ if (p) {
*p = 0;
}
- Cmd_TokenizeString( data, qtrue );
+ Cmd_TokenizeString(data, qtrue);
argc = Cmd_Argc();
- if( argc ) {
- cmd = Cmd_Argv( 0 );
- if( menu ) {
- if( !strcmp( cmd, "end" ) ) {
- if( menu->nitems ) {
- List_Append( &ui_menus, &menu->entry );
+ if (argc) {
+ cmd = Cmd_Argv(0);
+ if (menu) {
+ if (!strcmp(cmd, "end")) {
+ if (menu->nitems) {
+ List_Append(&ui_menus, &menu->entry);
} else {
- Com_WPrintf( "Menu entry without items\n" );
- menu->free( menu );
+ Com_WPrintf("Menu entry without items\n");
+ menu->free(menu);
}
menu = NULL;
- } else if( !strcmp( cmd, "title" ) ) {
- if( menu->title ) {
- Z_Free( menu->title );
+ } else if (!strcmp(cmd, "title")) {
+ if (menu->title) {
+ Z_Free(menu->title);
}
- menu->title = UI_CopyString( Cmd_Argv( 1 ) );
- } else if( !strcmp( cmd, "plaque" ) ) {
- Parse_Plaque( menu );
- } else if( !strcmp( cmd, "banner" ) ) {
- Parse_Banner( menu );
- } else if( !strcmp( cmd, "background" ) ) {
- Parse_Background( menu );
- } else if( !strcmp( cmd, "values" ) ) {
- Parse_Spin( menu, MTYPE_SPINCONTROL );
- } else if( !strcmp( cmd, "strings" ) ) {
- Parse_Spin( menu, MTYPE_STRINGS );
- } else if( !strcmp( cmd, "pairs" ) ) {
- Parse_Pairs( menu );
- } else if( !strcmp( cmd, "range" ) ) {
- Parse_Range( menu );
- } else if( !strcmp( cmd, "action" ) ) {
- Parse_Action( menu );
- } else if( !strcmp( cmd, "bitmap" ) ) {
- Parse_Bitmap( menu );
- } else if( !strcmp( cmd, "bind" ) ) {
- Parse_Bind( menu );
- } else if( !strcmp( cmd, "toggle" ) ) {
- Parse_Toggle( menu );
- } else if( !strcmp( cmd, "field" ) ) {
- Parse_Field( menu );
- } else if( !strcmp( cmd, "blank" ) ) {
- Parse_Blank( menu );
+ menu->title = UI_CopyString(Cmd_Argv(1));
+ } else if (!strcmp(cmd, "plaque")) {
+ Parse_Plaque(menu);
+ } else if (!strcmp(cmd, "banner")) {
+ Parse_Banner(menu);
+ } else if (!strcmp(cmd, "background")) {
+ Parse_Background(menu);
+ } else if (!strcmp(cmd, "values")) {
+ Parse_Spin(menu, MTYPE_SPINCONTROL);
+ } else if (!strcmp(cmd, "strings")) {
+ Parse_Spin(menu, MTYPE_STRINGS);
+ } else if (!strcmp(cmd, "pairs")) {
+ Parse_Pairs(menu);
+ } else if (!strcmp(cmd, "range")) {
+ Parse_Range(menu);
+ } else if (!strcmp(cmd, "action")) {
+ Parse_Action(menu);
+ } else if (!strcmp(cmd, "bitmap")) {
+ Parse_Bitmap(menu);
+ } else if (!strcmp(cmd, "bind")) {
+ Parse_Bind(menu);
+ } else if (!strcmp(cmd, "toggle")) {
+ Parse_Toggle(menu);
+ } else if (!strcmp(cmd, "field")) {
+ Parse_Field(menu);
+ } else if (!strcmp(cmd, "blank")) {
+ Parse_Blank(menu);
} else {
- Com_WPrintf( "Unknown keyword '%s'\n", cmd );
+ Com_WPrintf("Unknown keyword '%s'\n", cmd);
}
} else {
- if( !strcmp( cmd, "begin" ) ) {
- char *s = Cmd_Argv( 1 );
- if( !*s ) {
- Com_WPrintf( "Expected menu name after '%s'\n", cmd );
+ if (!strcmp(cmd, "begin")) {
+ char *s = Cmd_Argv(1);
+ if (!*s) {
+ Com_WPrintf("Expected menu name after '%s'\n", cmd);
break;
}
- menu = UI_FindMenu( s );
- if( menu ) {
- if( menu->free ) {
- menu->free( menu );
+ menu = UI_FindMenu(s);
+ if (menu) {
+ if (menu->free) {
+ menu->free(menu);
}
- List_Remove( &menu->entry );
+ List_Remove(&menu->entry);
}
- menu = UI_Mallocz( sizeof( *menu ) );
- menu->name = UI_CopyString( s );
+ menu = UI_Mallocz(sizeof(*menu));
+ menu->name = UI_CopyString(s);
menu->push = Menu_Push;
menu->pop = Menu_Pop;
menu->free = Menu_Free;
menu->image = uis.backgroundHandle;
menu->color.u32 = uis.color.background.u32;
- } else if( !strcmp( cmd, "include" ) ) {
- char *s = Cmd_Argv( 1 );
- if( !*s ) {
- Com_WPrintf( "Expected file name after '%s'\n", cmd );
+ } else if (!strcmp(cmd, "include")) {
+ char *s = Cmd_Argv(1);
+ if (!*s) {
+ Com_WPrintf("Expected file name after '%s'\n", cmd);
break;
}
- if( depth == 16 ) {
- Com_WPrintf( "Includes too deeply nested\n" );
+ if (depth == 16) {
+ Com_WPrintf("Includes too deeply nested\n");
} else {
- Parse_File( s, depth + 1 );
+ Parse_File(s, depth + 1);
}
- } else if( !strcmp( cmd, "color" ) ) {
+ } else if (!strcmp(cmd, "color")) {
Parse_Color();
- } else if( !strcmp( cmd, "background" ) ) {
- char *s = Cmd_Argv( 1 );
+ } else if (!strcmp(cmd, "background")) {
+ char *s = Cmd_Argv(1);
- if( SCR_ParseColor( s, &uis.color.background ) ) {
+ if (SCR_ParseColor(s, &uis.color.background)) {
uis.backgroundHandle = 0;
} else {
- uis.backgroundHandle = R_RegisterPic( s );
+ uis.backgroundHandle = R_RegisterPic(s);
}
- } else if( !strcmp( cmd, "font" ) ) {
- uis.fontHandle = R_RegisterFont( Cmd_Argv( 1 ) );
- } else if( !strcmp( cmd, "cursor" ) ) {
- uis.cursorHandle = R_RegisterPic( Cmd_Argv( 1 ) );
- R_GetPicSize( &uis.cursorWidth,
- &uis.cursorHeight, uis.cursorHandle );
- } else if( !strcmp( cmd, "weapon" ) ) {
- Cmd_ArgvBuffer( 1, uis.weaponModel, sizeof( uis.weaponModel ) );
+ } else if (!strcmp(cmd, "font")) {
+ uis.fontHandle = R_RegisterFont(Cmd_Argv(1));
+ } else if (!strcmp(cmd, "cursor")) {
+ uis.cursorHandle = R_RegisterPic(Cmd_Argv(1));
+ R_GetPicSize(&uis.cursorWidth,
+ &uis.cursorHeight, uis.cursorHandle);
+ } else if (!strcmp(cmd, "weapon")) {
+ Cmd_ArgvBuffer(1, uis.weaponModel, sizeof(uis.weaponModel));
} else {
- Com_WPrintf( "Unknown keyword '%s'\n", cmd );
+ Com_WPrintf("Unknown keyword '%s'\n", cmd);
break;
}
}
}
- if( !p ) {
+ if (!p) {
break;
}
data = p + 1;
}
- FS_FreeFile( raw );
+ FS_FreeFile(raw);
- if( menu ) {
- Com_WPrintf( "Menu entry without 'end' terminator\n" );
- menu->free( menu );
+ if (menu) {
+ Com_WPrintf("Menu entry without 'end' terminator\n");
+ menu->free(menu);
}
return qtrue;
}
-void UI_LoadScript( void ) {
- Parse_File( "q2pro.menu", 0 );
+void UI_LoadScript(void)
+{
+ Parse_File("q2pro.menu", 0);
}
diff --git a/src/vid_local.h b/src/vid_local.h
index 3e8c4d4..c927186 100644
--- a/src/vid_local.h
+++ b/src/vid_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -27,14 +27,14 @@ extern cvar_t *_vid_fullscreen;
//
// vid_*.c
//
-void VID_PumpEvents( void );
-void VID_SetMode( void );
-char *VID_GetDefaultModeList( void );
+void VID_PumpEvents(void);
+void VID_SetMode(void);
+char *VID_GetDefaultModeList(void);
//
// cl_ref.c
//
-qboolean VID_GetFullscreen( vrect_t *rc, int *freq_p, int *depth_p );
-qboolean VID_GetGeometry( vrect_t *rc );
-void VID_SetGeometry( vrect_t *rc );
-void VID_ToggleFullscreen( void );
+qboolean VID_GetFullscreen(vrect_t *rc, int *freq_p, int *depth_p);
+qboolean VID_GetGeometry(vrect_t *rc);
+void VID_SetGeometry(vrect_t *rc);
+void VID_ToggleFullscreen(void);
diff --git a/src/vid_public.h b/src/vid_public.h
index eb5fc1c..73889d2 100644
--- a/src/vid_public.h
+++ b/src/vid_public.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -20,19 +20,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// vid_public.h -- interface to the host window system
-qboolean VID_Init( void );
-void VID_Shutdown( void );
-void VID_FatalShutdown( void );
+qboolean VID_Init(void);
+void VID_Shutdown(void);
+void VID_FatalShutdown(void);
-void VID_UpdateGamma( const byte *table );
-void VID_UpdatePalette( const byte *palette );
-void *VID_GetProcAddr( const char *symbol );
+void VID_UpdateGamma(const byte *table);
+void VID_UpdatePalette(const byte *palette);
+void *VID_GetProcAddr(const char *symbol);
-qboolean VID_VideoSync( void );
-void VID_VideoWait( void );
+qboolean VID_VideoSync(void);
+void VID_VideoWait(void);
-void VID_BeginFrame( void );
-void VID_EndFrame( void );
+void VID_BeginFrame(void);
+void VID_EndFrame(void);
-char *VID_GetClipboardData( void );
-void VID_SetClipboardData( const char *data );
+char *VID_GetClipboardData(void);
+void VID_SetClipboardData(const char *data);
diff --git a/src/vid_sdl.c b/src/vid_sdl.c
index aa37966..840fd89 100644
--- a/src/vid_sdl.c
+++ b/src/vid_sdl.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -37,7 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#if USE_REF == REF_GL
#include <GL/glx.h>
#include <GL/glxext.h>
-typedef const char *(*PFNGLXQUERYEXTENSIONSSTRING)( Display *, int );
+typedef const char *(*PFNGLXQUERYEXTENSIONSSTRING)(Display *, int);
#endif
#endif
@@ -73,19 +73,20 @@ COMMON SDL VIDEO RELATED ROUTINES
*/
#if USE_REF == REF_GL
-static void init_opengl( void );
+static void init_opengl(void);
#endif
#if USE_X11
-static void init_x11( void ) {
+static void init_x11(void)
+{
SDL_SysWMinfo info;
- SDL_VERSION( &info.version );
- if( !SDL_GetWMInfo( &info ) ) {
+ SDL_VERSION(&info.version);
+ if (!SDL_GetWMInfo(&info)) {
return;
}
- if( info.subsystem != SDL_SYSWM_X11 ) {
+ if (info.subsystem != SDL_SYSWM_X11) {
return;
}
@@ -93,21 +94,22 @@ static void init_x11( void ) {
sdl.win = info.info.x11.window;
}
-static void set_wm_hints( void ) {
+static void set_wm_hints(void)
+{
XSizeHints hints;
- if( !sdl.dpy ) {
+ if (!sdl.dpy) {
return;
}
- memset( &hints, 0, sizeof( hints ) );
- hints.flags = PMinSize|PResizeInc;
+ memset(&hints, 0, sizeof(hints));
+ hints.flags = PMinSize | PResizeInc;
hints.min_width = 64;
hints.min_height = 64;
hints.width_inc = 8;
hints.height_inc = 2;
- XSetWMSizeHints( sdl.dpy, sdl.win, &hints, XA_WM_SIZE_HINTS );
+ XSetWMSizeHints(sdl.dpy, sdl.win, &hints, XA_WM_SIZE_HINTS);
}
#endif
@@ -116,7 +118,8 @@ static void set_wm_hints( void ) {
VID_GetClipboardData
=================
*/
-char *VID_GetClipboardData( void ) {
+char *VID_GetClipboardData(void)
+{
#if USE_X11
Window sowner;
Atom type, property;
@@ -125,38 +128,38 @@ char *VID_GetClipboardData( void ) {
int format, result;
char *ret;
- if( !sdl.dpy ) {
+ if (!sdl.dpy) {
return NULL;
}
- sowner = XGetSelectionOwner( sdl.dpy, XA_PRIMARY );
- if( sowner == None ) {
+ sowner = XGetSelectionOwner(sdl.dpy, XA_PRIMARY);
+ if (sowner == None) {
return NULL;
}
- property = XInternAtom( sdl.dpy, "GETCLIPBOARDDATA_PROP", False );
-
- XConvertSelection( sdl.dpy, XA_PRIMARY, XA_STRING, property, sdl.win, CurrentTime );
-
- XSync( sdl.dpy, False );
-
- result = XGetWindowProperty( sdl.dpy, sdl.win, property, 0, 0, False,
- AnyPropertyType, &type, &format, &len, &bytes_left, &data );
-
- if( result != Success ) {
+ property = XInternAtom(sdl.dpy, "GETCLIPBOARDDATA_PROP", False);
+
+ XConvertSelection(sdl.dpy, XA_PRIMARY, XA_STRING, property, sdl.win, CurrentTime);
+
+ XSync(sdl.dpy, False);
+
+ result = XGetWindowProperty(sdl.dpy, sdl.win, property, 0, 0, False,
+ AnyPropertyType, &type, &format, &len, &bytes_left, &data);
+
+ if (result != Success) {
return NULL;
}
ret = NULL;
- if( bytes_left ) {
- result = XGetWindowProperty( sdl.dpy, sdl.win, property, 0, bytes_left, True,
- AnyPropertyType, &type, &format, &len, &bytes_left, &data );
- if( result == Success ) {
- ret = Z_CopyString( ( char * )data );
+ if (bytes_left) {
+ result = XGetWindowProperty(sdl.dpy, sdl.win, property, 0, bytes_left, True,
+ AnyPropertyType, &type, &format, &len, &bytes_left, &data);
+ if (result == Success) {
+ ret = Z_CopyString((char *)data);
}
}
- XFree( data );
+ XFree(data);
return ret;
#else
@@ -169,45 +172,47 @@ char *VID_GetClipboardData( void ) {
VID_SetClipboardData
=================
*/
-void VID_SetClipboardData( const char *data ) {
+void VID_SetClipboardData(const char *data)
+{
}
-static qboolean set_video_mode( int flags, int forcedepth ) {
+static qboolean set_video_mode(int flags, int forcedepth)
+{
SDL_Surface *surf;
vrect_t rc;
int depth;
- flags &= ~(SDL_FULLSCREEN|SDL_RESIZABLE);
+ flags &= ~(SDL_FULLSCREEN | SDL_RESIZABLE);
sdl.flags &= ~QVF_FULLSCREEN;
- if( vid_fullscreen->integer > 0 ) {
- VID_GetFullscreen( &rc, NULL, &depth );
- if( forcedepth ) {
+ if (vid_fullscreen->integer > 0) {
+ VID_GetFullscreen(&rc, NULL, &depth);
+ if (forcedepth) {
depth = forcedepth;
}
- Com_DPrintf( "...setting fullscreen mode: %dx%d:%d\n",
- rc.width, rc.height, depth );
- surf = SDL_SetVideoMode( rc.width, rc.height, depth,
- flags | SDL_FULLSCREEN );
- if( surf ) {
+ Com_DPrintf("...setting fullscreen mode: %dx%d:%d\n",
+ rc.width, rc.height, depth);
+ surf = SDL_SetVideoMode(rc.width, rc.height, depth,
+ flags | SDL_FULLSCREEN);
+ if (surf) {
sdl.flags |= QVF_FULLSCREEN;
goto success;
}
- Com_EPrintf( "Fullscreen video mode failed: %s\n", SDL_GetError() );
- Cvar_Set( "vid_fullscreen", "0" );
+ Com_EPrintf("Fullscreen video mode failed: %s\n", SDL_GetError());
+ Cvar_Set("vid_fullscreen", "0");
}
flags |= SDL_RESIZABLE;
- VID_GetGeometry( &rc );
- Com_DPrintf( "...setting windowed mode: %dx%d\n", rc.width, rc.height );
- surf = SDL_SetVideoMode( rc.width, rc.height, forcedepth, flags );
- if( !surf ) {
+ VID_GetGeometry(&rc);
+ Com_DPrintf("...setting windowed mode: %dx%d\n", rc.width, rc.height);
+ surf = SDL_SetVideoMode(rc.width, rc.height, forcedepth, flags);
+ if (!surf) {
return qfalse;
}
success:
// init some stuff for the first time
- if( sdl.surface != surf ) {
+ if (sdl.surface != surf) {
sdl.surface = surf;
#if USE_X11
init_x11();
@@ -217,12 +222,13 @@ success:
init_opengl();
#endif
}
- R_ModeChanged( rc.width, rc.height, sdl.flags, surf->pitch, surf->pixels );
+ R_ModeChanged(rc.width, rc.height, sdl.flags, surf->pitch, surf->pixels);
SCR_ModeChanged();
return qtrue;
}
-char *VID_GetDefaultModeList( void ) {
+char *VID_GetDefaultModeList(void)
+{
return Z_CopyString(VID_MODELIST);
}
@@ -231,117 +237,122 @@ char *VID_GetDefaultModeList( void ) {
VID_SetMode
============
*/
-void VID_SetMode( void ) {
- if( !set_video_mode( sdl.surface->flags, sdl.surface->format->BitsPerPixel ) ) {
- Com_Error( ERR_FATAL, "Couldn't change video mode: %s", SDL_GetError() );
+void VID_SetMode(void)
+{
+ if (!set_video_mode(sdl.surface->flags, sdl.surface->format->BitsPerPixel)) {
+ Com_Error(ERR_FATAL, "Couldn't change video mode: %s", SDL_GetError());
}
}
-void VID_FatalShutdown( void ) {
- SDL_ShowCursor( SDL_ENABLE );
- SDL_WM_GrabInput( SDL_GRAB_OFF );
+void VID_FatalShutdown(void)
+{
+ SDL_ShowCursor(SDL_ENABLE);
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
SDL_Quit();
}
-static qboolean init_video( void ) {
+static qboolean init_video(void)
+{
SDL_Color color;
byte *dst;
char buffer[MAX_QPATH];
int i, ret;
cvar_t *vid_hwgamma;
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 ) {
- ret = SDL_Init( SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE );
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
} else {
- ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
+ ret = SDL_InitSubSystem(SDL_INIT_VIDEO);
}
- if( ret == -1 ) {
- Com_EPrintf( "Couldn't initialize SDL video: %s\n", SDL_GetError() );
+ if (ret == -1) {
+ Com_EPrintf("Couldn't initialize SDL video: %s\n", SDL_GetError());
return qfalse;
}
- if( SDL_VideoDriverName( buffer, sizeof( buffer ) ) != NULL ) {
- Com_Printf( "Using SDL video driver: %s\n", buffer );
+ if (SDL_VideoDriverName(buffer, sizeof(buffer)) != NULL) {
+ Com_Printf("Using SDL video driver: %s\n", buffer);
}
- sdl.icon = SDL_CreateRGBSurface( SDL_SWSURFACE, q2icon_width,
- q2icon_height, 8, 0, 0, 0, 0 );
- if( sdl.icon ) {
- SDL_SetColorKey( sdl.icon, SDL_SRCCOLORKEY, 0 );
+ sdl.icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width,
+ q2icon_height, 8, 0, 0, 0, 0);
+ if (sdl.icon) {
+ SDL_SetColorKey(sdl.icon, SDL_SRCCOLORKEY, 0);
// transparent pixel
color.r = 255; color.g = 255; color.b = 255;
- SDL_SetColors( sdl.icon, &color, 0, 1 );
+ SDL_SetColors(sdl.icon, &color, 0, 1);
// colored pixel
color.r = 0; color.g = 128; color.b = 128;
- SDL_SetColors( sdl.icon, &color, 1, 1 );
+ SDL_SetColors(sdl.icon, &color, 1, 1);
// expand the bitmap
dst = sdl.icon->pixels;
- for( i = 0; i < q2icon_width * q2icon_height; i++ ) {
- *dst++ = Q_IsBitSet( q2icon_bits, i );
+ for (i = 0; i < q2icon_width * q2icon_height; i++) {
+ *dst++ = Q_IsBitSet(q2icon_bits, i);
}
- SDL_WM_SetIcon( sdl.icon, NULL );
+ SDL_WM_SetIcon(sdl.icon, NULL);
}
- vid_hwgamma = Cvar_Get( "vid_hwgamma", "0", CVAR_REFRESH );
+ vid_hwgamma = Cvar_Get("vid_hwgamma", "0", CVAR_REFRESH);
- if( vid_hwgamma->integer ) {
- if( SDL_GetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] ) != -1 &&
- SDL_SetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] ) != -1 )
- {
- Com_Printf( "...enabling hardware gamma\n" );
+ if (vid_hwgamma->integer) {
+ if (SDL_GetGammaRamp(sdl.gamma[0], sdl.gamma[1], sdl.gamma[2]) != -1 &&
+ SDL_SetGammaRamp(sdl.gamma[0], sdl.gamma[1], sdl.gamma[2]) != -1) {
+ Com_Printf("...enabling hardware gamma\n");
sdl.flags |= QVF_GAMMARAMP;
} else {
- Com_Printf( "...hardware gamma not supported\n" );
- Cvar_Reset( vid_hwgamma );
+ Com_Printf("...hardware gamma not supported\n");
+ Cvar_Reset(vid_hwgamma);
}
}
- SDL_WM_SetCaption( PRODUCT, APPLICATION );
+ SDL_WM_SetCaption(PRODUCT, APPLICATION);
- SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
return qtrue;
}
-void VID_Shutdown( void ) {
- if( sdl.flags & QVF_GAMMARAMP ) {
- SDL_SetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] );
+void VID_Shutdown(void)
+{
+ if (sdl.flags & QVF_GAMMARAMP) {
+ SDL_SetGammaRamp(sdl.gamma[0], sdl.gamma[1], sdl.gamma[2]);
}
- if( sdl.icon ) {
- SDL_FreeSurface( sdl.icon );
+ if (sdl.icon) {
+ SDL_FreeSurface(sdl.icon);
}
- memset( &sdl, 0, sizeof( sdl ) );
+ memset(&sdl, 0, sizeof(sdl));
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_VIDEO ) {
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO) {
SDL_Quit();
} else {
- SDL_QuitSubSystem( SDL_INIT_VIDEO );
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
}
-void VID_UpdateGamma( const byte *table ) {
+void VID_UpdateGamma(const byte *table)
+{
Uint16 ramp[256];
int i;
- if( sdl.flags & QVF_GAMMARAMP ) {
- for( i = 0; i < 256; i++ ) {
+ if (sdl.flags & QVF_GAMMARAMP) {
+ for (i = 0; i < 256; i++) {
ramp[i] = table[i] << 8;
}
- SDL_SetGammaRamp( ramp, ramp, ramp );
+ SDL_SetGammaRamp(ramp, ramp, ramp);
}
}
-static void activate_event( void ) {
+static void activate_event(void)
+{
int state = SDL_GetAppState();
active_t active;
- if( state & SDL_APPACTIVE ) {
- if( state & (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) ) {
+ if (state & SDL_APPACTIVE) {
+ if (state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) {
active = ACT_ACTIVATED;
} else {
active = ACT_RESTORED;
@@ -350,125 +361,128 @@ static void activate_event( void ) {
active = ACT_MINIMIZED;
}
- CL_Activate( active );
+ CL_Activate(active);
}
-static void key_event( SDL_keysym *keysym, qboolean down ) {
+static void key_event(SDL_keysym *keysym, qboolean down)
+{
unsigned key1, key2 = 0;
- if( keysym->sym <= 127 ) {
+ if (keysym->sym <= 127) {
// ASCII chars are mapped directly
- Key_Event( keysym->sym, down, com_eventTime );
+ Key_Event(keysym->sym, down, com_eventTime);
return;
}
-#define K( s, d ) case SDLK_ ## s: key1 = K_ ## d; break;
-#define KK( s, d1, d2 ) case SDLK_ ## s: key1 = K_ ## d1; key2 = K_ ## d2; break;
-
- switch( keysym->sym ) {
- K( KP0, KP_INS )
- K( KP1, KP_END )
- K( KP2, KP_DOWNARROW )
- K( KP3, KP_PGDN )
- K( KP4, KP_LEFTARROW )
- K( KP5, KP_5 )
- K( KP6, KP_RIGHTARROW )
- K( KP7, KP_HOME )
- K( KP8, KP_UPARROW )
- K( KP9, KP_PGUP )
- K( KP_PERIOD, KP_DEL )
- K( KP_DIVIDE, KP_SLASH )
- K( KP_MULTIPLY, KP_MULTIPLY )
- K( KP_MINUS, KP_MINUS )
- K( KP_PLUS, KP_PLUS )
- K( KP_ENTER, KP_ENTER )
-
- K( UP, UPARROW )
- K( DOWN, DOWNARROW )
- K( RIGHT, RIGHTARROW )
- K( LEFT, LEFTARROW )
- K( INSERT, INS )
- K( HOME, HOME )
- K( END, END )
- K( PAGEUP, PGUP )
- K( PAGEDOWN, PGDN )
-
- K( F1, F1 )
- K( F2, F2 )
- K( F3, F3 )
- K( F4, F4 )
- K( F5, F5 )
- K( F6, F6 )
- K( F7, F7 )
- K( F8, F8 )
- K( F9, F9 )
- K( F10, F10 )
- K( F11, F11 )
- K( F12, F12 )
-
- K( NUMLOCK, NUMLOCK )
- K( CAPSLOCK, CAPSLOCK )
- K( SCROLLOCK, SCROLLOCK )
- K( LSUPER, LWINKEY )
- K( RSUPER, RWINKEY )
- K( MENU, MENU )
-
- KK( RSHIFT, SHIFT, RSHIFT )
- KK( LSHIFT, SHIFT, LSHIFT )
- KK( RCTRL, CTRL, RCTRL )
- KK( LCTRL, CTRL, LCTRL )
- KK( RALT, ALT, RALT )
- KK( LALT, ALT, LALT )
+#define K(s, d) case SDLK_ ## s: key1 = K_ ## d; break;
+#define KK(s, d1, d2) case SDLK_ ## s: key1 = K_ ## d1; key2 = K_ ## d2; break;
+
+ switch (keysym->sym) {
+ K(KP0, KP_INS)
+ K(KP1, KP_END)
+ K(KP2, KP_DOWNARROW)
+ K(KP3, KP_PGDN)
+ K(KP4, KP_LEFTARROW)
+ K(KP5, KP_5)
+ K(KP6, KP_RIGHTARROW)
+ K(KP7, KP_HOME)
+ K(KP8, KP_UPARROW)
+ K(KP9, KP_PGUP)
+ K(KP_PERIOD, KP_DEL)
+ K(KP_DIVIDE, KP_SLASH)
+ K(KP_MULTIPLY, KP_MULTIPLY)
+ K(KP_MINUS, KP_MINUS)
+ K(KP_PLUS, KP_PLUS)
+ K(KP_ENTER, KP_ENTER)
+
+ K(UP, UPARROW)
+ K(DOWN, DOWNARROW)
+ K(RIGHT, RIGHTARROW)
+ K(LEFT, LEFTARROW)
+ K(INSERT, INS)
+ K(HOME, HOME)
+ K(END, END)
+ K(PAGEUP, PGUP)
+ K(PAGEDOWN, PGDN)
+
+ K(F1, F1)
+ K(F2, F2)
+ K(F3, F3)
+ K(F4, F4)
+ K(F5, F5)
+ K(F6, F6)
+ K(F7, F7)
+ K(F8, F8)
+ K(F9, F9)
+ K(F10, F10)
+ K(F11, F11)
+ K(F12, F12)
+
+ K(NUMLOCK, NUMLOCK)
+ K(CAPSLOCK, CAPSLOCK)
+ K(SCROLLOCK, SCROLLOCK)
+ K(LSUPER, LWINKEY)
+ K(RSUPER, RWINKEY)
+ K(MENU, MENU)
+
+ KK(RSHIFT, SHIFT, RSHIFT)
+ KK(LSHIFT, SHIFT, LSHIFT)
+ KK(RCTRL, CTRL, RCTRL)
+ KK(LCTRL, CTRL, LCTRL)
+ KK(RALT, ALT, RALT)
+ KK(LALT, ALT, LALT)
#undef K
#undef KK
default:
- Com_DPrintf( "%s: unknown keysym %d\n", __func__, keysym->sym );
+ Com_DPrintf("%s: unknown keysym %d\n", __func__, keysym->sym);
return;
}
- Key_Event( key1, down, com_eventTime );
- if( key2 ) {
- Key_Event( key2, down, com_eventTime );
+ Key_Event(key1, down, com_eventTime);
+ if (key2) {
+ Key_Event(key2, down, com_eventTime);
}
}
-static void button_event( int button, qboolean down ) {
+static void button_event(int button, qboolean down)
+{
unsigned key;
- if( !sdl.mouse.initialized ) {
+ if (!sdl.mouse.initialized) {
return;
}
-#define K( s, d ) case SDL_BUTTON_ ## s: key = K_ ## d; break;
+#define K(s, d) case SDL_BUTTON_ ## s: key = K_ ## d; break;
- switch( button ) {
- K( LEFT, MOUSE1 )
- K( RIGHT, MOUSE2 )
- K( MIDDLE, MOUSE3 )
- K( WHEELUP, MWHEELUP )
- K( WHEELDOWN, MWHEELDOWN )
+ switch (button) {
+ K(LEFT, MOUSE1)
+ K(RIGHT, MOUSE2)
+ K(MIDDLE, MOUSE3)
+ K(WHEELUP, MWHEELUP)
+ K(WHEELDOWN, MWHEELDOWN)
#undef K
default:
- Com_DPrintf( "%s: unknown button %d\n", __func__, button );
+ Com_DPrintf("%s: unknown button %d\n", __func__, button);
return;
}
- Key_Event( key, down, com_eventTime );
+ Key_Event(key, down, com_eventTime);
}
-static void resize_event( int w, int h ) {
- if( !sdl.surface ) {
+static void resize_event(int w, int h)
+{
+ if (!sdl.surface) {
return;
}
- if( !( sdl.surface->flags & SDL_RESIZABLE ) ) {
+ if (!(sdl.surface->flags & SDL_RESIZABLE)) {
return;
}
- Cvar_Set( "vid_geometry", va( "%dx%d", w, h ) );
+ Cvar_Set("vid_geometry", va("%dx%d", w, h));
VID_SetMode();
}
@@ -477,37 +491,38 @@ static void resize_event( int w, int h ) {
VID_PumpEvents
============
*/
-void VID_PumpEvents( void ) {
+void VID_PumpEvents(void)
+{
SDL_Event event;
- while( SDL_PollEvent( &event ) ) {
- switch( event.type ) {
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
case SDL_ACTIVEEVENT:
activate_event();
break;
case SDL_QUIT:
- Com_Quit( NULL, ERR_DISCONNECT );
+ Com_Quit(NULL, ERR_DISCONNECT);
break;
case SDL_VIDEORESIZE:
- resize_event( event.resize.w, event.resize.h );
+ resize_event(event.resize.w, event.resize.h);
return; // process only one resize event per frame
case SDL_VIDEOEXPOSE:
SCR_UpdateScreen();
break;
case SDL_KEYDOWN:
- key_event( &event.key.keysym, qtrue );
+ key_event(&event.key.keysym, qtrue);
break;
case SDL_KEYUP:
- key_event( &event.key.keysym, qfalse );
+ key_event(&event.key.keysym, qfalse);
break;
case SDL_MOUSEBUTTONDOWN:
- button_event( event.button.button, qtrue );
+ button_event(event.button.button, qtrue);
break;
case SDL_MOUSEBUTTONUP:
- button_event( event.button.button, qfalse );
+ button_event(event.button.button, qfalse);
break;
case SDL_MOUSEMOTION:
- IN_MouseEvent( event.motion.x, event.motion.y );
+ IN_MouseEvent(event.motion.x, event.motion.y);
break;
}
}
@@ -516,20 +531,21 @@ void VID_PumpEvents( void ) {
/*
===============================================================================
-RENDERER SPECIFIC
+RENDERER SPECIFIC
===============================================================================
*/
#if USE_REF == REF_SOFT
-qboolean VID_Init( void ) {
- if( !init_video() ) {
+qboolean VID_Init(void)
+{
+ if (!init_video()) {
return qfalse;
}
- if( !set_video_mode( SDL_SWSURFACE|SDL_HWPALETTE|SDL_RESIZABLE, 8 ) ) {
- Com_EPrintf( "Couldn't set video mode: %s\n", SDL_GetError() );
+ if (!set_video_mode(SDL_SWSURFACE | SDL_HWPALETTE | SDL_RESIZABLE, 8)) {
+ Com_EPrintf("Couldn't set video mode: %s\n", SDL_GetError());
VID_Shutdown();
return qfalse;
}
@@ -538,34 +554,39 @@ qboolean VID_Init( void ) {
return qtrue;
}
-void VID_UpdatePalette( const byte *palette ) {
+void VID_UpdatePalette(const byte *palette)
+{
SDL_Color colors[256];
SDL_Color *c;
- for( c = colors; c < colors + 256; c++ ) {
+ for (c = colors; c < colors + 256; c++) {
c->r = palette[0];
c->g = palette[1];
c->b = palette[2];
palette += 4;
}
- SDL_SetPalette( sdl.surface, SDL_LOGPAL, colors, 0, 256 );
+ SDL_SetPalette(sdl.surface, SDL_LOGPAL, colors, 0, 256);
}
-void VID_VideoWait( void ) {
+void VID_VideoWait(void)
+{
}
-qboolean VID_VideoSync( void ) {
+qboolean VID_VideoSync(void)
+{
return qtrue;
}
-void VID_BeginFrame( void ) {
- SDL_LockSurface( sdl.surface );
+void VID_BeginFrame(void)
+{
+ SDL_LockSurface(sdl.surface);
}
-void VID_EndFrame( void ) {
- SDL_UnlockSurface( sdl.surface );
- SDL_Flip( sdl.surface );
+void VID_EndFrame(void)
+{
+ SDL_UnlockSurface(sdl.surface);
+ SDL_Flip(sdl.surface);
}
#else // USE_REF == REF_SOFT
@@ -574,57 +595,60 @@ void VID_EndFrame( void ) {
// for debugging
#define SHOW_SYNC() \
- Com_DDDDPrintf( "%s: %u\n", __func__, sdl.sync_count )
+ Com_DDDDPrintf("%s: %u\n", __func__, sdl.sync_count)
-static unsigned glx_parse_extension_string( const char *s ) {
+static unsigned glx_parse_extension_string(const char *s)
+{
static const char *const extnames[] = {
"GLX_SGI_video_sync",
NULL
};
- return Com_ParseExtensionString( s, extnames );
+ return Com_ParseExtensionString(s, extnames);
}
-static void init_glx( void ) {
+static void init_glx(void)
+{
const char *extensions;
cvar_t *gl_video_sync;
unsigned mask;
- if( !sdl.dpy ) {
+ if (!sdl.dpy) {
return;
}
- sdl.glXQueryExtensionsString = SDL_GL_GetProcAddress( "glXQueryExtensionsString" );
- if( !sdl.glXQueryExtensionsString ) {
+ sdl.glXQueryExtensionsString = SDL_GL_GetProcAddress("glXQueryExtensionsString");
+ if (!sdl.glXQueryExtensionsString) {
return;
}
- gl_video_sync = Cvar_Get( "gl_video_sync", "1", 0 );
+ gl_video_sync = Cvar_Get("gl_video_sync", "1", 0);
- extensions = sdl.glXQueryExtensionsString( sdl.dpy, DefaultScreen( sdl.dpy ) );
- mask = glx_parse_extension_string( extensions );
- if( mask & 1 ) {
- if( gl_video_sync->integer ) {
- Com_Printf( "...enabling GLX_SGI_video_sync\n" );
- sdl.glXGetVideoSyncSGI = SDL_GL_GetProcAddress( "glXGetVideoSyncSGI" );
- sdl.glXWaitVideoSyncSGI = SDL_GL_GetProcAddress( "glXWaitVideoSyncSGI" );
- sdl.glXGetVideoSyncSGI( &sdl.sync_count );
+ extensions = sdl.glXQueryExtensionsString(sdl.dpy, DefaultScreen(sdl.dpy));
+ mask = glx_parse_extension_string(extensions);
+ if (mask & 1) {
+ if (gl_video_sync->integer) {
+ Com_Printf("...enabling GLX_SGI_video_sync\n");
+ sdl.glXGetVideoSyncSGI = SDL_GL_GetProcAddress("glXGetVideoSyncSGI");
+ sdl.glXWaitVideoSyncSGI = SDL_GL_GetProcAddress("glXWaitVideoSyncSGI");
+ sdl.glXGetVideoSyncSGI(&sdl.sync_count);
sdl.flags |= QVF_VIDEOSYNC;
} else {
- Com_Printf( "...ignoring GLX_SGI_video_sync\n" );
+ Com_Printf("...ignoring GLX_SGI_video_sync\n");
}
- } else if( gl_video_sync->integer ) {
- Com_Printf( "GLX_SGI_video_sync not found\n" );
- Cvar_Set( "gl_video_sync", "0" );
+ } else if (gl_video_sync->integer) {
+ Com_Printf("GLX_SGI_video_sync not found\n");
+ Cvar_Set("gl_video_sync", "0");
}
}
#endif
-static void init_opengl( void ) {
+static void init_opengl(void)
+{
int accel;
- SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &accel );
- if( accel ) {
+ SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &accel);
+ if (accel) {
sdl.flags |= QVF_ACCELERATED;
}
@@ -633,48 +657,49 @@ static void init_opengl( void ) {
#endif
}
-qboolean VID_Init( void ) {
+qboolean VID_Init(void)
+{
cvar_t *gl_driver;
char *s;
- if( !init_video() ) {
+ if (!init_video()) {
return qfalse;
}
- gl_driver = Cvar_Get( "gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_REFRESH );
+ gl_driver = Cvar_Get("gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_REFRESH);
- while( 1 ) {
+ while (1) {
// ugly hack to work around brain-dead servers that actively
// check and enforce `gl_driver' cvar to `opengl32', unaware
// of other systems than Windows
s = gl_driver->string;
- if( !Q_stricmp( s, "opengl32" ) || !Q_stricmp( s, "opengl32.dll" ) ) {
- Com_Printf( "...attempting to load %s instead of %s\n", DEFAULT_OPENGL_DRIVER, s );
+ if (!Q_stricmp(s, "opengl32") || !Q_stricmp(s, "opengl32.dll")) {
+ Com_Printf("...attempting to load %s instead of %s\n", DEFAULT_OPENGL_DRIVER, s);
s = DEFAULT_OPENGL_DRIVER;
}
- if( SDL_GL_LoadLibrary( s ) == 0 ) {
+ if (SDL_GL_LoadLibrary(s) == 0) {
break;
}
- Com_EPrintf( "Couldn't load OpenGL library: %s\n", SDL_GetError() );
- if( !strcmp( s, DEFAULT_OPENGL_DRIVER ) ) {
+ Com_EPrintf("Couldn't load OpenGL library: %s\n", SDL_GetError());
+ if (!strcmp(s, DEFAULT_OPENGL_DRIVER)) {
goto fail;
}
// attempt to recover
- Com_Printf( "...falling back to %s\n", DEFAULT_OPENGL_DRIVER );
- Cvar_SetByVar( gl_driver, DEFAULT_OPENGL_DRIVER, FROM_CODE );
+ Com_Printf("...falling back to %s\n", DEFAULT_OPENGL_DRIVER);
+ Cvar_SetByVar(gl_driver, DEFAULT_OPENGL_DRIVER, FROM_CODE);
}
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- if( !set_video_mode( SDL_OPENGL|SDL_RESIZABLE, 0 ) ) {
- Com_EPrintf( "Couldn't set video mode: %s\n", SDL_GetError() );
+ if (!set_video_mode(SDL_OPENGL | SDL_RESIZABLE, 0)) {
+ Com_EPrintf("Couldn't set video mode: %s\n", SDL_GetError());
goto fail;
}
@@ -686,30 +711,32 @@ fail:
return qfalse;
}
-void VID_VideoWait( void ) {
+void VID_VideoWait(void)
+{
#if USE_X11
- if( !sdl.glXWaitVideoSyncSGI ) {
+ if (!sdl.glXWaitVideoSyncSGI) {
return;
}
- sdl.glXWaitVideoSyncSGI( 2, 1, &sdl.sync_count );
+ sdl.glXWaitVideoSyncSGI(2, 1, &sdl.sync_count);
SHOW_SYNC();
#endif
}
-qboolean VID_VideoSync( void ) {
+qboolean VID_VideoSync(void)
+{
#if USE_X11
GLuint count;
- if( !sdl.glXGetVideoSyncSGI ) {
+ if (!sdl.glXGetVideoSyncSGI) {
return qtrue;
}
- if( sdl.glXGetVideoSyncSGI( &count ) ) {
+ if (sdl.glXGetVideoSyncSGI(&count)) {
return qtrue;
}
- if( count != sdl.sync_count ) {
+ if (count != sdl.sync_count) {
sdl.sync_count = count;
SHOW_SYNC();
return qtrue;
@@ -721,21 +748,24 @@ qboolean VID_VideoSync( void ) {
#endif
}
-void VID_BeginFrame( void ) {
+void VID_BeginFrame(void)
+{
}
-void VID_EndFrame( void ) {
+void VID_EndFrame(void)
+{
SDL_GL_SwapBuffers();
#if USE_X11
- if( sdl.glXGetVideoSyncSGI ) {
- sdl.glXGetVideoSyncSGI( &sdl.sync_count );
+ if (sdl.glXGetVideoSyncSGI) {
+ sdl.glXGetVideoSyncSGI(&sdl.sync_count);
SHOW_SYNC();
}
#endif
}
-void *VID_GetProcAddr( const char *sym ) {
- return SDL_GL_GetProcAddress( sym );
+void *VID_GetProcAddr(const char *sym)
+{
+ return SDL_GL_GetProcAddress(sym);
}
#endif // USE_REF == REF_GL
@@ -751,87 +781,93 @@ MOUSE DRIVER
#define SDL_FULLFOCUS (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)
-static void AcquireMouse( void ) {
+static void AcquireMouse(void)
+{
int state;
// move cursor to center of the main window before we grab the mouse
- if( sdl.surface ) {
- SDL_WarpMouse( sdl.surface->w / 2, sdl.surface->h / 2 );
+ if (sdl.surface) {
+ SDL_WarpMouse(sdl.surface->w / 2, sdl.surface->h / 2);
}
// pump mouse motion events generated by SDL_WarpMouse
- SDL_PollEvent( NULL );
+ SDL_PollEvent(NULL);
// grab the mouse, so SDL enters relative mouse mode
- SDL_WM_GrabInput( SDL_GRAB_ON );
+ SDL_WM_GrabInput(SDL_GRAB_ON);
state = SDL_GetAppState();
- if( ( state & SDL_FULLFOCUS ) != SDL_FULLFOCUS ) {
- Com_DPrintf( "AcquireMouse: don't have full focus\n" );
+ if ((state & SDL_FULLFOCUS) != SDL_FULLFOCUS) {
+ Com_DPrintf("AcquireMouse: don't have full focus\n");
}
- SDL_ShowCursor( SDL_DISABLE );
-
+ SDL_ShowCursor(SDL_DISABLE);
+
// pump mouse motion events still pending
- SDL_PollEvent( NULL );
+ SDL_PollEvent(NULL);
// clear any deltas generated
- SDL_GetRelativeMouseState( NULL, NULL );
+ SDL_GetRelativeMouseState(NULL, NULL);
}
-static qboolean GetMouseMotion( int *dx, int *dy ) {
- if( !sdl.mouse.grabbed ) {
+static qboolean GetMouseMotion(int *dx, int *dy)
+{
+ if (!sdl.mouse.grabbed) {
return qfalse;
}
- SDL_GetRelativeMouseState( dx, dy );
+ SDL_GetRelativeMouseState(dx, dy);
return qtrue;
}
-static void WarpMouse( int x, int y ) {
- SDL_WarpMouse( x, y );
- SDL_PollEvent( NULL );
- SDL_GetRelativeMouseState( NULL, NULL );
+static void WarpMouse(int x, int y)
+{
+ SDL_WarpMouse(x, y);
+ SDL_PollEvent(NULL);
+ SDL_GetRelativeMouseState(NULL, NULL);
}
-static void ShutdownMouse( void ) {
+static void ShutdownMouse(void)
+{
// release the mouse
- SDL_ShowCursor( SDL_ENABLE );
- SDL_WM_GrabInput( SDL_GRAB_OFF );
- SDL_WM_SetCaption( PRODUCT, APPLICATION );
- memset( &sdl.mouse, 0, sizeof( sdl.mouse ) );
+ SDL_ShowCursor(SDL_ENABLE);
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_WM_SetCaption(PRODUCT, APPLICATION);
+ memset(&sdl.mouse, 0, sizeof(sdl.mouse));
}
-static qboolean InitMouse( void ) {
- if( SDL_WasInit( SDL_INIT_VIDEO ) != SDL_INIT_VIDEO ) {
+static qboolean InitMouse(void)
+{
+ if (SDL_WasInit(SDL_INIT_VIDEO) != SDL_INIT_VIDEO) {
return qfalse;
}
- Com_Printf( "SDL mouse initialized.\n" );
+ Com_Printf("SDL mouse initialized.\n");
sdl.mouse.initialized = qtrue;
return qtrue;
}
-static void GrabMouse( grab_t grab ) {
- if( !sdl.mouse.initialized ) {
+static void GrabMouse(grab_t grab)
+{
+ if (!sdl.mouse.initialized) {
return;
}
- if( sdl.mouse.grabbed == grab ) {
- SDL_GetRelativeMouseState( NULL, NULL );
+ if (sdl.mouse.grabbed == grab) {
+ SDL_GetRelativeMouseState(NULL, NULL);
return;
}
- if( grab == IN_GRAB ) {
+ if (grab == IN_GRAB) {
AcquireMouse();
- SDL_WM_SetCaption( "[" PRODUCT "]", APPLICATION );
+ SDL_WM_SetCaption("[" PRODUCT "]", APPLICATION);
} else {
- if( sdl.mouse.grabbed == IN_GRAB ) {
- SDL_WM_GrabInput( SDL_GRAB_OFF );
- SDL_WM_SetCaption( PRODUCT, APPLICATION );
+ if (sdl.mouse.grabbed == IN_GRAB) {
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_WM_SetCaption(PRODUCT, APPLICATION);
}
- if( grab == IN_HIDE ) {
- SDL_ShowCursor( SDL_DISABLE );
+ if (grab == IN_HIDE) {
+ SDL_ShowCursor(SDL_DISABLE);
} else {
- SDL_ShowCursor( SDL_ENABLE );
+ SDL_ShowCursor(SDL_ENABLE);
}
}
@@ -843,7 +879,8 @@ static void GrabMouse( grab_t grab ) {
VID_FillInputAPI
============
*/
-void VID_FillInputAPI( inputAPI_t *api ) {
+void VID_FillInputAPI(inputAPI_t *api)
+{
api->Init = InitMouse;
api->Shutdown = ShutdownMouse;
api->Grab = GrabMouse;
diff --git a/src/vid_win.c b/src/vid_win.c
index 671aa4f..10c2025 100644
--- a/src/vid_win.c
+++ b/src/vid_win.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,10 +28,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define WINDOW_CLASS_NAME "Quake2"
// mode_changed flags
-#define MODE_SIZE (1<<0)
-#define MODE_POS (1<<1)
-#define MODE_STYLE (1<<2)
-#define MODE_REPOSITION (1<<3)
+#define MODE_SIZE (1 << 0)
+#define MODE_POS (1 << 1)
+#define MODE_STYLE (1 << 2)
+#define MODE_REPOSITION (1 << 3)
win_state_t win;
@@ -45,8 +45,8 @@ static cvar_t *win_alwaysontop;
static cvar_t *win_xpfix;
static cvar_t *win_rawmouse;
-static qboolean Win_InitMouse( void );
-static void Win_ClipCursor( void );
+static qboolean Win_InitMouse(void);
+static void Win_ClipCursor(void);
/*
===============================================================================
@@ -56,36 +56,37 @@ COMMON WIN32 VIDEO RELATED ROUTINES
===============================================================================
*/
-static void Win_SetPosition( void ) {
+static void Win_SetPosition(void)
+{
RECT r;
LONG style;
int x, y, w, h;
HWND after;
// get previous window style
- style = GetWindowLong( win.wnd, GWL_STYLE );
- style &= ~( WS_OVERLAPPEDWINDOW | WS_POPUP | WS_DLGFRAME );
+ style = GetWindowLong(win.wnd, GWL_STYLE);
+ style &= ~(WS_OVERLAPPEDWINDOW | WS_POPUP | WS_DLGFRAME);
// set new style bits
- if( win.flags & QVF_FULLSCREEN ) {
+ if (win.flags & QVF_FULLSCREEN) {
after = HWND_TOPMOST;
style |= WS_POPUP;
} else {
- if( win_alwaysontop->integer ) {
+ if (win_alwaysontop->integer) {
after = HWND_TOPMOST;
} else {
after = HWND_NOTOPMOST;
}
style |= WS_OVERLAPPED;
- if( win_notitle->integer ) {
- if( win_noresize->integer ) {
+ if (win_notitle->integer) {
+ if (win_noresize->integer) {
style |= WS_DLGFRAME;
} else {
style |= WS_THICKFRAME;
}
} else {
style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
- if( !win_noresize->integer ) {
+ if (!win_noresize->integer) {
style |= WS_THICKFRAME;
}
}
@@ -97,7 +98,7 @@ static void Win_SetPosition( void ) {
r.right = win.rc.width;
r.bottom = win.rc.height;
- AdjustWindowRect( &r, style, FALSE );
+ AdjustWindowRect(&r, style, FALSE);
// figure out position
x = win.rc.x;
@@ -106,13 +107,13 @@ static void Win_SetPosition( void ) {
h = r.bottom - r.top;
// set new window style and position
- SetWindowLong( win.wnd, GWL_STYLE, style );
- SetWindowPos( win.wnd, after, x, y, w, h, SWP_FRAMECHANGED );
- ShowWindow( win.wnd, SW_SHOW );
- SetForegroundWindow( win.wnd );
- SetFocus( win.wnd );
+ SetWindowLong(win.wnd, GWL_STYLE, style);
+ SetWindowPos(win.wnd, after, x, y, w, h, SWP_FRAMECHANGED);
+ ShowWindow(win.wnd, SW_SHOW);
+ SetForegroundWindow(win.wnd);
+ SetFocus(win.wnd);
- if( win.mouse.grabbed == IN_GRAB ) {
+ if (win.mouse.grabbed == IN_GRAB) {
Win_ClipCursor();
}
}
@@ -122,12 +123,13 @@ static void Win_SetPosition( void ) {
Win_ModeChanged
============
*/
-void Win_ModeChanged( void ) {
+void Win_ModeChanged(void)
+{
#if USE_REF == REF_SOFT
SWimp_ModeChanged();
#endif
- R_ModeChanged( win.rc.width, win.rc.height, win.flags,
- win.pitch, win.buffer );
+ R_ModeChanged(win.rc.width, win.rc.height, win.flags,
+ win.pitch, win.buffer);
SCR_ModeChanged();
}
@@ -237,7 +239,7 @@ char *VID_GetDefaultModeList(void)
return Z_CopyString(VID_MODELIST);
num_modes = 0;
- for (i = 0; i < MAX_MODES*4; i++) {
+ for (i = 0; i < MAX_MODES * 4; i++) {
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
@@ -276,79 +278,81 @@ char *VID_GetDefaultModeList(void)
}
// use desktop frequency by default if using desktop resolution
-static int get_desktop_frequency( const DEVMODE *desktop ) {
+static int get_desktop_frequency(const DEVMODE *desktop)
+{
const int mask = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
- if( (desktop->dmFields & mask) != mask )
+ if ((desktop->dmFields & mask) != mask)
return 0;
- if( desktop->dmPelsWidth != win.rc.width )
+ if (desktop->dmPelsWidth != win.rc.width)
return 0;
- if( desktop->dmPelsHeight != win.rc.height )
+ if (desktop->dmPelsHeight != win.rc.height)
return 0;
return desktop->dmDisplayFrequency;
}
-static qboolean set_fullscreen_mode( void ) {
+static qboolean set_fullscreen_mode(void)
+{
DEVMODE desktop, dm;
LONG ret;
int freq, depth;
- memset( &desktop, 0, sizeof( desktop ) );
- desktop.dmSize = sizeof( desktop );
+ memset(&desktop, 0, sizeof(desktop));
+ desktop.dmSize = sizeof(desktop);
- EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &desktop );
+ EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &desktop);
// parse vid_modelist specification
- if( VID_GetFullscreen( &win.rc, &freq, &depth ) ) {
- Com_DPrintf( "...setting fullscreen mode: %dx%d\n",
- win.rc.width, win.rc.height );
- } else if( DM_USABLE( &desktop ) ) {
+ if (VID_GetFullscreen(&win.rc, &freq, &depth)) {
+ Com_DPrintf("...setting fullscreen mode: %dx%d\n",
+ win.rc.width, win.rc.height);
+ } else if (DM_USABLE(&desktop)) {
win.rc.width = desktop.dmPelsWidth;
win.rc.height = desktop.dmPelsHeight;
- Com_DPrintf( "...falling back to desktop mode: %dx%d\n",
- win.rc.width, win.rc.height );
+ Com_DPrintf("...falling back to desktop mode: %dx%d\n",
+ win.rc.width, win.rc.height);
} else {
- Com_DPrintf( "...falling back to default mode: %dx%d\n",
- win.rc.width, win.rc.height );
+ Com_DPrintf("...falling back to default mode: %dx%d\n",
+ win.rc.width, win.rc.height);
}
- memset( &dm, 0, sizeof( dm ) );
- dm.dmSize = sizeof( dm );
+ memset(&dm, 0, sizeof(dm));
+ dm.dmSize = sizeof(dm);
dm.dmPelsWidth = win.rc.width;
dm.dmPelsHeight = win.rc.height;
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
- if( freq ) {
+ if (freq) {
dm.dmDisplayFrequency = freq;
dm.dmFields |= DM_DISPLAYFREQUENCY;
- Com_DPrintf( "...using display frequency of %d\n", freq );
+ Com_DPrintf("...using display frequency of %d\n", freq);
} else {
- freq = get_desktop_frequency( &desktop );
- if( freq > 1 ) {
+ freq = get_desktop_frequency(&desktop);
+ if (freq > 1) {
dm.dmDisplayFrequency = freq;
dm.dmFields |= DM_DISPLAYFREQUENCY;
- Com_DPrintf( "...using desktop display frequency of %d\n", freq );
+ Com_DPrintf("...using desktop display frequency of %d\n", freq);
}
}
- if( depth ) {
+ if (depth) {
dm.dmBitsPerPel = depth;
dm.dmFields |= DM_BITSPERPEL;
- Com_DPrintf( "...using bitdepth of %d\n", depth );
- } else if( desktop.dmFields & DM_BITSPERPEL ) {
+ Com_DPrintf("...using bitdepth of %d\n", depth);
+ } else if (desktop.dmFields & DM_BITSPERPEL) {
dm.dmBitsPerPel = desktop.dmBitsPerPel;
dm.dmFields |= DM_BITSPERPEL;
- Com_DPrintf( "...using desktop bitdepth of %lu\n", desktop.dmBitsPerPel );
+ Com_DPrintf("...using desktop bitdepth of %lu\n", desktop.dmBitsPerPel);
}
- Com_DPrintf( "...calling CDS: " );
- ret = ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
- if( ret != DISP_CHANGE_SUCCESSFUL ) {
- Com_DPrintf( "failed with error %ld\n", ret );
+ Com_DPrintf("...calling CDS: ");
+ ret = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
+ if (ret != DISP_CHANGE_SUCCESSFUL) {
+ Com_DPrintf("failed with error %ld\n", ret);
return qfalse;
}
- Com_DPrintf( "ok\n" );
+ Com_DPrintf("ok\n");
win.dm = dm;
win.flags |= QVF_FULLSCREEN;
@@ -363,42 +367,43 @@ static qboolean set_fullscreen_mode( void ) {
Win_SetMode
============
*/
-void Win_SetMode( void ) {
+void Win_SetMode(void)
+{
// set full screen mode if requested
- if( vid_fullscreen->integer > 0 ) {
- if( set_fullscreen_mode() ) {
+ if (vid_fullscreen->integer > 0) {
+ if (set_fullscreen_mode()) {
return;
}
- Cvar_Reset( vid_fullscreen );
- Com_Printf( "Full screen mode %dx%d failed.\n",
- win.rc.width, win.rc.height );
+ Cvar_Reset(vid_fullscreen);
+ Com_Printf("Full screen mode %dx%d failed.\n",
+ win.rc.width, win.rc.height);
// fall back to windowed mode
}
// parse vid_geometry specification
- VID_GetGeometry( &win.rc );
+ VID_GetGeometry(&win.rc);
// align client area
win.rc.width &= ~7;
win.rc.height &= ~1;
// don't allow too small size
- if( win.rc.width < 320 ) win.rc.width = 320;
- if( win.rc.height < 240 ) win.rc.height = 240;
+ if (win.rc.width < 320) win.rc.width = 320;
+ if (win.rc.height < 240) win.rc.height = 240;
- Com_DPrintf( "...setting windowed mode: %dx%d%+d%+d\n",
- win.rc.width, win.rc.height, win.rc.x, win.rc.y );
+ Com_DPrintf("...setting windowed mode: %dx%d%+d%+d\n",
+ win.rc.width, win.rc.height, win.rc.x, win.rc.y);
- ChangeDisplaySettings( NULL, 0 );
+ ChangeDisplaySettings(NULL, 0);
- memset( &win.dm, 0, sizeof( win.dm ) );
+ memset(&win.dm, 0, sizeof(win.dm));
win.flags &= ~QVF_FULLSCREEN;
Win_SetPosition();
win.mode_changed = 0;
// set vid_geometry back
- VID_SetGeometry( &win.rc );
+ VID_SetGeometry(&win.rc);
}
/*
@@ -406,108 +411,114 @@ void Win_SetMode( void ) {
VID_UpdateGamma
============
*/
-void VID_UpdateGamma( const byte *table ) {
+void VID_UpdateGamma(const byte *table)
+{
WORD v;
int i;
- if( win.flags & QVF_GAMMARAMP ) {
- for( i = 0; i < 256; i++ ) {
+ if (win.flags & QVF_GAMMARAMP) {
+ for (i = 0; i < 256; i++) {
v = table[i] << 8;
win.gamma_cust[0][i] = v;
win.gamma_cust[1][i] = v;
win.gamma_cust[2][i] = v;
}
- SetDeviceGammaRamp( win.dc, win.gamma_cust );
+ SetDeviceGammaRamp(win.dc, win.gamma_cust);
}
}
-static void Win_DisableAltTab( void ) {
- if( !win.alttab_disabled ) {
- RegisterHotKey( 0, 0, MOD_ALT, VK_TAB );
- RegisterHotKey( 0, 1, MOD_ALT, VK_RETURN );
+static void Win_DisableAltTab(void)
+{
+ if (!win.alttab_disabled) {
+ RegisterHotKey(0, 0, MOD_ALT, VK_TAB);
+ RegisterHotKey(0, 1, MOD_ALT, VK_RETURN);
win.alttab_disabled = qtrue;
}
}
-static void Win_EnableAltTab( void ) {
- if( win.alttab_disabled ) {
- UnregisterHotKey( 0, 0 );
- UnregisterHotKey( 0, 1 );
+static void Win_EnableAltTab(void)
+{
+ if (win.alttab_disabled) {
+ UnregisterHotKey(0, 0);
+ UnregisterHotKey(0, 1);
win.alttab_disabled = qfalse;
}
}
-static void win_noalttab_changed( cvar_t *self ) {
- if( self->integer ) {
+static void win_noalttab_changed(cvar_t *self)
+{
+ if (self->integer) {
Win_DisableAltTab();
} else {
Win_EnableAltTab();
}
}
-static void Win_Activate( WPARAM wParam ) {
+static void Win_Activate(WPARAM wParam)
+{
active_t active;
- if( HIWORD( wParam ) ) {
+ if (HIWORD(wParam)) {
// we don't want to act like we're active if we're minimized
active = ACT_MINIMIZED;
} else {
- if( LOWORD( wParam ) ) {
+ if (LOWORD(wParam)) {
active = ACT_ACTIVATED;
} else {
active = ACT_RESTORED;
}
}
- CL_Activate( active );
+ CL_Activate(active);
- if( win_noalttab->integer ) {
- if( active == ACT_ACTIVATED ) {
+ if (win_noalttab->integer) {
+ if (active == ACT_ACTIVATED) {
Win_EnableAltTab();
} else {
Win_DisableAltTab();
}
}
- if( win.flags & QVF_GAMMARAMP ) {
- if( active == ACT_ACTIVATED ) {
- SetDeviceGammaRamp( win.dc, win.gamma_cust );
+ if (win.flags & QVF_GAMMARAMP) {
+ if (active == ACT_ACTIVATED) {
+ SetDeviceGammaRamp(win.dc, win.gamma_cust);
} else {
- SetDeviceGammaRamp( win.dc, win.gamma_orig );
+ SetDeviceGammaRamp(win.dc, win.gamma_orig);
}
}
- if( win.flags & QVF_FULLSCREEN ) {
- if( active == ACT_ACTIVATED ) {
- ShowWindow( win.wnd, SW_RESTORE );
+ if (win.flags & QVF_FULLSCREEN) {
+ if (active == ACT_ACTIVATED) {
+ ShowWindow(win.wnd, SW_RESTORE);
} else {
- ShowWindow( win.wnd, SW_MINIMIZE );
+ ShowWindow(win.wnd, SW_MINIMIZE);
}
- if( vid_flip_on_switch->integer ) {
- if( active == ACT_ACTIVATED ) {
- ChangeDisplaySettings( &win.dm, CDS_FULLSCREEN );
+ if (vid_flip_on_switch->integer) {
+ if (active == ACT_ACTIVATED) {
+ ChangeDisplaySettings(&win.dm, CDS_FULLSCREEN);
} else {
- ChangeDisplaySettings( NULL, 0 );
+ ChangeDisplaySettings(NULL, 0);
}
}
}
- if( active == ACT_ACTIVATED ) {
- SetForegroundWindow( win.wnd );
+ if (active == ACT_ACTIVATED) {
+ SetForegroundWindow(win.wnd);
}
}
-STATIC LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam ) {
- PKBDLLHOOKSTRUCT kb = ( PKBDLLHOOKSTRUCT )lParam;
+STATIC LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+ PKBDLLHOOKSTRUCT kb = (PKBDLLHOOKSTRUCT)lParam;
unsigned key;
- if( nCode != HC_ACTION ) {
+ if (nCode != HC_ACTION) {
goto ignore;
}
- switch( kb->vkCode ) {
+ switch (kb->vkCode) {
case VK_LWIN:
key = K_LWINKEY;
break;
@@ -518,31 +529,32 @@ STATIC LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM l
goto ignore;
}
- switch( wParam ) {
+ switch (wParam) {
case WM_KEYDOWN:
- Key_Event( key, qtrue, kb->time );
+ Key_Event(key, qtrue, kb->time);
return TRUE;
case WM_KEYUP:
- Key_Event( key, qfalse, kb->time );
+ Key_Event(key, qfalse, kb->time);
return TRUE;
default:
break;
}
ignore:
- return CallNextHookEx( NULL, nCode, wParam, lParam );
+ return CallNextHookEx(NULL, nCode, wParam, lParam);
}
-static void win_disablewinkey_changed( cvar_t *self ) {
- if( self->integer ) {
- win.kbdHook = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, hGlobalInstance, 0 );
- if( !win.kbdHook ) {
- Com_EPrintf( "Couldn't set low-level keyboard hook, error %#lX\n", GetLastError() );
- Cvar_Set( "win_disablewinkey", "0" );
+static void win_disablewinkey_changed(cvar_t *self)
+{
+ if (self->integer) {
+ win.kbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hGlobalInstance, 0);
+ if (!win.kbdHook) {
+ Com_EPrintf("Couldn't set low-level keyboard hook, error %#lX\n", GetLastError());
+ Cvar_Set("win_disablewinkey", "0");
}
} else {
- if( win.kbdHook ) {
- UnhookWindowsHookEx( win.kbdHook );
+ if (win.kbdHook) {
+ UnhookWindowsHookEx(win.kbdHook);
win.kbdHook = NULL;
}
}
@@ -570,23 +582,24 @@ static const byte scantokey[128] = {
};
// Map from windows to quake keynums
-static void legacy_key_event( WPARAM wParam, LPARAM lParam, qboolean down ) {
- unsigned scancode = ( lParam >> 16 ) & 255;
- unsigned extended = ( lParam >> 24 ) & 1;
+static void legacy_key_event(WPARAM wParam, LPARAM lParam, qboolean down)
+{
+ unsigned scancode = (lParam >> 16) & 255;
+ unsigned extended = (lParam >> 24) & 1;
unsigned result;
- if( scancode > 127 ) {
+ if (scancode > 127) {
return;
}
result = scantokey[scancode];
- if( !result ) {
- Com_DPrintf( "%s: unknown scancode: %u\n", __func__, scancode );
+ if (!result) {
+ Com_DPrintf("%s: unknown scancode: %u\n", __func__, scancode);
return;
}
- if( !extended ) {
- switch( result ) {
+ if (!extended) {
+ switch (result) {
case K_HOME:
result = K_KP_HOME;
break;
@@ -618,24 +631,24 @@ static void legacy_key_event( WPARAM wParam, LPARAM lParam, qboolean down ) {
result = K_KP_DEL;
break;
case K_LSHIFT:
- Key_Event( K_SHIFT, down, win.lastMsgTime );
- Key_Event( K_LSHIFT, down, win.lastMsgTime );
+ Key_Event(K_SHIFT, down, win.lastMsgTime);
+ Key_Event(K_LSHIFT, down, win.lastMsgTime);
return;
case K_RSHIFT:
- Key_Event( K_SHIFT, down, win.lastMsgTime );
- Key_Event( K_RSHIFT, down, win.lastMsgTime );
+ Key_Event(K_SHIFT, down, win.lastMsgTime);
+ Key_Event(K_RSHIFT, down, win.lastMsgTime);
return;
case K_ALT:
- Key_Event( K_ALT, down, win.lastMsgTime );
- Key_Event( K_LALT, down, win.lastMsgTime );
+ Key_Event(K_ALT, down, win.lastMsgTime);
+ Key_Event(K_LALT, down, win.lastMsgTime);
return;
case K_CTRL:
- Key_Event( K_CTRL, down, win.lastMsgTime );
- Key_Event( K_LCTRL, down, win.lastMsgTime );
- return;
+ Key_Event(K_CTRL, down, win.lastMsgTime);
+ Key_Event(K_LCTRL, down, win.lastMsgTime);
+ return;
}
} else {
- switch( result ) {
+ switch (result) {
case K_ENTER:
result = K_KP_ENTER;
break;
@@ -646,90 +659,93 @@ static void legacy_key_event( WPARAM wParam, LPARAM lParam, qboolean down ) {
result = K_NUMLOCK;
break;
case K_ALT:
- Key_Event( K_ALT, down, win.lastMsgTime );
- Key_Event( K_RALT, down, win.lastMsgTime );
+ Key_Event(K_ALT, down, win.lastMsgTime);
+ Key_Event(K_RALT, down, win.lastMsgTime);
return;
case K_CTRL:
- Key_Event( K_CTRL, down, win.lastMsgTime );
- Key_Event( K_RCTRL, down, win.lastMsgTime );
- return;
+ Key_Event(K_CTRL, down, win.lastMsgTime);
+ Key_Event(K_RCTRL, down, win.lastMsgTime);
+ return;
}
}
- Key_Event( result, down, win.lastMsgTime );
+ Key_Event(result, down, win.lastMsgTime);
}
-static void mouse_wheel_event( int delta ) {
+static void mouse_wheel_event(int delta)
+{
UINT lines, key;
// FIXME: handle WHEEL_DELTA and partial scrolls...
- if( delta > 0 ) {
+ if (delta > 0) {
key = K_MWHEELUP;
- } else if( delta < 0 ) {
+ } else if (delta < 0) {
key = K_MWHEELDOWN;
} else {
return;
}
- if( Key_GetDest() & KEY_CONSOLE ) {
- SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &lines, 0 );
- clamp( lines, 1, 9 );
+ if (Key_GetDest() & KEY_CONSOLE) {
+ SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines, 0);
+ clamp(lines, 1, 9);
} else {
lines = 1;
}
do {
- Key_Event( key, qtrue, win.lastMsgTime );
- Key_Event( key, qfalse, win.lastMsgTime );
- } while( --lines );
+ Key_Event(key, qtrue, win.lastMsgTime);
+ Key_Event(key, qfalse, win.lastMsgTime);
+ } while (--lines);
}
-static void mouse_hwheel_event( int delta ) {
+static void mouse_hwheel_event(int delta)
+{
UINT key;
// FIXME: handle WHEEL_DELTA and partial scrolls...
- if( delta > 0 ) {
+ if (delta > 0) {
key = K_MWHEELRIGHT;
- } else if( delta < 0 ) {
+ } else if (delta < 0) {
key = K_MWHEELLEFT;
} else {
return;
}
- Key_Event( key, qtrue, win.lastMsgTime );
- Key_Event( key, qfalse, win.lastMsgTime );
+ Key_Event(key, qtrue, win.lastMsgTime);
+ Key_Event(key, qfalse, win.lastMsgTime);
}
// this is complicated because Win32 seems to pack multiple mouse events into
// one update sometimes, so we always check all states and look for events
-static void legacy_mouse_event( WPARAM wParam ) {
+static void legacy_mouse_event(WPARAM wParam)
+{
int i, mask, temp = 0;
- if( wParam & MK_LBUTTON )
+ if (wParam & MK_LBUTTON)
temp |= 1;
- if( wParam & MK_RBUTTON )
+ if (wParam & MK_RBUTTON)
temp |= 2;
- if( wParam & MK_MBUTTON )
+ if (wParam & MK_MBUTTON)
temp |= 4;
- if( wParam & MK_XBUTTON1 )
+ if (wParam & MK_XBUTTON1)
temp |= 8;
- if( wParam & MK_XBUTTON2 )
+ if (wParam & MK_XBUTTON2)
temp |= 16;
- if( temp == win.mouse.state )
+ if (temp == win.mouse.state)
return;
// perform button actions
- for( i = 0, mask = 1; i < MOUSE_BUTTONS; i++, mask <<= 1 ) {
- if( ( temp & mask ) && !( win.mouse.state & mask ) ) {
- Key_Event( K_MOUSE1 + i, qtrue, win.lastMsgTime );
+ for (i = 0, mask = 1; i < MOUSE_BUTTONS; i++, mask <<= 1) {
+ if ((temp & mask) && !(win.mouse.state & mask)) {
+ Key_Event(K_MOUSE1 + i, qtrue, win.lastMsgTime);
}
- if( !( temp & mask ) && ( win.mouse.state & mask ) ) {
- Key_Event( K_MOUSE1 + i, qfalse, win.lastMsgTime );
+ if (!(temp & mask) && (win.mouse.state & mask)) {
+ Key_Event(K_MOUSE1 + i, qfalse, win.lastMsgTime);
}
}
@@ -737,7 +753,8 @@ static void legacy_mouse_event( WPARAM wParam ) {
}
// returns TRUE if mouse cursor inside client area
-static BOOL check_cursor_pos( void ) {
+static BOOL check_cursor_pos(void)
+{
POINT pt;
if (win.mouse.grabbed == IN_GRAB)
@@ -752,77 +769,80 @@ static BOOL check_cursor_pos( void ) {
#define BTN_DN(i) (1<<(i*2+0))
#define BTN_UP(i) (1<<(i*2+1))
-static void raw_mouse_event( PRAWMOUSE rm ) {
+static void raw_mouse_event(PRAWMOUSE rm)
+{
int i;
- if( !check_cursor_pos() ) {
+ if (!check_cursor_pos()) {
// cursor is over non-client area
// perform just button up actions
- for( i = 0; i < MOUSE_BUTTONS; i++ ) {
- if( rm->usButtonFlags & BTN_UP(i) ) {
- Key_Event( K_MOUSE1 + i, qfalse, win.lastMsgTime );
+ for (i = 0; i < MOUSE_BUTTONS; i++) {
+ if (rm->usButtonFlags & BTN_UP(i)) {
+ Key_Event(K_MOUSE1 + i, qfalse, win.lastMsgTime);
}
}
return;
}
- if( rm->usButtonFlags ) {
+ if (rm->usButtonFlags) {
// perform button actions
- for( i = 0; i < MOUSE_BUTTONS; i++ ) {
- if( rm->usButtonFlags & BTN_DN(i) ) {
- Key_Event( K_MOUSE1 + i, qtrue, win.lastMsgTime );
+ for (i = 0; i < MOUSE_BUTTONS; i++) {
+ if (rm->usButtonFlags & BTN_DN(i)) {
+ Key_Event(K_MOUSE1 + i, qtrue, win.lastMsgTime);
}
- if( rm->usButtonFlags & BTN_UP(i) ) {
- Key_Event( K_MOUSE1 + i, qfalse, win.lastMsgTime );
+ if (rm->usButtonFlags & BTN_UP(i)) {
+ Key_Event(K_MOUSE1 + i, qfalse, win.lastMsgTime);
}
}
- if( rm->usButtonFlags & RI_MOUSE_WHEEL ) {
- mouse_wheel_event( ( short )rm->usButtonData );
+ if (rm->usButtonFlags & RI_MOUSE_WHEEL) {
+ mouse_wheel_event((short)rm->usButtonData);
}
// this flag is undocumented, but confirmed to work on Win7
- if( rm->usButtonFlags & 0x0800 ) {
- mouse_hwheel_event( ( short )rm->usButtonData );
+ if (rm->usButtonFlags & 0x0800) {
+ mouse_hwheel_event((short)rm->usButtonData);
}
}
- if( ( rm->usFlags & (MOUSE_MOVE_RELATIVE|MOUSE_MOVE_ABSOLUTE) ) == MOUSE_MOVE_RELATIVE ) {
+ if ((rm->usFlags & (MOUSE_MOVE_RELATIVE | MOUSE_MOVE_ABSOLUTE)) == MOUSE_MOVE_RELATIVE) {
win.mouse.mx += rm->lLastX;
win.mouse.my += rm->lLastY;
}
}
-static void raw_input_event( HANDLE handle ) {
+static void raw_input_event(HANDLE handle)
+{
BYTE buffer[64];
UINT len, ret;
PRAWINPUT ri;
- len = sizeof( buffer );
- ret = GetRawInputData( handle, RID_INPUT, buffer, &len, sizeof( RAWINPUTHEADER ) );
- if( ret == ( UINT )-1 ) {
- Com_EPrintf( "GetRawInputData failed with error %#lx\n", GetLastError() );
+ len = sizeof(buffer);
+ ret = GetRawInputData(handle, RID_INPUT, buffer, &len, sizeof(RAWINPUTHEADER));
+ if (ret == (UINT) - 1) {
+ Com_EPrintf("GetRawInputData failed with error %#lx\n", GetLastError());
return;
}
- ri = ( PRAWINPUT )buffer;
- if( ri->header.dwType == RIM_TYPEMOUSE ) {
- raw_mouse_event( &ri->data.mouse );
+ ri = (PRAWINPUT)buffer;
+ if (ri->header.dwType == RIM_TYPEMOUSE) {
+ raw_mouse_event(&ri->data.mouse);
}
}
-static void pos_changing_event( HWND wnd, WINDOWPOS *pos ) {
+static void pos_changing_event(HWND wnd, WINDOWPOS *pos)
+{
int w, h, nc_w, nc_h;
LONG style;
RECT rc;
- if( win.flags & QVF_FULLSCREEN )
+ if (win.flags & QVF_FULLSCREEN)
return;
- if( pos->flags & SWP_NOSIZE )
+ if (pos->flags & SWP_NOSIZE)
return;
- style = GetWindowLong( wnd, GWL_STYLE );
+ style = GetWindowLong(wnd, GWL_STYLE);
// calculate size of non-client area
rc.left = 0;
@@ -830,25 +850,26 @@ static void pos_changing_event( HWND wnd, WINDOWPOS *pos ) {
rc.right = 1;
rc.bottom = 1;
- AdjustWindowRect( &rc, style, FALSE );
+ AdjustWindowRect(&rc, style, FALSE);
nc_w = rc.right - rc.left - 1;
nc_h = rc.bottom - rc.top - 1;
// align client area
- w = ( pos->cx - nc_w ) & ~7;
- h = ( pos->cy - nc_h ) & ~1;
+ w = (pos->cx - nc_w) & ~7;
+ h = (pos->cy - nc_h) & ~1;
// don't allow too small size
- if( w < 320 ) w = 320;
- if( h < 240 ) h = 240;
+ if (w < 320) w = 320;
+ if (h < 240) h = 240;
// convert back to window size
pos->cx = w + nc_w;
pos->cy = h + nc_h;
}
-static void pos_changed_event( HWND wnd, WINDOWPOS *pos ) {
+static void pos_changed_event(HWND wnd, WINDOWPOS *pos)
+{
RECT rc;
// get window position
@@ -884,32 +905,33 @@ static void pos_changed_event( HWND wnd, WINDOWPOS *pos ) {
}
// main window procedure
-STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
- switch( uMsg ) {
+STATIC LONG WINAPI Win_MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
case WM_MOUSEWHEEL:
- if( win.mouse.initialized == WIN_MOUSE_LEGACY ) {
- mouse_wheel_event( ( short )HIWORD( wParam ) );
+ if (win.mouse.initialized == WIN_MOUSE_LEGACY) {
+ mouse_wheel_event((short)HIWORD(wParam));
}
break;
case WM_MOUSEHWHEEL:
- if( win.mouse.initialized == WIN_MOUSE_LEGACY ) {
- mouse_hwheel_event( ( short )HIWORD( wParam ) );
+ if (win.mouse.initialized == WIN_MOUSE_LEGACY) {
+ mouse_hwheel_event((short)HIWORD(wParam));
}
break;
case WM_NCMOUSEMOVE:
- if( win.mouse.initialized ) {
+ if (win.mouse.initialized) {
// don't hide cursor
- IN_MouseEvent( -1, -1 );
+ IN_MouseEvent(-1, -1);
}
break;
case WM_MOUSEMOVE:
- if( win.mouse.initialized ) {
- int x = ( short )LOWORD( lParam );
- int y = ( short )HIWORD( lParam );
+ if (win.mouse.initialized) {
+ int x = (short)LOWORD(lParam);
+ int y = (short)HIWORD(lParam);
- IN_MouseEvent( x, y );
+ IN_MouseEvent(x, y);
}
// fall through
@@ -921,8 +943,8 @@ STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
case WM_MBUTTONUP:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
- if( win.mouse.initialized == WIN_MOUSE_LEGACY ) {
- legacy_mouse_event( wParam );
+ if (win.mouse.initialized == WIN_MOUSE_LEGACY) {
+ legacy_mouse_event(wParam);
}
break;
@@ -930,17 +952,17 @@ STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
return FALSE;
case WM_INPUT:
- if( wParam == RIM_INPUT && win.mouse.initialized == WIN_MOUSE_RAW ) {
- raw_input_event( ( HANDLE )lParam );
+ if (wParam == RIM_INPUT && win.mouse.initialized == WIN_MOUSE_RAW) {
+ raw_input_event((HANDLE)lParam);
}
break;
case WM_CLOSE:
- PostQuitMessage( 0 );
+ PostQuitMessage(0);
return FALSE;
case WM_ACTIVATE:
- Win_Activate( wParam );
+ Win_Activate(wParam);
break;
case WM_WINDOWPOSCHANGING:
@@ -957,11 +979,11 @@ STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
break;
case WM_SYSCOMMAND:
- switch( wParam & 0xFFF0 ) {
+ switch (wParam & 0xFFF0) {
case SC_SCREENSAVE:
return FALSE;
case SC_MAXIMIZE:
- if( !vid_fullscreen->integer ) {
+ if (!vid_fullscreen->integer) {
VID_ToggleFullscreen();
}
return FALSE;
@@ -970,27 +992,27 @@ STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
- legacy_key_event( wParam, lParam, qtrue );
+ legacy_key_event(wParam, lParam, qtrue);
return FALSE;
case WM_KEYUP:
case WM_SYSKEYUP:
- legacy_key_event( wParam, lParam, qfalse );
+ legacy_key_event(wParam, lParam, qfalse);
return FALSE;
case WM_SYSCHAR:
case WM_CHAR:
#if USE_CHAR_EVENTS
- Key_CharEvent( wParam );
+ Key_CharEvent(wParam);
#endif
return FALSE;
- default:
+ default:
break;
}
// pass all unhandled messages to DefWindowProc
- return DefWindowProc( hWnd, uMsg, wParam, lParam );
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
/*
@@ -998,7 +1020,8 @@ STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
VID_SetMode
============
*/
-void VID_SetMode( void ) {
+void VID_SetMode(void)
+{
Win_SetMode();
Win_ModeChanged();
}
@@ -1008,38 +1031,40 @@ void VID_SetMode( void ) {
VID_PumpEvents
============
*/
-void VID_PumpEvents( void ) {
+void VID_PumpEvents(void)
+{
MSG msg;
- while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
- if( msg.message == WM_QUIT ) {
- Com_Quit( NULL, ERR_DISCONNECT );
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT) {
+ Com_Quit(NULL, ERR_DISCONNECT);
break;
}
win.lastMsgTime = msg.time;
- TranslateMessage( &msg );
- DispatchMessage( &msg );
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
}
- if( win.mode_changed ) {
- if( win.mode_changed & MODE_REPOSITION ) {
+ if (win.mode_changed) {
+ if (win.mode_changed & MODE_REPOSITION) {
Win_SetPosition();
}
- if( win.mode_changed & (MODE_SIZE | MODE_POS | MODE_STYLE) ) {
- VID_SetGeometry( &win.rc );
- if( win.mouse.grabbed == IN_GRAB ) {
+ if (win.mode_changed & (MODE_SIZE | MODE_POS | MODE_STYLE)) {
+ VID_SetGeometry(&win.rc);
+ if (win.mouse.grabbed == IN_GRAB) {
Win_ClipCursor();
}
}
- if( win.mode_changed & MODE_SIZE ) {
+ if (win.mode_changed & MODE_SIZE) {
Win_ModeChanged();
}
win.mode_changed = 0;
}
}
-static void win_style_changed( cvar_t *self ) {
- if( win.wnd && !( win.flags & QVF_FULLSCREEN ) ) {
+static void win_style_changed(cvar_t *self)
+{
+ if (win.wnd && !(win.flags & QVF_FULLSCREEN)) {
win.mode_changed |= MODE_REPOSITION;
}
}
@@ -1049,73 +1074,74 @@ static void win_style_changed( cvar_t *self ) {
Win_Init
============
*/
-void Win_Init( void ) {
+void Win_Init(void)
+{
WNDCLASSEX wc;
// register variables
- vid_flip_on_switch = Cvar_Get( "vid_flip_on_switch", "0", 0 );
- vid_hwgamma = Cvar_Get( "vid_hwgamma", "0", CVAR_REFRESH );
- win_noalttab = Cvar_Get( "win_noalttab", "0", CVAR_ARCHIVE );
+ vid_flip_on_switch = Cvar_Get("vid_flip_on_switch", "0", 0);
+ vid_hwgamma = Cvar_Get("vid_hwgamma", "0", CVAR_REFRESH);
+ win_noalttab = Cvar_Get("win_noalttab", "0", CVAR_ARCHIVE);
win_noalttab->changed = win_noalttab_changed;
- win_disablewinkey = Cvar_Get( "win_disablewinkey", "0", 0 );
+ win_disablewinkey = Cvar_Get("win_disablewinkey", "0", 0);
win_disablewinkey->changed = win_disablewinkey_changed;
- win_noresize = Cvar_Get( "win_noresize", "0", 0 );
+ win_noresize = Cvar_Get("win_noresize", "0", 0);
win_noresize->changed = win_style_changed;
- win_notitle = Cvar_Get( "win_notitle", "0", 0 );
+ win_notitle = Cvar_Get("win_notitle", "0", 0);
win_notitle->changed = win_style_changed;
- win_alwaysontop = Cvar_Get( "win_alwaysontop", "0", 0 );
+ win_alwaysontop = Cvar_Get("win_alwaysontop", "0", 0);
win_alwaysontop->changed = win_style_changed;
- win_xpfix = Cvar_Get( "win_xpfix", "0", 0 );
- win_rawmouse = Cvar_Get( "win_rawmouse", "1", 0 );
+ win_xpfix = Cvar_Get("win_xpfix", "0", 0);
+ win_rawmouse = Cvar_Get("win_rawmouse", "1", 0);
- win_disablewinkey_changed( win_disablewinkey );
+ win_disablewinkey_changed(win_disablewinkey);
// register the frame class
- memset( &wc, 0, sizeof( wc ) );
- wc.cbSize = sizeof( wc );
- wc.lpfnWndProc = ( WNDPROC )Win_MainWndProc;
+ memset(&wc, 0, sizeof(wc));
+ wc.cbSize = sizeof(wc);
+ wc.lpfnWndProc = (WNDPROC)Win_MainWndProc;
wc.hInstance = hGlobalInstance;
- wc.hIcon = LoadImage( hGlobalInstance, MAKEINTRESOURCE( IDI_APP ),
- IMAGE_ICON, 32, 32, LR_CREATEDIBSECTION );
- wc.hIconSm = LoadImage( hGlobalInstance, MAKEINTRESOURCE( IDI_APP ),
- IMAGE_ICON, 16, 16, LR_CREATEDIBSECTION );
- wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
- wc.hbrBackground = GetStockObject( BLACK_BRUSH );
- wc.lpszClassName = _T( WINDOW_CLASS_NAME );
+ wc.hIcon = LoadImage(hGlobalInstance, MAKEINTRESOURCE(IDI_APP),
+ IMAGE_ICON, 32, 32, LR_CREATEDIBSECTION);
+ wc.hIconSm = LoadImage(hGlobalInstance, MAKEINTRESOURCE(IDI_APP),
+ IMAGE_ICON, 16, 16, LR_CREATEDIBSECTION);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = GetStockObject(BLACK_BRUSH);
+ wc.lpszClassName = _T(WINDOW_CLASS_NAME);
- if( !RegisterClassEx( &wc ) ) {
- Com_Error( ERR_FATAL, "Couldn't register main window class" );
+ if (!RegisterClassEx(&wc)) {
+ Com_Error(ERR_FATAL, "Couldn't register main window class");
}
// create the window
win.wnd = CreateWindow(
- _T( WINDOW_CLASS_NAME ),
- _T( PRODUCT ),
- 0, //style
- 0, 0, 0, 0,
- NULL,
- NULL,
- hGlobalInstance,
- NULL );
+ _T(WINDOW_CLASS_NAME),
+ _T(PRODUCT),
+ 0, //style
+ 0, 0, 0, 0,
+ NULL,
+ NULL,
+ hGlobalInstance,
+ NULL);
- if( !win.wnd ) {
- Com_Error( ERR_FATAL, "Couldn't create main window" );
+ if (!win.wnd) {
+ Com_Error(ERR_FATAL, "Couldn't create main window");
}
- win.dc = GetDC( win.wnd );
- if( !win.dc ) {
- Com_Error( ERR_FATAL, "Couldn't get DC of the main window" );
+ win.dc = GetDC(win.wnd);
+ if (!win.dc) {
+ Com_Error(ERR_FATAL, "Couldn't get DC of the main window");
}
// init gamma ramp
- if( vid_hwgamma->integer ) {
- if( GetDeviceGammaRamp( win.dc, win.gamma_orig ) ) {
- Com_DPrintf( "...enabling hardware gamma\n" );
+ if (vid_hwgamma->integer) {
+ if (GetDeviceGammaRamp(win.dc, win.gamma_orig)) {
+ Com_DPrintf("...enabling hardware gamma\n");
win.flags |= QVF_GAMMARAMP;
- memcpy( win.gamma_cust, win.gamma_orig, sizeof( win.gamma_cust ) );
+ memcpy(win.gamma_cust, win.gamma_orig, sizeof(win.gamma_cust));
} else {
- Com_DPrintf( "...hardware gamma not supported\n" );
- Cvar_Set( "vid_hwgamma", "0" );
+ Com_DPrintf("...hardware gamma not supported\n");
+ Cvar_Set("vid_hwgamma", "0");
}
}
}
@@ -1125,26 +1151,27 @@ void Win_Init( void ) {
Win_Shutdown
============
*/
-void Win_Shutdown( void ) {
- if( win.flags & QVF_GAMMARAMP ) {
- SetDeviceGammaRamp( win.dc, win.gamma_orig );
+void Win_Shutdown(void)
+{
+ if (win.flags & QVF_GAMMARAMP) {
+ SetDeviceGammaRamp(win.dc, win.gamma_orig);
}
// prevents leaving empty slots in the taskbar
- ShowWindow( win.wnd, SW_SHOWNORMAL );
- ReleaseDC( win.wnd, win.dc );
- DestroyWindow( win.wnd );
- UnregisterClass( _T( WINDOW_CLASS_NAME ), hGlobalInstance );
+ ShowWindow(win.wnd, SW_SHOWNORMAL);
+ ReleaseDC(win.wnd, win.dc);
+ DestroyWindow(win.wnd);
+ UnregisterClass(_T(WINDOW_CLASS_NAME), hGlobalInstance);
- if( win.kbdHook ) {
- UnhookWindowsHookEx( win.kbdHook );
+ if (win.kbdHook) {
+ UnhookWindowsHookEx(win.kbdHook);
}
- if( win.flags & QVF_FULLSCREEN ) {
- ChangeDisplaySettings( NULL, 0 );
+ if (win.flags & QVF_FULLSCREEN) {
+ ChangeDisplaySettings(NULL, 0);
}
- memset( &win, 0, sizeof( win ) );
+ memset(&win, 0, sizeof(win));
}
/*
@@ -1155,68 +1182,74 @@ MOUSE
===============================================================================
*/
-static void Win_HideCursor( void ) {
- while( ShowCursor( FALSE ) >= 0 )
+static void Win_HideCursor(void)
+{
+ while (ShowCursor(FALSE) >= 0)
;
}
-static void Win_ShowCursor( void ) {
- while( ShowCursor( TRUE ) < 0 )
+static void Win_ShowCursor(void)
+{
+ while (ShowCursor(TRUE) < 0)
;
}
// Called when the window gains focus or changes in some way
-static void Win_ClipCursor( void ) {
- SetCursorPos( win.center_x, win.center_y );
- ClipCursor( &win.screen_rc );
+static void Win_ClipCursor(void)
+{
+ SetCursorPos(win.center_x, win.center_y);
+ ClipCursor(&win.screen_rc);
}
// Called when the window gains focus
-static void Win_AcquireMouse( void ) {
+static void Win_AcquireMouse(void)
+{
int parms[3];
- if( win.mouse.parmsvalid ) {
- if( win_xpfix->integer ) {
+ if (win.mouse.parmsvalid) {
+ if (win_xpfix->integer) {
parms[0] = parms[1] = parms[2] = 0;
} else {
parms[0] = parms[1] = 0;
parms[2] = 1;
}
win.mouse.restoreparms = SystemParametersInfo(
- SPI_SETMOUSE, 0, parms, 0 );
+ SPI_SETMOUSE, 0, parms, 0);
}
Win_ClipCursor();
- SetCapture( win.wnd );
+ SetCapture(win.wnd);
- SetWindowText( win.wnd, "[" PRODUCT "]" );
+ SetWindowText(win.wnd, "[" PRODUCT "]");
}
// Called when the window loses focus
-static void Win_DeAcquireMouse( void ) {
- if( win.mouse.restoreparms )
- SystemParametersInfo( SPI_SETMOUSE, 0, win.mouse.originalparms, 0 );
+static void Win_DeAcquireMouse(void)
+{
+ if (win.mouse.restoreparms)
+ SystemParametersInfo(SPI_SETMOUSE, 0, win.mouse.originalparms, 0);
- SetCursorPos( win.center_x, win.center_y );
+ SetCursorPos(win.center_x, win.center_y);
- ClipCursor( NULL );
+ ClipCursor(NULL);
ReleaseCapture();
- SetWindowText( win.wnd, PRODUCT );
+ SetWindowText(win.wnd, PRODUCT);
}
-static qboolean Win_GetMouseMotion( int *dx, int *dy ) {
+static qboolean Win_GetMouseMotion(int *dx, int *dy)
+{
POINT pt;
- if( !win.mouse.initialized ) {
+ if (!win.mouse.initialized) {
return qfalse;
}
- if( win.mouse.grabbed != IN_GRAB ) {
+ if (win.mouse.grabbed != IN_GRAB) {
return qfalse;
}
- if( win.mouse.initialized == WIN_MOUSE_RAW ) {
+ if (win.mouse.initialized == WIN_MOUSE_RAW) {
*dx = win.mouse.mx;
*dy = win.mouse.my;
win.mouse.mx = 0;
@@ -1225,7 +1258,7 @@ static qboolean Win_GetMouseMotion( int *dx, int *dy ) {
}
// find mouse movement
- if( !GetCursorPos( &pt ) ) {
+ if (!GetCursorPos(&pt)) {
return qfalse;
}
@@ -1233,75 +1266,80 @@ static qboolean Win_GetMouseMotion( int *dx, int *dy ) {
*dy = pt.y - win.center_y;
// force the mouse to the center, so there's room to move
- SetCursorPos( win.center_x, win.center_y );
+ SetCursorPos(win.center_x, win.center_y);
return qtrue;
}
-static BOOL register_raw_mouse( DWORD flags ) {
+static BOOL register_raw_mouse(DWORD flags)
+{
RAWINPUTDEVICE rid;
- memset( &rid, 0, sizeof( rid ) );
+ memset(&rid, 0, sizeof(rid));
rid.usUsagePage = 0x01;
rid.usUsage = 0x02;
rid.dwFlags = flags;
rid.hwndTarget = win.wnd;
- return RegisterRawInputDevices( &rid, 1, sizeof( rid ) );
+ return RegisterRawInputDevices(&rid, 1, sizeof(rid));
}
-static void Win_ShutdownMouse( void ) {
- if( !win.mouse.initialized ) {
+static void Win_ShutdownMouse(void)
+{
+ if (!win.mouse.initialized) {
return;
}
Win_DeAcquireMouse();
Win_ShowCursor();
- if( win.mouse.initialized == WIN_MOUSE_RAW ) {
- register_raw_mouse( RIDEV_REMOVE );
+ if (win.mouse.initialized == WIN_MOUSE_RAW) {
+ register_raw_mouse(RIDEV_REMOVE);
}
win_xpfix->changed = NULL;
win_rawmouse->changed = NULL;
- memset( &win.mouse, 0, sizeof( win.mouse ) );
+ memset(&win.mouse, 0, sizeof(win.mouse));
}
-static void win_xpfix_changed( cvar_t *self ) {
- if( win.mouse.grabbed == IN_GRAB ) {
+static void win_xpfix_changed(cvar_t *self)
+{
+ if (win.mouse.grabbed == IN_GRAB) {
Win_AcquireMouse();
}
}
-static void win_rawmouse_changed( cvar_t *self ) {
- if( win.mouse.initialized ) {
+static void win_rawmouse_changed(cvar_t *self)
+{
+ if (win.mouse.initialized) {
Win_ShutdownMouse();
Win_InitMouse();
}
}
-static qboolean Win_InitMouse( void ) {
- if( !win.wnd ) {
+static qboolean Win_InitMouse(void)
+{
+ if (!win.wnd) {
return qfalse;
}
win.mouse.initialized = WIN_MOUSE_LEGACY;
- if( win_rawmouse->integer ) {
- if( !register_raw_mouse( /*RIDEV_NOLEGACY*/ 0 ) ) {
- Com_EPrintf( "RegisterRawInputDevices failed with error %#lx\n", GetLastError() );
- Cvar_Set( "win_rawmouse", "0" );
+ if (win_rawmouse->integer) {
+ if (!register_raw_mouse(/*RIDEV_NOLEGACY*/ 0)) {
+ Com_EPrintf("RegisterRawInputDevices failed with error %#lx\n", GetLastError());
+ Cvar_Set("win_rawmouse", "0");
} else {
- Com_Printf( "Raw mouse initialized.\n" );
+ Com_Printf("Raw mouse initialized.\n");
win.mouse.initialized = WIN_MOUSE_RAW;
}
}
- if( win.mouse.initialized == WIN_MOUSE_LEGACY ) {
- win.mouse.parmsvalid = SystemParametersInfo( SPI_GETMOUSE, 0,
- win.mouse.originalparms, 0 );
+ if (win.mouse.initialized == WIN_MOUSE_LEGACY) {
+ win.mouse.parmsvalid = SystemParametersInfo(SPI_GETMOUSE, 0,
+ win.mouse.originalparms, 0);
win_xpfix->changed = win_xpfix_changed;
- Com_Printf( "Legacy mouse initialized.\n" );
+ Com_Printf("Legacy mouse initialized.\n");
}
win_rawmouse->changed = win_rawmouse_changed;
@@ -1310,28 +1348,29 @@ static qboolean Win_InitMouse( void ) {
}
// Called when the main window gains or loses focus.
-static void Win_GrabMouse( grab_t grab ) {
- if( !win.mouse.initialized ) {
+static void Win_GrabMouse(grab_t grab)
+{
+ if (!win.mouse.initialized) {
return;
}
- if( win.mouse.grabbed == grab ) {
- if( win.mouse.initialized == WIN_MOUSE_LEGACY ) {
- SetCursorPos( win.center_x, win.center_y );
+ if (win.mouse.grabbed == grab) {
+ if (win.mouse.initialized == WIN_MOUSE_LEGACY) {
+ SetCursorPos(win.center_x, win.center_y);
}
win.mouse.mx = 0;
win.mouse.my = 0;
return;
}
- if( grab == IN_GRAB ) {
+ if (grab == IN_GRAB) {
Win_AcquireMouse();
Win_HideCursor();
} else {
- if( win.mouse.grabbed == IN_GRAB ) {
+ if (win.mouse.grabbed == IN_GRAB) {
Win_DeAcquireMouse();
}
- if( grab == IN_HIDE ) {
+ if (grab == IN_HIDE) {
Win_HideCursor();
} else {
Win_ShowCursor();
@@ -1344,8 +1383,9 @@ static void Win_GrabMouse( grab_t grab ) {
win.mouse.my = 0;
}
-static void Win_WarpMouse( int x, int y ) {
- SetCursorPos( win.screen_rc.left + x, win.screen_rc.top + y );
+static void Win_WarpMouse(int x, int y)
+{
+ SetCursorPos(win.screen_rc.left + x, win.screen_rc.top + y);
}
/*
@@ -1353,24 +1393,25 @@ static void Win_WarpMouse( int x, int y ) {
VID_GetClipboardData
================
*/
-char *VID_GetClipboardData( void ) {
+char *VID_GetClipboardData(void)
+{
HANDLE clipdata;
char *data = NULL;
char *cliptext;
- if( OpenClipboard( NULL ) == FALSE ) {
- Com_DPrintf( "Couldn't open clipboard.\n" );
+ if (OpenClipboard(NULL) == FALSE) {
+ Com_DPrintf("Couldn't open clipboard.\n");
return data;
}
- if( ( clipdata = GetClipboardData( CF_TEXT ) ) != NULL ) {
- if( ( cliptext = GlobalLock( clipdata ) ) != NULL ) {
- data = Z_CopyString( cliptext );
- GlobalUnlock( clipdata );
+ if ((clipdata = GetClipboardData(CF_TEXT)) != NULL) {
+ if ((cliptext = GlobalLock(clipdata)) != NULL) {
+ data = Z_CopyString(cliptext);
+ GlobalUnlock(clipdata);
}
}
CloseClipboard();
-
+
return data;
}
@@ -1379,31 +1420,32 @@ char *VID_GetClipboardData( void ) {
VID_SetClipboardData
================
*/
-void VID_SetClipboardData( const char *data ) {
+void VID_SetClipboardData(const char *data)
+{
HANDLE clipdata;
char *cliptext;
size_t length;
- if( !data[0] ) {
+ if (!data[0]) {
return;
}
- if( OpenClipboard( NULL ) == FALSE ) {
- Com_DPrintf( "Couldn't open clipboard.\n" );
+ if (OpenClipboard(NULL) == FALSE) {
+ Com_DPrintf("Couldn't open clipboard.\n");
return;
}
EmptyClipboard();
- length = strlen( data ) + 1;
- if( ( clipdata = GlobalAlloc( GMEM_MOVEABLE | GMEM_DDESHARE, length ) ) != NULL ) {
- if( ( cliptext = GlobalLock( clipdata ) ) != NULL ) {
- memcpy( cliptext, data, length );
- GlobalUnlock( clipdata );
- SetClipboardData( CF_TEXT, clipdata );
+ length = strlen(data) + 1;
+ if ((clipdata = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, length)) != NULL) {
+ if ((cliptext = GlobalLock(clipdata)) != NULL) {
+ memcpy(cliptext, data, length);
+ GlobalUnlock(clipdata);
+ SetClipboardData(CF_TEXT, clipdata);
}
}
-
+
CloseClipboard();
}
@@ -1412,7 +1454,8 @@ void VID_SetClipboardData( const char *data ) {
VID_FillInputAPI
@@@@@@@@@@@@@@@@@@@
*/
-void VID_FillInputAPI( inputAPI_t *api ) {
+void VID_FillInputAPI(inputAPI_t *api)
+{
api->Init = Win_InitMouse;
api->Shutdown = Win_ShutdownMouse;
api->Grab = Win_GrabMouse;
diff --git a/src/win_ac.c b/src/win_ac.c
index 83cd462..83baed3 100644
--- a/src/win_ac.c
+++ b/src/win_ac.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,21 +24,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "win_local.h"
-typedef PVOID (*FNINIT)( VOID );
+typedef PVOID(*FNINIT)(VOID);
STATIC PVOID anticheatApi;
STATIC FNINIT anticheatInit;
STATIC HMODULE anticheatHandle;
-qboolean Sys_GetAntiCheatAPI( void ) {
+qboolean Sys_GetAntiCheatAPI(void)
+{
qboolean updated = qfalse;
//already loaded, just reinit
- if( anticheatInit ) {
+ if (anticheatInit) {
anticheatApi = anticheatInit();
- if( !anticheatApi ) {
- Com_LPrintf( PRINT_ERROR, "Anticheat failed to reinitialize!\n" );
- FreeLibrary( anticheatHandle );
+ if (!anticheatApi) {
+ Com_LPrintf(PRINT_ERROR, "Anticheat failed to reinitialize!\n");
+ FreeLibrary(anticheatHandle);
anticheatHandle = NULL;
anticheatInit = NULL;
return qfalse;
@@ -47,39 +48,39 @@ qboolean Sys_GetAntiCheatAPI( void ) {
}
reInit:
- anticheatHandle = LoadLibrary( "anticheat" );
- if( !anticheatHandle ) {
- Com_LPrintf( PRINT_ERROR, "Anticheat failed to load.\n" );
+ anticheatHandle = LoadLibrary("anticheat");
+ if (!anticheatHandle) {
+ Com_LPrintf(PRINT_ERROR, "Anticheat failed to load.\n");
return qfalse;
}
//this should never fail unless the anticheat.dll is bad
- anticheatInit = ( FNINIT )GetProcAddress(
- anticheatHandle, "Initialize" );
- if( !anticheatInit ) {
- Com_LPrintf( PRINT_ERROR,
+ anticheatInit = (FNINIT)GetProcAddress(
+ anticheatHandle, "Initialize");
+ if (!anticheatInit) {
+ Com_LPrintf(PRINT_ERROR,
"Couldn't get API of anticheat.dll!\n"
"Please check you are using a valid "
- "anticheat.dll from http://antiche.at/" );
- FreeLibrary( anticheatHandle );
+ "anticheat.dll from http://antiche.at/");
+ FreeLibrary(anticheatHandle);
anticheatHandle = NULL;
return qfalse;
}
anticheatApi = anticheatInit();
- if( anticheatApi ) {
+ if (anticheatApi) {
return qtrue; // succeeded
}
- FreeLibrary( anticheatHandle );
+ FreeLibrary(anticheatHandle);
anticheatHandle = NULL;
anticheatInit = NULL;
- if( !updated ) {
+ if (!updated) {
updated = qtrue;
goto reInit;
}
- Com_LPrintf( PRINT_ERROR, "Anticheat failed to initialize.\n" );
+ Com_LPrintf(PRINT_ERROR, "Anticheat failed to initialize.\n");
return qfalse;
}
diff --git a/src/win_ascii.c b/src/win_ascii.c
index d23dcd4..0122e4c 100644
--- a/src/win_ascii.c
+++ b/src/win_ascii.c
@@ -1,91 +1,98 @@
#include <windows.h>
-HANDLE WINAPI FindFirstFileA( LPCSTR path, LPWIN32_FIND_DATAA data ) {
+HANDLE WINAPI FindFirstFileA(LPCSTR path, LPWIN32_FIND_DATAA data)
+{
WCHAR wbuffer[MAX_PATH];
HANDLE ret;
WIN32_FIND_DATAW wdata;
- if( !MultiByteToWideChar( CP_ACP, 0, path, -1, wbuffer, MAX_PATH ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, path, -1, wbuffer, MAX_PATH)) {
return INVALID_HANDLE_VALUE;
}
- ret = FindFirstFileW( wbuffer, &wdata );
- if( ret != INVALID_HANDLE_VALUE ) {
- memcpy( data, &wdata, FIELD_OFFSET( WIN32_FIND_DATAA, cFileName ) );
- WideCharToMultiByte( CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL );
+ ret = FindFirstFileW(wbuffer, &wdata);
+ if (ret != INVALID_HANDLE_VALUE) {
+ memcpy(data, &wdata, FIELD_OFFSET(WIN32_FIND_DATAA, cFileName));
+ WideCharToMultiByte(CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL);
}
return ret;
}
-BOOL WINAPI FindNextFileA( HANDLE handle, LPWIN32_FIND_DATAA data ) {
+BOOL WINAPI FindNextFileA(HANDLE handle, LPWIN32_FIND_DATAA data)
+{
BOOL ret;
WIN32_FIND_DATAW wdata;
- ret = FindNextFileW( handle, &wdata );
- if( ret != FALSE ) {
- memcpy( data, &wdata, FIELD_OFFSET( WIN32_FIND_DATAA, cFileName ) );
- WideCharToMultiByte( CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL );
+ ret = FindNextFileW(handle, &wdata);
+ if (ret != FALSE) {
+ memcpy(data, &wdata, FIELD_OFFSET(WIN32_FIND_DATAA, cFileName));
+ WideCharToMultiByte(CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL);
}
return ret;
}
-HINSTANCE WINAPI LoadLibraryA( LPCSTR path ) {
+HINSTANCE WINAPI LoadLibraryA(LPCSTR path)
+{
WCHAR wbuffer[MAX_PATH];
- if( !MultiByteToWideChar( CP_ACP, 0, path, -1, wbuffer, MAX_PATH ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, path, -1, wbuffer, MAX_PATH)) {
return NULL;
}
- return LoadLibraryW( wbuffer );
+ return LoadLibraryW(wbuffer);
}
-int WINAPI MessageBoxA( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType ) {
+int WINAPI MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
+{
WCHAR wText[4096];
WCHAR wCaption[256];
- if( !MultiByteToWideChar( CP_ACP, 0, lpText, -1, wText, 4096 ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, lpText, -1, wText, 4096)) {
return 0;
}
- if( !MultiByteToWideChar( CP_ACP, 0, lpCaption, -1, wCaption, 256 ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, lpCaption, -1, wCaption, 256)) {
return 0;
}
- return MessageBoxW( hWnd, wText, wCaption, uType );
+ return MessageBoxW(hWnd, wText, wCaption, uType);
}
-BOOL WINAPI CreateDirectoryA( LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ) {
+BOOL WINAPI CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
+{
WCHAR wbuffer[MAX_PATH];
- if( !MultiByteToWideChar( CP_ACP, 0, lpPathName, -1, wbuffer, MAX_PATH ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, lpPathName, -1, wbuffer, MAX_PATH)) {
return FALSE;
}
- return CreateDirectoryW( wbuffer, lpSecurityAttributes );
+ return CreateDirectoryW(wbuffer, lpSecurityAttributes);
}
-BOOL WINAPI GetFileAttributesExA( LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation ) {
+BOOL WINAPI GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation)
+{
WCHAR wbuffer[MAX_PATH];
- if( !MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, wbuffer, MAX_PATH ) ) {
+ if (!MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wbuffer, MAX_PATH)) {
return FALSE;
}
- return GetFileAttributesExW( wbuffer, fInfoLevelId, lpFileInformation );
+ return GetFileAttributesExW(wbuffer, fInfoLevelId, lpFileInformation);
}
-DWORD WINAPI GetModuleFileNameA( HMODULE hModule, LPSTR lpFileName, DWORD nSize ) {
+DWORD WINAPI GetModuleFileNameA(HMODULE hModule, LPSTR lpFileName, DWORD nSize)
+{
WCHAR wbuffer[MAX_PATH];
DWORD ret;
- if( nSize > MAX_PATH ) {
+ if (nSize > MAX_PATH) {
nSize = MAX_PATH;
}
- ret = GetModuleFileNameW( hModule, wbuffer, nSize );
- if( ret ) {
- if( !WideCharToMultiByte( CP_ACP, 0, wbuffer, ret, lpFileName, ret, NULL, NULL ) ) {
+ ret = GetModuleFileNameW(hModule, wbuffer, nSize);
+ if (ret) {
+ if (!WideCharToMultiByte(CP_ACP, 0, wbuffer, ret, lpFileName, ret, NULL, NULL)) {
return 0;
}
}
diff --git a/src/win_dbg.c b/src/win_dbg.c
index ee624c0..3e6c562 100644
--- a/src/win_dbg.c
+++ b/src/win_dbg.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -25,23 +25,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "win_local.h"
#include <dbghelp.h>
-typedef DWORD (WINAPI *SETSYMOPTIONS)( DWORD );
-typedef BOOL (WINAPI *SYMGETMODULEINFO64)( HANDLE, DWORD64,
- PIMAGEHLP_MODULE64 );
-typedef BOOL (WINAPI *SYMINITIALIZE)( HANDLE, PSTR, BOOL );
-typedef BOOL (WINAPI *SYMCLEANUP)( HANDLE );
-typedef BOOL (WINAPI *ENUMERATELOADEDMODULES64)( HANDLE,
- PENUMLOADED_MODULES_CALLBACK64, PVOID );
-typedef BOOL (WINAPI *STACKWALK64)( DWORD, HANDLE, HANDLE, LPSTACKFRAME64,
- PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64,
- PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64 );
-typedef BOOL (WINAPI *SYMFROMADDR)( HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO );
-typedef PVOID (WINAPI *SYMFUNCTIONTABLEACCESS64)( HANDLE, DWORD64 );
-typedef DWORD64 (WINAPI *SYMGETMODULEBASE64)( HANDLE, DWORD64 );
-typedef BOOL (WINAPI *GETFILEVERSIONINFOA)( LPCSTR, DWORD, DWORD, PVOID );
-typedef BOOL (WINAPI *VERQUERYVALUEA)( const LPVOID, LPSTR, LPVOID *, PUINT );
-typedef HINSTANCE (WINAPI *SHELLEXECUTEA)( HWND, LPCSTR, LPCSTR,
- LPCSTR, LPCSTR, INT );
+typedef DWORD (WINAPI *SETSYMOPTIONS)(DWORD);
+typedef BOOL (WINAPI *SYMGETMODULEINFO64)(HANDLE, DWORD64,
+ PIMAGEHLP_MODULE64);
+typedef BOOL (WINAPI *SYMINITIALIZE)(HANDLE, PSTR, BOOL);
+typedef BOOL (WINAPI *SYMCLEANUP)(HANDLE);
+typedef BOOL (WINAPI *ENUMERATELOADEDMODULES64)(HANDLE,
+ PENUMLOADED_MODULES_CALLBACK64, PVOID);
+typedef BOOL (WINAPI *STACKWALK64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64,
+ PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64,
+ PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
+typedef BOOL (WINAPI *SYMFROMADDR)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO);
+typedef PVOID(WINAPI *SYMFUNCTIONTABLEACCESS64)(HANDLE, DWORD64);
+typedef DWORD64(WINAPI *SYMGETMODULEBASE64)(HANDLE, DWORD64);
+typedef BOOL (WINAPI *GETFILEVERSIONINFOA)(LPCSTR, DWORD, DWORD, PVOID);
+typedef BOOL (WINAPI *VERQUERYVALUEA)(const LPVOID, LPSTR, LPVOID *, PUINT);
+typedef HINSTANCE(WINAPI *SHELLEXECUTEA)(HWND, LPCSTR, LPCSTR,
+ LPCSTR, LPCSTR, INT);
STATIC SETSYMOPTIONS pSymSetOptions;
STATIC SYMGETMODULEINFO64 pSymGetModuleInfo64;
@@ -67,7 +67,7 @@ STATIC DWORD moduleInfoSize;
// google://dbghelp+not+backwards+compatible
STATIC CONST DWORD tryModuleSizes[4] = {
- sizeof( IMAGEHLP_MODULE64 ), MI_SIZE_V3, MI_SIZE_V2, MI_SIZE_V1
+ sizeof(IMAGEHLP_MODULE64), MI_SIZE_V3, MI_SIZE_V2, MI_SIZE_V1
};
static const char monthNames[12][4] = {
@@ -88,18 +88,19 @@ static const char monthNames[12][4] = {
#endif
// does not check for overflow!
-STATIC VOID write_report( LPCTSTR fmt, ... ) {
+STATIC VOID write_report(LPCTSTR fmt, ...)
+{
TCHAR buf[1024];
va_list argptr;
int len;
DWORD written;
- va_start( argptr, fmt );
- len = wvsprintf( buf, fmt, argptr );
- va_end( argptr );
+ va_start(argptr, fmt);
+ len = wvsprintf(buf, fmt, argptr);
+ va_end(argptr);
- if( len > 0 && len < 1024 ) {
- WriteFile( crashReport, buf, len, &written, NULL );
+ if (len > 0 && len < 1024) {
+ WriteFile(crashReport, buf, len, &written, NULL);
}
}
@@ -107,10 +108,10 @@ STATIC BOOL CALLBACK enum_modules_callback(
PCSTR ModuleName,
DWORD64 ModuleBase,
ULONG ModuleSize,
- PVOID UserContext )
+ PVOID UserContext)
{
IMAGEHLP_MODULE64 moduleInfo;
- DWORD64 pc = *( DWORD64 * )UserContext;
+ DWORD64 pc = *(DWORD64 *)UserContext;
BYTE buffer[4096];
PBYTE data;
UINT numBytes;
@@ -120,48 +121,47 @@ STATIC BOOL CALLBACK enum_modules_callback(
int len;
BOOL ret;
- len = lstrlen( ModuleName );
- if( len >= MAX_PATH ) {
+ len = lstrlen(ModuleName);
+ if (len >= MAX_PATH) {
return TRUE;
}
- if( pGetFileVersionInfoA( ModuleName, 0, sizeof( buffer ), buffer ) &&
- pVerQueryValueA( buffer, "\\", ( LPVOID * )&data, &numBytes ) &&
- numBytes >= sizeof( *info ) )
- {
- info = ( VS_FIXEDFILEINFO * )data;
- wsprintf( version, "%u.%u.%u.%u",
- HIWORD( info->dwFileVersionMS ),
- LOWORD( info->dwFileVersionMS ),
- HIWORD( info->dwFileVersionLS ),
- LOWORD( info->dwFileVersionLS ) );
+ if (pGetFileVersionInfoA(ModuleName, 0, sizeof(buffer), buffer) &&
+ pVerQueryValueA(buffer, "\\", (LPVOID *)&data, &numBytes) &&
+ numBytes >= sizeof(*info)) {
+ info = (VS_FIXEDFILEINFO *)data;
+ wsprintf(version, "%u.%u.%u.%u",
+ HIWORD(info->dwFileVersionMS),
+ LOWORD(info->dwFileVersionMS),
+ HIWORD(info->dwFileVersionLS),
+ LOWORD(info->dwFileVersionLS));
} else {
- CopyMemory( version, "unknown", 8 );
+ CopyMemory(version, "unknown", 8);
}
moduleInfo.SizeOfStruct = moduleInfoSize;
ret = pSymGetModuleInfo64(
- processHandle,
- ModuleBase,
- &moduleInfo );
- if( ret ) {
+ processHandle,
+ ModuleBase,
+ &moduleInfo);
+ if (ret) {
ModuleName = moduleInfo.ModuleName;
- switch( moduleInfo.SymType ) {
- case SymNone: symbols = "none"; break;
- case SymCoff: symbols = "COFF"; break;
- case SymPdb: symbols = "PDB"; break;
- case SymExport: symbols = "export"; break;
- case SymVirtual: symbols = "virtual"; break;
- default: symbols = "unknown"; break;
+ switch (moduleInfo.SymType) {
+ case SymNone: symbols = "none"; break;
+ case SymCoff: symbols = "COFF"; break;
+ case SymPdb: symbols = "PDB"; break;
+ case SymExport: symbols = "export"; break;
+ case SymVirtual: symbols = "virtual"; break;
+ default: symbols = "unknown"; break;
}
} else {
- write_report( "SymGetModuleInfo64 failed with error %#x\r\n",
- GetLastError() );
+ write_report("SymGetModuleInfo64 failed with error %#x\r\n",
+ GetLastError());
symbols = "failed";
}
- if( pc >= ModuleBase && pc < ModuleBase + ModuleSize ) {
- CopyMemory( faultyModuleName, ModuleName, len + 1 );
+ if (pc >= ModuleBase && pc < ModuleBase + ModuleSize) {
+ CopyMemory(faultyModuleName, ModuleName, len + 1);
star = " *";
} else {
star = "";
@@ -169,8 +169,8 @@ STATIC BOOL CALLBACK enum_modules_callback(
write_report(
"%"PRIxx" %"PRIxx" %s (version %s, symbols %s)%s\r\n",
- WORDxx( ModuleBase ), WORDxx( ModuleBase + ModuleSize ),
- ModuleName, version, symbols, star );
+ WORDxx(ModuleBase), WORDxx(ModuleBase + ModuleSize),
+ ModuleName, version, symbols, star);
return TRUE;
}
@@ -179,7 +179,8 @@ STATIC BOOL CALLBACK enum_modules_callback(
// be careful to avoid using any non-trivial C runtime functions here!
// C runtime structures may be already corrupted and unusable at this point.
-LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
+LONG WINAPI Sys_ExceptionFilter(LPEXCEPTION_POINTERS exceptionInfo)
+{
STACKFRAME64 stackFrame;
PEXCEPTION_RECORD exception;
PCONTEXT context;
@@ -187,7 +188,7 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
SYMBOL_INFO *symbol;
int count, ret, i;
DWORD64 offset;
- BYTE buffer[sizeof( SYMBOL_INFO ) + 256 - 1];
+ BYTE buffer[sizeof(SYMBOL_INFO) + 256 - 1];
IMAGEHLP_MODULE64 moduleInfo;
char path[MAX_PATH];
char execdir[MAX_PATH];
@@ -198,20 +199,20 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
LONG action;
// give previous filter a chance to handle this exception
- if( prevExceptionFilter ) {
- action = prevExceptionFilter( exceptionInfo );
- if( action != EXCEPTION_CONTINUE_SEARCH ) {
+ if (prevExceptionFilter) {
+ action = prevExceptionFilter(exceptionInfo);
+ if (action != EXCEPTION_CONTINUE_SEARCH) {
return action;
}
}
// debugger present? not our business
- if( IsDebuggerPresent() ) {
+ if (IsDebuggerPresent()) {
return EXCEPTION_CONTINUE_SEARCH;
}
// called from different thread? not our business
- if( GetCurrentThread() != mainProcessThread ) {
+ if (GetCurrentThread() != mainProcessThread) {
return EXCEPTION_CONTINUE_SEARCH;
}
@@ -219,121 +220,121 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
Win_Shutdown();
#endif
- ret = MessageBox( NULL,
- PRODUCT " has encountered an unhandled "
- "exception and needs to be terminated.\n"
- "Would you like to generate a crash report?",
- CRASH_TITLE,
- MB_ICONERROR | MB_YESNO
+ ret = MessageBox(NULL,
+ PRODUCT " has encountered an unhandled "
+ "exception and needs to be terminated.\n"
+ "Would you like to generate a crash report?",
+ CRASH_TITLE,
+ MB_ICONERROR | MB_YESNO
#if !USE_CLIENT
- | MB_SERVICE_NOTIFICATION
+ | MB_SERVICE_NOTIFICATION
#endif
- );
- if( ret == IDNO ) {
+ );
+ if (ret == IDNO) {
return EXCEPTION_EXECUTE_HANDLER;
}
-#define LL( x ) \
+#define LL(x) \
do { \
- moduleHandle = LoadLibrary( x ); \
- if( !moduleHandle ) { \
+ moduleHandle = LoadLibrary(x); \
+ if (!moduleHandle) { \
return EXCEPTION_CONTINUE_SEARCH; \
} \
- } while( 0 )
-
-#define GPA( x, y ) \
- do { \
- p ## y = ( x )GetProcAddress( moduleHandle, #y ); \
- if( !p ## y ) { \
- return EXCEPTION_CONTINUE_SEARCH; \
- } \
- } while( 0 )
-
- LL( "dbghelp.dll" );
- GPA( SETSYMOPTIONS, SymSetOptions );
- GPA( SYMGETMODULEINFO64, SymGetModuleInfo64 );
- GPA( SYMCLEANUP, SymCleanup );
- GPA( SYMINITIALIZE, SymInitialize );
- GPA( ENUMERATELOADEDMODULES64, EnumerateLoadedModules64 );
- GPA( STACKWALK64, StackWalk64 );
- GPA( SYMFROMADDR, SymFromAddr );
- GPA( SYMFUNCTIONTABLEACCESS64, SymFunctionTableAccess64 );
- GPA( SYMGETMODULEBASE64, SymGetModuleBase64 );
-
- LL( "version.dll" );
- GPA( GETFILEVERSIONINFOA, GetFileVersionInfoA );
- GPA( VERQUERYVALUEA, VerQueryValueA );
-
- LL( "shell32.dll" );
- GPA( SHELLEXECUTEA, ShellExecuteA );
+ } while(0)
+
+#define GPA(x, y) \
+ do { \
+ p##y = (x)GetProcAddress(moduleHandle, #y); \
+ if (!p##y) { \
+ return EXCEPTION_CONTINUE_SEARCH; \
+ } \
+ } while(0)
+
+ LL("dbghelp.dll");
+ GPA(SETSYMOPTIONS, SymSetOptions);
+ GPA(SYMGETMODULEINFO64, SymGetModuleInfo64);
+ GPA(SYMCLEANUP, SymCleanup);
+ GPA(SYMINITIALIZE, SymInitialize);
+ GPA(ENUMERATELOADEDMODULES64, EnumerateLoadedModules64);
+ GPA(STACKWALK64, StackWalk64);
+ GPA(SYMFROMADDR, SymFromAddr);
+ GPA(SYMFUNCTIONTABLEACCESS64, SymFunctionTableAccess64);
+ GPA(SYMGETMODULEBASE64, SymGetModuleBase64);
+
+ LL("version.dll");
+ GPA(GETFILEVERSIONINFOA, GetFileVersionInfoA);
+ GPA(VERQUERYVALUEA, VerQueryValueA);
+
+ LL("shell32.dll");
+ GPA(SHELLEXECUTEA, ShellExecuteA);
// get base directory to save crash dump to
- len = GetModuleFileName( NULL, execdir, sizeof( execdir ) );
- if( !len || len >= sizeof( execdir ) ) {
+ len = GetModuleFileName(NULL, execdir, sizeof(execdir));
+ if (!len || len >= sizeof(execdir)) {
return EXCEPTION_CONTINUE_SEARCH;
}
- while( --len ) {
- if( execdir[len] == '\\' ) {
+ while (--len) {
+ if (execdir[len] == '\\') {
break;
}
}
- if( !len || len + 24 >= MAX_PATH ) {
+ if (!len || len + 24 >= MAX_PATH) {
return EXCEPTION_CONTINUE_SEARCH;
}
execdir[len] = 0;
- CopyMemory( path, execdir, len );
- CopyMemory( path + len, "\\Q2PRO_CrashReportXX.txt", 25 );
- for( i = 0; i < 100; i++ ) {
- path[len+18] = '0' + i / 10;
- path[len+19] = '0' + i % 10;
+ CopyMemory(path, execdir, len);
+ CopyMemory(path + len, "\\Q2PRO_CrashReportXX.txt", 25);
+ for (i = 0; i < 100; i++) {
+ path[len + 18] = '0' + i / 10;
+ path[len + 19] = '0' + i % 10;
crashReport = CreateFile(
- path,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- CREATE_NEW,
- FILE_ATTRIBUTE_NORMAL,
- NULL );
-
- if( crashReport != INVALID_HANDLE_VALUE ) {
+ path,
+ GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (crashReport != INVALID_HANDLE_VALUE) {
break;
}
- if( GetLastError() != ERROR_FILE_EXISTS ) {
- MessageBox( NULL,
- "Couldn't create crash report. "
- "Base directory is not writable.",
- CRASH_TITLE,
- MB_ICONERROR );
+ if (GetLastError() != ERROR_FILE_EXISTS) {
+ MessageBox(NULL,
+ "Couldn't create crash report. "
+ "Base directory is not writable.",
+ CRASH_TITLE,
+ MB_ICONERROR);
return EXCEPTION_EXECUTE_HANDLER;
}
}
- if( i == 100 ) {
- MessageBox( NULL,
- "Couldn't create crash report. "
- "All report slots are full.\n"
- "Please remove existing reports from base directory.",
- CRASH_TITLE,
- MB_ICONERROR );
+ if (i == 100) {
+ MessageBox(NULL,
+ "Couldn't create crash report. "
+ "All report slots are full.\n"
+ "Please remove existing reports from base directory.",
+ CRASH_TITLE,
+ MB_ICONERROR);
return EXCEPTION_EXECUTE_HANDLER;
}
pSymSetOptions(
SYMOPT_LOAD_ANYTHING |
SYMOPT_DEBUG |
- SYMOPT_FAIL_CRITICAL_ERRORS );
+ SYMOPT_FAIL_CRITICAL_ERRORS);
processHandle = GetCurrentProcess();
threadHandle = GetCurrentThread();
- pSymInitialize( processHandle, execdir, TRUE );
+ pSymInitialize(processHandle, execdir, TRUE);
- GetSystemTime( &systemTime );
+ GetSystemTime(&systemTime);
write_report(
"Crash report generated %s %u %u, %02u:%02u:%02u UTC\r\n",
monthNames[(systemTime.wMonth - 1) % 12],
@@ -341,54 +342,53 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
systemTime.wYear,
systemTime.wHour,
systemTime.wMinute,
- systemTime.wSecond );
+ systemTime.wSecond);
write_report(
"by " APPLICATION " " VERSION
- ", built " __DATE__", " __TIME__ "\r\n" );
+ ", built " __DATE__", " __TIME__ "\r\n");
- vinfo.dwOSVersionInfoSize = sizeof( vinfo );
- if( GetVersionEx( &vinfo ) ) {
+ vinfo.dwOSVersionInfoSize = sizeof(vinfo);
+ if (GetVersionEx(&vinfo)) {
write_report(
"\r\nWindows version: %u.%u (build %u) %s\r\n",
vinfo.dwMajorVersion,
vinfo.dwMinorVersion,
vinfo.dwBuildNumber,
- vinfo.szCSDVersion );
+ vinfo.szCSDVersion);
} else {
- write_report( "GetVersionEx failed with error %#x\r\n",
- GetLastError() );
+ write_report("GetVersionEx failed with error %#x\r\n",
+ GetLastError());
}
// oh no, dbghelp is not backwards and forwards compatible
// why in hell is it different from other windows DLLs?
- for( i = 0; i < 4; i++ ) {
+ for (i = 0; i < 4; i++) {
len = tryModuleSizes[i];
- if( i && len >= sizeof( moduleInfo ) ) {
+ if (i && len >= sizeof(moduleInfo)) {
continue;
}
moduleInfo.SizeOfStruct = len;
- if( pSymGetModuleInfo64(
+ if (pSymGetModuleInfo64(
processHandle,
(DWORD64)((INT_PTR)hGlobalInstance),
- &moduleInfo ) )
- {
+ &moduleInfo)) {
moduleInfoSize = len;
- if( i ) {
+ if (i) {
write_report(
"Module info size is %u (not %u)\r\n",
- len, tryModuleSizes[0] );
+ len, tryModuleSizes[0]);
}
break;
}
}
- if( i == 4 ) {
+ if (i == 4) {
// bad luck
- write_report( "SymGetModuleInfo64 is fucked up :(" );
- moduleInfoSize = sizeof( moduleInfo );
+ write_report("SymGetModuleInfo64 is fucked up :(");
+ moduleInfoSize = sizeof(moduleInfo);
}
- CopyMemory( faultyModuleName, "unknown", 8 );
+ CopyMemory(faultyModuleName, "unknown", 8);
exception = exceptionInfo->ExceptionRecord;
context = exceptionInfo->ContextRecord;
@@ -396,48 +396,48 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
#ifdef _WIN64
pc = context->Rip;
#else
- pc = ( DWORD64 )context->Eip;
+ pc = (DWORD64)context->Eip;
#endif
- write_report( "\r\nLoaded modules:\r\n" );
+ write_report("\r\nLoaded modules:\r\n");
ret = pEnumerateLoadedModules64(
- processHandle,
- enum_modules_callback,
- &pc
- );
- if( !ret ) {
- write_report( "EnumerateLoadedModules64 failed with error %#x\r\n",
- GetLastError() );
+ processHandle,
+ enum_modules_callback,
+ &pc
+ );
+ if (!ret) {
+ write_report("EnumerateLoadedModules64 failed with error %#x\r\n",
+ GetLastError());
}
- write_report( "\r\nException information:\r\n" );
- write_report( "Code: %#08x\r\n", exception->ExceptionCode );
- write_report( "Address: %"PRIxx" (%s)\r\n", WORDxx( pc ), faultyModuleName );
+ write_report("\r\nException information:\r\n");
+ write_report("Code: %#08x\r\n", exception->ExceptionCode);
+ write_report("Address: %"PRIxx" (%s)\r\n", WORDxx(pc), faultyModuleName);
- write_report( "\r\nThread context:\r\n" );
+ write_report("\r\nThread context:\r\n");
#ifdef _WIN64
- write_report( "RIP: %"PRIxx64" RBP: %"PRIxx64" RSP: %"PRIxx64"\r\n",
- context->Rip, context->Rbp, context->Rsp );
- write_report( "RAX: %"PRIxx64" RBX: %"PRIxx64" RCX: %"PRIxx64"\r\n",
- context->Rax, context->Rbx, context->Rcx );
- write_report( "RDX: %"PRIxx64" RSI: %"PRIxx64" RDI: %"PRIxx64"\r\n",
- context->Rdx, context->Rsi, context->Rdi );
- write_report( "R8 : %"PRIxx64" R9 : %"PRIxx64" R10: %"PRIxx64"\r\n",
- context->R8, context->R9, context->R10 );
- write_report( "R11: %"PRIxx64" R12: %"PRIxx64" R13: %"PRIxx64"\r\n",
- context->R11, context->R12, context->R13 );
- write_report( "R14: %"PRIxx64" R15: %"PRIxx64"\r\n",
- context->R14, context->R15 );
+ write_report("RIP: %"PRIxx64" RBP: %"PRIxx64" RSP: %"PRIxx64"\r\n",
+ context->Rip, context->Rbp, context->Rsp);
+ write_report("RAX: %"PRIxx64" RBX: %"PRIxx64" RCX: %"PRIxx64"\r\n",
+ context->Rax, context->Rbx, context->Rcx);
+ write_report("RDX: %"PRIxx64" RSI: %"PRIxx64" RDI: %"PRIxx64"\r\n",
+ context->Rdx, context->Rsi, context->Rdi);
+ write_report("R8 : %"PRIxx64" R9 : %"PRIxx64" R10: %"PRIxx64"\r\n",
+ context->R8, context->R9, context->R10);
+ write_report("R11: %"PRIxx64" R12: %"PRIxx64" R13: %"PRIxx64"\r\n",
+ context->R11, context->R12, context->R13);
+ write_report("R14: %"PRIxx64" R15: %"PRIxx64"\r\n",
+ context->R14, context->R15);
#else
- write_report( "EIP: %"PRIxx32" EBP: %"PRIxx32" ESP: %"PRIxx32"\r\n",
- context->Eip, context->Ebp, context->Esp );
- write_report( "EAX: %"PRIxx32" EBX: %"PRIxx32" ECX: %"PRIxx32"\r\n",
- context->Eax, context->Ebx, context->Ecx );
- write_report( "EDX: %"PRIxx32" ESI: %"PRIxx32" EDI: %"PRIxx32"\r\n",
- context->Edx, context->Esi, context->Edi );
+ write_report("EIP: %"PRIxx32" EBP: %"PRIxx32" ESP: %"PRIxx32"\r\n",
+ context->Eip, context->Ebp, context->Esp);
+ write_report("EAX: %"PRIxx32" EBX: %"PRIxx32" ECX: %"PRIxx32"\r\n",
+ context->Eax, context->Ebx, context->Ecx);
+ write_report("EDX: %"PRIxx32" ESI: %"PRIxx32" EDI: %"PRIxx32"\r\n",
+ context->Edx, context->Esi, context->Edi);
#endif
- ZeroMemory( &stackFrame, sizeof( stackFrame ) );
+ ZeroMemory(&stackFrame, sizeof(stackFrame));
#ifdef _WIN64
stackFrame.AddrPC.Offset = context->Rip;
stackFrame.AddrFrame.Offset = context->Rbp;
@@ -449,71 +449,68 @@ LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS exceptionInfo ) {
#endif
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrFrame.Mode = AddrModeFlat;
- stackFrame.AddrStack.Mode = AddrModeFlat;
+ stackFrame.AddrStack.Mode = AddrModeFlat;
- write_report( "\r\nStack trace:\r\n" );
+ write_report("\r\nStack trace:\r\n");
count = 0;
- symbol = ( SYMBOL_INFO * )buffer;
- symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
+ symbol = (SYMBOL_INFO *)buffer;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = 256;
- while( pStackWalk64(
+ while (pStackWalk64(
#ifdef _WIN64
- IMAGE_FILE_MACHINE_AMD64,
+ IMAGE_FILE_MACHINE_AMD64,
#else
- IMAGE_FILE_MACHINE_I386,
+ IMAGE_FILE_MACHINE_I386,
#endif
- processHandle,
- threadHandle,
- &stackFrame,
- context,
- NULL,
- pSymFunctionTableAccess64,
- pSymGetModuleBase64,
- NULL ) )
- {
+ processHandle,
+ threadHandle,
+ &stackFrame,
+ context,
+ NULL,
+ pSymFunctionTableAccess64,
+ pSymGetModuleBase64,
+ NULL)) {
write_report(
"%d: %"PRIxx" %"PRIxx" %"PRIxx" %"PRIxx" ",
count,
- WORDxx( stackFrame.Params[0] ),
- WORDxx( stackFrame.Params[1] ),
- WORDxx( stackFrame.Params[2] ),
- WORDxx( stackFrame.Params[3] ) );
+ WORDxx(stackFrame.Params[0]),
+ WORDxx(stackFrame.Params[1]),
+ WORDxx(stackFrame.Params[2]),
+ WORDxx(stackFrame.Params[3]));
moduleInfo.SizeOfStruct = moduleInfoSize;
- if( pSymGetModuleInfo64(
+ if (pSymGetModuleInfo64(
processHandle,
stackFrame.AddrPC.Offset,
- &moduleInfo ) )
- {
- if( moduleInfo.SymType != SymNone &&
+ &moduleInfo)) {
+ if (moduleInfo.SymType != SymNone &&
moduleInfo.SymType != SymExport &&
pSymFromAddr(
processHandle,
stackFrame.AddrPC.Offset,
&offset,
- symbol ) )
- {
- write_report( "%s!%s+%"PRIxx32"\r\n",
- moduleInfo.ModuleName,
- symbol->Name, (DWORD32)offset );
+ symbol)) {
+ write_report("%s!%s+%"PRIxx32"\r\n",
+ moduleInfo.ModuleName,
+ symbol->Name, (DWORD32)offset);
} else {
- write_report( "%s!%"PRIxx"\r\n",
- moduleInfo.ModuleName,
- WORDxx( stackFrame.AddrPC.Offset ) );
+ write_report("%s!%"PRIxx"\r\n",
+ moduleInfo.ModuleName,
+ WORDxx(stackFrame.AddrPC.Offset));
}
} else {
- write_report( "%"PRIxx"\r\n",
- WORDxx( stackFrame.AddrPC.Offset ) );
+ write_report("%"PRIxx"\r\n",
+ WORDxx(stackFrame.AddrPC.Offset));
}
count++;
}
- CloseHandle( crashReport );
+ CloseHandle(crashReport);
- pSymCleanup( processHandle );
+ pSymCleanup(processHandle);
- pShellExecuteA( NULL, "open", path, NULL, execdir, SW_SHOW );
+ pShellExecuteA(NULL, "open", path, NULL, execdir, SW_SHOW);
return EXCEPTION_EXECUTE_HANDLER;
}
diff --git a/src/win_glimp.c b/src/win_glimp.c
index d7c2069..f006736 100644
--- a/src/win_glimp.c
+++ b/src/win_glimp.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -50,32 +50,34 @@ subsystem. Under OpenGL this means NULLing out the current DC and
HGLRC, deleting the rendering context, and releasing the DC acquired
for the window. The state structure is also nulled out.
*/
-void VID_Shutdown( void ) {
- if( qwglMakeCurrent ) {
- qwglMakeCurrent( NULL, NULL );
+void VID_Shutdown(void)
+{
+ if (qwglMakeCurrent) {
+ qwglMakeCurrent(NULL, NULL);
}
- if( glw.hGLRC && qwglDeleteContext ) {
- qwglDeleteContext( glw.hGLRC );
+ if (glw.hGLRC && qwglDeleteContext) {
+ qwglDeleteContext(glw.hGLRC);
glw.hGLRC = NULL;
}
WGL_Shutdown();
Win_Shutdown();
- if( gl_swapinterval ) {
+ if (gl_swapinterval) {
gl_swapinterval->changed = NULL;
}
- if( gl_drawbuffer ) {
+ if (gl_drawbuffer) {
gl_drawbuffer->changed = NULL;
}
- memset( &glw, 0, sizeof( glw ) );
+ memset(&glw, 0, sizeof(glw));
}
-static qboolean InitGL( void ) {
+static qboolean InitGL(void)
+{
PIXELFORMATDESCRIPTOR pfd = {
- sizeof( PIXELFORMATDESCRIPTOR ), // size of this pfd
+ sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
@@ -87,7 +89,7 @@ static qboolean InitGL( void ) {
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
- 32, // 32-bit z-buffer
+ 32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
@@ -98,93 +100,92 @@ static qboolean InitGL( void ) {
const char *what;
// figure out if we're running on a minidriver or not
- if( !Q_stristr( gl_driver->string, "opengl32" ) ) {
- Com_Printf( "...running a minidriver: %s\n", gl_driver->string );
+ if (!Q_stristr(gl_driver->string, "opengl32")) {
+ Com_Printf("...running a minidriver: %s\n", gl_driver->string);
glw.minidriver = qtrue;
} else {
glw.minidriver = qfalse;
}
// load OpenGL library
- if( !WGL_Init( gl_driver->string ) ) {
+ if (!WGL_Init(gl_driver->string)) {
what = "WGL_Init";
goto fail1;
}
// set pixel format
- if( glw.minidriver ) {
+ if (glw.minidriver) {
// check if certain entry points are present if using a minidriver
- if( !qwglChoosePixelFormat || !qwglSetPixelFormat ||
- !qwglDescribePixelFormat || !qwglSwapBuffers )
- {
- Com_EPrintf( "Required MCD entry points are missing\n" );
+ if (!qwglChoosePixelFormat || !qwglSetPixelFormat ||
+ !qwglDescribePixelFormat || !qwglSwapBuffers) {
+ Com_EPrintf("Required MCD entry points are missing\n");
goto fail2;
}
- if ( ( pixelformat = qwglChoosePixelFormat( win.dc, &pfd ) ) == 0 ) {
+ if ((pixelformat = qwglChoosePixelFormat(win.dc, &pfd)) == 0) {
what = "wglChoosePixelFormat";
goto fail1;
}
- if( qwglSetPixelFormat( win.dc, pixelformat, &pfd ) == FALSE ) {
+ if (qwglSetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) {
what = "wglSetPixelFormat";
goto fail1;
}
- qwglDescribePixelFormat( win.dc, pixelformat, sizeof( pfd ), &pfd );
+ qwglDescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd);
} else {
- if( ( pixelformat = ChoosePixelFormat( win.dc, &pfd ) ) == 0 ) {
+ if ((pixelformat = ChoosePixelFormat(win.dc, &pfd)) == 0) {
what = "ChoosePixelFormat";
goto fail1;
}
- if( SetPixelFormat( win.dc, pixelformat, &pfd ) == FALSE ) {
+ if (SetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) {
what = "SetPixelFormat";
goto fail1;
}
- DescribePixelFormat( win.dc, pixelformat, sizeof( pfd ), &pfd );
+ DescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd);
}
// check for software emulation
- if( pfd.dwFlags & PFD_GENERIC_FORMAT ) {
- if( !gl_allow_software->integer ) {
- Com_EPrintf( "No hardware OpenGL acceleration detected\n" );
+ if (pfd.dwFlags & PFD_GENERIC_FORMAT) {
+ if (!gl_allow_software->integer) {
+ Com_EPrintf("No hardware OpenGL acceleration detected\n");
goto fail2;
}
- Com_WPrintf( "...using software emulation\n" );
- } else if( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) {
- Com_DPrintf( "...MCD acceleration found\n" );
+ Com_WPrintf("...using software emulation\n");
+ } else if (pfd.dwFlags & PFD_GENERIC_ACCELERATED) {
+ Com_DPrintf("...MCD acceleration found\n");
win.flags |= QVF_ACCELERATED;
} else {
- Com_DPrintf( "...ICD acceleration found\n" );
+ Com_DPrintf("...ICD acceleration found\n");
win.flags |= QVF_ACCELERATED;
}
// startup the OpenGL subsystem by creating a context and making it current
- if( ( glw.hGLRC = qwglCreateContext( win.dc ) ) == NULL ) {
+ if ((glw.hGLRC = qwglCreateContext(win.dc)) == NULL) {
what = "wglCreateContext";
goto fail1;
}
- if( !qwglMakeCurrent( win.dc, glw.hGLRC ) ) {
+ if (!qwglMakeCurrent(win.dc, glw.hGLRC)) {
what = "wglMakeCurrent";
goto fail1;
}
// print out PFD specifics
- Com_DPrintf( "GL_VENDOR: %s\n", qwglGetString( GL_VENDOR ) );
- Com_DPrintf( "GL_RENDERER: %s\n", qwglGetString( GL_RENDERER ) );
- Com_DPrintf( "GL_PFD: color(%d-bits: %d,%d,%d,%d) Z(%d-bit) stencil(%d-bit)\n",
- pfd.cColorBits, pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits,
- pfd.cAlphaBits, pfd.cDepthBits, pfd.cStencilBits );
+ Com_DPrintf("GL_VENDOR: %s\n", qwglGetString(GL_VENDOR));
+ Com_DPrintf("GL_RENDERER: %s\n", qwglGetString(GL_RENDERER));
+ Com_DPrintf("GL_PFD: color(%d-bits: %d,%d,%d,%d) Z(%d-bit) stencil(%d-bit)\n",
+ pfd.cColorBits, pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits,
+ pfd.cAlphaBits, pfd.cDepthBits, pfd.cStencilBits);
return qtrue;
fail1:
- Com_EPrintf( "%s failed with error %#lx\n", what, GetLastError() );
- if( glw.hGLRC && qwglDeleteContext ) {
- qwglDeleteContext( glw.hGLRC );
+ Com_EPrintf("%s failed with error %#lx\n", what, GetLastError());
+ if (glw.hGLRC && qwglDeleteContext) {
+ qwglDeleteContext(glw.hGLRC);
glw.hGLRC = NULL;
}
@@ -193,23 +194,25 @@ fail2:
return qfalse;
}
-static void gl_swapinterval_changed( cvar_t *self ) {
- if( qwglSwapIntervalEXT ) {
- qwglSwapIntervalEXT( self->integer );
+static void gl_swapinterval_changed(cvar_t *self)
+{
+ if (qwglSwapIntervalEXT) {
+ qwglSwapIntervalEXT(self->integer);
}
}
-static void gl_drawbuffer_changed( cvar_t *self ) {
- if( !Q_stricmp( self->string, "GL_FRONT" ) ) {
+static void gl_drawbuffer_changed(cvar_t *self)
+{
+ if (!Q_stricmp(self->string, "GL_FRONT")) {
glw.drawbuffer = GL_FRONT;
- } else if( !Q_stricmp( self->string, "GL_BACK" ) ) {
+ } else if (!Q_stricmp(self->string, "GL_BACK")) {
glw.drawbuffer = GL_BACK;
} else {
- Cvar_Reset( self );
+ Cvar_Reset(self);
glw.drawbuffer = GL_BACK;
}
- qwglDrawBuffer( glw.drawbuffer );
+ qwglDrawBuffer(glw.drawbuffer);
}
/*
@@ -219,21 +222,22 @@ This routine is responsible for initializing the OS specific portions
of OpenGL. Under Win32 this means dealing with the pixelformats and
doing the wgl interface stuff.
*/
-qboolean VID_Init( void ) {
+qboolean VID_Init(void)
+{
const char *extensions;
unsigned mask;
- gl_driver = Cvar_Get( "gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_ARCHIVE|CVAR_REFRESH );
- gl_drawbuffer = Cvar_Get( "gl_drawbuffer", "GL_BACK", 0 );
- gl_swapinterval = Cvar_Get( "gl_swapinterval", "1", CVAR_ARCHIVE );
- gl_allow_software = Cvar_Get( "gl_allow_software", "0", 0 );
+ gl_driver = Cvar_Get("gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_ARCHIVE | CVAR_REFRESH);
+ gl_drawbuffer = Cvar_Get("gl_drawbuffer", "GL_BACK", 0);
+ gl_swapinterval = Cvar_Get("gl_swapinterval", "1", CVAR_ARCHIVE);
+ gl_allow_software = Cvar_Get("gl_allow_software", "0", 0);
- while( 1 ) {
+ while (1) {
// create the window
Win_Init();
// initialize OpenGL context
- if( InitGL() ) {
+ if (InitGL()) {
break;
}
@@ -241,44 +245,47 @@ qboolean VID_Init( void ) {
Win_Shutdown();
// see if this was a minidriver
- if( !glw.minidriver ) {
+ if (!glw.minidriver) {
return qfalse;
}
// attempt to recover
- Com_Printf( "...attempting to load opengl32\n" );
- Cvar_Set( "gl_driver", "opengl32" );
+ Com_Printf("...attempting to load opengl32\n");
+ Cvar_Set("gl_driver", "opengl32");
}
// initialize WGL extensions
- extensions = ( const char * )qwglGetString( GL_EXTENSIONS );
- mask = WGL_ParseExtensionString( extensions );
+ extensions = (const char *)qwglGetString(GL_EXTENSIONS);
+ mask = WGL_ParseExtensionString(extensions);
- if( mask & QWGL_EXT_swap_control ) {
- Com_Printf( "...enabling WGL_EXT_swap_control\n" );
- WGL_InitExtensions( QWGL_EXT_swap_control );
+ if (mask & QWGL_EXT_swap_control) {
+ Com_Printf("...enabling WGL_EXT_swap_control\n");
+ WGL_InitExtensions(QWGL_EXT_swap_control);
gl_swapinterval->changed = gl_swapinterval_changed;
- gl_swapinterval_changed( gl_swapinterval );
+ gl_swapinterval_changed(gl_swapinterval);
} else {
- Com_Printf( "WGL_EXT_swap_control not found\n" );
+ Com_Printf("WGL_EXT_swap_control not found\n");
}
gl_drawbuffer->changed = gl_drawbuffer_changed;
- gl_drawbuffer_changed( gl_drawbuffer );
+ gl_drawbuffer_changed(gl_drawbuffer);
VID_SetMode();
return qtrue;
}
-void VID_VideoWait( void ) {
+void VID_VideoWait(void)
+{
}
-qboolean VID_VideoSync( void ) {
+qboolean VID_VideoSync(void)
+{
return qtrue;
}
-void VID_BeginFrame( void ) {
+void VID_BeginFrame(void)
+{
}
/*
@@ -288,32 +295,34 @@ Responsible for doing a swapbuffers and possibly for other stuff
as yet to be determined. Probably better not to make this a GLimp
function and instead do a call to GLimp_SwapBuffers.
*/
-void VID_EndFrame( void ) {
+void VID_EndFrame(void)
+{
BOOL ret;
// don't flip if drawing to front buffer
- if( glw.drawbuffer == GL_FRONT ) {
+ if (glw.drawbuffer == GL_FRONT) {
return;
}
- if( glw.minidriver ) {
- ret = qwglSwapBuffers( win.dc );
+ if (glw.minidriver) {
+ ret = qwglSwapBuffers(win.dc);
} else {
- ret = SwapBuffers( win.dc );
+ ret = SwapBuffers(win.dc);
}
- if( !ret ) {
+ if (!ret) {
DWORD error = GetLastError();
// this happens sometimes when the window is iconified
- if( !IsIconic( win.wnd ) ) {
- Com_Error( ERR_FATAL, "%s failed with error %#lx",
- glw.minidriver ? "wglSwapBuffers" : "SwapBuffers", error );
+ if (!IsIconic(win.wnd)) {
+ Com_Error(ERR_FATAL, "%s failed with error %#lx",
+ glw.minidriver ? "wglSwapBuffers" : "SwapBuffers", error);
}
}
}
-void *VID_GetProcAddr( const char *symbol ) {
- return ( void * )GetProcAddress( glw.hinstOpenGL, symbol );
+void *VID_GetProcAddr(const char *symbol)
+{
+ return (void *)GetProcAddress(glw.hinstOpenGL, symbol);
}
diff --git a/src/win_glimp.h b/src/win_glimp.h
index 34f363d..47065c0 100644
--- a/src/win_glimp.h
+++ b/src/win_glimp.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
diff --git a/src/win_local.h b/src/win_local.h
index 5b60d65..24b5bcd 100644
--- a/src/win_local.h
+++ b/src/win_local.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -112,10 +112,10 @@ typedef struct {
extern win_state_t win;
-void Win_Init( void );
-void Win_Shutdown( void );
-void Win_SetMode( void );
-void Win_ModeChanged( void );
+void Win_Init(void);
+void Win_Shutdown(void);
+void Win_SetMode(void);
+void Win_ModeChanged(void);
#endif // USE_CLIENT
@@ -125,6 +125,6 @@ extern HINSTANCE hGlobalInstance;
extern HANDLE mainProcessThread;
extern LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter;
-LONG WINAPI Sys_ExceptionFilter( LPEXCEPTION_POINTERS );
+LONG WINAPI Sys_ExceptionFilter(LPEXCEPTION_POINTERS);
#endif
diff --git a/src/win_swimp.c b/src/win_swimp.c
index e738d46..c73a8a8 100644
--- a/src/win_swimp.c
+++ b/src/win_swimp.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -49,29 +49,29 @@ typedef struct {
} identitypalette_t;
static const int s_syspalindices[] = {
- COLOR_ACTIVEBORDER,
- COLOR_ACTIVECAPTION,
- COLOR_APPWORKSPACE,
- COLOR_BACKGROUND,
- COLOR_BTNFACE,
- COLOR_BTNSHADOW,
- COLOR_BTNTEXT,
- COLOR_CAPTIONTEXT,
- COLOR_GRAYTEXT,
- COLOR_HIGHLIGHT,
- COLOR_HIGHLIGHTTEXT,
- COLOR_INACTIVEBORDER,
-
- COLOR_INACTIVECAPTION,
- COLOR_MENU,
- COLOR_MENUTEXT,
- COLOR_SCROLLBAR,
- COLOR_WINDOW,
- COLOR_WINDOWFRAME,
- COLOR_WINDOWTEXT
+ COLOR_ACTIVEBORDER,
+ COLOR_ACTIVECAPTION,
+ COLOR_APPWORKSPACE,
+ COLOR_BACKGROUND,
+ COLOR_BTNFACE,
+ COLOR_BTNSHADOW,
+ COLOR_BTNTEXT,
+ COLOR_CAPTIONTEXT,
+ COLOR_GRAYTEXT,
+ COLOR_HIGHLIGHT,
+ COLOR_HIGHLIGHTTEXT,
+ COLOR_INACTIVEBORDER,
+
+ COLOR_INACTIVECAPTION,
+ COLOR_MENU,
+ COLOR_MENUTEXT,
+ COLOR_SCROLLBAR,
+ COLOR_WINDOW,
+ COLOR_WINDOWFRAME,
+ COLOR_WINDOWTEXT
};
-#define NUM_SYS_COLORS ( sizeof( s_syspalindices ) / sizeof( int ) )
+#define NUM_SYS_COLORS (sizeof(s_syspalindices) / sizeof(s_syspalindices[0]))
typedef struct {
HDC dibdc; // DC compatible with DIB section
@@ -94,53 +94,55 @@ SWimp_Shutdown
System specific graphics subsystem shutdown routine.
Destroys DIB surfaces as appropriate.
*/
-void VID_Shutdown( void ) {
- if ( sww.palettized ) {
- SetSystemPaletteUse( win.dc, SYSPAL_STATIC );
- SetSysColors( NUM_SYS_COLORS, s_syspalindices, sww.oldsyscolors );
+void VID_Shutdown(void)
+{
+ if (sww.palettized) {
+ SetSystemPaletteUse(win.dc, SYSPAL_STATIC);
+ SetSysColors(NUM_SYS_COLORS, s_syspalindices, sww.oldsyscolors);
}
- if( sww.pal ) {
- DeleteObject( sww.pal );
+ if (sww.pal) {
+ DeleteObject(sww.pal);
}
- if( sww.oldpal ) {
- SelectPalette( win.dc, sww.oldpal, FALSE );
- RealizePalette( win.dc );
+ if (sww.oldpal) {
+ SelectPalette(win.dc, sww.oldpal, FALSE);
+ RealizePalette(win.dc);
}
- if( sww.dibdc ) {
- SelectObject( sww.dibdc, sww.prevobj );
- DeleteDC( sww.dibdc );
+ if (sww.dibdc) {
+ SelectObject(sww.dibdc, sww.prevobj);
+ DeleteDC(sww.dibdc);
}
- if( sww.dibsect ) {
- DeleteObject( sww.dibsect );
+ if (sww.dibsect) {
+ DeleteObject(sww.dibsect);
}
- memset( &sww, 0, sizeof( sww ) );
+ memset(&sww, 0, sizeof(sww));
Win_Shutdown();
}
-void SWimp_ModeChanged( void ) {
+void SWimp_ModeChanged(void)
+{
dibinfo_t info;
- BITMAPINFO *pbmiDIB = ( BITMAPINFO * )&info;
+ BITMAPINFO *pbmiDIB = (BITMAPINFO *)&info;
- if( !sww.dibdc ) {
+ if (!sww.dibdc) {
return;
}
// destroy previous DIB section
- if( sww.dibsect ) {
- SelectObject( sww.dibdc, sww.prevobj );
- DeleteObject( sww.dibsect );
+ if (sww.dibsect) {
+ SelectObject(sww.dibdc, sww.prevobj);
+ DeleteObject(sww.dibsect);
}
// fill in the BITMAPINFO struct
- memset( pbmiDIB, 0, sizeof( dibinfo_t ) );
+ memset(pbmiDIB, 0, sizeof(dibinfo_t));
- pbmiDIB->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
+ pbmiDIB->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmiDIB->bmiHeader.biWidth = win.rc.width;
pbmiDIB->bmiHeader.biHeight = win.rc.height;
pbmiDIB->bmiHeader.biPlanes = 1;
@@ -150,20 +152,20 @@ void SWimp_ModeChanged( void ) {
pbmiDIB->bmiHeader.biClrImportant = 256;
// create the DIB section
- sww.dibsect = CreateDIBSection( win.dc,
- pbmiDIB,
- DIB_RGB_COLORS,
- ( void ** )&sww.pixels,
- NULL,
- 0 );
-
- if ( !sww.dibsect ) {
- Com_Error( ERR_FATAL, "DIB_Init: CreateDIBSection failed" );
+ sww.dibsect = CreateDIBSection(win.dc,
+ pbmiDIB,
+ DIB_RGB_COLORS,
+ (void **)&sww.pixels,
+ NULL,
+ 0);
+
+ if (!sww.dibsect) {
+ Com_Error(ERR_FATAL, "DIB_Init: CreateDIBSection failed");
}
- if ( pbmiDIB->bmiHeader.biHeight > 0 ) {
+ if (pbmiDIB->bmiHeader.biHeight > 0) {
// bottom up
- win.buffer = sww.pixels + ( win.rc.height - 1 ) * win.rc.width;
+ win.buffer = sww.pixels + (win.rc.height - 1) * win.rc.width;
win.pitch = -win.rc.width;
} else {
// top down
@@ -172,11 +174,11 @@ void SWimp_ModeChanged( void ) {
}
// clear the DIB memory buffer
- memset( sww.pixels, 0xff, win.rc.width * win.rc.height );
+ memset(sww.pixels, 0xff, win.rc.width * win.rc.height);
- sww.prevobj = SelectObject( sww.dibdc, sww.dibsect );
- if( !sww.prevobj ) {
- Com_Error( ERR_FATAL, "DIB_Init: SelectObject failed\n" );
+ sww.prevobj = SelectObject(sww.dibdc, sww.dibsect);
+ if (!sww.prevobj) {
+ Com_Error(ERR_FATAL, "DIB_Init: SelectObject failed\n");
}
}
@@ -187,7 +189,8 @@ SWimp_Init
This routine is responsible for initializing the implementation
specific stuff in a software rendering subsystem.
*/
-qboolean VID_Init( void ) {
+qboolean VID_Init(void)
+{
int i;
// create the window
@@ -197,18 +200,18 @@ qboolean VID_Init( void ) {
Win_SetMode();
// figure out if we're running in an 8-bit display mode
- if ( GetDeviceCaps( win.dc, RASTERCAPS ) & RC_PALETTE ) {
+ if (GetDeviceCaps(win.dc, RASTERCAPS) & RC_PALETTE) {
sww.palettized = qtrue;
- for ( i = 0; i < NUM_SYS_COLORS; i++ )
- sww.oldsyscolors[i] = GetSysColor( s_syspalindices[i] );
+ for (i = 0; i < NUM_SYS_COLORS; i++)
+ sww.oldsyscolors[i] = GetSysColor(s_syspalindices[i]);
} else {
sww.palettized = qfalse;
}
// create logical DC
- sww.dibdc = CreateCompatibleDC( win.dc );
- if( !sww.dibdc ) {
- Com_EPrintf( "DIB_Init: CreateCompatibleDC failed\n" );
+ sww.dibdc = CreateCompatibleDC(win.dc);
+ if (!sww.dibdc) {
+ Com_EPrintf("DIB_Init: CreateCompatibleDC failed\n");
goto fail;
}
@@ -218,19 +221,22 @@ qboolean VID_Init( void ) {
return qtrue;
fail:
- Com_Printf( "GetLastError() = %#lx", GetLastError() );
+ Com_Printf("GetLastError() = %#lx", GetLastError());
VID_Shutdown();
return qfalse;
}
-void VID_VideoWait( void ) {
+void VID_VideoWait(void)
+{
}
-qboolean VID_VideoSync( void ) {
+qboolean VID_VideoSync(void)
+{
return qtrue;
}
-void VID_BeginFrame( void ) {
+void VID_BeginFrame(void)
+{
}
/*
@@ -239,8 +245,9 @@ SWimp_EndFrame
This does an implementation specific copy from the backbuffer to the
front buffer. In the Win32 case it uses BitBlt if we're using DIB sections/GDI.
*/
-void VID_EndFrame( void ) {
- BitBlt( win.dc, 0, 0, win.rc.width, win.rc.height, sww.dibdc, 0, 0, SRCCOPY );
+void VID_EndFrame(void)
+{
+ BitBlt(win.dc, 0, 0, win.rc.width, win.rc.height, sww.dibdc, 0, 0, SRCCOPY);
}
/*
@@ -256,14 +263,15 @@ G = offset 1
B = offset 2
A = offset 3
*/
-void VID_UpdatePalette( const byte *_pal ) {
+void VID_UpdatePalette(const byte *_pal)
+{
const byte *pal = _pal;
RGBQUAD colors[256];
int i;
// set the DIB color table
- if ( sww.dibdc ) {
- for ( i = 0; i < 256; i++, pal += 4 ) {
+ if (sww.dibdc) {
+ for (i = 0; i < 256; i++, pal += 4) {
colors[i].rgbRed = pal[0];
colors[i].rgbGreen = pal[1];
colors[i].rgbBlue = pal[2];
@@ -278,26 +286,26 @@ void VID_UpdatePalette( const byte *_pal ) {
colors[255].rgbGreen = 0xff;
colors[255].rgbBlue = 0xff;
- if ( SetDIBColorTable( sww.dibdc, 0, 256, colors ) == 0 ) {
- Com_EPrintf( "DIB_SetPalette: SetDIBColorTable failed\n" );
+ if (SetDIBColorTable(sww.dibdc, 0, 256, colors) == 0) {
+ Com_EPrintf("DIB_SetPalette: SetDIBColorTable failed\n");
}
}
// for 8-bit color desktop modes we set up the palette for maximum
// speed by going into an identity palette mode.
- if ( sww.palettized ) {
+ if (sww.palettized) {
int ret;
HPALETTE hpalOld;
identitypalette_t ipal;
- LOGPALETTE *pLogPal = ( LOGPALETTE * )&ipal;
+ LOGPALETTE *pLogPal = (LOGPALETTE *)&ipal;
- if ( SetSystemPaletteUse( win.dc, SYSPAL_NOSTATIC ) == SYSPAL_ERROR ) {
- Com_Error( ERR_FATAL, "DIB_SetPalette: SetSystemPaletteUse() failed\n" );
+ if (SetSystemPaletteUse(win.dc, SYSPAL_NOSTATIC) == SYSPAL_ERROR) {
+ Com_Error(ERR_FATAL, "DIB_SetPalette: SetSystemPaletteUse() failed\n");
}
// destroy our old palette
- if ( sww.pal ) {
- DeleteObject( sww.pal );
+ if (sww.pal) {
+ DeleteObject(sww.pal);
sww.pal = 0;
}
@@ -306,7 +314,7 @@ void VID_UpdatePalette( const byte *_pal ) {
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = 256;
- for ( i = 0, pal = _pal; i < 256; i++, pal += 4 ) {
+ for (i = 0, pal = _pal; i < 256; i++, pal += 4) {
pLogPal->palPalEntry[i].peRed = pal[0];
pLogPal->palPalEntry[i].peGreen = pal[1];
pLogPal->palPalEntry[i].peBlue = pal[2];
@@ -321,19 +329,19 @@ void VID_UpdatePalette( const byte *_pal ) {
pLogPal->palPalEntry[255].peBlue = 0xff;
pLogPal->palPalEntry[255].peFlags = 0;
- if ( ( sww.pal = CreatePalette( pLogPal ) ) == NULL ) {
- Com_Error( ERR_FATAL, "DIB_SetPalette: CreatePalette failed(%lx)\n", GetLastError() );
+ if ((sww.pal = CreatePalette(pLogPal)) == NULL) {
+ Com_Error(ERR_FATAL, "DIB_SetPalette: CreatePalette failed(%lx)\n", GetLastError());
}
- if ( ( hpalOld = SelectPalette( win.dc, sww.pal, FALSE ) ) == NULL ) {
- Com_Error( ERR_FATAL, "DIB_SetPalette: SelectPalette failed(%lx)\n", GetLastError() );
+ if ((hpalOld = SelectPalette(win.dc, sww.pal, FALSE)) == NULL) {
+ Com_Error(ERR_FATAL, "DIB_SetPalette: SelectPalette failed(%lx)\n", GetLastError());
}
- if ( sww.oldpal == NULL )
+ if (sww.oldpal == NULL)
sww.oldpal = hpalOld;
- if ( ( ret = RealizePalette( win.dc ) ) != pLogPal->palNumEntries ) {
- Com_Error( ERR_FATAL, "DIB_SetPalette: RealizePalette set %d entries\n", ret );
+ if ((ret = RealizePalette(win.dc)) != pLogPal->palNumEntries) {
+ Com_Error(ERR_FATAL, "DIB_SetPalette: RealizePalette set %d entries\n", ret);
}
}
}
diff --git a/src/win_wgl.c b/src/win_wgl.c
index f165350..61d4084 100644
--- a/src/win_wgl.c
+++ b/src/win_wgl.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -21,24 +21,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "win_glimp.h"
#include "win_wgl.h"
-void ( APIENTRY * qwglDrawBuffer )(GLenum mode);
-const GLubyte * ( APIENTRY * qwglGetString )(GLenum name);
+void (APIENTRY * qwglDrawBuffer)(GLenum mode);
+const GLubyte * (APIENTRY * qwglGetString)(GLenum name);
-int ( WINAPI * qwglChoosePixelFormat )(HDC, CONST PIXELFORMATDESCRIPTOR *);
-int ( WINAPI * qwglDescribePixelFormat )(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
-BOOL ( WINAPI * qwglSetPixelFormat )(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
-BOOL ( WINAPI * qwglSwapBuffers )(HDC);
+int (WINAPI * qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
+int (WINAPI * qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
+BOOL (WINAPI * qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
+BOOL (WINAPI * qwglSwapBuffers)(HDC);
-HGLRC ( WINAPI * qwglCreateContext )(HDC);
-BOOL ( WINAPI * qwglDeleteContext )(HGLRC);
-PROC ( WINAPI * qwglGetProcAddress )(LPCSTR);
-BOOL ( WINAPI * qwglMakeCurrent )(HDC, HGLRC);
+HGLRC (WINAPI * qwglCreateContext)(HDC);
+BOOL (WINAPI * qwglDeleteContext)(HGLRC);
+PROC (WINAPI * qwglGetProcAddress)(LPCSTR);
+BOOL (WINAPI * qwglMakeCurrent)(HDC, HGLRC);
-BOOL ( WINAPI * qwglSwapIntervalEXT )(int interval);
+BOOL (WINAPI * qwglSwapIntervalEXT)(int interval);
-void WGL_Shutdown( void ) {
- if( glw.hinstOpenGL ) {
- FreeLibrary( glw.hinstOpenGL );
+void WGL_Shutdown(void)
+{
+ if (glw.hinstOpenGL) {
+ FreeLibrary(glw.hinstOpenGL);
glw.hinstOpenGL = NULL;
}
@@ -55,57 +56,61 @@ void WGL_Shutdown( void ) {
qwglGetProcAddress = NULL;
qwglMakeCurrent = NULL;
- WGL_ShutdownExtensions( ~0 );
+ WGL_ShutdownExtensions(~0);
}
-#define GPA( x ) ( void * )GetProcAddress( glw.hinstOpenGL, x );
+#define GPA(x) (void *)GetProcAddress(glw.hinstOpenGL, x);
-qboolean WGL_Init( const char *dllname ) {
- if( ( glw.hinstOpenGL = LoadLibrary( dllname ) ) == NULL ) {
+qboolean WGL_Init(const char *dllname)
+{
+ if ((glw.hinstOpenGL = LoadLibrary(dllname)) == NULL) {
return qfalse;
}
- qwglDrawBuffer = GPA( "glDrawBuffer" );
- qwglGetString = GPA( "glGetString" );
+ qwglDrawBuffer = GPA("glDrawBuffer");
+ qwglGetString = GPA("glGetString");
- qwglChoosePixelFormat = GPA( "wglChoosePixelFormat" );
- qwglDescribePixelFormat = GPA( "wglDescribePixelFormat" );
- qwglSetPixelFormat = GPA( "wglSetPixelFormat" );
- qwglSwapBuffers = GPA( "wglSwapBuffers" );
+ qwglChoosePixelFormat = GPA("wglChoosePixelFormat");
+ qwglDescribePixelFormat = GPA("wglDescribePixelFormat");
+ qwglSetPixelFormat = GPA("wglSetPixelFormat");
+ qwglSwapBuffers = GPA("wglSwapBuffers");
- qwglCreateContext = GPA( "wglCreateContext" );
- qwglDeleteContext = GPA( "wglDeleteContext" );
- qwglGetProcAddress = GPA( "wglGetProcAddress" );
- qwglMakeCurrent = GPA( "wglMakeCurrent" );
+ qwglCreateContext = GPA("wglCreateContext");
+ qwglDeleteContext = GPA("wglDeleteContext");
+ qwglGetProcAddress = GPA("wglGetProcAddress");
+ qwglMakeCurrent = GPA("wglMakeCurrent");
return qtrue;
}
#undef GPA
-void WGL_ShutdownExtensions( unsigned mask ) {
- if( mask & QWGL_EXT_swap_control ) {
+void WGL_ShutdownExtensions(unsigned mask)
+{
+ if (mask & QWGL_EXT_swap_control) {
qwglSwapIntervalEXT = NULL;
}
}
-#define GPA( x ) ( void * )qwglGetProcAddress( x )
+#define GPA(x) (void *)qwglGetProcAddress(x)
-void WGL_InitExtensions( unsigned mask ) {
- if( mask & QWGL_EXT_swap_control ) {
- qwglSwapIntervalEXT = GPA( "wglSwapIntervalEXT" );
+void WGL_InitExtensions(unsigned mask)
+{
+ if (mask & QWGL_EXT_swap_control) {
+ qwglSwapIntervalEXT = GPA("wglSwapIntervalEXT");
}
}
#undef GPA
-unsigned WGL_ParseExtensionString( const char *s ) {
+unsigned WGL_ParseExtensionString(const char *s)
+{
// must match defines in win_wgl.h!
static const char *const extnames[] = {
"WGL_EXT_swap_control",
NULL
};
- return Com_ParseExtensionString( s, extnames );
+ return Com_ParseExtensionString(s, extnames);
}
diff --git a/src/win_wgl.h b/src/win_wgl.h
index dc639d9..0a37cb6 100644
--- a/src/win_wgl.h
+++ b/src/win_wgl.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -24,24 +24,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define QWGL_EXT_swap_control (1<<0)
-qboolean WGL_Init( const char *dllname );
-void WGL_Shutdown( void );
-void WGL_InitExtensions( unsigned mask );
-void WGL_ShutdownExtensions( unsigned mask );
-unsigned WGL_ParseExtensionString( const char *s );
+qboolean WGL_Init(const char *dllname);
+void WGL_Shutdown(void);
+void WGL_InitExtensions(unsigned mask);
+void WGL_ShutdownExtensions(unsigned mask);
+unsigned WGL_ParseExtensionString(const char *s);
-extern void ( APIENTRY * qwglDrawBuffer )(GLenum mode);
-extern const GLubyte * ( APIENTRY * qwglGetString )(GLenum name);
+extern void (APIENTRY * qwglDrawBuffer)(GLenum mode);
+extern const GLubyte * (APIENTRY * qwglGetString)(GLenum name);
-extern int ( WINAPI * qwglChoosePixelFormat )(HDC, CONST PIXELFORMATDESCRIPTOR *);
-extern int ( WINAPI * qwglDescribePixelFormat ) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
-extern BOOL ( WINAPI * qwglSetPixelFormat )(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
-extern BOOL ( WINAPI * qwglSwapBuffers )(HDC);
+extern int (WINAPI * qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
+extern int (WINAPI * qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
+extern BOOL (WINAPI * qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
+extern BOOL (WINAPI * qwglSwapBuffers)(HDC);
-extern HGLRC ( WINAPI * qwglCreateContext )(HDC);
-extern BOOL ( WINAPI * qwglDeleteContext )(HGLRC);
-extern PROC ( WINAPI * qwglGetProcAddress )(LPCSTR);
-extern BOOL ( WINAPI * qwglMakeCurrent )(HDC, HGLRC);
+extern HGLRC (WINAPI * qwglCreateContext)(HDC);
+extern BOOL (WINAPI * qwglDeleteContext)(HGLRC);
+extern PROC (WINAPI * qwglGetProcAddress)(LPCSTR);
+extern BOOL (WINAPI * qwglMakeCurrent)(HDC, HGLRC);
-extern BOOL ( WINAPI * qwglSwapIntervalEXT )(int interval);
+extern BOOL (WINAPI * qwglSwapIntervalEXT)(int interval);
diff --git a/src/wsaerr.h b/src/wsaerr.h
index 93a9da9..e335db3 100644
--- a/src/wsaerr.h
+++ b/src/wsaerr.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -18,69 +18,69 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#define MAPERR( x ) case x: return #x;
+#define MAPERR(x) case x: return #x;
- MAPERR( WSAEINTR )
- MAPERR( WSAEBADF )
- MAPERR( WSAEACCES )
- MAPERR( WSAEFAULT )
- MAPERR( WSAEINVAL )
- MAPERR( WSAEMFILE )
- MAPERR( WSAEWOULDBLOCK )
- MAPERR( WSAEINPROGRESS )
- MAPERR( WSAEALREADY )
- MAPERR( WSAENOTSOCK )
- MAPERR( WSAEDESTADDRREQ )
- MAPERR( WSAEMSGSIZE )
- MAPERR( WSAEPROTOTYPE )
- MAPERR( WSAENOPROTOOPT )
- MAPERR( WSAEPROTONOSUPPORT )
- MAPERR( WSAESOCKTNOSUPPORT )
- MAPERR( WSAEOPNOTSUPP )
- MAPERR( WSAEPFNOSUPPORT )
- MAPERR( WSAEAFNOSUPPORT )
- MAPERR( WSAEADDRINUSE )
- MAPERR( WSAEADDRNOTAVAIL )
- MAPERR( WSAENETDOWN )
- MAPERR( WSAENETUNREACH )
- MAPERR( WSAENETRESET )
- MAPERR( WSAECONNABORTED )
- MAPERR( WSAECONNRESET )
- MAPERR( WSAENOBUFS )
- MAPERR( WSAEISCONN )
- MAPERR( WSAENOTCONN )
- MAPERR( WSAESHUTDOWN )
- MAPERR( WSAETOOMANYREFS )
- MAPERR( WSAETIMEDOUT )
- MAPERR( WSAECONNREFUSED )
- MAPERR( WSAELOOP )
- MAPERR( WSAENAMETOOLONG )
- MAPERR( WSAEHOSTDOWN )
- MAPERR( WSAEHOSTUNREACH )
- MAPERR( WSAENOTEMPTY )
- MAPERR( WSAEPROCLIM )
- MAPERR( WSAEUSERS )
- MAPERR( WSAEDQUOT )
- MAPERR( WSAESTALE )
- MAPERR( WSAEREMOTE )
- MAPERR( WSASYSNOTREADY )
- MAPERR( WSAVERNOTSUPPORTED )
- MAPERR( WSANOTINITIALISED )
- MAPERR( WSAEDISCON )
- MAPERR( WSAENOMORE )
- MAPERR( WSAECANCELLED )
- MAPERR( WSAEINVALIDPROCTABLE )
- MAPERR( WSAEINVALIDPROVIDER )
- MAPERR( WSAEPROVIDERFAILEDINIT )
- MAPERR( WSASYSCALLFAILURE )
- MAPERR( WSASERVICE_NOT_FOUND )
- MAPERR( WSATYPE_NOT_FOUND )
- MAPERR( WSA_E_NO_MORE )
- MAPERR( WSA_E_CANCELLED )
- MAPERR( WSAEREFUSED )
- MAPERR( WSAHOST_NOT_FOUND )
- MAPERR( WSATRY_AGAIN )
- MAPERR( WSANO_RECOVERY )
- MAPERR( WSANO_DATA )
+MAPERR(WSAEINTR)
+MAPERR(WSAEBADF)
+MAPERR(WSAEACCES)
+MAPERR(WSAEFAULT)
+MAPERR(WSAEINVAL)
+MAPERR(WSAEMFILE)
+MAPERR(WSAEWOULDBLOCK)
+MAPERR(WSAEINPROGRESS)
+MAPERR(WSAEALREADY)
+MAPERR(WSAENOTSOCK)
+MAPERR(WSAEDESTADDRREQ)
+MAPERR(WSAEMSGSIZE)
+MAPERR(WSAEPROTOTYPE)
+MAPERR(WSAENOPROTOOPT)
+MAPERR(WSAEPROTONOSUPPORT)
+MAPERR(WSAESOCKTNOSUPPORT)
+MAPERR(WSAEOPNOTSUPP)
+MAPERR(WSAEPFNOSUPPORT)
+MAPERR(WSAEAFNOSUPPORT)
+MAPERR(WSAEADDRINUSE)
+MAPERR(WSAEADDRNOTAVAIL)
+MAPERR(WSAENETDOWN)
+MAPERR(WSAENETUNREACH)
+MAPERR(WSAENETRESET)
+MAPERR(WSAECONNABORTED)
+MAPERR(WSAECONNRESET)
+MAPERR(WSAENOBUFS)
+MAPERR(WSAEISCONN)
+MAPERR(WSAENOTCONN)
+MAPERR(WSAESHUTDOWN)
+MAPERR(WSAETOOMANYREFS)
+MAPERR(WSAETIMEDOUT)
+MAPERR(WSAECONNREFUSED)
+MAPERR(WSAELOOP)
+MAPERR(WSAENAMETOOLONG)
+MAPERR(WSAEHOSTDOWN)
+MAPERR(WSAEHOSTUNREACH)
+MAPERR(WSAENOTEMPTY)
+MAPERR(WSAEPROCLIM)
+MAPERR(WSAEUSERS)
+MAPERR(WSAEDQUOT)
+MAPERR(WSAESTALE)
+MAPERR(WSAEREMOTE)
+MAPERR(WSASYSNOTREADY)
+MAPERR(WSAVERNOTSUPPORTED)
+MAPERR(WSANOTINITIALISED)
+MAPERR(WSAEDISCON)
+MAPERR(WSAENOMORE)
+MAPERR(WSAECANCELLED)
+MAPERR(WSAEINVALIDPROCTABLE)
+MAPERR(WSAEINVALIDPROVIDER)
+MAPERR(WSAEPROVIDERFAILEDINIT)
+MAPERR(WSASYSCALLFAILURE)
+MAPERR(WSASERVICE_NOT_FOUND)
+MAPERR(WSATYPE_NOT_FOUND)
+MAPERR(WSA_E_NO_MORE)
+MAPERR(WSA_E_CANCELLED)
+MAPERR(WSAEREFUSED)
+MAPERR(WSAHOST_NOT_FOUND)
+MAPERR(WSATRY_AGAIN)
+MAPERR(WSANO_RECOVERY)
+MAPERR(WSANO_DATA)
#undef MAPERR