Browse Source

- The "onAdd()" and "onRemove()" callbacks are now processed by SimObject meaning each derived-type doesn't have to do so.
- Changed the NSLinkMask to a useful default.

MelvMay-GG 12 years ago
parent
commit
6de480a615

+ 0 - 14
engine/source/2d/scene/Scene.cc

@@ -263,8 +263,6 @@ Scene::Scene() :
     // Assign scene index.    
     mSceneIndex = ++sSceneMasterIndex;
     sSceneCount++;
-
-    mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 //-----------------------------------------------------------------------------
@@ -286,9 +284,6 @@ bool Scene::onAdd()
     if(!Parent::onAdd())
         return false;
 
-    // Synchronize Namespace's
-    linkNamespaces();
-
     // Create physics world.
     mpWorld = new b2World( mWorldGravity );
 
@@ -313,9 +308,6 @@ bool Scene::onAdd()
     // Set loading scene.
     Scene::LoadingScene = this;
 
-    // Tell the scripts
-    Con::executef(this, 1, "onAdd");
-
     // Turn-on tick processing.
     setProcessTicks( true );
 
@@ -330,9 +322,6 @@ void Scene::onRemove()
     // Turn-off tick processing.
     setProcessTicks( false );
 
-    // tell the scripts
-    Con::executef(this, 1, "onRemove");
-
     // Clear Scene.
     clearScene();
 
@@ -355,9 +344,6 @@ void Scene::onRemove()
     // Call Parent. Clear scene handles all the object removal, so we can skip
     // that part and just do the sim-object stuff.
     SimObject::onRemove();
-
-    // Restore NameSpace's
-    unlinkNamespaces();
 }
 
 //-----------------------------------------------------------------------------

+ 0 - 6
engine/source/2d/sceneobject/SceneObject.cc

@@ -373,9 +373,6 @@ bool SceneObject::onAdd()
 
         mpTargetScene = NULL;
     }
-
-    // Perform the callback.
-    Con::executef(this, 1, "onAdd");
    
     // Return Okay.
     return true;
@@ -385,9 +382,6 @@ bool SceneObject::onAdd()
 
 void SceneObject::onRemove()
 {
-    // Perform the callback.
-    Con::executef(this, 1, "onRemove");
-
     // Detach Any GUI Control.
     detachGui();
 

+ 0 - 2
engine/source/collection/undo.cc

@@ -35,8 +35,6 @@ UndoAction::UndoAction( const UTF8* actionName)
 {
    mActionName = StringTable->insert(actionName);
    mUndoManager = NULL;
-
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 // Modified to clean up quiet sub actions [KNM | 08/10/11 | ITGB-152]

+ 0 - 10
engine/source/collection/undo.h

@@ -147,7 +147,6 @@ public:
 
    UndoScriptAction() : UndoAction()
    {
-      mNSLinkMask = LinkSuperClassName | LinkClassName;
    };
 
    virtual void undo() { Con::executef(this, 1, "undo"); };
@@ -159,11 +158,6 @@ public:
       if(!Parent::onAdd())
          return false;
 
-
-      // Notify Script.
-      if(isMethod("onAdd"))
-         Con::executef(this, 1, "onAdd");
-
       // Return Success.
       return true;
    };
@@ -173,10 +167,6 @@ public:
       if (mUndoManager)
          mUndoManager->removeAction((UndoAction*)this);
 
-      // notify script
-      if(isMethod("onRemove"))
-         Con::executef(this, 1, "onRemove");
-
       Parent::onRemove();
    }
 

+ 0 - 2
engine/source/component/simComponent.cpp

@@ -33,8 +33,6 @@ SimComponent::SimComponent() : mOwner( NULL )
    mMutex = Mutex::createMutex();
    
    mEnabled = true;
-
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 SimComponent::~SimComponent()

+ 0 - 20
engine/source/graphics/PNGImage.cpp

@@ -31,26 +31,6 @@ IMPLEMENT_CONOBJECT(PNGImage);
 
 #define PNGSIGSIZE 8
 
-bool PNGImage::onAdd()
-{
-   if (!Parent::onAdd())
-      return false;
-
-   // Call onAdd in script!
-   Con::executef(this, 2, "onAdd", Con::getIntArg(getId()));
-   return true;
-}
-
-void PNGImage::onRemove()
-{
-   // We call this on this objects namespace so we unlink them after. - jdd
-   //
-   // Call onRemove in script!
-   Con::executef(this, 2, "onRemove", Con::getIntArg(getId()));
-
-   Parent::onRemove();
-}
-
 PNGImage::PNGImage() : mPNGImageType(PNGTYPE_UNKNOWN)
 {
     mWidth = 0;

+ 0 - 6
engine/source/graphics/PNGImage.h

@@ -58,12 +58,6 @@ public:
     PNGImage();
     ~PNGImage();
 
-    /// Called when the object is instantiated and registered 
-    bool onAdd();
-
-    /// Called when the object is destroyed and removed from script memory
-    void onRemove();
-
     DECLARE_CONOBJECT(PNGImage);
 
     /// Construct the png information from the .png file path provided.

+ 0 - 10
engine/source/gui/guiControl.cc

@@ -80,8 +80,6 @@ GuiControl::GuiControl()
    mTipHoverTime        = 1000;
    mTooltipWidth		= 250;
    mIsContainer         = false;
-
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 GuiControl::~GuiControl()
@@ -109,10 +107,6 @@ bool GuiControl::onAdd()
    // Add to root group.
    Sim::getGuiGroup()->addObject(this);
 
-   // Notify Script.
-   if( isMethod("onAdd") )
-      Con::executef(this, 1, "onAdd");
-
    // Return Success.
    return true;
 }
