writefile: replace most struct lookups /w constants

Removes many hash lookups per file-save and undo-step.
This commit is contained in:
2016-06-28 20:05:42 +10:00
parent f181839c57
commit 55546b4e13
4 changed files with 504 additions and 410 deletions

View File

@@ -35,6 +35,10 @@ set(INC
../nodes ../nodes
../render/extern/include ../render/extern/include
../../../intern/guardedalloc ../../../intern/guardedalloc
# for writefile.c: dna_type_offsets.h
${CMAKE_BINARY_DIR}/source/blender/makesdna/intern
) )
set(INC_SYS set(INC_SYS
@@ -74,3 +78,6 @@ if(WITH_CODEC_FFMPEG)
endif() endif()
blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}") blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}")
# needed so writefile.c can use dna_type_offsets.h
add_dependencies(bf_blenloader bf_dna)

File diff suppressed because it is too large Load Diff

View File

@@ -56,8 +56,14 @@ add_executable(makesdna ${SRC} ${SRC_DNA_INC})
# Output dna.c # Output dna.c
add_custom_command( add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dna.c OUTPUT
COMMAND "$<TARGET_FILE:makesdna>" ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_SOURCE_DIR}/source/blender/makesdna/ ${CMAKE_CURRENT_BINARY_DIR}/dna.c
${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h
COMMAND
"$<TARGET_FILE:makesdna>"
${CMAKE_CURRENT_BINARY_DIR}/dna.c
${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h
${CMAKE_SOURCE_DIR}/source/blender/makesdna/
DEPENDS makesdna DEPENDS makesdna
) )
@@ -78,7 +84,11 @@ set(SRC
${SRC_DNA_INC} ${SRC_DNA_INC}
) )
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dna.c PROPERTIES GENERATED TRUE) set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/dna.c
${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h
PROPERTIES GENERATED TRUE
)
blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}") blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}")

View File

@@ -968,7 +968,7 @@ void printStructLengths(void)
} }
static int make_structDNA(const char *baseDirectory, FILE *file) static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets)
{ {
int len, i; int len, i;
const short *sp; const short *sp;
@@ -1159,6 +1159,19 @@ static int make_structDNA(const char *baseDirectory, FILE *file)
/* end end padding test */ /* end end padding test */
} }
/* write a simple enum with all structs offsets,
* should only be accessed via SDNA_TYPE_FROM_STRUCT macro */
{
fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
fprintf(file_offsets, "enum {\n");
for (i = 0; i < nr_structs; i++) {
const short *structpoin = structs[i];
const int structtype = structpoin[0];
fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", types[structtype], i);
}
fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs);
fprintf(file_offsets, "};\n");
}
MEM_freeN(namedata); MEM_freeN(namedata);
MEM_freeN(typedata); MEM_freeN(typedata);
@@ -1190,43 +1203,53 @@ static void make_bad_file(const char *file, int line)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
FILE *file;
int return_status = 0; int return_status = 0;
if (argc != 2 && argc != 3) { if (argc != 3 && argc != 4) {
printf("Usage: %s outfile.c [base directory]\n", argv[0]); printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
return_status = 1; return_status = 1;
} }
else { else {
file = fopen(argv[1], "w"); FILE *file_dna = fopen(argv[1], "w");
if (!file) { FILE *file_dna_offsets = fopen(argv[2], "w");
if (!file_dna) {
printf("Unable to open file: %s\n", argv[1]); printf("Unable to open file: %s\n", argv[1]);
return_status = 1; return_status = 1;
} }
else if (!file_dna_offsets) {
printf("Unable to open file: %s\n", argv[2]);
return_status = 1;
}
else { else {
const char *baseDirectory; const char *baseDirectory;
if (argc == 3) { if (argc == 4) {
baseDirectory = argv[2]; baseDirectory = argv[3];
} }
else { else {
baseDirectory = BASE_HEADER; baseDirectory = BASE_HEADER;
} }
fprintf(file, "const unsigned char DNAstr[] = {\n"); fprintf(file_dna, "const unsigned char DNAstr[] = {\n");
if (make_structDNA(baseDirectory, file)) { if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) {
/* error */ /* error */
fclose(file); fclose(file_dna);
file_dna = NULL;
make_bad_file(argv[1], __LINE__); make_bad_file(argv[1], __LINE__);
return_status = 1; return_status = 1;
} }
else { else {
fprintf(file, "};\n"); fprintf(file_dna, "};\n");
fprintf(file, "const int DNAlen = sizeof(DNAstr);\n"); fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
fclose(file);
} }
} }
if (file_dna) {
fclose(file_dna);
}
if (file_dna_offsets) {
fclose(file_dna_offsets);
}
} }