From: Christian Heller Date: Fri, 28 Jun 2013 00:12:23 +0000 (+0200) Subject: Rewrote update_log () for a comeback of the message repition compression feature... X-Git-Tag: tce~1185 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/gitweb.js?a=commitdiff_plain;h=06423bfe47a2548fd8e45576dafbed1603e54243;p=plomrogue Rewrote update_log () for a comeback of the message repition compression feature; this time less buggy. --- diff --git a/src/actors.c b/src/actors.c index 1f8f28e..ca1305c 100644 --- a/src/actors.c +++ b/src/actors.c @@ -30,7 +30,7 @@ extern void move_monster (struct World * world, struct Monster * monster) { monster->pos = t; } extern void move_player (struct World * world, char d) { -// Move player in direction d, increment turn counter and update log. +// Move player in direction d, update log and turn over to the enemy. struct yx_uint16 t = mv_yx_in_dir (d, world->player->pos); struct Monster * monster; for (monster = world->monster; monster != 0; monster = monster->next) diff --git a/src/roguelike.c b/src/roguelike.c index d212388..ce3f5a4 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -20,14 +20,25 @@ uint16_t rrand(char use_seed, uint32_t new_seed) { return (seed / 65536); } // Ignore least significant 16 bits (they are less random). void update_log (struct World * world, char * text) { -// Update log with new text to be appended. +// Update log by appending text, or by appending a "." if text is the same as the last one. + static char * last_msg; + if (0 == last_msg) + last_msg = calloc(1, sizeof(char)); char * new_text; uint16_t len_old = strlen(world->log); - uint16_t len_new = strlen(text); - uint16_t len_whole = len_old + len_new + 1; - new_text = calloc(len_whole, sizeof(char)); - memcpy(new_text, world->log, len_old); - memcpy(new_text + len_old, text, len_new); + if (0 == strcmp(last_msg, text)) { + uint16_t len_whole = len_old + 1; + new_text = calloc(len_whole + 1, sizeof(char)); + memcpy(new_text, world->log, len_old); + memcpy(new_text + len_old, ".", 1); } + else { + uint16_t len_new = strlen(text); + uint16_t len_whole = len_old + len_new + 1; + new_text = calloc(len_whole, sizeof(char)); + memcpy(new_text, world->log, len_old); + memcpy(new_text + len_old, text, len_new); + last_msg = calloc(len_new + 1, sizeof(char)); + memcpy(last_msg, text, len_new); } free(world->log); world->log = new_text; }