当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_PumpEvents函数代码示例

本文整理汇总了C++中SDL_PumpEvents函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_PumpEvents函数的具体用法?C++ SDL_PumpEvents怎么用?C++ SDL_PumpEvents使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_PumpEvents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sdl_joypad_poll

static void sdl_joypad_poll(void)
{
#ifdef HAVE_SDL2
   SDL_Event event;

   SDL_PumpEvents();

   while (SDL_PeepEvents(&event, 1,
            SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED) > 0)
   {
      switch (event.type)
      {
         case SDL_JOYDEVICEADDED:
            sdl_pad_connect(event.jdevice.which);
            break;
         case SDL_JOYDEVICEREMOVED:
            sdl_pad_disconnect(event.jdevice.which);
            break;
      }
   }
#else
   SDL_JoystickUpdate();
#endif
}
开发者ID:chungy,项目名称:RetroArch,代码行数:24,代码来源:sdl_joypad.c

示例2: levelTwo

int levelTwo()
{
	

	moving = 0;
	SDL_RenderClear(gt_graphics_get_active_renderer());
	ResetBuffer();

	backOffset = ((int)camera.x+3200)%3200;
	offset = ((int)camera.x+1600)%1600;

	drawSprite(moonBack,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	
	drawSprite(levelTwoBackTrees,0,vec2d(-backOffset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
    drawSprite(levelTwoFrontTrees,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoFloor,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	
	drawSprite(levelTwoFrontTrees,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoBackTrees,0,vec2d(-backOffset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoFloor,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());

	



	entity_think_all();
	entity_touch_all();
	entity_update_all();
	entity_draw_all();
	if(player->position.x >= 300)
		{
			camera.x = player->position.x - 300;
			
		}
	if(player->position.x < 300)
		{
			camera.x = 0;
			
		}
	if(xDistance == 12000.00)
	{
		done = 1;
	}

	healthBar();
    NextFrame();
    SDL_PumpEvents();
	diff = (gt_graphics_now - gt_graphics_then);
	
	if(playerData.shotTimer>0)
	{
		playerData.shotTimer -= diff;
	}
    keys = SDL_GetKeyboardState(NULL);
    if(keys[SDL_SCANCODE_ESCAPE])
    {
        done = 1;
    }
	else if(keys[SDL_SCANCODE_W])
	{
		moving = 1;
		moveCharacter(DIR_UP,player);
		yDistance = player->position.y;
	}
	else if(keys[SDL_SCANCODE_A])
	{
		moving = 1;
		moveCharacter(DIR_LEFT,player);
		xDistance = player->position.x;
	}
	else if(keys[SDL_SCANCODE_D])
	{
		moving = 1;
		moveCharacter(DIR_RIGHT,player);
		xDistance = player->position.x;
		
	}
	else if(keys[SDL_SCANCODE_S])
	{
		moving = 1;
		moveCharacter(DIR_DOWN,player);
		yDistance = player->position.y;
	}
	else if(keys[SDL_SCANCODE_1])
	{
		fire_Pistol();
	}
	else if(keys[SDL_SCANCODE_2])
	{
		fire_Shotgun();
	}
	else if(keys[SDL_SCANCODE_3])
	{
		fire_Machinegun();
	}
	else if(keys[SDL_SCANCODE_4])
	{
		fire_Heavy_Machinegun();
	}
	else if(keys[SDL_SCANCODE_P])
//.........这里部分代码省略.........
开发者ID:ljg6,项目名称:MyGame2D,代码行数:101,代码来源:game.c

示例3: SDL_PumpEvents

    void InputWrapper::capture(bool windowEventsOnly)
    {
        mViewer->getEventQueue()->frame(0.f);

        SDL_PumpEvents();

        SDL_Event evt;

        if (windowEventsOnly)
        {
            // During loading, just handle window events, and keep others for later
            while (SDL_PeepEvents(&evt, 1, SDL_GETEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT))
                handleWindowEvent(evt);
            return;
        }

        while(SDL_PollEvent(&evt))
        {
            switch(evt.type)
            {
                case SDL_MOUSEMOTION:
                    // Ignore this if it happened due to a warp
                    if(!_handleWarpMotion(evt.motion))
                    {
                        // If in relative mode, don't trigger events unless window has focus
                        if (!mWantRelative || mWindowHasFocus)
                            mMouseListener->mouseMoved(_packageMouseMotion(evt));

                        // Try to keep the mouse inside the window
                        if (mWindowHasFocus)
                            _wrapMousePointer(evt.motion);
                    }
                    break;
                case SDL_MOUSEWHEEL:
                    mMouseListener->mouseMoved(_packageMouseMotion(evt));
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    mMouseListener->mousePressed(evt.button, evt.button.button);
                    break;
                case SDL_MOUSEBUTTONUP:
                    mMouseListener->mouseReleased(evt.button, evt.button.button);
                    break;
                case SDL_KEYDOWN:
                    mKeyboardListener->keyPressed(evt.key);

                    if (!isModifierHeld(KMOD_ALT) && evt.key.keysym.sym >= SDLK_F1 && evt.key.keysym.sym <= SDLK_F12)
                    {
                        mViewer->getEventQueue()->keyPress(osgGA::GUIEventAdapter::KEY_F1 + (evt.key.keysym.sym - SDLK_F1));
                    }

                    break;
                case SDL_KEYUP:
                    if (!evt.key.repeat)
                    {
                        mKeyboardListener->keyReleased(evt.key);

                        if (!isModifierHeld(KMOD_ALT) && evt.key.keysym.sym >= SDLK_F1 && evt.key.keysym.sym <= SDLK_F12)
                            mViewer->getEventQueue()->keyRelease(osgGA::GUIEventAdapter::KEY_F1 + (evt.key.keysym.sym - SDLK_F1));
                    }

                    break;
                case SDL_TEXTEDITING:
                    break;
                case SDL_TEXTINPUT:
                    mKeyboardListener->textInput(evt.text);
                    break;

#if SDL_VERSION_ATLEAST(2, 0, 4)
                case SDL_KEYMAPCHANGED:
                    break;
#endif
                case SDL_JOYHATMOTION: //As we manage everything with GameController, don't even bother with these.
                case SDL_JOYAXISMOTION:
                case SDL_JOYBUTTONDOWN:
                case SDL_JOYBUTTONUP:
                case SDL_JOYDEVICEADDED:
                case SDL_JOYDEVICEREMOVED:
                    break;
                case SDL_CONTROLLERDEVICEADDED:
                    if(mConListener)
                        mConListener->controllerAdded(1, evt.cdevice); //We only support one joystick, so give everything a generic deviceID
                    break;
                case SDL_CONTROLLERDEVICEREMOVED:
                    if(mConListener)
                        mConListener->controllerRemoved(evt.cdevice);
                    break;
                case SDL_CONTROLLERBUTTONDOWN:
                    if(mConListener)
                        mConListener->buttonPressed(1, evt.cbutton);
                    break;
                case SDL_CONTROLLERBUTTONUP:
                    if(mConListener)
                        mConListener->buttonReleased(1, evt.cbutton);
                    break;
                case SDL_CONTROLLERAXISMOTION:
                    if(mConListener)
                        mConListener->axisMoved(1, evt.caxis);
                    break;
                case SDL_WINDOWEVENT:
                    handleWindowEvent(evt);
//.........这里部分代码省略.........
开发者ID:Allofich,项目名称:openmw,代码行数:101,代码来源:sdlinputwrapper.cpp

示例4: main

int main(int argc,char **argv)
{
	setlocale(LC_ALL,"RUSSIAN");

	SDL_DisplayMode displayMode;

	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
    cout << "SDL_Init Error: " << SDL_GetError() << endl;
    return 1;
	}

	int request = SDL_GetDesktopDisplayMode(0,&displayMode); 

	SDL_Window *win = SDL_CreateWindow("Trubi", 300, 300,800, 800, SDL_WINDOW_SHOWN);
	if (win == nullptr)
	{
		cout << "SDL_CreateWindow Error: " << SDL_GetError() << endl;
	    return 1;
	}

	SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == nullptr)
	{
		cout << "SDL_CreateRenderer Error: " << SDL_GetError() << endl;
	    return 1;
	}

	vector<DPipe> DPIPES(13);
	vector<DoublePipe> DOUBPIPES(6);

	DPipe background(400,400,800,800);
	DPipe a0(70,300,100,40);
	DPipe a1(170,300,100,40);
	DPipe a2(270,300,100,40);
	DPipe a3(370,400,100,40);
	DPipe a4(370,500,100,40);
	DPipe a5(470,600,100,40);
	DPipe a6(570,600,100,40);
	DPipe a7(670,500,100,40);
	DPipe a8(670,400,100,40);
	
	DPipe a9(370,200,100,40);
	DPipe a10(470,100,100,40);
	DPipe a11(570,100,100,40);
	DPipe a12(670,200,100,40);
	DPipe kletka(370,300,100,100);

	DoublePipe b0(370,300,70,40);
	DoublePipe b1(370,600,70,40);
	DoublePipe b2(670,600,70,40);
	DoublePipe b3(670,300,70,40);
	DoublePipe b4(370,100,70,40);
	DoublePipe b5(670,100,70,40);

	DPIPES[0]=a0;
	DPIPES[1]=a1;
	DPIPES[2]=a2;
	DPIPES[3]=a3;
	DPIPES[4]=a4;
	DPIPES[5]=a5;
	DPIPES[6]=a6;
	DPIPES[7]=a7;
	DPIPES[8]=a8;
	DPIPES[9]=a9;
	DPIPES[10]=a10;
	DPIPES[11]=a11;
	DPIPES[12]=a12;
	
	DOUBPIPES[0]=b0;
	DOUBPIPES[1]=b1;
	DOUBPIPES[2]=b2;
	DOUBPIPES[3]=b3;
	DOUBPIPES[4]=b4;
	DOUBPIPES[5]=b5;

	SDL_RenderClear(ren);
	background.default_create(ren,"newbackground.bmp");
	for(int i=0;i<DPIPES.size();++i)
	{
		DPIPES[i].default_create(ren,"text1.bmp");
	}
	for(int i=0;i<DOUBPIPES.size();++i)
	{
		DOUBPIPES[i].default_create1(ren,"double1.bmp","double2.bmp");
	}
	SDL_RenderPresent(ren); 

	bool quit=false;
	while(!quit)
	{
		 while(SDL_PollEvent(&event))
		 {
			SDL_PumpEvents(); 

			if(event.type == SDL_QUIT)
				quit=true;
			else if(event.type==SDL_MOUSEBUTTONDOWN &&  event.button.button==SDL_BUTTON_LEFT)
			{
				for(int i=0;i<DPIPES.size();++i)
//.........这里部分代码省略.........
开发者ID:Blaze5xD,项目名称:pipeproject,代码行数:101,代码来源:Main.cpp

示例5: main

int main(int argc, char *argv[])
{
	GList* list = NULL;
	json_t *root;

	SDL_Surface *optimized_surface = NULL;
	SDL_Surface *temp = NULL;
	Sound *bg_music = NULL;
	Sound *level_music = NULL;
	int done;
	const Uint8 *keys;
	char imagepath[512];

	game_initialize_system();
	SDL_ShowCursor(SDL_DISABLE);

	bg_music = sound_load_music("sounds/vanguard_bouncy.mp3");
	if(!bg_music)
	{
		slog("Could not load music\n");
	}
	
	level_music = sound_load_music("sounds/chippy_cloud_kid.mp3");
	if(!level_music)
	{
		slog("Could not load music\n");
	}
	Mix_VolumeMusic(5);

	if(temp)
	{
		optimized_surface = SDL_ConvertSurface( temp, graphics_surface->format, NULL );
		SDL_FreeSurface(temp);
		
	}

	SDL_Event e;
	done = 0;

	int lock = true;
	do
	{
		if(menu_flag)
		{
			menu_draw();
			if(lock == false)
			{
				Mix_HaltMusic();
				lock = true;
			}

			if(Mix_PlayingMusic() == 0)
			{
				Mix_PlayMusic(bg_music->music, -1);
			}
		}
		else
		{
			tilemap_render_tile();
			entity_draw_all();
			if(lock == true)
			{
				Mix_HaltMusic();
				lock = false;
			}

			if(Mix_PlayingMusic() == 0)
			{
				Mix_PlayMusic(level_music->music, -1);
			}
		}

		mouse_draw_self();

		graphics_next_frame();
		SDL_PumpEvents();

		entity_think_all();

		while(SDL_PollEvent(&e) != 0)
		{
			if(e.type == SDL_QUIT)
			{
				done = 1;
			}
			
			bool leftclick = false ;
			bool rightclick = false;
			if(e.type == SDL_MOUSEBUTTONDOWN)
			{
				if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
				{
					leftclick = true;
				}
				else if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))
				{
					rightclick = true;
				}
			}

//.........这里部分代码省略.........
开发者ID:yi7,项目名称:MouseAlert,代码行数:101,代码来源:game.c

示例6: gst_sdlv_process_events

/* Process pending events. Call with ->lock held */
static void
gst_sdlv_process_events (GstSDLVideoSink * sdlvideosink)
{
  SDL_Event event;
  int numevents;
  char *keysym = NULL;

  do {
    SDL_PumpEvents ();
    numevents = SDL_PeepEvents (&event, 1, SDL_GETEVENT,
        SDL_KEYDOWNMASK | SDL_KEYUPMASK |
        SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
        SDL_MOUSEBUTTONUPMASK | SDL_QUITMASK | SDL_VIDEORESIZEMASK);

    if (numevents > 0 && (event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)) {
      keysym = SDL_GetKeyName (event.key.keysym.sym);
    }

    if (numevents > 0) {
      g_mutex_unlock (sdlvideosink->lock);
      switch (event.type) {
        case SDL_MOUSEMOTION:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-move", 0, event.motion.x, event.motion.y);
          break;
        case SDL_MOUSEBUTTONDOWN:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-button-press",
              event.button.button, event.button.x, event.button.y);
          break;
        case SDL_MOUSEBUTTONUP:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-button-release",
              event.button.button, event.button.x, event.button.y);
          break;
        case SDL_KEYUP:
          GST_DEBUG ("key press event %s !",
              SDL_GetKeyName (event.key.keysym.sym));
          gst_navigation_send_key_event (GST_NAVIGATION (sdlvideosink),
              "key-release", keysym);
          break;
        case SDL_KEYDOWN:
          if (SDLK_ESCAPE != event.key.keysym.sym) {
            GST_DEBUG ("key press event %s !",
                SDL_GetKeyName (event.key.keysym.sym));
            gst_navigation_send_key_event (GST_NAVIGATION (sdlvideosink),
                "key-press", keysym);
            break;
          } else {
            /* fall through */
          }
        case SDL_QUIT:
          sdlvideosink->running = FALSE;
          GST_ELEMENT_ERROR (sdlvideosink, RESOURCE, OPEN_WRITE,
              ("Video output device is gone."),
              ("We were running fullscreen and user "
                  "pressed the ESC key, stopping playback."));
          break;
        case SDL_VIDEORESIZE:
          /* create a SDL window of the size requested by the user */
          g_mutex_lock (sdlvideosink->lock);
          GST_VIDEO_SINK_WIDTH (sdlvideosink) = event.resize.w;
          GST_VIDEO_SINK_HEIGHT (sdlvideosink) = event.resize.h;
          gst_sdlvideosink_create (sdlvideosink);
          g_mutex_unlock (sdlvideosink->lock);
          break;
      }
      g_mutex_lock (sdlvideosink->lock);
    }
  } while (numevents > 0);
}
开发者ID:ylatuya,项目名称:gst-plugins-bad,代码行数:72,代码来源:sdlvideosink.c

示例7: pump

void pump()
{
	SDL_PumpEvents();

	pump_info info;

	//used to keep track of double click events
	static int last_mouse_down = -1;
	static int last_click_x = -1, last_click_y = -1;

	SDL_Event temp_event;
	int poll_count = 0;
	int begin_ignoring = 0;
	std::vector< SDL_Event > events;
	while(SDL_PollEvent(&temp_event)) {
		++poll_count;
		if(!begin_ignoring && temp_event.type == SDL_ACTIVEEVENT) {
			begin_ignoring = poll_count;
		} else if(begin_ignoring > 0 && SDL_EVENTMASK(temp_event.type)&INPUT_MASK) {
			//ignore user input events that occurred after the window was activated
			continue;
		}
		events.push_back(temp_event);
	}
	std::vector<SDL_Event>::iterator ev_it = events.begin();
	for(int i=1; i < begin_ignoring; ++i){
		if(SDL_EVENTMASK(ev_it->type)&INPUT_MASK) {
			//ignore user input events that occurred before the window was activated
			ev_it = events.erase(ev_it);
		} else {
			++ev_it;
		}
	}
	std::vector<SDL_Event>::iterator ev_end = events.end();
	for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
		SDL_Event &event = *ev_it;
		switch(event.type) {

			case SDL_ACTIVEEVENT: {
				SDL_ActiveEvent& ae = reinterpret_cast<SDL_ActiveEvent&>(event);
				if((ae.state & SDL_APPMOUSEFOCUS) != 0 || (ae.state & SDL_APPINPUTFOCUS) != 0) {
					cursor::set_focus(ae.gain != 0);
				}
				break;
			}

			//if the window must be redrawn, update the entire screen
			case SDL_VIDEOEXPOSE: {
				update_whole_screen();
				break;
			}

			case SDL_VIDEORESIZE: {
				const SDL_ResizeEvent* const resize = reinterpret_cast<SDL_ResizeEvent*>(&event);
				info.resize_dimensions.first = resize->w;
				info.resize_dimensions.second = resize->h;
				break;
			}

			case SDL_MOUSEMOTION: {
				//always make sure a cursor is displayed if the
				//mouse moves or if the user clicks
				cursor::set_focus(true);
				raise_help_string_event(event.motion.x,event.motion.y);
				break;
			}

			case SDL_MOUSEBUTTONDOWN: {
				//always make sure a cursor is displayed if the
				//mouse moves or if the user clicks
				cursor::set_focus(true);
				if(event.button.button == SDL_BUTTON_LEFT) {
					static const int DoubleClickTime = 500;
					static const int DoubleClickMaxMove = 3;
					if(last_mouse_down >= 0 && info.ticks() - last_mouse_down < DoubleClickTime &&
					   abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
					   abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
						SDL_UserEvent user_event;
						user_event.type = DOUBLE_CLICK_EVENT;
						user_event.code = 0;
						user_event.data1 = reinterpret_cast<void*>(event.button.x);
						user_event.data2 = reinterpret_cast<void*>(event.button.y);
						::SDL_PushEvent(reinterpret_cast<SDL_Event*>(&user_event));
					}
					last_mouse_down = info.ticks();
					last_click_x = event.button.x;
					last_click_y = event.button.y;
				}
				break;
			}

#if defined(_X11) && !defined(__APPLE__)
			case SDL_SYSWMEVENT: {
				//clipboard support for X11
				handle_system_event(event);
				break;
			}
#endif

			case SDL_QUIT: {
//.........这里部分代码省略.........
开发者ID:asimonov-im,项目名称:wesnoth,代码行数:101,代码来源:events.cpp

示例8: pump

void pump()
{
	if(boost::this_thread::get_id() != main_thread) {
		// Can only call this on the main thread!
		return;
	}
	SDL_PumpEvents();
	peek_for_resize();
	pump_info info;

	//used to keep track of double click events
	static int last_mouse_down = -1;
	static int last_click_x = -1, last_click_y = -1;

	SDL_Event temp_event;
	int poll_count = 0;
	int begin_ignoring = 0;
	std::vector< SDL_Event > events;
	while(SDL_PollEvent(&temp_event)) {
		++poll_count;
		peek_for_resize();

		if(!begin_ignoring && temp_event.type == SDL_WINDOWEVENT
				&& (temp_event.window.event == SDL_WINDOWEVENT_ENTER
						|| temp_event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED))
		{
			begin_ignoring = poll_count;
		} else if(begin_ignoring > 0 && is_input(temp_event)) {
			//ignore user input events that occurred after the window was activated
			continue;
		}
		events.push_back(temp_event);
	}

	std::vector<SDL_Event>::iterator ev_it = events.begin();
	for(int i=1; i < begin_ignoring; ++i){
		if(is_input(*ev_it)) {
			//ignore user input events that occurred before the window was activated
			ev_it = events.erase(ev_it);
		} else {
			++ev_it;
		}
	}

	std::vector<SDL_Event>::iterator ev_end = events.end();
	bool resize_found = false;
	for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
		SDL_Event &event = *ev_it;
		if (event.type == SDL_WINDOWEVENT &&
				event.window.event == SDL_WINDOWEVENT_RESIZED) {
			resize_found = true;
			last_resize_event = event;
			last_resize_event_used = false;

		}
	}
	// remove all inputs, draw events and only keep the last of the resize events
	// This will turn horrible after ~38 days when the Uint32 wraps.
	if (resize_found || SDL_GetTicks() <= last_resize_event.window.timestamp + resize_timeout) {
		events.erase(std::remove_if(events.begin(), events.end(), remove_on_resize), events.end());
	} else if(SDL_GetTicks() > last_resize_event.window.timestamp + resize_timeout && !last_resize_event_used) {
		events.insert(events.begin(), last_resize_event);
		last_resize_event_used = true;
	}

	ev_end = events.end();

	for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
		for (context& c : event_contexts)
		{
			c.add_staging_handlers();
		}

		SDL_Event &event = *ev_it;
		switch(event.type) {

			case SDL_WINDOWEVENT:
				switch(event.window.event) {
					case SDL_WINDOWEVENT_ENTER:
					case SDL_WINDOWEVENT_FOCUS_GAINED:
						cursor::set_focus(1);
						break;

					case SDL_WINDOWEVENT_LEAVE:
					case SDL_WINDOWEVENT_FOCUS_LOST:
						cursor::set_focus(1);
						break;

					case SDL_WINDOWEVENT_RESIZED:
						info.resize_dimensions.first = event.window.data1;
						info.resize_dimensions.second = event.window.data2;
						break;
				}
				//make sure this runs in it's own scope.
				{
					flip_locker flip_lock(CVideo::get_singleton());
					for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++i) {
						const handler_list& event_handlers = (*i).handlers;
						for(auto handler : event_handlers) {
							handler->handle_window_event(event);
//.........这里部分代码省略.........
开发者ID:shikadilord,项目名称:wesnoth,代码行数:101,代码来源:events.cpp

示例9: main

int main(int argc,char** argv)
{
	DPipe tryba1_rect(200,200,100,40);
	DPipe tryba2_rect(400,400,100,40);
	DPipe background_rect(350,350,700,700);
	DPipe kletka_rect(200,200,100,100);
	DPipe kletka2_rect(400,400,100,100);


	setlocale(LC_ALL,"RUSSIAN");
	//------создаем окно с фоном и парой труб--------//
	SDL_DisplayMode displayMode;

	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
    cout << "SDL_Init Error: " << SDL_GetError() << endl;
    return 1;
	}

	int request = SDL_GetDesktopDisplayMode(0,&displayMode);

	//создаем монитор
	SDL_Window *win = SDL_CreateWindow("Trubi", 300, 300,SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	if (win == nullptr)
	{
		cout << "SDL_CreateWindow Error: " << SDL_GetError() << endl;
	    return 1;
	}

	//создаем рендерер
	SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == nullptr)
	{
		cout << "SDL_CreateRenderer Error: " << SDL_GetError() << endl;
	    return 1;
	}

	SDL_Surface *BMP_TRYBA=SDL_LoadBMP("kletka.bmp");
	if (BMP_TRYBA == nullptr)
	{
	    cout << "SDL_LoadBMP Error: " << SDL_GetError() << endl;
		return 1;
	}
	SDL_Texture *TRYBA = SDL_CreateTextureFromSurface(ren, BMP_TRYBA);

	SDL_RenderClear(ren);
	background_rect.default_create(ren,"project.bmp");
	kletka_rect.default_create(ren,"kletka.bmp");
	kletka2_rect.default_create(ren,"kletka.bmp");
	tryba1_rect.default_create(ren,"text1.bmp");
	tryba2_rect.default_create(ren,"text1.bmp");
	SDL_RenderPresent(ren); 

	SDL_Event event;
	bool quit=false;
	int trybi=2;
	while(!quit)
	{
		 while(SDL_PollEvent(&event))
		 {
			SDL_PumpEvents(); // обработчик событий.
			
			//крестик
			if(event.type == SDL_QUIT)
				quit=true;
			else if(event.type==SDL_MOUSEBUTTONDOWN &&  event.button.button==SDL_BUTTON_LEFT)
			{
				if((event.button.x>=kletka_rect.center().x-kletka_rect.width()/2 && event.button.x<=kletka_rect.center().x+kletka_rect.width()/2) && 
					(event.button.y>=kletka_rect.center().y-kletka_rect.height()/2 && event.button.y<=kletka_rect.center().y+kletka_rect.height()/2))
				{
						SDL_RenderClear(ren);
						background_rect.default_create(ren,"project.bmp");
						kletka_rect.default_create(ren,"kletka.bmp");
						kletka2_rect.default_create(ren,"kletka.bmp");
						tryba2_rect.upgrade(ren); 
						tryba1_rect.spin(ren);
						SDL_RenderPresent(ren); 
				}
				else if((event.button.x>=kletka2_rect.center().x-kletka2_rect.width()/2 && event.button.x<=kletka2_rect.center().x+kletka2_rect.width()/2) && 
					(event.button.y>=kletka2_rect.center().y-kletka2_rect.height()/2 && event.button.y<=kletka2_rect.center().y+kletka2_rect.height()/2))
				{
						SDL_RenderClear(ren);
						background_rect.default_create(ren,"project.bmp");
						kletka_rect.default_create(ren,"kletka.bmp");
						kletka2_rect.default_create(ren,"kletka.bmp");
						tryba1_rect.upgrade(ren);
						tryba2_rect.spin(ren);
						SDL_RenderPresent(ren); 
				}
						
			}
		 }
	}
	return 1;
}
开发者ID:Blaze5xD,项目名称:pipeproject,代码行数:95,代码来源:DPipe.cpp

示例10: run

void run(struct Computer *computer) {
	struct CPU *cpu = &computer->cpu;
	struct RAM *ram = &computer->ram;
	struct GPU *gpu = &computer->gpu;
	struct DMA *dma = &computer->dma;
	
	struct Screen *screen = computer->screen;
	
	// TODO boot computer
	initTime();
	
	// init CPU
	cpu->IP = CODE_ADDR;
	cpu->SP = ram->size - 1;
	
	CPU_run(cpu);
	
	// how many emulated cycles can we do until the next refresh
	uint32 cpuCycles = cpu->clockRate / gpu->refreshRate;
	uint32 tickCounter = 0;
		
	double refreshTimeMs = 1000.0 / (double) gpu->refreshRate;
	double sleepTimeMs = 0.0;
	
	double tickStartMs = 0.0;
	double tickEndMs = 0.0;
	double tickDiffMs = 0.0;
	
	printf("CPU clock rate: %ld Hz\n", cpu->clockRate);
	printf("Video refresh rate: %ld Hz\n", gpu->refreshRate);
	printf("CPU cycles per frame: %ld\n", cpuCycles);
	printf("Refresh time: %f ms\n", refreshTimeMs);
	
	while (CPU_isRunning(cpu)) {
		tickCounter = cpuCycles;
	
		tickStartMs = getMilliTime();
	
		while (CPU_isRunning(cpu) && tickCounter > 0) {
			CPU_tick(cpu);
			DMA_tick(dma);
			
			tickCounter--;
		}

		// update the screen
		if (screen != NULL) {
			draw(gpu, screen);
			CPU_interrupt(cpu, VBLANK_INTERRUPT);
		}
		
		// we need to pump events or the window freezes
		SDL_PumpEvents();
		
		SDL_RenderClear(screen->renderer);
		SDL_RenderCopy(screen->renderer, screen->texture, NULL, NULL);
		SDL_RenderPresent(screen->renderer);

		tickEndMs = getMilliTime();
		tickDiffMs = tickEndMs - tickStartMs;
		
		sleepTimeMs = refreshTimeMs - tickDiffMs;

		// printf("> %f %f\n", tickDiffMs, sleepTimeMs);
		
		if (sleepTimeMs >= 1.0) {
			SDL_Delay((Uint32) sleepTimeMs);
		}
	}
}
开发者ID:GOMF,项目名称:virtbit,代码行数:70,代码来源:computer.c

示例11: main

/*notice the default arguments for main.  SDL expects main to look like that, so don't change it*/
int main(int argc, char *argv[])
{
  SDL_Surface *temp = NULL;
  int done;
  int tx = 0,ty = 0;
  int i;
  const Uint8 *keys;
  char imagepath[512];
  SDL_Rect srcRect={0,0,SCREEN_WIDTH,SCREEN_HEIGHT};
  SDL_Event e;
  last_time = current_time = SDL_GetTicks();
  
  Init_All();
  slog("Finished Init All()");
  done = 0;
  do
  {
	   //render or draw functions go here
	//draw functions should go in order from background first to player draw calls last
    ResetBuffer();
    SDL_RenderClear(__gt_graphics_renderer);//clear screen
	tile_render();	
	player_draw();
	DrawMouse2();
	
	/*monster_spawn(Monster::grue);
	monster_spawn(Monster::spider01);
	monster_spawn(Monster::mino);		
	monster_spawn(Monster::orc);	
	support_spawn(Support::sara);	
	support_spawn(Support::healer);	
	support_spawn(Support::archer);
	
	*/
	entity_update_all();
	entity_think_all();
	entity_check_collision_all();
	particle_em_draw_all();
//	struct_update_all();
	

	G_MONSTER_SPAWN_TIMER -= 1;

	while(SDL_PollEvent(&e) != 0)
		player_move (&e);
    NextFrame();
	//end
    SDL_PumpEvents();
    keys = SDL_GetKeyboardState(NULL);
	//taken from lazyfoo
	//handles generally keyboard inputs	
	
	while( SDL_PollEvent( &e) != 0){
		if(e.type == SDL_QUIT)
			done = 1;
    	else
			player_move(&e);	
	}

		if(keys[SDL_SCANCODE_ESCAPE])
		{
			done = 1;
		}
		
	SDL_RenderPresent(__gt_graphics_renderer);
	last_time = current_time;
	current_time = SDL_GetTicks();
	delta = current_time - last_time;
  }while(!done);
  exit(0);		/*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/
  return 0;
}
开发者ID:GarryGuanDoubleG,项目名称:Conquest-Rule-or-Die,代码行数:73,代码来源:game.c

示例12: main

int main( int argc, char **argv )
{
#ifdef __APPLE__
    string macDir = get_mac_dir();
    string configFile = macDir + "/../configuration.ini";
#else
    string configFile = "configuration.ini";
#endif
    load_configuration(configFile);

    SDL_Surface *surface;
    SDL_Event event;

    int videoFlags;
    videoFlags  = SDL_OPENGL;          // Enable OpenGL in SDL
    videoFlags |= SDL_GL_DOUBLEBUFFER; // Enable double buffering
    //videoFlags |= SDL_HWPALETTE;       // Store the palette in hardware

    if ( displayFullscreen )
        videoFlags |= SDL_FULLSCREEN;

    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        fprintf( stderr, "Video initialization failed: %s\n",
                 SDL_GetError( ) );
        //Quit( 1 );
    }

    if (hardwareCursor)
        SDL_ShowCursor(SDL_DISABLE);

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    surface = SDL_SetVideoMode( displayWidth, displayHeight, displayBpp, videoFlags );

    SDL_WM_SetCaption("Torque Tracer","icon");

    bindKeys();

    OpenGL_init();
#ifdef __APPLE__
    string fontPath = macDir + "/Contents/Resources/Vera.ttf";
    const char *fontFile = strdup(fontPath.c_str());
#else
    const char *fontFile = "Vera.ttf";
#endif
    load_font(fontFile, &font[0], 18);

    //////////////////////////////////////
    // torque curve initial points - for debugging
    /*torqueCurve.push_back( vector2fSet(-0.7, -0.7) );
     torqueCurve.push_back( vector2fSet(-0.7 + incrementX * 1, -0.7 + incrementY*2) );
     torqueCurve.push_back( vector2fSet(-0.7 + incrementX * 2, -0.7 + incrementY*3) );*/

    bool exitApplication = false;

    while ( true )
    {
        if (exitApplication == true) break;

        SDL_PollEvent( &event );

        SDL_PumpEvents();
        sdl_mouseUpdate();

        if (event.type == SDL_QUIT)
            exitApplication = true;

        ////////////////////////////////////////////
        // check keyboard keys
        unsigned char *keyState = (unsigned char *) SDL_GetKeyState(NULL);
        for ( unsigned int klv=0 ; klv<BUTTONS_KEYBOARD ; klv++)
        {
            if ( keyState[klv] && keyboardButtons[klv].pressedLf == false )
            {
                keyboardButtons[klv].pressedLf = true;

                if (keyboardButtons[klv].action == ACTION_QUIT) exitApplication = true;

                if (keyboardButtons[klv].action == ACTION_TOGGLE_MODE)
                {
                    if (inputMode == INPUT_MODE_RESIZE)
                        inputMode = INPUT_MODE_DRAW;
                    else if (inputMode == INPUT_MODE_DRAW)
                        inputMode = INPUT_MODE_ENTER_TEXT;
                    else if (inputMode == INPUT_MODE_ENTER_TEXT)
                        inputMode = INPUT_MODE_RESIZE;
                    //printf("toggle mode\n");
                }

                if (keyboardButtons[klv].action == ACTION_TORQUE_ZOOM_IN)
                {
                    if (incrementY < 6)
                        incrementY *= 1.25;
                }
                if (keyboardButtons[klv].action == ACTION_TORQUE_ZOOM_OUT)
                {
                    if (incrementY > 0.05)
                        incrementY /= 1.25;
                }
                if (keyboardButtons[klv].action == ACTION_WRITE_FILE)
//.........这里部分代码省略.........
开发者ID:VDrift,项目名称:torque-tracer,代码行数:101,代码来源:main.cpp

示例13: SDL_PumpEvents

bool InputHandler::MousePressed(MouseButton button)
{
	SDL_PumpEvents();
	return(SDL_GetMouseState(&m_MouseX, &m_MouseY) & SDL_BUTTON(button));
}
开发者ID:Zieroc,项目名称:SDL_TextBasedGame,代码行数:5,代码来源:InputHandler.cpp

示例14: main_menu

int main_menu()
{
  static int i = 0;
  static int upHeld = 0;
  static int downHeld = 0;
  SDL_Renderer *render;
  render = gt_graphics_get_active_renderer();
  SDL_RenderClear(gt_graphics_get_active_renderer());
  ResetBuffer();
  mainScreen = loadSprite("images/opening_screen.png",800,600,1);
  selection = loadSprite("images/selection.png",149,53,1);
  printf("%i", i);
  if(i == 0)
	{
		drawSprite(mainScreen,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
		drawSprite(selection,0,vec2d(311,292),vec2d(1,1),0,gt_graphics_get_active_renderer());
  }else if(i == 1)
  {
	  drawSprite(mainScreen,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	  drawSprite(selection,0,vec2d(275,376),vec2d(1.5,1),0,gt_graphics_get_active_renderer());
	  
  }else if(i == 2)
  {
	  drawSprite(mainScreen,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	  drawSprite(selection,0,vec2d(311,460),vec2d(1,1),0,gt_graphics_get_active_renderer());
	  
  }
  NextFrame();
  SDL_PumpEvents();
  keys = SDL_GetKeyboardState(NULL);
  if(keys[SDL_SCANCODE_ESCAPE])
    {
        done = 1;
    }
  if(keys[SDL_SCANCODE_DOWN]&&downHeld == 0)
    {
	  i=(i+1)%3;
	  downHeld = 1;
	}else if(!keys[SDL_SCANCODE_DOWN])
  {
		downHeld = 0;
  }
  if(keys[SDL_SCANCODE_UP]&&upHeld == 0)
  {
	  if((i = i-1)<0)
		  i = 2;

	  upHeld = 1;
	}else if(!keys[SDL_SCANCODE_UP])
  {
		upHeld = 0;
  }
  if(keys[SDL_SCANCODE_RETURN])
  {
	  if(i == 0)
	  {
		  gameState = 1;
		  init_lvl1();
	  }
	  else if(i == 2)
	  {
		  done = 1;
	  }
	  else if(i == 1)
	  {
		  init_player();

		  loadState();
		  if(gameState == 1)
		  {
			  init_lvl1();
		  }else if(gameState == 2)
		  {
			  init_lvl2();
		  }
	  }
  }	  
   return 1;
}
开发者ID:ljg6,项目名称:MyGame2D,代码行数:79,代码来源:game.c

示例15: while

void inputLib::readInput()
{
    _used_keyboard = false;
    while (SDL_PollEvent(&event)) {

        if (_show_btn_debug == false) {
            _show_btn_debug = true;
        }

        if (game_config.input_type == INPUT_TYPE_DOUBLE || game_config.input_type == INPUT_TYPE_KEYBOARD) {
            if (event.type == SDL_KEYDOWN) {
                for (int i=0; i<BTN_COUNT; i++) {
                    if (game_config.keys_codes[i] != -1 && game_config.keys_codes[i] == event.key.keysym.sym) {
                        p1_input[i] = 1;
                        _used_keyboard = true;
                        if (i == BTN_JUMP) {
                            p1_input[BTN_JUMP_TIMER] = timer.getTimer();
                        }
                    }
                }
            } else if (event.type == SDL_KEYUP) {
                for (int i=0; i<BTN_COUNT; i++) {
                    if (game_config.keys_codes[i] != -1 && game_config.keys_codes[i] == event.key.keysym.sym) {
                        p1_input[i] = 0;
                        _used_keyboard = true;
                        if (i == BTN_JUMP) {
                            p1_input[BTN_JUMP_TIMER] = 0;
                        }
                    }
                }
            }
            SDL_PumpEvents(); // check keyboard events
#if !defined(PLAYSTATION2) && !defined(PSP) && !defined(WII) && !defined(DREAMCAST)
            if (event.type == SDL_QUIT) {
                std::cout << "LEAVE #1" << std::endl;
                std::fflush(stdout);
                gameControl.leave_game();
            }
#endif
        }
        if (_used_keyboard == true) { // next commands are all joystick only
            return;
        }
        if (game_config.input_type == INPUT_TYPE_DOUBLE || game_config.input_type == INPUT_TYPE_JOYSTICK) {
            if (event.type == SDL_JOYBUTTONDOWN) {
                //std::cout << "#1 INPUT::readInput - joystick button[" << (int)event.jbutton.button << "] pressed." << std::endl;
                for (int i=0; i<BTN_COUNT; i++) {
                    //std::cout << "#1 INPUT::readInput - button_codes[" << i << "]: " << game_config.button_codes[i] << std::endl;
                    if (game_config.button_codes[i] != -1 && game_config.button_codes[i] == event.jbutton.button) {
                        //std::cout << "#1 INPUT::readInput - FOUND ACTION for i: " << i << std::endl;
                        p1_input[i] = 1;
                        if (i == BTN_JUMP) {
                            p1_input[BTN_JUMP_TIMER] = timer.getTimer();
                        }
                        //break;
                    }
                }
            } else if (event.type == SDL_JOYBUTTONUP) {
                //std::cout << "#2 INPUT::readInput - joystick button[" << event.jbutton.button << "] released" << std::endl;
                for (int i=0; i<BTN_COUNT; i++) {
                    if (game_config.button_codes[i] != -1 && game_config.button_codes[i] == event.jbutton.button) {
                        p1_input[i] = 0;
                        if (i == BTN_JUMP) {
                            p1_input[BTN_JUMP_TIMER] = 0;
                        }
                        break;
                    }
                }
            }
        }
        if ((game_config.input_mode == INPUT_MODE_ANALOG || game_config.input_mode == INPUT_MODE_DOUBLE) && event.type == SDL_JOYAXISMOTION) {
            if (event.jaxis.axis == 0) {
                if (event.jaxis.value < -JOYVAL) {
                    p1_input[BTN_RIGHT] = 0;
                    p1_input[BTN_LEFT] = 1;
                    _used_keyboard = false;
                } else if (event.jaxis.value > JOYVAL) {
                    p1_input[BTN_RIGHT] = 1;
                    p1_input[BTN_LEFT] = 0;
                    _used_keyboard = false;
                } else if ((event.jaxis.value < JOYVAL || event.jaxis.value > -JOYVAL) && _used_keyboard == false) {
                    p1_input[BTN_RIGHT] = 0;
                    p1_input[BTN_LEFT] = 0;
                }
            }
            if (event.jaxis.axis == 1) {
                if (event.jaxis.value < -JOYVAL) {
                    p1_input[BTN_DOWN] = 0;
                    p1_input[BTN_UP] = 1;
                    _used_keyboard = false;
                } else if (event.jaxis.value > JOYVAL) {
                    p1_input[BTN_DOWN] = 1;
                    p1_input[BTN_UP] = 0;
                    _used_keyboard = false;
                } else if ((event.jaxis.value < JOYVAL || event.jaxis.value > -JOYVAL) && _used_keyboard == false) {
                    p1_input[BTN_DOWN] = 0;
                    p1_input[BTN_UP] = 0;
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:DavidKnight247,项目名称:Rockbot-GCW0-port,代码行数:101,代码来源:inputlib.cpp


注:本文中的SDL_PumpEvents函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。