@@ -1125,10 +1119,6 @@ ConsoleMethod( GuiControl, getMinExtent, const char*, 2, 2, "() Get the minimum
 
 void GuiControl::onRemove()
 {
-   // Only invoke script callbacks if they can be received
-   if( isMethod("onRemove") )
-      Con::executef(this, 1, "onRemove");
-
    clearFirstResponder();
 
    Parent::onRemove();

+ 0 - 21
engine/source/messaging/message.cc

@@ -53,32 +53,11 @@ extern SimIdDictionary *gIdDictionary;
 Message::Message()
 {
    mRefCount = 0;
-
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 
 IMPLEMENT_CONOBJECT(Message);
 
-//////////////////////////////////////////////////////////////////////////
-
-bool Message::onAdd()
-{
-   if(! Parent::onAdd())
-      return false;
-
-   linkNamespaces();
-   Con::executef(this, 1, "onAdd");
-   return true;
-}
-
-void Message::onRemove()
-{
-   Con::executef(this, 1, "onRemove");
-   unlinkNamespaces();
-   
-   Parent::onRemove();
-}
 
 //////////////////////////////////////////////////////////////////////////
 // Public Methods

+ 0 - 2
engine/source/messaging/message.h

@@ -119,8 +119,6 @@ public:
    //////////////////////////////////////////////////////////////////////////
    static SimObjectId getNextMessageID();
 
-   virtual bool onAdd();
-   virtual void onRemove();
 
    //////////////////////////////////////////////////////////////////////////
    /// @brief Get the type of the message

+ 0 - 21
engine/source/messaging/scriptMsgListener.cc

@@ -43,31 +43,10 @@
 
 ScriptMsgListener::ScriptMsgListener()
 {
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 IMPLEMENT_CONOBJECT(ScriptMsgListener);
 
-//////////////////////////////////////////////////////////////////////////
-
-bool ScriptMsgListener::onAdd()
-{
-   if(! Parent::onAdd())
-      return false;
-
-   linkNamespaces();
-   Con::executef(this, 1, "onAdd");
-   return true;
-}
-
-void ScriptMsgListener::onRemove()
-{
-   Con::executef(this, 1, "onRemove");
-   unlinkNamespaces();
-   
-   Parent::onRemove();
-}
-
 //////////////////////////////////////////////////////////////////////////
 // Public Methods
 //////////////////////////////////////////////////////////////////////////

+ 0 - 5
engine/source/messaging/scriptMsgListener.h

@@ -52,11 +52,6 @@ public:
 
    ///////////////////////////////////////////////////////////////////////
 
-   virtual bool onAdd();
-   virtual void onRemove();
-
-   ///////////////////////////////////////////////////////////////////////
-
    virtual bool onMessageReceived(StringTableEntry queue, const char* event, const char* data);
    virtual bool onMessageObjectReceived(StringTableEntry queue, Message *msg);
 

+ 0 - 5
engine/source/platform/menus/popupMenu.cc

@@ -37,8 +37,6 @@ PopupMenu::PopupMenu()
    mSubmenus->registerObject();
 
    mIsPopup = false;
-
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 PopupMenu::~PopupMenu()
@@ -80,14 +78,11 @@ bool PopupMenu::onAdd()
 
    createPlatformMenu();
 
-   Con::executef(this, 1, "onAdd");
    return true;
 }
 
 void PopupMenu::onRemove()
 {
-   Con::executef(this, 1, "onRemove");
-
    Parent::onRemove();
 }
 

+ 0 - 21
engine/source/sim/scriptGroup.cc

@@ -34,28 +34,7 @@ IMPLEMENT_CONOBJECT(ScriptGroup);
 
 ScriptGroup::ScriptGroup()
 {
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
 //-----------------------------------------------------------------------------
 
-bool ScriptGroup::onAdd()
-{
-   if (!Parent::onAdd())
-      return false;
-
-   // Call onAdd in script!
-   Con::executef(this, 2, "onAdd", Con::getIntArg(getId()));
-   return true;
-}
-
-//-----------------------------------------------------------------------------
-
-void ScriptGroup::onRemove()
-{
-   // Call onRemove in script!
-   Con::executef(this, 2, "onRemove", Con::getIntArg(getId()));
-
-   // Call parent.
-   Parent::onRemove();
-}

+ 0 - 2
engine/source/sim/scriptGroup.h

@@ -35,8 +35,6 @@ class ScriptGroup : public SimGroup
    
 public:
    ScriptGroup();
-   bool onAdd();
-   void onRemove();
 
    DECLARE_CONOBJECT(ScriptGroup);
 };

+ 0 - 23
engine/source/sim/scriptObject.cc

@@ -34,28 +34,5 @@ IMPLEMENT_CONOBJECT(ScriptObject);
 
 ScriptObject::ScriptObject()
 {
-   mNSLinkMask = LinkSuperClassName | LinkClassName;
 }
 
-//-----------------------------------------------------------------------------
-
-bool ScriptObject::onAdd()
-{
-   if (!Parent::onAdd())
-      return false;
-
-   // Call onAdd in script!
-   Con::executef(this, 2, "onAdd", Con::getIntArg(getId()));
-   return true;
-}
-
-//-----------------------------------------------------------------------------
-
-void ScriptObject::onRemove()
-{
-   // Call onRemove in script!
-   Con::executef(this, 2, "onRemove", Con::getIntArg(getId()));
-
-   // Call parent.
-   Parent::onRemove();
-}

+ 0 - 2
engine/source/sim/scriptObject.h

@@ -35,8 +35,6 @@ class ScriptObject : public SimObject
 
 public:
    ScriptObject();
-   bool onAdd();
-   void onRemove();
 
    DECLARE_CONOBJECT(ScriptObject);
 };

+ 11 - 0
engine/source/sim/simObject.cc

@@ -97,6 +97,10 @@ bool SimObject::registerObject()
       unregisterObject();
 
    AssertFatal(!ret || isProperlyAdded(), "Object did not call SimObject::onAdd()");
+
+    if ( isMethod( "onAdd" ) )
+        Con::executef( this, 1, "onAdd" );
+
    return ret;
 }
 
@@ -107,6 +111,9 @@ void SimObject::unregisterObject()
     // Sanity!
     AssertISV( getScriptCallbackGuard() == 0, "SimObject::unregisterObject: Object is being unregistered whilst performing a script callback!" );
 
+    if ( isMethod( "onRemove" ) )
+        Con::executef( this, 1, "onRemove" );
+
    mFlags.set(Removed);
 
    // Notify object first
@@ -1473,6 +1480,8 @@ void SimObject::copyTo(SimObject* object)
    object->linkNamespaces();
 }
 
+//-----------------------------------------------------------------------------
+
 bool SimObject::setParentGroup(void* obj, const char* data)
 {
    SimGroup *parent = NULL;
@@ -1654,11 +1663,13 @@ void SimObject::unlinkNamespaces()
 void SimObject::setClassNamespace( const char *classNamespace )
 {
    mClassName = StringTable->insert( classNamespace );
+   linkNamespaces();
 }
 
 void SimObject::setSuperClassNamespace( const char *superClassNamespace )
 {  
    mSuperClassName = StringTable->insert( superClassNamespace );
+   linkNamespaces();
 }
 
 ConsoleMethod(SimObject, getClassNamespace, const char*, 2, 2, "")

+ 1 - 1
engine/source/sim/simObject.h

@@ -453,7 +453,7 @@ public:
     //from the console or C++.
     virtual void			dumpClassHierarchy();
     ///
-    SimObject( const U8 namespaceLinkMask = 0 );
+    SimObject( const U8 namespaceLinkMask = LinkSuperClassName | LinkClassName );
     virtual ~SimObject();
 
     virtual bool processArguments(S32 argc, const char **argv);  ///< Process constructor options. (ie, new SimObject(1,2,3))