/* Copyright (C) 2007, 2010 - Bit-Blot This file is part of Aquaria. Aquaria is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "Event.h" #include "ActionMapper.h" EventPtr::EventPtr() : e(0) { this->_evm = EVM_NONE; this->actionMapperCallback = 0; this->actionValue = 0; this->stateToCall = 0; } EventPtr::~EventPtr() { } void EventPtr::clean() { // check to see if we have a pointer + want to clean up // if so, do so! if (e && evm()==EVM_CLEANUP) { delete e; e=0; } } const EventPtr& EventPtr::operator= (const EventPtr &e) { this->e = e.e; this->_evm = e._evm; return *this; } void EventPtr::call() { if (e) e->act(); if (e && evm()==EVM_CLEANUP) { delete e; e=0; } if (actionMapperCallback) { actionMapperCallback->action(actionValue, stateToCall, -1, INPUT_NODEVICE); } } void EventPtr::set(Event *e, EventManage _evm) { this->e = e; this->_evm = _evm; } void EventPtr::setActionMapperCallback(ActionMapper *actionMapperCallback, int actionValue, int stateToCall) { this->actionMapperCallback = actionMapperCallback; this->actionValue = actionValue; this->stateToCall = stateToCall; } Timer::Timer() { timer = time = 0; running = 0; } float Timer::getPerc() { if (timer <= 0 || time <= 0) return 0; return timer/time; } void Timer::start(float t) { timer = t; time = t; running = 1; } void Timer::stop() { timer = 0; running = 0; } void Timer::startStopWatch() { timer = 0; running = 2; } bool Timer::isDone() { return running == 0; } bool Timer::isActive() { return running != 0; } void Timer::update(float dt) { switch (running) { case 1: timer -= dt; if (timer < 0) { timer = 0; running = 0; } break; case 2: timer += dt; break; } } bool Timer::updateCheck(float dt) { int wasRunning = running; update(dt); if (wasRunning && !running) return true; return false; } float Timer::getValue() { return timer; }