Skip to content

Commit

Permalink
Multiple rendering related changes
Browse files Browse the repository at this point in the history
-Made shaders load into a list to be globally accessed instead of loaded per instance, program now accesses pre loaded shaders.
-Made textures load into a list to be globally accessed instad of loaded per instance, program now accesses pre loaded textures.
-Made models load into a list to be globally accessed instad of loaded per instance, program now accesses pre loaded models.
-commented out unecessary unbinding code for draw calls reducing driver overhead
-increased accuracy and detail of debugging screen and profiler ms averages.
  • Loading branch information
fredrickbancan committed Sep 15, 2020
1 parent aba0e0d commit c6b54f8
Show file tree
Hide file tree
Showing 39 changed files with 580 additions and 250 deletions.
6 changes: 5 additions & 1 deletion Coictus/Coictus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@
<Compile Include="Src\Rendering\Models\EntityModels\Tank\EntityTankModel.cs" />
<Compile Include="Src\Rendering\Models\EntityModels\Tank\EntityTankProjectileModel.cs" />
<Compile Include="Src\Rendering\Models\ModelDrawableDynamicInterpolated.cs" />
<Compile Include="Src\Rendering\Models\ModelDrawableInstanced.cs" />
<Compile Include="Src\Rendering\Models\ModelDrawableInstancedInterpolated.cs" />
<Compile Include="Src\Rendering\Models\ModelUtil.cs" />
<Compile Include="Src\Rendering\Models\Prefabs\CubePrefab.cs" />
<Compile Include="Src\Rendering\Models\Prefabs\DefaultDebugModel.cs" />
<Compile Include="Src\Rendering\Models\OBJProcessing\OBJLoader.cs" />
<Compile Include="Src\Rendering\Models\OBJLoader.cs" />
<Compile Include="Src\Rendering\ShaderUtil.cs" />
<Compile Include="Src\Rendering\SubRendering\Batching\LineBatcher.cs" />
<Compile Include="Src\Rendering\SubRendering\GUI\GUIScreen.cs" />
<Compile Include="Src\Rendering\SubRendering\GUI\GUIScreenComponent.cs" />
<Compile Include="Src\Rendering\SubRendering\Batching\TriangleBatcher.cs" />
<Compile Include="Src\Rendering\SubRendering\OffScreen.cs" />
<Compile Include="Src\Rendering\TextureUtil.cs" />
<Compile Include="Src\Rendering\VFX\VFXExplosion.cs" />
<Compile Include="Src\Rendering\VFX\VFXPointParticles.cs" />
<Compile Include="Src\Rendering\VFX\VFXUtil.cs" />
Expand Down
40 changes: 25 additions & 15 deletions Coictus/Src/Game/Debugging/DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Coictus.GUI;
using Coictus.GUI.Text;
using System;

namespace Coictus.Debugging
{
/*A class for abstracting the process of displaying debug information on the screen when active.*/
public static class DebugInfo
{
public static readonly string debugInfoPanelName = "debugInfo";

private static float collisionsAverage;
private static float gameLoopAverage;
private static float renderAverage;
/*Initialize the text panel for the debug info, can only be done if the mainGUI panel is created first*/
public static void init()
{
Expand All @@ -17,7 +18,7 @@ public static void init()
{
("press F3 to hide debug screen.")
}
).setPanelColor(CustomColor.grey)));
).setPanelColor(CustomColor.black)));
}

