ref: f9b1182580fd66857a4a0cc11a328f9856f6039c
parent: fe76590b8d9e7ff1b23a5b4ada446e8540c8a602
author: rodri <rgl@antares-labs.eu>
date: Sat Jul 13 06:02:00 EDT 2024
get rid of redundant draw lock and adapt to libgraphics changes.
--- a/med.c
+++ b/med.c
@@ -76,7 +76,6 @@
Model *model;
Shadertab *shader;
QLock scenelk;
-QLock drawlk;
Mouse om;
Quaternion orient = {1,0,0,0};
@@ -219,7 +218,7 @@
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 @@
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
void
@@ -552,7 +550,7 @@
};
static Menu menu = { .item = items };
- qlock(&drawlk);
+ lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){
case TSNEAREST:
tsampler = neartexsampler;
@@ -563,7 +561,7 @@
case QUIT:
threadexitsall(nil);
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -591,7 +589,7 @@
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 @@
break;
}
nohit:
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -783,7 +781,7 @@
scene = newscene(nil);
model = newmodel();
- subject = newentity(model);
+ subject = newentity("main", model);
scene->addent(scene, subject);
addbasis();
--- a/solar.c
+++ b/solar.c
@@ -144,7 +144,6 @@
Tm date;
char datestr[16];
Scene *scene;
-QLock drawlk;
Camera camera;
Camcfg cameracfg = {
@@ -271,17 +270,6 @@
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 @@
Planet *p;
Point3 pos;
- p = getentityplanet(sp->su->entity);
+ p = getplanet(sp->su->entity->name);
assert(p != nil);
Matrix3 S = {
@@ -436,11 +424,10 @@
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
static char *
@@ -458,13 +445,13 @@
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 @@
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 @@
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 @@
snprint(datestr, sizeof datestr, "%τ", tmfmt(&date, datefmt));
updateplanets();
nodate:
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -573,7 +560,7 @@
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 @@
case QUIT:
threadexitsall(nil);
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -774,7 +761,7 @@
}
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++)
--- a/vis.c
+++ b/vis.c
@@ -57,7 +57,6 @@
Shadertab *shader;
Model *model;
Scene *scene;
-QLock drawlk;
Mouse om;
Quaternion orient = {1,0,0,0};
@@ -540,11 +539,10 @@
{
threadsetname("drawproc");
- for(;;)
- if(recv(drawc, nil) && canqlock(&drawlk)){
- redraw();
- qunlock(&drawlk);
- }
+ for(;;){
+ recv(drawc, nil);
+ redraw();
+ }
}
static Color
@@ -613,7 +611,7 @@
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 @@
shownormals ^= 1;
break;
}
- qunlock(&drawlk);
+ unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -654,7 +652,7 @@
static Menu menu = { .gen = genrmbmenuitem };
int idx;
- qlock(&drawlk);
+ lockdisplay(display);
idx = menuhit(3, mctl, &menu, _screen);
if(idx >= 0){
shader = &shadertab[idx];
@@ -661,7 +659,7 @@
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 @@
while(argc--){
mdlpath = argv[argc];
model = newmodel();
- subject = newentity(model);
+ subject = newentity(mdlpath, model);
// subject->p.x = argc*4;
scene->addent(scene, subject);