Author Topic: Whats Causing the slow down in this code?  (Read 2401 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Whats Causing the slow down in this code?
« on: October 25, 2018, 11:24:10 am »
So I've started my next project of bringing another of my old QB45 games up to QB64 and I'm encountering a problem right off the bat.
The code that displays the enemy ship slows way down. on my antiquated machine I start out around 110 cycles a second, but when it starts to display the ship graphics the number plummets down to the mid to upper 30s, that is nearly a loss of 70-75% cycle speed! and that is all this code does, I haven't even started with the AI logic for this ship to shoot at the player or any of the players side! It ran just find in QB45 with DirectQB no speed issues then with all the code working. So what is causing the major performance hit now? I've tried to cut off anything that doesn't display on screen so its not wasting time there but does not seemed to have helped.

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.  Xsize AS _BYTE 'ship size X
  3.  Ysize AS _BYTE 'ship size Y
  4.  Engines AS _BYTE 'Engines remaining 0-4
  5.  Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.  Silos AS _BYTE 'Silos remaining 0-5
  7.  ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.  Ships AS _BYTE 'Dreadnaughts destroied
  10.  Score AS _UNSIGNED LONG 'Players score
  11.  Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.  Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.  Xpos AS INTEGER
  15.  Ypos AS INTEGER
  16.  Speed AS INTEGER
  17.  ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.  Xpos AS INTEGER
  20.  Ypos AS INTEGER
  21.  Kind AS _BYTE
  22.  Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. SCREEN _NEWIMAGE(640, 480, 32)
  34. Layer(0) = _LOADIMAGE("DFsprit8.bmp") '  Sprite Layer
  35. Layer(1) = _DISPLAY
  36. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  37. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. Xloc% = 1000: start! = TIMER
  48.  DrawDreadnaught Xloc%, -32, 2
  49.  IF TIMER >= start! + 1 THEN f% = c%: start! = TIMER: c% = 0
  50.  _PUTIMAGE , Layer(MASK), Layer(2)
  51.  _PUTIMAGE , Layer(2), Layer(1)
  52.  _PRINTSTRING (0, 464), "cycles:" + STR$(f%), Layer(1)
  53.  ClearLayer 2
  54.  _DELAY .005
  55.  Xloc% = Xloc% - 1
  56.  IF Xloc% <= -1000 THEN Xloc% = 1000
  57.  c% = c% + 1
  58.  
  59.  
  60. Delta:
  61. DATA 24,21
  62. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  63. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  64. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  65. data 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  66. data 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  67. data 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  68. data 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  69. data 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  70. data 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  71. data 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  72. data 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  73. data 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  74. data 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  75. data 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  76. data 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  77. data 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  78. data 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  79. data 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  80. data 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  81. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  82. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  83. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  84.  
  85. DeltaWepondry:
  86. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  87. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  88. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  89. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  90. data 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  91. data 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  92. data 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  93. data 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  94. data 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  95. data 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  96. data 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  97. data 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  98. data 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  99. data 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  100. data 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  101. data 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  102. data 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  103. data 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  104. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  105. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  106. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  107. data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  108.  
  109.  
  110.  
  111. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  112.  'find last tile to display
  113.  Endx%% = (640 - Xloc%) / 32
  114.  Endy%% = (400 - Yloc%) / 32
  115.  'range check keep values within array size(or dreadnaught data size)
  116.  IF Endx%% > S.Xsize THEN Endx%% = S.Xsize
  117.  IF Endy%% > S.Ysize THEN Endy%% = S.Ysize
  118.  'find first tile to display
  119.  Startx%% = (0 + Xloc%) / 32
  120.  Starty%% = (0 + Yloc%) / 32
  121.  'make sure value is always negative(-) otherwise start at 0
  122.  IF Startx%% > 0 THEN Startx%% = 0
  123.  IF Starty%% > 0 THEN Starty%% = 0
  124.  'fix negative value to positive, this means that portion is off screen so
  125.  'start at the + array location in other words don't bother with whats off
  126.  'screen
  127.  Startx%% = ABS(Startx%%)
  128.  Starty%% = ABS(Starty%%)
  129.  
  130.  FOR y% = Starty%% TO Endy%%
  131.   FOR x% = Startx%% TO Endx%%
  132.    layer% = Ship(x%, y%, 0)
  133.    SELECT CASE Ship(x%, y%, 1)
  134.     CASE 0
  135.     CASE 65 TO 92
  136.      xoff% = 16 * (Ship(x%, y%, 1) - 65)
  137.      XL% = Xloc% + xoffs% + 0 + x% * 32
  138.      YL% = Yloc% + yoff% + y% * 32
  139.      IF layer% > 0 THEN _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0, 0 + ((layer% - 1) * 16))-(15, 15 + ((layer% - 1) * 16))
  140.      _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + (layer% * 16))-(15 + xoff%, 15 + (layer% * 16))
  141.    END SELECT
  142.    layer% = Arms(x%, y%, 0) + 4
  143.    SELECT CASE Arms(x%, y%, 1)
  144.     CASE 0
  145.     CASE 65 TO 92
  146.      xoff% = 16 * (Arms(x%, y%, 1) - 65)
  147.      XL% = Xloc% + xoffs% + 0 + x% * 32
  148.      YL% = Yloc% + yoff% + y% * 32
  149.      _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + (layer% * 16))-(15 + xoff%, 15 + (layer% * 16))
  150.    END SELECT
  151.   NEXT x%
  152.  NEXT y%
  153.  
  154. SUB LoadDreadnaughtlayout
  155.  RESTORE Delta
  156.  READ S.Xsize
  157.  READ S.Ysize
  158.  DIM temp AS STRING * 2
  159.  
  160.  FOR y% = 0 TO S.Ysize
  161.   FOR x% = 0 TO S.Xsize
  162.    READ temp
  163.    Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  164.    Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  165.  NEXT x%, y%
  166.  RESTORE DeltaWepondry
  167.  FOR y% = 0 TO S.Ysize
  168.   FOR x% = 0 TO S.Xsize
  169.    READ temp
  170.    Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  171.    Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  172.  NEXT x%, y%
  173.  
  174. SUB ClearLayer (id%%)
  175.  old& = _DEST
  176.  _DEST Layer(id%%)
  177.  CLS
  178.  _DEST old&
  179.  
  180.  
« Last Edit: October 25, 2018, 11:41:12 am by Cobalt »
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Whats Causing the slow down in this code?
« Reply #1 on: October 25, 2018, 11:31:20 am »
What's the code in SUB ClearLayer?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Whats Causing the slow down in this code?
« Reply #2 on: October 25, 2018, 11:40:38 am »
odd, Select all didn't get it?

SUB ClearLayer (id%%)
 old& = _DEST
 _DEST Layer(id%%)
 CLS
 _DEST old&
END SUB

 (added it to the code above too.)
« Last Edit: October 25, 2018, 11:41:58 am by Cobalt »
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Whats Causing the slow down in this code?
« Reply #3 on: October 25, 2018, 11:52:12 am »
I don't see anything to blame at a first glance. _DELAY inside a DO/LOOP doesn't look like the best way to go (_LIMIT, maybe?), but it shouldn't delay more than what it's instructed to anyway.

Hope the issue emerges soon so you can proceed.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Whats Causing the slow down in this code?
« Reply #4 on: October 25, 2018, 12:07:37 pm »
_delay is just there to control CPU usage. when I remove it , I start 190ish cycles and drop down to mid 40s which I think is even worse than having the delay! gain nearly 80(72% gain) cycles on the max and only only about 10(29% gain) on the lower.

This is the first time I've experienced any kind of issue with speed in involving the graphics in QB64.
« Last Edit: October 25, 2018, 12:08:53 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #5 on: October 25, 2018, 12:28:45 pm »
Try this and see how it performs for you:

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.     Xsize AS _BYTE 'ship size X
  3.     Ysize AS _BYTE 'ship size Y
  4.     Engines AS _BYTE 'Engines remaining 0-4
  5.     Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.     Silos AS _BYTE 'Silos remaining 0-5
  7.     ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.     Ships AS _BYTE 'Dreadnaughts destroied
  10.     Score AS _UNSIGNED LONG 'Players score
  11.     Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.     Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.     Xpos AS INTEGER
  15.     Ypos AS INTEGER
  16.     Speed AS INTEGER
  17.     ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.     Xpos AS INTEGER
  20.     Ypos AS INTEGER
  21.     Kind AS _BYTE
  22.     Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. SCREEN _NEWIMAGE(640, 480, 32)
  34. Layer(0) = _LOADIMAGE("DFsprit8.bmp") '  Sprite Layer
  35. Layer(1) = _DISPLAY
  36. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  37. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF 'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. Xloc% = 1000: start! = TIMER
  48.     DrawDreadnaught Xloc%, -32, 2
  49.     IF TIMER >= start! + 1 THEN f% = c%: start! = TIMER: c% = 0
  50.     _PUTIMAGE , Layer(MASK), Layer(2)
  51.     _PUTIMAGE , Layer(2), Layer(1)
  52.     _PRINTSTRING (0, 464), "cycles:" + STR$(f%), Layer(1)
  53.     ClearLayer 2
  54.     _LIMIT 120
  55.     Xloc% = Xloc% - 1
  56.     IF Xloc% <= -1000 THEN Xloc% = 1000
  57.     c% = c% + 1
  58.  
  59.  
  60. Delta:
  61. DATA 24,21
  62. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  63. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  64. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  65. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  66. DATA 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  67. DATA 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  68. DATA 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  69. DATA 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  70. DATA 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  71. DATA 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  72. DATA 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  73. DATA 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  74. DATA 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  75. DATA 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  76. DATA 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  77. DATA 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  78. DATA 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  79. DATA 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  80. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  81. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  82. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  83. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  84.  
  85. DeltaWepondry:
  86. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  87. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  88. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  89. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  90. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  91. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  92. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  93. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  94. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  95. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  96. DATA 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  97. DATA 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  98. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  99. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  100. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  101. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  102. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  103. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  104. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  105. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  106. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  107. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  108.  
  109.  
  110.  
  111. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  112.     'find last tile to display
  113.     Endx%% = (640 - Xloc%) \ 32
  114.     Endy%% = (400 - Yloc%) \ 32
  115.     'range check keep values within array size(or dreadnaught data size)
  116.     IF Endx%% > S.Xsize THEN Endx%% = S.Xsize
  117.     IF Endy%% > S.Ysize THEN Endy%% = S.Ysize
  118.     'find first tile to display
  119.     Startx%% = (0 + Xloc%) \ 32
  120.     Starty%% = (0 + Yloc%) \ 32
  121.     'make sure value is always negative(-) otherwise start at 0
  122.     IF Startx%% > 0 THEN Startx%% = 0
  123.     IF Starty%% > 0 THEN Starty%% = 0
  124.     'fix negative value to positive, this means that portion is off screen so
  125.     'start at the + array location in other words don't bother with whats off
  126.     'screen
  127.     Startx%% = -Startx%%
  128.     Starty%% = -Starty%%
  129.  
  130.     FOR y% = Starty%% TO Endy%%
  131.         FOR x% = Startx%% TO Endx%%
  132.             layer% = Ship(x%, y%, 0) * 16
  133.             x1% = Xloc% + x% * 32
  134.             y1% = Yloc% + y% * 32
  135.             SELECT CASE Ship(x%, y%, 1)
  136.                 CASE 0
  137.                 CASE 65 TO 92
  138.                     xoff% = 16 * (Ship(x%, y%, 1) - 65)
  139.                     XL% = x1% + xoffs%
  140.                     YL% = y1% + yoff%
  141.                     IF layer% > 0 THEN _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0, layer% - 1)-STEP(15, 0)
  142.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + layer%)-STEP(15, 0)
  143.             END SELECT
  144.             layer% = (Arms(x%, y%, 0) + 4) * 16
  145.             SELECT CASE Arms(x%, y%, 1)
  146.                 CASE 0
  147.                 CASE 65 TO 92
  148.                     xoff% = 16 * (Arms(x%, y%, 1) - 65)
  149.                     XL% = x1% + xoffs%
  150.                     YL% = y1% + yoff%
  151.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, layer%)-STEP(15, 15)
  152.             END SELECT
  153.         NEXT x%
  154.     NEXT y%
  155.  
  156. SUB LoadDreadnaughtlayout
  157.     RESTORE Delta
  158.     READ S.Xsize
  159.     READ S.Ysize
  160.     DIM temp AS STRING * 2
  161.  
  162.     FOR y% = 0 TO S.Ysize
  163.         FOR x% = 0 TO S.Xsize
  164.             READ temp
  165.             Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  166.             Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  167.     NEXT x%, y%
  168.     RESTORE DeltaWepondry
  169.     FOR y% = 0 TO S.Ysize
  170.         FOR x% = 0 TO S.Xsize
  171.             READ temp
  172.             Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  173.             Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  174.     NEXT x%, y%
  175.  
  176. SUB ClearLayer (id%%)
  177.     old& = _DEST
  178.     _DEST Layer(id%%)
  179.     CLS
  180.     _DEST old&

Simplified some of the math, moved some of it outside the loop, and replaced the _DELAY with a _LIMIT, which performs much better on my system.  I'm holding steady at 120FPS now, but don't know what performance you might expect to see on an older system.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Whats Causing the slow down in this code?
« Reply #6 on: October 25, 2018, 01:02:20 pm »
Afraid not, only gaining about 7(average) cycles but uh, take a look at the graphics being outputted.

Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #7 on: October 25, 2018, 01:06:59 pm »
And, if you can't get the FPS up to the speed that you expect for your game to operate properly, you may need to change the step that the ships move to keep the game flow consistent, such as something like this:

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.     Xsize AS _BYTE 'ship size X
  3.     Ysize AS _BYTE 'ship size Y
  4.     Engines AS _BYTE 'Engines remaining 0-4
  5.     Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.     Silos AS _BYTE 'Silos remaining 0-5
  7.     ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.     Ships AS _BYTE 'Dreadnaughts destroied
  10.     Score AS _UNSIGNED LONG 'Players score
  11.     Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.     Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.     Xpos AS INTEGER
  15.     Ypos AS INTEGER
  16.     Speed AS INTEGER
  17.     ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.     Xpos AS INTEGER
  20.     Ypos AS INTEGER
  21.     Kind AS _BYTE
  22.     Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. Layer(0) = _LOADIMAGE("DFsprit8.bmp", 32) '  Sprite Layer
  34. Layer(1) = _NEWIMAGE(640, 480, 32) 'Display layer
  35. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  36. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  37. SCREEN Layer(1)
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF 'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. Xloc% = 1000: start! = TIMER
  48.     DrawDreadnaught Xloc!, -32, 2
  49.     IF TIMER >= start! + 1 THEN f% = c%: start! = TIMER: c% = 0
  50.     _PUTIMAGE , Layer(MASK), Layer(2)
  51.     _PUTIMAGE , Layer(2), Layer(1)
  52.     _PRINTSTRING (0, 464), "cycles:" + STR$(f%), Layer(1)
  53.     ClearLayer 2
  54.     _DELAY .1
  55.     '_LIMIT 120
  56.     IF f% < 120 THEN Xstep! = 120 / f% ELSE Xstep! = 1
  57.     Xloc! = Xloc! - Xstep!
  58.     IF Xloc! <= -1000 THEN Xloc! = 1000
  59.     c% = c% + 1
  60.  
  61.  
  62. Delta:
  63. DATA 24,21
  64. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  65. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  66. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  67. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  68. DATA 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  69. DATA 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  70. DATA 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  71. DATA 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  72. DATA 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  73. DATA 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  74. DATA 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  75. DATA 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  76. DATA 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  77. DATA 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  78. DATA 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  79. DATA 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  80. DATA 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  81. DATA 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  82. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  83. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  84. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  85. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  86.  
  87. DeltaWepondry:
  88. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  89. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  90. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  91. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  92. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  93. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  94. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  95. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  96. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  97. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  98. DATA 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  99. DATA 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  100. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  101. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  102. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  103. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  104. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  105. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  106. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  107. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  108. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  109. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  110.  
  111.  
  112.  
  113. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  114.     'find last tile to display
  115.     Endx%% = (640 - Xloc%) \ 32
  116.     Endy%% = (400 - Yloc%) \ 32
  117.     'range check keep values within array size(or dreadnaught data size)
  118.     IF Endx%% > S.Xsize THEN Endx%% = S.Xsize
  119.     IF Endy%% > S.Ysize THEN Endy%% = S.Ysize
  120.     'find first tile to display
  121.     Startx%% = (0 + Xloc%) \ 32
  122.     Starty%% = (0 + Yloc%) \ 32
  123.     'make sure value is always negative(-) otherwise start at 0
  124.     IF Startx%% > 0 THEN Startx%% = 0
  125.     IF Starty%% > 0 THEN Starty%% = 0
  126.     'fix negative value to positive, this means that portion is off screen so
  127.     'start at the + array location in other words don't bother with whats off
  128.     'screen
  129.     Startx%% = -Startx%%
  130.     Starty%% = -Starty%%
  131.  
  132.     FOR y% = Starty%% TO Endy%%
  133.         FOR x% = Startx%% TO Endx%%
  134.             layer% = Ship(x%, y%, 0) * 16
  135.             x1% = Xloc% + x% * 32
  136.             y1% = Yloc% + y% * 32
  137.             SELECT CASE Ship(x%, y%, 1)
  138.                 CASE 0
  139.                 CASE 65 TO 92
  140.                     xoff% = 16 * (Ship(x%, y%, 1) - 65)
  141.                     XL% = x1% + xoffs%
  142.                     YL% = y1% + yoff%
  143.                     IF layer% > 0 THEN _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0, layer% - 1)-STEP(15, 0)
  144.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + layer%)-STEP(15, 0)
  145.             END SELECT
  146.             layer% = (Arms(x%, y%, 0) + 4) * 16
  147.             SELECT CASE Arms(x%, y%, 1)
  148.                 CASE 0
  149.                 CASE 65 TO 92
  150.                     xoff% = 16 * (Arms(x%, y%, 1) - 65)
  151.                     XL% = x1% + xoffs%
  152.                     YL% = y1% + yoff%
  153.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, layer%)-STEP(15, 15)
  154.             END SELECT
  155.         NEXT x%
  156.     NEXT y%
  157.  
  158. SUB LoadDreadnaughtlayout
  159.     RESTORE Delta
  160.     READ S.Xsize
  161.     READ S.Ysize
  162.     DIM temp AS STRING * 2
  163.  
  164.     FOR y% = 0 TO S.Ysize
  165.         FOR x% = 0 TO S.Xsize
  166.             READ temp
  167.             Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  168.             Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  169.     NEXT x%, y%
  170.     RESTORE DeltaWepondry
  171.     FOR y% = 0 TO S.Ysize
  172.         FOR x% = 0 TO S.Xsize
  173.             READ temp
  174.             Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  175.             Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  176.     NEXT x%, y%
  177.  
  178. SUB ClearLayer (id%%)
  179.     old& = _DEST
  180.     _DEST Layer(id%%)
  181.     CLS
  182.     _DEST old&

