Sign in to follow this  

2d RingQueue data structure, help with index wrapping?

Recommended Posts

I'm building a special vertex data cache for a terrain heightfield basically its a 2d ringqueue so, as the player moves north off the terrain, I 'scroll' the ringqueue north, and load new terrain data into the space cleared by the old stuff that got scrolled out does this similarly for all 4 compass directions once issue im getting, is how to safely access the data in this 2d queue ive been using a procedural terrain generating method that requires relatively random access to verticies and it would be very hard to redesign this method to explicitly avoid stepping over cache boundries so I'm considering, that perhaps I should simply do a safety check for every access i make something like safety(y,x){ return cache[(y+size)&(size-1)][(x+size)&(size-1)]; } that basically uses a bitlogic trick to modulus the indecies so they wrap back to the other size of the cache (assming size is a power of 2) so, what do you think? how do other people build 2d ringqueues? can someone suggest a better, cheaper way to make it wrap even with random accesses?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this