User Script File Reference
This section contains reference information for the user script file. Below is all message response functions list. These functions will be executed by Scene Player when some event happen (e.g. user press a key or click mouse button). In User Script File, all script codes which outside these functions will be executed once when loading scene file.
Keyboard Input Messages:
| Function Name | Parameter | Return | Explain |
| OnKeyDown | number nChar | None |
The framework calls this member function when a nonsystem key is pressed. A nonsystem key is a keyboard key that is pressed when the ALT key is not pressed or a keyboard key that is pressed when the window has the input focus. Parameters nChar Example function OnKeyDown(nChar) |
| OnKeyUp | number nChar | None | The framework calls this member function when a
nonsystem key is released. A nonsystem key is a keyboard key that is
pressed when the ALT key is not pressed or a keyboard key that is pressed
when the window has the input focus.
Parameters nChar
|
| OnChar | number nChar | None | The framework calls this member function when a
keystroke translates to a nonsystem character. This function is called
before the OnKeyUp member
function and after the OnKeyDown
member function are called. OnChar contains the value of the
keyboard key being pressed or released.
Parameters nChar Example function OnChar(nChar) |
| OnKillFocus | None | None | The framework calls this member function immediately before losing the input focus. |
| OnSetFocus | None | None | The framework calls this member function after gaining the input focus. |
Mouse Input Messages:
| Function Name | Parameter | Return | Explain |
| OnMouseMove | number x, y | number | The framework calls this member function when
the mouse cursor moves.
Parameters x, y |
| OnMouseWheel | number delta | number | The framework calls this member function as a
user rotates the mouse wheel and encounters the wheel's next notch.
Parameters delta
|
| OnLButtonDown | number x, y | number | The framework calls this member function when
the user presses the left mouse button.
Parameters x, y
|
| OnLButtonUp | number x, y | number | The framework calls this member function when the user releases the left mouse button. |
| OnLButtonDblClk | number x, y | number | The framework calls this member function when the user double-clicks the left mouse button. |
| OnRButtonDown | number x, y | number | The framework calls this member function when the user presses the right mouse button. |
| OnRButtonUp | number x, y | number | The framework calls this member function when the user releases the right mouse button. |
| OnRButtonDblClk | number x, y | number | The framework calls this member function when the user double-clicks the right mouse button. |
| OnMButtonDown | number x, y | number | The framework calls this member function when the user presses the middle mouse button. |
| OnMButtonUp | number x, y | number | The framework calls this member function when the user releases the middle mouse button. |
| OnMButtonDblClk | number x, y | number | The framework calls this member function when the user double-clicks the middle mouse button. |
Remark:
All mouse input message functions returns a number.
If the return number is zero, the framework will continue process message.
If the return number is nonzero, the framework will give up farther process.
Window Messages:
| Function Name | Parameter | Return | Explain |
| OnActivate | number nActive, nMinimized |
None | The framework calls this member function
immediately both the window being activated and the window being
deactivated.
Parameters nActive nMinimized |
| OnSize | number type, cx, cy | None | This function is called after the window size has changed. |
Application Flow:
| Function Name | Parameter | Return | Explain |
| FrameMove | None | None | This function is called before rendering every frame picture. |
| Render2D | draw2d | None | This function is called after rendering scene. You can only draw 2D content in this function. |
| Render3D | draw3d | None | This function is called after rendering scene. You can only draw 3D content in this function. |
| OnRestoreDevice | None | None | This function is called after restoring device. see Remark 2. |
| UpdateUserInput | userinput | None | This function is called after system inputting. see Remark 3. |
Remark 1:
The calling sequence of these function is:
FrameMove
Scene
Rendering
Render3D
Render2D
Remark 2:
The D3D device and correlative objects will be restored when resizing
window, loading scene, etc. While restoring, all device dependent resources
(like textures, shader texts, etc) will be reloaded. So the OnRestoreDevice is
the right place to do some setting for those resources. For example, assume a
shader text include several techniques, when restoring it, the device will
active the first valid technique; but you can active special technique to override
device's choice.
Remark 3:
System collect all input device's events, then translate to input commands
which stored in the
userinput table. In the UpdateUserInput
function, you can custom your own inputting by modifying the
userinput table. The process flow of
inputting is:
Collect device events
Translate
to input commands
call
UpdateUserInput()
Update
world by input commands