Libprimis
Imprimis' 3D destroyable world engine
|
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. | |
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 | bboccluded (const ivec &bo, const ivec &br) const |
void | findtjoints () |
void | allchanged (bool load=false) |
const cube & | neighborcube (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 |
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
.
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.
void cubeworld::cleanupva | ( | ) |
Destroys vertex arrays for the octree world.
Cleans up the geometry objects used by the renderer to render the octree world.
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.
int cubeworld::compactvslots | ( | bool | cull = false | ) |
Removes unnecessary virtual texture slots.
Checks and removes unused virtual texture slots (vslots) from the octree world.
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.
factor | sets the gridscale (power of 2 size) of the map; limit 10 to 15 |
force | if true, creates map regardless of check variables |
usecfg | if true, uses the default map config path |
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.
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.
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.
mname | the name of the map to load (the ogz) |
gameident | the name of the game calling (this is saved in the map) |
gameinfo | the string to render while the map is loading |
the | name of the map's configuration file (if different than the octree) |
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.
to | the location to look in |
tsize | the size of cube to find (by gridpower) |
ro | the found location to be assigned by reference |
rsize | the found size (gridpower) of the cube to be assigned by reference |
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.
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.
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.
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.
d | the physent to check |
dir | the direction at which to check for a collision |
cutoff | the model cutoff factor |
bo | the vector for the minimum position of the model |
bs | the vector for the maximum position of the model |
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.
o | the starting location of the ray to be drawn |
ray | normalized direction vector for the ray to point |
radius | region around ray that counts as a hit |
mode | flags which determine what counts as a hit |
size | size of cube which registers a hit |
t | entity to check against |
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.
bool cubeworld::save_world | ( | const char * | mname, |
const char * | gameident ) |
Saves the current map to an ogz file.
mname | the name of the map file once saved |
gameident | the name of the game saving the file |
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.