Headers/SWCommonHeaders.h File Reference

common macros, constants, and stuff, used throughout More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <SDL/SDL.h>
#include <stdexcept>

Classes

struct  SWPoint
 a Point (h,v) More...
struct  SWRect
 a Rect (l,t,r,b) More...
struct  SWRGBColor
 a Color (r,g,b) More...
struct  DrawDataRec
 Draw data structure. More...
class  TError
 CLASS TError, wrapping SWError. More...

Defines

#define SW_DEBUG   0
 Change this to 1 for debugging builds. [use 1/0, not true/false].
#define SW_ASSERT_ON   1
 Change this to 0 to turn assertions off. [use 1/0, not true/false].
#define SW_NAMESPACE_BEGIN
#define SW_NAMESPACE_END
#define SW_FUNC
 Used for setting linking type.
#define SW_ASSERT(condition)
#define SW_UNUSED(var)   (void) var
 Avoids warnings, for unused parameters.
#define SW_ABS(x)   ((x) < (0) ? -(x) : (x))
#define SW_MIN(a, b)   ((a) < (b) ? (a) : (b))
#define SW_MAX(a, b)   ((a) > (b) ? (a) : (b))
#define SW_RECT_WIDTH(r)   ((r).right - (r).left)
#define SW_RECT_HEIGHT(r)   ((r).bottom - (r).top)
#define SW_TOP_LEFT(r)   (((SWPoint *) &(r))[0])
#define SW_BOT_RIGHT(r)   (((SWPoint *) &(r))[1])
#define SW_SET_RECT(theRect, myleft, mytop, myright, mybottom)
 Set the fields of the struct (beware of macro side effects).
#define SW_CONVERT_SW_TO_SDL_RECT(swRect, sdlRect)
 Convert SW to SDL rect (beware of macro side effects).
#define SW_CONVERT_SDL_TO_SW_RECT(sdlRect, swRect)
 Convert SDL to SW rect (beware of macro side effects).
#define SW_OFFSET_RECT(theRect, deltaH, deltaV)
 Offset the fields of the struct (beware of macro side effects).
#define SW_CENTER_RECT(centerThis, insideThis)
 Centers one rect inside another.
#define SW_INSET_RECT(theRect, insetX, insetY)
 Offset the fields of the struct (beware of macro side effects).
#define SW_POINT_IS_IN_RECT(x, y, rect)
 Checks whether x,y is inside rect.
#define SW_RECT_IS_IN_RECT(rectA, rectB)
 Checks whether rectA is inside rectB.
#define SW_CLIP_RECT(rectA, rectB)
 Clips rectA with rectB.
#define SW_CLIP_DST_AND_SRC_RECT(dstRect, srcRect, clipRect)
 Clips dstRect and srcRect with clipRect.
#define SW_UNION_RECT(dstRect, srcRect)
#define SW_CONVERT_SW_TO_SDL_COLOR(swColor, sdlColor)
 Convert SW to SDL color (beware of macro side effects).
#define SW_CONVERT_SDL_TO_SW_COLOR(sdlColor, swColor)
 Convert SDL to SW color (beware of macro side effects).
#define SW_COLLISION_RECT_TOP(spriteP)   (spriteP->destFrameRect.top + spriteP->curFrameP->collisionInset.top)
#define SW_COLLISION_RECT_LEFT(spriteP)   (spriteP->destFrameRect.left + spriteP->curFrameP->collisionInset.left)
#define SW_COLLISION_RECT_BOTTOM(spriteP)   (spriteP->destFrameRect.bottom - spriteP->curFrameP->collisionInset.bottom)
#define SW_COLLISION_RECT_RIGHT(spriteP)   (spriteP->destFrameRect.right - spriteP->curFrameP->collisionInset.right)

Typedefs

typedef float SWMovementType
 The precision of each sprite's movement.
typedef SpriteWorldRec SpriteWorldRec
typedef SpriteWorldRecSpriteWorldPtr
typedef TileMapStruct TileMapStruct
typedef TileMapStructTileMapStructPtr
typedef SpriteLayerRec SpriteLayerRec
typedef SpriteLayerRecSpriteLayerPtr
typedef SpriteRec SpriteRec
typedef SpriteRecSpritePtr
typedef FrameRec FrameRec
typedef FrameRecFramePtr
typedef unsigned char SWBoolean
 A Boolean value, of either true or false.
typedef SWPoint SWPoint
typedef SWPointSWPointPtr
typedef SWRect SWRect
typedef SWRectSWRectPtr
typedef SWRGBColor SWRGBColor
typedef SWRGBColorSWRGBColorPtr
typedef DrawDataRec DrawDataRec
typedef DrawDataRecDrawDataPtr
typedef enum SWError SWError
 Error value integer, zero if no error.

Enumerations

enum  SWError {
  kNoError = 0, kSystemTooOldErr = 100, kMaxFramesErr = 101, kInvalidFramesIndexErr = 102,
  kNotCWindowErr = 103, kNilParameterErr = 104, kWrongDepthErr = 105, kWrongMaskErr = 106,
  kOutOfRangeErr = 107, kTilingNotInitialized = 108, kTilingAlreadyInitialized = 109, kNullTileMapErr = 110,
  kTileMapNotLockedErr = 111, kAlreadyCalledErr = 112, kSpriteNotCompiledErr = 113, kBadParameterErr = 114,
  kSpriteAlreadyInLayer = 115, kNilFrameErr = 116, kNotLockedErr = 117, k68kOnlyErr = 118,
  kNotInCarbonErr = 119, kWrongDrawProcTypeErr = 120, kMemoryAllocationError = 200, kSpriteCreationError = 201,
  kFrameCreationError = 202, kFailedToInitSDL = 300, kSDLSetVideoMode = 301, kSDLCreateSurface = 302,
  kSDLCreateSurfaceFromFile = 303, kSDLBlitError = 304, KSDLBlitVideoMemoryError = 305, kSDLSurfaceConversion = 306,
  kSDLSetAlpha = 307, kUnknownError = 999
}
 sprite world error constants More...

Functions

void SW_CONVERT_SW_TO_SDL_RECT (SWRect swRect, SDL_Rect sdlRect)
void SW_CONVERT_SDL_TO_SW_RECT (SDL_Rect sdlRect, SWRect swRect)
void SW_CONVERT_SW_TO_SDL_COLOR (SWRGBColor swColor, SDL_Color sdlColor)
void SW_CONVERT_SDL_TO_SW_COLOR (SDL_Color sdlColor, SWRGBColor swColor)

Variables

SW_NAMESPACE_END typedef void(* AssertFailProcPtr )(char *filename, char *functionname, int lineNum)
AssertFailProcPtr gSWAssertFailProc


Detailed Description

common macros, constants, and stuff, used throughout


Define Documentation

#define SW_ABS  )     ((x) < (0) ? -(x) : (x))
 

#define SW_ASSERT condition   ) 
 

Value:

if ( !(condition) ) \
        gSWAssertFailProc( __FILE__, "unknown", __LINE__ )

#define SW_ASSERT_ON   1
 

Change this to 0 to turn assertions off. [use 1/0, not true/false].

#define SW_BOT_RIGHT  )     (((SWPoint *) &(r))[1])
 

#define SW_CENTER_RECT centerThis,
insideThis   ) 
 

Value:

{ \
    SW_OFFSET_RECT( centerThis, \
        (insideThis.left + insideThis.right - centerThis.left - centerThis.right) >> 1, \
        (insideThis.top + insideThis.bottom - centerThis.top - centerThis.bottom) >>1 ); \
}
Centers one rect inside another.

#define SW_CLIP_DST_AND_SRC_RECT dstRect,
srcRect,
clipRect   ) 
 

Value:

if ((dstRect).top < (clipRect).top) \
    { \
        (srcRect).top += (clipRect).top - (dstRect).top; \
        (dstRect).top = (clipRect).top; \
    } \
    if ((dstRect).bottom > (clipRect).bottom) \
    { \
        (srcRect).bottom += (clipRect).bottom - (dstRect).bottom; \
        (dstRect).bottom = (clipRect).bottom; \
    } \
    if (dstRect.left < clipRect.left) \
    { \
        (srcRect).left += (clipRect).left - (dstRect).left; \
        (dstRect).left = (clipRect).left; \
    } \
    if ((dstRect).right > (clipRect).right) \
    { \
        (srcRect).right += (clipRect).right - (dstRect).right; \
        (dstRect).right = (clipRect).right; \
    }
Clips dstRect and srcRect with clipRect.

#define SW_CLIP_RECT rectA,
rectB   ) 
 

Value:

if ((rectA).top < (rectB).top)  \
        (rectA).top = (rectB).top;  \
    if ((rectA).bottom > (rectB).bottom) \
        (rectA).bottom = (rectB).bottom; \
    if ((rectA).left < (rectB).left) \
        (rectA).left = (rectB).left; \
    if ((rectA).right > (rectB).right) \
        (rectA).right = (rectB).right;
Clips rectA with rectB.

#define SW_COLLISION_RECT_BOTTOM spriteP   )     (spriteP->destFrameRect.bottom - spriteP->curFrameP->collisionInset.bottom)
 

