Gnash  0.8.10
sprite_definition.h
Go to the documentation of this file.
00001 // sprite_definition.h:  Holds immutable data for a sprite, for Gnash.
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 
00021 #ifndef GNASH_SPRITE_DEFINITION_H
00022 #define GNASH_SPRITE_DEFINITION_H
00023 
00024 #include <boost/intrusive_ptr.hpp>
00025 #include <boost/cstdint.hpp>
00026 #include <string>
00027 #include <map>
00028 #include "movie_definition.h" // for inheritance
00029 #include "log.h"
00030 #include "SWFRect.h"
00031 #include "StringPredicates.h" // StringNoCaseLessThan
00032 
00033 // Forward declarations
00034 namespace gnash {
00035         class SWFStream;
00036         class as_function;
00037     class RunResources;
00038 }
00039 
00040 namespace gnash
00041 {
00042 
00043 
00049 class sprite_definition : public movie_definition
00050 {
00051 
00052 public:
00053 
00056         //
00067         sprite_definition(movie_definition& m, SWFStream& in,
00068             const RunResources& runResources, boost::uint16_t id);
00069 
00071         ~sprite_definition();
00072 
00073     virtual void incrementLoadedFrames() {
00074         ++m_loading_frame;
00075     }
00076 
00077         // overload from movie_definition
00078         virtual size_t get_width_pixels() const { return 1; }
00079 
00080         // overload from movie_definition
00081         virtual size_t get_height_pixels() const { return 1; }
00082 
00083         // overload from movie_definition
00084         virtual size_t get_frame_count() const { return m_frame_count; }
00085 
00090         virtual size_t get_bytes_total() const
00091         {
00092                 return m_movie_def.get_bytes_total();
00093         }
00094 
00099         virtual size_t get_bytes_loaded() const
00100         {
00101                 return m_movie_def.get_bytes_loaded();
00102         }
00103 
00104         virtual float   get_frame_rate() const
00105         {
00106                 return m_movie_def.get_frame_rate();
00107         }
00108 
00109         const SWFRect& get_frame_size() const
00110         {
00111                 abort();
00112                 static const SWFRect unused;
00113                 return unused;
00114         }
00115 
00116         // Return number of frames loaded (of current sprite)
00117         virtual size_t  get_loading_frame() const { return m_loading_frame; }
00118 
00119         virtual int     get_version() const
00120         {
00121                 return m_movie_def.get_version();
00122         }
00123 
00125         virtual void add_font(int /*id*/, boost::intrusive_ptr<Font> /*ch*/)
00126         {
00127                 IF_VERBOSE_MALFORMED_SWF (
00128                 log_swferror(_("add_font tag appears in sprite tags"));
00129                 );
00130         }
00131 
00133         virtual Font* get_font(int id) const
00134         {
00135                 return m_movie_def.get_font(id);
00136         }
00137 
00139         virtual CachedBitmap* getBitmap(int id) const
00140         {
00141                 return m_movie_def.getBitmap(id);
00142         }
00143 
00145         virtual void addBitmap(int /*id*/, boost::intrusive_ptr<CachedBitmap> /*im*/)
00146         {
00147                 IF_VERBOSE_MALFORMED_SWF (
00148                 log_swferror(_("add_bitmap_SWF::DefinitionTag appears in sprite tags"));
00149                 );
00150         }
00151 
00153         virtual sound_sample* get_sound_sample(int id) const
00154         {
00155                 return m_movie_def.get_sound_sample(id);
00156         }
00157 
00159         virtual void add_sound_sample(int id, sound_sample* sam)
00160         {
00161                 // DEFINESOUND tags *are* allowed in a sprite context,
00162                 // and it is *expected* for them to be registered into
00163                 // the main dictionary.
00164                 m_movie_def.add_sound_sample(id,sam);
00165         }
00166 
00167         // See dox in movie_definition.h
00168         virtual void set_loading_sound_stream_id(int id)
00169         {
00170                 _loadingSoundStream = id;
00171         }
00172 
00173         // See dox in movie_definition.h
00174         virtual int get_loading_sound_stream_id() const
00175         {
00176                 return _loadingSoundStream;
00177         }
00178 
00179     virtual boost::uint16_t exportID(const std::string& symbol) const {
00180         return m_movie_def.exportID(symbol);
00181     }
00182     
00183     virtual void registerExport(const std::string& s, boost::uint16_t id) {
00184         m_movie_def.registerExport(s, id);
00185     }
00186 
00191         virtual SWF::DefinitionTag*     getDefinitionTag(boost::uint16_t id) const
00192         {
00193             return m_movie_def.getDefinitionTag(id);
00194         }
00195 
00197         virtual void addDisplayObject(boost::uint16_t id, SWF::DefinitionTag* c)
00198         {
00199                 m_movie_def.addDisplayObject(id, c);
00200         }
00201 
00202         // Create a (mutable) instance of our definition.  The
00203         // instance is created to live (temporarily) on some level on
00204         // the parent movie's display list.
00205         //
00206         // overloads from SWF::DefinitionTag
00207         virtual DisplayObject* createDisplayObject(Global_as& gl,
00208             DisplayObject* parent) const;
00209 
00210         // See dox in movie_definition.h
00211         virtual void addControlTag(boost::intrusive_ptr<SWF::ControlTag> c)
00212         {
00213                 m_playlist[m_loading_frame].push_back(c);
00214         }
00215 
00216 private:
00217 
00218         void read(SWFStream& in, const RunResources& runResources);
00219 
00222         movie_definition& m_movie_def;
00223 
00224         typedef std::map<size_t, PlayList> PlayListMap;
00225 
00227         PlayListMap m_playlist;
00228 
00229         // stores 0-based frame #'s
00230         typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap;
00231         NamedFrameMap _namedFrames;
00232 
00233         size_t m_frame_count;
00234 
00235         // Number of frames completely parsed 
00236         size_t m_loading_frame;
00237 
00238         // See dox in movie_definition.h
00239         virtual void add_frame_name(const std::string& name);
00240 
00241         // See dox in movie_definition
00242         bool get_labeled_frame(const std::string& label, size_t& frame_number)
00243         const;
00244 
00246         const PlayList* getPlaylist(size_t frame_number) const
00247         {
00248                 // Don't access playlist of a frame which has not been
00249                 // completely parsed yet.
00250                 //assert(frame_number < m_loading_frame);
00251 
00252                 PlayListMap::const_iterator it = m_playlist.find(frame_number);
00253                 if ( it == m_playlist.end() ) return NULL;
00254                 else return &(it->second);
00255         }
00256 
00257         virtual const std::string& get_url() const
00258         {
00259                 return m_movie_def.get_url();
00260         }
00261 
00266         virtual bool ensure_frame_loaded(size_t framenum) const
00267         {
00268                 // TODO: return false on timeout
00269                 while ( m_loading_frame < framenum )
00270                 {
00271                         log_debug(_("sprite_definition: "
00272                                 "loading of frame %d requested "
00273                                 "(we are at %d/%d)"),
00274                                 framenum, m_loading_frame, m_frame_count);
00275                         // Could this ever happen ? YES ! See tuner_7_6_0_0_pandora.swf
00276                         return false;
00277                 }
00278                 return true;
00279         }
00280 
00281         int     _loadingSoundStream;
00282 
00283 };
00284 
00285 
00286 } // end of namespace gnash
00287 
00288 #endif