5个不稳定版本
0.4.0 | 2020年10月17日 |
---|---|
0.3.1 |
|
0.2.2 | 2020年10月3日 |
0.2.1 | 2020年9月26日 |
0.1.2 |
|
#637 在 图形API
每月57次下载
6.5MB
3.5K SLoC
包含 (Windows DLL, 1.5MB) msvc/dll/64/SDL2.dll, (Windows DLL, 1.5MB) SDL2.dll, (Windows DLL, 1MB) msvc/dll/86/SDL2.dll, (静态库, 1MB) msvc/lib/64/SDL2test.lib, (静态库, 1MB) msvc/lib/86/SDL2test.lib, (静态库, 150KB) msvc/lib/64/SDL2.lib 等等.
rustbatch
这是我在 Rust 中创建 2D 游戏库的尝试。我的主要重点是性能,该库为游戏瓶颈(如碰撞检测或路径查找)提供快速解决方案。尽管库的主要功能是围绕批量处理构建的 OpenGL 包装器。请查看 示例存储库,我在其中展示了以 60 fps 渲染和处理 10k boids 的能力。借助 rustbatch 扫描仪,每帧不需要进行 1000 万次迭代。
如果你想知道为什么 Rustbatch 的前三个版本被撤回,让我说,我没有充分测试核心功能。
此外,rustbatch 有自己的 Discord 频道。
lib.rs
:
为了使包运行,您必须从 存储库 复制 msvc
文件夹和 build.rs
,并将其放置在项目的根目录中。
RustBatch
这个包为构建大型 2D 游戏(处理大量实体)提供了一些高性能工具。到目前为止,包包含
- 基于批量处理的 OpenGL 抽象
- 碰撞扫描器,为数千个实体提供快速碰撞检测
- 多线程路径查找器,即使对于 1000 x 1000 的瓦片地图也没有问题
- 数学模块,包含 Matrix、Vector 或 Rectangle 等结构体
- 支持自定义每批顶点和片段着色器
- 精灵打包,让您充分利用批量处理
预热
值得注意的是,渲染模块中的某些函数调用 gl 包中的函数和枚举。必须首先加载这些函数,这可以通过创建窗口来实现。
示例
extern crate rustbatch;
use rustbatch::{sdl2, image, gl};
use rustbatch::debug::FPS;
use rustbatch::{Window, Texture, Sprite, Batch};
use rustbatch::{Mat, Vect};
use rustbatch::render::texture::TextureConfig;
use rustbatch::rgba::WHITE;
fn main() {
// creating window to draw to and event pump to read input. Ignore
// gl var, it cannot be dropped otherwise rendering will not work so just leave it be
let (mut window, mut event_pump, _gl, _sdl, _video_subsystem) = Window::new(|sys| {
sys.window("rusty batch", 400, 400)
.opengl()
.resizable()
.build()
.unwrap()
});
window.set_background_color(&[0.5f32, 0.5f32, 0.5f32, 1f32]); //gray background
// This is wrapped opengl texture object
let texture = Texture::new(
"C:/Users/jakub/Documents/programming/rust/src/rustbatch/assets/logo.png",
TextureConfig::DEFAULT,
).unwrap();
// Creating sprite. Notice that sprite is just collection of points and it cannot be directly
// drawn to window
let mut sprite = Sprite::new(texture.frame());
// On the other hand batch owns texture witch can be drawn to window
let mut batch = Batch::new(texture);
// this is just a little helper
let mut fps = FPS::new(1f32);
'main: loop {
//polling events
for event in event_pump.poll_iter() {
match event {
// break loop if X button on window is pressed
sdl2::event::Event::Quit { .. } => break 'main,
_ => {}
}
}
// i hope you know how to get delta on your own but fps returns is as bonus if you supply
// 0f32 as delta
let _delta = fps.increase(0f32);
window.clear();
// drawing sprite to batch
// texture color is multiplied by inputted color
sprite.draw(&mut batch, Vect::ZERO, Vect::mirror(1f32), 0f32, &WHITE);
// drawing batch to window
batch.draw(&mut window.canvas);
// Don't forget to clear batch if you not planning to use it as canvas,
// after all drawing sprites to batch takes some time
batch.clear();
// finishing with window update so you can se it changing
window.update();
}
}
依赖关系
~27MB
~521K SLoC