1 /*
2  *  ActionQueues.h
3  *  created for Marathon: Aleph One <http://source.bungie.org/>
4 
5     Copyright (C) 1991-2002 and beyond by Woody Zenfell, III
6 	and the "Aleph One" developers.
7 
8 	This program is free software; you can redistribute it and/or modify
9 	it under the terms of the GNU General Public License as published by
10 	the Free Software Foundation; either version 3 of the License, or
11 	(at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 	GNU General Public License for more details.
17 
18 	This license is contained in the file "COPYING",
19 	which is included with this source code; it is available online at
20 	http://www.gnu.org/licenses/gpl.html
21 
22 May 9, 2002 (Loren Petrich):
23 	Changed enqueueActionFlags() so that it can make zombie players controllable by Pfhortran;
24 	did this by adding the argument "ZombiesControllable" (default: false)
25 
26 Jun 9, 2002 (tiennou):
27 	Following the above example, I modified dequeueActionFlags() & countActionFlags().
28 
29 Feb 3, 2003 (Woody Zenfell):
30         Made 'ZombiesControllable' a property of a queue-set rather than an argument to the methods.
31 
32 May 14, 2003 (Woody Zenfell):
33 	A few additional minor methods to make interface more like TickBasedCircularQueues'.
34 
35  June 14, 2003 (Woody Zenfell):
36 	Added "peekActionFlags()" method to examine action_flags without removing them
37 
38  *  Encapsulates a set of action_queues, so we can have multiple sets and explicitly choose one.
39  *
40  *  Created by woody on Wed Feb 20 2002.
41  */
42 
43 #ifndef	ACTIONQUEUES_H
44 #define	ACTIONQUEUES_H
45 
46 #include "cseries.h"
47 
48 class ActionQueues {
49 public:
50     ActionQueues(unsigned int inNumPlayers, unsigned int inQueueSize, bool inZombiesControllable);
51 
52     void		reset();
53     void		resetQueue(int inPlayerIndex);
54 
55     void		enqueueActionFlags(int inPlayerIndex, const uint32* inFlags, int inFlagsCount);
56     uint32		dequeueActionFlags(int inPlayerIndex);
57     uint32		peekActionFlags(int inPlayerIndex, size_t inElementsFromHead);
58     unsigned int	countActionFlags(int inPlayerIndex);
totalCapacity(int inPlayerIndex)59     unsigned int	totalCapacity(int inPlayerIndex) { return mQueueSize - 1; }
availableCapacity(int inPlayerIndex)60     unsigned int	availableCapacity(int inPlayerIndex) { return totalCapacity(inPlayerIndex) - countActionFlags(inPlayerIndex); }
61     bool		zombiesControllable();
62     void		setZombiesControllable(bool inZombiesControllable);
63 
64     ~ActionQueues();
65 
66 protected:
67     struct action_queue {
68 	    unsigned int read_index, write_index;
69 
70 	    uint32 *buffer;
71     };
72 
73     unsigned int	mNumPlayers;
74     unsigned int	mQueueSize;
75     action_queue*	mQueueHeaders;
76     uint32*		mFlagsBuffer;
77     bool		mZombiesControllable;
78 
79 // Hide these until they have valid implementation
80 private:
81     ActionQueues(ActionQueues&);
82     ActionQueues& operator =(ActionQueues&);
83 };
84 
85 class ModifiableActionQueues : public ActionQueues {
86 public:
ModifiableActionQueues(unsigned int inNumPlayers,unsigned int inQueueSize,bool inZombiesControllable)87 	ModifiableActionQueues(unsigned int inNumPlayers, unsigned int inQueueSize, bool inZombiesControllable) : ActionQueues(inNumPlayers, inQueueSize, inZombiesControllable) { }
88 
89 	// modifies action flags at the head of the queue
90 	void modifyActionFlags(int inPlayerIndex, uint32 inFlags, uint32 inFlagsMask);
91 };
92 
93 #endif // ACTIONQUEUES_H
94