System PUI - Perfect Unit Indexing

Sooda

Diversity enchants
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
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
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.
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
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.
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
Not if they are in different scopes or libraries.
I name all my structs as Data (private mostly)
 

Builder Bob

Live free or don't
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
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.
 

Zwiebelchen

You can change this now in User CP.
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 ...
 

Zwiebelchen

You can change this now in User CP.
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
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:
    They aren't cutting my responsibilities or interjecting in my management abilities or anything, it's just stupid shit that comes up. And they don't exactly have people lining up for my job, there's not that many people applying for the positions I hire
  • Varine Varine:
    Eh, whatever. Thanks for listening guys
  • jonas jonas:
    Sure :) Let us know how it ends
  • Varine Varine:
    All of these things will end happily, they're just stressful. And I still lack many good friends that I can go to, and the ones I can are preoccupied with similar things. Thus general chit chat, cuz for some reason TH and Ghan and Tom all actively keep it up.
  • Varine Varine:
    Just gotta keep Miss Mazie up through the week until her shock wears off and she realizes that she still has family all around her, and bossman will do whatever he's going to do and I'll respond appropriately when it happens. Thank you all for the support, I do very much appreciate everyone being here for me through the years
    +3
  • vypur85 vypur85:
    Best of luck Varine!
  • vypur85 vypur85:
    I just gotten myself an offer to work in China. The pay quadruples my current one. Damn.... Not really ready to start a new life there in China.
  • The Helper The Helper:
    I have heard that they pay pretty good to English teachers in China - you would be an expat
  • jonas jonas:
    Cool, what kind of job?
  • Accname Accname:
    I would be careful with jobs in China. They can be hit and miss depending on where in China you go. Places like hong kong / Shengzen / Beijing can be neat. Other places not so much.
  • Accname Accname:
    I would recommend searching for some first person experiences for the city you got the offer in. Especially now when the political situation in China is deteriorating.
  • jonas jonas:
    Accname, long time no see
  • jonas jonas:
    What have you been up to
  • tom_mai78101 tom_mai78101:
    Hey Accname, welcome back.
  • Accname Accname:
    Not much. Working in the Renewable Energy Sector as an IT Consultant. Its okay, but I think I preferred working at the university. It was more relaxed and you met all kinds of crazy people there.
  • vypur85 vypur85:
    I gotten a teaching position for Biology in a college in Wuhan (yes, there)... I suppose it should be fine there (I hope). Many of my ex colleagues are teaching in China as well currently (none in Wuhan though)
  • vypur85 vypur85:
    And I signed the contract already. I guess there's no turning back....
  • jonas jonas:
    @Accname how many hours do you work? I heard in some sectors IT consultants rack up insane hours
  • jonas jonas:
    @vypur85 sounds nice, have fun : )
  • Accname Accname:
    I am supposed to work 40 hrs a week, but I can work more if I like and I will be paid for those hours (as long as I don't go too far, there are laws and company policies, etc)
  • Accname Accname:
    In practice its basically work as much as you like, as long as the job gets done in time.
  • jonas jonas:
    Haha, my job is like that as well... that usually means I have a few 70-80 hours weeks a year, and lots of 20 hours weeks...
  • jonas jonas:
    a few weeks ago, one of my friends basically said "jonas, I received an invitation to submit something to conference X but I'm too lazy to do it and also the conference isn't advanced enough for my high level of research*, why don't you write something? Oh by the way, the deadline is in two weeks. Enjoy!" so I got two 80 hour weeks out of that kind offer. (*of course he didn't say those parts, but it's a better story this way)
  • jonas jonas:
    now I'll have next week off to make up for overtime :p and I'll play some good old gothic 2
  • The Helper The Helper:
    Hope you are enjoying that gothic 2~

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome
    Top