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