void global_screen_clear() { loopi(0, global_width) loopj(0, global_height) global_screen_set(i, j, ' '); loopj(0, global_height) global_screen[j][global_width]='\n'; loopj(0, global_height) global_screen[j][global_width+1] = 0; global_screen[global_height-1][global_width] = 0; };
void eraseGeometry() { // Clear out map int halfSize = getworldsize()/2; loopi(2) loopj(2) loopk(2) deleteCube(i*halfSize, j*halfSize, k*halfSize, halfSize); }
static void buildfont() { u8 *font = (u8*)MALLOC(fontw*fonth*sizeof(u8)); loopi(fonth) loopj(fontw/32) loopk(32) font[i*fontw+j*32+k] = (fontdata[i*fontw/32+j]&(1<<k))?~0x0:0x0; u32 id = ogl::maketex("TB Ir Dr B2 Wsr Wtr Mn mn", font, fontw, fonth); FREE(font); textfont = id; }
char *conc(char **w, int n, bool space) { int len = space ? max(n-1, 0) : 0; loopj(n) len += (int)strlen(w[j]); char *r = newstring("", len); loopi(n) { strcat(r, w[i]); // make string-list out of all arguments if(i==n-1) break; if(space) strcat(r, " "); } return r; }
void render() { char *refs[ndraw]; const int nd = conlinenum(refs); // console output const auto font = text::fontdim(); text::displaywidth(font.x); loopj(nd) text::draw(refs[j], font.x, float(sys::scrh)-font.y*(j+1)); // command line const auto cmd = curcmd(); if (cmd) text::drawf("> %s_", vec2f(font.x, float(sys::scrh)-font.y*(nd+1)), cmd); }
static void initparticles(void) { // indices never change we set them once here const u16 twotriangles[] = {0,1,2,2,3,1}; u16 *indices = NEWAE(u16, glindexn); ogl::genbuffers(1, &particleibo); ogl::bindbuffer(ogl::ELEMENT_ARRAY_BUFFER, particleibo); loopi(MAXPARTICLES) loopj(6) indices[6*i+j]=4*i+twotriangles[j]; OGL(BufferData, GL_ELEMENT_ARRAY_BUFFER, glindexn*sizeof(u16), indices, GL_STATIC_DRAW); ogl::bindbuffer(ogl::ELEMENT_ARRAY_BUFFER, 0); // vertices will be created at each drawing call ogl::genbuffers(1, &particlevbo); ogl::bindbuffer(ogl::ARRAY_BUFFER, particlevbo); OGL(BufferData, GL_ARRAY_BUFFER, glvertexn*sizeof(glparticle), NULL, GL_DYNAMIC_DRAW); ogl::bindbuffer(ogl::ARRAY_BUFFER, 0); SAFE_DELETEA(indices); // Init the array dynamically since VS2012 crashes with a static declaration glparts = NEWAE(glparticle, glvertexn); }
void draw(const char *str, vec2f pos) { ogl::bindtexture(GL_TEXTURE_2D, ogl::coretex(ogl::TEX_CHARACTERS)); // use a triangle mesh to display the text const auto len = strlen(str); auto indices = (indextype*) alloca(len*sizeof(int[6])); auto verts = (vec4f*) alloca(len*sizeof(vec4f[4])); // traverse the string and build the mesh auto index = 0, vert = 0; auto x = pos.x, y = pos.y; for (int i = 0; str[i] != 0; ++i) { int c = str[i]; if (c=='\t') {x = (x-pos.y+rr::PIXELTAB)/rr::PIXELTAB*rr::PIXELTAB+pos.y; continue;} if (c=='\f') {OGL(VertexAttrib3f,ogl::ATTRIB_COL,0.25f,1.f,0.5f); continue;} if (c==' ') {x += displayw; continue;} c -= 32; if (c<0 || c>=95) continue; const float EPS = 1e-3f; const auto in_left = (float(c%fontcol)*float(charw)-EPS) / float(fontw); const auto in_top = (float(c/fontcol)*float(charh)-EPS) / float(fonth); const auto in_right = in_left + (float(charw)-EPS)/float(fontw); const auto in_bottom = in_top + (float(charh)-EPS)/float(fonth); loopj(6) indices[index+j] = vert+twotriangles[j]; verts[vert+0] = vec4f(in_left, in_bottom, x, y); verts[vert+1] = vec4f(in_right,in_bottom, x+displayw,y); verts[vert+2] = vec4f(in_right,in_top,x+displayw,y+displayh); verts[vert+3] = vec4f(in_left, in_top,x, y+displayh); x += displayw; index += 6; vert += 4; } bindfontshader(); ogl::immdrawelememts("Tst2p2", index, indices, &verts[0].x); }
/// Internal: Render an object to text. static char *print_object(JSON *item, int depth, bool fmt) { char **entries = 0, **names = 0; char *out = 0, *ptr, *ret, *str; int len=7, i=0; JSON *child = item->firstchild; int numentries=0, fail=0; // Count the number of entries. while (child) numentries++, child = child->next; if(!numentries) // Explicitly handle empty object case { out=new char[fmt?depth+4:3]; if(!out) return 0; ptr = out; *ptr++='{'; if(fmt) { *ptr++='\n'; for (i=0; i<depth-1; i++) *ptr++='\t';} *ptr++='}'; *ptr++=0; return out; } // Allocate space for the names and the objects entries = new char *[numentries*sizeof(char*)]; if(!entries) return 0; names = new char *[numentries*sizeof(char*)]; memset(entries, 0, sizeof(char*)*numentries); memset(names, 0, sizeof(char*)*numentries); // Collect all the results into our arrays: child = item->firstchild; depth++; if(fmt) len+=depth; while (child) { names[i] = str = print_string_ptr(child->name); entries[i++]= ret = print_value(child, depth, fmt); if(str && ret) len+= strlen(ret) + strlen(str) + 2 + (fmt ? depth+2 : 0); else fail=1; child = child->next; } // Try to allocate the output string if(!fail) out = new char[len]; // Handle failure if(fail) { loopi(numentries) { delete[] names[i]; delete[] entries[i];} delete[] names; delete[] entries; return 0; } // Compose the output: *out = '{'; ptr = out+1; if(fmt) *ptr++ = '\n'; *ptr = 0; loopi(numentries) { if(fmt) loopj(depth) *ptr++ = '\t'; strcpy(ptr, names[i]); ptr += strlen(names[i]); *ptr++=':'; if(fmt) *ptr++ = '\t'; strcpy(ptr, entries[i]); ptr += strlen(entries[i]); if(i != numentries-1) *ptr++ = ','; if(fmt) *ptr++='\n'; *ptr = 0; delete[] names[i]; delete[] entries[i]; } delete[] names; delete[] entries; if(fmt) loopi(depth-1) *ptr++='\t'; *ptr++='}';*ptr++=0; return out; }
int execute(char *p, bool isdown) // all evaluation happens here, recursively { const int MAXWORDS = 25; // limit, remove char *w[MAXWORDS]; int val = 0; for(bool cont = true; cont;) // for each ; seperated statement { int numargs = MAXWORDS; loopi(MAXWORDS) // collect all argument values { w[i] = (char*) ""; if(i>numargs) continue; char *s = parseword(p); // parse and evaluate exps if(!s) { numargs = i; s = (char*) ""; }; if(*s=='$') s = lookup(s); // substitute variables w[i] = s; }; p += strcspn(p, ";\n\0"); cont = *p++!=0; // more statements if this isn't the end of the string const char *c = w[0]; if(*c=='/') c++; // strip irc-style command prefix if(!*c) continue; // empty statement ident *id = idents->access(c); if(!id) { val = ATOI(c); if(!val && *c!='0') console::out("unknown command: %s", c); } else switch(id->type) { case ID_COMMAND: // game defined commands switch(id->narg) // use very ad-hoc function signature, and just call it { case ARG_1INT: if(isdown) ((void (__cdecl *)(int))id->fun)(ATOI(w[1])); break; case ARG_2INT: if(isdown) ((void (__cdecl *)(int, int))id->fun)(ATOI(w[1]), ATOI(w[2])); break; case ARG_3INT: if(isdown) ((void (__cdecl *)(int, int, int))id->fun)(ATOI(w[1]), ATOI(w[2]), ATOI(w[3])); break; case ARG_4INT: if(isdown) ((void (__cdecl *)(int, int, int, int))id->fun)(ATOI(w[1]), ATOI(w[2]), ATOI(w[3]), ATOI(w[4])); break; case ARG_NONE: if(isdown) ((void (__cdecl *)())id->fun)(); break; case ARG_1STR: if(isdown) ((void (__cdecl *)(char *))id->fun)(w[1]); break; case ARG_2STR: if(isdown) ((void (__cdecl *)(char *, char *))id->fun)(w[1], w[2]); break; case ARG_3STR: if(isdown) ((void (__cdecl *)(char *, char *, char*))id->fun)(w[1], w[2], w[3]); break; case ARG_5STR: if(isdown) ((void (__cdecl *)(char *, char *, char*, char*, char*))id->fun)(w[1], w[2], w[3], w[4], w[5]); break; case ARG_DOWN: ((void (__cdecl *)(bool))id->fun)(isdown); break; case ARG_DWN1: ((void (__cdecl *)(bool, char *))id->fun)(isdown, w[1]); break; case ARG_1EXP: if(isdown) val = ((int (__cdecl *)(int))id->fun)(execute(w[1])); break; case ARG_2EXP: if(isdown) val = ((int (__cdecl *)(int, int))id->fun)(execute(w[1]), execute(w[2])); break; case ARG_1EST: if(isdown) val = ((int (__cdecl *)(char *))id->fun)(w[1]); break; case ARG_2EST: if(isdown) val = ((int (__cdecl *)(char *, char *))id->fun)(w[1], w[2]); break; case ARG_VARI: if(isdown) { string r; // limit, remove r[0] = 0; for(int i = 1; i<numargs; i++) { strcat_s(r, w[i]); // make string-list out of all arguments if(i==numargs-1) break; strcat_s(r, " "); }; ((void (__cdecl *)(char *))id->fun)(r); break; } }; break; case ID_VAR: // game defined variabled if(isdown) { if(!w[1][0]) console::out("%s = %d", c, *id->storage); // var with no value just prints its current value else { if(id->min>id->max) { console::out("variable is read-only"); } else { int i1 = ATOI(w[1]); if(i1<id->min || i1>id->max) { i1 = i1<id->min ? id->min : id->max; // clamp to valid range console::out("valid range for %s is %d..%d", c, id->min, id->max); } *id->storage = i1; }; if(id->fun) ((void (__cdecl *)())id->fun)(); // call trigger function if available }; }; break; case ID_ALIAS: // alias, also used as functions and (global) variables for(int i = 1; i<numargs; i++) { sprintf_sd(t)("arg%d", i); // set any arguments as (global) arg values so functions can access them alias(t, w[i]); }; char *action = newstring(id->action); // create new string here because alias could rebind itself val = execute(action, isdown); gp()->deallocstr(action); break; }; loopj(numargs) gp()->deallocstr(w[j]); }; return val; };
void global_screen_draw_level() { //return; loopj(0, global_height) loopi(0, strlen( &(global_level[j][0]) )) global_screen_set(i, j, global_level[j][i]); };
bool CslGameRedEclipse::ParseDefaultPong(ucharbuf& buf,CslServerInfo& info) const { vector<int>attr; wxUint32 l,numattr; char text[_MAXDEFSTR]; bool wasfull=info.IsFull(); l=getint(buf); if (info.HasRegisteredEvent(CslServerEvents::EVENT_EMPTY) && info.Players>0 && !l) info.SetEvents(CslServerEvents::EVENT_EMPTY); else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_EMPTY) && !info.Players && l>0) info.SetEvents(CslServerEvents::EVENT_NOT_EMPTY); info.Players=l; numattr=getint(buf); loopj(numattr) attr.add(getint(buf)); if (numattr>=1) { info.Protocol=attr[0]; info.Version=GetVersionName(info.Protocol); } if (numattr>=2) info.GameMode=GetModeName(attr[1],attr[2]); if (numattr>=4) info.TimeRemain=attr[3]; if (numattr>=5) { info.PlayersMax=attr[4]; if (info.HasRegisteredEvent(CslServerEvents::EVENT_FULL) && !wasfull && info.IsFull()) info.SetEvents(CslServerEvents::EVENT_FULL); else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_FULL) && wasfull && !info.IsFull()) info.SetEvents(CslServerEvents::EVENT_NOT_FULL); } l=info.MM; info.MM=CSL_SERVER_OPEN; info.MMDescription.Empty(); if (numattr>=6) { if (attr[5]==MM_PASSWORD) { info.MMDescription<<wxT("PASS"); info.MM|=CSL_SERVER_PASSWORD; } else { info.MMDescription=wxString::Format(wxT("%d"),attr[5]); if (attr[5]==MM_OPEN) info.MMDescription<<wxT(" (O)"); else if (attr[5]==MM_VETO) { info.MMDescription<<wxT(" (V)"); info.MM=CSL_SERVER_VETO; } else if (attr[5]==MM_LOCKED) { if (info.HasRegisteredEvent(CslServerEvents::EVENT_LOCKED) && CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_LOCKED(l)) info.SetEvents(CslServerEvents::EVENT_LOCKED); info.MMDescription<<wxT(" (L)"); info.MM=CSL_SERVER_LOCKED; } else if (attr[5]==MM_PRIVATE) { if (info.HasRegisteredEvent(CslServerEvents::EVENT_PRIVATE) && CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_PRIVATE(l)) info.SetEvents(CslServerEvents::EVENT_PRIVATE); info.MMDescription<<wxT(" (P)"); info.MM=CSL_SERVER_PRIVATE; } } } getstring(text,buf); info.Map=A2U(text); getstring(text,buf); l=(wxInt32)strlen(text); FixString(text,&l,1); info.SetDescription(A2U(text)); return !buf.overread(); }