Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
23 May, 2013, 00:27:20 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Running Line Commands from a String -  (Read 487 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« on: 18 September, 2011, 16:02:15 »
0

I'm writing a BASIC program that does lots of sprite drawing with lines, and I was hoping to optimize it by putting the Line( commands for each sprite into a string, and then simply using expr(String wherever the sprite was needed. Unfortunately, the expr( command seems to not work with commands that don't return answers. It would be very useful if there were another way (Or if someone had a better idea) to achieve the desired result. (I would prefer to stick with using the Line( commands)

Thanks!  Grin

EDIT: Here's a more visual explanation:

This bulky thing repeated multiple times:

1
2
3
4
Line(6X,6Y,6X,6Y+5
Line(6X,6Y+5,6X+5,6Y+5
Line(6X+5,6Y+5,6X+5,6Y
Line(6X+5,6Y,6X,6Y

Versus

At the beginning:

1
"Line(6X,6Y,6X,6Y+5):Line(6X,6Y+5,6X+5,6Y+5):Line(6X+5,6Y+5,6X+5,6Y):Line(6X+5,6Y,6X,6Y"->Str1
And then later in the program:

1
expr(Str1
« Last Edit: 18 September, 2011, 16:11:02 by Blue72 » Logged
Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 21 May, 2013, 21:08:05
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Total Post Ratings: +428

View Profile
« Reply #1 on: 18 September, 2011, 16:41:59 »
0

I can't think of a way to do just that, but can you explain how that would help optimize your program?  Maybe it's because I'm a noob at Ti-Basic Smiley, but the way I'm looking at it, you add at least 7 bytes (maybe more) to your program, and expr( itself takes time
Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« Reply #2 on: 18 September, 2011, 16:51:40 »
0

Well, there are multiple places in the program where each sprite is drawn, and rather than have subprograms or repeat those large blocks, I'd like to have something short and clean.

These drawing events are also mostly nested in conditionals, and I imagine there would be some speed benefit from the program not having to run over large blocks of code it isn't using at the moment.

In general, it would make the main loop of the game much cleaner and somewhat faster, as well as some size reduction by shrinking repetitive code.
« Last Edit: 18 September, 2011, 16:53:37 by Blue72 » Logged
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #3 on: 18 September, 2011, 16:56:38 »
0

If you have to use it more than four times or so, you could try doing it like this:

While 0
Lbl L
Line(6X,6Y,6X,6Y+5
Line(6X,6Y+5,6X+5,6Y+5
Line(6X+5,6Y+5,6X+5,6Y
Line(6X+5,6Y,6X,6Y
End

<program start>

Then, whenever you need to draw those lines you just do this:
For(A,0,1) // parentheses for speed
If not(A
Goto L
End


It is by no means the most elegant solution, but it would still work.  You could also try using subroutines, but this would add an additional program to your project. Undecided
« Last Edit: 18 September, 2011, 16:57:30 by ztrumpet » Logged

Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« Reply #4 on: 18 September, 2011, 16:59:13 »
0

I thought about that, but I am a little reluctant to have it jumping around a lot, as that just contributes to the whole "time spent running over unused code" thing.  Tongue

I do appreciate the suggestion, however, and I may end up doing something similar.

It's quite frustrating that one of the few situations where expr( would be ideal is also one where it doesn't work.
Logged
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #5 on: 18 September, 2011, 17:18:30 »
0

The best thing I can think of doing is something like this at the start:
"6X+5->u
"6Y+5->v


Then doing this when you need to display the lines:
Line(6X,6Y,6X,v
Line(6X,v,u,v
Line(u,v,u,6Y
Line(u,6Y,6X,6Y


Edit: I was fed up with my awful grammar, so I changed it. Tongue
« Last Edit: 18 September, 2011, 17:25:02 by ztrumpet » Logged

Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« Reply #6 on: 18 September, 2011, 17:26:45 »
0

I like that, but I think it would be better to do it as:

1
2
3
4
5
6
6X->U
6Y->V
Line(U,V,U,V+5
Line(U,V+5,U+5,V+5
Line(U+5,V+5,U+5,V
Line(U+5,V,U,V

Since some of the sprites are more complicated, and require different amounts to be added and subtracted.

I still hope to find a way to only have to write the commands once, though.
Logged
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #7 on: 18 September, 2011, 17:31:36 »
0

Almost.  You have to remember that "6X" and "u" take the same amount of space because "u" is a two byte token.  However, you can change the values of u and v whenever you want.  If you want four dynamic corners of your box, you could use r1 - r4, with one for each corner.  That could lead to some really interesting box manipulation. Azn
Logged

Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« Reply #8 on: 18 September, 2011, 17:36:35 »
0

True, but I like to prioritize speed over size. Though 6X is a very simple calculation, having it performed only once could see a minor speedup.

As for the box corners, that seems like it would provide less speedup and trim little size.

EDIT:  Tongue That made it sound like I didn't appreciate its usefulness. It would be useful for manipulating boxes, but the sprites in my program are all the same size.
« Last Edit: 18 September, 2011, 17:51:32 by Blue72 » Logged
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #9 on: 18 September, 2011, 22:20:26 »
0

Ah, I see that you misunderstood me.  Check this out:

(The u and v are from [2nd] [7] and [2nd] [8].)


* Screenie110918.gif (178.28 KB, 192x128 - viewed 47 times.)
Logged

Blue72
LV2 Member (Next: 40)
**
Offline Offline

Gender: Male
Last Login: 25 May, 2012, 00:34:13
Date Registered: 18 September, 2011, 15:56:14
Posts: 20

Topic starter
Total Post Ratings: +3

View Profile
« Reply #10 on: 18 September, 2011, 23:21:48 »
0

Intriguing, so they're some kind of expression-storing variable?

(I am clearly a newbie)
« Last Edit: 18 September, 2011, 23:24:11 by Blue72 » Logged
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #11 on: 18 September, 2011, 23:27:11 »
0

Intriguing, so they're some kind of expression-storing variable?
Yup.  They're actually just like Y1 through Y0, only for Sequential mode instead of Function mode.  Any of the variables in [Vars] [Right] will do the exact same thing.  u, v, and w are normally used because they look the nicest, are the easiest to access, and users rarely have to use sequential mode.  (You can change the graphing mode by pressing Mode and scrolling down a few lines).
« Last Edit: 18 September, 2011, 23:27:24 by ztrumpet » Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.236 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.