gpt4 book ai didi

rust - 如何在 bevy 中读取鼠标运动?

转载 作者:行者123 更新时间:2023-12-04 07:51:33 26 4
gpt4 key购买 nike

我想创建一个第一人称相机。
我已经研究了其他几个实现的源代码,比如
https://github.com/mcpar-land/bevy_fly_camera
https://github.com/sburris0/bevy_flycam
但是当我自己实现它时(主要是复制粘贴 tbh),当在 git 上使用最新的 bevy 版本时,它无法编译。
编译输出:

error[E0277]: `*mut (usize, PhantomData<MouseMotion>)` cannot be sent between threads safely
--> src/player_input.rs:151:13
|
151 | mut state: ResMut<State>,
| ^^^^^^^^^^^^^ `*mut (usize, PhantomData<MouseMotion>)` cannot be sent between threads safely
|
::: /home/luca/.cargo/git/checkouts/bevy-f7ffde730c324c74/89a41bc/crates/bevy_ecs/src/resource/resource_query.rs:66:26
|
66 | pub struct ResMut<'a, T: Resource> {
| -------- required by this bound in `bevy::prelude::ResMut`
|
= help: within `player_input::State<'_>`, the trait `Send` is not implemented for `*mut (usize, PhantomData<MouseMotion>)`
= note: required because it appears within the type `Local<'_, (usize, PhantomData<MouseMotion>)>`
= note: required because it appears within the type `bevy::prelude::EventReader<'_, MouseMotion>`
= note: required because it appears within the type `player_input::State<'_>`
= note: required because of the requirements on the impl of `Resource` for `player_input::State<'_>`

这是代码:
#[derive(Default)]
struct State<'a> {
mouse_motion_event_reader: EventReader<'a, MouseMotion>,
}

fn mouse_motion_system(
time: Res<Time>,

mut state: ResMut<State>, //<-- IMPORTANT LINE (Line 151)

mouse_motion_events: Res<Events<MouseMotion>>,
mut query: Query<(&mut FlyCamera, &mut Transform)>,
) {
//...
}
它只会在最新版本的 bevy 上引发此错误,而不会在 0.4.0 版上引发此错误。
我做错了什么还是应该在github上打开一个问题,因为这是引擎的错?
我该怎么做才能让它发挥作用?

最佳答案

你不应该有 EventReaderState在这里。也许您想跟踪状态中的最后一个光标位置?
由于事件 API 针对 Bevy 0.5 进行了简化,因此您只需要 EventReader作为系统参数; mouse_motion_events: Res<Events<MouseMotion>>,现在已过时,可以替换为 mut mouse_motion_events: EventReader<MouseMotion> .

关于rust - 如何在 bevy 中读取鼠标运动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66946558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com