1. Because you're using both VRAM and system RAM for graphics, you have to needlessly check everytime whether-or-not the operation is being performed against the screen (into VRAM) or against something else (in system RAM). Considering it has 2MB, isn't it being a little restrictive using it exclusively for the ~256KB frame buffer? It would be a lot faster to just use VRAM exclusively, and just have an error if the user tries to load more graphics than memory permits.
Either that, or go the AMOS/Darkbasic way and start making more libraries that use and manage VRAM themselves (like sprites with collision detection and scrolling tilemapped playfields).
2. Every single graphics command, including pixel() is bounds checking. While this is the safest practice against novice programmers, it adds a lot of overhead (e.g., compare filling the screen with fillScreenRect versus doing it a pixel-at-a-time within LUA). Perhaps a Blitz like FastWitePixel and FastReadPixel function could be made that does not do this and only draws to the screen (to also avoid the overhead of that test).
3. Unless perfectly optimized, MUL and DIV should be avoided at the top loop in drawing functions. For example, in fillScreenRect, instead of doing a PSP_LINE_SIZE * whatever each pixel, you calculate the pixels skipped per line (which is the image width minus the rect width).
Code: Select all
void fillScreenRect(u16 color, int x0, int y0, int width, int height)
{
sceKernelDcacheWritebackInvalidateAll();
if (!initialized) return;
u16* vram = getVramDrawBuffer();
int x, y;
int xSkip, screenPos;
xSkip = PSP_LINE_SIZE - width;
screenPos = (PSP_LINE_SIZE * y0) + x0;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
vram[screenPos++] = color;
}
screenPos += xSkip;
}
sceKernelDcacheWritebackInvalidateAll();
}
Code: Select all
((y << 9) - (y << 5))
Code: Select all
public void lineFast(int x0, int y0, int x1, int y1, Color color)
{
int pix = color.getRGB();
int dy = y1 - y0;
int dx = x1 - x0;
int stepx, stepy;
if (dy < 0) { dy = -dy; stepy = -raster.width; } else { stepy = raster.width; }
if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
dy <<= 1;
dx <<= 1;
y0 *= raster.width;
y1 *= raster.width;
raster.pixel[x0+y0] = pix;
if (dx > dy) {
int fraction = dy - (dx >> 1);
while (x0 != x1) {
if (fraction >= 0) {
y0 += stepy;
fraction -= dx;
}
x0 += stepx;
fraction += dy;
raster.pixel[x0+y0] = pix;
}
} else {
int fraction = dx - (dy >> 1);
while (y0 != y1) {
if (fraction >= 0) {
x0 += stepx;
fraction -= dy;
}
y0 += stepy;
fraction += dx;
raster.pixel[x0+y0] = pix;
}
}
}
5. Does Luaplayer support lua binary modules? It may be an interesting way to go, then different modules could be created for different needs. I just don't know if the PSP's DRM with stop this possibility... but for example.
ok, str = loadmodule("luadebuggfx") loads standard Lua graphics routines
ok, str = loadmodule("luafastgfx") loads graphics routines that are VRAM only and have all bounds (x<0) checking removed for speed.