作業メモ:bevy 0.11 → 0.12
Bevy 0.11.3から0.12.0へマイグレーションするお題はこれ↓
Bevy Asset V2関連ののエラー。
bevy::asset::AssetServer::load
の引数に要求されるライフタイムが変わったらしい。
error[E0521]: borrowed data escapes outside of function
--> src\public\misc.rs:152:24
|
145 | ( message: &[ MessageSect ],
| -------
| |
| `message` is a reference that is only valid in the function body
| has type `&[(&'1 str, &'1 str, f32, bevy::prelude::Color)]`
...
152 | { font : asset_svr.load( *file ),
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| `message` escapes the function body here
| argument requires that `'1` must outlive `'static`
For more information about this error, try `rustc --explain E0521`.
上記引数に関わる参照がある場合、そのライフタイムを'static
へ変える必要がある。
pub type MessageSect<'a> =
( &'a str, //表示文字列
&'a str, //フォントのAssets
f32, //フォントのサイズ
Color, //フォントの色
);
pub type MessageSect =
( &'static str, //表示文字列
&'static str, //フォントのAssets
f32, //フォントのサイズ
Color, //フォントの色
);
bevy::asset::AssetServer::load_untyped
の戻り値がHandle<LoadedUntypedAsset>
へ変わった。
※0.11の時の戻り値であるbevy::asset::HandleUntyped
はもう存在しない。
struct LoadedAssets { handles: Vec<HandleUntyped> }
use bevy::asset::LoadedUntypedAsset;
struct LoadedAssets { handles: Vec<Handle<LoadedUntypedAsset>> }
<補足>
load_untyped
とLoadedUntypedAsset
の情報がマイグレガイドのNon-blocking load_untyped using a wrapper assetの項に載っている。
bevy::asset::AssetServer::get_load_state
の戻り値がLoadState
からOption<LoadState>
へ変わった。
match asset_svr.get_load_state( handle )
{ LoadState::Loaded => (), //ロード完了
LoadState::Failed => (), //ロード失敗
_ => (),
}
match asset_svr.get_load_state( handle )
{ Some ( LoadState::Loaded ) => (), //ロード完了
Some ( LoadState::Failed ) => (), //ロード失敗
_ => (),
}
bevy::asset::AssetServer::get_handle_path
の代わりにbevy::asset::Handle::path
を使う。
※意識する必要はないが、untypedの場合はbevy::asset::UntypedHandle::path
になる
if let Some ( asset_path ) = asset_svr.get_handle_path( handle )
{ /*略*/ }
if let Some ( asset_path ) = handle.path()
{ /*略*/ }
<補足>
ニュースレターのBetter Asset Handlesの項に情報が載っている。
ワーニング対応。
warning: use of deprecated method `bevy::prelude::EventReader::<'w, 's, E>::iter`: use `.read()` instead.
bevy::ecs::event::EventReader::iter
の使用が非推奨としてワーニング表示されるようになった。
代わりにbevy::ecs::event::EventReader::read
を使う。
if evt_clear.iter().next().is_some() { return }
if evt_clear.read().next().is_some() { return }
<補足>
マイグレガイドのRefactor EventReader::iter to readの項に情報がある。
おや? もう修正が終わってしまった。
このゲームAsset V2の恩恵受けるほどasset使い込んでないし、2Dゲームだから3D関係のホットな改善・拡張の影響受けないからだな。