/** \file IsoRenderer.h * Contains the IsoRenderer class, which combines several blitting optimizations into one easy-to-use package. * * @author Vovansim (aka Scorpion) * @version 1.0 * @date June 6, 2003 */ #ifndef ISO_RENDERER_H #define ISO_RENDERER_H #include "SDL/SDL.h" #include "IsoCore.h" /** Rendering function pointer typedef. * * @param destination The surface onto which the tile should be blitted * @param clipRectangle The rectangle by which the blit should be clipped * @param destX The x coordinate of the blit, relative to the surface * @param destY The y coordinate of the blit, relative to the surface * @param mapX The x coordinate of the tile to blit on the map * @param mapY The y coordinate of the tile on the map */ typedef void (*RENDERFN)(SDL_Surface* destination, RECT* clipRectangle, int destX, int destY, int mapX, int mapY); /** * Class IsoRenderer: the class that should be used to render the map and everything on it. Encapsulates all of the functionality required to render the map. Basically, the way it operates is: during the main body of the program loop, the class collects information on which areas of the screen need updating. This is done through several methods: addTile should be called when we know the coordinates of the tile on the map that needs updating (due to animation or whatever else) - the class will then automatically calculate the update rectangle and add it to the update list; addRect should be called when we know the rectangular area of the screen that needs to be updated (due to moving the GUI elements, for instance); finally, scrollFrame should be called when we need to scroll the view. Once all of the operations that might result in the map needing updating have been concluded, one should call the updateFrame method, which goes through the list of update rectangles and blits the areas affected onto the screen. * * @todo Make the data members of the class private, and create the necessary accessors. * @todo Format the comments in emacs. * @todo Comment the functions. * * @author Vovansim (aka Scorpion) * @version 1.0 * @date June 6, 2003 */ class IsoRenderer { public: /////////////////////////////// Data Members ////////////////////////////// /** The back buffer surface, onto which everything will be drawn once the map needs to be updated. */ SDL_Surface* backBuffer; /** The frame buffer surface, onto which everything will be drawn real-time, as it needs updating. */ SDL_Surface* frameBuffer; /** The Tile Plotter used for display. */ IsoTilePlotter* tilePlotter; /** The Tile Walker used in the current game. */ IsoTileWalker* tileWalker; /** The Mouse Map used for the current instance of the game. */ IsoMouseMap* mouseMap; /** The scroller used in the current instance of the game. */ IsoScroller* scroller; /** The list of rectangles on the map that need updating. */ RECT* updateList; /** The number of update rectangles. */ int updateRectCount; /** The index of the next rectangle in the list to update. */ int updateRectIndex; /** The two-dimensional array of the same size as the map that contains the boolean values for each tile depending on whether that tile needs updating or not. */ bool* theMap; /** The width of the map in tiles. */ int mapWidth; /** The height of the map in tiles. */ int mapHeight; /** The extent rectangle of a tile. Used when determining whether any of the neighboring tiles with the one that needs updating need updating as well. */ RECT extentRectangle; /** The pointer to the function that will be used to render one tile. */ RENDERFN renderFunction; ///////////////////////////// End Data Members //////////////////////////// //////////////////////////////// Functions //////////////////////////////// //constructor IsoRenderer(); //destructor virtual ~IsoRenderer(); /** Sets the back buffer used for the game. */ void setBackBuffer(SDL_Surface* surface); /** Sets the frame buffer used for the game. */ void setFrameBuffer(SDL_Surface* surface); /** Sets the IsoTilePlotter used for the current instance of the game. */ void setPlotter(IsoTilePlotter* newPlotter); /** Sets the IsoTileWalker used for the current instance of the game. */ void setWalker(IsoTileWalker* newWalker); /** Sets the IsoMouseMap used for the current instance of the game. */ void setMouseMap(IsoMouseMap* newMouseMap); /** Sets the IsoScroller used for the current instance of the game. */ void setScroller(IsoScroller* newScroller); /** Sets the maximum number of update rectangles to keep track of during the game. */ void setUpdateRectCount(int maxRects); /** Sets the size of the map (in tiles). */ void setMapSize(int newMapWidth, int newMapHeight); /** Sets the rendering function that will be called by the updateFrame method to render the tiles. */ void setRenderFunction(RENDERFN newRenderFunction); /** Sets the maximum extent rectangle of the tile, which is used to determine which neightbor tiles need updating when the addTile method is called. */ void setExtentRect(RECT* newExtent); /** Adds an update rectangle to the list. This method should be called any time a rectangular area of the map needs updating. */ void addRect(RECT* updateRect); /** Adds a tile to the update list. This method should be called any time we know the coordinates of the tile that needs updating. */ void addTile(int newMapX, int newMapY); /** This method should be called whenever we want to scroll the map. The parameter values are in pixels. */ void scrollFrame(int scrollX, int scrollY); /** After the map areas have been marked dirty, it is time to update the map. Call this method to complete the blitting. */ void updateFrame(); ////////////////////////////// End Functions ////////////////////////////// }; #endif//ISO_RENDERER_H