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
|
||||
+ (size_t)serializedSize
|
||||
{
|
||||
return sizeof(dynent);
|
||||
return sizeof(struct dynent);
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
|
@ -117,7 +117,7 @@ struct dynent {
|
|||
{
|
||||
// This is frighteningly *TERRIBLE*, but the format used by existing
|
||||
// savegames.
|
||||
dynent data = { .o = _o,
|
||||
struct dynent data = { .o = _o,
|
||||
.vel = _vel,
|
||||
.yaw = _yaw,
|
||||
.pitch = _pitch,
|
||||
|
@ -175,7 +175,7 @@ struct dynent {
|
|||
{
|
||||
struct dynent d;
|
||||
|
||||
if (data.count != sizeof(dynent))
|
||||
if (data.count != sizeof(struct dynent))
|
||||
@throw [OFOutOfRangeException exception];
|
||||
|
||||
memcpy(&d, data.items, data.count);
|
|
@ -21,7 +21,7 @@ struct md2_frame {
|
|||
float scale[3];
|
||||
float translate[3];
|
||||
char name[16];
|
||||
md2_vertex vertices[1];
|
||||
struct md2_vertex vertices[1];
|
||||
};
|
||||
|
||||
static float
|
||||
|
@ -51,10 +51,14 @@ snap(int sn, float f)
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_glCommands)
|
||||
delete[] _glCommands;
|
||||
if (_frames)
|
||||
delete[] _frames;
|
||||
OFFreeMemory(_glCommands);
|
||||
OFFreeMemory(_frames);
|
||||
|
||||
if (_mverts != NULL)
|
||||
for (size_t i = 0; i < _numFrames; i++)
|
||||
OFFreeMemory(_mverts[i]);
|
||||
|
||||
OFFreeMemory(_mverts);
|
||||
}
|
||||
|
||||
- (bool)loadWithIRI:(OFIRI *)IRI
|
||||
|
@ -71,16 +75,18 @@ snap(int sn, float f)
|
|||
if (![stream isKindOfClass:OFSeekableStream.class])
|
||||
return false;
|
||||
|
||||
md2_header header;
|
||||
[stream readIntoBuffer:&header exactLength:sizeof(md2_header)];
|
||||
endianswap(&header, sizeof(int), sizeof(md2_header) / sizeof(int));
|
||||
struct md2_header header;
|
||||
[stream readIntoBuffer:&header exactLength:sizeof(header)];
|
||||
endianswap(&header, sizeof(int), sizeof(header) / sizeof(int));
|
||||
|
||||
if (header.magic != 844121161 || header.version != 8)
|
||||
return false;
|
||||
|
||||
_frames = new char[header.frameSize * header.numFrames];
|
||||
if (_frames == NULL)
|
||||
@try {
|
||||
_frames = OFAllocMemory(header.numFrames, header.frameSize);
|
||||
} @catch (OFOutOfMemoryException *e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[stream seekToOffset:header.offsetFrames whence:OFSeekSet];
|
||||
[stream readIntoBuffer:_frames
|
||||
|
@ -89,9 +95,11 @@ snap(int sn, float f)
|
|||
for (int i = 0; i < header.numFrames; ++i)
|
||||
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
|
||||
|
||||
_glCommands = new int[header.numGlCommands];
|
||||
if (_glCommands == NULL)
|
||||
@try {
|
||||
_glCommands = OFAllocMemory(header.numGlCommands, sizeof(int));
|
||||
} @catch (OFOutOfMemoryException *e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[stream seekToOffset:header.offsetGlCommands whence:OFSeekSet];
|
||||
[stream readIntoBuffer:_glCommands
|
||||
|
@ -106,16 +114,18 @@ snap(int sn, float f)
|
|||
|
||||
[stream close];
|
||||
|
||||
_mverts = new OFVector3D *[_numFrames];
|
||||
loopj(_numFrames) _mverts[j] = NULL;
|
||||
_mverts = OFAllocZeroedMemory(_numFrames, sizeof(OFVector3D *));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn
|
||||
{
|
||||
_mverts[frame] = new OFVector3D[_numVerts];
|
||||
md2_frame *cf = (md2_frame *)((char *)_frames + _frameSize * frame);
|
||||
OFAssert(_mverts[frame] == NULL);
|
||||
|
||||
_mverts[frame] = OFAllocMemory(_numVerts, sizeof(OFVector3D));
|
||||
struct md2_frame *cf =
|
||||
(struct md2_frame *)((char *)_frames + _frameSize * frame);
|
||||
float sc = 16.0f / scale;
|
||||
loop(vi, _numVerts)
|
||||
{
|
||||
|
@ -186,9 +196,7 @@ snap(int sn, float f)
|
|||
float tv = *((float *)command++);
|
||||
glTexCoord2f(tu, tv);
|
||||
int vn = *command++;
|
||||
OFVector3D &v1 = verts1[vn];
|
||||
OFVector3D &v2 = verts2[vn];
|
||||
#define ip(c) v1.c *frac2 + v2.c *frac1
|
||||
#define ip(c) verts1[vn].c *frac2 + verts2[vn].c *frac1
|
||||
glVertex3f(ip(x), ip(z), ip(y));
|
||||
}
|
||||
|
12
src/cube.h
12
src/cube.h
|
@ -243,9 +243,12 @@ struct vertex {
|
|||
|
||||
// globals ooh naughty
|
||||
|
||||
extern sqr *world,
|
||||
*wmip[]; // map data, the mips are sequential 2D arrays in memory
|
||||
extern header hdr; // current map header
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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 cubicsize, mipsize; // cubicsize = ssize^2
|
||||
// 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 xtraverts;
|
||||
extern bool demoplayback;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DMF 16.0f
|
||||
#define DAF 1.0f
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
executable('client',
|
||||
[
|
||||
'Alias.m',
|
||||
'Client.mm',
|
||||
'Command.mm',
|
||||
'Client.m',
|
||||
'Command.m',
|
||||
'ConsoleLine.m',
|
||||
'Cube.mm',
|
||||
'DynamicEntity.mm',
|
||||
'DynamicEntity.m',
|
||||
'Entity.m',
|
||||
'Identifier.m',
|
||||
'KeyMapping.m',
|
||||
'MD2.mm',
|
||||
'MD2.m',
|
||||
'MapModelInfo.m',
|
||||
'Menu.m',
|
||||
'MenuItem.m',
|
||||
'OFString+Cube.mm',
|
||||
'OFString+Cube.m',
|
||||
'PersistentEntity.m',
|
||||
'Projectile.m',
|
||||
'ResolverResult.mm',
|
||||
'ResolverThread.mm',
|
||||
'ResolverResult.m',
|
||||
'ResolverThread.m',
|
||||
'ServerEntity.m',
|
||||
'ServerInfo.mm',
|
||||
'Variable.mm',
|
||||
'ServerInfo.m',
|
||||
'Variable.m',
|
||||
'clients.mm',
|
||||
'clientextras.mm',
|
||||
'clientgame.mm',
|
||||
|
@ -69,7 +69,7 @@ executable('client',
|
|||
|
||||
executable('server',
|
||||
[
|
||||
'Client.mm',
|
||||
'Client.m',
|
||||
'ServerEntity.m',
|
||||
'server.mm',
|
||||
'serverms.mm',
|
||||
|
|
49
src/protos.h
49
src/protos.h
|
@ -1,5 +1,9 @@
|
|||
// protos for ALL external functions in cube...
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// command
|
||||
extern int variable(OFString *name, int min, int cur, int max, int *storage,
|
||||
void (*fun)(), bool persist);
|
||||
|
@ -47,22 +51,23 @@ extern void cleangl();
|
|||
extern void gl_drawframe(int w, int h, float curfps);
|
||||
extern bool installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp);
|
||||
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 int lookuptexture(int tex, int *xs, int *ys);
|
||||
|
||||
// rendercubes
|
||||
extern void resetcubes();
|
||||
extern void render_flat(int tex, int x, int y, int size, int h, sqr *l1,
|
||||
sqr *l2, sqr *l3, sqr *l4, bool isceil);
|
||||
extern void render_flat(int tex, int x, int y, int size, int h, struct sqr *l1,
|
||||
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,
|
||||
float h2, float h3, float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4,
|
||||
bool isceil);
|
||||
float h2, float h3, float h4, struct sqr *l1, struct sqr *l2,
|
||||
struct sqr *l3, struct sqr *l4, bool isceil);
|
||||
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,
|
||||
bool topleft);
|
||||
extern void render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2,
|
||||
sqr *s, sqr *t, sqr *u, sqr *v);
|
||||
float ceil2, int x1, int y1, int x2, int y2, int size, struct sqr *l1,
|
||||
struct sqr *l2, bool topleft);
|
||||
extern void render_tris(int x, int y, int size, bool topleft, struct sqr *h1,
|
||||
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 int renderwater(float hf);
|
||||
extern void finishstrips();
|
||||
|
@ -114,8 +119,8 @@ extern void renderscores();
|
|||
// world
|
||||
extern void setupworld(int factor);
|
||||
extern void empty_world(int factor, bool force);
|
||||
extern void remip(const block *b, int level);
|
||||
extern void remipmore(const block *b, int level);
|
||||
extern void remip(const struct block *b, int level);
|
||||
extern void remipmore(const struct block *b, int level);
|
||||
extern int closestent();
|
||||
extern int findentity(int type, int index);
|
||||
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,
|
||||
int strength, DynamicEntity *owner);
|
||||
extern void cleardlights();
|
||||
extern block *blockcopy(const block *b);
|
||||
extern void blockpaste(const block *b);
|
||||
extern struct block *blockcopy(const struct block *b);
|
||||
extern void blockpaste(const struct block *b);
|
||||
|
||||
// worldrender
|
||||
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 toggleedit();
|
||||
extern void editdrag(bool isdown);
|
||||
extern void setvdeltaxy(int delta, const block *sel);
|
||||
extern void editequalisexy(bool isfloor, const block *sel);
|
||||
extern void edittypexy(int type, const block *sel);
|
||||
extern void edittexxy(int type, int t, const block *sel);
|
||||
extern void editheightxy(bool isfloor, int amount, const block *sel);
|
||||
extern void setvdeltaxy(int delta, const struct block *sel);
|
||||
extern void editequalisexy(bool isfloor, const struct block *sel);
|
||||
extern void edittypexy(int type, const struct block *sel);
|
||||
extern void edittexxy(int type, int t, const struct block *sel);
|
||||
extern void editheightxy(bool isfloor, int amount, const struct block *sel);
|
||||
extern bool noteditmode();
|
||||
extern void pruneundos(int maxremain);
|
||||
|
||||
// renderextras
|
||||
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 linestyle(float width, int r, int g, int b);
|
||||
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);
|
||||
|
||||
// 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))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern void endianswap(void *, int, int);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue