int Booster::launchProcess() { setEnvironmentBeforeLaunch(); // Load the application and find out the address of main() loadMain(); // make booster specific initializations unless booster is in boot mode if (!m_bootMode) preinit(); // make booster specific initializations unless booster is in boot mode if (!m_bootMode) preinit(); #ifdef WITH_COVERAGE __gcov_flush(); #endif // Close syslog closelog(); // Jump to main() const int retVal = m_appData->entry()(m_appData->argc(), const_cast<char **>(m_appData->argv())); #ifdef WITH_COVERAGE __gcov_flush(); #endif return retVal; }
// 主函数 int main( int argc, char* argv[] ) { int i, ms_x = -1024, ms_y = -1024, exitflag = 0; int fps = 60; double dtime; int mode = preinit( argc, argv ); // 记录初始化模式 if ( mode < 0 ) return 0; randomize(); // 初始化随机种子 initgraph( -1, -1 ); // 打开图形窗口,以全屏模式 showmouse( mode ); sc_width = getwidth(); sc_heigh = getheight(); // 初始化所有星星 for ( i = 0; i < g_max; i++ ) { InitStar( i ); star[i].x = randomf(); } // 绘制星空,按任意键或移动鼠标退出 setfont( 12, 6, "宋体" ); setrendermode( RENDER_MANUAL ); dtime = fclock(); while ( kbmsg() ) getkey(); for ( ; !exitflag && is_run() && kbmsg() == 0; delay_fps( fps ) ) { //每秒画120帧,kbhit(1)是获取键盘任意键的消息,详见pdf // 如果有鼠标消息 while ( mousemsg() ) { mouse_msg msg = getmouse(); if ( ms_x <= -1024 ) { ms_x = msg.x; ms_y = msg.y; } // 处理鼠标,移动超出范围就退出 if ( mode == 0 ) { // 仅全屏模式才处理鼠标 int x = msg.x, y = msg.y; x -= ms_x; y -= ms_y; if ( x * x + y * y > 400 ) exitflag = 1; } } // 显示星星 double dt = 1.0 / fps; //fclock() - dtime; dtime += dt; for ( int i = 0; i < g_max; i++ ) { MoveStar( i, dt ); } // 显示FPS { char str[60]; sprintf( str, "%8.2f FPS", getfps()); outtextxy( 0, 0, str ); //显示fps } } closegraph(); // 关闭图形窗口 return 0; }
void ParticlesControl::init(Vertices* vertices, GLuint particlePosTexID[]) { /// Common initialization. preinit(vertices, passthrough_vshader, particles_control_fshader, NULL, "vertexPosition2D"); /// The Sampler uniforms always refer to texture indices 0 and 1. /// The binding to textures 0 and 1 are however flipped every frame. GLuint uniformID = glGetUniformLocation(_programID, "particlePosTex"); glUniform1i( uniformID, 0); uniformID = glGetUniformLocation(_programID, "particleVelTex"); glUniform1i( uniformID, 1); /// Generate the two position and velocity textures (last and current). glGenTextures(4, _particleTexID); particlePosTexID[0] = _particleTexID[0]; particlePosTexID[1] = _particleTexID[1]; /// Position and velocity : three components, unclamped 32 bits float. /// Filtering technique has to be set, even that texels are fetch /// individually by fetchTexel() which bypass any filtering. /// Attach the textures to the corresponding FBO color attachments. glGenFramebuffers(1, &_framebufferID); glBindFramebuffer(GL_FRAMEBUFFER, _framebufferID); for(int k=0; k<4; ++k) { glBindTexture(GL_TEXTURE_1D, _particleTexID[k]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + k, _particleTexID[k], 0); } /// Initial particles position and velocity. /// Particles can be in x=[-1,1], y=[-1,1], z=[0,5]. /// While g++ does, VC++ does not support particlesPos[3*nParticles] as /// nParticles isn't a compile-time constant. Allocate dynamically on the heap. const unsigned int nParticles = _nParticlesSide*_nParticlesSide*_nParticlesSide; float *particlesPos = new float[3*nParticles]; float *particlesVel = new float[3*nParticles]; for(int k=0; k<nParticles; ++k) { particlesPos[3*k+0] = 2.0f * float(k % (_nParticlesSide*_nParticlesSide) % _nParticlesSide) / float(_nParticlesSide) - 1.0f; // x particlesPos[3*k+1] = 2.0f * float(k % (_nParticlesSide*_nParticlesSide) / _nParticlesSide) / float(_nParticlesSide) - 1.0f; // y particlesPos[3*k+2] = 2.0f * float(k / (_nParticlesSide*_nParticlesSide) ) / float(_nParticlesSide) + 6.2f; // z particlesVel[3*k+0] = 0.0f; // x particlesVel[3*k+1] = 0.0f; // y particlesVel[3*k+2] = 0.1f * float(k / (_nParticlesSide*_nParticlesSide) ) / float(_nParticlesSide) + 0.0f; // z } glBindTexture(GL_TEXTURE_1D, _particleTexID[0]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, particlesPos); glBindTexture(GL_TEXTURE_1D, _particleTexID[2]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, particlesVel); delete[] particlesPos, particlesVel; /// Set uniform IDs. _deltaTID = glGetUniformLocation(_programID, "deltaT"); }
void load_init(int argc,char **argv) { uintptr_t addr; if(lookup_byName(NULL,"__libc_preinit",&addr)) { fPreinit preinit = (fPreinit)addr; preinit(0,argc,argv); } for(sSharedLib *l = libs; l != NULL; l = l->next) load_initLib(l); }
int main(int argc, char **argv) { pid_t pid; ulog_open(ULOG_KMSG, LOG_DAEMON, "init"); sigaction(SIGTERM, &sa_shutdown, NULL); sigaction(SIGUSR1, &sa_shutdown, NULL); sigaction(SIGUSR2, &sa_shutdown, NULL); early(); cmdline(); watchdog_init(1); pid = fork(); if (!pid) { char *kmod[] = { "/sbin/kmodloader", "/etc/modules-boot.d/", NULL }; if (debug < 3) { int fd = open("/dev/null", O_RDWR); if (fd > -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > STDERR_FILENO) close(fd); } } execvp(kmod[0], kmod); ERROR("Failed to start kmodloader\n"); exit(-1); } if (pid <= 0) { ERROR("Failed to start kmodloader instance\n"); } else { int i; for (i = 0; i < 120; i++) { if (waitpid(pid, NULL, WNOHANG) > 0) break; sleep(1); watchdog_ping(); } } uloop_init(); preinit(); uloop_run(); return 0; }
void CameraPathControls::init(Vertices* vertices) { /// Common initialization. preinit(vertices, camera_path_controls_vshader, rendering_simple_fshader, camera_path_controls_gshader, "vertexPosition3DWorld"); /// Set uniform IDs. _projectionID = glGetUniformLocation(_programID, "projection"); _viewID = glGetUniformLocation(_programID, "view"); _lightPositionWorldID = glGetUniformLocation(_programID, "lightPositionWorld"); _selectedControlPointID = glGetUniformLocation(_programID, "selectedControlPoint"); _rotationMatrixID = glGetUniformLocation(_programID, "rotationMatrix"); }
/* Now we really start accessing some data and determining file format. * Format now is allowed to change on-the-fly. Here is the only point * that has MPlayer react to errors. We have to pray that exceptional * erros in other places simply cannot occur. */ static int init(struct dec_audio *da, const char *decoder) { if (!preinit(da)) return 0; struct ad_mpg123_context *con = da->priv; int ret; ret = mpg123_open_feed(con->handle); if (ret != MPG123_OK) goto fail; for (int n = 0; ; n++) { if (feed_new_packet(da) < 0) { ret = MPG123_NEED_MORE; goto fail; } size_t got_now = 0; ret = mpg123_decode_frame(con->handle, NULL, NULL, &got_now); if (ret == MPG123_OK || ret == MPG123_NEW_FORMAT) { ret = set_format(da); if (ret == MPG123_OK) break; } if (ret != MPG123_NEED_MORE) goto fail; // max. 16 retries (randomly chosen number) if (n > 16) { ret = MPG123_NEED_MORE; goto fail; } } return 1; fail: if (ret == MPG123_NEED_MORE) { MP_ERR(da, "Could not find mp3 stream.\n"); } else { MP_ERR(da, "mpg123 init error: %s\n", mpg123_strerror(con->handle)); } uninit(da); return 0; }
// open & setup audio device // return: 1=success 0=fail static int init(int rate,int channels,int format,int flags){ if(preinit(NULL)<0) return 0; ao_data.channels=2; ao_data.outburst=2000; switch(format){ case AF_FORMAT_S16_BE: case AF_FORMAT_MPEG2: case AF_FORMAT_AC3_BE: ao_data.format=format; break; case AF_FORMAT_AC3_LE: ao_data.format=AF_FORMAT_AC3_BE; break; default: ao_data.format=AF_FORMAT_S16_BE; } switch(rate){ case 48000: freq_id=0;break; case 96000: freq_id=1;break; case 44100: freq_id=2;break; case 32000: freq_id=3;break; default: mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_MPEGPES_UnsupSamplerate, rate); #if 0 if(rate>48000) rate=96000; else if(rate>44100) rate=48000; else if(rate>32000) rate=44100; else rate=32000; goto retry; #else rate=48000; freq_id=0; #endif } ao_data.bps=rate*2*2; freq=ao_data.samplerate=rate; return 1; }
int main(int argc,char **argv) { int n; for (n=0;n<HARD_USERLIMIT;n++) pchild[n]=(child_t *)NULL; for (n=0;n<LOGININFO_COUNT;n++) logininfo[n]=(logininfo_t *)NULL; parsecmdline(argc,argv); while (reinit) { reinit=0; preinit(); if (readini()<0) exit(1); if (!checkconf()) exit(1); do_writepidfile(); do_changeroot(); if (daemonmode) { if (fork()==0) startserver(); exit(0); /* better be sure */ } else startserver(); for (n=0;n<maxusers;n++) if (pchild[n]) { free(pchild[n]); pchild[n]=(child_t *)NULL; } for (n=0;n<logininfocount;n++) if (logininfo[n]) { free(logininfo[n]); logininfo[n]=(logininfo_t *)NULL; } } exit(0); }
int main(int argc, char **argv) { int ret = 0; int i; char chunk[BUFF_SIZE]; int lenna_fd; int total; char *ptr; struct v4l2_buffer buf; uint32_t type = V4L2_BUF_TYPE_VIDEO_OUTPUT; printf("vo_atmel %d.%d.%d (%s)\n", VERSION, PATCHLEVEL, SUBLEVEL, VERSION_NAME); ret = preinit(); if (ret) return -1; /* with scaling */ ret = config(512, 512, 400, 400, 0, "lenna", V4L2_PIX_FMT_YUV420); if (ret) goto err; printf("vo_atmel: open file\n"); lenna_fd = open("./lenna.yuv", O_RDWR); if (lenna_fd < 0) { printf("vo_atmel: Could not open image file\n"); goto err; } memset(&buf, '\0', sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.memory = V4L2_MEMORY_MMAP; // Test with solid colors: //memset(atmel_priv.buf[buf.index], '\0', atmel_priv.len[buf.index]); //memset(atmel_priv.buf[buf.index], 0xff, atmel_priv.len[buf.index]); // Test with YUV data total = atmel_priv.len[buf.index]; ptr = (char *)atmel_priv.buf[buf.index]; ret = read(lenna_fd, chunk, BUFF_SIZE); while (ret > 0) { total -= ret; if (total <= 0) { printf("ret remains: %d\n", ret); break; } memcpy(ptr, chunk, ret); ptr += ret; ret = read(lenna_fd, chunk, BUFF_SIZE); } ret = 0; printf("vo_atmel: sleeping a little bit\n"); sleep(10); err: uninit(); return ret; }
Common::Error KyraEngine_MR::go() { bool running = true; preinit(); _screen->hideMouse(); initMainMenu(); _screen->clearPage(0); _screen->clearPage(2); const bool firstTimeGame = !saveFileLoadable(0); if (firstTimeGame) { playVQA("K3INTRO"); _wasPlayingVQA = false; } if (_gameToLoad != -1 || firstTimeGame) { while (!_screen->isMouseVisible()) _screen->showMouse(); uninitMainMenu(); _musicSoundChannel = -1; startup(); runLoop(); running = false; } while (running && !shouldQuit()) { _screen->_curPage = 0; _screen->clearPage(0); _screen->setScreenPalette(_screen->getPalette(0)); playMenuAudioFile(); for (int i = 0; i < 64 && !shouldQuit(); ++i) { uint32 nextRun = _system->getMillis() + 3 * _tickLength; _menuAnim->displayFrame(i, 0, 0, 0, 0, 0, 0); _screen->updateScreen(); delayUntil(nextRun); } for (int i = 64; i > 29 && !shouldQuit(); --i) { uint32 nextRun = _system->getMillis() + 3 * _tickLength; _menuAnim->displayFrame(i, 0, 0, 0, 0, 0, 0); _screen->updateScreen(); delayUntil(nextRun); } _eventList.clear(); switch (_menu->handle(3)) { case 2: _menuDirectlyToLoad = true; // fall through case 0: uninitMainMenu(); fadeOutMusic(60); _screen->fadeToBlack(60); _musicSoundChannel = -1; startup(); runLoop(); running = false; break; case 1: playVQA("K3INTRO"); _wasPlayingVQA = false; _screen->hideMouse(); break; case 3: fadeOutMusic(60); _screen->fadeToBlack(60); uninitMainMenu(); quitGame(); running = false; break; default: break; } } if (_showOutro && !shouldQuit()) playVQA("CREDITS"); return Common::kNoError; }