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.
- checksums.yaml +7 -0
- data/Cargo.lock +4279 -0
- data/Cargo.toml +36 -0
- data/README.md +226 -0
- data/crates/bevy/Cargo.toml +52 -0
- data/crates/bevy/src/app.rs +43 -0
- data/crates/bevy/src/component.rs +111 -0
- data/crates/bevy/src/entity.rs +30 -0
- data/crates/bevy/src/error.rs +32 -0
- data/crates/bevy/src/event.rs +190 -0
- data/crates/bevy/src/input_bridge.rs +300 -0
- data/crates/bevy/src/lib.rs +42 -0
- data/crates/bevy/src/mesh_renderer.rs +328 -0
- data/crates/bevy/src/query.rs +53 -0
- data/crates/bevy/src/render_app.rs +689 -0
- data/crates/bevy/src/resource.rs +28 -0
- data/crates/bevy/src/schedule.rs +186 -0
- data/crates/bevy/src/sprite_renderer.rs +355 -0
- data/crates/bevy/src/system.rs +44 -0
- data/crates/bevy/src/text_renderer.rs +258 -0
- data/crates/bevy/src/types/color.rs +114 -0
- data/crates/bevy/src/types/dynamic.rs +131 -0
- data/crates/bevy/src/types/math.rs +260 -0
- data/crates/bevy/src/types/mod.rs +9 -0
- data/crates/bevy/src/types/transform.rs +166 -0
- data/crates/bevy/src/world.rs +163 -0
- data/crates/bevy_ruby_render/Cargo.toml +22 -0
- data/crates/bevy_ruby_render/src/asset.rs +360 -0
- data/crates/bevy_ruby_render/src/audio.rs +511 -0
- data/crates/bevy_ruby_render/src/camera.rs +365 -0
- data/crates/bevy_ruby_render/src/gamepad.rs +398 -0
- data/crates/bevy_ruby_render/src/lib.rs +26 -0
- data/crates/bevy_ruby_render/src/material.rs +310 -0
- data/crates/bevy_ruby_render/src/mesh.rs +491 -0
- data/crates/bevy_ruby_render/src/sprite.rs +289 -0
- data/ext/bevy/Cargo.toml +20 -0
- data/ext/bevy/extconf.rb +6 -0
- data/ext/bevy/src/conversions.rs +137 -0
- data/ext/bevy/src/lib.rs +29 -0
- data/ext/bevy/src/ruby_app.rs +65 -0
- data/ext/bevy/src/ruby_color.rs +149 -0
- data/ext/bevy/src/ruby_component.rs +189 -0
- data/ext/bevy/src/ruby_entity.rs +33 -0
- data/ext/bevy/src/ruby_math.rs +384 -0
- data/ext/bevy/src/ruby_query.rs +64 -0
- data/ext/bevy/src/ruby_render_app.rs +779 -0
- data/ext/bevy/src/ruby_system.rs +122 -0
- data/ext/bevy/src/ruby_world.rs +107 -0
- data/lib/bevy/animation.rb +597 -0
- data/lib/bevy/app.rb +675 -0
- data/lib/bevy/asset.rb +613 -0
- data/lib/bevy/audio.rb +545 -0
- data/lib/bevy/audio_effects.rb +224 -0
- data/lib/bevy/camera.rb +412 -0
- data/lib/bevy/component.rb +91 -0
- data/lib/bevy/diagnostics.rb +227 -0
- data/lib/bevy/ecs_advanced.rb +296 -0
- data/lib/bevy/event.rb +199 -0
- data/lib/bevy/gizmos.rb +158 -0
- data/lib/bevy/gltf.rb +227 -0
- data/lib/bevy/hierarchy.rb +444 -0
- data/lib/bevy/input.rb +514 -0
- data/lib/bevy/lighting.rb +369 -0
- data/lib/bevy/material.rb +248 -0
- data/lib/bevy/mesh.rb +257 -0
- data/lib/bevy/navigation.rb +344 -0
- data/lib/bevy/networking.rb +335 -0
- data/lib/bevy/particle.rb +337 -0
- data/lib/bevy/physics.rb +396 -0
- data/lib/bevy/plugins/default_plugins.rb +34 -0
- data/lib/bevy/plugins/input_plugin.rb +49 -0
- data/lib/bevy/reflect.rb +361 -0
- data/lib/bevy/render_graph.rb +210 -0
- data/lib/bevy/resource.rb +185 -0
- data/lib/bevy/scene.rb +254 -0
- data/lib/bevy/shader.rb +319 -0
- data/lib/bevy/shape.rb +195 -0
- data/lib/bevy/skeletal.rb +248 -0
- data/lib/bevy/sprite.rb +152 -0
- data/lib/bevy/sprite_sheet.rb +444 -0
- data/lib/bevy/state.rb +277 -0
- data/lib/bevy/system.rb +206 -0
- data/lib/bevy/text.rb +99 -0
- data/lib/bevy/text_advanced.rb +455 -0
- data/lib/bevy/timer.rb +147 -0
- data/lib/bevy/transform.rb +158 -0
- data/lib/bevy/ui.rb +454 -0
- data/lib/bevy/ui_advanced.rb +568 -0
- data/lib/bevy/version.rb +5 -0
- data/lib/bevy/visibility.rb +250 -0
- data/lib/bevy/window.rb +302 -0
- data/lib/bevy.rb +390 -0
- metadata +150 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
use bevy_ruby::system::{ScheduleLabel, SystemDescriptor};
|
|
2
|
+
use magnus::{function, method, prelude::*, Error, RModule, Ruby, Symbol};
|
|
3
|
+
use std::cell::RefCell;
|
|
4
|
+
|
|
5
|
+
#[magnus::wrap(class = "Bevy::SystemDescriptor", free_immediately, size)]
|
|
6
|
+
pub struct RubySystemDescriptor {
|
|
7
|
+
inner: RefCell<SystemDescriptor>,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
impl RubySystemDescriptor {
|
|
11
|
+
fn new(schedule: Symbol) -> Result<Self, Error> {
|
|
12
|
+
let ruby = Ruby::get().unwrap();
|
|
13
|
+
let schedule_str = schedule.name().map_err(|e| {
|
|
14
|
+
Error::new(ruby.exception_runtime_error(), format!("Invalid schedule symbol: {}", e))
|
|
15
|
+
})?;
|
|
16
|
+
let label = ScheduleLabel::from_str(&schedule_str).map_err(|e| {
|
|
17
|
+
Error::new(ruby.exception_runtime_error(), e.to_string())
|
|
18
|
+
})?;
|
|
19
|
+
Ok(Self {
|
|
20
|
+
inner: RefCell::new(SystemDescriptor::new(label)),
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fn with_param(&self, param_type: String) -> Self {
|
|
25
|
+
let inner = self.inner.borrow();
|
|
26
|
+
let new_descriptor = inner.clone().with_param(¶m_type);
|
|
27
|
+
Self {
|
|
28
|
+
inner: RefCell::new(new_descriptor),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fn schedule(&self) -> String {
|
|
33
|
+
let inner = self.inner.borrow();
|
|
34
|
+
match inner.schedule {
|
|
35
|
+
ScheduleLabel::Startup => "startup".to_string(),
|
|
36
|
+
ScheduleLabel::Update => "update".to_string(),
|
|
37
|
+
ScheduleLabel::FixedUpdate => "fixed_update".to_string(),
|
|
38
|
+
ScheduleLabel::PostUpdate => "post_update".to_string(),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn param_types(&self) -> Vec<String> {
|
|
43
|
+
self.inner.borrow().param_types.clone()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[allow(dead_code)]
|
|
47
|
+
pub fn inner(&self) -> SystemDescriptor {
|
|
48
|
+
self.inner.borrow().clone()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
unsafe impl Send for RubySystemDescriptor {}
|
|
53
|
+
|
|
54
|
+
#[magnus::wrap(class = "Bevy::ScheduleLabel", free_immediately, size)]
|
|
55
|
+
pub struct RubyScheduleLabel {
|
|
56
|
+
inner: ScheduleLabel,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
impl RubyScheduleLabel {
|
|
60
|
+
fn startup() -> Self {
|
|
61
|
+
Self { inner: ScheduleLabel::Startup }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn update() -> Self {
|
|
65
|
+
Self { inner: ScheduleLabel::Update }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fn fixed_update() -> Self {
|
|
69
|
+
Self { inner: ScheduleLabel::FixedUpdate }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn post_update() -> Self {
|
|
73
|
+
Self { inner: ScheduleLabel::PostUpdate }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn from_string(s: String) -> Result<Self, Error> {
|
|
77
|
+
let ruby = Ruby::get().unwrap();
|
|
78
|
+
let label = ScheduleLabel::from_str(&s).map_err(|e| {
|
|
79
|
+
Error::new(ruby.exception_runtime_error(), e.to_string())
|
|
80
|
+
})?;
|
|
81
|
+
Ok(Self { inner: label })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn to_s(&self) -> String {
|
|
85
|
+
match self.inner {
|
|
86
|
+
ScheduleLabel::Startup => "startup".to_string(),
|
|
87
|
+
ScheduleLabel::Update => "update".to_string(),
|
|
88
|
+
ScheduleLabel::FixedUpdate => "fixed_update".to_string(),
|
|
89
|
+
ScheduleLabel::PostUpdate => "post_update".to_string(),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn eq(&self, other: &RubyScheduleLabel) -> bool {
|
|
94
|
+
self.inner == other.inner
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[allow(dead_code)]
|
|
98
|
+
pub fn inner(&self) -> ScheduleLabel {
|
|
99
|
+
self.inner
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
unsafe impl Send for RubyScheduleLabel {}
|
|
104
|
+
|
|
105
|
+
pub fn define(ruby: &Ruby, module: &RModule) -> Result<(), Error> {
|
|
106
|
+
let descriptor_class = module.define_class("SystemDescriptor", ruby.class_object())?;
|
|
107
|
+
descriptor_class.define_singleton_method("new", function!(RubySystemDescriptor::new, 1))?;
|
|
108
|
+
descriptor_class.define_method("with_param", method!(RubySystemDescriptor::with_param, 1))?;
|
|
109
|
+
descriptor_class.define_method("schedule", method!(RubySystemDescriptor::schedule, 0))?;
|
|
110
|
+
descriptor_class.define_method("param_types", method!(RubySystemDescriptor::param_types, 0))?;
|
|
111
|
+
|
|
112
|
+
let label_class = module.define_class("ScheduleLabel", ruby.class_object())?;
|
|
113
|
+
label_class.define_singleton_method("startup", function!(RubyScheduleLabel::startup, 0))?;
|
|
114
|
+
label_class.define_singleton_method("update", function!(RubyScheduleLabel::update, 0))?;
|
|
115
|
+
label_class.define_singleton_method("fixed_update", function!(RubyScheduleLabel::fixed_update, 0))?;
|
|
116
|
+
label_class.define_singleton_method("post_update", function!(RubyScheduleLabel::post_update, 0))?;
|
|
117
|
+
label_class.define_singleton_method("from_string", function!(RubyScheduleLabel::from_string, 1))?;
|
|
118
|
+
label_class.define_method("to_s", method!(RubyScheduleLabel::to_s, 0))?;
|
|
119
|
+
label_class.define_method("==", method!(RubyScheduleLabel::eq, 1))?;
|
|
120
|
+
|
|
121
|
+
Ok(())
|
|
122
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
use bevy_ruby::WorldWrapper;
|
|
2
|
+
use magnus::{function, method, prelude::*, Error, RArray, RModule, Ruby};
|
|
3
|
+
use std::cell::RefCell;
|
|
4
|
+
|
|
5
|
+
use crate::ruby_component::RubyComponent;
|
|
6
|
+
use crate::ruby_entity::RubyEntity;
|
|
7
|
+
|
|
8
|
+
#[magnus::wrap(class = "Bevy::World", free_immediately, size)]
|
|
9
|
+
pub struct RubyWorld {
|
|
10
|
+
inner: RefCell<WorldWrapper>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
impl RubyWorld {
|
|
14
|
+
pub fn new() -> Self {
|
|
15
|
+
Self {
|
|
16
|
+
inner: RefCell::new(WorldWrapper::new()),
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub fn from_wrapper(wrapper: WorldWrapper) -> Self {
|
|
21
|
+
Self {
|
|
22
|
+
inner: RefCell::new(wrapper),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn spawn(&self) -> RubyEntity {
|
|
27
|
+
let entity = self.inner.borrow().spawn();
|
|
28
|
+
RubyEntity::new(entity)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn spawn_with(&self, components: RArray) -> Result<RubyEntity, Error> {
|
|
32
|
+
let mut component_list = Vec::new();
|
|
33
|
+
|
|
34
|
+
for item in components.into_iter() {
|
|
35
|
+
let component = <&RubyComponent>::try_convert(item)?;
|
|
36
|
+
component_list.push(component.inner());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let entity = self.inner.borrow().spawn_with_components(component_list);
|
|
40
|
+
Ok(RubyEntity::new(entity))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fn entity_exists(&self, entity: &RubyEntity) -> bool {
|
|
44
|
+
self.inner.borrow().entity_exists(entity.inner())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn despawn(&self, entity: &RubyEntity) -> Result<(), Error> {
|
|
48
|
+
self.inner
|
|
49
|
+
.borrow()
|
|
50
|
+
.despawn(entity.inner())
|
|
51
|
+
.map_err(|e| Error::new(Ruby::get().unwrap().exception_runtime_error(), e.to_string()))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fn insert(&self, entity: &RubyEntity, component: &RubyComponent) -> Result<(), Error> {
|
|
55
|
+
self.inner
|
|
56
|
+
.borrow()
|
|
57
|
+
.insert_component(entity.inner(), component.inner())
|
|
58
|
+
.map_err(|e| Error::new(Ruby::get().unwrap().exception_runtime_error(), e.to_string()))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn get(&self, entity: &RubyEntity, type_name: String) -> Result<RubyComponent, Error> {
|
|
62
|
+
self.inner
|
|
63
|
+
.borrow()
|
|
64
|
+
.get_component(entity.inner(), &type_name)
|
|
65
|
+
.map(RubyComponent::from_dynamic)
|
|
66
|
+
.map_err(|e| Error::new(Ruby::get().unwrap().exception_runtime_error(), e.to_string()))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fn has_component(&self, entity: &RubyEntity, type_name: String) -> bool {
|
|
70
|
+
self.inner.borrow().has_component(entity.inner(), &type_name)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fn query(&self, type_names: RArray) -> Result<RArray, Error> {
|
|
74
|
+
let ruby = Ruby::get().unwrap();
|
|
75
|
+
let mut names: Vec<String> = Vec::new();
|
|
76
|
+
|
|
77
|
+
for item in type_names.into_iter() {
|
|
78
|
+
names.push(String::try_convert(item)?);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let name_refs: Vec<&str> = names.iter().map(|s| s.as_str()).collect();
|
|
82
|
+
let entities = self.inner.borrow().query_entities_with(&name_refs);
|
|
83
|
+
|
|
84
|
+
let result = ruby.ary_new();
|
|
85
|
+
for entity in entities {
|
|
86
|
+
result.push(RubyEntity::new(entity))?;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Ok(result)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
unsafe impl Send for RubyWorld {}
|
|
94
|
+
|
|
95
|
+
pub fn define(ruby: &Ruby, module: &RModule) -> Result<(), Error> {
|
|
96
|
+
let class = module.define_class("World", ruby.class_object())?;
|
|
97
|
+
class.define_singleton_method("new", function!(RubyWorld::new, 0))?;
|
|
98
|
+
class.define_method("spawn", method!(RubyWorld::spawn, 0))?;
|
|
99
|
+
class.define_method("spawn_with", method!(RubyWorld::spawn_with, 1))?;
|
|
100
|
+
class.define_method("entity_exists?", method!(RubyWorld::entity_exists, 1))?;
|
|
101
|
+
class.define_method("despawn_native", method!(RubyWorld::despawn, 1))?;
|
|
102
|
+
class.define_method("insert", method!(RubyWorld::insert, 2))?;
|
|
103
|
+
class.define_method("get", method!(RubyWorld::get, 2))?;
|
|
104
|
+
class.define_method("has_component?", method!(RubyWorld::has_component, 2))?;
|
|
105
|
+
class.define_method("query", method!(RubyWorld::query, 1))?;
|
|
106
|
+
Ok(())
|
|
107
|
+
}
|