Jump to content
  • Advertisement
Sign in to follow this  

SDL window

This topic is 4317 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

I'm using SDL to create my window but openGL for graphics. I'm coming to a point now where the user might want to grab the window and move it, BUT when that happens, the loop pauses until the user lets go, but the time keeps going, so all my physics think that object has still been moving and veer off in that direction. is there a way to have the code still go even while the user clicks and draws the window title bar?

Share this post


Link to post
Share on other sites
Advertisement
good question. i don't have an answer, but a temporary (possibly not good enough) solution would be to use SDL_ActiveEvent to pause the application.

SDL_Event e;
while( SDL_PollEvent(&e) ) {
switch(e.type) {
...
case SDL_ACTIVEEVENT:
if( e.active.gain == 1 ) {
// focus gained (unpause)
} else {
// focus lost (pause)
}
...


Share this post


Link to post
Share on other sites
i would do that, but i'm planning on incorperating networking into my engine and if a user does that and i have have time stop, then i'd have to stop time for everyone, which wouldn't be practical...

Share this post


Link to post
Share on other sites
The easyest solution would to make the app fullscreen all the time. Bascially all games use fullscreen.

Share this post


Link to post
Share on other sites
well i'm not making all games. i'm apart of a team and not only am i the lead 2d game engine program but i also make all the tools the graphics and such use: drawing program, particle system editor, collision tests, etc. Those I keep in windowed mode.

Share this post


Link to post
Share on other sites
i need a solution for this in the near future as well. i've been working on the problem for the last half hour (in windows xp) and still have nothing. [sad]

Share this post


Link to post
Share on other sites
You could try handling your window events in a different thread? I have never used threads before myself but my understanding of them is that they may be what you need to look into to fix this problem.

possible problems:
I know SDL has/had issues with rendering in a different thread other than the one the window was created in but I am unsure if this is still the case or if this is even an issue with OpenGL as the rendering API or if this is even relevent information :)

I do think that threads may be the answer you are looking for though.

Share this post


Link to post
Share on other sites
Actually, i just thought of something although not sure how "elegant" it is.

Assuming the major problem comes with the pysics aspect of things perhaps defining a maximum time-step the physics engine can handle at once (~33ms or tweak it) and running it in a for loop of the max time-step until the amount of time you were paused has expired.

say you were moving the screen for about 2 seconds...

max_time_step = 33;
time_elapsed = 2000;

for ( delta = time_elapsed; delta > 0; delta -= max_time_step )
{
... do physics based on delta
}




That should keep the physics even no matter what the fps is as well although it may cost a few frames to catch up initially and on really slow systems it will look really choppy but you should still get pretty even results.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!