Note that this has a HUGE set delay of .1 seconds per cycle (compared to your original of 0.005, it's 20 times slower), and the ships still scroll right to left at around the same speed -- they're just moving in "chunks" now, as they skip several draws, but they're still advancing across the screen at the same rate.

Since you're only dropping from 110 to mid/upper 30s, that's a decrease of only about 1/3 for you, rather than the 1/20 which we see here, so that "step" isn't going to be as large and you're not going to notice the jerkiness as badly.

Honestly though, I'd go with a _LIMIT in this case, rather than a _DELAY.  Then, when the machine bogs down and needs more power for performance, it can use it, instead of having to wait no matter what.   ;)

(And I didn't pay attention to the background; I just was paying attention to the ship/arms.  Let me see what I did to the background...  :P)
« Last Edit: October 25, 2018, 01:09:25 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #8 on: October 25, 2018, 01:18:26 pm »
Without changing anything but the delay, see if this won't continue to scroll at the rate you expect it to:

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.     Xsize AS _BYTE 'ship size X
  3.     Ysize AS _BYTE 'ship size Y
  4.     Engines AS _BYTE 'Engines remaining 0-4
  5.     Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.     Silos AS _BYTE 'Silos remaining 0-5
  7.     ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.     Ships AS _BYTE 'Dreadnaughts destroied
  10.     Score AS _UNSIGNED LONG 'Players score
  11.     Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.     Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.     Xpos AS INTEGER
  15.     Ypos AS INTEGER
  16.     Speed AS INTEGER
  17.     ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.     Xpos AS INTEGER
  20.     Ypos AS INTEGER
  21.     Kind AS _BYTE
  22.     Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. SCREEN _NEWIMAGE(640, 480, 32)
  34. Layer(0) = _LOADIMAGE("DFsprit8.bmp") '  Sprite Layer
  35. Layer(1) = _DISPLAY
  36. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  37. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF 'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. Xloc! = 1000: start! = TIMER
  48.     DrawDreadnaught Xloc!, -32, 2
  49.     IF TIMER >= start! + 1 THEN f% = c%: start! = TIMER: c% = 0
  50.     _PUTIMAGE , Layer(MASK), Layer(2)
  51.     _PUTIMAGE , Layer(2), Layer(1)
  52.     _PRINTSTRING (0, 464), "cycles:" + STR$(f%), Layer(1)
  53.     ClearLayer 2
  54.     _DELAY .005
  55.     IF f% < 120 THEN Xstep! = 120 / f% ELSE Xstep! = 1
  56.     Xloc! = Xloc! - Xstep!
  57.     IF Xloc! <= -1000 THEN Xloc! = 1000
  58.     c% = c% + 1
  59.  
  60.  
  61. Delta:
  62. DATA 24,21
  63. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  64. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  65. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  66. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  67. DATA 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  68. DATA 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  69. DATA 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  70. DATA 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  71. DATA 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  72. DATA 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  73. DATA 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  74. DATA 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  75. DATA 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  76. DATA 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  77. DATA 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  78. DATA 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  79. DATA 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  80. DATA 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  81. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  82. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  83. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  84. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  85.  
  86. DeltaWepondry:
  87. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  88. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  89. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  90. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  91. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  92. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  93. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  94. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  95. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  96. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  97. DATA 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  98. DATA 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  99. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  100. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  101. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  102. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  103. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  104. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  105. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  106. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  107. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  108. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  109.  
  110.  
  111.  
  112. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  113.     'find last tile to display
  114.     Endx%% = (640 - Xloc%) / 32
  115.     Endy%% = (400 - Yloc%) / 32
  116.     'range check keep values within array size(or dreadnaught data size)
  117.     IF Endx%% > S.Xsize THEN Endx%% = S.Xsize
  118.     IF Endy%% > S.Ysize THEN Endy%% = S.Ysize
  119.     'find first tile to display
  120.     Startx%% = (0 + Xloc%) / 32
  121.     Starty%% = (0 + Yloc%) / 32
  122.     'make sure value is always negative(-) otherwise start at 0
  123.     IF Startx%% > 0 THEN Startx%% = 0
  124.     IF Starty%% > 0 THEN Starty%% = 0
  125.     'fix negative value to positive, this means that portion is off screen so
  126.     'start at the + array location in other words don't bother with whats off
  127.     'screen
  128.     Startx%% = ABS(Startx%%)
  129.     Starty%% = ABS(Starty%%)
  130.  
  131.     FOR y% = Starty%% TO Endy%%
  132.         FOR x% = Startx%% TO Endx%%
  133.             layer% = Ship(x%, y%, 0)
  134.             SELECT CASE Ship(x%, y%, 1)
  135.                 CASE 0
  136.                 CASE 65 TO 92
  137.                     xoff% = 16 * (Ship(x%, y%, 1) - 65)
  138.                     XL% = Xloc% + xoffs% + 0 + x% * 32
  139.                     YL% = Yloc% + yoff% + y% * 32
  140.                     IF layer% > 0 THEN _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0, 0 + ((layer% - 1) * 16))-(15, 15 + ((layer% - 1) * 16))
  141.                     _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + (layer% * 16))-(15 + xoff%, 15 + (layer% * 16))
  142.             END SELECT
  143.             layer% = Arms(x%, y%, 0) + 4
  144.             SELECT CASE Arms(x%, y%, 1)
  145.                 CASE 0
  146.                 CASE 65 TO 92
  147.                     xoff% = 16 * (Arms(x%, y%, 1) - 65)
  148.                     XL% = Xloc% + xoffs% + 0 + x% * 32
  149.                     YL% = Yloc% + yoff% + y% * 32
  150.                     _PUTIMAGE (XL%, YL%)-(XL% + 32, YL% + 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + (layer% * 16))-(15 + xoff%, 15 + (layer% * 16))
  151.             END SELECT
  152.         NEXT x%
  153.     NEXT y%
  154.  
  155. SUB LoadDreadnaughtlayout
  156.     RESTORE Delta
  157.     READ S.Xsize
  158.     READ S.Ysize
  159.     DIM temp AS STRING * 2
  160.  
  161.     FOR y% = 0 TO S.Ysize
  162.         FOR x% = 0 TO S.Xsize
  163.             READ temp
  164.             Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  165.             Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  166.     NEXT x%, y%
  167.     RESTORE DeltaWepondry
  168.     FOR y% = 0 TO S.Ysize
  169.         FOR x% = 0 TO S.Xsize
  170.             READ temp
  171.             Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  172.             Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  173.     NEXT x%, y%
  174.  
  175. SUB ClearLayer (id%%)
  176.     old& = _DEST
  177.     _DEST Layer(id%%)
  178.     CLS
  179.     _DEST old&
  180.  

