System LightningRecycle

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
LightningRecycle allowes efficient usage of [ljass]lightning[/ljass]s and moving from destroying them to recycling.
Can be configured to precache only the types of [ljass]lightning[/ljass]s that the map is using.
There is also a picture of how the different types of lightnings look like (for fast refference).

API:

Exported constants mapped with human readable names to the Blizzards internal "code names" for lightnings:

[ljass]constant string LIGHTNING_CHAIN_LIGHTNING_PRIMARY = "CLPB"[/ljass]
[ljass]constant integer LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID = 0[/ljass]

[ljass]constant string LIGHTNING_CHAIN_LIGHTNING_SECONDARY = "CLSB"[/ljass]
[ljass]constant integer LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID = 1[/ljass]

[ljass]constant string LIGHTNING_DRAIN = "DRAB"[/ljass]
[ljass]constant integer LIGHTNING_DRAIN_ID = 2[/ljass]

[ljass]constant string LIGHTNING_DRAIN_LIFE = "DRAL"[/ljass]
[ljass]constant integer LIGHTNING_DRAIN_LIFE_ID = 3[/ljass]

[ljass]constant string LIGHTNING_DRAIN_MANA = "DRAM"[/ljass]
[ljass]constant integer LIGHTNING_DRAIN_MANA_ID = 4[/ljass]

[ljass]constant string LIGHTNING_FINGER_OF_DEATH = "AFOD"[/ljass]
[ljass]constant integer LIGHTNING_FINGER_OF_DEATH_ID = 5[/ljass]

[ljass]constant string LIGHTNING_FORKED_LIGHTNING = "FORK"[/ljass]
[ljass]constant integer LIGHTNING_FORKED_LIGHTNING_ID = 6[/ljass]

[ljass]constant string LIGHTNING_HEALING_WAVE_PRIMARY = "HWPB"[/ljass]
[ljass]constant integer LIGHTNING_HEALING_WAVE_PRIMARY_ID = 7[/ljass]

[ljass]constant string LIGHTNING_HEALING_WAVE_SECONDARY = "HWSB"[/ljass]
[ljass]constant integer LIGHTNING_HEALING_WAVE_SECONDARY_ID = 8[/ljass]

[ljass]constant string LIGHTNING_LIGHTNING_ATTACK = "CHIM"[/ljass]
[ljass]constant integer LIGHTNING_LIGHTNING_ATTACK_ID = 9[/ljass]

[ljass]constant string LIGHTNING_MAGIC_LEASH = "LEAS"[/ljass]
[ljass]constant integer LIGHTNING_MAGIC_LEASH_ID = 10[/ljass]

[ljass]constant string LIGHTNING_MANA_BURN = "MBUR"[/ljass]
[ljass]constant integer LIGHTNING_MANA_BURN_ID = 11[/ljass]

[ljass]constant string LIGHTNING_MANA_FLARE = "MFPB"[/ljass]
[ljass]constant integer LIGHTNING_MANA_FLARE_ID = 12[/ljass]

[ljass]constant string LIGHTNING_SPIRIT_LINK = "SPLK"[/ljass]
[ljass]constant integer LIGHTNING_SPIRIT_LINK_ID = 13[/ljass]

[ljass]constant integer LIGHTNING_COUNT = 14[/ljass]

[ljass]function GetLightning takes integer lightning_id returns lightning[/ljass]
[ljass]function RecycleLightning takes lightning l, integer lightning_id returns nothing[/ljass]

[ljass]function GetLightningCodeNameById takes integer lightning_id returns string[/ljass]
[ljass]function GetLightningIdByCodeName takes string code_name returns integer[/ljass]

JASS:
//! zinc





