@bornengine/engine 0.4.16 → 0.5.0

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.
Files changed (62) hide show
  1. package/README.md +24 -14
  2. package/native/android/Cargo.lock +577 -28
  3. package/native/android/Cargo.toml +2 -0
  4. package/native/android/src/lib.rs +39 -3
  5. package/native/ios/Cargo.lock +573 -24
  6. package/native/ios/Cargo.toml +2 -0
  7. package/native/ios/src/lib.rs +72 -9
  8. package/native/ios/src/text_input.rs +48 -0
  9. package/native/linux/Cargo.lock +623 -35
  10. package/native/linux/Cargo.toml +3 -0
  11. package/native/macos/Cargo.lock +630 -35
  12. package/native/macos/Cargo.toml +3 -0
  13. package/native/shared/Cargo.lock +430 -27
  14. package/native/shared/Cargo.toml +5 -0
  15. package/native/shared/build.rs +41 -1
  16. package/native/shared/src/engine.rs +54 -2
  17. package/native/shared/src/ffi.rs +54 -1
  18. package/native/shared/src/ffi_core/mod.rs +2 -0
  19. package/native/shared/src/ffi_core/ui.rs +182 -0
  20. package/native/shared/src/input.rs +317 -12
  21. package/native/shared/src/lib.rs +1 -0
  22. package/native/shared/src/renderer/mod.rs +47 -201
  23. package/native/shared/src/renderer/texture_store.rs +5 -0
  24. package/native/shared/src/renderer/ui_pass.rs +742 -0
  25. package/native/shared/src/textures.rs +2 -0
  26. package/native/shared/src/ui/commands.rs +213 -0
  27. package/native/shared/src/ui/egui.rs +1282 -0
  28. package/native/shared/src/ui/imgui.rs +1056 -0
  29. package/native/shared/src/ui/input.rs +173 -0
  30. package/native/shared/src/ui/mod.rs +252 -0
  31. package/native/shared/src/ui/responses.rs +61 -0
  32. package/native/tvos/Cargo.lock +576 -27
  33. package/native/tvos/Cargo.toml +2 -0
  34. package/native/visionos/Cargo.lock +571 -22
  35. package/native/visionos/Cargo.toml +2 -0
  36. package/native/watchos/src/ffi_stubs.rs +27 -0
  37. package/native/web/Cargo.lock +346 -11
  38. package/native/web/Cargo.toml +6 -0
  39. package/native/web/bloom_glue.js +84 -11
  40. package/native/web/build.sh +150 -34
  41. package/native/web/src/lib.rs +2 -0
  42. package/native/web/src/ui_ffi.rs +148 -0
  43. package/native/windows/Cargo.lock +638 -38
  44. package/native/windows/Cargo.toml +3 -0
  45. package/native/windows/src/lib.rs +50 -1
  46. package/native/windows/src/windows_text.rs +69 -0
  47. package/package.json +91 -2
  48. package/src/debug-ui/index.ts +4 -0
  49. package/src/debug-ui/types.ts +1 -0
  50. package/src/game/adapters/audio-source-component.ts +67 -0
  51. package/src/game/adapters/rigid-body-component.ts +69 -0
  52. package/src/game/adapters/scene-node-component.ts +49 -0
  53. package/src/game/game-component.ts +89 -0
  54. package/src/game/game-object.ts +338 -0
  55. package/src/game/game-scene.ts +303 -0
  56. package/src/game/index.ts +7 -0
  57. package/src/game/transform.ts +315 -0
  58. package/src/index.ts +27 -0
  59. package/src/ui/api.ts +216 -0
  60. package/src/ui/index.ts +5 -0
  61. package/src/ui/opcodes.ts +66 -0
  62. 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
+ }