FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Responsive Form, Games
(Moderator: REAS)
   TileMapRenderer
« Previous topic | Next topic »

Pages: 1 2 
   Author  Topic: TileMapRenderer  (Read 4597 times)
Andre_Michelle

WWW
TileMapRenderer
« on: Aug 1st, 2004, 8:23pm »

hi,
 
 
i've coded a fast TileMap Renderer in processing.
Any suggestions are welcome. I don't see any further details to increase the performance.
 
I found one nice thing to have more speed:
Store references (even from the object itself) into local vars ( this gave me 200% boost). this is weird, cause its the same thing in Flash
 
 
http://www.andre-michelle.com/processing/tilemap/
« Last Edit: Aug 1st, 2004, 8:26pm by Andre_Michelle »  
flight404

WWW Email
Re: TileMapRenderer
« Reply #1 on: Aug 1st, 2004, 10:08pm »

Tease.
I want to play it.
 
r
 
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #2 on: Aug 1st, 2004, 10:55pm »

Before making a game with it, there are serious problems to solve. I don't know if this is a java issue, cause all frameevents are fired with Threads.
 
This affects some little dirty stopps while scrolling.
To much for me for playing...
 
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #3 on: Aug 2nd, 2004, 3:19am »

wow. whats that ?
 
http://www.andre-michelle.com/processing/test/tilemap/
 
I take now a Timer Object for instead of the given void loop() and its 250% faster and super smooth.
 
Its keycontrolled now (be sure having keyfocus).
mouseX, mouseY has no valid values in the method.
 
Thats pretty cool for games. Please post the fps(I have up to 370(!) on a 3Ghz WinXP).
« Last Edit: Aug 2nd, 2004, 3:23am by Andre_Michelle »  
arielm

WWW
Re: TileMapRenderer
« Reply #4 on: Aug 2nd, 2004, 3:41am »

hey, mario bros
 
on Aug 1st, 2004, 8:23pm, Andre_Michelle wrote:
i've coded a fast TileMap Renderer in processing.
Any suggestions are welcome. I don't see any further details to increase the performance.

1- why using a "buffer image" instead of blitting directly to the screen's pixels (123.5% increase in performance guaranteed)
 
2- in your blit-loop, you could take the cache-to-local-variables principle even further (95.3% increase in performance guaranteed):
 
(before) Code:
for( y = y0 ; y < y1 ; y++ )
{
  for( x = x0 ; x < x1 ; x++ )
  {
    //-- I LIKE THIS ROW :) --//
    mpx[i++ ] = bpx[(((m[y >> 4][x >> 4] << 4) + y % 16) << 4) + x % 16];
  }
}

(after) Code:
for( y = y0 ; y < y1 ; y++ )
{
  int[] M = m[y >> 4];
  int Y = y % 16;
  for( x = x0 ; x < x1 ; x++ )
  {
    //-- I PREFER THIS ONE --//
    mpx[i++ ] = bpx[(((M[x >> 4] << 4) + Y) << 4) + x % 16];
  }
}

 
on Aug 1st, 2004, 8:23pm, Andre_Michelle wrote:
I found one nice thing to have more speed:
Store references (even from the object itself) into local vars ( this gave me 200% boost). this is weird, cause its the same thing in Flash

yep, this is one is called java secret weapon #2
 
secret weapon #1 is called high-level optimization: for scrolling maps, there's a zillions of black-art technics, e.g.
 
right now, you're copying all the visible tiles at each frame which require for each tile a bunch of operations.
 
instead, you could copy this way only the edge's tiles, and move the main part of the image using a faster technic.
 
don't have anything more detailed offhand (but maybe toxi could enlight us on this very topic)
« Last Edit: Aug 2nd, 2004, 3:45am by arielm »  

Ariel Malka | www.chronotext.org
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #5 on: Aug 2nd, 2004, 11:32am »

thanks Ariel,
 
 
very nice tips. yes, copying and moving it all is the way I do in Flash, so why should it be slower in P5
 
 
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #6 on: Aug 2nd, 2004, 2:11pm »

Quote:

1- why using a "buffer image" instead of blitting directly to the screen's pixels? (123.5% increase in performance guaranteed)

 
Cause I want to implement more than 1 layer. Otherwise I cannot copy from the layer itself.
 
arielm

WWW
Re: TileMapRenderer
« Reply #7 on: Aug 2nd, 2004, 2:14pm »

on Aug 2nd, 2004, 3:19am, Andre_Michelle wrote:
Thats pretty cool for games. Please post the fps(I have up to 370(!) on a 3Ghz WinXP).

keep on the (high level optimization) efforts: with such a machine and such a small output window, you have no excuses not to reach 1000fps
 

Ariel Malka | www.chronotext.org
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #8 on: Aug 2nd, 2004, 2:24pm »

1000 frame. haha. its so curious, when coming from flash, where I'm happy to reach 30 fps in the final game
 
Another question about the copy-method.
 
After the first render process I have:
 
+------
+//////
+//////
+//////
+------
 
Image I move 1 pixel right and down:
 
+------
+////
+////
+  
+------
 
 
What is the fastest way to copy the rect I will see next frame ?
Perhaps a built-in method should faster that going through 2 loops to build the whole layer.
 
arielm

WWW
Re: TileMapRenderer
« Reply #9 on: Aug 2nd, 2004, 2:27pm »

on Aug 2nd, 2004, 2:11pm, Andre_Michelle wrote:
Cause I want to implement more than 1 layer. Otherwise I cannot copy from the layer itself.

if we're still in mario land, you don't need alpha-channel friendly layers (i.e. you need 1 bit good-old transparency, right), so...
 
you don't need a buffer image for that, instead:
 
1) blit your background-layer to the screen's pixel
 
2) for the 2nd layer (the one with on-off transparency): don't use any expansive operation that tries to blend with the underlying pixel, but: use the normal and fast way to copy tiles, except that this time you use an additional and simple "if" for each pixel, i.e.
 
for each transparent tile, you have an array of booleans (one boolean for each pixel) that states if the pixel have to be copied or not.
 
makes sense
 

Ariel Malka | www.chronotext.org
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #10 on: Aug 2nd, 2004, 2:28pm »

Oh, I see now, that I cannot simply copy the image, cause in the next step I want to implement animated blocks. So I cannot see how to reach 1000 fps, arielm. I have to compute and draw the whole screen.
 
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #11 on: Aug 2nd, 2004, 2:54pm »

Quote:
for each transparent tile, you have an array of booleans (one boolean for each pixel) that states if the pixel have to be copied or not.

 
This is what I can do now with the pixels Array from the screen. Where to get the mask ? No performance issue to render the whole mask on Start ?
Code:

for( y...y++ )
for( x...x++ )
if(mask[y][x])take last calc pixel(copy)
endloops
 
And than fill the new Area.

 
This is great arielm. There is always something more to perform.
 
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #12 on: Aug 2nd, 2004, 5:10pm »

Its faster to compute the Pixels from the Tileset, than any copy function I found.
 
I can't find any method or algorithm, that can crop an image fast enough.
 
arielm

WWW
Re: TileMapRenderer
« Reply #13 on: Aug 2nd, 2004, 5:14pm »

grossly, i meant something like:
 
Code:
for( y = y0 ; y < y1 ; y++ )  
{  
  int[] M = m[y >> 4];  
  int Y = y % 16;  
  for( x = x0 ; x < x1 ; x++ )  
  {
    int index = (((M[x >> 4] << 4) + Y) << 4) + x % 16;
    if (mask[index])
    {
      mpx[i] = bpx[index];
    }
    i++;
  }  
}

of course, mask[] have to be pre-computed during setup(), which is absolutely not a problem (a matter of a few millis at most...)
 
 
on Aug 2nd, 2004, 2:54pm, Andre_Michelle wrote:
This is great arielm. There is always something more to perform.

yep, definitely... it's only a matter of how much time and patience you have to invest, and that's the reason i talked about 1000fps (k, let's say 500) (it may take a lot of efforts to achieve, but at the end: it means that you'll be able to have a much bigger screen, say, 640x480 that runs at 60fps...)
« Last Edit: Aug 2nd, 2004, 5:18pm by arielm »  

Ariel Malka | www.chronotext.org
Andre_Michelle

WWW
Re: TileMapRenderer
« Reply #14 on: Aug 2nd, 2004, 5:36pm »

http://www.andre-michelle.com/processing/test/tilemap/
 
480x320px - not bad
But sometime while moving you see it drawing. There are no gaps, but waves. Perhaps this could be eliminate by the copying of the last screen, but as I said, I don't find any methods, which crop my last frame and move it some pixels.
 
Pages: 1 2 

« Previous topic | Next topic »