budget: Avoid unnecessary work
Ship, plane and land unit repairs depend on and change the state of
the sector. To predict repairs, we need to predict the state of the
sector before repairs. The obvious way to do that is to simulate the
sector update and all ship, plane and land unit updates there in the
correct order.
Until recently, we simulated only own sectors, ships, planes and land
units. Wrong when foreign sectors, ships, planes or land units are
involved. The fix (commit 70f6964
) makes budget simulate all
countries. Correct, but does much more work than necessary. With a
little effort, we can track what needs to be simulated.
Use the bp map for tracking. We need to mark the player's sectors and
all sectors where he has ships, planes or land units. Do the former
in bp_alloc(), and the latter in prep_ships(), prep_planes(),
prep_lands().
Skip sectors not so marked. This requires delaying prepare_sects()
until after prep_ships(), prep_planes(), prep_lands(). Their order
doesn't actually matter: prep_ships() & friends only spend money, and
nothing in preparation depends on whether the country is still
solvent.
Skip ships, planes and land units in sectors not so marked.
This speeds up budget by around a third in my testing, more for small
countries. Roughly 15% slower than before the fix for repairs abroad.
The update has to do a bit more work than before, but the performance
difference is lost in the noise.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
549561ff03
commit
b6509b7309
10 changed files with 82 additions and 26 deletions
|
@ -84,6 +84,9 @@ extern void age_levels(int);
|
|||
extern void delete_old_announcements(void);
|
||||
/* bp.c */
|
||||
extern struct bp *bp_alloc(void);
|
||||
extern int bp_skip_sect(struct bp *, struct sctstr *);
|
||||
extern int bp_skip_unit(struct bp *, struct empobj *);
|
||||
extern void bp_consider_unit(struct bp *, struct empobj *);
|
||||
extern void bp_set_from_sect(struct bp *, struct sctstr *);
|
||||
extern void bp_to_sect(struct bp *, struct sctstr *);
|
||||
/* deliver.c */
|
||||
|
@ -98,7 +101,7 @@ extern int feed_people(short *, int);
|
|||
extern double food_needed(short *, int);
|
||||
extern int famine_victims(short *, int);
|
||||
/* land.c */
|
||||
extern void prep_lands(int);
|
||||
extern void prep_lands(int, struct bp *);
|
||||
extern void prod_land(int, struct bp *, int);
|
||||
/* main.c */
|
||||
/* in server.h */
|
||||
|
@ -122,13 +125,14 @@ extern void do_plague(struct sctstr *, int);
|
|||
extern int plague_people(struct natstr *, short *, int *, int *, int);
|
||||
extern void plague_report(natid, int, int, int, int, char *, char *);
|
||||
/* plane.c */
|
||||
extern void prep_planes(int);
|
||||
extern void prep_planes(int, struct bp *);
|
||||
extern void prod_plane(int, struct bp *, int);
|
||||
/* populace.c */
|
||||
extern void populace(struct sctstr *, int);
|
||||
extern int total_work(int, int, int, int, int, int);
|
||||
/* prepare.c */
|
||||
extern void prepare_sects(int, struct bp *);
|
||||
extern void prep_one_sect(struct sctstr *, int, struct bp *);
|
||||
extern void pay_reserve(struct natstr *, int);
|
||||
/* produce.c */
|
||||
extern void produce(struct natstr *, struct sctstr *);
|
||||
|
@ -148,7 +152,7 @@ extern void spread_fallout(struct sctstr *, int);
|
|||
extern void decay_fallout(struct sctstr *, int);
|
||||
extern void produce_sect(int, struct bp *);
|
||||
/* ship.c */
|
||||
extern void prep_ships(int);
|
||||
extern void prep_ships(int, struct bp *);
|
||||
extern void prod_ship(int, struct bp *, int);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue