‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
throttle_shared.gsc
Go to the documentation of this file.
1 #insert scripts\shared\shared.gsh;
2 
3 #namespace Throttle;
4 
5 function private ‪_UpdateThrottleThread( throttle )
6 {
7  while ( IsDefined( throttle ) )
8  {
9  [[ throttle ]]->_UpdateThrottle();
10 
11  wait throttle.updateRate_;
12  }
13 }
14 
16 {
17  var ‪queue_;
21 
23  {
24  ‪queue_ = [];
25  ‪processed_ = 0;
26  ‪processLimit_ = 1;
28  }
29 
31  {
32  }
33 
34  function private ‪_UpdateThrottle()
35  {
36  ‪processed_ = 0;
37  currentQueue = ‪queue_;
38  ‪queue_ = [];
39 
40  foreach( item in currentQueue )
41  {
42  if ( IsDefined( item ) )
43  {
44  ‪queue_[ ‪queue_.size ] = item;
45  }
46  }
47  }
48 
49  function ‪Initialize( processLimit = 1, updateRate = ‪SERVER_FRAME )
50  {
51  ‪processLimit_ = processLimit;
52  ‪updateRate_ = updateRate;
53 
54  self thread ‪Throttle::_UpdateThrottleThread( self );
55  }
56 
57  function ‪WaitInQueue( entity )
58  {
60  {
61  // Wait in the queue
62  ‪queue_[ ‪queue_.size ] = entity;
63 
64  firstInQueue = false;
65 
66  while ( !firstInQueue )
67  {
68  if ( !IsDefined( entity ) )
69  {
70  return;
71  }
72 
73  if ( ‪processed_ < ‪processLimit_ && ‪queue_[ 0 ] === entity )
74  {
75  firstInQueue = true;
76  ‪queue_[ 0 ] = undefined;
77  }
78  else
79  {
80  wait ‪updateRate_;
81  }
82  }
83  }
84 
85  ‪processed_++;
86  }
87 }
‪Throttle::_UpdateThrottle
‪function private _UpdateThrottle()
Definition: throttle_shared.gsc:34
‪Throttle::queue_
‪var queue_
Definition: throttle_shared.gsc:17
‪Throttle::updateRate_
‪var updateRate_
Definition: throttle_shared.gsc:20
‪Throttle::Initialize
‪function Initialize(processLimit=1, updateRate=SERVER_FRAME)
Definition: throttle_shared.gsc:49
‪Throttle::processLimit_
‪var processLimit_
Definition: throttle_shared.gsc:19
‪Throttle
Definition: throttle_shared.gsc:15
‪Throttle::destructor
‪destructor()
Definition: throttle_shared.gsc:30
‪Throttle::constructor
‪constructor()
Definition: throttle_shared.gsc:22
‪Throttle::WaitInQueue
‪function WaitInQueue(entity)
Definition: throttle_shared.gsc:57
‪_UpdateThrottleThread
‪function private _UpdateThrottleThread(throttle)
Definition: throttle_shared.gsc:5
‪Throttle::processed_
‪var processed_
Definition: throttle_shared.gsc:18
‪SERVER_FRAME
‪#define SERVER_FRAME
Definition: shared.gsh:264