Simple Elixir Game Suit design-player process run up

Source: Internet
Author: User

With the player model, we try to make the player process run.

A playersupervisor is required to initiate and monitor the player process.

defmodule playersupervisor do and    Supervisor    def  Start_link (_opts)        do Supervisor.start_link (__module____module__)      end    def  Init (: OK) do        supervisor.init ([Playerserver], strategy:: Simple_one_for_one)    end    def  start_player (player) do        supervisor.start_child (__module__, [player])            EndEnd
Player_supervisor.ex

Get a playerserver to take charge of the player process.

defmodule playerserver do use    genserver, restart:: temporary, start: {__module__,: Start_ Link, []}    def  Start_link (player) do        Genserver.start_link (__module____ module__)      end    def  Init (player) do        {: OK, player}    endend
Player_server.ex

Test code for Plyaer_supervisor

defmodule playersupervisortest do and    exunit.case    doctest playersupervisor    setup do        Start_ Supervised playersupervisor        %{}    end    " test playersupervisor start Playerserver "Doassert {: OK, _player_pid} =  playersupervisor.start_player (         Player.init)    EndEnd
Player_supervisor_test.exs

In the next chapter, we will solve the player process registration problem (now only 1 players), if only a single service can be used with elixir registry.

Cross-serve words with SYN or GPROC.

Because it's just for demonstration (work easy), I'll use registry.

At the same time Game_server is the time to modify the app to launch.

Simple Elixir Game Suit design-player process run up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.