Multiple missile question (Again) :)
-
Wednesday, September 26, 2012 2:53 AMAnswererJFC007 I try doing my own cleanup but it still jams. I was wondering if someone could explane How to fix this so I can do ones in the future by my self. Thanks!!
One thing that is impossible is impossible no matter if it is proven so first.
All Replies
-
Wednesday, September 26, 2012 7:08 AMAnswerer
Hey Zock77!
I did some tweaks. Import Code -> JFC007-0
But still far from enough to fix it!
There are 2 main serious problems:
1st) Your code allows infinite shots! You have a sub-loop like this -> For iii = 1 To numshotsfired
As the number of shots increases (numshotsfired = numshotsfired + 1 inside Sub Fire), the bigger the loop iteration, and thus, the longer to complete it!!!
Since it always starts from the very 1st shot (For iii = 1) till the most latest one (To numshotsfired), even though most of them are already far off screen size limits!
For example, if 100 missiles were shot, it is 100 loop iterations for iii, times TurretNum ii loop! Total 500 iterations if TurretNum is 5!!!
2nd) To make matters worse, there's no mechanism to delete older used indices from the many arrays the game uses!
It means all of those many arrays get fatter & slower as numshotsfired increases!
I tried to put some code to delete them after Else Shapes.Remove(Ball[ii][iii]) part. But I still can't figure out how to properly clean them all. Only you can understand when an older array index can get removed safely.
There were other non-optimized code, like using GraphicsWindow.MouseX or GraphicsWindow.Width while their corresponding variables were already available (MouseX & gw)!
As a general rule, getting values from variables are faster than from function or property calls! :P
A final advise... Since this Lotsa Turrets game is based on previous Missile Turret (MJV649-3), it'd be good if you take another look at it, to see how many things got implemented or tweaked there, especially the Sub GarbageCleanup event.
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Wednesday, September 26, 2012 7:40 AM
-
Wednesday, September 26, 2012 6:05 PMAnswerer
Thanks!!!!
I was wondering also if there was any other approach I could go at it at. It may just be small basic, but games like this:<cite>onslaught2.org/</cite> Are Very smooth. Maybe they did it a different way?
Thanks Again.
One thing that is impossible is impossible no matter if it is proven so first.
-
Wednesday, September 26, 2012 9:42 PMAnswerer
KXN139
I just tried fixing it by:
1) finding out which was the highest ball number that was off the screen
2) making sure that all the numbers before that were out and,
3) If so then making the for statement go from the highest ball number.
But it doesn't quite work. can you help?
One thing that is impossible is impossible no matter if it is proven so first.
-
Thursday, September 27, 2012 2:19 AMAnswerer
Sup Zock77!
Noticed none of my little optimization tweaks haven't shown up at your KXN139 current version. At least I hope you've run JFC007-0 just to check them out. :-D
Anyways, I have to repeat myself again:
Your For iii = 1 To shotsFired loop is flawed in terms of speed & memory! shotsFired scales up to infinity!!!
Compare that to the solution present in previous MJV649-3 @ Multiple Missile Question thread.
Instead of a loop including all shots ever fired, it was done like this inside Sub MoveMissiles:
For p = i - MTrack To i
Consider p = iii & i = shotsFired for comparing yours to the above.
instead of p = 1, which is the 1st shot fired, it uses current i missile - MTrack.
MTrack is the maximum number of missiles shot the program can care about!
So, the number of loop iterations is fixed, dictated by MTrack! In yours, it gets bigger as shotsFired increases!!!
I'll leave to you about the garbage collector adaptation, which is responsible to erase old used array indices.Otherwise, they will consume all memory and make read & write operations in arrays extremely slow!
Just dig up from MJV649-3 to see how some features were implemented there, so you can adapt them to your current Turrets version.
Good luck!
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Thursday, September 27, 2012 2:21 AM
- Marked As Answer by Zock77Editor Thursday, September 27, 2012 5:40 PM
-
Thursday, September 27, 2012 5:40 PMAnswererSweet! I'll try that! And yes I did look @ your program! I will try adding all the stuff you told me together and get it to work! Thanks!
One thing that is impossible is impossible no matter if it is proven so first.

