gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9678: Drop assertion in Sound.cpp,


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9678: Drop assertion in Sound.cpp, make mouse button events handling in movie_root
Date: Thu, 04 Sep 2008 15:42:44 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9678
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2008-09-04 15:42:44 +0200
message:
  Drop assertion in Sound.cpp, make mouse button events handling in movie_root
  a bit more sensible. Don't leak ClassHierarchy on VM destruction (doesn't
  really matter now, but would if SWFs could be played successively).
modified:
  libcore/asobj/ClassHierarchy.cpp
  libcore/asobj/Sound.cpp
  libcore/mouse_button_state.h
  libcore/movie_root.cpp
  libcore/movie_root.h
  libcore/vm/VM.cpp
  libcore/vm/VM.h
    ------------------------------------------------------------
    revno: 9675.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2008-09-04 10:32:58 +0200
    message:
      Delete ClassHierarchy on destruction of VM.
    modified:
      libcore/asobj/ClassHierarchy.cpp
      libcore/vm/VM.cpp
      libcore/vm/VM.h
    ------------------------------------------------------------
    revno: 9675.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2008-09-04 14:08:55 +0200
    message:
      Some movies have sound IDs of more than 1000.
    modified:
      libcore/asobj/Sound.cpp
    ------------------------------------------------------------
    revno: 9675.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2008-09-04 14:09:34 +0200
    message:
      Make MouseButtonState into a struct as it has no private members. Rename
      its members.
      
      Make generate_mouse_button_events a member of movie_root so that it 
doesn't
      have to use VM::get() to get the movie_root. It can access
      m_mouse_button_events directly now, so doesn't need an argument. Make it a
      bit more readable (okay, not very much).
    modified:
      libcore/mouse_button_state.h
      libcore/movie_root.cpp
      libcore/movie_root.h
    ------------------------------------------------------------
    revno: 9675.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2008-09-04 14:15:33 +0200
    message:
      Use LOG_ONCE, update media handlers message.
    modified:
      libcore/asobj/Sound.cpp
=== modified file 'libcore/asobj/ClassHierarchy.cpp'
--- a/libcore/asobj/ClassHierarchy.cpp  2008-08-25 06:59:44 +0000
+++ b/libcore/asobj/ClassHierarchy.cpp  2008-09-04 08:32:58 +0000
@@ -213,6 +213,10 @@
 
 } // end anonymous namespace
 
+ClassHierarchy::~ClassHierarchy()
+{
+}
+
 bool
 ClassHierarchy::declareClass(extensionClass& c)
 {

=== modified file 'libcore/asobj/Sound.cpp'
--- a/libcore/asobj/Sound.cpp   2008-08-29 08:49:48 +0000
+++ b/libcore/asobj/Sound.cpp   2008-09-04 12:15:33 +0000
@@ -105,23 +105,13 @@
 void
 Sound::getPan()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_unimpl (__FUNCTION__);
-               warned = true;
-       }
+       LOG_ONCE(log_unimpl(__FUNCTION__));
 }
 
 void
 Sound::getTransform()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_unimpl (__FUNCTION__);
-               warned = true;
-       }
+       LOG_ONCE(log_unimpl(__FUNCTION__));
 }
 
 bool
@@ -184,23 +174,13 @@
 void
 Sound::setPan()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_unimpl (__FUNCTION__);
-               warned = true;
-       }
+       LOG_ONCE(log_unimpl(__FUNCTION__));
 }
 
 void
 Sound::setTransform()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_unimpl (__FUNCTION__);
-               warned = true;
-       }
+       LOG_ONCE(log_unimpl(__FUNCTION__));
 }
 
 void
@@ -274,7 +254,8 @@
        {
            if (si > -1) {
                        _soundHandler->stop_sound(soundId);
-               } else {
+               }
+               else {
                        _soundHandler->stop_sound(si);
                }
        }
@@ -283,24 +264,14 @@
 unsigned int
 Sound::getDuration()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_error(_("%s: only works when ffmpeg, gstreamer or libmad is 
enabled"), __FUNCTION__);
-               warned = true;
-       }
+    LOG_ONCE(log_error(_("%s: only works when a media handler is enabled"), 
__FUNCTION__));
        return 0;
 }
 
 unsigned int
 Sound::getPosition()
 {
-       static bool warned = false;
-       if ( ! warned )
-       {
-               log_error(_("%s: only works when ffmpeg, gstreamer or libmad is 
enabled"), __FUNCTION__);
-               warned = true;
-       }
+    LOG_ONCE(log_error(_("%s: only works when a media handler is enabled"), 
__FUNCTION__));
        return 0;
 }
 
@@ -470,7 +441,7 @@
        }
 
        // sanity check
-       assert(si >= 0 && si < 1000);
+       assert(si >= 0);
        so->attachSound(si, name);
        return as_value();
 }

=== modified file 'libcore/mouse_button_state.h'
--- a/libcore/mouse_button_state.h      2008-04-21 10:27:41 +0000
+++ b/libcore/mouse_button_state.h      2008-09-04 12:09:34 +0000
@@ -20,41 +20,37 @@
 namespace gnash {
 
 /// Helper to generate mouse events, given mouse state & history.
-class mouse_button_state
+struct MouseButtonState
 {
 
 public:
 
        /// Possible button states
-       enum state {
-
-               /// Button is depressed
-               UP=0,
-
-               /// Button is pressed
-               DOWN=1
-       };
+       enum State {
+        UP,
+        DOWN
+    };  
 
        /// entity that currently owns the mouse pointer
-       boost::intrusive_ptr<character> m_active_entity;
+       boost::intrusive_ptr<character> activeEntity;
 
        /// what's underneath the mouse right now
-       boost::intrusive_ptr<character> m_topmost_entity;
+       boost::intrusive_ptr<character> topmostEntity;
 
        /// previous state of mouse button
-       bool    m_mouse_button_state_last;      
+       bool previousButtonState;       
 
        /// current state of mouse button
-       bool    m_mouse_button_state_current;   
+       bool currentButtonState;        
 
        /// whether mouse was inside the active_entity last frame
-       bool    m_mouse_inside_entity_last;
+       bool wasInsideActiveEntity;
 
-       mouse_button_state()
+       MouseButtonState()
                :
-               m_mouse_button_state_last(UP),
-               m_mouse_button_state_current(UP),
-               m_mouse_inside_entity_last(false)
+               previousButtonState(UP),
+               currentButtonState(UP),
+               wasInsideActiveEntity(false)
        {
        }
 
@@ -62,8 +58,8 @@
        /// Mark reachable objects (active and topmost entities)
        void markReachableResources() const
        {
-               if ( m_active_entity.get() ) m_active_entity->setReachable();
-               if ( m_topmost_entity.get() ) m_topmost_entity->setReachable();
+               if ( activeEntity.get() ) activeEntity->setReachable();
+               if ( topmostEntity.get() ) topmostEntity->setReachable();
        }
 #endif // GNASH_USE_GC
 };

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2008-09-04 03:04:47 +0000
+++ b/libcore/movie_root.cpp    2008-09-04 12:09:34 +0000
@@ -129,11 +129,9 @@
        _disableScripts = true;
 
        // NOTE: we won't clear the action queue now
-       //       to avoid invalidating iterators as we've
-       //       been probably called during processing
-       //       of the queue.
-       //
-       //clearActionQueue();
+       // to avoid invalidating iterators as we've
+       // been probably called during processing
+       // of the queue.
 }
 
 void
@@ -625,7 +623,7 @@
 
        // Notify both character and non-character Key listeners
        //      for user defined handerlers.
