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
use {
super::{
GameObject,
camera::Camera,
light::Light,
},
crate::{
registration::{
relation::{
Child, Parent,
ParentWrapper
},
named::Named,
id::ID,
},
scripting::{
Scriptable,
globals::{EngineGlobals, Global},
Script,
executor::Spawner,
},
graphics::{
Drawable,
draw_pass_manager::DrawPassManager,
lighting_pass_manager::LightingPassManager,
},
event::UserEvent,
components::triangle_mesh::TriangleMesh
},
std::{
any::Any,
mem,
sync::{Arc, RwLock}
},
feo_math::{
utils::space::Space,
rotation::quaternion::Quaternion,
linear_algebra::vector3::Vector3
},
winit::event::Event,
};
#[derive(Scriptable, Drawable, GameObject, Child, Parent, Named)]
pub struct Group {
pub id: ID,
pub name: String,
pub parent: ParentWrapper,
pub subspace: Space,
pub visible: bool,
pub script: Option<Box<Script<Self>>>,
pub children: Vec<Arc<RwLock<dyn GameObject>>>
}
impl std::fmt::Debug for Group {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Group")
.field("id", &self.id)
.field("name", &self.name)
.field("parent", &self.parent)
.field("subspace", &self.subspace)
.field("visible", &self.visible)
.field("script", &self.script)
.field("children", &self.children).finish()
}
}
impl Clone for Group {
fn clone(&self) -> Self {
let id = self.id.get_system().take();
Group{
id,
name: self.name.clone(),
parent: self.parent.clone(),
visible: self.visible,
subspace: self.subspace,
script: self.script.clone(),
children: self.children.clone().into_iter().map(|_child| {
todo!();
}).collect::<Vec<Arc<RwLock<dyn GameObject>>>>(),
}
}
}
impl PartialEq for Group{
fn eq(&self, other: &Self) -> bool {
self.get_id() == other.get_id()
}
}
impl Group {
#[allow(clippy::too_many_arguments)]
pub fn new(
name: Option<&str>,
parent: Option<Arc<RwLock<dyn GameObject>>>,
position: Option<Vector3<f32>>,
rotation: Option<Quaternion<f32>>,
scale_factor: Option<Vector3<f32>>,
visible: bool,
engine_globals: EngineGlobals,
script: Option<Box<Script<Self>>>) -> Arc<RwLock<Self>> {
let id = engine_globals.id_system.take();
Arc::new(RwLock::new(Group{
name: match name {
Some(name) => name.to_string(),
None => String::from("group_") + id.to_string().as_str()
},
id,
parent: match parent {
Some(game_object) => ParentWrapper::GameObject(game_object),
None => ParentWrapper::Scene(engine_globals.scene)
},
subspace: Space::new(position, rotation, scale_factor),
visible,
script,
children: Vec::new()
}))
}
}