]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - client.h
make CSQC support the >0.05s/<0.0005s handling of standard player physics so CSQC...
[xonotic/darkplaces.git] / client.h
index fc13bae0bb767e983f8aefd698f3c7060eb36668..45964700ce7532b71f18522874ebc86ddebe44b2 100644 (file)
--- a/client.h
+++ b/client.h
@@ -25,16 +25,44 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "matrixlib.h"
 #include "snd_main.h"
 
-// LordHavoc: 256 dynamic lights
-#define MAX_DLIGHTS 256
-
-/// this is the maximum number of input packets that can be predicted
-#define CL_MAX_USERCMDS 256
-
 // flags for rtlight rendering
 #define LIGHTFLAG_NORMALMODE 1
 #define LIGHTFLAG_REALTIMEMODE 2
 
+typedef struct tridecal_s
+{
+       // color and initial alpha value
+       float                   texcoord2f[3][2];
+       float                   vertex3f[3][3];
+       float                   color4f[3][4];
+       float                   plane[4]; // backface culling
+       // how long this decal has lived so far (the actual fade begins at cl_decals_time)
+       float                   lived;
+       // if >= 0 this indicates the decal should follow an animated triangle
+       int                             triangleindex;
+       // for visibility culling
+       int                             surfaceindex;
+       // old decals are killed to obey cl_decals_max
+       int                             decalsequence;
+}
+tridecal_t;
+
+typedef struct decalsystem_s
+{
+       dp_model_t *model;
+       double lastupdatetime;
+       int maxdecals;
+       int freedecal;
+       int numdecals;
+       tridecal_t *decals;
+       float *vertex3f;
+       float *texcoord2f;
+       float *color4f;
+       int *element3i;
+       unsigned short *element3s;
+}
+decalsystem_t;
+
 typedef struct effect_s
 {
        int active;
@@ -62,6 +90,13 @@ typedef struct beam_s
 }
 beam_t;
 
+typedef struct rtlight_particle_s
+{
+       float origin[3];
+       float color[3];
+}
+rtlight_particle_t;
+
 typedef struct rtlight_s
 {
        // shadow volumes are done entirely in model space, so there are no matrices for dealing with them...  they just use the origin
@@ -114,17 +149,43 @@ typedef struct rtlight_s
        float corona_visibility;
        unsigned int corona_queryindex_visiblepixels;
        unsigned int corona_queryindex_allpixels;
-       /// this is R_Shadow_Cubemap(rtlight->cubemapname)
+       /// this is R_GetCubemap(rtlight->cubemapname)
        rtexture_t *currentcubemap;
+       /// set by R_Shadow_PrepareLight to decide whether R_Shadow_DrawLight should draw it
+       qboolean draw;
+       /// these fields are set by R_Shadow_PrepareLight for later drawing
+       int cached_numlightentities;
+       int cached_numlightentities_noselfshadow;
+       int cached_numshadowentities;
+       int cached_numshadowentities_noselfshadow;
+       int cached_numsurfaces;
+       struct entity_render_s **cached_lightentities;
+       struct entity_render_s **cached_lightentities_noselfshadow;
+       struct entity_render_s **cached_shadowentities;
+       struct entity_render_s **cached_shadowentities_noselfshadow;
+       unsigned char *cached_shadowtrispvs;
+       unsigned char *cached_lighttrispvs;
+       int *cached_surfacelist;
+       // reduced light cullbox from GetLightInfo
+       vec3_t cached_cullmins;
+       vec3_t cached_cullmaxs;
+       // current shadow-caster culling planes based on view
+       // (any geometry outside these planes can not contribute to the visible
+       //  shadows in any way, and thus can be culled safely)
+       int cached_numfrustumplanes;
+       mplane_t cached_frustumplanes[5]; // see R_Shadow_ComputeShadowCasterCullingPlanes
 
        /// static light info
        /// true if this light should be compiled as a static light
        int isstatic;
        /// true if this is a compiled world light, cleared if the light changes
        int compiled;
+       /// the shadowing mode used to compile this light
+       int shadowmode;
        /// premade shadow volumes to render for world entity
        shadowmesh_t *static_meshchain_shadow_zpass;
        shadowmesh_t *static_meshchain_shadow_zfail;
+       shadowmesh_t *static_meshchain_shadow_shadowmap;
        /// used for visibility testing (more exact than bbox)
        int static_numleafs;
        int static_numleafpvsbytes;
@@ -146,6 +207,18 @@ typedef struct rtlight_s
        /// (important on big surfaces such as terrain)
        int static_numlighttrispvsbytes;
        unsigned char *static_lighttrispvs;
+       /// masks of all shadowmap sides that have any potential static receivers or casters
+       int static_shadowmap_receivers;
+       int static_shadowmap_casters;
+       /// particle-tracing cache for global illumination
+       int particlecache_numparticles;
+       int particlecache_maxparticles;
+       int particlecache_updateparticle;
+       rtlight_particle_t *particlecache_particles;
+
+       /// bouncegrid light info
+       float photoncolor[3];
+       float photons;
 }
 rtlight_t;
 
@@ -222,23 +295,11 @@ typedef struct dlight_s
 }
 dlight_t;
 
-#define MAX_FRAMEGROUPBLENDS 4
-typedef struct framegroupblend_s
-{
-       // animation number and blend factor
-       // (for most models this is the frame number)
-       int frame;
-       float lerp;
-       // time frame began playing (for framegroup animations)
-       double start;
-}
-framegroupblend_t;
-
 // this is derived from processing of the framegroupblend array
 // note: technically each framegroupblend can produce two of these, but that
 // never happens in practice because no one blends between more than 2
 // framegroups at once
-#define MAX_FRAMEBLENDS MAX_FRAMEGROUPBLENDS
+#define MAX_FRAMEBLENDS (MAX_FRAMEGROUPBLENDS * 2)
 typedef struct frameblend_s
 {
        int subframe;
@@ -268,6 +329,8 @@ typedef struct entity_render_s
        float alpha;
        // size the model is shown
        float scale;
+       // transparent sorting offset
+       float transparent_offset;
 
        // NULL = no model
        dp_model_t *model;
@@ -287,6 +350,7 @@ typedef struct entity_render_s
 
        // colormod tinting of models
        float colormod[3];
+       float glowmod[3];
 
        // interpolated animation - active framegroups and blend factors
        framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
@@ -300,18 +364,36 @@ typedef struct entity_render_s
        vec3_t mins, maxs;
        // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
        frameblend_t frameblend[MAX_FRAMEBLENDS];
-
-       // animation cache index
-       int animcacheindex;
+       // skeletal animation data (if skeleton.relativetransforms is not NULL, it overrides frameblend)
+       skeleton_t *skeleton;
+
+       // animation cache (pointers allocated using R_FrameData_Alloc)
+       // ONLY valid during R_RenderView!  may be NULL (not cached)
+       float *animcache_vertex3f;
+       float *animcache_normal3f;
+       float *animcache_svector3f;
+       float *animcache_tvector3f;
+       // interleaved arrays for rendering and dynamic vertex buffers for them
+       r_meshbuffer_t *animcache_vertex3fbuffer;
+       r_vertexmesh_t *animcache_vertexmesh;
+       r_meshbuffer_t *animcache_vertexmeshbuffer;
 
        // current lighting from map (updated ONLY by client code, not renderer)
        vec3_t modellight_ambient;
        vec3_t modellight_diffuse; // q3bsp
        vec3_t modellight_lightdir; // q3bsp
 
+       // storage of decals on this entity
+       // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
+       int allowdecals;
+       decalsystem_t decalsystem;
+
        // FIELDS UPDATED BY RENDERER:
        // last time visible during trace culling
        double last_trace_visibility;
+
+       // user wavefunc parameters (from csqc)
+       float userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
 }
 entity_render_t;
 
@@ -408,6 +490,7 @@ typedef struct scoreboard_s
        float   qw_entertime;
        int             qw_ping;
        int             qw_packetloss;
