static int finalize_pfv() { int i; int references[FPVM_MAXBINDINGS]; /* assign dummy values for output */ if(!fpvm_assign(&pfv_fragment, "_Xo", "_Xi")) goto fail_fpvm; if(!fpvm_assign(&pfv_fragment, "_Yo", "_Yi")) goto fail_fpvm; if(!fpvm_finalize(&pfv_fragment)) goto fail_fpvm; #ifdef EVAL_DEBUG printf("EVL: per-frame FPVM fragment:\n"); fpvm_dump(&pfv_fragment); #endif /* Build variable allocation table */ fpvm_get_references(&pfv_fragment, references); for(i=0;i<EVAL_PFV_COUNT;i++) if(references[pfv_preallocation[i]]) pfv_allocation[i] = pfv_preallocation[i]; else pfv_allocation[i] = -1; return 1; fail_fpvm: printf("EVL: failed to finalize per-frame variables: %s\n", pfv_fragment.last_error); return 0; }
static void compile_vm(const char *pgm) { struct fpvm_fragment fragment; struct parser_comm comm = { .u.fragment = &fragment, .assign_default = assign_raw, .assign_per_frame = assign_raw, .assign_per_vertex = assign_raw_fail, .assign_image_name = assign_image_fail, }; int ok; init_fpvm(&fragment, 0); fpvm_set_bind_mode(&fragment, FPVM_BIND_ALL); symtab_init(); ok = parse(pgm, TOK_START_ASSIGN, &comm); if (ok) fpvm_dump(&fragment); symtab_free(); if (ok) return; fflush(stdout); fprintf(stderr, "%s\n", comm.msg); free((void *) comm.msg); exit(1); } /* ----- Command-line processing ------------------------------------------- */ static void free_buffer(void) { free((void *) buffer); }
static int finalize_pvv() { int i; int references[FPVM_MAXBINDINGS]; #define A(dest, val) if(!fpvm_assign(&pvv_fragment, dest, val)) goto fail_assign /* Zoom */ A("_invzoom", "1/zoom"); A("_xz", "_invzoom*(x-0.5)+0.5"); A("_yz", "_invzoom*(y-0.5)+0.5"); /* Scale */ A("_xs", "(_xz-cx)/sx+cx"); A("_ys", "(_yz-cy)/sy+cy"); /* Warp */ A("_warptime", "time*fWarpAnimSpeed"); A("_invwarpscale", "1/fWarpScale"); A("_f0", "11.68 + 4.0*cos(_warptime*1.413 + 10)"); A("_f1", "8.77 + 3.0*cos(_warptime*1.113 + 7)"); A("_f2", "10.54 + 3.0*cos(_warptime*1.233 + 3)"); A("_f3", "11.49 + 4.0*cos(_warptime*0.933 + 5)"); A("_ox2", "2*x-1"); A("_oy2", "2*y-1"); A("_xw", "_xs+warp*0.0035*(" "sin(_warptime*0.333+_invwarpscale*(_ox2*_f0-_oy2*_f3))" "+cos(_warptime*0.753-_invwarpscale*(_ox2*_f1-_oy2*_f2)))"); A("_yw", "_ys+warp*0.0035*(" "cos(_warptime*0.375-_invwarpscale*(_ox2*_f2+_oy2*_f1))" "+sin(_warptime*0.825+_invwarpscale*(_ox2*_f0+_oy2*_f3)))"); /* Rotate */ A("_cosr", "cos(rot)"); A("_sinr", "sin(0-rot)"); A("_u", "_xw-cx"); A("_v", "_yw-cy"); A("_xr", "_u*_cosr-_v*_sinr+cx"); A("_yr", "_u*_sinr+_v*_cosr+cy"); /* Translate */ A("_xd", "_xr-dx"); A("_yd", "_yr-dy"); /* Convert to framebuffer coordinates */ A("_Xo", "f2i(_xd*_texsize)"); A("_Yo", "f2i(_yd*_texsize)"); #undef A if(!fpvm_finalize(&pvv_fragment)) goto fail_finalize; #ifdef EVAL_DEBUG printf("EVL: per-vertex FPVM fragment:\n"); fpvm_dump(&pvv_fragment); #endif /* Build variable allocation table */ fpvm_get_references(&pvv_fragment, references); for(i=0;i<EVAL_PVV_COUNT;i++) if(references[pvv_preallocation[i]]) pvv_allocation[i] = pvv_preallocation[i]; else pvv_allocation[i] = -1; return 1; fail_assign: printf("EVL: failed to add equation to per-vertex footer: %s\n", pvv_fragment.last_error); return 0; fail_finalize: printf("EVL: failed to finalize per-vertex variables: %s\n", pvv_fragment.last_error); return 0; }