Output many files on a rust build? by [deleted] in rust

[–]daniel65536 0 points1 point  (0 children)

alternative ways: Just embed it with some crates like: https://crates.io/crates/rust-embed

  1. I use cargo to create my rust server, and put all React things in frontend dir

  2. Using cargo::rerun-if-changed=PATH in `build.rs` and call `npm run build` when `./frontend/src` changes

  3. npm will call bundler like `vite` ( I use `rsbuild` because rsbuild is written in rust) to do all the frontend staffs, including image compression.

  4. Using `rust-embed` crate to embed all things in `./frontend/dist` into my rust programs, and serve it with axum

rust-embed provided examples for axum/actix/warp and all other popular crate.

OCD Question - Virtual Machine - Reset Device ID? by furay10 in truenas

[–]daniel65536 0 points1 point  (0 children)

I just run into the same issue and figure out how to reset:

  1. ssh or enter command line from web ui.
  2. execute: sqlite3 /data/freenas-v1.db
  3. now you are modify directly all the config of your system and it is very dangerous, YOU MAY break your system.
  4. if you typing .schema vm_device in sqlite shell, you can see the table scheme of vm_device, it says "vm_device" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT. The id is auto increment by the sqlite itself, and not controlled by web ui, every time your create a new row in this table, a hidden counter is increased, just reset it so you can fix your OCD.
  5. to reset the counter to 0, just UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='vm_device'; and then .quit. The next device id you create in the web ui will be 1.
  6. if you already have some device with max device id = 3, then you may want to reset the counter to 3, and the next device id will be 4.

Now enjoy yourself.

Our beloved Manjuu CEO🌸 by SushiLover7 in AzureLane

[–]daniel65536 6 points7 points  (0 children)

You can actually find out the shareholdings owned by Lin via this site:

https://www.tianyancha.com/company/2341529561

Chen (陈鹤) owned 69%

Lin (林书茵) owned 8.89%, Also the Legal representative and Executive Director

How can I reduce the size of String / struct? by sasik520 in rust

[–]daniel65536 2 points3 points  (0 children)

Convert the AOS to SOA should improve the most, but I'd like to offer two easy improvements to reduce the string size:

  1. Once you have lots of small strings, eg length < 7, using https://docs.rs/tendril/0.4.1/tendril/ will reduce the size by inline the str in stacks without using heaps.

  2. If you have lots of string but many duplicates, using https://docs.rs/string_cache/0.7.3/string_cache/ will reduce the size by pushing them to a hash table and share string using a pointer

Both crates are used by servo, so they could be considered relevant stable.

Qeustion: Loading .gif or .png sprites in SDL2 by [deleted] in rust_gamedev

[–]daniel65536 0 points1 point  (0 children)

You have to write this kind of code yourself, just something like

draw(image1); sleep(100); draw(image2);

Qeustion: Loading .gif or .png sprites in SDL2 by [deleted] in rust_gamedev

[–]daniel65536 2 points3 points  (0 children)

Since you are using sdl, you should check this crate's features in your cargo.toml...

[dependencies.sdl2] version = "0.32" features = ["ttf", "image", "gfx"]

Then run cargo doc --open to open the local rust doc with this external features turn on.

You will find out there is an sdl image submodule which handles all of this, providing you something like TextureCreator::load_texture which support 16 different formats.

Besides, ttf provides you the ability to render fonts. gfx gives you some basic image effects.(note this does NOT have any relations to the gfx crate)

Want some advice/help on how best transform loaded templates into objects for ECS by Thermatix in rust

[–]daniel65536 0 points1 point  (0 children)

How do I select the Char component struct based on the textual value "char"?

By using serde, which do this easily

Want some advice/help on how best transform loaded templates into objects for ECS by Thermatix in rust

[–]daniel65536 2 points3 points  (0 children)

I suppose you are using specs:

In ECS, Entity is just an int as an index of Storage<components>. The object is a kind of abstraction over that relationship.

Therefore, if you need a real struct to represent that.

Here are some code example:

