diff --git a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java index 153489f6..d34e3c2f 100644 --- a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java +++ b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java @@ -34,6 +34,12 @@ public class ImGuiBarPlot implements ImGuiElement { double[] xs = IntStream.range(0, dataPoints.size()).mapToDouble(v -> (double)v).toArray(); double[] ys = dataPoints.stream().map(v -> v.value).mapToDouble(Double::doubleValue).toArray(); ImPlot.plotBars(plotTitle, xs, ys, dataPoints.size(), width, 0); + int i = 0; + for(ImGuiBarPlotDatapoint point : dataPoints){ + //coordinates are inside the plot itself, not relative to window + ImPlot.plotText(point.label, i, 1, true); + i++; + } ImPlot.endPlot(); } } diff --git a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java index 596f9e3a..c18fc769 100644 --- a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java +++ b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java @@ -27,6 +27,7 @@ public class ImGuiWindowMacros { //server sim time graph private static ImGuiWindow serverFrametimeWindow; private static ImGuiBarPlot serverFrametimePlot; + private static double serverFrametimeTrackerStorage = 0; /** * Initializes imgui windows @@ -101,12 +102,19 @@ public class ImGuiWindowMacros { } /** - * Adds an amount to a single bar in the server frametime graph - * @param valueName The value to add to - * @param amountToAdd The amount to add + * Starts a tracker for server frametime for a given method */ - public static void addToServerFrametimeValue(String valueName, double amountToAdd){ - serverFrametimePlot.addToDatapoint(valueName, amountToAdd); + public static void startServerFrametimeTrackerFlame(double startValue){ + serverFrametimeTrackerStorage = startValue; + } + + /** + * Finishes tracking a single run of a specific method + * @param valueName The name of the method + * @param endValue the end time that the method finished on + */ + public static void clockServerFrametimeTrackerFlame(String valueName, double endValue){ + serverFrametimePlot.addToDatapoint(valueName, endValue - serverFrametimeTrackerStorage); } /** diff --git a/src/main/java/electrosphere/server/datacell/Realm.java b/src/main/java/electrosphere/server/datacell/Realm.java index 89a4b6ba..6287d1ff 100644 --- a/src/main/java/electrosphere/server/datacell/Realm.java +++ b/src/main/java/electrosphere/server/datacell/Realm.java @@ -7,6 +7,7 @@ import electrosphere.entity.Entity; import electrosphere.entity.Scene; import electrosphere.entity.types.hitbox.HitboxManager; import electrosphere.net.parser.net.message.NetworkMessage; +import electrosphere.renderer.ui.imgui.ImGuiWindowMacros; import electrosphere.server.datacell.interfaces.DataCellManager; import java.util.HashSet; @@ -155,10 +156,15 @@ public class Realm { * Tells the data cell manager to simulate all loaded cells */ protected void simulate(){ + ImGuiWindowMacros.clearServerFrametime(); //simulate bullet physics engine step + ImGuiWindowMacros.startServerFrametimeTrackerFlame(System.currentTimeMillis()); collisionEngine.simulatePhysics(Main.deltaFrames); + ImGuiWindowMacros.clockServerFrametimeTrackerFlame("physics", System.currentTimeMillis()); //main simulation + ImGuiWindowMacros.startServerFrametimeTrackerFlame(System.currentTimeMillis()); dataCellManager.simulate(); + ImGuiWindowMacros.clockServerFrametimeTrackerFlame("simulate", System.currentTimeMillis()); //data cell manager update misc variables (player positions, unload not-in-use cells) if(dataCellManager != null){ dataCellManager.unloadPlayerlessChunks();