DEV Community

Aceld
Aceld

Posted on

19. Movement and AOI Broadcast Across Grids

[Zinx]

<1.Building Basic Services with Zinx Framework>
<2. Zinx-V0.2 Simple Connection Encapsulation and Binding with Business>
<3.Design and Implementation of the Zinx Framework's Routing Module>
<4.Zinx Global Configuration>
<5.Zinx Message Encapsulation Module Design and Implementation>
<6.Design and Implementation of Zinx Multi-Router Mode>
<7. Building Zinx's Read-Write Separation Model>
<8.Zinx Message Queue and Task Worker Pool Design and Implementation>
<9. Zinx Connection Management and Property Setting>

[Zinx Application - MMO Game Case Study]

<10. Application Case Study using the Zinx Framework>
<11. MMO Online Game AOI Algorithm>
<12.Data Transmission Protocol: Protocol Buffers>
<13. MMO Game Server Application Protocol>
<14. Building the Project and User Login>
<15. World Chat System Implementation>
<16. Online Location Information Synchronization>
<17. Moving position and non-crossing grid AOI broadcasting>
<18. Player Logout>
<19. Movement and AOI Broadcast Across Grids>


MMO-GAME Source Code

https://github.com/aceld/zinx/tree/master/zinx_app_demo/mmo_game


When players are moving within the user interface without logging out, it's possible that for performance reasons, we need to handle the disappearance of players from our local client's view when they move beyond the boundaries of our AOI nine-grid. The specific process for movement and crossing grid boundaries is shown in Figure 19.1.

Figure 19.1

Figure 19.1

The process of handling visibility disappearance when crossing grid boundaries may seem complex, but in reality, it is similar to the process used before without grid crossings. The key difference is that, when a player moves, we need to obtain two sets of players: one set belongs to the player's old nine-grid but not the player's new nine-grid (Player Set A), and the other set belongs to the player's new nine-grid but not the player's old nine-grid (Player Set B). Player Set A represents the players who are leaving the current player's field of view, while Player Set B represents the players who are newly entering the current player's field of view.

We can then handle the visibility disappearance process for Player Set A and the visibility appearance process for Player Set B sequentially. Finally, we send the current player's updated position information to all players within the current player's surrounding nine-grid, allowing other players' clients to see that the current player is in motion.

This section serves as an additional exercise and does not provide code explanations. Interested readers can refer to the previously developed processes and work on this task independently.

Summary

This chapter introduced a practical project application case based on the Zinx framework. Its purpose was to cover all the interfaces of the Zinx framework that were built from scratch in previous chapters. The project case presented in this chapter is an MMO online map-based scenario that serves as a clear example of using Zinx and custom communication message protocols for server communication.

The first half of this chapter primarily covered some fundamental knowledge related to MMO game business, including concepts like the AOI (Area of Interest) point of interest algorithm. The AOI point of interest algorithm is not limited to MMO games; it can be applied to various map-based applications, such as ride-sharing, nearby people, nearby stores, running systems, and more. These algorithms can help identify associated objects within a specific radius. In this case, communication data layer protocols were implemented using the Proto Buffer serialization standard format. Proto Buffer's binary nature provides excellent performance during encoding and decoding, making it suitable for server-side business scenarios with low latency and high-performance requirements. It's also good practice to define communication protocol formats before starting a project, as this alignment allows for parallel development, ensuring that both sides of communication are clear on the details.

The project case in this chapter didn't fully develop a complete MMO game suitable for enterprise production. Instead, it focused on implementing core backend service logic, including functionalities like login, logout, movement synchronization, movement broadcasting, visibility disappearance, and appearance. For readers with a greater interest, this case can serve as a foundation to develop more advanced game systems or reference solutions for further development.

Zinx is not limited to online gaming scenarios; it can be applied to a wide range of service scenarios, such as dynamic configuration, log monitoring, device management, and instant messaging (IM) systems. Zinx essentially serves as a development board, allowing readers to gain a complete understanding of its internal constructs and code writing processes through this book. If readers wish to implement additional features or create a unique framework based on their requirements and preferences, they can easily extend or engage in DIY (Do It Yourself) development on top of the Zinx framework.


MMO-GAME Source Code

https://github.com/aceld/zinx/tree/master/zinx_app_demo/mmo_game


[Zinx]

<1.Building Basic Services with Zinx Framework>
<2. Zinx-V0.2 Simple Connection Encapsulation and Binding with Business>
<3.Design and Implementation of the Zinx Framework's Routing Module>
<4.Zinx Global Configuration>
<5.Zinx Message Encapsulation Module Design and Implementation>
<6.Design and Implementation of Zinx Multi-Router Mode>
<7. Building Zinx's Read-Write Separation Model>
<8.Zinx Message Queue and Task Worker Pool Design and Implementation>
<9. Zinx Connection Management and Property Setting>

[Zinx Application - MMO Game Case Study]

<10. Application Case Study using the Zinx Framework>
<11. MMO Online Game AOI Algorithm>
<12.Data Transmission Protocol: Protocol Buffers>
<13. MMO Game Server Application Protocol>
<14. Building the Project and User Login>
<15. World Chat System Implementation>
<16. Online Location Information Synchronization>
<17. Moving position and non-crossing grid AOI broadcasting>
<18. Player Logout>
<19. Movement and AOI Broadcast Across Grids>


Author:
discord: https://discord.gg/xQ8Xxfyfcz
zinx: https://github.com/aceld/zinx
github: https://github.com/aceld
aceld's home: https://yuque.com/aceld

Top comments (0)