Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Enumerations | Functions | Variables
pvs.cpp File Reference
#include <limits.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "SDL_keycode.h"
#include "SDL_mutex.h"
#include "SDL_stdinc.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "inexor/engine/material.hpp"
#include "inexor/engine/octarender.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/pvs.hpp"
#include "inexor/engine/renderbackground.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/io/input/InputRouter.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/network/legacy/buffer_types.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_hash.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_queue.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/cube_vector.hpp"
#include "inexor/shared/ents.hpp"
#include "inexor/shared/tools.hpp"

Classes

struct  pvsnode
 
struct  shaftplane
 
struct  shaftbb
 
struct  shaft
 
struct  pvsdata
 
struct  viewcellrequest
 
struct  pvsworker
 
struct  pvsworker::cullorder
 
struct  viewcellnode
 
union  viewcellnode::viewcellchild
 
union  shaftbb.__unnamed__
 
struct  shaftbb.__unnamed__.__unnamed__
 

Macros

#define MERGEBBS(res, coord, row, col)
 
#define MAXWATERPVS   32
 

Enumerations

enum  { PVS_HIDE_GEOM = 1<<0, PVS_HIDE_BB = 1<<1 }
 

Functions

static bool mergepvsnodes (pvsnode &p, pvsnode *children)
 
static void genpvsnodes (cube *c, int parent=0, const ivec &co=ivec(0, 0, 0), int size=worldsize/2)
 
static uint hthash (const pvsdata &k)
 
static bool htcmp (const pvsdata &x, const pvsdata &y)
 
 VAR (maxpvsblocker, 1, 512, 1<< 16)
 
 VAR (pvsleafsize, 1, 64, 1024)
 
 VARP (pvsthreads, 0, 0, 16)
 
static Uint32 genpvs_timer (Uint32 interval, void *param)
 
static void show_genpvs_progress (int unique=pvs.length(), int processed=numviewcells)
 
static void calcpvsbounds ()
 
static bool isallclip (cube *c)
 
static int countviewcells (cube *c, const ivec &co, int size, int threshold)
 
static void genviewcells (viewcellnode &p, cube *c, const ivec &co, int size, int threshold)
 
static pvsdatalookupviewcell (const vec &p)
 
static void lockpvs_ (bool lock)
 
 VARF (lockpvs, 0, 0, 1, lockpvs_(lockpvs!=0))
 
 VARN (pvs, usepvs, 0, 1, 1)
 
 VARN (waterpvs, usewaterpvs, 0, 1, 1)
 
void setviewcell (const vec &p)
 
void clearpvs ()
 
 COMMAND (clearpvs,"")
 
static void findwaterplanes ()
 
void testpvs (int *vcsize)
 
 COMMAND (testpvs,"i")
 
void genpvs (int *viewcellsize)
 
 COMMAND (genpvs,"i")
 
void pvsstats ()
 
 COMMAND (pvsstats,"")
 
static bool pvsoccluded (uchar *buf, const ivec &co, int size, const ivec &bbmin, const ivec &bbmax)
 
static bool pvsoccluded (uchar *buf, const ivec &bbmin, const ivec &bbmax)
 
bool pvsoccluded (const ivec &bbmin, const ivec &bbmax)
 
bool pvsoccludedsphere (const vec &center, float radius)
 
bool waterpvsoccluded (int height)
 
void saveviewcells (stream *f, viewcellnode &p)
 
void savepvs (stream *f)
 
viewcellnodeloadviewcells (stream *f)
 
void loadpvs (stream *f, int numpvs)
 
int getnumviewcells ()
 

Variables

static vector< pvsnodeorigpvsnodes
 
static vector< ucharpvsbuf
 
static SDL_mutex * pvsmutex = nullptr
 
static hashtable< pvsdata, int > pvscompress
 
static vector< pvsdatapvs
 
static SDL_mutex * viewcellmutex = nullptr
 
static vector< viewcellrequestviewcellrequests
 
static bool genpvs_canceled = false
 
static int numviewcells = 0
 
struct {
int height
 
vector< materialsurface * > matsurfs
 
waterplanes [MAXWATERPVS]
 
static vector< materialsurface * > waterfalls
 
uint numwaterplanes = 0
 
static vector< pvsworker * > pvsworkers
 
static volatile bool check_genpvs_progress = false
 
static int totalviewcells = 0
 
static shaftbb pvsbounds
 
static viewcellnodeviewcells = nullptr
 
static int lockedwaterplanes [MAXWATERPVS]
 
static ucharcurpvs = nullptr
 
static ucharlockedpvs = nullptr
 
static int curwaterpvs = 0
 
static int lockedwaterpvs = 0
 

Class Documentation

struct pvsnode
Class Members
uint children
bvec edges
uchar flags
struct shaftplane
Class Members
float c
uchar cfar
uchar cnear
float offset
float r
uchar rfar
uchar rnear
struct viewcellrequest
Class Members
ivec o
int * result
int size
union viewcellnode::viewcellchild
Class Members
viewcellnode * node
int pvs
union shaftbb.__unnamed__
Class Members
__unnamed__ __unnamed__
ushort v[6]
struct shaftbb.__unnamed__.__unnamed__
Class Members
usvec max
usvec min

Macro Definition Documentation

#define MAXWATERPVS   32
#define MERGEBBS (   res,
  coord,
  row,
  col 
)
Value:
if(lo.coord==0xFF) \
{ \
if(hi.coord!=0xFF) \
{ \
res.coord = ((hi.coord&~0x11)>>1) + 0x44; \
res.row = hi.row; \
res.col = hi.col; \
} \
} \
else if(hi.coord==0xFF) \
{ \
res.coord = (lo.coord&0xEE)>>1; \
res.row = lo.row; \
res.col = lo.col; \
} \
else if(lo.row!=hi.row || lo.col!=hi.col || (lo.coord&0xF0)!=0x80 || (hi.coord&0xF)!=0) return false; \
else \
{ \
res.coord = ((lo.coord&~0xF1)>>1) | (((hi.coord&~0x1F)>>1) + 0x40); \
res.row = lo.row; \
res.col = lo.col; \
}
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2

