Only took about 7 days and added a bunch more code :-) it is reasonably documented. And it works well. I would however be interested in feedback on the way I handle loading from a resource file. Maybe someone can post how to use add_buffer and file_load to do this... Or even a better way that I am not aware of...

Anyway enjoy...

Oh BTW yes I do have a mouse system that integrates with this but not willing to post that just yet.


support files that are needed
memext.h
Code:
//*@@Module User Memext ******************************************************
// Name:
//    Memext
//
// Author:
//    Gordon Tackett
//
// Date:
//		03/22/2012
//
// Copyright:
//		copyright 2012 by Westmarch Studios. All rights reserved.
//
// Description:
//		Extended memory allocation functions that clear the allocated memory.
//
//----------------------------------------------------------------------------
// History:
//		03/31/2012		First release.    
//
//*@@End----------------------------------------------------------------------

#ifndef memext_h
#define memext_h

void* crealloc(void* ptr, int newsize, int oldsize);
void* calloc(int size);

#endif



memext.c
Code:
//*@@Module User Memext ******************************************************
// Name:
//    Memext
//
// Author:
//    Gordon Tackett
//
// Date:
//		03/22/2012
//
// Copyright:
//		copyright 2012 by Westmarch Studios. All rights reserved.
//
// Description:
//		Extended memory allocation functions that clear the allocated memory.
//
//----------------------------------------------------------------------------
// History:
//		03/31/2012		First release.    
//
//*@@End----------------------------------------------------------------------

#ifndef memext_c
#define memext_c

//@@function API crealloc ----------------------------------------------------
//
// Name:
//    crealloc
//
// Description:
//    calls realloc to change the size of an allocated area. If the size is
//		larger than the original then the new area is cleared to zero. causes
//		program halt on reallocation failure.
//
// Usage:
//		ptr = crealloc(ptr,size);
//
// Parameters:
//		# ptr - pointer to allocated memory
//		# size - new size of allocated area.
//
// Output:
//		void* - pointer to allocated memory. note memory could have moved.
//
//*@@End----------------------------------------------------------------------
void* crealloc(void* ptr, int oldsize, int newsize)
{
	void* new;
	new = realloc(ptr, newsize);
	if (new != NULL) {
		ptr = new;
		if (newsize >  oldsize) {
			memset(ptr+oldsize,0,newsize-oldsize);
		}
	} else {
		printf("crittical memory error - crealloc");
		sys_exit("3200");
	}
	return(ptr);
}

//@@function API calloc ------------------------------------------------------
//
// Name:
//    calloc
//
// Description:
//    calls malloc to allocate memory then the new area is cleared to zero. 
//		returns NULL if allocation fails.
//
// Usage:
//		ptr = calloc(size);
//
// Parameters:
//		# size - new size of allocated area.
//
// Output:
//		void* - pointer to allocated memory. 
//
//*@@End----------------------------------------------------------------------
void* calloc(int size)
{
	void* ptr = malloc(size);
	if (ptr != NULL) {
		memset(ptr, 0, size);
	}
	return(ptr);
}

#endif



imagemanager.h
Code:
//*@@Module User Image Manager ***********************************************
// Name:
//    Image Manager
//
// Author:
//    Gordon Tackett
//
// Date:
//		03/22/2012
//
// Copyright:
//		copyright 2012 by Westmarch Studios. All rights reserved.
//
// Description:
//		See imagemanager.c 
//
//----------------------------------------------------------------------------
// History:
//		03/31/2012		First release.    
//
//*@@End----------------------------------------------------------------------

#ifndef imagemanager_h
#define imagemanager_h

#define PRAGMA_POINTER
#include <acknex.h>

typedef struct {
	BMAP*		bmap;
	var		size_x;
	var		size_y;
} image;

typedef struct {
	int		imagecount;
	int		hotspot_x;
	int		hotspot_y;
	image*	images;
	int		particlecount;
	image*   particles;
	void*		emitter;
	int		emitter_x;
	int		emitter_y;
} mouseimage;

int	im_initdone(void);
int	im_getImageCount(void);
BMAP* im_getbmap(int index);
int im_getheight(int index);
int im_getwidth(int index);

void im_setMouseEmitter(int mouse, void* fnc, int x, int y);

int im_getMouseCount(void);
int im_getMouseParticleCount(int mouse);
BMAP* im_getMouseParticle(int mouse, int index);
int im_getMouseParticleSizeX(int mouse);
int im_getMouseParticleSizeY(int mouse);

