NXC word-wrapping
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
NXC word-wrapping
It have now been a half year without really doing anything to my NXT-RPG project so I decided to finally do something. I have made a few updates to the word-wrapping code, fixing a rather embarrassing bug and some few but effective optimizations.
So here is the usual screenshot:
(It didn't want to upload of some reason so I hope linking to my wordpress.com blog works...)
This brings the rendering time for the example string down from 109 to 76 msec, an improvement of about 30%. To do this I just manually converted two if and one for statement to NBC code instead of relying on the NXC compiling which just isn't good enough right now... I really hate to have to do this manually, but I guess I have no choice...
So here is the usual screenshot:
(It didn't want to upload of some reason so I hope linking to my wordpress.com blog works...)
This brings the rendering time for the example string down from 109 to 76 msec, an improvement of about 30%. To do this I just manually converted two if and one for statement to NBC code instead of relying on the NXC compiling which just isn't good enough right now... I really hate to have to do this manually, but I guess I have no choice...
- Attachments
-
- Word wrapping v0.5.1.zip
- (3.4 KiB) Downloaded 270 times
Last edited by spillerrec on 04 Feb 2011, 10:51, edited 3 times in total.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: NXC word-wrapping
Can you please post it in a zip file instead of a .7z file please?
Thanks, and have a nice day,
nxtboy III
programnxt.com
nxtboy III
programnxt.com
Re: NXC word-wrapping
Why don't you get the great free, open source 7-Zip program which scares the heck out of WinZip, WinRAR, and any other commercial compression programs out there?nxtboyiii wrote:Can you please post it in a zip file instead of a .7z file please?
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: NXC word-wrapping
zip files are supported out of the box in Windows, no need for WinZip. Not everyone is allowed or able or willing to to just install stuff on their computer, so making them install something like 7zip is just silly. Please make it a zip file, so everyone can look at it.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC word-wrapping
Sorry, I didn't really think about it as everyone have 7zip installed at the school so I don't use .zip anymore... I have added a .zip version.
muntoo, wasn't it you that originally requested a .zip version of me a long time ago? : P
muntoo, wasn't it you that originally requested a .zip version of me a long time ago? : P
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: NXC word-wrapping
Your school rocks.spillerrec wrote:<Insert: Something about a school using 7-zip>
Possibly. But I just wanted to adverti— BANNED.spillerrec wrote:muntoo, wasn't it you that originally requested a .zip version of me a long time ago? : P
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC word-wrapping
Portable apps are making a portable version available of 7-zip so you should be able to use it even on computers where you aren't allowed to install anything (as long as you use a usb-drive) if that is an issue. And it shouldn't mess with your computer either.mightor wrote:Not everyone is allowed or able or willing to to just install stuff on their computer, so making them install something like 7zip is just silly.
Windows can only handle .zip (and some windows specific formats that aren't really used if I remember correctly) and it is not that uncommon to find a .rar or tarball on the web...
Anyway, optimized it a little bit more and I'm getting pretty satisfied with the results now. It takes about 500 msec to process a 1.5KB text file and I don't expect much more to be used on the NXT. (Program is attached to the first post.)
It still don't want to upload the image, something wrong with PNG images? (edit: uploaded it on wordpress) Anyway it says 62 msec now... This benchmark is no longer sufficient as 20 msec is directly spend in the syscall to FontTextOut.
I will probably not do much more speed optimization as this would probably require me to convert the whole thing to NBC for a gain of a few milliseconds. And I'm not really interested in that...
Next step will be to go through the compiled code and check for any memory issues. Since all variables are global in NBC they are pretty much like static variables. If I want to use a 5KB file, it will be copied into the function, then a few more copies might be made in some of the NXC to NBC conversions. When the function finishes, these will not be deleted and it might make 25KB memory unavailable for other tasks... (actually, a 3KB file makes my file viewer program (which is also using this code) run out of memory right now...)
ARGHHH, it doesn't even want to post it since the file-upload failed and it tries to upload it each time I tries to post... ARGHH, here, a useless html file!
ARGHHH, I should have known, HTML not allowed! and it also said "The upload was rejected because the uploaded file was identified as a possible attack vector." : P But it seems to finally have removed it from the Upload attachment box : )
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: NXC word-wrapping
Remember: "A little refactoring can totally pwn assembly, dude! " (I heard something similar once before, but it was much more professional).spillerrec wrote: I will probably not do much more speed optimization as this would probably require me to convert the whole thing to NBC for a gain of a few milliseconds. And I'm not really interested in that...
You could make an alternate Word-Wrap function which is faster, but has some "bugs"* in sake of speed... if that's possible.
*By that, I mean less features. Ironic, I know.
A ClearWordWrap() function? Have the user call this, or specify it as an optional parameter (which is true by default, in case the user doesn't know what it does) in your word wrap function. You can always restore the memory by using:spillerrec wrote: Next step will be to go through the compiled code and check for any memory issues. Since all variables are global in NBC they are pretty much like static variables. If I want to use a 5KB file, it will be copied into the function, then a few more copies might be made in some of the NXC to NBC conversions. When the function finishes, these will not be deleted and it might make 25KB memory unavailable for other tasks... (actually, a 3KB file makes my file viewer program (which is also using this code) run out of memory right now...)
Code: Select all
unsigned long veryLargeArray[]; // isn't 32-bit data type faster on a 32-bit processor?
// allocate
ArrayInit(veryLargeArray, NULL, 4242);
// un-allocate
ArrayInit(veryLargeArray, NULL, NULL);
Code: Select all
// [adagio] for strings
string szWasteSomeMemoryForKicks = "MUHU";
repeat(4242)
{
szWasteSomeMemoryForKicks += "HA";
}
szWasteSomeMemoryForKicks += "!!!";
// clear memory
szWasteSomeMemoryForKicks = "";
I'm pretty sure the first one works, and if the second one doesn't, I blame LEGO.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: NXC word-wrapping
Not sure why png give you the errors. It does the same for me but the file type is in the same group as jpg, gif, etc.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC word-wrapping
Yeah, but it requires me to be innovative and err... that is probably not going to happen...muntoo wrote:Remember: "A little refactoring can totally pwn assembly, dude! " (I heard something similar once before, but it was much more professional).
(I wrote this in a commit half a year ago btw:)
SVN rev. 102 wrote:Minor optimizations, I don't think there is much more that can be done to the current code...
The problem is that I can't use ArrayInit( array, 0, 0 ) on some variables as these are created by the compiler and thus not available in the NXC code. (It seems that if you can guess the names the compiler will create you can do it in asm{} statements though I rather would like to avoid this...) The issue doesn't appear to be as big as I feared though.muntoo wrote:A ClearWordWrap() function? Have the user call this, or specify it as an optional parameter (which is true by default, in case the user doesn't know what it does) in your word wrap function.
So I will return focus on the main game now (once I can get it to work properly again).
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 0 guests