summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--med.c22
-rw-r--r--solar.c41
-rw-r--r--vis.c20
3 files changed, 33 insertions, 50 deletions
diff --git a/med.c b/med.c
index c4c0797..d8379af 100644
--- a/med.c
+++ b/med.c
@@ -76,7 +76,6 @@ Entity *subject;
Model *model;
Shadertab *shader;
QLock scenelk;
-QLock drawlk;
Mouse om;
Quaternion orient = {1,0,0,0};
@@ -219,7 +218,7 @@ addbasis(void)
Primitive prims[3];
m = newmodel();
- e = newentity(m);
+ e = newentity("basis", m);
e->RFrame3 = subject->RFrame3;
memset(prims, 0, sizeof prims);
@@ -508,11 +507,10 @@ drawproc(void *)
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
void
@@ -552,7 +550,7 @@ mmb(void)
};
static Menu menu = { .item = items };
- qlock(&drawlk);
+ lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){
case TSNEAREST:
tsampler = neartexsampler;
@@ -563,7 +561,7 @@ mmb(void)
case QUIT:
threadexitsall(nil);
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -591,7 +589,7 @@ rmb(void)
static Menu menu = { .gen = genrmbmenuitem };
int idx;
- qlock(&drawlk);
+ lockdisplay(display);
idx = menuhit(3, mctl, &menu, _screen);
if(idx < 0)
goto nohit;
@@ -606,7 +604,7 @@ rmb(void)
break;
}
nohit:
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -783,7 +781,7 @@ threadmain(int argc, char *argv[])
scene = newscene(nil);
model = newmodel();
- subject = newentity(model);
+ subject = newentity("main", model);
scene->addent(scene, subject);
addbasis();
diff --git a/solar.c b/solar.c
index f9b2712..679979a 100644
--- a/solar.c
+++ b/solar.c
@@ -144,7 +144,6 @@ int kdown;
Tm date;
char datestr[16];
Scene *scene;
-QLock drawlk;
Camera camera;
Camcfg cameracfg = {
@@ -271,17 +270,6 @@ getplanet(char *name)
return nil;
}
-static Planet *
-getentityplanet(Entity *e)
-{
- int i;
-
- for(i = 0; i < nelem(planets); i++)
- if(e == planets[i].body)
- return &planets[i];
- return nil;
-}
-
static void
gotoplanet(Planet *p)
{
@@ -330,7 +318,7 @@ identvshader(VSparams *sp)
Planet *p;
Point3 pos;
- p = getentityplanet(sp->su->entity);
+ p = getplanet(sp->su->entity->name);
assert(p != nil);
Matrix3 S = {
@@ -436,11 +424,10 @@ drawproc(void *)
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
static char *
@@ -458,13 +445,13 @@ lookat_cmd(Cmdbut *)
Planet *p;
int idx;
- qlock(&drawlk);
+ lockdisplay(display);
idx = menuhit(1, mctl, &menu, _screen);
if(idx >= 0){
p = &planets[idx];
placecamera(&camera, camera.p, p->body->p, cameracfg.up);
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -474,11 +461,11 @@ goto_cmd(Cmdbut *)
static Menu menu = { .gen = genplanetmenu };
int idx;
- qlock(&drawlk);
+ lockdisplay(display);
idx = menuhit(1, mctl, &menu, _screen);
if(idx >= 0)
gotoplanet(&planets[idx]);
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -492,7 +479,7 @@ date_cmd(Cmdbut *)
return;
memmove(buf, datestr, sizeof buf);
- qlock(&drawlk);
+ lockdisplay(display);
if(enter("new date", buf, sizeof buf, mctl, kctl, nil) <= 0)
goto nodate;
if(tmparse(&t, datefmt, buf, nil, nil) == nil)
@@ -501,7 +488,7 @@ date_cmd(Cmdbut *)
snprint(datestr, sizeof datestr, "%τ", tmfmt(&date, datefmt));
updateplanets();
nodate:
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -573,7 +560,7 @@ mmb(void)
if((om.buttons ^ mctl->buttons) == 0)
return;
- qlock(&drawlk);
+ lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){
case CHGSPEED:
snprint(buf, sizeof buf, "%g", speed);
@@ -583,7 +570,7 @@ mmb(void)
case QUIT:
threadexitsall(nil);
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -774,7 +761,7 @@ threadmain(int argc, char *argv[])
}
scene = newscene(nil);
for(i = 0; i < nelem(planets); i++){
- subject = newentity(model);
+ subject = newentity(planets[i].name, model);
scene->addent(scene, subject);
planets[i].body = subject;
for(j = 0; j < model->nmaterials; j++)
diff --git a/vis.c b/vis.c
index e43c170..b443905 100644
--- a/vis.c
+++ b/vis.c
@@ -57,7 +57,6 @@ int kdown;
Shadertab *shader;
Model *model;
Scene *scene;
-QLock drawlk;
Mouse om;
Quaternion orient = {1,0,0,0};
@@ -540,11 +539,10 @@ drawproc(void *)
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
static Color
@@ -613,7 +611,7 @@ mmb(void)
char buf[256], *f[3];
int nf;
- qlock(&drawlk);
+ lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){
case MOVELIGHT:
snprint(buf, sizeof buf, "%g %g %g", light.p.x, light.p.y, light.p.z);
@@ -636,7 +634,7 @@ mmb(void)
shownormals ^= 1;
break;
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -654,14 +652,14 @@ rmb(void)
static Menu menu = { .gen = genrmbmenuitem };
int idx;
- qlock(&drawlk);
+ lockdisplay(display);
idx = menuhit(3, mctl, &menu, _screen);
if(idx >= 0){
shader = &shadertab[idx];
for(idx = 0; idx < nelem(cams); idx++)
memset(&cams[idx].stats, 0, sizeof(cams[idx].stats));
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -856,7 +854,7 @@ threadmain(int argc, char *argv[])
while(argc--){
mdlpath = argv[argc];
model = newmodel();
- subject = newentity(model);
+ subject = newentity(mdlpath, model);
// subject->p.x = argc*4;
scene->addent(scene, subject);