@@ -10,6 +10,19 @@ use std::any::TypeId;
1010
1111use hecs:: { Archetype , ColumnBatchBuilder , ColumnBatchType , Component , TypeIdMap , TypeInfo , World } ;
1212
13+ #[ derive( Clone , Debug , PartialEq ) ]
14+ struct Count ( i32 ) ;
15+ impl Component for Count { }
16+
17+ #[ derive( Clone , Debug , PartialEq ) ]
18+ struct Name ( String ) ;
19+ impl Component for Name { }
20+
21+ /// A component that will not be registered with the [`WorldCloner`]
22+ #[ derive( Clone , Debug , PartialEq ) ]
23+ struct Marker ( u8 ) ;
24+ impl Component for Marker { }
25+
1326struct ComponentCloneMetadata {
1427 type_info : TypeInfo ,
1528 insert_into_batch_func : & ' static dyn Fn ( & Archetype , & mut ColumnBatchBuilder ) ,
@@ -75,21 +88,15 @@ impl WorldCloner {
7588}
7689
7790pub fn main ( ) {
78- let int0 = 0 ;
79- let int1 = 1 ;
80- let str0 = "Ada" . to_owned ( ) ;
81- let str1 = "Bob" . to_owned ( ) ;
82- let str2 = "Cal" . to_owned ( ) ;
83-
8491 let mut world0 = World :: new ( ) ;
85- let entity0 = world0. spawn ( ( int0 , str0 ) ) ;
86- let entity1 = world0. spawn ( ( int1 , str1 ) ) ;
87- let entity2 = world0. spawn ( ( str2 , ) ) ;
88- let entity3 = world0. spawn ( ( 0u8 , ) ) ; // unregistered component
92+ let entity0 = world0. spawn ( ( Count ( 0 ) , Name ( "Ada" . to_owned ( ) ) ) ) ;
93+ let entity1 = world0. spawn ( ( Count ( 1 ) , Name ( "Bob" . to_owned ( ) ) ) ) ;
94+ let entity2 = world0. spawn ( ( Name ( "Cal" . to_owned ( ) ) , ) ) ;
95+ let entity3 = world0. spawn ( ( Marker ( 0 ) , ) ) ; // unregistered component
8996
9097 let mut cloner = WorldCloner :: default ( ) ;
91- cloner. register :: < i32 > ( ) ;
92- cloner. register :: < String > ( ) ;
98+ cloner. register :: < Count > ( ) ;
99+ cloner. register :: < Name > ( ) ;
93100
94101 let world1 = cloner. clone_world ( & world0) ;
95102
@@ -104,18 +111,18 @@ pub fn main() {
104111 world0
105112 . entity( entity3)
106113 . expect( "w0 entity3 should exist" )
107- . has:: <u8 >( ) ,
108- "original world entity has u8 component"
114+ . has:: <Marker >( ) ,
115+ "original world entity has Marker component"
109116 ) ;
110117 assert ! (
111118 !world1
112119 . entity( entity3)
113120 . expect( "w1 entity3 should exist" )
114- . has:: <u8 >( ) ,
115- "cloned world entity does not have u8 component because it was not registered"
121+ . has:: <Marker >( ) ,
122+ "cloned world entity does not have Marker component because it was not registered"
116123 ) ;
117124
118- type AllRegisteredComponentsQuery = ( & ' static i32 , & ' static String ) ;
125+ type AllRegisteredComponentsQuery = ( & ' static Count , & ' static Name ) ;
119126 for entity in [ entity0, entity1] {
120127 let w0_e = world0. entity ( entity) . expect ( "w0 entity should exist" ) ;
121128 let w1_e = world1. entity ( entity) . expect ( "w1 entity should exist" ) ;
@@ -128,7 +135,7 @@ pub fn main() {
128135 ) ;
129136 }
130137
131- type SomeRegisteredComponentsQuery = ( & ' static String , ) ;
138+ type SomeRegisteredComponentsQuery = ( & ' static Name , ) ;
132139 let w0_e = world0. entity ( entity2) . expect ( "w0 entity2 should exist" ) ;
133140 let w1_e = world1. entity ( entity2) . expect ( "w1 entity2 should exist" ) ;
134141 assert ! ( w0_e. satisfies:: <SomeRegisteredComponentsQuery >( ) ) ;
0 commit comments