Just recompiled but not found any noticeable improvement...but i want to take your attention on 2 things i'm experimenting.
Load of TTF font only on startup of the game and try to use mp3 files instead of ogg music files.
I have changed some code (but i'm not a programmer) and with mp3 music the game work but didn't hear nothing on output.
With TTF font i remember i've read from gp32x.de forum ( i think from "hmn" user ) this doc:
from
http://www.gp32x.de/board/index.php?/topic/55495-gaming-wiz-slow-with-sdl-ttf-h/?hl=%2Bttf+%2Bbenchmark#entry896721
Not loading the font every time should give a BIG speedup. I actually wrote a little benchmark for this:
Loading font every time -> 6 FPS
Loading font just once --> 195 FPS
------------------------------------------------------------------------------
#include <SDL.h>
#include <SDL_ttf.h>
#include <assert.h>
const char* fontFilename = "DejaVuSans.ttf";
const int fontSize = 20;
void DrawTextOld( SDL_Surface* screen, char *text, int x, int y) {
TTF_Font *font;
//font=TTF_OpenFont("gfx/font.ttf",12);
font = TTF_OpenFont( fontFilename, fontSize );
SDL_Color color = { 255, 255, 255 };
SDL_Rect coordinates;
coordinates.x = (int)x;
coordinates.y = (int)y;
SDL_Surface *message = NULL;
message=TTF_RenderText_Solid(font,text,color);
SDL_BlitSurface(message,0,screen,&coordinates);
TTF_CloseFont(font);
SDL_FreeSurface(message);
}
void DrawTextNew( SDL_Surface* screen, TTF_Font* font, char *text, int x, int y) {
//TTF_Font *font;
//font=TTF_OpenFont("gfx/font.ttf",12);
SDL_Color color = { 255, 255, 255 };
SDL_Rect coordinates;
coordinates.x = (int)x;
coordinates.y = (int)y;
SDL_Surface *message = NULL;
message=TTF_RenderText_Solid(font,text,color);
SDL_BlitSurface(message,0,screen,&coordinates);
//TTF_CloseFont(font);
SDL_FreeSurface(message);
}
void DrawText( SDL_Surface* screen, TTF_Font* font, char *text, int x, int y, int old ) {
if( old )
DrawTextOld( screen, text, x, y );
else
DrawTextNew( screen, font, text, x, y );
}
int main( int argc, char** argv )
{
assert( !SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) );
assert( SDL_JoystickOpen( 0 ) );
SDL_Surface* screen = SDL_SetVideoMode( 320, 240, 0, SDL_SWSURFACE );
assert( screen );
assert( !TTF_Init() );
TTF_Font* font = TTF_OpenFont( fontFilename, fontSize );
assert( font );
int old = 1;
Uint32 ticks0 = SDL_GetTicks();
Uint32 ticks = 0;
Uint32 frames = 0;
Uint32 fps = 0;
for( ;; ) {
int run = 1;
SDL_Event e;
while( SDL_PollEvent( &e ) ) {
if( e.type == SDL_QUIT ) {
run = 0;
}
else if( e.type == SDL_JOYBUTTONDOWN ) {
if( e.jbutton.button == 8 ) {
run = 0;
}
else if( e.jbutton.button == 9 ) {
old = old ? 0 : 1;
}
}
}
if( !run )
break;
SDL_FillRect( screen, 0, 0 );
const int x = 16;
int y = 16;
DrawText( screen, font, "Press menu to quit", x, y, old );
y += 30;
DrawText( screen, font, "Press select to change routine", x, y, old );
y += 30;
DrawText( screen, font, old ? "Old routine" : "New routine", x, y, old );
y += 30;
char buffer[ 100 ];
snprintf( buffer, sizeof( buffer ), "FPS: %d", fps );
DrawText( screen, font, buffer, x, y, old );
SDL_Flip( screen );
frames++;
Uint32 ticks1 = SDL_GetTicks();
ticks += ticks1 - ticks0;
ticks0 = ticks1;
if( ticks >= 1000 ) {
fps = ( 1000 * frames ) / ticks;
ticks = 0;
frames = 0;
}
}
TTF_Quit();
SDL_Quit();
return 0;
}
I have added this but i have segfault...but maybe i have done something wrong.
Also i have commented out a line in main.c as suggested by an user on gp32x.de forum :
Code:
/* Contadores */
if (ciclo[0] < 29)
ciclo[0] ++;
else
ciclo[0] = 0;
if (ciclo[1] < 90)
ciclo[1] ++;
else
ciclo[1] = 0;
if (ciclo[2] < 8)
ciclo[2] ++;
else
ciclo[2] = 0;
//disabled by farox...seems ok
//SDL_FillRect(pantalla, NULL, SDL_MapRGB(ventana->format, 0, 0, 0));
animitems (fase, habitacion, ciclo);
dibujarfase (ventana, fase, tiles, habitacion, ciclo, *cambiot, fondomd);
if (habitacion != 4)
barradeestado (ventana, tiles, habitacion, jean.estado[0], jean.estado[1]);
if (jean.flags[6] < 8)
dibujarjean (ventana, tiles, &jean, ciclo);
/* Gestion de enemigos */
if (enemigos.tipo[0] > 0) {
if (habitacion != 4)
moverenemigos (&enemigos, fase, ciclo, proyec, jean);
if ((habitacion == 5) || (habitacion == 6))
cruzados (&enemigos, ventana, tiles, ciclo, habitacion);
if (habitacion == 10)
dragon (&enemigos, ventana, tiles, ciclo, proyec);
if (habitacion == 11)
bolafuego (&enemigos, ventana, tiles, ciclo, jean, fase);
if (habitacion == 14)
plantas (&enemigos, ventana, tiles, ciclo, proyec);
if (habitacion == 9)
dibujarcuerda (enemigos, ventana, tiles);
if (habitacion == 18)
muerte (&enemigos, ventana, tiles, ciclo, proyec, fase);
if ((habitacion == 24) && (enemigos.tipo[0] == 18))
satan (&enemigos, ventana, tiles, ciclo, proyec);
if ((habitacion == 24) && (jean.flags[6] == 5))
cruzados (&enemigos, ventana, tiles, ciclo, habitacion);
dibujarenemigos (&enemigos, ventana, tiles);
}
/* Gestion de disparos */
if ((proyec[0] > 0) && ((habitacion == 17) || (habitacion == 20) || (habitacion == 21) || (habitacion == 22)))
dibujardisparo (proyec, tiles, ventana, &enemigos);