🔒 Locked
Speeding up the render loop
Advertisement
Original Post
The way I have my engine now it checks every single tile to see if it lies in the viewport. If it does, it renders it. However this is extremely slow... On maps that grow in size > 256x256 tiles, it lags....
One way I''m thinking of speeding this up is finding the first tile that lies in the viewport, and start rendering from there. Is this the way to go, or is there a faster better way?
Other specifics:
D3D dx8 Ortho isometric tiles
(vertex buffer for each "type" of tile)
-Vulcan
you would rather want to "calculate" the first visible tile and go from there. I don''t know how your tiles look, but if they are flat then calculating which tiles are visible and which aren''t is pretty straightforward. Do some math!
With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/
With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/
okay, i had this problem with dx8 a little while ago. This is how i solved. The way i set it up is width the x and y axis, but not the z axis because i can get the effect with just the x and y. i have stored in a global, the world_x and world_y position as floats. This has to be done with a little trial and error, but calculate the x and y world position and use that to find out with tiles are on screen and mark them for rendering. Instead of looping through the whole map, i did some tests to see which tile would be seen at the current world position instead of a loop. basically, it converts from tile coorinents to worls coordinents and marks the ones that are in the world coordinent. Get it? I think i make stuff a little more confusing than it needs to be
finally i can give some advice.
render the tiles to an offscrren surface.
render it each time the user pan the screen (i.e. moves the map up, dowan,left,right)
by that you earn about 30fps. y?
calculate the amount of size of the transparant
pixels who arnt being blitted, but still passed upon.
it smting like quadruple of your final surface,
and ive noticed that the hardware blitter blit
larger surfaces faster.
Gil
render the tiles to an offscrren surface.
render it each time the user pan the screen (i.e. moves the map up, dowan,left,right)
by that you earn about 30fps. y?
calculate the amount of size of the transparant
pixels who arnt being blitted, but still passed upon.
it smting like quadruple of your final surface,
and ive noticed that the hardware blitter blit
larger surfaces faster.
Gil
kmsixspence is right, though doesnt give all the details.
I suggest some things:
ALWAYS perform a search on this forum BEFORE asking, as to save time and space on this site. So, do a search in this forum for "scrolling"
Next, go to gamedev articles, i believe there is an Isometric section. Look for scrolling. Hopefully, JIM ADAMS paper on scrolling is still around. It describes how to render on the viewable map area.
If you cant find the info, ILL email you the article, i saved some of the good ones when i was into iso stuff.
I suggest some things:
ALWAYS perform a search on this forum BEFORE asking, as to save time and space on this site. So, do a search in this forum for "scrolling"
Next, go to gamedev articles, i believe there is an Isometric section. Look for scrolling. Hopefully, JIM ADAMS paper on scrolling is still around. It describes how to render on the viewable map area.
If you cant find the info, ILL email you the article, i saved some of the good ones when i was into iso stuff.
Once i was doing this in 3d but it was very slow for that times, anyway i think this could be greatly used in a 2d/iso environment, first i divided the world into discrete boxes
thus doing a 3d hash , then i''ve calculated the position of the player with only 3 divisions , to get the array locations in to the 3d hash grid, and then i was performing a sort of 3d ray casting , you could do this in 2d but this will require to review from the beginning you engine, anyway is not that difficult , first find the bounding box of the entire level , then divide it into small boxes no recursion here , since it not a tree data structure, then calculate how many rays your level requires to be shot , depending the grid size, then for each ray calculate the intersection with the grid using a sort of Bhresenamn algorightm which is very fast for a 2d grid, you may find also interesting the ray casting methods around the net.
thus doing a 3d hash , then i''ve calculated the position of the player with only 3 divisions , to get the array locations in to the 3d hash grid, and then i was performing a sort of 3d ray casting , you could do this in 2d but this will require to review from the beginning you engine, anyway is not that difficult , first find the bounding box of the entire level , then divide it into small boxes no recursion here , since it not a tree data structure, then calculate how many rays your level requires to be shot , depending the grid size, then for each ray calculate the intersection with the grid using a sort of Bhresenamn algorightm which is very fast for a 2d grid, you may find also interesting the ray casting methods around the net.
quote:
Original post by GalaxyQuest
kmsixspence is right, though doesnt give all the details.
I suggest some things:
ALWAYS perform a search on this forum BEFORE asking, as to save time and space on this site. So, do a search in this forum for "scrolling"
Dude, not once in my post did I even mention scrolling, and yes, I have looked at all the tutorials, except for the fact that there are none for what I am trying to do (~sorta)
Here''s how I do it. Find out which tile is in the upper left, upper right, lower left, and lower right corners. Then only render the tiles between these.
This is even further simplified if you set the map up so that the upper left & lower right corner tiles (and upper right/lower right) have the same x position in the map.
This is even further simplified if you set the map up so that the upper left & lower right corner tiles (and upper right/lower right) have the same x position in the map.
[What they said]
AND:
If you want ppl to be able to smooth-scroll around your world instead of scrolling tile-by-tile, this is what i suggest:
Let them smooth scroll (x++, y++).
If the width/height of your tile is 32 then do this to find the first tile visible:
Map[(int)(x/32)][(int)(y/32)]
It works for me. Sorry, I dunno if i've explained very well...
---------------
I finally got it all together...
...and then forgot where I put it.
Edited by - AdmiralBinary on December 2, 2001 4:13:15 PM
AND:
If you want ppl to be able to smooth-scroll around your world instead of scrolling tile-by-tile, this is what i suggest:
Let them smooth scroll (x++, y++).
If the width/height of your tile is 32 then do this to find the first tile visible:
Map[(int)(x/32)][(int)(y/32)]
It works for me. Sorry, I dunno if i've explained very well...
---------------
I finally got it all together...
...and then forgot where I put it.
Edited by - AdmiralBinary on December 2, 2001 4:13:15 PM
"One way I''m thinking of speeding this up is finding the first tile that lies in the viewport, and start rendering from there. Is this the way to go, or is there a faster better way?"
You don''t need to find it. You should have a camera struct that knows where it is at all times. Same as you would with 3D.
The "faster" way is incorporating a bunch of optimization tricks. Start by not even checking parts of the map that aren''t on the screen based on the camera.
The camera should be centered so you''d go from say camera.x-5 to camera.x+5 and the same for the y in the render loop.
To speed it up even more you''ll need to eliminate a bunch of redundant math.
Ben
You don''t need to find it. You should have a camera struct that knows where it is at all times. Same as you would with 3D.
The "faster" way is incorporating a bunch of optimization tricks. Start by not even checking parts of the map that aren''t on the screen based on the camera.
The camera should be centered so you''d go from say camera.x-5 to camera.x+5 and the same for the y in the render loop.
To speed it up even more you''ll need to eliminate a bunch of redundant math.
Ben
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement