full header for rendermodel.hh

master
Daniel Kolesa 2020-05-27 01:00:45 +02:00
parent 2e715a5d90
commit 90dc5550a1
14 changed files with 53 additions and 220 deletions

View File

@ -1,3 +1,4 @@
#include "rendermodel.hh" // loadmapmodel
#include "stain.hh"
#include "texture.hh"

View File

@ -5,6 +5,8 @@
struct stainrenderer;
struct Texture;
struct physent;
struct extentity;
struct BIH
{

View File

@ -8,7 +8,6 @@
#include "light.hh"
#include "bih.hh"
#include "model.hh"
extern dynent *player;
extern physent *camera1; // special ent that acts as camera, same object as player1 in FPS mode
@ -201,39 +200,6 @@ extern bool overlapsdynent(const vec &o, float radius);
extern void rotatebb(vec &center, vec &radius, int yaw, int pitch, int roll = 0);
extern float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity *t = NULL);
// rendermodel
struct mapmodelinfo { string name; model *m, *collide; };
extern vector<mapmodelinfo> mapmodels;
extern void loadskin(const char *dir, const char *altdir, Texture *&skin, Texture *&masks);
extern void resetmodelbatches();
extern void startmodelquery(occludequery *query);
extern void endmodelquery();
extern void rendershadowmodelbatches(bool dynmodel = true);
extern void shadowmaskbatchedmodels(bool dynshadow = true);
extern void rendermapmodelbatches();
extern void rendermodelbatches();
extern void rendertransparentmodelbatches(int stencil = 0);
extern void rendermapmodel(int idx, int anim, const vec &o, float yaw = 0, float pitch = 0, float roll = 0, int flags = MDL_CULL_VFC | MDL_CULL_DIST, int basetime = 0, float size = 1);
extern void clearbatchedmapmodels();
extern void preloadusedmapmodels(bool msg = false, bool bih = false);
extern int batcheddynamicmodels();
extern int batcheddynamicmodelbounds(int mask, vec &bbmin, vec &bbmax);
extern void cleanupmodels();
static inline model *loadmapmodel(int n)
{
if(mapmodels.inrange(n))
{
model *m = mapmodels[n].m;
return m ? m : loadmodel(NULL, n);
}
return NULL;
}
static inline mapmodelinfo *getmminfo(int n) { return mapmodels.inrange(n) ? &mapmodels[n] : NULL; }
#endif
#endif

View File

@ -3,6 +3,7 @@
#include "blend.hh"
#include "movie.hh"
#include "rendergl.hh"
#include "rendermodel.hh" // cleanupmodels
#include "renderparticles.hh"
#include "rendersky.hh"
#include "rendertext.hh"

View File

