HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trackable limit problem?

09-05-2009, 06:01 PM#1
Flame_Phoenix
Hi guys, having in mind my project died (thx Blizz ...) I am now starting something a lot smaller, just to have small fun, I call it SpaceShipFighters but I think I may need a new name xD

I am using trackables, and I want to cover an entire map with them, just like Kattana's did here:
http://www.wc3jass.com/viewtopic.php?t=1997

However my the trackables represent by peasants don't reach half of the map .... and now they simply don't get activated .... and I don't understand why ... is there a limit to the number of trackables one can have, or am I doing something wrong?

Trackable, you only need to know the create method...
Collapse JASS:
//===========================================================================
//This simple library defines a trackable. It needs a special imported model
//and units to make sense.
//===========================================================================
library Trackable 
    struct Trackable
        real tcX
        real tcY
        real tcFacing
        string tcPath
        trackable track
        player tcOwner
        
        static method create takes real x, real y, real facing, string path, player owner returns Trackable
            local Trackable this = Trackable.allocate()
            
            if GetLocalPlayer() != owner then
                set .tcPath = ""
            else 
                set .tcPath = path 
            endif
            
            set .tcX = x
            set .tcY = y
            set .tcFacing = facing
            set .tcOwner = owner
            set .track = CreateTrackable(.tcPath, .tcX, .tcY, .tcFacing)
            
            return this
        endmethod
    
        //getters
        method operator x takes nothing returns real
            return .tcX
        endmethod
        
        method operator y takes nothing returns real
            return .tcY
        endmethod
        
        method operator facing takes nothing returns real
            return .tcFacing
        endmethod
    
        method operator path takes nothing returns string
            return .tcPath
        endmethod
        
        method operator tracker takes nothing returns trackable
            return .track
        endmethod
        
        method operator owner takes nothing returns player
            return .tcOwner
        endmethod
        
        //setters
        method operator x= takes real newX returns nothing
            set .tcX = newX
        endmethod
        
        method operator y= takes real newY returns nothing
            set .tcY = newY
        endmethod
        
        method operator facing= takes real newFacing returns nothing
            set .tcFacing = newFacing
        endmethod
        
        method operator path= takes string newPath returns nothing
            set .tcPath = newPath
        endmethod
        
        method operator owner= takes player newPlayer returns nothing
            set .tcOwner = newPlayer
        endmethod
    endstruct
endlibrary

code...
Collapse JASS:
    globals 
        boolean array PlayersOnline
        constant integer MAX_PLAYERS = 4
        private constant string TRACK_PATH = "units\\human\\Peasant\\Peasant.mdl"
        private constant real TRACK_SIZE = 80.
    endglobals
//===========================================================================
    private function TrackableHit takes nothing returns nothing
        call BJDebugMsg("cliked!")
    endfunction
//===========================================================================
    private function TrackableTrack takes nothing returns nothing
        call BJDebugMsg("over!")
    endfunction
//===========================================================================
private function CreateTrackables takes nothing returns nothing
        local real maxX = GetRectMaxX(bj_mapInitialPlayableArea)
        local real maxY = GetRectMaxY(bj_mapInitialPlayableArea)
        local real minX = GetRectMinX(bj_mapInitialPlayableArea)
        local real minY = GetRectMinX(bj_mapInitialPlayableArea)
        local real currentX = minX + TRACK_SIZE
        local real currentY = minY + TRACK_SIZE
        local trigger onHit = CreateTrigger()
        local trigger onTrack = CreateTrigger()
        local integer i = 0
        local Trackable tracker
        
        call CreateUnit(Player(0), 'hfoo', minX, minY, 0)
        call CreateUnit(Player(0), 'hfoo', maxX, maxY, 0)
        
        //see who is playing
        loop
            exitwhen i == MAX_PLAYERS
            
            if GetPlayerController(Player(i)) == MAP_CONTROL_USER then
                set PlayersOnline[i] = true
                
                //create the trackables
                loop
                    exitwhen currentY > maxY - TRACK_SIZE
                    call BJDebugMsg("y= " + R2S(currentY))
                    
                    set currentX = minX + TRACK_SIZE
                    loop
                        exitwhen currentX > maxX - TRACK_SIZE

                        set tracker = Trackable.create(currentX, currentY, 0., TRACK_PATH, Player(i))
                        call TriggerRegisterTrackableTrackEvent(onTrack, tracker.track)
                        call TriggerRegisterTrackableHitEvent(onHit, tracker.track)
                        
                        set currentX = currentX + TRACK_SIZE*2
                    endloop
                    
                    set currentY = currentY + TRACK_SIZE*2
                endloop
                
                call TriggerAddAction(onTrack, function TrackableTrack)
                call TriggerAddAction(onHit, function TrackableHit)
            else
                set PlayersOnline[i] = false
            endif
            
            set i = i + 1
        endloop
        
        call BJDebugMsg("maxY = "+R2S(maxY))
    endfunction

