]> git.pond.sub.org Git - empserver/commitdiff
Store sequence numbers more compactly
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 31 Dec 2009 09:30:54 +0000 (10:30 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 19 Jan 2010 07:31:10 +0000 (08:31 +0100)
Store them and ef_type in bit-fields.

Allocate eight bits for ef_type.  Values range from 0 to EF_GAME
(currently 16), so this is plenty.

Allocate twelve bits for sequence numbers.  Sequence number mismatches
are now missed when the numbers are equal modulo 2^12.  Still
sufficiently improbable.

Common machines store the bit-fields in a 32 bit word.  There are
twelve bits left in that word for future use.  Total savings 16 bits,
which is exactly what the previous commit spent on wider uids on
common machines.

15 files changed:
include/commodity.h
include/empobj.h
include/file.h
include/game.h
include/land.h
include/loan.h
include/lost.h
include/nat.h
include/nuke.h
include/plane.h
include/sect.h
include/ship.h
include/trade.h
include/treaty.h
src/lib/subs/unitsub.c

index a36d9b45dd8d1a161cdd71ca9d66b67330116b0d..1f03fa78e7026b40d6ab3c1b3fd80a88f876071b 100644 (file)
@@ -42,9 +42,9 @@
 
 struct comstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned com_seqno: 12;
     int com_uid;
-    unsigned com_seqno;
     time_t com_timestamp;
     natid com_owner;
     /* end of part matching struct empobj */
index 5ff65486fbe369844d8d10e21394300ec12090fe..9574073d071e65f7437f6b450330f9f7c19b267d 100644 (file)
@@ -55,9 +55,9 @@ struct empobj {
      * initial part must match struct emptypedstr
      * valid if EFF_TYPED is set in table's flags
      */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned seqno: 12;
     int uid;
-    unsigned seqno;
     time_t timestamp;
     /* end of part matching struct emptypedstr */
     natid own;         /* valid if EFF_OWNER is in table's flags */
@@ -76,7 +76,6 @@ struct empobj {
 };
 
 union empobj_storage {
-    short ef_type;
     struct empobj gen;
     struct comstr comm;
     struct gamestr game;
index e0a56cadbe60e719e91e349250a56bf39e85c319..4c0424b42d73f8ac55a1d13a496850ed08f54d15 100644 (file)
@@ -85,9 +85,9 @@ struct empfile {
 };
 
 struct emptypedstr {
-    short ef_type;
+    signed ef_type: 8;
+    unsigned seqno: 12;
     int uid;
-    unsigned seqno;
     time_t timestamp;
 };
 
index a465d2ae19303bc30390423f138565e16f75ba8f..a58d1bdb884b3e35a7b50c51d6567bc62d7d1e88 100644 (file)
@@ -38,9 +38,9 @@
 
 struct gamestr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned game_seqno: 12;
     int game_uid;
-    unsigned game_seqno;
     time_t game_timestamp;
     /* end of part matching struct empobj */
     char game_upd_disable;     /* updates disabled? */
index 91d9f01c38e80a0892ba9f2b63e3e616c3442f48..5b1fb707954641194e0410bf41bfc1e4f1163519 100644 (file)
@@ -49,9 +49,9 @@
 
 struct lndstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned lnd_seqno: 12;
     int lnd_uid;               /* unit id (land #) */
-    unsigned lnd_seqno;
     time_t lnd_timestamp;      /* Last time this unit was touched */
     natid lnd_own;             /* owner's country num */
     coord lnd_x;               /* x location in abs coords */
index 1015acb4bd6262e0ef0353cbc5428d5fe6b64609..d4fae4c701f441730a71561764c59580fde9dbe5 100644 (file)
@@ -42,9 +42,9 @@
 
 struct lonstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned l_seqno: 12;
     int l_uid;
-    unsigned l_seqno;
     time_t l_timestamp;
     /* end of part matching struct empobj */
     natid l_loner;             /* loan shark */
index 63e68d8c5f41f34f169de329cba99429cab36ae9..0e40470c3319973b99e8d51779b9e6f5a473695d 100644 (file)
@@ -39,9 +39,9 @@
 
 struct loststr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned lost_seqno: 12;
     int lost_uid;
-    unsigned lost_seqno;
     time_t lost_timestamp;     /* When it was lost */
     natid lost_owner;          /* Who lost it */
     /* end of part matching struct empobj */
index ce1390151fcf144d2b803da582feafb6db767c4c..5b658bdbb89c2de289e32fdd257154ba39f5b3db 100644 (file)
@@ -70,9 +70,9 @@ enum nat_status {
  */
 struct realmstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned r_seqno: 12;
     int r_uid;                 /* realm table index */
-    unsigned r_seqno;
     time_t r_timestamp;                /* Last time this realm was touched */
     natid r_cnum;              /* country number */
     /* end of part matching struct empobj */
@@ -83,9 +83,9 @@ struct realmstr {
 
 struct natstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned nat_seqno: 12;
     int nat_uid;               /* equals nat_cnum */
-    unsigned nat_seqno;
     time_t nat_timestamp;
     natid nat_cnum;            /* our country number */
     /* end of part matching struct empobj */
index d24a83edcb9d2d3bc6b884097370cc2713b57fb2..6a0db83fff36f56d4e8d92741aecee34084ffd9a 100644 (file)
@@ -42,9 +42,9 @@
 
 struct nukstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned nuk_seqno: 12;
     int nuk_uid;               /* unit id (nuke #) */
-    unsigned nuk_seqno;
     time_t nuk_timestamp;      /* Last time this nuke was touched */
     natid nuk_own;
     coord nuk_x, nuk_y;                /* current loc of device */
index fa3a3f5dbc4f2fdc6781079835e8a82538472913..e77ee93acef4438ffab683ae145d9d20cd73b850 100644 (file)
@@ -46,9 +46,9 @@
 
 struct plnstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned pln_seqno: 12;
     int pln_uid;               /* unit id (plane #) */
-    unsigned pln_seqno;
     time_t pln_timestamp;      /* Last time this plane was touched */
     natid pln_own;             /* owning country */
     coord pln_x;               /* plane x-y */
index 01fda989dad2b496b346e91fda6281fcabe3f55a..9b6fe8d8e18d7e6d27926259ba68a8ba1c0bd645 100644 (file)
@@ -44,9 +44,9 @@
 
 struct sctstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned sct_seqno: 12;
     int sct_uid;               /* equals XYOFFSET(sct_x, sct_y) */
-    unsigned sct_seqno;
     time_t sct_timestamp;      /* Last time this sector was written to */
     natid sct_own;             /* owner's country num */
     coord sct_x;               /* x coord of sector */
index a0b325d38e1b46805933ccf87eace31d4f9e6982..23cefa1f79e7eca718c2c150f3dd57d301fb122e 100644 (file)
@@ -63,9 +63,9 @@
 
 struct shpstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned shp_seqno: 12;
     int shp_uid;               /* unit it (ship #) */
-    unsigned shp_seqno;
     time_t shp_timestamp;      /* Last time this ship was touched. */
     natid shp_own;             /* owner's country num */
     coord shp_x;               /* x location in abs coords */
index d40060c63a7fa49d9ee84a52979949209a5d4793..72ebdbbb90b3d9261850fc1b4af76cb4f15c29b0 100644 (file)
@@ -42,9 +42,9 @@
 
 struct trdstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned trd_seqno: 12;
     int trd_uid;
-    unsigned trd_seqno;
     time_t trd_timestamp;
     natid trd_owner;
     /* end of part matching struct empobj */
index 0c6902f67098a1a11d29e9c1aaedcafff48731d0..440d7f533aad73b9523bfec76223bcab92dca992 100644 (file)
@@ -39,9 +39,9 @@
 
 struct trtstr {
     /* initial part must match struct empobj */
-    short ef_type;
+    signed ef_type: 8;
+    unsigned trt_seqno: 12;
     int trt_uid;
-    unsigned trt_seqno;
     time_t trt_timestamp;
     /* end of part matching struct empobj */
     natid trt_cna;             /* proposer */
index d91aae4b72c9d12879595f8ca18b2fcdd6f0b8a4..f907ff7b8cce2ad817fa0ac3b7322a302f94bcdd 100644 (file)
@@ -56,7 +56,7 @@ unit_list(struct emp_qelem *unit_list)
        return;
     qp = unit_list->q_back;
     ulp = (struct ulist *)qp;
-    type = ulp->unit.ef_type;
+    type = ulp->unit.gen.ef_type;
     if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
        return;
 
@@ -191,10 +191,10 @@ unit_view(struct emp_qelem *list)
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        ulp = (struct ulist *)qp;
-       if (CANT_HAPPEN(!(ef_flags(ulp->unit.ef_type) & EFF_XY)))
+       if (CANT_HAPPEN(!(ef_flags(ulp->unit.gen.ef_type) & EFF_XY)))
            continue;
        getsect(ulp->unit.gen.x, ulp->unit.gen.y, &sect);
-       if (ulp->unit.ef_type == EF_SHIP) {
+       if (ulp->unit.gen.ef_type == EF_SHIP) {
            if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
                pr("[fert:%d] ", sect.sct_fertil);
            if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)