@ -1,98 +0,0 @@
enum { MDL_MD2 = 0, MDL_MD3, MDL_MD5, MDL_OBJ, MDL_SMD, MDL_IQM, NUMMODELTYPES };
struct Shader;
struct model
{
char *name;
float spinyaw, spinpitch, spinroll, offsetyaw, offsetpitch, offsetroll;
bool shadow, alphashadow, depthoffset;
float scale;
vec translate;
BIH *bih;
vec bbcenter, bbradius, bbextend, collidecenter, collideradius;
float rejectradius, eyeheight, collidexyradius, collideheight;
char *collidemodel;
int collide, batch;
model(const char *name) : name(name ? newstring(name) : NULL), spinyaw(0), spinpitch(0), spinroll(0), offsetyaw(0), offsetpitch(0), offsetroll(0), shadow(true), alphashadow(true), depthoffset(false), scale(1.0f), translate(0, 0, 0), bih(0), bbcenter(0, 0, 0), bbradius(-1, -1, -1), bbextend(0, 0, 0), collidecenter(0, 0, 0), collideradius(-1, -1, -1), rejectradius(-1), eyeheight(0.9f), collidexyradius(0), collideheight(0), collidemodel(NULL), collide(COLLIDE_OBB), batch(-1) {}
virtual ~model() { DELETEA(name); DELETEP(bih); }
virtual void calcbb(vec &center, vec &radius) = 0;
virtual void calctransform(matrix4x3 &m) = 0;
virtual int intersect(int anim, int basetime, int basetime2, const vec &pos, float yaw, float pitch, float roll, dynent *d, modelattach *a, float size, const vec &o, const vec &ray, float &dist, int mode) = 0;
virtual void render(int anim, int basetime, int basetime2, const vec &o, float yaw, float pitch, float roll, dynent *d, modelattach *a = NULL, float size = 1, const vec4 &color = vec4(1, 1, 1, 1)) = 0;
virtual bool load() = 0;
virtual int type() const = 0;
virtual BIH *setBIH() { return NULL; }
virtual bool envmapped() const { return false; }
virtual bool skeletal() const { return false; }
virtual bool animated() const { return false; }
virtual bool pitched() const { return true; }
virtual bool alphatested() const { return false; }
virtual void setshader(Shader *shader) {}
virtual void setenvmap(float envmapmin, float envmapmax, Texture *envmap) {}
virtual void setspec(float spec) {}
virtual void setgloss(int gloss) {}
virtual void setglow(float glow, float glowdelta, float glowpulse) {}
virtual void setalphatest(float alpha) {}
virtual void setfullbright(float fullbright) {}
virtual void setcullface(int cullface) {}
virtual void setcolor(const vec &color) {}
virtual void genshadowmesh(vector<triangle> &tris, const matrix4x3 &orient) {}
virtual void preloadBIH() { if(!bih) setBIH(); }
virtual void preloadshaders() {}
virtual void preloadmeshes() {}
virtual void cleanup() {}
virtual void startrender() {}
virtual void endrender() {}
void boundbox(vec &center, vec &radius)
{
if(bbradius.x < 0)
{
calcbb(bbcenter, bbradius);
bbradius.add(bbextend);
}
center = bbcenter;
radius = bbradius;
}
float collisionbox(vec &center, vec &radius)
{
if(collideradius.x < 0)
{
boundbox(collidecenter, collideradius);
if(collidexyradius)
{
collidecenter.x = collidecenter.y = 0;
collideradius.x = collideradius.y = collidexyradius;
}
if(collideheight)
{
collidecenter.z = collideradius.z = collideheight/2;
}
rejectradius = collideradius.magnitude();
}
center = collidecenter;
radius = collideradius;
return rejectradius;
}
float boundsphere(vec &center)
{
vec radius;
boundbox(center, radius);
return radius.magnitude();
}
float above()
{
vec center, radius;
boundbox(center, radius);
return center.z+radius.z;
}
};

View File

@ -3,6 +3,7 @@
// they "felt right", and have no basis in reality. Collision detection is simplistic but
// very robust (uses discrete steps at fixed fps).
#include "rendermodel.hh"
#include "octa.hh"
#include "world.hh"

View File

@ -7,6 +7,7 @@
#include "pvs.hh"
#include "rendergl.hh"
#include "renderlights.hh"
#include "rendermodel.hh"
#include "renderparticles.hh"
#include "rendersky.hh"
#include "rendertext.hh"

View File