The BJ message from currentY dies for some reason and I don't understand why ... further more the events don't work, so I am assuming that the thread dies somewhere in the middle, but I just can't find where ...

I appreciate help and here is map.

rep++ given ...
Attached Files
File type: w3xSpaceShipFight.w3x (109.2 KB)
09-05-2009, 06:44 PM#2
Hans_Maulwurf
I know that problem. You just hit the oplimit of the tread. The x loop inside the y loop inside the playerloop is too much. maybe you can put the x loop into a function, which you call with .execute?
09-05-2009, 07:28 PM#3
Flame_Phoenix
Quote:
You just hit the oplimit of the tread.
There is an oplimit for threads !? Didn't know that ... This is the code I tested:

Collapse JASS:
scope StartMap initializer Init
    globals 
        boolean array PlayersOnline
        constant integer MAX_PLAYERS = 4
        private constant string TRACK_PATH = "units\\human\\Peasant\\Peasant.mdl"
        private constant real TRACK_SIZE = 80.
    endglobals
//===========================================================================
    private function TrackableHit takes nothing returns nothing
        call BJDebugMsg("cliked!")
    endfunction
//===========================================================================
    private function TrackableTrack takes nothing returns nothing
        call BJDebugMsg("over!")
    endfunction
//===========================================================================
    private function CreateLines takes real x, real y, integer i, real maxX, trigger onTrack, trigger onHit returns nothing
        local real currentX = x
        local Trackable tracker
        
        loop
            exitwhen currentX > maxX - TRACK_SIZE

            set tracker = Trackable.create(currentX, y, 0., TRACK_PATH, Player(i))
            call TriggerRegisterTrackableTrackEvent(onTrack, tracker.track)
            call TriggerRegisterTrackableHitEvent(onHit, tracker.track)
            
            set currentX = currentX + TRACK_SIZE*2
        endloop
endfunction
//===========================================================================
    private function CreateTrackables takes nothing returns nothing
        local real maxX = GetRectMaxX(bj_mapInitialPlayableArea)
        local real maxY = GetRectMaxY(bj_mapInitialPlayableArea)
        local real minX = GetRectMinX(bj_mapInitialPlayableArea)
        local real minY = GetRectMinX(bj_mapInitialPlayableArea)
        local real currentX = minX + TRACK_SIZE
        local real currentY = minY + TRACK_SIZE
        local trigger onHit = CreateTrigger()
        local trigger onTrack = CreateTrigger()
        local integer i = 0
        local Trackable tracker
        
        call CreateUnit(Player(0), 'hfoo', minX, minY, 0)
        call CreateUnit(Player(0), 'hfoo', maxX, maxY, 0)
        
        //see who is playing
        loop
            exitwhen i == MAX_PLAYERS
            
            if GetPlayerController(Player(i)) == MAP_CONTROL_USER then
                set PlayersOnline[i] = true
                
                //create the trackables
                loop
                    exitwhen currentY > maxY - TRACK_SIZE
                    call BJDebugMsg("y= " + R2S(currentY))
                    
                    set currentX = minX + TRACK_SIZE

                    call CreateLines(currentX, currentY, i, maxX, onTrack, onHit)
                    set currentY = currentY + TRACK_SIZE*2
                endloop
                
                call TriggerAddAction(onTrack, function TrackableTrack)
                call TriggerAddAction(onHit, function TrackableHit)
            else
                set PlayersOnline[i] = false
            endif
            
            set i = i + 1
        endloop
        
        call BJDebugMsg("maxY = "+R2S(maxY))
    endfunction
//===========================================================================
    private function Init takes nothing returns nothing
        local trigger StartMapTrg = CreateTrigger(  )
        call TriggerRegisterTimerEvent(StartMapTrg, 0.01, false )
        call TriggerAddAction(StartMapTrg, function CreateTrackables )
    endfunction
endscope

It also does not work ... is it because the map is too big? 256x256 ?
09-05-2009, 08:50 PM#4
Veev
You're trying to make way too many things way too fast. Also, I am pretty sure a 256x256 map has 65536 32-by-32 unit squares, and if each trackable is 80 (?) units wide, you'd need to make approximately 10,400 trackables for ONE player and you have FOUR. So, yes, you're doing way too much at once, since that trigger is attempting to create over 40,000 trackables "at once."

