Newer
Older
} else if(!strcmp(argv[0], "filepath")) {
int k = 0;
char *path[64], *dir;
for(i = 1, k = 0; i < argc && k < COUNT(path)-1; i++) {
dir = strtok(argv[i], ":");
do {
if(!strcmp(dir,"+")) {
int m = 0;
while(k<COUNT(path)-1 && oldpath && oldpath[m])
path[k++] = oldpath[m++];
} else {
path[k++] = dir;
}
dir = strtok(NULL, ":");
} while(dir && k < COUNT(path)-1);
} else if(!strcmp(argv[0], "texture")) {
int txno = -1;
int txflags = TXF_SCLAMP | TXF_TCLAMP;
int txapply = TXF_DECAL;
int qual = 7;
char *txfname, *key;
i = 1;
if(argc > 1 && sscanf(argv[1], "%d", &txno) > 0)
i = 2;
while(i < argc && (key = argv[i])[0] == '-' || key[0] == '+') {
int tqual = (strchr(key,'m') ? 4:0) |
(strchr(key,'l') ? 2:0) |
(strchr(key,'n') ? 1:0);
if(key[0] == '-') qual &= ~tqual;
else qual |= tqual;
if(strchr(key,'a')) txflags |= TXF_ALPHA;
if(strchr(key,'i')) txflags |= TXF_INTENSITY;
if(strchr(key, 'A')) txflags |= TXF_ADD;
if(strchr(key, 'M')) txapply = TXF_MODULATE;
if(strchr(key, 'D')) txapply = TXF_DECAL;
if(strchr(key, 'B')) txapply = TXF_BLEND;
if((i < argc && txno < 0 && sscanf(argv[i++], "%d", &txno) <= 0) ||
(txfname = argv[i]) == NULL) {
msg("Expected ``texture [-lmnaMDB] txno file.sgi'', got %s", line);
msg(" opts: -l(inear) -m(ipmap) -n(earest) -i(intensity) -a(lpha) -A(dd) -M(odulate)|-D(ecal)|-B(lend))");
} else {
txaddentry( &st->textures, &st->ntextures, fname, txno, txfname, txapply, txflags, qual );
}
} else if(!strcmp(argv[0], "polyorivar") && argc == 2) {
if(1!=specks_set_byvariable( st, argv[1], &st->polyorivar0 ))
msg("polyorivar: unknown field %s", argv[1]);
} else if(!strcmp(argv[0], "texturevar") && argc == 2) {
if(1!=specks_set_byvariable( st, argv[1], &st->texturevar ))
msg("texturevar: unknown field %s", argv[1]);
} else if(!strncmp(argv[0], "coord", 5) || !strncmp(argv[0], "altcoord", 8)) {
msg("coord %s %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g",
st->altcoord[0].name, t[0],t[1],t[2],t[3],
t[4],t[5],t[6],t[7],
t[8],t[9],t[10],t[11],
t[12],t[13],t[14],t[15]);
} else if(argc == 18) {
sprintf(st->altcoord[0].name, "%.9s", argv[1]);
i = getfloats( t, 16, 2, argc, argv );
if(i != 16) {
msg("%s: expected 16 numbers; what's %s", argv[0],argv[i+2]);
continue;
} else {
msg("expected \"coord\" name ... 16 world-to-coord tfm floats (GL order) ...");
} else if(!strncmp(argv[0], "dataset", 7) && argc == 3) {
if(sscanf(argv[1], "%d", &indexno) <= 0
|| sscanf(argv[2], "%11s", name) <= 0
|| indexno < 0 || indexno >= MAXFILES) {
msg("%s: expected ``dataset <indexno> <datasetname>'' with 0<=indexno<=%d",
fname, MAXFILES-1);
continue;
}
strncpyt(st->dataname[indexno], name, sizeof(st->dataname[indexno]));
st->curdata = indexno;
} else if(!strncmp(argv[0], "datavar", 7) && argc > 2) {
if(sscanf(argv[1], "%d", &varno)<=0
|| sscanf(argv[2], "%19s", vd.name)<=0
msg("%s: expected ``datavar <indexno> <variablename> [minval maxval]'' with 0<=indexno<=%d",
line, MAXVAL-1);
continue;
}
strcpy(st->vdesc[st->curdata][varno].name, vd.name);
if(argc == 5) {
st->vdesc[st->curdata][varno].min = atof(argv[3]);
st->vdesc[st->curdata][varno].max = atof(argv[4]);
} else if(!strcmp(argv[0], "datatime") && argc==2) {
int newt = st->curtime; /* so e.g. "datatime now" => apply to current data */
sscanf(argv[1], "%d", &newt);
if(sscanf(argv[1], "%d", &newt) <= 0 || newt < 0) {
msg("%s: datatime %s: timestep must be >= 0", fname, argv[1]);
continue;
}
if(newt == st->datatime) /* no need to change anything */
continue;
} else if(!strcmp(argv[0], "mesh") || !strcmp(argv[0], "tstrip")
|| !strcmp(argv[0], "tfan")) {
specks_read_mesh(st, f, argc, argv, line);
} else if(!strcmp(argv[0], "textcolor") && argc==2) {
sscanf(argv[1], "%d", &s.rgba);
} else if(!strcmp(argv[0], "maxcomment") && argc==2) {
int newmax = st->maxcomment;
sscanf(argv[1], "%d", &newmax);
if(newmax != st->maxcomment) {
SPFLUSH();
st->maxcomment = newmax;
tsl.bytesperspeck =
(st->maxcomment+1 + (sizeof(s) - sizeof(s.title)) + 3) & ~3;
maxnsp = sizeof(speckbuf) / tsl.bytesperspeck;
}
k = getfloats( &s.p.x[0], 3, ignorefirst, argc, argv );
if(k < 3) {
msg("Unrecognized datacmd: %s", line);
k = getfloats( &s.val[0], COUNT(s.val), i, argc, argv );
for(m = 0; m < k; m++) {
if(vdp->nsamples++ == 0) {
vdp->min = vdp->max = s.val[m];
} else {
if(vdp->min > s.val[m]) vdp->min = s.val[m];
else if(vdp->max < s.val[m]) vdp->max = s.val[m];
vdp->sum += s.val[m];
vdp->mean = vdp->sum / vdp->nsamples;
vdp++;
if(maxfields < k) maxfields = k;
m = i+k;
if(!strcmp(argv[m], "text")) {
s.size = 1;
if(++m < argc-1 && !strcmp(argv[m], "-size")) {
sscanf(argv[m+1], "%f", &s.size);
m += 2;
}
addchunk( st, 1, SMALLSPECKSIZE(0),
speckscale, &s,
rejoinargs(m, argc, argv),
SMALLSPECKSIZE(0) );
else if(!strcmp(argv[m], "ellipsoid")) {
specks_read_ellipsoid( st, &s.p, argc-m, argv+m, comment );
} else {
*sp = s;
nsp++;
sp = NextSpeck( speckbuf, &tsl, nsp );
} else if(comment) {
int len;
char *title = comment + (comment[1] == ' ' ? 2 : 1);
*sp = s;
strncpyt(sp->title, title, st->maxcomment+1);
maxfields = MAXVAL+1; /* "keep titles too" */
nsp++;
sp = NextSpeck( speckbuf, &tsl, nsp );
} else {
*sp = s;
nsp++;
sp = NextSpeck( speckbuf, &tsl, nsp );
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
}
}
}
fclose(f);
SPFLUSH();
*stp = st;
}
/* Add a static (eternal) box to display list */
int specks_add_box( struct stuff *st, struct AMRbox *box, int timestep )
{
int i;
if(box->level >= 0 && st->boxlevels <= box->level)
st->boxlevels = box->level+1;
for(i = 0; i < st->staticboxroom && st->staticboxes[i].level >= 0; i++) {
if(box->boxno != -1 && box->boxno == st->staticboxes[i].boxno) {
st->staticboxes[i] = *box;
return ~i;
}
}
if(i >= st->staticboxroom-1) {
st->staticboxroom = (st->staticboxroom>0) ? st->staticboxroom*2 : 12;
st->staticboxes = RenewN( st->staticboxes, struct AMRbox, st->staticboxroom );
}
st->staticboxes[i] = *box;
st->staticboxes[i+1].level = -1;
return i;
}
void specks_read_boxes( struct stuff *st, char *fname, int timebase )
{
FILE *f = fopen(fname, "rb");
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
char line[1024];
int ntimes = -1, maxbox = -1, curbox = 0, curtime = 0, level = -1, i;
int lno = 0;
int boxseq, boxno;
struct AMRbox *boxes = NULL;
struct AMRbox box;
if(timebase < 0) /* if unspecified time, start at first timestep */
timebase = 0;
if(f == NULL) {
msg("Can't open AMRboxes file %s (as from hier2boxes.pl)", fname);
return;
}
while(fgets(line, sizeof(line), f) != NULL) {
lno++;
boxno = -1;
if(sscanf(line, "%f%f%f %f%f%f # %d",
&box.p0.x[0],&box.p0.x[1],&box.p0.x[2],
&box.p1.x[0],&box.p1.x[1],&box.p1.x[2], &boxno) >= 6) {
for(i = 0; i < 3; i++) {
box.p0.x[i] *= st->spacescale;
box.p1.x[i] *= st->spacescale;
}
if(boxno != -1)
box.boxno = boxno;
else
box.boxno = boxseq++;
if(curbox < maxbox && boxes != NULL && level >= 0) {
boxes[curbox] = box;
curbox++;
} else {
msg("%s line %d: Excess box (only expected %d at timestep %d)",
fname, lno, maxbox, curtime);
}
}
else if(sscanf(line, "AMRboxes %d timesteps", &ntimes) > 0 && ntimes >= 0) {
int needtimes = ntimes + (timebase<0 ? 0 : timebase);
if(st->boxtimes <= needtimes+1) {
needtimes += st->boxtimes + 15; /* leave lots of extra room */
st->boxes = RenewN( st->boxes, struct AMRbox *, needtimes );
memset( &st->boxes[st->boxtimes], 0,
(needtimes - st->boxtimes) * sizeof(struct AMRbox *) );
if(st->boxtimes < ntimes+timebase)
st->boxtimes = ntimes+timebase;
}
boxes = NULL;
}
else if(sscanf(line, "timestep %d %d grids", &curtime, &maxbox) == 2) {
boxseq = 1;
if(ntimes < 0) {
msg(
"%s line %d: ``AMRboxes N timesteps'' must precede ``timestep'' lines!",
fname, lno);
curtime = -1;
boxes = NULL;
continue;
} else if(curtime<0 || curtime>=ntimes || maxbox<0) {
msg("%s line %d: bad timestep number", fname, lno);
curtime = -1;
boxes = NULL;
continue;
}
if((boxes = st->boxes[curtime+timebase]) != NULL) {
msg("%s line %d: Respecifying timestep %d",
fname, lno, curtime);
Free( st->boxes[curtime+timebase] );
}
boxes = NewN( struct AMRbox, maxbox+1 );
for(curbox = 0; curbox <= maxbox; curbox++)
boxes[curbox].level = -(maxbox+1);
st->boxes[curtime+timebase] = boxes;
/* Ensure that known span of time includes this timestep */
(void) specks_timespecksptr( st, st->curdata, curtime+timebase );
curbox = 0;
}
else if(sscanf(line, "level %d", &level) > 0) {
if(boxes == NULL) {
msg("%s line %d: Must specify timestep before level",
fname, lno);
level = -1;
}
if(st->boxlevels <= level)
st->boxlevels = level+1;
box.level = level;
}
}
fclose(f);
/* st->boxlevelmask |= (1 << st->boxlevels) - 1;
* Don't do this -- it turns on all boxlevels whenever we get a new box!
*/
}
static struct AMRbox *findboxno( struct AMRbox *box, int boxno, int *count, int *bmin, int *bmax ) {
if(box == NULL) return NULL;
while(box->level >= 0) {
if(box->boxno == boxno)
return box;
if(*bmin > box->boxno) *bmin = box->boxno;
if(*bmax < box->boxno) *bmax = box->boxno;
++*count;
box++;
}
return NULL;
}
int specks_gobox( struct stuff *st, int boxno, int argc, char *argv[] )
{
Point pmid;
float sz, scale;
char cmd[128];
int bmin = 1<<30, bmax = -1<<30;
int count = 0;
struct AMRbox *box = NULL;
if(st->boxes && st->curtime < st->boxtimes)
box = findboxno( st->boxes[st->curtime], boxno, &count, &bmin, &bmax );
if(box == NULL)
box = findboxno( st->staticboxes, boxno, &count, &bmin, &bmax );
if(box == NULL) {
if(count == 0)
msg("No AMR boxes for timestep %d", st->curtime);
else
msg("%d AMR boxes (numbered %d..%d) for timestep %d, but no box number %d",
count, bmin, bmax, st->curtime, boxno);
return 0;
}
vlerp( &pmid, .5*st->gscale, &box->p0, &box->p1 );
set_interest_point( &pmid );
sz = vdist( &box->p0, &box->p1 );
sprintf(cmd, "%.1g", st->gscale * st->goboxscale * sz);
/* round to 1 decimal */
scale = atof(cmd);
#if CAVE
{
Point pmid, fwd, headv, pos, offset, newpos;
static Point zvec = {0,0,1};
CAVENavConvertVectorCAVEToWorld( zvec.x, fwd.x );
CAVEGetPosition( CAVE_HEAD, headv.x );
headv.x[2] -= 10.0; /* a point in front of head, in CAVE coords */
CAVENavConvertVectorCAVEToWorld( headv.x, offset.x );
msg("scale %g caveunit %g offsetW %g %g %g", scale, vlength(&fwd), offset.x[0],offset.x[1],offset.x[2]);
vsadd( &newpos, &pmid, -scale / vlength(&fwd), &offset );
sprintf(cmd,
sz > 0 ? "jumpto %g %g %g . . . %g"
: "jumpto %g %g %g",
newpos.x[0], newpos.x[1], newpos.x[2], scale);
VIDI_queue_commandstr( cmd );
}
#endif
return 1;
}
void specks_read_cmap( struct stuff *st, char *fname, int *ncmapp, struct cment **cmapp )
{
int i;
char *cp;
char line[256];
int k, count = 0;
int *tcmap;
struct cment *cm;
float fr,fg,fb,fa;
int big = 0;
int lno = 0;
int ncmap = 0;
int cval;
int csrc;
FILE *f = fopen(fname, "rb");
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
if(f == NULL) {
msg("Can't open colormap file %s", fname);
return;
}
tcmap = NULL;
ncmap = 0;
while(fgets(line, sizeof(line), f) != NULL) {
lno++;
cp = line;
rescan:
for( ; isspace(*cp); cp++)
;
if(*cp == '\0' || *cp == '#')
continue;
fa = 1.0;
k = sscanf(cp, "%f%f%f", &fr,&fg,&fb/*,&fa*/);
if(k == 1) {
if(count == 0 && fr == (int)fr && fr > 0) {
count = fr;
if(count >= 1 && count < 1000000) /* OK */
continue;
msg("Unreasonable number of colormap entries claimed in header");
/* and fall into error case */
} else {
while(isspace(*cp) || isdigit(*cp)) cp++;
if(*cp == ':') {
ncmap = fr;
if(ncmap < 0) {
ncmap = 0; /* don't continue -- fall into error */
} else if(ncmap >= count) {
msg("Colormap index %g exceeds size %d given in header",
fr, count); /* don't continue -- ditto */
} else {
cp++;
goto rescan; /* All's well */
}
}
}
} else if(k >= 3) {
if(fr > 2 || fg > 2 || fb > 2 || fa > 2)
big = 1;
if(!big) {
fr *= 255; fg *= 255; fb *= 255; /*fa *= 255;*/
}
cval = PACKRGBA( (int)fr, (int)fg, (int)fb, 0 );
if(tcmap == NULL) {
tcmap = NewA( int, count );
/* Fill unused entries with gray */
memset(tcmap, 0x80, count*sizeof(int));
}
tcmap[ncmap>=count ? count-1 : ncmap<0 ? 0 : ncmap] = cval;
ncmap++;
if(ncmap >= count)
break;
continue;
} else if(sscanf(cp, "=%d", &csrc) > 0) {
if(csrc < 0 || csrc >= count || ncmap < 0 || ncmap >= count || tcmap == NULL) {
msg("Colormap index out of range: %d or %d isn't in 0..%d",
ncmap, csrc, count-1);
} else {
tcmap[ncmap++] = tcmap[csrc];
continue;
}
/* Fall through into error */
}
msg("Trouble reading colormap file %s: bad line %d: %s",
fname, lno, line);
fclose(f);
return;
}
fclose(f);
if(tcmap == NULL)
return;
*ncmapp = count;
if(*ncmapp < 2) {
*ncmapp = 2;
tcmap[1] = tcmap[0];
}
*cmapp = cm = RenewN( *cmapp, struct cment, *ncmapp );
k = *ncmapp;
for(i = 0; i < k; i++) {
cm[i].raw = tcmap[i];
cm[i].cooked = specks_cookcment( st, tcmap[i] );
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
}
#if CAVEMENU
void set_psize( float psize, MenuEnt *me, void *st ) {
char str[20];
((struct stuff *)st)->psize = psize;
sprintf(str, "pointsize %.3g", psize);
menu_settitle( me, str );
}
/* set_tknob() only used if PARTIMENU mentions "survey" */
void set_tknob( float val, MenuEnt *me, void *vtb ) {
char str[128];
struct stuff *st = ((struct boxleveler *)vtb)->st;
int self = ((struct boxleveler *)vtb)->level;
static int mod[3] = { 1, 4, 16 };
static char *fmt[3] = {
"StarMassEjFrac [%d/4]",
"SNFeedback [%d/4]",
"StarEfficiency [%d/4]",
};
int range = 4, mine, rest, above;
above = mod[self] * range;
rest = st->curtime % mod[self] + (st->curtime / above) * above;
mine = (st->curtime / mod[self]) % range;
if(me->state == ME_PICKED || me->state == ME_HELD) {
mine = val;
if(mine < 0) mine = 0; else if(mine >= range) mine = range-1;
clock_set_time( st->clk, rest + mine*mod[self] );
clock_set_running( st->clk, 0 );
}
sprintf(str, fmt[self], mine+1);
menu_settitle( me, str );
}
void set_step( float time0, MenuEnt *me, void *vst ) {
char str[32];
struct stuff *st = (struct stuff *)vst;
if(me->state == ME_PICKED) {
/* NOTE we use the static values snapped by the framefunction.
* st->curtime etc. might have changed since then.
*/
sprintf(str, "step %2d of 0..%d", st->frame_time, st->ntimes - 1);
if(st->fetching > 0)
sprintf(str+strlen(str), " (loading %d)", st->fetchtime);
menu_settitle( me, str );
}
void set_fwd( int fwd, MenuEnt *me, void *st ) {
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
menu_settitle( me, fwd ? ">>> fwd >>>" : "<<< rev <<<" );
}
void set_viewall( int all, MenuEnt *me, void *vst ) {
struct stuff *st = (struct stuff *)vst;
if(all) {
strcpy( st->vdcmd, "\002jump all" );
menu_settitle( me, "view all" );
}
else {
strcpy( st->vdcmd, "\002jump peak" );
menu_settitle( me, "view peak" );
}
}
float get_nav_scale(void)
{
float nav[4][4];
CAVENavGetMatrix( nav );
return 1 / sqrtf( vdot( (Point *)&nav[0][0], (Point *)&nav[0][0] ) );
}
void set_scale( float logscale, MenuEnt *me, void *vst ) {
struct stuff *st = (struct stuff *)vst;
float scl = pow(10., logscale);
char str[64];
if(me->state == ME_PICKED || me->state == ME_HELD) {
sprintf( st->vdcmd, "\002scale %g", scl);
} else {
scl = get_nav_scale();
me->val = scl<=0 ? -6 : log10( scl );
}
sprintf( str, "scale %.4g", scl );
menu_settitle( me, str );
}
void set_dataset( int which, MenuEnt *me, void *vst ) {
char str[32];
struct stuff *st = (struct stuff *)vst;
if(which < 0 || which >= st->ndata || which >= MAXFILES) which = 0;
st->curdata = which;
sprintf(str, "viewing %s (%d)", st->dataname[which], which);
menu_settitle( me, str );
}
void set_lumvar( int lumvar, MenuEnt *me, void *vst ) {
char str[80];
struct stuff *st = (struct stuff *)vst;
struct valdesc *vd;
if(lumvar < 0 || lumvar >= MAXVAL+1) lumvar = 0;
st->sizedby = lumvar;
vd = &st->vdesc[st->curdata][lumvar];
if(vd->lmin == vd->lmax) vd->lmin = vd->min, vd->lmax = vd->max;
sprintf(str, "lum by %s (%d) [%.3g..%.3g]", vd->name, lumvar, vd->lmin, vd->lmax);
menu_settitle( me, str );
}
void set_colorvar( int colorvar, MenuEnt *me, void *vst ) {
char str[80];
struct stuff *st = (struct stuff *)vst;
struct valdesc *vd;
if(colorvar < 0 || colorvar >= MAXVAL+1) colorvar = 0;
st->coloredby = colorvar;
vd = &st->vdesc[st->curdata][colorvar];
if(vd->cmin == vd->cmax) vd->cmin = vd->min, vd->cmax = vd->max;
sprintf(str, "color by %s (%d) [%.3g..%.3g]", vd->name,
colorvar, vd->cmin, vd->cmax);
menu_settitle( me, str );
}
void set_slum( float slum, MenuEnt *me, void *vst ) {
char str[32];
struct stuff *st = (struct stuff *)vst;
st->vdesc[st->curdata][st->sizedby].lum = slum;
sprintf(str, slum == 0 ? "scale-lum <unset>" : "scale-lum %.2g", slum);
menu_settitle( me, str );
}
void set_speed( float speed, MenuEnt *me, void *vst ) {
char str[32];
struct stuff *st = (struct stuff *)vst;
sprintf(str, "speed %.1f steps/anim sec", speed);
menu_settitle( me, str );
}
void set_fspeed( float speed, MenuEnt *me, void *vst ) {
char str[64];
struct stuff *st = (struct stuff *)vst;
sprintf(str, "fspeed %.1f steps/real sec (%s)", speed,
clock_running(st->clk) ? "running" : "stopped");
menu_settitle( me, str );
}
void set_seedata( int which, MenuEnt *me, void *vst ) {
struct stuff *st = (struct stuff *)vst;
char str[64];
if(which >= st->ndata) which = st->ndata - 1;
if(which < 0) which = 0;
st->curdata = which;
sprintf(str, "seedata %.24s (%d)", st->dataname[which], which);
menu_settitle( me, str );
}
void set_every( float every, MenuEnt *me, void *vst ) {
char str[32];
struct stuff *st = (struct stuff *)vst;
if(every < 1) every = 1;
st->subsample = me->val = every;
sprintf(str, "every %dth p'cle (of %d)", (int)every, specks_count(st->sl));
menu_settitle( me, str );
}
void set_menu( int on, MenuEnt *me, void *vst ) {
struct stuff *st = (struct stuff *)vst;
if(me->state == ME_PICKED)
st->hidemenu = !st->hidemenu;
menu_sethidden( pmenu, st->hidemenu || empty );
menu_sethidden( stubmenu, st->hidemenu<=0 || empty );
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
}
void set_allboxes( int on, MenuEnt *me, void *vst ) {
struct stuff *st = (struct stuff *)vst;
st->useboxes = on;
menu_settitle( me, on==2 ? "Boxes ONLY" :
on ? "Boxes ON" : "Boxes off" );
}
void set_boxlevel( int on, MenuEnt *me, void *vblr ) {
struct boxleveler *blr = (struct boxleveler *)vblr;
struct stuff *st = blr->st;
int bit = 1 << blr->level;
char str[32];
if(blr->level >= st->boxlevels) {
menu_settitle(me, "" );
} else {
if(me->state == ME_PICKED)
st->boxlevelmask ^= bit;
sprintf(str, "Level %d %s", blr->level,
st->boxlevelmask & bit ? "ON" : "off" );
menu_settitle( me, str );
}
}
void
set_point( int on, MenuEnt *me, void *st )
{
struct stuff *stuff = (struct stuff *)st;
stuff->usepoint = (on<0) ? !stuff->usepoint : on;
menu_settitle( me, stuff->usepoint ? "Point On" : "Point Off" );
}
void
set_poly( int on, MenuEnt *me, void *st )
{
struct stuff *stuff = (struct stuff *)st;
stuff->usepoly = (on<0) ? !stuff->usepoly : on;
menu_settitle( me, stuff->usepoly ? "Poly On" : "Poly Off" );
}
void
set_label( int on, MenuEnt *me, void *st )
{
struct stuff *stuff = (struct stuff *)st;
stuff->usetext = (on<0) ? !stuff->usetext : on;
menu_settitle( me, stuff->usetext ? "Labels On" : "Labels Off" );
}
void
set_alpha( float alpha, MenuEnt *me, void *st )
{
char str[20];
((struct stuff *)st)->alpha = alpha;
sprintf(str, "Alpha %.2f", alpha);
menu_settitle( me, str );
}
void
set_fog( float fog, MenuEnt *me, void *st )
{
char str[20];
((struct stuff *)st)->fog = fog;
sprintf(str, "Fog %.2f (not yet)", fog);
menu_settitle( me, str );
}
void
set_polysize( float polysize, MenuEnt *me, void *st )
{
char str[20];
((struct stuff *)st)->polysize = polysize;
sprintf(str, "Spotsize %.2f", polysize);
menu_settitle( me, str );
}
#endif /*CAVEMENU*/
int specks_set_byvariable( struct stuff *st, char *str, int *val )
{
int i;
char *ep;
int best = -1;
if(str == NULL) return 0;
if(!strcasecmp( str, "const" ) || !strcasecmp( str, "constant" )
|| !strcasecmp( str, "rgb" )) {
*val = CONSTVAL;
return -1;
}
for(i = 0; i < MAXVAL; i++) {
if(strncasecmp( str, st->vdesc[st->curdata][i].name, strlen(str) ) == 0) {
best = i;
if(!strcmp( str, st->vdesc[st->curdata][i].name ))
break;
}
}
if(best >= 0) {
*val = best;
return 1;
}
i = strtol(str, &ep, 0);
if(ep == str || i < 0 || i > MAXVAL || (*ep != '\0' && *ep != '('))
return 0;
*val = i;
return 1;
}
static char *putcoords( char *buf, Point *pos, Matrix *T,
int isvec, char *cartfmt,
char *lonlatfmt, char *hmdmfmt )
{
Point p;
char *cp = buf;
float lat, lon, r;
if(T == NULL) T = &Tidentity;
buf[0] = '\0';
if(isvec)
vtfmvector( &p, pos, T );
else vtfmpoint( &p, pos, T );
if(cartfmt)
cp += sprintf(cp, cartfmt, p.x[0],p.x[1],p.x[2]);
lon = atan2(p.x[1], p.x[0]) * 180/M_PI;
if(lon < 0) lon += 360;
lat = atan2(p.x[2], hypot(p.x[1],p.x[0])) * 180/M_PI;
r = vlength(&p);
if(lonlatfmt)
cp += sprintf(cp, lonlatfmt, lon, lat, r);
if(hmdmfmt) {
char *sign = (lat < 0) ? "-" : "+";
lat = fabs(lat);
lon /= 15;
cp += sprintf(cp, hmdmfmt, (int)lon, 60. * (lon - (int)lon),
sign, (int)lat, 60. * (lat - (int)lat),
r);
}
return buf;
}
static char *whereis(struct stuff *st, char *buf, Point *pos, int isvec)
{
putcoords(buf, pos, NULL, isvec, "%.2f %.2f %.2f", NULL, NULL);
if(strstr(st->altcoord[0].name, "2000")
|| strstr(st->altcoord[0].name, "1950")
|| strstr(st->altcoord[0].name, "eq")) {
sprintf(buf + strlen(buf), "; %.9s: ", st->altcoord[0].name);
putcoords(buf+strlen(buf), pos, &st->altcoord[0].w2coord, isvec,
NULL, NULL, "%02d:%02.0f %s%02d:%02.0f %g");
} else if(st->altcoord[0].name[0] != '\0') {
sprintf(buf + strlen(buf), "; %.9s: ", st->altcoord[0].name);
putcoords(buf+strlen(buf), pos, &st->altcoord[0].w2coord, isvec,
NULL, "%.2f %.2f %g", NULL);
}
return buf;
}
static Point zero = {0,0,0}, forward = {0,0,-1};
#if CAVE
void set_where(int which, MenuEnt *me, void *vst) {
struct stuff *st = (struct stuff *)vst;
char buf[180];
Point pos;
Matrix cam2w;
switch(which) {
case 0:
CAVEGetPosition( CAVE_HEAD_NAV, pos.x );
sprintf(buf, "head at ");
whereis(st, buf+strlen(buf), &pos, 0);
break;
case 1:
VD_get_cam2world_matrix( cam2w.m );
vtfmpoint( &pos, &zero, &cam2w );
sprintf(buf, "camera at ");
whereis(st, buf+strlen(buf), &pos, 0);
break;
case 2:
VD_get_cam2world_matrix( cam2w.m );
vtfmvector( &pos, &forward, &cam2w );
sprintf(buf, "cam looks ");
whereis(st, buf+strlen(buf), &pos, 1);
break;
case 3:
VD_get_interest( pos.x );
sprintf(buf, "interest at ");
whereis(st, buf+strlen(buf), &pos, 0);
break;
default:
return;
}
menu_settitle( me, buf );
}
#endif /*CAVE*/
static void tellwhere(struct stuff *st)
{
Point pos, fwd;
Matrix cam2w;
char buf[180];
#ifdef CAVE
CAVENavConvertCAVEToWorld( zero.x, pos.x );
msg("cave at %s", whereis(st, buf, &pos, 0));
CAVEGetPosition( CAVE_WAND_NAV, pos.x );
msg("wand at %s", whereis(st, buf, &pos, 0));
CAVEGetVector( CAVE_WAND_FRONT_NAV, fwd.x );
VD_get_cam2world_matrix( cam2w.m );
#else
parti_getc2w( &cam2w );
#endif
vtfmpoint( &pos, &zero, &cam2w );
vtfmvector( &fwd, &forward, &cam2w );
msg("camera at %s", whereis(st, buf, &pos, 0));
msg("looking to %s", whereis(st, buf, &fwd, 1));
msg("c2w: %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g",
cam2w.m[0], cam2w.m[1], cam2w.m[2], cam2w.m[3],
cam2w.m[4], cam2w.m[5], cam2w.m[6], cam2w.m[7],
cam2w.m[8], cam2w.m[9], cam2w.m[10], cam2w.m[11],
cam2w.m[12], cam2w.m[13], cam2w.m[14], cam2w.m[15]);
}
FILE *asyncmd[MAX_ASYNC];
int specks_add_async( struct stuff *st, char *cmdstr )
{
int i;
#if unix /* not WIN32 */
if(cmdstr == NULL)
return -1;
for(i = 0; i < MAX_ASYNC; i++) {
if(asyncmd[i] == NULL) {
#if !CAVEMENU
parti_asyncfd( fileno( asyncmd[i] ) );
#endif
return i;
}
}
#endif /*unix*/
msg("Sorry, all %d async-command slots full: can't run %s", MAX_ASYNC, cmdstr);
return -1;
}
int specks_check_async( struct stuff **stp )
{
int i, any = 0;
char *av[128];
int ac;
char buf[5120], tbuf[5120];
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
static int reentered = 0; /* Don't allow recursion! */
#if unix /* not WIN32 */
if(stp == NULL || *stp == NULL) return 0;
if(reentered>0) return 0;
reentered = 1;
for(i = 0; i < MAX_ASYNC; i++) {
int brackets = 0;
int none = 1;
int nlines = 0;
while(asyncmd[i] && (none || brackets > 0)) {
int c = (brackets>0) ? fnextc(asyncmd[i], 1)
: async_fnextc(asyncmd[i], 1);
switch(c) {
case EOF:
if(getenv("DBG")) msg("Closing async %d", i);
#if !CAVEMENU
parti_unasyncfd( fileno( asyncmd[i] ) );
#endif
pclose(asyncmd[i]);
asyncmd[i] = NULL;
break;
case -2: /* NODATA */
none = 0;
break;
default:
/* Got something. Assume that we can read a whole line quickly. */
if(fgets(buf, sizeof(buf), asyncmd[i]) == NULL) {
if(getenv("DBG")) msg("fgets: Closing async %d", i);
pclose(asyncmd[i]);
asyncmd[i] = NULL;
break;
}
nlines++;
any++;
for(c = 0; isspace(buf[c]) || buf[c] == '{' || buf[c] == '}'; c++) {
if(buf[c] == '{') brackets++;
else if(buf[c] == '}' && brackets > 0) brackets--;
buf[c] = ' ';
}
if(getenv("DBG")) msg("async %d[%d]{%d}: %s", i, nlines, brackets, buf);
ac = tokenize( buf, tbuf, COUNT(av), av, 0 );
if(ac > 0) {
none = 0;
#if CAVEMENU
if(!specks_parse_args( stp, ac, av ))
VIDI_queue_commandstr( buf );