[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10728: Lots of changes resulting fr
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10728: Lots of changes resulting from a small rationalization of frequently-used |
Date: |
Thu, 19 Mar 2009 17:27:50 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10728
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2009-03-19 17:27:50 +0100
message:
Lots of changes resulting from a small rationalization of frequently-used
headers. GnashNumeric contains mathematical functions. Clean up
includes of timer.h (Timer.h) now that it isn't used for object callbacks.
Base GnashException on std::runtime_error, as they should never be
logic errors.
Remove undefined behaviour that may have been responsible for bugs on
some ARM platforms.
Make some preparations for as3compile (swftools) testsuite.
added:
libbase/GnashNumeric.h
testsuite/as3/
renamed:
libcore/timers.cpp => libcore/Timers.cpp
libcore/timers.h => libcore/Timers.h
modified:
backend/render_handler_agg.cpp
backend/render_handler_ogl.cpp
configure.ac
gui/Kde4Gui.cpp
gui/gnash.cpp
gui/kde.cpp
libbase/GnashException.h
libbase/URL.cpp
libbase/utility.h
libcore/Makefile.am
libcore/MovieClip.cpp
libcore/RGBA.cpp
libcore/SWFMatrix.cpp
libcore/TextField.cpp
libcore/as_value.cpp
libcore/asobj/Array_as.cpp
libcore/asobj/ClassHierarchy.cpp
libcore/asobj/Date_as.cpp
libcore/asobj/Global.cpp
libcore/asobj/LoadableObject.cpp
libcore/asobj/Math_as.cpp
libcore/asobj/NetConnection_as.cpp
libcore/asobj/NetStream_as.cpp
libcore/asobj/Sound_as.cpp
libcore/asobj/String_as.cpp
libcore/asobj/TextFormat_as.cpp
libcore/asobj/TextSnapshot_as.cpp
libcore/asobj/XMLSocket_as.cpp
libcore/asobj/flash/geom/Point_as.cpp
libcore/asobj/flash/geom/Rectangle_as.cpp
libcore/asobj/flash/geom/Transform_as.cpp
libcore/character.cpp
libcore/cxform.cpp
libcore/fill_style.cpp
libcore/movie_root.cpp
libcore/parser/BitmapMovieDefinition.h
libcore/parser/SWFMovieDefinition.h
libcore/parser/morph2_character_def.cpp
libcore/rect.cpp
libcore/styles.cpp
libcore/swf/DefineVideoStreamTag.cpp
libcore/swf/SetBackgroundColorTag.h
libcore/swf/tag_loaders.cpp
libcore/vm/ASHandlers.cpp
libmedia/AudioDecoderSimple.cpp
plugin/klash4/klash_part.moc.in
testsuite/libcore.all/AsValueTest.cpp
testsuite/libnet.all/test_http.cpp
libcore/Timers.cpp
libcore/Timers.h
------------------------------------------------------------
revno: 10706.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 10:44:00 +0100
message:
Make Timer files purely for the Timer class, move AS methods to Global.cpp
(they are global methods).
Drop timer.h includes where Timers are no longer needed.
renamed:
libcore/timers.cpp => libcore/Timers.cpp
libcore/timers.h => libcore/Timers.h
modified:
libcore/Makefile.am
libcore/asobj/ClassHierarchy.cpp
libcore/asobj/Global.cpp
libcore/asobj/LoadableObject.cpp
libcore/asobj/NetConnection_as.cpp
libcore/asobj/NetStream_as.cpp
libcore/asobj/Sound_as.cpp
libcore/asobj/XMLSocket_as.cpp
libcore/movie_root.cpp
libcore/swf/tag_loaders.cpp
libcore/Timers.cpp
libcore/Timers.h
------------------------------------------------------------
revno: 10706.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 12:39:48 +0100
message:
Move mathematical functions to GnashNumeric.h (new header) to separate
them
from typeName, thead identifcation and other miscellanea.
Generalize truncation of double to int so it can be used in SWFMatrix too,
removing undefined behaviour.
modified:
backend/render_handler_agg.cpp
gui/gnash.cpp
libbase/utility.h
libcore/MovieClip.cpp
libcore/RGBA.cpp
libcore/SWFMatrix.cpp
libcore/TextField.cpp
libcore/as_value.cpp
libcore/asobj/Array_as.cpp
libcore/asobj/Date_as.cpp
libcore/asobj/Global.cpp
libcore/asobj/Math_as.cpp
libcore/asobj/String_as.cpp
libcore/asobj/TextFormat_as.cpp
libcore/asobj/TextSnapshot_as.cpp
libcore/asobj/flash/geom/Point_as.cpp
libcore/asobj/flash/geom/Rectangle_as.cpp
libcore/asobj/flash/geom/Transform_as.cpp
libcore/character.cpp
libcore/cxform.cpp
libcore/fill_style.cpp
libcore/movie_root.cpp
libcore/parser/BitmapMovieDefinition.h
libcore/parser/SWFMovieDefinition.h
libcore/parser/morph2_character_def.cpp
libcore/rect.cpp
libcore/styles.cpp
libcore/swf/DefineVideoStreamTag.cpp
libcore/swf/SetBackgroundColorTag.h
libcore/vm/ASHandlers.cpp
libmedia/AudioDecoderSimple.cpp
------------------------------------------------------------
revno: 10706.1.4
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 13:01:42 +0100
message:
Rename PIXELS_TO_TWIPS and TWIPS_TO_PIXELS.
Derive GnashException from std::runtime_error.
modified:
backend/render_handler_agg.cpp
backend/render_handler_ogl.cpp
gui/Kde4Gui.cpp
gui/kde.cpp
gui/klash4.moc.in
libbase/GnashException.h
libcore/MovieClip.cpp
libcore/SWFMatrix.cpp
libcore/TextField.cpp
libcore/asobj/TextFormat_as.cpp
libcore/asobj/TextSnapshot_as.cpp
libcore/asobj/flash/geom/Transform_as.cpp
libcore/character.cpp
libcore/movie_root.cpp
libcore/parser/BitmapMovieDefinition.h
libcore/parser/SWFMovieDefinition.h
libcore/swf/DefineVideoStreamTag.cpp
libcore/vm/ASHandlers.cpp
plugin/klash4/klash_part.moc.in
------------------------------------------------------------
revno: 10706.1.5
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 13:07:36 +0100
message:
Correct include in render_handler_ogl.
modified:
backend/render_handler_ogl.cpp
------------------------------------------------------------
revno: 10706.1.6
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 13:32:36 +0100
message:
Update testsuite.
modified:
testsuite/libcore.all/AsValueTest.cpp
testsuite/libnet.all/test_http.cpp
------------------------------------------------------------
revno: 10706.1.7
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 13:57:05 +0100
message:
Bump advertised SWF version to 10.
modified:
configure.ac
------------------------------------------------------------
revno: 10706.1.8
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 14:03:04 +0100
message:
Test for as3compile.
modified:
configure.ac
------------------------------------------------------------
revno: 10706.1.9
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2009-03-17 17:14:19 +0100
message:
Add GnashNumeric.h Remove unused things from URL.cpp, rearrange the file
into
a more conventional order.
added:
libbase/GnashNumeric.h
modified:
libbase/URL.cpp
------------------------------------------------------------
revno: 10706.1.10
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Thu 2009-03-19 08:24:03 +0100
message:
Add as3 testsuite dir.
added:
testsuite/as3/
=== modified file 'backend/render_handler_agg.cpp'
--- a/backend/render_handler_agg.cpp 2009-03-18 15:29:29 +0000
+++ b/backend/render_handler_agg.cpp 2009-03-19 16:27:50 +0000
@@ -116,14 +116,13 @@
#include "gnash.h"
#include "RGBA.h"
#include "GnashImage.h"
-#include "utility.h"
#include "log.h"
#include "render_handler.h"
#include "render_handler_agg.h"
#include "Range2d.h"
-
#include "shape_character_def.h"
#include "DisplayObject.h"
+#include "GnashNumeric.h"
#include <agg_rendering_buffer.h>
#include <agg_renderer_base.h>
@@ -237,14 +236,14 @@
void operator()(const edge& edge)
{
if (edge.is_straight()) {
- _path.line_to(TWIPS_TO_PIXELS(edge.ap.x) + _shift,
- TWIPS_TO_PIXELS(edge.ap.y) + _shift);
+ _path.line_to(twipsToPixels(edge.ap.x) + _shift,
+ twipsToPixels(edge.ap.y) + _shift);
}
else {
- _path.curve3(TWIPS_TO_PIXELS(edge.cp.x) + _shift,
- TWIPS_TO_PIXELS(edge.cp.y) + _shift,
- TWIPS_TO_PIXELS(edge.ap.x) + _shift,
- TWIPS_TO_PIXELS(edge.ap.y) + _shift);
+ _path.curve3(twipsToPixels(edge.cp.x) + _shift,
+ twipsToPixels(edge.cp.y) + _shift,
+ twipsToPixels(edge.ap.x) + _shift,
+ twipsToPixels(edge.ap.y) + _shift);
}
}
@@ -270,8 +269,8 @@
{
agg::path_storage& p = *_it;
- p.move_to(TWIPS_TO_PIXELS(in.ap.x) + _shift,
- TWIPS_TO_PIXELS(in.ap.y) + _shift);
+ p.move_to(twipsToPixels(in.ap.x) + _shift,
+ twipsToPixels(in.ap.y) + _shift);
std::for_each(in.m_edges.begin(), in.m_edges.end(),
EdgeToPath(p, _shift));
@@ -1125,8 +1124,8 @@
hairline = true;
}
- float prev_ax = TWIPS_TO_PIXELS(this_path.ap.x);
- float prev_ay = TWIPS_TO_PIXELS(this_path.ap.y);
+ float prev_ax = twipsToPixels(this_path.ap.x);
+ float prev_ay = twipsToPixels(this_path.ap.y);
bool prev_align_x = true;
bool prev_align_y = true;
@@ -1140,8 +1139,8 @@
const edge& this_edge = this_path.m_edges[eno];
- float this_ax = TWIPS_TO_PIXELS(this_edge.ap.x);
- float this_ay = TWIPS_TO_PIXELS(this_edge.ap.y);
+ float this_ax = twipsToPixels(this_edge.ap.x);
+ float this_ay = twipsToPixels(this_edge.ap.y);
if (hinting || this_edge.is_straight()) {
@@ -1211,8 +1210,8 @@
// never align curves!
new_path.curve3(
- TWIPS_TO_PIXELS(this_edge.cp.x) + subpixel_offset,
- TWIPS_TO_PIXELS(this_edge.cp.y) + subpixel_offset,
+ twipsToPixels(this_edge.cp.x) + subpixel_offset,
+ twipsToPixels(this_edge.cp.y) + subpixel_offset,
this_ax + subpixel_offset,
this_ay + subpixel_offset);
@@ -1571,8 +1570,8 @@
this_path.m_fill1==0 ? -1 : 0);
// starting point of path
- path.move_to(TWIPS_TO_PIXELS(this_path.ap.x),
- TWIPS_TO_PIXELS(this_path.ap.y));
+ path.move_to(twipsToPixels(this_path.ap.x),
+ twipsToPixels(this_path.ap.y));
// Add all edges to the path.
std::for_each(this_path.m_edges.begin(), this_path.m_edges.end(),
@@ -1694,7 +1693,7 @@
if (!thickness) stroke.width(1); // hairline
else if ( (!lstyle.scaleThicknessVertically()) &&
(!lstyle.scaleThicknessHorizontally()) )
{
- stroke.width(TWIPS_TO_PIXELS(thickness));
+ stroke.width(twipsToPixels(thickness));
}
else
{
=== modified file 'backend/render_handler_ogl.cpp'
--- a/backend/render_handler_ogl.cpp 2009-03-12 09:23:59 +0000
+++ b/backend/render_handler_ogl.cpp 2009-03-17 12:07:36 +0000
@@ -28,9 +28,8 @@
#include "gnash.h"
#include "RGBA.h"
#include "GnashImage.h"
-#include "utility.h"
+#include "GnashNumeric.h"
#include "log.h"
-
#include "GnashImage.h"
#include "utility.h"
#include "Range2d.h"
@@ -739,8 +738,8 @@
d.x = b.x + c.x - a.x;
d.y = b.y + c.y - a.y;
- float w_bounds = TWIPS_TO_PIXELS(b.x - a.x);
- float h_bounds = TWIPS_TO_PIXELS(c.y - a.y);
+ float w_bounds = twipsToPixels(b.x - a.x);
+ float h_bounds = twipsToPixels(c.y - a.y);
unsigned char* ptr = frame->data();
float xpos = a.x < 0 ? 0.0f : a.x; //hack
@@ -778,7 +777,7 @@
pixel_to_world(int x, int y)
{
// TODO: verify this is correct
- return point(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ return point(pixelsToTwips(x), pixelsToTwips(y));
}
virtual void begin_display(
@@ -870,10 +869,10 @@
GLint box[4];
glGetIntegerv(GL_SCISSOR_BOX, box);
- int x = PIXELS_TO_TWIPS(box[0]),
- y = PIXELS_TO_TWIPS(box[1]),
- w = PIXELS_TO_TWIPS(box[2]),
- h = PIXELS_TO_TWIPS(box[3]);
+ int x = pixelsToTwips(box[0]),
+ y = pixelsToTwips(box[1]),
+ w = pixelsToTwips(box[2]),
+ h = pixelsToTwips(box[3]);
glRectd(x, y - h, x + w, y + h);
#endif
@@ -1292,7 +1291,7 @@
}
else if ( (!style.scaleThicknessVertically()) &&
(!style.scaleThicknessHorizontally()) )
{
- float pxThickness = TWIPS_TO_PIXELS(width);
+ float pxThickness = twipsToPixels(width);
glLineWidth(pxThickness);
glPointSize(pxThickness);
}
@@ -1307,7 +1306,7 @@
stroke_scale /= 2.0f;
stroke_scale *= (fabsf(_xscale) + fabsf(_yscale)) / 2.0f;
width *= stroke_scale;
- width = TWIPS_TO_PIXELS(width);
+ width = twipsToPixels(width);
GLfloat width_info[2];
@@ -1692,8 +1691,8 @@
geometry::Range2d<float> area = ranges.getFullArea;
- glScissor( (int)TWIPS_TO_PIXELS(area.getMinX()),
window_height-(int)TWIPS_TO_PIXELS(area.getMaxY()),
- (int)TWIPS_TO_PIXELS(area.width()),
(int)TWIPS_TO_PIXELS(area.height()));
+ glScissor( (int)twipsToPixels(area.getMinX()),
window_height-(int)twipsToPixels(area.getMaxY()),
+ (int)twipsToPixels(area.width()),
(int)twipsToPixels(area.height()));
#endif
}
=== modified file 'configure.ac'
--- a/configure.ac 2009-03-06 03:31:05 +0000
+++ b/configure.ac 2009-03-17 13:03:04 +0000
@@ -37,8 +37,8 @@
dnl Set the default values for Flash Version. These are converted into
dnl various strings to make JavaScript or ActionScript detectors
dnl recognize Gnash as a SWF Player.
-DEFAULT_FLASH_MAJOR_VERSION="9"
-DEFAULT_FLASH_MINOR_VERSION="0"
+DEFAULT_FLASH_MAJOR_VERSION="10"
+DEFAULT_FLASH_MINOR_VERSION="1"
DEFAULT_FLASH_REV_NUMBER="999"
AC_SUBST(DEFAULT_FLASH_MAJOR_VERSION)
AC_SUBST(DEFAULT_FLASH_MINOR_VERSION)
@@ -1629,11 +1629,13 @@
dnl See if we can use the swfmill, mtasc, swfc and haxe based testsuites
dnl
if test x$cross_compiling = xno; then
+ AC_PATH_PROG(AS3COMPILE, as3compile)
AC_PATH_PROG(SWFC, swfc)
AC_PATH_SWFMILL
AC_PATH_MTASC
AC_PATH_HAXE
fi
+AM_CONDITIONAL(ENABLE_AS3COMPILE, [ test x"$AS3COMPILE" != x ])
AM_CONDITIONAL(ENABLE_SWFMILL, [ test x"$SWFMILL" != x ])
AM_CONDITIONAL(ENABLE_MTASC, [ test x"$MTASC" != x ])
AM_CONDITIONAL(ENABLE_HAXE, [ test x"$HAXE" != x ])
@@ -3038,6 +3040,14 @@
echo " or .deb users: apt-get install swftools" >&4
fi
+ if test x"$AS3COMPILE" != x; then
+ echo " AS3COMPILE is $AS3COMPILE"
+ else
+ echo " WARNING: you need as3compile from SWFTools" >&4
+ echo " to run some of the tests in Gnash testsuite." >&4
+ echo " You can install it from http://www.swftools.org/"
>&4
+ fi
+
if test x"$HTTP_TESTSUITE" != x; then
echo " HTTP testsuite dir is $HTTP_TESTSUITE"
fi
=== modified file 'gui/Kde4Gui.cpp'
--- a/gui/Kde4Gui.cpp 2009-03-07 18:04:27 +0000
+++ b/gui/Kde4Gui.cpp 2009-03-17 12:01:42 +0000
@@ -63,7 +63,7 @@
#include "Kde4Gui.h"
#include "klash4.moc"
#include "render_handler.h"
-#include "utility.h" // for PIXELS_TO_TWIPS
+#include "utility.h" // for pixelsToTwips
// Macro for using gettext strings where Qt expects QStrings
#define _q(Str) QString::fromUtf8(_(Str))
=== modified file 'gui/gnash.cpp'
--- a/gui/gnash.cpp 2009-02-25 22:33:03 +0000
+++ b/gui/gnash.cpp 2009-03-17 11:39:48 +0000
@@ -26,7 +26,7 @@
#include "rc.h" // for use of rcfile
#include "debugger.h"
#include "arg_parser.h"
-#include "utility.h" // for clamp
+#include "GnashNumeric.h" // for clamp
#ifdef HAVE_FFMPEG_AVCODEC_H
extern "C" {
@@ -282,7 +282,7 @@
player.hideMenu(true);
break;
case 's':
- player.setScale(gnash::utility::clamp<float>(
+ player.setScale(gnash::clamp<float>(
parser.argument<float>(i),
0.01f, 100.f));
break;
=== modified file 'gui/kde.cpp'
--- a/gui/kde.cpp 2009-02-25 22:33:03 +0000
+++ b/gui/kde.cpp 2009-03-17 12:01:42 +0000
@@ -43,7 +43,7 @@
#include "gui.h"
#include "kdesup.h"
#include "klash3.moc"
-#include "utility.h" // for PIXELS_TO_TWIPS
+#include "GnashNumeric.h" // for pixelsToTwips
using namespace std;
@@ -473,10 +473,10 @@
const QRegion& region = event->region();
QRect rect = region.boundingRect();
- int xmin = static_cast<int> (PIXELS_TO_TWIPS(rect.x()-1)),
- ymin = static_cast<int> (PIXELS_TO_TWIPS(rect.y()-1)),
- xmax = static_cast<int> (PIXELS_TO_TWIPS(rect.right()+1)),
- ymax = static_cast<int> (PIXELS_TO_TWIPS(rect.bottom()+1));
+ int xmin = static_cast<int> (pixelsToTwips(rect.x()-1)),
+ ymin = static_cast<int> (pixelsToTwips(rect.y()-1)),
+ xmax = static_cast<int> (pixelsToTwips(rect.right()+1)),
+ ymax = static_cast<int> (pixelsToTwips(rect.bottom()+1));
geometry::Range2d<int> range(xmin, ymin, xmax, ymax);
InvalidatedRanges ranges;
=== modified file 'libbase/GnashException.h'
--- a/libbase/GnashException.h 2009-03-01 13:57:54 +0000
+++ b/libbase/GnashException.h 2009-03-17 12:01:42 +0000
@@ -16,9 +16,9 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef GNASH_GNASHEXCEPTION_H
-#define GNASH_GNASHEXCEPTION_H 1
+#define GNASH_GNASHEXCEPTION_H
-#include <exception>
+#include <stdexcept>
#include <string>
#include "dsodefs.h"
@@ -26,28 +26,22 @@
{
/// Top-level gnash exception
-class DSOEXPORT GnashException: public std::exception
+class DSOEXPORT GnashException: public std::runtime_error
{
public:
GnashException(const std::string& s)
:
- _msg(s)
+ std::runtime_error(s)
{}
GnashException()
:
- _msg("Generic error")
+ std::runtime_error("Generic error")
{}
virtual ~GnashException() throw() {}
-
- const char* what() const throw() { return _msg.c_str(); }
-
-private:
-
- std::string _msg;
};
/// An exception from MediaHandler subsystem
=== added file 'libbase/GnashNumeric.h'
--- a/libbase/GnashNumeric.h 1970-01-01 00:00:00 +0000
+++ b/libbase/GnashNumeric.h 2009-03-17 16:14:19 +0000
@@ -0,0 +1,100 @@
+
+#ifndef GNASH_NUMERIC_H
+#define GNASH_NUMERIC_H
+
+namespace gnash {
+
+// Using a possible built-in pi constant M_PI, which is not in
+// the C++ standard, has no greate advantage, so we will use this
+// one. Make it as accurate as you like.
+static const double PI = 3.14159265358979323846;
+
+inline bool
+isFinite(double d)
+{
+#if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
+ return (finite(d));
+#else
+ // Put using namespace std; here if you have to
+ // put it anywhere.
+ using namespace std;
+ return (isfinite(d));
+#endif
+}
+
+inline double
+infinite_to_zero(double x)
+{
+ return isFinite(x) ? x : 0.0;
+}
+
+template <typename T>
+inline T
+clamp(T i, T min, T max)
+{
+ assert(min <= max);
+ return std::max<T>(min, std::min<T>(i, max));
+}
+
+inline float
+flerp(float a, float b, float f)
+{
+ return (b - a) * f + a;
+}
+
+inline int
+frnd(float f)
+{
+ return static_cast<int>(f + 0.5f);
+}
+
+inline double
+twipsToPixels(int i)
+{
+ return static_cast<double>(i / 20.0);
+}
+
+template<size_t Factor>
+boost::int32_t
+truncateWithFactor(double a)
+{
+
+ const double factor = static_cast<double>(Factor);
+
+ // This truncates large values without relying on undefined behaviour.
+ // For very large values of 'a' it is noticeably slower than the UB
+ // version (due to fmod), but should always be legal behaviour. For
+ // ordinary values (within ±1.07374e+08 pixels) it is comparable to
+ // the UB version for speed. Because values outside the limit are
+ // extremely rare, using this safe version has no implications for
+ // performance under normal circumstances.
+ static const double upperUnsignedLimit =
+ std::numeric_limits<boost::uint32_t>::max() + 1.0;
+ static const double upperSignedLimit =
+ std::numeric_limits<boost::int32_t>::max() / factor;
+ static const double lowerSignedLimit =
+ std::numeric_limits<boost::int32_t>::min() / factor;
+
+ if (a >= lowerSignedLimit && a <= upperSignedLimit) {
+ return static_cast<boost::int32_t>(a * factor);
+ }
+
+ // This slow truncation happens only in very unlikely cases.
+ return a >= 0 ?
+ static_cast<boost::uint32_t>(
+ std::fmod(a * factor, upperUnsignedLimit))
+ :
+ -static_cast<boost::uint32_t>(
+ std::fmod(-a * factor, upperUnsignedLimit));
+}
+
+// truncate when overflow occurs.
+inline boost::int32_t
+pixelsToTwips(double a)
+{
+ return truncateWithFactor<20>(a);
+}
+
+} // namespace gnash
+
+#endif
=== modified file 'libbase/URL.cpp'
--- a/libbase/URL.cpp 2009-03-10 09:34:10 +0000
+++ b/libbase/URL.cpp 2009-03-17 16:14:19 +0000
@@ -44,7 +44,54 @@
namespace gnash {
-/*private*/
+URL::URL(const std::string& relative_url, const URL& baseurl)
+{
+ init_relative(relative_url, baseurl);
+}
+
+// only for UNIX
+void
+URL::normalize_path(std::string& path)
+{
+
+#if defined(_WIN32) || defined(WIN32) || defined(__OS2__)
+ return;
+#endif
+
+ assert(path[0] == '/');
+
+ std::vector<std::string> components;
+
+ std::string::iterator prev=path.begin();
+ for (std::string::iterator curr = prev + 1;
+ curr != path.end();
+ ++curr )
+ {
+ if ( *curr == '/')
+ {
+ std::string comp = std::string(prev+1, curr);
+ //cerr << "comp:" << comp << endl;
+ prev = curr;
+
+ if ( comp == "" || comp == "." ) continue;
+ if ( comp == ".." && components.size() )
+ components.pop_back();
+ else components.push_back(comp);
+ }
+ }
+ // add last component
+ components.push_back(std::string(prev+1, path.end()));
+
+ path = "";
+ for (std::vector<std::string>::const_iterator i=components.begin(),
+ e=components.end();
+ i!=e; ++i)
+ {
+ path += "/" + *i;
+ }
+
+}
+
void
URL::init_absolute(const std::string& in)
{
@@ -100,7 +147,7 @@
normalize_path(_path);
}
-/*public*/
+
URL::URL(const std::string& absolute_url)
{
//cerr << "URL(" << absolute_url << ")" << endl;
@@ -144,66 +191,6 @@
}
}
-class DupSlashes
-{
-public:
- bool operator() (char a, char b) const
- {
- return ( a == '/' && b == '/' );
- }
-};
-
-/*private*/
-// only for UNIX
-void
-URL::normalize_path(std::string& path)
-{
-
-#if defined(_WIN32) || defined(WIN32) || defined(__OS2__)
- return;
-#endif
-
- assert(path[0] == '/');
-
- std::vector<std::string> components;
-
- std::string::iterator prev=path.begin();
- for (std::string::iterator curr = prev + 1;
- curr != path.end();
- ++curr )
- {
- if ( *curr == '/')
- {
- std::string comp = std::string(prev+1, curr);
- //cerr << "comp:" << comp << endl;
- prev = curr;
-
- if ( comp == "" || comp == "." ) continue;
- if ( comp == ".." && components.size() )
- components.pop_back();
- else components.push_back(comp);
- }
- }
- // add last component
- components.push_back(std::string(prev+1, path.end()));
-
- path = "";
- for (std::vector<std::string>::const_iterator i=components.begin(),
- e=components.end();
- i!=e; ++i)
- {
- path += "/" + *i;
- }
-
-}
-
-/*public*/
-URL::URL(const std::string& relative_url, const URL& baseurl)
-{
- init_relative(relative_url, baseurl);
-}
-
-/*private*/
void
URL::init_relative(const std::string& relative_url, const URL& baseurl)
{
@@ -301,11 +288,10 @@
}
-/*public*/
std::string
URL::str() const
{
- std::string ret = _proto + "://" + _host;
+ std::string ret = _proto + "://" + _host;
if ( _port != "" )
{
ret += ":" + _port;
@@ -323,7 +309,6 @@
return ret;
}
-/*private*/
void
URL::split_anchor_from_path()
{
@@ -338,7 +323,6 @@
}
}
-/*private*/
void
URL::split_port_from_host()
{
@@ -353,7 +337,6 @@
}
}
-/*private*/
void
URL::split_querystring_from_path()
{
@@ -375,7 +358,6 @@
}
-/* public static */
void
URL::parse_querystring(const std::string& query_string,
std::map<std::string, std::string>& target_map)
@@ -419,7 +401,6 @@
}
-/* public static */
void
URL::encode(std::string& input)
{
@@ -444,14 +425,13 @@
}
std::string
-URL::encode (const std::string& str)
+URL::encode(const std::string& str)
{
std::string escapestring(str);
encode(escapestring);
return escapestring;
}
-/* public static */
void
URL::decode(std::string& input)
{
@@ -484,7 +464,8 @@
}
}
-std::ostream& operator<< (std::ostream& o, const URL& u)
+std::ostream&
+operator<< (std::ostream& o, const URL& u)
{
return o << u.str();
}
=== modified file 'libbase/utility.h'
--- a/libbase/utility.h 2009-02-26 18:48:57 +0000
+++ b/libbase/utility.h 2009-03-17 11:39:48 +0000
@@ -59,108 +59,6 @@
namespace gnash {
-// Using a possible built-in pi constant M_PI, which is not in
-// the C++ standard, has no conceivable advantage, so we will use this
-// one. Make it as accurate as you like.
-static const double PI = 3.14159265358979323846;
-
-// Commonly-used inlined mathematical functions are defined in
-// namespace gnash::utility so that it's clear where they
-// come from.
-namespace utility {
-
-inline bool isFinite(double d)
-{
-#if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
- return (finite(d));
-#else
- // Put using namespace std; here if you have to
- // put it anywhere.
- using namespace std;
- return (isfinite(d));
-#endif
-}
-
-inline double
-infinite_to_zero(double x)
-{
- return utility::isFinite(x) ? x : 0.0;
-}
-
-template <typename T>
-inline T
-clamp(T i, T min, T max)
-{
- assert( min <= max );
- return std::max<T>(min, std::min<T>(i, max));
-}
-
-inline float
-flerp(float a, float b, float f)
-{
- return (b - a) * f + a;
-}
-
-inline int
-frnd(float f)
-{
- return static_cast<int>(f + 0.5f);
-}
-
-} // end of namespace utility
-
-/// Some of these functions could also be in the gnash::utility namespace,
-/// although some are used so often that it would get annoying.
-
-inline double
-TWIPS_TO_PIXELS(int i)
-{
- return static_cast<double>(i / 20.0);
-}
-
-// truncate when overflow occurs.
-inline boost::int32_t
-PIXELS_TO_TWIPS(double a)
-{
-
- // This truncates large values without relying on undefined behaviour.
- // For very large values of 'a' it is noticeably slower than the UB
- // version (due to fmod), but should always be legal behaviour. For
- // ordinary values (within ±1.07374e+08 pixels) it is comparable to
- // the UB version for speed. Because values outside the limit are
- // extremely rare, using this safe version has no implications for
- // performance under normal circumstances.
- static const double upperUnsignedLimit =
- std::numeric_limits<boost::uint32_t>::max() + 1.0;
- static const double upperSignedLimit =
- std::numeric_limits<boost::int32_t>::max() / 20.0;
- static const double lowerSignedLimit =
- std::numeric_limits<boost::int32_t>::min() / 20.0;
-
- if (a >= lowerSignedLimit && a <= upperSignedLimit)
- {
- return static_cast<boost::int32_t>(a * 20.0);
- }
-
- // This slow truncation happens only in very unlikely cases.
- return a >= 0 ?
- static_cast<boost::uint32_t>(std::fmod(a * 20.0, upperUnsignedLimit))
- :
- -static_cast<boost::uint32_t>(std::fmod(-a * 20.0,
upperUnsignedLimit));
-}
-
-/// \brief
-/// Return the smallest multiple of given base greater or equal
-/// given limit
-inline unsigned int
-smallestMultipleContaining(unsigned int base, unsigned int x)
-{
- int f = x / base;
- if (x % base) f++;
- return base*f;
-}
-
-
/// Return (unmangled) name of this instance type. Used for
/// logging in various places.
template <class T>
=== modified file 'libcore/Makefile.am'
--- a/libcore/Makefile.am 2009-03-10 20:43:50 +0000
+++ b/libcore/Makefile.am 2009-03-17 09:44:00 +0000
@@ -114,7 +114,7 @@
render.cpp \
SWFStream.cpp \
styles.cpp \
- timers.cpp \
+ Timers.cpp \
RGBA.cpp \
$(FREETYPE_SOURCES) \
$(NULL)
@@ -210,7 +210,7 @@
swf/ScriptLimitsTag.h \
swf_event.h \
swf_function.h \
- timers.h \
+ Timers.h \
RGBA.h \
Video.h \
$(NULL)
=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp 2009-03-13 22:46:37 +0000
+++ b/libcore/MovieClip.cpp 2009-03-17 12:01:42 +0000
@@ -42,6 +42,7 @@
#include "VM.h"
#include "Range2d.h" // for getBounds
#include "GnashException.h"
+#include "GnashNumeric.h"
#include "GnashAlgorithm.h"
#include "URL.h"
#include "sound_handler.h"
@@ -58,6 +59,7 @@
#include "flash/display/BitmapData_as.h"
#include "flash/geom/Matrix_as.h"
#include "ExportableResource.h"
+#include "GnashNumeric.h"
#ifdef USE_SWFTREE
# include "tree.hh"
@@ -141,7 +143,6 @@
as_value movieclip_getNextHighestDepth(const fn_call& fn);
as_value movieclip_getTextSnapshot(const fn_call& fn);
as_value movieclip_tabIndex(const fn_call& fn);
- as_value movieclip_forceSmoothing(const fn_call& fn);
as_value movieclip_opaqueBackground(const fn_call& fn);
as_value movieclip_filters(const fn_call& fn);
as_value movieclip_forceSmoothing(const fn_call& fn);
@@ -686,7 +687,7 @@
//log_debug("get_frame_number(%s), num: %g", frame_spec, num);
- if ( ! utility::isFinite(num) || int(num) != num || num == 0)
+ if (!isFinite(num) || int(num) != num || num == 0)
{
bool ret = m_def->get_labeled_frame(fspecStr, frameno);
//log_debug("get_labeled_frame(%s) returned %d, frameno is %d",
fspecStr, ret, frameno);
@@ -775,7 +776,7 @@
// Create a definition (TODO: cleanup this thing, definitions should be
immutable!)
// Set textfield bounds
- rect bounds(0, 0, PIXELS_TO_TWIPS(width), PIXELS_TO_TWIPS(height));
+ rect bounds(0, 0, pixelsToTwips(width), pixelsToTwips(height));
// Create an instance
boost::intrusive_ptr<character> txt_char = new TextField(this, bounds);
@@ -786,7 +787,7 @@
// Set _x and _y
SWFMatrix txt_matrix;
- txt_matrix.set_translation(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ txt_matrix.set_translation(pixelsToTwips(x), pixelsToTwips(y));
txt_char->setMatrix(txt_matrix, true); // update caches (altought
shouldn't be needed as we only set translation)
// Here we add the character to the displayList.
@@ -3820,16 +3821,16 @@
case 2: // x, y
{
- boost::int32_t x = PIXELS_TO_TWIPS(fn.arg(0).to_number());
- boost::int32_t y = PIXELS_TO_TWIPS(fn.arg(1).to_number());
+ boost::int32_t x = pixelsToTwips(fn.arg(0).to_number());
+ boost::int32_t y = pixelsToTwips(fn.arg(1).to_number());
return movieclip->pointInBounds(x, y);
}
case 3: // x, y, shapeFlag
{
- boost::int32_t x = PIXELS_TO_TWIPS(fn.arg(0).to_number());
- boost::int32_t y = PIXELS_TO_TWIPS(fn.arg(1).to_number());
+ boost::int32_t x = pixelsToTwips(fn.arg(0).to_number());
+ boost::int32_t y = pixelsToTwips(fn.arg(1).to_number());
bool shapeFlag = fn.arg(2).to_bool();
if ( ! shapeFlag ) return movieclip->pointInBounds(x, y);
@@ -4106,10 +4107,10 @@
if ( !bounds.is_null() )
{
// Round to the twip
- xMin = TWIPS_TO_PIXELS(bounds.get_x_min());
- yMin = TWIPS_TO_PIXELS(bounds.get_y_min());
- xMax = TWIPS_TO_PIXELS(bounds.get_x_max());
- yMax = TWIPS_TO_PIXELS(bounds.get_y_max());
+ xMin = twipsToPixels(bounds.get_x_min());
+ yMin = twipsToPixels(bounds.get_y_min());
+ xMax = twipsToPixels(bounds.get_x_max());
+ yMax = twipsToPixels(bounds.get_y_max());
}
boost::intrusive_ptr<as_object> bounds_obj(new as_object());
@@ -4161,7 +4162,7 @@
);
return ret;
}
- x = PIXELS_TO_TWIPS(tmp.to_number());
+ x = pixelsToTwips(tmp.to_number());
if ( ! obj->get_member(NSV::PROP_Y, &tmp) )
{
@@ -4172,14 +4173,14 @@
);
return ret;
}
- y = PIXELS_TO_TWIPS(tmp.to_number());
+ y = pixelsToTwips(tmp.to_number());
point pt(x, y);
SWFMatrix world_mat = movieclip->getWorldMatrix();
world_mat.invert().transform(pt);
- obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(pt.x));
- obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(pt.y));
+ obj->set_member(NSV::PROP_X, twipsToPixels(pt.x));
+ obj->set_member(NSV::PROP_Y, twipsToPixels(pt.y));
return ret;
}
@@ -4224,7 +4225,7 @@
);
return ret;
}
- x = PIXELS_TO_TWIPS(tmp.to_number());
+ x = pixelsToTwips(tmp.to_number());
if ( ! obj->get_member(NSV::PROP_Y, &tmp) )
{
@@ -4235,14 +4236,14 @@
);
return ret;
}
- y = PIXELS_TO_TWIPS(tmp.to_number());
+ y = pixelsToTwips(tmp.to_number());
point pt(x, y);
SWFMatrix world_mat = movieclip->getWorldMatrix();
world_mat.transform(pt);
- obj->set_member(NSV::PROP_X, TWIPS_TO_PIXELS(pt.x));
- obj->set_member(NSV::PROP_Y, TWIPS_TO_PIXELS(pt.y));
+ obj->set_member(NSV::PROP_X, twipsToPixels(pt.x));
+ obj->set_member(NSV::PROP_Y, twipsToPixels(pt.y));
return ret;
}
@@ -4340,7 +4341,7 @@
double x = fn.arg(0).to_number();
double y = fn.arg(1).to_number();
- if ( ! utility::isFinite(x) )
+ if (!isFinite(x) )
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4351,7 +4352,7 @@
x = 0;
}
- if ( ! utility::isFinite(y) )
+ if (!isFinite(y) )
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4365,7 +4366,7 @@
#ifdef DEBUG_DRAWING_API
log_debug("%s.lineTo(%g,%g);", movieclip->getTarget(), x, y);
#endif
- movieclip->lineTo(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ movieclip->lineTo(pixelsToTwips(x), pixelsToTwips(y));
return as_value();
}
@@ -4395,7 +4396,7 @@
double x = fn.arg(0).to_number();
double y = fn.arg(1).to_number();
- if ( ! utility::isFinite(x) )
+ if (!isFinite(x) )
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4406,7 +4407,7 @@
x = 0;
}
- if ( ! utility::isFinite(y) )
+ if (!isFinite(y) )
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4420,7 +4421,7 @@
#ifdef DEBUG_DRAWING_API
log_debug(_("%s.moveTo(%g,%g);"), movieclip->getTarget(), x, y);
#endif
- movieclip->moveTo(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ movieclip->moveTo(pixelsToTwips(x), pixelsToTwips(y));
return as_value();
}
@@ -4479,7 +4480,7 @@
"first eight will be discarded"), ss.str());
);
case 8:
- miterLimitFactor = utility::clamp<int>(fn.arg(7).to_int(), 1, 255);
+ miterLimitFactor = clamp<int>(fn.arg(7).to_int(), 1, 255);
case 7:
{
std::string joinStyleStr = fn.arg(6).to_string();
@@ -4549,20 +4550,20 @@
pixelHinting = fn.arg(3).to_bool();
case 3:
{
- const float alphaval = utility::clamp<float>(fn.arg(2).to_number(),
+ const float alphaval = clamp<float>(fn.arg(2).to_number(),
0, 100);
a = boost::uint8_t(255 * (alphaval / 100));
}
case 2:
{
boost::uint32_t rgbval = boost::uint32_t(
- utility::clamp<float>(fn.arg(1).to_number(), 0, 16777216));
+ clamp<float>(fn.arg(1).to_number(), 0, 16777216));
r = boost::uint8_t((rgbval & 0xFF0000) >> 16);
g = boost::uint8_t((rgbval & 0x00FF00) >> 8);
b = boost::uint8_t((rgbval & 0x0000FF) );
}
case 1:
- thickness = boost::uint16_t(PIXELS_TO_TWIPS(utility::clamp<float>(
+ thickness = boost::uint16_t(pixelsToTwips(clamp<float>(
fn.arg(0).to_number(), 0, 255)));
break;
}
@@ -4607,7 +4608,7 @@
double ax = fn.arg(2).to_number();
double ay = fn.arg(3).to_number();
- if ( ! utility::isFinite(cx) )
+ if (!isFinite(cx))
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4618,7 +4619,7 @@
cx = 0;
}
- if ( ! utility::isFinite(cy) )
+ if (!isFinite(cy))
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4629,7 +4630,7 @@
cy = 0;
}
- if ( ! utility::isFinite(ax) )
+ if (!isFinite(ax))
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4640,7 +4641,7 @@
ax = 0;
}
- if ( ! utility::isFinite(ay) )
+ if (!isFinite(ay))
{
IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss; fn.dump_args(ss);
@@ -4655,8 +4656,8 @@
log_debug(_("%s.curveTo(%g,%g,%g,%g);"), movieclip->getTarget(),
cx, cy, ax, ay);
#endif
- movieclip->curveTo(PIXELS_TO_TWIPS(cx), PIXELS_TO_TWIPS(cy),
- PIXELS_TO_TWIPS(ax), PIXELS_TO_TWIPS(ay));
+ movieclip->curveTo(pixelsToTwips(cx), pixelsToTwips(cy),
+ pixelsToTwips(ax), pixelsToTwips(ay));
return as_value();
}
@@ -4699,14 +4700,14 @@
{
// 2^24 is the max here
boost::uint32_t rgbval = boost::uint32_t(
- utility::clamp<float>(fn.arg(0).to_number(), 0, 16777216));
+ clamp<float>(fn.arg(0).to_number(), 0, 16777216));
r = boost::uint8_t( (rgbval&0xFF0000) >> 16);
g = boost::uint8_t( (rgbval&0x00FF00) >> 8);
b = boost::uint8_t( (rgbval&0x0000FF) );
if ( fn.nargs > 1 )
{
- a = 255 * utility::clamp<int>(fn.arg(1).to_int(), 0, 100) / 100;
+ a = 255 * clamp<int>(fn.arg(1).to_int(), 0, 100) / 100;
IF_VERBOSE_ASCODING_ERRORS(
if ( fn.nargs > 2 )
{
@@ -4815,13 +4816,13 @@
if ( matrixArg->getMember(NSV::PROP_MATRIX_TYPE).to_string() == "box" )
{
- boost::int32_t valX = PIXELS_TO_TWIPS(
+ boost::int32_t valX = pixelsToTwips(
matrixArg->getMember(NSV::PROP_X).to_number());
- boost::int32_t valY = PIXELS_TO_TWIPS(
+ boost::int32_t valY = pixelsToTwips(
matrixArg->getMember(NSV::PROP_Y).to_number());
- boost::int32_t valW = PIXELS_TO_TWIPS(
+ boost::int32_t valW = pixelsToTwips(
matrixArg->getMember(NSV::PROP_W).to_number());
- boost::int32_t valH = PIXELS_TO_TWIPS(
+ boost::int32_t valH = pixelsToTwips(
matrixArg->getMember(NSV::PROP_H).to_number());
float valR = matrixArg->getMember(NSV::PROP_R).to_number();
@@ -4860,9 +4861,9 @@
float valB = matrixArg->getMember(NSV::PROP_B).to_number() ; // yx
float valD = matrixArg->getMember(NSV::PROP_D).to_number() ; // xy
float valE = matrixArg->getMember(NSV::PROP_E).to_number() ; // yy
- boost::int32_t valG = PIXELS_TO_TWIPS(
+ boost::int32_t valG = pixelsToTwips(
matrixArg->getMember(NSV::PROP_G).to_number()); // x0
- boost::int32_t valH = PIXELS_TO_TWIPS(
+ boost::int32_t valH = pixelsToTwips(
matrixArg->getMember(NSV::PROP_H).to_number()); // y0
input_matrix.sx = valA * 65536; // sx
@@ -4956,11 +4957,11 @@
as_value alpVal = alphas->getMember(key);
boost::uint8_t alp = alpVal.is_number() ?
- utility::clamp<int>(alpVal.to_int(), 0, 255) : 0;
+ clamp<int>(alpVal.to_int(), 0, 255) : 0;
as_value ratVal = ratios->getMember(key);
boost::uint8_t rat = ratVal.is_number() ?
- utility::clamp<int>(ratVal.to_int(), 0, 255) : 0;
+ clamp<int>(ratVal.to_int(), 0, 255) : 0;
rgba color;
color.parseRGB(col);
@@ -5009,10 +5010,10 @@
// check for infinite values
bool gotinf = false;
- if ( ! utility::isFinite(x0) ) { x0=0; gotinf=true; }
- if ( ! utility::isFinite(y0) ) { y0=0; gotinf=true; }
- if ( ! utility::isFinite(x1) ) { x1=0; gotinf=true; }
- if ( ! utility::isFinite(y1) ) { y1=0; gotinf=true; }
+ if (!isFinite(x0) ) { x0=0; gotinf=true; }
+ if (!isFinite(y0) ) { y0=0; gotinf=true; }
+ if (!isFinite(x1) ) { x1=0; gotinf=true; }
+ if (!isFinite(y1) ) { y1=0; gotinf=true; }
// check for swapped values
bool swapped = false;
@@ -5044,8 +5045,8 @@
}
);
- rect bounds(PIXELS_TO_TWIPS(x0), PIXELS_TO_TWIPS(y0),
- PIXELS_TO_TWIPS(x1), PIXELS_TO_TWIPS(y1));
+ rect bounds(pixelsToTwips(x0), pixelsToTwips(y0),
+ pixelsToTwips(x1), pixelsToTwips(y1));
st.setBounds(bounds);
}
}
=== modified file 'libcore/RGBA.cpp'
--- a/libcore/RGBA.cpp 2009-01-05 09:32:03 +0000
+++ b/libcore/RGBA.cpp 2009-03-17 11:39:48 +0000
@@ -6,86 +6,90 @@
#include <boost/thread.hpp>
#include "RGBA.h"
-
-#include "utility.h"
+#include "GnashNumeric.h"
#include "log.h"
#include "SWFStream.h"
#include <sstream> // for ::print and ::toString
namespace gnash {
- //
- // rgba
- //
-
- /// Can throw ParserException on premature end of input stream
- void rgba::read(SWFStream& in, SWF::TagType tag)
- {
- switch (tag)
- {
- case SWF::DEFINESHAPE:
- case SWF::DEFINESHAPE2:
- read_rgb(in);
- break;
- default:
- case SWF::DEFINESHAPE3:
- read_rgba(in);
- break;
- }
- }
-
- /// Can throw ParserException on premature end of input stream
- void rgba::read_rgba(SWFStream& in)
- {
- read_rgb(in);
- in.ensureBytes(1);
- m_a = in.read_u8();
- }
-
- /// Can throw ParserException on premature end of input stream
- void rgba::read_rgb(SWFStream& in)
- {
- in.ensureBytes(3);
- m_r = in.read_u8();
- m_g = in.read_u8();
- m_b = in.read_u8();
- m_a = 0x0FF;
- }
-
- void rgba::print() const
- // For debugging.
- {
- log_parse("rgba: %d %d %d %d", m_r, m_g, m_b, m_a);
- }
-
- std::string rgba::toString() const
- // For debugging.
- {
- std::stringstream ss;
- ss << *this;
- return ss.str();
- }
-
- std::string rgba::toShortString() const
- // For debugging.
- {
- std::stringstream ss;
- ss << (unsigned)m_r << ","
- << (unsigned)m_g << ","
- << (unsigned)m_b << ","
- << (unsigned)m_a;
- return ss.str();
- }
-
- void rgba::set_lerp(const rgba& a, const rgba& b, float f)
- {
- using utility::frnd;
- using utility::flerp;
- m_r = static_cast<boost::uint8_t>(frnd(flerp(a.m_r, b.m_r, f)));
- m_g = static_cast<boost::uint8_t>(frnd(flerp(a.m_g, b.m_g, f)));
- m_b = static_cast<boost::uint8_t>(frnd(flerp(a.m_b, b.m_b, f)));
- m_a = static_cast<boost::uint8_t>(frnd(flerp(a.m_a, b.m_a, f)));
- }
+//
+// rgba
+//
+
+/// Can throw ParserException on premature end of input stream
+void
+rgba::read(SWFStream& in, SWF::TagType tag)
+{
+ switch (tag)
+ {
+ case SWF::DEFINESHAPE:
+ case SWF::DEFINESHAPE2:
+ read_rgb(in);
+ break;
+ default:
+ case SWF::DEFINESHAPE3:
+ read_rgba(in);
+ break;
+ }
+}
+
+/// Can throw ParserException on premature end of input stream
+void
+rgba::read_rgba(SWFStream& in)
+{
+ read_rgb(in);
+ in.ensureBytes(1);
+ m_a = in.read_u8();
+}
+
+/// Can throw ParserException on premature end of input stream
+void
+rgba::read_rgb(SWFStream& in)
+{
+ in.ensureBytes(3);
+ m_r = in.read_u8();
+ m_g = in.read_u8();
+ m_b = in.read_u8();
+ m_a = 0x0FF;
+}
+
+void
+rgba::print() const
+// For debugging.
+{
+ log_parse("rgba: %d %d %d %d", m_r, m_g, m_b, m_a);
+}
+
+std::string
+rgba::toString() const
+// For debugging.
+{
+ std::stringstream ss;
+ ss << *this;
+ return ss.str();
+}
+
+std::string
+rgba::toShortString() const
+// For debugging.
+{
+ std::stringstream ss;
+ ss << (unsigned)m_r << ","
+ << (unsigned)m_g << ","
+ << (unsigned)m_b << ","
+ << (unsigned)m_a;
+ return ss.str();
+}
+
+void
+rgba::set_lerp(const rgba& a, const rgba& b, float f)
+{
+ m_r = static_cast<boost::uint8_t>(frnd(flerp(a.m_r, b.m_r, f)));
+ m_g = static_cast<boost::uint8_t>(frnd(flerp(a.m_g, b.m_g, f)));
+ m_b = static_cast<boost::uint8_t>(frnd(flerp(a.m_b, b.m_b, f)));
+ m_a = static_cast<boost::uint8_t>(frnd(flerp(a.m_a, b.m_a, f)));
+}
std::ostream&
operator<< (std::ostream& os, const rgba& r)
=== modified file 'libcore/SWFMatrix.cpp'
--- a/libcore/SWFMatrix.cpp 2009-02-25 22:33:03 +0000
+++ b/libcore/SWFMatrix.cpp 2009-03-17 12:01:42 +0000
@@ -28,35 +28,19 @@
#include "SWFMatrix.h"
#include "SWFStream.h" // for reading from SWF
#include "log.h"
-#include "utility.h"
+#include "GnashNumeric.h"
#include <cmath>
#include <iomanip>
namespace gnash {
-#define TRUST_FLOAT_TO_UINT32_CONVERSION 1
-
namespace {
-inline
-boost::int32_t DoubleToFixed16(double a)
+inline boost::int32_t
+DoubleToFixed16(double a)
{
-#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
- // truncate when overflow occurs.
- return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a *
65536.0));
-#else
- boost::int32_t b;
- if (a >= 0)
- {
- b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0, 4294967296.0));
- }
- else
- {
- b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0,
4294967296.0));
- }
- return b;
-#endif
+ return truncateWithFactor<65536>(a);
}
inline boost::int32_t
@@ -195,7 +179,6 @@
SWFMatrix::set_lerp(const SWFMatrix& m1, const SWFMatrix& m2, float t)
// Set this SWFMatrix to a blend of m1 and m2, parameterized by t.
{
- using utility::flerp;
sx = flerp(m1.sx, m2.sx, t);
shx = flerp(m1.shx, m2.shx, t);
shy = flerp(m1.shy, m2.shy, t);
@@ -394,14 +377,14 @@
<< std::setw(fieldWidth) << std::fixed << std::setprecision(4)
<< m.shy/ 65536.0 << " "
<< std::setw(fieldWidth) << std::fixed << std::setprecision(4)
- << TWIPS_TO_PIXELS(m.tx) << " |"
+ << twipsToPixels(m.tx) << " |"
<< std::endl << "|"
<< std::setw(fieldWidth) << std::fixed << std::setprecision(4)
<< m.shx/ 65536.0 << " "
<< std::setw(fieldWidth) << std::fixed << std::setprecision(4)
<< m.sy / 65536.0 << " "
<< std::setw(fieldWidth) << std::fixed << std::setprecision(4)
- << TWIPS_TO_PIXELS(m.ty) << " |";
+ << twipsToPixels(m.ty) << " |";
return o;
}
=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp 2009-03-10 11:44:46 +0000
+++ b/libcore/TextField.cpp 2009-03-17 12:01:42 +0000
@@ -45,6 +45,7 @@
#include "GnashKey.h" // key::code
#include "TextRecord.h"
#include "Point2d.h"
+#include "GnashNumeric.h"
#include <algorithm> // std::min
#include <string>
@@ -599,9 +600,9 @@
break;
case NSV::PROP_uX:
{
- SWFMatrix m = getMatrix();
- double x = utility::infinite_to_zero( val.to_number() );
- m.tx = PIXELS_TO_TWIPS(x);
+ SWFMatrix m = getMatrix();
+ double x = infinite_to_zero( val.to_number() );
+ m.tx = pixelsToTwips(x);
setMatrix(m); // no need to update caches when only changing
translation
// m_accept_anim_moves = false;
@@ -609,9 +610,9 @@
}
case NSV::PROP_uY:
{
- SWFMatrix m = getMatrix();
- double y = utility::infinite_to_zero( val.to_number() );
- m.ty = PIXELS_TO_TWIPS(y);
+ SWFMatrix m = getMatrix();
+ double y = infinite_to_zero( val.to_number() );
+ m.ty = pixelsToTwips(y);
setMatrix(m); // no need to update caches when only changing
translation
// m_accept_anim_moves = false;
@@ -620,7 +621,7 @@
case NSV::PROP_uWIDTH:
{
double nw = val.to_number();
- if ( ! utility::isFinite(nw) )
+ if (!isFinite(nw) )
{
// might be our fault, see the TODO above
// (missing to pass as_environment out..)
@@ -639,7 +640,7 @@
nw = -nw;
}
- if ( _bounds.width() == PIXELS_TO_TWIPS(nw) )
+ if ( _bounds.width() == pixelsToTwips(nw) )
{
#ifdef GNASH_DEBUG_TEXTFIELDS
log_debug("TextField width already == %g, nothing to do to "
@@ -666,11 +667,11 @@
boost::int32_t xmin = _bounds.get_x_min();
boost::int32_t ymin = _bounds.get_y_min();
boost::int32_t ymax = _bounds.get_y_max();
- boost::int32_t xmax = xmin + PIXELS_TO_TWIPS(nw);
+ boost::int32_t xmax = xmin + pixelsToTwips(nw);
assert(xmin <= xmax);
_bounds.set_to_rect(xmin, ymin, xmax, ymax);
- assert( _bounds.width() == PIXELS_TO_TWIPS(nw) );
+ assert( _bounds.width() == pixelsToTwips(nw) );
// previously truncated text might get visible now
// TODO: if nested masks were implemented we would
@@ -682,7 +683,7 @@
case NSV::PROP_uHEIGHT:
{
double nh = val.to_number();
- if ( ! utility::isFinite(nh) )
+ if (!isFinite(nh) )
{
// might be our fault, see the TODO above (missing to pass
// as_environment out..)
@@ -701,7 +702,7 @@
nh = -nh;
}
- if ( _bounds.height() == PIXELS_TO_TWIPS(nh) )
+ if ( _bounds.height() == pixelsToTwips(nh) )
{
#ifdef GNASH_DEBUG_TEXTFIELDS
log_debug("TextField height already == %g, nothing to do to "
@@ -724,9 +725,9 @@
boost::int32_t xmin = _bounds.get_x_min();
boost::int32_t xmax = _bounds.get_x_max();
boost::int32_t ymin = _bounds.get_y_min();
- _bounds.set_to_rect(xmin, ymin, xmax, ymin + PIXELS_TO_TWIPS(nh) );
+ _bounds.set_to_rect(xmin, ymin, xmax, ymin + pixelsToTwips(nh) );
- assert(_bounds.height() == PIXELS_TO_TWIPS(nh));
+ assert(_bounds.height() == pixelsToTwips(nh));
// previously truncated text might get visible now
// TODO: if nested masks were implemented we would
@@ -784,18 +785,18 @@
case NSV::PROP_uX:
{
SWFMatrix m = getMatrix();
- val->set_double(TWIPS_TO_PIXELS(m.tx));
+ val->set_double(twipsToPixels(m.tx));
return true;
}
case NSV::PROP_uY:
{
SWFMatrix m = getMatrix();
- val->set_double(TWIPS_TO_PIXELS(m.ty));
+ val->set_double(twipsToPixels(m.ty));
return true;
}
case NSV::PROP_uWIDTH:
{
- val->set_double(TWIPS_TO_PIXELS(get_width()));
+ val->set_double(twipsToPixels(get_width()));
#ifdef GNASH_DEBUG_TEXTFIELDS
log_debug("Got TextField width == %s", *val);
#endif // GNASH_DEBUG_TEXTFIELDS
@@ -803,7 +804,7 @@
}
case NSV::PROP_uHEIGHT:
{
- val->set_double(TWIPS_TO_PIXELS(get_height()));
+ val->set_double(twipsToPixels(get_height()));
#ifdef GNASH_DEBUG_TEXTFIELDS
log_debug("Got TextField height == %s", *val);
#endif // GNASH_DEBUG_TEXTFIELDS
@@ -2188,7 +2189,7 @@
// bounding box.)
//
// In local coords. Verified against Macromedia Flash.
- return as_value(TWIPS_TO_PIXELS(ptr->getTextBoundingBox().height()));
+ return as_value(twipsToPixels(ptr->getTextBoundingBox().height()));
}
else // setter
@@ -2214,7 +2215,7 @@
// bounding box.)
//
// In local coords. Verified against Macromedia Flash.
- return as_value(TWIPS_TO_PIXELS(ptr->getTextBoundingBox().width()));
+ return as_value(twipsToPixels(ptr->getTextBoundingBox().width()));
}
else // setter
=== renamed file 'libcore/timers.cpp' => 'libcore/Timers.cpp'
--- a/libcore/timers.cpp 2009-02-25 22:33:03 +0000
+++ b/libcore/Timers.cpp 2009-03-17 09:44:00 +0000
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -8,21 +8,17 @@
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
//
//
//
-
-#include "timers.h"
-#include "as_function.h" // for class as_function
-#include "as_object.h" // for inheritance
+#include "Timers.h"
#include "log.h"
#include "fn_call.h"
#include "VM.h"
@@ -30,117 +26,114 @@
#include "action.h" // call_method
#include <limits> // for numeric_limits
+#include <functional>
+#include <algorithm>
namespace gnash {
- Timer::Timer() :
- _interval(0),
- _start(std::numeric_limits<unsigned long>::max()),
- _object(0),
- _runOnce(false)
- {
- }
-
- Timer::~Timer()
- {
- //log_debug("%s: \n", __FUNCTION__);
- }
-
- void
- Timer::setInterval(as_function& method, unsigned long ms,
boost::intrusive_ptr<as_object> this_ptr,
- ArgsContainer& args, bool runOnce)
- {
+Timer::Timer()
+ :
+ _interval(0),
+ _start(std::numeric_limits<unsigned long>::max()),
+ _object(0),
+ _runOnce(false)
+{
+}
+
+Timer::~Timer()
+{
+}
+
+void
+Timer::setInterval(as_function& method, unsigned long ms,
+ boost::intrusive_ptr<as_object> this_ptr,
+ ArgsContainer& args, bool runOnce)
+{
_function = &method;
_interval = ms; // keep as milliseconds
- //log_debug("_interval milliseconds: %llu", _interval);
_object = this_ptr;
_args = args;
_runOnce = runOnce;
start();
- }
+}
- void
- Timer::setInterval(as_function& method, unsigned long ms,
boost::intrusive_ptr<as_object> this_ptr, bool runOnce)
- {
+void
+Timer::setInterval(as_function& method, unsigned long ms,
+ boost::intrusive_ptr<as_object> this_ptr, bool runOnce)
+{
_function = &method;
_interval = ms; // keep as milliseconds
- //log_debug("_interval milliseconds: %llu", _interval);
_object = this_ptr;
_runOnce = runOnce;
start();
- }
+}
- void
- Timer::setInterval(boost::intrusive_ptr<as_object> this_ptr, const
std::string& methodName, unsigned long ms,
- std::vector<as_value>& args, bool runOnce)
- {
+void
+Timer::setInterval(boost::intrusive_ptr<as_object> this_ptr,
+ const std::string& methodName, unsigned long ms,
+ std::vector<as_value>& args, bool runOnce)
+{
_object = this_ptr;
_methodName = methodName;
_interval = ms; // keep as milliseconds
- //log_debug("_interval milliseconds: %llu", _interval);
_args = args;
_runOnce = runOnce;
start();
- }
+}
- void
- Timer::clearInterval()
- {
+void
+Timer::clearInterval()
+{
_interval = 0;
_start = std::numeric_limits<unsigned long>::max();
- }
-
- void
- Timer::start()
- {
- _start = _object->getVM().getTime();
- //log_debug("_start at seconds %lu", _start);
- }
-
+}
+
+void
+Timer::start()
+{
+ _start = _object->getVM().getTime();
+}
+
bool
Timer::expired(unsigned long now, unsigned long& elapsed)
{
- if ( cleared() ) return false;
- long unsigned expTime = _start + _interval;
- if ( now < expTime ) return false;
- elapsed = expTime-now;
- return true;
+ if ( cleared() ) return false;
+ long unsigned expTime = _start + _interval;
+ if ( now < expTime ) return false;
+ elapsed = expTime-now;
+ return true;
}
void
Timer::executeAndReset()
{
- if ( cleared() ) return;
- execute();
- if ( _runOnce ) clearInterval();
- else _start += _interval; // reset the timer
+ if ( cleared() ) return;
+ execute();
+ if ( _runOnce ) clearInterval();
+ else _start += _interval; // reset the timer
}
void
Timer::execute()
{
- //printf("FIXME: %s:\n", __FUNCTION__);
- //log_debug("INTERVAL ID is %d\n", getIntervalID());
as_value timer_method;
as_object* super = _object->get_super(_function ? 0 : _methodName.c_str());
VM& vm = _object->getVM();
- if ( _function.get() )
- {
+ if (_function.get() ) {
timer_method.set_as_function(_function.get());
}
- else
- {
+ else {
string_table::key k = vm.getStringTable().find(_methodName);
as_value tmp;
if ( ! _object->get_member(k, &tmp) )
{
IF_VERBOSE_ASCODING_ERRORS(
log_aserror("object %p has no member named %s (interval method)",
- _object, _methodName);
+ _object, _methodName);
);
return;
}
@@ -148,8 +141,8 @@
if ( ! f )
{
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("member %s of object %p (interval method) is not a
function (%s)",
- _methodName, (void*)_object.get(), tmp);
+ log_aserror("member %s of object %p (interval method) is not "
+ "a function (%s)", _methodName, (void*)_object.get(), tmp);
);
return;
}
@@ -159,15 +152,14 @@
as_environment env(vm);
// Prepare args
- std::auto_ptr< std::vector<as_value> > args ( new std::vector<as_value> );
+ std::auto_ptr<std::vector<as_value> > args ( new std::vector<as_value> );
for ( ArgsContainer::iterator it=_args.begin(), itEnd=_args.end();
- it != itEnd; ++it )
+ it != itEnd; ++it )
{
- //log_debug("Env-pushing %s", *it);
- args->push_back(*it);
+ //log_debug("Env-pushing %s", *it);
+ args->push_back(*it);
}
- /* as_value val = */
call_method(timer_method, &env, _object.get(), args, super);
}
@@ -176,197 +168,12 @@
void
Timer::markReachableResources() const
{
- for (ArgsContainer::const_iterator i=_args.begin(), e=_args.end();
- i!=e; ++i)
- {
- i->setReachable();
- }
+ std::for_each(_args.begin(), _args.end(),
+ std::mem_fun_ref(&as_value::setReachable));
- if ( _function ) _function->setReachable();
- if ( _object ) _object->setReachable();
+ if (_function) _function->setReachable();
+ if (_object) _object->setReachable();
}
#endif // GNASH_USE_GC
-// TODO: move to Global.cpp
-as_value
-timer_setinterval(const fn_call& fn)
-{
- //std::stringstream ss; fn.dump_args(ss);
- //log_debug("setInterval(%s)", ss.str());
-
- //log_debug("%s: args=%d", __FUNCTION__, fn.nargs);
-
- if ( fn.nargs < 2 )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setInterval(%s) "
- "- need at least 2 arguments",
- ss.str());
- );
- return as_value();
- }
-
- unsigned timer_arg = 1;
-
- boost::intrusive_ptr<as_object> obj = fn.arg(0).to_object();
- if ( ! obj )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setInterval(%s) "
- "- first argument is not an object or function",
- ss.str());
- );
- return as_value();
- }
-
- std::string methodName;
-
- // Get interval function
- boost::intrusive_ptr<as_function> as_func = obj->to_function();
- if ( ! as_func )
- {
- methodName = fn.arg(1).to_string();
- timer_arg = 2;
- }
-
-
- if ( fn.nargs < timer_arg+1 )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setInterval(%s) "
- "- missing timeout argument",
- ss.str());
- );
- return as_value();
- }
-
- // Get interval time
- unsigned long ms = static_cast<unsigned
long>(fn.arg(timer_arg).to_number());
- // TODO: check validity of interval time number ?
-
- // Parse arguments
- Timer::ArgsContainer args;
- for (unsigned i=timer_arg+1; i<fn.nargs; ++i)
- {
- args.push_back(fn.arg(i));
- }
-
- std::auto_ptr<Timer> timer(new Timer);
- if ( as_func )
- {
- // TODO: 'this_ptr' should be NULL/undefined in this case
- timer->setInterval(*as_func, ms, fn.this_ptr, args);
- }
- else
- {
- timer->setInterval(obj, methodName, ms, args);
- }
-
-
- movie_root& root = fn.env().getVM().getRoot();
- int id = root.add_interval_timer(timer);
- return as_value(id);
-}
-
-// TODO: move to Global.cpp
-as_value
-timer_settimeout(const fn_call& fn)
-{
- //std::stringstream ss; fn.dump_args(ss);
- //log_debug("setTimeout(%s)", ss.str());
-
- //log_debug("%s: args=%d", __FUNCTION__, fn.nargs);
-
- if ( fn.nargs < 2 )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setTimeout(%s) "
- "- need at least 2 arguments",
- ss.str());
- );
- return as_value();
- }
-
- unsigned timer_arg = 1;
-
- boost::intrusive_ptr<as_object> obj = fn.arg(0).to_object();
- if ( ! obj )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setInterval(%s) "
- "- first argument is not an object or function",
- ss.str());
- );
- return as_value();
- }
-
- std::string methodName;
-
- // Get interval function
- boost::intrusive_ptr<as_function> as_func = obj->to_function();
- if ( ! as_func )
- {
- methodName = fn.arg(1).to_string();
- timer_arg = 2;
- }
-
-
- if ( fn.nargs < timer_arg+1 )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror("Invalid call to setTimeout(%s) "
- "- missing timeout argument",
- ss.str());
- );
- return as_value();
- }
-
- // Get interval time
- unsigned long ms = static_cast<unsigned
long>(fn.arg(timer_arg).to_number());
- // TODO: check validity of interval time number ?
-
- // Parse arguments
- Timer::ArgsContainer args;
- for (unsigned i=timer_arg+1; i<fn.nargs; ++i)
- {
- args.push_back(fn.arg(i));
- }
-
- std::auto_ptr<Timer> timer(new Timer);
- if ( as_func )
- {
- // TODO: 'this_ptr' should be NULL/undefined in this case
- timer->setInterval(*as_func, ms, fn.this_ptr, args, true);
- }
- else
- {
- timer->setInterval(obj, methodName, ms, args, true);
- }
-
-
- movie_root& root = fn.env().getVM().getRoot();
-
- int id = root.add_interval_timer(timer);
- return as_value(id);
-}
-
-// TODO: move to Global.cpp
-as_value
-timer_clearinterval(const fn_call& fn)
-{
- //log_debug("%s: nargs = %d", __FUNCTION__, fn.nargs);
-
- int id = int(fn.arg(0).to_number());
-
- movie_root& root = fn.env().getVM().getRoot();
- bool ret = root.clear_interval_timer(id);
- return as_value(ret);
-}
-
} // namespace gnash
=== renamed file 'libcore/timers.h' => 'libcore/Timers.h'
--- a/libcore/timers.h 2009-02-25 22:33:03 +0000
+++ b/libcore/Timers.h 2009-03-17 09:44:00 +0000
@@ -19,11 +19,9 @@
#define HAVE_TIMERS_H
#include "dsodefs.h"
-
-#include "as_value.h" // for struct variable composition
-#include "as_object.h" // for inheritance
-#include "as_function.h" // for visibility of destructor by intrusive_ptr
-#include "smart_ptr.h" // GNASH_USE_GC
+#include "as_object.h"
+#include "as_function.h"
+#include "smart_ptr.h"
#include <string>
#include <vector>
@@ -31,7 +29,6 @@
// Forward declarations
namespace gnash {
- class fn_call;
class as_function;
}
@@ -52,194 +49,184 @@
/// function at regular intervals. As a facility, the Timer class provides
/// an execution operator, proxying the execution to the associated function
/// with properly set-up context.
-///
-///
class DSOEXPORT Timer
{
-
public:
-
- /// Construct a disabled (cleared) timer.
- Timer();
-
- ~Timer();
-
- /// Setup the Timer, enabling it.
- //
- /// @param method
- /// The function to call from execution operator.
- /// Will be stored in an intrusive_ptr.
- ///
- /// @param ms
- /// The number of milliseconds between expires.
- ///
- /// @param this_ptr
- /// The object to be used as 'this' pointer when calling the
- /// associated function. Will be stored in an intrusive_ptr.
- /// It is allowed to be NULL as long as fn_call is allowed
- /// a NULL as 'this_ptr' (we might want to change this).
- ///
- /// @param runOnce
- /// If true the interval will run only once. False if omitted.
- ///
- void setInterval(as_function& method, unsigned long ms,
boost::intrusive_ptr<as_object> this_ptr, bool runOnce=false);
-
- /// Setup the Timer, enabling it.
- //
- /// @param method
- /// The function to call from execution operator.
- /// Will be stored in an intrusive_ptr.
- ///
- /// @param ms
- /// The number of milliseconds between expires.
- ///
- /// @param this_ptr
- /// The object to be used as 'this' pointer when calling the
- /// associated function. Will be stored in an intrusive_ptr.
- /// It is allowed to be NULL as long as fn_call is allowed
- /// a NULL as 'this_ptr' (we might want to change this).
- ///
- /// @param args
- /// The list of arguments to pass to the function being invoked.
- ///
- /// @param runOnce
- /// If true the interval will run only once. False if omitted.
- ///
- void setInterval(as_function& method, unsigned long ms,
boost::intrusive_ptr<as_object> this_ptr,
- std::vector<as_value>& args, bool runOnce=false);
-
- /// Setup the Timer to call a late-evaluated object method, enabling it.
- //
- /// @param this_ptr
- /// The object to be used as 'this' pointer when calling the
- /// associated function. Will be stored in an intrusive_ptr.
- /// It is allowed to be NULL as long as fn_call is allowed
- /// a NULL as 'this_ptr' (we might want to change this).
- ///
- /// @param methodName
- /// The method name to call from execution operator.
- ///
- /// @param ms
- /// The number of milliseconds between expires.
- ///
- /// @param args
- /// The list of arguments to pass to the function being invoked.
- ///
- /// @param runOnce
- /// If true the interval will run only once. False if omitted.
- ///
- void setInterval(boost::intrusive_ptr<as_object> obj, const std::string&
methodName, unsigned long ms,
- std::vector<as_value>& args, bool runOnce=false);
-
- /// Clear the timer, ready for reuse
- //
- /// When a Timer is cleared, the expired() function
- /// will always return false.
- ///
- /// Use setInterval() to reset it.
- ///
- void clearInterval();
-
- /// Get expiration state
- //
- /// @param now
- /// Current time, in milliseconds.
- ///
- /// @param elapsed
- /// Output parameter, will be set to the amount of milliseconds
- /// elapsed since actual expiration, if expired.
- ///
- /// @return true if the timer expired, false otherwise.
- ///
- bool expired(unsigned long now, unsigned long& elapsed);
-
- /// Return true if interval has been cleared.
- //
- /// Note that the timer is constructed as cleared and you
- /// need to call setInterval() to make it not-cleared.
- bool cleared() const
- {
- return _start == std::numeric_limits<unsigned long>::max();
- }
-
- /// Execute associated function and reset state
- //
- /// After execution either the timer is cleared
- /// (if runOnce) or start time is incremented
- /// by the interval.
- ///
- /// NOTE: if the timer is cleared this call
- /// results in a no-op.
- ///
- void executeAndReset();
-
- /// Arguments list type
- typedef std::vector<as_value> ArgsContainer;
+
+ /// Arguments list type
+ typedef std::vector<as_value> ArgsContainer;
+
+ /// Construct a disabled (cleared) timer.
+ Timer();
+
+ ~Timer();
+
+ /// Setup the Timer, enabling it.
+ //
+ /// @param method
+ /// The function to call from execution operator.
+ /// Will be stored in an intrusive_ptr.
+ ///
+ /// @param ms
+ /// The number of milliseconds between expires.
+ ///
+ /// @param this_ptr
+ /// The object to be used as 'this' pointer when calling the
+ /// associated function. Will be stored in an intrusive_ptr.
+ /// It is allowed to be NULL as long as fn_call is allowed
+ /// a NULL as 'this_ptr' (we might want to change this).
+ ///
+ /// @param runOnce
+ /// If true the interval will run only once. False if omitted.
+ void setInterval(as_function& method, unsigned long ms,
+ boost::intrusive_ptr<as_object> this_ptr, bool runOnce = false);
+
+ /// Setup the Timer, enabling it.
+ //
+ /// @param method
+ /// The function to call from execution operator.
+ /// Will be stored in an intrusive_ptr.
+ ///
+ /// @param ms
+ /// The number of milliseconds between expires.
+ ///
+ /// @param this_ptr
+ /// The object to be used as 'this' pointer when calling the
+ /// associated function. Will be stored in an intrusive_ptr.
+ /// It is allowed to be NULL as long as fn_call is allowed
+ /// a NULL as 'this_ptr' (we might want to change this).
+ ///
+ /// @param args
+ /// The list of arguments to pass to the function being invoked.
+ ///
+ /// @param runOnce
+ /// If true the interval will run only once. False if omitted.
+ void setInterval(as_function& method, unsigned long ms,
+ boost::intrusive_ptr<as_object> this_ptr,
+ std::vector<as_value>& args, bool runOnce = false);
+
+ /// Setup the Timer to call a late-evaluated object method, enabling it.
+ //
+ /// @param this_ptr
+ /// The object to be used as 'this' pointer when calling the
+ /// associated function. Will be stored in an intrusive_ptr.
+ /// It is allowed to be NULL as long as fn_call is allowed
+ /// a NULL as 'this_ptr' (we might want to change this).
+ ///
+ /// @param methodName
+ /// The method name to call from execution operator.
+ ///
+ /// @param ms
+ /// The number of milliseconds between expires.
+ ///
+ /// @param args
+ /// The list of arguments to pass to the function being invoked.
+ ///
+ /// @param runOnce
+ /// If true the interval will run only once. False if omitted.
+ void setInterval(boost::intrusive_ptr<as_object> obj,
+ const std::string& methodName, unsigned long ms,
+ std::vector<as_value>& args, bool runOnce = false);
+
+ /// Clear the timer, ready for reuse
+ //
+ /// When a Timer is cleared, the expired() function
+ /// will always return false.
+ ///
+ /// Use setInterval() to reset it.
+ ///
+ void clearInterval();
+
+ /// Get expiration state
+ // /// @param now
+ /// Current time, in milliseconds.
+ ///
+ /// @param elapsed
+ /// Output parameter, will be set to the amount of milliseconds
+ /// elapsed since actual expiration, if expired.
+ ///
+ /// @return true if the timer expired, false otherwise.
+ ///
+ bool expired(unsigned long now, unsigned long& elapsed);
+
+ /// Return true if interval has been cleared.
+ //
+ /// Note that the timer is constructed as cleared and you
+ /// need to call setInterval() to make it not-cleared.
+ bool cleared() const {
+ return _start == std::numeric_limits<unsigned long>::max();
+ }
+
+ /// Execute associated function and reset state
+ //
+ /// After execution either the timer is cleared
+ /// (if runOnce) or start time is incremented
+ /// by the interval.
+ ///
+ /// NOTE: if the timer is cleared this call
+ /// results in a no-op.
+ ///
+ void executeAndReset();
#ifdef GNASH_USE_GC
- /// Mark all reachable resources (for GC)
- //
- /// Resources reachable from Timer are:
- ///
- /// - Arguments list (_args)
- /// - Associated function (_function)
- /// - Target object (_object)
- ///
- void markReachableResources() const;
+ /// Mark all reachable resources (for GC)
+ //
+ /// Resources reachable from Timer are:
+ ///
+ /// - Arguments list (_args)
+ /// - Associated function (_function)
+ /// - Target object (_object)
+ ///
+ void markReachableResources() const;
#endif // GNASH_USE_GC
private:
- /// Execute associated function properly setting up context
- void execute();
-
- /// Execute associated function properly setting up context
- void operator() () { execute(); }
-
- /// Return number of milliseconds between expirations
- unsigned long getInterval() const { return _interval; }
-
- /// Return number of milliseconds after VM start this timer was last
reset
- unsigned long getStart() const { return _start; }
-
-
- /// Set timer start
- //
- /// Called by every function setting the interval.
- ///
- void start();
-
- /// Number of milliseconds between expirations
- unsigned int _interval;
-
- /// Number of milliseconds since epoch at Timer start
- //
- /// This will be numeric_limits<unsigned long>::max()
- /// if the timer is not active (or cleared)
- ///
- unsigned long _start;
-
- /// The associated function (if statically-bound) stored in an intrusive
pointer
- boost::intrusive_ptr<as_function> _function;
-
- /// The associated method name, stored in an intrusive pointer
- std::string _methodName;
-
- /// Context for the function call. Will be used as 'this' pointer.
- boost::intrusive_ptr<as_object> _object;
-
- /// List of arguments
- ArgsContainer _args;
-
- /// True if the timer should execute only once (for setTimeout)
- bool _runOnce;
+ /// Execute associated function properly setting up context
+ void execute();
+
+ /// Execute associated function properly setting up context
+ void operator() () { execute(); }
+
+ /// Return number of milliseconds between expirations
+ unsigned long getInterval() const { return _interval; }
+
+ /// Return number of milliseconds after VM start this timer was last reset
+ unsigned long getStart() const { return _start; }
+
+ /// Set timer start
+ //
+ /// Called by every function setting the interval.
+ ///
+ void start();
+
+ /// Number of milliseconds between expirations
+ unsigned int _interval;
+
+ /// Number of milliseconds since epoch at Timer start
+ //
+ /// This will be numeric_limits<unsigned long>::max()
+ /// if the timer is not active (or cleared)
+ ///
+ unsigned long _start;
+
+ /// The associated function (if statically-bound) stored in
+ /// an intrusive pointer
+ boost::intrusive_ptr<as_function> _function;
+
+ /// The associated method name, stored in an intrusive pointer
+ std::string _methodName;
+
+ /// Context for the function call. Will be used as 'this' pointer.
+ boost::intrusive_ptr<as_object> _object;
+
+ /// List of arguments
+ ArgsContainer _args;
+
+ /// True if the timer should execute only once (for setTimeout)
+ bool _runOnce;
};
- as_value timer_setinterval(const fn_call& fn);
- as_value timer_settimeout(const fn_call& fn);
- as_value timer_clearinterval(const fn_call& fn);
-
-} // end of namespace gnash
+} // namespace gnash
- // HAVE_TIMERS_H
#endif
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/as_value.cpp 2009-03-17 11:39:48 +0000
@@ -30,7 +30,8 @@
#include "Number_as.h" // for automatic as_value::NUMBER => Number
#include "Boolean_as.h" // for automatic as_value::BOOLEAN => Boolean
#include "action.h" // for call_method0
-#include "utility.h" // for typeName() and utility::isFinite
+#include "utility.h" // for typeName()
+#include "GnashNumeric.h"
#include "namedStrings.h"
#include "element.h"
#include "GnashException.h"
@@ -894,7 +895,7 @@
{
double d = to_number();
- if ( ! utility::isFinite(d) ) return 0;
+ if (!isFinite(d)) return 0;
return truncateToInt(d);
}
@@ -1234,7 +1235,7 @@
if (m_type == NUMBER && v.m_type == STRING)
{
double n = v.to_number();
- if ( ! utility::isFinite(n) ) return false;
+ if (!isFinite(n)) return false;
return equalsSameType(n);
}
@@ -1243,8 +1244,8 @@
if (v.m_type == NUMBER && m_type == STRING)
{
double n = to_number();
- if ( ! utility::isFinite(n) ) return false;
- return v.equalsSameType(n);
+ if (!isFinite(n)) return false;
+ return v.equalsSameType(n);
}
// 18. If Type(x) is Boolean, return the result of the comparison
ToNumber(x) == y.
=== modified file 'libcore/asobj/Array_as.cpp'
--- a/libcore/asobj/Array_as.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/Array_as.cpp 2009-03-17 11:39:48 +0000
@@ -32,6 +32,7 @@
#include "action.h" // for call_method
#include "VM.h" // for PROPNAME, registerNative
#include "Object.h" // for getObjectInterface()
+#include "GnashNumeric.h"
#include <string>
#include <algorithm>
@@ -591,7 +592,7 @@
double value = temp.to_number();
// if we were sent a string that can't convert like "asdf", it returns as
NaN. -1 means invalid index
- if (!utility::isFinite(value)) return -1;
+ if (!isFinite(value)) return -1;
return int(value);
}
@@ -914,7 +915,7 @@
unsigned startoffset;
int start = fn.arg(0).to_int();
if ( start < 0 ) start = array->size()+start; // start is negative, so +
means -abs()
- startoffset = utility::clamp<int>(start, 0, origlen);
+ startoffset = clamp<int>(start, 0, origlen);
#ifdef GNASH_DEBUG
if ( startoffset != start )
log_debug(_("Array.splice: start:%d became %u"), start, startoffset);
@@ -935,7 +936,7 @@
);
return as_value();
}
- len = utility::clamp<int>(lenval, 0, origlen-startoffset);
+ len = clamp<int>(lenval, 0, origlen-startoffset);
}
//----------------
=== modified file 'libcore/asobj/ClassHierarchy.cpp'
--- a/libcore/asobj/ClassHierarchy.cpp 2009-03-04 17:52:33 +0000
+++ b/libcore/asobj/ClassHierarchy.cpp 2009-03-17 09:44:00 +0000
@@ -54,7 +54,6 @@
#include "Video.h"
#include "extension.h"
#include "VM.h"
-#include "timers.h"
#include "URL.h" // for URL::encode and URL::decode (escape/unescape)
#include "builtin_function.h"
#include "TextField.h"
=== modified file 'libcore/asobj/Date_as.cpp'
--- a/libcore/asobj/Date_as.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/Date_as.cpp 2009-03-17 11:39:48 +0000
@@ -68,7 +68,7 @@
#endif
#include "log.h"
-#include "utility.h"
+#include "GnashNumeric.h"
#include "Date_as.h"
#include "fn_call.h"
#include "GnashException.h"
@@ -732,7 +732,7 @@
const double magicMaxValue = 8.64e+15;
double d = fn.arg(0).to_number();
- if (!utility::isFinite(d) || std::abs(d) > magicMaxValue) {
+ if (!isFinite(d) || std::abs(d) > magicMaxValue) {
date->setTimeValue(NaN);
}
else {
=== modified file 'libcore/asobj/Global.cpp'
--- a/libcore/asobj/Global.cpp 2009-02-10 16:01:43 +0000
+++ b/libcore/asobj/Global.cpp 2009-03-17 11:39:48 +0000
@@ -58,14 +58,14 @@
#include "Video.h"
#include "extension.h"
#include "VM.h"
-#include "timers.h"
+#include "Timers.h"
#include "URL.h" // for URL::encode and URL::decode (escape/unescape)
#include "builtin_function.h"
#include "TextField.h"
#include "rc.h"
#include "ClassHierarchy.h"
#include "namedStrings.h"
-#include "utility.h" // for isfinite replacement
+#include "GnashNumeric.h" // for isfinite replacement
#include "flash_pkg.h"
#include "fn_call.h"
@@ -92,22 +92,26 @@
namespace gnash {
// Forward declarations
-static as_value as_global_trace(const fn_call& fn);
-static as_value as_global_isNaN(const fn_call& fn);
-static as_value as_global_isfinite(const fn_call& fn);
-static as_value as_global_unescape(const fn_call& fn);
-static as_value as_global_escape(const fn_call& fn);
-static as_value as_global_parsefloat(const fn_call& fn);
-static as_value as_global_parseint(const fn_call& fn);
-static as_value as_global_assetpropflags(const fn_call& fn);
-static as_value as_global_asnative(const fn_call& fn);
-static as_value as_global_asnew(const fn_call& /*fn*/);
-static as_value as_global_assetnative(const fn_call& /*fn*/);
-static as_value as_global_assetnativeaccessor(const fn_call& /*fn*/);
-static as_value as_global_asconstructor(const fn_call& /*fn*/);
-static as_value as_global_updateAfterEvent(const fn_call& /*fn*/);
-
namespace {
+ as_value global_trace(const fn_call& fn);
+ as_value global_isNaN(const fn_call& fn);
+ as_value global_isfinite(const fn_call& fn);
+ as_value global_unescape(const fn_call& fn);
+ as_value global_escape(const fn_call& fn);
+ as_value global_parsefloat(const fn_call& fn);
+ as_value global_parseint(const fn_call& fn);
+ as_value global_assetpropflags(const fn_call& fn);
+ as_value global_asnative(const fn_call& fn);
+ as_value global_asnew(const fn_call& fn);
+ as_value global_assetnative(const fn_call& fn);
+ as_value global_assetnativeaccessor(const fn_call& fn);
+ as_value global_asconstructor(const fn_call& fn);
+ as_value global_updateAfterEvent(const fn_call& fn);
+ as_value global_setTimeout(const fn_call& fn);
+ as_value global_clearTimeout(const fn_call& fn);
+ as_value global_clearInterval(const fn_call& fn);
+ as_value global_setInterval(const fn_call& fn);
+
void registerNatives(as_object& global);
}
@@ -130,19 +134,18 @@
// These functions are only available in SWF6+, but this is just
// because SWF5 or lower did not have a "_global"
// reference at all.
- init_member("ASnative", new builtin_function(as_global_asnative));
- init_member("ASconstructor", new
builtin_function(as_global_asconstructor));
+ init_member("ASnative", new builtin_function(global_asnative));
+ init_member("ASconstructor", new builtin_function(global_asconstructor));
init_member("ASSetPropFlags", vm.getNative(1, 0));
init_member("ASSetNative", vm.getNative(4, 0));
init_member("ASSetNativeAccessor", vm.getNative(4, 1));
init_member("updateAfterEvent", vm.getNative(9, 0));
init_member("trace", vm.getNative(100, 4));
- // Defined in timers.h
init_member("setInterval", vm.getNative(250, 0));
init_member("clearInterval", vm.getNative(250, 1));
- init_member("setTimeout", new builtin_function(timer_settimeout));
- init_member("clearTimeout", new builtin_function(timer_clearinterval));
+ init_member("setTimeout", new builtin_function(global_setTimeout));
+ init_member("clearTimeout", new builtin_function(global_clearInterval));
ch->setGlobal(this);
@@ -240,9 +243,10 @@
#endif
+namespace {
as_value
-as_global_trace(const fn_call& fn)
+global_trace(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
@@ -259,20 +263,20 @@
as_value
-as_global_isNaN(const fn_call& fn)
+global_isNaN(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
- return as_value( static_cast<bool>(isNaN(fn.arg(0).to_number()) ));
+ return as_value(static_cast<bool>(isNaN(fn.arg(0).to_number())));
}
as_value
-as_global_isfinite(const fn_call& fn)
+global_isfinite(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
- return as_value(
static_cast<bool>(utility::isFinite(fn.arg(0).to_number())) );
+ return as_value(static_cast<bool>(isFinite(fn.arg(0).to_number())));
}
/// \brief Encode a string to URL-encoded format
@@ -287,7 +291,7 @@
/// See RFC1738 http://www.rfc-editor.org/rfc/rfc1738.txt,
/// Section 2.2 "URL Character Encoding Issues"
as_value
-as_global_escape(const fn_call& fn)
+global_escape(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
@@ -304,7 +308,7 @@
/// See RFC1738 http://www.rfc-editor.org/rfc/rfc1738.txt,
/// Section 2.2 "URL Character Encoding Issues"
as_value
-as_global_unescape(const fn_call& fn)
+global_unescape(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
@@ -315,23 +319,18 @@
// parseFloat (string)
as_value
-as_global_parsefloat(const fn_call& fn)
+global_parsefloat(const fn_call& fn)
{
ASSERT_FN_ARGS_IS_1
-
- as_value rv;
+
+ std::istringstream s(fn.arg(0).to_string());
double result;
- std::istringstream s(fn.arg(0).to_string());
-
- if ( ! (s >> result) )
- {
- rv.set_nan();
- return rv;
+ if (!(s >> result)) {
+ return as_value(NaN);
}
- rv = result;
- return rv;
+ return as_value(result);
}
// parseInt(string[, base])
@@ -347,7 +346,7 @@
// 4. If the string starts with *any* other sequence of characters, including
// whitespace, it is decimal.
as_value
-as_global_parseint(const fn_call& fn)
+global_parseint(const fn_call& fn)
{
if (!fn.nargs) {
IF_VERBOSE_ASCODING_ERRORS(
@@ -384,8 +383,7 @@
double d;
if (as_value::parseNonDecimalInt(expr, d, false)) return d;
}
- catch (boost::bad_lexical_cast&)
- {
+ catch (boost::bad_lexical_cast&) {
return as_value(NaN);
}
@@ -441,8 +439,7 @@
++it;
while (it != expr.end() && (digit = digits.find(toupper(*it))) < base
- && digit != std::string::npos)
- {
+ && digit != std::string::npos) {
result = result * base + digit;
++it;
}
@@ -453,29 +450,25 @@
// ASSetPropFlags function
as_value
-as_global_assetpropflags(const fn_call& fn)
+global_assetpropflags(const fn_call& fn)
{
- //log_debug(_("ASSetPropFlags called with %d args"), fn.nargs);
-
- // Check the arguments
- // assert(fn.nargs == 3 || fn.nargs == 4);
- // assert((version == 5) ? (fn.nargs == 3) : true);
if (fn.nargs < 3) {
- IF_VERBOSE_ASCODING_ERRORS(
+ IF_VERBOSE_ASCODING_ERRORS(
log_aserror(_("%s needs at least three arguments"), __FUNCTION__);
- )
- return as_value();
+ )
+ return as_value();
}
+
IF_VERBOSE_ASCODING_ERRORS(
- if (fn.nargs > 4)
- log_aserror(_("%s has more than four arguments"), __FUNCTION__);
- )
+ if (fn.nargs > 4) {
+ log_aserror(_("%s has more than four arguments"),
"AsSetPropFlags");
+ }
+ );
// object
boost::intrusive_ptr<as_object> obj = fn.arg(0).to_object();
- if ( ! obj )
- {
+ if ( ! obj ) {
IF_VERBOSE_ASCODING_ERRORS(
log_aserror(_("Invalid call to ASSetPropFlags: "
"first argument is not an object: %s"),
@@ -520,7 +513,7 @@
// ASNative function
// See: http://osflash.org/flashcoders/undocumented/asnative?s=asnative
as_value
-as_global_asnative(const fn_call& fn)
+global_asnative(const fn_call& fn)
{
as_value ret;
@@ -568,7 +561,7 @@
// Obsolete ASnew function (exists only as ASnative(2, 0))
as_value
-as_global_asnew(const fn_call& /*fn*/)
+global_asnew(const fn_call& /*fn*/)
{
LOG_ONCE(log_unimpl("ASNative (2, 0) - old ASnew"));
return as_value();
@@ -577,7 +570,7 @@
// ASSetNative function
// TODO: find dox
as_value
-as_global_assetnative(const fn_call& /*fn*/)
+global_assetnative(const fn_call& /*fn*/)
{
LOG_ONCE(log_unimpl("ASSetNative"));
return as_value();
@@ -586,7 +579,7 @@
// ASSetNativeAccessor function
// TODO: find dox
as_value
-as_global_assetnativeaccessor(const fn_call& /*fn*/)
+global_assetnativeaccessor(const fn_call& /*fn*/)
{
LOG_ONCE(log_unimpl("ASSetNativeAccessor"));
return as_value();
@@ -595,7 +588,7 @@
// ASconstructor function
// TODO: find dox
as_value
-as_global_asconstructor(const fn_call& /*fn*/)
+global_asconstructor(const fn_call& /*fn*/)
{
LOG_ONCE(log_unimpl("ASconstructor"));
return as_value();
@@ -604,13 +597,170 @@
// updateAfterEvent function
as_value
-as_global_updateAfterEvent(const fn_call& /*fn*/)
+global_updateAfterEvent(const fn_call& /*fn*/)
{
LOG_ONCE(log_unimpl("updateAfterEvent()"));
return as_value();
}
-namespace {
+as_value
+global_setInterval(const fn_call& fn)
+{
+
+ if (fn.nargs < 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setInterval(%s) "
+ "- need at least 2 arguments",
+ ss.str());
+ );
+ return as_value();
+ }
+
+ unsigned timer_arg = 1;
+
+ boost::intrusive_ptr<as_object> obj = fn.arg(0).to_object();
+ if ( ! obj )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setInterval(%s) "
+ "- first argument is not an object or function",
+ ss.str());
+ );
+ return as_value();
+ }
+
+ std::string methodName;
+
+ // Get interval function
+ boost::intrusive_ptr<as_function> as_func = obj->to_function();
+ if (!as_func) {
+ methodName = fn.arg(1).to_string();
+ timer_arg = 2;
+ }
+
+
+ if (fn.nargs < timer_arg + 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setInterval(%s) "
+ "- missing timeout argument",
+ ss.str());
+ );
+ return as_value();
+ }
+
+ // Get interval time
+ unsigned long ms =
+ static_cast<unsigned long>(fn.arg(timer_arg).to_number());
+ // TODO: check validity of interval time number ?
+
+ // Parse arguments
+ Timer::ArgsContainer args;
+ for (unsigned i=timer_arg+1; i<fn.nargs; ++i) {
+ args.push_back(fn.arg(i));
+ }
+
+ std::auto_ptr<Timer> timer(new Timer);
+ if (as_func) {
+ timer->setInterval(*as_func, ms, fn.this_ptr, args);
+ }
+ else {
+ timer->setInterval(obj, methodName, ms, args);
+ }
+
+
+ movie_root& root = fn.env().getVM().getRoot();
+ int id = root.add_interval_timer(timer);
+ return as_value(id);
+}
+
+// TODO: move to Global.cpp
+as_value
+global_setTimeout(const fn_call& fn)
+{
+
+ if (fn.nargs < 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setTimeout(%s) "
+ "- need at least 2 arguments",
+ ss.str());
+ );
+ return as_value();
+ }
+
+ unsigned timer_arg = 1;
+
+ boost::intrusive_ptr<as_object> obj = fn.arg(0).to_object();
+ if (!obj) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setInterval(%s) "
+ "- first argument is not an object or function",
+ ss.str());
+ );
+ return as_value();
+ }
+
+ std::string methodName;
+
+ // Get interval function
+ boost::intrusive_ptr<as_function> as_func = obj->to_function();
+ if (!as_func) {
+ methodName = fn.arg(1).to_string();
+ timer_arg = 2;
+ }
+
+
+ if (fn.nargs < timer_arg + 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("Invalid call to setTimeout(%s): missing "
+ "timeout argument", ss.str());
+ );
+ return as_value();
+ }
+
+ // Get interval time
+ unsigned long ms =
+ static_cast<unsigned long>(fn.arg(timer_arg).to_number());
+
+ // Parse arguments
+ Timer::ArgsContainer args;
+ for (unsigned i=timer_arg+1; i<fn.nargs; ++i) {
+ args.push_back(fn.arg(i));
+ }
+
+ std::auto_ptr<Timer> timer(new Timer);
+ if (as_func) {
+ timer->setInterval(*as_func, ms, fn.this_ptr, args, true);
+ }
+ else {
+ timer->setInterval(obj, methodName, ms, args, true);
+ }
+
+
+ movie_root& root = fn.env().getVM().getRoot();
+
+ int id = root.add_interval_timer(timer);
+ return as_value(id);
+}
+
+as_value
+global_clearInterval(const fn_call& fn)
+{
+ //log_debug("%s: nargs = %d", __FUNCTION__, fn.nargs);
+
+ int id = int(fn.arg(0).to_number());
+
+ movie_root& root = fn.env().getVM().getRoot();
+ bool ret = root.clear_interval_timer(id);
+ return as_value(ret);
+}
+
+
void
registerNatives(as_object& global)
@@ -620,20 +770,20 @@
// ASNew was dropped as a builtin function but exists
// as ASnative.
- vm.registerNative(as_global_assetpropflags, 1, 0);
- vm.registerNative(as_global_asnew, 2, 0);
- vm.registerNative(as_global_assetnative, 4, 0);
- vm.registerNative(as_global_assetnativeaccessor, 4, 1);
- vm.registerNative(as_global_updateAfterEvent, 9, 0);
- vm.registerNative(as_global_escape, 100, 0);
- vm.registerNative(as_global_unescape, 100, 1);
- vm.registerNative(as_global_parseint, 100, 2);
- vm.registerNative(as_global_parsefloat, 100, 3);
- vm.registerNative(as_global_trace, 100, 4);
- vm.registerNative(as_global_isNaN, 200, 18);
- vm.registerNative(as_global_isfinite, 200, 19);
- vm.registerNative(timer_setinterval, 250, 0);
- vm.registerNative(timer_clearinterval, 250, 1);
+ vm.registerNative(global_assetpropflags, 1, 0);
+ vm.registerNative(global_asnew, 2, 0);
+ vm.registerNative(global_assetnative, 4, 0);
+ vm.registerNative(global_assetnativeaccessor, 4, 1);
+ vm.registerNative(global_updateAfterEvent, 9, 0);
+ vm.registerNative(global_escape, 100, 0);
+ vm.registerNative(global_unescape, 100, 1);
+ vm.registerNative(global_parseint, 100, 2);
+ vm.registerNative(global_parsefloat, 100, 3);
+ vm.registerNative(global_trace, 100, 4);
+ vm.registerNative(global_isNaN, 200, 18);
+ vm.registerNative(global_isfinite, 200, 19);
+ vm.registerNative(global_setInterval, 250, 0);
+ vm.registerNative(global_clearInterval, 250, 1);
registerSelectionNative(global);
registerColorNative(global);
=== modified file 'libcore/asobj/LoadableObject.cpp'
--- a/libcore/asobj/LoadableObject.cpp 2009-03-16 10:40:30 +0000
+++ b/libcore/asobj/LoadableObject.cpp 2009-03-17 09:44:00 +0000
@@ -26,7 +26,6 @@
#include "namedStrings.h"
#include "VM.h"
#include "builtin_function.h"
-#include "timers.h"
#include "utf8.h"
#include "fn_call.h"
#include "GnashAlgorithm.h"
=== modified file 'libcore/asobj/Math_as.cpp'
--- a/libcore/asobj/Math_as.cpp 2009-02-10 15:38:43 +0000
+++ b/libcore/asobj/Math_as.cpp 2009-03-17 11:39:48 +0000
@@ -38,6 +38,7 @@
#include "log.h"
#include "builtin_function.h"
#include "Object.h" // for getObjectInterface
+#include "GnashNumeric.h"
namespace gnash {
@@ -155,7 +156,7 @@
}
double arg1 = fn.arg(1).to_number();
- return as_value( utility::isFinite(arg0) ? std::pow(arg0, arg1) : NaN );
+ return as_value(isFinite(arg0) ? std::pow(arg0, arg1) : NaN );
}
/// Math.min
=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp 2009-03-14 13:51:05 +0000
+++ b/libcore/asobj/NetConnection_as.cpp 2009-03-17 09:44:00 +0000
@@ -45,7 +45,6 @@
#include "VM.h"
#include "amf.h"
#include "SimpleBuffer.h"
-#include "timers.h"
#include "namedStrings.h"
#include "GnashAlgorithm.h"
=== modified file 'libcore/asobj/NetStream_as.cpp'
--- a/libcore/asobj/NetStream_as.cpp 2009-03-16 11:14:19 +0000
+++ b/libcore/asobj/NetStream_as.cpp 2009-03-17 09:44:00 +0000
@@ -30,7 +30,6 @@
#include "fn_call.h"
#include "builtin_function.h"
-#include "timers.h" // for registering the advance timer
#include "GnashException.h"
#include "NetConnection_as.h"
#include "Object.h" // for getObjectInterface
=== modified file 'libcore/asobj/Sound_as.cpp'
--- a/libcore/asobj/Sound_as.cpp 2009-03-14 13:51:05 +0000
+++ b/libcore/asobj/Sound_as.cpp 2009-03-17 09:44:00 +0000
@@ -34,7 +34,6 @@
#include "builtin_function.h"
#include "Object.h" // for getObjectInterface
#include "VM.h"
-#include "timers.h" // for registering the probe timer
#include "namedStrings.h"
#include "ExportableResource.h"
#include "StreamProvider.h"
=== modified file 'libcore/asobj/String_as.cpp'
--- a/libcore/asobj/String_as.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/String_as.cpp 2009-03-17 11:39:48 +0000
@@ -34,6 +34,7 @@
#include "namedStrings.h"
#include "utf8.h"
#include "String_as.h"
+#include "GnashNumeric.h"
#include <boost/algorithm/string/case_conv.hpp>
#include <algorithm>
@@ -393,7 +394,7 @@
// Return empty array.
return as_value(array.get());
}
- max = utility::clamp<size_t>(limit, 0, max);
+ max = clamp<size_t>(limit, 0, max);
}
if (delimiterSize > 1 || fn.arg(0).is_undefined() || wstr.empty())
@@ -425,7 +426,7 @@
// Return empty array if
return as_value(array.get());
}
- max = utility::clamp<size_t>(limit, 0, max);
+ max = clamp<size_t>(limit, 0, max);
}
// If the delimiter is empty, put each character in an
@@ -945,7 +946,7 @@
index = subject.size() + index;
}
- index = utility::clamp<int>(index, 0, subject.size());
+ index = clamp<int>(index, 0, subject.size());
return index;
}
=== modified file 'libcore/asobj/TextFormat_as.cpp'
--- a/libcore/asobj/TextFormat_as.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/TextFormat_as.cpp 2009-03-17 12:01:42 +0000
@@ -27,6 +27,7 @@
#include "RGBA.h" // for rgba type
#include "StringPredicates.h" // for parseAlignString
#include "smart_ptr.h" // intrusive_ptr
+#include "GnashNumeric.h"
namespace gnash {
@@ -168,13 +169,13 @@
default:
log_error(_("Too many args (%d) passed to TextFormat"), args);
case 13:
- tf->leadingSet(PIXELS_TO_TWIPS(fn.arg(12).to_int()));
+ tf->leadingSet(pixelsToTwips(fn.arg(12).to_int()));
case 12:
- tf->indentSet(PIXELS_TO_TWIPS(fn.arg(11).to_int()));
+ tf->indentSet(pixelsToTwips(fn.arg(11).to_int()));
case 11:
- tf->rightMarginSet(PIXELS_TO_TWIPS(fn.arg(10).to_int()));
+ tf->rightMarginSet(pixelsToTwips(fn.arg(10).to_int()));
case 10:
- tf->leftMarginSet(PIXELS_TO_TWIPS(fn.arg(9).to_int()));
+ tf->leftMarginSet(pixelsToTwips(fn.arg(9).to_int()));
case 9:
tf->alignSet(fn.arg(8).to_string());
case 8:
@@ -194,7 +195,7 @@
tf->colorSet(col);
}
case 2:
- tf->sizeSet(PIXELS_TO_TWIPS(fn.arg(1).to_int()));
+ tf->sizeSet(pixelsToTwips(fn.arg(1).to_int()));
case 1:
tf->fontSet(fn.arg(0).to_string());
break;
@@ -253,12 +254,12 @@
if ( fn.nargs == 0 ) // getter
{
- if ( ptr->blockIndentDefined() )
ret.set_double(TWIPS_TO_PIXELS(ptr->blockIndent()));
+ if ( ptr->blockIndentDefined() )
ret.set_double(twipsToPixels(ptr->blockIndent()));
else ret.set_null();
}
else // setter
{
- ptr->blockIndentSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->blockIndentSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
@@ -273,12 +274,12 @@
if ( fn.nargs == 0 ) // getter
{
- if ( ptr->leadingDefined() )
ret.set_double(TWIPS_TO_PIXELS(ptr->leading()));
+ if ( ptr->leadingDefined() )
ret.set_double(twipsToPixels(ptr->leading()));
else ret.set_null();
}
else // setter
{
- ptr->leadingSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->leadingSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
@@ -293,12 +294,12 @@
if ( fn.nargs == 0 ) // getter
{
- if ( ptr->indentDefined() )
ret.set_double(TWIPS_TO_PIXELS(ptr->indent()));
+ if ( ptr->indentDefined() )
ret.set_double(twipsToPixels(ptr->indent()));
else ret.set_null();
}
else // setter
{
- ptr->indentSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->indentSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
@@ -313,12 +314,12 @@
if ( fn.nargs == 0 ) // getter
{
- if ( ptr->rightMarginDefined() )
ret.set_double(TWIPS_TO_PIXELS(ptr->rightMargin()));
+ if ( ptr->rightMarginDefined() )
ret.set_double(twipsToPixels(ptr->rightMargin()));
else ret.set_null();
}
else // setter
{
- ptr->rightMarginSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->rightMarginSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
@@ -335,13 +336,13 @@
if ( fn.nargs == 0 ) // getter
{
if (ptr->leftMarginDefined()) {
- ret.set_double(TWIPS_TO_PIXELS(ptr->leftMargin()));
+ ret.set_double(twipsToPixels(ptr->leftMargin()));
}
else ret.set_null();
}
else // setter
{
- ptr->leftMarginSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->leftMarginSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
@@ -480,12 +481,12 @@
if ( fn.nargs == 0 ) // getter
{
- if ( ptr->sizeDefined() )
ret.set_double(TWIPS_TO_PIXELS(ptr->size()));
+ if ( ptr->sizeDefined() )
ret.set_double(twipsToPixels(ptr->size()));
else ret.set_null();
}
else // setter
{
- ptr->sizeSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+ ptr->sizeSet(pixelsToTwips(fn.arg(0).to_int()));
}
return ret;
=== modified file 'libcore/asobj/TextSnapshot_as.cpp'
--- a/libcore/asobj/TextSnapshot_as.cpp 2009-03-11 10:14:31 +0000
+++ b/libcore/asobj/TextSnapshot_as.cpp 2009-03-17 12:01:42 +0000
@@ -35,6 +35,7 @@
#include "swf/TextRecord.h"
#include "Array_as.h"
#include "RGBA.h"
+#include "GnashNumeric.h"
#include <boost/algorithm/string/compare.hpp>
#include <boost/dynamic_bitset.hpp>
@@ -237,7 +238,7 @@
selected.test(pos - fieldStartIndex));
el->init_member("font", font->name());
el->init_member("color", tr->color().toRGBA());
- el->init_member("height", TWIPS_TO_PIXELS(tr->textHeight()));
+ el->init_member("height", twipsToPixels(tr->textHeight()));
const double factor = 65536.0;
el->init_member("matrix_a", mat.sx / factor);
@@ -245,8 +246,8 @@
el->init_member("matrix_c", mat.shy / factor);
el->init_member("matrix_d", mat.sy / factor);
- const double xpos = TWIPS_TO_PIXELS(mat.tx + x);
- const double ypos = TWIPS_TO_PIXELS(mat.ty + tr->yOffset());
+ const double xpos = twipsToPixels(mat.tx + x);
+ const double ypos = twipsToPixels(mat.ty + tr->yOffset());
el->init_member("matrix_tx", xpos);
el->init_member("matrix_ty", ypos);
=== modified file 'libcore/asobj/XMLSocket_as.cpp'
--- a/libcore/asobj/XMLSocket_as.cpp 2009-03-14 17:27:38 +0000
+++ b/libcore/asobj/XMLSocket_as.cpp 2009-03-17 09:44:00 +0000
@@ -27,7 +27,6 @@
#include "utility.h"
#include "XML_as.h"
#include "XMLSocket_as.h"
-#include "timers.h"
#include "as_function.h"
#include "fn_call.h"
#include "VM.h"
=== modified file 'libcore/asobj/flash/geom/Point_as.cpp'
--- a/libcore/asobj/flash/geom/Point_as.cpp 2009-02-25 22:33:03 +0000
+++ b/libcore/asobj/flash/geom/Point_as.cpp 2009-03-17 11:39:48 +0000
@@ -26,7 +26,7 @@
#include "GnashException.h" // for ActionException
#include "Object.h" // for AS inheritance
#include "VM.h" // for addStatics
-#include "utility.h" // isFinite
+#include "GnashNumeric.h"
#include <sstream>
@@ -263,9 +263,9 @@
ptr->get_member(NSV::PROP_Y, &yval);
double x = xval.to_number();
- if ( ! utility::isFinite(x) ) return as_value();
+ if (!isFinite(x)) return as_value();
double y = yval.to_number();
- if ( ! utility::isFinite(y) ) return as_value();
+ if (!isFinite(y)) return as_value();
if ( x == 0 && y == 0 ) return as_value();
@@ -462,17 +462,17 @@
as_value x1val;
o1->get_member(NSV::PROP_X, &x1val);
double x1 = x1val.to_number();
- //if ( ! utility::isFinite(x1) ) return as_value(NaN);
+ //if ( ! isFinite(x1) ) return as_value(NaN);
as_value y1val;
o1->get_member(NSV::PROP_Y, &y1val);
double y1 = y1val.to_number();
- //if ( ! utility::isFinite(y1) ) return as_value(NaN);
+ //if ( ! isFinite(y1) ) return as_value(NaN);
as_value x2val;
o2->get_member(NSV::PROP_X, &x2val);
double x2 = x2val.to_number();
- //if ( ! utility::isFinite(x2) ) return as_value(NaN);
+ //if ( ! isFinite(x2) ) return as_value(NaN);
as_value y2val;
o2->get_member(NSV::PROP_Y, &y2val);
=== modified file 'libcore/asobj/flash/geom/Rectangle_as.cpp'
--- a/libcore/asobj/flash/geom/Rectangle_as.cpp 2009-02-27 11:55:27 +0000
+++ b/libcore/asobj/flash/geom/Rectangle_as.cpp 2009-03-17 11:39:48 +0000
@@ -33,7 +33,7 @@
#include "VM.h" // for addStatics
#include "as_value.h"
#include "namedStrings.h"
-#include "utility.h" // isFinite
+#include "GnashNumeric.h" // isFinite
#include <sstream>
@@ -318,10 +318,10 @@
if ( h.is_undefined() || h.is_null() ) return as_value(true);
double wn = w.to_number();
- if ( ! utility::isFinite(wn) || wn <= 0 ) return as_value(true);
+ if (!isFinite(wn) || wn <= 0) return as_value(true);
double hn = h.to_number();
- if ( ! utility::isFinite(hn) || hn <= 0 ) return as_value(true);
+ if (!isFinite(hn) || hn <= 0) return as_value(true);
log_debug("Width: %g, Height: %g", wn, hn);
=== modified file 'libcore/asobj/flash/geom/Transform_as.cpp'
--- a/libcore/asobj/flash/geom/Transform_as.cpp 2009-02-27 11:55:27 +0000
+++ b/libcore/asobj/flash/geom/Transform_as.cpp 2009-03-17 12:01:42 +0000
@@ -32,6 +32,7 @@
#include "VM.h" // for addStatics
#include "MovieClip.h" // For MovieClip
#include "ColorTransform_as.h"
+#include "GnashNumeric.h"
#include <sstream>
#include <limits>
@@ -287,8 +288,8 @@
args->push_back(m.shx / factor);
args->push_back(m.shy / factor);
args->push_back(m.sy / factor);
- args->push_back(TWIPS_TO_PIXELS(m.tx));
- args->push_back(TWIPS_TO_PIXELS(m.ty));
+ args->push_back(twipsToPixels(m.tx));
+ args->push_back(twipsToPixels(m.ty));
boost::intrusive_ptr<as_object> matrixObj =
matrixCtor->constructInstance(fn.env(), args);
@@ -336,8 +337,8 @@
m.shx = b.to_number() * factor;
m.shy = c.to_number() * factor;
m.sy = d.to_number() * factor;
- m.set_x_translation(PIXELS_TO_TWIPS(tx.to_number()));
- m.set_y_translation(PIXELS_TO_TWIPS(ty.to_number()));
+ m.set_x_translation(pixelsToTwips(tx.to_number()));
+ m.set_y_translation(pixelsToTwips(ty.to_number()));
ptr->setMatrix(m);
=== modified file 'libcore/character.cpp'
--- a/libcore/character.cpp 2009-02-26 18:48:57 +0000
+++ b/libcore/character.cpp 2009-03-17 12:01:42 +0000
@@ -28,11 +28,12 @@
#include "drag_state.h" // for do_mouse_drag (to be moved in movie_root)
#include "VM.h" // for do_mouse_drag (to be moved in movie_root)
#include "fn_call.h" // for shared ActionScript getter-setters
-#include "GnashException.h" // for shared ActionScript getter-setters
(ensure_character)
+#include "GnashException.h"
#include "render.h" // for bounds_in_clipping_area()
#include "ExecutableCode.h"
#include "namedStrings.h"
#include "gnash.h" // Quality
+#include "GnashNumeric.h"
#ifdef USE_SWFTREE
# include "tree.hh"
@@ -360,7 +361,7 @@
if ( fn.nargs == 0 ) // getter
{
SWFMatrix m = ptr->getMatrix();
- rv = as_value(TWIPS_TO_PIXELS(m.get_x_translation()));
+ rv = as_value(twipsToPixels(m.get_x_translation()));
}
else // setter
{
@@ -394,7 +395,7 @@
SWFMatrix m = ptr->getMatrix();
// NOTE: infinite_to_zero is wrong here, see
actionscript.all/setProperty.as
-
m.set_x_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newx)));
+ m.set_x_translation(pixelsToTwips(infinite_to_zero(newx)));
ptr->setMatrix(m); // no need to update caches when only
changing translation
ptr->transformedByScript(); // m_accept_anim_moves = false;
}
@@ -411,7 +412,7 @@
if ( fn.nargs == 0 ) // getter
{
SWFMatrix m = ptr->getMatrix();
- rv = as_value(TWIPS_TO_PIXELS(m.get_y_translation()));
+ rv = as_value(twipsToPixels(m.get_y_translation()));
}
else // setter
{
@@ -446,7 +447,7 @@
SWFMatrix m = ptr->getMatrix();
// NOTE: infinite_to_zero is wrong here,
// see actionscript.all/setProperty.as
-
m.set_y_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newy)));
+ m.set_y_translation(pixelsToTwips(infinite_to_zero(newy)));
ptr->setMatrix(m); // no need to update caches when only
changing translation
ptr->transformedByScript(); // m_accept_anim_moves = false;
}
@@ -558,10 +559,10 @@
ptr->getVM().getRoot().get_mouse_state(x, y, buttons);
SWFMatrix m = ptr->getWorldMatrix();
- point a(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ point a(pixelsToTwips(x), pixelsToTwips(y));
m.invert().transform(a);
- return as_value(TWIPS_TO_PIXELS(a.x));
+ return as_value(twipsToPixels(a.x));
}
as_value
@@ -574,9 +575,9 @@
ptr->getVM().getRoot().get_mouse_state(x, y, buttons);
SWFMatrix m = ptr->getWorldMatrix();
- point a(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ point a(pixelsToTwips(x), pixelsToTwips(y));
m.invert().transform(a);
- return as_value(TWIPS_TO_PIXELS(a.y));
+ return as_value(twipsToPixels(a.y));
}
as_value
@@ -778,12 +779,12 @@
{
SWFMatrix m = ptr->getMatrix();
m.transform(bounds);
- double w = TWIPS_TO_PIXELS( bounds.width() );
+ double w = twipsToPixels( bounds.width() );
rv = as_value(w);
}
else // setter
{
- const double newwidth = PIXELS_TO_TWIPS(fn.arg(0).to_number());
+ const double newwidth = pixelsToTwips(fn.arg(0).to_number());
if ( newwidth <= 0 )
{
IF_VERBOSE_ASCODING_ERRORS(
@@ -845,13 +846,13 @@
{
SWFMatrix m = ptr->getMatrix();
m.transform(bounds);
- double h = TWIPS_TO_PIXELS(bounds.height());
+ double h = twipsToPixels(bounds.height());
rv = as_value(h);
}
else // setter
{
- const double newheight = PIXELS_TO_TWIPS(fn.arg(0).to_number());
+ const double newheight = pixelsToTwips(fn.arg(0).to_number());
if ( newheight <= 0 )
{
IF_VERBOSE_ASCODING_ERRORS(
=== modified file 'libcore/cxform.cpp'
--- a/libcore/cxform.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/cxform.cpp 2009-03-17 11:39:48 +0000
@@ -22,7 +22,7 @@
#include "RGBA.h"
#include "SWFStream.h" // for reading from SWF
#include "log.h"
-#include "utility.h" // for utility::clamp
+#include "GnashNumeric.h"
#include <iomanip>
namespace gnash {
@@ -78,8 +78,6 @@
bt = (bt * ba >> 8) + bb;
at = (at * aa >> 8) + ab;
- using utility::clamp;
-
r = (uint8_t)(clamp<int16_t>(rt, 0, 255));
g = (uint8_t)(clamp<int16_t>(gt, 0, 255));
b = (uint8_t)(clamp<int16_t>(bt, 0, 255));
=== modified file 'libcore/fill_style.cpp'
--- a/libcore/fill_style.cpp 2009-03-18 15:28:18 +0000
+++ b/libcore/fill_style.cpp 2009-03-19 16:27:50 +0000
@@ -28,7 +28,7 @@
#include "movie_definition.h"
#include "swf.h"
#include "GnashException.h"
-
+#include "GnashNumeric.h"
#include <cmath> // sqrt, floor
#include <iostream> // for output operator
@@ -546,8 +546,7 @@
for (size_t j=0, nj=m_gradients.size(); j<nj; ++j)
{
m_gradients[j].m_ratio =
- (boost::uint8_t) utility::frnd(
- utility::flerp(a.m_gradients[j].m_ratio,
+ (boost::uint8_t) frnd( flerp(a.m_gradients[j].m_ratio,
b.m_gradients[j].m_ratio, t)
);
m_gradients[j].m_color.set_lerp(a.m_gradients[j].m_color,
=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp 2009-03-19 09:10:05 +0000
+++ b/libcore/movie_root.cpp 2009-03-19 16:27:50 +0000
@@ -28,15 +28,15 @@
#include "VM.h"
#include "ExecutableCode.h"
#include "Stage_as.h"
-#include "utility.h"
#include "URL.h"
#include "namedStrings.h"
#include "GnashException.h"
#include "sound_handler.h"
-#include "timers.h" // for Timer use
-#include "GnashKey.h" // key::code
+#include "Timers.h"
+#include "GnashKey.h"
#include "gnash.h"
#include "GnashAlgorithm.h"
+#include "GnashNumeric.h"
#include <boost/algorithm/string/replace.hpp>
#include <utility>
@@ -854,8 +854,8 @@
assert(testInvariant());
- boost::int32_t x = PIXELS_TO_TWIPS(m_mouse_x);
- boost::int32_t y = PIXELS_TO_TWIPS(m_mouse_y);
+ boost::int32_t x = pixelsToTwips(m_mouse_x);
+ boost::int32_t y = pixelsToTwips(m_mouse_y);
// Generate a mouse event
m_mouse_button_state.topmostEntity = getTopmostMouseEntity(x, y);
@@ -944,7 +944,7 @@
// Get current mouse coordinates
boost::int32_t x, y, buttons;
get_mouse_state(x, y, buttons);
- point world_mouse(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ point world_mouse(pixelsToTwips(x), pixelsToTwips(y));
boost::int32_t xoffset = world_mouse.x - world_origin.x;
boost::int32_t yoffset = world_mouse.y - world_origin.y;
@@ -970,7 +970,7 @@
boost::int32_t x, y, buttons;
get_mouse_state(x, y, buttons);
- point world_mouse(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ point world_mouse(pixelsToTwips(x), pixelsToTwips(y));
SWFMatrix parent_world_mat;
character* parent = dragChar->get_parent();
@@ -1404,8 +1404,8 @@
const character*
movie_root::getEntityUnderPointer() const
{
- boost::int32_t x = PIXELS_TO_TWIPS(m_mouse_x);
- boost::int32_t y = PIXELS_TO_TWIPS(m_mouse_y);
+ boost::int32_t x = pixelsToTwips(m_mouse_x);
+ boost::int32_t y = pixelsToTwips(m_mouse_y);
const character* dropChar = findDropTarget(x, y, getDraggingCharacter());
return dropChar;
}
@@ -2133,7 +2133,7 @@
{
//GNASH_REPORT_FUNCTION;
- boost::uint8_t newAlpha = utility::clamp<int>(utility::frnd(alpha *
255.0f), 0, 255);
+ boost::uint8_t newAlpha = clamp<int>(frnd(alpha * 255.0f), 0, 255);
if ( m_background_color.m_a != newAlpha )
{
=== modified file 'libcore/parser/BitmapMovieDefinition.h'
--- a/libcore/parser/BitmapMovieDefinition.h 2009-03-12 07:53:23 +0000
+++ b/libcore/parser/BitmapMovieDefinition.h 2009-03-17 12:01:42 +0000
@@ -25,6 +25,7 @@
#include "BitmapInfo.h" // for destructor visibility by intrusive_ptr
#include "DynamicShape.h" // for destructor visibility by intrusive_ptr
#include "GnashImage.h"
+#include "GnashNumeric.h"
#include <string>
#include <memory> // for auto_ptr
@@ -72,11 +73,11 @@
}
virtual float get_width_pixels() const {
- return std::ceil(TWIPS_TO_PIXELS(_framesize.width()));
+ return std::ceil(twipsToPixels(_framesize.width()));
}
virtual float get_height_pixels() const {
- return std::ceil(TWIPS_TO_PIXELS(_framesize.height()));
+ return std::ceil(twipsToPixels(_framesize.height()));
}
virtual size_t get_frame_count() const {
=== modified file 'libcore/parser/SWFMovieDefinition.h'
--- a/libcore/parser/SWFMovieDefinition.h 2009-03-12 07:53:23 +0000
+++ b/libcore/parser/SWFMovieDefinition.h 2009-03-17 12:01:42 +0000
@@ -32,9 +32,9 @@
#include "IOChannel.h"
#include "movie_definition.h" // for inheritance
#include "character_def.h" // for boost::intrusive_ptr visibility of dtor
-#include "StringPredicates.h" // for case-insensitive string comparision
(ExportMap)
-#include "utility.h" // for TWIPS_TO_PIXELS
+#include "StringPredicates.h"
#include "rect.h"
+#include "GnashNumeric.h"
#include <map> // for CharacterDictionary
#include <set> // for _importSources
@@ -195,12 +195,12 @@
float get_width_pixels() const
{
- return std::ceil(TWIPS_TO_PIXELS(m_frame_size.width()));
+ return std::ceil(twipsToPixels(m_frame_size.width()));
}
float get_height_pixels() const
{
- return std::ceil(TWIPS_TO_PIXELS(m_frame_size.height()));
+ return std::ceil(twipsToPixels(m_frame_size.height()));
}
virtual int get_version() const { return m_version; }
=== modified file 'libcore/parser/morph2_character_def.cpp'
--- a/libcore/parser/morph2_character_def.cpp 2009-03-12 09:23:59 +0000
+++ b/libcore/parser/morph2_character_def.cpp 2009-03-17 11:39:48 +0000
@@ -27,7 +27,7 @@
#include "render.h"
#include "movie_definition.h"
#include "MovieClip.h"
-
+#include "GnashNumeric.h"
namespace gnash {
@@ -179,8 +179,8 @@
const path& p1 = i < paths1.size() ? paths1[i] : empty_path;
const path& p2 = n < paths2.size() ? paths2[n] : empty_path;
- const float new_ax = utility::flerp(p1.ap.x, p2.ap.x, ratio);
- const float new_ay = utility::flerp(p1.ap.y, p2.ap.y, ratio);
+ const float new_ax = flerp(p1.ap.x, p2.ap.x, ratio);
+ const float new_ay = flerp(p1.ap.y, p2.ap.y, ratio);
p.reset(new_ax, new_ay, p1.getLeftFill(),
p2.getRightFill(), p1.getLineStyle());
@@ -195,10 +195,10 @@
const edge& e1 = j < p1.size() ? p1[j] : empty_edge;
const edge& e2 = k < p2.size() ? p2[k] : empty_edge;
- e.cp.x = static_cast<int>(utility::flerp(e1.cp.x, e2.cp.x, ratio));
- e.cp.y = static_cast<int>(utility::flerp(e1.cp.y, e2.cp.y, ratio));
- e.ap.x = static_cast<int>(utility::flerp(e1.ap.x, e2.ap.x, ratio));
- e.ap.y = static_cast<int>(utility::flerp(e1.ap.y, e2.ap.y, ratio));
+ e.cp.x = static_cast<int>(flerp(e1.cp.x, e2.cp.x, ratio));
+ e.cp.y = static_cast<int>(flerp(e1.cp.y, e2.cp.y, ratio));
+ e.ap.x = static_cast<int>(flerp(e1.ap.x, e2.ap.x, ratio));
+ e.ap.y = static_cast<int>(flerp(e1.ap.y, e2.ap.y, ratio));
++k;
if (p2.size() <= k) {
=== modified file 'libcore/rect.cpp'
--- a/libcore/rect.cpp 2009-02-25 22:33:03 +0000
+++ b/libcore/rect.cpp 2009-03-17 11:39:48 +0000
@@ -19,13 +19,13 @@
#include "log.h"
#include "SWFStream.h"
#include "SWFMatrix.h"
-#include "utility.h" // for flerp, clamp...
+#include "GnashNumeric.h" // for flerp, clamp...
#include <sstream> // for ::print and ::toString
namespace gnash {
-void rect::read(SWFStream& in)
+void rect::read(SWFStream& in)
{
in.align();
in.ensureBits(5);
@@ -104,7 +104,8 @@
expand_to(p3.x, p3.y);
}
-void rect::expand_to_rect(const rect& r)
+void
+rect::expand_to_rect(const rect& r)
// Expand ourself to enclose the given rect.
{
if( r.is_null() ) {
@@ -121,7 +122,8 @@
}
}
-void rect::expand_to_transformed_rect(const SWFMatrix& m, const rect& r)
+void
+rect::expand_to_transformed_rect(const SWFMatrix& m, const rect& r)
// Expand ourself to a transformed rect.
{
if ( r.is_null() )
@@ -160,7 +162,6 @@
assert( !a.is_null() );
assert( !b.is_null() );
- using utility::flerp;
_xMin = (boost::int32_t)(flerp(a.get_x_min(), b.get_x_min(), t));
_yMin = (boost::int32_t)(flerp(a.get_y_min(), b.get_y_min(), t));
_xMax = (boost::int32_t)(flerp(a.get_x_max(), b.get_x_max(), t));
@@ -171,8 +172,8 @@
rect::clamp(point& p) const
{
assert( !is_null() );
- p.x = utility::clamp<boost::int32_t>(p.x, _xMin, _xMax);
- p.y = utility::clamp<boost::int32_t>(p.y, _yMin, _yMax);
+ p.x = gnash::clamp<boost::int32_t>(p.x, _xMin, _xMax);
+ p.y = gnash::clamp<boost::int32_t>(p.y, _yMin, _yMax);
}
std::string
=== modified file 'libcore/styles.cpp'
--- a/libcore/styles.cpp 2009-01-05 09:32:03 +0000
+++ b/libcore/styles.cpp 2009-03-17 11:39:48 +0000
@@ -15,6 +15,7 @@
#include "swf.h"
#include "GnashException.h"
#include "fill_style.h"
+#include "GnashNumeric.h"
namespace gnash {
@@ -141,7 +142,7 @@
line_style::set_lerp(const line_style& ls1, const line_style& ls2, float ratio)
{
m_width = static_cast<boost::uint16_t>(
- utility::frnd(utility::flerp(ls1.getThickness(), ls2.getThickness(),
ratio)));
+ frnd(flerp(ls1.getThickness(), ls2.getThickness(), ratio)));
m_color.set_lerp(ls1.get_color(), ls2.get_color(), ratio);
if ( ls1._scaleVertically != ls2._scaleVertically )
{
=== modified file 'libcore/swf/DefineVideoStreamTag.cpp'
--- a/libcore/swf/DefineVideoStreamTag.cpp 2009-03-13 22:46:37 +0000
+++ b/libcore/swf/DefineVideoStreamTag.cpp 2009-03-17 12:01:42 +0000
@@ -24,6 +24,7 @@
#include "SWFStream.h" // for read()
#include "movie_definition.h"
#include "GnashAlgorithm.h"
+#include "GnashNumeric.h"
namespace gnash {
namespace SWF {
@@ -100,7 +101,7 @@
_height = in.read_u16();
m_bound.set_to_point(0, 0);
- m_bound.expand_to_point(PIXELS_TO_TWIPS(_width),
PIXELS_TO_TWIPS(_height));
+ m_bound.expand_to_point(pixelsToTwips(_width), pixelsToTwips(_height));
m_reserved_flags = in.read_uint(5);
m_deblocking_flags = in.read_uint(2);
=== modified file 'libcore/swf/SetBackgroundColorTag.h'
--- a/libcore/swf/SetBackgroundColorTag.h 2009-01-22 20:10:39 +0000
+++ b/libcore/swf/SetBackgroundColorTag.h 2009-03-17 11:39:48 +0000
@@ -28,7 +28,7 @@
#include "movie_definition.h" // for inlines (loader)
#include "log.h" // for log_parse
#include "RGBA.h" // for rgba class
-#include "utility.h" // for frnd
+#include "GnashNumeric.h" // for frnd
// Forward declarations
namespace gnash {
@@ -86,7 +86,7 @@
{
float current_alpha = m->get_background_alpha();
rgba newcolor = m_color; // to avoid making m_color mutable
- newcolor.m_a = utility::frnd(current_alpha * 255.0f);
+ newcolor.m_a = frnd(current_alpha * 255.0f);
m->set_background_color(newcolor);
}
=== modified file 'libcore/swf/tag_loaders.cpp'
--- a/libcore/swf/tag_loaders.cpp 2009-03-10 20:43:50 +0000
+++ b/libcore/swf/tag_loaders.cpp 2009-03-17 09:44:00 +0000
@@ -33,7 +33,6 @@
#include "Geometry.h"
#include "SWFStream.h"
#include "styles.h"
-#include "timers.h"
#include "GnashImage.h"
#include "zlib_adapter.h"
#include "sprite_definition.h"
=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2009-03-05 16:57:54 +0000
+++ b/libcore/vm/ASHandlers.cpp 2009-03-17 12:01:42 +0000
@@ -48,7 +48,8 @@
#include "sound_handler.h"
#include "namedStrings.h"
#include "utf8.h"
-#include "StringPredicates.h" // StringNoCaseEqual
+#include "StringPredicates.h"
+#include "GnashNumeric.h"
#include <string>
#include <vector>
@@ -1340,10 +1341,10 @@
// we must remember to updated this as required
- boost::int32_t y1 = PIXELS_TO_TWIPS(env.top(3).to_number());
- boost::int32_t x1 = PIXELS_TO_TWIPS(env.top(4).to_number());
- boost::int32_t y0 = PIXELS_TO_TWIPS(env.top(5).to_number());
- boost::int32_t x0 = PIXELS_TO_TWIPS(env.top(6).to_number());
+ boost::int32_t y1 = pixelsToTwips(env.top(3).to_number());
+ boost::int32_t x1 = pixelsToTwips(env.top(4).to_number());
+ boost::int32_t y0 = pixelsToTwips(env.top(5).to_number());
+ boost::int32_t x0 = pixelsToTwips(env.top(6).to_number());
// check for swapped values
if ( y1 < y0 )
=== modified file 'libmedia/AudioDecoderSimple.cpp'
--- a/libmedia/AudioDecoderSimple.cpp 2009-02-25 22:33:03 +0000
+++ b/libmedia/AudioDecoderSimple.cpp 2009-03-17 11:39:48 +0000
@@ -23,7 +23,7 @@
#include "BitsReader.h"
#include "SoundInfo.h"
#include "MediaParser.h" // for AudioInfo definition..
-#include "utility.h" // for clamp
+#include "GnashNumeric.h" // for clamp
#include "log.h"
@@ -87,11 +87,11 @@
if (code_sign_bit) delta = -delta;
sample += delta;
- sample = utility::clamp<int>(sample, -32768, 32767);
+ sample = clamp<int>(sample, -32768, 32767);
/* Update our stepsize index. Use a lookup table. */
stepsize_index += index_update_table[code_mag];
- stepsize_index = utility::clamp<int>(stepsize_index, 0,
STEPSIZE_CT - 1);
+ stepsize_index = clamp<int>(stepsize_index, 0, STEPSIZE_CT - 1);
}
/* Uncompress 4096 mono samples of ADPCM. */
=== modified file 'plugin/klash4/klash_part.moc.in'
--- a/plugin/klash4/klash_part.moc.in 2008-12-04 09:27:57 +0000
+++ b/plugin/klash4/klash_part.moc.in 2009-03-17 12:01:42 +0000
@@ -1,12 +1,13 @@
/****************************************************************************
** Meta object code from reading C++ file 'klash_part.h'
**
-** Created: Thu Dec 4 10:00:51 2008
+** Created: Tue Mar 17 12:54:45 2009
** by: The Qt Meta Object Compiler version 59 (Qt 4.4.3)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
+#include "../../../../work/plugin/klash4/klash_part.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'klash_part.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 59
=== added directory 'testsuite/as3'
=== modified file 'testsuite/libcore.all/AsValueTest.cpp'
--- a/testsuite/libcore.all/AsValueTest.cpp 2009-02-25 22:33:03 +0000
+++ b/testsuite/libcore.all/AsValueTest.cpp 2009-03-17 12:32:36 +0000
@@ -46,6 +46,7 @@
#include "network.h"
#include "amf.h"
#include "element.h"
+#include "GnashNumeric.h"
using namespace amf;
using namespace gnash;
@@ -335,7 +336,7 @@
} else {
runtest.fail("isNaN(9999999)");
}
- if(utility::isFinite(num)) {
+ if(isFinite(num)) {
runtest.pass("isFinite(9999999)");
} else {
runtest.fail("isFinite(9999999)");
@@ -348,7 +349,7 @@
} else {
runtest.fail("isNaN(quiet_NaN)");
}
- if(!utility::isFinite(num)) {
+ if(!isFinite(num)) {
runtest.pass("isFinite(quiet_NaN)");
} else {
runtest.fail("isFinite(quiet_NaN)");
@@ -361,7 +362,7 @@
} else {
runtest.fail("isNaN(infinity)");
}
- if(!utility::isFinite(num)) {
+ if(!isFinite(num)) {
runtest.pass("isFinite(infinity)");
} else {
runtest.fail("isFinite(infinity)");
@@ -374,7 +375,7 @@
} else {
runtest.fail("isNaN(1.0/0.0)");
}
- if(!utility::isFinite(num)) {
+ if(!isFinite(num)) {
runtest.pass("isFinite(1.0/0.0)");
} else {
runtest.fail("isFinite(1.0/0.0)");
@@ -389,7 +390,7 @@
} else {
runtest.fail("isNaN(int)");
}
- if(utility::isFinite(num)) {
+ if(isFinite(num)) {
runtest.pass("isFinite(int)");
} else {
runtest.fail("isFinite(int)");
=== modified file 'testsuite/libnet.all/test_http.cpp'
--- a/testsuite/libnet.all/test_http.cpp 2009-02-25 22:33:03 +0000
+++ b/testsuite/libnet.all/test_http.cpp 2009-03-17 12:32:36 +0000
@@ -48,7 +48,7 @@
#include "network.h"
#include "amf.h"
#include "buffer.h"
-#include "utility.h"
+#include "GnashNumeric.h"
using namespace gnash;
using namespace amf;
@@ -1201,7 +1201,7 @@
if ((strncmp(headers22x[0]->getName(), "echo", 4) == 0)
&& (strncmp(headers22x[1]->getName(), "/14", 2) == 0)
&& (headers22x[3]->getType() == Element::NUMBER_AMF0)
- && (utility::isFinite(headers22x[3]->to_number()))) {
+ && (isFinite(headers22x[3]->to_number()))) {
runtest.pass("HTTP::parseEchoRequest(Number Infinity)");
} else {
runtest.fail("HTTP::parseEchoRequest(Number Infinity)");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10728: Lots of changes resulting from a small rationalization of frequently-used,
Benjamin Wolsey <=