void game_loop() { while (game_running) { // do things update_keys(); handle_input(); // draw things blank_screen(&renderer); draw_player(); SDL_RenderPresent(renderer); // keep things at a normal pace SDL_Delay(10); } }
/* * Performs the back end of a vt switch */ void complete_change_console(unsigned int new_console) { unsigned char old_vc_mode; if (new_console == fg_console || new_console >= NR_CONSOLES) return; /* * If we're switching, we could be going from KD_GRAPHICS to * KD_TEXT mode or vice versa, which means we need to blank or * unblank the screen later. */ old_vc_mode = vt_cons[fg_console].vc_mode; update_screen(new_console); /* * If this new console is under process control, send it a signal * telling it that it has acquired. Also check if it has died and * clean up (similar to logic employed in change_console()) */ if (vt_cons[new_console].vt_mode.mode == VT_PROCESS) { /* * Send the signal as privileged - kill_proc() will * tell us if the process has gone or something else * is awry */ if (kill_proc(vt_cons[new_console].vt_pid, vt_cons[new_console].vt_mode.acqsig, 1) != 0) { /* * The controlling process has died, so we revert back to * normal operation. In this case, we'll also change back * to KD_TEXT mode. I'm not sure if this is strictly correct * but it saves the agony when the X server dies and the screen * remains blanked due to KD_GRAPHICS! It would be nice to do * this outside of VT_PROCESS but there is no single process * to account for and tracking tty count may be undesirable. */ vt_cons[new_console].vc_mode = KD_TEXT; clr_vc_kbd_mode(kbd_table + new_console, VC_RAW); clr_vc_kbd_mode(kbd_table + new_console, VC_MEDIUMRAW); vt_cons[new_console].vt_mode.mode = VT_AUTO; vt_cons[new_console].vt_mode.waitv = 0; vt_cons[new_console].vt_mode.relsig = 0; vt_cons[new_console].vt_mode.acqsig = 0; vt_cons[new_console].vt_mode.frsig = 0; vt_cons[new_console].vt_pid = -1; vt_cons[new_console].vt_newvt = -1; } } /* * We do this here because the controlling process above may have * gone, and so there is now a new vc_mode */ if (old_vc_mode != vt_cons[new_console].vc_mode) { if (vt_cons[new_console].vc_mode == KD_TEXT) unblank_screen(); else { timer_active &= ~(1<<BLANK_TIMER); blank_screen(); } } /* * Wake anyone waiting for their VT to activate */ vt_wake_waitactive(); return; }
/* * We handle the console-specific ioctl's here. We allow the * capability to modify any console, not just the fg_console. */ int vt_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned int arg) { int console; unsigned char ucval; console = tty->line - 1; if (console < 0 || console >= NR_CONSOLES) return -EINVAL; switch (cmd) { case KIOCSOUND: return kiocsound((unsigned int)arg); case KDGKBTYPE: /* * this is naive. */ verify_area((void *) arg, sizeof(unsigned char)); put_fs_byte(KB_101, (unsigned char *) arg); return 0; case KDADDIO: case KDDELIO: /* * KDADDIO and KDDELIO may be able to add ports beyond what * we reject here, but to be safe... */ if (arg < GPFIRST || arg > GPLAST) return -EINVAL; return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0; case KDENABIO: case KDDISABIO: return sys_ioperm(GPFIRST, GPNUM, (cmd == KDENABIO)) ? -ENXIO : 0; case KDSETMODE: /* * currently, setting the mode from KD_TEXT to KD_GRAPHICS * doesn't do a whole lot. i'm not sure if it should do any * restoration of modes or what... */ switch (arg) { case KD_GRAPHICS: break; case KD_TEXT0: case KD_TEXT1: arg = KD_TEXT; case KD_TEXT: break; default: return -EINVAL; } if (vt_cons[console].vt_mode == (unsigned char) arg) return 0; vt_cons[console].vt_mode = (unsigned char) arg; if (console != fg_console) return 0; if (arg == KD_TEXT) unblank_screen(); else { timer_active &= 1<<BLANK_TIMER; blank_screen(); } return 0; case KDGETMODE: verify_area((void *) arg, sizeof(unsigned long)); put_fs_long(vt_cons[console].vt_mode, (unsigned long *) arg); return 0; case KDMAPDISP: case KDUNMAPDISP: /* * these work like a combination of mmap and KDENABIO. * this could be easily finished. */ return -EINVAL; case KDSKBMODE: if (arg == K_RAW) { if (console == fg_console) { kraw = 1; ke0 = 0; } else { vt_cons[console].vc_kbdraw = 1; vt_cons[console].vc_kbde0 = 0; } } else if (arg == K_XLATE) { if (console == fg_console) kraw = 0; else vt_cons[console].vc_kbdraw = 0; } else return -EINVAL; flush_input(tty); return 0; case KDGKBMODE: verify_area((void *) arg, sizeof(unsigned long)); ucval = (console == fg_console) ? kraw : vt_cons[console].vc_kbdraw; put_fs_long(ucval ? K_RAW : K_XLATE, (unsigned long *) arg); return 0; case KDGETLED: verify_area((void *) arg, sizeof(unsigned char)); ucval = (console == fg_console) ? kleds : vt_cons[console].vc_kbdleds; put_fs_byte((((ucval & 1) ? LED_SCR : 0) | ((ucval & 2) ? LED_NUM : 0) | ((ucval & 4) ? LED_CAP : 0)), (unsigned char *) arg); return 0; case KDSETLED: if (arg & ~7) return -EINVAL; ucval = (((arg & LED_SCR) ? 1 : 0) | ((arg & LED_NUM) ? 2 : 0) | ((arg & LED_CAP) ? 4 : 0)); if (console == fg_console) { kleds = ucval; set_leds(); } else vt_cons[console].vc_kbdleds = ucval; return 0; default: return -EINVAL; } }
reset_graphics() { blank_screen(draw_win); do_axes(); hi_lite(draw_win); }
static int parse_rbuf(const char *rbuf, struct config *conf, int row, int col, int sel, char **client, int *count, int details, const char *sclient) { //int c=0; char *cp=NULL; char *dp=NULL; char *copyall=NULL; if(!(copyall=strdup(rbuf))) { logp("out of memory\n"); return -1; } dp=copyall; *count=0; // First, blank the whole screen. blank_screen(row, col); while((cp=strchr(dp, '\n'))) { int t=1; char *copy=NULL; char **toks=NULL; *cp='\0'; if(!(toks=(char **)realloc(toks, t*sizeof(char *)))) { logp("out of memory"); return -1; } if(!(copy=strdup(dp))) { logp("out of memory\n"); free(copyall); free(toks); return -1; } if((toks[0]=strtok(copy, "\t\n"))) { char *tmp=NULL; while(1) { if(!(tmp=strtok(NULL, "\t\n"))) break; if(!(toks=(char **)realloc(toks, (t+1)*sizeof(char *)))) { logp("out of memory"); free(copyall); free(copy); return -1; } toks[t++]=tmp; } } if(t<2) { free(toks); free(copy); continue; } if(details) { if(*count==sel || sclient) { if(toks[0] && (!*client || strcmp(toks[0], *client))) { if(*client) free(*client); *client=strdup(toks[0]); } if(!sclient || !strcmp(toks[0], sclient)) detail(toks, t, conf, 0, col); } } else { summary(toks, t, *count, row, col); } (*count)++; dp=cp+1; free(copy); free(toks); } if(copyall) free(copyall); return 0; }
gboolean mon_timer_popped(gpointer data) { int rc = cib_ok; int options = cib_scope_local; if(timer_id > 0) { Gmain_timeout_remove(timer_id); } if(as_console) { #if CURSES_ENABLED move(0, 0); printw("Updating...\n"); clrtoeol(); refresh(); #endif } else { crm_notice("Updating..."); } if(cib_conn == NULL) { crm_debug_4("Creating CIB connection"); cib_conn = cib_new(); } CRM_DEV_ASSERT(cib_conn != NULL); if(crm_assert_failed) { return FALSE; } else if(cib_conn->state != cib_connected_query){ crm_debug_4("Connecting to the CIB"); #if CURSES_ENABLED if(as_console) { printw("Signing on...\n"); clrtoeol(); refresh(); } #endif if(cib_ok == cib_conn->cmds->signon( cib_conn, crm_system_name, cib_query)) { failed_connections = 0; } else if (simple_status || one_shot) { fprintf(stdout, "Critical: Unable to connect to the CIB\n"); exit(2); } else { failed_connections++; CRM_DEV_ASSERT(cib_conn->cmds->signoff(cib_conn) == cib_ok); wait_for_refresh(0, "Not connected: ", 2*interval); return FALSE; } #if CURSES_ENABLED if(as_console) { printw("Querying...\n"); clrtoeol(); refresh(); } #endif } if(as_console) { blank_screen(); } rc = cib_conn->cmds->query(cib_conn, NULL, NULL, options); add_cib_op_callback(rc, FALSE, NULL, mon_update); return FALSE; }