Plug more leaks (in the test, not the core)
[gnash.git] / libcore / SWFMovie.cpp
blob823b47d2a1be4ef429c6cef42f717bb56ee08fad
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // 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
19 #include "SWFMovie.h"
20 #include "movie_definition.h"
21 #include "movie_root.h"
22 #include "log.h"
24 #include <vector>
25 #include <string>
27 #include <functional> // for mem_fun, bind1st
28 #include <algorithm> // for for_each, std::min
29 #include <utility>
30 #include <map>
32 namespace gnash {
34 SWFMovie::SWFMovie(as_object* object, const SWFMovieDefinition* def,
35 DisplayObject* parent)
37 Movie(object, def, parent),
38 _def(def)
40 assert(object);
43 void
44 SWFMovie::construct(as_object* /*init*/)
47 saveOriginalTarget();
49 // Load first frame (1-based index)
50 size_t nextframe = 1;
51 if ( !_def->ensure_frame_loaded(nextframe) )
53 IF_VERBOSE_MALFORMED_SWF(
54 log_swferror("Frame %d never loaded. Total frames: %d",
55 nextframe, get_frame_count());
59 // Invoke parent placement event handler
60 MovieClip::construct();
63 // Advance of an SWF-defined movie instance
64 void
65 SWFMovie::advance()
67 // Load next frame if available (+2 as m_current_frame is 0-based)
69 // We do this inside advance_root to make sure
70 // it's only for a root sprite (not a sprite defined
71 // by DefineSprite!)
72 size_t nextframe = std::min<size_t>(get_current_frame() + 2,
73 get_frame_count());
74 if ( !_def->ensure_frame_loaded(nextframe) )
76 IF_VERBOSE_MALFORMED_SWF(
77 log_swferror("Frame %d never loaded. Total frames: %d.",
78 nextframe, get_frame_count());
82 MovieClip::advance();
85 SWF::DefinitionTag*
86 SWFMovie::exportedCharacter(const std::string& symbol)
88 const boost::uint16_t id = _def->exportID(symbol);
89 if (!id) return 0;
90 Characters::iterator it = _characters.find(id);
91 if (it == _characters.end()) return 0;
92 return _def->getDefinitionTag(id);
95 void
96 SWFMovie::addCharacter(boost::uint16_t id)
98 // If a character is already known, we don't want to mark it uninitialized
99 // again.
100 _characters.insert(std::make_pair(id, false));
103 bool
104 SWFMovie::initializeCharacter(boost::uint16_t cid)
106 Characters::iterator it = _characters.find(cid);
107 if (it == _characters.end()) {
108 IF_VERBOSE_MALFORMED_SWF(
109 log_swferror("Attempt to perform initialized for a character %s "
110 "that does not exist (either not exported or not defined)",
111 cid);
113 return false;
115 if (it->second) return false;
116 it->second = true;
117 return true;
120 } // namespace gnash