Reading a text file into a guiMLTextCtrl - slow!
by Ian Omroth Hardingham · in Torque Game Engine · 11/25/2009 (10:54 am) · 6 replies
Hey guys.
I'm using this code:
To read a 37kb text file into a guiMlTextCtrl. This has a noticable pause of about a second - any suggestions?
Thanks,
Ian
I'm using this code:
function readTextFromFileToML(%file, %retHeader, %ml)
{
%fo = new FileObject();
%fo.openForRead(%file);
%ml.setText("");
if (%retHeader)
{
$getTextRetHeader = %fo.readLine();
}
while(!%fo.isEOF())
%ml.addText(%fo.readLine() @ "\n", false);
%fo.delete();
}To read a 37kb text file into a guiMlTextCtrl. This has a noticable pause of about a second - any suggestions?
Thanks,
Ian
About the author
Designer and lead programmer on Frozen Synapse, Frozen Endzone, and Determinance. Co-owner of Mode 7 Games.
#3
11/25/2009 (11:48 am)
Then throttle it I guess, what is the max size limit? Whenever the length of %txt gets to a specific size, addText.
#4
11/25/2009 (11:49 am)
I did actually try that too just now, and if anything it made the pause slightly worse. I may need to add a loadFromFile method directly within guiMlTextCtrl.
#5
11/25/2009 (9:49 pm)
37kb is pretty big for a plain text file, isn't it? I'd suggest adding a method like you said, if you really need to load that much text at once. No chance to split it up and have a 'continue' button when you get to the end of each segment?
#6
11/26/2009 (12:41 pm)
What version of Torque are you dealing with here? I have observed and fixed this behavior in Torque 1.3. However, in 1.4+ (after the addition of unicode support) things are handled quite differently; and while the problem may be much the same, my fix could not be directly applied.
Torque Owner James Greenhalgh
function readTextFromFileToML(%file, %retHeader, %ml) { %fo = new FileObject(); %txt = ""; %ml.setText(""); if ( %fo.openForRead( %file ) ) { while ( !%fo.isEOF() ) { %line = %fo.readLine(); %txt = %txt NL %line; } %fo.close(); } %fo.delete(); %ml.setText(%txt); }