Shocking Speeds!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Shocking Speeds!

Post by Art »

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: 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&#40;"C2", 0x1000, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

int ballx = 0;
int bally = 0;
int done = 0;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	done = 1;
	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;
	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

  thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int main&#40;void&#41; &#123;

	char blankscreen_buffer&#91;200&#93;;
	Image* blankscreen;
	sprintf&#40;blankscreen_buffer, "./C2/blankscreen.png"&#41;;
	blankscreen = loadImage&#40;blankscreen_buffer&#41;;

	char ball_buffer&#91;200&#93;;
	Image* ball;
	sprintf&#40;ball_buffer, "./C2/ball.png"&#41;;
	ball = loadImage&#40;ball_buffer&#41;;

	char blackball_buffer&#91;200&#93;;
	Image* blackball;
	sprintf&#40;blackball_buffer, "./C2/blackball.png"&#41;;
	blackball = loadImage&#40;blackball_buffer&#41;;

	initGraphics&#40;&#41;;
	SceCtrlData pad, lastpad;

	SetupCallbacks&#40;&#41;;

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;1&#41;;
  
                blitAlphaImageToScreen&#40;0, 0, 480, 272, blankscreen, 0,0&#41;;
		flipScreen&#40;&#41;;

	sceCtrlReadBufferPositive&#40;&lastpad, 1&#41;;
	do &#123;

                blitAlphaImageToScreen&#40;0, 0, 32, 32, ball, ballx, bally&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
		flipScreen&#40;&#41;;

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons != lastpad.Buttons&#41; &#123;
     		lastpad = pad;
		&#125;
				
		if&#40;pad.Buttons & PSP_CTRL_UP&#41; &#123;
blitAlphaImageToScreen&#40;0, 0, 32, 32, blackball, ballx, bally&#41;;
bally = bally - 1;
if &#40;bally == -1&#41; &#123;
bally = 272;
&#125;
		&#125;
		
    		if&#40;pad.Buttons & PSP_CTRL_DOWN&#41; &#123;
blitAlphaImageToScreen&#40;0, 0, 32, 32, blackball, ballx, bally&#41;;
bally = bally + 1;
if &#40;bally == 273&#41; &#123;
bally = 0;
&#125;
		&#125;
			
		if&#40;pad.Buttons & PSP_CTRL_LEFT&#41; &#123;
blitAlphaImageToScreen&#40;0, 0, 32, 32, blackball, ballx, bally&#41;;
ballx = ballx - 1;
if &#40;ballx == -1&#41; &#123;
ballx = 480;
&#125;
		&#125;
		
    		if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41; &#123;
blitAlphaImageToScreen&#40;0, 0, 32, 32, blackball, ballx, bally&#41;;
ballx = ballx + 1;
if &#40;ballx == 481&#41; &#123;
ballx = 0;
&#125;
		&#125;
		sceDisplayWaitVblankStart&#40;&#41;;
		
	&#125; while&#40;!&#40;&#40;pad.Buttons & PSP_CTRL_START&#41; || done&#41;&#41;;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

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
Image Oldschool library for PSP - PC version released
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

Also try sceCtrlPeekBufferPositive instead of sceCtrlReadBufferPositive.

(Note, I'm not at my own PC right now, so hopefully those function names are correct).
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Ok, thanx.
I expected it to go very fast like a bullet if I added no delay.

I will try both of those suggestions.
Post Reply