+       int             qw_movementloss;
        int             qw_spectator;
        char    qw_team[8];
        char    qw_skin[MAX_QPATH];
@@ -436,9 +519,6 @@ typedef struct cshift_s
 
 #define        SIGNONS         4                       // signon messages to receive before connected
 
-#define        MAX_DEMOS               8
-#define        MAX_DEMONAME    16
-
 typedef enum cactive_e
 {
        ca_uninitialized,       // during early startup
@@ -461,7 +541,7 @@ qw_downloadtype_t;
 typedef enum capturevideoformat_e
 {
        CAPTUREVIDEOFORMAT_AVI_I420,
-       CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA,
+       CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA
 }
 capturevideoformat_t;
 
@@ -500,7 +580,7 @@ typedef struct capturevideostate_s
        const char *formatextension;
        qfile_t *videofile;
                // always use this:
-               //   cls.capturevideo.videofile = FS_OpenRealFile(va("%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
+               //   cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
        void (*endvideo) (void);
        void (*videoframes) (int num);
        void (*soundframe) (const portable_sampleframe_t *paintbuffer, size_t length);
@@ -552,6 +632,7 @@ typedef struct client_static_s
        fs_offset_t demo_lastcsprogssize;
        int demo_lastcsprogscrc;
        qboolean demoplayback;
+       qboolean demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
        qboolean timedemo;
        // -1 = use normal cd track
        int forcetrack;
@@ -581,6 +662,13 @@ typedef struct client_static_s
        // (kept outside client_state_t because it's used between levels)
        protocolversion_t protocol;
 
+#define MAX_RCONS 16
+       int rcon_trying;
+       lhnetaddress_t rcon_addresses[MAX_RCONS];
+       char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
+       double rcon_timeout[MAX_RCONS];
+       int rcon_ringpos;
+
 // connection information
        // 0 to SIGNONS
        int signon;
@@ -627,8 +715,19 @@ typedef struct client_static_s
        // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
        char userinfo[MAX_USERINFO_STRING];
 
+       // extra user info for the "connect" command
+       char connect_userinfo[MAX_USERINFO_STRING];
+
        // video capture stuff
        capturevideostate_t capturevideo;
+
+       // crypto channel
+       crypto_t crypto;
+
+       // ProQuake compatibility stuff
+       int proquake_servermod; // 0 = not proquake, 1 = proquake
+       int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
+       int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
 }
 client_static_t;
 
@@ -683,7 +782,7 @@ typedef struct particletype_s
 }
 particletype_t;
 
-typedef enum
+typedef enum ptype_e
 {
        pt_dead, pt_alphastatic, pt_static, pt_spark, pt_beam, pt_rain, pt_raindecal, pt_snow, pt_bubble, pt_blood, pt_smoke, pt_decal, pt_entityparticle, pt_total
 }
@@ -694,6 +793,7 @@ typedef struct decal_s
        // fields used by rendering:  (44 bytes)
        unsigned short  typeindex;
        unsigned short  texnum;
+       int                             decalsequence;
        vec3_t                  org;
        vec3_t                  normal;
        float                   size;
