| 05-10-2007, 09:00 PM | #1 |
Once again, I've managed to get the impression that I've come up with something smart... I'd like you thoughts on this :) If we consider how the unit enters region event actually works; I think that the result would be something like: JASS:// C++ >> ABSTRACT Jass // :) loop // for every alive unit, u set x=GetUnitX(u) set y=GetUnitY(u) // This would be the unit actually moving; through its movement speed. call UpdateUnitPosition(u) // This would be the region check... // It would check if the units old position was outside/inside; then compare to if it is outside/inside now. call ForEveryRegionCheckIfEntered(u,x,y) endloop // Understandable? Is this a logic assumption? If yes, wouldn't that in a lot of cases, quite some performance could be saved by doing manual checks of relevant units? |
| 05-11-2007, 10:41 AM | #2 |
remember that jass natives has different performance from the events. The method may be like that, but by making a custom method like that with jass may make it slower. Or i think it will be slower than using the event directly. And UpgateUnitPosition() isnt a native, which means its a function call, and that will also be very slow... And ofc you need to use SquareRoot or Sin Cos to get the x and y speed of the unit's actually speed, which also slow it down a bit. So using the event directly is from my opinion alot faster, than simulating it like this. This is a script not C++ :P Methods can be same tho. |
| 05-11-2007, 07:27 PM | #3 |
I'm quite bad at expressing myself, ain't I? :P I meant like this: Any Unit Enters Region is ofc. a c++ built-event. Doing it in JASS will ofc. be a lot slower. However, by using jass, you can in most cases delimit the number of units being checked, thus winning performance. I think that the C++ code will have to compare every unit's position to every event-registered region. Thus, the following would reqire a check of all units in the map... Trigger: ![]() Event - A unit enters region Testus![]() Condition - (Entering Unit) Is In (MyOwnUnitGroup)![]() --- do action ---... while this idéa of a JASS-Script would give the same result, but only check the relevant units, which require less actual calculations. This way is theoretically faster. JASS:// This is an idéa for a script. A desperate try to provide my thoughts. // I too do realise that the script in its current shape don't do much. // This is a function that would be run periodically function RegionCheckLoop takes nothing returns nothing // For each unit in MyOwnUnitGroup do // where u is the EnumUnit() set i=GetUnitUserData(u) set oldX=udg_oldX[i] set oldY=udg_oldY[i] set x=GetUnitX(u) set y=GetUnitY(u) // If point(oldX;oldY) is not within the region but point(x,y) is, do "unit entered region" actions... // Checks and actions (no, I'm not writing it all out) // lots o' fun code... // Finally: set udg_oldX[i]=x set udg_oldY[i]=y endfunction This way is logically better, but since I know that JASS is a lot slower than C++, my question is: Will I gain any performance by doing checks in my alternate way, instead of the standard one? Let's assume that the map has 100 to 200 units; and that 10% of the map's units are in (MyOwnUnitGroup). ----- What's quite interesting with this is that we would no longer be forced to use quadratic regions; it would be possible to check if units passed through a linear curve, for instance. |
| 05-11-2007, 09:50 PM | #4 |
Probablly not. Its a nice idea, but the C++ its made from with be stupidly rapid compaired to one call of that check you make. As far as i know, they wouldnt use checks, and if they did, it would be sync'd in the game, so its gonna happen either way, so might aswell go along with it. |
| 05-12-2007, 12:03 AM | #5 |
but ofc u can test this urself, by making massive units and region checks and compare |
| 05-12-2007, 12:18 AM | #6 |
Based on the cell nature of regions, I believe the underlying implementation colors the map so that there is one loop through each unit then one loop through the events of the square that the unit stands on. |
| 05-12-2007, 04:04 PM | #7 | |||
Quote:
Okay. That's too bad then. It would really be nice to get away from the quadratic regions sometimes... If GetUnitY(u) > f(GetUnitX(u)), where f(x)=k*x+m ) :P Quote:
Yeah, I tried to imply that synchronization in my first post.. Quote:
Ah, yes. That makes sense. |
