Cube  Check-in [11889bf242]

Overview
Comment:Migrate strings for all commands
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 11889bf242c1346514823c710dcf369bebc7339b24399f2c6369b146c644996c
User & Date: js on 2025-03-07 22:30:15
Other Links: manifest | tags
Context
2025-03-07
22:44
Make execute() take an OFString check-in: acc50da079 user: js tags: trunk
22:30
Migrate strings for all commands check-in: 11889bf242 user: js tags: trunk
21:16
Clean up variables check-in: 5e43ae9916 user: js tags: trunk
Changes

Modified src/Command.mm from [5f4325b0d6] to [91c3da5caf].

42
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
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
42
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
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







-
+
-
-
-
+
+
-
-


-
+
-
-
-
-
+
+
-
-


-
+
-
-
-
-
+
+
+
-
-


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





-
-
+
+













-
-
+
+



-
-
+
+
+













-
+







			    ATOI(arguments[3]), ATOI(arguments[4]));
		break;
	case ARG_NONE:
		if (isDown)
			((void(__cdecl *)())_function)();
		break;
	case ARG_1STR:
		if (isDown) {
		if (isDown)
			@autoreleasepool {
				((void(__cdecl *)(OFString *))_function)(
				    @(arguments[1]));
			((void(__cdecl *)(OFString *))_function)(
			    @(arguments[1]));
			}
		}
		break;
	case ARG_2STR:
		if (isDown) {
		if (isDown)
			@autoreleasepool {
				((void(__cdecl *)(
				    OFString *, OFString *))_function)(
				    @(arguments[1]), @(arguments[2]));
			((void(__cdecl *)(OFString *, OFString *))_function)(
			    @(arguments[1]), @(arguments[2]));
			}
		}
		break;
	case ARG_3STR:
		if (isDown) {
		if (isDown)
			@autoreleasepool {
				((void(__cdecl *)(OFString *, OFString *,
				    OFString *))_function)(@(arguments[1]),
				    @(arguments[2]), @(arguments[3]));
			((void(__cdecl *)(
			    OFString *, OFString *, OFString *))_function)(
			    @(arguments[1]), @(arguments[2]), @(arguments[3]));
			}
		}
		break;
	case ARG_5STR:
		if (isDown) {
		if (isDown)
			@autoreleasepool {
				((void(__cdecl *)(OFString *, OFString *,
				    OFString *, OFString *,
			((void(__cdecl *)(OFString *, OFString *, OFString *,
			    OFString *, OFString *))_function)(@(arguments[1]),
				    OFString *))_function)(@(arguments[1]),
				    @(arguments[2]), @(arguments[3]),
				    @(arguments[4]), @(arguments[5]));
			    @(arguments[2]), @(arguments[3]), @(arguments[4]),
			    @(arguments[5]));
			}
		}
		break;
	case ARG_DOWN:
		((void(__cdecl *)(bool))_function)(isDown);
		break;
	case ARG_DWN1:
		((void(__cdecl *)(bool, char *))_function)(
		    isDown, arguments[1]);
		((void(__cdecl *)(bool, OFString *))_function)(
		    isDown, @(arguments[1]));
		break;
	case ARG_1EXP:
		if (isDown)
			return ((int(__cdecl *)(int))_function)(
			    execute(arguments[1]));
		break;
	case ARG_2EXP:
		if (isDown)
			return ((int(__cdecl *)(int, int))_function)(
			    execute(arguments[1]), execute(arguments[2]));
		break;
	case ARG_1EST:
		if (isDown)
			return ((int(__cdecl *)(char *))_function)(
			    arguments[1]);
			return ((int(__cdecl *)(OFString *))_function)(
			    @(arguments[1]));
		break;
	case ARG_2EST:
		if (isDown)
			return ((int(__cdecl *)(char *, char *))_function)(
			    arguments[1], arguments[2]);
			return (
			    (int(__cdecl *)(OFString *, OFString *))_function)(
			    @(arguments[1]), @(arguments[2]));
		break;
	case ARG_VARI:
		if (isDown) {
			// limit, remove
			string r;
			r[0] = 0;
			for (int i = 1; i < numArguments; i++) {
				// make string-list out of all arguments
				strcat_s(r, arguments[i]);
				if (i == numArguments - 1)
					break;
				strcat_s(r, " ");
			}
			((void(__cdecl *)(char *))_function)(r);
			((void(__cdecl *)(OFString *))_function)(@(r));
		}
		break;
	}

	return 0;
}
@end

Modified src/client.mm from [434fc9c95a] to [e93d114d64].

162
163
164
165
166
167
168
169

170

171
172



173
174
175
176

177
178

179
180
181
182
183
184
185
162
163
164
165
166
167
168

169
170
171


172
173
174
175
176
177

178
179

180
181
182
183
184
185
186
187







-
+

+
-
-
+
+
+



-
+

-
+







	}
	conoutf(@"attempting to disconnect...");
	disconnect(0, !disconnecting);
}

string ctext;
void
toserver(const char *text)
toserver(OFString *text)
{
	@autoreleasepool {
	conoutf(@"%s:\f %s", player1->name, text);
	strn0cpy(ctext, text, 80);
		conoutf(@"%s:\f %@", player1->name, text);
		strn0cpy(ctext, text.UTF8String, 80);
	}
}

void
echo(char *text)
echo(OFString *text)
{
	conoutf(@"%s", text);
	conoutf(@"%@", text);
}

COMMAND(echo, ARG_VARI)
COMMANDN(say, toserver, ARG_VARI)
COMMANDN(connect, connects, ARG_1STR)
COMMANDN(disconnect, trydisconnect, ARG_NONE)

Modified src/clientextras.mm from [bd809a3634] to [55a0200404].

200
201
202
203
204
205
206
207
208
209




210
211
212
213
214
215
216
200
201
202
203
204
205
206



207
208
209
210
211
212
213
214
215
216
217







-
-
-
+
+
+
+







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

void
getmap()
{

Modified src/commands.mm from [645f04d656] to [f53c401a17].

459
460
461
462
463
464
465
466

467
468
469
470
471






472
473

474
475
476

477
478
479
480
481

482

483
484
485



486
487
488
489
490

491



492
493
494
495
496
497
498










499
500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
459
460
461
462
463
464
465

466
467




468
469
470
471
472
473
474

475
476
477

478
479
480
481
482

483
484
485



486
487
488
489
490
491
492

493
494
495
496
497







498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519

520
521
522
523
524
525
526
527







-
+

-
-
-
-
+
+
+
+
+
+

-
+


-
+




-
+

+
-
-
-
+
+
+




-
+

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












-
+








		while (execute(cond.get()))
			execute(body.get());
	}
}

void
onrelease(bool on, char *body)
onrelease(bool on, OFString *body)
{
	if (!on)
		execute(body);
}

	if (!on) {
		std::unique_ptr<char> copy(strdup(body.UTF8String));
		execute(copy.get());
	}
}

void
concat(char *s)
concat(OFString *s)
{
	@autoreleasepool {
		alias(@"s", @(s));
		alias(@"s", s);
	}
}

void
concatword(char *s)
concatword(OFString *s)
{
	// The original used this code which does nothing:
	for (char *a = s, *b = s; *a = *b; b++)
		if (*a != ' ')
			a++;
	// for (char *a = s, *b = s; *a = *b; b++)
	//	if (*a != ' ')
	//		a++;
	concat(s);
}

int
listlen(char *a)
listlen(OFString *a_)
{
	@autoreleasepool {
		const char *a = a_.UTF8String;

	if (!*a)
		return 0;
	int n = 0;
	while (*a)
		if (*a++ == ' ')
			n++;
	return n + 1;
		if (!*a)
			return 0;

		int n = 0;
		while (*a)
			if (*a++ == ' ')
				n++;

		return n + 1;
	}
}

void
at(OFString *s_, OFString *pos)
{
	@autoreleasepool {
		int n = (int)pos.longLongValue;
		std::unique_ptr<char> copy(strdup(s_.UTF8String));
		char *s = copy.get();

		loopi(n) s += strspn(s += strcspn(s, " \0"), " ");
		s[strcspn(s, " \0")] = 0;
		concat(s);
		concat(@(s));
	}
}

COMMANDN(loop, loopa, ARG_2STR)
COMMANDN(while, whilea, ARG_2STR)
COMMANDN(if, ifthen, ARG_3STR)
COMMAND(onrelease, ARG_DWN1)
575
576
577
578
579
580
581
582

583
584

585
586
587
588
589
590
591
584
585
586
587
588
589
590

591
592

593
594
595
596
597
598
599
600







-
+

-
+







gt(int a, int b)
{
	return (int)(a > b);
}
COMMANDN(>, gt, ARG_2EXP)

int
strcmpa(char *a, char *b)
strcmpa(OFString *a, OFString *b)
{
	return strcmp(a, b) == 0;
	return [a isEqual:b];
}
COMMANDN(strcmp, strcmpa, ARG_2EST)

int
rndn(int a)
{
	return a > 0 ? rnd(a) : 0;

Modified src/console.mm from [635cf832c8] to [86266db4fd].

124
125
126
127
128
129
130
131

132
133

134
135
136
137
138
139
140
141
142
143


144
145

146
147
148
149
150
151
152
124
125
126
127
128
129
130

131
132

133
134
135
136
137
138
139
140
141


142
143
144

145
146
147
148
149
150
151
152







-
+

-
+








-
-
+
+

-
+







	}

	conoutf(@"unknown key \"%@\"", key);
}
COMMANDN(bind, bindkey, ARG_2STR)

void
saycommand(const char *init) // turns input to the command line on or off
saycommand(OFString *init) // turns input to the command line on or off
{
	saycommandon = (init != NULL);
	saycommandon = (init != nil);
	if (saycommandon)
		SDL_StartTextInput();
	else
		SDL_StopTextInput();

	if (!editmode)
		Cube.sharedInstance.repeatsKeys = saycommandon;

	if (!init)
		init = "";
	if (init == nil)
		init = @"";

	commandbuf = [[OFMutableString alloc] initWithUTF8String:init];
	commandbuf = [init mutableCopy];
}
COMMAND(saycommand, ARG_VARI)

void
mapmsg(OFString *s)
{
	@autoreleasepool {
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265







-
+







					histpos = vhistory.count;
					if ([commandbuf hasPrefix:@"/"]) {
						std::unique_ptr<char> copy(
						    strdup(
						        commandbuf.UTF8String));
						execute(copy.get(), true);
					} else
						toserver(commandbuf.UTF8String);
						toserver(commandbuf);
				}
				saycommand(NULL);
			} else if (code == SDLK_ESCAPE) {
				saycommand(NULL);
			}
		}
	} else if (!menukey(code, isdown)) {

Modified src/protos.h from [6d021108a0] to [0b98b4aee6].

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







extern void finishstrips();
extern void setarraypointers();

// client
extern void localservertoclient(uchar *buf, int len);
extern void connects(OFString *servername);
extern void disconnect(int onlyclean = 0, int async = 0);
extern void toserver(const char *text);
extern void toserver(OFString *text);
extern void addmsg(int rel, int num, int type, ...);
extern bool multiplayer();
extern bool allowedittoggle();
extern void sendpackettoserv(void *packet);
extern void gets2c();
extern void c2sinfo(dynent *d);
extern void neterr(OFString *s);

Modified src/sound.mm from [34f20331ba] to [2ceb58ac38].

127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142




143
144
145


146
147
148


149
150
151


152
153


154
155
156
157
158
159
160
127
128
129
130
131
132
133

134
135







136
137
138
139
140


141
142
143


144
145
146


147
148


149
150
151
152
153
154
155
156
157







-
+

-
-
-
-
-
-
-
+
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+
-
-
+
+







#else
vector<FSOUND_SAMPLE *> samples;
#endif

static OFMutableArray<OFString *> *snames;

int
registersound(char *name_)
registersound(OFString *name)
{
	@autoreleasepool {
		OFString *name = @(name_);

		int i = 0;
		for (OFString *iter in snames) {
			if ([iter isEqual:name])
				return i;
	int i = 0;
	for (OFString *iter in snames) {
		if ([iter isEqual:name])
			return i;

			i++;
		}
		i++;
	}

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

		[snames addObject:name];
		samples.add(NULL);
	[snames addObject:name];
	samples.add(NULL);
		return samples.length() - 1;
	}

	return samples.length() - 1;
}
COMMAND(registersound, ARG_1EST)

void
cleansound()
{
	if (nosound)