1 //
2 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 //   Free Software Foundation, Inc
4 //
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.
9 //
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.
14 //
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
18 
19 // Stateful live Movie instance
20 
21 
22 #ifndef GNASH_SWF_MOVIE_H
23 #define GNASH_SWF_MOVIE_H
24 
25 #include <boost/intrusive_ptr.hpp>
26 #include <string>
27 #include <map>
28 
29 #include "Movie.h" // for inheritance
30 #include "SWFMovieDefinition.h" // for dtor visibility by smart ptr
31 #include "dsodefs.h" // for DSOTEXPORT
32 
33 // Forward declarations
34 namespace gnash {
35 	class DisplayObject;
36 }
37 
38 namespace gnash
39 {
40 
41 /// Stateful Movie object (a special kind of sprite)
42 //
43 /// The tasks of the Movie include:
44 //
45 /// 1. Keep a 'dictionary' of parsed characters.
46 ///     This is a container of characters defined in previous frames. It
47 ///     acts like a genuine runtime dictionary of characters, although Gnash
48 ///     actually stores the definitions in the SWFMovieDefinition as it is
49 ///     parsed.
50 class SWFMovie : public Movie
51 {
52 
53     /// A container to track known characters and whether they are initialized.
54     typedef std::map<std::uint16_t, bool> Characters;
55 
56 public:
57 
58 	DSOTEXPORT SWFMovie(as_object* object, const SWFMovieDefinition* def,
59             DisplayObject* parent);
60 
~SWFMovie()61 	virtual ~SWFMovie() {}
62 
63 	virtual void advance();
64 
frameRate()65     virtual float frameRate() const {
66         return _def->get_frame_rate();
67     }
68 
widthPixels()69     virtual size_t widthPixels() const {
70         return _def->get_width_pixels();
71     }
72 
heightPixels()73     virtual size_t heightPixels() const {
74         return _def->get_height_pixels();
75     }
76 
ensureFrameLoaded(size_t frameNo)77     virtual bool ensureFrameLoaded(size_t frameNo) const {
78         return _def->ensure_frame_loaded(frameNo);
79     }
80 
81 	/// Handle a top-level movie on stage placement.
82 	//
83 	/// This method will just ensure first frame is loaded
84 	/// and then call MovieClip::construct
85 	///
86 	/// It's intended to be called by movie_root::setLevel().
87     void construct(as_object* init = nullptr);
88 
89     /// Get the URL of the SWFMovie's definition.
url()90     const std::string& url() const {
91         return _def->get_url();
92     }
93 
94     /// Get the version of the SWFMovie.
95     //
96     /// @return     the version of the SWFMovie.
version()97     int version() const {
98         return _def->get_version();
99     }
100 
101     /// Get an exported character definition by its symbol name.
102     //
103     /// The character is only available after the ExportAssets tag has been
104     /// executed.
105     //
106     /// @param symbol   The exported symbol of the character to retrieve.
107     /// @return         The DefinitionTag of the requested character or 0
108     ///                 if the character has not yet been exported.
109     virtual SWF::DefinitionTag* exportedCharacter(const std::string& symbol);
110 
111     /// Add a character to the list of known characters
112     //
113     /// This makes the character known to ActionScript for initialization.
114     /// Exported characters must both be in the definition's list of exports
115     /// and added with this function before they are available.
116     //
117     /// If a duplicated character is added, it will not be marked
118     /// uninitialized, as SWF::DoInitAction tags are only executed once
119     /// for each id.
120     void addCharacter(std::uint16_t id);
121 
122     /// Attempt to mark a character as initialized.
123     //
124     /// A character can be initialized once, but only after it is known to this
125     /// Movie.
126     //
127     /// @param id   The id of the character to initialize.
128     /// @return     false if the character cannot be initialized. This can mean
129     ///             1. The character is not yet present (either not exported
130     ///                or has not yet been placed on stage).
131     ///             2. The character has already been initialized.
132     ///             true if the character was marked initialized.
133 	bool initializeCharacter(std::uint16_t id);
134 
definition()135     const movie_definition* definition() const {
136         return _def.get();
137     }
138 
139 private:
140 
141     /// Tracks known characters and whether they have been initialized.
142 	Characters _characters;
143 
144     /// This should only be a top-level movie, not a sprite_definition.
145 	const boost::intrusive_ptr<const SWFMovieDefinition> _def;
146 };
147 
148 
149 } // end of namespace gnash
150 
151 #endif // GNASH_MOVIE_INSTANCE_H
152