Gnash  0.8.11dev
sprite_definition.h
Go to the documentation of this file.
1 // sprite_definition.h: Holds immutable data for a sprite, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 
21 #ifndef GNASH_SPRITE_DEFINITION_H
22 #define GNASH_SPRITE_DEFINITION_H
23 
24 #include <boost/intrusive_ptr.hpp>
25 #include <boost/cstdint.hpp>
26 #include <string>
27 #include <map>
28 #include "movie_definition.h" // for inheritance
29 #include "log.h"
30 #include "SWFRect.h"
31 #include "StringPredicates.h" // StringNoCaseLessThan
32 
33 // Forward declarations
34 namespace gnash {
35  class SWFStream;
36  class as_function;
37  class RunResources;
38 }
39 
40 namespace gnash
41 {
42 
43 
50 {
51 
52 public:
53 
56  //
68  const RunResources& runResources, boost::uint16_t id);
69 
72 
73  virtual void incrementLoadedFrames() {
74  ++m_loading_frame;
75  }
76 
77  // overload from movie_definition
78  virtual size_t get_width_pixels() const { return 1; }
79 
80  // overload from movie_definition
81  virtual size_t get_height_pixels() const { return 1; }
82 
83  // overload from movie_definition
84  virtual size_t get_frame_count() const { return m_frame_count; }
85 
90  virtual size_t get_bytes_total() const
91  {
92  return m_movie_def.get_bytes_total();
93  }
94 
99  virtual size_t get_bytes_loaded() const
100  {
101  return m_movie_def.get_bytes_loaded();
102  }
103 
104  virtual float get_frame_rate() const
105  {
106  return m_movie_def.get_frame_rate();
107  }
108 
109  const SWFRect& get_frame_size() const
110  {
111  abort();
112  static const SWFRect unused;
113  return unused;
114  }
115 
116  // Return number of frames loaded (of current sprite)
117  virtual size_t get_loading_frame() const { return m_loading_frame; }
118 
119  virtual int get_version() const
120  {
121  return m_movie_def.get_version();
122  }
123 
125  virtual void add_font(int /*id*/, boost::intrusive_ptr<Font> /*ch*/)
126  {
128  log_swferror(_("add_font tag appears in sprite tags"));
129  );
130  }
131 
133  virtual Font* get_font(int id) const
134  {
135  return m_movie_def.get_font(id);
136  }
137 
139  virtual CachedBitmap* getBitmap(int id) const
140  {
141  return m_movie_def.getBitmap(id);
142  }
143 
145  virtual void addBitmap(int /*id*/, boost::intrusive_ptr<CachedBitmap> /*im*/)
146  {
148  log_swferror(_("add_bitmap_SWF::DefinitionTag appears in sprite tags"));
149  );
150  }
151 
153  virtual sound_sample* get_sound_sample(int id) const
154  {
155  return m_movie_def.get_sound_sample(id);
156  }
157 
159  virtual void add_sound_sample(int id, sound_sample* sam)
160  {
161  // DEFINESOUND tags *are* allowed in a sprite context,
162  // and it is *expected* for them to be registered into
163  // the main dictionary.
164  m_movie_def.add_sound_sample(id,sam);
165  }
166 
167  // See dox in movie_definition.h
168  virtual void set_loading_sound_stream_id(int id)
169  {
170  _loadingSoundStream = id;
171  }
172 
173  // See dox in movie_definition.h
174  virtual int get_loading_sound_stream_id() const
175  {
176  return _loadingSoundStream;
177  }
178 
179  virtual boost::uint16_t exportID(const std::string& symbol) const {
180  return m_movie_def.exportID(symbol);
181  }
182 
183  virtual void registerExport(const std::string& s, boost::uint16_t id) {
184  m_movie_def.registerExport(s, id);
185  }
186 
191  virtual SWF::DefinitionTag* getDefinitionTag(boost::uint16_t id) const
192  {
193  return m_movie_def.getDefinitionTag(id);
194  }
195 
197  virtual void addDisplayObject(boost::uint16_t id, SWF::DefinitionTag* c)
198  {
199  m_movie_def.addDisplayObject(id, c);
200  }
201 
202  // Create a (mutable) instance of our definition. The
203  // instance is created to live (temporarily) on some level on
204  // the parent movie's display list.
205  //
206  // overloads from SWF::DefinitionTag
208  DisplayObject* parent) const;
209 
210  // See dox in movie_definition.h
211  virtual void addControlTag(boost::intrusive_ptr<SWF::ControlTag> c)
212  {
213  m_playlist[m_loading_frame].push_back(c);
214  }
215 
216 private:
217 
218  void read(SWFStream& in, const RunResources& runResources);
219 
222  movie_definition& m_movie_def;
223 
224  typedef std::map<size_t, PlayList> PlayListMap;
225 
227  PlayListMap m_playlist;
228 
229  // stores 0-based frame #'s
230  typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap;
231  NamedFrameMap _namedFrames;
232 
233  size_t m_frame_count;
234 
235  // Number of frames completely parsed
236  size_t m_loading_frame;
237 
238  // See dox in movie_definition.h
239  virtual void add_frame_name(const std::string& name);
240 
241  // See dox in movie_definition
242  bool get_labeled_frame(const std::string& label, size_t& frame_number)
243  const;
244 
246  const PlayList* getPlaylist(size_t frame_number) const
247  {
248  // Don't access playlist of a frame which has not been
249  // completely parsed yet.
250  //assert(frame_number < m_loading_frame);
251 
252  PlayListMap::const_iterator it = m_playlist.find(frame_number);
253  if ( it == m_playlist.end() ) return NULL;
254  else return &(it->second);
255  }
256 
257  virtual const std::string& get_url() const
258  {
259  return m_movie_def.get_url();
260  }
261 
266  virtual bool ensure_frame_loaded(size_t framenum) const
267  {
268  // TODO: return false on timeout
269  while ( m_loading_frame < framenum )
270  {
271  log_debug(_("sprite_definition: "
272  "loading of frame %d requested "
273  "(we are at %d/%d)"),
274  framenum, m_loading_frame, m_frame_count);
275  // Could this ever happen ? YES ! See tuner_7_6_0_0_pandora.swf
276  return false;
277  }
278  return true;
279  }
280 
281  int _loadingSoundStream;
282 
283 };
284 
285 
286 } // end of namespace gnash
287 
288 #endif