• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

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 Free Software
00004 //   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 
00025 #include <boost/intrusive_ptr.hpp>
00026 #include <boost/cstdint.hpp>
00027 #include <string>
00028 #include <map>
00029 #include "smart_ptr.h" // GNASH_USE_GC
00030 #include "movie_definition.h" // for inheritance
00031 #include "log.h"
00032 #include "SWFRect.h"
00033 #include "StringPredicates.h" // StringNoCaseLessThan
00034 
00035 // Forward declarations
00036 namespace gnash {
00037         class SWFStream;
00038         class as_function;
00039     class RunResources;
00040 }
00041 
00042 namespace gnash
00043 {
00044 
00045 
00051 class sprite_definition : public movie_definition
00052 {
00053 
00054 public:
00055 
00058         //
00069         sprite_definition(movie_definition& m, SWFStream& in,
00070             const RunResources& runResources, boost::uint16_t id);
00071 
00073         ~sprite_definition();
00074 
00076         //
00085         void registerClass(as_function* the_class);
00086 
00088         as_function* getRegisteredClass() const
00089         {
00090                 return registeredClass.get();
00091         }
00092 
00093     virtual void incrementLoadedFrames() {
00094         ++m_loading_frame;
00095     }
00096 
00097         // overload from movie_definition
00098         virtual size_t get_width_pixels() const { return 1; }
00099 
00100         // overload from movie_definition
00101         virtual size_t get_height_pixels() const { return 1; }
00102 
00103         // overload from movie_definition
00104         virtual size_t get_frame_count() const { return m_frame_count; }
00105 
00110         virtual size_t get_bytes_total() const
00111         {
00112                 return m_movie_def.get_bytes_total();
00113         }
00114 
00119         virtual size_t get_bytes_loaded() const
00120         {
00121                 return m_movie_def.get_bytes_loaded();
00122         }
00123 
00124         virtual float   get_frame_rate() const
00125         {
00126                 return m_movie_def.get_frame_rate();
00127         }
00128 
00129         const SWFRect& get_frame_size() const
00130         {
00131                 abort();
00132                 static const SWFRect unused;
00133                 return unused;
00134         }
00135 
00136         // Return number of frames loaded (of current sprite)
00137         virtual size_t  get_loading_frame() const { return m_loading_frame; }
00138 
00139         virtual int     get_version() const
00140         {
00141                 return m_movie_def.get_version();
00142         }
00143 
00145         virtual void add_font(int /*id*/, Font* /*ch*/)
00146         {
00147                 IF_VERBOSE_MALFORMED_SWF (
00148                 log_swferror(_("add_font tag appears in sprite tags"));
00149                 );
00150         }
00151 
00153         virtual Font* get_font(int id) const
00154         {
00155                 return m_movie_def.get_font(id);
00156         }
00157 
00159         virtual CachedBitmap* getBitmap(int id) const
00160         {
00161                 return m_movie_def.getBitmap(id);
00162         }
00163 
00165         virtual void addBitmap(int /*id*/, boost::intrusive_ptr<CachedBitmap> /*im*/)
00166         {
00167                 IF_VERBOSE_MALFORMED_SWF (
00168                 log_swferror(_("add_bitmap_SWF::DefinitionTag appears in sprite tags"));
00169                 );
00170         }
00171 
00173         virtual sound_sample* get_sound_sample(int id) const
00174         {
00175                 return m_movie_def.get_sound_sample(id);
00176         }
00177 
00179         virtual void add_sound_sample(int id, sound_sample* sam)
00180         {
00181                 // DEFINESOUND tags *are* allowed in a sprite context,
00182                 // and it is *expected* for them to be registered into
00183                 // the main dictionary.
00184                 m_movie_def.add_sound_sample(id,sam);
00185         }
00186 
00187         // See dox in movie_definition.h
00188         virtual void set_loading_sound_stream_id(int id)
00189         {
00190                 _loadingSoundStream = id;
00191         }
00192 
00193         // See dox in movie_definition.h
00194         virtual int get_loading_sound_stream_id() const
00195         {
00196                 return _loadingSoundStream;
00197         }
00198 
00199     virtual boost::uint16_t exportID(const std::string& symbol) const {
00200         return m_movie_def.exportID(symbol);
00201     }
00202     
00203     virtual void registerExport(const std::string& s, boost::uint16_t id) {
00204         m_movie_def.registerExport(s, id);
00205     }
00206 
00211         virtual SWF::DefinitionTag*     getDefinitionTag(boost::uint16_t id) const
00212         {
00213             return m_movie_def.getDefinitionTag(id);
00214         }
00215 
00217         virtual void addDisplayObject(boost::uint16_t id, SWF::DefinitionTag* c)
00218         {
00219                 m_movie_def.addDisplayObject(id, c);
00220         }
00221 
00222         // Create a (mutable) instance of our definition.  The
00223         // instance is created to live (temporarily) on some level on
00224         // the parent movie's display list.
00225         //
00226         // overloads from SWF::DefinitionTag
00227         virtual DisplayObject* createDisplayObject(Global_as& gl,
00228             DisplayObject* parent) const;
00229 
00230         // See dox in movie_definition.h
00231         virtual void addControlTag(SWF::ControlTag* c)
00232         {
00233                 m_playlist[m_loading_frame].push_back(c);
00234         }
00235 
00236 private:
00237 
00238         void read(SWFStream& in, const RunResources& runResources);
00239 
00242         movie_definition& m_movie_def;
00243 
00244         typedef std::map<size_t, PlayList> PlayListMap;
00245 
00247         PlayListMap m_playlist;
00248 
00249         // stores 0-based frame #'s
00250         typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap;
00251         NamedFrameMap _namedFrames;
00252 
00253         size_t m_frame_count;
00254 
00255         // Number of frames completely parsed 
00256         size_t m_loading_frame;
00257 
00258         // See dox in movie_definition.h
00259         virtual void add_frame_name(const std::string& name);
00260 
00261         // See dox in movie_definition
00262         bool get_labeled_frame(const std::string& label, size_t& frame_number)
00263         const;
00264 
00266         const PlayList* getPlaylist(size_t frame_number) const
00267         {
00268                 // Don't access playlist of a frame which has not been
00269                 // completely parsed yet.
00270                 //assert(frame_number < m_loading_frame);
00271 
00272                 PlayListMap::const_iterator it = m_playlist.find(frame_number);
00273                 if ( it == m_playlist.end() ) return NULL;
00274                 else return &(it->second);
00275         }
00276 
00277         virtual const std::string& get_url() const
00278         {
00279                 return m_movie_def.get_url();
00280         }
00281 
00286         virtual bool ensure_frame_loaded(size_t framenum) const
00287         {
00288                 // TODO: return false on timeout
00289                 while ( m_loading_frame < framenum )
00290                 {
00291                         log_debug(_("sprite_definition: "
00292                                 "loading of frame %d requested "
00293                                 "(we are at %d/%d)"),
00294                                 framenum, m_loading_frame, m_frame_count);
00295                         // Could this ever happen ? YES ! See tuner_7_6_0_0_pandora.swf
00296                         return false;
00297                 }
00298                 return true;
00299         }
00300 
00304         //
00308         boost::intrusive_ptr<as_function> registeredClass;
00309 
00310         int     _loadingSoundStream;
00311 
00312 protected:
00313 
00314 
00315 #ifdef GNASH_USE_GC
00316 
00317         //
00321         void markReachableResources() const;
00322 #endif // GNASH_USE_GC
00323 };
00324 
00325 
00326 } // end of namespace gnash
00327 
00328 #endif // GNASH_SPRITE_H

Generated on Thu Sep 30 2010 14:35:03 for Gnash by  doxygen 1.7.1