OSDN Git Service

[denncoCreator] integrated dennco engine changes into dennco creator.
authortkawata <tkawata@users.sourceforge.jp>
Sat, 24 Nov 2012 04:01:59 +0000 (13:01 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Sat, 24 Nov 2012 04:01:59 +0000 (13:01 +0900)
16 files changed:
Source/dccell.cpp
Source/dccell.h
Source/dccontainer.cpp
Source/dccontainer.h
Source/engine/dennco.qrc [new file with mode: 0644]
Source/engine/dn.rc [new file with mode: 0644]
Source/engine/dnicon.ico [new file with mode: 0644]
Source/engine/layer1/TKCell.cpp
Source/engine/layer1/TKCell.h
Source/engine/layer1/TKContainer.cpp
Source/engine/layer1/TKContainer.h
Source/engine/layer1/TKReceptor.cpp
Source/engine/layer1/TKReceptor.h
Source/engine/versioninfo.h
Source/utils/dccomponentutil.cpp
Source/utils/dccomponentutil.h

index a431a56..9e4cc7a 100644 (file)
@@ -30,8 +30,8 @@
 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);
index d495a59..216ee61 100644 (file)
@@ -40,7 +40,7 @@ class DCCell : public QObject, public TKCell
     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;
index d3de997..443973d 100644 (file)
@@ -207,7 +207,7 @@ TKCellCode* DCContainer::addCellCode(std::string theName, std::string theAPIType
     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)
     {
@@ -219,7 +219,7 @@ TKCell* DCContainer::cellFactory(std::string location, std::string name, std::st
     }
     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;
index 6a68d43..156b88f 100644 (file)
@@ -57,7 +57,7 @@ public:
     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);
diff --git a/Source/engine/dennco.qrc b/Source/engine/dennco.qrc
new file mode 100644 (file)
index 0000000..4d8ed66
--- /dev/null
@@ -0,0 +1,3 @@
+<RCC>
+    <qresource prefix="/"/>
+</RCC>
diff --git a/Source/engine/dn.rc b/Source/engine/dn.rc
new file mode 100644 (file)
index 0000000..bbd2a53
--- /dev/null
@@ -0,0 +1 @@
+IDI_ICON1               ICON    DISCARDABLE     "dnicon.ico"
diff --git a/Source/engine/dnicon.ico b/Source/engine/dnicon.ico
new file mode 100644 (file)
index 0000000..b13ae9d
Binary files /dev/null and b/Source/engine/dnicon.ico differ
index 7f5a31b..0b9963d 100644 (file)
@@ -26,8 +26,9 @@
 #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)
 {
 }
 
@@ -116,3 +117,24 @@ TKReceptor* TKCell::createReceptor(std::string name)
     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;
+        }
+    }
+}
index 62e8eb9..3d5e5e7 100644 (file)
@@ -34,7 +34,7 @@ typedef std::map<std::string, TKReceptor*> TKReceptorMap;
 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();
@@ -49,11 +49,14 @@ public:
 
     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);
@@ -64,7 +67,9 @@ protected:
     TKAxon                  *mAxon;
     TKReceptorMap           mReceptors;
     TKCellCodeInstance      *mCellCodeInstance;
-    bool                    mCanInterface;
+    bool                    mCanInterfaceIn;
+    bool                    mCanInterfaceOut;
+    bool                    mReceptorValueUpdated;
 
 };
 
index d4bbe89..f45621d 100644 (file)
@@ -48,27 +48,81 @@ TKContainer::~TKContainer()
 
 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();
@@ -77,9 +131,9 @@ bool TKContainer::doDestroy()
         delete it->second;
     }
     mCells.clear();
-    mInterfaceCells.clear();
+    mInpInterfaceCells.clear();
+    mOutInterfaceCells.clear();
 
-    mLock.unlock();
     return true;
 }
 
@@ -90,21 +144,21 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::
 
     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
     {
@@ -117,9 +171,20 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::
     {
         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)
         {
@@ -156,11 +221,11 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCel
 
     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)
     {
@@ -188,9 +253,20 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCel
         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
@@ -248,22 +324,29 @@ TKCell* TKContainer::getCell(std::string theFQNName)
     }
 }
 
-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;
     }
 }
 
index af46ce5..da4ee78 100644 (file)
@@ -59,12 +59,16 @@ public:
     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);
@@ -73,7 +77,7 @@ public:
     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;
@@ -85,7 +89,9 @@ public:
 protected:
     TKContainer();
     TKCellMap       mCells;
-    TKCellMap       mInterfaceCells;
+    TKCellMap       mInpInterfaceCells;
+    TKCellMap       mOutInterfaceCells;
+    TKCellMap       mNonInterfaceCells;
     TKCellCodeMap   mCellCodes;
     std::string     mContainerRootPath;
     DNStorage       *mStorage;
index 45e4a3a..76b8184 100644 (file)
 #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)
index 58ad661..5efb02c 100644 (file)
 #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
index de81b28..0e16696 100644 (file)
@@ -1,7 +1,7 @@
 #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
index 94602e5..57b9111 100644 (file)
@@ -35,9 +35,9 @@
 #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);
index 1867040..ec7cf3e 100644 (file)
@@ -32,7 +32,7 @@ class DCContainer;
 
 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);