DEMO - High Scores: supports now unicode
-
ID: 9SGP3MNDN8 (v1.2)
ID:DM3N3MNDN83ZX53MNDN8 (DEMO - High Scores v2.1, for saving multiple tables)Check the great list of game codes for the latest version.
-
@spikey Thanks for this code, i implemented it with my own highscore drawing, everything works great except i get a huge FPS drop when using PrintHighscores in my frameloop. I need to print them every frame as my background changes constantly. the slowness seems to come from the righttrim function which calls strlen a lot. Do you by any chance know of a way to speed this up or have a version where this slowdown is fixed ? I don't immediatly see what i can do to improve it myself and i'm affraid to mess about with it much to break things related to unicode. just posting this in case you are not aware of this issue.
Thanks
-
@spikey @Gothon provided me with an alternative strLen function which improves speed a lot but the righttrim function still calls it a lot but unsure how the function can be made so it does not need to keep calling strLen everytime but atm with this function from gothon it's usable for me
Function strLen(S) Return Int(TextWidth(S) / TextWidth(" ") + .5)
-
@joyrider3774 Thanks for the feedback. Later I will have a look at the code. On a scrolling 3D background like in 'Da Bean' it worked well. If its the function you mentioned, the CPU (dark blue line in the debugger) would go up, please confirm.
In general I will check if i can just do this length calculations, once the scores change and afterwards just print the content from an array. -
@spikey yes cpu time went from 10 ms (from my own 3d background in main menu) to 60 ms when using the printhighscores function. And given frames start to drop when you go over 16.66667... ms it was noticeable a lot. I have now replaced the strlen function with gothon's version and that seems to help a great deal.if i commented out the righttrim part in the printhighscores function fps remained normal. Do note i changed Field_SIZE_SCORE to 10 as i have a max score of 9999999999 (just made sure it was high enough) and i only display 10 scores at a time
-
@joyrider3774 Hey, decent testing, cool. And by the way thanks @Gothon for helping out. With that details, I will review if additional changes can bring further improvement.
-
Just submitted v3.0. It seperates display operations from trim operations. Means 'printHighscores()' only iterates through 10 strings instead of trimming 3x10 entries. So, inserting a rank, resetting the highscores or loading new highscores takes 3 seconds because it updates 10 formatted lines of text for every highscore table. But printing them later should be done in no time. I will check when its live and update the post.
Happy if you could test this. Thank you.
Download code: EMT73MNDN8pending -
Its live now.
-
@spikey thanks man, just tested it in my game, and all fine now. Initially i was affraid of the 3 seconds thing you mentioned but i only have 3 highscore tables and it does not even take 1 second to do the actions you mentioned. Everything speed wise behaves normal as well now when viewing the highscores.
I guess if people still have problems if they have many many highscore tables they could still use gothon's function. But in my game with your new code the delay is hardly noticeable (i only see a small spike in the graphs but nothing else).
It also makes me wonder is there any reason we can not use gothon's functions or better why you did not use it ?
Thanks again :)
-
This post is deleted! -
ok no problem out of safety i'm using your function again then until we can confirm it works somehow. Thanks again
-
Ok, after a first round of tests I was not able to find any case where it was not working. The + .5 is the cool thing that rounds to the right value. Basically use it, if there is a bug you can go back to the original. I mean its from @Gothon, my guts cannot compete 😂 with a single line of code.
-
I removed my guessing comment about
textWidth()
, it works 100% according to my tests in the current FUZE version 3.0.0. For all unicode.chars. textWidth(chr(x)) for all x is the same for the same text size; or 0 for some characters, which do not draw anyhting at all.
So, good to go, I will adjust the code and resubmit.
Just a side note: the width returned, is the width, the character will obtain, including space before and after the character. TextWidth() does not return the distance between the left most to the right most pixel. E.g. "W" has almost no unused pixels to the left and right, where "i" has a lot of unused pixels to the left and right. But textWidth() returns the same value, which is perfect for aligning texts. But if you want to center a word, starting or ending with lower case, above a word in upper case, you will have to adjust the position a bit (if you use a big font size).
submission status: pending -
@spikey thanks for verifying / testing it out :) now it's all perfect :)