Quake II RTX doxygen
1.0 dev
|
|
Go to the documentation of this file.
20 #include "common/files.h"
21 #include "refresh/images.h"
36 #define MAX_CSV_VALUES 32
46 strncpy(dest, csv->
values[index], MAX_QPATH);
55 *dest = atof(csv->
values[index]);
63 *dest = atoi(csv->
values[index]);
71 if (atoi(csv->
values[index]))
72 *flags = *flags | mask;
78 static char delim =
',';
80 char * cptr = linebuf,
c;
91 csv->
values[index] = cptr + 1;
96 else if (
c == delim && !inquote)
99 csv->
values[++index] = cptr + 1;
104 return Q_ERR_SUCCESS;
114 size_t len = strlen(src);
115 assert(len < MAX_QPATH);
117 if (len > 4 && src[len - 4] ==
'.')
121 memcpy(dest, src, len);
159 mat->
flags = mat_index;
176 Com_EPrintf(
"duplicate material names in materials table '%s'\n", table->
filename);
177 return Q_ERR_FAILURE;
181 Com_WPrintf(
"materials table '%s' is not sorted - fast search disabled\n", table->
filename);
185 return Q_ERR_SUCCESS;
231 char path[MAX_OSPATH];
232 qhandle_t f =
FS_EasyOpenFile(path,
sizeof(path), FS_MODE_WRITE | FS_FLAG_TEXT,
"", filename,
"");
234 Com_EPrintf(
"Error opening '%s'\n", path);
235 return Q_ERR_FAILURE;
238 FS_FPrintf(f,
"Material,Bump Scale,Roughness Override,Specular Scale,Emissive Scale,Kind,Invisible Flag,Light Flag,Correct Albedo Flag\n");
257 Com_Printf(
"Saved '%s'\n", path);
258 return Q_ERR_SUCCESS;
267 byte * buffer = NULL; ssize_t buffer_size = 0;
268 buffer_size = FS_LoadFile(filename, (
void**)&buffer);
271 Com_EPrintf(
"cannot load materials table '%s'\n", filename);
272 return Q_ERR_FAILURE;
278 char const * ptr = (
char const *)buffer;
279 char linebuf[MAX_QPATH * 3];
280 while (
sgets(linebuf,
sizeof(linebuf), &ptr))
283 if (currentLine == 0 && strncmp(linebuf,
"Material", 8) == 0)
290 qerror_t status = Q_ERR_SUCCESS;
302 char kindname[MAX_QPATH];
314 status = Q_ERR_FAILURE;
316 if (status == Q_ERR_SUCCESS)
323 Com_EPrintf(
"CSV error in materials table : '%s':%d", table->
filename, currentLine);
330 Com_Printf(
"Loaded '%s' (fast search = %s)\n", filename, table->
alpha_sorted == qtrue ?
"true" :
"false");
352 * new_table = &newtable;
358 Com_EPrintf(
"Cannot reload materials table : table has different material count, please restart the game\n");
359 return Q_ERR_FAILURE;
364 Com_EPrintf(
"Cannot reload materials table : table has different material keys, please check your edits\n");
365 return Q_ERR_FAILURE;
371 * new_mat = &new_table->materials[i];
373 if (strncmp(old_mat->
name, new_mat->name, MAX_QPATH) != 0)
375 Com_EPrintf(
"Cannot update material '%s' : incorrect name, please check your edits\n", new_mat->name);
384 old_mat->
flags = new_mat->flags;
388 return Q_ERR_FAILURE;
402 return Q_ERR_FAILURE;
407 return Q_ERR_SUCCESS;
418 return Q_ERR_SUCCESS;
453 return Q_ERR_SUCCESS;
467 char name_copy[MAX_QPATH];
475 int search_start = 0;
482 while (left <=
right)
484 int middle = floor((left +
right) / 2);
511 strcpy(mat->
name, name_copy);
512 Com_Printf(
"Created a material entry %d for unknown material %s\n", index, name_copy);
551 Com_Printf(
"{ %s\n", mat->
name);
555 Com_Printf(
" bump_scale = %f,\n", mat->
bump_scale);
560 Com_Printf(
" kind = '%s',\n", kind ? kind :
"");
576 enum TokenType { TOKEN_BOOL, TOKEN_FLOAT, TOKEN_STRING };
578 static struct Token {
583 {0,
"bump_scale", TOKEN_FLOAT},
584 {1,
"roughness_override", TOKEN_FLOAT},
585 {2,
"specular_scale", TOKEN_FLOAT},
586 {3,
"emissive_scale", TOKEN_FLOAT},
587 {4,
"kind", TOKEN_STRING},
588 {5,
"light_flag", TOKEN_BOOL},
589 {6,
"correct_albedo_flag", TOKEN_BOOL} };
591 static int ntokens =
sizeof(tokens) /
sizeof(
struct Token);
593 if (token == NULL || value == NULL)
596 struct Token const * t = NULL;
597 for (
int i = 0; i < ntokens; ++i)
599 if (strcmp(token, tokens[i].name) == 0)
604 Com_EPrintf(
"Unknown material token '%s'\n",
Cmd_Argv(1));
608 float fvalue = 0.f; qboolean bvalue = qfalse;
char const * svalue = NULL;
611 case TOKEN_BOOL: bvalue = atoi(value) == 0 ? qfalse : qtrue;
break;
612 case TOKEN_FLOAT: fvalue = (float)atof(value);
break;
613 case TOKEN_STRING: svalue = value;
break;
615 assert(
"unknown PBR MAT attribute token type");
632 Com_EPrintf(
"Unknown material kind '%s'\n", svalue);
633 return Q_ERR_FAILURE;
640 return Q_ERR_SUCCESS;
643 Com_Printf(
"Usage : set_material <token> <value>\n");
644 for (
int i = 0; i < ntokens; ++i)
646 struct Token const * t = &tokens[i];
648 char const *
typename =
"(undefined)";
651 case TOKEN_BOOL:
typename =
"bool [0,1]";
break;
652 case TOKEN_FLOAT:
typename =
"float";
break;
653 case TOKEN_STRING:
typename =
"string";
break;
655 Com_Printf(
" %s (%s)\n", t->name,
typename);
657 return Q_ERR_FAILURE;
static qerror_t parse_CSV_line(char *linebuf, CSV_values_t *csv)
static qerror_t getStringValue(CSV_values_t const *csv, int index, char *dest)
int MAT_GetNumPBRMaterials()
struct pbr_materials_table_s pbr_materials_table_t
qhandle_t FS_EasyOpenFile(char *buf, size_t size, unsigned mode, const char *dir, const char *name, const char *ext)
#define MATERIAL_KIND_INVALID
#define MATERIAL_FLAG_CORRECT_ALBEDO
static qerror_t validateMaterialsTable(pbr_materials_table_t *table)
#define MATERIAL_KIND_LAVA
qerror_t MAT_SavePBRMaterials()
static struct MaterialKind materialKinds[]
void MAT_PrintMaterialProperties(pbr_material_t const *mat)
static const char * materials_filename
void MAT_UpdateRegistration(pbr_material_t *mat)
qerror_t MAT_SetPBRMaterialAttribute(pbr_material_t *mat, char const *token, char const *value)
int registration_sequence
ssize_t FS_FPrintf(qhandle_t f, const char *format,...)
pbr_material_t * MAT_GetPBRMaterial(int index)
#define MATERIAL_KIND_SKY
#define MATERIAL_FLAG_LIGHT
const pbr_material_t * MAT_UpdatePBRMaterialSkin(image_t *image_diffuse)
qerror_t MAT_RegisterPBRMaterial(pbr_material_t *mat, image_t *image_diffuse, image_t *image_normals, image_t *image_emissive)
static qerror_t writeMaterialsTable(char const *filename, pbr_materials_table_t const *table)
static qerror_t getIntValue(CSV_values_t const *csv, int index, int *dest)
qerror_t MAT_ReloadPBRMaterials()
qerror_t MAT_ResetUnused()
struct CSV_values_s CSV_values_t
#define MATERIAL_KIND_REGULAR
static void MAT_Reset(pbr_material_t *mat, int mat_index)
#define MATERIAL_KIND_MASK
static int nMaterialKinds
#define MATERIAL_KIND_CHROME
char * values[MAX_CSV_VALUES]
const pbr_material_t * MAT_GetPBRMaterialsTable()
qboolean MAT_IsKind(uint32_t material, uint32_t kind)
pbr_material_t materials[MAX_PBR_MATERIALS]
#define MAX_PBR_MATERIALS
int Q_strcasecmp(const char *s1, const char *s2)
#define MATERIAL_KIND_CAMERA
#define MATERIAL_KIND_SLIME
char * sgets(char *str, int num, char const **input)
int registration_sequence
#define MATERIAL_KIND_SCREEN
static pbr_materials_table_t pbr_materials_table
static const char * getMaterialKindName(uint32_t flag)
void FS_FCloseFile(qhandle_t f)
size_t Q_concat(char *dest, size_t size,...)
static qerror_t getFlagValue(CSV_values_t const *csv, int index, uint32_t *flags, uint32_t mask)
qerror_t MAT_InitializePBRmaterials()
#define MATERIAL_KIND_INVISIBLE
static uint32_t getMaterialKind(char const *kindname)
#define MATERIAL_INDEX_MASK
static size_t truncateExtension(char const *src, char *dest)
#define MATERIAL_KIND_WATER
static qerror_t getFloatValue(CSV_values_t const *csv, int index, float *dest)
static qerror_t parseMaterialsTable(char const *filename, pbr_materials_table_t *table)
int MAT_GetPBRMaterialIndex(pbr_material_t const *mat)
uint32_t MAT_SetKind(uint32_t material, uint32_t kind)
pbr_material_t * MAT_FindPBRMaterial(char const *name)
#define MATERIAL_KIND_GLASS