wrote documentation for spritesheet, and worked on adding spritesheet to graphics config
This commit is contained in:
parent
bbffbe1cb3
commit
83b87c6d63
9 changed files with 136 additions and 126 deletions
|
|
@ -5,8 +5,8 @@
|
|||
#include "renderer.h"
|
||||
#include "sprite.h"
|
||||
#include "spritesheet.h"
|
||||
#include "arc/std/array.h"
|
||||
#include "arc/std/string.h"
|
||||
#include "arc/std/parser/helpers.h"
|
||||
#include "arc/std/errno.h"
|
||||
#include "arc/graphics/sprite.h"
|
||||
#include "arc/graphics/spritesheet.h"
|
||||
|
|
@ -14,146 +14,51 @@
|
|||
#include "arc/math/point.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
|
||||
|
||||
void ARC_Config_InitGraphics(ARC_Config *config, ARC_Renderer *renderer){
|
||||
//ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete);
|
||||
ARC_Config_RegisterTypeWithCStr(config, "ARC_Spritesheet", (ARC_ConfigType){ ARC_ConfigType_SpritesheetCopyFn, ARC_ConfigType_SpritesheetDestroyFn, renderer});
|
||||
ARC_Config_RegisterTypeWithCStr(config, "ARC_Sprite" , (ARC_ConfigType){ ARC_ConfigType_SpriteCopyFn , ARC_ConfigType_SpriteDestroyFn , renderer});
|
||||
}
|
||||
|
||||
int32_t ARC_SDL_Texture_Load(SDL_Texture **texture, ARC_Renderer *renderer, const char *path){
|
||||
IMG_Init(IMG_INIT_PNG);
|
||||
SDL_Surface *surface = IMG_Load(path);
|
||||
if(!surface){
|
||||
printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError());
|
||||
return 1; // GE_SDL_ERRNO_
|
||||
}
|
||||
void ARC_ConfigType_SpritesheetString(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
|
||||
ARC_Renderer *renderer = (ARC_Renderer *)userdata;
|
||||
|
||||
SDL_BlendMode tempMode;
|
||||
SDL_GetSurfaceBlendMode(surface, &tempMode);
|
||||
*texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface);
|
||||
SDL_GetTextureBlendMode(*texture, &tempMode);
|
||||
//get the path
|
||||
ARC_String *path;
|
||||
ARC_String_Create(&path, NULL, 0);
|
||||
ARC_ParserData_HelperRecurseStringAdd(&path, parsedData);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
IMG_Quit();
|
||||
//read in and set the texture
|
||||
ARC_Spritesheet_CreateFromFile((ARC_Spritesheet **)type, renderer, path);
|
||||
|
||||
return 0;
|
||||
//cleanup
|
||||
ARC_String_Destroy(path);
|
||||
}
|
||||
|
||||
//uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){
|
||||
// ARC_Config_Get(config, string, value);
|
||||
// if(*value){
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// ARC_String *tempStr, *textureStr;
|
||||
// ARC_String_StripEndsWhitespace(&tempStr, string);
|
||||
//
|
||||
// ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
|
||||
// ARC_String_Destroy(tempStr);
|
||||
//
|
||||
// ARC_SDL_Texture_Load(textureStr->data, (SDL_Texture **)value);
|
||||
//
|
||||
// ARC_String_Destroy(textureStr);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
//void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){
|
||||
// SDL_Texture *texture;
|
||||
//
|
||||
// ARC_String *tempStr, *textureStr;
|
||||
// ARC_String_StripEndsWhitespace(&tempStr, string);
|
||||
//
|
||||
// //check for reference
|
||||
// ARC_Config_Get(config, tempStr, (void **)&texture);
|
||||
// if(!texture && (tempStr->data[0] != '"' || tempStr->data[string->length - 1] != '"')){
|
||||
// arc_errno = ARC_ERRNO_DATA;
|
||||
// }
|
||||
//
|
||||
// ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
|
||||
// ARC_String_Destroy(tempStr);
|
||||
//
|
||||
// //try reading in the texture
|
||||
// if(!texture){
|
||||
// ARC_SDL_Texture_Read(config, string, (void **)&texture);
|
||||
// if(arc_errno){
|
||||
// *value = NULL;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ARC_String_Destroy(textureStr);
|
||||
//
|
||||
// *value = malloc(sizeof(ARC_Spritesheet));
|
||||
// ((ARC_Spritesheet *) *value)->texture = texture;
|
||||
// ((ARC_Spritesheet *) *value)->size = size;
|
||||
//}
|
||||
|
||||
void ARC_ConfigType_SpritesheetCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
|
||||
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
|
||||
|
||||
switch(valueTagToken->id){
|
||||
case ARC_CONFIG_STRING:
|
||||
ARC_ConfigType_SpritesheetString(type, valueTagToken, config, userdata);
|
||||
break;
|
||||
|
||||
case ARC_CONFIG_NESTED_VALUE:
|
||||
break;
|
||||
return;
|
||||
|
||||
default:
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_SpritesheetCopyFn(type, parsedData, config, userdata), cannot use a value that is not a string or nested value. Look at documention for this function for more info");
|
||||
break;
|
||||
}
|
||||
// if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
|
||||
// ARC_Spritesheet_ReadTexture(config, string, NULL, value);
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
|
||||
// if(arc_errno){
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// ARC_String *temp, *textureStr, *sizeStr;
|
||||
// ARC_String_CopySubstring(&temp, string, 1, split - 2);
|
||||
// ARC_String_StripEndsWhitespace(&textureStr, temp);
|
||||
// ARC_String_Destroy(temp);
|
||||
//
|
||||
// ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
|
||||
// ARC_String_StripEndsWhitespace(&sizeStr, temp);
|
||||
// ARC_String_Destroy(temp);
|
||||
//
|
||||
// uint32_t *size;
|
||||
// ARC_Config_Get(config, string, (void **)&size);
|
||||
// if(!size){
|
||||
// ARC_ConfigKey_Read_Uint32_t(config, sizeStr, (void **)&size);
|
||||
// if(arc_errno){
|
||||
// ARC_String_Destroy(sizeStr);
|
||||
// ARC_String_Destroy(textureStr);
|
||||
// return ARC_ERRNO_DATA;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ARC_Spritesheet_ReadTexture(config, textureStr, size, value);
|
||||
//
|
||||
// ARC_String_Destroy(sizeStr);
|
||||
// ARC_String_Destroy(textureStr);
|
||||
//
|
||||
// return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_ConfigType_SpritesheetDestroyFn(void *type){
|
||||
ARC_Spritesheet_Destroy((ARC_Spritesheet *)type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_ConfigType_SpriteDestroyFn(void *type){
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue