gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9830: Const correctness, reduce unn


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9830: Const correctness, reduce unnecessary const_casts (const_casts are particularly
Date: Wed, 24 Sep 2008 17:47:37 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9830
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2008-09-24 17:47:37 +0200
message:
  Const correctness, reduce unnecessary const_casts (const_casts are 
particularly
  evil), optimize Button (button_character_instance) class.
  
  Minor actionscript compatibility fixes.
  
  Drop unused methods.
modified:
  libcore/PropertyList.cpp
  libcore/PropertyList.h
  libcore/as_object.cpp
  libcore/asobj/flash/geom/ColorTransform_as.cpp
  libcore/button_character_instance.cpp
  libcore/button_character_instance.h
  libcore/parser/button_character_def.cpp
  libcore/sprite_instance.h
    ------------------------------------------------------------
    revno: 9827.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 11:05:56 +0200
    message:
      Set correct propflags on ColorTransform methods (see swfdec testsuite).
    modified:
      libcore/asobj/flash/geom/ColorTransform_as.cpp
    ------------------------------------------------------------
    revno: 9827.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 12:32:01 +0200
    message:
      Drop unnecessary const_casts, const-correct PropertyList::setValue.
    modified:
      libcore/PropertyList.cpp
      libcore/PropertyList.h
      libcore/as_object.cpp
    ------------------------------------------------------------
    revno: 9827.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 14:58:50 +0200
    message:
      Drop unneeded transition() member.
    modified:
      libcore/sprite_instance.h
    ------------------------------------------------------------
    revno: 9827.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 14:59:06 +0200
    message:
      Rename button_character_instance to Button (as suggested in typedef). This
      is a local change, as there is only one user outside the class itself.
      
      Drop const_casts by providing a const and non-const getActiveCharacters().
      Use standard algorithms rather than for-loops.
      
      Fix some errors in documentation, drop unused members.
    modified:
      libcore/button_character_instance.cpp
      libcore/button_character_instance.h
      libcore/parser/button_character_def.cpp
    ------------------------------------------------------------
    revno: 9827.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 15:25:31 +0200
    message:
      Make button definition private and pass by reference not pointer.
    modified:
      libcore/button_character_instance.cpp
      libcore/button_character_instance.h
      libcore/parser/button_character_def.cpp
    ------------------------------------------------------------
    revno: 9827.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2008-09-24 15:33:21 +0200
    message:
      Reduce logging, add documentation.
    modified:
      libcore/button_character_instance.cpp
=== modified file 'libcore/PropertyList.cpp'
--- a/libcore/PropertyList.cpp  2008-09-19 09:50:15 +0000
+++ b/libcore/PropertyList.cpp  2008-09-24 10:32:01 +0000
@@ -161,7 +161,7 @@
 }
 
 bool
-PropertyList::setValue(string_table::key key, as_value val,
+PropertyList::setValue(string_table::key key, const as_value& val,
                as_object& this_ptr, string_table::key nsId,
                const as_prop_flags& flagsIfMissing)
 {

=== modified file 'libcore/PropertyList.h'
--- a/libcore/PropertyList.h    2008-09-19 10:24:02 +0000
+++ b/libcore/PropertyList.h    2008-09-24 10:32:01 +0000
@@ -231,7 +231,7 @@
        /// @return true if the value was successfully set, false
        ///         otherwise (found a read-only property, most likely).
        ///
-       bool setValue(string_table::key key, as_value value,
+       bool setValue(string_table::key key, const as_value& value,
                        as_object& this_ptr, string_table::key namespaceId = 0,
                        const as_prop_flags& flagsIfMissing=0);
 

=== modified file 'libcore/as_object.cpp'
--- a/libcore/as_object.cpp     2008-09-19 10:24:02 +0000
+++ b/libcore/as_object.cpp     2008-09-24 10:32:01 +0000
@@ -606,7 +606,7 @@
        if ( ifFound ) return false;
 
        // Property does not exist, so it won't be read-only. Set it.
-       if (!_members.setValue(key, const_cast<as_value&>(val), *this, nsname))
+       if (!_members.setValue(key, val, *this, nsname))
        {
                IF_VERBOSE_ASCODING_ERRORS(
                        log_aserror(_("Unknown failure in setting property '%s' 
on "
@@ -730,7 +730,7 @@
        }
                
        // Set (or create) a SimpleProperty 
-       if (! _members.setValue(key, const_cast<as_value&>(val), *this, nsname, 
flags) )
+       if (! _members.setValue(key, val, *this, nsname, flags) )
        {
                log_error(_("Attempt to initialize read-only property ``%s''"
                        " on object ``%p'' twice"),
@@ -1498,7 +1498,7 @@
                args->push_back(newval);
                args->push_back(_customArg);
 
-               fn_call fn(const_cast<as_object*>(&this_obj), &env, args);
+               fn_call fn(&this_obj, &env, args);
 
                as_value ret = _func->call(fn);
 

=== modified file 'libcore/asobj/flash/geom/ColorTransform_as.cpp'
--- a/libcore/asobj/flash/geom/ColorTransform_as.cpp    2008-09-22 15:01:31 
+0000
+++ b/libcore/asobj/flash/geom/ColorTransform_as.cpp    2008-09-24 09:05:56 
+0000
@@ -53,17 +53,34 @@
 static void
 attachColorTransformInterface(as_object& o)
 {
-    o.init_member("concat", new builtin_function(ColorTransform_concat));
-    o.init_member("toString", new builtin_function(ColorTransform_toString));
-    o.init_property("alphaMultiplier", ColorTransform_alphaMultiplier_getset, 
ColorTransform_alphaMultiplier_getset);
-    o.init_property("alphaOffset", ColorTransform_alphaOffset_getset, 
ColorTransform_alphaOffset_getset);
-    o.init_property("blueMultiplier", ColorTransform_blueMultiplier_getset, 
ColorTransform_blueMultiplier_getset);
-    o.init_property("blueOffset", ColorTransform_blueOffset_getset, 
ColorTransform_blueOffset_getset);
-    o.init_property("greenMultiplier", ColorTransform_greenMultiplier_getset, 
ColorTransform_greenMultiplier_getset);
-    o.init_property("greenOffset", ColorTransform_greenOffset_getset, 
ColorTransform_greenOffset_getset);
-    o.init_property("redMultiplier", ColorTransform_redMultiplier_getset, 
ColorTransform_redMultiplier_getset);
-    o.init_property("redOffset", ColorTransform_redOffset_getset, 
ColorTransform_redOffset_getset);
-    o.init_property("rgb", ColorTransform_rgb_getset, 
ColorTransform_rgb_getset);
+    int flags = 0;
+    /// This has no flags:
+    o.init_member("concat", new builtin_function(ColorTransform_concat), 
flags);
+
+    flags = as_prop_flags::isProtected;
+
+    /// These are all protected:
+    o.init_member("toString", new builtin_function(ColorTransform_toString),
+            flags);
+
+    o.init_property("alphaMultiplier", ColorTransform_alphaMultiplier_getset,
+            ColorTransform_alphaMultiplier_getset, flags);
+    o.init_property("alphaOffset", ColorTransform_alphaOffset_getset,
+            ColorTransform_alphaOffset_getset, flags);
+    o.init_property("blueMultiplier", ColorTransform_blueMultiplier_getset,
+            ColorTransform_blueMultiplier_getset, flags);
+    o.init_property("blueOffset", ColorTransform_blueOffset_getset,
+            ColorTransform_blueOffset_getset, flags);
+    o.init_property("greenMultiplier", ColorTransform_greenMultiplier_getset,
+            ColorTransform_greenMultiplier_getset, flags);
+    o.init_property("greenOffset", ColorTransform_greenOffset_getset,
+            ColorTransform_greenOffset_getset, flags);
+    o.init_property("redMultiplier", ColorTransform_redMultiplier_getset,
+            ColorTransform_redMultiplier_getset, flags);
+    o.init_property("redOffset", ColorTransform_redOffset_getset,
+            ColorTransform_redOffset_getset, flags);
+    o.init_property("rgb", ColorTransform_rgb_getset,
+            ColorTransform_rgb_getset, flags);
 }
 
 

=== modified file 'libcore/button_character_instance.cpp'
--- a/libcore/button_character_instance.cpp     2008-09-18 09:59:32 +0000
+++ b/libcore/button_character_instance.cpp     2008-09-24 13:33:21 +0000
@@ -1,4 +1,4 @@
-// button_character_instance.cpp:  Mouse-sensitive buttons, for Gnash.
+// Button.cpp:  Mouse-sensitive buttons, for Gnash.
 // 
 //   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 // 
@@ -24,7 +24,6 @@
 #include "smart_ptr.h" // GNASH_USE_GC
 #include "button_character_instance.h"
 #include "button_character_def.h"
-#include "action.h" // for as_standard_member enum
 #include "as_value.h"
 
 #include "ActionExec.h"
@@ -216,19 +215,27 @@
 // Forward declarations
 static as_object* getButtonInterface();
 
-/// A couple of typedefs to make code neater
-typedef button_character_instance Button;
-typedef boost::intrusive_ptr<Button> ButtonPtr;
+/// Predicates for standard algorithms.
 
+/// Depth comparator for characters.
 static bool charDepthLessThen(const character* ch1, const character* ch2) 
 {
        return ch1->get_depth() < ch2->get_depth();
 }
 
+/// Predicate for finding active characters.
+//
+/// Returns true if the character should be skipped:
+/// 1) if it is NULL, or 
+/// 2) if we don't want unloaded characters and the character is unloaded.
+static bool isCharacterNull(character* ch, bool includeUnloaded)
+{
+    return (!ch || (!includeUnloaded && ch->isUnloaded()));
+}
+
 static void
 attachButtonInterface(as_object& o)
 {
-       //int target_version = o.getVM().getSWFVersion();
 
        as_c_function_ptr gettersetter;
 
@@ -278,48 +285,47 @@
        gettersetter = character::name_getset;
        o.init_property(NSV::PROP_uNAME, gettersetter, gettersetter);
        
-       gettersetter = &button_character_instance::enabled_getset;
+       gettersetter = &Button::enabled_getset;
        o.init_property(NSV::PROP_ENABLED, *gettersetter, *gettersetter);
 
 }
 
-button_character_instance::button_character_instance(
-               button_character_definition* def,
+Button::Button(
+               button_character_definition& def,
                character* parent, int id)
        :
        character(parent, id),
-       m_def(def),
        m_last_mouse_flags(IDLE),
        m_mouse_flags(IDLE),
        m_mouse_state(UP),
+       _def(def),
        m_enabled(true)
 {
-       assert(m_def);
 
        set_prototype(getButtonInterface());
 
        // check up presence Key events
-       if ( m_def->hasKeyPressHandler() )
+       if ( _def.hasKeyPressHandler() )
        {
                _vm.getRoot().add_key_listener(this);
        }
 
 }
 
-button_character_instance::~button_character_instance()
+Button::~Button()
 {
        _vm.getRoot().remove_key_listener(this);
 }
 
 
 bool 
-button_character_instance::get_enabled()
+Button::get_enabled()
 {
        return m_enabled;
 }
 
 void 
-button_character_instance::set_enabled(bool value)
+Button::set_enabled(bool value)
 {
        if (value == m_enabled) return;
        m_enabled = value; 
@@ -329,9 +335,9 @@
 
 
 as_value
-button_character_instance::enabled_getset(const fn_call& fn)
+Button::enabled_getset(const fn_call& fn)
 {
-       ButtonPtr ptr = ensureType<Button>(fn.this_ptr);
+       boost::intrusive_ptr<Button> ptr = ensureType<Button>(fn.this_ptr);
 
        as_value rv;
 
@@ -351,7 +357,7 @@
 // called from Key listener only
 // (the above line is wrong, it's also called with onConstruct, for instance)
 bool
-button_character_instance::on_event(const event_id& id)
+Button::on_event(const event_id& id)
 {
        if ( isUnloaded() )
        {
@@ -371,38 +377,36 @@
        if ( id.keyCode == key::INVALID ) return false;
 
        ButtonActionPusher xec(getVM().getRoot(), this); 
-       m_def->forEachTrigger(id, xec);
+       _def.forEachTrigger(id, xec);
 
        return xec.called;
 }
 
 void
-button_character_instance::restart()
+Button::restart()
 {
-       log_error("button_character_instance::restart called, from whom??");
+       log_error("Button::restart called, from whom??");
 }
 
 void
-button_character_instance::display()
+Button::display()
 {
-//     GNASH_REPORT_FUNCTION;
 
        std::vector<character*> actChars;
-       get_active_characters(actChars);
-
-       //log_debug("At display time, button %s got %d currently active chars", 
getTarget(), actChars.size());
+       getActiveCharacters(actChars);
 
        // TODO: by keeping chars sorted by depth we'd avoid the sort on display
        std::sort(actChars.begin(), actChars.end(), charDepthLessThen);
 
-       std::for_each(actChars.begin(), actChars.end(), 
std::mem_fun(&character::display)); 
+       std::for_each(actChars.begin(), actChars.end(),
+            std::mem_fun(&character::display)); 
 
        clear_invalidated();
 }
 
 
 character*
-button_character_instance::get_topmost_mouse_entity(boost::int32_t x, 
boost::int32_t y)
+Button::get_topmost_mouse_entity(boost::int32_t x, boost::int32_t y)
 // Return the topmost entity that the given point covers.  NULL if none.
 // I.e. check against ourself.
 {
@@ -412,12 +416,12 @@
        }
 
        //-------------------------------------------------
-       // Check our active and visible childrens first
+       // Check our active and visible children first
        //-------------------------------------------------
 
        typedef std::vector<character*> Chars;
        Chars actChars;
-       get_active_characters(actChars);
+       getActiveCharacters(actChars);
 
        if ( ! actChars.empty() )
        {
@@ -441,8 +445,7 @@
        //-------------------------------------------------
 
        // Find hit characters
-       const CharsVect& hitChars = getHitCharacters();
-       if ( hitChars.empty() ) return 0;
+       if ( _hitCharacters.empty() ) return 0;
 
        // point is in parent's space,
        // we need to convert it in world space
@@ -453,11 +456,10 @@
                parent->get_world_matrix().transform(wp);
        }
 
-       for (size_t i=0, e=hitChars.size(); i<e; ++i)
+       for (CharsVect::const_iterator i = _hitCharacters.begin(),
+            e = _hitCharacters.end(); i !=e; ++i)
        {
-               const character* ch = hitChars[i];
-
-               if ( ch->pointInVisibleShape(wp.x, wp.y) )
+               if ((*i)->pointInVisibleShape(wp.x, wp.y))
                {
                        // The mouse is inside the shape.
                        return this;
@@ -469,7 +471,7 @@
 
 
 void
-button_character_instance::on_button_event(const event_id& event)
+Button::on_button_event(const event_id& event)
 {
        if ( isUnloaded() )
        {
@@ -480,7 +482,7 @@
                return;
        }
 
-       e_mouse_state new_state = m_mouse_state;
+       MouseState new_state = m_mouse_state;
   
        // Set our mouse state (so we know how to render).
        switch (event.m_id)
@@ -513,7 +515,7 @@
        set_current_state(new_state);
     
        // Button transition sounds.
-       if (m_def->m_sound != NULL)
+       if (_def.m_sound != NULL)
        {
                int bi; // button sound array index [0..3]
                media::sound_handler* s = get_sound_handler();
@@ -540,11 +542,11 @@
                        }
                        if (bi >= 0)
                        {
-                               button_character_definition::button_sound_info& 
bs = m_def->m_sound->m_button_sounds[bi];
+                               button_character_definition::button_sound_info& 
bs = _def.m_sound->m_button_sounds[bi];
                                // character zero is considered as null 
character
                                if (bs.m_sound_id > 0)
                                {
-                                       if 
(m_def->m_sound->m_button_sounds[bi].m_sam != NULL)
+                                       if 
(_def.m_sound->m_button_sounds[bi].m_sam != NULL)
                                        {
                                                if 
(bs.m_sound_style.m_stop_playback)
                                                {
@@ -573,7 +575,7 @@
        movie_root& mr = getVM().getRoot();
 
        ButtonActionPusher xec(mr, this); 
-       m_def->forEachTrigger(event, xec);
+       _def.forEachTrigger(event, xec);
 
        // check for built-in event handler.
        std::auto_ptr<ExecutableCode> code ( get_event_handler(event) );
@@ -596,31 +598,48 @@
        //else log_debug(_("No statically-defined handler for event: %s"), 
event);
 }
 
-void 
-button_character_instance::get_active_characters(std::vector<character*>& 
list, bool includeUnloaded)
-{
-       list.clear();
-       
-       for (size_t i=0,e=m_record_character.size(); i<e; ++i)
-       {
-               character* ch = m_record_character[i];
-               if (ch == NULL) continue;
-               if ( ! includeUnloaded && ch->isUnloaded() ) continue;
-               list.push_back(ch);
-       } 
-}
-
-void 
-button_character_instance::get_active_records(RecSet& list, e_mouse_state 
state)
-{
-       list.clear();
-       
-       size_t nrecs = m_def->m_button_records.size();
-
-       //log_debug("%s.get_active_records(%s) - def has %d records", 
getTarget(), mouseStateName(state), m_def->m_button_records.size());
+
+void
+Button::getActiveCharacters(
+        std::vector<const character*>& list) const
+{
+    list.clear();
+
+    // Copy all the characters to the new list, skipping NULL and unloaded
+    // characters.
+    std::remove_copy_if(_stateCharacters.begin(), _stateCharacters.end(),
+            std::back_inserter(list),
+            boost::bind(&isCharacterNull, _1, false));
+
+}
+
+
+void 
+Button::getActiveCharacters(
+        std::vector<character*>& list, bool includeUnloaded)
+{
+       list.clear();
+
+    // Copy all the characters to the new list, skipping NULL
+    // characters, optionally including unloaded characters.
+    std::remove_copy_if(_stateCharacters.begin(),
+            _stateCharacters.end(),
+            std::back_inserter(list),
+            boost::bind(&isCharacterNull, _1, includeUnloaded));
+       
+}
+
+void 
+Button::get_active_records(RecSet& list, MouseState state)
+{
+       list.clear();
+       
+       size_t nrecs = _def.m_button_records.size();
+
+       //log_debug("%s.get_active_records(%s) - def has %d records", 
getTarget(), mouseStateName(state), _def.m_button_records.size());
        for (size_t i=0; i<nrecs; ++i)
        {
-               button_record&  rec = m_def->m_button_records[i];
+               button_record& rec = _def.m_button_records[i];
                //log_debug(" rec %d has hit:%d down:%d over:%d up:%d", i, 
rec.m_hit_test, rec.m_down, rec.m_over, rec.m_up);
 
                if ((state == UP && rec.m_up)
@@ -643,7 +662,10 @@
                if ( ! ch ) ss << "NULL.";
                else
                {
-                       ss << ch->getTarget() << " (depth:" << 
ch->get_depth()-character::staticDepthOffset-1 << " unloaded:" << 
ch->isUnloaded() << " destroyed:" << ch->isDestroyed() << ")";
+                       ss << ch->getTarget() << " (depth:" << 
+                ch->get_depth()-character::staticDepthOffset-1
+                << " unloaded:" << ch->isUnloaded() <<
+                " destroyed:" << ch->isDestroyed() << ")";
                }
                ss << std::endl;
        }
@@ -651,7 +673,7 @@
 #endif
 
 void
-button_character_instance::set_current_state(e_mouse_state new_state)
+Button::set_current_state(MouseState new_state)
 {
        if (new_state == m_mouse_state)
                return;
@@ -659,7 +681,7 @@
 #ifdef GNASH_DEBUG_BUTTON_DISPLAYLIST
        std::stringstream ss;
        ss << "at set_current_state enter: " << std::endl;
-       dump(m_record_character, ss);
+       dump(_stateCharacters, ss);
        log_debug("%s", ss.str());
 #endif
 
@@ -668,9 +690,9 @@
        get_active_records(newChars, new_state);
 
        // For each possible record, check if it should still be there
-       for (size_t i=0, e=m_record_character.size(); i<e; ++i)
+       for (size_t i=0, e=_stateCharacters.size(); i<e; ++i)
        {
-               character* oldch = m_record_character[i];
+               character* oldch = _stateCharacters[i];
                bool shouldBeThere = ( newChars.find(i) != newChars.end() );
 
                if ( ! shouldBeThere )
@@ -679,7 +701,7 @@
                        if ( oldch && oldch->isUnloaded() )
                        {
                                if ( ! oldch->isDestroyed() ) oldch->destroy();
-                               m_record_character[i] = NULL;
+                               _stateCharacters[i] = NULL;
                                oldch = NULL;
                        }
 
@@ -691,7 +713,7 @@
                                {
                                        // No onUnload handler: destroy and 
clear slot
                                        if ( ! oldch->isDestroyed() ) 
oldch->destroy();
-                                       m_record_character[i] = NULL;
+                                       _stateCharacters[i] = NULL;
                                }
                                else
                                {
@@ -711,14 +733,14 @@
                        if ( oldch && oldch->isUnloaded() )
                        {
                                if ( ! oldch->isDestroyed() ) oldch->destroy();
-                               m_record_character[i] = NULL;
+                               _stateCharacters[i] = NULL;
                                oldch = NULL;
                        }
 
                        if ( ! oldch )
                        {
                                // Not there, instantiate
-                               button_record& bdef = 
m_def->m_button_records[i];
+                               button_record& bdef = _def.m_button_records[i];
 
                                const matrix&   mat = bdef.m_button_matrix;
                                const cxform&   cx = bdef.m_button_cxform;
@@ -740,7 +762,7 @@
 
                                set_invalidated();
 
-                               m_record_character[i] = ch;
+                               _stateCharacters[i] = ch;
                                ch->stagePlacementCallback(); // give this 
character a life
 
                        }
@@ -750,7 +772,7 @@
 #ifdef GNASH_DEBUG_BUTTON_DISPLAYLIST
        ss.str("");
        ss << "at set_current_state end: " << std::endl;
-       dump(m_record_character, ss);
+       dump(_stateCharacters, ss);
        log_debug("%s", ss.str());
 #endif
 
@@ -766,35 +788,32 @@
 
 
 void 
-button_character_instance::add_invalidated_bounds(InvalidatedRanges& ranges, 
+Button::add_invalidated_bounds(InvalidatedRanges& ranges, 
        bool force)
 {
-       if (!m_visible)
-       {
-               //log_debug("button %s not visible on add_invalidated_bounds", 
getTarget());
-               return; // not visible anyway
-       }
-       //log_debug("button %s add_invalidated_bounds called", getTarget());
+
+    // Not visible anyway
+       if (!m_visible) return;
 
        ranges.add(m_old_invalidated_ranges);  
 
        std::vector<character*> actChars;
-       get_active_characters(actChars);
+       getActiveCharacters(actChars);
        std::for_each(actChars.begin(), actChars.end(),
-               boost::bind(&character::add_invalidated_bounds, _1,
-                           boost::ref(ranges), force||m_invalidated)
+            boost::bind(&character::add_invalidated_bounds, _1,
+                boost::ref(ranges), force||m_invalidated)
        );
 }
 
 rect
-button_character_instance::getBounds() const
+Button::getBounds() const
 {
        rect allBounds;
 
-       typedef std::vector<character*> CharVect;
+       typedef std::vector<const character*> CharVect;
        CharVect actChars;
-       
const_cast<button_character_instance*>(this)->get_active_characters(actChars);
-       for(CharVect::iterator i=actChars.begin(),e=actChars.end(); i!=e; ++i)
+       getActiveCharacters(actChars);
+       for(CharVect::const_iterator i=actChars.begin(),e=actChars.end(); i!=e; 
++i)
        {
                const character* ch = *i;
                // Child bounds need be transformed in our coordinate space
@@ -807,12 +826,12 @@
 }
 
 bool
-button_character_instance::pointInShape(boost::int32_t x, boost::int32_t y) 
const
+Button::pointInShape(boost::int32_t x, boost::int32_t y) const
 {
-       typedef std::vector<character*> CharVect;
+       typedef std::vector<const character*> CharVect;
        CharVect actChars;
-       
const_cast<button_character_instance*>(this)->get_active_characters(actChars);
-       for(CharVect::iterator i=actChars.begin(),e=actChars.end(); i!=e; ++i)
+       getActiveCharacters(actChars);
+       for(CharVect::const_iterator i=actChars.begin(),e=actChars.end(); i!=e; 
++i)
        {
                const character* ch = *i;
                if ( ch->pointInShape(x,y) ) return true;
@@ -821,7 +840,7 @@
 }
 
 as_object*
-button_character_instance::get_path_element(string_table::key key)
+Button::get_path_element(string_table::key key)
 {
        as_object* ch = get_path_element_character(key);
        if ( ch ) return ch;
@@ -831,12 +850,11 @@
 }
 
 character *
-button_character_instance::getChildByName(const std::string& name) const
+Button::getChildByName(const std::string& name)
 {
        // Get all currently active characters, including unloaded
        CharsVect actChars;
-       // TODO: fix the const_cast
-       
const_cast<button_character_instance*>(this)->get_active_characters(actChars, 
true);
+       getActiveCharacters(actChars, true);
 
        // Lower depth first for duplicated names, so we sort
        std::sort(actChars.begin(), actChars.end(), charDepthLessThen);
@@ -862,7 +880,7 @@
 }
 
 void
-button_character_instance::stagePlacementCallback()
+Button::stagePlacementCallback()
 {
        saveOriginalTarget(); // for soft refs
 
@@ -875,7 +893,7 @@
        get_active_records(hitChars, HIT);
        for (RecSet::iterator i=hitChars.begin(),e=hitChars.end(); i!=e; ++i)
        {
-               button_record& bdef = m_def->m_button_records[*i];
+               button_record& bdef = _def.m_button_records[*i];
 
                const matrix& mat = bdef.m_button_matrix;
                const cxform& cx = bdef.m_button_cxform;
@@ -897,7 +915,7 @@
        // Some slots will probably be never used (consider HIT-only records)
        // but for now this direct corrispondence between record number
        // and active character will be handy.
-       m_record_character.resize(m_def->m_button_records.size());
+       _stateCharacters.resize(_def.m_button_records.size());
 
        // Instantiate the default state characters 
        RecSet upChars;
@@ -906,7 +924,7 @@
        for (RecSet::iterator i=upChars.begin(),e=upChars.end(); i!=e; ++i)
        {
                int rno = *i;
-               button_record& bdef = m_def->m_button_records[rno];
+               button_record& bdef = _def.m_button_records[rno];
 
                const matrix&   mat = bdef.m_button_matrix;
                const cxform&   cx = bdef.m_button_cxform;
@@ -926,7 +944,7 @@
                        ch->set_name(getNextUnnamedInstanceName());
                }
 
-               m_record_character[rno] = ch;
+               _stateCharacters[rno] = ch;
                ch->stagePlacementCallback(); // give this character a life
        }
 
@@ -935,14 +953,14 @@
 
 #ifdef GNASH_USE_GC
 void
-button_character_instance::markReachableResources() const
+Button::markReachableResources() const
 {
        assert(isReachable());
 
-       m_def->setReachable();
+       _def.setReachable();
 
        // Mark state characters as reachable
-       for (CharsVect::const_iterator i=m_record_character.begin(), 
e=m_record_character.end();
+       for (CharsVect::const_iterator i=_stateCharacters.begin(), 
e=_stateCharacters.end();
                        i!=e; ++i)
        {
                character* ch = *i;
@@ -964,15 +982,14 @@
 #endif // GNASH_USE_GC
 
 bool
-button_character_instance::unload()
+Button::unload()
 {
-       //log_debug("Button %s being unloaded", getTarget());
 
        bool childsHaveUnload = false;
 
        // We need to unload all childs, or the global instance list will keep 
growing forever !
-       //std::for_each(m_record_character.begin(), m_record_character.end(), 
boost::bind(&character::unload, _1));
-       for (CharsVect::iterator i=m_record_character.begin(), 
e=m_record_character.end(); i!=e; ++i)
+       //std::for_each(_stateCharacters.begin(), _stateCharacters.end(), 
boost::bind(&character::unload, _1));
+       for (CharsVect::iterator i=_stateCharacters.begin(), 
e=_stateCharacters.end(); i!=e; ++i)
        {
                character* ch = *i;
                if ( ! ch ) continue;
@@ -995,11 +1012,11 @@
 }
 
 void
-button_character_instance::destroy()
+Button::destroy()
 {
        //log_debug("Button %s being destroyed", getTarget());
 
-       for (CharsVect::iterator i=m_record_character.begin(), 
e=m_record_character.end(); i!=e; ++i)
+       for (CharsVect::iterator i=_stateCharacters.begin(), 
e=_stateCharacters.end(); i!=e; ++i)
        {
                character* ch = *i;
                if ( ! ch ) continue;
@@ -1020,7 +1037,7 @@
 }
 
 bool
-button_character_instance::get_member(string_table::key name_key, as_value* 
val,
+Button::get_member(string_table::key name_key, as_value* val,
   string_table::key nsname)
 {
   // FIXME: use addProperty interface for these !!
@@ -1119,9 +1136,9 @@
 }
 
 int
-button_character_instance::getSWFVersion() const
+Button::getSWFVersion() const
 {
-       return m_def->getSWFVersion();
+       return _def.getSWFVersion();
 }
 
 static as_object*
@@ -1163,13 +1180,13 @@
 
 #ifdef USE_SWFTREE
 character::InfoTree::iterator 
-button_character_instance::getMovieInfo(InfoTree& tr, InfoTree::iterator it)
+Button::getMovieInfo(InfoTree& tr, InfoTree::iterator it)
 {
        InfoTree::iterator selfIt = character::getMovieInfo(tr, it);
        std::ostringstream os;
 
        std::vector<character*> actChars;
-       get_active_characters(actChars, true);
+       getActiveCharacters(actChars, true);
        std::sort(actChars.begin(), actChars.end(), charDepthLessThen);
 
        os << actChars.size() << " active characters for state " << 
mouseStateName(m_mouse_state);
@@ -1182,7 +1199,7 @@
 #endif
 
 const char*
-button_character_instance::mouseStateName(e_mouse_state s)
+Button::mouseStateName(MouseState s)
 {
        switch (s)
        {

=== modified file 'libcore/button_character_instance.h'
--- a/libcore/button_character_instance.h       2008-07-04 10:00:28 +0000
+++ b/libcore/button_character_instance.h       2008-09-24 13:25:31 +0000
@@ -19,8 +19,8 @@
 // SWF buttons.  Mouse-sensitive update/display, actions, etc.
 
 
-#ifndef GNASH_BUTTON_CHARACTER_INSTANCE_H
-#define GNASH_BUTTON_CHARACTER_INSTANCE_H
+#ifndef GNASH_BUTTON_H
+#define GNASH_BUTTON_H
 
 #include "smart_ptr.h" // GNASH_USE_GC
 #include "character.h" // for inheritance
@@ -39,13 +39,12 @@
 //
 
 //
-// button_character_instance
+// Button
 //
 
-class button_character_instance : public character
+class Button : public character
 {
 public:
-       button_character_definition*    m_def;
 
        typedef std::vector< character* > CharsVect;
        typedef std::set<int> RecSet;
@@ -63,7 +62,7 @@
        };
        int     m_last_mouse_flags, m_mouse_flags;
 
-       enum e_mouse_state
+       enum MouseState
        {
                UP = 0,
                DOWN,
@@ -71,14 +70,14 @@
                HIT
        };
 
-       static const char* mouseStateName(e_mouse_state s);
-
-       e_mouse_state m_mouse_state;
-
-       button_character_instance(button_character_definition* def,
+       static const char* mouseStateName(MouseState s);
+
+       MouseState m_mouse_state;
+
+       Button(button_character_definition& def,
                        character* parent, int id);
 
-       ~button_character_instance();
+       ~Button();
 
        // See dox in as_object.h
        bool get_member(string_table::key name, as_value* val, 
@@ -89,19 +88,11 @@
        // called from keypress listener only
        bool on_event(const event_id& id);
 
-       void    restart();
+       void restart();
 
-       void    display();
+       void display();
        
-       void set_current_state(e_mouse_state new_state);
-
-       /// Combine the flags to avoid a conditional.
-       //  It would be faster with a macro.
-       inline int      transition(int a, int b) const
-       {
-               return (a << 2) | b;
-       }
-
+       void set_current_state(MouseState new_state);
 
        /// \brief
        /// Return the topmost entity that the given point covers. 
@@ -119,7 +110,7 @@
        /// Overridden to look in button records for a match
        virtual as_object* get_path_element(string_table::key key);
 
-       virtual void    on_button_event(const event_id& event);
+       virtual void on_button_event(const event_id& event);
 
        //
        // ActionScript overrides
@@ -164,15 +155,17 @@
        //
        /// These are:
        ///     - this char's definition (m_def)
-       ///     - the vector of state characters (m_record_character)
-       ///     - the vector of hit characters (m_record_character)
+       ///     - the vector of state characters (_stateCharacters)
+       ///     - the vector of hit characters (_hitCharacters)
        ///
        void markReachableResources() const;
 #endif // GNASH_USE_GC
 
 private:
 
-       CharsVect m_record_character;
+       button_character_definition& _def;
+
+       CharsVect _stateCharacters;
 
        CharsVect _hitCharacters;
 
@@ -181,12 +174,21 @@
        /// The "_visible" property does not matter here. 
        ///
        /// @param list
-       ///     The vector to push active characters into
+       ///     The container to push active characters into
        ///
        /// @param includeUnloaded
        ///     If true, include unloaded but still reachable chars in the 
records slot.
        ///
-       void get_active_characters(std::vector<character*>& list, bool 
includeUnloaded=false);
+       void getActiveCharacters(std::vector<character*>& list,
+                       bool includeUnloaded=false);
+
+    /// Returns all characters that are active based on the current state.
+    //
+    /// This is a const method because the returned characters cannot be
+    /// modified.
+    ///
+    /// @param list     The container to push unmodifiable characters into.
+       void getActiveCharacters(std::vector<const character*>& list) const;
 
        /// Returns all characters (record nums) that should be active on the 
given state.
        //
@@ -196,13 +198,7 @@
        /// @param state
        ///     The state we're interested in
        ///
-       void get_active_records(RecSet& list, e_mouse_state state);
-
-       const CharsVect& getHitCharacters() const
-       {
-               return _hitCharacters;
-       }
-
+       void get_active_records(RecSet& list, MouseState state);
 
        /// Return any state character whose name matches the given string
        //
@@ -212,12 +208,12 @@
        ///     Name to match, search is case sensitive for SWF7 and higher,
        ///     case insensitive up to SWF6.
        ///
-       character * getChildByName(const std::string& name) const;
+       character * getChildByName(const std::string& name);
 
        /// \brief
        /// Return version of the SWF containing
        /// the button definition this is an instance of.
-        int getSWFVersion() const;
+    int getSWFVersion() const;
 
        bool m_enabled;
 
@@ -229,7 +225,7 @@
 }      // end namespace gnash
 
 
-#endif // GNASH_BUTTON_CHARACTER_INSTANCE_H
+#endif // GNASH_Button_H
 
 
 // Local Variables:

=== modified file 'libcore/parser/button_character_def.cpp'
--- a/libcore/parser/button_character_def.cpp   2008-09-04 15:32:42 +0000
+++ b/libcore/parser/button_character_def.cpp   2008-09-24 13:25:31 +0000
@@ -510,7 +510,7 @@
 button_character_definition::create_character_instance(
                character* parent, int id)
 {
-       character* ch = new button_character_instance(this, parent, id);
+       character* ch = new Button(*this, parent, id);
        return ch;
 }
 

=== modified file 'libcore/sprite_instance.h'
--- a/libcore/sprite_instance.h 2008-09-03 15:21:15 +0000
+++ b/libcore/sprite_instance.h 2008-09-24 12:58:50 +0000
@@ -224,14 +224,6 @@
         return m_has_looped;
     }
 
-    /// Combine the flags to avoid a conditional.
-    /// It would be faster with a macro.
-    inline int transition(int a, int b) const
-    {
-        return (a << 2) | b;
-    }
-
-
     /// Return true if we have any mouse event handlers.
     //
     /// NOTE: this function currently does not consider


reply via email to

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