Sunday, March 28, 2010

Globetrotting - debugging 1

So, I've been working on fixing the extra walls showing up in tinyworld, and I've made a lot of progress.

The first thing I did was I added a clause in the 'draw a room' function. You see, when a dungeon gets built, it only actually calculates the size of the first room - everything off of that is recursive (well, kinda). It just says 'based on the size and position of the first room, draw a room over there'. Which means if a 20 space wide map generates a 10 space wide room, and it wants to have a ten space-wide room on either side of it - those would have run off the edge of the map before. Now, they just look ugly. >.> Which is an improvement, running wise, but I need to come up with a more eloquent way of keeping that from happening.

Actually, that makes me think of another thing I need to add to the program - a recursive dungeon generator. What I have is highly random, but not perfectly so. There's only a few dozen possible combinations. Something to add to the random, but stay away from that spaghetti dungeon feel would be great...

Anyways, keeping rooms from generating off the edge of the maps made a noticable difference in the number of 'null location walls' that were drawing at world 0,0. That's a great thing. But it didn't fix all of them, only a few less than half. I soon realized, that's because every time I drew a wall, I just threw away whatever was on that space beforehand. Okay, that's fine - except that I draw rooms adjacent to one another, I redraw the walls, because the code doesn't care what walls are external. So, for a 5x5 room with a 5x5 room adjacent, I'm creating adn then losing track of five walls. With six rooms (often closer to 10x10) across five floors times five dungeons, that means probably 200 (or 500 with less conservative numbers) walls being created, told to keep track of themselves, and then dropped.

So, I make it clear off a square properly before adding a wall on it. Instant speed increase. But it still doesn't get them all, and I think - well, it's probably the same problem but slightly different.

The answer is staring me in the face - doorways. I draw doorways after I draw walls, and that involves deleting the wall there. I was right, I wasn't removing them properly. I don't see a speed increase here, but that's okay - it's only really affecting twenty squares to the previous change's 200.

Still, there's one square left that's eating away at me, and I can't figure it out. I'm almost positive it's related to the stairs, and it dissapears once I reach the top floor. Weird.

I've got other debugging and optimizing still to do, but the change is enormous.

Previous time taken to take one step: minimum ten seconds. Now? One and a half. Still unnacceptable, but there are a bucketload of things I'm doing wrong somewhere, and that last null-location wall is going to fall some day.

No comments:

Post a Comment