Cube  Check-in [5e43ae9916]

Overview
Comment:Clean up variables
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5e43ae9916e0f61b00913c7f5c72f9349e1afecab908fd09b193edfd3f10006d
User & Date: js on 2025-03-07 21:16:47
Other Links: manifest | tags
Context
2025-03-07
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
21:02
Clean up identifiers check-in: d35fd65699 user: js tags: trunk
Changes

Modified src/Variable.h from [c2a873c551] to [d1b2d68346].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17


18
19
20
#import "Identifier.h"

OF_ASSUME_NONNULL_BEGIN

@interface Variable : Identifier
@property (readonly, nonatomic) int min, max;
@property (readonly, nonatomic) int *storage;
@property (readonly, nonatomic) void (*function)();
@property (readonly, nonatomic) bool persisted;

- (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE;
- (instancetype)initWithName:(OFString *)name
                         min:(int)min
                         max:(int)max
                     storage:(int *)storage
                    function:(void (*)())function
                   persisted:(bool)persisted;


@end

OF_ASSUME_NONNULL_END







|







|

>
>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#import "Identifier.h"

OF_ASSUME_NONNULL_BEGIN

@interface Variable : Identifier
@property (readonly, nonatomic) int min, max;
@property (readonly, nonatomic) int *storage;
@property (readonly, nonatomic) void (*__cdecl function)();
@property (readonly, nonatomic) bool persisted;

- (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE;
- (instancetype)initWithName:(OFString *)name
                         min:(int)min
                         max:(int)max
                     storage:(int *)storage
                    function:(void (*__cdecl)())function
                   persisted:(bool)persisted;
- (void)printValue;
- (void)setValue:(int)value;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/Variable.m [f42a4c7759] to src/Variable.mm [a7099f1853].

1


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


































21
#import "Variable.h"



@implementation Variable
- (instancetype)initWithName:(OFString *)name
                         min:(int)min
                         max:(int)max
                     storage:(int *)storage
                    function:(void (*)())function
                   persisted:(bool)persisted
{
	self = [super initWithName:name];

	_min = min;
	_max = max;
	_storage = storage;
	_function = function;
	_persisted = persisted;

	return self;
}


































@end

>
>






|












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#import "Variable.h"

#include "cube.h"

@implementation Variable
- (instancetype)initWithName:(OFString *)name
                         min:(int)min
                         max:(int)max
                     storage:(int *)storage
                    function:(void (*__cdecl)())function
                   persisted:(bool)persisted
{
	self = [super initWithName:name];

	_min = min;
	_max = max;
	_storage = storage;
	_function = function;
	_persisted = persisted;

	return self;
}

- (void)printValue
{
	conoutf(@"%@ = %d", self.name, *_storage);
}

- (void)setValue:(int)value
{
	bool outOfRange = false;

	if (_min > _max) {
		conoutf(@"variable is read-only");
		return;
	}

	if (value < _min) {
		value = _min;
		outOfRange = true;
	}

	if (value > _max) {
		value = _max;
		outOfRange = true;
	}

	if (outOfRange)
		conoutf(@"valid range for %@ is %d..%d", self.name, _min, _max);

	*_storage = value;

	if (_function != NULL)
		// call trigger function if available
		_function();
}
@end

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

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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
					               isDown:isdown];
				} else if ([identifier
				               isKindOfClass:[Variable
				                                 class]]) {
					// game defined variables
					if (isdown) {
						if (!w[1][0])
							// var with no value
							// just prints its
							// current value
							conoutf(@"%s = %d", c,
							    *[identifier
							        storage]);
						else {
							if ([identifier min] >
							    [identifier max]) {
								conoutf(
								    @"variable "
								    @"is "
								    @"read-"
								    @"only");
							} else {
								int i1 =
								    ATOI(w[1]);
								if (i1 <
								        [identifier
								            min] ||
								    i1 >
								        [identifier
								            max]) {
									// clamp
									// to
									// valid
									// range
									i1 =
									    i1 < [identifier
									             min]
									        ? [identifier
									              min]
									        : [identifier
									              max];
									conoutf(
									    @"v"
									    @"a"
									    @"l"
									    @"i"
									    @"d"
									    @" "
									    @"r"
									    @"a"
									    @"n"
									    @"g"
									    @"e"
									    @" "
									    @"f"
									    @"o"
									    @"r"
									    @" "
									    @"%"
									    @"s"
									    @" "
									    @"i"
									    @"s"
									    @" "
									    @"%"
									    @"d"
									    @"."
									    @"."
									    @"%"
									    @"d",
									    c,
									    [identifier
									        min],
									    [identifier
									        max]);
								}
								*[identifier
								    storage] =
								    i1;
							}
							if ([identifier
							        function] !=
							    NULL)
								// call trigger
								// function if
								// available
								((void(__cdecl
								        *)())[identifier
								        function])();
						}
					}
				} else if ([identifier
				               isKindOfClass:[Alias class]]) {
					// alias, also used as functions and
					// (global) variables
					for (int i = 1; i < numargs; i++) {
						@autoreleasepool {







<
<
<
<
<
<
<
<
|
<
<
<
<
<
|
<
<
<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







239
240
241
242
243
244
245








246





247



248






249









































250















251
252
253
254
255
256
257
					               isDown:isdown];
				} else if ([identifier
				               isKindOfClass:[Variable
				                                 class]]) {
					// game defined variables
					if (isdown) {
						if (!w[1][0])








							[identifier printValue];





						else



							[identifier






							    setValue:ATOI(









































							                 w[1])];















					}
				} else if ([identifier
				               isKindOfClass:[Alias class]]) {
					// alias, also used as functions and
					// (global) variables
					for (int i = 1; i < numargs; i++) {
						@autoreleasepool {

Modified src/meson.build from [4579a2b4bb] to [b573376159].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
executable('client',
  [
    'Alias.m',
    'Command.mm',
    'Cube.mm',
    'Identifier.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',
    'Menu.m',
    'MenuItem.m',
    'Variable.m',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'commands.mm',
    'console.mm',
    'editing.mm',











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
executable('client',
  [
    'Alias.m',
    'Command.mm',
    'Cube.mm',
    'Identifier.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',
    'Menu.m',
    'MenuItem.m',
    'Variable.mm',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'commands.mm',
    'console.mm',
    'editing.mm',