diff --git a/.gitignore b/.gitignore index 10efd345..191dd27a 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,7 @@ .settings #docs -/docs-dist/** \ No newline at end of file +/docs-dist/** + +#imgui local layout +/imgui.ini \ No newline at end of file diff --git a/docs/src/highlevel-design/highleveldesignindex.md b/docs/src/highlevel-design/highleveldesignindex.md index 1dbd8ac8..fc8f5f54 100644 --- a/docs/src/highlevel-design/highleveldesignindex.md +++ b/docs/src/highlevel-design/highleveldesignindex.md @@ -8,3 +8,4 @@ - @subpage magicindex - @subpage creaturesindex - @subpage macrosimtimeline +- @subpage narrativemanager diff --git a/docs/src/highlevel-design/locations/macrolocationideas.md b/docs/src/highlevel-design/locations/macrolocationideas.md index 9ae5f4b9..bfa34b09 100644 --- a/docs/src/highlevel-design/locations/macrolocationideas.md +++ b/docs/src/highlevel-design/locations/macrolocationideas.md @@ -36,4 +36,7 @@ - IDK if this should be made out of marching cubes or particles or what ### Massive Ruins - - For instance sticking out of the side of a mountain and of comparable size to said mountain \ No newline at end of file + - For instance sticking out of the side of a mountain and of comparable size to said mountain + +### Sunset Ruins + - Extremely tall ruins that are permanently sunset. Always overcast with godrays shooting through. \ No newline at end of file diff --git a/docs/src/highlevel-design/narrativemanager/narrativemanager.md b/docs/src/highlevel-design/narrativemanager/narrativemanager.md new file mode 100644 index 00000000..dcc6ccdd --- /dev/null +++ b/docs/src/highlevel-design/narrativemanager/narrativemanager.md @@ -0,0 +1,8 @@ +@page narrativemanager Narrative Manager + +TODO: describe + +basic idea is have a system that watches over each player and tries to shape the world around them to create interesting stories. +ie creates quests and tries to lightly railroad the players on to them -- or at the very least provides them as options. +Will need to have plotline templates and generate/select characters to be members of that plotline. +Then move macro level pieces around to conform to the plotline. \ No newline at end of file diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index ab0bde9e..1df2758e 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -141,6 +141,11 @@ Bake in imgui # TODO +Server frametime bar graph + +Environment background noise manager - does what it says on the tin + +Methods for sleeping physics bodies if nothing nearby them is dynamic (ie trees if there are no moving creatures near them) diff --git a/imgui.ini b/imgui.ini deleted file mode 100644 index 01aa08ea..00000000 --- a/imgui.ini +++ /dev/null @@ -1,25 +0,0 @@ -[Window][Debug##Default] -Pos=60,60 -Size=400,400 -Collapsed=0 - -[Window][test window] -Pos=791,428 -Size=328,189 -Collapsed=1 - -[Window][FPS Graph] -Pos=1148,36 -Size=775,335 -Collapsed=0 - -[Window][Frametime Graph] -Pos=1308,4 -Size=566,324 -Collapsed=0 - -[Window][Debug] -Pos=10,9 -Size=178,77 -Collapsed=0 - diff --git a/src/main/java/electrosphere/engine/Main.java b/src/main/java/electrosphere/engine/Main.java index 22d19735..be20171f 100644 --- a/src/main/java/electrosphere/engine/Main.java +++ b/src/main/java/electrosphere/engine/Main.java @@ -244,7 +244,7 @@ public class Main { // track total frametiime in debug graph // if(captureFramerate){ - ImGuiWindowMacros.addFramerateDatapoint("totalframerate",deltaTime * 1000); + ImGuiWindowMacros.addGlobalFramerateDatapoint("totalframerate",deltaTime * 1000); } @@ -303,7 +303,7 @@ public class Main { ClientFunctions.runClientFunctions(); } if(!Globals.HEADLESS && captureFramerate){ - ImGuiWindowMacros.addFramerateDatapoint("clientsim",(glfwGetTime()-functionTrackTimeStart)*1000); + ImGuiWindowMacros.addGlobalFramerateDatapoint("clientsim",(glfwGetTime()-functionTrackTimeStart)*1000); } @@ -333,7 +333,7 @@ public class Main { Globals.macroSimulation.simulate(); } if(!Globals.HEADLESS && captureFramerate){ - ImGuiWindowMacros.addFramerateDatapoint("serversim",(glfwGetTime()-functionTrackTimeStart)*1000); + ImGuiWindowMacros.addGlobalFramerateDatapoint("serversim",(glfwGetTime()-functionTrackTimeStart)*1000); } @@ -349,7 +349,7 @@ public class Main { Globals.renderingEngine.drawScreen(); } if(!Globals.HEADLESS && captureFramerate){ - ImGuiWindowMacros.addFramerateDatapoint("render",(glfwGetTime()-functionTrackTimeStart)*1000); + ImGuiWindowMacros.addGlobalFramerateDatapoint("render",(glfwGetTime()-functionTrackTimeStart)*1000); } diff --git a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java new file mode 100644 index 00000000..153489f6 --- /dev/null +++ b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiBarPlot.java @@ -0,0 +1,100 @@ +package electrosphere.renderer.ui.imgui; + +import java.util.LinkedList; +import java.util.List; +import java.util.stream.IntStream; + +import imgui.ImVec2; +import imgui.extension.implot.ImPlot; +import imgui.extension.implot.flag.ImPlotAxisFlags; + +/** + * A bar plot + */ +public class ImGuiBarPlot implements ImGuiElement { + + //the title of the plot + String plotTitle; + + //the data sets to draw + List dataPoints = new LinkedList(); + + float width = 0.5f; + + /** + * Creates an im gui line plot + */ + public ImGuiBarPlot(String plotTitle){ + this.plotTitle = plotTitle; + } + + @Override + public void draw() { + if(ImPlot.beginPlot(plotTitle,"","",new ImVec2(-1,-1),0,ImPlotAxisFlags.AutoFit,ImPlotAxisFlags.AutoFit)){ + 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); + ImPlot.endPlot(); + } + } + + /** + * Adds a datapoint to the bar plot + * @param datapoint The datapoint + */ + public void addDatapoint(ImGuiBarPlotDatapoint datapoint){ + this.dataPoints.add(datapoint); + } + + /** + * Adds a value amount to the current amount in a given datapoint. If the datapoint is null, it is created with value as its initial amount. + * @param datapointName The datapoint's name + * @param value The value to add to the datapoint + */ + public void addToDatapoint(String datapointName, double value){ + ImGuiBarPlotDatapoint targetDatapoint = null; + for(ImGuiBarPlotDatapoint point : dataPoints){ + if(point.label.equals(datapointName)){ + targetDatapoint = point; + break; + } + } + if(targetDatapoint!=null){ + targetDatapoint.value = targetDatapoint.value + value; + } else { + dataPoints.add(new ImGuiBarPlotDatapoint(datapointName, value)); + } + } + + /** + * Clears the values in all datapoints + */ + public void clearDatapoints(){ + for(ImGuiBarPlotDatapoint dataPoint : dataPoints){ + dataPoint.value = 0; + } + } + + /** + * A single set of data to be plotted in this graph + */ + public static class ImGuiBarPlotDatapoint { + + //the label of the line + String label; + + double value; + + /** + * Creates a datapoint object + * @param label the label for the data + * @param value the value of this bar item + */ + public ImGuiBarPlotDatapoint(String label, double value){ + this.label = label; + this.value = value; + } + + + } +} diff --git a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java index 62f998be..596f9e3a 100644 --- a/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java +++ b/src/main/java/electrosphere/renderer/ui/imgui/ImGuiWindowMacros.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import electrosphere.renderer.RenderingEngine; +import electrosphere.renderer.ui.imgui.ImGuiBarPlot.ImGuiBarPlotDatapoint; import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; import imgui.ImGui; @@ -13,39 +14,46 @@ import imgui.ImGui; */ public class ImGuiWindowMacros { - //Framerate graph - private static ImGuiWindow framerateWindow; - private static ImGuiLinePlot plot; - private static Map dataSetMap; //main debug menu private static ImGuiWindow mainDebugWindow; + + //Framerate graph + private static ImGuiWindow globalFrametimeWindow; + private static ImGuiLinePlot globalFrametimePlot; + private static Map globalFrametimeDatasets; + + //server sim time graph + private static ImGuiWindow serverFrametimeWindow; + private static ImGuiBarPlot serverFrametimePlot; + /** * Initializes imgui windows */ public static void initImGuiWindows(){ createMainDebugMenu(); createFramerateGraph(); + createServerFrametimeGraph(); } /** * Creates a framerate graph */ private static void createFramerateGraph(){ - framerateWindow = new ImGuiWindow("Frametime Graph"); - plot = new ImGuiLinePlot("Frametime plot"); - dataSetMap = new HashMap(); + globalFrametimeWindow = new ImGuiWindow("Frametime Graph"); + globalFrametimePlot = new ImGuiLinePlot("Frametime plot"); + globalFrametimeDatasets = new HashMap(); initFramerateGraphSeries("totalframerate"); initFramerateGraphSeries("serversim"); initFramerateGraphSeries("clientsim"); initFramerateGraphSeries("render"); - framerateWindow.addElement(plot); - framerateWindow.setCallback(new ImGuiWindowCallback() { + globalFrametimeWindow.addElement(globalFrametimePlot); + globalFrametimeWindow.setCallback(new ImGuiWindowCallback() { @Override public void exec() { if(ImGui.button("Close")){ - RenderingEngine.removeImGuiWindow(framerateWindow); + RenderingEngine.removeImGuiWindow(globalFrametimeWindow); } } }); @@ -55,13 +63,13 @@ public class ImGuiWindowMacros { * Inits a series for the framerate graph * @param seriesName The name of the series */ - public static void initFramerateGraphSeries(String seriesName){ + private static void initFramerateGraphSeries(String seriesName){ ImGuiLinePlotDataset dataSet = new ImGuiLinePlotDataset(seriesName, 50); - dataSetMap.put(seriesName,dataSet); + globalFrametimeDatasets.put(seriesName,dataSet); for(int x = 0; x < 50; x++){ dataSet.addPoint(x, 0); } - plot.addDataset(dataSet); + globalFrametimePlot.addDataset(dataSet); } /** @@ -69,12 +77,45 @@ public class ImGuiWindowMacros { * @param seriesName The name of the series to add a datapoint for * @param y the y coord */ - public static void addFramerateDatapoint(String seriesName, double y){ - if(dataSetMap != null && dataSetMap.containsKey(seriesName)){ - dataSetMap.get(seriesName).addPoint(y); + public static void addGlobalFramerateDatapoint(String seriesName, double y){ + if(globalFrametimeDatasets != null && globalFrametimeDatasets.containsKey(seriesName)){ + globalFrametimeDatasets.get(seriesName).addPoint(y); } } + /** + * Creates a server frametime breakdown graph + */ + private static void createServerFrametimeGraph(){ + serverFrametimeWindow = new ImGuiWindow("Server Frametime Graph"); + serverFrametimePlot = new ImGuiBarPlot("Server Frametime plot"); + serverFrametimeWindow.addElement(serverFrametimePlot); + serverFrametimeWindow.setCallback(new ImGuiWindowCallback() { + @Override + public void exec() { + if(ImGui.button("Close")){ + RenderingEngine.removeImGuiWindow(serverFrametimeWindow); + } + } + }); + } + + /** + * 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 + */ + public static void addToServerFrametimeValue(String valueName, double amountToAdd){ + serverFrametimePlot.addToDatapoint(valueName, amountToAdd); + } + + /** + * Clears the server frametime values so they can be re-filled + */ + public static void clearServerFrametime(){ + serverFrametimePlot.clearDatapoints(); + } + /** * Inits the main debug menu @@ -84,9 +125,13 @@ public class ImGuiWindowMacros { mainDebugWindow.callback = new ImGuiWindowCallback() { @Override public void exec() { - //show framerate graph + //show global framerate line graph if(ImGui.button("Show Overall Frametime")){ - RenderingEngine.addImGuiWindow(framerateWindow); + RenderingEngine.addImGuiWindow(globalFrametimeWindow); + } + //show server frametime bar graph + if(ImGui.button("Show Server Frametime Breakdown")){ + RenderingEngine.addImGuiWindow(serverFrametimeWindow); } //close button if(ImGui.button("Close")){