#define SW_COLLISION_RECT_LEFT spriteP   )     (spriteP->destFrameRect.left + spriteP->curFrameP->collisionInset.left)
 

#define SW_COLLISION_RECT_RIGHT spriteP   )     (spriteP->destFrameRect.right - spriteP->curFrameP->collisionInset.right)
 

#define SW_COLLISION_RECT_TOP spriteP   )     (spriteP->destFrameRect.top + spriteP->curFrameP->collisionInset.top)
 

#define SW_CONVERT_SDL_TO_SW_COLOR sdlColor,
swColor   ) 
 

Value:

{ \
    (swColor).red = (sdlColor).r << 8; \
    (swColor).green = (sdlColor).g << 8; \
    (swColor).blue = (sdlColor).b << 8; \
}
Convert SDL to SW color (beware of macro side effects).

#define SW_CONVERT_SDL_TO_SW_RECT sdlRect,
swRect   ) 
 

Value:

{ \
    (swRect).left = (sdlRect).x; \
    (swRect).top = (sdlRect).y; \
    (swRect).right = (swRect).x + (sdlRect).w; \
    (swRect).bottom = (swRect).y + (sdlRect).h; \
}
Convert SDL to SW rect (beware of macro side effects).

#define SW_CONVERT_SW_TO_SDL_COLOR swColor,
sdlColor   ) 
 

Value:

{ \
    (sdlColor).r = (swColor).red >> 8; \
    (sdlColor).g = (swColor).green >> 8; \
    (sdlColor).b = (swColor).blue >> 8; \
}
Convert SW to SDL color (beware of macro side effects).

#define SW_CONVERT_SW_TO_SDL_RECT swRect,
sdlRect   ) 
 

Value:

{ \
    (sdlRect).x = (swRect).left; \
    (sdlRect).y = (swRect).top; \
    (sdlRect).w = (swRect).right - (swRect).left; \
    (sdlRect).h = (swRect).bottom - (swRect).top; \
}
Convert SW to SDL rect (beware of macro side effects).

#define SW_DEBUG   0
 

Change this to 1 for debugging builds. [use 1/0, not true/false].

#define SW_FUNC
 

Used for setting linking type.

#define SW_INSET_RECT theRect,
insetX,
insetY   ) 
 

Value:

{ \
    (theRect).top += insetY; \
    (theRect).left += insetX; \
    (theRect).bottom -= insetY; \
    (theRect).right -= insetX; \
}
Offset the fields of the struct (beware of macro side effects).

#define SW_MAX a,
 )     ((a) > (b) ? (a) : (b))
 

#define SW_MIN a,
 )     ((a) < (b) ? (a) : (b))
 

#define SW_NAMESPACE_BEGIN
 

#define SW_NAMESPACE_END
 

#define SW_OFFSET_RECT theRect,
deltaH,
deltaV   ) 
 

Value:

{ \
    (theRect).top += deltaV; \
    (theRect).left += deltaH; \
    (theRect).bottom += deltaV; \
    (theRect).right += deltaH; \
}
Offset the fields of the struct (beware of macro side effects).

#define SW_POINT_IS_IN_RECT x,
y,
rect   ) 
 

Value:

( (x >= (rect).left) && \
      (x <= (rect).right) &&    \
      (y >= (rect).top) &&  \
      (y <= (rect).bottom) )
Checks whether x,y is inside rect.

#define SW_RECT_HEIGHT  )     ((r).bottom - (r).top)
 

#define SW_RECT_IS_IN_RECT rectA,
rectB   ) 
 

Value:

( ((rectA).top < (rectB).bottom) && \
      ((rectA).bottom > (rectB).top) && \
      ((rectA).left < (rectB).right) && \
      ((rectA).right > (rectB).left) )
Checks whether rectA is inside rectB.

#define SW_RECT_WIDTH  )     ((r).right - (r).left)
 

#define SW_SET_RECT theRect,
myleft,
mytop,
myright,
mybottom   ) 
 

Value:

{ \
    (theRect).top = mytop; \
    (theRect).left = myleft; \
    (theRect).bottom = mybottom; \
    (theRect).right = myright; \
}
Set the fields of the struct (beware of macro side effects).

#define SW_TOP_LEFT  )     (((SWPoint *) &(r))[0])
 

#define SW_UNION_RECT dstRect,
srcRect   ) 
 

Value:

{   \
    (dstRect).top = SW_MIN((dstRect).top, (srcRect).top);   \
    (dstRect).left = SW_MIN((dstRect).left,(srcRect).left); \
    (dstRect).bottom = SW_MAX((dstRect).bottom, (srcRect).bottom);  \
    (dstRect).right = SW_MAX((dstRect).right, (srcRect).right); \
}

