
-----------------------------------
Cervantes
Sat Feb 19, 2005 11:29 am

Why You Should Avoid Processes
-----------------------------------
For the somewhat new programmer, using processes may seem almost manditory.  You may want to do two things simultaneously and immediately think, "I can use a process for that!"  But when you think that, you're making a big mistake.  
In Turing, processes are terrible.  They should be avoided at all costs (really, the only time they should be used is for playing music, but Turing 4.0.5 makes it so we don't even need them for that).  
"Why are processes so terrible," you ask?  Well, take a look at the example in the help file:

process greetings (word : string)
    loop
        put word
    end loop
end greetings

fork greetings ("Hi")
fork greetings ("Ho")

Run it.  After a second, stop it.  You should see a very inconsistant pattern on the screen.  This is because the processes execute at different (almost random, it seems) speeds.  It's not as though greetings ("Hi") executes once, then greetings ("Ho") once, then once again for greetings ("Hi"), etc.  No, Turing's processes don't work the way you want them to.  
"But I don't care if they work at different rates!", you yell.   
Aah, you should.  Lets say we've got two objects, and we want to move them across the screen.  object1 has a speed of 1, and object2 has a speed of 2.  Both must travel the same distance.  Using processes, object 2 will likely not reach its destination twice as fast as object1.  Rather, it will reach its destination approximately twice as fast as object1.  This may not seem like a big issue, but it is.  You never know how your program is going to behave, because the processes run in a random fashion. 

Actually I just discovered another bad thing about processes: you can't use "var" parameters.  ie. you can't go 
process move (var foo : string)

We'll let Hacker Dan finish this for us:

Process can be good but you have to understand how they work and turing has limited conortl over them. Since turing has no way to set proity of a process all you know is that the code may run at some time. So baliky unless you got a dual CPU system a process will run lines of code in it at basicly random times durning the excution of your progame. If it dose not mater when they run then it could be good to use them but it gives you less conortl over things.



In conclusion, don't use processes.  They are evil.  If you choose to use them, fine, but you are only hurting your own program.  You'll probably end up spending hours down the line reworking everything to eliminate the processes.


I'm no expert on this matter, but so many people have been trying to/using processes lately I felt something had to be done.  Any elaboration on this matter, or more convincing/moral support, is welcome.

-Cervantes

-----------------------------------
cycro1234
Sat Feb 19, 2005 12:21 pm


-----------------------------------
Wow, thanks for that tutorial! 

But If I shouldn't use processes to make 2 things run at the same time, I use instead? Like, what if I'm making a game and I want the person to shoot and move at the same time. How will I work that out? Or what If i want to animate 2 objects at the same time doing different actions unrelated to each other.

-----------------------------------
Martin
Sat Feb 19, 2005 1:04 pm


-----------------------------------
No. Your main loop should look like this:

loop
   if up arrow pressed then
      playery  += 1
   end if
   if left arrow pressed then
      playerx += 1
   end if
   if ...
      ...
   end if
   for i : 1 .. numBullets
      updatebulletposition(i)
   end for
   drawScene %player, bullets, etc.
end loop

The absolute only time that you should ever use a process is when you are doing sound.

-----------------------------------
cycro1234
Sat Feb 19, 2005 1:08 pm


-----------------------------------
Ok. Thanks.

-----------------------------------
Cervantes
Sat Feb 19, 2005 1:31 pm


-----------------------------------
Basically, you stick it all in the same loop.  As to how to do it (well, it's really easy, but if you're stuck thinking in terms of processes, it might be a little difficult), the easiest way to show you how is with examples.

Like, what if I'm making a game and I want the person to shoot and move at the same time. 
There's an easy one.  Shooting and moving is the same, in that both rely on input from the keyboard (or mouse).  

var x, y := 100

var keys : array char of boolean

proc fire
    %code
end fire
loop

    Input.KeyDown (keys)
    if keys (KEY_CTRL) then
        fire
    end if
    if keys (KEY_UP_ARROW) then
        y += 1
    end if
    if keys (KEY_DOWN_ARROW) then
        y -= 1
    end if
    if keys (KEY_RIGHT_ARROW) then
        x += 1
    end if
    if keys (KEY_LEFT_ARROW) then
        x -= 1
    end if

    cls
    drawfilloval (x, y, 5, 5, black)
    delay (10)

end loop

All you have to do is make your fire procedure.  How you do that is related to your second question.

Or what If i want to animate 2 objects at the same time doing different actions unrelated to each other.

There is always something that is related.  Always.  What is related is time.  Just as my fingers move to type this, our solar system is hurtling around the Milky Way at 900 000km/h.  We have two objects (my fingers, and the solar system) whose motions pretty well don't affect one another, but are nonetheless related through time.  Every hour that my fingers move, the solar system travels 900 000km.  Or, every hour that my fingers don't move, the solar system travels 900 000km.  No matter what, the motions of the two objects are joined by time.
Because the motions are joined by time, we want to avoid using a process.  Using a process would be like randomly accelerating time for one object, and slowing time for another.  By using just one loop, however, we can keep time going at a constant pace.
Below you'll find three programs.  The first is really all that I need to show how you do this without using processes.  The second program is the same code, but much neater.  The last uses many objects.  :)


View.Set ("offscreenonly")
var ballx := 0.0
var bally := 50.0
var ballvx := 2
var ballvy := 0.6

var starx := 50.0
var stary := 150.0
var starvx := 2.5
var starvy := -0.3

loop
    ballx += ballvx
    bally += ballvy
    starx += starvx
    stary += starvy

    cls
    Draw.FillOval (round (ballx), round (bally), 15, 15, brightred)
    Draw.FillStar (round (starx - 15), round (stary - 15), round (starx + 15), round (stary + 15), brightblue)
    %the 15 is half the width and half the height.  Remember the star is drawn with x1, y1, x2, y2
    View.Update
    delay (15)
end loop


Here's the same thing, but neater.  Types are always nice for keeping things organized.

View.Set ("offscreenonly")
type obj :
    record
        x : real
        y : real
        vx : real
        vy : real
    end record

var ball : obj
ball.x := 0
ball.y := 50
ball.vx := 2
ball.vy := 0.6

var star : obj
star.x := 50
star.y := 150
star.vx := 2.5
star.vy := -0.3

loop
    ball.x += ball.vx
    ball.y += ball.vy
    star.x += star.vx
    star.y += star.vy

    cls
    Draw.FillOval (round (ball.x), round (ball.y), 15, 15, brightred)
    Draw.FillStar (round (star.x - 15), round (star.y - 15), round (star.x + 15), round (star.y + 15), brightblue) 
            %the 15 is half the width and half the height.  Remember the star is drawn with x1, y1, x2, y2
    View.Update
    delay (15)
end loop


The next code takes the motion section (the ball.x += ball.vx etc. part) and sticks it into a procedure.  Then it uses that procedure many times, for there are many more objects in this one. :)


