Cube  Check-in [09eb96f339]

Overview
Comment:Make use of the new -[OFString intValue]
Downloads: Tarball | ZIP 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.648
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
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
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]);
			    [arguments[1] intValueWithBase: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]);
			    [arguments[1] intValueWithBase:0],
			    [arguments[2] intValueWithBase: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]);
			    [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)(
			    (int)[arguments[1] longLongValueWithBase:0],
			    (int)[arguments[2] longLongValueWithBase:0],
			    (int)[arguments[3] longLongValueWithBase:0],
			    (int)[arguments[4] longLongValueWithBase:0]);
			    [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:
45
46
47
48
49
50
51
52

53
54
55

56
57
58

59
60
61

62
63
64
65
66
67
68
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;
			_width = optionsParser.argument.intValue;
			break;
		case 'h':
			_height = (int)optionsParser.argument.longLongValue;
			_height = optionsParser.argument.intValue;
			break;
		case 'u':
			uprate = (int)optionsParser.argument.longLongValue;
			uprate = optionsParser.argument.intValue;
			break;
		case 'c':
			maxcl = (int)optionsParser.argument.longLongValue;
			maxcl = optionsParser.argument.intValue;
			break;
		case ':':
		case '=':
		case '?':
			conoutf(@"unknown commandline option");
			[OFApplication terminateWithStatus:1];
		}
16
17
18
19
20
21
22
23

24
25
26

27
28

29
30
31
32
33
34
35
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 = (int)_text.longLongValue;
		x = _text.intValue;
	} @catch (OFInvalidFormatException *e) {
		x = 0;
	}

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

	if (x > y)
		return OFOrderedAscending;
	if (x < y)
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
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;
	sleepwait = msec.intValue + lastmillis;
	sleepcmd = cmd;
}
COMMANDN(sleep, sleepf, ARG_2STR)

void
updateworld(int millis) // main game update loop
{
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
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];
					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
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:
							        [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
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;
		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
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;
		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));
	}
102
103
104
105
106
107
108
109
110


111
112
113
114
115
116
117
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];
	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)
601
602
603
604
605
606
607
608

609
610
611

612
613
614
615
616
617
618
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,
		    (int)[a1 longLongValueWithBase:0],
		    [a1 intValueWithBase:0], [a2 intValueWithBase:0],
		    (int)[a2 longLongValueWithBase:0],
		    (int)[a3 longLongValueWithBase:0],
		    (int)[a4 longLongValueWithBase:0]);
		    [a3 intValueWithBase:0], [a4 intValueWithBase:0]);
	}
}

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)
COMMAND(replace, ARG_NONE)
COMMAND(archvertex, ARG_3INT)
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
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;
		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)
64
65
66
67
68
69
70
71
72
73
74




75
76
77
78
79
80
81
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
	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];
}
59
60
61
62
63
64
65
66
67
68



69
70
71
72
73
74
75
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));
	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
{