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: Select all
//
#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;
}