Regarding Structs

Ayanami

칼리
Reaction score
288
Just read this.

Does this mean that doing [ljass]struct MyStruct extends array[/ljass] is better than simply doing [ljass]struct MyStruct[/ljass]? And if I use [ljass]struct MyStruct extends array[/ljass], does [ljass].allocate()[/ljass] and [ljass].deallocate()[/ljass] still work? Or would I just have to use the custom create and destroy?

And what exactly is [ljass]delegate[/ljass]?
 

tooltiperror

Super Moderator
Reaction score
231
It means that if you care about something like .0001 seconds of quickness for a huge loss in interface then you should use what that struct teaches.

If you're a sane person like the rest of the world, just use structs.

If you're coding something that needs extreme speed like a projectile system, then use that tutorial's contents.

And yes, you have to do all of your allocation by hand when extending array. Hint: someone write an allocation module.

A delegate is complicated.

JASS:

//! zinc

library Delegate
{

  struct Data
  {
      public method Alert(string str)
      {
          BJDebugMsg(str);
      }
  }
  
  struct Subdata
  {
    delegate Data data_delegate;
    
      static method create() -> thistype
      {
        thistype this = thistype.allocate();
        data_delegate = Data.create();
          return this;
      }
  }
  
  function onInit()
  {
    /*
     *  Note that we're calling "data.Alert()" even though
     *  data is Subdata and not Data.  Because there is
     *  no Alert method in data (because data is Subdata)
     *  it looks for the delegate and calls data_delegate.Alert().
     *
     */
    Subdata data = Subdata.create();
      data.Alert("Delegates rock!");
  }
  
}

//! endzinc
 

Sevion

The DIY Ninja
Reaction score
413
Just use extends array. It's more efficient (less overhead) and requires little work.

In struct arrays, you have to have your own allocation. But it's really easy. Here's my method (ripped from Nestharus)

JASS:
struct myStruct extends array
    private static integer instanceCount = 0
    private static thistype recycle = 0
    private thistype recycleNext

    static method create takes nothing returns thistype
        local thistype this

        if (recycle == 0) then
            set instanceCount = instanceCount + 1
            set this = instanceCount
        else
            set this = recycle
            set recycle = recycle.recycleNext
        endif

        return this
    endmethod

    method destroy takes nothing returns nothing
        set recycleNext = recycle
        set recycle = this
    endmethod
endstruct


I should write a module for this... Has done.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top