From: Siraaj Khandkar Date: Wed, 25 Jul 2012 17:06:17 +0000 (-0400) Subject: Printing X and Y in the status bar. X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=1aa9333c0dab226e2e54ea60863c9e55523d77d7;p=cellular-automata.git Printing X and Y in the status bar. --- diff --git a/001/src/life.erl b/001/src/life.erl index e40d841..2c0f3d3 100644 --- a/001/src/life.erl +++ b/001/src/life.erl @@ -28,7 +28,7 @@ start(_StartType, _StartArgs) -> {ok, X} = application:get_env(?MODULE, x), {ok, Y} = application:get_env(?MODULE, y), CellData = cell_data(X, Y), - life_god:start_link(X, CellData). + life_god:start_link(X, Y, CellData). stop(_State) -> diff --git a/001/src/life_god.erl b/001/src/life_god.erl index 84c511a..8000eaa 100644 --- a/001/src/life_god.erl +++ b/001/src/life_god.erl @@ -3,7 +3,7 @@ %% API --export([start_link/2]). +-export([start_link/3]). %% Callbacks -export([init/1]). @@ -17,19 +17,19 @@ %% API %% ============================================================================ -start_link(X, CellData) -> - supervisor:start_link({local, ?MODULE}, ?MODULE, [X, CellData]). +start_link(X, Y, CellData) -> + supervisor:start_link({local, ?MODULE}, ?MODULE, [X, Y, CellData]). %% ============================================================================ %% Callbacks %% ============================================================================ -init([X, CellData]) -> +init([X, Y, CellData]) -> CellNames = [Name || {_, Name, _} <- CellData], RestartStrategy = {one_for_one, 1000000, 1}, Cells = [spec_cell(Datum) || Datum <- CellData], - Time = ?CHILD(worker, life_time, [X, CellNames]), + Time = ?CHILD(worker, life_time, [X, Y, CellNames]), Children = Cells ++ [Time], {ok, {RestartStrategy, Children}}. diff --git a/001/src/life_time.erl b/001/src/life_time.erl index 6827d29..6f9d859 100644 --- a/001/src/life_time.erl +++ b/001/src/life_time.erl @@ -3,7 +3,7 @@ %% API --export([start_link/2 +-export([start_link/3 ,tock/2 ]). @@ -25,6 +25,7 @@ -record(state, {x :: integer() + ,y :: integer() ,cells :: list(atom()) ,num_cells :: integer() ,state_pairs :: list(tuple(integer(), integer())) | [] @@ -37,9 +38,9 @@ %% API %% ============================================================================ -start_link(X, Cells) -> +start_link(X, Y, Cells) -> ServerName = {local, ?MODULE}, - Args = [X, Cells], + Args = [X, Y, Cells], Opts = [], gen_server:start_link(ServerName, ?MODULE, Args, Opts). @@ -52,8 +53,9 @@ tock(CellID, CellState) -> %% Callbacks %% ============================================================================ -init([X, Cells]) -> +init([X, Y, Cells]) -> State = #state{x=X + ,y=Y ,cells=Cells ,num_cells=length(Cells) ,state_pairs=[] @@ -86,6 +88,7 @@ handle_cast(next_tick, handle_cast({tock, {ID, CellState}}, #state{x=X + ,y=Y ,state_pairs=StatePairs ,replies_pending=RepliesPending ,gen_count=GenCount @@ -106,8 +109,8 @@ handle_cast({tock, {ID, CellState}}, StateChars = [state_to_char(S) || {_, S} <- SortedStatePairs], ok = io:format( - "CELLS: ~b GENERATIONS: ~b~n", - [NumCells, NewGenCount] + "X: ~b Y: ~b CELLS: ~b GENERATIONS: ~b~n", + [X, Y, NumCells, NewGenCount] ), ok = do_print_bar(X),