View.Set ("offscreenonly")
type obj :
    record
        x : real
        y : real
        vx : real
        vy : real
    end record

var ball : array 1 .. 30 of obj
for i : 1 .. upper (ball)
    ball (i).x := Rand.Int (0, maxx)
    ball (i).y := Rand.Int (0, maxy)
    ball (i).vx := Rand.Int (-3, 3)
    ball (i).vy := Rand.Int (-3, 3)
end for

procedure moveObj (var obj : obj)
    obj.x += obj.vx
    obj.y += obj.vy
end moveObj

loop
    
    %Move all the balls
    for i : 1 .. upper (ball)
        moveObj (ball (i))
    end for


    cls
    
    %Draw all the balls
    for i : 1 .. upper (ball)
        Draw.FillOval (round (ball (i).x), round (ball (i).y), 15, 15, brightred)
    end for
    View.Update
    delay (15)
end loop


Hopefully that wasn't hard to get through.  

To recap: don't use processes, because doing so means you're screwing with time.  Use a single main loop.  The concept is no different than using processes. You just have to keep your main loop structured nicely.  (ie. keep all your drawing at the end, all your input at the beginning, and all your variable manipulation in the middle).

-Cervantes

-----------------------------------
Tony
Sat Feb 19, 2005 1:31 pm


-----------------------------------
I'd like to add that if both processes use the same global variable, the results will be disastrous.

You essensially throw your code flow into a blender, mix it up and say. "Here I have a bunch of lines of code. They are in no particular order. If the computer happens to pick the right order - the results will be as expected. Otherwise I have no idea what might happen"

-----------------------------------
cycro1234
Sat Feb 19, 2005 1:45 pm


-----------------------------------
Ok, thanks a lot for that guys! I get it a lot more now. :D 

But if processes are so useless, why were they added in Turing? Only to make music run?

-----------------------------------
Cervantes
Sat Feb 19, 2005 3:33 pm


-----------------------------------
Processes (threads?) are not a feature of Turing alone.  Many other languages have them, though I believe their processes actually work orderly, not randomly.  I can only assume Holtsoft tried to give Turing what those other languages have.  Boy did they fail...

-----------------------------------
Flikerator
Sat Feb 19, 2005 6:00 pm


