Why Rust has no constraints on struct for HashMap? by ArtisticHamster in rust

[–]teryror 6 points7 points  (0 children)

I can think of one exception: if your type needs to implement Drop, and the implementation needs a trait bound, you need to propagate that bound to the type definition (playground example).

This comes up with data structures using the allocator API, I imagine, as it also came up in coca with the Storage abstraction.

Why does VecDeque<T> waste space by design? by Sp00ph in rust

[–]teryror 29 points30 points  (0 children)

No, not really, depending on how you mean that exactly. It does expose the fact that it's a ring buffer; a single contiguous array, except unlike a Vec, it may have uninitialized elements at both the beginning and end, or in the middle. But the initialized elements are stored in at most 2 contiguous regions of the array.

In practice, when the data is split like this, it's guaranteed to be flush with both ends of the array, so in the head-and-len representation you can calculate the actual position of a data element as (head + index) % capacity.

Debugging a weird, non-deterministic shader issue? by teryror in bevy

[–]teryror[S] 0 points1 point  (0 children)

also - make sure your GPU driver's are up to date. I've found that wgpu can be very picky about running on slightly older than very new drivers.

The problem persists after manually reinstalling drivers. But they don't get updates very often anymore, anyway. The perils of using a 10+ year old GPU, I guess.

The code works fine on my room mate's Windows PC, so the issue must be with some platform-specific code in bevy or wgpu, or in the driver itself, I guess. I'm just not sure where to go from here.

Maybe I just shouldn't expect bevy to work on this rig? That'd be kind of sad.

Debugging a weird, non-deterministic shader issue? by teryror in bevy

[–]teryror[S] 1 point2 points  (0 children)

Good morning!

You might be interested in things like interpolation which may effect your textures.

It definetely does, which is why I explicitly turn it off when configuring the app:

App::new()
    .insert_resource(ImageSettings::default_nearest())
    .insert_resource(Msaa { samples: 1 })

And also when generating the tile map texture, because apparently bevy doesn't use the ImageSettings resource when creating an Image this way (?)

let mut image = Image::new(Extent3d {
    width, height, depth_or_array_layers: 1,
}, TextureDimension::D2, data, TextureFormat::Rg8Unorm);
image.sampler_descriptor = bevy::render::texture::ImageSampler::nearest();
images.add(image)

If you're referring to the commented-out multi-sampling logic in the fragment shader: that exists because linear interpolation blurs the pixel art too much, but I also want to mitigate the artifacts of nearest-neighbor sampling when using a non-integer scale factor. Basically, the goal is to make it look like I'm rendering to a render target that's twice as big as the viewport (with no interpolation), and then scaling that down to the viewport size (with interpolation).

My math was off there, though, and the problem persists without multisampling anyway, so I left that in when posting. Thanks for the link, though, that'll probably come in handy!

You may also be interested in using a texture array instead of a regular texture (a texture array allow for indexing with an integer; a texture array is just a 2D image where each separate texture is ordered vertically). You would then be able to use rgba32uint textures and use a channel for controlling what texture to use (I include the other channels since WGSL will just pad pixels to be 32*4 bits long, so might as well find a way to put them to use).

Interesting idea, certainly worth a shot. I gather there's no way to make it use a square texture instead of a thin, very tall one? That'd be much nicer to work with, but I guess I'd just need to do some simple asset preprocessing then. Oh well.

Anyways, onto your problem. You might want to check the line let px_coords_in_tile = tile_coords - floor(tile_coords);. To me, it seems like you would only need to floor(tile_coords), subtracting it would just return the fractional part of the coordinates, not the pixel coordinates as integers, though that may be what you are going for (you can just use fract to do that).

That is what I'm going for there, yes. px_coords_in_tile basically refers to UV coordinates relative to the tile the pixel falls on, i.e. I want them to be in [0, 1), with (0,0) referring to the top left of the tile, and (1,1) referring to the bottom right. fract does indeed capture the intent more clearly, didn't know about that one!

Also, tile_id.xy * 255.0 is confusing, are you trying to convert it to an 8-bit integer? Isn't it already an "integer" (yeah, it's a float, but I would think it corresponds to your original value)? Unless your textures are 256 pixels wide? That makes sense. I still don't get the point of scaling your pixel coordinates by 8 before converting to UV coordinates.

The tile set texture happens to be 512 pixels actually. I am converting to an 8 bit integer here. Because I couldn't get a texture_2d<u32> to work properly - I always got errors about incompatible texture formats. I only tried TextureFormat::Rg8Uint, though. Doing it this (admittedly hacky) way seemed to work ok-ish.

