@@ -4,6 +4,8 @@ use crate::camera::Camera2D;
44
55pub use macroquad_macro:: CapabilityTrait ;
66
7+ mod arena;
8+
79#[ rustfmt:: skip]
810pub trait Node {
911 fn ready ( _node : RefMut < Self > ) where Self : Sized { }
@@ -12,10 +14,6 @@ pub trait Node {
1214 fn draw ( _node : RefMut < Self > ) where Self : Sized { }
1315}
1416
15- trait NodeTyped < T > {
16- fn self_node ( & self ) -> & T ;
17- }
18-
1917trait NodeAny : Any + Node {
2018 fn as_any ( & self ) -> & dyn Any ;
2119 fn as_any_mut ( & mut self ) -> & mut dyn Any ;
@@ -345,7 +343,7 @@ struct Scene {
345343 dense : Vec < Id > ,
346344 dense_ongoing : Vec < Result < Id , Id > > ,
347345 nodes : Vec < Option < Cell > > ,
348- arena : bumpalo :: Bump ,
346+ arena : arena :: Arena ,
349347 camera : [ Option < Camera2D > ; 4 ] ,
350348 camera_pos : crate :: Vec2 ,
351349
@@ -363,7 +361,7 @@ impl Scene {
363361 dense : vec ! [ ] ,
364362 dense_ongoing : vec ! [ ] ,
365363 nodes : Vec :: new ( ) ,
366- arena : bumpalo :: Bump :: new ( ) ,
364+ arena : arena :: Arena :: new ( ) ,
367365 free_nodes : Vec :: new ( ) ,
368366 camera : [ Some ( Camera2D :: default ( ) ) , None , None , None ] ,
369367 camera_pos : crate :: vec2 ( 0. , 0. ) ,
@@ -461,15 +459,22 @@ impl Scene {
461459 let trait_obj = & data as & dyn NodeAny ;
462460 let ( _, vtable) = unsafe { std:: mem:: transmute :: < _ , ( * mut ( ) , * mut ( ) ) > ( trait_obj) } ;
463461
464- let data = self . arena . alloc ( data) as * mut _ as * mut _ ;
465- let used = self . arena . alloc ( false ) as * mut _ as * mut _ ;
462+ let ptr = self . arena . alloc ( std:: mem:: size_of :: < T > ( ) ) as * mut _ as * mut T ;
463+ unsafe {
464+ std:: ptr:: write ( ptr, data) ;
465+ }
466+ let ptr = ptr as * mut ( ) ;
467+ let used = self . arena . alloc ( 1 ) as * mut _ as * mut bool ;
468+ unsafe {
469+ std:: ptr:: write ( used, false ) ;
470+ }
471+ let used = used as * mut _ as * mut bool ;
466472
467473 id = Id {
468474 id : self . nodes . len ( ) ,
469475 generation : 0 ,
470476 } ;
471- self . nodes
472- . push ( Some ( Cell :: new :: < T > ( id, data, vtable, used) ) ) ;
477+ self . nodes . push ( Some ( Cell :: new :: < T > ( id, ptr, vtable, used) ) ) ;
473478 }
474479
475480 self . dense . push ( id) ;
@@ -616,7 +621,7 @@ unsafe fn get_scene() -> &'static mut Scene {
616621}
617622
618623pub ( crate ) fn allocated_memory ( ) -> usize {
619- unsafe { get_scene ( ) } . arena . allocated_bytes ( )
624+ unsafe { get_scene ( ) . arena . offset ( ) }
620625}
621626
622627pub fn clear ( ) {
0 commit comments