NXC word-wrapping

Discussion specific to projects ideas and support.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

NXC word-wrapping

Post by spillerrec »

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:
Image
(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/
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC word-wrapping

Post by nxtboyiii »

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
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC word-wrapping

Post by muntoo »

nxtboyiii wrote:Can you please post it in a zip file instead of a .7z file please?
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?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC word-wrapping

Post by mightor »

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
| 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)
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC word-wrapping

Post by spillerrec »

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
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC word-wrapping

Post by muntoo »

spillerrec wrote:<Insert: Something about a school using 7-zip>
Your school rocks.
spillerrec wrote:muntoo, wasn't it you that originally requested a .zip version of me a long time ago? : P
Possibly. :) But I just wanted to adverti— BANNED.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC word-wrapping

Post by spillerrec »

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.
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.
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.)
Image
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/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC word-wrapping

Post by muntoo »

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...
Remember: "A little refactoring can totally pwn assembly, dude! :lol: " (I heard something similar once before, but it was much more professional).
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. :D
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...)
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:

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);
or

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.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC word-wrapping

Post by mightor »

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
| 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)
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC word-wrapping

Post by spillerrec »

muntoo wrote:Remember: "A little refactoring can totally pwn assembly, dude! :lol: " (I heard something similar once before, but it was much more professional).
Yeah, but it requires me to be innovative and err... that is probably not going to happen...

(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...
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.
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.
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/
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests