So heres my problem. I'm working on my text based game, but I've run into a wall in that the game runs down to 25 FPS on my system; I need to append string characters every frame in the form of a 60x26 grid; 1560 total '"X" + "X"' actions, in my fast loops. However, simply doing this character by character with normal string objects, or text blitter, will eat up the system because string appending seems to be inefficient in MMF. And because I need the columns to be split up vertically instead of horizontally, but taking chunks out of a larger string that goes horizontally, it makes it devilishly hard to parse.
Is there some extension that can take entire vertical slices out of a string array, or some way I can directly convert this array into text instead of having to read one element at a time and append it? IE its a 60x26 array of characters in the form of a string, and I need to slice off 60 different columns, only reading X number of characters from the top, not necessarily all of them, and paste that into a DIFFERENT string object.
Programming a way to do it was easy, finding a more efficient way is not...
Imagine I wanted to make a scrabble-like game. I have the entire board saved as an array or a string or whatever, I can do either way, and I want to extract the vertical words, traveling from top down. As far as I know, all the conventional methods and extensions only parse horizontally, left to right. I want to take a substring slice out of it, and export that to another string.
I can do this by doing one character at a time, but thats so inefficient it drops the games FPS by half.
I wonder if theres some workaround, like an extension that can convert letters into numbers, which I could then stack doing simple "A + B * 100 + C * 10000" and converting back into letters, since I know that direct math takes essentially no system time in MMF. Like an "A = 01, B = 02, C = 03, Z = 26" kind of thing.
http://www.yoda.arachsys.com/csharp/stringbuilder.html
If you read that, it explains why string appending is extremely inefficient; the system needs to allocate the memory of the entire string each time, instead of just adding the letter to the end. However, we don't HAVE a "stringbuilder" object, so im at a loss how to work around it.
Originally Posted by Pixelthief I wonder if theres some workaround, like an extension that can convert letters into numbers, which I could then stack doing simple "A + B * 100 + C * 10000" and converting back into letters, since I know that direct math takes essentially no system time in MMF. Like an "A = 01, B = 02, C = 03, Z = 26" kind of thing.
Though I don't understand the problem you're facing (the first post), this problem does have a solution. Since you can convert letters to ascii values with string parser 2. Unless I misunderstood this post too
tried that, but as the string parser only does 1 character at a time, I'd need to append them again. And the text blitter has a built in append function thats *slightly* more efficient, but didn't work. However, the guys on the clickteam forum pointed out that I can use the Binary object to convert the string into bytes, append the bytes, and convert back, which is working like a charm. So solved the problem.
Originally Posted by Pixelthief I've got a good way to put it.
Imagine I wanted to make a scrabble-like game. I have the entire board saved as an array or a string or whatever, I can do either way, and I want to extract the vertical words, traveling from top down. As far as I know, all the conventional methods and extensions only parse horizontally, left to right. I want to take a substring slice out of it, and export that to another string.
I can do this by doing one character at a time, but thats so inefficient it drops the games FPS by half.
lol; 13 years for an answer? Seems about right for DK.
Fastloops aren't a great option if they account for a bulk of your events. All fastloops run before a graphical update, which means the more fastloops you have going in a single frame, the lower your FPS.
Accessing any kind of external file source or importing data from elsewhere inside of a fastloop will make it run like complete mud. If you need to import data, do that at the start of frame, outside of a fastloop. Load the data into control objects you can work with directly.
It'd be a little less direct, but you could probably simplify this a bit by having a single list object with one horizontal line from your array on each line in the list. Append changes to the list object using Mid$. Once all changes are made, read the array and display it.
If you need to change a bunch of values every frame, tackle as much of that change in as few fastloops as possible. In the past, I've created interpreters that operate off of a list object and tokenized values built around an X|Y|Z pattern where X is the horizontal position of the character, Y is the vertical row that needs editing, and Z is the new string or value to be updated. A single fastloop can then be run an amount of times equal to the number of entries in the list object, which would force all changes to occur in a single display frame; probably without much noticeable lag.
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?