idTech4.idGameConsole.DrawFPS C# (CSharp) Method

DrawFPS() private method

private DrawFPS ( float y ) : float
y float
return float
		private float DrawFPS(float y)
		{
			// don't use serverTime, because that will be drifting to
			// correct for internet lag changes, timescales, timedemos, etc
			int t = idE.System.Milliseconds;
			int frameTime = t - _previousFrameTime;
			int fpsFrames = _previousFrameTimes.Length;

			_previousFrameTime = t;
			_previousFrameTimes[_frameIndex % fpsFrames] = frameTime;
			_frameIndex++;
	
			if(_frameIndex > fpsFrames)
			{
				// average multiple frames together to smooth changes out a bit
				int total = 0;

				for(int i = 0; i < fpsFrames; i++)
				{
					total += _previousFrameTimes[i];
				}

				if(total == 0)
				{
					total = 1;
				}

				int fps = (10000 * fpsFrames) / total;
				fps = (fps + 5) / 10;

				string s = string.Format("{0}fps", fps);
				int width = s.Length * idE.BigCharacterWidth;
			
				idE.RenderSystem.DrawBigString(635 - width, (int) y + 2, s, idColor.White, true, _charSetShader);
			}

			return (y + idE.BigCharacterHeight + 4);
		}