summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile39
-rw-r--r--src/graphics_c3.c11
-rw-r--r--src/graphics_c3.h1
-rw-r--r--src/graphics_cs_fb.c232
-rw-r--r--src/graphics_fb.h5
-rwxr-xr-xsrc/hackvr9
-rw-r--r--src/hackvr.c29
l---------src/hackvr_xdie.c1
-rw-r--r--src/input.c19
-rw-r--r--src/input.h14
-rw-r--r--src/keyboard.c2
-rw-r--r--src/keyboard_die.c22
-rw-r--r--src/math.c5
-rw-r--r--src/math.h1
-rw-r--r--src/mouse_die.c55
-rw-r--r--src/mouse_x11.c3
16 files changed, 157 insertions, 291 deletions
diff --git a/src/Makefile b/src/Makefile
index 5c83e45..5803a1a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@
PREFIX:=/usr/local/
-BASE_CFLAGS=-Wall -pedantic -std=c99 -ffast-math -I$(PREFIX)/include
+BASE_CFLAGS=-g -Wall -pedantic -std=c99 -ffast-math -I$(PREFIX)/include
CFLAGS+=$(BASE_CFLAGS)
CFLAGS+=-DGRAPHICAL
@@ -10,9 +10,12 @@ CFLAGS+=-DGRAPHICAL
LDFLAGS+=-L$(PREFIX)/lib
#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_headless hackvr_x11 slowcat nonblocktail
+all: hackvr_fb hackvr_xdie hackvr_headless hackvr_x11 slowcat nonblocktail
# hackvr_fb hackvr_freeglut slowcat
+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
+
nonblocktail: override LDLIBS+=-lidc
nonblocktail: nonblocktail.c
@@ -20,7 +23,8 @@ hackvr_headless: override LDLIBS+=-lm -lidc -lhashtable
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 input.o
+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
+
#notice how all the targets have generic graphics objects up until a specific one.
hackvr_fb: override LDLIBS+=-lm -lidc -lhashtable
@@ -34,33 +38,40 @@ hackvr_freeglut: hackvr_freeglut.o graphics_c3_freeglut.o math.o physics.o keybo
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"'
install: all
mkdir -p $(PREFIX)/bin
- install hackvr $(PREFIX)/bin/hackvr
- install hackvr_headless $(PREFIX)/bin/hackvr_headless
- install hackvr_x11 $(PREFIX)/bin/hackvr_x11
- install slowcat $(PREFIX)/bin/slowcat
- install nonblocktail $(PREFIX)/bin/nonblocktail
-# install hackvr_fb $(PREFIX)/bin/hackvr_fb
-# install hackvr_freeglut $(PREFIX)/bin/hackvr_freeglut
+ install -t $(PREFIX)/bin hackvr_headless
+ install -t $(PREFIX)/bin hackvr_x11
+ install -t $(PREFIX)/bin slowcat
+ install -t $(PREFIX)/bin nonblocktail
+ install -t $(PREFIX)/bin hackvr_xdie
+ install -t $(PREFIX)/bin hackvr_fb
+# install -t $(PREFIX)/bin hackvr_freeglut
uninstall:
rm $(PREFIX)/bin/hackvr
rm $(PREFIX)/bin/hackvr_headless
rm $(PREFIX)/bin/hackvr_x11
- rm $(PREFIX)/bin/hackvr_fb
rm $(PREFIX)/bin/slowcat
+ rm $(PREFIX)/bin/nonblocktail
+ rm $(PREFIX)/bin/hackvr_xdie
+ rm $(PREFIX)/bin/hackvr_fb
+# rm $(PREFIX)/bin/hackvr_freeglut
clean:
- rm -f hackvr_freeglut
+# do *not* rm hackvr. it is a script which doesn't actually belong in this dir so...
rm -f hackvr_headless
- rm -f hackvr_opengl
rm -f hackvr_x11
- rm -f hackvr_fb
rm -f slowcat
+ rm -f nonblocktail
+ rm -f hackvr_xdie
+# rm -f hackvr_opengl
+ rm -f hackvr_fb
+# rm -f hackvr_freeglut
rm -f *.o
status:
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index 98c2c25..2af58d7 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -483,11 +483,16 @@ void draw_screen() {
//this should be minimap shit
//draw a line from the center to 80 away from the center in the angle of what should point at the mouse.
- /*draw_c2_line((c2_t){0,0},gra_global.mouse);
+ //draw_c2_line((c2_t){0,0},gra_global.mouse);
+ set_color();
+ draw_c2_line(c2_add(gra_global.mouse,(c2_t){0,1}) , c2_add(gra_global.mouse,(c2_t){0,5}) );
+ draw_c2_line(c2_add(gra_global.mouse,(c2_t){0,-1}) , c2_add(gra_global.mouse,(c2_t){0,-5}) );
+ draw_c2_line(c2_add(gra_global.mouse,(c2_t){1,0}) , c2_add(gra_global.mouse,(c2_t){5,0}) );
+ draw_c2_line(c2_add(gra_global.mouse,(c2_t){-1,0}) , c2_add(gra_global.mouse,(c2_t){-5,0}) );
set_color();
//if(points_on_same_side_of_line(gra_global.mouse,(c2_t){80,80},(c2_t){0,0},(c2_t){0,80})) {
- draw_c2_line((c2_t){0,0},rotate_c2((c2_t){80,0},(c2_t){0,0},points_to_angle((c2_t){0,0},gra_global.mouse)));
- //}*/
+ //draw_c2_line((c2_t){0,0},rotate_c2((c2_t){80,0},(c2_t){0,0},points_to_angle((c2_t){0,0},gra_global.mouse)));
+ //}
flipscreen();
}
diff --git a/src/graphics_c3.h b/src/graphics_c3.h
index 3f9fb78..7ea5c74 100644
--- a/src/graphics_c3.h
+++ b/src/graphics_c3.h
@@ -2,6 +2,7 @@
#define _HACKVR_GRAPHICS_H_
#include <idc.h>
+#include "common.h"
struct gra_global {
unsigned int width;
diff --git a/src/graphics_cs_fb.c b/src/graphics_cs_fb.c
index b566302..d8bb133 100644
--- a/src/graphics_cs_fb.c
+++ b/src/graphics_cs_fb.c
@@ -30,7 +30,7 @@
//Pixmap skypixmap;
//char sky[SKYH][SKYW];
-extern struct global global;
+extern struct hvr_global global;
extern struct gra_global gra_global;
struct fb_global fb_global;
@@ -67,7 +67,7 @@ void draw_cs_point(int x,int y) {//this should write to a backbuffer then I can
if(y > fb_global.info.yres) return;
if(i > fb_global.fblen) return;
//hack to test it with. remove me later.
- fb_global.current_color=-1;
+ //fb_global.current_color=-1;
int derp;
derp=(fb_global.current_color == -1) ? (rand()) : fb_global.current_color;
switch(fb_global.draw_mode) {
@@ -102,11 +102,13 @@ void draw_cs_line(cs_t p1,cs_t p2) {//error somewhere in here. derp...
for(y=min(p1.y,p2.y);y<max(p1.y,p2.y);y++) {
draw_cs_point(p1.x,y);
}
+ return;
}
if(p1.y == p2.y) {
for(x=min(p1.x,p2.x);x<max(p1.x,p2.x);x++) {
draw_cs_point(x,p1.y);
}
+ return;
}
xd=p1.x<p2.x?1:-1;
yd=p1.y<p2.y?1:-1;
@@ -330,11 +332,13 @@ void set_demands_attention() {
#endif
+//this should be returning an fd to something that'll be readable when events happen...
+//what kind of events would the fb ever have?
+//none?
int graphics_sub_init() {//some of this is keyboard init... should it be moved out? probably.
//int i;
int x,y;
fb_global.fb=open("/dev/fb0",O_RDWR);
- fb_global.kb=open("/dev/input/event0",O_RDWR);
memset(fb_global.keystate,0,sizeof(fb_global.keystate));
fcntl(fb_global.kb,F_SETFL,O_NONBLOCK);
assert(fb_global.fb > 0);
@@ -354,7 +358,8 @@ int graphics_sub_init() {//some of this is keyboard init... should it be moved o
flipscreen();
gra_global.width=fb_global.info.xres;
gra_global.height=fb_global.info.yres;
- return 0;
+ fprintf(stderr,"# width: %d height: %d\n",gra_global.width,gra_global.height);
+ return -1;//don't return a usable fd!
}
/* this need a framebuffer equivalent
@@ -370,221 +375,6 @@ int graphics_sub_init() {//some of this is keyboard init... should it be moved o
#define KEY_IS_DOWN(a) (fb_global.keystate[a/8] & (1<< (a % 8)))
-int graphics_event_handler(int world_changed) { //should calling draw_screen be in here?
-#if 0
- int redraw=0;
- char line[2048];
- char line2[1025];
- int len;
- struct input_event ie;
- memset(&ie,0,sizeof(ie));
- int l;
- real tmpx;
- real tmpz;
- radians tmprad;
- radians tmprad2;
- int i;
- //update the keystates...
- ioctl(fb_global.kb,EVIOCGKEY(sizeof(fb_global.keystate)),fb_global.keystate);//update keystate
- read(fb_global.kb,&ie,sizeof(ie));//????
-//need to not be using KEY_IS_DOWN so that it gets these events instead of just checking when it gets to this loop.
- if(KEY_IS_DOWN(KEY_ESC)) exit(0);
- if(KEY_IS_DOWN(KEY_ENTER)) {
- snprintf(line,sizeof(line)-1,"%s action %s\n",global.user,global.selected_object);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_UP)) {
- tmprad=d2r((degrees){global.camera.r.y.d});//if the angle is 0...
- tmprad2=d2r((degrees){global.camera.r.y.d});
- tmpx=WALK_SPEED*sin(tmprad.r);//cos(0)==1
- tmpz=WALK_SPEED*cos(tmprad2.r);//sin(0)==0
- snprintf(line,sizeof(line)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_DOWN)) {
- tmprad=d2r((degrees){global.camera.r.y.d+180});
- tmprad2=d2r((degrees){global.camera.r.y.d+180});
- tmpx=WALK_SPEED*sin(tmprad.r);
- tmpz=WALK_SPEED*cos(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_LEFT)) {
- tmprad=d2r((degrees){global.camera.r.y.d+90});
- tmprad2=d2r((degrees){global.camera.r.y.d+90});
- tmpx=WALK_SPEED*sin(tmprad.r);
- tmpz=WALK_SPEED*cos(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_RIGHT)) {
- tmprad=d2r((degrees){global.camera.r.y.d+270});
- tmprad2=d2r((degrees){global.camera.r.y.d+270});
- tmpx=WALK_SPEED*sin(tmprad.r);
- tmpz=WALK_SPEED*cos(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_W)) {
- snprintf(line,sizeof(line)-1,"%s move +0 +1 +0\n",global.user);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_S)) {
- snprintf(line,sizeof(line)-1,"%s move +0 +-1 +0\n",global.user);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_R)) {
- snprintf(line,sizeof(line)-1,"%s rotate +%d +0 +0\n",global.user,ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_Y)) {
- snprintf(line,sizeof(line)-1,"%s rotate +%d +0 +0\n",global.user,-ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_Q)) {
- snprintf(line,sizeof(line)-1,"%s rotate +0 +%d +0\n",global.user,ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_E)) {
- snprintf(line,sizeof(line)-1,"%s rotate +0 +%d +0\n",global.user,-ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_U)) {
- snprintf(line,sizeof(line)-1,"%s rotate +0 +0 +%d\n",global.user,ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_O)) {
- snprintf(line,sizeof(line)-1,"%s rotate +0 +0 +%d\n",global.user,-ROTATE_STEP);
- selfcommand(line);
- }
- if(KEY_IS_DOWN(KEY_P)) gra_global.split+=.1;
- if(KEY_IS_DOWN(KEY_L)) gra_global.split-=.1;
- if(KEY_IS_DOWN(KEY_Z)) global.zoom+=1;
- if(KEY_IS_DOWN(KEY_X)) {
- global.zoom-=1;
- if(global.zoom < 1) global.zoom=1;
- }
- if(KEY_IS_DOWN(KEY_C)) global.mmz*=1.1;
- if(KEY_IS_DOWN(KEY_V)) global.mmz/=1.1;
- if(KEY_IS_DOWN(KEY_H)) global.split+=1;
- if(KEY_IS_DOWN(KEY_J)) global.split-=1;
- if(KEY_IS_DOWN(KEY_6)) gra_global.maxshapes+=10;
- if(KEY_IS_DOWN(KEY_7)) gra_global.maxshapes-=10;
- if(KEY_IS_DOWN(KEY_D)) global.debug ^= 1;
- if(KEY_IS_DOWN(KEY_F)) global.derp ^= 1;
- if(KEY_IS_DOWN(KEY_M)) {
- gra_global.drawminimap += 1;
- gra_global.drawminimap %= 4;
- }
- if(KEY_IS_DOWN(KEY_A)) gra_global.drawsky ^= 1;
- if(KEY_IS_DOWN(KEY_3)) {
- gra_global.draw3d += 1;
- gra_global.draw3d %= 4;
- }
-//LONG comment. then rest of function. don't end it too early, derp.
-/*
- }
- break;
- default:
- switch(sym) {
- case XK_Return:
- strcpy(line,"\n");
- len=1;
- break;
- case XK_Left://hack. probably just replace this with printf()s
- strcpy(line,"\x1b[D");
- len=3;
- break;
- case XK_Right:
- strcpy(line,"\x1b[C");
- len=3;
- break;
- case XK_Down:
- strcpy(line,"\x1b[B");
- len=3;
- break;
- case XK_Up:
- strcpy(line,"\x1b[A");
- len=3;
- break;
- default:
- len=XLookupString(xkey,line,1023,NULL,NULL);
- break;
- }
- for(i=0;i/2 < len;i++) line2[i]="0123456789abcdef"[(line[i/2]>>(4*(1-(i%2)))) % 16];
- line2[i]=0;
- printf("%s data %s\n",global.user,line2);
- break;
- }
-
- //then do stuff based on what keystates are set.
- //... loop over the whole array?
- //have an array of deltas?
- //what sets mask?
- char motionnotify=0;
- unsigned int mask;
- if(global.beep) {
- global.beep=0;
- XBell(x11_global.dpy,1000);
- set_demands_attention();
- }
- while(XPending(x11_global.dpy)) {//these are taking too long?
- XNextEvent(x11_global.dpy, &e);
-// fprintf(stderr,"# handling event with type: %d\n",e.type);
- switch(e.type) {
-// case Expose:
-// if(e.xexpose.count == 0) redraw=1;
-// break;
- case MotionNotify:
- if(global.debug >= 2) fprintf(stderr,"# MotionNotify\n");
- motionnotify=1;
- break;
- case ButtonPress:
- if(global.debug >= 2) fprintf(stderr,"# ButtonPress\n");
- redraw=1;
- gra_global.buttonpressed=e.xbutton.button;//what's this for? mouse?
- break;
- case ButtonRelease:
- if(global.debug >= 2) fprintf(stderr,"# ButtonRelease\n");
- redraw=1;
- gra_global.buttonpressed=0;//what's this for???
- break;
- case ConfigureNotify:
- if(global.debug >= 2) fprintf(stderr,"# ConfigureNotify\n");
- redraw=1;
- XGetGeometry(x11_global.dpy,x11_global.w,&root,&global.x,&global.y,&gra_global.width,&gra_global.height,&gra_global.border_width,&gra_global.depth);
- if(gra_global.height * AR_W / AR_H != gra_global.width / (gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1))) {
- // height / AR_H * AR_W = width / (ss / (rab ? ss : 1))
- if(global.debug >= 2) {
- fprintf(stderr,"# %d != %d for some reason. probably your WM not respecting aspect ratio hints or calculating based on them differently. (would cause an off-by-one or so)\n",gra_global.height * AR_W / AR_H , gra_global.width / (gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1)));
- }
- if(gra_global.width / (gra_global.red_and_blue ? 1 : gra_global.split_screen) * AR_H / AR_W < gra_global.height) {
- gra_global.height=gra_global.width / (gra_global.red_and_blue ? 1 : gra_global.split_screen) * AR_H / AR_W;
- } else {
- gra_global.width=gra_global.height * AR_W / AR_H * (gra_global.red_and_blue ? 1 : gra_global.split_screen);
- }
- }
- gra_global.mapxoff=gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1))/2;
- gra_global.mapyoff=gra_global.height/2;
- break;
- case KeyPress:
- if(global.debug >= 2) fprintf(stderr,"# KeyPress\n");
- redraw=1;
- x11_keypress_handler(&e.xkey,gra_global.mousex,gra_global.mousey);
- break;
- default:
-// fprintf(stderr,"# received unknown event with type: %d\n",e.type);
- break;
- }
- }
- if(motionnotify) {
- XQueryPointer(x11_global.dpy,x11_global.w,&root,&child,&gra_global.rmousex,&gra_global.rmousey,&gra_global.mousex,&gra_global.mousey,&mask);
- redraw=1;
- }
-*/
-#endif
- if(world_changed) {
- draw_screen();//includes its own flip.
- }
- return 1;//redraw;
+void graphics_event_handler(struct shit *me,char *line) {
+ return;//fuck if i know. nothing to do?
}
diff --git a/src/graphics_fb.h b/src/graphics_fb.h
index d6e8d7c..0c3a753 100644
--- a/src/graphics_fb.h
+++ b/src/graphics_fb.h
@@ -1,9 +1,6 @@
#ifndef _HACKVR_GRAPHICS_FB_H_
#define _HACKVR_GRAPHICS_FB_H_
-//find this with trial and error or X11 log or... I don't care.
-#define FB_KEYB "/dev/input/event0"
-
#include <linux/input.h>
#define DRAW_MODE_CLEAR 0x0
@@ -16,7 +13,7 @@ struct fb_global {
int kb;
int draw_mode;
unsigned int current_color;
- unsigned int *backbuf;
+ unsigned int *backbuf;//this is assuming unsigned int is 4 bytes and color depth is 32.
struct fb_var_screeninfo info;
unsigned int *buf;
unsigned int fblen;
diff --git a/src/hackvr b/src/hackvr
deleted file mode 100755
index 1c9d16c..0000000
--- a/src/hackvr
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-if [ "_$HACKVR" != "_" -a "_$HACKVR" != "_$0" ];then
- exec $HACKVR $*
-fi
-if [ $DISPLAY ]; then
- exec hackvr_x11 $*
-else
- exec hackvr_fb $*
-fi
diff --git a/src/hackvr.c b/src/hackvr.c
index 9ffcaf7..80991dd 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -49,6 +49,8 @@ int lum_based_on_distance(c3_s_t *s) {
//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;
@@ -133,6 +135,7 @@ int hackvr_handler(char *line);
void hackvr_handler_idc(struct shit *me,char *line) {
switch(hackvr_handler(line)) {
case -1://quit
+ fprintf(stderr,"# exiting due to EOF\n");
exit(0);
case 0://don't redraw
break;
@@ -330,7 +333,11 @@ int hackvr_handler(char *line) {
return ret;
}
if(!strcmp(command,"quit")) {
- return -1;
+ if(!strcmp(id,global.user)) {//only exit hackvr if *we* are quitting
+ return -1;
+ } else {
+ fprintf(stderr,"# %s has quit hackvr\n",id);
+ }
}
if(!strcmp(command,"set")) { //set variable //TODO: add more things to this.
if(len != 3 && len != 4) return ret;
@@ -610,6 +617,9 @@ int hackvr_handler(char *line) {
return ret;
}
fprintf(stderr,"# I don't know what command you're talking about. %s\n",command);
+ for(i=0;a[i];i++) {
+ fprintf(stderr,"# a[%d] = %s\n",i,a[i]);
+ }
//I used to have free(line) here, but this place is never gotten to if a command is found so it wasn't getting released.
return ret;
}
@@ -640,6 +650,7 @@ void alarm_handler(int sig) {
int main(int argc,char *argv[]) {
int i;
+ int fd;
if(argc == 2) {
if(!strcmp(argv[1],"-v") || !strcmp(argv[1],"--version")) {
hvr_version();
@@ -662,7 +673,6 @@ int main(int argc,char *argv[]) {
inittable(&global.ht_group,65536);
- fcntl(1,F_SETFL,O_NONBLOCK);//won't work
setbuf(stdin,0);
setbuf(stdout,0);
global.debug=DEBUG;
@@ -676,11 +686,20 @@ int main(int argc,char *argv[]) {
idc.shitlen=0;
#ifdef GRAPHICAL
- i=add_fd(graphics_init(),graphics_event_handler);
+ if((fd=graphics_init()) == -1) {
+ fprintf(stderr,"# graphics system in use doesn't generate events.\n");
+ } else {
+ i=add_fd(graphics_init(),graphics_event_handler);
+ fprintf(stderr,"# graphics fd: %d\n",idc.fds[i].fd);
+ idc.fds[i].read_lines_for_us=0;
+ }
+
+ i=add_fd(mouse_init(),mouse_event_handler);//this should probably be split to keyboard_init, and mouse_init
+ fprintf(stderr,"# mouse fd: %d\n",idc.fds[i].fd);
idc.fds[i].read_lines_for_us=0;
- fprintf(stderr,"# x11 fd: %d\n",input_init());
- i=add_fd(input_init(),input_event_handler);
+ i=add_fd(keyboard_init(),keyboard_event_handler);
+ fprintf(stderr,"# keyboard fd: %d\n",idc.fds[i].fd);
idc.fds[i].read_lines_for_us=0;
pipe(gra_global.redraw);
diff --git a/src/hackvr_xdie.c b/src/hackvr_xdie.c
new file mode 120000
index 0000000..e4c9ddd
--- /dev/null
+++ b/src/hackvr_xdie.c
@@ -0,0 +1 @@
+hackvr.c \ No newline at end of file
diff --git a/src/input.c b/src/input.c
deleted file mode 100644
index 8c1b99b..0000000
--- a/src/input.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <idc.h>
-#include "common.h"
-#include "graphics_x11.h"
-#include "keyboard_x11.h"
-#include "mouse_x11.h"
-#include "input.h"
-
-extern struct x11_global x11_global;
-
-int input_init() {
- return x11_global.fd;
-}
-
-void input_event_handler(struct shit *me,char *line) {
- if(keyboard_event_handler(me,line)) {
- }
- if(mouse_event_handler(me,line)) {
- }
-}
diff --git a/src/input.h b/src/input.h
index 15b28f4..0c878e6 100644
--- a/src/input.h
+++ b/src/input.h
@@ -1,11 +1,17 @@
#ifndef _HV_MOUSE_H_
#define _HV_MOUSE_H_
+//these might as well be in keyboard.h and mouse.h
+//but I don't have separate files for those yet.
+//all keyboard and mouse drivers will need to implement these functions
+
#include <idc.h>
-int input_init();
-void input_event_handler(struct shit *me,char *line);
-int mouse_event_handler();
-int keyboard_event_handler();
+//these *_init() will return the fd that will have the keyboard and mouse events
+int mouse_init();
+int keyboard_init();
+//these two functions are libidc handlers
+void mouse_event_handler(struct shit *,char *);
+void keyboard_event_handler(struct shit *,char *);
#endif
diff --git a/src/keyboard.c b/src/keyboard.c
index c0e8ed9..78a0064 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10,7 +10,7 @@ extern struct gra_global gra_global;
char keyboard_map[1024]={0};
//return 0 is all is fine, -1 if we need to exit
-void keyboard_event_handler() {
+void keyboard_event_handler(struct shit *me,char *junk) {//these arguments aren't actually used.
int k;
char line[2560];
c3_group_rot_t *gr;
diff --git a/src/keyboard_die.c b/src/keyboard_die.c
index d620f70..5a52879 100644
--- a/src/keyboard_die.c
+++ b/src/keyboard_die.c
@@ -6,10 +6,22 @@
#include "keyboard.h"
-#define KBDEV "/dev/input/event0"
+//#define KBDEV "/dev/input/event0"
+#define KBDEV "/dev/input/by-path/platform-i8042-serio-0-event-kbd"
int kbfd = -1;
+int keyboard_init() {
+ if((kbfd=open(KBDEV,O_RDWR)) == -1) {
+ fprintf(stderr,"# failed to open keyboard: %s\n",KBDEV);
+ }
+ return kbfd;
+}
+
+/*void keyboard_event_handler(struct *me,char *junk) {
+ //wtf goes here?
+}*/
+
hvk_t die_keypress_handler(unsigned short code) {
switch(code) {
case KEY_W: return HVK_FORWARD;
@@ -26,14 +38,6 @@ hvk_t get_keyboard_event() {
struct input_event ie;
int l;
memset(&ie,0,sizeof(ie));
- if(kbfd == -1) {
- kbfd=open(KBDEV,O_RDWR);
- fcntl(kbfd,F_SETFL,O_NONBLOCK);
- }
- if(kbfd == -1) {
- fprintf(stderr,"# keyboard shit fucked up.\n");
- return 1;
- }
if((l=read(kbfd,&ie,sizeof(ie))) > 0) {
if(ie.type == 1) {
fprintf(stderr,"# value: %d code: %d type: %d\n",ie.value,ie.code,ie.type);
diff --git a/src/math.c b/src/math.c
index 6a077f0..9f7e0cc 100644
--- a/src/math.c
+++ b/src/math.c
@@ -193,6 +193,11 @@ c3_t c3_add(c3_t p1,c3_t p2) {
return (c3_t){p1.x+p2.x,p1.y+p2.y,p1.z+p2.z};
}
+//this could probably be a macro, or inline or whatever. and also work for cs_t
+c2_t c2_add(c2_t p1,c2_t p2) {
+ return (c2_t){p1.x+p2.x,p1.y+p2.y};
+}
+
real distance3(c3_t p1,c3_t p2) {
return sqrt(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) )+( (p1.z-p2.z)*(p1.z-p2.z) ));
}
diff --git a/src/math.h b/src/math.h
index e7b5249..b333767 100644
--- a/src/math.h
+++ b/src/math.h
@@ -21,6 +21,7 @@ radians points_to_angle(c2_t p1,c2_t p2);
int between_angles(degrees d,real lower,real upper);
c3_s_t apply_group_relative(c3_s_t s,c3_group_rot_t *group_rot);
c3_t c3_add(c3_t p1,c3_t p2);
+c2_t c2_add(c2_t p1,c2_t p2);
real distance3(c3_t p1,c3_t p2);
void print_point(c3_t p);
diff --git a/src/mouse_die.c b/src/mouse_die.c
index 6729a94..4fddf5f 100644
--- a/src/mouse_die.c
+++ b/src/mouse_die.c
@@ -4,6 +4,10 @@
#include <fcntl.h>
#include <unistd.h>
+#include "graphics_c3.h"
+
+extern struct hvr_global global;
+extern struct gra_global gra_global;
//#define MOUSEDEV "/dev/input/mouse0" //just one of the many possibly connected mice. (just in case you want to use one mouse for one thing and another mouse for something else)
#define MOUSEDEV "/dev/input/mice" //all the mice connected act as one.
@@ -18,13 +22,24 @@ struct wtf {
char dy;
};
+int mouse_init() {
+ if((mfd=open(MOUSEDEV,O_RDWR)) == -1) {
+ fprintf(stderr,"# failed to open mouse: %d\n",mfd);
+ }
+ return mfd;
+}
+
int mouse_event_handler() {
struct wtf ie;
+ int butt;
int l;
+ int i;
+ int redrawplzkthx=0;
memset(&ie,0,sizeof(ie));
if(mfd == -1) {
mfd=open(MOUSEDEV,O_RDWR);
- fcntl(mfd,F_SETFL,O_NONBLOCK);
+ //probably don't need nonblock anymore.
+ //fcntl(mfd,F_SETFL,O_NONBLOCK);
}
if(mfd == -1) {
fprintf(stderr,"# mouse shit fucked up.\n");
@@ -32,7 +47,43 @@ int mouse_event_handler() {
}
if((l=read(mfd,&ie,sizeof(ie))) > 0) {
//type == 8 and a or of some bits to say which direction.
- fprintf(stderr,"# mouse debug: type:\t%d\tdx:%d\tdy:%d\n",ie.type,ie.dx,ie.dy);
+ //these types are movement: 8 40 56 24
+ for(i=0;i<4;i++) {//we need to loop over all buttons each event. :/
+ butt=ie.type & 0x07 & (1<<i);
+ if(butt) {//this button is down
+ fprintf(stderr,"# mouse button %d is down.\n",butt-1);
+ if(gra_global.mousemap[butt-1] != 1) {//freshly down. save coords and set it to down.
+ gra_global.dragstart[butt-1]=gra_global.mouse;
+ gra_global.mousemap[butt-1]=1;
+ redrawplzkthx=1;
+ }
+ } else {
+ if(gra_global.mousemap[(1<<i)-1]) {//only if it was pressed we mark it as "released"
+ fprintf(stderr,"# mouse button %d is being marked as released.\n",(1<<i)-1);
+ gra_global.mousemap[(1<<i)-1]=-1;
+ if((1<<i)-1 == 1) {//do this for right-click only.
+ gra_global.oldcamera = global.camera.r;//we're done dragging, so set this as where the camera points at for next drag around
+ }
+ redrawplzkthx=1;
+ //this is where camera rotation based on dragging is done?
+ }
+ }
+ }
+ if(ie.dx || ie.dy) {
+ fprintf(stderr,"# mouse debug: type:\t%d\tdx:%d\tdy:%d\n",ie.type,ie.dx,ie.dy);
+ gra_global.mouse.x+=ie.dx;
+ gra_global.mouse.y+=ie.dy;
+ fprintf(stderr,"# mouse: x:%F y:%F\n",gra_global.mouse.x,gra_global.mouse.y);
+ if(gra_global.mousemap[1] == 1) {//if "right" click is held down
+ global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[1].y);
+ global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[1].x);
+ }
+ redrawplzkthx=1;
+ }
+ }
+ if(redrawplzkthx) {
+ redraw();
+ return 1;
}
return 0;
}
diff --git a/src/mouse_x11.c b/src/mouse_x11.c
index 16c577c..719940e 100644
--- a/src/mouse_x11.c
+++ b/src/mouse_x11.c
@@ -73,6 +73,9 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu
global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[2].y);
global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[2].x);
}
+ //do we need to redraw on mouse movement?
+ //probably.
+ redrawplzkthx=1;
}
if(redrawplzkthx) {
redraw();