我正在尝试在 Rust 中设置一个简单的计时器,该计时器以特定频率返回 true。
#[derive(Clone, Debug)]
pub struct IntervalTimer {
pub period: Duration,
pub delta: Instant,
}
impl IntervalTimer {
pub fn new(period: Duration) -> Self {
let delta = Instant::now();
Self { period, delta }
}
/// Returns true if the interval between calls has exceeded the period
pub fn ready(&mut self) -> bool {
if self.delta.elapsed() < self.period {
false
} else {
self.delta = self.delta + self.period;
true
}
}
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这std::time::Instant在rayon任务中使用时似乎一直很恐慌(如果重要的话,在 Legion …
我正在从Shing Lyu 的“Practical Rust Projects”中学习 Rust 。我现在正在尝试按照第 4 章中的步骤构建游戏。我正在 Ubuntu 18.04 LTS 上工作。
安装 Rust 和 Amethyst 命令行后,我通过amethyst new cat_volleyball. 下一步是使用cargo run --features=vulkan
. 当我这样做时,我收到下面的错误提示。你有关于如何解决这个问题的建议吗?
error[E0433]: failed to resolve: could not find `__rt` in `quote`
--> /home/alberto/.cargo/registry/src/github.com-1ecc6299db9ec823/err-derive-0.1.6/src/lib.rs:145:63
|
145 | fn display_body(s: &synstructure::Structure) -> Option<quote::__rt::TokenStream> {
| ^^^^ could not find `__rt` in `quote`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `err-derive`. …Run Code Online (Sandbox Code Playgroud) 当我在 Ubuntu 18.04 上尝试使用amethystcargo build的“hello world”时,收到有关缺少 lxbcb 库的错误。我不确定这个错误试图告诉我什么或如何修复它。似乎我缺少库、和,但我似乎找不到它们。-lxcb-render-lxcb-shap-lxcb-xfixes
紫水晶的hello world代码
extern crate amethyst;
use amethyst::{
prelude::*,
renderer::{DisplayConfig, DrawFlat, Pipeline, PosNormTex, RenderBundle, Stage, VirtualKeyCode},
utils::application_root_dir,
input::is_key_down,
};
struct Example;
impl SimpleState for Example {}
fn main() -> amethyst::Result<()> {
amethyst::start_logger(Default::default());
let path = format!(
"{}/resources/display_config.ron",
application_root_dir()
);
let config = DisplayConfig::load(&path);
let pipe = Pipeline::build().with_stage(
Stage::with_backbuffer()
.clear_target([0.00196, 0.23726, 0.21765, 1.0], 1.0)
.with_pass(DrawFlat::<PosNormTex>::new()),
);
let game_data =
GameDataBuilder::default().with_bundle(RenderBundle::new(pipe, Some(config)))?;
let mut game = Application::new("./", Example, game_data)?; …Run Code Online (Sandbox Code Playgroud)