Perfomance problem in Android

Previous topic - Next topic

galiksoft

Hi everybody.

I made a game in GLBasic 10, a kwirk clone. I compilled both to windows and Android. In windows everything is ok, but the Android users report big perfomance problems, mainly, the need for press several times in buttons, to the event be accepted...

Check the two versions, both free:
win: galiksoft.is-great.org/kwirkfree.zip   (copy and paste in url space of the browser)
android: https://play.google.com/store/apps/details?id=com.galiksoft.kwirkfree

The code structure is something like that:

gosub openlevel
gosub play
...
sub play:
   while quit=0
       gosub checkinput
       gosub showgraphics
   wend
endsub

...

sub showgraphics:
   //draw everything
   showscreen
endsub

...

sub checkinput:
   local mx,my,b1,b2

   mousestate mx,my,b1,b2

   if b1>0
      if mx>... and mx<... and my>... and my<...   //test is the button area was pressed, example: up button
           move(0,-1)
      endif
   endif
endsub

...

function move: %xx, %yy
   //check if the character can move
   //if it can move, refresh positions, move blocks or turn pieces if aplicable...
endfunction


Apparently this is the fine way to do, and in windows there is no problem.
But it Android, the game runs very slow...

I tought the problem would be in play sub, in the loop because the game is allways redrawing the screen and present it. I tried just redraw if there is a move, but that cause game crash in checkinput sub because of the mousestate command...

How can I improve the perfomance in Android?

i don't have an Android device but I got the same slow gameplay (with problems in accept button press) in Android Virtual Device, after compillation for Android.

Thank you in advance!

okee

Runs fine on my Galaxy S2 but is a bit slow on my ZTE Blade
You have to press the move buttons a few times feels very unresponsive
The whole game is slow including the animation of the character

From what you say you seem to be doing everything right
You should be redrawing every loop

Maybe make sure your not loading images or levels in the main loop by accident
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

dreamerman

#2
That isn't problem of Android but more likely not properly written code. On my dual-core pc, controls are responsive but game takes 50% of cpu power, it shouldn't happen.
You should use at least Limitfps and Sleep commands:
Code (glbasic) Select
sub play:
Limitfps 30
   while quit=0
       gosub checkinput
       gosub showgraphics
       sleep 25
   wend
endsub


Or your main loop can be more sophisticated:
Code (glbasic) Select
sub play:
Limitfps 30
   while quit=0
