Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Daepilin

Pages: [1]
1
Window / Re: SetFramerateLimit makes the Game stutter
« on: July 29, 2013, 05:42:11 pm »
I thought so.

And honestly: my CPU is not that modern anymore (phenom II x4 955), this runs in one thread and even in a frame where rendering is done it's not even close to drop a frame ( without every limit i easily get 1500fps+, handle events and updates both not even take 100microS most of the time)

A guy in a different forum testet it on a 1.2Ghz dual core notebook and it gave him stable fps^^ so at least now it's no issue.

But yeah, my update methods themselves are given the Frametime and will base all time relevant calculations on it, so there should be no problem when some frames drop on very very low end machines.

And i think i will include an option to set the FPS target, for those 120Hz monitor guys^^ (+ maybe a benchmark for really low end computers)

But thanks to you both :)

2
Window / Re: SetFramerateLimit makes the Game stutter
« on: July 29, 2013, 04:24:50 pm »
Okay, i actually got my own frame limiter running with individual timesteps for update and render methods.

But: I guess there is now way to increase sf:sleep accuracy? Atm i loose about 3-6 fps on my machine, though i guess that number will differ.

or is my Code just broken:

Code: [Select]
while(mMainWindow->isOpen()){

HandleEvents();
Update();

if(mCurrentRenderTime >= mRenderT){
Render();
mCurrentRenderTime = 0.0;
}

mCurrentFrameTime = mMainClock->restart().asMicroseconds();
mCurrentRenderTime += mCurrentFrameTime;

mSleepTime = sf::microseconds(mUpdateT - mCurrentFrameTime);
sf::sleep(mSleepTime);
}

mUpdateT is 1667 and mRenderT is 16667.  I sure know that sf::sleep is not that accurate, but maybe i have some additional errors in there^^

3
Window / Re: SetFramerateLimit makes the Game stutter
« on: July 28, 2013, 09:05:33 pm »
Well i don't have much movement code to show, as i just have implemented very basic stuff but:

Code: [Select]
void Player::validateMovement(){
//ckeck left corners
mCurrentTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left, getCollisionBox().top));
mFirstNewTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left + getMovementVector().x , getCollisionBox().top/* + getMovementVector().y*/)); //top left
mSecondNewTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left + getMovementVector().x , getCollisionBox().top + getCollisionBox().height/* + getMovementVector().y*/)); //bottom left

//collision
if(mCurrentRoomTiles[mFirstNewTilePosition.x][mFirstNewTilePosition.y].getCollideID() == 1 || mCurrentRoomTiles[mSecondNewTilePosition.x][mSecondNewTilePosition.y].getCollideID() == 1){
setMovementVector(sf::Vector2f(0.0, getMovementVector().y));
}

//doors
else if(mCurrentRoomTiles[mFirstNewTilePosition.x][mFirstNewTilePosition.y].getTileID() == 2 || mCurrentRoomTiles[mSecondNewTilePosition.x][mSecondNewTilePosition.y].getTileID() == 2){
if( (mFirstNewTilePosition.x == 0 && mFirstNewTilePosition.y == 4 ) || (mSecondNewTilePosition.x == 0 && mSecondNewTilePosition.y == 4)) mTeleportTo = "Left";
else if( (mFirstNewTilePosition.x == 7 && mFirstNewTilePosition.y == 0 )) mTeleportTo = "Up";
else if( mSecondNewTilePosition.x == 7 && mSecondNewTilePosition.y == 8) mTeleportTo = "Down";
}


//ckeck top corners
mCurrentTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left, getCollisionBox().top));
mFirstNewTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left /*+ getMovementVector().x*/ , getCollisionBox().top + getMovementVector().y)); //left top
mSecondNewTilePosition = convertToTilePosition(sf::Vector2i(getCollisionBox().left /*+ getMovementVector().x*/ + getCollisionBox().width , getCollisionBox().top + getMovementVector().y)); //right top

//collision
if(mCurrentRoomTiles[mFirstNewTilePosition.x][mFirstNewTilePosition.y].getCollideID() == 1 || mCurrentRoomTiles[mSecondNewTilePosition.x][mSecondNewTilePosition.y].getCollideID() == 1){
setMovementVector(sf::Vector2f(getMovementVector().x, 0.0));
}

//doors
else if(mCurrentRoomTiles[mFirstNewTilePosition.x][mFirstNewTilePosition.y].getTileID() == 2 || mCurrentRoomTiles[mSecondNewTilePosition.x][mSecondNewTilePosition.y].getTileID() == 2){
if( (mFirstNewTilePosition.x == 7 && mFirstNewTilePosition.y == 0 ) || (mSecondNewTilePosition.x == 7 && mSecondNewTilePosition.y == 0)) mTeleportTo = "Up";
else if( (mFirstNewTilePosition.x == 0 && mFirstNewTilePosition.y == 4 )) mTeleportTo = "Left";
else if( (mSecondNewTilePosition.x == 14 && mSecondNewTilePosition.y == 4)) mTeleportTo = "Right";
}


.
        .
        .
}