library LightningRecycle
{
    public
    {
        constant string  LIGHTNING_CHAIN_LIGHTNING_PRIMARY      = "CLPB";
        constant integer LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID   = 0;

        constant string  LIGHTNING_CHAIN_LIGHTNING_SECONDARY    = "CLSB";
        constant integer LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID = 1;

        constant string  LIGHTNING_DRAIN                        = "DRAB";
        constant integer LIGHTNING_DRAIN_ID                     = 2;

        constant string  LIGHTNING_DRAIN_LIFE                   = "DRAL";
        constant integer LIGHTNING_DRAIN_LIFE_ID                = 3;

        constant string  LIGHTNING_DRAIN_MANA                   = "DRAM";
        constant integer LIGHTNING_DRAIN_MANA_ID                = 4;

        constant string  LIGHTNING_FINGER_OF_DEATH              = "AFOD";
        constant integer LIGHTNING_FINGER_OF_DEATH_ID           = 5;

        constant string  LIGHTNING_FORKED_LIGHTNING             = "FORK";
        constant integer LIGHTNING_FORKED_LIGHTNING_ID          = 6;

        constant string  LIGHTNING_HEALING_WAVE_PRIMARY         = "HWPB";
        constant integer LIGHTNING_HEALING_WAVE_PRIMARY_ID      = 7;

        constant string  LIGHTNING_HEALING_WAVE_SECONDARY       = "HWSB";
        constant integer LIGHTNING_HEALING_WAVE_SECONDARY_ID    = 8;

        constant string  LIGHTNING_LIGHTNING_ATTACK             = "CHIM";
        constant integer LIGHTNING_LIGHTNING_ATTACK_ID          = 9;

        constant string  LIGHTNING_MAGIC_LEASH                  = "LEAS";
        constant integer LIGHTNING_MAGIC_LEASH_ID               = 10;

        constant string  LIGHTNING_MANA_BURN                    = "MBUR";
        constant integer LIGHTNING_MANA_BURN_ID                 = 11;

        constant string  LIGHTNING_MANA_FLARE                   = "MFPB";
        constant integer LIGHTNING_MANA_FLARE_ID                = 12;

        constant string  LIGHTNING_SPIRIT_LINK                  = "SPLK";
        constant integer LIGHTNING_SPIRIT_LINK_ID               = 13;
        
        constant integer LIGHTNING_COUNT                        = 14;

        function GetLightningCodeNameById(integer id) -> string
        {
            if      (id == LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID)   return LIGHTNING_CHAIN_LIGHTNING_PRIMARY;
            else if (id == LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID) return LIGHTNING_CHAIN_LIGHTNING_SECONDARY;
            else if (id == LIGHTNING_DRAIN_ID)                     return LIGHTNING_DRAIN;
            else if (id == LIGHTNING_DRAIN_LIFE_ID)                return LIGHTNING_DRAIN_LIFE;
            else if (id == LIGHTNING_DRAIN_MANA_ID)                return LIGHTNING_DRAIN_MANA; 
            else if (id == LIGHTNING_FINGER_OF_DEATH_ID)           return LIGHTNING_FINGER_OF_DEATH;
            else if (id == LIGHTNING_FORKED_LIGHTNING_ID)          return LIGHTNING_FORKED_LIGHTNING;
            else if (id == LIGHTNING_HEALING_WAVE_PRIMARY_ID)      return LIGHTNING_HEALING_WAVE_PRIMARY;
            else if (id == LIGHTNING_HEALING_WAVE_SECONDARY_ID)    return LIGHTNING_HEALING_WAVE_SECONDARY;
            else if (id == LIGHTNING_LIGHTNING_ATTACK_ID)          return LIGHTNING_LIGHTNING_ATTACK;
            else if (id == LIGHTNING_MAGIC_LEASH_ID)               return LIGHTNING_MAGIC_LEASH;
            else if (id == LIGHTNING_MANA_BURN_ID)                 return LIGHTNING_MANA_BURN;
            else if (id == LIGHTNING_MANA_FLARE_ID)                return LIGHTNING_MANA_FLARE;
            else if (id == LIGHTNING_SPIRIT_LINK_ID)               return LIGHTNING_SPIRIT_LINK;

            return "";
        }

        function GetLightningIdByCodeName(string code_name) -> integer
        {
            if      (code_name == LIGHTNING_CHAIN_LIGHTNING_PRIMARY)   return LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID;
            else if (code_name == LIGHTNING_CHAIN_LIGHTNING_SECONDARY) return LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID;
            else if (code_name == LIGHTNING_DRAIN)                     return LIGHTNING_DRAIN_ID;
            else if (code_name == LIGHTNING_DRAIN_LIFE)                return LIGHTNING_DRAIN_LIFE_ID;
            else if (code_name == LIGHTNING_DRAIN_MANA)                return LIGHTNING_DRAIN_MANA_ID; 
            else if (code_name == LIGHTNING_FINGER_OF_DEATH)           return LIGHTNING_FINGER_OF_DEATH_ID;
            else if (code_name == LIGHTNING_FORKED_LIGHTNING)          return LIGHTNING_FORKED_LIGHTNING_ID;
            else if (code_name == LIGHTNING_HEALING_WAVE_PRIMARY)      return LIGHTNING_HEALING_WAVE_PRIMARY_ID;
            else if (code_name == LIGHTNING_HEALING_WAVE_SECONDARY)    return LIGHTNING_HEALING_WAVE_SECONDARY_ID;
            else if (code_name == LIGHTNING_LIGHTNING_ATTACK)          return LIGHTNING_LIGHTNING_ATTACK_ID;
            else if (code_name == LIGHTNING_MAGIC_LEASH)               return LIGHTNING_MAGIC_LEASH_ID;
            else if (code_name == LIGHTNING_MANA_BURN)                 return LIGHTNING_MANA_BURN_ID;
            else if (code_name == LIGHTNING_MANA_FLARE)                return LIGHTNING_MANA_FLARE_ID;
            else if (code_name == LIGHTNING_SPIRIT_LINK)               return LIGHTNING_SPIRIT_LINK_ID;

            return -1;
        }
    }

    // configure the constants to your map's requirments
    //                                                                  example numbers
    constant integer LIGHTNING_CHAIN_LIGHTNING_PRIMARY_PRECACHE_COUNT   = 100;
    constant integer LIGHTNING_CHAIN_LIGHTNING_SECONDARY_PRECACHE_COUNT = 21;
    constant integer LIGHTNING_DRAIN_PRECACHE_COUNT                     = 34;
    constant integer LIGHTNING_DRAIN_LIFE_PRECACHE_COUNT                = 40;
    constant integer LIGHTNING_DRAIN_MANA_PRECACHE_COUNT                = 32;
    constant integer LIGHTNING_FINGER_OF_DEATH_PRECACHE_COUNT           = 1;
    constant integer LIGHTNING_FORKED_LIGHTNING_PRECACHE_COUNT          = 2;
    constant integer LIGHTNING_HEALING_WAVE_PRIMARY_PRECACHE_COUNT      = 67;
    constant integer LIGHTNING_HEALING_WAVE_SECONDARY_PRECACHE_COUNT    = 123;
    constant integer LIGHTNING_LIGHTNING_ATTACK_PRECACHE_COUNT          = 0;
    constant integer LIGHTNING_MAGIC_LEASH_PRECACHE_COUNT               = 0xF;
    constant integer LIGHTNING_MANA_BURN_PRECACHE_COUNT                 = 'A';
    constant integer LIGHTNING_MANA_FLARE_PRECACHE_COUNT                = 1;
    constant integer LIGHTNING_SPIRIT_LINK_PRECACHE_COUNT               = 2;

    // set this constant to the biggest number from the above (123 for the example configuration)
    //
    constant integer LIGHTNING_PRECACHE_COUNT_MAX = LIGHTNING_HEALING_WAVE_SECONDARY_PRECACHE_COUNT;

    lightning stack[LIGHTNING_COUNT][LIGHTNING_PRECACHE_COUNT_MAX];
    integer   top[LIGHTNING_COUNT];

    function init_lightnings()
    {
        integer i;

        for (0 <= i < LIGHTNING_CHAIN_LIGHTNING_PRIMARY_PRECACHE_COUNT)
        {
            stack[LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_CHAIN_LIGHTNING_PRIMARY_ID] = LIGHTNING_CHAIN_LIGHTNING_PRIMARY_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_DRAIN_PRECACHE_COUNT)
        {
            stack[LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_CHAIN_LIGHTNING_SECONDARY_ID] = LIGHTNING_CHAIN_LIGHTNING_SECONDARY_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_DRAIN_PRECACHE_COUNT)
        {
            stack[LIGHTNING_DRAIN_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_DRAIN_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_DRAIN_ID] = LIGHTNING_DRAIN_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_DRAIN_LIFE_PRECACHE_COUNT)
        {
            stack[LIGHTNING_DRAIN_LIFE_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_DRAIN_LIFE_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_DRAIN_LIFE_ID] = LIGHTNING_DRAIN_LIFE_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_DRAIN_MANA_PRECACHE_COUNT)
        {
            stack[LIGHTNING_DRAIN_MANA_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_DRAIN_MANA_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_DRAIN_MANA_ID] = LIGHTNING_DRAIN_MANA_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_FINGER_OF_DEATH_PRECACHE_COUNT)
        {
            stack[LIGHTNING_FINGER_OF_DEATH_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_FINGER_OF_DEATH_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_FINGER_OF_DEATH_ID] = LIGHTNING_FINGER_OF_DEATH_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_FORKED_LIGHTNING_PRECACHE_COUNT)
        {
            stack[LIGHTNING_FORKED_LIGHTNING_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_FORKED_LIGHTNING_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_FORKED_LIGHTNING_ID] = LIGHTNING_FORKED_LIGHTNING_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_HEALING_WAVE_PRIMARY_PRECACHE_COUNT)
        {
            stack[LIGHTNING_HEALING_WAVE_PRIMARY_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_HEALING_WAVE_PRIMARY_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_HEALING_WAVE_PRIMARY_ID] = LIGHTNING_HEALING_WAVE_PRIMARY_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_HEALING_WAVE_SECONDARY_PRECACHE_COUNT)
        {
            stack[LIGHTNING_HEALING_WAVE_SECONDARY_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_HEALING_WAVE_SECONDARY_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_HEALING_WAVE_SECONDARY_ID] = LIGHTNING_HEALING_WAVE_SECONDARY_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_LIGHTNING_ATTACK_PRECACHE_COUNT)
        {
            stack[LIGHTNING_LIGHTNING_ATTACK_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_LIGHTNING_ATTACK_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_LIGHTNING_ATTACK_ID] = LIGHTNING_LIGHTNING_ATTACK_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_MAGIC_LEASH_PRECACHE_COUNT)
        {
            stack[LIGHTNING_MAGIC_LEASH_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_MAGIC_LEASH_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_MAGIC_LEASH_ID] = LIGHTNING_MAGIC_LEASH_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_MANA_BURN_PRECACHE_COUNT)
        {
            stack[LIGHTNING_MANA_BURN_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_MANA_BURN_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_MANA_BURN_ID] = LIGHTNING_MANA_BURN_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_MANA_FLARE_PRECACHE_COUNT)
        {
            stack[LIGHTNING_MANA_FLARE_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_MANA_FLARE_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_MANA_FLARE_ID] = LIGHTNING_MANA_FLARE_PRECACHE_COUNT;

        for (0 &lt;= i &lt; LIGHTNING_SPIRIT_LINK_PRECACHE_COUNT)
        {
            stack[LIGHTNING_SPIRIT_LINK_ID]<i> = AddLightning(GetLightningCodeNameById(LIGHTNING_SPIRIT_LINK_ID), false, 0, 0, 0, 0);
        }
        top[LIGHTNING_SPIRIT_LINK_ID] = LIGHTNING_SPIRIT_LINK_PRECACHE_COUNT;
    }

    public function GetLightning(integer lightning_id) -&gt; lightning
    {
        top[lightning_id] =  top[lightning_id] - 1;   
        debug 
        {   
            if (top[lightning_id] &lt; 0) 
            {
                BJDebugMsg(&quot;LightningRecycle error: no more lightnings of type \&quot;&quot; + /*
                         */ GetLightningCodeNameById(lightning_id) + &quot;\&quot;, maybe you are not recycling them or you need to precache more&quot;); 
            }
        }

        return stack[lightning_id][top[lightning_id]];
    }

    public function RecycleLightning(lightning l, integer lightning_id)
    {
        MoveLightningEx(l, false, 0, 0, 0, 0, 0, 0);
        stack[lightning_id][top[lightning_id]] = l;
        top[lightning_id] = top[lightning_id] + 1;
    }   

    function onInit()
    {
        init_lightnings();
    }       
}

//! endzinc
</i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Attachments

  • lightnings_demo.png
    lightnings_demo.png
    437.4 KB · Views: 450

Azlier

Old World Ghost
Reaction score
461
Will lightning recycling even actually do anything? Improve efficiency? Save memory? It's clear the lightning is different from, say, a unit and more like a texttag in that it is not an agent, but simply extends a handle instead. It's been learned in the past that recycling texttags was useless, after all, because they recycle themselves under the hood.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Azlier:
1. Will lightning recycling even actually do anything? Improve efficiency? Save memory? It's clear the lightning is different from, say, a unit and more like a texttag in that it is not an agent, but simply extends a handle instead. It's been learned in the past that recycling texttags was useless, after all, because they recycle themselves under the hood.

1. I am not exactly sure if lightnings are like textags (i.e being recycled under the hood and textags are limited to 1600 total for all playesr 100 per player), while lightnings are not. But still calling a Destroy function on a

JASS:
struct lightning
{
    real x0, y0, z0, x1, y1, z1, a, r, g, b;
    string code_name;
};


is probably not the best idea.

Other handles like image, ubersplat, terraindeformation and weathereffect don't extend agent does that mean that they are recycled under the hood as well?
 

Bribe

vJass errors are legion
Reaction score
67
terrain deformations cannot be destroyed whatsoever. Nor are their handle indices removed. Creating on terrain deformation creates a permanent leak in-game.

It is similar to using GUI group-enumerating techniques, because the handle ID stack will never go down.
 

Deaod

Member
Reaction score
6
images are being recycled. They dont, however, use reference counting.
Ubersplats are just glorified images.
 

tooltiperror

Super Moderator
Reaction score
231
images are being recycled. They dont, however, use reference counting.
Ubersplats are just glorified images.
Do Ubersplats share in the images' handle id pool?
 

Jedi

New Member
Reaction score
63
Lightning handle id number goes from 1 to ... ?
Texgtags from 99 to 0.
Images from 98 to ...?They increases two by two, 100 - 102 - 104
Ubersplats from 0 to ...?

Four objects can share id 98 :O

Edit:not 99
 

tooltiperror

Super Moderator
Reaction score
231
Graveyarded.

Lightning is plenty fast, and any speed difference is completely negligible.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top