diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rwxr-xr-x | bin/hackvr (renamed from src/hackvr) | 0 | ||||
| -rw-r--r-- | share/hackvr/examples/tictactoe/board | 18 | ||||
| -rw-r--r-- | share/hackvr/examples/tictactoe/board_orig | 18 | ||||
| -rwxr-xr-x | share/hackvr/examples/tictactoe/game.sh | 52 | ||||
| -rwxr-xr-x | share/hackvr/examples/tictactoe/run | 2 | ||||
| -rw-r--r-- | src/Makefile | 40 | ||||
| -rw-r--r-- | src/hackvr.c | 22 | ||||
| l--------- | src/hackvr_xdie.c | 1 | ||||
| -rw-r--r-- | src/input.c | 19 | ||||
| -rw-r--r-- | src/input.h | 14 | ||||
| -rw-r--r-- | src/keyboard.c | 2 | ||||
| -rw-r--r-- | src/keyboard_die.c | 16 | ||||
| -rw-r--r-- | src/mouse_die.c | 10 | 
14 files changed, 129 insertions, 87 deletions
| @@ -4,5 +4,7 @@ src/hackvr_fb  src/hackvr_freeglut  src/hackvr_headless  src/hackvr_x11 +src/hackvr_xdie  src/hackvr_opengl  src/slowcat +src/nonblocktail diff --git a/share/hackvr/examples/tictactoe/board b/share/hackvr/examples/tictactoe/board index 607ebf3..e7494fd 100644 --- a/share/hackvr/examples/tictactoe/board +++ b/share/hackvr/examples/tictactoe/board @@ -1,13 +1,13 @@  _reset addshape 2 3 -4 6 4 -5 6 4 -4 5 4 -topleft addshape 2 4 -3 13 4 -1 13 4 -1 11 4 -3 11 4 -topcenter addshape 2 4 -1 13 4 1 13 4 1 11 4 -1 11 4 -topright addshape 2 4 1 13 4 3 13 4 3 11 4 1 11 4 +boardtopleft addshape 2 4 -3 13 4 -1 13 4 -1 11 4 -3 11 4 +boardtopcenter addshape 2 4 -1 13 4 1 13 4 1 11 4 -1 11 4 +boardtopright addshape 2 4 1 13 4 3 13 4 3 11 4 1 11 4 -middleleft addshape 2 4 -3 11 4 -1 11 4 -1 9 4 -3 9 4 -middlecenter addshape 2 4 -1 11 4 1 11 4 1 9 4 -1 9 4 -middleright addshape 2 4 1 11 4 3 11 4 3 9 4 1 9 4 +boardmiddleleft addshape 2 4 -3 11 4 -1 11 4 -1 9 4 -3 9 4 +boardmiddlecenter addshape 2 4 -1 11 4 1 11 4 1 9 4 -1 9 4 +boardmiddleright addshape 2 4 1 11 4 3 11 4 3 9 4 1 9 4 -bottomleft addshape 2 4 -3 9 4 -1 9 4 -1 7 4 -3 7 4 -bottomcenter addshape 2 4 -1 9 4 1 9 4 1 7 4 -1 7 4 -bottomright addshape 2 4 1 9 4 3 9 4 3 7 4 1 7 4 +boardbottomleft addshape 2 4 -3 9 4 -1 9 4 -1 7 4 -3 7 4 +boardbottomcenter addshape 2 4 -1 9 4 1 9 4 1 7 4 -1 7 4 +boardbottomright addshape 2 4 1 9 4 3 9 4 3 7 4 1 7 4 diff --git a/share/hackvr/examples/tictactoe/board_orig b/share/hackvr/examples/tictactoe/board_orig index bc97ee4..2fff3ba 100644 --- a/share/hackvr/examples/tictactoe/board_orig +++ b/share/hackvr/examples/tictactoe/board_orig @@ -1,14 +1,14 @@  _reset addshape 2 3 -4 -4 4 -5 -4 4 -4 -5 4  _exit addshape 2 3 4 -4 4 5 -4 4 4 -5 4 -topleft addshape 2 4 -3 3 4 -1 3 4 -1 1 4 -3 1 4 -topcenter addshape 2 4 -1 3 4 1 3 4 1 1 4 -1 1 4 -topright addshape 2 4 1 3 4 3 3 4 3 1 4 1 1 4 +boardtopleft addshape 2 4 -3 3 4 -1 3 4 -1 1 4 -3 1 4 +boardtopcenter addshape 2 4 -1 3 4 1 3 4 1 1 4 -1 1 4 +boardtopright addshape 2 4 1 3 4 3 3 4 3 1 4 1 1 4 -middleleft addshape 2 4 -3 1 4 -1 1 4 -1 -1 4 -3 -1 4 -middlecenter addshape 2 4 -1 1 4 1 1 4 1 -1 4 -1 -1 4 -middleright addshape 2 4 1 1 4 3 1 4 3 -1 4 1 -1 4 +boardmiddleleft addshape 2 4 -3 1 4 -1 1 4 -1 -1 4 -3 -1 4 +boardmiddlecenter addshape 2 4 -1 1 4 1 1 4 1 -1 4 -1 -1 4 +boardmiddleright addshape 2 4 1 1 4 3 1 4 3 -1 4 1 -1 4 -bottomleft addshape 2 4 -3 -1 4 -1 -1 4 -1 -3 4 -3 -3 4 -bottomcenter addshape 2 4 -1 -1 4 1 -1 4 1 -3 4 -1 -3 4 -bottomright addshape 2 4 1 -1 4 3 -1 4 3 -3 4 1 -3 4 +boardbottomleft addshape 2 4 -3 -1 4 -1 -1 4 -1 -3 4 -3 -3 4 +boardbottomcenter addshape 2 4 -1 -1 4 1 -1 4 1 -3 4 -1 -3 4 +boardbottomright addshape 2 4 1 -1 4 3 -1 4 3 -3 4 1 -3 4 diff --git a/share/hackvr/examples/tictactoe/game.sh b/share/hackvr/examples/tictactoe/game.sh index b4187dd..92192cc 100755 --- a/share/hackvr/examples/tictactoe/game.sh +++ b/share/hackvr/examples/tictactoe/game.sh @@ -4,30 +4,34 @@ BOARDFILE=board_orig  cat camera.pos $BOARDFILE  echo "go. player: $turn" >&2  grep --line-buffered action \ -  | while read user derp group;do -#    echo FUCK >&2 -    if grep "_reset" <<<$group >/dev/null;then -     printf "%s deleteallexcept .\n" "$user" -     cat $BOARDFILE -     continue -    elif grep "_exit" <<<$group >/dev/null;then #this doesn't work in local games. :/ -     exit 0 -    elif grep "_" <<<$group >/dev/null;then -#     xmessage "CUT IT OUT" -     echo CUT IT OUT > /dev/stderr -     continue -    else -     turn=$(expr \( $turn + 1 \) % 2) -     #printf "# turn: %d\n" "$turn" > /dev/stderr -     printf "$user deletegroup %s\n" "$group" -     #printf "$user deletegroup %s\n" "$group" > /dev/stderr +  | while read user action group;do +    if [ $action = "action" ];then +      if grep "_reset" <<<$group >/dev/null;then +       printf "%s deleteallexcept %s\n" "$user" "$user" +       cat $BOARDFILE +       continue +      elif grep "_exit" <<<$group >/dev/null;then +       #if a program wants to exit, it should just exit. +       #the program may have been ran by some other program. +       #maybe just filter out server-side quit messages for your own username? +       #any user quit will cause any hackvr to quit? +       #printf "%s quit\n" "$user" +       exit 0 +      elif grep "_" <<<$group >/dev/null;then +       echo CUT IT OUT > /dev/stderr +       continue +      elif grep "^board" <<<$group >/dev/null;then +       turn=$(expr \( $turn + 1 \) % 2) +       #printf "# turn: %d\n" "$turn" > /dev/stderr +       printf "%s deletegroup %s\n" "$user" "$group" +       #printf "$user deletegroup %s\n" "$group" > /dev/stderr  #need to get the first point of the group clicked and translate the new shape by that much -     translatex="$(grep "$group" $BOARDFILE | grep -v '^#' | tr -s ' ' | cut '-d ' -f5)" -     translatey="$(grep "$group" $BOARDFILE | grep -v '^#' | tr -s ' ' | cut '-d ' -f6)" -     cat "marker$turn" | offsetshape.sh $translatex "$(expr "$translatey" - 2 )" 0 -#     printf "%s move %s %s 2\n" "_marker" "$(expr "$translatex")" "$(expr "$translatey" - 2 )" -     #printf "%s move %s %s 2\n" "_marker" "$(expr "$translatex")" "$(expr "$translatey" - 2 )" >/dev/stderr -     grep "$group" $BOARDFILE | sed "s/$group/_marker2/g" #this is to make it still show the square around it. -     printf "%s renamegroup _marker _marker%s%s\n" "$user" "$(date +%s)" "$RANDOM" +       translatex="$(grep "$group" $BOARDFILE | grep -v '^#' | tr -s ' ' | cut '-d ' -f5)" +       translatey="$(grep "$group" $BOARDFILE | grep -v '^#' | tr -s ' ' | cut '-d ' -f6)" +       cat "marker$turn" | offsetshape.sh $translatex "$(expr "$translatey" - 2 )" 0 +       grep "$group" $BOARDFILE | sed "s/$group/_marked/g" +      else +       xmessage "what? $group" +      fi      fi    done diff --git a/share/hackvr/examples/tictactoe/run b/share/hackvr/examples/tictactoe/run index bf9c87a..54d712a 100755 --- a/share/hackvr/examples/tictactoe/run +++ b/share/hackvr/examples/tictactoe/run @@ -1,4 +1,4 @@  #!/usr/bin/env bash  turn=$( expr $RANDOM % 2) -echo "go. player: $turn" +echo "# go. player: $turn" >&2  hackvr_coproc ./game.sh diff --git a/src/Makefile b/src/Makefile index 5c83e45..6ed9c5d 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_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,41 @@ 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 +	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/hackvr.c b/src/hackvr.c index 9ffcaf7..7d2a8dc 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;  } @@ -677,10 +687,16 @@ int main(int argc,char *argv[]) {  #ifdef GRAPHICAL    i=add_fd(graphics_init(),graphics_event_handler); +  fprintf(stderr,"# x11 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..e043db4 100644 --- a/src/keyboard_die.c +++ b/src/keyboard_die.c @@ -10,6 +10,17 @@  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; @@ -28,10 +39,11 @@ hvk_t get_keyboard_event() {    memset(&ie,0,sizeof(ie));    if(kbfd == -1) {      kbfd=open(KBDEV,O_RDWR); -    fcntl(kbfd,F_SETFL,O_NONBLOCK); +    //probably not needed anymore +    //fcntl(kbfd,F_SETFL,O_NONBLOCK);    }    if(kbfd == -1) { -    fprintf(stderr,"# keyboard shit fucked up.\n"); +    fprintf(stderr,"# keyboard shit fucked up. probably permissions error.\n");      return 1;    }    if((l=read(kbfd,&ie,sizeof(ie))) > 0) { diff --git a/src/mouse_die.c b/src/mouse_die.c index 6729a94..b17c143 100644 --- a/src/mouse_die.c +++ b/src/mouse_die.c @@ -18,13 +18,21 @@ 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 l;    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"); | 
