However, I am not sure what is meant with “you always have to do two dereferences to get to the first entry” if a pointer table is used. Is it the extra check to see if the value is null, or is TileChunkHash[HashSlot] slower than TileChunkHash + HashSlot?
Here is how I would have done it with a pointer table:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 | tile_chunk *Chunk = TileMap->TileChunkHash[HashSlot];
while(Chunk)
{
if((TileChunkX == Chunk->TileChunkX) &&
(TileChunkY == Chunk->TileChunkY) &&
(TileChunkZ == Chunk->TileChunkZ))
{
return(Chunk);
}
Chunk = Chunk->NextInHash;
}
if(Arena)
{
Chunk = PushStruct(Arena, tile_chunk);
uint32 TileCount = TileMap->ChunkDim*TileMap->ChunkDim;
Chunk->TileChunkX = TileChunkX;
Chunk->TileChunkY = TileChunkY;
Chunk->TileChunkZ = TileChunkZ;
Chunk->Tiles = PushArray(Arena, TileCount, uint32);
// TODO(casey): Do we want to always initialize?
for(uint32 TileIndex = 0;
TileIndex < TileCount;
++TileIndex)
{
Chunk->Tiles[TileIndex] = 1;
}
Chunk->NextInHash = TileMap->TileChunkHash[HashSlot];
TileMap->TileChunkHash[HashSlot] = Chunk;
}
return(Chunk);
|
/Kim