1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
extern "C" {
fn application_get_frame() -> i32;
fn application_get_buffer_size() -> i64;
fn application_get_visual_size() -> i64;
fn application_get_device_pixel_ratio() -> f32;
fn application_get_platform() -> i64;
fn application_get_version() -> i64;
fn application_get_deps() -> i64;
fn application_get_delta_time() -> f64;
fn application_get_elapsed_time() -> f64;
fn application_get_total_time() -> f64;
fn application_get_running_time() -> f64;
fn application_get_rand() -> i64;
fn application_get_max_fps() -> i32;
fn application_is_debugging() -> i32;
fn application_set_locale(val: i64);
fn application_get_locale() -> i64;
fn application_set_theme_color(val: i32);
fn application_get_theme_color() -> i32;
fn application_set_seed(val: i32);
fn application_get_seed() -> i32;
fn application_set_target_fps(val: i32);
fn application_get_target_fps() -> i32;
fn application_set_win_size(val: i64);
fn application_get_win_size() -> i64;
fn application_set_win_position(val: i64);
fn application_get_win_position() -> i64;
fn application_set_fps_limited(val: i32);
fn application_is_fps_limited() -> i32;
fn application_set_idled(val: i32);
fn application_is_idled() -> i32;
fn application_set_full_screen(val: i32);
fn application_is_full_screen() -> i32;
fn application_set_always_on_top(val: i32);
fn application_is_always_on_top() -> i32;
fn application_shutdown();
}
/// A struct representing an application.
pub struct App { }
impl App {
/// Gets the current passed frame number.
pub fn get_frame() -> i32 {
return unsafe { application_get_frame() };
}
/// Gets the size of the main frame buffer texture used for rendering.
pub fn get_buffer_size() -> crate::dora::Size {
return unsafe { crate::dora::Size::from(application_get_buffer_size()) };
}
/// Gets the logic visual size of the screen.
/// The visual size only changes when application window size changes.
/// And it won't be affacted by the view buffer scaling factor.
pub fn get_visual_size() -> crate::dora::Size {
return unsafe { crate::dora::Size::from(application_get_visual_size()) };
}
/// Gets the ratio of the pixel density displayed by the device
/// Can be calculated as the size of the rendering buffer divided by the size of the application window.
pub fn get_device_pixel_ratio() -> f32 {
return unsafe { application_get_device_pixel_ratio() };
}
/// Gets the platform the game engine is running on.
pub fn get_platform() -> String {
return unsafe { crate::dora::to_string(application_get_platform()) };
}
/// Gets the version string of the game engine.
/// Should be in format of "v0.0.0".
pub fn get_version() -> String {
return unsafe { crate::dora::to_string(application_get_version()) };
}
/// Gets the dependencies of the game engine.
pub fn get_deps() -> String {
return unsafe { crate::dora::to_string(application_get_deps()) };
}
/// Gets the time in seconds since the last frame update.
pub fn get_delta_time() -> f64 {
return unsafe { application_get_delta_time() };
}
/// Gets the elapsed time since current frame was started, in seconds.
pub fn get_elapsed_time() -> f64 {
return unsafe { application_get_elapsed_time() };
}
/// Gets the total time the game engine has been running until last frame ended, in seconds.
/// Should be a contant number when invoked in a same frame for multiple times.
pub fn get_total_time() -> f64 {
return unsafe { application_get_total_time() };
}
/// Gets the total time the game engine has been running until this field being accessed, in seconds.
/// Should be a increasing number when invoked in a same frame for multiple times.
pub fn get_running_time() -> f64 {
return unsafe { application_get_running_time() };
}
/// Gets a random number generated by a random number engine based on Mersenne Twister algorithm.
/// So that the random number generated by a same seed should be consistent on every platform.
pub fn get_rand() -> i64 {
return unsafe { application_get_rand() };
}
/// Gets the maximum valid frames per second the game engine is allowed to run at.
/// The max FPS is being inferred by the device screen max refresh rate.
pub fn get_max_fps() -> i32 {
return unsafe { application_get_max_fps() };
}
/// Gets whether the game engine is running in debug mode.
pub fn is_debugging() -> bool {
return unsafe { application_is_debugging() != 0 };
}
/// Sets the system locale string, in format like: `zh-Hans`, `en`.
pub fn set_locale(val: &str) {
unsafe { application_set_locale(crate::dora::from_string(val)) };
}
/// Gets the system locale string, in format like: `zh-Hans`, `en`.
pub fn get_locale() -> String {
return unsafe { crate::dora::to_string(application_get_locale()) };
}
/// Sets the theme color for Dora SSR.
pub fn set_theme_color(val: &crate::dora::Color) {
unsafe { application_set_theme_color(val.to_argb() as i32) };
}
/// Gets the theme color for Dora SSR.
pub fn get_theme_color() -> crate::dora::Color {
return unsafe { crate::dora::Color::from(application_get_theme_color()) };
}
/// Sets the random number seed.
pub fn set_seed(val: i32) {
unsafe { application_set_seed(val) };
}
/// Gets the random number seed.
pub fn get_seed() -> i32 {
return unsafe { application_get_seed() };
}
/// Sets the target frames per second the game engine is supposed to run at.
/// Only works when `fpsLimited` is set to true.
pub fn set_target_fps(val: i32) {
unsafe { application_set_target_fps(val) };
}
/// Gets the target frames per second the game engine is supposed to run at.
/// Only works when `fpsLimited` is set to true.
pub fn get_target_fps() -> i32 {
return unsafe { application_get_target_fps() };
}
/// Sets the application window size.
/// May differ from visual size due to the different DPIs of display devices.
/// It is not available to set this property on platform Android and iOS.
pub fn set_win_size(val: &crate::dora::Size) {
unsafe { application_set_win_size(val.into_i64()) };
}
/// Gets the application window size.
/// May differ from visual size due to the different DPIs of display devices.
/// It is not available to set this property on platform Android and iOS.
pub fn get_win_size() -> crate::dora::Size {
return unsafe { crate::dora::Size::from(application_get_win_size()) };
}
/// Sets the application window position.
/// It is not available to set this property on platform Android and iOS.
pub fn set_win_position(val: &crate::dora::Vec2) {
unsafe { application_set_win_position(val.into_i64()) };
}
/// Gets the application window position.
/// It is not available to set this property on platform Android and iOS.
pub fn get_win_position() -> crate::dora::Vec2 {
return unsafe { crate::dora::Vec2::from(application_get_win_position()) };
}
/// Sets whether the game engine is limiting the frames per second.
/// Set `fpsLimited` to true, will make engine run in a busy loop to track the precise frame time to switch to the next frame. And this behavior can lead to 100% CPU usage. This is usually common practice on Windows PCs for better CPU usage occupation. But it also results in extra heat and power consumption.
pub fn set_fps_limited(val: bool) {
unsafe { application_set_fps_limited(if val { 1 } else { 0 }) };
}
/// Gets whether the game engine is limiting the frames per second.
/// Set `fpsLimited` to true, will make engine run in a busy loop to track the precise frame time to switch to the next frame. And this behavior can lead to 100% CPU usage. This is usually common practice on Windows PCs for better CPU usage occupation. But it also results in extra heat and power consumption.
pub fn is_fps_limited() -> bool {
return unsafe { application_is_fps_limited() != 0 };
}
/// Sets whether the game engine is currently idled.
/// Set `idled` to true, will make game logic thread use a sleep time and going idled for next frame to come. Due to the imprecision in sleep time. This idled state may cause game engine over slept for a few frames to lost.
/// `idled` state can reduce some CPU usage.
pub fn set_idled(val: bool) {
unsafe { application_set_idled(if val { 1 } else { 0 }) };
}
/// Gets whether the game engine is currently idled.
/// Set `idled` to true, will make game logic thread use a sleep time and going idled for next frame to come. Due to the imprecision in sleep time. This idled state may cause game engine over slept for a few frames to lost.
/// `idled` state can reduce some CPU usage.
pub fn is_idled() -> bool {
return unsafe { application_is_idled() != 0 };
}
/// Sets whether the game engine is running in full screen mode.
/// It is not available to set this property on platform Android and iOS.
pub fn set_full_screen(val: bool) {
unsafe { application_set_full_screen(if val { 1 } else { 0 }) };
}
/// Gets whether the game engine is running in full screen mode.
/// It is not available to set this property on platform Android and iOS.
pub fn is_full_screen() -> bool {
return unsafe { application_is_full_screen() != 0 };
}
/// Sets whether the game engine window is always on top. Default is true.
/// It is not available to set this property on platform Android and iOS.
pub fn set_always_on_top(val: bool) {
unsafe { application_set_always_on_top(if val { 1 } else { 0 }) };
}
/// Gets whether the game engine window is always on top. Default is true.
/// It is not available to set this property on platform Android and iOS.
pub fn is_always_on_top() -> bool {
return unsafe { application_is_always_on_top() != 0 };
}
/// Shuts down the game engine.
/// It is not working and acts as a dummy function for platform Android and iOS to follow the specification of how mobile platform applications should operate.
pub fn shutdown() {
unsafe { application_shutdown(); }
}
}