Cube  Check-in [09eb96f339]

Overview
Comment:Make use of the new -[OFString intValue]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 09eb96f3397daee11cfda5cbbbcc5caa6d3d9fb9ff3eeb07971e8e3773b65dd6
User & Date: js on 2025-03-11 01:20:17
Other Links: manifest | tags
Context
2025-03-12
00:16
Be more tolerant of invalid arguments check-in: d2f07d884a user: js tags: trunk
2025-03-11
01:20
Make use of the new -[OFString intValue] check-in: 09eb96f339 user: js tags: trunk
2025-03-10
20:52
Fix menu sorting check-in: e1c921ff76 user: js tags: trunk
Changes

Modified src/Command.mm from [3d696164e9] to [07fd8b4957].

34
35
36
37
38
39
40
41
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
- (int)callWithArguments:(OFArray<OFString *> *)arguments isDown:(bool)isDown
{
	switch (_argumentsTypes) {
	case ARG_1INT:
		if (isDown) {
			arguments = padArguments(arguments, 2);
			((void(__cdecl *)(int))_function)(
			    (int)[arguments[1] longLongValueWithBase:0]);
		}
		break;
	case ARG_2INT:
		if (isDown) {
			arguments = padArguments(arguments, 3);
			((void(__cdecl *)(int, int))_function)(
			    (int)[arguments[1] longLongValueWithBase:0],
			    (int)[arguments[2] longLongValueWithBase:0]);
		}
		break;
	case ARG_3INT:
		if (isDown) {
			arguments = padArguments(arguments, 4);
			((void(__cdecl *)(int, int, int))_function)(
			    (int)[arguments[1] longLongValueWithBase:0],
			    (int)[arguments[2] longLongValueWithBase:0],
			    (int)[arguments[3] longLongValueWithBase:0]);
		}
		break;
	case ARG_4INT:
		if (isDown) {
			arguments = padArguments(arguments, 5);
			((void(__cdecl *)(int, int, int, int))_function)(
			    (int)[arguments[1] longLongValueWithBase:0],
			    (int)[arguments[2] longLongValueWithBase:0],
			    (int)[arguments[3] longLongValueWithBase:0],
			    (int)[arguments[4] longLongValueWithBase:0]);
		}
		break;
	case ARG_NONE:
		if (isDown)
			((void(__cdecl *)())_function)();
		break;
	case ARG_1STR:







|






|
|






|
|
|






|
|
|
|







34
35
36
37
38
39
40
41
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
- (int)callWithArguments:(OFArray<OFString *> *)arguments isDown:(bool)isDown
{
	switch (_argumentsTypes) {
	case ARG_1INT:
		if (isDown) {
			arguments = padArguments(arguments, 2);
			((void(__cdecl *)(int))_function)(
			    [arguments[1] intValueWithBase:0]);
		}
		break;
	case ARG_2INT:
		if (isDown) {
			arguments = padArguments(arguments, 3);
			((void(__cdecl *)(int, int))_function)(
			    [arguments[1] intValueWithBase:0],
			    [arguments[2] intValueWithBase:0]);
		}
		break;
	case ARG_3INT:
		if (isDown) {
			arguments = padArguments(arguments, 4);
			((void(__cdecl *)(int, int, int))_function)(
			    [arguments[1] intValueWithBase:0],
			    [arguments[2] intValueWithBase:0],
			    [arguments[3] intValueWithBase:0]);
		}
		break;
	case ARG_4INT:
		if (isDown) {
			arguments = padArguments(arguments, 5);
			((void(__cdecl *)(int, int, int, int))_function)(
			    [arguments[1] intValueWithBase:0],
			    [arguments[2] intValueWithBase:0],
			    [arguments[3] intValueWithBase:0],
			    [arguments[4] intValueWithBase:0]);
		}
		break;
	case ARG_NONE:
		if (isDown)
			((void(__cdecl *)())_function)();
		break;
	case ARG_1STR:

Modified src/Cube.mm from [874b037f55] to [980c015cd9].

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
		{ '\0', nil, 0, NULL, NULL } };
	OFOptionsParser *optionsParser =
	    [OFOptionsParser parserWithOptions:options];
	OFUnichar option;
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'w':
			_width = (int)optionsParser.argument.longLongValue;
			break;
		case 'h':
			_height = (int)optionsParser.argument.longLongValue;
			break;
		case 'u':
			uprate = (int)optionsParser.argument.longLongValue;
			break;
		case 'c':
			maxcl = (int)optionsParser.argument.longLongValue;
			break;
		case ':':
		case '=':
		case '?':
			conoutf(@"unknown commandline option");
			[OFApplication terminateWithStatus:1];
		}







|


|


|


|







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
		{ '\0', nil, 0, NULL, NULL } };
	OFOptionsParser *optionsParser =
	    [OFOptionsParser parserWithOptions:options];
	OFUnichar option;
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'w':
			_width = optionsParser.argument.intValue;
			break;
		case 'h':
			_height = optionsParser.argument.intValue;
			break;
		case 'u':
			uprate = optionsParser.argument.intValue;
			break;
		case 'c':
			maxcl = optionsParser.argument.intValue;
			break;
		case ':':
		case '=':
		case '?':
			conoutf(@"unknown commandline option");
			[OFApplication terminateWithStatus:1];
		}

