Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Help|Fps and 2DPhysics

Author
Message
linkertt
5
Years of Service
User Offline
Joined: 20th Feb 2019
Location:
Posted: 19th Mar 2019 03:08 Edited at: 19th Mar 2019 03:09
I couldnt find an answer in the webs, therefore im writing this.

Made a relative simple game with no "fat" code that causes fps drops.
Sometimes(like 1 time every minute) the fps rate drops like half a frame for a few frames.
Everytime it does that my 2d physiic sprites lose 90% of their current velocity making my game unplayable.

is there a workaround?

I found "StepPhysics()" but it doesnt help me with my problem.
Thanks in advance!
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 19th Mar 2019 07:16 Edited at: 19th Mar 2019 07:20
Are you using either of these?


If so, I experienced the same in my Pops game.

At first, i believed it was my use of looping OGG music because it sometimes lagged when the song re-started. So, i manually "looped" and i believe the lag frequency diminished somewhat but not altogether.

Recently, i got away from those 2 commands. Looking at the Help files, some less-than-desirables are mentioned.

I've gone to using SetSpritePhysicsForce(), instead, and, while i've done very little testing since: "So Far, So Good".
I still haven't gotten my head totally around the "force" that i want to use but i do know that to avoid the issue, i'm only calling it once (never constant because something interupts the above 2 commands and i want to avoid that).

So, something like:



which is a huge # to get the clown where i want him to go, but, its working (so far).

hope that helps

Btw, if you're using Sync(), you don't need StepPhysics(). Not sure if you are, but thought i'd throw that out there.

linkertt
5
Years of Service
User Offline
Joined: 20th Feb 2019
Location:
Posted: 19th Mar 2019 13:19
Thanks for the reply
I am using setspritephysicsimpule() indeed. But only when my level gets initialized. So there are no problems with that (till now).
My sprites bounce around with 0 friction and restitution on 1. They should never lose any velocity, but they do when the millisecund lag gets in the way.

Thats a fun looking game you have made
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 19th Mar 2019 16:38
Thanks, linkertt

Unfortunately, i do still have lag issues when using SetSpritePhysicsForce(),. Not as "unplayable" as before/it's a step in the right direction (i think because the force i'm using is so strong that it partially overpowers the lag (too soon for a May 4th pun, i know))

Pops is such a simple game that i'll probably write my own physics for it to remove the lag. Sadly, i'm thinking we're stuck with no other option (though i haven't sought help from others, yet).

And, one thing i haven't tried yet is to check whether or not the lag or interruption has occurred in-game/live and somehow compensate for it in the code. Ie, If LAG() then REAPPLY FORCE(). I think that's something we should both look into.




linkertt
5
Years of Service
User Offline
Joined: 20th Feb 2019
Location:
Posted: 19th Mar 2019 22:54
Found out if i tab out of the window or if i broadcast it to my android phone and tab out for a short moment, the physics get screwed over too
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Mar 2019 02:04 Edited at: 20th Mar 2019 02:05
i tried SetPhysicsThreading(-1) and the lags continued to pop up.

then, i shut the music off and played Pops for ~15 minutes without a single snag... the lag normally hits every 3-10 minutes, otherwise.

only 15 minutes of testing/not confirmed, but i know music has something to do with it. there might be more to it, but it's a start, for me.

are you, by chance, playing music?

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Mar 2019 02:43 Edited at: 20th Mar 2019 02:44
I made a test thingy (From the sample small games) that saves the velocity and if the difference in velocity over a frame is more than 1.5 it takes the last velocity and applies it.
Dunno if it will fix a lag but it seems to work when i drag the window
Click/Drag the ball to start
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Mar 2019 05:18
thanks, blink.

it's a start but i gotta tweak it since, when the clown hits a wall, it will continue applying the last force (making it climb the wall and stay in the corner).

checking for GetSpriteFirstContact(clown) = 1 (wall) isn't much help on its own so i'm not sure how to determine when if lastspeed.v / speed.v > 1.5 should be checked where, when it hits a wall, it shouldn't be.

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Mar 2019 05:24 Edited at: 20th Mar 2019 05:29
So you set physics force every frame or just when he bounces?

Quote: "when the clown hits a wall, it will continue applying the last force"

I dunno why it would do that? I cannot for the life of me make the code i posted do it
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Mar 2019 06:34
only once, when it bounces.

and, i didn't play with all the code you offered. i stripped these parts out and plugged them in to Pops:


when it hits a wall, it's always > 1.5 and the collision check is "hit and miss" (pun intended) so, the (single) check can't be trusted (on its own) the way i implemented the code.

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Mar 2019 06:45
Yeah that looks good to me. Very strange. I doesn't happen with the example
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Mar 2019 15:57 Edited at: 24th Mar 2019 15:59
linkertt,

haven't forgotten you, buddy, since we're sitting across from each other "in the same boat".

i saw this: https://forum.thegamecreators.com/thread/221608#msg2618894

and changed it to this and added it just before sync():



it should compensate for any lost frames (in case that's the problem).

still testing but i haven't had the lag since; give it a shot and see if it helps?

Login to post a reply

Server time is: 2024-11-23 02:07:55
Your offset time is: 2024-11-23 02:07:55