int main(int argc, char *argv[]) { char buffWrite [BUFFSIZE]; unsigned short port1, port2; if(argc!=3) { fprintf(stderr, "Uso: %s <Port1> <Port2>\n",argv[0]); exit(1); } port1=atoi(argv[1]); port2=atoi(argv[2]); init_1(port1); init_2(port2); while(1) { fflush(stdout); fgets(buffWrite, BUFFSIZE, stdin); //Es necesario quitarle el ultimo caracter porque es un enter '\n' buffWrite[strlen(buffWrite)-1] = '\0'; if(strcmp("FIN", buffWrite)==0) break; } cerrarSocket_1(); cerrarSocket_2(); return 0; }
int main(int argc, char * argv[]) { int a = 1, b = 2, z1 = 3, z2 = 4, z3 = 5; void *handle0, *handle1; char *error; if (argc == 3) { a = atoi(argv[1]); b = atoi(argv[2]); } DynamicLoader load0("./closure_callee0"); DynamicLoader load1("./closure_callee1"); DynamicLoader load2("./closure_callee2"); DynamicLoader load3("./closure_callee3"); std::function<int (int)> init_0 = load0.load<int (int)>("callee_init"); std::function<int (int, int&, int*)> init_1 = load1.load<int (int, int&, int*)>("callee_init"); std::function<int (int, int&, int*)> init_3 = load3.load<int (int, int&, int*)>("create_callee"); std::function<int (void)> del_3 = load3.load<int (void)>("destroy_callee"); std::function<int (int, int)> callee_0 = load0.load<int (int, int)>("callee"); std::function<int (int, int)> callee_1 = load1.load<int (int, int)>("callee"); std::function<int (int, int)> callee_3 = load3.load<int (int, int)>("lam"); typedef std::function<int (int, int)> T_lam; std::function<int (T_lam, int, int)> callee_2 = load2.load<int (T_lam, int, int)>("callee"); init_0(z1); init_1(z1, z2, &z3); printf("<%s:%d> : z1 = %d, z2 = %d, z3 = %d\n", __FUNCTION__, __LINE__, z1, z2, z3); init_3(z1, z2, &z3); printf("<%s:%d> : z1 = %d, z2 = %d, z3 = %d\n", __FUNCTION__, __LINE__, z1, z2, z3); callee_0(a, b); callee_1(a, b); // callee_3(a, b); callee_2(callee_0, a, b); callee_2(callee_1, a, b); printf("<%s:%d> : z1 = %d, z2 = %d, z3 = %d\n", __FUNCTION__, __LINE__, z1, z2, z3); callee_2(callee_3, a, b); printf("<%s:%d> : z1 = %d, z2 = %d, z3 = %d\n", __FUNCTION__, __LINE__, z1, z2, z3); del_3(); load0.close(); load1.close(); load2.close(); load3.close(); return 0; }
void calccompprog_1(char *host) { CLIENT *clnt; int *result_1; complexe add_1_arg; int *result_2; complexe mul_1_arg; void *result_3; complexe init_1_arg; #ifndef DEBUG clnt = clnt_create (host, CALCCOMPPROG, CALCVERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ add_1_arg.pentiere = 2; add_1_arg.pimaginaire = 0.5; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } mul_1_arg.pentiere = 3; mul_1_arg.pimaginaire = 1.5; result_2 = mul_1(&mul_1_arg, clnt); if (result_2 == (int *) NULL) { clnt_perror (clnt, "call failed"); } init_1_arg.pentiere = 4; init_1_arg.pimaginaire = 2.5; result_3 = init_1(&init_1_arg, clnt); if (result_3 == (void *) NULL) { clnt_perror (clnt, "call failed"); } printf("ADD result : %d", *result_1); printf("MUL result : %d", *result_2); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
int fightPlayer (getThetaFunction (*init_1)(const Game, void *), getThetaFunction (*init_2)(const Game, void *), void * arg1, void * arg2, char isGUI) { srand(clock()); Game game = game_new_game (); char newTheta_1, newTheta_2; clock_t delay, t = clock (); if (isGUI) initGUI (); getThetaFunction getTheta1 = init_1 (game, arg1); getThetaFunction getTheta2 = init_2 (game, arg2); while (!game->won) { if (isGUI && getEvent () == -1) break; newTheta_1 = (*getTheta1) (game, arg1); newTheta_1 = (newTheta_1 > 0 ? 1 : newTheta_1 == 0 ? 0 : -1); newTheta_2 = (*getTheta2) (game, arg2); newTheta_2 = (newTheta_2 > 0 ? 1 : newTheta_2 == 0 ? 0 : -1); game_update_game (game, newTheta_1, newTheta_2); if (isGUI) { delay = clock(); if ((delay - t) * IMAGES_PER_SEC < CLOCKS_PER_SEC) { struct timespec ts = {0, (1000 / IMAGES_PER_SEC - (delay - t) * 1000 / CLOCKS_PER_SEC) * 1000000}; nanosleep (&ts, NULL); } draw (game); t = clock (); } } int r = game->won; if (isGUI) quitGUI (); game_free_game (game); return r; }
void calcprog_1(char *host) { CLIENT *clnt; int *result_1; int add_1_arg; int *result_2; int mul_1_arg; void *result_3; int init_1_arg; #ifndef DEBUG clnt = clnt_create (host, CALCPROG, CALCVERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ init_1_arg = 100; result_3 = init_1(&init_1_arg, clnt); if (result_3 == (void *) NULL) { clnt_perror (clnt, "call failed"); } printf ("init fait: \n"); add_1_arg = 12; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } printf ("resul: %d \n", *result_1); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
//----------------------------------------------------------------------------- // Name: WinMain() // Desc: The application's entry point //----------------------------------------------------------------------------- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASSEX winClass; MSG uMsg; bool deviceReset = FALSE; memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WindowProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON); winClass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.lpszMenuName = NULL; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; if(!RegisterClassEx( &winClass) ) return E_FAIL; // // Create window #0... // g_hWnd_0 = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", "Direct3D (DX9) - Multiple Devices (Window #0)", WS_EX_TOPMOST | WS_POPUP, // fullscreen values /* WS_OVERLAPPEDWINDOW | WS_VISIBLE,*/ 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL ); if( g_hWnd_0 == NULL ) return E_FAIL; ShowWindow( g_hWnd_0, nCmdShow ); UpdateWindow( g_hWnd_0 ); #ifdef TWO // // Create window #1... // g_hWnd_1 = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", "Direct3D (DX9) - Multiple Devices (Window #1)", WS_EX_TOPMOST | WS_POPUP, // fullscreen values /* WS_OVERLAPPEDWINDOW | WS_VISIBLE,*/ 1920, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL ); if( g_hWnd_1 == NULL ) return E_FAIL; ShowWindow( g_hWnd_1, nCmdShow ); UpdateWindow( g_hWnd_1 ); #endif // // Init Direct3D usage on both windows... // init_0(); #ifdef TWO init_1(); #endif ResetDevice(); // Important !!! LoadModels(); while( uMsg.message != WM_QUIT ) { if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &uMsg ); DispatchMessage( &uMsg ); } else { g_dCurrentTime = timeGetTime(); g_dElpasedFrameTime = g_dCurrentTime - g_dLastTime; // How much time has passed since the last frame? g_dElpasedAppTime += g_dElpasedFrameTime; // How much time has passed overall for the application? g_dLastTime = g_dCurrentTime; render_0(); #ifdef TWO render_1(); #endif } } // // Cleanup Direct3D usage on both windows... // #ifdef TWO shutDown_1(); #endif shutDown_0(); UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance ); return uMsg.wParam; }