From cf25327c2d8f47a297f36ce81bb44096aa26e92e Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Tue, 25 May 2010 00:21:35 +0000 Subject: [PATCH] temporarily reverting draw_text to 1.0.4 function and other stuff related to medals git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5049 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/rendertext.cpp | 376 +++++++++++++++++++++----------------- source/src/serverchecks.h | 48 ++--- 2 files changed, 226 insertions(+), 198 deletions(-) diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 370e9c8d..9a7c9ba2 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -116,16 +116,16 @@ extern int shdsize, outline, win32msg; struct charringbuf : ringbuf { // find by character code - int findbycharcode(int code) - { - loopi(len) - { - if(data[i].code == code) - return i; - } + int findbycharcode(int code) + { + loopi(len) + { + if(data[i].code == code) + return i; + } - return -1; - } + return -1; + } }; TTF_Font *ttffont = NULL; @@ -134,82 +134,82 @@ charringbuf utf8chars; void initfont() { - static bool initialized = false; - if(!initialized) - { - TTF_Init(); + static bool initialized = false; + if(!initialized) + { + TTF_Init(); - int fsize = 64; - const char *fontname = "packages/misc/font.ttf"; - ttffont = TTF_OpenFont(findfile(path(fontname, true), "r"), fsize); + int fsize = 64; + const char *fontname = "packages/misc/font.ttf"; + ttffont = TTF_OpenFont(findfile(path(fontname, true), "r"), fsize); - utf8font.defaulth = 0; - utf8font.defaultw = 0; - utf8font.offsetw = 0; - utf8font.offseth = 10; - utf8font.offsetx = 0; - utf8font.offsety = 0; + utf8font.defaulth = 0; + utf8font.defaultw = 0; + utf8font.offsetw = 0; + utf8font.offseth = 10; + utf8font.offsetx = 0; + utf8font.offsety = 0; - initialized = true; - } + initialized = true; + } } void createutf8charset() { - int isize = 512; + int isize = 512; - SDL_Surface *charsetsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, isize, isize, 32, RMASK, GMASK, BMASK, AMASK); + SDL_Surface *charsetsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, isize, isize, 32, RMASK, GMASK, BMASK, AMASK); - if(charsetsurface) - { - SDL_Color color; - color.r = 255; - color.g = 255; - color.b = 255; + if(charsetsurface) + { + SDL_Color color; + color.r = 255; + color.g = 255; + color.b = 255; - int posx = 0; - int posy = 0; + int posx = 0; + int posy = 0; - loopv(utf8chars) - { - font::utf8charinfo &charinfo = utf8chars[i]; - int code = charinfo.code; + loopv(utf8chars) + { + font::utf8charinfo &charinfo = utf8chars[i]; + int code = charinfo.code; - char u[5] = {0,0,0,0,0}; - utf8::append(code, u); + char u[5] = {0,0,0,0,0}; + utf8::append(code, u); - SDL_Surface *fontsurface = TTF_RenderUTF8_Blended(ttffont, u, color); + SDL_Surface *fontsurface = TTF_RenderUTF8_Blended(ttffont, u, color); // update row/column info - if(posx + fontsurface->w > charsetsurface->w) - { - posx = 0; - posy += fontsurface->h; // fixme - } - if(posy + fontsurface->h > charsetsurface->h) - break; + if(posx + fontsurface->w > charsetsurface->w) + { + posx = 0; + posy += fontsurface->h; // fixme + } + if(posy + fontsurface->h > charsetsurface->h) + break; // blit onto charset - SDL_SetAlpha(fontsurface, 0, 0); - blitsurface(charsetsurface, fontsurface, posx, posy); + SDL_SetAlpha(fontsurface, 0, 0); + blitsurface(charsetsurface, fontsurface, posx, posy); // update charinfo properties - charinfo.x = posx; - charinfo.y = posy; - charinfo.w = fontsurface->w; - charinfo.h = fontsurface->h; + charinfo.x = posx; + charinfo.y = posy; + charinfo.w = fontsurface->w; + charinfo.h = fontsurface->h; - posx += fontsurface->w; - SDL_FreeSurface(fontsurface); - } + posx += fontsurface->w; + SDL_FreeSurface(fontsurface); + } - utf8font.tex = createtexturefromsurface("utf8charset", charsetsurface); + utf8font.tex = createtexturefromsurface("utf8charset", charsetsurface); //extern void savepng(SDL_Surface *s, const char *name); //savepng(t, "font.png"); - SDL_FreeSurface(charsetsurface); - } + SDL_FreeSurface(charsetsurface); + } } void addutf8char(int code) @@ -240,22 +240,22 @@ font::charinfo *loadchar(int code) int draw_char(font &f, font::charinfo &info, int charcode, int x, int y) { // fixme - glEnd(); - glBindTexture(GL_TEXTURE_2D, f.tex->id); - glBegin(GL_QUADS); + glEnd(); + glBindTexture(GL_TEXTURE_2D, f.tex->id); + glBegin(GL_QUADS); - float tc_left = (info.x + f.offsetx) / float(f.tex->xs); - float tc_top = (info.y + f.offsety) / float(f.tex->ys); - float tc_right = (info.x + info.w + f.offsetw) / float(f.tex->xs); - float tc_bottom = (info.y + info.h + f.offseth) / float(f.tex->ys); + float tc_left = (info.x + f.offsetx) / float(f.tex->xs); + float tc_top = (info.y + f.offsety) / float(f.tex->ys); + float tc_right = (info.x + info.w + f.offsetw) / float(f.tex->xs); + float tc_bottom = (info.y + info.h + f.offseth) / float(f.tex->ys); - glTexCoord2f(tc_left, tc_top ); glVertex2f(x, y); - glTexCoord2f(tc_right, tc_top ); glVertex2f(x + info.w, y); - glTexCoord2f(tc_right, tc_bottom); glVertex2f(x + info.w, y + info.h); - glTexCoord2f(tc_left, tc_bottom); glVertex2f(x, y + info.h); + glTexCoord2f(tc_left, tc_top ); glVertex2f(x, y); + glTexCoord2f(tc_right, tc_top ); glVertex2f(x + info.w, y); + glTexCoord2f(tc_right, tc_bottom); glVertex2f(x + info.w, y + info.h); + glTexCoord2f(tc_left, tc_bottom); glVertex2f(x, y + info.h); - xtraverts += 4; - return info.w; + xtraverts += 4; + return info.w; } // fixme @@ -474,152 +474,190 @@ void text_bounds(const char *str, int &width, int &height, int maxwidth) #undef TEXTWORD } -/* WIP ALERT */ -void draw_text(const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth) +/** This is the 1.0.4 function + It will substituted by draw_text_wip + I am putting this temporarily here because it is impossible to test without colours : Brahma */ +void draw_text(const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth) +{ +#define TEXTINDEX(idx) if(idx == cursor) { cx = x; cy = y; cc = str[idx]; } +#define TEXTTAB(idx) TEXTGETCOLUMN +#define TEXTWHITE(idx) +#define TEXTLINE(idx) +#define TEXTCOLOR(idx) text_color(str[idx], colorstack, sizeof(colorstack), colorpos, color, a); +#define TEXTCHAR(idx) x += draw_char(c, left+x, top+y)+1; +#define TEXTWORD TEXTWORDSKELETON + char colorstack[10]; + bvec color(r, g, b); + int colorpos = 0, cx = INT_MIN, cy = 0, cc = ' '; + colorstack[0] = 'c'; //indicate user color + glBlendFunc(GL_SRC_ALPHA, curfont->tex->bpp==32 ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE); + glBindTexture(GL_TEXTURE_2D, curfont->tex->id); + glBegin(GL_QUADS); + glColor4ub(color.x, color.y, color.z, a); + TEXTSKELETON + glEnd(); + if(cursor >= 0) + { + if(cx == INT_MIN) { cx = x; cy = y; } + if(maxwidth != -1 && cx >= maxwidth) { cx = 0; cy += FONTH; } + int cw = curfont->chars.inrange(cc-33) ? curfont->chars[cc-33].w + 1 : curfont->defaultw; + rendercursor(left+cx, top+cy, cw); + } +#undef TEXTINDEX +#undef TEXTTAB +#undef TEXTWHITE +#undef TEXTLINE +#undef TEXTCOLOR +#undef TEXTCHAR +#undef TEXTWORD +} + +/** WIP ALERT */ +void draw_text_wip(const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth) { char colorstack[10]; bvec color(r, g, b); int colorpos = 0, cx = INT_MIN, cy = 0, cc = ' '; colorstack[0] = 'c'; //indicate user color - glBlendFunc(GL_SRC_ALPHA, curfont->tex->bpp==32 ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE); - glBindTexture(GL_TEXTURE_2D, curfont->tex->id); + glBlendFunc(GL_SRC_ALPHA, curfont->tex->bpp==32 ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE); + glBindTexture(GL_TEXTURE_2D, curfont->tex->id); glBegin(GL_QUADS); glColor4ub(color.x, color.y, color.z, a); - std::string text(str); - std::string::iterator begin = text.begin(); - std::string::iterator end = text.end(); - std::string::iterator cursoriter = end; - if(cursor >= 0 && cursor < utf8::distance(begin, end)) - { - cursoriter = begin; - utf8::advance(cursoriter, cursor, end); - } + std::string text(str); + std::string::iterator begin = text.begin(); + std::string::iterator end = text.end(); + std::string::iterator cursoriter = end; + if(cursor >= 0 && cursor < utf8::distance(begin, end)) + { + cursoriter = begin; + utf8::advance(cursoriter, cursor, end); + } int y = 0, x = 0, col = 0, colx = 0; - for(std::string::iterator iter = text.begin(); iter != text.end(); utf8::next(iter, text.end())) + for(std::string::iterator iter = text.begin(); iter != text.end(); utf8::next(iter, text.end())) { - int c = utf8::peek_next(iter, text.end()); + int c = utf8::peek_next(iter, text.end()); - if(iter == cursoriter) - { - cx = x; - cy = y; - cc = c; - } + if(iter == cursoriter) + { + cx = x; + cy = y; + cc = c; + } if(c=='\t') - { - if(columns && collength()) - { - colx += (*columns)[col++]; - x = colx; - } - else x = TABALIGN(x); - } + { + if(columns && collength()) + { + colx += (*columns)[col++]; + x = colx; + } + else x = TABALIGN(x); + } else if(c==' ') - { - x += curfont->defaultw; - } + { + x += curfont->defaultw; + } else if(c=='\n') - { - x = 0; - y += FONTH; - } + { + x = 0; + y += FONTH; + } else if(c=='\f') - { - std::string::iterator test = iter; - test++; - if(test != end) - { - c = utf8::next(iter, end); - text_color(c, colorstack, sizeof(colorstack), colorpos, color, a); - } - } + { + std::string::iterator test = iter; + test++; + if(test != end) + { + c = utf8::next(iter, end); + text_color(c, colorstack, sizeof(colorstack), colorpos, color, a); + } + } else if(c=='\a') - { - std::string::iterator next = iter; - next++; - if(next != end) - { - iter++; - } + { + std::string::iterator next = iter; + next++; + if(next != end) + { + iter++; + } - } + } else if(curfont->chars.inrange(c-curfont->skip)) { - font::charinfo &cinfo = getcharinfo(c); + font::charinfo &cinfo = getcharinfo(c); if(maxwidth != -1) { - std::string::iterator next = iter; + std::string::iterator next = iter; int w = cinfo.w; - do + do { - std::string::iterator test = iter; - int c = utf8::next(test, end); - if(test == end) break; + std::string::iterator test = iter; + int c = utf8::next(test, end); + if(test == end) break; if(c=='\f') - { - std::string::iterator test = iter; - utf8::advance(test, 2, end); - if(test == end) break; - utf8::next(iter, end); - continue; - } - if(utf8::distance(iter, next) > 16) break; + { + std::string::iterator test = iter; + utf8::advance(test, 2, end); + if(test == end) break; + utf8::next(iter, end); + continue; + } + if(utf8::distance(iter, next) > 16) break; //if(!curfont->chars.inrange(c-curfont->skip)) fixme - if(c < curfont->skip) // fixme - { - break; - } - int cw = getcharinfo(c).w + 1; + if(c < curfont->skip) // fixme + { + break; + } + int cw = getcharinfo(c).w + 1; if(w + cw >= maxwidth) break; w += cw; - utf8::next(iter, end); + utf8::next(iter, end); } while(true); if(x + w >= maxwidth && next != begin) //fixme - { - x = 0; - y += FONTH; - } - - for(; next <= iter && next != end; ) { - int c = utf8::peek_next(next, end); - if(next == cursoriter) { cx = x; cy = y; cc = c; } + x = 0; + y += FONTH; + } + + for(; next <= iter && next != end; ) + { + int c = utf8::peek_next(next, end); + if(next == cursoriter) { cx = x; cy = y; cc = c; } if(c=='\f') - { - std::string::iterator test = next; - utf8::next(test, end); - if(test != end) - { - c = utf8::next(next, end); - text_color(c, colorstack, sizeof(colorstack), colorpos, color, a); - } - } + { + std::string::iterator test = next; + utf8::next(test, end); + if(test != end) + { + c = utf8::next(next, end); + text_color(c, colorstack, sizeof(colorstack), colorpos, color, a); + } + } else - { - x += draw_char(c, left+x, top+y)+1; - } + { + x += draw_char(c, left+x, top+y)+1; + } - utf8::next(next, end); + utf8::next(next, end); } } else { - x += draw_char(c, left+x, top+y)+1; - } + x += draw_char(c, left+x, top+y)+1; + } } } diff --git a/source/src/serverchecks.h b/source/src/serverchecks.h index 237e8f35..ab3a530e 100644 --- a/source/src/serverchecks.h +++ b/source/src/serverchecks.h @@ -68,7 +68,6 @@ int checkarea(int maplayout_factor, char *maplayout) { area = getmaxarea((i & 1),(i & 2),(i & 4), maplayout_factor, maplayout); if ( area > maxarea ) maxarea = area; } - printf("MAX AREA %d\n",maxarea); return maxarea; } @@ -109,7 +108,6 @@ void checkcombo (client *target, client *actor, int damage, int gun) actor->combo++; actor->points += 10; actor->ncombos++; - sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 0); } } } else { @@ -124,7 +122,6 @@ void checkcombo (client *target, client *actor, int damage, int gun) actor->combo++; actor->points += 10; actor->ncombos++; - sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 0); break; } } @@ -146,45 +143,39 @@ void checkcover (client *target, client *actor) // FIXME sflaginfo &f = sflaginfos[team]; sflaginfo &of = sflaginfos[oteam]; float flagflag = sqrt(float((f.x-of.x)*(f.x-of.x) + (f.y-of.y)*(f.y-of.y))); - if (flagflag < 50) return; - if (flagflag > 300 || flagflag < 50) flagflag = 150; + if ( flagflag < 50 ) return; + if ( flagflag > 200 ) flagflag = 200; if (m_ctf) { - float range = flagflag/3; + float range = flagflag / 4; if (f.state == CTFF_INBASE) { float dx = actor->state.o.x-f.x, dy = actor->state.o.y-f.y; float dist = sqrt (dx*dx+dy*dy); - int n = 0; - if (dist < range) n++; dx = target->state.o.x-f.x, dy = target->state.o.y-f.y; - dist = sqrt (dx*dx+dy*dy); - if (dist < range) n++; - if ( n > 0 ) { + dist += sqrt (dx*dx+dy*dy); + if ( dist < range ) { sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 1); //FIXME - actor->points += 3 * n * clientnumber / 2; - actor->ncovers += n; + actor->points += 3 * clientnumber / 2; + actor->ncovers++; } } if (of.state == CTFF_STOLEN && actor->clientnum != of.actor_cn) { float dx = actor->state.o.x-clients[of.actor_cn]->state.o.x, dy = actor->state.o.y-clients[of.actor_cn]->state.o.y; float dist = sqrt (dx*dx+dy*dy); - int n = 0; - if (dist < range) n++; dx = target->state.o.x-clients[of.actor_cn]->state.o.x, dy = target->state.o.y-clients[of.actor_cn]->state.o.y; - dist = sqrt (dx*dx+dy*dy); - if (dist < range) n++; - if ( n>0 ) { + dist += sqrt(dx*dx+dy*dy); + if ( dist < range ) { sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 1); //FIXME - actor->points += 5 * n * clientnumber / 2; - actor->ncovers += n; + actor->points += 5 * clientnumber / 2; + actor->ncovers++; } } } else if (m_htf) { - float range = flagflag/4; + float range = flagflag / 5; if (f.state == CTFF_DROPPED) { float dx = target->state.o.x-f.pos[0], dy = target->state.o.y-f.pos[1]; float dist = sqrt (dx*dx+dy*dy); - if (dist < range) { + if ( dist < range ) { sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 1); //FIXME actor->points += 3 * clientnumber / 2; actor->ncovers++; @@ -193,15 +184,12 @@ void checkcover (client *target, client *actor) // FIXME if (f.state == CTFF_STOLEN && actor->clientnum != f.actor_cn) { float dx = actor->state.o.x-clients[f.actor_cn]->state.o.x, dy = actor->state.o.y-clients[f.actor_cn]->state.o.y; float dist = sqrt (dx*dx+dy*dy); - int n = 0; - if (dist < range) n++; dx = target->state.o.x-clients[f.actor_cn]->state.o.x, dy = target->state.o.y-clients[f.actor_cn]->state.o.y; - dist = sqrt (dx*dx+dy*dy); - if (dist < range) n++; - if ( n>0 ) { + dist += sqrt (dx*dx+dy*dy); + if ( dist < range ) { sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 1); //FIXME - actor->points += 6 * n * clientnumber / 2; - actor->ncovers += n; + actor->points += 6 * clientnumber / 2; + actor->ncovers++; } } } @@ -241,6 +229,8 @@ void checkfrag (client *target, client *actor, int gun, bool gib) if ( m_flags ) checkcover (target, actor); + if ( actor->combo ) sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, 0); + } else { if ( targethasflag >= 0 ) {