Some records about player default data in game development

      The most recent work of the blogger is to develop the task system of the game. After reading my code, the leader gave me some suggestions.

      The mission situation is probably like this. After a player logs in, the client will display a mission button, and the player can view his mission after clicking. According to planning needs, players currently have a dozen missions. The mission data of each player must be recorded in the DB (database).

      My initial approach was:

      1. If the game has a task system enabled, when the player logs in, I will assign default values ​​to each task.

      2. Record these default values ​​into db.

      3. When the player clicks on the task icon, the client requests the player's task data, and the server returns.

      Occasionally, although my code can also achieve functions, the leader discovered that my code will do a lot of db operations in an instant, and then told me that the content is roughly as follows: " General db operations are one of the bottlenecks of our server. There is no need to assign a default value to each task at the beginning and record it in the db. When the client requests it, a default value is directly returned. When the player participates in a specific task, the player's data is calculated and recorded in the database. ",

      I thought about it later and felt that it made sense.

      1. Some players may only log in once, click on the task icon, but do not do the task, I will record all the task data for him when he clicks on the icon (default value).

      2. Some players may log in and only do one mission, then stop playing, but I will record all mission data for him when he clicks on the icon (default value).

      3. In an instant, many players click on the task icon for the first time, which will cause many db operations in an instant.

      。。。。

      There are too many reasons to show that this is a very bad design.

      After thinking about it, I sorted out the program changes and expressed it as follows:

    1. The player clicks on the task icon. When the client requests task data, if the player's data is not recorded in the database, it will directly return a default value. For example: if the task is to kill 1000 frogs, 0 will be returned directly, and there is no need to record in the db

     2. When the player participates in a specific task, record it in db. For example: if the player kills 100 frogs now, 100 will be recorded in the db. When the player clicks on the task icon next time, return to 100 in the storage and db.

     After this modification, the default values ​​of the default various tasks will not be written to the db at the beginning. Even if some players log in once, they also click on the task system, and their data will not be recorded to the db. When the player clicks on the mission system for the first time, there will not be a lot of data to be written to db instantly.

 

     For this record, I may still have some areas that are not well designed. Welcome to discuss with each other.

Guess you like

Origin blog.csdn.net/banfushen007/article/details/103445717