void	idle(void)
{
	if (!time_frame())
	{
		if (g_env->keys & FLAG_RIGHT)
			g_env->camtrans[0] += -0.2;
		if (g_env->keys & FLAG_LEFT)
			g_env->camtrans[0] += 0.2;
		if (g_env->keys & FLAG_UP)
			g_env->camtrans[2] += 0.2;
		if (g_env->keys & FLAG_DOWN)
			g_env->camtrans[2] += -0.2;
		glutPostRedisplay();
	}
}
Exemple #2
0
void server_main(int argc, char* argv[])
{
  ///////////////////////////////////////////////////////////////
  //set up global data structures
  Syncronizer<Env::K>                       syncronizer;
  std::cout <<"before env"<<std::endl;
  Env                                       env(argc,argv);
  std::cout <<"after env"<<std::endl;


  Time_frame::Interval_color                player_a_color = PLAYER_A_COLOR;
  Time_frame::Interval_color                player_b_color = PLAYER_B_COLOR;
  Time_frame                                time_frame( player_a_color, //player a is red
                                                        get_colored_sleep_time());
  File_names                                file_names(&time_frame);
  Targets_manager                           target_configurations_manager(env.get_target_configurations(),
                                                                          env.get_additional_target_configurations());
  Additional_target_configurations_manager  additional_target_configurations_manager(5,&time_frame); //add additional targets at fifth interval
                                                                                    
  Robot_location                            robot_location_a(env.get_source_configuration_a());
  Robot_location                            robot_location_b(env.get_source_configuration_b());
  Writen_paths_filenames                    writen_paths_filenames_a;
  Writen_paths_filenames                    writen_paths_filenames_b;

  Safe_bool									is_game_over(false);
  Result                                    result;

  ///////////////////////////////////////////////////////////////
  //set up sockets 
  Socket* socket_g= set_up_connection__gui(robot_location_a, robot_location_b, &target_configurations_manager);
#if USE_PLAYER_A
  Socket* socket_a= set_up_connection__player_a();
#endif //USE_PLAYER_A
#if USE_PLAYER_B   
  Socket* socket_b= set_up_connection__player_b();   
#endif //USE_PLAYER_B

  ///////////////////////////////////////////////////////////////
  //set up request handlers
#if USE_PLAYER_A
  Client_request_handler request_handler_a;
  request_handler_a.start(socket_a, player_a_color,
                          &time_frame, &file_names,
                          &additional_target_configurations_manager,
                          &writen_paths_filenames_a,
                          &robot_location_b,
						  &is_game_over);
  
#endif //USE_PLAYER_A
#if USE_PLAYER_B
  Client_request_handler request_handler_b;
  request_handler_b.start(socket_b, player_b_color,
                          &time_frame, &file_names,
                          &additional_target_configurations_manager,
                          &writen_paths_filenames_b,
                          &robot_location_a,
						  &is_game_over);
#endif //USE_PLAYER_B

  ///////////////////////////////////////////////////////////////
  //start up syncronizer

  std::cout <<"in main thread : " <<boost::this_thread::get_id()<<std::endl;
  std::cout <<"before synchronizer"<<std::endl<<std::endl;

  syncronizer.start(&time_frame, &env, &result, socket_g,
                    &target_configurations_manager,
                    &additional_target_configurations_manager,
                    &robot_location_a, &robot_location_b,
                    &writen_paths_filenames_a, &writen_paths_filenames_b,
					&is_game_over);
  
  syncronizer.join();
  
  std::cout <<"player a score: " 
            <<result.first 
            <<"player b score: "
            <<result.second 
            <<std::endl;
  
#if USE_PLAYER_A
  request_handler_a.join();
#endif //USE_PLAYER_A
#if USE_PLAYER_B
  request_handler_b.join();
#endif //USE_PLAYER_B

  end_connection__gui(socket_g);
  
  return ;
}