update: Drop redundant bp map updates and functions

produce_sect() updates the bp map several times.  This is wasteful:
since only ship, plane and land unit building reads it, bp map writes
before the last one are never read.  Update it just once for every
sector.

The update for sectors that are stopped or whose owner is broke is the
only remaining use of bp_put_items().  Since available work must still
be unchanged there, we can replace it by bp_set_from_sect().

bp_get_item(), bp_put_item(), bp_get_items(), bp_get_avail() and
bp_put_avail() are now unused.  Drop them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-05 18:18:12 +02:00
parent 199b1498c8
commit 5b0fd1171d
3 changed files with 8 additions and 64 deletions

View file

@ -43,11 +43,6 @@
struct bp *bp_alloc(void); struct bp *bp_alloc(void);
void bp_set_from_sect(struct bp *, struct sctstr *); void bp_set_from_sect(struct bp *, struct sctstr *);
int bp_get_item(struct bp *, struct sctstr *, i_type);
void bp_put_item(struct bp *, struct sctstr *, i_type, int);
void bp_put_items(struct bp *, struct sctstr *);
int bp_get_avail(struct bp *, struct sctstr *);
void bp_put_avail(struct bp *, struct sctstr *, int);
void bp_to_sect(struct bp *, struct sctstr *); void bp_to_sect(struct bp *, struct sctstr *);
extern int money[MAXNOC]; extern int money[MAXNOC];

View file

@ -66,70 +66,21 @@ static enum bp_item_idx bud_key[I_MAX + 1] = {
BP_LCM, BP_HCM, BP_NONE, BP_NONE BP_LCM, BP_HCM, BP_NONE, BP_NONE
}; };
/* /* Set the values tracked in @bp for sector @sp to the values in @sp. */
* Return the item value tracked in @bp for sector @sp's item @comm.
* @comm must be a tracked item type.
*/
int
bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm)
{
enum bp_item_idx idx = bud_key[comm];
if (CANT_HAPPEN(idx < 0) || !bp)
return sp->sct_item[comm];
return bp[sp->sct_uid].bp_item[idx];
}
/*
* Set item value tracked in @bp for sector @sp's item @comm to @amount.
*/
void void
bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount) bp_set_from_sect(struct bp *bp, struct sctstr *sp)
{ {
enum bp_item_idx idx = bud_key[comm];
if (bp && idx >= 0)
bp[sp->sct_uid].bp_item[idx] = amount;
}
/* Set the item values tracked in @bp from sector @sp. */
void
bp_put_items(struct bp *bp, struct sctstr *sp)
{
enum bp_item_idx idx;
i_type i; i_type i;
enum bp_item_idx idx;
if (!bp) if (!bp)
return; return;
for (i = I_NONE + 1; i <= I_MAX; i++) { for (i = I_NONE + 1; i <= I_MAX; i++) {
idx = bud_key[i]; idx = bud_key[i];
if (idx >= 0) if (idx >= 0)
bp[sp->sct_uid].bp_item[idx] = sp->sct_item[i]; bp[sp->sct_uid].bp_item[idx] = sp->sct_item[i];
} }
} bp[sp->sct_uid].bp_avail = sp->sct_avail;
/* Return avail tracked in @bp for sector @sp. */
int
bp_get_avail(struct bp *bp, struct sctstr *sp)
{
return bp ? bp[sp->sct_uid].bp_avail : sp->sct_avail;
}
/* Set avail tracked in @bp for sector @sp to @amount. */
void
bp_put_avail(struct bp *bp, struct sctstr *sp, int amount)
{
if (bp)
bp[sp->sct_uid].bp_avail = amount;
}
/* Set the values tracked in @bp for sector @sp to the values in @sp. */
void
bp_set_from_sect(struct bp *bp, struct sctstr *sp)
{
bp_put_items(bp, sp);
bp_put_avail(bp, sp, sp->sct_avail);
} }
/* Copy the values tracked in @bp for sector @sp back to @sp. */ /* Copy the values tracked in @bp for sector @sp back to @sp. */

View file

@ -270,10 +270,11 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
} }
work = do_feed(sp, np, etu, 0); work = do_feed(sp, np, etu, 0);
bp_put_items(bp, sp);
if (sp->sct_off || np->nat_money < 0) if (sp->sct_off || np->nat_money < 0) {
bp_set_from_sect(bp, sp);
continue; continue;
}
sp->sct_avail = work; sp->sct_avail = work;
amount = 0; amount = 0;
@ -290,7 +291,6 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money >= 0) { np->nat_money >= 0) {
cost = buildeff(sp); cost = buildeff(sp);
bp_put_items(bp, sp);
p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][0]++;
p_sect[SCT_EFFIC][1] += cost; p_sect[SCT_EFFIC][1] += cost;
if (!player->simulation) if (!player->simulation)
@ -303,7 +303,6 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
p_sect[sp->sct_type][1] += ecost; p_sect[sp->sct_type][1] += ecost;
if (!player->simulation) if (!player->simulation)
np->nat_money -= ecost; np->nat_money -= ecost;
bp_put_items(bp, sp);
} }
/* /*
@ -313,10 +312,9 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if (sp->sct_effic >= 60) { if (sp->sct_effic >= 60) {
if (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0) if (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0)
amount = produce(np, sp, &pcost); amount = produce(np, sp, &pcost);
bp_put_items(bp, sp);
} }
bp_put_avail(bp, sp, sp->sct_avail); bp_set_from_sect(bp, sp);
p_sect[sp->sct_type][0] += amount; p_sect[sp->sct_type][0] += amount;
p_sect[sp->sct_type][1] += pcost; p_sect[sp->sct_type][1] += pcost;
if (!player->simulation) if (!player->simulation)