Repository navigation
Conversation
A player aims at what their client shows, which is where the others were about one ping ago. By the time the server traces the shot the targets have moved on, so a player with a high ping has to lead even with instant-hit weapons. With sv_antilag 1, the axe, bullets fired by players, the instagib shotgun, the lightning beam and the lightning discharge now move the other living players and the movers back to where they were at the time of the shot, resolve the attack and put them back. With other values of sv_antilag nothing is rewound. How far back is the engine's to say: the "*antilag_rewind" info key gives the rewind for the attacker, on an engine that answers "yes" to a probe for the key. On other engines it is the attacker's ping less 20 ms (1/77 s below 20 ms), and the ping is read from "*ping_current" where the engine has that key and from "ping" where it does not. The rewind is at most 250 ms. No player is moved to before their last spawn. A player who has sent no move since the rewound time is extrapolated along their velocity for up to 20 ms, and an attacker who stood on a mover then is moved along with it. time_corrected holds the time the attack is resolved at, and is the current time whenever nothing is rewound. A player killed by a rewound attack is put back where they are, unless they teleported after the rewound time. Co-Authored-By: Reki <spiper212@gmail.com> Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
With sv_antilag 1 an attack can be resolved at a time before its target went through a teleporter. The knockback from such a hit would throw the player at the destination with a push meant for where they were before. Under sv_antilag 1, only apply knockback when the target teleported before time_corrected, the time the attack is resolved at, or when they damaged themselves. The other antilag modes are left as they were. Co-Authored-By: Reki <spiper212@gmail.com>
The server runs the physics of each entity at most once per frame. A mod that moves a newly fired projectile forward itself has to tell the server that it did, or the projectile is moved again in the same frame. Map the SkipEntityPhysics extension, which marks an entity as already run in the current frame, and add trap_SkipEntityPhysics to call it. Only servers that provide the extension support the call, so callers have to ask for it with HAVEEXTENSION first. Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
A projectile only starts to move when the server receives the shot. By then the targets the player aimed at have moved on by about one ping, so a player with a high ping has to lead them further. With sv_antilag 1, rockets, grenades and nails are moved forward by the shooter's ping, at most 80 ms, as soon as they are fired. They move in steps of at most 8 units, with the other players rewound to the time of each step, and touch what they hit on the way; grenades bounce under a copy of the server's bounce physics. Think timers, such as a grenade's fuse, are shortened by the time caught up. A ping of 1/77 s or less gets only the first move. The server's own first 0.05 s move of a new projectile is made here as well, in the rewound world, and newmis is cleared so that the server does not repeat it. On a server with the SkipEntityPhysics extension the projectile is also not run again in the frame it was fired. Without it that frame's physics still moves the projectile, so the first move is shortened by as much. A projectile can explode during the catch-up, before its fire function is done with it. The fire functions check for that before they hand it to the bots. When a rocket explodes under sv_antilag 1, its splash damage to the shooter is applied apart from the rest, and for a rocket that was caught up after a delay of about the time it was advanced. In race, where players are not solid, that separate damage reaches the shooter the way T_RadiusDamage() does there. Co-Authored-By: Reki <spiper212@gmail.com> Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
A race is decided on time. With sv_antilag 1 a player's rockets and grenades are moved forward by their ping when fired, so the same rocket jump would play out differently for players with different pings. Set sv_antilag 0 with the other race settings. This also turns off the server's own lag compensation (sv_antilag 2) during races. Co-Authored-By: Reki <spiper212@gmail.com>
The antilag vote switched sv_antilag between 0 and 2 and reported it as on or off, so players could not vote for the mod's own lag compensation. A passed vote now steps sv_antilag from 0 to 1 to 2 and back to 0, and the messages name the mode: '0 - disabled', '1 - KTX' or '2 - MVDSV'. Casting a vote shows the mode it would switch to, and during a match the command still only reports the current mode. Co-Authored-By: Reki <spiper212@gmail.com>
A weapon's refire delay is measured on server time. A client that predicts its own weapon cannot know at what server time each of its commands is run; what it knows is the commands it has sent and how long each one lasts. Give every player a clock, client_time, that PlayerPreThink advances by the frame time of each movement command the server runs for them. attack_finished is now set from and compared with this clock everywhere: in the weapon code, the player animations, PutClientInServer and PlayerPreThink, the hook, kfjump and krjump, the yawnmode backpack rule, the matchless idle timer, the MOTD and the bots. The 50 ms after a spawn in which W_WeaponFrame acts on neither attack nor impulses is measured on it as well, from client_spawn_time. This changes refire for every player on every server, whatever sv_antilag is set to. A delay now runs out once the player's own commands have covered it rather than after that much server time, so it stands still while their commands do not arrive and follows the msec their client reports. Co-Authored-By: Reki <spiper212@gmail.com>
The frames of a weapon animation, and the nails and lightning bolts that held fire shoots from them, are think functions the server runs on its own time. A client that predicts its weapon cannot tell when they will run. Schedule them on client_time instead. Each frame function except the hook's now stores the next one in client_think, its time in client_nextthink and its place in the weapon's sequence in client_thinkindex, and PlayerPostThink runs it once client_time has reached client_nextthink, with client_time set to the scheduled time while it runs. The server-side think is switched off until the sequence returns to player_run. player_run, player_stand1 and PlayerDead clear the schedule, so a respawn ends the animation too. The axe picked one of its four swings with g_random(). The pick is now a hash of client_time, made with arithmetic that QuakeC can repeat with floats alone, so that a client can make the same one. This applies on every server. Weapon frames advance with the player's own commands, and the shots of held nailgun and lightning gun fire leave from where the player is after the move in PlayerPostThink, not before it. Co-Authored-By: Reki <spiper212@gmail.com>
An impulse can still be pending when a player respawns, either from a command sent before the respawn or from the backup copies of earlier commands that a client sends along with each new one. A weapon selection carried over like that was made for the inventory the player had before. k_respawn now takes the pending impulse aside and puts it back after PutClientInServer, unless it selects a weapon (1 to 8, or 22 for the hook) that the player cannot switch to now. In the first 50 ms after a spawn, while W_WeaponFrame acts on neither attack nor impulses, a weapon selection that the player cannot make is now cleared instead of being kept until that time is over. This applies on every server. Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
CSQC (client-side QuakeC) is a program, csprogs.dat, that a server
hands to the clients able to run it, and that receives entity updates
written by the mod. A client that runs it can predict its own weapon
once it knows the weapon's state on the server: the weapon and ammo,
and where the weapon is in its animation and refire.
Give every player a weapon-info entity: an extra edict, created on
connect and sent only to its owner, that writes the owner's weapon and
ammo, attack_finished, the next animation frame and its time,
client_time and the view model frame, the prediction flags and the
ping. Every PlayerPostThink marks for sending the fields that have
changed, and always the clock. It goes out once the server reports
CSQC running for the player ("csqcactive"). Each respawn counts
weapon_generation up and sends the whole state again, so that the
client can tell the new life from the old one.
client_predflags tells the client about rules that change the weapons
(yawnmode, instagib and, under sv_antilag 1, the faster rockets of
midair with quad) and turns prediction off where the client cannot
follow: when tracking another player, with the hook or the CTF haste
rune, while the player may not fire, and with the lightning gun under
water. With sv_antilag 1, client_ping is the ping the antilag code
works with, at most the 80 ms that projectiles are advanced by;
otherwise it is 0.
The entity needs the SetSendEntity field and the SetSendNeeded
extension. SetSendNeeded() is a wrapper that does nothing on an engine
without the extension, and on such an engine no weapon-info entity is
created. With them, each player has the extra edict on every server,
and the flags are worked out in every PlayerPostThink.
Co-Authored-By: Reki <spiper212@gmail.com>
Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
A client that predicts its own shots draws its rockets, grenades and nails at once and then has to match them up with the server's. A plain entity update says neither where a projectile started nor how fast it is going. With sv_antilag 1, send rockets, grenades and nails to clients running CSQC as CSQC entities, once they have been fired and advanced. The first update carries the origin and velocity together with the server time, the model and effects, the angles, the owner, and the point the projectile was fired from, which is now kept in pos1. Grenades bounce, so every server frame each live grenade sends its origin and velocity again. A projectile that is already gone after the catch-up is not sent. In the other antilag modes projectiles stay ordinary entities. Co-Authored-By: Reki <spiper212@gmail.com> Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
A client that predicts its grenades has to know the server's gravity. The client has been sent it with the movement variables at connect, but CSQC has no way to read them. On an engine with the pointerstat extension, register sv_gravity as CSQC stat 32, the first of the stats the engine leaves to mods, at worldspawn, and bring it up to date at the start of every server frame. With other engines nothing changes.
Client-side QuakeC is compiled against the builtins, constants, fields and entry points that the client engine provides. FTE can write out a QuakeC file that declares all of them. Add that file as qcsrc/fteextensions.qc, so that client-side QuakeC can be built against it. It was generated by FTE QW git-6732-6668d1a9a-dirty, dated 2026-06-20, with "pr_dumpplatform -Tcs", as its header says: the client-side definitions only. It is not written by hand; to change it, generate it again from a newer FTE.
can_prewar() decides whether a player may fire or jump before a match, and when the answer is no it also flashes the player's screen and prints why. That makes it unusable as a plain question. Move the decision to prewar_denied(), which returns the reason or NULL and has no side effects. can_prewar() prints the reason it gets, so its two callers behave as before. The rules now read top to bottom without the jumps to a shared label.
To compensate for latency the server has to know where players and moving brush entities were a moment ago, so that it can put them back there while it resolves an attack. Keep the last 40 states of every player and of every plat, train, door, secret door, func_bob, func_laser and func_movewall. Each state holds the origin, the velocity, the time and the entity the player stands on. A player's history starts when they connect and leaves the list when they disconnect, and a state is logged after their PlayerPostThink, at most once every 10 ms. Movers are registered when they spawn, logged at the end of StartFrame, at most once per sv_mintic, and taken off the list when they are removed. Everything is forgotten at the start of a map. PlayerPreThink also notes the time it last ran for each player. Nothing reads the history yet. Co-Authored-By: Reki <spiper212@gmail.com> Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
dsvensson
force-pushed
the
csqc
branch
5 times, most recently
from
November 29, 2026 17:57
e661162 to
5e45c56
Compare
With the weapon state and the projectiles on the wire, a client that runs CSQC can show what pressing fire does without waiting a round trip for the server. Add the client-side QuakeC for that under qcsrc/. It is plain version 6 bytecode, the kind every QuakeC VM runs, so that it does not depend on FTE's own; progs.src says how fteextensions.qc is regenerated. The build follows in a commit of its own. Every frame the csprogs takes the last weapon state the server sent, replays on top of it the movement commands the server has not acknowledged yet, and walks its own copy of the server's weapon animations to draw the view model. It plays the weapon sounds at once and drops the server's copy when that arrives, draws the lightning beam, and spawns the player's own projectiles locally, handing each over to the server's copy of the shot when a matching one arrives. Projectiles from the server are extrapolated every rendered frame from the origin, velocity and server time they were sent with, which needs the client's clock to follow the server's (FTE_PEXT_ACCURATETIMINGS), and are lit by the effect bits the server sends. The cvars are named as in ezQuake. cl_nopred_weapon turns prediction off; cl_predict_weaponsound and cl_predict_projectiles by default follow the server and are on only under sv_antilag 1; cl_predict_beam, cl_predict_buffer and cl_predict_debug do what they say. Prediction stands aside in demos and whenever the server's flags say it cannot follow. Co-Authored-By: Reki <spiper212@gmail.com> Co-Authored-By: dusty-qw <71472647+dusty-qw@users.noreply.github.com>
CSQC_SUPPORT, on by default, covers the client-side QuakeC and what depends on it. Turning it off is for a server that must not hand a csprogs.dat to its clients. Without it the mod keeps sv_antilag 1 out of reach: KTX's own antilag advances a new projectile by the shooter's latency, and without the csprogs predicting it the shooter would see it appear well ahead of the gun. - The antilag vote goes between off and the engine's antilag, leaving out KTX's own. - sv_antilag 1 set by a config or an admin is turned into 2. - No weapon-info entity is created for the players.
The client-side QuakeC in qcsrc/ is compiled by fteqcc, which few build machines have. Take fteqcc from the FTEQCC environment variable, else from the PATH, else fetch fteqw's qclib at a fixed commit and build it at configure, with the host's compiler also when the mod is cross compiled. It is installed under KTX_DEPS_DIR, by default in the build directory, where later configures find it. fteqcc writes where progs.src says, beside the sources, and reports success when it could not write. So a copy of qcsrc is compiled in the build directory, into csprogs.dat beside the mod, the build fails when no file comes out, and it runs only when a source has changed. csprogs.lno is written with it: the table of line numbers with which an engine names the source line in an error from the csprogs, and which a debugger needs. fteqcc drops it when it optimises unless -Flno asks for it. csprogs.dat is the same file whatever the mod is built for. BUILD_CSPROGS, on by default, says whether a build compiles it; with it off the mod is built with CSQC support as before and needs no fteqcc, and the csprogs target builds csprogs.dat without building the mod. Nothing is compiled either when CSQC_SUPPORT is off. build_cmake.sh gets "csprogs" as a platform of its own, built once, and turns the option off for the others.
The csprogs is the same for every target, so it gets one job, which runs beside the per-target builds and builds the fteqcc the build pins, since the image has none. The per-target and verify jobs leave it out. The upload job waits for it too. csprogs.dat, csprogs.lno and the md5 go beside the linux, qvm and windows directories, with the same prefix as the other files for a snapshot, and once more under latest. A release gets csprogs.zip and a line in the checksums. A new verify job builds with CSQC support off.
Every user mode starts from the settings in common_um_init, which turned on MVDSV's lag compensation with sv_antilag 2. Set sv_antilag 1 there instead, for the mod's own lag compensation. It is also the setting under which CSQC clients predict weapon sounds and projectiles by default. A build without CSQC support keeps sv_antilag 2. This changes existing servers. Choosing a user mode such as 1on1, 2on2 or ffa now sets sv_antilag 1, unless the mode's own settings or the server's usermode configs set something else. Hitscan attacks are then rewound by KTX rather than by MVDSV, and rockets, grenades and nails are advanced by the shooter's ping, up to 80 ms, when they are fired. The example mvdsv.cfg called sv_antilag 1 unsupported by KTX; it now says what the three values are. Co-Authored-By: Reki <spiper212@gmail.com>
Use k_antilag_projectile_cap_ms to cap antilag 1 projectile catch-up. Default to 80 ms. Zero gives projectiles ordinary server physics and disables CSQC projectile prediction.
Antilag 1 skips projectile catch-up when ping is at or below k_antilag_projectile_threshold_ms. The default is 12.987013 ms, or one frame at 77 Hz.
The smooth hook may not be thrown again until hook_reset_time, which was measured in the server's time. With sv_antilag 1 every other weapon timer runs on the player's own clock, and a client that predicts the hook has only that clock to tell when the next throw is allowed. Measure it with WeaponTime(), so it stays in the server's time with sv_antilag 0 or 2. The two clocks are unrelated, so the time is cleared when a player spawns and cannot be left over from another mode.
Throwing the hook, its flight, where it lands and its pull on the player all waited for the server, a round trip behind the player's hand, and the engine's movement prediction fought the pull for as long as it lasted. The hook is now replayed with the weapon: on top of the state the server sent, every command it has not seen yet throws, flies, anchors and lets go of the hook as the server will. The four hook styles differ in the throw speed, in when letting go calls back a hook in flight, and in the smooth hook's wait and its rise to full speed; all are followed. A style this does not know, and the haste rune, leave the hook to the server. While a hook is out the player's movement over those commands is run twice with runstandardplayerphysics, once with the hook's pull and once without. The engine has already predicted the second, so the view is moved by the difference between the two: nothing until the hook pulls, and nothing again once the server has seen it let go. The replay moves in whole commands, while ezQuake draws the player on their way between where the last two commands leave them. The hook in flight, the chain and that move of the view are drawn part of the way between the same two, so they do not shake against the view. Hooks the server sends are drawn as projectiles, with a chain of three links to their owner, as the server used to send them. The player's own is drawn from the prediction instead, and the view model shows the throw and the hook coming back on the commands the server does. cl_predict_hook 0 shows it as the server sends it. Only the world stops a predicted hook. One that lands on a player, a door or a platform is put right when the server says so, and a hook that lands before the server has seen it thrown pulls nobody until it has.
With sv_antilag 1 the hook was the one weapon a client could not predict: the server switched prediction off while it was in hand. This sends what a client needs to predict it, and stops switching it off. A player with a hook gets an entity only they are sent, as they do for their weapon. It says whether the hook is out and whether it holds, the hook style, and when the next throw is allowed. While the hook is out it is sent on every command, with where and when the hook was thrown, where it is and how fast, and where the player is and how fast, which is what a client replays the pull from. The flight is given from the throw because where the hook is depends on which side of a server frame it is sent. The haste rune scales the hook's speeds by a cvar the client cannot see, so that is flagged for the client to stand aside. The hook itself is sent as other projectiles are, marked as a hook, and sent again when it lands and for as long as it rides a player or a door. It is not moved on by the thrower's latency: what it does is move the thrower, and it lands on the command a predicting client expects when it flies in step with the commands. The three chain links are not sent to a CSQC client, which draws the chain itself between the hook and its owner. The hook gets a weapon index of its own, 9, where it shared 0 with having no weapon at all. Nothing changes with sv_antilag 0 or 2, or for a client that does not run CSQC.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Far from done, but can just as well have a draft PR open for visibility.