gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...
Date: Wed, 20 Dec 2006 15:56:02 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/12/20 15:56:02

Modified files:
        .              : ChangeLog 
        server         : as_value.cpp as_value.h 
        server/vm      : ASHandlers.cpp 

Log message:
                * server/as_value.{cpp,h}: add MOVIECLIP primitive type.
                * server/vm/ASHandlers.cpp (ActionTypeOf):
                  do the right thing for MOVIECLIP values.
        
        ( All current tests run successfully again with this patch )

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1979&r2=1.1980
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.h?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.20&r2=1.21

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1979
retrieving revision 1.1980
diff -u -b -r1.1979 -r1.1980
--- ChangeLog   20 Dec 2006 14:50:35 -0000      1.1979
+++ ChangeLog   20 Dec 2006 15:56:02 -0000      1.1980
@@ -1,5 +1,11 @@
 2006-12-20 Sandro Santilli <address@hidden>
 
+       * server/as_value.{cpp,h}: add MOVIECLIP primitive type.
+       * server/vm/ASHandlers.cpp (ActionTypeOf):
+         do the right thing for MOVIECLIP values.
+
+2006-12-20 Sandro Santilli <address@hidden>
+
        * server/sprite_instance.cpp (sprite_swap_depths):
          Use as_value::is_object() rather then comparing get_type().
          This helps when as_value will support MOVIECLIP types.

Index: server/as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- server/as_value.cpp 12 Dec 2006 17:00:30 -0000      1.13
+++ server/as_value.cpp 20 Dec 2006 15:56:02 -0000      1.14
@@ -23,6 +23,10 @@
 #include "as_value.h"
 #include "as_object.h"
 #include "as_function.h" // for as_function
+#include "sprite_instance.h" // for MOVIECLIP values
+#include "as_environment.h" // for MOVIECLIP values
+#include "VM.h" // for MOVIECLIP values
+#include "movie_root.h" // for MOVIECLIP values
 
 using namespace std;
 
@@ -42,9 +46,21 @@
     m_type(OBJECT),
     m_object_value(obj)
 {
-    if (m_object_value)        {
+       if (m_object_value)
+       {
+               sprite_instance* sp = m_object_value->to_movie();
+               if ( sp && 0)
+               {
+                       m_type = MOVIECLIP;
+                       // TODO: simplify next statement when m_string_value
+                       //       will become a std::string
+                       m_string_value = sp->get_text_value();
+               }
+               else
+               {
        m_object_value->add_ref();
     }
+       }
 }
 
 
@@ -92,6 +108,7 @@
        {
 
                case STRING:
+               case MOVIECLIP:
                        /* don't need to do anything */
                        break;
 
@@ -332,11 +349,42 @@
     } else if (m_type == AS_FUNCTION) {
        // An AS_FUNCTION *is* an object
        return m_as_function_value;
+    } else if (m_type == MOVIECLIP) {
+       return to_sprite();
     } else {
        return NULL;
     }
 }
 
+sprite_instance*
+as_value::to_sprite() const
+{
+       // Evaluate target everytime an attempt is made 
+       // to fetch a movieclip value.
+       sprite_instance* root = VM::get().getRoot().get_root_movie();
+       as_environment& env = root->get_environment();
+       // TODO: simplify next statement when m_string_value will become a 
std::string
+       character* target = 
env.find_target(std::string(m_string_value.c_str()));
+       return target->to_movie();
+}
+
+void
+as_value::set_sprite(const sprite_instance& sprite)
+{
+       drop_refs();
+       m_type = MOVIECLIP;
+       // TODO: simplify next statement when m_string_value will become a 
std::string
+       m_string_value = sprite.get_text_value();
+}
+
+void
+as_value::set_sprite(const std::string& path)
+{
+       drop_refs();
+       m_type = MOVIECLIP;
+       // TODO: simplify next statement when m_string_value will become a 
std::string
+       m_string_value = path.c_str();
+}
 
 as_c_function_ptr
 as_value::to_c_function() const
@@ -390,12 +438,26 @@
 
 
 void
