   need more efficiency in SDL
  ok so i understand that software rotations a very slow, but if you cache then thats no longer a problem, it then becomes an issue of how much and how fast your ram is. ok so i cached all 360 rotations of a 32bit depth 32x32 image, that comes out to 11.5 MB i believe, ok so far so good. i have a 1024x1024 screen size and i blit 1024 of the cached images on to the screen and every frame there rotations increase. this is where i think i have problem i guess 1024 images is too much for SDL to handle above 30fps. so my question is, is this too much for SDL to handle above 30fps (well on my proc at least) and if not what can i do to improve my code so that it will handle more.  here is my code: #include <windows.h>#include <stdio.h>#include <string>#include <sstream>#include <SDL/SDL.h>#include <SDL_image.h>#include <SDL_ttf.h>#include <SDL_rotozoom.h>#include <al.h>#include <alc.h>#include <alut.h>extern "C" {#include "lua.h"#include "lualib.h"#include "lauxlib.h"}int FRAMES_PER_SECOND;SDL_Surface *background[360];SDL_Surface *message = NULL;SDL_Surface *screen = NULL;SDL_Surface *Astroids = NULL;SDL_Surface *Backdrop3 = NULL;SDL_Surface *Backdrop2 = NULL;SDL_Surface *Backdrop1 = NULL;SDL_Surface *Background = NULL;TTF_Font *font = NULL;SDL_Event event;SDL_Color textColor = { 255, 255, 255 };FILE * ctt = fopen("CON", "w" );int i,j,k;SDL_Surface *load_image( std::string filename ) {    //The image that's loaded    SDL_Surface* loadedImage = NULL;    //The optimized surface that will be used    SDL_Surface* optimizedImage = NULL;    //Load the image    loadedImage = IMG_Load( filename.c_str() );    //If the image loaded    if ( loadedImage != NULL ) {   //Create an optimized surface   optimizedImage =   SDL_DisplayFormatAlpha( loadedImage );   //Free the old surface   SDL_FreeSurface( loadedImage );   //If the surface was optimized   if ( optimizedImage != NULL ) {  //Color key surface   }    }    //Return the optimized surface    return optimizedImage;}SDL_Surface *load_image2( std::string filename ) {    //The image that's loaded    SDL_Surface* loadedImage = NULL;    //The optimized surface that will be used    SDL_Surface* optimizedImage = NULL;    //Load the image    loadedImage = IMG_Load( filename.c_str() );    //If the image loaded    if ( loadedImage != NULL ) {   //Create an optimized surface   optimizedImage = SDL_DisplayFormat( loadedImage );   //Free the old surface   SDL_FreeSurface( loadedImage );   //If the surface was optimized   if ( optimizedImage != NULL ) {  //Color key surface  SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF ) );   }    }    //Return the optimized surface    return optimizedImage;}int init_sdl(){    SDL_Init( SDL_INIT_VIDEO );    TTF_Init();    SDL_WM_SetCaption( "SDL test", NULL );    freopen( "CON", "w", stdout );    freopen( "con", "w", stderr );    screen = SDL_SetVideoMode(1024,1024, 32, SDL_HWSURFACE|SDL_DOUBLEBUF );    fclose( ctt );    FRAMES_PER_SECOND = 120;}bool load_files(){    Background = load_image("test.png");    Astroids = load_image("backdrop.bmp");    //If there was a problem in loading the background    return true;}void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ){    //Holds offsets    SDL_Rect offset;    //Get offsets    offset.x = x;    offset.y = y;    //Blit    SDL_BlitSurface( source, clip, destination, &offset );}void clean_up(){    //Free the surfaces    delete [] background;    SDL_FreeSurface( message );    //Close the font that was used    TTF_CloseFont( font );    //Quit SDL_ttf    TTF_Quit();    //Quit SDL    SDL_Quit();}class Timer {private:    //The clock time when the timer started    int startTicks;    //The ticks stored when the timer was paused    int pausedTicks;    //The timer status    bool paused;    bool started;public:    //Initializes variables    Timer();    //The various clock actions    void start();    void stop();    void pause();    void unpause();    //Gets the timer's time    int get_ticks();    //Checks the status of the timer    bool is_started();    bool is_paused();};Timer::Timer() {    //Initialize the variables    startTicks = 0;    pausedTicks = 0;    paused = false;    started = false;}void Timer::start() {    //Start the timer    started = true;    //Unpause the timer    paused = false;    //Get the current clock time    startTicks = SDL_GetTicks();}void Timer::stop() {    //Stop the timer    started = false;    //Unpause the timer    paused = false;}void Timer::pause() {    //If the timer is running and isn't already paused    if ( ( started == true ) && ( paused == false ) ) {   //Pause the timer   paused = true;   //Calculate the paused ticks   pausedTicks = SDL_GetTicks() - startTicks;    }}void Timer::unpause() {    //If the timer is paused    if ( paused == true ) {   //Unpause the timer   paused = false;   //Reset the starting ticks   startTicks = SDL_GetTicks() - pausedTicks;   //Reset the paused ticks   pausedTicks = 0;    }}int Timer::get_ticks() {    //If the timer is running    if ( started == true ) {   //If the timer is paused   if ( paused == true ) {  //Return the number of ticks when the timer was paused  return pausedTicks;   } else {  //Return the current time minus the start time  return SDL_GetTicks() - startTicks;   }    }    //If the timer isn't running    return 0;}bool Timer::is_started() {    return started;}bool Timer::is_paused() {    return paused;}void output(char *cout, char *Error) {    fprintf(stdout, cout, Error);    fprintf( stderr, "\n" );}void outputNum(int num) {    std::stringstream test;    test << num;    fprintf(stdout, test.str().c_str());    fprintf( stderr, "\n" );}int main_loop(){    bool quit = false;    char *string;    if ( init_sdl() == false ) {  output( "could not init: \n", SDL_GetError());    }    if ( load_files() == false ) {   output("could not load all files: \n", SDL_GetError());    }    Timer fps;    for(i=0;i<=360;i++) {  outputNum(i);  background = rotozoomSurface(Background, i, 1, 0);   }    i=0;    while ( quit == false ) {   //Start the frame timer   fps.start();   //While there's events to handle   while ( SDL_PollEvent( &event ) ) {  //If the user has Xed out the window  if ( event.type == SDL_QUIT ) { //Quit the program quit = true;  }   }   apply_surface(0, 0, Astroids, screen, NULL);   i++;   if(i==360) {i=0;   }   outputNum(i);   for(j=0;j<=1024;j+=32) {  for(k=0;k<=1024;k+=32) { apply_surface(j, k, background, screen, NULL);  }   }   //Update the screen   if ( SDL_Flip( screen ) == -1 ) {  return 1;   }   //Cap the frame rate   if ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) {  SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );   }    }}int main( int argc, char *argv[] ){   init_sdl();   main_loop();   return FPS;}
