const float DCCell::S_MAXSIZE = 5;
const float DCCell::S_MINSIZE = 0.5;
-DCCell::DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInterface) :
- TKCell(container, location, name, canInterface), d_vComponent(NULL), d_cellCode(NULL),
+DCCell::DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInputInterface, bool canOutputInterface) :
+ TKCell(container, location, name, canInputInterface, canOutputInterface), d_vComponent(NULL), d_cellCode(NULL),
d_viewSize(0.5), d_viewHeight(0.5)
{
d_type = QString::fromStdString(type);
friend class DCComponentUtil;
friend class DCContainer;
- DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInterface);
+ DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInputInterface, bool canOutputInterface);
void bindComponent(DCVPageComponent *component);
DCVPageComponent *d_vComponent;
return cellCode;
}
-TKCell* DCContainer::cellFactory(std::string location, std::string name, std::string type, bool canInterface)
+TKCell* DCContainer::cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut)
{
if (location != d_factoryCachedLocation || d_factoryCachedPageObject.ref() == NULL)
{
}
d_factoryCachedLocation = location;
- TKCell *cell = DCComponentUtil::createCell(this, dynamic_cast<DCVCPage*>(d_factoryCachedPageObject.ref()), location, name, type, canInterface);
+ TKCell *cell = DCComponentUtil::createCell(this, dynamic_cast<DCVCPage*>(d_factoryCachedPageObject.ref()), location, name, type, canInterfaceIn, canInterfaceOut);
cell->init();
return cell;
virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
virtual TKCellCode* addCellCode(std::string theName, std::string theAPIType, std::string code);
- virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true);
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut);
virtual TKAxon* axonFactory(TKCell *theOwner);
virtual TKReceptor* receptorFactory(TKCell *theOwner);
virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
--- /dev/null
+<RCC>
+ <qresource prefix="/"/>
+</RCC>
--- /dev/null
+IDI_ICON1 ICON DISCARDABLE "dnicon.ico"
#include "TKLog.h"
#include <string>
-TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarface)
-: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mCanInterface(canIntarface)
+TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarfaceIn, bool canInterfaceOut)
+: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL),
+ mCanInterfaceIn(canIntarfaceIn), mCanInterfaceOut(canInterfaceOut), mReceptorValueUpdated(false)
{
}
return receptor;
}
+bool TKCell::enterDoTick(float time, bool forceUpdate)
+{
+ if (!forceUpdate && !mReceptorValueUpdated)
+ return false;
+
+ bool r = doTick(time);
+ mReceptorValueUpdated = false;
+
+ return r;
+}
+
+void TKCell::updateReceptorValue()
+{
+ for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it )
+ {
+ if (it->second->update())
+ {
+ mReceptorValueUpdated = true;
+ }
+ }
+}
class TKCell
{
public:
- TKCell(TKContainer *container, std::string location, std::string name, bool canInterface);
+ TKCell(TKContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
virtual ~TKCell();
void init();
bool connectTo(std::string connectionName, TKCell *targetReceptor);
inline TKContainer* getContainer() const { return mContainer; }
- bool isInterface() { return mCanInterface; }
+ bool canInterfaceIn() { return mCanInterfaceIn; }
+ bool canInterfaceOut() { return mCanInterfaceOut; }
+ bool enterDoTick(float time, bool forceUpdate);
virtual bool doTick(float time) = 0;
virtual bool doInit() = 0;
virtual bool doDestroy() = 0;
+ virtual void updateReceptorValue();
protected:
virtual TKReceptor* createReceptor(std::string name);
TKAxon *mAxon;
TKReceptorMap mReceptors;
TKCellCodeInstance *mCellCodeInstance;
- bool mCanInterface;
+ bool mCanInterfaceIn;
+ bool mCanInterfaceOut;
+ bool mReceptorValueUpdated;
};
bool TKContainer::doInit()
{
- mLock.lock();
+ DNLocker locker(&mLock);
+
for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
it->second->doInit();
}
- mLock.unlock();
return true;
}
-bool TKContainer::doTick(float time)
+bool TKContainer::doTickInputInterfaces(float time)
{
- mLock.lock();
- for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
- it->second->doTick(time);
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mInpInterfaceCells.begin(); it != mInpInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mInpInterfaceCells.begin(); it != mInpInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
+ }
+ return true;
+}
+
+bool TKContainer::doTickOutputInterfaces(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mOutInterfaceCells.begin(); it != mOutInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mOutInterfaceCells.begin(); it != mOutInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
+ }
+ return true;
+}
+
+bool TKContainer::doTickSignalScan(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,false);
+ }
+ return true;
+}
+
+bool TKContainer::doTickFullScan(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
}
- mLock.unlock();
return true;
}
bool TKContainer::doDestroy()
{
- mLock.lock();
+ DNLocker locker(&mLock);
for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
(it->second)->doDestroy();
delete it->second;
}
mCells.clear();
- mInterfaceCells.clear();
+ mInpInterfaceCells.clear();
+ mOutInterfaceCells.clear();
- mLock.unlock();
return true;
}
if (type == CELLTYPE_JSBASIC || type.length() == 0)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_IN)
{
- cell = cellFactory(theLocation, theName, type, true);
+ cell = cellFactory(theLocation, theName, type, true, false);
noScript = true;
}
else if (type == CELLTYPE_OUT)
{
- cell = cellFactory(theLocation, theName, type, true);
+ cell = cellFactory(theLocation, theName, type, false, true);
noScript = true;
}
else if (type == CELLTYPE_BASICSTORAGE)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else
{
{
std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
mCells.insert(TKCellMap::value_type(fqnName, cell));
- if (cell->isInterface())
+ bool interface = false;
+ if (cell->canInterfaceIn())
{
- mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ mInpInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (cell->canInterfaceOut())
+ {
+ mOutInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (!interface)
+ {
+ mNonInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
}
if (!noScript)
{
if (type == CELLTYPE_JSBASIC)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_BASICSTORAGE)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_OUT)
{
mCells.insert(TKCellMap::value_type(fqnName, cell));
cell->setCellCode(cellCode,(const void*)customScript.c_str());
- if (cell->isInterface())
+ bool interface = false;
+ if (cell->canInterfaceIn())
+ {
+ mInpInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (cell->canInterfaceOut())
+ {
+ mOutInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (!interface)
{
- mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ mNonInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
}
}
else
}
}
-TKCell* TKContainer::getInterfaceCell(std::string theFQNName)
+TKCell* TKContainer::getInputInterfaceCell(std::string theFQNName)
{
- DNLocker locker(&mLock);
-
- if (mInterfaceCells.empty())
+ TKCellMap::iterator iti = mInpInterfaceCells.find(theFQNName);
+ if (iti == mInpInterfaceCells.end())
{
return NULL;
}
- TKCellMap::iterator it = mInterfaceCells.find(theFQNName);
- if (it == mInterfaceCells.end())
+ else
+ {
+ return iti->second;
+ }
+}
+
+TKCell* TKContainer::getOutputInterfaceCell(std::string theFQNName)
+{
+ TKCellMap::iterator ito = mOutInterfaceCells.find(theFQNName);
+ if (ito == mInpInterfaceCells.end())
{
return NULL;
}
else
{
- return it->second;
+ return ito->second;
}
}
DNStorage* getDataStore() { return mStorage; }
bool releaseDataStore();
TKCell* getCell(std::string theFQNName);
- TKCell* getInterfaceCell(std::string theFQNName);
+ TKCell* getInputInterfaceCell(std::string theFQNName);
+ TKCell* getOutputInterfaceCell(std::string theFQNName);
TKCellCode* getCellCode(std::string theCellCodeName);
- bool doInit();
- bool doTick(float time);
- bool doDestroy();
+ virtual bool doInit();
+ virtual bool doTickInputInterfaces(float time);
+ virtual bool doTickOutputInterfaces(float time);
+ virtual bool doTickSignalScan(float time);
+ virtual bool doTickFullScan(float time);
+ virtual bool doDestroy();
virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
virtual void setValue(std::string key, float value) = 0;
inline virtual float getValue(std::string key) const = 0;
- virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true) = 0;
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut) = 0;
virtual TKAxon* axonFactory(TKCell *theOwner) = 0;
virtual TKReceptor* receptorFactory(TKCell *theOwner) = 0;
virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner) = 0;
protected:
TKContainer();
TKCellMap mCells;
- TKCellMap mInterfaceCells;
+ TKCellMap mInpInterfaceCells;
+ TKCellMap mOutInterfaceCells;
+ TKCellMap mNonInterfaceCells;
TKCellCodeMap mCellCodes;
std::string mContainerRootPath;
DNStorage *mStorage;
#include "TKAxon.h"
#include "TKLog.h"
+bool TKReceptor::update()
+{
+ if (mTerminal)
+ {
+ float newValue = mTerminal->getValue();
+ if (newValue != mValue)
+ {
+ mValue = newValue;
+ return true;
+ }
+ }
+ return false;
+}
+
float TKReceptor::getValue()
{
#ifdef DEBUG_CONNECTION
TKLog::debugPrintf("TKReceptor::getValue called: owner:%s tarminal owner:%s value:%f\n",
mOwner->getName().c_str(),
mTerminal->getOwner()->getOwner()->getName().c_str(),
- mTerminal->getValue());
+ mValue;
#endif
- if (mTerminal)
- {
- return mTerminal->getValue();
- }
- return 0.0;
+ return mValue;
}
void TKReceptor::setTarget(TKAxonTerminal *theTerminal)
#ifndef __INCLUDE_TKRECEPTOR__
#define __INCLUDE_TKRECEPTOR__
+#include "math.h"
+
class TKCell;
class TKAxonTerminal;
class TKReceptor
{
public:
- TKReceptor(TKCell *theOwner) : mOwner(theOwner), mTerminal(0) {}
+ TKReceptor(TKCell *theOwner) : mOwner(theOwner), mTerminal(0), mValue(NAN) {}
virtual ~TKReceptor() {}
void setTarget(TKAxonTerminal *theTerminal);
+ bool update();
float getValue();
protected:
TKCell *mOwner;
TKAxonTerminal *mTerminal;
+ float mValue;
};
#endif
#ifndef VERSIONINFO_H
#define VERSIONINFO_H
-#define CONTAINER_VERSION "alpha 1.1"
-#define ENGINE_VERSION "alpha 1.1"
+#define CONTAINER_VERSION "alpha 1.2"
+#define ENGINE_VERSION "alpha 1.2"
#endif // VERSIONINFO_H
#include <map>
//static
-DCCell* DCComponentUtil::createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface)
+DCCell* DCComponentUtil::createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut)
{
- DCCell *cell = new DCCell(container, location, name, type, canInterface);
+ DCCell *cell = new DCCell(container, location, name, type, canInterfaceIn, canInterfaceOut);
DCVPageComponent *vcompo = new DCVCCell(cell, page, 0.5, 0.5);
cell->bindComponent(vcompo);
page->registerCell(vcompo);
struct DCComponentUtil
{
- static DCCell* createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface);
+ static DCCell* createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut);
static DCCellCode* createCellCode(DCContainer *container, DCVCPage *page, std::string theName, std::string theCellAPIName);
static DCAxon* createAxon(DCCell *theOwner);
static DCAxonTerminal* createAxonTerminal(DCAxon *theOwner);