summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2018-12-16 19:28:39 -0600
committerepoch <epoch@hacking.allowed.org>2018-12-16 19:28:39 -0600
commitf479b438e6119e83c95b19aaeccd61a8e5eded27 (patch)
tree726a3916d9128f6c970f49431ef8b27140e49747 /src
parent13dd5a6d313a2086647751286ca8315a12c804f1 (diff)
downloadhackvr-f479b438e6119e83c95b19aaeccd61a8e5eded27.tar.gz
hackvr-f479b438e6119e83c95b19aaeccd61a8e5eded27.zip
fuck if I know. lots of shit. moved files.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile18
-rw-r--r--src/common.h11
-rw-r--r--src/config.h2
-rw-r--r--src/graphics_c3.c60
-rw-r--r--src/graphics_c3.h10
-rw-r--r--src/graphics_c3_freeglut.c7
-rw-r--r--src/graphics_cs_fb.c43
-rw-r--r--src/graphics_cs_x11.c97
-rw-r--r--src/graphics_x11.h4
-rwxr-xr-xsrc/hackvr3
-rw-r--r--src/hackvr.c108
-rw-r--r--src/math.c2
-rw-r--r--src/slowcat.c1
-rwxr-xr-xsrc/testit.sh2
14 files changed, 212 insertions, 156 deletions
diff --git a/src/Makefile b/src/Makefile
index 90a5e73..7bc082b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,23 +3,23 @@
CFLAGS=-Wall -pedantic -std=c99 -DGRAPHICAL -ffast-math
#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 hackvr_fb slowcat
+all: hackvr_headless hackvr_x11 hackvr_fb hackvr_freeglut slowcat
hackvr_headless: LDLIBS=-lm
-hackvr_headless: hackvr_headless.o math.o
+hackvr_headless: hackvr_headless.o math.o physics.o
hackvr_x11: LDLIBS=-lm -lX11
-hackvr_x11: hackvr_x11.o graphics_c3.o graphics_c2.o graphics_cs_x11.o math.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: LDLIBS=-lm
-hackvr_fb: hackvr_fb.o graphics_c3.o graphics_c2.o graphics_cs_fb.o math.o
+hackvr_fb: hackvr_fb.o graphics_c3.o graphics_c2.o graphics_cs_fb.o math.o physics.o keyboard_die.o keyboard.o mouse_die.o
hackvr_opengl: LDLIBS=-lm -lGL -lGLU -lglut
-hackvr_opengl: hackvr_opengl.o graphics_c3.o graphics_c2_opengl.o graphics_cs_opengl.o math.o
+hackvr_opengl: hackvr_opengl.o graphics_c3.o graphics_c2_opengl.o graphics_cs_opengl.o math.o physics.o
hackvr_freeglut: LDLIBS=-lm -lGL -lGLU -lglut
-hackvr_freeglut: hackvr_freeglut.o graphics_c3_freeglut.o math.o
+hackvr_freeglut: hackvr_freeglut.o graphics_c3_freeglut.o math.o physics.o keyboard.o mouse_die.o keyboard_die.o
hackvr_freeglut.o: LDLIBS=-lm -lGL -lGLU -lglut
@@ -33,8 +33,12 @@ hackvr_headless.o: LDLIBS=-lm
graphics_c3.o: LDLIBS=-lm
graphics_c2.o: LDLIBS=-lm
+physics.o: LDLIBS=-lm
+keyboard.o: LDLIBS=-lm
graphics_cs_x11.o: LDLIBS=-lm -lX11
+mouse_x11.o:-lX11
+keyboard_x11.o:-lX11
graphics_c2_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
graphics_cs_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
@@ -45,6 +49,7 @@ install:
install -D hackvr_headless $(PREFIX)/bin/hackvr_headless
install -D hackvr_x11 $(PREFIX)/bin/hackvr_x11
install -D hackvr_fb $(PREFIX)/bin/hackvr_fb
+ install -D hackvr_freeglut $(PREFIX)/bin/hackvr_freeglut
install -D slowcat $(PREFIX)/bin/slowcat
uninstall:
@@ -55,6 +60,7 @@ uninstall:
rm $(PREFIX)/bin/slowcat
clean:
+ rm -f hackvr_freeglut
rm -f hackvr_headless
rm -f hackvr_opengl
rm -f hackvr_x11
diff --git a/src/common.h b/src/common.h
index da34ea2..93e8d27 100644
--- a/src/common.h
+++ b/src/common.h
@@ -48,9 +48,10 @@ typedef struct {
typedef struct {
char *id;
- c3_rot_t r;
- c3_t p;
- c3_t s;
+ c3_rot_t r;//rotation
+ c3_t p;//position
+ c3_t s;//??? shape??? I dunno.
+ c3_t v;//velocity
} c3_group_rot_t;
//typedef struct c3_line {//is this even used? I think I just use c3_s_t with 2 points.
@@ -88,6 +89,7 @@ typedef struct c3_shape {//use array or linked list?
shape_flavor type;
unsigned char len;
c3_t p[MAX_SIDES];
+ c3_t v;//velocities.
struct attrib attrib;
} c3_s_t;
@@ -102,6 +104,7 @@ struct global {
char selected_object[2000];//meh
int periodic_output;//if false, we output commands from keypresses as they're being sent to the command interpreter. if true we output every value amount of time. miliseconds probably.
real mmz;
+ int lps;//loops per second. same as frame per second but also works for headless.
struct c3_shape *shape[SHAPES];
int shapes;
c3_group_rot_t *group_rot[SHAPES];//there can be less of these.
@@ -111,4 +114,6 @@ struct global {
real split;
};
+int selfcommand(char *);
+
#endif
diff --git a/src/config.h b/src/config.h
index 2541056..a044ff2 100644
--- a/src/config.h
+++ b/src/config.h
@@ -14,7 +14,7 @@
#define SHAPES 65535
-#define PERIODIC_OUTPUT 10000
+#define PERIODIC_OUTPUT 100
#define MAX_SIDES 8
#define MAXWIDTH 4000
#define WIDTH 320
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index 3bef7c6..3013a82 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -155,11 +155,11 @@ c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE
real delta_x=(global.camera.p.x - final.x);//I guess X needs this flippage too.
real delta_y=(global.camera.p.y - final.y);//I dunno. Y is weird.
real delta_z=(final.z - global.camera.p.z);
-// real d=distance3(camera.p,final);
+ //real d=distance3(global.camera.p,final);
p2.x=global.zoom * (delta_x * MAGIC(delta_z) - delta_x);
- p2.y=global.zoom * (delta_y * MAGIC(delta_z) - delta_y);
-// p2.x=global.zoom * (delta_x * MAGIC(delta_z));
-// p2.y=global.zoom * (delta_y * MAGIC(delta_z));//dunno if this is better or not.
+ 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.
return p2;
}
@@ -252,7 +252,7 @@ void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shi
// darker is draw_mode_and(); brighter is draw_mode_or(); lol. set some global? XD hackhackhack
//the color of this shape is set before it gets drawn.
//which is a grey.
- if(s.attrib.col < 16) {
+ if(s.attrib.col < 8) {
set_luminosity_color(s.attrib.lum);
draw_c2_filled_shape(s3);
if(s.attrib.lum > 100) {
@@ -261,7 +261,7 @@ void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shi
draw_mode_and();
}
}
- set_ansi_color(s.attrib.col%16);
+ set_ansi_color(s.attrib.col%8);
draw_c2_filled_shape(s3);
draw_mode_copy();
draw_c2_shape(s3);
@@ -381,23 +381,12 @@ void draw_c3_point_text(c3_t p,char *text) {
XDrawString(global.dpy,global.backbuffer,global.backgc,p2.x,p2.y+(descent+ascent),tmp,strlen(tmp));
}*/
-//push a string back into stdin so it can be read by the file loader. :P
-int selfcommand(char *s) {
- char t;
- if(!strlen(s)) return 0;
- ungetc(s[strlen(s)-1],stdin);
- t=s[strlen(s)-1];
- s[strlen(s)-1]=0;
- selfcommand(s);
- if(global.periodic_output==0) putchar(t);//output commands immediately
- return 0;
-}
#endif
void draw_screen() {
int i;
int cn=0;//camera number.
- char tmp[256];
+ //char tmp[256];
zsort_t zs[SHAPES];
clear_backbuffer();
real oldx=global.camera.p.x;
@@ -437,31 +426,6 @@ void draw_screen() {
if(gra_global.draw3d) {
draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0}); //horizon
}
- if(time(0) == gra_global.oldtime) {
- gra_global.fps++;
- }
- else {
- gra_global.oldtime=time(0);
- gra_global.oldfps=gra_global.fps;
- gra_global.fps=0;
- if(global.debug) {//the way I have text done won't scale...
-// draw_c2_text((cs_t){0,0},global.user);
-// fprintf(stderr,"\x1b[H");
-// fprintf(stderr,"\x1b[2J");
- snprintf(tmp,sizeof(tmp)-1,"debug: %s minimap: %d 3d: %d fps: %d shapes: %d",global.debug?"on":"off",gra_global.drawminimap,gra_global.draw3d,gra_global.oldfps,global.shapes);
- fprintf(stderr,"%s\n",tmp);
-// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+10},tmp);
-// snprintf(tmp,sizeof(tmp)-1,"x: %d y: %d",gra_global.mousex,gra_global.mousey);
- fprintf(stderr,"%s\n",tmp);
-// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp);
- snprintf(tmp,sizeof(tmp)-1,"cx: %f cy: %f cz: %f",global.camera.p.x,global.camera.p.y,global.camera.p.z);
- fprintf(stderr,"%s\n",tmp);
-// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp);
- snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",global.camera.r.x.d,global.camera.r.y.d,global.camera.r.z.d);
- fprintf(stderr,"%s\n",tmp);
-// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp);
- }
- }
///// 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++) {
@@ -517,10 +481,10 @@ void draw_screen() {
//just draw a line from center to 40 away from the center at the angle of the camera's y-rotation
//this should be minimap shit draw_c2_line((c2_t){0,0},rotate_c2((c2_t){40,0},(c2_t){0,0},d2r(global.camera.r.y)));
//draw a line from the center to 80 away from the center in the angle of what should point at the mouse.
- //if(points_on_same_side_of_line((c2_t){gra_global.mousex,gra_global.mousey},(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},cs_to_c2((cs_t){gra_global.mousex,gra_global.mousey}))));
+ //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},cs_to_c2((cs_t){gra_global.mousex,gra_global.mousey}));
+ //draw_c2_line((c2_t){0,0},gra_global.mouse);
global.camera.p.x = oldx;
global.camera.p.z = oldz; //-= cn*CAMERA_SEPARATION;
flipscreen();
@@ -536,8 +500,8 @@ int graphics_init() {
global.shape[0]=0;//we'll allocate as we need more.
global.camera.id=strdup(global.user);//make a copy so if we change global.user later we can reattach to this camera.
- global.group_rot[0]=&global.camera;//why do we have the camera in here? we need to prevent this from getting deleted.
- global.group_rot[1]=0;
+ global.group_rot[0]=&global.camera;
+ global.group_rot[1]=0;//why do we have the camera in here? we need to prevent this from getting deleted.
global.camera.p.x=0;
global.camera.p.y=10;//10 units above the ground should be as low as it goes.
diff --git a/src/graphics_c3.h b/src/graphics_c3.h
index 1406dca..2490e07 100644
--- a/src/graphics_c3.h
+++ b/src/graphics_c3.h
@@ -4,8 +4,7 @@
struct gra_global {
unsigned int width;
unsigned int height;
- int mousex;
- int mousey;
+ c2_t mouse;
int greyscale;
int xoff;
int split_screen;
@@ -15,9 +14,6 @@ struct gra_global {
char red_and_blue;
unsigned int depth;//???
unsigned int border_width;
- int oldtime;
- int fps;
- int oldfps;
char zsort;
char drawminimap;
char input_mode;
@@ -25,9 +21,7 @@ struct gra_global {
char draw3d;
int mapxoff;
int mapyoff;
- int rmousex;
- int rmousey;
- int buttonpressed;
+ int mousemap[10];//you're only going to have 10 buttons on your mouse... right?
int maxshapes;
};
diff --git a/src/graphics_c3_freeglut.c b/src/graphics_c3_freeglut.c
index e4d6cf8..2276aa8 100644
--- a/src/graphics_c3_freeglut.c
+++ b/src/graphics_c3_freeglut.c
@@ -5,6 +5,8 @@
#include <assert.h>
#include <unistd.h>
#include <dirent.h>
+
+#define __USE_MISC //set for random() in stdlib
#include <stdlib.h>
#include <time.h>
@@ -419,6 +421,7 @@ int graphics_sub_init() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);//testing
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);//look up alternatives to all of these functions.
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
@@ -435,8 +438,8 @@ void draw_screen() {//welp... do something here.
glLoadIdentity();//resets the current matrix to default. not translation or rotation will be applied to the shapes going in...
gr=get_group_relative(global.shape[i]->id);
if(gr) {
- glRotatef(gr->r.x
- glTranslatef(gr->p.x + global.camera.p.x , gr->p.y + global.camera.p.y , gr->p.z + global.camera.p.z);
+ //glRotatef(gr->r.x
+ glTranslatef(gr->p.x + global.camera.p.x , global.camera.p.y - gr->p.y , gr->p.z + global.camera.p.z);
} else {
glTranslatef(global.camera.p.x,global.camera.p.y,global.camera.p.z);
}
diff --git a/src/graphics_cs_fb.c b/src/graphics_cs_fb.c
index c123fee..292f7e7 100644
--- a/src/graphics_cs_fb.c
+++ b/src/graphics_cs_fb.c
@@ -66,15 +66,19 @@ void draw_cs_point(int x,int y) {//this should write to a backbuffer then I can
if(x > fb_global.info.xres) return;
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;
+ int derp;
+ derp=(fb_global.current_color == -1) ? (rand()) : fb_global.current_color;
switch(fb_global.draw_mode) {
case DRAW_MODE_COPY:
- fb_global.backbuf[i]=fb_global.current_color;
+ fb_global.backbuf[i] = derp;
break;
case DRAW_MODE_OR:
- fb_global.backbuf[i] |= fb_global.current_color;
+ fb_global.backbuf[i] |= derp;
break;
case DRAW_MODE_AND:
- fb_global.backbuf[i] &= fb_global.current_color;
+ fb_global.backbuf[i] &= derp;
break;
case DRAW_MODE_CLEAR:
fb_global.backbuf[i]=0;
@@ -85,6 +89,10 @@ void draw_cs_point(int x,int y) {//this should write to a backbuffer then I can
}
}
+void draw_cs_arc() {//now... how to draw an arc.
+
+}
+
void draw_cs_line(cs_t p1,cs_t p2) {//error somewhere in here. derp...
int x,y;
real m;
@@ -137,12 +145,12 @@ void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it c
int miny=s.p[0].y;
int maxx=s.p[0].x;
int maxy=s.p[0].y;
- int h;
+ //int h;
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:
//circle
- h=max(s.p[0].x,s.p[1].x)-min(s.p[0].x,s.p[1].x);
+ //h=max(s.p[0].x,s.p[1].x)-min(s.p[0].x,s.p[1].x);
//XDrawArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,s.p[0].x-h,s.p[0].y-h,h*2,h*2,0,360*64);
break;
default:
@@ -151,13 +159,14 @@ void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it c
miny=(s.p[i].y<miny)?s.p[i].y:miny;
maxx=(s.p[i].x>maxx)?s.p[i].x:maxx;
maxy=(s.p[i].y>maxy)?s.p[i].y:maxy;
- draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
+ // draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
}
- if(gra_global.mousex >= minx &&
- gra_global.mousey >= miny &&
- gra_global.mousex <= maxx &&
- gra_global.mousey <= maxy) {
- if(gra_global.buttonpressed) {//if we're inside the bounding box let's make SOMETHING happen.
+ if(gra_global.mouse.x >= minx &&
+ gra_global.mouse.y >= miny &&
+ gra_global.mouse.x <= maxx &&
+ gra_global.mouse.y <= maxy) {
+ if(gra_global.mousemap[0] == -1) {//if we're inside the bounding box let's make SOMETHING happen.
+ gra_global.mousemap[0]=0;
printf("%s action %s\n",global.user,s.id);
}
if(!strncmp(s.id,"term",4)) {
@@ -279,6 +288,10 @@ void red_and_blue_magic() {
// 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() {
+ fb_global.current_color=-1;//kek
+}
+
void set_ansi_color(int i) {
fb_global.current_color=(i&4?0xff0000:0x0) | (i&2 ?0xff00:0x0) | (i&1?0xff:0x0);// :D
}
@@ -320,8 +333,8 @@ void set_demands_attention() {
#endif
-int graphics_sub_init() {
- int i;
+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);
@@ -361,6 +374,7 @@ int graphics_sub_init() {
#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];
@@ -571,7 +585,8 @@ int graphics_event_handler(int world_changed) { //should calling draw_screen be
redraw=1;
}
*/
- if(redraw || world_changed) {
+#endif
+ if(world_changed) {
gra_global.input_mode=0;
draw_screen();//includes its own flip.
}
diff --git a/src/graphics_cs_x11.c b/src/graphics_cs_x11.c
index f17cc5c..4111ae5 100644
--- a/src/graphics_cs_x11.c
+++ b/src/graphics_cs_x11.c
@@ -14,10 +14,13 @@
#include <time.h>
#include "config.h"
+#include "math.h"
#include "common.h"
#include "graphics_c3.h"//not needed?
#include "graphics_x11.h"
#include "graphics_cs.h"
+#include "keyboard_x11.h"
+#include "mouse_x11.h"
//typedef float real; //think this conflicts?
@@ -64,6 +67,9 @@ void set_luminosity_color(int lum) {
void draw_cs_line(cs_t p1,cs_t p2) {
+ if(x11_global.snow) {
+ //manually draw the line with random grey for each pixel
+ }
XDrawLine(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p1.x,p1.y,p2.x,p2.y);
}
@@ -91,8 +97,9 @@ void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it c
//circle
h=max(s.p[0].x,s.p[1].x)-min(s.p[0].x,s.p[1].x);
XDrawArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,s.p[0].x-h,s.p[0].y-h,h*2,h*2,0,360*64);
- if(distance2((c2_t){s.p[0].x,s.p[1].y},(c2_t){gra_global.mousex,gra_global.mousey} ) < h) {
- if(gra_global.buttonpressed) {
+ if(distance2((c2_t){s.p[0].x,s.p[1].y},(c2_t){gra_global.mouse.x,gra_global.mouse.y} ) < h) {
+ if(gra_global.mousemap[0]==-1) {
+ gra_global.mousemap[0]=0;
printf("%s action %s\n",global.user,s.id);
}
XDrawArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,s.p[0].x-h-2,s.p[0].y-h-2,h*2+4,h*2+4,0,360*64);
@@ -106,11 +113,12 @@ void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it c
maxy=(s.p[i].y>maxy)?s.p[i].y:maxy;
draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
}
- if(gra_global.mousex >= minx &&
- gra_global.mousey >= miny &&
- gra_global.mousex <= maxx &&
- gra_global.mousey <= maxy) {
- if(gra_global.buttonpressed) {//if we're inside the bounding box let's make SOMETHING happen.
+ if(gra_global.mouse.x >= minx &&
+ gra_global.mouse.y >= miny &&
+ gra_global.mouse.x <= maxx &&
+ gra_global.mouse.y <= maxy) {
+ if(gra_global.mousemap[0]==-1) {//if we're inside the bounding box let's make SOMETHING happen.
+ gra_global.mousemap[0]=0;
printf("%s action %s\n",global.user,s.id);
}
if(!strncmp(s.id,"term",4)) {
@@ -192,6 +200,10 @@ void red_and_blue_magic() {
// 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) {
XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.ansi_color[i].pixel);
}
@@ -231,6 +243,7 @@ void set_demands_attention() {
XFree(hints);
}
+/* this needs to be removed.
void x11_keypress_handler(XKeyEvent *xkey,int x,int y) {
char line[2048];
char line2[1025];
@@ -239,6 +252,7 @@ void x11_keypress_handler(XKeyEvent *xkey,int x,int y) {
radians tmprad2;
real tmpx;
int i;
+ c3_group_rot_t *gr;
int sym=XLookupKeysym(xkey,0);
real tmpz;
switch(gra_global.input_mode) {
@@ -265,6 +279,14 @@ void x11_keypress_handler(XKeyEvent *xkey,int x,int y) {
snprintf(line,sizeof(line)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
selfcommand(line);
break;
+ case XK_space://jump
+ gr=get_group_relative(global.camera.id);
+ if(gr) {
+ gr->v.y=-5;//10 meter jump? too high for my liking.
+ } else {
+ fprintf(stderr,"# camera doesn't have a group relative!!! can't jump. :/\n");
+ }
+ break;
case XK_Left:
tmprad=d2r((degrees){global.camera.r.y.d+90});
tmprad2=d2r((degrees){global.camera.r.y.d+90});
@@ -348,6 +370,7 @@ void x11_keypress_handler(XKeyEvent *xkey,int x,int y) {
gra_global.draw3d %= 4;
break;
case XK_Escape:
+ fprintf(stderr,"# hackvr exiting.\n");
exit(0);
default:
break;
@@ -385,6 +408,7 @@ void x11_keypress_handler(XKeyEvent *xkey,int x,int y) {
break;
}
}
+*/
#endif
int graphics_sub_init() {
@@ -393,8 +417,8 @@ int graphics_sub_init() {
char tmp[64];
Cursor cursor;
XSetWindowAttributes attributes;
-// Window root,child;//why do I have this?
// XColor toss;
+ x11_global.snow=0;
fprintf(stderr,"# Opening X Display... (%s)\n",getenv("DISPLAY"));
if((x11_global.dpy = XOpenDisplay(0)) == NULL) {
fprintf(stderr,"# failure.\n");
@@ -422,7 +446,7 @@ int graphics_sub_init() {
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);
set_aspect_ratio();
- XSelectInput(x11_global.dpy, x11_global.w, PointerMotionMask|StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|KeyPressMask|ExposureMask);
+ 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);
XStoreName(x11_global.dpy,x11_global.w,"hackvr");
@@ -472,42 +496,25 @@ int graphics_sub_init() {
int graphics_event_handler(int world_changed) { //should calling draw_screen be in here?
int redraw=0;
+ Window root;//just used to sponge up a return value
XEvent e;
- Window child,root;
- //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;
+ 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:
+// 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))) {
+
+//These are all window events.
+ 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)));
@@ -521,26 +528,16 @@ int graphics_event_handler(int world_changed) { //should calling draw_screen be
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;
-// global.camera.r.x.d=gra_global.mousey - (HEIGHT/2);
-// global.camera.r.y.d=gra_global.mousex - (LEFT/2);
- }
//redraw=1;//meh.
if(redraw || world_changed) {
gra_global.input_mode=0;
- draw_screen();
+ draw_screen();//should this be in here? :?
}
return redraw;
}
diff --git a/src/graphics_x11.h b/src/graphics_x11.h
index 7d123a8..38f5737 100644
--- a/src/graphics_x11.h
+++ b/src/graphics_x11.h
@@ -3,6 +3,8 @@
#include <X11/Xlib.h>
+#define HV_GRAPHICS_X11_EVENT_MASK StructureNotifyMask|ExposureMask
+
struct x11_global {//stores global variables for the x11 *specific* shit.
XColor colors[256];
XColor ansi_color[16];
@@ -17,6 +19,8 @@ struct x11_global {//stores global variables for the x11 *specific* shit.
Pixmap cleanbackbuffer;
GC gc;
GC backgc;
+ char snow;
+ cs_t rootmouse;
int root_window;
};
diff --git a/src/hackvr b/src/hackvr
index 919b697..1c9d16c 100755
--- a/src/hackvr
+++ b/src/hackvr
@@ -1,4 +1,7 @@
#!/bin/sh
+if [ "_$HACKVR" != "_" -a "_$HACKVR" != "_$0" ];then
+ exec $HACKVR $*
+fi
if [ $DISPLAY ]; then
exec hackvr_x11 $*
else
diff --git a/src/hackvr.c b/src/hackvr.c
index f3df371..a6b31b4 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -8,10 +8,13 @@
#include <sys/select.h> //code to use select instead of non-blocking is commented out. might decide to use it later.
#include <time.h>
#include <math.h>
+#include <errno.h>
#include "config.h"
#include "common.h"
#include "math.h"
+#include "physics.h"
+#include "input.h" //just the input handler function definitions.
#ifdef GRAPHICAL
#include "graphics_c3.h"
extern struct gra_global gra_global;
@@ -34,13 +37,21 @@ struct global global;
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:
- return 0;
+ 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;
@@ -48,6 +59,17 @@ char *read_line_hack(FILE *fp,int len) {
return t;
}
+int selfcommand(char *s) {
+ char t;
+ if(!strlen(s)) return 0;
+ ungetc(s[strlen(s)-1],stdin);
+ t=s[strlen(s)-1];
+ s[strlen(s)-1]=0;
+ selfcommand(s);
+ if(global.periodic_output==0) putchar(t);//output commands immediately
+ return 0;
+}
+
//warning: clobbers input
//skips leading and trailing space.
//compresses multiple spaces to one.
@@ -92,6 +114,13 @@ int glob_match(char *a,char *b) {
int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, and 1 to ask for redraw
// struct c3_shape s;
// struct c3_line l;
+//move UP, DOWN, LEFT, RIGHT etc shit
+ radians tmprady;
+ //radians tmpradx,tmprady,tmpradz;
+ real tmpx,tmpy,tmpz;
+ char tmp[256];
+//^ there
+
c3_group_rot_t *gr;
char *command;
char *line=0;
@@ -165,7 +194,7 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw,
fprintf(stderr,"# export grou*\n");
fprintf(stderr,"# * scaleup x y z\n");
fprintf(stderr,"# * move x y z\n");
- fprintf(stderr,"# * move forward|backward|left|right\n");
+ fprintf(stderr,"# * move forward|backward|up|down|left|right\n");
fprintf(stderr,"# that is all.\n");
continue;
} else {
@@ -191,7 +220,7 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw,
}
ret=1;
//now do the same stuff but for the group_rot structs.
- for(j=1;global.group_rot[j] && j < MAXSHAPES;j++) {//start at 1 so we skip the camera.
+ for(j=1;global.group_rot[j] && j < MAXSHAPES;j++) {//start at 1 so we skip the camera. fuck it. let's delete camera.
if(glob_match(a[2],global.group_rot[j]->id)) {
free(global.group_rot[j]->id);
free(global.group_rot[j]);
@@ -295,10 +324,8 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw,
continue;
}
if(!strcmp(command,"status")) {
-#ifdef GRAPHICAL
- fprintf(stderr,"# fps: %d\n",gra_global.fps);
+ fprintf(stderr,"# loops per second: %d\n",global.lps);
continue;
-#endif
}
if(!strcmp(command,"dump")) {//same as debug output... and the periodic data.
printf("%s set global.camera.p.x %f\n",global.user,global.camera.p.x);
@@ -473,21 +500,33 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw,
global.group_rot[i]->p.z=(a[4][0]=='+'?global.group_rot[i]->p.z:0)+strtold(a[4]+(a[4][0]=='+'),0);
}
else if(len > 2) {
+ tmpy=0;
if(!strcmp(a[2],"forward")) {
- //global.
+ tmprady=d2r((degrees){global.camera.r.y.d});
+ //snprintf(tmp,sizeof(tmp)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
} else if(!strcmp(a[2],"backward")) {
-
+ tmprady=d2r((degrees){global.camera.r.y.d+180});
+ //snprintf(tmp,sizeof(tmp)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
} else if(!strcmp(a[2],"up")) {
-
+ tmprady=d2r((degrees){global.camera.r.y.d});//doesn't matter.
+ tmpy=WALK_SPEED*1;
} else if(!strcmp(a[2],"down")) {
-
+ tmprady=d2r((degrees){global.camera.r.y.d});//doesn't matter. yet.
+ tmpy=WALK_SPEED*1;
} else if(!strcmp(a[2],"left")) {
-
+ tmprady=d2r((degrees){global.camera.r.y.d+90});
+ //snprintf(tmp,sizeof(tmp)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
} else if(!strcmp(a[2],"right")) {
-
+ tmprady=d2r((degrees){global.camera.r.y.d+270});
+ //snprintf(tmp,sizeof(tmp)-1,"%s move +%f +0 +%f\n",global.user,tmpx,tmpz);
} else {
fprintf(stderr,"# dunno what direction you're talking about. try up, down, left, right, forward, or backward\n");
+ continue;
}
+ tmpx=WALK_SPEED*sin(tmprady.r);//the camera's y rotation.
+ tmpz=WALK_SPEED*cos(tmprady.r);//these are only based on
+ snprintf(tmp,sizeof(tmp)-1,"%s move +%f +%f +%f\n",global.user,tmpx,tmpy,tmpz);
+ selfcommand(tmp);
} else {
fprintf(stderr,"# ERROR: wrong amount of parts for move. got: %d expected: 4 or 2\n",len);
}
@@ -512,14 +551,25 @@ int export_file(FILE *fp) {//not used yet. maybe export in obj optionally? no. t
int main(int argc,char *argv[]) {
char redraw;
+ time_t oldtime;
+ unsigned int lps;
c3_t old_p;
c3_rot_t old_r;
- if(argc < 2) {
- fprintf(stderr,"usage: hackvr yourname < from_others > to_others\n");
- return 1;
- } else {
- global.user=strdup(argv[1]);
+ if(argc == 2) {
+ if(!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help")) {
+ printf("usage: hackvr file1 file2 file3 ... fileN < from_others > to_others\n");
+ return 0;
+ }
+ }
+ if(argc == 1) {
+ //we're just doing stdin
+ }
+ if(argc > 1) {
+ //open every argument and add it to list of files to read..
+ //I could just read
}
+ global.user=getenv("USER");
+
fcntl(1,F_SETFL,O_NONBLOCK);//won't work
setbuf(stdin,0);
setbuf(stdout,0);
@@ -530,8 +580,8 @@ int main(int argc,char *argv[]) {
graphics_init();
#endif
fprintf(stderr,"# entering main loop\n");
- for(;;) {
- switch(redraw=load_stdin()) {
+ for(lps=0;;lps++) {
+ switch(redraw=load_stdin()) {//this needs to loop over all opened files.
case -1:
return 0;
break;
@@ -540,7 +590,20 @@ int main(int argc,char *argv[]) {
default:
break;
}
- if(global.periodic_output == 1) {//this is the same type of thing the debug output does.
+ if(time(0) != oldtime) {
+ global.lps=lps;
+ lps=0;
+ oldtime=time(0);
+ }
+ //fprintf(stderr,"# applying physics...\n");
+ redraw |= apply_physics();
+ //fprintf(stderr,"# derping.\n");
+ if(global.periodic_output == 1) {//this is the same type of thing the debug output does. debug output now goes here.
+#ifdef GRAPHICAL
+ printf("# loops per second: %d mouse.x: %f mouse.y: %f\n",global.lps,gra_global.mouse.x,gra_global.mouse.y);
+#else
+ printf("# loops per second: %d\n",global.lps);
+#endif
global.periodic_output = PERIODIC_OUTPUT;
//output any difference between current camera's state
//and the camera state the last time we output it.
@@ -559,8 +622,9 @@ int main(int argc,char *argv[]) {
}
global.periodic_output--;
#ifdef GRAPHICAL
- //input_event_handler();//keyboard, mouse AND joysticks all at once?
- graphics_event_handler(redraw);//this thing should call draw_screen when it needs to.
+ if(graphics_event_handler(redraw) == -1) break;//this thing should call draw_screen when it needs to.
+ if(mouse_event_handler() == -1) break;
+ if(keyboard_event_handler() == -1) break;
#endif
sleep(.01);
}
diff --git a/src/math.c b/src/math.c
index c016744..0dd46e8 100644
--- a/src/math.c
+++ b/src/math.c
@@ -5,7 +5,7 @@
extern struct global global;
//might change this to use hashtables for faster lookups.
-c3_group_rot_t *get_group_relative(char *id) {
+c3_group_rot_t *get_group_relative(char *id) {//crashes in here somehwere...
int i;
for(i=0;global.group_rot[i];i++) {
if(!strcmp(global.group_rot[i]->id,id)) {//should I use glob here and return an array?
diff --git a/src/slowcat.c b/src/slowcat.c
index 305c0d8..24c9b3b 100644
--- a/src/slowcat.c
+++ b/src/slowcat.c
@@ -1,5 +1,6 @@
#define _DEFAULT_SOURCE
#include <stdio.h>
+#include <string.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/src/testit.sh b/src/testit.sh
index 7932862..441903f 100755
--- a/src/testit.sh
+++ b/src/testit.sh
@@ -5,4 +5,4 @@
# <(echo "woman2 move -10 0 -200") \
# <(sort -R ../meshes/female_basemesh1_2.hackvr | sed 's/woman/woamn3/g') | ./slowcat 10000 | ./hackvr_opengl $USER
#../tools/obj2hackvr.pl woman ../meshes/female_basemesh1_2.obj | ./hackvr_opengl epoch
-cat <(../tools/obj2hackvr2.pl woman ../meshes/female_basemesh1_2.obj ) <(echo woman rotate 0 180 0) /dev/stdin | ./hackvr_x11 epoch
+cat <(../tools/obj2hackvr2.pl woman ../meshes/female_basemesh1_2.obj ) <(echo woman rotate 0 180 0) <(hackvr_x11 woman | tee /dev/stderr) | ./hackvr_freeglut epoch