From 9ddfe0aae19ec13f13da6bfc5dbb18116ab7ac51 Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 19 Dec 2017 04:40:18 -0600 Subject: added support for color, turned printfs of information to fprintf for stderr, did some error handling, actually remove group_rot of shapes... meh. --- src/hackvr.c | 161 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 57 deletions(-) diff --git a/src/hackvr.c b/src/hackvr.c index 30fe173..78a4759 100644 --- a/src/hackvr.c +++ b/src/hackvr.c @@ -100,7 +100,7 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, //FD_SET(0,&master);//just stdin. int i;//used to store the last triangle. even though I have a global for that. >_> -// printf("# entering load_stdin()\n"); +// fprintf(stderr,"# entering load_stdin()\n"); //#ifdef _HACKVR_USE_NONBLOCK_ for(i=0;global.shape[i];i++) ;//hop to the end. fcntl(0,F_SETFL,O_NONBLOCK); @@ -119,7 +119,7 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, //#endif while((line=line?free(line),read_line_hack(stdin,0):read_line_hack(stdin,0))) {//load as long there's something to load if(*line == '#') return 0; -// printf("# read command: %s\n",line); +// fprintf(stderr,"# read command: %s\n",line); if(a) free(a); a=line_splitter(line,&len); // for(i=0;iid,a[2])) {//TODO: memory leak! - //free(global.triangle[j]->id); - //free(global.triangle[j]); + if(strcmp(global.shape[j]->id,a[2])) { + free(global.shape[j]->id); + free(global.shape[j]); global.shape[j]=0; } } - l=0; for(k=0;kid,a[2])) { -// free(global.shape[j]->id); -// free(global.shape[j]); - global.shape[j]=0; + if(!strcmp(command,"deletegroup")) {//should the grouprot get deleted too? sure... + if(len == 3) { + for(j=0;global.shape[j] && j < MAXSHAPES;j++) { + if(!strcmp(global.shape[j]->id,a[2])) { + free(global.shape[j]->id); + free(global.shape[j]); + global.shape[j]=0; + } } + //we now have an array that needs to be compressed. + //max length of j. + //1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,1,0,1,1 + // + for(k=0;kid,a[2])) { + free(global.group_rot[j]->id); + free(global.group_rot[j]); + global.group_rot[j]=0; + } + } + for(k=0;k 3) { - if(len != ((strtold(a[2],0)+(strtold(a[2],0)==1))*3)+3) { - printf("# ERROR: wrong amount of parts for addshape. got: %d expected %d\n",len,((int)strtold(a[2],0)+(strtold(a[2],0)==1))*3+3); + if(len != ((strtold(a[3],0)+(strtold(a[3],0)==1))*3)+4) { + fprintf(stderr,"# ERROR: wrong amount of parts for addshape. got: %d expected %d\n",len,((int)strtold(a[3],0)+(strtold(a[3],0)==1))*3+4); + fprintf(stderr,"# usage: addshape color number x y z x y z repeated number of time.\n"); continue; } - for(i=0;global.shape[i];i++);//just take me to the end. + for(i=0;global.shape[i];i++) { if(i>= MAXSHAPES) abort();}//just take me to the end. global.shape[i]=malloc(sizeof(struct c3_shape)); - global.shape[i]->len=strtold(a[2],0); + global.shape[i]->len=strtold(a[3],0); global.shape[i]->id=strdup(id); + global.shape[i]->attrib.col=strtold(a[2],0); + global.shape[i]->attrib.lum=0; for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) { - global.shape[i]->p[j].x=strtold(a[(j*3)+3],0);//second arg is just for a return value. set to 0 if you don't want it. - global.shape[i]->p[j].y=strtold(a[(j*3)+4],0); - global.shape[i]->p[j].z=strtold(a[(j*3)+5],0); + global.shape[i]->p[j].x=strtold(a[(j*3)+4],0);//second arg is just for a return value. set to 0 if you don't want it. + global.shape[i]->p[j].y=strtold(a[(j*3)+5],0); + global.shape[i]->p[j].z=strtold(a[(j*3)+6],0); } i++; global.shapes=i; global.shape[i]=0; for(i=0;global.group_rot[i];i++) { + if(i >= MAXSHAPES) abort(); if(!strcmp(global.group_rot[i]->id,id)) { break; } @@ -325,8 +355,8 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, if(!strcmp(global.shape[i]->id,id)) { for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) { global.shape[i]->p[j].x*=strtold(a[2],0); - global.shape[i]->p[j].y*=strtold(a[2],0); - global.shape[i]->p[j].z*=strtold(a[2],0); + global.shape[i]->p[j].y*=strtold(len>4?a[3]:a[2],0); + global.shape[i]->p[j].z*=strtold(len>4?a[4]:a[2],0); } } } @@ -374,13 +404,29 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, global.group_rot[i]->p.y+=strtold(a[3],0); global.group_rot[i]->p.z+=strtold(a[4],0); } - else { - printf("# ERROR: wrong amount of parts for move. got: %d expected: 4\n",len); + else if(len > 2) { + if(!strcmp(a[2],"forward")) { + //move id forward based on id's rotation. + } else if(!strcmp(a[2],"backward")) { + + } else if(!strcmp(a[2],"up")) { + + } else if(!strcmp(a[2],"down")) { + + } else if(!strcmp(a[2],"left")) { + + } else if(!strcmp(a[2],"right")) { + + } else { + fprintf(stderr,"# dunno what direction you're talking about. try up, down, left, right, forward, or backward\n"); + } + } else { + fprintf(stderr,"# ERROR: wrong amount of parts for move. got: %d expected: 4 or 2\n",len); } ret=1; continue; } - printf("# I don't know what command you're talking about. %s\n",command); + fprintf(stderr,"# I don't know what command you're talking about. %s\n",command); //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; @@ -408,10 +454,11 @@ int main(int argc,char *argv[]) { setbuf(stdin,0); setbuf(stdout,0); global.debug=DEBUG; + global.beep=0; #ifdef GRAPHICAL graphics_init(); #endif - printf("# entering main loop\n"); + fprintf(stderr,"# entering main loop\n"); for(;;) { switch(redraw=load_stdin()) { case -1: -- cgit v1.2.3