Fuse update wait thread and update thread:
(update_main): No longer a thread entry point. Remove the parameter.
Remove *player setup. Don't terminate the thread when done.
(update_pending): Move to src/server/update.c.
(update_wait): Call update_main() instead of running it in its own
thread. Set up *player for it.
(update_init): Create the fused update thread instead of the update
wait thread.
Synchronize commands and update properly with a lock (towards
resolving #1458175 and #1504036):
(update_lock): New.
(update_shed): Initialize it.
(update_wait, dispatch): Take exclusive update_lock around the update,
shared update_lock around commands. This makes the update block until
all aborted commands terminated and gave up their lock. Remove the
cheesy and unsafe two second wait for commands to finish. It also
makes player threads block before executing commands while the update
is pending, removing the need to fail commands then. So don't.
Ron Koenderink [Mon, 15 Jan 2007 13:34:33 +0000 (13:34 +0000)]
(struct loc_Thread_t, struct loc_Sem_t, hThreadStartEvent)
(loc_RunThisThread, empth_init, empth_create, empth_wait_for_signal)
[EMPTH_W32]: Remove some incorrect references to semaphones
in the comments. No functional changes.
Ron Koenderink [Mon, 15 Jan 2007 12:45:35 +0000 (12:45 +0000)]
(loc_RunThread, empth_init, empth_threadMain, empth_yield)
(empth_select, empth_sleep, empth_wait_for_signal)
(empth_sem_wait) [EMPTH_W32]: Add the ability to wait additional
event in loc_RunThread() when acquiring the hThread mutex.
(produce_sect): Use bp_put_items() after calls that may update vec[].
This is more robust than using bp_put_item() for those elements of
vec[] that the call may change. The old code missed some changes:
upd_buildeff() changing population when tearing down a big city,
enlist(), and produce(). The first two should have been harmless, the
last one made budget mispredict repairs when required materials were
produced in the same update.
(do_feed, produce_sect): Move bp_put_item() calls from do_feed() to
produce_sect(), for consistency with the other update functions that
update sct_item[]. Parameter bp is now unused, remove.
(bp): Rename member val to bp_item, member avail to bp_avail. Users
changed. Switch from int to short, to match struct sctstr members
sct_item and sct_avail.
Symbolic indexes for struct bp member bp_item[]:
(BP_NONE, BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, BP_LCM, BP_HCM)
(BP_MAX): New.
(bug_key): Use them. Values are now array indexes, not indexes + 1.
(bp_get_item, bp_put_item, bp_set_from_sect): Update for changed
bud_key[].
(get_wp, bp_ref): Replace function returning pointer into a struct bp
by function returning to struct bp. Leave member access to callers.
Callers changed.
Replace the revolting build pointer data structure by a proper data
type. Make it abstract because that's possible. Change data layout
so that the slots belonging to a sector are together in memory, it's
nicer to the cache.
(bp): The new type. Users changed.
(get_wp): Update accordingly.
(alloc_bp): New.
(update_main, calc_all): Use it. Before, calc_all() allocated 1/7
more than necessary.
(get_materials): Redesign.
(shiprepair, planerepair, landrepair): Use it. Behavioral change:
ship repairs outside harbors and plane repairs by a carrier can use
fewer materials. Before, such repairs consumed each required
commodity as far as available. Now, they consume the same fraction of
the real cost of each commodity, i.e. commodity use is limited by the
most scarce commodity. Neither old nor new behavior make much sense,
but the new code is simpler.
Ron Koenderink [Wed, 3 Jan 2007 12:54:41 +0000 (12:54 +0000)]
(decl): Prevent the deity from changing relations for a player to
self. Closes #1384998. Allow the deity to set the relations of a
player towards the deity.
New option AUTO_POWER; closes #1009993:
(opt_AUTO_POWER, update_power): New.
(update_main): Implement AUTO_POWER.
(powe): Disable power new when AUTO_POWER is on.
(powe): New power update.
(gen_power): Compute power into buffer passed by caller, make write to
power file optional.
Ron Koenderink [Tue, 26 Dec 2006 19:17:22 +0000 (19:17 +0000)]
(do_mob_land): Disable automatic land unit fortification with excess
mobility when MOB_ACCESS is on. It leads to excessively deep
recursion and thus miserable performance as the number of land units
grows.
Ron Koenderink [Wed, 29 Nov 2006 12:16:43 +0000 (12:16 +0000)]
(ef_open) [_WIN32]: Fix to get a read lock instead of a write lock for
EFF_RDONLY and to get a write lock instead of a total file lock for
file opened for writing.
Ron Koenderink [Tue, 10 Oct 2006 20:23:19 +0000 (20:23 +0000)]
(switch_leader): Generalize the code, no functional changes.
(navi): Change switch_flagship() to call switch_leader() instead.
(switch_flagship): Remove, not needed, replaced with switch_leader().
(take_casualties): Code for distributing casualties among units did
not make sense, and in its confusion destroyed land land units when it
shouldn't. Minimally invasive fix; code is still ugly and
incomprehensible.
Ron Koenderink [Wed, 4 Oct 2006 01:20:29 +0000 (01:20 +0000)]
(struct ulist): Add abstract reference to types.h to accomodate
the ciruclar reference between struct ulist and union empobj_storage
and struct lndstr.
(produce_sect, finish_sects): Move stop order expiry to end of update,
so that stopped sectors don't repair units. The update sequence
masked this bug until its change in src/lib/update/main.c rev. 1.25,
but use of budget priorities (gone since rev. 1.24) could unmask it.
(sect_has_dock): NAV_CANAL in sect.h rev. 1.36 broke loading in
canals, fix. Can't enforce M_CANAL condition here, so leave it to
callers. Callers don't enforce it either, which means landlocked
ships can load in canals. Oh well.
Ron Koenderink [Fri, 18 Aug 2006 23:32:45 +0000 (23:32 +0000)]
(empobj_chr): New, create a new (imcomplete) structure for
empobj characteristics.
(get_empobj_chr): Update get_empobj_chr() to use new
struct empobj_chr.
Allow xdump before break; partial solution for #1417871:
(player_coms): Set xdump's c_permit to VIS.
(xdump): Deny countries that couldn't run xdump before access to game
state.
Ron Koenderink [Wed, 2 Aug 2006 21:46:34 +0000 (21:46 +0000)]
(makelost, makenotlost, findlost, struct loststr): Change type to be a
short instead of a char. This will make lost_type consistent with
ef_type in the rest of the structures.
Ron Koenderink [Wed, 2 Aug 2006 18:39:22 +0000 (18:39 +0000)]
(unit_map): Replace player->owner with direct owner check and
player->god check. player->owner is not set if ef_ptr() is used
as no post_read() is done. Broken in rev 1.38. Not completely fixed
in rev 1.40.
(ef_open): Lock the file. This prevents two programs (servers in
particular) running on the same game state. fairland does not use
ef_open() at this time, and thus ignores the lock.
(produce): The reported amount produced (returned through last
parameter) did not reflect production cut for ITEM_MAX. Broken in
3.0.14 or so. Reported by Stefan Hauser.
Ron Koenderink [Wed, 26 Jul 2006 00:21:58 +0000 (00:21 +0000)]
(get_empobjp): New. Returns a pointer an empobj.
(emp_obj_chr_name): New. Returns a pointer to the characteristics name
for an empobj.
(unit_map): Simplify unit_map() by using get_empobjp() and
emp_obj_chr_name().
(map, cmd_move_map): Switch to EF_SHIP as unit_map does not default
to EF_SHIP for EF_BAD anymore.
(swaps): Failed to update coastal flags. Was missed in the changeset
containing coastal.c rev. 1.1.
(set_coastal): New parameter olddes, to simplify fixing swaps().
Callers changed.
(update_coastal_flag, coast_sea_to_land, coastal_land_to_sea): Return
new coastal flag instead of updating the sector. This is a bit
simpler. Change arguments from sectors to coordinates to make it
obvious that the sector is not touched.
(set_coastal): Update the coastal flag, but leave putsect() to
callers. All existing callers do that anyway.
Ron Koenderink [Thu, 20 Jul 2006 14:12:35 +0000 (14:12 +0000)]
(put_empobj): New. Put generic empobj into the appropriate data file.
(get_empobj_chr): New. Get characteristics for empobj.
(mission, build_mission_list_type): Switch to use new
functions put_empobj() and get_empobj_chr().
Ron Koenderink [Thu, 20 Jul 2006 01:29:25 +0000 (01:29 +0000)]
(prod_nat): Change the wording from "total pop is" to
"total pop was" to be less confusing. The total population
display is the total at the start of the update, not after the
update is complete.