When creating the thread you are suposed to assign it a function to do work. What you posted here creates a thread that simply changes the value of "done" to true. My comment "// DOING HEAVY DUTY WORK HERE" actually was meant to be replaced by the work you wanted done there, meaning tile creation code.
The separate thread (meaning separate from the main thread), will build the tiles and when its done it will set "done" to true.
In the update loop while "done" is still false (meaning the separate thread has still not finished building the tiles since in the end it sets "done" to true) you draw the text. Your update loop keeps going checking every time time it loops if "done" is true. When the thread finishes your update loop will detect that "done" is now true and will draw the tiles instead.
Remember that you will need to reassign the sf::View you normally use because while "done" is false you are setting the default view to draw the text.
Note: Since you are creating the tiles on a separate thread with smart pointers they will go out of scope when the thread function finishes due to RAII. You need to actually allocate the memory for the tiles outside the thread function or move the created memory to a variable in a scope outside the thread to do this the vector itself would need to be wrapped in a smart pointer.
Example with memory allocation in main thead.
// Still in main thread
std::vector<std::shared_ptr<Tile>> tilesVector;
tilesVector.reserve(Map_Height * Map_Width); // This creates the tiles with default constructor ( Tile() )
std::atomic<bool> done(false);
// Create thread to execute the bellow code while main thread continues normal execution
std::thread t([&done, &tilesVector] {
// Tile creation IS the heavy duty work
for(auto y = 0; y < Map_Height; ++y)
{
for (auto x = 0; x < Map_Width; ++x)
{
Tile * tile = tilesVector[y * Map_Width + x].get(); // Get a pointer to tile to change its attributes
tile->spr.setSize(TILE_SIZE);
tile->spr.setFillColor({ 0,255,0,15 });
tile->spr.setOutlineColor(sf::Color::White);
tile->spr.setOutlineThickness(1.f);
tile->spr.setPosition(x * TILE_SIZE.x, y * TILE_SIZE.y);
tile->spr.setOrigin(TILE_SIZE.x / 2.f, TILE_SIZE.y / 2.f);
if (y >= 240 && y <= 260 && x >= 240 && x <= 260)
{
tile->spr.setFillColor({ 200,25,22 });
}
// tiles.emplace_back(std::move(tile)); This line no longer needed, we already have our tile vector
}
}
// After building the tiles we set variable to true to signal that our work
// (tile creation) on this separate thread is done.
done = true;
});
/* Meanwhile main thread continued to execute and do its thing */
/* ... Update loop ... */
while(window.open())
{
/*
..... Any other stuff you do on the update loop here ....
*/
window.clear();
if ( ! done) // If the thread has not finished it's work yet
{
window.setView(window.getDefaultView());
window.draw(text);
}
else
{
// Here tile drawing code
}
window.display();
}