gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libbase/utility.h server/charac...


From: Zou Lunkai
Subject: [Gnash-commit] gnash ChangeLog libbase/utility.h server/charac...
Date: Fri, 13 Jun 2008 09:13:06 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Zou Lunkai <zoulunkai>  08/06/13 09:13:06

Modified files:
        .              : ChangeLog 
        libbase        : utility.h 
        server         : character.cpp matrix.cpp matrix.h 
                         sprite_instance.cpp types.h 

Log message:
                * libbase/utility.h,
                  server/types.h:  make sure truncation is used when convert 
float to integer.
                * server/matrix.{h,cpp} : use double instead of float for 
ActionScripts, use
                  integers for x_translation and y_translation. Add a template 
function transform(point2d),
                  since renderer agg and ogl use different point formats.
                * server/character.cpp, server/sprite_instance.cpp: take care 
of data types, minor cleanups.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6915&r2=1.6916
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/utility.h?cvsroot=gnash&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/gnash/server/character.cpp?cvsroot=gnash&r1=1.103&r2=1.104
http://cvs.savannah.gnu.org/viewcvs/gnash/server/matrix.cpp?cvsroot=gnash&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/gnash/server/matrix.h?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.cpp?cvsroot=gnash&r1=1.551&r2=1.552
http://cvs.savannah.gnu.org/viewcvs/gnash/server/types.h?cvsroot=gnash&r1=1.25&r2=1.26

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6915
retrieving revision 1.6916
diff -u -b -r1.6915 -r1.6916
--- ChangeLog   12 Jun 2008 19:49:35 -0000      1.6915
+++ ChangeLog   13 Jun 2008 09:13:04 -0000      1.6916
@@ -1,3 +1,12 @@
+2008-06-12 Zou Lunkai <address@hidden>
+       
+       * libbase/utility.h,
+         server/types.h:  make sure truncation is used when convert float to 
integer.
+       * server/matrix.{h,cpp} : use double instead of float for 
ActionScripts, use
+         integers for x_translation and y_translation. Add a template function 
transform(point2d),
+         since renderer agg and ogl use different point formats.
+       * server/character.cpp, server/sprite_instance.cpp: take care of data 
types, minor cleanups.
+       
 2008-06-12 Sandro Santilli <address@hidden>
 
        * libbase/Buffer.h, SimpleBuffer.h, Makefile.am,

Index: libbase/utility.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/utility.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- libbase/utility.h   12 Jun 2008 03:13:41 -0000      1.59
+++ libbase/utility.h   13 Jun 2008 09:13:05 -0000      1.60
@@ -107,11 +107,17 @@
 #endif
 }
 
+// TODO: deprecate this.
 inline float infinite_to_fzero(float x)
 {
     return utility::isFinite(x) ? x : 0.0f;
 }
 
+inline double infinite_to_zero(double x)
+{
+    return utility::isFinite(x) ? x : 0.0;
+}
+
 inline int iabs(int i)
 {
     return (i < 0) ? -i : i;
@@ -137,20 +143,20 @@
 
 inline boost::int32_t Fixed16Mul(boost::int32_t a, boost::int32_t b)
 {
-    // There might be overflows, but we don't care in our specific case.
+    // truncate when overflow occurs.
     return (boost::int32_t)((boost::int64_t)a * (boost::int64_t)b >> 16);
 }
 
 inline boost::int32_t FloatToFixed16(float a)
 {
-    // There might be overflows, but we don't care in our specific case.
-    return (boost::int32_t)(a * 65536.0f);
+    // truncate when overflow occurs.
+    return (boost::int32_t)(boost::uint32_t)(a * 65536.0f);
 }
 
 inline boost::int32_t DoubleToFixed16(double a)
 {
-    // There might be overflows, but we don't care in our specific case.
-    return (boost::int32_t)(a * 65536.0);
+    // truncate when overflow occurs.
+    return (boost::int32_t)(boost::uint32_t)(a * 65536.0);
 }
 
 }

Index: server/character.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/character.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -b -r1.103 -r1.104
--- server/character.cpp        12 Jun 2008 03:13:41 -0000      1.103
+++ server/character.cpp        13 Jun 2008 09:13:05 -0000      1.104
@@ -242,7 +242,7 @@
        {
                const double newx = fn.arg(0).to_number();
                matrix m = ptr->get_matrix();
-               
m.set_x_translation(std::floor(utility::infinite_to_fzero(PIXELS_TO_TWIPS(newx))));
+        m.set_x_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newx)));
                ptr->set_matrix(m);
                ptr->transformedByScript(); // m_accept_anim_moves = false; 
        }