You most certainly need to reduce the size of your map. Or you can figure out some way to make the trigger run slower (perhaps use a timer? Not sure what is best, here). I have no idea what the op-limit is, but you have definitely hit it.
09-06-2009, 12:23 AM#5
Bobo_The_Kodo
would be safe to create 1000 - 2500 per timer interval, or TSA's reset op limit >.< w/e

1048576 trackables? delete map -> new idea Oo
09-06-2009, 01:15 AM#6
Zandose
If I remember right, I've tried trackables before and something around a 64x64 map filled with trackables every 128.00 starts to cause lag.
09-06-2009, 10:17 AM#7
Flame_Phoenix
Ahhh .... too many things too fast ...
Having in mind I intend to make this run by levels, perhaps I should only create trackables when a new level starts ... I had no idea this would be a problem. Thx.
09-06-2009, 01:42 PM#8
Anitarf
Quote:
Originally Posted by Flame_Phoenix
Ahhh .... too many things too fast ...
Having in mind I intend to make this run by levels, perhaps I should only create trackables when a new level starts ... I had no idea this would be a problem. Thx.
Perhaps you should reuse the same trackables for all levels, then?
09-06-2009, 05:55 PM#9
Veev
I think your best plan of attack, Flame, would be to use smaller map, use a timer to create the trackables, and reuse the trackables.
09-06-2009, 06:05 PM#10
Flame_Phoenix
I don't get it. How can I change the X and Y of a trackable if I can't move it nor destroy it?
Anyway, you guys are correct. My first approach (using trackables) was, at least, incorrect. Even reusing trackables I would need an entire screen of them, plus the fact I have 4 players, so I would have to multiply that by 4. This is cause a considerable amount of lag thus limiting my options.

I decided that to create my spacehip map I will instead use arrow keys to move the ship. It is also easy and it allows me to turn the ship angle when moving it =).

Rep++ to all, thanks for help.

Btw, is there a way to know when I am hitting the oplimit ? Is there a test? Or am I doomed to brute force with BJ mesages?
09-06-2009, 06:26 PM#11
Eleandor
If it stops running, you've hit the oplimit...

Just use TSA to reset it.
09-06-2009, 07:14 PM#12
Hans_Maulwurf
You don't necessary have to abandon the trackables idea. When you want to create a 2d shooter, you dont have to create tracks across the whole map. Think a bit outside the box for a moment. Instead of moving your ship forward every interval, you could leave it alone and move everything else (enemys/powerups/enviroment) backwards. That concept itself defenetly works (I once did a mario like jump n run with flash this way). This way you only need 1 screen filled with tracks. And at least for me, this didnt drop any performance. Only problem would be, you couldnt really use wc3 terrain.
Just a small idea that came into mind.
09-07-2009, 12:52 PM#13
Flame_Phoenix
Your idea and concept may just work, I am admired. I am now sure if I can use it by some reasons:
- I still don't know how I am going to use the terrain (I don't even know if I will make an entire adventure on space without terrain, but for that I would need a little white model that could look like a star... )
- Using trackables does not allow my ship to have turn animations when I move it. Using keys I can add a curvature when you go right and left.
- Using trackables I cannot tell the difference between the right button and left button of the mouse, so the ship would lose a secondary attack.

On the other hand ...
I know I am already converted to key, but I didn't stop working on my trackable library.
Now I am using TSA to reset the oplimit, but I am having this message:Click image for larger version

Name:	Image1.jpg
Views:	35
Size:	184.4 KB
ID:	45507

The game has insane lag, so I can only assume that has to be bad ...
But what is this exactly?
Attached Images
File type: jpgImage1.jpg (184.4 KB)
09-07-2009, 02:32 PM#14
Themerion
I think you are using more than 8190 struct instances of Trackable. Remember that a struct is allocated in an array, so you have to tell JASSHelper to use multiple arrays in order to have more instances than 8190 (or if it's 8191, whatev, it's not the important point)...

Collapse JASS:
// This struct can have 16382 instances!
struct MYTYPE[16382]
endstruct

But I really think that if possible, you should go for what Anitarf said.
09-07-2009, 03:00 PM#15
Flame_Phoenix
AUch ....
Trackables are not the right solution. The reason why I am still making questions is because I simply like learning =)
Thanks for your answer though, I always wanted to know what that meant.