Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Convert egs_quests_sup to a simple_one_for_one supervisor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Hoguin committed Jun 8, 2011
1 parent e227466 commit c42b1a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/egs.erl
Expand Up @@ -29,13 +29,15 @@

%% Location related types.

-type uniid() :: 21 | 26..254 | 16#ffffffff.
-type questid() :: 0..16#ffffffff. %% @todo What's the real max?
-type zoneid() :: 0..16#ffff. %% @todo What's the real max?
-type mapid() :: 0..9999.
-type entryid() :: 0..16#ffff. %% @todo What's the real max?
-type area() :: {questid(), zoneid(), mapid()}. %% @todo Probably remove later.
-type position() :: {X::float(), Y::float(), Z::float(), Dir::float()}.
-export_type([questid/0, zoneid/0, mapid/0, entryid/0, area/0, position/0]).
-export_type([uniid/0, questid/0, zoneid/0, mapid/0, entryid/0,
area/0, position/0]).

%% API.

Expand Down
14 changes: 10 additions & 4 deletions src/egs_quests_sup.erl
Expand Up @@ -20,19 +20,25 @@
-module(egs_quests_sup).
-behaviour(supervisor).

-export([start_link/0]). %% API.
-export([start_link/0, start_quest/2]). %% API.
-export([init/1]). %% supervisor.

-define(SUPERVISOR, ?MODULE).

%% API.

-spec start_link() -> {ok, Pid::pid()}.
-spec start_link() -> {ok, pid()}.
start_link() ->
supervisor:start_link({local, ?SUPERVISOR}, ?MODULE, []).

-spec start_quest(egs:uniid(), egs:questid()) -> {ok, pid()}.
start_quest(UniID, QuestID) ->
supervisor:start_child(?SUPERVISOR, [UniID, QuestID]).

%% supervisor.

-spec init([]) -> {ok, {{simple_one_for_one, 0, 1}, [{_, _, _, _, _, _}, ...]}}.
init([]) ->
Procs = [],
{ok, {{one_for_one, 10, 10}, Procs}}.
{ok, {{simple_one_for_one, 0, 1}, [{egs_quests,
{egs_quests, start_link, []}, temporary, brutal_kill,
worker, [egs_quests]}]}}.
2 changes: 1 addition & 1 deletion src/egs_universes.erl
Expand Up @@ -152,6 +152,6 @@ create_unis([Name|Tail], UniID, Acc) ->
%% @doc Start lobbies for the given universe.
init_lobbies(UniID) ->
lists:map(fun(QuestID) ->
{ok, Pid} = supervisor:start_child(egs_quests_sup, {{quest, UniID, QuestID}, {egs_quests, start_link, [UniID, QuestID]}, permanent, 5000, worker, dynamic}),
{ok, Pid} = egs_quests_sup:start_quest(UniID, QuestID),
{{UniID, QuestID}, Pid}
end, ?LOBBIES).

0 comments on commit c42b1a8

Please sign in to comment.