Saturday, March 20, 2010

Globetrotting - part 1

Tinyworld currently is just that. Tiny. If it were the real world, there would be the space for about two football fields side by side, and that's it.

But, the world is more than one map large, and more than one map tall. It is, effectively, a three dimensional world. Good for it. I've recycled my stairs code to connect one map to another side to side and top to bottom, and like all good fantasy worlds, it loops.

But some old bugs have come back to plague me, and I fear I won't be able to continue working on the world until I sort them out, and I hate debugging. Even when it's my own stuff. Especially when it's my own stuff.

So, every tile contains a number of items, two of which can have art associated with them - the variable names for these onMe, and the holding. onMe is anything that fills the space. A player, a creature, a tree, a wall, things like that. Things will run into and interact with these things. holding are anything that can be picked up. swords, shields, eventually gold.

When something is off screen, it's supposed to not draw at all. But that doesn't work. When a holding item is on another map, it still draws, and that takes up a lot of memory. Furthermore, if a building ever hits the end of the map, it will attempt to draw an item in a square that doesn't exist, and those will also always draw.

Which is where we come to the problem. Drawing stuff takes insanely longer than simply calculating it. My testing environment was a 5x5 world containing 10x10 maps. That's 2500 tiles to calculate. Without dungeons, no issue. With one dungeon, mild slowdown (okay, each dungeon increases the number of tiles by 500 or so, but see below). with two, it's chugging. Three or more and it's unplayable.

But I know it's not the tiles. I've tested this by increasing the number of maps to 20x20, and the size of the maps to the same amount, that becomes 160,000 tiles. Not a chug in site.

So, I have to stop and debug. First, the obvious problems - when a dungeon gets too big and draws outside of it's boundaries. Ironically, I could avert this by having huge maps, but that's a little counterproductive, because I want to make the dungeons bigger than they are, too. So, fix overflowing dungeons. Then fix overdrawing stuff. Then, back to the top, and see if we can have dungeons in the world...

No comments:

Post a Comment