Merge pull request #7299 from dabingnn/fast_tmx

Fast tmx
This commit is contained in:
minggo 2014-07-04 09:49:30 +08:00
commit 95fe74a34b
3 changed files with 16 additions and 10 deletions

View File

@ -237,7 +237,7 @@ void FastTMXLayer::updateTiles(const Rect& culledRect)
else else
{ {
//do nothing, do not support //do nothing, do not support
CCASSERT(0, "TMX invalid value"); //CCASSERT(0, "TMX invalid value");
} }
_indicesVertexZNumber.clear(); _indicesVertexZNumber.clear();
@ -264,9 +264,8 @@ void FastTMXLayer::updateTiles(const Rect& culledRect)
int offset = iter->second; int offset = iter->second;
iter->second++; iter->second++;
//CC_ASSERT(_tileToQuadIndex.find(tileIndex) != _tileToQuadIndex.end() && _tileToQuadIndex[tileIndex] <= _totalQuads.size()-1); int quadIndex = _tileToQuadIndex[tileIndex];
int quadIndex = (int)_tileToQuadIndex[tileIndex]; CC_ASSERT(-1 != quadIndex);
_indices[6 * offset + 0] = quadIndex * 4 + 0; _indices[6 * offset + 0] = quadIndex * 4 + 0;
_indices[6 * offset + 1] = quadIndex * 4 + 1; _indices[6 * offset + 1] = quadIndex * 4 + 1;
_indices[6 * offset + 2] = quadIndex * 4 + 2; _indices[6 * offset + 2] = quadIndex * 4 + 2;
@ -387,7 +386,13 @@ Mat4 FastTMXLayer::tileToNodeTransform()
} }
case FAST_TMX_ORIENTATION_HEX: case FAST_TMX_ORIENTATION_HEX:
{ {
_tileToNodeTransform = Mat4::IDENTITY; _tileToNodeTransform = Mat4
(
h * sqrtf(0.75), 0, 0, 0,
-h/2, -h, 0, offY,
0, 0, 1, 0,
0, 0, 0, 1
);
return _tileToNodeTransform; return _tileToNodeTransform;
} }
default: default:
@ -408,6 +413,7 @@ void FastTMXLayer::updateTotalQuads()
_tileToQuadIndex.clear(); _tileToQuadIndex.clear();
_totalQuads.resize(int(_layerSize.width * _layerSize.height)); _totalQuads.resize(int(_layerSize.width * _layerSize.height));
_indices.resize(6 * int(_layerSize.width * _layerSize.height)); _indices.resize(6 * int(_layerSize.width * _layerSize.height));
_tileToQuadIndex.resize(int(_layerSize.width * _layerSize.height),-1);
_indicesVertexZOffsets.clear(); _indicesVertexZOffsets.clear();
int quadIndex = 0; int quadIndex = 0;
@ -617,7 +623,7 @@ int FastTMXLayer::getVertexZForPos(const Vec2& pos)
ret = static_cast<int>(-(_layerSize.height-pos.y)); ret = static_cast<int>(-(_layerSize.height-pos.y));
break; break;
case FAST_TMX_ORIENTATION_HEX: case FAST_TMX_ORIENTATION_HEX:
CCASSERT(0, "TMX Hexa zOrder not supported"); CCASSERT(0, "TMX Hexa vertexZ not supported");
break; break;
default: default:
CCASSERT(0, "TMX invalid value"); CCASSERT(0, "TMX invalid value");

View File

@ -239,7 +239,7 @@ protected:
Mat4 _tileToNodeTransform; Mat4 _tileToNodeTransform;
/** data for rendering */ /** data for rendering */
bool _quadsDirty; bool _quadsDirty;
std::unordered_map<ssize_t, ssize_t> _tileToQuadIndex; std::vector<int> _tileToQuadIndex;
std::vector<V3F_C4B_T2F_Quad> _totalQuads; std::vector<V3F_C4B_T2F_Quad> _totalQuads;
std::vector<int> _indices; std::vector<int> _indices;
std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets; std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets;

View File

@ -43,7 +43,7 @@ namespace
CLN(TMXIsoTest1New), CLN(TMXIsoTest1New),
CLN(TMXIsoTest2New), CLN(TMXIsoTest2New),
CLN(TMXUncompressedTestNew), CLN(TMXUncompressedTestNew),
//CLN(TMXHexTestNew), CLN(TMXHexTestNew),
CLN(TMXReadWriteTestNew), CLN(TMXReadWriteTestNew),
CLN(TMXTilesetTestNew), CLN(TMXTilesetTestNew),
CLN(TMXOrthoObjectsTestNew), CLN(TMXOrthoObjectsTestNew),
@ -55,8 +55,8 @@ namespace
CLN(TMXOrthoFlipRunTimeTestNew), CLN(TMXOrthoFlipRunTimeTestNew),
CLN(TMXOrthoFromXMLTestNew), CLN(TMXOrthoFromXMLTestNew),
CLN(TMXOrthoXMLFormatTestNew), CLN(TMXOrthoXMLFormatTestNew),
// CLN(TileMapTestNew), CLN(TileMapTestNew),
// CLN(TileMapEditTestNew), CLN(TileMapEditTestNew),
CLN(TMXBug987New), CLN(TMXBug987New),
CLN(TMXBug787New), CLN(TMXBug787New),
CLN(TMXGIDObjectsTestNew), CLN(TMXGIDObjectsTestNew),