Help with larger amounts of Trackables

Rllulium

New Member
Reaction score
10
In an attempt to teach myself how to utilize trackables, I tried to fill a small area with trackables earlier. I thought I would then make a simple click to move test to see if it worked as I wanted. The problem that I have run into however, is that the game freezes when I try to to create more than roughly 60-100 trackables in one go. For reference, here is the code I am using; I was hoping that someone can point out something that I am doing wrong here:
JASS:
library TrackTest uses Trackable2 

globals
    private constant string  modelPath = "Doodads\\Terrain\\InvisiblePlatformSmall\\InvisiblePlatformSmall.mdl"
    private constant real    size      = 73.59
    private Trackable2 temp
endglobals

struct data
    //Set in Create function
    rect    zone
    real    minX
    real    maxX
    real    minY
    real    maxY
    //Used in methods
    boolean done     = false
    integer rowCount = 0
    real    x
    real    y
    
    method AddRow takes nothing returns nothing
        local integer i = 0
        set .y = .minY + size/2 + .rowCount*size
        loop
            set .x = .minX + size/2 + i*size
            set temp = Trackable2.create(modelPath, .x, .y, 0, 0)
            call temp.registerAnyClick(Click)
            call temp.registerAnyTrack(Track)
            set i = i + 1
        exitwhen i*size >= .maxX - .minX
        endloop
        set .rowCount = .rowCount + 1
        set .done = .rowCount*size >= .maxY - .minY
    endmethod
    
    method FillRect takes nothing returns nothing
        loop
            call .AddRow()
            call BJDebugMsg("Row Complete")
        exitwhen .done
        endloop
    endmethod
    
endstruct

public function Create takes rect area returns nothing
    local data new = data.create()
    set new.zone  = area
    set new.minX  = GetRectMinX(area)
    set new.maxX  = GetRectMaxX(area)
    set new.minY  = GetRectMinY(area)
    set new.maxY  = GetRectMaxY(area)
    call new.FillRect()
    call new.destroy()
endfunction

endlibrary
 

the Immortal

I know, I know...
Reaction score
51
Just a wild guess, but maybe hitting the OP limit? Try changing [ljass].AddRow()[/ljass] to [ljass].AddRow.execute()[/ljass] and see if there's a change.

If there IS a change but it still stops, then try splitting your functions to more parts, each using .execute()

If there ain't.. well.. I don't know, gonna eat! o_O
 

Azlier

Old World Ghost
Reaction score
461
Needs restructuring, although the current problems probably aren't causing the freeze.

Here's a rough layout.
JASS:
function CreateB takes nothing returns nothing
    //Loop through all x coordinates, creating all trackables with the given y
endfunction

function CreateA takes nothing returns nothing
    //Loop through all y coordinates, resetting the x global to the rect's minimum x and executing CreateB with the current y stored in a global in each iteration
endfunction

function Create takes rect r, other stuff returns nothing
    //Store the rect's data in globals, execute CreateA
endfunction
 

Rllulium

New Member
Reaction score
10
New Code:
JASS:
library TrackTest uses Trackable2 

globals
    private constant string  modelPath = "Doodads\\Terrain\\InvisiblePlatformSmall\\InvisiblePlatformSmall.mdl"
    private constant real    size      = 73.59
    private Trackable2 temp
endglobals

struct data
    //Set in Create function
    rect    zone
    real    minX
    real    maxX
    real    minY
    real    maxY
    //Used in methods
    integer rowCount = 0
    real    x
    real    y
    
    method FillRow takes nothing returns nothing
        set .x = .minX + size/2
        loop
            set .x = .x + size
            set temp = Trackable2.create(modelPath, .x, .y, 0, 0)
            call temp.registerAnyClick(Click)
            call temp.registerAnyTrack(Track)
        exitwhen .x >= .maxX
        endloop
    endmethod
    
    method FillRect takes nothing returns nothing
        set .y = .minY + size/2
        loop
            set .y = .y + size
            call FillRow()
        exitwhen .y >= .maxY
        endloop
    endmethod

endstruct

public function Create takes rect area returns nothing
    local data new = data.create()
    set new.zone  = area
    set new.minX  = GetRectMinX(area)
    set new.maxX  = GetRectMaxX(area)
    set new.minY  = GetRectMinY(area)
    set new.maxY  = GetRectMaxY(area)
    call new.FillRect()
    call new.destroy()
endfunction

endlibrary

I let the game remain frozen for a while, until I finally got an error message complaining about lack of storage. It seems that I need a way to let the game create one small rect at a time, waiting for the last one to finish before beginning to fill another. Which I actually should be able to make since I don't need to fill new rects on the fly ingame. Yet. I think.
 

Azlier

Old World Ghost
Reaction score
461
You forgot to, in the FillRect function, to reset x to it's minimum position with every iteration.
 

Azlier

Old World Ghost
Reaction score
461
I see. What rect are you trying to fill?

Also, you might want to throw in some .execute.
 

Rllulium

New Member
Reaction score
10
I see. What rect are you trying to fill?
Only small rects at a time right now, more than 500*500 crashes.
Also, you might want to throw in some .execute.
This did actually not make that much of difference. What however did make a very large difference was switching to normal Trackables instead of Trackable2s.

Something tells me that the the CreateTrackableZ-stuff should be optional. Creating and destroying an extra destructable with every trackable is probably a strain.
 

Azlier

Old World Ghost
Reaction score
461
The real bulk of operations coming from trackable2 has to do with how they are created. It's O(n) complexity. Normal trackables with some simple attachment are probably best.
 

Anachron

New Member
Reaction score
53
JASS:
    method FillRow takes nothing returns nothing
        set .x = .minX + size/2
        loop
            set .x = .x + size
            set temp = Trackable2.create(modelPath, .x, .y, 0, 0)
            call temp.registerAnyClick(Click)
            call temp.registerAnyTrack(Track)
        exitwhen .x >= .maxX
        endloop
    endmethod
    
    method FillRect takes nothing returns nothing
        set .y = .minY + size/2
        loop
            set .y = .y + size
            call FillRow()
        exitwhen .y >= .maxY
        endloop
    endmethod

You serious?

You should create one trackable which is 64*64 size big every 64px. Thats enough.
Something like this

JASS:
    globals
        private constant real       TILE_DIST = 64
    endglobals

    function createTracks takes rect r returns nothing
        local real xMin = GetRectMinX(r)
        local real yMin = GetRectMinY(r)
        local real xMax = GetRectMaxX(r)
        local real yMax = GetRectMaxY(r)
        local real x    = xMin
        local real y    = yMin
        local integer xTimes = R2I((xMax - xMin) / TILE_DIST)
        local integer yTimes = R2I((yMax - yMin) / TILE_DIST)
        local integer xCur = 0
        local integer yCur = 0
        
        loop
            exitwhen xCur >= xTimes
            
            set yCur = 0 
            set y = yMin
            loop
                exitwhen yCur >= yTimes
                
                set y = y + TILE_DIST
                // Create Trackable here on X and Y
                
                set yCur = yCur + 1
            endloop
            
            set x = x + TILE_DIST 
            set xCur = xCur + 1
        endloop
    endfunction
 

Rllulium

New Member
Reaction score
10
You serious?

You should create one trackable which is 64*64 size big every 64px. Thats enough.
Something like this

Now, I fail to see what you are trying to say here. I currently create one trackable of 74*74 every 74 units. What you are suggesting would require MORE trackables.
 

Anachron

New Member
Reaction score
53
Sorry, I missread it, its not 14, but 74. Sorry.

And did you try with my function? maybe you have an endless loop.
 

Rllulium

New Member
Reaction score
10
Sorry, I missread it, its not 14, but 74. Sorry.

And did you try with my function? maybe you have an endless loop.

Endless, nono. Covering a small area works like a charm. The problem is that I hit the operations limit very fast when I attempt to fill large rects.
 

Azlier

Old World Ghost
Reaction score
461
JASS:
library TrackTest uses Trackable2 

globals
    private constant string  modelPath = "Doodads\\Terrain\\InvisiblePlatformSmall\\InvisiblePlatformSmall.mdl"
    private constant real    size      = 73.59
    private Trackable2 temp
endglobals

struct data
    //Set in Create function
    rect    zone
    real    minX
    real    maxX
    real    minY
    real    maxY
    //Used in methods
    integer rowCount = 0
    real    x
    real    y
    
    method FillRow takes nothing returns nothing
        set .x = .minX + size/2
        loop
            set .x = .x + size
            set temp = Trackable2.create.execute(modelPath, .x, .y, 0, 0)
            call temp.registerAnyClick(Click)
            call temp.registerAnyTrack(Track)
        exitwhen .x >= .maxX
        endloop
    endmethod
    
    method FillRect takes nothing returns nothing
        set .y = .minY + size/2
        loop
            set .y = .y + size
            call FillRow.execute()
        exitwhen .y >= .maxY
        endloop
    endmethod

endstruct

public function Create takes rect area returns nothing
    local data new = data.create()
    set new.zone  = area
    set new.minX  = GetRectMinX(area)
    set new.maxX  = GetRectMaxX(area)
    set new.minY  = GetRectMinY(area)
    set new.maxY  = GetRectMaxY(area)
    call new.FillRect.execute()
    call new.destroy()
endfunction

endlibrary
 

Azlier

Old World Ghost
Reaction score
461
Yes, but why would you ever use something existing when you can reinvent the wheel repeatedly?
 

Rllulium

New Member
Reaction score
10
Here's something no one's mentioning.

Well, the whole point of this was for me to learn how to use trackables properly (as mentioned in the first post). One might argue that learning how to use a good system works just as well, but that's not really what I was searching for here.

For now, it seems that the usage of normal trackables with attachments is doing the job, so we may close this thread.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top