ref: 5c1343cbd75656fc976c4a5aaa6a51ce4ddf1380
parent: 37b243c4eace5777e584c7e9c9d3c0578439be49
author: rodri <rgl@antares-labs.eu>
date: Sat Feb 14 11:59:33 EST 2026
adapt to new changes in libgraphics SUparams was removed. there also some leftover changes which i just have to push.
--- a/med.c
+++ b/med.c
@@ -456,7 +456,6 @@
void
redraw(void)
{- lockdisplay(display);
draw(screen, screen->r, screenb, nil, ZP);
usrlog->draw(usrlog);
drawopmode();
@@ -463,7 +462,6 @@
if(showhud)
drawstats();
flushimage(display, 1);
- unlockdisplay(display);
}
void
@@ -493,11 +491,9 @@
Δt = nanosec() - t0;
if(Δt > HZ2NS(60)){- lockdisplay(display);
draw(screenb, screenb->r, bg, nil, ZP);
cam->view->draw(cam->view, screenb, nil);
compass.cam->view->draw(compass.cam->view, screenb, nil);
- unlockdisplay(display);
nbsend(drawc, nil);
t0 = nanosec();
@@ -609,7 +605,6 @@
static char buf[256];
int fd;
- lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){case ORBIT:
opmode = OMOrbit;
@@ -618,7 +613,7 @@
opmode = OMSelect;
break;
case SAVE:
- if(enter("path", buf, sizeof buf, mctl, kctl, nil) <= 0)+ if(enter("path", buf, sizeof buf, mctl, kctl, _screen) <= 0)break;
fd = create(buf, OWRITE, 0644);
if(fd < 0){@@ -631,7 +626,6 @@
case QUIT:
threadexitsall(nil);
}
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -659,7 +653,6 @@
static Menu menu = { .gen = genrmbmenuitem };int idx;
- lockdisplay(display);
idx = menuhit(3, mctl, &menu, _screen);
if(idx < 0)
goto nohit;
@@ -674,7 +667,6 @@
break;
}
nohit:
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -774,10 +766,8 @@
void
resize(void)
{- lockdisplay(display);
if(getwindow(display, Refnone) < 0)
fprint(2, "can't reattach to window\n");
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -869,8 +859,6 @@
kctl->c = chancreate(sizeof(Rune), 16);
keyc = chancreate(sizeof(void*), 1);
drawc = chancreate(sizeof(void*), 1);
- display->locking = 1;
- unlockdisplay(display);
proccreate(kbdproc, nil, mainstacksize);
proccreate(keyproc, keyc, mainstacksize);
--- a/plot3.c
+++ b/plot3.c
@@ -64,7 +64,7 @@
static Point3
vs(Shaderparams *sp)
{- return world2clip(sp->su->camera, model2world(sp->su->entity, sp->v->p));
+ return world2clip(sp->camera, model2world(sp->entity, sp->v->p));
}
static Color
@@ -277,10 +277,8 @@
redrawb(void)
{shootcamera(cam, &shaders);
- lockdisplay(display);
draw(screenb, screenb->r, display->white, nil, ZP);
cam->view->draw(cam->view, screenb, nil);
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -287,10 +285,8 @@
void
redraw(void)
{- lockdisplay(display);
draw(screen, screen->r, screenb, nil, ZP);
flushimage(display, 1);
- unlockdisplay(display);
}
void
@@ -358,10 +354,8 @@
void
resize(void)
{- lockdisplay(display);
if(getwindow(display, Refnone) < 0)
fprint(2, "can't reattach to window\n");
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -412,9 +406,6 @@
screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, DNofill);
cam = Cam(screenb->r, rctl, PERSPECTIVE, 90*DEG, 0.1, 1000);
placecamera(cam, theplot.scn, addpt3(theplot.bbox.c, mulpt3(normvec3(Vec3(1,1,1)), 1.5*theplot.bbox.r)), theplot.bbox.c, Vec3(0,1,0));
-
- display->locking = 1;
- unlockdisplay(display);
drawc = chancreate(sizeof(void*), 1);
proccreate(drawproc, nil, mainstacksize);
--- a/procgen.c
+++ b/procgen.c
@@ -112,8 +112,8 @@
double dt, shift, h, time;
uv = Pt2(sp->p.x,sp->p.y,1);
- uv.x /= Dx(sp->su->fb->r);
- uv.y /= Dy(sp->su->fb->r);
+ uv.x /= Dx(sp->fb->r);
+ uv.y /= Dy(sp->fb->r);
uv.y = 1 - uv.y; /* make [0 0] the bottom-left corner */
va = sp->getuniform(sp, "time");
--- a/raymarch.c
+++ b/raymarch.c
@@ -99,9 +99,9 @@
int i;
uv = Pt2(sp->p.x, sp->p.y, 1);
- uv.x = 2*uv.x - Dx(sp->su->fb->r);
- uv.y = Dy(sp->su->fb->r) - 2*uv.y;
- uv = divpt2(uv, Dy(sp->su->fb->r));
+ uv.x = 2*uv.x - Dx(sp->fb->r);
+ uv.y = Dy(sp->fb->r) - 2*uv.y;
+ uv = divpt2(uv, Dy(sp->fb->r));
va = sp->getuniform(sp, "time");
time = va == nil? 0: va->n;
@@ -110,9 +110,9 @@
va = sp->getuniform(sp, "mouse");
mpt = va == nil? ZP3: va->p;
m = Pt2(mpt.x, mpt.y, 1);
- m.x = 2*m.x - Dx(sp->su->fb->r);
- m.y = Dy(sp->su->fb->r) - 2*m.y;
- m = divpt2(m, Dy(sp->su->fb->r)/2);
+ m.x = 2*m.x - Dx(sp->fb->r);
+ m.y = Dy(sp->fb->r) - 2*m.y;
+ m = divpt2(m, Dy(sp->fb->r)/2);
ro = Pt3(0, 0, 3, 1);
rd = normvec3(Vec3(uv.x, uv.y, -1));
@@ -143,16 +143,14 @@
void
redraw(void)
{- lockdisplay(display);
draw(screen, screen->r, screenb, nil, ZP);
flushimage(display, 1);
- unlockdisplay(display);
}
void
-drawproc(void *)
+drawthread(void *)
{- threadsetname("drawproc");+ threadsetname("drawthread"); for(;;){recv(drawc, nil);
@@ -179,10 +177,8 @@
Δt = nanosec() - t0;
if(Δt > HZ2NS(60)){- lockdisplay(display);
draw(screenb, screenb->r, display->black, nil, ZP);
cam->view->draw(cam->view, screenb, nil);
- unlockdisplay(display);
nbsend(drawc, nil);
t0 = nanosec();
}else{@@ -204,10 +200,8 @@
void
resize(void)
{- lockdisplay(display);
if(getwindow(display, Refnone) < 0)
fprint(2, "can't reattach to window\n");
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -299,11 +293,9 @@
scn->addent(scn, ent);
drawc = chancreate(sizeof(void*), 1);
- display->locking = 1;
- unlockdisplay(display);
proccreate(renderproc, nil, mainstacksize);
- proccreate(drawproc, nil, mainstacksize);
+ threadcreate(drawthread, nil, mainstacksize);
enum {MOUSE, RESIZE, KEY}; Alt a[] = {--- a/shaders.inc
+++ b/shaders.inc
@@ -11,8 +11,8 @@
LightSource *l;
Color ambient, diffuse, specular, lightc;
- sp->v->n = model2world(sp->su->entity, sp->v->n);
- sp->v->p = model2world(sp->su->entity, sp->v->p);
+ sp->v->n = model2world(sp->entity, sp->v->n);
+ sp->v->p = model2world(sp->entity, sp->v->p);
if(sp->v->mtl != nil)
m = *sp->v->mtl;
@@ -23,10 +23,10 @@
m.shininess = 1;
}
- lightc = getscenecolor(sp->su->camera->scene, sp->v->p, sp->v->n);
+ lightc = getscenecolor(sp->scene, sp->v->p, sp->v->n);
sp->v->c = ZP3;
- for(l = sp->su->camera->scene->lights.next; l != &sp->su->camera->scene->lights; l = l->next){+ for(l = sp->scene->lights.next; l != &sp->scene->lights; l = l->next){lightdir = normvec3(subpt3(l->p, sp->v->p));
ambient = mulpt3(lightc, Ka);
@@ -36,7 +36,7 @@
diffuse = mulpt3(lightc, Kd);
diffuse = modulapt3(diffuse, m.diffuse);
- lookdir = normvec3(subpt3(sp->su->camera->p, sp->v->p));
+ lookdir = normvec3(subpt3(sp->camera->p, sp->v->p));
lightdir = qrotate(lightdir, sp->v->n, PI); /* reflect */
spec = pow(max(0, _Xdotvec3(lookdir, lightdir)), m.shininess);
specular = mulpt3(lightc, spec*Ks);
@@ -45,7 +45,7 @@
sp->v->c = addpt3(sp->v->c, addpt3(ambient, addpt3(diffuse, specular)));
}
sp->v->c.a = m.diffuse.a;
- return world2clip(sp->su->camera, sp->v->p);
+ return world2clip(sp->camera, sp->v->p);
}
Color
@@ -67,12 +67,12 @@
Point3
phongvshader(Shaderparams *sp)
{- sp->v->n = model2world(sp->su->entity, sp->v->n);
- sp->v->p = model2world(sp->su->entity, sp->v->p);
+ sp->v->n = model2world(sp->entity, sp->v->n);
+ sp->v->p = model2world(sp->entity, sp->v->p);
sp->setattr(sp, "pos", VAPoint, &sp->v->p);
if(sp->v->mtl != nil){if(sp->v->mtl->normalmap != nil && sp->v->uv.w != 0)
- sp->v->tangent = model2world(sp->su->entity, sp->v->tangent);
+ sp->v->tangent = model2world(sp->entity, sp->v->tangent);
sp->setattr(sp, "ambient", VAPoint, &sp->v->mtl->ambient);
sp->setattr(sp, "diffuse", VAPoint, &sp->v->mtl->diffuse);
@@ -79,7 +79,7 @@
sp->setattr(sp, "specular", VAPoint, &sp->v->mtl->specular);
sp->setattr(sp, "shininess", VANumber, &sp->v->mtl->shininess);
}
- return world2clip(sp->su->camera, sp->v->p);
+ return world2clip(sp->camera, sp->v->p);
}
Color
@@ -131,10 +131,10 @@
m.specular = sampletexture(sp->v->mtl->specularmap, sp->v->uv, tsampler);
}
- lightc = getscenecolor(sp->su->camera->scene, pos, n);
+ lightc = getscenecolor(sp->scene, pos, n);
sp->v->c = ZP3;
- for(l = sp->su->camera->scene->lights.next; l != &sp->su->camera->scene->lights; l = l->next){+ for(l = sp->scene->lights.next; l != &sp->scene->lights; l = l->next){lightdir = normvec3(subpt3(l->p, pos));
ambient = mulpt3(lightc, Ka);
@@ -144,7 +144,7 @@
diffuse = mulpt3(lightc, Kd);
diffuse = modulapt3(diffuse, m.diffuse);
- lookdir = normvec3(subpt3(sp->su->camera->p, pos));
+ lookdir = normvec3(subpt3(sp->camera->p, pos));
lightdir = qrotate(lightdir, n, PI); /* reflect */
spec = pow(max(0, _Xdotvec3(lookdir, lightdir)), m.shininess);
specular = mulpt3(lightc, spec*Ks);
@@ -212,10 +212,10 @@
m.specular = sampletexture(sp->v->mtl->specularmap, sp->v->uv, tsampler);
}
- lightc = getscenecolor(sp->su->camera->scene, pos, n);
+ lightc = getscenecolor(sp->scene, pos, n);
sp->v->c = ZP3;
- for(l = sp->su->camera->scene->lights.next; l != &sp->su->camera->scene->lights; l = l->next){+ for(l = sp->scene->lights.next; l != &sp->scene->lights; l = l->next){lightdir = normvec3(subpt3(l->p, pos));
ambient = mulpt3(lightc, Ka);
@@ -225,7 +225,7 @@
diffuse = mulpt3(lightc, Kd);
diffuse = modulapt3(diffuse, m.diffuse);
- lookdir = normvec3(subpt3(sp->su->camera->p, pos));
+ lookdir = normvec3(subpt3(sp->camera->p, pos));
lightdir = normvec3(addpt3(lookdir, lightdir)); /* half vector */
spec = pow(max(0, _Xdotvec3(lookdir, lightdir)), m.shininess);
specular = mulpt3(lightc, spec*Ks);
@@ -251,10 +251,10 @@
LightSource *l;
double intens;
- sp->v->n = model2world(sp->su->entity, sp->v->n);
- sp->v->p = model2world(sp->su->entity, sp->v->p);
+ sp->v->n = model2world(sp->entity, sp->v->n);
+ sp->v->p = model2world(sp->entity, sp->v->p);
intens = 0;
- for(l = sp->su->camera->scene->lights.next; l != &sp->su->camera->scene->lights; l = l->next){+ for(l = sp->scene->lights.next; l != &sp->scene->lights; l = l->next){lightdir = normvec3(subpt3(l->p, sp->v->p));
intens += max(0, _Xdotvec3(sp->v->n, lightdir));
}
@@ -261,7 +261,7 @@
sp->setattr(sp, "intensity", VANumber, &intens);
if(sp->v->mtl != nil)
sp->v->c = sp->v->mtl->diffuse;
- return world2clip(sp->su->camera, sp->v->p);
+ return world2clip(sp->camera, sp->v->p);
}
Color
@@ -289,7 +289,7 @@
{if(sp->v->mtl != nil)
sp->v->c = sp->v->mtl->diffuse;
- return world2clip(sp->su->camera, model2world(sp->su->entity, sp->v->p));
+ return world2clip(sp->camera, model2world(sp->entity, sp->v->p));
}
Color
@@ -311,9 +311,9 @@
Point3
ivshader(Shaderparams *sp)
{- sp->v->n = model2world(sp->su->entity, sp->v->n);
- sp->v->p = model2world(sp->su->entity, sp->v->p);
- return world2clip(sp->su->camera, sp->v->p);
+ sp->v->n = model2world(sp->entity, sp->v->n);
+ sp->v->p = model2world(sp->entity, sp->v->p);
+ return world2clip(sp->camera, sp->v->p);
}
Color
@@ -374,8 +374,8 @@
double r, d, time;
uv = Pt2(sp->p.x,sp->p.y,1);
- uv.x /= Dx(sp->su->fb->r);
- uv.y /= Dy(sp->su->fb->r);
+ uv.x /= Dx(sp->fb->r);
+ uv.y /= Dy(sp->fb->r);
va = sp->getuniform(sp, "time");
time = va == nil? 0: va->n;
@@ -399,8 +399,8 @@
double y, pct, time;
uv = Pt2(sp->p.x,sp->p.y,1);
- uv.x /= Dx(sp->su->fb->r);
- uv.y /= Dy(sp->su->fb->r);
+ uv.x /= Dx(sp->fb->r);
+ uv.y /= Dy(sp->fb->r);
uv.y = 1 - uv.y; /* make [0 0] the bottom-left corner */
va = sp->getuniform(sp, "time");
@@ -423,8 +423,8 @@
Point2 r;
uv = Pt2(sp->p.x,sp->p.y,1);
- uv.x /= Dx(sp->su->fb->r);
- uv.y /= Dy(sp->su->fb->r);
+ uv.x /= Dx(sp->fb->r);
+ uv.y /= Dy(sp->fb->r);
r = Vec2(0.2,0.4);
p = Pt2(fabs(uv.x - 0.5), fabs(uv.y - 0.5), 1);
--- a/solar.c
+++ b/solar.c
@@ -297,10 +297,8 @@
}
qunlock(&scenelk);
- lockdisplay(display);
freeinfobox(infobox);
infobox = nil;
- unlockdisplay(display);
/* if nil, we cleaned the selection and infobox, so now get out */
if(p == nil)
@@ -311,9 +309,7 @@
esel = newentity("selection", msel);esel->RFrame3 = e->RFrame3;
- lockdisplay(display);
infobox = mkplanetinfobox(p, Rpt(subpt(viewr.max, Pt(500,250)), viewr.max));
- unlockdisplay(display);
memset(&aabb, 0, sizeof aabb);
pt = e->mdl->positions->items;
@@ -478,7 +474,7 @@
{Planet *p;
- p = getplanet(sp->su->entity->name);
+ p = getplanet(sp->entity->name);
if(p != nil){ Matrix3 S = {@@ -492,7 +488,7 @@
sp->v->c = p->mtl->diffuse;
}
- return world2clip(sp->su->camera, model2world(sp->su->entity, sp->v->p));
+ return world2clip(sp->camera, model2world(sp->entity, sp->v->p));
}
Color
@@ -544,7 +540,6 @@
{int i;
- lockdisplay(display);
draw(screen, rectaddpt(viewr, screen->r.min), screenb, nil, ZP);
draw(screen, rectaddpt(cmdbox.r, screen->r.min), display->white, nil, ZP);
drawinfobox(screen, infobox);
@@ -555,7 +550,6 @@
if(showhud)
drawstats();
flushimage(display, 1);
- unlockdisplay(display);
}
void
@@ -576,10 +570,8 @@
Δt = nanosec() - t0;
if(Δt > HZ2NS(60)){- lockdisplay(display);
draw(screenb, screenb->r, bg, nil, ZP);
camera->view->draw(camera->view, screenb, nil);
- unlockdisplay(display);
nbsend(drawc, nil);
t0 = nanosec();
}else{@@ -593,9 +585,9 @@
}
void
-drawproc(void *)
+drawthread(void *)
{- threadsetname("drawproc");+ threadsetname("drawthread"); for(;;){recv(drawc, nil);
@@ -618,13 +610,11 @@
Planet *p;
int idx;
- lockdisplay(display);
idx = menuhit(1, mctl, &menu, _screen);
if(idx >= 0){p = &planets[idx];
aimcamera(camera, p->body->p);
}
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -634,11 +624,9 @@
static Menu menu = { .gen = genplanetmenu };int idx;
- lockdisplay(display);
idx = menuhit(1, mctl, &menu, _screen);
if(idx >= 0)
gotoplanet(&planets[idx]);
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -652,8 +640,7 @@
return;
memmove(buf, datestr, sizeof buf);
- lockdisplay(display);
- if(enter("new date", buf, sizeof buf, mctl, kctl, nil) <= 0)+ if(enter("new date", buf, sizeof buf, mctl, kctl, _screen) <= 0)goto nodate;
if(tmparse(&t, datefmt, buf, nil, nil) == nil)
goto nodate;
@@ -661,7 +648,6 @@
snprint(datestr, sizeof datestr, "%τ", tmfmt(&date, datefmt));
updateplanets();
nodate:
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -731,17 +717,15 @@
if((om.buttons ^ mctl->buttons) == 0)
return;
- lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){case CHGSPEED:
snprint(buf, sizeof buf, "%g", speed);
- if(enter("speed (km)", buf, sizeof buf, mctl, kctl, nil) > 0)+ if(enter("speed (km)", buf, sizeof buf, mctl, kctl, _screen) > 0)speed = fabs(strtod(buf, nil));
break;
case QUIT:
threadexitsall(nil);
}
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -861,10 +845,8 @@
void
resize(void)
{- lockdisplay(display);
if(getwindow(display, Refnone) < 0)
fprint(2, "can't reattach to window\n");
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -987,13 +969,12 @@
kctl->c = chancreate(sizeof(Rune), 16);
keyc = chancreate(sizeof(void*), 1);
drawc = chancreate(sizeof(void*), 1);
- display->locking = 1;
- unlockdisplay(display);
proccreate(kbdproc, nil, mainstacksize);
proccreate(keyproc, keyc, mainstacksize);
proccreate(renderproc, nil, mainstacksize);
- proccreate(drawproc, nil, mainstacksize);
+
+ threadcreate(drawthread, nil, mainstacksize);
enum {MOUSE, RESIZE, KEY}; Alt a[] = {--- a/vis.c
+++ b/vis.c
@@ -252,12 +252,10 @@
void
redraw(void)
{- lockdisplay(display);
draw(screen, screen->r, screenb, nil, ZP);
if(showhud)
drawstats();
flushimage(display, 1);
- unlockdisplay(display);
}
void
@@ -300,10 +298,8 @@
Δt = nanosec() - t0;
if(Δt > HZ2NS(60)){- lockdisplay(display);
draw(screenb, screenb->r, clr, nil, ZP);
maincam->view->draw(maincam->view, screenb, curraster);
- unlockdisplay(display);
nbsend(drawc, nil);
@@ -325,9 +321,9 @@
}
void
-drawproc(void *)
+drawthread(void *)
{- threadsetname("drawproc");+ threadsetname("drawthread"); for(;;){recv(drawc, nil);
@@ -448,16 +444,18 @@
int nf;
ulong clrcol;
- lockdisplay(display);
switch(menuhit(2, mctl, &menu, _screen)){case MOVELIGHT:
qlock(&scenelk);
snprint(buf, sizeof buf, "%g %g %g", lights[0]->p.x, lights[0]->p.y, lights[0]->p.z);
- if(enter("light pos", buf, sizeof buf, mctl, kctl, nil) <= 0)+ qunlock(&scenelk);
+ if(enter("light pos", buf, sizeof buf, mctl, kctl, _screen) <= 0){break;
+ }
nf = tokenize(buf, f, 3);
if(nf != 3)
break;
+ qlock(&scenelk);
lights[0]->p.x = strtod(f[0], nil);
lights[0]->p.y = strtod(f[1], nil);
lights[0]->p.z = strtod(f[2], nil);
@@ -464,10 +462,14 @@
qunlock(&scenelk);
break;
case TSNEAREST:
+ qlock(&scenelk);
tsampler = neartexsampler;
+ qunlock(&scenelk);
break;
case TSBILINEAR:
+ qlock(&scenelk);
tsampler = bilitexsampler;
+ qunlock(&scenelk);
break;
case SHOWNORMALS:
curraster = curraster && strcmp(curraster, "normals") == 0? nil: "normals";
@@ -483,7 +485,7 @@
break;
clrcol = clrcol<<8 | 0xFF; /* xrgb2rgba */
snprint(buf, sizeof buf, "0x%08lux", clrcol);
- if(enter("clear color", buf, sizeof buf, mctl, kctl, nil) <= 0)+ if(enter("clear color", buf, sizeof buf, mctl, kctl, _screen) <= 0)break;
nf = tokenize(buf, f, 1);
if(nf != 1)
@@ -514,7 +516,6 @@
viewabuffer();
break;
}
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -532,7 +533,6 @@
static Menu menu = { .gen = genrmbmenuitem };int idx;
- lockdisplay(display);
idx = menuhit(3, mctl, &menu, _screen);
if(idx >= 0){shader = &shadertab[idx];
@@ -546,7 +546,6 @@
// maincam->view->p.x += p.x;
// maincam->view->p.y += p.y;
// }
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -715,10 +714,8 @@
void
resize(void)
{- lockdisplay(display);
if(getwindow(display, Refnone) < 0)
fprint(2, "can't reattach to window\n");
- unlockdisplay(display);
nbsend(drawc, nil);
}
@@ -879,13 +876,12 @@
kctl->c = chancreate(sizeof(Rune), 16);
keyc = chancreate(sizeof(void*), 1);
drawc = chancreate(sizeof(void*), 1);
- display->locking = 1;
- unlockdisplay(display);
proccreate(kbdproc, nil, mainstacksize);
proccreate(keyproc, keyc, mainstacksize);
proccreate(renderproc, nil, mainstacksize);
- proccreate(drawproc, nil, mainstacksize);
+
+ threadcreate(drawthread, nil, mainstacksize);
enum {MOUSE, RESIZE, KEY}; Alt a[] = {--
⑨