Tile* Map::getTile(unsigned short _x, unsigned short _y, unsigned char _z) { if (_z < MAP_LAYER) { // _x & 0x3F is like _x % 64 // _x & 0x1F is like _x % 32 TileMap *tm = &tileMaps[_x & 0x1F][_y & 0x1F][_z]; // search in the stl map for the requested tile TileMap::iterator it = tm->find((_x << 16) | _y); // ... found if (it != tm->end()) return it->second; } // or not return NULL; }
// Print the map in the console for testing purpose void Mapper::print(TileMap& tiles) { std::string out = ""; for (TileMap::iterator col = tiles.begin(); col != tiles.end(); ++col) { for (std::vector<TileSprite*>::iterator it = col->begin(); it != col->end(); ++it) { TileSprite* tile = *it; if(!tile) { out += MAP_NULL; } else if(tile->getType() == TileType::GROUND) { out += MAP_GROUND; } } out += MAP_LINE_BREAK; } }