From 55510047e2b4d5a0c5d740da89d6df9f25502f17 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 1 Jun 2007 11:06:13 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1049 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- config/font.cfg | 95 ++++++++++++++++ source/src/command.cpp | 2 + source/src/command.h | 2 +- source/src/main.cpp | 4 + source/src/protos.h | 1 + source/src/rendertext.cpp | 221 +++++++++++++++++--------------------- source/src/server.cpp | 4 +- source/src/texture.cpp | 5 +- 8 files changed, 204 insertions(+), 130 deletions(-) create mode 100644 config/font.cfg diff --git a/config/font.cfg b/config/font.cfg new file mode 100644 index 00000000..ac1a9fdd --- /dev/null +++ b/config/font.cfg @@ -0,0 +1,95 @@ +font default "packages/misc/chars.png" 32 64 0 2 0 -2 +fontchar 0 0 25 64 //! +fontchar 25 0 29 64 //" +fontchar 54 0 53 64 //# +fontchar 107 0 41 64 //$ +fontchar 148 0 69 64 //% +fontchar 217 0 46 64 //& +fontchar 263 0 17 64 //' +fontchar 280 0 29 64 //( +fontchar 309 0 29 64 //) +fontchar 338 0 41 64 //* +fontchar 379 0 53 64 //+ +fontchar 432 0 23 64 //, +fontchar 455 0 29 64 //- +fontchar 0 64 21 64 //. +fontchar 23 64 29 64 /// +fontchar 52 64 41 64 //0 +fontchar 93 64 40 64 //1 +fontchar 133 64 41 64 //2 +fontchar 174 64 41 64 //3 +fontchar 215 64 41 64 //4 +fontchar 256 64 40 64 //5 +fontchar 296 64 41 64 //6 +fontchar 337 64 41 64 //7 +fontchar 378 64 41 64 //8 +fontchar 419 64 40 64 //9 +fontchar 459 64 29 64 //: +fontchar 0 128 29 64 //; +fontchar 29 128 52 64 //< +fontchar 81 128 53 64 //= +fontchar 134 128 52 64 //> +fontchar 186 128 35 64 //? +fontchar 221 128 64 64 //@ +fontchar 285 128 44 64 //A +fontchar 329 128 44 64 //B +fontchar 373 128 45 64 //C +fontchar 418 128 49 64 //D +fontchar 0 192 40 64 //E +fontchar 40 192 37 64 //F +fontchar 77 192 50 64 //G +fontchar 127 192 48 64 //H +fontchar 175 192 27 64 //I +fontchar 202 192 29 64 //J +fontchar 231 192 44 64 //K +fontchar 275 192 36 64 //L +fontchar 311 192 54 64 //M +fontchar 365 192 48 64 //N +fontchar 413 192 50 64 //O +fontchar 1 256 37 64 //P +fontchar 38 256 51 64 //Q +fontchar 89 256 44 64 //R +fontchar 133 256 43 64 //S +fontchar 177 256 39 64 //T +fontchar 217 256 46 64 //U +fontchar 263 256 44 64 //V +fontchar 307 256 63 64 //W +fontchar 370 256 44 64 //X +fontchar 414 256 39 64 //Y +fontchar 453 256 44 64 //Z +fontchar 0 320 29 64 //[ +fontchar 29 320 29 64 //\ +fontchar 59 320 28 64 //] +fontchar 87 320 52 64 //^ +fontchar 139 320 41 64 //_ +fontchar 180 320 41 64 //` +fontchar 221 320 38 64 //a +fontchar 259 320 40 64 //b +fontchar 299 320 33 64 //c +fontchar 332 320 40 64 //d +fontchar 372 320 39 64 //e +fontchar 411 320 22 64 //f +fontchar 435 320 38 64 //g +fontchar 0 384 40 64 //h +fontchar 40 384 16 64 //i +fontchar 58 384 22 64 //j +fontchar 80 384 38 64 //k +fontchar 118 384 17 64 //l +fontchar 135 384 62 64 //m +fontchar 197 384 41 64 //n +fontchar 238 384 39 64 //o +fontchar 277 384 40 64 //p +fontchar 317 384 39 64 //q +fontchar 357 384 27 64 //r +fontchar 385 384 32 64 //s +fontchar 417 384 25 64 //t +fontchar 443 384 40 64 //u +fontchar 0 448 38 64 //v +fontchar 38 448 52 64 //w +fontchar 90 448 38 64 //x +fontchar 128 448 38 64 //y +fontchar 166 448 34 64 //z +fontchar 200 448 41 64 //{ +fontchar 241 448 29 64 //| +fontchar 270 448 40 64 //} +fontchar 310 448 53 64 //~ diff --git a/source/src/command.cpp b/source/src/command.cpp index d62dfd84..8d1ebe6f 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -158,6 +158,8 @@ int execute(char *p) // all evaluation happens here, case ARG_4STR: ((void (__cdecl *)(char *, char *, char*, char*))id->fun)(w[1], w[2], w[3], w[4]); break; case ARG_5STR: ((void (__cdecl *)(char *, char *, char*, char*, char*))id->fun)(w[1], w[2], w[3], w[4], w[5]); break; case ARG_6STR: ((void (__cdecl *)(char *, char *, char*, char*, char*, char*))id->fun)(w[1], w[2], w[3], w[4], w[5], w[6]); break; + case ARG_7STR: ((void (__cdecl *)(char *, char *, char*, char*, char*, char*, char*))id->fun)(w[1], w[2], w[3], w[4], w[5], w[6], w[7]); break; + case ARG_8STR: ((void (__cdecl *)(char *, char *, char*, char*, char*, char*, char*, char*))id->fun)(w[1], w[2], w[3], w[4], w[5], w[6], w[7], w[8]); break; case ARG_DOWN: ((void (__cdecl *)(bool))id->fun)(addreleaseaction(id->name)!=NULL); break; case ARG_1EXP: val = ((int (__cdecl *)(int))id->fun)(execute(w[1])); break; case ARG_2EXP: val = ((int (__cdecl *)(int, int))id->fun)(execute(w[1]), execute(w[2])); break; diff --git a/source/src/command.h b/source/src/command.h index 5a78135a..068af3f9 100644 --- a/source/src/command.h +++ b/source/src/command.h @@ -16,7 +16,7 @@ enum // function signatures for script functions, see command.cpp { ARG_1INT, ARG_2INT, ARG_3INT, ARG_4INT, ARG_NONE, - ARG_1STR, ARG_2STR, ARG_3STR, ARG_4STR, ARG_5STR, ARG_6STR, + ARG_1STR, ARG_2STR, ARG_3STR, ARG_4STR, ARG_5STR, ARG_6STR, ARG_7STR, ARG_8STR, ARG_DOWN, ARG_1EXP, ARG_2EXP, ARG_1EST, ARG_2EST, diff --git a/source/src/main.cpp b/source/src/main.cpp index 673ea9c3..9e7fb50b 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -252,6 +252,10 @@ int main(int argc, char **argv) keyrepeat(false); SDL_ShowCursor(0); + initlog("console"); + if(!execfile("config/font.cfg")) fatal("cannot find font definitions"); + if(!setfont("default")) fatal("no default font specified"); + initlog("gl"); gl_init(scr_w, scr_h, bpp, depth, fsaa); diff --git a/source/src/protos.h b/source/src/protos.h index c8ed93c8..10fd8217 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -191,6 +191,7 @@ extern void fatal(char *s, char *o = ""); extern void keyrepeat(bool on); // rendertext +extern bool setfont(char *name); extern void draw_text(const char *str, int left, int top); extern void draw_textf(const char *fstr, int left, int top, ...); extern int char_width(int c, int x = 0); diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 08d23061..884fc00c 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -2,113 +2,76 @@ #include "cube.h" -short char_coords[96][4] = +struct font { - {0,0,25,64}, //! - {25,0,54,64}, //" - {54,0,107,64}, //# - {107,0,148,64}, //$ - {148,0,217,64}, //% - {217,0,263,64}, //& - {263,0,280,64}, //' - {280,0,309,64}, //( - {309,0,338,64}, //) - {338,0,379,64}, //* - {379,0,432,64}, //+ - {432,0,455,64}, //, - {455,0,484,64}, //- - {0,64,21,128}, //. - {23,64,52,128}, /// - {52,64,93,128}, //0 - {93,64,133,128}, //1 - {133,64,174,128}, //2 - {174,64,215,128}, //3 - {215,64,256,128}, //4 - {256,64,296,128}, //5 - {296,64,337,128}, //6 - {337,64,378,128}, //7 - {378,64,419,128}, //8 - {419,64,459,128}, //9 - {459,64,488,128}, //: - {0,128,29,192}, //; - {29,128,81,192}, //< - {81,128,134,192}, //= - {134,128,186,192}, //> - {186,128,221,192}, //? - {221,128,285,192}, //@ - {285,128,329,192}, //A - {329,128,373,192}, //B - {373,128,418,192}, //C - {418,128,467,192}, //D - {0,192,40,256}, //E - {40,192,77,256}, //F - {77,192,127,256}, //G - {127,192,175,256}, //H - {175,192,202,256}, //I - {202,192,231,256}, //J - {231,192,275,256}, //K - {275,192,311,256}, //L - {311,192,365,256}, //M - {365,192,413,256}, //N - {413,192,463,256}, //O - {1,256,38,320}, //P - {38,256,89,320}, //Q - {89,256,133,320}, //R - {133,256,176,320}, //S - {177,256,216,320}, //T - {217,256,263,320}, //U - {263,256,307,320}, //V - {307,256,370,320}, //W - {370,256,414,320}, //X - {414,256,453,320}, //Y - {453,256,497,320}, //Z - {0,320,29,384}, //[ - {29,320,58,384}, //"\" - {59,320,87,384}, //] - {87,320,139,384}, //^ - {139,320,180,384}, //_ - {180,320,221,384}, //` - {221,320,259,384}, //a - {259,320,299,384}, //b - {299,320,332,384}, //c - {332,320,372,384}, //d - {372,320,411,384}, //e - {411,320,433,384}, //f - {435,320,473,384}, //g - {0,384,40,448}, //h - {40,384,56,448}, //i - {58,384,80,448}, //j - {80,384,118,448}, //k - {118,384,135,448}, //l - {135,384,197,448}, //m - {197,384,238,448}, //n - {238,384,277,448}, //o - {277,384,317,448}, //p - {317,384,356,448}, //q - {357,384,384,448}, //r - {385,384,417,448}, //s - {417,384,442,448}, //t - {443,384,483,448}, //u - {0,448,38,512}, //v - {38,448,90,512}, //w - {90,448,128,512}, //x - {128,448,166,512}, //y - {166,448,200,512}, //z - {200,448,241,512}, //{ - {241,448,270,512}, //| - {270,448,310,512}, //} - {310,448,363,512}, //~ + struct charinfo + { + short x, y, w, h; + }; + + char *name; + Texture *tex; + vector chars; + short defaultw, defaulth; + short offsetx, offsety, offsetw, offseth; }; +static hashtable fonts; +static font *fontdef = NULL, *curfont = NULL; + +void newfont(char *name, char *tex, char *defaultw, char *defaulth, char *offsetx, char *offsety, char *offsetw, char *offseth) +{ + font *f = fonts.access(name); + if(!f) + { + name = newstring(name); + f = &fonts[name]; + f->name = name; + } + + f->tex = textureload(tex); + f->chars.setsize(0); + f->defaultw = ATOI(defaultw); + f->defaulth = ATOI(defaulth); + f->offsetx = ATOI(offsetx); + f->offsety = ATOI(offsety); + f->offsetw = ATOI(offsetw); + f->offseth = ATOI(offseth); + + fontdef = f; +} + +void fontchar(int x, int y, int w, int h) +{ + if(!fontdef) return; + + font::charinfo &c = fontdef->chars.add(); + c.x = x; + c.y = y; + c.w = w ? w : fontdef->defaultw; + c.h = h ? h : fontdef->defaulth; +} + +COMMANDN(font, newfont, ARG_8STR); +COMMANDN(fontchar, fontchar, ARG_4INT); + +bool setfont(char *name) +{ + font *f = fonts.access(name); + if(!f) return false; + curfont = f; + return true; +} + int char_width(int c, int x) { - if(c=='\t') x = (x+PIXELTAB)/PIXELTAB*PIXELTAB; - else if(c==' ') x += FONTH/2; - else if(c>=33 && c<=126) + if(!curfont) return x; + else if(c=='\t') x = (x+PIXELTAB)/PIXELTAB*PIXELTAB; + else if(c==' ') x += curfont->defaultw; + else if(curfont->chars.inrange(c-33)) { c -= 33; - int in_width = char_coords[c][2] - char_coords[c][0]; - x += in_width + 1; + x += curfont->chars[c].w + 1; } return x; } @@ -201,19 +164,17 @@ void draw_textf(const char *fstr, int left, int top, ...) void draw_text(const char *str, int left, int top) { - static Texture *charstex = NULL; - if(!charstex) charstex = textureload("packages/misc/chars.png"); + if(!curfont) return; glBlendFunc(GL_ONE, GL_ONE); - glBindTexture(GL_TEXTURE_2D, charstex->id); + glBindTexture(GL_TEXTURE_2D, curfont->tex->id); glColor3ub(255, 255, 255); - int x = left, y = top, col = 0; - - float in_left, in_top, in_right, in_bottom; - int in_width, in_height; + static float colorstack[8][4]; + int colorpos = 0, x = left, y = top, col = 0; - for (int i = 0; str[i]; i++) + glBegin(GL_QUADS); + for(int i = 0; str[i]; i++) { int c = str[i]; switch(c) @@ -232,33 +193,45 @@ void draw_text(const char *str, int left, int top) case '3': glColor3ub(255, 64, 64); i++; continue; // red: important errors case '4': glColor3ub(128, 128, 128); i++; continue; // gray case '5': glColor3ub(255, 255, 255); i++; continue; // white: everything else + case 's': // save color + if((size_t)colorpos0) + glColor4fv(colorstack[--colorpos]); + i++; + continue; default: i++; continue; } case ' ': - x += FONTH/2; + x += curfont->defaultw; continue; } c -= 33; - if(c<0 || c>=95) continue; + if(!curfont->chars.inrange(c)) continue; - in_left = ((float) char_coords[c][0]) / 512.0f; - in_top = ((float) char_coords[c][1]+2) / 512.0f; - in_right = ((float) char_coords[c][2]) / 512.0f; - in_bottom = ((float) char_coords[c][3]-2) / 512.0f; + font::charinfo &info = curfont->chars[c]; + float tc_left = (info.x + curfont->offsetx) / float(curfont->tex->xs); + float tc_top = (info.y + curfont->offsety) / float(curfont->tex->ys); + float tc_right = (info.x + info.w + curfont->offsetw) / float(curfont->tex->xs); + float tc_bottom = (info.y + info.h + curfont->offseth) / float(curfont->tex->ys); - in_width = char_coords[c][2] - char_coords[c][0]; - in_height = char_coords[c][3] - char_coords[c][1]; + glTexCoord2f(tc_left, tc_top ); glVertex2i(x, y); + glTexCoord2f(tc_right, tc_top ); glVertex2i(x + info.w, y); + glTexCoord2f(tc_right, tc_bottom); glVertex2i(x + info.w, y + info.h); + glTexCoord2f(tc_left, tc_bottom); glVertex2i(x, y + info.h); - glBegin(GL_QUADS); - glTexCoord2f(in_left, in_top ); glVertex2i(x, y); - glTexCoord2f(in_right, in_top ); glVertex2i(x + in_width, y); - glTexCoord2f(in_right, in_bottom); glVertex2i(x + in_width, y + in_height); - glTexCoord2f(in_left, in_bottom); glVertex2i(x, y + in_height); - glEnd(); - xtraverts += 4; - x += in_width + 1; + x += info.w + 1; } + glEnd(); } + diff --git a/source/src/server.cpp b/source/src/server.cpp index 79883db3..cbb34884 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -443,10 +443,10 @@ void sendteamtext(char *text, int sender) if(packet->referenceCount==0) enet_packet_destroy(packet); } -char *disc_reason(int reason) +const char *disc_reason(int reason) { static char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?" }; - return reason >= 0 && reason < sizeof(disc_reasons)/sizeof(disc_reasons[0]) ? disc_reasons[reason] : "unknown"; + return reason >= 0 && (size_t)reason < sizeof(disc_reasons)/sizeof(disc_reasons[0]) ? disc_reasons[reason] : "unknown"; } void disconnect_client(int n, int reason = -1) diff --git a/source/src/texture.cpp b/source/src/texture.cpp index dd7bfb5b..94af217c 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -5,7 +5,7 @@ Texture *crosshair = NULL; hashtable textures; -VAR(maxtexsize, 0, 0, 4096); +VAR(maxtexsize, 0, -1, 4096); void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format) { @@ -17,6 +17,7 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); int tw = w, th = h; + if(maxtexsize<0) glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&maxtexsize); if(maxtexsize) while(tw>maxtexsize || th>maxtexsize) { tw /= 2; th /= 2; } if(tw!=w) { @@ -313,8 +314,6 @@ void setuptmu(int n, const char *rgbfunc, const char *alphafunc) void inittmus() { - glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&maxtexsize); - if(hasTE && !hasMT) maxtmus = 1; else if(hasTE && hasMT) {