   SDL Framework: XEngine
  Hello, all.I've been working on creating a "framework" or "engine" for SDL called XEngine. I'm thinking it'll just be for my own use to make creating games easier and allow me to concentrate on game design issues and not SDL intricacies. Of course, if anyone finds it interesting or would like to take a look, I'd be glad to let others fiddle with it.Anyway, I just wanted to get some opinions of this "framework" in practice. :-) This is my first structured engine so... well, don't expect too much! Here's a small example program that will run using XEngine.// INCLUDES#include<string>#include "XEngine.h"// ENUMERATIONSenum GAMEMODE{    GM_DEFAULT = -1,    GM_SPLASH,    GM_MENU,    GM_GAME,    GM_HIGHSCORE,    GM_CREDITS,    GM_EXIT};// GLOBAL VARIABLESGAMEMODE  _Mode = GM_SPLASH;XLib::XEngine* _pXE  = NULL;// FUNCTION PROTOTYPESvoid ShowSplash();void ShowMenu();using namespace XLib;using namespace XLib::XInput;int main( int iNumArgs, char* szvArgs[] ){    _pXE = new XEngine; // CREATE XENGINE    XGraphics::XPort Port = {   0, // X POSITION   0, // Y POSITION   400,    // WIDTH   220,    // HEIGHT   0, // HORIZONTAL BORDER   0, // VERTICAL BORDER   -1,// SCROLL SPEED   NULL    // OBJECT    };    XSound::XAudFmt Aud = {   22050,  // SAMPLE RATE   2, // NUMBER OF CHANNELS   256,    // CHUNK SIZE   AUDIO_S16SYS // AUDIO SYSTEM    };    _pXE->Initialize(   Port,   // VIEW PORT   Aud,    // AUDIO SPECIFICATION   "XEngine",   // WINDOW CAPTION   "" // ICON FILE NAME    );    _pXE->Timer()->SetFrameRate( 60 );    XJoystick* pJoy = new XJoystick();    while ( _pXE->Update() == 0 ) // GAME LOOP    {   switch ( _Mode )   {  case GM_SPLASH:  { ShowSplash(); break;  }  case GM_MENU:  { ShowMenu(); break;  }  //...  default:  { break;  }   }   if ( XKeyboard::KeyPressed( SDLK_SPACE ) || pJoy->Button( 0 ) )   {  break;   }    }    delete pJoy;    delete _pXE; // KILL XENGINE    _pXE = NULL;    return 0;}void ShowSplash(){    XGraphics* pXG = _pXE->Graphics();    std::string FrmRt = "Frames/sec: ";    FrmRt += _pXE->Timer()->FrameRateString(); // GET THE FRAME RATE AS A STRING    static XGraphics::XSprite Sprite1(   "Jetpak.gif", // FILE NAME   30, // NUMBER OF FRAMES   400,// FRAME HEIGHT   240,// FRAME WIDTH   1,  // NUMBER OF ROWS   30, // FRAMES PER ROW   0   // FRAME PADDING    );    Sprite1.SetCenter( 0, 0 );    static XGraphics::XSprite Sprite2(   "Target.png", // FILE NAME   1   // NUMBER OF FRAMES    );    pXG->Paint( 0, 0, Sprite1 );    pXG->Text()->Format(   "Akbar.TTF",  // FONT FILE NAME   18, // POINT SIZE   255,// COLOR (RED)   255,// COLOR (GREEN)   255 // COLOR (BLUE)    );    pXG->Text()->SetTypeMode( XGraphics::XText::TM_BLEND );    pXG->Text()->SetAlign( XGraphics::XText::FA_LEFT );    pXG->Paint(   10,  // X POSITION   pXG->Port().Height - 30, // Y POSITION   FrmRt.c_str()  // TEXT (ALSO ACCEPTS std::string)    );    pXG->Text()->SetAlign( XGraphics::XText::FA_CENTER );    pXG->Paint(   pXG->Port().Width / 2,   // X POSITION   0,   // Y POSITION   "XEngine for Simple DirectMedia Layer", // TEXT   10   // DEPTH    );    pXG = NULL;    return;}void ShowMenu(){    XGraphics* pXG = _pXE->Graphics();    //...    pXG = NULL;    return;}//...This is greatly expanded to add comments and reveal the meaning of arguments. It's also quite incomplete, hence the elipsis; I just threw it together as an example. To get started, you need to instanstiate an XEngine object. There can be only one instance of this class in your program and it acts as the central interface to the framework.Almost all of the methods and functions seen in this example are overloaded to take various arguments, including the Initialize() method. I wanted to be able to supply only the arguments that I needed.I passed two special structures into Initialize() to get things rolling, which tell the engine how to setup video and audio. One problem I need to fix here is some minor exposure to SDL: the XAud structure contains an SDL datatype (AUDIO_S16SYS).Input is handled from either functions in the XKeyboard namespace or an XJoystick object. I use both here in the game loop, which tests the Update() method of XEngine. If XEngine runs into a fatal error or detects the user closing the window, it will break the loop.Within the ShowSplash() function, I use the graphics component of XEngine: XGraphics. The XEngine instance you create has several accessor methods which return pointers to each component. To make code shorter, I just stuffed a pointer to the graphics component into a variable within ShowSplash(). Using an XSprite, I load some images and display them with the Paint() method of XGraphics, which is heavily overloaded to draw just about anything with varying arguments. (The depth argument is like a Z-buffer and controls what is drawn before or after what, regardless of the order in which the Paint() method is called.)The text work should be pretty straightforward. The Paint() method accepts std::string objects as well, but I'm having some small problems getting such strings to display properly, so I pass in a C string in this example instead.I plan to include file I/O support, audio routines, and much more; I'm just getting started so far.Here's a screenshot of this example program in action.So... how does this structure look? I hope it's not too confusing. Any input is appreciated. Please remember... I'm just trying to make something useful, but not necessarily "professional". In any case, I'm sure there are some design flaws.Thanks!   