16
16
// along with this program; if not, write to the Free Software
17
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* $Id: processor.cpp,v 1.84.2.1 2008/03/03 16:53:25 strk Exp $ */
21
20
#ifdef HAVE_CONFIG_H
22
21
#include "gnashconfig.h"
24
#include "NullSoundHandler.h"
25
26
#include <iostream>
27
29
#include <sys/time.h>
34
36
#include "gettext.h"
37
#include "ClockTime.h"
37
39
#include "movie_definition.h"
38
40
#include "sprite_instance.h"
97
gnash::movie_definition* m_movie;
101
gnash::movie_definition* m_movie;
98
102
std::string m_filename;
101
static gnash::movie_definition* play_movie(const char* filename);
105
static boost::intrusive_ptr<gnash::movie_definition> play_movie(const char* filename);
103
107
static bool s_do_output = false;
104
108
static bool s_stop_on_errors = true;
112
116
resetLastAdvanceTimer()
114
using namespace tu_timer;
115
lastAdvanceTimer = ticks_to_seconds(get_ticks());
118
// clocktime::getTicks() returns milliseconds
119
lastAdvanceTimer = static_cast<double>(clocktime::getTicks()) / 1000.0;
119
123
secondsSinceLastAdvance()
121
using namespace tu_timer;
122
double now = ticks_to_seconds(get_ticks());
125
// clocktime::getTicks() returns milliseconds
126
double now = static_cast<double>(clocktime::getTicks()) / 1000.0;
123
127
return ( now - lastAdvanceTimer);
129
133
static int quitrequested = false;
131
void execFsCommand(sprite_instance* movie, const char* command, const char* args)
133
log_debug(_("fs_callback(%p): %s %s"), (void*)movie, command, args);
135
if ( ! strcasecmp(command, "quit") ) quitrequested=true;
135
class FsCommandExecutor: public movie_root::AbstractFsCallback {
137
void notify(const std::string& command, const std::string& args)
139
log_debug(_("fs_callback(%p): %s %s"), command, args);
141
StringNoCaseEqual ncasecomp;
143
if ( ncasecomp(command, "quit") ) quitrequested = true;
147
class EventCallback: public movie_root::AbstractIfaceCallback {
149
std::string call(const std::string& event, const std::string& arg)
151
log_debug(_("eventCallback: %s %s"), event, arg);
153
static bool mouseShown = true;
155
// These should return "true" if the mouse was visible before
157
if ( event == "Mouse.hide" ) {
158
bool state = mouseShown;
160
return state ? "true" : "false";
163
if ( event == "Mouse.show" ) {
164
bool state = mouseShown;
166
return state ? "true" : "false" ;
169
// Some fake values for consistent test results.
171
if ( event == "System.capabilities.screenResolutionX" ) {
175
if ( event == "System.capabilities.screenResolutionY" ) {
179
if ( event == "System.capabilities.screenDPI" ) {
183
if ( event == "System.capabilities.screenColor" ) {
187
if ( event == "System.capabilities.playerType" ) {
196
EventCallback eventCallback;
197
FsCommandExecutor execFsCommand;
139
200
main(int argc, char *argv[])
144
205
// Enable native language support, i.e. internationalization
145
206
#ifdef ENABLE_NLS
146
setlocale (LC_ALL, "");
207
std::setlocale (LC_ALL, "");
147
208
bindtextdomain (PACKAGE, LOCALEDIR);
148
209
textdomain (PACKAGE);
165
226
std::vector<const char*> infiles;
167
RcInitFile& rcfile = RcInitFile::getDefaultInstance();
228
//RcInitFile& rcfile = RcInitFile::getDefaultInstance();
229
//rcfile.loadFiles();
170
231
if (rcfile.verbosityLevel() > 0) {
171
232
dbglogfile.setVerbosity(rcfile.verbosityLevel());
235
dbglogfile.setLogFilename(rcfile.getDebugLog());
237
if (rcfile.useWriteLog()) {
238
dbglogfile.setWriteDisk(true);
174
241
if (rcfile.useActionDump()) {
175
242
dbglogfile.setActionDump(true);
220
287
allowed_end_hits = strtol(optarg, NULL, 0);
223
delay = atoi(optarg)*1000; // delay is in microseconds
290
delay = strtol(optarg, NULL, 0)*1000; // delay is in microseconds
224
291
// this will be recognized as a request to run at FPS speed
225
292
if ( delay < 0 ) delay = -1;
255
gnash::set_use_cache_files(false); // don't load old cache files!
322
std::auto_ptr<media::sound_handler> soundHandler(new media::NullSoundHandler());
323
gnash::set_sound_handler(soundHandler.get());
257
325
std::vector<movie_data> data;
268
register_fscommand_callback(execFsCommand);
270
336
// Play through all the movies.
271
337
for (int i = 0, n = infiles.size(); i < n; i++) {
273
339
set_base_url(URL(infiles[i]));
275
gnash::movie_definition* m = play_movie(infiles[i]);
341
boost::intrusive_ptr<gnash::movie_definition> m = play_movie(infiles[i]);
277
343
if (s_stop_on_errors) {
302
368
// or build font textures again.
304
370
// Return the movie definition.
305
gnash::movie_definition*
371
boost::intrusive_ptr<gnash::movie_definition>
306
372
play_movie(const char* filename)
308
gnash::movie_definition* md;
374
boost::intrusive_ptr<gnash::movie_definition> md;
311
377
if ( ! strcmp(filename, "-") )
313
std::auto_ptr<tu_file> in ( noseek_fd_adapter::make_stream(fileno(stdin)) );
379
std::auto_ptr<IOChannel> in ( noseek_fd_adapter::make_stream(fileno(stdin)) );
314
380
md = gnash::create_movie(in, filename, false);
347
413
long clockAdvance = fpsDelay/1000;
348
414
long localDelay = delay == -1 ? fpsDelay : delay; // microseconds
350
printf("Will sleep %ld microseconds between iterations - fps is %g, clockAdvance is %lu\n", localDelay, fps, clockAdvance);
416
log_debug("Will sleep %ld microseconds between iterations - "
417
"fps is %g, clockAdvance is %lu", localDelay, fps, clockAdvance);
352
419
// Use a clock advanced at every iteration to match exact FPS speed.
354
421
gnash::movie_root& m = VM::init(*md, cl).getRoot();
423
// Register processor to receive ActionScript events (Mouse, Stage
425
m.registerEventCallback(&eventCallback);
426
m.registerFSCommandCallback(&execFsCommand);
356
428
md->completeLoad();
367
printf("iteration, timer: %lu, localDelay: %ld\n", cl.elapsed(), localDelay);
439
log_debug("iteration, timer: %lu, localDelay: %ld\n",
440
cl.elapsed(), localDelay);
441
gnashSleep(localDelay);
370
443
resetLastAdvanceTimer();
371
444
int kick_count = 0;
413
486
if ( allowed_end_hits && ++end_hitcount >= allowed_end_hits )
415
printf("exiting after " SIZET_FMT
416
" times last frame was reached\n", end_hitcount);
488
log_debug("exiting after %d"
489
" times last frame was reached", end_hitcount);
453
526
if ( last_frame > latest_frame ) latest_frame = last_frame;
454
527
if ( ++loop_back_count > allowloopbacks )
456
printf(SIZET_FMT " loop backs; jumping one-after "
457
"latest frame (" SIZET_FMT ")\n",
529
log_debug("%d loop backs; jumping one-after "
458
531
loop_back_count, latest_frame+1);
459
532
m.goto_frame(latest_frame + 1);
460
533
loop_back_count = 0;
467
540
resetLastAdvanceTimer();
470
printf("iteration, timer: %lu, localDelay: %ld\n", cl.elapsed(), localDelay);
543
log_debug("iteration, timer: %lu, localDelay: %ld\n",
544
cl.elapsed(), localDelay);
545
gnashSleep(localDelay);