If all else fails, you might need to skip some frames so the game continues to move at the same rate for you.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Whats Causing the slow down in this code?
« Reply #9 on: October 25, 2018, 01:31:28 pm »
After running this little test code, I may just increase the size of my sprite sheet, look at the speed differnce between the regular putimage and the putimage that zooms tests! that is a major hit. when you zoom with putimage you lose over 10x the speed. why would that be?

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. Layer&(0) = _LOADIMAGE("DFsprit8.bmp", 32) '  Sprite Layer
  3.  
  4. DIM testimage(1024) AS LONG
  5.  
  6. _DEST Layer&(0)
  7. GET (0, 0)-(15, 15), testimage()
  8. LOCATE 5, 1: PRINT "Test 1"
  9. start1! = TIMER
  10.  PUT (0, 0), testimage()
  11.  LINE (0, 0)-(15, 15), _RGB32(0, 0, 0), BF
  12.  cycle1& = cycle1& + 1
  13. LOOP UNTIL TIMER >= start1! + 5
  14.  
  15. PRINT "Test 2"
  16. start2! = TIMER
  17.  _PUTIMAGE (0, 0), Layer&(0), _DISPLAY, (0, 0)-(15, 15)
  18.  LINE (0, 0)-(15, 15), _RGB32(0, 0, 0), BF
  19.  cycle2& = cycle2& + 1
  20. LOOP UNTIL TIMER >= start2! + 5
  21.  
  22. PRINT "Test 3"
  23. start3! = TIMER
  24.  _PUTIMAGE (0, 0)-STEP(32, 32), Layer&(0), _DISPLAY, (0, 0)-(15, 15)
  25.  LINE (0, 0)-(32, 32), _RGB32(0, 0, 0), BF
  26.  cycle3& = cycle3& + 1
  27. LOOP UNTIL TIMER >= start3! + 5
  28.  
  29. PRINT "Put Test Cycles per second          :"; cycle1& / 5
  30. PRINT "PutImage Test Cycles per second     :"; cycle2& / 5
  31. PRINT "PutImage zoom Test Cycles per second:"; cycle3& / 5
  32.  
  33.  

I'm not overly sure how the play would be if things begin to get 'jumpy' while your trying to line up the small fighter to shoot or bomb the targets(ARMS) on the ship, that is my main concern there.
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #10 on: October 25, 2018, 01:40:53 pm »
If you don't need alpha, try to add this command in there:  _DONTBLEND

By default, QB64 tries to blend images into the background, but if you don't need to, _DONTBLEND is a heckuva speed boost usually.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #11 on: October 25, 2018, 02:29:19 pm »
After running this little test code, I may just increase the size of my sprite sheet, look at the speed differnce between the regular putimage and the putimage that zooms tests! that is a major hit. when you zoom with putimage you lose over 10x the speed. why would that be?

Code: QB64: [Select]
  1. PRINT "Test 2"
  2.  _PUTIMAGE (0, 0), Layer&(0), _DISPLAY, (0, 0)-(15, 15)
  3.  
  4. PRINT "Test 3"
  5.  _PUTIMAGE (0, 0)-STEP(32, 32), Layer&(0), _DISPLAY, (0, 0)-(15, 15)
  6.  

