void main() { init(); start_gol(); io_write(7, 1); delay_ms(200); quit_app(); return; }
void ACEApp::parent_hatch(pid_t* child_pids, int child_proc_num) { for (int i = 0; i < child_proc_num; i++) { if (child_pids[i] != 0) { continue; } pid_t child_pid = ACE_OS::fork(); if (child_pid == -1) { ACE_DEBUG((LM_ERROR, "[%D] fork %d child failed, (%d)%s\n", i, errno, ACE_OS::strerror(errno))); ACE_OS::sleep(10); continue; } else if (child_pid == 0) { // child is_child_ = true; is_quit_ = false; ACE_Reactor::instance()->reset_reactor_event_loop(); ACE_OS::signal (SIGINT, SIG_IGN); ACE_OS::signal (SIGCHLD, SIG_IGN); if (init_log(i) == 0) { ACE_DEBUG((LM_INFO, "[%D] enter child main pid %d: %d\n", i, ACE_OS::getpid())); child_main(); ACE_DEBUG((LM_INFO, "[%D] leave child main pid %d: %d\n", i, ACE_OS::getpid())); } quit_app(); ACE_OS::exit(0); } else { // parent ACE_DEBUG((LM_ERROR, "[%D] child forked, pid %d: %d\n", i, child_pid)); child_pids[i] = child_pid; } } }
void process_events( void ) { SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: handle_keydown( &event.key.keysym ); break; case SDL_KEYUP: handle_keyup( &event.key.keysym ); break; case SDL_QUIT: quit_app( 0 ); break; } } }
void handle_keydown( SDL_keysym* keysym ) { switch (keysym->sym) { case SDLK_UP: you_dir = -1; break; case SDLK_DOWN: you_dir = 1; break; case SDLK_LEFT: you_turn = -1; break; case SDLK_RIGHT: you_turn = 1; break; case SDLK_KP_PLUS: you_velocity++; break; case SDLK_KP_MINUS: you_velocity--; break; case SDLK_q: case SDLK_ESCAPE: quit_app( 0 ); break; case SDLK_l: light = !light; if ( !light ) glDisable( GL_LIGHTING ); else glEnable( GL_LIGHTING ); break; case SDLK_d: debug = !debug; break; default: break; } }
int ACEApp::init(int argc, ACE_TCHAR* argv[]) { // get the program name #ifdef WIN32 char* ptr = ACE_OS::strrchr(argv[0], '\\'); #else char* ptr = ACE_OS::strrchr(argv[0], '/'); #endif if (ptr) { // strip path name strcpy(program_, ptr + 1); } else { strcpy(program_, argv[0]); } #ifdef WIN32 // strip .exe extension on WIN32 ptr = strchr(program_, '.'); if (ptr) { *ptr = '\0'; } #endif int child_proc_num = 0; ACE_Get_Opt get_opt(argc, argv, "vdp:c:"); char c; while ((c = get_opt()) != EOF) { switch (c) { case 'd': // run as daemon ACE::daemonize(); break; case 'p': // specified program name strcpy(program_, get_opt.opt_arg()); break; case 'c': // child process number child_proc_num = atoi(get_opt.opt_arg()); break; case 'v': //disp version info disp_version(); return 0; default: break; } } ACE_OS::signal (SIGPIPE, SIG_IGN); ACE_OS::signal (SIGTERM, SIG_IGN); ACE_OS::signal (SIGCHLD, SIG_IGN); ACE_Sig_Action sig_int((ACE_SignalHandler)daemon_quit, SIGINT); //ACE_Sig_Action sig_term((ACE_SignalHandler)daemon_quit, SIGTERM); //ACE_Sig_Action sig_chld((ACE_SignalHandler)child_sighdr, SIGCHLD); ACE_UNUSED_ARG(sig_int); //ACE_UNUSED_ARG(sig_term); //ACE_UNUSED_ARG(sig_chld); //在 init_log() 之前即可 if (init_reactor() != 0) { ACE_DEBUG((LM_ERROR, "[%D] init reactor failed, program exit\n")); return -1; } ACE_DEBUG((LM_INFO, "[%D] init reactor succ\n")); if (init_sys_path(program_) != 0) { ACE_DEBUG((LM_ERROR, "[%D] init sys path failed, program exit\n")); return -1; } if (init_conf() != 0) { ACE_DEBUG((LM_ERROR, "[%D] init conf failed, program exit\n")); return -1; } ACE_DEBUG((LM_INFO, "[%D] init conf succeed\n")); if (init_log() != 0) { ACE_DEBUG((LM_ERROR, "[%D] init log failed, program exit\n")); return -1; } ACE_DEBUG((LM_INFO, "[%D] init log succ\n")); //版本信息记录日志 disp_version(); if (init_app(argc, argv) != 0) { ACE_DEBUG((LM_ERROR, "[%D] init app failed, program exit\n")); return -1; } ACE_DEBUG((LM_INFO, "[%D] init app succ\n")); write_pid_file(); ACE_DEBUG((LM_INFO, "[%D] write pid file succ\n")); if (child_proc_num > 0) { parent_main(child_proc_num); } else { ACE_DEBUG((LM_INFO, "[%D] enter daemon main pid: %d\n", ACE_OS::getpid())); daemon_main(); ACE_DEBUG((LM_INFO, "[%D] leave daemon main pid: %d\n", ACE_OS::getpid())); } quit_app(); return 0; }
int main( int argc, char* argv[] ) { bool fullscreen = false; char* world = "world"; for (int i=0; i<argc; i++) { if (strcmp(argv[i], "-win") == 0) fullscreen = false; if (strcmp(argv[i], "-f") == 0) fullscreen = true; if (strcmp(argv[i], "-w") == 0) world = argv[i+1]; if (strcmp(argv[i], "-d") == 0) debug = true; } SetupWorld(world); you_x = getWorldX(); you_z = getWorldZ(); you_angle = getWorldAngle(); const SDL_VideoInfo* info = NULL; int width = 0; int height = 0; int bpp = 0; int flags = 0; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); quit_app( 1 ); } info = SDL_GetVideoInfo( ); if( !info ) { fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) ); quit_app( 1 ); } width = 640; height = 480; bpp = info->vfmt->BitsPerPixel; 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 ); flags = SDL_OPENGL; if (fullscreen) flags |= SDL_FULLSCREEN; if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); quit_app( 1 ); } setup_opengl( width, height ); bool init = true; while( 1 ) { process_events( ); draw_screen( ); if (init) { glEnable( GL_LIGHTING ); init=false; } } return 0; }
void start_terminal() { char c; byte echo = 1, cnt = 0; write_inverse(6, 30, " SELECT BAUD RATE "); write_inverse(7, 30, " 1: 4800 "); write_inverse(8, 30, " 2: 9600 "); write_inverse(9, 30, " 3: 19200 "); write_inverse(10, 30, " 4: 38400 "); write_inverse(11, 30, " 5: 57600 "); write_inverse(12, 30, " 6: 115200 "); do { c = getchar_nc(); } while (!(c >= '1' && c <= '6')); io_write(170, c - '0'); switch (c) { case '1': write_inverse(0, 20, "4800 BAUD"); break; case '2': write_inverse(0, 20, "9600 BAUD"); break; case '3': write_inverse(0, 20, "19200 BAUD"); break; case '4': write_inverse(0, 20, "38400 BAUD"); break; case '5': write_inverse(0, 20, "57600 BAUD"); break; case '6': write_inverse(0, 20, "115200 BAUD"); break; } v_cls(); while (1) { if (cnt == 0) v_showcursor(); c = io_read(128); if (((byte)c) == 255) { delay_ms(15); if (cnt == CURSOR_DELAY) v_hidecursor(); if (++cnt == CURSOR_DELAY << 1) cnt = 0; } // if (c == 255) else { v_hidecursor(); cnt = 0; if (c == 0) { // special key c = getchar(); switch (c) { case 60: // F2 echo = 1 - echo; if (echo) write_inverse(0, 0, " F2: ECHO ON "); else write_inverse(0, 0, " F2: ECHO OFF"); break; case 66: // F8 v_cls(); break; case 68: // F10 quit_app(); break; } // switch (c) } // if (c == 0) else { io_write(171, c); if (echo) { if (c == 8) v_backspace(); else putchar(c); } // if (echo) } // if (c == 0) else } // if (c == 255) else if (io_read(174)) { v_hidecursor(); do { c = io_read(173); if (c) putchar(c); } while (c); } } // while (1) } // start_editor
void start_terminal() { char c; byte echo = 1, cnt = 0; write_inverse(6, 30, " SELECT BAUD RATE "); write_inverse(7, 30, " 1: 1200 "); write_inverse(8, 30, " 2: 2400 "); write_inverse(9, 30, " 3: 4800 "); write_inverse(10, 30, " 4: 9600 "); write_inverse(11, 30, " 5: 19200 "); write_inverse(12, 30, " 6: 38400 "); write_inverse(13, 30, " 7: 57600 "); write_inverse(14, 30, " 8: 115200 "); do { c = getchar(); } while (!(c >= '1' && c <= '8')); // set baud rate io_write(170, c - '0'); switch (c) { case '1': write_inverse(0, 20, "1200 BAUD"); break; case '2': write_inverse(0, 20, "2400 BAUD"); break; case '3': write_inverse(0, 20, "4800 BAUD"); break; case '4': write_inverse(0, 20, "9600 BAUD"); break; case '5': write_inverse(0, 20, "19200 BAUD"); break; case '6': write_inverse(0, 20, "38400 BAUD"); break; case '7': write_inverse(0, 20, "57600 BAUD"); break; case '8': write_inverse(0, 20, "115200 BAUD"); break; } clrscr(); showcursor(); while (1) { c = getchar(); cnt = 0; if (c == 0) { // special key c = getchar(); switch (c) { case 60: // F2 echo = 1 - echo; if (echo) write_inverse(0, 0, " F2: ECHO ON "); else write_inverse(0, 0, " F2: ECHO OFF"); break; case 66: // F8 clrscr(); break; case 68: // F10 quit_app(); break; } // switch (c) } // if (c == 0) else { io_write(171, c); if (echo) putchar(c); } // if (c == 0) else if (io_read(174)) { hidecursor(); do { c = io_read(173); if (c) putchar(c); } while (c); showcursor(); } } // while (1) } // start_terminal