World Looping

The last week I have been working on several different features: optimized world loading, horizontal world looping, and a secret feature I’m working on that I will announce in detail before too long. Aside from that I’ve been doing some other things such as getting the forums up and running!

The world loading optimizations I made are really going to make a huge difference with the game’s performance. Before the entire world would be loaded and stay loaded. Every single entity would be updated every frame. This all could be quite taxing on both the cpu and memory. Now the world is broken up into regions and a region is only loaded if it is needed. If a region is unused for awhile then it is unloaded. For a large world only 1/8 of it will typically be loaded at one time. That’s a huge difference!

While I was breaking up the world into regions I decided it was a good time to finally implement world looping. This means that if a player runs in the same direction then he will eventually loop back around to the same place he started. Another way to think of it is take a piece of paper and curl it up so that two opposite ends are touching. This is what the world looks like now. This world looping was actually quite a bit of work. I faced two major challenges with it.

The first one was getting the rending to work. If standing next to the world seam (where the two ends meet), then I needed to have the entities, tiles and whatever else render from two sides of the world.

The other challenge, the more difficult one, was that all of the systems relied on the assumption that the world started at (0,0) and ended at the world’s end. If something went past either of these points, across the seam, then it would be ignored. For example light would suddenly stop at the seam and cause some odd lighting as shown below. The light needed to jump across the world seam and affect the other end of the world. I had to worry about this for all of the other systems as well such as the automata (water) and physics. There are still a few issues with it that I need to cleanup but I’d say it is 90% of the way there.

Expect updates from me to come a little more frequently starting now.

Notice the line in the middle of the blocks. That’s the world seam and shouldn’t be visible…

3 thoughts on “World Looping

  1. fidgetwidget

    I encountered similar problems when I was experimenting with XNA and making a looking tile world with lighting. The one approach I had the most success with was to not treat the world as an array of blocks (starting at 0,0 and growing outwards), but as a tree of connected chunks. Each chunk was aware of its neighbors, and lighting was calculated across chunks (so there were never any seams).

    Reply
    1. Jasson Post author

      I something similar to this. I split the world into 16×16 tile segments. So instead of looping the actual tiles I just have to deal with looping the segments. :)

      Reply

Leave a Reply