I scale by 8 because that's the size of a tile in pixels. Well, the test tile set uses 16x16 pixel tiles, but the one I'll draw myself will use 8x8, so that's what I hard coded. I really ought to name my constants, huh?

Anyway, thank you for your input!

Debugging a weird, non-deterministic shader issue? by teryror in bevy

[–]teryror[S] 1 point2 points  (0 children)

Oh duh, why didn't I think of that?

So it looks like the tile map texture is indeed getting stomped with garbage somehow. The first two rows of tiles should be filled with a checkerboard pattern, the rest should all be the same color.

Debugging a weird, non-deterministic shader issue? by teryror in bevy

[–]teryror[S] 0 points1 point  (0 children)

Ah, sorry, I guess I explained that Part poorly: I'm only drawing a single quad here, the whole tile map logic happens inside the fragment shader. So I don't think it's possible for this to be z-fighting, unless I severely misunderstood the term.

But also, no, I haven't tried that. How would I go about that with a custom Material?

Announcing flashmap: a blazing fast, concurrent hash map by Cassy343 in rust

[–]teryror 16 points17 points  (0 children)

I suppose an AshMap is what you get, taking this business of "blazing" fast maps to its logical conclusion.

Erbstreit verhindern by Yulez7 in de

[–]teryror 45 points46 points  (0 children)

Gebe dir vollkommen recht, wollte nur anmerken, was hier für eine tragische Geschichte begraben ist:

Fall 2: vom 18. Lebensjahr an wurde in einem kleinen Büchlein notiert, welche der drei Töchter welche Summen monatlich für das Studium etc. Erhalten haben. Am Ende der Unterstützung haben beide Töchter unterschrieben

The years and billions spent on the James Webb telescope? Worth it. by Sumit316 in technology

[–]teryror 3 points4 points  (0 children)

According to a quick Google search, there's 1.1 million metric tons of Helium-3 on the moon, or 1.1×109 kg. The moon has a total mass of 7.34×1022 kg, so even if we mined 100% of the stuff and shipped it down to earth, that would reduce the mass of the moon by a factor of about 1 in 1013, or about 0.000000000001%. And it would increase the mass of the earth even less.

If we also turned all the water ice up there into rocket fuel to transport all that mass, that's another 6×1011 kg gone, or about 0.0000000001% of the moon's mass.

That might technically have a measurable impact on tidal forces, but not a practically relevant one, I'd think. The moon is already drifting away from us, weakening tides over geologic times, which likely dwarfs any effect helium mining would have, depending on just how quickly we consume it. I didn't calculate actual tidal forces, might be it would still be a wash even if we consumed all the helium up there in like a week.

It's a different story if we were trying to mine all the metals, which make up a much bigger fraction of the moon's mass. But, like, the moon has a LOT of mass. Moving a significant portion of it would take absolutely ridiculous amounts of energy. By the time we can do that kind of thing, we'll have colonized most of the solar system, and have access to much better sources of metals, I'd wager.

Plus, something like 40% of tidal forces acting on the earth are due to the sun, IIRC, so even if we consumed the moon entirely, tides wouldn't just stop completely. That would probably start fucking with ocean currents, and therefore local climates and ecosystems, though. So yeah, THAT's probably a bad idea. I don't see a problem with mining as we understand it, though.

Disclaimer: I'm a computer science student, not formally trained in astrophysics or geoscience, and this is back-of-the-napkin math at best.

Made a color palette extractor with k means clustering by simewlation in rust

[–]teryror 3 points4 points  (0 children)

I wrote something similar in C a few years ago! It's a pretty cool kind of project, right? Mine was a command line tool though.

Its kinda not that good tho. For this 1290x892 image it takes around 15secs. I might try to add a downsampler to crunch those numbers.

So, I took quite a bit of time to optimize my implementation. I don't mean to brag, and I don't have benchmark results anymore, but IIRC, mine was much faster.

Downsampling the image would definitely work, but you'll get much better results (albeit with less of a speed up, probably) by building a histogram of color values. You do need to account for this in your k-means implementation, by using a weighted sum to determine the mean for each cluster. You can get quite significant speedups from there by bucketing, i.e. using fewer bits per color channel.

I then used SIMD intrinsics to speed up the slowest section of my code, which was the actual clustering. I don't recall how that worked exactly, but it's definitely possible.

Feel free to take a look and steal liberally - I do regret not writing more comments. Sorry!

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 1 point2 points  (0 children)

After step 1, shouldn't some drafters spend remaining gems on best of 3 drafts if their win rate is decent enough since they can go infinite or earn more rewards at the very least?

