aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepoch <epoch@enzo.thebackupbox.net>2021-01-24 20:24:21 -0600
committerepoch <epoch@enzo.thebackupbox.net>2021-01-24 20:24:21 -0600
commita1f549f07c378aa57852e288f0405ac8af18d907 (patch)
tree4ec93118940dd716866d06b44de97ce5667866ef
parent4feb44b2849b9c2779118f58991a295efb0727b9 (diff)
downloadhackvr-a1f549f07c378aa57852e288f0405ac8af18d907.tar.gz
hackvr-a1f549f07c378aa57852e288f0405ac8af18d907.zip
added a state var, and a title var. svg will now use those in its output "svg" (html)
-rwxr-xr-xshare/hackvr/examples/anonet_map/map8
-rw-r--r--src/common.h8
-rw-r--r--src/graphics_cs_svg.c14
-rw-r--r--src/graphics_cs_x11.c8
-rw-r--r--src/hackvr.c58
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 "<whois://whois.ano/AS%s> addshape 5 4 -1 8 0 -1 10 0 1 10 0 1 8 0\n" "$node"
- printf "<whois://whois.ano/AS* rotate 0 0 +%d\n" "$[360 / ${nodes_count} ]"
- printf "<whois://whois.ano/AS* flatten\n"
+ printf "<//whois.ano/AS%s> addshape 5 4 -1 8 0 -1 10 0 1 10 0 1 8 0\n" "$node"
+ printf "<//whois.ano/AS* rotate 0 0 +%d\n" "$[360 / ${nodes_count} ]"
+ printf "<//whois.ano/AS* flatten\n"
makelabel.sh AS$node $( echo | awk "{print $(xcoord_by_ASN $node) * 13}" ) $( echo | awk "{print $(ycoord_by_ASN $node) * 13}" ) -19 <<< $node
printf "AS%s scale .1 .1 .1\n" "$node"
done | tee -a $MAP
diff --git a/src/common.h b/src/common.h
index 77ad619..7d8e5ab 100644
--- a/src/common.h
+++ b/src/common.h
@@ -96,6 +96,12 @@ typedef struct c3_shape {//use array or linked list?
struct attrib attrib;
} c3_s_t;
+typedef enum hvr_state {
+ HVR_STATE_INIT,
+ HVR_STATE_RUN,
+ HVR_STATE_EXIT
+} hvr_state;
+
struct hvr_global {
int x;
int y;
@@ -115,12 +121,14 @@ struct hvr_global {
struct hashtable ht_group;
c3_group_rel_t eye[MAX_SIDES];//lol. 1000 eyes! array of group_rels for each eye. how to arrange eyes?
c3_group_rel_t camera;//should there be an array for this? camera has .s which is a shape struct. each point is the eye?
+ hvr_state state;//I dunno.
real zoom;
int derp;
real split;
char localecho;
int selfpipe[2];
char *version;
+ char *title;
};
int selfcommand(char *);
diff --git a/src/graphics_cs_svg.c b/src/graphics_cs_svg.c
index 210a1cf..65f0bc5 100644
--- a/src/graphics_cs_svg.c
+++ b/src/graphics_cs_svg.c
@@ -143,7 +143,15 @@ void draw_cs_filled_shape(cs_s_t s) {
//should I do clipping in each graphics lib or make graphics.c just have clipping stuff?
void clear_backbuffer() {
// strcpy(svg_global.backbuffer,"<?xml version=\"1.0\" standalone=\"no\">\n");
- strcpy(svg_global.backbuffer,"<html><head><meta http-equiv=\"refresh\" content=\"0\" /></head><body>\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,"<html><head><title>");
+ strcat(svg_global.backbuffer,global.title);
+ strcat(svg_global.backbuffer,"</title></head><body>\n");
+ } else {
+ strcpy(svg_global.backbuffer,"<html><head><title>");
+ strcat(svg_global.backbuffer,global.title);
+ strcat(svg_global.backbuffer,"</title><meta http-equiv=\"refresh\" content=\"0\" /></head><body>\n");
+ }
strcat(svg_global.backbuffer,"<svg width=\"1024\" height=\"768\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\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;