The Erlang Game Loop

After my last blog post I took the time to signup for Linode and setup my application there.
After running a few tests it was apparent my initial game loop was flawed.
Even with the beefy hardware the erlang beam process was hitting 300% after around 50 areas.

My initial approach to the game loop was a bit naive. 
When loading each area I would spawn an erlang process with a game loop that would grab all the players in that area and process any new move flags, pathfinding, checking collisions, updating character positions, etc.

I figured that even though this was CPU intensive it shouldn't be too much of a problem.  I was wrong.

However, if you pay attention you'll notice I can easily improve this by having a global game loop, and processing all the players regardless of their area.

So, the old was was something like this in pseudo-code:

foreach (areas)

It took me no longer than 30 minutes to update the code.  Now it looks like this:

foreach (areas)

I then ran some tests on my Linode, first I had to set my ERL_MAX_ETS_TABLES to 7000.
I was able to load over 3000 areas with the beam process hovering around 10%.  Great!

It now seems like SolomonRPG should handle well for a good while.  There are a few things that need to be smoothed out, but for the most part everything seems to work.
With all these areas the only issue is now running out of memory but Linode has some good plans for adding more memory.  And although I haven't done much testing, thanks to Erlang, I think I can just add more nodes and have them process sets of players.
For example, have node1 process players 1 - 1000, node2 1001 - 2000, node 3....
Or perhaps separate them by area.  Either way should be easy to implement, damn Erlang rocks.


On The Road to Release - Part: 1

After having ported the map editor to HTML and Javascript, I also took the time to setup a domain and implement the player's website.

The final url for the game is: solrpg.com

There is still a lot of work to do, though, before I release the client in the Android Market and enable signups.
Here's a breakdown of what's needed or being worked on.

For reference, here is the hardware I'm developing the SolomonRPG server on:

1 Core CPU - AMD Duron(tm) 1.2GHz
80GB - PATA Hard Drive
Cent OS 5 - x86

Hosting - Linode
At the moment, the domain is hosted on my only spare computer at home.
Obviously, I can't release the game because my upload speed is pathetic.

Linode has a hosting plan that starts at $20 a month.  I've been hearing good things about them, and I'm excited to try them out.
Here's what the basic hosting plan includes:

4 Core CPU - Intel(R) Xeon(R) CPU L5420 @ 2.50GHz
512MB - RAM
16GB - Hard Drive
Cent OS 5 x86_64

The Solomon server holds a lot of small bits in memory ram, such as player credential, player location, status, tileset layouts, etc.
Simply storing a player and area definitions in memory can be a scaling issue
However, from preliminary tests reveal the real wall seems to be the game loop for each area.

Each area has a process that handles all the game logic for that area.  Each game loop runs at a variable 60FPS.
This is fairly CPU intensive, and my development machine starts giving out at barely 20 areas.

At the moment, I'm not sure if I can optimize this.  Perhaps by having a game loop for each Erlang node and try to squeeze the game logic there, but I haven't given it much thought.
I want to do some tests on the Linode host itself to see if its worth my time to optimize.

Content Creation
The fun part is creating content for the game.  Creating tilesets using Gimp and constantly testing them out and choosing which tiles to use.
I have choose carefully because tilesets have to be as small as possible.  The bigger the tileset, the longer it takes to load in a mobile phone.

Mapping out areas is also quite fun, I have to first map out the world on grid paper with a pencil.
Then, mapping out each area using the new editor. 

Story making is another challenging aspect.  For that, I'm turning to my favorite book in the world, The Bible.  In the coming months, I hope to continue carefully reading the Bible and implementing some of the cool stories into the game.  I want people to know that I'm Christian and that God was the only one who helped me make this game, I never would have been able to get this far by myself.

Polish, Polish, Polish
Continue to refine the SolomonRPG codebase and try to fix as many bugs as possible.
Make the client not drain the phone battery.
Lower the SolomonRPG CPU requirements.
Implement scripting in Erlang using erlang_js (MAYBE)
Make teleporting from area to area as smooth as possible.

Funds and Revenue
If I am unable to lower the CPU requirements, it'll be very expensive to release the website for the game.  Ideally, I'd like players to create as many areas as they'd like for free.
I will have advertisement in both the client and the website, but I'm not sure if it'll be enough.
I don't have a budget for the game at all, and I'm trying to save up enough to sign up for the Android Market and the first month of hosting.  Anyway, I'm thinking of adding a donation button to the blog.  We'll see though.