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


Paging System Goodness

Recommended Posts

toucel    188
Heres some pseudo code for a paging system Im thinking up right now. I think this will work out fine, but it looks ugly especially the notion that each movement has a separate branch of code handling the transition. I was wondering if anyone could lend me some insight into tightening it up and making it more clean. Little background info: think of a system encompassing 9 seperate nodes arranged in a 3x3 grid the center is the one the player currently "resides" in. when the player/camera steps outside of a particular boundary the paging system comes into effect - throwing out the old stuff from the opposite direction the player is heading, loading the new nodes, and rearranging the structure to reflect the change (ie if the player goes left enough the original left node is now labeled as the center node) t = top, b = bottom, l = left, r = right ie - tl = top left delete(s) deletes the page node currently with s from the linked list change(f,t) changes the stage of the page node currently with f to t load(xpos, zpos, s) allocates a new node with s and loads the data off disk @ (xpos, zpos) for example:

delete(tl); //deletes the top left node

change(tl,t); //changes the label of the top left node to top

load(1,1,c); //adds a node to the list and loads the map at (1,1) labeling it as center

So anywho... heres the actual bit:

void page(unsigned int to)	//to describes the direction the player is moving

	int x,z;

	//Left and Right

	if (to == l) {

		//First get rid of the old nodes

		delete(tr); delete(r); delete(br); 

		//Now reflect the change in the structure

		change(t,  tr);
		change(c,  r); 
		change(tl, t); 
		change(b,  br); 
		change(bl, b); 
		change(l,  c);

		//Grab the current base (x,z) coordinates of the center node

		x = currentsector().x;
		z = currentsector().z;

		//Load the new nodes

		load(x-1, z-1, tl);
		load(x-1, z,   l );
		load(x-1, z+1, bl);


	... //do the same for movement to the right, bottom, etc


Hopefully this makes enough sense for someone out there... if there is a need for any bit of clarification just tell me. Basically I want to know if there are any issues I am failing to see here and/or if there is a cleaner way to do what I want to do. Thanks a lot!

Share this post

Link to post
Share on other sites