Photon Framework - MMO Client/Server Foundation

My name is Christian Richards, I run CJR Gaming and today, I would like to present my “Photon Framework”.

I have been working with Photon for over 2 years now. My first videos were on the Release Candidate of Photon 3.0 At the same time I started the videos, I started the framework. I started simple, with code to get photon to work. Then I rewrote it from scratch when Exit Games added in the Server2Server piece for Photon. Since then I went on to build what this framework has been turned into.

First a little bit about what this isn’t:

  • It isn’t an MMO “easy” button
  • It isn’t complete
  • It isn’t simple scripting

That is to say that this framework is the beginning of an authoritative client/server setup. It isn’t a simple set of scripts, but a foundation built by a developer who has worked for 13 years building applications for 3 companies.

So if it isn’t complete and it isn’t an easy button, just what is it?

Right now it is comprised of:

Through my tutorials, website and streams I continue each week to push this code a bit further.

So how is this different from the vast majority of other “MMO posts”?

As I said above, this is a foundation with which to build an MMO. I strive very hard to make sure it is modular, easy to work with, and easily updated. I also work week after week taking in feedback and comments to iron out kinks in the code.

At the time of this writing, I also have prototype code for a World server, client prediction, and I’m working on getting stats working. The world server will eventually handle communication between region servers and will serve as the server that groups are held on so they can go across regions. The only concrete character stat I have is MoveSpeed because it is used by BulletPhysics and the client to determine where others are going to be until the server updates that position directly. All other stats don’t even exist until they get written so you aren’t locked into a specific set of character stats.

It is my intention to continue to build this framework piece by piece in such a way that people will be able to quickly modify it to suit their needs. Again, this sounds like an “MMO easy button” but it isn’t. You actually need experience programming to work with the client and server.

If you think this is something you are interested in, hop over to my site and consider purchasing it. And be sure to check out my YouTube channel where I constantly post new videos adding on to the framework.

Some of you may be asking why I’m selling this on my site and not on the asset store. Really, it boils down to the fact that it relies on more than just Unity3d. It isn’t just an asset for Unity3d, but rather a package that contains both the server and client components that happens to use Unity3d for the client portion of it.

In the future as I build more modules for the framework, I will post them up for sale.

Glad to see you finally got to a point to “release” what you were working on. I of course have been following you, and thank you for all the learning tools you have provided… Got a purchase from me, but you already knew that. :slight_smile:

For those that are interested, the prototype repository is updated every time new code is added.

Tonight’s stream on twitch made some changes and got smooth movement up as well as client side prediction for other players.

I’ve also already begun the modifications to work with stats. Once the core functionality for calculating a stat is done I’ll focus my attention on effects (buffs and debuffs) that modify stats and then move on to skills (passives and spells) that apply effects and lastly move on to items (armor and weapons). As I finish different pieces of the prototype, I begin incorporating those changes into the tutorials as new modules.

I have been following this series for awhile, its great to see you bringing it to the forums! I can definitely recommend this to anyone who is interested in building a well thought out framework for online gaming. Now you can just get the code but the videos are really great for understanding the reasoning behind the framework decisions. Since it is open source you could always modify it to fit your specific game if you needed.

BTW, the physics module is looking really awesome. I have been enjoying watching this series progress, especially now that we are getting to the fun parts. :smile:

-Dane

Love your series CJR, they’re very educational and a great motivation :smile:

I do have one question about your physics module. Now that you’ve moved over to bullet, you’re not longer using a managed physics engine like DigitalRunes so you lose out on web player builds. Any reason why DigitalRunes didn’t work out for you? Web player builds is super important to me.

The reason I moved over to BulletPhysics was to keep everything using free components. If you notice, I am actually using a C# conversion, not a wrapper. Using this conversion shouldn’t be causing web builds to no longer work. I did this specifically because web builds are also what interests me. I’ll do some testing, but I was 90% sure that the Bullet Physics conversion was working just fine with Web Builds. If you are running into specific problems, I would LOVE to know what you ran into so that I can correct it, as I want this viable for iOS, Android, Web, and Win/Mac/Linux support.

Ahh my mistake, I thought it was a wrapper. Wow, I’m switching over asap!

For you, and those interested, the conversion I use is located here I did not convert this, but did clone it, made several changes, and reuploaded to my bit bucket. You can find the original at Google Code. As you can see, the author’s last changes were getting it to BulletPhysics 2.79, I updated it with the changes made up to 2.82.

So I’m testing out BulletXNA right now on Unity, just to see how I’ll be able to handle CSP in the future, and I’m a bit worried about the performance.

Here’s a screenshot of my scene:


http://content.screencast.com/users/DigitalGlass/folders/Jing/media/db4eb38f-1d2d-47c6-a428-96afad02d205/2013-12-14_1240.png

I followed the same setup you did on the physics module, and right now with 32 kinematic character controllers, it’s costing 10-11ms per frame which is pretty concerning. Have you spent any time benchmarking the physics modules yet? I’ll do a comparison with BEPU later

No, I haven’t done benchmarking yet. I went looking for anything that was C#, open source, and not a wrapper around a C++ library. The only thing I had found was the conversion of BulletPhysics. I wrote the code in such a way that it should be easy to remove BulletPhysics and move to another physics engine. So if you find better success with BEPU, i can work on a new BackgroundThread, IPhysics implementation, and exporter and present it with the code. Especially if it is better performance wise.

One of the things I don’t like about BulletPhysics is that many of the objects are structs, which means any time i say var x = obj.posistion; x is a new copy of obj.position and will be garbage collected.

So I have started going through BEPU Physics. It does appear to be much better in terms of memory usage and usability. Once I get it fully functional, I will probably record a set of tutorials to switch over to BEPUphysics.

Right now I’m just getting it to work in my own code.

One of the nice things is that their demos show you how to already get moving platforms working, which is a big plus for many people. I’m really looking forward to seeing what all it can do.

That’s great to hear :slight_smile: I did a test with boxshape rigidbodies, and not only is the performance better by about 0.1-0.2ms after spawning 32 objects. It also produced no garbage, which is a really good sign. I plan on doing a comparison of the kinematic character controllers, but the latest version of BEPU doesn’t seem to run by default in Unity, so I’ll need to dig in to figure out what’s wrong.

The “problem” is that BEPU uses .NET 4.0 to handle its threading with Parallel.For

You can do one of 2 things, go into the ParallelLooper and comment out the Parallel.For and use Thread.Sleep(0) (also comment out the #if Windows and other directives) or you can go in and download the TPL backport for .NET 3.5. Then you just have to set the properties to use .NET 3.5 and you can pull it into Unity.

The TPL backport sounds promising, I’ll try that one out when I get home tonight.

Alright I plugged in TPL and it’s working great. Tried out the kinematic controller, and I have a capsule moving aroundish. Unfortunately I’m out of time tonight to continue testing. I’ll try to set up a benchmark tomorrow and let you know how it performs compared to BulletXNA

The Photon Framework has been updated. I have included everything in the videos up to this point. That means that Interest management is fixed and ready, the Physics Exporter is included automatically, and Physics is now more responsive. This still uses BulletPhysics, but in the near future, along side the videos for the stats module, we will cover the conversion over to BEPU Physics.

Alright, so with BEPUPhysics, it takes around 0.9-1.2ms to tick 32 kinematic character controllers. Compared to BulletXNA which takes an average of 10 ms. BEPU generated 4.5kb of garbage, Bullet generated 20kb.


http://content.screencast.com/users/DigitalGlass/folders/Jing/media/abb42604-63ba-40bf-b9af-609d880d667d/2013-12-18_2333.png

So we’re looking at BEPU being 10x faster than BulletXNA in this case. I remember someone on the forums had implemented Jitter into their project but I don’t think that user ever posted any benchmarks.

Anyhow, you were already going to switch over, I just wanted to have some numbers to throw around in case anyone asks.

Wowhoho, just stumbled upon your project. Seems like you dont have own forum so I`m going to use this thread for all my questions, ok?

Im a noob in a Photon and the Framework - just began to look through tutorials. Sorry if I ask too easy thing but Im so impatient to know! In fact I try to implement a hexagonal-tile-turn-based-tactics game, if that context does matter for the following questions.

  • Is there a roadmap? Could you probably update the 1st page with it?
  • What updates are going to be avaliable for 100$ and what will be above?
  • Is it possible/easy to have a Photon authorative server created/found on demand by a player in lobby?
  • Is it any easier to achieve fog of war than with Unity Networking? I mean enemies positions and animations get updated while visible for certain clients only.

If these things are ok, than your framework is going to save me tons of time and really worths the money.

The roadmap isn’t “well defined” I know what features I want to cover, but not their order. I’m looking at Smooth Movement, Stats, NPCs, Items, and Quests in the near-ish term. I already have the stats code prototyped out. I want to finish up what I call “StatusStats” which are things that change frequently such as current hp/mp/stamina and experience. Again I’m working on something that doesn’t require those specific stats because I want others to be able to say “We don’t have experience or levels”

The 100$ purchase gets you everything I’ve done up to this point. I am not planning on updating it beyond this point except with fixes that I or others encounter and a separate download that will replace BulletPhysics with BEPU physics because it appears to be a superior product compared to the C# conversion of BulletPhysics.

I have not worked on a Lobby/GameServer module. It was something I considered, but my focus has been on things generally used in MMOs. It isn’t “hard” to make one: you would start with the login server and after they logged in and moved to “in game” that server would need to know all other servers, create a “key” to tell the game server you are who you say you are and go from there.

the “fog of war” is the interest management piece I put together. right now that works for single players. If you are aiming for an RTS or 4x game or something that can see pieces and parts from different entities, then that is a horse of another color, and while it is possible to add on, it isn’t something it does currently.

These are all things I would like to work on and make available, but I only have so much time each day since I do have to work for a living.

For those who are interested, this week I spent recording the entire stats module, it is 7 videos long ranging from 7 to 30 min. I am encoding them now and expect them to be posted tomorrow.

This module defines a generic way to build stats without locking you into specific stats. Most places force you into HP/MP and you are stuck with experience, etc being defined for you. This takes that out of the equation by generically defining what a stat is and how you can use it across your setup.