Cube  Check-in [cc7ebd7f79]

Overview
Comment:Run newer version of clang-format
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cc7ebd7f79185bc5f0a595af12d4de9ca8ad89c57858d96aaa7c0b8f9802d59f
User & Date: js on 2025-03-26 21:47:31
Other Links: manifest | tags
Context
2025-03-29
13:01
Make more use of OFColor check-in: 932a90c261 user: js tags: trunk
2025-03-26
21:47
Run newer version of clang-format check-in: cc7ebd7f79 user: js tags: trunk
21:44
Remove OF_DIRECT_MEMBERS from category check-in: 5bca00e8e2 user: js tags: trunk
Changes

Modified src/Cube.m from [5cd2f98f97] to [37d676edf6].

80
81
82
83
84
85
86
87

88
89
90
91


92
93
94

95
96
97
98
99
100
101
80
81
82
83
84
85
86

87

88


89
90

91

92
93
94
95
96
97
98
99







-
+
-

-
-
+
+
-

-
+







			passwd = @"";

		_gameDataIRI =
		    [OFFileManager.defaultManager currentDirectoryIRI];
		_userDataIRI =
		    [OFFileManager.defaultManager currentDirectoryIRI];

		[OFFileManager.defaultManager
		[OFFileManager.defaultManager createDirectoryAtIRI:
		    createDirectoryAtIRI:
		        [_userDataIRI IRIByAppendingPathComponent:@"demos"]
		           createParents:true];
		[OFFileManager.defaultManager
		                                     createParents:true];
		[OFFileManager.defaultManager createDirectoryAtIRI:
		    createDirectoryAtIRI:
		        [_userDataIRI IRIByAppendingPathComponent:@"savegames"]
		           createParents:true];
		                                     createParents:true];

		if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0)
			fatal(@"Unable to initialize SDL");

		initEntities();
		initPlayers();

149
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
175
176
177
178
179
147
148
149
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
175
176
177







-
+



-
+



-
+



-
+



-
+







		int xs, ys;
		if (!installtex(2,
		        [_gameDataIRI
		            IRIByAppendingPathComponent:@"data/newchars.png"],
		        &xs, &ys, false) ||
		    !installtex(3,
		        [_gameDataIRI IRIByAppendingPathComponent:
		                          @"data/martin/base.png"],
		                @"data/martin/base.png"],
		        &xs, &ys, false) ||
		    !installtex(6,
		        [_gameDataIRI IRIByAppendingPathComponent:
		                          @"data/martin/ball1.png"],
		                @"data/martin/ball1.png"],
		        &xs, &ys, false) ||
		    !installtex(7,
		        [_gameDataIRI IRIByAppendingPathComponent:
		                          @"data/martin/smoke.png"],
		                @"data/martin/smoke.png"],
		        &xs, &ys, false) ||
		    !installtex(8,
		        [_gameDataIRI IRIByAppendingPathComponent:
		                          @"data/martin/ball2.png"],
		                @"data/martin/ball2.png"],
		        &xs, &ys, false) ||
		    !installtex(9,
		        [_gameDataIRI IRIByAppendingPathComponent:
		                          @"data/martin/ball3.png"],
		                @"data/martin/ball3.png"],
		        &xs, &ys, false) ||
		    !installtex(4,
		        [_gameDataIRI
		            IRIByAppendingPathComponent:@"data/explosion.jpg"],
		        &xs, &ys, false) ||
		    !installtex(5,
		        [_gameDataIRI

Modified src/OFString+Cube.h from [68d220125c] to [521e5eedaf].

1
2
3

4
5
6
7
8
1
2

3

4
5
6
7


-
+
-




#import <ObjFW/ObjFW.h>

@interface
@interface OFString (Cube)
OFString (Cube)
@property (readonly, nonatomic) int cube_intValue;

- (int)cube_intValueWithBase:(unsigned char)base;
@end

Modified src/OFString+Cube.m from [73a4498977] to [fe77741148].

1
2
3
4
5

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

5

6
7
8
9
10
11
12




-
+
-







#import "OFString+Cube.h"

#include "cube.h"

@implementation
@implementation OFString (Cube)
OFString (Cube)
- (int)cube_intValue
{
	@try {
		return self.intValue;
	} @catch (OFInvalidFormatException *e) {
		conoutf(@"invalid value: %@", self);
		return 0;

Modified src/clientextras.m from [8674a8f070] to [89ccbf227a].

110
111
112
113
114
115
116
117
118
119
120



121
122
123
124
125
126
127
110
111
112
113
114
115
116




117
118
119
120
121
122
123
124
125
126







-
-
-
-
+
+
+







static OFMutableArray<OFString *> *scoreLines;

static void
renderscore(Player *d)
{
	OFString *lag = [OFString stringWithFormat:@"%d", d.lag];
	OFString *name = [OFString stringWithFormat:@"(%@)", d.name];
	OFString *line =
	    [OFString stringWithFormat:@"%d\t%@\t%d\t%@\t%@", d.frags,
	              (d.state == CS_LAGGED ? @"LAG" : lag), d.ping, d.team,
	              (d.state == CS_DEAD ? name : d.name)];
	OFString *line = [OFString stringWithFormat:@"%d\t%@\t%d\t%@\t%@",
	    d.frags, (d.state == CS_LAGGED ? @"LAG" : lag), d.ping, d.team,
	    (d.state == CS_DEAD ? name : d.name)];

	if (scoreLines == nil)
		scoreLines = [[OFMutableArray alloc] init];

	[scoreLines addObject:line];

	menumanual(0, scoreLines.count - 1, line);
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180







-
+







			if ([player isKindOfClass:Player.class])
				addteamscore(player);
		if (!demoplayback)
			addteamscore(Player.player1);
		OFMutableString *teamScores = [OFMutableString string];
		for (size_t j = 0; j < teamsUsed; j++)
			[teamScores appendFormat:@"[ %@: %d ]", teamName[j],
			            teamScore[j]];
			    teamScore[j]];
		menumanual(0, scoreLines.count, @"");
		menumanual(0, scoreLines.count + 1, teamScores);
	}
}

// sendmap/getmap commands, should be replaced by more intuitive map downloading

204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217







-
+







	*(unsigned short *)start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	sendpackettoserv(packet);
	conoutf(@"sending map %@ to server...", mapname);
	OFString *msg =
	    [OFString stringWithFormat:@"[map %@ uploaded to server, "
	                               @"\"getmap\" to receive it]",
	              mapname];
	        mapname];
	toserver(msg);
}))

COMMAND(getmap, ARG_NONE, ^{
	ENetPacket *packet =
	    enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
	unsigned char *start = packet->data;

Modified src/clients.m from [0fa2d4f6d1] to [0204d78717].

92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106







-
+







	newteam(name);
})

void
writeclientinfo(OFStream *stream)
{
	[stream writeFormat:@"name \"%@\"\nteam \"%@\"\n", Player.player1.name,
	        Player.player1.team];
	    Player.player1.team];
}

void
connects(OFString *servername)
{
	disconnect(true, false); // reset state
	addserver(servername);

Modified src/commands.m from [45797ae2bc] to [45f7f8cf15].

349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377







-
+













-
+







	[Identifier.identifiers enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, __kindof Identifier *identifier, bool *stop) {
		if (![identifier isKindOfClass:Variable.class] ||
		    ![identifier persisted])
			return;

		[stream writeFormat:@"%@ %d\n", identifier.name,
		        *[identifier storage]];
		    *[identifier storage]];
	}];
	[stream writeString:@"\n"];

	writebinds(stream);
	[stream writeString:@"\n"];

	[Identifier.identifiers enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, __kindof Identifier *identifier, bool *stop) {
		if (![identifier isKindOfClass:Alias.class] ||
		    [identifier.name hasPrefix:@"nextmap_"])
			return;

		[stream writeFormat:@"alias \"%@\" [%@]\n", identifier.name,
		        [identifier action]];
		    [identifier action]];
	}];

	[stream close];
}

COMMAND(writecfg, ARG_NONE, ^{
	writecfg();

Modified src/console.m from [d7f7b48227] to [a83084fb6c].

180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
180
181
182
183
184
185
186


187
188
189
190
191
192
193
194







-
-
+







			switch (code) {
			case SDLK_RETURN:
				break;

			case SDLK_BACKSPACE:
			case SDLK_LEFT:
				if (commandbuf.length > 0)
					[commandbuf
					    deleteCharactersInRange:
					[commandbuf deleteCharactersInRange:
					        OFMakeRange(
					            commandbuf.length - 1, 1)];

				resetcomplete();
				break;

			case SDLK_UP:
273
274
275
276
277
278
279
280

281
272
273
274
275
276
277
278

279
280







-
+


void
writebinds(OFStream *stream)
{
	for (KeyMapping *mapping in keyMappings)
		if (mapping.action.length > 0)
			[stream writeFormat:@"bind \"%@\" [%@]\n", mapping.name,
			        mapping.action];
			    mapping.action];
}

Modified src/renderextras.m from [cde282f0a8] to [d086f388d4].

195
196
197
198
199
200
201
202
203


204
205
206
207
208
209
210
195
196
197
198
199
200
201


202
203
204
205
206
207
208
209
210







-
-
+
+








	int e = closestent();
	if (e >= 0) {
		Entity *c = ents[e];
		closeent =
		    [OFString stringWithFormat:@"closest entity = %@ (%d, %d, "
		                               @"%d, %d), selection = (%d, %d)",
		              entnames[c.type], c.attr1, c.attr2, c.attr3,
		              c.attr4, getvar(@"selxs"), getvar(@"selys")];
		        entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,
		        getvar(@"selxs"), getvar(@"selys")];
	}
}

COMMAND(loadsky, ARG_1STR, (^(OFString *basename) {
	static OFString *lastsky = @"";

	basename = [basename stringByReplacingOccurrencesOfString:@"\\"

Modified src/server.m from [d5e909dacd] to [853a6dbe34].

98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112







-
+







		enet_packet_destroy(packet);
}

void
disconnect_client(int n, OFString *reason)
{
	[OFStdOut writeFormat:@"disconnecting client (%@) [%@]\n",
	          clients[n].hostname, reason];
	    clients[n].hostname, reason];
	enet_peer_disconnect(clients[n].peer);
	clients[n].type = ST_EMPTY;
	send2(true, -1, SV_CDIS, n);
}

void
resetitems()
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500







-
+







			if (event.packet->referenceCount == 0)
				enet_packet_destroy(event.packet);
			break;
		case ENET_EVENT_TYPE_DISCONNECT:
			if ((intptr_t)event.peer->data < 0)
				break;
			[OFStdOut writeFormat:@"disconnected client (%@)\n",
			          clients[(size_t)event.peer->data].hostname];
			    clients[(size_t)event.peer->data].hostname];
			clients[(size_t)event.peer->data].type = ST_EMPTY;
			send2(true, -1, SV_CDIS, (intptr_t)event.peer->data);
			event.peer->data = (void *)-1;
			break;
		case ENET_EVENT_TYPE_NONE:
			break;
		}

Modified src/serverbrowser.m from [6d0f47176b] to [738828d34a].

217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
217
218
219
220
221
222
223

224

225
226
227
228
229
230
231
232
233

234

235
236
237
238
239
240
241







-
+
-









-
+
-







	[servers sort];

	__block int maxmenu = 16;
	[servers enumerateObjectsUsingBlock:^(
	    ServerInfo *si, size_t i, bool *stop) {
		if (si.address.host != ENET_HOST_ANY && si.ping != 9999) {
			if (si.protocol != PROTOCOL_VERSION)
				si.full = [OFString
				si.full = [OFString stringWithFormat:
				    stringWithFormat:
				        @"%@ [different cube protocol]",
				    si.name];
			else
				si.full = [OFString
				    stringWithFormat:@"%d\t%d\t%@, %@: %@ %@",
				    si.ping, si.numplayers,
				    si.map.length > 0 ? si.map : @"[unknown]",
				    modestr(si.mode), si.name, si.sdesc];
		} else
			si.full = [OFString
			si.full = [OFString stringWithFormat:
			    stringWithFormat:
			        (si.address.host != ENET_HOST_ANY
			                ? @"%@ [waiting for server response]"
			                : @"%@ [unknown host]\t"),
			    si.name];

		// cut off too long server descriptions
		if (si.full.length > 50)

Modified src/serverms.m from [45981a3e7c] to [3e3cb4cc55].

26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+







		return;
	}
	ENetBuffer buf;
	OFString *httpget = [OFString stringWithFormat:@"GET %@ HTTP/1.0\n"
	                                               @"Host: %@\n"
	                                               @"Referer: %@\n"
	                                               @"User-Agent: %@\n\n",
	                              req, hostname, ref, agent];
	    req, hostname, ref, agent];
	buf.data = (void *)httpget.UTF8String;
	buf.dataLength = httpget.UTF8StringLength;
	[OFStdOut writeFormat:@"sending request to %@...\n", hostname];
	enet_socket_send(mssock, NULL, &buf, 1);
}

static void
136
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
136
137
138
139
140
141
142



143
144
145
146
147
148
149
150
151







-
-
-
+
+







		if (len < 0)
			return;
		p = &pong[len];
		putint(&p, PROTOCOL_VERSION);
		putint(&p, mode);
		putint(&p, numplayers);
		putint(&p, minremain);
		OFString *mname =
		    [OFString stringWithFormat:@"%@%@",
		              (isfull ? @"[FULL] " : @""), smapname];
		OFString *mname = [OFString stringWithFormat:@"%@%@",
		    (isfull ? @"[FULL] " : @""), smapname];
		sendstring(mname, &p);
		sendstring(serverdesc, &p);
		buf.dataLength = p - pong;
		enet_socket_send(pongsock, &addr, &buf, 1);
	}
}

Modified src/worldio.m from [f78faa674c] to [d379fda5be].

36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50







-
+







		pakname = @"base";
		mapname = name;
	}

	cgzname = [[OFString alloc]
	    initWithFormat:@"packages/%@/%@.cgz", pakname, mapname];
	bakname = [[OFString alloc] initWithFormat:@"packages/%@/%@_%d.BAK",
	                            pakname, mapname, lastmillis];
	    pakname, mapname, lastmillis];
	pcfname = [[OFString alloc]
	    initWithFormat:@"packages/%@/package.cfg", pakname];
	mcfname = [[OFString alloc]
	    initWithFormat:@"packages/%@/%@.cfg", pakname, mapname];
}

// the optimize routines below are here to reduce the detrimental effects of