@@ -713,33 +813,43 @@ decal_t;
 
 typedef struct particle_s
 {
-       // fields used by rendering: (40 bytes)
+       // for faster batch rendering, particles are rendered in groups by effect (resulting in less perfect sorting but far less state changes)
+
+       // fields used by rendering: (48 bytes)
+       vec3_t          sortorigin; // sort by this group origin, not particle org
+       vec3_t          org;
+       vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
+       float           size;
+       float           alpha; // 0-255
+       float           stretch; // only for sparks
+
+       // fields not used by rendering:  (44 bytes)
+       float           stainsize;
+       float           stainalpha;
+       float           sizeincrease; // rate of size change per second
+       float           alphafade; // how much alpha reduces per second
+       float           time2; // used for snow fluttering and decal fade
+       float           bounce; // how much bounce-back from a surface the particle hits (0 = no physics, 1 = stop and slide, 2 = keep bouncing forever, 1.5 is typical)
+       float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
+       float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
+       float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
+//     float           delayedcollisions; // time that p->bounce becomes active
+       float           delayedspawn; // time that particle appears and begins moving
+       float           die; // time when this particle should be removed, regardless of alpha
+
+       // short variables grouped to save memory (4 bytes)
+       short                   angle; // base rotation of particle
+       short                   spin; // geometry rotation speed around the particle center normal
+
+       // byte variables grouped to save memory (12 bytes)
+       unsigned char   color[3];
+       unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
        unsigned char   typeindex;
-       pblend_t   blendmode;
-       porientation_t   orientation;
+       unsigned char   blendmode;
+       unsigned char   orientation;
        unsigned char   texnum;
-       vec3_t                  org;
-       vec3_t                  vel; // velocity of particle, or orientation of decal, or end point of beam
-       float                   size;
-       float                   alpha; // 0-255
-       unsigned char   color[3];
-       unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
-       float           stretch; // only for sparks
-       int             staincolor;
+       unsigned char   staincolor[3];
        signed char     staintexnum;
-       float           stainsizefactor;
-
-       // fields not used by rendering:  (40 bytes)
-       float                   sizeincrease; // rate of size change per second
-       float                   alphafade; // how much alpha reduces per second
-       float                   time2; // used for snow fluttering and decal fade
-       float                   bounce; // how much bounce-back from a surface the particle hits (0 = no physics, 1 = stop and slide, 2 = keep bouncing forever, 1.5 is typical)
-       float                   gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
-       float                   airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
-       float                   liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
-       float                   delayedcollisions; // time that p->bounce becomes active
-       float                   delayedspawn; // time that particle appears and begins moving
-       float                   die; // time when this particle should be removed, regardless of alpha
 }
 particle_t;
 
@@ -846,6 +956,17 @@ typedef struct client_state_s
        // whether the replay should allow a jump at the first sequence
        qboolean movement_replay_canjump;
 
+       // previous gun angles (for leaning effects)
+       vec3_t gunangles_prev;
+       vec3_t gunangles_highpass;
+       vec3_t gunangles_adjustment_lowpass;
+       vec3_t gunangles_adjustment_highpass;
+       // previous gun angles (for leaning effects)
+       vec3_t gunorg_prev;
+       vec3_t gunorg_highpass;
+       vec3_t gunorg_adjustment_lowpass;
+       vec3_t gunorg_adjustment_highpass;
+
 // pitch drifting vars
        float idealpitch;
        float pitchvel;
@@ -857,6 +978,7 @@ typedef struct client_state_s
        float sensitivityscale;
        csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
        qboolean csqc_wantsmousemove;
+       qboolean csqc_paused; // vortex: int because could be flags
        struct model_s *csqc_model_precache[MAX_MODELS];
 
        // local amount for smoothing stepups
@@ -871,6 +993,9 @@ typedef struct client_state_s
        qboolean oldonground;
        double lastongroundtime;
        double hitgroundtime;
+       float bob2_smooth;
+       float bobfall_speed;
+       float bobfall_swing;
 
        // don't change view angle, full screen, etc
        int intermission;
@@ -908,7 +1033,11 @@ typedef struct client_state_s
        char sound_name[MAX_SOUNDS][MAX_QPATH];
 
        // for display on solo scoreboard
-       char levelname[40];
+       char worldmessage[40]; // map title (not related to filename)
+       // variants of map name
+       char worldbasename[MAX_QPATH]; // %s
+       char worldname[MAX_QPATH]; // maps/%s.bsp
+       char worldnamenoextension[MAX_QPATH]; // maps/%s
        // cl_entitites[cl.viewentity] = player
        int viewentity;
        // the real player entity (normally same as viewentity,
@@ -967,8 +1096,10 @@ typedef struct client_state_s
 
        // entity database stuff
        // latest received entity frame numbers
-#define LATESTFRAMENUMS 3
+#define LATESTFRAMENUMS 32
+       int latestframenumsposition;
        int latestframenums[LATESTFRAMENUMS];
