move octa apis to octa header

master
Daniel Kolesa 2020-05-02 20:21:42 +02:00
parent 26ce5f8423
commit c053bcbe03
10 changed files with 139 additions and 114 deletions

View File

@ -159,60 +159,6 @@ extern void endtimer(timer *t);
// renderextras
extern void render3dbox(vec &o, float tofloor, float toceil, float xradius, float yradius = 0);
// octa
extern cube *newcubes(uint face = F_EMPTY, int mat = MAT_AIR);
extern cubeext *growcubeext(cubeext *ext, int maxverts);
extern void setcubeext(cube &c, cubeext *ext);
extern cubeext *newcubeext(cube &c, int maxverts = 0, bool init = true);
extern void getcubevector(cube &c, int d, int x, int y, int z, ivec &p);
extern void setcubevector(cube &c, int d, int x, int y, int z, const ivec &p);
extern int familysize(const cube &c);
extern void freeocta(cube *c);
extern void discardchildren(cube &c, bool fixtex = false, int depth = 0);
extern void optiface(uchar *p, cube &c);
extern void validatec(cube *c, int size = 0);
extern bool isvalidcube(const cube &c);
extern ivec lu;
extern int lusize;
extern cube &lookupcube(const ivec &to, int tsize = 0, ivec &ro = lu, int &rsize = lusize);
extern const cube *neighbourstack[32];
extern int neighbourdepth;
extern const cube &neighbourcube(const cube &c, int orient, const ivec &co, int size, ivec &ro = lu, int &rsize = lusize);
extern void resetclipplanes();
extern int getmippedtexture(const cube &p, int orient);
extern void forcemip(cube &c, bool fixtex = true);
extern bool subdividecube(cube &c, bool fullcheck=true, bool brighten=true);
extern int faceconvexity(const ivec v[4]);
extern int faceconvexity(const ivec v[4], int &vis);
extern int faceconvexity(const vertinfo *verts, int numverts, int size);
extern int faceconvexity(const cube &c, int orient);
extern void calcvert(const cube &c, const ivec &co, int size, ivec &vert, int i, bool solid = false);
extern void calcvert(const cube &c, const ivec &co, int size, vec &vert, int i, bool solid = false);
extern uint faceedges(const cube &c, int orient);
extern bool collapsedface(const cube &c, int orient);
extern bool touchingface(const cube &c, int orient);
extern bool flataxisface(const cube &c, int orient);
extern bool collideface(const cube &c, int orient);
extern void genclipbounds(const cube &c, const ivec &co, int size, clipplanes &p);
extern int genclipplane(const cube &c, int i, vec *v, plane *clip);
extern void genclipplanes(const cube &c, const ivec &co, int size, clipplanes &p, bool collide = true, bool noclip = false);
extern bool visibleface(const cube &c, int orient, const ivec &co, int size, ushort mat = MAT_AIR, ushort nmat = MAT_AIR, ushort matmask = MATF_VOLUME);
extern int classifyface(const cube &c, int orient, const ivec &co, int size);
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);
extern int visibleorient(const cube &c, int orient);
extern void genfaceverts(const cube &c, int orient, ivec v[4]);
extern int calcmergedsize(int orient, const ivec &co, int size, const vertinfo *verts, int numverts);
extern void invalidatemerges(cube &c, const ivec &co, int size, bool msg);
extern void calcmerges();
extern int mergefaces(int orient, facebounds *m, int sz);
extern void mincubeface(const cube &cu, int orient, const ivec &o, int size, const facebounds &orig, facebounds &cf, ushort nmat = MAT_AIR, ushort matmask = MATF_VOLUME);
extern void remip();
static inline cubeext &ext(cube &c)
{
return *(c.ext ? c.ext : newcubeext(c));
}
// renderlights
#include "renderlights.hh"

View File

@ -1,4 +1,5 @@
#include "blend.hh"
#include "octa.hh"
#include "texture.hh"
#include "engine.hh"

View File