int im_getMouseImageCount(int mouse);
BMAP* im_getMouseImage(int mouse, int index);
int im_getMouseSizeX(int mouse);
int im_getMouseSizeY(int mouse);
int im_getMouseHotspotX(int Mouse);
int im_getMouseHotspotY(int Mouse);

void* im_getMouseEmitter(int mouse);
int im_getMouseEmitX(int mouse);
int im_getMouseEmitY(int Mouse);

void im_buildFiles(void);
void im_releaseAll(void);

#endif



imagemanager.c
Code:
//*@@Module User Image Manager ***********************************************
// Name:
//    Image Manager
//
// Author:
//    Gordon Tackett
//
// Date:
//		03/22/2012
//
// Copyright:
//		copyright 2012 by Westmarch Studios. All rights reserved.
//
// Description:
//		This module in development mode will load images form relative
//		relative directories to the main file. It can load 3 types of
//		image resources:
//			# Standard image resources
//			# mouse cursor images
//			# mouse particle effect images
//
//		Image loading is controled by a plain text file "imagemanager.cfg". 
//		This file can contain the following statements and order is sequencial.
//			# // - comment lines in the file
//			# imagecount NUM - allocates space for NUM number of images
//			# path PATH - sets a path for file locations. May contain more than one
//			# mousecount NUM - allocates space for NUM mouse cursor blocks
//			# mouseimagecount MOUSE NUM HOTX HOTY - allocates space in the MOUSE mouse
//				control block for NUM number of images and sets the hot spot to HOTX
//				and HOTY. There needs to be one mouseimagecount statement for each
//				mouse control block allocated in mousecount.
//			# mouseparticles MOUSE NUM - allocates space in MOUSE mouse control block
//				for NUM number of images for particle effects from mouse. not needed
//				if mouse has not particle effects;
//			# file FILE SYM - Loades a standard image file at next available location.
//				SYM is used to create a define statement when building headers. SYM
//				is optional.
//			# mousefile MOUSE INDEX FILE SYM - Loads an image into the MOUSE mouse
//				control block from FILE on the current PATH as set by path statement
//				at INDEX location. SYM is used to create define statement for mouse 
//				control block and only the first image for mouse cursor should have 
//				this. 
//			# mouseparticlefile MOUSE INDEX FILE - loads a particle image into
//				the MOUSE mouse control block at the INDEX location for FILE
//				file. 
//
//		Calling im_buildFiles will create the file imconfig.h and imbind.wdl. 
//		The .h file contains defines for accessing images and mouse control blocks
//		the .wdl file contains bind statements for all files. It also copies the
//		config file to "imagemanager.pak" and a bind statement is created for this
//		new file.
//
//		When the game is published it will load all resource file for pro version.
//		for no pro versions the config file will need to be edited to adjust the path. 
//
//		Note: for integration with a loading bar image counts should be accurate and
//		all mouseimagecount and mouseparticles statements should be before any files
//		are loaded.
//
//----------------------------------------------------------------------------
// History:
//		03/31/2012		First release.    
//
//*@@End----------------------------------------------------------------------


#ifndef imagemanager_c
#define imagemanager_c

#include "..\\imagemanager\\imagemanager.h"
#include "..\\memext\\memext.h"
#include <strio.c>

#ifdef loader_h
#ifndef semaphore_h
#include "..\\semaphore\\semaphore.h"
#endif
#endif

#define PRAGMA_POINTER

//*@@type intermal im_namespacetype-------------------------------------------
//
// Name:
//    im_namespacetype
//
// Description:
//    This structure is used to hold all the module variables and prevent 
//		name collistion in other modules. Only one varaible of this time is
//		ever declared.
//
//*@@End----------------------------------------------------------------------
typedef struct {
	int			initdone;
	image*		images;
	int			imagecount;
	mouseimage* mouseimages;	
	int			mousecount;
	var			percentdone;
	int			semaphore;
	void*			proc;
} im_namespacetype;

//*@@data intermal im_namespace ----------------------------------------------
//
// Name:
//    im_namespace
//
// Description:
//    the one instance of im_namespacetype
//
//*@@End----------------------------------------------------------------------
im_namespacetype im_namespace;


//@@function user im_getImageCount -------------------------------------------
//
// Name:
//    im_getImageCount
//
// Description:
//    This function returns the number of loaded images for the main image
//		section. 
//
// Usage:
//		imagecnt = im_getImageCount();
//
// Parameters:
//		None
//
// Output:
//		int - number of loaded images in main image section.
//
//*@@End----------------------------------------------------------------------
int	im_getImageCount(void)
{
	return(im_namespace.imagecount);
}


//@@function user im_initdone ------------------------------------------------
//
// Name:
//    im_initdone
//
// Description:
//    Returns the initialization state of the module.
//
// Usage:
//		while(!im_initdone()) wait(1);
//
// Parameters:
//		None
//
// Output:
//		int - 0 not finished initializing, 1 - finished initializing
//
//*@@End----------------------------------------------------------------------
int	im_initdone(void)
{
	return(im_namespace.initdone);
}


//@@function user im_getimage ------------------------------------------------
//
// Name:
//    im_getimage
//
// Description:
//    This function returns a pointer to an image structure for use by other
//		routines and hides the internal structure of storage in this module.
//		returns NULL if index is out of range.
//
// Usage:
//		img = im_getimage(img_wand);
//
// Parameters:
//		# index - integer value of the 0 based index of the image required.
//
// Output:
//		image* - pointer to image structure.
//
//*@@End----------------------------------------------------------------------
image* im_getimage(int index)
{
	if ((index < 0 || index >= im_namespace.imagecount) || im_namespace.initdone != 1) {
		return(NULL);
	}
	return(&(im_namespace.images)[index]);
}


//@@function user im_getbmap -------------------------------------------------
//
// Name:
//    im_getbmap
//
// Description:
//    This function returns just the bit map pointer from the indexed image
//		object. Will return null if index is out of range or bit map failed
//		to load.
//
// Usage:
//		bmap = im_getbmap(img_wand);
//
// Parameters:
//		# index - integer value of the 0 based index of the image required.
//
// Output:
//		BMAP* - pointer to the loaded image
//
//*@@End----------------------------------------------------------------------
BMAP* im_getbmap(int index)
{
	if ((index >= 0 || index < im_namespace.imagecount) && im_namespace.initdone != 1) {
		return((im_namespace.images)[index].bmap);
	}
	return(NULL);
}


//@@function user im_getheight -----------------------------------------------
//
// Name:
//    im_getheight
//
// Description:
//    returns the heigth from the images structure pointed to by index.
//
// Usage:
//		heigth = im_getheight(img_wand);
//
// Parameters:
//		# index - integer value of the 0 based index of the image required.
//
// Output:
//		
//
//*@@End----------------------------------------------------------------------
int im_getheight(int index)
{
	if ((index >= 0 || index < im_namespace.imagecount) && im_namespace.initdone != 1) {
		return((im_namespace.images)[index].size_x);
	}
	return(-1);
}


//@@function user im_getwidth ------------------------------------------------
//
// Name:
//    im_getwidth
//
// Description:
//    returns the width from the image structure. Will return 0 if image index
//		is out of range or image didn't load.
//
// Usage:
//		width = im_getwidth(img_wand);
//
// Parameters:
//		# index - integer value of the 0 based index of the image required.
//
// Output:
//		int - width of the indexed bitmap.
//
//*@@End----------------------------------------------------------------------
int im_getwidth(int index)
{
	if ((index >= 0 || index < im_namespace.imagecount) && im_namespace.initdone != 1) {
		return((im_namespace.images)[index].size_y);
	}
	return(-1);
}


//@@function user im_setMouseEmitter -----------------------------------------
//
// Name:
//    im_setMouseEmitter
//
// Description:
//    This function sets some values that can be used by mouse module.
//		While this functionallity is not really image managment having
//		all the data for the animated mouse cursor in one place is a good thing.
//		At this point this is the only way to set this information. It may be
//		posible to add this into the configuration file at some point. At that
//		time this function should be depricated.
//
// Usage:
//		im_setMouseEmitter
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//		# fnc - void* to emitter function
//		# x - int x location of emitter offset
//		# y - int y location of emitter offset
//
// Output:
//		None
//
//*@@End----------------------------------------------------------------------
void im_setMouseEmitter(int mouse, void* fnc, int x, int y)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		((im_namespace.mouseimages)[mouse-1]).emitter = fnc;
		((im_namespace.mouseimages)[mouse-1]).emitter_x = x;
		((im_namespace.mouseimages)[mouse-1]).emitter_y = y;
	}
}


