void main_loop() { struct timespec ptime; struct timespec ctime; struct timespec diff; clock_gettime(CLOCK_MONOTONIC_COARSE, &ctime); while (running) { clock_gettime(CLOCK_MONOTONIC_COARSE, &ptime); reshape_window(); poll_geometry(); process_events(); display_func(); clock_gettime(CLOCK_MONOTONIC_COARSE, &ctime); diff.tv_sec = ctime.tv_sec - ptime.tv_sec; diff.tv_nsec = ctime.tv_nsec - ptime.tv_nsec; long sleeptime = 16666666l - ( diff.tv_sec * 1000000000l + diff.tv_nsec ); diff.tv_sec = 0; diff.tv_nsec = sleeptime; while (diff.tv_nsec > 0) { struct timespec rem; int i = nanosleep(&diff, &rem); if (i < 0) { diff.tv_sec = rem.tv_sec; diff.tv_nsec = rem.tv_nsec; } else { break; } } } }
static int handle_event(Display *dpy, XEvent *ev) { static int win_mapped; KeySym keysym; switch(ev->type) { case MapNotify: win_mapped = 1; break; case UnmapNotify: win_mapped = 0; break; case Expose: if(win_mapped) { if(display_rect_func) { display_rect_func(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); } if(!ev->xexpose.count && display_func) { display_func(); } } break; case KeyPress: case KeyRelease: keysym = XLookupKeysym((XKeyEvent*)&ev->xkey, 0); if(keyb_func) { keyb_func(keysym & 0xff, ev->type == KeyPress); } break; case ClientMessage: if(ev->xclient.message_type == wm_prot) { if(ev->xclient.data.l[0] == wm_del) { return -1; } } break; case ConfigureNotify: win_xsz = ev->xconfigure.width; win_ysz = ev->xconfigure.height; if(reshape_func) { reshape_func(win_xsz, win_ysz); } break; default: break; } return 0; }
void APIENTRY glutMainLoop (void) { GLboolean idle; GLboolean have_event; XEvent evt; int visible = 0; glutPostRedisplay(); if (reshape_func) reshape_func(g_width, g_height); while (GL_TRUE) { idle = GL_TRUE; if (visible && idle_func) have_event = XCheckMaskEvent( dpy, ~0, &evt ); else have_event = XNextEvent( dpy, &evt ); if (have_event) { idle = GL_FALSE; switch(evt.type) { case MapNotify: if (visibility_func) { visibility_func(GLUT_VISIBLE); } visible = 1; break; case UnmapNotify: if (visibility_func) { visibility_func(GLUT_NOT_VISIBLE); } visible = 0; break; case Expose: g_redisplay = 1; break; } } if (visible && g_redisplay && display_func) { idle = GL_FALSE; g_redisplay = GL_FALSE; display_func(); } if (visible && idle && idle_func) { idle_func(); } } }
/* If enabled in menuconfig, this function is periodically called change "timer(100,app_sample_periodic)" if needed Wird ca alle 200ms aufgerufen */ int16_t rainmaster_periodic(void) { // Uhrzeit aktualisieren clock_current_localtime(&date); // Eingänge und Sensore abfragen rainmaster_check_inputs(); // GUI Anzeige abarbeiten (Pointer auf Anzeigefunktion im Menu) display_func(); return ECMD_FINAL_OK; }
int main ( int argc, char ** argv ) { //glutInit ( &argc, argv ); if(!glfwInit()) { fprintf( stderr, "Failed to initialize GLFW\n" ); return EXIT_FAILURE; } // GLenum err = glewInit(); // if (GLEW_OK != err) { // fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); // } if ( argc != 1 && argc != 6 ) { fprintf ( stderr, "usage : %s N dt diff visc force source\n", argv[0] ); fprintf ( stderr, "where:\n" );\ fprintf ( stderr, "\t N : grid resolution\n" ); fprintf ( stderr, "\t dt : time step\n" ); fprintf ( stderr, "\t diff : diffusion rate of the density\n" ); fprintf ( stderr, "\t visc : viscosity of the fluid\n" ); fprintf ( stderr, "\t force : scales the mouse movement that generate a force\n" ); fprintf ( stderr, "\t source : amount of density that will be deposited\n" ); exit ( 1 ); } if ( argc == 1 ) { N = 64; dt = 0.1f; diff = 0.0f; visc = 0.0f; force = 5.0f; source = 100.0f; fprintf ( stderr, "Using defaults : N=%d dt=%g diff=%g visc=%g force = %g source=%g\n", N, dt, diff, visc, force, source ); } else { N = atoi(argv[1]); dt = atof(argv[2]); diff = atof(argv[3]); visc = atof(argv[4]); force = atof(argv[5]); source = atof(argv[6]); } printf ( "\n\nHow to use this demo:\n\n" ); printf ( "\t Add densities with the right mouse button\n" ); printf ( "\t Add velocities with the left mouse button and dragging the mouse\n" ); printf ( "\t Toggle density/velocity display with the 'v' key\n" ); printf ( "\t Clear the simulation by pressing the 'c' key\n" ); printf ( "\t Quit by pressing the 'q' key\n" ); dvel = 2; if ( !allocate_data () ) exit ( 1 ); clear_data (); win_x = 512; win_y = 512; open_glut_window (); while(1) { idle_func(); display_func(); mouse(); if (!glfwGetWindowParam(GLFW_OPENED)) { exit(0); } } glfwTerminate(); //glutMainLoop (); exit ( 0 ); }