2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-08-16 20:45:37 +00:00
|
|
|
* Delay trigger
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-08-16 20:45:37 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:32:11 +00:00
|
|
|
/** \file gameengine/GameLogic/SCA_DelaySensor.cpp
|
|
|
|
* \ingroup gamelogic
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-15 16:13:32 +00:00
|
|
|
#if defined(WIN32) && !defined(FREE_WINDOWS)
|
2008-08-16 20:45:37 +00:00
|
|
|
// This warning tells us about truncation of __long__ stl-generated names.
|
|
|
|
// It can occasionally cause DevStudio to have internal compiler warnings.
|
|
|
|
#pragma warning( disable : 4786 )
|
|
|
|
#endif
|
|
|
|
|
2011-01-27 00:02:25 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2008-08-16 20:45:37 +00:00
|
|
|
#include "SCA_DelaySensor.h"
|
|
|
|
#include "SCA_LogicManager.h"
|
|
|
|
#include "SCA_EventManager.h"
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
SCA_DelaySensor::SCA_DelaySensor(class SCA_EventManager* eventmgr,
|
|
|
|
SCA_IObject* gameobj,
|
|
|
|
int delay,
|
|
|
|
int duration,
|
2009-06-28 11:22:26 +00:00
|
|
|
bool repeat)
|
|
|
|
: SCA_ISensor(gameobj,eventmgr),
|
2009-02-25 03:26:02 +00:00
|
|
|
m_repeat(repeat),
|
2008-08-16 20:45:37 +00:00
|
|
|
m_delay(delay),
|
2009-02-25 03:26:02 +00:00
|
|
|
m_duration(duration)
|
2008-08-16 20:45:37 +00:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCA_DelaySensor::Init()
|
|
|
|
{
|
|
|
|
m_lastResult = false;
|
|
|
|
m_frameCount = -1;
|
|
|
|
m_reset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCA_DelaySensor::~SCA_DelaySensor()
|
|
|
|
{
|
|
|
|
/* intentionally empty */
|
|
|
|
}
|
|
|
|
|
|
|
|
CValue* SCA_DelaySensor::GetReplica()
|
|
|
|
{
|
|
|
|
CValue* replica = new SCA_DelaySensor(*this);
|
|
|
|
// this will copy properties and so on...
|
2009-06-08 20:08:19 +00:00
|
|
|
replica->ProcessReplica();
|
2008-08-16 20:45:37 +00:00
|
|
|
|
|
|
|
return replica;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SCA_DelaySensor::IsPositiveTrigger()
|
|
|
|
{
|
|
|
|
return (m_invert ? !m_lastResult : m_lastResult);
|
|
|
|
}
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
bool SCA_DelaySensor::Evaluate()
|
2008-08-16 20:45:37 +00:00
|
|
|
{
|
|
|
|
bool trigger = false;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
if (m_frameCount==-1) {
|
|
|
|
// this is needed to ensure ON trigger in case delay==0
|
|
|
|
// and avoid spurious OFF trigger when duration==0
|
|
|
|
m_lastResult = false;
|
|
|
|
m_frameCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_frameCount<m_delay) {
|
|
|
|
m_frameCount++;
|
|
|
|
result = false;
|
|
|
|
} else if (m_duration > 0) {
|
|
|
|
if (m_frameCount < m_delay+m_duration) {
|
|
|
|
m_frameCount++;
|
|
|
|
result = true;
|
|
|
|
} else {
|
|
|
|
result = false;
|
|
|
|
if (m_repeat)
|
|
|
|
m_frameCount = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = true;
|
|
|
|
if (m_repeat)
|
|
|
|
m_frameCount = -1;
|
|
|
|
}
|
|
|
|
if ((m_reset && m_level) || result != m_lastResult)
|
|
|
|
trigger = true;
|
|
|
|
m_reset = false;
|
|
|
|
m_lastResult = result;
|
|
|
|
return trigger;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2008-08-16 20:45:37 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject SCA_DelaySensor::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2008-08-16 20:45:37 +00:00
|
|
|
"SCA_DelaySensor",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2008-08-16 20:45:37 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2008-08-16 20:45:37 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
2009-06-29 12:06:46 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,
|
2009-06-28 11:22:26 +00:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
2009-06-29 12:06:46 +00:00
|
|
|
&SCA_ISensor::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2008-08-16 20:45:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef SCA_DelaySensor::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-01-02 17:43:56 +00:00
|
|
|
PyAttributeDef SCA_DelaySensor::Attributes[] = {
|
|
|
|
KX_PYATTRIBUTE_INT_RW("delay",0,100000,true,SCA_DelaySensor,m_delay),
|
|
|
|
KX_PYATTRIBUTE_INT_RW("duration",0,100000,true,SCA_DelaySensor,m_duration),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("repeat",SCA_DelaySensor,m_repeat),
|
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2008-08-16 20:45:37 +00:00
|
|
|
/* eof */
|