Fps + InGame Console
Monkey Forums/Monkey Code/Fps + InGame Console
| ||
Hello, This is part of my Debug Module and I thought it might be useful for some. It draws the current Frames per second and a window which acts like the textarea in html5. Instructions how to use in the top Rem comment block. [monkeycode] Strict Import mojo #Rem - Use ShowDebugInfo() in OnRender() after all other drawing commands - Use DebugLog (String) to output text to the Console - GetFps() relies on FpsCounter.Update() (if you don't call ShowDebugInfo you have to call FpsCounter.Update() manually) #End Function ShowDebugInfo:Void() FpsCounter.Update() InGameConsole.Render() FpsCounter.Render() End Function DebugLog:Void (message:String) InGameConsole.AddMessage (message) End Function GetFps:Void() Return FpsCounter.CurrentRate End Private Class FpsCounter Final Global fpsCount:Int Global startTime:Int Global CurrentRate:Int Function Update:Void() If (Millisecs() - startTime) >= 1000 CurrentRate = fpsCount fpsCount = 0 startTime = Millisecs() Else fpsCount += 1 End End Function Render:Void() SetColor (255, 255, 255) SetAlpha (0.4) DrawText ("FPS >> " + FpsCounter.CurrentRate, 4, 4) End End Class InGameConsole Final Function AddMessage:Void (message:String) Output.AddLast (message) If Output.Count() > MaxItems scrolling = 16 removeAfterScrolling += 1 End End Function Render:Void() SetScissor (0, 20, 180, 204) SetAlpha (0.4) SetColor (0, 0, 0) DrawRect (0, 0, 180, 224) SetColor (255, 255, 255) scrolling -= 2 scrolling = Max (scrolling, 0) If removeAfterScrolling > 0 Output.RemoveFirst() removeAfterScrolling -= 1 End Local s:String Local yPos:Int = 26 For s = Eachin Output DrawText ("~ " + s, 12, yPos + scrolling) yPos += 16 Next SetScissor (0, 0, DeviceWidth(), DeviceHeight()) End Global Output:StringList = New StringList() Global MaxItems:Int = 12 Global scrolling:Int = 0 Global removeAfterScrolling:Int End [/monkeycode] I hope you like it. |
| ||
very generous, thanks |