//@@function user im_getMouseCount -------------------------------------------
//
// Name:
//    im_getMouseCount
//
// Description:
//    returns the number of mouse control blocks that were allocated. This
//		should be equal to the number of control blocks loaded but may be greater
//		than the number of control blocks loaded.
//
// Usage:
//		mousecount = im_getMouseCount();
//
// Parameters:
//		none
//
// Output:
//		int - Number of mouse control blockes that were allocated.
//
//*@@End----------------------------------------------------------------------
int im_getMouseCount(void)
{
	return(im_namespace.mousecount);
}


//@@function user im_getMouseParticleCount -----------------------------------
//
// Name:
//    im_getMouseParticleCount
//
// Description:
//    This function returns the number of particle images loaded for the indexed
//		mouse control block.
//
// Usage:
//		partcnt = im_getMouseParticleCount(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - count of particle images in this mouse control block.
//
//*@@End----------------------------------------------------------------------
int im_getMouseParticleCount(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return((im_namespace.mouseimages)[mouse-1].particlecount);
	}
	return(0);
}


//@@function user im_getMouseParticle ----------------------------------------
//
// Name:
//    im_getMouseParticle
//
// Description:
//    This function returns the bitmap for the indexed particle bmap for the
//		indexed particle image. out of range errors return a NULL pointer.
//
// Usage:
//		im_getMouseParticle
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//		# index - int index of particle image for mouse effects.
//
// Output:
//		BMAP* - pointer to image bitmap
//
//*@@End----------------------------------------------------------------------
BMAP* im_getMouseParticle(int mouse, int index)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		if (index > 0  && index < (im_namespace.mouseimages)[mouse-1].particlecount) {
			return(((im_namespace.mouseimages)[mouse-1].particles)[index].bmap);
		}
	}
	return(0);
}


//@@function user im_getMouseParticleSizeX ------------------------------
//
// Name:
//    im_getMouseParticleSizeX
//
// Description:
//    This function returns the size in the x direction fo the first
//		particle image.
//
// Usage:
//		im_getMouseParticleSizeX
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - size_x for particle
//
//*@@End----------------------------------------------------------------------
int im_getMouseParticleSizeX(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1].particles)[0].size_x);
	}
	return(0);
}


//@@function user im_getMouseParticleSizeY ------------------------------
//
// Name:
//    im_getMouseParticleSizeY
//
// Description:
//    This function returns the size of the particle in the Y direction.
//
// Usage:
//		size_y = im_getMouseParticleSizeY
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - size of particl in Y direction.
//
//*@@End----------------------------------------------------------------------
int im_getMouseParticleSizeY(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1].particles)[0].size_y);
	}
	return(0);
}


//@@function user im_getMouseImageCount --------------------------------------
//
// Name:
//    im_getMouseImageCount
//
// Description:
//    This function returns the number of mouse images for animated cursor
//
// Usage:
//		cnt = im_getMouseImageCount(mouse);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - count of cursor images for animated mouse cursor.
//
//*@@End----------------------------------------------------------------------
int im_getMouseImageCount(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return((im_namespace.mouseimages)[mouse-1].imagecount);
	}
	return(0);
}
	

//@@function user im_getMouseImage -------------------------------------------
//
// Name:
//    im_getMouseImage
//
// Description:
//    This function returns the image for a frame of the animated mouse
//		cursor. Non animated cursors will only have 1 frame.
//
// Usage:
//		mouse_map = im_getMouseImage(mouse_finger,frame);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//		# index - int index of image for animated cursor.
//
// Output:
//		BMAP* - image for a frame of animated cursor.
//
//*@@End----------------------------------------------------------------------
BMAP* im_getMouseImage(int mouse, int index)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		if (index > 0  && index < (im_namespace.mouseimages)[mouse-1].imagecount) {
			return((((im_namespace.mouseimages)[mouse-1]).images)[index].bmap);
		}
	}
	return(0);
}


//@@function user im_getMouseSizeX -------------------------------------------
//
// Name:
//    im_getMouseSizeX
//
// Description:
//    This function returns the width of the mouse cursor.
//
// Usage:
//		width = im_getMouseSizeX(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - width of mouse cursor image.
//
//*@@End----------------------------------------------------------------------
int im_getMouseSizeX(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return((((im_namespace.mouseimages)[mouse-1]).images)[0].size_x);
	}
	return(0);
}


