Witam. Piszę program w C++ oraz SFML 2.X. Potrzebuję przesłać wskaźniki Terrain* do funkcji Terrain::generateBorders(). Niestety funkcja wypisuje, że przesłane wskaźniki są nullptr. Jak przesłać te wskaźniki do funkcji ?
(Jakby to było istotne to Terrain dziedziczy po sf::Drawable, public sf::Transformable)
void Terrain::generateBorders( Terrain* topTerrain, Terrain* bottomTerrain, Terrain* leftTerrain, Terrain* rightTerrain) {
outlines.clear();
outlines.setPrimitiveType(sf::Quads);
if (coords.x / 16 == 1 && coords.y / 16 == 1) {
cout << "coords " << coords.x / 16 << " " << coords.y / 16 << "\n";
if (topTerrain != nullptr)
cout << "topTerrain exist\n";
else
cout << "topTerrain is null\n";
if (bottomTerrain != nullptr)
cout << "bottomTerrain exist\n";
else
cout << "bottomTerrain is null\n";
if (leftTerrain != nullptr)
cout << "leftTerrain exist\n";
else
cout << "leftTerrain is null\n";
if (rightTerrain != nullptr)
cout << "rightTerrain exist\n";
else
cout << "rightTerrain is null\n";
}
}
void generateBorders() {
Chunk* topChunk;
Chunk* bottomChunk;
Chunk* leftChunk;
Chunk* rightChunk;
Terrain* topTerrain;
Terrain* bottomTerrain;
Terrain* leftTerrain;
Terrain* rightTerrain;
int y, x;
for (int i = 0; i < chunks.size(); i++) {
y = i / width;
x = i % width;
topChunk = getChunk(x, y - 1);
bottomChunk = getChunk(x, y + 1);
leftChunk = getChunk(x - 1, y);
rightChunk = getChunk(x + 1, y);
if (topChunk != nullptr)
topTerrain = topChunk->terrain;
else
topTerrain = nullptr;
if (bottomChunk != nullptr)
bottomTerrain = bottomChunk->terrain;
else
bottomTerrain = nullptr;
if (leftChunk != nullptr)
leftTerrain = leftChunk->terrain;
else
leftTerrain = nullptr;
if (rightChunk != nullptr)
rightTerrain = rightChunk->terrain;
else
rightTerrain = nullptr;
if (topTerrain != nullptr) cout << "loaded topTerrain\n";
if (bottomTerrain != nullptr) cout << "loaded bottomTerrain\n";
if (leftTerrain != nullptr) cout << "loaded leftTerrain\n";
if (rightTerrain != nullptr) cout << "loaded rightTerrain\n";
chunks[i]->terrain->generateBorders(topTerrain, bottomTerrain, leftTerrain, rightTerrain);
}
}
loaded bottomTerrain
loaded rightTerrain
loaded bottomTerrain
loaded leftTerrain
coords 1 1
topTerrain is null
bottomTerrain is null
leftTerrain is null
rightTerrain is null
chunk 1x1 nie ma ani jednego sąsiadującego terenu a powinien mieć cztery sąsiadujące tereny