@ -1,5 +1,6 @@
// core world management routines
#include "octa.hh"
#include "world.hh"
#include "engine.hh"
@ -107,6 +108,8 @@ void freecubeext(cube &c)
}
}
static int getmippedtexture(const cube &p, int orient);
void discardchildren(cube &c, bool fixtex, int depth)
{
c.material = MAT_AIR;
@ -308,7 +311,7 @@ const cube &neighbourcube(const cube &c, int orient, const ivec &co, int size, i
////////// (re)mip //////////
int getmippedtexture(const cube &p, int orient)
static int getmippedtexture(const cube &p, int orient)
{
cube *c = p.children;
int d = dimension(orient), dc = dimcoord(orient), texs[4] = { -1, -1, -1, -1 }, numtexs = 0;
@ -457,6 +460,8 @@ bool subdividecube(cube &c, bool fullcheck, bool brighten)
bool crushededge(uchar e, int dc) { return dc ? e==0 : e==0x88; }
static bool touchingface(const cube &c, int orient);
int visibleorient(const cube &c, int orient)
{
loopi(2)
@ -566,6 +571,8 @@ bool remip(cube &c, const ivec &co, int size)
return true;
}
static void calcmerges();
void remip()
{
remipprogress = 1;
@ -679,7 +686,7 @@ bool flataxisface(const cube &c, int orient)
return (face&0x0F0F0F0F) == 0x01010101*(face&0x0F);
}
bool collideface(const cube &c, int orient)
static bool collideface(const cube &c, int orient)
{
if(flataxisface(c, orient))
{
@ -691,7 +698,7 @@ bool collideface(const cube &c, int orient)
return true;
}
bool touchingface(const cube &c, int orient)
static bool touchingface(const cube &c, int orient)
{
uint face = c.faces[dimension(orient)];
return dimcoord(orient) ? (face&0xF0F0F0F0)==0x80808080 : (face&0x0F0F0F0F)==0;
@ -759,7 +766,7 @@ static inline void faceedges(const cube &c, int orient, uchar edges[4])
loopk(4) edges[k] = c.edges[faceedgesidx[orient][k]];
}
uint faceedges(const cube &c, int orient)
static uint faceedges(const cube &c, int orient)
{
union { uchar edges[4]; uint face; } u;
faceedges(c, orient, u.edges);
@ -903,7 +910,7 @@ static inline int clipfacevecs(const ivec2 *o, int numo, int cx, int cy, int siz
return r;
}
bool collapsedface(const cube &c, int orient)
static bool collapsedface(const cube &c, int orient)
{
int e0 = c.edges[faceedgesidx[orient][0]], e1 = c.edges[faceedgesidx[orient][1]],
e2 = c.edges[faceedgesidx[orient][2]], e3 = c.edges[faceedgesidx[orient][3]],
@ -1178,7 +1185,8 @@ int visibletris(const cube &c, int orient, const ivec &co, int size, ushort vmat
return 3;
}
void calcvert(const cube &c, const ivec &co, int size, ivec &v, int i, bool solid)
#if 0
static void calcvert(const cube &c, const ivec &co, int size, ivec &v, int i, bool solid = false)
{
if(solid) v = cubecoords[i]; else gencubevert(c, i, v);
// avoid overflow
@ -1186,8 +1194,9 @@ void calcvert(const cube &c, const ivec &co, int size, ivec &v, int i, bool soli
else v.div(8/size);
v.add(ivec(co).shl(3));
}
#endif
void calcvert(const cube &c, const ivec &co, int size, vec &v, int i, bool solid)
static void calcvert(const cube &c, const ivec &co, int size, vec &v, int i, bool solid = false)
{
if(solid) v = vec(cubecoords[i]); else gencubevert(c, i, v);
v.mul(size/8.0f).add(vec(co));
@ -1212,7 +1221,8 @@ void genclipbounds(const cube &c, const ivec &co, int size, clipplanes &p)
p.visible = 0x80;
}
int genclipplane(const cube &c, int orient, vec *v, plane *clip)
#if 0
static int genclipplane(const cube &c, int orient, vec *v, plane *clip)
{
int planes = 0, convex = faceconvexity(c, orient), order = convex < 0 ? 1 : 0;
const vec &v0 = v[fv[orient][order]], &v1 = v[fv[orient][order+1]], &v2 = v[fv[orient][order+2]], &v3 = v[fv[orient][(order+3)&3]];
@ -1221,6 +1231,7 @@ int genclipplane(const cube &c, int orient, vec *v, plane *clip)
if(v0!=v3 && v2!=v3 && (!planes || convex)) clip[planes++].toplane(v0, v2, v3);
return planes;
}
#endif
void genclipplanes(const cube &c, const ivec &co, int size, clipplanes &p, bool collide, bool noclip)
{
@ -1259,6 +1270,7 @@ void genclipplanes(const cube &c, const ivec &co, int size, clipplanes &p, bool
}
}
#if 0
static inline bool mergefacecmp(const facebounds &x, const facebounds &y)
{
if(x.v2 < y.v2) return true;
@ -1309,7 +1321,7 @@ static int mergeface(int orient, facebounds *m, int sz, facebounds &n)
return sz;
}
int mergefaces(int orient, facebounds *m, int sz)
static int mergefaces(int orient, facebounds *m, int sz)
{
quicksort(m, sz, mergefacecmp);
@ -1317,6 +1329,7 @@ int mergefaces(int orient, facebounds *m, int sz)
loopi(sz) nsz = mergeface(orient, m, nsz, m[i]);
return nsz;
}
#endif
struct cfkey
{
@ -1336,7 +1349,7 @@ static inline uint hthash(const cfkey &k)
return hthash(k.n)^k.offset^k.tex^k.orient^k.material;
}
void mincubeface(const cube &cu, int orient, const ivec &o, int size, const facebounds &orig, facebounds &cf, ushort nmat, ushort matmask)
static void mincubeface(const cube &cu, int orient, const ivec &o, int size, const facebounds &orig, facebounds &cf, ushort nmat = MAT_AIR, ushort matmask = MATF_VOLUME)
{
int dim = dimension(orient);
if(cu.children)
@ -1881,7 +1894,7 @@ void invalidatemerges(cube &c, const ivec &co, int size, bool msg)
invalidatemerges(c);
}
void calcmerges()
static void calcmerges()
{
genmergeprogress = 0;
genmerges();

View File

@ -368,4 +368,111 @@ enum
GENFACEVERTSXY(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1) \
GENFACEVERTSZ(x0,x1, y0,y1, z0,z1, c0,c1, r0,r1, d0,d1)
#endif
/* material flags and ids */
enum
{
MATF_INDEX_SHIFT = 0,
MATF_VOLUME_SHIFT = 2,
MATF_CLIP_SHIFT = 5,
MATF_FLAG_SHIFT = 8,
MATF_INDEX = 3 << MATF_INDEX_SHIFT,
MATF_VOLUME = 7 << MATF_VOLUME_SHIFT,
MATF_CLIP = 7 << MATF_CLIP_SHIFT,
MATF_FLAGS = 0xFF << MATF_FLAG_SHIFT
};
enum // cube empty-space materials
{
MAT_AIR = 0, // the default, fill the empty space with air
MAT_WATER = 1 << MATF_VOLUME_SHIFT, // fill with water, showing waves at the surface
MAT_LAVA = 2 << MATF_VOLUME_SHIFT, // fill with lava
MAT_GLASS = 3 << MATF_VOLUME_SHIFT, // behaves like clip but is blended blueish
MAT_NOCLIP = 1 << MATF_CLIP_SHIFT, // collisions always treat cube as empty
MAT_CLIP = 2 << MATF_CLIP_SHIFT, // collisions always treat cube as solid
MAT_GAMECLIP = 3 << MATF_CLIP_SHIFT, // game specific clip material
MAT_DEATH = 1 << MATF_FLAG_SHIFT, // force player suicide
MAT_NOGI = 2 << MATF_FLAG_SHIFT, // disable global illumination
MAT_ALPHA = 4 << MATF_FLAG_SHIFT // alpha blended
};
#define isliquid(mat) ((mat)==MAT_WATER || (mat)==MAT_LAVA)
#define isclipped(mat) ((mat)==MAT_GLASS)
#define isdeadly(mat) ((mat)==MAT_LAVA)
/* API */
void freeocta(cube *c);
cube *newcubes(uint face = F_EMPTY, int mat = MAT_AIR);
cubeext *growcubeext(cubeext *ext, int maxverts);
void setcubeext(cube &c, cubeext *ext);
cubeext *newcubeext(cube &c, int maxverts = 0, bool init = true);
void getcubevector(cube &c, int d, int x, int y, int z, ivec &p);
void setcubevector(cube &c, int d, int x, int y, int z, const ivec &p);
int familysize(const cube &c);
void discardchildren(cube &c, bool fixtex = false, int depth = 0);
void optiface(uchar *p, cube &c);
void validatec(cube *c, int size = 0);
bool isvalidcube(const cube &c);
extern ivec lu;
extern int lusize;
cube &lookupcube(const ivec &to, int tsize = 0, ivec &ro = lu, int &rsize = lusize);
extern const cube *neighbourstack[32];
extern int neighbourdepth;
const cube &neighbourcube(const cube &c, int orient, const ivec &co, int size, ivec &ro = lu, int &rsize = lusize);
void resetclipplanes();
void forcemip(cube &c, bool fixtex = true);
bool subdividecube(cube &c, bool fullcheck=true, bool brighten=true);
int faceconvexity(const ivec v[4]);
int faceconvexity(const ivec v[4], int &vis);
int faceconvexity(const vertinfo *verts, int numverts, int size);
int faceconvexity(const cube &c, int orient);
bool flataxisface(const cube &c, int orient);
void genclipbounds(const cube &c, const ivec &co, int size, clipplanes &p);
void genclipplanes(const cube &c, const ivec &co, int size, clipplanes &p, bool collide = true, bool noclip = false);
bool visibleface(const cube &c, int orient, const ivec &co, int size, ushort mat = MAT_AIR, ushort nmat = MAT_AIR, ushort matmask = MATF_VOLUME);
int classifyface(const cube &c, int orient, const ivec &co, int size);
int visibletris(const cube &c, int orient, const ivec &co, int size, ushort vmat = MAT_AIR, ushort nmat = MAT_ALPHA, ushort matmask = MAT_ALPHA);
int visibleorient(const cube &c, int orient);
void genfaceverts(const cube &c, int orient, ivec v[4]);
int calcmergedsize(int orient, const ivec &co, int size, const vertinfo *verts, int numverts);
void invalidatemerges(cube &c, const ivec &co, int size, bool msg);
void remip();
static inline cubeext &ext(cube &c)
{
return *(c.ext ? c.ext : newcubeext(c));
}
int lookupmaterial(const vec &o);
static inline bool insideworld(const vec &o)
{
extern int worldsize;
return o.x>=0 && o.x<worldsize && o.y>=0 && o.y<worldsize && o.z>=0 && o.z<worldsize;
}
static inline bool insideworld(const ivec &o)
{
extern int worldsize;
return uint(o.x)<uint(worldsize) && uint(o.y)<uint(worldsize) && uint(o.z)<uint(worldsize);
}
#endif /* ENGINE_OCTA_HH */

View File

@ -1,5 +1,6 @@
#include "blend.hh"
#include "material.hh"
#include "octa.hh"
#include "renderva.hh"
#include "texture.hh"
#include "world.hh"

View File

@ -3,6 +3,7 @@
// they "felt right", and have no basis in reality. Collision detection is simplistic but
// very robust (uses discrete steps at fixed fps).
#include "octa.hh"
#include "world.hh"
#include "engine.hh"

View File

@ -1,3 +1,5 @@
#include "octa.hh"
#include "engine.hh"
enum

View File

@ -1,6 +1,7 @@
// world.cpp: core map management stuff
#include "blend.hh"
#include "octa.hh"
#include "texture.hh"
#include "worldio.hh"
#include "world.hh"

View File

@ -1,6 +1,7 @@
// worldio.cpp: loading & saving of maps and savegames
#include "blend.hh"
#include "octa.hh"
#include "texture.hh"
#include "world.hh"
#include "worldio.hh"

View File

@ -6,39 +6,6 @@ extern int elapsedtime; // elapsed frame time
extern int totalmillis; // total elapsed time
extern int gamespeed, paused;
enum
{
MATF_INDEX_SHIFT = 0,
MATF_VOLUME_SHIFT = 2,
MATF_CLIP_SHIFT = 5,
MATF_FLAG_SHIFT = 8,
MATF_INDEX = 3 << MATF_INDEX_SHIFT,
MATF_VOLUME = 7 << MATF_VOLUME_SHIFT,
MATF_CLIP = 7 << MATF_CLIP_SHIFT,
MATF_FLAGS = 0xFF << MATF_FLAG_SHIFT
};
enum // cube empty-space materials
{
MAT_AIR = 0, // the default, fill the empty space with air
MAT_WATER = 1 << MATF_VOLUME_SHIFT, // fill with water, showing waves at the surface
MAT_LAVA = 2 << MATF_VOLUME_SHIFT, // fill with lava
MAT_GLASS = 3 << MATF_VOLUME_SHIFT, // behaves like clip but is blended blueish
MAT_NOCLIP = 1 << MATF_CLIP_SHIFT, // collisions always treat cube as empty
MAT_CLIP = 2 << MATF_CLIP_SHIFT, // collisions always treat cube as solid
MAT_GAMECLIP = 3 << MATF_CLIP_SHIFT, // game specific clip material
MAT_DEATH = 1 << MATF_FLAG_SHIFT, // force player suicide
MAT_NOGI = 2 << MATF_FLAG_SHIFT, // disable global illumination
MAT_ALPHA = 4 << MATF_FLAG_SHIFT // alpha blended
};
#define isliquid(mat) ((mat)==MAT_WATER || (mat)==MAT_LAVA)
#define isclipped(mat) ((mat)==MAT_GLASS)
#define isdeadly(mat) ((mat)==MAT_LAVA)
extern void lightent(extentity &e, float height = 8.0f);
extern void lightreaching(const vec &target, vec &color, vec &dir, bool fast = false, extentity *e = 0, float minambient = 0.4f);
@ -169,21 +136,6 @@ extern void conoutf(const char *s, ...) PRINTFARGS(1, 2);
extern void conoutf(int type, const char *s, ...) PRINTFARGS(2, 3);
extern void conoutfv(int type, const char *fmt, va_list args);
// octa
extern int lookupmaterial(const vec &o);
static inline bool insideworld(const vec &o)
{
extern int worldsize;
return o.x>=0 && o.x<worldsize && o.y>=0 && o.y<worldsize && o.z>=0 && o.z<worldsize;
}
static inline bool insideworld(const ivec &o)
{
extern int worldsize;
return uint(o.x)<uint(worldsize) && uint(o.y)<uint(worldsize) && uint(o.z)<uint(worldsize);
}
// main
extern void fatal(const char *s, ...) PRINTFARGS(1, 2);