//@@function user im_getMouseSizeY ------------------------------
//
// Name:
//    im_getMouseSizeY
//
// Description:
//    This function returns the height of the mouse cursor.
//
// Usage:
//		height = im_getMouseSizeY(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - height of indexed mouse cursor.
//
//*@@End----------------------------------------------------------------------
int im_getMouseSizeY(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return((((im_namespace.mouseimages)[mouse-1]).images)[0].size_x);
	}
	return(0);
}


//@@function user im_getMouseHotspotX ----------------------------------------
//
// Name:
//    im_getMouseHotspotX
//
// Description:
//    This function returns the hot spot x offset.
//
// Usage:
//		mouse_spot.x = im_getMouseHotspotX(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - mouse hot spot x location.
//
//*@@End----------------------------------------------------------------------
int im_getMouseHotspotX(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1]).hotspot_x);
	}
	return(0);
}


//@@function user im_getMouseHotspotY ----------------------------------------
//
// Name:
//    im_getMouseHotspotY
//
// Description:
//    This function returns the hot spot y ofsset.
//
// Usage:
//		mouse_spot.y = im_getMouseHotspotY(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - hot spot y offset.
//
//*@@End----------------------------------------------------------------------
int im_getMouseHotspotY(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1]).hotspot_y);
	}
	return(0);
}


//@@function user im_getMouseEmitter -----------------------------------------
//
// Name:
//    im_getMouseEmitter
//
// Description:
//    This function returns the pointer for the mouse particle effect function.
//
// Usage:
//		effect(im_getMouseEmitter(mouse_hand),4,POS,VEL);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		void* - pointer to emitter function. NULL for no emitter.
//
//*@@End----------------------------------------------------------------------
void* im_getMouseEmitter(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1]).emitter);
	}
	return(0);
}


//@@function user im_getMouseEmitX -------------------------------------------
//
// Name:
//    im_getMouseEmitX
//
// Description:
//    This function returns the offset from the mouse postion for particle effects.
//
// Usage:
//		emitx = im_getMouseEmitX(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - x offset for particle effects.
//
//*@@End----------------------------------------------------------------------
int im_getMouseEmitX(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1]).emitter_x);
	}
	return(0);
}


//@@function user im_getMouseEmitY -------------------------------------------
//
// Name:
//    im_getMouseEmitY
//
// Description:
//    Returns the y offset for mouse particle effects.
//
// Usage:
//		emity = im_getMouseEmitY(mouse_hand);
//
// Parameters:
//		# mouse - int index of mouse control block to access.
//
// Output:
//		int - y offset for particle effects function.
//
//*@@End----------------------------------------------------------------------
int im_getMouseEmitY(int mouse)
{
	if (mouse > 0 && mouse <= im_namespace.mousecount) {
		return(((im_namespace.mouseimages)[mouse-1]).emitter_y);
	}
	return(0);
}


