PDA

View Full Version : Speed concerns


~J~
01-31-2009, 11:09 PM
I've been playing about for a number of weeks now with a program, and while I'm in the middle of testing, just wrote a very simple test program to see what the speed would be like on the PocketPC.

My phone is an Orbit2 (or Polaris for the official HTC name) so quite a decent bit of kit.

However, the following code runs absolutely lousy on the device!!!! Almost unusable.

Is there any immediate mistakes or things to take into consideration? Should I remove string draws to the screen, should I not be performing a constant calculation and simple set velocities on X and Y to zero if they fall below a minimum threashold rather than going into .#########th of a float?


// Default Advanced Game API skeleton

#include "GameAPI.ppl"

func mainproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;

case (Msg$)
WM_CLOSE:
// Shutdown the GameAPI.
ShutGameAPI(hWnd$);

WM_KEYDOWN:
KeysPressed$[wParam$] = 1;

WM_KEYUP:
if (wParam$ == keys.vkB$)
if (KeysPressed$[keys.vkB$])
FirstTime$ = not FirstTime$;
end;
end;
KeysPressed$[wParam$] = 0;
end;

return (ok$);
end;

func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
// Clear screen first
G_Clear(0);
// Render all loaded sprites on screen.
RenderSprites;

g_textout(NULL, SpriteVelX(s$), DVT_CENTER, 0, 2, g_rgb(255, 255, 0));
g_textout(NULL, svx$, DVT_CENTER, 0, 20, g_rgb(255, 255, 0));
g_textout(NULL, SpriteVelY(s$), DVT_CENTER, 0, 40, g_rgb(255, 255, 0));

WM_TIMER:
// Check the keys if they are pressed.
if (KeysPressed$[keys.vkUp$])
if (SpriteVelY(s$)>-1.5)
SetSpriteVelY(s$,SpriteVelY(s$)-power$);
end;
end;

if (KeysPressed$[keys.vkDown$])

end;

if (KeysPressed$[keys.vkLeft$])
SetSpriteVelX(s$,SpriteVelX(s$)-0.01);
end;

if (KeysPressed$[keys.vkRight$])
SetSpriteVelX(s$,SpriteVelX(s$)+0.01);
end;

if (NOT KeysPressed$[Keys.vkUp$])

end;



end;
return (true);
end;

func LoadImages
s$ = loadsprite(AppPath$ + "ball.bmp", G_RGB(255, 0, 255), 1, 0, NULL);
AddSpriteOption(s$, SO_OVAL | SO_CHECKCOLLIDE | SO_PIXELCHECK | SO_BORDER | SO_KINETIC);
SetSpriteMass(s$, 0.05);
SetSpriteVelLimits(s$, 0, 05);
MoveSprite(s$,10,10);
SetSpriteCollide(s$, "player");
SetSpriteId(s$, "player");


t$ = loadsprite(AppPath$ + "ball.bmp", G_RGB(255, 0, 255), 1, 0, NULL);
AddSpriteOption(t$, SO_OVAL | SO_CHECKCOLLIDE | SO_PIXELCHECK | SO_BORDER | SO_KINETIC);
SetSpriteCollide(t$, "object");
SetSpriteId(t$, "object");

SetSpriteCollide(s$, "object");
MoveSprite(t$,50,100);
end;

func WinMain
// Create a new form that will hold the GAPI.
h$ = newform({GAPI}, {GAPIClass}, &mainproc);
ShowWindow(h$, SW_SHOW);

// Activate FPS display in white.
ShowFPS(true, G_RGB(255, 255, 255));




// Initialize GameAPI.
InitGameAPIEx(h$, &GameProc, 240, 320, true, 5, 360);

SetFriction(0.001);
SetGravity(0.01);


power$=0.03;


Global(s$,power$);
GameCollide(true);


LoadImages;

return (true);
end;

zehlein
02-01-2009, 07:22 AM
Hi,
the problem is your
InitGameAPIEx(h$, &GameProc, 240, 320, true, 5, 360);
which tells PPL to try to reach 360 frames per second on the ppc. This is of course a bit too much... :)
Try:
InitGameAPIEx(h$, &GameProc, 240, 320, true, 0, 30);
and watch your code fly!

~J~
02-01-2009, 11:11 AM
Yep that works fine, thank you.

However...

How come it doesn't work when running on the laptop? That's what's confusing me.

zehlein
02-01-2009, 11:31 AM
Change to
InitGameAPIEx(h$, &GameProc, 240, 320, true, 5, 30);

~J~
02-01-2009, 12:47 PM
yep, done that, but I thought that number dealt with the number of processes to run. So, for the PPC version, setting it to 0 in my mind would mean that no additional processes are run - which of course they are.

zehlein
02-01-2009, 01:05 PM
This is not quite right. Have a look here (http://forums.arianesoft.ca/showpost.php?p=9340&postcount=2) for a short description of InitGameAPIEx parameters.

~J~
02-01-2009, 04:47 PM
Ahhh, yeah that's answered it perfectly.

Thanks for the help Zehlein, much appreciated.