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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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