Difference between revisions of "User:DavidJCobb/Stack dumping"

101 bytes removed ,  03:35, 2 March 2015
code snippet for BF
imported>DavidJCobb
m (→‎Events that can trigger large numbers of suspended stacks: OnHit's concurrency has been experimentally verified. Item events' consecutive...ness... has not.)
imported>DavidJCobb
(code snippet for BF)
Line 35: Line 35:
** For OnItemAdded and OnItemRemoved, I list some additional methods for avoiding stack dumping [[Talk:OnItemAdded - ObjectReference#Facts about OnItemAdded|here]].
** For OnItemAdded and OnItemRemoved, I list some additional methods for avoiding stack dumping [[Talk:OnItemAdded - ObjectReference#Facts about OnItemAdded|here]].
** OnItemAdded and OnItemRemoved don't appear to be able to run concurrently with themselves, so their stacks will be suspended as a matter of course.
** OnItemAdded and OnItemRemoved don't appear to be able to run concurrently with themselves, so their stacks will be suspended as a matter of course.
== Things to investigate ==
=== How do update events work? ===
*'''Possibility 1:''' when you call RegisterForSingleUpdate(''x''), Skyrim queues an update event to fire in ''x'' seconds. No new stacks are created.
*'''Possibility 2:''' when you call RegisterForSingleUpdate(''x''), Skyrim immediately creates a call stack for OnUpdate, and suspends it for ''x'' seconds.
**If this one is the case, then you would not be able to use update events to minimize generated stacks. Like, I seriously doubt it, but AFAIK this sort of thing is documented ''so little.''
*'''Test procedure:''' RegisterForSingleUpdate(20.0), and then DumpPapyrusStacks using the debug console. See if an OnUpdate stack is dumped.


== Miscellaneous facts ==
== Miscellaneous facts ==
* RegisterForSingleUpdate(''n'') does ''not'' create a stack and suspend it for ''n'' seconds. I have confirmed this experimentally.
* RegisterForSingleUpdate(''n'') does ''not'' create a stack and suspend it for ''n'' seconds. I have confirmed this experimentally.
== Code snippets ==
=== Process a task OnHit, and don't re-process for X seconds ===
<source lang="Papyrus">
Bool Property pbBusy = False Auto Hidden
Bool Property pbProcessed = False Auto Hidden
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked)
  If pbBusy || pbProcessed
      Return
  EndIf
  pbBusy = True
  ;
  ; Do your processing here.
  ;
  pbProcessed = True
  RegisterForSingleUpdate(x)
  pbBusy = False
EndEvent
Event OnUpdate()
  pbProcessed = False
EndEvent
</source>
Anonymous user