Modified src/MenuItem.m from [f7a80f995c] to [2e2fceadfe].

16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
	MenuItem *otherItem;

	if (![otherObject isKindOfClass:MenuItem.class])
		@throw [OFInvalidArgumentException exception];

	int x, y;
	@try {
		x = (int)_text.longLongValue;
	} @catch (OFInvalidFormatException *e) {
		x = 0;
	}

	@try {
		y = (int)otherItem.text.longLongValue;
	} @catch (OFInvalidFormatException *e) {
		y = 0;
	}

	if (x > y)
		return OFOrderedAscending;
	if (x < y)







|



>

|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	MenuItem *otherItem;

	if (![otherObject isKindOfClass:MenuItem.class])
		@throw [OFInvalidArgumentException exception];

	int x, y;
	@try {
		x = _text.intValue;
	} @catch (OFInvalidFormatException *e) {
		x = 0;
	}

	@try {
		y = otherItem.text.intValue;
	} @catch (OFInvalidFormatException *e) {
		y = 0;
	}

	if (x > y)
		return OFOrderedAscending;
	if (x < y)

Modified src/clientgame.mm from [5f10611541] to [c71213128a].

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
}

int sleepwait = 0;
static OFString *sleepcmd = nil;
void
sleepf(OFString *msec, OFString *cmd)
{
	sleepwait = (int)msec.longLongValue + lastmillis;
	sleepcmd = cmd;
}
COMMANDN(sleep, sleepf, ARG_2STR)

void
updateworld(int millis) // main game update loop
{







|







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
}

int sleepwait = 0;
static OFString *sleepcmd = nil;
void
sleepf(OFString *msec, OFString *cmd)
{
	sleepwait = msec.intValue + lastmillis;
	sleepcmd = cmd;
}
COMMANDN(sleep, sleepf, ARG_2STR)

void
updateworld(int millis) // main game update loop
{

Modified src/commands.mm from [095c9bcfa3] to [69ee305979].

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
			// empty statement
			if (c.length == 0)
				continue;

			__kindof Identifier *identifier = identifiers[c];
			if (identifier == nil) {
				@try {
					val = (int)[c longLongValueWithBase:0];
				} @catch (OFInvalidFormatException *e) {
					conoutf(@"unknown command: %@", c);
				}
			} else {
				if ([identifier isKindOfClass:Command.class]) {
					// game defined commands use very
					// ad-hoc function signature, and just







|







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
			// empty statement
			if (c.length == 0)
				continue;

			__kindof Identifier *identifier = identifiers[c];
			if (identifier == nil) {
				@try {
					val = [c intValueWithBase:0];
				} @catch (OFInvalidFormatException *e) {
					conoutf(@"unknown command: %@", c);
				}
			} else {
				if ([identifier isKindOfClass:Command.class]) {
					// game defined commands use very
					// ad-hoc function signature, and just
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
					// game defined variables
					if (isDown) {
						if (w[1].length == 0)
							[identifier printValue];
						else
							[identifier
							    setValue:
							        (int)[w[1]
							            longLongValueWithBase:
							                0]];
					}
				} else if ([identifier
				               isKindOfClass:Alias.class]) {
					// alias, also used as functions and
					// (global) variables
					for (int i = 1; i < numargs; i++) {







|
|







254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
					// game defined variables
					if (isDown) {
						if (w[1].length == 0)
							[identifier printValue];
						else
							[identifier
							    setValue:
							        [w[1]
							            intValueWithBase:
							                0]];
					}
				} else if ([identifier
				               isKindOfClass:Alias.class]) {
					// alias, also used as functions and
					// (global) variables
					for (int i = 1; i < numargs; i++) {
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
	execute((![cond hasPrefix:@"0"] ? thenp : elsep));
}

void
loopa(OFString *times, OFString *body)
{
	@autoreleasepool {
		int t = (int)times.longLongValue;

		loopi(t)
		{
			intset(@"i", i);
			execute(body);
		}
	}







|







435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
	execute((![cond hasPrefix:@"0"] ? thenp : elsep));
}

void
loopa(OFString *times, OFString *body)
{
	@autoreleasepool {
		int t = times.intValue;

		loopi(t)
		{
			intset(@"i", i);
			execute(body);
		}
	}
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
	}
}

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));
	}







|







493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
	}
}

void
at(OFString *s_, OFString *pos)
{
	@autoreleasepool {
		int n = pos.intValue;
		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));
	}

Modified src/console.mm from [e0a1b6879f] to [1408af0279].

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