#define SW_UNUSED var   )     (void) var
 

Avoids warnings, for unused parameters.


Typedef Documentation

typedef struct DrawDataRec * DrawDataPtr
 

typedef struct DrawDataRec DrawDataRec
 

typedef struct FrameRec * FramePtr
 

typedef struct FrameRec FrameRec
 

typedef struct SpriteLayerRec * SpriteLayerPtr
 

typedef struct SpriteLayerRec SpriteLayerRec
 

typedef struct SpriteRec * SpritePtr
 

typedef struct SpriteRec SpriteRec
 

typedef struct SpriteWorldRec * SpriteWorldPtr
 

typedef struct SpriteWorldRec SpriteWorldRec
 

typedef unsigned char SWBoolean
 

A Boolean value, of either true or false.

typedef enum SWError SWError
 

Error value integer, zero if no error.

typedef float SWMovementType
 

The precision of each sprite's movement.

(Change to "short" if you don't need floating-point precision, and need the speed-up.)

typedef struct SWPoint SWPoint
 

typedef struct SWPoint * SWPointPtr
 

typedef struct SWRect SWRect
 

typedef struct SWRect * SWRectPtr
 

typedef struct SWRGBColor SWRGBColor
 

typedef struct SWRGBColor * SWRGBColorPtr
 

typedef struct TileMapStruct TileMapStruct
 

typedef struct TileMapStruct * TileMapStructPtr
 


Enumeration Type Documentation

enum SWError
 

sprite world error constants

Enumerator:
kNoError  no error at all
kSystemTooOldErr  < System 7.0
kMaxFramesErr  attempt to exceed maximum number of frames for a sprite
kInvalidFramesIndexErr  frame index out of range
kNotCWindowErr  attempt to make a SpriteWorld from non-color WindowPtr
kNilParameterErr  NULL SpritePtr, FramePtr, etc.
kWrongDepthErr  invalid pixel size for attempted function
kWrongMaskErr  invalid mask type for attempted function
kOutOfRangeErr  tileID, tileMap, or other value out of bounds
kTilingNotInitialized  tiling hasn't been initialized
kTilingAlreadyInitialized  tiling already initialized; can't be initialized again
kNullTileMapErr  no TileMap has ever been created/loaded
kTileMapNotLockedErr  the TileMap is not locked and can't be used until it is
kAlreadyCalledErr  the function was already called and can't be called again
kSpriteNotCompiledErr  the sprite must be compiled before drawProc can be set
kBadParameterErr  a parameter that was passed to the function is invalid
kSpriteAlreadyInLayer  the Sprite is already in a Layer, and can't be added to another
kNilFrameErr  the Frame this function acts on is NULL
kNotLockedErr  a structure that must be locked is not
k68kOnlyErr  can only be used from 68k code
kNotInCarbonErr  not supported for Carbon builds
kWrongDrawProcTypeErr  hardware drawprocs can only be used for hardware
kMemoryAllocationError  problem allocationg memory
kSpriteCreationError  could not fully create the sprite
kFrameCreationError  problem creating frame
kFailedToInitSDL  could not init the sdl lib
kSDLSetVideoMode 
kSDLCreateSurface  could not create a surface
kSDLCreateSurfaceFromFile  could not create surface from file
kSDLBlitError  could not blit surfaces, maybe they are locked?
KSDLBlitVideoMemoryError  sdl_blit returned -2 indicating texture is out of video memory
kSDLSurfaceConversion  SDL_DisplayFormat failed to convert the surface.
kSDLSetAlpha  SDL_SetAlpha failed to set the alpha channel.
kUnknownError 


Function Documentation

void SW_CONVERT_SDL_TO_SW_COLOR SDL_Color  sdlColor,
SWRGBColor  swColor
 

void SW_CONVERT_SDL_TO_SW_RECT SDL_Rect  sdlRect,
SWRect  swRect
 

void SW_CONVERT_SW_TO_SDL_COLOR SWRGBColor  swColor,
SDL_Color  sdlColor
 

void SW_CONVERT_SW_TO_SDL_RECT SWRect  swRect,
SDL_Rect  sdlRect
 


Variable Documentation

SW_NAMESPACE_END typedef void(* AssertFailProcPtr)(char *filename, char *functionname, int lineNum)
 

AssertFailProcPtr gSWAssertFailProc
 


Generated on Sun Jun 18 14:11:04 2006 for SpriteWorld X by  doxygen 1.4.6