bevy 1.0.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 (93) hide show
  1. checksums.yaml +7 -0
  2. data/Cargo.lock +4279 -0
  3. data/Cargo.toml +36 -0
  4. data/README.md +226 -0
  5. data/crates/bevy/Cargo.toml +52 -0
  6. data/crates/bevy/src/app.rs +43 -0
  7. data/crates/bevy/src/component.rs +111 -0
  8. data/crates/bevy/src/entity.rs +30 -0
  9. data/crates/bevy/src/error.rs +32 -0
  10. data/crates/bevy/src/event.rs +190 -0
  11. data/crates/bevy/src/input_bridge.rs +300 -0
  12. data/crates/bevy/src/lib.rs +42 -0
  13. data/crates/bevy/src/mesh_renderer.rs +328 -0
  14. data/crates/bevy/src/query.rs +53 -0
  15. data/crates/bevy/src/render_app.rs +689 -0
  16. data/crates/bevy/src/resource.rs +28 -0
  17. data/crates/bevy/src/schedule.rs +186 -0
  18. data/crates/bevy/src/sprite_renderer.rs +355 -0
  19. data/crates/bevy/src/system.rs +44 -0
  20. data/crates/bevy/src/text_renderer.rs +258 -0
  21. data/crates/bevy/src/types/color.rs +114 -0
  22. data/crates/bevy/src/types/dynamic.rs +131 -0
  23. data/crates/bevy/src/types/math.rs +260 -0
  24. data/crates/bevy/src/types/mod.rs +9 -0
  25. data/crates/bevy/src/types/transform.rs +166 -0
  26. data/crates/bevy/src/world.rs +163 -0
  27. data/crates/bevy_ruby_render/Cargo.toml +22 -0
  28. data/crates/bevy_ruby_render/src/asset.rs +360 -0
  29. data/crates/bevy_ruby_render/src/audio.rs +511 -0
  30. data/crates/bevy_ruby_render/src/camera.rs +365 -0
  31. data/crates/bevy_ruby_render/src/gamepad.rs +398 -0
  32. data/crates/bevy_ruby_render/src/lib.rs +26 -0
  33. data/crates/bevy_ruby_render/src/material.rs +310 -0
  34. data/crates/bevy_ruby_render/src/mesh.rs +491 -0
  35. data/crates/bevy_ruby_render/src/sprite.rs +289 -0
  36. data/ext/bevy/Cargo.toml +20 -0
  37. data/ext/bevy/extconf.rb +6 -0
  38. data/ext/bevy/src/conversions.rs +137 -0
  39. data/ext/bevy/src/lib.rs +29 -0
  40. data/ext/bevy/src/ruby_app.rs +65 -0
  41. data/ext/bevy/src/ruby_color.rs +149 -0
  42. data/ext/bevy/src/ruby_component.rs +189 -0
  43. data/ext/bevy/src/ruby_entity.rs +33 -0
  44. data/ext/bevy/src/ruby_math.rs +384 -0
  45. data/ext/bevy/src/ruby_query.rs +64 -0
  46. data/ext/bevy/src/ruby_render_app.rs +779 -0
  47. data/ext/bevy/src/ruby_system.rs +122 -0
  48. data/ext/bevy/src/ruby_world.rs +107 -0
  49. data/lib/bevy/animation.rb +597 -0
  50. data/lib/bevy/app.rb +675 -0
  51. data/lib/bevy/asset.rb +613 -0
  52. data/lib/bevy/audio.rb +545 -0
  53. data/lib/bevy/audio_effects.rb +224 -0
  54. data/lib/bevy/camera.rb +412 -0
  55. data/lib/bevy/component.rb +91 -0
  56. data/lib/bevy/diagnostics.rb +227 -0
  57. data/lib/bevy/ecs_advanced.rb +296 -0
  58. data/lib/bevy/event.rb +199 -0
  59. data/lib/bevy/gizmos.rb +158 -0
  60. data/lib/bevy/gltf.rb +227 -0
  61. data/lib/bevy/hierarchy.rb +444 -0
  62. data/lib/bevy/input.rb +514 -0
  63. data/lib/bevy/lighting.rb +369 -0
  64. data/lib/bevy/material.rb +248 -0
  65. data/lib/bevy/mesh.rb +257 -0
  66. data/lib/bevy/navigation.rb +344 -0
  67. data/lib/bevy/networking.rb +335 -0
  68. data/lib/bevy/particle.rb +337 -0
  69. data/lib/bevy/physics.rb +396 -0
  70. data/lib/bevy/plugins/default_plugins.rb +34 -0
  71. data/lib/bevy/plugins/input_plugin.rb +49 -0
  72. data/lib/bevy/reflect.rb +361 -0
  73. data/lib/bevy/render_graph.rb +210 -0
  74. data/lib/bevy/resource.rb +185 -0
  75. data/lib/bevy/scene.rb +254 -0
  76. data/lib/bevy/shader.rb +319 -0
  77. data/lib/bevy/shape.rb +195 -0
  78. data/lib/bevy/skeletal.rb +248 -0
  79. data/lib/bevy/sprite.rb +152 -0
  80. data/lib/bevy/sprite_sheet.rb +444 -0
  81. data/lib/bevy/state.rb +277 -0
  82. data/lib/bevy/system.rb +206 -0
  83. data/lib/bevy/text.rb +99 -0
  84. data/lib/bevy/text_advanced.rb +455 -0
  85. data/lib/bevy/timer.rb +147 -0
  86. data/lib/bevy/transform.rb +158 -0
  87. data/lib/bevy/ui.rb +454 -0
  88. data/lib/bevy/ui_advanced.rb +568 -0
  89. data/lib/bevy/version.rb +5 -0
  90. data/lib/bevy/visibility.rb +250 -0
  91. data/lib/bevy/window.rb +302 -0
  92. data/lib/bevy.rb +390 -0
  93. metadata +150 -0
