261 lines
10 KiB
Java
261 lines
10 KiB
Java
package electrosphere.menu.debug;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import org.ode4j.ode.DBody;
|
|
|
|
import electrosphere.audio.VirtualAudioSource;
|
|
import electrosphere.collision.PhysicsEntityUtils;
|
|
import electrosphere.engine.Globals;
|
|
import electrosphere.entity.Entity;
|
|
import electrosphere.entity.EntityUtils;
|
|
import electrosphere.entity.types.creature.CreatureUtils;
|
|
import electrosphere.renderer.RenderingEngine;
|
|
import electrosphere.renderer.ui.imgui.ImGuiLinePlot;
|
|
import electrosphere.renderer.ui.imgui.ImGuiWindow;
|
|
import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset;
|
|
import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback;
|
|
import electrosphere.server.datacell.utils.EntityLookupUtils;
|
|
import imgui.ImGui;
|
|
|
|
/**
|
|
* Various methods for creating specific imgui windows in engine
|
|
*/
|
|
public class ImGuiWindowMacros {
|
|
|
|
|
|
//main debug menu
|
|
private static ImGuiWindow mainDebugWindow;
|
|
|
|
|
|
//Framerate graph
|
|
private static ImGuiWindow globalFrametimeWindow;
|
|
private static ImGuiLinePlot globalFrametimePlot;
|
|
private static Map<String,ImGuiLinePlotDataset> globalFrametimeDatasets;
|
|
|
|
//audio debug menu
|
|
private static ImGuiWindow audioDebugMenu;
|
|
private static boolean showAllVirtualAudioChildren = false;
|
|
private static boolean showMappedVirtualAudioChildren = true;
|
|
|
|
//player entity details
|
|
private static ImGuiWindow playerEntityWindow;
|
|
|
|
//fluid details
|
|
private static ImGuiWindow fluidWindow;
|
|
|
|
/**
|
|
* Initializes imgui windows
|
|
*/
|
|
public static void initImGuiWindows(){
|
|
createMainDebugMenu();
|
|
createFramerateGraph();
|
|
createAudioDebugMenu();
|
|
createPlayerEntityDebugWindow();
|
|
createFluidDebugWindow();
|
|
ImGuiEntityMacros.createClientEntityWindows();
|
|
}
|
|
|
|
/**
|
|
* Creates a framerate graph
|
|
*/
|
|
private static void createFramerateGraph(){
|
|
globalFrametimeWindow = new ImGuiWindow("Frametime Graph");
|
|
globalFrametimePlot = new ImGuiLinePlot("Frametime plot");
|
|
globalFrametimeDatasets = new HashMap<String,ImGuiLinePlotDataset>();
|
|
initFramerateGraphSeries("totalframerate");
|
|
initFramerateGraphSeries("serversim");
|
|
initFramerateGraphSeries("clientsim");
|
|
initFramerateGraphSeries("render");
|
|
initFramerateGraphSeries("assetLoad");
|
|
initFramerateGraphSeries("clientNetwork");
|
|
initFramerateGraphSeries("controls");
|
|
globalFrametimeWindow.addElement(globalFrametimePlot);
|
|
globalFrametimeWindow.setOpen(false);
|
|
RenderingEngine.addImGuiWindow(globalFrametimeWindow);
|
|
}
|
|
|
|
/**
|
|
* Inits a series for the framerate graph
|
|
* @param seriesName The name of the series
|
|
*/
|
|
private static void initFramerateGraphSeries(String seriesName){
|
|
ImGuiLinePlotDataset dataSet = new ImGuiLinePlotDataset(seriesName, 50);
|
|
globalFrametimeDatasets.put(seriesName,dataSet);
|
|
for(int x = 0; x < 50; x++){
|
|
dataSet.addPoint(x, 0);
|
|
}
|
|
globalFrametimePlot.addDataset(dataSet);
|
|
}
|
|
|
|
/**
|
|
* Adds a datapoint to the framerate graph
|
|
* @param seriesName The name of the series to add a datapoint for
|
|
* @param y the y coord
|
|
*/
|
|
public static void addGlobalFramerateDatapoint(String seriesName, double y){
|
|
if(globalFrametimeDatasets != null && globalFrametimeDatasets.containsKey(seriesName)){
|
|
globalFrametimeDatasets.get(seriesName).addPoint(y);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create audio debug menu
|
|
*/
|
|
private static void createAudioDebugMenu(){
|
|
audioDebugMenu = new ImGuiWindow("Audio");
|
|
audioDebugMenu.setCallback(new ImGuiWindowCallback() {
|
|
@Override
|
|
public void exec() {
|
|
//audio engine details
|
|
ImGui.text("Audio Engine Details");
|
|
ImGui.text("Current audio device: " + Globals.audioEngine.getDevice());
|
|
ImGui.text("Default audio device: " + Globals.audioEngine.getDefaultDevice());
|
|
ImGui.text("Has HRTF: " + Globals.audioEngine.getHRTFStatus());
|
|
ImGui.text("Listener location: " + Globals.audioEngine.getListener().getPosition());
|
|
ImGui.text("Listener eye vector: " + Globals.audioEngine.getListener().getEyeVector());
|
|
ImGui.text("Listener up vector: " + Globals.audioEngine.getListener().getUpVector());
|
|
ImGui.text("Virtual Audio Source Manager Details");
|
|
ImGui.text("Total number active virtual sources: " + Globals.virtualAudioSourceManager.getSourceQueue().size());
|
|
//only active children
|
|
if(showMappedVirtualAudioChildren){
|
|
ImGui.beginChild("mapped virtual sources");
|
|
for(VirtualAudioSource source : Globals.virtualAudioSourceManager.getMappedSources()){
|
|
ImGui.text("Source " + source.getPriority());
|
|
ImGui.text(" - Position " + source.getPosition());
|
|
ImGui.text(" - Gain " + source.getGain());
|
|
ImGui.text(" - Type " + source.getType());
|
|
ImGui.text(" - Total time played " + source.getTotalTimePlayed());
|
|
ImGui.text(" - Buffer Lenth " + source.getBufferLength());
|
|
}
|
|
ImGui.endChild();
|
|
if(ImGui.button("Hide Mapped Virtual Children")){
|
|
showMappedVirtualAudioChildren = false;
|
|
}
|
|
} else {
|
|
if(ImGui.button("Show Mapped Virtual Children")){
|
|
showMappedVirtualAudioChildren = true;
|
|
}
|
|
}
|
|
//all virtual children
|
|
if(showAllVirtualAudioChildren){
|
|
ImGui.beginChild("all virtual sources");
|
|
for(VirtualAudioSource source : Globals.virtualAudioSourceManager.getSourceQueue()){
|
|
ImGui.text("Position " + source.getPosition());
|
|
}
|
|
ImGui.endChild();
|
|
if(ImGui.button("Hide All Virtual Children")){
|
|
showAllVirtualAudioChildren = false;
|
|
}
|
|
} else {
|
|
if(ImGui.button("Show All Virtual Children")){
|
|
showAllVirtualAudioChildren = true;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
audioDebugMenu.setOpen(false);
|
|
RenderingEngine.addImGuiWindow(audioDebugMenu);
|
|
}
|
|
|
|
|
|
/**
|
|
* Create player entity debug menu
|
|
*/
|
|
private static void createPlayerEntityDebugWindow(){
|
|
playerEntityWindow = new ImGuiWindow("Player Entity");
|
|
playerEntityWindow.setCallback(new ImGuiWindowCallback() {
|
|
@Override
|
|
public void exec() {
|
|
//player entity details
|
|
ImGui.text("Player Entity Details");
|
|
if(Globals.playerEntity != null){
|
|
ImGui.text("Position: " + EntityUtils.getPosition(Globals.playerEntity));
|
|
DBody body = PhysicsEntityUtils.getDBody(Globals.playerEntity);
|
|
if(body != null){
|
|
ImGui.text("Velocity: " + body.getLinearVel());
|
|
ImGui.text("Force: " + body.getForce());
|
|
ImGui.text("Angular Velocity: " + body.getAngularVel());
|
|
ImGui.text("Torque: " + body.getTorque());
|
|
ImGui.text("Move Vector: " + CreatureUtils.getFacingVector(Globals.playerEntity));
|
|
Entity serverEntity = EntityLookupUtils.getEntityById(Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()));
|
|
ImGui.text("Move Vector (Server): " + CreatureUtils.getFacingVector(serverEntity));
|
|
}
|
|
}
|
|
if(ImGui.button("Toggle Player Camera Lock")){
|
|
Globals.cameraHandler.setTrackPlayerEntity(!Globals.cameraHandler.getTrackPlayerEntity());
|
|
}
|
|
}
|
|
});
|
|
playerEntityWindow.setOpen(false);
|
|
RenderingEngine.addImGuiWindow(playerEntityWindow);
|
|
}
|
|
|
|
/**
|
|
* Create fluid debug menu
|
|
*/
|
|
private static void createFluidDebugWindow(){
|
|
fluidWindow = new ImGuiWindow("Fluids");
|
|
fluidWindow.setCallback(new ImGuiWindowCallback() {
|
|
@Override
|
|
public void exec() {
|
|
//audio engine details
|
|
ImGui.text("Fluids Debug");
|
|
if(ImGui.button("Toggle Simulation")){
|
|
Globals.serverFluidManager.setSimulate(!Globals.serverFluidManager.getSimulate());;
|
|
}
|
|
}
|
|
});
|
|
fluidWindow.setOpen(false);
|
|
RenderingEngine.addImGuiWindow(fluidWindow);
|
|
}
|
|
|
|
|
|
/**
|
|
* Inits the main debug menu
|
|
*/
|
|
private static void createMainDebugMenu(){
|
|
mainDebugWindow = new ImGuiWindow("Debug");
|
|
mainDebugWindow.setCallback(new ImGuiWindowCallback() {
|
|
@Override
|
|
public void exec() {
|
|
//show global framerate line graph
|
|
if(ImGui.button("Show Overall Frametime")){
|
|
globalFrametimeWindow.setOpen(true);
|
|
}
|
|
//show audio debug
|
|
if(ImGui.button("Show Audio Debug Menu")){
|
|
audioDebugMenu.setOpen(true);
|
|
}
|
|
//show audio debug
|
|
if(ImGui.button("Show Player Entity Debug Menu")){
|
|
playerEntityWindow.setOpen(true);
|
|
}
|
|
//show fluids debug
|
|
if(ImGui.button("Show Fluids Debug Menu")){
|
|
fluidWindow.setOpen(true);
|
|
}
|
|
//client entity debug
|
|
if(ImGui.button("Client Entity Debug")){
|
|
ImGuiEntityMacros.clientEntityWindow.setOpen(true);
|
|
}
|
|
//close button
|
|
if(ImGui.button("Close")){
|
|
mainDebugWindow.setOpen(false);
|
|
}
|
|
}
|
|
});
|
|
mainDebugWindow.setOpen(false);
|
|
RenderingEngine.addImGuiWindow(mainDebugWindow);
|
|
}
|
|
|
|
/**
|
|
* Toggles the open state of the menu
|
|
*/
|
|
public static void toggleMainDebugMenu(){
|
|
mainDebugWindow.setOpen(!mainDebugWindow.isOpen());
|
|
}
|
|
|
|
}
|