@@ -265,7 +265,7 @@
        {
                const double newy = fn.arg(0).to_number();
                matrix m = ptr->get_matrix();
-               
m.set_y_translation(std::floor(utility::infinite_to_fzero(PIXELS_TO_TWIPS(newy))));
+               
m.set_y_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newy)));
                ptr->set_matrix(m);
                ptr->transformedByScript(); // m_accept_anim_moves = false; 
        }
@@ -282,7 +282,7 @@
        if ( fn.nargs == 0 ) // getter
        {
                matrix m = ptr->get_matrix();
-               const float xscale = m.get_x_scale();
+               const double xscale = m.get_x_scale();
                rv = as_value(xscale * 100); // result in percent
        }
        else // setter
@@ -302,7 +302,7 @@
                }
 
                // input is in percent
-               float scale = static_cast<float>(scale_percent) / 100.f;
+               double scale = scale_percent / 100.0;
                ptr->set_x_scale(scale);
        }
        return rv;
@@ -384,7 +384,7 @@
        as_value rv;
        if ( fn.nargs == 0 ) // getter
        {
-               rv = as_value(ptr->get_cxform().aa / 2.56f);
+               rv = as_value(ptr->get_cxform().aa / 2.56);
        }
        else // setter
        {

Index: server/matrix.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/matrix.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- server/matrix.cpp   12 Jun 2008 03:07:54 -0000      1.36
+++ server/matrix.cpp   13 Jun 2008 09:13:05 -0000      1.37
@@ -114,9 +114,8 @@
     *this = t;
 }
 
-
 void
-matrix::concatenate_translation(float xoffset, float yoffset)
+matrix::concatenate_translation(int xoffset, int yoffset)
 // Concatenate a translation onto the front of our
 // matrix.  When transforming points, the translation
 // happens first, then our original xform.
@@ -125,16 +124,15 @@
     ty += Fixed16Mul(shx, xoffset) + Fixed16Mul(sy, yoffset);
 }
 
-
 void
-matrix::concatenate_scale(float xscale, float yscale)
+matrix::concatenate_scale(double xscale, double yscale)
 // Concatenate scales to our matrix. When transforming points, these 
 // scales happen first, then our matirx.
 {
-    sx  = Fixed16Mul(sx, FloatToFixed16(xscale));
-    shy = Fixed16Mul(shy,FloatToFixed16(yscale));
-    shx = Fixed16Mul(shx,FloatToFixed16(xscale));
-    sy  = Fixed16Mul(sy, FloatToFixed16(yscale));
+    sx  = Fixed16Mul(sx, DoubleToFixed16(xscale));
+    shy = Fixed16Mul(shy,DoubleToFixed16(yscale));
+    shx = Fixed16Mul(shx,DoubleToFixed16(xscale));
+    sy  = Fixed16Mul(sy, DoubleToFixed16(yscale)); 
 }
 
 void
@@ -150,9 +148,8 @@
     ty = flerp(m1.ty, m2.ty, t);
 }
 
-
 void
-matrix::set_scale_rotation(float x_scale, float y_scale, float angle)
+matrix::set_scale_rotation(double x_scale, double y_scale, double angle)
 // Set the scale & rotation part of the matrix.
 // angle in radians.
 {
@@ -165,52 +162,41 @@
 }
 
 void
-matrix::set_x_scale(float xscale)
+matrix::set_x_scale(double xscale)
 {
-    float angle = get_rotation();
-    float cos_v = cosf(angle);
-    float sin_v = sinf(angle);
-    sx  =  FloatToFixed16(xscale * cos_v);
-    shx =  FloatToFixed16(xscale * sin_v);
+    double angle = get_rotation();
+    double cos_v = cos(angle);
+    double sin_v = sin(angle);
+    sx  =  DoubleToFixed16(xscale * cos_v);
+    shx =  DoubleToFixed16(xscale * sin_v); 
 }
 
 void
-matrix::set_y_scale(float yscale)
+matrix::set_y_scale(double yscale)
 {
-    float angle = get_rotation();
-    float cos_v = cosf(angle);
-    float sin_v = sinf(angle);
-    shy =  - FloatToFixed16(yscale * sin_v);
-    sy  =  FloatToFixed16(yscale * cos_v);
+    double angle = get_rotation();
+    double cos_v = cos(angle);
+    double sin_v = sin(angle);
+    shy =  - DoubleToFixed16(yscale * sin_v);
+    sy  =  DoubleToFixed16(yscale * cos_v); 
 }
 
 void
-matrix::set_scale(float xscale, float yscale)
+matrix::set_scale(double xscale, double yscale)
 {
-    float rotation = get_rotation();
+    double rotation = get_rotation();
     set_scale_rotation(xscale, yscale, rotation);
 }
 
 void
-matrix::set_rotation(float rotation)
+matrix::set_rotation(double rotation)
 {   
-    float xscale = get_x_scale();
-    float yscale = get_y_scale();
+    double xscale = get_x_scale();
+    double yscale = get_y_scale();
     set_scale_rotation(xscale, yscale, rotation);
 }
 
 void
-matrix::transform(point &p) const
-{
-    //boost::int32_t x = Fixed16Mul(sx,  p.x) + Fixed16Mul(shy, p.y) + tx;
-    //boost::int32_t y = Fixed16Mul(shx, p.x) + Fixed16Mul(sy,  p.y) + ty;
-    float x = sx / 65536.0f * p.x + shy/ 65536.0f * p.y + tx;
-    float y = shx/ 65536.0f * p.x + sy / 65536.0f * p.y + ty;
-    p.x = x;
-    p.y = y;
-}
-
-void
 matrix::transform(point* result, const point& p) const
 // Transform point 'p' by our matrix.  Put the result in *result.
 {
@@ -285,29 +271,29 @@
     return (boost::int64_t)sx * sy - (boost::int64_t)shx * shy;
 }
 
-float
+double
 matrix::get_x_scale() const
 {
-    return sqrtf(((float)sx * sx + (float)shx * shx)) / 65536.0f;
+    return sqrt(((double)sx * sx + (double)shx * shx)) / 65536.0;
 }
 
-float
+double
 matrix::get_y_scale() const
 {
-    return sqrtf(((float)sy * sy + (float)shy * shy)) / 65536.0f;
+    return sqrt(((double)sy * sy + (double)shy * shy)) / 65536.0;
 }
 
-float
+double
 matrix::get_rotation() const
 {
     if (determinant() < 0)
     {
         // TODO: check this.
-        return atan2f(shx, -sx);
+        return atan2(shx, -sx);
     }
     else
     {
-        return atan2f(shx, sx);
+        return atan2(shx, sx);
     }
 }
 

Index: server/matrix.h
===================================================================
RCS file: /sources/gnash/gnash/server/matrix.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/matrix.h     12 Jun 2008 03:07:54 -0000      1.26
+++ server/matrix.h     13 Jun 2008 09:13:05 -0000      1.27
@@ -83,47 +83,47 @@
     /// When transforming points, the translation
     /// happens first, then our original xform.
     ///
-    void    concatenate_translation(float tx, float ty);
+    void    concatenate_translation(int tx, int ty);
 
     /// Concatenate scale x and y to the front of our matrix 
     //
     /// When transforming points, these scales happen first, then
     /// our original matrix. 
     /// 
-    void    concatenate_scale(float x, float y);
+    void    concatenate_scale(double x, double y);
 
     /// Set this matrix to a blend of m1 and m2, parameterized by t.
     void    set_lerp(const matrix& m1, const matrix& m2, float t);
 
     /// Set the scale & rotation part of the matrix. angle in radians.
-    void    set_scale_rotation(float x_scale, float y_scale, float rotation);
+    void    set_scale_rotation(double x_scale, double y_scale, double 
rotation);
 
     /// Set x and y scales, rotation is unchanged.
-    void    set_scale(float x_scale, float y_scale);
+    void    set_scale(double x_scale, double y_scale);
 
     /// Set x scale, rotation any y scale are unchanged.
-    void    set_x_scale(float scale);
+    void    set_x_scale(double scale);
 
     /// Set y scale, rotation and x scale are unchanged.
-    void    set_y_scale(float scale);
+    void    set_y_scale(double scale);
 
     /// Set rotation in radians, scales component are unchanged.
-    void    set_rotation(float rotation);
+    void    set_rotation(double rotation);
 
     /// Set x translation in TWIPS
-    void set_x_translation(float x)
+    void set_x_translation(int x)
     {
         tx = x;
     }
 
     /// Set y translation in TWIPS.
-    void set_y_translation(float y)
+    void set_y_translation(int y)
     {
         ty = y;
     }
 
     /// Set x and y translation in TWIPS.
