int main(int argc, char** argv) { try { // create game cft::GameConfig game_config; cft::Game game; game.CreateGame(game_config); #ifdef QT_CORE_LIB // create QT application QApplication app(argc, argv); cft::GameWidget game_widget(game); #endif // create game processing object and thread #ifdef QT_CORE_LIB GameProcessing game_processing(game, [&game_widget]() { game_widget.GameUpdated(); }); #else GameProcessing game_processing([]() { }); #endif boost::thread game_thread(game_processing); #ifdef QT_CORE_LIB // run qt application game_widget.show(); app.exec(); #endif // wait for thread game_thread.join(); return 0; } catch (cft::IntersectionException&) { std::cerr << "some objects intersect\n"; } catch (cft::WithinException&) { std::cerr << "some object is outside the field\n"; } catch (std::exception&) { std::cerr << "std::exception\n"; } catch (...) { std::cerr << "unkknown exception\n"; } return 1; }
void conn::conecta(std::string server,std::string port){ bot::team_id id = 1000; boost::asio::io_service io_service; tcp::resolver resolver(io_service); auto endpoint_iterator = resolver.resolve({ server, port }); std::shared_ptr<tcp::socket> socket(new tcp::socket(io_service)); boost::asio::connect(*socket, endpoint_iterator); bot::field_size field_width; bot::field_size field_height; int win_width = 500; int win_height = 500; bots Mundo; boost::mutex state_mutex; SDL_Init(SDL_INIT_VIDEO); atexit(SDL_Quit); SDL_WM_SetCaption("Superbots", "Superbots"); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); MYscreen.set_screen(win_width, win_height); SDL_Event event; bool gameover = false; bool connected = false; boost::thread t = boost::thread([this,socket, &state_mutex, &gameover, &connected, &Mundo, &id, &field_width, &field_height, &win_width, &win_height] () { game_thread(socket, gameover, Mundo, id, state_mutex, field_width, field_height, win_width, win_height, connected); } ); while (!gameover) { if(connected) { if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: gameover = true; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_q: gameover = true; break; default: break; } break; case SDL_VIDEORESIZE: win_width = event.resize.w; win_height = event.resize.h; MYscreen.set_screen(win_width, win_height, field_width, field_height); break; } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); { boost::mutex::scoped_lock lock(state_mutex); Mundo.for_each_bot([&Mundo] (const bot & the_bot) { auto t = the_bot.get_team() + 1; glColor3f(t * 0.2, 1 - t * 0.3, t * 0.1); const bot::position & pos = the_bot.get_position(); glLoadIdentity(); glTranslatef(pos.first, pos.second, 0); glBegin(GL_QUADS); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); }); } SDL_GL_SwapBuffers(); } } if(Mundo.bot_count().size() != 1) { std::cout << "Shit!" << std::endl; } else { for(auto inmortal : Mundo.bot_count()) { std::cout << inmortal.first << " se ha pulido a todos!" << std::endl; } } }