artvinn

artvinn

Elixir for game server with simple physics calculations

Hi guys! I’ve been thinking about making a multiplayer(I think 50-150 concurrent players per server) web game as a side project, similar to currently popular .io games. Initially I wanted to do it with Node.js due to my experience with it and ecosystem maturity, but now thinking to implement it in Elixir, as I’ve been learning it for some time and haven’t used for any serious project. The server will need to handle calculations like players bounding, velocity, acceleration and simple gravity. I’ve read that elixir is not very good for high CPU computations and I couldn’t find any physics libraries. Would it be too much to calculate all this in elixir? Or it would be a better idea to do it through NIFs or it is very slow?

Thanks in advance :slight_smile:

Most Liked

idi527

idi527

The server will need to handle calculations like players bounding, velocity, acceleration and simple gravity.

I think elixir/erlang would be able to calculate that. But something more involved would require using a NIF probably.

I would model each player as a process (maybe a gen_statem) that would keep all information about itself (its position, current velocity and acceleration, life-cycle status). Gravity could probably be expressed as some callback functions acting on these processes’ states called after each process action.

I think it’ll mostly be simple arithmetics, so erlang should do fine.

btw, I think the miniclips’ ios app for agar.io used erlang on the backend, but c++ for the original browser version. Don’t remember how I learned this, but after a little bit of googling I found these “proofs”:

easco

easco

Not to put too fine a point on it, but I recommend that you try it in Elixir, run some timing tests, then optimize with a NIF if you find performance lags.

Qqwy

Qqwy

TypeCheck Core Team

Indeed, @easco has the right idea.

when you find out that you need NIFs, Rustler nowadays works really well and makes it very clear what is going on.

sneako

sneako

NIF is a Native Implemented Function, a way to run native code from elixir/erlang see http://erlang.org/doc/tutorial/nif.html

mlgarchery

mlgarchery

Sorry guys, but what is a NIF ? thx

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

We're in Beta

About us Mission Statement