Rust Programming

7734 readers
1 users here now

founded 5 years ago
MODERATORS
26
27
23
submitted 3 months ago* (last edited 3 months ago) by [email protected] to c/[email protected]
 
 

I’m working on a big project in #Rust, there is toolset and API for #Playdate.

All going great, moving to stabilization step by step, but I’m tired of looking at the dull 90⭐️. Seriously, could you please throw me into the trends of the github, please! ❤️‍🔥

Project repository, mastodon.

28
 
 

The April edition of "This Month in Rust GameDev" has just landed!.

You may have noticed that this marks the first release since quite a while. To revive the newsletter, we made some organisational changes.
We want to continue improving the project, so we've put together a survey for you to tell us how the newsletter should evolve. We'd be happy if you filled it out and / or shared it with your fellow game devs 🙂

This is also your call for submissions for May's edition!

Happy coding ✨

29
 
 

I just released v0.1.0 of hinoki, my static site generator :)
The README.md should explain usage, and you can also see how I ported my blog to it here.

This project started because I'm not entirely happy with Zola, which does not support customizing page paths much (e.g. /year/month/day/title/index.html style paths) and made some other design decisions that I wanted to explore alternatives to.

You can download the binary from GitHub releases, or cargo install it from git.

Any feedback is appreciated, here or in the GitHub issues!

30
31
 
 

The Rust gamedev working group's newsletter "This Month in Rust GameDev" has been rebooted, starting this April 🎉

This is your call for submissions. Got a game you're tinkering on? A crate for fellow game devs? Do you want to share a tutorial you've made? Are you excited about a new feature in your favorite engine? Share it with us! You can add your news to this month's WIP newsletter and mention the current tracking issue in your PR to get them included. We will then send out the newsletter at the start of next month.

Happy coding!

32
7
submitted 4 months ago* (last edited 4 months ago) by [email protected] to c/[email protected]
 
 

So I want to update the sprite so my character looks in a different direction each time the player presses left/right, how could I do this? I can't do it in the setup fn, since it's a startup system, appreciate any help

EDIT: changed formating

here is my code:

use bevy::prelude::*;

`fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) // prevents blurry sprites
        .add_systems(Startup, setup)
        .add_systems(Update, animate_sprite)
        .add_systems(Update, player_movement_system)
        .run();
}

const BOUNDS: Vec2 = Vec2::new(1200.0, 640.0);
static mut FLIP_BOOLEAN: bool = false;

fn set_flip_boolean(boolean: bool) {
    unsafe {
        FLIP_BOOLEAN = boolean;
    }
}

fn get_flip_boolean() -> bool{
    unsafe {
        FLIP_BOOLEAN
    }
}

#[derive(Component)]
struct Player {
    movement_speed: f32,
}

#[derive(Component)]
struct AnimationIndices {
    first: usize,
    last: usize,
}

#[derive(Component, Deref, DerefMut)]
struct AnimationTimer(Timer);

fn animate_sprite(
    time: Res<Time>,
    mut query: Query<(&AnimationIndices, &mut AnimationTimer, &mut TextureAtlas)>,
) {
    for (indices, mut timer, mut atlas) in &mut query {
        timer.tick(time.delta());
        if timer.just_finished() {
            atlas.index = if atlas.index == indices.last {
                indices.first
            } else {
                atlas.index + 1
            };
        }
    }
}


fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
) {
    let texture = asset_server.load("sprites/Idle01.png");
    let layout = TextureAtlasLayout::from_grid(Vec2::new(64.0, 40.0), 5, 1, None, None);
    let texture_atlas_layout = texture_atlas_layouts.add(layout);
    let animation_indices = AnimationIndices { first: 0, last: 4 };
    let boolean = get_flip_boolean();
    commands.spawn(Camera2dBundle::default());
    commands.spawn((
        SpriteSheetBundle {
            texture,
            atlas: TextureAtlas {
                layout: texture_atlas_layout,
                index: animation_indices.first,
            },
            
            ..default()
        },
        Player {
            movement_speed: 500.0,
        },
        animation_indices,
        AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
    ));
}

fn player_movement_system(
    time: Res<Time>,
    keyboard_input: Res<ButtonInput<KeyCode>>,
    mut query: Query<(&Player, &mut Transform)>,
) {
    let (guy, mut transform) = query.single_mut();

    let mut movement_factor = 0.0;

    let mut movement_direction = Vec3::X;

    if keyboard_input.pressed(KeyCode::ArrowLeft) {
        movement_factor -= 1.0;
        movement_direction = Vec3::X;
        set_flip_boolean(true);
    }

    if keyboard_input.pressed(KeyCode::ArrowRight) {
        movement_factor += 1.0;
        movement_direction = Vec3::X;
        set_flip_boolean(false);
    }

    if keyboard_input.pressed(KeyCode::ArrowUp) {
        movement_factor += 1.0;
        movement_direction = Vec3::Y;
    }

    if keyboard_input.pressed(KeyCode::ArrowDown) {
        movement_factor -= 1.0;
        movement_direction = Vec3::Y;
    }


    let movement_distance = movement_factor * guy.movement_speed * time.delta_seconds();
    let translation_delta = movement_direction * movement_distance;
    transform.translation += translation_delta;

    let extents = Vec3::from((BOUNDS / 2.0, 0.0));
    transform.translation = transform.translation.min(extents).max(-extents);
}
33
 
 

Been working on this a few months. It's inspired by previous generations of parser generators, and by my own previous work generating ast lexers from grammar files. This integrates seamlessly with the type system, allowing you to declare your syntax, extract only the data you want as variables, and evaluate them easily. And just from a simple description of your syntax, you'll get beautiful errors which visually point out structures in the input.

With this I have been able to implement a (mostly complete) JSON parser in just 12 lines of parsing logic, and a pmdas-respecting expression parser in just 6 (with one helper function to apply individual operators).

Examples available on the github repo, also now available on crates.io!

34
35
 
 

Hi.

Rust can run on anything from web browsers to Adruinos. BUT can you make Android/iOS apps with it? I heard that you can make the backend of your app in Rust and then incorporate it into your Java/Kotlin app, but I'm looking for something like React Native or Flutter, where you can build the entire app (including UI and interacting with native APIs) in Rust without writing a single line of Java/Kotlin.

Does something like that exist? If not, then is anyone working on it?

Oh, and I don't mean I want one of the many libraries which just compile your code to WASM and run the app in a WebView... I want something that lets me make native UIs - like React Native or Flutter.

Thanks

36
 
 

Rust is beautiful and at the same time pretty hard language to learn. While mastering it and digging deeper, I decided to play around basic data structures and algorithms. I put a repo with some theory, implementations and examples on github mainly for myself, but maybe someone will find it helpful, or share more effective solutions. For now, just a few topics are covered, and I'm going to update it from time to time.

repo: https://github.com/tracyspacy/algos_data_structures_rust

37
38
 
 

I have a plugin trait that includes some heavy types that would be almost impossible to wrap into a single API. It looks like this:

pub struct PluginContext<'a> {
    pub query: &'a mut String,
    pub gl_window: &'a GlutinWindowContext,
    flow: PluginFlowControl,
    pub egui_ctx: &'a Context,
    disable_cursor: bool,
    error: Option<String>,
}
pub trait Plugin {
    fn configure(&mut self, builder: ConfigBuilder) -> Result<ConfigBuilder, ConfigError> {
        Ok(builder)
    }
    fn search(&mut self, ui: &mut Ui, ctx: &mut PluginContext<'_>);
    fn before_search(&mut self, _ctx: &mut PluginContext<'_>) {}
}

Here is what I considered:

  1. Keeping all plugins in-repo. This is what I do now, however I'd like to make a plugin that would just pollute the repository. So I need another option that would keep the plugins' freedom as it is right now, but with the possibility to move the plugin out to a separate repository.
  2. I tried to look into dynamic loading, and since rust doesn't have a stable ABI, I'm okay with restricting the rust versions for the plugin ecosystem. However, I don't think it's possible to compile this complex API into a dynamic lib and load it safely.
  3. I'm also ok with recompiling the app every time I need a new plugin, but I would like to load these plugins automatically, so I don't want to change the code every time I need a new plugin. For example, I imagine loading all plugins from a folder. Unfortunately, I didn't find an easy solution for this neither. I think I will write a build macro that checks the ~/.config/myapp/plugins and include all of them into the repo.

Do you have any better ideas, suggestions? Thanks in advance.

(For context, this the app I'm writing about: https://github.com/fxdave/vonal-rust)

39
 
 

When I install some Linux app from, let's say GitHub, I can feel how long without updates means the project is not maintained.
For example last commit being 5 years ago for GTK app is a long time and this is considered an abandoned repo. For super simple things like cowsay it's not that simple but still I can feel it.

How is that with crates with Rust? I see a lot of parsers or web libraries that are not updated for a year, two years, three years... How old is too old?
Also, many of them have a version 0.x.x, so can I even consider them stable?

40
41
 
 

similar to other tools. the author says "RustViz is a bit more of a purely educational tool, as code has to be annotated manually, while Boris aims to be more of a development assistance"

42
 
 

Using the Overpass API to read OSM data, parsing the data with Rust, and then drawing the map onto HTML5 canvas.

43
 
 

I recently made a fairly simple shader heavily inspired by the one used for characters in The Legend of Zelda: The Wind Waker. I've got all my info on how it worked on the GameCube from this amazing video

Check out the source at bevy_wind_waker_shader

Here are some screenshots :)

Sphere:

Sphere

Light throughout day:

Light throughout day

Daylight

Daylight

Night time

Night time

44
45
46
 
 

Anyone aware of a testing framework hopefully integrating well, and abstracting the shuttle testing functionality?

BTW I found rtest, but it doesn't in particular abstracts shuttle at all, it's a fixtures generic framework.

Planning to use shuttle to do MT testing targeting C binded code, and looking for a way to abstract as much as possible the shuttle scheduler trait and such...

Thanks !

47
 
 

publicado de forma cruzada desde: https://infosec.pub/post/8054415

Stract is an open source search engine where the user has the ability to see exactly what is going on and customize almost everything about their search results. It's a search engine made for hackers and tinkerers just like ourselves. No more searches where some of the terms in the query arent used, and the engine tries to guess what you really meant. You get what you search for.

Fun fact: It's written in Rust! (nearly 90%) https://github.com/StractOrg/stract

48
 
 

Hi all,

We've started a new community for learning rust and/or the lemmy codebase together.

Come join in: [email protected]

The idea is that there are probably a good amount of people interested in learning rust, or, interested in contributing to or using the lemmy codebase, but find it difficult to get started ... so basically why not start a sort of study group or reading group or support channel style of community? Here's where the idea was originally suggested: https://lemmy.ml/post/11232276

We're just putting the place together and sorting out how it could work, but all kinds of inputs and levels of expertise are welcome!

49
50
view more: ‹ prev next ›