-as_value::set_as_object(as_object* obj) {
-    if (m_type != OBJECT || m_object_value != obj) {
+as_value::set_as_object(as_object* obj)
+{
+       if ( ! obj )
+       {
+               set_null();
+               return;
+       }
+       sprite_instance* sp = obj->to_movie();
+       if ( sp )
+       {
+               set_sprite(*sp);
+               return;
+       }
+       if (m_type != OBJECT || m_object_value != obj)
+       {
        drop_refs();
        m_type = OBJECT;
        m_object_value = obj;
-       if (m_object_value) {
+               if (m_object_value)
+               {
            m_object_value->add_ref();
        }
     }

Index: server/as_value.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/as_value.h   12 Dec 2006 16:58:31 -0000      1.19
+++ server/as_value.h   20 Dec 2006 15:56:02 -0000      1.20
@@ -17,7 +17,7 @@
 // 
 //
 
-/* $Id: as_value.h,v 1.19 2006/12/12 16:58:31 strk Exp $ */
+/* $Id: as_value.h,v 1.20 2006/12/20 15:56:02 strk Exp $ */
 
 #ifndef GNASH_AS_VALUE_H
 #define GNASH_AS_VALUE_H
@@ -38,6 +38,7 @@
 class as_object;
 class fn_call;
 class as_function;
+class sprite_instance;
 
 #ifndef HAVE_ISFINITE
 # ifndef isfinite 
@@ -97,13 +98,19 @@
                C_FUNCTION,
 
                /// ActionScript function reference
-               AS_FUNCTION
+               AS_FUNCTION,
+
+               /// MovieClip reference
+               MOVIECLIP
        };
 
+       // TODO: make private
        type    m_type;
 
+       // TODO: make private, switch to std::string
        mutable tu_string       m_string_value;
 
+       // TODO: make private
        union
        {
                bool m_boolean_value;
@@ -238,6 +245,11 @@
        ///
        void    drop_refs();
 
+       // TODO: make private. The rationale is that callers of this functions
+       //       should use is_WHAT() instead, or changes in the available
+       //       primitive value types will require modifications in all 
callers.
+       //       This happened when adding MOVIECLIP.
+       //
        type    get_type() const { return m_type; }
 
        /// \brief
@@ -250,10 +262,10 @@
 
        /// \brief
        /// Return true if this value is an object
-       /// (OBJECT or AS_FUNCTION).
+       /// (OBJECT, AS_FUNCTION or MOVIECLIP).
        bool is_object() const
        {
-               return m_type == OBJECT || m_type == AS_FUNCTION;
+               return m_type == OBJECT || m_type == AS_FUNCTION || m_type == 
MOVIECLIP;
        }
 
        /// Get a C string representation of this value.
@@ -294,6 +306,19 @@
        /// or NULL if this is not possible.
        as_object*      to_object() const;
 
+       /// Return value as a sprite or NULL if this is not possible.
+       //
+       /// If the value is a MOVIECLIP value, the stored sprite target
+       /// is evaluated using the root movie's environment
+       /// (see gnash::as_environment::find_target). If the target
+       /// points to something that doesn't cast to a sprite,
+       /// NULL is returned.
+       ///
+       /// Note that if the value is NOT a MOVIECLIP, NULL is always
+       /// returned.
+       ///
+       sprite_instance* to_sprite() const;
+
        /// \brief
        /// Return value as a C function ptr
        /// or NULL if it is not a C function.
@@ -327,6 +352,8 @@
        void    set_string(const char* str) { drop_refs(); m_type = STRING; 
m_string_value = str; }
        void    set_double(double val) { drop_refs(); m_type = NUMBER; 
m_number_value = val; }
        void    set_bool(bool val) { drop_refs(); m_type = BOOLEAN; 
m_boolean_value = val; }
+       void    set_sprite(const std::string& path);
+       void    set_sprite(const sprite_instance& sp);
        void    set_int(int val) { set_double(val); }
        void    set_nan() { double x = 0.0; set_double(x/x); }
 
@@ -352,8 +379,13 @@
                else if (v.m_type == STRING) set_tu_string(v.m_string_value);
                else if (v.m_type == NUMBER) set_double(v.m_number_value);
                else if (v.m_type == OBJECT) set_as_object(v.m_object_value);
+
+               //TODO: don't use c_str() when m_string_value will be a 
std::string
+               else if (v.m_type == MOVIECLIP) 
set_sprite(v.m_string_value.c_str());
+
                else if (v.m_type == C_FUNCTION) 
set_as_c_function_ptr(v.m_c_function_value);
                else if (v.m_type == AS_FUNCTION) 
set_as_function(v.m_as_function_value);
+               else assert(0);
        }
 
        bool    is_nan() const { return (m_type == NUMBER && 
isnan(m_number_value)); }

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- server/vm/ASHandlers.cpp    19 Dec 2006 18:00:12 -0000      1.20
+++ server/vm/ASHandlers.cpp    20 Dec 2006 15:56:02 -0000      1.21
@@ -16,7 +16,7 @@
 
 //
 
-/* $Id: ASHandlers.cpp,v 1.20 2006/12/19 18:00:12 strk Exp $ */
+/* $Id: ASHandlers.cpp,v 1.21 2006/12/20 15:56:02 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -2339,6 +2339,8 @@
 
     ensure_stack(env, 1); 
 
+    // TODO: delegate this work to as_value directly !
+
     switch(env.top(0).get_type()) {
       case as_value::UNDEFINED:
           env.top(0).set_string("undefined");
@@ -2353,12 +2355,11 @@
           env.top(0).set_string("boolean");
           break;
       case as_value::OBJECT:
-         // Should we have as_object expose a typeOf() method ?
-          if ( dynamic_cast<sprite_instance*>(env.top(0).to_object()) )
-              env.top(0).set_string("movieclip");
-         else
               env.top(0).set_string("object");
           break;
+      case as_value::MOVIECLIP:
+          env.top(0).set_string("movieclip");
+         break;
       case as_value::NULLTYPE:
           env.top(0).set_string("null");
           break;




reply via email to

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