297 lines
10 KiB
C++
297 lines
10 KiB
C++
#ifndef __ENGINE_H__
|
|
#define __ENGINE_H__
|
|
|
|
#include "cube.hh"
|
|
#include "world.hh"
|
|
|
|
#ifndef STANDALONE
|
|
|
|
#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
|
|
|
|
extern int worldscale, worldsize;
|
|
extern int mapversion;
|
|
extern char *maptitle;
|
|
extern vector<ushort> texmru;
|
|
extern int xtraverts, xtravertsva;
|
|
extern const ivec cubecoords[8];
|
|
extern const ivec facecoords[6][4];
|
|
extern const uchar fv[6][4];
|
|
extern const uchar fvmasks[64];
|
|
extern const uchar faceedgesidx[6][4];
|
|
extern bool inbetweenframes, renderedframe;
|
|
|
|
extern SDL_Window *screen;
|
|
extern int screenw, screenh;
|
|
|
|
// texture
|
|
struct cubemapside;
|
|
|
|
extern void drawcubemap(int size, const vec &o, float yaw, float pitch, const cubemapside &side, bool onlysky = false);
|
|
extern void compacteditvslots();
|
|
extern void compactmruvslots();
|
|
|
|
// renderlights
|
|
|
|
#include "renderlights.hh"
|
|
|
|
extern int lighttilealignw, lighttilealignh, lighttilevieww, lighttileviewh, lighttilew, lighttileh;
|
|
|
|
extern int vieww, viewh; /* rendergl */
|
|
|
|
template<class T>
|
|
static inline void calctilebounds(float sx1, float sy1, float sx2, float sy2, T &bx1, T &by1, T &bx2, T &by2)
|
|
{
|
|
int tx1 = max(int(floor(((sx1 + 1)*0.5f*vieww)/lighttilealignw)), 0),
|
|
ty1 = max(int(floor(((sy1 + 1)*0.5f*viewh)/lighttilealignh)), 0),
|
|
tx2 = min(int(ceil(((sx2 + 1)*0.5f*vieww)/lighttilealignw)), lighttilevieww),
|
|
ty2 = min(int(ceil(((sy2 + 1)*0.5f*viewh)/lighttilealignh)), lighttileviewh);
|
|
bx1 = T((tx1 * lighttilew) / lighttilevieww);
|
|
by1 = T((ty1 * lighttileh) / lighttileviewh);
|
|
bx2 = T((tx2 * lighttilew + lighttilevieww - 1) / lighttilevieww);
|
|
by2 = T((ty2 * lighttileh + lighttileviewh - 1) / lighttileviewh);
|
|
}
|
|
|
|
static inline void masktiles(uint *tiles, float sx1, float sy1, float sx2, float sy2)
|
|
{
|
|
int tx1, ty1, tx2, ty2;
|
|
calctilebounds(sx1, sy1, sx2, sy2, tx1, ty1, tx2, ty2);
|
|
for(int ty = ty1; ty < ty2; ty++) tiles[ty] |= ((1<<(tx2-tx1))-1)<<tx1;
|
|
}
|
|
|
|
enum { SM_NONE = 0, SM_REFLECT, SM_CUBEMAP, SM_CASCADE, SM_SPOT };
|
|
|
|
extern int shadowmapping;
|
|
|
|
extern matrix4 shadowmatrix;
|
|
|
|
extern void loaddeferredlightshaders();
|
|
extern void cleardeferredlightshaders();
|
|
extern void clearshadowcache();
|
|
|
|
extern void rendervolumetric();
|
|
extern void cleanupvolumetric();
|
|
|
|
extern int calcshadowinfo(const extentity &e, vec &origin, float &radius, vec &spotloc, int &spotangle, float &bias);
|
|
extern void rendershadowatlas();
|
|
extern bool useradiancehints();
|
|
extern void renderradiancehints();
|
|
extern void clearradiancehintscache();
|
|
extern void cleanuplights();
|
|
extern void workinoq();
|
|
|
|
extern int calcbbcsmsplits(const ivec &bbmin, const ivec &bbmax);
|
|
extern int calcspherecsmsplits(const vec ¢er, float radius);
|
|
extern int calcbbrsmsplits(const ivec &bbmin, const ivec &bbmax);
|
|
extern int calcspherersmsplits(const vec ¢er, float radius);
|
|
|
|
static inline bool sphereinsidespot(const vec &dir, int spot, const vec ¢er, float radius)
|
|
{
|
|
const vec2 &sc = sincos360[spot];
|
|
float cdist = dir.dot(center), cradius = radius + sc.y*cdist;
|
|
return sc.x*sc.x*(center.dot(center) - cdist*cdist) <= cradius*cradius;
|
|
}
|
|
static inline bool bbinsidespot(const vec &origin, const vec &dir, int spot, const ivec &bbmin, const ivec &bbmax)
|
|
{
|
|
vec radius = vec(ivec(bbmax).sub(bbmin)).mul(0.5f), center = vec(bbmin).add(radius);
|
|
return sphereinsidespot(dir, spot, center.sub(origin), radius.magnitude());
|
|
}
|
|
|
|
extern matrix4 worldmatrix, screenmatrix;
|
|
|
|
extern int transparentlayer;
|
|
|
|
extern int gw, gh, gdepthformat, ghasstencil;
|
|
extern GLuint gdepthtex, gcolortex, gnormaltex, gglowtex, gdepthrb, gstencilrb;
|
|
extern int msaasamples, msaalight;
|
|
extern GLuint msdepthtex, mscolortex, msnormaltex, msglowtex, msdepthrb, msstencilrb;
|
|
extern vector<vec2> msaapositions;
|
|
enum { AA_UNUSED = 0, AA_LUMA, AA_MASKED, AA_SPLIT, AA_SPLIT_LUMA, AA_SPLIT_MASKED };
|
|
|
|
extern void cleanupgbuffer();
|
|
extern void initgbuffer();
|
|
extern bool usepacknorm();
|
|
extern void maskgbuffer(const char *mask);
|
|
extern void bindgdepth();
|
|
extern void preparegbuffer(bool depthclear = true);
|
|
extern void rendergbuffer(bool depthclear = true);
|
|
extern void shadesky();
|
|
extern void shadegbuffer();
|
|
extern void shademinimap(const vec &color = vec(-1, -1, -1));
|
|
extern void shademodelpreview(int x, int y, int w, int h, bool background = true, bool scissor = false);
|
|
extern void rendertransparent();
|
|
extern void renderao();
|
|
extern void loadhdrshaders(int aa = AA_UNUSED);
|
|
extern void processhdr(GLuint outfbo = 0, int aa = AA_UNUSED);
|
|
extern void copyhdr(int sw, int sh, GLuint fbo, int dw = 0, int dh = 0, bool flipx = false, bool flipy = false, bool swapxy = false);
|
|
extern void setuplights();
|
|
extern void setupgbuffer();
|
|
extern GLuint shouldscale();
|
|
extern void doscale(GLuint outfbo = 0);
|
|
extern bool debuglights();
|
|
extern void cleanuplights();
|
|
|
|
extern int avatarmask;
|
|
extern bool useavatarmask();
|
|
extern void enableavatarmask();
|
|
extern void disableavatarmask();
|
|
|
|
// octaedit
|
|
extern void cancelsel();
|
|
extern void rendertexturepanel(int w, int h);
|
|
extern void addundo(undoblock *u);
|
|
extern void commitchanges(bool force = false);
|
|
extern void changed(const ivec &bbmin, const ivec &bbmax, bool commit = true);
|
|
extern void changed(const block3 &sel, bool commit = true);
|
|
extern void rendereditcursor();
|
|
extern void tryedit();
|
|
|
|
extern void renderprefab(const char *name, const vec &o, float yaw, float pitch, float roll, float size = 1, const vec &color = vec(1, 1, 1));
|
|
extern void previewprefab(const char *name, const vec &color);
|
|
extern void cleanupprefabs();
|
|
|
|
// octarender
|
|
extern ivec worldmin, worldmax, nogimin, nogimax;
|
|
extern vector<tjoint> tjoints;
|
|
extern vector<vtxarray *> varoot, valist;
|
|
|
|
extern ushort encodenormal(const vec &n);
|
|
extern vec decodenormal(ushort norm);
|
|
extern void guessnormals(const vec *pos, int numverts, vec *normals);
|
|
extern void reduceslope(ivec &n);
|
|
extern void findtjoints();
|
|
extern void octarender();
|
|
extern void allchanged(bool load = false);
|
|
extern void clearvas(cube *c);
|
|
extern void destroyva(vtxarray *va, bool reparent = true);
|
|
extern void updatevabb(vtxarray *va, bool force = false);
|
|
extern void updatevabbs(bool force = false);
|
|
|
|
// dynlight
|
|
|
|
extern void updatedynlights();
|
|
extern int finddynlights();
|
|
extern bool getdynlight(int n, vec &o, float &radius, vec &color, vec &dir, int &spot, int &flags);
|
|
|
|
// client
|
|
extern void localdisconnect(bool cleanup = true);
|
|
extern void clientkeepalive();
|
|
|
|
// command
|
|
extern hashnameset<ident> idents;
|
|
extern int identflags;
|
|
|
|
extern void clearoverrides();
|
|
extern void writecfg(const char *name = NULL);
|
|
|
|
extern void checksleep(int millis);
|
|
extern void clearsleep(bool clearoverrides = true);
|
|
|
|
// console
|
|
extern float conscale;
|
|
|
|
extern void processkey(int code, bool isdown, int modstate = 0);
|
|
extern void processtextinput(const char *str, int len);
|
|
extern float rendercommand(float x, float y, float w);
|
|
extern float renderfullconsole(float w, float h);
|
|
extern float renderconsole(float w, float h, float abovehud);
|
|
extern void conoutf(const char *s, ...) PRINTFARGS(1, 2);
|
|
extern void conoutf(int type, const char *s, ...) PRINTFARGS(2, 3);
|
|
extern void resetcomplete();
|
|
extern void complete(char *s, int maxlen, const char *cmdprefix);
|
|
const char *getkeyname(int code);
|
|
extern const char *addreleaseaction(char *s);
|
|
extern tagval *addreleaseaction(ident *id, int numargs);
|
|
extern void writebinds(stream *f);
|
|
extern void writecompletions(stream *f);
|
|
|
|
// main
|
|
|
|
extern int mainmenu;
|
|
|
|
extern void clearmainmenu();
|
|
|
|
enum
|
|
{
|
|
NOT_INITING = 0,
|
|
INIT_GAME,
|
|
INIT_LOAD,
|
|
INIT_RESET
|
|
};
|
|
extern int initing, numcpus;
|
|
|
|
extern bool initwarning(const char *desc, int level = INIT_RESET, int type = 0);
|
|
|
|
extern bool grabinput, minimized;
|
|
|
|
extern void pushevent(const SDL_Event &e);
|
|
extern bool interceptkey(int sym);
|
|
|
|
extern float loadprogress;
|
|
extern void renderbackground(const char *caption = NULL, Texture *mapshot = NULL, const char *mapname = NULL, const char *mapinfo = NULL, bool force = false);
|
|
extern void renderprogress(float bar, const char *text, bool background = false);
|
|
|
|
extern void getframemillis(float &avg, float &best, float &worst);
|
|
extern void getfps(int &fps, int &bestdiff, int &worstdiff);
|
|
extern void swapbuffers(bool overlay = true);
|
|
extern int getclockmillis();
|
|
|
|
enum { KR_CONSOLE = 1<<0, KR_GUI = 1<<1, KR_EDITMODE = 1<<2 };
|
|
|
|
extern void keyrepeat(bool on, int mask = ~0);
|
|
|
|
enum { TI_CONSOLE = 1<<0, TI_GUI = 1<<1 };
|
|
|
|
extern void textinput(bool on, int mask = ~0);
|
|
|
|
// physics
|
|
extern void mousemove(int dx, int dy);
|
|
extern bool overlapsdynent(const vec &o, float radius);
|
|
extern void rotatebb(vec ¢er, 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 float transmdlsx1, transmdlsy1, transmdlsx2, transmdlsy2;
|
|
extern uint transmdltiles[LIGHTTILE_MAXH];
|
|
|
|
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
|
|
|