Jump to content

  • Log In with Google      Sign In   
  • Create Account


Martix91

Member Since 05 Jan 2013
Offline Last Active Jun 06 2013 03:20 PM

Posts I've Made

In Topic: Realtime games. General question

10 January 2013 - 02:47 PM

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?


In Topic: Realtime games. General question

07 January 2013 - 04:27 PM

@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 rolleyes.gif  

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. 


In Topic: Realtime games. General question

06 January 2013 - 04:59 AM

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.


In Topic: Realtime games. General question

05 January 2013 - 05:34 PM

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


PARTNERS