-       if(global_key)
+       if (global_key)
        {
            try
            {
@@ -691,184 +689,148 @@
 }
 #endif
 
-// Return wheter any action triggered by this event requires display redraw.
+// Return whether any action triggered by this event requires display redraw.
 // See page about events_handling (in movie_interface.h)
 //
 /// TODO: make this code more readable !
 bool
-generate_mouse_button_events(mouse_button_state* ms)
+movie_root::generate_mouse_button_events()
 {
-       boost::intrusive_ptr<character> active_entity = ms->m_active_entity;
-       boost::intrusive_ptr<character> topmost_entity = ms->m_topmost_entity;
+
+    MouseButtonState& ms = m_mouse_button_state;
 
        // Did this event trigger any action that needs redisplay ?
        bool need_redisplay = false;
 
-       VM& vm = VM::get();
-
-       if (ms->m_mouse_button_state_last == mouse_button_state::DOWN)
-       {
-               // Mouse button was down.
-               // TODO: Handle trackAsMenu dragOver
-               // Handle onDragOut, onDragOver
-               if (ms->m_mouse_inside_entity_last == false)
-               {
-                       if (topmost_entity == active_entity)
-                       {
-                               // onDragOver
-                               if (active_entity != NULL)
-                               {
-                                       
active_entity->on_button_event(event_id::DRAG_OVER);
-                                       // TODO: have on_button_event return
-                                       //       wheter the action must trigger
-                                       //       a redraw.
-                                       need_redisplay=true;
-                               }
-                               ms->m_mouse_inside_entity_last = true;
-                       }
-               }
-               else
-               {
-                       // mouse_inside_entity_last == true
-                       if (topmost_entity != active_entity)
-                       {
-                               // onDragOut
-                               if (active_entity != NULL)
-                               {
-#ifndef GNASH_USE_GC
-                                       assert(active_entity->get_ref_count() > 
1); // we are NOT the only object holder !
-#endif // GNASH_USE_GC
-                                       
active_entity->on_button_event(event_id::DRAG_OUT);
-                                       // TODO: have on_button_event return
-                                       //       wheter the action must trigger
-                                       //       a redraw.
-                                       need_redisplay=true;
-                               }
-                               ms->m_mouse_inside_entity_last = false;
-                       }
-               }
-
-               // Handle onRelease, onReleaseOutside
-               if (ms->m_mouse_button_state_current == mouse_button_state::UP)
-               {
-                       // Mouse button just went up.
-                       ms->m_mouse_button_state_last = mouse_button_state::UP;
-
-                       if (active_entity != NULL)
-                       {
-                               if (ms->m_mouse_inside_entity_last)
-                               {
-                                       // onRelease
-                                       
active_entity->on_button_event(event_id::RELEASE);
-                                       // TODO: have on_button_event return
-                                       //       wheter the action must trigger
-                                       //       a redraw.
-                                       need_redisplay=true;
-                               }
-                               else
-                               {
-                                       // TODO: Handle trackAsMenu 
-
-                                       // onReleaseOutside
-                                       
active_entity->on_button_event(event_id::RELEASE_OUTSIDE);
-
-                                       // We got out of active entity
-                                       //ms->m_mouse_inside_entity_last = 
false;
-                                       active_entity = NULL; // so we don't 
get RollOut next...
-
-                                       // TODO: have on_button_event return
-                                       //       wheter the action must trigger
-                                       //       a redraw.
-                                       need_redisplay=true;
-                               }
-                       }
-               }
-       }
-       else if ( ms->m_mouse_button_state_last == mouse_button_state::UP )
-       {
-               // Mouse button was up.
-
-               // New active entity is whatever is below the mouse right now.
-               if (topmost_entity != active_entity)
-               {
-                       // onRollOut
-                       if (active_entity != NULL)
-                       {
-                               
active_entity->on_button_event(event_id::ROLL_OUT);
-                               // TODO: have on_button_event return
-                               //       wheter the action must trigger
-                               //       a redraw.
-                               need_redisplay=true;
-                       }
-
-                       active_entity = topmost_entity;
-
-                       // onRollOver
-                       if (active_entity != NULL)
-                       {
-                               
active_entity->on_button_event(event_id::ROLL_OVER);
-                               // TODO: have on_button_event return
-                               //       wheter the action must trigger
-                               //       a redraw.
-                               need_redisplay=true;
-                       }
-
-                       ms->m_mouse_inside_entity_last = true;
-               }
-
-               // mouse button press
-               if (ms->m_mouse_button_state_current == 
mouse_button_state::DOWN )
-               {
-                       // onPress
-
-                       // set/kill focus for current root
-                       movie_root& mroot = VM::get().getRoot();
-                       character* current_active_entity = mroot.getFocus();
-
-                       // It's another entity ?
-                       if (current_active_entity != active_entity.get())
-                       {
-                               // First to clean focus
-                               if (current_active_entity != NULL)
-                               {
-                                       
current_active_entity->on_event(event_id::KILLFOCUS);
-                                       // TODO: have on_button_event return
-                                       //       wheter the action must trigger
-                                       //       a redraw.
-                                       need_redisplay=true;
-                                       mroot.setFocus(NULL);
-                               }
-
-                               // Then to set focus
-                               if (active_entity != NULL)
-                               {
-                                       if 
(active_entity->on_event(event_id::SETFOCUS))
-                                       {
-                                               
mroot.setFocus(active_entity.get());
-                                       }
-                               }
-                       }
-
-                       if (active_entity != NULL)
-                       {
-                               active_entity->on_button_event(event_id::PRESS);
-                               // TODO: have on_button_event return
-                               //       wheter the action must trigger
-                               //       a redraw.
-                               need_redisplay=true;
-                       }
-                       ms->m_mouse_inside_entity_last = true;
-                       ms->m_mouse_button_state_last = 
mouse_button_state::DOWN;
-               }
-       }
-
-       // Write the (possibly modified) boost::intrusive_ptr copies back
-       // into the state struct.
-       ms->m_active_entity = active_entity;
-       ms->m_topmost_entity = topmost_entity;
-
-       //if ( ! need_redisplay ) log_debug("Hurray, an event didn't trigger 
redisplay!");
-       return need_redisplay;
+    // TODO: have on_button_event return
+    // whether the action must trigger
+    // a redraw.
+
+    switch (ms.previousButtonState)
+    {
+        case MouseButtonState::DOWN:
+           {
+                   // TODO: Handle trackAsMenu dragOver
+                   // Handle onDragOut, onDragOver
+                   if (!ms.wasInsideActiveEntity)
+                   {
+                           if (ms.topmostEntity == ms.activeEntity)
+                           {
+                                   // onDragOver
+                                   if (ms.activeEntity)
+                                   {
+                                           
ms.activeEntity->on_button_event(event_id::DRAG_OVER);
+                                           need_redisplay=true;
+                                   }
+                                   ms.wasInsideActiveEntity = true;
+                           }
+                   }
+                   else if (ms.topmostEntity != ms.activeEntity)
+                   {
+                           // onDragOut
+                           if (ms.activeEntity)
+                           {
+                                   
ms.activeEntity->on_button_event(event_id::DRAG_OUT);
+                                   need_redisplay=true;
+                           }
+                           ms.wasInsideActiveEntity = false;
+                   }
+
+                   // Handle onRelease, onReleaseOutside
+                   if (ms.currentButtonState == MouseButtonState::UP)
+                   {
+                           // Mouse button just went up.
+                           ms.previousButtonState = MouseButtonState::UP;
+
+                           if (ms.activeEntity)
+                           {
+                                   if (ms.wasInsideActiveEntity)
+                                   {
+                                           // onRelease
+                                           
ms.activeEntity->on_button_event(event_id::RELEASE);
+                                           need_redisplay = true;
+                                   }
+                                   else
+                                   {
+                                           // TODO: Handle trackAsMenu 
+                                           // onReleaseOutside
+                                           
ms.activeEntity->on_button_event(event_id::RELEASE_OUTSIDE);
+                                           // We got out of active entity
+                                           ms.activeEntity = NULL; // so we 
don't get RollOut next...
+                                           need_redisplay = true;
+                                   }
+                           }
+                   }
+               return need_redisplay;
+           }
+
+
+           case MouseButtonState::UP:
+        {
+               // New active entity is whatever is below the mouse right now.
+               if (ms.topmostEntity != ms.activeEntity)
+               {
+                       // onRollOut
+                       if (ms.activeEntity != NULL)
+                       {
+                               
ms.activeEntity->on_button_event(event_id::ROLL_OUT);
+                               need_redisplay=true;
+                       }
+
+                       ms.activeEntity = ms.topmostEntity;
+
+                       // onRollOver
+                       if (ms.activeEntity != NULL)
+                       {
+                               
ms.activeEntity->on_button_event(event_id::ROLL_OVER);
+                               need_redisplay=true;
+                       }
+
+                       ms.wasInsideActiveEntity = true;
+               }
+
+               // mouse button press
+               if (ms.currentButtonState == MouseButtonState::DOWN )
+               {
+                       // onPress
+
+                       // set/kill focus for current root
+                       character* current_active_entity = getFocus();
+
+                       // It's another entity ?
+                       if (current_active_entity != ms.activeEntity.get())
+                       {
+                               // First to clean focus
+                               if (current_active_entity != NULL)
+                               {
+                                       
current_active_entity->on_event(event_id::KILLFOCUS);
+                                       need_redisplay=true;
+                                       setFocus(NULL);
+                               }
+
+                               // Then to set focus
+                               if (ms.activeEntity)
+                               {
+                                       if 
(ms.activeEntity->on_event(event_id::SETFOCUS))
+                                       {
+                                               setFocus(ms.activeEntity.get());
+                                       }
+                               }
+                       }
+
+                       if (ms.activeEntity)
+                       {
+                               
ms.activeEntity->on_button_event(event_id::PRESS);
+                               need_redisplay=true;
+                       }
+                       ms.wasInsideActiveEntity = true;
+                       ms.previousButtonState = MouseButtonState::DOWN;
+               }
+        }
+        default:
+           return need_redisplay;
+    }
+
 }
 
 
@@ -883,8 +845,8 @@
     boost::int32_t y = PIXELS_TO_TWIPS(m_mouse_y);
 
     // Generate a mouse event
-    m_mouse_button_state.m_topmost_entity = getTopmostMouseEntity(x, y);
-    m_mouse_button_state.m_mouse_button_state_current = (m_mouse_buttons & 1);
+    m_mouse_button_state.topmostEntity = getTopmostMouseEntity(x, y);
+    m_mouse_button_state.currentButtonState = (m_mouse_buttons & 1);
 
     // Set _droptarget if dragging a sprite
     sprite_instance* dragging = 0;
@@ -912,8 +874,7 @@
 
     try
     {
-        need_redraw = generate_mouse_button_events(&m_mouse_button_state);
-
+        need_redraw = generate_mouse_button_events();
         processActionQueue();
     }
     catch (ActionLimitException& al)
@@ -1369,7 +1330,7 @@
 character*
 movie_root::getActiveEntityUnderPointer() const
 {
-       return m_mouse_button_state.m_active_entity.get();
+       return m_mouse_button_state.activeEntity.get();
 }
 
 character*
@@ -1393,7 +1354,7 @@
 {
        assert(testInvariant());
 
-       boost::intrusive_ptr<character> entity ( 
m_mouse_button_state.m_active_entity );
+       boost::intrusive_ptr<character> entity ( 
m_mouse_button_state.activeEntity );
        if ( ! entity.get() ) {
         return false;
     }

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2008-09-04 03:04:47 +0000
+++ b/libcore/movie_root.h      2008-09-04 12:09:34 +0000
@@ -924,7 +924,7 @@
     float       m_timer;
     int         m_mouse_x, m_mouse_y, m_mouse_buttons;
 
-    mouse_button_state  m_mouse_button_state;
+    MouseButtonState  m_mouse_button_state;
 
     typedef std::map<int, Timer*> TimerMap;
 
@@ -971,6 +971,8 @@
     ///
     bool fire_mouse_event();
 
+    bool generate_mouse_button_events();
+
     /// \brief
     /// Return the topmost entity covering the given point
     /// and enabled to receive mouse events.

=== modified file 'libcore/vm/VM.cpp'
--- a/libcore/vm/VM.cpp 2008-09-01 18:11:06 +0000
+++ b/libcore/vm/VM.cpp 2008-09-04 08:32:58 +0000
@@ -61,8 +61,8 @@
        assert(_singleton.get());
        NSV::load_strings(&_singleton->mStringTable, 
_singleton->getSWFVersion());
 
-       _singleton->mClassHierarchy = new ClassHierarchy;
-       _singleton->setGlobal(new Global(*_singleton, 
_singleton->mClassHierarchy));
+       _singleton->mClassHierarchy.reset(new ClassHierarchy);
+       _singleton->setGlobal(new Global(*_singleton, 
_singleton->mClassHierarchy.get()));
        assert(_singleton->getGlobal());
 
        return *_singleton;
@@ -87,7 +87,6 @@
        _root_movie(new movie_root()),
        _swfversion(topmovie.get_version()),
        _swfurl(topmovie.get_url()),
-       mClassHierarchy(0),
        mMachine(0),
        _clock(clock),
        _stack()

=== modified file 'libcore/vm/VM.h'
--- a/libcore/vm/VM.h   2008-09-01 18:11:06 +0000
+++ b/libcore/vm/VM.h   2008-09-04 08:32:58 +0000
@@ -147,8 +147,10 @@
 
        /// Mutable since it should not affect how the VM runs.
        mutable string_table mStringTable;
+
        /// Not mutable since changing this changes behavior of the VM.
-       ClassHierarchy *mClassHierarchy;
+       std::auto_ptr<ClassHierarchy> mClassHierarchy;
+
        /// A running execution thread.
        Machine *mMachine;
 
@@ -266,7 +268,7 @@
        as_object* getGlobal() const;
 
        /// Get a pointer to this VM's global ClassHierarchy object.
-       ClassHierarchy* getClassHierarchy() const { return mClassHierarchy; }
+       ClassHierarchy* getClassHierarchy() const { return 
mClassHierarchy.get(); }
        
        /// Get the SWF locale to use 
        std::locale& getLocale() const;


reply via email to

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