|
1 |
| -use std::ops::{Deref, DerefMut}; |
2 |
| - |
3 | 1 | use crate::MainWorld;
|
4 | 2 | use bevy_ecs::{
|
5 | 3 | prelude::*,
|
6 | 4 | system::{
|
7 |
| - ReadOnlySystemParamFetch, SystemParam, SystemParamFetch, SystemParamItem, SystemParamState, |
8 |
| - SystemState, |
| 5 | + ReadOnlySystemParamFetch, SystemParam, SystemParamFetch, SystemParamItem, SystemState, |
9 | 6 | },
|
10 | 7 | };
|
11 | 8 |
|
12 |
| -pub struct ExtractFromMainWorld<'s, P: SystemParam + 'static>(SystemParamItem<'s, 's, P>) |
13 |
| -where |
14 |
| - P::Fetch: ReadOnlySystemParamFetch; |
15 |
| - |
16 |
| -impl<'s, P: SystemParam + 'static> Deref for ExtractFromMainWorld<'s, P> |
17 |
| -where |
18 |
| - P::Fetch: ReadOnlySystemParamFetch, |
19 |
| -{ |
20 |
| - type Target = SystemParamItem<'s, 's, P>; |
21 |
| - |
22 |
| - fn deref(&self) -> &Self::Target { |
23 |
| - &self.0 |
24 |
| - } |
25 |
| -} |
26 |
| - |
27 |
| -impl<'s, P: SystemParam + 'static> DerefMut for ExtractFromMainWorld<'s, P> |
28 |
| -where |
29 |
| - P::Fetch: ReadOnlySystemParamFetch, |
30 |
| -{ |
31 |
| - fn deref_mut(&mut self) -> &mut Self::Target { |
32 |
| - &mut self.0 |
33 |
| - } |
34 |
| -} |
| 9 | +pub struct MainWorldState<P: SystemParam>(SystemState<P>); |
35 | 10 |
|
36 |
| -impl<'s, P: SystemParam + 'static> ExtractFromMainWorld<'s, P> |
37 |
| -where |
38 |
| - P::Fetch: ReadOnlySystemParamFetch, |
39 |
| -{ |
40 |
| - pub fn into_inner(self) -> SystemParamItem<'s, 's, P> { |
41 |
| - self.0 |
| 11 | +impl<P: SystemParam> FromWorld for MainWorldState<P> { |
| 12 | + fn from_world(world: &mut World) -> Self { |
| 13 | + Self(SystemState::new(&mut world.resource_mut::<MainWorld>().0)) |
42 | 14 | }
|
43 | 15 | }
|
44 | 16 |
|
45 |
| -impl<'s, P: SystemParam + 'static> SystemParam for ExtractFromMainWorld<'s, P> |
| 17 | +#[derive(SystemParam)] |
| 18 | +pub struct Extract<'w, 's, P: SystemParam + 'static> |
46 | 19 | where
|
47 | 20 | P::Fetch: ReadOnlySystemParamFetch,
|
48 | 21 | {
|
49 |
| - type Fetch = ExtractFromMainWorldState<P>; |
| 22 | + state: Local< |
| 23 | + 's, |
| 24 | + MainWorldState<<<P as SystemParam>::Fetch as SystemParamFetch<'static, 'static>>::Item>, |
| 25 | + >, |
| 26 | + world: Res<'w, World>, |
50 | 27 | }
|
51 | 28 |
|
52 |
| -unsafe impl<P: SystemParam + 'static> SystemParamState for ExtractFromMainWorldState<P> { |
53 |
| - fn init(world: &mut World, system_meta: &mut bevy_ecs::system::SystemMeta) -> Self { |
54 |
| - Self { |
55 |
| - world: SystemParamState::init(world, system_meta), |
56 |
| - state: SystemState::new(&mut (*world.resource_mut::<MainWorld>())), |
57 |
| - } |
58 |
| - } |
59 |
| -} |
60 |
| - |
61 |
| -pub struct ExtractFromMainWorldState<P: SystemParam + 'static> { |
62 |
| - world: <Res<'static, MainWorld> as SystemParam>::Fetch, |
63 |
| - state: SystemState<P>, |
64 |
| -} |
65 |
| - |
66 |
| -impl<'world, 'state, P: SystemParam + 'static> SystemParamFetch<'world, 'state> |
67 |
| - for ExtractFromMainWorldState<P> |
| 29 | +impl<'w, 's, P: SystemParam + 'static> Extract<'w, 's, P> |
68 | 30 | where
|
69 | 31 | P::Fetch: ReadOnlySystemParamFetch,
|
70 | 32 | {
|
71 |
| - type Item = ExtractFromMainWorld<'state, P>; |
72 |
| - |
73 |
| - unsafe fn get_param( |
74 |
| - state: &'state mut Self, |
75 |
| - system_meta: &bevy_ecs::system::SystemMeta, |
76 |
| - world: &'world World, |
77 |
| - change_tick: u32, |
78 |
| - ) -> Self::Item { |
79 |
| - let world = SystemParamFetch::get_param(&mut state.world, system_meta, world, change_tick); |
80 |
| - ExtractFromMainWorld(state.state.get(&world)) |
| 33 | + pub fn value(&mut self) -> SystemParamItem<'_, '_, P> { |
| 34 | + self.state.0.get(&self.world) |
81 | 35 | }
|
82 | 36 | }
|
0 commit comments