-----------------------------------
For my final project (Pong) I used like 6 forks. Ai, paddle, paddle2 (2 player), music, lives, and ball. I wouldn't do anything like that cause now I am not so nubish anymore. 

I pulled a 90 out of my first year with that sort of programming lolz. 


the only time they should be used is for playing music, but Turing 4.0.5 makes it so we don't even need them for that

What do you mean, how do we play music without using a process? This will help greatly in Zombie Mass'Acres :D

-----------------------------------
rizzix
Sun Feb 20, 2005 12:40 am


-----------------------------------
hmm i dont get it.. what do u guys mean by random? the lines of code executed with the process code-block is random? (quite impossible) if so, never use processes. if not.. there is nothing wrong with the processes. they are just fine, just that you guys are not used to concurrent programming.

-----------------------------------
md
Sun Feb 20, 2005 1:17 am


-----------------------------------
Processes (threads?) are not a feature of Turing alone.  Many other languages have them, though I believe their processes actually work orderly, not randomly.  I can only assume Holtsoft tried to give Turing what those other languages have.  Boy did they fail...

Threads (as processes are really known) are actually a feature of the OS (windows), or very low level code (linux can use kernel threads and user threads [i think], basically their only different in what does the schedualing). However your wrong in your assumption that they are run in an orderly fasion. 

Say we have two threads, A and B. Thread A will be run for a given time (a very small ammount of time...), then thread B will be given a chance.
 
The problem is when unshedualed things happen, say a keystroke. The OS must then switch from the thread to the keyboard handling process which will then run until it is done or something else interupts it. Once the keyboard process is done the OS returns execution back to the next ready process (not nessarilly ours). The next time it gets arround to running our process it will probably run the next thread in the queue (which, again, will probably not be the one that was interupted).

Thus something as trivial as an interupt can cause any thread to lose some of it's execution time. And since interupts are generated by almost all hardware and at a fairly high rate, execution times are not perfectly balanced.

Of course modern threads can be prioritized, or blocked (set not to run), so in practice threads are actually are very usefull tool. Although I wouldn't recomend creating a lot of threads, as each thread adds overhead, and creating one for such a simple task as an animation is frivilous.

-----------------------------------
cycro1234
Tue Feb 22, 2005 4:55 pm


-----------------------------------
I have this code to shoot and move, but it's not working:


View.Set ("offscreenonly")

var chars : array char of boolean
var x, y : int := 100
forward proc movement

proc shoot (var y : int)
    loop
        y := y + 1
        drawoval (x+35,y-1,10,10,0)
        drawoval (x+35,y,10,10,7)
        drawoval (x-35,y-1,10,10,0)
        drawoval (x-35,y,10,10,7)
        View.Update
        exit when y + 20 > maxy
        movement
    end loop
end shoot

body proc movement
    loop
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) and y + 64 < maxy then
            y := y + 1
        elsif chars (KEY_DOWN_ARROW) and y > 0 then
            y := y - 1
        elsif chars (KEY_LEFT_ARROW) and x > 0 then
            x := x - 1
        elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
            x := x + 1
        elsif chars (KEY_CTRL) then
            shoot (y)
        end if
        cls
        drawfilloval (x,y,20,20,7)
        View.Update
    end loop
end movement

loop
    movement
end loop


Hold ctrl to shoot and move with arrow keys.

I thought that if I called movement in the procedure shoot then I could shoot and move at the same time. It doesn't work! The y value that I need for the bullet interferes wit the y value of the position of the circle. After shooting the bullets, the y value of them is stored and is used to draw the cirle in a place i do not need. Any ideas how to fix?

-----------------------------------
jamonathin
Tue Feb 22, 2005 8:13 pm


-----------------------------------
You have to give the bullet's their own variables.  'x' and 'y' are already used by the "shooter" and so by adding to the y-value, you're changing where the shooter is.  This is what i came up with. .

View.Set ("offscreenonly")

var chars : array char of boolean
var x, y, bullety, bulletx : int := 100
var shot : int := 0
forward proc movement

proc shoot
    loop
        shot := 1
        bullety += 1
        exit when bullety + 20 > maxy
        movement
    end loop
    shot := 0
end shoot

body proc movement
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y + 64 < maxy then
        y := y + 1
    elsif chars (KEY_DOWN_ARROW) and y > 0 then
        y := y - 1
    elsif chars (KEY_LEFT_ARROW) and x > 0 then
        x := x - 1
    elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
        x := x + 1
    end if
    if chars (KEY_CTRL) and shot = 0 then
        bullety := y
        bulletx := x
        shoot
    end if
    cls
    if shot = 1 then
        drawoval (bulletx + 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx + 35, bullety, 10, 10, 7)
        drawoval (bulletx - 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx - 35, bullety, 10, 10, 7)
    end if
    drawfilloval (x, y, 20, 20, 7)
    View.Update
end movement

loop
    movement
end loop

The shooter moves a little slower while the bullets are being fired however.  If you want, you can have a variable represent the displacement of the shoot (y + 1 to y + dif), and when the ball is being fired, dif will equal 2, but outside the loop, dif will equal 1, your choice.   :?

-----------------------------------
cycro1234
Tue Feb 22, 2005 10:06 pm


-----------------------------------
K got it. Thx.

-----------------------------------
HyperFlexed
Wed Feb 23, 2005 10:04 pm


-----------------------------------
Never looked into it but I believe Turing has a way to set the priorities of processes. I must agree though, many people failed my compsci class because they used them innapropriately.

One guy made this game where red and black blocks float across the screen and you gotta hit the red and avoid the black. Not only did he use processes, he made one process for each block rather than passsing in the values (I suppose it'd be redundant eather way).

The biggest thing to understand is a computer goes so fast, you don't have to worry to much about the order of how things are done. And if you are using View.Update and getting everything at once, your user won't get screwed, and your program will be alot faster for it.


that reminds me, I should post my final project. I made tetris, hehe.

-----------------------------------
Martin
Tue Mar 01, 2005 2:45 pm


-----------------------------------
No. No processes, ever (except for music). I don't care what you are making: processes will only make your code junky.

-----------------------------------
StarGateSG-1
Tue Mar 01, 2005 4:34 pm


-----------------------------------
I am Sick and tried of all you people bashing processes becasue they are random, with that said they are. But if you are trying to save lines in a program and say you have a guiclear that you don't wnat to have to call again and again and alos not call ina  procedure becasue they run by themselves and not with other parts. So yes procedures are good for like moving a character and stuff, but if you have the same command 400 times in your program make a process of it. For example if you have a press any key, which is 100's of times bigger youi don't wnat to have to right the 5 or 6 lines again and again. 
Now you say well their is copy and paste. 
How long do you think it takes to compile a program with 500++ extra lines??

-----------------------------------
[Gandalf]
Tue Mar 01, 2005 5:10 pm


-----------------------------------
Now you say well their is copy and paste. 

I don't think anyone would say that  :? .  Personally, I have never had to use proccess' except for music - just stick to procedures.

-----------------------------------
Bacchus
Tue Mar 01, 2005 6:38 pm


-----------------------------------
processes are random and dont go in the order you specify. using them will make you a monkey, which is accually unfair to monkeys b/c thier really smart but they dont speak english, the speak monkey language (lol). ne who procedure are much better and even if your calling the proc many many times its still better (and what did you even mean by that, use a process?! it would run continuasly (im assuming u meant in a loop, if not it would still be like a proc) and then how would you nat have it run when you wanted to) the point of a proc is to save space you could do that very efficiently with parameters while a process is meant to just run at the same time as the main program. and who even cares if the proc doesnt run the same time as the main program? i mean cmon do you really notice the delay it takes to go completly thu a proc?

-----------------------------------
person
Tue Mar 01, 2005 7:10 pm


-----------------------------------
processes are random and dont go in the order you specify. using them will make you a monkey, which is accually unfair to monkeys b/c thier really smart but they dont speak english, the speak monkey language (lol). 

omg!...lol u got that off of CCC

I am Sick and tried of all you people bashing processes becasue they are random, with that said they are. But if you are trying to save lines in a program and say you have a guiclear that you don't wnat to have to call again and again and alos not call ina procedure becasue they run by themselves and not with other parts. So yes procedures are good for like moving a character and stuff, but if you have the same command 400 times in your program make a process of it. For example if you have a press any key, which is 100's of times bigger youi don't wnat to have to right the 5 or 6 lines again and again. 
Now you say well their is copy and paste. 
How long do you think it takes to compile a program with 500++ extra lines??

i dont understand y u cant use a procedure instead i mean who cares if it runs on its own...like the user is gonna notice

-----------------------------------
Bacchus
Tue Mar 01, 2005 7:32 pm


-----------------------------------
yes exacly

and yes it did come from CCC lol that was a funny question and had me confused for a bit. funny thing was i screwed up question 3 sooo much. i was like over thinking it and started to use flexible arrays and more complex things and completly lost my train of thought redid it a couple times to no avail came close started to go crazy and twitchy (i do that quite often) and went to the next question lol

-----------------------------------
person
Tue Mar 01, 2005 8:46 pm


-----------------------------------
just wondering did u get q4?

-----------------------------------
Bacchus
Tue Mar 01, 2005 9:17 pm


-----------------------------------
we're not really suposed to be talking about this but i wont reviel much. i was spacing out and kept reading the same thing over and over so i got fed up and just made the accual picture and had a guy walk around till he stopped and i could figure out where he was lol

-----------------------------------
Martin
Wed Mar 02, 2005 10:42 am


-----------------------------------
Here's a challenge, open for anyone.

Write a program using processes that I can't improve by getting rid of the processes. If you can do this, I'll give you 1000 bits.

Go. Only rule is no music.

-----------------------------------
StarGateSG-1
Wed Mar 02, 2005 12:28 pm


-----------------------------------
I will take your challenge and I will beat you. 
But one questions who's is to say what is better :?: 
obvious you nor me can decide and i don't think this is a impartial person on this forum.

But we will deal witht that later.

-----------------------------------
Tony
Wed Mar 02, 2005 1:26 pm


-----------------------------------
But one questions who's is to say what is better :?:
We'll run both programs though tests. Execution times, glitches, etc.

Btw, Martin:

Music.PlayFileReturn ( fileName : string )

Unlike Music.PlayFile, the Music.PlayFileReturn procedure should not be called in a separate process. Instead, the procedure returns immediately. This makes Music.PlayFileReturn easier to use, but makes it unsuitable for playing a set of files sequentially.


-----------------------------------
Martin
Wed Mar 02, 2005 2:14 pm


-----------------------------------
Yeah, I haven't used turing in a while suffice to say.

-----------------------------------
Mazer
Wed Mar 02, 2005 3:14 pm


-----------------------------------
What's wrong with what Martin said? Music.PlayFileReturn just calls a process, so it makes sense not to allow music in the competition.

-----------------------------------
person
Wed Mar 02, 2005 3:37 pm


-----------------------------------

process a
    put "hi"
end a
process b
    fork a
    put "ho"
end b
loop
    fork b
end loop


puts random hi and ho (dont know if it counts though)

-----------------------------------
Tony
Wed Mar 02, 2005 4:45 pm


-----------------------------------
Damn it, processes are so freaking hard to benchmark :? Here're the two programs with benchmarks incorporated. I hope everybody finds them fair.

processes

var bench : int := 0
process a
    put "hi"
    bench += 1
end a
process b
    fork a
    put "ho"
    bench += 1
end b
loop
    fork b
    exit when bench >= 100
end loop
put ""
put "Bench :: ", bench
put Time.Elapsed

Results:: 100 outputs in ~1800

no processes

var bench : int := 0
loop
    if (Rand.Real > 0.5) then
        put "hi"
    else
        put "ho"
    end if
    bench += 1
    exit when bench >= 100
end loop
put ""
put "Bench :: ", bench
put Time.Elapsed

Result:: 100 outputs in ~855..

Results of this case study... vertually identical output, but processes take up twice as long. Also notice that in processes, even after the benchmark has been reached and loop exited, "hi/ho" output still went in between the results. Glitches are not undocumented features.

so.. ~1800 milliseconds for processes vs. ~850 without.

Anyone else?

-----------------------------------
StarGateSG-1
Wed Mar 02, 2005 5:20 pm


-----------------------------------
I am not going to do this not becaus ei can't but because you guys don't see were i am coming from.
A process is like a method in java or C++ not the way you guys are using it.
All a process is the same hard code for a C++ method but made simple for learning!
It is nothing more !
That is were i'm cming from every one else is doing something the first program in topic.

-----------------------------------
Cervantes
Wed Mar 02, 2005 7:00 pm


-----------------------------------
I am not going to do this not becaus ei can't but because you guys don't see were i am coming from.

Then do it, and show us where you are coming from.  I'd like to see it done. :)

-----------------------------------
Andy
Wed Mar 02, 2005 7:04 pm


-----------------------------------
I am not going to do this not becaus ei can't but because you guys don't see were i am coming from.
A process is like a method in java or C++ not the way you guys are using it.
All a process is the same hard code for a C++ method but made simple for learning!
It is nothing more !
That is were i'm cming from every one else is doing something the first program in topic.
o really.. show us some c code? cuz well im a c programmer and right now, you're making absolutely no sense... in java a method is just simply a member function of the class

-----------------------------------
Martin
Wed Mar 02, 2005 9:00 pm


-----------------------------------
1000 bits.... :p

-----------------------------------
StarGateSG-1
Thu Mar 03, 2005 8:27 am


-----------------------------------
I guess I should have mentioned this but i kinda gave up programing for lent so I can only post source for programs I have and i don't have any ones right now. (I delete most of them to make room for C++) but i can tell you that look up processes in turing help and look at priroties!

-----------------------------------
Tony
Thu Mar 03, 2005 9:47 am


-----------------------------------
look up processes in turing help and look at priroties!
priorities appear to be interesting.. I'd have to think a bit more about their proper implemintation and will most likely be writing a tutorial this week.

-----------------------------------
Martin
Thu Mar 03, 2005 10:54 am


-----------------------------------
So does this mean that I win?

-----------------------------------
Tony
Thu Mar 03, 2005 11:00 am


-----------------------------------
I'll tell you that after I revisit processes in detail.

-----------------------------------
StarGateSG-1
Thu Mar 03, 2005 12:05 pm


-----------------------------------
I glad to see you aleats listen to me and are looking in to it.
I really am sry i can't give you any source code i take lent very seriously.
lol even thos i drew it out of a hat with everyhing i could give up.
I guess it was luck of the draw.

-----------------------------------
person
Thu Mar 03, 2005 6:21 pm


-----------------------------------
how about animating 2 things at the same time with different speeds?

wouldnt u need a process for that?

-----------------------------------
ssr
Thu Mar 03, 2005 6:29 pm


-----------------------------------
not really
put them all in a same loop
and then set different speed
... 8)

-----------------------------------
Martin
Thu Mar 03, 2005 6:33 pm


-----------------------------------
Yeah.

Delays are another bad thing...I'll get into that later though.

-----------------------------------
Bacchus
Thu Mar 03, 2005 6:39 pm


-----------------------------------
cooldowns work quite well, do a search for that with author Cervantes, he posted an example b4 and it works quite well

-----------------------------------
Tony
Fri Mar 04, 2005 3:45 pm


-----------------------------------
Processes still suck.
Hmm.. I think I'll take on your challange.

Martin -- get your Turing reference book out, you're going to need to relearn a language :lol:

-----------------------------------
Martin
Fri Mar 04, 2005 6:47 pm


-----------------------------------
Processes still suck.
Hmm.. I think I'll take on your challange.

Martin -- get your Turing reference book out, you're going to need to relearn a language :lol:

Bring it on. :)

-----------------------------------
[Gandalf]
Fri Mar 04, 2005 7:34 pm


-----------------------------------
Delays are another bad thing...I'll get into that later though.

Why are delays bad?  Why don't you get on that some time soon, they only pause the code - whats bad about that?

-----------------------------------
ssr
Fri Mar 04, 2005 8:34 pm


-----------------------------------
I donno but I think that I've heard
delays are not really accurate
use Time.Elapse
 8)

-----------------------------------
person
Fri Mar 04, 2005 9:30 pm


-----------------------------------
u can actually read about how bad delays are in F10 but frankly it doesnt matter much for me

-----------------------------------
Martin
Fri Mar 04, 2005 9:52 pm


-----------------------------------
I'll write up a bit about delays later. Basically, they're bad because you've got your program structured like so:

loop
    
    
end loop

What this means is that the speed of the game is directly dependant upon the speed of the client computer.

-----------------------------------
person
Fri Mar 04, 2005 9:54 pm


-----------------------------------
isnt it always dependant on the clients computer (processing speeds and etc.) ??

-----------------------------------
Tony
Fri Mar 04, 2005 11:18 pm


-----------------------------------
The idea is to control frame-rate, and pause for less on slower machines and during calculation heavy moments.

In practice, you don't want a Counter-Strike player to shoot twice as fast as the next guy just because one has liquid cooling installed.

-----------------------------------
Martin
Sat Mar 05, 2005 10:01 am


-----------------------------------
isnt it always dependant on the clients computer (processing speeds and etc.) ??

No. Yes, on a faster computer, the animation will be smoother, but a player shouldn't be put at a disadvantage because they have a slower processor. Similarly, people with faster computers shouldn't be able to shoot 5 times faster than everyone else.

Let's say that you want each frame of animation to take 20 milliseconds.

Suppose on your computer it takes 10 ms to do all of the crunching, so you delay(10) at the end. Works exactly how you wanted it to on your computer.

You bring it over to your buddy's computer, who has a slower processor, so it takes 15 seconds to do the number crunching, but you still are delaying 10 at the end of each frame. So the game runs slower on his computer.

Now, the quick solution to this is to:
1. Determine the total time, GoalTime, you want the frame to last (in the above example, the total time was 20).
2. In each iteration of the loop, determine how long the number crunching took with Time.Elapsed.
3. Delay for the GoalTime - Time.Elapsed.

Now, what happens if the number crunching is longer than GoalTime? This is where time based movement comes into play, which I'll explain later.

-----------------------------------
Bacchus
Sat Mar 05, 2005 7:19 pm


-----------------------------------
1 simple thing that is fixed in 4.0.5 :P Time.DelaySinceLast()

-----------------------------------
Martin
Thu Mar 10, 2005 10:34 am


-----------------------------------
Nobody has taken me up on this 1000 bit challenge. So I'm raising the stakes. 2000 bits.

I still don't think it can be done.

-----------------------------------
StarGateSG-1
Thu Mar 10, 2005 12:26 pm


-----------------------------------
This program comes form the top!


monitor controller
            export observe, report
        
            var counter : int := 0
        
            procedure observe
                counter := counter + 1
            end observe
        
            procedure report (var n : int )
                n := counter
                counter := 0
            end report
        end controller
        process observer
            loop
              %  "¦ observe one event "¦
                controller . observe
            end loop
        end observer
        
        process reporter
            var n : int
            loop
                controller.report ( n )
              %  "¦ report n events "¦
            end loop
        end reporter
        
        fork observer       % Activate the observer
        fork reporter       % Activate the reporter


This is form deep in the Documentation of turing and I even contacted Tom West to make sure.

-----------------------------------
Martin
Thu Mar 10, 2005 1:10 pm


-----------------------------------
And umm...what is that supposed to be doing?

-----------------------------------
Tony
Thu Mar 10, 2005 1:44 pm


-----------------------------------
This program comes form the top!
...
This is form deep in the Documentation of turing and I even contacted Tom West to make sure.
And we all know that the said top thinks at a highschool level.

Martin : [url=http://www.compsci.ca/v2/viewtopic.php?t=8049]Your turn

-----------------------------------
StarGateSG-1
Fri Mar 11, 2005 7:14 am


-----------------------------------
The program runs 2 processes at the same time.


And we all know that the said top thinks at a highschool level.
 

What do you mean by this :?:

-----------------------------------
Martin
Fri Mar 11, 2005 8:05 am


-----------------------------------
The program runs 2 processes at the same time.


And we all know that the said top thinks at a highschool level.
 

What do you mean by this :?:

Umm, that's easy enough to do without processes, although the above code seems somewhat abstract for me to provide a solid counter arguement.

And Tony, it's on. I'll have the processless code posted by the end of the weekend hopefully.

-----------------------------------
StarGateSG-1
Fri Mar 11, 2005 8:29 am


-----------------------------------

Umm, that's easy enough to do without processes, although the above code seems somewhat abstract for me to provide a solid counter arguement. 


Well if it is so easy do it.
If works exaclty the same as anyone other way.

The coed is not abstract, it is right out of the help file.

-----------------------------------
Martin
Fri Mar 11, 2005 8:46 am


-----------------------------------
Oh, it's easy enough to fix, but it's still abstract. It doesn't actually do anything.

-----------------------------------
Tony
Fri Mar 11, 2005 9:24 am


-----------------------------------
StarGateSG-1 : the code you posted was to demonstrate the monitor, not processes. The abstract consept is that two processes access the same variable and a monitor class queries their requests.

-----------------------------------
StarGateSG-1
Fri Mar 11, 2005 12:00 pm


-----------------------------------
It demostrates that two processes can be run at the same time as well though, and that was the point. I believe all the challege was was to right (or find a program that couldn't be written better without porcesses. This meets those req.

-----------------------------------
Martin
Fri Mar 11, 2005 2:54 pm


-----------------------------------
Not yet, I definately see where I can improve this.

However, like I said, it would be much easier if you were to post code that actually did something.

-----------------------------------
StarGateSG-1
Fri Mar 11, 2005 3:50 pm


-----------------------------------
It does do something it just has no output!

-----------------------------------
Bacchus
Fri Mar 11, 2005 4:02 pm


-----------------------------------
just stick a put statment to output the counter variable after one gets added to it, it should never reach 2, but it does lol

-----------------------------------
McKenzie
Fri Mar 18, 2005 2:00 am


-----------------------------------
Silly Conest, and silly judging.
OK, don't touch processes until you know what you are doing.  (this is about one year after you think you know what you are doing, for some never :cry: ) Better or worse is not measured simply be execution time.  Better, for the most part, is if it makes the program easier without sacrificing efficiency.  The reality is processes can make the program more efficient, but this only happens with advanced programs (e.g. A chess program when the IA is doing it's work while waiting for the player to do his move.) There is no program that is written with processes that can't be written without. The question is "does this program lend itself to processes?"  The same can can be said of recursion or even subroutines. You can always do without them, but the real issue is WHEN SHOULD THEY BE USED.
For the record, I would be a happy man if no grade 11 ever used a process (they mostly mess it up)

-----------------------------------
Tony
Fri Mar 18, 2005 9:18 am


-----------------------------------
good point by McKenzie; though I'm still waiting for Martin's code :lol: 

But yes -- processes are justified to be used only when one knows what he's doing. Oftentimes I saw people do something like

process foo
loop
   %program
end loop
end foo

fork foo

The reasoning behind such is simply beyond me.

-----------------------------------
McKenzie
Fri Mar 18, 2005 10:07 am


-----------------------------------
I know, I see those programs too.  I don't know if they think they're being 1337 or if they think that they own a machine with massively parrallel processors.  If they come from accross the hall (there are two computer teachers at massey) I'm gently explain how they are adding complexity for no good reason.  If they're my student I shake my head in disgust, talk about how I've failed them as a teacher and maybe I should go back to driving taxi. They get the Idea that they may have done something wrong. (It's kinda like Holt's message about "it's not your fault" ... don't kid yourself ... it's your fault)

-----------------------------------
Bacchus
Fri Mar 18, 2005 10:33 am


-----------------------------------
lol send them on a guilt trip

-----------------------------------
StarGateSG-1
Fri Mar 18, 2005 10:48 am


-----------------------------------
I am Glad to see this topic is warped up with common sense, people finally see it my way as my old singature said.

-----------------------------------
StarGateSG-1
Fri Mar 18, 2005 10:52 am

One last  thing
-----------------------------------

For the record, I would be a happy man if no grade 11 ever used a process (they mostly mess it up)

You need to make this say forst or second year, not all school start up in grade 11, me I started, way back in grade nine soon to be 5 years.

-----------------------------------
McKenzie
Fri Mar 18, 2005 3:08 pm


-----------------------------------
There is a certain amount of mental maturity that is seperate from years of programming experience.  Some of this maturinty is physical and some has to with other educational experience (mainly math)

-----------------------------------
Martin
Fri Mar 18, 2005 3:32 pm


-----------------------------------
Sorry I haven't posted anything yet, I've been working 11 hour days lately, and haven't been up to it. Soon I promise. I've already written myself a stack and a queue class :) Damn turing's lack of an STL.

-----------------------------------
StarGateSG-1
Sat Mar 19, 2005 11:39 am


-----------------------------------

There is a certain amount of mental maturity that is seperate from years of programming experience. Some of this maturinty is physical and some has to with other educational experience (mainly math)


I only said that becasue at my school we have a great teacher, and he is buddy with Tom West, so even comes and visit , and we always get like the newest version before the board. Our school it a trade school so we have a lot of programing courses not just a few bits and pieces. On top of that our school has well trained programers because all of the higher grades peer-tutor the lower ones, Always. I just got a little ticked off because you lumped all grades people together.

-----------------------------------
TokenHerbz
Wed Oct 26, 2005 4:13 am


-----------------------------------
O M F G ???

i use mass proc's??   is that bad?

-----------------------------------
[Gandalf]
Wed Oct 26, 2005 4:40 am


-----------------------------------
Matters what you mean by proc.

In Turing procedure = proc, process = process.

-----------------------------------
beard0
Wed Oct 26, 2005 11:13 am


-----------------------------------
Martin, I know I'm somewhat late, but a perfect example of a program that requires a process:

var connected := false
var userString := ""
var ch : string (1)
var stream : int
var inAddr : string

process GetConnect
    stream := Net.WaitForConnection (3942, inAddr)
    connected := true
end GetConnect

fork GetConnect

loop
    if hasch then
        getch (ch)
        userString += ch
    end if
    exit when connected
end loop

if stream > 0 then
    if userString = "" then
        put : stream, "The user did not enter anything."
    else
        put : stream, userString
    end if
end if

Otherwise, I agree that processes should not be used - Net.WaitForConnection is the only legitimate use I see for them.

-----------------------------------
[Gandalf]
Wed Oct 26, 2005 11:30 am


-----------------------------------
Or if you want to play Turing's music (ie. play()) in the background.  If you are playing it from a file, anything like Music.PlayFileLoop() will work without a process.

-----------------------------------
beard0
Wed Oct 26, 2005 11:57 am


-----------------------------------
For my high scool programming class we used the old DOS Turing.  I wanted to have background music in my final project which meant, in the DOS version, using play("abcd") etc.  The problem was that the play command returned as it began to play the last note only.  Thankfully, we were graced with a function playdone, which allowed me to do this:

var music : string := ">8gf+fe-4e84c8ac4dabcabc