void GW_GameEngine_VTech::score_add(int count) { score_+=count; if (score_>9999) score_-=10000; score_update(); level_update(); }
inline void Board::paintAll() { static QPixmap pix(rect().size()); static QPainter p; p.begin(&pix); drawBackground(&p); for(int i = 1; i < 65; i++){ drawGrid(i, &p); } p.end(); bitBlt( this, rect().topLeft(), &pix ); score.sprintf( "%2d:%2d", black_num, white_num); emit score_update(score); }
void GW_GameEngine_VTech::do_game_start(int mode) { data_hideall(true); score_=0; data().position_get((mode==MODE_GAMEA?PS_GAMEA:PS_GAMEB))->show(); score_update(); misses_=0; canmove_=true; gameover_=false; miss_update(); level_update(mode); game_start(mode); data_starttimer(TMR_GAMESTART); }
void CGI_prefork_server(const char *host, int port, const char *pidfile, int maxproc, int minidle, int maxidle, int maxreq, void (*callback)(void)) { int i, sock, fd; struct score_state message; struct score_board *scb; pid_t pid; FILE *fp; int pfd[2]; char **realenv, **tmpenv; char *tmpbuf; extern char **environ; /* sanity check arguments */ if (callback == 0) { syslog(LOG_ERR, "CGI_prefork_server(): null callback " "function pointer"); return; } if (minidle <= 0) { minidle = 2; } if (maxidle <= minidle) { maxidle = minidle + 2; } if (maxproc <= 0) { maxproc = maxidle; } if (maxproc > SCORE_MAX_PROC) { maxproc = SCORE_MAX_PROC; } syslog(LOG_INFO, "CGI_prefork_server(): maxproc = %d, minidle = %d, " "maxidle = %d, maxreq = %d", maxproc, minidle, maxidle, maxreq); /* parent puts self into the background */ if (fork() != 0) { _exit(0); } setsid(); set_handler(SIGTERM, terminate); set_handler(SIGCHLD, child_handler); if ( freopen("/dev/null", "r", stdin) != 0 ) printf("freopen error\n"); if ( freopen("/dev/null", "w", stdout) != 0 ) printf("freopen2 error\n"); /* write our pid to pidfile */ if (pidfile != 0 && *pidfile != 0 && (fp = fopen(pidfile, "w")) != 0) { fprintf(fp, "%d\n", getpid()); fclose(fp); } /* create child process scoreboard */ scb = score_new(maxproc, minidle, maxidle); /* parent opens the listen socket, children accept() connections */ if ((sock = setup_sock(host, port)) < 0) { syslog(LOG_ERR, "CGI_prefork_server(): setup_sock() failed: %m"); return; } /* open pipe to receive messages from child processes */ if ( pipe(pfd) != 0 ) printf("pipe error\n"); /* parent manages child processes */ for (;;) { /* fork child if necessary */ if (scb->numidle < scb->minidle && scb->numproc < scb->maxproc) { if ((pid = fork()) == 0) { break; } else if (pid > 0) { score_add(scb, pid); continue; } else { syslog(LOG_ERR, "CGI_prefork_server(): fork() failed: %m"); if (scb->numproc == 0) { return; } } } /* * read status message from child. The read() call returns with * an error if we catch SIGCHLD or SIGTERM. */ if (child_exited == 0 && terminate_flag == 0 && read(pfd[0], &message, sizeof(message)) == sizeof(message)) { score_update(scb, &message); } /* kill everything and exit if we got SIGTERM */ if (terminate_flag != 0) { set_handler(SIGTERM, SIG_IGN); kill(0, SIGTERM); /* kill process group */ while(wait(0) >= 0) ; exit(0); } /* kill idle child if necessary */ if (scb->numidle > scb->maxidle) { score_kill(scb); } /* wait for exited children */ child_exited = 0; while ((pid = waitpid(-1, 0, WNOHANG)) > 0) { score_remove(scb, pid); } } /* child handles maxreq requests and exits */ set_handler(SIGTERM, SIG_DFL); set_handler(SIGCHLD, SIG_DFL); close(pfd[0]); message.pid = getpid(); realenv = environ; for (i = 0; i < maxreq || maxreq <= 0; i++) { /* accept connection from SCGI client (httpd) */ if ((fd = accept(sock, 0, 0)) < 0) { syslog(LOG_ERR, "CGI_prefork_server(): accept() failed: %m"); break; } /* notify parent we are busy */ message.state = SCORE_BUSY; if ( write(pfd[1], &message, sizeof(message)) != sizeof(message) ) printf("write error\n"); /* redirect stdin and stdout to socket */ dup2(fd, 0); dup2(fd, 1); close(fd); /* read environment and call callback */ if ((tmpenv = read_env()) != 0) { tmpbuf = tmpenv[0]; environ = tmpenv; callback(); } else { fputs("Content-type: text/plain\r\n\r\n" "CGI_prefork_server() could not read environment.\r\n", stdout); syslog(LOG_ERR, "CGI_prefork_server(): could not read " "environment"); } /* close socket and restore environment */ if ( freopen("/dev/null", "r", stdin) != 0 ) printf("freopen3 error\n"); if ( freopen("/dev/null", "w", stdout) != 0 ) printf("freopen4 error\n"); environ = realenv; if (tmpenv != 0) { free(tmpbuf); free(tmpenv); } /* notify parent we are idle */ message.state = SCORE_IDLE; if ( write(pfd[1], &message, sizeof(message)) != sizeof(message) ) printf("write2 error\n"); } _exit(0); }