static void print_counts(perf_event_desc_t *fds, int num) { int i; read_groups(fds, num); for(i=0; i < num; i++) { double ratio; uint64_t val; val = fds[i].value - fds[i].prev_value; ratio = 0.0; if (fds[i].enabled) ratio = 1.0 * fds[i].running / fds[i].enabled; /* separate groups */ if (perf_is_group_leader(fds, i)) putchar('\n'); if (fds[i].value < fds[i].prev_value) { printf("inconsistent scaling %s (cur=%'"PRIu64" : prev=%'"PRIu64")\n", fds[i].name, fds[i].value, fds[i].prev_value); continue; } printf("%'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n", val, fds[i].name, (1.0-ratio)*100.0, fds[i].enabled, fds[i].running); } }
ItemDefinition read_item_definition(lua_State *L, int index, ItemDefinition default_def) { if(index < 0) index = lua_gettop(L) + 1 + index; // Read the item definition ItemDefinition def = default_def; def.type = (ItemType)getenumfield(L, index, "type", es_ItemType, ITEM_NONE); getstringfield(L, index, "name", def.name); getstringfield(L, index, "description", def.description); getstringfield(L, index, "inventory_image", def.inventory_image); getstringfield(L, index, "wield_image", def.wield_image); lua_getfield(L, index, "wield_scale"); if(lua_istable(L, -1)){ def.wield_scale = check_v3f(L, -1); } lua_pop(L, 1); def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max); if(def.stack_max == 0) def.stack_max = 1; lua_getfield(L, index, "on_use"); def.usable = lua_isfunction(L, -1); lua_pop(L, 1); getboolfield(L, index, "liquids_pointable", def.liquids_pointable); warn_if_field_exists(L, index, "tool_digging_properties", "deprecated: use tool_capabilities"); lua_getfield(L, index, "tool_capabilities"); if(lua_istable(L, -1)){ def.tool_capabilities = new ToolCapabilities( read_tool_capabilities(L, -1)); } // If name is "" (hand), ensure there are ToolCapabilities // because it will be looked up there whenever any other item has // no ToolCapabilities if(def.name == "" && def.tool_capabilities == NULL){ def.tool_capabilities = new ToolCapabilities(); } lua_getfield(L, index, "groups"); read_groups(L, -1, def.groups); lua_pop(L, 1); // Client shall immediately place this node when player places the item. // Server will update the precise end result a moment later. // "" = no prediction getstringfield(L, index, "node_placement_prediction", def.node_placement_prediction); return def; }
static void print_counts(perf_event_desc_t *fds, int num) { int i; unsigned long int values[10]; read_groups(fds, num); for(i=0; i < num; i++) { double ratio; unsigned long int val; val = fds[i].value - fds[i].prev_value; ratio = 0.0; if (fds[i].enabled) ratio = 1.0 * fds[i].running / fds[i].enabled; /* separate groups */ /*if (perf_is_group_leader(fds, i)) putchar('\n');*/ // if (fds[i].value < fds[i].prev_value) { // fprintf(output_file, "inconsistent scaling %s (cur=%'"PRIu64" : prev=%'"PRIu64")\n", fds[i].name, fds[i].value, fds[i].prev_value); // continue; // } values[i] = val; /*printf("%'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n", val, fds[i].name, (1.0-ratio)*100.0, fds[i].enabled, fds[i].running);*/ } /*if (acc_cycles == 0) { acc_cycles = values[0]; } else { acc_cycles += values[0]; }*/ //for(i=0; i < num; i++) { // printf("%lu \t %lu \t %lu \t %.2f\n", output_file = fopen(file_name, "w"); //fprintf(output_file, "%lu\t%lu\t%lu\n", fprintf(output_file, "%lu\t%lu\n", values[0], //values[1], // values[2], values[1]); // fflush(output_file); //} fclose(output_file); }
// get_hit_params(groups, tool_capabilities[, time_from_last_punch]) static int l_get_hit_params(lua_State *L) { std::map<std::string, int> groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) push_hit_params(L, getHitParams(groups, &tp)); else push_hit_params(L, getHitParams(groups, &tp, luaL_checknumber(L, 3))); return 1; }
// set_armor_groups(self, groups) int ObjectRef::l_set_armor_groups(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; // Do it ItemGroupList groups; read_groups(L, 2, groups); co->setArmorGroups(groups); return 0; }
// get_dig_params(groups, tool_capabilities[, time_from_last_punch]) int ModApiUtil::l_get_dig_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; ItemGroupList groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) push_dig_params(L, getDigParams(groups, &tp)); else push_dig_params(L, getDigParams(groups, &tp, luaL_checknumber(L, 3))); return 1; }
// get_hit_params(groups, tool_capabilities[, time_from_last_punch]) int ModApiUtil::l_get_hit_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; std::map<std::string, int> groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) push_hit_params(L, getHitParams(groups, &tp)); else push_hit_params(L, getHitParams(groups, &tp, luaL_checknumber(L, 3))); return 1; }
static void test_group_readwrite(CuTest * tc) { faction * f; group *g; ally *al; int i; gamedata data; storage store; test_cleanup(); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); f = test_create_faction(0); new_group(f, "NW", 42); g = new_group(f, "Egoisten", 43); key_set(&g->attribs, 44); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); WRITE_INT(&store, 47); free_group(f->groups); free_group(g); f->groups = 0; data.strm.api->rewind(data.strm.handle); read_groups(&data, f); READ_INT(&store, &i); mstream_done(&data.strm); gamedata_done(&data); CuAssertIntEquals(tc, 47, i); CuAssertPtrNotNull(tc, f->groups); CuAssertIntEquals(tc, 42, f->groups->gid); CuAssertStrEquals(tc, "NW", f->groups->name); CuAssertPtrNotNull(tc, f->groups->next); CuAssertIntEquals(tc, 43, f->groups->next->gid); CuAssertStrEquals(tc, "Egoisten", f->groups->next->name); CuAssertPtrEquals(tc, 0, f->groups->allies); g = f->groups->next; CuAssertTrue(tc, key_get(g->attribs, 44)); CuAssertPtrNotNull(tc, g->allies); CuAssertPtrEquals(tc, 0, g->allies->next); CuAssertPtrEquals(tc, f, g->allies->faction); CuAssertIntEquals(tc, HELP_GIVE, g->allies->status); test_cleanup(); }
static bool weston_launch_allowed(struct weston_launch *wl) { struct group *gr; gid_t *groups; int i; #ifdef HAVE_SYSTEMD_LOGIN char *session, *seat; int err; #endif if (getuid() == 0) return true; gr = getgrnam("weston-launch"); if (gr) { groups = read_groups(); if (groups) { for (i = 0; groups[i]; ++i) { if (groups[i] == gr->gr_gid) { free(groups); return true; } } free(groups); } } #ifdef HAVE_SYSTEMD_LOGIN err = sd_pid_get_session(getpid(), &session); if (err == 0 && session) { if (sd_session_is_active(session) && sd_session_get_seat(session, &seat) == 0) { free(seat); free(session); return true; } free(session); } #endif return false; }
static void print_counts(perf_event_desc_t *fds, int num) { double ratio; uint64_t val, delta; int i; read_groups(fds, num); for(i=0; i < num; i++) { val = perf_scale(fds[i].values); delta = perf_scale_delta(fds[i].values, fds[i].prev_values); ratio = perf_scale_ratio(fds[i].values); /* separate groups */ if (perf_is_group_leader(fds, i)) putchar('\n'); if (options.print) printf("%'20"PRIu64" %'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n", val, delta, fds[i].name, (1.0-ratio)*100.0, fds[i].values[1], fds[i].values[2]); else printf("%'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n", val, fds[i].name, (1.0-ratio)*100.0, fds[i].values[1], fds[i].values[2]); fds[i].prev_values[0] = fds[i].values[0]; fds[i].prev_values[1] = fds[i].values[1]; fds[i].prev_values[2] = fds[i].values[2]; } }
static void test_group_readwrite(CuTest * tc) { faction * f; group *g; ally *al; storage store; FILE *F; stream strm; F = fopen("test.dat", "wb"); fstream_init(&strm, F); binstore_init(&store, &strm); test_cleanup(); test_create_world(); f = test_create_faction(0); g = new_group(f, "test", 42); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); binstore_done(&store); fstream_done(&strm); F = fopen("test.dat", "rb"); fstream_init(&strm, F); binstore_init(&store, &strm); f->groups = 0; free_group(g); read_groups(&store, f); binstore_done(&store); fstream_done(&strm); CuAssertPtrNotNull(tc, f->groups); CuAssertPtrNotNull(tc, f->groups->allies); CuAssertPtrEquals(tc, 0, f->groups->allies->next); CuAssertPtrEquals(tc, f, f->groups->allies->faction); CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status); remove("test.dat"); test_cleanup(); }
serve() { char line[NNTP_STRLEN]; char host[MAXHOSTNAMELEN]; char gdbuf[MAXBUFLEN]; char **argp; char *timeptr, *cp; int argnum, i; double Tstart, Tfinish; double user, sys; #ifdef USG time_t start, finish; #else not USG struct timeval start, finish; #endif not USG extern char *ctime(); #ifdef POSTER struct passwd *pp; #endif #ifdef LOG # ifdef USG struct tms cpu; # else not USG struct rusage me, kids; # endif not USG # ifdef TIMEOUT void timeout(); # endif grps_acsd = arts_acsd = 0; #endif /* Not all systems pass fd's 1 and 2 from inetd */ (void) close(1); (void) close(2); (void) dup(0); (void) dup(0); /* If we're ALONE, then we've already opened syslog */ #ifndef ALONE # ifdef SYSLOG # ifdef BSD_42 openlog("nntpd", LOG_PID); # else openlog("nntpd", LOG_PID, SYSLOG); # endif # endif #endif #ifdef ALONE #ifndef USG (void) signal(SIGCHLD, SIG_IGN); #endif not USG #endif /* Ignore SIGPIPE, since we'll see closed connections with read */ (void) signal(SIGPIPE, SIG_IGN); /* Get permissions and see if we can talk to this client */ host_access(&canread, &canpost, &canxfer, gdbuf); if (gethostname(host, sizeof(host)) < 0) (void) strcpy(host, "Amnesiac"); if (!canread && !canxfer) { printf("%d %s NNTP server can't talk to you. Goodbye.\r\n", ERR_ACCESS, host); (void) fflush(stdout); #ifdef LOG syslog(LOG_INFO, "%s refused connection", hostname); #endif exit(1); } /* If we can talk, proceed with initialization */ ngpermcount = get_nglist(&ngpermlist, gdbuf); #ifdef POSTER pp = getpwnam(POSTER); if (pp != NULL) { uid_poster = pp->pw_uid; gid_poster = pp->pw_gid; } else #endif uid_poster = gid_poster = 0; #ifndef FASTFORK num_groups = 0; num_groups = read_groups(); /* Read in the active file */ #else signal(SIGALRM, SIG_IGN); /* Children don't deal with */ /* these things */ #endif art_fp = NULL; argp = (char **) NULL; /* for first time */ #ifdef USG (void) time(&start); Tstart = (double) start; timeptr = ctime(&start); #else not USG (void) gettimeofday(&start, (struct timezone *)NULL); Tstart = (double) start.tv_sec - ((double)start.tv_usec)/1000000.0; timeptr = ctime(&start.tv_sec); #endif not USG if ((cp = index(timeptr, '\n')) != NULL) *cp = '\0'; else timeptr = "Unknown date"; printf("%d %s NNTP server version %s ready at %s (%s).\r\n", canpost ? OK_CANPOST : OK_NOPOST, host, nntp_version, timeptr, canpost ? "posting ok" : "no posting"); (void) fflush(stdout); /* * Now get commands one at a time and execute the * appropriate routine to deal with them. */ #ifdef TIMEOUT (void) signal(SIGALRM, timeout); (void) alarm(TIMEOUT); #endif TIMEOUT while (fgets(line, sizeof(line), stdin) != NULL) { #ifdef TIMEOUT (void) alarm(0); #endif TIMEOUT cp = index(line, '\r'); /* Zap CR-LF */ if (cp != NULL) *cp = '\0'; else { cp = index(line, '\n'); if (cp != NULL) *cp = '\0'; } if ((argnum = parsit(line, &argp)) == 0) continue; /* Null command */ else { for (i = 0; i < NUMCMDS; ++i) if (!strcasecmp(cmdtbl[i].cmd_name, argp[0])) break; if (i < NUMCMDS) (*cmdtbl[i].cmd_fctn)(argnum, argp); else { if (!strcasecmp(argp[0], "quit")) break; #ifdef LOG syslog(LOG_INFO, "%s unrecognized %s", hostname, line); #endif printf("%d Command unrecognized.\r\n", ERR_COMMAND); (void) fflush(stdout); } } #ifdef TIMEOUT (void) alarm(TIMEOUT); #endif TIMEOUT } printf("%d %s closing connection. Goodbye.\r\n", OK_GOODBYE, host); (void) fflush(stdout); #ifdef LOG if (ferror(stdout)) syslog(LOG_ERR, "%s disconnect: %m", hostname); #ifdef USG (void) time(&finish); Tfinish = (double) finish; #ifndef HZ #define HZ 60.0 /* typical system clock ticks - param.h */ #endif not HZ (void) times(&cpu); user = (double)(cpu.tms_utime + cpu.tms_cutime) / HZ; sys = (double)(cpu.tms_stime + cpu.tms_cstime) / HZ; #else not USG (void) gettimeofday(&finish, (struct timezone *)NULL); Tfinish = (double) finish.tv_sec - ((double)finish.tv_usec)/1000000.0; (void) getrusage(RUSAGE_SELF, &me); (void) getrusage(RUSAGE_CHILDREN, &kids); user = (double) me.ru_utime.tv_sec + me.ru_utime.tv_usec/1000000.0 + kids.ru_utime.tv_sec + kids.ru_utime.tv_usec/1000000.0; sys = (double) me.ru_stime.tv_sec + me.ru_stime.tv_usec/1000000.0 + kids.ru_stime.tv_sec + kids.ru_stime.tv_usec/1000000.0; #endif not USG if (grps_acsd) syslog(LOG_INFO, "%s exit %d articles %d groups", hostname, arts_acsd, grps_acsd); if (nn_told) syslog(LOG_INFO, "%s newnews_stats told %d took %d", hostname, nn_told, nn_took); if (ih_accepted || ih_rejected || ih_failed) syslog(LOG_INFO, "%s ihave_stats accepted %d rejected %d failed %d", hostname, ih_accepted, ih_rejected, ih_failed); (void) sprintf(line, "user %.1f system %.1f elapsed %.1f", user, sys, Tfinish - Tstart); syslog(LOG_INFO, "%s times %s", hostname, line); #endif LOG #ifdef PROFILE profile(); #endif exit(0); }
main() { #ifdef ALONE /* If no inetd */ int sockt, client, length; struct sockaddr_in from; extern int reaper(); disassoc(); /* fd 0-2 should be open and point to / now. */ #ifdef SYSLOG #ifdef BSD_42 openlog("nntpd", LOG_PID); /* fd 3 */ #else openlog("nntpd", LOG_PID, SYSLOG); /* fd 3 */ #endif #endif #ifdef FASTFORK num_groups = read_groups(); /* Read active file now (fd 4) */ /* and then do it every */ set_timer(); /* so often later */ #endif #ifndef EXCELAN sockt = get_socket(); /* should be fd 4 or 5 */ #endif #ifndef USG (void) signal(SIGCHLD, reaper); #endif #ifndef EXCELAN if (listen(sockt, SOMAXCONN) < 0) { #ifdef SYSLOG syslog(LOG_ERR, "main: listen: %m"); #endif exit(1); } #endif for (;;) { #ifdef EXCELAN int status; sockt = get_socket(); if (sockt < 0) continue; client = accept(sockt, &from); #else length = sizeof (from); client = accept(sockt, &from, &length); #endif EXCELAN if (client < 0) { #ifdef SYSLOG if (errno != EINTR) syslog(LOG_ERR, "accept: %m\n"); #endif #ifdef EXCELAN close(sockt); sleep(1); #endif continue; } switch (fork()) { case -1: #ifdef SYSLOG syslog(LOG_ERR, "fork: %m\n"); #endif #ifdef EXCELAN (void) close(sockt); #endif (void) close(client); break; case 0: #ifdef EXCELAN if (fork()) exit(0); bcopy(&from,¤t_peer,sizeof(from)); make_stdio(sockt); #else (void) close(sockt); make_stdio(client); #endif serve(); break; default: #ifdef EXCELAN (void) close(sockt); (void) wait(&status); #else (void) close(client); #endif break; } } #else /* We have inetd */ serve(); #endif }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char dir[256]; char *snapshot_fname = NULL, *fof_fname = NULL, *groups_fname = NULL, *gmap_fname = NULL; int files; float fPeriodf1,fPeriodf2,fPeriodf3,fEpsf; int i,nf; int *pmap; /* A map between a particle and the group it is in */ int nGroups, nMapGroups, Ngroups; group_t *groups; gmap_t *gmap; int mode = DO_NOTHING; /*======================================================================= * Parse command line arguments *=====================================================================*/ for (i=1; i < argc; i++) { if (!strcmp("--make-fof", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); mode = MAKE_FOF; } else if (!strcmp("--make-groups", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); mode = MAKE_GROUPS; } else if (!strcmp("--make-tree", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) groups_fname = argv[i]; else help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); if (++i < argc) gmap_fname = argv[i]; else help(); mode = MAKE_TREE; } else if (!strcmp("-M", argv[i])) { if (++i < argc) MassMin = atof(argv[i]); else help(); if (++i < argc) MassMax = atof(argv[i]); else help(); } else if (!strcmp("-nmin", argv[i])) { if (++i < argc) nMin = atof(argv[i]); else help(); } } /*======================================================================= * Check that the user gave us sensible parameters *=====================================================================*/ if (mode == DO_NOTHING) help(); /*======================================================================= * Load in the snapshot (GADGET format) *=====================================================================*/ files=1; /* number of files per snapshot */ fprintf(stderr, "Loading snapshot %s.\n", snapshot_fname); load_snapshot(snapshot_fname, files); printf("Npart: %d; Time: %lf; Redshift: %lf\n",NumPart,header1.time, header1.redshift); nf=NumPart; printf("First particle: %f %f %f \n",P[1].Pos[0],P[1].Pos[1],P[1].Pos[2]); printf("Medium particle: %f %f %f \n",P[nf/2].Pos[0],P[nf/2].Pos[1],P[nf/2].Pos[2]); printf("Last particle: %f %f %f \n",P[nf].Pos[0],P[nf].Pos[1],P[nf].Pos[2]); /*======================================================================= * Prepare to either create or load the FOF data *=====================================================================*/ fEpsf = header1.BoxSize/ pow( NumPart, 1./3.); printf("Distanza interparticellare media: %f\n",fEpsf); fEpsf *= 0.2; /* fEpsf *= 0.15; */ /* fEpsf *= 0.1; */ fPeriodf1=fPeriodf2=fPeriodf3=(float) header1.BoxSize; pmap=malloc((NumPart+1)*sizeof(int)); if(pmap==NULL) { printf("Errore di allocazione memoria indici.\n"); exit(-1); } /* LE UNITA' NATURALI GADGET LAVORANO IN 10^10 MSOL. SE SONO STATE CAMBIATE, OCCORRE MODIFICARE QUI */ if (MassMin != -1 && MassMax != -1) { fprintf(stderr, "Mass range: [%2.2e,%2.2e]\n", MassMin, MassMax); MassMin /= UdM; MassMax /= UdM; } else { fprintf(stderr, "Mass range: Unbounded\n"); MassMin = 0; MassMax = 1e33; } switch (mode) { case MAKE_FOF: fprintf(stderr, "Making FOFs.\n"); fof_(fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,P,pmap); write_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap); break; case MAKE_GROUPS: fprintf(stderr, "Making Groups.\n"); if (read_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap)) exit(1); EvalGroups0(pmap,snapshot_fname); break; case MAKE_TREE: fprintf(stderr, "Making Progenitor Trees.\n"); if (read_groups(groups_fname, &groups, &nGroups)) exit(1); if (read_gmap(gmap_fname, &gmap, &nMapGroups)) exit(1); /*======================================================================= * Sanity check that the group files match up. *=====================================================================*/ #if 0 if (nGroups != nMapGroups) { fprintf(stderr, "Mismatched number of groups between group and map files (%i != %i).\n", nGroups, nMapGroups); exit(1); } #endif #if 0 int nPartInGroups=0, nPartInMap=0; for (i=0; i < nGroups; i++) { nPartInGroups += groups[i].npart; nPartInMap += gmap[i].npart; } fprintf(stderr, "HERE 4\n"); if (nGroups != nMapGroups) { fprintf(stderr, "Mismatched number of particles between group and map files.\n"); exit(1); } #endif /*======================================================================= * Now load the particle->group map. *=====================================================================*/ if (read_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap)) exit(1); //sonidx=malloc( (NumPart+1)*sizeof(int)); //npson=load_son_idx(sonidx, index_fname); //if(npson <= 0) { printf("ERROR: group non find.\n"); exit(-1); } //printf("<<Son>> group with %d particles loaded.\n",npson); mkdir("GROUPS", -1); assert(!chdir("GROUPS")); Ngroups = EvalGroups1(pmap); chdir(".."); gmap_t *gmap2 = (gmap_t *)calloc(Ngroups+1, sizeof(gmap_t)); for (i=1; i < NumPart+1; i++) gmap2[pmap[i]].npart++; for (i=0; i < Ngroups+1; i++) { gmap2[i].ps = (int *)malloc(gmap2[i].npart * sizeof(int)); assert(gmap2[i].ps != NULL); gmap2[i].npart = 0; } for (i=1; i < NumPart+1; i++) { gmap2[pmap[i]].ps[ gmap2[pmap[i]].npart++ ] = i; } #if 1 printf("Finding progenitors with mass %%: %f\n",PROGPERC); for (i=0; i < nGroups; i++) { //fprintf(stderr, "Group %i [Mass: %f]\n", i, groups[i].Mass); #if 1 if (MassMin != -1 && MassMax != -1) { if (!(MassMin < groups[i].Mass && groups[i].Mass < MassMax)) { fprintf(stderr, "Outside mass range. Group %i/%i.\n", i+1, nGroups+1);; continue; } } snprintf(dir, 256, "%05i", groups[i].id); fprintf(stderr, "Making directory %s. Group %i/%i.\n", dir, i+1, nGroups+1);; mkdir(dir, -1); assert(!chdir(dir)); int *ps = NULL; int npart = 0; int j; for (j=0; j < nMapGroups; j++) { if (groups[i].id == gmap[j].gid) { assert(ps == NULL); ps = gmap[j].ps; npart = gmap[j].npart; assert(groups[i].npart == gmap[j].npart); /* Intentionally not breaking here to check the assert()'ion if there * is somehow a duplicate groups. */ } } assert(ps != NULL); EvalProgenitors(snapshot_fname, pmap, ps, npart, Ngroups, gmap2, Ngroups); chdir(".."); #endif } #endif break; default: fprintf(stderr, "Unknown internal mode: %i\n", mode); exit(1); } return 0; }
ContentFeatures read_content_features(lua_State *L, int index) { if(index < 0) index = lua_gettop(L) + 1 + index; ContentFeatures f; /* Cache existence of some callbacks */ lua_getfield(L, index, "on_construct"); if(!lua_isnil(L, -1)) f.has_on_construct = true; lua_pop(L, 1); lua_getfield(L, index, "on_destruct"); if(!lua_isnil(L, -1)) f.has_on_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "after_destruct"); if(!lua_isnil(L, -1)) f.has_after_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "on_rightclick"); f.rightclickable = lua_isfunction(L, -1); lua_pop(L, 1); /* Name */ getstringfield(L, index, "name", f.name); /* Groups */ lua_getfield(L, index, "groups"); read_groups(L, -1, f.groups); lua_pop(L, 1); /* Visual definition */ f.drawtype = (NodeDrawType)getenumfield(L, index, "drawtype", ScriptApiNode::es_DrawType,NDT_NORMAL); getfloatfield(L, index, "visual_scale", f.visual_scale); // tiles = {} lua_getfield(L, index, "tiles"); // If nil, try the deprecated name "tile_images" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "tile_images", "Deprecated; new name is \"tiles\"."); lua_getfield(L, index, "tile_images"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef[i] = read_tiledef(L, -1); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==6){ lua_pop(L, 1); break; } } // Copy last value to all remaining textures if(i >= 1){ TileDef lasttile = f.tiledef[i-1]; while(i < 6){ f.tiledef[i] = lasttile; i++; } } } lua_pop(L, 1); // special_tiles = {} lua_getfield(L, index, "special_tiles"); // If nil, try the deprecated name "special_materials" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "special_materials", "Deprecated; new name is \"special_tiles\"."); lua_getfield(L, index, "special_materials"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef_special[i] = read_tiledef(L, -1); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==6){ lua_pop(L, 1); break; } } } lua_pop(L, 1); f.alpha = getintfield_default(L, index, "alpha", 255); bool usealpha = getboolfield_default(L, index, "use_texture_alpha", false); if (usealpha) f.alpha = 0; /* Other stuff */ lua_getfield(L, index, "post_effect_color"); if(!lua_isnil(L, -1)) f.post_effect_color = readARGB8(L, -1); lua_pop(L, 1); f.param_type = (ContentParamType)getenumfield(L, index, "paramtype", ScriptApiNode::es_ContentParamType, CPT_NONE); f.param_type_2 = (ContentParamType2)getenumfield(L, index, "paramtype2", ScriptApiNode::es_ContentParamType2, CPT2_NONE); // Warn about some deprecated fields warn_if_field_exists(L, index, "wall_mounted", "deprecated: use paramtype2 = 'wallmounted'"); warn_if_field_exists(L, index, "light_propagates", "deprecated: determined from paramtype"); warn_if_field_exists(L, index, "dug_item", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item_rarity", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "metadata_name", "deprecated: use on_add and metadata callbacks"); // True for all ground-like things like stone and mud, false for eg. trees getboolfield(L, index, "is_ground_content", f.is_ground_content); f.light_propagates = (f.param_type == CPT_LIGHT); getboolfield(L, index, "sunlight_propagates", f.sunlight_propagates); // This is used for collision detection. // Also for general solidness queries. getboolfield(L, index, "walkable", f.walkable); // Player can point to these getboolfield(L, index, "pointable", f.pointable); // Player can dig these getboolfield(L, index, "diggable", f.diggable); // Player can climb these getboolfield(L, index, "climbable", f.climbable); // Player can build on these getboolfield(L, index, "buildable_to", f.buildable_to); // Whether the node is non-liquid, source liquid or flowing liquid f.liquid_type = (LiquidType)getenumfield(L, index, "liquidtype", ScriptApiNode::es_LiquidType, LIQUID_NONE); // If the content is liquid, this is the flowing version of the liquid. getstringfield(L, index, "liquid_alternative_flowing", f.liquid_alternative_flowing); // If the content is liquid, this is the source version of the liquid. getstringfield(L, index, "liquid_alternative_source", f.liquid_alternative_source); // Viscosity for fluid flow, ranging from 1 to 7, with // 1 giving almost instantaneous propagation and 7 being // the slowest possible f.liquid_viscosity = getintfield_default(L, index, "liquid_viscosity", f.liquid_viscosity); f.liquid_range = getintfield_default(L, index, "liquid_range", f.liquid_range); f.leveled = getintfield_default(L, index, "leveled", f.leveled); getboolfield(L, index, "liquid_renewable", f.liquid_renewable); getstringfield(L, index, "freezemelt", f.freezemelt); f.drowning = getintfield_default(L, index, "drowning", f.drowning); // Amount of light the node emits f.light_source = getintfield_default(L, index, "light_source", f.light_source); f.damage_per_second = getintfield_default(L, index, "damage_per_second", f.damage_per_second); lua_getfield(L, index, "node_box"); if(lua_istable(L, -1)) f.node_box = read_nodebox(L, -1); lua_pop(L, 1); lua_getfield(L, index, "selection_box"); if(lua_istable(L, -1)) f.selection_box = read_nodebox(L, -1); lua_pop(L, 1); // Set to true if paramtype used to be 'facedir_simple' getboolfield(L, index, "legacy_facedir_simple", f.legacy_facedir_simple); // Set to true if wall_mounted used to be set to true getboolfield(L, index, "legacy_wallmounted", f.legacy_wallmounted); // Sound table lua_getfield(L, index, "sounds"); if(lua_istable(L, -1)){ lua_getfield(L, -1, "footstep"); read_soundspec(L, -1, f.sound_footstep); lua_pop(L, 1); lua_getfield(L, -1, "dig"); read_soundspec(L, -1, f.sound_dig); lua_pop(L, 1); lua_getfield(L, -1, "dug"); read_soundspec(L, -1, f.sound_dug); lua_pop(L, 1); } lua_pop(L, 1); return f; }
ContentFeatures read_content_features(lua_State *L, int index) { if(index < 0) index = lua_gettop(L) + 1 + index; ContentFeatures f; /* Cache existence of some callbacks */ lua_getfield(L, index, "on_construct"); if(!lua_isnil(L, -1)) f.has_on_construct = true; lua_pop(L, 1); lua_getfield(L, index, "on_destruct"); if(!lua_isnil(L, -1)) f.has_on_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "after_destruct"); if(!lua_isnil(L, -1)) f.has_after_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "on_activate"); if(!lua_isnil(L, -1)) { f.has_on_activate = true; f.is_circuit_element = true; } lua_pop(L, 1); lua_getfield(L, index, "on_deactivate"); if(!lua_isnil(L, -1)) { f.has_on_deactivate = true; f.is_circuit_element = true; } lua_pop(L, 1); lua_getfield(L, index, "on_rightclick"); f.rightclickable = lua_isfunction(L, -1); lua_pop(L, 1); /* Name */ getstringfield(L, index, "name", f.name); /* Groups */ lua_getfield(L, index, "groups"); read_groups(L, -1, f.groups); lua_pop(L, 1); /* Visual definition */ f.drawtype = (NodeDrawType)getenumfield(L, index, "drawtype", ScriptApiNode::es_DrawType,NDT_NORMAL); getfloatfield(L, index, "visual_scale", f.visual_scale); /* Meshnode model filename */ getstringfield(L, index, "mesh", f.mesh); // tiles = {} lua_getfield(L, index, "tiles"); // If nil, try the deprecated name "tile_images" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "tile_images", "Deprecated; new name is \"tiles\"."); lua_getfield(L, index, "tile_images"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef[i] = read_tiledef(L, -1); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==6){ lua_pop(L, 1); break; } } // Copy last value to all remaining textures if(i >= 1){ TileDef lasttile = f.tiledef[i-1]; while(i < 6){ f.tiledef[i] = lasttile; i++; } } } lua_pop(L, 1); /* Circuit options */ lua_getfield(L, index, "is_wire"); if(!lua_isnil(L, -1)) { f.is_wire = true; } lua_pop(L, 1); lua_getfield(L, index, "is_wire_connector"); if(!lua_isnil(L, -1)) { f.is_wire_connector = true; } lua_pop(L, 1); lua_getfield(L, index, "wire_connections"); if(!lua_isnil(L, -1) && lua_istable(L, -1)) { // Both can't be set to true f.is_wire |= !f.is_wire_connector; int table = lua_gettop(L); lua_pushnil(L); int i; unsigned char current_shift = 1; for(i = 0; (i < 6) && (lua_next(L, table) != 0); ++i) { f.wire_connections[i] = lua_tonumber(L, -1); f.wire_connections[i] |= current_shift; current_shift <<= 1; lua_pop(L, 1); } if(i < 6) { luaL_error(L, "Wire connectins array must have exactly 6 integer numbers."); } // Convert to two-way wire (one-way may cause undefined behavior) for(i = 0; i < 6; ++i) { for(int j = 0; j < 6; ++j) { f.wire_connections[i] |= f.wire_connections[j] & (1 << i); f.wire_connections[j] |= f.wire_connections[i] & (1 << j); } } } else if(f.is_wire || f.is_wire_connector) { // Assuming that it's a standart wire or wire connector for(int i = 0; i < 6; ++i) { f.wire_connections[i] = 0x3F; } } lua_pop(L, 1); lua_getfield(L, index, "circuit_states"); if(!lua_isnil(L, -1) && lua_istable(L, -1)) { f.is_circuit_element = true; int table = lua_gettop(L); lua_pushnil(L); int i; for(i = 0; (i < 64) && (lua_next(L, table) != 0); ++i) { f.circuit_element_func[i] = lua_tonumber(L, -1); lua_pop(L, 1); } if(i < 64) { luaL_error(L, "Circuit element states table must have exactly 64 integer numbers."); } } lua_pop(L, 1); f.circuit_element_delay = getintfield_default(L, index, "circuit_element_delay", f.circuit_element_delay + 1) - 1; if(f.circuit_element_delay > 100) { luaL_error(L, "\"circuit_element_delay\" must be a positive integer number less than 101"); } // special_tiles = {} lua_getfield(L, index, "special_tiles"); // If nil, try the deprecated name "special_materials" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "special_materials", "Deprecated; new name is \"special_tiles\"."); lua_getfield(L, index, "special_materials"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef_special[i] = read_tiledef(L, -1); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==CF_SPECIAL_COUNT){ lua_pop(L, 1); break; } } } lua_pop(L, 1); f.alpha = getintfield_default(L, index, "alpha", 255); bool usealpha = getboolfield_default(L, index, "use_texture_alpha", false); if (usealpha) f.alpha = 0; /* Other stuff */ lua_getfield(L, index, "post_effect_color"); if(!lua_isnil(L, -1)) f.post_effect_color = readARGB8(L, -1); lua_pop(L, 1); f.param_type = (ContentParamType)getenumfield(L, index, "paramtype", ScriptApiNode::es_ContentParamType, CPT_NONE); f.param_type_2 = (ContentParamType2)getenumfield(L, index, "paramtype2", ScriptApiNode::es_ContentParamType2, CPT2_NONE); // Warn about some deprecated fields warn_if_field_exists(L, index, "wall_mounted", "deprecated: use paramtype2 = 'wallmounted'"); warn_if_field_exists(L, index, "light_propagates", "deprecated: determined from paramtype"); warn_if_field_exists(L, index, "dug_item", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item_rarity", "deprecated: use 'drop' field"); warn_if_field_exists(L, index, "metadata_name", "deprecated: use on_add and metadata callbacks"); // True for all ground-like things like stone and mud, false for eg. trees getboolfield(L, index, "is_ground_content", f.is_ground_content); f.light_propagates = (f.param_type == CPT_LIGHT); getboolfield(L, index, "sunlight_propagates", f.sunlight_propagates); // This is used for collision detection. // Also for general solidness queries. getboolfield(L, index, "walkable", f.walkable); // Player can point to these getboolfield(L, index, "pointable", f.pointable); // Player can dig these getboolfield(L, index, "diggable", f.diggable); // Player can climb these getboolfield(L, index, "climbable", f.climbable); // Player can build on these getboolfield(L, index, "buildable_to", f.buildable_to); // Whether the node is non-liquid, source liquid or flowing liquid f.liquid_type = (LiquidType)getenumfield(L, index, "liquidtype", ScriptApiNode::es_LiquidType, LIQUID_NONE); // If the content is liquid, this is the flowing version of the liquid. getstringfield(L, index, "liquid_alternative_flowing", f.liquid_alternative_flowing); // If the content is liquid, this is the source version of the liquid. getstringfield(L, index, "liquid_alternative_source", f.liquid_alternative_source); // Viscosity for fluid flow, ranging from 1 to 7, with // 1 giving almost instantaneous propagation and 7 being // the slowest possible f.liquid_viscosity = getintfield_default(L, index, "liquid_viscosity", f.liquid_viscosity); f.leveled = getintfield_default(L, index, "leveled", f.leveled); getboolfield(L, index, "liquid_renewable", f.liquid_renewable); getstringfield(L, index, "freeze", f.freeze); getstringfield(L, index, "melt", f.melt); f.drowning = getintfield_default(L, index, "drowning", f.drowning); // Amount of light the node emits f.light_source = getintfield_default(L, index, "light_source", f.light_source); f.damage_per_second = getintfield_default(L, index, "damage_per_second", f.damage_per_second); lua_getfield(L, index, "node_box"); if(lua_istable(L, -1)) f.node_box = read_nodebox(L, -1); lua_pop(L, 1); lua_getfield(L, index, "selection_box"); if(lua_istable(L, -1)) f.selection_box = read_nodebox(L, -1); lua_pop(L, 1); lua_getfield(L, index, "collision_box"); if(lua_istable(L, -1)) f.collision_box = read_nodebox(L, -1); lua_pop(L, 1); f.waving = getintfield_default(L, index, "waving", f.waving); // Set to true if paramtype used to be 'facedir_simple' getboolfield(L, index, "legacy_facedir_simple", f.legacy_facedir_simple); // Set to true if wall_mounted used to be set to true getboolfield(L, index, "legacy_wallmounted", f.legacy_wallmounted); // Sound table lua_getfield(L, index, "sounds"); if(lua_istable(L, -1)){ lua_getfield(L, -1, "footstep"); read_soundspec(L, -1, f.sound_footstep); lua_pop(L, 1); lua_getfield(L, -1, "dig"); read_soundspec(L, -1, f.sound_dig); lua_pop(L, 1); lua_getfield(L, -1, "dug"); read_soundspec(L, -1, f.sound_dug); lua_pop(L, 1); } lua_pop(L, 1); return f; }
int main(int argc, Char *argv[]) { pattern_elm ***pattern_array; long tip_count = 0; double ln_maxgrp; double ln_maxgrp1; double ln_maxgrp2; node * p; #ifdef MAC argc = 1; /* macsetup("Treedist", ""); */ argv[0] = "Treedist"; #endif init(argc, argv); emboss_getoptions("ftreedist",argc,argv); /* Initialize option-based variables, then ask for changes regarding their values. */ ntrees = 0.0; lasti = -1; /* read files to determine size of structures we'll be working with */ countcomma(ajStrGetuniquePtr(&phylotrees[0]->Tree),&tip_count); tip_count++; /* countcomma does a raw comma count, tips is one greater */ /* * EWFIX.BUG.756 -- this section may be killed if a good solution * to bug 756 is found * * inside cons.c there are several arrays which are allocated * to size "maxgrp", the maximum number of groups (sets of * tips more closely connected than the rest of the tree) we * can see as the code executes. * * We have two measures we use to determine how much space to * allot: * (1) based on the tip count of the trees in the infile * (2) based on total number of trees in infile, and * * (1) -- Tip Count Method * Since each group is a subset of the set of tips we must * represent at most pow(2,tips) different groups. (Technically * two fewer since we don't store the empty or complete subsets, * but let's keep this simple. * * (2) -- Total Tree Size Method * Each tree we read results in * singleton groups for each tip, plus * a group for each interior node except the root * Since the singleton tips are identical for each tree, this gives * a bound of #tips + ( #trees * (# tips - 2 ) ) * * * Ignoring small terms where expedient, either of the following should * result in an adequate allocation: * pow(2,#tips) * (#trees + 1) * #tips * * Since "maxgrp" is a limit on the number of items we'll need to put * in a hash, we double it to make space for quick hashing * * BUT -- all of this has the possibility for overflow, so -- let's * make the initial calculations with doubles and then convert * */ /* limit chosen to make hash arithmetic work */ maxgrp = LONG_MAX / 2; ln_maxgrp = log((double)maxgrp); /* 2 * (#trees + 1) * #tips */ ln_maxgrp1 = log(2.0 * (double)tip_count * ((double)trees_in_1 + (double)trees_in_2)); /* ln only for 2 * pow(2,#tips) */ ln_maxgrp2 = (double)(1 + tip_count) * log(2.0); /* now -- find the smallest of the three */ if(ln_maxgrp1 < ln_maxgrp) { maxgrp = 2 * (trees_in_1 + trees_in_2 + 1) * tip_count; ln_maxgrp = ln_maxgrp1; } if(ln_maxgrp2 < ln_maxgrp) { maxgrp = pow(2,tip_count+1); } /* Read the (first) tree file and put together grouping, order, and timesseen */ read_groups (&pattern_array, trees_in_1 + trees_in_2, tip_count, phylotrees); if ((tree_pairing == ADJACENT_PAIRS) || (tree_pairing == ALL_IN_FIRST)) { /* Here deal with the adjacent or all-in-first pairing difference computation */ compute_distances (pattern_array, trees_in_1, 0); } else if (tree_pairing == NO_PAIRING) { /* Compute the consensus tree. */ putc('\n', outfile); /* consensus(); Reserved for future development */ } if (progress) printf("\nOutput written to file \"%s\"\n\n", outfilename); FClose(outtree); FClose(intree); FClose(outfile); if ((tree_pairing == ALL_IN_1_AND_2) || (tree_pairing == CORR_IN_1_AND_2)) FClose(intree2); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif free_patterns (pattern_array, trees_in_1 + trees_in_2); clean_up_final(); /* clean up grbg */ p = grbg; while (p != NULL) { node * r = p; p = p->next; free(r->nodeset); free(r->view); free(r); } printf("Done.\n\n"); embExit(); return 0; } /* main */
ContentFeatures read_content_features(lua_State *L, int index) { if(index < 0) index = lua_gettop(L) + 1 + index; ContentFeatures f; /* Cache existence of some callbacks */ lua_getfield(L, index, "on_construct"); if(!lua_isnil(L, -1)) f.has_on_construct = true; lua_pop(L, 1); lua_getfield(L, index, "on_destruct"); if(!lua_isnil(L, -1)) f.has_on_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "after_destruct"); if(!lua_isnil(L, -1)) f.has_after_destruct = true; lua_pop(L, 1); lua_getfield(L, index, "on_rightclick"); f.rightclickable = lua_isfunction(L, -1); lua_pop(L, 1); /* Name */ getstringfield(L, index, "name", f.name); /* Groups */ lua_getfield(L, index, "groups"); read_groups(L, -1, f.groups); lua_pop(L, 1); /* Visual definition */ f.drawtype = (NodeDrawType)getenumfield(L, index, "drawtype", ScriptApiNode::es_DrawType,NDT_NORMAL); getfloatfield(L, index, "visual_scale", f.visual_scale); /* Meshnode model filename */ getstringfield(L, index, "mesh", f.mesh); // tiles = {} lua_getfield(L, index, "tiles"); // If nil, try the deprecated name "tile_images" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "tile_images", "Deprecated; new name is \"tiles\"."); lua_getfield(L, index, "tile_images"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef[i] = read_tiledef(L, -1, f.drawtype); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==6){ lua_pop(L, 1); break; } } // Copy last value to all remaining textures if(i >= 1){ TileDef lasttile = f.tiledef[i-1]; while(i < 6){ f.tiledef[i] = lasttile; i++; } } } lua_pop(L, 1); // special_tiles = {} lua_getfield(L, index, "special_tiles"); // If nil, try the deprecated name "special_materials" instead if(lua_isnil(L, -1)){ lua_pop(L, 1); warn_if_field_exists(L, index, "special_materials", "Deprecated; new name is \"special_tiles\"."); lua_getfield(L, index, "special_materials"); } if(lua_istable(L, -1)){ int table = lua_gettop(L); lua_pushnil(L); int i = 0; while(lua_next(L, table) != 0){ // Read tiledef from value f.tiledef_special[i] = read_tiledef(L, -1, f.drawtype); // removes value, keeps key for next iteration lua_pop(L, 1); i++; if(i==CF_SPECIAL_COUNT){ lua_pop(L, 1); break; } } } lua_pop(L, 1); f.alpha = getintfield_default(L, index, "alpha", 255); bool usealpha = getboolfield_default(L, index, "use_texture_alpha", false); if (usealpha) f.alpha = 0; // Read node color. lua_getfield(L, index, "color"); read_color(L, -1, &f.color); lua_pop(L, 1); getstringfield(L, index, "palette", f.palette_name); /* Other stuff */ lua_getfield(L, index, "post_effect_color"); read_color(L, -1, &f.post_effect_color); lua_pop(L, 1); f.param_type = (ContentParamType)getenumfield(L, index, "paramtype", ScriptApiNode::es_ContentParamType, CPT_NONE); f.param_type_2 = (ContentParamType2)getenumfield(L, index, "paramtype2", ScriptApiNode::es_ContentParamType2, CPT2_NONE); if (f.palette_name != "" && !(f.param_type_2 == CPT2_COLOR || f.param_type_2 == CPT2_COLORED_FACEDIR || f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) warningstream << "Node " << f.name.c_str() << " has a palette, but not a suitable paramtype2." << std::endl; // Warn about some deprecated fields warn_if_field_exists(L, index, "wall_mounted", "Deprecated; use paramtype2 = 'wallmounted'"); warn_if_field_exists(L, index, "light_propagates", "Deprecated; determined from paramtype"); warn_if_field_exists(L, index, "dug_item", "Deprecated; use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item", "Deprecated; use 'drop' field"); warn_if_field_exists(L, index, "extra_dug_item_rarity", "Deprecated; use 'drop' field"); warn_if_field_exists(L, index, "metadata_name", "Deprecated; use on_add and metadata callbacks"); // True for all ground-like things like stone and mud, false for eg. trees getboolfield(L, index, "is_ground_content", f.is_ground_content); f.light_propagates = (f.param_type == CPT_LIGHT); getboolfield(L, index, "sunlight_propagates", f.sunlight_propagates); // This is used for collision detection. // Also for general solidness queries. getboolfield(L, index, "walkable", f.walkable); // Player can point to these getboolfield(L, index, "pointable", f.pointable); // Player can dig these getboolfield(L, index, "diggable", f.diggable); // Player can climb these getboolfield(L, index, "climbable", f.climbable); // Player can build on these getboolfield(L, index, "buildable_to", f.buildable_to); // Liquids flow into and replace node getboolfield(L, index, "floodable", f.floodable); // Whether the node is non-liquid, source liquid or flowing liquid f.liquid_type = (LiquidType)getenumfield(L, index, "liquidtype", ScriptApiNode::es_LiquidType, LIQUID_NONE); // If the content is liquid, this is the flowing version of the liquid. getstringfield(L, index, "liquid_alternative_flowing", f.liquid_alternative_flowing); // If the content is liquid, this is the source version of the liquid. getstringfield(L, index, "liquid_alternative_source", f.liquid_alternative_source); // Viscosity for fluid flow, ranging from 1 to 7, with // 1 giving almost instantaneous propagation and 7 being // the slowest possible f.liquid_viscosity = getintfield_default(L, index, "liquid_viscosity", f.liquid_viscosity); f.liquid_range = getintfield_default(L, index, "liquid_range", f.liquid_range); f.leveled = getintfield_default(L, index, "leveled", f.leveled); getboolfield(L, index, "liquid_renewable", f.liquid_renewable); f.drowning = getintfield_default(L, index, "drowning", f.drowning); // Amount of light the node emits f.light_source = getintfield_default(L, index, "light_source", f.light_source); if (f.light_source > LIGHT_MAX) { warningstream << "Node " << f.name.c_str() << " had greater light_source than " << LIGHT_MAX << ", it was reduced." << std::endl; f.light_source = LIGHT_MAX; } f.damage_per_second = getintfield_default(L, index, "damage_per_second", f.damage_per_second); lua_getfield(L, index, "node_box"); if(lua_istable(L, -1)) f.node_box = read_nodebox(L, -1); lua_pop(L, 1); lua_getfield(L, index, "connects_to"); if (lua_istable(L, -1)) { int table = lua_gettop(L); lua_pushnil(L); while (lua_next(L, table) != 0) { // Value at -1 f.connects_to.push_back(lua_tostring(L, -1)); lua_pop(L, 1); } } lua_pop(L, 1); lua_getfield(L, index, "connect_sides"); if (lua_istable(L, -1)) { int table = lua_gettop(L); lua_pushnil(L); while (lua_next(L, table) != 0) { // Value at -1 std::string side(lua_tostring(L, -1)); // Note faces are flipped to make checking easier if (side == "top") f.connect_sides |= 2; else if (side == "bottom") f.connect_sides |= 1; else if (side == "front") f.connect_sides |= 16; else if (side == "left") f.connect_sides |= 32; else if (side == "back") f.connect_sides |= 4; else if (side == "right") f.connect_sides |= 8; else warningstream << "Unknown value for \"connect_sides\": " << side << std::endl; lua_pop(L, 1); } } lua_pop(L, 1); lua_getfield(L, index, "selection_box"); if(lua_istable(L, -1)) f.selection_box = read_nodebox(L, -1); lua_pop(L, 1); lua_getfield(L, index, "collision_box"); if(lua_istable(L, -1)) f.collision_box = read_nodebox(L, -1); lua_pop(L, 1); f.waving = getintfield_default(L, index, "waving", f.waving); // Set to true if paramtype used to be 'facedir_simple' getboolfield(L, index, "legacy_facedir_simple", f.legacy_facedir_simple); // Set to true if wall_mounted used to be set to true getboolfield(L, index, "legacy_wallmounted", f.legacy_wallmounted); // Sound table lua_getfield(L, index, "sounds"); if(lua_istable(L, -1)){ lua_getfield(L, -1, "footstep"); read_soundspec(L, -1, f.sound_footstep); lua_pop(L, 1); lua_getfield(L, -1, "dig"); read_soundspec(L, -1, f.sound_dig); lua_pop(L, 1); lua_getfield(L, -1, "dug"); read_soundspec(L, -1, f.sound_dug); lua_pop(L, 1); } lua_pop(L, 1); return f; }
int main(int argc, char *argv[]) { SID_Init(&argc, &argv, NULL); // Fetch user inputs char filename_halos_root[256]; char filename_catalog_root[256]; char filename_PHKs_root[256]; double box_size; double dx; int i_file_lo_in; int i_file_hi_in; int i_file_skip; strcpy(filename_halos_root, argv[1]); strcpy(filename_catalog_root, argv[2]); strcpy(filename_PHKs_root, argv[3]); box_size = atof(argv[4]); dx = atof(argv[5]); i_file_lo_in = atoi(argv[6]); i_file_hi_in = atoi(argv[7]); i_file_skip = atoi(argv[8]); int i_file_lo; int i_file_hi; if(i_file_lo_in < i_file_hi_in) { i_file_lo = i_file_lo_in; i_file_hi = i_file_hi_in; } else { i_file_lo = i_file_hi_in; i_file_hi = i_file_lo_in; } SID_log("Generating group PH keys for files #%d->#%d...", SID_LOG_OPEN | SID_LOG_TIMER, i_file_lo, i_file_hi); for(int i_file = i_file_lo; i_file <= i_file_hi; i_file += i_file_skip) { SID_log("Processing file #%03d...", SID_LOG_OPEN | SID_LOG_TIMER, i_file); SID_set_verbosity(SID_SET_VERBOSITY_RELATIVE, 0); // Read group info from the halo catalogs plist_info plist; int * PHK_group = NULL; size_t * PHK_group_index = NULL; char * filename_number = (char *)SID_malloc(sizeof(char) * 10); init_plist(&plist, NULL, GADGET_LENGTH, GADGET_MASS, GADGET_VELOCITY); sprintf(filename_number, "%03d", i_file); ADaPS_store(&(plist.data), (void *)filename_number, "read_catalog", ADaPS_DEFAULT); read_groups(filename_halos_root, i_file, READ_GROUPS_ALL | READ_GROUPS_MBP_IDS_ONLY, &plist, filename_number); int n_groups_all = ((int *)ADaPS_fetch(plist.data, "n_groups_all_%s", filename_number))[0]; int n_groups = ((int *)ADaPS_fetch(plist.data, "n_groups_%s", filename_number))[0]; // If there's any groups to analyze ... int * n_particles_groups = NULL; size_t n_particles_cumulative = 0; int n_bits = 0; // Default value if there are no groups if(n_groups > 0) { // Fetch the halo sizes n_particles_groups = (int *)ADaPS_fetch(plist.data, "n_particles_group_%s", filename_number); // Read MBP data from halo catalogs SID_log("Reading most-bound-particle positions...", SID_LOG_OPEN); halo_properties_info group_properties; fp_catalog_info fp_group_properties; double * x_array = (double *)SID_malloc(sizeof(double) * n_groups); double * y_array = (double *)SID_malloc(sizeof(double) * n_groups); double * z_array = (double *)SID_malloc(sizeof(double) * n_groups); fopen_catalog(filename_catalog_root, i_file, READ_CATALOG_GROUPS | READ_CATALOG_PROPERTIES, &fp_group_properties); if(fp_group_properties.n_halos_total != n_groups) SID_exit_error("Halo counts in group files and catalogs don't match (ie. %d!=%d)", SID_ERROR_LOGIC, fp_group_properties.n_halos_total, n_groups); for(int i_group = 0; i_group < n_groups; i_group++) { fread_catalog_file(&fp_group_properties, NULL, NULL, &group_properties, NULL, i_group); x_array[i_group] = group_properties.position_MBP[0]; y_array[i_group] = group_properties.position_MBP[1]; z_array[i_group] = group_properties.position_MBP[2]; // Enforce periodic BCs if(x_array[i_group] < 0.) x_array[i_group] += box_size; if(x_array[i_group] >= box_size) x_array[i_group] -= box_size; if(y_array[i_group] < 0.) y_array[i_group] += box_size; if(y_array[i_group] >= box_size) y_array[i_group] -= box_size; if(z_array[i_group] < 0.) z_array[i_group] += box_size; if(z_array[i_group] >= box_size) z_array[i_group] -= box_size; } fclose_catalog(&fp_group_properties); SID_log("Done.", SID_LOG_CLOSE); // Determine the number of bits to use for the PHKs for(n_bits = N_BITS_MIN; (box_size / pow(2., (double)(n_bits + 1))) > dx && n_bits <= 20;) n_bits++; // Compute PHKs SID_log("Computing PHKs (using %d bits per dimension)...", SID_LOG_OPEN, n_bits); PHK_group = (int *)SID_malloc(sizeof(int) * n_groups); for(int i_group = 0; i_group < n_groups; i_group++) { // Compute the key for this group PHK_group[i_group] = compute_PHK_from_Cartesian( n_bits, 3, (double)x_array[i_group] / box_size, (double)y_array[i_group] / box_size, (double)z_array[i_group] / box_size); } SID_free(SID_FARG x_array); SID_free(SID_FARG y_array); SID_free(SID_FARG z_array); SID_log("Done.", SID_LOG_CLOSE); // Sort PHKs SID_log("Sorting PHKs...", SID_LOG_OPEN); merge_sort((void *)PHK_group, n_groups, &PHK_group_index, SID_INT, SORT_COMPUTE_INDEX, GBP_FALSE); SID_log("Done.", SID_LOG_CLOSE); // Count the number of particles for(int i_group = 0; i_group < n_groups; i_group++) n_particles_cumulative += n_particles_groups[PHK_group_index[i_group]]; } // Write results SID_log("Writing results for %d groups...", SID_LOG_OPEN, n_groups); char filename_output_properties[256]; sprintf(filename_output_properties, "%s_%s.catalog_PHKs", filename_PHKs_root, filename_number); FILE *fp_PHKs = fopen(filename_output_properties, "w"); fwrite(&n_groups, sizeof(int), 1, fp_PHKs); fwrite(&n_bits, sizeof(int), 1, fp_PHKs); fwrite(&n_particles_cumulative, sizeof(size_t), 1, fp_PHKs); n_particles_cumulative = 0; for(int i_group = 0; i_group < n_groups; i_group++) { int index_temp = (int)PHK_group_index[i_group]; n_particles_cumulative += n_particles_groups[index_temp]; fwrite(&(PHK_group[index_temp]), sizeof(int), 1, fp_PHKs); fwrite(&index_temp, sizeof(int), 1, fp_PHKs); fwrite(&n_particles_cumulative, sizeof(size_t), 1, fp_PHKs); } fclose(fp_PHKs); SID_log("Done.", SID_LOG_CLOSE); // Clean-up free_plist(&plist); if(n_groups > 0) { SID_free(SID_FARG PHK_group); SID_free(SID_FARG PHK_group_index); } SID_set_verbosity(SID_SET_VERBOSITY_DEFAULT); SID_log("Done.", SID_LOG_CLOSE); } SID_log("Done.", SID_LOG_CLOSE); SID_Finalize(); }