GML Longest String from txt File Read and Copied without Dropping Below 75-60 fps

What's the maximum number of characters you can read (and copy to a variable) from txt file without incuring a drop below 60 fps? Maybe 75 fps if there nothing else running to make some room for the actual game that will be running. Also, any major difference between GM8 and GM Studio here?
 

Mike

nobody important
GMC Elder
There is no size that will guarantee you will keep running at 60fps.... this is totally dependant on an end users system. Not only will CPU, machine load and RAM all play a factor, but HDs are totally different and have varying speeds across the board. Older systems will use 5400 RPM drives and be incredibly slow, while newer systems might use SSDs and be virtually instant.

Even reading 1 byte will cause a stutter on a slower machine unless the read/write is async.
 
There is no size that will guarantee you will keep running at 60fps.... this is totally dependant on an end users system. Not only will CPU, machine load and RAM all play a factor, but HDs are totally different and have varying speeds across the board. Older systems will use 5400 RPM drives and be incredibly slow, while newer systems might use SSDs and be virtually instant.

Even reading 1 byte will cause a stutter on a slower machine unless the read/write is async.
I meant generally how much is too much to grab at once. I'm assuming a modern machine with a 7200 rpm hard drive and at least 4gb of ram, I'm not asking about ancient ones. How much data is a single character anyway?
 
Last edited:

Mike

nobody important
GMC Elder
Even with this setup, it depends on fragmentation, OS workload etc. You simply can not guarantee any kind of read/write at 60fps, and I would personally never try and base a game around this.
 
Even with this setup, it depends on fragmentation, OS workload etc. You simply can not guarantee any kind of read/write at 60fps, and I would personally never try and base a game around this.
So how would I get lines from a txt file as strings to read dialog in games without having this problem? Does async allow reading lines from a txt file? I don't really know what you're suggesting I do.
 
Last edited:

sylvain_l

Member
So how would I get lines from a txt file as strings to read dialog in games without having this problem?
if its a novel game, speed shouldn't be the problem (a drop under 60 fps shouldn't create any real disconfort - text that the player read in general aren't animated -)
for other, in general I would think just preload the required text elements for the whole tree dialog with the npc. (or if there are not too much dialog you could even load the dialogs of the whole level/room; or even the full texts of the game).

In my half started/finished hobbyist games, what always take most of memory are the sprites and sounds, never the texts

edit:

also what you could manage, is starting preloading text when player approach an npc. open the file, keep it open and read a line by step. at 60 fps that give you a buffer of 60 lines. much more that what a player should be able to read in 1 sec, what you'll have to load the next 60 lines.
and for the lenght of the lines, I would first care more of it being coherent with the size of the dialog box, than maximising the lenght to get more text in on step read call.
 
Last edited:

Mike

nobody important
GMC Elder
Yeah, a hic-up while reading text isn't drastic. Also, why wouldn't you just read it all in at the start? text isn't exactly going to take up a lot of memory, and even a few megs of it loaded at the start won't slow things down much. Then you'll never have to worry about it again.

if your worried about memory, keep it in a buffer and just extract it when you need to.
 

Yal

🐧 *penguin noises*
GMC Elder
How much data is a single character anyway?
1 byte, assuming it's an ASCII character and not an Unicode character. You should know basic stuff like this...


Is the speed concern because you're making an infinite-world style game where you need to load world "chunks" dynamically as the player enters new areas? It might be more efficient to "cache" them in memory in some way (even as text strings that are parsed each time you load a chunk as objects/tiles this could be more efficient) and only re-read them if the file has changed.
 
1 byte, assuming it's an ASCII character and not an Unicode character. You should know basic stuff like this...

Is the speed concern because you're making an infinite-world style game where you need to load world "chunks" dynamically as the player enters new areas? It might be more efficient to "cache" them in memory in some way (even as text strings that are parsed each time you load a chunk as objects/tiles this could be more efficient) and only re-read them if the file has changed.
No. I'm making a text reading dialog box that word wraps and goes through multiple boxes if the text fed it is longer than 1 box. I need to know how much I can grab from a txt file at once before I impact game performance so I can have a parent object do the bulk of coding, and minimize coding in specific npcs that may talk a lot, or maybe book reading on the long end of things. Basically I want to avoid manually calling each box or display line and allow dialog reading to be automated.

