Creating a server for online MMO games in PHP part 10 – Open seamless world in a 2D game and what does drones have to do with it

This time I will tell you how we managed to implement an open seamless world in a horizontally scalable 2D online gameas well as share the idea of ​​​​controlling reconnaissance unmanned aerial vehicles over vast territories.

about the project

For those who read my articles for the first time – I develop authoritarian server gaming controlled by API and application software for editing maps, game mechanics, managing downloadable content (music, animations, dialogues, translations) and talk about it in a series of articles. This will be a single play space (not rooms) where NPCs will be controlled by artificial intelligence.

This is a Russian development – an analogue of Western services such as Firebase, Photon, PlayFab, Mirror, RakNet, AWS GameLift (in any case, this is what the ChatGPT neural network answered me).

open world

The general principle of the open world is based on the fact that the game becomes non-linear – we can go wherever we want and usually this is associated with side game tasks. However, if the world is huge, then it will take a lot of computer resources to fully load and process it. This problem is solved by breaking the world into separate locations, the transition between which is associated with the loading of the game (during which some kind of animation usually plays).

edge of the Fallout game location on the bottom right

edge of the Fallout game location on the bottom right

Seamless world

we see neighboring loaded game locations

we see neighboring loaded game locations

With a seamless world, everything looks much more interesting – being in a certain location, those locations that are around us are loaded into the computer’s memory, provided that we approach their borders. Often fog is used in an area where locations are not loaded (for example, we have moved far away from them and they are removed from RAM until we get closer to them). This is mainly used for 3D games.

My implementation for a 2D online game

I already made sure that the world will be open and scalable (where each location can be separately on a physical machine), it remains to figure out how to make it seamless.

The first thing that came to mind was to connect via a websocket channel not only to the server (location) where we play, but also to adjacent ones. However, this idea had to be immediately abandoned, because not only the client (player), but also the server (location) where the client plays needs to know what is happening on neighboring ones (for example, the mechanics of a projectile explosion at the border of locations should also affect those creatures that will be at a neighboring location near the border ). As a result, our server location always connects via websocket to adjacent locations (that is, the server also becomes a client).

Immediately there were problems – the server rises after a reboot only if someone plays on it (I had to implement an internal api for the servers themselves that checks the status of another, restarts, stops and starts the selected server location), as well as the problem of consistency of who should connect with whom because neighboring locations also want to connect with us, forming some kind of network (a temporary solution was that the server whose sum of numbers in IP is higher should initialize the connection, and if there are several locations on the same physical server, in addition we will check the port locations operate on different ports within the same physical server).

The priority server raises the location and initiates a websocket connection to it

The priority server raises the location and initiates a websocket connection to it

A neighboring location where no one has risen and accepted a request to connect to a priority server (where the player logged in)

A neighboring location where no one has risen and accepted a request to connect to a priority server (where the player logged in)

Our server where we play receives packets from neighboring locations what is happening there (thus it has an understanding of who is there) and already relays to all players’ clients, and also sends packets to neighboring locations what is happening with it.

Border of multiple server locations

Border of multiple server locations

I had an idea that in this way you can control drones over a vast territory

It remains to implement the functionality of the transition between servers (they can be physically different machines). The idea is the following:

  • The player sends an exit command to the server

  • The server saves the player in the database

  • The server removes the player from the array of creatures located on it, we send out a command to everyone that the player is removed from the server

  • Clients receive a command that the player disconnects, wait a couple of seconds and remove this “prfab” from the stage (in Unity, game entities are called prefabs)

  • If in those couple of seconds that clients are waiting for the removal of the prefab, it appeared in another location server – we animate a smooth transition of the border

In the client side developer panel itself (I’m currently using Unity), the locations and the creatures (prefabs) in them look like this.

Layer group Map - contains graphics of the current (center) location and neighboring (left)

Layer group Map – contains graphics of the current (center) location and neighboring (left)

World layer group - contains the prafabs of the current (center) location and neighboring (left)

World layer group – contains the prafabs of the current (center) location and neighboring (left)

As a result of the first experiments, the transition between locations turned out to be not very smooth, but in the following articles I will tell you how to fix this and how to process only those creatures that are visible to the players. A demonstration of what happened in the video below:

In conclusion, I want to say the following: once again seeking support from our Russian state for the development of the project (I do everything using my personal means), I encountered criticism of the form: “one person will not be able to do anything – it is necessary to support the companies. they have teams“, and in turn, representatives of the business of the gaming industry declare that this is a long time and hundreds of employees of Western companies are working on similar projects – where are we before them. Thus giving up before you even start.

I sincerely believe that if one person has an idea and the desire to solve it, he will succeed over time.

If you are interested in following the implementation of the project (address my‑fantasy.ru) – you can subscribe to me and be aware of the release of new articles.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *