<div dir="ltr"><br><div class="" itemprop="text">
<p>I try to using Erlang to implement my tiny mmo game server.</p>
<p>I know the skeleton of c++ version is like this:</p>
<pre style="" class=""><code><span class="">int main()
{
</span><span class="">GameApp</span><span class=""> app</span><span class="">;</span><span class="">
int interval = </span><span class="">50</span><span class="">;</span><span class=""> //</span><span class="">50</span><span class="">ms</span><span class="">,</span><span class=""> </span><span class="">20</span><span class=""> ticks per second</span><span class="">.</span><span class="">
int sleep = </span><span class="">0</span><span class="">;</span><span class="">
uint64_t tick_start</span><span class="">,</span><span class=""> tick_end</span><span class="">,</span><span class=""> tick_passed</span><span class="">;</span><span class="">
while(true)
{
tick_start = </span><span class="">CurrentTick</span><span class="">()</span><span class="">;</span><span class="">
// all logic</span><span class="">,</span><span class=""> timer will be drive </span><span class="">in</span><span class=""> the app</span><span class="">.</span><span class="">tick
app</span><span class="">.</span><span class="">tick(tick)</span><span class="">;</span><span class="">
tick_end = </span><span class="">CurrentTick</span><span class="">()</span><span class="">;</span><span class="">
tick_passed = tick_end - tick_start</span><span class="">;</span><span class="">
sleep = interval - tick_passed</span><span class="">;</span><span class="">
if (sleep < </span><span class="">0</span><span class="">) sleep = </span><span class="">0</span><span class="">;</span><span class="">
</span><span class="">SleepMilliSeconds</span><span class="">(sleep)</span><span class="">;</span><span class="">
}
}</span></code></pre>
<p>But now, I have no idea about the Erlang version.</p>
<p>in the erlang world, one client is one process (maybe <code>gen_server</code>).
the process has it's own loop, and timer can use <code>erlang:send_after</code> or <code>erlang:start_timer</code> .</p>
<p>I want to know how to implement a MMO server in erlang ?</p>
<p>consider this situation:</p>
<p>Player A VS Player B.</p>
<p>A cast a skill X to some direction, then X flying.</p>
<p>the server need to detect whether X is hit on B,</p>
<p>When hit, add X's debuff on B, debuff will remove after 3 seconds.</p>
<p>......</p>
<p>many things , many times , many sync ...</p>
<p>c++ has a signal tick,</p>
<p>But how about erlang ?</p>
</div><br><br><br><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr">My GitHub<br><a href="https://github.com/yueyoum" target="_blank">https://github.com/yueyoum</a><br><br></div></div>
</div>