From: Siraaj Khandkar Date: Thu, 9 Aug 2012 13:16:35 +0000 (-0400) Subject: Don't sleep longer than necessary to meet the interval. X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=704cefa6bfd9bab26938b62c14b47f4803e0cd64;p=cellular-automata.git Don't sleep longer than necessary to meet the interval. --- diff --git a/003/src/life.erl b/003/src/life.erl index ddb5115..f4b1fe5 100644 --- a/003/src/life.erl +++ b/003/src/life.erl @@ -7,7 +7,7 @@ -define(CHAR_ALIVE, 111). % "o" -define(CHAR_BAR, 45). % "-" --define(INTERVAL, 100). +-define(GEN_INTERVAL, 100). -record(state, {x :: non_neg_integer() @@ -73,7 +73,10 @@ life_loop( ,print_time = PrintTime }, - timer:sleep(?INTERVAL), + NewTimeMil = NewTime / 1000, + NextGenDelay = round(?GEN_INTERVAL - NewTimeMil), + timer:sleep(NextGenDelay), + life_loop(NewState).