Convert several files to pure Objective-C
FossilOrigin-Name: eac9e3d9480c641e752bce15f24de48bbb77705cd44ef2bb9a04603ca04c67e1
This commit is contained in:
parent
2085a651bd
commit
565a845aaf
13 changed files with 84 additions and 55 deletions
|
@ -36,7 +36,7 @@ struct dynent {
|
||||||
@implementation DynamicEntity
|
@implementation DynamicEntity
|
||||||
+ (size_t)serializedSize
|
+ (size_t)serializedSize
|
||||||
{
|
{
|
||||||
return sizeof(dynent);
|
return sizeof(struct dynent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
|
@ -117,7 +117,7 @@ struct dynent {
|
||||||
{
|
{
|
||||||
// This is frighteningly *TERRIBLE*, but the format used by existing
|
// This is frighteningly *TERRIBLE*, but the format used by existing
|
||||||
// savegames.
|
// savegames.
|
||||||
dynent data = { .o = _o,
|
struct dynent data = { .o = _o,
|
||||||
.vel = _vel,
|
.vel = _vel,
|
||||||
.yaw = _yaw,
|
.yaw = _yaw,
|
||||||
.pitch = _pitch,
|
.pitch = _pitch,
|
||||||
|
@ -175,7 +175,7 @@ struct dynent {
|
||||||
{
|
{
|
||||||
struct dynent d;
|
struct dynent d;
|
||||||
|
|
||||||
if (data.count != sizeof(dynent))
|
if (data.count != sizeof(struct dynent))
|
||||||
@throw [OFOutOfRangeException exception];
|
@throw [OFOutOfRangeException exception];
|
||||||
|
|
||||||
memcpy(&d, data.items, data.count);
|
memcpy(&d, data.items, data.count);
|
|
@ -21,7 +21,7 @@ struct md2_frame {
|
||||||
float scale[3];
|
float scale[3];
|
||||||
float translate[3];
|
float translate[3];
|
||||||
char name[16];
|
char name[16];
|
||||||
md2_vertex vertices[1];
|
struct md2_vertex vertices[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
static float
|
static float
|
||||||
|
@ -51,10 +51,14 @@ snap(int sn, float f)
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
if (_glCommands)
|
OFFreeMemory(_glCommands);
|
||||||
delete[] _glCommands;
|
OFFreeMemory(_frames);
|
||||||
if (_frames)
|
|
||||||
delete[] _frames;
|
if (_mverts != NULL)
|
||||||
|
for (size_t i = 0; i < _numFrames; i++)
|
||||||
|
OFFreeMemory(_mverts[i]);
|
||||||
|
|
||||||
|
OFFreeMemory(_mverts);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (bool)loadWithIRI:(OFIRI *)IRI
|
- (bool)loadWithIRI:(OFIRI *)IRI
|
||||||
|
@ -71,16 +75,18 @@ snap(int sn, float f)
|
||||||
if (![stream isKindOfClass:OFSeekableStream.class])
|
if (![stream isKindOfClass:OFSeekableStream.class])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
md2_header header;
|
struct md2_header header;
|
||||||
[stream readIntoBuffer:&header exactLength:sizeof(md2_header)];
|
[stream readIntoBuffer:&header exactLength:sizeof(header)];
|
||||||
endianswap(&header, sizeof(int), sizeof(md2_header) / sizeof(int));
|
endianswap(&header, sizeof(int), sizeof(header) / sizeof(int));
|
||||||
|
|
||||||
if (header.magic != 844121161 || header.version != 8)
|
if (header.magic != 844121161 || header.version != 8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_frames = new char[header.frameSize * header.numFrames];
|
@try {
|
||||||
if (_frames == NULL)
|
_frames = OFAllocMemory(header.numFrames, header.frameSize);
|
||||||
|
} @catch (OFOutOfMemoryException *e) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
[stream seekToOffset:header.offsetFrames whence:OFSeekSet];
|
[stream seekToOffset:header.offsetFrames whence:OFSeekSet];
|
||||||
[stream readIntoBuffer:_frames
|
[stream readIntoBuffer:_frames
|
||||||
|
@ -89,9 +95,11 @@ snap(int sn, float f)
|
||||||
for (int i = 0; i < header.numFrames; ++i)
|
for (int i = 0; i < header.numFrames; ++i)
|
||||||
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
|
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
|
||||||
|
|
||||||
_glCommands = new int[header.numGlCommands];
|
@try {
|
||||||
if (_glCommands == NULL)
|
_glCommands = OFAllocMemory(header.numGlCommands, sizeof(int));
|
||||||
|
} @catch (OFOutOfMemoryException *e) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
[stream seekToOffset:header.offsetGlCommands whence:OFSeekSet];
|
[stream seekToOffset:header.offsetGlCommands whence:OFSeekSet];
|
||||||
[stream readIntoBuffer:_glCommands
|
[stream readIntoBuffer:_glCommands
|
||||||
|
@ -106,16 +114,18 @@ snap(int sn, float f)
|
||||||
|
|
||||||
[stream close];
|
[stream close];
|
||||||
|
|
||||||
_mverts = new OFVector3D *[_numFrames];
|
_mverts = OFAllocZeroedMemory(_numFrames, sizeof(OFVector3D *));
|
||||||
loopj(_numFrames) _mverts[j] = NULL;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn
|
- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn
|
||||||
{
|
{
|
||||||
_mverts[frame] = new OFVector3D[_numVerts];
|
OFAssert(_mverts[frame] == NULL);
|
||||||
md2_frame *cf = (md2_frame *)((char *)_frames + _frameSize * frame);
|
|
||||||
|
_mverts[frame] = OFAllocMemory(_numVerts, sizeof(OFVector3D));
|
||||||
|
struct md2_frame *cf =
|
||||||
|
(struct md2_frame *)((char *)_frames + _frameSize * frame);
|
||||||
float sc = 16.0f / scale;
|
float sc = 16.0f / scale;
|
||||||
loop(vi, _numVerts)
|
loop(vi, _numVerts)
|
||||||
{
|
{
|
||||||
|
@ -186,9 +196,7 @@ snap(int sn, float f)
|
||||||
float tv = *((float *)command++);
|
float tv = *((float *)command++);
|
||||||
glTexCoord2f(tu, tv);
|
glTexCoord2f(tu, tv);
|
||||||
int vn = *command++;
|
int vn = *command++;
|
||||||
OFVector3D &v1 = verts1[vn];
|
#define ip(c) verts1[vn].c *frac2 + verts2[vn].c *frac1
|
||||||
OFVector3D &v2 = verts2[vn];
|
|
||||||
#define ip(c) v1.c *frac2 + v2.c *frac1
|
|
||||||
glVertex3f(ip(x), ip(z), ip(y));
|
glVertex3f(ip(x), ip(z), ip(y));
|
||||||
}
|
}
|
||||||
|
|
12
src/cube.h
12
src/cube.h
|
@ -243,9 +243,12 @@ struct vertex {
|
||||||
|
|
||||||
// globals ooh naughty
|
// globals ooh naughty
|
||||||
|
|
||||||
extern sqr *world,
|
#ifdef __cplusplus
|
||||||
*wmip[]; // map data, the mips are sequential 2D arrays in memory
|
extern "C" {
|
||||||
extern header hdr; // current map header
|
#endif
|
||||||
|
// map data, the mips are sequential 2D arrays in memory
|
||||||
|
extern struct sqr *world, *wmip[];
|
||||||
|
extern struct header hdr; // current map header
|
||||||
extern int sfactor, ssize; // ssize = 2^sfactor
|
extern int sfactor, ssize; // ssize = 2^sfactor
|
||||||
extern int cubicsize, mipsize; // cubicsize = ssize^2
|
extern int cubicsize, mipsize; // cubicsize = ssize^2
|
||||||
// special client ent that receives input and acts as camera
|
// special client ent that receives input and acts as camera
|
||||||
|
@ -260,6 +263,9 @@ extern int curtime; // current frame time
|
||||||
extern int gamemode, nextmode;
|
extern int gamemode, nextmode;
|
||||||
extern int xtraverts;
|
extern int xtraverts;
|
||||||
extern bool demoplayback;
|
extern bool demoplayback;
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DMF 16.0f
|
#define DMF 16.0f
|
||||||
#define DAF 1.0f
|
#define DAF 1.0f
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
executable('client',
|
executable('client',
|
||||||
[
|
[
|
||||||
'Alias.m',
|
'Alias.m',
|
||||||
'Client.mm',
|
'Client.m',
|
||||||
'Command.mm',
|
'Command.m',
|
||||||
'ConsoleLine.m',
|
'ConsoleLine.m',
|
||||||
'Cube.mm',
|
'Cube.mm',
|
||||||
'DynamicEntity.mm',
|
'DynamicEntity.m',
|
||||||
'Entity.m',
|
'Entity.m',
|
||||||
'Identifier.m',
|
'Identifier.m',
|
||||||
'KeyMapping.m',
|
'KeyMapping.m',
|
||||||
'MD2.mm',
|
'MD2.m',
|
||||||
'MapModelInfo.m',
|
'MapModelInfo.m',
|
||||||
'Menu.m',
|
'Menu.m',
|
||||||
'MenuItem.m',
|
'MenuItem.m',
|
||||||
'OFString+Cube.mm',
|
'OFString+Cube.m',
|
||||||
'PersistentEntity.m',
|
'PersistentEntity.m',
|
||||||
'Projectile.m',
|
'Projectile.m',
|
||||||
'ResolverResult.mm',
|
'ResolverResult.m',
|
||||||
'ResolverThread.mm',
|
'ResolverThread.m',
|
||||||
'ServerEntity.m',
|
'ServerEntity.m',
|
||||||
'ServerInfo.mm',
|
'ServerInfo.m',
|
||||||
'Variable.mm',
|
'Variable.m',
|
||||||
'clients.mm',
|
'clients.mm',
|
||||||
'clientextras.mm',
|
'clientextras.mm',
|
||||||
'clientgame.mm',
|
'clientgame.mm',
|
||||||
|
@ -69,7 +69,7 @@ executable('client',
|
||||||
|
|
||||||
executable('server',
|
executable('server',
|
||||||
[
|
[
|
||||||
'Client.mm',
|
'Client.m',
|
||||||
'ServerEntity.m',
|
'ServerEntity.m',
|
||||||
'server.mm',
|
'server.mm',
|
||||||
'serverms.mm',
|
'serverms.mm',
|
||||||
|
|
49
src/protos.h
49
src/protos.h
|
@ -1,5 +1,9 @@
|
||||||
// protos for ALL external functions in cube...
|
// protos for ALL external functions in cube...
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// command
|
// command
|
||||||
extern int variable(OFString *name, int min, int cur, int max, int *storage,
|
extern int variable(OFString *name, int min, int cur, int max, int *storage,
|
||||||
void (*fun)(), bool persist);
|
void (*fun)(), bool persist);
|
||||||
|
@ -47,22 +51,23 @@ extern void cleangl();
|
||||||
extern void gl_drawframe(int w, int h, float curfps);
|
extern void gl_drawframe(int w, int h, float curfps);
|
||||||
extern bool installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp);
|
extern bool installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp);
|
||||||
extern void mipstats(int a, int b, int c);
|
extern void mipstats(int a, int b, int c);
|
||||||
extern void vertf(float v1, float v2, float v3, sqr *ls, float t1, float t2);
|
extern void vertf(
|
||||||
|
float v1, float v2, float v3, struct sqr *ls, float t1, float t2);
|
||||||
extern void addstrip(int tex, int start, int n);
|
extern void addstrip(int tex, int start, int n);
|
||||||
extern int lookuptexture(int tex, int *xs, int *ys);
|
extern int lookuptexture(int tex, int *xs, int *ys);
|
||||||
|
|
||||||
// rendercubes
|
// rendercubes
|
||||||
extern void resetcubes();
|
extern void resetcubes();
|
||||||
extern void render_flat(int tex, int x, int y, int size, int h, sqr *l1,
|
extern void render_flat(int tex, int x, int y, int size, int h, struct sqr *l1,
|
||||||
sqr *l2, sqr *l3, sqr *l4, bool isceil);
|
struct sqr *l2, struct sqr *l3, struct sqr *l4, bool isceil);
|
||||||
extern void render_flatdelta(int wtex, int x, int y, int size, float h1,
|
extern void render_flatdelta(int wtex, int x, int y, int size, float h1,
|
||||||
float h2, float h3, float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4,
|
float h2, float h3, float h4, struct sqr *l1, struct sqr *l2,
|
||||||
bool isceil);
|
struct sqr *l3, struct sqr *l4, bool isceil);
|
||||||
extern void render_square(int wtex, float floor1, float floor2, float ceil1,
|
extern void render_square(int wtex, float floor1, float floor2, float ceil1,
|
||||||
float ceil2, int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2,
|
float ceil2, int x1, int y1, int x2, int y2, int size, struct sqr *l1,
|
||||||
bool topleft);
|
struct sqr *l2, bool topleft);
|
||||||
extern void render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2,
|
extern void render_tris(int x, int y, int size, bool topleft, struct sqr *h1,
|
||||||
sqr *s, sqr *t, sqr *u, sqr *v);
|
struct sqr *h2, struct sqr *s, struct sqr *t, struct sqr *u, struct sqr *v);
|
||||||
extern void addwaterquad(int x, int y, int size);
|
extern void addwaterquad(int x, int y, int size);
|
||||||
extern int renderwater(float hf);
|
extern int renderwater(float hf);
|
||||||
extern void finishstrips();
|
extern void finishstrips();
|
||||||
|
@ -114,8 +119,8 @@ extern void renderscores();
|
||||||
// world
|
// world
|
||||||
extern void setupworld(int factor);
|
extern void setupworld(int factor);
|
||||||
extern void empty_world(int factor, bool force);
|
extern void empty_world(int factor, bool force);
|
||||||
extern void remip(const block *b, int level);
|
extern void remip(const struct block *b, int level);
|
||||||
extern void remipmore(const block *b, int level);
|
extern void remipmore(const struct block *b, int level);
|
||||||
extern int closestent();
|
extern int closestent();
|
||||||
extern int findentity(int type, int index);
|
extern int findentity(int type, int index);
|
||||||
extern void trigger(int tag, int type, bool savegame);
|
extern void trigger(int tag, int type, bool savegame);
|
||||||
|
@ -129,8 +134,8 @@ extern void calclight();
|
||||||
extern void dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach,
|
extern void dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach,
|
||||||
int strength, DynamicEntity *owner);
|
int strength, DynamicEntity *owner);
|
||||||
extern void cleardlights();
|
extern void cleardlights();
|
||||||
extern block *blockcopy(const block *b);
|
extern struct block *blockcopy(const struct block *b);
|
||||||
extern void blockpaste(const block *b);
|
extern void blockpaste(const struct block *b);
|
||||||
|
|
||||||
// worldrender
|
// worldrender
|
||||||
extern void render_world(float vx, float vy, float vh, int yaw, int pitch,
|
extern void render_world(float vx, float vy, float vh, int yaw, int pitch,
|
||||||
|
@ -154,17 +159,17 @@ extern void draw_envbox(int t, int fogdist);
|
||||||
extern void cursorupdate();
|
extern void cursorupdate();
|
||||||
extern void toggleedit();
|
extern void toggleedit();
|
||||||
extern void editdrag(bool isdown);
|
extern void editdrag(bool isdown);
|
||||||
extern void setvdeltaxy(int delta, const block *sel);
|
extern void setvdeltaxy(int delta, const struct block *sel);
|
||||||
extern void editequalisexy(bool isfloor, const block *sel);
|
extern void editequalisexy(bool isfloor, const struct block *sel);
|
||||||
extern void edittypexy(int type, const block *sel);
|
extern void edittypexy(int type, const struct block *sel);
|
||||||
extern void edittexxy(int type, int t, const block *sel);
|
extern void edittexxy(int type, int t, const struct block *sel);
|
||||||
extern void editheightxy(bool isfloor, int amount, const block *sel);
|
extern void editheightxy(bool isfloor, int amount, const struct block *sel);
|
||||||
extern bool noteditmode();
|
extern bool noteditmode();
|
||||||
extern void pruneundos(int maxremain);
|
extern void pruneundos(int maxremain);
|
||||||
|
|
||||||
// renderextras
|
// renderextras
|
||||||
extern void line(int x1, int y1, float z1, int x2, int y2, float z2);
|
extern void line(int x1, int y1, float z1, int x2, int y2, float z2);
|
||||||
extern void box(const block *b, float z1, float z2, float z3, float z4);
|
extern void box(const struct block *b, float z1, float z2, float z3, float z4);
|
||||||
extern void dot(int x, int y, float z);
|
extern void dot(int x, int y, float z);
|
||||||
extern void linestyle(float width, int r, int g, int b);
|
extern void linestyle(float width, int r, int g, int b);
|
||||||
extern void newsphere(const OFVector3D *o, float max, int type);
|
extern void newsphere(const OFVector3D *o, float max, int type);
|
||||||
|
@ -270,4 +275,8 @@ extern void teleport(int n, DynamicEntity *d);
|
||||||
extern void baseammo(int gun);
|
extern void baseammo(int gun);
|
||||||
|
|
||||||
// rndmap
|
// rndmap
|
||||||
extern void perlinarea(const block *b, int scale, int seed, int psize);
|
extern void perlinarea(const struct block *b, int scale, int seed, int psize);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -46,6 +46,12 @@ typedef unsigned int uint;
|
||||||
|
|
||||||
#define fast_f2nat(val) ((int)(val))
|
#define fast_f2nat(val) ((int)(val))
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
extern void endianswap(void *, int, int);
|
extern void endianswap(void *, int, int);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue