Loading World Nodes Incrementally

DrKane
Unregistered
 
Post: #1
I am working on the level-laoding secting of my rpg engine. For testing sake, I have on 2d world array which holds is 30 x 30 tiles. Right now each of my world nodes are 10x10 tiles and are kept seperate as text files. So bassically I keep 9 nodes loaded into my worldArray at all times. My goal is to reload all of the nodes into my worldArray whenever the player crosses into a new node, so that the player will always remain in the center node. Now I've been fooling around with this for a while and just realized that when I ReLoad the new nodes into my worldArray, if I don't somehow reposition the player, that the player will hit the worldArray boundry. Say that the player has just crossed over from the middle node, into the right node, (i already know how to load the new nodes) how would I reset the player's position to make him go back to the center node( once I load the new nodes)?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #2
You probably need to make the player's coordinates wrap around in the centre node. For example, if the player crosses the right edge of the centre node, put them back on the left edge and reload the nodes. If they cross the left edge, put them back on the right and reload the nodes. Do the same for the top and bottom edges.

By the way, you don't necessarily need to reload all the nodes. You can just load the ones that weren't previously visible and move the ones that should still be visible into their new locations. When I say 'move', I mean you could do something with linked lists or array indexing to avoid having to copy memory. That's more of an optimisation issue though, so you might want to leave that kind of thing until you've got it working! Wink

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Feanor
Unregistered
 
Post: #3
This is hard to answer because you haven't provided enough details about your approach. I would think that, if your world is a grid, you'd give every square in the grid a unique id, starting maybe at AA00, and ending at BC29 or something. Then you just keep track of which section the player is on. Or you use world coordinates and, instead of "moving the player", you move the active boundary (the square around the nine currently loaded map sections).

Are you using a C array to hold references to your map sections? Or something more elaborate? In my dynaMap demo I used a double-linked list of references to a set of double-linked lists of map squares, one for each East-West line of map squares. You could also use a single quad-linked list, where each loaded map square pointed to the maps around it (or to NULL for neighbour squares which aren't yet loaded).
In any case, whether by using ids, or pointers, I'd have a field in the player data structure which referred to the map square currently occupied.

If this doesn't help, please elaborate on your situation.
--FÎanor
Quote this message in a reply
DrKane
Unregistered
 
Post: #4
I am using a tile-based grid. For testing purposes we'll say that I'm using a 90 x 90 2d array and each node is 30 x 30. I keep one large map in a map file. Now once the player moves out of the center node, I just load the new nodes and add or subtract the size of a node to the player's position. Now this works, but I'd like to work out a more elegant solution. What exactly do you mean when you say move the bordes instead of moving the player?
Quote this message in a reply
Feanor
Unregistered
 
Post: #5
I'm sorry -- I think I confused nodes with tiles (wasn't reading carefully). Also, I'm having trouble visualizing. When you say "move the player back to the centre node", are you physically moving him? I'm trying to picture a 2D world from above with a player icon moving across the screen and the world moving under him, but I still can't imagine why you have to move the player, if his position is relative to the world. If his position is relative to the screen then I maybe understand you.

A tile is what, ground/dirt/water etc? Approximately the size of the player? And a node is 10 tiles across and 10 tiles down? And the screen shows nine nodes (three across and three down) making it 30 tiles across and 30 tiles down? You have arrays of integers to represent the tiles, I guess? So if the value at worldArray[5][4] is DIRT_VALUE, you draw dirt, or if it's GRASS_VALUE, you draw grass, something like that? So player walks across the screen and suddenly he crosses from one node into another node, and you then want to scroll the screen and reposition everything, dump the old nodes and load the new nodes? This is where I'm getting lost. But you've changed your node from 10x10 to 30x30 :-).

This is why I don't like arrays of primitives for this sort of thing--you're not giving yourself enough information to go on. If you want to stick with arrays, and assuming I'm understanding you, perhaps you can use offset values for the array in memory and the position of the player. If you always know the location of the bottom left tile in world co-ordinates, you will always know the locations of all of the tiles on screen in world co-ordinates. If you remeber the player's location in world co-ordinates, you will always know which tile to draw him on, because you just subtract the world co-ordinates of the bottom left corner tile and what's left is the local co-ordinates of your player in the array in memory.

You're still going to have to do a lot of data copying if you use static arrays, which is a bit primitive, but should still work.

I hope this is helpful. I'm doing my best to get the big picture. I thought all 2D rpgs kept the player pinned in the exact centre of the screen, but maybe you've got player movement and screen scrolling happening independently like Baldur's Gate?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Maps Pathfinding Nodes jigzat 10 4,437 Jun 17, 2008 02:58 PM
Last Post: jigzat