Use enumerateObjectsUsingBlock: where appropriate

FossilOrigin-Name: fd4460c7b65410b1f78e2f0df253cb5dd3cb73cff37ac75a012f8cbee1cadddd
This commit is contained in:
Jonathan Schleifer 2025-03-20 11:03:23 +00:00
parent 12bf5923b0
commit 4bdb80410d
5 changed files with 29 additions and 37 deletions

View file

@ -80,15 +80,13 @@ extern int democlientnum;
void
renderclients()
{
size_t i = 0;
for (id player in players) {
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null] &&
(!demoplayback || i != democlientnum))
renderclient(player,
isteam(player1.team, [player team]),
@"monster/ogro", false, 1.0f);
i++;
}
}];
}
// creation of scoreboard pseudo-menu

View file

@ -198,22 +198,21 @@ extern int democlientnum;
void
otherplayers()
{
size_t i = 0;
for (id player in players) {
if (player != [OFNull null]) {
const int lagtime = lastmillis - [player lastupdate];
if (lagtime > 1000 && [player state] == CS_ALIVE) {
[player setState:CS_LAGGED];
i++;
continue;
}
if (lagtime && [player state] != CS_DEAD &&
(!demoplayback || i != democlientnum))
// use physics to extrapolate player position
moveplayer(player, 2, false);
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player == [OFNull null])
return;
const int lagtime = lastmillis - [player lastupdate];
if (lagtime > 1000 && [player state] == CS_ALIVE) {
[player setState:CS_LAGGED];
return;
}
i++;
}
if (lagtime && [player state] != CS_DEAD &&
(!demoplayback || i != democlientnum))
// use physics to extrapolate player position
moveplayer(player, 2, false);
}];
}
void

View file

@ -429,17 +429,16 @@ serverslice(int seconds,
checkintermission();
if (interm && seconds > interm) {
interm = 0;
size_t i = 0;
for (Client *client in clients) {
[clients enumerateObjectsUsingBlock:^(
Client *client, size_t i, bool *stop) {
if (client.type != ST_EMPTY) {
// ask a client to trigger map reload
send2(true, i, SV_MAPRELOAD, 0);
mapreload = true;
break;
*stop = true;
return;
}
i++;
}
}];
}
resetserverifempty();

View file

@ -274,10 +274,10 @@ refreshservers()
if (lastmillis - lastinfo >= 5000)
pingservers();
[servers sort];
int maxmenu = 16;
size_t i = 0;
for (ServerInfo *si in servers) {
__block int maxmenu = 16;
[servers enumerateObjectsUsingBlock:^(
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]
@ -306,9 +306,7 @@ refreshservers()
if (!--maxmenu)
return;
i++;
}
}];
}
void

View file

@ -345,7 +345,7 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, DynamicEntity *d, bool local)
void
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
OFVector3D &from, OFVector3D &to)
const OFVector3D &from, const OFVector3D &to)
{
hit(target, damage, d, at);
vdist(dist, v, from, to);
@ -355,7 +355,7 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
void
raydamage(
DynamicEntity *o, OFVector3D &from, OFVector3D &to, DynamicEntity *d, int i)
DynamicEntity *o, const OFVector3D &from, const OFVector3D &to, DynamicEntity *d, int i)
{
if (o.state != CS_ALIVE)
return;
@ -424,12 +424,10 @@ shoot(DynamicEntity *d, const OFVector3D &targ)
if (guns[d.gunselect].projspeed)
return;
size_t i = 0;
for (id player in players) {
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null])
raydamage(player, from, to, d, i);
i++;
}
}];
for (DynamicEntity *monster in getmonsters())
if (monster != d)