MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / buildTileDistance

Method buildTileDistance

source/gamemap/TileContainer.cpp:645–719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

643}
644
645void TileContainer::buildTileDistance(int distance)
646{
647 if(mTileDistanceComputed >= distance)
648 return;
649
650 // We want to be able to fill a vector of tiles sorted beginning with the closest tile. If we look a grid (each letter
651 // represents a tile at the same distance from the center: a):
652 // jihghij
653 // ifedefi
654 // hecbceh
655 // gdbabdg
656 // hecbceh
657 // ifedefi
658 // jihghij
659 // We can see that there are 3 kind of tiles:
660 // - Vertical/Horizontal tiles (abdg): at each distance, there are 4 of them
661 // - Diagonal tiles (acfj): at each distance, there are 4 of them
662 // - Other tiles (ehi...): at each distance, there are 8 of them
663 // Moreover, we can see a symmetry. We can compute all tiles by computing only 1/8 tiles:
664 // j
665 // fi
666 // ceh
667 // abdg
668
669 // If we compute only the minimum tiles needed, we have no vertical tiles (since each of them can be deduced from the horizontal)
670 // To compute tiles easily, we will compute the 1/8 tiles until distance. Then, we will sort the tiles to begin with
671 // closest distance until farthest
672 mTileDistance.clear();
673 for(int y = 0; y <= distance; ++y)
674 {
675 for(int x = y; x <= distance; ++x)
676 {
677 TileDistance::TileDistanceType type;
678 if(y == 0)
679 {
680 type = TileDistance::TileDistanceType::Horizontal;
681 }
682 else if(x == y)
683 {
684 type = TileDistance::TileDistanceType::Diagonal;
685 }
686 else
687 {
688 type = TileDistance::TileDistanceType::Other;
689 }
690 int distSquared = x * x + y * y;
691 mTileDistance.push_back(TileDistance(x, y, type, distSquared));
692 }
693 }
694
695 std::sort(mTileDistance.begin(), mTileDistance.end(), sortByDistSquared);
696
697 // We have filled the tile distance vector. Now, we fill how each tile hides the
698 // other ones when they mask vision to help calculate visible tiles
699 for(TileDistance& tileDistance : mTileDistance)
700 {
701 // We don't process the first tile
702 if(tileDistance.getDiffX() == 0 && tileDistance.getDiffY() == 0)

Callers

nothing calls this directly

Calls 5

clearMethod · 0.80
getDiffXMethod · 0.80
getDiffYMethod · 0.80
computeTileDistancesMethod · 0.80
TileDistanceClass · 0.70

Tested by

no test coverage detected