diff options
| author | epoch <epoch@hacking.allowed.org> | 2020-04-02 04:59:36 -0500 | 
|---|---|---|
| committer | epoch <epoch@hacking.allowed.org> | 2020-04-02 04:59:36 -0500 | 
| commit | 3ad65451ff1326f2fc44057ffa76f44e01c7c6bb (patch) | |
| tree | 2f3721130bb362d4d2896ce04d0c19dfef0ef651 /src | |
| parent | 192c4437672ce7743f1e567b3fbf2ef7c9c4bbca (diff) | |
| download | hackvr-3ad65451ff1326f2fc44057ffa76f44e01c7c6bb.tar.gz hackvr-3ad65451ff1326f2fc44057ffa76f44e01c7c6bb.zip | |
added a handler for graphics events and not only assuming we only need to redraw when there's an input event, so draw_screen() got moved and now redraw() will actually call it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics_c3.c | 5 | ||||
| -rw-r--r-- | src/graphics_c3.h | 4 | ||||
| -rw-r--r-- | src/graphics_cs.h | 3 | ||||
| -rw-r--r-- | src/graphics_cs_x11.c | 21 | ||||
| -rw-r--r-- | src/graphics_x11.h | 2 | ||||
| -rw-r--r-- | src/hackvr.c | 19 | 
6 files changed, 27 insertions, 27 deletions
| diff --git a/src/graphics_c3.c b/src/graphics_c3.c index 3240058..0727fd7 100644 --- a/src/graphics_c3.c +++ b/src/graphics_c3.c @@ -476,7 +476,7 @@ void redraw() {//something is requesting a redraw.    }  } -int graphics_init() { +int graphics_init() {//return the fd needed to read graphics events.  //some of these values set   global.zoom=25.0l;//I think if this is set to 1, then 1 3d unit is 1 2d unit?   global.camera.r.x.d=0; @@ -515,6 +515,5 @@ int graphics_init() {   gra_global.drawminimap=DEFAULT_MINIMAP;   gra_global.draw3d=2;   gra_global.force_redraw=FORCE_REDRAW; - graphics_sub_init(); - return 0;//we're fine + return graphics_sub_init();  } diff --git a/src/graphics_c3.h b/src/graphics_c3.h index 56d85b7..388a982 100644 --- a/src/graphics_c3.h +++ b/src/graphics_c3.h @@ -1,6 +1,8 @@  #ifndef _HACKVR_GRAPHICS_H_  #define _HACKVR_GRAPHICS_H_ +#include <idc.h> +  struct gra_global {    unsigned int width;    unsigned int height; @@ -36,7 +38,7 @@ typedef struct {  int graphics_init();  int graphics_sub_init(); -int graphics_event_handler(); +void graphics_event_handler(struct shit *me,char *line);  void draw_screen();  void set_aspect_ratio();  int selfcommand(char *s); diff --git a/src/graphics_cs.h b/src/graphics_cs.h index 31ee5f1..a16f03f 100644 --- a/src/graphics_cs.h +++ b/src/graphics_cs.h @@ -2,6 +2,7 @@  #define _HACKVR_GRAPHICS_CS_H_  #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. @@ -21,7 +22,7 @@ void set_color_blue();  void clear_backbuffer();  void keypress_handler(unsigned char sym,int x,int y);  int graphics_init(); -int graphics_event_handler(); +void graphics_event_handler(struct shit *me,char *line);  void set_clipping_rectangle(int x,int y,int width,int height);  void red_and_blue_magic();  void draw_mode_and(); diff --git a/src/graphics_cs_x11.c b/src/graphics_cs_x11.c index f58600b..389d9f7 100644 --- a/src/graphics_cs_x11.c +++ b/src/graphics_cs_x11.c @@ -495,11 +495,11 @@ int graphics_sub_init() {   }   fprintf(stderr,"# done.\n");  */ - return 0;//we're fine + return x11_global.fd;//we're fine  } -int graphics_event_handler(int world_changed) { //should calling draw_screen be in here? - int redraw=0; +void graphics_event_handler(struct shit *me,char *line) {//line should always be empty + int redrawplzkthx=0;   Window root;//just used to sponge up a return value   XEvent e;   if(global.beep) { @@ -509,15 +509,14 @@ int graphics_event_handler(int world_changed) { //should calling draw_screen be   }   while(XCheckMaskEvent(x11_global.dpy,HV_GRAPHICS_X11_EVENT_MASK,&e)) {//we should squish all of the window events. they just cause a redraw anyway     switch(e.type) { -     case Expose: case NoExpose: case MapNotify: +     case Expose: case NoExpose: case MapNotify: case FocusIn: case FocusOut: case VisibilityNotify:         //if(e.xexpose.count == 0) redraw=1; -       redraw=1; +       redrawplzkthx=1;         break; -//These are all window events.       case ConfigureNotify:         if(global.debug >= 2) fprintf(stderr,"# ConfigureNotify\n"); -       redraw=1; +       redrawplzkthx=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)) @@ -536,12 +535,10 @@ int graphics_event_handler(int world_changed) { //should calling draw_screen be      default:        fprintf(stderr,"# received unknown event with type: %d\n",e.type); +      fprintf(stderr,"# let's redraw anyway.\n"); +      redrawplzkthx=1;        break;    }   } - //redraw=1;//meh. - if(redraw || world_changed) { -  draw_screen();//should this be in here? :? - } - return redraw; + if(redrawplzkthx) redraw();  } diff --git a/src/graphics_x11.h b/src/graphics_x11.h index b5c3119..41c0bbe 100644 --- a/src/graphics_x11.h +++ b/src/graphics_x11.h @@ -3,7 +3,7 @@  #include <X11/Xlib.h> -#define HV_GRAPHICS_X11_EVENT_MASK StructureNotifyMask|ExposureMask +#define HV_GRAPHICS_X11_EVENT_MASK StructureNotifyMask|ExposureMask|VisibilityChangeMask|FocusChangeMask  struct x11_global {//stores global variables for the x11 *specific* shit.    XColor colors[256]; diff --git a/src/hackvr.c b/src/hackvr.c index aa5286b..aa9a1f2 100644 --- a/src/hackvr.c +++ b/src/hackvr.c @@ -131,16 +131,16 @@ int hackvr_handler(char *line);  void hackvr_handler_idc(struct shit *me,char *line) {    switch(hackvr_handler(line)) { -    case -1: +    case -1://quit        exit(0); -    case 0: +    case 0://don't redraw        break; -    case 1: +    case 1://redraw please.      #ifdef GRAPHICAL        redraw();      #endif        break; -    default: +    default://no idea.        break;    }  } @@ -604,9 +604,9 @@ 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) { +void redraw_handler(struct shit *me,char *line) {//how do we strip out extra redraws?    if(gra_global.force_redraw) { -    graphics_event_handler(1); +    draw_screen();      gra_global.force_redraw=0;    }  } @@ -655,14 +655,15 @@ int main(int argc,char *argv[]) {    idc.shitlen=0;  #ifdef GRAPHICAL -  graphics_init(); +  i=add_fd(graphics_init(),graphics_event_handler); +  idc.fds[i].read_lines_for_us=0; -  fprintf(stderr,"# x11 fd: %d",input_init()); +  fprintf(stderr,"# x11 fd: %d\n",input_init());    i=add_fd(input_init(),input_event_handler);    idc.fds[i].read_lines_for_us=0;    pipe(gra_global.redraw); -  add_fd(gra_global.redraw[0],redraw_handler);//lol. write a byte to other half of pipe to redraw screen. +  add_fd(gra_global.redraw[0],redraw_handler);//write a line to get a redraw?  #endif    add_fd(0,hackvr_handler_idc);//looks like default mode is to exit on EOF of stdin    pipe(global.selfpipe); | 