/*Shows and updates the debug info on the screen, Can be called every tick (Do not call every frame, too expensive)*/
Expand All @@ -26,23 +27,32 @@ public static void displayOrClearDebugInfo()
if (GameSettings.debugScreen && GameInstance.get.thePlayer != null)
{
GUIHandler.unHideTextPanelInGUI(MainGUI.mainGUIName, debugInfoPanelName);
collisionsAverage = Profiler.getAveragesForProfile(Profiler.collisionsName);
gameLoopAverage = Profiler.getAveragesForProfile(Profiler.gameLoopName);
renderAverage = Profiler.getAveragesForProfile(Profiler.renderingName);
GUIHandler.getTextPanelFormatFromGUI(MainGUI.mainGUIName, debugInfoPanelName).setLines(
new string[]
{
("Player Name: " + GameInstance.get.thePlayer.getName()),
("X: " + GameInstance.get.thePlayer.getPosition().X.ToString("0.##")),
("Y: " + GameInstance.get.thePlayer.getPosition().Y.ToString("0.##")),
("Z: " + GameInstance.get.thePlayer.getPosition().Z.ToString("0.##")),
("Velocity X: " + GameInstance.get.thePlayer.getVelocity().X.ToString("0.##")),
("Velocity Y: " + GameInstance.get.thePlayer.getVelocity().Y.ToString("0.##")),
("Velocity Z: " + GameInstance.get.thePlayer.getVelocity().Z.ToString("0.##")),
("Head Pitch: " + GameInstance.get.thePlayer.getHeadPitch().ToString("0.##")),
("Yaw: " + GameInstance.get.thePlayer.getYaw().ToString("0.##")),
("X: " + GameInstance.get.thePlayer.getPosition().X.ToString("0.00")),
("Y: " + GameInstance.get.thePlayer.getPosition().Y.ToString("0.00")),
("Z: " + GameInstance.get.thePlayer.getPosition().Z.ToString("0.00")),
("Velocity X: " + GameInstance.get.thePlayer.getVelocity().X.ToString("0.00")),
("Velocity Y: " + GameInstance.get.thePlayer.getVelocity().Y.ToString("0.00 ")),
("Velocity Z: " + GameInstance.get.thePlayer.getVelocity().Z.ToString("0.00")),
("Head Pitch: " + GameInstance.get.thePlayer.getHeadPitch().ToString("0.00")),
("Yaw: " + GameInstance.get.thePlayer.getYaw().ToString("0.00")),
("Profiler ms averages: "),
("Render: " + Profiler.getAveragesForProfile(Profiler.renderingName).ToString("0.##") + " ms."),
("Game loop: " + Profiler.getAveragesForProfile(Profiler.gameLoopName).ToString("0.##") + " ms."),
("Collisions: " + Profiler.getAveragesForProfile(Profiler.collisionsName).ToString("0.##") + " ms."),
("Entities: " + GameInstance.get.currentPlanet.getEntityCount())
("{"),
(" [Per Frame]Render: " + renderAverage.ToString("0.00 ms")),
(" [Per Tick]Game loop: " + gameLoopAverage.ToString("0.00 ms") + (gameLoopAverage / TicksAndFps.tps).ToString(" (0.00 ms per frame)")),
(" {"),
(" Collisions: " + collisionsAverage.ToString("0.00 ms") + (collisionsAverage / TicksAndFps.tps).ToString(" (0.00 ms per frame)")),
(" }Residual: " + (gameLoopAverage - collisionsAverage).ToString("0.00 ms") + ((gameLoopAverage - collisionsAverage) / TicksAndFps.tps).ToString(" (0.00 ms per frame)")),
("}"),
("Entities: " + GameInstance.get.currentPlanet.getEntityCount()),
("VFX's: " + GameInstance.get.currentPlanet.getVFXCount()),
("Draw Calls: " + Renderer.getAndResetTotalDrawCount()),
});
}
else
Expand Down
6 changes: 3 additions & 3 deletions Coictus/Src/Game/Debugging/HitboxRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Coictus.Debugging
/*This class handles the rendering of hitboxes for debugging purposes.*/
public static class HitboxRenderer
{
private static string linesShader = ResourceUtil.getShaderFileDir("Color3D.shader");
public static readonly string linesShaderName = "Color3D.shader";


public static readonly int maxAABBRenderCount = 512;
Expand All @@ -27,9 +27,9 @@ public static void init()
/*Builds the prefab model for an AABB, basically a cube made of lines*/
private static void buildAABBModel()
{
aabbDynamicModel = new ModelDrawableDynamic(linesShader, "none", LineBatcher.getIndicesForLineQuadCount(maxAABBRenderCount * 6), maxAABBRenderCount * 48 /*aabb models have 48 vertices*/);//initializing dynamic model for drawing aabb
aabbDynamicModel = new ModelDrawableDynamic(linesShaderName, "none", LineBatcher.getIndicesForLineQuadCount(maxAABBRenderCount * 6), maxAABBRenderCount * 48 /*aabb models have 48 vertices*/);//initializing dynamic model for drawing aabb

aabbModelPrefab = CubePrefab.getNewModel();
aabbModelPrefab = CubePrefab.copyModel();
}

/*called on tick. Adds all of the provided colliders to a list of hitboxes to be dynamically batched and drawn.*/
Expand Down
30 changes: 12 additions & 18 deletions Coictus/Src/Game/Debugging/Profiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public static float getAveragesForProfile(string profileName)
/*private class for profiles.*/
private class Profile
{
private int[] recordedTimes = new int[100];
private long startTime;
private string name;
private int totalUpdates;
private long combinedTimePassed;
private int updateIndex;
private int combinedTimePassed;
public bool hasEnded = false;

public Profile(string name)
Expand All @@ -61,38 +62,31 @@ public Profile(string name)

public Profile begin()
{
startTime = TicksAndFps.getMiliseconds();
startTime = TicksAndFps.getCurrentTime();
hasEnded = false;
return this;
}

public void end()
{
combinedTimePassed += (TicksAndFps.getMiliseconds() - startTime);
totalUpdates++;
int time = (int)(TicksAndFps.getCurrentTime() - startTime);
combinedTimePassed -= recordedTimes[updateIndex];
combinedTimePassed += time;
recordedTimes[updateIndex++] = time;
updateIndex %= 100;//keep update index within 100
hasEnded = true;
}

public float getAverageCompletionTime()
{
if(totalUpdates < 1)
{
return (float)combinedTimePassed;
}
float result = (float)combinedTimePassed / (float)totalUpdates;

if(totalUpdates >= 100)//resetting after 100 updates to give a more accurate result
{
totalUpdates = 0;
combinedTimePassed = 0;
}
return result;
return (float)combinedTimePassed / 100F;
}

private void printInfo()
{
Console.BackgroundColor = ConsoleColor.Cyan;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("Profile: \"" + name + "\" measured " + (TicksAndFps.getMiliseconds() - startTime) + " miliseconds from start to finish.");
Console.WriteLine("Profile: \"" + name + "\" measured " + (TicksAndFps.getCurrentTime() - startTime) + " miliseconds from start to finish.");
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.White;
}
Expand Down
9 changes: 5 additions & 4 deletions Coictus/Src/Game/GUIS/MainGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void init()
/*Called every tick*/
public static void onTick()
{
displayFps();
/*Temporary, for arcade popups.*/
if (showingDirectHitPopup)
{
Expand Down Expand Up @@ -127,17 +128,17 @@ public static void onAirShot()
}

/*Called every second by the TicksAndFps class to display new fps if setting is on*/
public static void displayFps(int fps)
public static void displayFps()
{
if (GameSettings.displayFps)
{
GUIHandler.unHideTextPanelInGUI(mainGUIName, fpsPanelName);
string fpsstring = fps.ToString();
if (fps < 75)
string fpsstring = TicksAndFps.fps.ToString();
if (TicksAndFps.fps < 75)
{
GUIHandler.getTextPanelFormatFromGUI(mainGUIName, fpsPanelName).setLine(fpsstring).setPanelColor(CustomColor.red);
}
else if (fps < 120)
else if (TicksAndFps.fps < 120)
{
GUIHandler.getTextPanelFormatFromGUI(mainGUIName, fpsPanelName).setLine(fpsstring).setPanelColor(CustomColor.yellow);
}
Expand Down
23 changes: 12 additions & 11 deletions Coictus/Src/Game/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenTK;
using OpenTK.Graphics;
using System;
using System.ComponentModel;
using System.Drawing;

namespace Coictus
Expand Down Expand Up @@ -39,7 +40,6 @@ public GameInstance(int screenWidth, int screenHeight, int initialWindowWidth, i

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GameInstance.instance = this;
GameInstance.privateRand = new Random();
GameInstance.mouseCenterX = this.X + this.Width / 2;
Expand All @@ -48,7 +48,7 @@ protected override void OnLoad(EventArgs e)
TextUtil.loadAllFoundTextFiles();
setDPIScale();
Renderer.init();
TicksAndFps.init(30.0F);
TicksAndFps.init(30);
MainGUI.init();
DebugInfo.init();
HitboxRenderer.init();
Expand All @@ -65,20 +65,14 @@ protected override void OnLoad(EventArgs e)
//center mouse in preperation for first person
Input.centerMouse();
Input.toggleHideMouse();
}


/*overriding OpenTk game update function, called every frame.*/
protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);

base.OnLoad(e);
}

/*overriding OpenTk render update function, called every frame.*/
protected override void OnRenderFrame(FrameEventArgs args)
{
base.OnRenderFrame(args);

for (int i = 0; i < TicksAndFps.getTicksElapsed(); i++)//for each tick that has elapsed since the start of last update, run the games logic enough times to catch up.
{
onTick();
Expand Down Expand Up @@ -119,24 +113,31 @@ private void onTick()
Profiler.beginEndProfile(Profiler.gameLoopName);
}

//TODO: Create event system for handling these events

/*Called when player lands direct hit on a cactus, TEMPORARY!*/
public static void onDirectHit()
{
MainGUI.onDirectHit();
}

/*Called when player lands air shot on a cactus, TEMPORARY!*/
public static void onAirShot()
{
MainGUI.onAirShot();
}

public static void pauseGame()
{
Input.centerMouse(); // center the mouse cursor when closing or opening menu
Input.toggleHideMouse();
GameInstance.get.thePlayer.togglePause();
}

protected override void OnClosing(CancelEventArgs e)
{
Renderer.onClosing();
base.OnClosing(e);
}
private void setDPIScale()
{
Graphics g = Graphics.FromHwnd(this.WindowInfo.Handle);
Expand Down
2 changes: 1 addition & 1 deletion Coictus/Src/Game/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Coictus

/*This class is responsable for detecting input which changes the players state.
Such as movement, inventory use, attacking etc*/
public static class PlayerController//TODO: impliment custom bindings in gamesettings
public static class PlayerController
{
private static KeyboardState currentKeyboardState;
private static MouseState currentMouseState;
Expand Down
12 changes: 5 additions & 7 deletions Coictus/Src/Game/ResourceUtil.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using System;

namespace Coictus
namespace Coictus
{
/*A class containing functions to gelp find resources. This class will make it much easier to change resource directories.*/
public static class ResourceUtil
{
public static string getTextureFileDir(string fileName)
public static string getTextureFileDir(string fileName = "")
{
return @"..\..\Res\Texture\" + fileName;
}

public static string getFontFileDir(string fileName)
public static string getFontFileDir(string fileName = "")
{
return @"..\..\Res\Font\" + fileName;
}

public static string getShaderFileDir(string shaderName)
public static string getShaderFileDir(string shaderName = "")
{
return @"..\..\Res\Shaders\" + shaderName;
}
public static string getOBJFileDir(string modelName)
public static string getOBJFileDir(string modelName = "")
{
return @"..\..\Res\OBJ\" + modelName;
}
Expand Down
Loading

0 comments on commit c6b54f8

Please sign in to comment.