Quote:Original post by ishkabibleok so i cached all 360 rotations of a 32bit depth 32x32 image, that comes out to 11.5 MB i believe, ok so far so good.YIKES! Ya know, all day i read people saying "I don't want a slow program so that's my excuse for this premature optimization." It's a little refreshing to read someone not doing that.Have you profiled your code to find out where exactly the slowdown is? (Really, i can't be more helpful than that. I just wanted to give kudos for not worrying about performance.)   ;  As the above poster alluded to the forums are loaded with people asking optimization questions for things that won't even be in the game. It is highly doubtful that the scenario you are currently displaying will actually occur in your game. Get something closer to the end result and you can cut away the fat from there. Any optimizations made now will most likely be irrelevant when the rest of the game is in play.As many others have said before - make it work and then make it fast.This can basically be broken down further by saying - simplify your game to get the basic game concept running. Then work on adding features and optimizations.   ;  kk thanks, i'm actually not really making a game, though i am making a Lua interpreter (that i wanted to be in OpenGL but i'm not quite ready for that) that will be for making games, but really just for me. i got the idea out of pure frustration with OpenGL and Flash, one has a very sharp learning curve and the other is slow as all get out, same test crashes in Flash both AS3 and AS2. but anyway the original idea was to have an OpenGL/OpenAL driven interpreter that would give lua simple and powerful functions for making 2D games. this way you would have the best of both worlds. i have come to figure out two things, one this has been done before many times successfully, two i went little over broad for my skill level, so i decided really just to try to learn some things first with an SDL version and then maybe with more specific  goals in mind go and learn some more about OpenGL and then maybe after how ever long that will take i could make a simple version of what i hoped to make in the first place.   ;  How do you know it's running at 30 FPS?  Your timer code is broken (which leads to broken frame cap code which leads to jumpy animations for anything that relies on 30 fps).And yes, you could make rendering more efficient still.  Less blits is better, so you could create an intermediate surface to render a portion of the pattern to and then tile that across the screen to reduce # blits from 1,024 to as a few as 68.  But then we run into the question of will every game have a background filled with rotating sprites?  Is this level of optimization necessary?  You won't know until you've coded up the other parts and tested it.   ;Quote:Original post by ishkabiblebut anyway the original idea was to have an OpenGL/OpenAL driven interpreter that would give lua simple and powerful functions for making 2D games. this way you would have the best of both worlds. Have you looked at LOVE, it sounds pretty much what you want. (although the website seems to be down atm, so heres the sourceforge site  http://sourceforge.net/projects/love/ )