You're doing a lot more work with the "zoom" print.  First, it's got to scale up your image to twice the size.  Then it's drawing to an area 4x the size.  (Twice as wide, Twice as tall). 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #12 on: October 25, 2018, 11:09:39 pm »
I've played around with this a bit more, and here's my solution to the problem:

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.     Xsize AS _BYTE 'ship size X
  3.     Ysize AS _BYTE 'ship size Y
  4.     Engines AS _BYTE 'Engines remaining 0-4
  5.     Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.     Silos AS _BYTE 'Silos remaining 0-5
  7.     ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.     Ships AS _BYTE 'Dreadnaughts destroied
  10.     Score AS _UNSIGNED LONG 'Players score
  11.     Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.     Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.     Xpos AS INTEGER
  15.     Ypos AS INTEGER
  16.     Speed AS INTEGER
  17.     ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.     Xpos AS INTEGER
  20.     Ypos AS INTEGER
  21.     Kind AS _BYTE
  22.     Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. SCREEN _NEWIMAGE(640, 480, 32)
  34. Layer(0) = _LOADIMAGE("DFsprit8.bmp") '  Sprite Layer
  35. Layer(1) = _DISPLAY
  36. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  37. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF 'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. Xloc! = 1000: start! = TIMER
  48. Limit% = 200
  49.     DrawDreadnaught Xloc!, -32, 2
  50.     IF TIMER >= start! + .1 THEN f% = c%: start! = TIMER: c% = 0
  51.     _PUTIMAGE , Layer(MASK), Layer(2)
  52.     _PUTIMAGE , Layer(2), Layer(1)
  53.     LOCATE 27, 1
  54.     PRINT "cycles:" + STR$(f%), Layer(1)
  55.     PRINT "MoveStep:"; Xstep!
  56.     ClearLayer 2
  57.     _LIMIT Limit%
  58.     IF f% < Limit% THEN Xstep! = Limit% / f% ELSE Xstep! = 1
  59.     Xloc! = Xloc! - Xstep!
  60.     IF Xloc! <= -1000 THEN Xloc! = 1000
  61.     c% = c% + 10
  62.     _DISPLAY
  63.  
  64.  
  65. Delta:
  66. DATA 24,21
  67. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  68. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  69. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  70. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  71. DATA 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  72. DATA 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  73. DATA 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  74. DATA 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  75. DATA 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  76. DATA 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  77. DATA 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  78. DATA 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  79. DATA 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  80. DATA 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  81. DATA 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  82. DATA 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  83. DATA 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  84. DATA 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  85. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  86. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  87. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  88. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  89.  
  90. DeltaWepondry:
  91. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  92. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  93. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  94. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  95. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  96. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  97. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  98. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  99. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  100. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  101. DATA 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  102. DATA 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  103. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  104. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  105. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  106. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  107. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  108. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  109. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  110. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  111. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  112. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  113.  
  114.  
  115.  
  116. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  117.     'find last tile to display
  118.     Endx%% = (640 - Xloc%) \ 32
  119.     Endy%% = (400 - Yloc%) \ 32
  120.     'range check keep values within array size(or dreadnaught data size)
  121.     IF Endx%% > S.Xsize THEN Endx%% = S.Xsize
  122.     IF Endy%% > S.Ysize THEN Endy%% = S.Ysize
  123.     'find first tile to display
  124.     Startx%% = Xloc% \ 32
  125.     Starty%% = Yloc% \ 32
  126.     'make sure value is always negative(-) otherwise start at 0
  127.     IF Startx%% > 0 THEN Startx%% = 0
  128.     IF Starty%% > 0 THEN Starty%% = 0
  129.     'fix negative value to positive, this means that portion is off screen so
  130.     'start at the + array location in other words don't bother with whats off
  131.     'screen
  132.     Startx%% = -Startx%%
  133.     Starty%% = -Starty%%
  134.  
  135.     FOR y% = Starty%% TO Endy%%
  136.         YL% = Yloc% + y% * 32
  137.         FOR x% = Startx%% TO Endx%%
  138.             layer% = Ship(x%, y%, 0)
  139.             x1% = Xloc% + x% * 32
  140.             SELECT CASE Ship(x%, y%, 1)
  141.                 CASE 0
  142.                 CASE 65 TO 92
  143.                     xoff% = 16 * (Ship(x%, y%, 1) - 65)
  144.                     XL% = x1% + xoffs%
  145.                     IF layer% > 0 THEN _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0, 0 + ((layer% - 1) * 16))-STEP(15, 15)
  146.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, 0 + (layer% * 16))-STEP(15, 15)
  147.             END SELECT
  148.             layer% = Arms(x%, y%, 0) + 4
  149.             SELECT CASE Arms(x%, y%, 1)
  150.                 CASE 0
  151.                 CASE 65 TO 92
  152.                     xoff% = 16 * (Arms(x%, y%, 1) - 65)
  153.                     XL% = x1% + xoffs%
  154.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), Layer(LayerID%%), (0 + xoff%, layer% * 16)-STEP(15, 15)
  155.             END SELECT
  156.         NEXT x%
  157.     NEXT y%
  158.  
  159. SUB LoadDreadnaughtlayout
  160.     RESTORE Delta
  161.     READ S.Xsize
  162.     READ S.Ysize
  163.     DIM temp AS STRING * 2
  164.  
  165.     FOR y% = 0 TO S.Ysize
  166.         FOR x% = 0 TO S.Xsize
  167.             READ temp
  168.             Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  169.             Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  170.     NEXT x%, y%
  171.     RESTORE DeltaWepondry
  172.     FOR y% = 0 TO S.Ysize
  173.         FOR x% = 0 TO S.Xsize
  174.             READ temp
  175.             Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  176.             Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  177.     NEXT x%, y%
  178.  
  179. SUB ClearLayer (id%%)
  180.     old& = _DEST
  181.     _DEST Layer(id%%)
  182.     CLS
  183.     _DEST old&
  184.  

