Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GalaxyQuest

About "Tiling in DX: part 2" verification.

This topic is 6410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I was looking at the New article "Tiling in DirectX: Part 2" by martin estevao. The article was pretty lame since he pretty much copied Jim adams smooth scrolling, but thats not the point i want(hehe..just had to slip that in). The point i want to verify is his 2 for loops: - his outer loop goes in x direction < screen_sizeX - inner for loop goes in y direction < screen_sizeY I hope its not just me..because i got the jim adams copy right here and its different, yeah sure you can do it martins way..but images will be cut if they are bigger than a 32x32 tile. Well anyways... For tiling a map and objects correctly, isnt this backwards?!?

Share this post


Link to post
Share on other sites
Advertisement
I dunno... I always did my X loop inside my Y... This is especially useful if you are doing trees... they automatically ZOrder that way.

E.D.

Share this post


Link to post
Share on other sites
Thats exactly my point. His x loop is on OUTSIDE, therefore he draws column wise one at a time...which is what i thought was wrong way to do it.

Share this post


Link to post
Share on other sites
Yes, if you want easy z ording, you draw your x loop inside of your y loop, and your tile array should be organized as so:
tile[y][x]

Possibility

Share this post


Link to post
Share on other sites
you''re right, gq. even for a rectangular map, you want to loop the x inside of the y loop, except in one situation: when there is absolutely NO overlap with neighboring tiles, which when doing isometric tiles, is almost never.

ideally, each layer is rendered from "far" to "near", and that is usually dependent on the y coordinate rather than the x coordinate.

on another note...while those of us who come to this forum are well aware of who jim adams is, the rest of the world is "unenlightened", and the author of the article probably doesnt even know who jim is(unfortunate, really, jim''s a good guy). this may change, however, when jim''s new book comes out sometime late next year.

Share this post


Link to post
Share on other sites
Hi Tanstaafl.
Your right about the comment with jim adams, I sometimes get a little hasty with my words. I guess i am just a little frustrated with the article only because i didnt really get anything new out of the article that wasnt already posted in the GameDev Tile-Based Articles Vault. "Smooth scrolling" is one of those articles. Oh well, I guess i psyched myself up too much..hehe. If you read this martin, i take back the "lameness" comment i made, sorry, but im still disappointed.

Share this post


Link to post
Share on other sites
Hi all, just thought you might find this interesting if your thinking of using martins version of smooth scrolling VS. jim adams version(also on this website)

** Here are my latest finding concerning the article "tiling in directX part2 **

Basically i did a comparison of math operations of the 2 different versions since i noticed somethings a little weird so here i go:

Note: first of all, both versions use 2 for() loops which iterate for a total of (SCREEN_SIZEX-1)*(SCREEN_SIZEY-1). So if for my example you can fit 20 by 20 tiles on your screen, the 2 for() loops iterate for 19*19 or 361 total iterations. So...

JIM''s version ---VS.--- MARTIN''s version
------------------ ----------------------
both calculate offsets using the &(AND) operation for x and y:
x-> 1 time .............. x-> 361 times
y-> 1 time .............. y-> 361 times
= 2 & operations ....... = 722 & operations !!

both find tile to use in map using /(DIVIDE) operation for x,y:
x-> 1 time .............. x-> 361 times
y-> 1 time .............. y-> 361 times
= 2 / operations ........ = 722 / operations !!

*Note all other operations are pretty much the same except for the difference in above. So martins version does 1440 MORE math operations then Jims. So, you guys just learning, all these extra math operations could have been spent displaying more animations or more AI calculations..it adds up if you dont watch out! I let you make an informed decision to use his code or not..thats all.



aka John M.
Never give up. Never surrender!


Share this post


Link to post
Share on other sites
Just to explain a little why / and & are not necessarily that
bad...

scroll_x = x + (world_camerax / TILE_SIZE);
scroll_y = y + (world_cameray / TILE_SIZE);

The "world_camerax / TILE_SIZE" is a constant for the entire
loop and therefore is called a CSE or common-subexpression.
CSEs can be optimized by any decent compiler and will be
calculated OUTSIDE the loop.
Note that if TILE_SIZE is a power of 2, the / will even be
replaced by a shift instruction.

offset_x = world_camerax & TILE_SIZE;
offset_y = world_cameray & TILE_SIZE;

Since world_camerax & TILE_SIZE is also a CSE, it will be calculated outside the loop (if the compiler thinks it''s
worth it... an AND instruction takes a single cycle on an
recent Pentium)

Stop worrying about indivual cycles, it''s not worth the time... unless you still want to do 70 fps software rendering ;-)
The biggest delay in the algorithm are caused by the blits to
the screen!

--- axelP

Share this post


Link to post
Share on other sites
Hmm...Interesting thread. This is Martin, the author of "Tiling in DirectX: Part II."

First of all, I HAVE heard of Jim Adams (although I don''t recall reading his smooth scrolling article), and I''m pleased to hear that some people are actually comparing me to him. So that''s cool.

Second, the for loops problem (MY MISTAKE, I ADMIT) was fixed. Many thanks to Dave Astle for modifying them!

Third, I would appreciate if people wouldn''t call my stuff "lame." I''m just trying to help some of the newer game developers out a little. However, I do realize that the "for" loops thing was inexcusable, though.

Thanks.





______________
Martin Estevao
lpSoftware

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!