Tuesday, December 06, 2011

Multiplayer Milestones and A Summary of the Past Year

I started coding today by jumping straight into multiplayer.  I added support for structures, multiple players, AI and the environment when I realized I'm doing this all wrong.  I need to stop and rebuild from the ground up.

So I've come up with a plan.

I have my base server.  It currently compiles fine, but most of the sections where I'm checking for player collision are commented out because they currently only support 1 player.  I need to add multiple player support for those, but that's for later.  For now, I have my base server with all of the AstroMiner objects and classes built in and compiling.

Next on the list is the world.  Generating asteroids, for starters.  This will be done on the fly, like it currently is, and the player should be able to fly around in an infinite world, like they can currently do.  This also means I will be adding support for multiplayer player movement, light support (which I'm going to calculate client side) and some other things.

Once that milestone is passed, I will move onto adding/deleting blocks.  This will force me to build out a changesManager that can dynamically update from any source and report what changes it has so I can build an efficient packet to send.  We obviously don't want to send all the changes all the time.  We only want to send updates.  These kinds of updates are important, so they will require some validation on the client end telling the server that they received the update.  This will also require me to sync up the player's inventory (and now that I think about it, the floating items manager (the little blocks that drop when you eat a block) will have to be working here).

At that point, I should be able to have multiple players log into the same server, delete and change blocks and have them see eachother's updates.  That will be a major milestone because I will have collision detection for multiple players done, an efficient packet packing algorithm and a streaming server-side world that can save itself to the file system.

Next on the list is environment.  This will be game night/day sequence, gravity for any objects that register for it and water.  This one will be easy because it's pretty much already done, but nonetheless it's on the list to be reviewed and updated.

After that, structures.  I believe this will be one of the hardest to implement and that's why I've saved it for the very end.  Lots of objects check to see if the player is near them to activate.  I can do a foreach() on every logged-in player and check, but that seems horribly inefficient.  In order for this milestone to be complete, the player should be able craft an object (this will be validated client and server-side), place and remove it from the world.  The structures should all run their normal update() routines.

The next, and definitely hardest out of the bunch, will be the AI manager.  90% of the AI manager will have no problems and will be a seamless transition.  10% will be very complicated.  That last 10% is enemy movement and player collision detection.  There could be hundreds of enemies in the world and all of them need to check for player collision.  They also need to detect if they're near a player and if they are, go towards that player.  A foreach loop would also work here, but again - very inefficient.

So that's my multiplayer roadmap.  My goal is to have this done by the end of the month.  That's my goal because I'm going home to see my brother before he ships off to the Navy and I'd like to play multiplayer with him there before he goes.  I have a feeling that once I get started and figure out the fundamentals of how this server should be laid out, the rest is going to fly by quickly.

I still don't have a 100% solid idea of how I want the client to interpret the data.  I have an idea of how I want to efficiently build packets and how each player will have their own custom packet.  Sending it is already done.  How the client will interpret that packet and use it to update the world, though, is still a little foggy.

So anyway, that's my plan.  I feel like this is a whole new chapter in my game development saga.

- The First Chapter was just getting started.  Learning about Unity, 3d and the different engines/languages I can use.

- The Second Chapter was my Minecraft clone.  I learned about algorithms, heavy 3d triangle strips and efficient ways of rendering millions of cubes, player input and writing very efficient code.  Object pools and utilizing floats efficiently.  Using the Garbage Collector as little as possible.

- The Third Chapter was the beginnings of AstroMiner.  Creating a seamless 2d world.  Adding/deleting blocks.  Spritesheets.

- Fourth Chapter would be AI.  Implementing an effective, "thinking" enemy that can react to the player.  Making that enemy spawn in ways that make sense.

- Fifth Chapter would be crafting and structures.  Creating graphics that make sense.  Creating structures that take time to do their job.  Creating structures that pay attention to their surroundings and react accordingly.  Turrets that shoot enemy, doors that open and close and tractor beams that raise and lower the player.

- The most recent chapter, the Sixth, was all about fluids.  Creating an efficient fluid engine that let me have vast amounts of liquids and let them all update and react with the world around them without taking up tons of resources.

And now we're on the Seventh Chapter, multiplayer.  I've barely started this chapter and I've already learned a lot.  This might be one of the most challenging ones yet, mainly because I have so much of the fundamentals already done and there's so much that now needs to be changed.  I feel like I will definitely learn a lot though.  The nice thing is, at the end of the day, that's the point of this entire adventure.  To Learn.

So until next time my friends. ~

Learning 3d

First AstroMiner concept

First AstroMiner Build

Latest Screenshot

No comments: