The general architecture I set up is very simple.
Frontend access process + backend service logic processing process + database cache process + other collaboration Processes
I. Basic component Introduction
1. All processes of the communication component use a single thread and no other threads. Inter-process communication uses a self-developed communication component.
2. The data protocol component is also a self-developed xml representation. The. h header file and binary binfile are generated using tools. Load data files. Data Files that can interact with databases, network transmission, and other functions are powerful.
The basic components of the game are not described in detail. This article mainly introduces how to use these good components to build a game project featuring availability, stability, and scalability.
Ii. Framework
In a single-process game, internal functions run in a variety of States, such as receiving a signal. The following describes several callback functions.
1. process initialization function, that is, initialization of the configuration file and some components when the program starts.
2. Time-driven function, which runs every second.
3. The message processing function is essentially an endless loop that keeps receiving and processing messages from other modules or networks.
4. Overload functions. When the process has some configurations and other things that require hot updates, you can directly call this function for reload
5. process exit function. After receiving a signal, the process needs to exit safely
....
OK. When we define the callback functions of these modules, the framework will be ready. Then, some component information is initialized for inter-process communication and data description.
Currently, a specific frontend access process is available, which is sent to the backend service process through the shared memory of components.
III. Basic game elements
1. Map
For our mmorpg games, map is the most basic thing. When a player enters the game, he first enters the concept of a world, that is, running on a map and interacting with other players.
To simulate the real life environment.
So our map is like and implementation.
First, you must know that the map is in pixels and is on a two-dimensional flat map. Each pixel has coordinates, but each map is huge and it is impossible to record each coordinate point. Therefore, our program must process the set of vertices.
It requires a good gaming experience and fast processing speed. Select a proper Small Grid. In terms of projects I have experienced, there are diamond, square, and rectangle, and so on, and we will handle them as needed. We have a rectangle with a side length of 30*50 pixels.
This rectangle represents a lot of information. We use a byte to express the information of this lattice. For example, the first is blocking information, and the second is the skill layer, there are eight places to choose from. The frontend and backend must be agreed
Then, when art gives us a map, we will develop a map editor tool to generate a map mask file based on the specified small lattice and the data information agreed between the front and back ends. Provided to the backend.
OK. We have obtained some basic data information, so we need to provide some specific functions. We need to perform some necessary verification for the mask file, for example, when we walk on a map, is the next point a hindrance.
When we release some skills, whether they can pass. Whether it has reached the map boundary, slice attack angle, range, and other functions. Here we need some basic mathematical knowledge.
In order to achieve a more real experience of our game, effects, computer speed, and other factors, we have divided the map into a larger area. It is called a dynamic region. Each dynamic area has a fixed size. This is based on our game screens. Divide the screen into nine areas, each of which mainly contains some entity memory instance IDs. For example, when a player enters this area, we will add the player's memory id to this area, delete it when you leave. This is a dynamic process.
Each map has a tick, that is, the tick we mentioned above.
That is, we promise that when a player sees you, I will be able to see each other. At this time, we use this write to call the packet sending protocol and send our data to the other party.
Because there is a tick, players in the memory will perform tick every second, and the location of the players will be updated every second for dynamic regions.
Similarly, monsters use tick to process monsters on the map. If a monster dies, it deletes its id and updates its view. Then, according to the specific business
2. People, monsters, and things
How to use a computer and then display it on a map.
First of all, we know that all our entities in the computer are actually a piece of memory performance. Through this memory, we record all the data we need to record. For example, the account name and online information.
Then, we first pre-allocate a huge memory pool. When a new account is logged on, we will fetch a memory segment in the memory pool. Now we have recorded the data in the database.
Similarly, we allocated the monster memory, and so on.
3. Skill system.
Skill systems are the most complex of all systems. There are many designs. For example, when a player plays a skill, injury, mp, status, and so on, the damage will be corrected and what effect will the player play.
On the map, how is the performance, whether it can pass through obstacles, and so on.
4. Task System
The task system mainly includes acceptance, completion, and rewards. It is not difficult as a whole.
5. backpack,
It is also the most complicated one. It mainly involves some operations on backpacks. Organize, stack and move, and design a large number of algorithms.
There are many other systems. Currently, I have designed and developed all the systems. At present, I am mainly committed to anti-click farming, performance improvement, bug fixing, and so on.
The next article may mainly introduce network access and specific login sections.
It is quite fun to develop games. I will continue to share my experiences with you in the future.