Пример #1
0
player::~player()
{
    // Clean up gameswf as much as possible, so valgrind will help find actual leaks.
    // Maximum release of resources.  Calls clear_library() and
    // fontlib::clear(), and also clears some extra internal stuff
    // that may have been allocated (e.g. global ActionScript
    // objects).  This should get all gameswf structures off the
    // heap, with the exception of any objects that are still
    // referenced by the host program and haven't had drop_ref()
    // called on them.

    m_current_root = NULL;
    m_global = NULL;
    --s_player_count;

    clear_heap();

    gameswf_engine_mutex().lock();

    clear_library();

    // Clear shared stuff only when all players are deleted
    if (s_player_count == 0)
    {
        clears_tag_loaders();
        clear_shared_libs();
        clear_registered_type_handlers();
        clear_standard_method_map();
        clear_disasm();
        delete s_glyph_provider;
        s_glyph_provider = NULL;
    }

    gameswf_engine_mutex().unlock();

    action_clear();
}
Пример #2
0
	void	root::advance(float delta_time)
	{
		// Lock gameswf engine. Video is running in separate thread and
		// it calls gameswf functions from separate thread to set
		// status of netstream object
		gameswf_engine_mutex().lock();

		// Handle mouse dragging
		do_mouse_drag();

		// Handle the mouse.
		character *te;
		m_movie->get_topmost_mouse_entity(te, PIXELS_TO_TWIPS(m_mouse_x), PIXELS_TO_TWIPS(m_mouse_y));
		m_mouse_button_state.m_topmost_entity = te;

		m_mouse_button_state.m_mouse_button_state_current = (m_mouse_buttons & 1);
		generate_mouse_button_events(&m_mouse_button_state);

		// advance Action script objects (interval timers, xmlsocket, ...)
		m_listener.advance(delta_time);

		m_time_remainder += delta_time;
		if (m_time_remainder >= m_frame_time)
		{

			// mark all as garbage
			m_player->set_as_garbage();

			// this should be called infinitely to not repeat
			// the game situation after restart
			tu_random::next_random();

			if (m_on_event_load_called == false)
			{
				set_flash_vars(m_player->m_flash_vars);
				if (m_def->m_is_avm2)
				{
					const abc_def* adef  = m_def->get_abc();
					if (adef)
					{
						as_environment env(m_player.get_ptr());
						gameswf::call_method(adef->get_script_function(), 
							&env, as_value(m_movie.get_ptr()), 0, 0);
					}
				}
			}

			if (m_player->get_force_realtime_framerate() == true)
			{
				while (m_time_remainder >= m_frame_time)
				{
					m_movie->advance(m_frame_time);
					m_time_remainder -= m_frame_time;
				}
			}
			else
			{
				m_movie->advance(delta_time);
				m_time_remainder = fmod(m_time_remainder - m_frame_time, m_frame_time);
			}

			if (m_on_event_load_called == false)
			{
				// Must do loading events.  For child sprites this is
				// done by the dlist, but root movies don't get added
				// to a dlist, so we do it here.
				m_on_event_load_called = true;
				m_movie->on_event(event_id::LOAD);
			}

			m_player->clear_garbage();
		}

		gameswf_engine_mutex().unlock();
	}
Пример #3
0
	void	root::notify_key_event(player* player, key::code k, bool down)
	{
		// multithread plugins can call gameswf core therefore we should 
		// use gameswf mutex to lock gameswf engine
		gameswf_engine_mutex().lock();

		// First notify global Key object
		// listeners that uses the last keypressed code
		player->notify_key_object(k, down);

		// Notify keypress listeners.
		if (down)
		{
			m_keypress_listener.notify(event_id(event_id::KEY_PRESS, (key::code) k));
		}

		// A bit of a hack huh
		if( k == key::SHIFT )
		{
			m_shift_key_state = down;
		}

		if (((key::code)k == key::TAB) && down)
		{
			bool killfocus = false;
			int	 tab = 0;
			int  lastvalid = -1;

			// lets see if focus is in the root
			int i = 0;
			for (i = 0; get_character(i) != NULL; ++i)
			{
				character* movie = get_character(i);
				assert(movie);

				if (movie->is(AS_EDIT_TEXT) == false)
				{
					continue;
				}

				if (movie->can_handle_mouse_event() == false)
				{
					continue;
				}

				if (movie == m_current_active_entity.get_ptr())
				{
					if (lastvalid != -1 && m_shift_key_state)
					{
						movie->on_event(event_id::KILLFOCUS);
						get_character(lastvalid)->on_event(event_id::SETFOCUS);
						break;
					}
					//we only want to kill focus if there is another event below this one
					tab = i;

					//now i need to find which event to set focus on
					killfocus = true;
					continue;
				}

				lastvalid = i;

				if (killfocus)
				{
					get_character(tab)->on_event(event_id::KILLFOCUS);
					movie->on_event(event_id::SETFOCUS);
					killfocus = false;
					break;
				}
			}

			if (get_character(i) == NULL)
			{
				for (int i = 0; get_character(i) != NULL; ++i)
				{
					if (stricmp(get_character(i)->type_of(), "movieclip") != 0)
					{
						continue;
					}

					change_focus_character(get_character(i), m_current_active_entity.get_ptr(), m_shift_key_state);
				}
			}
		}

		gameswf_engine_mutex().unlock();
	}