User Tag List

Results 1 to 6 of 6

Thread: Generating code from my program - hit a brickwall

  1. #1
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleMac Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    NashMuhandes's Avatar
    Join Date
    Dec 2013
    Location
    Kuala Lumpur, Malaysia
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating code from my program - hit a brickwall

    So I've been working on an editor-like thing with CF 2.5 for another project of mine that's not made in MMF. The purpose of this program is to allow me to edit items and have it generate C-like code and save it to a text file so I can copy and paste that into my other project.

    Here's a sample of what my MFA app actually outputs:

    Code:
    //===========================================================================
    //
    // AUTOMATICALLY GENERATED BY Z.A.C.K
    // DO NOT EDIT BY HAND!
    //
    //===========================================================================
    
    #library "item"
    
    #include "zcommon.acs"
    #include "is_spec.acs"
    #include "is_defs.acs"
    
    #import "itemfunc.acs"
    
    function void InitItems(void)
    {
    	// 0
    	SetBaseItem(0, BASE_ITEM_PROP_IDNAME, "Z_NewItem0");
    	SetBaseItem(0, BASE_ITEM_PROP_NAME, "Default Item 0");
    	SetBaseItem(0, BASE_ITEM_PROP_DESCRIPTION, "An undescribed item.");
    	SetBaseItem(0, BASE_ITEM_PROP_TYPE, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_VALUE, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_WEIGHT, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_RATING, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_CREATIONTIME, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_CONDITION, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_CONDITIONMAX, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_STOLEN, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_OWNER, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_EFFECT, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_SCRIPTACT, 0);
    	SetBaseItem(0, BASE_ITEM_PROP_SCRIPT, "");
    
    	// 1
    	SetBaseItem(1, BASE_ITEM_PROP_IDNAME, "Z_NewItem1");
    	SetBaseItem(1, BASE_ITEM_PROP_NAME, "Default Item 1");
    	SetBaseItem(1, BASE_ITEM_PROP_DESCRIPTION, "An undescribed item.");
    	SetBaseItem(1, BASE_ITEM_PROP_TYPE, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_VALUE, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_WEIGHT, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_RATING, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_CREATIONTIME, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_CONDITION, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_CONDITIONMAX, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_STOLEN, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_OWNER, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_EFFECT, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_SCRIPTACT, 0);
    	SetBaseItem(1, BASE_ITEM_PROP_SCRIPT, "");
    
    	// 2
    	SetBaseItem(2, BASE_ITEM_PROP_IDNAME, "Z_NewItem2");
    	SetBaseItem(2, BASE_ITEM_PROP_NAME, "Default Item 2");
    	SetBaseItem(2, BASE_ITEM_PROP_DESCRIPTION, "An undescribed item.");
    	SetBaseItem(2, BASE_ITEM_PROP_TYPE, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_VALUE, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_WEIGHT, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_RATING, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_CREATIONTIME, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_CONDITION, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_CONDITIONMAX, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_STOLEN, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_OWNER, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_EFFECT, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_SCRIPTACT, 0);
    	SetBaseItem(2, BASE_ITEM_PROP_SCRIPT, "");
    
    	// 3
    	SetBaseItem(3, BASE_ITEM_PROP_IDNAME, "");
    	SetBaseItem(3, BASE_ITEM_PROP_NAME, "");
    	SetBaseItem(3, BASE_ITEM_PROP_DESCRIPTION, "");
    	SetBaseItem(3, BASE_ITEM_PROP_TYPE, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_VALUE, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_WEIGHT, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_RATING, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_CREATIONTIME, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_CONDITION, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_CONDITIONMAX, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_STOLEN, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_OWNER, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_EFFECT, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_SCRIPTACT, 0);
    	SetBaseItem(3, BASE_ITEM_PROP_SCRIPT, "");
    
    	// goes all the way to 127 but I edited it out to save forum space
    }
    
    // EOF
    Anyway, I've run into a brickwall with regards to speed and efficiency. The item data is stored in a 2D string array (first dimension being total items, second dimension being properties for each item), but I just can't get it to generate the code fast enough. It works fine if there are only like 10 - 100 items in the X dimension, but it's just too slow beyond that. And no, 100 items isn't enough for my project.

    At first, what I'm doing with the code generation is, I write a bunch of stuff into a global string array, and then copy this text to an Edit object, then finally opening a Save dialog to save the text to disk. This is way too slow and I think the program simply cannot handle such a large amount of text being stored in memory.

    Secondly, I tried to avoid storing so much data in the memory and instead write to the disk directly constantly. So upon clicking the Generate button, it just goes through the X dimension, reads all the properties, writes to disk, and keeps moving on until the end of the X array. This is still slow and I don't think it's a good idea to write so much data to the disk in such quick succession... I don't know, it just feels abusive haha.

    So basically my question is, what's the best way to get my program to generate a HUGE amount of text that can then be saved to the disk?

    I'll put up my MFA files so this all makes more sense:

    https://dl.dropboxusercontent.com/u/...0String%5D.mfa (global string version)

    https://dl.dropboxusercontent.com/u/...%20Disk%5D.mfa (write directly to disk version)

    I'd really appreciate any help on this because this has been bothering me for days and I can't continue if I don't solve this problem.

  2. #2
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Writing to disk would definitely introduce a bottleneck, you'd be surprised at how much time it takes to constantly add to a file - I would go back to the way that you were doing it originally and construct the entire file in MMF before writing it to disk. If it's all text, even with thousands of items, I don't think memory will be a problem.

    I don't have MMF on the computer I'm on just now, but you could try adding a couple of debug lines to measure the time taken for each step (add a line to a List object or something with a timestamp) to see where the majority of the time is going.

  3. #3
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleMac Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    NashMuhandes's Avatar
    Join Date
    Dec 2013
    Location
    Kuala Lumpur, Malaysia
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It obviously stalls the longest in Generate ACS -> generate loop (line 52) while it's trying to write all of that text into the global string. It's fine with a few hundred items but going into the thousands, it becomes impossible. It's frustrating because typically things like this shouldn't take this long, there are programs out there that generate a larger amount of data in a much shorter amount of time.

    In line 52 I have 16 actions fired in 1 loop to write the source code text into the global string, I had to split it into 16 actions because trying to cram it all into a single action, MMF reports "the expression is too complex"... could this be a problem? I don't know any other way to do it and trying to do it in a single action is just not possible.

    EDIT: Okay, reducing line 52 to a single action (so it only generates 1 line of code) definitely makes the generation much faster and I was successfully able to generate 1024 items into a text file. I think MMF just can't handle that many actions in a single fast loop? D: What other options do I have?

    On a side note - if my program hangs from trying to generate too many lines of code, the app will just close itself without any messages and my computer will be slow as a turtle that I have to restart the machine... I guess the MMf runtime isn't cleaning up the memory properly... :S

    EDIT 2: Even by limiting the code generated to a single line (it only generates "// <loop index>"), it can only go so far... it fails if I set the X dimension to 8192 (the file selector doesn't appear, and then the runtime just freezes)... so again, I guess the global string just can't hold that much text? :S

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fanotherpg's Avatar
    Join Date
    Jul 2006
    Location
    High Wycombe, Buckinghamshire, UK
    Posts
    3,665
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried to use Internal List Object (by LIJI?) instead of Global Stings? Remember you can make objects global as well. And ILO is so much faster than List object or global strings according to author.

  5. #5
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleMac Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    NashMuhandes's Avatar
    Join Date
    Dec 2013
    Location
    Kuala Lumpur, Malaysia
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the bump. Apparently there is no Fusion 2.5 version of the Internal List Object by Liji. Anyone care to clarify?

  6. #6
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Ryan's Avatar
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    1,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried keeping your data in a list object and using the save to file feature of the list object? Hiding the list object will also speed things up as redrawing the list tends to bottleneck the application.

    Lists can have handle large amounts of data and save without appearing to crash the application. If you're not using the list object, changing the cursor to a loading icon (hourglass) via the cursor extension before you save also prevents windows from detecting a freeze.

Similar Threads

  1. Generating Backdrops
    By hellii in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 9th February 2014, 08:24 PM
  2. Generating raindrops where the player is
    By AndyBazooka in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 11th December 2013, 01:55 PM
  3. Non Repeating Number Generating in IOS .
    By hcem in forum iOS Export Module Version 2.0
    Replies: 1
    Last Post: 19th January 2013, 03:51 PM
  4. anyone use sikuli, autohotkeys or macro program to help them code Faster?
    By dov_b in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 30th August 2012, 11:43 AM
  5. Generating 1 or -1 in an expression
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 21st August 2012, 05:22 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
  •