*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@884 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2007-04-02 03:32:23 +00:00
parent 121280de74
commit cd34a82291
8 changed files with 165 additions and 150 deletions
+1
View File
@@ -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;
+2 -2
View File
@@ -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();
+42 -56
View File
@@ -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 &center, 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);
+98 -73
View File
@@ -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<strip> *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<<minimapres;
while(size > 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);
+1 -1
View File
@@ -400,7 +400,7 @@ struct vertmodel : model
#endif
if(aasize > 1<<dynshadowsize)
gluScaleImage(GL_ALPHA, aasize, aasize, GL_UNSIGNED_BYTE, pixels, 1<<dynshadowsize, 1<<dynshadowsize, GL_UNSIGNED_BYTE, pixels);
createtexture(shadows[frame], min(aasize, 1<<dynshadowsize), min(aasize, 1<<dynshadowsize), pixels, 3, GL_ALPHA);
createtexture(shadows[frame], min(aasize, 1<<dynshadowsize), min(aasize, 1<<dynshadowsize), pixels, 3, true, GL_ALPHA);
}
void genshadows(float height, float rad)
+1
View File
@@ -369,6 +369,7 @@ void load_world(char *mname) // still supports all map formats that have
c2skeepalive();
preload_mapmodels();
c2skeepalive();
clearminimap();
}
COMMANDN(savemap, save_world, ARG_1STR);
+1 -1
View File
@@ -70,7 +70,7 @@ inline float ma(float x, float y) { return x==0 ? (y>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(nx<cx) nx = cx;
+19 -17
View File
@@ -142,9 +142,9 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs,
if(s->defer && !s->occluded && mip && xx>=lx && xx<rx && yy>=ly && yy<ry)
#define LOOPD sqr *t = SWS(s,1,0,sz); \
sqr *u = SWS(s,1,1,sz); \
sqr *v = SWS(s,0,1,sz); \
sqr *v = SWS(s,0,1,sz);
LOOPH // ceils
LOOPH // floors
{
int start = yy;
sqr *next;
@@ -153,6 +153,22 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs,
continue;
}
stats[mip]++;
LOOPD
if((s->type==SPACE || s->type==CHF) && s->floor<=vh && render_floor)
{
render_flat(s->ftex, xx<<mip, yy<<mip, 1<<mip, s->floor, s, t, u, v, false);
if(s->floor<hdr.waterlevel && !SOLID(s)) addwaterquad(xx<<mip, yy<<mip, 1<<mip);
}
if(s->type==FHF)
{
render_flatdelta(s->ftex, xx<<mip, yy<<mip, 1<<mip, df(s), df(t), df(u), df(v), s, t, u, v, false);
if(s->floor-s->vdelta/4.0f<hdr.waterlevel && !SOLID(s)) addwaterquad(xx<<mip, yy<<mip, 1<<mip);
}
}}
if(minimap) return; // minimap only shows floors
LOOPH continue; // ceils
LOOPD
if((s->type==SPACE || s->type==FHF) && s->ceil>=vh && render_ceil)
render_flat(s->ctex, xx<<mip, yy<<mip, 1<<mip, s->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<<mip, yy<<mip, 1<<mip, dc(s), dc(t), dc(u), dc(v), s, t, u, v, true);
}}
LOOPH continue; // floors
LOOPD
if((s->type==SPACE || s->type==CHF) && s->floor<=vh && render_floor)
{
render_flat(s->ftex, xx<<mip, yy<<mip, 1<<mip, s->floor, s, t, u, v, false);
if(s->floor<hdr.waterlevel && !SOLID(s)) addwaterquad(xx<<mip, yy<<mip, 1<<mip);
}
if(s->type==FHF)
{
render_flatdelta(s->ftex, xx<<mip, yy<<mip, 1<<mip, df(s), df(t), df(u), df(v), s, t, u, v, false);
if(s->floor-s->vdelta/4.0f<hdr.waterlevel && !SOLID(s)) addwaterquad(xx<<mip, yy<<mip, 1<<mip);
}
}}
LOOPH continue; // walls
LOOPH continue; // walls
LOOPD
// w
// zSt