/////////////////////////////////////////////////////////////////////////////////////////////// private static ProfileInformation FindProfileBlock(String id) { ProfileInformation result = null; if (m_profileDictionary.ContainsKey(id)) { result = m_profileDictionary[id]; } return(result); }
public static void Initialize(bool millisecondTimer, Game game, SpriteFont spriteFont) { m_millisecondTimer = millisecondTimer; m_profileDictionary = new Dictionary<string, ProfileInformation>(); m_profileDictionary[m_totalID] = new ProfileInformation(m_totalID, m_millisecondTimer); m_texture = new Texture2D(game.GraphicsDevice, s_textureWidth, s_textureHeight); ScreenPosition = new Vector2(0, 30); m_spriteBatch = new SpriteBatch(game.GraphicsDevice); m_spriteFont = spriteFont; }
public static void Initialize(bool millisecondTimer, Game game, SpriteFont spriteFont) { m_millisecondTimer = millisecondTimer; m_profileDictionary = new Dictionary <string, ProfileInformation>(); m_profileDictionary[m_totalID] = new ProfileInformation(m_totalID, m_millisecondTimer); m_texture = new Texture2D(game.GraphicsDevice, s_textureWidth, s_textureHeight); ScreenPosition = new Vector2(0, 30); m_spriteBatch = new SpriteBatch(game.GraphicsDevice); m_spriteFont = spriteFont; }
/////////////////////////////////////////////////////////////////////////////////////////////// public static void EndProfileBlock(String id) { if (Enabled) { ProfileInformation info = FindProfileBlock(id); //System.Diagnostics.Debug.Assert(info != null, "Trying to close a block that wasn't opened"); // stopped asserts here as with this toggleable we can miss an update if (info != null) { info.stop(); } } }
/////////////////////////////////////////////////////////////////////////////////////////////// public static void StartProfileBlock(String id) { if (Enabled) { ProfileInformation info = FindProfileBlock(id); if (info == null) { info = new ProfileInformation(id, m_millisecondTimer); m_profileDictionary[id] = info; } info.start(); } }
/////////////////////////////////////////////////////////////////////////////////////////////// public static void Draw(GameTime gameTime) { if (Enabled) { //SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState, Matrix.Identity); int numEntries = m_profileDictionary.Count; int ystep = s_textureHeight / numEntries; int counter = 0; //int fontHeight = m_spriteFont. ProfileInformation totalPI = m_profileDictionary[m_totalID]; //unsafe { uint[] textureData = new uint[s_textureWidth * s_textureHeight]; //Array.Clear(textureData, 0, textureData.Length); m_texture.GetData <uint>(textureData); foreach (String key in m_profileDictionary.Keys) { ProfileInformation currentPi = m_profileDictionary[key]; Vector2 lineDims = m_spriteFont.MeasureString(currentPi.debugInfo()); float scaler = totalPI.LastTime != 0 ? (float)((double)currentPi.LastTime / (double)totalPI.LastTime) : 1.0f; // seems to have a bug where individual values exceed total so clamp. scaler = Math.Min(1f, scaler); int scaledWidth = (int)(scaler * s_textureWidth); Color colour = Color.White; switch (counter % 3) { case 0: colour = Color.Red; break; case 1: colour = Color.Yellow; break; case 2: colour = Color.Green; break; } int xpos = (int)ScreenPosition.X; int ypos = (int)ScreenPosition.Y + (counter * ystep); for (int y = 0; y < ystep; ++y) { for (int x = 0; x < scaledWidth; ++x) { int index = (ystep * counter * s_textureWidth) + (s_textureWidth * y) + x; textureData[index] = colour.PackedValue; } for (int x = scaledWidth; x < s_textureWidth; ++x) { int index = (ystep * counter * s_textureWidth) + (s_textureWidth * y) + x; textureData[index] = Color.Gray.PackedValue; } } counter++; } m_texture.SetData(textureData); } SpriteBatch.Begin(); SpriteBatch.Draw(m_texture, ScreenPosition, Color.White); counter = 0; foreach (string key in m_profileDictionary.Keys) { int xpos = (int)ScreenPosition.X; int ypos = (int)ScreenPosition.Y + (counter * ystep); String debugInfo = m_profileDictionary[key].debugInfo(); Vector2 lineDims = m_spriteFont.MeasureString(debugInfo); SpriteBatch.DrawString(m_spriteFont, debugInfo, new Vector2(xpos, ypos), Color.Black); ++counter; } SpriteBatch.End(); } }