]> git.pond.sub.org Git - empserver/commitdiff
update: Drop redundant bp map updates and functions
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 5 Jun 2016 16:18:12 +0000 (18:18 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 17:59:58 +0000 (19:59 +0200)
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>
include/budg.h
src/lib/update/bp.c
src/lib/update/sect.c

index 0a5b452eb7f337fb9f4c3f0c30c3144f04c67def..a8aef7c32eb246f4e30020d8c5d7dda6b9302e09 100644 (file)
 
 struct bp *bp_alloc(void);
 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 *);
 
 extern int money[MAXNOC];
index 020cf1c216271648db45bd37c723b10fb3c28047..941e68d95dc0b2172effe14d9fc39d5aebc08ed1 100644 (file)
@@ -66,70 +66,21 @@ static enum bp_item_idx bud_key[I_MAX + 1] = {
     BP_LCM, BP_HCM, BP_NONE, BP_NONE
 };
 
-/*
- * 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
-bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount)
-{
-    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. */
+/* Set the values tracked in @bp for sector @sp to the values in @sp. */
 void
-bp_put_items(struct bp *bp, struct sctstr *sp)
+bp_set_from_sect(struct bp *bp, struct sctstr *sp)
 {
-    enum bp_item_idx idx;
     i_type i;
+    enum bp_item_idx idx;
 
     if (!bp)
        return;
-
     for (i = I_NONE + 1; i <= I_MAX; i++) {
        idx = bud_key[i];
        if (idx >= 0)
            bp[sp->sct_uid].bp_item[idx] = sp->sct_item[i];
     }
-}
-
-/* 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);
+    bp[sp->sct_uid].bp_avail = sp->sct_avail;
 }
 
 /* Copy the values tracked in @bp for sector @sp back to @sp. */
index fb97142fd84f260b001fab30c82462b5aa118b21..206c0788efdf01ebbabadef8b52b95e75b4abded 100644 (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);
-       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;
+       }
 
        sp->sct_avail = work;
        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) &&
            np->nat_money >= 0) {
            cost = buildeff(sp);
-           bp_put_items(bp, sp);
            p_sect[SCT_EFFIC][0]++;
            p_sect[SCT_EFFIC][1] += cost;
            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;
            if (!player->simulation)
                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 (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0)
                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][1] += pcost;
        if (!player->simulation)