14const int Face_MaxVerts = 15;
153 void setmat(ushort mat, ushort matmask, ushort filtermat, ushort filtermask,
int filtergeom);
190 ushort u1, u2, v1, v2;
194 return u1 >= u2 || v1 >= v2;
202 pvert(ushort x, ushort y) : x(x), y(y) {}
204 bool operator==(
const pvert &o)
const
206 return x == o.x && y == o.y;
208 bool operator!=(
const pvert &o)
const
210 return x != o.x || y != o.y;
219 pedge(
const pvert &from,
const pvert &to) : from(from), to(to) {}
221 bool operator==(
const pedge &o)
const
223 return from == o.from && to == o.to;
225 bool operator!=(
const pedge &o)
const
227 return from != o.from || to != o.to;
231 class plink :
public pedge
241 plink(
const pedge &p) : pedge(p)
248 polys[0] = polys[1] = -1;
257 pvert verts[Face_MaxVerts];
259 bool clippoly(
const facebounds &b);
260 bool mergepolys(std::unordered_set<plink> &links, std::deque<const plink *> &queue,
int owner, poly &q,
const pedge &e);
263 bool mincubeface(
const cube &cu,
int orient,
const ivec &co,
int size, facebounds &orig)
const;
264 void mincubeface(
const cube &cu,
int orient,
const ivec &o,
int size,
const facebounds &orig, facebounds &cf, ushort nmat, ushort matmask)
const;
266 void freecubeext(
cube &c);
267 void genmerges(
cube * root,
const ivec &o =
ivec(0, 0, 0),
int size = 9);
268 bool genpoly(
int orient,
const ivec &o,
int size,
int vis,
ivec &n,
int &offset, poly &p);
269 void clearmerge(
int orient);
270 void addmerge(
int orient,
const ivec &n,
int offset, poly &p);
271 void addmerges(
int orient,
const ivec &n,
int offset, std::deque<poly> &polys);
272 void mergepolys(
int orient,
const ivec &n,
int offset, std::deque<poly> &polys);
276 std::deque<poly> polys;
282 ushort material, tex;
288 friend std::hash<plink>;
289 friend std::hash<cfkey>;
290 friend bool operator==(
const cfkey &x,
const cfkey &y);
299 int cx, cxs, cy, cys;
304 selinfo() : corner(0), cx(0), cxs(0), cy(0), cys(0),
o(0, 0, 0),
s(0, 0, 0),
grid(8),
orient(0) {}
364 const cube *getcube()
const
366 return reinterpret_cast<const cube *
>(
this+1);
371 return reinterpret_cast<cube *
>(
this+1);
401 return reinterpret_cast<block3 *
>(
this + 1);
407 return reinterpret_cast<uchar *
>(ub->c() + ub->size());
412 return reinterpret_cast<undoent *
>(
this + 1);
416extern int selchildcount, selchildmat;
426inline int octadim(
int d)
432#define LOOP_XY(b) for(int y = 0; y < (b).s[C[DIMENSION((b).orient)]]; ++y) for(int x = 0; x < (b).s[R[DIMENSION((b).orient)]]; ++x)
433#define LOOP_XYZ(b, r, f) { for(int z = 0; z < (b).s[D[DIMENSION((b).orient)]]; ++z) LOOP_XY((b)) { cube &c = blockcube(x,y,z,b,r); f; } }
434#define LOOP_SEL_XYZ(f) { if(local) makeundo(); LOOP_XYZ(sel, sel.grid, f); rootworld.changed(sel); }
435#define SELECT_CUBE(x, y, z) blockcube(x, y, z, sel, sel.grid)
438#define PROTECT_SEL(f) { undoblock *_u = newundocube(sel); f; if(_u) { pasteundoblock(_u->block(), _u->gridmap()); freeundo(_u); } }
440#define DIMENSION(orient) ((orient)>>1)
441#define DIM_COORD(orient) ((orient)&1)
458 std::array<cube, 8> *worldroot;
483 bool emptymap(
int factor,
bool force,
bool usecfg =
true);
494 bool modifyoctaent(
int flags,
int id,
extentity &e);
518 bool load_world(
const char *mname,
const char *gameident,
const char *gameinfo =
nullptr,
const char *cname =
nullptr);
538 void genprefabmesh(prefab &p);
558 float raycube (
const vec &o,
const vec &ray,
float radius = 0,
int mode = 3,
int size = 0,
const extentity *t = 0)
const;
580 bool bboccluded(
const ivec &bo,
const ivec &br)
const;
582 void allchanged(
bool load =
false);
583 const cube &neighborcube(
int orient,
const ivec &co,
int size,
ivec &ro,
int &rsize);
592 float shadowray(
const vec &o,
const vec &ray,
float radius,
int mode,
const extentity *t =
nullptr);
593 void changed(
const ivec &bbmin,
const ivec &bbmax,
bool commit =
true);
594 void changed(
const block3 &sel,
bool commit =
true);
595 clipplanes &getclipbounds(
const cube &c,
const ivec &o,
int size,
int offset);
596 void calcnormals(
bool lerptjoints);
625 void entitiesinoctanodes();
626 void commitchanges(
bool force =
false);
627 void updateparticles();
653 string ogzname, bakname, cfgname, picname;
658 struct emptycube :
cube
668 for(
int i = 0; i < 6; ++i)
705 void seedparticles();
706 void makeparticles(
const entity &e);
713 void resetclipplanes();
726 void savec(
const std::array<cube, 8> &c,
const ivec &o,
int size,
stream *
const f);
738 bool loadmapheader(
stream *f,
const char *ogzname, mapheader &hdr, octaheader &ohdr)
const;
748 void setmapfilenames(
const char *fname,
const char *cname =
nullptr);
750 bool upoctree(
const vec& v,
int& x,
int& y,
int& z,
const ivec& lo,
int& lshift)
const;
751 bool checkinsideworld(
const vec &invray,
float radius,
float &outrad,
const vec &o,
vec &v,
const vec &ray,
float &dist)
const;
The fundemental building block of the octree world, representing a 3D cube.
Definition octa.h:100
std::array< cube, 8 > * children
Definition octa.h:102
uint faces[3]
Definition octa.h:108
void calcmerges()
Merges adjacent faces that can be losslessly merged.
bool issolid() const
returns if the cube passed is entirely solid (no distortions)
Definition octa.h:133
uchar escaped
Definition octa.h:115
bool valid
Definition octa.h:118
cubeext * ext
Definition octa.h:103
bool isvalidcube() const
Returns whether the cube is valid.
uchar merged
Definition octa.h:112
uchar visible
Definition octa.h:116
void setmat(ushort mat, ushort matmask, ushort filtermat, ushort filtermask, int filtergeom)
Sets a cube's materials, given a material & filter to use.
bool isempty() const
returns if the cube is empty (face 0 does not exist)
Definition octa.h:125
void discardchildren(bool fixtex=false, int depth=0)
discards children
ushort material
Definition octa.h:111
uchar edges[12]
Definition octa.h:106
ushort texture[6]
Definition octa.h:110
An object representing the entirety of an octree world.
Definition octa.h:456
int mapsize() const
Returns the linear dimensions of the world.
bool emptymap(int factor, bool force, bool usecfg=true)
Clears the old level and creates a new one.
void clearmapcrc()
sets the CRC field variable to 0
void remip()
Reduces the number of cubes on the level losslessly.
void shrinkmap()
attempts to reduce the mapsize by 1 (halves all linear dimensions)
uint getmapcrc() const
Returns the CRC code for the map currently loaded.
void cleanupva()
Destroys vertex arrays for the octree world.
bool enlargemap(bool force)
Grows the map to an additional gridsize.
int lookupmaterial(const vec &v)
Returns the material bitmask value at the given location.
void calclight()
Calculates normals and re-calculates geometry.
int mapscale() const
Returns the gridpower scale of the world.
int compactvslots(bool cull=false)
Removes unnecessary virtual texture slots.
bool save_world(const char *mname, const char *gameident)
Saves the current map to an ogz file.
cube & lookupcube(const ivec &to, int tsize=0, ivec &ro=lu, int &rsize=lusize)
Returns a reference to the cube at the specified world coordinates.
bool octacollide(const physent *d, const vec &dir, float cutoff, const ivec &bo, const ivec &bs) const
Returns whether the entity passed has collided with this octaworld.
float raycube(const vec &o, const vec &ray, float radius=0, int mode=3, int size=0, const extentity *t=0) const
Returns the distance before a ray hits a cube.
bool load_world(const char *mname, const char *gameident, const char *gameinfo=nullptr, const char *cname=nullptr)
Loads a map file into the octaworld object.
constexpr uint facesolid
Definition octa.h:19
void setcubefaces(cube &c, uint face)
sets the faces to a given value face given
Definition octa.h:421
constexpr uint faceempty
Definition octa.h:18
A representation of a rectangular volume of cubes, with less metadata.
Definition octa.h:358
Entity data capable of being saved to disk.
Definition ents.h:82
Extended entity data not of the subset which is saved to disk.
Definition ents.h:93
A base object representing a class.
Definition ents.h:111
A representation of a rectangular volume of cubes.
Definition octa.h:297
bool operator==(const selinfo &sel) const
Returns whether the two selections occupy the same space.
Definition octa.h:339
int size() const
Returns the volume of the selection.
Definition octa.h:315
int orient
Definition octa.h:303
bool validate()
Keeps the selection within the world.
int grid
Definition octa.h:302
ivec s
Definition octa.h:301
ivec o
Definition octa.h:300
int us(int d) const
Returns the absolute size of the selection along the specified axis.
Definition octa.h:327
int size
Definition octa.h:395
int numents
Definition octa.h:397
int timestamp
Definition octa.h:396
size_t i
Definition octa.h:388
three dimensional Cartesian vector object
Definition geom.h:185