Make more use of convenience methods
FossilOrigin-Name: 89fbd7a1520ecb65809b4c1bd10006ce9bb3a662cb7e7804abaf85d1ee1da63a
This commit is contained in:
parent
4bdb80410d
commit
34b31eb77f
44 changed files with 320 additions and 188 deletions
|
@ -6,6 +6,9 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (copy, nonatomic) OFString *action;
|
||||
@property (readonly, nonatomic) bool persisted;
|
||||
|
||||
+ (instancetype)aliasWithName:(OFString *)name
|
||||
action:(OFString *)action
|
||||
persisted:(bool)persisted;
|
||||
- (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE;
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
action:(OFString *)action
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#import "Alias.h"
|
||||
|
||||
@implementation Alias
|
||||
+ (instancetype)aliasWithName:(OFString *)name
|
||||
action:(OFString *)action
|
||||
persisted:(bool)persisted;
|
||||
{
|
||||
return [[self alloc] initWithName:name
|
||||
action:action
|
||||
persisted:persisted];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
action:(OFString *)action
|
||||
persisted:(bool)persisted
|
||||
|
|
15
src/Client.h
Normal file
15
src/Client.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#import "cube.h"
|
||||
|
||||
// server side version of "dynent" type
|
||||
@interface Client: OFObject
|
||||
@property (nonatomic) int type;
|
||||
@property (nonatomic) ENetPeer *peer;
|
||||
@property (copy, nonatomic) OFString *hostname;
|
||||
@property (copy, nonatomic) OFString *mapvote;
|
||||
@property (copy, nonatomic) OFString *name;
|
||||
@property (nonatomic) int modevote;
|
||||
|
||||
+ (instancetype)client;
|
||||
@end
|
8
src/Client.mm
Normal file
8
src/Client.mm
Normal file
|
@ -0,0 +1,8 @@
|
|||
#import "Client.h"
|
||||
|
||||
@implementation Client
|
||||
+ (instancetype)client
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
@end
|
|
@ -6,6 +6,9 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (readonly, nonatomic) void (*function)();
|
||||
@property (readonly, nonatomic) int argumentsTypes;
|
||||
|
||||
+ (instancetype)commandWithName:(OFString *)name
|
||||
function:(void (*)())function
|
||||
argumentsTypes:(int)argumentsTypes;
|
||||
- (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE;
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
function:(void (*)())function
|
||||
|
|
|
@ -20,6 +20,15 @@ padArguments(OFArray<OFString *> *arguments, size_t count)
|
|||
}
|
||||
|
||||
@implementation Command
|
||||
+ (instancetype)commandWithName:(OFString *)name
|
||||
function:(void (*)())function
|
||||
argumentsTypes:(int)argumentsTypes
|
||||
{
|
||||
return [[self alloc] initWithName:name
|
||||
function:function
|
||||
argumentsTypes:argumentsTypes];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
function:(void (*)())function
|
||||
argumentsTypes:(int)argumentsTypes
|
||||
|
|
9
src/ConsoleLine.h
Normal file
9
src/ConsoleLine.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
@interface ConsoleLine: OFObject
|
||||
@property (readonly, copy) OFString *text;
|
||||
@property (readonly) int outtime;
|
||||
|
||||
+ (instancetype)lineWithText:(OFString *)text outtime:(int)outtime;
|
||||
- (instancetype)initWithText:(OFString *)text outtime:(int)outtime;
|
||||
@end
|
18
src/ConsoleLine.m
Normal file
18
src/ConsoleLine.m
Normal file
|
@ -0,0 +1,18 @@
|
|||
#import "ConsoleLine.h"
|
||||
|
||||
@implementation ConsoleLine
|
||||
+ (instancetype)lineWithText:(OFString *)text outtime:(int)outtime
|
||||
{
|
||||
return [[self alloc] initWithText:text outtime:outtime];
|
||||
}
|
||||
|
||||
- (instancetype)initWithText:(OFString *)text outtime:(int)outtime
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
_text = [text copy];
|
||||
_outtime = outtime;
|
||||
|
||||
return self;
|
||||
}
|
||||
@end
|
|
@ -7,6 +7,8 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (readonly, nonatomic) OFString *name;
|
||||
@property (copy, nonatomic) OFString *action;
|
||||
|
||||
+ (instancetype)mappingWithCode:(int)code name:(OFString *)name;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithCode:(int)code name:(OFString *)name;
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#import "KeyMapping.h"
|
||||
|
||||
@implementation KeyMapping
|
||||
+ (instancetype)mappingWithCode:(int)code name:(OFString *)name
|
||||
{
|
||||
return [[self alloc] initWithCode:code name:name];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCode:(int)code name:(OFString *)name
|
||||
{
|
||||
self = [super init];
|
||||
|
|
|
@ -10,13 +10,12 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic) int mdlnum;
|
||||
@property (nonatomic) bool loaded;
|
||||
|
||||
+ (instancetype)md2;
|
||||
- (bool)loadWithIRI:(OFIRI *)IRI;
|
||||
- (void)renderWithLight:(OFVector3D)light
|
||||
frame:(int)frame
|
||||
range:(int)range
|
||||
x:(float)x
|
||||
y:(float)y
|
||||
z:(float)z
|
||||
position:(OFVector3D)position
|
||||
yaw:(float)yaw
|
||||
pitch:(float)pitch
|
||||
scale:(float)scale
|
||||
|
|
11
src/MD2.mm
11
src/MD2.mm
|
@ -44,6 +44,11 @@ snap(int sn, float f)
|
|||
int _displaylistverts;
|
||||
}
|
||||
|
||||
+ (instancetype)md2
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_glCommands)
|
||||
|
@ -126,9 +131,7 @@ snap(int sn, float f)
|
|||
- (void)renderWithLight:(OFVector3D)light
|
||||
frame:(int)frame
|
||||
range:(int)range
|
||||
x:(float)x
|
||||
y:(float)y
|
||||
z:(float)z
|
||||
position:(OFVector3D)position
|
||||
yaw:(float)yaw
|
||||
pitch:(float)pitch
|
||||
scale:(float)sc
|
||||
|
@ -141,7 +144,7 @@ snap(int sn, float f)
|
|||
snap:sn];
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, z);
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glRotatef(yaw + 180, 0, -1, 0);
|
||||
glRotatef(pitch, 0, 0, 1);
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic) int rad, h, zoff, snap;
|
||||
@property (copy, nonatomic) OFString *name;
|
||||
|
||||
+ (instancetype)infoWithRad:(int)rad
|
||||
h:(int)h
|
||||
zoff:(int)zoff
|
||||
snap:(int)snap
|
||||
name:(OFString *)name;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithRad:(int)rad
|
||||
h:(int)h
|
||||
zoff:(int)zoff
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#import "MapModelInfo.h"
|
||||
|
||||
@implementation MapModelInfo
|
||||
+ (instancetype)infoWithRad:(int)rad
|
||||
h:(int)h
|
||||
zoff:(int)zoff
|
||||
snap:(int)snap
|
||||
name:(OFString *)name
|
||||
{
|
||||
return [[self alloc] initWithRad:rad h:h zoff:zoff snap:snap name:name];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRad:(int)rad
|
||||
h:(int)h
|
||||
zoff:(int)zoff
|
||||
|
|
|
@ -10,6 +10,8 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic) int mwidth;
|
||||
@property (nonatomic) int menusel;
|
||||
|
||||
+ (instancetype)menuWithName:(OFString *)name;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithName:(OFString *)name;
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#import "Menu.h"
|
||||
|
||||
@implementation Menu
|
||||
+ (instancetype)menuWithName:(OFString *)name
|
||||
{
|
||||
return [[self alloc] initWithName:name];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
{
|
||||
self = [super init];
|
||||
|
|
|
@ -3,5 +3,7 @@
|
|||
@interface MenuItem: OFObject
|
||||
@property (readonly, nonatomic) OFString *text, *action;
|
||||
|
||||
+ (instancetype)itemWithText:(OFString *)text action:(OFString *)action;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithText:(OFString *)text action:(OFString *)action;
|
||||
@end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#import "MenuItem.h"
|
||||
|
||||
@implementation MenuItem
|
||||
+ (instancetype)itemWithText:(OFString *)text action:(OFString *)action
|
||||
{
|
||||
return [[self alloc] initWithText:text action:action];
|
||||
}
|
||||
|
||||
- (instancetype)initWithText:(OFString *)text action:(OFString *)action
|
||||
{
|
||||
self = [super init];
|
||||
|
|
|
@ -8,4 +8,6 @@
|
|||
@property (nonatomic) DynamicEntity *owner;
|
||||
@property (nonatomic) int gun;
|
||||
@property (nonatomic) bool inuse, local;
|
||||
|
||||
+ (instancetype)projectile;
|
||||
@end
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#import "Projectile.h"
|
||||
|
||||
@implementation Projectile
|
||||
+ (instancetype)projectile
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
@end
|
||||
|
|
12
src/ResolverResult.h
Normal file
12
src/ResolverResult.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#import "cube.h"
|
||||
|
||||
@interface ResolverResult: OFObject
|
||||
@property (readonly, nonatomic) OFString *query;
|
||||
@property (readonly, nonatomic) ENetAddress address;
|
||||
|
||||
+ (instancetype)resultWithQuery:(OFString *)query address:(ENetAddress)address;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithQuery:(OFString *)query address:(ENetAddress)address;
|
||||
@end
|
18
src/ResolverResult.mm
Normal file
18
src/ResolverResult.mm
Normal file
|
@ -0,0 +1,18 @@
|
|||
#import "ResolverResult.h"
|
||||
|
||||
@implementation ResolverResult
|
||||
+ (instancetype)resultWithQuery:(OFString *)query address:(ENetAddress)address
|
||||
{
|
||||
return [[self alloc] initWithQuery:query address:address];
|
||||
}
|
||||
|
||||
- (instancetype)initWithQuery:(OFString *)query address:(ENetAddress)address
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
_query = query;
|
||||
_address = address;
|
||||
|
||||
return self;
|
||||
}
|
||||
@end
|
12
src/ResolverThread.h
Normal file
12
src/ResolverThread.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
@interface ResolverThread: OFThread
|
||||
{
|
||||
volatile bool _stop;
|
||||
}
|
||||
|
||||
@property (copy, nonatomic) OFString *query;
|
||||
@property (nonatomic) int starttime;
|
||||
|
||||
- (void)stop;
|
||||
@end
|
44
src/ResolverThread.mm
Normal file
44
src/ResolverThread.mm
Normal file
|
@ -0,0 +1,44 @@
|
|||
#import "ResolverThread.h"
|
||||
|
||||
#import "ResolverResult.h"
|
||||
|
||||
extern SDL_sem *resolversem;
|
||||
extern OFMutableArray<OFString *> *resolverqueries;
|
||||
extern OFMutableArray<ResolverResult *> *resolverresults;
|
||||
|
||||
@implementation ResolverThread
|
||||
- (id)main
|
||||
{
|
||||
while (!_stop) {
|
||||
SDL_SemWait(resolversem);
|
||||
|
||||
@synchronized(ResolverThread.class) {
|
||||
if (resolverqueries.count == 0)
|
||||
continue;
|
||||
|
||||
_query = resolverqueries.lastObject;
|
||||
[resolverqueries removeLastObject];
|
||||
_starttime = lastmillis;
|
||||
}
|
||||
|
||||
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT };
|
||||
enet_address_set_host(&address, _query.UTF8String);
|
||||
|
||||
@synchronized(ResolverThread.class) {
|
||||
[resolverresults
|
||||
addObject:[ResolverResult resultWithQuery:_query
|
||||
address:address]];
|
||||
|
||||
_query = NULL;
|
||||
_starttime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)stop
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
@end
|
|
@ -10,6 +10,7 @@
|
|||
@property (nonatomic) int mode, numplayers, ping, protocol, minremain;
|
||||
@property (nonatomic) ENetAddress address;
|
||||
|
||||
+ (instancetype)infoWithName:(OFString *)name;
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithName:(OFString *)name;
|
||||
@end
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#include "cube.h"
|
||||
|
||||
@implementation ServerInfo
|
||||
+ (instancetype)infoWithName:(OFString *)name;
|
||||
{
|
||||
return [[self alloc] initWithName:name];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
{
|
||||
self = [super init];
|
||||
|
|
|
@ -8,6 +8,12 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
@property (readonly, nonatomic) void (*__cdecl function)();
|
||||
@property (readonly, nonatomic) bool persisted;
|
||||
|
||||
+ (instancetype)variableWithName:(OFString *)name
|
||||
min:(int)min
|
||||
max:(int)max
|
||||
storage:(int *)storage
|
||||
function:(void (*__cdecl)())function
|
||||
persisted:(bool)persisted;
|
||||
- (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE;
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
min:(int)min
|
||||
|
|
|
@ -3,6 +3,21 @@
|
|||
#include "cube.h"
|
||||
|
||||
@implementation Variable
|
||||
+ (instancetype)variableWithName:(OFString *)name
|
||||
min:(int)min
|
||||
max:(int)max
|
||||
storage:(int *)storage
|
||||
function:(void (*__cdecl)())function
|
||||
persisted:(bool)persisted
|
||||
{
|
||||
return [[self alloc] initWithName:name
|
||||
min:min
|
||||
max:max
|
||||
storage:storage
|
||||
function:function
|
||||
persisted:persisted];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(OFString *)name
|
||||
min:(int)min
|
||||
max:(int)max
|
||||
|
|
|
@ -71,8 +71,9 @@ renderclient(
|
|||
scale *= 32;
|
||||
mz -= 1.9f;
|
||||
}
|
||||
rendermodel(mdlname, frame[n], range[n], 0, 1.5f, d.o.x, mz, d.o.y,
|
||||
d.yaw + 90, d.pitch / 2, team, scale, speed, 0, basetime);
|
||||
rendermodel(mdlname, frame[n], range[n], 0, 1.5f,
|
||||
OFMakeVector3D(d.o.x, mz, d.o.y), d.yaw + 90, d.pitch / 2, team,
|
||||
scale, speed, 0, basetime);
|
||||
}
|
||||
|
||||
extern int democlientnum;
|
||||
|
@ -161,7 +162,7 @@ renderscores()
|
|||
addteamscore(player);
|
||||
if (!demoplayback)
|
||||
addteamscore(player1);
|
||||
OFMutableString *teamScores = [[OFMutableString alloc] init];
|
||||
OFMutableString *teamScores = [OFMutableString string];
|
||||
for (size_t j = 0; j < teamsUsed; j++)
|
||||
[teamScores appendFormat:@"[ %@: %d ]", teamName[j],
|
||||
teamScore[j]];
|
||||
|
|
|
@ -471,8 +471,6 @@ getclient(int cn) // ensure valid entity
|
|||
neterr(@"clientnum");
|
||||
return nil;
|
||||
}
|
||||
if (players == nil)
|
||||
players = [[OFMutableArray alloc] init];
|
||||
while (cn >= players.count)
|
||||
[players addObject:[OFNull null]];
|
||||
return (players[cn] != [OFNull null] ? players[cn]
|
||||
|
@ -484,8 +482,6 @@ setclient(int cn, id client)
|
|||
{
|
||||
if (cn < 0 || cn >= MAXCLIENTS)
|
||||
neterr(@"clientnum");
|
||||
if (players == nil)
|
||||
players = [[OFMutableArray alloc] init];
|
||||
while (cn >= players.count)
|
||||
[players addObject:[OFNull null]];
|
||||
players[cn] = client;
|
||||
|
|
|
@ -20,9 +20,7 @@ alias(OFString *name, OFString *action)
|
|||
Alias *alias = identifiers[name];
|
||||
|
||||
if (alias == nil) {
|
||||
alias = [[Alias alloc] initWithName:name
|
||||
action:action
|
||||
persisted:true];
|
||||
alias = [Alias aliasWithName:name action:action persisted:true];
|
||||
|
||||
if (identifiers == nil)
|
||||
identifiers = [[OFMutableDictionary alloc] init];
|
||||
|
@ -42,7 +40,7 @@ int
|
|||
variable(OFString *name, int min, int cur, int max, int *storage,
|
||||
void (*function)(), bool persisted)
|
||||
{
|
||||
Variable *variable = [[Variable alloc] initWithName:name
|
||||
Variable *variable = [Variable variableWithName:name
|
||||
min:min
|
||||
max:max
|
||||
storage:storage
|
||||
|
@ -89,7 +87,7 @@ getalias(OFString *name)
|
|||
bool
|
||||
addcommand(OFString *name, void (*function)(), int argumentsTypes)
|
||||
{
|
||||
Command *command = [[Command alloc] initWithName:name
|
||||
Command *command = [Command commandWithName:name
|
||||
function:function
|
||||
argumentsTypes:argumentsTypes];
|
||||
|
||||
|
|
|
@ -4,35 +4,12 @@
|
|||
|
||||
#include <ctype.h>
|
||||
|
||||
#import "ConsoleLine.h"
|
||||
#import "KeyMapping.h"
|
||||
#import "OFString+Cube.h"
|
||||
|
||||
@interface ConsoleLine: OFObject
|
||||
@property (readonly, copy) OFString *text;
|
||||
@property (readonly) int outtime;
|
||||
|
||||
- (instancetype)initWithText:(OFString *)text outtime:(int)outtime;
|
||||
@end
|
||||
|
||||
static OFMutableArray<ConsoleLine *> *conlines;
|
||||
|
||||
@implementation ConsoleLine
|
||||
- (instancetype)initWithText:(OFString *)text outtime:(int)outtime
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
_text = [text copy];
|
||||
_outtime = outtime;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (OFString *)description
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
@end
|
||||
|
||||
const int ndraw = 5;
|
||||
const int WORDWRAP = 80;
|
||||
int conskip = 0;
|
||||
|
@ -59,7 +36,7 @@ conline(OFString *sf, bool highlight) // add a line to the console buffer
|
|||
text = [conlines.lastObject.text mutableCopy];
|
||||
[conlines removeLastObject];
|
||||
} else
|
||||
text = [[OFMutableString alloc] init];
|
||||
text = [OFMutableString string];
|
||||
|
||||
if (highlight)
|
||||
// show line in a different colour, for chat etc.
|
||||
|
@ -70,7 +47,7 @@ conline(OFString *sf, bool highlight) // add a line to the console buffer
|
|||
if (conlines == nil)
|
||||
conlines = [[OFMutableArray alloc] init];
|
||||
|
||||
[conlines insertObject:[[ConsoleLine alloc] initWithText:text
|
||||
[conlines insertObject:[ConsoleLine lineWithText:text
|
||||
outtime:lastmillis]
|
||||
atIndex:0];
|
||||
|
||||
|
@ -135,8 +112,8 @@ keymap(OFString *code, OFString *key, OFString *action)
|
|||
if (keyMappings == nil)
|
||||
keyMappings = [[OFMutableArray alloc] init];
|
||||
|
||||
KeyMapping *mapping =
|
||||
[[KeyMapping alloc] initWithCode:code.cube_intValue name:key];
|
||||
KeyMapping *mapping = [KeyMapping mappingWithCode:code.cube_intValue
|
||||
name:key];
|
||||
mapping.action = action;
|
||||
[keyMappings addObject:mapping];
|
||||
}
|
||||
|
|
|
@ -26,8 +26,9 @@ void
|
|||
renderent(entity &e, OFString *mdlname, float z, float yaw, int frame = 0,
|
||||
int numf = 1, int basetime = 0, float speed = 10.0f)
|
||||
{
|
||||
rendermodel(mdlname, frame, numf, 0, 1.1f, e.x, z + S(e.x, e.y)->floor,
|
||||
e.y, yaw, 0, false, 1.0f, speed, 0, basetime);
|
||||
rendermodel(mdlname, frame, numf, 0, 1.1f,
|
||||
OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false,
|
||||
1.0f, speed, 0, basetime);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -43,8 +44,10 @@ renderentities()
|
|||
if (mmi == nil)
|
||||
continue;
|
||||
rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
|
||||
e.x, (float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
|
||||
e.y, (float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
|
||||
OFMakeVector3D(e.x,
|
||||
(float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
|
||||
e.y),
|
||||
(float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
|
||||
false, 1.0f, 10.0f, mmi.snap);
|
||||
} else {
|
||||
if (OUTBORD(e.x, e.y))
|
||||
|
|
|
@ -95,7 +95,7 @@ newmenu(OFString *name)
|
|||
if (menus == nil)
|
||||
menus = [[OFMutableArray alloc] init];
|
||||
|
||||
[menus addObject:[[Menu alloc] initWithName:name]];
|
||||
[menus addObject:[Menu menuWithName:name]];
|
||||
}
|
||||
COMMAND(newmenu, ARG_1STR)
|
||||
|
||||
|
@ -105,7 +105,7 @@ menumanual(int m, int n, OFString *text)
|
|||
if (n == 0)
|
||||
[menus[m].items removeAllObjects];
|
||||
|
||||
MenuItem *item = [[MenuItem alloc] initWithText:text action:@""];
|
||||
MenuItem *item = [MenuItem itemWithText:text action:@""];
|
||||
[menus[m].items addObject:item];
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ menuitem(OFString *text, OFString *action)
|
|||
Menu *menu = menus.lastObject;
|
||||
|
||||
MenuItem *item =
|
||||
[[MenuItem alloc] initWithText:text
|
||||
[MenuItem itemWithText:text
|
||||
action:(action.length > 0 ? action : text)];
|
||||
[menu.items addObject:item];
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
executable('client',
|
||||
[
|
||||
'Alias.m',
|
||||
'Client.mm',
|
||||
'Command.mm',
|
||||
'ConsoleLine.m',
|
||||
'Cube.mm',
|
||||
'DynamicEntity.mm',
|
||||
'Identifier.m',
|
||||
|
@ -12,9 +14,11 @@ executable('client',
|
|||
'MenuItem.m',
|
||||
'OFString+Cube.mm',
|
||||
'Projectile.m',
|
||||
'ResolverResult.mm',
|
||||
'ResolverThread.mm',
|
||||
'ServerInfo.mm',
|
||||
'Variable.mm',
|
||||
'client.mm',
|
||||
'clients.mm',
|
||||
'clientextras.mm',
|
||||
'clientgame.mm',
|
||||
'clients2c.mm',
|
||||
|
@ -62,6 +66,7 @@ executable('client',
|
|||
|
||||
executable('server',
|
||||
[
|
||||
'Client.mm',
|
||||
'server.mm',
|
||||
'serverms.mm',
|
||||
'serverutil.mm',
|
||||
|
|
|
@ -210,8 +210,8 @@ extern void cleansound();
|
|||
|
||||
// rendermd2
|
||||
extern void rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
|
||||
float x, float y, float z, float yaw, float pitch, bool teammate,
|
||||
float scale, float speed, int snap = 0, int basetime = 0);
|
||||
OFVector3D position, float yaw, float pitch, bool teammate, float scale,
|
||||
float speed, int snap = 0, int basetime = 0);
|
||||
@class MapModelInfo;
|
||||
extern MapModelInfo *getmminfo(int i);
|
||||
|
||||
|
|
|
@ -192,11 +192,11 @@ renderents() // show sparkly thingies for map entities in edit mode
|
|||
int e = closestent();
|
||||
if (e >= 0) {
|
||||
entity &c = ents[e];
|
||||
closeent = [[OFString alloc]
|
||||
initWithFormat:@"closest entity = %@ (%d, %d, %d, %d), "
|
||||
@"selection = (%d, %d)",
|
||||
entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,
|
||||
getvar(@"selxs"), getvar(@"selys")];
|
||||
closeent =
|
||||
[OFString stringWithFormat:@"closest entity = %@ (%d, %d, "
|
||||
@"%d, %d), selection = (%d, %d)",
|
||||
entnames[c.type], c.attr1, c.attr2, c.attr3,
|
||||
c.attr4, getvar(@"selxs"), getvar(@"selys")];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -359,8 +359,8 @@ void
|
|||
drawhudmodel(int start, int end, float speed, int base)
|
||||
{
|
||||
rendermodel(hudgunnames[player1.gunselect], start, end, 0, 1.0f,
|
||||
player1.o.x, player1.o.z, player1.o.y, player1.yaw + 90,
|
||||
player1.pitch, false, 1.0f, speed, 0, base);
|
||||
OFMakeVector3D(player1.o.x, player1.o.z, player1.o.y),
|
||||
player1.yaw + 90, player1.pitch, false, 1.0f, speed, 0, base);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -41,9 +41,9 @@ loadmodel(OFString *name)
|
|||
if (m != nil)
|
||||
return m;
|
||||
|
||||
m = [[MD2 alloc] init];
|
||||
m = [MD2 md2];
|
||||
m.mdlnum = modelnum++;
|
||||
m.mmi = [[MapModelInfo alloc] initWithRad:2 h:2 zoff:0 snap:0 name:@""];
|
||||
m.mmi = [MapModelInfo infoWithRad:2 h:2 zoff:0 snap:0 name:@""];
|
||||
m.loadname = name;
|
||||
|
||||
if (mdllookup == nil)
|
||||
|
@ -60,7 +60,7 @@ mapmodel(
|
|||
{
|
||||
MD2 *m = loadmodel([name stringByReplacingOccurrencesOfString:@"\\"
|
||||
withString:@"/"]);
|
||||
m.mmi = [[MapModelInfo alloc] initWithRad:rad.cube_intValue
|
||||
m.mmi = [MapModelInfo infoWithRad:rad.cube_intValue
|
||||
h:h.cube_intValue
|
||||
zoff:zoff.cube_intValue
|
||||
snap:snap.cube_intValue
|
||||
|
@ -87,13 +87,14 @@ getmminfo(int i)
|
|||
}
|
||||
|
||||
void
|
||||
rendermodel(OFString *mdl, int frame, int range, int tex, float rad, float x,
|
||||
float y, float z, float yaw, float pitch, bool teammate, float scale,
|
||||
rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
|
||||
OFVector3D position, float yaw, float pitch, bool teammate, float scale,
|
||||
float speed, int snap, int basetime)
|
||||
{
|
||||
MD2 *m = loadmodel(mdl);
|
||||
|
||||
if (isoccluded(player1.o.x, player1.o.y, x - rad, z - rad, rad * 2))
|
||||
if (isoccluded(player1.o.x, player1.o.y, position.x - rad,
|
||||
position.z - rad, rad * 2))
|
||||
return;
|
||||
|
||||
delayedload(m);
|
||||
|
@ -102,8 +103,8 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad, float x,
|
|||
glBindTexture(GL_TEXTURE_2D,
|
||||
tex ? lookuptexture(tex, &xs, &ys) : FIRSTMDL + m.mdlnum);
|
||||
|
||||
int ix = (int)x;
|
||||
int iy = (int)z;
|
||||
int ix = (int)position.x;
|
||||
int iy = (int)position.z;
|
||||
OFVector3D light = OFMakeVector3D(1, 1, 1);
|
||||
|
||||
if (!OUTBORD(ix, iy)) {
|
||||
|
@ -124,9 +125,7 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad, float x,
|
|||
[m renderWithLight:light
|
||||
frame:frame
|
||||
range:range
|
||||
x:x
|
||||
y:y
|
||||
z:z
|
||||
position:position
|
||||
yaw:yaw
|
||||
pitch:pitch
|
||||
scale:scale
|
||||
|
|
|
@ -3,21 +3,10 @@
|
|||
|
||||
#include "cube.h"
|
||||
|
||||
#import "Client.h"
|
||||
|
||||
enum { ST_EMPTY, ST_LOCAL, ST_TCPIP };
|
||||
|
||||
// server side version of "dynent" type
|
||||
@interface Client: OFObject
|
||||
@property (nonatomic) int type;
|
||||
@property (nonatomic) ENetPeer *peer;
|
||||
@property (copy, nonatomic) OFString *hostname;
|
||||
@property (copy, nonatomic) OFString *mapvote;
|
||||
@property (copy, nonatomic) OFString *name;
|
||||
@property (nonatomic) int modevote;
|
||||
@end
|
||||
|
||||
@implementation Client
|
||||
@end
|
||||
|
||||
static OFMutableArray<Client *> *clients;
|
||||
|
||||
int maxclients = 8;
|
||||
|
@ -359,7 +348,7 @@ addclient()
|
|||
if (client.type == ST_EMPTY)
|
||||
return client;
|
||||
|
||||
Client *client = [[Client alloc] init];
|
||||
Client *client = [Client client];
|
||||
|
||||
if (clients == nil)
|
||||
clients = [[OFMutableArray alloc] init];
|
||||
|
|
|
@ -4,80 +4,16 @@
|
|||
#include "SDL_thread.h"
|
||||
#include "cube.h"
|
||||
|
||||
#import "ResolverResult.h"
|
||||
#import "ResolverThread.h"
|
||||
#import "ServerInfo.h"
|
||||
|
||||
@interface ResolverThread: OFThread
|
||||
{
|
||||
volatile bool _stop;
|
||||
}
|
||||
|
||||
@property (copy, nonatomic) OFString *query;
|
||||
@property (nonatomic) int starttime;
|
||||
@end
|
||||
|
||||
@interface ResolverResult: OFObject
|
||||
@property (readonly, nonatomic) OFString *query;
|
||||
@property (readonly, nonatomic) ENetAddress address;
|
||||
|
||||
- (instancetype)init OF_UNAVAILABLE;
|
||||
- (instancetype)initWithQuery:(OFString *)query address:(ENetAddress)address;
|
||||
@end
|
||||
|
||||
static OFMutableArray<ResolverThread *> *resolverthreads;
|
||||
static OFMutableArray<OFString *> *resolverqueries;
|
||||
static OFMutableArray<ResolverResult *> *resolverresults;
|
||||
static SDL_sem *resolversem;
|
||||
OFMutableArray<OFString *> *resolverqueries;
|
||||
OFMutableArray<ResolverResult *> *resolverresults;
|
||||
SDL_sem *resolversem;
|
||||
static int resolverlimit = 1000;
|
||||
|
||||
@implementation ResolverThread
|
||||
- (id)main
|
||||
{
|
||||
while (!_stop) {
|
||||
SDL_SemWait(resolversem);
|
||||
|
||||
@synchronized(ResolverThread.class) {
|
||||
if (resolverqueries.count == 0)
|
||||
continue;
|
||||
|
||||
_query = resolverqueries.lastObject;
|
||||
[resolverqueries removeLastObject];
|
||||
_starttime = lastmillis;
|
||||
}
|
||||
|
||||
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT };
|
||||
enet_address_set_host(&address, _query.UTF8String);
|
||||
|
||||
@synchronized(ResolverThread.class) {
|
||||
[resolverresults addObject:[[ResolverResult alloc]
|
||||
initWithQuery:_query
|
||||
address:address]];
|
||||
|
||||
_query = NULL;
|
||||
_starttime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)stop
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ResolverResult
|
||||
- (instancetype)initWithQuery:(OFString *)query address:(ENetAddress)address
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
_query = query;
|
||||
_address = address;
|
||||
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
void
|
||||
resolverinit(int threads, int limit)
|
||||
{
|
||||
|
@ -88,7 +24,7 @@ resolverinit(int threads, int limit)
|
|||
resolversem = SDL_CreateSemaphore(0);
|
||||
|
||||
while (threads > 0) {
|
||||
ResolverThread *rt = [[ResolverThread alloc] init];
|
||||
ResolverThread *rt = [ResolverThread thread];
|
||||
rt.name = @"resolverthread";
|
||||
[resolverthreads addObject:rt];
|
||||
[rt start];
|
||||
|
@ -104,7 +40,7 @@ resolverstop(size_t i, bool restart)
|
|||
[rt stop];
|
||||
|
||||
if (restart) {
|
||||
rt = [[ResolverThread alloc] init];
|
||||
rt = [ResolverThread thread];
|
||||
rt.name = @"resolverthread";
|
||||
|
||||
resolverthreads[i] = rt;
|
||||
|
@ -187,7 +123,7 @@ addserver(OFString *servername)
|
|||
if (servers == nil)
|
||||
servers = [[OFMutableArray alloc] init];
|
||||
|
||||
[servers addObject:[[ServerInfo alloc] initWithName:servername]];
|
||||
[servers addObject:[ServerInfo infoWithName:servername]];
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -280,19 +216,19 @@ refreshservers()
|
|||
ServerInfo *si, size_t i, bool *stop) {
|
||||
if (si.address.host != ENET_HOST_ANY && si.ping != 9999) {
|
||||
if (si.protocol != PROTOCOL_VERSION)
|
||||
si.full = [[OFString alloc]
|
||||
initWithFormat:
|
||||
si.full = [OFString
|
||||
stringWithFormat:
|
||||
@"%@ [different cube protocol]",
|
||||
si.name];
|
||||
else
|
||||
si.full = [[OFString alloc]
|
||||
initWithFormat:@"%d\t%d\t%@, %@: %@ %@",
|
||||
si.full = [OFString
|
||||
stringWithFormat:@"%d\t%d\t%@, %@: %@ %@",
|
||||
si.ping, si.numplayers,
|
||||
si.map.length > 0 ? si.map : @"[unknown]",
|
||||
modestr(si.mode), si.name, si.sdesc];
|
||||
} else
|
||||
si.full = [[OFString alloc]
|
||||
initWithFormat:
|
||||
si.full = [OFString
|
||||
stringWithFormat:
|
||||
(si.address.host != ENET_HOST_ANY
|
||||
? @"%@ [waiting for server response]"
|
||||
: @"%@ [unknown host]\t"),
|
||||
|
|
|
@ -158,8 +158,7 @@ servermsinit(OFString *master_, OFString *sdesc, bool listen)
|
|||
if (!mid)
|
||||
mid = master;
|
||||
masterpath = @(mid);
|
||||
masterbase = [[OFString alloc] initWithUTF8String:master
|
||||
length:mid - master];
|
||||
masterbase = [OFString stringWithUTF8String:master length:mid - master];
|
||||
serverdesc = sdesc;
|
||||
|
||||
if (listen) {
|
||||
|
|
|
@ -148,10 +148,8 @@ newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
|||
for (size_t i = 0; i < MAXPROJ; i++) {
|
||||
Projectile *p = projs[i];
|
||||
|
||||
if (p == nil) {
|
||||
p = [[Projectile alloc] init];
|
||||
projs[i] = p;
|
||||
}
|
||||
if (p == nil)
|
||||
projs[i] = p = [Projectile projectile];
|
||||
|
||||
if (p.inuse)
|
||||
continue;
|
||||
|
@ -354,8 +352,8 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
|
|||
}
|
||||
|
||||
void
|
||||
raydamage(
|
||||
DynamicEntity *o, const OFVector3D &from, const OFVector3D &to, DynamicEntity *d, int i)
|
||||
raydamage(DynamicEntity *o, const OFVector3D &from, const OFVector3D &to,
|
||||
DynamicEntity *d, int i)
|
||||
{
|
||||
if (o.state != CS_ALIVE)
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue