int main() { SetupAll(); SetupBalls(); DoTimers(); LoadBitmaps(); DoBlock(); while (!key[KEY_ESC] && GoGame == 1) { CheckDead(); CheckBlock(); MoveBall(); if (BallsToDrop > 0) DropBalls(); if (Lives <= 0) GoGame = 0; DrawBack(); CheckExplode(); DrawBalls(); MoveMouse(); MoveStoneBlock(); WaitTimer(); flip(); } EndOfGame(); allegro_exit(); //Clean up allegro return 0; }
/** マウスカーソルの移動 */ int CSunApp::MoveMouse(int x,int y) { RECT rect; ::GetWindowRect(m_hWnd,&rect); MoveMouse(rect.left + x, rect.right + y); return 1; }
InputProvider::InputProvider () : display (NULL), root_window (0), xtest_available (false), down_keys (NULL) { display = XOpenDisplay (NULL); if (!display) { printf ("Unable to open XDisplay, input tests will not run.\n"); return; } // I guess we'll assume there is only one screen root_window = XRootWindow (display, 0); if (root_window <= 0) { printf ("Unable to get the root window, some of the input tests will not run.\n"); return; } int event_base, error_base, majorp, minorp; if (!XTestQueryExtension (display, &event_base, &error_base, &majorp, &minorp)) { printf ("XTEST Extension unavailable, input tests will not run.\n"); return; } xtest_available = true; keyboard_speed = 10; SendKeyInput (VK_NUMLOCK, true, false, false); MoveMouse (0,0); }
void solve() { MOUSEMSG m; long i,j,k,r,w,x,y; long nowx=-1,nowy=-1; while(1) { m = GetMouseMsg(); x = ( m.x - (BL-SIDE/2) ) / SIDE; y = ( m.y - (BH-SIDE/2) ) / SIDE; if( ok(x,y) ) { switch(m.uMsg) { case WM_MOUSEMOVE: //移动 if( nowx != x || nowy != y ) MoveMouse(x,y); break; case WM_LBUTTONDOWN: //按下 PressMouse(x,y); Computer(); break; } nowx = x; nowy = y; if( Pan() ) break; } } End(); }
void Thread( void* pParams ) { while ( 1 ) { MoveMouse(); Sleep(60000); //Sleep(600); } }
void MAS::Window::MsgLostmouse() { Dialog::MsgLostmouse(); SetCursor(Skin::MOUSE_NORMAL); if ((extraFlags & W_AUTOROLLUP) && !(extraFlags & W_MINIMIZED)) { Minimize(); UpdateWindowProperties(); } MoveMouse(mouseObject, NULL); }
extern "C" _declspec(dllexport) void __cdecl SleepAndMoveMouse( int atime ) { bool Moving = false; int mx = 0, my = 0; float x = 0.0, y = 0.0, xv = 0.0, yv = 0.0; float gx = 0.0, gy = 0.0; srand(time(NULL)); GetMousePosition( mx, my ); x = mx; y = my; if ( rand()%( 2 ) == 0 ) Moving = false; else Moving = true; gx = 130 + rand()% 500; gy = 130 + rand()% 300; DWORD T = GetTickCount(); do { Sleep( 10 ); if ( Moving ) { if ( gx > x ) xv = xv + 0.1; else xv = xv - 0.1; if ( gy > y ) yv = yv + 0.1; else yv = yv - 0.1; x = x + xv; y = y + yv; MoveMouse( rnd( x ), rnd( y ) ); } if ( rand()% 100 == 0 ) Moving = ! Moving; if ( rand()% 30 == 0 ) { gx = 130 + rand()% 500 ; gy = 130 + rand()% 300 ; } } while ( ! ( abs( int(GetTickCount() - T) ) >= atime ) ); }
/** Run a menu action. */ void RunTaskBarCommand(MenuAction *action, unsigned button) { ClientEntry *cp; if(action->type & MA_GROUP_MASK) { TaskEntry *tp = action->context; for(cp = tp->clients; cp; cp = cp->next) { if(!ShouldFocus(cp->client, 0)) { continue; } switch(action->type & ~MA_GROUP_MASK) { case MA_SENDTO: SetClientDesktop(cp->client, action->value); break; case MA_CLOSE: DeleteClient(cp->client); break; case MA_RESTORE: RestoreClient(cp->client, 0); break; case MA_MINIMIZE: MinimizeClient(cp->client, 0); break; default: break; } } } else if(action->type == MA_EXECUTE) { if(button == Button3) { Window w; int x, y; GetMousePosition(&x, &y, &w); ShowWindowMenu(action->context, x, y, 0); } else { ClientNode *np = action->context; RestoreClient(np, 1); FocusClient(np); MoveMouse(np->window, np->width / 2, np->height / 2); } } else { RunWindowCommand(action, button); } }
void solve() { MOUSEMSG m; long i,j,k,r,w,x,y,ox=-1,oy=-1; long nowx=-1,nowy=-1; while(1) { m = GetMouseMsg(); x = ( m.x - (BL-SIDE/2) ) / SIDE; y = ( m.y - (BH-SIDE/2) ) / SIDE; if( ok(x,y) ) { switch(m.uMsg) { case WM_MOUSEMOVE: //移动 if( nowx != x || nowy != y ) MoveMouse(x,y,nowx,nowy); break; case WM_LBUTTONDOWN: //按下 if(map[y][x] != 0) break; PressMouse(x,y); over = 0; if(Pan())break; k = Max(1,-MAXN-3,MAXN+3); if(k >= MAXN ) over =2; if(k <= -MAXN ) { /*over =1; */ Xia(); } ComXia(xx,yy); break; } nowx = x; nowy = y; if( Pan() ) break; } } End(); }
void InputBoard::HandleMessage( const SDL_Event& event ) { switch( event.type ) { case SDL_MOUSEMOTION: MoveMouse( event.motion ); break; case SDL_KEYDOWN: Strike( event.key, ZOYAINPUT_STRIKEDOWN ); break; case SDL_KEYUP: Strike( event.key, ZOYAINPUT_STRIKEUP ); break; case SDL_MOUSEBUTTONDOWN: StrikeMouse( event.button, ZOYAINPUT_STRIKEDOWN ); break; case SDL_MOUSEBUTTONUP: StrikeMouse( event.button, ZOYAINPUT_STRIKEUP ); break; case SDL_MOUSEWHEEL: ScrollMouse( event.wheel ); break; } }
static void on_button1_clicked(GtkButton* button, gpointer data) { /* cast the data back to a char* */ char* txt = (char*)data; /*button activate*/ gtk_widget_set_sensitive(button1, FALSE); gtk_widget_set_sensitive(button2, TRUE); buttonflag = 1; while(buttonflag == 1) { memset(&readbuf, 0, MAXBUF); //make server socket if((ssock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("Failed to make socket discriptor"); exit(1); } clen = sizeof(client_addr); //setting address structure memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(9999); //binding if(bind(ssock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Failed to binding server socket"); exit(1); } //wait for client if(listen(ssock, 8) <0 ) { perror("listen error : "); exit(1); } while(1) { csock = accept(ssock, (struct sockaddr *)&client_addr, &clen); i++; //if(write(csock, buf, MAXBUF) <= 0) // perror("Writing error : "); if(read(csock, readbuf, MAXBUF) < 0) perror("Reading error : "); fprintf(stderr, "[client] %s\n", readbuf); result=parsing(readbuf,x,y,z); if(result == 888) clickMouse(1); if(result == 999) clickMouse(3); if(result != 999){ scaledata(x); scaledata(y); scaledata(z); //printf("sa----- %s %s %s\n ",x,y,z); MoveMouse(z,x); } close(csock); } } printf("open_button_clicked - '%s'\n", txt); fflush(stdout); }
extern "C" _declspec(dllexport) void __cdecl BrakeWindMouse( float xs, float ys, float xe, float ye, float gravity, float wind, float minWait, float maxWait, float targetArea ) { float veloX = 0.0, veloY = 0.0, windX = 0.0, windY = 0.0, veloMag = 0.0, dist = 0.0, randomDist = 0.0; int lastX = 0, lastY = 0, MSP = 0, W = 0, maxStep = 0, D = 0, TDist = 0; float sqrt2 = 0.0, sqrt3 = 0.0, sqrt5 = 0.0, PDist = 0.0; veloX = 0; veloY = 0; windX = 0; windY = 0; MSP = MouseSpeed; sqrt2 = sqrt( 2 ); sqrt3 = sqrt( 3 ); sqrt5 = sqrt( 5 ); srand(time(NULL)); TDist = Distance( rnd( xs ), rnd( ys ), rnd( xe ), rnd( ye ) ); if ( TDist < 1 ) TDist = 1; do { dist = hypot( xs - xe, ys - ye ); wind = Min( wind, dist ); if ( dist < 1 ) dist = 1; PDist = ( dist / TDist ); if ( PDist < 0.01 ) PDist = 0.01; /* These constants seem smooth to me, but feel free to modify these settings however you wish. */ if ( PDist >= 0.15 ) //15% (or higher) dist to destination { D = rnd( rnd( ( rnd( dist ) * 0.3 ) ) / 5 ); if ( D < 20 ) D = 20; //D := RandomRange(15, 25); {Original} } else if ( PDist < 0.15 ) { if ( ( PDist <= 0.15 ) && ( PDist >= 0.10 ) ) //10%-15% D = RandomRange( 8, 13 ); else if ( PDist < 0.10 ) //< 10% D = RandomRange( 4, 7 ); } if ( D <= rnd( dist ) ) maxStep = D; else maxStep = rnd( dist ); if ( dist >= targetArea ) { windX = windX / sqrt3 + ( rand()% rnd( wind ) * 2 + 1 - wind ) / sqrt5; windY = windY / sqrt3 + ( rand()% rnd( wind ) * 2 + 1 - wind ) / sqrt5; } else { windX = windX / sqrt2; windY = windY / sqrt2; } veloX = veloX + windX; veloY = veloY + windY; veloX = veloX + gravity * ( xe - xs ) / dist; veloY = veloY + gravity * ( ye - ys ) / dist; if ( hypot( veloX, veloY ) > maxStep ) { randomDist = maxStep / 2.0 + rand()% rnd( maxStep ) / 2 ; veloMag = sqrt( veloX * veloX + veloY * veloY ); veloX = ( veloX / veloMag ) * randomDist; veloY = ( veloY / veloMag ) * randomDist; } lastX = rnd( xs ); lastY = rnd( ys ); xs = xs + veloX; ys = ys + veloY; if ( ( lastX != rnd( xs ) ) || ( lastY != rnd( ys ) ) ) MoveMouse( rnd( xs ), rnd( ys ) ); W = ( rand()% rnd( 100 / MSP ) ) * 6; if ( W < 5 ) W = 5; W = rnd( W * 1.2 ); Sleep( W ); // lastDist = dist; } while ( ! ( hypot( xs - xe, ys - ye ) < 1 ) ); if ( ( rnd( xe ) != rnd( xs ) ) || ( rnd( ye ) != rnd( ys ) ) ) MoveMouse( rnd( xe ), rnd( ye ) ); MouseSpeed = MSP; }
extern "C" _declspec(dllexport) void __cdecl ShiftWindMouse( float xs, float ys, float xe, float ye, float gravity, float wind, float minWait, float maxWait, float maxStep, float targetArea ) { float veloX = 0.0, veloY = 0.0, windX = 0.0, windY = 0.0, veloMag = 0.0, dist = 0.0, randomDist = 0.0, step = 0.0; int lastX = 0, lastY = 0, MS = 0; float sqrt2 = 0.0, sqrt3 = 0.0, sqrt5 = 0.0; veloX = 0; veloY = 0; windX = 0; windY = 0; srand(time(NULL)); MS = MouseSpeed; sqrt2 = sqrt( 2 ); sqrt3 = sqrt( 3 ); sqrt5 = sqrt( 5 ); while ( hypot( xs - xe, ys - ye ) > 1 ) { dist = hypot( xs - xe, ys - ye ); wind = Min( wind, dist ); if ( dist >= targetArea ) { windX = windX / sqrt3 + ( rand()% rnd( wind ) * 2 + 1 - wind ) / sqrt5; windY = windY / sqrt3 + ( rand()% rnd( wind ) * 2 + 1 - wind ) / sqrt5; } else { windX = windX / sqrt2; windY = windY / sqrt2; if ( maxStep < 3 ) { maxStep = rand()% 3 + 3.0; } else { maxStep = maxStep / sqrt5; } } veloX = veloX + windX; veloY = veloY + windY; veloX = veloX + gravity * ( xe - xs ) / dist; veloY = veloY + gravity * ( ye - ys ) / dist; if ( hypot( veloX, veloY ) > maxStep ) { randomDist = maxStep / 2.0 + rand()% rnd( maxStep ) / 2 ; veloMag = sqrt( veloX * veloX + veloY * veloY ); veloX = ( veloX / veloMag ) * randomDist; veloY = ( veloY / veloMag ) * randomDist; } lastX = rnd( xs ); lastY = rnd( ys ); xs = xs + veloX; ys = ys + veloY; switch ( rand()% 2 ) { case 1: MouseSpeed = ( MS + ( RandomRange( 2, 5 ) ) ); break; case 2: MouseSpeed = ( MS - ( RandomRange( 2, 5 ) ) ); break; } if ( MouseSpeed < 4 ) MouseSpeed = 4; if ( ( lastX != rnd( xs ) ) || ( lastY != rnd( ys ) ) ) MoveMouse( rnd( xs ), rnd( ys ) ); step = hypot( xs - lastX, ys - lastY ); Sleep( rnd( ( maxWait - minWait ) * ( step / maxStep ) + minWait ) ); // lastDist = dist; MouseSpeed = MS; } switch ( rand()% 2 ) { case 1: MouseSpeed = ( MS + ( RandomRange( 2, 5 ) ) ); break; case 2: MouseSpeed = ( MS - ( RandomRange( 2, 5 ) ) ); break; } if ( MouseSpeed < 4 ) MouseSpeed = 4; if ( ( rnd( xe ) != rnd( xs ) ) || ( rnd( ye ) != rnd( ys ) ) ) MoveMouse( rnd( xe ), rnd( ye ) ); MouseSpeed = MS; }
int main(int argc, const char* argv[]) { int time = 0; int ssock, csock; int clen; struct sockaddr_in client_addr, server_addr; char buf[MAXBUF] = "Im server connecting success."; char readbuf[MAXBUF]; memset(&readbuf, 0, MAXBUF); int i=0; int idx=0; char x[10]={0,}; char y[10]={0,}; char z[10]={0,}; //make server socket if((ssock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("Failed to make socket discriptor"); exit(1); } clen = sizeof(client_addr); //setting address structure memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(9999); //binding if(bind(ssock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Failed to binding server socket"); exit(1); } //wait for client if(listen(ssock, 8) <0 ) { perror("listen error : "); exit(1); } while(1) { csock = accept(ssock, (struct sockaddr *)&client_addr, &clen); i++; //if(write(csock, buf, MAXBUF) <= 0) // perror("Writing error : "); if(read(csock, readbuf, MAXBUF) < 0) perror("Reading error : "); fprintf(stderr, "[client] %s\n", readbuf); parsing(readbuf,x,y,z); scaledata(x); scaledata(y); scaledata(z); //printf("sa----- %s %s %s\n ",x,y,z); MoveMouse(z,x); close(csock); } return 0; }
int soko_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; Fx2ShowPig( 540, 450, 120, 90 ); ladeVerzeichnis(); Startbildschirm(); while( doexit != 3 ) { doexit=0; BoardInitialize(); #ifdef USEX FBFlushGrafic(); #endif if ( doexit == 4 ) /* fx2 - install error: no level found */ { doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } break; } while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); MoveMouse(); } if ( doexit != 3 ) { actcode=0xee; if ( doexit ==2 ) DrawScore(); else DrawGameOver(); if (level+1 < max_level) { level++; } else { level = 0; } doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } } } Fx2StopPig(); /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } RcClose(); FBClose(); freeMem(); return 0; }
/** Move a client window (keyboard or menu initiated). */ char MoveClientKeyboard(ClientNode *np) { XEvent event; int oldx, oldy; int moved; int height; int north, south, east, west; MaxFlags maxFlags; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } maxFlags = np->state.maxFlags; if(np->state.maxFlags != MAX_NONE) { MaximizeClient(np, MAX_NONE); } if(JUNLIKELY(JXGrabKeyboard(display, np->parent, True, GrabModeAsync, GrabModeAsync, CurrentTime))) { Debug("MoveClient: could not grab keyboard"); return 0; } GrabMouseForMove(); GetBorderSize(&np->state, &north, &south, &east, &west); oldx = np->x; oldy = np->y; RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; CreateMoveWindow(np); UpdateMoveWindow(np); MoveMouse(rootWindow, np->x, np->y); DiscardMotionEvents(&event, np->window); if(np->state.status & STAT_SHADED) { height = 0; } else { height = np->height; } for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return 1; } moved = 0; if(event.type == KeyPress) { DiscardKeyEvents(&event, np->window); switch(GetKey(&event.xkey) & 0xFF) { case KEY_UP: if(np->y + height > 0) { np->y -= 10; } break; case KEY_DOWN: if(np->y < rootHeight) { np->y += 10; } break; case KEY_RIGHT: if(np->x < rootWidth) { np->x += 10; } break; case KEY_LEFT: if(np->x + np->width > 0) { np->x -= 10; } break; default: StopMove(np, 1, oldx, oldy, maxFlags); return 1; } MoveMouse(rootWindow, np->x, np->y); DiscardMotionEvents(&event, np->window); moved = 1; } else if(event.type == MotionNotify) { DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x; np->y = event.xmotion.y; moved = 1; } else if(event.type == ButtonRelease) { StopMove(np, 1, oldx, oldy, maxFlags); return 1; } if(moved) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); DrawOutline(np->x - west, np->y - west, np->width + west + east, height + north + west); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); RequirePagerUpdate(); } } }
/** Move a client window. */ char MoveClient(ClientNode *np, int startx, int starty, int snap) { XEvent event; int oldx, oldy; int doMove; int north, south, east, west; int height; int hmax, vmax; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } GrabMouseForMove(); RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; oldx = np->x; oldy = np->y; vmax = 0; hmax = 0; if(!(GetMouseMask() & (Button1Mask | Button2Mask))) { StopMove(np, 0, oldx, oldy, 0, 0); return 0; } GetBorderSize(&np->state, &north, &south, &east, &west); startx -= west; starty -= north; currentClient = np; atTop = 0; atBottom = 0; atLeft = 0; atRight = 0; doMove = 0; for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return doMove; } switch(event.type) { case ButtonRelease: if(event.xbutton.button == Button1 || event.xbutton.button == Button2) { StopMove(np, doMove, oldx, oldy, hmax, vmax); return doMove; } break; case MotionNotify: DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x_root - startx; np->y = event.xmotion.y_root - starty; GetCurrentTime(&moveTime); atLeft = 0; atTop = 0; atRight = 0; atBottom = 0; if(event.xmotion.x_root == 0) { atLeft = 1; } else if(event.xmotion.x_root == rootWidth - 1) { atRight = 1; } if(event.xmotion.y_root == 0) { atTop = 1; } else if(event.xmotion.y_root == rootHeight - 1) { atBottom = 1; } if(snap) { DoSnap(np); } if(!doMove && (abs(np->x - oldx) > MOVE_DELTA || abs(np->y - oldy) > MOVE_DELTA)) { if(np->state.status & (STAT_HMAX | STAT_VMAX)) { if(np->state.status & STAT_HMAX) { hmax = 1; } if(np->state.status & STAT_VMAX) { vmax = 1; } MaximizeClient(np, 0, 0); startx = np->width / 2; starty = -north / 2; MoveMouse(np->parent, startx, starty); } CreateMoveWindow(np); doMove = 1; } if(doMove) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); height = north + south; if(!(np->state.status & STAT_SHADED)) { height += np->height; } DrawOutline(np->x - west, np->y - north, np->width + west + east, height); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); UpdatePager(); } break; default: break; } } }
void GameLoop( sf::RenderWindow &app, bool &bczyGra, bool &bMenu ) { ResetGame(); bool pauseGame = false; sf::Mouse::setPosition( sf::Vector2i( Width / 2, Height / 2 ), app ); app.setMouseCursorVisible( false ); sounds[2].play(); while ( bczyGra ) { LoopTime = TimeLoop.GetElapsedSeconds(); TimeLoop.Reset(); sf::Event event; while (app.pollEvent(event)) { if (event.type == sf::Event::Closed) { bczyGra = false; bMenu = false; app.close(); } else if (event.type == sf::Event::Resized) { ChangeSize( event.size.width, event.size.height ); } else if ( ( event.type == sf::Event::KeyReleased ) && ( event.key.code == sf::Keyboard::Escape ) ){ bczyGra = false; bMenu = true; } if ( ( ( event.type == sf::Event::JoystickButtonReleased ) && ( event.joystickButton.button == 0 ) ) || ( event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::P ) ){ pauseGame = !pauseGame; if ( pauseGame == true ) { app.setMouseCursorVisible( true ); sounds[2].pause(); } else { sf::Mouse::setPosition( sf::Vector2i( Width / 2, Height / 2 ), app ); app.setMouseCursorVisible( false ); LoopTime = 0.0f; TimeLoop.Reset(); sounds[2].play(); } } } KeyControl( LoopTime, app ); if ( !pauseGame ) { MoveMouse( sf::Mouse::getPosition( app ).x, sf::Mouse::getPosition( app ).y, app ); MouseControl( LoopTime ); Joystick( LoopTime, app ); if ( Player.getLife() < 0 ) { bczyGra = false; bMenu = true; } Logika( LoopTime ); RenderScene(); app.display(); } } sounds[2].stop(); hud.sendScore(); }
int mines_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; while( doexit != 3 ) { BoardInitialize(); DrawBoard( 0 ); Fx2ShowPig( 470, 300, 176, 144 ); doexit=0; while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); MoveMouse(); #ifdef USEX FBFlushGrafic(); #endif } if ( doexit != 3 ) { actcode=0xee; if ( doexit ==2 ) DrawScore(); else DrawGameOver(); #ifdef USEX FBFlushGrafic(); #endif doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } } } Fx2StopPig(); /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } RcClose(); FBClose(); return 0; }
extern "C" _declspec(dllexport) void __cdecl WindMouse( float xs, float ys, float xe, float ye, float gravity, float wind, float minWait, float maxWait, float maxStep, float targetArea ) { float veloX = 0.0, veloY = 0.0, windX = 0.0, windY = 0.0, veloMag = 0.0, dist = 0.0, randomDist = 0.0, step = 0.0; int lastX = 0, lastY = 0; float sqrt2 = 0.0, sqrt3 = 0.0, sqrt5 = 0.0; veloX = 0; veloY = 0; windX = 0; windY = 0; srand (static_cast <unsigned> (time(0))); try { sqrt2 = sqrt( 2 ); sqrt3 = sqrt( 3 ); sqrt5 = sqrt( 5 ); while ( hypot( xs - xe, ys - ye ) > 1 ) { dist = hypot( xs - xe, ys - ye ); wind = Min( wind, dist ); if ( dist >= targetArea ) { windX = windX / sqrt3 + (Random() * (wind * 2.0 + 1.0) - wind) / sqrt5; windY = windY / sqrt3 + (Random() * (wind * 2.0 + 1.0) - wind) / sqrt5; } else { windX = windX / sqrt2; windY = windY / sqrt2; if ( maxStep < 3 ) { maxStep = Random() * 3 + 3.0; } else { maxStep = maxStep / sqrt5; } } veloX = veloX + windX; veloY = veloY + windY; veloX = veloX + gravity * ( xe - xs ) / dist; veloY = veloY + gravity * ( ye - ys ) / dist; if ( hypot( veloX, veloY ) > maxStep ) { randomDist = maxStep / 2.0 + Random() * maxStep / 2.0; veloMag = sqrt( veloX * veloX + veloY * veloY ); veloX = ( veloX / veloMag ) * randomDist; veloY = ( veloY / veloMag ) * randomDist; } lastX = rnd( xs ); lastY = rnd( ys ); xs = xs + veloX; ys = ys + veloY; if ( ( lastX != rnd( xs ) ) || ( lastY != rnd( ys ) ) ) MoveMouse( rnd( xs ), rnd( ys ) ); step = hypot( xs - lastX, ys - lastY ); Sleep( rnd( ( maxWait - minWait ) * ( step / maxStep ) + minWait ) ); // lastDist = dist; } if ( ( rnd( xe ) != rnd( xs ) ) || ( rnd( ye ) != rnd( ys ) ) ) MoveMouse( rnd( xe ), rnd( ye ) ); } catch(...) { } }
/** Move a client window. */ char MoveClient(ClientNode *np, int startx, int starty) { XEvent event; int oldx, oldy; int doMove; int north, south, east, west; int height; MaxFlags maxFlags; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } GrabMouseForMove(); RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; oldx = np->x; oldy = np->y; maxFlags = np->state.maxFlags; if(!(GetMouseMask() & (Button1Mask | Button2Mask))) { StopMove(np, 0, oldx, oldy, maxFlags); return 0; } GetBorderSize(&np->state, &north, &south, &east, &west); startx -= west; starty -= north; currentClient = np; atTop = atBottom = atLeft = atRight = 0; doMove = 0; for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return doMove; } switch(event.type) { case ButtonRelease: if(event.xbutton.button == Button1 || event.xbutton.button == Button2) { StopMove(np, doMove, oldx, oldy, maxFlags); return doMove; } break; case MotionNotify: DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x_root - startx; np->y = event.xmotion.y_root - starty; /* Get the move time used for desktop switching. */ if(!(atLeft | atTop | atRight | atBottom)) { if(event.xmotion.state & Mod1Mask) { moveTime.seconds = 0; moveTime.ms = 0; } else { GetCurrentTime(&moveTime); } } /* Determine if we are at a border for desktop switching. */ atLeft = atTop = atRight = atBottom = 0; if(event.xmotion.x_root == 0) { atLeft = 1; } else if(event.xmotion.x_root == rootWidth - 1) { atRight = 1; } if(event.xmotion.y_root == 0) { atTop = 1; } else if(event.xmotion.y_root == rootHeight - 1) { atBottom = 1; } if(event.xmotion.state & Mod1Mask) { /* Switch desktops immediately if alt is pressed. */ if(atLeft | atRight | atTop | atBottom) { TimeType now; GetCurrentTime(&now); UpdateDesktop(&now); } } else { /* If alt is not pressed, snap to borders. */ DoSnap(np); } if(!doMove && (abs(np->x - oldx) > MOVE_DELTA || abs(np->y - oldy) > MOVE_DELTA)) { if(np->state.maxFlags) { MaximizeClient(np, MAX_NONE); startx = np->width / 2; starty = -north / 2; MoveMouse(np->parent, startx, starty); } CreateMoveWindow(np); doMove = 1; } if(doMove) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); height = north + south; if(!(np->state.status & STAT_SHADED)) { height += np->height; } DrawOutline(np->x - west, np->y - north, np->width + west + east, height); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); RequirePagerUpdate(); } break; default: break; } } }
int CApplication::Run() { m_active = true; GetSystemUtils()->GetCurrentTimeStamp(m_baseTimeStamp); GetSystemUtils()->GetCurrentTimeStamp(m_lastTimeStamp); GetSystemUtils()->GetCurrentTimeStamp(m_curTimeStamp); MoveMouse(Math::Point(0.5f, 0.5f)); // center mouse on start while (true) { ResetPerformanceCounters(); if (m_active) { StartPerformanceCounter(PCNT_ALL); StartPerformanceCounter(PCNT_EVENT_PROCESSING); } // To be sure no old event remains m_private->currentEvent.type = SDL_NOEVENT; // Call SDL_PumpEvents() only once here // (SDL_PeepEvents() doesn't call it) if (m_active) SDL_PumpEvents(); m_private->lastMouseMotionEvent.type = SDL_NOEVENT; bool haveEvent = true; while (haveEvent) { haveEvent = false; int count = 0; // Use SDL_PeepEvents() if the app is active, so we can use idle time to // render the scene. Else, use SDL_WaitEvent() to avoid eating CPU time. if (m_active) count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_ALLEVENTS); else count = SDL_WaitEvent(&m_private->currentEvent); // If received an event if (count > 0) { haveEvent = true; // Skip mouse motion events, for now if (m_private->currentEvent.type == SDL_MOUSEMOTION) { m_private->lastMouseMotionEvent = m_private->currentEvent; continue; } Event event = ProcessSystemEvent(); if (event.type == EVENT_QUIT) goto end; // exit the loop if (event.type != EVENT_NULL) { bool passOn = ProcessEvent(event); if (m_engine != nullptr && passOn) passOn = m_engine->ProcessEvent(event); if (passOn) m_eventQueue->AddEvent(event); } Event virtualEvent = CreateVirtualEvent(event); if (virtualEvent.type != EVENT_NULL) { bool passOn = ProcessEvent(virtualEvent); if (m_engine != nullptr && passOn) passOn = m_engine->ProcessEvent(virtualEvent); if (passOn) m_eventQueue->AddEvent(virtualEvent); } } } // Now, process the last received mouse motion if (m_private->lastMouseMotionEvent.type != SDL_NOEVENT) { m_private->currentEvent = m_private->lastMouseMotionEvent; Event event = ProcessSystemEvent(); if (event.type == EVENT_QUIT) goto end; // exit the loop if (event.type != EVENT_NULL) { bool passOn = ProcessEvent(event); if (m_engine != nullptr && passOn) passOn = m_engine->ProcessEvent(event); if (passOn) m_eventQueue->AddEvent(event); } } // Enter game update & frame rendering only if active if (m_active) { Event event; while (m_eventQueue->GetEvent(event)) { if (event.type == EVENT_QUIT) goto end; // exit both loops bool passOn = true; // Skip system events (they have been processed earlier) if (! event.systemEvent) { passOn = ProcessEvent(event); if (passOn && m_engine != nullptr) passOn = m_engine->ProcessEvent(event); } if (passOn && m_robotMain != nullptr) m_robotMain->EventProcess(event); } StopPerformanceCounter(PCNT_EVENT_PROCESSING); StartPerformanceCounter(PCNT_UPDATE_ALL); // Prepare and process step simulation event event = CreateUpdateEvent(); if (event.type != EVENT_NULL && m_robotMain != nullptr) { StartPerformanceCounter(PCNT_UPDATE_ENGINE); m_engine->FrameUpdate(); StopPerformanceCounter(PCNT_UPDATE_ENGINE); m_sound->FrameMove(m_relTime); StartPerformanceCounter(PCNT_UPDATE_GAME); m_robotMain->EventProcess(event); StopPerformanceCounter(PCNT_UPDATE_GAME); } StopPerformanceCounter(PCNT_UPDATE_ALL); /* Update mouse position explicitly right before rendering * because mouse events are usually way behind */ UpdateMouse(); StartPerformanceCounter(PCNT_RENDER_ALL); Render(); StopPerformanceCounter(PCNT_RENDER_ALL); StopPerformanceCounter(PCNT_ALL); UpdatePerformanceCountersData(); if (m_lowCPU) { usleep(20000); // should still give plenty of fps } } } end: Destroy(); return m_exitCode; }