Move deltatime computing into a function.

Make globals variables for speed computing local to the computing function.