Added RollingAverage
Added RollingAverage

--- a/sandbox/sandbox.sln
+++ b/sandbox/sandbox.sln
@@ -1,18 +1,18 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sandbox", "sandbox\sandbox.csproj", "{89E37932-E22D-4D94-8438-ACEB73667456}"
-EndProject
-Global
-	GlobalSection(SolutionConfigurationPlatforms) = preSolution
-		Debug|x86 = Debug|x86
-		Release|x86 = Release|x86
-	EndGlobalSection
-	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{89E37932-E22D-4D94-8438-ACEB73667456}.Debug|x86.ActiveCfg = Debug|x86
-		{89E37932-E22D-4D94-8438-ACEB73667456}.Debug|x86.Build.0 = Debug|x86
-		{89E37932-E22D-4D94-8438-ACEB73667456}.Release|x86.ActiveCfg = Release|x86
-		{89E37932-E22D-4D94-8438-ACEB73667456}.Release|x86.Build.0 = Release|x86
-	EndGlobalSection
-EndGlobal
+

+Microsoft Visual Studio Solution File, Format Version 12.00

+# Visual Studio 2012

+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sandbox", "sandbox\sandbox.csproj", "{89E37932-E22D-4D94-8438-ACEB73667456}"

+EndProject

+Global

+	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+		Debug|x86 = Debug|x86

+		Release|x86 = Release|x86

+	EndGlobalSection

+	GlobalSection(ProjectConfigurationPlatforms) = postSolution

+		{89E37932-E22D-4D94-8438-ACEB73667456}.Debug|x86.ActiveCfg = Debug|x86

+		{89E37932-E22D-4D94-8438-ACEB73667456}.Debug|x86.Build.0 = Debug|x86

+		{89E37932-E22D-4D94-8438-ACEB73667456}.Release|x86.ActiveCfg = Release|x86

+		{89E37932-E22D-4D94-8438-ACEB73667456}.Release|x86.Build.0 = Release|x86

+	EndGlobalSection

+EndGlobal

 

--- /dev/null
+++ b/sandbox/sandbox/Types/RollingAverage.cs
@@ -1,1 +1,113 @@
+using System;
 
+namespace sandbox
+{
+	public class RollingAverageD
+	{
+		public static UInt32 DefaultCapacity = 16;
+
+		public double Sum()
+		{
+			return sum;
+		}
+
+		public double Average()
+		{
+			return average;
+		}
+
+		public UInt32 Count()
+		{
+			return count;
+		}
+
+		public UInt32 Capacity()
+		{
+			return capacity;
+		}
+
+		public void AddItem(double num)
+		{
+			if (this.items == null)
+			{
+				this.items = new double[DefaultCapacity];
+			}
+
+			double oldNum = this.items[this.index];
+
+			this.sum -= oldNum;
+			this.sum += num;
+
+			this.items[this.index] = num;
+
+			if (this.count < this.capacity)
+			{
+				this.count++;
+			}
+
+			this.average = this.sum / this.count;
+
+			this.index = (this.index + 1) % this.capacity;
+		}
+
+		public void SetCapacity(UInt32 newcap)
+		{
+			double[] newList = new double[newcap];
+
+			this.sum = 0d;
+
+			UInt32 idx = 0;
+
+			while (idx < newList.Length && idx < this.items.Length)
+			{
+				newList[idx] = this.items[idx];
+				this.sum += newList[idx];
+
+				idx++;
+			}
+
+			this.count = idx + 1;
+		}
+
+		public RollingAverageD(double[] startingItems, UInt32 cap)
+		{
+			this.items = new double[cap];
+			this.capacity = cap;
+
+			this.sum = 0d;
+
+			UInt32 idx = 0;
+
+			while (idx < startingItems.Length && idx < this.capacity)
+			{
+				this.items[idx] = startingItems[idx];
+				this.sum += startingItems[idx];
+
+				idx++;
+			}
+
+			this.count = idx + 1u;
+			this.index = this.count % this.capacity;
+
+			this.average = this.sum / this.count;
+		}
+
+		public RollingAverageD(double[] items) : this(items, DefaultCapacity) {}
+
+		public RollingAverageD(UInt32 cap) : this(new double[0], cap) {}
+
+		public RollingAverageD() : this(DefaultCapacity) {}
+
+		private double sum;
+		private double average;
+
+		private UInt32 count;
+		private UInt32 capacity;
+
+		private UInt32 index;
+
+		private double[] items;
+	}
+}
+
+