Referenced by mergepvsnodes().

Enumeration Type Documentation

anonymous enum
Enumerator
PVS_HIDE_GEOM 
PVS_HIDE_BB 

Function Documentation

static void calcpvsbounds ( )
static
void clearpvs ( )
COMMAND ( clearpvs  ,
""   
)
COMMAND ( testpvs  ,
"i"   
)
COMMAND ( genpvs  ,
"i"   
)
COMMAND ( pvsstats  ,
""   
)
static int countviewcells ( cube c,
const ivec co,
int  size,
int  threshold 
)
static
static void findwaterplanes ( )
static
void genpvs ( int *  viewcellsize)
static Uint32 genpvs_timer ( Uint32  interval,
void param 
)
static

References check_genpvs_progress.

Referenced by genpvs().

static void genpvsnodes ( cube c,
int  parent = 0,
const ivec co = ivec(0, 0, 0),
int  size = worldsize/2 
)
static
static void genviewcells ( viewcellnode p,
cube c,
const ivec co,
int  size,
int  threshold 
)
static
int getnumviewcells ( )

References pvs.

Referenced by gl_drawhud(), and save_world().

static bool htcmp ( const pvsdata x,
const pvsdata y 
)
inlinestatic

References pvsdata::len, pvsdata::offset, and pvsbuf.

static uint hthash ( const pvsdata k)
inlinestatic
static bool isallclip ( cube c)
inlinestatic
void loadpvs ( stream f,
int  numpvs 
)
viewcellnode* loadviewcells ( stream f)
static void lockpvs_ ( bool  lock)
static
static pvsdata* lookupviewcell ( const vec p)
inlinestatic
static bool mergepvsnodes ( pvsnode p,
pvsnode children 
)
static

References pvsnode::edges, hmap::flags, loop, loopi(), MERGEBBS, and octaindex.

Referenced by genpvsnodes().

static bool pvsoccluded ( uchar buf,
const ivec co,
int  size,
const ivec bbmin,
const ivec bbmax 
)
inlinestatic
static bool pvsoccluded ( uchar buf,
const ivec bbmin,
const ivec bbmax 
)
inlinestatic
bool pvsoccluded ( const ivec bbmin,
const ivec bbmax 
)

References curpvs, and pvsoccluded().

Referenced by pvsoccluded().

bool pvsoccludedsphere ( const vec center,
float  radius 
)

References curpvs, and pvsoccluded().

Referenced by finddynlights().

void pvsstats ( )
void savepvs ( stream f)
void saveviewcells ( stream f,
viewcellnode p 
)
void setviewcell ( const vec p)
static void show_genpvs_progress ( int  unique = pvs.length(),
int  processed = numviewcells 
)
static
void testpvs ( int *  vcsize)
VAR ( maxpvsblocker  ,
,
512  ,
1<<  16 
)
VAR ( pvsleafsize  ,
,
64  ,
1024   
)
VARF ( lockpvs  ,
,
,
,
lockpvs_(lockpvs!=0)   
)
VARN ( pvs  ,
usepvs  ,
,
,
 
)
VARN ( waterpvs  ,
usewaterpvs  ,
,
,
 
)
VARP ( pvsthreads  ,
,
,
16   
)
bool waterpvsoccluded ( int  height)

Variable Documentation

volatile bool check_genpvs_progress = false
static
uchar* curpvs = nullptr
static
int curwaterpvs = 0
static

Referenced by setviewcell(), and waterpvsoccluded().

bool genpvs_canceled = false
static
uchar * lockedpvs = nullptr
static
int lockedwaterplanes[MAXWATERPVS]
static

Referenced by lockpvs_(), testpvs(), and waterpvsoccluded().

int lockedwaterpvs = 0
static

Referenced by lockpvs_(), setviewcell(), and testpvs().

int numviewcells = 0
static

Referenced by genpvs(), and pvsworker::genviewcell().

uint numwaterplanes = 0
vector<pvsnode> origpvsnodes
static
vector<pvsdata> pvs
static
shaftbb pvsbounds
static
vector<uchar> pvsbuf
static
hashtable<pvsdata, int> pvscompress
static

Referenced by genpvs(), and pvsworker::genviewcell().

SDL_mutex* pvsmutex = nullptr
static

Referenced by genpvs(), and pvsworker::genviewcell().

vector<pvsworker *> pvsworkers
static

Referenced by genpvs(), and genviewcells().

int totalviewcells = 0
static

Referenced by genpvs(), and show_genpvs_progress().

SDL_mutex* viewcellmutex = nullptr
static

Referenced by genpvs(), and pvsworker::run().

vector<viewcellrequest> viewcellrequests
static
viewcellnode* viewcells = nullptr
static
vector<materialsurface *> waterfalls
static
struct { ... } waterplanes[MAXWATERPVS]