Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Not the usual speed issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not the usual speed issue

    The attached code is an example of code that, on my Vista machine(dual core), runs at 64 'frames' per second.(This will vary depending on machine abilities). There are these three inconsistencies:
    1
    However, when the program is minimized(by clicking on the taskbar icon) it runs at ~175 'frames' per second.
    2
    When any one of the MS games Hearts, Solitaire, or Spider Solitaire are running with focus and the app running in the background, the app runs at ~145 'frames' per second.
    3
    If my web browser, the PBWin IDE, or most other apps are running with focus, I get the 64 'frames' per second speed.

    Further, if I check and install any M$ updates, then run these tests, the app runs at its usual speed and item 3 above is as usual, but 1 and 2 the speed difference drops to approximately 90 and 75 'frames' per second respectively.

    But if the computer sits idle for a time, say while I have a nap, the speed difference for 2 and 3 increases.
    I have achieved speeds > 240 'frames' per second while playing Solitaire thus a range of speed increases from 0.25 to just under 4.

    There is no threading in the app, but I thought at first it had something to do with being relegated to the second core when another app had focus, but the increase in speed from the idle time doesn't make sense.

    Can others duplicate the events using the attached code? (speed will be dependent on the computer model) Does anyone have any code that follows this same pattern? And finally, is there some way to force this speed increase?

    The following code has been chopped a bit to keep the display simple, but one can run the app just by clicking the start button, no need to restart the program for a second try as each run is independent of the previous.
    Code:
    #PBFORMS CREATED V2.00
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** Includes **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #INCLUDE ONCE "WIN32API.INC"
    #PBFORMS END INCLUDES
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    #RESOURCE ICON, 7219, "C:\PBWin10\iconsFC\flasher4.ico"
    
    MACRO circle (xx,yy,rr,colour)= GRAPHIC ELLIPSE (xx-rr,yy-rr)-(xx+rr,yy+rr),colour,colour
    MACRO circlet (xx,yy,rr,colour)= GRAPHIC ELLIPSE (xx-rr,yy-rr)-(xx+rr,yy+rr),colour
    
    TYPE locator
      x       AS DOUBLE
      z       AS DOUBLE
    END TYPE
    
    TYPE star
      x       AS DOUBLE
      y       AS DOUBLE
      z       AS DOUBLE
      velx    AS DOUBLE
      vely    AS DOUBLE
      velz    AS DOUBLE
      colr    AS LONG
      hilite  AS LONG
      mass    AS DOUBLE
      unts    AS DOUBLE
      allun   AS EXT
      'temx    AS double
      'temy    AS double
      'temz    AS double                           #RESOURCE ICON, 7307, "C:\PBWin10\iconsFC\pointer1.ico"
      'radius  AS double
    END TYPE
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** Constants **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1            =  101  '*
    %IDC_COMBOBOX1          = 1001  '*
    %IDC_LABEL1             = 1002  '*
    %IDC_HIGHLIGHTOPT       = 1003
    %IDC_LOWLIGHTOPT        = 1004
    %IDC_NEITHEROPT         = 1005
    %IDC_YELLOWSOPT         = 1006
    %IDC_MAGENTASOPT        = 1007
    %IDC_GREENSOPT          = 1008
    %IDC_BLUESOPT           = 1009
    %IDC_GRAYSOPT           = 1010
    %IDC_MIXTURESOPT        = 1011
    %IDCANCEL               =    2
    %IDC_YELLOWSOPT2        = 1012
    %IDC_MAGENTASOPT2       = 1013
    %IDC_GREENSOPT2         = 1014
    %IDC_BLUESOPT2          = 1015
    %IDC_GRAYSOPT2          = 1016
    %IDC_MIXTURESOPT2       = 1017
    %IDC_YELLOWHILO         = 1018
    %IDC_MAGENTAHILO        = 1019
    %IDC_CYANHILO           = 1020
    %IDC_WHITEHILO          = 1021
    %IDC_LABEL2             = 1024
    %IDC_LABEL3             = 1025
    %IDC_STARSPERCLUSTER    = 1026
    %IDC_FRAMES             = 1027
    %IDC_LABEL4             = 1028
    %IDC_LABEL5             = 1029
    %IDC_LABEL6             = 1030
    %IDC_LABEL7             = 1031
    %IDC_SAVEALL            = 1033
    %IDC_SAVEFIRSTLAST      = 1034
    %IDC_SAVENO             = 1035
    %IDC_SHOWFINALFRAMEONLY = 1036
    %IDC_START              = 1037
    %IDC_CLOCKWISE          = 1038
    %IDC_COUNTERCLOCKWISE   = 1039
    %IDC_LABEL8             = 1040  '*
    %IDC_FRAME1             = 1041
    %IDC_FRAME2             = 1042
    %IDC_LABEL9             = 1043
    %IDC_LABEL10            = 1044
    %IDD_DIALOG2            =  101
    #PBFORMS END CONSTANTS
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** Declarations **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG2Proc()
    DECLARE FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    FUNCTION PBMAIN()
      ShowDIALOG2 %HWND_DESKTOP
    END FUNCTION
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** CallBacks **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG2Proc()
      STATIC winw, winh, wloc, hloc,cntr, gwin, ggwin AS LONG
      STATIC wwyd, whyt, pwyd, phyt, cwyd, chyt, nwyd, nhyt AS DOUBLE
      STATIC cx, cy, tx, ty, wyd, hyt, pi, rr, r, factor, xwyd, yhyt AS DOUBLE
      STATIC focuss(), lfocuss() AS DOUBLE
      STATIC orientate, rotation, indic, indi1, indi2, indi3, indicol, clrd AS LONG
      STATIC clus1, clus2, spin, bodies, frames, shwall, shwfl, shwno AS LONG
      STATIC uflag, xx, yy, zz, tt, dc1, df1, dc2, df2 AS DOUBLE
      STATIC clsst1, frthst1, clsst2, frthst2 AS LONG
      STATIC tmr, ftmr, bigun AS EXT
      STATIC totalstars, xxx, yyy AS LONG
      STATIC temstr,img, imtemp AS STRING
      STATIC sect() AS STRING
      STATIC cbsel, fnt, fnt1, fnt2, showit AS LONG
      STATIC str(), fstr() AS star      'str() AS star,
      LOCAL gravity, temp AS DOUBLE
      LOCAL cnts AS LONG
      LOCAL st AS star PTR
      STATIC slow(), fast(), slw(), fst() AS locator
    
    
      FONT NEW "Arial", 12, 0 TO fnt
      FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO fnt2
      FONT NEW "Arial", 14, 1, %ANSI_CHARSET TO fnt1
      imtemp="Multi_"+dattim
      gravity= -0.0000000000667384
      pi = ATN(1) * 4
      SELECT CASE AS LONG CB.MSG
        CASE %WM_INITDIALOG
          ' Initialization handler
          CONTROL SET OPTION CB.HNDL, %IDC_NEITHEROPT, %IDC_HIGHLIGHTOPT, %IDC_NEITHEROPT
          CONTROL SET OPTION CB.HNDL, %IDC_WHITEHILO, %IDC_YELLOWHILO, %IDC_WHITEHILO
          CONTROL SET OPTION CB.HNDL, %IDC_MAGENTASOPT, %IDC_YELLOWSOPT, %IDC_MIXTURESOPT
          CONTROL SET OPTION CB.HNDL, %IDC_YELLOWSOPT2, %IDC_YELLOWSOPT2, %IDC_MIXTURESOPT2
          CONTROL SET OPTION CB.HNDL, %IDC_SAVENO, %IDC_SAVEALL, %IDC_SAVENO
          CONTROL SET OPTION CB.HNDL, %IDC_CLOCKWISE, %IDC_CLOCKWISE, %IDC_COUNTERCLOCKWISE
          DESKTOP GET CLIENT TO winw, winh                'dialog height is 223
          wloc = winw/2-200
          hloc = winh/2-312
          cwyd=winw/2
          chyt=winh/2
          nwyd=401
          nhyt=401
          xwyd=200
          yhyt=200
          r=380/2
          factor= 473351040000000000/r
          DIALOG SET LOC CB.HNDL, wloc-100, hloc+403
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CB.WPARAM THEN
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
        CASE %WM_USER + 200
          COMBOBOX GET SELECT CB.HNDL, %IDC_COMBOBOX1 TO cbsel
          CONTROL GET CHECK CB.HNDL, %IDC_HIGHLIGHTOPT TO indi1
          CONTROL GET CHECK CB.HNDL, %IDC_LOWLIGHTOPT TO indi2
          CONTROL GET CHECK CB.HNDL, %IDC_NEITHEROPT TO indi3
          CONTROL GET CHECK CB.HNDL, %IDC_SHOWFINALFRAMEONLY TO showit
          CONTROL GET CHECK CB.HNDL, %IDC_SAVEALL TO shwall
          CONTROL GET CHECK CB.HNDL, %IDC_SAVEFIRSTLAST TO shwfl
          CONTROL GET CHECK CB.HNDL, %IDC_SAVENO TO shwno
          IF ISTRUE indi1 THEN
            indic=1
          ELSEIF ISTRUE indi2 THEN
            indic=2
          ELSEIF ISTRUE indi3 THEN
            indic=0
          END IF
          indicol=0
          FOR cntr=%IDC_YELLOWHILO TO %IDC_WHITEHILO
            INCR indicol
            CONTROL GET CHECK CB.HNDL, cntr TO indi1
            IF ISTRUE indi1 THEN EXIT FOR
          NEXT cntr
          SELECT CASE indicol
            CASE 1
              clrd=RGB(191,031,047)
            CASE 2
              clrd=RGB(128,127,255)
            CASE 3
              clrd=%RGB_DARKKHAKI
            CASE 4
              clrd= %RGB_GAINSBORO
          END SELECT
          clus1=0
          FOR cntr=%IDC_YELLOWSOPT TO %IDC_MIXTURESOPT
            INCR clus1
            CONTROL GET CHECK CB.HNDL, cntr TO indi1
            IF ISTRUE indi1 THEN EXIT FOR
          NEXT cntr
          clus2=0
          FOR cntr=%IDC_YELLOWSOPT2  TO %IDC_MIXTURESOPT2
            INCR clus2
            CONTROL GET CHECK CB.HNDL, cntr TO indi1
            IF ISTRUE indi1 THEN EXIT FOR
          NEXT cntr
          CONTROL GET CHECK CB.HNDL, %IDC_CLOCKWISE TO spin
          CONTROL GET TEXT CB.HNDL, %IDC_STARSPERCLUSTER TO temstr
          bodies=VAL(temstr)
          CONTROL GET TEXT CB.HNDL, %IDC_FRAMES TO temstr
          frames=VAL(temstr)
          totalstars=bodies*2+1
          REDIM str(totalstars)
          REDIM fstr(totalstars)
          REDIM slow(frames), fast(frames), slw(frames), fst(frames)
          DIALOG HIDE CB.HNDL
          IF ISFALSE gwin THEN
            GRAPHIC WINDOW NEW "",wloc-201 ,hloc ,nwyd,nhyt TO gWin
            DIALOG SET ICON CB.HNDL, "#7219"
            DIALOG SET ICON gwin, "#7219"
            DIALOG SET TEXT gwin, "SpiralGalaxy-all pairs"
            GRAPHIC ATTACH gwin,0, REDRAW
            GRAPHIC SET OVERLAP 1
            GRAPHIC CLEAR %BLACK
            GRAPHIC COLOR %MAGENTA,%BLACK
            GRAPHIC SCALE (-xwyd,-yhyt)-(xwyd, yhyt)
    
            GRAPHIC WINDOW NEW "",wloc+201 ,hloc ,nwyd,nhyt TO ggWin
            DIALOG SET ICON CB.HNDL, "#7219"
            DIALOG SET ICON ggwin, "#7219"
            DIALOG SET TEXT ggwin, "SpiralGalaxy-all bodies"
            GRAPHIC ATTACH ggwin,0, REDRAW
            GRAPHIC SET OVERLAP 1
            GRAPHIC CLEAR %BLACK
            GRAPHIC COLOR %MAGENTA,%BLACK
            GRAPHIC SCALE (-xwyd,-yhyt)-(xwyd, yhyt)
            GRAPHIC REDRAW
    
            GRAPHIC ATTACH gwin,0, REDRAW
            GRAPHIC WINDOW HIDE gwin
          END IF
          filler gwin, ggwin, str(),totalstars, indicol, clus1, clus2, factor, spin
    
    
          FOR cntr=0 TO totalstars             'find the smallest mass- could be done in the sub fillit
            IF cntr=0 THEN
              uflag=str(cntr).mass
            ELSEIF uflag>str(cntr).mass THEN
              uflag=str(cntr).mass
            END IF
    
            xx=str(cntr).x-0
            yy=str(cntr).y-0
            zz=str(cntr).z-0
            tt=SQR(xx*xx+yy*yy+zz*zz)
            IF cntr=0 THEN
              clsst1    =cntr
              dc1       =tt
              frthst1   =cntr
              df1       =tt
              clsst2    =cntr
              dc2       =tt
              frthst2   =cntr
              df2       =tt
            ELSE
              IF str(cntr).x<0 THEN
                IF tt>dc2 THEN
                  dc2= tt
                  clsst2=cntr
                ELSEIF tt<df2 THEN
                  df2=tt
                  frthst2=cntr
                END IF
              ELSEIF str(cntr).x>0 THEN
                IF tt<dc1 THEN
                  dc1=tt
                  clsst1=cntr
                ELSEIF tt>df1 THEN
                  df1=tt
                  frthst1=cntr
                END IF
              END IF
            END IF
            'if cntr=50 or cntr=60 then msgbox "closest neg "+format$(dc2)+$crlf+"furthest neg "+format$(df2)+$crlf+format$(dc1)+$crlf+format$(df1)
          NEXT cntr
          RESET bigun
          FOR cntr=0 TO totalstars      'calculate the number of 'smallest masses' that would fit in mass
            str(cntr).unts= str(cntr).mass/uflag
            bigun+=str(cntr).unts
          NEXT cntr
    
          FOR cntr=0 TO totalstars
            fstr(cntr).x      = str(cntr).x
            fstr(cntr).z      = str(cntr).z
            fstr(cntr).y      = str(cntr).y
            fstr(cntr).velz   = str(cntr).velz
            fstr(cntr).velx   = str(cntr).velx
            fstr(cntr).vely   = str(cntr).vely
            fstr(cntr).mass   = str(cntr).mass
            fstr(cntr).colr   = str(cntr).colr
            fstr(cntr).hilite = str(cntr).hilite
            fstr(cntr).unts   = str(cntr).unts
            fstr(cntr).allun  = bigun-fstr(cntr).unts
          NEXT cntr
          uflag=gravity*uflag
          GOTO jumpin
          tmr=TIMER
          FOR cntr=1 TO frames
            'if cntr>1 then tmr=TIMER-tm:msgbox format$(tmr)
            flexit str(),totalstars, uflag     'do the calculations  , clsst1, frthst1, clsst2, frthst2
            'tm=TIMER
            'DIALOG DOEVENTS 2
            'if isfalse showit then
            flashit str(),totalstars, cntr, clrd, clsst1, frthst1, indic, factor, r, frames, slow(), fast() ', wyd, hyt    'show the results
            'elseif istrue showit and cntr=frames then
              'flashit str(),totalstars, cntr, focuss(), clrd, gwin, clsst1, frthst1, indic, factor, r, frames ', wyd, hyt    'show the results
            'end if
            GRAPHIC SET POS (-xwyd+10, -yhyt+10)
            'GRAPHIC PRINT "PRIMARY VIEW"
            GRAPHIC PRINT "Frame # "cntr"/" frames '" of " totalstars " stars"
            GRAPHIC PRINT "   Stars : " totalstars
            GRAPHIC SET POS (xwyd-150, -yhyt+1)
            GRAPHIC COLOR RGB(0,0,25), %BLACK
            GRAPHIC PRINT "Copyright 2012, Rodney Hicks"
            GRAPHIC REDRAW
            GRAPHIC COLOR %MAGENTA, %BLACK
            IF ISTRUE shwno THEN         ' s$ = STRINSERT$(MainStr$, NewStr$, position&)
              IF cntr=1 THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                'msgbox imtemp
              END IF
            ELSE
              IF ISTRUE shwall THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                img=imtemp+"_"+FORMAT$(cntr,"000000")+".BMP"
                GRAPHIC SAVE img
              ELSEIF ISTRUE shwfl AND (cntr=1 OR cntr=frames) THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                img=imtemp+"_"+FORMAT$(cntr,"000000")+".BMP"
                GRAPHIC SAVE img
              END IF
            END IF
          NEXT cntr
    
          MSGBOX "Elapsed time(sec) :"+ FORMAT$(TIMER-tmr)+$CRLF+ "Elapsed time(min) :"+ _
          FORMAT$((TIMER-tmr)/60), %MB_TASKMODAL
     Jumpin:
          GRAPHIC ATTACH ggwin, 0,REDRAW
          ftmr=TIMER
          FOR cntr=1 TO frames
            GRAPHIC CLEAR %BLACK
            circlet (xxx, yyy, r, RGB(45,45,45))
            circlet (xxx, yyy, (r/2), RGB(45,45,45))
    '      temp      = uf/(dx*dx+dy*dy+dz*dz)  'calc acceleration of the smallest mass
    '      tem1      = temp*@s2.unts        'assign to complete mass of the first of the pair
    '      tem2      = -temp*@s1.unts       'assign to complete mass of the second body with opposite direction (-)
    '      @s1.velx  = @s1.velx+(tem1)*dx
    '      @s1.vely  = @s1.vely+(tem1)*dy
    '      @s1.velz  = @s1.velz+(tem1)*dz
    '      @s2.velx  = @s2.velx+(tem2)*dx
    '      @s2.vely  = @s2.vely+(tem2)*dy
    '      @s2.velz  = @s2.velz+(tem2)*dz
    '    NEXT cntd
    '    @s1.x     = @[email protected]
    '    @s1.y     = @[email protected]
    '    @s1.z     = @[email protected]
            FOR cnts = 0 TO totalstars
              st=VARPTR(fstr(cnts))
              IF cnts<>totalstars THEN
                temp=uflag/(@st.x*@[email protected]*@[email protected]*@st.y)*@st.allun
                @[email protected]+temp*@st.x
                @[email protected]+temp*@st.z
                @[email protected]+temp*@st.y
                @[email protected][email protected]
                @[email protected][email protected]
                @[email protected][email protected]
              END IF
              IF indic=1 THEN
                IF ABS(@st.velx)+ABS(@st.vely)+ABS(@st.velz)<100550050000000  THEN   '0  35550050000000
                  circle ((@st.x*(1/factor)+xxx), (@st.z*(1/factor)+yyy), 1, clrd)
                END IF
              ELSEIF indic=2 THEN
                IF ABS(@st.velx)+ABS(@st.vely)+ABS(@st.velz)<100550050000000  THEN   '0  35550050000000
                  circle ((@st.x*(1/factor)+xxx), (@st.z*(1/factor)+yyy), 1, clrd)
                END IF
                'circle (@st.x*(1/factor), @st.z*(1/factor), 1, @st.colr)
                GRAPHIC SET PIXEL (@st.x*(1/factor)+xxx, @st.z*(1/factor)+yyy), @st.colr
              ELSE
                'circle (@st.x*(1/factor), @st.z*(1/factor), (1893404160000000*1), @st.colr)
                GRAPHIC SET PIXEL (@st.x*(1/factor)+xxx, @st.z*(1/factor)+yyy), @st.colr
              END IF
    
            NEXT cnts
            st=VARPTR(fstr(clsst1))
            circle ((@st.x*(1/factor)+xxx),(@st.z*(1/factor)+yyy), 2, %CYAN)
            st=VARPTR(fstr(frthst1))
            circle ((@st.x*(1/factor)+xxx), (@st.z*(1/factor)+yyy), 2, %GREEN)
            GRAPHIC SET POS (-xwyd+10, -yhyt+10)
            'GRAPHIC PRINT "PRIMARY VIEW"
            GRAPHIC PRINT "Frame # "cntr"/" frames '" of " totalstars " stars"
            GRAPHIC PRINT "   Stars : " totalstars
            GRAPHIC SET POS (xwyd-150, -yhyt+1)
            GRAPHIC COLOR RGB(0,0,25), %BLACK
            GRAPHIC PRINT "Copyright 2012, Rodney Hicks"
            GRAPHIC REDRAW
            GRAPHIC COLOR %MAGENTA, %BLACK
            IF ISTRUE shwno THEN         ' s$ = STRINSERT$(MainStr$, NewStr$, position&)
              IF cntr=1 THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                'msgbox imtemp
              END IF
            ELSE
              IF ISTRUE shwall THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                img=imtemp+"_"+FORMAT$(cntr,"000000")+".BMP"
                GRAPHIC SAVE img
              ELSEIF ISTRUE shwfl AND (cntr=1 OR cntr=frames) THEN
                imtemp=dattim
                imtemp=STRINSERT$(imtemp,"_",9)
                imtemp="spi_"+imtemp
                img=imtemp+"_"+FORMAT$(cntr,"000000")+".BMP"
                GRAPHIC SAVE img
              END IF
            END IF
          NEXT cntr
          MSGBOX "Elapsed time(sec) :"+ FORMAT$(TIMER-ftmr)+$CRLF+ "Elapsed time(min) :"+ _
          FORMAT$((TIMER-ftmr)/60)+$CRLF+"Frames/sec :"+FORMAT$(frames/(TIMER-ftmr)), %MB_TASKMODAL
          DIALOG NORMALIZE CB.HNDL
        CASE %WM_COMMAND
          ' Process control notifications
          SELECT CASE AS LONG CB.CTL
            CASE %IDC_HIGHLIGHTOPT
    
            CASE %IDC_LOWLIGHTOPT
    
            CASE %IDC_NEITHEROPT
    
            CASE %IDC_YELLOWHILO
    
            CASE %IDC_MAGENTAHILO
    
            CASE %IDC_CYANHILO
    
            CASE %IDC_WHITEHILO
    
            CASE %IDC_YELLOWSOPT
    
            CASE %IDC_MAGENTASOPT
    
            CASE %IDC_GREENSOPT
    
            CASE %IDC_BLUESOPT
    
            CASE %IDC_GRAYSOPT
    
            CASE %IDC_MIXTURESOPT
    
            CASE %IDC_YELLOWSOPT2
    
            CASE %IDC_MAGENTASOPT2
    
            CASE %IDC_GREENSOPT2
    
            CASE %IDC_BLUESOPT2
    
            CASE %IDC_GRAYSOPT2
    
            CASE %IDC_MIXTURESOPT2
    
            CASE %IDC_START
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                DIALOG POST CB.HNDL, %WM_USER + 200, 0, 0
                'MSGBOX "%IDC_START=" + FORMAT$(%IDC_START), %MB_TASKMODAL
              END IF
    
            CASE %IDC_STARSPERCLUSTER
    
            CASE %IDC_FRAMES
    
            CASE %IDC_SAVEALL
    
            CASE %IDC_SAVEFIRSTLAST
    
            CASE %IDC_SAVENO
    
            CASE %IDC_SHOWFINALFRAMEONLY
    
            CASE %IDCANCEL
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                GRAPHIC WINDOW END gwin
                DIALOG END CB.HNDL, 0
              END IF
    
            CASE %IDC_CLOCKWISE
    
            CASE %IDC_COUNTERCLOCKWISE
    
          END SELECT
      END SELECT
    END FUNCTION
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    '   ** Dialogs **
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
      LOCAL lRslt  AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG2->->
      LOCAL hDlg   AS DWORD
      LOCAL hFont1 AS DWORD
    
      DIALOG NEW PIXELS, hParent, "", 124, 485, 600, 223, %WS_POPUP OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
        %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
      DIALOG  SET COLOR     hDlg, %WHITE, %BLACK
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_HIGHLIGHTOPT, "Highlight", 96, 48, 75, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_NOTIFY OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_HIGHLIGHTOPT, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_LOWLIGHTOPT, "Lowlight", 96, 64, 75, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR _
        %BS_NOTIFY OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LOWLIGHTOPT, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_NEITHEROPT, "Neither", 96, 80, 75, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR _
        %BS_NOTIFY OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_NEITHEROPT, %WHITE, -2
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_YELLOWHILO, "Dark Red", 208, 48, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_YELLOWHILO, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_MAGENTAHILO, "Purple", 208, 64, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_MAGENTAHILO, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_CYANHILO, "Gold", 208, 80, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_CYANHILO, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_WHITEHILO, "Gray", 208, 96, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_WHITEHILO, %WHITE, -2
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_YELLOWSOPT, "Yellows", 320, 48, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_YELLOWSOPT, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_MAGENTASOPT, "Magentas", 320, 64, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_MAGENTASOPT, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_GRAYSOPT, "Grays", 320, 80, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_GRAYSOPT, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_MIXTURESOPT, "Mixtures", 320, 96, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_MIXTURESOPT, %WHITE, -2
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_YELLOWSOPT2, "Yellows", 432, 48, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_YELLOWSOPT2, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_MAGENTASOPT2, "Magentas", 432, 64, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_MAGENTASOPT2, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_GRAYSOPT2, "Grays", 432, 80, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_GRAYSOPT2, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_MIXTURESOPT2, "Mixtures", 432, 96, 80, 16
      CONTROL SET COLOR     hDlg, %IDC_MIXTURESOPT2, %WHITE, -2
      ' %WS_GROUP...
      CONTROL ADD BUTTON,   hDlg, %IDC_START, "Start", 360, 184, 123, 24, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR %BS_PUSHBUTTON OR _
        %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL ADD TEXTBOX,  hDlg, %IDC_STARSPERCLUSTER, "2500", 8, 184, 150, 21, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_CENTER OR %ES_AUTOHSCROLL OR _
        %ES_NUMBER, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
      CONTROL ADD TEXTBOX,  hDlg, %IDC_FRAMES, "10000", 200, 184, 150, 21, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_CENTER OR %ES_AUTOHSCROLL OR %ES_NUMBER, _
        %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_SAVEALL, "Save all Bitmaps", 208, 128, 175, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_SAVEALL, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_SAVEFIRSTLAST, "Save First/Last Bitmaps", 208, 144, 175, 16
      CONTROL SET COLOR     hDlg, %IDC_SAVEFIRSTLAST, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_SAVENO, "Save No Bitmaps", 392, 128, 175, 16
      CONTROL SET COLOR     hDlg, %IDC_SAVENO, %WHITE, -2
      ' %WS_GROUP...
     ' CONTROL ADD CHECKBOX, hDlg, %IDC_SHOWFINALFRAMEONLY, "Show Final Frame Only", 400, 160, 160, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR _
       ' %BS_TEXT OR %BS_AUTOCHECKBOX OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_SHOWFINALFRAMEONLY, %WHITE, -2
      CONTROL ADD BUTTON,   hDlg, %IDCANCEL, "Exit", 520, 184, 75, 24
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL2, "Stars per cluster", 8, 168, 150, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL2, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL3, "Frames", 200, 168, 150, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL3, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL4, "Indicator", 96, 32, 75, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL4, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL5, "Cluster 1", 320, 32, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL5, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL6, "Cluster 2", 432, 32, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL6, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL7, "Colours", 208, 32, 80, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL7, %WHITE, -2
      ' %WS_GROUP...
      CONTROL ADD OPTION,   hDlg, %IDC_CLOCKWISE, "Clockwise", 48, 128, 150, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR %WS_TABSTOP OR %BS_TEXT OR _
        %BS_AUTORADIOBUTTON OR %BS_LEFT OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_CLOCKWISE, %WHITE, -2
      CONTROL ADD OPTION,   hDlg, %IDC_COUNTERCLOCKWISE, "Counter-Clockwise", 48, 144, 150, 16
      CONTROL SET COLOR     hDlg, %IDC_COUNTERCLOCKWISE, %WHITE, -2
      CONTROL ADD FRAME,    hDlg, %IDC_FRAME1, "", 88, 16, 208, 104
      CONTROL SET COLOR     hDlg, %IDC_FRAME1, %WHITE, -2
      CONTROL ADD FRAME,    hDlg, %IDC_FRAME2, "", 312, 16, 208, 104
      CONTROL SET COLOR     hDlg, %IDC_FRAME2, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL9, "Slowest Moving", 88, 8, 208, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL9, %WHITE, -2
      CONTROL ADD LABEL,    hDlg, %IDC_LABEL10, "Star Colours", 312, 8, 208, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING
      CONTROL SET COLOR     hDlg, %IDC_LABEL10, %WHITE, -2
    
      FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
    
      CONTROL SET FONT hDlg, %IDC_HIGHLIGHTOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_LOWLIGHTOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_NEITHEROPT, hFont1
      CONTROL SET FONT hDlg, %IDC_YELLOWHILO, hFont1
      CONTROL SET FONT hDlg, %IDC_MAGENTAHILO, hFont1
      CONTROL SET FONT hDlg, %IDC_CYANHILO, hFont1
      CONTROL SET FONT hDlg, %IDC_WHITEHILO, hFont1
      CONTROL SET FONT hDlg, %IDC_YELLOWSOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_MAGENTASOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_GREENSOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_MIXTURESOPT, hFont1
      CONTROL SET FONT hDlg, %IDC_YELLOWSOPT2, hFont1
      CONTROL SET FONT hDlg, %IDC_MAGENTASOPT2, hFont1
      CONTROL SET FONT hDlg, %IDC_GREENSOPT2, hFont1
      CONTROL SET FONT hDlg, %IDC_MIXTURESOPT2, hFont1
      CONTROL SET FONT hDlg, %IDC_START, hFont1
      CONTROL SET FONT hDlg, %IDC_STARSPERCLUSTER, hFont1
      CONTROL SET FONT hDlg, %IDC_FRAMES, hFont1
      CONTROL SET FONT hDlg, %IDC_SAVEALL, hFont1
      CONTROL SET FONT hDlg, %IDC_SAVEFIRSTLAST, hFont1
      CONTROL SET FONT hDlg, %IDC_SAVENO, hFont1
      CONTROL SET FONT hDlg, %IDC_SHOWFINALFRAMEONLY, hFont1
      CONTROL SET FONT hDlg, %IDCANCEL, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL2, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL3, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL4, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL5, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL6, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL7, hFont1
      CONTROL SET FONT hDlg, %IDC_CLOCKWISE, hFont1
      CONTROL SET FONT hDlg, %IDC_COUNTERCLOCKWISE, hFont1
      CONTROL SET FONT hDlg, %IDC_FRAME1, hFont1
      CONTROL SET FONT hDlg, %IDC_FRAME2, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL9, hFont1
      CONTROL SET FONT hDlg, %IDC_LABEL10, hFont1
    #PBFORMS END DIALOG
        CONTROL SHOW STATE hDlg, %IDC_SAVEALL, %SW_HIDE
      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG2Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG2
      FONT END hFont1
    #PBFORMS END CLEANUP
    
      FUNCTION = lRslt
    END FUNCTION
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    FUNCTION Dater() COMMON AS STRING
      dater=RIGHT$(DATE$,4)+"-"+LEFT$(DATE$,5)  'changes MM-DD-YYYY to YYYY-MM-DD SLL format
    END FUNCTION
    
    FUNCTION datel() COMMON AS STRING
      datel=REMOVE$(dater,"-")                  'changes YYYY-MM-DD to YYYYMMDD SLL format
    END FUNCTION
    
    FUNCTION dattim() COMMON AS STRING
      dattim= datel+REMOVE$(TIME$,":")          'creates a YYYYMMDDHHMMSS string SLL format
    END FUNCTION
    
    SUB fillculler(clust1 AS LONG, clust2 AS LONG, clr1() AS LONG, clr2() AS LONG)
      LOCAL cnts,ar, ge, be,c1, c2 AS LONG
      ar=99
      ge=99
      be=99
      SELECT CASE AS LONG clust1
        CASE 1
          ar =86
          ge =86
          be =0
        CASE 2
          ar =86
          ge =0
          be =86
        CASE 3
          ar =0
          ge =86
          be =0
        CASE 4
          ar =0
          ge =0
          be =86
        CASE 5
          ar =73
          ge =73
          be =73
        CASE 6
          ar =(RND(1,13))*13+86
          ge =(RND(1,13))*13+86
          be =(RND(1,13))*13+86
      END SELECT
      FOR cnts=1 TO 13
        IF clust1<6 THEN
          IF ISTRUE ar THEN
            ar+=(cnts*13)
          END IF
          IF ISTRUE ge THEN
            ge+=(cnts*13)
          END IF
          IF ISTRUE be THEN
            be+=(cnts*13)
          END IF
          clr1(cnts)=RGB(ar,ge,be)
        ELSE
          ar =(RND(1,13))*13+86
          ge =(RND(1,13))*13+86
          be =(RND(1,13))*13+86
          clr1(cnts)=RGB(ar,ge,be)
        END IF
      NEXT cnts
      SELECT CASE AS LONG clust2
        CASE 1
          ar =86
          ge =86
          be =0
        CASE 2
          ar =86
          ge =0
          be =86
        CASE 3
          ar =0
          ge =86
          be =0
        CASE 4
          ar =0
          ge =0
          be =86
        CASE 5
          ar =73
          ge =73
          be =73
        CASE 6
          ar =(RND(1,13))*13+86
          ge =(RND(1,13))*13+86
          be =(RND(1,13))*13+86
      END SELECT
      FOR cnts=1 TO 13
        IF clust2<6 THEN
          IF ISTRUE ar THEN
            ar+=(cnts*13)
          END IF
          IF ISTRUE ge THEN
            ge+=(cnts*13)
          END IF
          IF ISTRUE be THEN
            be+=(cnts*13)
          END IF
          clr2(cnts)=RGB(ar,ge,be)
        ELSE
          ar =(RND(1,13))*13+86
          ge =(RND(1,13))*13+86
          be =(RND(1,13))*13+86
          clr2(cnts)=RGB(ar,ge,be)
        END IF
      NEXT cnts
    END SUB
    SUB filler(gwin AS LONG, ggwin AS LONG, str() AS star,tp AS LONG, hilo AS LONG, clust1 AS LONG, clust2 AS LONG, factor AS DOUBLE, spn AS LONG)
      LOCAL inky AS STRING
      LOCAL pn, nn, kolour, kolour2, weit, cntr, zspd, xspd, yspd, bh AS LONG
      LOCAL xloc, ln, yloc, zloc, dist, pi, dst, sol, velm AS DOUBLE
      LOCAL angl AS SINGLE
      LOCAL clr1(), clr2() AS LONG
      DIM clr1(13), clr2(13)
      fillculler clust1,clust2,clr1(),clr2()
      bh=1
      pi = 4 * ATN(1)
      sol= 1.989e30
    
      pn=1
      'IF ISTRUE bh THEN
        dst=SQR((200343072000000000^2)/2)               '260343072000000000
        velm= 90000000000000             ' 17500000000000
      'ELSE
      '  dst=SQR((189340416000000000^2)/2)
      '  velm= 100000000
      'END IF
      FOR cntr=0 TO tp
        nn=RND(1,2)
        IF nn=2 THEN
        nn=-1
        END IF
        ln=RND(0,2147483647)*30000000
        pn=pn * -1
        weit=RND(1,10)
        IF weit=10 THEN
          weit=RND(10,1600)
        END IF
        IF weit=160 THEN
          weit=RND(1600, 2500)
        END IF
        IF cntr=tp AND bh=1 THEN
          weit=1500000000'0
        END IF
        IF pn=1 THEN
          kolour2 = %CYAN
        ELSE
          kolour2 = %WHITE
        END IF
        SELECT CASE AS LONG weit
          CASE 1 TO 9
            IF pn=1 THEN
              kolour  = clr1(weit)
            ELSE
              kolour  = clr2(weit)
            END IF
    '      CASE 2
    '        IF pn=1 THEN
    '          kolour= RGB(138,138,000)
    '        ELSE
    '          kolour= RGB(138,000,138)
    '        END IF
    '      CASE 3
    '        IF pn=1 THEN
    '          kolour= RGB(151,151,000)
    '        ELSE
    '          kolour= RGB(151,000,151)
    '        END IF
    '      CASE 4
    '        IF pn=1 THEN
    '          kolour= RGB(164,164,000)
    '        ELSE
    '          kolour= RGB(164,000,164)
    '        END IF
    '      CASE 5
    '        IF pn=1 THEN
    '          kolour= RGB(177,177,000)
    '        ELSE
    '          kolour= RGB(177,000,177)
    '        END IF
    '      CASE 6
    '        IF pn=1 THEN
    '          kolour= RGB(190,190,000)
    '        ELSE
    '          kolour= RGB(190,000,190)
    '        END IF
    '      CASE 7
    '        IF pn=1 THEN
    '          kolour= RGB(203,203,000)
    '        ELSE
    '          kolour= RGB(203,000,203)
    '        END IF
    '      CASE 8
    '        IF pn=1 THEN
    '          kolour= RGB(216,216,000)
    '        ELSE
    '          kolour= RGB(216,000,216)
    '        END IF
    '      CASE 9
    '        IF pn=1 THEN
    '          kolour= RGB(229,229,000)
    '        ELSE
    '          kolour= RGB(229,000,229)
    '        END IF
          CASE 10 TO 399
            IF pn=1 THEN
              kolour= clr1(10)
            ELSE
              kolour= clr2(10)
            END IF
          CASE 400 TO 799
            IF pn=1 THEN
              kolour= clr1(11)
            ELSE
              kolour= clr2(11)
            END IF
          CASE 800 TO 1199
            IF pn=1 THEN
              kolour= clr1(12)
            ELSE
              kolour= clr2(12)
            END IF
          CASE 1200 TO 1599
            IF pn=1 THEN
              kolour= clr1(13)
            ELSE
              kolour= clr2(13)
            END IF
          CASE 1600 TO 2500
            kolour=%WHITE
          CASE >2500
            kolour=%RGB_IVORY
        END SELECT
        IF cntr<tp OR bh=0 THEN
          angl=RND(0,36000)/100            'angle from the cluster centre
          dist=RND*108870739200000000   '108870739200000000    ' increasing this moves the clusters apart
          xspd=RND(-10000,10000)           'random velocities with the cluster   not optimized
          zspd=RND(-10000,10000)           'random velocities with the cluster   not optimized
          yspd=RND(-10000,10000)           'random velocities with the cluster   not optimized
          str(cntr).x      = (pn*dst)+dist*COS(angl*pi/180)+(ln*pn)  'initial x location in cluster
          str(cntr).z      = (ln*pn)+((pn*dst)+dist*SIN(angl*pi/180))    'initial z location in cluster
          str(cntr).y      = RND*32335104000000000*pn*nn'(pn*dst)+dist*sin(angl*pi/180)   'initial y location in cluster
          IF spn=0 THEN
            str(cntr).velz   = zspd+pn*-1* velm  'velocity against the background
            str(cntr).velx   = xspd                    'RND*47335104000000000*pn
          ELSE
            str(cntr).velz   = zspd  'velocity against the background
            str(cntr).velx   = xspd+pn*-1* velm
          END IF
          str(cntr).vely   = yspd
          str(cntr).mass   = weit/10*sol
          str(cntr).colr   = kolour
          str(cntr).hilite = kolour2
        ELSEIF cntr=tp AND bh=1 THEN
          str(cntr).x      = 0'(pn*dst/2)+dist*COS(angl*pi/180)  'initial x location in cluster
          str(cntr).z      = 0'(pn*dst)+dist*SIN(angl*pi/180)    'initial z location in cluster
          str(cntr).y      = 0'RND*47335104000000000*pn          'initial y location in cluster
          str(cntr).velz   = 0'zspd+pn*-1* 78125000000   'velocity against the background
          str(cntr).velx   = 0'xspd
          str(cntr).vely   = 0'yspd
          str(cntr).mass   = weit/10*sol
          str(cntr).colr   = kolour
          str(cntr).hilite = kolour2
        END IF
        GRAPHIC SET PIXEL ((str(cntr).x)/factor,(str(cntr).z)/factor), str(cntr).colr
    
      NEXT cntr
      GRAPHIC REDRAW
      GRAPHIC ATTACH ggwin,0, REDRAW
      FOR cntr=0 TO tp
        GRAPHIC SET PIXEL ((str(cntr).x)/factor,(str(cntr).z)/factor), str(cntr).colr
      NEXT cntr
      GRAPHIC REDRAW
      GRAPHIC ATTACH gwin, 0,REDRAW
    END SUB
    SUB flexit(str() AS star, tp AS DWORD, uf AS DOUBLE)
      LOCAL cntr, cntd AS LONG
      LOCAL temp, tem1, tem2, dx, dy, dz, duh AS DOUBLE
      STATIC s1, s2 AS star PTR
    
      FOR cntr=0 TO tp-1
        s1  = VARPTR (str(cntr))
        FOR cntd=cntr+1 TO tp
          s2        = VARPTR (str(cntd))
          dx        = @[email protected]
          dy        = @[email protected]
          dz        = @[email protected]
          temp      = uf/(dx*dx+dy*dy+dz*dz)  'calc acceleration of the smallest mass
          tem1      = temp*@s2.unts        'assign to complete mass of the first of the pair
          tem2      = -temp*@s1.unts       'assign to complete mass of the second body with opposite direction (-)
          @s1.velx  = @s1.velx+(tem1)*dx
          @s1.vely  = @s1.vely+(tem1)*dy
          @s1.velz  = @s1.velz+(tem1)*dz
          @s2.velx  = @s2.velx+(tem2)*dx
          @s2.vely  = @s2.vely+(tem2)*dy
          @s2.velz  = @s2.velz+(tem2)*dz
        NEXT cntd
        @s1.x     = @[email protected]
        @s1.y     = @[email protected]
        @s1.z     = @[email protected]
    
      NEXT cntr
      s1        = VARPTR (str(tp))
      @s1.x     = @[email protected]
      @s1.y     = @[email protected]
      @s1.z     = @[email protected]
    END SUB
    
    
    SUB flashit(str() AS star,ttp AS DWORD, cnt AS LONG, _
          hili AS LONG, clsst1 AS LONG, frthst1 AS LONG, _
               ind AS LONG, fctr AS DOUBLE, rrr AS DOUBLE, frames AS LONG, _
               slow() AS locator, fast() AS locator)', wyd as double, hyt as double)
      LOCAL cnts,cntd AS LONG
      LOCAL xxx, yyy AS DOUBLE
      LOCAL st AS star PTR
    'circle (xxx,yyy,rrr,%BLACK)
      GRAPHIC CLEAR %BLACK
            circlet (xxx, yyy, rrr, RGB(45,45,45))
            circlet (xxx, yyy, (rrr/2), RGB(45,45,45))
            FOR cnts = 0 TO ttp
              st=VARPTR(str(cnts))
              IF ind=1 THEN
                IF ABS(@st.velx)+ABS(@st.vely)+ABS(@st.velz)<55550050000000  THEN   '0  35550050000000
                  circle ((@st.x*(1/fctr)+xxx), (@st.z*(1/fctr)+yyy), 1, hili)
                END IF
              ELSEIF ind=2 THEN
                IF ABS(@st.velx)+ABS(@st.vely)+ABS(@st.velz)<55550050000000  THEN   '0  35550050000000
                  circle ((@st.x*(1/fctr)+xxx), (@st.z*(1/fctr)+yyy), 1, hili)
                END IF
                'circle (@st.x*(1/fctr), @st.z*(1/fctr), 1, @st.colr)
                GRAPHIC SET PIXEL (@st.x*(1/fctr)+xxx, @st.z*(1/fctr)+yyy), @st.colr
              ELSE
                'circle (@st.x*(1/fctr), @st.z*(1/fctr), (1893404160000000*1), @st.colr)
                GRAPHIC SET PIXEL (@st.x*(1/fctr)+xxx, @st.z*(1/fctr)+yyy), @st.colr
              END IF
            NEXT cnts
            st=VARPTR(str(clsst1))
            circle ((@st.x*(1/fctr)+xxx),(@st.z*(1/fctr)+yyy), 2, %CYAN)
            st=VARPTR(str(frthst1))
            circle ((@st.x*(1/fctr)+xxx), (@st.z*(1/fctr)+yyy), 2, %GREEN)
      ' GRAPHIC SET POS (-190, -190)
            'GRAPHIC PRINT "PRIMARY VIEW"
      ' GRAPHIC PRINT "Frame # "cnt"/" frames " of " ttp " stars"
      'GRAPHIC REDRAW
    END SUB
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

  • #2
    Okay, I'll ask a different question.

    Why would a program speed up when it loses focus?
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      Hi Rodney!
      If the program was doing a lot of graphical/screen updates/redraws/refreshes, those actions could take away from the OS time available to do background actions.

      Likewise, any other application that takes OS time will slow yours down. I'd think a web browser would be a likely candidate for needing OS time.

      Comment


      • #4
        But, running a test ...

        FireFox jumps CPU usage by about 10%. Not exactly a CPU hog.

        Also, RAM usage jumps up a few hundred MB when starting FireFox. Not a RAM hog either.

        What do you get on your system? I used TaskManager to check.

        Comment


        • #5
          On my system, with or without FireFox, I get 64 frames/sec.

          Win7
          i7860
          4GB
          64Bit

          Comment


          • #6
            Originally posted by Rodney Hicks View Post
            Why would a program speed up when it loses focus?
            Because it doesn't have to deal with screen updates.
            There are no atheists in a fox hole or the morning of a math test.
            If my flag offends you, I'll help you pack.

            Comment


            • #7
              @Gary, did you try it with Solitaire or Hearts running with the focus on the game? Nothing seems to be slowing it down, only the opposite. With just the PB IDE and the app, I get the 64 frames/second. With more programs running, but the app having focus, I get 64 frames/second. Only when the focus is on those games with the app running in the background(visible) do I get increased speeds. There may be other programs that speed the app up.

              @Mel, that makes sense for the increased speed when the app is minimized but not for the times when Solitaire or Hearts are running and the program is showing in the background.

              Thanks for looking at it!!
              Last edited by Rodney Hicks; 7 Jul 2013, 12:02 AM.
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                Rodney,
                although I get near enough 100fps with your code on my PC regardless, this does sound like the old timeslice-speed problem.

                When graphics are drawn, the current timeslice is given up at the end of the draw so any time remaining is lost to your program. The code then resumes on the next time slice.
                Just for illustration, suppose the timeslices are 20ms and the code takes 5ms per draw then you can spend 5ms drawing followed by 15ms idle before the next time slice arrives and you get to draw something again.

                When the window is picked up or the mouse is moved over the window, the window is forced to redraw immediately so it get's an extra go at drawing which speeds things up.
                Also, other code can increase the redraw speed by, for example, using TimeBeginPeriod()/TimeEndPeriod(). If the other program was to change the timeslice to 10ms then your code could now spend 5ms drawing and 5ms waiting before the next 5ms drawing. That's twice as fast.

                I haven't checked your code to see if that's the problem but it's where I would investigate first.

                Paul.

                Comment


                • #9
                  Rodney,
                  When I start Solitaire and give it the focus, your app speed jumps up to 200 fps (from 64fps).

                  Comment


                  • #10
                    Thanks Gary and Paul!
                    @Gary, I needed to know if others or at least some percentage of others got the same issue.
                    @Paul, the TimeBeginPeriod()/TimeEndPeriod() makes a certain amount of sense, but I never thought about anything like that. I shall investigate and report back.

                    Thanks all!
                    Rod
                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                    Comment


                    • #11
                      Having run a few tests with the TimeBeginPeriod()/TimeEndPeriod() pair I think Paul was right on with his assessment.
                      Some numbers
                      TimeBeginPeriod(20) 64.144 fps
                      TimeBeginPeriod(10) 146.636 fps
                      TimeBeginPeriod(7) 152.828 fps
                      TimeBeginPeriod(5) 153.489 fps
                      TimeBeginPeriod(3) 152.230 fps
                      TimeBeginPeriod(1) 154.256 fps

                      The settings 7,5,3,1 all drop to ~140 fps when Solitare is running with focus
                      At 10 the rate drops to 136 fps
                      At 20 I get the same treatment I started this thread with.
                      I think I'll go with the 7 setting for now until I've done more testing anyhow.

                      Thanks Paul for the direction, and thanks all for your input!
                      Rod
                      I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                      Comment


                      • #12
                        Hi Rod.

                        I've messing around with TimeBeginPeriod lately and have been searching Poffs for programs to test using this API and came across this thread.

                        On Win7, and probably others, TimeBeginPeriod(n) only makes sense for n = 1, 2, 3, 5, 10 and 16 with time slices of 1ms, 1.25ms, 2.5ms, 5ms, 10ms and 16ms respectively.

                        When you decided to go for 7 you were actually given 5, the nearest valid number below.

                        In this thread at post #2 there is an app which will change the time slice on the fly and the value may be set from a command line; see the following post. I have put a shortcut on my desktop called MTR. So, "C:\PBWin\Timers\MaximizeTimerResolution.exe /Res: 10000" will do what TimeBeginPeriod(1) does in your applications.

                        With your code in the opening post, or any other app, running then let it run for a while just to 'get a feel' and then double click on MTR to see what difference there is. If you have a Chromium based browser running at the time then close it down because it changes the time slice to 1ms as soon as it opens. This is quite handy as you can test executables without having to introduce TimeBeginPeriod to their source code and then recompile.

                        Your above code was handy for me in another aspect. I changed all the RND(a,b) to CryptoR(a,b) and RND to CryptoS with varying buffer sizes to see what different stutter periods make. Using Crypto* dispenses with seeding the PRNG and has no period. So far, stuttering seems to be academic but none of this won't make any sense if this thread hasn't been visited.

                        Incidentally, why didn't you use Randomize?

                        Added:

                        With differing MTR values this is what I get on my machine.

                        Code:
                        5000   250
                        10000  250
                        12500  265
                        50000  200
                        100000 100
                        156000 64
                        I ran that 12500 (1.25ms) a few times. I was hoping to see an increase with 5000 ( 0.5ms ) but the only thing that I have seen to benefit from that is Sleep which is made to have a resolution of 0.5ms; which TimeBeginPeriod cannot give us, MTR uses NtSetTimerResolution.
                        Last edited by David Roberts; 25 Aug 2014, 10:00 AM.

                        Comment


                        • #13
                          but none of this won't make any sense if this thread hasn't been visited.
                          I have been lurking!

                          Incidentally, why didn't you use Randomize?
                          Probably because I thought it was already in there, since that program was copied from a previous, which was copied from a previous, which.... A well, 'Something's lost and something's gained in living every day.' she sang(Joni Mitchell-Both Sides Now)

                          I will be revisiting this thread and the other, but not before I've picked up my octo-core machine, and I'm kinda hoping that Windows 9 is out when I do, so I've been stalling on the purchase.
                          On Win7, and probably others, TimeBeginPeriod(n) only makes sense for n = 1, 2, 3, 5, 10 and 16 with time slices of 1ms, 1.25ms, 2.5ms, 5ms, 10ms and 16ms respectively.
                          IIRC I thought the sequence might be 1, 3, 7, 15 but I didn't want to dig in to find out because I was trying to maintain my focus on other issues and not get sidetracked.

                          T'is good to know, for soon I'll need all of this again. Thanks!!
                          Rod
                          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                          Comment


                          • #14
                            What exactly are you trying to achieve?

                            All the stuff about minimizing and running Solitaire and doing Windows updates and napping is just so much fluff. Your application should perform similarly regardless of what else is running, and if that does not occur 'naturally' then I guess you are going to have to "do something" to make it so.

                            That said, you may not have enough hardware to do what you WANT to do. There are only so many CPU cycles available each second, and your job has to share with other processes (albeit you have a little control over that but none which come with a free lunch).


                            When I ran it (post is missing the "flasher" icon so I am not sure if that is fatal to whatever you are showing) and clicked 'start' I got what kind of looked like two galaxies colliding. (Escape did not terminate, I had to Alt+F4).

                            What exactly is the "problem" here?

                            MCM
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Ok, you fooled me, for fair.

                              After the screen went away on Alt+F4, I thought it was all over.

                              But then a few minutes later I got a message box with
                              Code:
                              ---------------------------
                              PowerBASIC
                              ---------------------------
                              Elapsed time(sec) :9223.37203685478
                              
                              Elapsed time(min) :5.7401
                              
                              Frames/sec :29.0354988008339
                              ---------------------------
                              OK   
                              ---------------------------
                              BTW just looking at the math? 5.7 minutes is not even close to 9223 seconds.

                              Are you maybe dividing apples by oranges to get your "frames per second" figure?

                              MCM
                              Michael Mattias
                              Tal Systems Inc. (retired)
                              Racine WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                BTW just looking at the math? 5.7 minutes is not even close to 9223 seconds.
                                Yes, well, it wasn't made to be shut down mid-stride and make me look bad! #*$(&&@! suzi user!
                                (Hint, it's two star fields or clusters that 'collide' and become an obvious spiral galaxy if run with a higher 'Frame' setting. Say 40000)

                                In truth, it was made so I could study different effects, not intended for others to use, and then the issue raised its head and I posted it seeking the reason why.
                                Rod
                                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                Comment


                                • #17
                                  and then the issue raised its head and I posted it seeking the reason why.
                                  And you found it, Rod.

                                  Your application should perform similarly regardless of what else is running
                                  From MSDN with regard TimeBeginPeriod: "This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process." ( My underlining )

                                  Quite a few times in the last weeks or so I have said something along the lines "Don't try this with Chrome running." In my thread above there is a give away with "With your code in the opening post, or any other app, running then let it run for a while just to 'get a feel' and then double click on MTR to see what difference there is."

                                  an obvious spiral galaxy if run with a higher 'Frame' setting. Say 40000
                                  So it is.

                                  Comment


                                  • #18
                                    I program slot-machines with lots of moving graphics. It's jerking heavily until I start firefox in den background(!) and open any webside with animated advertisement banners. Instantly my slots (with focus!) are running smoothly, until I close Firefox. It's a miracle for me.

                                    Comment


                                    • #19
                                      And you found it, Rod.
                                      Yes, I did. Paul pointed me in the right direction and I think I will keep your MTR handy for when I get back at it.
                                      Rod
                                      I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                      Comment


                                      • #20
                                        > #*$(&&@! suzi user!

                                        I'll take that as a compliment. Thank you.
                                        Michael Mattias
                                        Tal Systems Inc. (retired)
                                        Racine WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X