[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog pythonmodule/pyGnash.cpp python...
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] gnash ChangeLog pythonmodule/pyGnash.cpp python... |
Date: |
Fri, 11 Jan 2008 16:50:37 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Benjamin Wolsey <bwy> 08/01/11 16:50:36
Modified files:
. : ChangeLog
pythonmodule : pyGnash.cpp gnashpython.cpp gnashpython.h
gnashPythonExample.py
server : LoadVariablesThread.cpp sprite_instance.cpp
Log message:
* Fix some size_t compiler warnings in the proper way.
* More pythonmodule stuff (I know it's not really the time to do this
just before a release...)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5381&r2=1.5382
http://cvs.savannah.gnu.org/viewcvs/gnash/pythonmodule/pyGnash.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/pythonmodule/gnashpython.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/pythonmodule/gnashpython.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/pythonmodule/gnashPythonExample.py?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/server/LoadVariablesThread.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.cpp?cvsroot=gnash&r1=1.439&r2=1.440
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5381
retrieving revision 1.5382
diff -u -b -r1.5381 -r1.5382
--- ChangeLog 11 Jan 2008 16:15:58 -0000 1.5381
+++ ChangeLog 11 Jan 2008 16:50:35 -0000 1.5382
@@ -1,3 +1,11 @@
+2008-01-11 Benjamin Wolsey <address@hidden>
+
+ * server/sprite_instance.cpp, server/loadVariablesThread.cpp: Use
+ SIZET_FMT for size_t format string.
+ * pythonmodule/gnashpython.cpp: more methods in Player class.
+ * pythonmodule/pyGnash.cpp: update bindings.
+ * pythonmodule/gnashPythonExample.py: update examples.
+
2008-01-11 Sandro Santilli <address@hidden>
* testsuite/swfdec/PASSING: chartoascii-4.swf succeed
Index: pythonmodule/pyGnash.cpp
===================================================================
RCS file: /sources/gnash/gnash/pythonmodule/pyGnash.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pythonmodule/pyGnash.cpp 10 Jan 2008 00:36:24 -0000 1.2
+++ pythonmodule/pyGnash.cpp 11 Jan 2008 16:50:36 -0000 1.3
@@ -17,6 +17,11 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
//
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <boost/python.hpp>
#include "gnashpython.h"
@@ -28,13 +33,16 @@
namespace gnash {
BOOST_PYTHON_MODULE(gnash) {
- class_<pythonwrapper::GnashPlayer>("Player", "Allows direct control of a
Gnash player.")
+ class_<pythonwrapper::GnashPlayer>("Player", "Wrapper round Gnash player
functions.")
- .def("setBaseURL", &pythonwrapper::GnashPlayer::setBaseURL)
- .def("loadMovie", &pythonwrapper::GnashPlayer::createMovieDefinition)
+ .def("loadMovie", &pythonwrapper::GnashPlayer::loadMovie)
.def("initVM", &pythonwrapper::GnashPlayer::initVM)
- .def("addRenderer", &pythonwrapper::GnashPlayer::initRenderer)
+ .def("setRenderer", &pythonwrapper::GnashPlayer::setRenderer,
+ "Pass a string naming the renderer to use. Valid
renderers are: "
+ "AGG_RGB555, AGG_RGB565, AGG_RGBA16, AGG_RGB24,
AGG_BGR24, "
+ "AGG_RGBA32, AGG_BGRA32, AGG_ARGB32, AGG_ABGR32,
OpenGL, "
+ "Cairo.")
.def("currentFrame", &pythonwrapper::GnashPlayer::getCurrentFrame)
@@ -43,7 +51,12 @@
.def("restart", &pythonwrapper::GnashPlayer::restart)
.def("pressKey", &pythonwrapper::GnashPlayer::pressKey)
.def("allowRescale", &pythonwrapper::GnashPlayer::allowRescale)
+ .def("setVerbose", &pythonwrapper::GnashPlayer::setVerbose)
.def("render", &pythonwrapper::GnashPlayer::render)
+ .def("movePointer", &pythonwrapper::GnashPlayer::movePointer,
+ "Move pointer to specified coordinates. Returns true "
+ "if the move triggered an action requiring a redraw.")
+ .def("mouseClick", &pythonwrapper::GnashPlayer::mouseClick)
.def("swfFrameRate", &pythonwrapper::GnashPlayer::getSWFFrameRate)
.def("swfFrameCount", &pythonwrapper::GnashPlayer::getSWFFrameCount)
@@ -65,6 +78,7 @@
class_<pythonwrapper::GnashCharacter>("Character", "A character from the
movie."
"This class doesn't
work")
+ .def("name", &pythonwrapper::GnashCharacter::name)
;
}
Index: pythonmodule/gnashpython.cpp
===================================================================
RCS file: /sources/gnash/gnash/pythonmodule/gnashpython.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pythonmodule/gnashpython.cpp 10 Jan 2008 00:36:24 -0000 1.2
+++ pythonmodule/gnashpython.cpp 11 Jan 2008 16:50:36 -0000 1.3
@@ -17,6 +17,10 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "GnashException.h"
#include "URL.h"
#include "noseek_fd_adapter.h"
@@ -30,6 +34,7 @@
#include "render_handler.h"
#include "render_handler_agg.h"
#include "SystemClock.h"
+#include "log.h"
#include <cstdio>
#include <string>
@@ -49,10 +54,11 @@
:
_movieDef(NULL),
_movieRoot(NULL),
- _movieInstance(NULL),
- _handler(NULL),
+ _renderer(NULL),
+ _logFile(gnash::LogFile::getDefaultInstance()),
+ _xpos(0),
+ _ypos(0),
_url(""),
- _forceRedraw(false),
_fp(NULL)
{
init();
@@ -60,6 +66,7 @@
GnashPlayer::~GnashPlayer()
{
+ close();
}
// Initialize the core libs. If this gets called twice:
@@ -70,10 +77,17 @@
// TODO: Find way of checking whether gnashInit() has been called
// Better TODO: Get Gnash to handle more than one movie.
void
-GnashPlayer::init() {
+GnashPlayer::init()
+{
gnash::gnashInit();
}
+void
+GnashPlayer::close()
+{
+ gnash::clear();
+}
+
// Set our _url member and pass this to the core.
void
GnashPlayer::setBaseURL(std::string url)
@@ -92,10 +106,13 @@
// TODO: Read in movies from a python file object.
bool
-GnashPlayer::createMovieDefinition()
+GnashPlayer::loadMovie(std::string url)
{
+
if (_movieDef) return false;
+ setBaseURL(url);
+
// Fail if base URL not set
if (_url == "") return false;
@@ -122,7 +139,7 @@
// If movie definition hasn't already been created, try to create it,
// fail if that doesn't work either.
- if (!_movieDef && !createMovieDefinition()) return false;
+ if (!_movieDef && !loadMovie(_url)) return false;
// Initialize the VM with a manual clock
_movieRoot = &(gnash::VM::init(*_movieDef, _manualClock).getRoot());
@@ -142,9 +159,6 @@
// I don't know why it's done like this.
auto_ptr<movie_instance> mi (_movieDef->create_movie_instance());
- // Setup Movie Instance.
- _movieInstance = mi.get();
-
// Put the instance on stage.
_movieRoot->setRootMovie( mi.release() );
@@ -159,6 +173,14 @@
_movieRoot->allowRescaling(allow);
}
+// Whether debug messages are sent to stdout
+void
+GnashPlayer::setVerbose(bool verbose)
+{
+ // Can't turn this off yet...
+ if (verbose) _logFile.setVerbosity();
+}
+
// Move Gnash's sense of time along manually
void
GnashPlayer::advanceClock(unsigned long ms)
@@ -167,13 +189,15 @@
_manualClock.advance(ms);
}
+// This moves the manual clock on automatically by the length of
+// time allocated to a frame by the FPS setting.
void
GnashPlayer::advance() {
REQUIRE_VM_STARTED;
float fps = getSWFFrameRate();
- unsigned long clockAdvance = long(1000/fps);
+ unsigned long clockAdvance = long(1000 / fps);
advanceClock(clockAdvance);
_movieRoot->advance();
@@ -182,11 +206,30 @@
// Send a key event to the movie. This is matched to
// gnash::key::code. You could even use this to
// implement a UI in python.
-void
+bool
GnashPlayer::pressKey(int code)
{
REQUIRE_VM_STARTED;
- _movieRoot->notify_key_event((gnash::key::code)code, true);
+ return _movieRoot->notify_key_event((gnash::key::code)code, true);
+}
+
+// Move the pointer to the specified coordinates.
+bool
+GnashPlayer::movePointer(int x, int y)
+{
+ _xpos = x;
+ _ypos = y;
+ return _movieRoot->notify_mouse_moved(x, y);
+}
+
+// Click the mouse at the specified coordinates.
+bool
+GnashPlayer::mouseClick()
+{
+ return ((
+ _movieRoot->notify_mouse_clicked(true, 1) ||
+ _movieRoot->notify_mouse_clicked(false, 1)
+ ));
}
// Start the movie from the beginning.
@@ -273,40 +316,40 @@
// Renderer functions
//
-// Initialize the named rendererm throwing exception
+// Initialize the named renderer
bool
-GnashPlayer::initRenderer(const std::string& r)
+GnashPlayer::setRenderer(const std::string& r)
{
- if (_handler) return false;
+
+ // Set pointer to NULL in case we want to change renderer, which
+ // is entirely possible. This is necessary to check if the switch
+ // succeeded or not.
+ _renderer = NULL;
#ifdef RENDERER_AGG
if (r.substr(0,4) == "AGG_") {
- _handler = gnash::create_render_handler_agg(r.substr(4).c_str());
+ _renderer = gnash::create_render_handler_agg(r.substr(4).c_str());
}
#endif
#ifdef RENDERER_CAIRO
else if (r == "Cairo") {
- _handler = (gnash::renderer::cairo::create_handler();
+ _renderer = (gnash::renderer::cairo::create_renderer();
}
#endif
#ifdef RENDERER_OPENGL
else if (r == "OpenGL") {
- _handler = gnash::create_render_handler_ogl(false);
+ _renderer = gnash::create_render_handler_ogl(false);
}
#endif
- if (!_handler) {
- // If the handler doesn't exist or can't be opened, throw
- // exception
- throw GnashException("Cannot create that renderer");
- }
- else {
- // Try adding handler, return result
- return addRenderer(_handler);
+ if (!_renderer) {
+ // If the handler doesn't exist or can't be opened, return false.
+ return false;
}
- // Shouldn't get to here...
- return false;
+ // Try to add the renderer.
+ return addRenderer(_renderer);
+
}
// Test and set the render handler, returning false if anything
@@ -314,6 +357,7 @@
bool
GnashPlayer::addRenderer(gnash::render_handler* handler)
{
+ // A brief test to see if the renderer works.
if (!handler->initTestBuffer(getSWFWidth(), getSWFHeight())) {
return false;
}
@@ -325,25 +369,24 @@
// Render the frame
void
-GnashPlayer::render()
+GnashPlayer::render(bool forceRedraw)
{
- if (!_handler) return;
+ if (!_renderer) return;
_invalidatedBounds.setNull();
_movieRoot->add_invalidated_bounds(_invalidatedBounds, false);
- // Force full redraw by using a WORLD invalidated ranges
gnash::InvalidatedRanges ranges = _invalidatedBounds;
- if ( _forceRedraw ) {
- ranges.setWorld(); // set to world if asked a full redraw
- _forceRedraw = false; // reset to no forced redraw
- }
- gnash::set_render_handler(_handler);
+ if (forceRedraw) {
+ // Change invalidated regions to cover entire movie
+ // if the caller asked for a full redraw
+ ranges.setWorld();
+ }
- _handler->set_invalidated_regions(ranges);
+ _renderer->set_invalidated_regions(ranges);
_movieRoot->display();
}
Index: pythonmodule/gnashpython.h
===================================================================
RCS file: /sources/gnash/gnash/pythonmodule/gnashpython.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pythonmodule/gnashpython.h 10 Jan 2008 00:36:24 -0000 1.2
+++ pythonmodule/gnashpython.h 11 Jan 2008 16:50:36 -0000 1.3
@@ -16,19 +16,28 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
+
#ifndef GNASHPYTHON_H
#define GNASHPYTHON_H
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "gnash.h"
#include "ManualClock.h"
#include "movie_root.h"
#include "movie_definition.h"
#include "render_handler.h"
-#include "movie_instance.h"
#include "character.h"
+#include "log.h"
#include <string>
+// Because the Python bindings are there to allow flexible access
+// to Gnash in an interpreted language, there need to be many
+// checks on initialization order to avoid memory errors.
+
// Boost 1.33 seems to dislike auto_ptrs in the class
// declaration. Perhaps I'm not handling them correctly, perhaps
// it's better in 1.34.
@@ -36,10 +45,8 @@
// Forward declarations
namespace gnash {
namespace pythonwrapper {
-
class GnashCharacter;
class GnashPlayer;
-
}
}
@@ -55,13 +62,15 @@
GnashPlayer();
~GnashPlayer();
+ // For exiting
+ void close();
+
// Movie creation
- bool createMovieDefinition();
+ bool loadMovie(std::string url);
bool initVM();
- void setBaseURL(std::string url);
- bool initRenderer(const std::string& r);
- bool addRenderer(gnash::render_handler* handler);
+ // Renderer
+ bool setRenderer(const std::string& r);
// Movie information
float getSWFFrameRate() const;
@@ -73,35 +82,54 @@
int getSWFBytesLoaded() const;
std::string getSWFURL() const;
+ // Player state
int getCurrentFrame() const;
// Sprites
-
GnashCharacter* getCharacterById(int id);
GnashCharacter* getTopmostMouseEntity();
// Interaction
void advanceClock(unsigned long ms);
void advance();
- void pressKey(int code);
void allowRescale(bool allow);
- void render();
+ void render(bool forceRedraw);
void restart();
+ void setVerbose(bool verbose);
+
+ // Move the pointer to position x, y.
+ // @ return whether the move triggered an event needing a redraw. Use this
+ // to decide whether to rerender.
+ bool movePointer(int x, int y);
+
+ // Send a mouse click event at the current position of the pointer.
+ // @ return whether the move triggered an event needing a redraw. Use this
+ // to decide whether to rerender.
+ bool mouseClick();
+
+ // @ return whether the keypress triggered an event needing a redraw. Use
this
+ // to decide whether to rerender.
+ bool pressKey(int code);
private:
void init();
+ void setBaseURL(std::string url);
+ bool addRenderer(gnash::render_handler* handler);
gnash::movie_definition* _movieDef;
gnash::movie_root* _movieRoot;
- gnash::movie_instance* _movieInstance;
gnash::ManualClock _manualClock;
+ gnash::render_handler* _renderer;
- gnash::render_handler* _handler;
+ gnash::InvalidatedRanges _invalidatedBounds;
+
+ gnash::LogFile& _logFile ;
+
+ // The position of our pointer
+ int _xpos, _ypos;
// The base URL of the movie;
std::string _url;
- bool _forceRedraw;
- gnash::InvalidatedRanges _invalidatedBounds;
// File to open (a bit primitive...)
FILE* _fp;
@@ -114,12 +142,11 @@
GnashCharacter(gnash::character* c);
~GnashCharacter();
- const std::string name() { return _character->get_name(); }
+ const std::string name() { return _character->getTarget(); }
const float ratio() { return _character->get_ratio(); }
private:
gnash::character* _character;
-
};
}
Index: pythonmodule/gnashPythonExample.py
===================================================================
RCS file: /sources/gnash/gnash/pythonmodule/gnashPythonExample.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pythonmodule/gnashPythonExample.py 10 Jan 2008 00:36:24 -0000 1.2
+++ pythonmodule/gnashPythonExample.py 11 Jan 2008 16:50:36 -0000 1.3
@@ -41,12 +41,9 @@
# Functions are accessed through the Player() class
player = gnash.Player()
-# The initialization of the player is split into three stages. First,
-# set the base URL:
-player.setBaseURL("../../testsuite/movies.all/gravity.swf")
-
-# Then instruct Gnash to load the movie from the URL:
-if player.loadMovie():
+# The initialization of the player is split into two stages.
+# First, load the movie from the URL (currently only local files):
+if player.loadMovie("../../testsuite/movies.all/gravity.swf"):
print "Movie successfully created."
else:
print "Load of movie failed."
@@ -55,13 +52,13 @@
# At this stage, you can query movie properties like so:
print "The frame rate of this movie is " + str(player.swfFrameRate()) + " FPS."
print "It has " + str(player.swfFrameCount()) + " frames altogether."
-print "Loaded " + str(player.swfBytesLoaded()) + " of " +
str(player.swfBytesTotal()) + "reported bytes."
+print "Loaded " + str(player.swfBytesLoaded()) + " of " +
str(player.swfBytesTotal()) + " reported bytes."
print "It is version " + str(player.swfVersion()) +"."
print "It is " + str(player.swfWidth()) + "x" + str(player.swfWidth()) + "
pixels."
print "URL: " + player.swfURL() + "."
-# The third stage completes initialization.
+# The second stage completes loading and initialization.
if player.initVM():
print "VM initialized."
else:
@@ -72,9 +69,9 @@
print "Loaded " + str(player.swfBytesLoaded()) + " of " +
str(player.swfBytesTotal()) + " bytes reported."
# This initializes the named renderer. "Cairo", "OpenGL" and various
-# AGG types are possible. Asking for a non-existent renderer results
-# in a runtime exception.
-if player.addRenderer("AGG_RGB565"):
+# AGG types are possible. Returns False if the renderer does not exist
+# or otherwise fails.
+if player.setRenderer("AGG_RGB565"):
print "Renderer added."
# Once the movie is loaded, you can advance to the next frame of the movie.
@@ -85,12 +82,19 @@
# Advance 10 times.
for i in range(0,10):
player.advance()
- print player.currentFrame()
+ print "Frame: " + str(player.currentFrame())
print "After 10 advances we are at frame " + str(player.currentFrame()) + "
(You don't necessarily move to the next frame when you advance)."
-# Render like this (don't expect to see anything...)
-player.render()
+# Render like this (don't expect to see anything):
+player.render(True)
+# By passing 'True', you can force the renderer to redraw
+# the entire window. False redraws only the invalidated bounds
+# calculated by Gnash.
+
+# Turn verbosity on to send debug messages to stdout and the logfile.
+player.setVerbose(True)
+# This can't be turned off at the moment.
# You can also make time pass in an instant:
player.advanceClock(199)
@@ -98,8 +102,15 @@
# or press a key
player.pressKey(65)
-
-
+# Move the pointer to the specified co-ordinates. Returns true if the
+# action requires a redraw.
+if player.movePointer(x,y):
+ render(False)
+
+# Click the mouse at the current pointer position. True if the action
+# requires a redraw.
+if player.clickMouse():
+ render(False)
Index: server/LoadVariablesThread.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/LoadVariablesThread.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- server/LoadVariablesThread.cpp 11 Jan 2008 14:38:43 -0000 1.5
+++ server/LoadVariablesThread.cpp 11 Jan 2008 16:50:36 -0000 1.6
@@ -86,7 +86,7 @@
_bytesLoaded = _stream->get_position();
if ( _bytesTotal != _bytesLoaded )
{
- log_error("Size of stream variables were loaded from advertised
to be %d bytes long, while turned out to be only %d bytes long",
+ log_error("Size of stream variables were loaded from advertised
to be "SIZET_FMT" bytes long, but turned out to be only "SIZET_FMT" bytes long",
_bytesTotal, _bytesLoaded);
_bytesTotal = _bytesLoaded;
}
Index: server/sprite_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.cpp,v
retrieving revision 1.439
retrieving revision 1.440
diff -u -b -r1.439 -r1.440
--- server/sprite_instance.cpp 11 Jan 2008 11:42:44 -0000 1.439
+++ server/sprite_instance.cpp 11 Jan 2008 16:50:36 -0000 1.440
@@ -1544,7 +1544,7 @@
{
std::stringstream ss; fn.dump_args(ss);
log_debug("%s.beginGradientFill(%s) : too many array elements"
- " for colors and ratios (%d), trim to 8",
+ " for colors and ratios ("SIZET_FMT"), trim to 8",
sprite->getTarget().c_str(), ss.str().c_str(),
ngradients);
ngradients = 8;
}
@@ -1554,7 +1554,7 @@
for (size_t i=0; i<ngradients; ++i)
{
char buf[32];
- sprintf(buf, "%d", i);
+ sprintf(buf, SIZET_FMT, i);
string_table::key key = st.find(buf);
as_value colVal = colors->getMember(key);
@@ -2871,7 +2871,7 @@
if ( ! m_def->ensure_frame_loaded(target_frame_number+1) )
{
- log_error("Target frame of a gotoFrame("SIZET_FMT") was
never loaded, although frame count in header (%d) said we would have found it",
+ log_error("Target frame of a gotoFrame("SIZET_FMT") was
never loaded, although frame count in header ("SIZET_FMT") said we would have
found it",
target_frame_number+1,
m_def->get_frame_count());
return; // ... I guess, or not ?
}
@@ -2916,7 +2916,7 @@
);
if ( ! m_def->ensure_frame_loaded(target_frame_number+1) )
{
- log_error("Target frame of a gotoFrame("SIZET_FMT") was
never loaded, although frame count in header (%d) said we would have found it",
+ log_error("Target frame of a gotoFrame("SIZET_FMT") was
never loaded, although frame count in header ("SIZET_FMT") said we would have
found it",
target_frame_number+1,
m_def->get_frame_count());
return; // ... I guess, or not ?
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog pythonmodule/pyGnash.cpp python...,
Benjamin Wolsey <=