diff --git a/source/src/main.cpp b/source/src/main.cpp index 1ffd0324..18315afe 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -275,6 +275,7 @@ int main(int argc, char **argv) log("models"); preload_playermodels(); preload_hudguns(); + preload_entmodels(); execute("start_game"); diff --git a/source/src/md2.h b/source/src/md2.h index 8c7707dd..85021354 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -196,10 +196,10 @@ struct md2 : vertmodel } } - void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw, model *vwepmdl) + void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float yaw, model *vwepmdl) { - parts[0]->rendershadow(anim, varseed, speed, basetime, o, rad, yaw); - if(vwepmdl) ((md2 *)vwepmdl)->parts[0]->rendershadow(anim, varseed, speed, basetime, o, rad, yaw); + parts[0]->rendershadow(anim, varseed, speed, basetime, o, yaw); + if(vwepmdl) ((md2 *)vwepmdl)->parts[0]->rendershadow(anim, varseed, speed, basetime, o, yaw); } bool load() diff --git a/source/src/md3.h b/source/src/md3.h index cbc5e7ab..dfe0b8f2 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -167,6 +167,12 @@ struct md3 : vertmodel glPopMatrix(); } + void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float yaw, model *vwepmdl) + { + if(parts.length()>1) return; + parts[0]->rendershadow(anim, varseed, speed, basetime, o, yaw); + } + bool load() { if(loaded) return true; diff --git a/source/src/model.h b/source/src/model.h index 692e6a52..07c1cec6 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -37,7 +37,8 @@ struct model virtual int type() = 0; virtual void genshadows(float height, float rad) {} - virtual void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw, model *vwepmdl = NULL) {} + virtual void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float yaw, model *vwepmdl = NULL) {} + virtual bool hasshadows() { return false; } }; struct mapmodelinfo { int rad, h, zoff; string name; model *m; }; diff --git a/source/src/protos.h b/source/src/protos.h index fd5f689a..2b18702f 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -250,6 +250,7 @@ extern int findanim(const char *name); extern void loadskin(const char *dir, const char *altdir, Texture *&skin, model *m); extern model *loadmodel(const char *name, int i = -1); extern void preload_playermodels(); +extern void preload_entmodels(); extern void preload_hudguns(); extern void preload_mapmodels(); extern void renderclients(); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 38ed425c..c9eb53f3 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -115,15 +115,13 @@ void rendermodel(char *mdl, int anim, int tex, float rad, float x, float y, floa light.y = s->g/ll+of; light.z = s->b/ll+of; - if(dynshadow && d && (anim&ANIM_INDEX)!=ANIM_LYING_DEAD) + if(dynshadow && m->hasshadows() && (!d || (anim&ANIM_INDEX)!=ANIM_LYING_DEAD)) { vec center(x, z, s->floor); if(s->type==FHF) center.z -= s->vdelta/4.0f; - float radius = 4.0f; - radius *= 1.0f + min(1.0f, max(0.0f, 0.5f*(y - d->eyeheight - center.z)/(d->aboveeye + d->eyeheight))); center.z += 0.1f; glColor4f(1, 1, 1, dynshadow/100.0f); - m->rendershadow(anim, varseed, speed, basetime, center, radius, yaw, vwep); + m->rendershadow(anim, varseed, speed, basetime, center, yaw, vwep); } } @@ -173,6 +171,22 @@ void preload_playermodels() } } +void preload_entmodels() +{ + extern char *entmdlnames[]; + loopi(I_AKIMBO-I_CLIPS+1) + { + model *mdl = loadmodel(entmdlnames[i]); + if(dynshadow && mdl) mdl->genshadows(8.0f, 2.0f); + } + static char *bouncemdlnames[] = { "misc/gib01", "misc/gib02", "misc/gib03", "weapons/grenade/static" }; + loopi(sizeof(bouncemdlnames)/sizeof(bouncemdlnames[0])) + { + model *mdl = loadmodel(bouncemdlnames[i]); + if(dynshadow && mdl) mdl->genshadows(8.0f, 2.0f); + } +} + void preload_mapmodels() { int xs, ys; diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index f6068f81..a7bd2c00 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -149,7 +149,7 @@ struct vertmodel : model if(index>=tristrip::RESTART) continue; } tcvert &tc = tcverts[index]; - if(!(as.anim&ANIM_NOSKIN)) glTexCoord2f(tc.u, tc.v); + if(isstat || !(as.anim&ANIM_NOSKIN)) glTexCoord2f(tc.u, tc.v); glVertex3fv(&dynbuf[tc.index].x); } glEnd(); @@ -191,8 +191,9 @@ struct vertmodel : model tag *tags; int numtags; GLuint *shadows; + float shadowrad; - part() : loaded(false), anims(NULL), links(NULL), tags(NULL), numtags(0), shadows(NULL) {} + part() : loaded(false), anims(NULL), links(NULL), tags(NULL), numtags(0), shadows(NULL), shadowrad(0) {} virtual ~part() { meshes.deletecontentsp(); @@ -407,6 +408,7 @@ struct vertmodel : model { if(shadows) return; + shadowrad = rad; shadows = new GLuint[numframes]; glGenTextures(numframes, shadows); @@ -436,7 +438,7 @@ struct vertmodel : model glViewport(0, 0, scr_w, scr_h); } - void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw) + void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float yaw) { if(!shadows) return; animstate as; @@ -452,8 +454,8 @@ struct vertmodel : model yaw *= RAD; float c = cosf(yaw), s = sinf(yaw); - float x1 = -rad, x2 = +rad; - float y1 = -rad, y2 = +rad; + float x1 = -shadowrad, x2 = shadowrad; + float y1 = -shadowrad, y2 = shadowrad; glBegin(GL_POLYGON); glTexCoord2f(0, 1); glVertex3f(x1*c - y1*s + o.x, o.z, y1*c + x1*s + o.y); @@ -499,7 +501,13 @@ struct vertmodel : model void genshadows(float height, float rad) { - loopv(parts) parts[i]->genshadows(height, rad); + if(parts.length()>1) return; + parts[0]->genshadows(height, rad); + } + + bool hasshadows() + { + return parts.length()==1 && parts[0]->shadows; } };