2 - C++ Development of "Fight the Landlord" - Backend Architecture

Translation: In the preliminary phase of our work, we have established the communication protocol and data structure of the project, and selected TCP protocol with JSON format for data transmission and parsing.

Entering the architecture design stage, we faced key decisions regarding the choice of thread model: whether to use multi-threading, multi-threading combined with coroutines, or single-threaded mode?

Given that database operations constitute a significant portion of I/O operations, primarily focusing on user registration, login, and player data archiving, among others. Specifically, the data archiving part can be handled entirely by an independent thread.

Therefore, we designed a dual-thread structure to handle a large volume of work: one main thread for game logic and another dedicated to database-related operations.

Benefiting from the network library encapsulated by YLIB, which is based on HPSocket, it supports high-concurrency connection management, thus reducing concerns about network communication. The network thread is responsible for receiving data, which is then directly passed to the main thread for processing after preliminary validation. If there are data update (UPDATE) operations in the main thread that consume a considerable amount of time, they are forwarded to the database thread for asynchronous processing.

Through this division of labor, we ensure both the coherence and real-time response of game logic, avoid blocking the main thread due to database I/O operations, and fully utilize the advantages of multi-core CPUs to improve the efficiency and stability of the entire game server.

Architecture design

Manager or contriller(unique instance)

图片.png

name illustrate
PlayerManager Player Manager, manages the cached data of all online players
RoomManager
ServiceManager Referring to Skynet’s design philosophy, the various functional sets that handle game logic are all services
RoomQueue Game room queue. Players click Start Game to insert the queue until three players are satisfied, and then call RoomManager to create a room
ConfigManager Configure File Manager, maintain a config.json configuration file

Analysis Services

The service inherits the IService interface class and is bound and added to the ServiceManager during construction

图片.png

Operation process

图片.png

Title of this article:<2 - C++ Development of "Fight the Landlord" - Backend Architecture>Author:minimini
Original link:https://www.xxmjw.com/post/14.html
Unless otherwise specified, all content is original. Please indicate when reprinting.

Related

minimini

minimini