From a1f549f07c378aa57852e288f0405ac8af18d907 Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 24 Jan 2021 20:24:21 -0600 Subject: added a state var, and a title var. svg will now use those in its output "svg" (html) --- share/hackvr/examples/anonet_map/map | 8 +++-- src/common.h | 8 +++++ src/graphics_cs_svg.c | 14 +++++++-- src/graphics_cs_x11.c | 8 +++-- src/hackvr.c | 58 +++++++++++++----------------------- 5 files changed, 51 insertions(+), 45 deletions(-) diff --git a/share/hackvr/examples/anonet_map/map b/share/hackvr/examples/anonet_map/map index 976bb79..51a9e59 100755 --- a/share/hackvr/examples/anonet_map/map +++ b/share/hackvr/examples/anonet_map/map @@ -1,4 +1,6 @@ #!/bin/bash +echo $USER set title anonet_AS_map + paths="$(ncat --recv-only 21.41.41.1 64777 | sort | uniq | tee ${PREFIX}/var/cache/hackvr/anonet_data.new)" MAP=${PREFIX}/var/cache/hackvr/anonet_map.hackvr @@ -54,9 +56,9 @@ line_between_nodes() { } for node in $nodes;do - printf " addshape 5 4 -1 8 0 -1 10 0 1 10 0 1 8 0\n" "$node" - printf " addshape 5 4 -1 8 0 -1 10 0 1 10 0 1 8 0\n" "$node" + printf "\n"); - strcpy(svg_global.backbuffer,"\n"); + if(global.state == HVR_STATE_EXIT) {//we only want to actually print a refresh if we're not doing the last frame. + strcpy(svg_global.backbuffer,""); + strcat(svg_global.backbuffer,global.title); + strcat(svg_global.backbuffer,"\n"); + } else { + strcpy(svg_global.backbuffer,""); + strcat(svg_global.backbuffer,global.title); + strcat(svg_global.backbuffer,"\n"); + } strcat(svg_global.backbuffer,"\n"); } @@ -243,7 +251,9 @@ void set_demands_attention() { */ } -void set_title(char *t) { +void set_title(char *t) {//this might need to be put somewhere else... + if(global.title) free(global.title); + global.title=strdup(t); //XStoreName(x11_global.dpy,x11_global.w,t); } diff --git a/src/graphics_cs_x11.c b/src/graphics_cs_x11.c index 1f9774a..f2911f6 100644 --- a/src/graphics_cs_x11.c +++ b/src/graphics_cs_x11.c @@ -372,7 +372,11 @@ void x11_keypress_handler(XKeyEvent *xkey,int x,int y) { #endif void set_title(char *t) { - XStoreName(x11_global.dpy,x11_global.w,t); + if(global.title) free(global.title); + global.title=strdup(t); + if(x11_global.dpy && x11_global.w) { + XStoreName(x11_global.dpy,x11_global.w,t); + } } int graphics_sub_init() { @@ -415,8 +419,8 @@ int graphics_sub_init() { set_aspect_ratio(); XSelectInput(x11_global.dpy, x11_global.w, HV_MOUSE_X11_EVENT_MASK|HV_X11_KB_EVENT_MASK|HV_GRAPHICS_X11_EVENT_MASK); } + XStoreName(x11_global.dpy,x11_global.w,global.title); XMapWindow(x11_global.dpy,x11_global.w); - set_title("hackvr");//uses the globals to know what dpy and w x11_global.gc=XCreateGC(x11_global.dpy,x11_global.w, 0, 0); x11_global.backbuffer=XCreatePixmap(x11_global.dpy,x11_global.w,MAXWIDTH,MAXHEIGHT,DefaultDepth(x11_global.dpy,DefaultScreen(x11_global.dpy))); x11_global.cleanbackbuffer=XCreatePixmap(x11_global.dpy,x11_global.w,MAXWIDTH,MAXHEIGHT,DefaultDepth(x11_global.dpy,DefaultScreen(x11_global.dpy))); diff --git a/src/hackvr.c b/src/hackvr.c index 4eaec17..1f64004 100644 --- a/src/hackvr.c +++ b/src/hackvr.c @@ -37,6 +37,13 @@ struct hvr_global global; //TODO: will have to make some pixmaps get resized when the window does. //for now set them to be as big as you think you'll ever resize the window to. +#ifndef GRAPHICAL +void set_title(char *t) { + if(global.title) free(global.title); + global.title=strdup(t); +} +#endif + int lum_based_on_distance(c3_s_t *s) { int i; real sum=0; @@ -47,36 +54,6 @@ int lum_based_on_distance(c3_s_t *s) { return sum * 5; } - -//might be able to make this faster by just using fgets() and not using recursion and malloc. -/* does not return the newline. */ - -//this isn't being used anymore afaict. -char *read_line_hack(FILE *fp,int len) { - short in; - char *t; - errno=0; - switch(in=fgetc(fp)) { - case '\n': - t=malloc(len+1); - t[len]=0; - return t; - case -1: - if(errno == EAGAIN) return 0; - if(feof(fp)) { - fprintf(stderr,"# reached EOF. exiting.\n"); - exit(0); - } - fprintf(stderr,"# some other error happened while reading. %d %d\n",EAGAIN,errno); - perror("hackvr"); - exit(1); - default: - if((t=read_line_hack(fp,len+1))) t[len]=in; - break; - } - return t; -} - int selfcommand(char *s) {//send this line to be handled by ourselves and output to stdout if(global.localecho) { write(global.selfpipe[1],s,strlen(s)); @@ -138,17 +115,18 @@ void hackvr_handler_idc(struct shit *me,char *line) { switch(hackvr_handler(line)) { case -1://quit fprintf(stderr,"# exiting due to EOF\n"); - //we need to flush another draw before exiting probably for _svg to get one last frame in. - #ifdef GRAPHICAL - redraw(); - #endif + global.state=HVR_STATE_EXIT; + #ifdef GRAPHICAL + draw_screen(); + #endif + //close(me->fd);//this doesn't make the main loop exit. gonna have to exit(0); exit(0); case 0://don't redraw break; case 1://redraw please. - #ifdef GRAPHICAL - redraw(); - #endif + #ifdef GRAPHICAL + redraw(); + #endif break; default://no idea. break; @@ -388,8 +366,8 @@ int hackvr_handler(char *line) { if(len != 3 && len != 4) return ret; if(len == 4) { if(0); -#ifdef GRAPHICAL else if(!strcmp(a[2],"title")) set_title(a[3]);//who cares for spaces anyway? +#ifdef GRAPHICAL else if(!strcmp(a[2],"camera.p.x")) global.camera.p.x=strtold(a[3],0); else if(!strcmp(a[2],"camera.p.y")) global.camera.p.y=strtold(a[3],0); else if(!strcmp(a[2],"camera.p.z")) global.camera.p.z=strtold(a[3],0); @@ -767,7 +745,10 @@ void alarm_handler(int sig) { } int main(int argc,char *argv[]) { + global.state=HVR_STATE_INIT; global.version=HVR_VERSION; + global.title=0; + set_title("hackvr"); int i; int fd=0;//stdin if(argc == 2) { @@ -835,6 +816,7 @@ int main(int argc,char *argv[]) { //signal(SIGALRM,alarm_handler); //alarm(10); fprintf(stderr,"# entering main loop\n"); + global.state=HVR_STATE_RUN; select_on_everything(); return 0; -- cgit v1.2.3