From cc5cc21aca8b123f05a64ec4e5a237be746350c2 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Tue, 25 Mar 2025 23:52:50 +0000 Subject: [PATCH] Make use of OF_DIRECT FossilOrigin-Name: 7a98b92af94db34093428fc95da00435311c270d74135e69aa94bca16871a023 --- src/Alias.h | 7 ++++--- src/Client.h | 1 + src/Command.h | 3 ++- src/ConsoleLine.h | 1 + src/DynamicEntity.h | 41 ++++++++++++++++++++--------------------- src/Entity.h | 1 + src/Identifier.h | 4 ++-- src/KeyMapping.h | 1 + src/MD2.h | 1 + src/MapModelInfo.h | 1 + src/Menu.h | 1 + src/MenuItem.h | 1 + src/Monster.h | 1 + src/OFString+Cube.h | 1 + src/Player.h | 1 + src/Projectile.h | 1 + src/ResolverResult.h | 1 + src/ResolverThread.h | 1 + src/ServerEntity.h | 1 + src/ServerInfo.h | 1 + src/ServerInfo.m | 8 ++++---- src/Variable.h | 15 ++++++++------- src/clientextras.m | 15 ++++++++------- src/clientgame.m | 6 +++--- src/clients2c.m | 6 ++++-- src/cube.h | 1 + src/meson.build | 1 + 27 files changed, 73 insertions(+), 50 deletions(-) diff --git a/src/Alias.h b/src/Alias.h index 74788cf..e0c197d 100644 --- a/src/Alias.h +++ b/src/Alias.h @@ -3,16 +3,17 @@ OF_ASSUME_NONNULL_BEGIN @interface Alias: Identifier -@property (copy, nonatomic) OFString *action; +@property (direct, copy, nonatomic) OFString *action; @property (readonly, nonatomic) bool persisted; + (instancetype)aliasWithName:(OFString *)name action:(OFString *)action - persisted:(bool)persisted; + persisted:(bool)persisted OF_DIRECT; - (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name action:(OFString *)action - persisted:(bool)persisted; + persisted:(bool)persisted OF_DESIGNATED_INITIALIZER + OF_DIRECT; @end OF_ASSUME_NONNULL_END diff --git a/src/Client.h b/src/Client.h index 28fddb8..6eb88b3 100644 --- a/src/Client.h +++ b/src/Client.h @@ -3,6 +3,7 @@ #import "cube.h" // server side version of "dynent" type +OF_DIRECT_MEMBERS @interface Client: OFObject @property (nonatomic) int type; @property (nonatomic) ENetPeer *peer; diff --git a/src/Command.h b/src/Command.h index 98a88c3..80eaace 100644 --- a/src/Command.h +++ b/src/Command.h @@ -13,6 +13,7 @@ OF_ASSUME_NONNULL_BEGIN }); \ } +OF_DIRECT_MEMBERS @interface Command: Identifier @property (readonly, nonatomic) int argumentsTypes; @@ -22,7 +23,7 @@ OF_ASSUME_NONNULL_BEGIN - (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name argumentsTypes:(int)argumentsTypes - block:(id)block; + block:(id)block OF_DESIGNATED_INITIALIZER; - (int)callWithArguments:(OFArray *)arguments isDown:(bool)isDown; @end diff --git a/src/ConsoleLine.h b/src/ConsoleLine.h index 5648e9d..2bfcca2 100644 --- a/src/ConsoleLine.h +++ b/src/ConsoleLine.h @@ -1,5 +1,6 @@ #import +OF_DIRECT_MEMBERS @interface ConsoleLine: OFObject @property (readonly, copy) OFString *text; @property (readonly) int outtime; diff --git a/src/DynamicEntity.h b/src/DynamicEntity.h index 270a19e..028be2e 100644 --- a/src/DynamicEntity.h +++ b/src/DynamicEntity.h @@ -2,37 +2,36 @@ // players & monsters @interface DynamicEntity: OFObject -@property (class, readonly, nonatomic) size_t serializedSize; +@property (class, direct, readonly, nonatomic) size_t serializedSize; -@property (nonatomic) OFVector3D origin, velocity; +@property (direct, nonatomic) OFVector3D origin, velocity; // used as OFVector3D in one place -@property (nonatomic) float yaw, pitch, roll; +@property (direct, nonatomic) float yaw, pitch, roll; // cubes per second, 24 for player -@property (nonatomic) float maxSpeed; +@property (direct, nonatomic) float maxSpeed; // from his eyes -@property (nonatomic) bool outsideMap; -@property (nonatomic) bool inWater; -@property (nonatomic) bool onFloor, jumpNext; -@property (nonatomic) int move, strafe; +@property (direct, nonatomic) bool outsideMap; +@property (direct, nonatomic) bool inWater; +@property (direct, nonatomic) bool onFloor, jumpNext; +@property (direct, nonatomic) int move, strafe; // see input code -@property (nonatomic) bool k_left, k_right, k_up, k_down; +@property (direct, nonatomic) bool k_left, k_right, k_up, k_down; // used for fake gravity -@property (nonatomic) int timeInAir; +@property (direct, nonatomic) int timeInAir; // bounding box size -@property (nonatomic) float radius, eyeHeight, aboveEye; -@property (nonatomic) int lastUpdate, lag, ping; +@property (direct, nonatomic) float radius, eyeHeight, aboveEye; +@property (direct, nonatomic) int lastUpdate, lag, ping; // one of CS_* below -@property (nonatomic) int state; -@property (nonatomic) int health, armour, armourType, quadMillis; -@property (nonatomic) int gunSelect, gunWait; -@property (nonatomic) int lastAction, lastAttackGun, lastMove; -@property (readonly, nonatomic) int *ammo; -@property (nonatomic) bool attacking; +@property (direct, nonatomic) int state; +@property (direct, nonatomic) int health, armour, armourType, quadMillis; +@property (direct, nonatomic) int gunSelect, gunWait; +@property (direct, nonatomic) int lastAction, lastAttackGun, lastMove; +@property (direct, readonly, nonatomic) int *ammo; +@property (direct, nonatomic) bool attacking; // used by physics to signal ai -@property (nonatomic) bool blocked, moving; -@property (copy, nonatomic) OFString *name; +@property (direct, nonatomic) bool blocked, moving; +@property (direct, copy, nonatomic) OFString *name; -+ (instancetype)entity; - (OFData *)dataBySerializing; - (void)setFromSerializedData:(OFData *)data; - (void)resetMovement; diff --git a/src/Entity.h b/src/Entity.h index 6a86ea0..486356f 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -1,6 +1,7 @@ #import // map entity +OF_DIRECT_MEMBERS @interface Entity: OFObject @property (nonatomic) short x, y, z; // cube aligned position @property (nonatomic) short attr1; diff --git a/src/Identifier.h b/src/Identifier.h index 4348284..d96bf34 100644 --- a/src/Identifier.h +++ b/src/Identifier.h @@ -3,8 +3,8 @@ OF_ASSUME_NONNULL_BEGIN @interface Identifier: OFObject -@property (readonly, copy, nonatomic) OFString *name; -@property (class, readonly, nonatomic) +@property (direct, readonly, copy, nonatomic) OFString *name; +@property (class, direct, readonly, nonatomic) OFMutableDictionary *identifiers; - (instancetype)init OF_UNAVAILABLE; diff --git a/src/KeyMapping.h b/src/KeyMapping.h index 955ad4f..2c7f283 100644 --- a/src/KeyMapping.h +++ b/src/KeyMapping.h @@ -2,6 +2,7 @@ OF_ASSUME_NONNULL_BEGIN +OF_DIRECT_MEMBERS @interface KeyMapping: OFObject @property (readonly) int code; @property (readonly, nonatomic) OFString *name; diff --git a/src/MD2.h b/src/MD2.h index 87d23a9..189a348 100644 --- a/src/MD2.h +++ b/src/MD2.h @@ -4,6 +4,7 @@ OF_ASSUME_NONNULL_BEGIN @class MapModelInfo; +OF_DIRECT_MEMBERS @interface MD2: OFObject @property (nonatomic) MapModelInfo *mmi; @property (copy, nonatomic) OFString *loadname; diff --git a/src/MapModelInfo.h b/src/MapModelInfo.h index 67723bc..fee0288 100644 --- a/src/MapModelInfo.h +++ b/src/MapModelInfo.h @@ -2,6 +2,7 @@ OF_ASSUME_NONNULL_BEGIN +OF_DIRECT_MEMBERS @interface MapModelInfo: OFObject @property (nonatomic) int rad, h, zoff, snap; @property (copy, nonatomic) OFString *name; diff --git a/src/Menu.h b/src/Menu.h index abd817c..f39f41a 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -4,6 +4,7 @@ OF_ASSUME_NONNULL_BEGIN @class MenuItem; +OF_DIRECT_MEMBERS @interface Menu: OFObject @property (readonly, nonatomic) OFString *name; @property (readonly) OFMutableArray *items; diff --git a/src/MenuItem.h b/src/MenuItem.h index b9b4d6f..584d54b 100644 --- a/src/MenuItem.h +++ b/src/MenuItem.h @@ -1,5 +1,6 @@ #import +OF_DIRECT_MEMBERS @interface MenuItem: OFObject @property (readonly, nonatomic) OFString *text, *action; diff --git a/src/Monster.h b/src/Monster.h index 1e4554d..d14f074 100644 --- a/src/Monster.h +++ b/src/Monster.h @@ -1,5 +1,6 @@ #import "DynamicEntity.h" +OF_DIRECT_MEMBERS @interface Monster: DynamicEntity @property (class, readonly, nonatomic) OFMutableArray *monsters; // one of M_* diff --git a/src/OFString+Cube.h b/src/OFString+Cube.h index 2d10d4a..50c4be0 100644 --- a/src/OFString+Cube.h +++ b/src/OFString+Cube.h @@ -1,5 +1,6 @@ #import +OF_DIRECT_MEMBERS @interface OFString (Cube) @property (readonly, nonatomic) int cube_intValue; diff --git a/src/Player.h b/src/Player.h index ceb6b40..d3c7e83 100644 --- a/src/Player.h +++ b/src/Player.h @@ -1,5 +1,6 @@ #import "DynamicEntity.h" +OF_DIRECT_MEMBERS @interface Player: DynamicEntity // special client ent that receives input and acts as camera @property (class, nonatomic) Player *player1; diff --git a/src/Projectile.h b/src/Projectile.h index 73d8a8c..81c86fd 100644 --- a/src/Projectile.h +++ b/src/Projectile.h @@ -2,6 +2,7 @@ @class DynamicEntity; +OF_DIRECT_MEMBERS @interface Projectile: OFObject @property (nonatomic) OFVector3D o, to; @property (nonatomic) float speed; diff --git a/src/ResolverResult.h b/src/ResolverResult.h index 2ae1481..20ee7d2 100644 --- a/src/ResolverResult.h +++ b/src/ResolverResult.h @@ -2,6 +2,7 @@ #import "cube.h" +OF_DIRECT_MEMBERS @interface ResolverResult: OFObject @property (readonly, nonatomic) OFString *query; @property (readonly, nonatomic) ENetAddress address; diff --git a/src/ResolverThread.h b/src/ResolverThread.h index 884bc74..5b4b6b9 100644 --- a/src/ResolverThread.h +++ b/src/ResolverThread.h @@ -1,5 +1,6 @@ #import +OF_DIRECT_MEMBERS @interface ResolverThread: OFThread { volatile bool _stop; diff --git a/src/ServerEntity.h b/src/ServerEntity.h index bcf1a04..c793618 100644 --- a/src/ServerEntity.h +++ b/src/ServerEntity.h @@ -1,6 +1,7 @@ #import // server side version of "entity" type +OF_DIRECT_MEMBERS @interface ServerEntity: OFObject @property (nonatomic) bool spawned; @property (nonatomic) int spawnsecs; diff --git a/src/ServerInfo.h b/src/ServerInfo.h index ddad319..3d542b1 100644 --- a/src/ServerInfo.h +++ b/src/ServerInfo.h @@ -2,6 +2,7 @@ #include +OF_DIRECT_MEMBERS @interface ServerInfo: OFObject @property (readonly, nonatomic) OFString *name; @property (copy, nonatomic) OFString *full; diff --git a/src/ServerInfo.m b/src/ServerInfo.m index b774b1d..10f0cfa 100644 --- a/src/ServerInfo.m +++ b/src/ServerInfo.m @@ -27,16 +27,16 @@ return self; } -- (OFComparisonResult)compare:(id)otherObject +- (OFComparisonResult)compare:(ServerInfo *)otherObject { if (![otherObject isKindOfClass:ServerInfo.class]) @throw [OFInvalidArgumentException exception]; - if (_ping > [otherObject ping]) + if (_ping > otherObject.ping) return OFOrderedDescending; - if (_ping < [otherObject ping]) + if (_ping < otherObject.ping) return OFOrderedAscending; - return [_name compare:[otherObject name]]; + return [_name compare:otherObject.name]; } @end diff --git a/src/Variable.h b/src/Variable.h index b26e743..4bfe712 100644 --- a/src/Variable.h +++ b/src/Variable.h @@ -74,9 +74,9 @@ OF_ASSUME_NONNULL_BEGIN static void var_##name() { body; } @interface Variable: Identifier -@property (readonly, nonatomic) int min, max; -@property (readonly, nonatomic) int *storage; -@property (readonly, nullable, nonatomic) void (*function)(); +@property (direct, readonly, nonatomic) int min, max; +@property (direct, readonly, nonatomic) int *storage; +@property (direct, readonly, nullable, nonatomic) void (*function)(); @property (readonly, nonatomic) bool persisted; + (instancetype)variableWithName:(OFString *)name @@ -84,16 +84,17 @@ OF_ASSUME_NONNULL_BEGIN max:(int)max storage:(int *)storage function:(void (*_Nullable)())function - persisted:(bool)persisted; + persisted:(bool)persisted OF_DIRECT; - (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name min:(int)min max:(int)max storage:(int *)storage function:(void (*_Nullable)())function - persisted:(bool)persisted; -- (void)printValue; -- (void)setValue:(int)value; + persisted:(bool)persisted OF_DESIGNATED_INITIALIZER + OF_DIRECT; +- (void)printValue OF_DIRECT; +- (void)setValue:(int)value OF_DIRECT; @end OF_ASSUME_NONNULL_END diff --git a/src/clientextras.m b/src/clientextras.m index 0573d2b..82a3c46 100644 --- a/src/clientextras.m +++ b/src/clientextras.m @@ -86,13 +86,14 @@ extern int democlientnum; void renderclients() { - [players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) { - if (player != [OFNull null] && - (!demoplayback || i != democlientnum)) - renderclient(player, - isteam(Player.player1.team, [player team]), - @"monster/ogro", false, 1.0f); - }]; + [players + enumerateObjectsUsingBlock:^(Player *player, size_t i, bool *stop) { + if ([player isKindOfClass:Player.class] && + (!demoplayback || i != democlientnum)) + renderclient(player, + isteam(Player.player1.team, [player team]), + @"monster/ogro", false, 1.0f); + }]; } // creation of scoreboard pseudo-menu diff --git a/src/clientgame.m b/src/clientgame.m index 4fba916..8f815bd 100644 --- a/src/clientgame.m +++ b/src/clientgame.m @@ -417,9 +417,9 @@ startmap(OFString *name) // called just after a map load spawncycle = -1; spawnplayer(Player.player1); Player.player1.frags = 0; - for (id player in players) - if (player != [OFNull null]) - [player setFrags:0]; + for (Player *player in players) + if ([player isKindOfClass:Player.class]) + player.frags = 0; resetspawns(); clientmap = name; if (editmode) diff --git a/src/clients2c.m b/src/clients2c.m index d08e1a9..47ed710 100644 --- a/src/clients2c.m +++ b/src/clients2c.m @@ -279,7 +279,8 @@ localservertoclient(unsigned char *buf, int len) } case SV_FRAGS: - [players[cn] setFrags:getint(&p)]; + OFAssert([players[cn] isKindOfClass:Player.class]); + ((Player *)players[cn]).frags = getint(&p); break; case SV_ITEMPICKUP: @@ -371,7 +372,8 @@ localservertoclient(unsigned char *buf, int len) break; case SV_CLIENTPING: - [players[cn] setPing:getint(&p)]; + OFAssert([players[cn] isKindOfClass:Player.class]); + ((Player *)players[cn]).ping = getint(&p); break; case SV_GAMEMODE: diff --git a/src/cube.h b/src/cube.h index 0064273..a69349d 100644 --- a/src/cube.h +++ b/src/cube.h @@ -12,6 +12,7 @@ @class Entity; @class Player; +OF_DIRECT_MEMBERS @interface Cube: OFObject @property (class, readonly, nonatomic) Cube *sharedInstance; @property (readonly, nonatomic) SDL_Window *window; diff --git a/src/meson.build b/src/meson.build index 41af4e3..ca202e9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -70,6 +70,7 @@ executable('client', executable('server', [ 'Client.m', + 'Entity.m', 'ServerEntity.m', 'server.m', 'serverms.m',