Skip to content

Commit f6da77e

Browse files
committed
ANTILAG: Support sv_antilag 1.
Forward port of Reki's initial implementation.
1 parent dae4805 commit f6da77e

28 files changed

+2355
-128
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(SRC_NATIVE
3333
set(SRC_COMMON
3434
"${DIR_SRC}/g_main.c" # WARNING: should be first in list for QVM, since it contains vmMain().
3535
"${DIR_SRC}/admin.c"
36+
"${DIR_SRC}/antilag.c"
3637
"${DIR_SRC}/arena.c"
3738
"${DIR_SRC}/bot_aim.c"
3839
"${DIR_SRC}/bot_blocked.c"

include/g_consts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@
174174
#define MSG_ONE 1 // reliable to one (msg_entity)
175175
#define MSG_ALL 2 // reliable to all
176176
#define MSG_INIT 3 // write to the init string
177+
#define MSG_CSQC 5 // for csqc
178+
179+
#define EZCSQC_WEAPONINFO 1
180+
#define EZCSQC_PROJECTILE 2
181+
#define EZCSQC_PLAYER 3
182+
#define EZCSQC_WEAPONDEF 4
183+
#define EZCSQC_HUDELEMENT 32
177184

178185
// message levels
179186
#define PRINT_LOW 0 // pickup messages

include/g_local.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,31 @@ void visible_to(gedict_t *viewer, gedict_t *first, int len, byte *visible);
465465
// It retuns dots array filled with dots, amount of dots depends of how long cmd name and longest cmd name.
466466
char* make_dots(char *dots, size_t dots_len, int cmd_max_len, char *cmd);
467467

468+
// antilag.c
469+
//
470+
#define PRDFL_MIDAIR 1
471+
#define PRDFL_COILGUN 2
472+
#define PRDFL_FORCEOFF 255
473+
extern float time_corrected;
474+
void WPredict_Initialize(void);
475+
qbool WeaponDefinition_SendEntity(int sendflags);
476+
void antilag_lagmove(antilag_t *data, float goal_time);
477+
void antilag_lagmove_all(gedict_t *e, float goal_time);
478+
void antilag_lagmove_all_hitscan(gedict_t *e);
479+
void antilag_lagmove_all_proj(gedict_t *owner, gedict_t *e);
480+
void antilag_lagmove_all_proj_bounce(gedict_t *owner, gedict_t *e);
481+
void antilag_platform_move(antilag_t *list, float ms);
482+
void antilag_unmove_all(void);
483+
void antilag_clearflags_all(void);
484+
int antilag_getseek(antilag_t *data, float ms);
485+
antilag_t *antilag_create_player(gedict_t *e);
486+
antilag_t *antilag_create_world(gedict_t *e);
487+
void antilag_delete_player(gedict_t *e);
488+
void antilag_delete_world(gedict_t *e);
489+
void antilag_clearstates(antilag_t *antilag);
490+
void antilag_addflags(gedict_t *e, antilag_t *antilag, byte flags);
491+
void antilag_log(gedict_t *e, antilag_t *antilag);
492+
468493
//
469494
// subs.c
470495
void SUB_CalcMove(vec3_t tdest, float tspeed, void (*func)(void));
@@ -555,7 +580,7 @@ void SpawnMeatSpray(vec3_t org, vec3_t vel);
555580
void W_FireAxe(void);
556581
void W_FireSpikes(float ox);
557582
void W_FireLightning(void);
558-
void LightningDamage(vec3_t p1, vec3_t p2, gedict_t *from, float damage);
583+
void LightningDamage(vec3_t p1, vec3_t p2, gedict_t *from, float damage, qbool is_antilagged);
559584
qbool W_CanSwitch(int wp, qbool warn);
560585

561586
void FireBullets(float shotcount, vec3_t dir, float spread_x, float spread_y, float spread_z,
@@ -585,9 +610,10 @@ qbool ISDEAD(gedict_t *e);
585610
qbool CanDamage(gedict_t *targ, gedict_t *inflictor);
586611

587612
void T_Damage(gedict_t *targ, gedict_t *inflictor, gedict_t *attacker, float damage);
588-
void T_RadiusDamage(gedict_t *inflictor, gedict_t *attacker, float damage, gedict_t *ignore,
589-
deathType_t dtype);
590-
void T_BeamDamage(gedict_t *attacker, float damage);
613+
void T_RadiusDamage(gedict_t *inflictor, gedict_t *attacker, float damage, gedict_t *ignore, deathType_t dtype);
614+
void T_RadiusDamage_Ignore2(gedict_t *inflictor, gedict_t *attacker, float damage, gedict_t *ignore, gedict_t *ignore2, deathType_t dtype);
615+
void T_RadiusDamageApply(gedict_t *inflictor, gedict_t *attacker, gedict_t *head, float damage, deathType_t dtype);
616+
void T_BeamDamage(gedict_t * attacker, float damage);
591617

592618
//items.c
593619
void DropPowerup(float timeleft, int powerup);

include/progs.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,102 @@ typedef struct fb_entvars_s {
755755
} fb_entvars_t;
756756
#endif
757757

758+
#define ANTILAG_REWIND_MAXHITSCAN 0.250f
759+
#define ANTILAG_REWIND_MAXPROJECTILE 0.080f
760+
#define ANTILAG_TIMESTEP 0.01f
761+
//#define ANTILAG_XERP 0
762+
#define ANTILAG_MAX_PREDICTION 0.02f
763+
#define ANTILAG_MAX_XERP 0.02f
764+
#define ANTILAG_MAXEDICTS 256
765+
766+
#define ANTILAG_MAXSTATES 0x20
767+
#define ANTILAG_MASK 0x1F
768+
769+
#define ANTILAG_FL_REWOUND 0x01
770+
#define ANTILAG_FL_FATALPROTECT 0x02
771+
#define ANTILAG_FL_KNOCKBACKPROTECT 0x04
772+
773+
#define SENDFLAGS_ALL 0xFFFFFF
774+
775+
#define WEPPRED_MAXSTATES 32
776+
#define WEPPREDANIM_SOUND 0x0001
777+
#define WEPPREDANIM_PROJECTILE 0x0002
778+
#define WEPPREDANIM_LGBEAM 0x0004
779+
#define WEPPREDANIM_MUZZLEFLASH 0x0008
780+
#define WEPPREDANIM_DEFAULT 0x0010 // +attack will always be checked on this (unless current frame is +attack waiting
781+
#define WEPPREDANIM_ATTACK 0x0020
782+
#define WEPPREDANIM_BRANCH 0x0040
783+
#define WEPPREDANIM_MOREBYTES 0x0080 // mark if we need "full" 16 bits of flags
784+
#define WEPPREDANIM_SOUNDAUTO 0x0100 | WEPPREDANIM_MOREBYTES
785+
#define WEPPREDANIM_LTIME 0x0200 | WEPPREDANIM_MOREBYTES
786+
787+
#define WEAPONDEF_INIT (1 << 0)
788+
#define WEAPONDEF_FLAGS (1 << 1)
789+
#define WEAPONDEF_ANIM (1 << 2)
790+
791+
#define WEAPONINFO_INDEX (1 << 0)
792+
#define WEAPONINFO_AMMO_SHELLS (1 << 1)
793+
#define WEAPONINFO_AMMO_NAILS (1 << 2)
794+
#define WEAPONINFO_AMMO_ROCKETS (1 << 3)
795+
#define WEAPONINFO_AMMO_CELLS (1 << 4)
796+
#define WEAPONINFO_ATTACK (1 << 5)
797+
#define WEAPONINFO_TIMING (1 << 6)
798+
#define WEAPONINFO_PRED_PING (1 << 7)
799+
800+
#define PROJECTILE_ORIGIN (1 << 0)
801+
#define PROJECTILE_MODEL (1 << 1)
802+
#define PROJECTILE_ANGLES (1 << 2)
803+
#define PROJECTILE_OWNER (1 << 3)
804+
#define PROJECTILE_SPAWN_ORIGIN (1 << 4)
805+
806+
typedef struct weppredanim_s
807+
{
808+
signed char mdlframe; // frame number in model
809+
unsigned short flags; // flags from WEPPREDANIM
810+
unsigned short sound; // WEPPREDANIM_SOUND: sound index to play
811+
unsigned short soundmask; // WEPPREDANIM_SOUND: bitmask for sound (cl_predict_weaponsound)
812+
unsigned short projectile_model; // WEPPREDANIM_PROJECTILE: model index of projectile
813+
short projectile_velocity[3]; // WEPPREDANIM_PROJECTILE: projectile velocity (v_right, v_forward, v_up)
814+
byte projectile_offset[3]; // WEPPREDANIM_PROJECTILE: projectile spawn position (v_right, v_forward, z)
815+
byte nextanim; // next anim state index
816+
byte altanim; // WEPPREDANIM_BRANCH: next anim state if condition is fullfilled
817+
short length; // msec length of anim state (networked in 10ms increments)
818+
} weppredanim_t;
819+
820+
typedef struct weppreddef_s
821+
{
822+
unsigned short modelindex; // view model index
823+
unsigned short attack_time; // attack time in msec
824+
825+
byte impulse; // impulse for equipping this weapon
826+
int itemflag; // .items bit for this item
827+
828+
byte anim_number; // number of anim frames
829+
weppredanim_t anim_states[WEPPRED_MAXSTATES];
830+
} weppreddef_t;
831+
832+
833+
struct gedict_s;
834+
typedef struct antilag_s {
835+
vec3_t rewind_origin[ANTILAG_MAXSTATES];
836+
vec3_t rewind_velocity[ANTILAG_MAXSTATES];
837+
vec3_t rewind_platform_offset[ANTILAG_MAXSTATES];
838+
int rewind_platform_edict[ANTILAG_MAXSTATES];
839+
float rewind_time[ANTILAG_MAXSTATES];
840+
byte rewind_frameflags[ANTILAG_MAXSTATES];
841+
int rewind_seek;
842+
843+
byte state_flags;
844+
vec3_t held_origin;
845+
vec3_t held_velocity;
846+
847+
struct gedict_s *owner;
848+
849+
struct antilag_s *prev;
850+
struct antilag_s *next;
851+
} antilag_t;
852+
853+
758854
//typedef (void(*)(gedict_t *)) one_edict_func;
759855
typedef struct gedict_s
760856
{
@@ -1192,6 +1288,7 @@ typedef struct gedict_s
11921288
// {
11931289
// let mvdsv know when player has teleported, and adjust for high-ping
11941290
int teleported;
1291+
float teleport_time;
11951292
// }
11961293

11971294
// {
@@ -1230,6 +1327,19 @@ typedef struct gedict_s
12301327
float healtimer; // internal timer for tracking health replenishment interval
12311328
// }
12321329

1330+
// { antilag
1331+
struct antilag_s *antilag_data;
1332+
int weapon_index;
1333+
float client_time;
1334+
float client_lastupdated;
1335+
float client_nextthink;
1336+
func_t client_think;
1337+
float client_thinkindex;
1338+
float client_ping;
1339+
float client_predflags;
1340+
struct gedict_s *weapon_pred;
1341+
// }
1342+
12331343
// { csqc
12341344
func_t SendEntity;
12351345
// }

0 commit comments

Comments
 (0)