(given a line range from the txt file send to the box parent to decide what to display)

How often do I need to break up grabbing from the txt file so it doesn't slow down from a large amount of text? Basically how large the parts grabbed, but not yet displayed, can be without there being screen pausing slowdown.

(per page, per paragraph, per line, a number of characters?)


The method I'm using to grab the the string before deciding what to display is this.

-uses file_text_open_read

-loops through file_text_readln based on line range given (eg. starts at 5 ends at 7) and adds to full_string each pass

-file_text_close

-uses full_string in box parent object to decide what to display​

If there's a faster method getting from a txt file I'd like to know.
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
If there's a faster method getting from a txt file I'd like to know.
It might be faster to load it into a buffer and read it using binary functions, .txt text is usually pretty simple binary data (especially if it's ASCII-encoded rather than Shift-JIS or Unicode-encoded)
 

sylvain_l

Member
No. I'm making a text reading dialog box that word wraps and goes through multiple boxes if the text fed it is longer than 1 box. I need to know how much I can grab from a txt file at once before I impact game performance so I can have a parent object do the bulk of coding, and minimize coding in specific npcs that may talk a lot, or maybe book reading on the long end of things.
answer going to be pretty simple: the whole text ! (do it at start and your are done with that)

a book is around 60k chars, if ascii its only 1 byte per char (unicode are max 4bytes if my memory is good), that make the whole book to only be 60kb any of your background image weights much more than that. And a good mp3 music files is a few Mb too. Even with the equivalent of a hundred of books we would still only talk about 6Mb !

you are overoptimising something that really don't need any optimisation. (so if it isn't as a learning exercise, forget about batch loading the text. load it all)

what you need to look for isn't the loading of text. Its the drawing. and even not where you think.

because I assume drawing 60k char on screen would hurt (I'm not sure how much - never tried). But as you only draw at max a full screen of char, that shouldn't happen. In fact you even not draw that much char, as you only want to draw the visible text inside your textbox.

so at the end, what you should care of is the UX: ensuring drawing of text is clear as crystal to have a good reading and that the scrolling of text is smooth, fast, reliable.
(and as we have decided we could afford having the whole text in memory, that shouldn't be much of a problem except if you mess up the word wrap, etc... well in fact you shouldn't because GMS has functions to deal with that: draw_text_ext, string_width,etc - and alternatively, if the width size of your textbox is fixed, you could just already have it formated in your text file to fit in)
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
because I assume drawing 60k char on screen would hurt (I'm not sure how much - never tried).
It would hurt a ton, I can assure you :p It's basically 60,000 sequential draw_sprite() calls with some extra maths to check dimensions to make sure the next one aligns properly. (Every character is drawn separately)
 
It might be faster to load it into a buffer and read it using binary functions, .txt text is usually pretty simple binary data (especially if it's ASCII-encoded rather than Shift-JIS or Unicode-encoded)
So you load the file into a buffer. Do I still use file_text_open_read or something else once it's loaded into the buffer. How do I get a line range out of the txt file then (the only way I know to do this is file_text_readln starting from a line number adding to full_string until I reach the line range I want to grab.) What's the procedure for this when using a buffer? Were buffers added in Studio, or could you do them in GM8?
 

Yal

🐧 *penguin noises*
GMC Elder
Added in Studio, and there's a special function to read a file into a buffer as-is (which makes it a lot more convenient to load binary files now).
 
Added in Studio, and there's a special function to read a file into a buffer as-is (which makes it a lot more convenient to load binary files now).
Do I have to refer to it differently once it's in the buffer? No longer using file_text_open_read. How do I read a line out it like file_text_readln would do also, once it's in there?
 
Top