ActionController.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_)
00022 #define AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_
00023 
00024 #include <set>
00025 #include <list>
00026 #include <vector>
00027 #include <engine/GameStateI.h>
00028 #include <engine/Action.h>
00029 #include <engine/EventContainer.h>
00030 #include <common/RandomGenerator.h>
00031 
00032 class ScorchedContext;
00033 class ActionController : public GameStateI
00034 {
00035 public:
00036         ActionController();
00037         virtual ~ActionController();
00038 
00039         // Add an action to be simulated
00040         void addAction(Action *action);
00041         void addLastAction(Action *action);
00042         bool noReferencedActions();
00043         void resetTime();
00044         void clear(bool warn = false);
00045         void setStopImmediately(bool stop) { stopImmediately_ = stop; }
00046 
00047         // Turn on action tracing
00048         bool &getActionLogging() { return actionTracing_; }
00049         bool &getActionProfiling() { return actionProfiling_; }
00050         void logProfiledActions();
00051         void logActions();
00052 
00053         // SyncCheck
00054         void addSyncCheck(const std::string &msg);
00055         std::vector<std::string> &getSyncCheck() { return syncCheck_; }
00056 
00057         RandomGenerator &getRandom() { return random_; }
00058         EventContainer &getEvents() { return events_; }
00059         fixed getActionTime() { return time_; }
00060 
00061         // Set the simulation speed
00062         void setScorchedContext(ScorchedContext *context);
00063         void setFast(fixed speedMult);
00064         fixed getFast() { return speed_; }
00065 
00066         // Inherited from GameStateI
00067         virtual void simulate(const unsigned state, float frameTime);
00068         virtual void draw(const unsigned state);
00069 
00070 protected:
00071         class ActionList
00072         {
00073         public:
00074                 ActionList() : actionCount(0), maxActions(1000)
00075                 {
00076                         actions = new Action*[maxActions];
00077                 }
00078 
00079                 void push_back(Action *action)
00080                 {
00081                         actions[actionCount++] = action;
00082                         if (actionCount == maxActions)
00083                         {
00084                                 Action **newActions = new Action*[maxActions * 2];
00085                                 memcpy(newActions, actions, sizeof(Action *) * maxActions);
00086                                 delete [] actions;
00087                                 maxActions = maxActions * 2;
00088                                 actions = newActions;
00089                         }
00090                 }
00091                 void clear()
00092                 {
00093                         actionCount = 0;
00094                 }
00095 
00096                 int actionCount;
00097                 Action **actions;
00098         private:
00099                 int maxActions;
00100         };
00101 
00102         ScorchedContext *context_;
00103         EventContainer events_;
00104         RandomGenerator random_;
00105         std::list<Action *> newActions_, newLastActions_;
00106         std::vector<std::string> syncCheck_;
00107         ActionList actions_;
00108         std::map<std::string, int> actionProfile_;
00109         int referenceCount_;
00110         unsigned int actionNumber_;
00111         fixed speed_;
00112         fixed time_;
00113         fixed lastTraceTime_;
00114         fixed stepTime_;
00115         bool actionProfiling_;
00116         bool actionTracing_;
00117         bool actionEvents_;
00118         bool stopImmediately_;
00119 
00120         bool allEvents();
00121         void stepActions(fixed frameTime);
00122         void addNewActions();
00123         void addNewLastActions();
00124 
00125 };
00126 
00127 #endif // !defined(AFX_ACTIONCONTROLLER_H__86995B4A_478E_4CFE_BD4C_79128DE51904__INCLUDED_)

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3