@ -35,6 +35,8 @@ static model *__loadmodel__##modelclass(const char *filename) \
} \
UNUSED static int __dummy__##modelclass = addmodeltype((modeltype), __loadmodel__##modelclass);
static void loadskin(const char *dir, const char *altdir, Texture *&skin, Texture *&masks);
#include "md2.hh"
#include "md3.hh"
#include "md5.hh"
@ -51,35 +53,35 @@ MODELTYPE(MDL_IQM, iqm);
#define checkmdl if(!loadingmodel) { conoutf(CON_ERROR, "not loading a model"); return; }
void mdlcullface(int *cullface)
static void mdlcullface(int *cullface)
{
checkmdl;
loadingmodel->setcullface(*cullface);
}
COMMAND(mdlcullface, "i");
void mdlcolor(float *r, float *g, float *b)
static void mdlcolor(float *r, float *g, float *b)
{
checkmdl;
loadingmodel->setcolor(vec(*r, *g, *b));
}
COMMAND(mdlcolor, "fff");
void mdlcollide(int *collide)
static void mdlcollide(int *collide)
{
checkmdl;
loadingmodel->collide = *collide!=0 ? (loadingmodel->collide ? loadingmodel->collide : COLLIDE_OBB) : COLLIDE_NONE;
}
COMMAND(mdlcollide, "i");
void mdlellipsecollide(int *collide)
static void mdlellipsecollide(int *collide)
{
checkmdl;
loadingmodel->collide = *collide!=0 ? COLLIDE_ELLIPSE : COLLIDE_NONE;
}
COMMAND(mdlellipsecollide, "i");
void mdltricollide(char *collide)
static void mdltricollide(char *collide)
{
checkmdl;
DELETEA(loadingmodel->collidemodel);
@ -90,7 +92,7 @@ void mdltricollide(char *collide)
}
COMMAND(mdltricollide, "s");
void mdlspec(float *percent)
static void mdlspec(float *percent)
{
checkmdl;
float spec = *percent > 0 ? *percent/100.0f : 0.0f;
@ -98,28 +100,28 @@ void mdlspec(float *percent)
}
COMMAND(mdlspec, "f");
void mdlgloss(int *gloss)
static void mdlgloss(int *gloss)
{
checkmdl;
loadingmodel->setgloss(clamp(*gloss, 0, 2));
}
COMMAND(mdlgloss, "i");
void mdlalphatest(float *cutoff)
static void mdlalphatest(float *cutoff)
{
checkmdl;
loadingmodel->setalphatest(max(0.0f, min(1.0f, *cutoff)));
}
COMMAND(mdlalphatest, "f");
void mdldepthoffset(int *offset)
static void mdldepthoffset(int *offset)
{
checkmdl;
loadingmodel->depthoffset = *offset!=0;
}
COMMAND(mdldepthoffset, "i");
void mdlglow(float *percent, float *delta, float *pulse)
static void mdlglow(float *percent, float *delta, float *pulse)
{
checkmdl;
float glow = *percent > 0 ? *percent/100.0f : 0.0f, glowdelta = *delta/100.0f, glowpulse = *pulse > 0 ? *pulse/1000.0f : 0;
@ -128,28 +130,28 @@ void mdlglow(float *percent, float *delta, float *pulse)
}
COMMAND(mdlglow, "fff");
void mdlenvmap(float *envmapmax, float *envmapmin, char *envmap)
static void mdlenvmap(float *envmapmax, float *envmapmin, char *envmap)
{
checkmdl;
loadingmodel->setenvmap(*envmapmin, *envmapmax, envmap[0] ? cubemapload(envmap) : NULL);
}
COMMAND(mdlenvmap, "ffs");
void mdlfullbright(float *fullbright)
static void mdlfullbright(float *fullbright)
{
checkmdl;
loadingmodel->setfullbright(*fullbright);
}
COMMAND(mdlfullbright, "f");
void mdlshader(char *shader)
static void mdlshader(char *shader)
{
checkmdl;
loadingmodel->setshader(lookupshaderbyname(shader));
}
COMMAND(mdlshader, "s");
void mdlspin(float *yaw, float *pitch, float *roll)
static void mdlspin(float *yaw, float *pitch, float *roll)
{
checkmdl;
loadingmodel->spinyaw = *yaw;
@ -158,7 +160,7 @@ void mdlspin(float *yaw, float *pitch, float *roll)
}
COMMAND(mdlspin, "fff");
void mdlscale(float *percent)
static void mdlscale(float *percent)
{
checkmdl;
float scale = *percent > 0 ? *percent/100.0f : 1.0f;
@ -166,49 +168,49 @@ void mdlscale(float *percent)
}
COMMAND(mdlscale, "f");
void mdltrans(float *x, float *y, float *z)
static void mdltrans(float *x, float *y, float *z)
{
checkmdl;
loadingmodel->translate = vec(*x, *y, *z);
}
COMMAND(mdltrans, "fff");
void mdlyaw(float *angle)
static void mdlyaw(float *angle)
{
checkmdl;
loadingmodel->offsetyaw = *angle;
}
COMMAND(mdlyaw, "f");
void mdlpitch(float *angle)
static void mdlpitch(float *angle)
{
checkmdl;
loadingmodel->offsetpitch = *angle;
}
COMMAND(mdlpitch, "f");
void mdlroll(float *angle)
static void mdlroll(float *angle)
{
checkmdl;
loadingmodel->offsetroll = *angle;
}
COMMAND(mdlroll, "f");
void mdlshadow(int *shadow)
static void mdlshadow(int *shadow)
{
checkmdl;
loadingmodel->shadow = *shadow!=0;
}
COMMAND(mdlshadow, "i");
void mdlalphashadow(int *alphashadow)
static void mdlalphashadow(int *alphashadow)
{
checkmdl;
loadingmodel->alphashadow = *alphashadow!=0;
}
COMMAND(mdlalphashadow, "i");
void mdlbb(float *rad, float *h, float *eyeheight)
static void mdlbb(float *rad, float *h, float *eyeheight)
{
checkmdl;
loadingmodel->collidexyradius = *rad;
@ -217,14 +219,14 @@ void mdlbb(float *rad, float *h, float *eyeheight)
}
COMMAND(mdlbb, "fff");
void mdlextendbb(float *x, float *y, float *z)
static void mdlextendbb(float *x, float *y, float *z)
{
checkmdl;
loadingmodel->bbextend = vec(*x, *y, *z);
}
COMMAND(mdlextendbb, "fff");
void mdlname()
static void mdlname()
{
checkmdl;
result(loadingmodel->name);
@ -244,7 +246,7 @@ COMMAND(mdlname, "");
if(ragdoll->loaded) return;
void rdvert(float *x, float *y, float *z, float *radius)
static void rdvert(float *x, float *y, float *z, float *radius)
{
checkragdoll;
ragdollskel::vert &v = ragdoll->verts.add();
@ -253,14 +255,14 @@ void rdvert(float *x, float *y, float *z, float *radius)
}
COMMAND(rdvert, "ffff");
void rdeye(int *v)
static void rdeye(int *v)
{
checkragdoll;
ragdoll->eye = *v;
}
COMMAND(rdeye, "i");
void rdtri(int *v1, int *v2, int *v3)
static void rdtri(int *v1, int *v2, int *v3)
{
checkragdoll;
ragdollskel::tri &t = ragdoll->tris.add();
@ -270,7 +272,7 @@ void rdtri(int *v1, int *v2, int *v3)
}
COMMAND(rdtri, "iii");
void rdjoint(int *n, int *t, int *v1, int *v2, int *v3)
static void rdjoint(int *n, int *t, int *v1, int *v2, int *v3)
{
checkragdoll;
if(*n < 0 || *n >= skel->numbones) return;
@ -283,7 +285,7 @@ void rdjoint(int *n, int *t, int *v1, int *v2, int *v3)
}
COMMAND(rdjoint, "iibbb");
void rdlimitdist(int *v1, int *v2, float *mindist, float *maxdist)
static void rdlimitdist(int *v1, int *v2, float *mindist, float *maxdist)
{
checkragdoll;
ragdollskel::distlimit &d = ragdoll->distlimits.add();
@ -294,7 +296,7 @@ void rdlimitdist(int *v1, int *v2, float *mindist, float *maxdist)
}
COMMAND(rdlimitdist, "iiff");
void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float *qz, float *qw)
static void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float *qz, float *qw)
{
checkragdoll;
ragdollskel::rotlimit &r = ragdoll->rotlimits.add();
@ -306,7 +308,7 @@ void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float *
}
COMMAND(rdlimitrot, "iifffff");
void rdanimjoints(int *on)
static void rdanimjoints(int *on)
{
checkragdoll;
ragdoll->animjoints = *on!=0;
@ -319,7 +321,7 @@ vector<mapmodelinfo> mapmodels;
static const char * const mmprefix = "mapmodel/";
static const int mmprefixlen = strlen(mmprefix);
void mapmodel(char *name)
static void mapmodel(char *name)
{
mapmodelinfo &mmi = mapmodels.add();
if(name[0]) formatstring(mmi.name, "%s%s", mmprefix, name);
@ -327,7 +329,7 @@ void mapmodel(char *name)
mmi.m = mmi.collide = NULL;
}
void mapmodelreset(int *n)
static void mapmodelreset(int *n)
{
if(!(identflags&IDF_OVERRIDDEN) && !game::allowedittoggle()) return;
mapmodels.shrink(clamp(*n, 0, mapmodels.length()));
@ -344,9 +346,9 @@ ICOMMAND(nummapmodels, "", (), { intret(mapmodels.length()); });
// model registry
hashnameset<model *> models;
vector<const char *> preloadmodels;
hashset<char *> failedmodels;
static hashnameset<model *> models;
static vector<const char *> preloadmodels;
static hashset<char *> failedmodels;
void preloadmodel(const char *name)
{
@ -462,7 +464,7 @@ void cleanupmodels()
enumerate(models, model *, m, m->cleanup());
}
void clearmodel(char *name)
static void clearmodel(char *name)
{
model *m = models.find(name, NULL);
if(!m) { conoutf("model %s is not loaded", name); return; }
@ -480,7 +482,7 @@ void clearmodel(char *name)
COMMAND(clearmodel, "s");
bool modeloccluded(const vec &center, float radius)
static bool modeloccluded(const vec &center, float radius)
{
ivec bbmin(vec(center).sub(radius)), bbmax(vec(center).add(radius+1));
return pvsoccluded(bbmin, bbmax) || bboccluded(bbmin, bbmax);
@ -516,7 +518,7 @@ void resetmodelbatches()
modelattached.setsize(0);
}
void addbatchedmodel(model *m, batchedmodel &bm, int idx)
static void addbatchedmodel(model *m, batchedmodel &bm, int idx)
{
modelbatch *b = NULL;
if(batches.inrange(m->batch))
@ -1098,7 +1100,7 @@ ICOMMAND(findanims, "s", (char *name),
result(buf.getbuf());
});
void loadskin(const char *dir, const char *altdir, Texture *&skin, Texture *&masks) // model skin sharing
static void loadskin(const char *dir, const char *altdir, Texture *&skin, Texture *&masks) // model skin sharing
{
#define ifnoload(tex, path) if((tex = textureload(path, 0, true, false))==notexture)
#define tryload(tex, prefix, cmd, name) \

View File

@ -6,6 +6,7 @@
#include "pvs.hh"
#include "rendergl.hh"
#include "renderlights.hh"
#include "rendermodel.hh"
#include "rendersky.hh"
#include "texture.hh"

View File

@ -1,6 +1,7 @@
// shader.cpp: OpenGL GLSL shader management
#include "rendergl.hh"
#include "rendermodel.hh" // cleanupmodels
#include "shader.hh"
#include "texture.hh"

View File

@ -1,5 +1,6 @@
#include "material.hh"
#include "rendergl.hh"
#include "rendermodel.hh" // loadmapmodel
#include "stain.hh"
#include "texture.hh"

View File

@ -5,6 +5,7 @@
#include "pvs.hh"
#include "rendergl.hh" /* fovy */
#include "renderlights.hh"
#include "rendermodel.hh" // loadmapmodel
#include "renderparticles.hh"
#include "stain.hh"
#include "texture.hh"

View File

@ -3,6 +3,7 @@
#include "blend.hh"
#include "octa.hh"
#include "pvs.hh"
#include "rendermodel.hh" // loadmapmodel, getmminfo, flushpreloadedmodels
#include "texture.hh"
#include "world.hh"
#include "worldio.hh"

View File

@ -223,54 +223,6 @@ extern void updatedynentcache(physent *d);
extern bool entinmap(dynent *d, bool avoidplayers = false);
extern void findplayerspawn(dynent *d, int forceent = -1, int tag = 0);
// sound
enum
{
SND_MAP = 1<<0,
SND_NO_ALT = 1<<1,
SND_USE_ALT = 1<<2
};
inline int playsound(
int, const vec * = NULL, extentity * = NULL, int = 0, int = 0, int = 0,
int = -1, int = 0, int = -1
) {
return -1;
}
// rendermodel
enum { MDL_CULL_VFC = 1<<0, MDL_CULL_DIST = 1<<1, MDL_CULL_OCCLUDED = 1<<2, MDL_CULL_QUERY = 1<<3, MDL_FULLBRIGHT = 1<<4, MDL_NORENDER = 1<<5, MDL_MAPMODEL = 1<<6, MDL_NOBATCH = 1<<7, MDL_ONLYSHADOW = 1<<8, MDL_NOSHADOW = 1<<9, MDL_FORCESHADOW = 1<<10, MDL_FORCETRANSPARENT = 1<<11 };
struct model;
struct modelattach
{
const char *tag, *name;
int anim, basetime;
vec *pos;
model *m;
modelattach() : tag(NULL), name(NULL), anim(-1), basetime(0), pos(NULL), m(NULL) {}
modelattach(const char *tag, const char *name, int anim = -1, int basetime = 0) : tag(tag), name(name), anim(anim), basetime(basetime), pos(NULL), m(NULL) {}
modelattach(const char *tag, vec *pos) : tag(tag), name(NULL), anim(-1), basetime(0), pos(pos), m(NULL) {}
};
extern void rendermodel(const char *mdl, int anim, const vec &o, float yaw = 0, float pitch = 0, float roll = 0, int cull = MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED, dynent *d = NULL, modelattach *a = NULL, int basetime = 0, int basetime2 = 0, float size = 1, const vec4 &color = vec4(1, 1, 1, 1));
extern int intersectmodel(const char *mdl, int anim, const vec &pos, float yaw, float pitch, float roll, const vec &o, const vec &ray, float &dist, int mode = 0, dynent *d = NULL, modelattach *a = NULL, int basetime = 0, int basetime2 = 0, float size = 1);
extern void abovemodel(vec &o, const char *mdl);
extern void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float scale = 1, bool ragdoll = false, float trans = 1);
extern void interpolateorientation(dynent *d, float &interpyaw, float &interppitch);
extern void setbbfrommodel(dynent *d, const char *mdl);
extern const char *mapmodelname(int i);
extern model *loadmodel(const char *name, int i = -1, bool msg = false);
extern void preloadmodel(const char *name);
extern void flushpreloadedmodels(bool msg = true);
extern bool matchanim(const char *name, const char *pattern);
// ragdoll
extern void moveragdoll(dynent *d);
extern void cleanragdoll(dynent *d);
// client
extern bool haslocalclients();
extern bool isconnected(bool attempt = false, bool local = true);