void MovableObject::moveObject(){
if(mMovementVector.x != 0 || mMovementVector.y != 0){

this->move(mMovementVector.x, mMovementVector.y);

setCollisionBox(sf::FloatRect(mCollisionBox.left + mMovementVector.x, mCollisionBox.top + mMovementVector.y, mCollisionBox.width, mCollisionBox.height));

setCollisionBoxShapePosition(sf::Vector2f(mCollisionBox.left, mCollisionBox.top));
}

}

The first Method is basically a part of my (current) collisiondetection for collisions with the room. It basically sets the movementvector.x and/or .y to 0 if the movement would cause a collision. (not the optimal way, in future i want to adjust it depending on the distance to the collisionobject to move right up to it)

The second method moves the playersprite, collisionbox and my visualization (ofc just for development).

the movementvector is set via 8 else if comparisons:

Code: [Select]
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
setMovementVector(sf::Vector2f(-getMovementSpeed(), 0.0f));
setNextAnimation(3);
}
(getMovementspeed()  just returns a double value)

the code is not yet made to work without the inbuild frame limiter and will let the player cross the whole room in 1sec without it, but that is a fixable problem.

but i get those framedrops in the menu as well (without much to draw) even though i don't know if it stutters there.
(the stutter, to describe it better) is a really short break in a continous movement(with pressed key)

i actually had someone else test it (quite a powerfull i5 as cpu and 8gigs of ram, quite a bit stronger than my machine). He "felt" no stuttering but had the same framedrops. But i guess he just did not notice as my cpu is below 10% with the built in limiter, which makes me think cpu performance is not an issue.


4
Window / SetFramerateLimit makes the Game stutter
« on: July 28, 2013, 08:12:30 pm »
Hi :)

I've got a little problem with my game. If i use the built in SetFramerateLimit method to limit my Windows Framerate to 60 it varies a bit (not the problem) but has some issues:

1) stuttering. Quite regular the game stutters which results in double or tripple the "normal" rendertime for the window.
2) Framerate is actually below 60. On my system it's on 58, a friend tested it on quite a weak laptop and only got 53Fps(which stayed the same when he underclocked the thing, so i guess it's no lack of performance)

(Fps measured with Fraps, rendertimes with sf::clock. Don't get any Framedrops, when i leave the Limiter out but 1500+FPs is not what i want^^)

i wrote my own functionality, very crude, but working(no drops and bang on 60Fps on my machine), but: i don't really know how to prevent it from using the core it runs on at 100%:

Code: [Select]
void Framework::Render(){

if(mCurrentRenderFrameTime >= 0.01667){
mMainWindow->clear();
mMainStateManager->Render();
mMainWindow->display();

mCurrentRenderFrameTime = 0.0;
}
mCurrentRenderFrameTime += mFrameT / 1000000.0;
}

Code: [Select]
void Framework::RunGame(){
mCurrentRenderFrameTime = 1.0;
while (mMainWindow->isOpen()){

this->HandleEvents();
this->Update();
this->Render();
}
}


Any Tips how i could solve the problem?

5
Window / Re: Get Window Style?
« on: June 23, 2013, 05:06:51 pm »
been there, done that, but i thought i have overseen something^^

guess i have to it this way...

6
Window / Get Window Style?
« on: June 23, 2013, 04:22:00 pm »
Hi :)

I was wondering if there is a way to get the current window style?

background is, that i would only want to recreate the window when the style changes (fullscreen to windowed and vice versa) and not always uppon applying my settings.

(atm i just recreate it either with one or the other style, but every time).

Code: [Select]
if(mSettings->GetFullscreen()){
mMainStateWindow->create(sf::VideoMode(sf::VideoMode::getDesktopMode()), "Test", sf::Style::Fullscreen);
}
else{
mMainStateWindow->create(sf::VideoMode(mSettings->GetXRes(), mSettings->GetYRes(), 32), "Testn", sf::Style::Close);
}

sure, i could have a history of my fullscreen setting but  i don't really like that solution.

7
well thanks :)

8
well, thanks a lot for the explanation. It was some german youtube tutorial.

and btw: i don't think this( http://www.sfml-dev.org/tutorials/2.0/window-inputs.php) gives too much insight :P

9
actually i got the code from a tutorial( for a button):

void Button::HandleEvents(sf::Event *ev){
        if(GetActive() == true){
        //Is the Mouse above the button? if yes check if left button is down and release (also set the current animation id to the rigth value)
        if(mInFocus == true){
                if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                        SetNextAnimationID("Anim3");
                        if(ev->MouseButtonReleased){
                                SetClicked(true);
                                }
                }
                else{
                        SetClicked(false);
                        SetNextAnimationID("Anim2");
                }
        }
        else{
                SetClicked(false);
                SetNextAnimationID("Anim1");
        }
        }
}

that works, but when i try it like that and change mState outside of the event loop depending on the state of IsClicked() it won't work as well...

e: got it to work :) still wondering why it works for the button OO

10
Hi :)

I'm quite new to SFML and atm trying to write myself a GUI for a game in want to make.

For that i need a checkbox, but that doesn't work the way i think it should.

my code:

Code: [Select]
if(mInFocus == true){
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
if(ev->MouseButtonReleased){
mState = !mState;
}
}
}

it keeps changing the mState Value when the button is pressed down and the mouse is moved in the checkbox area(mInFocus == true).

the button release seems to be ignored as long as there are other mouse events like the movement.

Any idea what i could do to prevent that from happening?

Pages: [1]