Я создаю программу-лабиринт, которая случайным образом генерирует путь.Я использую функцию бездействия, чтобы вычислить следующее направление и форму пути, но по какой-то причине функция бездействия не вызывается glutIdleFunc.Я проверил это с помощью отладчика Visual Studio и заставил его пройти по каждой строке кода.Когда отладчик попадает в «glutIdleFunc (idle)», он просто пропускает его, а не входит в функцию.
В предыдущей сборке вызывался режим ожидания, но логика в нем была неправильной, поэтому япришлось полностью переписать функцию простоя.Я избавился от некоторых глобальных переменных, которые мне больше не нужны, с помощью моей новой логики, но я не думаю, что они должны были повлиять на то, будет ли вызываться простоя.
Это - главная, которая вызывает glutIdleFunc.
//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char **argv){
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode
glutInitWindowSize(640,480); // set the window size
glutInitWindowPosition(100, 150); // set the window position on the screen
glutCreateWindow("Maze"); // open the screen window(with its exciting title)
glutDisplayFunc(myDisplay); // register the redraw function
myInit();
glutIdleFunc(idle); // IDLE FUNCTION IS CALLED HERE
glutMainLoop(); // go into a perpetual loop
}
Вот функция ожидания
void idle(){
int c; // holds column value for square
int r; // holds row value for square
if((done == false) && just_visited.empty()){
// initialize random seed
srand ( time(NULL) );
// randomly select first maze square indices
c = rand() % num_col + 1;
r = rand() % num_row + 1;
}
else if(done == false){
// set c and r to index values for last
// accessed block
c = just_visited.top().col;
r = just_visited.top().row;
vector<square> possible_paths;
bool open_path = false; // will set to true if there is an untouched adjacent square to move to
// will not exit loop until an open path is found or the maze has been completed
while(open_path != true || done != true){
// if statements check each adjacent square to see if they are possible_paths
// if they are then they get put into possible paths vector for access later
if(map[r][c].north == true && map[r+1][c].east == true && map[r+1][c].north == true && map[r+1][c-1].east == true){
possible_paths.push_back(map[r+1][c]);
open_path = true;
}
if(map[r][c].east == true && map[r][c+1].east == true && map[r][c+1].north == true && map[r-1][c+1].north == true){
possible_paths.push_back(map[r][c+1]);
open_path = true;
}
if(map[r-1][c].north == true && map[r-1][c].east == true && map[r-2][c].north == true && map[r-1][c-1].east == true){
possible_paths.push_back(map[r-1][c]);
open_path = true;
}
if(map[r][c-1].north == true && map[r][c-1].east == true && map[r][c-2].east == true && map[r-1][c].north == true){
possible_paths.push_back(map[r][c-1]);
open_path = true;
}
if(!open_path){ // if no direction around current square is open, backtrack in maze
just_visited.pop(); // pop last off the stack
if(just_visited.empty()){ // if stack is empty then the maze is done
done = true;
}
// set and c and r to new square values
c = just_visited.top().col;
r = just_visited.top().row;
}
} // end of while loop
if(!done && open_path){
//choose a direction to go
int dir = rand() % possible_paths.size();
if(possible_paths[dir].col > c){
map[c][r].east = false;
just_visited.push(map[c+1][r]);
}
else if(possible_paths[dir].col < c){
map[c-1][r].east = false;
just_visited.push(map[c-1][r]);
}
else if(possible_paths[dir].row > r){
map[c][r].north = false;
just_visited.push(map[c][r+1]);
}
else if(possible_paths[dir].row < r){
map[c][r-1].north = false;
just_visited.push(map[c][r-1]);
}
} // end of if statement
glutPostRedisplay();
} //end of if statement
} // end of idle
Кто-нибудь может мне помочь?Что я упускаю, делая неправильно, что простаивающий не вызывается?
(Также у меня возникают проблемы при вставке кода сюда из визуальных студий, форматирование очень запутано. Я использую Chrome для своего браузера)
Вот ссылка на мою полную папку проекта Visual Studio
http://dl.dropbox.com/u/15786901/Maze.rar