To poll or not to poll

Post » Wed Mar 18, 2015 11:29 am

I need to know whenever the player moves from one Hold to another. I currently just listen for OnLocationChange, but that doesn't fire as often as I'd like while the player is outdoors because most exterior worldspace cells have no location assignment.

I considered the concept from the http://www.creationkit.com/Detect_Player_Cell_Change_(Without_Polling) which gives a callback on every worldspace cell transition, but that still limits my resolution to whole cells, and it's going to fire every 8-10 seconds while the player is running, and even more often if they're sprinting or riding a horse. (I estimate ~350 units per second run speed; cells are 4096 units, but if the player runs at an angle they can run to a new cell every sqrt(2*2048*2048) ~= 2896 units)

Given that event frequency, is it even worth all the infrastructure (magic effect, object reference, conditions) to do it the "resource friendly event driven" way from that tutorial? Can I just get away with polling every 5-10 seconds?

That would give me infinite resolution (so diagonal borders don't have to zigzag along cell boundaries) and, it seems to me, pretty similar resource load. No matter if the update function is triggered by polling or by the OnEffectStart event from that tutorial, it's still going to involve about 2 or 3 native calls in most cases: if GetWorldSpace() == None then GetCurrentLocation() else GetPositionX(), GetPositionY(). After that it'd usually be just one point-in-polygon test against the border of the region the player was previously in, and if that fails, then similar tests against the other regions to see where they are now. Each of those tests involves ~50 math operations, but no further framerate-delayed native calls.

Is that a reasonable amount of work to do by polling? Or is there some additional benefit to the event driven scheme, even if the events fire just as often as I'd be polling?

User avatar
Angela
 
Posts: 3492
Joined: Mon Mar 05, 2007 8:33 am

Post » Wed Mar 18, 2015 9:41 am

What's going to happen when the new event occurs? Does the player turn into a pumpkin?

I suspect there's a way to get the same effect you're trying to achieve without doing this, but you're only explaining how, not what.

Crime, for example, doesn't need this, as the hold check is made as part of any encounter that depends on it, and nothing needs to happen until that event.
User avatar
Juan Cerda
 
Posts: 3426
Joined: Thu Jul 12, 2007 8:49 pm

Post » Wed Mar 18, 2015 12:01 pm

This is for http://www.nexusmods.com/skyrim/mods/49369/? -- when the player enters a new Hold, I have to change the gold value of some items and fiddle some leveled item lists so that things have region-specific prices and merchant supplies. That process takes about 3 seconds (after threading it; used to be ~10), and only has to be done when the player actually moves from one Hold's territory to another (which is not every time OnLocationChange fires).

But that part doesn't really matter for this question, because no matter how I go about monitoring when the player enters a new Hold, they're still going to enter a new Hold however often they do, and that will trigger the regional update. That part works fine now, and I'm not making it happen more often than it already does, I just want to reduce the latency between the player crossing a border and the mod noticing that they have done so.

User avatar
Sabrina Schwarz
 
Posts: 3538
Joined: Fri Jul 14, 2006 10:02 am


Return to V - Skyrim