<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="197489" data-post-id="197489">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mjaric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mjaric/120/7788_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mjaric
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>There are so many “depends” what the game is.</p>
<p>Simple games such as chess shouldn’t be a problem, game session state consists of 64 elements in simplest implementation. There is no frames, and state is changed only on user interaction. The rest are functions that should guard legal/illegal moves and are called only when user interacts with backend.</p>
<p>But games such as Call Of Duty, that should handle N player is rather challenge. Here you need to think in frames, hence, you need to process all relevant data in “single pass”. This is not concurrency problem, it is rather parallelism problem when you have to execute game logic in single frame, in other words you have max 16.7ms  to process state and respond to all clients.</p>
<p>I don’t say it is impossible, but it depends how demanding processing is. Erlang gives you process isolation out of the box, and that is fine for communication, but you will find challenging the part with parallel processing.</p>
<p>I do think that <a href="https://en.wikipedia.org/wiki/Entity_component_system" rel="noopener nofollow ugc">ECS</a> can be implemented, where state is stored in ETS in form of components, then use pipeline (GenStage) processes to run game logic you need. For instance here is one frame:</p>
<ol>
<li>query player bullets, recalculate their new positions store in ETS</li>
<li>query players and bullets, check if player entity is in collision with bullet… store player status and bullet status in ETS</li>
<li>query survived players and move them in requested direction</li>
</ol>
<p>Of course, you can filter or split entities in stage before the one that will execute above, then process each chunk in parallel. Good example is when some players are in one room while others are in other room. Then you can split processing in two parallel processes and handle each separately, since bullet can’t pass through room walls…</p>
<p>Of course, ECS is not the only game engine interanls, there are others that maybe be better fit for your case, but at the end, you will have to think how to slice data into smaller chunks so you can quickly process it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="197489" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/use-case-for-elixir-phoenix-as-a-game-server-thoughts-appreciated/36055/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-197489" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="197489"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>