Asset - Scripts TMC Script Batch

Discussion in 'Marketplace' started by icuurd12b42, Apr 22, 2016.

  1. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    Posted 26 May 2015 - 06:20 AM

    [​IMG]

    TMC Script Batch

    Outputs: All

    Type: Scripts

    Included: Scripts

    Demo: None

    Marketplace: https://marketplace....mc-script-batch



    Description:

    Defer Script Calls for Later!

    TMC Script Batch allows you to batch a set of scripts from anywhere in your game to be performed later.

    One major hurdle in game maker is to have an object do multiple things at different times, have an effect on multiple parts of your game.

    Such hurdle for example is to have 2 rendering modes, like say you have a light that draws a lightbulb in the room but also needs to draw a light pattern on a surface... The conventional method is to draw the bulb, switch the rendering mode to bm_add and set the draw target to a surface and draw you light pattern on the surface...

    Another hurdle is drawing shadows on the ground for a character, but the character is at a higher depth than the ground and other things have been drawn already... and you can't draw under the other stuff...

    With this system you can batch script calls into a script container and perform the calls at a later time from another object!

    For example, a character renders itself in the draw on screen, but can add scripts to a batch directly from the end step to tell the ground to draw its shadow when the ground draws.

    Another hurdle is texture swaps and draw batches on android; having things render with bm_add, then bm_normal, having to change the texture for a render... with this system you can batch the draw calls yourself. Have a script batch for bm_add mode, setting the mode ounce and performing all the scripts in one go,

    Features
    • Create multiple independent script batches
    • Run the batch at any time and in any event you want
    • API similar to the ds_list
    • Use it to batch your rendering
    • Use it to perform actions on multiple parts of the game from one location
    BETA RELEASE
    Only 2 batchable scripts are provided Please suggest or post your additions below. Mind you it would be senseless to bloat the assets with batchable scripts since they are easy to make.
     
    Last edited: Aug 14, 2018
  2. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    Example use, keep in mind that I'm keeping this simple and not including any variables your instance may be using aside the batch system related stuff

    An instance, drawing stuff as specified in its step or end step. Useful for, say, if you have code in the end step that warrants adding a special effect to be drawn in the draw event...

    Create:
    Code:
    batch = tmc_sb_batch_create(); //create the batch
    
    Destroy and room ends (room end may need to check for object or room persistence)
    Code:
    tmc_sb_batch_destroy(batch); //cleanup/free the batch
    
    Draw:
    Code:
    draw_self(); //this could actually have a batch equivalent :)
    tmc_sb_batch_execute_clear(batch);// perform the batch, this holds draw instructions in this case
    
    Begin step, optional, if say you have frame skipping and you want to make sure the batch does not hold instructions covering multiple steps
    Code:
    tmc_sb_batch_clear(batch); //clear it
    
    Ok, now you can use it like in the end step in this case
    Code:
    if(Thrust != 0) //check if the ship is thrusting forward
    {
       //Draw the engine thrust
        tmc_sb_batch_add(batch, tmc_sb_draw_sprite_ext, Thust_spr, irandom(4), x, y, image_xscale, image_yscale, image_angle, merge_color(c_orange,c_yellow,random(1)), image_alpha );
    }
    
    Usage for a global batch for, say, a layered bm_add effect
    bm_add_layer object, depth -1000
    Create:
    Code:
    global.bm_add_batch = tmc_sb_batch_create(); //create the batch
    
    Destroy and room ends (room end may need to check for object or room persistence)
    Code:
    tmc_sb_batch_destroy(global.bm_add_batch); //cleanup/free the batch
    
    Draw:
    Code:
    draw_set_blend_mode(bm_add);
    tmc_sb_batch_execute_clear(global.bm_add_batch);// perform the batch, this holds draw instructions in this case
    draw_set_blend_mode(bm_normal);
    
    Begin step, optional, if say you have frame skipping and you want to make sure the batch does not hold instructions covering multiple steps
    Code:
    tmc_sb_batch_clear(global.bm_add_batch); //clear it
    
    objects that have bm_add things to draw on that bm_add layer
    end step:
    Code:
    if(OnFire) //check if the ship is on fire
    {
       //draw the flames
        tmc_sb_batch_add(global.bm_add_batch, tmc_sb_draw_sprite_ext, Fire_spr, irandom(4), x, y, image_xscale, image_yscale, image_angle, merge_color(c_orange,c_yellow,random(1)), image_alpha );
    }
    
    These examples are pretty "draw" centric. But it can be used for other things you need to handle together.
    Other uses
    drawing on the gui layer
    drawing on a surface
    drawing in a shader context
    drawing in a depth context
    drawing in a blend mode context
    defer actions to the next step by processing the batch in the begin step and adding to it in the step or end step or draw
    Have an instance Tell a controller to do things
    Have a controller tell an instance to do things

    You can have multiple batch in the instance, like an end step batch, a pre draw batch, an after draw batch... Multiple global batches. You can really go nuts
     
    Last edited: Dec 1, 2016
  3. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    Example zordering for isometric game

    iso_draw_object, depth -1000;
    Create:
    Code:
    //create a batch from 0 to the view height+256, the +256 is to allow instance below the view bottom that are still visible, assuming largest sprite height is 256
    global.extra = 256;
    for(var i = 0; i<view_hview+global.extra; i++)
    {
        global.batch_layers[i] = tmc_sb_batch_create();
    }
    
    Draw:
    Code:
    //draw from 0 to the view height + extra.
    for(var i = 0; i<view_hview+global.extra; i++)
    {
        tmc_sb_batch_execute_clear(global.batch_layers[i]);
    }
    
    Your isometric object. Depth 0, y origin is assumed to be at the bottom of the sprite
    draw:
    Code:
    //In draw, don't draw self, add self in the right batch array according to y position
    //if in view and not outside the array limit on y adjusted
    if(bbox_right>view_xview and bbox_left<view_xview+view_wview and y>view_yview and bbox_top<view_yview+view_hview and y<view_yview+view_hview+global.extra)
    {
        var i = y-view_yview; //map the y to the array index 0 to max array size
        //add the drawing of self to the array for the batch to process it
        tmc_sb_batch_add(global.batch_layers[i], tmc_sb_draw_sprite_ext, sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha );
    }
     
    Last edited: Dec 1, 2016

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice