@bornengine/engine 0.4.16 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -14
- package/native/android/Cargo.lock +577 -28
- package/native/android/Cargo.toml +2 -0
- package/native/android/src/lib.rs +39 -3
- package/native/ios/Cargo.lock +573 -24
- package/native/ios/Cargo.toml +2 -0
- package/native/ios/src/lib.rs +72 -9
- package/native/ios/src/text_input.rs +48 -0
- package/native/linux/Cargo.lock +623 -35
- package/native/linux/Cargo.toml +3 -0
- package/native/macos/Cargo.lock +630 -35
- package/native/macos/Cargo.toml +3 -0
- package/native/shared/Cargo.lock +430 -27
- package/native/shared/Cargo.toml +5 -0
- package/native/shared/build.rs +41 -1
- package/native/shared/src/engine.rs +54 -2
- package/native/shared/src/ffi.rs +54 -1
- package/native/shared/src/ffi_core/mod.rs +2 -0
- package/native/shared/src/ffi_core/ui.rs +182 -0
- package/native/shared/src/input.rs +317 -12
- package/native/shared/src/lib.rs +1 -0
- package/native/shared/src/renderer/mod.rs +47 -201
- package/native/shared/src/renderer/texture_store.rs +5 -0
- package/native/shared/src/renderer/ui_pass.rs +742 -0
- package/native/shared/src/textures.rs +2 -0
- package/native/shared/src/ui/commands.rs +213 -0
- package/native/shared/src/ui/egui.rs +1282 -0
- package/native/shared/src/ui/imgui.rs +1056 -0
- package/native/shared/src/ui/input.rs +173 -0
- package/native/shared/src/ui/mod.rs +252 -0
- package/native/shared/src/ui/responses.rs +61 -0
- package/native/tvos/Cargo.lock +576 -27
- package/native/tvos/Cargo.toml +2 -0
- package/native/visionos/Cargo.lock +571 -22
- package/native/visionos/Cargo.toml +2 -0
- package/native/watchos/src/ffi_stubs.rs +27 -0
- package/native/web/Cargo.lock +346 -11
- package/native/web/Cargo.toml +6 -0
- package/native/web/bloom_glue.js +84 -11
- package/native/web/build.sh +150 -34
- package/native/web/src/lib.rs +2 -0
- package/native/web/src/ui_ffi.rs +148 -0
- package/native/windows/Cargo.lock +638 -38
- package/native/windows/Cargo.toml +3 -0
- package/native/windows/src/lib.rs +50 -1
- package/native/windows/src/windows_text.rs +69 -0
- package/package.json +91 -2
- package/src/debug-ui/index.ts +4 -0
- package/src/debug-ui/types.ts +1 -0
- package/src/game/adapters/audio-source-component.ts +67 -0
- package/src/game/adapters/rigid-body-component.ts +69 -0
- package/src/game/adapters/scene-node-component.ts +49 -0
- package/src/game/game-component.ts +89 -0
- package/src/game/game-object.ts +338 -0
- package/src/game/game-scene.ts +303 -0
- package/src/game/index.ts +7 -0
- package/src/game/transform.ts +315 -0
- package/src/index.ts +27 -0
- package/src/ui/api.ts +240 -0
- package/src/ui/index.ts +5 -0
- package/src/ui/opcodes.ts +66 -0
- package/src/ui/types.ts +82 -0
|
@@ -102,6 +102,8 @@ impl TextureManager {
|
|
|
102
102
|
|
|
103
103
|
pub fn unload_texture(&mut self, handle: f64, renderer: &mut Renderer) {
|
|
104
104
|
if let Some(tex) = self.textures.free(handle) {
|
|
105
|
+
renderer.unload_egui_texture(handle as u64);
|
|
106
|
+
renderer.unload_imgui_texture(handle as u64);
|
|
105
107
|
renderer.unload_texture(tex.bind_group_idx);
|
|
106
108
|
}
|
|
107
109
|
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
use std::convert::TryFrom;
|
|
2
|
+
|
|
3
|
+
use super::UiBackend;
|
|
4
|
+
|
|
5
|
+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
6
|
+
#[repr(u32)]
|
|
7
|
+
pub enum UiOpcode {
|
|
8
|
+
BeginWindow = 1,
|
|
9
|
+
EndWindow = 2,
|
|
10
|
+
BeginPanel = 3,
|
|
11
|
+
EndPanel = 4,
|
|
12
|
+
BeginHorizontal = 5,
|
|
13
|
+
EndHorizontal = 6,
|
|
14
|
+
BeginVertical = 7,
|
|
15
|
+
EndVertical = 8,
|
|
16
|
+
SetWindowPosition = 9,
|
|
17
|
+
SetWindowSize = 10,
|
|
18
|
+
Spacing = 11,
|
|
19
|
+
Separator = 12,
|
|
20
|
+
Label = 13,
|
|
21
|
+
Link = 14,
|
|
22
|
+
Button = 15,
|
|
23
|
+
Checkbox = 16,
|
|
24
|
+
RadioButton = 17,
|
|
25
|
+
SliderFloat = 18,
|
|
26
|
+
SliderInt = 19,
|
|
27
|
+
DragFloat = 20,
|
|
28
|
+
TextEdit = 21,
|
|
29
|
+
Combo = 22,
|
|
30
|
+
Selectable = 23,
|
|
31
|
+
CollapsingHeader = 24,
|
|
32
|
+
BeginScrollArea = 25,
|
|
33
|
+
EndScrollArea = 26,
|
|
34
|
+
BeginTabBar = 27,
|
|
35
|
+
EndTabBar = 28,
|
|
36
|
+
BeginTabItem = 29,
|
|
37
|
+
EndTabItem = 30,
|
|
38
|
+
ProgressBar = 31,
|
|
39
|
+
Image = 32,
|
|
40
|
+
PaintLine = 33,
|
|
41
|
+
PaintRect = 34,
|
|
42
|
+
PaintCircle = 35,
|
|
43
|
+
PaintText = 36,
|
|
44
|
+
PaintPolyline = 37,
|
|
45
|
+
PaintPolygon = 38,
|
|
46
|
+
SetStyle = 39,
|
|
47
|
+
LoadFont = 40,
|
|
48
|
+
RegisterTexture = 41,
|
|
49
|
+
BeginMenuBar = 42,
|
|
50
|
+
EndMenuBar = 43,
|
|
51
|
+
BeginMenu = 44,
|
|
52
|
+
EndMenu = 45,
|
|
53
|
+
MenuItem = 46,
|
|
54
|
+
TreeNode = 47,
|
|
55
|
+
TreePop = 48,
|
|
56
|
+
BeginTable = 49,
|
|
57
|
+
EndTable = 50,
|
|
58
|
+
TableNextRow = 51,
|
|
59
|
+
TableNextColumn = 52,
|
|
60
|
+
PlotLines = 53,
|
|
61
|
+
DemoWindow = 54,
|
|
62
|
+
MetricsWindow = 55,
|
|
63
|
+
EndCombo = 56,
|
|
64
|
+
EndCollapsingHeader = 57,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
impl TryFrom<u32> for UiOpcode {
|
|
68
|
+
type Error = ();
|
|
69
|
+
|
|
70
|
+
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
71
|
+
Ok(match value {
|
|
72
|
+
1 => Self::BeginWindow,
|
|
73
|
+
2 => Self::EndWindow,
|
|
74
|
+
3 => Self::BeginPanel,
|
|
75
|
+
4 => Self::EndPanel,
|
|
76
|
+
5 => Self::BeginHorizontal,
|
|
77
|
+
6 => Self::EndHorizontal,
|
|
78
|
+
7 => Self::BeginVertical,
|
|
79
|
+
8 => Self::EndVertical,
|
|
80
|
+
9 => Self::SetWindowPosition,
|
|
81
|
+
10 => Self::SetWindowSize,
|
|
82
|
+
11 => Self::Spacing,
|
|
83
|
+
12 => Self::Separator,
|
|
84
|
+
13 => Self::Label,
|
|
85
|
+
14 => Self::Link,
|
|
86
|
+
15 => Self::Button,
|
|
87
|
+
16 => Self::Checkbox,
|
|
88
|
+
17 => Self::RadioButton,
|
|
89
|
+
18 => Self::SliderFloat,
|
|
90
|
+
19 => Self::SliderInt,
|
|
91
|
+
20 => Self::DragFloat,
|
|
92
|
+
21 => Self::TextEdit,
|
|
93
|
+
22 => Self::Combo,
|
|
94
|
+
23 => Self::Selectable,
|
|
95
|
+
24 => Self::CollapsingHeader,
|
|
96
|
+
25 => Self::BeginScrollArea,
|
|
97
|
+
26 => Self::EndScrollArea,
|
|
98
|
+
27 => Self::BeginTabBar,
|
|
99
|
+
28 => Self::EndTabBar,
|
|
100
|
+
29 => Self::BeginTabItem,
|
|
101
|
+
30 => Self::EndTabItem,
|
|
102
|
+
31 => Self::ProgressBar,
|
|
103
|
+
32 => Self::Image,
|
|
104
|
+
33 => Self::PaintLine,
|
|
105
|
+
34 => Self::PaintRect,
|
|
106
|
+
35 => Self::PaintCircle,
|
|
107
|
+
36 => Self::PaintText,
|
|
108
|
+
37 => Self::PaintPolyline,
|
|
109
|
+
38 => Self::PaintPolygon,
|
|
110
|
+
39 => Self::SetStyle,
|
|
111
|
+
40 => Self::LoadFont,
|
|
112
|
+
41 => Self::RegisterTexture,
|
|
113
|
+
42 => Self::BeginMenuBar,
|
|
114
|
+
43 => Self::EndMenuBar,
|
|
115
|
+
44 => Self::BeginMenu,
|
|
116
|
+
45 => Self::EndMenu,
|
|
117
|
+
46 => Self::MenuItem,
|
|
118
|
+
47 => Self::TreeNode,
|
|
119
|
+
48 => Self::TreePop,
|
|
120
|
+
49 => Self::BeginTable,
|
|
121
|
+
50 => Self::EndTable,
|
|
122
|
+
51 => Self::TableNextRow,
|
|
123
|
+
52 => Self::TableNextColumn,
|
|
124
|
+
53 => Self::PlotLines,
|
|
125
|
+
54 => Self::DemoWindow,
|
|
126
|
+
55 => Self::MetricsWindow,
|
|
127
|
+
56 => Self::EndCombo,
|
|
128
|
+
57 => Self::EndCollapsingHeader,
|
|
129
|
+
_ => return Err(()),
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
impl UiOpcode {
|
|
135
|
+
pub fn from_abi(value: f64) -> Option<Self> {
|
|
136
|
+
if !value.is_finite() || value < 0.0 || value.fract() != 0.0 || value > u32::MAX as f64 {
|
|
137
|
+
return None;
|
|
138
|
+
}
|
|
139
|
+
Self::try_from(value as u32).ok()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
144
|
+
pub struct UiCommand {
|
|
145
|
+
pub backend: UiBackend,
|
|
146
|
+
pub opcode: UiOpcode,
|
|
147
|
+
pub id: u32,
|
|
148
|
+
pub args: [f64; 4],
|
|
149
|
+
pub text: String,
|
|
150
|
+
pub scratch: Vec<f64>,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
impl UiCommand {
|
|
154
|
+
pub fn new(
|
|
155
|
+
backend: UiBackend,
|
|
156
|
+
opcode: UiOpcode,
|
|
157
|
+
id: u32,
|
|
158
|
+
args: [f64; 4],
|
|
159
|
+
text: impl Into<String>,
|
|
160
|
+
) -> Self {
|
|
161
|
+
Self {
|
|
162
|
+
backend,
|
|
163
|
+
opcode,
|
|
164
|
+
id,
|
|
165
|
+
args,
|
|
166
|
+
text: text.into(),
|
|
167
|
+
scratch: Vec::new(),
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
pub fn with_scratch(mut self, scratch: Vec<f64>) -> Self {
|
|
172
|
+
self.scratch = scratch;
|
|
173
|
+
self
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#[cfg(test)]
|
|
178
|
+
mod tests {
|
|
179
|
+
use crate::ui::{UiBackend, UiCommand, UiOpcode, UiSystem};
|
|
180
|
+
|
|
181
|
+
fn command(backend: UiBackend, opcode: UiOpcode, id: u32, text: &str) -> UiCommand {
|
|
182
|
+
UiCommand::new(backend, opcode, id, [0.0; 4], text)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#[test]
|
|
186
|
+
fn command_queue_preserves_order_per_backend() {
|
|
187
|
+
let mut ui = UiSystem::default();
|
|
188
|
+
assert!(ui.queue_command(command(UiBackend::Egui, UiOpcode::Button, 7, "Continue")));
|
|
189
|
+
assert!(ui.queue_command(command(
|
|
190
|
+
UiBackend::DearImGui,
|
|
191
|
+
UiOpcode::Button,
|
|
192
|
+
8,
|
|
193
|
+
"Inspect"
|
|
194
|
+
)));
|
|
195
|
+
assert!(ui.queue_command(command(UiBackend::Egui, UiOpcode::Label, 9, "Ready")));
|
|
196
|
+
|
|
197
|
+
let egui = ui.take_commands(UiBackend::Egui);
|
|
198
|
+
assert_eq!(
|
|
199
|
+
egui.iter().map(|command| command.id).collect::<Vec<_>>(),
|
|
200
|
+
[7, 9]
|
|
201
|
+
);
|
|
202
|
+
let debug = ui.take_commands(UiBackend::DearImGui);
|
|
203
|
+
assert_eq!(
|
|
204
|
+
debug.iter().map(|command| command.id).collect::<Vec<_>>(),
|
|
205
|
+
[8]
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
#[test]
|
|
210
|
+
fn unknown_opcodes_are_rejected_without_panicking() {
|
|
211
|
+
assert!(UiOpcode::try_from(65_535).is_err());
|
|
212
|
+
}
|
|
213
|
+
}
|