Gnash  0.8.11dev
DoInitActionTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SWF_DOINITACTIONTAG_H
20 #define GNASH_SWF_DOINITACTIONTAG_H
21 
22 #include "ControlTag.h" // for inheritance
23 #include "SWF.h" // for TagType definition
24 #include "action_buffer.h" // for composition
25 #include "MovieClip.h" // for inlines
26 #include "SWFStream.h" // for inlines
27 
28 // Forward declarations
29 namespace gnash {
30  class movie_definition;
31 }
32 
33 namespace gnash {
34 namespace SWF {
35 
37 //
41 {
42 public:
43 
45  :
46  _buf(md),
47  _cid(cid)
48  {
49  read(in);
50  }
51 
53  //
56  //
59  virtual void executeState(MovieClip* m, DisplayList& /*dlist*/) const {
60  m->execute_init_action_buffer(_buf, _cid);
61  }
62 
63  static void loader(SWFStream& in, TagType tag, movie_definition& m,
64  const RunResources& /*r*/)
65  {
66  if (m.isAS3()) {
68  log_swferror("SWF contains DoInitAction tag, but is an "
69  "AS3 SWF!");
70  );
71  throw ParserException("DoInitAction tag found in AS3 SWF!");
72  }
73 
74  in.ensureBytes(2);
75  const std::uint16_t cid = in.read_u16();
76 
78  log_parse(_(" tag %d: do_init_action_loader"), tag);
79  log_parse(_(" -- init actions for sprite %d"), cid);
80  );
81 
82  // TODO: Currently, tags are only be executed for already parsed
83  // character ids. This is known to be wrong: a more accurate
84  // description is:
85  //
86  // The DoInitAction tag is executed only for characters on the stage
87  // or exported characters. It is only executed once.
88  //
89  // It's not known whether characters that were placed on the stage
90  // but then removed before the InitAction tag is encountered cause
91  // the actions to be executed.
92  //
93  // Gnash currently doesn't know which characters are on the stage, or
94  // which IDs have been exported.
95  boost::intrusive_ptr<ControlTag> da(new DoInitActionTag(in, m, cid));
96  m.addControlTag(da); // ownership transferred
97  }
98 
99 private:
100 
102  //
103  void read(SWFStream& in)
104  {
105  _buf.read(in, in.get_tag_end_position());
106  }
107 
108 
109  action_buffer _buf;
110 
111  // id of referenced DisplayObject definition
112  int _cid;
113 };
114 
115 } // namespace gnash::SWF
116 } // namespace gnash
117 
118 
119 #endif // GNASH_SWF_DOINITACTIONTAG_H
120 
121 
122 // Local Variables:
123 // mode: C++
124 // indent-tabs-mode: t
125 // End:
126 
unsigned long get_tag_end_position()
Return the file position of the end of the current tag.
Definition: SWFStream.cpp:497
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:83
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
An SWF parsing exception.
Definition: GnashException.h:89
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
SWF Tag DoInitAction (59)
Definition: DoInitActionTag.h:40
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
Control tags are swf tags that control the operation of the movie.
Definition: ControlTag.h:43
void execute_init_action_buffer(const action_buffer &a, int cid)
Execute the given init action buffer, if not done yet for the target DisplayObject id...
Definition: MovieClip.cpp:980
void log_parse(StringType msg, Args... args)
Definition: log.h:313
virtual void executeState(MovieClip *m, DisplayList &) const
Execute &#39;state&#39; tags.
Definition: DoInitActionTag.h:59
static void loader(SWFStream &in, TagType tag, movie_definition &m, const RunResources &)
Definition: DoInitActionTag.h:63
#define _(String)
Definition: log.h:44
DoInitActionTag(SWFStream &in, movie_definition &md, int cid)
Definition: DoInitActionTag.h:44
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
void read(SWFStream &in, unsigned long endPos)
Read action bytes from input stream up to but not including endPos.
Definition: action_buffer.cpp:48
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
virtual bool isAS3() const
True if the SWFMovie should use AVM2.
Definition: movie_definition.h:410
Definition: GnashKey.h:159
A code segment.
Definition: action_buffer.h:49
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag >)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: movie_definition.h:273
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
Definition: GnashKey.h:331
SWF stream wrapper class.
Definition: SWFStream.h:58
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag...
Definition: SWFStream.cpp:50