Handmade Hero»Forums»Code»How does the asset streaming work?
16 posts
How does the asset streaming work?
1 month, 2 weeks ago Edited by Opoiregwfetags on June 14, 2021, 11:22 p.m. Reason: Wording mistake
I've seen some episodes about the asset streaming but I don't quite understand the idea. I get that when an asset is needed and it isn't in memory, it is loaded into memory. But from where? Is it read from disk, or from a big buffer of all assets?

It can't be loaded from a big buffer of all assets in permanent memory, because that would mean we do have enough space in memory for all assets. But I think that there was a big file that stored all assets, maybe encrypted. You could read only the part of the asset you want... But of course, it can't be encrypted all as one package because then to access any part of it you have to decrypt the whole thing and, again, store it somewhere. So, is it that the big file has each asset stored encrypted individually, one after the other, and when an asset is needed it is pulled from permanent memory/disk, decrypted, and loaded into memory? Or what???

Mārtiņš Možeiko
2244 posts / 1 project
How does the asset streaming work?
1 month, 2 weeks ago Edited by Mārtiņš Možeiko on June 14, 2021, 11:43 p.m.
If you're asking specifically about HH code then it does not do any encryption - it just reads part of .hha file where asset is into memory. And when read operation finishes, then rest of code can use the asset.

But if you're asking how this would work with encryption, the answer is exactly the same. When applying encryption to packed asset file, you never want to encrypt everything as one huge stream - specifically because of these asset loading reasons. You must provide ability to load random parts of it. You can do that easily by doing CTR mode of block cipher that allows to decrypt any block at arbitrary location. This is pretty much how most modern uses for block ciphers are implemented (like in TLS/HTTPS). Or you could simply encrypt each asset portion independently. So all assets are encrypted separately, and then the encrypted contents are concatenated into file. This way you would simply read each file from where it begins till where it ends and decrypt only this part.
16 posts
How does the asset streaming work?
1 month, 2 weeks ago
Thanks a lot! <3