System PUI - Perfect Unit Indexing

Sooda

Diversity enchants
Reaction score
318
5.1 seems good, so good that I have twice tried to use it and failed, someone has manged to make simple spells using PUI 5.1, because:
JASS:
scope StructExample initializer Init

//===========================================================================
//  If we want struct to be attachable to units we run PUI macro inside it.
//  Putting 5-6 unit properties inside struct is more efficient 
//  than declaring 5 PUI_PROPERTY each for itself
//===========================================================================
private struct UnitData
    //! runtextmacro PUI()
    integer KillCounter = 0
    
    // you can add any of your own stuff here
endstruct

//===========================================================================
private function Actions takes nothing returns nothing
    local unit killer = GetKillingUnit()
    local UnitData dat = UnitData[killer]
    
    // is struct attached?
    if dat == 0 then
        set dat = UnitData.create() // if not create it
        set UnitData[killer] = dat // and attach it
    endif

    // again it is simple
    set dat.KillCounter = dat.KillCounter + 1
    
    // do some other stuff with your struct...
endfunction

//===========================================================================
//  WARNING: never destroy PUI structs directly use release() method instead
//  In fact it is best that you never destroy them manually,
//  they will be destroyed automatically when unit is removed from game.
//===========================================================================

//===========================================================================
private function Conditions takes nothing returns boolean
    return true
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

part looks out of space to me :p

Especially line:
JASS:
        set UnitData[killer] = dat // and attach it

Operator? vJASS feature, interesting, very high tech. I tried to add static method 'create' which took arguments and also there were 'onDestroy' method. With new PUI 5.1 hacks implemented
JASS:
//! runtextmacro PUI()

my map simply didn't loaded, after hitting 'start map' button in game (Because with JNGP and latest Blizzard patch there are small complications which drive me mad).
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
    //-----------------------------------------------------------------------
    //  If you do not call release struct will be destroyed when unit handle gets recycled
    //-----------------------------------------------------------------------
    method release takes nothing returns nothing
        local integer pui= .pui_id[integer(this)]
        call .destroy()
        set .pui_unit[pui] = null
        set .pui_data[pui] = 0
    endmethod


I thought there was the possibility of an static onDestroy method here, which would replace this and enable .destroy() instead - or didn't I understand something there?
Jasshelpermanual said:
The onDestroy method

There is no actual syntax for destructors, but there is a rule and it is that if the struct has a method called onDestroy, it is always automatically called when .destroy() is issued on an instance.

It is useful to have onDestroy when an instance of the type may hold things that have to be correctly cleaned, it saves time and even makes things safer.

struct sta
real a
real b
endstruct

struct stb
sta H=0
sta K=0

method onDestroy takes nothing returns nothing
if (H!=0) then
call sta.destroy(H)
endif
if (K!=0) then
call sta.destroy(K)
endif
endmethod
endstruct

In the above example, it is only needed to destroy the object of type stb and it would automatically destroy the attached objects of type sta if present.
 

Cohadar

master of fugue
Reaction score
209
I tried to add static method 'create' which took arguments and also there were 'onDestroy' method. With new PUI 5.1 hacks implemented
JASS:
//! runtextmacro PUI()

my map simply didn't loaded, after hitting 'start map' button in game (Because with JNGP and latest Blizzard patch there are small complications which drive me mad).

I am not sure what you are asking me to do here?
I can't fix blizzards problems.
create with arguments will work.
onDestroy will work, but you must not call .destroy directly, use .release instead. (or even better don't use anything, let PUI do it.)

If map does not load I have no idea why is that, I use older wc3 patch.
 

cleeezzz

The Undead Ranger.
Reaction score
268
i just used your system this morning and in your example struct code, you did local Data (something) = Data[Unit], then checked if Data = 0 (to check if struct is already created).

my question is, can you attach multiple structs onto a unit?

(if i had two different codes that followed your example struct, and first one runs, detects d = 0 and creates a struct and sets it as Data, then the 2nd trigger runs and detects that struct is already created (but lets say struct in trigger 2 was different) then wouldn't it screw up?)
 

Builder Bob

Live free or don't
Reaction score
249
let's say you have two structs named Data and Info.

Data[Unit] != Info[Unit]

GetUnitIndex(Unit) will return the same index in both cases. The difference between them is that they store and retrieve struct instances from separate arrays.

So you can say that all units can have one instance of each struct type attached to them.
 

cleeezzz

The Undead Ranger.
Reaction score
268
oh i just name the structs different?

Data
and
Info

?
but if i name them both Data, then it will mess up?
 

Cohadar

master of fugue
Reaction score
209
Not if they are in different scopes or libraries.
I name all my structs as Data (private mostly)
 

cleeezzz

The Undead Ranger.
Reaction score
268
sorry im a bit confused on which question you were answering lol, first or second?
 

Builder Bob

Live free or don't
Reaction score
249
sorry im a bit confused on which question you were answering lol, first or second?

oh i just name the structs different?

short answer: yes

long answer: you can reuse the same name as long as you make the structs private/public in different scopes/libraries. Private/public really just changes their names, so they won't be the same.

but if i name them both Data, then it will mess up?


no

The structs must be private/public of course.
 

Builder Bob

Live free or don't
Reaction score
249
I don't fully understand how the PUI recycler work, so I have to ask. Would the same principle that you use for PUI be equally suitable for items? I need something like a Perfect Item Indexing system.

I have another system in place to handle item indexes, but I just like the simplicity of PUI, so I thought I might as well ask.
 

Cohadar

master of fugue
Reaction score
209
Yes the same principle would work for items.
You just need to replace names.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
What if I want to remove a unit index? Is it enough to set the UnitUserData of the unit to 0? Maybe you should write a RemoveUnitInde function ...
 

Cohadar

master of fugue
Reaction score
209
It is enough to set it to zero.
Why would you want to remove index manually anyways?
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
It is enough to set it to zero.
Why would you want to remove index manually anyways?

Hm, basicly I use the GetUnitIndex() on any unit that comes in range of 2000 of one of 8 player controlled heroes (required for the aggro system i use).
I know that when a unit dies, the index gets recycled ... however; I have a trigger that removes the unit from the aggro system when the unit leaves a certain distance to all player heroes (to "clean" the system up and avoid having too much units on the aggro system). This trigger would be perfect to also remove the unit index, since the index is only used for the aggro system at my map.

I didn't check the code of PUI completely (because I trust you coding skills :D). Is it a problem if there are hundrets of units indexed? I mean; are there loopcalls, handle creations, etc. that will increase the memory usage or processing power usage? My RPG has an enormous size (480x480) and thus also has a lot of creeps. I just don't want to use up all the 8190 handle slots so fast with loads of units indexed.
 

Azlier

Old World Ghost
Reaction score
461
Well, I think you'll need over 8000 living units on the map for that to happen.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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