Hi monkeys,
I’ve got a big performance-problem with my new nifty-gui. I’ve been switching from my own old GUI to nifty, so i’m currently cutting dead flesh a lot and trying to fit it to nifty. That process is going really well, but now i ran into this issue.
The game was at 60 fps (vsync enabled) with my old GUI and now i’ve about 30-35 fps ingame with nearly the same displaying via nifty.
Only bottom right is GUI:
http://imgur.com/avvdH
Here with the stats-layer if TAB is hold:
http://imgur.com/czSNc
The stats displayed in the stats-layer are updated once per second! Here the xml for the singleplayer-screen and the styles used:
[xml]
<?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”>
<!-- GAME STATS CONTROL -->
<controlDefinition name=“player-stats-line”>
<panel childLayout=“horizontal” width=“100%” height=“47px”
align=“center” padding=“3px”>
<!-- STATS_PLAYER_NAME_TEXT -->
<panel childLayout=“center” width=“25%” visibleToMouse=“false”>
<text id="#stats-player-name-text"
font=“Interface/Fonts/SolarWarsStats.fnt”
color="#ffff" text="" align=“center”>
</text>
</panel>
<!-- STATS_PLAYER_SHIPS_TEXT -->
<panel childLayout=“center” width=“15%” visibleToMouse=“false”>
<text id="#stats-player-ships-text"
font=“Interface/Fonts/SolarWarsStats.fnt”
color="#ffff" text="" align=“center”
valign=“top” width=“100%”>
</text>
</panel>
<!-- STATS_PLAYER_PLANET_TEXT -->
<panel childLayout=“center” width=“15%” visibleToMouse=“false”>
<text id="#stats-player-planet-text"
font=“Interface/Fonts/SolarWarsStats.fnt”
color="#ffff" text="" align=“center”
valign=“top” width=“100%”>
</text>
</panel>
<!-- STATS_PLAYER_SHIPSPERSEC_TEXT -->
<panel childLayout=“center” width=“15%” visibleToMouse=“false”>
<text id="#stats-player-shipspersec-text"
font=“Interface/Fonts/SolarWarsStats.fnt”
color="#ffff" text="" align=“center”
valign=“top” width=“100%”>
</text>
</panel>
<!-- STATS_PLAYER_COLOR_PANEL -->
<panel childLayout=“vertical” width=“15%” visibleToMouse=“false”>
<panel id="#stats-player-color-panel" height=“24px”
width=“24px” align=“center” valign=“bottom” backgroundColor="#0000"/>
</panel>
<!-- STATS_PLAYER_POWER_TEXT -->
<panel childLayout=“center” width=“15%” visibleToMouse=“false”>
<text id="#stats-player-power-text"
font=“Interface/Fonts/SolarWarsStats.fnt”
color="#ffff" text="" align=“center”
valign=“top” width=“100%”>
</text>
</panel>
</panel>
</controlDefinition>
<!-- GAME STATS WINDOW STYLE -->
<style id=“game-stats-style”>
<attributes width=“100%” height="*" padding=“10px”
backgroundColor="#0000" childLayout=“center” />
</style>
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- singleplayer screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<screen id=“singleplayer” controller=“com.solarwars.gamestates.SingleplayerState”>
<layer id=“none” backgroundColor="#0000" childLayout=“center” >
</layer>
<layer id=“stats” backgroundColor="#0000" childLayout=“center” >
<effect>
<onShow name=“move” length=“200” mode=“in”
direction=“left” startDelay=“0” inherit=“true”/>
<onHide name=“move” length=“200” mode=“out”
direction=“left” startDelay=“0” inherit=“true”/>
</effect>
<panel id=“game_stats_panel_frame” childLayout=“vertical”
align=“left” backgroundColor="#00f8" width=“60%”
height=“60%” padding=“5px”>
<panel id=“game_stats_heading” height=“15%” childLayout=“horizontal”>
<panel id=“player_icon_align” width=“25%” childLayout=“center”>
<image id=“player_icon”
filename=“Interface/ScoreIcons/player_icon.png”
filter=“false” align=“center”/>
</panel>
<panel id=“ship_icon_align” width=“15%” childLayout=“center”>
<image id=“ship_icon”
filename=“Interface/ScoreIcons/ship_icon.png” filter=“false”/>
</panel>
<panel id=“planet_icon_align” width=“15%” childLayout=“center”>
<image id=“planet_icon”
filename=“Interface/ScoreIcons/planet_icon.png” filter=“false”/>
</panel>
<panel id=“gain_icon_align” width=“15%” childLayout=“center”>
<image id=“gain_icon”
filename=“Interface/ScoreIcons/gain_icon.png” filter=“false”/>
</panel>
<panel id=“color_icon_align” width=“15%” childLayout=“center”>
<image id=“color_icon”
filename=“Interface/ScoreIcons/color_icon.png” filter=“false”/>
</panel>
<panel id=“power_icon_align” width=“15%” childLayout=“center”>
<image id=“power_icon”
filename=“Interface/ScoreIcons/power_icon.png” filter=“false”/>
</panel>
</panel>
<panel id=“spacer” height=“5px” backgroundColor="#fff8"/>
<panel id=“game_stats_box_panel” childLayout=“horizontal”>
<control id=“game_stats_box” style=“game-stats-style”
name=“listBox” horizontal=“off” displayItems=“8” height=“80%”
selectionMode=“Disabled” forceSelection=“false” vertical=“optional”
viewConverterClass=“com.solarwars.gamestates.gui.PlayerStatsItemConverter”>
<control name=“player-stats-line”/>
</control>
</panel>
</panel>
</layer>
<layer id=“hud” backgroundColor="#0000" childLayout=“center”>
<panel id=“percentage_panel_frame” height=“7%” width=“10%” align=“right” valign=“bottom”
backgroundColor="#fff8" childLayout=“center” visibleToMouse=“false”>
<panel id=“percentage_panel” height=“95%” width=“98%” align=“right” valign=“bottom”
backgroundColor="#00f8" childLayout=“center” visibleToMouse=“false”>
<text id=“percentage” font=“Interface/Fonts/SolarWarsFont64.fnt”
color="#f88f" text="${CALL.refreshPercentage()}%" align=“center” valign=“center”>
<effect>
<onActive name=“textSize” startSize=“0.3” endSize=“0.3” oneShot=“true”/>
</effect>
</text>
</panel>
</panel>
</layer>
</screen>
</nifty>
[/xml]
Here my controller class SingleplayerState.java
[java]
public class SingleplayerState extends Gamestate {
//==========================================================================
//=== Private Fields
//==========================================================================
private Level currentLevel;
private Hub hub;
private PausePopupController pauseListener;
private Element statsLayer;
private GameStatsModule gameStatsModule;
//==========================================================================
//=== Methods & Constructor
//==========================================================================
/**
- Instantiates a new singleplayer state.
*
-
@param game the game
*/
public SingleplayerState() {
super(SolarWarsGame.SINGLEPLAYER_STATE);
hub = Hub.getInstance();
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
// create pause listener
pauseListener = new PausePopupController(niftyGUI);
}
@Override
protected void loadContent() {
// switch to singleplayer gui
niftyGUI.gotoScreen("singleplayer");
// setup game for singleplayer
setupSingleplayer();
// attach iso control
application.attachIsoCameraControl();
// Create Level and setup gameplay
currentLevel = new Level(
application.getRootNode(),
application.getAssetManager(),
application.getIsoControl(),
Hub.playersByID);
game.setupGameplay(new DeathmatchGameplay(), currentLevel);
currentLevel.generateLevel(System.currentTimeMillis());
// setup nifty properly
setupNiftyGUI();
// play startup sound
AudioManager.getInstance().
playSoundInstance(AudioManager.SOUND_LOAD);
}
/**
- Setup gui.
*/
private void setupNiftyGUI() {
pauseListener.hidePopup();
// attach listener for pause layer
application.getInputManager().addListener(
pauseListener,
InputMappings.PAUSE_GAME);
statsLayer = niftyGUI.getCurrentScreen().
findElementByName("stats");
gameStatsModule = new GameStatsModule(
statsLayer,
niftyGUI.getCurrentScreen().
findNiftyControl("game_stats_box_panel",
ListBox.class), currentLevel);
gameStatsModule.addPlayers(Hub.getPlayers());
// creates the drag-rect geometry
// IsoControl.getInstance().createDragRectGeometry();
}
@Override
protected void unloadContent() {
//pause gui
gameStatsModule.destroy();
application.getInputManager().removeListener(pauseListener);
//level
currentLevel.destroy();
//3d controls
application.detachIsoCameraControl();
}
@Override
public void update(float tpf) {
if (isEnabled()) {
currentLevel.updateLevel(tpf);
updateNifty(tpf);
}
}
private void updateNifty(float tpf) {
// find old text
Element niftyElement = niftyGUI.getCurrentScreen().
findElementByName("percentage");
// swap old with new text
niftyElement.getRenderer(TextRenderer.class).
setText(refreshPercentage() + "%");
gameStatsModule.update(tpf);
}
/**
- Setup singleplayer.
*/
private void setupSingleplayer() {
Player local = new Player(“Human”, ColorRGBA.Blue, ServerHub.getContiniousPlayerID(), true);
Player ai = new Player(“AI”, ColorRGBA.Red, ServerHub.getContiniousPlayerID());
hub.initialize(local, null);
hub.addPlayer(ai);
hub.addPlayer(local);
}
public int refreshPercentage() {
return (int) (Hub.getLocalPlayer().getShipPercentage() * 100);
}
public void continueGame() {
pauseListener.hidePopup();
}
public void quitGame() {
switchToState(SolarWarsGame.MAINMENU_STATE);
}
}
[/java]
Please let me now if you need more code or anything else! I’ll post it asap. I could also deploy a web-start so anyone who wants to see it in real-time can do this
So my general question is: How to get back to my smooth 60 fps and stay with nifty!
I did some research here, but nothing suffers my desired solution:
http://hub.jmonkeyengine.org/groups/gui/forum/topic/performance-issue-with-complex-nifty-screen/?topic_page=1&num=15
→ Here was the solution, that all size attributes are absolute not relative. not an elegant way to solve it in my opinion but maybe worth to try.
→ also said: too much styles are an performance-killer. i only have one in this screen -.-
So, with my best regards 8O,
gormed