[ADD] Added a basic Array List, still under development.

This commit is contained in:
Xane 2009-03-08 19:28:23 +00:00
parent 5836c028de
commit 2bed5b3d46
2 changed files with 137 additions and 53 deletions

View file

@ -22,7 +22,9 @@ u32 fb = 0;
static void *xfb[2] = {NULL, NULL};
GXRModeObj *rmode;
void *gp_fifo = NULL;
static GRRLIB_drawSettings GRRLIB_Settings;
static GRRLIB_linkedList *GRRLIB_ListImages;
static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int width, const unsigned int height);
@ -288,8 +290,9 @@ GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) {
PNGU_ReleaseImageContext(ctx);
my_texture.w = imgProp.imgWidth;
my_texture.h = imgProp.imgHeight;
GRRLIB_FlushTex( my_texture );
GRRLIB_ListAddTexture( &my_texture );
GRRLIB_SetHandle( &my_texture, 0, 0 );
GRRLIB_FlushTex(my_texture);
return my_texture;
}
@ -346,9 +349,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
my_texture.w = cinfo.output_width;
my_texture.h = cinfo.output_height;
GRRLIB_SetHandle( &my_texture, 0, 0 );
GRRLIB_FlushTex(my_texture);
GRRLIB_ListAddTexture( &my_texture );
GRRLIB_SetHandle( &my_texture, 0, 0 );
return my_texture;
}
@ -516,6 +519,7 @@ GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) {
* @param color Color in RGBA format.
*/
inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color) {
if (!tex.data) { return; }
GXTexObj texObj;
u16 width, height;
Mtx m, m1, m2, mv;
@ -566,9 +570,9 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
/**
* Draw a textured quad.
* @param pos vector array of the 4 points
* @param tex texture to draw.
* @param color
* @param pos Vector array of the 4 points.
* @param tex The texture to draw.
* @param color Color in RGBA format.
*/
inline void GRRLIB_DrawImgQuad(Vector pos[4], GRRLIB_texImg tex, u32 color) {
GXTexObj texObj;
@ -1153,6 +1157,7 @@ void GRRLIB_Init() {
// Default settings
GRRLIB_Settings.antialias = true;
GRRLIB_ListImages = NULL;
}
/**
@ -1212,3 +1217,68 @@ bool GRRLIB_ScrShot(const char* File)
}
return !ErrorCode;
}
/**
* Add a GRRLIB texture into the list.
* @param img The texture to add.
*/
void GRRLIB_ListAddTexture( GRRLIB_texImg *img ) {
GRRLIB_linkedList *temp = malloc(sizeof(GRRLIB_linkedList));
if (newList == NULL) { return; }
temp->next = *&GRRLIB_ListImages;
temp->texture = img;
*&GRRLIB_ListImages = temp;
}
/**
* Delete an list entry containing the pointer of a texture.
* @param img The texture to delete.
*/
bool GRRLIB_ListDelTexture( GRRLIB_texImg *img ) {
GRRLIB_linkedList *temp = GRRLIB_ListImages;
if (!temp) { return false; } // List is empty.
while ( temp->next ) {
if (temp->texture == img) { // <- Doesn't really work, need to find another way. :x
return true;
//free(img->data);
//free(img);
//GRRLIB_ListRemove( &temp );
//return true;
}
temp = temp->next;
}
return false;
}
/**
* Removes an entry of an Array List.
* @param list The pointer to a list.
*/
void GRRLIB_ListRemove( GRRLIB_linkedList **list ) {
if (list) {
GRRLIB_linkedList *temp = *list;
*list = (*list)->next;
free(temp);
}
}
/**
* Just for testing purposes.
* Loops through all members of an Array List.
*/
unsigned int GRRLIB_ListGetTextureEntries() {
unsigned int cnt = 0;
GRRLIB_linkedList *temp = GRRLIB_ListImages;
if (!temp) { return 0; } // List is empty.
while ( temp->next ) {
cnt = cnt + 1;
temp = temp->next;
}
return cnt;
}

View file

@ -83,6 +83,14 @@ typedef struct GRRLIB_bytemapFont {
GRRLIB_bytemapChar *charDef; /**< List of bitmap character definitions. */
} GRRLIB_bytemapFont;
/**
* Linked List to inherit all members of an GRRLIB struct.
*/
typedef struct GRRLIB_linkedList {
GRRLIB_texImg *texture; /**< GRRLIB Texture */
struct GRRLIB_linkedList *next; /**< Pointer to next LinkedList */
} GRRLIB_linkedList;
extern Mtx GXmodelView2D;
@ -156,6 +164,12 @@ void GRRLIB_Exit();
bool GRRLIB_ScrShot(const char*);
void GRRLIB_ListAddTexture( GRRLIB_texImg *img );
bool GRRLIB_ListDelTexture( GRRLIB_texImg *img );
void GRRLIB_ListRemove( GRRLIB_linkedList **list );
unsigned int GRRLIB_ListGetTextureEntries();
#ifdef __cplusplus
}
#endif /* __cplusplus */