void
keymap(OFString *code, OFString *key, OFString *action)
{
	if (keyMappings == nil)
		keyMappings = [[OFMutableArray alloc] init];

	KeyMapping *mapping =
	    [[KeyMapping alloc] initWithCode:(int)code.longLongValue name:key];
	mapping.action = action;
	[keyMappings addObject:mapping];
}
COMMAND(keymap, ARG_3STR)

void
bindkey(OFString *key, OFString *action)







|
|







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

void
keymap(OFString *code, OFString *key, OFString *action)
{
	if (keyMappings == nil)
		keyMappings = [[OFMutableArray alloc] init];

	KeyMapping *mapping = [[KeyMapping alloc] initWithCode:code.intValue
	                                                  name:key];
	mapping.action = action;
	[keyMappings addObject:mapping];
}
COMMAND(keymap, ARG_3STR)

void
bindkey(OFString *key, OFString *action)

Modified src/editing.mm from [ecc3874fd1] to [b565167d7b].

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{
	EDITSEL;
	@autoreleasepool {
		newentity(sel.x, sel.y, (int)player1.o.z, what,
		    (int)[a1 longLongValueWithBase:0],
		    (int)[a2 longLongValueWithBase:0],
		    (int)[a3 longLongValueWithBase:0],
		    (int)[a4 longLongValueWithBase:0]);
	}
}

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)
COMMAND(replace, ARG_NONE)
COMMAND(archvertex, ARG_3INT)







|
<
<
|







601
602
603
604
605
606
607
608


609
610
611
612
613
614
615
616

void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{
	EDITSEL;
	@autoreleasepool {
		newentity(sel.x, sel.y, (int)player1.o.z, what,
		    [a1 intValueWithBase:0], [a2 intValueWithBase:0],


		    [a3 intValueWithBase:0], [a4 intValueWithBase:0]);
	}
}

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)
COMMAND(replace, ARG_NONE)
COMMAND(archvertex, ARG_3INT)

Modified src/rendergl.mm from [6011a74a0d] to [4da3c2483c].

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}
COMMAND(texturereset, ARG_NONE)

void
texture(OFString *aframe, OFString *name)
{
	@autoreleasepool {
		int num = curtexnum++, frame = (int)aframe.longLongValue;
		if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
			return;
		mapping[num][frame] = 1;
		mapname[num][frame] = name;
	}
}
COMMAND(texture, ARG_2STR)







|







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}
COMMAND(texturereset, ARG_NONE)

void
texture(OFString *aframe, OFString *name)
{
	@autoreleasepool {
		int num = curtexnum++, frame = aframe.intValue;
		if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
			return;
		mapping[num][frame] = 1;
		mapname[num][frame] = name;
	}
}
COMMAND(texture, ARG_2STR)

Modified src/rendermd2.mm from [21d4efdffc] to [53ddda709f].

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
}

void
mapmodel(
    OFString *rad, OFString *h, OFString *zoff, OFString *snap, OFString *name)
{
	MD2 *m = loadmodel(name);
	m.mmi = [[MapModelInfo alloc] initWithRad:(int)rad.longLongValue
	                                        h:(int)h.longLongValue
	                                     zoff:(int)zoff.longLongValue
	                                     snap:(int)snap.longLongValue
	                                     name:m.loadname];

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

	[mapmodels addObject:m];
}







|
|
|
|







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
}

void
mapmodel(
    OFString *rad, OFString *h, OFString *zoff, OFString *snap, OFString *name)
{
	MD2 *m = loadmodel(name);
	m.mmi = [[MapModelInfo alloc] initWithRad:rad.intValue
	                                        h:h.intValue
	                                     zoff:zoff.intValue
	                                     snap:snap.intValue
	                                     name:m.loadname];

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

	[mapmodels addObject:m];
}

Modified src/weapon.mm from [c57ce4ac4b] to [1d3f50a464].

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
	return guns[gun].attackdelay;
}

void
weapon(OFString *a1, OFString *a2, OFString *a3)
{
	selectgun((a1.length > 0 ? (int)a1.longLongValue : -1),
	    (a2.length > 0 ? (int)a2.longLongValue : -1),
	    (a3.length > 0 ? (int)a3.longLongValue : -1));
}
COMMAND(weapon, ARG_3STR)

void
createrays(OFVector3D &from,
    OFVector3D &to) // create random spread of rays for the shotgun
{







|
|
|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
	return guns[gun].attackdelay;
}

void
weapon(OFString *a1, OFString *a2, OFString *a3)
{
	selectgun((a1.length > 0 ? a1.intValue : -1),
	    (a2.length > 0 ? a2.intValue : -1),
	    (a3.length > 0 ? a3.intValue : -1));
}
COMMAND(weapon, ARG_3STR)

void
createrays(OFVector3D &from,
    OFVector3D &to) // create random spread of rays for the shotgun
{