less ugly mapdims
replaced the mapdims array with a struct with properly identified members also reduced the calclight postfilter to actually used map areas
This commit is contained in:
+2
-1
@@ -483,6 +483,7 @@ extern void teamflagscores(int &team1, int &team2);
|
||||
extern void setupworld(int factor);
|
||||
extern void sqrdefault(sqr *s);
|
||||
extern bool worldbordercheck(int x1, int x2, int y1, int y2, int z1, int z2);
|
||||
extern void calcmapdims();
|
||||
extern bool empty_world(int factor, bool force);
|
||||
extern void remip(const block &b, int level = 0);
|
||||
extern void remipmore(const block &b, int level = 0);
|
||||
@@ -679,7 +680,7 @@ extern bool addscorchmark(vec &o, float radius = 7);
|
||||
extern void render_particles(int time, int typemask = ~0);
|
||||
|
||||
// worldio
|
||||
extern int mapdims[8];
|
||||
extern mapdim mapdims;
|
||||
extern const char *setnames(const char *name);
|
||||
extern void save_world(char *mname, bool skipoptimise = false, bool addcomfort = false);
|
||||
extern bool load_world(char *mname);
|
||||
|
||||
+17
-17
@@ -506,9 +506,9 @@ void recomputecamera()
|
||||
case SM_OVERVIEW:
|
||||
{
|
||||
// TODO : fix water rendering
|
||||
camera1->o.x = mapdims[0] + mapdims[4]/2;
|
||||
camera1->o.y = mapdims[1] + mapdims[5]/2;
|
||||
camera1->o.z = mapdims[7] + 1;
|
||||
camera1->o.x = mapdims.xm;
|
||||
camera1->o.y = mapdims.ym;
|
||||
camera1->o.z = mapdims.maxceil + 1;
|
||||
camera1->pitch = -90;
|
||||
camera1->yaw = 0;
|
||||
|
||||
@@ -798,14 +798,14 @@ void drawminimap(int w, int h)
|
||||
physent minicam;
|
||||
camera1 = &minicam;
|
||||
camera1->type = ENT_CAMERA;
|
||||
camera1->o.x = mapdims[0] + mapdims[4]/2.0f;
|
||||
camera1->o.y = mapdims[1] + mapdims[5]/2.0f;
|
||||
camera1->o.x = mapdims.xm;
|
||||
camera1->o.y = mapdims.ym;
|
||||
|
||||
//float gdim = max(mapdims[4], mapdims[5])+2.0f; //make 1 cube smaller to give it a black edge
|
||||
float gdim = max(mapdims[4], mapdims[5]); //no border
|
||||
//float gdim = max(mapdims.xspan, mapdims.yspan)+2.0f; //make 1 cube smaller to give it a black edge
|
||||
float gdim = max(mapdims.xspan, mapdims.yspan); //no border
|
||||
|
||||
if(!gdim) gdim = ssize/2.0f;
|
||||
camera1->o.z = mapdims[7] + 1;
|
||||
if(gdim < 1) gdim = ssize/2.0f;
|
||||
camera1->o.z = mapdims.maxceil + 1;
|
||||
camera1->pitch = -90;
|
||||
camera1->yaw = 0;
|
||||
|
||||
@@ -820,7 +820,7 @@ void drawminimap(int w, int h)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // stencil added 2010jul22
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-orthd, orthd, -orthd, orthd, 0, (mapdims[7]-mapdims[6])+2); // depth of map +2 covered
|
||||
glOrtho(-orthd, orthd, -orthd, orthd, 0, (mapdims.maxceil - mapdims.minfloor) + 2); // depth of map +2 covered
|
||||
glScalef(1, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glCullFace(GL_BACK);
|
||||
@@ -836,7 +836,7 @@ void drawminimap(int w, int h)
|
||||
renderstrips();
|
||||
glDepthFunc(GL_LESS);
|
||||
rendermapmodels();
|
||||
renderzones(mapdims[7]);
|
||||
renderzones(mapdims.maxceil);
|
||||
//renderentities();// IMHO better done by radar itself, if at all
|
||||
resettmu(0);
|
||||
float hf = hdr.waterlevel-0.3f;
|
||||
@@ -849,10 +849,10 @@ void drawminimap(int w, int h)
|
||||
glColor3f(0, 0, 0);
|
||||
glLineWidth(2.0f);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3f(mapdims[0]+0.02f, mapdims[1]+0.02f, mapdims[7]);
|
||||
glVertex3f(mapdims[0]+mapdims[4]-0.02f, mapdims[1]+0.02f, mapdims[7]);
|
||||
glVertex3f(mapdims[0]+mapdims[4]-0.02f, mapdims[1]+mapdims[5]-0.02f, mapdims[7]);
|
||||
glVertex3f(mapdims[0]+0.02f, mapdims[1]+mapdims[5]-0.02f, mapdims[7]);
|
||||
glVertex3f(mapdims.x1 + 0.02f, mapdims.y1 + 0.02f, mapdims.maxceil);
|
||||
glVertex3f(mapdims.x1 + mapdims.xspan - 0.02f, mapdims.y1 + 0.02f, mapdims.maxceil);
|
||||
glVertex3f(mapdims.x1 + mapdims.xspan - 0.02f, mapdims.y1 + mapdims.yspan - 0.02f, mapdims.maxceil);
|
||||
glVertex3f(mapdims.x1 + 0.02f, mapdims.y1 + mapdims.yspan - 0.02f, mapdims.maxceil);
|
||||
glEnd();
|
||||
glLineWidth(prevLineWidth);
|
||||
glEnable(GL_BLEND);
|
||||
@@ -904,10 +904,10 @@ void setperspective(float fovy, float aspect, float nearplane, float farplane)
|
||||
GLdouble ydist = nearplane * tan(fovy/2*RAD), xdist = ydist * aspect;
|
||||
if(player1->isspectating() && player1->spectatemode == SM_OVERVIEW)
|
||||
{
|
||||
int gdim = max(mapdims[4], mapdims[5]);
|
||||
int gdim = max(mapdims.xspan, mapdims.yspan);
|
||||
if(!gdim) gdim = ssize/2;
|
||||
int orthd = 2 + gdim/2;
|
||||
glOrtho(-orthd, orthd, -orthd, orthd, 0, (mapdims[7]-mapdims[6])+2); // depth of map +2 covered
|
||||
glOrtho(-orthd, orthd, -orthd, orthd, 0, (mapdims.maxceil - mapdims.minfloor) + 2); // depth of map +2 covered
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+13
-14
@@ -534,15 +534,14 @@ void drawradar_showmap(playerent *p, int w, int h)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
float gdim = max(mapdims[4], mapdims[5]); //no border
|
||||
float coordtrans = (minimapviewsize)/(gdim);
|
||||
|
||||
float offd = fabs(float(mapdims[5])-float(mapdims[4])) /2.0f;
|
||||
float gdim = max(mapdims.xspan, mapdims.yspan); //no border
|
||||
float offd = fabs((mapdims.yspan - mapdims.xspan) / 2.0f);
|
||||
if(!gdim) { gdim = ssize/2.0f; offd = 0; }
|
||||
float offx = gdim==mapdims[5] ? offd : 0;
|
||||
float offy = gdim==mapdims[4] ? offd : 0;
|
||||
float coordtrans = minimapviewsize / gdim;
|
||||
float offx = gdim == mapdims.yspan ? offd : 0;
|
||||
float offy = gdim == mapdims.xspan ? offd : 0;
|
||||
|
||||
vec mdd = vec(mapdims[0]-offx, mapdims[1]-offy, 0);
|
||||
vec mdd = vec(mapdims.x1 - offx, mapdims.y1 - offy, 0);
|
||||
vec cod(offx, offy, 0);
|
||||
vec ppv = vec(p->o).sub(mdd).mul(coordtrans);
|
||||
|
||||
@@ -600,18 +599,18 @@ void drawradar_showmap(playerent *p, int w, int h)
|
||||
void drawradar_vicinity(playerent *p, int w, int h)
|
||||
{
|
||||
extern GLuint minimaptex;
|
||||
int gdim = max(mapdims[4], mapdims[5]);
|
||||
int gdim = max(mapdims.xspan, mapdims.yspan);
|
||||
float radarviewsize = min(VIRTW,VIRTH)/5;
|
||||
float halfviewsize = radarviewsize/2.0f;
|
||||
float iconsize = radarentsize/0.4f;
|
||||
float scaleh = radarheight/(2.0f*gdim);
|
||||
float scaled = radarviewsize/float(radarheight);
|
||||
float offd = fabs((mapdims[5]-mapdims[4]) /2.0f);
|
||||
if(!gdim) { gdim = ssize/2; offd = 0; }
|
||||
float offx = gdim==mapdims[5]?offd:0;
|
||||
float offy = gdim==mapdims[4]?offd:0;
|
||||
vec rtr = vec(mapdims[0]-offx, mapdims[1]-offy, 0);
|
||||
vec rsd = vec(mapdims[0]+mapdims[4]/2, mapdims[1]+mapdims[5]/2, 0);
|
||||
float offd = fabs((mapdims.yspan - mapdims.xspan) / 2.0f);
|
||||
if(gdim < 1) { gdim = ssize/2; offd = 0; }
|
||||
float offx = gdim == mapdims.yspan ? offd : 0;
|
||||
float offy = gdim==mapdims.xspan ? offd : 0;
|
||||
vec rtr = vec(mapdims.x1 - offx, mapdims.y1 - offy, 0);
|
||||
vec rsd = vec(mapdims.xm, mapdims.ym, 0);
|
||||
float d2s = radarheight/2.0f;
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glPushMatrix();
|
||||
|
||||
+11
-9
@@ -59,7 +59,7 @@ int fixmapheadersize(int version, int headersize) // we can't trust hdr.header
|
||||
return headersize;
|
||||
}
|
||||
|
||||
int mapdims[8]; // min/max X/Y and delta X/Y and min/max Z
|
||||
mapdim mapdims; // min/max X/Y and delta X/Y and min/max Z
|
||||
|
||||
extern char *maplayout, *testlayout;
|
||||
extern int maplayout_factor, testlayout_factor, Mvolume, Marea, Mopen, SHhits;
|
||||
@@ -189,19 +189,21 @@ mapstats *loadmapstats(const char *filename, bool getlayout)
|
||||
maplayout = new char[layoutsize + 256];
|
||||
memcpy(maplayout, testlayout, layoutsize * sizeof(char));
|
||||
|
||||
loopk(8) mapdims[k] = k < 2 ? maplayoutssize : 0;
|
||||
memset(&mapdims, 0, sizeof(struct mapdim));
|
||||
mapdims.x1 = mapdims.y1 = maplayoutssize;
|
||||
loopk(layoutsize) if (testlayout[k] != 127)
|
||||
{
|
||||
int cwx = k%maplayoutssize,
|
||||
cwy = k/maplayoutssize;
|
||||
if(cwx < mapdims[0]) mapdims[0] = cwx;
|
||||
if(cwy < mapdims[1]) mapdims[1] = cwy;
|
||||
if(cwx > mapdims[2]) mapdims[2] = cwx;
|
||||
if(cwy > mapdims[3]) mapdims[3] = cwy;
|
||||
if(cwx < mapdims.x1) mapdims.x1 = cwx;
|
||||
if(cwy < mapdims.y1) mapdims.y1 = cwy;
|
||||
if(cwx > mapdims.x2) mapdims.x2 = cwx;
|
||||
if(cwy > mapdims.y2) mapdims.y2 = cwy;
|
||||
}
|
||||
loopk(2) mapdims[k+4] = mapdims[k+2] - mapdims[k];
|
||||
mapdims[6] = minfloor;
|
||||
mapdims[7] = maxceil;
|
||||
mapdims.xspan = mapdims.x2 - mapdims.x1;
|
||||
mapdims.yspan = mapdims.y2 - mapdims.y1;
|
||||
mapdims.minfloor = minfloor;
|
||||
mapdims.maxceil = maxceil;
|
||||
}
|
||||
}
|
||||
delete f;
|
||||
|
||||
+34
-6
@@ -447,6 +447,39 @@ bool worldbordercheck(int x1, int x2, int y1, int y2, int z1, int z2) // check
|
||||
return true;
|
||||
}
|
||||
|
||||
void calcmapdims()
|
||||
{
|
||||
mapdims.x1 = mapdims.y1 = ssize;
|
||||
mapdims.x2 = mapdims.y2 = 0;
|
||||
mapdims.minfloor = 127; mapdims.maxceil = -128; // flow initialised those two with "0", but i'd guess, that was by mistake
|
||||
sqr *s = world;
|
||||
for(int y = 0; y < ssize; y++) for(int x = 0; x < ssize; x++)
|
||||
{
|
||||
if(!SOLID(s))
|
||||
{
|
||||
if(x < mapdims.x1) mapdims.x1 = x;
|
||||
if(x > mapdims.x2) mapdims.x2 = x;
|
||||
if(y < mapdims.y1) mapdims.y1 = y;
|
||||
mapdims.y2 = y;
|
||||
if(s->floor < mapdims.minfloor) mapdims.minfloor = s->floor; // for some reason, flow excluded cubes with floor == -128 here - let's try without that...
|
||||
if(s->ceil > mapdims.maxceil) mapdims.maxceil = s->ceil;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if(mapdims.x2 < mapdims.x1 || mapdims.y2 < mapdims.y1)
|
||||
{ // map is completely solid -> default to empty map values
|
||||
mapdims.x1 = mapdims.y1 = 2;
|
||||
mapdims.x2 = mapdims.y2 = ssize - 3;
|
||||
mapdims.minfloor = 0;
|
||||
mapdims.maxceil = 16;
|
||||
}
|
||||
if(mapdims.x1 < 2 || mapdims.y1 < 2 || mapdims.x2 > ssize - 3 || mapdims.y2 > ssize - 3) fatal("calcmapdims(): border violation");
|
||||
mapdims.xspan = mapdims.x2 - mapdims.x1 + 1;
|
||||
mapdims.yspan = mapdims.y2 - mapdims.y1 + 1;
|
||||
mapdims.xm = mapdims.x1 + mapdims.xspan / 2.0f;
|
||||
mapdims.ym = mapdims.y1 + mapdims.yspan / 2.0f;
|
||||
}
|
||||
|
||||
bool empty_world(int factor, bool force) // main empty world creation routine, if passed factor -1 will enlarge old world by 1, factor -2 will shrink old world by 1
|
||||
{
|
||||
if(!force && noteditmode("empty world")) return false;
|
||||
@@ -509,6 +542,7 @@ bool empty_world(int factor, bool force) // main empty world creation routine
|
||||
hdr.headersize = sizeof(header);
|
||||
hdr.sfactor = sfactor;
|
||||
|
||||
calcmapdims();
|
||||
calclight();
|
||||
resetmap(!copy);
|
||||
if(clearmap)
|
||||
@@ -522,12 +556,6 @@ bool empty_world(int factor, bool force) // main empty world creation routine
|
||||
popscontext();
|
||||
setvar("fullbright", 1);
|
||||
fullbrightlight();
|
||||
|
||||
mapdims[0] = mapdims[1] = 0;
|
||||
mapdims[2] = mapdims[3] = ssize;
|
||||
mapdims[4] = mapdims[5] = ssize;
|
||||
mapdims[6] = 0;
|
||||
mapdims[7] = 16;
|
||||
}
|
||||
if(!copy)
|
||||
{
|
||||
|
||||
@@ -75,6 +75,14 @@ struct mapstats
|
||||
bool hasflags;
|
||||
};
|
||||
|
||||
struct mapdim
|
||||
{ // 0 2 1 3 6 7
|
||||
int x1, x2, y1, y2, minfloor, maxceil; // outer borders (points to last used cube)
|
||||
// 4 5
|
||||
int xspan, yspan; // size of area between x1|y1 and x2|y2
|
||||
float xm, ym; // middle of the map
|
||||
};
|
||||
|
||||
#define SWS(w,x,y,s) (&(w)[((y)<<(s))+(x)])
|
||||
#define SW(w,x,y) SWS(w,x,y,sfactor)
|
||||
#define S(x,y) SW(world,x,y) // convenient lookup of a lowest mip cube
|
||||
|
||||
+5
-15
@@ -519,12 +519,11 @@ VARP(preserveundosonsave, 0, 0, 1);
|
||||
COMMANDF(savemap, "s", (char *name) { save_world(name, preserveundosonsave && editmode, preserveundosonsave && editmode); } );
|
||||
COMMANDF(savemapoptimised, "s", (char *name) { save_world(name, false, false); } );
|
||||
|
||||
extern int mapdims[8]; // min/max X/Y and delta X/Y and min-floor/max-ceil
|
||||
void showmapdims()
|
||||
{
|
||||
conoutf(" min X|Y|Z: %3d : %3d : %3d", mapdims[0], mapdims[1], mapdims[6]);
|
||||
conoutf(" max X|Y|Z: %3d : %3d : %3d", mapdims[2], mapdims[3], mapdims[7]);
|
||||
conoutf("delta X|Y|Z: %3d : %3d : %3d", mapdims[4], mapdims[5], mapdims[7]-mapdims[6]);
|
||||
conoutf(" min X|Y|Z: %3d : %3d : %3d", mapdims.x1, mapdims.y1, mapdims.minfloor);
|
||||
conoutf(" max X|Y|Z: %3d : %3d : %3d", mapdims.x2, mapdims.y2, mapdims.maxceil);
|
||||
conoutf("delta X|Y|Z: %3d : %3d : %3d", mapdims.xspan, mapdims.yspan, mapdims.maxceil - mapdims.minfloor);
|
||||
}
|
||||
COMMAND(showmapdims, "");
|
||||
|
||||
@@ -684,7 +683,6 @@ bool load_world(char *mname) // still supports all map formats that have
|
||||
Mv = Ma = Hhits = 0;
|
||||
char texuse[256];
|
||||
loopi(256) texuse[i] = 0;
|
||||
loopk(8) mapdims[k] = k < 2 ? ssize : 0;
|
||||
loopk(cubicsize)
|
||||
{
|
||||
sqr *s = &world[k];
|
||||
@@ -700,21 +698,13 @@ bool load_world(char *mname) // still supports all map formats that have
|
||||
Mv += diff;
|
||||
}
|
||||
texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1;
|
||||
int cwx = k%ssize,
|
||||
cwy = k/ssize;
|
||||
if(cwx < mapdims[0]) mapdims[0] = cwx;
|
||||
if(cwy < mapdims[1]) mapdims[1] = cwy;
|
||||
if(cwx > mapdims[2]) mapdims[2] = cwx;
|
||||
if(cwy > mapdims[3]) mapdims[3] = cwy;
|
||||
if(s->floor != -128 && s->floor < mapdims[6]) mapdims[6] = s->floor;
|
||||
if(s->ceil > mapdims[7]) mapdims[7] = s->ceil;
|
||||
}
|
||||
texuse[s->wtex] = 1;
|
||||
}
|
||||
Mh = Ma ? (float)Mv/Ma : 0;
|
||||
loopk(2) mapdims[k+4] = mapdims[k+2] + 1 - mapdims[k]; // 8..15 ^= 8 cubes - minimal X/Y == 2 - != 0 !!
|
||||
c2skeepalive();
|
||||
|
||||
c2skeepalive();
|
||||
calcmapdims();
|
||||
calclight();
|
||||
conoutf("read map %s rev %d (%d milliseconds)", cgzname, hdr.maprevision, watch.stop());
|
||||
conoutf("%s", hdr.maptitle);
|
||||
|
||||
@@ -178,6 +178,7 @@ VARF(ambient, 0, 0, 0xFFFFFF, if(!noteditmode("ambient")) { hdr.ambient = ambien
|
||||
|
||||
void calclight()
|
||||
{
|
||||
if(editmode) calcmapdims();
|
||||
uchar r = (hdr.ambient>>16) & 0xFF, g = (hdr.ambient>>8) & 0xFF, b = hdr.ambient & 0xFF;
|
||||
if(!r && !g)
|
||||
{
|
||||
@@ -205,7 +206,7 @@ void calclight()
|
||||
|
||||
seedMT(keep);
|
||||
|
||||
block bb = { 1, 1, ssize-2, ssize-2 };
|
||||
block bb = { mapdims.x1 - 1, mapdims.y1 - 1, mapdims.x2 + 1, mapdims.y2 + 1 };
|
||||
postlightarea(bb);
|
||||
setvar("fullbright", 0);
|
||||
lastcalclight = totalmillis;
|
||||
|
||||
Reference in New Issue
Block a user