Thinking Fast

This post looks at the problem of entities with a nextthink rate higher than the framerate (inspired by a func_ post that I’ve lost in the meantime). The Quake engine guarantees 10 fps, anything more frequent risks lagging behind when framerates drop. Obviously rendering at 10fps can never draw a 20fps animation correctly; our goal for today is to have a 0.05 nextthink entity execute its think function 20 times in 1 second, running multiple times in a single frame when necessary. This results in dropped frames in an animation; a health regeneration function benefits more by reaching the correct total. The plan is to do something like
while(self.nextthink < time + frametime) self.think();
but the details of Quake’s timekeeping present some pitfalls.
This article was updated on 11th April to correct which ranges of time the Quake engine runs think frames in Continue reading