User Tag List

Results 1 to 6 of 6

Thread: Can you help optimise this code?

  1. #1
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you help optimise this code?

    Hi peeps, can anyone help with the following?

    Each player has a similar toolbar, in the middle are the weapons and 4 upgrades (hull, speed, boosters & magnets):

    RT01.png

    The red areas are upgrades/weapons you already have purchased, and the light green are upgrades which you can afford based on your current coins and current upgrade level of that item/weapon.

    Each of the upgrades and levels costs a different amount, and nothing is on a linear scale - so in order to code this I'm having to perform loads of counter comparing which is eating up resources on the XNA exporter.

    The actual item/weapon purchasing isn't too bad as the code is nested in a deactivated group until you visit your garage - plus I'm only having to check whether a player is on a particular item in the garage, test if they press a button, test resources, then make the changes - which is all contained in one event per upgrade.

    The problem is the upgrade notifications, which show what you can afford - and is a feature I'd like to keep because it really helps keep players in the main game, rather than wasting time in the garage (which otherwise leaves them at a disadvantage). This feature currently works out what you can afford on each single item/weapon all the way to fully upgraded, but it's coded in a very crude fashion just to test it - but I now need a far more efficient method than constantly testing counters (which is smashing the frame rate as it costs around 250 events per player - i.e. 1,000 bad events!) I tried grouping bits, but it's still a really poor method.

    RT02.png

    So basically:
    If you have no hull upgrade, the counter will test the 4 counters for the cost of level 1 upgrade, and highlight it green if you have enough - it will also test the cost Tlevel 1 + 2 upgrade and if you have enough for both, highlight level 2 upgrade as available; and so on.
    If you have one hull upgrade, the same applies, but it is now comparing the counters to different values, taking into account you've bought the first one.
    Each level of upgrade you purchase activates an appropriate group which constantly checks your coins to see how many upgrades of that item you can afford.

    So... very bad, I know

    I assume this can be done better by testing the value of your upgrade and taking certain costs off based on that, but I'm finding it hard to get something coded efficiently. Is there a better way of doing this (within the limitations of XNA objects) such as using an array to check values?

    Thanks

  2. #2
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    If you can use an array in XNA, then yes, that is the better way to do it. :P

  3. #3
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Konidias View Post
    If you can use an array in XNA, then yes, that is the better way to do it. :P
    There is an array object, but I have no idea how to implement that into a shop code

  4. #4
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You'd want to set up the array somewhat like this:

    X index = Thing you want to upgrade
    Y index = Upgrade slot
    Z index = Info about the upgrade (lets say 1 = cost)

    So x1,y2,z1 would be the cost of the green upgrade on the S row. (if your array index starts at 0)

    x2,y1,z1 would be the cost of the green upgrade on the B row, and so forth.

    You could have z0 equal the unlocked flag to determine if the player has that upgrade purchased already. So z0 = 0 would mean it's not purchased, and z0 = 1 would mean purchased.

    Then you could set up a fastloop that would run through all the non-purchased slots and determine if the player's money amount can afford those... etc.

    You'd only want to run the fastloop when necessary. Running it all the time would be bad. One way to do this would be to run an initial fastloop through all possibilities to determine the next lowest cost upgrade that can be afforded. This would be the value you would check each iteration against the player's money. If the player gets more money than that value, then you'd want to run the fastloop at that point to update the possible upgrades the player could purchase, and determine the next lowest cost upgrade to replace the other one.

    So if upgrade A costs 500, upgrade B costs 900, upgrade C costs 1100, it would set the "lowest cost" value to 500, and then when the player has 500 or over in money, it would run the fast loop, highlight upgrade A as "available to buy" and then set the value to 900 since that's the next lowest available upgrade. This way the loop only runs once each time the player reaches that next money milestone to afford the next lowest cost upgrade.

    Doing it this way should be pretty instant and not require tons of processing or anything, as it's only looping through all upgrade options once per milestone.

  5. #5
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are a gentleman and a scholar Konidias!

    I created the array pretty much as you said, but left Z0,1,2,3 as the 4 different resource costs for the upgrade - then I got stuck working out how to use that data. I managed to get the garage to check your coins and deduct them as appropriate using the array database instead (which is great, because it means I only need to change the array data when game balancing, not shed loads of events for each player), but then got a bit stuck working out how to do more with that array data and actually utilise it to strip events out - I completely overlooked the idea of expanding the Z to include on/off flags or other information, so that's superb - thank you for your help.

  6. #6
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Glad I could be of help. Also you may end up using nested fastloops for this, but it should still be okay as long as you make sure they don't get stuck in infinite loops (you'll know right away since the game will just freeze :p) If anything, you could look up more info about fastloops and nested fastloops on the forum. It has all the info you could need on the subject.

    Also on a final note, it's always good to put fastloops into groups and disable those groups when they aren't needed, so the game isn't running through those events. Just an optimization tip.

    Good luck! I hope everything works out well for you.

Similar Threads

  1. [PAID] Optimise Group List
    By Ryan in forum Paid Design & Development Requests
    Replies: 5
    Last Post: 20th March 2014, 10:44 PM
  2. RGB into Hex code?
    By Game_Master in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 4th October 2009, 09:37 AM
  3. Using DLL or Code
    By Pegasus_Seiya in forum Extension Development
    Replies: 0
    Last Post: 12th June 2009, 04:43 PM
  4. V-Code Generator Source Code
    By LB in forum File Archive
    Replies: 1
    Last Post: 10th March 2008, 08:52 PM

Posting Permissions

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