Question regarding Regions and rects

GoGo-Boy

You can change this now in User CP
Reaction score
40
Hi there,
I want a confirmation about something I'm not entirely sure of.

Does working with regions like
JASS:
IsPointInRegion(REGION,x,y)
take more processing power the more rects you added to the region? I guess it does but as I dunno how it is working I wanted to ask you guys.

This is important for me, as I use rects for some physics inside my map and depending on whether or not there's a performance difference in regions with more / less rects, I add rects dynamically during the game instead of adding them all right at the start.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Meh no.
My question is whether functions that involve regions become slower when working with regions that have lots of rects added via
JASS:
call RegionAddRect(...)

So is there a performance difference between a function call like this
JASS:
call IsPointInRegion(REGION,x,y)

when using a region with 1 rect and a region with like 1000 rects. Just as an example.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I've understood, but if you add rects every 0.02 s or so you're doing it wrong, and would check coordinates instead imho.
That's why i ask it.

Else, i suppose IsUnitInRegion is just fine instead of comparing each rect coordinates with GetUnitX/Y, i would go for the IsUnitInRegion way.

I mean there is not a good alternative way anyway.


EDIT : Hmm, you could also test the enter/leave region event and link a boolean to the unit, set it to true when the unit enter the region and set it to false when the unit leave.
I'm totally sure the event consider the region changes (add/remove) rects/cells but i don't know what's happen when the unit is inside a region and you remove a rect under these feets, and when an unit wasn't in the region and you add a rect under these feets.
You should test it.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
I still doubt you understand me.
But actually I've no clue how to explain it again...
all I wanna know is:
JASS:
call RegionAddRect(REGION_WITH_100_RECTS,some_rec)
... // repeat 100 times and add a different rect to the region each time
call IsPointInRegion(REGION_WITH_100_RECTS,x,y) // does running this function require more processing power as this region contains 100 rects
                                                // or doesn't it matter and it is just as fast as the following one
call IsPointInRegion(REGION_WITH_JUST_1_RECT,x,y)


That's it. That's all I wanna know!
Depending on your answer I then might add/remove the rects (global once I pre-placed on the map) dynamically to the regions during the game or all right at the initialization.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I still doubt you understand me.
But actually I've no clue how to explain it again...
all I wanna know is:
Oh, i have understood, but i simply don't know the answer and gave you an other solution if you have performance issue using the native IsunitInRegion.

Depending on your answer I then might add/remove the rects (global once I pre-placed on the map) dynamically to the regions during the game or all right at the initialization.
Now, it's my turn, i don't understand the point of that.
I mean if you have performance issued using IsUnitRegion, by adding many rects later in game, you will just report the problem, that's definitely a bad solution.

You can make an inline-friendly function and change the code inside the function if you got performance issue, just test it yourself.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
You can make an inline-friendly function and change the code inside the function if you got performance issue, just test it yourself.

Though coding for a quite a while I don't clearly know what people mean when talking about inlining. I guess making several function calls to a function itself and call that instead? Or s.th. like that.

Now regarding the performance. I would only add rects (pre-placed globals as I said (gg_rct_...) every few minutes or so depending on the players progress.

Basically I do it like this: Player enters a specific area, I add all important rects inside that area to either a global region variable that I use for vertical doodad collisions or one for horizontal doodad collision.
As I can't check for doodads I use rects as I don't need a lot of them anyway and it's quite easy to work with em.

When I move units withing my trigger I use "IsPointInRegion(HORI_COL_REG,x,y) and IsPointInRegion(VERTI_COL_REG,x,y)" to check if that point the unit will be moved to in some steps is a point where it should be knocked back. Note that it is NOT the current unit position and neither the very next one.

So and when the players leave that certain area I do call RegionClearRect(...)
do remove/clear the rects from the global REGION variables. And that does work btw.

So if I have a lot different areas I can spare some performance IF there's any performance increase for working with Region calls when these regions contain a lot rects.

Edit: I wonder though, why you NOW tell me that you don't know it. Giving other opinions about what I'm doing is fine etc. but I just thought you totally misunderstood my question.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JassHelper Manual said:
Function inlining

Function inlining will look for function calls that can be inlined and then just convert their calls to a direct usage of the function's contents. In order not to break the normal execution of the map, this is done only in few cases. An example of inlining follows.

function MyFunction takes integer a, integer b returns integer
return myarray[a]*b
endfunction

function MyOtherFunction takes nothing returns integer
return MyFunction(3,4)
endfunction

//becomes:

function MyOtherFunction takes nothing returns integer
return myarray[3]*4
endfunction

Inlining is important because it will reduce the number of function calls and make certain parts of the map script faster, while at the same time it will allow you to write readable code.

How to make a function inlineable? The current algorithm basically follows these rules (which are subject to change to allow more functions to be considered inlineable in the future):

* The function is a one-liner
* If the function is called by call the function's contents must begin with set or call or be a return of a single function.
* If the inlined function is an assigment (set) it should not assign one of its arguments.
* Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.
* If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.

But now you've detailed more if you don't use isPointInRegion you wouldn't make a friendly-inlining-function.

That seems fine, i would go for the region way i highly doubt you will have performance issue.
Anyway you don't really have the choice.
the alternative way is to make an array of coordinates X/Y, but it would be much slower.

Edit: I wonder though, why you NOW tell me that you don't know it. Giving other opinions about what I'm doing is fine etc. but I just thought you totally misunderstood my question.
I thought it was pretty obvious, i mean i test these kind of things myself, next time i will be clearer i guess.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top