Cube  Check-in [eac9e3d948]

Overview
Comment:Convert several files to pure Objective-C
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: eac9e3d9480c641e752bce15f24de48bbb77705cd44ef2bb9a04603ca04c67e1
User & Date: js on 2025-03-20 20:59:25
Other Links: manifest | tags
Context
2025-03-20
21:18
Convert more files to pure Objective-C check-in: b250dfa8d4 user: js tags: trunk
20:59
Convert several files to pure Objective-C check-in: eac9e3d948 user: js tags: trunk
20:38
Remove all default arguments from protos.h check-in: ef1d7e47f7 user: js tags: trunk
Changes

Name change from src/Command.mm to src/Command.m.

Renamed and modified src/DynamicEntity.mm [412962c92b] to src/DynamicEntity.m [ace0df653e].

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46







-
+







	int anger;
	char name[260], team[260];
};

@implementation DynamicEntity
+ (size_t)serializedSize
{
	return sizeof(dynent);
	return sizeof(struct dynent);
}

- (instancetype)init
{
	self = [super init];

	_ammo = (int *)OFAllocZeroedMemory(NUMGUNS, sizeof(int));
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+







	return copy;
}

- (OFData *)dataBySerializing
{
	// 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,
		.roll = _roll,
		.maxspeed = _maxspeed,
		.outsidemap = _outsidemap,
		.inwater = _inwater,
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185







-
+







	return [OFData dataWithItems:&data count:sizeof(data)];
}

- (void)setFromSerializedData:(OFData *)data
{
	struct dynent d;

	if (data.count != sizeof(dynent))
	if (data.count != sizeof(struct dynent))
		@throw [OFOutOfRangeException exception];

	memcpy(&d, data.items, data.count);

	_o = d.o;
	_vel = d.vel;
	_yaw = d.yaw;

Renamed and modified src/MD2.mm [3c502ddbf2] to src/MD2.m [9f4a91ba94].

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31







-
+







	uchar vertex[3], lightNormalIndex;
};

struct md2_frame {
	float scale[3];
	float translate[3];
	char name[16];
	md2_vertex vertices[1];
	struct md2_vertex vertices[1];
};

static float
snap(int sn, float f)
{
	return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
}
47
48
49
50
51
52
53
54
55
56
57








58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76



77
78
79
80

81

82

83

84
85
86
87
88
89
90
91

92

93

94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118





119
120
121
122
123
124
125
47
48
49
50
51
52
53




54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77



78
79
80
81
82
83
84
85

86

87
88
89
90
91
92
93
94
95
96
97
98

99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116


117
118
119
120
121
122
123


124
125
126
127
128
129
130
131
132
133
134
135







-
-
-
-
+
+
+
+
+
+
+
+
















-
-
-
+
+
+




+
-
+
-
+

+








+
-
+
-
+

+














-
-
+






-
-
+
+
+
+
+







+ (instancetype)md2
{
	return [[self alloc] init];
}

- (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
{
	OFSeekableStream *stream;
	@try {
		stream = (OFSeekableStream *)[[OFIRIHandler handlerForIRI:IRI]
		    openItemAtIRI:IRI
		             mode:@"r"];
	} @catch (id e) {
		return false;
	}

	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;

	@try {
	_frames = new char[header.frameSize * header.numFrames];
		_frames = OFAllocMemory(header.numFrames, header.frameSize);
	if (_frames == NULL)
	} @catch (OFOutOfMemoryException *e) {
		return false;
	}

	[stream seekToOffset:header.offsetFrames whence:OFSeekSet];
	[stream readIntoBuffer:_frames
	           exactLength:header.frameSize * header.numFrames];

	for (int i = 0; i < header.numFrames; ++i)
		endianswap(_frames + i * header.frameSize, sizeof(float), 6);

	@try {
	_glCommands = new int[header.numGlCommands];
		_glCommands = OFAllocMemory(header.numGlCommands, sizeof(int));
	if (_glCommands == NULL)
	} @catch (OFOutOfMemoryException *e) {
		return false;
	}

	[stream seekToOffset:header.offsetGlCommands whence:OFSeekSet];
	[stream readIntoBuffer:_glCommands
	           exactLength:header.numGlCommands * sizeof(int)];
	endianswap(_glCommands, sizeof(int), header.numGlCommands);

	_numFrames = header.numFrames;
	_numGlCommands = header.numGlCommands;
	_frameSize = header.frameSize;
	_numTriangles = header.numTriangles;
	_numVerts = header.numVertices;

	[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)
	{
		uchar *cv = (uchar *)&cf->vertices[vi].vertex;
		OFVector3D *v = &(_mverts[frame])[vi];
		v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
		v->y =
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
192
193
194
195
196
197
198



199
200
201
202
203
204
205
206







-
-
-
+








			loopi(numVertex)
			{
				float tu = *((float *)command++);
				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));
			}

			xtraverts += numVertex;

			glEnd();
		}

Name change from src/OFString+Cube.mm to src/OFString+Cube.m.

Name change from src/ResolverResult.mm to src/ResolverResult.m.

Name change from src/ResolverThread.mm to src/ResolverThread.m.

Name change from src/ServerInfo.mm to src/ServerInfo.m.

Name change from src/Variable.mm to src/Variable.m.

Name change from src/Client.mm to src/client.m.

Modified src/cube.h from [6d45041e84] to [3a60f1d5c8].

239
240
241
242
243
244
245

246
247
248





249
250
251
252
253
254
255
256
257
258
259
260
261
262



263
264
265
266
267
268
269
239
240
241
242
243
244
245
246



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275







+
-
-
-
+
+
+
+
+














+
+
+







struct vertex {
	float u, v, x, y, z;
	uchar r, g, b, a;
};

// globals ooh naughty

#ifdef __cplusplus
extern sqr *world,
    *wmip[];       // map data, the mips are sequential 2D arrays in memory
extern header hdr; // current map header
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
extern DynamicEntity *player1;
// all the other clients (in multiplayer)
extern OFMutableArray *players;
extern bool editmode;
extern OFMutableArray<Entity *> *ents; // map entities
extern OFVector3D worldpos; // current target of the crosshair in the world
extern int lastmillis;      // last time
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
#define DVF 100.0f

#define VIRTW 2400 // virtual screen size for text & HUD
#define VIRTH 1800

Modified src/meson.build from [8f9d724584] to [0f5a54e283].

1
2
3
4
5


6
7
8

9
10
11
12

13
14
15
16

17
18
19
20


21
22
23


24
25
26
27
28
29
30
1
2
3


4
5
6
7

8
9
10
11

12
13
14
15

16
17
18


19
20
21


22
23
24
25
26
27
28
29
30



-
-
+
+


-
+



-
+



-
+


-
-
+
+

-
-
+
+







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',
    'clients2c.mm',
    'commands.mm',
    'console.mm',
    'editing.mm',
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







  include_directories: [enet_includes],
  link_args: client_link_args,
  link_with: [enet],
  win_subsystem: 'windows')

executable('server',
  [
    'Client.mm',
    'Client.m',
    'ServerEntity.m',
    'server.mm',
    'serverms.mm',
    'serverutil.mm',
    'tools.mm',
  ],
  objcpp_args: ['-DSTANDALONE'],

Modified src/protos.h from [9719c1da0f] to [b7d19818d1].

1




2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
10
11
12

+
+
+
+







// 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);
extern void setvar(OFString *name, int i);
extern int getvar(OFString *name);
extern bool identexists(OFString *name);
43
44
45
46
47
48
49
50


51
52
53
54
55
56
57


58
59
60


61
62
63
64
65




66
67
68
69
70
71
72
47
48
49
50
51
52
53

54
55
56
57
58
59
60


61
62
63


64
65
66




67
68
69
70
71
72
73
74
75
76
77







-
+
+





-
-
+
+

-
-
+
+

-
-
-
-
+
+
+
+








// rendergl
extern void gl_init(int w, int h);
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();
extern void setarraypointers();

// client
extern void localservertoclient(uchar *buf, int len);
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133


134
135
136
137
138
139
140
115
116
117
118
119
120
121


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


137
138
139
140
141
142
143
144
145







-
-
+
+













-
-
+
+







    DynamicEntity *d, bool team, OFString *mdlname, bool hellpig, float scale);
void showscores(bool on);
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);
extern void resettagareas();
extern void settagareas();
extern Entity *newentity(
    int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4);

// worldlight
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,
    float widef, int w, int h);

// worldocull
extern void computeraytable(float vx, float vy);
150
151
152
153
154
155
156
157
158
159
160
161





162
163
164
165
166
167

168
169
170
171
172
173
174
155
156
157
158
159
160
161





162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179







-
-
-
-
-
+
+
+
+
+





-
+







extern int text_width(OFString *string);
extern void draw_envbox(int t, int fogdist);

// editing
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);
extern void renderspheres(int time);
extern void gl_drawhud(
    int w, int h, int curfps, int nquads, int curvert, bool underwater);
extern void readdepth(int w, int h);
266
267
268
269
270
271
272
273





271
272
273
274
275
276
277

278
279
280
281
282







-
+
+
+
+
+
extern void renderentities();
extern void resetspawns();
extern void setspawn(uint i, bool on);
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

Modified src/tools.h from [1aee766b5c] to [277ccadbda].

42
43
44
45
46
47
48



49



50
51
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+
+
+

+
+
+



#ifndef OF_WINDOWS
# define __cdecl
#endif

#define fast_f2nat(val) ((int)(val))

#ifdef __cplusplus
extern "C" {
#endif
extern void endianswap(void *, int, int);
#ifdef __cplusplus
}
#endif

#endif