From: Christian Heller Date: Thu, 10 Jul 2014 01:28:18 +0000 (+0200) Subject: Server: Simplify rule for when to update worldstate file. X-Git-Tag: tce~713 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/decks/%7Broute%7D?a=commitdiff_plain;h=036e0f646d4b55cc0162a8fad7f1a9559db50c50;p=plomrogue Server: Simplify rule for when to update worldstate file. --- diff --git a/src/server/init.c b/src/server/init.c index e9bb3d4..dd6ee15 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -127,7 +127,7 @@ extern void remake_world() world.log = NULL; /* thing_actions.c's update_log() checks for this. */ world.seed_map = world.seed; free_things(world.things); - world.last_update_turn = 0; + world.do_update = 1; remake_map(); struct ThingType * tt; for (tt = world.thing_types; NULL != tt; tt = tt->next) diff --git a/src/server/init.h b/src/server/init.h index e563374..cadacf3 100644 --- a/src/server/init.h +++ b/src/server/init.h @@ -20,9 +20,8 @@ extern void setup_server_io(); * Unlinks any pre-existing record file. * * Thing (action) definitions read in from server config directory are not - * affected. The map is populated accordingly. world.last_update_turn is set to - * 0 and world.turn to 1, so that io_round()'s criteria for updating the output - * file are triggered even when this function is called during a round 1. + * affected. The map is populated accordingly. world.turn is set to 1, as is + * world.do_update, so that io_round() is told to update the worldstate file. */ extern void remake_world(); diff --git a/src/server/io.c b/src/server/io.c index c8f5167..00afb3c 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -304,10 +304,10 @@ extern char * io_round() { return get_message_from_queue(); } - if (world.turn != world.last_update_turn) + if (world.do_update) { update_worldstate_file(); - world.last_update_turn = world.turn; + world.do_update = 0; } read_file_into_queue(); if (world.queue_size && '\0' != world.queue[world.queue_size - 1]) diff --git a/src/server/io.h b/src/server/io.h index 8211753..2f8397f 100644 --- a/src/server/io.h +++ b/src/server/io.h @@ -10,10 +10,9 @@ /* Return single \0-terminated string read from input queue (world.queue); or, - * if queue is empty and world.turn is unequal world.last_update_turn, update - * world state file (and world.last_update_turn) and write a single dot line to - * server out file, then read server in file for the next load of bytes to put - * onto the input queue. + * if queue is empty and world.do_update is set, update world state file (and + * unset world.do_update) and write a single dot line to server out file, then + * read server in file for the next load of bytes to put onto the input queue. * * Reading the server in file may put many \0-terminated strings on the queue at * once. Successive calls of io_round() will make these available one by one. diff --git a/src/server/run.c b/src/server/run.c index 3f1b1e3..8e1914b 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -360,7 +360,7 @@ extern void obey_msg(char * msg, uint8_t do_record) free(msg_copy); return; } - world.last_update_turn = 0; + world.do_update = 1; free(msg_copy); if (do_record) { diff --git a/src/server/world.h b/src/server/world.h index 3592809..22af12c 100644 --- a/src/server/world.h +++ b/src/server/world.h @@ -31,7 +31,7 @@ struct World uint32_t seed_map; /* Map seed. */ uint16_t replay; /* Turn up to which to replay game. No replay if zero. */ uint16_t turn; /* Current game turn. */ - uint16_t last_update_turn; /* Last turn the .path_out file was updated. */ + uint16_t do_update; /* Update worldstate file if !0. */ uint8_t player_type; /* Thing type that player will start as. */ uint8_t is_verbose; /* Should server send debugging info to stdout? */ };