I'm learning Cocos2dx and I'm using tiled map. So, let consider a following piece of code:
auto map = TMXTiledMap::create("map.tmx");
auto layer = map->getLayer("Tile Layer 1");
auto gid = layer->tileGIDAt(Point(X, Y));
And last line matters to me. I'm confused because I saw implementation of tileGIDAt(Point):
uint32_t TMXLayer::getTileGIDAt(const Vec2& pos, TMXTileFlags* flags/* = nullptr*/)
{
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
ssize_t idx = static_cast<int>((pos.x + pos.y * _layerSize.width));
// Bits on the far end of the 32-bit global tile ID are used for tile flags
uint32_t tile = _tiles[idx];
// issue1264, flipped tiles can be changed dynamically
if (flags)
{
*flags = (TMXTileFlags)(tile & kTMXFlipedAll);
}
return (tile & kTMXFlippedMask);
}
So, I am confused because the map seems to be represented as array in memory.
Why is it possible? It matters to me because as you know tiled map may be very large. And what's about map of size: 1000000 tiles x 1000000 tiles. In a result we should take a 1000000^2 elements of Tile, so we need a very long continuous chunk of memory. But it is impossible to get such big chunk of memory ( is it possible?).
Please explain me.