started working on graphics config

This commit is contained in:
herbglitch 2025-03-17 18:01:18 -06:00
parent 585768f33d
commit 13ef683164
5 changed files with 69 additions and 67 deletions

View file

@ -8,8 +8,31 @@ extern "C" {
#include "arc/std/config.h" #include "arc/std/config.h"
#include "arc/graphics/renderer.h" #include "arc/graphics/renderer.h"
/**
* @brief
*/
void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer); void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer);
/**
* @brief
*/
void ARC_ConfigType_SpritesheetCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata);
/**
* @brief
*/
void ARC_ConfigType_SpritesheetDestroyFn(void *type);
/**
* @brief
*/
void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata);
/**
* @brief
*/
void ARC_ConfigType_SpriteDestroyFn(void *type);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -17,7 +17,7 @@ typedef struct ARC_Config ARC_Config;
/** /**
* @brief a function callback to create a type stored within a config * @brief a function callback to create a type stored within a config
*/ */
typedef void (* ARC_ConfigType_CopyFn)(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config); typedef void (* ARC_ConfigType_CopyFn)(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata);
/** /**
* @brief a function callback to destroy a type * @brief a function callback to destroy a type
@ -30,6 +30,7 @@ typedef void (* ARC_ConfigType_DestroyFn)(void *type);
typedef struct ARC_ConfigType { typedef struct ARC_ConfigType {
ARC_ConfigType_CopyFn copyFn; ARC_ConfigType_CopyFn copyFn;
ARC_ConfigType_DestroyFn destroyFn; ARC_ConfigType_DestroyFn destroyFn;
void *userdata;
} ARC_ConfigType; } ARC_ConfigType;
/** /**

View file

@ -1,68 +1,45 @@
#include "arc/graphics/config.h" #include "arc/graphics/config.h"
//#include <SDL_image.h> #include <SDL_image.h>
//#include <stdio.h> #include <stdio.h>
//#include "renderer.h" #include "renderer.h"
//#include "sprite.h" #include "sprite.h"
//#include "spritesheet.h" #include "spritesheet.h"
//#include "arc/std/array.h" #include "arc/std/array.h"
//#include "arc/std/string.h" #include "arc/std/string.h"
//#include "arc/std/errno.h" #include "arc/std/errno.h"
//#include "arc/graphics/sprite.h" #include "arc/graphics/sprite.h"
//#include "arc/graphics/spritesheet.h" #include "arc/graphics/spritesheet.h"
//#include "arc/math/config.h" #include "arc/math/config.h"
//#include "arc/math/point.h" #include "arc/math/point.h"
//#include "arc/math/rectangle.h" #include "arc/math/rectangle.h"
// #define ARC_DEFAULT_CONFIG
//#include "arc/std/defaults/config.h"
//SDL_Renderer *global_renderer; 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);
//uint8_t ARC_SDL_Texture_Read(ARC_Config *config, ARC_String *string, void **value); ARC_Config_RegisterTypeWithCStr(config, "ARC_Spritesheet", (ARC_ConfigType){ ARC_ConfigType_SpritesheetCopyFn, ARC_ConfigType_SpritesheetDestroyFn, renderer});
//uint8_t ARC_Spritesheet_Read(ARC_Config *config, ARC_String *string, void **value); ARC_Config_RegisterTypeWithCStr(config, "ARC_Sprite" , (ARC_ConfigType){ ARC_ConfigType_SpriteCopyFn , ARC_ConfigType_SpriteDestroyFn , renderer});
//uint8_t ARC_Sprite_Read (ARC_Config *config, ARC_String *string, void **value); }
//
//void ARC_SDL_Texture_Delete(ARC_Config *config, ARC_String *string, void *value); int32_t ARC_SDL_Texture_Load(SDL_Texture **texture, ARC_Renderer *renderer, const char *path){
//void ARC_Spritesheet_Delete(ARC_Config *config, ARC_String *string, void *value); IMG_Init(IMG_INIT_PNG);
//void ARC_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value); SDL_Surface *surface = IMG_Load(path);
// if(!surface){
//void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError());
// global_renderer = (SDL_Renderer *)renderer; return 1; // GE_SDL_ERRNO_
// ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete); }
// ARC_Config_AddKeyCString(config, (char *)"ARC_Spritesheet", 15, ARC_Spritesheet_Read, ARC_Spritesheet_Delete);
// ARC_Config_AddKeyCString(config, (char *)"ARC_Sprite" , 10, ARC_Sprite_Read , ARC_Sprite_Delete ); SDL_BlendMode tempMode;
//} SDL_GetSurfaceBlendMode(surface, &tempMode);
// *texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface);
//uint64_t ARC_GraphicsConfig_GetIndexAndErrorCheck(ARC_String *string, char *search, uint64_t searchLength){ SDL_GetTextureBlendMode(*texture, &tempMode);
// uint64_t separator = ARC_String_FindCString(string, ",", 1);
// SDL_FreeSurface(surface);
// if(separator == ~(uint64_t)0){ IMG_Quit();
// arc_errno = ARC_ERRNO_DATA;
// } return 0;
// }
// return separator;
//}
//
//int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
// 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_
// }
//
// SDL_BlendMode tempMode;
// SDL_GetSurfaceBlendMode(surface, &tempMode);
// *texture = SDL_CreateTextureFromSurface(global_renderer, surface);
// SDL_GetTextureBlendMode(*texture, &tempMode);
//
// SDL_FreeSurface(surface);
// IMG_Quit();
//
// return 0;
//}
//
//uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){ //uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){
// ARC_Config_Get(config, string, value); // ARC_Config_Get(config, string, value);
// if(*value){ // if(*value){
@ -80,7 +57,7 @@
// ARC_String_Destroy(textureStr); // ARC_String_Destroy(textureStr);
// return 0; // return 0;
//} //}
//
//void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){ //void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){
// SDL_Texture *texture; // SDL_Texture *texture;
// //

View file

@ -364,7 +364,7 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
} }
//passed the parsed value into the copy type function and set the destroy function //passed the parsed value into the copy type function and set the destroy function
type->copyFn(&(typeData->data), childTagToken, config); type->copyFn(&(typeData->data), childTagToken, config, type->userdata);
typeData->destroyFn = type->destroyFn; typeData->destroyFn = type->destroyFn;
//add to the current group hashtable //add to the current group hashtable

View file

@ -7,7 +7,7 @@
static const char *testType = "int32"; static const char *testType = "int32";
void TEST_configType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config){ void TEST_configType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
//go into the <numberSign> tag //go into the <numberSign> tag
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_NUMBER_SIGN){ if(childTagToken->id != ARC_CONFIG_NUMBER_SIGN){
@ -83,7 +83,8 @@ ARC_TEST(config_BasicTest){
ARC_ConfigType int32Type = { ARC_ConfigType int32Type = {
TEST_configType_CopyInt32Fn, TEST_configType_CopyInt32Fn,
TEST_configType_DestroyInt32Fn TEST_configType_DestroyInt32Fn,
NULL
}; };
ARC_Config_RegisterTypeWithCStr(config, testType, int32Type); ARC_Config_RegisterTypeWithCStr(config, testType, int32Type);