⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameswf_test_ogl.cpp

📁 一个开源的Flash 播放器,可以在Windows/Linux 上运行
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#endif			{				fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());					exit(1);			}		}		atexit(SDL_Quit);		SDL_EnableKeyRepeat(250, 33);				if (s_bit_depth == 16)		{			// 16-bit color, surface creation is likely to succeed.			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);			SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 15);			SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);			SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);		}		else		{			assert(s_bit_depth == 32);			// 32-bit color etc, for getting dest alpha,			// for MULTIPASS_ANTIALIASING (see			// gameswf_render_handler_ogl.cpp).			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);			SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);			SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);			SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);			SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);		}		// Change the LOD BIAS values to tweak blurriness.		if (tex_lod_bias != 0.0f) {#ifdef FIX_I810_LOD_BIAS				// If 2D textures weren't previously enabled, enable			// them now and force the driver to notice the update,			// then disable them again.			if (!glIsEnabled(GL_TEXTURE_2D)) {				// Clearing a mask of zero *should* have no				// side effects, but coupled with enbling				// GL_TEXTURE_2D it works around a segmentation				// fault in the driver for the Intel 810 chip.				glEnable(GL_TEXTURE_2D);				glClear(0);				glDisable(GL_TEXTURE_2D);			}#endif // FIX_I810_LOD_BIAS			glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tex_lod_bias);		}				// Set the video mode.		if (SDL_SetVideoMode(width, height, s_bit_depth, SDL_OPENGL) == 0)		{			fprintf(stderr, "SDL_SetVideoMode() failed.");			exit(1);		}		ogl::open();		// Turn on alpha blending.		glEnable(GL_BLEND);		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);		// Turn on line smoothing.  Antialiased lines can be used to		// smooth the outsides of shapes.		glEnable(GL_LINE_SMOOTH);		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);	// GL_NICEST, GL_FASTEST, GL_DONT_CARE		glMatrixMode(GL_PROJECTION);		glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1);		glMatrixMode(GL_MODELVIEW);		glLoadIdentity();		// We don't need lighting effects		glDisable(GL_LIGHTING);		// glColorPointer(4, GL_UNSIGNED_BYTE, 0, *);		// glInterleavedArrays(GL_T2F_N3F_V3F, 0, *)		glPushAttrib (GL_ALL_ATTRIB_BITS);			}	// Load the actual movie.	gameswf::movie_definition*	md = gameswf::create_library_movie(infile);	if (md == NULL)	{		fprintf(stderr, "error: can't create a movie from '%s'\n", infile);		exit(1);	}	gameswf::movie_interface*	m = create_library_movie_inst(md);	if (m == NULL)	{		fprintf(stderr, "error: can't create movie instance\n");		exit(1);	}	gameswf::set_current_root(m);	// Mouse state.	int	mouse_x = 0;	int	mouse_y = 0;	int	mouse_buttons = 0;	float	speed_scale = 1.0f;	Uint32	start_ticks = 0;	if (do_render)	{		start_ticks = SDL_GetTicks();			}	Uint32	last_ticks = start_ticks;	int	frame_counter = 0;	int	last_logged_fps = last_ticks;	SDL_Thread *thread = NULL;	if (s_event_thread) {		thread = SDL_CreateThread(runThread, NULL);		if ( thread == NULL) {			fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());		}	}			for (;;)	{		Uint32	ticks;		if (do_render)		{			ticks = SDL_GetTicks();		}		else		{			// Simulate time.			ticks = last_ticks + (Uint32) (1000.0f / movie_fps);		}		int	delta_ticks = ticks - last_ticks;		float	delta_t = delta_ticks / 1000.f;		last_ticks = ticks;		// Check auto timeout counter.		if (exit_timeout > 0		    && ticks - start_ticks > (Uint32) (exit_timeout * 1000))		{			// Auto exit now.			break;		}				bool ret = true;		if (do_render)		{			SDL_Event	event;			// Handle input.			while (ret)			{#ifdef HAVE_LIBXML				if (s_event_thread && xml_fd > 0) {					ret = SDL_WaitEvent(&event) ? true : false;				} else {					ret = SDL_PollEvent(&event) ? true : false;				}#else				ret = SDL_PollEvent(&event) ? true : false;#endif				//printf("EVENT Type is %d\n", event.type);				switch (event.type)				{				case SDL_USEREVENT:					//printf("SDL_USER_EVENT at %s, code %d%d\n", __FUNCTION__, __LINE__, event.user.code);					ret = false;					break;				case SDL_KEYDOWN:				{					SDLKey	key = event.key.keysym.sym;					bool	ctrl = (event.key.keysym.mod & KMOD_CTRL) != 0;					if (key == SDLK_ESCAPE					    || (ctrl && key == SDLK_q)					    || (ctrl && key == SDLK_w))					{						goto done;					}					else if (ctrl && key == SDLK_p)					{						// Toggle paused state.						if (m->get_play_state() == gameswf::movie_interface::STOP)						{							m->set_play_state(gameswf::movie_interface::PLAY);						}						else						{							m->set_play_state(gameswf::movie_interface::STOP);						}					}					else if (ctrl && key == SDLK_r)					{						// Restart the movie.						m->restart();					}					else if (ctrl && (key == SDLK_LEFTBRACKET || key == SDLK_KP_MINUS))					{						m->goto_frame(m->get_current_frame()-1);					}					else if (ctrl && (key == SDLK_RIGHTBRACKET || key == SDLK_KP_PLUS))					{						m->goto_frame(m->get_current_frame()+1);					}					else if (ctrl && key == SDLK_a)					{						// Toggle antialiasing.						s_antialiased = !s_antialiased;						//gameswf::set_antialiased(s_antialiased);					}					else if (ctrl && key == SDLK_t)					{						// test text replacement / variable setting:						m->set_variable("test.text", "set_edit_text was here...\nanother line of text for you to see in the text box\nSome UTF-8: ñö£ç°ÄÀÔ¿");					}					else if (ctrl && key == SDLK_g)					{						// test get_variable.						message_log("testing get_variable: '");						message_log(m->get_variable("test.text"));						message_log("'\n");					}					else if (ctrl && key == SDLK_m)					{						// Test call_method.						const char* result = m->call_method(							"test_call",							"%d, %f, %s, %ls",							200,							1.0f,							"Test string",							L"Test long string");						if (result)						{							message_log("call_method: result = ");							message_log(result);							message_log("\n");						}						else						{							message_log("call_method: null result\n");						}					}					else if (ctrl && key == SDLK_b)					{						// toggle background color.						s_background = !s_background;					}					else if (ctrl && key == SDLK_f)	//xxxxxx					{						extern bool gameswf_debug_show_paths;						gameswf_debug_show_paths = !gameswf_debug_show_paths;					}					else if (ctrl && key == SDLK_EQUALS)					{						float	f = gameswf::get_curve_max_pixel_error();						f *= 1.1f;						gameswf::set_curve_max_pixel_error(f);						printf("curve error tolerance = %f\n", f);					}					else if (ctrl && key == SDLK_MINUS)					{						float	f = gameswf::get_curve_max_pixel_error();						f *= 0.9f;						gameswf::set_curve_max_pixel_error(f);						printf("curve error tolerance = %f\n", f);					}					key_event(key, true);					break;				}				case SDL_KEYUP:				{					SDLKey	key = event.key.keysym.sym;					key_event(key, false);					break;				}				case SDL_MOUSEMOTION:					mouse_x = (int) (event.motion.x / s_scale);					mouse_y = (int) (event.motion.y / s_scale);					break;				case SDL_MOUSEBUTTONDOWN:				case SDL_MOUSEBUTTONUP:				{					int	mask = 1 << (event.button.button - 1);					if (event.button.state == SDL_PRESSED)					{						mouse_buttons |= mask;					}					else					{						mouse_buttons &= ~mask;					}					break;				}				case SDL_QUIT:					goto done;					break;				default:					break;				}			}		}		m = gameswf::get_current_root();		gameswf::delete_unused_root();		m->set_display_viewport(0, 0, width, height);		m->set_background_alpha(s_background ? 1.0f : 0.05f);		m->notify_mouse_state(mouse_x, mouse_y, mouse_buttons);		m->advance(delta_t * speed_scale);		if (do_render)		{			glDisable(GL_DEPTH_TEST);	// Disable depth testing.			glDrawBuffer(GL_BACK);		}		m->display();		frame_counter++;				if (do_render)		{			SDL_GL_SwapBuffers();			//glPopAttrib ();			if (s_measure_performance == false)			{				// Don't hog the CPU.				SDL_Delay(delay);			}			else			{				// Log the frame rate every second or so.				if (last_ticks - last_logged_fps > 1000)				{					float	delta = (last_ticks - last_logged_fps) / 1000.f;					if (delta > 0)					{						printf("fps = %3.1f\n", frame_counter / delta);					}					else					{						printf("fps = *inf*\n");					}					last_logged_fps = last_ticks;					frame_counter = 0;				}			}		}		// See if we should exit.		if (do_loop == false		    && m->get_current_frame() + 1 == md->get_frame_count())		{			// We're reached the end of the movie; exit.			break;		}	}done:	doneYet = 1;	SDL_KillThread(thread);	// kill the network read thread	//SDL_Quit();		if (md) md->drop_ref();	if (m) m->drop_ref();	delete sound;	delete render;	// For testing purposes, throw some keypresses into gameswf,	// to make sure the key handler is properly using weak	// references to listeners.	gameswf::notify_key_event(gameswf::key::A, true);	gameswf::notify_key_event(gameswf::key::B, true);	gameswf::notify_key_event(gameswf::key::C, true);	// Clean up gameswf as much as possible, so valgrind will help find actual leaks.	gameswf::clear();	return 0;}static intrunThread(void *nothing){#ifdef HAVE_LIBXML	//int i = 123;	int val;	int count = 0;	SDL_Event *ptr;#if 1	SDL_Event ev;	ev.type = SDL_USEREVENT;	ev.user.code  = 0;	ev.user.data1 = 0;	ev.user.data2 = 0;	ptr = &ev;#else	ptr = (SDL_Event *)ev_ptr;	ptr->type = SDL_USEREVENT;	ptr->user.code  = 0;	ptr->user.data1 = 0;	ptr->user.data2 = 0;#endif	printf("Initializing event thread...\n");		while (!doneYet) {		//ptr->user.data1 = (void *)i;		// FIXME: this file descriptor is hardcoded so this		// doesn't work under GDB right now.		if ((val = gameswf::check_sockets(xml_fd)) == -1) {			sleep(100);			continue;		}		s_event_thread = true;		// Don't push an event if there is already one in the		// queue. XMLSocket::onData() will come around and get		// the data anyway.		count = SDL_PeepEvents(ptr, 1, SDL_PEEKEVENT, SDL_USEREVENT);		// printf("%d User Events in queue\n", count);		if ((count == 0) && (val >= 0)) {			//printf("Pushing User Event on queue\n");			SDL_PushEvent(ptr);			SDL_Delay(300);		}	}#endif // HAVE_LIBXML		return 0;}// Local Variables:// mode: C++// c-basic-offset: 8 // tab-width: 8// indent-tabs-mode: t// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -