MCPcopy Create free account
hub / github.com/axmolengine/axmol / tilesetForLayer

Method tilesetForLayer

core/2d/FastTMXTiledMap.cpp:121–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121TMXTilesetInfo* FastTMXTiledMap::tilesetForLayer(TMXLayerInfo* layerInfo, TMXMapInfo* mapInfo)
122{
123 Vec2 size = layerInfo->_layerSize;
124 auto& tilesets = mapInfo->getTilesets();
125
126 for (auto iter = tilesets.crbegin(), iterCrend = tilesets.crend(); iter != iterCrend; ++iter)
127 {
128 TMXTilesetInfo* tilesetInfo = *iter;
129 if (tilesetInfo)
130 {
131 for (int y = 0; y < size.height; y++)
132 {
133 for (int x = 0; x < size.width; x++)
134 {
135 uint32_t pos = static_cast<uint32_t>(x + size.width * y);
136 uint32_t gid = layerInfo->_tiles[pos];
137
138 // gid are stored in little endian.
139 // if host is big endian, then swap
140 // if( o == CFByteOrderBigEndian )
141 // gid = CFSwapInt32( gid );
142 /* We support little endian.*/
143
144 // FIXME: gid == 0 --> empty tile
145 if (gid != 0)
146 {
147 // Optimization: quick return
148 // if the layer is invalid (more than 1 tileset per layer) an AXASSERT will be thrown later
149 if ((gid & kTMXFlippedMask) >= static_cast<uint32_t>(tilesetInfo->_firstGid))
150 {
151 return tilesetInfo;
152 }
153 }
154 }
155 }
156 }
157 }
158
159 // If all the tiles are 0, return empty tileset
160 AXLOGW("axmol: Warning: TMX Layer '{}' has no tiles", layerInfo->_name);
161 return nullptr;
162}
163
164void FastTMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo, bool allowInvisibleLayers)
165{

Callers

nothing calls this directly

Calls 2

crbeginMethod · 0.45
crendMethod · 0.45

Tested by

no test coverage detected