Make use of OF_DIRECT

FossilOrigin-Name: 7a98b92af94db34093428fc95da00435311c270d74135e69aa94bca16871a023
This commit is contained in:
Jonathan Schleifer 2025-03-25 23:52:50 +00:00
parent fb8a872695
commit cc5cc21aca
27 changed files with 73 additions and 50 deletions

View file

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

View file

@ -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;

View file

@ -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<OFString *> *)arguments isDown:(bool)isDown;
@end

View file

@ -1,5 +1,6 @@
#import <ObjFW/ObjFW.h>
OF_DIRECT_MEMBERS
@interface ConsoleLine: OFObject
@property (readonly, copy) OFString *text;
@property (readonly) int outtime;

View file

@ -2,37 +2,36 @@
// players & monsters
@interface DynamicEntity: OFObject <OFCopying>
@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;

View file

@ -1,6 +1,7 @@
#import <ObjFW/ObjFW.h>
// map entity
OF_DIRECT_MEMBERS
@interface Entity: OFObject
@property (nonatomic) short x, y, z; // cube aligned position
@property (nonatomic) short attr1;

View file

@ -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<OFString *, __kindof Identifier *> *identifiers;
- (instancetype)init OF_UNAVAILABLE;

View file

@ -2,6 +2,7 @@
OF_ASSUME_NONNULL_BEGIN
OF_DIRECT_MEMBERS
@interface KeyMapping: OFObject
@property (readonly) int code;
@property (readonly, nonatomic) OFString *name;

View file

@ -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;

View file

@ -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;

View file

@ -4,6 +4,7 @@ OF_ASSUME_NONNULL_BEGIN
@class MenuItem;
OF_DIRECT_MEMBERS
@interface Menu: OFObject
@property (readonly, nonatomic) OFString *name;
@property (readonly) OFMutableArray<MenuItem *> *items;

View file

@ -1,5 +1,6 @@
#import <ObjFW/ObjFW.h>
OF_DIRECT_MEMBERS
@interface MenuItem: OFObject
@property (readonly, nonatomic) OFString *text, *action;

View file

@ -1,5 +1,6 @@
#import "DynamicEntity.h"
OF_DIRECT_MEMBERS
@interface Monster: DynamicEntity
@property (class, readonly, nonatomic) OFMutableArray<Monster *> *monsters;
// one of M_*

View file

@ -1,5 +1,6 @@
#import <ObjFW/ObjFW.h>
OF_DIRECT_MEMBERS
@interface
OFString (Cube)
@property (readonly, nonatomic) int cube_intValue;

View file

@ -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;

View file

@ -2,6 +2,7 @@
@class DynamicEntity;
OF_DIRECT_MEMBERS
@interface Projectile: OFObject
@property (nonatomic) OFVector3D o, to;
@property (nonatomic) float speed;

View file

@ -2,6 +2,7 @@
#import "cube.h"
OF_DIRECT_MEMBERS
@interface ResolverResult: OFObject
@property (readonly, nonatomic) OFString *query;
@property (readonly, nonatomic) ENetAddress address;

View file

@ -1,5 +1,6 @@
#import <ObjFW/ObjFW.h>
OF_DIRECT_MEMBERS
@interface ResolverThread: OFThread
{
volatile bool _stop;

View file

@ -1,6 +1,7 @@
#import <ObjFW/ObjFW.h>
// server side version of "entity" type
OF_DIRECT_MEMBERS
@interface ServerEntity: OFObject
@property (nonatomic) bool spawned;
@property (nonatomic) int spawnsecs;

View file

@ -2,6 +2,7 @@
#include <enet/enet.h>
OF_DIRECT_MEMBERS
@interface ServerInfo: OFObject <OFComparing>
@property (readonly, nonatomic) OFString *name;
@property (copy, nonatomic) OFString *full;

View file

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

View file

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

View file

@ -86,8 +86,9 @@ extern int democlientnum;
void
renderclients()
{
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null] &&
[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]),

View file

@ -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)

View file

@ -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:

View file

@ -12,6 +12,7 @@
@class Entity;
@class Player;
OF_DIRECT_MEMBERS
@interface Cube: OFObject <OFApplicationDelegate>
@property (class, readonly, nonatomic) Cube *sharedInstance;
@property (readonly, nonatomic) SDL_Window *window;

View file

@ -70,6 +70,7 @@ executable('client',
executable('server',
[
'Client.m',
'Entity.m',
'ServerEntity.m',
'server.m',
'serverms.m',