--- a/sandbox/sandbox/sandbox.csproj
+++ b/sandbox/sandbox/sandbox.csproj
@@ -1,88 +1,87 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
-    <ProjectGuid>{89E37932-E22D-4D94-8438-ACEB73667456}</ProjectGuid>
-    <OutputType>Exe</OutputType>
-    <RootNamespace>sandbox</RootNamespace>
-    <AssemblyName>sandbox</AssemblyName>
-    <UseMSBuildEngine>False</UseMSBuildEngine>
-    <StartupObject>sandbox.Program</StartupObject>
-    <CodePage>65001</CodePage>
-    <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug</OutputPath>
-    <DefineConstants>DEBUG;</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <PlatformTarget>x86</PlatformTarget>
-    <ConsolePause>false</ConsolePause>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
-    <DebugType>full</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release</OutputPath>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <PlatformTarget>x86</PlatformTarget>
-    <ConsolePause>false</ConsolePause>
-  </PropertyGroup>
-  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-  <ItemGroup>
-    <Compile Include="Program.cs" />
-    <Compile Include="Game.cs" />
-    <Compile Include="Texture2D.cs" />
-    <Compile Include="DrawingFunctions.cs" />
-    <Compile Include="Input\InputManager.cs" />
-    <Compile Include="Input\InputSubscription.cs" />
-    <Compile Include="Loaders.cs" />
-    <Compile Include="Yoda.cs" />
-    <Compile Include="API\IGameModule.cs" />
-    <Compile Include="API\IRenderModule.cs" />
-    <Compile Include="API\AGameModuleDependency.cs" />
-    <Compile Include="Tools.cs" />
-    <Compile Include="TextWriter.cs" />
-    <Compile Include="JustSomeText.cs" />
-    <Compile Include="Types\Entity.cs" />
-    <Compile Include="Types\Rect.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <Reference Include="System.Drawing" />
-    <Reference Include="System" />
-    <Reference Include="OpenTK">
-      <HintPath>..\..\libs\OpenTK.dll</HintPath>
-    </Reference>
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\AlternatingBrick-ColorMap.png">
-      <Link>data\AlternatingBrick-ColorMap.png</Link>
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\AlternatingBrick-NormalMap.png">
-      <Link>data\AlternatingBrick-NormalMap.png</Link>
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\font24.fnt">
-      <Link>data\font24.fnt</Link>
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\font24.png">
-      <Link>data\font24.png</Link>
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-    <None Include="data\Yoda-276x276.jpg">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-  </ItemGroup>
-  <ItemGroup>
-    <Folder Include="data\" />
-    <Folder Include="Input\" />
-    <Folder Include="API\" />
-    <Folder Include="Types\" />
-  </ItemGroup>
+<?xml version="1.0" encoding="utf-8"?>

+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+  <PropertyGroup>

+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>

+    <ProjectGuid>{89E37932-E22D-4D94-8438-ACEB73667456}</ProjectGuid>

+    <OutputType>Exe</OutputType>

+    <RootNamespace>sandbox</RootNamespace>

+    <AssemblyName>sandbox</AssemblyName>

+    <StartupObject>sandbox.Program</StartupObject>

+    <CodePage>65001</CodePage>

+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

+  </PropertyGroup>

+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">

+    <DebugSymbols>true</DebugSymbols>

+    <DebugType>full</DebugType>

+    <Optimize>false</Optimize>

+    <OutputPath>bin\Debug</OutputPath>

+    <DefineConstants>DEBUG;</DefineConstants>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <PlatformTarget>x86</PlatformTarget>

+    <ConsolePause>false</ConsolePause>

+  </PropertyGroup>

+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">

+    <Optimize>true</Optimize>

+    <OutputPath>bin\Release</OutputPath>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <PlatformTarget>x86</PlatformTarget>

+    <ConsolePause>false</ConsolePause>

+  </PropertyGroup>

+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

+  <ItemGroup>

+    <Compile Include="Program.cs" />

+    <Compile Include="Game.cs" />

+    <Compile Include="Texture2D.cs" />

+    <Compile Include="DrawingFunctions.cs" />

+    <Compile Include="Input\InputManager.cs" />

+    <Compile Include="Input\InputSubscription.cs" />

+    <Compile Include="Loaders.cs" />

+    <Compile Include="Yoda.cs" />

+    <Compile Include="API\IGameModule.cs" />

+    <Compile Include="API\IRenderModule.cs" />

+    <Compile Include="API\AGameModuleDependency.cs" />

+    <Compile Include="Tools.cs" />

+    <Compile Include="TextWriter.cs" />

+    <Compile Include="JustSomeText.cs" />

+    <Compile Include="Types\Entity.cs" />

+    <Compile Include="Types\Rect.cs" />

+    <Compile Include="Types\RollingAverage.cs" />

+  </ItemGroup>

+  <ItemGroup>

+    <Reference Include="System.Drawing" />

+    <Reference Include="System" />

+    <Reference Include="OpenTK">

+      <HintPath>..\..\libs\OpenTK.dll</HintPath>

+    </Reference>

+  </ItemGroup>

+  <ItemGroup>

+    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\AlternatingBrick-ColorMap.png">

+      <Link>data\AlternatingBrick-ColorMap.png</Link>

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\AlternatingBrick-NormalMap.png">

+      <Link>data\AlternatingBrick-NormalMap.png</Link>

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\font24.fnt">

+      <Link>data\font24.fnt</Link>

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="..\..\opengl4tutorials\OpenGLTutorial13\OpenGLTutorial13\data\font24.png">

+      <Link>data\font24.png</Link>

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="data\Yoda-276x276.jpg">

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+  </ItemGroup>

+  <ItemGroup>

+    <Folder Include="data\" />

+    <Folder Include="Input\" />

+    <Folder Include="API\" />

+    <Folder Include="Types\" />

+  </ItemGroup>

 </Project>