U
Urto
Guest
The player in my game has to explore a rather large world that can't reasonably fit into memory. Instead, they simply load parts of the world from files as they approach and unload as they walk away. This was working fine at first, but as I added more complexity in how designers can build these pieces of the world, there started to be a bad hiccup in FPS when these loads occurred. They're just too big right now. I've done some other optimizations, but the big one I seem to need is asynchronous file loading. And gratefully, GMS2 has the buffer_load_async() function.
Here's my issue: one of the arguments of buffer_load_async requires me to specify a buffer size. Presumably, I just want the buffer to be exactly as big as the file I'm going to load. But near as I can make out, GMS2 has no functions to get the size of a file on disk.
Since I can make the buffer beforehand, I've tried setting it's type to buffer_grow, but that doesn't seem to matter; no matter what I do, the size I specify in the 4th argument of buffer_load_async is the maximum amount of characters I can load into the buffer as a string. Making it a grow-type buffer offers me no extra room.
I can just make all of the buffers WAY too big, but that seems like a waste of memory and could potentially lead to some bad data when I read the buffer. The only solution I can even come up with is: on game load, read every file the normal synchronous way, but discard the findings and store the length of the final string in a map (with the key being the filename). Then, when I have to load the file later, I can get the size of the buffer by looking up the file name in that map...
... but that solution just seems to suck. Surely there's some better way to use buffer_load_async and to actually know how big I need the buffer to be based on the file I'm loading, right? Or at worst to let it be a grow-type buffer?
Here's my issue: one of the arguments of buffer_load_async requires me to specify a buffer size. Presumably, I just want the buffer to be exactly as big as the file I'm going to load. But near as I can make out, GMS2 has no functions to get the size of a file on disk.
Since I can make the buffer beforehand, I've tried setting it's type to buffer_grow, but that doesn't seem to matter; no matter what I do, the size I specify in the 4th argument of buffer_load_async is the maximum amount of characters I can load into the buffer as a string. Making it a grow-type buffer offers me no extra room.
I can just make all of the buffers WAY too big, but that seems like a waste of memory and could potentially lead to some bad data when I read the buffer. The only solution I can even come up with is: on game load, read every file the normal synchronous way, but discard the findings and store the length of the final string in a map (with the key being the filename). Then, when I have to load the file later, I can get the size of the buffer by looking up the file name in that map...
... but that solution just seems to suck. Surely there's some better way to use buffer_load_async and to actually know how big I need the buffer to be based on the file I'm loading, right? Or at worst to let it be a grow-type buffer?