317 Regions

My server is going to use Region objects to split the game world up, such that each player can view a maximum of 4 Regions.

I’ve been told that regions are 104*104. However I decided to dump some logs, and I don’t really follow.
Anyone care to take a look and explain?

This is the code used to obtain the X/Y co-ordinates displayed:

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getHeight() {
        return height;
    }

    public int getLocalX() {
        return getLocalX(this);
    }

    public int getLocalX(Point p) {
        return x - 8 * p.getRegionX();
    }

    public int getLocalY() {
        return getLocalY(this);
    }

    public int getLocalY(Point p) {
        return y - 8 * p.getRegionY();
    }

    public int getRegionX() {
        return (x >> 3) - 6;
    }

    public int getRegionY() {
        return (y >> 3) - 6;
    }

And this is the code used to print the values out:

        for (int i = 0; i < 50; i++) {
            for (int y = 0; y < 50; y++) {
                Point p = Point.getLocation(i, y, 0);
                String output = "\nTile info: X=" + i + " Y=" + y + "\n";
                output += "LocalX=" + p.getLocalX() + " LocalY=" + 
                        p.getLocalY() + "\n";
                
                output += "RegionX=" + (p.getRegionX() + 6) + " " +
                        "RegionY=" + (p.getRegionY() + 6) + "\n";
                logger.info(output);
            }
        }

This code is found in the (342) client:

public Class30[][][] aClass30ArrayArrayArray837 = new Class30[4][104][104];

This looks like a multidimensional array that holds all possible positions in a region, 4 is z, 104 and 104 are x and y.
So I’m pretty sure it’s 104x104, but I could be wrong. :stuck_out_tongue:

@blakeman8192: Congratz on finding the ground item spawns array. 104x104 is the region size afaik, and 4 is the level/‘floor’ objects can be placed at.

You’ve both overlooked my actual question. :stuck_out_tongue: How come the regions are significantly smaller than 104*104, according to those logs?

The actual regions are technically 88 tiles (hence the /8 and 8 you see often) but the client displays a 104104 area (with the local player/npc area being 3232). Additionally, it’ll send the map region load packet every 4 of the 8 tile regions iirc. Then you have the +6/-6 stuff which confuses it even more :P.

No, 4x104x104 is the current map load area for the client. The client usually has around 6 regions loaded at one time, all clipped to fit that 104x104 area, where the viewarea is x by y.

why server-side regions? i understand the client loads the maps first, but the server doesn’t send all the data (npcs, ground items etc) for the 4 regions around you does it? why not like RSC, your minimap is 16x16 tiles, so server sends all data for +8 & -8 tiles from you. Same with the chat radius

yes this works fine except i believe 32x32 in rs2 however separating in regions is useful for reasons of interfaces. some regions have snow and get darker some regions like mini games have a interface up at all times.

would it not be possible to have an almost second layer of regions? so that where 4 regions on layer meet that is also the centre of a region on layer 2, then you check against both layers to see which player entities are near. So if we kept your idea object of having 100 regions with 10 players in each, you’d do the same calculation but then do it a second time for the second layer. Sure this would double the iterations per cycle but it would be a more effective manner in which to see who is close to you even if they are in a neighbouring region

  1. Your javadoc comments are too verbose…
  2. Your package name is truly just too long. Reminds me of ruler’s method names.
  3. Switch-case blocks don’t need a scope… it’s only needed in languages like C/++ if you define a variable in that block that has the name of a variable defined in another block because you’ll run into multiple-declaration issues.
  4. I don’t like your formatting style.
    /rant :\

[quote=“oksuper_, post:10, topic:293433”]1. Your javadoc comments are too verbose…
2. Your package name is truly just too long. Reminds me of ruler’s method names.
3. Switch-case blocks don’t need a scope… it’s only needed in languages like C/++ if you define a variable in that block that has the name of a variable defined in another block because you’ll run into multiple-declaration issues.
4. I don’t like your formatting style.
/rant :[/quote]
5. Only Satan or maybe Hitler would implement an algorithm like that
6. Calling it ‘pro-choice’ does not change the fact that it’s the horribe slaughter of innocent unborn babies!!

/adhominem

Your indentation is fine. Although I prefer 4 spaces. Anyway, I was talking about your bracket placement :expressionless:

