Gnash 0.8.10dev
|
00001 // sprite_definition.h: Holds immutable data for a sprite, for Gnash. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00004 // 2011 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 00074 // 00083 void registerClass(as_function* the_class); 00084 00086 as_function* getRegisteredClass() const { 00087 return registeredClass; 00088 } 00089 00090 virtual void incrementLoadedFrames() { 00091 ++m_loading_frame; 00092 } 00093 00094 // overload from movie_definition 00095 virtual size_t get_width_pixels() const { return 1; } 00096 00097 // overload from movie_definition 00098 virtual size_t get_height_pixels() const { return 1; } 00099 00100 // overload from movie_definition 00101 virtual size_t get_frame_count() const { return m_frame_count; } 00102 00107 virtual size_t get_bytes_total() const 00108 { 00109 return m_movie_def.get_bytes_total(); 00110 } 00111 00116 virtual size_t get_bytes_loaded() const 00117 { 00118 return m_movie_def.get_bytes_loaded(); 00119 } 00120 00121 virtual float get_frame_rate() const 00122 { 00123 return m_movie_def.get_frame_rate(); 00124 } 00125 00126 const SWFRect& get_frame_size() const 00127 { 00128 abort(); 00129 static const SWFRect unused; 00130 return unused; 00131 } 00132 00133 // Return number of frames loaded (of current sprite) 00134 virtual size_t get_loading_frame() const { return m_loading_frame; } 00135 00136 virtual int get_version() const 00137 { 00138 return m_movie_def.get_version(); 00139 } 00140 00142 virtual void add_font(int /*id*/, boost::intrusive_ptr<Font> /*ch*/) 00143 { 00144 IF_VERBOSE_MALFORMED_SWF ( 00145 log_swferror(_("add_font tag appears in sprite tags")); 00146 ); 00147 } 00148 00150 virtual Font* get_font(int id) const 00151 { 00152 return m_movie_def.get_font(id); 00153 } 00154 00156 virtual CachedBitmap* getBitmap(int id) const 00157 { 00158 return m_movie_def.getBitmap(id); 00159 } 00160 00162 virtual void addBitmap(int /*id*/, boost::intrusive_ptr<CachedBitmap> /*im*/) 00163 { 00164 IF_VERBOSE_MALFORMED_SWF ( 00165 log_swferror(_("add_bitmap_SWF::DefinitionTag appears in sprite tags")); 00166 ); 00167 } 00168 00170 virtual sound_sample* get_sound_sample(int id) const 00171 { 00172 return m_movie_def.get_sound_sample(id); 00173 } 00174 00176 virtual void add_sound_sample(int id, sound_sample* sam) 00177 { 00178 // DEFINESOUND tags *are* allowed in a sprite context, 00179 // and it is *expected* for them to be registered into 00180 // the main dictionary. 00181 m_movie_def.add_sound_sample(id,sam); 00182 } 00183 00184 // See dox in movie_definition.h 00185 virtual void set_loading_sound_stream_id(int id) 00186 { 00187 _loadingSoundStream = id; 00188 } 00189 00190 // See dox in movie_definition.h 00191 virtual int get_loading_sound_stream_id() const 00192 { 00193 return _loadingSoundStream; 00194 } 00195 00196 virtual boost::uint16_t exportID(const std::string& symbol) const { 00197 return m_movie_def.exportID(symbol); 00198 } 00199 00200 virtual void registerExport(const std::string& s, boost::uint16_t id) { 00201 m_movie_def.registerExport(s, id); 00202 } 00203 00208 virtual SWF::DefinitionTag* getDefinitionTag(boost::uint16_t id) const 00209 { 00210 return m_movie_def.getDefinitionTag(id); 00211 } 00212 00214 virtual void addDisplayObject(boost::uint16_t id, SWF::DefinitionTag* c) 00215 { 00216 m_movie_def.addDisplayObject(id, c); 00217 } 00218 00219 // Create a (mutable) instance of our definition. The 00220 // instance is created to live (temporarily) on some level on 00221 // the parent movie's display list. 00222 // 00223 // overloads from SWF::DefinitionTag 00224 virtual DisplayObject* createDisplayObject(Global_as& gl, 00225 DisplayObject* parent) const; 00226 00227 // See dox in movie_definition.h 00228 virtual void addControlTag(boost::intrusive_ptr<SWF::ControlTag> c) 00229 { 00230 m_playlist[m_loading_frame].push_back(c); 00231 } 00232 00233 private: 00234 00235 void read(SWFStream& in, const RunResources& runResources); 00236 00239 movie_definition& m_movie_def; 00240 00241 typedef std::map<size_t, PlayList> PlayListMap; 00242 00244 PlayListMap m_playlist; 00245 00246 // stores 0-based frame #'s 00247 typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap; 00248 NamedFrameMap _namedFrames; 00249 00250 size_t m_frame_count; 00251 00252 // Number of frames completely parsed 00253 size_t m_loading_frame; 00254 00255 // See dox in movie_definition.h 00256 virtual void add_frame_name(const std::string& name); 00257 00258 // See dox in movie_definition 00259 bool get_labeled_frame(const std::string& label, size_t& frame_number) 00260 const; 00261 00263 const PlayList* getPlaylist(size_t frame_number) const 00264 { 00265 // Don't access playlist of a frame which has not been 00266 // completely parsed yet. 00267 //assert(frame_number < m_loading_frame); 00268 00269 PlayListMap::const_iterator it = m_playlist.find(frame_number); 00270 if ( it == m_playlist.end() ) return NULL; 00271 else return &(it->second); 00272 } 00273 00274 virtual const std::string& get_url() const 00275 { 00276 return m_movie_def.get_url(); 00277 } 00278 00283 virtual bool ensure_frame_loaded(size_t framenum) const 00284 { 00285 // TODO: return false on timeout 00286 while ( m_loading_frame < framenum ) 00287 { 00288 log_debug(_("sprite_definition: " 00289 "loading of frame %d requested " 00290 "(we are at %d/%d)"), 00291 framenum, m_loading_frame, m_frame_count); 00292 // Could this ever happen ? YES ! See tuner_7_6_0_0_pandora.swf 00293 return false; 00294 } 00295 return true; 00296 } 00297 00300 // 00302 as_function* registeredClass; 00303 00304 int _loadingSoundStream; 00305 00306 protected: 00307 00309 // 00313 void markReachableResources() const; 00314 }; 00315 00316 00317 } // end of namespace gnash 00318 00319 #endif