Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
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  
  How to render this the fastest way?  (Read 1034 times)
0 Members and 1 Guest are viewing this topic.
Offline gridur

Senior Newbie




Groovy


« Posted 2005-07-31 15:01:01 »

Hey all!

I have a little problem with rendering tiles for my map, it really slowes down the whole game very much, I noticed that using "rotate" really wasnt as cheap as i belived.

As it is now, i can run the game without rendering the tiles and get a nice fps at 50, but if i render the tiles it slowes down to about 20, with the rotation involved the game spins in on about 5-10 fps, well this just is'nt feasible so i really would need some rendering tips from some of you gurus on the forum =)

Here is the rendering function anyway, maybe you guys can spot something there and give me some pointers on how to make the whole thing faster..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
   public void drawMap(Graphics2D g, Map m, int indexX, int indexY, short[] tileWidth, short[] tileHeight)
   {
      int tempIndexX = indexX;
      boolean trans = false;
      AffineTransform original = g.getTransform();
     
      for(int i = tileHeight[0]; i < tileHeight[1]; i++)
      {
         for(int j = tileWidth[0]; j < tileWidth[1]; j++)
         {
            if(i >= 0 && j >= 0 && i < m.sizeY && j < m.sizeX)
            {
               if(m.MapTile[j][i].id == 0)
               {
                 
               }
               else
               {
                  switch(m.MapTile[j][i].transform)
                  {
                  case 0:
                     break;
                  case 1:
                     g.rotate(1.5707963267949d, indexX+24, indexY+24);
                     trans = true;
                     break;
                  case 2:
                     g.rotate(3.1415926535898d, indexX+24, indexY+24);
                     trans = true;
                     break;
                  case 3:
                     g.rotate(4.71238898038469d, indexX+24, indexY+24);
                     trans = true;
                     break;
                  }
                 
                  switch(m.MapTile[j][i].id )
                  {
                  case 1:
                     image = concrete1;
                     break;
                  case 2:
                     image = concrete2;
                     break;
                  case 3:
                     image = concrete2_c;
                     break;
                  case 4:
                     image = concrete2_cc;
                     break;
                  case 101:
                     image = wall1;
                     break;
                  case 102:
                     image = wall1_c;
                     break;
                  case 103:
                     image = wall1_cc;
                  case 201:
                     if(frame == 0)
                        image = dorr1f1;
                     else if(frame == 1)
                        image = dorr1f2;
                     else
                        image = dorr1f3;
                     break;
                  default:
                     image = concrete1;
                  break;
                  }
                 
                  g.drawImage(image, indexX, indexY, 48, 48, null);
                 
                  if(trans)
                     g.setTransform(original);
               }
            }
            indexX += 48;
         }
         indexY += 48;
         indexX = tempIndexX;
      }
   }


tnx

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #1 - Posted 2005-07-31 15:52:27 »

Your code rotates in increments of 90 degrees.  Therefore you could pre-rotate each tile in the initialisation & just use the appropriately rotated tile in the main loop.  That should get you back to 20fps.

If you assigned all the images adjacent numbers starting from zero, you could just index into an array of images to acquire the correct image, saving on the switch statements.  E.g. a 2D array  of image[20][4] would provide 20 images in each of the four rotations.  This probably won't gain a huge amount.

Speeding things up is always a problem.  Inspecting each line in the innermost loop & asking yourself does it really need to be there is a good start.

Alan

Time flies like a bird. Fruit flies like a banana.
Offline gridur

Senior Newbie




Groovy


« Reply #2 - Posted 2005-07-31 16:43:47 »

Yes, i think i will go with the "pre rendered" tiles, i really thought that i could work with transform now when i have accelerated graphics, but not hehe.
As a mather of fact, the game is much slower now than when i loaded my gfx with Toolkit/Image (now i use ImageIO/BufferedImage) so thats a little wierd, but i'll continuing working on optimisation hehe, when will i be able to accually work on the game? =P

Very well, thx for the tip, i'll start working on the init rotate stuff right away!

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gridur

Senior Newbie




Groovy


« Reply #3 - Posted 2005-07-31 18:46:48 »

Wow!

Finally figured out how to enable the OpenGL pipeline, and i thought that this already were enabled, but it was'nt.

Now the game spins at 40-50 fps with the AffineTransform operations =))))
Soooooo sweet to finaly see it all work out like it should! damn thats sweet, now i can finally sitt down and start programing a game again hehe...

Anyway, tnx for the help. Is there a way to permenantly enable OpenGL pipeline or do i always have to run the game with the -Dsun stuff? And if so, is there a way to configure Eclipse to run the game with OpenGL enabled?Huh

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline weston

Junior Devvie





« Reply #4 - Posted 2005-07-31 21:48:30 »

Thats odd that BufferedImage/ImageIO was slower... one thing you might consider is whether your images were larger than 256x256 (or any other dimensions with > 65536 pixels), it probably won't get accelerated if its this big. The other thing is that it doesn't matter if the image is accelerated if you rotate it (or scale it or draw it with translucency) because it loses its acceleration.

 I'm guessing you are using jdk 1.5 (or higher), so this may not be an issue but if you plan on making your game compatible for 1.4 users then you should know that just loading the image with ImageIO won't accelerate it. Instead you need to obtain a GraphicsConfiguration object and use its createCompatibleImage method to obtain a managed BufferedImage. From there you can draw your loaded image onto the managed image you created (Graphics2D g2 = myManagedImage.createGraphics()Wink. I'm sure you can find a more complete example by using the search feature on these forums if you need to.

I'm not sure its safe to rely on the opengl pipeline as of 1.5, but maybe someone else will say differently Smiley If you don't absolutely require the rotation of large (or a bunch of) images in real-time then java2d should be sufficient, but otherwise you might want to look into using an opengl binding (lwjgl/jogl).

In eclipse you can go to the run options->arguments tab and enter vm arguments.

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
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.

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

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

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

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

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

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

CopyableCougar4 (64 views)
2014-11-29 21:32:03

toopeicgaming1999 (126 views)
2014-11-26 15:22:04

toopeicgaming1999 (116 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
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!