Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Enumerations | Functions | Variables
world.cpp File Reference
#include <boost/algorithm/clamp.hpp>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "SDL_opengl.h"
#include "inexor/client/network.hpp"
#include "inexor/engine/blend.hpp"
#include "inexor/engine/decal.hpp"
#include "inexor/engine/glemu.hpp"
#include "inexor/engine/lightmap.hpp"
#include "inexor/engine/octa.hpp"
#include "inexor/engine/octaedit.hpp"
#include "inexor/engine/octarender.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/pvs.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/renderparticles.hpp"
#include "inexor/engine/water.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/engine/worldio.hpp"
#include "inexor/fpsgame/client.hpp"
#include "inexor/fpsgame/entities.hpp"
#include "inexor/fpsgame/fps.hpp"
#include "inexor/fpsgame/player.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/model/model.hpp"
#include "inexor/model/rendermodel.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/physics/physics.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_loops.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/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/sound/sound.hpp"
#include "inexor/texture/slot.hpp"
#include "inexor/ui/legacy/menus.hpp"

Macros

#define addimplicit(f)   { if(entgroup.empty() && enthover>=0) { entadd(enthover); undonext = (enthover != oldhover); f; entgroup.drop(); } else f; }
 
#define entfocusv(i, f, v)   { int n = efocus = (i); if(n>=0) { extentity &e = *v[n]; f; } }
 
#define entfocus(i, f)   entfocusv(i, f, entities::getents())
 
#define enteditv(i, f, v)
 
#define entedit(i, f)   enteditv(i, f, entities::getents())
 
#define addgroup(exp)   { vector<extentity *> &ents = entities::getents(); loopv(ents) entfocusv(i, if(exp) entadd(n), ents); }
 
#define setgroup(exp)   { entcancel(); addgroup(exp); }
 
#define groupeditloop(f)   { vector<extentity *> &ents = entities::getents(); entlooplevel++; int _ = efocus; loopv(entgroup) enteditv(entgroup[i], f, ents); efocus = _; entlooplevel--; }
 
#define groupeditpure(f)   { if(entlooplevel>0) { entedit(efocus, f); } else groupeditloop(f); }
 
#define groupeditundo(f)   { makeundoent(); groupeditpure(f); }
 
#define groupedit(f)   { addimplicit(groupeditundo(f)); }
 

Enumerations

enum  { MODOE_ADD = 1<<0, MODOE_UPDATEBB = 1<<1, MODOE_LIGHTENT = 1<<2 }
 

Functions

 VARR (mapversion, 1, MAPVERSION, 0)
 
 VARNR (mapscale, worldscale, 1, 0, 0)
 
 VARNR (mapsize, worldsize, 1, 0, 0)
 
 SVARR (maptitle,"Untitled Map by Unknown")
 
 VAR (octaentsize, 0, 64, 1024)
 
 VAR (entselradius, 0, 2, 10)
 
 VARF (entediting, 0, 0, 1,{if(!entediting){entcancel();efocus=enthover=-1;}})
 
static void mmboundbox (const entity &e, model *m, vec &center, vec &radius)
 
static void mmcollisionbox (const entity &e, model *m, vec &center, vec &radius)
 
bool getentboundingbox (const extentity &e, ivec &o, ivec &r)
 
void modifyoctaentity (int flags, int id, extentity &e, cube *c, const ivec &cor, int size, const ivec &bo, const ivec &br, int leafsize, vtxarray *lastva=nullptr)
 
static bool modifyoctaent (int flags, int id, extentity &e)
 
bool modifyoctaent (int flags, int id)
 
static void addentity (int id)
 
static void removeentity (int id)
 
void freeoctaentities (cube &c)
 
void entitiesinoctanodes ()
 
static void findents (octaentities &oe, int low, int high, bool notspawned, const vec &pos, const vec &invradius, vector< int > &found)
 
static void findents (cube *c, const ivec &o, int size, const ivec &bo, const ivec &br, int low, int high, bool notspawned, const vec &pos, const vec &invradius, vector< int > &found)
 
void findents (int low, int high, bool notspawned, const vec &pos, const vec &radius, vector< int > &found)
 
char * entname (entity &e)
 
bool noentedit ()
 
bool pointinsel (const selinfo &sel, const vec &o)
 
bool haveselent ()
 
void entcancel ()
 cancel (remove) entity selection More...
 
void entadd (int id)
 
undoblocknewundoent ()
 
void makeundoent ()
 
void detachentity (extentity &e)
 
 VAR (attachradius, 1, 100, 1000)
 
void attachentity (extentity &e)
 
void attachentities ()
 
vec getselpos ()
 
undoblockcopyundoents (undoblock *u)
 
void pasteundoent (int idx, const entity &ue)
 
void pasteundoents (undoblock *u)
 
void entflip ()
 
void entrotate (int *cw)
 
void entselectionbox (const entity &e, vec &eo, vec &es)
 
 VAR (entselsnap, 0, 0, 1)
 
 VAR (entmovingshadow, 0, 1, 1)
 
void boxs (int orient, vec o, const vec &s, float size)
 renders a rectangular box to the target location with faked thick lines More...
 
void boxs (int orient, vec o, const vec &s)
 renders a rectangular box to the target location More...
 
void boxs3D (const vec &o, vec s, int g)
 render cube (6 boxes) to target location More...
 
bool editmoveplane (const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first)
 move the selection grid (the "plane") along the selection has an origin and can only be moved in 2 dimensions simultaneously More...
 
void entdrag (const vec &ray)
 
 VAR (showentradius, 0, 1, 1)
 
void renderentring (const extentity &e, float radius, int axis)
 
void renderentsphere (const extentity &e, float radius)
 
void renderentattachment (const extentity &e)
 
void renderentarrow (const extentity &e, const vec &dir, float radius)
 
void renderentcone (const extentity &e, const vec &dir, float radius, float angle)
 
void renderentradius (extentity &e, bool color)
 
static void renderentbox (const vec &eo, vec es)
 
void renderentselection (const vec &o, const vec &ray, bool entmoving)
 
bool enttoggle (int id)
 
bool hoveringonent (int ent, int orient)
 
 VAR (entitysurf, 0, 0, 1)
 
 ICOMMAND (entadd,"",(),{if(enthover >=0 &&!noentedit()){if(entgroup.find(enthover)< 0) entadd(enthover);if(entmoving > 1) entmoving=1;}})
 
 ICOMMAND (enttoggle,"",(),{if(enthover< 0||noentedit()||!enttoggle(enthover)){entmoving=0;intret(0);}else{if(entmoving > 1) entmoving=1;intret(1);}})
 
 ICOMMAND (entmoving,"b",(int *n),{if(*n >=0){if(!*n||enthover< 0||noentedit()) entmoving=0;else{if(entgroup.find(enthover)< 0){entadd(enthover);entmoving=1;}else if(!entmoving) entmoving=1;}}intret(entmoving);})
 
void entpush (int *dir)
 
 VAR (entautoviewdist, 0, 25, 100)
 
void entautoview (int *dir)
 
 COMMAND (entautoview,"i")
 
 COMMAND (entflip,"")
 
 COMMAND (entrotate,"i")
 
 COMMAND (entpush,"i")
 
void delent ()
 
int findtype (char *what)
 
 VAR (entdrop, 0, 2, 3)
 
bool dropentity (entity &e, int drop=-1)
 
void dropent ()
 
void attachent ()
 
 COMMAND (attachent,"")
 
extentitynewentity (bool local, const vec &o, int type, int v1, int v2, int v3, int v4, int v5, int &idx)
 
void newentity (int type, int a1, int a2, int a3, int a4, int a5)
 
void newent (char *what, int *a1, int *a2, int *a3, int *a4, int *a5)
 
void entcopy ()
 
void entpaste ()
 
 COMMAND (newent,"siiiii")
 
 COMMAND (delent,"")
 
 COMMAND (dropent,"")
 
 COMMAND (entcopy,"")
 
 COMMAND (entpaste,"")
 