@@ -0,0 +1,328 @@
1
+ use std::collections::HashMap;
2
+
3
+ #[derive(Debug, Clone, Copy, PartialEq)]
4
+ pub enum ShapeType {
5
+ Rectangle,
6
+ Circle,
7
+ RegularPolygon,
8
+ Line,
9
+ Ellipse,
10
+ }
11
+
12
+ #[derive(Debug, Clone)]
13
+ pub struct MeshData {
14
+ pub shape_type: ShapeType,
15
+ pub color_r: f32,
16
+ pub color_g: f32,
17
+ pub color_b: f32,
18
+ pub color_a: f32,
19
+ pub width: f32,
20
+ pub height: f32,
21
+ pub radius: f32,
22
+ pub sides: u32,
23
+ pub line_start_x: f32,
24
+ pub line_start_y: f32,
25
+ pub line_end_x: f32,
26
+ pub line_end_y: f32,
27
+ pub thickness: f32,
28
+ pub fill: bool,
29
+ }
30
+
31
+ impl Default for MeshData {
32
+ fn default() -> Self {
33
+ Self {
34
+ shape_type: ShapeType::Rectangle,
35
+ color_r: 1.0,
36
+ color_g: 1.0,
37
+ color_b: 1.0,
38
+ color_a: 1.0,
39
+ width: 100.0,
40
+ height: 100.0,
41
+ radius: 50.0,
42
+ sides: 6,
43
+ line_start_x: 0.0,
44
+ line_start_y: 0.0,
45
+ line_end_x: 100.0,
46
+ line_end_y: 0.0,
47
+ thickness: 2.0,
48
+ fill: true,
49
+ }
50
+ }
51
+ }
52
+
53
+ #[derive(Debug, Clone)]
54
+ pub struct MeshTransformData {
55
+ pub translation_x: f32,
56
+ pub translation_y: f32,
57
+ pub translation_z: f32,
58
+ pub rotation_x: f32,
59
+ pub rotation_y: f32,
60
+ pub rotation_z: f32,
61
+ pub rotation_w: f32,
62
+ pub scale_x: f32,
63
+ pub scale_y: f32,
64
+ pub scale_z: f32,
65
+ }
66
+
67
+ impl Default for MeshTransformData {
68
+ fn default() -> Self {
69
+ Self {
70
+ translation_x: 0.0,
71
+ translation_y: 0.0,
72
+ translation_z: 0.0,
73
+ rotation_x: 0.0,
74
+ rotation_y: 0.0,
75
+ rotation_z: 0.0,
76
+ rotation_w: 1.0,
77
+ scale_x: 1.0,
78
+ scale_y: 1.0,
79
+ scale_z: 1.0,
80
+ }
81
+ }
82
+ }
83
+
84
+ #[derive(Debug, Clone)]
85
+ pub enum MeshOperation {
86
+ Sync {
87
+ ruby_entity_id: u64,
88
+ mesh_data: MeshData,
89
+ transform_data: MeshTransformData,
90
+ },
91
+ Remove {
92
+ ruby_entity_id: u64,
93
+ },
94
+ Clear,
95
+ }
96
+
97
+ struct EntityData {
98
+ #[cfg(feature = "rendering")]
99
+ bevy_entity: bevy_ecs::entity::Entity,
100
+ #[cfg(not(feature = "rendering"))]
101
+ _phantom: (),
102
+ }
103
+
104
+ pub struct MeshSync {
105
+ entity_map: HashMap<u64, EntityData>,
106
+ pub pending_operations: Vec<MeshOperation>,
107
+ }
108
+
109
+ impl MeshSync {
110
+ pub fn new() -> Self {
111
+ Self {
112
+ entity_map: HashMap::new(),
113
+ pending_operations: Vec::new(),
114
+ }
115
+ }
116
+
117
+ pub fn sync_mesh_standalone(
118
+ &mut self,
119
+ ruby_entity_id: u64,
120
+ mesh_data: &MeshData,
121
+ transform_data: &MeshTransformData,
122
+ ) {
123
+ self.pending_operations.push(MeshOperation::Sync {
124
+ ruby_entity_id,
125
+ mesh_data: mesh_data.clone(),
126
+ transform_data: transform_data.clone(),
127
+ });
128
+ }
129
+
130
+ pub fn remove_mesh_standalone(&mut self, ruby_entity_id: u64) {
131
+ self.pending_operations.push(MeshOperation::Remove { ruby_entity_id });
132
+ }
133
+
134
+ pub fn clear_standalone(&mut self) {
135
+ self.pending_operations.push(MeshOperation::Clear);
136
+ }
137
+
138
+ #[cfg(feature = "rendering")]
139
+ pub fn apply_pending(&mut self, world: &mut bevy_ecs::world::World) {
140
+ use bevy_color::Color;
141
+ use bevy_math::Vec3;
142
+ use bevy_prototype_lyon::prelude::*;
143
+ use bevy_render::view::Visibility;
144
+ use bevy_transform::components::Transform;
145
+
146
+ let ops: Vec<_> = self.pending_operations.drain(..).collect();
147
+ for op in ops {
148
+ match op {
149
+ MeshOperation::Sync {
150
+ ruby_entity_id,
151
+ mesh_data,
152
+ transform_data,
153
+ } => {
154
+ let color = Color::srgba(
155
+ mesh_data.color_r,
156
+ mesh_data.color_g,
157
+ mesh_data.color_b,
158
+ mesh_data.color_a,
159
+ );
160
+
161
+ let transform = Transform {
162
+ translation: Vec3::new(
163
+ transform_data.translation_x,
164
+ transform_data.translation_y,
165
+ transform_data.translation_z,
166
+ ),
167
+ rotation: bevy_math::Quat::from_xyzw(
168
+ transform_data.rotation_x,
169
+ transform_data.rotation_y,
170
+ transform_data.rotation_z,
171
+ transform_data.rotation_w,
172
+ ),
173
+ scale: Vec3::new(
174
+ transform_data.scale_x,
175
+ transform_data.scale_y,
176
+ transform_data.scale_z,
177
+ ),
178
+ };
179
+
180
+ if let Some(entity_data) = self.entity_map.get(&ruby_entity_id) {
181
+ let bevy_entity = entity_data.bevy_entity;
182
+ if let Some(mut t) = world.get_mut::<Transform>(bevy_entity) {
183
+ *t = transform;
184
+ }
185
+ if let Some(mut fill) = world.get_mut::<Fill>(bevy_entity) {
186
+ fill.color = color;
187
+ }
188
+ if let Some(mut stroke) = world.get_mut::<Stroke>(bevy_entity) {
189
+ stroke.color = color;
190
+ }
191
+ } else {
192
+ let transparent = Color::srgba(0.0, 0.0, 0.0, 0.0);
193
+ let draw_mode = if mesh_data.fill {
194
+ (
195
+ Fill::color(color),
196
+ Stroke::new(color, mesh_data.thickness),
197
+ )
198
+ } else {
199
+ (
200
+ Fill::color(transparent),
201
+ Stroke::new(color, mesh_data.thickness),
202
+ )
203
+ };
204
+
205
+ let bevy_entity = match mesh_data.shape_type {
206
+ ShapeType::Rectangle => {
207
+ let shape = shapes::Rectangle {
208
+ extents: bevy_math::Vec2::new(mesh_data.width, mesh_data.height),
209
+ origin: RectangleOrigin::Center,
210
+ ..Default::default()
211
+ };
212
+ world.spawn((
213
+ ShapeBundle {
214
+ path: GeometryBuilder::build_as(&shape),
215
+ transform,
216
+ visibility: Visibility::Visible,
217
+ ..Default::default()
218
+ },
219
+ draw_mode.0,
220
+ draw_mode.1,
221
+ )).id()
222
+ }
223
+ ShapeType::Circle => {
224
+ let shape = shapes::Circle {
225
+ radius: mesh_data.radius,
226
+ center: bevy_math::Vec2::ZERO,
227
+ };
228
+ world.spawn((
229
+ ShapeBundle {
230
+ path: GeometryBuilder::build_as(&shape),
231
+ transform,
232
+ visibility: Visibility::Visible,
233
+ ..Default::default()
234
+ },
235
+ draw_mode.0,
236
+ draw_mode.1,
237
+ )).id()
238
+ }
239
+ ShapeType::RegularPolygon => {
240
+ let shape = shapes::RegularPolygon {
241
+ sides: mesh_data.sides as usize,
242
+ feature: RegularPolygonFeature::Radius(mesh_data.radius),
243
+ ..Default::default()
244
+ };
245
+ world.spawn((
246
+ ShapeBundle {
247
+ path: GeometryBuilder::build_as(&shape),
248
+ transform,
249
+ visibility: Visibility::Visible,
250
+ ..Default::default()
251
+ },
252
+ draw_mode.0,
253
+ draw_mode.1,
254
+ )).id()
255
+ }
256
+ ShapeType::Line => {
257
+ let shape = shapes::Line(
258
+ bevy_math::Vec2::new(mesh_data.line_start_x, mesh_data.line_start_y),
259
+ bevy_math::Vec2::new(mesh_data.line_end_x, mesh_data.line_end_y),
260
+ );
261
+ world.spawn((
262
+ ShapeBundle {
263
+ path: GeometryBuilder::build_as(&shape),
264
+ transform,
265
+ visibility: Visibility::Visible,
266
+ ..Default::default()
267
+ },
268
+ Stroke::new(color, mesh_data.thickness),
269
+ )).id()
270
+ }
271
+ ShapeType::Ellipse => {
272
+ let shape = shapes::Ellipse {
273
+ radii: bevy_math::Vec2::new(mesh_data.width / 2.0, mesh_data.height / 2.0),
274
+ center: bevy_math::Vec2::ZERO,
275
+ };
276
+ world.spawn((
277
+ ShapeBundle {
278
+ path: GeometryBuilder::build_as(&shape),
279
+ transform,
280
+ visibility: Visibility::Visible,
281
+ ..Default::default()
282
+ },
283
+ draw_mode.0,
284
+ draw_mode.1,
285
+ )).id()
286
+ }
287
+ };
288
+
289
+ self.entity_map.insert(ruby_entity_id, EntityData { bevy_entity });
290
+ }
291
+ }
292
+ MeshOperation::Remove { ruby_entity_id } => {
293
+ if let Some(entity_data) = self.entity_map.remove(&ruby_entity_id) {
294
+ world.despawn(entity_data.bevy_entity);
295
+ }
296
+ }
297
+ MeshOperation::Clear => {
298
+ for (_, entity_data) in self.entity_map.drain() {
299
+ world.despawn(entity_data.bevy_entity);
300
+ }
301
+ }
302
+ }
303
+ }
304
+ }
305
+
306
+ #[cfg(not(feature = "rendering"))]
307
+ pub fn apply_pending(&mut self, _world: &mut ()) {
308
+ self.pending_operations.clear();
309
+ }
310
+
311
+ pub fn len(&self) -> usize {
312
+ self.entity_map.len()
313
+ }
314
+
315
+ pub fn is_empty(&self) -> bool {
316
+ self.entity_map.is_empty()
317
+ }
318
+
319
+ pub fn synced_entities(&self) -> Vec<u64> {
320
+ self.entity_map.keys().copied().collect()
321
+ }
322
+ }
323
+
324
+ impl Default for MeshSync {
325
+ fn default() -> Self {
326
+ Self::new()
327
+ }
328
+ }
@@ -0,0 +1,53 @@
1
+ use bevy_ecs::component::ComponentId;
2
+
3
+ #[derive(Debug, Clone)]
4
+ pub enum QueryFilter {
5
+ With(ComponentId),
6
+ Without(ComponentId),
7
+ Changed(ComponentId),
8
+ Added(ComponentId),
9
+ }
10
+
11
+ #[derive(Clone)]
12
+ pub struct QueryBuilder {
13
+ fetch: Vec<String>,
14
+ filters: Vec<QueryFilter>,
15
+ }
16
+
17
+ impl QueryBuilder {
18
+ pub fn new() -> Self {
19
+ Self {
20
+ fetch: Vec::new(),
21
+ filters: Vec::new(),
22
+ }
23
+ }
24
+
25
+ pub fn fetch(mut self, component_name: &str) -> Self {
26
+ self.fetch.push(component_name.to_string());
27
+ self
28
+ }
29
+
30
+ pub fn filter_with(mut self, component_id: ComponentId) -> Self {
31
+ self.filters.push(QueryFilter::With(component_id));
32
+ self
33
+ }
34
+
35
+ pub fn filter_without(mut self, component_id: ComponentId) -> Self {
36
+ self.filters.push(QueryFilter::Without(component_id));
37
+ self
38
+ }
39
+
40
+ pub fn fetch_components(&self) -> &[String] {
41
+ &self.fetch
42
+ }
43
+
44
+ pub fn filters(&self) -> &[QueryFilter] {
45
+ &self.filters
46
+ }
47
+ }
48
+
49
+ impl Default for QueryBuilder {
50
+ fn default() -> Self {
51
+ Self::new()
52
+ }
53
+ }