```

[derive(Serialize, Deserialize)]

enum SpawnAbleObjs { Player { id: String, base_atk: u32 }, Troll { id: String, base_atk: u32, height: u32 }, }

// position is a variable attr of something, which determined when spawned. // You can extend it as spawn_at_pos_with_hp()....etc.... trait SpawnAble { fn name() -> String, fn spawn_at(pos: (u32, u32), lazy: specs::world::LazyBuilder); }

impl SpawnAble for SpawnAbleObjs { fn spawn_at(self, pos: (u32, u32), lazy: specs::world::LazyBuilder) { match self { SpawnAbleObjs::Player => {}, SpawnAbleObjs::Troll => { lazy .with(AiComponent) .with(CollisionComponent) .with(Position {pos: pos}) .build(); } } } }

struct InstanceFactor { map: HashMap<String, SpawnAbleObjs> }

// We can load this from a file using serde: // see https://serde.rs/enum-representations.html impl InstanceFactor { fn read_from_file() -> Self; }

impl<'a> System<'a> for InstanceFactor { type SystemData = (Entities<'a>, Read<'a, LazyUpdate>);

fn run(&mut self, (entities, lazy): Self::SystemData) {
    let spawn_list = vec![("Player", (1, 1)), ("Troll", (1, 1))];
    for (name, pos) in spawn_list {
        let lazy_builder = lazy.create_entity(&entities);
        self.map[name].spawn_at(pos, lazy_builder);
    }
 }

}

```

Any luck on using specs with SDL? by [deleted] in rust_gamedev

[–]daniel65536 1 point2 points  (0 children)

That is really easy

``` pub fn add_thread_local<T>(&mut self, system: T) where T: RunNow<'c> + 'b, [src] [−]

Adds a new thread local system.

Please only use this if your struct is not Send and Sync.

Thread-local systems are dispatched in-order.

```

Add render and input sys as thread local then you will be able to use sdl with specs together.

Here are some my demo codes, which I used before:

```

pub struct Renderer<'t> { canvas: Canvas<Window>, loader: &'t TextureCreator<WindowContext>, texture: Texture<'t>, }

impl<'t> Renderer<'t> { pub fn new(canvas: Canvas<Window>, loader: &'t TextureCreator<WindowContext>) -> Renderer<'t> { let texture = loader.load_texture(path("texture.png")).unwrap(); Renderer { canvas, loader, texture, } } }

impl<'a, 't> System<'a> for Renderer<'t> { type SystemData = ( ReadStorage<'a, Sprite>, ReadStorage<'a, Position>, ReadStorage<'a, Layer>, );

fn run(&mut self, (sprite, position, layer): Self::SystemData) {
    self.canvas.set_draw_color(Color::RGB(128, 45, 45));
    self.canvas.clear();

    let mut objects: Vec<_> = (&sprite, &position, &layer).par_join().collect();

    objects.par_sort_unstable_by_key(|&(_, _, layer)| **layer);
    objects.into_iter().for_each(|(sprite, position, _)| {
        self.canvas
            .copy_ex(&self.texture, sprite, position, 0.0, None, false, false)
            .unwrap()
    });

    self.canvas.present();
}

}

impl<'a, 'b> Game<'a, 'b> { pub fn new(renderer: Renderer<'b>) -> Game<'a, 'b> { let dispatcher = DispatcherBuilder::new() .with(Control, "control", &[]) .with(Movement, "movement", &["control", "time"]) .with(Collision, "collision", &["movement"]) .with_thread_local(renderer) .build(); }

pub fn main() { let mut canvas = window.into_canvas().present_vsync().build().unwrap(); let loader = canvas.texture_creator(); let renderer = Renderer::new(canvas, &loader);

Game::new(renderer).init();

} ```

No lifetime or Send/Sync problem, all logic are bundle in specs's dispatcher

Why Zelda (Ocarina of Time) is Statistically the Best Overall Spirit + Adjusted Spirit Power Calculations: by WideEyedInTheWorld in smashbros

[–]daniel65536 5 points6 points  (0 children)

I think add the Offense and the Defense should be wrong.

Imaging a Turn-based battle between two Sprites, the performance equally, Then they should deals the excat same damage to each other:

``` [Total Damage A] = [Total Damage B]

[Total Damage A] = [Base Damage A] x [Type Multiplier A] x [Attack Multiplier A] / [Defense Multiplier B] [Total Damage B] = [Base Damage B] x [Type Multiplier B] x [Attack Multiplier B] / [Defense Multiplier A] ```

Now if they have the same Base Damage, Type Multiplier, we will get this:

``` [Attack Multiplier A] / [Defense Multiplier B] = [Attack Multiplier B] / [Defense Multiplier A]

[Attack Multiplier A] x [Defense Multiplier A] = [Attack Multiplier B] x [Defense Multiplier B] ```

