From ff6481e8c57e6a126b6a5442cb6ac5b3171dc979 Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 1 Apr 2007 23:42:03 +0000 Subject: [PATCH] minimap git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@880 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/main.cpp | 6 +++- source/src/protos.h | 1 + source/src/renderextras.cpp | 11 ++++--- source/src/rendergl.cpp | 62 +++++++++++++++++++++++++++++++++++++ source/src/rendermodel.cpp | 3 +- 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index a61e8f3d..3a2189ea 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -57,7 +57,11 @@ void screenshot(char *imagepath) memcpy(dest, (char *)image->pixels+image->pitch*(scr_h-1-idx), 3*scr_w); endianswap(dest, 3, scr_w); } - if(!imagepath) s_sprintf(imagepath)("screenshots/screenshot_%d.bmp", lastmillis); + if(!imagepath) + { + imagepath = new string; + s_sprintf(imagepath)("screenshots/screenshot_%d.bmp", lastmillis); + } SDL_SaveBMP(temp, path(imagepath)); SDL_FreeSurface(temp); } diff --git a/source/src/protos.h b/source/src/protos.h index 5fd81c16..48430a78 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -58,6 +58,7 @@ 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); // rendercubes extern void resetcubes(); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 36101ec0..da521072 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -341,14 +341,15 @@ 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 char *map = NULL; - + static string map; char *curmap = getclientmap(); - if(!map || strcmp(map, curmap)) // update once on map load + if(strcmp(map, curmap)) // update once on map load { - map = curmap; - s_sprintfd(texpath)("packages/%s.jpg", map); + 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); } diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index d4cd33b7..180c78c6 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -441,3 +441,65 @@ void gl_drawframe(int w, int h, float changelod, float curfps) glEnable(GL_CULL_FACE); glEnable(GL_FOG); } + +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); \ No newline at end of file diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index c7d6f98e..bde41394 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -183,5 +183,4 @@ void preload_mapmodels() if(!loadmodel(NULL, e.attr2)) continue; if(e.attr4) lookuptexture(e.attr4, xs, ys); } -} - +} \ No newline at end of file