File tree Expand file tree Collapse file tree 4 files changed +88
-17
lines changed
Expand file tree Collapse file tree 4 files changed +88
-17
lines changed Original file line number Diff line number Diff line change @@ -174,16 +174,60 @@ template <class T, U32 N> struct fixed_queue
174174 U32 _last;
175175 T _buffer[N + 1 ];
176176
177- void reset ();
178- T& front ();
179- T& pop_front ();
180- void push_front (const T& element);
181- void push_back (const T& element);
182- bool full () const ;
183- T& back ();
184- T& pop_back ();
185- bool empty () const ;
186- U32 size () const ;
177+ void reset ()
178+ {
179+ clear ();
180+ }
181+ void clear ()
182+ {
183+ _last = 0 ;
184+ _first = 0 ;
185+ }
186+ T& front ()
187+ {
188+ fixed_queue<T, N>::iterator it = begin ();
189+ return *it;
190+ }
191+ void pop_front ()
192+ {
193+ _first = (_first + 1 ) & N;
194+ }
195+ void push_front ()
196+ {
197+ _first = (_first + N) & N;
198+ }
199+ void push_front (const T& data)
200+ {
201+ push_front ();
202+ T& new_front = front ();
203+ new_front = data;
204+ }
205+ void push_back ();
206+ U32 max_size () const
207+ {
208+ return N;
209+ }
210+ bool full () const
211+ {
212+ return size () == max_size ();
213+ }
214+ T& back ()
215+ {
216+ fixed_queue<T, N>::iterator it = end () - 1 ;
217+ return *it;
218+ }
219+ void pop_back ()
220+ {
221+ _last = (_last + N) & N;
222+ }
223+ bool empty () const
224+ {
225+ return _last == _first;
226+ }
227+ U32 size () const
228+ {
229+ return _last - _first;
230+ }
187231
188232 struct iterator {
189233 U32 _it;
@@ -201,15 +245,32 @@ template <class T, U32 N> struct fixed_queue
201245
202246 iterator* operator +=(S32 value)
203247 {
204- // This operation should be equivalent to 1 << ceil(logbase2(N)), which can be used as a mask
205- // for doing a fast modulus. This should be computed compile time, but there is no constexpr here
206- // And I don't know if this fixed_queue will see use again. So here it sits
207- const S32 mask = ((1 << (31 - __cntlzw (N))) - 1 );
208248 value += _it;
209- _it = value & mask ;
249+ _it = ( value + N) & N ;
210250 return this ;
211251 }
212252
253+ iterator* operator -=(S32 value)
254+ {
255+ iterator* tmp = operator +=(-value);
256+ return tmp;
257+ }
258+
259+ iterator* operator --()
260+ {
261+ *this -= 1 ;
262+ return this ;
263+ }
264+
265+ iterator operator -(S32 value) const
266+ {
267+ iterator tmp;
268+ tmp._it = _it;
269+ tmp._owner = _owner;
270+ tmp -= value;
271+ return tmp;
272+ }
273+
213274 iterator* operator ++()
214275 {
215276 *this += 1 ;
Original file line number Diff line number Diff line change @@ -538,6 +538,15 @@ void aqua_beam::update(F32 dt)
538538 update_rings (dt);
539539}
540540
541+ void aqua_beam::emit_ring ()
542+ {
543+ if (!ring.queue .full ())
544+ {
545+ kill_ring ();
546+ }
547+ ring.queue .push_front ();
548+ }
549+
541550void aqua_beam::render ()
542551{
543552 fixed_queue<aqua_beam::ring_segment, 31 >::iterator entry = ring.queue .begin ();
Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ struct aqua_beam
189189 void kill_ring ();
190190 void render ();
191191 void render_ring (aqua_beam::ring_segment&);
192+ void emit_ring ();
192193};
193194
194195struct zNPCPrawn : zNPCSubBoss
Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ namespace
3232
3333 if (shared.delay_events == 0 )
3434 {
35- shared.triggered .push_back ();
36- shared.triggered .back ();
35+ shared.triggered .push_back (); // wrong
36+ shared.triggered .back (); // wrong
3737 shared.active ->id = 0 ;
3838 }
3939 else
You can’t perform that action at this time.
0 commit comments