Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you make turing do two things at once?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kharybdis




PostPosted: Fri Apr 18, 2008 12:42 pm   Post subject: How do you make turing do two things at once?

well.. is it even possible?

i know there must be some ways to trick turing to do this.
Sponsor
Sponsor
Sponsor
sponsor
Carey




PostPosted: Fri Apr 18, 2008 12:49 pm   Post subject: RE:How do you make turing do two things at once?

using processes you can, but they are unpredictable and should be avoided. the other alternative is a class-based system where every object is a class and has a procedure called update or such. you would call update on every object, then update the screen. using the class based style it only looks like the program is doing things at the same time, but in actuality it is updating everything separately then drawing all the updates to the screen. Sorry if thats not very clear, just ask if you don't understand.
Tony




PostPosted: Fri Apr 18, 2008 2:00 pm   Post subject: RE:How do you make turing do two things at once?

depends on what you're asking. In the vast majority of cases "doing two things" just means doing one thing after another.

With an exception of multithreading, where you work with two separate CPUs, the rest is just simulation of such.

Most often, something like
Turing:

loop
   frame += 1
   do_one(frame)
   do_two(frame)
end loop

will do what you want.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
andrew.




PostPosted: Fri Apr 18, 2008 8:26 pm   Post subject: Re: How do you make turing do two things at once?

Most of the time, you can include everything into the main loop. It won't technically do two things at once, but will process the two things then draw them at once. For example:

Turing:
setscreen ("graphics:offscreenonly") % This makes Turing process everything then draw it all at once View.Update is written.

loop
    Your_First_Thing
    Your_Second_Thing
    View.Update
end loop


Also, if you have more than one, you can keep it more uncluttered by doing this:

Turing:
setscreen ("graphics:offscreenonly")

procedure Your_First_Thing
    Do_Your_First_Thing
end Your_First_Thing

procedure Your_Second_Thing
    Do_Your_Second_Thing
end Your_Second_Thing

loop
    Your_First_Thing
    Your_Second_Thing
    View.Update
end loop


This is how I would do it, but if this is not the "proper" form, Tony just tell me and I will never use this again and will never suggest this again.
Mackie




PostPosted: Sat Apr 19, 2008 3:11 am   Post subject: Re: How do you make turing do two things at once?

andrew. @ Fri Apr 18, 2008 8:26 pm wrote:
It won't technically do two things at once, but will process the two things then draw them at once.


Technically it's just drawing both things so quickly that it looks like it's the same time, the View.Update makes it so we only update the screen when we want to. Giving the illision it's being drawn at the same time. Not trying to be a jerk here, just trying to be accurate.
CodeMonkey2000




PostPosted: Sat Apr 19, 2008 10:01 am   Post subject: RE:How do you make turing do two things at once?

No what View.Update does is it enables double buffering. With double buffering you have one surface that represents the screen. You blit (or draw) your stuff on this surface, and when you are done you blit this surface to the screen. The surface only remembers what the screen looks like before displaying it, it's not drawing two things at once. All the pixel values are known by this point.
Tony




PostPosted: Sat Apr 19, 2008 12:16 pm   Post subject: Re: How do you make turing do two things at once?

andrew. @ Fri Apr 18, 2008 8:26 pm wrote:
This is how I would do it, but if this is not the "proper" form, Tony just tell me and I will never use this again and will never suggest this again.

Andrew, you are quite correct in your approach. You'll notice that the structure is similar to what I've posted above. Good call on View.Update. Though I think it's the frame/step-of-the-loop concept that should be highlighted here, this would allow for simultaneous animation of multiple procedures.

In other words, you get a computer to "do two things at once" by structuring your code to "do two things inside a loop".
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: