Click to See Complete Forum and Search --> : MFC OpenGL GALib


Arqueangel
July 23rd, 2009, 03:40 PM
Hello to anyone who decides to help a complete noob :D I have an application that has GALib added as a static library. I run the GA and generate points for plotting in a for loop as shown bellow:

while(!ga.done())
{
// Get the current values from the screen
UpdateData(TRUE);
ga.step();

//CSingleLock lock(&mutex);
//lock.Lock();
if(ga.generation() <= 10)
{
for(int i=0; i<ga.population().size(); i++)
{

genome = ga.population().individual(i);
//convert from float to string

sprintf( floatToString, "%g", genome.fitness());
strcpy (line,floatToString);
strcat (line,"\t");

for(int j=0;j<genome.nPhenotypes();j++)
{
strcat (line,"\t");
sprintf( floatToString, "%g", genome.phenotype(j));
strcat (line,floatToString);


}
strcat (line,"\t");
sprintf( floatToString, "%g", genome.score());
strcat (line,floatToString);
strcat (line,"\n");

//UpdateData(TRUE);
DoBohachevsky2(line, i);

//cout << line;

}

}
//Sleep(100);

//lock.Unlock();
}
// TODO: Add your control notification handler code here
}

The function "DoBohachevsky2(line, i);" basically sends the points over to OpenGL to be plotted. The problem I'm having is that the points are not plotted until the for loop and the while loop ends. I assumed that I would need to do some multithreading to get around this, but I am not quite sure how to do any of this as it is my first time ever. If any genius out there could shed some light as to how to get around this problem that would be great.

Arjay
July 27th, 2009, 11:35 AM
A couple of things:

Since you are running this in the UI thread, the UI thread is going to block until this loop has finished. That would prevent the UI from refreshing (and cause other problems as well).

You are calling UpdateData(...) each time in the loop - this causes the MFC DDX mechanism to fire which forces all the controls on the dialog to be read and their data transferred into variables. This is also overhead that you probably can do without in each loop iteration. Instead, call UpdateData(...) once before entering the loop.

Arqueangel
July 30th, 2009, 10:39 AM
Thank you very much I solve the problem with a message loop which was my first choice. Thank you for pointing that out too :D I dont suppose you have done any work with GALib?