LCOV - code coverage report
Current view: top level - engine/world - octaworld.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 4.0 % 50 2
Test Date: 2025-02-18 06:21:28 Functions: 6.7 % 15 1

            Line data    Source code
       1              : #ifndef OCTAWORLD_H_
       2              : #define OCTAWORLD_H_
       3              : 
       4              : #define EDGE_GET(edge, coord) ((coord) ? (edge)>>4 : (edge)&0xF)
       5              : #define EDGE_SET(edge, coord, val) ((edge) = ((coord) ? ((edge)&0xF)|((val)<<4) : ((edge)&0xF0)|(val)))
       6              : 
       7              : #define CUBE_EDGE(c, d, x, y) ((c).edges[(((d)<<2)+((y)<<1)+(x))])
       8              : 
       9           90 : inline int oppositeorient(int orient)
      10              : {
      11           90 :     return orient^1;
      12              : }
      13              : 
      14              : enum BlendMapLayers
      15              : {
      16              :     BlendLayer_Top    = (1<<5),
      17              :     BlendLayer_Bottom = (1<<6),
      18              :     BlendLayer_Blend  = BlendLayer_Top|BlendLayer_Bottom,
      19              : };
      20              : 
      21              : struct prefab;
      22              : 
      23              : struct vertinfo
      24              : {
      25              :     ushort x, y, z, norm;
      26              : 
      27            0 :     void setxyz(ushort a, ushort b, ushort c)
      28              :     {
      29            0 :         x = a;
      30            0 :         y = b;
      31            0 :         z = c;
      32            0 :     }
      33              : 
      34            0 :     void setxyz(const ivec &v)
      35              :     {
      36            0 :         setxyz(v.x, v.y, v.z);
      37            0 :     }
      38              : 
      39            0 :     void set(ushort a, ushort b, ushort c, ushort n = 0)
      40              :     {
      41            0 :         setxyz(a, b, c);
      42            0 :         norm = n;
      43            0 :     }
      44              : 
      45            0 :     void set(const ivec &v, ushort n = 0)
      46              :     {
      47            0 :         set(v.x, v.y, v.z, n);
      48            0 :     }
      49              : 
      50            0 :     ivec getxyz() const
      51              :     {
      52            0 :         return ivec(x, y, z);
      53              :     }
      54              : };
      55              : 
      56              : struct octaentities
      57              : {
      58              :     std::vector<int> mapmodels, //set of indices refering to a position in the getentities() vector corresponding to a mapmodel
      59              :                      decals,    //set of indices refering to a position in the getentities() vector corresponding to a decal
      60              :                      other;     //set of indices refering to a position in the getentities() vector corresponding to a non-mapmodel non-decal entity (sound etc.)
      61              :     occludequery *query;
      62              :     octaentities *next, *rnext;
      63              :     int distance;
      64              :     ivec o;
      65              :     int size;
      66              :     ivec bbmin, bbmax;
      67              : 
      68            0 :     octaentities(const ivec &o, int size) : query(0), o(o), size(size), bbmin(o), bbmax(o)
      69              :     {
      70            0 :         bbmin.add(size);
      71            0 :     }
      72              : };
      73              : 
      74              : enum OcclusionLevels
      75              : {
      76              :     Occlude_Nothing = 0,
      77              :     Occlude_Geom,
      78              :     Occlude_BB,
      79              :     Occlude_Parent
      80              : };
      81              : 
      82              : enum CubeMerges
      83              : {
      84              :     Merge_Origin = 1<<0,
      85              :     Merge_Part   = 1<<1,
      86              :     Merge_Use    = 1<<2
      87              : };
      88              : 
      89              : class cube;
      90              : 
      91              : struct clipplanes
      92              : {
      93              :     vec o, r;
      94              :     std::array<vec, 8> v;
      95              :     std::array<plane, 12> p;
      96              :     std::array<uchar, 12> side;
      97              :     uchar size, //should always be between 0..11 (a valid index to p/side arrays above)
      98              :           visible;
      99              :     const cube *owner;
     100              :     int version;
     101              : 
     102            0 :     void clear()
     103              :     {
     104            0 :         o = vec(0,0,0);
     105            0 :         r = vec(0,0,0);
     106            0 :         for(int i = 0; i < 8; ++i)
     107              :         {
     108            0 :           v[i] = vec(0,0,0);
     109              :         }
     110            0 :         for(int i = 0; i < 12; ++i)
     111              :         {
     112            0 :             p[i] = plane();
     113            0 :             side[i] = 0;
     114              :         }
     115            0 :         size = 0;
     116            0 :         visible = 0;
     117            0 :         owner = nullptr;
     118            0 :         version = 0;
     119            0 :     }
     120              : };
     121              : 
     122              : struct surfaceinfo
     123              : {
     124              :     uchar verts, numverts;
     125              : 
     126            0 :     surfaceinfo() : verts(0), numverts(BlendLayer_Top)
     127              :     {
     128            0 :     }
     129            0 :     surfaceinfo(uchar verts, uchar num) : verts(verts), numverts(num)
     130              :     {
     131            0 :     }
     132              : 
     133            0 :     int totalverts() const
     134              :     {
     135            0 :         return numverts&Face_MaxVerts;
     136              :     }
     137              : 
     138            0 :     bool used() const
     139              :     {
     140            0 :         return (numverts&~BlendLayer_Top) != 0;
     141              :     }
     142              : 
     143            0 :     void clear()
     144              :     {
     145            0 :         numverts = (numverts&Face_MaxVerts) | BlendLayer_Top;
     146            0 :     }
     147              : 
     148              :     void brighten()
     149              :     {
     150              :         clear();
     151              :     }
     152              : };
     153              : 
     154              : struct vtxarray;
     155              : 
     156              : struct cubeext
     157              : {
     158              :     vtxarray *va;            /**< Vertex array for children, or nullptr. */
     159              :     octaentities *ents;      /**< Map entities inside cube. */
     160              :     std::array<surfaceinfo, 6> surfaces; // render info for each surface
     161              :     int tjoints;             // linked list of t-joints
     162              :     uchar maxverts;          // allocated space for verts
     163              : 
     164            0 :     vertinfo *verts()
     165              :     {
     166            0 :         return reinterpret_cast<vertinfo *>(this+1);
     167              :     }
     168              : };
     169              : 
     170              : enum CubeFaceOrientation
     171              : {
     172              :     Orient_Left = 0,
     173              :     Orient_Right,
     174              :     Orient_Back,
     175              :     Orient_Front,
     176              :     Orient_Bottom,
     177              :     Orient_Top,
     178              :     Orient_Any
     179              : };
     180              : 
     181              : extern uchar octaboxoverlap(const ivec &o, int size, const ivec &bbmin, const ivec &bbmax);
     182              : 
     183              : #define LOOP_OCTA_BOX(o, size, bbmin, bbmax) uchar possible = octaboxoverlap(o, size, bbmin, bbmax); for(int i = 0; i < 8; ++i) if(possible&(1<<i))
     184              : 
     185              : #define OCTA_COORD(d, i)     (((i)&octadim(d))>>(d))
     186              : #define OCTA_STEP(x, y, z, scale) (((((z)>>(scale))&1)<<2) | ((((y)>>(scale))&1)<<1) | (((x)>>(scale))&1))
     187              : 
     188              : extern int wtris, wverts,
     189              :            vtris, vverts,
     190              :            glde, gbatches,
     191              :            rplanes;
     192              : 
     193              : extern int allocnodes;
     194              : 
     195              : enum
     196              : {
     197              :     ViewFrustumCull_FullyVisible = 0,
     198              :     ViewFrustumCull_PartlyVisible,
     199              :     ViewFrustumCull_Fogged,
     200              :     ViewFrustumCull_NotVisible,
     201              : };
     202              : 
     203              : extern std::array<cube, 8> *newcubes(uint face = faceempty, int mat = Mat_Air);
     204              : extern cubeext *growcubeext(cubeext *ext, int maxverts);
     205              : extern void setcubeext(cube &c, cubeext *ext);
     206              : extern cubeext *newcubeext(cube &c, int maxverts = 0, bool init = true);
     207              : extern void getcubevector(const cube &c, int d, int x, int y, int z, ivec &p);
     208              : extern void setcubevector(cube &c, int d, int x, int y, int z, const ivec &p);
     209              : extern int familysize(const cube &c);
     210              : extern void freeocta(std::array<cube, 8> *&c);
     211              : extern void validatec(std::array<cube, 8> *&c, int size = 0);
     212              : 
     213              : extern const cube *neighborstack[32];
     214              : extern int neighbordepth;
     215              : extern int getmippedtexture(const cube &p, int orient);
     216              : extern void forcemip(cube &c, bool fixtex = true);
     217              : extern bool subdividecube(cube &c, bool fullcheck=true, bool brighten=true);
     218              : extern int faceconvexity(const std::array<ivec, 4> &v);
     219              : extern int faceconvexity(const std::array<ivec, 4> &v, int &vis);
     220              : extern int faceconvexity(const vertinfo *verts, int numverts, int size);
     221              : extern int faceconvexity(const cube &c, int orient);
     222              : extern uint faceedges(const cube &c, int orient);
     223              : extern bool flataxisface(const cube &c, int orient);
     224              : extern void genclipbounds(const cube &c, const ivec &co, int size, clipplanes &p);
     225              : extern void genclipplanes(const cube &c, const ivec &co, int size, clipplanes &p, bool collide = true, bool noclip = false);
     226              : extern bool visibleface(const cube &c, int orient, const ivec &co, int size, ushort mat = Mat_Air, ushort nmat = Mat_Air, ushort matmask = MatFlag_Volume);
     227              : extern int classifyface(const cube &c, int orient, const ivec &co, int size);
     228              : extern int visibletris(const cube &c, int orient, const ivec &co, int size, ushort vmat = Mat_Air, ushort nmat = Mat_Alpha, ushort matmask = Mat_Alpha);
     229              : extern int visibleorient(const cube &c, int orient);
     230              : extern void genfaceverts(const cube &c, int orient, std::array<ivec, 4> &v);
     231              : extern int calcmergedsize(const ivec &co, int size, const vertinfo *verts, int numverts);
     232              : extern void invalidatemerges(cube &c);
     233              : extern void remip();
     234              : 
     235            0 : inline cubeext &ext(cube &c)
     236              : {
     237            0 :     return *(c.ext ? c.ext : newcubeext(c));
     238              : }
     239              : 
     240              : #define GENFACEVERTX(o,n, x,y,z, xv,yv,zv) GENFACEVERT(o,n, x,y,z, xv,yv,zv)
     241              : 
     242              : #define GENFACEVERTSX(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     243              :     GENFACEORIENT(0, GENFACEVERTX(0,0, x0,y1,z1, d0,r1,c1), GENFACEVERTX(0,1, x0,y1,z0, d0,r1,c0), GENFACEVERTX(0,2, x0,y0,z0, d0,r0,c0), GENFACEVERTX(0,3, x0,y0,z1, d0,r0,c1)) \
     244              :     GENFACEORIENT(1, GENFACEVERTX(1,0, x1,y1,z1, d1,r1,c1), GENFACEVERTX(1,1, x1,y0,z1, d1,r0,c1), GENFACEVERTX(1,2, x1,y0,z0, d1,r0,c0), GENFACEVERTX(1,3, x1,y1,z0, d1,r1,c0))
     245              : 
     246              : #define GENFACEVERTY(o,n, x,y,z, xv,yv,zv) GENFACEVERT(o,n, x,y,z, xv,yv,zv)
     247              : 
     248              : #define GENFACEVERTSY(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     249              :     GENFACEORIENT(2, GENFACEVERTY(2,0, x1,y0,z1, c1,d0,r1), GENFACEVERTY(2,1, x0,y0,z1, c0,d0,r1), GENFACEVERTY(2,2, x0,y0,z0, c0,d0,r0), GENFACEVERTY(2,3, x1,y0,z0, c1,d0,r0)) \
     250              :     GENFACEORIENT(3, GENFACEVERTY(3,0, x0,y1,z0, c0,d1,r0), GENFACEVERTY(3,1, x0,y1,z1, c0,d1,r1), GENFACEVERTY(3,2, x1,y1,z1, c1,d1,r1), GENFACEVERTY(3,3, x1,y1,z0, c1,d1,r0))
     251              : #define GENFACEVERTZ(o,n, x,y,z, xv,yv,zv) GENFACEVERT(o,n, x,y,z, xv,yv,zv)
     252              : 
     253              : #define GENFACEVERTSZ(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     254              :     GENFACEORIENT(4, GENFACEVERTZ(4,0, x0,y0,z0, r0,c0,d0), GENFACEVERTZ(4,1, x0,y1,z0, r0,c1,d0), GENFACEVERTZ(4,2, x1,y1,z0, r1,c1,d0), GENFACEVERTZ(4,3, x1,y0,z0, r1,c0,d0)) \
     255              :     GENFACEORIENT(5, GENFACEVERTZ(5,0, x0,y0,z1, r0,c0,d1), GENFACEVERTZ(5,1, x1,y0,z1, r1,c0,d1), GENFACEVERTZ(5,2, x1,y1,z1, r1,c1,d1), GENFACEVERTZ(5,3, x0,y1,z1, r0,c1,d1))
     256              : 
     257              : #define GENFACEVERTSXY(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     258              :     GENFACEVERTSX(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     259              :     GENFACEVERTSY(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1)
     260              : 
     261              : #define GENFACEVERTS(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     262              :     GENFACEVERTSXY(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
     263              :     GENFACEVERTSZ(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1)
     264              : 
     265              : #endif
        

Generated by: LCOV version 2.0-1