how to normalize speed(frame rate) of thread in different phones - android

I have been doing some work on surfaceview class in android.
there i have used "thread.sleep(50)" in my run method.But the game runs faster on some phones and slower on others.What can i do to normalize the speed or make speed constant across different phones.

Yes FPS can vary device to device based on the device configuration(processor/camera etc). You can set your sleep time depending on FPS.

Related

How to trick Android to run cpu at max clock speed?

Here is some context. I am working on a 3d game on Android, and have been getting fluctuating FPS which is annoying.
Then I profiled the game and figured out that the processors were not always running at max clock speed. In fact, this was due to the fact that the active (as well as default) governor appeared to be 'interactive', which would try to act smart in that it would adjust clock speed according to current load.
I then rooted my device and set the governor to be 'performance', which locks clock speed at max. As the result the game was running super smooth giving a stable fps of 30.
The issue is that you don't have control, as an application, over what governor to use. That is, you cannot do anything if a player has an un-rooted phone, as it is an OS-level thing anyway. Even if they had their phones rooted, it would be still their, not our, judgement to make in which governor profile to activate.
So my question is, what can we do as developers, on application level, to 'trick' processors so that they are believed to have much work to do, which in fact they do not? The goal is to trick whatever governor to set clock speed at max, or at least at some fixed numbers, so that FPS would not fluctuate and make the game run at a performance that is lacking and below user expectations.
Thanks!

andengine (android opengl) low cpu usage

I have an andengine game, which has:
45-50-55 fps on a normal Galaxy S3, the phone temperature is warm.
stable 60 fps on CM11 Galaxy S3 with root in performance mode (maximum cpu frequence = 1400mhz) . With root you can modify the cpu frequence. The phone temperature is almost hot.
40-45fps on my Nexus 6 (without root), but this phone is faster than galaxy s3! The phone temperature is almost cold.
The resolutions of the game are the same!
The main question is: why does my game fps same on the both device? On Nexus6 it should be faster!
The game is: https://play.google.com/store/apps/details?id=com.hattedskull.gangsters
when a cpu is faster but does show less performance then the other cpus, it could be that it uses only 1 of 2,4,8,12 cores. thats just 25% usages, s the cpu stays cold. a single core cpu will always burn at 100%, and gets warm. Multithreading is the solution. that will "force" the cpu to go at 100%, and the game will run faster
I am answering my question, because it is not obvious (for me), so the solution is:
Performance mode: After rooting the phone, I changed the scaling governor (at processor) mode in performance, changing min hz was not necessary. Now the phone are hot, not warm!
Mobil ads bad performance: I switched off all the internet connections (wifi, mobile), therefore the mobile ad disappeared from the game. I use admob in my game, which has not the best performance.
These caused the FPS drops in my game(s)!

Android thread performance/priority on Galaxy Note 2 when screen is touched/released

I have an OpenGL game for Android. It runs at a good 60fps when the screen is touched. When I release my finger it goes back down to around 30fps. Does the touch event/release raise/lower a thread's priority and if so how can I replicate this to keep it at a constant 60fps. This only seems to be an issue on Galaxy Note 2 so far.
I'll assume you are using onDrawFrame and setRenderMode(RENDERMODE_CONTINUOUSLY).
30 and 60FPS indicates that your implementation of onDrawFrame is called as the device's screen refreshes. Most displays refresh at 60Hz, giving you 60FPS.
It is likely that the Galaxy Note 2 has some power saving feature that limits screen refresh to 30Hz when there are no touches on screen. Check if there's any way to disable this feature.
AFAIK, OpenGL ES does not specify a standard for screen refresh rates, you will need a throttling function to ensure that your game runs/feels the same (i.e. at the same speed) despite differences in FPS.
Yes.
The best way to observe this phenomena is to use systrace with the "freq" tag enabled. You probably need a rooted device, and you definitely need one on which systrace is enabled.
systrace will record changes in the clock frequency for various components. It varies by device, but you can usually get the per-core CPU clocks and GPU memory rate. You will likely see several of them drop significantly at the same time your frame rate drops.
The motivation for doing this is to reduce power requirements and extend battery life. The assumption is that, while your finger is in contact with the screen, you're actively doing something and the device should be as responsive as possible. After a brief period of time, the clocks will slow to a level appropriate for the current workload. The heuristics that determine how long to wait before slowing, and how much to slow down, are tuned for each device.
(This has caused some people to create a thread that just sits and spins on multi-core devices as a way to artificially prop up the CPU clock rate. Not recommended. See also this answer.)
The bottom line is that this isn't a simple matter of adjusting thread priorities. You have to choose between recognizing that the slowdown will happen and adapting to it (by making your game updates independent of frame rate), or figure out some way to fool the device into staying in a higher-power mode when you want smooth animation.
(For anyone who wants to play along at home: build a copy of Grafika and start the "Record GL app" activity. If you drag your finger around the screen all will be well, but if you leave it alone for a few seconds you may start to see the dropped-frame counter rising as the app falls behind. Seen on Nexus 5, Nexus 7 (2013), and others.)

Box2d libgdx very slow on device

its supposed that, a time step is necesary to run a game at the correct speed, a fast hardware will adjust the speed to 30 or 60 fps, otherwise, the game will run so fast as the hardware can handle it. Now, my game runs as expected on the pc, but, when is launched on the device(galaxy ace), the body moves very slow, even has a maximum speed wich can not exceed, whatever be amount in Body.AppliLinearImpulse or AppliForce, also, i've changed the setLinearVelocity to a very high number, and always is the same speed.
could be a bug on libgdx box2d? or a bug with my galaxy ace android 2.3
You are probably simulating Box2D bodies while passing in the dimensions equal to pixel values. Box2D runs in meters, however, so creating bodies 300 meters in size really puts a low ceiling on your entire simulation.
Recommended approach is to use arbitrary ratio (1m == 64px) and scale down your Box2D system - initialize and manipulate bodies using meter values converted from px.
This will allow for a wider variety of motion and a higher ceiling on velocity. Had the same issue as you and took me a bit of time to figure it out.

Android game loop, how to control speed and frame rate

I've written a game for Android, and I've tested it on the Dev Phone 1. It works perfectly, the speed is just right. However, I'm sure phone CPU's are getting faster. They may already be faster than the dev phone.
How do I make sure that my game runs at the exact same speed no matter what the device or how fast it runs? Do you know of any techniques? Should I check some kind of timer at the top of the loop each time?
I guess I'm referring to frame rate - but mostly the speed at which my game runs through the main game loop.
Any theory or experience would be great! Thank you.
If you are targeting certain frame rate, the basic idea is that you should have a timer or thread that executes your game's tick method at desired intervals. With timers the implementation is pretty trivial: just schedule a timer to execute at regular intervals. When using threads you have to put the thread to sleep between consecutive ticks if it runs faster than the desired frame rate.
However, this alone doesn't lead to the best possible results as the interval can vary a bit between the frames. There is a very good article on this issue: http://gafferongames.com/game-physics/fix-your-timestep/.
Also, there are already slower and faster Android phones than the dev phone 1. So you have to prepare for the both cases if you are targeting all Android devices. If your game is not that CPU heavy, it might be that you can achieve the desired frame rate on all the devices. But if you don't limit the frame rate, your game will be too fast on the faster Android phones.

Categories

Resources