Libove Blog

Personal Blog about anything - mostly programming, cooking and random thoughts

Tag: rust

#

I've just one-shotted an iterator with a lifetime in #rust. Is this what it feels like when the language finally clicks?



#

#gamedev progress on hotel game:

  • did some further refactoring to rendering function
  • added room highlighting when building new rooms and selecting bed rooms for new guests

Not sure if I should be proud or embarrassed about this #rust code :D

// mark building tile
if let Some(mut r) = match game.mouse_action {
    MouseAction::BuildGrill => Some(Room::new_grill()),
    MouseAction::BuildStairs => Some(Room::new_stairs()),
    MouseAction::BuildBedroom => Some(Room::new_bed_room()),
    MouseAction::BuildCorridor => Some(Room::new_corridor()),
    MouseAction::BuildRestaurant => Some(Room::new_restaurant()),
    MouseAction::BuildWineCellar => Some(Room::new_wine_cellar()),
    _ => None,
} {
    // rendering code
}

Screen Recording of my hotel game. It shows the highlighting of available bed rooms and placing new rooms


#

Insights from the weekend:

  • Claude Sonnet 3.7 is the first #GenAI I tried out that actually produced usable code. The code is not pretty but it was the first time I was impressed by an AI system being able to produce non-trivial code and being able to adjust it to feedback.
  • I should stop using #python for one off scripts to convert data. The #rust ecosystem has a similar maturity. Building such scripts takes roughly the same time in both languages, but the rust system will finish the job order of magnitudes faster.
  • When your rust program feels slow you probably forget --release.

#

#gamedev progress on unnamed hotel game:

  • Spent a lot of time trying to streamline the guest AI code. This is something I still can wrap my head around entirely, partially due to #rust, mainly as this is something I never worked on before.
  • Corridors and doors are now rendered in front of rooms. Rooms are only shown if someone is in them.
  • Added simple buttons as start of UI.
  • It's now possible to place new rooms.

Screenshot of unnamed hotel game


#

I'm missing the vocabulary for googling this.

Is there a better way to write this? I want to filter a vector of enums to elements that match one specific pattern.

.filter(|r| match r.kind {
    RoomKind::BedRoom(_) => true,
    _ => false
})

#rust #dev



#

#gamedev progress:

Slow progress in the last couple of sessions. I've started to implement employees. Employees work at rooms/stations whenever a guest wants to interact with them (e.g. booking a room). I'm not yet 100% happy with the implementation (blaming my #rust skills).

Additionally implemented a hunger+restaurant prototype.

Screenshot from my hotel game. The guests are currently eating in the restaurant


#

#gamedev progress:

I'm in the mood for game development again. This is the progress after the second evening on a yet unnamed game.

Not much yet just:

  • rendering ground
  • rendering rooms

I'm currently using #rust and #sdl2


#

https://programming.dev/post/21199936

I've tried this quickly and you can use pango markup to change the text color in the label.

Here is a snippet with a label and a button that changes the text color from blue to red.

    let label = Label::builder().label("<span foreground=\"blue\">Blue text</span>").build();
    label.set_use_markup(true);
    tool_box.append(&label.clone());
    let button = Button::builder().label("Change").build();
    button.connect_clicked(move |button| {
        println!("Moved");
        label.set_label("<span foreground=\"red\">Red text</span>");
    });
    tool_box.append(&button.clone());

#rust #gtk #gkt-rs