void UpdateController::moveSnake(Snake &snake) { switch (input) { case KEY_LEFT: snake.movex(-1); break; case KEY_RIGHT: snake.movex(1); break; case KEY_UP: snake.movey(-1); break; case KEY_DOWN: snake.movey(1); break; default: snake.movex(1); } for ( auto iter = coins.begin(), endPtr = coins.end() ; iter != endPtr ; ++iter ) { if (snake.headLiesOn(iter->getxy())) { snake.grow(iter->getvalue()); coinMutex.lock(); *iter = Coin(getFreeCoord()); coinMutex.unlock(); break; } } auto head = snake.getHead(); if (snake.bitItself() || !map.contains(head) || snakeWallCollision()) { stop(); } }
void mbesselmodall (header *hdx) { header *st=hdx,*hd=nextof(hdx); double bj,by,bdj,bdy; hd=getvalue(hd); if (error) return; hdx=getvalue(hdx); if (error) return; if (hd->type!=s_real || hdx->type!=s_real) wrong_arg_in("besselmodall"); bessik(*realof(hd),*realof(hdx),&bj,&by,&bdj,&bdy); if (error) return; newram=(char *)st; new_real(bj,""); if (error) return; new_real(by,""); if (error) return; new_real(bdj,""); if (error) return; new_real(bdy,""); }
void EquipmentData::toObj(json_spirit::Object& eq) { eq.push_back( Pair("id", id) ); eq.push_back( Pair("name", name()) ); eq.push_back( Pair("spic", baseid) ); eq.push_back( Pair("type", type) ); eq.push_back( Pair("level", qLevel) ); eq.push_back( Pair("maxLevel", quality*20) ); int cur = getvalue(); int add2 = 0; int add = equipmentUpgrade::getInstance()->getUpgradeValue(up_quality, type, qLevel + 1, add2); eq.push_back( Pair("addNums", cur) ); eq.push_back( Pair("nextNums", cur + add) ); if (add2 > 0) { int cur2 = getvalue2(); eq.push_back( Pair("addNums2", cur2) ); eq.push_back( Pair("nextNums2", cur2 + add2) ); } eq.push_back( Pair("quality", quality) ); eq.push_back( Pair("up_quality", up_quality) ); eq.push_back( Pair("price", sellPrice()) ); eq.push_back( Pair("memo", memo()) ); if (baseEq.get()) { eq.push_back( Pair("needLevel", baseEq->needLevel) ); } }
void mzeros (header *hd) { header *st=hd,*result; int r,c; double *m; hd=getvalue(hd); if (error) return; if (hd->type==s_matrix) { make_complex(st); if (error) return; hd=getvalue(st); if (error) return; } if (hd->type!=s_cmatrix || dimsof(hd)->r!=1 || dimsof(hd)->c<2) { output("Need a complex polynomial\n"); error=300; return; } getmatrix(hd,&r,&c,&m); result=new_cmatrix(1,c-1,""); if (error) return; bauhuber(m,c-1,matrixof(result),1,0,0); moveresult(st,result); }
void mgetvector (header *hd) { header *st=hd,*result; int i,c,n,negative; double *m; hd=getvalue(hd); if (error) return; if (hd->type!=s_real) wrong_arg_in("getvector"); if (!fa) return; n=(unsigned int) *realof(hd); result=new_matrix(1,n,""); if (error) return; m=matrixof(result); for (i=0; i<n; i++) { another: c=getc(fa); if (c==EOF || feof(fa)) break; if (c=='-') { negative=1; c=getc(fa); if (c==EOF) break; } else negative=0; if (!isdigit(c)) goto another; ungetc(c,fa); fscanf(fa,"%lg",m); if (negative) *m=-*m; m++; } c=i; for (; i<n; i++) *m++=0.0; moveresult(st,result); new_real(c,""); }
/* xleval - evaluate an xlisp expression (checking for *evalhook*) */ LVAL xleval(LVAL expr) { /* check for control codes */ if (--xlsample <= 0) { xlsample = SAMPLE; oscheck(); } /* check for *evalhook* */ if (getvalue(s_evalhook)) return (evalhook(expr)); /* check for nil */ if (null(expr)) return (NIL); /* dispatch on the node type */ switch (ntype(expr)) { case CONS: return (evform(expr)); case SYMBOL: return (xlgetvalue(expr)); default: return (expr); } }
/* xlenter - enter a symbol into the obarray */ NODE *xlenter(char *name,int type) { NODE ***oldstk,*sym __HEAPIFY,*array; int i; /* check for nil */ if (strcmp(name,"NIL") == 0) return (NIL); /* check for symbol already in table */ array = getvalue(obarray); i = hash(name,HSIZE); for (sym = getelement(array,i); sym; sym = cdr(sym)) if (strcmp(name,getstring(getpname(car(sym)))) == 0) return (car(sym)); /* make a new symbol node and link it into the list */ oldstk = xlsave1(&sym); sym = consd(getelement(array,i)); rplaca(sym,xlmakesym(name,type)); setelement(array,i,sym); xlstack = oldstk; /* return the new symbol */ return (car(sym)); }
void mstore (header *hd) { FILE *file; ptyp p; hd=getvalue(hd); if (error) return; if (hd->type!=s_string) { output("Expect file name.\n"); error=1100; return; } p.udfend=udfend-ramstart; p.startlocal=startlocal-ramstart; p.endlocal=endlocal-ramstart; p.newram=newram-ramstart; file=fopen(stringof(hd),"wb"); if (!file) { output1("Could not open %s.\n",stringof(hd)); error=1101; return; } fwrite(&p,sizeof(ptyp),1,file); fwrite(ramstart,1,newram-ramstart,file); if (ferror(file)) { output("Write error.\n"); error=1102; return; } fclose(file); }
/* * Get a number from a variable. * Try to be clever about reusing subscripts by caching the Value structure. */ static mnumber getmathparam(struct mathvalue *mptr) { mnumber result; if (!mptr->pval) { char *s = mptr->lval; mptr->pval = (Value)zhalloc(sizeof(struct value)); if (!getvalue(mptr->pval, &s, 1)) { mptr->pval = NULL; if (isset(FORCEFLOAT)) { result.type = MN_FLOAT; result.u.d = 0.0; return result; } return zero_mnumber; } } result = getnumvalue(mptr->pval); if (isset(FORCEFLOAT) && result.type == MN_INTEGER) { result.type = MN_FLOAT; result.u.d = (double)result.u.l; } return result; }
LVAL xssystem() { char *cmd; int status; LVAL stream = NIL; FILE *p; int ch; cmd = (char *) getstring(xlgastring()); if (moreargs()) { stream = xlgetarg(); if (stream == s_true) stream = getvalue(s_stdout); else if (!streamp(stream) && !ustreamp(stream)) xlbadtype(stream); } if (stream == NIL) { status = system(cmd); if (status == 127) xlfail("shell could not execute command"); } else { if ((p = popen(cmd, "r")) == NULL) xlfail("could not execute command"); while ((ch = getc(p)) != EOF) xlputc(stream, ch); status = pclose(p); } return(cvfixnum((FIXTYPE) status)); }
void compflush(Obj p){ Obj cp = CDR(p); int i, l; switch (SUBSUBPORT(p)){ case COMP_T: case COMP_ECHO: case COMP_2WAY: Fflush( CAR(cp)); Fflush( CDR(cp)); break; case COMP_CONCAT: Fflush( CAR(cp)); break; case COMP_BCAST: l = CLENGTH(cp); for(i=0; i<l; i++) Fflush( CVECTOR(cp)[i] ); break; case COMP_SYNO: Fflush( getvalue(cp)); break; case COMP_FUNC: funcall_0("#<internal:compflush>", CVECTOR(cp)[2]); break; default: break; } }
/* composite ports */ void compputc(Obj p, int c){ int i, l; Obj cp = CDR(p); switch (SUBSUBPORT(p)){ case COMP_T: writechar( CAR( cp ), c); writechar( CDR( cp ), c); break; case COMP_BCAST: l = CLENGTH(cp); for(i=0; i<l; i++) writechar( CVECTOR(cp)[i], c); break; case COMP_ECHO: case COMP_2WAY: writechar( CDR(cp), c); break; case COMP_SYNO: Fputc( MAKCHAR(c), getvalue(cp) ); break; case COMP_FUNC: funcall_1("#<internal:compputc>", CVECTOR(cp)[1], MAKCHAR(c)); break; default: break; } }
/* xleval - evaluate an xlisp expression (checking for *evalhook*) */ NODE *xleval(NODE *expr) { /* check for control codes */ if (--xlsample <= 0) { xlsample = SAMPLE; oscheck(); } /* check for *evalhook* */ if (getvalue(s_evalhook)) return (evalhook(expr)); /* add trace entry */ if (++xltrace < TDEPTH) trace_stack[xltrace] = expr; /* check type of value */ if (consp(expr)) expr = evform(expr); else if (symbolp(expr)) expr = xlgetvalue(expr); /* remove trace entry */ --xltrace; /* return the value */ return (expr); }
// --------------------------------------------------------------------------- // // ----------- void bLessThanElement::init(void* ctx){ _ctx=(bSelectSolver*)ctx; bStdXMLGeog::init(ctx); char val[_values_length_max_]; bGenericXMLBaseElement* elt=getelement(1); if(elt){ elt->getvalue(val); } else{ getvalue(val); } _dst=atof(val); _ctx->set_preprocess(); bArray* src=_ctx->get_source(); bGenericGeoIterator* it=_ctx->get_type()->iterator(); for(int i=1;i<=src->count();i++){ src->get(i,&_ref); _ref->getBounds(&_vxr); _vxr.top-=round(_dst); _vxr.left-=round(_dst); _vxr.bottom+=round(_dst); _vxr.right+=round(_dst); it->iterate(&_vxr,this,process); } }
int ctest (header *hd) /**** ctest test, if a matrix contains nonzero elements. ****/ { double *m; LONG n,i; hd=getvalue(hd); if (error) return 0; if (hd->type==s_string) return (*stringof(hd)!=0); if (hd->type==s_real) return (*realof(hd)!=0.0); if (hd->type==s_complex) return (*realof(hd)!=0.0 && *imagof(hd)!=0.0); if (hd->type==s_matrix) { n=(LONG)(dimsof(hd)->r)*dimsof(hd)->c; m=matrixof(hd); for (i=0; i<n; i++) if (*m++==0.0) return 0; return 1; } if (hd->type==s_cmatrix) { n=(LONG)(dimsof(hd)->r)*dimsof(hd)->c; m=matrixof(hd); for (i=0; i<n; i++) { if (*m==0.0 && *m==0.0) return 0; m+=2; } return 1; } return 0; }
char * getcgivar(char *cgistring, char *param) { register int i; char *result = NULL; char cgiinput[BUFFER_LEN]; static char result2[BUFFER_LEN]; char *nvpair; strcpy(cgiinput, cgistring); /** Change all plusses back to spaces **/ for (i = 0; cgiinput[i]; i++) if (cgiinput[i] == '+') cgiinput[i] = ' '; nvpair = strtok(cgiinput, "&"); while (nvpair) { char *test = getparam(nvpair); if (!vcSTRCASECMP(test, param)) { result = getvalue(nvpair); free((void *) test); break; } free((void *) test); nvpair = strtok(NULL, "&"); } unescape_url(result); strcpy(result2, result); free((void *) result); return (result2); }
LVAL xlc_snd_save(void) { LVAL arg1 = xlgetarg(); long arg2 = getfixnum(xlgafixnum()); unsigned char * arg3 = getstring(xlgastring()); long arg4 = getfixnum(xlgafixnum()); long arg5 = getfixnum(xlgafixnum()); long arg6 = getfixnum(xlgafixnum()); long arg7 = getfixnum(xlgafixnum()); double arg8 = 0.0; long arg9 = 0; double arg10 = 0.0; LVAL arg11 = xlgetarg(); double result; xllastarg(); result = sound_save(arg1, arg2, arg3, arg4, arg5, arg6, arg7, &arg8, &arg9, &arg10, arg11); { LVAL *next = &getvalue(RSLT_sym); *next = cons(NIL, NIL); car(*next) = cvflonum(arg8); next = &cdr(*next); *next = cons(NIL, NIL); car(*next) = cvfixnum(arg9); next = &cdr(*next); *next = cons(NIL, NIL); car(*next) = cvflonum(arg10); } return cvflonum(result); }
void mbetai (header *hd) { header *result,*st=hd,*hda,*hdb; double x; hda=nextof(hd); hdb=nextof(hda); hd=getvalue(hd); if (error) return; hda=getvalue(hda); if (error) return; hdb=getvalue(hdb); if (error) return; if (hd->type!=s_real || hda->type!=s_real || hdb->type!=s_real) wrong_arg_in("betai"); x=betai(*realof(hd),*realof(hda),*realof(hdb)); if (error) return; result=new_real(x,""); if (error) return; moveresult(st,result); }
/* xlenter - enter a symbol into the obarray */ LVAL xlenter(char *name) { LVAL sym,array; int i; /* check for nil */ if (strcmp(name,"NIL") == 0) return (NIL); /* check for symbol already in table */ array = getvalue(obarray); i = hash(name,HSIZE); for (sym = getelement(array,i); sym; sym = cdr(sym)) if (strcmp(name,(char *) getstring(getpname(car(sym)))) == 0) return (car(sym)); /* make a new symbol node and link it into the list */ xlsave1(sym); sym = consd(getelement(array,i)); rplaca(sym,xlmakesym(name)); setelement(array,i,sym); xlpop(); /* return the new symbol */ return (car(sym)); }
// --------------------------------------------------------------------------- // // ----------- bool bPDFDocumentElement::actionstd(bGenericGraphicContext* ctx){ char val[_values_length_max_]; if(objectcompliant()){ bStdXMLValueElement* elt=find_value(); if(elt==NULL){ return(true); } elt->getvalue(NULL,val); } else{ getvalue(val); } if(_data==NULL){ if(strlen(val)==0){ if(_ispdf){ ctx->setPDF(NULL,0,""); } else{ ctx->setImage(NULL,0,""); } return(objectcompliant()); } if(_tp){ if(!_tp->fields()->get_param("icons",val,&_data,&_sz)){ if(_ispdf){ ctx->setPDF(NULL,0,""); } else{ ctx->setImage(NULL,0,""); } return(false); } // on pourrait chercher ailleurs } else{ if(!_gapp->document()->readParam(&_data,&_sz,"icons",val)){ if(_ispdf){ ctx->setPDF(NULL,0,""); } else{ ctx->setImage(NULL,0,""); } return(false); } // on pourrait chercher ailleurs } strcpy(_last,val); } _ispdf=(GetImageKind(val)==kQTFileTypePDF); if(_ispdf){ ctx->setPDF(_data,_sz,val); } else{ ctx->setImage(_data,_sz,val); } if(_data==NULL){ return(objectcompliant()); } return(true); }
void mrestore (header *hd) { FILE *file; ptyp p; if (udfon) { output("Cannot restore inside a UDF.\n"); error=1; return; } hd=getvalue(hd); if (error) return; if (hd->type!=s_string) { output("Expect file name.\n"); error=1100; return; } file=fopen(stringof(hd),"rb"); if (!file) { output1("Could not open %s.\n",stringof(hd)); error=1103; return; } fread(&p,sizeof(ptyp),1,file); if (ferror(file)) { output("Read error.\n"); error=1104; return; } fread(ramstart,1,p.newram,file); if (ferror(file)) { output("Read error (fatal for EULER).\n"); error=1104; return; } fclose(file); udfend=ramstart+p.udfend; startlocal=ramstart+p.startlocal; endlocal=ramstart+p.endlocal; newram=ramstart+p.newram; next=input_line; *next=0; }
/* defmacro - define a read macro */ void defmacro(int ch, LVAL type, int offset) { extern FUNDEF funtab[]; LVAL subr; subr = cvsubr(funtab[offset].fd_subr,funtab[offset].fd_type,offset); setelement(getvalue(s_rtable),ch,cons(type,subr)); }
/* evalhook - call the evalhook function */ LOCAL LVAL evalhook(LVAL expr) { LVAL *newfp,olddenv,val; /* create the new call frame */ newfp = xlsp; pusharg(cvfixnum((FIXTYPE)(newfp - xlfp))); pusharg(getvalue(s_evalhook)); pusharg(cvfixnum((FIXTYPE)2)); pusharg(expr); pusharg(cons(xlenv,xlfenv)); xlfp = newfp; /* rebind the hook functions to nil */ olddenv = xldenv; xldbind(s_evalhook,NIL); xldbind(s_applyhook,NIL); /* call the hook function */ val = xlapply(2); /* unbind the symbols */ xlunbind(olddenv); /* return the value */ return (val); }
void polytrunc (header *hd) { header *st=hd,*result; double *m; complex *mc; int i; hd=getvalue(hd); if (error) return; if (hd->type==s_matrix && dimsof(hd)->r==1) { m=matrixof(hd); for (i=dimsof(hd)->c-1; i>=0; i--) { if (fabs(m[i])>epsilon) break; } if (i<0) result=new_real(0.0,""); else { result=new_matrix(1,i+1,""); memmove((char *)matrixof(result),(char *)matrixof(hd), (i+1)*sizeof(double)); } } else if (hd->type==s_complex && dimsof(hd)->r==1) { mc=(complex *)matrixof(hd); for (i=dimsof(hd)->c-1; i>=0; i--) { if (fabs(mc[i][0])>epsilon && fabs(mc[i][1])>epsilon) break; } if (i<0) result=new_complex(0.0,0.0,""); else { result=new_cmatrix(1,i+1,""); memmove((char *)matrixof(result),(char *)matrixof(hd), (i+1)*sizeof(complex)); } } else wrong_arg(); moveresult(st,result); }
void mopen (header *hd) { header *st=hd,*hd1,*result; if (fa) fclose(fa); hd1=nextof(hd); hd=getvalue(hd); if (error) return; hd1=getvalue(hd1); if (error) return; if (hd->type!=s_string || hd1->type!=s_string) wrong_arg_in("open"); fa=fopen(stringof(hd),stringof(hd1)); if (!fa) { error=1; output("Could not open the file!\n"); return; } result=new_real((double)ferror(fa),""); if (error) return; moveresult(st,result); }
// --------------------------------------------------------------------------- // // ----------- bool bFillPatternElement::actionstd(bGenericGraphicContext* ctx){ char val[_values_length_max_]; ctx->setColorLevel(_fill); ctx->setAlpha(1); if(objectcompliant()){ bStdXMLValueElement* elt=find_value(); if(elt==NULL){ return(true); } elt->getvalue(NULL,val); } else{ getvalue(val); } if(_data==NULL){ if(strlen(val)==0){ ctx->setFillPattern(NULL,0,""); return(objectcompliant()); } if(!_tp->fields()->get_param("patterns",val,&_data,&_sz)){ ctx->setFillPattern(NULL,0,""); return(objectcompliant()); } strcpy(_last,val); } ctx->setFillPattern(_data,_sz,val); if(_data==NULL){ return(objectcompliant()); } return(true); }
// Make a copy of the original obarray, leaving the original in place LOCAL void nyx_save_obarray() { LVAL newarray; int i; // This provide permanent protection for nyx_obarray as we do not want it // to be garbage-collected. xlprot1(nyx_obarray); nyx_obarray = getvalue(obarray); // Create and set the new vector. This allows us to use xlenter() to // properly add the new symbol. Probably slower than adding directly, // but guarantees proper hashing. newarray = newvector(HSIZE); setvalue(obarray, newarray); // Scan all obarray vectors for (i = 0; i < HSIZE; i++) { LVAL sym; // Scan all elements for (sym = getelement(nyx_obarray, i); sym; sym = cdr(sym)) { LVAL syma = car(sym); char *name = (char *) getstring(getpname(syma)); LVAL nsym = xlenter(name); // Ignore *OBARRAY* since there's no need to copy it if (strcmp(name, "*OBARRAY*") == 0) { continue; } // Ignore *SCRATCH* since it's allowed to be updated if (strcmp(name, "*SCRATCH*") == 0) { continue; } // Duplicate the symbol's values setvalue(nsym, nyx_dup_value(getvalue(syma))); setplist(nsym, nyx_dup_value(getplist(syma))); setfunction(nsym, nyx_dup_value(getfunction(syma))); } } // Swap the obarrays, so that the original is put back into service setvalue(obarray, nyx_obarray); nyx_obarray = newarray; }
/* xformat - formatted output function */ LVAL xformat(void) { unsigned char *fmt; LVAL stream,val; int ch; /* protect stream in case it is a new ustream */ xlsave1(stream); /* get the stream and format string */ stream = xlgetarg(); if (stream == NIL) val = stream = newustream(); else { if (stream == s_true) stream = getvalue(s_stdout); else if (!streamp(stream) && !ustreamp(stream)) xlbadtype(stream); val = NIL; } fmt = getstring(xlgastring()); /* process the format string */ while ((ch = *fmt++)) if (ch == '~') { switch (*fmt++) { case '\0': xlerror("expecting a format directive",cvstring((char *) (fmt-1))); case 'a': case 'A': xlprint(stream,xlgetarg(),FALSE); break; case 's': case 'S': xlprint(stream,xlgetarg(),TRUE); break; case '%': xlterpri(stream); break; case '~': xlputc(stream,'~'); break; case '\n': case '\r': /* mac may read \r -- this should be ignored */ if (*fmt == '\r') fmt++; while (*fmt && *fmt != '\n' && isspace(*fmt)) ++fmt; break; default: xlerror("unknown format directive",cvstring((char *) (fmt-1))); } } else xlputc(stream,ch); /* return the value */ if (val) val = getstroutput(val); xlpop(); return val; }
/* tentry - get a readtable entry */ LVAL tentry(int ch) { LVAL rtable; rtable = getvalue(s_rtable); if (!vectorp(rtable) || ch < 0 || ch >= getsize(rtable)) return (NIL); return (getelement(rtable,ch)); }
int main(void) { for(int i = 0; i < max_limit; i++) { if (getvalue(i) != limit) { printf("%i is under %u\n", i, limit); } } return EXIT_SUCCESS; }