Issue:
I want to be able to set up my game loop to work concurrently with my pathfinder request, that would be a queue which different units request for in order in the pathfinder thread.
My current attempts have so far failed.
-
while (ConqEngine->IsRunning())
{
bool running = ConqEngine->IsRunning();
// Draw the scene
ConqEngine->DrawScene();
updateTime = ConqEngine->Timer(); // Frame Timer
s1.pathfinderthread(ref(unitsneedpathfinding)) // this here, beginning of
if (menuloop)
{
initial_menu_loop(loaded_men_interface, menuloop, loadloop, infoloop ,textControl);
}
else if (loadloop)
{
preconqload(loadloop, gameloop, startingx, pipnumber);
}
else if (infoloop)
{
if (ConqEngine->AnyKeyHit())
{
ConqEngine->RemoveSprite(MainAB.LoadingSprite);
infoloop = false;
menuloop = true;
}
}
else if (gameloop)
{
if (game_n_setup)
{
SetupMusic("sound/RA2.ogg");
sMusic.play();
game_n_setup = false;
}
ConqCamera->LookAt(0, 0, 0);
CamLastFrame = CameraVec;
gameloop_interface(cspeed, CameraVec, displaycubes, dcubestime, CamLastFrame,
draycasttime, CitySprite, cityspriteno, wealthtick, myFont, myFont2, textControl);
gameloop_player(wealthtick, gameloop, menuloop);
gameloop_units();
//gameloop_interface()
if (ConqEngine->KeyHit(Key_Escape))
{
gameloop = false;
loadloop = false;
menuloop = false;
ConqEngine->Stop();
}
s1.join();
}
}
Currently what this attempts to do is that i have a bool for gameloop as a global, and a global[currently] lists of units needing pathfinding, and i am trying to execute the thread each frame seperately from the rest of the thing running, and then do a join at the end to force the program to wait for all to be completed but this causes a crash.
What is a good structure for multithreading my game with a pathing requester ? I'm honestly not sure how to tackle this the best way, I don't mind my Unit having to wait a few seconds, as that would look somewhat realistic anyway, a thinking animation is really no problem for me.
Is there a standard practice for seperating out the game loop with something else?