PDA

View Full Version : Power consumption of PPL programs on mobile devices


sdkfz250
10-08-2009, 11:33 AM
Hello,

I have nearly finished a Mahjongg Solitaire game with PPL which I run on my HTC Artemis (3300). This games uses a lot of sprites and I noticed that my battery runs out of power extremley fast when I play a few rounds with this game (I will post a version here when it is finished). Other mobile games do not waste so much energy during game play. Are there any hints you can give me how to reduce power consumption of PPL programs on mobile dvices?

Thanks for your help in advance.

Sdkfz250

kornalius
10-08-2009, 02:35 PM
Hi,

It really depends on how you code your game. PPL uses a loop internally but can also use Windows messaging to let the device in idle mode until an event occurs (like a stylus press or button press).

Check the g_setcyclemode() function.

Nicknack
10-08-2009, 07:02 PM
isn't also the 100% cpu power need of the gapi a reason for the energy drain?
is there some info on the web why the gameapi always uses as much cpu power as it gets?
would be very interesting to know, btw have you read my email at the support address kornalius?

kornalius
10-08-2009, 10:00 PM
gapi does not use 100% CPU, it is the loop that runs internally that draws the scene and processes the objects of the game. You can reduce this drastically by using a GetMessage() (in C) inside the loop and draw the screen only when an API event is triggered. However this will make the objects of the game unresponsive. Another great way would be to use multi-threading.

All of this talk here is mainly for C and not PPL. PPL has all of these technics built-in (except multi-threading for now).

sdkfz250
10-09-2009, 05:46 AM
Thanks,

Do you have a simple code example (maybe with multi-threading, which can be used with GAME api? For example, a simple program which waits for user input and then performs a repaint of the screen for updating the sprites?

Sorry for selecting the PPL 2 forum.Thisis more a PPL 1 question (maybe).

Sdkfz250

Nicknack
10-09-2009, 08:36 AM
is this example good for you? I tried to include every avaible gameapi method to speed it up.
read the help for further information, eg g_SetMainLoop doesn't work for you if you use automatic sprite movements. g_setCycleMode's help file is incomplete so I'm not sure if I use it at its best way.
#include "GameAPI.ppl"

func mainproc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_CLOSE: // Window is closed
ShutGameAPI(hWnd$);
WM_KEYDOWN:
g_KeyEvent(wParam$, True);
WM_KEYUP:
g_KeyEvent(wParam$, False);
end;
return (true);
end;

func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
g_clear(0);
RenderSprites;
WM_TIMER:
Offsetsprite(sp$, 1, 1);
if (g_key.vkA$)
PostMessage(hWnd$, WM_CLOSE, 0, 0);
end;
end;
return (true);
end;

func WinMain
h$ = newform({GAPI}, {GAPIClass}, &mainproc);
ShowWindow(h$, SW_SHOW);
ShowFPS(true, G_RGB(255, 255, 255));
InitGameAPIEx(h$, &GameProc, 240, 320, false, 5, 60);

global(sp$);
sp$=newsprite(null);
Setspritewidth(sp$, 10);
Setspriteheight(sp$, 10);
g_setcyclemode(1);
g_SetUpdateMode(UM_SINGLE);
g_SetMainLoop(1);

return (true);
end;
@kornalius: please, check also the incorrect help file of SetSpriteVelocity!

sdkfz250
10-09-2009, 10:05 AM
Thanks Nicknack,

I will try the code and hope that this will reduce power drain significantly.

Cheers

Sdkfz250