-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8788817
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# This file describes files and paths that should not be tracked by Git version control | ||
# https://git-scm.com/docs/gitignore | ||
|
||
# Auto-generated code editor files | ||
.vs/* | ||
.vscode/* | ||
*.csproj | ||
obj/* | ||
Properties/* | ||
code/obj/* | ||
code/Properties/* | ||
|
||
# Auto-generated asset related files | ||
*.generated.* | ||
*.*_c | ||
*.los | ||
*.vpk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"Title": "perfmon", | ||
"Type": "library", | ||
"Org": "nfm", | ||
"Ident": "perfmon", | ||
"Tags": null, | ||
"Schema": 1, | ||
"HasAssets": true, | ||
"AssetsPath": "", | ||
"Resources": null, | ||
"MenuResources": null, | ||
"HasCode": true, | ||
"CodePath": ".", | ||
"PackageReferences": [], | ||
"EditorReferences": null, | ||
"Metadata": { | ||
"ProjectTemplate": null, | ||
"CsProjName": "", | ||
"Compiler": { | ||
"RootNamespace": "Sandbox", | ||
"DefineConstants": "SANDBOX;ADDON;DEBUG", | ||
"NoWarn": "1701;1702;1591;", | ||
"WarningsAsErrors": "", | ||
"References": [], | ||
"DistinctReferences": [] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Non | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@using System; | ||
@using Sandbox; | ||
@using Sandbox.UI; | ||
|
||
@inherits Panel | ||
@attribute [StyleSheet] | ||
|
||
@namespace Perfmon | ||
|
||
<root class="perfmon"> | ||
<div class="fps @FPSStatus"> | ||
<p>@fps fps / @ms ms</p> | ||
</div> | ||
</root> | ||
|
||
@code | ||
{ | ||
string FPSStatus | ||
{ | ||
get | ||
{ | ||
if (fps >= 60) return "green"; | ||
if (fps >= 30) return "orange"; | ||
else return "red"; | ||
} | ||
} | ||
|
||
float fps; | ||
float ms; | ||
|
||
float updateRate = 1f; | ||
float deltaBetweenUpdates; | ||
int framesBetweenUpdates; | ||
|
||
public Perfmon() | ||
{ | ||
// RenderedManually = true; // Only for RootPanel | ||
// Scale = 1; // Only for RootPanel | ||
} | ||
|
||
[Sandbox.GameEvent.Client.FrameAttribute] | ||
void NewFrame() | ||
{ | ||
deltaBetweenUpdates += Time.Delta; | ||
framesBetweenUpdates++; | ||
|
||
if (deltaBetweenUpdates > 1 / updateRate) | ||
{ | ||
//Log.Info("Updating FPS meter"); | ||
// Update FPS meter | ||
fps = (float)Math.Round(framesBetweenUpdates / deltaBetweenUpdates, 2, MidpointRounding.AwayFromZero); | ||
ms = (float)Math.Round(deltaBetweenUpdates / framesBetweenUpdates * 1000f, 2, MidpointRounding.AwayFromZero); | ||
|
||
// Reset counters | ||
deltaBetweenUpdates = 0; | ||
framesBetweenUpdates = 0; | ||
|
||
// Invalidate Panel | ||
StateHasChanged(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.perfmon { | ||
margin-left: auto; | ||
margin-right: 5px; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
width: 200px; | ||
height: 100px; | ||
border: 3px solid rgba(255, 255, 255, 0.1); | ||
border-radius: 10px; | ||
} | ||
|
||
.fps { | ||
font-weight: bold; | ||
text-align: right; | ||
} | ||
|
||
.red { | ||
color: rgb(255, 0, 0); | ||
} | ||
|
||
.orange { | ||
color: rgb(255, 150, 0); | ||
} | ||
|
||
.green { | ||
color: rgb(0, 255, 0); | ||
} |