LinearFireRate
Improves the non-linear fire rate situation in the vanilla game.
The vanilla version spends an extra 3 frames between shots, causing the actual fire rate loss to increase as the panel fire rate increases (of course, if your frame rate is infinite, the impact is minimal). This mod manages to optimize this situation, restoring the fire rate to be linear, and solves the problem of the fire rate being affected by the frame rate to a certain extent. When the fire rate is less than or equal to the frame rate, the panel fire rate can be achieved; when the fire rate is greater than the frame rate, it is still subject to the limit of 1 shot per frame.
Attention! Enemies also receive this bonus, so high fire rate weapons in the hands of enemies will be more dangerous.
The following is the detailed principle, for those interested to know:
First, all operations must be executed at the start of a frame, which is the root cause of the fire rate being affected by the frame rate.
Taking automatic weapons as an example, there are four states: Ready, Fire, Cooling, and Empty:
Assuming initially the gun is in the Ready state, and the player presses the mouse to fire in a certain frame, if all behaviors for this frame have already been executed, the firing logic must wait until the start of the next frame to execute, wasting less than 1 frame of time;
At the start of the next frame, the gun executes the firing logic and transitions to the Fire state, doing nothing else, which consumes 1 frame of time;
In the Fire state, the gun checks if there is enough ammo remaining. Considering only continuous firing here, assuming the gun transitions to the Cooling state, this state transition consumes another 1 frame of time;
In the Cooling state, the gun actually starts the cooldown timer. After the timer ends, if all behaviors for the current frame have already been executed, subsequent logic must wait until the start of the next frame to execute, wasting another less than 1 frame of time;
When it detects that the cooldown timer is greater than the gun’s fire interval, the gun transitions back to the Ready state, returning to the initial state, which consumes another 1 frame of time.
In summary, the fixed time consumed is 3 frames, and up to 2 frames might be wasted depending on the firing timing, leading to an error of 3~5 frames! Assuming the game runs at 60 frames, this brings an error of 0.05~0.08 seconds. If a gun fires 30 rounds continuously, even with a conservative estimate, there will be a delay of 30×0.05=1.5 seconds!
For low fire rate guns, this is nothing, but for high fire rate guns, the loss is significant. For a weapon with a fire rate of 10, firing 30 rounds theoretically takes 3 seconds, but actually takes 4.5 seconds, which is 50% slower; for a weapon with a fire rate of 20, firing 30 rounds theoretically takes 1.5 seconds, but actually takes 3 seconds, which is a full 100% slower!
This mod compresses the 3 frames consumed by state switching into 1 frame, and compensates for the floating delay caused by firing timing. It records the time wasted because the current frame finished execution, and allows less waiting time for the next shot, thereby achieving a linear increase in fire rate.