aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepoch <epoch@thebackupbox.net>2020-10-10 00:00:55 -0500
committerepoch <epoch@thebackupbox.net>2020-10-10 00:00:55 -0500
commitfe9ad894000ff986cd642d23ac4762e97d5b1ccc (patch)
tree1e253ac02dc7d3339b60ca68d9bfca24cbd3ef7e
parent19feecae5124e5eb4c8a2f2dfd300e94e59b9d9f (diff)
parent4982876f0d021e4637f6db500063169477fe7289 (diff)
downloadhackvr-fe9ad894000ff986cd642d23ac4762e97d5b1ccc.tar.gz
hackvr-fe9ad894000ff986cd642d23ac4762e97d5b1ccc.zip
Merge branch 'master' of ssh://batou.thebackupbox.net:65432/hackvr
-rw-r--r--.gitignore2
-rw-r--r--README68
-rwxr-xr-xbin/map2globe.py5
-rwxr-xr-xshare/hackvr/examples/marquee/marquee.sh28
-rw-r--r--share/hackvr/examples/subsume/arms.hackvr7
-rwxr-xr-xshare/hackvr/examples/subsume/test.sh11
-rw-r--r--src/Makefile28
-rw-r--r--src/graphics_c2.h5
-rw-r--r--src/graphics_c3.c38
-rw-r--r--src/graphics_c3.h3
-rw-r--r--src/graphics_cs.h3
-rw-r--r--src/graphics_cs_svg.c270
-rw-r--r--src/graphics_svg.h15
-rw-r--r--src/hackvr.c44
l---------src/hackvr_svg.c1
l---------src/hackvr_xdiewii.c1
-rw-r--r--src/keyboard_die.c6
-rw-r--r--src/math.c17
-rw-r--r--src/mouse.h11
-rw-r--r--src/mouse_die.c57
-rw-r--r--src/mouse_wii.c145
-rw-r--r--src/mouse_x11.c60
22 files changed, 712 insertions, 113 deletions
diff --git a/.gitignore b/.gitignore
index 7b6a851..5c4941d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,7 @@ src/hackvr_headless
src/hackvr_x11
src/hackvr_xdie
src/hackvr_opengl
+src/hackvr_svg
+src/hackvr_xdiewii
src/slowcat
src/nonblocktail
diff --git a/README b/README
index a3a4ff3..36ff84b 100644
--- a/README
+++ b/README
@@ -8,11 +8,14 @@ hackvr... um. outputs commands to stdout based on keys pressed inside hackvr,
and inputs the same type of commands.
so do some plumbing and get a multiplayer game going?
-I'm working on making hackvr work with different output and input types. Right now the only one
-that works with everything is hackvr_x11. There's also a hackvr_fb that uses the linux framebuffer,
-but it doesn't have mouse support and keyboard support is wonky due to me not thinging it through.
+How about a nice GL version written in zig made by someone else?
+https://git.random-projects.net/xq/hackvr-turbo
-quick start:
+I'm telling you. It looks a lot nicer than my stuff.
+
+::::::::::::::::::::
+::: DEPENDENCIES :::
+::::::::::::::::::::
You'll need to have the library and headers of libx11 installed for hackvr to build successfully.
Which usually means you will need the dev version of the libx11 (xlib) package for your distro.
@@ -24,8 +27,6 @@ If you want to build the GLut crap you'll need
freeglut3-dev
-Although I haven't touched the non-x11 versions in a long time. Good luck.
-
Since I first wrote this README, I pushed a couple other libraries I've written into hackvr.
You'll need those too.
@@ -49,18 +50,51 @@ git://thebackupbox.net/libhashtable
git://main.lv/libhashtable
https://github.com/kkabrams/libhashtable
+
+::::::::::::::::
+::: BUILDING :::
+::::::::::::::::
+
I have a script that just runs make with PREFIX=$PREFIX prefix=$PREFIX so I end up with
everything installed under ~/.local/
-
-After you have that installed you should be able to do these to get hackvr built:
+You should be able to do these to get hackvr built:
make #BSD make doesn't do target specific variables. use GNUMake.
+
+The make install will create the following programs:
+
+:: hackvr_headless ::
+This doesn't output to any display, but you can still read commands in, do manipulations
+then export them back out. This can make writing a few scripts for hackvr easier
+and it can also compress any long list of hackvr commands.
+
+:: hackvr_x11 ::
+This is the binary I use most on my desktop. It outputs to a single X11 window,
+and gets its input events from that same X11 window.
+
+:: hackvr_fb ::
+This outputs to the /dev/fb0 device so you can run hackvr without an X11 server if you want.
+It uses /dev/input/events for user input.
+
+:: hackvr_xdie ::
+This is a mix of the last two programs. It outputs to an X11 window, but uses
+/dev/input/events for user input.
+
+:: hackvr_svg ::
+This uses /dev/input/events for user input, and each screen-draw it overwrites an HTML file
+in /tmp that contains an inline SVG with an autorefresh. I think this program was meant
+as a joke to myself. Still kind of funny.
+
+:::::::::::::::
+::: INSTALL :::
+:::::::::::::::
+
+The way I install updated hackvr binaries is this way:
+
export PREFIX=$(HOME)/.local #the Makefiles are short, worth a read.
make install
-The make install will create hackvr_headless, hackvr_x11, hackvr_fb.
-
If you didn't want to make install the libraries, there are variables you can set to
let the makefile know where they are:
@@ -76,17 +110,11 @@ A few helper scripts are written in perl and python.
So you might want to install perl and python if you want to play with them.
They're pretty nifty.
-what hackvr can do...
-
-I dunno.
-
-try cd tictactoe ; ./run
-or... fiddle with the scripts laying around?
-_ _
- \O_o/
-
+:::::::::::::::::::
+::: Stereoscopy :::
+:::::::::::::::::::
-Red and Blue mode
+Right now there's side-by-side mode and red-and-blue mode.
You'll have to either enable this using a command sent to hackvr's stdin that
I don't even remember, or just enable it in config.h make clean then rebuild.
diff --git a/bin/map2globe.py b/bin/map2globe.py
index cb49675..1a50ea5 100755
--- a/bin/map2globe.py
+++ b/bin/map2globe.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3.6
+#!/usr/bin/python3
import sys
import math
@@ -49,9 +49,6 @@ while(1):
break
if(lat and lon and x and y and z and plat and plon and px and py and pz): #if the previouses exist
print("{} addshape 2 2 {} {} {} {} {} {}".format(name,x,y,z,px,py,pz))
- print("{} rotate 0 {} 0".format(name,str(rotation)))
- rotation+=1
- rotation%=360
#set previouses to currents
(plat,plon,px,py,pz)=(lat,lon,x,y,z)
diff --git a/share/hackvr/examples/marquee/marquee.sh b/share/hackvr/examples/marquee/marquee.sh
new file mode 100755
index 0000000..4ea6c61
--- /dev/null
+++ b/share/hackvr/examples/marquee/marquee.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -o pipefail
+
+pi=3 #lol
+
+from_cam=150
+
+elevation=10
+while printf "marquee rotate 0 +-2 0\n";do
+ sleep .1
+done &
+
+tail -F ~/.local/var/cache/music/nowplaying.txt 2>/dev/null | while read -r line;do
+ printf "%s deleteallexcept %s\n" "$USER" "$USER"
+ printf "nowplaying flatten\n"
+ printf "%s\n" "$line" >&2
+ chars="$(printf "%s" "$line" | wc -c | tr -cd '[0-9]')"
+ char_width=5 #I think..
+ rot=$[ 360 / $chars ]
+ diameter=$[ $chars * $char_width / $pi ]
+ printf "%s\n" "$line" | fold -w1 | while read -r char;do
+ printf "%s\n" "$char" | makelabel.sh nowplaying 0 0 0 | offsetshape.sh 0 0 "-${diameter}"
+ printf "nowplaying rotate 0 %d 0\n" "-$rot"
+ printf "nowplaying flatten\n"
+ done
+ printf "marquee assimilate nowplaying\n"
+ printf "marquee move 0 %s %s\n" "$elevation" "$[$diameter + $from_cam]" #this won't work before the generation loop unless I can flatten on certain parts.
+done
diff --git a/share/hackvr/examples/subsume/arms.hackvr b/share/hackvr/examples/subsume/arms.hackvr
new file mode 100644
index 0000000..de31aba
--- /dev/null
+++ b/share/hackvr/examples/subsume/arms.hackvr
@@ -0,0 +1,7 @@
+base addshape 1 2 0 0 0 0 8 0
+mid addshape 2 2 0 0 0 0 4 0
+mid move 0 8 0
+base subsume mid
+end addshape 4 2 0 0 0 0 2 0
+end move 0 4 0
+mid subsume end
diff --git a/share/hackvr/examples/subsume/test.sh b/share/hackvr/examples/subsume/test.sh
new file mode 100755
index 0000000..67139ac
--- /dev/null
+++ b/share/hackvr/examples/subsume/test.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+cat arms.hackvr
+
+# these start all straight-up, rotate counter clockwise as rotation increases, and
+# at these rates of rotation they should all be curled in on themselves at the bottom.
+while true;do
+ printf "base rotate 0 0 +1\n"
+ printf "mid rotate 0 0 +2\n"
+ printf "end rotate 0 0 +3\n"
+ sleep .1
+done
diff --git a/src/Makefile b/src/Makefile
index 398aaa8..6187723 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -11,15 +11,18 @@ LIBHASHTABLE_INCLUDE_PATH:=$(PREFIX)/include
BASE_CFLAGS=-g -Wall -pedantic -std=c99 -ffast-math -I$(PREFIX)/include -I$(LIBIDC_INCLUDE_PATH) -I$(LIBHASHTABLE_INCLUDE_PATH)
-CFLAGS+=$(BASE_CFLAGS)
-CFLAGS+=-DGRAPHICAL
+override CFLAGS+=$(BASE_CFLAGS)
+override CFLAGS+=-DGRAPHICAL
-LDFLAGS+=-L$(PREFIX)/lib -L$(LIBIDC_LIB_PATH) -L$(LIBHASHTABLE_LIB_PATH)
+override LDFLAGS+=-L$(PREFIX)/lib -L$(LIBIDC_LIB_PATH) -L$(LIBHASHTABLE_LIB_PATH)
#all: hackvr_headless hackvr_x11 hackvr_opengl slowcat ### when hackvr_opengl gets useful at all I'll start including it in default build.
-all: hackvr_fb hackvr_xdie hackvr_headless hackvr_x11 slowcat nonblocktail
+all: hackvr_svg hackvr_fb hackvr_xdie hackvr_headless hackvr_x11 slowcat nonblocktail hackvr_xdiewii
# hackvr_fb hackvr_freeglut slowcat
+hackvr_xdiewii: override LDLIBS+=-lm -lidc -lX11 -lhashtable
+hackvr_xdiewii: hackvr_xdiewii.o graphics_c3.o graphics_c2.o graphics_cs_x11.o math.o physics.o keyboard.o mouse_wii.o keyboard_x11.o
+
hackvr_xdie: override LDLIBS+=-lm -lidc -lX11 -lhashtable
hackvr_xdie: hackvr_xdie.o graphics_c3.o graphics_c2.o graphics_cs_x11.o math.o physics.o keyboard.o mouse_die.o keyboard_die.o
@@ -32,6 +35,9 @@ hackvr_headless: hackvr_headless.o math.o physics.o
hackvr_x11: override LDLIBS+=-lm -lidc -lX11 -lhashtable
hackvr_x11: hackvr_x11.o graphics_c3.o graphics_c2.o graphics_cs_x11.o math.o physics.o keyboard.o mouse_x11.o keyboard_x11.o
+hackvr_svg: override LDLIBS+=-lm -lidc -lhashtable
+hackvr_svg: hackvr_svg.o graphics_c3.o graphics_c2.o graphics_cs_svg.o math.o physics.o keyboard.o keyboard_die.o mouse_die.o
+
#notice how all the targets have generic graphics objects up until a specific one.
hackvr_fb: override LDLIBS+=-lm -lidc -lhashtable
@@ -43,11 +49,13 @@ hackvr_opengl: hackvr_opengl.o graphics_c3.o graphics_c2_opengl.o graphics_cs_op
hackvr_freeglut: override LDLIBS+=-lm -lidc -lGL -lGLU -lglut -lhashtable
hackvr_freeglut: hackvr_freeglut.o graphics_c3_freeglut.o math.o physics.o keyboard.o mouse_die.o keyboard_die.o
-hackvr_fb.o: CFLAGS+='-DHVR_VERSION="framebuffer"'
-hackvr_x11.o: CFLAGS+='-DHVR_VERSION="x11"'
-hackvr_xdie.o: CFLAGS+='-DHVR_VERSION="x11+die"'
-hackvr_headless.o: CFLAGS=$(BASE_CFLAGS)
-hackvr_headless.o: CFLAGS+='-DHVR_VERSION="headless"'
+hackvr_fb.o: override CFLAGS+='-DHVR_VERSION="framebuffer"'
+hackvr_x11.o: override CFLAGS+='-DHVR_VERSION="x11"'
+hackvr_xdie.o: override CFLAGS+='-DHVR_VERSION="x11+die"'
+hackvr_xdiewii.o: override CFLAGS+='-DHVR_VERSION="x11+kdie+wii"'
+hackvr_svg.o: override CFLAGS+='-DHVR_VERSION="svg"'
+hackvr_headless.o: override CFLAGS=$(BASE_CFLAGS)
+hackvr_headless.o: override CFLAGS+='-DHVR_VERSION="headless"'
install: all
mkdir -p $(PREFIX)/bin
@@ -57,6 +65,8 @@ install: all
install -t $(PREFIX)/bin nonblocktail
install -t $(PREFIX)/bin hackvr_xdie
install -t $(PREFIX)/bin hackvr_fb
+ install -t $(PREFIX)/bin hackvr_svg
+ install -t $(PREFIX)/bin hackvr_xdiewii
# install -t $(PREFIX)/bin hackvr_freeglut
uninstall:
diff --git a/src/graphics_c2.h b/src/graphics_c2.h
index 35920fd..8a481d9 100644
--- a/src/graphics_c2.h
+++ b/src/graphics_c2.h
@@ -3,6 +3,11 @@
#include "math.h"
+#define TOP 240.0
+#define BOTTOM -240.0
+#define RIGHT 320.0
+#define LEFT -320.0
+
int c2sX(real x);
int s2cX(real x);
int c2sY(real y);
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index eb63909..72a03e3 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -10,6 +10,7 @@
#include "config.h"
#include "common.h"
+#include "mouse.h"
//#include "graphics_cs.h" //this header includes all the functions you'll need to implement if you want to port hackvr to something else
#include "graphics_c3.h"//we're defining these functions in this file.
@@ -28,14 +29,6 @@ struct gra_global gra_global;
#ifdef GRAPHICAL
-//used to figure out what c2 values are associated with each edge of the window.
-//#define TOP 160.0
-//#define BOTTOM -160.0
-#define TOP 240.0
-#define BOTTOM -240.0
-#define RIGHT 320.0
-#define LEFT -320.0
-
/*
real distance2(c2_t p1,c2_t p2) {
return sqrt(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) ));
@@ -127,6 +120,7 @@ c3_t c3_subtract(c3_t p1,c3_t p2) {
//how is this supposed to work? x is distance?
#define MAGIC(x) (1.0l-(1.0l/pow(1.01l,(x)))) //??? might want to have some changables in here
+//#define MAGIC(x) (1.0l-(1.0l/pow(1.0001l,(x))))
//#define MAGIC(x) (-250.0l / x )
#define TOO_CLOSE (.25l)
@@ -153,12 +147,13 @@ c2_t c3_to_c2(c3_group_rel_t eye,c3_t p3) { //DO NOT DRAW STUFF IN HERE
real delta_x=(eye.p.x - final.x);//I guess X needs this flippage too.
real delta_y=(eye.p.y - final.y);//I dunno. Y is weird.
real delta_z=(final.z - eye.p.z);
- //real d=distance3(global.camera.p,final);
+ //real d=distance3(eye.p,final);
+
p2.x=global.zoom * (delta_x * MAGIC(delta_z) - delta_x);
p2.y=global.zoom * (delta_y * MAGIC(delta_z) - delta_y);//this doesn't look right either.
- // p2.x=global.zoom * (delta_x * MAGIC(d) - delta_x); // this doesn't look quite right
-// p2.y=global.zoom * (delta_y * MAGIC(d) - delta_y);//dunno if this is better or not.
+ //p2.x=2 * (d * MAGIC(d) - delta_x); // this doesn't look quite right
+ //p2.y=2 * (d * MAGIC(d) - delta_y); // dunno if this is better or not.
return p2;
}
@@ -421,9 +416,13 @@ void draw_screen() {
//draw_sky();//???p?
//XCopyArea(global.dpy,skypixmap,global.backbuffer,global.backgc,((camera.yr*5)+SKYW)%SKYW,0,WIDTH,global.height/2,0,0);
}
- if(gra_global.draw3d) {//wtf? why do I not compensate for camaera rotation along the x and z?
- //draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0}); //horizon
- }
+ //if(gra_global.draw3d) {//wtf? why do I not compensate for camaera rotation along the x and z?
+ //horizon line
+ draw_c2_line((c2_t){LEFT,
+ (int)((real)(global.camera.r.x.d) * (real)(BOTTOM+BOTTOM) / (real)90.0)},
+ (c2_t){RIGHT,
+ (int)((real)(global.camera.r.x.d) * (real)(BOTTOM+BOTTOM) / (real)90.0)});
+ //}
///// shiiiit. I should be applying group rotations to all these shapes before sorting them.
//when I do that. I need to make sure to take the group rotation out of draw_c3_shape()'s code.
for(i=0;global.shape[i];i++) {
@@ -458,9 +457,9 @@ void draw_screen() {
//}
}
//we check here to see if the mouse button is still down
- if(gra_global.mousemap[0]==-1) {
+ if(gra_global.mousemap[MOUSE_PRIMARY]==-1) {//0 in x11
printf("%s action %f %f\n",global.user,gra_global.mouse.x,gra_global.mouse.y);
- gra_global.mousemap[0]=0;
+ gra_global.mousemap[MOUSE_PRIMARY]=0;
}
/*
if(gra_global.drawminimap == 1) {
@@ -515,9 +514,10 @@ void draw_screen() {
}
void redraw() {//something is requesting a redraw.
- if(gra_global.force_redraw == 0) {
- gra_global.force_redraw=1;//this is to prevent drawing way too often.
- write(gra_global.redraw[1],"redraw plzkthx!\n",16);
+ if(gra_global.redrawplzkthx == 0) {
+ gra_global.redrawplzkthx=1;//this is to prevent drawing way too often.
+ //fprintf(stderr,"# in the redraw() function\n");
+ write(gra_global.redraw[1],"redrawplzkthx!\n",15);
}
}
diff --git a/src/graphics_c3.h b/src/graphics_c3.h
index ce3354c..36b7c6b 100644
--- a/src/graphics_c3.h
+++ b/src/graphics_c3.h
@@ -13,7 +13,8 @@ struct gra_global {
int split_screen;
real split;
int split_flip;
- char force_redraw;
+ char force_redraw;//this should be to make it draw as often as possible
+ char redrawplzkthx;//this is just a flag that redraw() sets, so if multiple draws are asked for, it can clear all of them at once instead of queueing them
char red_and_blue;
unsigned int depth;//???
unsigned int border_width;
diff --git a/src/graphics_cs.h b/src/graphics_cs.h
index a16f03f..1abba31 100644
--- a/src/graphics_cs.h
+++ b/src/graphics_cs.h
@@ -4,9 +4,6 @@
#include "math.h"
#include <idc.h>
-//these are just the functions that all backends need to implement to work with hackvr.
-//the list of functions are subject to change.
-
void draw_cs_line(cs_t p1,cs_t p2);
void draw_cs_text(cs_t p,char *text);
void draw_cs_shape(cs_s_t s);
diff --git a/src/graphics_cs_svg.c b/src/graphics_cs_svg.c
new file mode 100644
index 0000000..305ad39
--- /dev/null
+++ b/src/graphics_cs_svg.c
@@ -0,0 +1,270 @@
+#define _POSIX_C_SOURCE 200809L //for fileno and strdup
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <stdlib.h>
+//#include <sys/select.h> //code to use select instead of non-blocking is commented out. might decide to use it later.
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/cursorfont.h>
+#include <X11/Xutil.h> //for size hints
+#include <time.h>
+
+#include "config.h"
+#include "math.h"
+#include "common.h"
+#include "graphics_c3.h"//not needed?
+#include "graphics_svg.h"
+#include "graphics_c2.h"
+#include "graphics_cs.h"
+
+//typedef float real; //think this conflicts?
+
+//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.
+
+//#define SKYRULE 90
+//#define SKYW (WIDTH*5)
+//#define SKYH (HEIGHT/2)
+
+//Pixmap skypixmap;
+//char sky[SKYH][SKYW];
+
+extern struct hvr_global global;
+extern struct gra_global gra_global;
+struct svg_global svg_global;
+
+#ifdef GRAPHICAL
+
+void set_luminosity_color(int lum) {
+ svg_global.foreground_color=svg_global.colors[lum%100];
+}
+
+
+void draw_cs_line(cs_t p1,cs_t p2) {
+ char tmp[1024];
+ snprintf(tmp,sizeof(tmp)-1,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke=\"%s\" />\n"
+ ,p1.x ,p1.y ,p2.x ,p2.y ,svg_global.foreground_color);
+ strcat(svg_global.backbuffer,tmp);
+}
+
+void draw_cs_text(cs_t p,char *text) {//lol. I don't even use this anymore.
+/* char t[256];
+ int direction,ascent,descent;
+ XFontStruct *font=XLoadQueryFont(x11_global.dpy,"fixed");
+ XCharStruct overall;
+ snprintf(t,sizeof(t)-1,"%s",text);
+ XTextExtents(font,text,strlen(text),&direction,&ascent,&descent,&overall);
+ XDrawString(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p.x,p.y+(descent+ascent),text,strlen(text));
+*/
+}
+
+void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it could be moved up to graphics.c? probl no.
+ char tmp[1024];
+ //cs_t smouse=c2_to_cs(gra_global.mouse);
+ int i;//all cs shapes can have 1, 2, or 3+ points. guess I gotta do that logic here too.
+ switch(s.len) {
+ case 1:
+ break;
+ default:
+ strcat(svg_global.backbuffer,"<polygon points=\"");
+ for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
+ snprintf(tmp,sizeof(tmp)-1,"%d,%d",s.p[i].x,s.p[i].y);
+ strcat(svg_global.backbuffer,tmp);
+ if(i != s.len-1) strcat(svg_global.backbuffer," ");//only print space after points that have a point after them.
+ }
+ snprintf(tmp,sizeof(tmp)-1,"\" fill=\"dark%s\" stroke=\"%s\" />\n",svg_global.foreground_color,svg_global.foreground_color);
+ strcat(svg_global.backbuffer,tmp);
+ break;
+ }
+}
+
+void draw_cs_filled_shape(cs_s_t s) {
+ int i;
+ char tmp[1024];
+ switch(s.len) {
+ case 1:
+ break;
+ default:
+ strcat(svg_global.backbuffer,"<polygon points=\"");
+ for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
+ snprintf(tmp,sizeof(tmp)-1,"%d,%d",s.p[i].x,s.p[i].y);
+ strcat(svg_global.backbuffer,tmp);
+ if(i != s.len-1) strcat(svg_global.backbuffer," ");//only print space after points that have a point after them.
+ }
+ snprintf(tmp,sizeof(tmp)-1,"\" fill=\"%s\" stroke=\"%s\" />\n",svg_global.foreground_color,svg_global.foreground_color);
+ strcat(svg_global.backbuffer,tmp);
+ break;
+ }
+}
+
+//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");
+ strcat(svg_global.backbuffer,"<svg width=\"1024\" height=\"768\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n");
+}
+
+void set_clipping_rectangle(int x,int y,int width,int height) {
+/*
+ XRectangle cliprect;
+ cliprect.x=0;
+ cliprect.y=0;
+ cliprect.width=width;
+ cliprect.height=height;
+ XSetClipRectangles(x11_global.dpy,x11_global.backgc,x,y,&cliprect,1,Unsorted);
+*/
+}
+
+void draw_mode_copy() {
+/*
+ XGCValues gcval;
+ gcval.function=GXcopy;
+ XChangeGC(x11_global.dpy,x11_global.backgc,GCFunction,&gcval);
+*/
+}
+
+void draw_mode_and() {
+/*
+ XGCValues gcval;
+ gcval.function=GXand;
+ XChangeGC(x11_global.dpy,x11_global.backgc,GCFunction,&gcval);
+*/
+}
+
+void draw_mode_or() {
+/*
+ XGCValues gcval;
+ gcval.function=GXor;
+ XChangeGC(x11_global.dpy,x11_global.backgc,GCFunction,&gcval);
+*/
+}
+
+void red_and_blue_magic() {
+ //draw_mode_or();
+}
+
+//void draw_sky() {
+// XCopyArea(x11_global.dpy,skypixmap,x11_global.backbuffer,x11_global.backgc,((global.camera.yr.d*5)+SKYW)%SKYW,0,WIDTH,gra_global.height/2,0,0);
+//}
+
+void set_color_snow() {
+ //x11_global.snow=1;//override foreground color in the draw functions. drawing different grey each time.
+}
+
+void set_ansi_color(int i) {
+ svg_global.foreground_color=svg_global.ansi_color[i];
+}
+
+void set_color() {
+ svg_global.foreground_color=svg_global.green;
+}
+
+void set_color_red() {
+ svg_global.foreground_color=svg_global.red;
+}
+
+void set_color_blue() {
+ svg_global.foreground_color=svg_global.blue;
+}
+
+void flipscreen() {
+ fprintf(stderr,"# flipping screen!\n");
+// strcat(svg_global.backbuffer,"</svg>\n</xml>\n");
+ strcat(svg_global.backbuffer,"</svg></body></html>\n");
+ int fd=open(svg_global.filename,O_TRUNC|O_WRONLY|O_CREAT);
+ write(fd,svg_global.backbuffer,strlen(svg_global.backbuffer));
+ close(fd);
+}
+
+void set_aspect_ratio() {
+/*
+ XSizeHints *hints=XAllocSizeHints();
+ hints->min_aspect.x=AR_W*(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1));
+ hints->min_aspect.y=AR_H;
+ hints->max_aspect.x=AR_W*(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1));
+ hints->max_aspect.y=AR_H;
+ hints->flags |= PAspect;
+ XSetWMNormalHints(x11_global.dpy,x11_global.w,hints);
+ XFree(hints);
+*/
+}
+
+void set_demands_attention() {
+/*
+ XWMHints *hints=XGetWMHints(x11_global.dpy,x11_global.w);
+ if(!hints) hints=XAllocWMHints();
+ hints->flags |= XUrgencyHint;
+ XSetWMHints(x11_global.dpy,x11_global.w,hints);
+ XFree(hints);
+*/
+}
+
+void set_title(char *t) {
+ //XStoreName(x11_global.dpy,x11_global.w,t);
+}
+
+int graphics_sub_init() {//this returns an fd we need to keep an eye one? :/
+ svg_global.filename="/tmp/hackvr.html";
+ svg_global.ansi_color[0]="black";
+ svg_global.ansi_color[1]="blue";
+ svg_global.ansi_color[2]="green";
+ svg_global.ansi_color[3]="cyan";
+ svg_global.ansi_color[4]="red";
+ svg_global.ansi_color[5]="magenta";
+ svg_global.ansi_color[6]="yellow";
+ svg_global.ansi_color[7]="white";
+ svg_global.ansi_color[8]=0;
+/* x11_global.fd=ConnectionNumber(x11_global.dpy);//we need to to pass to libidc
+ x11_global.color_map=DefaultColormap(x11_global.dpy, DefaultScreen(x11_global.dpy));
+ fprintf(stderr,"# generating colors...\n");
+ for(i=0;ansi_color[i];i++) {
+ XAllocNamedColor(x11_global.dpy,x11_global.color_map,ansi_color[i],&x11_global.ansi_color[i],&x11_global.ansi_color[i]);
+ }
+ for(i=0;i<=100;i++) {
+ snprintf(tmp,sizeof(tmp),"gray%d",i);
+ XAllocNamedColor(x11_global.dpy,x11_global.color_map,tmp,&x11_global.colors[i],&x11_global.colors[i]);
+ }
+ fprintf(stderr,"# done.\n");
+ assert(x11_global.dpy);
+ x11_global.root_window=0;
+ //global.colors[0]=BlackPixel(x11_global.dpy,DefaultScreen(x11_global.dpy));
+// int whiteColor = //WhitePixel(x11_global.dpy, DefaultScreen(x11_global.dpy));
+ attributes.background_pixel=x11_global.colors[0].pixel;
+ if(x11_global.root_window) {
+ x11_global.w = DefaultRootWindow(x11_global.dpy); //this is still buggy.
+ } else {
+ fprintf(stderr,"# creating window...\n");
+ x11_global.w = XCreateWindow(x11_global.dpy,DefaultRootWindow(x11_global.dpy),0,0,WIDTH*(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1)),HEIGHT,1,DefaultDepth(x11_global.dpy,DefaultScreen(x11_global.dpy)),InputOutput,DefaultVisual(x11_global.dpy,DefaultScreen(x11_global.dpy))\
+ ,CWBackPixel, &attributes);
+ fprintf(stderr,"# done. window id: %ld\n",x11_global.w);
+ 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);
+ }
+ 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)));
+
+//backbuffer is uninitialized
+ x11_global.backgc=XCreateGC(x11_global.dpy,x11_global.backbuffer,0,0);
+
+ cursor=XCreateFontCursor(x11_global.dpy,XC_crosshair);
+ XDefineCursor(x11_global.dpy, x11_global.w, cursor);
+*/
+ svg_global.green="green";
+ svg_global.red="red";
+ svg_global.blue="blue";
+
+ return -1;//what do we return in svg's case?
+}
+
+void graphics_event_handler(struct shit *me,char *line) {//line should always be empty
+ redraw();
+}
+
+#endif
diff --git a/src/graphics_svg.h b/src/graphics_svg.h
new file mode 100644
index 0000000..3ad1cae
--- /dev/null
+++ b/src/graphics_svg.h
@@ -0,0 +1,15 @@
+#ifndef _HACKVR_GRAPHICS_SVG_H_
+#define _HACKVR_GRAPHICS_SVG_H_
+
+struct svg_global {//stores global variables for the x11 *specific* shit.
+ char backbuffer[1024 * 1024 * 1024];//1 meg should be fine?
+ char *colors[256];
+ char *ansi_color[16];
+ char *foreground_color;
+ char *filename;
+ char *red;
+ char *green;
+ char *blue;
+};
+
+#endif
diff --git a/src/hackvr.c b/src/hackvr.c
index b789dbe..1a72896 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L //for fileno and strdup
+#include <ctype.h> //isspace
#include <stdio.h>
#include <fcntl.h>
#include <assert.h>
@@ -92,21 +93,21 @@ char **line_splitter(char *line,int *rlen) {
char **a;
int len,i=0;
len=1;//we're just counting how much we'll need the first loop through.
- for(i=0;line[i] && line[i] == ' ';i++);//skip leading space
+ for(i=0;line[i] && isspace(line[i]);i++);//skip leading space
for(;line[i];len++) {
- for(;line[i] && line[i] != ' ';i++);//skip rest of data
- for(;line[i] && line[i] == ' ';i++);//skip rest of space
+ for(;line[i] && !isspace(line[i]);i++);//skip rest of data
+ for(;line[i] && isspace(line[i]);i++);//skip rest of space
}
a=malloc(sizeof(char *) * len+1);
a[len]=0;
len=0;//reuse!
- for(i=0;line[i] && line[i] == ' ';i++);//skip leading space
+ for(i=0;line[i] && isspace(line[i]);i++);//skip leading space
a[len]=line+i;
for(;;) {
- for(;line[i] && line[i] != ' ';i++);//skip rest of data
+ for(;line[i] && !isspace(line[i]);i++);//skip rest of data
if(!line[i]) break;
line[i++]=0;
- for(;line[i] && line[i] == ' ';i++);//skip rest of space
+ for(;line[i] && isspace(line[i]);i++);//skip rest of space
if(!line[i]) break;
a[++len]=line+i;
}
@@ -133,6 +134,7 @@ void hvr_version() {
int hackvr_handler(char *line);
void hackvr_handler_idc(struct shit *me,char *line) {
+ //fprintf(stderr,"# got a hackvr line.\n");
switch(hackvr_handler(line)) {
case -1://quit
fprintf(stderr,"# exiting due to EOF\n");
@@ -155,7 +157,7 @@ int hackvr_handler(char *line) {
int len;
int j,i,k,l;
unsigned int key_count;
- c3_group_rel_t *gr;
+ c3_group_rel_t *gr,*pgr;
real tmpx,tmpy,tmpz;
char **a;
char **keys;
@@ -418,7 +420,7 @@ int hackvr_handler(char *line) {
#endif
return ret;
}
- fprintf(stderr,"# %s toggled!\n",a[2]);
+ fprintf(stderr,"# %s toggled.\n",a[2]);
ret=1;
return ret;
}
@@ -446,8 +448,21 @@ int hackvr_handler(char *line) {
/* ---------- */
if(helping) fprintf(stderr,"# subsume child-group\n");
if(!strcmp(command,"subsume")) {
- gr=get_group_relative(a[2]);//we need the child's group relative...
- gr->parent = gr->id;
+ if(strchr(a[2],'*')) {
+ for(i=0;i < global.ht_group.kl;i++) {
+ for(m=global.ht_group.bucket[global.ht_group.keys[i]]->ll;m;m=m->next) {
+ if(!glob_match(id,m->original)) {
+ gr=m->target;
+ pgr=get_group_relative(id);
+ gr->parent = pgr->id;
+ }
+ }
+ }
+ } else {
+ gr=get_group_relative(a[2]);//we need the child's group relative...
+ pgr=get_group_relative(id);
+ gr->parent = pgr->id;
+ }
ret=0;
return ret;
}
@@ -730,9 +745,14 @@ int export_file(FILE *fp) {//not used yet. maybe export in obj optionally? no. t
#ifdef GRAPHICAL
void redraw_handler(struct shit *me,char *line) {//how do we strip out extra redraws?
- if(gra_global.force_redraw) {
+ //fprintf(stderr,"# attempting to redraw\n");
+ if(gra_global.redrawplzkthx) {//this is how multiple calls to redraw() don't cause a flood of draw_screen();
draw_screen();
- gra_global.force_redraw=0;
+ gra_global.redrawplzkthx=0;
+ if(gra_global.force_redraw == 1) {
+ fprintf(stderr,"# warning. force redrawing.\n");
+ redraw();//wew.
+ }
}
}
#endif
diff --git a/src/hackvr_svg.c b/src/hackvr_svg.c
new file mode 120000
index 0000000..e4c9ddd
--- /dev/null
+++ b/src/hackvr_svg.c
@@ -0,0 +1 @@
+hackvr.c \ No newline at end of file
diff --git a/src/hackvr_xdiewii.c b/src/hackvr_xdiewii.c
new file mode 120000
index 0000000..e4c9ddd
--- /dev/null
+++ b/src/hackvr_xdiewii.c
@@ -0,0 +1 @@
+hackvr.c \ No newline at end of file
diff --git a/src/keyboard_die.c b/src/keyboard_die.c
index 5a52879..dd172b9 100644
--- a/src/keyboard_die.c
+++ b/src/keyboard_die.c
@@ -3,11 +3,13 @@
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdlib.h> //getenv()
#include "keyboard.h"
-//#define KBDEV "/dev/input/event0"
-#define KBDEV "/dev/input/by-path/platform-i8042-serio-0-event-kbd"
+//#define KBDEV "/dev/input/by-path/pci-0000:00:02.0-usb-0:2.1:1.0-event-kbd"
+//#define KBDEV "/dev/input/event3"
+#define KBDEV getenv("HVR_KBDEV")
int kbfd = -1;
diff --git a/src/math.c b/src/math.c
index 2221957..0f48dd3