LB Booster
« #graphicHandle "discard" »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:53am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: #graphicHandle "discard"  (Read 1218 times)
Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: #graphicHandle "discard"
« Reply #18 on: Jun 3rd, 2017, 2:56pm »

I see the point you are making. I have always used discard ahead of redraw. I was probably not even aware that redraw has an implicit discard function.

However to muddy the water further the following code behaves very differently with and without the discard statement. Without it I see memory use escalate, with it I see rock steady memory use. Win10 LB 4.5.1

Whether it matters for LBB I am not sure, ignoring discard seems the correct strategy.

Code:
    nomainwin
    WindowWidth  = 600
    WindowHeight = 400
    UpperLeftX   = (DisplayWidth-WindowWidth)/2
    UpperLeftY   = (DisplayHeight-WindowHeight)/2
    button #1.b, "Draw Graphic", [nextdrawing], UL, 250, 340
    graphicbox #1.gb, 50,25,500,300
    open "Refreshed Graphic Example" for window_nf as #1
    #1 "trapclose [quit]"

    'put the pen down and set the font
    'note cls has no impact on these settings
    #1.gb "down ; font comic_sans 48"

    'good practice to start with a clean sheet
    #1.gb "cls"

    'draw the background
    #1.gb "fill pink ; backcolor red ; color red"
    #1.gb "place 100 50 ; boxfilled  300 150"
    #1.gb "place 300 150 ; circlefilled 100"
    #1.gb "backcolor pink"
    #1.gb "place 50 100 ;\1"

    'now flush as the named segment "backgroundimage"
    #1.gb "flush backgroundimage"


    [loop]
    scan
    'redraw the background using its segment name
    #1.gb "discard ; redraw backgroundimage"

    'now paint the new foreground image
    'notice that the foreground images do not use
    'full screen fills.
        #1.gb "backcolor green ; color green"
        #1.gb "place 300 50 ; boxfilled  400 200"
        #1.gb "place 300 200 ; circlefilled 100"
        #1.gb "backcolor red"
        #1.gb "place 180 120 ;\2"
   goto [loop]

[quit]
close #1
end

 

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: #graphicHandle "discard"
« Reply #19 on: Jun 3rd, 2017, 4:04pm »

on Jun 3rd, 2017, 2:56pm, Rod wrote:
However to muddy the water further the following code behaves very differently with and without the discard statement.

There's nothing in the docs to suggest that redrawing a named segment makes any difference (especially if it's exactly the same segment). Also, the 'redraw backgroundimage' makes the items drawn since the last flush inaccessible, guaranteeing a memory leak if the discard is omitted.

So my conclusion is that it's probably a bug.

Richard.
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: #graphicHandle "discard"
« Reply #20 on: Jun 3rd, 2017, 4:58pm »

Testing further I see that the drawing commands are held in memory in the "current segment". The redraw erases them from the screen but they can still be preserved and redrawn with a flush and redraw.

So it seems redraw does not have an implicit discard. It matters little to LBB.

Code:
nomainwin
    WindowWidth  = 600
    WindowHeight = 400
    UpperLeftX   = (DisplayWidth-WindowWidth)/2
    UpperLeftY   = (DisplayHeight-WindowHeight)/2
    button #1.b, "Draw Graphic", [nextdrawing], UL, 250, 340
    graphicbox #1.gb, 50,25,500,300
    open "Refreshed Graphic Example" for window_nf as #1
    #1 "trapclose [quit]"

    'put the pen down and set the font
    'note cls has no impact on these settings
    #1.gb "down ; font comic_sans 48"

    'good practice to start with a clean sheet
    #1.gb "cls"

    'draw the background
    #1.gb "fill pink ; backcolor red ; color red"
    #1.gb "place 100 50 ; boxfilled  300 150"
    #1.gb "place 300 150 ; circlefilled 100"
    #1.gb "backcolor pink"
    #1.gb "place 50 100 ;\1"

    'now flush as the named segment "backgroundimage"
    #1.gb "flush backgroundimage"


    [loop]
    scan
    'redraw the background using its segment name
    #1.gb "discard ; redraw backgroundimage"

    'now paint the new foreground image
    'notice that the foreground images do not use
    'full screen fills.
        #1.gb "backcolor green ; color green"
        #1.gb "place 300 50 ; boxfilled  400 200"
        #1.gb "place 300 200 ; circlefilled 100"
        #1.gb "backcolor red"
        #1.gb "place 180 120 ;\2"
    #1.gb "redraw backgroundimage"
    #1.gb "flush s"
    #1.gb "redraw s"


[quit]
close #1
end

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: #graphicHandle "discard"
« Reply #21 on: Jun 3rd, 2017, 5:57pm »

on Jun 3rd, 2017, 4:58pm, Rod wrote:
So it seems redraw does not have an implicit discard.

Right, but only when an explicit segment is redrawn. The LB docs are quite clear that redraw on its own causes any drawing commands since the last flush to be 'lost'. You can confirm that by changing 'redraw backgroundimage' to just 'redraw' in your most recent program.

I'm confident that the use of discard in both "flush; discard" and "discard; redraw" is superfluous, and serves only to slow down the program slightly.

Richard.
« Last Edit: Jun 3rd, 2017, 5:57pm by Richard Russell » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls