summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorxolatile2025-08-04 18:17:30 +0200
committerxolatile2025-08-04 18:17:30 +0200
commita89dca11cf475e0bd1399cf5d5c5135d00495ec3 (patch)
tree4d551a7f4193bc89a0b8560e955f4f874101b388 /src/engine
parent9d533fa4d82935a083ff93a09aed95baea9fbfd4 (diff)
downloadxolatile-badassbug-a89dca11cf475e0bd1399cf5d5c5135d00495ec3.tar.xz
xolatile-badassbug-a89dca11cf475e0bd1399cf5d5c5135d00495ec3.tar.zst
Minor changes...
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/animmodel.h85
-rw-r--r--src/engine/bih.h3
-rw-r--r--src/engine/depthfx.h23
-rw-r--r--src/engine/engine.h5
-rw-r--r--src/engine/glare.cpp8
-rw-r--r--src/engine/lightmap.h18
-rw-r--r--src/engine/main.cpp41
-rw-r--r--src/engine/master.cpp16
-rw-r--r--src/engine/material.cpp72
-rw-r--r--src/engine/rendergl.cpp76
-rw-r--r--src/engine/rendermodel.cpp2
-rw-r--r--src/engine/renderparticles.cpp37
-rw-r--r--src/engine/rendertarget.h93
-rw-r--r--src/engine/renderva.cpp5
-rw-r--r--src/engine/server.cpp357
-rw-r--r--src/engine/serverbrowser.cpp50
-rw-r--r--src/engine/shadowmap.cpp23
-rw-r--r--src/engine/sound.cpp152
-rw-r--r--src/engine/textedit.h158
-rw-r--r--src/engine/texture.cpp409
-rw-r--r--src/engine/texture.h1
-rw-r--r--src/engine/water.cpp8
-rw-r--r--src/engine/worldio.cpp13
23 files changed, 256 insertions, 1399 deletions
diff --git a/src/engine/animmodel.h b/src/engine/animmodel.h
index 16d5189..df30231 100644
--- a/src/engine/animmodel.h
+++ b/src/engine/animmodel.h
@@ -19,7 +19,7 @@ struct animmodel : model
void setframes(const animinfo &info)
{
anim = info.anim;
- if(info.range<=1)
+ if(info.range<=1)
{
fr1 = 0;
t = 0;
@@ -149,7 +149,7 @@ struct animmodel : model
}
else
{
- float bias = max(mincolor-1.0f, 0.2f), scale = 0.5f*max(0.8f-bias, 0.0f),
+ float bias = max(mincolor-1.0f, 0.2f), scale = 0.5f*max(0.8f-bias, 0.0f),
minshade = scale*max(ambient, mincolor);
LOCALPARAMF(lightscale, scale - minshade, scale, minshade + bias);
}
@@ -178,7 +178,7 @@ struct animmodel : model
if(shader) return shader;
string opts;
- int optslen = 0;
+ int optslen = 0;
if(alphatested()) opts[optslen++] = 'a';
if(owner->tangents()) opts[optslen++] = 'q';
if(bumpmapped()) opts[optslen++] = 'n';
@@ -201,13 +201,13 @@ struct animmodel : model
{
if(tex->type&Texture::ALPHA && !tex->alphamask) loadalphamask(tex);
}
-
+
void preloadshader(bool force)
{
if(force) cleanup();
loadshader();
}
-
+
void setshader(mesh *m, const animstate *as)
{
m->setshader(loadshader());
@@ -314,17 +314,18 @@ struct animmodel : model
}
}
- virtual void setshader(Shader *s)
- {
+ virtual void setshader(Shader *s)
+ {
if(glaring) s->setvariant(0, 1);
- else s->set();
+ else s->set();
}
template<class V, class T> void smoothnorms(V *verts, int numverts, T *tris, int numtris, float limit, bool areaweight)
{
hashtable<vec, int> share;
int *next = new int[numverts];
- memset(next, -1, numverts*sizeof(int));
+ for(int i=0;i<numverts;++i)next[i]=-1;
+ //~memset(next, -1, numverts*sizeof(int));
loopi(numverts)
{
V &v = verts[i];
@@ -344,7 +345,8 @@ struct animmodel : model
v3.norm.add(norm);
}
vec *norms = new vec[numverts];
- memclear(norms, numverts);
+ for(int i=0;i<numverts;++i)norms[i]=vec(0,0,0);
+ //~memclear(norms, numverts);
loopi(numverts)
{
V &v = verts[i];
@@ -384,13 +386,13 @@ struct animmodel : model
}
loopi(numverts) verts[i].norm.normalize();
}
-
+
template<class V, class T> void buildnorms(V *verts, int numverts, T *tris, int numtris, bool areaweight, int numframes)
{
if(!numverts) return;
loopi(numframes) buildnorms(&verts[i*numverts], numverts, tris, numtris, areaweight);
}
-
+
static inline void fixqtangent(quat &q, float bt)
{
static const float bias = -1.5f/65535, biasscale = sqrtf(1 - bias*bias);
@@ -412,11 +414,12 @@ struct animmodel : model
fixqtangent(q, bt);
v.tangent = q;
}
-
+
template<class B, class V, class TC, class T> void calctangents(B *bumpverts, V *verts, TC *tcverts, int numverts, T *tris, int numtris, bool areaweight)
{
vec *tangent = new vec[2*numverts], *bitangent = tangent+numverts;
- memclear(tangent, 2*numverts);
+ for(int i=0;i<2*numverts;++i)tangent[i]=vec(0,0,0);
+ //~memclear(tangent, 2*numverts);
loopi(numtris)
{
const T &t = tris[i];
@@ -489,7 +492,7 @@ struct animmodel : model
DELETEA(name);
meshes.deletecontents();
DELETEP(next);
- }
+ }
virtual int findtag(const char *name) { return -1; }
virtual void concattagtransform(part *p, int i, const matrix4x3 &m, matrix4x3 &n) {}
@@ -760,7 +763,7 @@ struct animmodel : model
info.frame = 0;
info.range = meshes->totalframes();
}
- else
+ else
{
animspec *spec = NULL;
if(anims[animpart])
@@ -775,7 +778,7 @@ struct animmodel : model
{
int secondaryidx = (anim>>ANIM_SECONDARY)&ANIM_INDEX;
if(secondaryidx < NUMANIMS)
- {
+ {
vector<animspec> &secondary = anims[animpart][secondaryidx];
if(secondary.length())
{
@@ -826,7 +829,7 @@ struct animmodel : model
animinterpinfo &ai = d->animinterp[interp];
if((info.anim&ANIM_CLAMP)==ANIM_CLAMP) aitime = min(aitime, int(info.range*info.speed*0.5e-3f));
void *ak = meshes->animkey();
- if(d->ragdoll && !(anim&ANIM_RAGDOLL))
+ if(d->ragdoll && !(anim&ANIM_RAGDOLL))
{
ai.prev.range = ai.cur.range = 0;
ai.lastswitch = -1;
@@ -913,7 +916,7 @@ struct animmodel : model
meshes->render(as, pitch, oaxis, oforward, d, this);
- if(!(anim&ANIM_REUSE))
+ if(!(anim&ANIM_REUSE))
{
loopv(links)
{
@@ -1027,7 +1030,7 @@ struct animmodel : model
part *p = m->parts[0];
switch(linktype(m))
{
- case LINK_TAG:
+ case LINK_TAG:
if(p->index >= 0) unlink(p);
p->index = 0;
break;
@@ -1038,7 +1041,7 @@ struct animmodel : model
break;
case LINK_REUSE:
- p->render(anim | ANIM_REUSE, basetime, basetime2, pitch, axis, forward, d, as);
+ p->render(anim | ANIM_REUSE, basetime, basetime2, pitch, axis, forward, d, as);
break;
}
}
@@ -1093,7 +1096,7 @@ struct animmodel : model
if(transparent<1)
{
- if(anim&ANIM_GHOST)
+ if(anim&ANIM_GHOST)
{
glDepthFunc(GL_GREATER);
glDepthMask(GL_FALSE);
@@ -1117,7 +1120,7 @@ struct animmodel : model
render(anim, basetime, basetime2, pitch, axis, forward, d, a);
- if(transparent<1 && (alphadepth || anim&ANIM_GHOST))
+ if(transparent<1 && (alphadepth || anim&ANIM_GHOST))
{
glDepthFunc(GL_LESS);
if(anim&ANIM_GHOST) glDepthMask(GL_TRUE);
@@ -1269,7 +1272,7 @@ struct animmodel : model
void setglow(float glow, float delta, float pulse)
{
if(parts.empty()) loaddefaultparts();
- loopv(parts) loopvj(parts[i]->skins)
+ loopv(parts) loopvj(parts[i]->skins)
{
skin &s = parts[i]->skins[j];
s.glow = glow;
@@ -1318,7 +1321,7 @@ struct animmodel : model
if(parts.empty()) return;
vec bbmin(1e16f, 1e16f, 1e16f), bbmax(-1e16f, -1e16f, -1e16f);
matrix4x3 m;
- initmatrix(m);
+ initmatrix(m);
parts[0]->calcbb(bbmin, bbmax, m);
radius = bbmax;
radius.sub(bbmin);
@@ -1487,7 +1490,7 @@ template<class MDL, class MESH> struct modelcommands
}
#define loopskins(meshname, s, body) loopmeshes(meshname, m, { skin &s = mdl.skins[i]; body; })
-
+
static void setskin(char *meshname, char *tex, char *masks, float *envmapmax, float *envmapmin)
{
loopskins(meshname, s,
@@ -1500,7 +1503,7 @@ template<class MDL, class MESH> struct modelcommands
}
);
}
-
+
static void setspec(char *meshname, int *percent)
{
float spec = 1.0f;
@@ -1508,7 +1511,7 @@ template<class MDL, class MESH> struct modelcommands
else if(*percent<0) spec = 0.0f;
loopskins(meshname, s, s.spec = spec);
}
-
+
static void setambient(char *meshname, int *percent)
{
float ambient = 0.3f;
@@ -1516,7 +1519,7 @@ template<class MDL, class MESH> struct modelcommands
else if(*percent<0) ambient = 0.0f;
loopskins(meshname, s, s.ambient = ambient);
}
-
+
static void setglow(char *meshname, int *percent, int *delta, float *pulse)
{
float glow = 3.0f, glowdelta = *delta/100.0f, glowpulse = *pulse > 0 ? *pulse/1000.0f : 0;
@@ -1525,66 +1528,66 @@ template<class MDL, class MESH> struct modelcommands
glowdelta -= glow;
loopskins(meshname, s, { s.glow = glow; s.glowdelta = glowdelta; s.glowpulse = glowpulse; });
}
-
+
static void setglare(char *meshname, float *specglare, float *glowglare)
{
loopskins(meshname, s, { s.specglare = *specglare; s.glowglare = *glowglare; });
}
-
+
static void setalphatest(char *meshname, float *cutoff)
{
loopskins(meshname, s, s.alphatest = max(0.0f, min(1.0f, *cutoff)));
}
-
+
static void setalphablend(char *meshname, int *blend)
{
loopskins(meshname, s, s.alphablend = *blend!=0);
}
-
+
static void setcullface(char *meshname, int *cullface)
{
loopskins(meshname, s, s.cullface = *cullface!=0);
}
-
+
static void setenvmap(char *meshname, char *envmap)
{
Texture *tex = cubemapload(envmap);
loopskins(meshname, s, s.envmap = tex);
}
-
+
static void setbumpmap(char *meshname, char *normalmapfile)
{
Texture *normalmaptex = textureload(makerelpath(MDL::dir, normalmapfile), 0, true, false);
loopskins(meshname, s, s.normalmap = normalmaptex);
}
-
+
static void setfullbright(char *meshname, float *fullbright)
{
loopskins(meshname, s, s.fullbright = *fullbright);
}
-
+
static void setshader(char *meshname, char *shader)
{
loopskins(meshname, s, s.shader = lookupshaderbyname(shader));
}
-
+
static void setscroll(char *meshname, float *scrollu, float *scrollv)
{
loopskins(meshname, s, { s.scrollu = *scrollu; s.scrollv = *scrollv; });
}
-
+
static void setnoclip(char *meshname, int *noclip)
{
loopmeshes(meshname, m, m.noclip = *noclip!=0);
}
-
+
static void setlink(int *parent, int *child, char *tagname, float *x, float *y, float *z)
{
if(!MDL::loading) { conoutf(CON_ERROR, "not loading an %s", MDL::formatname()); return; }
if(!MDL::loading->parts.inrange(*parent) || !MDL::loading->parts.inrange(*child)) { conoutf(CON_ERROR, "no models loaded to link"); return; }
if(!MDL::loading->parts[*parent]->link(MDL::loading->parts[*child], tagname, vec(*x, *y, *z))) conoutf(CON_ERROR, "could not link model %s", MDL::loading->name);
}
-
+
template<class F> void modelcommand(F *fun, const char *suffix, const char *args)
{
defformatstring(name, "%s%s", MDL::formatname(), suffix);
diff --git a/src/engine/bih.h b/src/engine/bih.h
index 0f9482f..971e64b 100644
--- a/src/engine/bih.h
+++ b/src/engine/bih.h
@@ -71,9 +71,8 @@ struct BIH
bool traverse(const vec &o, const vec &ray, float maxdist, float &dist, int mode);
bool traverse(const mesh &m, const vec &o, const vec &ray, const vec &invray, float maxdist, float &dist, int mode, node *curnode, float tmin, float tmax);
bool triintersect(const mesh &m, int tidx, const vec &mo, const vec &mray, float maxdist, float &dist, int mode);
-
+
void preload();
};
extern bool mmintersect(const extentity &e, const vec &o, const vec &ray, float maxdist, int mode, float &dist);
-
diff --git a/src/engine/depthfx.h b/src/engine/depthfx.h
index a9c0fdf..8332ab5 100644
--- a/src/engine/depthfx.h
+++ b/src/engine/depthfx.h
@@ -15,7 +15,6 @@ VARP(depthfxparts, 0, 1, 1);
VARP(blurdepthfx, 0, 1, 7);
VARP(blurdepthfxsigma, 1, 50, 200);
VAR(depthfxscissor, 0, 2, 2);
-VAR(debugdepthfx, 0, 0, 1);
#define MAXDFXRANGES 4
@@ -73,7 +72,7 @@ static struct depthfxtexture : rendertarget
{
extern void finddepthfxranges();
finddepthfxranges();
- return (numdepthfxranges && scissorx1 < scissorx2 && scissory1 < scissory2) || debugdepthfx;
+ return (numdepthfxranges && scissorx1 < scissorx2 && scissory1 < scissory2);
}
bool dorender()
@@ -107,18 +106,6 @@ static struct depthfxtexture : rendertarget
return numdepthfxranges > 0;
}
-
- void dodebug(int w, int h)
- {
- if(numdepthfxranges > 0)
- {
- gle::colorf(0, 1, 0);
- debugscissor(w, h, true);
- gle::colorf(0, 0, 1);
- debugblurtiles(w, h, true);
- gle::colorf(1, 1, 1);
- }
- }
} depthfxtex;
void cleanupdepthfx()
@@ -126,17 +113,11 @@ void cleanupdepthfx()
depthfxtex.cleanup(true);
}
-void viewdepthfxtex()
-{
- if(!depthfx) return;
- depthfxtex.debug();
-}
-
bool depthfxing = false;
bool binddepthfxtex()
{
- if(!reflecting && !refracting && depthfx && depthfxtex.rendertex && numdepthfxranges>0)
+ if(!reflecting && !refracting && depthfx && depthfxtex.rendertex && numdepthfxranges>0)
{
glActiveTexture_(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, depthfxtex.rendertex);
diff --git a/src/engine/engine.h b/src/engine/engine.h
index dc0b240..a9d70ef 100644
--- a/src/engine/engine.h
+++ b/src/engine/engine.h
@@ -537,10 +537,6 @@ extern void checkmapsounds();
extern void updatesounds();
extern void preloadmapsounds();
-extern void initmumble();
-extern void closemumble();
-extern void updatemumble();
-
// blendmap
extern int blendpaintmode;
@@ -565,4 +561,3 @@ extern uchar shouldsaveblendmap();
#endif
#endif
-
diff --git a/src/engine/glare.cpp b/src/engine/glare.cpp
index 5842fdc..c674e35 100644
--- a/src/engine/glare.cpp
+++ b/src/engine/glare.cpp
@@ -22,14 +22,6 @@ VARP(blurglare, 0, 4, 7);
VARP(blurglareaspect, 0, 1, 1);
VARP(blurglaresigma, 1, 50, 200);
-VAR(debugglare, 0, 0, 1);
-
-void viewglaretex()
-{
- if(!glare) return;
- glaretex.debug();
-}
-
bool glaring = false;
void drawglaretex()
diff --git a/src/engine/lightmap.h b/src/engine/lightmap.h
index 51ddc73..005f1fe 100644
--- a/src/engine/lightmap.h
+++ b/src/engine/lightmap.h
@@ -28,15 +28,15 @@ struct PackNode
bool insert(ushort &tx, ushort &ty, ushort tw, ushort th);
};
-enum
-{
- LM_DIFFUSE = 0,
- LM_BUMPMAP0,
- LM_BUMPMAP1,
+enum
+{
+ LM_DIFFUSE = 0,
+ LM_BUMPMAP0,
+ LM_BUMPMAP1,
LM_TYPE = 0x0F,
- LM_ALPHA = 1<<4,
- LM_FLAGS = 0xF0
+ LM_ALPHA = 1<<4,
+ LM_FLAGS = 0xF0
};
struct LightMap
@@ -44,7 +44,7 @@ struct LightMap
int type, bpp, tex, offsetx, offsety;
PackNode packroot;
uint lightmaps, lumels;
- int unlitx, unlity;
+ int unlitx, unlity;
uchar *data;
LightMap()
@@ -106,7 +106,7 @@ struct lerpvert
bool operator==(const lerpvert &l) const { return tc == l.tc;; }
bool operator!=(const lerpvert &l) const { return tc != l.tc; }
};
-
+
struct lerpbounds
{
const lerpvert *min;
diff --git a/src/engine/main.cpp b/src/engine/main.cpp
index 40ef42a..499002f 100644
--- a/src/engine/main.cpp
+++ b/src/engine/main.cpp
@@ -190,7 +190,6 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
gettextres(w, h);
static int lastupdate = -1, lastw = -1, lasth = -1;
- //~static float backgroundu = 0, backgroundv = 0, detailu = 0, detailv = 0;
static int numdecals = 0;
static struct decal { float x, y, size; int side; } decals[12];
if((renderedframe && !mainmenu && lastupdate != lastmillis) || lastw != w || lasth != h)
@@ -199,10 +198,6 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
lastw = w;
lasth = h;
- //~backgroundu = rndscale(1);
- //~backgroundv = rndscale(1);
- //~detailu = rndscale(1);
- //~detailv = rndscale(1);
numdecals = sizeof(decals)/sizeof(decals[0]);
numdecals = numdecals/3 + rnd((numdecals*2)/3 + 1);
float maxsize = min(w, h)/16.0f;
@@ -214,19 +209,6 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
}
else if(lastupdate != lastmillis) lastupdate = lastmillis;
- //~if (mapname) {
- //~defformatstring(backpath, "background/%s.png", mapname);
- //~if (file_does_indeed_exist(backpath)) {
- //~settexture(backpath, 0);
- //~bgquad(0, 0, 1920, 1080, 0, 0, 1920, 1080);
- //~gle::begin(GL_TRIANGLE_STRIP);
- //~gle::attribf(0.0f, 0.0f); gle::attribf(0.0f, 0.0f);
- //~gle::attribf(1.0f, 0.0f); gle::attribf(1920.0f, 0.0f);
- //~gle::attribf(0.0f, 1.0f); gle::attribf(0.0f, 1.0f);
- //~gle::attribf(1.0f, 1.0f); gle::attribf(1920.0f, 1.0f);
- //~gle::end();
- //~}
- //~} else {
loopi(restore ? 1 : 3)
{
hudmatrix.ortho(0, w, h, 0, -1, 1);
@@ -238,30 +220,9 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
gle::defvertex(2);
gle::deftexcoord0();
- //~defformatstring(backpath, "background/%s.png", mapname);
- //~if (file_does_indeed_exist(backpath)) {
- //~settexture(backpath, 0);
settexture("background/daemex.png", 0);
bgquad(0, 0, screenw, screenh, 0, 0, 1, 1);
- //~settexture("data/background.png", 0);
- //~float bu = w*0.67f/256.0f + backgroundu, bv = h*0.67f/256.0f + backgroundv;
- //~bgquad(0, 0, w, h, 0, 0, bu, bv);
- //~glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
- //~settexture("data/background_detail.png", 0);
- //~float du = w*0.8f/512.0f + detailu, dv = h*0.8f/512.0f + detailv;
- //~bgquad(0, 0, w, h, 0, 0, du, dv);
- //~settexture("data/background_decal.png", 3);
- //~gle::begin(GL_QUADS);
- //~loopj(numdecals)
- //~{
- //~float hsz = decals[j].size, hx = clamp(decals[j].x, hsz, w-hsz), hy = clamp(decals[j].y, hsz, h-hsz), side = decals[j].side;
- //~gle::attribf(hx-hsz, hy-hsz); gle::attribf(side, 0);
- //~gle::attribf(hx+hsz, hy-hsz); gle::attribf(1-side, 0);
- //~gle::attribf(hx+hsz, hy+hsz); gle::attribf(1-side, 1);
- //~gle::attribf(hx-hsz, hy+hsz); gle::attribf(side, 1);
- //~}
- //~gle::end();
float lh = 0.5f*min(w, h), lw = lh*2,
lx = 0.5f*(w - lw), ly = 0.5f*(h*0.5f - lh);
settexture((maxtexsize ? min(maxtexsize, hwtexsize) : hwtexsize) >= 1024 && (screenw > 1280 || screenh > 800) ? "data/logo_1024.png" : "data/logo.png", 3);
@@ -334,7 +295,6 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
glDisable(GL_BLEND);
if(!restore) swapbuffers(false);
}
- //~}
if(!restore) setbackgroundinfo(caption, mapshot, mapname, mapinfo);
}
@@ -1354,7 +1314,6 @@ int main(int argc, char **argv)
if(initscript) execute(initscript);
- initmumble();
resetfpshistory();
inputgrab(grabinput = true);
diff --git a/src/engine/master.cpp b/src/engine/master.cpp
index 2522e97..6eb6fe6 100644
--- a/src/engine/master.cpp
+++ b/src/engine/master.cpp
@@ -1,10 +1,6 @@
-#ifdef WIN32
-#define FD_SETSIZE 4096
-#else
#include <sys/types.h>
#undef __FD_SETSIZE
#define __FD_SETSIZE 4096
-#endif
#include "cube.h"
#include <signal.h>
@@ -258,7 +254,7 @@ void gengbanlist()
loopv(gbans)
{
ipmask &b = gbans[i];
- l->buf.put(cmd, cmdlen + b.print(&cmd[cmdlen]));
+ l->buf.put(cmd, cmdlen + b.print(&cmd[cmdlen]));
l->buf.add('\n');
}
if(gbanlists.length() && gbanlists.last()->equals(*l))
@@ -277,7 +273,7 @@ void gengbanlist()
loopv(clients)
{
client &c = *clients[i];
- if(c.servport >= 0 && !c.message)
+ if(c.servport >= 0 && !c.message)
{
c.message = l;
c.message->refs++;
@@ -628,9 +624,9 @@ void checkclients()
{
if(c.output.length()) c.output.setsize(0);
else
- {
+ {
c.message->purge();
- c.message = NULL;
+ c.message = NULL;
}
c.outputpos = 0;
if(!c.message && c.output.empty() && c.shouldpurge)
@@ -668,12 +664,10 @@ void banclients()
volatile int reloadcfg = 1;
-#ifndef WIN32
void reloadsignal(int signum)
{
reloadcfg = 1;
}
-#endif
int main(int argc, char **argv)
{
@@ -692,9 +686,7 @@ int main(int argc, char **argv)
logfile = fopen(logname, "a");
if(!logfile) logfile = stdout;
setvbuf(logfile, NULL, _IOLBF, BUFSIZ);
-#ifndef WIN32
signal(SIGUSR1, reloadsignal);
-#endif
setupserver(port, ip);
for(;;)
{
diff --git a/src/engine/material.cpp b/src/engine/material.cpp
index 59f47f8..d56c7e2 100644
--- a/src/engine/material.cpp
+++ b/src/engine/material.cpp
@@ -1,35 +1,25 @@
#include "engine.h"
-struct QuadNode
-{
+struct QuadNode {
int x, y, size;
uint filled;
QuadNode *child[4];
QuadNode(int x, int y, int size) : x(x), y(y), size(size), filled(0) { loopi(4) child[i] = 0; }
- void clear()
- {
- loopi(4) DELETEP(child[i]);
- }
-
- ~QuadNode()
- {
- clear();
- }
+ void clear() { loopi(4) DELETEP(child[i]); }
- void insert(int mx, int my, int msize)
- {
- if(size == msize)
- {
+ ~QuadNode() { clear(); }
+
+ void insert(int mx, int my, int msize) {
+ if(size == msize) {
filled = 0xF;
return;
}
int csize = size>>1, i = 0;
if(mx >= x+csize) i |= 1;
if(my >= y+csize) i |= 2;
- if(csize == msize)
- {
+ if(csize == msize) {
filled |= (1 << i);
return;
}
@@ -37,16 +27,14 @@ struct QuadNode
child[i]->insert(mx, my, msize);
loopj(4) if(child[j])
{
- if(child[j]->filled == 0xF)
- {
+ if(child[j]->filled == 0xF) {
DELETEP(child[j]);
filled |= (1 << j);
}
}
}
- void genmatsurf(ushort mat, uchar orient, uchar visible, int x, int y, int z, int size, materialsurface *&matbuf)
- {
+ void genmatsurf(ushort mat, uchar orient, uchar visible, int x, int y, int z, int size, materialsurface *&matbuf) {
materialsurface &m = *matbuf++;
m.material = mat;
m.orient = orient;
@@ -59,8 +47,7 @@ struct QuadNode
m.o[dim] = z;
}
- void genmatsurfs(ushort mat, uchar orient, uchar flags, int z, materialsurface *&matbuf)
- {
+ void genmatsurfs(ushort mat, uchar orient, uchar flags, int z, materialsurface *&matbuf) {
if(filled == 0xF) genmatsurf(mat, orient, flags, x, y, z, size, matbuf);
else if(filled)
{
@@ -74,8 +61,7 @@ struct QuadNode
static float wfwave;
-static const bvec4 matnormals[6] =
-{
+static const bvec4 matnormals[6] = {
bvec4(0x80, 0, 0),
bvec4(0x7F, 0, 0),
bvec4(0, 0x80, 0),
@@ -139,7 +125,7 @@ const struct material
{
const char *name;
ushort id;
-} materials[] =
+} materials[] =
{
{"air", MAT_AIR},
{"water", MAT_WATER}, {"water1", MAT_WATER}, {"water2", MAT_WATER+1}, {"water3", MAT_WATER+2}, {"water4", MAT_WATER+3},
@@ -157,16 +143,16 @@ int findmaterial(const char *name)
loopi(sizeof(materials)/sizeof(material))
{
if(!strcmp(materials[i].name, name)) return materials[i].id;
- }
+ }
return -1;
-}
+}
const char *findmaterialname(int mat)
{
loopi(sizeof(materials)/sizeof(materials[0])) if(materials[i].id == mat) return materials[i].name;
return NULL;
}
-
+
const char *getmaterialdesc(int mat, const char *prefix)
{
static const ushort matmasks[] = { MATF_VOLUME|MATF_INDEX, MATF_CLIP, MAT_DEATH, MAT_ALPHA };
@@ -175,7 +161,7 @@ const char *getmaterialdesc(int mat, const char *prefix)
loopi(sizeof(matmasks)/sizeof(matmasks[0])) if(mat&matmasks[i])
{
const char *matname = findmaterialname(mat&matmasks[i]);
- if(matname)
+ if(matname)
{
concatstring(desc, desc[0] ? ", " : prefix);
concatstring(desc, matname);
@@ -183,9 +169,9 @@ const char *getmaterialdesc(int mat, const char *prefix)
}
return desc;
}
-
+
int visiblematerial(const cube &c, int orient, const ivec &co, int size, ushort matmask)
-{
+{
ushort mat = c.material&matmask;
switch(mat)
{
@@ -220,7 +206,7 @@ void genmatsurfs(const cube &c, const ivec &co, int size, vector<materialsurface
{
int matmask = matmasks[j];
int vis = visiblematerial(c, i, co, size, matmask&~MATF_INDEX);
- if(vis != MATSURF_NOT_VISIBLE)
+ if(vis != MATSURF_NOT_VISIBLE)
{
materialsurface m;
m.material = c.material&matmask;
@@ -322,7 +308,7 @@ int optimizematsurfs(materialsurface *matbuf, int matsurfs)
while(cur < end &&
cur->material == start->material &&
cur->orient == start->orient &&
- cur->visible == start->visible &&
+ cur->visible == start->visible &&
cur->o[dim] == start->o[dim])
++cur;
if(!isliquid(start->material&MATF_VOLUME) || start->orient != O_TOP || !vertwater)
@@ -357,7 +343,7 @@ void setupmaterials(int start, int len)
vector<waterinfo> water;
unionfind uf;
if(!len) len = valist.length();
- for(int i = start; i < len; i++)
+ for(int i = start; i < len; i++)
{
vtxarray *va = valist[i];
materialsurface *skip = NULL;
@@ -387,7 +373,7 @@ void setupmaterials(int start, int len)
m.light = brightestlight(center, vec(0, 0, 1));
float depth = raycube(center, vec(0, 0, -1), 10000);
wi.depth = double(depth)*m.rsize*m.csize;
- wi.area = m.rsize*m.csize;
+ wi.area = m.rsize*m.csize;
}
else if(isliquid(matvol) && m.orient!=O_BOTTOM && m.orient!=O_TOP)
{
@@ -427,7 +413,7 @@ void setupmaterials(int start, int len)
m.skip = 0;
if(skip && m.material == skip->material && m.orient == skip->orient && skip->skip < 0xFFFF)
skip->skip++;
- else
+ else
skip = &m;
}
}
@@ -452,7 +438,7 @@ void setupmaterials(int start, int len)
preloadwatershaders(true);
loopi(4) if(hasmat&(1<<(MAT_WATER+i))) lookupmaterialslot(MAT_WATER+i);
}
- if(hasmat&(0xF<<MAT_LAVA))
+ if(hasmat&(0xF<<MAT_LAVA))
{
useshaderbyname("lava");
useshaderbyname("lavaglare");
@@ -715,12 +701,12 @@ void rendermaterials()
if(waterfallrefract && wfog && !reflecting && !refracting)
{
- if(waterfallenv) SETSHADER(waterfallenvrefract);
+ if(waterfallenv) SETSHADER(waterfallenvrefract);
else SETSHADER(waterfallrefract);
if(blended) { glDisable(GL_BLEND); blended = false; }
if(!depth) { glDepthMask(GL_TRUE); depth = true; }
}
- else
+ else
{
SETSHADER(waterfallenv);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -762,7 +748,7 @@ void rendermaterials()
usedwaterfall = m.material;
}
}
- float angle = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f),
+ float angle = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f),
s = angle - int(angle) - 0.5f;
s *= 8 - fabs(s)*16;
wfwave = vertwater ? WATER_AMPLITUDE*s-WATER_OFFSET : -WATER_OFFSET;
@@ -824,7 +810,7 @@ void rendermaterials()
{
if(!blended) { glEnable(GL_BLEND); blended = true; }
if(depth) { glDepthMask(GL_FALSE); depth = false; }
- const bvec &gcol = getglasscolor(m.material);
+ const bvec &gcol = getglasscolor(m.material);
if(m.envmap!=EMID_NONE && glassenv)
{
glBlendFunc(GL_ONE, GL_SRC_ALPHA);
@@ -840,7 +826,7 @@ void rendermaterials()
}
}
break;
-
+
default: continue;
}
lastmat = m.material;
diff --git a/src/engine/rendergl.cpp b/src/engine/rendergl.cpp
index f6d19b9..b05be7d 100644
--- a/src/engine/rendergl.cpp
+++ b/src/engine/rendergl.cpp
@@ -8,28 +8,7 @@ VAR(glversion, 1, 0, 0);
VAR(glslversion, 1, 0, 0);
VAR(glcompat, 1, 0, 0);
-// OpenGL 1.3
-#ifdef WIN32
-PFNGLACTIVETEXTUREPROC glActiveTexture_ = NULL;
-
-PFNGLBLENDEQUATIONEXTPROC glBlendEquation_ = NULL;
-PFNGLBLENDCOLOREXTPROC glBlendColor_ = NULL;
-
-PFNGLTEXIMAGE3DPROC glTexImage3D_ = NULL;
-PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D_ = NULL;
-PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D_ = NULL;
-
-PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D_ = NULL;
-PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D_ = NULL;
-PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D_ = NULL;
-PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D_ = NULL;
-PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage_ = NULL;
-
-PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements_ = NULL;
-#endif
-
// OpenGL 2.0
-#ifndef __APPLE__
PFNGLMULTIDRAWARRAYSPROC glMultiDrawArrays_ = NULL;
PFNGLMULTIDRAWELEMENTSPROC glMultiDrawElements_ = NULL;
@@ -124,7 +103,6 @@ PFNGLVERTEXATTRIB4NUSVPROC glVertexAttrib4Nusv_ = NULL;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer_ = NULL;
PFNGLDRAWBUFFERSPROC glDrawBuffers_ = NULL;
-#endif
// OpenGL 3.0
PFNGLGETSTRINGIPROC glGetStringi_ = NULL;
@@ -245,26 +223,6 @@ void gl_checkextensions()
if(glversion < 200) fatal("OpenGL 2.0 or greater is required!");
-#ifdef WIN32
- glActiveTexture_ = (PFNGLACTIVETEXTUREPROC) getprocaddress("glActiveTexture");
-
- glBlendEquation_ = (PFNGLBLENDEQUATIONPROC) getprocaddress("glBlendEquation");
- glBlendColor_ = (PFNGLBLENDCOLORPROC) getprocaddress("glBlendColor");
-
- glTexImage3D_ = (PFNGLTEXIMAGE3DPROC) getprocaddress("glTexImage3D");
- glTexSubImage3D_ = (PFNGLTEXSUBIMAGE3DPROC) getprocaddress("glTexSubImage3D");
- glCopyTexSubImage3D_ = (PFNGLCOPYTEXSUBIMAGE3DPROC) getprocaddress("glCopyTexSubImage3D");
-
- glCompressedTexImage3D_ = (PFNGLCOMPRESSEDTEXIMAGE3DPROC) getprocaddress("glCompressedTexImage3D");
- glCompressedTexImage2D_ = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) getprocaddress("glCompressedTexImage2D");
- glCompressedTexSubImage3D_ = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) getprocaddress("glCompressedTexSubImage3D");
- glCompressedTexSubImage2D_ = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) getprocaddress("glCompressedTexSubImage2D");
- glGetCompressedTexImage_ = (PFNGLGETCOMPRESSEDTEXIMAGEPROC) getprocaddress("glGetCompressedTexImage");
-
- glDrawRangeElements_ = (PFNGLDRAWRANGEELEMENTSPROC) getprocaddress("glDrawRangeElements");
-#endif
-
-#ifndef __APPLE__
glMultiDrawArrays_ = (PFNGLMULTIDRAWARRAYSPROC) getprocaddress("glMultiDrawArrays");
glMultiDrawElements_ = (PFNGLMULTIDRAWELEMENTSPROC) getprocaddress("glMultiDrawElements");
@@ -359,7 +317,6 @@ void gl_checkextensions()
glVertexAttribPointer_ = (PFNGLVERTEXATTRIBPOINTERPROC) getprocaddress("glVertexAttribPointer");
glDrawBuffers_ = (PFNGLDRAWBUFFERSPROC) getprocaddress("glDrawBuffers");
-#endif
if(glversion >= 300)
{
@@ -465,15 +422,6 @@ void gl_checkextensions()
}
else
{
- if(intel)
- {
-#ifdef WIN32
- intel_vertexarray_bug = 1;
- // MapBufferRange is buggy on older Intel drivers on Windows
- if(glversion <= 310) intel_mapbufferrange_bug = 1;
-#endif
- }
-
reservevpparams = 20;
if(mesa) mesa_swap_bug = 1;
@@ -2044,32 +1992,8 @@ void gl_drawhud()
gle::colorf(1, 1, 1);
- extern int debugsm;
- if(debugsm)
- {
- extern void viewshadowmap();
- viewshadowmap();
- }
-
- extern int debugglare;
- if(debugglare)
- {
- extern void viewglaretex();
- viewglaretex();
- }
-
- extern int debugdepthfx;
- if(debugdepthfx)
- {
- extern void viewdepthfxtex();
- viewdepthfxtex();
- }
-
glEnable(GL_BLEND);
- extern void debugparticles();
- debugparticles();
-
if(!mainmenu)
{
drawdamagescreen(w, h);
diff --git a/src/engine/rendermodel.cpp b/src/engine/rendermodel.cpp
index 312849b..c8a7eb6 100644
--- a/src/engine/rendermodel.cpp
+++ b/src/engine/rendermodel.cpp
@@ -793,7 +793,7 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl
if(!m) return;
vec center(0, 0, 0), bbradius(0, 0, 0);
float radius = 0;
- bool shadow = !shadowmap && !glaring && (flags&(MDL_SHADOW|MDL_DYNSHADOW));//~ && showblobs;
+ bool shadow = !shadowmap && !glaring && (flags&(MDL_SHADOW|MDL_DYNSHADOW));
if(flags&(MDL_CULL_VFC|MDL_CULL_DIST|MDL_CULL_OCCLUDED|MDL_CULL_QUERY|MDL_SHADOW|MDL_DYNSHADOW))
{
diff --git a/src/engine/renderparticles.cpp b/src/engine/renderparticles.cpp
index ad9e9d8..c6994bf 100644
--- a/src/engine/renderparticles.cpp
+++ b/src/engine/renderparticles.cpp
@@ -178,7 +178,6 @@ struct partrenderer
virtual void update() { }
virtual void render() = 0;
virtual bool haswork() = 0;
- virtual int count() = 0; //for debug
virtual void cleanup() {}
virtual void seedemitter(particleemitter &pe, const vec &o, const vec &d, int fade, float size, int gravity)
@@ -226,26 +225,6 @@ struct partrenderer
}
}
}
-
- const char *debuginfo()
- {
- formatstring(info, "%d\t%s(", count(), partnames[type&0xFF]);
- if(type&PT_GLARE) concatstring(info, "g,");
- if(type&PT_SOFT) concatstring(info, "s,");
- if(type&PT_LERP) concatstring(info, "l,");
- if(type&PT_MOD) concatstring(info, "m,");
- if(type&PT_RND4) concatstring(info, "r,");
- if(type&PT_FLIP) concatstring(info, "f,");
- if(collide) concatstring(info, "c,");
- int len = strlen(info);
- info[len-1] = info[len-1] == ',' ? ')' : '\0';
- if(texname)
- {
- const char *title = strrchr(texname, '/');
- if(title) concformatstring(info, ": %s", title+1);
- }
- return info;
- }
};
struct listparticle : particle
@@ -984,25 +963,9 @@ void removetrackedparticles(physent *owner)
VARP(particleglare, 0, 2, 100);
-VARN(debugparticles, dbgparts, 0, 0, 1);
-
-void debugparticles()
-{
- if(!dbgparts) return;
- int n = sizeof(parts)/sizeof(parts[0]);
- pushhudmatrix();
- hudmatrix.ortho(0, FONTH*n*2*screenw/float(screenh), FONTH*n*2, 0, -1, 1); //squeeze into top-left corner
- flushhudmatrix();
- hudshader->set();
- loopi(n) draw_text(parts[i]->info, FONTH, (i+n/2)*FONTH);
- pophudmatrix();
-}
-
void renderparticles(bool mainpass)
{
canstep = mainpass;
- //want to debug BEFORE the lastpass render (that would delete particles)
- if(dbgparts && mainpass) loopi(sizeof(parts)/sizeof(parts[0])) parts[i]->debuginfo();
if(glaring && !particleglare) return;
diff --git a/src/engine/rendertarget.h b/src/engine/rendertarget.h
index 3c93f18..f1e13e6 100644
--- a/src/engine/rendertarget.h
+++ b/src/engine/rendertarget.h
@@ -121,7 +121,7 @@ struct rendertarget
while(!depthfmt && depthfmts[++find]);
if(!depthfmt) depthfmt = depthfmts[find];
}
-
+
glBindFramebuffer_(GL_FRAMEBUFFER, 0);
texw = w;
@@ -152,8 +152,8 @@ struct rendertarget
bool checkblurtiles(float x1, float y1, float x2, float y2, float blurmargin = 0)
{
float blurerror = 2.0f*float(2*blursize + blurmargin);
- if(x2+blurerror/vieww < scissorx1 || y2+blurerror/viewh < scissory1 ||
- x1-blurerror/vieww > scissorx2 || y1-blurerror/viewh > scissory2)
+ if(x2+blurerror/vieww < scissorx1 || y2+blurerror/viewh < scissory1 ||
+ x1-blurerror/vieww > scissorx2 || y1-blurerror/viewh > scissory2)
return false;
if(!blurtile) return true;
@@ -247,7 +247,7 @@ struct rendertarget
}
if(scissor) glDisable(GL_SCISSOR_TEST);
-
+
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
@@ -259,7 +259,7 @@ struct rendertarget
virtual bool shouldrender() { return true; }
virtual void doblur(int blursize, float blursigma, int blurysize)
- {
+ {
int sx, sy, sw, sh;
bool scissoring = rtscissor && scissorblur(sx, sy, sw, sh) && sw > 0 && sh > 0;
if(!scissoring) { sx = sy = 0; sw = vieww; sh = viewh; }
@@ -268,7 +268,7 @@ struct rendertarget
virtual bool scissorrender(int &x, int &y, int &w, int &h)
{
- if(scissorx1 >= scissorx2 || scissory1 >= scissory2)
+ if(scissorx1 >= scissorx2 || scissory1 >= scissory2)
{
if(vieww < texw || viewh < texh)
{
@@ -323,19 +323,19 @@ struct rendertarget
vieww = w;
viewh = h;
if(w!=texw || h!=texh || (swaptexs() && !rtsharefb ? !blurfb : blurfb)) cleanup();
-
+
if(!filter())
{
if(blurtex) cleanupblur();
blursize = blurysize = 0;
}
-
+
if(!rendertex) setup(w, h);
-
+
scissorx2 = scissory2 = -1;
scissorx1 = scissory1 = 1;
memset(blurtiles, 0, sizeof(blurtiles));
-
+
if(!shouldrender()) return;
if(blursize && !blurtex) setupblur();
@@ -387,78 +387,5 @@ struct rendertarget
glBindFramebuffer_(GL_FRAMEBUFFER, 0);
glViewport(0, 0, screenw, screenh);
}
-
- virtual void dodebug(int w, int h) {}
- virtual bool flipdebug() const { return true; }
-
- void debugscissor(int w, int h, bool lines = false)
- {
- if(!rtscissor || scissorx1 >= scissorx2 || scissory1 >= scissory2) return;
- int sx = int(0.5f*(scissorx1 + 1)*w),
- sy = int(0.5f*(scissory1 + 1)*h),
- sw = int(0.5f*(scissorx2 - scissorx1)*w),
- sh = int(0.5f*(scissory2 - scissory1)*h);
- if(flipdebug()) { sy = h - sy; sh = -sh; }
- gle::defvertex(2);
- gle::begin(lines ? GL_LINE_LOOP : GL_TRIANGLE_STRIP);
- gle::attribf(sx, sy);
- gle::attribf(sx + sw, sy);
- if(lines) gle::attribf(sx + sw, sy + sh);
- gle::attribf(sx, sy + sh);
- if(!lines) gle::attribf(sx + sw, sy + sh);
- gle::end();
- }
-
- void debugblurtiles(int w, int h, bool lines = false)
- {
- if(!blurtile) return;
- float vxsz = float(w)/BLURTILES, vysz = float(h)/BLURTILES;
- gle::defvertex(2);
- loop(y, BLURTILES+1)
- {
- uint mask = blurtiles[y];
- int x = 0;
- while(mask)
- {
- while(!(mask&0xFF)) { mask >>= 8; x += 8; }
- while(!(mask&1)) { mask >>= 1; x++; }
- int xstart = x;
- do { mask >>= 1; x++; } while(mask&1);
- uint strip = (BLURTILEMASK>>(BLURTILES - x)) & (BLURTILEMASK<<xstart);
- int yend = y;
- do { blurtiles[yend] &= ~strip; yend++; } while((blurtiles[yend] & strip) == strip);
- float vx = xstart*vxsz,
- vy = y*vysz,
- vw = (x-xstart)*vxsz,
- vh = (yend-y)*vysz;
- if(flipdebug()) { vy = h - vy; vh = -vh; }
- loopi(lines ? 1 : 2)
- {
- if(!lines) gle::colorf(1, 1, i ? 1.0f : 0.5f);
- gle::begin(lines || i ? GL_LINE_LOOP : GL_TRIANGLE_STRIP);
- gle::attribf(vx, vy);
- gle::attribf(vx+vw, vy);
- if(lines || i) gle::attribf(vx+vw, vy+vh);
- gle::attribf(vx, vy+vh);
- if(!lines && !i) gle::attribf(vx+vw, vy+vh);
- gle::end();
- }
- }
- }
- }
-
- void debug()
- {
- if(!rendertex) return;
- int w = min(screenw, screenh)/2, h = (w*screenh)/screenw;
- hudshader->set();
- gle::colorf(1, 1, 1);
- glBindTexture(GL_TEXTURE_2D, rendertex);
- float tx1 = 0, tx2 = 1, ty1 = 0, ty2 = 1;
- if(flipdebug()) swap(ty1, ty2);
- hudquad(0, 0, w, h, tx1, ty1, tx2-tx1, ty2-ty1);
- hudnotextureshader->set();
- dodebug(w, h);
- }
};
diff --git a/src/engine/renderva.cpp b/src/engine/renderva.cpp
index c88ac6c..cef5ac5 100644
--- a/src/engine/renderva.cpp
+++ b/src/engine/renderva.cpp
@@ -128,11 +128,6 @@ void findvisiblevas(vector<vtxarray *> &vas, bool resetocclude = false)
v.curvfc = isvisiblecube(v.o, v.size);
if(v.curvfc!=VFC_NOT_VISIBLE)
{
- //~if(pvsoccluded(v.o, v.size))
- //~{
- //~v.curvfc += PVS_FULL_VISIBLE - VFC_FULL_VISIBLE;
- //~continue;
- //~}
addvisibleva(&v);
if(v.children.length()) findvisiblevas(v.children, prevvfc>=VFC_NOT_VISIBLE);
if(prevvfc>=VFC_NOT_VISIBLE)
diff --git a/src/engine/server.cpp b/src/engine/server.cpp
index e76c67d..9348b67 100644
--- a/src/engine/server.cpp
+++ b/src/engine/server.cpp
@@ -18,11 +18,7 @@ void closelogfile()
FILE *getlogfile()
{
-#ifdef WIN32
- return logfile;
-#else
return logfile ? logfile : stdout;
-#endif
}
void setlogfile(const char *fname)
@@ -64,21 +60,17 @@ static void writelogv(FILE *file, const char *fmt, va_list args)
vformatstring(buf, fmt, args, sizeof(buf));
writelog(file, buf);
}
-
+
#ifdef STANDALONE
-void fatal(const char *fmt, ...)
-{
+void fatal(const char *fmt, ...)
+{
void cleanupserver();
- cleanupserver();
+ cleanupserver();
defvformatstring(msg,fmt,fmt);
if(logfile) logoutf("%s", msg);
-#ifdef WIN32
- MessageBox(NULL, msg, "Cube 2: Sauerbraten fatal error", MB_OK|MB_SYSTEMMODAL);
-#else
fprintf(stderr, "server error: %s\n", msg);
-#endif
closelogfile();
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
void conoutfv(int type, const char *fmt, va_list args)
@@ -103,7 +95,7 @@ struct client // server side version of "dynent" type
vector<client *> clients;
ENetHost *serverhost = NULL;
-int laststatus = 0;
+int laststatus = 0;
ENetSocket pongsock = ENET_SOCKET_NULL, lansock = ENET_SOCKET_NULL;
int localclients = 0, nonlocalclients = 0;
@@ -221,7 +213,7 @@ ENetPacket *sendf(int cn, int chan, const char *format, ...)
break;
}
- case 'i':
+ case 'i':
{
int n = isdigit(*format) ? *format++-'0' : 1;
loopi(n) putint(p, va_arg(args, int));
@@ -359,7 +351,7 @@ VARN(updatemaster, allowupdatemaster, 0, 1, 1);
void disconnectmaster()
{
- if(mastersock != ENET_SOCKET_NULL)
+ if(mastersock != ENET_SOCKET_NULL)
{
server::masterdisconnected();
enet_socket_destroy(mastersock);
@@ -453,7 +445,7 @@ void processmasterinput()
masterinpos = end - masterin.getbuf();
input = end;
end = (char *)memchr(input, '\n', masterin.length() - masterinpos);
- }
+ }
if(masterinpos >= masterin.length())
{
@@ -556,8 +548,8 @@ void checkserversockets() // reply all server info requests
{
if(!masterconnected)
{
- if(ENET_SOCKETSET_CHECK(readset, mastersock) || ENET_SOCKETSET_CHECK(writeset, mastersock))
- {
+ if(ENET_SOCKETSET_CHECK(readset, mastersock) || ENET_SOCKETSET_CHECK(writeset, mastersock))
+ {
int error = 0;
if(enet_socket_get_option(mastersock, ENET_SOCKOPT_ERROR, &error) < 0 || error)
{
@@ -566,9 +558,9 @@ void checkserversockets() // reply all server info requests
}
else
{
- masterconnecting = 0;
- masterconnected = totalmillis ? totalmillis : 1;
- server::masterconnected();
+ masterconnecting = 0;
+ masterconnected = totalmillis ? totalmillis : 1;
+ server::masterconnected();
}
}
}
@@ -596,7 +588,7 @@ uint totalsecs = 0;
void updatetime()
{
static int lastsec = 0;
- if(totalmillis - lastsec >= 1000)
+ if(totalmillis - lastsec >= 1000)
{
int cursecs = (totalmillis - lastsec) / 1000;
totalsecs += cursecs;
@@ -606,16 +598,16 @@ void updatetime()
void serverslice(bool dedicated, uint timeout) // main server update, called from main loop in sp, or from below in dedicated server
{
- if(!serverhost)
+ if(!serverhost)
{
server::serverupdate();
server::sendpackets();
return;
}
-
+
// below is network only
- if(dedicated)
+ if(dedicated)
{
int millis = (int)enet_time_get();
elapsedtime = millis - totalmillis;
@@ -635,10 +627,10 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
if(!lastupdatemaster || totalmillis-lastupdatemaster>60*60*1000) // send alive signal to masterserver every hour of uptime
updatemasterserver();
-
+
if(totalmillis-laststatus>60*1000) // display bandwidth stats, useful for server ops
{
- laststatus = totalmillis;
+ laststatus = totalmillis;
if(nonlocalclients || serverhost->totalSentData || serverhost->totalReceivedData) logoutf("status: %d remote clients, %.1f send, %.1f rec (K/sec)", nonlocalclients, serverhost->totalSentData/60.0f/1024, serverhost->totalReceivedData/60.0f/1024);
serverhost->totalSentData = serverhost->totalReceivedData = 0;
}
@@ -662,7 +654,7 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
string hn;
copystring(c.hostname, (enet_address_get_host_ip(&c.peer->address, hn, sizeof(hn))==0) ? hn : "unknown");
logoutf("client connected (%s)", c.hostname);
- int reason = server::clientconnect(c.num, c.peer->address.host);
+ int reason = server::clientconnect(c.num);
if(reason) disconnect_client(c.num, reason);
break;
}
@@ -673,7 +665,7 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
if(event.packet->referenceCount==0) enet_packet_destroy(event.packet);
break;
}
- case ENET_EVENT_TYPE_DISCONNECT:
+ case ENET_EVENT_TYPE_DISCONNECT:
{
client *c = (client *)event.peer->data;
if(!c) break;
@@ -698,7 +690,7 @@ void flushserver(bool force)
void localdisconnect(bool cleanup)
{
bool disconnected = false;
- loopv(clients) if(clients[i]->type==ST_LOCAL)
+ loopv(clients) if(clients[i]->type==ST_LOCAL)
{
server::localdisconnect(i);
delclient(clients[i]);
@@ -719,279 +711,12 @@ void localconnect()
}
#endif
-#ifdef WIN32
-#include "shellapi.h"
-
-#define IDI_ICON1 1
-
-static string apptip = "";
-static HINSTANCE appinstance = NULL;
-static ATOM wndclass = 0;
-static HWND appwindow = NULL, conwindow = NULL;
-static HICON appicon = NULL;
-static HMENU appmenu = NULL;
-static HANDLE outhandle = NULL;
-static const int MAXLOGLINES = 200;
-struct logline { int len; char buf[LOGSTRLEN]; };
-static queue<logline, MAXLOGLINES> loglines;
-
-static void cleanupsystemtray()
-{
- NOTIFYICONDATA nid;
- memset(&nid, 0, sizeof(nid));
- nid.cbSize = sizeof(nid);
- nid.hWnd = appwindow;
- nid.uID = IDI_ICON1;
- Shell_NotifyIcon(NIM_DELETE, &nid);
-}
-
-static bool setupsystemtray(UINT uCallbackMessage)
-{
- NOTIFYICONDATA nid;
- memset(&nid, 0, sizeof(nid));
- nid.cbSize = sizeof(nid);
- nid.hWnd = appwindow;
- nid.uID = IDI_ICON1;
- nid.uCallbackMessage = uCallbackMessage;
- nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
- nid.hIcon = appicon;
- strcpy(nid.szTip, apptip);
- if(Shell_NotifyIcon(NIM_ADD, &nid) != TRUE)
- return false;
- atexit(cleanupsystemtray);
- return true;
-}
-
-#if 0
-static bool modifysystemtray()
-{
- NOTIFYICONDATA nid;
- memset(&nid, 0, sizeof(nid));
- nid.cbSize = sizeof(nid);
- nid.hWnd = appwindow;
- nid.uID = IDI_ICON1;
- nid.uFlags = NIF_TIP;
- strcpy(nid.szTip, apptip);
- return Shell_NotifyIcon(NIM_MODIFY, &nid) == TRUE;
-}
-#endif
-
-static void cleanupwindow()
-{
- if(!appinstance) return;
- if(appmenu)
- {
- DestroyMenu(appmenu);
- appmenu = NULL;
- }
- if(wndclass)
- {
- UnregisterClass(MAKEINTATOM(wndclass), appinstance);
- wndclass = 0;
- }
-}
-
-static BOOL WINAPI consolehandler(DWORD dwCtrlType)
-{
- switch(dwCtrlType)
- {
- case CTRL_C_EVENT:
- case CTRL_BREAK_EVENT:
- case CTRL_CLOSE_EVENT:
- exit(EXIT_SUCCESS);
- return TRUE;
- }
- return FALSE;
-}
-
-static void writeline(logline &line)
-{
- static uchar ubuf[512];
- size_t len = strlen(line.buf), carry = 0;
- while(carry < len)
- {
- size_t numu = encodeutf8(ubuf, sizeof(ubuf), &((uchar *)line.buf)[carry], len - carry, &carry);
- DWORD written = 0;
- WriteConsole(outhandle, ubuf, numu, &written, NULL);
- }
-}
-
-static void setupconsole()
-{
- if(conwindow) return;
- if(!AllocConsole()) return;
- SetConsoleCtrlHandler(consolehandler, TRUE);
- conwindow = GetConsoleWindow();
- SetConsoleTitle(apptip);
- //SendMessage(conwindow, WM_SETICON, ICON_SMALL, (LPARAM)appicon);
- SendMessage(conwindow, WM_SETICON, ICON_BIG, (LPARAM)appicon);
- outhandle = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO coninfo;
- GetConsoleScreenBufferInfo(outhandle, &coninfo);
- coninfo.dwSize.Y = MAXLOGLINES;
- SetConsoleScreenBufferSize(outhandle, coninfo.dwSize);
- SetConsoleCP(CP_UTF8);
- SetConsoleOutputCP(CP_UTF8);
- loopv(loglines) writeline(loglines[i]);
-}
-
-enum
-{
- MENU_OPENCONSOLE = 0,
- MENU_SHOWCONSOLE,
- MENU_HIDECONSOLE,
- MENU_EXIT
-};
-
-static LRESULT CALLBACK handlemessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- switch(uMsg)
- {
- case WM_APP:
- SetForegroundWindow(hWnd);
- switch(lParam)
- {
- //case WM_MOUSEMOVE:
- // break;
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- {
- POINT pos;
- GetCursorPos(&pos);
- TrackPopupMenu(appmenu, TPM_CENTERALIGN|TPM_BOTTOMALIGN|TPM_RIGHTBUTTON, pos.x, pos.y, 0, hWnd, NULL);
- PostMessage(hWnd, WM_NULL, 0, 0);
- break;
- }
- }
- return 0;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case MENU_OPENCONSOLE:
- setupconsole();
- if(conwindow) ModifyMenu(appmenu, 0, MF_BYPOSITION|MF_STRING, MENU_HIDECONSOLE, "Hide Console");
- break;
- case MENU_SHOWCONSOLE:
- ShowWindow(conwindow, SW_SHOWNORMAL);
- ModifyMenu(appmenu, 0, MF_BYPOSITION|MF_STRING, MENU_HIDECONSOLE, "Hide Console");
- break;
- case MENU_HIDECONSOLE:
- ShowWindow(conwindow, SW_HIDE);
- ModifyMenu(appmenu, 0, MF_BYPOSITION|MF_STRING, MENU_SHOWCONSOLE, "Show Console");
- break;
- case MENU_EXIT:
- PostMessage(hWnd, WM_CLOSE, 0, 0);
- break;
- }
- return 0;
- case WM_CLOSE:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
-}
-
-static void setupwindow(const char *title)
-{
- copystring(apptip, title);
- //appinstance = GetModuleHandle(NULL);
- if(!appinstance) fatal("failed getting application instance");
- appicon = LoadIcon(appinstance, MAKEINTRESOURCE(IDI_ICON1));//(HICON)LoadImage(appinstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
- if(!appicon) fatal("failed loading icon");
-
- appmenu = CreatePopupMenu();
- if(!appmenu) fatal("failed creating popup menu");
- AppendMenu(appmenu, MF_STRING, MENU_OPENCONSOLE, "Open Console");
- AppendMenu(appmenu, MF_SEPARATOR, 0, NULL);
- AppendMenu(appmenu, MF_STRING, MENU_EXIT, "Exit");
- //SetMenuDefaultItem(appmenu, 0, FALSE);
-
- WNDCLASS wc;
- memset(&wc, 0, sizeof(wc));
- wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = appicon;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = title;
- wc.style = 0;
- wc.hInstance = appinstance;
- wc.lpfnWndProc = handlemessages;
- wc.cbWndExtra = 0;
- wc.cbClsExtra = 0;
- wndclass = RegisterClass(&wc);
- if(!wndclass) fatal("failed registering window class");
-
- appwindow = CreateWindow(MAKEINTATOM(wndclass), title, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, appinstance, NULL);
- if(!appwindow) fatal("failed creating window");
-
- atexit(cleanupwindow);
-
- if(!setupsystemtray(WM_APP)) fatal("failed adding to system tray");
-}
-
-static char *parsecommandline(const char *src, vector<char *> &args)
-{
- char *buf = new char[strlen(src) + 1], *dst = buf;
- for(;;)
- {
- while(isspace(*src)) src++;
- if(!*src) break;
- args.add(dst);
- for(bool quoted = false; *src && (quoted || !isspace(*src)); src++)
- {
- if(*src != '"') *dst++ = *src;
- else if(dst > buf && src[-1] == '\\') dst[-1] = '"';
- else quoted = !quoted;
- }
- *dst++ = '\0';
- }
- args.add(NULL);
- return buf;
-}
-
-
-int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
-{
- vector<char *> args;
- char *buf = parsecommandline(GetCommandLine(), args);
- appinstance = hInst;
-#ifdef STANDALONE
- int standalonemain(int argc, char **argv);
- int status = standalonemain(args.length()-1, args.getbuf());
- #define main standalonemain
-#else
- SDL_SetMainReady();
- int status = SDL_main(args.length()-1, args.getbuf());
-#endif
- delete[] buf;
- exit(status);
- return 0;
-}
-
-void logoutfv(const char *fmt, va_list args)
-{
- if(appwindow)
- {
- logline &line = loglines.add();
- vformatstring(line.buf, fmt, args, sizeof(line.buf));
- if(logfile) writelog(logfile, line.buf);
- line.len = min(strlen(line.buf), sizeof(line.buf)-2);
- line.buf[line.len++] = '\n';
- line.buf[line.len] = '\0';
- if(outhandle) writeline(line);
- }
- else if(logfile) writelogv(logfile, fmt, args);
-}
-
-#else
-
void logoutfv(const char *fmt, va_list args)
{
FILE *f = getlogfile();
if(f) writelogv(f, fmt, args);
}
-#endif
-
static bool dedicatedserver = false;
bool isdedicatedserver() { return dedicatedserver; }
@@ -1000,22 +725,7 @@ void rundedicatedserver()
{
dedicatedserver = true;
logoutf("dedicated server started, waiting for clients...");
-#ifdef WIN32
- SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
- for(;;)
- {
- MSG msg;
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if(msg.message == WM_QUIT) exit(EXIT_SUCCESS);
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- serverslice(true, 5);
- }
-#else
for(;;) serverslice(true, 5);
-#endif
dedicatedserver = false;
}
@@ -1032,7 +742,7 @@ bool servererror(bool dedicated, const char *desc)
fatal("%s", desc);
return false;
}
-
+
bool setuplistenserver(bool dedicated)
{
ENetAddress address = { ENET_HOST_ANY, enet_uint16(serverport <= 0 ? server::serverport() : serverport) };
@@ -1067,13 +777,6 @@ bool setuplistenserver(bool dedicated)
void initserver(bool listen, bool dedicated)
{
- if(dedicated)
- {
-#ifdef WIN32
- setupwindow("Cube 2: Sauerbraten server");
-#endif
- }
-
execfile("server-init.cfg", false);
if(listen) setuplistenserver(dedicated);
@@ -1097,12 +800,12 @@ void startlistenserver(int *usemaster)
if(serverhost) { conoutf(CON_ERROR, "listen server is already running"); return; }
allowupdatemaster = *usemaster>0 ? 1 : 0;
-
+
if(!setuplistenserver(false)) return;
-
+
updatemasterserver();
-
- conoutf("listen server started for %d clients%s", maxclients, allowupdatemaster ? " and listed with master server" : "");
+
+ conoutf("listen server started for %d clients%s", maxclients, allowupdatemaster ? " and listed with master server" : "");
}
COMMAND(startlistenserver, "i");
@@ -1126,7 +829,7 @@ bool serveroption(char *opt)
case 'u': setvar("serveruprate", atoi(opt+2)); return true;
case 'c': setvar("maxclients", atoi(opt+2)); return true;
case 'i': setsvar("serverip", opt+2); return true;
- case 'j': setvar("serverport", atoi(opt+2)); return true;
+ case 'j': setvar("serverport", atoi(opt+2)); return true;
case 'm': setsvar("mastername", opt+2); setvar("updatemaster", mastername[0] ? 1 : 0); return true;
#ifdef STANDALONE
case 'q': logoutf("Using home directory: %s", opt); sethomedir(opt+2); return true;
@@ -1141,7 +844,7 @@ vector<const char *> gameargs;
#ifdef STANDALONE
int main(int argc, char **argv)
-{
+{
setlogfile(NULL);
if(enet_initialize()<0) fatal("Unable to initialise network module");
atexit(enet_deinitialize);
diff --git a/src/engine/serverbrowser.cpp b/src/engine/serverbrowser.cpp
index 281b0dc..ee36eea 100644
--- a/src/engine/serverbrowser.cpp
+++ b/src/engine/serverbrowser.cpp
@@ -2,6 +2,8 @@
#include "engine.h"
+#define PROTOCOL_VERSION 260 // bump when protocol changes, dpulicate
+
struct resolverthread
{
SDL_Thread *thread;
@@ -88,7 +90,7 @@ void resolverstop(resolverthread &rt)
rt.query = NULL;
rt.starttime = 0;
SDL_UnlockMutex(resolvermutex);
-}
+}
void resolverclear()
{
@@ -129,12 +131,12 @@ bool resolvercheck(const char **name, ENetAddress *address)
else loopv(resolverthreads)
{
resolverthread &rt = resolverthreads[i];
- if(rt.query && totalmillis - rt.starttime > RESOLVERLIMIT)
+ if(rt.query && totalmillis - rt.starttime > RESOLVERLIMIT)
{
resolverstop(rt);
*name = rt.query;
resolved = true;
- }
+ }
}
SDL_UnlockMutex(resolvermutex);
return resolved;
@@ -152,10 +154,10 @@ bool resolverwait(const char *name, ENetAddress *address)
SDL_CondSignal(querycond);
int starttime = SDL_GetTicks(), timeout = 0;
bool resolved = false;
- for(;;)
+ for(;;)
{
SDL_CondWaitTimeout(resultcond, resolvermutex, 250);
- loopv(resolverresults) if(resolverresults[i].query == name)
+ loopv(resolverresults) if(resolverresults[i].query == name)
{
address->host = resolverresults[i].address.host;
resolverresults.remove(i);
@@ -163,11 +165,11 @@ bool resolverwait(const char *name, ENetAddress *address)
break;
}
if(resolved) break;
-
+
timeout = SDL_GetTicks() - starttime;
renderprogress(min(float(timeout)/RESOLVERLIMIT, 1.0f), text);
if(interceptkey(SDLK_ESCAPE)) timeout = RESOLVERLIMIT + 1;
- if(timeout > RESOLVERLIMIT) break;
+ if(timeout > RESOLVERLIMIT) break;
}
if(!resolved && timeout > RESOLVERLIMIT)
{
@@ -213,7 +215,7 @@ int connectwithtimeout(ENetSocket sock, const char *hostname, const ENetAddress
return -1;
}
-
+
struct pingattempts
{
enum { MAXATTEMPTS = 2 };
@@ -224,7 +226,7 @@ struct pingattempts
void clearattempts() { memset(attempts, 0, sizeof(attempts)); }
- void setoffset() { offset = 1 + rnd(0xFFFFFF); }
+ void setoffset() { offset = 1 + rnd(0xFFFFFF); }
int encodeping(int millis)
{
@@ -261,8 +263,8 @@ enum { UNRESOLVED = 0, RESOLVING, RESOLVED };
struct serverinfo : pingattempts
{
- enum
- {
+ enum
+ {
WAITING = INT_MAX,
MAXPINGS = 3
@@ -334,8 +336,8 @@ struct serverinfo : pingattempts
static bool compare(serverinfo *a, serverinfo *b)
{
- bool ac = server::servercompatible(a->name, a->sdesc, a->map, a->ping, a->attr, a->numplayers),
- bc = server::servercompatible(b->name, b->sdesc, b->map, b->ping, b->attr, b->numplayers);
+ bool ac = (a->attr.length() != 0) && (a->attr[0]==PROTOCOL_VERSION);
+ bool bc = (b->attr.length() != 0) && (b->attr[0]==PROTOCOL_VERSION);
if(ac > bc) return true;
if(bc > ac) return false;
if(a->keep > b->keep) return true;
@@ -415,7 +417,7 @@ template<size_t N> static inline void buildping(ENetBuffer &buf, uchar (&ping)[N
void pingservers()
{
- if(pingsock == ENET_SOCKET_NULL)
+ if(pingsock == ENET_SOCKET_NULL)
{
pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
if(pingsock == ENET_SOCKET_NULL)
@@ -441,7 +443,7 @@ void pingservers()
if(si.address.host == ENET_HOST_ANY) continue;
buildping(buf, ping, si);
enet_socket_send(pingsock, &si.address, &buf, 1);
-
+
si.checkdecay(servpingdecay);
}
if(searchlan)
@@ -454,7 +456,7 @@ void pingservers()
}
lastinfo = totalmillis;
}
-
+
void checkresolver()
{
int resolving = 0;
@@ -480,7 +482,7 @@ void checkresolver()
serverinfo &si = *servers[i];
if(name == si.name)
{
- si.resolved = RESOLVED;
+ si.resolved = RESOLVED;
si.address.host = addr.host;
break;
}
@@ -498,12 +500,12 @@ void checkpings()
ENetAddress addr;
uchar ping[MAXTRANS];
char text[MAXTRANS];
- buf.data = ping;
+ buf.data = ping;
buf.dataLength = sizeof(ping);
while(enet_socket_wait(pingsock, &events, 0) >= 0 && events)
{
int len = enet_socket_receive(pingsock, &addr, &buf, 1);
- if(len <= 0) return;
+ if(len <= 0) return;
ucharbuf p(ping, len);
int millis = getint(p);
serverinfo *si = NULL;
@@ -516,7 +518,7 @@ void checkpings()
else if(!searchlan || !lanpings.checkattempt(millis, false)) continue;
else
{
- si = newserver(NULL, server::serverport(addr.port), addr.host);
+ si = newserver(NULL, server::serverport(addr.port), addr.host);
millis = lanpings.decodeping(millis);
}
int rtt = clamp(totalmillis - millis, 0, min(servpingdecay, totalmillis));
@@ -545,7 +547,7 @@ void refreshservers()
{
static int lastrefresh = 0;
if(lastrefresh==totalmillis) return;
- if(totalmillis - lastrefresh > 1000)
+ if(totalmillis - lastrefresh > 1000)
{
loopv(servers) servers[i]->reset();
lastreset = totalmillis;
@@ -633,7 +635,7 @@ void retrieveservers(vector<char> &data)
while(reqlen > 0)
{
enet_uint32 events = ENET_SOCKET_WAIT_SEND;
- if(enet_socket_wait(sock, &events, 250) >= 0 && events)
+ if(enet_socket_wait(sock, &events, 250) >= 0 && events)
{
buf.data = (void *)req;
buf.dataLength = reqlen;
@@ -737,10 +739,10 @@ void writeservercfg()
}
if(kept) f->printf("\n");
f->printf("// servers connected to are added here automatically\n\n");
- loopv(servers)
+ loopv(servers)
{
serverinfo *s = servers[i];
- if(!s->keep)
+ if(!s->keep)
{
if(s->password) f->printf("addserver %s %d %s\n", escapeid(s->name), s->port, escapestring(s->password));
else f->printf("addserver %s %d\n", escapeid(s->name), s->port);
diff --git a/src/engine/shadowmap.cpp b/src/engine/shadowmap.cpp
index 34b0fd4..7b7f894 100644
--- a/src/engine/shadowmap.cpp
+++ b/src/engine/shadowmap.cpp
@@ -171,20 +171,6 @@ static struct shadowmaptexture : rendertarget
return shadowmapcasters>0;
}
-
- bool flipdebug() const { return false; }
-
- void dodebug(int w, int h)
- {
- if(shadowmapcasters)
- {
- glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
- debugscissor(w, h);
- glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
- debugblurtiles(w, h);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- }
- }
} shadowmaptex;
void cleanshadowmap()
@@ -318,12 +304,3 @@ void rendershadowmap()
shadowmaptex.render(1<<shadowmapsize, 1<<shadowmapsize, blurshadowmap, blursmsigma/100.0f);
}
-
-VAR(debugsm, 0, 0, 1);
-
-void viewshadowmap()
-{
- if(!shadowmap) return;
- shadowmaptex.debug();
-}
-
diff --git a/src/engine/sound.cpp b/src/engine/sound.cpp
index 38ff025..18cc0ab 100644
--- a/src/engine/sound.cpp
+++ b/src/engine/sound.cpp
@@ -30,7 +30,7 @@ struct soundconfig
bool hasslot(const soundslot *p, const vector<soundslot> &v) const
{
- return p >= v.getbuf() + slots && p < v.getbuf() + slots+numslots && slots+numslots < v.length();
+ return p >= v.getbuf() + slots && p < v.getbuf() + slots+numslots && slots+numslots < v.length();
}
int chooseslot(int flags) const
@@ -42,12 +42,12 @@ struct soundconfig
};
struct soundchannel
-{
+{
int id;
bool inuse;
- vec loc;
+ vec loc;
soundslot *slot;
- extentity *ent;
+ extentity *ent;
int radius, volume, pan, flags;
bool dirty;
@@ -156,11 +156,7 @@ void stopmusic()
DELETEP(musicstream);
}
-#ifdef WIN32
-#define AUDIODRIVER "directsound winmm"
-#else
#define AUDIODRIVER ""
-#endif
bool shouldinitaudio = true;
SVARF(audiodriver, AUDIODRIVER, { shouldinitaudio = true; initwarning("sound configuration", INIT_RESET, CHANGE_SOUND); });
VARF(usesound, 0, 1, 1, { shouldinitaudio = true; initwarning("sound configuration", INIT_RESET, CHANGE_SOUND); });
@@ -197,11 +193,7 @@ bool initaudio()
if(restorefallback)
{
restorefallback = false;
- #ifdef WIN32
- SDL_setenv("SDL_AUDIODRIVER", fallback, 1);
- #else
unsetenv("SDL_AUDIODRIVER");
- #endif
}
if(SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0) return true;
conoutf(CON_ERROR, "sound init failed: %s", SDL_GetError());
@@ -236,7 +228,7 @@ void initsound()
conoutf(CON_ERROR, "sound init failed (SDL_mixer): %s", Mix_GetError());
return;
}
- Mix_AllocateChannels(soundchans);
+ Mix_AllocateChannels(soundchans);
maxchannels = soundchans;
nosound = false;
}
@@ -263,7 +255,7 @@ Mix_Music *loadmusic(const char *name)
if(!musicrw) DELETEP(musicstream);
}
if(musicrw) music = Mix_LoadMUSType_RW(musicrw, MUS_NONE, 0);
- else music = Mix_LoadMUS(findfile(name, "rb"));
+ else music = Mix_LoadMUS(findfile(name, "rb"));
if(!music)
{
if(musicrw) { SDL_FreeRW(musicrw); musicrw = NULL; }
@@ -271,7 +263,7 @@ Mix_Music *loadmusic(const char *name)
}
return music;
}
-
+
void startmusic(char *name, char *cmd)
{
if(nosound) return;
@@ -293,7 +285,7 @@ void startmusic(char *name, char *cmd)
else
{
conoutf(CON_ERROR, "could not play music: %s", file);
- intret(0);
+ intret(0);
}
}
}
@@ -582,7 +574,6 @@ void resetchannels()
void clear_sound()
{
- closemumble();
if(nosound) return;
stopmusic();
@@ -672,7 +663,7 @@ bool updatechannel(soundchannel &chan)
chan.pan = pan;
chan.dirty = true;
return true;
-}
+}
void reclaimchannels()
{
@@ -696,7 +687,6 @@ VARP(minimizedsounds, 0, 0, 1);
void updatesounds()
{
- updatemumble();
if(nosound) return;
if(minimized && !minimizedsounds) stopsounds();
else
@@ -736,7 +726,7 @@ void preloadmapsounds()
if(e.type==ET_SOUND) mapsounds.preloadsound(e.attr1);
}
}
-
+
int playsound(int n, const vec *loc, extentity *ent, int flags, int loops, int fade, int chanid, int radius, int expire)
{
if(nosound || !soundvol || (minimized && !minimizedsounds)) return -1;
@@ -757,7 +747,7 @@ int playsound(int n, const vec *loc, extentity *ent, int flags, int loops, int f
Mix_HaltChannel(chanid);
freechannel(chanid);
}
- return -1;
+ return -1;
}
}
@@ -792,7 +782,7 @@ int playsound(int n, const vec *loc, extentity *ent, int flags, int loops, int f
if(!slot.sample->chunk && !slot.sample->load()) return -1;
if(dbgsound) conoutf(CON_DEBUG, "sound: %s", slot.sample->name);
-
+
chanid = -1;
loopv(channels) if(!channels[i].inuse) { chanid = i; break; }
if(chanid < 0 && channels.length() < maxchannels) chanid = channels.length();
@@ -802,13 +792,13 @@ int playsound(int n, const vec *loc, extentity *ent, int flags, int loops, int f
soundchannel &chan = newchannel(chanid, &slot, loc, ent, flags, radius);
updatechannel(chan);
int playing = -1;
- if(fade)
+ if(fade)
{
Mix_Volume(chanid, chan.volume);
playing = expire >= 0 ? Mix_FadeInChannelTimed(chanid, slot.sample->chunk, loops, fade, expire) : Mix_FadeInChannel(chanid, slot.sample->chunk, loops, fade);
}
else playing = expire >= 0 ? Mix_PlayChannelTimed(chanid, slot.sample->chunk, loops, expire) : Mix_PlayChannel(chanid, slot.sample->chunk, loops);
- if(playing >= 0) syncchannel(chan);
+ if(playing >= 0) syncchannel(chan);
else freechannel(chanid);
return playing;
}
@@ -834,8 +824,8 @@ bool stopsound(int n, int chanid, int fade)
return true;
}
-int playsoundname(const char *s, const vec *loc, int vol, int flags, int loops, int fade, int chanid, int radius, int expire)
-{
+int playsoundname(const char *s, const vec *loc, int vol, int flags, int loops, int fade, int chanid, int radius, int expire)
+{
if(!vol) vol = 100;
int id = gamesounds.findsound(s, vol);
if(id < 0) id = gamesounds.addsound(s, vol);
@@ -847,7 +837,7 @@ ICOMMAND(sound, "i", (int *n), playsound(*n));
void resetsound()
{
clearchanges(CHANGE_SOUND);
- if(!nosound)
+ if(!nosound)
{
cleanupsamples();
if(music)
@@ -881,111 +871,3 @@ void resetsound()
}
COMMAND(resetsound, "");
-
-#ifdef WIN32
-
-#include <wchar.h>
-
-#else
-
-#include <unistd.h>
-
-#ifdef _POSIX_SHARED_MEMORY_OBJECTS
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <wchar.h>
-#endif
-
-#endif
-
-#if defined(WIN32) || defined(_POSIX_SHARED_MEMORY_OBJECTS)
-struct MumbleInfo
-{
- int version, timestamp;
- vec pos, front, top;
- wchar_t name[256];
-};
-#endif
-
-#ifdef WIN32
-static HANDLE mumblelink = NULL;
-static MumbleInfo *mumbleinfo = NULL;
-#define VALID_MUMBLELINK (mumblelink && mumbleinfo)
-#elif defined(_POSIX_SHARED_MEMORY_OBJECTS)
-static int mumblelink = -1;
-static MumbleInfo *mumbleinfo = (MumbleInfo *)-1;
-#define VALID_MUMBLELINK (mumblelink >= 0 && mumbleinfo != (MumbleInfo *)-1)
-#endif
-
-#ifdef VALID_MUMBLELINK
-VARFP(mumble, 0, 1, 1, { if(mumble) initmumble(); else closemumble(); });
-#else
-VARFP(mumble, 0, 0, 1, { if(mumble) initmumble(); else closemumble(); });
-#endif
-
-void initmumble()
-{
- if(!mumble) return;
-#ifdef VALID_MUMBLELINK
- if(VALID_MUMBLELINK) return;
-
- #ifdef WIN32
- mumblelink = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "MumbleLink");
- if(mumblelink)
- {
- mumbleinfo = (MumbleInfo *)MapViewOfFile(mumblelink, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(MumbleInfo));
- if(mumbleinfo) wcsncpy(mumbleinfo->name, L"Sauerbraten", 256);
- }
- #elif defined(_POSIX_SHARED_MEMORY_OBJECTS)
- defformatstring(shmname, "/MumbleLink.%d", getuid());
- mumblelink = shm_open(shmname, O_RDWR, 0);
- if(mumblelink >= 0)
- {
- mumbleinfo = (MumbleInfo *)mmap(NULL, sizeof(MumbleInfo), PROT_READ|PROT_WRITE, MAP_SHARED, mumblelink, 0);
- if(mumbleinfo != (MumbleInfo *)-1) wcsncpy(mumbleinfo->name, L"Sauerbraten", 256);
- }
- #endif
- if(!VALID_MUMBLELINK) closemumble();
-#else
- conoutf(CON_ERROR, "Mumble positional audio is not available on this platform.");
-#endif
-}
-
-void closemumble()
-{
-#ifdef WIN32
- if(mumbleinfo) { UnmapViewOfFile(mumbleinfo); mumbleinfo = NULL; }
- if(mumblelink) { CloseHandle(mumblelink); mumblelink = NULL; }
-#elif defined(_POSIX_SHARED_MEMORY_OBJECTS)
- if(mumbleinfo != (MumbleInfo *)-1) { munmap(mumbleinfo, sizeof(MumbleInfo)); mumbleinfo = (MumbleInfo *)-1; }
- if(mumblelink >= 0) { close(mumblelink); mumblelink = -1; }
-#endif
-}
-
-static inline vec mumblevec(const vec &v, bool pos = false)
-{
- // change from X left, Z up, Y forward to X right, Y up, Z forward
- // 8 cube units = 1 meter
- vec m(-v.x, v.z, v.y);
- if(pos) m.div(8);
- return m;
-}
-
-void updatemumble()
-{
-#ifdef VALID_MUMBLELINK
- if(!VALID_MUMBLELINK) return;
-
- static int timestamp = 0;
-
- mumbleinfo->version = 1;
- mumbleinfo->timestamp = ++timestamp;
-
- mumbleinfo->pos = mumblevec(player->o, true);
- mumbleinfo->front = mumblevec(vec(RAD*player->yaw, RAD*player->pitch));
- mumbleinfo->top = mumblevec(vec(RAD*player->yaw, RAD*(player->pitch+90)));
-#endif
-}
-
diff --git a/src/engine/textedit.h b/src/engine/textedit.h
index c273661..31f23ed 100644
--- a/src/engine/textedit.h
+++ b/src/engine/textedit.h
@@ -101,7 +101,7 @@ struct editline
void del(int start, int count)
{
if(!text) return;
- if(start < 0) { count += start; start = 0; }
+ if(start < 0) { count += start; start = 0; }
if(count <= 0 || start >= len) return;
if(start + count > len) count = len - start - 1;
memmove(&text[start], &text[start+count], len + 1 - (start + count));
@@ -136,8 +136,8 @@ struct editline
}
}
};
-
-struct editor
+
+struct editor
{
int mode; //editor mode - 1= keep while focused, 2= keep while used in gui, 3= keep forever (i.e. until mode changes)
bool active, rendered;
@@ -147,23 +147,23 @@ struct editor
int cx, cy; // cursor position - ensured to be valid after a region() or currentline()
int mx, my; // selection mark, mx=-1 if following cursor - avoid direct access, instead use region()
int maxx, maxy; // maxy=-1 if unlimited lines, 1 if single line editor
-
+
int scrolly; // vertical scroll offset
-
+
bool linewrap;
int pixelwidth; // required for up/down/hit/draw/bounds
int pixelheight; // -1 for variable sized, i.e. from bounds()
-
+
vector<editline> lines; // MUST always contain at least one line!
-
- editor(const char *name, int mode, const char *initval) :
+
+ editor(const char *name, int mode, const char *initval) :
mode(mode), active(true), rendered(false), name(newstring(name)), filename(NULL),
cx(0), cy(0), mx(-1), maxx(-1), maxy(-1), scrolly(0), linewrap(false), pixelwidth(-1), pixelheight(-1)
{
//printf("editor %08x '%s'\n", this, name);
lines.add().set(initval ? initval : "");
}
-
+
~editor()
{
//printf("~editor %08x '%s'\n", this, name);
@@ -171,7 +171,7 @@ struct editor
DELETEA(filename);
clear(NULL);
}
-
+
void clear(const char *init = "")
{
cx = cy = 0;
@@ -180,19 +180,19 @@ struct editor
lines.shrink(0);
if(init) lines.add().set(init);
}
-
+
void setfile(const char *fname)
{
- DELETEA(filename);
+ DELETEA(filename);
if(fname) filename = newstring(fname);
}
-
+
void load()
{
if(!filename) return;
clear(NULL);
stream *file = openutf8file(filename, "r");
- if(file)
+ if(file)
{
while(lines.add().read(file, maxx) && (maxy < 0 || lines.length() <= maxy));
lines.pop().clear();
@@ -200,7 +200,7 @@ struct editor
}
if(lines.empty()) lines.add().set("");
}
-
+
void save()
{
if(!filename) return;
@@ -209,29 +209,29 @@ struct editor
loopv(lines) file->putline(lines[i].text);
delete file;
}
-
- void mark(bool enable)
+
+ void mark(bool enable)
{
mx = (enable) ? cx : -1;
my = cy;
}
-
+
void selectall()
{
mx = my = INT_MAX;
cx = cy = 0;
}
-
+
// constrain results to within buffer - s=start, e=end, return true if a selection range
// also ensures that cy is always within lines[] and cx is valid
bool region(int &sx, int &sy, int &ex, int &ey)
{
- int n = lines.length();
+ int n = lines.length();
ASSERT(n != 0);
if(cy < 0) cy = 0; else if(cy >= n) cy = n-1;
int len = lines[cy].len;
if(cx < 0) cx = 0; else if(cx > len) cx = len;
- if(mx >= 0)
+ if(mx >= 0)
{
if(my < 0) my = 0; else if(my >= n) my = n-1;
len = lines[my].len;
@@ -242,16 +242,16 @@ struct editor
ex = cx;
ey = cy;
if(sy > ey) { swap(sy, ey); swap(sx, ex); }
- else if(sy==ey && sx > ex) swap(sx, ex);
+ else if(sy==ey && sx > ex) swap(sx, ex);
return (sx != ex) || (sy != ey);
}
-
+
bool region() { int sx, sy, ex, ey; return region(sx, sy, ex, ey); }
// also ensures that cy is always within lines[] and cx is valid
editline &currentline()
{
- int n = lines.length();
+ int n = lines.length();
ASSERT(n != 0);
if(cy < 0) cy = 0; else if(cy >= n) cy = n-1;
if(cx < 0) cx = 0; else if(cx > lines[cy].len) cx = lines[cy].len;
@@ -329,16 +329,16 @@ struct editor
loopi(count) lines[start+i].clear();
lines.remove(start, count);
}
-
+
bool del() // removes the current selection (if any)
{
int sx, sy, ex, ey;
- if(!region(sx, sy, ex, ey))
- {
- mark(false);
- return false;
+ if(!region(sx, sy, ex, ey))
+ {
+ mark(false);
+ return false;
}
- if(sy == ey)
+ if(sy == ey)
{
if(sx == 0 && ex == lines[ey].len) removelines(sy, 1);
else lines[sy].del(sx, ex - sx);
@@ -361,12 +361,12 @@ struct editor
}
return true;
}
-
- void insert(char ch)
+
+ void insert(char ch)
{
del();
editline &current = currentline();
- if(ch == '\n')
+ if(ch == '\n')
{
if(maxy == -1 || cy < maxy-1)
{
@@ -377,7 +377,7 @@ struct editor
}
else current.chop(cx);
cx = 0;
- }
+ }
else
{
int len = current.len;
@@ -391,31 +391,31 @@ struct editor
while(*s) insert(*s++);
}
- void insertallfrom(editor *b)
- {
+ void insertallfrom(editor *b)
+ {
if(b==this) return;
del();
-
- if(b->lines.length() == 1 || maxy == 1)
+
+ if(b->lines.length() == 1 || maxy == 1)
{
editline &current = currentline();
- char *str = b->lines[0].text;
+ char *str = b->lines[0].text;
int slen = b->lines[0].len;
if(maxx >= 0 && b->lines[0].len + cx > maxx) slen = maxx-cx;
- if(slen > 0)
+ if(slen > 0)
{
int len = current.len;
if(maxx >= 0 && slen + cx + len > maxx) len = max(0, maxx-(cx+slen));
- current.insert(str, cx, slen);
+ current.insert(str, cx, slen);
cx += slen;
}
- }
- else
+ }
+ else
{
- loopv(b->lines)
- {
- if(!i)
+ loopv(b->lines)
+ {
+ if(!i)
{
lines[cy++].append(b->lines[i].text);
}
@@ -431,12 +431,12 @@ struct editor
void key(int code)
{
- switch(code)
+ switch(code)
{
case SDLK_UP:
- if(linewrap)
+ if(linewrap)
{
- int x, y;
+ int x, y;
char *str = currentline().text;
text_pos(str, cx+1, x, y, pixelwidth);
if(y > 0) { cx = text_visible(str, x, y-FONTH, pixelwidth); break; }
@@ -444,7 +444,7 @@ struct editor
cy--;
break;
case SDLK_DOWN:
- if(linewrap)
+ if(linewrap)
{
int x, y, width, height;
char *str = currentline().text;
@@ -495,7 +495,7 @@ struct editor
if(!del())
{
editline &current = currentline();
- if(cx > 0) current.del(--cx, 1);
+ if(cx > 0) current.del(--cx, 1);
else if(cy > 0)
{ //combine with previous line
cx = lines[cy-1].len;
@@ -507,7 +507,7 @@ struct editor
case SDLK_LSHIFT:
case SDLK_RSHIFT:
break;
- case SDLK_RETURN:
+ case SDLK_RETURN:
insert('\n');
break;
case SDLK_TAB:
@@ -530,10 +530,10 @@ struct editor
int width, height;
text_bounds(lines[i].text, width, height, maxwidth);
if(h + height > pixelheight) break;
-
- if(hity >= h && hity <= h+height)
+
+ if(hity >= h && hity <= h+height)
{
- int x = text_visible(lines[i].text, hitx, hity-h, maxwidth);
+ int x = text_visible(lines[i].text, hitx, hity-h, maxwidth);
if(dragged) { mx = x; my = i; } else { cx = x; cy = i; };
break;
}
@@ -559,13 +559,13 @@ struct editor
void draw(int x, int y, int color, bool hit)
{
int maxwidth = linewrap?pixelwidth:-1;
-
+
int sx, sy, ex, ey;
bool selection = region(sx, sy, ex, ey);
-
+
// fix scrolly so that <cx, cy> is always on screen
if(cy < scrolly) scrolly = cy;
- else
+ else
{
if(scrolly < 0) scrolly = 0;
int h = 0;
@@ -577,7 +577,7 @@ struct editor
h += height;
}
}
-
+
if(selection)
{
// convert from cursor coords into pixel coords
@@ -589,15 +589,15 @@ struct editor
for(int i = scrolly; i < maxy; i++)
{
int width, height;
- text_bounds(lines[i].text, width, height, maxwidth);
+ text_bounds(lines[i].text, width, height, maxwidth);
if(h + height > pixelheight) { maxy = i; break; }
if(i == sy) psy += h;
if(i == ey) { pey += h; break; }
h += height;
}
maxy--;
-
- if(ey >= scrolly && sy <= maxy)
+
+ if(ey >= scrolly && sy <= maxy)
{
// crop top/bottom within window
if(sy < scrolly) { sy = scrolly; psy = 0; psx = 0; }
@@ -607,19 +607,19 @@ struct editor
gle::colorub(0xA0, 0x80, 0x80);
gle::defvertex(2);
gle::begin(GL_QUADS);
- if(psy == pey)
+ if(psy == pey)
{
gle::attribf(x+psx, y+psy);
gle::attribf(x+pex, y+psy);
gle::attribf(x+pex, y+pey+FONTH);
gle::attribf(x+psx, y+pey+FONTH);
- }
- else
+ }
+ else
{ gle::attribf(x+psx, y+psy);
gle::attribf(x+psx, y+psy+FONTH);
gle::attribf(x+pixelwidth, y+psy+FONTH);
gle::attribf(x+pixelwidth, y+psy);
- if(pey-psy > FONTH)
+ if(pey-psy > FONTH)
{
gle::attribf(x, y+psy+FONTH);
gle::attribf(x+pixelwidth, y+psy+FONTH);
@@ -635,17 +635,17 @@ struct editor
hudshader->set();
}
}
-
+
int h = 0;
for(int i = scrolly; i < lines.length(); i++)
{
int width, height;
text_bounds(lines[i].text, width, height, maxwidth);
if(h + height > pixelheight) break;
-
+
draw_text(lines[i].text, x, y+h, color>>16, (color>>8)&0xFF, color&0xFF, 0xFF, hit&&(cy==i)?cx:-1, maxwidth);
if(linewrap && height > FONTH) // line wrap indicator
- {
+ {
hudnotextureshader->set();
gle::colorub(0x80, 0xA0, 0x80);
gle::defvertex(2);
@@ -667,23 +667,23 @@ static vector <editor*> editors;
static editor *currentfocus() { return editors.length() ? editors.last() : NULL; }
-static void readyeditors()
+static void readyeditors()
{
loopv(editors) editors[i]->active = (editors[i]->mode==EDITORFOREVER);
}
-static void flusheditors()
+static void flusheditors()
{
- loopvrev(editors) if(!editors[i]->active)
+ loopvrev(editors) if(!editors[i]->active)
{
editor *e = editors.remove(i);
DELETEP(e);
}
}
-static editor *useeditor(const char *name, int mode, bool focus, const char *initval = NULL)
+static editor *useeditor(const char *name, int mode, bool focus, const char *initval = NULL)
{
- loopv(editors) if(strcmp(editors[i]->name, name) == 0)
+ loopv(editors) if(strcmp(editors[i]->name, name) == 0)
{
editor *e = editors[i];
if(focus) { editors.add(e); editors.remove(i); } // re-position as last
@@ -691,7 +691,7 @@ static editor *useeditor(const char *name, int mode, bool focus, const char *ini
return e;
}
editor *e = new editor(name, mode, initval);
- if(focus) editors.add(e); else editors.insert(0, e);
+ if(focus) editors.add(e); else editors.insert(0, e);
return e;
}
@@ -705,7 +705,7 @@ static editor *useeditor(const char *name, int mode, bool focus, const char *ini
ICOMMAND(textlist, "", (), // @DEBUG return list of all the editors
vector<char> s;
loopv(editors)
- {
+ {
if(i > 0) s.put(", ", 2);
s.put(editors[i]->name, strlen(editors[i]->name));
}
@@ -728,9 +728,9 @@ TEXTCOMMAND(textmode, "i", (int *m), // (1= keep while focused, 2= keep while us
else intret(top->mode);
);
TEXTCOMMAND(textsave, "s", (char *file), // saves the topmost (filename is optional)
- if(*file) top->setfile(path(file, true));
+ if(*file) top->setfile(path(file, true));
top->save();
-);
+);
TEXTCOMMAND(textload, "s", (char *file), // loads into the topmost editor, returns filename if no args
if(*file)
{
@@ -749,7 +749,7 @@ TEXTCOMMAND(textinit, "sss", (char *name, char *file, char *initval), // loads i
e->load();
}
});
-
+
#define PASTEBUFFER "#pastebuffer"
TEXTCOMMAND(textcopy, "", (), editor *b = useeditor(PASTEBUFFER, EDITORFOREVER, false); top->copyselectionto(b););
diff --git a/src/engine/texture.cpp b/src/engine/texture.cpp
index f25cfa7..e76b59e 100644
--- a/src/engine/texture.cpp
+++ b/src/engine/texture.cpp
@@ -1385,10 +1385,6 @@ static vec parsevec(const char *arg)
return v;
}
-VAR(usedds, 0, 1, 1);
-VAR(dbgdds, 0, 0, 1);
-VAR(scaledds, 0, 2, 4);
-
static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL, bool msg = true, int *compress = NULL, int *wrap = NULL)
{
const char *cmds = NULL, *file = tname;
@@ -1418,7 +1414,7 @@ static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL,
}
int flen = strlen(file);
- bool raw = !usedds || !compress, dds = false, guess = false;
+ bool raw = !compress, guess = false;
for(const char *pcmds = cmds; pcmds;)
{
#define PARSETEXCOMMANDS(cmds) \
@@ -1435,8 +1431,7 @@ static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL,
else arg[i]++; \
}
PARSETEXCOMMANDS(pcmds);
- if(matchstring(cmd, len, "dds")) dds = true;
- else if(matchstring(cmd, len, "thumbnail"))
+ if(matchstring(cmd, len, "thumbnail"))
{
raw = true;
guess = flen >= 4 && !strchr(file+flen-4, '.');
@@ -1446,19 +1441,6 @@ static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL,
if(msg) renderprogress(loadprogress, file);
- if(flen >= 4 && (!strcasecmp(file + flen - 4, ".dds") || (dds && !raw)))
- {
- string dfile;
- copystring(dfile, file);
- memcpy(dfile + flen - 4, ".dds", 4);
- if(!loaddds(dfile, d, raw ? 1 : (dds ? 0 : -1)) && (!dds || raw))
- {
- if(msg) conoutf(CON_ERROR, "could not load texture %s", dfile);
- return false;
- }
- if(d.data && !d.compressed && !dds && compress) *compress = scaledds;
- }
-
if(!d.data)
{
SDL_Surface *s = NULL;
@@ -1507,10 +1489,10 @@ static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL,
}
else if(matchstring(cmd, len, "premul")) texpremul(d);
else if(matchstring(cmd, len, "agrad")) texagrad(d, atof(arg[0]), atof(arg[1]), atof(arg[2]), atof(arg[3]));
- else if(matchstring(cmd, len, "compress") || matchstring(cmd, len, "dds"))
+ else if(matchstring(cmd, len, "compress"))
{
int scale = atoi(arg[0]);
- if(scale <= 0) scale = scaledds;
+ if(scale <= 0) scale = 2;
if(compress) *compress = scale;
}
else if(matchstring(cmd, len, "nocompress"))
@@ -2915,389 +2897,6 @@ void reloadtextures()
loadprogress = 0;
}
-enum
-{
- DDSD_CAPS = 0x00000001,
- DDSD_HEIGHT = 0x00000002,
- DDSD_WIDTH = 0x00000004,
- DDSD_PITCH = 0x00000008,
- DDSD_PIXELFORMAT = 0x00001000,
- DDSD_MIPMAPCOUNT = 0x00020000,
- DDSD_LINEARSIZE = 0x00080000,
- DDSD_BACKBUFFERCOUNT = 0x00800000,
- DDPF_ALPHAPIXELS = 0x00000001,
- DDPF_FOURCC = 0x00000004,
- DDPF_INDEXED = 0x00000020,
- DDPF_ALPHA = 0x00000002,
- DDPF_RGB = 0x00000040,
- DDPF_COMPRESSED = 0x00000080,
- DDPF_LUMINANCE = 0x00020000,
- DDSCAPS_COMPLEX = 0x00000008,
- DDSCAPS_TEXTURE = 0x00001000,
- DDSCAPS_MIPMAP = 0x00400000,
- DDSCAPS2_CUBEMAP = 0x00000200,
- DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400,
- DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800,
- DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000,
- DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000,
- DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000,
- DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000,
- DDSCAPS2_VOLUME = 0x00200000,
- FOURCC_DXT1 = 0x31545844,
- FOURCC_DXT2 = 0x32545844,
- FOURCC_DXT3 = 0x33545844,
- FOURCC_DXT4 = 0x34545844,
- FOURCC_DXT5 = 0x35545844,
- FOURCC_ATI1 = 0x31495441,
- FOURCC_ATI2 = 0x32495441
-};
-
-struct DDCOLORKEY { uint dwColorSpaceLowValue, dwColorSpaceHighValue; };
-struct DDPIXELFORMAT
-{
- uint dwSize, dwFlags, dwFourCC;
- union { uint dwRGBBitCount, dwYUVBitCount, dwZBufferBitDepth, dwAlphaBitDepth, dwLuminanceBitCount, dwBumpBitCount, dwPrivateFormatBitCount; };
- union { uint dwRBitMask, dwYBitMask, dwStencilBitDepth, dwLuminanceBitMask, dwBumpDuBitMask, dwOperations; };
- union { uint dwGBitMask, dwUBitMask, dwZBitMask, dwBumpDvBitMask; struct { ushort wFlipMSTypes, wBltMSTypes; } MultiSampleCaps; };
- union { uint dwBBitMask, dwVBitMask, dwStencilBitMask, dwBumpLuminanceBitMask; };
- union { uint dwRGBAlphaBitMask, dwYUVAlphaBitMask, dwLuminanceAlphaBitMask, dwRGBZBitMask, dwYUVZBitMask; };
-
-};
-struct DDSCAPS2 { uint dwCaps, dwCaps2, dwCaps3, dwCaps4; };
-struct DDSURFACEDESC2
-{
- uint dwSize, dwFlags, dwHeight, dwWidth;
- union { int lPitch; uint dwLinearSize; };
- uint dwBackBufferCount;
- union { uint dwMipMapCount, dwRefreshRate, dwSrcVBHandle; };
- uint dwAlphaBitDepth, dwReserved, lpSurface;
- union { DDCOLORKEY ddckCKDestOverlay; uint dwEmptyFaceColor; };
- DDCOLORKEY ddckCKDestBlt, ddckCKSrcOverlay, ddckCKSrcBlt;
- union { DDPIXELFORMAT ddpfPixelFormat; uint dwFVF; };
- DDSCAPS2 ddsCaps;
- uint dwTextureStage;
-};
-
-#define DECODEDDS(name, dbpp, initblock, writeval, nextval) \
-static void name(ImageData &s) \
-{ \
- ImageData d(s.w, s.h, dbpp); \
- uchar *dst = d.data; \
- const uchar *src = s.data; \
- for(int by = 0; by < s.h; by += s.align) \
- { \
- for(int bx = 0; bx < s.w; bx += s.align, src += s.bpp) \
- { \
- int maxy = min(d.h - by, s.align), maxx = min(d.w - bx, s.align); \
- initblock; \
- loop(y, maxy) \
- { \
- int x; \
- for(x = 0; x < maxx; ++x) \
- { \
- writeval; \
- nextval; \
- dst += d.bpp; \
- } \
- for(; x < s.align; ++x) { nextval; } \
- dst += d.pitch - maxx*d.bpp; \
- } \
- dst += maxx*d.bpp - maxy*d.pitch; \
- } \
- dst += (s.align-1)*d.pitch; \
- } \
- s.replace(d); \
-}
-
-DECODEDDS(decodedxt1, s.compressed == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 4 : 3,
- ushort color0 = lilswap(*(const ushort *)src);
- ushort color1 = lilswap(*(const ushort *)&src[2]);
- uint bits = lilswap(*(const uint *)&src[4]);
- bvec4 rgba[4];
- rgba[0] = bvec4(bvec::from565(color0), 0xFF);
- rgba[1] = bvec4(bvec::from565(color1), 0xFF);
- if(color0 > color1)
- {
- rgba[2].lerp(rgba[0], rgba[1], 2, 1, 3);
- rgba[3].lerp(rgba[0], rgba[1], 1, 2, 3);
- }
- else
- {
- rgba[2].lerp(rgba[0], rgba[1], 1, 1, 2);
- rgba[3] = bvec4(0, 0, 0, 0);
- }
-,
- memcpy(dst, rgba[bits&3].v, d.bpp);
-,
- bits >>= 2;
-);
-
-DECODEDDS(decodedxt3, 4,
- ullong alpha = lilswap(*(const ullong *)src);
- ushort color0 = lilswap(*(const ushort *)&src[8]);
- ushort color1 = lilswap(*(const ushort *)&src[10]);
- uint bits = lilswap(*(const uint *)&src[12]);
- bvec rgb[4];
- rgb[0] = bvec::from565(color0);
- rgb[1] = bvec::from565(color1);
- rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);
- rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);
-,
- memcpy(dst, rgb[bits&3].v, 3);
- dst[3] = ((alpha&0xF)*1088 + 32) >> 6;
-,
- bits >>= 2;
- alpha >>= 4;
-);
-
-static inline void decodealpha(uchar alpha0, uchar alpha1, uchar alpha[8])
-{
- alpha[0] = alpha0;
- alpha[1] = alpha1;
- if(alpha0 > alpha1)
- {
- alpha[2] = (6*alpha0 + alpha1)/7;
- alpha[3] = (5*alpha0 + 2*alpha1)/7;
- alpha[4] = (4*alpha0 + 3*alpha1)/7;
- alpha[5] = (3*alpha0 + 4*alpha1)/7;
- alpha[6] = (2*alpha0 + 5*alpha1)/7;
- alpha[7] = (alpha0 + 6*alpha1)/7;
- }
- else
- {
- alpha[2] = (4*alpha0 + alpha1)/5;
- alpha[3] = (3*alpha0 + 2*alpha1)/5;
- alpha[4] = (2*alpha0 + 3*alpha1)/5;
- alpha[5] = (alpha0 + 4*alpha1)/5;
- alpha[6] = 0;
- alpha[7] = 0xFF;
- }
-}
-
-DECODEDDS(decodedxt5, 4,
- uchar alpha[8];
- decodealpha(src[0], src[1], alpha);
- ullong alphabits = lilswap(*(const ushort *)&src[2]) + ((ullong)lilswap(*(const uint *)&src[4]) << 16);
- ushort color0 = lilswap(*(const ushort *)&src[8]);
- ushort color1 = lilswap(*(const ushort *)&src[10]);
- uint bits = lilswap(*(const uint *)&src[12]);
- bvec rgb[4];
- rgb[0] = bvec::from565(color0);
- rgb[1] = bvec::from565(color1);
- rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);
- rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);
-,
- memcpy(dst, rgb[bits&3].v, 3);
- dst[3] = alpha[alphabits&7];
-,
- bits >>= 2;
- alphabits >>= 3;
-);
-
-DECODEDDS(decodergtc1, 1,
- uchar red[8];
- decodealpha(src[0], src[1], red);
- ullong redbits = lilswap(*(const ushort *)&src[2]) + ((ullong)lilswap(*(const uint *)&src[4]) << 16);
-,
- dst[0] = red[redbits&7];
-,
- redbits >>= 3;
-);
-
-DECODEDDS(decodergtc2, 2,
- uchar red[8];
- decodealpha(src[0], src[1], red);
- ullong redbits = lilswap(*(const ushort *)&src[2]) + ((ullong)lilswap(*(const uint *)&src[4]) << 16);
- uchar green[8];
- decodealpha(src[8], src[9], green);
- ullong greenbits = lilswap(*(const ushort *)&src[10]) + ((ullong)lilswap(*(const uint *)&src[12]) << 16);
-,
- dst[0] = red[redbits&7];
- dst[1] = green[greenbits&7];
-,
- redbits >>= 3;
- greenbits >>= 3;
-);
-
-bool loaddds(const char *filename, ImageData &image, int force)
-{
- stream *f = openfile(filename, "rb");
- if(!f) return false;
- GLenum format = GL_FALSE;
- uchar magic[4];
- if(f->read(magic, 4) != 4 || memcmp(magic, "DDS ", 4)) { delete f; return false; }
- DDSURFACEDESC2 d;
- if(f->read(&d, sizeof(d)) != sizeof(d)) { delete f; return false; }
- lilswap((uint *)&d, sizeof(d)/sizeof(uint));
- if(d.dwSize != sizeof(DDSURFACEDESC2) || d.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) { delete f; return false; }
- bool supported = false;
- if(d.ddpfPixelFormat.dwFlags & DDPF_FOURCC)
- {
- switch(d.ddpfPixelFormat.dwFourCC)
- {
- case FOURCC_DXT1:
- if((supported = hasS3TC) || force) format = d.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS ? GL_COMPRESSED_RGBA_S3TC_DXT1_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
- break;
- case FOURCC_DXT2:
- case FOURCC_DXT3:
- if((supported = hasS3TC) || force) format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- break;
- case FOURCC_DXT4:
- case FOURCC_DXT5:
- if((supported = hasS3TC) || force) format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
- break;
- case FOURCC_ATI1:
- if((supported = hasRGTC) || force) format = GL_COMPRESSED_RED_RGTC1;
- else if((supported = hasLATC)) format = GL_COMPRESSED_LUMINANCE_LATC1_EXT;
- break;
- case FOURCC_ATI2:
- if((supported = hasRGTC) || force) format = GL_COMPRESSED_RG_RGTC2;
- else if((supported = hasLATC)) format = GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
- break;
- }
- }
- if(!format || (!supported && !force)) { delete f; return false; }
- if(dbgdds) conoutf(CON_DEBUG, "%s: format 0x%X, %d x %d, %d mipmaps", filename, format, d.dwWidth, d.dwHeight, d.dwMipMapCount);
- int bpp = 0;
- switch(format)
- {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: bpp = 8; break;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: bpp = 16; break;
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_RED_RGTC1: bpp = 8; break;
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_RG_RGTC2: bpp = 16; break;
- }
- image.setdata(NULL, d.dwWidth, d.dwHeight, bpp, !supported || force > 0 ? 1 : d.dwMipMapCount, 4, format);
- size_t size = image.calcsize();
- if(f->read(image.data, size) != size) { delete f; image.cleanup(); return false; }
- delete f;
- if(!supported || force > 0) switch(format)
- {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- decodedxt1(image);
- break;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- decodedxt3(image);
- break;
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- decodedxt5(image);
- break;
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_RED_RGTC1:
- decodergtc1(image);
- break;
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_RG_RGTC2:
- decodergtc2(image);
- break;
- }
- return true;
-}
-
-void gendds(char *infile, char *outfile)
-{
- if(!hasS3TC || usetexcompress <= 1) { conoutf(CON_ERROR, "OpenGL driver does not support S3TC texture compression"); return; }
-
- glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
-
- defformatstring(cfile, "<compress>%s", infile);
- extern void reloadtex(char *name);
- Texture *t = textures.access(path(cfile));
- if(t) reloadtex(cfile);
- t = textureload(cfile);
- if(t==notexture) { conoutf(CON_ERROR, "failed loading %s", infile); return; }
-
- glBindTexture(GL_TEXTURE_2D, t->id);
- GLint compressed = 0, format = 0, width = 0, height = 0;
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
-
- if(!compressed) { conoutf(CON_ERROR, "failed compressing %s", infile); return; }
- int fourcc = 0;
- switch(format)
- {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: fourcc = FOURCC_DXT1; conoutf("compressed as DXT1"); break;
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: fourcc = FOURCC_DXT1; conoutf("compressed as DXT1a"); break;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: fourcc = FOURCC_DXT3; conoutf("compressed as DXT3"); break;
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: fourcc = FOURCC_DXT5; conoutf("compressed as DXT5"); break;
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_RED_RGTC1: fourcc = FOURCC_ATI1; conoutf("compressed as ATI1"); break;
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_RG_RGTC2: fourcc = FOURCC_ATI2; conoutf("compressed as ATI2"); break;
- default:
- conoutf(CON_ERROR, "failed compressing %s: unknown format: 0x%X", infile, format); break;
- return;
- }
-
- if(!outfile[0])
- {
- static string buf;
- copystring(buf, infile);
- int len = strlen(buf);
- if(len > 4 && buf[len-4]=='.') memcpy(&buf[len-4], ".dds", 4);
- else concatstring(buf, ".dds");
- outfile = buf;
- }
-
- stream *f = openfile(path(outfile, true), "wb");
- if(!f) { conoutf(CON_ERROR, "failed writing to %s", outfile); return; }
-
- int csize = 0;
- for(int lw = width, lh = height, level = 0;;)
- {
- GLint size = 0;
- glGetTexLevelParameteriv(GL_TEXTURE_2D, level++, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
- csize += size;
- if(max(lw, lh) <= 1) break;
- if(lw > 1) lw /= 2;
- if(lh > 1) lh /= 2;
- }
-
- DDSURFACEDESC2 d;
- memset(&d, 0, sizeof(d));
- d.dwSize = sizeof(DDSURFACEDESC2);
- d.dwWidth = width;
- d.dwHeight = height;
- d.dwLinearSize = csize;
- d.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE | DDSD_MIPMAPCOUNT;
- d.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
- d.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
- d.ddpfPixelFormat.dwFlags = DDPF_FOURCC | (alphaformat(uncompressedformat(format)) ? DDPF_ALPHAPIXELS : 0);
- d.ddpfPixelFormat.dwFourCC = fourcc;
-
- uchar *data = new uchar[csize], *dst = data;
- for(int lw = width, lh = height;;)
- {
- GLint size;
- glGetTexLevelParameteriv(GL_TEXTURE_2D, d.dwMipMapCount, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
- glGetCompressedTexImage_(GL_TEXTURE_2D, d.dwMipMapCount++, dst);
- dst += size;
- if(max(lw, lh) <= 1) break;
- if(lw > 1) lw /= 2;
- if(lh > 1) lh /= 2;
- }
-
- lilswap((uint *)&d, sizeof(d)/sizeof(uint));
-
- f->write("DDS ", 4);
- f->write(&d, sizeof(d));
- f->write(data, csize);
- delete f;
-
- delete[] data;
-
- conoutf("wrote DDS file %s", outfile);
-
- setuptexcompress();
-}
-COMMAND(gendds, "ss");
-
void writepngchunk(stream *f, const char *type, uchar *data = NULL, uint len = 0)
{
f->putbig<uint>(len);
diff --git a/src/engine/texture.h b/src/engine/texture.h
index 61b0bd7..b39ba80 100644
--- a/src/engine/texture.h
+++ b/src/engine/texture.h
@@ -756,7 +756,6 @@ extern void setblurshader(int pass, int size, int radius, float *weights, float
extern void savepng(const char *filename, ImageData &image, bool flip = false);
extern void savetga(const char *filename, ImageData &image, bool flip = false);
-extern bool loaddds(const char *filename, ImageData &image, int force = 0);
extern bool loadimage(const char *filename, ImageData &image);
extern MSlot &lookupmaterialslot(int slot, bool load = true);
diff --git a/src/engine/water.cpp b/src/engine/water.cpp
index 9ae5847..ff184cc 100644
--- a/src/engine/water.cpp
+++ b/src/engine/water.cpp
@@ -771,19 +771,11 @@ void queryreflections()
{
Reflection &ref = reflections[i];
++ref.age;
- //~if(ref.height>=0 && !ref.age && ref.matsurfs.length())
- //~{
- //~/***/ref.matsurfs.setsize(0);
- //~}
}
if(waterfallrefract)
{
Reflection &ref = waterfallrefraction;
++ref.age;
- //~if(ref.height>=0 && !ref.age && ref.matsurfs.length())
- //~{
- //~/***/ref.matsurfs.setsize(0);
- //~}
}
if((editmode && showmat && !drawtex) || !oqfrags || !oqwater || drawtex == DRAWTEX_MINIMAP) return;
diff --git a/src/engine/worldio.cpp b/src/engine/worldio.cpp
index 387678c..d1fd52f 100644
--- a/src/engine/worldio.cpp
+++ b/src/engine/worldio.cpp
@@ -736,8 +736,6 @@ cube *loadchildren(stream *f, const ivec &co, int size, bool &failed)
return c;
}
-VAR(dbgvars, 0, 0, 1);
-
void savevslot(stream *f, VSlot &vs, int prev)
{
f->putlil<int>(vs.changed);
@@ -782,7 +780,6 @@ void savevslots(stream *f, int numvslots)
if(vslots.empty()) return;
int *prev = new int[numvslots];
for(int i=0;i<numvslots;++i)prev[i]=-1;
- //~memset((void*)prev, -1, (size_t)numvslots*sizeof(int));
loopi(numvslots)
{
VSlot *vs = vslots[i];
@@ -856,7 +853,6 @@ void loadvslots(stream *f, int numvslots)
int *prev = new (false) int[numvslots];
if(!prev) return;
for(int i=0;i<numvslots;++i)prev[i]=-1;
- //~memset((void*)prev, -1, (size_t)numvslots*sizeof(int));
while(numvslots > 0)
{
int changed = f->getlil<int>();
@@ -923,25 +919,20 @@ bool save_world(const char *mname, bool nolms)
switch(id.type)
{
case ID_VAR:
- if(dbgvars) conoutf(CON_DEBUG, "wrote var %s: %d", id.name, *id.storage.i);
f->putlil<int>(*id.storage.i);
break;
case ID_FVAR:
- if(dbgvars) conoutf(CON_DEBUG, "wrote fvar %s: %f", id.name, *id.storage.f);
f->putlil<float>(*id.storage.f);
break;
case ID_SVAR:
- if(dbgvars) conoutf(CON_DEBUG, "wrote svar %s: %s", id.name, *id.storage.s);
f->putlil<ushort>(strlen(*id.storage.s));
f->write(*id.storage.s, strlen(*id.storage.s));
break;
}
});
- if(dbgvars) conoutf(CON_DEBUG, "wrote %d vars", hdr.numvars);
-
f->putchar((int)strlen(game::gameident()));
f->write(game::gameident(), (int)strlen(game::gameident())+1);
f->putlil<ushort>(entities::extraentinfosize());
@@ -1090,7 +1081,6 @@ bool load_world(const char *mname, const char *cname) // still supports a
{
int val = f->getlil<int>();
if(exists && id->minval <= id->maxval) setvar(name, val);
- if(dbgvars) conoutf(CON_DEBUG, "read var %s: %d", name, val);
break;
}
@@ -1098,7 +1088,6 @@ bool load_world(const char *mname, const char *cname) // still supports a
{
float val = f->getlil<float>();
if(exists && id->minvalf <= id->maxvalf) setfvar(name, val);
- if(dbgvars) conoutf(CON_DEBUG, "read fvar %s: %f", name, val);
break;
}
@@ -1110,12 +1099,10 @@ bool load_world(const char *mname, const char *cname) // still supports a
val[min(slen, MAXSTRLEN-1)] = '\0';
if(slen >= MAXSTRLEN) f->seek(slen - (MAXSTRLEN-1), SEEK_CUR);
if(exists) setsvar(name, val);
- if(dbgvars) conoutf(CON_DEBUG, "read svar %s: %s", name, val);
break;
}
}
}
- if(dbgvars) conoutf(CON_DEBUG, "read %d vars", hdr.numvars);
string gametype;
copystring(gametype, "fps");