Store sequence numbers more compactly
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.
This commit is contained in:
parent
ba2044be18
commit
358aee203e
15 changed files with 33 additions and 34 deletions
|
@ -42,9 +42,9 @@
|
||||||
|
|
||||||
struct comstr {
|
struct comstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned com_seqno: 12;
|
||||||
int com_uid;
|
int com_uid;
|
||||||
unsigned com_seqno;
|
|
||||||
time_t com_timestamp;
|
time_t com_timestamp;
|
||||||
natid com_owner;
|
natid com_owner;
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
|
|
|
@ -55,9 +55,9 @@ struct empobj {
|
||||||
* initial part must match struct emptypedstr
|
* initial part must match struct emptypedstr
|
||||||
* valid if EFF_TYPED is set in table's flags
|
* valid if EFF_TYPED is set in table's flags
|
||||||
*/
|
*/
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned seqno: 12;
|
||||||
int uid;
|
int uid;
|
||||||
unsigned seqno;
|
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
/* end of part matching struct emptypedstr */
|
/* end of part matching struct emptypedstr */
|
||||||
natid own; /* valid if EFF_OWNER is in table's flags */
|
natid own; /* valid if EFF_OWNER is in table's flags */
|
||||||
|
@ -76,7 +76,6 @@ struct empobj {
|
||||||
};
|
};
|
||||||
|
|
||||||
union empobj_storage {
|
union empobj_storage {
|
||||||
short ef_type;
|
|
||||||
struct empobj gen;
|
struct empobj gen;
|
||||||
struct comstr comm;
|
struct comstr comm;
|
||||||
struct gamestr game;
|
struct gamestr game;
|
||||||
|
|
|
@ -85,9 +85,9 @@ struct empfile {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct emptypedstr {
|
struct emptypedstr {
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned seqno: 12;
|
||||||
int uid;
|
int uid;
|
||||||
unsigned seqno;
|
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,9 @@
|
||||||
|
|
||||||
struct gamestr {
|
struct gamestr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned game_seqno: 12;
|
||||||
int game_uid;
|
int game_uid;
|
||||||
unsigned game_seqno;
|
|
||||||
time_t game_timestamp;
|
time_t game_timestamp;
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
char game_upd_disable; /* updates disabled? */
|
char game_upd_disable; /* updates disabled? */
|
||||||
|
|
|
@ -49,9 +49,9 @@
|
||||||
|
|
||||||
struct lndstr {
|
struct lndstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned lnd_seqno: 12;
|
||||||
int lnd_uid; /* unit id (land #) */
|
int lnd_uid; /* unit id (land #) */
|
||||||
unsigned lnd_seqno;
|
|
||||||
time_t lnd_timestamp; /* Last time this unit was touched */
|
time_t lnd_timestamp; /* Last time this unit was touched */
|
||||||
natid lnd_own; /* owner's country num */
|
natid lnd_own; /* owner's country num */
|
||||||
coord lnd_x; /* x location in abs coords */
|
coord lnd_x; /* x location in abs coords */
|
||||||
|
|
|
@ -42,9 +42,9 @@
|
||||||
|
|
||||||
struct lonstr {
|
struct lonstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned l_seqno: 12;
|
||||||
int l_uid;
|
int l_uid;
|
||||||
unsigned l_seqno;
|
|
||||||
time_t l_timestamp;
|
time_t l_timestamp;
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
natid l_loner; /* loan shark */
|
natid l_loner; /* loan shark */
|
||||||
|
|
|
@ -39,9 +39,9 @@
|
||||||
|
|
||||||
struct loststr {
|
struct loststr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned lost_seqno: 12;
|
||||||
int lost_uid;
|
int lost_uid;
|
||||||
unsigned lost_seqno;
|
|
||||||
time_t lost_timestamp; /* When it was lost */
|
time_t lost_timestamp; /* When it was lost */
|
||||||
natid lost_owner; /* Who lost it */
|
natid lost_owner; /* Who lost it */
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
|
|
|
@ -70,9 +70,9 @@ enum nat_status {
|
||||||
*/
|
*/
|
||||||
struct realmstr {
|
struct realmstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned r_seqno: 12;
|
||||||
int r_uid; /* realm table index */
|
int r_uid; /* realm table index */
|
||||||
unsigned r_seqno;
|
|
||||||
time_t r_timestamp; /* Last time this realm was touched */
|
time_t r_timestamp; /* Last time this realm was touched */
|
||||||
natid r_cnum; /* country number */
|
natid r_cnum; /* country number */
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
|
@ -83,9 +83,9 @@ struct realmstr {
|
||||||
|
|
||||||
struct natstr {
|
struct natstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned nat_seqno: 12;
|
||||||
int nat_uid; /* equals nat_cnum */
|
int nat_uid; /* equals nat_cnum */
|
||||||
unsigned nat_seqno;
|
|
||||||
time_t nat_timestamp;
|
time_t nat_timestamp;
|
||||||
natid nat_cnum; /* our country number */
|
natid nat_cnum; /* our country number */
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
|
|
|
@ -42,9 +42,9 @@
|
||||||
|
|
||||||
struct nukstr {
|
struct nukstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned nuk_seqno: 12;
|
||||||
int nuk_uid; /* unit id (nuke #) */
|
int nuk_uid; /* unit id (nuke #) */
|
||||||
unsigned nuk_seqno;
|
|
||||||
time_t nuk_timestamp; /* Last time this nuke was touched */
|
time_t nuk_timestamp; /* Last time this nuke was touched */
|
||||||
natid nuk_own;
|
natid nuk_own;
|
||||||
coord nuk_x, nuk_y; /* current loc of device */
|
coord nuk_x, nuk_y; /* current loc of device */
|
||||||
|
|
|
@ -46,9 +46,9 @@
|
||||||
|
|
||||||
struct plnstr {
|
struct plnstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned pln_seqno: 12;
|
||||||
int pln_uid; /* unit id (plane #) */
|
int pln_uid; /* unit id (plane #) */
|
||||||
unsigned pln_seqno;
|
|
||||||
time_t pln_timestamp; /* Last time this plane was touched */
|
time_t pln_timestamp; /* Last time this plane was touched */
|
||||||
natid pln_own; /* owning country */
|
natid pln_own; /* owning country */
|
||||||
coord pln_x; /* plane x-y */
|
coord pln_x; /* plane x-y */
|
||||||
|
|
|
@ -44,9 +44,9 @@
|
||||||
|
|
||||||
struct sctstr {
|
struct sctstr {
|
||||||
/* initial part must match struct empobj */
|
/* 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) */
|
int sct_uid; /* equals XYOFFSET(sct_x, sct_y) */
|
||||||
unsigned sct_seqno;
|
|
||||||
time_t sct_timestamp; /* Last time this sector was written to */
|
time_t sct_timestamp; /* Last time this sector was written to */
|
||||||
natid sct_own; /* owner's country num */
|
natid sct_own; /* owner's country num */
|
||||||
coord sct_x; /* x coord of sector */
|
coord sct_x; /* x coord of sector */
|
||||||
|
|
|
@ -63,9 +63,9 @@
|
||||||
|
|
||||||
struct shpstr {
|
struct shpstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned shp_seqno: 12;
|
||||||
int shp_uid; /* unit it (ship #) */
|
int shp_uid; /* unit it (ship #) */
|
||||||
unsigned shp_seqno;
|
|
||||||
time_t shp_timestamp; /* Last time this ship was touched. */
|
time_t shp_timestamp; /* Last time this ship was touched. */
|
||||||
natid shp_own; /* owner's country num */
|
natid shp_own; /* owner's country num */
|
||||||
coord shp_x; /* x location in abs coords */
|
coord shp_x; /* x location in abs coords */
|
||||||
|
|
|
@ -42,9 +42,9 @@
|
||||||
|
|
||||||
struct trdstr {
|
struct trdstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned trd_seqno: 12;
|
||||||
int trd_uid;
|
int trd_uid;
|
||||||
unsigned trd_seqno;
|
|
||||||
time_t trd_timestamp;
|
time_t trd_timestamp;
|
||||||
natid trd_owner;
|
natid trd_owner;
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
|
|
|
@ -39,9 +39,9 @@
|
||||||
|
|
||||||
struct trtstr {
|
struct trtstr {
|
||||||
/* initial part must match struct empobj */
|
/* initial part must match struct empobj */
|
||||||
short ef_type;
|
signed ef_type: 8;
|
||||||
|
unsigned trt_seqno: 12;
|
||||||
int trt_uid;
|
int trt_uid;
|
||||||
unsigned trt_seqno;
|
|
||||||
time_t trt_timestamp;
|
time_t trt_timestamp;
|
||||||
/* end of part matching struct empobj */
|
/* end of part matching struct empobj */
|
||||||
natid trt_cna; /* proposer */
|
natid trt_cna; /* proposer */
|
||||||
|
|
|
@ -56,7 +56,7 @@ unit_list(struct emp_qelem *unit_list)
|
||||||
return;
|
return;
|
||||||
qp = unit_list->q_back;
|
qp = unit_list->q_back;
|
||||||
ulp = (struct ulist *)qp;
|
ulp = (struct ulist *)qp;
|
||||||
type = ulp->unit.ef_type;
|
type = ulp->unit.gen.ef_type;
|
||||||
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
|
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -191,10 +191,10 @@ unit_view(struct emp_qelem *list)
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
ulp = (struct ulist *)qp;
|
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;
|
continue;
|
||||||
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
||||||
if (ulp->unit.ef_type == EF_SHIP) {
|
if (ulp->unit.gen.ef_type == EF_SHIP) {
|
||||||
if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
|
if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
|
||||||
pr("[fert:%d] ", sect.sct_fertil);
|
pr("[fert:%d] ", sect.sct_fertil);
|
||||||
if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
|
if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue