Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
cubeworld Class Reference

An object representing the entirety of an octree world. More...

#include <octa.h>

Public Member Functions

int lookupmaterial (const vec &v)
 Returns the material bitmask value at the given location.
 
bool emptymap (int factor, bool force, bool usecfg=true)
 Clears the old level and creates a new one.
 
bool enlargemap (bool force)
 Grows the map to an additional gridsize.
 
bool modifyoctaent (int flags, int id, extentity &e)
 
void shrinkmap ()
 attempts to reduce the mapsize by 1 (halves all linear dimensions)
 
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.
 
bool save_world (const char *mname, const char *gameident)
 Saves the current map to an ogz file.
 
int compactvslots (bool cull=false)
 Removes unnecessary virtual texture slots.
 
void genprefabmesh (prefab &p)
 
void cleanupva ()
 Destroys vertex arrays for the octree world.
 
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 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.
 
cubelookupcube (const ivec &to, int tsize=0, ivec &ro=lu, int &rsize=lusize)
 Returns a reference to the cube at the specified world coordinates.
 
bool bboccluded (const ivec &bo, const ivec &br) const
 
void findtjoints ()
 
void allchanged (bool load=false)
 
const cubeneighborcube (int orient, const ivec &co, int size, ivec &ro, int &rsize)
 
void calclight ()
 Calculates normals and re-calculates geometry.
 
float shadowray (const vec &o, const vec &ray, float radius, int mode, const extentity *t=nullptr)
 
void changed (const ivec &bbmin, const ivec &bbmax, bool commit=true)
 
void changed (const block3 &sel, bool commit=true)
 
clipplanes & getclipbounds (const cube &c, const ivec &o, int size, int offset)
 
void calcnormals (bool lerptjoints)
 
void remip ()
 Reduces the number of cubes on the level losslessly.
 
uint getmapcrc () const
 Returns the CRC code for the map currently loaded.
 
void clearmapcrc ()
 sets the CRC field variable to 0
 
void entitiesinoctanodes ()
 
void commitchanges (bool force=false)
 
void updateparticles ()
 
int mapscale () const
 Returns the gridpower scale of the world.
 
int mapsize () const
 Returns the linear dimensions of the world.
 

Public Attributes

std::array< cube, 8 > * worldroot
 

Detailed Description

An object representing the entirety of an octree world.

A cubeworld is an object storing an entire octree structure and its data; the octree is made up of cube objects, the topmost of which is pointed to by worldroot.

Member Function Documentation

◆ calclight()

void cubeworld::calclight ( )

Calculates normals and re-calculates geometry.

Re-mips the cube structure of the level to remove unnecessary nodes, then calculates normal maps for corners.

◆ cleanupva()

void cubeworld::cleanupva ( )

Destroys vertex arrays for the octree world.

Cleans up the geometry objects used by the renderer to render the octree world.

◆ clearmapcrc()

void cubeworld::clearmapcrc ( )

sets the CRC field variable to 0

Invalidates the CRC code saved as a cubeworld field for the world, usually to indicate that the CRC has become invalid as a result of modification.

◆ compactvslots()

int cubeworld::compactvslots ( bool cull = false)

Removes unnecessary virtual texture slots.

Checks and removes unused virtual texture slots (vslots) from the octree world.

◆ emptymap()

bool cubeworld::emptymap ( int factor,
bool force,
bool usecfg = true )

Clears the old level and creates a new one.

This function unloads the old map, including textures, and creates a new level of the size specified.

Parameters
factorsets the gridscale (power of 2 size) of the map; limit 10 to 15
forceif true, creates map regardless of check variables
usecfgif true, uses the default map config path

◆ enlargemap()

bool cubeworld::enlargemap ( bool force)

Grows the map to an additional gridsize.

Expands the map by placing the old map in the corner nearest the origin and adding 7 old-map sized cubes to create a new largest cube.

This moves the worldroot cube to the new parent cube of the old map.

◆ getmapcrc()

uint cubeworld::getmapcrc ( ) const

Returns the CRC code for the map currently loaded.

Returns the cyclic redundancy checksum for the file currently loaded. This value is unique for every revision of a map binary, and is useful to make sure multiple clients have the same binary.

Returns
the cyclic redundancy code of the map file currently loaded

◆ load_world()

bool cubeworld::load_world ( const char * mname,
const char * gameident,
const char * gameinfo = nullptr,
const char * cname = nullptr )

Loads a map file into the octaworld object.

Loads a map that has been saved in .ogz format. Will load the configuration file of the same name, unless cname is specified.

Parameters
mnamethe name of the map to load (the ogz)
gameidentthe name of the game calling (this is saved in the map)
gameinfothe string to render while the map is loading
thename of the map's configuration file (if different than the octree)
Returns
true if the map was loaded
false if the map failed to load or was not found

◆ lookupcube()

cube & cubeworld::lookupcube ( const ivec & to,
int tsize = 0,
ivec & ro = lu,
int & rsize = lusize )

Returns a reference to the cube at the specified world coordinates.

Parameters
tothe location to look in
tsizethe size of cube to find (by gridpower)
rothe found location to be assigned by reference
rsizethe found size (gridpower) of the cube to be assigned by reference

◆ lookupmaterial()

int cubeworld::lookupmaterial ( const vec & v)

Returns the material bitmask value at the given location.

Given a world location, returns the material bitmask at the specified location. This bitmask may be the sum of multiple materials if present. Returns 0 (air) if the location specified has no material or is outside the world.

Returns
an integer corresponding to the material(s) at the specified location

◆ mapscale()

int cubeworld::mapscale ( ) const

Returns the gridpower scale of the world.

Returns the size of the worldroot cube, in terms of the number of half-linear-size cubes it has as descendents in the octree. This value is generally between 10 and 15.

Returns
the scale of the world

◆ mapsize()

int cubeworld::mapsize ( ) const

Returns the linear dimensions of the world.

Returns the size of the worldroot cube, in terms of the number of size 0 cubes on each linear axis. This value is generally between 2^10 and 2^15.

Returns
the size of the world

◆ octacollide()

bool cubeworld::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.

Parameters
dthe physent to check
dirthe direction at which to check for a collision
cutoffthe model cutoff factor
bothe vector for the minimum position of the model
bsthe vector for the maximum position of the model

◆ raycube()

float cubeworld::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.

Parameters
othe starting location of the ray to be drawn
raynormalized direction vector for the ray to point
radiusregion around ray that counts as a hit
modeflags which determine what counts as a hit
sizesize of cube which registers a hit
tentity to check against

◆ remip()

void cubeworld::remip ( )

Reduces the number of cubes on the level losslessly.

Loops through all cube objects, dissolving child nodes where it is possible to convert them to their parent nodes. The largest gridpower that can be optimizied can be controlled by the maxmerge variable.

◆ save_world()

bool cubeworld::save_world ( const char * mname,
const char * gameident )

Saves the current map to an ogz file.

Parameters
mnamethe name of the map file once saved
gameidentthe name of the game saving the file
Returns
true if the map was saved
false if the map failed to save

◆ shrinkmap()

void cubeworld::shrinkmap ( )

attempts to reduce the mapsize by 1 (halves all linear dimensions)

Fails if the 7 octants not at the origin are not empty. On success, the resulting map will have its maximum gridsize reduced by 1.


The documentation for this class was generated from the following file: