User Tag List

Results 1 to 7 of 7

Thread: Speed issues with tower defense

  1. #1
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Yima's Avatar
    Join Date
    Feb 2008
    Location
    Sweden
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Speed issues with tower defense

    I have created a simple engine, hoping to be able to create a tower defense like game. However, I am running into performance issues, probably due to the amounts of loops I use.

    When I have about 30 "cannons" firing on the same amount of enemies, I experience nasty slowdowns.

    My question is if anyone know about any game of this kind, made in MMF2, that runs smoothly. It would be interesting to know if this is a processing power limitation in MMF2 (I have read that the fastloop solution, while often practical, is a weakness performance wise in MMF2), or if my solution is just flawed.

    Thank you for any answers

  2. #2
    Clickteam Clickteam
    Jeff's Avatar
    Join Date
    Jun 2006
    Location
    Battle Ground Washington
    Posts
    11,822
    Mentioned
    7 Post(s)
    Tagged
    2 Thread(s)

    Re: Speed issues with tower defense

    It shouldn't slow down much.

    Did you see this game:
    http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=200350&Searchpa ge=2&Main=27346&Words=Outpost&Search=true#Post2003 50

    I don't think its release yet but when I saw it at the last convention it had a lot going on and ran amazingly fast. So its possible you might need to refine your events to get more out of the program.

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Yima's Avatar
    Join Date
    Feb 2008
    Location
    Sweden
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Speed issues with tower defense

    Thanks for the quick reply. It really seems I have to learn a bit more, and that the fault lies in my solution. I also just stumbled over the Foreach object, which seems to be very interesting and highly related to my problem. Now I just need to lean how to use it

  4. #4
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Århus
    Posts
    3,455
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Re: Speed issues with tower defense

    What kind of system to you use to make the cannons fire at the nearest enemy? If each tower [1..N] must check if each enemy [1..M] is within shooting distance, you have to perform N*M distance calculations every frame.

    30 cannons firing at 30 enemies gives you 900 distance calculations to test for.. every frame..

    You need to find some way to make this faster. You could for example make them only test for nearby enemies once they are ready to shoot again, and not test anything during their cooldown time-period. Combining this with other methods should make it run pretty fast.

  5. #5
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Yima's Avatar
    Join Date
    Feb 2008
    Location
    Sweden
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Speed issues with tower defense

    I have sort of figured out how to use the foreach object now, and the results so far are very promising.

    The test I did now consists of 100 cannons firing at about 70 enemies, and the program runs at a steady 60 fps for me.

    The shooting is managed by two loops - one that loops through the cannons, and one that does the distance check for each possible target, and fires if the target is in reach. Only cannons that are ready to shoot are added to the loop, to keep the loop size reasonable (pretty much the cooldown method you mentioned).

    I am pretty certain that with a few more tweaks there will be little trouble creating this game. The game will not be based around these amounts of cannons and enemies anyway - the numbers will probably be around half of what I have tested with, at most. I just like to have a good margin

    If you (or anyone else) are interested in looking at the test project, here are two links - one for the mfa, and one for the executable.

    www.akr.se/Anders/defenseengine.mfa (requires the foreach object version 1.003)

    www.akr.se/Anders/defenseengine.exe

    Thanks again for the help!


  6. #6
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module

    Join Date
    May 2011
    Location
    Pennsylvania, USA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Speed issues with tower defense

    Here's a technique I use, in hopes it would help others that stumble across this post.

    I employ the use of an circle active object(actually, it's an oval due to using isometric perspective) that is transparent everywhere except for the circle itself. Then, on each execution cycle I have a fastloop through each turret via an active object acting as a controller(I use this object to hold all turret properties, because each turret could be a different type and have different actions/attributes). All turret controllers have the variable "range" that I store and use to perform a scaling of the circle to the value stored in "range." So, during the fastloop, I move the circle to the x,y coordinates of the controller(which are also the x,y coords of the actual turret as well) and apply the scaling(it could be different for different types of turrets and their "level" as they can be upgraded). From here, I use the built-in collision detection between the circle and all enemies to perform a distance calculation on only those enemies colliding with the "range mask" and store the fixed variable of the enemy with the closest distance and essentially keep track of that enemy as the "target." At the end of the loop, I move the range mask offscreen, so it won't be rendered. Also, I use the technique described by Andos to only perform this calculation only when the turret is off cooldown. Likewise, I control whether the turret is in an "active" state, meaning it has a target and it will perform the "shooting" animation in another alt value, which helps to optimize the events controlling the action process of the associated turret.

    So, the target processing and the action processing work as blocking mechanisms for each other to help optimize code execution. So far, I've not found any slowdown, but I often wonder about the processing difference of scaling a circle and the built-in collision detection qualifier with that of distance calculation on all objects. I only assume it is faster, but I could be wrong since I haven't looked at the source code of those functions.

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)

    Re: Speed issues with tower defense

    It's definitely faster to calculate the range, instead of using circle shaped detectors. Detectors can be scaled quickly if you're using HWA, but fine collision detection is still very slow (and gets exponentially slower, the larger the object).

    I haven't actually looked at his file, but it sounds like Yima is doing it right. It could still be made more efficient by spreading the range checks over several frames (turrets don't need to react within 1/60th of a second after all).

Similar Threads

  1. Working on Tower Defense, running into issues...
    By Stiffman in forum The Games Factory 2 - Technical Support
    Replies: 4
    Last Post: 29th July 2013, 02:23 PM
  2. Elaboration d'un Tower defense
    By faeriebass in forum Multimedia Fusion 2 - Technical Support
    Replies: 11
    Last Post: 5th June 2010, 01:45 PM
  3. Tower defense tower firing
    By splicel in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 7th May 2010, 06:34 PM
  4. Tower Defense with MMF2?
    By gro0003 in forum Multimedia Fusion 2 - Technical Support
    Replies: 22
    Last Post: 12th August 2007, 01:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •