gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r12179: Some cleanups of action code


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12179: Some cleanups of action code.
Date: Fri, 07 May 2010 11:47:13 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12179 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2010-05-07 11:47:13 +0200
message:
  Some cleanups of action code.
modified:
  libcore/Button.cpp
  libcore/DisplayObject.cpp
  libcore/MovieClip.cpp
  libcore/MovieLoader.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  libcore/swf/ControlTag.h
  libcore/vm/ExecutableCode.h
=== modified file 'libcore/Button.cpp'
--- a/libcore/Button.cpp        2010-03-11 17:03:04 +0000
+++ b/libcore/Button.cpp        2010-05-07 08:01:02 +0000
@@ -563,7 +563,7 @@
     // check for built-in event handler.
     std::auto_ptr<ExecutableCode> code ( get_event_handler(event) );
     if (code.get()) {
-        mr.pushAction(code, movie_root::apDOACTION);
+        mr.pushAction(code, movie_root::PRIORITY_DOACTION);
     }
 
     callMethod(getObject(this), event.functionKey());

=== modified file 'libcore/DisplayObject.cpp'
--- a/libcore/DisplayObject.cpp 2010-03-11 01:47:08 +0000
+++ b/libcore/DisplayObject.cpp 2010-05-07 08:01:02 +0000
@@ -472,7 +472,7 @@
 {
 
        if (!_unloaded) {
-               queueEvent(event_id::UNLOAD, movie_root::apDOACTION);
+               queueEvent(event_id::UNLOAD, movie_root::PRIORITY_DOACTION);
        }
 
     // Unregister this DisplayObject as mask and/or maskee.

=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp     2010-05-06 11:25:42 +0000
+++ b/libcore/MovieClip.cpp     2010-05-07 09:20:30 +0000
@@ -87,7 +87,12 @@
 //
 //#define DEBUG_MOUSE_ENTITY_FINDING 1
 
-/// Anonymous namespace for module-private definitions
+namespace {
+    inline void executeIfActionTag(const SWF::ControlTag& t, MovieClip* m,
+            DisplayList& dlist);
+}
+
+// Anonymous namespace for module-private definitions
 namespace {
 
 /// ConstructEvent, used for queuing construction
@@ -540,8 +545,8 @@
     if (playlist) {
         PlayList::const_iterator it = playlist->begin();
         const PlayList::const_iterator e = playlist->end();
-        for(; it != e; it++) {
-            (*it)->execute_action(this, _displayList);
+        for (; it != e; it++) {
+            executeIfActionTag(**it, this, _displayList);
         }
     }
     _callingFrameActions = false;
@@ -819,7 +824,7 @@
 #endif
 
     // I'm not sure ENTERFRAME goes in a different queue then DOACTION...
-    queueEvent(event_id::ENTER_FRAME, movie_root::apDOACTION);
+    queueEvent(event_id::ENTER_FRAME, movie_root::PRIORITY_DOACTION);
 
     // Update current and next frames.
     if (_playState == PLAYSTATE_PLAY)
@@ -886,7 +891,7 @@
 #endif
         std::auto_ptr<ExecutableCode> code(new GlobalCode(a, this));
 
-        stage().pushAction(code, movie_root::apINIT);
+        stage().pushAction(code, movie_root::PRIORITY_INIT);
     }
     else
     {
@@ -972,9 +977,8 @@
         else
         {
             assert(typeflags & SWF::ControlTag::TAG_ACTION);
-            for( ; it != e; it++)
-            {
-                (*it)->execute_action(this, dlist);
+            for( ; it != e; it++) {
+                executeIfActionTag(**it, this, _displayList);
             }
         }
     }
@@ -1796,7 +1800,7 @@
 #ifdef GNASH_DEBUG
             log_debug(_("Queuing ONLOAD event for movieclip %s"), getTarget());
 #endif
-            queueEvent(event_id::LOAD, movie_root::apDOACTION);
+            queueEvent(event_id::LOAD, movie_root::PRIORITY_DOACTION);
         }
 
     }
@@ -1805,7 +1809,7 @@
 #ifdef GNASH_DEBUG
         log_debug(_("Queuing ONLOAD event for movieclip %s"), getTarget());
 #endif
-        queueEvent(event_id::LOAD, movie_root::apDOACTION);
+        queueEvent(event_id::LOAD, movie_root::PRIORITY_DOACTION);
 
 #ifdef GNASH_DEBUG
         log_debug(_("Executing tags of frame0 in movieclip %s"), getTarget());
@@ -1831,10 +1835,10 @@
         log_debug(_("Queuing INITIALIZE and CONSTRUCT events for movieclip 
%s"),
                 getTarget());
 #endif
-        queueEvent(event_id::INITIALIZE, movie_root::apINIT);
+        queueEvent(event_id::INITIALIZE, movie_root::PRIORITY_INIT);
 
         std::auto_ptr<ExecutableCode> code(new ConstructEvent(this));
-        stage().pushAction(code, movie_root::apCONSTRUCT);
+        stage().pushAction(code, movie_root::PRIORITY_CONSTRUCT);
 
     }
     else {
@@ -1851,7 +1855,7 @@
         // Tested in testsuite/swfdec/duplicateMovieclip-events.c and
         // testsuite/swfdec/clone-sprite-events.c not to call notifyEvent
         // immediately.
-        queueEvent(event_id::INITIALIZE, movie_root::apINIT);
+        queueEvent(event_id::INITIALIZE, movie_root::PRIORITY_INIT);
     }
 
 
@@ -2281,4 +2285,15 @@
     _playState = s;
 }
 
+namespace {
+
+/// 
+inline void
+executeIfActionTag(const SWF::ControlTag& t, MovieClip* m, DisplayList& dlist)
+{
+    if (t.is_action_tag()) t.execute(m, dlist);
+}
+
+}
+
 } // namespace gnash

=== modified file 'libcore/MovieLoader.cpp'
--- a/libcore/MovieLoader.cpp   2010-03-11 01:47:08 +0000
+++ b/libcore/MovieLoader.cpp   2010-05-07 08:17:21 +0000
@@ -226,17 +226,15 @@
     //GNASH_REPORT_FUNCTION;
 
     boost::intrusive_ptr<movie_definition> md;
-    if ( ! r.getCompleted(md) ) return false; // not completed yet
+    if (!r.getCompleted(md)) return false; // not completed yet
 
     const std::string& target = r.getTarget();
     DisplayObject* targetDO = _movieRoot.findCharacterByTarget(target);
     as_object* handler = r.getHandler();
 
-    if ( ! md )
-    {
+    if (!md) {
 
-        if ( targetDO && handler )
-        {
+        if (targetDO && handler) {
             // Signal load error
             // Tested not to happen if target isn't found at time of loading
             //
@@ -261,8 +259,7 @@
     const URL& url = r.getURL();
 
        Movie* extern_movie = md->createMovie(*_movieRoot.getVM().getGlobal());
-       if (!extern_movie)
-    {
+       if (!extern_movie) {
                log_error(_("Can't create Movie instance "
                     "for definition loaded from %s"), url);
                return true; // completed in any case...
@@ -273,31 +270,26 @@
        url.parse_querystring(url.querystring(), vars);
     extern_movie->setVariables(vars);
 
-    if (targetDO)
-    {
+    if (targetDO) {
         targetDO->getLoadedMovie(extern_movie);
     }
-    else
-    {
+    else {
         unsigned int levelno;
         const int version = _movieRoot.getVM().getSWFVersion();
-        if (isLevelTarget(version, target, levelno))
-        {
+        if (isLevelTarget(version, target, levelno)) {
             log_debug(_("processCompletedRequest: _level loading "
                     "(level %u)"), levelno);
                extern_movie->set_depth(levelno + 
DisplayObject::staticDepthOffset);
             _movieRoot.setLevel(levelno, extern_movie);
         }
-        else
-        {
+        else {
             log_debug("Target %s of a loadMovie request doesn't exist at "
                   "load complete time", target);
             return true;
         }
     }
 
-    if (handler && targetDO)
-    {
+    if (handler && targetDO) {
         // Dispatch onLoadStart
         // FIXME: should be signalled before starting to load
         //        (0/-1 bytes loaded/total) but still with *new*
@@ -335,7 +327,7 @@
                 new DelayedFunctionCall(handler, NSV::PROP_BROADCAST_MESSAGE, 
                     "onLoadInit", getObject(targetDO)));
 
-        getRoot(*handler).pushAction(code, movie_root::apDOACTION);
+        getRoot(*handler).pushAction(code, movie_root::PRIORITY_DOACTION);
     }
 
     return true;

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2010-04-22 00:25:00 +0000
+++ b/libcore/movie_root.cpp    2010-05-07 08:31:47 +0000
@@ -130,7 +130,7 @@
     _rootMovie(0),
     _invalidated(true),
     _disableScripts(false),
-    _processingActionLevel(movie_root::apSIZE),
+    _processingActionLevel(movie_root::PRIORITY_SIZE),
     _hostfd(-1),
     _quality(QUALITY_HIGH),
     _alignMode(0),
@@ -170,10 +170,8 @@
 void
 movie_root::clearActionQueue()
 {
-    for (int lvl=0; lvl<apSIZE; ++lvl)
-    {
+    for (int lvl=0; lvl < PRIORITY_SIZE; ++lvl) {
         ActionQueue& q = _actionQueue[lvl];
-
         deleteChecked(q.begin(), q.end());
         q.clear();
     }
@@ -1408,18 +1406,17 @@
 
 }
 
-int
+size_t
 movie_root::minPopulatedPriorityQueue() const
 {
-    for (int l=0; l<apSIZE; ++l)
-    {
+    for (size_t l = 0; l < PRIORITY_SIZE; ++l) {
         if (!_actionQueue[l].empty()) return l;
     }
-    return apSIZE;
+    return PRIORITY_SIZE;
 }
 
-int
-movie_root::processActionQueue(int lvl)
+size_t
+movie_root::processActionQueue(size_t lvl)
 {
     ActionQueue& q = _actionQueue[lvl];
 
@@ -1429,8 +1426,7 @@
     static unsigned calls=0;
     ++calls;
     bool actionsToProcess = !q.empty();
-    if ( actionsToProcess )
-    {
+    if (actionsToProcess) {
         log_debug(" Processing %d actions in priority queue %d (call %u)",
                     q.size(), lvl, calls);
     }
@@ -1439,15 +1435,14 @@
     // _actionQueue may be changed due to actions (appended-to)
     // this loop might be optimized by using an iterator
     // and a final call to .clear() 
-    while ( ! q.empty() )
-    {
+    while (!q.empty()) {
+
         std::auto_ptr<ExecutableCode> code(q.front());
         q.pop_front(); 
         code->execute();
 
-        int minLevel = minPopulatedPriorityQueue();
-        if ( minLevel < lvl )
-        {
+        size_t minLevel = minPopulatedPriorityQueue();
+        if (minLevel < lvl) {
 #ifdef GNASH_DEBUG
             log_debug(" Actions pushed in priority %d (< "
                     "%d), restarting the scan (call"
@@ -1460,8 +1455,7 @@
     assert(q.empty());
 
 #ifdef GNASH_DEBUG
-    if ( actionsToProcess )
-    {
+    if (actionsToProcess) {
         log_debug(" Done processing actions in priority queue "
                 "%d (call %u)", lvl, calls);
     }
@@ -1520,16 +1514,15 @@
 void
 movie_root::processActionQueue()
 {
-    if ( _disableScripts )
-    {
+    if (_disableScripts) {
         /// cleanup anything pushed later..
         clearActionQueue();
         return;
     }
 
-    _processingActionLevel=minPopulatedPriorityQueue();
-    while ( _processingActionLevel<apSIZE )
-    {
+    _processingActionLevel = minPopulatedPriorityQueue();
+
+    while (_processingActionLevel < PRIORITY_SIZE) {
         _processingActionLevel = processActionQueue(_processingActionLevel);
     }
 
@@ -1539,16 +1532,15 @@
 }
 
 void
-movie_root::pushAction(std::auto_ptr<ExecutableCode> code, int lvl)
+movie_root::pushAction(std::auto_ptr<ExecutableCode> code, size_t lvl)
 {
-    assert(lvl >= 0 && lvl < apSIZE);
+    assert(lvl < PRIORITY_SIZE);
     _actionQueue[lvl].push_back(code.release());
 }
 
 void
-movie_root::pushAction(const action_buffer& buf, DisplayObject* target, int 
lvl)
+movie_root::pushAction(const action_buffer& buf, DisplayObject* target)
 {
-    assert(lvl >= 0 && lvl < apSIZE);
 #ifdef GNASH_DEBUG
     log_debug("Pushed action buffer for target %s", 
             target->getTargetPath());
@@ -1556,21 +1548,7 @@
 
     std::auto_ptr<ExecutableCode> code(new GlobalCode(buf, target));
 
-    _actionQueue[lvl].push_back(code.release());
-}
-
-void
-movie_root::pushAction(as_function* func, DisplayObject* target, int lvl)
-{
-    assert(lvl >= 0 && lvl < apSIZE);
-#ifdef GNASH_DEBUG
-    log_debug("Pushed function (event hanlder?) with target %s",
-            target->getTargetPath());
-#endif
-
-    std::auto_ptr<ExecutableCode> code(new FunctionCode(func, target));
-
-    _actionQueue[lvl].push_back(code.release());
+    _actionQueue[PRIORITY_DOACTION].push_back(code.release());
 }
 
 void
@@ -1676,7 +1654,7 @@
     _movieLoader.setReachable();
 
     // Mark resources reachable by queued action code
-    for (int lvl=0; lvl<apSIZE; ++lvl)
+    for (size_t lvl = 0; lvl < PRIORITY_SIZE; ++lvl)
     {
         const ActionQueue& q = _actionQueue[lvl];
         std::for_each(q.begin(), q.end(),

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2010-04-22 00:25:00 +0000
+++ b/libcore/movie_root.h      2010-05-07 08:31:47 +0000
@@ -617,32 +617,24 @@
     enum ActionPriorityLevel {
        
         /// Init actions, Init event handlers
-        apINIT=0,
+        PRIORITY_INIT,
        
         /// Construct event handlers
-        apCONSTRUCT=1,
-
-        /// EnterFrame event handlers
-        apENTERFRAME=2,
+        PRIORITY_CONSTRUCT,
 
         /// Frame actions, load handlers, unload handlers
-        apDOACTION=3,
+        PRIORITY_DOACTION,
 
         /// Last element used to easy computation of size...
-        apSIZE
+        PRIORITY_SIZE
         
     };
 
     /// Push an executable code to the ActionQueue
-    void pushAction(std::auto_ptr<ExecutableCode> code, int lvl=apDOACTION);
+    void pushAction(std::auto_ptr<ExecutableCode> code, size_t lvl);
 
     /// Push an executable code to the ActionQueue
-    void pushAction(const action_buffer& buf, DisplayObject* target,
-            int lvl=apDOACTION);
-
-    /// Push a function code to the ActionQueue
-    void pushAction(as_function* func, DisplayObject* target,
-            int lvl=apDOACTION);
+    void pushAction(const action_buffer& buf, DisplayObject* target);
 
 #ifdef GNASH_USE_GC
     /// Mark all reachable resources (for GC)
@@ -1060,16 +1052,16 @@
     //
     /// Scanned in proprity order (lower first)
     ///
-    int minPopulatedPriorityQueue() const;
+    size_t minPopulatedPriorityQueue() const;
 
     /// Process all actions in the the given queue, till more actions
     /// are found in lower levels, in which case we have an earlier
     /// return.
-    int processActionQueue(int lvl);
+    size_t processActionQueue(size_t lvl);
 
     bool processingActions() const
     {
-        return (_processingActionLevel < apSIZE);
+        return (_processingActionLevel < PRIORITY_SIZE);
     }
 
     const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y,
@@ -1094,7 +1086,7 @@
     /// frequent push_back and pop_front. We also have to traverse it, so
     /// a std::queue is not usable.
     typedef std::deque<ExecutableCode*> ActionQueue;
-    ActionQueue _actionQueue[apSIZE];
+    ActionQueue _actionQueue[PRIORITY_SIZE];
 
     /// Process all actions in the queue
     void processActionQueue();

=== modified file 'libcore/swf/ControlTag.h'
--- a/libcore/swf/ControlTag.h  2010-03-10 16:13:07 +0000
+++ b/libcore/swf/ControlTag.h  2010-05-07 09:20:30 +0000
@@ -62,12 +62,6 @@
        {
        }
 
-       /// Execute this tag but only if it is an action tag
-       void execute_action(MovieClip* m, DisplayList& dlist) const
-       {
-               if (is_action_tag()) execute(m, dlist);
-       }
-
        /// Return true if this is an action tag.
     //
     /// The default returns false.
@@ -75,7 +69,6 @@
 
 };
 
-
 } // namespace SWF
 } // namespace gnash
 

=== modified file 'libcore/vm/ExecutableCode.h'
--- a/libcore/vm/ExecutableCode.h       2010-03-11 01:47:08 +0000
+++ b/libcore/vm/ExecutableCode.h       2010-05-07 08:21:15 +0000
@@ -209,49 +209,6 @@
 
 };
 
-/// Function code
-class FunctionCode: public ExecutableCode {
-
-public:
-
-    FunctionCode(as_function* nFunc, DisplayObject* nTarget)
-        :
-        func(nFunc),
-        target(nTarget)
-    {}
-
-    ExecutableCode* clone() const
-    {
-        return new FunctionCode(*this);
-    }
-
-    virtual void execute()
-    {
-        as_environment env(getVM(*func)); env.set_target(target);
-        func->call(fn_call(getObject(target), env));
-    }
-
-#ifdef GNASH_USE_GC
-    /// Mark reachable resources (for the GC)
-    //
-    /// Reachable resources are:
-    ///  - the function body (func)
-    ///  - the action target (target)
-    ///
-    virtual void markReachableResources() const
-    {
-        if (func) func->setReachable();
-        if (target) target->setReachable();
-    }
-#endif // GNASU_USE_GC
-
-private:
-
-    as_function* func;
-
-    DisplayObject* target;
-};
-
 /// This class is used to queue a function call action
 //
 /// Exact use is to queue onLoadInit, which should be invoked


reply via email to

[Prev in Thread] Current Thread [Next in Thread]