LCOV - code coverage report
Current view: top level - engine/world - octaworld.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 0.0 % 46 0
Test Date: 2025-04-10 07:01:40 Functions: 0.0 % 13 0

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

Generated by: LCOV version 2.0-1