Author Topic: Unexpected pause in program execution  (Read 2627 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
Unexpected pause in program execution
« on: December 03, 2020, 01:35:14 pm »
So finally back to working on a program, "Astrosmash", and it is moving right along. However I find myself in a situation that is boggling my primitive little monkey brain. In this game I have 4 main types of objects to deal with(at the moment); Small Asteroids, Big Asteroids, Small Bombs and Big Bombs. Now when you blow up a Big Asteroid, it has a chance to split into 2 Small Asteroids. And everything seems to be working properly, save when you shoot a Big Bomb. This causes a pause in the games execution. I have yet to be able to identify why.

At first I thought maybe my numbers were off and the code was trying to split the Big Bomb into 2 Small Asteroids, which would have caused some issues somewhere due to the rather primative way I split the Big Asteroids. Another reason I thought it might be doing that is when the Big Asteroid splits it doesn't leave an "Explosion" sprite behind, and when the code pauses the Big Bomb that was hit doesn't leave one either. but that could just be because the explosion animation is only 6 frames and lasts a very short time, less time than the pause I believe.

If the SplitObject routine was running at this time there should be an associated output to the Debug.txt file when it happens, however there is not, the Object hit value outputs to show what was hit and thats it(this is a single BYTE value followed by &HFF). So where is this seemingly random pause coming from? It doesn't pause every time you hit a Big Bomb, just sometimes. Big Asteroids have a ~75% chance of splitting in two, yet another reason I thought the SplitObject would be a root cause.

this line determines a split;

Code: QB64: [Select]
  1.   IF (O(Hit%%).Kind >= 6 AND O(Hit%%).Kind <= 9) AND (RND * 100) > 25 THEN '~75%chance of split if large object is hit

Player's ship is 1
Small Asteroids have values 2-5(4 variations)
Big Asteroids have values 6-9 (4 variations)
Bombs have value 10

These are all defined in the CONSTs so.. no accidental changing should be happening.

And, debuging as I do, if I remove(aka Comment out) that line and subsequent lines the issue no longer happens. so why is that line trying to execute on a Bomb value of 10? or is it something completely different going on?
I have added prints here and there to try and catch the issue but alas, I am defeated.

I have removed all the subs, save for the MovePlayerShot and SplitObject, and placed them in an include file. Hopefully to make the code(that I think contributes to the issue anyway) more concise. may or may not need the font file, attached it anyway.

Now I have not added the RANDOMIZE TIMER yet as to make things more repeatable, (maybe) if you shoot the small bomb then the large yellow asteroid(which should split) then wait for a large bomb to enter the screen, shooting one should cause the pause.

Video demonstrating the pause issue.



Code: QB64: [Select]
  1. TYPE objects
  2.  Xpos AS SINGLE
  3.  Ypos AS SINGLE
  4.  Angle AS SINGLE
  5.  Speed AS SINGLE
  6.  Rotation AS _BYTE
  7.  Colr AS _BYTE
  8.  Kind AS _BYTE
  9.  Tracking AS _BYTE 'tells whether its a tracker and which direction its moving
  10.  CollideColr AS _BYTE
  11.  
  12. TYPE Gamedata
  13.  level AS _BYTE
  14.  Score AS LONG
  15.  ObjectCount AS _BYTE
  16.  BlastCount AS _BYTE
  17.  Count AS INTEGER
  18.  Movement AS _BYTE 'How fast player moves
  19.  ShotSpeed AS _BYTE 'how fast player shots move
  20.  GameOver AS _BYTE 'has player lost all lives
  21.  CurrentBG AS _BYTE 'current background color
  22.  MaxShot AS _BYTE
  23.  Speed AS _BYTE
  24.  
  25. TYPE Explosions
  26.  Xpos AS INTEGER
  27.  Ypos AS INTEGER
  28.  Frame AS _BYTE
  29.  
  30. TYPE Player
  31.  Xpos AS INTEGER
  32.  Ypos AS INTEGER
  33.  ShotCount AS _BYTE
  34.  
  35.  
  36. 'Load sprites--------------------------------
  37. SpriteData:
  38. DATA 311,16,16,16,56,124,238,254,68,16,84,56,108,56,124,254,170,76,124,118,174,252,127,90,48,118,255,122,47,15,60,126,44,104,252,124,62,122,222,252,56,124,126,126,55,63,250,239,102,32,120,236,254,120,95,47,58,124,127,253,218,110,126,58,16,12,60,126,118,127,255,250,60,124,126,111,255,254,126,108,32,24,24,60,36,36,60,24,24,0,6,30,36,36,120,96,0,0,0,60,231,231,60,0,0,0,96,120,36,36,30,6,0,0,0,36,24,24,36,0,0,0,66,60,36,36,60,66,0,0,60,102,90,90,102,60,0,60,0,153,165,165,153,0,60,66,153,36,66,66,36,153,66,153,66,0,129,129,0,66,153,0,0,0,16,16,124,16,16,0,0,0,16,56,124,56,16,0,0,0,56,124,124,124,56,0,0,0,16,56,124,56,16,16,16,16,16,16,16,16,56,56,124,108,238,254,254,68,68,128,128,64,64,64,32,112,112,60,108,110,126,120,32,32,32,128,128,64,64,48,48,62,62,23,23,28,28,24,24,8,8,0,0,128,192,108,127,63,22,22,28,28,28,8,8,8,0,0,0,0,2,7,15,30,250,250,30,15,7,2,0,0,0,0,0,24,60,60,24,0,0,60,126,255,213,255,60,0,0,24,90,255,171,126,153,0,0,153,90,255,171,126,90,0,0,0,0,84,42,84,42,0
  39. 'Load Main & Title screens
  40. MainScreenData:
  41. DATA 205,0,487,15,1,0,194,15,1,0,12,15,1,0,115,15,1,0,106,15,1,0,275,15,1,0,71,15,1,0,174,15,1,0,480,15,1,0,39,15,1,0,455,15,1,0,123,15,2,0,786,15,1,0,32,15,1,0,18,15,1,0,7,15,1,0,367,15,2,0,30,15,2,0,14,15,2,0,775,15,1,0,31,15,1,0,1170,15,1,0,195,15,1,0,36,15,1,0,354,15,2,0,591,15,1,0,162,15,1,0,7,15,1,0,20,15,1,0,39,15,1,0,394,15,1,0,31,15,1,0,294,15,1,0,317,15,1,0,151,15,1,0,110,15,1,0,347,15,1,0,83,15,2,0,257,15,1,0,365,15,1,0,42,15,1,0,192,15,1,0,103,15,1,0,31,15,1,0,135,15,1,0,138,15,2,0,305,15,1,0,1063,5,4,0,160,5,4,0,149,5,3,0,8,5,3,0,143,5,3,0,14,5,3,0,129,5,2,0,7,5,2,0,20,5,3,0,14,5,1,0,39,5,2,0,67,5,3,0,2,5,3,0,29,5,3,0,8,5,3,0,37,5,3,0,2,5,3,0,34,5,4,0,23,5,3,0,8,5,3,0,29,5,3,0,2,5,3,0,4,5,2,0,31,5,3,0,8,5,3,0,29,5,2,0,4,5,2,0,10,5,4,0,6,5,1,0,14,5,1,0,31,5,2,0,9,5,2,0,10,5,4,0,12,5,3,0,14,5,3,0,12,5,4,0,8,5,2,0,8,5,2,0,5,5,3,0,4,5,3,0,63,5,2,0,5,5,3,0,4,5,3,0,6,5,3,0,20,5,3,0,6,5,3,0,4,5,3,0,3,5,2,0,12,5,5,0,10,5,3,0,62,5,5,0,10,5,6,0,26,5,6,0,10,5,3,0,960,5,320,0,1600
  42. TitleScreenData:
  43. DATA 129,4,1617,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,13136
  44.  
  45. 'Color CONSTs
  46. CONST Black = 0, Blue = 1, Red = 2, Tanc = 3, Olive = 4, DkGreen = 5
  47. CONST BGGreen = 6, Yellow = 7, Grey = 8, SkyBlue = 9, Orange = 10
  48. CONST Pink = 11, Purple = 12, FadeGreen = 13, Maroon = 14, White = 15
  49. 'Zoom CONSTs
  50. CONST None = 0, H4 = 128, H2 = 64, H12 = 32, H14 = 16, V4 = 8, V2 = 4
  51. CONST V12 = 2, V14 = 1, HF = 512, VF = 256, COLLISION = 8192
  52. '4-x4, 2-x2, 12-x1/2, 14-x1/4, HF-Flip Horizontal, VF-Flip Vertical
  53. 'Sprite CONSTs
  54. CONST NullShip = 0, Ship = 1, SmallA = 2, SmallB = 3, SmallC = 4, SmallD = 5
  55. CONST LargeA = 6, LargeB = 7, LargeC = 8, LargeD = 9, Bomb = 10, Tracker = 11
  56. CONST SpaceShip = 12, SmallE = 13, SmallF = 14, SmallG = 15, SmallH = 16
  57. CONST Blast = 17, SpaceShipShot = 18
  58. CONST TRUE = -1, FALSE = NOT TRUE
  59. 'Game Scores CONSTs
  60. CONST SmallOid = 20
  61. CONST LargeOid = 10
  62. CONST LargeBomb = 40
  63. CONST SmallBomb = 80
  64. CONST Seeker = 100
  65. CONST Aliens = 150
  66. CONST AlienShot = 75
  67.  
  68. DIM SHARED Layer(12) AS LONG, Colors(16) AS _UNSIGNED LONG, FFX(1) AS LONG
  69. DIM SHARED G AS Gamedata, E(15) AS Explosions, P AS Player, O(15) AS objects
  70. DIM SHARED s(8) AS Explosions, TFX(5) AS LONG
  71.  
  72. SCREEN _NEWIMAGE(640, 480, 32)
  73. Layer(0) = _DISPLAY
  74. Layer(1) = _NEWIMAGE(640, 480, 32) 'Composite layer
  75. Layer(2) = _NEWIMAGE(640, 400, 13)
  76. Layer(3) = _NEWIMAGE(640, 480, 32) 'Title Screen Layer
  77. Layer(4) = _NEWIMAGE(640, 480, 32) 'Background sheet layer
  78. Layer(5) = _NEWIMAGE(640, 480, 32) 'Sprite draw layer
  79. Layer(6) = _NEWIMAGE(64, 64, 32) 'temp sprite layer for transparency
  80. Layer(7) = _NEWIMAGE(640, 480, 32) 'collision shadow layer Oids
  81. Layer(8) = _NEWIMAGE(640, 480, 32) 'background color
  82. Layer(9) = _NEWIMAGE(640, 480, 32) 'collision shadow layer Player
  83.  
  84. FFX(1) = _LOADFONT("PixelIntv.ttf", 40, "monospace")
  85. IF FFX(1) THEN _FONT FFX(1), Layer(1)
  86. IF FFX(1) THEN _FONT FFX(1), Layer(3)
  87.  
  88. Colors(0) = _RGB32(0, 0, 0) '       Black
  89. Colors(1) = _RGB32(0, 45, 255) '    Blue
  90. Colors(2) = _RGB32(255, 61, 16) '   Red
  91. Colors(3) = _RGB32(201, 207, 171) ' Tan
  92. Colors(4) = _RGB32(84, 110, 0) '    Olive Green
  93. Colors(5) = _RGB32(56, 107, 63) '   DkGreen
  94. Colors(6) = _RGB32(0, 167, 86) '    BGGreen
  95. Colors(7) = _RGB32(250, 234, 80) '  Yellow
  96. Colors(8) = _RGB32(189, 172, 200) ' Purpleish Grey
  97. Colors(9) = _RGB32(36, 184, 255) '  Sky Blue
  98. Colors(10) = _RGB32(255, 180, 31) ' Orange
  99. Colors(11) = _RGB32(255, 78, 87) '  Pinkish
  100. Colors(12) = _RGB32(164, 150, 255) 'Purplish
  101. Colors(13) = _RGB32(117, 204, 128) 'Faded Green
  102. Colors(14) = _RGB32(181, 26, 88) '  Maroon
  103. Colors(15) = _RGB32(255, 255, 255) 'White
  104.  
  105. TFX(1) = _FREETIMER
  106. TFX(2) = _FREETIMER
  107. ON TIMER(TFX(1), .4) AutoFire
  108. ON TIMER(TFX(2), .125) AnimOids
  109.  
  110. IF _FILEEXISTS("Astrodebug.txt") THEN KILL "Astrodebug.txt"
  111. OPEN "Astrodebug.txt" FOR BINARY AS #f&
  112.  
  113. 'Start Values
  114. P.Ypos = 321
  115. P.Xpos = 300
  116. G.Movement = 4
  117. G.ShotSpeed = 8
  118. G.Lives = 4
  119. G.level = 1
  120. G.MaxShot = 2
  121. G.Score = 0
  122. G.ObjectCount = 5
  123. FOR i%% = 0 TO G.ObjectCount - 1
  124.  MakeObject i%%
  125. NEXT i%%
  126.  
  127.  
  128. DrawSpriteSheet Layer(2)
  129. RESTORE MainScreenData
  130. DrawScreen 4
  131. RESTORE TitleScreenData
  132. DrawScreen 3
  133. _CLEARCOLOR _RGB32(0), Layer(4)
  134. TitleScreen
  135.  
  136. TIMER(TFX(2)) ON
  137.  
  138.  ClearLayer 7
  139.  Controls
  140.  CompositeBackGroundPlate
  141.  
  142.  '-------Draw the objects-------
  143.  FOR i%% = 0 TO G.ObjectCount - 1
  144.   DrawObject (i%%)
  145.  NEXT i%%
  146.  '------------------------------
  147.  
  148.  IF G.BlastCount THEN DrawExplosions
  149.  
  150.  DrawPlayer
  151.  
  152.  '--------Place the player shots on the screen--------
  153.  IF P.ShotCount THEN
  154.   FOR i%% = 0 TO P.ShotCount - 1
  155.    MovePlayerShot i%%
  156.    DrawPlayerShot i%%
  157.   NEXT i%%
  158.  '----------------------------------------------------
  159.  DisplayStats
  160.  _PUTIMAGE , Layer(1), Layer(0)
  161.  ClearLayer 1
  162.  _LIMIT 60 - 8 * G.Speed
  163.  FOR i%% = 0 TO G.ObjectCount - 1
  164.   MoveObject i%% 'move the objects
  165.  NEXT i%%
  166. TIMER(TFX(2)) OFF
  167. _PUTIMAGE (0, 0), Layer(7), Layer(0)
  168. 'PRINT _RGB32(32, 0, 0) - Colors(Black)
  169.  
  170.  
  171.  
  172. SUB MovePlayerShot (id~%%)
  173.  s(id~%%).Ypos = s(id~%%).Ypos - G.ShotSpeed
  174.  IF s(id~%%).Ypos > 0 THEN Hit%% = ShotCollision(id~%%) ELSE Hit%% = -1
  175.  _PRINTSTRING (0, 400), STR$(ShotCollision(id~%%)), Layer(1)
  176.  IF Hit%% > -1 THEN
  177.   s(id~%%).Ypos = -32 'move shot for removal
  178.   ScoreShot Hit%% 'increase score
  179.   PUT #f&, , O(Hit%%).Kind
  180.   Nul~%% = 255
  181.   PUT #f&, , Nul~%%
  182.   IF (O(Hit%%).Kind >= 6 AND O(Hit%%).Kind <= 9) AND (RND * 100) > 25 THEN '~75%chance of split if large object is hit
  183.    a$ = "Splitting object"
  184.    PUT #f&, , a$
  185.    PRINT a$
  186.    SplitObject Hit%% '
  187.   ELSE
  188.    MakeBlast G.BlastCount, Hit%%
  189.    G.BlastCount = G.BlastCount + 1 'add a new blast
  190.    MakeObject Hit%% 'replace the oid with a new one
  191.   END IF
  192.  IF s(id~%%).Ypos < -16 THEN
  193.   P.ShotCount = P.ShotCount - 1
  194.   FOR i%% = id~%% TO P.ShotCount
  195.    SWAP s(i%%), s(i%% + 1)
  196.   NEXT i%%
  197.   s(i%% - 1).Xpos = -10: s(i%% - 1).Ypos = 0
  198.  
  199.  
  200. SUB SplitObject (id~%%)
  201.  'some big Oids will split into two smaller Oids moving at sharper angles
  202.  'object 1 -uses original objects id
  203.  O(id~%%).Angle = O(id~%%).Angle - (RND * .25)
  204.  O(id~%%).Rotation = 1
  205.  O(id~%%).Kind = INT(RND * 4) + 2
  206.  O(id~%%).Speed = O(id~%%).Speed + (RND * 1 + .25) 'small objects move faster
  207.  O(id~%%).Colr = INT(RND * 5) + 6
  208.  O(id~%%).Zoom = V12
  209.  'object 2 -uses next availible id
  210.  id2~%% = G.ObjectCount 'instead of having to use a long varible name.
  211.  O(id2~%%).Xpos = O(id~%%).Xpos + 8
  212.  O(id2~%%).Ypos = O(id~%%).Ypos
  213.  O(id2~%%).Angle = O(id~%%).Angle + (RND * .25)
  214.  O(id2~%%).Rotation = 1
  215.  O(id2~%%).Kind = INT(RND * 4) + 2
  216.  O(id2~%%).Speed = O(id~%%).Speed + (RND * 1 + .25) 'small objects move faster
  217.  O(id2~%%).Colr = INT(RND * 5) + 6
  218.  O(id2~%%).Zoom = V12
  219.  G.ObjectCount = G.ObjectCount + 1 'add a new object to the list
  220.  
  221.  PUT #f&, , O()
  222.  
  223. '$include:'AstroAllSubs.bi'
  224.  
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Unexpected pause in program execution
« Reply #1 on: December 03, 2020, 02:28:11 pm »
Hi. Maybe this can be it or not. I add SOUND 300, .1 statement to AstroAllSubs.bi/ExplossionColission%% FUNCTION and in some cases is sound running in neverending loop. But, when all works as expected, is played just if colision occur. Because your colission detection is based on colors, maybe can be bug here and therefore is not running this object as two new objects.

Of course, this is just my guess, which may be completely out.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Unexpected pause in program execution
« Reply #2 on: December 03, 2020, 09:16:11 pm »
Hi. Maybe this can be it or not. I add SOUND 300, .1 statement to AstroAllSubs.bi/ExplossionColission%% FUNCTION and in some cases is sound running in neverending loop. But, when all works as expected, is played just if colision occur. Because your colission detection is based on colors, maybe can be bug here and therefore is not running this object as two new objects.

Of course, this is just my guess, which may be completely out.

yeah, that is probably right. The ExplosionCollision function checks to see if any of the Objects on the screen collide with it. so while there is an explosion showing on screen it should be running. It allows for a chain reaction, that counts for points.

so if it starts to play when the game pauses after hitting a large bomb then it might sound off. but that function should run a lot from time to time.
Granted after becoming radioactive I only have a half-life!