It seems that the demo mode for donkey does in fact come up but my graphics routine is apparently super super slow so it takes like a minute to get up.My graphics are probably like around 5 frames a second going by how slow donkey kong is moving.
Don't know how I'm gonna make it faster but hey I've gotten this far eh.
GlowCode, a profiler that I got is telling me that my graphics function is taking up 97% of the program time soooooo I think I know what to focus on here.
And 98% of my UpdateGraphics function is taken from within the function itself so it seems like the main culprit is stretch_blit(). Though I'm pretty sure the real problem is in my UpdateBackGround() function and how the Buffer BITMAP gets blitted.
now here's my background graphics routine. Now don't laugh, this just might be the most newbie, unoptimized crap you've ever seen....
Anyone that's using allegro, please help me at least somewhat optimize this mess cause I really have no idea here sadly
Don't know how I'm gonna make it faster but hey I've gotten this far eh.
GlowCode, a profiler that I got is telling me that my graphics function is taking up 97% of the program time soooooo I think I know what to focus on here.
And 98% of my UpdateGraphics function is taken from within the function itself so it seems like the main culprit is stretch_blit(). Though I'm pretty sure the real problem is in my UpdateBackGround() function and how the Buffer BITMAP gets blitted.
Code:
void Video::UpdateGraphics() {
UpdateBackGround(); // Buffer comes from this function
// just to show how many times this function got called
textprintf_centre_ex(Buffer, font, 75, 0, makecol(100,100,100), -1, "Update Graphics: %i", count);
stretch_blit(Buffer, screen, 0, 0, Buffer->w, Buffer->h, 0, 0, SCREEN_W, SCREEN_H);
count++;
}
UpdateBackGround(); // Buffer comes from this function
// just to show how many times this function got called
textprintf_centre_ex(Buffer, font, 75, 0, makecol(100,100,100), -1, "Update Graphics: %i", count);
stretch_blit(Buffer, screen, 0, 0, Buffer->w, Buffer->h, 0, 0, SCREEN_W, SCREEN_H);
count++;
}
now here's my background graphics routine. Now don't laugh, this just might be the most newbie, unoptimized crap you've ever seen....
Code:
void Video::UpdateBackGround() {
int NTval = 0; // The value of the current NameTable address
int PTaddr = 0; // Pattern table address
int ATaddr = 0; // The Attribute Table address
int PalleteVal = 0;
int COLOR = 0; // Current color of the pixel
int y = 0; // For use with the PutPixel function
// For blitting the Pattern Table onto the Background buffer
int TileX = 0;
int TileY = 0;
int NTstart = NameTableAddr;
int NTend = NameTableAddr + 0x3C0;
int bit = 7; // used for getting the first 2 bits of Color Index
// MAKING OF THE BACKGROUND
// 1) Find the current Name Table Value, Pattern Table address, Attribute Table address, and the current
// Attribute Table byte
// 2) Assemble all the 16 bytes of Pattern Table values to make one tile
// 3) Figure out first 2 bits for Color Index
// 4) Minus the bit variable for the next loop
// 5) Get last 2 bits from the Attribute Table. ATquadrant[] is a map used as a look-up table
// to see in which quadrant the Name Table byte is in
// 6) Get the Pallete value determined by the ColorIndex number which points to where
// in the Pallete table that color is
// 7) Find the color using the color from the int array look up table Color[0x40]
// 8) Plot that one pixel in the appropriate spot in the PatternTable BITMAP
// 9) Loop the x variable until the x coordinate reaches 8. Then up the y coordinate by one
// 10) Loop the PTbyte until all pixels have filled the tile
// 11) Now we have a Tile!
// 12) blit that tile(PatternTable) onto the BGbuffer BITMAP(256 x 240)
// 13) up the TileX coordinate by 8 to make room for the next tile
// 14) Loop back up to the 'addr' for loop(the very top loop) and move on to the next tile
// 15) rinse and repeat until all tiles are placed
// 16) FINALY: blit the fully tiled BGbuffer BITMAP onto the Buffer BITMAP
// Looping the current selected NameTable from beginning to end
for (int addr = NTstart; addr < NTend; addr++) {
NTval = VideoMem->GetValue(addr);
PTaddr = (NTval*0x10) + ScreenPTA;
ATaddr = FindATaddr(addr);
ATbyte = VideoMem->GetValue(ATaddr);
// Getting all the values needed to make one tile from the Pattern Table called
// from the value in the current Name Table byte.
for (int PToffset = 0; PToffset < 16; PToffset++) {
PTpixels[PToffset] = VideoMem->GetValue(PTaddr+PToffset);
}
for (int PTbyte = 0; PTbyte < 8; PTbyte++) {
for (int x = 0; x < 8; x++) {
ColorIndex.set(0, PTpixels[PTbyte].test(bit));
ColorIndex.set(1, PTpixels[PTbyte+8].test(bit));
bit--;
if (bit < 0) bit = 7;
switch(ATquadrant[addr]) {
case 0:
ColorIndex.set(2, ATbyte.test(0));
ColorIndex.set(3, ATbyte.test(1)); break;
case 1:
ColorIndex.set(2, ATbyte.test(2));
ColorIndex.set(3, ATbyte.test(3)); break;
case 2:
ColorIndex.set(2, ATbyte.test(4));
ColorIndex.set(3, ATbyte.test(5)); break;
case 3:
ColorIndex.set(2, ATbyte.test(6));
ColorIndex.set(3, ATbyte.test(7)); break;
}
switch(ColorIndex.to_ulong()) {
case 0: PalleteVal = VideoMem->GetValue(0x3F00); break;
case 1: PalleteVal = VideoMem->GetValue(0x3F01); break;
case 2: PalleteVal = VideoMem->GetValue(0x3F02); break;
case 3: PalleteVal = VideoMem->GetValue(0x3F03); break;
case 4: PalleteVal = VideoMem->GetValue(0x3F04); break;
case 5: PalleteVal = VideoMem->GetValue(0x3F05); break;
case 6: PalleteVal = VideoMem->GetValue(0x3F06); break;
case 7: PalleteVal = VideoMem->GetValue(0x3F07); break;
case 8: PalleteVal = VideoMem->GetValue(0x3F08); break;
case 9: PalleteVal = VideoMem->GetValue(0x3F09); break;
case 10: PalleteVal = VideoMem->GetValue(0x3F0A); break;
case 11: PalleteVal = VideoMem->GetValue(0x3F0B); break;
case 12: PalleteVal = VideoMem->GetValue(0x3F0C); break;
case 13: PalleteVal = VideoMem->GetValue(0x3F0D); break;
case 14: PalleteVal = VideoMem->GetValue(0x3F0E); break;
case 15: PalleteVal = VideoMem->GetValue(0x3F0F); break;
}
for (int col = 0; col < 0x40; col++) {
if (PalleteVal == col) {COLOR = Color[col]; break;}
}
putpixel(PatternTable, x, y, COLOR);
}
y++;
if (y == 8) y = 0;
}
stretch_blit(PatternTable, BGbuffer, 0, 0, PatternTable->w, PatternTable->h, TileX, TileY, 8, 8);
TileX += 8;
if (TileX == 256) {TileY += 8; TileX = 0;}
}
blit(BGbuffer, Buffer, 0, 0, 0, 0, 256, 240);
}
int NTval = 0; // The value of the current NameTable address
int PTaddr = 0; // Pattern table address
int ATaddr = 0; // The Attribute Table address
int PalleteVal = 0;
int COLOR = 0; // Current color of the pixel
int y = 0; // For use with the PutPixel function
// For blitting the Pattern Table onto the Background buffer
int TileX = 0;
int TileY = 0;
int NTstart = NameTableAddr;
int NTend = NameTableAddr + 0x3C0;
int bit = 7; // used for getting the first 2 bits of Color Index
// MAKING OF THE BACKGROUND
// 1) Find the current Name Table Value, Pattern Table address, Attribute Table address, and the current
// Attribute Table byte
// 2) Assemble all the 16 bytes of Pattern Table values to make one tile
// 3) Figure out first 2 bits for Color Index
// 4) Minus the bit variable for the next loop
// 5) Get last 2 bits from the Attribute Table. ATquadrant[] is a map used as a look-up table
// to see in which quadrant the Name Table byte is in
// 6) Get the Pallete value determined by the ColorIndex number which points to where
// in the Pallete table that color is
// 7) Find the color using the color from the int array look up table Color[0x40]
// 8) Plot that one pixel in the appropriate spot in the PatternTable BITMAP
// 9) Loop the x variable until the x coordinate reaches 8. Then up the y coordinate by one
// 10) Loop the PTbyte until all pixels have filled the tile
// 11) Now we have a Tile!
// 12) blit that tile(PatternTable) onto the BGbuffer BITMAP(256 x 240)
// 13) up the TileX coordinate by 8 to make room for the next tile
// 14) Loop back up to the 'addr' for loop(the very top loop) and move on to the next tile
// 15) rinse and repeat until all tiles are placed
// 16) FINALY: blit the fully tiled BGbuffer BITMAP onto the Buffer BITMAP
// Looping the current selected NameTable from beginning to end
for (int addr = NTstart; addr < NTend; addr++) {
NTval = VideoMem->GetValue(addr);
PTaddr = (NTval*0x10) + ScreenPTA;
ATaddr = FindATaddr(addr);
ATbyte = VideoMem->GetValue(ATaddr);
// Getting all the values needed to make one tile from the Pattern Table called
// from the value in the current Name Table byte.
for (int PToffset = 0; PToffset < 16; PToffset++) {
PTpixels[PToffset] = VideoMem->GetValue(PTaddr+PToffset);
}
for (int PTbyte = 0; PTbyte < 8; PTbyte++) {
for (int x = 0; x < 8; x++) {
ColorIndex.set(0, PTpixels[PTbyte].test(bit));
ColorIndex.set(1, PTpixels[PTbyte+8].test(bit));
bit--;
if (bit < 0) bit = 7;
switch(ATquadrant[addr]) {
case 0:
ColorIndex.set(2, ATbyte.test(0));
ColorIndex.set(3, ATbyte.test(1)); break;
case 1:
ColorIndex.set(2, ATbyte.test(2));
ColorIndex.set(3, ATbyte.test(3)); break;
case 2:
ColorIndex.set(2, ATbyte.test(4));
ColorIndex.set(3, ATbyte.test(5)); break;
case 3:
ColorIndex.set(2, ATbyte.test(6));
ColorIndex.set(3, ATbyte.test(7)); break;
}
switch(ColorIndex.to_ulong()) {
case 0: PalleteVal = VideoMem->GetValue(0x3F00); break;
case 1: PalleteVal = VideoMem->GetValue(0x3F01); break;
case 2: PalleteVal = VideoMem->GetValue(0x3F02); break;
case 3: PalleteVal = VideoMem->GetValue(0x3F03); break;
case 4: PalleteVal = VideoMem->GetValue(0x3F04); break;
case 5: PalleteVal = VideoMem->GetValue(0x3F05); break;
case 6: PalleteVal = VideoMem->GetValue(0x3F06); break;
case 7: PalleteVal = VideoMem->GetValue(0x3F07); break;
case 8: PalleteVal = VideoMem->GetValue(0x3F08); break;
case 9: PalleteVal = VideoMem->GetValue(0x3F09); break;
case 10: PalleteVal = VideoMem->GetValue(0x3F0A); break;
case 11: PalleteVal = VideoMem->GetValue(0x3F0B); break;
case 12: PalleteVal = VideoMem->GetValue(0x3F0C); break;
case 13: PalleteVal = VideoMem->GetValue(0x3F0D); break;
case 14: PalleteVal = VideoMem->GetValue(0x3F0E); break;
case 15: PalleteVal = VideoMem->GetValue(0x3F0F); break;
}
for (int col = 0; col < 0x40; col++) {
if (PalleteVal == col) {COLOR = Color[col]; break;}
}
putpixel(PatternTable, x, y, COLOR);
}
y++;
if (y == 8) y = 0;
}
stretch_blit(PatternTable, BGbuffer, 0, 0, PatternTable->w, PatternTable->h, TileX, TileY, 8, 8);
TileX += 8;
if (TileX == 256) {TileY += 8; TileX = 0;}
}
blit(BGbuffer, Buffer, 0, 0, 0, 0, 256, 240);
}
Anyone that's using allegro, please help me at least somewhat optimize this mess cause I really have no idea here sadly