Code has been cleaned up and math routines reduced as much as possible inside the graphic display portion, with no effect to display.  (WTH went wrong last time is beyond me.  Probably just something simple that I'm just too lazy to notice ATM.)

FPS counter has been replaced from a 1 second counter to a 1/10th second counter.
With this 1/10th counter, we now utilize a Limit% to set the maximum speed that we want the game to run.  On my PC, I've set the speed to 200 so I can watch the movement step in action.  A FPS of 120 or less doesn't require the movement to change at all now.

Changed the _PRINTSTRING to a lazy LOCATE and PRINT so that I could tag on some information without having to use my brain...  I imagine eventually they'll disappear completely once debugging is finished, so it shouldn't really matter.

Fixed _DELAY changed to variable _LIMIT for better use of maximum CPU power when the game needs it.

And added in a basic "skipframe" routine so that we maintain game speed even when the PC can't render all the graphics fast enough for us.  (Xstep!)  For me, the highest this step ever goes is to about 1.7 pixels instead of 1 pixel, so it's not a noticeable change at all.  Instead of the ship moving 1 pixel, 20 times in 1/10 of a second, to make 200 FPS, it ends up moving 1.7 pixels, 12 times in 1/10th of a seconds, to make 200 FPS, at its most taxed operation.

The change there just isn't very significant visually for me, but it keeps the game scrolling smoothly and without slowing down.
1 pixel, 20 times, in 1/10th of a second vs...
1.7 pixels, 12 times, in that same time frame...

And, if you think the game runs best at 100 FPS, then there's no change at all for us.  We'd run 1 pixel, 10 times, in 1/10 of a second, all the time.  (At least on my PC we would...)

It's the best solution I can think of for you, so the game can run smoothly on both older and newer machines.  ;)
« Last Edit: October 26, 2018, 03:18:36 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Whats Causing the slow down in this code?
« Reply #13 on: October 26, 2018, 04:41:33 am »
Actually, I think this would be a better solution:

Code: QB64: [Select]
  1. TYPE Dreadnaught
  2.     Xsize AS _BYTE 'ship size X
  3.     Ysize AS _BYTE 'ship size Y
  4.     Engines AS _BYTE 'Engines remaining 0-4
  5.     Vents AS _BYTE 'Vents remaining 0-16 (0 explodes ship)
  6.     Silos AS _BYTE 'Silos remaining 0-5
  7.     ShotsFired AS _BYTE 'how may shots are currently active
  8. TYPE Gamedata
  9.     Ships AS _BYTE 'Dreadnaughts destroied
  10.     Score AS _UNSIGNED LONG 'Players score
  11.     Lives AS _UNSIGNED _BYTE 'Player lives remaining
  12.     Distance AS _BYTE 'Dreadnaught Distance remaining
  13. TYPE Playerdata
  14.     Xpos AS INTEGER
  15.     Ypos AS INTEGER
  16.     Speed AS INTEGER
  17.     ShotsFired AS _BYTE
  18. TYPE Shotdata
  19.     Xpos AS INTEGER
  20.     Ypos AS INTEGER
  21.     Kind AS _BYTE
  22.     Time AS _BYTE
  23.  
  24. DIM SHARED Ship(44, 32, 1) AS _BYTE 'STRING * 2
  25. DIM SHARED Arms(44, 32, 1) AS _BYTE 'STRING * 2
  26. DIM SHARED Layer(16) AS LONG
  27. DIM SHARED S AS Dreadnaught, G AS Gamedata, P AS Playerdata
  28. DIM SHARED PS(2) AS Shotdata, DS(10) AS Shotdata
  29.  
  30. CONST TRUE = -1, FALSE = NOT TRUE, SPRITES = 0, MASK = 3
  31. CONST Shot = 1, Bomb = 2, SGun = 3, LGun = 4, STorp = 5, LTorp = 6, Trakr = 7
  32.  
  33. SCREEN _NEWIMAGE(640, 480, 32)
  34. Layer(0) = _LOADIMAGE("DFsprit8.bmp") '  Sprite Layer
  35. Layer(1) = _DISPLAY
  36. Layer(2) = _NEWIMAGE(640, 480, 32) 'ship draw layer
  37. Layer(3) = _NEWIMAGE(640, 480, 32) 'screen mask, top 32 and bottom 80 pixels masked
  38.  
  39. _DEST Layer(MASK)
  40. LINE (0, 0)-(639, 479), _RGB32(0, 0, 0), BF
  41. LINE (0, 33)-(639, 400), _RGB32(1, 1, 1), BF
  42. LINE (0, 464)-(639, 479), _RGB32(1, 1, 1), BF 'debugging
  43. _CLEARCOLOR _RGB32(0, 0, 0), Layer(SPRITES)
  44. _CLEARCOLOR _RGB32(1, 1, 1), Layer(MASK)
  45.  
  46. LoadDreadnaughtlayout
  47. DNS = _NEWIMAGE(S.Xsize * 36, S.Ysize * 36, 32)
  48. PreDrawShip
  49.  
  50. Xloc! = 1000: start! = TIMER
  51. Limit% = 200
  52.     DrawDreadnaught Xloc!, -32, 2
  53.     IF TIMER >= start! + .1 THEN f% = c%: start! = TIMER: c% = 0
  54.     _PUTIMAGE , Layer(MASK), Layer(2)
  55.     _PUTIMAGE , Layer(2), Layer(1)
  56.     LOCATE 27, 1
  57.     PRINT "cycles:" + STR$(f%), Layer(1)
  58.     PRINT "MoveStep:"; Xstep!
  59.     ClearLayer 2
  60.     _LIMIT Limit%
  61.     IF f% < Limit% THEN Xstep! = Limit% / f% ELSE Xstep! = 1
  62.     Xloc! = Xloc! - Xstep!
  63.     IF Xloc! <= -1000 THEN Xloc! = 1000
  64.     c% = c% + 10
  65.     _DISPLAY
  66.  
  67.  
  68. Delta:
  69. DATA 24,21
  70. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0V,0F,0A,0A,0I
  71. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A
  72. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,0A,0A,0A
  73. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1V,1V,1U,0A
  74. DATA 00,00,00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,0A
  75. DATA 00,00,00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,0A
  76. DATA 00,00,00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2V,2U,1A,0A
  77. DATA 00,00,00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2A,2A,2A,1A,0A
  78. DATA 00,00,00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,1A,1A,2T,2F,2A,2A,2A,1A,0A
  79. DATA 00,0T,0F,0A,0A,0A,0A,0A,1T,1F,1A,1A,1A,1A,2T,2A,1A,1A,2A,2A,2A,3T,3A,1A,0A
  80. DATA 0B,0A,0A,0A,0A,0A,0A,1L,1A,1A,1A,1A,1A,2B,3L,3A,1A,1A,2A,2A,3L,3A,3A,1A,0A
  81. DATA 0C,0A,0A,0A,0A,0A,0A,1M,1A,1A,1A,1A,1A,2C,3M,3A,1A,1A,2A,2A,3M,3A,3A,1A,0A
  82. DATA 00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,2J,2A,1A,1A,2A,2A,2A,3J,3A,1A,0A
  83. DATA 00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2G,2A,2A,2A,1A,0A
  84. DATA 00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,2J,2A,2A,1A,0A
  85. DATA 00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,2W,2K,1A,0A
  86. DATA 00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,1A,1A,0A
  87. DATA 00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1G,1A,1A,1A,1A,0A
  88. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,1J,1W,1W,1K,0A
  89. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A,0A,0A
  90. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0G,0A,0A,0A,0A,0A,0A
  91. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0J,0W,0G,0A,0A,0H
  92.  
  93. DeltaWepondry:
  94. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  95. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0E,0F,00
  96. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,1E,1F,00
  97. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  98. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,0E,0F,00,0A
  99. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,1E,1F,00,1A
  100. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,0E,0F,00,00,00,00,00,00,00
  101. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,1E,1F,00,00,2A,00,0M,00,00
  102. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,1M,00,0A
  103. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,0M,2A,0I,0J,00,2C,00,1A
  104. DATA 00,2A,00,0E,0F,00,0M,00,2A,00,0E,0F,00,00,00,0C,00,1M,2A,00,00,00,0C,00,00
  105. DATA 00,2A,00,1E,1F,00,1M,00,2A,00,1E,1F,00,00,00,1C,00,0M,2A,00,00,00,1C,00,00
  106. DATA 00,00,00,2A,00,00,0I,0J,00,00,00,2A,00,00,00,2C,00,1M,2A,0I,0J,00,2C,00,0A
  107. DATA 00,00,00,00,00,2A,00,00,0I,0J,00,00,00,00,2A,00,00,00,00,00,2A,00,0M,00,1A
  108. DATA 00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,0E,0F,00,00,2A,00,1M,00,00
  109. DATA 00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,1E,1F,00,00,00,00,00,00,00
  110. DATA 00,00,00,00,00,00,00,00,00,00,00,2G,00,00,0I,0J,00,00,2A,00,00,0E,0F,00,0A
  111. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,0I,0J,00,00,00,1E,1F,00,1A
  112. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2E,00,00,0I,0J,00,00,00,00,00
  113. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2A,00,00,00,00,0E,0F,00
  114. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,2G,00,00,1E,1F,00
  115. DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
  116.  
  117. SUB PreDrawShip
  118.     Endx%% = S.Xsize
  119.     Endy%% = S.Ysize
  120.     Startx%% = 0
  121.     Starty%% = 0
  122.  
  123.     FOR y% = Starty%% TO Endy%%
  124.         YL% = Yloc% + y% * 32
  125.         FOR x% = Startx%% TO Endx%%
  126.             layer% = Ship(x%, y%, 0)
  127.             x1% = Xloc% + x% * 32
  128.             IF Ship(x%, y%, 1) <> 0 THEN
  129.                 xoff% = 16 * (Ship(x%, y%, 1) - 65)
  130.                 XL% = x1% + xoffs%
  131.                 _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), DNS, (0, 0 + ((layer% - 1) * 16))-STEP(15, 15)
  132.                 _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), DNS, (0 + xoff%, 0 + (layer% * 16))-STEP(15, 15)
  133.             END IF
  134.             layer% = Arms(x%, y%, 0) + 4
  135.             SELECT CASE Arms(x%, y%, 1)
  136.                 CASE 0
  137.                 CASE 65 TO 92
  138.                     xoff% = 16 * (Arms(x%, y%, 1) - 65)
  139.                     XL% = x1% + xoffs%
  140.                     _PUTIMAGE (XL%, YL%)-STEP(32, 32), Layer(SPRITES), DNS, (0 + xoff%, layer% * 16)-STEP(15, 15)
  141.             END SELECT
  142.         NEXT
  143.     NEXT
  144.  
  145. SUB DrawDreadnaught (Xloc%, Yloc%, LayerID%%)
  146.     _PUTIMAGE (Xloc%, Yloc%), DNS, Layer(2)
  147.  
  148. SUB LoadDreadnaughtlayout
  149.     RESTORE Delta
  150.     READ S.Xsize
  151.     READ S.Ysize
  152.     DIM temp AS STRING * 2
  153.  
  154.     FOR y% = 0 TO S.Ysize
  155.         FOR x% = 0 TO S.Xsize
  156.             READ temp
  157.             Ship(x%, y%, 0) = VAL(LEFT$(temp, 1))
  158.             Ship(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  159.     NEXT x%, y%
  160.     RESTORE DeltaWepondry
  161.     FOR y% = 0 TO S.Ysize
  162.         FOR x% = 0 TO S.Xsize
  163.             READ temp
  164.             Arms(x%, y%, 0) = VAL(LEFT$(temp, 1))
  165.             Arms(x%, y%, 1) = ASC(RIGHT$(temp, 1))
  166.     NEXT x%, y%
  167.  
  168. SUB ClearLayer (id%%)
  169.     old& = _DEST
  170.     _DEST Layer(id%%)
  171.     CLS
  172.     _DEST old&
  173.  

By pre-drawing the ship, this runs at a nice little 520 FPS at the slowest part of execution (on my PC).

The only thing you'd want to do here is "erase" the weapons/engines/whatnot from the DNS image (or make a copy of the DNS image to use so you can erase from it), whenever the player destroys one of those weapons. 

Try it out, see if this might not be the way you'd want to go for the game.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!