Jump to content
  • Advertisement

Martin Barbov

  • Content Count

  • Joined

  • Last visited

Community Reputation

137 Neutral

About Martin Barbov

  • Rank
  1. Martin Barbov

    Realtime games. General question

    Yeah, typing mistake :p Thanks a lot guys, I made the coordinates into floats and the movement is much smoother now,   Final question, is it normal that the SDL fullscreen is not stretching onto the entire screen but only to its dimensions even if I set them to some known resolution like 1024 x 768 and so on. It works fine only if the resolution matches the monitor resolution but if smaller, it will be centered and surounded by black border. Is there a fix that doesn't require manual stretching of the screen?
  2. Martin Barbov

    Realtime games. General question

    @Khatharr  Thank you very much for the input. It seems I'll have to rewrite the motion mechanic and do some time system I currently lack.   @rip-off I wasn't aware    Thought it was angles. It's ok now   As for the freezing it was just like game lag.The game screen freezes, slowing down the whole system, but not crashing windows or something. The loop polls for events. I just commented that part for testing purposes. I did some testing and now it's much better. After I put a SDL_delay(8) in the loop. 
  3. Martin Barbov

    Realtime games. General question

    Here's the relevant code:       This updates the screen.  void UpdateScreen() { SDL_Surface* frame = SDL_GetVideoSurface(); int i = SDL_Flip(frame); }   This blits a surface to another surface void Asset::apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Temporary rectangle to hold the offsets SDL_Rect offset; //Get the offsets offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); }   This just calls the previous function but uses fewer parameters and is callable from outside the class. image is a SDL_surface* loaded with an image. void Asset::apply(int x, int y, SDL_Surface* dscreen) { //Apply the background to the screen apply_surface( x, y, image, dscreen ); }     This uses the previous function to draw the object. assetx and assety are there if I want to displace the image from the actual game object. They are 0 by default. void Object::Render() { SDL_Surface* screen = SDL_GetVideoSurface(); if(render&&exist) asset->apply(x+assetx,y+assety,screen); }   This calculates the coordinates for a move each frame. The angles are way off right now. Probably some int rounding again. Help on this would be appreciated. int VelocityVector::xMove() { double displacement = ((0.0+timy.get_ticks())/(0.0+1000))*speed*cos(double(angle)); return (int)displacement; } int VelocityVector::yMove() { double displacement = ((0.0+timy.get_ticks())/(0.0+1000))*speed*sin(double(angle)); timy.start(); return (int)displacement; }     This uses the previous functions to move the object by changing its coordinates. void Object::move() { setX(getX()+velo->xMove()); setY(getY()+velo->yMove()); }   This is the main function. I've commented the event handling loop and left only this one. There are a lot of preloadings before it but they are not looped and I doubt are causing the freezes. while( quit == false ) { CLS();//this fills the screen with black bg.move(); bg.Render(); UpdateScreen(); }   The image is set to move with a speed 1/10 of the whole screen per second but it lags horibly and moves 10 times slower, sometimes freezing for up to 5-10 seconds.
  4. Martin Barbov

    Realtime games. General question

    Thank you. I just figured out the problem. My logic looked like:   while(quit==false) {  move();  while( SDL_PollEvent( &event ) ) {do a lot of stuff including draw();}//no sleeps here }   So I'm just stupid. Forgot that the drawing is inside the second loop There are still a lot of problems though. I simplified it to while(quit == false) { move(); draw(); } Now it moves constantly, but way too slow and lags horribly. Can that be because I have no sleeps in the code The program takes up to 50% of the processor and less than 20 mb ram
  5. I started writing my own simple 2D engine in c++ and SDL and everything worked out great until i tried to implement Frame Independent Movement. I wrote a simple motion function that moves the object with given speed per second((current time - previous move time)/1000 * The Speed). Then I call it it the main loop inside a while. The function itself is buggy but that's not my problem.   The problem is that when i start the program the object do moves and it also moves with close to the desired speed. But only if i feed it inputs. If i stop moving the mouse everything pauses and when I move the mouse again the object continues to move, but without the paused time(meaning it doesn't jump to make up for the lost time).   And that led me to the assumption that I understand nothing about how the program really works. When I create a while(true) and put things in it, how often do these things get called. I always thought they are called as fast as the processor manages to, but it seems I'm wrong.    Is there something more or I just have a nasty bug somewhere and I have to post the code for debugging?
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!