banner
Olimi

Olimi

SCUT 小菜鸡
github
bilibili

Introduction to 3D Game Engine Course 6 - Event Handling and Scripting Language

Preface#

The content of this column is from the online course "Fundamentals of 3D Game Engine Architecture and Design" on XuetangX. I have converted it into a text and image version (I personally prefer text tutorials, which are much faster to read) for easy reference.
Original course link: Fundamentals of 3D Game Engine Architecture and Design.

Event Handling and Scripting Language#

Overview of Event Handling and Scripting Language#

Event Handling#

Event-driven game interaction control:
Insert Image Description Here
The event handling method of a game engine affects the design and style of the entire engine architecture. Event handling is a fundamental design of the engine architecture and one of the two main content areas of the engine (the other being scene management and rendering). The game engine loop architecture includes three styles:

  • Callback-driven interaction control framework

Event handling is done through callback functions, as shown below:

Insert Image Description Here
Insert Image Description Here
Event handling mechanism framework:
Insert Image Description Here

  • Event-driven interaction control framework
    Insert Image Description Here
  • Window message pump interaction control framework
    Insert Image Description Here

In the event handling mechanisms mentioned above, the callback-driven approach is mainly suitable for window or external input device events, using an event handling mechanism; the event-driven approach is mainly suitable for frame time updates in scene rendering, and can be implemented using callback functions; the window message pump approach is mainly suitable for integrating interaction control in existing GUI frameworks.

Design concept in event handling, Observer Pattern:
Insert Image Description Here
Applying the observer pattern reduces the coupling between events and event handling methods during definition.

Scripting Language#

A programming language created to shorten the traditional process of writing-compiling-linking-running, it is also an extension language of compiled languages. It has a simple syntax, is closely related to applications, and can directly call application functions, generally lacking generality. Its features include: interpretability, lightweightness, support for rapid iteration, and ease of use. Common scripting languages include: Python, Lua, JavaScript, etc.

The relationship between game engines and scripting:
Insert Image Description Here
The combination methods include:
Insert Image Description Here
Interface definition of scripting languages:
Insert Image Description Here

Event Handling Implementation Example#

OGRE Event Handling#

Events in OGRE:
Insert Image Description Here
So the core of OGRE event handling is handling rendering events, the main class being FrameListener as follows:
Insert Image Description Here
Further discussion on frameRenderingQueued frame rendering queued event:
Insert Image Description Here
OGRE's rendering event listener related classes:
Insert Image Description Here
External events in OGRE are implemented in the OGREBites module; the ApplicationContext class of the OGREBites module is a subclass of the FrameListener class, providing a convenient event listening interface; the InputListener structure of the OGREBites module defines callback functions for keyboard, mouse, touch, and other input events; other external classes in the OGREBites module include: window event class, GUI control event class, etc.

ApplicationContext class and its relevant parts in event handling:
Insert Image Description Here

Panda3D Event Handling#

Concept of tasks in Panda3D event handling mechanism:
Insert Image Description Here
Core class diagram of Panda3D events:
Insert Image Description Here
Relationship between task classes:
Insert Image Description Here
AsyncTask class interface:
Insert Image Description Here

Event handling mechanism and related classes:
Insert Image Description Here
Detailed analysis of event handlers:
Insert Image Description Here
Example of event object definition and handling:
Insert Image Description Here

GUI classes:
Insert Image Description Here

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.