Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  rendering tiles w/ static render method  (Read 2391 times)
0 Members and 1 Guest are viewing this topic.
Offline zyzz

Senior Newbie





« Posted 2012-06-06 22:34:54 »

I'm not sure how to go about rendering tiles "properly", if I were to create each tile as an individual object and call its render method -- the game's fps would drop dramatically (to about 20fps or so)

at line 76:
https://github.com/codecub/slicktest/blob/master/tribelife/src/Slick.java
(tile rendering method)

see Grass.java:
https://github.com/codecub/slicktest/blob/master/tribelife/src/Grass.java

so yeah: "Is there a better way to render tiles individually?"

I believe the problem lies in the fact that whenever I create an object out of a grass tile, calling "different rendering methods" (different objects w/ same render method, new instance) really slows down the rendering altogether

should I just create a static render method? how will it then take into account individual tile object data (x, y etc)?


(21x15, 27*27 tile size)

and yeah, I know slick2d contains a tilemap library (but still)
Offline davedes
« Reply #1 - Posted 2012-06-07 00:37:29 »

Haven't had a chance to look through the code, but these are the two common performance killers for tile maps:

  • Are you using an Image.draw call per tile? If so, try using Image.startUse/drawEmbedded/endUse instead. Performance should improve a lot. Image.draw exists as a convenience which does (more or less) the following:
1  
2  
3  
image.startUse();
image.drawEmbedded(...);
image.endUse();

To improve performance, I'd suggest using startUse/drawEmbedded/endUse as much as possible. It works on an a single texture (i.e. the backing OpenGL texture); so even if you're using multiple sub-images, scaled copies, etc. you will still be able to draw them all in the same "batch." In theory, your entire game could be rendered in the same startUse/endUse as long as it's all contained on the same sprite sheet. So your tile renderer might look more like this:
1  
2  
3  
4  
5  
grassSprite.startUse();
for (.. rows ..)
    for (.. columns ..)
        grassSprite.drawEmbedded( ... );
grassSprite.endUse();
    Just a note; if you want to render a different texture, or change the blend mode, or change the transform (translate/scale/etc), or what have you, you'll need to first "flush" it by calling endUse(), then change the state, then start again with startUse(). [/li]
  • Are your game tiles contained in a sprite sheet? If not, this can be another source of performance loss.

If you fix those you should be able to render thousands of tiles per frame with no performance loss!

More info here:
http://slick.cokeandcode.com/wiki/doku.php?id=performance_memory_tips

Offline zyzz

Senior Newbie





« Reply #2 - Posted 2012-06-07 01:54:13 »

thanks for the tips, but I tried using startUse(), drawEmbedded() and endUse() but I still get some fps drops

it's not so much that I'm receiving low fps at the moment with my current rendering technique but the fact that if I want to call multiple render methods for every tile as an "object" the fps will drop insanely
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-06-07 05:54:05 »

I took a browse through the code. Some other things which you should fix:
  • You only need to set the filter (linear or nearest) once. Ideally you should set it at image initialization. Setting it before you render every font glyph and tile can cause a significant drop in performance. NB: the filter only applies to the backing 'texture' of an image; so changing the filter of a sub-image will affect all other sub-images that point to the same backing texture.
  • SpriteSheet.getSubImage(int, int, int, int) creates a new image when called -- you should generally avoid using it per frame (it seems you're using it in your glyph class).
  • As suspected, your tile and font rendering relies on Image.draw -- use drawEmbedded instead.
Setting the filter each render and not using drawEmbedded seem to be the main culprits in your code. Try fixing those and report back with the new FPS. (Obviously it will drop significantly as soon as you start rendering some images.)

Have you read much about design patterns? You use some very weird standards that will make debugging your application a lot more difficult. Shocked

Offline zyzz

Senior Newbie





« Reply #4 - Posted 2012-06-07 11:38:56 »

thanks! I'll try to see what I can do and report back

(especially about the design patterns bit)
Offline zyzz

Senior Newbie





« Reply #5 - Posted 2012-06-09 23:49:01 »

changing the filter calls worked

(now I get max fps)

 Wink
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (84 views)
2014-12-05 12:39:02

SHC (94 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!