RSRC

namespace RSRC

Everything related to loading and mantaining a resource is in this namespace

Summary
RSRCEverything related to loading and mantaining a resource is in this namespace
Functions
InitInitializes the resource interfaces to use the specified mode
ShutdownShuts down the resource interface
CompleteUnloadUnloads all resources regardless of flags.
ResetUnloadUnloads all resource that have RSRC_RESET set.
ReloadReloads all resources that have are in state RSRC_STATE_PENDING.
Enumerations
RSRC_INTERFACE_TYPIdentifies what kind of interface a resource is using.
RSRC_FLAG_TYPUsed by the Resource to describe the needs of the lock or the resource
RSRC_STATE_TYPDescribes the state of a resource
RSRC_TYPE_TYPIdentifies that type of Resource that was created.
IMAGE_FLAGS_TYPHelps specify loading options for IMAGE_OPTIONS_TYP
VERTEX_TYPE_TYPHelps describe a VertexBufferResource.
Types
VERTEX_OPTIONSAlias for VERTEX_OPTIONS_TYP
VERTEX_OPTIONS_PTRAlias for a pointer to a VERTEX_OPTIONS_TYP
RSRC_LOCKINFOAlias for RSRC_LOCKINFO_TYP
RSRC_LOCKINFO_PTRAlias for a pointer to RSRC_LOCKINFO_TYP
IMAGE_OPTIONSAlias for IMAGE_OPTIONS_TYP
IMAGE_OPTIONS_PTRAlias for a pointer to IMAGE_OPTIONS_TYP
RSRC_LOCKINFO_TYPThis structure is used to request and to process locks made on resources.
Variables
FlagsDWORD This is a RSRC::RSRC_FLAG_TYP
pDestVOID* Points to the beginning of the memory block
PitchINT The amount of bytes between “lines” in the Resource
widthINT Width of the Resource
StrideINT The amount of bytes between objects (ie.
SizeINT Size of the resource in number of strides
ValidINT Wether the lock is valid or not
heightINT Height of the resource.
bppINT The bits per pxiel.
IMAGE_OPTIONS_TYPUsed to describe how to open and load an image from disk.
Variables
Image_FlagsDWORD RSRC::IMAGE_FLAGS_TYP that help setup options for loading the image
pFilenamechar* Null terminated filename to load
LoadRectRECT Size of the image or surface to create
SrcKeyColorDWORD Color for SrcKeying
BppINT Specifies a different bpp to convert the image to
numMipMapsINT Specifies the mipmap level if MIPMAP flag is set (0 for maximum)
LoadFunc*(LoadFunc)(RSRC::RSRC_LOCKINFO_PTR) Pointer to a function to load data to.
VERTEX_OPTIONS_TYPStructure used to create a VertexBufferResource
Variables
SizeINT The size of the vertex buffer
Vertex_TypeDWORD RSRC::VERTEX_TYPE_TYP used to descrive the vertex buffer
ObjectOur abstact geralized object class.
ResourceOur top level resource class.
Constructors
ResourceCreates an empty resource class.
ResourceCopy Constructor.
ResourceAssignment Constructor.
Destructor
~ResourceDetaches itself with the Object.
Virtual Object Functions
AquireAndLoadThe Object its attached to aquires any needed interfaces and loads the data into memory based on the initialization settings.
LockLocks a resource and locks the objects mutex.
UnlockUnlocks a resource that was Lock’d.
UnloadAndReleaseUnloads the Object the resource is pointing to from memory and releases it’s interfaces.
DetachDetaches itself from the Object it was pointing to.
TestStateTests the state of the Object and copies over all its state information into the resource.
Accessor Functions
getFlagsGets the current flags of the resource.
getStateGets the current state of the resource.
getTypeGets the current type of the object the resource is connected to.
SurfaceResourceAllows access to creation of SurfaceResources and provides the neccessary functions to create SurfaceObjects of various types.
Creation Functions
CreateFromFileUses provided options to create an object.
CreateFromFileUses the filename to create a generalized IMAGE_OPTIONS_TYP and runs CreateFromFile with the created settings.
CreateBlankSurfaceUses parameters to create a blank surface and optionally allows to fill the surface using a fuction pointer.
VertexBufferResourceInherits from Resource.
Creation Functions
CreateCreates a vertex buffer with the specified parameters

Functions

Init

int Init(MODE_TYP Interface)

Initializes the resource interfaces to use the specified mode

Parameters

InterfaceMODE_TYP Specifies what type of interface to use

Returns

False if succeeded, or false otherwise.

Shutdown

void Shutdown()

Shuts down the resource interface

CompleteUnload

void CompleteUnload()

Unloads all resources regardless of flags.  Puts them into state RSRC_STATE_PENDING

ResetUnload

void ResetUnload()

Unloads all resource that have RSRC_RESET set.  Puts them into state RSRC_STATE_PENDING

Reload

int Reload()

Reloads all resources that have are in state RSRC_STATE_PENDING.

Returns

False if successful, error code otherwise.

Enumerations

RSRC_INTERFACE_TYP

Identifies what kind of interface a resource is using.  This is useful when users of the resource have a special need to know.  It does not change during the life of the resource

RSRC_INVALIDThis is the default type to signal errors if it stays at this value
RSRC_D3DIndicates that this resource is using the D3DInterface
RSRC_DDRAWIndicates that this resource is using the DDrawInterface
RSRC_GDIIndicates that this resource is using the GDIInterface
RSRC_MANUALIndicates that this resource is not using any interface and created manually

RSRC_FLAG_TYP

Used by the Resource to describe the needs of the lock or the resource

RSRC_SYSMEMCreate the resource in system memory
RSRC_VIDMEMCreate the resource in video(device) memory
RSRC_STICKYDo not unload the resource until Shutdown
RSRC_WRITEONLYWill not need to read the resource
RSRC_READONLYWill not need to write to the resource
RSRC_SOFTWAREDo not use hardware resources
RSRC_RESETSet by object to signal a reload required at device reset
RSRC_RESIZESet by object to signal a resize needs to be reset and resized
RSRC_NOOVERWRITEData will be added, but existing data will not be touched.  Only implemented for D3DVertexBuffers.  No manual implementation is attempted.
RSRC_DISCARDData will be completely written over, existing data should be used then discarded when its been used.  Only implemented for D3DVertexBuffers.  No manual implementation is attempted.
RSRC_RNDR_LOCKUses the RSRC_LOCKINFO_TYP::pDest to point to a shared_ptr to the actual resource.  GDI::Graphic, DirectDrawSurface7, etc.  Manual objects will still fill in the structure normally.  Implies RSRC_READONLY and will allow multiple locks.

At the moment, only the VertexBuffer in D3D Mode can use RSRC_NOOVERWRITE and RSRC_DISCARD.  I would like to try implementing it into the others, but... its tricky since I didn’t anticipate the need.

RSRC_STATE_TYP

Describes the state of a resource

RSRC_STATE_CLEANObject has not been initialized
RSRC_STATE_ERRORObject is in an errored state
RSRC_STATE_DESTROYObject has been unloaded and awaits destruction
RSRC_STATE_INITObject has been initialized
RSRC_STATE_PENDINGObject has been unloaded by reset and awaits reload
RSRC_STATE_LOADObject is loaded and ready
RSRC_STATE_LOCKObject is locked by a resource

RSRC_TYPE_TYP

Identifies that type of Resource that was created.

RSRC_TYPE_NONEIndicates that the resource has no object created
RSRC_TYPE_SURFACEIndicates that the resource is a SurfaceResource
RSRC_TYPE_VERTEXBUFFERIndicates that the resource is a VertexBufferResource
RSRC_TYPE_DATABUFFERIndicates that the resource is a <DataBufferResource>
RSRC_TYPE_RENDERTARGETIndicates that the resource is a <RenderTargetResource>

IMAGE_FLAGS_TYP

Helps specify loading options for IMAGE_OPTIONS_TYP

IMAGE_FLAG_OVERRIDEThis flag specifies that the file settings should be ignored and only options that are set in these flags should be used Without this setting, these flags are used IN ADDITION TO the file settings from the image.
IMAGE_FLAG_RECTUses the RECT to specify a specific size for the image or blank surface
IMAGE_FLAG_SRCKEYUses the Src Key Color for a srckey
IMAGE_FLAG_ALPHAUsed to specify if a alpha enabled surface is needed or not
IMAGE_FLAG_NEWBPPUsed to create the new surface with a different bpp than back buffer
IMAGE_FLAG_STRETCHTells the load function that its OK to stretch to preserve texture coords.  TODO: A decision will need to be made wether the rest of the program will care TODO: I would imagine that the renderer could just convert using the total size TODO: of the surface and the needed size of the texture.
IMAGE_FLAG_MIPMAPSpecifies that mipmaps should be generated TODO: Only D3D for now.

VERTEX_TYPE_TYP

Helps describe a VertexBufferResource.  It specifies the details of the vertices.

VERTEX_3D and VERTEX_NORMAL cannot be used with VERTEX_2D

VERTEX_2DSpecifies pre-transformed vertices
VERTEX_3DSpecifies untransformed vertices.  Cannot be used with VERTEX_2D
VERTEX_NORMALSpecifies that a normal will be used.  Cannot be used with VERTEX_2D
VERTEX_TEXTURESpecifies texture coordinates
VERTEX_DIFFUSESpecifies diffuse information
VERTEX_SPECULARSpecifies specular information

Types

VERTEX_OPTIONS

VERTEX_OPTIONS_PTR

Alias for a pointer to a VERTEX_OPTIONS_TYP

RSRC_LOCKINFO

RSRC_LOCKINFO_PTR

Alias for a pointer to RSRC_LOCKINFO_TYP

IMAGE_OPTIONS

IMAGE_OPTIONS_PTR

Alias for a pointer to IMAGE_OPTIONS_TYP

RSRC_LOCKINFO_TYP

typedef struct RSRC_LOCKINFO_TYP

This structure is used to request and to process locks made on resources.

Pitch and width are mutually exclusive with Stride and Size

Union {
    struct { Pitch, width };
    struct { Stride, Size };
};
Summary
Variables
FlagsDWORD This is a RSRC::RSRC_FLAG_TYP
pDestVOID* Points to the beginning of the memory block
PitchINT The amount of bytes between “lines” in the Resource
widthINT Width of the Resource
StrideINT The amount of bytes between objects (ie.
SizeINT Size of the resource in number of strides
ValidINT Wether the lock is valid or not
heightINT Height of the resource.
bppINT The bits per pxiel.

Variables

Flags

DWORD Flags

DWORD This is a RSRC::RSRC_FLAG_TYP

pDest

void* pDest

VOID* Points to the beginning of the memory block

Pitch

int Pitch

INT The amount of bytes between “lines” in the Resource

width

int width

INT Width of the Resource

Stride

int Stride

INT The amount of bytes between objects (ie. vertices)

Size

int Size

INT Size of the resource in number of strides

Valid

int Valid

INT Wether the lock is valid or not

height

int height

INT Height of the resource.  Not always used and should be set to 0 when not needed.

bpp

int bpp

INT The bits per pxiel.  Not always used and should be set to 0 when not needed.

IMAGE_OPTIONS_TYP

typedef struct IMAGE_OPTIONS_TYP

Used to describe how to open and load an image from disk.

Summary
Variables
Image_FlagsDWORD RSRC::IMAGE_FLAGS_TYP that help setup options for loading the image
pFilenamechar* Null terminated filename to load
LoadRectRECT Size of the image or surface to create
SrcKeyColorDWORD Color for SrcKeying
BppINT Specifies a different bpp to convert the image to
numMipMapsINT Specifies the mipmap level if MIPMAP flag is set (0 for maximum)
LoadFunc*(LoadFunc)(RSRC::RSRC_LOCKINFO_PTR) Pointer to a function to load data to.

Variables

Image_Flags

DWORD Image_Flags

DWORD RSRC::IMAGE_FLAGS_TYP that help setup options for loading the image

pFilename

char *pFilename

char* Null terminated filename to load

LoadRect

RECT LoadRect

RECT Size of the image or surface to create

SrcKeyColor

DWORD SrcKeyColor

DWORD Color for SrcKeying

Bpp

int Bpp

INT Specifies a different bpp to convert the image to

numMipMaps

int numMipMaps

INT Specifies the mipmap level if MIPMAP flag is set (0 for maximum)

LoadFunc

int (*LoadFunc)(RSRC_LOCKINFO_PTR)

*(LoadFunc)(RSRC::RSRC_LOCKINFO_PTR) Pointer to a function to load data to.

VERTEX_OPTIONS_TYP

typedef struct VERTEX_OPTIONS_TYP

Structure used to create a VertexBufferResource

Summary
Variables
SizeINT The size of the vertex buffer
Vertex_TypeDWORD RSRC::VERTEX_TYPE_TYP used to descrive the vertex buffer

Variables

Size

int Size

INT The size of the vertex buffer

Vertex_Type

DWORD Vertex_Type

DWORD RSRC::VERTEX_TYPE_TYP used to descrive the vertex buffer

Object

class Object

Our abstact geralized object class.  Should not be created by anyone using the Resource Interface.  Only used by the Resource classes themselves.

Resource

class Resource

Our top level resource class.  It is used as an interface for the object classes and should be the only way users of the resource namespace use and create objects.

Summary
Constructors
ResourceCreates an empty resource class.
ResourceCopy Constructor.
ResourceAssignment Constructor.
Destructor
~ResourceDetaches itself with the Object.
Virtual Object Functions
AquireAndLoadThe Object its attached to aquires any needed interfaces and loads the data into memory based on the initialization settings.
LockLocks a resource and locks the objects mutex.
UnlockUnlocks a resource that was Lock’d.
UnloadAndReleaseUnloads the Object the resource is pointing to from memory and releases it’s interfaces.
DetachDetaches itself from the Object it was pointing to.
TestStateTests the state of the Object and copies over all its state information into the resource.
Accessor Functions
getFlagsGets the current flags of the resource.
getStateGets the current state of the resource.
getTypeGets the current type of the object the resource is connected to.

Constructors

Resource

Resource(
   
) : Flags(0), State(RSRC_STATE_CLEAN), Type(RSRC_TYPE_NONE), pObject(NULL)

Creates an empty resource class.  Fully valid, but connected to nothing

Resource

Resource(const Resource &R2)

Copy Constructor.  Clones the resource that its told to copy.  Adds to the objects reference count if an object exists.

Resource

Resource& operator=(const Resource &R2)

Assignment Constructor.  Copies the resource that its told to copy.  Adds to the objects reference count if an object exists.

Destructor

~Resource

virtual ~Resource()

Detaches itself with the Object.

Virtual Object Functions

AquireAndLoad

int AquireAndLoad()

The Object its attached to aquires any needed interfaces and loads the data into memory based on the initialization settings.  Puts the resource and the object into state RSRC::RSRC_STATE_LOAD.

Returns

False if successful, error code otherwise.

Lock

int Lock(RSRC_LOCKINFO_PTR LockInfo)

Locks a resource and locks the objects mutex.  Puts the resource and the object into state RSRC::RSRC_STATE_LOCK

Parameters

LockInfoRSRC::RSRC_LOCKINFO_PTR Describes how to lock them resource as well as provide information about how to access the data after a successful lock.  Check the RSRC_LOCKINFO_TYP::Valid flag to see if the data is valid or not.

Return

False if successful, error code otherwise.

Unlock

void Unlock()

Unlocks a resource that was Lock’d.  Puts the resource and the object into state RSRC::RSRC_STATE_LOAD

UnloadAndRelease

void UnloadAndRelease()

Unloads the Object the resource is pointing to from memory and releases it’s interfaces.  Puts the object into RSRC::RSRC_STATE_INIT

Detach

void Detach()

Detaches itself from the Object it was pointing to.  Will put the resource into RSRC::RSRC_STATE_CLEAN, while the Object determines wether to destroy itself based on how many references it still has to itself

TestState

RSRC_STATE_TYP TestState()

Tests the state of the Object and copies over all its state information into the resource.  Not all objects implement TestState, in those case it will return the current RSRC::RSRC_STATE_TYP

Accessor Functions

getFlags

DWORD getFlags()

Gets the current flags of the resource.  Note: Does not poll the object for current flag information.  Use TestState for that purpose.

Returns

DWORD RSRC::RSRC_FLAG_TYP describing the object

getState

RSRC_STATE_TYP getState()

Gets the current state of the resource.  Note: Does not poll the object for current state information.  Use TestState for that purpose.

Returns

RSRC::RSRC_STATE_TYP with the current state of the object

getType

RSRC_TYPE_TYP getType()

Gets the current type of the object the resource is connected to.  Note: Does not poll the object for the current type.  Use TestState for that purpose.

Returns

RSRC::RSRC_TYPE_TYP with the current type of the object.

SurfaceResource

class SurfaceResource : public Resource

Allows access to creation of SurfaceResources and provides the neccessary functions to create SurfaceObjects of various types.  Inherits from Resource.

|----------|      |-----------------|
| Resource |<-----| SurfaceResource |
|----------|      |-----------------|
Summary
Creation Functions
CreateFromFileUses provided options to create an object.
CreateFromFileUses the filename to create a generalized IMAGE_OPTIONS_TYP and runs CreateFromFile with the created settings.
CreateBlankSurfaceUses parameters to create a blank surface and optionally allows to fill the surface using a fuction pointer.

Creation Functions

CreateFromFile

int CreateFromFile(IMAGE_OPTIONS_PTR Options,
DWORD RSrc_Flags)

Uses provided options to create an object.  Runs Initialize for the object and puts the resource into RSRC::RSRC_STATE_INIT if there are no errors

Parameters

Options<IMAGE_OPTIONS_PTR> Describes how to load the file
RSrc_FlagsDWORD Describes how to load the file into memory

Returns

False if successful, error code otherwise

CreateFromFile

int CreateFromFile(char *filename,
DWORD RSrc_Flags)

Uses the filename to create a generalized IMAGE_OPTIONS_TYP and runs CreateFromFile with the created settings.

Parameters

filenameCHAR* Null terminated filename to load into an object.  Settings are completely determined by default assumptions and file settings
RSrc_FlagsDWORD Describes how to load the file into memory

Returns

False if successful, error code otherwise.

CreateBlankSurface

int CreateBlankSurface(LPRECT rcSize,  
DWORD RSrc_Flags,  
int (*Reset_Func)(RSRC_LOCKINFO_PTR LockInfo) =  NULL,
int AlphaEnabled =  true,
int NewBpp =  0)

Uses parameters to create a blank surface and optionally allows to fill the surface using a fuction pointer.  Will run objects initialize and put the resource into RSRC::RSRC_STATE_INIT.

Parameters

rcSizeLPRECT The size of the surface to create
RSrc_flagsDWORD Where to put it in memory
Reset_Func*(Reset_Func)(RSRC::RSRC_LOCKINFO_PTR LockInfo) Defaults to NULL.  Ran each time the surface needs to be redrawn.
AlphaEnabledINT Defaults to true.  Determines if an alpha channel is needed on the surface or not
NewBppINT Defaults to 0.  Creates the surface in a different Bpp than the back buffer

Returns

False if successful, error code otherwise.

VertexBufferResource

class VertexBufferResource : public Resource

Inherits from Resource.  Allow the creation of VertexBufferObjects.  These are used to store vertices in D3D Mode.  Currently implementation for the other interfaces in manual mode has not been completed.

|----------|      |----------------------|
| Resource |<-----| VertexBufferResource |
|----------|      |----------------------|
Summary
Creation Functions
CreateCreates a vertex buffer with the specified parameters

Creation Functions

Create

int Create(int size,
DWORD vertex_type,
DWORD RSrc_Flags)

Creates a vertex buffer with the specified parameters

Parameters

sizeINT The number of vertices requested
vertex_typeDWORD RSRC::VERTEX_TYPE_TYP that describes how the buffer should be setup
RSrc_FlagsDWORD RSRC::RSRC_FLAG_TYP that decides how the object should be loaded into memory

Returns

False if successful, error code otherwise.

namespace RSRC
Everything related to loading and mantaining a resource is in this namespace
int Init(MODE_TYP Interface)
Initializes the resource interfaces to use the specified mode
void Shutdown()
Shuts down the resource interface
void CompleteUnload()
Unloads all resources regardless of flags.
void ResetUnload()
Unloads all resource that have RSRC_RESET set.
Set by object to signal a reload required at device reset
int Reload()
Reloads all resources that have are in state RSRC_STATE_PENDING.
Object has been unloaded by reset and awaits reload
class Resource
Our top level resource class.
typedef struct IMAGE_OPTIONS_TYP
Used to describe how to open and load an image from disk.
class VertexBufferResource : public Resource
Inherits from Resource.
typedef struct VERTEX_OPTIONS_TYP
Structure used to create a VertexBufferResource
typedef struct RSRC_LOCKINFO_TYP
This structure is used to request and to process locks made on resources.
DWORD Flags
DWORD This is a RSRC::RSRC_FLAG_TYP
Used by the Resource to describe the needs of the lock or the resource
void* pDest
VOID* Points to the beginning of the memory block
int Pitch
INT The amount of bytes between “lines” in the Resource
int width
INT Width of the Resource
int Stride
INT The amount of bytes between objects (ie.
int Size
INT Size of the resource in number of strides
int Valid
INT Wether the lock is valid or not
int height
INT Height of the resource.
int bpp
INT The bits per pxiel.
DWORD Image_Flags
DWORD RSRC::IMAGE_FLAGS_TYP that help setup options for loading the image
Helps specify loading options for IMAGE_OPTIONS_TYP
char *pFilename
char* Null terminated filename to load
RECT LoadRect
RECT Size of the image or surface to create
DWORD SrcKeyColor
DWORD Color for SrcKeying
int Bpp
INT Specifies a different bpp to convert the image to
int numMipMaps
INT Specifies the mipmap level if MIPMAP flag is set (0 for maximum)
int (*LoadFunc)(RSRC_LOCKINFO_PTR)
*(LoadFunc)(RSRC::RSRC_LOCKINFO_PTR) Pointer to a function to load data to.
Alias for a pointer to RSRC_LOCKINFO_TYP
int Size
INT The size of the vertex buffer
DWORD Vertex_Type
DWORD RSRC::VERTEX_TYPE_TYP used to descrive the vertex buffer
Helps describe a VertexBufferResource.
class Object
Our abstact geralized object class.
Resource(
   
) : Flags(0), State(RSRC_STATE_CLEAN), Type(RSRC_TYPE_NONE), pObject(NULL)
Creates an empty resource class.
virtual ~Resource()
Detaches itself with the Object.
int AquireAndLoad()
The Object its attached to aquires any needed interfaces and loads the data into memory based on the initialization settings.
int Lock(RSRC_LOCKINFO_PTR LockInfo)
Locks a resource and locks the objects mutex.
void Unlock()
Unlocks a resource that was Lock’d.
void UnloadAndRelease()
Unloads the Object the resource is pointing to from memory and releases it’s interfaces.
void Detach()
Detaches itself from the Object it was pointing to.
RSRC_STATE_TYP TestState()
Tests the state of the Object and copies over all its state information into the resource.
DWORD getFlags()
Gets the current flags of the resource.
RSRC_STATE_TYP getState()
Gets the current state of the resource.
RSRC_TYPE_TYP getType()
Gets the current type of the object the resource is connected to.
class SurfaceResource : public Resource
Allows access to creation of SurfaceResources and provides the neccessary functions to create SurfaceObjects of various types.
int CreateFromFile(IMAGE_OPTIONS_PTR Options,
DWORD RSrc_Flags)
Uses provided options to create an object.
int CreateBlankSurface(LPRECT rcSize,  
DWORD RSrc_Flags,  
int (*Reset_Func)(RSRC_LOCKINFO_PTR LockInfo) =  NULL,
int AlphaEnabled =  true,
int NewBpp =  0)
Uses parameters to create a blank surface and optionally allows to fill the surface using a fuction pointer.
int Create(int size,
DWORD vertex_type,
DWORD RSrc_Flags)
Creates a vertex buffer with the specified parameters
Specifies what mode the program is running in
class D3DInterface
This is the main interface into Direct3D.
class DDrawInterface
Controls DirectDraw and provides a common interface to all of its functions.
class GDIInterface
Provides an interface to startup and shutdown the GDI+ Interface
Will not need to write to the resource
Data will be added, but existing data will not be touched.
Data will be completely written over, existing data should be used then discarded when its been used.
Specifies untransformed vertices.
Specifies that a normal will be used.
Specifies pre-transformed vertices
Object is loaded and ready
Object is locked by a resource
Object has been initialized
Object has not been initialized
Describes the state of a resource
Identifies that type of Resource that was created.
Close