Jump to content
  • Advertisement
Sign in to follow this  
XAngelbr

WaitMessage() for Linux

This topic is 3829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! That is my first time in Forum. :) Ok... I try to port the Game Engine Tutorial from GDWiki, but I found a problem. Somebody know a funcion to replace WaitMessage()? I'm trying to use XPending() without success.

Share this post


Link to post
Share on other sites
Advertisement
Because you are using SDL, you could probably replace WaitMessage() with SDL_WaitEvent(). However, you need to handle the event then. Something like this:

void CEngine::Start()
{
m_lLastTick = SDL_GetTicks();
m_bQuit = false;

// Main loop: loop forever.
while ( !m_bQuit )
{
// Handle mouse and keyboard input
HandleInput();

if ( m_bMinimized ) {
SDL_Event event;
SDL_WaitEvent(&event);
HandleEvent(event);
} else {
// Do some thinking
DoThink();

// Render stuff
DoRender();
}
}

End();
}


void Engine::HandleInput()
{
// Poll for events, and handle the ones we care about.
SDL_Event event;
while ( SDL_PollEvent( &event ) )
{
HandleEvent(event);
}
}

void Engine::HandleEvent(const SDL_Event &event)
{
switch ( event.type )
{
case SDL_KEYDOWN:
// If escape is pressed set the Quit-flag
if (event.key.keysym.sym == SDLK_ESCAPE)
{
m_bQuit = true;
break;
}

KeyDown( event.key.keysym.sym );
break;

case SDL_KEYUP:
KeyUp( event.key.keysym.sym );
break;

case SDL_QUIT:
m_bQuit = true;
break;

case SDL_MOUSEMOTION:
MouseMoved(
event.button.button,
event.motion.x,
event.motion.y,
event.motion.xrel,
event.motion.yrel);
break;

case SDL_MOUSEBUTTONUP:
MouseButtonUp(
event.button.button,
event.motion.x,
event.motion.y,
event.motion.xrel,
event.motion.yrel);
break;

case SDL_MOUSEBUTTONDOWN:
MouseButtonDown(
event.button.button,
event.motion.x,
event.motion.y,
event.motion.xrel,
event.motion.yrel);
break;

case SDL_ACTIVEEVENT:
if ( event.active.state & SDL_APPACTIVE ) {
if ( event.active.gain ) {
m_bMinimized = false;
WindowActive();
} else {
m_bMinimized = true;
WindowInactive();
}
}
break;
} // switch
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!