• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Structs and their memory usage

Status
Not open for further replies.
Level 25
Joined
Jun 5, 2008
Messages
2,572
I am just wondering how much memory does a struct allocate?

For example i got structs:

JASS:
struct aStruct

    bStruct array b[200]
    boolean array state[200]
    
    cStruct c

endstruct

struct bStruct

  //aprox 10 integer type members

endstruct

struct cStruct

destructable array instance[200]

endstruct

Now how much would allocating 1 struct aStruct, 1 struct bStruct and 1 struct cStruct take memory wise?

Would allocating too much of these structs lead to WC3 crash?

Because i will be using structs for data storing i want to know am i putting WC3 to too much pressure.
 
8190 instances are allowed for your normal struct.

The values of "this" range from 1 to 8190.
Normal array values range from 0 to 8191.

8192 values are allowed for an ordinary jass array.

This is not Java; these structs are not "classes". Though they seem magical, they are things any well-studied programmer can engineer.

Part of what makes JassHelper special is that the allocation and deallocation occurs behind the scenes. The problem is that there are limitations to contend with, which is why many people use arrays in conjunction with structs.
 
Last edited:
Level 25
Joined
Jun 5, 2008
Messages
2,572
Yes :p

EDIT:

Another question:

If i make the system only initialize stuff locally for the single player would that work in multiplayer?

For example Player(1) only will initialize the building of his inventory and the setting of data for his inventory not the rest.
Player(2) will do the same, etc...

Would that work in multiplayer?
Since every player is only initializing his part of the system locally and he doesn't need to initialize all the stuff at 1 time, does he?

Example:

I used to create N destructables at locations Xn and Yn for each player N.

Will (N*player number) desctructables be created at their suposed locations if for example 3 players were in the game?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Unless you show us code how can we possibly know if it will work in multiplayer. I honestly have no idea what you're trying to say with "initialize stuff" your description is completely vague.
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
Okay you asked for...

Also note i am rewriting the old code so a lot of stuff is not functioning atm and the code is a mess atm:

Edit2:

It also uses this lib:

JASS:
library Data


struct itemData

    integer dmg
    integer armor
    integer moveSpeed
    integer HpRegen
    integer MpRegen
    integer HpBonus
    integer MpBonus
    string Name
    integer Type
    integer AttackSpeed
    integer Cost
    integer SetNum
    integer Class
    integer ReqLevel
    integer ChargeNum
    integer ChargeId
    boolean equiped
    integer Id
    integer SetId
    integer Index
    integer iconId

endstruct

struct destData

    destructable array instance[300]

endstruct

struct uData

    itemData array slot[300]
    boolean array state[300]
    
    destData DestData

endstruct

struct mercData

    itemData array slot[200]
    boolean array state[200]
    
    destData DestData

endstruct

struct  trackyData

    real x
    real y
    integer pos

endstruct

struct primeData

    trackyData array td[400]

endstruct


endlibrary
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
I have no idea what that is. Not only is it not indented, but how exactly are you having a problem with all this code at once. Please locate the areas that you are having problems with and then maybe someone will put the effort in to help you. So far you haven't really given any useful information that would help us solve your problems, first giving me an ambiguous explanation and then posting an enormous contraption of a script.
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
JASS:
private function BuildBase takes real GetX,real GetY,integer i returns nothing
    local integer c = 0
    local integer r = 0
    local integer position = 0
    local trackable t
    local real x = GetX -(offset*cols)+offset
    local real y = (GetY - 2*offset)
    local string Type = TYPE[0]
    local primeData pd
    local trackyData temp
    call CreateDestructableZ(background,PlayerX[i],PlayerY[i],0,0,1.50,1)
    loop
        exitwhen r >= rows
        loop
            exitwhen c >= cols
            set t = CreateTrackable(model,x,y,0)
            call TriggerRegisterTrackableTrackEvent(TrackTrk,t)
            call TriggerRegisterTrackableHitEvent(ClickTrk,t)
            set pd = primeData(primeIndex[i])
            set temp = pd.td[position].create()
            call SaveInteger(StructData,GetHandleId(t),0,integer(temp))
            set temp.pos = position
            set temp.x = x
            set temp.y = y
            set x = x + offset
            set c = c+1
            set position = position + 1
        endloop
        if r < rows then
            set c = 0
            set y = y - offset
            set x = PlayerX[i] -(offset*cols) +offset
        endif
        set r=r+1
    endloop
endfunction


// ch5.3 A help function used to shorten the code and make other stuff more user friendly
function BuildHelp takes real x,real y,integer i,integer position returns nothing
    local trackable t = CreateTrackable(model,x,y,0)
    local primeData pd = primeData(primeIndex[i])
    local trackyData td = pd.td[position].create()
    call TriggerRegisterTrackableTrackEvent(TrackTrk,t)
    call TriggerRegisterTrackableHitEvent(ClickTrk,t)
    call SaveInteger(StructData,GetHandleId(t),0,integer(td))
    set td.pos = position
    set td.x = x
    set td.y = y
endfunction
    
// ch5.4 Defining Merchant Inventory, mainly it's X/Y
private function BuildMerc takes real GetX,real GetY,integer i returns nothing
    local integer c = 0
    local integer r = 0
    local integer position = (rows*cols)+reserved_space
    local trackable t
    local real x = GetX
    local real y = (GetY - mrows*offset)
    local string Type = TYPE[0]
    local primeData pd = primeData(primeIndex[i])
    local trackyData td
    loop
        exitwhen r >= mrows
        loop
            exitwhen c >= mcols
            set t = CreateTrackable(model,x,y,0)
            call TriggerRegisterTrackableTrackEvent(TrackTrk,t)
            call TriggerRegisterTrackableHitEvent(ClickTrk,t)
            set td = pd.td[position].create()
            call SaveInteger(StructData,GetHandleId(t),0,integer(td))
            set td.pos = position
            set td.x = x
            set td.y = y
            set x = x + offset
            set c = c+1
            set position = position + 1
        endloop
        if r < mrows then
            set c = 0
            set y = y - offset
            set x = PlayerX[i]+(offset*mcols)-(mcols/2*offset)
        endif
        set r=r+1
    endloop
endfunction


// ch5.5 Defining Equipment Location via offset constant, 1*offset = 1.7 X/Y displacement meaning if you add +1*(offset) to a slot
// you move it for 1 slot right
private function BuildEquip takes real GetX,real GetY,integer i returns nothing
    local integer position = (rows*cols)
    local real bx = (GetX-(offset*cols)+offset)+((cols/2)*offset)
    local real by = GetY+(6*offset)
    local real x
    local real y
    
    // exit inventory button
    set x = bx + (19*offset)
    set y = by - (12*offset)
    call BuildHelp(x,y,i,position)
    set position = position + 1
    // end of button
    
    // drop item button
    set x = bx + (17*offset)
    set y = by - (12*offset)
    call BuildHelp(x,y,i,position)
    set position = position + 1
    //end of button
    
    // trade item button
    set x = bx + (9*offset)
    set y = by - (4*offset)
    call BuildHelp(x,y,i,position)
    set position = position + 1
    // end of button
    
    // helm slot
    set x = bx
    set y = by
    call BuildHelp(x,y,i,position)
    set position = position + 1
    // end of slot
    
    // armor slot
    set y = by - (2*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // belt slot
    set y = by - (4*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // boots slot
    set y = by - (6*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // weapon slot
    set y = by - (2*offset)
    set x = bx - (3*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // offhand slot
    set x = bx + (3*offset)
    set y = by - (2*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // gloves slot
    set x = bx - (1.5*offset)
    set y = by - (2.5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // amulet slot
    set x = bx + (1.5*offset)
    set y = by + (0.5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // ring slot
    set x = bx - (3*offset)
    set y = by - (5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // ring slot
    set x = bx - (2*offset)
    set y = by - (5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // consumable slot
    set x = bx + (3*offset)
    set y = by - (5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // consumable slot
    set x = bx + (4*offset)
    set y = by - (5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // consumable slot
    set x = bx + (5*offset)
    set y = by - (5*offset)
    call BuildHelp(x,y,i,position)
    set position = position+1
    // end of slot
    
    // desirable slot that you want added goes here
    
    // end of desirable slot
endfunction





private function Build takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t2 = CreateTrigger()
    local trigger t3 = CreateTrigger()
    local trigger t4 = CreateTrigger()
    local trigger t5 = CreateTrigger()
    local integer i = 0
    local item Item = CreateItem('IXXX',0,0)
    local real x
    local real y
    local primeData pd
    set MinY = GetRectMinY(bj_mapInitialPlayableArea)
    set MinX = GetRectMinX(bj_mapInitialPlayableArea)
    set MaxY = GetRectMaxY(bj_mapInitialPlayableArea)
    set MaxX = GetRectMaxX(bj_mapInitialPlayableArea)
    set x =MinX-StartX -(offset*cols) +offset
    set item_index = reserved_space+1
    set y = MinY+StartY
    call CreateItemSimple(Item)
    call RemoveItem(Item)
    call SetCameraBounds(x,y,x, MaxY, MaxX, MaxY, MaxX,y)
    set i = 0
    loop
        exitwhen i >= bj_MAX_PLAYER_SLOTS
            if GetLocalPlayer() == Player(i) then
            set pd = primeData.create()
            set primeIndex[i] = integer(pd)
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            call TriggerRegisterPlayerEvent(t3,Player(i),EVENT_PLAYER_END_CINEMATIC)
            call TriggerRegisterPlayerUnitEvent(t4,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            call TriggerRegisterPlayerUnitEvent(t5,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            call TriggerRegisterPlayerUnitEvent(t2,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            set PlayerX[i] = x + (i*100)
            set PlayerY[i] = y
            call BuildBase(PlayerX[i],PlayerY[i],i)
            call BuildEquip(PlayerX[i],PlayerY[i],i)
            call BuildMerc(PlayerX[i]+(offset*mcols)-(mcols/2*offset),y+(offset*mrows)+(mrows/2*offset),i)
            set Multiboard[i] = null
            set vem[i] = CreateFogModifierRadius(Player(i),FOG_OF_WAR_VISIBLE,PlayerX[i],PlayerY[i],200,false,false)
            call FogModifierStop(vem[i])
            set camtimer[i] = CreateTimer()
            endif
            set i=i+1
    endloop
    call SetCameraBounds(MinX, MinY, MinX, MaxY, MaxX, MaxY, MaxX, MinY)
    call AddAbilsPreload()
    call TriggerAddAction(TrackTrk,function OnTrack)
    call TriggerAddAction(ClickTrk,function OnHit)
    call TriggerAddCondition(t,Condition(function ItemCondition))
    call TriggerAddAction(t,function ExecAction)
    call TriggerRegisterAnyUnitEventBJ(t2,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t2, function OpenThisInventory)
    call TriggerAddCondition(t2,Condition(function Condition2Open))
    call TriggerAddCondition(t3,Condition(function Condition2Close))
    call TriggerAddAction(t3,function CloseThisInventory)
    call TriggerAddCondition(t4,Condition(function Conditional))
    call TriggerAddAction(t4,function Actions)
    call TriggerAddCondition(t5,function Condition2Browse)
    call TriggerAddAction(t5,function InitBrowse)
    call DefineTypes()
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
            if GetLocalPlayer() == Player(i) then
            set pd = primeData.create()
            set primeIndex[i] = integer(pd)
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            call TriggerRegisterPlayerEvent(t3,Player(i),EVENT_PLAYER_END_CINEMATIC)
            call TriggerRegisterPlayerUnitEvent(t4,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            call TriggerRegisterPlayerUnitEvent(t5,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            call TriggerRegisterPlayerUnitEvent(t2,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            set PlayerX[i] = x + (i*100)
            set PlayerY[i] = y
            call BuildBase(PlayerX[i],PlayerY[i],i)
            call BuildEquip(PlayerX[i],PlayerY[i],i)
            call BuildMerc(PlayerX[i]+(offset*mcols)-(mcols/2*offset),y+(offset*mrows)+(mrows/2*offset),i)
            set Multiboard[i] = null
            set vem[i] = CreateFogModifierRadius(Player(i),FOG_OF_WAR_VISIBLE,PlayerX[i],PlayerY[i],200,false,false)
            call FogModifierStop(vem[i])
            set camtimer[i] = CreateTimer()
            endif

Okay, so this is the important area?

This would most definitely cause a desync in multiplayer.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Yea I see that, but it is running code locally that should not be run locally; all of your trigger events would cause serious problems and I think that CreateFogModifierRadius will also cause problems. I haven't really looked into what BuildBase and the others do, but I'm sure that there are some actions in there that would also cause a desync.

Okay in your BuildBase function you use CreateDestructableZ which would also for sure cause a desync.

I think you're going about this wrong... you shouldn't need such enormous blocks of local code.
 
Status
Not open for further replies.
Top