ZVISION: Keep a member variable ZVision pointer instead of passing it in every process()

This commit is contained in:
richiesams 2013-08-24 00:00:30 -05:00
parent 2431f60c02
commit 7095e613d5
2 changed files with 18 additions and 11 deletions

View File

@ -28,14 +28,15 @@
namespace ZVision {
NodeTimer::NodeTimer(uint32 key, uint timeInSeconds)
: _key(key), _timeLeft(timeInSeconds * 1000) {}
TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds)
: _engine(engine), _key(key), _timeLeft(timeInSeconds * 1000) {
}
bool NodeTimer::process(ZVision *engine, uint32 deltaTimeInMillis) {
bool TimerNode::process(uint32 deltaTimeInMillis) {
_timeLeft -= deltaTimeInMillis;
if (_timeLeft <= 0) {
engine->getScriptManager()->setStateValue(_key, 0);
_engine->getScriptManager()->setStateValue(_key, 0);
return true;
}

View File

@ -32,23 +32,29 @@ class ZVision;
class ActionNode {
public:
virtual ~ActionNode() {}
virtual bool process(ZVision *engine, uint32 deltaTimeInMillis) = 0;
/**
* Processes the node given the deltaTime since last frame
*
* @param deltaTimeInMillis The number of milliseconds that have passed since last frame
* @return If true, the node can be deleted after process() finishes
*/
virtual bool process(uint32 deltaTimeInMillis) = 0;
};
class NodeTimer : public ActionNode {
class TimerNode : public ActionNode {
public:
NodeTimer(uint32 key, uint timeInSeconds);
TimerNode(ZVision *engine, uint32 key, uint timeInSeconds);
/**
* Decrement the timer by the delta time. If the timer is finished, set the status
* in _globalState and let this node be deleted
*
* @param engine Pointer to the ZVision instance
* @param deltaTimeInMillis Amount of time that has passed since the last frame
* @return Node should be deleted after this (true) or kept (false)
* @param deltaTimeInMillis The number of milliseconds that have passed since last frame
* @return If true, the node can be deleted after process() finishes
*/
bool process(ZVision *engine, uint32 deltaTimeInMillis);
bool process(uint32 deltaTimeInMillis);
private:
ZVision *_engine;
uint32 _key;
uint32 _timeLeft;
};