 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sat May 13, 2006 11:56 pm Post subject: Shocking Speeds! |
|
|
Shockingly Slow that is....
This is an attempt to make a template for programs that use graphics .
The Dpad moves the "ball" sprite around the screen, but it's way too slow,
and I haven't added any delay.
Everytime the ball moves I am placing a black image over the top of the last frame.
Any ideas how to speed it up?
| Code: |
//
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <string.h>
#include <png.h>
#include <pspgu.h>
#include "graphics.h"
#include "mikmod.h"
#define true 1
#define false 0
/* Define the module info section */
PSP_MODULE_INFO("C2", 0x1000, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int ballx = 0;
int bally = 0;
int done = 0;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
done = 1;
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(void) {
char blankscreen_buffer[200];
Image* blankscreen;
sprintf(blankscreen_buffer, "./C2/blankscreen.png");
blankscreen = loadImage(blankscreen_buffer);
char ball_buffer[200];
Image* ball;
sprintf(ball_buffer, "./C2/ball.png");
ball = loadImage(ball_buffer);
char blackball_buffer[200];
Image* blackball;
sprintf(blackball_buffer, "./C2/blackball.png");
blackball = loadImage(blackball_buffer);
initGraphics();
SceCtrlData pad, lastpad;
SetupCallbacks();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
blitAlphaImageToScreen(0, 0, 480, 272, blankscreen, 0,0);
flipScreen();
sceCtrlReadBufferPositive(&lastpad, 1);
do {
blitAlphaImageToScreen(0, 0, 32, 32, ball, ballx, bally);
sceDisplayWaitVblankStart();
flipScreen();
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons != lastpad.Buttons) {
lastpad = pad;
}
if(pad.Buttons & PSP_CTRL_UP) {
blitAlphaImageToScreen(0, 0, 32, 32, blackball, ballx, bally);
bally = bally - 1;
if (bally == -1) {
bally = 272;
}
}
if(pad.Buttons & PSP_CTRL_DOWN) {
blitAlphaImageToScreen(0, 0, 32, 32, blackball, ballx, bally);
bally = bally + 1;
if (bally == 273) {
bally = 0;
}
}
if(pad.Buttons & PSP_CTRL_LEFT) {
blitAlphaImageToScreen(0, 0, 32, 32, blackball, ballx, bally);
ballx = ballx - 1;
if (ballx == -1) {
ballx = 480;
}
}
if(pad.Buttons & PSP_CTRL_RIGHT) {
blitAlphaImageToScreen(0, 0, 32, 32, blackball, ballx, bally);
ballx = ballx + 1;
if (ballx == 481) {
ballx = 0;
}
}
sceDisplayWaitVblankStart();
} while(!((pad.Buttons & PSP_CTRL_START) || done));
sceKernelExitGame();
return 0;
}
|
|
|
| Back to top |
|
 |
Brunni
Joined: 08 Oct 2005 Posts: 186
|
Posted: Sun May 14, 2006 5:13 am Post subject: |
|
|
You are waiting VBlank twice, so it won't run faster than 30 fps.
Anyways alpha blending in software rendering is extremely slow, you should really avoid it or use an hardware-accelerated library instead (see my signature if you're interested). _________________ Sorry for my bad english
Oldschool library for PSP - PC version released |
|
| Back to top |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Sun May 14, 2006 5:57 am Post subject: |
|
|
Also try sceCtrlPeekBufferPositive instead of sceCtrlReadBufferPositive.
(Note, I'm not at my own PC right now, so hopefully those function names are correct). |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sun May 14, 2006 6:22 am Post subject: |
|
|
Ok, thanx.
I expected it to go very fast like a bullet if I added no delay.
I will try both of those suggestions. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|