From cd34a822915846a631814724a2415148167c416e Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Mon, 2 Apr 2007 03:32:23 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@884 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/cube.h | 1 + source/src/protos.h | 4 +- source/src/renderextras.cpp | 98 +++++++++------------ source/src/rendergl.cpp | 171 +++++++++++++++++++++--------------- source/src/vertmodel.h | 2 +- source/src/worldio.cpp | 1 + source/src/worldocull.cpp | 2 +- source/src/worldrender.cpp | 36 ++++---- 8 files changed, 165 insertions(+), 150 deletions(-) diff --git a/source/src/cube.h b/source/src/cube.h index 481e6ec3..c662b4a4 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -116,6 +116,7 @@ extern int lastmillis; // last time extern int curtime; // current frame time extern int gamemode, nextmode; extern int xtraverts; +extern bool minimap; extern bool demoplayback; extern bool intermission; extern bool arenajoin; diff --git a/source/src/protos.h b/source/src/protos.h index 48430a78..bf2f10ca 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -52,13 +52,13 @@ extern Texture *crosshair; extern void gl_init(int w, int h, int bpp, int depth, int fsaa); extern void cleangl(); extern void gl_drawframe(int w, int h, float changelod, float curfps); -extern void createtexture(int tnum, int w, int h, void *pixels, int clamp, GLenum format); +extern void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format); extern Texture *textureload(const char *name, int clamp = 0); extern void mipstats(int a, int b, int c); extern void addstrip(int type, int tex, int start, int n); extern int lookuptexture(int tex, int &xs, int &ys); extern char *hudgunnames[]; -extern void createminimap(char *map); +extern void clearminimap(); // rendercubes extern void resetcubes(); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index da521072..5ba8ef8d 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -30,9 +30,9 @@ void box(block &b, float z1, float z2, float z3, float z4) xtraverts += 4; } -inline void quad(Texture *tex, float x, float y, float s, float tx, float ty, float ts) +void quad(GLuint tex, float x, float y, float s, float tx, float ty, float ts) { - if(tex) glBindTexture(GL_TEXTURE_2D, tex->id); + glBindTexture(GL_TEXTURE_2D, tex); glBegin(GL_QUADS); glTexCoord2f(tx, ty); glVertex2f(x, y); glTexCoord2f(tx+ts, ty); glVertex2f(x+s, y); @@ -198,7 +198,7 @@ void readdepth(int w, int h, vec &pos) void drawicon(Texture *tex, float x, float y, float s, int col, int row, float ts) { - if(tex && tex->xs == tex->ys) quad(tex, x, y, s, ts*col, ts*row, ts); + if(tex && tex->xs == tex->ys) quad(tex->id, x, y, s, ts*col, ts*row, ts); } void drawequipicon(float x, float y, int col, int row, float blend) @@ -340,62 +340,48 @@ void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, void drawradar(const vec ¢er, int radarres, int w, int h, bool fullscreen) { - static Texture *radar = NULL; - static string map; - char *curmap = getclientmap(); + glPushMatrix(); + glDisable(GL_BLEND); - if(strcmp(map, curmap)) // update once on map load + const float worldsize = (float)ssize; + const float radarviewsize = fullscreen ? VIRTH : VIRTH/6; + const float radarsize = worldsize/radarres*radarviewsize; + + if(fullscreen) glTranslatef(VIRTW/2-radarviewsize/2, 0, 0); + else glTranslatef(VIRTW-radarviewsize-10, 10, 0); + + extern GLuint minimaptex; + + vec centerpos(min(max(center.x, radarres/2), worldsize-radarres/2), min(max(center.y, radarres/2), worldsize-radarres/2), 0); + quad(minimaptex, 0, 0, radarviewsize, (centerpos.x-radarres/2)/worldsize, (centerpos.y-radarres/2)/worldsize, radarres/worldsize); + glTranslatef(-(centerpos.x-radarres/2)/worldsize*radarsize, -(centerpos.y-radarres/2)/worldsize*radarsize, 0); + + const float iconsize = radarentsize/(float)radarres*radarviewsize; + const float coordtrans = radarsize/worldsize; + + drawradarent(player1->o.x*coordtrans, player1->o.y*coordtrans, player1->yaw, player1->state==CS_ALIVE ? (player1->attacking ? 2 : 0) : 1, 2, iconsize, false); // local player + loopv(players) // other players { - s_strcpy(map, curmap); - s_sprintfd(texpath)("packages/%s.bmp", map); // fixme: image format - FILE *f = fopen(texpath, "r"); // check for existence first to avoid tex load error - if(!f) createminimap(texpath); // create if not available - radar = textureload(texpath); + playerent *pl = players[i]; + if(!pl || !isteam(player1->team, pl->team) || (centerpos.z=pl->o.z && centerpos.reject(pl->o, radarres/2))) continue; + drawradarent(pl->o.x*coordtrans, pl->o.y*coordtrans, pl->yaw, pl->state==CS_ALIVE ? (pl->attacking ? 2 : 0) : 1, team_int(pl->team), iconsize, false); + } + if(m_ctf) + { + glColor4f(1.0f, 1.0f, 1.0f, (sinf(lastmillis / 100.0f) + 1.0f) / 2.0f); + loopi(2) // flag items + { + flaginfo &f = flaginfos[i]; + entity *e = f.flag; + if(!e) continue; + if(f.state==CTFF_STOLEN && f.actor && (centerpos.z=f.actor->o.z && !centerpos.reject(f.actor->o, radarres/2))) + drawradarent(f.actor->o.x*coordtrans+iconsize/2, f.actor->o.y*coordtrans+iconsize/2, 0, 3, f.team, iconsize, true); // draw near flag thief + else if(!vec(e->x, e->y, centerpos.z).reject(centerpos, radarres/2)) drawradarent(e->x*coordtrans, e->y*coordtrans, 0, 3, f.team, iconsize, false); // draw on entitiy pos + } } - if(radar) - { - glPushMatrix(); - glDisable(GL_BLEND); - - const float worldsize = (float)ssize; - const float radarviewsize = fullscreen ? VIRTH : VIRTH/6; - const float radarsize = worldsize/radarres*radarviewsize; - - if(fullscreen) glTranslatef(VIRTW/2-radarviewsize/2, 0, 0); - else glTranslatef(VIRTW-radarviewsize-10, 10, 0); - - vec centerpos(min(max(center.x, radarres/2), worldsize-radarres/2), min(max(center.y, radarres/2), worldsize-radarres/2), 0); - quad(radar, 0, 0, radarviewsize, (centerpos.x-radarres/2)/worldsize, (centerpos.y-radarres/2)/worldsize, radarres/worldsize); - glTranslatef(-(centerpos.x-radarres/2)/worldsize*radarsize, -(centerpos.y-radarres/2)/worldsize*radarsize, 0); - - const float iconsize = radarentsize/(float)radarres*radarviewsize; - const float coordtrans = radarsize/worldsize; - - drawradarent(player1->o.x*coordtrans, player1->o.y*coordtrans, player1->yaw, player1->state==CS_ALIVE ? (player1->attacking ? 2 : 0) : 1, 2, iconsize, false); // local player - loopv(players) // other players - { - playerent *pl = players[i]; - if(!pl || !isteam(player1->team, pl->team) || (centerpos.z=pl->o.z && centerpos.reject(pl->o, radarres/2))) continue; - drawradarent(pl->o.x*coordtrans, pl->o.y*coordtrans, pl->yaw, pl->state==CS_ALIVE ? (pl->attacking ? 2 : 0) : 1, team_int(pl->team), iconsize, false); - } - if(m_ctf) - { - glColor4f(1.0f, 1.0f, 1.0f, (sinf(lastmillis / 100.0f) + 1.0f) / 2.0f); - loopi(2) // flag items - { - flaginfo &f = flaginfos[i]; - entity *e = f.flag; - if(!e) continue; - if(f.state==CTFF_STOLEN && f.actor && (centerpos.z=f.actor->o.z && !centerpos.reject(f.actor->o, radarres/2))) - drawradarent(f.actor->o.x*coordtrans+iconsize/2, f.actor->o.y*coordtrans+iconsize/2, 0, 3, f.team, iconsize, true); // draw near flag thief - else if(!vec(e->x, e->y, centerpos.z).reject(centerpos, radarres/2)) drawradarent(e->x*coordtrans, e->y*coordtrans, 0, 3, f.team, iconsize, false); // draw on entitiy pos - } - } - - glEnable(GL_BLEND); - glPopMatrix(); - } + glEnable(GL_BLEND); + glPopMatrix(); } void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) @@ -627,7 +613,7 @@ void loadingscreen() glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glOrtho(0, VIRTW, VIRTH, 0, -1, 1); - quad(logo, (VIRTW-VIRTH)/2, 0, VIRTH, 0, 0, 1); + quad(logo->id, (VIRTW-VIRTH)/2, 0, VIRTH, 0, 0, 1); SDL_GL_SwapBuffers(); } glDisable(GL_BLEND); diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 6d5b04c9..15323d0b 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -61,14 +61,14 @@ void cleangl() { } -void createtexture(int tnum, int w, int h, void *pixels, int clamp, GLenum format) +void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format) { glBindTexture(GL_TEXTURE_2D, tnum); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp&1 ? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp&2 ? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int tw = w, th = h; @@ -81,7 +81,11 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, GLenum forma th = h; } } - if(gluBuild2DMipmaps(GL_TEXTURE_2D, format, tw, th, format, GL_UNSIGNED_BYTE, pixels)) fatal("could not build mipmaps"); + if(mipmap) + { + if(gluBuild2DMipmaps(GL_TEXTURE_2D, format, tw, th, format, GL_UNSIGNED_BYTE, pixels)) fatal("could not build mipmaps"); + } + else glTexImage2D(GL_TEXTURE_2D, 0, format, tw, th, 0, format, GL_UNSIGNED_BYTE, pixels); } GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) @@ -96,7 +100,7 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) } GLuint tnum; glGenTextures(1, &tnum); - createtexture(tnum, s->w, s->h, s->pixels, clamp, s->format->BitsPerPixel==24 ? GL_RGB : GL_RGBA); + createtexture(tnum, s->w, s->h, s->pixels, clamp, true, s->format->BitsPerPixel==24 ? GL_RGB : GL_RGBA); xs = s->w; ys = s->h; SDL_FreeSurface(s); @@ -226,7 +230,11 @@ void addstrip(int type, int tex, int start, int n) { vector *strips; - if(tex==DEFAULT_SKY) strips = &skystrips; + if(tex==DEFAULT_SKY) + { + if(minimap) return; + strips = &skystrips; + } else { stripbatch *sb = &stripbatches[renderedtex[tex]]; @@ -299,6 +307,89 @@ void transplayer() glTranslatef(-camera1->o.x, -camera1->o.z, -camera1->o.y); } +bool minimap = false, minimapdirty = true; +int minimaplastsize = 0; +GLuint minimaptex = 0; + +void clearminimap() +{ + minimapdirty = true; +} + +COMMAND(clearminimap, ARG_NONE); + +VARFP(minimapres, 7, 9, 10, clearminimap()); + +void drawminimap() +{ + if(!minimapdirty) return; + + extern int scr_w, scr_h; + int size = 1< scr_w || size > scr_h) size /= 2; + if(size!=minimaplastsize) + { + glDeleteTextures(1, &minimaptex); + minimaptex = 0; + } + if(!minimaptex) + { + glGenTextures(1, &minimaptex); + createtexture(minimaptex, size, size, NULL, 3, false, GL_RGB); + minimaplastsize = size; + } + + minimap = true; + + physent minicam; + camera1 = &minicam; + camera1->o.x = camera1->o.y = ssize/2; + camera1->o.z = 128; + camera1->pitch = -90; + camera1->yaw = 0; + + glViewport(0, 0, size, size); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-ssize/2, ssize/2, -ssize/2, ssize/2, 0, 256); + glScalef(1, -1, 1); + glMatrixMode(GL_MODELVIEW); + + glCullFace(GL_BACK); + glDisable(GL_FOG); + glEnable(GL_TEXTURE_2D); + + transplayer(); + + resetcubes(); + + render_world(camera1->o.x, camera1->o.y, camera1->o.z, 250.0f, + (int)camera1->yaw, (int)camera1->pitch, 90.0f, size, size); + finishstrips(); + + setupworld(); + + overbright(2); + renderstrips(); + renderentities(); + overbright(1); + + minimap = false; + + glBindTexture(GL_TEXTURE_2D, minimaptex); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size, size); + minimapdirty = false; + + glCullFace(GL_FRONT); + glEnable(GL_FOG); + glDisable(GL_TEXTURE_2D); + + glViewport(0, 0, scr_w, scr_h); +} + VARP(fov, 90, 100, 120); int xtraverts; @@ -343,6 +434,8 @@ bool outsidemap(physent *pl) void gl_drawframe(int w, int h, float changelod, float curfps) { + drawminimap(); + recomputecamera(); float hf = hdr.waterlevel-0.3f; @@ -442,71 +535,3 @@ void gl_drawframe(int w, int h, float changelod, float curfps) glEnable(GL_FOG); } -/* -todo: refactor this & gl_drawframe - set image res to 512^2 - save as png? -*/ - -void createminimap(char *map) -{ - if(!map) return; - - extern void toggleocull(); - extern void screenshot(char *imagepath); - extern int scr_w, scr_h; - - int changelod = 100, curfps = 100; - - toggleocull(); - - camera1 = new physent(); - camera1->o.x = camera1->o.y = ssize/2; - camera1->o.z = ssize/3; - camera1->pitch = -90; - camera1->yaw = 0; - - glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-ssize/2, ssize/2, -ssize/2, ssize/2, -1, ssize); - glMatrixMode(GL_MODELVIEW); - - glEnable(GL_TEXTURE_2D); - - resetcubes(); - - render_world(camera1->o.x, camera1->o.y, camera1->o.z, changelod, - (int)camera1->yaw, (int)camera1->pitch, (float)fov, scr_w, scr_h); - finishstrips(); - - setupworld(); - - renderstripssky(); - - glLoadIdentity(); - glRotatef(camera1->pitch, -1, 0, 0); - glRotatef(camera1->yaw, 0, 1, 0); - glRotatef(90, 1, 0, 0); - glColor3f(1, 1, 1); - glDisable(GL_FOG); - glDepthFunc(GL_GREATER); - draw_envbox(fog*4/3); - glDepthFunc(GL_LESS); - glEnable(GL_FOG); - - transplayer(); - overbright(2); - renderstrips(); - renderentities(); - - delete camera1; - toggleocull(); - - screenshot(map); -} - -COMMAND(createminimap, ARG_NONE); - diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index 860599e2..f6068f81 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -400,7 +400,7 @@ struct vertmodel : model #endif if(aasize > 1<0 ? 2 : -2) : y/x; } int isoccluded(float vx, float vy, float cx, float cy, float csize) // v = viewer, c = cube to test { - if(!ocull) return 0; + if(!ocull || minimap) return 0; float nx = vx, ny = vy; // n = point on the border of the cube that is closest to v if(nxdefer && !s->occluded && mip && xx>=lx && xx=ly && yytype==SPACE || s->type==CHF) && s->floor<=vh && render_floor) + { + render_flat(s->ftex, xx<floor, s, t, u, v, false); + if(s->floortype==FHF) + { + render_flatdelta(s->ftex, xx<floor-s->vdelta/4.0ftype==SPACE || s->type==FHF) && s->ceil>=vh && render_ceil) render_flat(s->ctex, xx<ceil, s, t, u, v, true); @@ -160,21 +176,7 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, render_flatdelta(s->ctex, xx<type==SPACE || s->type==CHF) && s->floor<=vh && render_floor) - { - render_flat(s->ftex, xx<floor, s, t, u, v, false); - if(s->floortype==FHF) - { - render_flatdelta(s->ftex, xx<floor-s->vdelta/4.0f