Server Help

ASSS Questions - Bug: Overlapping Regions (I hope)

Bak - Mon Jan 03, 2005 2:01 pm
Post subject: Bug: Overlapping Regions (I hope)
There's a bug with eLVL files and overlapping regions.

Here's you can detect it:

download the attached overlapping.lvl file. It defines two regions(testRegion and then overlappingRegion) that are identical, as you can tell by the hex:



They are both encode one tile (0,0), while every other tile is not in either region.

Then you make a module using the attached (testModule.c) source... here's the part that matters from the source:

Code: Show/Hide

local void PlayerAction(Player *p, int action, Arena *arena)
{
   if (action == PA_ENTERGAME)
   {
      Region *test = md->FindRegionByName(arena,"testRegion");
      Region *over = md->FindRegionByName(arena,"overlappingRegion");
      int x = 0;
      int y = 0;

      if (test && over)
      {
         if (md->Contains(test,x,y))
         {
            printf("point is in the test region.\n");
         }
         else
         {
            printf("point is NOT in the test region\n");
         }

         if (md->Contains(over,x,y))
         {
            printf("point is in the overlapping region.\n");
         }
         else
         {
            printf("point is NOT in the overlapping region\n");
         }
      }
      else
         printf("one of our regions is null\n");
   }
}


so when a player enters the game it will look for the two regions and check for point (0,0) in both of them. Here's the output when it's run (and a player enters the arena):

Quote:
point is NOT in the test region
point is in the overlapping region.


I'm lead to beleive that this is a bug in mapdata.c, and I guess what's happening is that when the regions are being loaded a single sparse array is used and the second encoded region (overlappingRegion) overwrites the first region (testRegions), entry in the sparse array. That's just a guess, however.

I'd debug it myself, but I'm still a little shaky on the exact details of the implemented sparse array, and the code isn't the easiest to read:

Quote:
static inline unsigned char lookup_sparse(sparse_arr c_3, int x, int y)
{
sparse_chunk_2_t *c_2 = (*c_3)[(x>>5)&31][(y>>5)&31];
if (c_2)
{
sparse_chunk_1_t *c_1 = (*c_2)[(x>>3)&3][(y>>3)&3];
if (c_1)
{
return (*c_1)[(x>>0)&7][(y>>0)&7];
}
else
return 0x00;

}
else
return 0x00;

}


I'd really like a fix for mapdata.c which handles overlapping regions correctly.

MGB: I still can't have two code block in one post icon_sad.gif
Grelminar - Thu Jan 06, 2005 1:05 am
Post subject:
Don't try to read the sparse array code directly. It's generated by a script, gensparse.py, which can customize it for different sizes and time/space tradeoffs. The script isn't much easier to read, though. I'll bet the problem isn't in the sparse array stuff, though, but in how mapdata uses it. It's not as simple as overwriting a value, though: I tried to be clever and associate sets of overlapping regions with values in the sparse array. The cleverness saves about 30% of memory for region stuff, but is sort of complicated. I'lll take a look at this case in a minute.

Btw, are you using 1.3.2 or stuff from CVS? I fixed a rather serious bug in mapdata.c a week or two after 1.3.2.
Bak - Thu Jan 06, 2005 1:51 am
Post subject:
I'm using 1.3.2, can you post the new mapdata.c (or location of the CVS + how to access it).
Grelminar - Thu Jan 06, 2005 2:02 am
Post subject:
This was definitely a bug, and it's fixed. I've attached the updated file. You might have to add '#include "settings/game.h"' to make it compile with 1.3.2, though.
Bak - Thu Jan 06, 2005 2:35 am
Post subject:
no dice? It doesn't seem to work; I get the same output with the testModule:

Quote:
point is NOT in the test region
point is in the overlapping region


Did you change any other files?

On another note, it would be nice if findRegionByName returned an empty region instead of NULL if it couldn't find a region, if it didn't take up too much space... or if the contains function checked for null... basicly I want to be able to do:

md->Contains(md->FindRegionByName(arena,"anyname"),512,512)

and not have the server crash, but I can see why it's done the way it is... and this isn't a pressing issue.
Grelminar - Thu Jan 06, 2005 3:13 am
Post subject:
It works fine for me. Are you sure the new one is compiling and getting loaded?

Yes, I did change lots of other files since 1.3.2. I'll try to make a new release soon.

I'd rather have it return NULL so that you can tell the difference between a region that doesn't exist, and a region that exists but is empty. You can easily write your own function to take an arena and a name and coords and return what you want.
Bak - Thu Jan 06, 2005 11:42 am
Post subject:
You're right, I had the wrong one loading. Works great, thanks grel.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group