summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-06-29 18:24:47 +0000
committerrodri <rgl@antares-labs.eu>2020-06-29 18:24:47 +0000
commit5f823efa33ea598dabc3cb584363aa967bdf7b08 (patch)
treef2b4318f687a0fecd31d3adfc550234957e9edac
parent5d9dbc72e1c63b378023a283e53e43dc01a7b98c (diff)
download3dee-5f823efa33ea598dabc3cb584363aa967bdf7b08.tar.gz
3dee-5f823efa33ea598dabc3cb584363aa967bdf7b08.tar.bz2
3dee-5f823efa33ea598dabc3cb584363aa967bdf7b08.zip
localize the draw channel. put the alloc code in its own module.
-rw-r--r--alloc.c44
-rw-r--r--fns.h3
-rw-r--r--main.c45
-rw-r--r--mkfile1
4 files changed, 62 insertions, 31 deletions
diff --git a/alloc.c b/alloc.c
new file mode 100644
index 0000000..2589e89
--- /dev/null
+++ b/alloc.c
@@ -0,0 +1,44 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+void*
+emalloc(ulong n)
+{
+ void *p;
+
+ p = malloc(n);
+ if(p == nil)
+ sysfatal("malloc: %r");
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
+
+void*
+erealloc(void *p, ulong n)
+{
+ void *np;
+
+ np = realloc(p, n);
+ if(np == nil){
+ if(n == 0)
+ return nil;
+ sysfatal("realloc: %r");
+ }
+ if(p == nil)
+ setmalloctag(np, getcallerpc(&p));
+ else
+ setrealloctag(np, getcallerpc(&p));
+ return np;
+}
+
+Image*
+eallocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
+{
+ Image *i;
+
+ i = allocimage(d, r, chan, repl, col);
+ if(i == nil)
+ sysfatal("allocimage: %r");
+ return i;
+}
diff --git a/fns.h b/fns.h
index 0b4e1ba..ece9b68 100644
--- a/fns.h
+++ b/fns.h
@@ -1,2 +1,3 @@
-void *erealloc(void*, ulong);
void *emalloc(ulong);
+void *erealloc(void*, ulong);
+Image *eallocimage(Display*, Rectangle, ulong, int, ulong);
diff --git a/main.c b/main.c
index 72112d0..14468fa 100644
--- a/main.c
+++ b/main.c
@@ -41,7 +41,6 @@ Rune keys[Ke] = {
char stats[Se][256];
Mousectl *mctl;
-Channel *drawc;
int kdown;
vlong t0, t;
double Δt;
@@ -70,30 +69,6 @@ Camcfg camcfgs[4] = {
120*DEG, 0.1, 100, Ppersp
};
-void *
-emalloc(ulong n)
-{
- void *p;
-
- p = malloc(n);
- if(p == nil)
- sysfatal("malloc: %r");
- setmalloctag(p, getcallerpc(&n));
- return p;
-}
-
-void *
-erealloc(void *p, ulong n)
-{
- void *np;
-
- np = realloc(p, n);
- if(np == nil)
- sysfatal("realloc: %r");
- setrealloctag(np, getcallerpc(&p));
- return np;
-}
-
int
depthcmp(void *a, void *b)
{
@@ -203,11 +178,15 @@ redraw(void)
}
void
-drawproc(void *)
+drawproc(void *drawc)
{
+ Channel *c;
+
threadsetname("drawproc");
+
+ c = drawc;
for(;;){
- send(drawc, nil);
+ send(c, nil);
sleep(MS2FR);
}
}
@@ -352,6 +331,7 @@ void
threadmain(int argc, char *argv[])
{
OBJ *objmesh;
+ Channel *drawc;
int i;
GEOMfmtinstall();
@@ -363,10 +343,12 @@ threadmain(int argc, char *argv[])
}ARGEND;
if(argc != 0)
usage();
+
if(initdraw(nil, nil, "3d") < 0)
sysfatal("initdraw: %r");
if((mctl = initmouse(nil, screen)) == nil)
sysfatal("initmouse: %r");
+
for(i = 0; i < nelem(cams); i++){
placecamera(&cams[i], camcfgs[i].p, camcfgs[i].lookat, camcfgs[i].up);
configcamera(&cams[i], screen, camcfgs[i].fov, camcfgs[i].clipn, camcfgs[i].clipf, camcfgs[i].ptype);
@@ -374,11 +356,14 @@ threadmain(int argc, char *argv[])
maincam = &cams[0];
if((objmesh = objparse(mdlpath)) == nil)
sysfatal("objparse: %r");
- drawc = chancreate(1, 0);
+
display->locking = 1;
unlockdisplay(display);
- proccreate(drawproc, nil, mainstacksize);
- proccreate(kbdproc, nil, mainstacksize);
+
+ drawc = chancreate(1, 0);
+ proccreate(drawproc, drawc, 1024);
+ proccreate(kbdproc, nil, 4096);
+
t0 = nsec();
for(;;){
enum {MOUSE, RESIZE, DRAW};
diff --git a/mkfile b/mkfile
index 7e1d254..14aa18c 100644
--- a/mkfile
+++ b/mkfile
@@ -3,6 +3,7 @@
BIN=$home/$objtype/bin
TARG=3d
OFILES=\
+ alloc.$O\
main.$O\
HFILES=libgeometry/geometry.h\