curr_time# = GETTIMERALL()
IF (curr_time# - last_time# >= 33)
              gosub checkinput
              gosub showgraphics
   last_time# = curr_time#
ENDIF
       sleep 20
   wend
endsub


I don't have experience with current version of Android emulator, but add these changes and test how it will work.

Edit: Or maybe your drawing routines are messed up.. for example If your graphic covers whole screen don't use 'clearscreen' command, just draw new graphic over previous.
Check my source code editor for GLBasic - link Update: 20.04.2020

Asmodean

I've tested the Game on my Archos 101-Tablet and my Windows PC. On both platforms I had no speed-issue. The only thing i recognized was that the GPU-Usage on the PC was for this kind of game rather high. Maybe an OpenGL problem on some Android-Devices?
 

bigsofty

I can confirm, unfortunately, that on the Nexus 7 it's running very poorly, taking about a second a move.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

galiksoft

Quote from: dreamerman on 2012-Jul-25
That isn't problem of Android but more likely not properly written code. On my dual-core pc, controls are responsive but game takes 50% of cpu power, it shouldn't happen.
You should use at least Limitfps and Sleep commands:
Code (glbasic) Select
sub play:
Limitfps 30
   while quit=0
       gosub checkinput
       gosub showgraphics
       sleep 25
   wend
endsub


Or your main loop can be more sophisticated:
Code (glbasic) Select
sub play:
Limitfps 30
   while quit=0
curr_time# = GETTIMERALL()
IF (curr_time# - last_time# >= 33)
              gosub checkinput
              gosub showgraphics
   last_time# = curr_time#
ENDIF
       sleep 20
   wend
endsub


I don't have experience with current version of Android emulator, but add these changes and test how it will work.

Edit: Or maybe your drawing routines are messed up.. for example If your graphic covers whole screen don't use 'clearscreen' command, just draw new graphic over previous.

I made all these modifications and the game runs slow yet in Android Emulator....
Because in Android there are multiple resolutions I use stretchsprite commands instead of drawsprite. Is stretchsprite command so slow in Android to make the game been slow? As you can imagine, I use many times the command in the drawing sub. The cause would be that?

dreamerman

But does it still consume so much cpu/gpu power on pc? First extensively test your code on pc, with all possible trick's then, check how much speed it gained on emulator/real devices. Use 'LimitFps -1' to unlock fps limiter, and see how many fps you will get on pc with particular changes.
'StrechSprite' shoudn't be used many times, specially on mobile devices. There can be also other small issues, for example float calculations # are of course slower than integer %, so they should be used only when necessary.
When it comes to drawing, you probably should use other commands than strechsprite for example:
Code (glbasic) Select
1. draw all graphic at desired res (let say 320x480) to offscreen texture (UseScreen cmd)
2. render that texture (with all game graphic) to screen with one strechsprite/polyvector

Of course also mouse position should be recalculated also..
Or use some already made custom functions like these from 'Z Project' by Ampos -> LINK
Check my source code editor for GLBasic - link Update: 20.04.2020

Asmodean

Galiksoft, can you test your game with different Android-Versions on the Emulator? My Archos has 2.2 and I have no speed- or control-problems by playing your game.  Maybe there is only a problem with some Android-Versions.

MrTAToad

The Android emulator is extremely slow (as it's Java), so shouldn't be used as a guide to how GLBasic performs on Android.

You need either a proper machine or use Bluestacks, which emulates Android but at the proper speed (plus you can choose different display forms).  The only downside is that you must sign your application as it won't allow unsigned ones.

Asmodean

I've tested Kwirk on BlueStacks and it is way too slow.  Also the controls are sluggish and the player-sprite is wobbling.   I've testet Angry Birds Space too and there was no problem with speed or controls. Both Games had the same CPU-Usage.  I don't know which Android-Version Bluestacks uses, so I can't say the behavior is because of the  Android-Version.

galiksoft

Quote from: dreamerman on 2012-Jul-25
But does it still consume so much cpu/gpu power on pc? First extensively test your code on pc, with all possible trick's then, check how much speed it gained on emulator/real devices. Use 'LimitFps -1' to unlock fps limiter, and see how many fps you will get on pc with particular changes.
'StrechSprite' shoudn't be used many times, specially on mobile devices. There can be also other small issues, for example float calculations # are of course slower than integer %, so they should be used only when necessary.
When it comes to drawing, you probably should use other commands than strechsprite for example:
Code (glbasic) Select
1. draw all graphic at desired res (let say 320x480) to offscreen texture (UseScreen cmd)
2. render that texture (with all game graphic) to screen with one strechsprite/polyvector

Of course also mouse position should be recalculated also..
Or use some already made custom functions like these from 'Z Project' by Ampos -> LINK

Today, I made that. Now I'm using only drawsprite commands, createscreen, usescreen, and finally only one stretchsprite to present graphics to real screen. In windows all ok. In Android, simply doesn't work. When I start the level, I get only a full black screen. I press the top-right corner, where I know the exit button should be, and I go back to inicial menu...
So, I can't see graphics, neither conclude if now the buttons are responsive...

MrTAToad

Are you using a generic Chinese device ?

One thing that will be worth trying is https://play.google.com/store/apps/details?id=com.unmap.test3dspeed&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS51bm1hcC50ZXN0M2RzcGVlZCJd (my 3D speed tester)

There should be no control problems (at least until you start using models with lots of vertices - but thats the whole point of the program).

I had no control problems with your program.  However, the characters sprite does seem to move strangely...

galiksoft

Quote from: MrTAToad on 2012-Jul-26
I had no control problems with your program.  However, the characters sprite does seem to move strangely...

If you refer to character moving up and down, it is right. I made that as simple and stupid animation, I think it is better than be parked...

quangdx

replace all the sprite commands with polyvector.
i did this in my games and got a decent speed increase.
Asobi tech - the science of play.
Spare time indiegame developer.

galiksoft

Quote from: quangdx on 2012-Jul-31
replace all the sprite commands with polyvector.
i did this in my games and got a decent speed increase.

I did that and I don't see any improvement...

I conclude that GLBasic can't be used to make a decent game for Android. I will try another engine/language, maybe unity, or java itlsef...