-    void set_translation(float x, float y)
+    void set_translation(int x, int y)
     {
         tx = x;
         ty = y;
@@ -136,7 +136,14 @@
     void    read(SWFStream* in) { read(*in); }
 
     /// Transform a given point by our matrix
-    void    transform(point &p) const;
+    template <typename U>
+    void    transform(geometry::Point2d<U>& p) const
+    {
+        float x = sx / 65536.0f * p.x + shy/ 65536.0f * p.y + tx;
+        float y = shx/ 65536.0f * p.x + sy / 65536.0f * p.y + ty;
+        p.x = x;
+        p.y = y;
+    }
     
     /// Transform point 'p' by our matrix. 
     //
@@ -154,22 +161,22 @@
     const matrix& invert();
     
     /// return the magnitude scale of our x coord output
-    float   get_x_scale() const;
+    double   get_x_scale() const;
 
     /// return the magnitude scale of our y coord output
-    float   get_y_scale() const;
+    double   get_y_scale() const;
 
     /// return rotation component in radians.
-    float   get_rotation() const;
+    double   get_rotation() const;
 
     /// return x translation n TWIPS unit.
-    float   get_x_translation() const
+    int   get_x_translation() const
     {
         return tx;
     }
 
     /// return y translation in TWIPS unit.
-    float   get_y_translation() const
+    int   get_y_translation() const
     {
         return ty;
     }

Index: server/sprite_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.cpp,v
retrieving revision 1.551
retrieving revision 1.552
diff -u -b -r1.551 -r1.552
--- server/sprite_instance.cpp  12 Jun 2008 03:13:42 -0000      1.551
+++ server/sprite_instance.cpp  13 Jun 2008 09:13:05 -0000      1.552
@@ -1079,13 +1079,8 @@
   matrix world_mat = sprite->get_world_matrix();
   world_mat.invert().transform(pt);
 
-  // These used to be: round(pt.x), which would round negative
-  // half-values away from zero (-0.5 - > -1), whereas
-  // std::floor(x + 0.5) always rounds towards +Infinity (-0.5 -> 0).
-  // All other cases should be the same. The testsuite doesn't
-  // notice the difference.
-  obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(std::floor(pt.x + 0.5)));
-  obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(std::floor(pt.y + 0.5)));
+  obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(pt.x));
+  obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(pt.y));
 
   return ret;
 }
@@ -1146,14 +1141,8 @@
   matrix world_mat = sprite->get_world_matrix();
   world_mat.transform(pt);
 
-  // These used to be: round(pt.x), which would round negative
-  // half-values away from zero (-0.5 - > -1), whereas
-  // std::floor(x + 0.5) always rounds towards +Infinity (-0.5 -> 0).
-  // All other cases should be the same. The testsuite doesn't
-  // notice the difference.
-  obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(std::floor(pt.x + 0.5)));
-  obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(std::floor(pt.y + 0.5)));
-
+  obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(pt.x));
+  obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(pt.y));
   return ret;
 
 }
@@ -1245,6 +1234,7 @@
   float x = PIXELS_TO_TWIPS(fn.arg(0).to_number());
   float y = PIXELS_TO_TWIPS(fn.arg(1).to_number());
 
+  // FIXME: x and y are always valid after function PIXELS_TO_TWIPS()
   if ( ! utility::isFinite(x) )
   {
     IF_VERBOSE_ASCODING_ERRORS(
@@ -1299,6 +1289,7 @@
   float x = PIXELS_TO_TWIPS(fn.arg(0).to_number());
   float y = PIXELS_TO_TWIPS(fn.arg(1).to_number());
 
+  // FIXME: x and y are always valid after function PIXELS_TO_TWIPS()
   if ( ! utility::isFinite(x) )
   {
     IF_VERBOSE_ASCODING_ERRORS(

Index: server/types.h
===================================================================
RCS file: /sources/gnash/gnash/server/types.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- server/types.h      9 Jun 2008 10:18:23 -0000       1.25
+++ server/types.h      13 Jun 2008 09:13:05 -0000      1.26
@@ -12,7 +12,8 @@
 #include <boost/cstdint.hpp> // for boost::?int??_t 
 
 inline double TWIPS_TO_PIXELS(int i) { return i / 20.0; }
-inline int PIXELS_TO_TWIPS(double d) { return d * 20; }
+// truncate when overflow occurs.
+inline int PIXELS_TO_TWIPS(double d) { return (int)(unsigned int)(d * 20); }
 
 namespace gnash {
        class SWFStream;        // forward declaration




reply via email to

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