//@@function internal im_doload ------------------------------
//
// Name:
//    im_doload
//
// Description:
//    This function loads the images from disk or the resource file into
//		structured memory.
//
// Usage:
//		called from startup or loader.
//
// Parameters:
//		none
//
// Output:
//		none
//
// Todo:
//		investigate adding a file name param and adding a stub to call this 
//		function that has no parameters. This would allow for multiple config
//		files.
//
//*@@End----------------------------------------------------------------------
void im_doload(void)
{
	var file;
	STRING* line = "#128";
	STRING* filename = "#128";
	STRING* path = "#128";
	STRING* tmpstr = "#128";
	STRING* keyword = "#32";
	var EOF;
	var totalImagesToLoad;
	var totalLoaded;
	int mouseframe;
	int mouse;
	int filecount;
	int resourceload;
	
	im_namespace.images = NULL;
	im_namespace.imagecount = 0;
	im_namespace.mousecount = 0;
	im_namespace.mouseimages = NULL;
	im_namespace.initdone = 0;
	im_namespace.percentdone = 0;
	str_cpy(path,"");
	filecount = 0;
	resourceload = 0;
	totalImagesToLoad = 0;
	totalLoaded = 0;
	
	// loading bar integration is optional.
#ifdef loader_h
	im_namespace.semaphore = ld_getsemaphore(im_namespace.proc);
	wait_get_semaphore(im_namespace.semaphore);
#endif

	file = file_open_read("imagemanager.cfg");
	if (file == NULL) {
		// test for file in resources...
		if (file_cpy("imagemanager.cfg","imagemanager.pak")) {
			file = file_open_read("imagemanager.cfg");
			resourceload = 1;
		}
	}
	if (file != NULL) {
		EOF = file_str_read(file,line);
		while(EOF != -1) {
			str_trim(line);
			if (str_cmpni(line,"//")) {
				EOF = file_str_read(file,line);
				continue;
			}
			diag("\n line - ");
			diag(line);
			str_cpy(tmpstr,"");
			str_parse(keyword,line,1);
			if (str_cmpi(keyword,"images")) {
				diag("\n images");
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				if (im_namespace.imagecount < str_to_int(tmpstr)) {
					im_namespace.images 
						= crealloc(im_namespace.images,
							sizeof(image) * im_namespace.imagecount,
							sizeof(image) * str_to_int(tmpstr));
					im_namespace.imagecount = str_to_int(tmpstr);
					totalImagesToLoad += im_namespace.imagecount;
				}
			}
			if (str_cmpi(keyword,"mousecount")) {
				diag("\n mousecount");
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				if (im_namespace.mousecount < str_to_int(tmpstr)) {
					im_namespace.mouseimages 
						= crealloc(im_namespace.mouseimages,
							sizeof(mouseimage)* im_namespace.mousecount,
							sizeof(mouseimage) * str_to_int(tmpstr));
					im_namespace.mousecount = str_to_int(tmpstr);
				}
			}
			if (str_cmpi(keyword,"mouseimagecount")) {
				diag("\n mouseimagecount");
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				
				mouse = str_to_int(tmpstr);
				if (im_namespace.mousecount < mouse) {
					diag("\n mouseframes mouseimages to small");
					im_namespace.mouseimages 
						= crealloc(im_namespace.mouseimages,
							sizeof(mouseimage)* im_namespace.mousecount,
							sizeof(mouseimage) * mouse);
					im_namespace.mousecount = mouse;
				}
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				mouseframe = str_to_int(tmpstr);
				if (((im_namespace.mouseimages)[mouse-1]).imagecount < mouseframe) {
					((im_namespace.mouseimages)[mouse-1]).images 
						= crealloc(((im_namespace.mouseimages)[mouse-1]).images,
							sizeof(image)* ((im_namespace.mouseimages)[mouse-1]).imagecount,
							sizeof(image) * mouseframe);
					((im_namespace.mouseimages)[mouse-1]).imagecount = mouseframe;
					totalImagesToLoad += mouseframe;
				}
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				((im_namespace.mouseimages)[mouse-1]).hotspot_x = str_to_int(tmpstr);
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				((im_namespace.mouseimages)[mouse-1]).hotspot_y = str_to_int(tmpstr);
			}
			if (str_cmpi(keyword,"mouseparticles")) {
				diag("\n mouseparticles");
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				
				mouse = str_to_int(tmpstr);
				if (im_namespace.mousecount < mouse) {
					diag("\n mouseparticles mouseimages to small");
					im_namespace.mouseimages 
						= crealloc(im_namespace.mouseimages,
							sizeof(mouseimage)* im_namespace.mousecount,
							sizeof(mouseimage) * mouse);
					im_namespace.mousecount = mouse;
				}
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				mouseframe = str_to_int(tmpstr);
				if (((im_namespace.mouseimages)[mouse-1]).particlecount < mouseframe) {
					((im_namespace.mouseimages)[mouse-1]).particles 
						= crealloc(((im_namespace.mouseimages)[mouse-1]).particles,
							sizeof(image)* ((im_namespace.mouseimages)[mouse-1]).particlecount,
							sizeof(image) * mouseframe);
					((im_namespace.mouseimages)[mouse-1]).particlecount = mouseframe;
					totalImagesToLoad += mouseframe;
				}
			}

			if (str_cmpi(keyword,"path")) {
				diag("\n path ");
				str_parse(path,line,0);
				str_trim(path);
				diag(path);
			}
			if (str_cmpi(keyword,"file")) {
				diag("\n file ");
				str_parse(filename,line,0);
				str_trim(filename);
				str_cpy(tmpstr,path);
				str_cat(tmpstr,filename);
				str_cpy(filename,tmpstr);
				diag(filename);
				((im_namespace.images)[filecount]).bmap = 
					bmap_create(filename);
				if (((im_namespace.images)[filecount]).bmap != NULL) {
					((im_namespace.images)[filecount]).size_x 
						= bmap_width(((im_namespace.images)[filecount]).bmap);
					((im_namespace.images)[filecount]).size_y 
						= bmap_height(((im_namespace.images)[filecount]).bmap);
				} else {
					diag("\n error loading file \"");
					diag(filename);
					diag("\"");
				}
				filecount++;
				totalLoaded++;
				im_namespace.percentdone = totalLoaded / totalImagesToLoad;
#ifdef loader_h
				ld_update(im_namespace.proc, im_namespace.percentdone);
#endif				
			}
			if (str_cmpi(keyword,"mousefile")) {
				diag("\n mousefile ");
				str_parse(keyword, line, 0);
				str_trim(keyword);
				mouse = str_to_int(keyword);
				str_parse(keyword, line, 0);
				str_trim(keyword);
				str_parse(filename, line, 0);
				str_trim(filename);
				mouseframe = str_to_int(keyword);
				str_cpy(tmpstr,path);
				str_cat(tmpstr,filename);
				str_cpy(filename,tmpstr);
				diag(filename);
				((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).bmap =
					bmap_create(filename);
				if (((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).bmap != NULL && mouseframe == 1) {
					((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).size_x 
						= bmap_width(((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).bmap);
					((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).size_y 
						= bmap_height(((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).bmap);
				} else if (((((im_namespace.mouseimages)[mouse-1]).images)[mouseframe-1]).bmap == NULL) {
					diag("\n error loading file \"");
					diag(filename);
					diag("\"");
				}
				totalLoaded++;
				im_namespace.percentdone = totalLoaded / totalImagesToLoad;
#ifdef loader_h
				ld_update(im_namespace.proc, im_namespace.percentdone);
#endif				
			}
			if (str_cmpi(keyword,"mouseparticlefile")) {
				diag("\n mouseparticlefile ");
				str_parse(keyword, line, 0);
				str_trim(keyword);
				mouse = str_to_int(keyword);
				str_parse(keyword, line, 0);
				str_trim(keyword);
				str_parse(filename, line, 0);
				str_trim(filename);
				mouseframe = str_to_int(keyword);
				str_cpy(tmpstr,path);
				str_cat(tmpstr,filename);
				str_cpy(filename,tmpstr);
				diag(filename);
				((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).bmap =
					bmap_create(filename);
				if (((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).bmap != NULL && mouseframe == 1) {
					((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).size_x 
						= bmap_width(((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).bmap);
					((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).size_y 
						= bmap_height(((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).bmap);
				} else if (((((im_namespace.mouseimages)[mouse-1]).particles)[mouseframe-1]).bmap == NULL) {
					diag("\n error loading file \"");
					diag(filename);
					diag("\"");
				}
				totalLoaded++;
				im_namespace.percentdone = totalLoaded / totalImagesToLoad;
#ifdef loader_h
				ld_update(im_namespace.proc, im_namespace.percentdone);
#endif				
			}
			if (filecount % 3 == 0) {
				wait(1);
			}
			EOF = file_str_read(file,line);			
		}
		file_close(file);
		if (resourceload == 1) {
			file_delete("imagemanager.cfg");
		}
	}
	im_namespace.initdone = 1;
#ifdef loader_h
	sm_Set1_release(im_namespace.semaphore);
#endif
}


//@@function user im_startup -------------------------------------------------
//
// Name:
//    im_startup
//
// Description:
//    module initialization routine. Adds im_doload to loader process table
//		if using loader or justs calls im_doload if not.
//
// Usage:
//		called by system
//
// Parameters:
//		none
//
// Output:
//		none
//
//*@@End----------------------------------------------------------------------
void im_startup(void)
{
#ifdef loader_h
	while (!ld_initdone()) {
		wait(1);
	}
	im_namespace.proc = ld_addprocess(im_doload);
#else
	im_doload();
#endif
}


//@@function user im_buildFiles ------------------------------
//
// Name:
//    im_buildFiles
//
// Description:
//    reads config file and builds a WDL file with bind statements and a .h
//		file with symbolic names for indexes.
//
// Usage:
//		im_buildFiles();
//
// Parameters:
//		none
//
// Output:
//		none
//
//	Note:
//		changes to im_doload that affect syntax of config file or that add
//		symbolic name options need to be reflected here.
//
//*@@End----------------------------------------------------------------------
void im_buildFiles(void)
{
	var file;
	var include;
	var bind;
	STRING* line = "#128";
	STRING* filename = "#128";
	STRING* path = "#128";
	STRING* tmpstr = "#128";
	STRING* keyword = "#32";
	var EOF;
	int filecount;
	int	mouse;
	int	mouseframe;
	
	im_namespace.images = NULL;
	im_namespace.imagecount = 0;
	im_namespace.initdone = 0;
	
	filecount = 0;
	file = file_open_read("imagemanager.cfg");
	if (file == NULL) {
		return;
	}
	file_close(file);
	file_cpy("imagemanager.pak", "imagemanager.cfg");
	file = file_open_read("imagemanager.cfg");
	include = file_open_write("imconfig.h");
	if (include == NULL) {
		return;
	}
	bind = file_open_write("imbind.wdl");
	if (bind == NULL) {
		file_close(include);
		return;
	}
	file_str_write(bind, "BIND \"imagemanager.pak\";\n");
	if (file != NULL) {
		EOF = file_str_read(file,line);
		while(EOF != -1) {
			str_trim(line);
			if (str_cmpni(line,"//")) {
				EOF = file_str_read(file,line);
				continue;
			}
			str_parse(keyword,line,1);
			if (str_cmpi(keyword,"path")) {
				str_parse(path,line,0);
				str_trim(path);
			}
			if (str_cmpi(keyword,"file")) {
				str_parse(filename,line,0);
				str_trim(filename);
				str_cpy(tmpstr,path);
				str_cat(tmpstr,filename);
				str_cpy(filename,tmpstr);
				str_parse(tmpstr,line,0);
				str_trim(tmpstr);
				str_cpy(line,"BIND \"");
				str_cat(line, filename);
				str_cat(line,"\";\n");
				file_str_write(bind,line);
				if (str_len(tmpstr) > 0) {
					str_cpy(line,"#define img_");
					str_cat(line, tmpstr);
					str_cat(line, " ");
					str_for_num(keyword, filecount);
					str_cat(line,keyword);
					str_cat(line,"\n");
					file_str_write(include, line);
				}
				filecount++;
				
			}
			if (str_cmpi(keyword,"mousefile")) {
				str_parse(keyword, line, 0);
				str_trim(keyword);
				mouse = str_to_int(keyword);
				str_parse(keyword, line, 0);
				str_trim(keyword);
				str_parse(filename, line, 0);
				str_trim(filename);
				mouseframe = str_to_int(keyword);
				str_cpy(tmpstr,path);
				str_cat(tmpstr,filename);
				str_cpy(filename,tmpstr);
				str_cpy(tmpstr,"");
				str_parse(tmpstr, line, 0);
				str_trim(tmpstr);
				str_cpy(line,"BIND \"");
				str_cat(line, filename);
				str_cat(line,"\";\n");
				file_str_write(bind,line);
				if (str_len(tmpstr) > 0) {
					str_cpy(line,"#define mouse_");
					str_cat(line, tmpstr);
					str_cat(line, " ");
					str_for_num(keyword, mouse);
					str_cat(line,keyword);
					str_cat(line,"\n");
					file_str_write(include, line);
				}
			}
			EOF = file_str_read(file,line);			
		}
		file_close(file);
		file_close(include);
		file_close(bind);
	}
	im_namespace.initdone = 1;
}


//@@function user im_releaseAll ------------------------------
//
// Name:
//    im_releaseAll
//
// Description:
//    frees all images and allocated memory.
//
// Usage:
//		im_releaseAll();
//
// Parameters:
//		None.
//
// Output:
//		None.
//
//*@@End----------------------------------------------------------------------
void im_releaseAll(void)
{
	int i;
	int j;
	
	for (i = 0; i < im_namespace.imagecount; i++) {
		ptr_remove((im_namespace.images)[i].bmap);
	}
	free(im_namespace.images);
	im_namespace.images = NULL;
	im_namespace.imagecount = 0;
	for (i = 0; i < im_namespace.mousecount; i++) {
		for (j = 0; j < (im_namespace.mouseimages)[i].imagecount; j++) {
			ptr_remove(((im_namespace.mouseimages)[i].images)[j].bmap);
		}
		free((im_namespace.mouseimages)[i].images);
		for (j = 0; j < (im_namespace.mouseimages)[i].particlecount; j++) {
			ptr_remove(((im_namespace.mouseimages)[i].particles)[j].bmap);
		}
		free((im_namespace.mouseimages)[i].particles);
	}
	free(im_namespace.mouseimages);
	im_namespace.mouseimages = NULL;
	im_namespace.mousecount = 0;
}

#endif




Our new web site:Westmarch Studios