]> git.pond.sub.org Git - empserver/commit
budget: Avoid unnecessary work
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 16 Jul 2016 10:38:24 +0000 (12:38 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:06 +0000 (20:09 +0200)
commitb6509b7309555ebbdbe30f33b39e844dd1aa4ea2
tree11d10944ce6c08834de22d2441caccebf6308a0b
parent549561ff0332a8e8b2ee4ae2d92e44aa53a2d982
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>
include/update.h
info/Update-sequence.t
src/lib/commands/budg.c
src/lib/update/bp.c
src/lib/update/land.c
src/lib/update/main.c
src/lib/update/plane.c
src/lib/update/prepare.c
src/lib/update/sect.c
src/lib/update/ship.c