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