Convert remaining files to pure Objective-C
FossilOrigin-Name: 12cac9666ac09097e06d34da46bf50d15c8571dea22fd2a6d8a1fad076999689
This commit is contained in:
parent
61bf59bbfc
commit
fd09d38b8c
17 changed files with 182 additions and 182 deletions
16
meson.build
16
meson.build
|
@ -1,17 +1,15 @@
|
||||||
project('Cube', ['c', 'objc', 'objcpp'],
|
project('Cube', ['c', 'objc'],
|
||||||
meson_version: '>=1.5.0',
|
meson_version: '>=1.5.0',
|
||||||
default_options: {
|
default_options: {
|
||||||
'optimization': '2'
|
'optimization': '2'
|
||||||
})
|
})
|
||||||
|
|
||||||
foreach lang : ['objc', 'objcpp']
|
add_global_arguments(
|
||||||
add_global_arguments(
|
[
|
||||||
[
|
'-fobjc-arc',
|
||||||
'-fobjc-arc',
|
'-fobjc-arc-exceptions'
|
||||||
'-fobjc-arc-exceptions'
|
],
|
||||||
],
|
language: 'objc')
|
||||||
language: lang)
|
|
||||||
endforeach
|
|
||||||
|
|
||||||
objfw_dep = dependency('objfw')
|
objfw_dep = dependency('objfw')
|
||||||
sdl_dep = dependency('SDL2')
|
sdl_dep = dependency('SDL2')
|
||||||
|
|
|
@ -30,8 +30,8 @@ initEntities()
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame /* = 0*/,
|
renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame, int numf,
|
||||||
int numf /* = 1*/, int basetime /* = 0*/, float speed /* = 10.0f*/)
|
int basetime, float speed)
|
||||||
{
|
{
|
||||||
rendermodel(mdlname, frame, numf, 0, 1.1f,
|
rendermodel(mdlname, frame, numf, 0, 1.1f,
|
||||||
OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false,
|
OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false,
|
||||||
|
|
24
src/init.m
Normal file
24
src/init.m
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#import "cube.h"
|
||||||
|
|
||||||
|
static void **queue;
|
||||||
|
static size_t queueCount;
|
||||||
|
|
||||||
|
void
|
||||||
|
enqueueInit(void (^init)(void))
|
||||||
|
{
|
||||||
|
queue = realloc(queue, (queueCount + 1) * sizeof(void *));
|
||||||
|
if (queue == NULL)
|
||||||
|
fatal(@"cannot allocate init queue");
|
||||||
|
|
||||||
|
queue[queueCount++] = (__bridge void *)init;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
processInitQueue(void)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < queueCount; i++)
|
||||||
|
((__bridge void (^)())queue[i])();
|
||||||
|
|
||||||
|
free(queue);
|
||||||
|
queueCount = 0;
|
||||||
|
}
|
24
src/init.mm
24
src/init.mm
|
@ -1,24 +0,0 @@
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#import "cube.h"
|
|
||||||
#import "protos.h"
|
|
||||||
|
|
||||||
static std::vector<void (^)(void)> *queue;
|
|
||||||
|
|
||||||
void
|
|
||||||
enqueueInit(void (^init)(void))
|
|
||||||
{
|
|
||||||
if (queue == NULL)
|
|
||||||
queue = new std::vector<void (^)(void)>();
|
|
||||||
|
|
||||||
queue->push_back(init);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
processInitQueue(void)
|
|
||||||
{
|
|
||||||
for (auto &init : *queue)
|
|
||||||
init();
|
|
||||||
|
|
||||||
queue->clear();
|
|
||||||
}
|
|
|
@ -29,30 +29,30 @@ executable('client',
|
||||||
'console.m',
|
'console.m',
|
||||||
'editing.m',
|
'editing.m',
|
||||||
'entities.m',
|
'entities.m',
|
||||||
'init.mm',
|
'init.m',
|
||||||
'menus.m',
|
'menus.m',
|
||||||
'monster.m',
|
'monster.m',
|
||||||
'physics.m',
|
'physics.m',
|
||||||
'rendercubes.m',
|
'rendercubes.m',
|
||||||
'renderextras.m',
|
'renderextras.m',
|
||||||
'rendergl.mm',
|
'rendergl.m',
|
||||||
'rendermd2.mm',
|
'rendermd2.m',
|
||||||
'renderparticles.mm',
|
'renderparticles.m',
|
||||||
'rendertext.mm',
|
'rendertext.m',
|
||||||
'rndmap.mm',
|
'rndmap.m',
|
||||||
'savegamedemo.mm',
|
'savegamedemo.m',
|
||||||
'server.m',
|
'server.m',
|
||||||
'serverbrowser.mm',
|
'serverbrowser.m',
|
||||||
'serverms.m',
|
'serverms.m',
|
||||||
'serverutil.m',
|
'serverutil.m',
|
||||||
'sound.m',
|
'sound.m',
|
||||||
'tools.m',
|
'tools.m',
|
||||||
'weapon.m',
|
'weapon.m',
|
||||||
'world.mm',
|
'world.m',
|
||||||
'worldio.mm',
|
'worldio.m',
|
||||||
'worldlight.mm',
|
'worldlight.m',
|
||||||
'worldocull.mm',
|
'worldocull.m',
|
||||||
'worldrender.mm',
|
'worldrender.m',
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
objfw_dep,
|
objfw_dep,
|
||||||
|
|
|
@ -252,8 +252,8 @@ lookuptexture(int tex, int *xs, int *ys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
setupworld()
|
gl_setupworld()
|
||||||
{
|
{
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
@ -281,7 +281,7 @@ renderstripssky()
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, skyoglid);
|
glBindTexture(GL_TEXTURE_2D, skyoglid);
|
||||||
|
|
||||||
const strip *items = (const strip *)strips.items;
|
const struct strip *items = strips.items;
|
||||||
size_t count = strips.count;
|
size_t count = strips.count;
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++)
|
||||||
if (items[i].tex == skyoglid)
|
if (items[i].tex == skyoglid)
|
||||||
|
@ -293,7 +293,7 @@ void
|
||||||
renderstrips()
|
renderstrips()
|
||||||
{
|
{
|
||||||
int lasttex = -1;
|
int lasttex = -1;
|
||||||
const strip *items = (const strip *)strips.items;
|
const struct strip *items = strips.items;
|
||||||
size_t count = strips.count;
|
size_t count = strips.count;
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
if (items[i].tex == skyoglid)
|
if (items[i].tex == skyoglid)
|
||||||
|
@ -319,9 +319,10 @@ void
|
||||||
addstrip(int tex, int start, int n)
|
addstrip(int tex, int start, int n)
|
||||||
{
|
{
|
||||||
if (strips == nil)
|
if (strips == nil)
|
||||||
strips = [[OFMutableData alloc] initWithItemSize:sizeof(strip)];
|
strips = [[OFMutableData alloc]
|
||||||
|
initWithItemSize:sizeof(struct strip)];
|
||||||
|
|
||||||
strip s = { .tex = tex, .start = start, .num = n };
|
struct strip s = { .tex = tex, .start = start, .num = n };
|
||||||
[strips addItem:&s];
|
[strips addItem:&s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +452,7 @@ gl_drawframe(int w, int h, float curfps)
|
||||||
(int)player1.pitch, (float)fov, w, h);
|
(int)player1.pitch, (float)fov, w, h);
|
||||||
finishstrips();
|
finishstrips();
|
||||||
|
|
||||||
setupworld();
|
gl_setupworld();
|
||||||
|
|
||||||
renderstripssky();
|
renderstripssky();
|
||||||
|
|
|
@ -108,7 +108,7 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
|
||||||
OFVector3D light = OFMakeVector3D(1, 1, 1);
|
OFVector3D light = OFMakeVector3D(1, 1, 1);
|
||||||
|
|
||||||
if (!OUTBORD(ix, iy)) {
|
if (!OUTBORD(ix, iy)) {
|
||||||
sqr *s = S(ix, iy);
|
struct sqr *s = S(ix, iy);
|
||||||
float ll = 256.0f; // 0.96f;
|
float ll = 256.0f; // 0.96f;
|
||||||
float of = 0.0f; // 0.1f;
|
float of = 0.0f; // 0.1f;
|
||||||
light.x = s->r / ll + of;
|
light.x = s->r / ll + of;
|
|
@ -10,9 +10,9 @@ struct particle {
|
||||||
OFVector3D o, d;
|
OFVector3D o, d;
|
||||||
int fade, type;
|
int fade, type;
|
||||||
int millis;
|
int millis;
|
||||||
particle *next;
|
struct particle *next;
|
||||||
};
|
};
|
||||||
particle particles[MAXPARTICLES], *parlist = NULL, *parempty = NULL;
|
struct particle particles[MAXPARTICLES], *parlist = NULL, *parempty = NULL;
|
||||||
bool parinit = false;
|
bool parinit = false;
|
||||||
|
|
||||||
VARP(maxparticles, 100, 2000, MAXPARTICLES - 500);
|
VARP(maxparticles, 100, 2000, MAXPARTICLES - 500);
|
||||||
|
@ -29,7 +29,7 @@ newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type)
|
||||||
parinit = true;
|
parinit = true;
|
||||||
}
|
}
|
||||||
if (parempty) {
|
if (parempty) {
|
||||||
particle *p = parempty;
|
struct particle *p = parempty;
|
||||||
parempty = p->next;
|
parempty = p->next;
|
||||||
p->o = *o;
|
p->o = *o;
|
||||||
p->d = *d;
|
p->d = *d;
|
||||||
|
@ -86,8 +86,8 @@ render_particles(int time)
|
||||||
|
|
||||||
int numrender = 0;
|
int numrender = 0;
|
||||||
|
|
||||||
for (particle *p, **pp = &parlist; p = *pp;) {
|
for (struct particle *p, **pp = &parlist; (p = *pp) != NULL;) {
|
||||||
parttype *pt = &parttypes[p->type];
|
struct parttype *pt = &parttypes[p->type];
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, pt->tex);
|
glBindTexture(GL_TEXTURE_2D, pt->tex);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
|
@ -67,7 +67,7 @@ perlinnoise_2D(float x, float y, int seedstep, float pers)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
perlinarea(const block *b, int scale, int seed, int psize)
|
perlinarea(const struct block *b, int scale, int seed, int psize)
|
||||||
{
|
{
|
||||||
srand(seed);
|
srand(seed);
|
||||||
seed = rnd(10000);
|
seed = rnd(10000);
|
||||||
|
@ -75,7 +75,7 @@ perlinarea(const block *b, int scale, int seed, int psize)
|
||||||
scale = 10;
|
scale = 10;
|
||||||
for (int x = b->x; x <= b->x + b->xs; x++) {
|
for (int x = b->x; x <= b->x + b->xs; x++) {
|
||||||
for (int y = b->y; y <= b->y + b->ys; y++) {
|
for (int y = b->y; y <= b->y + b->ys; y++) {
|
||||||
sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
|
if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
|
||||||
s->type = FHF;
|
s->type = FHF;
|
||||||
s->vdelta =
|
s->vdelta =
|
|
@ -19,41 +19,41 @@ bool demoloading = false;
|
||||||
static OFMutableArray<DynamicEntity *> *playerhistory;
|
static OFMutableArray<DynamicEntity *> *playerhistory;
|
||||||
int democlientnum = 0;
|
int democlientnum = 0;
|
||||||
|
|
||||||
void startdemo();
|
extern void startdemo();
|
||||||
|
|
||||||
void
|
static void
|
||||||
gzput(int i)
|
gzput(int i)
|
||||||
{
|
{
|
||||||
gzputc(f, i);
|
gzputc(f, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gzputi(int i)
|
gzputi(int i)
|
||||||
{
|
{
|
||||||
gzwrite(f, &i, sizeof(int));
|
gzwrite(f, &i, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gzputv(OFVector3D &v)
|
gzputv(const OFVector3D *v)
|
||||||
{
|
{
|
||||||
gzwrite(f, &v, sizeof(OFVector3D));
|
gzwrite(f, v, sizeof(OFVector3D));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gzcheck(int a, int b)
|
gzcheck(int a, int b)
|
||||||
{
|
{
|
||||||
if (a != b)
|
if (a != b)
|
||||||
fatal(@"savegame file corrupt (short)");
|
fatal(@"savegame file corrupt (short)");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
gzget()
|
gzget()
|
||||||
{
|
{
|
||||||
char c = gzgetc(f);
|
char c = gzgetc(f);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
gzgeti()
|
gzgeti()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -61,10 +61,10 @@ gzgeti()
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gzgetv(OFVector3D &v)
|
gzgetv(OFVector3D *v)
|
||||||
{
|
{
|
||||||
gzcheck(gzread(f, &v, sizeof(OFVector3D)), sizeof(OFVector3D));
|
gzcheck(gzread(f, v, sizeof(OFVector3D)), sizeof(OFVector3D));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -326,7 +326,7 @@ incomingdemodata(uchar *buf, int len, bool extras)
|
||||||
bdamage = 0;
|
bdamage = 0;
|
||||||
gzputi(ddamage);
|
gzputi(ddamage);
|
||||||
if (ddamage) {
|
if (ddamage) {
|
||||||
gzputv(dorig);
|
gzputv(&dorig);
|
||||||
ddamage = 0;
|
ddamage = 0;
|
||||||
}
|
}
|
||||||
// FIXME: add all other client state which is not send through
|
// FIXME: add all other client state which is not send through
|
||||||
|
@ -453,7 +453,7 @@ demoplaybackstep()
|
||||||
if ((bdamage = gzgeti()))
|
if ((bdamage = gzgeti()))
|
||||||
damageblend(bdamage);
|
damageblend(bdamage);
|
||||||
if ((ddamage = gzgeti())) {
|
if ((ddamage = gzgeti())) {
|
||||||
gzgetv(dorig);
|
gzgetv(&dorig);
|
||||||
particle_splash(3, ddamage, 1000, &dorig);
|
particle_splash(3, ddamage, 1000, &dorig);
|
||||||
}
|
}
|
||||||
// FIXME: set more client state here
|
// FIXME: set more client state here
|
|
@ -202,7 +202,7 @@ checkpings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
void
|
||||||
refreshservers()
|
refreshservers()
|
||||||
{
|
{
|
||||||
checkresolver();
|
checkresolver();
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
extern OFString *entnames[]; // lookup from map entities above to strings
|
extern OFString *entnames[]; // lookup from map entities above to strings
|
||||||
|
|
||||||
sqr *world = NULL;
|
struct sqr *world = NULL;
|
||||||
int sfactor, ssize, cubicsize, mipsize;
|
int sfactor, ssize, cubicsize, mipsize;
|
||||||
|
|
||||||
header hdr;
|
struct header hdr;
|
||||||
|
|
||||||
// set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes
|
// set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes
|
||||||
// according to type
|
// according to type
|
||||||
|
@ -20,7 +20,7 @@ settag(int tag, int type)
|
||||||
int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
|
int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
|
||||||
loop(x, ssize) loop(y, ssize)
|
loop(x, ssize) loop(y, ssize)
|
||||||
{
|
{
|
||||||
sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
if (s->tag) {
|
if (s->tag) {
|
||||||
if (tag) {
|
if (tag) {
|
||||||
if (tag == s->tag)
|
if (tag == s->tag)
|
||||||
|
@ -40,7 +40,7 @@ settag(int tag, int type)
|
||||||
miny = y;
|
miny = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
|
struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
|
||||||
if (maxx)
|
if (maxx)
|
||||||
remip(&b, 0); // remip minimal area of changed geometry
|
remip(&b, 0); // remip minimal area of changed geometry
|
||||||
}
|
}
|
||||||
|
@ -90,17 +90,17 @@ COMMAND(trigger, ARG_2INT)
|
||||||
// rendering time if this is possible).
|
// rendering time if this is possible).
|
||||||
|
|
||||||
void
|
void
|
||||||
remip(const block *b, int level)
|
remip(const struct block *b, int level)
|
||||||
{
|
{
|
||||||
if (level >= SMALLEST_FACTOR)
|
if (level >= SMALLEST_FACTOR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int lighterr = getvar(@"lighterror") * 3;
|
int lighterr = getvar(@"lighterror") * 3;
|
||||||
sqr *w = wmip[level];
|
struct sqr *w = wmip[level];
|
||||||
sqr *v = wmip[level + 1];
|
struct sqr *v = wmip[level + 1];
|
||||||
int ws = ssize >> level;
|
int ws = ssize >> level;
|
||||||
int vs = ssize >> (level + 1);
|
int vs = ssize >> (level + 1);
|
||||||
block s = *b;
|
struct block s = *b;
|
||||||
if (s.x & 1) {
|
if (s.x & 1) {
|
||||||
s.x--;
|
s.x--;
|
||||||
s.xs++;
|
s.xs++;
|
||||||
|
@ -113,13 +113,13 @@ remip(const block *b, int level)
|
||||||
s.ys = (s.ys + 1) & ~1;
|
s.ys = (s.ys + 1) & ~1;
|
||||||
for (int x = s.x; x < s.x + s.xs; x += 2)
|
for (int x = s.x; x < s.x + s.xs; x += 2)
|
||||||
for (int y = s.y; y < s.y + s.ys; y += 2) {
|
for (int y = s.y; y < s.y + s.ys; y += 2) {
|
||||||
sqr *o[4];
|
struct sqr *o[4];
|
||||||
o[0] = SWS(w, x, y, ws); // the 4 constituent cubes
|
o[0] = SWS(w, x, y, ws); // the 4 constituent cubes
|
||||||
o[1] = SWS(w, x + 1, y, ws);
|
o[1] = SWS(w, x + 1, y, ws);
|
||||||
o[2] = SWS(w, x + 1, y + 1, ws);
|
o[2] = SWS(w, x + 1, y + 1, ws);
|
||||||
o[3] = SWS(w, x, y + 1, ws);
|
o[3] = SWS(w, x, y + 1, ws);
|
||||||
// the target cube in the higher mip level
|
// the target cube in the higher mip level
|
||||||
sqr *r = SWS(v, x / 2, y / 2, vs);
|
struct sqr *r = SWS(v, x / 2, y / 2, vs);
|
||||||
*r = *o[0];
|
*r = *o[0];
|
||||||
uchar nums[MAXTYPE];
|
uchar nums[MAXTYPE];
|
||||||
loopi(MAXTYPE) nums[i] = 0;
|
loopi(MAXTYPE) nums[i] = 0;
|
||||||
|
@ -242,9 +242,9 @@ remip(const block *b, int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
remipmore(const block *b, int level)
|
remipmore(const struct block *b, int level)
|
||||||
{
|
{
|
||||||
block bb = *b;
|
struct block bb = *b;
|
||||||
|
|
||||||
if (bb.x > 1)
|
if (bb.x > 1)
|
||||||
bb.x--;
|
bb.x--;
|
||||||
|
@ -433,7 +433,7 @@ findentity(int type, int index)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqr *wmip[LARGEST_FACTOR * 2];
|
struct sqr *wmip[LARGEST_FACTOR * 2];
|
||||||
|
|
||||||
void
|
void
|
||||||
setupworld(int factor)
|
setupworld(int factor)
|
||||||
|
@ -441,7 +441,8 @@ setupworld(int factor)
|
||||||
ssize = 1 << (sfactor = factor);
|
ssize = 1 << (sfactor = factor);
|
||||||
cubicsize = ssize * ssize;
|
cubicsize = ssize * ssize;
|
||||||
mipsize = cubicsize * 134 / 100;
|
mipsize = cubicsize * 134 / 100;
|
||||||
sqr *w = world = (sqr *)OFAllocZeroedMemory(mipsize, sizeof(sqr));
|
struct sqr *w = world =
|
||||||
|
OFAllocZeroedMemory(mipsize, sizeof(struct sqr));
|
||||||
loopi(LARGEST_FACTOR * 2)
|
loopi(LARGEST_FACTOR * 2)
|
||||||
{
|
{
|
||||||
wmip[i] = w;
|
wmip[i] = w;
|
||||||
|
@ -458,7 +459,7 @@ empty_world(int factor, bool force)
|
||||||
return;
|
return;
|
||||||
cleardlights();
|
cleardlights();
|
||||||
pruneundos(0);
|
pruneundos(0);
|
||||||
sqr *oldworld = world;
|
struct sqr *oldworld = world;
|
||||||
bool copy = false;
|
bool copy = false;
|
||||||
if (oldworld && factor < 0) {
|
if (oldworld && factor < 0) {
|
||||||
factor = sfactor + 1;
|
factor = sfactor + 1;
|
||||||
|
@ -472,7 +473,7 @@ empty_world(int factor, bool force)
|
||||||
|
|
||||||
loop(x, ssize) loop(y, ssize)
|
loop(x, ssize) loop(y, ssize)
|
||||||
{
|
{
|
||||||
sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
s->r = s->g = s->b = 150;
|
s->r = s->g = s->b = 150;
|
||||||
s->ftex = DEFAULT_FLOOR;
|
s->ftex = DEFAULT_FLOOR;
|
||||||
s->ctex = DEFAULT_CEIL;
|
s->ctex = DEFAULT_CEIL;
|
||||||
|
@ -486,7 +487,7 @@ empty_world(int factor, bool force)
|
||||||
|
|
||||||
strncpy(hdr.head, "CUBE", 4);
|
strncpy(hdr.head, "CUBE", 4);
|
||||||
hdr.version = MAPVERSION;
|
hdr.version = MAPVERSION;
|
||||||
hdr.headersize = sizeof(header);
|
hdr.headersize = sizeof(struct header);
|
||||||
hdr.sfactor = sfactor;
|
hdr.sfactor = sfactor;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
|
@ -507,7 +508,7 @@ empty_world(int factor, bool force)
|
||||||
loopi(15) hdr.reserved[i] = 0;
|
loopi(15) hdr.reserved[i] = 0;
|
||||||
loopk(3) loopi(256) hdr.texlists[k][i] = i;
|
loopk(3) loopi(256) hdr.texlists[k][i] = i;
|
||||||
[ents removeAllObjects];
|
[ents removeAllObjects];
|
||||||
block b = { 8, 8, ssize - 16, ssize - 16 };
|
struct block b = { 8, 8, ssize - 16, ssize - 16 };
|
||||||
edittypexy(SPACE, &b);
|
edittypexy(SPACE, &b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ setnames(OFString *name)
|
||||||
// to reduce the amount spend in the mipmapper (as that is done in realtime).
|
// to reduce the amount spend in the mipmapper (as that is done in realtime).
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
nhf(sqr *s)
|
nhf(struct sqr *s)
|
||||||
{
|
{
|
||||||
return s->type != FHF && s->type != CHF;
|
return s->type != FHF && s->type != CHF;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ voptimize() // reset vdeltas on non-hf cubes
|
||||||
{
|
{
|
||||||
loop(x, ssize) loop(y, ssize)
|
loop(x, ssize) loop(y, ssize)
|
||||||
{
|
{
|
||||||
sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
if (x && y) {
|
if (x && y) {
|
||||||
if (nhf(s) && nhf(S(x - 1, y)) &&
|
if (nhf(s) && nhf(S(x - 1, y)) &&
|
||||||
nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
|
nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
|
||||||
|
@ -73,34 +73,34 @@ voptimize() // reset vdeltas on non-hf cubes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
topt(sqr *s, bool &wf, bool &uf, int &wt, int &ut)
|
topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
|
||||||
{
|
{
|
||||||
sqr *o[4];
|
struct sqr *o[4];
|
||||||
o[0] = SWS(s, 0, -1, ssize);
|
o[0] = SWS(s, 0, -1, ssize);
|
||||||
o[1] = SWS(s, 0, 1, ssize);
|
o[1] = SWS(s, 0, 1, ssize);
|
||||||
o[2] = SWS(s, 1, 0, ssize);
|
o[2] = SWS(s, 1, 0, ssize);
|
||||||
o[3] = SWS(s, -1, 0, ssize);
|
o[3] = SWS(s, -1, 0, ssize);
|
||||||
wf = true;
|
*wf = true;
|
||||||
uf = true;
|
*uf = true;
|
||||||
if (SOLID(s)) {
|
if (SOLID(s)) {
|
||||||
loopi(4) if (!SOLID(o[i]))
|
loopi(4) if (!SOLID(o[i]))
|
||||||
{
|
{
|
||||||
wf = false;
|
*wf = false;
|
||||||
wt = s->wtex;
|
*wt = s->wtex;
|
||||||
ut = s->utex;
|
*ut = s->utex;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
loopi(4) if (!SOLID(o[i]))
|
loopi(4) if (!SOLID(o[i]))
|
||||||
{
|
{
|
||||||
if (o[i]->floor < s->floor) {
|
if (o[i]->floor < s->floor) {
|
||||||
wt = s->wtex;
|
*wt = s->wtex;
|
||||||
wf = false;
|
*wf = false;
|
||||||
}
|
}
|
||||||
if (o[i]->ceil > s->ceil) {
|
if (o[i]->ceil > s->ceil) {
|
||||||
ut = s->utex;
|
*ut = s->utex;
|
||||||
uf = false;
|
*uf = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,18 +110,18 @@ void
|
||||||
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
|
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
|
||||||
{
|
{
|
||||||
bool wf[4], uf[4];
|
bool wf[4], uf[4];
|
||||||
sqr *s[4];
|
struct sqr *s[4];
|
||||||
for (int x = 2; x < ssize - 4; x += 2) {
|
for (int x = 2; x < ssize - 4; x += 2) {
|
||||||
for (int y = 2; y < ssize - 4; y += 2) {
|
for (int y = 2; y < ssize - 4; y += 2) {
|
||||||
s[0] = S(x, y);
|
s[0] = S(x, y);
|
||||||
int wt = s[0]->wtex, ut = s[0]->utex;
|
int wt = s[0]->wtex, ut = s[0]->utex;
|
||||||
topt(s[0], wf[0], uf[0], wt, ut);
|
topt(s[0], &wf[0], &uf[0], &wt, &ut);
|
||||||
topt(s[1] = SWS(s[0], 0, 1, ssize), wf[1], uf[1], wt,
|
topt(s[1] = SWS(s[0], 0, 1, ssize), &wf[1], &uf[1], &wt,
|
||||||
ut);
|
&ut);
|
||||||
topt(s[2] = SWS(s[0], 1, 1, ssize), wf[2], uf[2], wt,
|
topt(s[2] = SWS(s[0], 1, 1, ssize), &wf[2], &uf[2], &wt,
|
||||||
ut);
|
&ut);
|
||||||
topt(s[3] = SWS(s[0], 1, 0, ssize), wf[3], uf[3], wt,
|
topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
|
||||||
ut);
|
&ut);
|
||||||
loopi(4)
|
loopi(4)
|
||||||
{
|
{
|
||||||
if (wf[i])
|
if (wf[i])
|
||||||
|
@ -185,19 +185,19 @@ save_world(OFString *mname)
|
||||||
for (Entity *e in ents)
|
for (Entity *e in ents)
|
||||||
if (e.type != NOTUSED)
|
if (e.type != NOTUSED)
|
||||||
hdr.numents++;
|
hdr.numents++;
|
||||||
header tmp = hdr;
|
struct header tmp = hdr;
|
||||||
endianswap(&tmp.version, sizeof(int), 4);
|
endianswap(&tmp.version, sizeof(int), 4);
|
||||||
endianswap(&tmp.waterlevel, sizeof(int), 16);
|
endianswap(&tmp.waterlevel, sizeof(int), 16);
|
||||||
gzwrite(f, &tmp, sizeof(header));
|
gzwrite(f, &tmp, sizeof(struct header));
|
||||||
for (Entity *e in ents) {
|
for (Entity *e in ents) {
|
||||||
if (e.type != NOTUSED) {
|
if (e.type != NOTUSED) {
|
||||||
struct persistent_entity tmp = { e.x, e.y, e.z, e.attr1,
|
struct persistent_entity tmp = { e.x, e.y, e.z, e.attr1,
|
||||||
e.type, e.attr2, e.attr3, e.attr4 };
|
e.type, e.attr2, e.attr3, e.attr4 };
|
||||||
endianswap(&tmp, sizeof(short), 4);
|
endianswap(&tmp, sizeof(short), 4);
|
||||||
gzwrite(f, &tmp, sizeof(persistent_entity));
|
gzwrite(f, &tmp, sizeof(struct persistent_entity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqr *t = NULL;
|
struct sqr *t = NULL;
|
||||||
int sc = 0;
|
int sc = 0;
|
||||||
#define spurge \
|
#define spurge \
|
||||||
while (sc) { \
|
while (sc) { \
|
||||||
|
@ -212,7 +212,7 @@ save_world(OFString *mname)
|
||||||
}
|
}
|
||||||
loopk(cubicsize)
|
loopk(cubicsize)
|
||||||
{
|
{
|
||||||
sqr *s = &world[k];
|
struct sqr *s = &world[k];
|
||||||
#define c(f) (s->f == t->f)
|
#define c(f) (s->f == t->f)
|
||||||
// 4 types of blocks, to compress a bit:
|
// 4 types of blocks, to compress a bit:
|
||||||
// 255 (2): same as previous block + count
|
// 255 (2): same as previous block + count
|
||||||
|
@ -270,7 +270,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
||||||
conoutf(@"could not read map %@", cgzname);
|
conoutf(@"could not read map %@", cgzname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gzread(f, &hdr, sizeof(header) - sizeof(int) * 16);
|
gzread(f, &hdr, sizeof(struct header) - sizeof(int) * 16);
|
||||||
endianswap(&hdr.version, sizeof(int), 4);
|
endianswap(&hdr.version, sizeof(int), 4);
|
||||||
if (strncmp(hdr.head, "CUBE", 4) != 0)
|
if (strncmp(hdr.head, "CUBE", 4) != 0)
|
||||||
fatal(@"while reading map: header malformatted");
|
fatal(@"while reading map: header malformatted");
|
||||||
|
@ -288,7 +288,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
||||||
loopi(hdr.numents)
|
loopi(hdr.numents)
|
||||||
{
|
{
|
||||||
struct persistent_entity tmp;
|
struct persistent_entity tmp;
|
||||||
gzread(f, &tmp, sizeof(persistent_entity));
|
gzread(f, &tmp, sizeof(struct persistent_entity));
|
||||||
endianswap(&tmp, sizeof(short), 4);
|
endianswap(&tmp, sizeof(short), 4);
|
||||||
|
|
||||||
Entity *e = [Entity entity];
|
Entity *e = [Entity entity];
|
||||||
|
@ -313,22 +313,22 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
||||||
setupworld(hdr.sfactor);
|
setupworld(hdr.sfactor);
|
||||||
char texuse[256];
|
char texuse[256];
|
||||||
loopi(256) texuse[i] = 0;
|
loopi(256) texuse[i] = 0;
|
||||||
sqr *t = NULL;
|
struct sqr *t = NULL;
|
||||||
loopk(cubicsize)
|
loopk(cubicsize)
|
||||||
{
|
{
|
||||||
sqr *s = &world[k];
|
struct sqr *s = &world[k];
|
||||||
int type = gzgetc(f);
|
int type = gzgetc(f);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 255: {
|
case 255: {
|
||||||
int n = gzgetc(f);
|
int n = gzgetc(f);
|
||||||
for (int i = 0; i < n; i++, k++)
|
for (int i = 0; i < n; i++, k++)
|
||||||
memcpy(&world[k], t, sizeof(sqr));
|
memcpy(&world[k], t, sizeof(struct sqr));
|
||||||
k--;
|
k--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 254: // only in MAPVERSION<=2
|
case 254: // only in MAPVERSION<=2
|
||||||
{
|
{
|
||||||
memcpy(s, t, sizeof(sqr));
|
memcpy(s, t, sizeof(struct sqr));
|
||||||
s->r = s->g = s->b = gzgetc(f);
|
s->r = s->g = s->b = gzgetc(f);
|
||||||
gzgetc(f);
|
gzgetc(f);
|
||||||
break;
|
break;
|
||||||
|
@ -382,7 +382,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
||||||
calclight();
|
calclight();
|
||||||
settagareas();
|
settagareas();
|
||||||
int xs, ys;
|
int xs, ys;
|
||||||
loopi(256) if (texuse) lookuptexture(i, &xs, &ys);
|
loopi(256) if (texuse[i]) lookuptexture(i, &xs, &ys);
|
||||||
conoutf(@"read map %@ (%d milliseconds)", cgzname,
|
conoutf(@"read map %@ (%d milliseconds)", cgzname,
|
||||||
SDL_GetTicks() - lastmillis);
|
SDL_GetTicks() - lastmillis);
|
||||||
conoutf(@"%s", hdr.maptitle);
|
conoutf(@"%s", hdr.maptitle);
|
|
@ -64,7 +64,7 @@ lightray(float bx, float by, PersistentEntity *light)
|
||||||
stepb /= lightscale;
|
stepb /= lightscale;
|
||||||
loopi(steps)
|
loopi(steps)
|
||||||
{
|
{
|
||||||
sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||||
int tl = (l >> PRECBITS) + s->r;
|
int tl = (l >> PRECBITS) + s->r;
|
||||||
s->r = tl > 255 ? 255 : tl;
|
s->r = tl > 255 ? 255 : tl;
|
||||||
tl = (g >> PRECBITS) + s->g;
|
tl = (g >> PRECBITS) + s->g;
|
||||||
|
@ -93,7 +93,7 @@ lightray(float bx, float by, PersistentEntity *light)
|
||||||
|
|
||||||
loopi(steps)
|
loopi(steps)
|
||||||
{
|
{
|
||||||
sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||||
int tl = (l >> PRECBITS) + s->r;
|
int tl = (l >> PRECBITS) + s->r;
|
||||||
s->r = s->g = s->b = tl > 255 ? 255 : tl;
|
s->r = s->g = s->b = tl > 255 ? 255 : tl;
|
||||||
if (SOLID(s))
|
if (SOLID(s))
|
||||||
|
@ -109,7 +109,7 @@ lightray(float bx, float by, PersistentEntity *light)
|
||||||
{
|
{
|
||||||
loopi(steps)
|
loopi(steps)
|
||||||
{
|
{
|
||||||
sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||||
int light = l >> PRECBITS;
|
int light = l >> PRECBITS;
|
||||||
if (light > s->r)
|
if (light > s->r)
|
||||||
s->r = s->g = s->b = (uchar)light;
|
s->r = s->g = s->b = (uchar)light;
|
||||||
|
@ -147,13 +147,13 @@ calclightsource(PersistentEntity *l)
|
||||||
rndtime();
|
rndtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// median filter, smooths out random noise in light and makes it more mipable
|
||||||
void
|
void
|
||||||
postlightarea(block &a) // median filter, smooths out random noise in light and
|
postlightarea(const struct block *a)
|
||||||
// makes it more mipable
|
|
||||||
{
|
{
|
||||||
loop(x, a.xs) loop(y, a.ys) // assumes area not on edge of world
|
loop(x, a->xs) loop(y, a->ys) // assumes area not on edge of world
|
||||||
{
|
{
|
||||||
sqr *s = S(x + a.x, y + a.y);
|
struct sqr *s = S(x + a->x, y + a->y);
|
||||||
#define median(m) \
|
#define median(m) \
|
||||||
s->m = \
|
s->m = \
|
||||||
(s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \
|
(s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \
|
||||||
|
@ -165,7 +165,7 @@ postlightarea(block &a) // median filter, smooths out random noise in light and
|
||||||
median(b);
|
median(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
remip(&a, 0);
|
remip(a, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -173,7 +173,7 @@ calclight()
|
||||||
{
|
{
|
||||||
loop(x, ssize) loop(y, ssize)
|
loop(x, ssize) loop(y, ssize)
|
||||||
{
|
{
|
||||||
sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
s->r = s->g = s->b = 10;
|
s->r = s->g = s->b = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,8 +181,8 @@ calclight()
|
||||||
if (e.type == LIGHT)
|
if (e.type == LIGHT)
|
||||||
calclightsource(e);
|
calclightsource(e);
|
||||||
|
|
||||||
block b = { 1, 1, ssize - 2, ssize - 2 };
|
struct block b = { 1, 1, ssize - 2, ssize - 2 };
|
||||||
postlightarea(b);
|
postlightarea(&b);
|
||||||
setvar(@"fullbright", 0);
|
setvar(@"fullbright", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ void
|
||||||
cleardlights()
|
cleardlights()
|
||||||
{
|
{
|
||||||
while (dlights.count > 0) {
|
while (dlights.count > 0) {
|
||||||
block *backup = *(block **)[dlights lastItem];
|
struct block *backup = *(struct block **)[dlights lastItem];
|
||||||
[dlights removeLastItem];
|
[dlights removeLastItem];
|
||||||
blockpaste(backup);
|
blockpaste(backup);
|
||||||
OFFreeMemory(backup);
|
OFFreeMemory(backup);
|
||||||
|
@ -215,8 +215,8 @@ dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int creach = reach + 16; // dependant on lightray random offsets!
|
int creach = reach + 16; // dependant on lightray random offsets!
|
||||||
block b = { (int)v->x - creach, (int)v->y - creach, creach * 2 + 1,
|
struct block b = { (int)v->x - creach, (int)v->y - creach,
|
||||||
creach * 2 + 1 };
|
creach * 2 + 1, creach * 2 + 1 };
|
||||||
|
|
||||||
if (b.x < 1)
|
if (b.x < 1)
|
||||||
b.x = 1;
|
b.x = 1;
|
||||||
|
@ -228,11 +228,11 @@ dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength,
|
||||||
b.ys = ssize - 2 - b.y;
|
b.ys = ssize - 2 - b.y;
|
||||||
|
|
||||||
if (dlights == nil)
|
if (dlights == nil)
|
||||||
dlights =
|
dlights = [[OFMutableData alloc]
|
||||||
[[OFMutableData alloc] initWithItemSize:sizeof(block *)];
|
initWithItemSize:sizeof(struct block *)];
|
||||||
|
|
||||||
// backup area before rendering in dynlight
|
// backup area before rendering in dynlight
|
||||||
block *copy = blockcopy(&b);
|
struct block *copy = blockcopy(&b);
|
||||||
[dlights addItem:©];
|
[dlights addItem:©];
|
||||||
|
|
||||||
PersistentEntity *l = [Entity entity];
|
PersistentEntity *l = [Entity entity];
|
||||||
|
@ -243,18 +243,18 @@ dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength,
|
||||||
l.type = LIGHT;
|
l.type = LIGHT;
|
||||||
l.attr2 = strength;
|
l.attr2 = strength;
|
||||||
calclightsource(l);
|
calclightsource(l);
|
||||||
postlightarea(b);
|
postlightarea(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility functions also used by editing code
|
// utility functions also used by editing code
|
||||||
|
|
||||||
block *
|
struct block *
|
||||||
blockcopy(const block *s)
|
blockcopy(const struct block *s)
|
||||||
{
|
{
|
||||||
block *b = (block *)OFAllocZeroedMemory(
|
struct block *b = OFAllocZeroedMemory(
|
||||||
1, sizeof(block) + s->xs * s->ys * sizeof(sqr));
|
1, sizeof(struct block) + s->xs * s->ys * sizeof(struct sqr));
|
||||||
*b = *s;
|
*b = *s;
|
||||||
sqr *q = (sqr *)(b + 1);
|
struct sqr *q = (struct sqr *)(b + 1);
|
||||||
for (int x = s->x; x < s->xs + s->x; x++)
|
for (int x = s->x; x < s->xs + s->x; x++)
|
||||||
for (int y = s->y; y < s->ys + s->y; y++)
|
for (int y = s->y; y < s->ys + s->y; y++)
|
||||||
*q++ = *S(x, y);
|
*q++ = *S(x, y);
|
||||||
|
@ -262,9 +262,9 @@ blockcopy(const block *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
blockpaste(const block *b)
|
blockpaste(const struct block *b)
|
||||||
{
|
{
|
||||||
sqr *q = (sqr *)(b + 1);
|
struct sqr *q = (struct sqr *)(b + 1);
|
||||||
for (int x = b->x; x < b->xs + b->x; x++)
|
for (int x = b->x; x < b->xs + b->x; x++)
|
||||||
for (int y = b->y; y < b->ys + b->y; y++)
|
for (int y = b->y; y < b->ys + b->y; y++)
|
||||||
*S(x, y) = *q++;
|
*S(x, y) = *q++;
|
|
@ -7,8 +7,8 @@
|
||||||
#import "DynamicEntity.h"
|
#import "DynamicEntity.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d1,
|
render_wall(struct sqr *o, struct sqr *s, int x1, int y1, int x2, int y2,
|
||||||
sqr *d2, bool topleft)
|
int mip, struct sqr *d1, struct sqr *d2, bool topleft)
|
||||||
{
|
{
|
||||||
if (SOLID(o) || o->type == SEMISOLID) {
|
if (SOLID(o) || o->type == SEMISOLID) {
|
||||||
float c1 = s->floor;
|
float c1 = s->floor;
|
||||||
|
@ -83,7 +83,7 @@ issemi(int mip, int x, int y, int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
if (!(mip--))
|
if (!(mip--))
|
||||||
return true;
|
return true;
|
||||||
sqr *w = wmip[mip];
|
struct sqr *w = wmip[mip];
|
||||||
int msize = ssize >> mip;
|
int msize = ssize >> mip;
|
||||||
x *= 2;
|
x *= 2;
|
||||||
y *= 2;
|
y *= 2;
|
||||||
|
@ -121,7 +121,7 @@ void
|
||||||
render_seg_new(
|
render_seg_new(
|
||||||
float vx, float vy, float vh, int mip, int x, int y, int xs, int ys)
|
float vx, float vy, float vh, int mip, int x, int y, int xs, int ys)
|
||||||
{
|
{
|
||||||
sqr *w = wmip[mip];
|
struct sqr *w = wmip[mip];
|
||||||
int sz = ssize >> mip;
|
int sz = ssize >> mip;
|
||||||
int vxx = ((int)vx + (1 << mip) / 2) >> mip;
|
int vxx = ((int)vx + (1 << mip) / 2) >> mip;
|
||||||
int vyy = ((int)vy + (1 << mip) / 2) >> mip;
|
int vyy = ((int)vy + (1 << mip) / 2) >> mip;
|
||||||
|
@ -164,21 +164,21 @@ render_seg_new(
|
||||||
{ \
|
{ \
|
||||||
for (int xx = x; xx < xs; xx++) \
|
for (int xx = x; xx < xs; xx++) \
|
||||||
for (int yy = y; yy < ys; yy++) { \
|
for (int yy = y; yy < ys; yy++) { \
|
||||||
sqr *s = SWS(w, xx, yy, sz); \
|
struct sqr *s = SWS(w, xx, yy, sz); \
|
||||||
if (s->occluded == 1) \
|
if (s->occluded == 1) \
|
||||||
continue; \
|
continue; \
|
||||||
if (s->defer && !s->occluded && mip && \
|
if (s->defer && !s->occluded && mip && \
|
||||||
xx >= lx && xx < rx && yy >= ly && \
|
xx >= lx && xx < rx && yy >= ly && \
|
||||||
yy < ry)
|
yy < ry)
|
||||||
#define LOOPD \
|
#define LOOPD \
|
||||||
sqr *t = SWS(s, 1, 0, sz); \
|
struct sqr *t = SWS(s, 1, 0, sz); \
|
||||||
sqr *u = SWS(s, 1, 1, sz); \
|
struct sqr *u = SWS(s, 1, 1, sz); \
|
||||||
sqr *v = SWS(s, 0, 1, sz);
|
struct sqr *v = SWS(s, 0, 1, sz);
|
||||||
|
|
||||||
LOOPH // ceils
|
LOOPH // ceils
|
||||||
{
|
{
|
||||||
int start = yy;
|
int start = yy;
|
||||||
sqr *next;
|
struct sqr *next;
|
||||||
while (yy < ys - 1 && (next = SWS(w, xx, yy + 1, sz))->defer &&
|
while (yy < ys - 1 && (next = SWS(w, xx, yy + 1, sz))->defer &&
|
||||||
!next->occluded)
|
!next->occluded)
|
||||||
yy++; // collect 2xN rect of lower mip
|
yy++; // collect 2xN rect of lower mip
|
||||||
|
@ -221,15 +221,15 @@ LOOPD
|
||||||
// zSt
|
// zSt
|
||||||
// vu
|
// vu
|
||||||
|
|
||||||
sqr *w = SWS(s, 0, -1, sz);
|
struct sqr *w = SWS(s, 0, -1, sz);
|
||||||
sqr *z = SWS(s, -1, 0, sz);
|
struct sqr *z = SWS(s, -1, 0, sz);
|
||||||
bool normalwall = true;
|
bool normalwall = true;
|
||||||
|
|
||||||
if (s->type == CORNER) {
|
if (s->type == CORNER) {
|
||||||
// cull also
|
// cull also
|
||||||
bool topleft = true;
|
bool topleft = true;
|
||||||
sqr *h1 = NULL;
|
struct sqr *h1 = NULL;
|
||||||
sqr *h2 = NULL;
|
struct sqr *h2 = NULL;
|
||||||
if (SOLID(z)) {
|
if (SOLID(z)) {
|
||||||
if (SOLID(w)) {
|
if (SOLID(w)) {
|
||||||
render_wall(w, h2 = s, xx + 1, yy, xx, yy + 1, mip, t,
|
render_wall(w, h2 = s, xx + 1, yy, xx, yy + 1, mip, t,
|
||||||
|
@ -299,16 +299,16 @@ if (normalwall) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
distlod(int &low, int &high, int angle, float widef)
|
distlod(int *low, int *high, int angle, float widef)
|
||||||
{
|
{
|
||||||
float f = 90.0f / lod / widef;
|
float f = 90.0f / lod / widef;
|
||||||
low = (int)((90 - angle) / f);
|
*low = (int)((90 - angle) / f);
|
||||||
high = (int)(angle / f);
|
*high = (int)(angle / f);
|
||||||
if (low < min_lod)
|
if (*low < min_lod)
|
||||||
low = min_lod;
|
*low = min_lod;
|
||||||
if (high < min_lod)
|
if (*high < min_lod)
|
||||||
high = min_lod;
|
*high = min_lod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// does some out of date view frustrum optimisation that doesn't contribute much
|
// does some out of date view frustrum optimisation that doesn't contribute much
|
||||||
|
@ -334,17 +334,17 @@ render_world(
|
||||||
lodtop = lodbot = lodleft = lodright = min_lod;
|
lodtop = lodbot = lodleft = lodright = min_lod;
|
||||||
if (yaw > 45 && yaw <= 135) {
|
if (yaw > 45 && yaw <= 135) {
|
||||||
lodleft = lod;
|
lodleft = lod;
|
||||||
distlod(lodtop, lodbot, yaw - 45, widef);
|
distlod(&lodtop, &lodbot, yaw - 45, widef);
|
||||||
} else if (yaw > 135 && yaw <= 225) {
|
} else if (yaw > 135 && yaw <= 225) {
|
||||||
lodbot = lod;
|
lodbot = lod;
|
||||||
distlod(lodleft, lodright, yaw - 135, widef);
|
distlod(&lodleft, &lodright, yaw - 135, widef);
|
||||||
} else if (yaw > 225 && yaw <= 315) {
|
} else if (yaw > 225 && yaw <= 315) {
|
||||||
lodright = lod;
|
lodright = lod;
|
||||||
distlod(lodbot, lodtop, yaw - 225, widef);
|
distlod(&lodbot, &lodtop, yaw - 225, widef);
|
||||||
} else {
|
} else {
|
||||||
lodtop = lod;
|
lodtop = lod;
|
||||||
distlod(
|
distlod(&lodright, &lodleft, yaw <= 45 ? yaw + 45 : yaw - 315,
|
||||||
lodright, lodleft, yaw <= 45 ? yaw + 45 : yaw - 315, widef);
|
widef);
|
||||||
}
|
}
|
||||||
float hyfov = fov * h / w / 2;
|
float hyfov = fov * h / w / 2;
|
||||||
render_floor = pitch < hyfov;
|
render_floor = pitch < hyfov;
|
Loading…
Add table
Add a link
Reference in a new issue