diff --git a/src/Entity.h b/src/Entity.h index 3cc4a5b..6a86ea0 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -1,5 +1,12 @@ -#import "PersistentEntity.h" +#import -@interface Entity: PersistentEntity -@property (nonatomic) bool spawned; // the only dynamic state of a map entity +// map entity +@interface Entity: OFObject +@property (nonatomic) short x, y, z; // cube aligned position +@property (nonatomic) short attr1; +@property (nonatomic) unsigned char type; // type is one of the above +@property (nonatomic) unsigned char attr2, attr3, attr4; +@property (nonatomic) bool spawned; + ++ (instancetype)entity; @end diff --git a/src/Entity.m b/src/Entity.m index 77e1d39..1bbec1c 100644 --- a/src/Entity.m +++ b/src/Entity.m @@ -1,4 +1,8 @@ #import "Entity.h" @implementation Entity ++ (instancetype)entity +{ + return [[self alloc] init]; +} @end diff --git a/src/PersistentEntity.h b/src/PersistentEntity.h deleted file mode 100644 index accf8bd..0000000 --- a/src/PersistentEntity.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -// map entity -@interface PersistentEntity: OFObject -@property (nonatomic) short x, y, z; // cube aligned position -@property (nonatomic) short attr1; -@property (nonatomic) unsigned char type; // type is one of the above -@property (nonatomic) unsigned char attr2, attr3, attr4; - -+ (instancetype)entity; -@end diff --git a/src/PersistentEntity.m b/src/PersistentEntity.m deleted file mode 100644 index be145be..0000000 --- a/src/PersistentEntity.m +++ /dev/null @@ -1,8 +0,0 @@ -#import "PersistentEntity.h" - -@implementation PersistentEntity -+ (instancetype)entity -{ - return [[self alloc] init]; -} -@end diff --git a/src/clientextras.m b/src/clientextras.m index 19fb5df..aa9087a 100644 --- a/src/clientextras.m +++ b/src/clientextras.m @@ -22,7 +22,8 @@ renderclient( int n = 3; float speed = 100.0f; float mz = d.o.z - d.eyeheight + 1.55f * scale; - int basetime = -((intptr_t)d & 0xFFF); + intptr_t tmp = (intptr_t)d; + int basetime = -(tmp & 0xFFF); if (d.state == CS_DEAD) { int r; if (hellpig) { diff --git a/src/clients.m b/src/clients.m index b467568..7bc908b 100644 --- a/src/clients.m +++ b/src/clients.m @@ -372,27 +372,29 @@ void gets2c() // get updates from the server { ENetEvent event; + if (!clienthost) return; + if (connecting && lastmillis / 3000 > connecting / 3000) { conoutf(@"attempting to connect..."); connecting = lastmillis; - ++connattempts; - if (connattempts > 3) { + + if (++connattempts > 3) { conoutf(@"could not connect to server"); disconnect(false, false); return; } } - while ( - clienthost != NULL && enet_host_service(clienthost, &event, 0) > 0) + + while (clienthost != NULL && + enet_host_service(clienthost, &event, 0) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: conoutf(@"connected to server"); connecting = 0; throttle(); break; - case ENET_EVENT_TYPE_RECEIVE: if (disconnecting) conoutf(@"attempting to disconnect..."); @@ -401,12 +403,14 @@ gets2c() // get updates from the server event.packet->dataLength); enet_packet_destroy(event.packet); break; - case ENET_EVENT_TYPE_DISCONNECT: if (disconnecting) disconnect(false, false); else server_err(); return; + case ENET_EVENT_TYPE_NONE: + break; } + } } diff --git a/src/editing.m b/src/editing.m index 927ac04..dd7d691 100644 --- a/src/editing.m +++ b/src/editing.m @@ -454,7 +454,7 @@ edittype(int type) { EDITSEL; if (type == CORNER && - (sel.xs != sel.ys || sel.xs == 3 || sel.xs > 4 && sel.xs != 8 || + (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) || sel.x & ~-sel.xs || sel.y & ~-sel.ys)) { conoutf(@"corner selection must be power of 2 aligned"); return; diff --git a/src/meson.build b/src/meson.build index 4414d58..acab84e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,7 +14,6 @@ executable('client', 'Menu.m', 'MenuItem.m', 'OFString+Cube.m', - 'PersistentEntity.m', 'Projectile.m', 'ResolverResult.m', 'ResolverThread.m', diff --git a/src/physics.m b/src/physics.m index 7aec96f..f47ba9a 100644 --- a/src/physics.m +++ b/src/physics.m @@ -113,46 +113,46 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise) struct sqr *s = S(x, y); float ceil = s->ceil; float floor = s->floor; + switch (s->type) { case SOLID: return false; - case CORNER: { int bx = x, by = y, bs = 1; - if (x == x1 && y == y1 && + if ((x == x1 && y == y1 && cornertest( 0, x, y, -1, -1, &bx, &by, &bs) && - fx1 - bx + fy1 - by <= bs || - x == x2 && y == y1 && + fx1 - bx + fy1 - by <= bs) || + (x == x2 && y == y1 && cornertest( 0, x, y, 1, -1, &bx, &by, &bs) && - fx2 - bx >= fy1 - by || - x == x1 && y == y2 && + fx2 - bx >= fy1 - by) || + (x == x1 && y == y2 && cornertest( 0, x, y, -1, 1, &bx, &by, &bs) && - fx1 - bx <= fy2 - by || - x == x2 && y == y2 && + fx1 - bx <= fy2 - by) || + (x == x2 && y == y2 && cornertest( 0, x, y, 1, 1, &bx, &by, &bs) && - fx2 - bx + fy2 - by >= bs) + fx2 - bx + fy2 - by >= bs)) return false; break; } - - case FHF: // FIXME: too simplistic collision with - // slopes, makes it feels like tiny stairs + // FIXME: too simplistic collision with slopes, makes + // it feels like tiny stairs + case FHF: floor -= (s->vdelta + S(x + 1, y)->vdelta + S(x, y + 1)->vdelta + S(x + 1, y + 1)->vdelta) / 16.0f; break; - case CHF: ceil += (s->vdelta + S(x + 1, y)->vdelta + S(x, y + 1)->vdelta + S(x + 1, y + 1)->vdelta) / 16.0f; } + if (ceil < hi) hi = ceil; if (floor > lo) diff --git a/src/server.m b/src/server.m index 9824700..e316576 100644 --- a/src/server.m +++ b/src/server.m @@ -483,7 +483,6 @@ serverslice(int seconds, if (event.packet->referenceCount == 0) enet_packet_destroy(event.packet); break; - case ENET_EVENT_TYPE_DISCONNECT: if ((intptr_t)event.peer->data < 0) break; @@ -493,6 +492,8 @@ serverslice(int seconds, send2(true, -1, SV_CDIS, (intptr_t)event.peer->data); event.peer->data = (void *)-1; break; + case ENET_EVENT_TYPE_NONE: + break; } if (numplayers > maxclients) diff --git a/src/world.m b/src/world.m index 6c57780..bb4387c 100644 --- a/src/world.m +++ b/src/world.m @@ -129,10 +129,9 @@ remip(const struct block *b, int level) r->type = SEMISOLID; loopk(MAXTYPE) if (nums[k] == 4) r->type = k; if (!SOLID(r)) { - int floor = 127, ceil = -128, num = 0; + int floor = 127, ceil = -128; loopi(4) if (!SOLID(o[i])) { - num++; int fh = o[i]->floor; int ch = o[i]->ceil; if (r->type == SEMISOLID) { @@ -332,7 +331,7 @@ newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4) { int type = findtype(what); - PersistentEntity *e = [PersistentEntity entity]; + Entity *e = [Entity entity]; e.x = x; e.y = y; e.z = z; @@ -351,7 +350,6 @@ newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4) if (!v2 && !v3 && !v4) e.attr2 = 255; break; - case MAPMODEL: e.attr4 = e.attr3; e.attr3 = e.attr2; @@ -365,7 +363,7 @@ newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4) addmsg(1, 10, SV_EDITENT, ents.count, type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4); - [ents addObject:e]; // unsafe! + [ents addObject:e]; if (type == LIGHT) calclight(); diff --git a/src/worldlight.m b/src/worldlight.m index a5fc860..2488c1c 100644 --- a/src/worldlight.m +++ b/src/worldlight.m @@ -4,7 +4,6 @@ #import "DynamicEntity.h" #import "Entity.h" -#import "PersistentEntity.h" extern bool hasoverbright; @@ -12,7 +11,7 @@ VAR(lightscale, 1, 4, 100); // done in realtime, needs to be fast void -lightray(float bx, float by, PersistentEntity *light) +lightray(float bx, float by, Entity *light) { float lx = light.x + (rnd(21) - 10) * 0.1f; float ly = light.y + (rnd(21) - 10) * 0.1f; @@ -39,10 +38,9 @@ lightray(float bx, float by, PersistentEntity *light) l /= lightscale; stepl /= lightscale; - if (light.attr3 || - light.attr4) // coloured light version, special case because - // most lights are white - { + // coloured light version, special case because most lights are + // white + if (light.attr3 || light.attr4) { int dimness = rnd( (255 - (light.attr2 + light.attr3 + light.attr4) / 3) / @@ -123,7 +121,7 @@ lightray(float bx, float by, PersistentEntity *light) } void -calclightsource(PersistentEntity *l) +calclightsource(Entity *l) { int reach = l.attr1; int sx = l.x - reach; @@ -235,7 +233,7 @@ dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength, struct block *copy = blockcopy(&b); [dlights addItem:©]; - PersistentEntity *l = [Entity entity]; + Entity *l = [Entity entity]; l.x = v->x; l.y = v->y; l.z = v->z;