• 🏆 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!

[vJASS] 0 instances with structs

Status
Not open for further replies.
Level 26
Joined
Feb 2, 2006
Messages
1,695
I am creating a small system which stores information about units over time. However, it seems that one struct after creating multiple instances will produce 0 instances.

I have attached the code and the map.
When walking around with the hero it produces the output of the following code lines:
Code:
set timeFrame = TimeFrameImpl.create()
        // TODO sometimes it is 0?! When having like 80?!!?!!?!?
        call PrintMsg("Adding time frame " + I2S(timeFrame) + " for object: " + this.timeObject.getName() + " at delta " + I2S(timeDeltaFromStartFrame))
        if (timeFrame != 0) then
            call SaveInteger(thistype.timeFrames, this, timeDeltaFromStartFrame, timeFrame)
        endif
        call PrintMsg("Time frame is now " + I2S(this.getTimeFrame(timeDeltaFromStartFrame)) + " for object: " + this.timeObject.getName())

TimeFrameImpl.create() produces 0 instances after like 80 instances. I have tried to increase the space by adding a limit to the interface TimeFrame:

Code:
interface TimeFrame[10000]

but it did not help. Any ideas why it produces 0 instances? The debug mode doesnt work in the reforged editor for me. Maybe, it would produce more helpful information.
 

Attachments

  • Tenet3.w3x
    5.7 MB · Views: 50
  • Tenet.j
    32 KB · Views: 50
JASS:
struct TimeFrameImpl extends TimeFrame
    private static constant integer MAX_CHANGE_EVENTS = 100
    private ChangeEvent array changeEvents[100]
    private integer changeEventsSize = 0

    ....
The vjass implementation is (still) bouned to 8182 array size, and so are the structs. With the usage ofprivate ChangeEvent array changeEvents[100] array for each member, you need to devide the max array size 8192 by 100, and you end up to something like 80. JassHelper 0.A.0.0

The new patch JASS array limit is iirc like 32k, not 8k. But vjass was I think never updated, so its default allocator won't work out with the new limit.

Instead of using arrays as members, something like Vector, or a List might be used, so the allocation bound won't be shrinked.
 
Level 26
Joined
Feb 2, 2006
Messages
1,695
Ok thx, I forgot about that.
Well, I am trying to use List now. From my understanding I have to use one head element of ChangeEventImpl to use the list methods:
JASS:
struct ChangeEventImpl extends ChangeEvent

    implement ListEx

    public stub method onChange takes nothing returns nothing
    endmethod

    public stub method restore takes nothing returns nothing
    endmethod

    method onTraverse takes thistype node returns boolean
        call node.restore()

        return true
    endmethod

endstruct

struct TimeFrameImpl extends TimeFrame
    private ChangeEventImpl changeEventsHead = 0

    public stub method getChangeEventsSize takes nothing returns integer
        return this.changeEventsHead.getSize()
    endmethod

    public stub method addChangeEvent takes ChangeEvent changeEvent returns integer
        if (this.changeEventsHead == 0) then
            call this.changeEventsHead = changeEvent
            call changeEvent.makeHead(changeEvent)
        else
            call this.changeEventsHead.pushBack(changeEvent)
        endif

        return this.getChangeEventsSize() - 1
    endmethod

    public stub method flush takes nothing returns nothing
        loop
            exitwhen (this.getChangeEventsSize() == 0)
            call this.changeEventsHead.popBack().destroy()
        endloop
        call this.changeEventsHead.clear()
    endmethod

    public stub method restore takes nothing returns nothing
        call this.changeEventsHead.traverseBackwards()
    endmethod

    public static method create takes nothing returns thistype
        local thistype this = thistype.allocate()
        call PrintMsg("Constructor of time frame with instance: " + I2S(this))
        return this
    endmethod

endstruct

However, it does not find my onTraverse method.
 
Level 26
Joined
Feb 2, 2006
Messages
1,695
Found the bug. I have to add the line after the method:
JASS:
struct ChangeEventImpl extends ChangeEvent

    public stub method onChange takes nothing returns nothing
    endmethod

    public stub method restore takes nothing returns nothing
    endmethod

    public method onTraverse takes thistype node returns boolean
        call node.restore()

        return false
    endmethod

    implement ListEx

endstruct
 
Status
Not open for further replies.
Top