After a period of thinking and learning about the game engine HGE and ogre, I think duilib should refer to the game development method to do some refactoring: the functional hierarchy can be divided into the main framework, Window Manager, event manager, rendering processing, logic processing, resource management, time system, script, and GUI.
1. Main framework: It is responsible for creating a unique physical window, processing system messages, and generating input events. It is also a main cycle that should have the start and stop functions.
2. Window Manager: All windows are virtual and can be conveniently managed when window switching and communication are involved. It is also very scalable to define window switching animations.
3. event manager: Manages input events and logical events in a unified manner. Input events are generally converted from system messages, while logical events are generally generated by logical processing. The event notification mechanism uses a hosting mechanism similar to C #, which is distributed to registered listeners (Windows and controls) by the event manager)
4. Rendering
(1) implement a frame callback method to adjust the refresh frequency according to the actual situation.
(2) frames can be split into logic processing frames and interface rendering frames, which are completely separated in different threads. Logical frames are used to process data and rendering object state changes, the rendered frame is used for actual rendering, and is synchronized at the end of a frame.
(3) the DDX mechanism of MFC can be used for processing simple data. For example, when the volume is adjusted, refresh of the view is triggered after the data volume is modified by logical processing.
5. Logical processing: processing data and event status switching, and notification Rendering
(1) Simple logic processing is directly completed in the event processing function.
(2) using finite state machines for complex logic processing
(3) There must be a synchronization mechanism for logical processing and rendering.
6. Resource Manager: Manages images, text, and sounds in a unified manner
(1) There is a resourcegen tool in the development framework of popcap_framework, which can generate a resource configuration file containing only the ID and path. The advantage is that the image and text can be dynamically changed.
(2) Resource pre-read thread. This helps improve efficiency when there are enough resources in the main framework.
(3) high-speed cache: prevents excessive resources from occupying a large amount of memory.
7. Script: If the interface and logic are completely separated, it is easier to use scripts for logical processing.
8. Gui: the existing control container of duilib is actually just a GUI, which has been well done. The difference is that the rendering thread is used to process these graphic units. It would be better to further abstract the point, line, and plane.
9. Renderer: it is best to abstract this part. one advantage is that the specific rendering modules such as GDI, GDI +, d3d, and OpenGL can be registered using plug-ins.
10. Time System: Do you need to understand this part.
11. log records
12. debugging: for example, memory leakage monitoring, recovery, and exception handling mechanisms
The above are purely personal ideas, because the game is more common in both logic processing and rendering processing. Program To be more complex, it is still unknown whether these ideas are effective in actual development. In addition, I strongly recommend a book on game development: <game Coding complete 3rd edition>. You are advised to read the English version directly. I have benefited a lot.