void entset (char *what, int *a1, int *a2, int *a3, int *a4, int *a5)
 
void printent (extentity &e, char *buf, int len)
 
void nearestent ()
 
 ICOMMAND (entget,"",(), entfocus(efocus, string s;printent(e, s, sizeof(s));result(s)))
 
 ICOMMAND (enthavesel,"",(), addimplicit(intret(entgroup.length())))
 
 ICOMMAND (entindex,"",(), intret(efocus))
 
 ICOMMAND (entloop,"e",(uint *body), if(!noentedit()) addimplicit(groupeditloop(((void) e, execute(body)))))
 
 ICOMMAND (entselect,"e",(uint *body), if(!noentedit()) addgroup(e.type!=ET_EMPTY &&entgroup.find(n)< 0 &&executebool(body)))
 
 ICOMMAND (insel,"",(), entfocus(efocus, intret(pointinsel(sel, e.o))))
 
 COMMAND (entset,"siiiii")
 
 COMMAND (nearestent,"")
 
void enttype (char *type, int *numargs)
 
void entattr (int *attr, int *val, int *numargs)
 
 COMMAND (enttype,"sN")
 
 COMMAND (entattr,"iiN")
 
int findentity (int type, int index, int attr1, int attr2)
 
void findplayerspawn (dynent *d, int forceent, int tag)
 
void splitocta (cube *c, int size)
 
void resetmap ()
 
void startmap (const char *name)
 
bool emptymap (int scale, bool force, const char *mname, bool usecfg)
 
bool enlargemap (bool force)
 
static bool isallempty (cube &c)
 
void shrinkmap ()
 
void newmap (int *i)
 
void mapenlarge ()
 
 COMMAND (newmap,"i")
 
 COMMAND (mapenlarge,"")
 
 COMMAND (shrinkmap,"")
 
void mapname ()
 
 COMMAND (mapname,"")
 
void mpeditent (int i, const vec &o, int type, int attr1, int attr2, int attr3, int attr4, int attr5, bool local)
 
int getworldsize ()
 
int getmapversion ()
 

Variables

int efocus = -1
 
int enthover = -1
 
int entorient = -1
 
int oldhover = -1
 
vector< int > outsideents
 
selinfo sel
 
bool havesel
 
int entlooplevel = 0
 
bool undonext = true
 
vector< int > entgroup
 
int entmoving = 0
 
static int keepents = 0
 
int entcopygrid
 
vector< entityentcopybuf
 
int spawncycle = -1
 

Macro Definition Documentation

#define addgroup (   exp)    { vector<extentity *> &ents = entities::getents(); loopv(ents) entfocusv(i, if(exp) entadd(n), ents); }
#define addimplicit (   f)    { if(entgroup.empty() && enthover>=0) { entadd(enthover); undonext = (enthover != oldhover); f; entgroup.drop(); } else f; }
#define entedit (   i,
  f 
)    enteditv(i, f, entities::getents())
#define enteditv (   i,
  f,
 
)
Value:
{ \
{ \
int oldtype = e.type; \
f; \
if(oldtype!=e.type) detachentity(e); \
if(e.type!=ET_EMPTY) { addentity(n); if(oldtype!=e.type) attachentity(e); } \
entities::editent(n, true); \
}, v); \
}
void editent(int i, bool local)
Definition: entities.cpp:746
void detachentity(extentity &e)
Definition: world.cpp:417
ICOMMAND * f(float *a, float *b), floatret(*a **b)
static void removeentity(int id)
Definition: world.cpp:268
#define entfocusv(i, f, v)
Definition: world.cpp:479
static void addentity(int id)
Definition: world.cpp:267
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
void attachentity(extentity &e)
Definition: world.cpp:426
Definition: ents.hpp:13
#define entfocus (   i,
  f 
)    entfocusv(i, f, entities::getents())
#define entfocusv (   i,
  f,
 
)    { int n = efocus = (i); if(n>=0) { extentity &e = *v[n]; f; } }
#define groupedit (   f)    { addimplicit(groupeditundo(f)); }
#define groupeditloop (   f)    { vector<extentity *> &ents = entities::getents(); entlooplevel++; int _ = efocus; loopv(entgroup) enteditv(entgroup[i], f, ents); efocus = _; entlooplevel--; }
#define groupeditpure (   f)    { if(entlooplevel>0) { entedit(efocus, f); } else groupeditloop(f); }

Referenced by entdrag(), and entpush().

#define groupeditundo (   f)    { makeundoent(); groupeditpure(f); }

Referenced by entflip(), entpaste(), and entrotate().

#define setgroup (   exp)    { entcancel(); addgroup(exp); }

Enumeration Type Documentation

anonymous enum
Enumerator
MODOE_ADD 
MODOE_UPDATEBB 
MODOE_LIGHTENT 

Function Documentation

static void addentity ( int  id)
inlinestatic
void attachent ( )
void attachentities ( )
void attachentity ( extentity e)
void boxs ( int  orient,
vec  o,
const vec s,
float  size 
)

renders a rectangular box to the target location with faked thick lines

References vec::add(), gle::attrib(), gle::begin(), boxoutline, C, D, hmap::d, hmap::dc, dimcoord, dimension, gle::end(), f(), R, and xtraverts.

Referenced by boxs3D(), rendereditcursor(), and renderentselection().

void boxs ( int  orient,
vec  o,
const vec s 
)

renders a rectangular box to the target location

Parameters
orientcube face orientation index (3 dimensions x 2 directions = 6 possible orientation indices)
otarget rendering position
sa constant scalar vector

References gle::attrib(), gle::begin(), boxoutline, C, D, hmap::d, hmap::dc, dimcoord, dimension, gle::end(), f(), R, and xtraverts.

void boxs3D ( const vec o,
vec  s,
int  g 
)

render cube (6 boxes) to target location

Parameters
oselection start vector
sselection end vector
ggridsize

References boxs(), loopi(), and vec::mul().

Referenced by rendereditcursor(), and renderentselection().

COMMAND ( entautoview  ,
"i"   
)
COMMAND ( entflip  ,
""   
)
COMMAND ( entrotate  ,
"i"   
)
COMMAND ( entpush  ,
"i"   
)
COMMAND ( attachent  ,
""   
)
COMMAND ( newent  ,
"siiiii"   
)
COMMAND ( delent  ,
""   
)
COMMAND ( dropent  ,
""   
)
COMMAND ( entcopy  ,
""   
)
COMMAND ( entpaste  ,
""   
)
COMMAND ( entset  ,
"siiiii"   
)
COMMAND ( nearestent  ,
""   
)
COMMAND ( enttype  ,
"sN"   
)
COMMAND ( entattr  ,
"iiN"   
)
COMMAND ( newmap  ,
"i"   
)
COMMAND ( mapenlarge  ,
""   
)
COMMAND ( shrinkmap  ,
""   
)
COMMAND ( mapname  ,
""   
)
undoblock* copyundoents ( undoblock u)
void delent ( )
void detachentity ( extentity e)

References extentity::attached.

Referenced by attachentity(), and mpeditent().

void dropent ( )
bool dropentity ( entity e,
int  drop = -1 
)
bool editmoveplane ( const vec o,
const vec ray,
int  d,
float  off,
vec handle,
vec dest,
bool  first 
)

move the selection grid (the "plane") along the selection has an origin and can only be moved in 2 dimensions simultaneously

References vec::add(), vec::mul(), physent::o, player, plane::rayintersect(), and vec::sub().

Referenced by entdrag(), and rendereditcursor().

bool emptymap ( int  scale,
bool  force,
const char *  mname,
bool  usecfg 
)
bool enlargemap ( bool  force)
void entadd ( int  id)
void entattr ( int *  attr,
int *  val,
int *  numargs 
)

References efocus, entfocus, groupedit, and intret().

void entautoview ( int *  dir)
void entcancel ( )

cancel (remove) entity selection

References entgroup, and vector< T, MINSIZE >::shrink().

Referenced by cancelsel(), copyundoents(), delent(), and entpaste().

void entcopy ( )
void entdrag ( const vec ray)
void entflip ( )
void entitiesinoctanodes ( )
char* entname ( entity e)
void entpaste ( )
void entpush ( int *  dir)
void entrotate ( int *  cw)
void entselectionbox ( const entity e,
vec eo,
vec es 
)
void entset ( char *  what,
int *  a1,
int *  a2,
int *  a3,
int *  a4,
int *  a5 
)
bool enttoggle ( int  id)
void enttype ( char *  type,
int *  numargs 
)
int findentity ( int  type,
int  index,
int  attr1,
int  attr2 
)
static void findents ( octaentities oe,
int  low,
int  high,
bool  notspawned,
const vec pos,
const vec invradius,
vector< int > &  found 
)
inlinestatic
static void findents ( cube c,
const ivec o,
int  size,
const ivec bo,
const ivec br,
int  low,
int  high,
bool  notspawned,
const vec pos,
const vec invradius,
vector< int > &  found 
)
inlinestatic
void findents ( int  low,
int  high,
bool  notspawned,
const vec pos,
const vec radius,
vector< int > &  found 
)
void findplayerspawn ( dynent d,
int  forceent,
int  tag 
)
int findtype ( char *  what)
void freeoctaentities ( cube c)
bool getentboundingbox ( const extentity e,
ivec o,
ivec r 
)
int getmapversion ( )

References mapversion.

vec getselpos ( )
int getworldsize ( )
bool haveselent ( )
bool hoveringonent ( int  ent,
int  orient 
)
ICOMMAND ( entadd  ,
""  ,
()  ,
{if(enthover >=0 &&!noentedit()){if(entgroup.find(enthover)< 0) entadd(enthover);if(entmoving > 1) entmoving=1;}}   
)
ICOMMAND ( enttoggle  ,
""  ,
()  ,
{if(enthover< 0||noentedit()||!enttoggle(enthover)){entmoving=0;intret(0);}else{if(entmoving > 1) entmoving=1;intret(1);}}   
)
ICOMMAND ( entmoving  ,
"b"  ,
(int *n)  ,
{if(*n >=0){if(!*n||enthover< 0||noentedit()) entmoving=0;else{if(entgroup.find(enthover)< 0){entadd(enthover);entmoving=1;}else if(!entmoving) entmoving=1;}}intret(entmoving);}   
)
ICOMMAND ( entget  ,
""  ,
()  ,
entfocus(efocus, string s;printent(e, s, sizeof(s));result(s))   
)
ICOMMAND ( enthavesel  ,
""  ,
()  ,
addimplicit(intret(entgroup.length()))   
)
ICOMMAND ( entindex  ,
""  ,
()  ,
intret(efocus  
)
ICOMMAND ( entloop  ,
"e"  ,
(uint *body)  ,
if(!noentedit()) addimplicit(groupeditloop(((void) e, execute(body))))   
)
ICOMMAND ( entselect  ,
"e"  ,
(uint *body)  ,
if(!noentedit()) addgroup(e.type!=ET_EMPTY &&entgroup.find(n)< 0 &&executebool(body))   
)
ICOMMAND ( insel  ,
""  ,
()  ,
entfocus(efocus, intret(pointinsel(sel, e.o)))   
)
static bool isallempty ( cube c)
static

References cube::children, isempty, and loopi().

Referenced by shrinkmap().

void makeundoent ( )

References addundo(), enthover, newundoent(), oldhover, and undonext.

Referenced by entdrag(), and newentity().

void mapenlarge ( )

References enlargemap(), and game::newmap().

void mapname ( )
static void mmboundbox ( const entity e,
model m,
vec center,
vec radius 
)
inlinestatic
static void mmcollisionbox ( const entity e,
model m,
vec center,
vec radius 
)
inlinestatic
static bool modifyoctaent ( int  flags,
int  id,
extentity e 
)
static
bool modifyoctaent ( int  flags,
int  id 
)
void modifyoctaentity ( int  flags,
int  id,
extentity e,
cube c,
const ivec cor,
int  size,
const ivec bo,
const ivec br,
int  leafsize,
vtxarray lastva = nullptr 
)
void mpeditent ( int  i,
const vec o,
int  type,
int  attr1,
int  attr2,
int  attr3,
int  attr4,
int  attr5,
bool  local 
)
void nearestent ( )
void newent ( char *  what,
int *  a1,
int *  a2,
int *  a3,
int *  a4,
int *  a5 
)
extentity* newentity ( bool  local,
const vec o,
int  type,
int  v1,
int  v2,
int  v3,
int  v4,
int  v5,
int &  idx 
)
void newentity ( int  type,
int  a1,
int  a2,
int  a3,
int  a4,
int  a5 
)
void newmap ( int *  i)
undoblock* newundoent ( )
bool noentedit ( )
void pasteundoent ( int  idx,
const entity ue 
)
void pasteundoents ( undoblock u)

References entedit, undoblock::ents(), loopi(), and undoblock::numents.

Referenced by pasteundo().

bool pointinsel ( const selinfo sel,
const vec o 
)

References selinfo::grid, selinfo::o, and selinfo::s.

void printent ( extentity e,
char *  buf,
int  len 
)
static void removeentity ( int  id)
inlinestatic
void renderentarrow ( const extentity e,
const vec dir,
float  radius 
)
void renderentattachment ( const extentity e)
static void renderentbox ( const vec eo,
vec  es 
)
static

References vec::add(), and gle::attrib().

Referenced by renderentselection().

void renderentcone ( const extentity e,
const vec dir,
float  radius,
float  angle 
)
void renderentradius ( extentity e,
bool  color 
)
void renderentring ( const extentity e,
float  radius,
int  axis 
)
void renderentselection ( const vec o,
const vec ray,
bool  entmoving 
)
void renderentsphere ( const extentity e,
float  radius 
)

References loopk, and renderentring().

Referenced by renderentradius().

void resetmap ( )
void shrinkmap ( )
void splitocta ( cube c,
int  size 
)

References cube::children, F_EMPTY, F_SOLID, isempty, loopi(), and newcubes().

Referenced by emptymap(), and enlargemap().

void startmap ( const char *  name)

Referenced by emptymap(), and load_world().

SVARR ( maptitle  ,
"Untitled Map by Unknown"   
)
VAR ( octaentsize  ,
,
64  ,
1024   
)
VAR ( entselradius  ,
,
,
10   
)
VAR ( attachradius  ,
,
100  ,
1000   
)
VAR ( entselsnap  ,
,
,
 
)
VAR ( entmovingshadow  ,
,
,
 
)
VAR ( showentradius  ,
,
,
 
)
VAR ( entitysurf  ,
,
,
 
)
VAR ( entautoviewdist  ,
,
25  ,
100   
)
VAR ( entdrop  ,
,
,
 
)
VARF ( entediting  ,
,
,
,
{if(!entediting){entcancel();efocus=enthover=-1;}}   
)
VARNR ( mapscale  ,
worldscale  ,
,
,
 
)
VARNR ( mapsize  ,
worldsize  ,
,
,
 
)
VARR ( mapversion  ,
,
MAPVERSION  ,
 
)

Variable Documentation

int efocus = -1
vector<entity> entcopybuf

Referenced by entcopy(), and entpaste().

int entcopygrid

Referenced by entcopy(), and entpaste().

vector<int> entgroup
int enthover = -1
int entlooplevel = 0
int entmoving = 0

Referenced by entdrag(), entpush(), and rendereditcursor().

int entorient = -1
bool havesel
int keepents = 0
static

Referenced by entpaste(), and newentity().

int oldhover = -1

Referenced by makeundoent().

vector<int> outsideents
selinfo sel
int spawncycle = -1

Referenced by findplayerspawn().

bool undonext = true

Referenced by entadd(), enttoggle(), and makeundoent().