summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hackvr.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/hackvr.c b/src/hackvr.c
index 1f64004..56a5f43 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L //for fileno and strdup
+#include <fnmatch.h> //fnmatch() ofc
#include <ctype.h> //isspace
#include <stdio.h>
#include <fcntl.h>
@@ -97,11 +98,14 @@ char **line_splitter(char *line,int *rlen) {
//but the first argument MAY use a simple * glob ONLY at the end.
//this function may be changed to allow globs in different spots later.
int glob_match(char *a,char *b) {
+ return fnmatch(a,b,FNM_NOESCAPE);
+ /*
if(strchr(a,'*')) {
if(*a == '*') return strcmp("yep","yep");//lol
return strncmp(a,b,strchr(a,'*')-a-1);//hack? sure.
}
return strcmp(a,b);
+ */
}
void hvr_version() {
@@ -139,7 +143,7 @@ int hackvr_handler(char *line) {
int len;
int j,i,k,l;
unsigned int key_count;
- c3_group_rel_t *gr,*pgr;
+ c3_group_rel_t *gr,*pgr,*ob;
real tmpx,tmpy,tmpz;
char **a;
char **keys;
@@ -269,10 +273,12 @@ int hackvr_handler(char *line) {
for(i=0;i<key_count;i++) {
if((m=ht_getentry(&global.ht_group,keys[i]))) {
if(m->target != &global.camera) {
- gr=m->target;
- free(gr->id);
- free(gr);
- ht_delete(&global.ht_group,m->original);
+ if(!glob_match(a[2],m->target)) {//make sure to negate it like we would with strcmp
+ gr=m->target;
+ free(gr->id);
+ free(gr);
+ ht_delete(&global.ht_group,m->original);
+ }
}
} else {
fprintf(stderr,"# somehow an item is in the list of keys but ht_getentry failed. '%s'\n",a[2]);
@@ -515,6 +521,43 @@ int hackvr_handler(char *line) {
/* ---------- */
+ if(helping) fprintf(stderr,"# relativeexport grou* observergroup\n");
+ if(!strcmp(command,"relativeexport")) {//dump shapes and group rotation for argument (or all if arg is *)
+ if(len > 3) {
+ ob=get_group_relative(a[3]);
+ for(i=0;global.shape[i];i++) {
+ if(!glob_match(a[2],global.shape[i]->id)) {
+ printf("%s_%s addshape %d %d",id,global.shape[i]->id,global.shape[i]->attrib.col,global.shape[i]->len);
+ for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) {
+ printf(" %f %f %f",global.shape[i]->p[j].x,global.shape[i]->p[j].y,global.shape[i]->p[j].z);
+ }//possible TODO: should I combine the string and output it all at once instead of throughout a loop?
+ printf("\n");
+ }
+ }
+ //so... this might be a bit dense.
+ //the hash table has an array of the filled buckets
+ //and we're looping over all of them.
+ //THEN inside each bucket is a linked list we also have to descend
+ //this all to just find the keys that match a glob.
+ for(i=0;i < global.ht_group.kl;i++) {//for each bucket and item in each bucket...
+ for(m=global.ht_group.bucket[global.ht_group.keys[i]]->ll;m;m=m->next) {
+ if(!glob_match(a[2],m->original)) {
+ gr=m->target;//this almost CERTAINLY exists... I think.
+ printf("%s_%s rotate %d %d %d\n",id,gr->id,gr->r.x.d,gr->r.y.d,gr->r.z.d);//these are world-based... we need "camera"-based
+
+ //printf("%s_%s move %f %f %f\n",id,gr->id,gr->p.x,gr->p.y,gr->p.z);//this need to be based on the observer's rotation?
+ printf("%s_%s move %f %f %f\n",id,gr->id,ob->p.x-gr->p.x,ob->p.y-gr->p.y,ob->p.z-gr->p.z);//this need to be based on the observer's rotation?
+
+ printf("%s_%s scale %f %f %f\n",id,gr->id,gr->s.x,gr->s.y,gr->s.z);
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+
+/* ---------- */
if(helping) fprintf(stderr,"# ping any-string-without-spaces\n");
if(!strcmp(command,"ping")) {//lol wat?
if(len > 2) {
@@ -679,8 +722,10 @@ int hackvr_handler(char *line) {
tmprady=d2r((degrees){global.camera.r.y.d+180});
} else if(!strcmp(a[2],"up")) {
tmprady=(radians){0};
+ tmpy=WALK_SPEED;
} else if(!strcmp(a[2],"down")) {
tmprady=(radians){0};
+ tmpy=-WALK_SPEED;
} else if(!strcmp(a[2],"left")) {
tmprady=d2r((degrees){global.camera.r.y.d+270});
} else if(!strcmp(a[2],"right")) {
@@ -745,6 +790,7 @@ void alarm_handler(int sig) {
}
int main(int argc,char *argv[]) {
+ global.active=strdup("");
global.state=HVR_STATE_INIT;
global.version=HVR_VERSION;
global.title=0;