Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-06-28 13:05:42 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-06-28 13:25:52 +0300
commit55546b4e135283f2ec4b5715536e59722c55f11c (patch)
tree31a96606e7a60bb7583da0077683b04ebd765cee /source/blender/makesdna/intern
parentf181839c572fdffe9554cf7d9e41c7ceffeec02e (diff)
writefile: replace most struct lookups /w constants
Removes many hash lookups per file-save and undo-step.
Diffstat (limited to 'source/blender/makesdna/intern')
-rw-r--r--source/blender/makesdna/intern/CMakeLists.txt16
-rw-r--r--source/blender/makesdna/intern/makesdna.c53
2 files changed, 51 insertions, 18 deletions
diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt
index b4ada7ffbf1..0bb6e866bf4 100644
--- a/source/blender/makesdna/intern/CMakeLists.txt
+++ b/source/blender/makesdna/intern/CMakeLists.txt
@@ -56,8 +56,14 @@ add_executable(makesdna ${SRC} ${SRC_DNA_INC})
# Output dna.c
add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dna.c
- COMMAND "$<TARGET_FILE:makesdna>" ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_SOURCE_DIR}/source/blender/makesdna/
+ OUTPUT
+ ${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
)
@@ -78,7 +84,11 @@ set(SRC
${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}")
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index fc94a8d9ff4..b78299316e1 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -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;
const short *sp;
@@ -1159,6 +1159,19 @@ static int make_structDNA(const char *baseDirectory, FILE *file)
/* 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(typedata);
@@ -1190,43 +1203,53 @@ static void make_bad_file(const char *file, int line)
int main(int argc, char **argv)
{
- FILE *file;
int return_status = 0;
- if (argc != 2 && argc != 3) {
- printf("Usage: %s outfile.c [base directory]\n", argv[0]);
+ if (argc != 3 && argc != 4) {
+ printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
return_status = 1;
}
else {
- file = fopen(argv[1], "w");
- if (!file) {
+ FILE *file_dna = fopen(argv[1], "w");
+ FILE *file_dna_offsets = fopen(argv[2], "w");
+ if (!file_dna) {
printf("Unable to open file: %s\n", argv[1]);
return_status = 1;
}
+ else if (!file_dna_offsets) {
+ printf("Unable to open file: %s\n", argv[2]);
+ return_status = 1;
+ }
else {
const char *baseDirectory;
- if (argc == 3) {
- baseDirectory = argv[2];
+ if (argc == 4) {
+ baseDirectory = argv[3];
}
else {
baseDirectory = BASE_HEADER;
}
- fprintf(file, "const unsigned char DNAstr[] = {\n");
- if (make_structDNA(baseDirectory, file)) {
+ fprintf(file_dna, "const unsigned char DNAstr[] = {\n");
+ if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) {
/* error */
- fclose(file);
+ fclose(file_dna);
+ file_dna = NULL;
make_bad_file(argv[1], __LINE__);
return_status = 1;
}
else {
- fprintf(file, "};\n");
- fprintf(file, "const int DNAlen = sizeof(DNAstr);\n");
-
- fclose(file);
+ fprintf(file_dna, "};\n");
+ fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
}
}
+
+ if (file_dna) {
+ fclose(file_dna);
+ }
+ if (file_dna_offsets) {
+ fclose(file_dna_offsets);
+ }
}