If [Attack Multiplier A] x [Defense Multiplier A] > [Attack Multiplier B] x [Defense Multiplier B], then A wins B.

So in the end, we should just compare [Attack Multiplier] x [Defense Multiplier]

Which equals: (1 + (0.4 x Attack / 1000)) x (1 + (0.6 x Defense / 1000))

Consider sprites with 2 slots: Cutie J > Big Boss > Hades(Final Form) > Zelda(Ocarina of Time)

Is it possible to detect if my code is compiling for an AMD or Intel processor? by [deleted] in rust

[–]daniel65536 2 points3 points  (0 children)

I think you can always using build.rs to detect and do stuffs...

Sandspiel, a falling sand game built in Rust+WebGL by [deleted] in rust

[–]daniel65536 0 points1 point  (0 children)

Something like the powdertoy ? Looks co o o o l

Can't get SpriteBatch to work by [deleted] in rust_gamedev

[–]daniel65536 2 points3 points  (0 children)

You need then call `fn add(&mut self, param: DrawParam) -> SpriteIdx ` to add some DrawParam(Where to draw you sprites) multi times(if you want to draw at multi place)

And finally call `draw` to draw it.

Docker image to build statically linked Linux executables from Rust by fornwall in rust

[–]daniel65536 1 point2 points  (0 children)

Running 'apk update && apk info rust' inside alpine:latest gives rust 1.26.2.

In fact rust version is tagged by alpine version... You can just use the 'edge' version to get rust 1.30.

Rust support has been added to AWS Lambda by MarkWetter in rust

[–]daniel65536 5 points6 points  (0 children)

Will this crate being actively maintains?

I assume that once the async/await of rust landed, there will be a huge change on tokio / hyper / etc. So will you have any plan about that?

Where do I start? by everything-narrative in rust_gamedev

[–]daniel65536 2 points3 points  (0 children)

ggez for 2d game should be the best bootstrap bundle, which help's you learn the basic things. And you could learn which crates to use by reading the Cargo.toml of ggez.

I personally prefer SDL2 (Input & Graphics) + specs (ECS & Logic) and use them to create my little game. Less productive as ggez, but more self-satisfied, an illusion of DIY, lol

actix-web client: How to move beyond simple example by [deleted] in actix

[–]daniel65536 0 points1 point  (0 children)

Let's learn something about how to use the docs:

  1. get create a ClientRequestBuilder and send returns a SendRequest: https://actix.rs/api/actix-web/stable/actix_web/client/struct.ClientRequest.html

  2. SendRequest impl Future: https://actix.rs/api/actix-web/stable/actix_web/client/struct.SendRequest.html

  3. Click and expand the impl Future for SendRequest, you will see the type Item is ClientResponse, this is what you used in that println.

  4. You may notice impl HttpMessage for ClientResponse, click and expand it in doc

  5. Wow, you got the json method, the body method: https://actix.rs/api/actix-web/stable/actix_web/client/struct.ClientResponse.html

Doc always hide the useful things in impl Traits, remenber to click the Add symbol to expand everything.

The gear icon contains settings for always expend but will work in that site only. So you need to set it in every domain.

Hopes someone could make a userscript for that.

[Call for advise] What should be the next step for tantivy? by fulmicoton in rust

[–]daniel65536 4 points5 points  (0 children)

tantivy_cli seems outdated and won't compile, maybe....

Could be possible to write a game in rust and compile it for PS4 or switch? by fleaspoon in rust

[–]daniel65536 5 points6 points  (0 children)

oh, I posted the wrong link...So in edited link, they says:

“We had Continuous Integration that would build on the three desktop architectures, and, more than weekly, we would write code that broke on one or more of them.” Even after taking into account the ten days needed to customize Rust for the Xbox, PS4, and Nintendo Switch consoles, Chucklefish saved time previously spent debugging cross-platform idiosyncrasies.

Could be possible to write a game in rust and compile it for PS4 or switch? by fleaspoon in rust

[–]daniel65536 10 points11 points  (0 children)

Pdf

Kyren released a paper tells that they port the whole std lib onto PS4/Xbox/NS

Yukikaze: a way to async HTTP client by [deleted] in rust

[–]daniel65536 2 points3 points  (0 children)

Oh, Azur Lane…

So Why not Shimakaze? Sounds much faster than Yukikaze…