diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-01-07 14:55:04 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-01-07 14:55:04 +0000 |
commit | 5ee926e8fe6ff9479b8968a3b40ab2f66bca2374 (patch) | |
tree | 8f7e3895984c0cd0d4b63f67f4c24f1a18d1fb3d /src | |
parent | e853459d4aad4a1d7c29a799b6f8d4b2f05cc452 (diff) | |
download | manaserv-5ee926e8fe6ff9479b8968a3b40ab2f66bca2374.tar.gz manaserv-5ee926e8fe6ff9479b8968a3b40ab2f66bca2374.tar.bz2 manaserv-5ee926e8fe6ff9479b8968a3b40ab2f66bca2374.tar.xz manaserv-5ee926e8fe6ff9479b8968a3b40ab2f66bca2374.zip |
r150@saline: gmelquio | 2007-01-07 15:48:59 +0100
Commented buckets a bit.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/mapcomposite.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 93ed2c37..207f1e33 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -265,17 +265,21 @@ ObjectBucket::ObjectBucket() { for (unsigned i = 0; i < 256 / int_bitsize; ++i) { + // An occupied ID is represented by zero in the bitmap. bitmap[i] = ~0u; } } int ObjectBucket::allocate() { + // Any free ID in the bucket? if (!free) { return -1; } + /* First check if next_object is a free ID. Directly check inside the + bitmap, as we have to update it anyway. */ if (bitmap[next_object / int_bitsize] & (1 << (next_object % int_bitsize))) { bitmap[next_object / int_bitsize] &= ~(1 << (next_object % int_bitsize)); @@ -285,11 +289,15 @@ int ObjectBucket::allocate() return i; } + /* next_object was not free. Check the whole bucket until one ID is found, + starting from the IDs around next_object. */ for (unsigned i = 0; i < 256 / int_bitsize; ++i) { int k = (i + next_object / int_bitsize) & 255; + // Check int_bitsize IDs at once. if (unsigned b = bitmap[k]) { + // One of them is free. Find it by looking bit-by-bit. int j = 0; while (!(b & 1)) { @@ -303,6 +311,8 @@ int ObjectBucket::allocate() return j; } } + + // No free ID in the bucket. return -1; } @@ -355,6 +365,9 @@ bool MapComposite::allocate(MovingObject *obj) b = buckets[i]; if (!b) { + /* Buckets are created in order. If there is nothing at position i, + there will not be anything in the next positions. So create a + new bucket. */ b = new ObjectBucket; buckets[i] = b; } |