From d6b2edd8cef2a3ab1bb9488fe7e82920a1333af1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 7 Mar 2024 21:58:14 +0100 Subject: wip --- tictactoe-2/apps/ttt_server/src/game.erl | 12 +++++++++--- tictactoe-2/apps/ttt_server/src/ttt_server.erl | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'tictactoe-2/apps') diff --git a/tictactoe-2/apps/ttt_server/src/game.erl b/tictactoe-2/apps/ttt_server/src/game.erl index 8c6550a..1b8aff2 100644 --- a/tictactoe-2/apps/ttt_server/src/game.erl +++ b/tictactoe-2/apps/ttt_server/src/game.erl @@ -2,7 +2,8 @@ -author("trygvis"). -export([ - game_loop/2]). + game_loop/2, + loop/1]). -import(ttt, [empty_board/0]). @@ -31,6 +32,11 @@ loop(State) -> Str = ttt:format(State#state.board), io:format("game ~p: current state:~n~p~n", [Id, Str]), From ! Str, + loop(State); + code_changed -> + io:format("game ~p: code changed~n", [Id]), + ?MODULE:loop(State); + X -> + io:format("unexpected message: ~p~n", [X]), loop(State) - end, - State. + end. diff --git a/tictactoe-2/apps/ttt_server/src/ttt_server.erl b/tictactoe-2/apps/ttt_server/src/ttt_server.erl index c7167fb..a0de947 100644 --- a/tictactoe-2/apps/ttt_server/src/ttt_server.erl +++ b/tictactoe-2/apps/ttt_server/src/ttt_server.erl @@ -52,8 +52,15 @@ loop(State) -> io:format("Exiting~n", []); {stop, Pid} -> Pid ! ok; - recompiled -> - io:format("Reloading~n", []), + code_changed -> + io:format("Code changed~n"), + io:format("Code changed: ~p~n", [State#ttt_state.games]), + orddict:map( + fun(_Id, [G]) -> + io:format("Id=~p, v=~p~n", [_Id, G]), + G#ttt_game.pid ! code_changed + end, + State#ttt_state.games), ?MODULE:loop(State); X -> io:format("unexpected message: ~p~n", [X]), -- cgit v1.2.3