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