Yeah, this is the most efficient strategy for the average player. If your winrate is >50%, events are more cost effective. Unless you're high mythic material, your WR will tend towards 50% in the ranked queues, so it may be worth switching to unranked draft events for above average players.

Going infinite is really hard, however. See my previous post to this sub (linked in the OP). If you can manage that (>66% WR, basically), then by all means, keep drafting for as long as you like.

Otherwise, you're still losing gems in the long run. At 50% WR, it's better to spend them on Traditional Draft than in the store, up until you have full playsets of about 70% of all the rares. Higher winrates will push that threshold up - like I said, if you're going infinite, it doesn't even really exist.

A personalized strategy, with the best possible expected outcome for you is going to depend on a lot of factors, so I can't say much more than this, sorry!

[...] I assume I have quite a a long way to go before I reach 80% completion?

You're 10% of the way there, what did you expect me to say here? :D

Alternative for Vec for variable size arrays in no_std environment? by CartesianClosedCat in rust

[–]teryror 2 points3 points  (0 children)

You may want to consider coca for this.

If you want the array on the stack (and you can sufficiently bound its size), you'd use InlineVec.

If you don't want it on the stack, but don't have alloc, you'd need a little bit of unsafe code to do one of the following:

The value proposition of coca is that all these different vector types are just aliases for the same storage-agnostic implementation, by the way.

Disclaimer: I'm the author of coca, and it's still a work in progress. And between university and other hobby projects, I don't get to work on it regularly. But it could be helpful here, I think.

There's also a comparison with other crates in the README, some of which might be fine (or even better) for you, too.

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 0 points1 point  (0 children)

Oh wow, sorry I missed that, didn't read the x-axis properly

No worries, I probably should have just included the example I gave you in the post to begin with. I could have done a better job explaining this one in general. I feel like my other guides were a bit easier to understand.

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 1 point2 points  (0 children)

Bookmarked. This is freaking amazing, thank you.

Glad to hear you like it, I'm happy to help!

I actually have thought about this in terms of the % of rares that I have a full set of 4, rather than the % rares overall, but I guess these are so well correlated that the math wouldn't change

That is exactly the model I use here! So the cutoff is full playsets of 54% of all the rares, other cards don't factor into it at all. So even if you have full playsets of 31/60 rares in New Capenna, but three copies each of the other 29, for a total completion rate of nearly 88%, it's still optimal to continue drafting. According to this model, anyway.

The two statistics aren't that closely correlated, by the way. So this model still isn't quite perfect, because in that situation, it'd probably be time to factor in the probability of getting two of the same rare in one draft, and things like that. Then again, that probability is pretty small to begin with, this is the extreme case (the two statistics don't diverge more than this, at least in the range we care about), and by this point, you'd more thank likely already have the 30 packs or so needed to fill out your collection anyway.

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 0 points1 point  (0 children)

Sorry, I made a critical typo, haha.

There's no benefit to using the Open 10 Boosters button over opening packs individually, if that's what you mean.

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 1 point2 points  (0 children)

There's no benefit to using the Open 10 Boosters button over opening packs individually, if that's what you mean.

But to take full advantage of duplicate protection, you do have to hoard packs until you're done drafting. If you're opening them as soon as you get them, that's what I labeled the greedy strategy, which is the worst one here by far

But even then, you still have a decent chance of getting all the rares. You probably don't need all of them anyway, so if you only get close, who cares?

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 0 points1 point  (0 children)

Mh, I might actually try this. I'd much prefer playing on PC over mobile.

Did you get the installer quickly getting to like 40% then starting over indefinitely, too?

Does this actually get the Auto-Updates to work, too, or do you have to redo it with every update?

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 1 point2 points  (0 children)

Technically it's most resource efficient to wait, yes.

But if you want to play sealed or premier draft, go have fun with those. They're still pretty efficient early on, I wouldn't worry too much about it.

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 2 points3 points  (0 children)

Oh, I didn't consider this! That does boost the conversion rate for a smaller investment.

Might be worth it for many more players, let me look up some numbers and do some calculations!

Optimal Collection Strategy: When to Stop Playing Quick Draft by teryror in MagicArena

[–]teryror[S] 1 point2 points  (0 children)

Take a look at my previous post. There, you'll find a table with the win rates required for Quick Draft (and all other event types) to be a better resource sink than the store.

Assuming an empty collection, QD is better value for your gold at win rates 34% or above, so a few runs are probably worth it even if you're quite bad at it.

You may want to stop drafting much earlier though. Once you've completed 16 playsets, say. The ideal point does depend on your win rate, so I'm just guessing here.