Page 1 of 1

Can someone compile this for me, please? Debug off. Thanks!

Posted: Mon Mar 07, 2005 3:51 am
by fmcpma
; ***********
; SPRITE TEST
; ***********

Gosub set_up
Gosub man_loop; MAIN LOOP
End

; ***********
; SUBROUTINES
; ***********

; 1 SET UP

set_up:
Gosub set_data
Gosub set_hardware
Gosub set_sprites
Return

; 1.1 Data

set_data:
Gosub set_constants
Gosub set_variables
Gosub set_lists
Declare spr_speed()
Return

; 1.1.1 CONSTANTS

set_constants:
#scr_width .l=1024
#scr_height .l= 768
#scr_depth .l= 32
#scr_freq .l= 60
#scr_hor_centre.l=#scr_width /2; SCREEN HORIZONTAL CENTRE
#scr_ver_centre.l=#scr_height/2
red .l=RGB(255, 0, 0)
green .l=RGB( 0,255, 0)
blue .l=RGB( 0, 0,255)
white .l=RGB(255,255,255)
purple .l=RGB(255, 0,255)
#ball .l= 1
#square .l= 2
#triangle .l= 3
#max_sprites .l=1000
#spd_spawn .l= 500; SPEED SPAWN
#spr_size .l= 32; SPRITE SIZE
#second .l=1000
Return

; 1.1.2 VARIABLES

set_variables:
ths_image .l; THIS IMAGE
num_sprites.l
lst_spawn .l; LAST SPAWN
num_frames .l
lst_second .l
fps .l
Return

; 1.1.3 LISTS and ARRAYS

set_lists:
Structure spr_info; SPRITE INFO
id .l
hor_position.l
ver_position.l
hor_speed .l
ver_speed .l
EndStructure
NewList spr.spr_info(); SPRITE
Dim image.l(3)
Return

; 1.2 HARDWARE

set_hardware:
LoadFont(#PB_Any,"fixedsys",16); The ID isn't needed!
InitSprite()
InitKeyboard()
SetRefreshRate(#scr_freq)
OpenScreen(#scr_width,#scr_height,#scr_depth,"Sprite test")
Return

; 1.3 IMAGES

set_sprites:
For ths_image=#ball To #triangle
image(ths_image)=CreateSprite(#PB_Any,32,32)
StartDrawing(SpriteOutput(image(ths_image)))
Select ths_image
Case #ball
Circle(15,15,15,red)
Case #square
Box(0,0,32,32,green)
Case #triangle
LineXY(15, 0, 0,31,purple)
LineXY( 0,31,31,31,purple)
LineXY(31,31,15, 0,purple)
FillArea(15,2,purple,purple)
EndSelect
StopDrawing()
Next ths_image
Return

; 2 MAIN LOOP

man_loop:
lst_second=ElapsedMilliseconds()
Repeat
ClearScreen(0,0,0)
Gosub spn_sprites; SPAWN SPRITES
Gosub drw_sprites; DRAW SPRITES
Gosub clc_fps ; CALCULATE FPS
Gosub prt_panel ; PRINT PANEL
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Return

; 2.1 SPAWN SPRITES

spn_sprites:
If num_sprites<#max_sprites
If ElapsedMilliseconds()-lst_spawn>=#spd_spawn
lst_spawn=ElapsedMilliseconds()
num_sprites+1
LastElement(spr())
AddElement(spr())
spr()\id=CopySprite(image(Random(2)+1),#PB_Any)
spr()\hor_position=#scr_hor_centre
spr()\ver_position=#scr_ver_centre
spr()\hor_speed=spr_speed()
spr()\ver_speed=spr_speed()
EndIf
EndIf
Return

; 2.2 DRAW SPRITES

drw_sprites:
ForEach spr()
spr()\hor_position+spr()\hor_speed
spr()\ver_position+spr()\ver_speed
DisplayTransparentSprite(spr()\id,spr()\hor_position,spr()\ver_position)
If spr()\hor_position<0 Or spr()\hor_position> #scr_width-#spr_size
spr()\hor_speed=-spr()\hor_speed
EndIf
If spr()\ver_position<0 Or spr()\ver_position>#scr_height-#spr_size
spr()\ver_speed=-spr()\ver_speed
EndIf
Next
Return

; 2.3 CALCULATE FPS

clc_fps:
num_frames+1
If ElapsedMilliseconds()-lst_second>=#second
fps=num_frames
num_frames=0
lst_second+#second
EndIf
Return

; 2.4 PRINT PANEL

prt_panel:
StartDrawing(ScreenOutput())
DrawingMode(1)
DrawingFont(FontID())
FrontColor(255,255,255)
Locate(0, 0)
DrawText("SCREEN WIDTH :"+RSet(Str( #scr_width),5))
Locate(0,12)
DrawText("SCREEN HEIGHT:"+RSet(Str(#scr_height),5))
Locate(0,24)
DrawText("SCREEN DEPTH :"+RSet(Str( #scr_depth),5))
Locate(0,36)
DrawText("N. OF SPRITES:"+RSet(Str(num_sprites),5))
Locate(0,48)
DrawText("PROGRAM FPS :"+RSet(Str( fps),5))
StopDrawing()
Return

; *********
; FUNCTIONS
; *********

Procedure.l spr_speed()
result.l
result=Random(5)+1
If Random(1)
result=-result
EndIf
ProcedureReturn result
EndProcedure

Posted: Mon Mar 07, 2005 4:26 am
by dracflamloc
why are we compiling this?

Posted: Mon Mar 07, 2005 7:09 am
by zikitrake
Results:

1024x768x32

More than 350 sprites in screen

FPS: 60


my pc: XP2400,512 RAM, ATI RADEON 9200 (128MB)

Posted: Mon Mar 07, 2005 7:59 am
by blueznl
fist make it bugfree and accoriding to 3.93 syntax

Posted: Mon Mar 07, 2005 8:42 am
by dagcrack
And disable emoticons when posting code with out a code tag!

Posted: Mon Mar 07, 2005 12:02 pm
by GedB
I assume you want to benchmark final compilation before buying. Seems reasonable.

Send me your email address and I'll reply with the exe.

Cleaned up code:

Code: Select all

; ***********
; SPRITE TEST
; ***********

Gosub set_up
Gosub man_loop; MAIN LOOP
End

; ***********
; SUBROUTINES
; ***********

; 1 SET UP

set_up:
   Gosub set_data; Actual constant declarations must be above actual use, so these too.
   Gosub set_hardware
   Gosub set_sprites
Return

; 1.1 Data

set_data:
   Gosub set_constants
   Gosub set_variables
   Gosub set_lists
   Declare spr_speed()
Return

; 1.1.1 CONSTANTS

set_constants:
   #scr_width     =1024
   #scr_height    = 768
   #scr_depth     =  32
   #scr_freq      =  60
   #scr_hor_centre=#scr_width /2; SCREEN HORIZONTAL CENTRE
   #scr_ver_centre=#scr_height/2
    red           =RGB(255,  0,  0)
    green         =RGB(  0,255,  0)
    blue          =RGB(  0,  0,255)
    white         =RGB(255,255,255)
    purple        =RGB(255,  0,255)
   #ball          =   1
   #square        =   2
   #triangle      =   3
   #max_sprites   =1000
   #spd_spawn     = 500; SPEED SPAWN
   #spr_size      =  32; SPRITE SIZE
   #second        =1000
Return

; 1.1.2 VARIABLES

set_variables:
   ths_image  .l; THIS IMAGE
   num_sprites.l
   lst_spawn  .l; LAST SPAWN
   num_frames .l
   lst_second .l
   fps        .l
Return

; 1.1.3 LISTS and ARRAYS

set_lists:
   Structure spr_info; SPRITE INFO
      id          .l
      hor_position.l
      ver_position.l
      hor_speed   .l
      ver_speed   .l
   EndStructure
   NewList spr.spr_info(); SPRITE
   Dim image.l(3)
Return

; 1.2 HARDWARE

set_hardware:
   LoadFont(#PB_Any,"fixedsys",16); The ID isn't needed!
   InitSprite()
   InitKeyboard()
   SetRefreshRate(#scr_freq)
   OpenScreen(#scr_width,#scr_height,#scr_depth,"Sprite test")
Return

; 1.3 IMAGES

set_sprites:
   For ths_image=#ball To #triangle
      image(ths_image)=CreateSprite(#PB_Any,32,32)
      StartDrawing(SpriteOutput(image(ths_image)))
      Select ths_image
         Case #ball
            Circle(15,15,15,red)
         Case #square
            Box(0,0,32,32,green)
         Case #triangle
            LineXY(15, 0, 0,31,purple)
            LineXY( 0,31,31,31,purple)
            LineXY(31,31,15, 0,purple)
            FillArea(15,2,purple,purple)
      EndSelect
      StopDrawing()
   Next ths_image
Return

; 2 MAIN LOOP

man_loop:
   lst_second=ElapsedMilliseconds()
   Repeat
      ClearScreen(0,0,0)
      Gosub spn_sprites; SPAWN SPRITES
      Gosub drw_sprites; DRAW SPRITES
      Gosub clc_fps    ; CALCULATE FPS
      Gosub prt_panel  ; PRINT PANEL
      FlipBuffers(0)
      ExamineKeyboard()
   Until KeyboardPushed(#PB_Key_Escape)
Return

; 2.1 SPAWN SPRITES

spn_sprites:
   If num_sprites<#max_sprites
      If ElapsedMilliseconds()-lst_spawn>=#spd_spawn
         lst_spawn=ElapsedMilliseconds()
         num_sprites+1
         LastElement(spr())
         AddElement(spr())
         spr()\id=CopySprite(image(Random(2)+1),#PB_Any)
         spr()\hor_position=#scr_hor_centre
         spr()\ver_position=#scr_ver_centre
         spr()\hor_speed=spr_speed()
         spr()\ver_speed=spr_speed()
      EndIf
   EndIf
Return

; 2.2 DRAW SPRITES

drw_sprites:
   ForEach spr()
      spr()\hor_position+spr()\hor_speed
      spr()\ver_position+spr()\ver_speed
      DisplayTransparentSprite(spr()\id,spr()\hor_position,spr()\ver_position)
      If spr()\hor_position<0 Or spr()\hor_position> #scr_width-#spr_size
         spr()\hor_speed=-spr()\hor_speed
      EndIf
      If spr()\ver_position<0 Or spr()\ver_position>#scr_height-#spr_size
         spr()\ver_speed=-spr()\ver_speed
      EndIf
   Next
Return

; 2.3 CALCULATE FPS

clc_fps:
   num_frames+1
   If ElapsedMilliseconds()-lst_second>=#second
      fps=num_frames
      num_frames=0
      lst_second+#second
   EndIf
Return

; 2.4 PRINT PANEL

prt_panel:
   StartDrawing(ScreenOutput())
   DrawingMode(1)
   DrawingFont(FontID())
   FrontColor(255,255,255)
   Locate(0, 0)
   DrawText("SCREEN WIDTH :"+RSet(Str( #scr_width),5))
   Locate(0,12)
   DrawText("SCREEN HEIGHT:"+RSet(Str(#scr_height),5))
   Locate(0,24)
   DrawText("SCREEN DEPTH :"+RSet(Str( #scr_depth),5))
   Locate(0,36)
   DrawText("N. OF SPRITES:"+RSet(Str(num_sprites),5))
   Locate(0,48)
   DrawText("PROGRAM FPS  :"+RSet(Str(        fps),5))
   StopDrawing()
Return

; *********
; FUNCTIONS
; *********

Procedure.l spr_speed()
   result.l
   result=Random(5)+1
   If Random(1)
      result=-result
   EndIf
   ProcedureReturn result
EndProcedure
; ExecutableFormat=
; DisableDebugger
; EOF


Posted: Mon Mar 07, 2005 1:59 pm
by thefool
dagcrack wrote:And disable emoticons when posting code with out a code tag!
do not post code without a code tag 8)

Posted: Mon Mar 07, 2005 5:45 pm
by fmcpma
dracflamloc - Because the demo version does not compile with debug off and I need to know if there is a real speed-up when it is turned off. The idea was for someone to send the executable back to me, though... I guess I wasn't very clear.

zikitrake - Thanks for the info; I was expecting to get more sprites on that kind of card, though...

blueznl - It is bug-free as of 3.92. I confess I haven't downloaded the new version.

dagcrack - Yes! I f***ed up good by not enabling code and not disabling emoticons! I am kind of new in this forum. Sorry.

Gedb - Yes, that was the idea. I also thought that my address could be right-clicked from my nick or something, but I see that's not the case. Thanks for your offer and for cleaning up the code (it would be nice and tidy if I had turned code on in the post!) Also, the final Locate() should be (0,48) if it wasn't for the smilie! Could you please fix that? Thanks again. My address is:

fmcpma@hotmail.com

thefool - Will do!

Posted: Mon Mar 07, 2005 6:29 pm
by zikitrake
fmcpma wrote: zikitrake - Thanks for the info; I was expecting to get more sprites on that kind of card, though...
:lol:
I stopped the program when it arrived at 320 FPS. now I have waited for the 1000 sprites and the result stays: 60FPS.

Posted: Tue Mar 08, 2005 1:50 am
by BinoX
I waited for 1000 sprites and it hovered between

100fps and 97fps

sprite test

Posted: Tue Mar 08, 2005 2:20 am
by BillNee
Hi - using the latest version of the program at 1280 x
1024 and flipbuffer(0) I got speeds of:
100 sprites - 245 fps
500 sprites - 146 fps
1000 sprites - 105 fps

Using not as many sprites, say 20, is there an easy way to check for collisions between all of them?
Or do you have to check (1,2-20),(2,3-20),,,(19,20)?
Thought a collision result might give the two sprite numbers that collided.
Thanks for any help>
Bill Nee
'

Posted: Tue Mar 08, 2005 2:00 pm
by thefool
you all have vertical sync off?

edit:

120 sprites: 860 fps

Posted: Tue Mar 08, 2005 5:26 pm
by GedB
I've updated the code.

It now uses FlipBuffer(0) for full speed.