shithub: 3dee

Download patch

ref: 8dca0cb97c2750ee2d2f57c01a5ece8dc5752c35
parent: 1e2596cb1497bd8e491a3b9cd05062a98256ab5d
author: rodri <rgl@antares-labs.eu>
date: Sat Jul 20 08:10:32 EDT 2024

improve redraw responsiveness.

--- a/med.c
+++ b/med.c
@@ -470,7 +470,6 @@
 redraw(void)
 {
 	lockdisplay(display);
-	cam->view->draw(cam->view, screenb);
 	draw(screen, screen->r, screenb, nil, ZP);
 	if(showhud)
 		drawstats();
@@ -498,6 +497,9 @@
 			cam->times.Rn[cam->times.cur-1].t0, cam->times.Rn[cam->times.cur-1].t1);
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
+			lockdisplay(display);
+			cam->view->draw(cam->view, screenb);
+			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
 		}
--- a/solar.c
+++ b/solar.c
@@ -386,7 +386,6 @@
 	int i;
 
 	lockdisplay(display);
-	camera->view->draw(camera->view, screenb);
 	draw(screen, rectaddpt(viewr, screen->r.min), screenb, nil, ZP);
 	draw(screen, rectaddpt(cmdbox.r, screen->r.min), display->white, nil, ZP);
 	for(i = 0; i < cmdbox.ncmds; i++){
@@ -417,6 +416,9 @@
 			camera->times.Rn[camera->times.cur-1].t0, camera->times.Rn[camera->times.cur-1].t1);
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
+			lockdisplay(display);
+			camera->view->draw(camera->view, screenb);
+			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
 		}
--- a/vis.c
+++ b/vis.c
@@ -495,10 +495,6 @@
 redraw(void)
 {
 	lockdisplay(display);
-	if(shownormals)
-		maincam->view->fbctl->drawnormals(maincam->view->fbctl, screenb);
-	else
-		maincam->view->draw(maincam->view, screenb);
 	draw(screen, screen->r, screenb, nil, ZP);
 	if(showhud)
 		drawstats();
@@ -529,12 +525,18 @@
 		shootcamera(maincam, shader);
 		if(doprof)
 		fprint(2, "R %llud %llud\nE %llud %llud\nT %llud %llud\nr %llud %llud\n\n",
-			maincam->times.R[maincam->times.cur-1].t0, maincam->times.R[maincam->times.cur-1].t1,
-			maincam->times.E[maincam->times.cur-1].t0, maincam->times.E[maincam->times.cur-1].t1,
-			maincam->times.Tn[maincam->times.cur-1].t0, maincam->times.Tn[maincam->times.cur-1].t1,
-			maincam->times.Rn[maincam->times.cur-1].t0, maincam->times.Rn[maincam->times.cur-1].t1);
+			maincam->times.R[maincam->times.last].t0, maincam->times.R[maincam->times.last].t1,
+			maincam->times.E[maincam->times.last].t0, maincam->times.E[maincam->times.last].t1,
+			maincam->times.Tn[maincam->times.last].t0, maincam->times.Tn[maincam->times.last].t1,
+			maincam->times.Rn[maincam->times.last].t0, maincam->times.Rn[maincam->times.last].t1);
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
+			lockdisplay(display);
+			if(shownormals)
+				maincam->view->fbctl->drawnormals(maincam->view->fbctl, screenb);
+			else
+				maincam->view->draw(maincam->view, screenb);
+			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
 			if(inception){
@@ -946,6 +948,7 @@
 		placecamera(cams[i], scene, camcfgs[i].p, camcfgs[i].lookat, camcfgs[i].up);
 		cams[i]->view->bx.x = Dx(screenb->r)/Dx(cams[i]->view->r);
 		cams[i]->view->by.y = Dy(screenb->r)/Dy(cams[i]->view->r);
+fprint(2, "scalex %g scaley %g\n", cams[i]->view->bx.x, cams[i]->view->by.y);
 	}
 	maincam = cams[3];
 	light.p = Pt3(0,100,100,1);