shutup

newline before bracket is awesome and you know it

[quote=“Cheese_Police, post:13, topic:293433”][quote author=oksuper_ link=topic=388288.msg2905510#msg2905510 date=1249768629]
Your indentation is fine. Although I prefer 4 spaces. Anyway, I was talking about your bracket placement :expressionless:
[/quote]

shutup

newline before bracket is awesome and you know it[/quote]

Makes sense that you’d think that, since you also think lisp is awesome.[br][br][size=1]Posted on: August 09, 2009, 02:11:12 am[/size][hr]

public static final int getBaseX(int x, int xSize)
{
return (x / xSize) * xSize;
}

object, do you realize the following method is completely useless:

     public static final int getBaseX(int x, int xSize)
     {
          return (x / xSize) * xSize;
     }

I don’t know if the compiler or hotspot will optimize that, but it’s a total waste of cpu usage. You could just eliminate the method and all subsequent methods altogether.

[quote=“Cheese_Police, post:13, topic:293433”][quote author=oksuper_ link=topic=388288.msg2905510#msg2905510 date=1249768629]
Your indentation is fine. Although I prefer 4 spaces. Anyway, I was talking about your bracket placement :expressionless:
[/quote]

shutup

newline before bracket is awesome and you know it[/quote]
makes sense that you’d say that since you use VS/VC# which takes that sort of style. ill stick with my bracket then newline[br][br][size=1]Posted on: August 08, 2009, 10:35:13 pm[/size][hr][quote=“Miss Silabsoft, post:8, topic:293433”][quote author=xEnt link=topic=388288.msg2904570#msg2904570 date=1249718175]
why server-side regions? i understand the client loads the maps first, but the server doesn’t send all the data (npcs, ground items etc) for the 4 regions around you does it? why not like RSC, your minimap is 16x16 tiles, so server sends all data for +8 & -8 tiles from you. Same with the chat radius
[/quote]
yes this works fine except i believe 32x32 in rs2 however separating in regions is useful for reasons of interfaces. some regions have snow and get darker some regions like mini games have a interface up at all times.[/quote]good point, forgot about all the features in rs2.

[quote=“xEnt, post:16, topic:293433”][quote author=Cheese_Police link=topic=388288.msg2905557#msg2905557 date=1249769935]

shutup

newline before bracket is awesome and you know it
[/quote]
makes sense that you’d say that since you use VS/VC# which takes that sort of style. ill stick with my bracket then newline[/quote]

uh, no, i don’t use visual studio at all

i use that style because i like it, it looks clean, and it doesnt suck nutsack.

[quote=“object, post:1, topic:293896”]Taharok: That method is working just like it should, and yes, I know it might look a little bit odd, just because it takes the X co-ordinate, divides it with its own X-planes’ length and then multiplies with the same value. However, since the data-type is int, it will also take rounding into consideration, thus making it correct. I can show you a few examples.

Example #1:

  • x = 35
  • xSize = 32

First we divide x with xSize, and we get the value 1. Then we multiply 1 with xSize, and our current value quite obviously will become 32 again. However, take a look at the next example.

Example #2:

  • x = 165
  • xSize = 32

First we divide x with xSize, and we get the value 5. Then we multiply 5 with xSize, and our current value will become 160 this time - in contrast to what you would expect; 165.[/quote]

I believe my calculations are right here, but if xSize is always going to be 32, you can use the following calculation instead:

[tt]return x & 0xE0;[/tt]

0xE0, which is 224 in decimal, was calculated using the following concept: [tt](~32 & 0xff) + 1[/tt]. Since AND only keeps bits that are both 1, we want to exclude all bits that make a number < 32, since that will also drop the bits that force a number to not be divisible by 32. NOTting it gives us the value we want, but we optionally limit it to the range of 255, or one byte. We add one to the final result because ~32 = -33, when we want to work with -32.

I’m sure there are other ways to do this, but if you really are only working with 32, [tt]x & 0xE0[/tt] is considerably faster than [tt](x / 32) * 32[/tt]. Just my two cents.

a client region is 1041044 but a map is 6464 so there tiled and trimmed to 6464, there are 4 maps loaded at a time

is that the 3 closest surrounding maps to your location and the current one?