contact: Move contact state from struct natstr to contactstr
Contact state is relatively bulky: it's a big chunk of struct natstr, and adds almost 200 bytes per country to xdump nat for deities. Contact changes rarely. Since we avoid unnecessary updates, it doesn't change at all unless option HIDDEN is enabled. Rewriting it to disk on every nation update and retransmitting it in every deity xdump nat is wasteful. To avoid this waste, move contact state to its own struct contactstr. This is of course an xdump compatibility break. We're not maintaining xdump compatibility in this release. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
4b4df53485
commit
c8e7548f24
19 changed files with 141 additions and 132 deletions
|
@ -59,6 +59,7 @@ static void pln_oninit(void *);
|
|||
static void lnd_oninit(void *);
|
||||
static void nuk_oninit(void *);
|
||||
static void nat_oninit(void *);
|
||||
static void contact_oninit(void *);
|
||||
static void realm_oninit(void *);
|
||||
static void game_oninit(void *);
|
||||
static void pchr_oninit(void *);
|
||||
|
@ -166,7 +167,7 @@ struct empfile empfile[] = {
|
|||
nat_oninit, NULL, NULL, NULL},
|
||||
{EF_CONTACT, "contact", NULL, "contact", contact_ca, EF_BAD,
|
||||
UNMAPPED_CACHE(struct contactstr, MAXNOC, EFF_TYPED),
|
||||
NULL, NULL, NULL, NULL},
|
||||
contact_oninit, NULL, NULL, NULL},
|
||||
{EF_LOAN, "loan", NULL, "loan", loan_ca, EF_BAD,
|
||||
UNMAPPED_CACHE(struct lonstr, -1, EFF_TYPED),
|
||||
NULL, NULL, NULL, NULL},
|
||||
|
@ -321,11 +322,17 @@ nat_oninit(void *ptr)
|
|||
struct natstr *np = ptr;
|
||||
|
||||
np->nat_cnum = np->nat_uid;
|
||||
}
|
||||
|
||||
static void
|
||||
contact_oninit(void *ptr)
|
||||
{
|
||||
struct contactstr *cp = ptr;
|
||||
|
||||
if (opt_HIDDEN)
|
||||
np->nat_contact[np->nat_cnum] = 1;
|
||||
cp->con_contact[cp->con_uid] = 1;
|
||||
else
|
||||
memset(np->nat_contact, 1, sizeof(np->nat_contact));
|
||||
memset(cp->con_contact, 1, sizeof(cp->con_contact));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Dave Pare, 1989
|
||||
* Ron Koenderink, 2005
|
||||
* Markus Armbruster, 2006-2011
|
||||
* Markus Armbruster, 2006-2016
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -98,19 +98,21 @@ getrejects(natid them, struct natstr *np)
|
|||
void
|
||||
agecontact(struct natstr *np)
|
||||
{
|
||||
struct contactstr con;
|
||||
int them;
|
||||
|
||||
getcontact(np->nat_cnum, &con);
|
||||
|
||||
for (them = 1; them < MAXNOC; ++them) {
|
||||
if (them != np->nat_cnum && np->nat_contact[them]) {
|
||||
--np->nat_contact[them];
|
||||
}
|
||||
if (them != np->nat_cnum && con.con_contact[them])
|
||||
con.con_contact[them]--;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
in_contact(struct natstr *np, natid them)
|
||||
{
|
||||
return np->nat_contact[them];
|
||||
return getcontactp(np->nat_cnum)->con_contact[them];
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -638,9 +638,6 @@ struct castr cou_ca[] = {
|
|||
EF_BAD, 0, CA_DUMP},
|
||||
{"relations", fldoff(nat_relate), NSC_UCHAR, MAXNOC, NULL,
|
||||
EF_NATION_RELATIONS, NSC_HIDDEN, CA_DUMP_NONE},
|
||||
/* mortals know there's contact (relations show), but not how strong */
|
||||
{"contacts", fldoff(nat_contact), NSC_UCHAR, MAXNOC, NULL,
|
||||
EF_BAD, NSC_DEITY, CA_DUMP_NONE},
|
||||
{"rejects", fldoff(nat_rejects), NSC_UCHAR, MAXNOC, NULL,
|
||||
EF_NATION_REJECTS, NSC_BITS, CA_DUMP_NONE},
|
||||
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
|
||||
|
@ -655,6 +652,9 @@ struct castr contact_ca[] = {
|
|||
{"uid", fldoff(con_uid), NSC_INT, 0, NULL, EF_CONTACT, 0, CA_DUMP},
|
||||
{"timestamp", fldoff(con_timestamp), NSC_TIME, 0, NULL,
|
||||
EF_BAD, 0, CA_DUMP_NONE},
|
||||
/* mortals know there's contact (relations show), but not how strong */
|
||||
{"contacts", fldoff(con_contact), NSC_UCHAR, MAXNOC, NULL,
|
||||
EF_BAD, NSC_DEITY, CA_DUMP},
|
||||
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
|
||||
#undef CURSTR
|
||||
};
|
||||
|
|
|
@ -113,9 +113,9 @@ setrel(natid us, natid them, int rel)
|
|||
void
|
||||
setcont(natid us, natid them, int contact)
|
||||
{
|
||||
struct natstr *np = getnatp(us);
|
||||
struct contactstr *conp = getcontactp(us);
|
||||
|
||||
if (CANT_HAPPEN(!np))
|
||||
if (CANT_HAPPEN(!conp))
|
||||
return;
|
||||
|
||||
if (CANT_HAPPEN(contact < 0))
|
||||
|
@ -125,9 +125,9 @@ setcont(natid us, natid them, int contact)
|
|||
|
||||
if (!opt_LOSE_CONTACT)
|
||||
contact = !!contact;
|
||||
if (np->nat_contact[them] < contact) {
|
||||
np->nat_contact[them] = contact;
|
||||
putnat(np);
|
||||
if (conp->con_contact[them] < contact) {
|
||||
conp->con_contact[them] = contact;
|
||||
putcontact(conp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue