
-----------------------------------
FC7321
Mon Jun 03, 2013 11:27 am

Speed up Turing
-----------------------------------
My program is  not running as fast as I would like it to (NOT because of delays). Is there any way to making Turing read and process the coding faster?

Thanks.

-----------------------------------
DemonWasp
Mon Jun 03, 2013 12:01 pm

RE:Speed up Turing
-----------------------------------
Not really. You could try OpenTuring, but that's a band-aid solution (and it won't help if your teacher/marker is running your code in standard Turing).

The problem is almost certainly in your code. Turing is brutally slow, but novice coders often make simple mistakes that slow their program down too--and you can actually fix those. Post your code and people here can suggest areas for improvement.

-----------------------------------
FC7321
Tue Jun 04, 2013 11:59 am

Re: Speed up Turing
-----------------------------------
 
setscreen ("graphics: 1000; 600") %Englarge execution window
setscreen ("onscreenonly") %Generates a smoother appearance

%GRPAHICS -- Variables
var fontmenu : int := Font.New ("impact:20") %Declaring font
var MainMenu : int := Pic.FileNew ("MainMenu.jpg") %Declare image for main menu
var introscreen : int := Pic.FileNew ("logo.jpg") %Declare image for introduction screen
var creditscreen : int := Pic.FileNew ("credits.jpg") %Declare image for credit screen
var gamescreen : int := Pic.FileNew ("gameScreen.jpg") %Declare image for game screen
var endscreen : int := Pic.FileNew ("endscreen.jpg") %Declare image for end screen
var I1 : int := Pic.FileNew ("I1.jpg") %Declare instruction screen (1)
var I2 : int := Pic.FileNew ("I2.jpg") %Declare instruction screen (2)
var I3 : int := Pic.FileNew ("I3.jpg") %Declare instruction screen (3)
var I4 : int := Pic.FileNew ("I4.jpg") %Declare instruction screen (4)
var I5 : int := Pic.FileNew ("I5.jpg") %Declare instruction screen (5)
var IBack : int := Pic.FileNew ("IBack.jpg") %Declare instruction screen background


%Set the following procedures as forward in order to avoid mutual recursion
forward procedure Instructions
forward procedure SongSelect
forward procedure Credits
forward procedure mainmenu
forward procedure lanes
forward procedure endscreen_song
forward procedure Instruction1
forward procedure Instruction2
forward procedure Instruction3
forward procedure Instruction4
forward procedure Instruction5

body procedure Instruction5 % open instruction screen, fifth slide
    cls % clear screen
    Pic.Draw (I5, 1, 1, 0) % display background of instruction screen
    loop
        drawfillbox ((maxx - 100), 0, maxx, 100, white)
        Font.Draw ("Menu", maxx - 80, 30, fontmenu, red)
        drawfillbox (0, maxy - 100, 100, maxy, white)
        Font.Draw ("Back", 20, maxy - 80, fontmenu, red)
        var m, n, o, p : int
        buttonwait ("up", m, n, o, p)
        if m >= (maxx - 100) and n >= 0 and m = (maxy - 100) and m = 0 and m = (maxy - 100) and m = (maxy - 100) and m = 0 and m = (maxy - 100) and m = (maxy - 100) and m = 0 and m = (maxy - 100) and m = (maxy - 100) and m = 0 and m = (maxy - 100) and m = 0 and m = 0 and m = 385 and m = 320 and m = 260 and m = 200 and m  68 and one_pressed = true then
            hitnote
            exit
        else
        end if

        Sprite.SetPosition (redsprite, 75, y1 - 25, false)
        Sprite.Show (redsprite)

        View.Update
        delay (5)

    end loop
end line01_individualnote

% animation of descending note in lane 01
procedure line02_individualnote
    loop
        View.Set ("offscreenonly")
        Pic.Draw (gamescreen, 1, 1, 0)
        Sprite.Show (slotredsprite)
        Sprite.Show (slotbluesprite)
        Sprite.Show (slotgreensprite)
        Sprite.Show (slotyellowsprite)
        Sprite.Show (slotorangesprite)

        Input.KeyDown (chars)
        if chars ('2') then
            two_pressed := true
        else
            two_pressed := false
        end if

        %THE y-VALUE
        y2 := y2 - 5 
        exit when y2 = -25

        %collision
        if 82 > y2 and y2 > 68 and two_pressed = true then
            hitnote
            exit
        else
        end if

        Sprite.SetPosition (bluesprite, 175, y2 - 25, false)
        Sprite.Show (bluesprite)
        View.Update
        delay (5)

    end loop
end line02_individualnote

% animation of descending note in lane 03
procedure line03_individualnote
    loop
        View.Set ("offscreenonly")
        Pic.Draw (gamescreen, 1, 1, 0)
        Sprite.Show (slotredsprite)
        Sprite.Show (slotbluesprite)
        Sprite.Show (slotgreensprite)
        Sprite.Show (slotyellowsprite)
        Sprite.Show (slotorangesprite)

        % lane 03 controls
        Input.KeyDown (chars)
        if chars ('3') then
            three_pressed := true
        else
            three_pressed := false
        end if

        % THE y-VALUE
        y3 := y3 - 5 

        exit when y3 = -25

        %collision
        if 82 > y3 and y3 > 68 and three_pressed = true then
            hitnote
            exit
        else
        end if

        Sprite.SetPosition (greensprite, 275, y3 - 25, false)
        Sprite.Show (greensprite)
        View.Update
        delay (5)

    end loop
end line03_individualnote

procedure line04_individualnote
    loop
        View.Set ("offscreenonly")
        Pic.Draw (gamescreen, 1, 1, 0)
        Sprite.Show (slotredsprite)
        Sprite.Show (slotbluesprite)
        Sprite.Show (slotgreensprite)
        Sprite.Show (slotyellowsprite)
        Sprite.Show (slotorangesprite)

        % lane 01 controls
        Input.KeyDown (chars)

        if chars ('4') then
            four_pressed := true
        else

            four_pressed := false
        end if

        % THE y-VALUE
        y4 := y4 - 5

        exit when y4 = -25

        %collision
        if 82 > y4 and y4 > 68 and four_pressed = true then
            hitnote
            exit
        else
        end if

        Sprite.SetPosition (yellowsprite, 375, y4 - 25, false)
        Sprite.Show (yellowsprite)
        View.Update
        delay (5)

    end loop
end line04_individualnote

procedure line05_individualnote
    loop
        View.Set ("offscreenonly")
        Pic.Draw (gamescreen, 1, 1, 0)
        Sprite.Show (slotredsprite)
        Sprite.Show (slotbluesprite)
        Sprite.Show (slotgreensprite)
        Sprite.Show (slotyellowsprite)
        Sprite.Show (slotorangesprite)


        Input.KeyDown (chars)

        if chars ('5') then
            five_pressed := true
        else
            five_pressed := false
        end if

        % THE y-VALUE
        y5 := y5 - 5 

        exit when y5 = -25

        %collision
        if 82 > y5 and y5 > 68 and five_pressed = true then
            hitnote
            exit
        else
        end if

        Sprite.SetPosition (orangesprite, 475, y5 - 25, false)
        Sprite.Show (orangesprite)
        View.Update
        delay (5)

    end loop
end line05_individualnote

% PROCEDURE for consecutive notes within song
body procedure lanes

    Music.PlayFileStop
    fork song01_subprogram

    Sprite.Show (slotredsprite)
    Sprite.Show (slotbluesprite)
    Sprite.Show (slotgreensprite)
    Sprite.Show (slotyellowsprite)
    Sprite.Show (slotorangesprite)

    for i : 1 .. totalnotes

        Pic.Draw (gamescreen, 1, 1, 0)

        delay (interval (i))

        randint (lanenumber, 1, 5)

        if lanenumber = 1 then
            line01_individualnote
        elsif lanenumber = 2 then
            line02_individualnote
        elsif lanenumber = 3 then
            line03_individualnote
        elsif lanenumber = 4 then
            line04_individualnote
        elsif lanenumber = 5 then
            line05_individualnote
        end if

        y1 := 450
        Pic.Draw (redslot, 75, 50, 0)
        y2 := 450
        Pic.Draw (blueslot, 175, 50, 0)
        y3 := 450
        Pic.Draw (greenslot, 275, 50, 0)
        y4 := 450
        Pic.Draw (yellowslot, 375, 50, 0)
        y5 := 450
        Pic.Draw (orangeslot, 475, 50, 0)

    end for
    Sprite.Hide (redsprite)
    Sprite.Hide (bluesprite)
    Sprite.Hide (greensprite)
    Sprite.Hide (yellowsprite)
    Sprite.Hide (orangesprite)

    endscreen_song
end lanes

body procedure endscreen_song

    Sprite.Hide (redsprite)
    Sprite.Hide (bluesprite)
    Sprite.Hide (greensprite)
    Sprite.Hide (yellowsprite)
    Sprite.Hide (orangesprite)
    Sprite.Hide (slotredsprite)
    Sprite.Hide (slotbluesprite)
    Sprite.Hide (slotgreensprite)
    Sprite.Hide (slotyellowsprite)
    Sprite.Hide (slotorangesprite)

    cls % clears the screen
    Pic.Draw (endscreen, 1, 1, 0) % displays the end screen

    totalpoints := (count_pt10 * 10) + (count_pt5 * 5) + (count_pt3 * 3) + (count_pt1) % calculates the number of points earned depending on how many notes were hit and to whast degree of accuracy
    winpercentage := (totalpoints div (totalnotes * 10)) * 100 % calculates the win percentage

    colour (white) % sets font colour to white
    colourback (black) % sets background colour of text to black
    locatexy (maxx - 50, 540)
    put count
    locatexy (maxx - 50, 505)
    put totalnotes - count
    locatexy (maxx - 50, 465)
    put winpercentage, "%"

    if winpercentage >= 80 then
        Font.Draw ("A", 170, 405, fontmenu, white)
    elsif winpercentage >= 70 then
        Font.Draw ("B", 170, 405, fontmenu, white)
    elsif winpercentage >= 60 then
        Font.Draw ("C", 170, 405, fontmenu, white)
    elsif winpercentage >= 50 then
        Font.Draw ("D", 170, 405, fontmenu, white)
    else
        Font.Draw ("F", 170, 405, fontmenu, white)
    end if

    var reply : string (1) % declare variable for user's response
    getch (reply) % waits for user to press any key before continuing program
    mainmenu % returns to main menu

end endscreen_song

%---------------------------------------------

% PROGRAM BEGINS

Pic.Draw (introscreen, 1, 1, 0) % display introduction screen
delay (3000) % waits 3 seconds before clearing the screen

% GAME BEGINS // MUSIC STARTS PLAYING
mainmenu


-----------------------------------
Tony
Tue Jun 04, 2013 2:12 pm

RE:Speed up Turing
-----------------------------------
so... which part is slow?

-----------------------------------
FC7321
Wed Jun 05, 2013 2:38 pm

RE:Speed up Turing
-----------------------------------
Sorry, there are many graphics that I imported. 

The procedures (line(01-05)_individualnote) are all slowing down. The "notes" do not move down the screen fast enough.

-----------------------------------
MihaiG
Wed Jun 05, 2013 6:09 pm

Re: Speed up Turing
-----------------------------------
In each of those you have a delay(5). Have you tried removing these or making the value smaller? 
A few years ago i made a wand you would wave in the air and connect via parallel port, and it would write out letters!
The issue was timing the delay, delay only works on increments of 1ms, while i had to work on much smaller orders.

I figured i could make a blank for loop ie

for i : 1..10000
end for


The only issue this provided was, clock speed on my CPU was a factor! 

You also seem to be using a delay in the procedure that calls the individualnote procedures. Delays in turing are generally bad!

-----------------------------------
Raknarg
Wed Jun 05, 2013 7:58 pm

RE:Speed up Turing
-----------------------------------
you can try replacing delay with Time.DelaySinceLast, that makes it more regulated

-----------------------------------
FC7321
Wed Jun 12, 2013 6:08 pm

RE:Speed up Turing
-----------------------------------
Thanks for your help :D

Open Turing helps the program run much faster, so the problem is fixed!
