I'm writing a program similar to Falling Sand Game, except without the physics and a couple previously unexplored features. (only one at the moment). It's supposed to be kind of specialized, for those who want to know where the physics have gone.
I've searched the relevant code for errors, revised it, rewritten it, everything, and I always end up with the same problem. I can now say confidently that the error must not be in my code, but rather in the complier.
Here's a brief explanation of what should happen and what is happening:
Each pixel is checked for either adjacent pixels, diagonal pixels, or both to see if the two elements each one can be match a combination saved in memory, and if they do, the desired results for each of those two pixels are stored in memory as well. The pixels are converted to the correct results, and the pixel is set to be unable to react until the next frame.
Now this is what it does - All but two of the reactions work perfectly fine. However, when all 8 pixels are checked, directly down (x+0,y+1) and directly right (x+1,y+0) continue to react with no regard for the instruvtion to react only once per frame, therefore making all reactions in a straight line in that direction occur instantaneously, reulting in bad visuals and messed up reactions for the rest of the pixels on-screen. When none of the for adjacent checks are done, the down-right diagonal (x+1,y+1) happens instantaneously, but only when none of the adjacency checks are performed.
If this is a programming error on my part, forgive me, but if it is, I cannot for the life of me find it. I've been trying to fix this for several days now with no results. The thing that really baffles me, though, is that all 8 reactions are passed through the exact same function, which means that if this is happening for one reaction, shouldn't all of them experience the same problem?
The entire program is a couple lines short of 400, so I don't think that's going to be very easy on you, so I'll post the function which is used and the code which uses it.
The function:
React type, which stores each possible reaction in memory.
Function applied:
Oh yea, I running Windows XP 32 bit processing with DirectX 9.0 (I'm pretty sure)
I have the latest version of Blitz+ (I think)
I've searched the relevant code for errors, revised it, rewritten it, everything, and I always end up with the same problem. I can now say confidently that the error must not be in my code, but rather in the complier.
Here's a brief explanation of what should happen and what is happening:
Each pixel is checked for either adjacent pixels, diagonal pixels, or both to see if the two elements each one can be match a combination saved in memory, and if they do, the desired results for each of those two pixels are stored in memory as well. The pixels are converted to the correct results, and the pixel is set to be unable to react until the next frame.
Now this is what it does - All but two of the reactions work perfectly fine. However, when all 8 pixels are checked, directly down (x+0,y+1) and directly right (x+1,y+0) continue to react with no regard for the instruvtion to react only once per frame, therefore making all reactions in a straight line in that direction occur instantaneously, reulting in bad visuals and messed up reactions for the rest of the pixels on-screen. When none of the for adjacent checks are done, the down-right diagonal (x+1,y+1) happens instantaneously, but only when none of the adjacency checks are performed.
If this is a programming error on my part, forgive me, but if it is, I cannot for the life of me find it. I've been trying to fix this for several days now with no results. The thing that really baffles me, though, is that all 8 reactions are passed through the exact same function, which means that if this is happening for one reaction, shouldn't all of them experience the same problem?
The entire program is a couple lines short of 400, so I don't think that's going to be very easy on you, so I'll post the function which is used and the code which uses it.
The function:
;The following variable and function are used in reactions during the main loop. Global reacted ;variable used in reactions ;This function is used for doing reactions. Function ReactIt(xloc,yloc,xmod,ymod,part1,part2,result1,result2) If part1=pix(xloc,yloc) ;We don't want to check where something is out of the array and get a memory access violation! If xloc+xmod>0 And xloc+xmod<gw And yloc+ymod>0 And yloc+ymod<gh Then If reacted=0 ;Only allow one reaction per pixel per frame If partimer(xloc,yloc)>0 And partimer(xloc+xmod,yloc+ymod)>0 Then If pix(xloc+xmod,yloc+ymod)=part2 Then pix(xloc,yloc)=result1 pix(xloc+xmod,yloc+ymod)=result2 reacted=1 EndIf ;This next piece of code updates the color if need be. In case you were unaware, this program only redraws ;updated pixels. This is because the majority of things will not have every pixel being updated frequently, and ;even if it was, it would end up no slower than if I updated it all continuously. If reacted ;Update the pixels on-screen WritePixelFast xloc,yloc,partrgb(result1) WritePixelFast xloc+xmod,yloc+ymod,partrgb(result2) ;Reset the timers partimer(xloc,yloc)=0 partimer(xloc+xmod,yloc+ymod)=0 EndIf EndIf EndIf EndIf EndIf End Function
React type, which stores each possible reaction in memory.
Type React Field part1,part2 ;the two elements involved Field result1,result2 ;what each of the elements become. End Type
Function applied:
Local sc ;For checking, 0 is all around, 1 is only adjacent, and 2 is only diagonal. ;That's whay it's laid out like this. ;I'll start the array at 1 because the majority of the screen is likely to be the first element stated. ;This increases FPS and does not do anything against flexibility. For sc=1 To totalparts ;First the program checks for reactions. reacted=0 ;The pixel should only react once! This variable helps to keep track of that. For r.React=Each React If reacted Exit If partimer(upx,upy)<1 Exit ;Check the surrounding pixels If checkmethod=0 Or checkmethod=1 ReactIt(upx,upy,0,-1,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,0,1,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,1,0,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,-1,0,r\part1,r\part2,r\result1,r\result2) EndIf ;Now that the code for adjacent checks has been done, it's time for the diagonals. If checkmethod=0 Or checkmethod=2 ReactIt(upx,upy,1,1,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,-1,1,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,1,-1,r\part1,r\part2,r\result1,r\result2) ReactIt(upx,upy,-1,-1,r\part1,r\part2,r\result1,r\result2) EndIf Next
Oh yea, I running Windows XP 32 bit processing with DirectX 9.0 (I'm pretty sure)
I have the latest version of Blitz+ (I think)