X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=001%2Fsrc%2Flife_cell.erl;h=4ee07acdd3b09b70fd667726b55eda7f1052e361;hb=bdfda001fb7cb77f29552bca0071ff3d389b5fd7;hp=a77e279edbf2b454956c02c6cf4af598ca2455ec;hpb=263bc3ae8952564b65bab30d02fc0462711e88fb;p=cellular-automata.git diff --git a/001/src/life_cell.erl b/001/src/life_cell.erl index a77e279..4ee07ac 100644 --- a/001/src/life_cell.erl +++ b/001/src/life_cell.erl @@ -38,6 +38,16 @@ start_link({_, Name, _}=Datum) -> gen_server:start_link(ServerName, ?MODULE, Args, Opts). +%% ============================================================================ +%% Callbacks (unused) +%% ============================================================================ + +handle_call(_Msg, _From, State) -> {reply, ok, State}. +handle_info(_Msg, State) -> {noreply, State}. +code_change(_Old, State, _Other) -> {ok, State}. +terminate(_Reason, State) -> {ok, State}. + + %% ============================================================================ %% Callbacks %% ============================================================================ @@ -55,18 +65,6 @@ init([{CellID, Name, NeighborNames}]) -> {ok, State}. -terminate(_Reason, State) -> - {ok, State}. - - -code_change(_Old, State, _Other) -> - {ok, State}. - - -handle_call(_Msg, _From, State) -> - {reply, ok, State}. - - handle_cast({next_gen, GenID}, #state{name=Name ,cell_state=CellState @@ -75,11 +73,11 @@ handle_cast({next_gen, GenID}, ,early_msgs=EarlyMsgs }=State) -> - ok = cast_one2all(Neighbors, {state_broadcast, GenID, CellState}), + ok = life_lib:cast_one2all(Neighbors, {state_broadcast, GenID, CellState}), % Put stashed messages back in the mailbox, % now that we're ready to handle them - ok = cast_all2one(Name, EarlyMsgs), + ok = life_lib:cast_all2one(Name, EarlyMsgs), NewState = State#state{replies_pending=NumNeighbors ,gen_id=GenID @@ -139,28 +137,10 @@ handle_cast(_Msg, State) -> {noreply, State}. -handle_info(_Msg, State) -> - {noreply, State}. - - %% ============================================================================ %% Internal %% ============================================================================ -% Cast all messages to one destination -cast_all2one(_, []) -> ok; -cast_all2one(Server, [Msg | Msgs]) -> - ok = gen_server:cast(Server, Msg), - cast_all2one(Server, Msgs). - - -% Cast one message to all destinations -cast_one2all([], _) -> ok; -cast_one2all([Server | Servers], Msg) -> - ok = gen_server:cast(Server, Msg), - cast_one2all(Servers, Msg). - - new_state(1, LiveNeighbors) when LiveNeighbors < 2 -> 0; new_state(1, LiveNeighbors) when LiveNeighbors < 4 -> 1; new_state(1, LiveNeighbors) when LiveNeighbors > 3 -> 0;