+       int latestsendnums[LATESTFRAMENUMS];
        entityframe_database_t *entitydatabase;
        entityframe4_database_t *entitydatabase4;
        entityframeqw_database_t *entitydatabaseqw;
@@ -983,7 +1114,11 @@ typedef struct client_state_s
        vec3_t playercrouchmins;
        vec3_t playercrouchmaxs;
 
+       // old decals are killed based on this
+       int decalsequence;
+
        int max_entities;
+       int max_csqcrenderentities;
        int max_static_entities;
        int max_effects;
        int max_beams;
@@ -995,6 +1130,7 @@ typedef struct client_state_s
        int max_showlmps;
 
        entity_t *entities;
+       entity_render_t *csqcrenderentities;
        unsigned char *entities_active;
        entity_t *static_entities;
        cl_effect_t *effects;
@@ -1055,6 +1191,7 @@ typedef struct client_state_s
        double lastpackettime;
 
        // movement parameters for client prediction
+       unsigned int moveflags;
        float movevars_wallfriction;
        float movevars_waterfriction;
        float movevars_friction;
@@ -1072,17 +1209,22 @@ typedef struct client_state_s
        float movevars_maxairspeed;
        float movevars_stepheight;
        float movevars_airaccel_qw;
+       float movevars_airaccel_qw_stretchfactor;
        float movevars_airaccel_sideways_friction;
        float movevars_airstopaccelerate;
        float movevars_airstrafeaccelerate;
        float movevars_maxairstrafespeed;
+       float movevars_airstrafeaccel_qw;
        float movevars_aircontrol;
+       float movevars_aircontrol_power;
+       float movevars_aircontrol_penalty;
        float movevars_warsowbunny_airforwardaccel;
        float movevars_warsowbunny_accel;
        float movevars_warsowbunny_topspeed;
        float movevars_warsowbunny_turnaccel;
        float movevars_warsowbunny_backtosideratio;
        float movevars_ticrate;
+       float movevars_airspeedlimit_nonqw;
 
        // models used by qw protocol
        int qw_modelindex_spike;
@@ -1107,8 +1249,11 @@ typedef struct client_state_s
        // server entity number corresponding to a clientside entity
        unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
        qboolean csqc_loaded;
-       vec3_t csqc_origin;
-       vec3_t csqc_angles;
+       vec3_t csqc_vieworigin;
+       vec3_t csqc_viewangles;
+       vec3_t csqc_vieworiginfromengine;
+       vec3_t csqc_viewanglesfromengine;
+       matrix4x4_t csqc_viewmodelmatrixfromengine;
        qboolean csqc_usecsqclistener;
        matrix4x4_t csqc_listenermatrix;
        char csqc_printtextbuf[MAX_INPUTLINE];
@@ -1126,6 +1271,9 @@ typedef struct client_state_s
        // freed on each level change
        size_t buildlightmapmemorysize;
        unsigned char *buildlightmapmemory;
+
+       // used by EntityState5_ReadUpdate
+       skeleton_t *engineskeletonobjects;
 }
 client_state_t;
 
@@ -1176,6 +1324,7 @@ extern cvar_t m_side;
 
 extern cvar_t cl_autodemo;
 extern cvar_t cl_autodemo_nameformat;
+extern cvar_t cl_autodemo_delete;
 
 extern cvar_t r_draweffects;
 
@@ -1188,6 +1337,7 @@ extern cvar_t cl_stainmaps;
 extern cvar_t cl_stainmaps_clearonload;
 
 extern cvar_t cl_prydoncursor;
+extern cvar_t cl_prydoncursor_notrace;
 
 extern cvar_t cl_locs_enable;
 
@@ -1207,7 +1357,7 @@ void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
 void CL_Shutdown (void);
 void CL_Init (void);
 
-void CL_EstablishConnection(const char *host);
+void CL_EstablishConnection(const char *host, int firstarg);
 
 void CL_Disconnect (void);
 void CL_Disconnect_f (void);
@@ -1249,6 +1399,7 @@ void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float
 
 void CL_ClearState (void);
 void CL_ExpandEntities(int num);
+void CL_ExpandCSQCRenderEntities(int num);
 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
 
 
@@ -1259,7 +1410,7 @@ extern int cl_ignoremousemoves;
 
 
 float CL_KeyState (kbutton_t *key);
-const char *Key_KeynumToString (int keynum);
+const char *Key_KeynumToString (int keynum, char *buf, size_t buflength);
 int Key_StringToKeynum (const char *str);
 
 //
@@ -1311,6 +1462,9 @@ extern cvar_t cl_particles_size;
 extern cvar_t cl_particles_quake;
 extern cvar_t cl_particles_blood;
 extern cvar_t cl_particles_blood_alpha;
+extern cvar_t cl_particles_blood_decal_alpha;
+extern cvar_t cl_particles_blood_decal_scalemin;
+extern cvar_t cl_particles_blood_decal_scalemax;
 extern cvar_t cl_particles_blood_bloodhack;
 extern cvar_t cl_particles_bulletimpacts;
 extern cvar_t cl_particles_explosions_sparks;
@@ -1329,6 +1483,7 @@ extern cvar_t cl_decals_fadetime;
 void CL_Particles_Clear(void);
 void CL_Particles_Init(void);
 void CL_Particles_Shutdown(void);
+particle_t *CL_NewParticle(const vec3_t sortorigin, unsigned short ptypeindex, int pcolor1, int pcolor2, int ptex, float psize, float psizeincrease, float palpha, float palphafade, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float pairfriction, float pliquidfriction, float originjitter, float velocityjitter, qboolean pqualityreduction, float lifetime, float stretch, pblend_t blendmode, porientation_t orientation, int staincolor1, int staincolor2, int staintex, float stainalpha, float stainsize, float angle, float spin, float tint[4]);
 
 typedef enum effectnameindex_s
 {
@@ -1375,7 +1530,7 @@ effectnameindex_t;
 int CL_ParticleEffectIndexForName(const char *name);
 const char *CL_ParticleEffectNameForIndex(int i);
 void CL_ParticleEffect(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor);
-void CL_ParticleTrail(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor, qboolean spawndlight, qboolean spawnparticles);
+void CL_ParticleTrail(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor, qboolean spawndlight, qboolean spawnparticles, float tintmins[4], float tintmaxs[4]);
 void CL_ParseParticleEffect (void);
 void CL_ParticleCube (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, vec_t gravity, vec_t randomvel);
 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
@@ -1392,9 +1547,8 @@ void Debug_PolygonEnd(void);
 
 extern qboolean sb_showscores;
 
-float FogPoint_World(const vec3_t p);
-float FogPoint_Model(const vec3_t p);
-float FogForDistance(vec_t dist);
+float RSurf_FogVertex(const vec3_t p);
+float RSurf_FogPoint(const vec3_t p);
 
 typedef struct r_refdef_stats_s
 {
@@ -1409,21 +1563,64 @@ typedef struct r_refdef_stats_s
        int lightmapupdates;
        int lightmapupdatepixels;
        int particles;
-       int decals;
-       int meshes;
-       int meshes_elements;
+       int drawndecals;
+       int totaldecals;
+       int draws;
+       int draws_vertices;
+       int draws_elements;
        int lights;
        int lights_clears;
        int lights_scissored;
        int lights_lighttriangles;
        int lights_shadowtriangles;
        int lights_dynamicshadowtriangles;
+       int bouncegrid_lights;
+       int bouncegrid_particles;
+       int bouncegrid_traces;
+       int bouncegrid_hits;
+       int bouncegrid_splats;
+       int bouncegrid_bounces;
+       int collisioncache_animated;
+       int collisioncache_cached;
+       int collisioncache_traced;
        int bloom;
        int bloom_copypixels;
        int bloom_drawpixels;
+       int indexbufferuploadcount;
+       int indexbufferuploadsize;
+       int vertexbufferuploadcount;
+       int vertexbufferuploadsize;
+       int framedatacurrent;
+       int framedatasize;
 }
 r_refdef_stats_t;
 
+typedef enum r_viewport_type_e
+{
+       R_VIEWPORTTYPE_ORTHO,
+       R_VIEWPORTTYPE_PERSPECTIVE,
+       R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP,
+       R_VIEWPORTTYPE_PERSPECTIVECUBESIDE,
+       R_VIEWPORTTYPE_TOTAL
+}
+r_viewport_type_t;
+
+typedef struct r_viewport_s
+{
+       matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
+       matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
+       matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
+       int x;
+       int y;
+       int z;
+       int width;
+       int height;
+       int depth;
+       r_viewport_type_t type;
+       float screentodepth[2]; // used by deferred renderer to calculate linear depth from device depth coordinates
+}
+r_viewport_t;
+
 typedef struct r_refdef_view_s
 {
        // view information (changes multiple times per frame)
@@ -1460,20 +1657,23 @@ typedef struct r_refdef_view_s
        int width;
        int height;
        int depth;
+       r_viewport_t viewport; // note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
 
        // which color components to allow (for anaglyph glasses)
        int colormask[4];
 
-       // global RGB color multiplier for rendering, this is required by HDR
+       // global RGB color multiplier for rendering
        float colorscale;
 
        // whether to call R_ClearScreen before rendering stuff
        qboolean clear;
        // if true, don't clear or do any post process effects (bloom, etc)
        qboolean isoverlay;
+       // if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor)
+       qboolean ismain;
 
        // whether to draw r_showtris and such, this is only true for the main
-       // view render, all secondary renders (HDR, mirrors, portals, cameras,
+       // view render, all secondary renders (mirrors, portals, cameras,
        // distortion effects, etc) omit such debugging information
        qboolean showdebug;
 
@@ -1488,19 +1688,24 @@ r_refdef_view_t;
 
 typedef struct r_refdef_viewcache_s
 {
+       // updated by gl_main_newmap()
+       int maxentities;
+       int world_numclusters;
+       int world_numclusterbytes;
+       int world_numleafs;
+       int world_numsurfaces;
+
        // these properties are generated by R_View_Update()
 
        // which entities are currently visible for this viewpoint
        // (the used range is 0...r_refdef.scene.numentities)
-       unsigned char entityvisible[MAX_EDICTS];
+       unsigned char *entityvisible;
+
        // flag arrays used for visibility checking on world model
        // (all other entities have no per-surface/per-leaf visibility checks)
-       // TODO: dynamic resize according to r_refdef.scene.worldmodel->brush.num_clusters
-       unsigned char world_pvsbits[(32768+7)>>3]; // FIXME: buffer overflow on huge maps
-       // TODO: dynamic resize according to r_refdef.scene.worldmodel->brush.num_leafs
-       unsigned char world_leafvisible[32768]; // FIXME: buffer overflow on huge maps
-       // TODO: dynamic resize according to r_refdef.scene.worldmodel->num_surfaces
-       unsigned char world_surfacevisible[262144]; // FIXME: buffer overflow on huge maps
+       unsigned char *world_pvsbits;
+       unsigned char *world_leafvisible;
+       unsigned char *world_surfacevisible;
        // if true, the view is currently in a leaf without pvs data
        qboolean world_novis;
 }
@@ -1530,6 +1735,7 @@ typedef struct r_refdef_scene_s {
        entity_render_t *tempentities;
        int numtempentities;
        int maxtempentities;
+       qboolean expandtempentities;
 
        // renderable dynamic lights
        rtlight_t *lights[MAX_DLIGHTS];
@@ -1537,10 +1743,10 @@ typedef struct r_refdef_scene_s {
        int numlights;
 
        // intensities for light styles right now, controls rtlights
-       float rtlightstylevalue[256];   // float fraction of base light value
+       float rtlightstylevalue[MAX_LIGHTSTYLES];       // float fraction of base light value
        // 8.8bit fixed point intensities for light styles
        // controls intensity lightmap layers
-       unsigned short lightstylevalue[256];    // 8.8 fraction of base light value
+       unsigned short lightstylevalue[MAX_LIGHTSTYLES];        // 8.8 fraction of base light value
 
        float ambient;
 
@@ -1575,10 +1781,14 @@ typedef struct r_refdef_s
 
        r_refdef_scene_t scene;
 
-       vec3_t fogcolor;
-       vec_t fogrange;
-       vec_t fograngerecip;
-       vec_t fogmasktabledistmultiplier;
+       float fogplane[4];
+       float fogplaneviewdist;
+       qboolean fogplaneviewabove;
+       float fogheightfade;
+       float fogcolor[3];
+       float fogrange;
+       float fograngerecip;
+       float fogmasktabledistmultiplier;
 #define FOGMASKTABLEWIDTH 1024
        float fogmasktable[FOGMASKTABLEWIDTH];
        float fogmasktable_start, fogmasktable_alpha, fogmasktable_range, fogmasktable_density;
@@ -1589,10 +1799,21 @@ typedef struct r_refdef_s
        float fog_alpha;
        float fog_start;
        float fog_end;
+       float fog_height;
+       float fog_fadedepth;
        qboolean fogenabled;
        qboolean oldgl_fogenable;
 
-       qboolean draw2dstage;
+       // new flexible texture height fog (overrides normal fog)
+       char fog_height_texturename[64]; // note: must be 64 for the sscanf code
+       unsigned char *fog_height_table1d;
+       unsigned char *fog_height_table2d;
+       int fog_height_tablesize; // enable
+       float fog_height_tablescale;
+       float fog_height_texcoordscale;
+       char fogheighttexturename[64]; // detects changes to active fog height texture
+
+       int draw2dstage; // 0 = no, 1 = yes, other value = needs setting up again
 
        // true during envmap command capture
        qboolean envmap;
@@ -1606,6 +1827,9 @@ typedef struct r_refdef_s
        float shadowpolygonfactor;
        float shadowpolygonoffset;
 
+       // how long R_RenderView took on the previous frame
+       double lastdrawscreentime;
+
        // rendering stats for r_speeds display
        // (these are incremented in many places)
        r_refdef_stats_t stats;
@@ -1614,5 +1838,60 @@ r_refdef_t;
 
 extern r_refdef_t r_refdef;
 
+typedef enum waterlevel_e
+{
+       WATERLEVEL_NONE,
+       WATERLEVEL_WETFEET,
+       WATERLEVEL_SWIMMING,
+       WATERLEVEL_SUBMERGED
+}
+waterlevel_t;
+
+typedef struct cl_clientmovement_state_s
+{
+       // position
+       vec3_t origin;
+       vec3_t velocity;
+       // current bounding box (different if crouched vs standing)
+       vec3_t mins;
+       vec3_t maxs;
+       // currently on the ground
+       qboolean onground;
+       // currently crouching
+       qboolean crouched;
+       // what kind of water (SUPERCONTENTS_LAVA for instance)
+       int watertype;
+       // how deep
+       waterlevel_t waterlevel;
+       // weird hacks when jumping out of water
+       // (this is in seconds and counts down to 0)
+       float waterjumptime;
+
+       // user command
+       usercmd_t cmd;
+}
+cl_clientmovement_state_t;
+void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
+
+// warpzone prediction hack (CSQC builtin)
+void CL_RotateMoves(const matrix4x4_t *m);
+
+void CL_NewFrameReceived(int num);
+void CL_ParseEntityLump(char *entitystring);
+void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
+void CL_RelinkLightFlashes(void);
+void Sbar_ShowFPS(void);
+void Sbar_ShowFPS_Update(void);
+void Host_SaveConfig(void);
+void Host_LoadConfig_f(void);
+void CL_UpdateMoveVars(void);
+void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
+void V_DriftPitch(void);
+void V_FadeViewFlashs(void);
+void V_CalcViewBlend(void);
+void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump, float clstatsviewheight);
+void V_CalcRefdef(void);
+void CL_Locs_Reload_f(void);
+
 #endif