2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "movie_definition.h"
21 #include "movie_root.h"
27 #include <functional> // for mem_fun, bind1st
28 #include <algorithm> // for for_each, std::min
34 SWFMovie::SWFMovie(as_object
* object
, const SWFMovieDefinition
* def
,
35 DisplayObject
* parent
)
37 Movie(object
, def
, parent
),
44 SWFMovie::construct(as_object
* /*init*/)
49 // Load first frame (1-based index)
51 if ( !_def
->ensure_frame_loaded(nextframe
) )
53 IF_VERBOSE_MALFORMED_SWF(
54 log_swferror(_("Frame %d never loaded. Total frames: %d"),
55 nextframe
, get_frame_count());
59 // Invoke parent placement event handler
60 MovieClip::construct();
63 // Advance of an SWF-defined movie instance
67 // Load next frame if available (+2 as m_current_frame is 0-based)
69 // We do this inside advance_root to make sure
70 // it's only for a root sprite (not a sprite defined
72 size_t nextframe
= std::min
<size_t>(get_current_frame() + 2,
74 if ( !_def
->ensure_frame_loaded(nextframe
) )
76 IF_VERBOSE_MALFORMED_SWF(
77 log_swferror(_("Frame %d never loaded. Total frames: %d."),
78 nextframe
, get_frame_count());
86 SWFMovie::exportedCharacter(const std::string
& symbol
)
88 const std::uint16_t id
= _def
->exportID(symbol
);
89 if (!id
) return nullptr;
90 Characters::iterator it
= _characters
.find(id
);
91 if (it
== _characters
.end()) return nullptr;
92 return _def
->getDefinitionTag(id
);
96 SWFMovie::addCharacter(std::uint16_t id
)
98 // If a character is already known, we don't want to mark it uninitialized
100 _characters
.insert(std::make_pair(id
, false));
104 SWFMovie::initializeCharacter(std::uint16_t cid
)
106 Characters::iterator it
= _characters
.find(cid
);
107 if (it
== _characters
.end()) {
108 IF_VERBOSE_MALFORMED_SWF(
109 log_swferror(_("Attempt to perform initialized for a character %s "
110 "that does not exist (either not exported or not defined)"),
115 if (it
->second
) return false;