Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11996 Posts in 1588 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 11:34:09 am
Xith3D CommunityGeneral CategoryNews (Moderators: Marvin Fröhlich, 'n ddrylliog)HUD reimplementation
Pages: [1]
Print
Author Topic: HUD reimplementation  (Read 3469 times)
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« on: 22. May 2009, 11:52:57 pm »

Good things come to those who wait... I proudly present: The new HUD implementation.

It is faster, cleaner, more pixel perfect and way easier and more comfortable to use in some cases.

The HUD3DTest ran at 2000 FPS with the old code. Now it runs at 5000 FPS.
The NumberLabelTest ran at 1000 FPS in best case with the old code. Now it runs at 5500 FPS.

The main new thing is about lightweight and heavyweight widgets. All widgets are drawn on a texture. Heavyweight widgets have their own texture (context) and lightweight widgets draw on the texture of the next heavyweight (grant-)parent container. This saves a lot of texture state changes in OpenGL, which is the main source of the new rendering speed. Almost all Widget types are lightweight by default. And almost all Widgets take an optional boolean parameter as first parameter to the constructor to define, if it is to be born as lightweight or heavyweight widget.

The HUD's ContentPane is a heavyweight widget by default. This means, it is backed by a texture of canvas resolution size. This can be a bit of memory. If you know, that you will only use a certain area of the screen for the HUD, you can reduce this memory consumption by either passing a false to the HUD contructor to make it create a lightweight ContentPane or you can create a smaller ContentPane and pass it to the HUD constructor or override the createDefaultContentPane() method of the HUD class and create it in there.

If you're using a lightweight ContentPane, all widgets added to it must be heavyweight. So you could use a lightweight ContentPane and add a heavyweight Panel of a smaller size somewhere to it and add your widgets to it.

If you want to drag a Widget by setting it draggable and moving it with the mouse, you should make it heavyweight. Otherwise it will be slow.

The List widget and Combobox widget have taken the largest amount of API changes. The List widget is using a ListModel as a data container for arbitrary data and doesn't use one Widget for each item to render the data to the HUD. This saves a lot of memory, is much easier to handle and should even be faster. The Combobox uses a List and hence uses a ListModel, too.

ListModel is an abstract class. And there are a few default implementations in the xith codebase. The most important one will be the TextListModel. You need an instance of ListModel to create a List widget. But for simplicity you can use the static method List.newTextList() to create a List with a TextListModel. This replaces the old TextList class. There are similar methods for the Combobox widget (newTextCombo()).

All widgets can have a dropshadow now. You can simply activate it through the setHasDropShadow() method. Windows have a drop shadow by default. If you want to change the drop shadow rendering code, you can implement your own version of the DropShadowFactory and attach it to the HUD.

Labels can have an optional icon, which is drawn left of the text.

I have repainted some of the widget textures for the default theme. So many of them will look a little nicer.

No HUD element takes jawa.awt.Font instances anymore. Everything is wrapped in HUDFont. You can get HUDFont instances through the HUDFont.getFont() method. This is used to let the font scale with the HUD resolution. This way texts will take the same percentual space on the HUD on different canvas resolutions, if a custom HUD resolution is defined. This scaling can be disabled (switch to the old behavior) by setting the HUDFont.setUseFontScaling() to false.

All widget background textures (BackgroundSettableWidgets) and the textures of Image widgets can be either stretched (default for images) or tiled (TILE_BOTH is default for background images). You should be careful with streched images and especially backgrounds, since they need to be drawn using AWT Graphics2D, which is awfully slow on DirectBufferedImages atm. Use tiling instead whereever you can.

IIRC these were the most important points of the new code.

Enjoy and please report any bugs.

Marvin
« Last Edit: 23. May 2009, 12:22:16 am by Marvin Fröhlich » Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #1 on: 23. May 2009, 08:24:08 pm »

FANTASTIC!!!!   I will update and use very soon ( I am in a fragile part of my game dev at the moment)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic