C reference: levels
These calls come from #include <macawlevel.h>. They let a C program open, draw, walk round and even build the levels you make in Brushwork, the level editor. A level is a number: openlevel, loadlevel and newlevel each give you one, and 0 means it didn't work. They work the same way as Lua's level calls, which Levels explains in more detail, and C tells you about C on Macaw OS.
A few things to know
- A level has two halves. Its table is what's in the
.lvlfile: its brushes, entities and settings. Its built level is that table made into something that draws and that you can bump into.openlevelgives you both;loadlevelandnewlevelgive you only the table until you callbuildlevel. - A brush is a solid convex shape, like a box or a wedge, that the level is made of. An entity is a thing at a place in the level, such as a lamp, the player start or a pickup.
- Everything counts from 0: the first brush, the first water, the first face.
- A path that doesn't start with
/is taken from your program's folder. - Calls that give text copy it into a buffer you pass, cut to fit with a 0 on the end, and return the length of the whole text, so you can tell when your buffer was too small.
- Asking a level that isn't built yet to draw or collide is an error, and your program stops with a message. So is using a brush, entity, water or probe that isn't there, except in the calls whose entries say they return 0 for one that isn't there.
The structs
levelcam is a camera, for water and reflection probes:
x,y,z: where the camera is, in the level's units.yaw: which way it turns, in degrees (0 looks along +z, 90 along +x).pitch: how far it looks up, in degrees (negative looks down).fov: how wide it sees, in degrees (0 or less means 90).
levelviewfn is the type of a function you write for water and probes to call. They call it when they need the view from a camera drawn: a mirrored camera under the water for a reflection, or one of the six views round a probe. Your function sets camera3d to the camera and draws the level above the height it's given (with leveldrawabove(level, above)), plus anything else that should show. It returns nothing. Where a call takes one, you can pass NULL, and then it draws just the level. Its arguments are:
c: the camera to draw from, alevelcam. It's only there during the call, so don't keep the pointer.above: the height of the water, so you can leave out what's under it; for a probe it's -1e30, which means draw everything.user: whatever pointer you gave the call that takes your function, passed back unchanged.
levellightinfo is a lamp or an area light, as levellight gives them and levelbake takes them. An area light is a glowing rectangle that lights one way.
x,y,z: where it is (for an area light, its middle).bright: how bright it is (a lamp is 1.2 and an area light 1.5 if the level doesn't say).radius: how far its light reaches (12 if the level doesn't say).r,g,b: its colour, each from 0 to 1.soft: a lamp's size, so how soft its shadows are (0 is hard; -1 means use the bake's softness).area: 1 for an area light, 0 for a lamp.w,h: an area light's size across.facing: which way an area light faces:LIGHT_DOWN(0),LIGHT_UP(1),LIGHT_PX(+x, 2),LIGHT_NX(-x, 3),LIGHT_PZ(+z, 4) orLIGHT_NZ(-z, 5).
Opening, saving and building
openlevel
int openlevel(const char *path)
Reads a .lvl file, builds it, and puts on its baked light from the .lit file next to it (and its baked probes from the .prb file, if the light went on). This is the usual way to start: the level is ready to draw and bump into straight away.
path: the level's file name, like"/system/maps/sample.lvl".
Returns the level's number, or 0 if it couldn't be opened (levelerror says why).
loadlevel
int loadlevel(const char *path)
Reads a .lvl file into a level table without building it. Use it when you want to look at or change a level before building it, or don't need to draw it at all.
path: the level's file name.
Returns the level's number, or 0 if it couldn't be read (levelerror says why).
newlevel
int newlevel(void)
Makes an empty level, with no brushes or entities, for building from code. Its settings start as an ambient of 0.08, a bounce of 1 and a luxel of 0.5.
It takes nothing.
Returns the new level's number.
savelevel
int savelevel(int level, const char *path)
Writes a level's table to a .lvl file, which Brushwork can open. It doesn't save the baked light: levellightdata gives you that to keep yourself. Brush corners are written to 4 significant figures and entity numbers to 6, so keep your sizes simple.
level: the level to save.path: the file to write, usually ending in.lvl.
Returns 1 if it was saved, or 0 if it couldn't be (levelerror says why).
buildlevel
int buildlevel(int level)
Builds a level's table into a level that draws and collides. Call it after loadlevel or newlevel, and again whenever you've changed the brushes. It makes the level's water and probes afresh from its table, and the new build has no baked light yet.
level: the level to build.
Returns 1 if it was built, or 0 if it couldn't be (levelerror says why).
freelevel
void freelevel(int level)
Lets go of a level and everything built for it. After this the number means nothing, so don't use it again.
level: the level to free (one that isn't a level is ignored).
levelerror
int levelerror(char *buf, int size)
Gives the message from the last call that didn't work, such as a file that wasn't there.
buf: where the message goes, achararray.size: how many bytesbufholds.
Returns the length of the whole message.
levelbuilt
int levelbuilt(int level)
Tells you whether a level has been built, so whether it can draw and collide yet.
level: the level to ask about.
Returns 1 if it's built, or 0 if not.
levellit
int levellit(int level)
Tells you whether a level has baked light on it, from its .lit file, levelsetlight or a finished bake.
level: the level to ask about.
Returns 1 if it's lit, or 0 if it has plain shading.
levelpath
int levelpath(int level, char *buf, int size)
Gives the file a level was opened or loaded from.
level: the level to ask about.buf: where the file name goes, achararray.size: how many bytesbufholds.
Returns the length of the file name, or 0 for a level from newlevel.
levellitpath
int levellitpath(const char *path, char *buf, int size)
Gives the file a level's baked light is kept in: the same name with .lit in place of .lvl.
path: the level's file name.buf: where the.litfile's name goes, achararray.size: how many bytesbufholds.
Returns the length of the .lit file's name.
levelprobepath
int levelprobepath(const char *path, char *buf, int size)
Gives the file a level's baked reflection probes are kept in: the same name with .prb in place of .lvl.
path: the level's file name.buf: where the.prbfile's name goes, achararray.size: how many bytesbufholds.
Returns the length of the .prb file's name.
Drawing
These draw a built level with camera3d's camera, unless they say otherwise.
leveldrawbsp
int leveldrawbsp(int level, int *faces)
Draws only the parts of the level the camera can see, working them out through the level's BSP tree and portals (the way it's cut into pieces). This is the fast way, and the one to use each frame.
level: the level to draw.faces: the address of anintto get how many faces were drawn, like&n, or NULL.
Returns how many leaves (pieces of the level) were drawn.
leveldraw
void leveldraw(int level)
Draws all of the level. With a graphics card this is quick too, since the card keeps the whole level.
level: the level to draw.
leveldrawabove
void leveldrawabove(int level, double y)
Draws only the part of the level above a height. Use it in a levelviewfn, to leave out what's under the water.
level: the level to draw.y: the height, in the level's units; only what's above it is drawn.
leveldrawgpu
void leveldrawgpu(int level)
Draws all of the level with the graphics chip's camera, viewport and fog (from <macawgpu.h>) instead of camera3d's.
level: the level to draw.
leveldrawgpuabove
void leveldrawgpuabove(int level, double y)
Draws the part of the level above a height, with the graphics chip's camera.
level: the level to draw.y: the height, in the level's units; only what's above it is drawn.
Bumping into it
These work on a built level. Water isn't solid, so they go straight through it.
leveltracebox
double leveltracebox(int level, double ax, double ay, double az, double bx, double by, double bz, double hx, double hy, double hz, double *nx, double *ny, double *nz, int *hit)
Moves a box from one place towards another and tells you how far it gets before it hits something. Use it to move a player or a ball: it stops just short of the wall.
level: the level to move through.ax: x of the box's middle where it starts.ay: y of the box's middle where it starts.az: z of the box's middle where it starts.bx: x of where the box's middle is going.by: y of where the box's middle is going.bz: z of where the box's middle is going.hx: half the box's width along x (less than 0 counts as 0).hy: half the box's height.hz: half the box's depth along z.nx: the address of adoublefor x of the direction the thing it hit faces, or NULL.ny: the address of adoublefor y of that direction, or NULL.nz: the address of adoublefor z of that direction, or NULL.hit: the address of anintto get 1 if it hit something and 0 if not, or NULL.
Returns how far it got, from 0 (not at all) to 1 (all the way).
leveltrace
double leveltrace(int level, double x0, double y0, double z0, double x1, double y1, double z1)
Follows a line from one point to another and tells you how far it gets before it hits something. Use it to see whether one place can see another.
level: the level to look through.x0: x of where the line starts.y0: y of where the line starts.z0: z of where the line starts.x1: x of where the line ends.y1: y of where the line ends.z1: z of where the line ends.
Returns how far along it got, from 0 to 1, where 1 means it hit nothing.
levelraycast
double levelraycast(int level, double x, double y, double z, double dx, double dy, double dz)
Sends a ray from a point in a direction and finds where it first goes into a brush. It tries every brush, so it works straight after building. A ray that starts inside a brush doesn't count that one.
level: the level to look through.x: x of where the ray starts.y: y of where the ray starts.z: z of where the ray starts.dx: how far the ray goes along x each step.dy: how far the ray goes along y each step.dz: how far the ray goes along z each step.
Returns t, so the spot it hits is x + t * dx, y + t * dy, z + t * dz, or -1 if it hits nothing. If the direction is one unit long, t is the distance.
levelboxsolid
int levelboxsolid(int level, double x0, double y0, double z0, double x1, double y1, double z1)
Tells you whether a box touches anything solid. The corners can be given in either order.
level: the level to look in.x0: x of one corner of the box.y0: y of that corner.z0: z of that corner.x1: x of the opposite corner.y1: y of the opposite corner.z1: z of the opposite corner.
Returns 1 if the box touches something solid, or 0 if it's in open space.
levelboxinside
int levelboxinside(int level, double x, double y, double z, double hx, double hy, double hz)
Tells you whether a box is inside a brush, by more than just touching it. Use it to check a player hasn't ended up stuck in a wall.
level: the level to look in.x: x of the box's middle.y: y of the box's middle.z: z of the box's middle.hx: half the box's width along x.hy: half the box's height.hz: half the box's depth along z.
Returns 1 if the box is inside something, or 0 if not.
Water
In Brushwork you can make brushes into water. Water isn't solid, and its top is a surface that reflects. A built level has a list of water surfaces, which you draw after the level. Each needs its reflection drawn first, with waterreflect, or baked once with waterbake.
watercount
int watercount(int level)
Tells you how many water surfaces a level has to draw: those built from its water brushes, and any you've added with newwater.
level: the level to ask about.
Returns how many water surfaces there are (they count from 0).
newwater
int newwater(int level, double x0, double z0, double x1, double z1, double y)
Adds a water surface of your own: a flat rectangle at a height. buildlevel makes the list again from the level's table, so add yours after building.
level: the level to add it to.x0: x of one corner.z0: z of that corner.x1: x of the opposite corner.z1: z of the opposite corner.y: the water's height.
Returns the new water's number, or -1 if one of the numbers wasn't a proper number.
waterinfo
void waterinfo(int level, int i, double *x0, double *z0, double *x1, double *z1, double *y)
Gives where a water surface is.
level: the level it's in.i: which water, from 0.x0: the address of adoublefor its smallest x, or NULL.z0: the address of adoublefor its smallest z, or NULL.x1: the address of adoublefor its largest x, or NULL.z1: the address of adoublefor its largest z, or NULL.y: the address of adoublefor its height, or NULL.
waterreflect
void waterreflect(int level, int i, const levelcam *cam, levelviewfn draw, void *user)
Draws a water's live reflection: the level is drawn again from a camera mirrored under the water, into the water's own picture. Call it before you clear the screen and draw the scene, then waterdraw after. It does nothing if the water's reflections are off.
level: the level the water's in.i: which water, from 0.cam: the camera you're looking from, alevelcam(see The structs).draw: your function that draws the mirrored view, or NULL to draw just the level.user: any pointer you like, passed todrawas itsuser; NULL is fine.
waterdraw
void waterdraw(int level, int i, const levelcam *cam, double t, const char *how)
Draws a water surface, with ripples and its reflection mixed in. Call it after you've drawn the level, with the same camera.
level: the level the water's in.i: which water, from 0.cam: the camera you're looking from, alevelcam.t: the time in seconds, which moves the ripples and drips (time()will do).how: NULL for the live reflection if there is one,"plain"for just the surface, or"baked"for the baked one.
waterbake
int waterbake(int level, int i, levelviewfn draw, void *user)
Bakes a water's reflection once, so it doesn't have to be drawn every frame. Each call draws one of six views from just above the middle of the water; keep calling it until it returns 1. Things that move won't show in a baked reflection.
level: the level the water's in.i: which water, from 0.draw: your function that draws each view, or NULL to draw just the level.user: any pointer you like, passed todrawas itsuser; NULL is fine.
Returns 1 once it's done (or once it's clear it can't be baked), or 0 while there are views left.
waterbaked
int waterbaked(int level, int i)
Tells you whether a water's reflection has been baked.
level: the level the water's in.i: which water, from 0.
Returns 1 if it's baked, 0 if not yet, or -1 if it can't be (the graphics card has no cube maps).
waterreflections
int waterreflections(int level, int i, int on)
Turns a water's reflection on or off, or asks whether it's on. With it off, the water is a plain sheet, which is quicker on a slow computer.
level: the level the water's in.i: which water, from 0.on: 1 to turn reflections on, 0 to turn them off, or -1 just to ask.
Returns 1 if reflections are on now, or 0 if they're off.
watercamera
void watercamera(const levelcam *cam)
Points the graphics chip's camera the same way as camera3d, so gpu_ drawing in a reflection lines up with the level. It also makes clockwise triangles the front ones.
cam: the camera to match, alevelcam.
Reflection probes
A shiny surface reflects the nearest reflection probe: a point in the level whose view all round is baked into a cube map (six square pictures, one each way). Probes need a graphics card with cube maps; without one, shiny surfaces are drawn as they are. A probe is a number of its own, not a level.
bakeprobes
int bakeprobes(int level)
Bakes any of a level's own probes that aren't baked yet, a little at a time. Call it once a frame until it returns 1; each call draws one of a probe's six views, so it never holds things up. If nothing in the level is shiny, there's nothing to do.
level: the level whose probes to bake.
Returns 1 once all are done (or there's nothing to bake), or 0 while there's more to do.
levelprobelimit
int levelprobelimit(int level, int n)
Sets how many probes may be on the graphics card at once, the ones nearest the camera, or asks. Each takes about 400 KB of the card's memory.
level: a built level.n: how many, from 1 to 64 (more counts as 64), or 0 to ask.
Returns the limit now.
probecount
int probecount(int level)
Tells you how many probes a built level has.
level: the level to ask about.
Returns how many probes there are (0 before it's built).
probeat
int probeat(int level, int i)
Gives one of a level's probes as a probe number, for the calls below.
level: the level it's in.i: which probe, from 0.
Returns the probe's number (the same one each time you ask for that probe).
newprobe
int newprobe(double x, double y, double z, int size)
Makes a probe of your own at a place. Bake it with probebake, then give its cube map to a level with levelsetprobes.
x: x of where it is.y: y of where it is (eye height is a good choice).z: z of where it is.size: how many pixels across each of its six pictures is, from 8 to 256 (0 or less: 128).
Returns the probe's number, or 0 if a place wasn't a proper number.
probepos
void probepos(int probe, double *x, double *y, double *z)
Gives where a probe is.
probe: the probe's number.x: the address of adoublefor its x, or NULL.y: the address of adoublefor its y, or NULL.z: the address of adoublefor its z, or NULL.
probebake
int probebake(int probe, levelviewfn draw, void *user, int level)
Bakes a probe, drawing one of its six views each call. Keep calling it until it returns 1.
probe: the probe's number.draw: your function that draws each view, or NULL to draw justlevel.user: any pointer you like, passed todrawas itsuser; NULL is fine.level: a built level to find the walls round the probe in (and to draw ifdrawis NULL), or 0 for none.
Returns 1 once it's done (or it can't be baked), or 0 while there are views left.
probebaked
int probebaked(int probe)
Tells you whether a probe has been baked.
probe: the probe's number.
Returns 1 if it's baked, 0 if not yet, or -1 if it can't be (the graphics card has no cube maps).
probeenv
int probeenv(int probe)
Gives a baked probe's cube map. It's the same kind of number <macawgpu.h>'s gpu_envmap gives, so gpu_envpixels and gpu_envmapbytes can keep it as bytes and make it again.
probe: the probe's number.
Returns the cube map's number, or 0 if the probe isn't baked yet.
levelsetprobes
void levelsetprobes(int level, const int *envs, int n)
Tells a built level which cube maps its shiny surfaces reflect. Each shiny face uses the nearest one in front of it, and prefers one in the same room.
level: the level.envs: an array of cube map numbers (fromprobeenv); 0s in it are skipped. NULL takes them all away.n: how many numbers are inenvs, up to 64 (0 takes them all away).
levelprobedata
int levelprobedata(int level, void *buf, int size)
Gives a level's baked probes as the bytes of a .prb file, for you to save. Call it with NULL first to find out how big a buffer you need.
level: the level.buf: where the bytes go, or NULL to only ask how many there are.size: how many bytesbufholds; no more than that are written.
Returns how many bytes there are in all, or 0 if none of its probes is baked.
applylevelprobes
int applylevelprobes(int level, const void *data, int count)
Gives a built level's probes their cube maps from a .prb file's bytes, so they don't need baking again.
level: a built level.data: the bytes, aslevelprobedatagave them or as read from the.prbfile.count: how many bytes are atdata.
Returns 1 if every probe got its cube map, or 0 if any didn't.
What's in a level
These read the level's table, so they work before it's built too.
levelstart
void levelstart(int level, double *x, double *y, double *z, double *angle)
Gives where the player starts: the player start's feet, and which way it faces. A level with no start gives 0, 2, 0 and an angle of 0.
level: the level.x: the address of adoublefor x, or NULL.y: the address of adoublefor y (where the feet are), or NULL.z: the address of adoublefor z, or NULL.angle: the address of adoublefor which way it faces, in degrees, or NULL.
levellightcount
int levellightcount(int level)
Tells you how many lamps and area lights a level has.
level: the level.
Returns how many lights there are.
levellight
int levellight(int level, int i, levellightinfo *light)
Gives one of a level's lamps or area lights, with the defaults filled in for what the level doesn't say.
level: the level.i: which light, from 0.light: alevellightinfoto fill in (see The structs), or NULL just to check it's there.
Returns 1 if there's an i'th light, or 0 if not.
levelwatercount
int levelwatercount(int level)
Tells you how many water brushes a level's table has.
level: the level.
Returns how many water surfaces the table has.
levelwater
int levelwater(int level, int i, double *x0, double *z0, double *x1, double *z1, double *y)
Gives where one of the table's water surfaces is: the top of a water brush (a shaped one gives the box round it).
level: the level.i: which water, from 0.x0: the address of adoublefor its smallest x, or NULL.z0: the address of adoublefor its smallest z, or NULL.x1: the address of adoublefor its largest x, or NULL.z1: the address of adoublefor its largest z, or NULL.y: the address of adoublefor its height (the brush's top), or NULL.
Returns 1 if there's an i'th water, or 0 if not.
levelprobecount
int levelprobecount(int level)
Tells you how many probe entities a level's table has.
level: the level.
Returns how many probes the table has.
levelprobe
int levelprobe(int level, int i, double *x, double *y, double *z)
Gives where one of the table's probes is.
level: the level.i: which probe, from 0.x: the address of adoublefor its x, or NULL.y: the address of adoublefor its y, or NULL.z: the address of adoublefor its z, or NULL.
Returns 1 if there's an i'th probe, or 0 if not.
Entities
Each entity has a class, its kind, such as "pickup" or "start", and fields with values. These calls read a level's entities of one class, with the class's defaults filled in for fields the level doesn't give. Give the class as NULL for every entity, in the level's order. A field reads as a number or as text, whichever it is.
levelentitycount
int levelentitycount(int level, const char *class_)
Tells you how many entities of a class a level has.
level: the level.class_: the class, like"pickup", or NULL for every entity.
Returns how many there are.
levelentity
int levelentity(int level, const char *class_, int i, double *x, double *y, double *z)
Gives where an entity is.
level: the level.class_: the class, or NULL for every entity.i: which one of them, from 0.x: the address of adoublefor its x, or NULL.y: the address of adoublefor its y, or NULL.z: the address of adoublefor its z, or NULL.
Returns 1 if there's an i'th one, or 0 if not.
levelentityhas
int levelentityhas(int level, const char *class_, int i, const char *field)
Tells you whether an entity has a field, and what kind of value it holds.
level: the level.class_: the class, or NULL for every entity.i: which one of them, from 0.field: the field's name, like"value".
Returns 0 if there's no such field, 1 for a number, 2 for text, or 3 for true or false.
levelentitynum
double levelentitynum(int level, const char *class_, int i, const char *field)
Gives an entity's field as a number. Text that's a number reads as that number, true as 1 and false as 0.
level: the level.class_: the class, or NULL for every entity.i: which one of them, from 0.field: the field's name.
Returns the field's value, or 0 if there's no such field (or it isn't a number).
levelentitytext
int levelentitytext(int level, const char *class_, int i, const char *field, char *buf, int size)
Gives an entity's field as text. Numbers come out as a level file writes them, and true or false as "true" or "false".
level: the level.class_: the class, or NULL for every entity.i: which one of them, from 0.field: the field's name.buf: where the text goes, achararray.size: how many bytesbufholds.
Returns the length of the text, or 0 if there's no such field.
levelentityfield
int levelentityfield(int level, const char *class_, int i, int k, char *buf, int size)
Gives the name of one of an entity's fields, so you can go through them all. They come in alphabetical order, and "class" is one of them.
level: the level.class_: the class, or NULL for every entity.i: which one of them, from 0.k: which field, from 0.buf: where the field's name goes, achararray.size: how many bytesbufholds.
Returns the length of the name, or 0 once there are no more fields.
Kinds of entity
These tell you about the classes a level can have: Macaw OS's own (light, arealight, start, probe), the generic ones (marker, pickup, enemy, trigger, sound, sign) and a game's own, from an entities.lua in the level's folder or a folder above it. Where a call takes classes, you can give it a level's number for the level's own classes, or a number from entityclasses.
entityclasses
int entityclasses(const char *path)
Finds the classes a level at a place can have, reading the game's entities.lua if there is one. The level doesn't need to exist yet.
path: where the level is (or would be), like"/home/mygame/levels/one.lvl".
Returns a number for that set of classes, or 0 if they couldn't be found.
entityclasscount
int entityclasscount(int classes)
Tells you how many classes there are in a set.
classes: a set of classes fromentityclasses, or a level's number.
Returns how many classes there are.
entityclassname
int entityclassname(int classes, int i, char *buf, int size)
Gives the name of one class in a set: Macaw OS's own first, then the game's, then the generic ones.
classes: a set of classes fromentityclasses, or a level's number.i: which class, from 0.buf: where the name goes, achararray.size: how many bytesbufholds.
Returns the length of the name, or 0 once there are no more.
entityclassinfo
int entityclassinfo(int classes, const char *name, const char *what, char *buf, int size)
Gives one thing about a class, as text. A class nobody describes comes back as a plain grey box marked "unknown".
classes: a set of classes fromentityclasses, or a level's number.name: the class's name, like"pickup".what:"label","about","colour","shape","size"or"float"; or"system","generic","game"or"unknown", which give"true"if it's that kind.buf: where the text goes, achararray.size: how many bytesbufholds.
Returns the length of the text, or 0 if there's nothing (so 0 for a kind it isn't).
entityclassfieldcount
int entityclassfieldcount(int classes, const char *name)
Tells you how many fields a class describes.
classes: a set of classes fromentityclasses, or a level's number.name: the class's name.
Returns how many fields it has (0 for a class nobody describes).
entityclassfield
int entityclassfield(int classes, const char *name, int k, char *fname, int fsize, char *type, int tsize, char *def, int dsize)
Gives one of a class's fields: its name, its type and its default, each as text.
classes: a set of classes fromentityclasses, or a level's number.name: the class's name.k: which field, from 0.fname: where the field's name goes, achararray.fsize: how many bytesfnameholds.type: where its type goes:"number","text","bool","choice","colour"or"angle".tsize: how many bytestypeholds.def: where its default goes, as text (true or false as"true"or"false").dsize: how many bytesdefholds.
Returns 1 if there's a k'th field, or 0 if not.
Building from code: brushes
These change a level's table. Call buildlevel afterwards to see the changes. A box's six faces, in order, are -x, +x, -y, +y, -z and +z (west, east, bottom, top, south, north), and a texture is a built-in name like "brick" or a .pxl picture's path.
levelbrushcount
int levelbrushcount(int level)
Tells you how many brushes a level has.
level: the level.
Returns how many brushes there are.
leveladdbox
int leveladdbox(int level, double x0, double y0, double z0, double x1, double y1, double z1, const char **tex)
Adds a box-shaped brush, from one corner to the opposite one. The corners can be given in either order.
level: the level to add it to.x0: x of one corner.y0: y of that corner.z0: z of that corner.x1: x of the opposite corner.y1: y of the opposite corner.z1: z of the opposite corner.tex: an array of six texture names, one a face in the order above; NULL, or a NULL name, means"stone".
Returns the new brush's number, or -1 if a corner wasn't a proper number.
leveladdshape
int leveladdshape(int level, const float *planes, int n, const char **tex)
Adds a convex brush of any shape, such as a wedge or a ramp, made of flat sides (planes). The brush is the space inside all of them.
level: the level to add it to.planes: fourfloats for each plane,nx ny nz d; inside is wherenx*x + ny*y + nz*z <= d, so the normal points out.n: how many planes, from 4 to 320.tex: an array ofntexture names, one a plane; NULL, or a NULL name, means"stone".
Returns the new brush's number, or -1 if it couldn't be added (too few planes, or a bad one).
levelremovebrush
void levelremovebrush(int level, int b)
Takes a brush out of the level. The brushes after it move down one number.
level: the level.b: which brush, from 0.
levelbrushbox
int levelbrushbox(int level, int b, double *x0, double *y0, double *z0, double *x1, double *y1, double *z1)
Gives a brush's corners: a box's own, or the box round a shaped brush.
level: the level.b: which brush, from 0.x0: the address of adoublefor the smallest x, or NULL.y0: the address of adoublefor the smallest y, or NULL.z0: the address of adoublefor the smallest z, or NULL.x1: the address of adoublefor the largest x, or NULL.y1: the address of adoublefor the largest y, or NULL.z1: the address of adoublefor the largest z, or NULL.
Returns 1 for a box, 2 for a shaped brush, or 0 if there's no such brush.
levelbrushtexture
void levelbrushtexture(int level, int b, int face, const char *name)
Changes the texture on one face of a brush.
level: the level.b: which brush, from 0.face: which face, from 0: a box's side in the order above, or a shape's plane.name: the texture's name; NULL means"stone".
levelbrushwater
void levelbrushwater(int level, int b, int on)
Makes a brush water or solid again. Water isn't solid, and its top is a reflecting surface.
level: the level.b: which brush, from 0.on: 1 to make it water, or 0 to make it solid.
levelbrushglow
void levelbrushglow(int level, int b, int face, double strength, const char *colour)
Makes a face of a brush glow. A glowing face lights the level when its light is baked.
level: the level.b: which brush, from 0.face: which face, from 0.strength: how strongly it glows; 0 or less stops it glowing.colour: its colour as text, like"#ff8800"; NULL means white.
levelbrushshine
void levelbrushshine(int level, int b, int face, double shine)
Makes a brush, or one face of it, shiny, so it reflects the nearest probe.
level: the level.b: which brush, from 0.face: which face, from 0, or -1 for the whole brush (which clears the faces' own shine).shine: how shiny, from 0 (not at all) to 1 (a mirror).
Building from code: entities and settings
leveladdentity
int leveladdentity(int level, const char *class_, double x, double y, double z)
Adds an entity of a class at a place. Give it fields with the calls below.
level: the level.class_: its class, like"pickup"or"light".x: x of where it is.y: y of where it is.z: z of where it is.
Returns the entity's number, in the level's order (as levelentity counts with a NULL class), or -1 if the class was empty or a place wasn't a proper number.
levelremoveentity
void levelremoveentity(int level, int e)
Takes an entity out of the level. The entities after it move down one number.
level: the level.e: which entity, from 0, in the level's order.
levelmoveentity
void levelmoveentity(int level, int e, double x, double y, double z)
Moves an entity to a new place.
level: the level.e: which entity, from 0, in the level's order.x: x of the new place.y: y of the new place.z: z of the new place.
levelentitysetnum
void levelentitysetnum(int level, int e, const char *field, double v)
Sets one of an entity's fields to a number.
level: the level.e: which entity, from 0, in the level's order.field: the field's name, like"bright".v: the number.
levelentitysettext
void levelentitysettext(int level, int e, const char *field, const char *text)
Sets one of an entity's fields to text, or takes the field away.
level: the level.e: which entity, from 0, in the level's order.field: the field's name, like"colour".text: the text, or NULL to take the field away.
levelentitysetbool
void levelentitysetbool(int level, int e, const char *field, int v)
Sets one of an entity's fields to true or false.
level: the level.e: which entity, from 0, in the level's order.field: the field's name, like"once".v: 1 (or anything not 0) for true, 0 for false.
levelsetting
double levelsetting(int level, const char *name)
Gives one of a level's number settings: "ambient" (the light everywhere), "bounce" (how much light bounces), "luxel" (the size of a patch of baked light) or "skylight" (how strong the sky's light is).
level: the level.name: the setting's name.
Returns the setting's value, or 0 if the level doesn't have it.
levelsettingtext
int levelsettingtext(int level, const char *name, char *buf, int size)
Gives one of a level's settings as text, such as "sky", the name of the sky round it.
level: the level.name: the setting's name.buf: where the text goes, achararray.size: how many bytesbufholds.
Returns the length of the text, or 0 if the level doesn't have that setting.
levelsetsetting
void levelsetsetting(int level, const char *name, double v)
Sets one of a level's number settings. savelevel keeps "ambient", "bounce", "luxel" and "skylight".
level: the level.name: the setting's name.v: its new value (something that isn't a proper number takes the setting away).
levelsetsettingtext
void levelsetsettingtext(int level, const char *name, const char *text)
Sets one of a level's settings to text, such as "sky".
level: the level.name: the setting's name.text: its new value, or NULL to take the setting away.
Skies and textures
levelskies
int levelskies(int i, char *buf, int size)
Gives the name of one of the skies there are, in alphabetical order, so you can list them.
i: which sky, from 0.buf: where the name goes, achararray.size: how many bytesbufholds.
Returns the length of the name, or 0 once there are no more.
levelsky
int levelsky(const char *name, int *pictures, double *r, double *g, double *b)
Gives a sky's six pictures, for levelsetsky, and its average colour.
name: the sky's name, like"cloudy".pictures: an array of sixints for its pictures' numbers (px nx py ny pz nz), or NULL.r: the address of adoublefor the red in its colour, 0 to 1, or NULL.g: the address of adoublefor the green, 0 to 1, or NULL.b: the address of adoublefor the blue, 0 to 1, or NULL.
Returns 1 if there's a sky of that name, or 0 if not.
leveltexture
int leveltexture(const char *name)
Gives the picture for a texture name, to draw with yourself.
name: a built-in texture name, or a.pxlpicture's path; NULL means"stone".
Returns the picture's number. A name it doesn't know gives the stone picture.
leveltexturename
int leveltexturename(int i, char *buf, int size)
Gives the name of one of the built-in textures, so you can list them.
i: which texture, from 0.buf: where the name goes, achararray.size: how many bytesbufholds.
Returns the length of the name, or 0 once there are no more.
Baking light and the built level
Baking light works out how the level's lamps, glowing faces and sky light every surface, bounces and shadows included, and keeps the result. It takes a while, so it's done a step at a time. These calls need a built level.
levelbake
int levelbake(int level, const levellightinfo *lights, int n, double ambient, double bounce, double softness)
Starts baking a level's light. Then call levelbakestep until it's done.
level: the level to bake.lights: an array oflevellightinfo(see The structs), or NULL for the level's own lamps and area lights.n: how many lights are inlights.ambient: the light everywhere, even in shadow; less than 0 for the level's setting (or 0.08).bounce: how much light bounces off surfaces; less than 0 for the level's setting (or 1).softness: the size of lamps that don't give one, so how soft their shadows are; less than 0 for 0.35.
Returns 1 if baking has started, or 0 if it couldn't (levelerror says why, such as a level too big to light).
levelbakestep
int levelbakestep(int level, double ms, double *progress, char *what, int size)
Bakes for a little while. Call it once a frame until it returns 1; then the level is lit.
level: the level being baked.ms: how long to bake for, in milliseconds (0 or less means 30).progress: the address of adoublefor how far it's got, from 0 to 1, or NULL.what: where text saying what it's doing goes (like"bouncing light"), or NULL.size: how many byteswhatholds.
Returns 1 once the baking is done, or 0 while there's more to do.
levellightdata
int levellightdata(int level, void *buf, int size)
Gives a level's baked light as bytes, to save in its .lit file. Call it with NULL first to find out how big a buffer you need.
level: the level.buf: where the bytes go, or NULL to only ask how many there are.size: how many bytesbufholds; no more than that are written.
Returns how many bytes there are in all, or 0 if the level isn't baked.
levelsetlight
int levelsetlight(int level, const void *data, int n)
Puts baked light back on a level, from bytes levellightdata gave or a .lit file holds.
level: the level.data: the bytes.n: how many bytes are atdata.
Returns 1 if the light went on, or 0 if it was baked for a different level.
levelunbake
void levelunbake(int level)
Takes a level's baked light off, back to plain shading.
level: the level.
levelsetsky
void levelsetsky(int level, const int *pictures)
Puts a sky round a level, from six square pictures, or takes it away. Faces with the "sky" texture show it. buildlevel already puts on the sky the level's "sky" setting names.
level: the level.pictures: an array of six picture numbers (px nx py ny pz nz), likelevelskygives, or NULL for no sky.
levelfacecount
int levelfacecount(int level)
Tells you how many faces the built level has. Building cuts brushes into faces, so this isn't the same as six times the brushes.
level: the level.
Returns how many faces there are.
levelface
int levelface(int level, int i, float *xyz, int max, int *tex, double *nx, double *ny, double *nz)
Gives one face of the built level: its corners, its texture and which way it faces. The corners go anticlockwise, seen from the front.
level: the level.i: which face, from 0.xyz: an array offloats for the corners, three (x, y, z) for each, or NULL.max: how many cornersxyzhas room for (so it holds3 * maxfloats).tex: the address of anintfor its texture's number, from 0, or NULL.nx: the address of adoublefor x of the way it faces, or NULL.ny: the address of adoublefor y of the way it faces, or NULL.nz: the address of adoublefor z of the way it faces, or NULL.
Returns how many corners the face has (even if more than max), or 0 if there's no face i.
levelstat
double levelstat(int level, const char *name)
Gives a number about the built level, such as "faces", "leaves", "portals", "luxels" (patches of baked light), "baked" (1 if it's lit), "drawn" (faces drawn last time), "shiny" (shiny faces) or "probes" (cube maps it's been given).
level: the level.name: the name of the number you want.
Returns that number, or 0 for a name there isn't.