1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_)
22 #define AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_
23 
24 #include <map>
25 #include <string.h>
26 #include <actions/Action.h>
27 
28 class ScorchedContext;
29 class ActionController
30 {
31 public:
32 	ActionController();
33 	virtual ~ActionController();
34 
35 	// Add an action to be simulated
36 	void addAction(Action *action);
37 	bool noReferencedActions();
38 	void clear(bool warn = false);
39 
40 	// Turn on action tracing
startActionProfiling()41 	void startActionProfiling() { actionProfiling_ = true; }
42 	void stopActionProfiling();
43 	void logActions();
44 
45 	// Set the simulation speed
46 	void setScorchedContext(ScorchedContext *context);
47 
48 	// Inherited from GameStateI
49 	void simulate(fixed frameTime, fixed time);
50 	void draw();
51 
52 protected:
53 	class ActionList
54 	{
55 	public:
ActionList(int startingSize)56 		ActionList(int startingSize) : actionCount(0), maxActions(startingSize)
57 		{
58 			actions = new Action*[maxActions];
59 		}
~ActionList()60 		~ActionList()
61 		{
62 			delete [] actions;
63 		}
64 
push_back(Action * action)65 		void push_back(Action *action)
66 		{
67 			actions[actionCount++] = action;
68 			if (actionCount == maxActions)
69 			{
70 				Action **newActions = new Action*[maxActions * 2];
71 				memcpy(newActions, actions, sizeof(Action *) * maxActions);
72 				delete [] actions;
73 				maxActions = maxActions * 2;
74 				actions = newActions;
75 			}
76 		}
clear()77 		void clear()
78 		{
79 			actionCount = 0;
80 		}
empty()81 		bool empty()
82 		{
83 			return (actionCount == 0);
84 		}
85 
86 		int actionCount;
87 		Action **actions;
88 	private:
89 		int maxActions;
90 	};
91 
92 	ScorchedContext *context_;
93 	ActionList newActions_;
94 	ActionList actions_;
95 	std::map<std::string, int> actionProfile_;
96 	int referenceCount_;
97 	bool actionProfiling_;
98 
99 	void addNewActions(fixed time);
100 
101 };
102 
103 #endif // !defined(AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_)
104