@Override public void postRender() { if (time > REFRESH_TIME) { prof.appStep(AppStep.EndFrame); Map<String, DetailedProfiler.StatLine> data = prof.getStats(); displayData(data); time = 0; } }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals(TOGGLE_KEY) && isPressed) { setEnabled(!isEnabled()); } if (isEnabled() && name.equals(CLICK_KEY) && isPressed) { handleClick(getApplication().getInputManager().getCursorPosition()); } } }
private StatLineView getStatLineView(String path) { StatLineView line = lines.get(path); if (line == null) { line = new StatLineView(getLeaf(path)); lines.put(path, line); line.attachTo(ui); } return line; }
private void layout() { height = 0; selectedValueCpu = 0; selectedValueGpu = 0; rootLine.layout(0); frameTimeValue.setText(df.format(getMsFromNs(prof.getAverageFrameTime())) + "ms"); frameTimeValue.setLocalTranslation(PANEL_WIDTH / 2, -PADDING, 0); setColor(frameTimeValue, prof.getAverageFrameTime(), totalTimeCpu, false, false); frameCpuTimeValue.setText(df.format(getMsFromNs(totalTimeCpu)) + "ms"); frameCpuTimeValue.setLocalTranslation(new Vector3f(PANEL_WIDTH / 4 - bigFont.getLineWidth(frameCpuTimeValue.getText()) / 2, -PADDING - 50, 0)); setColor(frameCpuTimeValue, totalTimeCpu, totalTimeCpu, false, false); frameGpuTimeValue.setText(df.format(getMsFromNs(totalTimeGpu)) + "ms"); frameGpuTimeValue.setLocalTranslation(new Vector3f(3 * PANEL_WIDTH / 4 - bigFont.getLineWidth(frameGpuTimeValue.getText()) / 2, -PADDING - 50, 0)); setColor(frameGpuTimeValue, totalTimeGpu, totalTimeGpu, false, false); selectedField.setText("Selected: " + df.format(getMsFromNs(selectedValueCpu)) + "ms / " + df.format(getMsFromNs(selectedValueGpu)) + "ms"); selectedField.setLocalTranslation(3 * PANEL_WIDTH / 4 - font.getLineWidth(selectedField.getText()) / 2, -PADDING - 75, 0); }
StatLineView line = getStatLineView(path); DetailedProfiler.StatLine statLine = data.get(path); line.updateValues(statLine.getAverageCpu(), statLine.getAverageGpu()); String parent = getParent(path); while (parent != null) { StatLineView parentView = getStatLineView(parent); parentView.updateValues(statLine.getAverageCpu(), statLine.getAverageGpu()); parentView.children.add(line); line.attachTo(ui); line = parentView; parent = getParent(parent); totalTimeGpu = rootLine.gpuValue + data.get("EndFrame").getAverageGpu(); layout();
@Override protected void onEnable() { getApplication().setAppProfiler(prof); ((SimpleApplication) getApplication()).getGuiNode().attachChild(ui); }
private void handleClick(Vector2f pos) { Vector3f lp = hideInsignificantField.getWorldTranslation(); float width = font.getLineWidth(hideInsignificantField.getText()); if (pos.x > lp.x && pos.x < (lp.x + width) && pos.y < lp.y && pos.y > lp.y - LINE_HEIGHT) { hideInsignificant = !hideInsignificant; hideInsignificantField.setText((hideInsignificant ? "X " : "O ") + INSIGNIFICANT); if (!hideInsignificant) { rootLine.setExpended(true); } } rootLine.onClick(pos); for (StatLineView statLineView : lines.values()) { statLineView.onClick(pos); } layout(); }
public void layout(int indent) { boolean insignificant; cpuText.setText(df.format(getMsFromNs(cpuValue)) + "ms /"); insignificant = setColor(cpuText, cpuValue, totalTimeCpu, !children.isEmpty(), expended); gpuText.setText(" " + df.format(getMsFromNs(gpuValue)) + "ms"); insignificant &= setColor(gpuText, gpuValue, totalTimeGpu, !children.isEmpty(), expended); if (insignificant && hideInsignificant) { setVisible(false); } if (!visible) { return; } if (selected) { label.setColor(ColorRGBA.Yellow); selectedValueCpu += cpuValue; selectedValueGpu += gpuValue; } else { label.setColor(ColorRGBA.White); } int y = -(height * LINE_HEIGHT + HEADER_HEIGHT); label.setLocalTranslation(PADDING + indent * PADDING, y, 0); float gpuPos = PANEL_WIDTH - font.getLineWidth(gpuText.getText()) - PADDING * (maxLevel - indent + 1); cpuText.setLocalTranslation(gpuPos - font.getLineWidth(cpuText.getText()), y, 0); gpuText.setLocalTranslation(gpuPos, y, 0); checkBox.setLocalTranslation(3, y, 0); height++; for (StatLineView child : children) { child.layout(indent + 1); } }
StatLineView line = getStatLineView(path); DetailedProfiler.StatLine statLine = data.get(path); line.updateValues(statLine.getAverageCpu(), statLine.getAverageGpu()); String parent = getParent(path); while (parent != null) { StatLineView parentView = getStatLineView(parent); parentView.updateValues(statLine.getAverageCpu(), statLine.getAverageGpu()); parentView.children.add(line); line.attachTo(ui); line = parentView; parent = getParent(parent); totalTimeGpu = rootLine.gpuValue + data.get("EndFrame").getAverageGpu(); layout();
private void layout() { height = 0; selectedValueCpu = 0; selectedValueGpu = 0; rootLine.layout(0); frameTimeValue.setText(df.format(getMsFromNs(prof.getAverageFrameTime())) + "ms"); frameTimeValue.setLocalTranslation(PANEL_WIDTH / 2, -PADDING, 0); setColor(frameTimeValue, prof.getAverageFrameTime(), totalTimeCpu, false, false); frameCpuTimeValue.setText(df.format(getMsFromNs(totalTimeCpu)) + "ms"); frameCpuTimeValue.setLocalTranslation(new Vector3f(PANEL_WIDTH / 4 - bigFont.getLineWidth(frameCpuTimeValue.getText()) / 2, -PADDING - 50, 0)); setColor(frameCpuTimeValue, totalTimeCpu, totalTimeCpu, false, false); frameGpuTimeValue.setText(df.format(getMsFromNs(totalTimeGpu)) + "ms"); frameGpuTimeValue.setLocalTranslation(new Vector3f(3 * PANEL_WIDTH / 4 - bigFont.getLineWidth(frameGpuTimeValue.getText()) / 2, -PADDING - 50, 0)); setColor(frameGpuTimeValue, totalTimeGpu, totalTimeGpu, false, false); selectedField.setText("Selected: " + df.format(getMsFromNs(selectedValueCpu)) + "ms / " + df.format(getMsFromNs(selectedValueGpu)) + "ms"); selectedField.setLocalTranslation(3 * PANEL_WIDTH / 4 - font.getLineWidth(selectedField.getText()) / 2, -PADDING - 75, 0); }
@Override protected void onDisable() { getApplication().setAppProfiler(null); ui.removeFromParent(); }
private void handleClick(Vector2f pos) { Vector3f lp = hideInsignificantField.getWorldTranslation(); float width = font.getLineWidth(hideInsignificantField.getText()); if (pos.x > lp.x && pos.x < (lp.x + width) && pos.y < lp.y && pos.y > lp.y - LINE_HEIGHT) { hideInsignificant = !hideInsignificant; hideInsignificantField.setText((hideInsignificant ? "X " : "O ") + INSIGNIFICANT); if (!hideInsignificant) { rootLine.setExpended(true); } } rootLine.onClick(pos); for (StatLineView statLineView : lines.values()) { statLineView.onClick(pos); } layout(); }
public void layout(int indent) { boolean insignificant; cpuText.setText(df.format(getMsFromNs(cpuValue)) + "ms /"); insignificant = setColor(cpuText, cpuValue, totalTimeCpu, !children.isEmpty(), expended); gpuText.setText(" " + df.format(getMsFromNs(gpuValue)) + "ms"); insignificant &= setColor(gpuText, gpuValue, totalTimeGpu, !children.isEmpty(), expended); if (insignificant && hideInsignificant) { setVisible(false); } if (!visible) { return; } if (selected) { label.setColor(ColorRGBA.Yellow); selectedValueCpu += cpuValue; selectedValueGpu += gpuValue; } else { label.setColor(ColorRGBA.White); } int y = -(height * LINE_HEIGHT + HEADER_HEIGHT); label.setLocalTranslation(PADDING + indent * PADDING, y, 0); float gpuPos = PANEL_WIDTH - font.getLineWidth(gpuText.getText()) - PADDING * (maxLevel - indent + 1); cpuText.setLocalTranslation(gpuPos - font.getLineWidth(cpuText.getText()), y, 0); gpuText.setLocalTranslation(gpuPos, y, 0); checkBox.setLocalTranslation(3, y, 0); height++; for (StatLineView child : children) { child.layout(indent + 1); } }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals(TOGGLE_KEY) && isPressed) { setEnabled(!isEnabled()); } if (isEnabled() && name.equals(CLICK_KEY) && isPressed) { handleClick(getApplication().getInputManager().getCursorPosition()); } } }
@Override protected void cleanup(Application app) { ui.detachAllChildren(); InputManager manager = getApplication().getInputManager(); manager.deleteMapping(TOGGLE_KEY); manager.deleteMapping(CLICK_KEY); manager.removeListener(inputListener); }
private StatLineView getStatLineView(String path) { StatLineView line = lines.get(path); if (line == null) { line = new StatLineView(getLeaf(path)); lines.put(path, line); line.attachTo(ui); } return line; }
@Override public void postRender() { if (time > REFRESH_TIME) { prof.appStep(AppStep.EndFrame); Map<String, DetailedProfiler.StatLine> data = prof.getStats(); displayData(data); time = 0; } }
@Override protected void onEnable() { getApplication().setAppProfiler(prof); ((SimpleApplication) getApplication()).getGuiNode().attachChild(ui); }
@Override protected void onDisable() { getApplication().setAppProfiler(null); ui.removeFromParent(); }
@Override protected void cleanup(Application app) { ui.detachAllChildren(); InputManager manager = getApplication().getInputManager(); manager.deleteMapping(TOGGLE_KEY); manager.deleteMapping(CLICK_KEY); manager.removeListener(inputListener); }