Hi Folks,
I started with the ingame gui of my project, everything is in place and working. But i get a framerate drop from 70 fps to 13 fps with the gui active.
Is it me or is there a problem with the Nifty, or my XML-layout?
The following is a testcase for the problem with a blank screen and a screen which is like mine.
The program does nothing special but change between two screens.
On gui screen i get something like 250 - 300 fps
On blank screen I get nearly 4000 fps.
gui.xml
[java]
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="clearScreen">
<layer>
</layer>
</screen>
<screen id="mainGame" controller="de.myrdragor.controller.nifty.screencontroller.MainGame">
<layer id="layUnitFrame" childLayout="vertical">
<panel id = "pnlMainFrame" height="80px" width = "640px" align="left" valign="top" childLayout="horizontal">
<panel width="256px" childLayout="vertical">
<panel id = "pnlPlayerCharFrame" height="64px" width = "256px" childLayout="horizontal">
<panel width="64px" height="64px" style="nifty-panel-no-shadow" childLayout="center" padding="5px">
<panel id="imgCharHead" style="nifty-panel-red-no-shadow" width="100%" height="100%" valign="center" align="center"/>
</panel>
<panel width="" height="100%" childLayout="vertical">
<panel width="100%" height="20px" style="nifty-panel-no-shadow" childLayout="center" padding="5px">
<control name="label" text="Name"/>
</panel>
<panel width="100%" height="" style="nifty-panel-no-shadow" childLayout="horizontal" padding="5px">
<panel childLayout="vertical" width="75%" height="100%">
<panel id="barPlayerHealth" backgroundColor="#ffff"/>
<panel id="barPlayerMana" backgroundColor="#f00f"/>
<panel id="barPlayerKarma" backgroundColor="#0f0f"/>
<panel id="barPlayerEnergy" backgroundColor="#00ff"/>
</panel>
<panel childLayout="vertical" width="" height="100%">
<control id="lblPlayerHealth" width="100%" height="" name="label" text="100%" />
<control id="lblPlayerMana" width="100%" height="" name="label" text="100%" />
<control id="lblPlayerKarma" width="100%" height="" name="label" text="100%" />
<control id="lblPlayerEnergy" width="100%" height="" name="label" text="100%" />
</panel>
</panel>
</panel>
</panel>
<panel height="" childLayout="vertical">
<panel id="barPlayerCast" visible="false"/>
</panel>
</panel>
<panel width="2px"/>
<panel id = "pnlTargetCharFrame" height="80px" width="256px" childLayout="vertical">
<panel width="100%" height="64px" childLayout = "horizontal">
<panel width="" height="64px" childLayout="vertical">
<panel width="100%" height="20px" style="nifty-panel-no-shadow" childLayout="horizontal" padding="5px">
<control name="label" id="lblTargetName" text="Target" color="000f" width="100%" align="center" style="base-font"/>
</panel>
<panel width="100%" height="" style="nifty-panel-no-shadow" childLayout="horizontal" padding="5px">
<panel childLayout="vertical" width="75%" height="100%">
<panel id="barTargetHealth" name="StatusBar" backgroundColor="#ffff"/>
<panel id="barTargetMana" name="StatusBar" backgroundColor="#f00f"/>
<panel id="barTargetKarma" name="StatusBar" backgroundColor="#0f0f"/>
<panel id="barTargetEnergy" name="StatusBar" backgroundColor="#00ff"/>
</panel>
<panel childLayout="vertical" width="" height="100%">
<control id="lblTargetHealth" width="100%" height="" name="label" text="100%" />
<control id="lblTargetMana" width="100%" height="" name="label" text="100%" />
<control id="lblTargetKarma" width="100%" height="" name="label" text="100%" />
<control id="lblTargetEnergy" width="100%" height="" name="label" text="100%" />
</panel>
</panel>
</panel>
<panel width="64px" height="64px" style="nifty-panel-no-shadow" childLayout="center" padding="5px">
<panel id="imgTargetHead" style="nifty-panel-red-no-shadow" width="100%" height="100%" valign="center" align="center"/>
</panel>
</panel>
<panel height="" childLayout="vertical">
<panel id="barTargetCast" visible="false"/>
</panel>
</panel>
<panel width="2px"/>
<panel id = "pnlTargetOfTargetCharFrame" width="128px" height="64px" childLayout="vertical">
<panel width="100%" height = "50%" childLayout="vertical">
<panel width="100%" height="20px" style="nifty-panel-no-shadow" childLayout="horizontal" padding="5px">
<control name="label" id="lblTargetOfTargetName" text="Target" color="000f" width="100%" align="center" style="base-font"/>
</panel>
<panel width="100%" height="" style="nifty-panel-no-shadow" childLayout="vertical" padding="5px">
<panel id="barTargetOfTargetHealth" backgroundColor="#f00f" />
</panel>
</panel>
<panel height="10px" childLayout="vertical">
<control id="barTargetOfTargetCast" name="StatusBar" visible="false"/>
</panel>
</panel>
<panel width=""/>
</panel>
</layer>
<layer id="Chat" childLayout="vertical">
<panel height=""/>
<panel id="pnlChatButtons" height="20px" width="300px" align="left" valign="bottom" childLayout="horizontal">
<panel width=""/>
<control id="ChatButtonSetting" name="button" width="20px" height="20px" label="A" backgroundcolor="#bbb" focusable="false">
</control>
<panel width="1%"/>
<control id="ChatButtonGuild" name="button" width="20px" height="20px" label="G" backgroundcolor="#bbb" focusable="false">
</control>
<panel width="1%"/>
<control id="ChatButtonOfficer" name="button" width="20px" height="20px" label="O" backgroundcolor="#bbb" focusable="false">
</control>
<panel width="1%"/>
<control id="ChatButtonParty" name="button" width="20px" height="20px" label="P" backgroundcolor="#bbb" focusable="false">
</control>
<panel width="1%"/>
<control id="ChatButtonReligion" name="button" width="20px" height="20px" label="R" backgroundcolor="#bbb" focusable="false">
</control>
<panel width="1%"/>
<control id="ChatButtonTown" name="button" width="20px" height="20px" label="T" backgroundcolor="#bbb" focusable="false">
</control>
<panel width=""/>
</panel>
<panel id="pnlChat" height="120px" width="300px" align="left" valign="bottom" childLayout="vertical" backgroundColor="#000a">
<control id="txtChat" name="textfield" width = "100%" height="23px" />
<control id="lbxChat" name="listBox" width = "100%" vertical="optional" horizontal="off" displayItems="6" selectionMode="Disabled">
<text text="Template" backgroundColor="#0000" style="nifty-console-listbox-item" controller="de.lessvoid.nifty.controls.listbox.ListBoxItemController"/>
</control>
</panel>
</layer>
<layer id="Minimap" childLayout="center">
<panel id="minimap" height="150px" width="150px" align="right" valign="top" childLayout="vertical">
<panel width="150px" height="150px" style="nifty-panel-no-shadow" childLayout="center" padding="5px">
<panel id="imgMinimap" width="100%" height="100%" style="nifty-panel-red-no-shadow" childLayout="absolute">
</panel>
</panel>
</panel>
</layer>
<layer id="UIBars" childLayout="center">
<panel childLayout="horizontal" width="100%" height="100px" align="right" valign="bottom">
<panel width=""/>
<panel childLayout="vertical">
<panel height=""/>
<panel id="SkillBar" align="right" width="400px" height="50px" backgroundColor="#555a" childLayout="horizontal" >
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton1" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB1Binding" name="label" width="20" height="20" x="30" y="30" text="1" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton2" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB2Binding" name="label" width="20" height="20" x="30" y="30" text="2" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton3" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB3Binding" name="label" width="20" height="20" x="30" y="30" text="3" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton4" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB4Binding" name="label" width="20" height="20" x="30" y="30" text="4" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton5" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB5Binding" name="label" width="20" height="20" x="30" y="30" text="5" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton6" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB6Binding" name="label" width="20" height="20" x="30" y="30" text="6" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton7" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB7Binding" name="label" width="20" height="20" x="30" y="30" text="7" color="#bbbf" visibleToMouse="false"/>
</panel>
<panel width="50px" height="50px" childLayout="absolute">
<control id="dropSBButton8" name="droppable" width="50px" height="50px" x="0" y="0" align="center" valign="top">
<effect>
<onActive name="border" post="true" color="#222f" border="1px" />
</effect>
</control>
<control id="lblSBB8Binding" name="label" width="20" height="20" x="30" y="30" text="8" color="#bbbf" visibleToMouse="false"/>
</panel>
</panel>
<panel height=""/>
</panel>
<panel id="GUICustomizer" style="nifty-panel-no-shadow" width="100px" height="100px" backgroundcolor="#aaa" align="right" childLayout="vertical">
<control padding="0px" id="SkillBar1" name="button" width="20px" height="20px" label="1" backgroundcolor="#bbb" focusable="false">
</control>
<control padding="0px" id="SkillBar2" name="button" width="20px" height="20px" label="2" backgroundcolor="#bbb" focusable="false">
</control>
<control padding="0px" id="SkillBar3" name="button" width="20px" height="20px" label="3" backgroundcolor="#bbb" focusable="false">
</control>
<control padding="0px" id="SkillBar4" name="button" width="20px" height="20px" label="4" backgroundcolor="#bbb" focusable="false">
</control>
</panel>
</panel>
</layer>
</screen>
</nifty>
[/java]
Main.java
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.RenderManager;
import de.lessvoid.nifty.Nifty;
/**
- test
-
@author agares
*/
public class Main extends SimpleApplication implements ActionListener {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
private Nifty nifty;
@Override
public void simpleInitApp() {
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
nifty = niftyDisplay.getNifty();
guiViewPort.addProcessor(niftyDisplay);
ClearScreenController csc = new ClearScreenController();
MainGameController mgc = new MainGameController();
nifty.registerScreenController(csc,mgc);
nifty.fromXml("Interface/Gui.xml","mainGame");
initKeys();
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
private void initKeys() {
inputManager.addMapping("switchGuiState", new KeyTrigger(KeyInput.KEY_F1));
inputManager.addListener(this, "switchGuiState");
}
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed){
return;
}
if (name.equals("switchGuiState")){
if (nifty.getCurrentScreen().getScreenId().equals("clearScreen")){
nifty.gotoScreen("mainGame");
} else {
nifty.gotoScreen("clearScreen");
}
}
}
}
[/java]
Any ideas?
Edit: I use the JME3 nightly build