int main(int argc, string argv[]) { string *mdtab, *names, *exprs, prog; int nexp = 0, i, j; initparam(argv, defv); mdtab = getmapdefs(); // get list of mapping vars for (i = 0; mdtab[i] != NULL; i += 2) if (getparamstat(mdtab[i]) & ARGPARAM) // if var has assigned value nexp++; eprintf("[%s: %scounted %d variable assignments]\n", getprog(), nexp > 0 ? "" : "warning: ", nexp); names = (string *) allocate(sizeof(string *) * (nexp + 1)); exprs = (string *) allocate(sizeof(string *) * (nexp + 1)); for (i = j = 0; mdtab[i] != NULL; i += 2) if (getparamstat(mdtab[i]) & ARGPARAM) { // if var has assigned value exprs[j] = getparam(mdtab[i]); // list value given as expr names[j] = mdtab[i+1]; // and name of access macro j++; } exprs[j] = names[j] = NULL; prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, NULL, strnull(getparam("t")) ? NULL : getparam("t"), Precision, NDIM, TRUE); execmap(prog); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getargv0(), prog); return (0); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields]; stream xstr, ostr; int nold = -1; initparam(argv, defv); exprs[0] = getparam("group"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); new_field(&GroupField, IntType, "Group"); new_field(&GroupField + 1, NULL, NULL); layout_body(btags, Precision, NDIM); while (get_snap(xstr, &bodytab, &nbody, &tbody, itags, FALSE)) { snaptrak(); put_snap(ostr, &traktab, &ntrak, &tbody, otags); if (ntrak != nold) eprintf("[%s: wrote %d groups at t = %f]\n", getprog(), ntrak, tbody); nold = ntrak; } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getprog(), prog); return (0); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields], otags[MaxBodyFields]; stream xstr, ostr; bodyptr btab = NULL; int nbody; real tnow; initparam(argv, defv); exprs[0] = getparam("weight"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); new_field(&WeightField, RealType, "Weight"); new_field(&WeightField + 1, NULL, NULL); while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) { snaprect(btab, nbody); del_tag(otags, itags, "Weight"); put_snap(ostr, &btab, &nbody, &tnow, otags); } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getargv0(), prog); return (0); }
int main(int argc, string argv[]) { string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields]; stream xstr, ostr; bodyptr btab = NULL, bp; int nbody; real tnow; vector cmpos, cmvel, cmacc; initparam(argv, defv); exprs[0] = getparam("weight"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); coords = getparam("coords"); new_field(&WeightField, RealType, "Weight"); new_field(&WeightField + 1, NULL, NULL); while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) { if (scanopt(coords, PosTag) && set_member(itags, PosTag)) { snapcmpos(cmpos, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Pos(bp), Pos(bp), cmpos); } eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(), cmpos[0], cmpos[1], cmpos[2]); } if (scanopt(coords, VelTag) && set_member(itags, VelTag)) { snapcmvel(cmvel, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Vel(bp), Vel(bp), cmvel); } eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(), cmvel[0], cmvel[1], cmvel[2]); } if (scanopt(coords, AccTag) && set_member(itags, AccTag)) { snapcmacc(cmacc, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Acc(bp), Acc(bp), cmacc); } eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(), cmacc[0], cmacc[1], cmacc[2]); } del_tag(otags, itags, "Weight"); put_snap(ostr, &btab, &nbody, &tnow, otags); } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getprog(), prog); return (0); }
stream execmap(string prog) { int handle[2]; char handbuf[32]; string names[] = { MassTag, NULL }, exprs[] = { NULL, NULL }; exprs[0] = getparam("mass"); buildmap(prog, names, exprs, NULL, NULL, Precision, NDIM, TRUE); pipe(handle); if (fork() == 0) { // if this is child process close(handle[0]); sprintf(handbuf, "-%d", handle[1]); execl(prog, getargv0(), getparam("in"), handbuf, getparam("times"), getparam("require"), MassTag "," PosTag, strnull(getparam("require")) ? "true" : "false", getparam("seed"), NULL); error("%s: execl %s failed\n", getargv0(), prog); } close(handle[1]); sprintf(handbuf, "-%d", handle[0]); return (stropen(handbuf, "r")); }
static void loadfont(int n, int s) { char file[256]; int i, fd, t, deep; static char *try[3] = {"", "times/R.", "pelm/"}; Subfont *f; Font *ff; try[0] = fname[n]; for (t = 0; t < 3; t++) { i = s * mag * charmap[fmap[n]].xheight/0.72; /* a pixel is 0.72 points */ if (i < MINSIZE) i = MINSIZE; dprint(2, "size %d, i %d, mag %g\n", s, i, mag); for(; i >= MINSIZE; i--) { /* if .font file exists, take that */ snprint(file, sizeof file, "%s/%s%d.font", libfont, try[t], i); ff = openfont(display, file); if(ff != 0) { fonttab[n][s] = ff; dprint(2, "using %s for font %d %d\n", file, n, s); return; } /* else look for a subfont file */ for (deep = log2[screen->depth]; deep >= 0; deep--) { snprint(file, sizeof file, "%s/%s%d.%d", libfont, try[t], i, deep); dprint(2, "trying %s for %d\n", file, i); if ((fd = open(file, 0)) >= 0) { f = readsubfont(display, file, fd, 0); if (f == 0) { fprint(2, "can't rdsubfontfile %s: %r\n", file); exits("rdsubfont"); } close(fd); ff = mkfont(f, 0); if(ff == 0) { fprint(2, "can't mkfont %s: %r\n", file); exits("rdsubfont"); } fonttab[n][s] = ff; dprint(2, "using %s for font %d %d\n", file, n, s); return; } } } } fprint(2, "can't find font %s.%d or substitute, quitting\n", fname[n], s); exits("no font"); } void loadfontname(int n, char *s) { int i; Font *f, *g = 0; if (strcmp(s, fname[n]) == 0) return; if(fname[n] && fname[n][0]) { if(lastload[n] && strcmp(lastload[n], fname[n]) == 0) return; strcpy(lastload[n], fname[n]); } fontlookup(n, s); for (i = 0; i < NSIZE; i++) if (f = fonttab[n][i]) { if (f != g) { freefont(f); g = f; } fonttab[n][i] = 0; } } void allfree(void) { int i; for (i=0; i<NFONT; i++) loadfontname(i, "??"); } void readmapfile(char *file) { Biobuf *fp; char *p, cmd[100]; if ((fp=Bopen(file, OREAD)) == 0) { fprint(2, "proof: can't open map file %s\n", file); exits("urk"); } while((p=Brdline(fp, '\n')) != 0) { p[Blinelen(fp)-1] = 0; scanstr(p, cmd, 0); if(p[0]=='\0' || eq(cmd, "#")) /* skip comments, empty */ continue; else if(eq(cmd, "xheight")) buildxheight(fp); else if(eq(cmd, "map")) buildmap(fp); else if(eq(cmd, "special")) buildtroff(p); else if(eq(cmd, "troff")) buildtroff(p); else fprint(2, "weird map line %s\n", p); } Bterm(fp); }
int game(SDL_Surface* Screen, int score) { int keep=1; int timebg=0, time=0; int sizesnake = 1; int direction = RIGHT; int i=0, j=0; SDL_Surface *Wall = NULL, *Snake = NULL, *Empty = NULL, *Mush; SDL_Rect position; position.x; position.y; int map[BLOCK_WIDTH][BLOCK_HEIGHT]= {{0}}; SDL_Event event; Snake = SDL_LoadBMP("BodySnake.bmp"); Wall = SDL_LoadBMP("Wall.bmp"); Empty = SDL_LoadBMP("MorceauFond.bmp"); Mush = SDL_LoadBMP("mush.bmp"); buildmap(map); while (keep) { SDL_PollEvent(&event); switch(event.type) { case SDL_QUIT: keep = 0; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_DOWN: direction = BOT; break; case SDLK_UP: direction = TOP; break; case SDLK_LEFT: direction = LEFT; break; case SDLK_RIGHT: direction = RIGHT; break; case SDLK_ESCAPE: keep = 0; break; default: break; } break; } time = SDL_GetTicks(); if ( (time - timebg) > 80 ) { keep = movement(map , direction, sizesnake); timebg=time; } BlitAll(map, Screen, Wall ,Empty, Snake, Mush); SDL_Flip(Screen); } SDL_Surface *Echec = NULL;//chargement de l'écran en cas d'échec SDL_Rect posEchec; posEchec.x = 0; posEchec.y = 0; Echec = SDL_LoadBMP("Echec.bmp"); SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format, 0, 0, 0)); SDL_BlitSurface(Echec, NULL, Screen, &posEchec); SDL_Flip(Screen); return EXIT_SUCCESS; }