@@ -4,6 +4,8 @@ use crate::camera::Camera2D;
4
4
5
5
pub use macroquad_macro:: CapabilityTrait ;
6
6
7
+ mod arena;
8
+
7
9
#[ rustfmt:: skip]
8
10
pub trait Node {
9
11
fn ready ( _node : RefMut < Self > ) where Self : Sized { }
@@ -12,10 +14,6 @@ pub trait Node {
12
14
fn draw ( _node : RefMut < Self > ) where Self : Sized { }
13
15
}
14
16
15
- trait NodeTyped < T > {
16
- fn self_node ( & self ) -> & T ;
17
- }
18
-
19
17
trait NodeAny : Any + Node {
20
18
fn as_any ( & self ) -> & dyn Any ;
21
19
fn as_any_mut ( & mut self ) -> & mut dyn Any ;
@@ -345,7 +343,7 @@ struct Scene {
345
343
dense : Vec < Id > ,
346
344
dense_ongoing : Vec < Result < Id , Id > > ,
347
345
nodes : Vec < Option < Cell > > ,
348
- arena : bumpalo :: Bump ,
346
+ arena : arena :: Arena ,
349
347
camera : [ Option < Camera2D > ; 4 ] ,
350
348
camera_pos : crate :: Vec2 ,
351
349
@@ -363,7 +361,7 @@ impl Scene {
363
361
dense : vec ! [ ] ,
364
362
dense_ongoing : vec ! [ ] ,
365
363
nodes : Vec :: new ( ) ,
366
- arena : bumpalo :: Bump :: new ( ) ,
364
+ arena : arena :: Arena :: new ( ) ,
367
365
free_nodes : Vec :: new ( ) ,
368
366
camera : [ Some ( Camera2D :: default ( ) ) , None , None , None ] ,
369
367
camera_pos : crate :: vec2 ( 0. , 0. ) ,
@@ -461,15 +459,22 @@ impl Scene {
461
459
let trait_obj = & data as & dyn NodeAny ;
462
460
let ( _, vtable) = unsafe { std:: mem:: transmute :: < _ , ( * mut ( ) , * mut ( ) ) > ( trait_obj) } ;
463
461
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 ;
466
472
467
473
id = Id {
468
474
id : self . nodes . len ( ) ,
469
475
generation : 0 ,
470
476
} ;
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) ) ) ;
473
478
}
474
479
475
480
self . dense . push ( id) ;
@@ -616,7 +621,7 @@ unsafe fn get_scene() -> &'static mut Scene {
616
621
}
617
622
618
623
pub ( crate ) fn allocated_memory ( ) -> usize {
619
- unsafe { get_scene ( ) } . arena . allocated_bytes ( )
624
+ unsafe { get_scene ( ) . arena . offset ( ) }
620
625
}
621
626
622
627
pub fn clear ( ) {
0 commit comments